cultmesh-rs: size an admitted put under the shortest message id CultNet encodes
The served-size check built its response under an empty message id, which the CultNet encoder refuses, so every put was rejected as ResponseEncodingFailed. No snapshot request can carry an id shorter than one character, so a one-character id gives the smallest response that could ever serve the document; that is the size a put is now judged by. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
85288a5a47
commit
027bd8aa47
2 changed files with 11 additions and 7 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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<usize> {
|
||||
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],
|
||||
}
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in a new issue