summary refs log tree commit diff
path: root/synapse/handlers/_base.py
diff options
context:
space:
mode:
authorLuke Barnard <lukeb@openmarket.com>2016-10-18 17:04:09 +0100
committerLuke Barnard <lukeb@openmarket.com>2016-10-18 17:04:09 +0100
commit5b54d51d1e98450451b8ffe3a57ad98373e8f5e6 (patch)
tree0d5a94da69eafae973f8c616668f99c4a3c845cd /synapse/handlers/_base.py
parentMerge branch 'release-v0.18.2' of github.com:matrix-org/synapse into develop (diff)
downloadsynapse-5b54d51d1e98450451b8ffe3a57ad98373e8f5e6.tar.xz
Allow Configurable Rate Limiting Per AS
This adds a flag loaded from the registration file of an AS that will determine whether or not its users are rate limited (by ratelimit in _base.py). Needed for IRC bridge reasons - see https://github.com/matrix-org/matrix-appservice-irc/issues/240.
Diffstat (limited to 'synapse/handlers/_base.py')
-rw-r--r--synapse/handlers/_base.py14
1 files changed, 14 insertions, 0 deletions
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 4981643166..a377b1225b 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -57,10 +57,24 @@ class BaseHandler(object):
         time_now = self.clock.time()
         user_id = requester.user.to_string()
 
+        # Disable rate limiting of users belonging to any AS that is configured
+        # not to be rate limited in its registration file (rate_limited: true|false).
+        # The AS user itself is never rate limited.
+
         app_service = self.store.get_app_service_by_user_id(user_id)
         if app_service is not None:
             return  # do not ratelimit app service senders
 
+        should_rate_limit = True
+
+        for service in self.store.get_app_services():
+            if service.is_interested_in_user(user_id):
+                should_rate_limit = service.is_rate_limited()
+                break
+
+        if not should_rate_limit:
+            return
+
         allowed, time_allowed = self.ratelimiter.send_message(
             user_id, time_now,
             msg_rate_hz=self.hs.config.rc_messages_per_second,