fix(collab-net): keep the client's message cap in range on 32-bit targets

This commit is contained in:
sushi-killer
2026-10-17 00:37:55 +03:00
parent b0f56ed169
commit 1b4db71957
2 changed files with 7 additions and 4 deletions
+4 -2
View File
@@ -506,6 +506,8 @@ fn files_above_64_mib_fit_every_limit() {
assert!(net.max_reading_total >= net.max_reading_block && net.max_queued_total >= net.max_queued_block);
assert!(core.max_message_bytes > file, "open={open_publish}: {}", core.max_message_bytes);
}
// A client takes the largest file any server can keep.
assert!(NetLimits::default().max_server_message > 4096 << 20);
// A client takes the largest file any server can keep, or as much as a 32-bit target can address
// (computed in u64: `4097 << 20` in a 32-bit usize wraps to 1 MiB).
let client = NetLimits::default().max_server_message as u64;
assert!(client > 4096 << 20 || client == u64::from(u32::MAX), "{client}");
}
+3 -2
View File
@@ -14,7 +14,8 @@ pub struct NetLimits {
pub max_hello: usize,
/// Largest message a client accepts from the host (a welcome carries the whole document): the
/// largest file a `figcraft-server` can be set to keep (`max_file_mb`, at most 4096) and a margin,
/// so a client can open every file a server takes.
/// so a client can open every file a server takes; on a 32-bit target (the browser) as much as
/// `usize` holds.
pub max_server_message: usize,
/// Messages a client may send per second on average, and in a burst; beyond that it is
/// disconnected.
@@ -63,7 +64,7 @@ impl Default for NetLimits {
max_connections: 64,
max_client_message: figcraft_collab::Limits::default().max_message_bytes,
max_hello: 64 << 10,
max_server_message: 4097 << 20,
max_server_message: usize::try_from(4097u64 << 20).unwrap_or(usize::MAX),
rate: 100.0,
burst: 400.0,
hello_timeout: Duration::from_secs(10),