Crate net

Source
Expand description

Bounded, versioned network protocol shared by native and browser game clients.

The protocol never accepts client positions or client-selected time steps. Native UDP is intentionally a thin primitive: accounts/encryption and NAT traversal remain outside this prototype. The first-party WebSocket gateway carries browser datagrams to the same authority.

Modules§

baselines
Bounded, separate sent and installed snapshot histories.
clock
Correlated clock probes and a bounded interpolation delay. All times are supplied explicitly, making jitter/loss/reorder behavior testable offline.
delta
Versioned byte snapshot differences. Callers acknowledge exact baselines before using a delta.
history
Bounded authority history and clock estimates; rendering and transport are independent.
local_link
Bounded, independently instantiated supplied-time datagram router.
reliable
Bounded ordered event delivery over an unreliable transport. This is not encryption.
time
Transport clock shared by native sockets and browser hosts. Browser hosts explicitly supply monotonic microseconds; no unsupported Wasm OS clock call.
udp
Native sockets are optional by target; packet codecs remain available on wasm.
websocket
Bounded binary WebSocket transport for native/browser development sessions. First-party RFC 6455 handshake/framing; no extensions, text messages or TLS. The handshake SHA-1 is required by the protocol, never used for authentication. References: https://www.rfc-editor.org/rfc/rfc6455 and https://www.rfc-editor.org/rfc/rfc3174.

Structs§

InputFrame
InputQueue
Deduplicates input redundancy and bounds per-client simulation backlog.
InputQueueMetrics
Queue-local activity since creation or the last InputQueue::reset_metrics.
PlayerSnapshot
Snapshot
TimedInput

Enums§

BorrowedEvent
Borrowed v5 reliable/tactical envelope for an reliable::EventSender::send_due callback. Uses the owned packet codec, without cloning an EventPacket or its payload. Both wire families add 24 bytes to the payload; reliable events accept empty payloads, commands require 1..=900 bytes. No sequence policy or application payload validation is added; validate the outer session and game payload before receiver admission. Safe Rust requires disjoint output/input.
ClientExtension
ClientPacket
EncodeError
Rejection from packet encoding. Field paths are stable diagnostic names; indices identify a zero-based input/player/epoch, never a byte offset.
InputAdmissionError
Reason a checked input admission was rejected.
ProtocolError
ServerExtension
ServerPacket

Constants§

BUTTON_FIRE
BUTTON_JUMP
BUTTON_RELOAD
MAX_INPUTS_PER_PACKET
MAX_PACKET_BYTES
MAX_PITCH
MAX_PLAYERS
MAX_QUEUED_INPUTS
PROTOCOL_VERSION
Version 4 adds timed inputs, clock exchanges, snapshot ACK/deltas and commands.

Functions§

decode_client
decode_server
encode_client
Allocating compatibility wrapper using the same validated v5 writer as encode_client_into. Accepted inputs, bytes and ProtocolError mapping are unchanged; returned Vec capacity is unspecified.
encode_client_into
Encode v5 into a disjoint caller slice without allocating. Success initializes exactly the returned prefix and leaves the tail untouched. Every error leaves the entire destination unchanged. Capacity means slice length, not any underlying Vec capacity; there is no internal scratch packet or retained state.
encode_server
Allocating compatibility wrapper for encode_server_into.
encode_server_into
Server counterpart of encode_client_into, with identical atomicity, tail, allocation and capacity guarantees. Preserves exact v5 float bits.
encoded_client_len
Exact v5 wire length after validating every client field; allocates nothing. Includes the six-byte header and session/envelope overhead. See encode_client_into for the shared validation/precedence contract.
encoded_server_len
Exact validated v5 server wire length, without allocation. Inner delta bytes remain opaque: only outer tick ordering and byte length are checked, matching the legacy encoder/decoder. Does not authenticate/install/ACK a snapshot.
sequence_newer
RFC-1982-style comparison. Exactly half a sequence space is ambiguous and rejected.