From 7ed5acacf4eeba4e5c0fb03f0ed433c0461c968b Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 1 Sep 2016 18:08:40 +0100 Subject: Fix up the calls to the notifier for device messages --- synapse/app/synchrotron.py | 3 +++ synapse/rest/client/v2_alpha/sendtodevice.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/synapse/app/synchrotron.py b/synapse/app/synchrotron.py index b8cedc7af5..07d3d047c6 100644 --- a/synapse/app/synchrotron.py +++ b/synapse/app/synchrotron.py @@ -399,6 +399,9 @@ class SynchrotronServer(HomeServer): notify_from_stream( result, "typing", "typing_key", room="room_id" ) + notify_from_stream( + result, "to_device", "to_device_key", user="user_id" + ) while True: try: diff --git a/synapse/rest/client/v2_alpha/sendtodevice.py b/synapse/rest/client/v2_alpha/sendtodevice.py index 7c0991ca55..9c10a99acf 100644 --- a/synapse/rest/client/v2_alpha/sendtodevice.py +++ b/synapse/rest/client/v2_alpha/sendtodevice.py @@ -78,7 +78,7 @@ class SendToDeviceRestServlet(servlet.RestServlet): stream_id = yield self.store.add_messages_to_device_inbox(local_messages) self.notifier.on_new_event( - "to_device", stream_id, users=local_messages.keys() + "to_device_key", stream_id, users=local_messages.keys() ) response = (200, {}) -- cgit 1.4.1 From 2854ee2a52226df9f29acb7d8c141af2a6546d21 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 10:49:43 +0100 Subject: Only pull out IDs from DB for /state_ids/ request --- synapse/federation/federation_server.py | 10 ++++------ synapse/handlers/federation.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/synapse/federation/federation_server.py b/synapse/federation/federation_server.py index aba19639c7..5621655098 100644 --- a/synapse/federation/federation_server.py +++ b/synapse/federation/federation_server.py @@ -223,16 +223,14 @@ class FederationServer(FederationBase): if not in_room: raise AuthError(403, "Host not in room.") - pdus = yield self.handler.get_state_for_pdu( + state_ids = yield self.handler.get_state_ids_for_pdu( room_id, event_id, ) - auth_chain = yield self.store.get_auth_chain( - [pdu.event_id for pdu in pdus] - ) + auth_chain_ids = yield self.store.get_auth_chain_ids(state_ids) defer.returnValue((200, { - "pdu_ids": [pdu.event_id for pdu in pdus], - "auth_chain_ids": [pdu.event_id for pdu in auth_chain], + "pdu_ids": state_ids, + "auth_chain_ids": auth_chain_ids, })) @defer.inlineCallbacks diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 8e61d74b13..fda09b21c0 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1102,6 +1102,32 @@ class FederationHandler(BaseHandler): else: defer.returnValue([]) + @defer.inlineCallbacks + def get_state_ids_for_pdu(self, room_id, event_id): + yield run_on_reactor() + + state_groups = yield self.store.get_state_groups_ids( + room_id, [event_id] + ) + + if state_groups: + _, state = state_groups.items().pop() + results = state + + event = yield self.store.get_event(event_id) + if event and event.is_state(): + # Get previous state + if "replaces_state" in event.unsigned: + prev_id = event.unsigned["replaces_state"] + if prev_id != event.event_id: + results[(event.type, event.state_key)] = prev_id + else: + del results[(event.type, event.state_key)] + + defer.returnValue(results.values()) + else: + defer.returnValue([]) + @defer.inlineCallbacks @log_function def on_backfill_request(self, origin, room_id, pdu_list, limit): -- cgit 1.4.1 From bd9b8d87ae08e3601631e86c54e95c7f53dd3b17 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 13:40:07 +0100 Subject: Only check if host is in room if we have state and auth_chain --- synapse/handlers/federation.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 8e61d74b13..ca51044ae4 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -118,12 +118,18 @@ class FederationHandler(BaseHandler): # FIXME (erikj): Awful hack to make the case where we are not currently # in the room work - is_in_room = yield self.auth.check_host_in_room( - event.room_id, - self.server_name - ) - if not is_in_room and not event.internal_metadata.is_outlier(): - logger.debug("Got event for room we're not in.") + if state and auth_chain and not event.internal_metadata.is_outlier(): + is_in_room = yield self.auth.check_host_in_room( + event.room_id, + self.server_name + ) + else: + is_in_room = True + if not is_in_room: + logger.info( + "Got event for room we're not in: %r %r", + event.room_id, event.event_id + ) try: event_stream_id, max_stream_id = yield self._persist_auth_tree( -- cgit 1.4.1 From cce957e254149fa1123b91ab09d1cc8ff2125786 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 14:08:33 +0100 Subject: Bump max_entries on get_destination_retry_timings --- synapse/storage/transactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/storage/transactions.py b/synapse/storage/transactions.py index 1c588bd46b..5055c04b24 100644 --- a/synapse/storage/transactions.py +++ b/synapse/storage/transactions.py @@ -245,7 +245,7 @@ class TransactionStore(SQLBaseStore): return self.cursor_to_dict(txn) - @cached() + @cached(max_entries=10000) def get_destination_retry_timings(self, destination): """Gets the current retry timings (if any) for a given destination. -- cgit 1.4.1 From b96c6c3185158fb0ed429cff50b8bfec105e99df Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 14:19:22 +0100 Subject: Docstrings --- synapse/handlers/federation.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index fda09b21c0..6ca69e2fdf 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -1062,6 +1062,8 @@ class FederationHandler(BaseHandler): @defer.inlineCallbacks def get_state_for_pdu(self, room_id, event_id): + """Returns the state at the event. i.e. not including said event. + """ yield run_on_reactor() state_groups = yield self.store.get_state_groups( @@ -1104,6 +1106,8 @@ class FederationHandler(BaseHandler): @defer.inlineCallbacks def get_state_ids_for_pdu(self, room_id, event_id): + """Returns the state at the event. i.e. not including said event. + """ yield run_on_reactor() state_groups = yield self.store.get_state_groups_ids( -- cgit 1.4.1 From 34e5e17f916d50027939582f1fd9d399592ba63f Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 14:26:07 +0100 Subject: Comment --- synapse/handlers/federation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index ca51044ae4..2338c3a72b 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -118,6 +118,9 @@ class FederationHandler(BaseHandler): # FIXME (erikj): Awful hack to make the case where we are not currently # in the room work + # If state and auth_chain are None, then we don't need to do this check + # as we already know we have enough state in the DB to handle this + # event. if state and auth_chain and not event.internal_metadata.is_outlier(): is_in_room = yield self.auth.check_host_in_room( event.room_id, -- cgit 1.4.1 From f7f1027d3d5d2c8a92fbe36eccf2008d823fc2b1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 14:42:38 +0100 Subject: Comment on when auth chain and state are None --- synapse/handlers/federation.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py index 2338c3a72b..fa7ea63858 100644 --- a/synapse/handlers/federation.py +++ b/synapse/handlers/federation.py @@ -101,6 +101,9 @@ class FederationHandler(BaseHandler): def on_receive_pdu(self, origin, pdu, state=None, auth_chain=None): """ Called by the ReplicationLayer when we have a new pdu. We need to do auth checks and put it through the StateHandler. + + auth_chain and state are None if we already have the necessary state + and prev_events in the db """ event = pdu -- cgit 1.4.1 From c0238ecbed8a075fac65944294e294f3453eaf9c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 2 Sep 2016 14:53:38 +0100 Subject: Explicitly specify state_key for history_visibility fetching --- synapse/notifier.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/notifier.py b/synapse/notifier.py index b86648f5e4..48653ae843 100644 --- a/synapse/notifier.py +++ b/synapse/notifier.py @@ -423,7 +423,8 @@ class Notifier(object): def _is_world_readable(self, room_id): state = yield self.state_handler.get_current_state( room_id, - EventTypes.RoomHistoryVisibility + EventTypes.RoomHistoryVisibility, + "", ) if state and "history_visibility" in state.content: defer.returnValue(state.content["history_visibility"] == "world_readable") -- cgit 1.4.1