summary refs log tree commit diff
path: root/synapse/federation/transport/server.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-02 13:53:30 +0000
committerErik Johnston <erik@matrix.org>2015-03-02 13:53:30 +0000
commit0a036944bd2f0b42195b1984ff0ad2b6ff3d50f3 (patch)
tree25ca81b14a72192a89c9399b3d80180ac124ca14 /synapse/federation/transport/server.py
parentMust update pending_transactions map before yield'ing (diff)
parentMerge pull request #83 from matrix-org/nofile_limit_config (diff)
downloadsynapse-0a036944bd2f0b42195b1984ff0ad2b6ff3d50f3.tar.xz
Merge branch 'develop' of github.com:matrix-org/synapse into batched_get_pdu
Diffstat (limited to 'synapse/federation/transport/server.py')
-rw-r--r--synapse/federation/transport/server.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py
index ad75c8ddb7..ece6dbcf62 100644
--- a/synapse/federation/transport/server.py
+++ b/synapse/federation/transport/server.py
@@ -98,15 +98,23 @@ class TransportLayerServer(object):
         def new_handler(request, *args, **kwargs):
             try:
                 (origin, content) = yield self._authenticate_request(request)
-                response = yield handler(
-                    origin, content, request.args, *args, **kwargs
-                )
+                with self.ratelimiter.ratelimit(origin) as d:
+                    yield d
+                    response = yield handler(
+                        origin, content, request.args, *args, **kwargs
+                    )
             except:
                 logger.exception("_authenticate_request failed")
                 raise
             defer.returnValue(response)
         return new_handler
 
+    def rate_limit_origin(self, handler):
+        def new_handler(origin, *args, **kwargs):
+            response = yield handler(origin, *args, **kwargs)
+            defer.returnValue(response)
+        return new_handler()
+
     @log_function
     def register_received_handler(self, handler):
         """ Register a handler that will be fired when we receive data.