diff --git a/packages/cultmesh-rs/src/rudp_document_server.rs b/packages/cultmesh-rs/src/rudp_document_server.rs index 00dc37db..34794fc5 100644 --- a/packages/cultmesh-rs/src/rudp_document_server.rs +++ b/packages/cultmesh-rs/src/rudp_document_server.rs @@ -11,6 +11,9 @@ use std::net::{SocketAddr, UdpSocket}; use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH}; const MAX_UDP_DATAGRAM_BYTES: usize = 65_535; +/// The shortest message id CultNet encodes: one character. A snapshot request +/// can carry no shorter id, so no response to it can be smaller. +const SHORTEST_MESSAGE_ID: &str = "0"; /// The transport identity of one remote CultNet RUDP session. /// @@ -186,7 +189,7 @@ pub enum CultMeshRudpRejectionReason { /// The caller's sink refused the document. Carries the sink's error text. SinkRefused(String), /// The document could never be served: a snapshot response carrying it - /// alone, with an empty message id, would exceed + /// alone, under the shortest message id CultNet allows, would exceed /// `max_snapshot_response_bytes`. It was not offered to the sink. DocumentUnservable { response_bytes: usize, @@ -555,9 +558,9 @@ where }; // Admit only what some snapshot request can return: the smallest // response that could carry this document is the document alone - // under an empty message id, sized by the snapshot path's encoder. + // under the shortest message id CultNet encodes, sized by the snapshot path's encoder. let alone = CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: SHORTEST_MESSAGE_ID.into(), documents: vec![document], }; let response_bytes = match encode_snapshot_response(&alone) { diff --git a/packages/cultmesh-rs/tests/rudp_document_server.rs b/packages/cultmesh-rs/tests/rudp_document_server.rs index 2e51cb2d..1d338058 100644 --- a/packages/cultmesh-rs/tests/rudp_document_server.rs +++ b/packages/cultmesh-rs/tests/rudp_document_server.rs @@ -212,11 +212,12 @@ fn connect( } /// The encoded size of the snapshot response that carries `document` alone -/// under an empty message id: the smallest response that could ever serve it. +/// under a one-character message id, the shortest CultNet encodes: the +/// smallest response that could ever serve it. fn served_alone_bytes(document: &CultNetRawDocumentRecord) -> Result { Ok(encode_cultnet_message_to_vec( &CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: "r".into(), documents: vec![document.clone()], }, CultNetWireContract::CultNetSchemaV0, @@ -758,7 +759,7 @@ fn a_put_the_server_could_never_serve_is_refused_and_one_at_the_bound_is_served( send( &mut writer, &CultNetMessage::SnapshotRequest { - message_id: String::new(), + message_id: "r".into(), schema_ids: None, record_keys: None, }, @@ -781,7 +782,7 @@ fn a_put_the_server_could_never_serve_is_refused_and_one_at_the_bound_is_served( assert_eq!( decode_cultnet_message_from_slice(&served, CultNetWireContract::CultNetSchemaV0)?, CultNetMessage::SnapshotResponseRaw { - message_id: String::new(), + message_id: "r".into(), documents: vec![at_bound], } );