mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-12 00:44:19 -05:00
Address review comments
This commit is contained in:
parent
d2f6a67cb4
commit
1fe3cc2c9c
@ -24,7 +24,6 @@ from synapse.api.errors import (
|
|||||||
AuthError,
|
AuthError,
|
||||||
Codes,
|
Codes,
|
||||||
ConsentNotGivenError,
|
ConsentNotGivenError,
|
||||||
LimitExceededError,
|
|
||||||
RegistrationError,
|
RegistrationError,
|
||||||
SynapseError,
|
SynapseError,
|
||||||
)
|
)
|
||||||
@ -218,8 +217,8 @@ class RegistrationHandler(BaseHandler):
|
|||||||
|
|
||||||
else:
|
else:
|
||||||
# autogen a sequential user ID
|
# autogen a sequential user ID
|
||||||
user = None
|
# Fail after being unable to find a suitable ID a few times
|
||||||
while not user:
|
for x in range(10):
|
||||||
localpart = yield self._generate_user_id()
|
localpart = yield self._generate_user_id()
|
||||||
user = UserID(localpart, self.hs.hostname)
|
user = UserID(localpart, self.hs.hostname)
|
||||||
user_id = user.to_string()
|
user_id = user.to_string()
|
||||||
@ -234,10 +233,12 @@ class RegistrationHandler(BaseHandler):
|
|||||||
create_profile_with_displayname=default_display_name,
|
create_profile_with_displayname=default_display_name,
|
||||||
address=address,
|
address=address,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Successfully registered
|
||||||
|
break
|
||||||
except SynapseError:
|
except SynapseError:
|
||||||
# if user id is taken, just generate another
|
# if user id is taken, just generate another
|
||||||
user = None
|
pass
|
||||||
user_id = None
|
|
||||||
|
|
||||||
if not self.hs.config.user_consent_at_registration:
|
if not self.hs.config.user_consent_at_registration:
|
||||||
yield self._auto_join_rooms(user_id)
|
yield self._auto_join_rooms(user_id)
|
||||||
@ -420,25 +421,24 @@ class RegistrationHandler(BaseHandler):
|
|||||||
for a given IP address
|
for a given IP address
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
address (str): the IP address used to perform the registration.
|
address (str|None): the IP address used to perform the registration. If this is
|
||||||
|
None, no ratelimiting will be performed.
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
LimitExceededError: If the rate limit has been exceeded.
|
LimitExceededError: If the rate limit has been exceeded.
|
||||||
"""
|
"""
|
||||||
|
if not address:
|
||||||
|
return
|
||||||
|
|
||||||
time_now = self.clock.time()
|
time_now = self.clock.time()
|
||||||
|
|
||||||
allowed, time_allowed = self.ratelimiter.can_do_action(
|
self.ratelimiter.ratelimit(
|
||||||
address,
|
address,
|
||||||
time_now_s=time_now,
|
time_now_s=time_now,
|
||||||
rate_hz=self.hs.config.rc_registration.per_second,
|
rate_hz=self.hs.config.rc_registration.per_second,
|
||||||
burst_count=self.hs.config.rc_registration.burst_count,
|
burst_count=self.hs.config.rc_registration.burst_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
if not allowed:
|
|
||||||
raise LimitExceededError(
|
|
||||||
retry_after_ms=int(1000 * (time_allowed - time_now))
|
|
||||||
)
|
|
||||||
|
|
||||||
def register_with_store(
|
def register_with_store(
|
||||||
self,
|
self,
|
||||||
user_id,
|
user_id,
|
||||||
|
@ -75,7 +75,7 @@ class ReplicationRegisterServlet(ReplicationEndpoint):
|
|||||||
async def _handle_request(self, request, user_id):
|
async def _handle_request(self, request, user_id):
|
||||||
content = parse_json_object_from_request(request)
|
content = parse_json_object_from_request(request)
|
||||||
|
|
||||||
await self.registration_handler.check_registration_ratelimit(content["address"])
|
self.registration_handler.check_registration_ratelimit(content["address"])
|
||||||
|
|
||||||
await self.registration_handler.register_with_store(
|
await self.registration_handler.register_with_store(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user