Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release-v1.13.0' into erikj/faster_device_lists_fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed May 5, 2020
2 parents 714560e + fe69fb6 commit 13dd458
Show file tree
Hide file tree
Showing 66 changed files with 847 additions and 691 deletions.
11 changes: 6 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,24 @@ recursive-include synapse/static *.gif
recursive-include synapse/static *.html
recursive-include synapse/static *.js

exclude Dockerfile
exclude .codecov.yml
exclude .coveragerc
exclude .dockerignore
exclude test_postgresql.sh
exclude .editorconfig
exclude Dockerfile
exclude mypy.ini
exclude sytest-blacklist
exclude test_postgresql.sh

include pyproject.toml
recursive-include changelog.d *

prune .buildkite
prune .circleci
prune .codecov.yml
prune .coveragerc
prune .github
prune contrib
prune debian
prune demo/etc
prune docker
prune mypy.ini
prune snap
prune stubs
31 changes: 31 additions & 0 deletions UPGRADE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,37 @@ for example:
wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb
dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb
Upgrading to v1.13.0
====================

Incorrect database migration in old synapse versions
----------------------------------------------------

A bug was introduced in Synapse 1.4.0 which could cause the room directory to
be incomplete or empty if Synapse was upgraded directly from v1.2.1 or earlier,
to versions between v1.4.0 and v1.12.x.

This will *not* be a problem for Synapse installations which were:
* created at v1.4.0 or later,
* upgraded via v1.3.x, or
* upgraded straight from v1.2.1 or earlier to v1.13.0 or later.

If completeness of the room directory is a concern, installations which are
affected can be repaired as follows:

1. Run the following sql from a `psql` or `sqlite3` console:

.. code:: sql
INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
('populate_stats_process_rooms', '{}', 'current_state_events_membership');
INSERT INTO background_updates (update_name, progress_json, depends_on) VALUES
('populate_stats_process_users', '{}', 'populate_stats_process_rooms');
2. Restart synapse.


Upgrading to v1.12.0
====================

