Skip to main content

ProtocolConfig

Struct ProtocolConfig 

Source
pub struct ProtocolConfig {
    pub quality_report_interval: Duration,
    pub shutdown_delay: Duration,
    pub max_checksum_history: usize,
    pub pending_output_limit: usize,
    pub sync_retry_warning_threshold: u32,
    pub sync_duration_warning_ms: u128,
    pub input_history_multiplier: usize,
    pub protocol_rng_seed: Option<u64>,
}
Expand description

Configuration for network protocol behavior.

These settings control network timing, buffering, and telemetry thresholds. The defaults work well for most scenarios; adjust for specific requirements.

§Forward Compatibility

New fields may be added to this struct in future versions. To ensure your code continues to compile, always use the ..Default::default() or ..ProtocolConfig::default() pattern when constructing instances.

§Example

use fortress_rollback::ProtocolConfig;
use web_time::Duration;

// For competitive/LAN play, use faster quality reports
let competitive_config = ProtocolConfig {
    quality_report_interval: Duration::from_millis(100),
    shutdown_delay: Duration::from_millis(3000),
    ..ProtocolConfig::default()
};

// For debugging, use longer timeouts and lower thresholds
let debug_config = ProtocolConfig {
    shutdown_delay: Duration::from_millis(10000),
    sync_retry_warning_threshold: 5,
    sync_duration_warning_ms: 1000,
    ..ProtocolConfig::default()
};

Fields§

§quality_report_interval: Duration

Interval between network quality reports.

Lower values provide more responsive network stats but increase bandwidth usage slightly. The quality report is a small packet that measures RTT.

Default: 200ms

§shutdown_delay: Duration

Time to wait in Disconnected state before transitioning to Shutdown.

This delay allows for graceful cleanup and final message delivery. After this timeout, the protocol will no longer process messages.

Default: 5000ms

§max_checksum_history: usize

Number of checksums to retain for desync detection history.

Higher values can detect older desyncs but use more memory. Only relevant when desync detection is enabled.

Default: 32

§pending_output_limit: usize

Maximum pending output messages before warning.

When pending outputs exceed this limit, it indicates the peer isn’t acknowledging inputs quickly enough. This may suggest network congestion or peer disconnection.

Default: 128

§sync_retry_warning_threshold: u32

Threshold for emitting sync retry warnings.

Emits a telemetry warning when sync requests exceed this number. With 5 required roundtrips and 200ms retry interval, this threshold represents roughly 50% sustained packet loss over multiple retries.

Default: 10

§sync_duration_warning_ms: u128

Threshold for emitting sync duration warnings in milliseconds.

Emits a telemetry warning when synchronization takes longer than this. Typical sync should complete in ~1 second for good connections.

Default: 3000ms

§input_history_multiplier: usize

Multiplier for input history retention.

Determines how many frames of received input history to retain. The protocol keeps inputs for input_history_multiplier * max_prediction frames behind the most recent received frame. This allows for packet reordering and delayed decoding without losing the ability to decode old packets.

Higher values use more memory but are more tolerant of extreme packet reordering.

Default: 2

§protocol_rng_seed: Option<u64>

Optional seed for protocol RNG, enabling deterministic behavior.

When set to Some(seed), the protocol will use a deterministic RNG seeded with this value for generating:

  • Session magic numbers (protocol identifiers)
  • Sync request validation tokens

This enables fully reproducible network sessions, which is useful for:

  • Replay systems
  • Deterministic testing
  • Debugging network issues

When None (the default), the protocol uses non-deterministic random values for security (harder to predict session IDs) and uniqueness (different magic numbers for each session).

§Example

use fortress_rollback::ProtocolConfig;

// For deterministic testing
let config = ProtocolConfig {
    protocol_rng_seed: Some(12345),
    ..ProtocolConfig::default()
};

// Or use the deterministic preset
let config = ProtocolConfig::deterministic(42);

Default: None (non-deterministic)

Implementations§

Source§

impl ProtocolConfig

Source

pub fn new() -> Self

Creates a new ProtocolConfig with default values.

Source

pub fn competitive() -> Self

Configuration preset for competitive/LAN play.

Uses faster quality reports and shorter shutdown delay for more responsive network stats and quicker cleanup.

Source

pub fn high_latency() -> Self

Configuration preset for high-latency WAN connections.

Uses longer intervals and more tolerant thresholds to reduce unnecessary warnings on slower connections.

Source

pub fn debug() -> Self

Configuration preset for debugging.

Uses longer timeouts and lower warning thresholds to make it easier to observe telemetry events during development.

Source

pub fn mobile() -> Self

Configuration preset for mobile/cellular networks.

Mobile networks have high variability and frequent temporary disconnections during handoffs. This preset is more tolerant of sync delays and allows for larger output buffers.

Characteristics addressed:

  • High jitter requiring more buffering
  • Connection handoffs during WiFi/cellular switches
  • Higher than normal retry expectations
Source

pub fn deterministic(seed: u64) -> Self

Configuration preset for deterministic/reproducible sessions.

Uses a fixed RNG seed to ensure protocol behavior is reproducible across runs. This is essential for:

  • Replay systems
  • Deterministic testing
  • Debugging network issues
  • Cross-platform consistency
§Arguments
  • seed - The RNG seed for protocol randomness
§Example
use fortress_rollback::ProtocolConfig;

// Create a deterministic config with seed 42
let config = ProtocolConfig::deterministic(42);
assert_eq!(config.protocol_rng_seed, Some(42));
Source

pub fn validate(&self) -> Result<(), FortressError>

Validates the protocol configuration.

§Errors

Returns a FortressError if any configuration value is out of range.

Trait Implementations§

Source§

impl Clone for ProtocolConfig

Source§

fn clone(&self) -> ProtocolConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ProtocolConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ProtocolConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for ProtocolConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for ProtocolConfig

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ProtocolConfig

Source§

fn eq(&self, other: &ProtocolConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ProtocolConfig

Source§

impl Eq for ProtocolConfig

Source§

impl StructuralPartialEq for ProtocolConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more