cultnet-rs: receipts refuse an expiring channel (P9); the window test asserts full and drains; doc marks P9, P10 addressed

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-28 11:01:31 +01:00
commit cf884569ac
3 changed files with 59 additions and 15 deletions

View file

@ -157,8 +157,8 @@ And places where the sender loses track, or is locked out, without the receiver'
| G1 | A restarted client on the same endpoint and Connect payload gets an Ack, never an Accept, and stays unconnected | Rust hub, C# listener and C# server mode, TS and Python server mode (Rust server mode resets on every Connect instead) | Cut 1c |
| G1b | C# and Python server-mode transports drop a Connect from any endpoint but the first, so a client that restarts on a new port is locked out for good | C#, Python | Cut 1c |
| P2 | An expired reliable packet leaves a permanent hole. Ordered frames after it are held forever, and `flush_reliable` succeeds (outstanding 0) | Rust (the only runtime with reliable expiry) | Cut F (FORWARD-TSN, Q-A3 B); Cut 4 reports it honestly where a receiver never acknowledges the notice |
| P9 | A receipt for an expiring send reads `Acknowledged` once the packet expires unacknowledged | Rust | Cut 4 |
| P10 | `send_reliable` with a full window queues the frame, then returns an error ("receipts require a non-empty reliable packet set"), so a caller that retries sends it twice | Rust | Cut 4 |
| P9 | A receipt for an expiring send reads `Acknowledged` once the packet expires unacknowledged | Rust | Cut 4 (guard landed) |
| P10 | `send_reliable` with a full window queues the frame, then returns an error ("receipts require a non-empty reliable packet set"), so a caller that retries sends it twice | Rust | Cut 4 (receipt over queued sequences landed) |
And two faults found by Soul passes during pass 3:
@ -208,8 +208,8 @@ Pass 2 (base `3bf1c0c`; mirror `CultLib-imag-ack2`):
| P5 | 3-fragment reliable frame, 2 fragments acked; 70 lossy fragment sets; last fragment arrives | Rust, TS, Python: never delivered, sender pending `[]` | Same, Rust, TS, Python | Unchanged (Cut 2) |
| P7 | An Ack with flag bit `0x10`, a nonzero sequence field, or a 5-byte payload | Decoded and applied in Rust, C#, TS, Python | Same, all four | n/a |
| P8 | Reliable `g` lost while 4,200+ later sequences are sent and acked; then `g` arrives | `g` not delivered, and acknowledged. All four | Same, all four | Unchanged (Cut 3) |
| P9 | Rust socket: `send_reliable("media")` with expiry 1 ms, never read | `Pending`, then `Acknowledged` | Same | `Pending` |
| P10 | Rust socket: 40 `schema` sends, then `send_reliable` | Error "receipts require a non-empty reliable packet set", after the frame was queued | Same (the probe's `?` fails on that error) | Not addressed (Cut 4) |
| P9 | Rust socket: `send_reliable("media")` with expiry 1 ms, never read | `Pending`, then `Acknowledged` | Same | Refused: `send_reliable` takes only a non-expiring reliable channel. Addressed (Cut 4) |
| P10 | Rust socket: 40 `schema` sends, then `send_reliable` | Error "receipts require a non-empty reliable packet set", after the frame was queued | Same (the probe's `?` fails on that error) | A receipt covering the queued sequences, `Pending` until acknowledged; the frame is sent once. Addressed (Cut 4) |
| G1 | Client A connects, sends one ordered frame (acknowledging the Accept), and exits. Client B, a fresh session with the same initial sequence, binds A's exact address and sends the same Connect payload five times | n/a | **Locked out.** Rust hub (payload `"svc"` and empty): 5 Acks, 0 Accepts, B unconnected, the hub still holds A's generation. C# listener: same, no `PeerDisconnected`. C# server mode: 5 Acks. Python server mode: 5 Acks. TS session: the answer is an Ack. Rust server mode (control): B gets an Accept and its frame is delivered, because it resets on every Connect | Not probed |
| G1b | C# and Python server mode: a third client on a new port sends a Connect | n/a | No reply; the datagram is counted dropped | Not probed |
| G2 | Client connects to server 1 (initial sequence 1) and receives `old1..3`. Server 1 is gone; the client connects again on the same session to server 2 (initial sequence 1), which sends `new1`, `new2` | n/a | **`new1`, `new2` never delivered, and acknowledged** (server 2's pending set empties). C#, Rust, TS, Python | Not probed |

View file

@ -2246,9 +2246,9 @@ impl CultNetRudpSocketTransportConnection {
channel_reliable_expire_after_ms(&self.profile, channel_id),
channel_delivery(&self.profile, channel_id),
);
// This lineage has no reliable-expiry concept, so every reliable channel is
// already non-expiring. Restore the expiry half of this guard if one is added.
if !options.reliable {
// An expiring packet can be dropped unsent or unacknowledged, and a
// receipt cannot tell that from delivery: refuse the channel.
if !options.reliable || options.reliable_expire_after_ms.is_some() {
return Err(anyhow!(
"RUDP acknowledgement receipts require a non-expiring reliable channel"
));

View file

@ -517,6 +517,13 @@ fn connected_client(
server_socket: &UdpSocket,
server_addr: SocketAddr,
) -> Result<CultNetRudpSocketTransportConnection> {
Ok(connected_client_and_session(server_socket, server_addr)?.0)
}
fn connected_client_and_session(
server_socket: &UdpSocket,
server_addr: SocketAddr,
) -> Result<(CultNetRudpSocketTransportConnection, CultNetRudpSession)> {
let mut client = CultNetRudpSocketTransportConnection::new(CultNetRudpSocketTransportOptions::client(
"client",
socket()?,
@ -533,11 +540,12 @@ fn connected_client(
break (packet, from);
}
};
let accept = session(500).accept_connect(&connect, 0, Vec::new())?;
let mut server_session = session(500);
let accept = server_session.accept_connect(&connect, 0, Vec::new())?;
server_socket.send_to(&encode_rudp_packet(&accept)?, client_addr)?;
client.receive_once()?;
assert!(client.connected());
Ok(client)
Ok((client, server_session))
}
/// A receipt belongs to the transport that issued it: asked of another
@ -1024,17 +1032,53 @@ fn the_hub_admits_a_pinned_client_that_restarts_on_the_same_address() -> Result<
/// A send that lands behind a full flow window is queued, not refused: it gets
/// a receipt for the sequence it was assigned, and the receipt reads Pending
/// while the packet is still queued. (Slow acknowledgements fill the window on
/// a loaded host; a silent peer fills it here without a clock.)
/// while the packet is still queued. A silent peer fills the window without a
/// clock.
#[test]
fn a_send_queued_behind_a_full_window_returns_a_pending_receipt() -> Result<()> {
let server = socket()?;
let server_addr = server.local_addr()?;
let mut client = connected_client(&server, server_addr)?;
let (mut client, mut session) = connected_client_and_session(&server, server_addr)?;
let mut receipts = Vec::new();
for _ in 0..CULTNET_RUDP_RELIABLE_SEND_WINDOW_PACKETS {
client.send_reliable("schema", b"fill".to_vec())?;
receipts.push(client.send_reliable("schema", b"fill".to_vec())?);
}
let receipt = client.send_reliable("schema", b"queued".to_vec())?;
assert_eq!(client.reliable_send_status(&receipt), CultNetRudpReliableSendStatus::Pending);
assert_eq!(client.outstanding_reliable_packet_count(), CULTNET_RUDP_RELIABLE_SEND_WINDOW_PACKETS);
let queued = client.send_reliable("schema", b"queued".to_vec())?;
assert_eq!(client.outstanding_reliable_packet_count(), CULTNET_RUDP_RELIABLE_SEND_WINDOW_PACKETS + 1);
assert_eq!(client.reliable_send_status(&queued), CultNetRudpReliableSendStatus::Pending);
// Drain: the server acknowledges every packet it sees; the queued one then
// goes out and is acknowledged too.
let mut buffer = vec![0_u8; 65_535];
for _ in 0..200 {
if let Ok((received, from)) = server.recv_from(&mut buffer) {
let packet = decode_rudp_packet(&buffer[..received])?;
if packet.packet_type == CultNetRudpPacketType::Data {
let result = session.receive(&packet, 0)?;
if let Some(reply) = result.reply {
server.send_to(&encode_rudp_packet(&reply)?, from)?;
}
}
}
client.poll_resends()?;
while client.receive_once()?.is_some() {}
if client.reliable_send_status(&queued) == CultNetRudpReliableSendStatus::Acknowledged {
break;
}
}
assert_eq!(client.reliable_send_status(&queued), CultNetRudpReliableSendStatus::Acknowledged);
assert!(receipts.iter().all(|r| client.reliable_send_status(r) == CultNetRudpReliableSendStatus::Acknowledged));
Ok(())
}
/// An expiring channel cannot give a receipt: a queued packet that expires
/// unsent would otherwise read Acknowledged.
#[test]
fn a_receipt_is_refused_on_an_expiring_channel() -> Result<()> {
let server = socket()?;
let server_addr = server.local_addr()?;
let mut client = connected_client(&server, server_addr)?;
assert!(client.send_reliable("media", b"m".to_vec()).is_err());
assert_eq!(client.outstanding_reliable_packet_count(), 0, "a refused send queues nothing");
Ok(())
}