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: u32Number 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: DurationTime 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: DurationTime 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: DurationTime between keepalive packets when idle. Keepalives prevent disconnect timeouts during periods of no input.
Default: 200ms
Implementations§
Source§impl SyncConfig
impl SyncConfig
Sourcepub fn high_latency() -> Self
pub fn high_latency() -> Self
Configuration preset for high-latency networks (100-200ms RTT).
Uses longer intervals to avoid flooding the network with retries.
Sourcepub fn lossy() -> Self
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.
Sourcepub fn lan() -> Self
pub fn lan() -> Self
Configuration preset for local network / LAN play.
Uses shorter intervals and fewer sync packets for faster connection.
Sourcepub fn mobile() -> Self
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)
Sourcepub fn competitive() -> Self
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
Sourcepub fn extreme() -> Self
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);Sourcepub fn stress_test() -> Self
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
impl Clone for SyncConfig
Source§fn clone(&self) -> SyncConfig
fn clone(&self) -> SyncConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more