Add server-side support to the v2 API

This commit is contained in:
Brendan Abolivier 2019-11-11 16:40:45 +00:00
parent 1e202a90f1
commit 74897de01f
No known key found for this signature in database
GPG Key ID: 1E015C145F1916CD
2 changed files with 33 additions and 14 deletions

View File

@ -376,15 +376,12 @@ class FederationServer(FederationBase):
res_pdus = await self.handler.on_send_join_request(origin, pdu) res_pdus = await self.handler.on_send_join_request(origin, pdu)
time_now = self._clock.time_msec() time_now = self._clock.time_msec()
return ( return {
200, "state": [p.get_pdu_json(time_now) for p in res_pdus["state"]],
{ "auth_chain": [
"state": [p.get_pdu_json(time_now) for p in res_pdus["state"]], p.get_pdu_json(time_now) for p in res_pdus["auth_chain"]
"auth_chain": [ ],
p.get_pdu_json(time_now) for p in res_pdus["auth_chain"] }
],
},
)
async def on_make_leave_request(self, origin, room_id, user_id): async def on_make_leave_request(self, origin, room_id, user_id):
origin_host, _ = parse_server_name(origin) origin_host, _ = parse_server_name(origin)
@ -411,7 +408,7 @@ class FederationServer(FederationBase):
pdu = await self._check_sigs_and_hash(room_version, pdu) pdu = await self._check_sigs_and_hash(room_version, pdu)
await self.handler.on_send_leave_request(origin, pdu) await self.handler.on_send_leave_request(origin, pdu)
return 200, {} return {}
async def on_event_auth(self, origin, room_id, event_id): async def on_event_auth(self, origin, room_id, event_id):
with (await self._server_linearizer.queue((origin, room_id))): with (await self._server_linearizer.queue((origin, room_id))):

View File

@ -506,7 +506,15 @@ class FederationMakeLeaveServlet(BaseFederationServlet):
return 200, content return 200, content
class FederationSendLeaveServlet(BaseFederationServlet): class FederationV1SendLeaveServlet(BaseFederationServlet):
PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id, event_id):
content = await self.handler.on_send_leave_request(origin, content, room_id)
return 200, (200, content)
class FederationV2SendLeaveServlet(BaseFederationServlet):
PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_leave/(?P<room_id>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, room_id, event_id): async def on_PUT(self, origin, content, query, room_id, event_id):
@ -521,9 +529,21 @@ class FederationEventAuthServlet(BaseFederationServlet):
return await self.handler.on_event_auth(origin, context, event_id) return await self.handler.on_event_auth(origin, context, event_id)
class FederationSendJoinServlet(BaseFederationServlet): class FederationV1SendJoinServlet(BaseFederationServlet):
PATH = "/send_join/(?P<context>[^/]*)/(?P<event_id>[^/]*)" PATH = "/send_join/(?P<context>[^/]*)/(?P<event_id>[^/]*)"
async def on_PUT(self, origin, content, query, context, event_id):
# TODO(paul): assert that context/event_id parsed from path actually
# match those given in content
content = await self.handler.on_send_join_request(origin, content, context)
return 200, (200, content)
class FederationV2SendJoinServlet(BaseFederationServlet):
PATH = "/send_join/(?P<context>[^/]*)/(?P<event_id>[^/]*)"
PREFIX = FEDERATION_V2_PREFIX
async def on_PUT(self, origin, content, query, context, event_id): async def on_PUT(self, origin, content, query, context, event_id):
# TODO(paul): assert that context/event_id parsed from path actually # TODO(paul): assert that context/event_id parsed from path actually
# match those given in content # match those given in content
@ -1367,8 +1387,10 @@ FEDERATION_SERVLET_CLASSES = (
FederationMakeJoinServlet, FederationMakeJoinServlet,
FederationMakeLeaveServlet, FederationMakeLeaveServlet,
FederationEventServlet, FederationEventServlet,
FederationSendJoinServlet, FederationV1SendJoinServlet,
FederationSendLeaveServlet, FederationV2SendJoinServlet,
FederationV1SendLeaveServlet,
FederationV2SendLeaveServlet,
FederationV1InviteServlet, FederationV1InviteServlet,
FederationV2InviteServlet, FederationV2InviteServlet,
FederationQueryAuthServlet, FederationQueryAuthServlet,