summary refs log tree commit diff
path: root/synapse/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/handlers')
-rw-r--r--synapse/handlers/_base.py164
-rw-r--r--synapse/handlers/federation.py19
2 files changed, 84 insertions, 99 deletions
diff --git a/synapse/handlers/_base.py b/synapse/handlers/_base.py
index 4052d0e1e7..810ce138ff 100644
--- a/synapse/handlers/_base.py
+++ b/synapse/handlers/_base.py
@@ -62,6 +62,8 @@ class BaseHandler(object):
 
     @defer.inlineCallbacks
     def _create_new_client_event(self, builder):
+        context = EventContext()
+
         latest_ret = yield self.store.get_latest_events_in_room(
             builder.room_id,
         )
@@ -69,34 +71,26 @@ class BaseHandler(object):
         depth = max([d for _, _, d in latest_ret])
         prev_events = [(e, h) for e, h, _ in latest_ret]
 
-        state_handler = self.state_handler
-        if builder.is_state():
-            ret = yield state_handler.resolve_state_groups(
-                [e for e, _ in prev_events],
-                event_type=builder.event_type,
-                state_key=builder.state_key,
-            )
+        builder.prev_events = prev_events
+        builder.depth = depth
 
-            group, curr_state, prev_state = ret
+        state_handler = self.state_handler
+        ret = yield state_handler.annotate_context_with_state(
+            builder,
+            context,
+        )
+        group, prev_state = ret
 
+        if builder.is_state():
             prev_state = yield self.store.add_event_hashes(
                 prev_state
             )
 
             builder.prev_state = prev_state
-        else:
-            group, curr_state, _ = yield state_handler.resolve_state_groups(
-                [e for e, _ in prev_events],
-            )
 
         builder.internal_metadata.state_group = group
 
-        builder.prev_events = prev_events
-        builder.depth = depth
-
-        auth_events = yield self.auth.get_auth_events(builder, curr_state)
-
-        builder.update_event_key("auth_events", auth_events)
+        yield self.auth.add_auth_events(builder, context)
 
         add_hashes_and_signatures(
             builder, self.server_name, self.signing_key
@@ -104,18 +98,6 @@ class BaseHandler(object):
 
         event = builder.build()
 
-        auth_ids = zip(*auth_events)[0]
-        curr_auth_events = {
-            k: v
-            for k, v in curr_state.items()
-            if v.event_id in auth_ids
-        }
-
-        context = EventContext(
-            current_state=curr_state,
-            auth_events=curr_auth_events,
-        )
-
         defer.returnValue(
             (event, context,)
         )
@@ -128,7 +110,7 @@ class BaseHandler(object):
         if not suppress_auth:
             self.auth.check(event, auth_events=context.auth_events)
 
-        yield self.store.persist_event(event)
+        yield self.store.persist_event(event, context=context)
 
         destinations = set(extra_destinations)
         for k, s in context.current_state.items():
@@ -152,63 +134,63 @@ class BaseHandler(object):
             destinations=destinations,
         )
 
-    @defer.inlineCallbacks
-    def _on_new_room_event(self, event, snapshot, extra_destinations=[],
-                           extra_users=[], suppress_auth=False,
-                           do_invite_host=None):
-        yield run_on_reactor()
-
-        snapshot.fill_out_prev_events(event)
-
-        yield self.state_handler.annotate_event_with_state(event)
-
-        yield self.auth.add_auth_events(event)
-
-        logger.debug("Signing event...")
-
-        add_hashes_and_signatures(
-            event, self.server_name, self.signing_key
-        )
-
-        logger.debug("Signed event.")
-
-        if not suppress_auth:
-            logger.debug("Authing...")
-            self.auth.check(event, auth_events=event.old_state_events)
-            logger.debug("Authed")
-        else:
-            logger.debug("Suppressed auth.")
-
-        if do_invite_host:
-            federation_handler = self.hs.get_handlers().federation_handler
-            invite_event = yield federation_handler.send_invite(
-                do_invite_host,
-                event
-            )
-
-            # FIXME: We need to check if the remote changed anything else
-            event.signatures = invite_event.signatures
-
-        yield self.store.persist_event(event)
-
-        destinations = set(extra_destinations)
-        # Send a PDU to all hosts who have joined the room.
-
-        for k, s in event.state_events.items():
-            try:
-                if k[0] == RoomMemberEvent.TYPE:
-                    if s.content["membership"] == Membership.JOIN:
-                        destinations.add(
-                            self.hs.parse_userid(s.state_key).domain
-                        )
-            except:
-                logger.warn(
-                    "Failed to get destination from event %s", s.event_id
-                )
-
-        event.destinations = list(destinations)
-
-        yield self.notifier.on_new_room_event(event, extra_users=extra_users)
-
-        federation_handler = self.hs.get_handlers().federation_handler
-        yield federation_handler.handle_new_event(event, snapshot)
+    # @defer.inlineCallbacks
+    # def _on_new_room_event(self, event, snapshot, extra_destinations=[],
+    #                        extra_users=[], suppress_auth=False,
+    #                        do_invite_host=None):
+    #     yield run_on_reactor()
+    #
+    #     snapshot.fill_out_prev_events(event)
+    #
+    #     yield self.state_handler.annotate_event_with_state(event)
+    #
+    #     yield self.auth.add_auth_events(event)
+    #
+    #     logger.debug("Signing event...")
+    #
+    #     add_hashes_and_signatures(
+    #         event, self.server_name, self.signing_key
+    #     )
+    #
+    #     logger.debug("Signed event.")
+    #
+    #     if not suppress_auth:
+    #         logger.debug("Authing...")
+    #         self.auth.check(event, auth_events=event.old_state_events)
+    #         logger.debug("Authed")
+    #     else:
+    #         logger.debug("Suppressed auth.")
+    #
+    #     if do_invite_host:
+    #         federation_handler = self.hs.get_handlers().federation_handler
+    #         invite_event = yield federation_handler.send_invite(
+    #             do_invite_host,
+    #             event
+    #         )
+    #
+    #         # FIXME: We need to check if the remote changed anything else
+    #         event.signatures = invite_event.signatures
+    #
+    #     yield self.store.persist_event(event)
+    #
+    #     destinations = set(extra_destinations)
+    #     # Send a PDU to all hosts who have joined the room.
+    #
+    #     for k, s in event.state_events.items():
+    #         try:
+    #             if k[0] == RoomMemberEvent.TYPE:
+    #                 if s.content["membership"] == Membership.JOIN:
+    #                     destinations.add(
+    #                         self.hs.parse_userid(s.state_key).domain
+    #                     )
+    #         except:
+    #             logger.warn(
+    #                 "Failed to get destination from event %s", s.event_id
+    #             )
+    #
+    #     event.destinations = list(destinations)
+    #
+    #     yield self.notifier.on_new_room_event(event, extra_users=extra_users)
+    #
+    #     federation_handler = self.hs.get_handlers().federation_handler
+    #     yield federation_handler.handle_new_event(event, snapshot)
diff --git a/synapse/handlers/federation.py b/synapse/handlers/federation.py
index b4a28ea3cb..5264e3eafc 100644
--- a/synapse/handlers/federation.py
+++ b/synapse/handlers/federation.py
@@ -17,7 +17,8 @@
 
 from ._base import BaseHandler
 
-from synapse.api.events.utils import prune_event
+from synapse.events.snapshot import EventContext
+from synapse.events.utils import prune_event
 from synapse.api.errors import (
     AuthError, FederationError, SynapseError, StoreError,
 )
@@ -416,7 +417,7 @@ class FederationHandler(BaseHandler):
 
     @defer.inlineCallbacks
     @log_function
-    def on_make_join_request(self, context, user_id):
+    def on_make_join_request(self, room_id, user_id):
         """ We've received a /make_join/ request, so we create a partial
         join event for the room and return that. We don *not* persist or
         process it until the other server has signed it and sent it back.
@@ -424,7 +425,7 @@ class FederationHandler(BaseHandler):
         builder = self.event_builder_factory.new({
             "type": RoomMemberEvent.TYPE,
             "content": {"membership": Membership.JOIN},
-            "room_id": context,
+            "room_id": room_id,
             "sender": user_id,
             "state_key": user_id,
         })
@@ -433,9 +434,7 @@ class FederationHandler(BaseHandler):
             builder=builder,
         )
 
-        yield self.state_handler.annotate_event_with_state(event)
-        yield self.auth.add_auth_events(event)
-        self.auth.check(event, auth_events=event.old_state_events)
+        self.auth.check(event, auth_events=context.auth_events)
 
         pdu = event
 
@@ -505,7 +504,9 @@ class FederationHandler(BaseHandler):
         """
         event = pdu
 
-        event.outlier = True
+        context = EventContext()
+
+        event.internal_metadata.outlier = True
 
         event.signatures.update(
             compute_event_signature(
@@ -515,10 +516,11 @@ class FederationHandler(BaseHandler):
             )
         )
 
-        yield self.state_handler.annotate_event_with_state(event)
+        yield self.state_handler.annotate_context_with_state(event, context)
 
         yield self.store.persist_event(
             event,
+            context=context,
             backfilled=False,
         )
 
@@ -640,6 +642,7 @@ class FederationHandler(BaseHandler):
     @defer.inlineCallbacks
     def _handle_new_event(self, event, state=None, backfilled=False,
                           current_state=None, fetch_missing=True):
+        context = EventContext()
         is_new_state = yield self.state_handler.annotate_event_with_state(
             event,
             old_state=state