Skip to content
dream-net
api

TransportConfig

Every packet size, timer, limit and smoothing factor, with its default and its rule; validation; and the datagram constants.

Module dream_net::config. TransportConfig is re-exported from the root.

struct TransportConfig { ... }

The runtime network profile a Server, Client or Shared is created with. It bounds memory and shapes what reaches netcode, and it need not match between peers: unlike the schema, it is not fingerprinted. All fields are public; build one with struct update syntax over Default. Clone, Debug, PartialEq.

Packets#

FieldDefaultMeaning
max_packet_size: usize32768The largest connection packet. It bounds the largest single event. Must be at least fragment_above, and need at most 256 fragments
fragment_above: usize1191Packets larger than this are fragmented. Must be 1 to MAX_UNFRAGMENTED_PACKET
fragment_size: usize1186Payload bytes per fragment. Must be 1 to MAX_FRAGMENT_SIZE
packet_budget: usize1191The size events are packed up to. An event larger than it gets a packet of its own. The default equals fragment_above, so ordinary packets are never fragmented. Must be 1 to max_packet_size
max_packets_per_flush: usize64The most packets one connection writes per flush. Must be at least 1

Timers#

FieldDefaultMeaning
handshake_timeout: f645.0Seconds a new connection has to complete the handshake. Must be finite and above 0
mismatch_linger: f641.0Seconds a server keeps a client that failed with a schema or protocol mismatch, sending only its hello, so the client can report the mismatch itself. 0 disconnects at once. Must be finite and not negative
idle_packet_interval: f640.1The longest gap between packets a connection sends. 0 sends one every flush. Must be finite and not negative

Memory#

FieldDefaultMeaning
max_pending_events: usize4096Received events waiting to be polled, per connection. Must be at least 1
max_pending_bytes: usize4 MiBReceived payload bytes waiting to be polled, per connection. Must hold the schema’s largest payload
max_parked_bytes: usize1 MiBBytes of reliable events held behind a gap, per connection, charged by real allocation. Must hold the largest reliable payload plus 2 × PARK_OVERHEAD
max_pooled_bytes: usize64 KiBBytes of recycled payload buffers each channel keeps
malformed_limit: u321Malformed packets tolerated before the peer is disconnected. Must be at least 1

Past the pending limits, unreliable events are dropped and a reliable event next in order is refused, its packet left unacknowledged to be resent. Memory and backpressure explains the parked budget and the ceiling the three together put on a connection.

reliable’s tracking#

FieldDefaultMeaning
sent_packets_buffer_size: usize256Sent packets tracked for acknowledgements, loss and bandwidth. Events stop being added when half are in flight. Must be a power of two, at most 32768
received_packets_buffer_size: usize256Received packets tracked; also reliable’s duplicate window. Must be a power of two, at most 32768; see below
fragment_reassembly_buffer_size: usize16Packets that may be reassembling at once. Must be at least 1
rtt_history_size: usize128Round-trip samples kept for the minimum, maximum, average and jitter. reliable rescans them every update, so this is most of an idle connection’s cost; reliable’s own default is 512. Must be at least 1
rtt_smoothing_factor: f320.0025Exponential smoothing of the RTT. Must be above 0 and at most 1
packet_loss_smoothing_factor: f320.1Exponential smoothing of the loss. Must be above 0 and at most 1
bandwidth_smoothing_factor: f320.1Exponential smoothing of the bandwidth. Must be above 0 and at most 1
packet_header_size: usize28Assumed IP and UDP header bytes per packet, for bandwidth statistics only

received_packets_buffer_size × max_messages_per_packet + 2 × the schema’s largest reliable window must not exceed 65536, so that a stale message id arriving late can never wrap around into the window and pass for a new one. With the defaults that is 256 × 64 + 2 × 1024 = 18432.

Methods#

fn validate(&self) -> Result<(), ConfigError>

Checks every rule that does not depend on a schema, returning ConfigError::Transport with a message naming the first bad value. Once it passes, no packet dream-net builds can trip one of reliable’s assertions, and every datagram fits netcode.

fn validate_for(&self, schema: &Schema) -> Result<(), ConfigError>

validate, then the rules that do: every event’s max_payload fits one max_packet_size packet with worst-case framing around it (EventTooLarge otherwise, with the limit), the stale-id rule above, max_pending_bytes, and max_parked_bytes when the schema has a reliable channel. Server::new, Client::new and Shared::new call it.

fn max_fragments(&self) -> usize

How many fragments the largest packet needs: max_packet_size divided by fragment_size, rounded up.

fn reliable_config(&self, name: &str) -> reliable::Config

The configuration of the reliable endpoint each connection creates, named name, with an acknowledgement buffer of 64.

use dream_net::{ConfigError, TransportConfig};

fn main() {
    let config = TransportConfig { max_pending_events: 256, ..TransportConfig::default() };
    assert!(config.validate().is_ok());
    assert_eq!(config.max_fragments(), 28);

    let odd = TransportConfig { sent_packets_buffer_size: 300, ..TransportConfig::default() };
    assert_eq!(
        odd.validate(),
        Err(ConfigError::Transport("sent_packets_buffer_size must be a power of two <= 32768"))
    );
}

Constants#

ConstantValueMeaning
DATAGRAM_BYTES: usize1200The largest payload netcode carries in one datagram
MAX_UNFRAGMENTED_PACKET: usize1191The largest connection packet that fits one datagram with reliable’s header
MAX_FRAGMENT_SIZE: usize1186The largest fragment that fits one datagram with reliable’s packet and fragment headers