Expand Down
1 change: 1 addition & 0 deletions changelog.d/7172.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use `stream.current_token()` and remove `stream_positions()`.
1 change: 1 addition & 0 deletions changelog.d/7363.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert RegistrationWorkerStore.is_server_admin and dependent code to async/await.
1 change: 1 addition & 0 deletions changelog.d/7368.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error responses when accessing remote public room lists.
1 change: 1 addition & 0 deletions changelog.d/7369.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Thread through instance name to replication client.
1 change: 1 addition & 0 deletions changelog.d/7387.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which would cause the room durectory to be incorrectly populated if Synapse was upgraded directly from v1.2.1 or earlier to v1.4.0 or later. Note that this fix does not apply retrospectively; see the [upgrade notes](UPGRADE.rst#upgrading-to-v1130) for more information.
1 change: 1 addition & 0 deletions changelog.d/7393.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in `EventContext.deserialize`.
1 change: 1 addition & 0 deletions changelog.d/7394.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert synapse.server_notices to async/await.
1 change: 1 addition & 0 deletions changelog.d/7395.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Convert synapse.notifier to async/await.
1 change: 1 addition & 0 deletions changelog.d/7401.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for running replication over Redis when using workers.
1 change: 1 addition & 0 deletions changelog.d/7404.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix issues with the Python package manifest.
1 change: 1 addition & 0 deletions changelog.d/7408.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Clean up some LoggingContext code.
3 changes: 3 additions & 0 deletions stubs/txredisapi.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class RedisProtocol:
def publish(self, channel: str, message: bytes): ...

class SubscriberProtocol:
password: Optional[str]
def subscribe(self, channels: Union[str, List[str]]): ...
def connectionMade(self): ...
def connectionLost(self, reason): ...

def lazyConnection(
host: str = ...,
Expand Down
9 changes: 4 additions & 5 deletions synapse/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ def compute_auth_events(

return defer.succeed(auth_ids)

@defer.inlineCallbacks
def check_can_change_room_list(self, room_id: str, user: UserID):
async def check_can_change_room_list(self, room_id: str, user: UserID):
"""Determine whether the user is allowed to edit the room's entry in the
published room list.
Expand All @@ -547,17 +546,17 @@ def check_can_change_room_list(self, room_id: str, user: UserID):
user
"""

is_admin = yield self.is_server_admin(user)
is_admin = await self.is_server_admin(user)
if is_admin:
return True

user_id = user.to_string()
yield self.check_user_in_room(room_id, user_id)
await self.check_user_in_room(room_id, user_id)

# We currently require the user is a "moderator" in the room. We do this
# by checking if they would (theoretically) be able to change the
# m.room.canonical_alias events
power_level_event = yield self.state.get_current_state(
power_level_event = await self.state.get_current_state(
room_id, EventTypes.PowerLevels, ""
)

Expand Down
26 changes: 4 additions & 22 deletions synapse/app/generic_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,12 +413,6 @@ def _reset(self):
# map room IDs to sets of users currently typing
self._room_typing = {}

def stream_positions(self):
# We must update this typing token from the response of the previous
# sync. In particular, the stream id may "reset" back to zero/a low
# value which we *must* use for the next replication request.
return {"typing": self._latest_room_serial}

def process_replication_rows(self, token, rows):
if self._latest_room_serial > token:
# The master has gone backwards. To prevent inconsistent data, just
Expand Down Expand Up @@ -652,20 +646,11 @@ def __init__(self, hs):
else:
self.send_handler = None

async def on_rdata(self, stream_name, token, rows):
await super(GenericWorkerReplicationHandler, self).on_rdata(
stream_name, token, rows
)
await self.process_and_notify(stream_name, token, rows)
async def on_rdata(self, stream_name, instance_name, token, rows):
await super().on_rdata(stream_name, instance_name, token, rows)
await self._process_and_notify(stream_name, instance_name, token, rows)

def get_streams_to_replicate(self):
args = super(GenericWorkerReplicationHandler, self).get_streams_to_replicate()
args.update(self.typing_handler.stream_positions())
if self.send_handler:
args.update(self.send_handler.stream_positions())
return args

async def process_and_notify(self, stream_name, token, rows):
async def _process_and_notify(self, stream_name, instance_name, token, rows):
try:
if self.send_handler:
await self.send_handler.process_replication_rows(
Expand Down Expand Up @@ -799,9 +784,6 @@ def on_start(self):
def wake_destination(self, server: str):
self.federation_sender.wake_destination(server)

def stream_positions(self):
return {"federation": self.federation_position}

async def process_replication_rows(self, stream_name, token, rows):
# The federation stream contains things that we want to send out, e.g.
# presence, typing, etc.
Expand Down
7 changes: 5 additions & 2 deletions synapse/events/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,14 @@ def _fill_out_state(self):
self._current_state_ids = yield self._storage.state.get_state_ids_for_group(
self.state_group
)
if self._prev_state_id and self._event_state_key is not None:
if self._event_state_key is not None:
self._prev_state_ids = dict(self._current_state_ids)

key = (self._event_type, self._event_state_key)
self._prev_state_ids[key] = self._prev_state_id
if self._prev_state_id:
self._prev_state_ids[key] = self._prev_state_id
else:
self._prev_state_ids.pop(key, None)
else:
self._prev_state_ids = self._current_state_ids

Expand Down
42 changes: 30 additions & 12 deletions synapse/federation/federation_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -883,18 +883,37 @@ async def _do_send_leave(self, destination, pdu):

def get_public_rooms(
self,
destination,
limit=None,
since_token=None,
search_filter=None,
include_all_networks=False,
third_party_instance_id=None,
remote_server: str,
limit: Optional[int] = None,
since_token: Optional[str] = None,
search_filter: Optional[Dict] = None,
include_all_networks: bool = False,
third_party_instance_id: Optional[str] = None,
):
if destination == self.server_name:
return
"""Get the list of public rooms from a remote homeserver
Args:
remote_server: The name of the remote server
limit: Maximum amount of rooms to return
since_token: Used for result pagination
search_filter: A filter dictionary to send the remote homeserver
and filter the result set
include_all_networks: Whether to include results from all third party instances
third_party_instance_id: Whether to only include results from a specific third
party instance
Returns:
Deferred[Dict[str, Any]]: The response from the remote server, or None if
`remote_server` is the same as the local server_name
Raises:
HttpResponseException: There was an exception returned from the remote server
SynapseException: M_FORBIDDEN when the remote server has disallowed publicRoom
requests over federation
"""
return self.transport_layer.get_public_rooms(
destination,
remote_server,
limit,
since_token,
search_filter,
Expand Down Expand Up @@ -957,14 +976,13 @@ async def get_missing_events(

return signed_events

@defer.inlineCallbacks
def forward_third_party_invite(self, destinations, room_id, event_dict):
async def forward_third_party_invite(self, destinations, room_id, event_dict):
for destination in destinations:
if destination == self.server_name:
continue

try:
yield self.transport_layer.exchange_third_party_invite(
await self.transport_layer.exchange_third_party_invite(
destination=destination, room_id=room_id, event_dict=event_dict
)
return None
Expand Down
56 changes: 42 additions & 14 deletions synapse/federation/transport/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
# limitations under the License.

import logging
from typing import Any, Dict
from typing import Any, Dict, Optional

from six.moves import urllib

from twisted.internet import defer

from synapse.api.constants import Membership
from synapse.api.errors import Codes, HttpResponseException, SynapseError
from synapse.api.urls import (
FEDERATION_UNSTABLE_PREFIX,
FEDERATION_V1_PREFIX,
Expand Down Expand Up @@ -326,18 +327,25 @@ def send_invite_v2(self, destination, room_id, event_id, content):
@log_function
def get_public_rooms(
self,
remote_server,
limit,
since_token,
search_filter=None,
include_all_networks=False,
third_party_instance_id=None,
remote_server: str,
limit: Optional[int] = None,
since_token: Optional[str] = None,
search_filter: Optional[Dict] = None,
include_all_networks: bool = False,
third_party_instance_id: Optional[str] = None,
):
"""Get the list of public rooms from a remote homeserver
See synapse.federation.federation_client.FederationClient.get_public_rooms for
more information.
"""
if search_filter:
# this uses MSC2197 (Search Filtering over Federation)
path = _create_v1_path("/publicRooms")

data = {"include_all_networks": "true" if include_all_networks else "false"}
data = {
"include_all_networks": "true" if include_all_networks else "false"
} # type: Dict[str, Any]
if third_party_instance_id:
data["third_party_instance_id"] = third_party_instance_id
if limit:
Expand All @@ -347,9 +355,19 @@ def get_public_rooms(

data["filter"] = search_filter

response = yield self.client.post_json(
destination=remote_server, path=path, data=data, ignore_backoff=True
)
try:
response = yield self.client.post_json(
destination=remote_server, path=path, data=data, ignore_backoff=True
)
except HttpResponseException as e:
if e.code == 403:
raise SynapseError(
403,
"You are not allowed to view the public rooms list of %s"
% (remote_server,),
errcode=Codes.FORBIDDEN,
)
raise
else:
path = _create_v1_path("/publicRooms")

Expand All @@ -363,9 +381,19 @@ def get_public_rooms(
if since_token:
args["since"] = [since_token]

response = yield self.client.get_json(
destination=remote_server, path=path, args=args, ignore_backoff=True
)
try:
response = yield self.client.get_json(
destination=remote_server, path=path, args=args, ignore_backoff=True
)
except HttpResponseException as e:
if e.code == 403:
raise SynapseError(
403,
"You are not allowed to view the public rooms list of %s"
% (remote_server,),
errcode=Codes.FORBIDDEN,
)
raise

return response

Expand Down
Loading

0 comments on commit 13dd458

Please sign in to comment.