From 8ca12a7e3ee854bc098a5141a0ee19805aa3f33c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Jan 2020 11:29:51 +0000 Subject: [PATCH 1/5] Fix POST /groups/:group/room/:room/config/:config fed API --- synapse/federation/transport/server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index d8cf9ed299f6..d53a9c9d75d0 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -971,7 +971,7 @@ async def on_POST(self, origin, content, query, group_id, room_id, config_key): if get_domain_from_id(requester_user_id) != origin: raise SynapseError(403, "requester_user_id doesn't match origin") - result = await self.groups_handler.update_room_in_group( + result = await self.handler.update_room_in_group( group_id, requester_user_id, room_id, config_key, content ) From f2c8ef8976b3905ecc633f46099dfc076c2fbc7c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Jan 2020 11:39:13 +0000 Subject: [PATCH 2/5] Fix sending server up commands from workers --- synapse/replication/tcp/client.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/synapse/replication/tcp/client.py b/synapse/replication/tcp/client.py index fc06a7b0536d..02ab5b66eab7 100644 --- a/synapse/replication/tcp/client.py +++ b/synapse/replication/tcp/client.py @@ -31,6 +31,7 @@ Command, FederationAckCommand, InvalidateCacheCommand, + RemoteServerUpCommand, RemovePusherCommand, UserIpCommand, UserSyncCommand, @@ -210,6 +211,9 @@ def send_user_ip(self, user_id, access_token, ip, user_agent, device_id, last_se cmd = UserIpCommand(user_id, access_token, ip, user_agent, device_id, last_seen) self.send_command(cmd) + def send_remote_server_up(self, server: str): + self.send_command(RemoteServerUpCommand(server)) + def await_sync(self, data): """Returns a deferred that is resolved when we receive a SYNC command with given data. From 80868afbae28e549637c2a054e8063064addfdfd Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Jan 2020 11:39:40 +0000 Subject: [PATCH 3/5] Fixup synapse.federation.transport typing --- synapse/federation/transport/client.py | 5 ++++- synapse/federation/transport/server.py | 24 ++++++++++++++---------- synapse/server.pyi | 12 +++++++++++- tox.ini | 1 + 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/synapse/federation/transport/client.py b/synapse/federation/transport/client.py index 198257414b3f..dc563538deb6 100644 --- a/synapse/federation/transport/client.py +++ b/synapse/federation/transport/client.py @@ -15,6 +15,7 @@ # limitations under the License. import logging +from typing import Any, Dict from six.moves import urllib @@ -352,7 +353,9 @@ def get_public_rooms( else: path = _create_v1_path("/publicRooms") - args = {"include_all_networks": "true" if include_all_networks else "false"} + args = { + "include_all_networks": "true" if include_all_networks else "false" + } # type: Dict[str, Any] if third_party_instance_id: args["third_party_instance_id"] = (third_party_instance_id,) if limit: diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index d53a9c9d75d0..d4c4600d7b7e 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -18,6 +18,7 @@ import functools import logging import re +from typing import Optional, Tuple, Type from twisted.internet.defer import maybeDeferred @@ -267,6 +268,8 @@ class BaseFederationServlet(object): returned. """ + PATH = "" # Overriden in subclasses, the regex to match against the path. + REQUIRE_AUTH = True PREFIX = FEDERATION_V1_PREFIX # Allows specifying the API version @@ -347,9 +350,6 @@ async def new_func(request, *args, **kwargs): return response - # Extra logic that functools.wraps() doesn't finish - new_func.__self__ = func.__self__ - return new_func def register(self, server): @@ -824,7 +824,7 @@ async def on_POST(self, origin, content, query): if not self.allow_access: raise FederationDeniedError(origin) - limit = int(content.get("limit", 100)) + limit = int(content.get("limit", 100)) # type: Optional[int] since_token = content.get("since", None) search_filter = content.get("filter", None) @@ -1422,11 +1422,13 @@ async def on_GET(self, origin, content, query, room_id): On3pidBindServlet, FederationVersionServlet, RoomComplexityServlet, -) +) # type: Tuple[Type[BaseFederationServlet], ...] -OPENID_SERVLET_CLASSES = (OpenIdUserInfo,) +OPENID_SERVLET_CLASSES = ( + OpenIdUserInfo, +) # type: Tuple[Type[BaseFederationServlet], ...] -ROOM_LIST_CLASSES = (PublicRoomList,) +ROOM_LIST_CLASSES = (PublicRoomList,) # type: Tuple[Type[PublicRoomList], ...] GROUP_SERVER_SERVLET_CLASSES = ( FederationGroupsProfileServlet, @@ -1447,17 +1449,19 @@ async def on_GET(self, origin, content, query, room_id): FederationGroupsAddRoomsServlet, FederationGroupsAddRoomsConfigServlet, FederationGroupsSettingJoinPolicyServlet, -) +) # type: Tuple[Type[BaseFederationServlet], ...] GROUP_LOCAL_SERVLET_CLASSES = ( FederationGroupsLocalInviteServlet, FederationGroupsRemoveLocalUserServlet, FederationGroupsBulkPublicisedServlet, -) +) # type: Tuple[Type[BaseFederationServlet], ...] -GROUP_ATTESTATION_SERVLET_CLASSES = (FederationGroupsRenewAttestaionServlet,) +GROUP_ATTESTATION_SERVLET_CLASSES = ( + FederationGroupsRenewAttestaionServlet, +) # type: Tuple[Type[BaseFederationServlet], ...] DEFAULT_SERVLET_GROUPS = ( "federation", diff --git a/synapse/server.pyi b/synapse/server.pyi index 07314030473a..90347ac23eb0 100644 --- a/synapse/server.pyi +++ b/synapse/server.pyi @@ -2,8 +2,8 @@ import twisted.internet import synapse.api.auth import synapse.config.homeserver +import synapse.crypto.keyring import synapse.federation.sender -import synapse.federation.transaction_queue import synapse.federation.transport.client import synapse.handlers import synapse.handlers.auth @@ -17,6 +17,7 @@ import synapse.handlers.room_member import synapse.handlers.set_password import synapse.http.client import synapse.notifier +import synapse.replication.tcp.client import synapse.rest.media.v1.media_repository import synapse.server_notices.server_notices_manager import synapse.server_notices.server_notices_sender @@ -27,6 +28,9 @@ class HomeServer(object): @property def config(self) -> synapse.config.homeserver.HomeServerConfig: pass + @property + def hostname(self) -> str: + pass def get_auth(self) -> synapse.api.auth.Auth: pass def get_auth_handler(self) -> synapse.handlers.auth.AuthHandler: @@ -97,3 +101,9 @@ class HomeServer(object): pass def get_reactor(self) -> twisted.internet.base.ReactorBase: pass + def get_keyring(self) -> synapse.crypto.keyring.Keyring: + pass + def get_tcp_replication( + self, + ) -> synapse.replication.tcp.client.ReplicationClientHandler: + pass diff --git a/tox.ini b/tox.ini index 1d946a02ba74..88ef12bebd32 100644 --- a/tox.ini +++ b/tox.ini @@ -179,6 +179,7 @@ extras = all commands = mypy \ synapse/api \ synapse/config/ \ + synapse/federation/transport \ synapse/handlers/ui_auth \ synapse/logging/ \ synapse/module_api \ From 43659a697ce84b2829b290c96b5f4b50e62ed3e3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Jan 2020 11:46:15 +0000 Subject: [PATCH 4/5] Newsfile --- changelog.d/6811.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/6811.bugfix diff --git a/changelog.d/6811.bugfix b/changelog.d/6811.bugfix new file mode 100644 index 000000000000..94d38df1c228 --- /dev/null +++ b/changelog.d/6811.bugfix @@ -0,0 +1 @@ +Fix waking waking up other servers when remote server is detected to have come back online from other workers. From 1dab1fba27a08f921128b4dfbd1434a3498eeef8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 30 Jan 2020 16:02:30 +0000 Subject: [PATCH 5/5] Fixup comments Co-Authored-By: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- changelog.d/6811.bugfix | 2 +- synapse/federation/transport/server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/changelog.d/6811.bugfix b/changelog.d/6811.bugfix index 94d38df1c228..361f2fc2e816 100644 --- a/changelog.d/6811.bugfix +++ b/changelog.d/6811.bugfix @@ -1 +1 @@ -Fix waking waking up other servers when remote server is detected to have come back online from other workers. +Fix waking up other workers when remote server is detected to have come back online. diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index d4c4600d7b7e..125eadd796ef 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -268,7 +268,7 @@ class BaseFederationServlet(object): returned. """ - PATH = "" # Overriden in subclasses, the regex to match against the path. + PATH = "" # Overridden in subclasses, the regex to match against the path. REQUIRE_AUTH = True