mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-27 12:08:32 +03:00
Switch from matrix://
to matrix-federation://
scheme for internal Synapse routing of outbound federation traffic (#15806)
`matrix://` is a registered specced scheme nowadays and doesn't make sense for our internal to Synapse use case anymore. ([discussion] (https://github.com/matrix-org/synapse/pull/15773#discussion_r1227598679))
This commit is contained in:
parent
4ba528d9c3
commit
887fa4b66b
7 changed files with 43 additions and 29 deletions
1
changelog.d/15806.misc
Normal file
1
changelog.d/15806.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Switch from `matrix://` to `matrix-federation://` scheme for internal Synapse routing of outbound federation traffic.
|
|
@ -29,7 +29,7 @@
|
||||||
"level": "error"
|
"level": "error"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"line": "my-matrix-server-federation-sender-1 | 2023-01-25 20:56:20,995 - synapse.http.matrixfederationclient - 709 - WARNING - federation_transaction_transmission_loop-3 - {PUT-O-3} [example.com] Request failed: PUT matrix://example.com/_matrix/federation/v1/send/1674680155797: HttpResponseException('403: Forbidden')",
|
"line": "my-matrix-server-federation-sender-1 | 2023-01-25 20:56:20,995 - synapse.http.matrixfederationclient - 709 - WARNING - federation_transaction_transmission_loop-3 - {PUT-O-3} [example.com] Request failed: PUT matrix-federation://example.com/_matrix/federation/v1/send/1674680155797: HttpResponseException('403: Forbidden')",
|
||||||
"level": "warning"
|
"level": "warning"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
@ -136,11 +136,11 @@ def request(
|
||||||
authorization_headers.append(header)
|
authorization_headers.append(header)
|
||||||
print("Authorization: %s" % header, file=sys.stderr)
|
print("Authorization: %s" % header, file=sys.stderr)
|
||||||
|
|
||||||
dest = "matrix://%s%s" % (destination, path)
|
dest = "matrix-federation://%s%s" % (destination, path)
|
||||||
print("Requesting %s" % dest, file=sys.stderr)
|
print("Requesting %s" % dest, file=sys.stderr)
|
||||||
|
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s.mount("matrix://", MatrixConnectionAdapter())
|
s.mount("matrix-federation://", MatrixConnectionAdapter())
|
||||||
|
|
||||||
headers: Dict[str, str] = {
|
headers: Dict[str, str] = {
|
||||||
"Authorization": authorization_headers[0],
|
"Authorization": authorization_headers[0],
|
||||||
|
|
|
@ -51,8 +51,10 @@ logger = logging.getLogger(__name__)
|
||||||
@implementer(IAgent)
|
@implementer(IAgent)
|
||||||
class MatrixFederationAgent:
|
class MatrixFederationAgent:
|
||||||
"""An Agent-like thing which provides a `request` method which correctly
|
"""An Agent-like thing which provides a `request` method which correctly
|
||||||
handles resolving matrix server names when using matrix://. Handles standard
|
handles resolving matrix server names when using `matrix-federation://`. Handles
|
||||||
https URIs as normal.
|
standard https URIs as normal. The `matrix-federation://` scheme is internal to
|
||||||
|
Synapse and we purposely want to avoid colliding with the `matrix://` URL scheme
|
||||||
|
which is now specced.
|
||||||
|
|
||||||
Doesn't implement any retries. (Those are done in MatrixFederationHttpClient.)
|
Doesn't implement any retries. (Those are done in MatrixFederationHttpClient.)
|
||||||
|
|
||||||
|
@ -167,14 +169,14 @@ class MatrixFederationAgent:
|
||||||
# There must be a valid hostname.
|
# There must be a valid hostname.
|
||||||
assert parsed_uri.hostname
|
assert parsed_uri.hostname
|
||||||
|
|
||||||
# If this is a matrix:// URI check if the server has delegated matrix
|
# If this is a matrix-federation:// URI check if the server has delegated matrix
|
||||||
# traffic using well-known delegation.
|
# traffic using well-known delegation.
|
||||||
#
|
#
|
||||||
# We have to do this here and not in the endpoint as we need to rewrite
|
# We have to do this here and not in the endpoint as we need to rewrite
|
||||||
# the host header with the delegated server name.
|
# the host header with the delegated server name.
|
||||||
delegated_server = None
|
delegated_server = None
|
||||||
if (
|
if (
|
||||||
parsed_uri.scheme == b"matrix"
|
parsed_uri.scheme == b"matrix-federation"
|
||||||
and not _is_ip_literal(parsed_uri.hostname)
|
and not _is_ip_literal(parsed_uri.hostname)
|
||||||
and not parsed_uri.port
|
and not parsed_uri.port
|
||||||
):
|
):
|
||||||
|
@ -250,7 +252,7 @@ class MatrixHostnameEndpointFactory:
|
||||||
|
|
||||||
@implementer(IStreamClientEndpoint)
|
@implementer(IStreamClientEndpoint)
|
||||||
class MatrixHostnameEndpoint:
|
class MatrixHostnameEndpoint:
|
||||||
"""An endpoint that resolves matrix:// URLs using Matrix server name
|
"""An endpoint that resolves matrix-federation:// URLs using Matrix server name
|
||||||
resolution (i.e. via SRV). Does not check for well-known delegation.
|
resolution (i.e. via SRV). Does not check for well-known delegation.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
|
@ -379,7 +381,7 @@ class MatrixHostnameEndpoint:
|
||||||
connect to.
|
connect to.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self._parsed_uri.scheme != b"matrix":
|
if self._parsed_uri.scheme != b"matrix-federation":
|
||||||
return [Server(host=self._parsed_uri.host, port=self._parsed_uri.port)]
|
return [Server(host=self._parsed_uri.host, port=self._parsed_uri.port)]
|
||||||
|
|
||||||
# Note: We don't do well-known lookup as that needs to have happened
|
# Note: We don't do well-known lookup as that needs to have happened
|
||||||
|
|
|
@ -174,7 +174,14 @@ class MatrixFederationRequest:
|
||||||
|
|
||||||
# The object is frozen so we can pre-compute this.
|
# The object is frozen so we can pre-compute this.
|
||||||
uri = urllib.parse.urlunparse(
|
uri = urllib.parse.urlunparse(
|
||||||
(b"matrix", destination_bytes, path_bytes, None, query_bytes, b"")
|
(
|
||||||
|
b"matrix-federation",
|
||||||
|
destination_bytes,
|
||||||
|
path_bytes,
|
||||||
|
None,
|
||||||
|
query_bytes,
|
||||||
|
b"",
|
||||||
|
)
|
||||||
)
|
)
|
||||||
object.__setattr__(self, "uri", uri)
|
object.__setattr__(self, "uri", uri)
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,7 @@ class FederationClientTest(FederatingHomeserverTestCase):
|
||||||
# check the right call got made to the agent
|
# check the right call got made to the agent
|
||||||
self._mock_agent.request.assert_called_once_with(
|
self._mock_agent.request.assert_called_once_with(
|
||||||
b"GET",
|
b"GET",
|
||||||
b"matrix://yet.another.server/_matrix/federation/v1/state/%21room_id?event_id=event_id",
|
b"matrix-federation://yet.another.server/_matrix/federation/v1/state/%21room_id?event_id=event_id",
|
||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
bodyProducer=None,
|
bodyProducer=None,
|
||||||
)
|
)
|
||||||
|
@ -232,7 +232,7 @@ class FederationClientTest(FederatingHomeserverTestCase):
|
||||||
# check the right call got made to the agent
|
# check the right call got made to the agent
|
||||||
self._mock_agent.request.assert_called_once_with(
|
self._mock_agent.request.assert_called_once_with(
|
||||||
b"GET",
|
b"GET",
|
||||||
b"matrix://yet.another.server/_matrix/federation/v1/event/event_id",
|
b"matrix-federation://yet.another.server/_matrix/federation/v1/event/event_id",
|
||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
bodyProducer=None,
|
bodyProducer=None,
|
||||||
)
|
)
|
||||||
|
|
|
@ -292,7 +292,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.agent = self._make_agent()
|
self.agent = self._make_agent()
|
||||||
|
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
test_d = self._make_get_request(b"matrix://testserv:8448/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv:8448/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -393,7 +393,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
|
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
self.reactor.lookups["proxy.com"] = "9.9.9.9"
|
self.reactor.lookups["proxy.com"] = "9.9.9.9"
|
||||||
test_d = self._make_get_request(b"matrix://testserv:8448/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv:8448/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -532,7 +532,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
# there will be a getaddrinfo on the IP
|
# there will be a getaddrinfo on the IP
|
||||||
self.reactor.lookups["1.2.3.4"] = "1.2.3.4"
|
self.reactor.lookups["1.2.3.4"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://1.2.3.4/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://1.2.3.4/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -568,7 +568,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
# there will be a getaddrinfo on the IP
|
# there will be a getaddrinfo on the IP
|
||||||
self.reactor.lookups["::1"] = "::1"
|
self.reactor.lookups["::1"] = "::1"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://[::1]/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://[::1]/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -604,7 +604,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
# there will be a getaddrinfo on the IP
|
# there will be a getaddrinfo on the IP
|
||||||
self.reactor.lookups["::1"] = "::1"
|
self.reactor.lookups["::1"] = "::1"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://[::1]:80/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://[::1]:80/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -639,7 +639,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
||||||
self.reactor.lookups["testserv1"] = "1.2.3.4"
|
self.reactor.lookups["testserv1"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv1/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv1/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -693,7 +693,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
# there will be a getaddrinfo on the IP
|
# there will be a getaddrinfo on the IP
|
||||||
self.reactor.lookups["1.2.3.5"] = "1.2.3.5"
|
self.reactor.lookups["1.2.3.5"] = "1.2.3.5"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://1.2.3.5/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://1.2.3.5/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -725,7 +725,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -780,7 +780,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
self.reactor.lookups["target-server"] = "1::f"
|
self.reactor.lookups["target-server"] = "1::f"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -844,7 +844,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
self.reactor.lookups["target-server"] = "1::f"
|
self.reactor.lookups["target-server"] = "1::f"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -933,7 +933,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
self.mock_resolver.resolve_service.side_effect = generate_resolve_service([])
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1009,7 +1009,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
test_d = agent.request(b"GET", b"matrix://testserv/foo/bar")
|
test_d = agent.request(b"GET", b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1042,7 +1042,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.reactor.lookups["srvtarget"] = "1.2.3.4"
|
self.reactor.lookups["srvtarget"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1082,7 +1082,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.reactor.lookups["testserv"] = "1.2.3.4"
|
self.reactor.lookups["testserv"] = "1.2.3.4"
|
||||||
self.reactor.lookups["srvtarget"] = "5.6.7.8"
|
self.reactor.lookups["srvtarget"] = "5.6.7.8"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1143,7 +1143,9 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
self.reactor.lookups["xn--bcher-kva.com"] = "1.2.3.4"
|
self.reactor.lookups["xn--bcher-kva.com"] = "1.2.3.4"
|
||||||
|
|
||||||
# this is idna for bücher.com
|
# this is idna for bücher.com
|
||||||
test_d = self._make_get_request(b"matrix://xn--bcher-kva.com/foo/bar")
|
test_d = self._make_get_request(
|
||||||
|
b"matrix-federation://xn--bcher-kva.com/foo/bar"
|
||||||
|
)
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1204,7 +1206,9 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.reactor.lookups["xn--trget-3qa.com"] = "1.2.3.4"
|
self.reactor.lookups["xn--trget-3qa.com"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://xn--bcher-kva.com/foo/bar")
|
test_d = self._make_get_request(
|
||||||
|
b"matrix-federation://xn--bcher-kva.com/foo/bar"
|
||||||
|
)
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
@ -1411,7 +1415,7 @@ class MatrixFederationAgentTests(unittest.TestCase):
|
||||||
)
|
)
|
||||||
self.reactor.lookups["target.com"] = "1.2.3.4"
|
self.reactor.lookups["target.com"] = "1.2.3.4"
|
||||||
|
|
||||||
test_d = self._make_get_request(b"matrix://testserv/foo/bar")
|
test_d = self._make_get_request(b"matrix-federation://testserv/foo/bar")
|
||||||
|
|
||||||
# Nothing happened yet
|
# Nothing happened yet
|
||||||
self.assertNoResult(test_d)
|
self.assertNoResult(test_d)
|
||||||
|
|
Loading…
Reference in a new issue