-
-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathconfig.rs
244 lines (206 loc) · 8.58 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
//
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
//
//! Configuration options for the calling backend.
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
use clap;
/// General configuration options, set by command line arguments or
/// falls back to default or environment variables (in some cases).
#[derive(clap::Parser, Debug, Clone)]
#[command(name = "calling_backend")]
pub struct Config {
/// The IP address to bind to for all servers.
#[arg(long, default_value = "::")]
pub binding_ip: IpAddr,
/// The IP address to share for for ICE candidates. Clients will
/// connect to the calling backend using this IP. If unset, binding-ip
/// is used, if binding-ip is set to 0.0.0.0 or ::, 127.0.0.1 is used
#[arg(long)]
pub ice_candidate_ip: Vec<IpAddr>,
/// The port to use for ICE candidates. Clients will connect to the
/// calling backend using this port.
#[arg(long, default_value = "10000")]
pub ice_candidate_port: u16,
/// The port to use for ICE candidates when connected over TCP. Clients
/// will connect to the calling backend using this port.
#[arg(long, default_value = "10000")]
pub ice_candidate_port_tcp: u16,
/// The port to use for ICE candidates when connected over TCP+TLS. Clients
/// will connect to the calling backend using this port.
#[arg(long)]
pub ice_candidate_port_tls: Option<u16>,
/// The IP address to share for direct access to the signaling_server. If
/// defined, then the signaling_server will be used, otherwise the
/// http_server will be used for testing.
#[arg(long)]
pub signaling_ip: Option<IpAddr>,
/// The port to use for the signaling interface.
#[arg(long, default_value = "8080")]
pub signaling_port: u16,
/// Maximum clients per call, if using the http_server for testing.
#[arg(long, default_value = "8")]
pub max_clients_per_call: u32,
/// The initial bitrate target for sending. In a 16-person call with
/// each base layer at 50kbps you'd need 800kbps to send them all.
#[arg(long, default_value = "800")]
pub initial_target_send_rate_kbps: u64,
/// The min target send rate for sending.
/// This affects the congestion controller (googcc).
#[arg(long, default_value = "100")]
pub min_target_send_rate_kbps: u64,
/// The max target send rate for sending.
/// This affects the congestion controller (googcc)
/// and indirectly the maximum that any client can receive
/// no matter how much the client requests.
#[arg(long, default_value = "30000")]
pub max_target_send_rate_kbps: u64,
/// If the client doesn't request a max send rate,
/// use this as the max send rate.
/// Affects the allocation of the target send rate,
/// not the calculation of the of the target send rate.
#[arg(long, default_value = "5000")]
pub default_requested_max_send_rate_kbps: u64,
/// Timer tick period for operating on the Sfu state (ms).
#[arg(long, default_value = "100")]
pub tick_interval_ms: u64,
/// How quickly we want to drain each outgoing queue.
/// This affects the rate we allocate for draining the queue.
/// It will push out other, lower-priority, streams to prioritize draining.
/// The lower the value here, the higher the rate and the
/// higher priority put on draining the outgoing queue.
#[arg(long, default_value = "500")]
pub outgoing_queue_drain_ms: u64,
/// Optional interval used to post diagnostics to the log. If not defined
/// then no periodic information about calls will be posted to the log.
#[arg(long)]
pub diagnostics_interval_secs: Option<u64>,
/// Interval for sending active speaker messages (ms). The amount of time
/// to wait between sending messages to the clients to remind them of the
/// current active speaker for the call. Using milliseconds in case sub-
/// second resolution is needed.
#[arg(long, default_value = "1000")]
pub active_speaker_message_interval_ms: u64,
/// Inactivity check interval (seconds). The amount of time to wait between
/// iterating structures for inactive calls and clients.
#[arg(long, default_value = "5")]
pub inactivity_check_interval_secs: u64,
/// Amount of time to wait before dropping a call or client due to inactivity (seconds).
#[arg(long, default_value = "30")]
pub inactivity_timeout_secs: u64,
/// Whether new clients require approval. Only used with the testing http_server.
#[arg(long)]
pub new_clients_require_approval: bool,
/// The URL to PUT the list of approved users to.
#[arg(long)]
pub approved_users_persistence_url: Option<reqwest::Url>,
/// The base URL to DELETE individual and batch of call records.
/// An empty URL disables backend initiated call record removal.
#[arg(long)]
pub remove_call_records_base_url: Option<reqwest::Url>,
/// Amount of time to wait before failing a call to the calling frontend.
#[arg(long, default_value = "5000")]
pub frontend_operation_timeout_ms: u64,
/// Whether to save any users who join to the approved users list.
///
/// ...as opposed to only those who are explicitly approved. Only used for testing.
#[arg(long)]
pub persist_approval_for_all_users_who_join: bool,
/// The path to the certificate file for TLS
#[arg(long)]
pub certificate_file_path: Option<String>,
/// The path to the private key file for TLS
#[arg(long)]
pub key_file_path: Option<String>,
// The hostname to give the client to validate the certificate used for TLS
#[arg(long)]
pub hostname: Option<String>,
#[clap(flatten)]
pub metrics: MetricsOptions,
}
#[derive(clap::Parser, Clone, Debug, Default)]
pub struct MetricsOptions {
/// Host and port of Datadog StatsD agent. Typically 127.0.0.1:8125.
#[arg(long)]
pub datadog: Option<String>,
/// Region appears as a tag in metrics and logging.
#[arg(long = "metrics-region", default_value = "unspecified")]
pub region: String,
/// Deployment version appears as a tag in metrics and in logging if specified.
#[arg(long = "metrics-version")]
pub version: Option<String>,
}
#[derive(Debug, Clone)]
pub struct MediaPorts {
pub udp: u16,
pub tcp: u16,
pub tls: Option<u16>,
}
pub struct ServerMediaAddress {
pub addresses: Vec<IpAddr>,
pub ports: MediaPorts,
pub hostname: Option<String>,
}
/// Public address of the server for media/UDP/TCP/TLS derived from the configuration.
impl ServerMediaAddress {
pub fn from(config: &'static Config) -> Self {
let addresses = if config.ice_candidate_ip.is_empty() {
let ip = if config.binding_ip == Ipv4Addr::UNSPECIFIED
|| config.binding_ip == Ipv6Addr::UNSPECIFIED
{
Ipv4Addr::LOCALHOST.into()
} else {
config.binding_ip
};
vec![ip]
} else {
config.ice_candidate_ip.clone()
};
Self {
addresses,
ports: MediaPorts {
udp: config.ice_candidate_port,
tcp: config.ice_candidate_port_tcp,
tls: config.ice_candidate_port_tls,
},
hostname: config.hostname.clone(),
}
}
pub fn ip(&self) -> &IpAddr {
self.addresses
.first()
.expect("addresses should be non-empty")
}
}
#[cfg(test)]
pub(crate) fn default_test_config() -> Config {
Config {
binding_ip: Ipv4Addr::LOCALHOST.into(),
ice_candidate_ip: vec![Ipv4Addr::LOCALHOST.into()],
signaling_ip: Some(Ipv4Addr::LOCALHOST.into()),
signaling_port: 8080,
ice_candidate_port: 10000,
ice_candidate_port_tcp: 10000,
max_clients_per_call: 8,
initial_target_send_rate_kbps: 1500,
min_target_send_rate_kbps: 100,
max_target_send_rate_kbps: 30000,
default_requested_max_send_rate_kbps: 20000,
tick_interval_ms: 100,
outgoing_queue_drain_ms: 500,
diagnostics_interval_secs: None,
active_speaker_message_interval_ms: 1000,
inactivity_check_interval_secs: 5,
inactivity_timeout_secs: 30,
new_clients_require_approval: false,
approved_users_persistence_url: Default::default(),
remove_call_records_base_url: Default::default(),
persist_approval_for_all_users_who_join: false,
metrics: Default::default(),
frontend_operation_timeout_ms: 1000,
certificate_file_path: None,
key_file_path: None,
hostname: None,
ice_candidate_port_tls: None,
}
}