Skip to main content

SyncConfig

Struct SyncConfig 

Source
pub struct SyncConfig {
    pub num_sync_packets: u32,
    pub sync_retry_interval: Duration,
    pub sync_timeout: Option<Duration>,
    pub running_retry_interval: Duration,
    pub keepalive_interval: Duration,
}
Expand description

Configuration for the synchronization protocol.

This struct allows fine-tuning the sync handshake behavior for different network conditions. The defaults work well for typical networks with <15% packet loss and <100ms RTT.

§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 ..SyncConfig::default() pattern when constructing instances.

§Example

use fortress_rollback::SyncConfig;
use web_time::Duration;

// For high-latency networks, increase retry intervals
let high_latency_config = SyncConfig {
    sync_retry_interval: Duration::from_millis(500),
    running_retry_interval: Duration::from_millis(500),
    keepalive_interval: Duration::from_millis(500),
    ..SyncConfig::default()
};

// For lossy networks, increase required roundtrips
let lossy_config = SyncConfig {
    num_sync_packets: 8,
    ..SyncConfig::default()
};

Fields§

§num_sync_packets: u32

Number of successful sync roundtrips required before considering the connection synchronized. Higher values provide more confidence but take longer to synchronize.

Default: 5

§sync_retry_interval: Duration

Time between sync request retries during the synchronization phase. If a sync request doesn’t receive a reply within this interval, another request is sent.

Default: 200ms

§sync_timeout: Option<Duration>

Maximum time to wait for synchronization to complete. If sync takes longer than this, a SyncTimeout event is emitted.

Default: None (no timeout)

§running_retry_interval: Duration

Time between input retries during the running phase. If we haven’t received an ack for our inputs within this interval, resend them.

Default: 200ms

§keepalive_interval: Duration

Time between keepalive packets when idle. Keepalives prevent disconnect timeouts during periods of no input.

Default: 200ms

Implementations§

Source§

impl SyncConfig

Source

pub fn new() -> Self

Creates a new SyncConfig with default values.

Source

pub fn high_latency() -> Self

Configuration preset for high-latency networks (100-200ms RTT).

Uses longer intervals to avoid flooding the network with retries.

Source

pub fn lossy() -> Self

Configuration preset for lossy networks (5-15% unidirectional packet loss).

Uses more sync packets for higher confidence and a sync timeout.

§Note on Packet Loss Math

When packet loss is applied bidirectionally (both send and receive), the effective loss rate compounds. For example:

  • 10% bidirectional loss = ~19% effective (1 - 0.9 × 0.9)
  • 15% bidirectional loss = ~28% effective (1 - 0.85 × 0.85)
  • 20% bidirectional loss = ~36% effective (1 - 0.8 × 0.8)
  • 30% bidirectional loss = ~51% effective (1 - 0.7 × 0.7)

For bidirectional loss rates > 20%, consider using Self::mobile() instead.

Source

pub fn lan() -> Self

Configuration preset for local network / LAN play.

Uses shorter intervals and fewer sync packets for faster connection.

Source

pub fn mobile() -> Self

Configuration preset for mobile/cellular networks.

Mobile networks have high variability, intermittent connectivity, and often switch between WiFi and cellular. This preset combines aspects of high_latency and lossy with additional tolerance.

Characteristics addressed:

  • High jitter (50-150ms variation)
  • Intermittent packet loss (5-20%)
  • Connection handoff during WiFi/cellular switches
  • Variable RTT (60-200ms)
Source

pub fn competitive() -> Self

Configuration preset for competitive/esports scenarios.

Prioritizes quick detection of network issues over tolerance. Assumes good network conditions and fails fast on problems.

Characteristics:

  • Fast sync handshake
  • Quick failure detection
  • Strict timeout for connection
Source

pub fn extreme() -> Self

Configuration preset for extreme/hostile network conditions (testing).

Designed for testing scenarios with very high packet loss, aggressive burst loss, or other extreme network impairments. Uses significantly more sync packets and longer timeouts to maximize chance of success.

This preset is not recommended for production use as it has very long timeouts that could delay error detection in real scenarios.

Characteristics addressed:

  • High burst loss (10%+ probability, 8+ packet bursts)
  • Combined high packet loss (>15%)
  • Extreme jitter and latency variation
  • Scenarios where multiple consecutive sync attempts may fail
§Example
use fortress_rollback::SyncConfig;

// For testing with aggressive burst loss
let config = SyncConfig::extreme();
assert_eq!(config.num_sync_packets, 20);
Source

pub fn stress_test() -> Self

Configuration preset for stress testing under the most hostile conditions.

This preset is specifically designed for automated testing scenarios where reliability is paramount, even at the cost of very long sync times. It uses aggressive parameters to survive the most hostile simulated network conditions.

ONLY USE FOR TESTING - These settings would cause unacceptable delays in production. The 60-second sync timeout means users would wait up to a full minute before connection failure is reported.

Characteristics addressed:

  • Extreme burst loss (10%+ probability with 8+ packet bursts)
  • Very high combined packet loss (>25%)
  • Multiple consecutive burst events during handshake
  • Slow CI environments with timing variability (macOS CI, coverage builds)
§Probability Analysis

With 10% burst probability and 8-packet bursts:

  • Each burst can drop 8 consecutive packets
  • With 150ms retry interval and 60s timeout: ~400 retry opportunities
  • With 40 required sync roundtrips spread across this window, the probability of success is very high even under worst-case conditions
§Example
use fortress_rollback::SyncConfig;

// For stress testing with extremely hostile network simulation
let config = SyncConfig::stress_test();
assert_eq!(config.num_sync_packets, 40);

Trait Implementations§

Source§

impl Clone for SyncConfig

Source§

fn clone(&self) -> SyncConfig

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 SyncConfig

Source§

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

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

impl Default for SyncConfig

Source§

fn default() -> Self

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

impl Display for SyncConfig

Source§

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

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

impl Hash for SyncConfig

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 SyncConfig

Source§

fn eq(&self, other: &SyncConfig) -> 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 SyncConfig

Source§

impl Eq for SyncConfig

Source§

impl StructuralPartialEq for SyncConfig

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