summary refs log tree commit diff
path: root/synapse/federation/sender/__init__.py (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Remove destinations from sending if not whitelisted (#18484)Devon Hudson2025-06-061-8/+54
| | | | Co-authored-by: Andrew Morgan <andrew@amorgan.xyz>
* Cleanup Python 3.8 leftovers (#17967)V024602025-02-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Some small cleanups after Python3.8 became EOL. - Move some type imports from `typing_extensions` to `typing` - Remove the `abi3-py38` feature from pyo3 ### Pull Request Checklist <!-- Please read https://element-hq.github.io/synapse/latest/development/contributing_guide.html before submitting your pull request --> * [x] Pull request is based on the develop branch * [x] Pull request includes a [changelog file](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#changelog). The entry should: - Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from `EventStore` to `EventWorkerStore`.". - Use markdown where necessary, mostly for `code blocks`. - End with either a period (.) or an exclamation mark (!). - Start with a capital letter. - Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry. * [x] [Code style](https://element-hq.github.io/synapse/latest/code_style.html) is correct (run the [linters](https://element-hq.github.io/synapse/latest/development/contributing_guide.html#run-the-linters)) --------- Co-authored-by: Quentin Gliech <quenting@element.io>
* Fix up logic for delaying sending read receipts over federation. (#17933)Erik Johnston2024-11-251-77/+88
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For context of why we delay read receipts, see https://github.com/matrix-org/synapse/issues/4730. Element Web often sends read receipts in quick succession, if it reloads the timeline it'll send one for the last message in the old timeline and again for the last message in the new timeline. This caused remote users to see a read receipt for older messages come through quickly, but then the second read receipt taking a while to arrive for the most recent message. There are two things going on in this PR: 1. There was a mismatch between seconds and milliseconds, and so we ended up delaying for far longer than intended. 2. Changing the logic to reuse the `DestinationWakeupQueue` (used for presence) The changes in logic are: - Treat the first receipt and subsequent receipts in a room in the same way - Whitelist certain classes of receipts to never delay being sent, i.e. receipts in small rooms, receipts for events that were sent within the last 60s, and sending receipts to the event sender's server. - The maximum delay a receipt can have before being sent to a server is 30s, and we'll send out receipts to remotes at least at 50Hz (by default) The upshot is that this should make receipts feel more snappy over federation. This new logic should send roughly between 10%–20% of transactions immediately on matrix.org.
* Ensure that pending to-device events are sent over federation at startup ↵Richard van der Hoff2024-03-221-8/+6
| | | | | | | | | | | | | | (#16925) Fixes https://github.com/element-hq/synapse/issues/16680, as well as a related bug, where servers which we had *never* successfully sent an event to would not be retried. In order to fix the case of pending to-device messages, we hook into the existing `wake_destinations_needing_catchup` process, by extending it to look for destinations that have pending to-device messages. The federation transmission loop then attempts to send the pending to-device messages as normal.
* Update license headersPatrick Cloke2023-11-211-10/+16
|
* Use full GitHub links instead of bare issue numbers. (#16637)Patrick Cloke2023-11-151-2/+2
|
* Add a new module API to update user presence state. (#16544)Patrick Cloke2023-10-261-1/+1
| | | | | | | | | | This adds a module API which allows a module to update a user's presence state/status message. This is useful for controlling presence from an external system. To fully control presence from the module the presence.enabled config parameter gains a new state of "untracked" which disables internal tracking of presence changes via user actions, etc. Only updates from the module will be persisted and sent down sync properly).
* Fix comments related to replication. (#16428)Patrick Cloke2023-10-061-1/+1
|
* Don't wake up destination transaction queue if they're not due for retry. ↵Erik Johnston2023-09-041-25/+61
| | | | (#16223)
* Regularly try to wake up dests instead of waiting for next PDU/EDU (#15743)Mathieu Velten2023-06-161-18/+16
|
* Factor out an `is_mine_server_name` method (#15542)Sean Quah2023-05-051-5/+6
| | | | | | | | | | | | Add an `is_mine_server_name` method, similar to `is_mine_id`. Ideally we would use this consistently, instead of sometimes comparing against `hs.hostname` and other times reaching into `hs.config.server.server_name`. Also fix a bug in the tests where `hs.hostname` would sometimes differ from `hs.config.server.server_name`. Signed-off-by: Sean Quah <seanq@matrix.org>
* Add developer documentation for the Federation Sender and add a ↵reivilibre2023-03-241-0/+113
| | | | | | documentation mechanism using Sphinx. (#15265) Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com>
* Change the parameter `immediate` of `send_device_messages` to default to ↵Shay2023-03-211-1/+1
| | | | `True` (#15297)
* Faster joins: Refactor handling of servers in room (#14954)Sean Quah2023-02-031-1/+1
| | | | | | | | | | | | | | Ensure that the list of servers in a partial state room always contains the server we joined off. Also refactor `get_partial_state_servers_at_join` to return `None` when the given room is no longer partial stated, to explicitly indicate when the room has partial state. Otherwise it's not clear whether an empty list means that the room has full state, or the room is partial stated, but the server we joined off told us that there are no servers in the room. Signed-off-by: Sean Quah <seanq@matrix.org>
* Use servers list approx to send read receipts when in partial state (#14549)Mathieu Velten2022-11-301-1/+1
| | | Signed-off-by: Mathieu Velten <mathieuv@matrix.org>
* Faster joins: use initial list of servers if we don't have the full state ↵Mathieu Velten2022-11-241-1/+17
| | | | | | | yet (#14408) Signed-off-by: Mathieu Velten <mathieuv@matrix.org> Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
* Fix `TypeError: 'dict_keys' object is not reversible` (#14280)Erik Johnston2022-10-241-2/+1
|
* Fix a bug where redactions were not being sent over federation if we did not ↵Shay2022-10-111-9/+20
| | | | have the original event. (#13813)
* Fix Prometheus recording rules to not use legacy metric names. (#13718)reivilibre2022-09-081-2/+2
|
* Add some logging to help track down #13444 (#13679)Erik Johnston2022-09-011-0/+13
|
* Federation Sender & Appservice Pusher Stream Optimisations (#13251)Nick Mills-Barrett2022-07-151-3/+7
| | | | | | | | | | | | | * Replace `get_new_events_for_appservice` with `get_all_new_events_stream` The functions were near identical and this brings the AS worker closer to the way federation senders work which can allow for multiple workers to handle AS traffic. * Pull received TS alongside events when processing the stream This avoids an extra query -per event- when both federation sender and appservice pusher process events.
* Reduce state pulled from DB due to sending typing and receipts over ↵Erik Johnston2022-06-061-1/+5
| | | | | federation (#12964) Reducing the amount of state we pull from the DB is useful as fetching state is expensive in terms of DB, CPU and memory.
* Add some type hints to datastore (#12717)Dirk Klimpel2022-05-171-7/+17
|
* Add extra debug logging to federation sender (#12614)Richard van der Hoff2022-05-031-2/+18
| | | | ... in order to debug some problems we've been having with certain events not being sent when expected.
* Exclude OOB memberships from the federation sender (#12570)Richard van der Hoff2022-05-031-0/+39
| | | | | | | As the comment says, there is no need to process such events, and indeed we need to avoid doing so. Fixes #12509.
* Spread out sending device lists to remote hosts (#12132)Erik Johnston2022-03-041-9/+17
|
* Remove `HomeServer.get_datastore()` (#12031)Richard van der Hoff2022-02-231-1/+1
| | | | | | | The presence of this method was confusing, and mostly present for backwards compatibility. Let's get rid of it. Part of #11733
* Use direct references for some configuration variables (part 2) (#10812)Patrick Cloke2021-09-151-1/+1
|
* Use direct references for some configuration variables (#10798)Patrick Cloke2021-09-131-1/+2
| | | | Instead of proxying through the magic getter of the RootConfig object. This should be more performant (and is more explicit).
* Add types to synapse.util. (#10601)reivilibre2021-09-101-2/+6
|
* Stagger send presence to remotes (#10398)Erik Johnston2021-07-151-2/+94
| | | | | | This is to help with performance, where trying to connect to thousands of hosts at once can consume a lot of CPU (due to TLS etc). Co-authored-by: Brendan Abolivier <babolivier@matrix.org>
* Use inline type hints in various other places (in `synapse/`) (#10380)Jonathan de Jong2021-07-151-8/+6
|
* Revert "Experimental Federation Speedup (#9702)"Andrew Morgan2021-04-281-93/+52
| | | | This reverts commit 05e8c70c059f8ebb066e029bc3aa3e0cefef1019.
* Remove `synapse.types.Collection` (#9856)Richard van der Hoff2021-04-221-2/+12
| | | This is no longer required, since we have dropped support for Python 3.5.
* Fix bug where we sent remote presence states to remote servers (#9850)Erik Johnston2021-04-201-0/+4
|
* Don't send normal presence updates over federation replication stream (#9828)Erik Johnston2021-04-191-95/+1
|
* Experimental Federation Speedup (#9702)Jonathan de Jong2021-04-141-56/+84
| | | | | This basically speeds up federation by "squeezing" each individual dual database call (to destinations and destination_rooms), which previously happened per every event, into one call for an entire batch (100 max). Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>
* Remove redundant "coding: utf-8" lines (#9786)Jonathan de Jong2021-04-141-1/+0
| | | | | | | Part of #9744 Removes all redundant `# -*- coding: utf-8 -*-` lines from files, as python 3 automatically reads source code as utf-8 now. `Signed-off-by: Jonathan de Jong <jonathan@automatia.nl>`
* Fix sharded federation sender sometimes using 100% CPU.Erik Johnston2021-04-081-2/+4
| | | | | | | We pull all destinations requiring catchup from the DB in batches. However, if all those destinations get filtered out (due to the federation sender being sharded), then the `last_processed` destination doesn't get updated, and we keep requesting the same set repeatedly.
* Add a Synapse Module for configuring presence update routing (#9491)Andrew Morgan2021-04-061-1/+18
| | | | | | | | | | | | At the moment, if you'd like to share presence between local or remote users, those users must be sharing a room together. This isn't always the most convenient or useful situation though. This PR adds a module to Synapse that will allow deployments to set up extra logic on where presence updates should be routed. The module must implement two methods, `get_users_for_states` and `get_interested_users`. These methods are given presence updates or user IDs and must return information that Synapse will use to grant passing presence updates around. A method is additionally added to `ModuleApi` which allows triggering a set of users to receive the current, online presence information for all users they are considered interested in. This is the equivalent of that user receiving presence information during an initial sync. The goal of this module is to be fairly generic and useful for a variety of applications, with hard requirements being: * Sending state for a specific set or all known users to a defined set of local and remote users. * The ability to trigger an initial sync for specific users, so they receive all current state.
* Add type hints for the federation sender. (#9681)Patrick Cloke2021-03-291-13/+103
| | | | Includes an abstract base class which both the FederationSender and the FederationRemoteSendQueue must implement.
* Be smarter about which hosts to send presence to when processing room joins ↵Andrew Morgan2021-02-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | (#9402) This PR attempts to eliminate unnecessary presence sending work when your local server joins a room, or when a remote server joins a room your server is participating in by processing state deltas in chunks rather than individually. --- When your server joins a room for the first time, it requests the historical state as well. This chunk of new state is passed to the presence handler which, after filtering that state down to only membership joins, will send presence updates to homeservers for each join processed. It turns out that we were being a bit naive and processing each event individually, and sending out presence updates for every one of those joins. Even if many different joins were users on the same server (hello IRC bridges), we'd send presence to that same homeserver for every remote user join we saw. This PR attempts to deduplicate all of that by processing the entire batch of state deltas at once, instead of only doing each join individually. We process the joins and note down which servers need which presence: * If it was a local user join, send that user's latest presence to all servers in the room * If it was a remote user join, send the presence for all local users in the room to that homeserver We deduplicate by inserting all of those pending updates into a dictionary of the form: ``` { server_name1: {presence_update1, ...}, server_name2: {presence_update1, presence_update2, ...} } ``` Only after building this dict do we then start sending out presence updates.
* Update black, and run auto formatting over the codebase (#9381)Eric Eastwood2021-02-161-4/+6
| | | | | | | - Update black version to the latest - Run black auto formatting over the codebase - Run autoformatting according to [`docs/code_style.md `](https://github.com/matrix-org/synapse/blob/80d6dc9783aa80886a133756028984dbf8920168/docs/code_style.md) - Update `code_style.md` docs around installing black to use the correct version
* Precompute joined hosts and store in Redis (#9198)Erik Johnston2021-01-261-15/+35
|
* Fix not sending events over federation when using sharded event persisters ↵Erik Johnston2020-10-141-2/+7
| | | | | | | | | | | | | | | | | (#8536) * Fix outbound federaion with multiple event persisters. We incorrectly notified federation senders that the minimum persisted stream position had advanced when we got an `RDATA` from an event persister. Notifying of federation senders already correctly happens in the notifier, so we just delete the offending line. * Change some interfaces to use RoomStreamToken. By enforcing use of `RoomStreamTokens` we make it less likely that people pass in random ints that they got from somewhere random.
* Remove stream ordering from Metadata dict (#8452)Richard van der Hoff2020-10-051-0/+2
| | | | | | | | There's no need for it to be in the dict as well as the events table. Instead, we store it in a separate attribute in the EventInternalMetadata object, and populate that on load. This means that we can rely on it being correctly populated for any event which has been persited to the database.
* Catch-up after Federation Outage (bonus): Catch-up on Synapse Startup (#8322)reivilibre2020-09-181-0/+51
| | | | | | | | | | Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net> Co-authored-by: Patrick Cloke <clokep@users.noreply.github.com> * Fix _set_destination_retry_timings This came about because the code assumed that retry_interval could not be NULL — which has been challenged by catch-up.
* Catch-up after Federation Outage (split, 1) (#8230)reivilibre2020-09-041-2/+9
| | | Signed-off-by: Olivier Wilkinson (reivilibre) <olivier@librepush.net>
* Stop sub-classing object (#8249)Patrick Cloke2020-09-041-1/+1
|
* Remove obsolete order field in `send_new_transaction` (#8245)reivilibre2020-09-031-6/+1
| | | Co-authored-by: Richard van der Hoff <1389908+richvdh@users.noreply.github.com>
* Add type hints for state. (#8140)Patrick Cloke2020-08-241-2/+2
|
* Convert stream database to async/await. (#8074)Patrick Cloke2020-08-171-1/+1
|
* Merge branch 'master' into developOlivier Wilkinson (reivilibre)2020-07-301-1/+1
|\
| * Update worker docs with recent enhancements (#7969)Erik Johnston2020-07-291-1/+1
| |
* | Convert federation client to async/await. (#7975)Patrick Cloke2020-07-301-13/+6
|/
* Convert state resolution to async/await (#7942)Patrick Cloke2020-07-241-1/+3
|
* Convert presence handler helpers to async/await. (#7939)Patrick Cloke2020-07-231-1/+3
|
* Add ability to run multiple pusher instances (#7855)Erik Johnston2020-07-161-8/+8
| | | This reuses the same scheme as federation sender sharding
* Add ability to shard the federation sender (#7798)Erik Johnston2020-07-101-2/+46
|
* Fix new metric where we used ms instead of seconds (#7771)Erik Johnston2020-07-011-1/+1
| | | | Introduced in #7755, not yet released.
* Add some metrics for inbound and outbound federation processing times (#7755)Erik Johnston2020-06-301-1/+9
|
* Replace iteritems/itervalues/iterkeys with native versions. (#7692)Patrick Cloke2020-06-151-3/+1
|
* Fix catchup-on-reconnect for the Federation Stream (#7374)Richard van der Hoff2020-05-051-5/+7
| | | | looks like we managed to break this during the refactorathon.
* Move catchup of replication streams to worker. (#7024)Erik Johnston2020-03-251-0/+9
| | | This changes the replication protocol so that the server does not send down `RDATA` for rows that happened before the client connected. Instead, the server will send a `POSITION` and clients then query the database (or master out of band) to get up to date.
* Add typing to synapse.federation.sender (#6871)Erik Johnston2020-02-071-51/+48
|
* Wake up transaction queue when remote server comes back online (#6706)Erik Johnston2020-01-171-2/+16
| | | | | This will be used to retry outbound transactions to a remote server if we think it might have come back up.
* Clean up newline quote marks around the codebase (#6362)Andrew Morgan2019-11-211-1/+1
|
* add some metrics on the federation sender (#6160)Richard van der Hoff2019-10-031-5/+6
|
* Move logging utilities out of the side drawer of util/ and into logging/ (#5606)Amber Brown2019-07-041-4/+8
|
* Run Black. (#5482)Amber Brown2019-06-201-33/+34
|
* Add experimental option to reduce extremities.Erik Johnston2019-06-181-0/+3
| | | | | | | Adds new config option `cleanup_extremities_with_dummy_events` which periodically sends dummy events to rooms with more than 10 extremities. THIS IS REALLY EXPERIMENTAL.
* Use event streams to calculate presenceErik Johnston2019-03-271-1/+18
| | | | | | | | | | | | | | | | | Primarily this fixes a bug in the handling of remote users joining a room where the server sent out the presence for all local users in the room to all servers in the room. We also change to using the state delta stream, rather than the distributor, as it will make it easier to split processing out of the master process (as well as being more flexible). Finally, when sending presence states to newly joined servers we filter out old presence states to reduce the number sent. Initially we filter out states that are offline and have a last active more than a week ago, though this can be changed down the line. Fixes #3962
* Batch up outgoing read-receipts to reduce federation traffic. (#4890)Richard van der Hoff2019-03-201-19/+96
| | | | Rate-limit outgoing read-receipts as per #4730.
* Rename and move the classesRichard van der Hoff2019-03-131-0/+388