Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'develop' into anoa/edit_redacting
Browse files Browse the repository at this point in the history
* develop:
  Update ModuleApi to avoid register(generate_token=True) (#5640)
  Factor out some redundant code in the login impl (#5639)
  Move get_or_create_user to test code (#5628)
  Add a few more common environment directory names to black exclusion (#5630)
  Add default push rule to ignore reactions (#5623)
  Add origin_server_ts and sender fields to m.replace (#5613)
  Remove support for invite_3pid_guest. (#5625)
  remove dead transaction persist code (#5622)
  Fixes to the federation rate limiter (#5621)
  • Loading branch information
anoadragon453 committed Jul 8, 2019
2 parents 5bc5d60 + 4b1f7fe commit 6e015df
Show file tree
Hide file tree
Showing 30 changed files with 321 additions and 395 deletions.
1 change: 1 addition & 0 deletions changelog.d/5613.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `sender` and `origin_server_ts` fields to `m.replace`.
1 change: 1 addition & 0 deletions changelog.d/5621.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Various minor fixes to the federation request rate limiter.
1 change: 1 addition & 0 deletions changelog.d/5622.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove dead code for persiting outgoing federation transactions.
1 change: 1 addition & 0 deletions changelog.d/5623.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add default push rule to ignore reactions.
1 change: 1 addition & 0 deletions changelog.d/5625.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove support for the `invite_3pid_guest` configuration setting.
1 change: 1 addition & 0 deletions changelog.d/5628.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move RegistrationHandler.get_or_create_user to test code.
1 change: 1 addition & 0 deletions changelog.d/5630.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add some more common python virtual-environment paths to the black exclusion list.
1 change: 1 addition & 0 deletions changelog.d/5639.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Factor out some redundant code in the login implementation.
1 change: 1 addition & 0 deletions changelog.d/5640.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ModuleApi to avoid register(generate_token=True).
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ exclude = '''
| \.git # root of the project
| \.tox
| \.venv
| \.env
| env
| _build
| _trial_temp.*
| build
Expand Down
4 changes: 2 additions & 2 deletions synapse/config/ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, config, defaults={"per_second": 0.17, "burst_count": 3.0}):

class FederationRateLimitConfig(object):
_items_and_default = {
"window_size": 10000,
"window_size": 1000,
"sleep_limit": 10,
"sleep_delay": 500,
"reject_limit": 50,
Expand Down Expand Up @@ -54,7 +54,7 @@ def read_config(self, config, **kwargs):

# Load the new-style federation config, if it exists. Otherwise, fall
# back to the old method.
if "federation_rc" in config:
if "rc_federation" in config:
self.rc_federation = FederationRateLimitConfig(**config["rc_federation"])
else:
self.rc_federation = FederationRateLimitConfig(
Expand Down
5 changes: 2 additions & 3 deletions synapse/config/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ def read_config(self, config, **kwargs):
self.default_identity_server = config.get("default_identity_server")
self.allow_guest_access = config.get("allow_guest_access", False)

self.invite_3pid_guest = self.allow_guest_access and config.get(
"invite_3pid_guest", False
)
if config.get("invite_3pid_guest", False):
raise ConfigError("invite_3pid_guest is no longer supported")

self.auto_join_rooms = config.get("auto_join_rooms", [])
for room_alias in self.auto_join_rooms:
Expand Down
6 changes: 5 additions & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ def serialize_event(self, event, time_now, bundle_aggregations=True, **kwargs):
serialized_event["content"].pop("m.relates_to", None)

r = serialized_event["unsigned"].setdefault("m.relations", {})
r[RelationTypes.REPLACE] = {"event_id": edit.event_id}
r[RelationTypes.REPLACE] = {
"event_id": edit.event_id,
"origin_server_ts": edit.origin_server_ts,
"sender": edit.sender,
}

defer.returnValue(serialized_event)

Expand Down
32 changes: 0 additions & 32 deletions synapse/federation/persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

import logging

from twisted.internet import defer

from synapse.logging.utils import log_function

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,33 +61,3 @@ def set_response(self, origin, transaction, code, response):
return self.store.set_received_txn_response(
transaction.transaction_id, origin, code, response
)

@defer.inlineCallbacks
@log_function
def prepare_to_send(self, transaction):
""" Persists the `Transaction` we are about to send and works out the
correct value for the `prev_ids` key.
Returns:
Deferred
"""
transaction.prev_ids = yield self.store.prep_send_transaction(
transaction.transaction_id,
transaction.destination,
transaction.origin_server_ts,
)

@log_function
def delivered(self, transaction, response_code, response_dict):
""" Marks the given `Transaction` as having been successfully
delivered to the remote homeserver, and what the response was.
Returns:
Deferred
"""
return self.store.delivered_txn(
transaction.transaction_id,
transaction.destination,
response_code,
response_dict,
)
9 changes: 0 additions & 9 deletions synapse/federation/sender/transaction_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def send_new_transaction(self, destination, pending_pdus, pending_edus):
len(edus),
)

logger.debug("TX [%s] Persisting transaction...", destination)

transaction = Transaction.create_new(
origin_server_ts=int(self.clock.time_msec()),
transaction_id=txn_id,
Expand All @@ -76,9 +74,6 @@ def send_new_transaction(self, destination, pending_pdus, pending_edus):

self._next_txn_id += 1

yield self._transaction_actions.prepare_to_send(transaction)

logger.debug("TX [%s] Persisted transaction", destination)
logger.info(
"TX [%s] {%s} Sending transaction [%s]," " (PDUs: %d, EDUs: %d)",
destination,
Expand Down Expand Up @@ -118,10 +113,6 @@ def json_data_cb():

logger.info("TX [%s] {%s} got %d response", destination, txn_id, code)

yield self._transaction_actions.delivered(transaction, code, response)

logger.debug("TX [%s] {%s} Marked as delivered", destination, txn_id)

if code == 200:
for e_id, r in response.get("pdus", {}).items():
if "error" in r:
Expand Down
81 changes: 0 additions & 81 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,87 +505,6 @@ def _submit_captcha(self, ip_addr, private_key, challenge, response):
)
defer.returnValue(data)

@defer.inlineCallbacks
def get_or_create_user(self, requester, localpart, displayname, password_hash=None):
"""Creates a new user if the user does not exist,
else revokes all previous access tokens and generates a new one.
Args:
localpart : The local part of the user ID to register. If None,
one will be randomly generated.
Returns:
A tuple of (user_id, access_token).
Raises:
RegistrationError if there was a problem registering.
NB this is only used in tests. TODO: move it to the test package!
"""
if localpart is None:
raise SynapseError(400, "Request must include user id")
yield self.auth.check_auth_blocking()
need_register = True

try:
yield self.check_username(localpart)
except SynapseError as e:
if e.errcode == Codes.USER_IN_USE:
need_register = False
else:
raise

user = UserID(localpart, self.hs.hostname)
user_id = user.to_string()
token = self.macaroon_gen.generate_access_token(user_id)

if need_register:
yield self.register_with_store(
user_id=user_id,
token=token,
password_hash=password_hash,
create_profile_with_displayname=user.localpart,
)
else:
yield self._auth_handler.delete_access_tokens_for_user(user_id)
yield self.store.add_access_token_to_user(user_id=user_id, token=token)

if displayname is not None:
logger.info("setting user display name: %s -> %s", user_id, displayname)
yield self.profile_handler.set_displayname(
user, requester, displayname, by_admin=True
)

defer.returnValue((user_id, token))

@defer.inlineCallbacks
def get_or_register_3pid_guest(self, medium, address, inviter_user_id):
"""Get a guest access token for a 3PID, creating a guest account if
one doesn't already exist.
Args:
medium (str)
address (str)
inviter_user_id (str): The user ID who is trying to invite the
3PID
Returns:
Deferred[(str, str)]: A 2-tuple of `(user_id, access_token)` of the
3PID guest account.
"""
access_token = yield self.store.get_3pid_guest_access_token(medium, address)
if access_token:
user_info = yield self.auth.get_user_by_access_token(access_token)

defer.returnValue((user_info["user"].to_string(), access_token))

user_id, access_token = yield self.register(
generate_token=True, make_guest=True
)
access_token = yield self.store.save_or_get_3pid_guest_access_token(
medium, address, access_token, inviter_user_id
)

defer.returnValue((user_id, access_token))

@defer.inlineCallbacks
def _join_user_to_room(self, requester, room_identifier):
room_id = None
Expand Down
39 changes: 0 additions & 39 deletions synapse/handlers/room_member.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ def _remote_reject_invite(self, remote_room_hosts, room_id, target):
"""
raise NotImplementedError()

@abc.abstractmethod
def get_or_register_3pid_guest(self, requester, medium, address, inviter_user_id):
"""Get a guest access token for a 3PID, creating a guest account if
one doesn't already exist.
Args:
requester (Requester)
medium (str)
address (str)
inviter_user_id (str): The user ID who is trying to invite the
3PID
Returns:
Deferred[(str, str)]: A 2-tuple of `(user_id, access_token)` of the
3PID guest account.
"""
raise NotImplementedError()

@abc.abstractmethod
def _user_joined_room(self, target, room_id):
"""Notifies distributor on master process that the user has joined the
Expand Down Expand Up @@ -890,21 +872,6 @@ def _ask_id_server_for_third_party_invite(
"sender_avatar_url": inviter_avatar_url,
}

if self.config.invite_3pid_guest:
guest_user_id, guest_access_token = yield self.get_or_register_3pid_guest(
requester=requester,
medium=medium,
address=address,
inviter_user_id=inviter_user_id,
)

invite_config.update(
{
"guest_access_token": guest_access_token,
"guest_user_id": guest_user_id,
}
)

data = yield self.simple_http_client.post_urlencoded_get_json(
is_url, invite_config
)
Expand Down Expand Up @@ -1010,12 +977,6 @@ def _remote_reject_invite(self, requester, remote_room_hosts, room_id, target):
yield self.store.locally_reject_invite(target.to_string(), room_id)
defer.returnValue({})

def get_or_register_3pid_guest(self, requester, medium, address, inviter_user_id):
"""Implements RoomMemberHandler.get_or_register_3pid_guest
"""
rg = self.registration_handler
return rg.get_or_register_3pid_guest(medium, address, inviter_user_id)

def _user_joined_room(self, target, room_id):
"""Implements RoomMemberHandler._user_joined_room
"""
Expand Down
12 changes: 0 additions & 12 deletions synapse/handlers/room_member_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from synapse.api.errors import SynapseError
from synapse.handlers.room_member import RoomMemberHandler
from synapse.replication.http.membership import (
ReplicationRegister3PIDGuestRestServlet as Repl3PID,
ReplicationRemoteJoinRestServlet as ReplRemoteJoin,
ReplicationRemoteRejectInviteRestServlet as ReplRejectInvite,
ReplicationUserJoinedLeftRoomRestServlet as ReplJoinedLeft,
Expand All @@ -33,7 +32,6 @@ class RoomMemberWorkerHandler(RoomMemberHandler):
def __init__(self, hs):
super(RoomMemberWorkerHandler, self).__init__(hs)

self._get_register_3pid_client = Repl3PID.make_client(hs)
self._remote_join_client = ReplRemoteJoin.make_client(hs)
self._remote_reject_client = ReplRejectInvite.make_client(hs)
self._notify_change_client = ReplJoinedLeft.make_client(hs)
Expand Down Expand Up @@ -80,13 +78,3 @@ def _user_left_room(self, target, room_id):
return self._notify_change_client(
user_id=target.to_string(), room_id=room_id, change="left"
)

def get_or_register_3pid_guest(self, requester, medium, address, inviter_user_id):
"""Implements RoomMemberHandler.get_or_register_3pid_guest
"""
return self._get_register_3pid_client(
requester=requester,
medium=medium,
address=address,
inviter_user_id=inviter_user_id,
)
Loading

0 comments on commit 6e015df

Please sign in to comment.