naia_shared/connection/
connection_config.rs

1use std::{default::Default, time::Duration};
2
3/// Contains Config properties which will be used by a Server or Client
4#[derive(Clone, Debug)]
5pub struct ConnectionConfig {
6    /// The duration to wait for communication from a remote host before
7    /// initiating a disconnect
8    pub disconnection_timeout_duration: Duration,
9    /// The duration to wait before sending a heartbeat message to a remote
10    /// host, if the host has not already sent another message within that time
11    pub heartbeat_interval: Duration,
12    /// The duration over which to measure bandwidth. Set to None to avoid
13    /// measure bandwidth at all.
14    pub bandwidth_measure_duration: Option<Duration>,
15}
16
17impl ConnectionConfig {
18    /// Creates a new ConnectionConfig, used to initialize a Connection
19    pub fn new(
20        disconnection_timeout_duration: Duration,
21        heartbeat_interval: Duration,
22        bandwidth_measure_duration: Option<Duration>,
23    ) -> Self {
24        ConnectionConfig {
25            disconnection_timeout_duration,
26            heartbeat_interval,
27            bandwidth_measure_duration,
28        }
29    }
30}
31
32impl Default for ConnectionConfig {
33    fn default() -> Self {
34        Self {
35            disconnection_timeout_duration: Duration::from_secs(30),
36            heartbeat_interval: Duration::from_secs(4),
37            bandwidth_measure_duration: None,
38        }
39    }
40}