0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-11-20 12:24:59 +01:00

Merge branch 'develop' of github.com:matrix-org/synapse into erikj/fixup_devices_stream

This commit is contained in:
Erik Johnston 2020-03-02 16:55:55 +00:00
commit 65a941d1f8
13 changed files with 55 additions and 40 deletions

View file

@ -6,12 +6,7 @@
set -ex set -ex
apt-get update apt-get update
apt-get install -y python3.5 python3.5-dev python3-pip libxml2-dev libxslt-dev zlib1g-dev apt-get install -y python3.5 python3.5-dev python3-pip libxml2-dev libxslt-dev zlib1g-dev tox
# workaround for https://github.com/jaraco/zipp/issues/40
python3.5 -m pip install 'setuptools>=34.4.0'
python3.5 -m pip install tox
export LANG="C.UTF-8" export LANG="C.UTF-8"

View file

@ -418,7 +418,7 @@ so, you will need to edit `homeserver.yaml`, as follows:
for having Synapse automatically provision and renew federation for having Synapse automatically provision and renew federation
certificates through ACME can be found at [ACME.md](docs/ACME.md). certificates through ACME can be found at [ACME.md](docs/ACME.md).
Note that, as pointed out in that document, this feature will not Note that, as pointed out in that document, this feature will not
work with installs set up after November 2020. work with installs set up after November 2019.
If you are using your own certificate, be sure to use a `.pem` file that If you are using your own certificate, be sure to use a `.pem` file that
includes the full certificate chain including any intermediate certificates includes the full certificate chain including any intermediate certificates

View file

@ -1 +0,0 @@
Fixed set a user as an admin with the admin API `PUT /_synapse/admin/v2/users/<user_id>`. Contributed by @dklimpel.

1
changelog.d/6995.misc Normal file
View file

@ -0,0 +1 @@
Add some type annotations to the federation base & client classes.

1
changelog.d/7015.misc Normal file
View file

@ -0,0 +1 @@
Change date in INSTALL.md#tls-certificates for last date of getting TLS certificates to November 2019.

1
changelog.d/7018.bugfix Normal file
View file

@ -0,0 +1 @@
Fix py35-old CI by using native tox package.

1
changelog.d/7019.misc Normal file
View file

@ -0,0 +1 @@
Port `synapse.handlers.presence` to async/await.

View file

@ -15,10 +15,9 @@ services:
restart: unless-stopped restart: unless-stopped
# See the readme for a full documentation of the environment settings # See the readme for a full documentation of the environment settings
environment: environment:
- SYNAPSE_CONFIG_PATH=/etc/homeserver.yaml - SYNAPSE_CONFIG_PATH=/data/homeserver.yaml
volumes: volumes:
# You may either store all the files in a local folder # You may either store all the files in a local folder
- ./matrix-config/homeserver.yaml:/etc/homeserver.yaml
- ./files:/data - ./files:/data
# .. or you may split this between different storage points # .. or you may split this between different storage points
# - ./files:/data # - ./files:/data

View file

@ -1,6 +1,6 @@
# Using the Synapse Grafana dashboard # Using the Synapse Grafana dashboard
0. Set up Prometheus and Grafana. Out of scope for this readme. Useful documentation about using Grafana with Prometheus: http://docs.grafana.org/features/datasources/prometheus/ 0. Set up Prometheus and Grafana. Out of scope for this readme. Useful documentation about using Grafana with Prometheus: http://docs.grafana.org/features/datasources/prometheus/
1. Have your Prometheus scrape your Synapse. https://github.com/matrix-org/synapse/blob/master/docs/metrics-howto.rst 1. Have your Prometheus scrape your Synapse. https://github.com/matrix-org/synapse/blob/master/docs/metrics-howto.md
2. Import dashboard into Grafana. Download `synapse.json`. Import it to Grafana and select the correct Prometheus datasource. http://docs.grafana.org/reference/export_import/ 2. Import dashboard into Grafana. Download `synapse.json`. Import it to Grafana and select the correct Prometheus datasource. http://docs.grafana.org/reference/export_import/
3. Set up additional recording rules 3. Set up additional recording rules

View file

