mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-21 17:15:38 +03:00
Namespace all the Federation HTTP URLs to /matrix/federation/v1/...
This commit is contained in:
parent
cf965af3c5
commit
820ed34abe
3 changed files with 35 additions and 27 deletions
|
@ -116,9 +116,13 @@ federation.]]
|
||||||
Protocol URLs
|
Protocol URLs
|
||||||
=============
|
=============
|
||||||
|
|
||||||
|
All these URLs are namespaced within a prefix of
|
||||||
|
|
||||||
|
/matrix/federation/v1/...
|
||||||
|
|
||||||
For active pushing of messages representing live activity "as it happens":
|
For active pushing of messages representing live activity "as it happens":
|
||||||
|
|
||||||
PUT /send/:transaction_id/
|
PUT .../send/:transaction_id/
|
||||||
Body: JSON encoding of a single Transaction
|
Body: JSON encoding of a single Transaction
|
||||||
|
|
||||||
Response: [[TODO(paul): I don't actually understand what
|
Response: [[TODO(paul): I don't actually understand what
|
||||||
|
@ -132,7 +136,7 @@ For active pushing of messages representing live activity "as it happens":
|
||||||
|
|
||||||
To fetch a particular PDU:
|
To fetch a particular PDU:
|
||||||
|
|
||||||
GET /pdu/:origin/:pdu_id/
|
GET .../pdu/:origin/:pdu_id/
|
||||||
|
|
||||||
Response: JSON encoding of a single Transaction containing one PDU
|
Response: JSON encoding of a single Transaction containing one PDU
|
||||||
|
|
||||||
|
@ -142,7 +146,7 @@ To fetch a particular PDU:
|
||||||
|
|
||||||
To fetch all the state of a given context:
|
To fetch all the state of a given context:
|
||||||
|
|
||||||
GET /state/:context/
|
GET .../state/:context/
|
||||||
|
|
||||||
Response: JSON encoding of a single Transaction containing multiple PDUs
|
Response: JSON encoding of a single Transaction containing multiple PDUs
|
||||||
|
|
||||||
|
@ -153,7 +157,7 @@ To fetch all the state of a given context:
|
||||||
|
|
||||||
To paginate events on a given context:
|
To paginate events on a given context:
|
||||||
|
|
||||||
GET /paginate/:context/
|
GET .../paginate/:context/
|
||||||
Query args: v, limit
|
Query args: v, limit
|
||||||
|
|
||||||
Response: JSON encoding of a single Transaction containing multiple PDUs
|
Response: JSON encoding of a single Transaction containing multiple PDUs
|
||||||
|
@ -167,7 +171,7 @@ To paginate events on a given context:
|
||||||
|
|
||||||
To stream events all the events:
|
To stream events all the events:
|
||||||
|
|
||||||
GET /pull/
|
GET .../pull/
|
||||||
Query args: origin, v
|
Query args: origin, v
|
||||||
|
|
||||||
Response: JSON encoding of a single Transaction consisting of multiple PDUs
|
Response: JSON encoding of a single Transaction consisting of multiple PDUs
|
||||||
|
|
|
@ -33,6 +33,9 @@ import re
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
PREFIX = "/matrix/federation/v1"
|
||||||
|
|
||||||
|
|
||||||
class TransportLayer(object):
|
class TransportLayer(object):
|
||||||
"""This is a basic implementation of the transport layer that translates
|
"""This is a basic implementation of the transport layer that translates
|
||||||
transactions and other requests to/from HTTP.
|
transactions and other requests to/from HTTP.
|
||||||
|
@ -84,9 +87,9 @@ class TransportLayer(object):
|
||||||
logger.debug("get_context_state dest=%s, context=%s",
|
logger.debug("get_context_state dest=%s, context=%s",
|
||||||
destination, context)
|
destination, context)
|
||||||
|
|
||||||
path = "/state/%s/" % context
|
subpath = "/state/%s/" % context
|
||||||
|
|
||||||
return self._do_request_for_transaction(destination, path)
|
return self._do_request_for_transaction(destination, subpath)
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def get_pdu(self, destination, pdu_origin, pdu_id):
|
def get_pdu(self, destination, pdu_origin, pdu_id):
|
||||||
|
@ -104,9 +107,9 @@ class TransportLayer(object):
|
||||||
logger.debug("get_pdu dest=%s, pdu_origin=%s, pdu_id=%s",
|
logger.debug("get_pdu dest=%s, pdu_origin=%s, pdu_id=%s",
|
||||||
destination, pdu_origin, pdu_id)
|
destination, pdu_origin, pdu_id)
|
||||||
|
|
||||||
path = "/pdu/%s/%s/" % (pdu_origin, pdu_id)
|
subpath = "/pdu/%s/%s/" % (pdu_origin, pdu_id)
|
||||||
|
|
||||||
return self._do_request_for_transaction(destination, path)
|
return self._do_request_for_transaction(destination, subpath)
|
||||||
|
|
||||||
@log_function
|
@log_function
|
||||||
def paginate(self, dest, context, pdu_tuples, limit):
|
def paginate(self, dest, context, pdu_tuples, limit):
|
||||||
|
@ -130,14 +133,14 @@ class TransportLayer(object):
|
||||||
if not pdu_tuples:
|
if not pdu_tuples:
|
||||||
return
|
return
|
||||||
|
|
||||||
path = "/paginate/%s/" % context
|
subpath = "/paginate/%s/" % context
|
||||||
|
|
||||||
args = {"v": ["%s,%s" % (i, o) for i, o in pdu_tuples]}
|
args = {"v": ["%s,%s" % (i, o) for i, o in pdu_tuples]}
|
||||||
args["limit"] = limit
|
args["limit"] = limit
|
||||||
|
|
||||||
return self._do_request_for_transaction(
|
return self._do_request_for_transaction(
|
||||||
dest,
|
dest,
|
||||||
path,
|
subpath,
|
||||||
args=args,
|
args=args,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -166,7 +169,7 @@ class TransportLayer(object):
|
||||||
|
|
||||||
code, response = yield self.client.put_json(
|
code, response = yield self.client.put_json(
|
||||||
transaction.destination,
|
transaction.destination,
|
||||||
path="/send/%s/" % transaction.transaction_id,
|
path=PREFIX + "/send/%s/" % transaction.transaction_id,
|
||||||
data=data
|
data=data
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -189,7 +192,7 @@ class TransportLayer(object):
|
||||||
# This is when someone is trying to send us a bunch of data.
|
# This is when someone is trying to send us a bunch of data.
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"PUT",
|
"PUT",
|
||||||
re.compile("^/send/([^/]*)/$"),
|
re.compile("^" + PREFIX + "/send/([^/]*)/$"),
|
||||||
self._on_send_request
|
self._on_send_request
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -207,7 +210,7 @@ class TransportLayer(object):
|
||||||
# This is for when someone asks us for everything since version X
|
# This is for when someone asks us for everything since version X
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"GET",
|
"GET",
|
||||||
re.compile("^/pull/$"),
|
re.compile("^" + PREFIX + "/pull/$"),
|
||||||
lambda request: handler.on_pull_request(
|
lambda request: handler.on_pull_request(
|
||||||
request.args["origin"][0],
|
request.args["origin"][0],
|
||||||
request.args["v"]
|
request.args["v"]
|
||||||
|
@ -218,7 +221,7 @@ class TransportLayer(object):
|
||||||
# data_id pair.
|
# data_id pair.
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"GET",
|
"GET",
|
||||||
re.compile("^/pdu/([^/]*)/([^/]*)/$"),
|
re.compile("^" + PREFIX + "/pdu/([^/]*)/([^/]*)/$"),
|
||||||
lambda request, pdu_origin, pdu_id: handler.on_pdu_request(
|
lambda request, pdu_origin, pdu_id: handler.on_pdu_request(
|
||||||
pdu_origin, pdu_id
|
pdu_origin, pdu_id
|
||||||
)
|
)
|
||||||
|
@ -227,7 +230,7 @@ class TransportLayer(object):
|
||||||
# This is when someone asks for all data for a given context.
|
# This is when someone asks for all data for a given context.
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"GET",
|
"GET",
|
||||||
re.compile("^/state/([^/]*)/$"),
|
re.compile("^" + PREFIX + "/state/([^/]*)/$"),
|
||||||
lambda request, context: handler.on_context_state_request(
|
lambda request, context: handler.on_context_state_request(
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
|
@ -235,7 +238,7 @@ class TransportLayer(object):
|
||||||
|
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"GET",
|
"GET",
|
||||||
re.compile("^/paginate/([^/]*)/$"),
|
re.compile("^" + PREFIX + "/paginate/([^/]*)/$"),
|
||||||
lambda request, context: self._on_paginate_request(
|
lambda request, context: self._on_paginate_request(
|
||||||
context, request.args["v"],
|
context, request.args["v"],
|
||||||
request.args["limit"]
|
request.args["limit"]
|
||||||
|
@ -244,7 +247,7 @@ class TransportLayer(object):
|
||||||
|
|
||||||
self.server.register_path(
|
self.server.register_path(
|
||||||
"GET",
|
"GET",
|
||||||
re.compile("^/context/([^/]*)/$"),
|
re.compile("^" + PREFIX + "/context/([^/]*)/$"),
|
||||||
lambda request, context: handler.on_context_pdus_request(context)
|
lambda request, context: handler.on_context_pdus_request(context)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -300,7 +303,7 @@ class TransportLayer(object):
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
@log_function
|
@log_function
|
||||||
def _do_request_for_transaction(self, destination, path, args={}):
|
def _do_request_for_transaction(self, destination, subpath, args={}):
|
||||||
"""
|
"""
|
||||||
Args:
|
Args:
|
||||||
destination (str)
|
destination (str)
|
||||||
|
@ -313,7 +316,7 @@ class TransportLayer(object):
|
||||||
|
|
||||||
data = yield self.client.get_json(
|
data = yield self.client.get_json(
|
||||||
destination,
|
destination,
|
||||||
path=path,
|
path=PREFIX + subpath,
|
||||||
args=args,
|
args=args,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# Empty context initially
|
# Empty context initially
|
||||||
(code, response) = yield self.mock_http_server.trigger("GET",
|
(code, response) = yield self.mock_http_server.trigger("GET",
|
||||||
"/state/my-context/", None)
|
"/matrix/federation/v1/state/my-context/", None)
|
||||||
self.assertEquals(200, code)
|
self.assertEquals(200, code)
|
||||||
self.assertFalse(response["pdus"])
|
self.assertFalse(response["pdus"])
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
(code, response) = yield self.mock_http_server.trigger("GET",
|
(code, response) = yield self.mock_http_server.trigger("GET",
|
||||||
"/state/my-context/", None)
|
"/matrix/federation/v1/state/my-context/", None)
|
||||||
self.assertEquals(200, code)
|
self.assertEquals(200, code)
|
||||||
self.assertEquals(1, len(response["pdus"]))
|
self.assertEquals(1, len(response["pdus"]))
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
(code, response) = yield self.mock_http_server.trigger("GET",
|
(code, response) = yield self.mock_http_server.trigger("GET",
|
||||||
"/pdu/red/abc123def456/", None)
|
"/matrix/federation/v1/pdu/red/abc123def456/", None)
|
||||||
self.assertEquals(404, code)
|
self.assertEquals(404, code)
|
||||||
|
|
||||||
# Now insert such a PDU
|
# Now insert such a PDU
|
||||||
|
@ -151,7 +151,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
(code, response) = yield self.mock_http_server.trigger("GET",
|
(code, response) = yield self.mock_http_server.trigger("GET",
|
||||||
"/pdu/red/abc123def456/", None)
|
"/matrix/federation/v1/pdu/red/abc123def456/", None)
|
||||||
self.assertEquals(200, code)
|
self.assertEquals(200, code)
|
||||||
self.assertEquals(1, len(response["pdus"]))
|
self.assertEquals(1, len(response["pdus"]))
|
||||||
self.assertEquals("m.text", response["pdus"][0]["pdu_type"])
|
self.assertEquals("m.text", response["pdus"][0]["pdu_type"])
|
||||||
|
@ -177,7 +177,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.mock_http_client.put_json.assert_called_with(
|
self.mock_http_client.put_json.assert_called_with(
|
||||||
"remote",
|
"remote",
|
||||||
path="/send/1000000/",
|
path="/matrix/federation/v1/send/1000000/",
|
||||||
data={
|
data={
|
||||||
"ts": 1000000,
|
"ts": 1000000,
|
||||||
"origin": "test",
|
"origin": "test",
|
||||||
|
@ -212,7 +212,7 @@ class FederationTestCase(unittest.TestCase):
|
||||||
# MockClock ensures we can guess these timestamps
|
# MockClock ensures we can guess these timestamps
|
||||||
self.mock_http_client.put_json.assert_called_with(
|
self.mock_http_client.put_json.assert_called_with(
|
||||||
"remote",
|
"remote",
|
||||||
path="/send/1000000/",
|
path="/matrix/federation/v1/send/1000000/",
|
||||||
data={
|
data={
|
||||||
"origin": "test",
|
"origin": "test",
|
||||||
"ts": 1000000,
|
"ts": 1000000,
|
||||||
|
@ -234,7 +234,8 @@ class FederationTestCase(unittest.TestCase):
|
||||||
|
|
||||||
self.federation.register_edu_handler("m.test", recv_observer)
|
self.federation.register_edu_handler("m.test", recv_observer)
|
||||||
|
|
||||||
yield self.mock_http_server.trigger("PUT", "/send/1001000/",
|
yield self.mock_http_server.trigger("PUT",
|
||||||
|
"/matrix/federation/v1/send/1001000/",
|
||||||
"""{
|
"""{
|
||||||
"origin": "remote",
|
"origin": "remote",
|
||||||
"ts": 1001000,
|
"ts": 1001000,
|
||||||
|
|
Loading…
Reference in a new issue