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: DurationInterval 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: DurationTime 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: usizeNumber 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: usizeMaximum 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: u32Threshold 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: u128Threshold 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: usizeMultiplier 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
impl ProtocolConfig
Sourcepub fn competitive() -> Self
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.
Sourcepub fn high_latency() -> Self
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.
Sourcepub fn debug() -> Self
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.
Sourcepub fn mobile() -> Self
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
Sourcepub fn deterministic(seed: u64) -> Self
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));Sourcepub fn validate(&self) -> Result<(), FortressError>
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
impl Clone for ProtocolConfig
Source§fn clone(&self) -> ProtocolConfig
fn clone(&self) -> ProtocolConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more