diff options
author | Erik Johnston <erik@matrix.org> | 2015-03-02 13:44:43 +0000 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-03-02 13:44:43 +0000 |
commit | e4f301e7a0bfd71187db319311590e0aac685927 (patch) | |
tree | d9e1596e1ecf6cfd6a3e7152a20748496a9e0890 /synapse/federation/transport/server.py | |
parent | Merge pull request #95 from matrix-org/serialize_transaction_processing (diff) | |
parent | Merge branch 'develop' of github.com:matrix-org/synapse into federation_rate_... (diff) | |
download | synapse-e4f301e7a0bfd71187db319311590e0aac685927.tar.xz |
Merge pull request #94 from matrix-org/federation_rate_limit
Federation rate limit
Diffstat (limited to 'synapse/federation/transport/server.py')
-rw-r--r-- | synapse/federation/transport/server.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index 2ffb37aa18..fce9c0195e 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. |