Commit graph

1792 commits

Author SHA1 Message Date
Lambda
c965c9747b Send User-Agent header in outbound requests 2025-05-29 19:53:02 +00:00
Lambda
d425ba72f8
Update ruma to 0.12.2 2025-05-04 14:03:46 -07:00
avdb13
48ecf50973 update documentation of service::users::Data::iter 2025-04-20 03:47:07 +00:00
Charles Hall
d1370f9834
refactor fetch_unknown_prev_events
Early returns (or continues, in this case) good.
2025-04-16 19:16:57 -07:00
Olivia Lee
6cb7896e17
use trust-dns for all DNS queries
Previously we were only using trust-dns for resolving SRV records in
server discovery, and then for resolving the hostname from the SRV
record target if one exists. With the previous behavior, admins need to
ensure that both their system resolver and trust-dns are working
correctly in order for outgoing traffic to work reliably. This can be
confusing to debug, because it's not obvious to the admin if or when
each resolver are being used. Now, everything goes through trust-dns and
outgoing federation DNS should fail/succeed more predictably.

I also expect some performance improvement from having an in-process DNS
cache, but haven't taken measurements yet.
2025-04-14 15:56:33 -07:00
Olivia Lee
e249aed1cb
rename Resolver -> FederationResolver and document 2025-04-14 15:50:04 -07:00
Olivia Lee
e98dd5b9a3
put global trust-dns resolver in an Arc
This allows us to reference it in reqwest clients configuration.
2025-04-14 15:50:04 -07:00
Olivia Lee
33f3592612
fix starting the server when db/media dirs do not exist yet
This used to be supported, as we explicitly call std::fs::create_dir_all
when initializing these, but it was broken in
b01b70fc20, which attempts to canonicalize
the paths to check for overlap before creating them.
2025-04-14 15:28:31 -07:00
Olivia Lee
abb1b5681e
add partial_canonicalize helper function
This is useful for checking for potential overlap between paths that
have not been fully created yet.
2025-04-14 15:28:31 -07:00
Lambda
6bcc4e310e
Immediately trigger EDU sending after client read receipt
Previously, read receipts would only be forwarded via federation
incidentally when some PDU was later sent to the destination server.
Trigger a send without any event to collect EDUs and get read receipts
out directly.
2025-03-30 16:48:06 -07:00
Lambda
81c5f09919
service/sending: tiny refactors, NFC 2025-03-30 16:48:06 -07:00
Lambda
d9c7fbbd82
services/sending: avoid unnecessary clone 2025-03-30 16:48:06 -07:00
Lambda
ed12b0bf67
services/sending: guard against federation requests to ourselves
These would always fail and get stuck/retried forever.
2025-03-30 16:48:02 -07:00
Charles Hall
d6475eee6d
remove redundant condition 2025-03-21 16:48:56 -07:00
Charles Hall
a04951541a
don't check canonicalized paths while sandboxed
Because the configured paths won't exist in the sandbox, so
canonicalization would fail.
2025-03-21 16:25:42 -07:00
Charles Hall
50583bc93e
reject overlapping non-canonical paths too
For example, if the database path is `/foo` and the media path is
`/foo/bar`, but `/foo/bar` is a symlink or hardlink to `/baz`, the
previous check would pass. The whole point of this check is to ensure
that the database and media data can't step on each other, so this check
is needed to deny that kind of situation as well.

It would probably be good to add a test for this behavior.
2025-03-21 16:25:31 -07:00
Charles Hall
b01b70fc20
reject overlapping media and database paths 2025-03-20 11:33:59 -07:00
Charles Hall
81a449d1d2
make database path a pathbuf
I'm guessing it wasn't like this already because of one of the admin
commands I deleted.
2025-03-20 11:33:59 -07:00
Charles Hall
5a5608e088
separate media and database paths
The primary motivation for this change is to support databases that
don't take a path, e.g. out of process databases.

This configuration structure leaves the door open for other media
storage mechanisms in the future, such as S3.

