This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Allow Configurable Rate Limiting Per AS #1175
Merged
lukebarnard1
merged 6 commits into
develop
from
luke/feature-configurable-as-rate-limiting
Oct 20, 2016
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5b54d51
Allow Configurable Rate Limiting Per AS
1b17d1a
Use real AS object by passing it through the requester
8bfd01f
flake8
f09db23
as_user->app_service, less redundant comments, better positioned comm…
07caa74
Closing brace on following line
6fdd319
Style
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,24 @@ def ratelimit(self, requester): | |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably compact the lot of this and remove for service in self.store.get_app_services():
if service.is_interested_in_user(user_id) and not service.is_rate_limited():
return But I defer to Erik's view on whether this is clearer / what he would prefer. |
||
|
||
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, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check looks like it could be relatively expensive and is on a vaguely hot path. (Its also wrong if multiple AS's register non-exclusive interest in it).
I'd rather we did this by checking if the authenticated thing actually doing the sending was an AS. We can probably do this by adding a field to the requester type when we authenticate the sender in auth module and checking that field here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I'll make some changes.