mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-10-01 08:25:44 -04:00
Reduce the duplication of code that invokes the rate limiter. (#13070)
This commit is contained in:
parent
1e0044e8f9
commit
7552615247
1
changelog.d/13070.misc
Normal file
1
changelog.d/13070.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Reduce the duplication of code that invokes the rate limiter.
|
@ -26,13 +26,7 @@ from synapse.api.constants import (
|
|||||||
GuestAccess,
|
GuestAccess,
|
||||||
Membership,
|
Membership,
|
||||||
)
|
)
|
||||||
from synapse.api.errors import (
|
from synapse.api.errors import AuthError, Codes, ShadowBanError, SynapseError
|
||||||
AuthError,
|
|
||||||
Codes,
|
|
||||||
LimitExceededError,
|
|
||||||
ShadowBanError,
|
|
||||||
SynapseError,
|
|
||||||
)
|
|
||||||
from synapse.api.ratelimiting import Ratelimiter
|
from synapse.api.ratelimiting import Ratelimiter
|
||||||
from synapse.event_auth import get_named_level, get_power_level_event
|
from synapse.event_auth import get_named_level, get_power_level_event
|
||||||
from synapse.events import EventBase
|
from synapse.events import EventBase
|
||||||
@ -380,16 +374,7 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||||||
# Only rate-limit if the user actually joined the room, otherwise we'll end
|
# Only rate-limit if the user actually joined the room, otherwise we'll end
|
||||||
# up blocking profile updates.
|
# up blocking profile updates.
|
||||||
if newly_joined and ratelimit:
|
if newly_joined and ratelimit:
|
||||||
time_now_s = self.clock.time()
|
await self._join_rate_limiter_local.ratelimit(requester)
|
||||||
(
|
|
||||||
allowed,
|
|
||||||
time_allowed,
|
|
||||||
) = await self._join_rate_limiter_local.can_do_action(requester)
|
|
||||||
|
|
||||||
if not allowed:
|
|
||||||
raise LimitExceededError(
|
|
||||||
retry_after_ms=int(1000 * (time_allowed - time_now_s))
|
|
||||||
)
|
|
||||||
|
|
||||||
result_event = await self.event_creation_handler.handle_new_client_event(
|
result_event = await self.event_creation_handler.handle_new_client_event(
|
||||||
requester,
|
requester,
|
||||||
@ -835,19 +820,10 @@ class RoomMemberHandler(metaclass=abc.ABCMeta):
|
|||||||
)
|
)
|
||||||
if remote_join:
|
if remote_join:
|
||||||
if ratelimit:
|
if ratelimit:
|
||||||
time_now_s = self.clock.time()
|
await self._join_rate_limiter_remote.ratelimit(
|
||||||
(
|
|
||||||
allowed,
|
|
||||||
time_allowed,
|
|
||||||
) = await self._join_rate_limiter_remote.can_do_action(
|
|
||||||
requester,
|
requester,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not allowed:
|
|
||||||
raise LimitExceededError(
|
|
||||||
retry_after_ms=int(1000 * (time_allowed - time_now_s))
|
|
||||||
)
|
|
||||||
|
|
||||||
inviter = await self._get_inviter(target.to_string(), room_id)
|
inviter = await self._get_inviter(target.to_string(), room_id)
|
||||||
if inviter and not self.hs.is_mine(inviter):
|
if inviter and not self.hs.is_mine(inviter):
|
||||||
remote_room_hosts.append(inviter.domain)
|
remote_room_hosts.append(inviter.domain)
|
||||||
|
Loading…
Reference in New Issue
Block a user