mirror of
https://mau.dev/maunium/synapse.git
synced 2024-08-28 21:22:02 +00:00
Merge pull request #80 from matrix-org/restrict-destinations
Restrict the destinations that synapse can talk to
This commit is contained in:
commit
7d304ae11c
@ -66,6 +66,26 @@ class TransactionQueue(object):
|
|||||||
# HACK to get unique tx id
|
# HACK to get unique tx id
|
||||||
self._next_txn_id = int(self._clock.time_msec())
|
self._next_txn_id = int(self._clock.time_msec())
|
||||||
|
|
||||||
|
def can_send_to(self, destination):
|
||||||
|
"""Can we send messages to the given server?
|
||||||
|
|
||||||
|
We can't send messages to ourselves. If we are running on localhost
|
||||||
|
then we can only federation with other servers running on localhost.
|
||||||
|
Otherwise we only federate with servers on a public domain.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
destination(str): The server we are possibly trying to send to.
|
||||||
|
Returns:
|
||||||
|
bool: True if we can send to the server.
|
||||||
|
"""
|
||||||
|
|
||||||
|
if destination == self.server_name:
|
||||||
|
return False
|
||||||
|
if self.server_name.startswith("localhost"):
|
||||||
|
return destination.startswith("localhost")
|
||||||
|
else:
|
||||||
|
return not destination.startswith("localhost")
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def enqueue_pdu(self, pdu, destinations, order):
|
def enqueue_pdu(self, pdu, destinations, order):
|
||||||
@ -74,8 +94,9 @@ class TransactionQueue(object):
|
|||||||
# table and we'll get back to it later.
|
# table and we'll get back to it later.
|
||||||
|
|
||||||
destinations = set(destinations)
|
destinations = set(destinations)
|
||||||
destinations.discard(self.server_name)
|
destinations = set(
|
||||||
destinations.discard("localhost")
|
dest for dest in destinations if self.can_send_to(dest)
|
||||||
|
)
|
||||||
|
|
||||||
logger.debug("Sending to: %s", str(destinations))
|
logger.debug("Sending to: %s", str(destinations))
|
||||||
|
|
||||||
@ -107,7 +128,7 @@ class TransactionQueue(object):
|
|||||||
def enqueue_edu(self, edu):
|
def enqueue_edu(self, edu):
|
||||||
destination = edu.destination
|
destination = edu.destination
|
||||||
|
|
||||||
if destination == self.server_name:
|
if not self.can_send_to(destination):
|
||||||
return
|
return
|
||||||
|
|
||||||
deferred = defer.Deferred()
|
deferred = defer.Deferred()
|
||||||
@ -130,6 +151,9 @@ class TransactionQueue(object):
|
|||||||
def enqueue_failure(self, failure, destination):
|
def enqueue_failure(self, failure, destination):
|
||||||
deferred = defer.Deferred()
|
deferred = defer.Deferred()
|
||||||
|
|
||||||
|
if not self.can_send_to(destination):
|
||||||
|
return
|
||||||
|
|
||||||
self.pending_failures_by_dest.setdefault(
|
self.pending_failures_by_dest.setdefault(
|
||||||
destination, []
|
destination, []
|
||||||
).append(
|
).append(
|
||||||
|
Loading…
Reference in New Issue
Block a user