naia_socket_shared/
link_conditioner_config.rs

1/// Contains configuration required to initialize a LinkConditioner
2#[derive(Clone)]
3pub struct LinkConditionerConfig {
4    /// Delay to receive incoming messages in milliseconds
5    pub incoming_latency: u32,
6    /// The maximum additional random latency to delay received incoming
7    /// messages in milliseconds. This may be added OR subtracted from the
8    /// latency determined in the `incoming_latency` property above
9    pub incoming_jitter: u32,
10    /// The % chance that an incoming packet will be dropped.
11    /// Represented as a value between 0 and 1
12    pub incoming_loss: f32,
13}
14
15impl LinkConditionerConfig {
16    /// Creates a new LinkConditionerConfig
17    pub fn new(incoming_latency: u32, incoming_jitter: u32, incoming_loss: f32) -> Self {
18        Self {
19            incoming_latency,
20            incoming_jitter,
21            incoming_loss,
22        }
23    }
24
25    pub fn perfect_condition() -> Self {
26        Self {
27            incoming_latency: 1,
28            incoming_jitter: 0,
29            incoming_loss: 0.0,
30        }
31    }
32
33    /// Creates a new LinkConditioner that simulates a connection which is in a
34    /// very good condition
35    pub fn very_good_condition() -> Self {
36        Self {
37            incoming_latency: 12,
38            incoming_jitter: 3,
39            incoming_loss: 0.001,
40        }
41    }
42
43    /// Creates a new LinkConditioner that simulates a connection which is in a
44    /// good condition
45    pub fn good_condition() -> Self {
46        Self {
47            incoming_latency: 40,
48            incoming_jitter: 10,
49            incoming_loss: 0.002,
50        }
51    }
52
53    /// Creates a new LinkConditioner that simulates a connection which is in an
54    /// average condition
55    pub fn average_condition() -> Self {
56        Self {
57            incoming_latency: 100,
58            incoming_jitter: 25,
59            incoming_loss: 0.02,
60        }
61    }
62
63    /// Creates a new LinkConditioner that simulates a connection which is in an
64    /// poor condition
65    pub fn poor_condition() -> Self {
66        Self {
67            incoming_latency: 200,
68            incoming_jitter: 50,
69            incoming_loss: 0.04,
70        }
71    }
72
73    /// Creates a new LinkConditioner that simulates a connection which is in an
74    /// very poor condition
75    pub fn very_poor_condition() -> Self {
76        Self {
77            incoming_latency: 300,
78            incoming_jitter: 75,
79            incoming_loss: 0.06,
80        }
81    }
82}