Commit graph

2498 commits

Author SHA1 Message Date
Charles Hall
c9859a9b2d
enable assigning_clones lint 2024-05-26 19:47:00 -07:00
Charles Hall
793d809ac6
enable unused_qualifications lint 2024-05-26 19:47:00 -07:00
Charles Hall
d7e945f4c5
enable dead_code lint 2024-05-26 19:46:48 -07:00
Charles Hall
518d0c9cf3
update the rust toolchain, ignore new lints
I will fix them in follow-up commits. Also apparently rustc doesn't warn
you when you pass it lints that don't exist (yet) so that's annoying.
2024-05-24 20:09:41 -07:00
Charles Hall
82c37f2983
remove stale reference
This should've been done in d5a9c6ac32,
my bad.
2024-05-24 20:09:41 -07:00
Charles Hall
b5321d81c0
update flake.lock
Nixpkgs and `rust-rocksdb` line up so we can drop our RocksDB input for
the time being.

Flake lock file updates:

• Updated input 'attic':
    'github:zhaofengli/attic/6eabc3f02fae3683bffab483e614bebfcd476b21' (2024-02-14)
  → 'github:zhaofengli/attic/4dbdbee45728d8ce5788db6461aaaa89d98081f0' (2024-03-29)
• Updated input 'attic/nixpkgs':
    'github:NixOS/nixpkgs/aa9d4729cbc99dabacb50e3994dcefb3ea0f7447' (2023-12-14)
  → 'github:NixOS/nixpkgs/07262b18b97000d16a4bdb003418bd2fb067a932' (2024-03-25)
• Updated input 'attic/nixpkgs-stable':
    'github:NixOS/nixpkgs/1e2e384c5b7c50dbf8e9c441a9e58d85f408b01f' (2023-12-17)
  → 'github:NixOS/nixpkgs/44733514b72e732bd49f5511bd0203dea9b9a434' (2024-03-26)
• Updated input 'crane':
    'github:ipetkov/crane/55f4939ac59ff8f89c6a4029730a2d49ea09105f' (2024-04-21)
  → 'github:ipetkov/crane/109987da061a1bf452f435f1653c47511587d919' (2024-05-24)
• Updated input 'fenix':
    'github:nix-community/fenix/c8943ea9e98d41325ff57d4ec14736d330b321b2' (2024-03-05)
  → 'github:nix-community/fenix/b6fc5035b28e36a98370d0eac44f4ef3fd323df6' (2024-05-22)
• Updated input 'fenix/rust-analyzer-src':
    'github:rust-lang/rust-analyzer/9f14343f9ee24f53f17492c5f9b653427e2ad15e' (2024-03-04)
  → 'github:rust-lang/rust-analyzer/21ec8f523812b88418b2bfc64240c62b3dd967bd' (2024-05-19)
• Updated input 'flake-utils':
    'github:numtide/flake-utils/d465f4819400de7c8d874d50b982301f28a84605' (2024-02-28)
  → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11)
• Updated input 'nix-filter':
    'github:numtide/nix-filter/3449dc925982ad46246cfc36469baf66e1b64f17' (2024-01-15)
  → 'github:numtide/nix-filter/3342559a24e85fc164b295c3444e8a139924675b' (2024-03-11)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/b8697e57f10292a6165a20f03d2f42920dfaf973' (2024-03-03)
  → 'github:NixOS/nixpkgs/5710852ba686cc1fd0d3b8e22b3117d43ba374c2' (2024-05-21)
• Removed input 'rocksdb'
2024-05-24 20:08:54 -07:00
Lambda
67cb6f817d Instrument caches 2024-05-22 20:10:42 +00:00
Lambda
62bff27d50 Remove unused cache 2024-05-22 20:08:43 +00:00
Charles Hall
6e2eec012f
special case userroomid_highlightcount
This fixes the panic on startup with a fresh database.
2024-05-21 17:56:56 -07:00
Charles Hall
b3709f262e
panic when a column family would be created twice
`create_cf` already fails when the column family already exists, but
this gives us a much better error message; namely, it tells us what
column family name is at fault.
2024-05-21 17:48:33 -07:00
Charles Hall
53fbd3fc41
store old_cfs as a HashSet
This list can't have duplicates.
2024-05-21 17:25:23 -07:00
Charles Hall
a60a9551e1
Revert "Merge branch 'check-if-membership-is-case-endpoints' into 'next'"
This reverts commit 7ace9b0dff, reversing
changes made to 624654a88b.
2024-05-21 16:34:26 -07:00
Charles Hall
49660b9e39
return a concrete error type from try_main
Also adds a utility for formatting an error message in addition to all
of its sources, i.e. errors that came before it that led to the current
error.

