Expand description
Backpressure-controlled streaming over REPE notifies.
When you need to push a large payload from the server to a peer
over REPE (multi-GB capture files, log streams, query results
that don’t fit in one message), the protocol gives you notify
frames but no flow control. This module adds the missing pieces:
- ACK-driven window credit. The producer waits before sending
if the receiver is more than
window_bytesbehind on ACKs; when an ACK arrives the producer wakes and resumes. - Idle watchdog. A transfer that has gone silent for longer
than
idle_timeoutis force-cancelled so a wedged peer can’t leak server resources. - Replay ring + reconnect. The producer keeps a byte-bounded
ring of recently-emitted bodies; on a brief WS disconnect it
parks until the peer reconnects and calls
TransferControl::request_resumewith alast_received_offset, then re-emits the ring tail through the new peer.
The protocol itself (the wire shape of transfer_begin /
file_chunk / transfer_ack / etc.) is up to you: this module
deals only in offsets, ACKs, and opaque body bytes. The concrete
embedding – how each chunk reaches the wire – lives in your
transport’s sink; a PeerHandle from the built-in
WebSocketServer is one such sink.
§Lifecycle
- Build a
TransferControlwith a window size and replay ring capacity. Install the initial peer withset_peer. - Register the control under your transfer-id type in a
TransferRegistryso inbound ACK / cancel / resume handlers can find it. - The producer thread, for each chunk:
wait_for_creditforchunk_lenbytes,- encode the body and call
push_replaywith the logicaldata_lenof the chunk and the wire body, - read the current
peerand callpeer.send_notify(...), - on
Okcallrecord_sent(new_offset), - on
Err(PeerSendError::Disconnected)callwait_for_reconnect; onReconnectOutcome::ResumeReadyre-emit ring chunks starting at the returnedresume_at_offsetthrough the new peer.
- Inbound ACK handlers call
record_ack; cancel callscancel; resume callsrequest_resume. - At each file (or whatever your chunked unit is) boundary, call
advance_to_fileto reset offsets and clear the ring. - When the transfer ends, call
TransferRegistry::unregister.
Structs§
- Pending
Resume - Resume request published by the inbound resume handler and
consumed by the producer thread on its next call to
TransferControl::wait_for_reconnect. - Ring
Chunk - One entry in the replay ring.
- Transfer
Control - Per-transfer control: credit window, ACK accounting, replay ring, peer slot, cancel flag, idle timestamps.
- Transfer
Registry - Table of in-flight transfers indexed by an embedder-chosen key
type
K(typically a transfer-id newtype).
Enums§
- Credit
Error - Why
TransferControl::wait_for_creditreturned without granting credit. The caller maps this to an error so the producer pipeline aborts cleanly. - Reconnect
Outcome - Outcome of
TransferControl::wait_for_reconnect. The producer uses this to decide whether to swap in a new peer + replay, give up because of cancel, or give up because the reconnect window expired. - Resume
Rejection - Why
TransferControl::request_resumerejected a resume. The embedder maps these to wire strings on its resume reply.
Constants§
- DEFAULT_
BACKPRESSURE_ TIMEOUT - Default per-chunk credit timeout. If
TransferControl::wait_for_credithasn’t been released by an ACK in this long, the producer should abort the transfer. - DEFAULT_
IDLE_ TIMEOUT - Default idle-transfer threshold. If neither a chunk has been sent nor an ACK received in this long, the watchdog force-cancels the transfer.
- DEFAULT_
RECONNECT_ TIMEOUT - Default reconnect window. After a disconnect the producer parks
on
TransferControl::wait_for_reconnectfor at most this long before giving up. - DEFAULT_
REPLAY_ RING_ BYTES - Default replay ring capacity (per active file). 64 MiB worth of recent bodies, FIFO-evicted; sized so a brief WS drop can replay the whole window.
- DEFAULT_
WINDOW_ BYTES - Default in-flight wire bytes per transfer the producer allows before it must wait on receiver ACKs. 64 MiB is a reasonable starting point for LAN-class links; lower it on slow links.
Functions§
- spawn_
watchdog - Spawn a background thread that scans
registryperiodically and firesTransferControl::cancel(“transfer idle”) on any transfer whose last chunk and last ACK are both older thanidle_timeout.