Skip to content

Commit

Permalink
Fix rate limiting in synapse. Handle when url doesnt have schema
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-russell committed Aug 5, 2024
1 parent 815683e commit ab6640f
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 114 deletions.
48 changes: 25 additions & 23 deletions fractal_database_matrix/controllers/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,38 @@ def init(self, url: str, *args, **kwargs):

try:
homeserver = MatrixHomeserver.create(url=url)
homeserver.config.apply()
# prompt user for credentials for their account
while True:
try:
matrix_id = input(
f"Enter your desired matrix ID (@userid:{homeserver.url}): "
)
password = getpass(f"Enter your desired password for {matrix_id}: ")

# register their account (and login)
# NOTE: Assuming that matrix is being launched locally for now
reg_controller = RegistrationController()
reg_controller.register(
matrix_id=matrix_id,
password=password,
homeserver_url=homeserver.url,
local=True,
)
break
except Exception as err:
print(f"Error registering: {err}", file=sys.stderr)
print("Try again", file=sys.stderr)
except KeyboardInterrupt:
print("Exiting...")
exit(1)
except MatrixHomeserverAlreadyExists:
print(f"A matrix homeserver with the url {url} already exists.", file=sys.stderr)
exit(1)
except Exception as err:
print(f"Error creating homeserver: {err}", file=sys.stderr)
exit(1)

homeserver.config.apply()
# prompt user for credentials for their account
while True:
try:
matrix_id = input(f"Enter your desired matrix ID (@userid:{homeserver.url}): ")
password = getpass(f"Enter your desired password for {matrix_id}: ")

# register their account (and login)
# NOTE: Assuming that matrix is being launched locally for now
reg_controller = RegistrationController()
reg_controller.register(
matrix_id=matrix_id,
password=password,
homeserver_url=homeserver.url,
local=True,
)
break
except Exception as err:
pass
except KeyboardInterrupt:
print("Exiting...")
exit(1)

# generate a registration token for the homeserver so that their devices can be registered
registration_token = reg_controller.token("create")

Expand Down
79 changes: 0 additions & 79 deletions fractal_database_matrix/migrations/0001_initial.py

This file was deleted.

5 changes: 4 additions & 1 deletion fractal_database_matrix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,12 @@ def create(cls, device: Optional["Device"] = None, **ckwargs) -> "MatrixHomeserv
if "localhost" in url.domain:
fqdn = cls.SYNAPSE_LOCAL

if not fqdn.startswith(("http://", "https://")):
fqdn = f"https://{fqdn}"

# ensure that the homeserver doesn't already exist
try:
cls.objects.get(url=url)
cls.objects.get(url=fqdn)
except cls.DoesNotExist:
pass
else:
Expand Down
31 changes: 20 additions & 11 deletions fractal_database_matrix/synapse/config/config_to_add.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ max_upload_size: 5000M

# increasing default rate limiting burst counts to avoid tests hanging for unauthenticated
# requtests to login
rc_message:
per_second: 656565
burst_count: 656565
rc_joins:
local:
per_second: 0.2
burst_count: 656565
remote:
per_second: 0.03
burst_count: 656565

rc_login:
address:
per_second: 0.15
Expand All @@ -30,3 +19,23 @@ rc_login:
rc_registration:
per_second: 0.15
burst_count: 656565
rc_message:
per_second: 656565
burst_count: 656565
rc_joins:
local:
per_second: 656565
burst_count: 656565
remote:
per_second: 0.03
burst_count: 656565
rc_invites:
per_room:
per_second: 656565
burst_count: 656565
per_user:
per_second: 656565
burst_count: 656565
per_issuer:
per_second: 656565
burst_count: 656565

0 comments on commit ab6640f

Please sign in to comment.