This helps us to provide better error messages to users by including
more information: both our own error message and all of the underlying
error messages, if any, instead of only one or the other.
2024-05-20 14:51:30 -07:00
Charles Hall
4407e15d78
reword error message about GRAPEVINE_CONFIG
The new message more accurately reflects the purpose and behaviors of
the environment variable.
2024-05-20 14:47:38 -07:00
Charles Hall
23f99015df
return ExitCode instead of using panic or exit
`panic!()` (and things that invoke it, such as `expect` and `unwrap`)
produces terrible looking error messages and `std::process::exit()`
doesn't run destructors. Instead, we'll make a `try_main` that can
return a `Result` with a structured error type, but for now I'm going to
be lazy and just use `Box<dyn Error>`. Then, `main` will call it and
return the appropriate `ExitCode` value based on `try_main`'s `Result`.
This gives us the opportunity to produce good error messages and doesn't
violently terminate the program.
2024-05-20 14:47:34 -07:00
Lambda
edfccea30a Convert giant tuple in state_compressor to struct 2024-05-20 21:27:57 +00:00
Benjamin Lee
8d09a7e490 don't return extra member count or e2ee device updates from sync
Previously, we were returning redundant member count updates or encrypted
device updates from the /sync endpoint in some cases. The extra member
count updates are spec-compliant, but unnecessary, while the extra
encrypted device updates violate the spec.

The refactor necessary to fix this bug is also necessary to support
filtering on state events in sync.

Details:

Joined room incremental sync needs to examine state events for four
purposes:

 1. determining whether we need to return an update to room member counts
 2. determining the set of left/joined devices for encrypted rooms
    (returned in `device_lists`)
 3. returning state events to the client (in `rooms.joined.*.state`)
 4. tracking which member events we have sent to the client, so they can
    be omitted on future requests when lazy-loading is enabled.

The state events that we need to examine for the first two cases is member
events in the delta between `since` and the end of `timeline`. For the
second two cases, we need the delta between `since` and the start of
`timeline`, plus contextual member events for any senders that occur in
`timeline`. The second list is subject to filtering, while the first is
not.

Before this change, we were using the same set of state events that we are
returning to the client (cases 3/4) to do the analysis for cases 1/2.
In a compliant implementation, this would result in us missing some
relevant member events in 1/2 in addition to seeing redundant member
events. In current grapevine this is not the case because the set of
events that we return to the client is always a superset of the set that
is needed for cases 1/2. This is because we don't support filtering, and
we have an existing bug[1] where we are returning the delta between
`since` and the end of `timeline` rather than the start.

[1]: https://gitlab.computer.surgery/matrix/grapevine-fork/-/issues/5

Fixing this is necessary to implement filtering because otherwise
we would start missing some member events for member count or encrypted
device updates if the relevant member events are rejected by the filter.
This would be much worse than our current behavior.
2024-05-20 21:13:13 +00:00
Lambda
5172f66c1a More useful tracing spans 2024-05-20 16:49:45 +00:00
Lambda
c0ce2ebbf8 Add utility function for truncating strings in logging 2024-05-20 16:49:45 +00:00
Lambda
9dbc7d92e2 utils: add helper for adding unbounded slices to tracing spans 2024-05-20 16:49:42 +00:00
Lambda
5a178ba393 Add comment to task spawner middleware 2024-05-20 16:49:40 +00:00
Lambda
ac42e0bfff Fix spans in tokio::spawn-ed tasks
tokio::spawn is a span boundary, the spawned future has no parent span.

For short futures, we simply inherit the current span with
`.in_current_span()`.