@ -15,11 +15,13 @@
# limitations under the License. # limitations under the License.
import logging import logging
from collections import namedtuple from collections import namedtuple
from typing import Iterable, List
import six import six
from twisted.internet import defer from twisted.internet import defer
from twisted.internet.defer import DeferredList from twisted.internet.defer import Deferred, DeferredList
from twisted.python.failure import Failure
from synapse.api.constants import MAX_DEPTH, EventTypes, Membership from synapse.api.constants import MAX_DEPTH, EventTypes, Membership
from synapse.api.errors import Codes, SynapseError from synapse.api.errors import Codes, SynapseError
@ -29,6 +31,7 @@ from synapse.api.room_versions import (
RoomVersion, RoomVersion,
) )
from synapse.crypto.event_signing import check_event_content_hash from synapse.crypto.event_signing import check_event_content_hash
from synapse.crypto.keyring import Keyring
from synapse.events import EventBase, make_event_from_dict from synapse.events import EventBase, make_event_from_dict
from synapse.events.utils import prune_event from synapse.events.utils import prune_event
from synapse.http.servlet import assert_params_in_dict from synapse.http.servlet import assert_params_in_dict
@ -56,7 +59,12 @@ class FederationBase(object):
@defer.inlineCallbacks @defer.inlineCallbacks
def _check_sigs_and_hash_and_fetch( def _check_sigs_and_hash_and_fetch(
self, origin, pdus, room_version, outlier=False, include_none=False self,
origin: str,
pdus: List[EventBase],
room_version: str,
outlier: bool = False,
include_none: bool = False,
): ):
"""Takes a list of PDUs and checks the signatures and hashs of each """Takes a list of PDUs and checks the signatures and hashs of each
one. If a PDU fails its signature check then we check if we have it in one. If a PDU fails its signature check then we check if we have it in
@ -69,11 +77,11 @@ class FederationBase(object):
a new list. a new list.
Args: Args:
origin (str) origin
pdu (list) pdu
room_version (str) room_version
outlier (bool): Whether the events are outliers or not outlier: Whether the events are outliers or not
include_none (str): Whether to include None in the returned list include_none: Whether to include None in the returned list
for events that have failed their checks for events that have failed their checks
Returns: Returns:
@ -82,7 +90,7 @@ class FederationBase(object):
deferreds = self._check_sigs_and_hashes(room_version, pdus) deferreds = self._check_sigs_and_hashes(room_version, pdus)
@defer.inlineCallbacks @defer.inlineCallbacks
def handle_check_result(pdu, deferred): def handle_check_result(pdu: EventBase, deferred: Deferred):
try: try:
res = yield make_deferred_yieldable(deferred) res = yield make_deferred_yieldable(deferred)
except SynapseError: except SynapseError:
@ -96,8 +104,10 @@ class FederationBase(object):
if not res and pdu.origin != origin: if not res and pdu.origin != origin:
try: try:
# This should not exist in the base implementation, until
# this is fixed, ignore it for typing. See issue #6997.
res = yield defer.ensureDeferred( res = yield defer.ensureDeferred(
self.get_pdu( self.get_pdu( # type: ignore
destinations=[pdu.origin], destinations=[pdu.origin],
event_id=pdu.event_id, event_id=pdu.event_id,
room_version=room_version, room_version=room_version,
@ -127,21 +137,23 @@ class FederationBase(object):
else: else:
return [p for p in valid_pdus if p] return [p for p in valid_pdus if p]
def _check_sigs_and_hash(self, room_version, pdu): def _check_sigs_and_hash(self, room_version: str, pdu: EventBase) -> Deferred:
return make_deferred_yieldable( return make_deferred_yieldable(
self._check_sigs_and_hashes(room_version, [pdu])[0] self._check_sigs_and_hashes(room_version, [pdu])[0]
) )
def _check_sigs_and_hashes(self, room_version, pdus): def _check_sigs_and_hashes(
self, room_version: str, pdus: List[EventBase]
) -> List[Deferred]:
"""Checks that each of the received events is correctly signed by the """Checks that each of the received events is correctly signed by the
sending server. sending server.
Args: Args:
room_version (str): The room version of the PDUs room_version: The room version of the PDUs
pdus (list[FrozenEvent]): the events to be checked pdus: the events to be checked
Returns: Returns:
list[Deferred]: for each input event, a deferred which: For each input event, a deferred which:
* returns the original event if the checks pass * returns the original event if the checks pass
* returns a redacted version of the event (if the signature * returns a redacted version of the event (if the signature
matched but the hash did not) matched but the hash did not)
@ -152,7 +164,7 @@ class FederationBase(object):
ctx = LoggingContext.current_context() ctx = LoggingContext.current_context()
def callback(_, pdu): def callback(_, pdu: EventBase):
with PreserveLoggingContext(ctx): with PreserveLoggingContext(ctx):
if not check_event_content_hash(pdu): if not check_event_content_hash(pdu):
# let's try to distinguish between failures because the event was # let's try to distinguish between failures because the event was
@ -189,7 +201,7 @@ class FederationBase(object):
return pdu return pdu
def errback(failure, pdu): def errback(failure: Failure, pdu: EventBase):
failure.trap(SynapseError) failure.trap(SynapseError)
with PreserveLoggingContext(ctx): with PreserveLoggingContext(ctx):
logger.warning( logger.warning(
@ -215,16 +227,18 @@ class PduToCheckSig(
pass pass
def _check_sigs_on_pdus(keyring, room_version, pdus): def _check_sigs_on_pdus(
keyring: Keyring, room_version: str, pdus: Iterable[EventBase]
) -> List[Deferred]:
"""Check that the given events are correctly signed """Check that the given events are correctly signed
Args: Args:
keyring (synapse.crypto.Keyring): keyring object to do the checks keyring: keyring object to do the checks
room_version (str): the room version of the PDUs room_version: the room version of the PDUs
pdus (Collection[EventBase]): the events to be checked pdus: the events to be checked
Returns: Returns:
List[Deferred]: a Deferred for each event in pdus, which will either succeed if A Deferred for each event in pdus, which will either succeed if
the signatures are valid, or fail (with a SynapseError) if not. the signatures are valid, or fail (with a SynapseError) if not.
""" """
@ -329,7 +343,7 @@ def _check_sigs_on_pdus(keyring, room_version, pdus):
return [_flatten_deferred_list(p.deferreds) for p in pdus_to_check] return [_flatten_deferred_list(p.deferreds) for p in pdus_to_check]
def _flatten_deferred_list(deferreds): def _flatten_deferred_list(deferreds: List[Deferred]) -> Deferred:
"""Given a list of deferreds, either return the single deferred, """Given a list of deferreds, either return the single deferred,
combine into a DeferredList, or return an already resolved deferred. combine into a DeferredList, or return an already resolved deferred.
""" """
@ -341,7 +355,7 @@ def _flatten_deferred_list(deferreds):
return defer.succeed(None) return defer.succeed(None)
def _is_invite_via_3pid(event): def _is_invite_via_3pid(event: EventBase) -> bool:
return ( return (
event.type == EventTypes.Member event.type == EventTypes.Member
and event.membership == Membership.INVITE and event.membership == Membership.INVITE

View file

@ -187,7 +187,7 @@ class FederationClient(FederationBase):
async def backfill( async def backfill(
self, dest: str, room_id: str, limit: int, extremities: Iterable[str] self, dest: str, room_id: str, limit: int, extremities: Iterable[str]
) -> List[EventBase]: ) -> Optional[List[EventBase]]:
"""Requests some more historic PDUs for the given room from the """Requests some more historic PDUs for the given room from the
given destination server. given destination server.
@ -199,9 +199,9 @@ class FederationClient(FederationBase):
""" """
logger.debug("backfill extrem=%s", extremities) logger.debug("backfill extrem=%s", extremities)
# If there are no extremeties then we've (probably) reached the start. # If there are no extremities then we've (probably) reached the start.
if not extremities: if not extremities:
return return None
transaction_data = await self.transport_layer.backfill( transaction_data = await self.transport_layer.backfill(
dest, room_id, extremities, limit dest, room_id, extremities, limit
@ -284,7 +284,7 @@ class FederationClient(FederationBase):
pdu_list = [ pdu_list = [
event_from_pdu_json(p, room_version, outlier=outlier) event_from_pdu_json(p, room_version, outlier=outlier)
for p in transaction_data["pdus"] for p in transaction_data["pdus"]
] ] # type: List[EventBase]
if pdu_list and pdu_list[0]: if pdu_list and pdu_list[0]:
pdu = pdu_list[0] pdu = pdu_list[0]
@ -615,7 +615,7 @@ class FederationClient(FederationBase):
] ]
if auth_chain_create_events != [create_event.event_id]: if auth_chain_create_events != [create_event.event_id]:
raise InvalidResponseError( raise InvalidResponseError(
"Unexpected create event(s) in auth chain" "Unexpected create event(s) in auth chain: %s"
% (auth_chain_create_events,) % (auth_chain_create_events,)
) )

View file

@ -15,6 +15,8 @@
import logging import logging
from twisted.internet import defer
from synapse.storage._base import SQLBaseStore from synapse.storage._base import SQLBaseStore
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -56,7 +58,7 @@ class StateDeltasStore(SQLBaseStore):
# if the CSDs haven't changed between prev_stream_id and now, we # if the CSDs haven't changed between prev_stream_id and now, we
# know for certain that they haven't changed between prev_stream_id and # know for certain that they haven't changed between prev_stream_id and
# max_stream_id. # max_stream_id.
return max_stream_id, [] return defer.succeed((max_stream_id, []))
def get_current_state_deltas_txn(txn): def get_current_state_deltas_txn(txn):
# First we calculate the max stream id that will give us less than # First we calculate the max stream id that will give us less than

View file

@ -181,6 +181,8 @@ commands = mypy \
synapse/appservice \ synapse/appservice \
synapse/config \ synapse/config \
synapse/events/spamcheck.py \ synapse/events/spamcheck.py \
synapse/federation/federation_base.py \
synapse/federation/federation_client.py \
synapse/federation/sender \ synapse/federation/sender \
synapse/federation/transport \ synapse/federation/transport \
synapse/handlers/presence.py \ synapse/handlers/presence.py \