Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSC4108 4KB maximum + 60 second TTL #17113

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions rust/src/rendezvous/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

use std::{
collections::BTreeMap,
collections::{BTreeMap, HashMap},
time::{Duration, SystemTime},
};

Expand Down Expand Up @@ -57,6 +57,7 @@ struct RendezvousHandler {
sessions: BTreeMap<Ulid, Session>,
capacity: usize,
max_content_length: u64,
ttl: Duration,
}

impl RendezvousHandler {
Expand Down Expand Up @@ -94,13 +95,14 @@ impl RendezvousHandler {
#[pymethods]
impl RendezvousHandler {
#[new]
#[pyo3(signature = (homeserver, /, capacity=100, max_content_length=1024*1024, eviction_interval=60*1000))]
#[pyo3(signature = (homeserver, /, capacity=100, max_content_length=1024*1024, eviction_interval=60*1000, ttl=60*1000))]
fn new(
py: Python<'_>,
homeserver: &PyAny,
capacity: usize,
max_content_length: u64,
eviction_interval: u64,
ttl: u64,
) -> PyResult<Py<Self>> {
let base: String = homeserver
.getattr("config")?
Expand All @@ -122,6 +124,7 @@ impl RendezvousHandler {
sessions: BTreeMap::new(),
capacity,
max_content_length,
ttl: Duration::from_millis(ttl),
},
)?;

Expand Down Expand Up @@ -165,7 +168,7 @@ impl RendezvousHandler {

let body = request.into_body();

let session = Session::new(body, content_type, now, Duration::from_secs(5 * 60));
let session = Session::new(body, content_type, now, self.ttl);

let response = serde_json::json!({
"url": uri,
Expand Down Expand Up @@ -242,11 +245,17 @@ impl RendezvousHandler {
let mut headers = HeaderMap::new();
prepare_headers(&mut headers, session);

let mut additional_fields = HashMap::with_capacity(1);
additional_fields.insert(
String::from("org.matrix.msc4108.errcode"),
String::from("M_CONCURRENT_WRITE"),
);

return Err(SynapseError::new(
StatusCode::PRECONDITION_FAILED,
"ETag does not match".to_owned(),
"M_CONCURRENT_WRITE",
None,
"M_UNKNOWN", // Would be M_CONCURRENT_WRITE
Option::from(additional_fields),
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
Some(headers),
));
}
Expand Down
3 changes: 2 additions & 1 deletion synapse/synapse_rust/rendezvous.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class RendezvousHandler:
homeserver: HomeServer,
/,
capacity: int = 100,
max_content_length: int = 1024 * 1024,
max_content_length: int = 4 * 1024, # the MSC specifies 4KB
anoadragon453 marked this conversation as resolved.
Show resolved Hide resolved
eviction_interval: int = 60 * 1000,
ttl: int = 60 * 1000,
) -> None: ...
def handle_post(self, request: IRequest) -> None: ...
def handle_get(self, request: IRequest, session_id: str) -> None: ...
Expand Down
9 changes: 6 additions & 3 deletions tests/rest/client/test_rendezvous.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ def test_msc4108(self) -> None:
)

self.assertEqual(channel.code, 412)
self.assertEqual(channel.json_body["errcode"], "M_CONCURRENT_WRITE")
self.assertEqual(channel.json_body["errcode"], "M_UNKNOWN")
self.assertEqual(
channel.json_body["org.matrix.msc4108.errcode"], "M_CONCURRENT_WRITE"
)

# If we try to get with the old etag, we should get the updated data
channel = self.make_request(
Expand Down Expand Up @@ -270,8 +273,8 @@ def test_msc4108_expiration(self) -> None:
self.assertEqual(channel.code, 200)
self.assertEqual(channel.text_body, "foo=bar")

# Advance the clock, TTL of entries is 5 minutes
self.reactor.advance(300)
# Advance the clock, TTL of entries is 1 minute
self.reactor.advance(60)

# Get the data back, it should be gone
channel = self.make_request(
Expand Down
Loading