For long running futures containing a sleeping infinite loop, we don't
actually want a span on the entire task or even the entire loop body,
both would result in very long spans. Instead, we put the outermost span
(created using #[tracing::instrument] or .instrument()) around the
actual work happening after the sleep, which results in a new root span
being created after every sleep.
2024-05-20 16:49:40 +00:00
Lambda
5e9e5b76bc service/sending: factor out closures into methods 2024-05-20 16:49:40 +00:00
Lambda
092315e2cd remove unnecessary async and select!{} 2024-05-20 16:49:20 +00:00
Charles Hall
a60501189d
prevent xss via user-uploaded media
Previously, `Content-Disposition` was always set to `inline`, even for
HTML, which means that XSS could be easily acheived by uploading
malicious HTML and getting someone to click on the Matrix HTTP API link
for that piece of media. Now, we have an allowlist of safe values for
`Content-Type` that use `inline` while everything else defaults to
`attachment`, including HTML and SVG, which prevents XSS.

We also set the `Content-Security-Policy` header because why not.

A `set_header_or_panic` function is introduced to do what it says in
case Ruma begins providing better or worse values for the relevant
headers in the future. The safest way to handle such a case is simply
to panic.
2024-05-19 21:05:02 -07:00
Charles Hall
6024f866e3
fix mod/use order 2024-05-19 19:04:23 -07:00
Charles Hall
f8961d5578
rename Ruma to Ar
This follows the pattern of the previous commit.
2024-05-19 19:04:20 -07:00
Charles Hall
7ea98dac72
rename RumaResponse to Ra
It's very commonly used so having a short name is worthwhile, I think.
2024-05-19 19:03:45 -07:00
Charles Hall
230ebd3884
don't automatically wrap in RumaResponse
This allows us to use the `ruma_route` convenience function even when we
need to add our own hacks into the responses, thus making us less
reliant on Ruma.
2024-05-18 18:31:36 -07:00
Charles Hall
87ac0e2a38
don't log that federation is disabled
This mostly just spams the logs with useless information when doing
cursed local testing.
2024-05-16 22:33:37 -07:00
Charles Hall
93a2bf9c93
change FedDest::{into -> to}_*
They don't need to take ownership of `self`.
2024-05-16 22:15:06 -07:00
Charles Hall
e7b8f78867
update rocksdb
Flake lock file updates:

• Updated input 'rocksdb':
    'github:facebook/rocksdb/bcf88d48ce8aa8b536aee4dd305533b3b83cf435' (2024-04-16)
  → 'github:facebook/rocksdb/6f7cabeac80a3a6150be2c8a8369fcecb107bf43' (2024-04-22)
2024-05-16 21:50:31 -07:00
Benjamin Lee
146465693e
remove sync response cache
This cache can serve invalid responses, and has an extremely low hit
rate.

It serves invalid responses because because it's only keyed off
the `since` parameter, but many of the other request parameters also
affect the response or it's side effects. This will become worse once we
implement filtering, because there will be a wider space of parameters
with different responses. This problem is fixable, but not worth it
because of the low hit rate.

The low hit rate is because normal clients will always issue the next
sync request with `since` set to the `prev_batch` value of the previous
response. The only time we expect to see multiple requests with the same
`since` is when the response is empty, but we don't cache empty
responses.

This was confirmed experimentally by logging cache hits and misses over
15 minutes with a wide variety of clients. This test was run on
matrix.computer.surgery, which has only a few active users, but a
large volume of sync traffic from many rooms. Over the test period, we
had 3 hits and 5309 misses. All hits occurred in the first minute, so I
suspect that they had something to do with client recovery from an
offline state. The clients that were connected during the test are:

 - element web
 - schildichat web
 - iamb
 - gomuks
 - nheko
 - fractal
 - fluffychat web
 - fluffychat android
 - cinny web
 - element android
 - element X android

Fixes: #2
2024-05-16 21:33:06 -07:00
Charles Hall
5cb2551422
enable error_on_line_overflow and fix errors
These required some manual intervention.
2024-05-16 19:11:40 -07:00
Charles Hall
0afc1d2f50
change rustfmt configuration
This change is fully automated, except the `rustfmt.toml` changes and
a few clippy directives to allow specific functions with too many lines
because they are longer now.
2024-05-16 19:11:40 -07:00
Charles Hall
40d6ce230d
reformat report formatting
I manually expanded the HTML into a more readable format, the rest was
rustfmt's doing. It's beyond me why/how someone would willing write a
pile of HTML like that...
2024-05-16 19:10:52 -07:00
Charles Hall
6bc17b268c
factor select bodies into closures
I would've preferred to factor these out into their own functions, but
unfortunately the inner type of the `FuturesUnordered` is unnameable.
`Box` or TAIT would help, but the former has a performance cost and the
latter doesn't exist on stable yet.
2024-05-16 19:09:57 -07:00
Charles Hall
ac53948450
use more, qualify less
Doing this will allow `rustfmt` to collapse lines more efficiently.
Specifically, a lot of these lines fail to wrap to 80 columns without
these changes.
2024-05-16 19:09:10 -07:00
Charles Hall
dc096d7ad7
abbreviate api categories
This reduces the amount of characters on each line.
2024-05-16 16:55:33 -07:00
Charles Hall
592dee368d
replace comment on services with a doc comment
The previous comment is pretty self-evident and also misunderstands
async closures.
2024-05-16 16:55:06 -07:00
Charles Hall
94978b95a6
fix references in doc comments
At least, this is all I've found so far.
2024-05-16 16:43:24 -07:00
Charles Hall
04184c6137
use gender-neutral pronouns 2024-05-16 16:17:40 -07:00
Charles Hall
05be778fbb
stop putting comments in the middle of call chains
`rustfmt` doesn't handle this very well.
2024-05-16 16:17:40 -07:00
Charles Hall
1911ad34d9
stop putting comments and code on the same line 2024-05-16 15:22:35 -07:00
Charles Hall
0915aba44c
remove commented-out code 2024-05-16 15:20:56 -07:00
Charles Hall
d3b7eecaed
swap commented code for prose about "ownership"
This more clearly communicates the purpose of the comments, and thus
also the order of fields in the struct.
2024-05-16 15:20:55 -07:00
Charles Hall
f8420883a1
expand abbreviation for clarity
This looked like a typo before.
2024-05-16 15:20:26 -07:00
Charles Hall
de662a88f5
clarify the meaning of this comment 2024-05-16 01:08:48 -07:00
Charles Hall
bac8b34faf
clarify comments about lazy loading 2024-05-16 01:08:48 -07:00
Charles Hall
3efe3fb337
remove comments about filtering buggy items 2024-05-16 01:08:48 -07:00