mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 10:46:06 -04:00
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.
This commit is contained in:
parent
50ac1d843d
commit
5b54d51d1e
3 changed files with 26 additions and 1 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue