Exemple #1
0
    async def _handle_request(self, request):
        with Measure(self.clock, "repl_fed_send_events_parse"):
            content = parse_json_object_from_request(request)

            backfilled = content["backfilled"]

            event_payloads = content["events"]

            event_and_contexts = []
            for event_payload in event_payloads:
                event_dict = event_payload["event"]
                format_ver = event_payload["event_format_version"]
                internal_metadata = event_payload["internal_metadata"]
                rejected_reason = event_payload["rejected_reason"]

                EventType = event_type_from_format_version(format_ver)
                event = EventType(event_dict, internal_metadata,
                                  rejected_reason)

                context = EventContext.deserialize(self.storage,
                                                   event_payload["context"])

                event_and_contexts.append((event, context))

        logger.info("Got %d events from federation", len(event_and_contexts))

        await self.federation_handler.persist_events_and_notify(
            event_and_contexts, backfilled)

        return 200, {}
Exemple #2
0
    async def _handle_request(self, request):
        with Measure(self.clock, "repl_fed_send_events_parse"):
            content = parse_json_object_from_request(request)

            room_id = content["room_id"]
            backfilled = content["backfilled"]

            event_payloads = content["events"]

            event_and_contexts = []
            for event_payload in event_payloads:
                event_dict = event_payload["event"]
                room_ver = KNOWN_ROOM_VERSIONS[event_payload["room_version"]]
                internal_metadata = event_payload["internal_metadata"]
                rejected_reason = event_payload["rejected_reason"]

                event = make_event_from_dict(event_dict, room_ver,
                                             internal_metadata,
                                             rejected_reason)

                context = EventContext.deserialize(self.storage,
                                                   event_payload["context"])

                event_and_contexts.append((event, context))

        logger.info("Got %d events from federation", len(event_and_contexts))

        max_stream_id = await self.federation_handler.persist_events_and_notify(
            room_id, event_and_contexts, backfilled)

        return 200, {"max_stream_id": max_stream_id}
    def _handle_request(self, request, event_id):
        with Measure(self.clock, "repl_send_event_parse"):
            content = parse_json_object_from_request(request)

            event_dict = content["event"]
            internal_metadata = content["internal_metadata"]
            rejected_reason = content["rejected_reason"]
            event = FrozenEvent(event_dict, internal_metadata, rejected_reason)

            requester = Requester.deserialize(self.store, content["requester"])
            context = yield EventContext.deserialize(self.store, content["context"])

            ratelimit = content["ratelimit"]
            extra_users = [UserID.from_string(u) for u in content["extra_users"]]

        if requester.user:
            request.authenticated_entity = requester.user.to_string()

        logger.info(
            "Got event to send with ID: %s into room: %s",
            event.event_id, event.room_id,
        )

        yield self.event_creation_handler.persist_and_notify_client_event(
            requester, event, context,
            ratelimit=ratelimit,
            extra_users=extra_users,
        )

        defer.returnValue((200, {}))
    async def _handle_request(self, request, event_id):
        with Measure(self.clock, "repl_send_event_parse"):
            content = parse_json_object_from_request(request)

            event_dict = content["event"]
            room_ver = KNOWN_ROOM_VERSIONS[content["room_version"]]
            internal_metadata = content["internal_metadata"]
            rejected_reason = content["rejected_reason"]

            event = make_event_from_dict(event_dict, room_ver,
                                         internal_metadata, rejected_reason)

            requester = Requester.deserialize(self.store, content["requester"])
            context = EventContext.deserialize(self.storage,
                                               content["context"])

            ratelimit = content["ratelimit"]
            extra_users = [
                UserID.from_string(u) for u in content["extra_users"]
            ]

        if requester.user:
            request.authenticated_entity = requester.user.to_string()

        logger.info("Got event to send with ID: %s into room: %s",
                    event.event_id, event.room_id)

        stream_id = await self.event_creation_handler.persist_and_notify_client_event(
            requester,
            event,
            context,
            ratelimit=ratelimit,
            extra_users=extra_users)

        return 200, {"stream_id": stream_id}
    def _handle_request(self, request):
        with Measure(self.clock, "repl_fed_send_events_parse"):
            content = parse_json_object_from_request(request)

            backfilled = content["backfilled"]

            event_payloads = content["events"]

            event_and_contexts = []
            for event_payload in event_payloads:
                event_dict = event_payload["event"]
                internal_metadata = event_payload["internal_metadata"]
                rejected_reason = event_payload["rejected_reason"]
                event = FrozenEvent(event_dict, internal_metadata,
                                    rejected_reason)

                context = yield EventContext.deserialize(
                    self.store,
                    event_payload["context"],
                )

                event_and_contexts.append((event, context))

        logger.info(
            "Got %d events from federation",
            len(event_and_contexts),
        )

        yield self.federation_handler.persist_events_and_notify(
            event_and_contexts,
            backfilled,
        )

        defer.returnValue((200, {}))
Exemple #6
0
    def _check_serialize_deserialize(self, event, context):
        serialized = self.get_success(context.serialize(event, self.store))

        d_context = EventContext.deserialize(self.storage, serialized)

        self.assertEqual(context.state_group, d_context.state_group)
        self.assertEqual(context.rejected, d_context.rejected)
        self.assertEqual(context.state_group_before_event,
                         d_context.state_group_before_event)
        self.assertEqual(context.prev_group, d_context.prev_group)
        self.assertEqual(context.delta_ids, d_context.delta_ids)
        self.assertEqual(context.app_service, d_context.app_service)

        self.assertEqual(
            self.get_success(context.get_current_state_ids()),
            self.get_success(d_context.get_current_state_ids()),
        )
        self.assertEqual(
            self.get_success(context.get_prev_state_ids()),
            self.get_success(d_context.get_prev_state_ids()),
        )
Exemple #7
0
    async def _handle_request(  # type: ignore[override]
            self, request: Request, event_id: str) -> Tuple[int, JsonDict]:
        with Measure(self.clock, "repl_send_event_parse"):
            content = parse_json_object_from_request(request)

            event_dict = content["event"]
            room_ver = KNOWN_ROOM_VERSIONS[content["room_version"]]
            internal_metadata = content["internal_metadata"]
            rejected_reason = content["rejected_reason"]

            event = make_event_from_dict(event_dict, room_ver,
                                         internal_metadata, rejected_reason)
            event.internal_metadata.outlier = content["outlier"]

            requester = Requester.deserialize(self.store, content["requester"])
            context = EventContext.deserialize(self._storage_controllers,
                                               content["context"])

            ratelimit = content["ratelimit"]
            extra_users = [
                UserID.from_string(u) for u in content["extra_users"]
            ]

        logger.info("Got event to send with ID: %s into room: %s",
                    event.event_id, event.room_id)

        event = await self.event_creation_handler.persist_and_notify_client_event(
            requester,
            event,
            context,
            ratelimit=ratelimit,
            extra_users=extra_users)

        return (
            200,
            {
                "stream_id": event.internal_metadata.stream_ordering,
                "event_id": event.event_id,
            },
        )