Merge pull request #4402 from matrix-org/erikj/fed_v2_invite_server
Implement server side of MSC1794 - Federation v2 Invite APIpull/4425/head
commit
83f335bedf
|
@ -0,0 +1 @@
|
||||||
|
Implement server support for MSC1794 - Federation v2 Invite API
|
|
@ -26,6 +26,7 @@ CLIENT_PREFIX = "/_matrix/client/api/v1"
|
||||||
CLIENT_V2_ALPHA_PREFIX = "/_matrix/client/v2_alpha"
|
CLIENT_V2_ALPHA_PREFIX = "/_matrix/client/v2_alpha"
|
||||||
FEDERATION_PREFIX = "/_matrix/federation"
|
FEDERATION_PREFIX = "/_matrix/federation"
|
||||||
FEDERATION_V1_PREFIX = FEDERATION_PREFIX + "/v1"
|
FEDERATION_V1_PREFIX = FEDERATION_PREFIX + "/v1"
|
||||||
|
FEDERATION_V2_PREFIX = FEDERATION_PREFIX + "/v2"
|
||||||
STATIC_PREFIX = "/_matrix/static"
|
STATIC_PREFIX = "/_matrix/static"
|
||||||
WEB_CLIENT_PREFIX = "/_matrix/client"
|
WEB_CLIENT_PREFIX = "/_matrix/client"
|
||||||
CONTENT_REPO_PREFIX = "/_matrix/content"
|
CONTENT_REPO_PREFIX = "/_matrix/content"
|
||||||
|
|
|
@ -369,13 +369,13 @@ class FederationServer(FederationBase):
|
||||||
})
|
})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_invite_request(self, origin, content):
|
def on_invite_request(self, origin, content, room_version):
|
||||||
pdu = event_from_pdu_json(content)
|
pdu = event_from_pdu_json(content)
|
||||||
origin_host, _ = parse_server_name(origin)
|
origin_host, _ = parse_server_name(origin)
|
||||||
yield self.check_server_matches_acl(origin_host, pdu.room_id)
|
yield self.check_server_matches_acl(origin_host, pdu.room_id)
|
||||||
ret_pdu = yield self.handler.on_invite_request(origin, pdu)
|
ret_pdu = yield self.handler.on_invite_request(origin, pdu)
|
||||||
time_now = self._clock.time_msec()
|
time_now = self._clock.time_msec()
|
||||||
defer.returnValue((200, {"event": ret_pdu.get_pdu_json(time_now)}))
|
defer.returnValue({"event": ret_pdu.get_pdu_json(time_now)})
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_send_join_request(self, origin, content):
|
def on_send_join_request(self, origin, content):
|
||||||
|
|
|
@ -21,8 +21,9 @@ import re
|
||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
|
|
||||||
import synapse
|
import synapse
|
||||||
|
from synapse.api.constants import RoomVersions
|
||||||
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
|
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
|
||||||
from synapse.api.urls import FEDERATION_V1_PREFIX
|
from synapse.api.urls import FEDERATION_V1_PREFIX, FEDERATION_V2_PREFIX
|
||||||
from synapse.http.endpoint import parse_and_validate_server_name
|
from synapse.http.endpoint import parse_and_validate_server_name
|
||||||
from synapse.http.server import JsonResource
|
from synapse.http.server import JsonResource
|
||||||
from synapse.http.servlet import (
|
from synapse.http.servlet import (
|
||||||
|
@ -490,14 +491,46 @@ class FederationSendJoinServlet(BaseFederationServlet):
|
||||||
defer.returnValue((200, content))
|
defer.returnValue((200, content))
|
||||||
|
|
||||||
|
|
||||||
class FederationInviteServlet(BaseFederationServlet):
|
class FederationV1InviteServlet(BaseFederationServlet):
|
||||||
PATH = "/invite/(?P<context>[^/]*)/(?P<event_id>[^/]*)"
|
PATH = "/invite/(?P<context>[^/]*)/(?P<event_id>[^/]*)"
|
||||||
|
|
||||||
|
@defer.inlineCallbacks
|
||||||
|
def on_PUT(self, origin, content, query, context, event_id):
|
||||||
|
# We don't get a room version, so we have to assume its EITHER v1 or
|
||||||
|
# v2. This is "fine" as the only difference between V1 and V2 is the
|
||||||
|
# state resolution algorithm, and we don't use that for processing
|
||||||
|
# invites
|
||||||
|
content = yield self.handler.on_invite_request(
|
||||||
|
origin, content, room_version=RoomVersions.V1,
|
||||||
|
)
|
||||||
|
|
||||||
|
# V1 federation API is defined to return a content of `[200, {...}]`
|
||||||
|
# due to a historical bug.
|
||||||
|
defer.returnValue((200, (200, content)))
|
||||||
|
|
||||||
|
|
||||||
|
class FederationV2InviteServlet(BaseFederationServlet):
|
||||||
|
PATH = "/invite/(?P<context>[^/]*)/(?P<event_id>[^/]*)"
|
||||||
|
|
||||||
|
PREFIX = FEDERATION_V2_PREFIX
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def on_PUT(self, origin, content, query, context, event_id):
|
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
|
||||||
content = yield self.handler.on_invite_request(origin, content)
|
|
||||||
|
room_version = content["room_version"]
|
||||||
|
event = content["event"]
|
||||||
|
invite_room_state = content["invite_room_state"]
|
||||||
|
|
||||||
|
# Synapse expects invite_room_state to be in unsigned, as it is in v1
|
||||||
|
# API
|
||||||
|
|
||||||
|
event.setdefault("unsigned", {})["invite_room_state"] = invite_room_state
|
||||||
|
|
||||||
|
content = yield self.handler.on_invite_request(
|
||||||
|
origin, event, room_version=room_version,
|
||||||
|
)
|
||||||
defer.returnValue((200, content))
|
defer.returnValue((200, content))
|
||||||
|
|
||||||
|
|
||||||
|
@ -1265,7 +1298,8 @@ FEDERATION_SERVLET_CLASSES = (
|
||||||
FederationEventServlet,
|
FederationEventServlet,
|
||||||
FederationSendJoinServlet,
|
FederationSendJoinServlet,
|
||||||
FederationSendLeaveServlet,
|
FederationSendLeaveServlet,
|
||||||
FederationInviteServlet,
|
FederationV1InviteServlet,
|
||||||
|
FederationV2InviteServlet,
|
||||||
FederationQueryAuthServlet,
|
FederationQueryAuthServlet,
|
||||||
FederationGetMissingEventsServlet,
|
FederationGetMissingEventsServlet,
|
||||||
FederationEventAuthServlet,
|
FederationEventAuthServlet,
|
||||||
|
|
Loading…
Reference in New Issue