Commit graph

2379 commits

Author SHA1 Message Date
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
Charles Hall
40f9aa6f60
remove stale comments
Should've been removed in 98f1480e2b.
2024-05-15 23:45:54 -07:00
Charles Hall
034169bb8a
remove obvious comments 2024-05-15 16:43:52 -07:00
Charles Hall
f9f066417b
remove pointless else branch 2024-05-15 16:43:52 -07:00
Charles Hall
46731d1f85
how did clippy not catch this 2024-05-15 15:54:12 -07:00
Lambda
4aab4c9b2e
service/appservice: fix weird indirection through global services 2024-05-14 20:21:51 -07:00
Lambda
ad7a5ea777
Remove useless wrapper Services 2024-05-14 20:21:51 -07:00
Lambda
87a1012ab5
Replace Box::into_pin(Box::new( with Box::pin( 2024-05-14 20:21:51 -07:00
Charles Hall
509b70bd82
use the version function for s2s API too
This way the extra version information can appear there as well. Mainly
useful for showing off :P
2024-05-14 20:21:51 -07:00
Charles Hall
a25f2ec950
add conduit compat mode
This makes it possible to deploy Grapevine while using a database
originally created by Conduit, including leaving the admin bot user's
localpart the same as before.
2024-05-14 20:21:51 -07:00
Charles Hall
33e7a46b53
add a nixos module 2024-05-14 20:21:51 -07:00
Charles Hall
17eb354590
prevent bindgen and dependents from building twice
See also <https://crane.dev/faq/rebuilds-bindgen.html>.
2024-05-14 20:21:51 -07:00
Charles Hall
21a4b9e5a1
only set GRAPEVINE_VERSION_EXTRA for final build
This prevents us from needing to recompile the dependencies when that
environment variable changes, which generally changes on every commit,
which is far more frequently than the dependencies are actually changed.
2024-05-14 20:21:51 -07:00
Charles Hall
bbb1a6fea4
make it easy to configure cargo profiles from nix
This way you can easily build in debug mode with Nix.
2024-05-14 20:21:51 -07:00
Charles Hall
51f9650ca7
make it easy to configure cargo features from nix
Users of the nix package can now just use `.override` to choose what
features they want.

This also makes RocksDB automatically use jemalloc when Grapevine is
configured to use jemalloc.
2024-05-14 20:21:51 -07:00
Charles Hall
09751227ea
get rocksdb via flake inputs
Flake lock file updates:

• Added input 'rocksdb':
    'github:facebook/rocksdb/bcf88d48ce8aa8b536aee4dd305533b3b83cf435' (2024-04-16)
2024-05-14 20:21:51 -07:00
Charles Hall
0f8d1a5ed7
factor out nix code into new files via makeScope
This makes the Nix code a lot easier to reason about.
2024-05-14 20:21:51 -07:00
Charles Hall
8d8d4425f3
always go through inputs
This way we don't have to modify the destructuring of `outputs`'
argument when adding or removing inputs.
2024-05-14 20:08:37 -07:00
Charles Hall
238bc85b1d
sort flake inputs 2024-05-14 20:08:37 -07:00
Charles Hall
17cb7732bd
flatten flake inputs 2024-05-14 20:08:37 -07:00