It's also structured to avoid `#[serde(flatten)]` so that we can use
`#[serde(deny_unknown_fields)]`.
2025-03-20 11:33:59 -07:00
Charles Hall
ae920fdbe8
make option name less redundant 2025-03-20 10:40:20 -07:00
Charles Hall
0a6d2b2731
make a media section in the config file 2025-03-20 10:40:20 -07:00
Charles Hall
f6b0a10e6e
implement _file in terms of _folder
what the heck lol
2025-03-20 10:40:16 -07:00
Lambda
175a62007d Update MSRV to 1.84.0
And appease clippy (`__CARGO_FIX_YOLO=1 cargo clippy --fix` plus some
manual type shuffling).
2025-02-18 17:06:08 +00:00
Lambda
5616510727 Use UInt instead of u32 for max request size
Sometimes you just really want to upload a full disk image as media.
2025-02-18 16:48:47 +00:00
Lambda
99924e5779 Add admin commands to get and reset tracing filters 2025-02-17 17:41:14 +00:00
Lambda
5eab758bd2 Make tracing filter reload handles mutable
Makes the following diff nicer.
2025-02-17 17:40:55 +00:00
Olivia Lee
472f51c350
allow adding canonical aliases from remote servers
Like is mentioned in the comment, this isn't explicitly required by the
spec, but it's reasonable and what synapse does.
2025-01-23 09:20:10 -08:00
Olivia Lee
29d8fbaefa
only validate canonical aliases that are new
Previously we required every alias in a canonical alias event sent by a
client to be valid, and would only validate local aliases. This
prevented clients from adding/removing canonical aliases if there were
existing remote or invalid aliases.
2025-01-23 09:20:10 -08:00
Olivia Lee
50c1e77cd6
factor canonical alias event validation into a helper function
Not all the semantics from the spec quote in the doc comment are
implemented yet.
2025-01-23 09:20:10 -08:00
Olivia Lee
051221c0ab
validate schema of new canonical alias events sent by clients
Previously, we would only attempt to validate the aliases in the event
content if we were able to parse the event, and would silently allow it
otherwise.
2025-01-23 09:20:10 -08:00
Olivia Lee
c748c7c188
return M_BAD_ALIAS when trying to set non-existent canonical aliases
This is the error code named in the spec.
2025-01-20 16:59:01 -08:00
Olivia Lee
795ce42518
return M_NOT_YET_UPLOADED when backing files are missing for a thumbnail
This was done for fetching original media files in
c70cfd3d25, but the change for thumbnails
was missed.
2024-12-13 01:21:14 -08:00
Olivia Lee
f216112455
don't treat media file open errors other than NotFound as missing media
For example, we want to return M_UNKNOWN and propagate the error if
somebody set up their database directory permissions wrong.
2024-12-13 01:21:05 -08:00
Olivia Lee
67f0689d73
move media file read/write logic to a helper function 2024-12-13 01:18:46 -08:00
Olivia Lee
ba72616672
do not backoff remote device key queries when a request fails due to backoff
The previous logic would increment the backoff counter both when a
request actually fails and when we do not make a request because the
server was already in backoff. This lead to a positive feedback loop
where every request made while a server is in backoff increases the
backoff delay, making it impossible to recover from backoff unless the
entire backoff delay elapses with zero requests.
2024-12-11 13:02:11 -08:00
Olivia Lee
4ee8312068
reset device key query backoff after a successful request
Failing to reset the backoff state resulted in a monotonically
increasing backoff delay. If a remote server was temporarily
unavailable, we would have a persistently increased rate of key query
failures until the backoff state was reset by a server restart. If
enough key queries were attempted while the remote was unavailable, it
can accumulate an arbitrarily long backoff delay and effectively block
all future key queries to this server.
2024-12-11 13:02:10 -08:00
Olivia Lee
79cedccdb6
factor remote device key request logic into helper functions
This is pure code-motion, with no behavior changes. The new structure
will make it easier to fix the backoff behavior, and makes the code
somewhat less of a nightmare to follow.
2024-12-11 13:02:10 -08:00
Lambda
daceadb310 sync/v3: factor out into separate functions
This is both easier to read and produces much better tracing spans.
2024-12-11 17:38:49 +00:00
Lambda
8a7f87e9b4 sync/v3: move readonly data to context struct
This makes it a lot easier to factor out parts of the big
sync_events_route().
2024-12-11 17:38:49 +00:00
Lambda
55a04f77c6 sync/v3: record relevant span fields 2024-12-11 17:38:49 +00:00
Lambda
79783ebe56 sync: split into separate files 2024-12-11 17:38:49 +00:00
Olivia Lee
46e8a63489
allow deleting dangling thumbnails
Previously attempting to delete an MXC that is only associated with
dangling thumbnails would fail, because it assumes that every thumbnail
must have a corresponding original in the db, and errors out if it can't
find the original. This is incorrect because we create dangling
thumbnails when requesting a remote thumbnail over federation when we
don't have the original file.
2024-12-01 16:18:05 -08:00
Olivia Lee
916088a22f
include mxcs from dangling thumbnails in service::media::iter_all
When requesting remote thumbnails over federation, we can end up with a
thumbnail in the media db without an associated original file. Because
of this, skipping thumbnails is insufficient to get a list of all MXCs.
2024-12-01 16:18:04 -08:00
Olivia Lee
230192be1b
skip thumbnails with only one nonzero dimension in all_file_metadata
Previously we were only skipping thumbnails that had both dimensions
nonzero. I think the assumption was that only the dimensions allowed by
services::media::thumbnail_properties would be used. This is not the
case because we have used arbitrary thumbnail dimensions when requesting
remote thumbnails.
2024-12-01 16:18:04 -08:00
Olivia Lee
14b44064b3
propagate corrupted media key errors
Now that we are able to distinguish between corrupted media keys and
missing files, it makes more sense to propagate the corrupted keys up to
the caller.
2024-12-01 16:18:04 -08:00
Olivia Lee
f0f81db99b
return Option from media::data::search_file_metadata
This is useful to easily distinguish missing files from corrupted keys.
All existing usage sites have been modified so there is no behavior
change in this commit.
2024-12-01 16:18:04 -08:00
Charles Hall
861016ce0f
inline state accessor service code from data trait
These were all calling into services() and not actually directly
accessing the database at all anyway.
2024-12-01 09:13:50 -08:00
Olivia Lee
8fcec6396e
keep going when one deletion fails in delete-remote-media
We *should* ensure that media deletion is always successful, but when a
bug causes a single object to fail deletion it's better to try to delete
the remaining objects than to give up entirely.
2024-11-28 18:32:05 -08:00
Olivia Lee
11b5055647
log details of failed media deletion 2024-11-28 18:32:05 -08:00
Olivia Lee
bdb623cb07
add comment explaining that failed media keys are logged 2024-11-28 16:46:54 -08:00