From 87e9aeb9143a3dab2dcac24797c822dedde845f1 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 18 Feb 2015 10:59:30 +0000 Subject: [PATCH 1/4] Move pynacl to the top of the depedency link list so that it is installed before syutil --- synapse/python_dependencies.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py index ec78fc362..a30a57055 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py @@ -24,6 +24,11 @@ def github_link(project, version, egg): return "https://github.com/%s/tarball/%s/#egg=%s" % (project, version, egg) DEPENDENCY_LINKS = [ + github_link( + project="pyca/pynacl", + version="d4d3175589b892f6ea7c22f466e0e223853516fa", + egg="pynacl-0.3.0", + ) github_link( project="matrix-org/syutil", version="v0.0.3", @@ -34,11 +39,6 @@ DEPENDENCY_LINKS = [ version="v0.6.2", egg="matrix_angular_sdk-0.6.2", ), - github_link( - project="pyca/pynacl", - version="d4d3175589b892f6ea7c22f466e0e223853516fa", - egg="pynacl-0.3.0", - ) ] From 5806d52423a97e219b710ca638866e0763fa416e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 18 Feb 2015 11:01:37 +0000 Subject: [PATCH 2/4] Fix syntax --- synapse/python_dependencies.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/python_dependencies.py b/synapse/python_dependencies.py index a30a57055..9464b4fb6 100644 --- a/synapse/python_dependencies.py +++ b/synapse/python_dependencies.py @@ -28,7 +28,7 @@ DEPENDENCY_LINKS = [ project="pyca/pynacl", version="d4d3175589b892f6ea7c22f466e0e223853516fa", egg="pynacl-0.3.0", - ) + ), github_link( project="matrix-org/syutil", version="v0.0.3", From 2462aacd77963431507bb97769acee3ed9d65ceb Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 18 Feb 2015 11:51:00 +0000 Subject: [PATCH 3/4] Restrict the destinations that synapse can talk to --- synapse/federation/transaction_queue.py | 30 ++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/synapse/federation/transaction_queue.py b/synapse/federation/transaction_queue.py index ae04774c7..4b5460c79 100644 --- a/synapse/federation/transaction_queue.py +++ b/synapse/federation/transaction_queue.py @@ -66,6 +66,26 @@ class TransactionQueue(object): # HACK to get unique tx id 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 @log_function def enqueue_pdu(self, pdu, destinations, order): @@ -74,8 +94,9 @@ class TransactionQueue(object): # table and we'll get back to it later. destinations = set(destinations) - destinations.discard(self.server_name) - destinations.discard("localhost") + destinations = set( + dest for dest in destinations if self.can_send_to(dest) + ) logger.debug("Sending to: %s", str(destinations)) @@ -107,7 +128,7 @@ class TransactionQueue(object): def enqueue_edu(self, edu): destination = edu.destination - if destination == self.server_name: + if not self.can_send_to(destination): return deferred = defer.Deferred() @@ -130,6 +151,9 @@ class TransactionQueue(object): def enqueue_failure(self, failure, destination): deferred = defer.Deferred() + if not self.can_send_to(destination): + return + self.pending_failures_by_dest.setdefault( destination, [] ).append( From 6375bd3e33f687499e6d15298e74416c77ab499e Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 18 Feb 2015 12:01:37 +0000 Subject: [PATCH 4/4] SYN-282: Don't log tracebacks for client errors --- synapse/rest/media/v1/base_resource.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/base_resource.py b/synapse/rest/media/v1/base_resource.py index d44d5f129..b10cbddb8 100644 --- a/synapse/rest/media/v1/base_resource.py +++ b/synapse/rest/media/v1/base_resource.py @@ -54,7 +54,7 @@ class BaseMediaResource(Resource): try: yield request_handler(self, request) except CodeMessageException as e: - logger.exception(e) + logger.info("Responding with error: %r", e) respond_with_json( request, e.code, cs_exception(e), send_cors=True )