webrtc_turn/server/
config.rs

1use crate::auth::*;
2use crate::errors::*;
3use crate::relay::*;
4
5use util::{Conn, Error};
6
7use tokio::time::Duration;
8
9use std::sync::Arc;
10
11// ConnConfig is used for UDP listeners
12pub struct ConnConfig {
13    pub conn: Arc<dyn Conn + Send + Sync>,
14
15    // When an allocation is generated the RelayAddressGenerator
16    // creates the net.PacketConn and returns the IP/Port it is available at
17    pub relay_addr_generator: Box<dyn RelayAddressGenerator + Send + Sync>,
18}
19
20impl ConnConfig {
21    pub fn validate(&self) -> Result<(), Error> {
22        self.relay_addr_generator.validate()
23    }
24}
25
26// ServerConfig configures the Pion TURN Server
27pub struct ServerConfig {
28    // conn_configs are a list of all the turn listeners
29    // Each listener can have custom behavior around the creation of Relays
30    pub conn_configs: Vec<ConnConfig>,
31
32    // realm sets the realm for this server
33    pub realm: String,
34
35    // auth_handler is a callback used to handle incoming auth requests, allowing users to customize Pion TURN with custom behavior
36    pub auth_handler: Arc<Box<dyn AuthHandler + Send + Sync>>,
37
38    // channel_bind_timeout sets the lifetime of channel binding. Defaults to 10 minutes.
39    pub channel_bind_timeout: Duration,
40}
41
42impl ServerConfig {
43    pub fn validate(&self) -> Result<(), Error> {
44        if self.conn_configs.is_empty() {
45            return Err(ERR_NO_AVAILABLE_CONNS.to_owned());
46        }
47
48        for cc in &self.conn_configs {
49            cc.validate()?;
50        }
51        Ok(())
52    }
53}