webrtc_turn/relay/
relay_none.rs1use super::*;
2use crate::errors::*;
3
4use util::vnet::net::*;
5
6use async_trait::async_trait;
7
8pub struct RelayAddressGeneratorNone {
10 pub address: String,
12 pub net: Arc<Net>,
13}
14
15#[async_trait]
16impl RelayAddressGenerator for RelayAddressGeneratorNone {
17 fn validate(&self) -> Result<(), Error> {
19 if self.address.is_empty() {
20 Err(ERR_LISTENING_ADDRESS_INVALID.to_owned())
21 } else {
22 Ok(())
23 }
24 }
25
26 async fn allocate_conn(
28 &self,
29 use_ipv4: bool,
30 requested_port: u16,
31 ) -> Result<(Arc<dyn Conn + Send + Sync>, SocketAddr), Error> {
32 let addr = self
33 .net
34 .resolve_addr(use_ipv4, &format!("{}:{}", self.address, requested_port))
35 .await?;
36 let conn = self.net.bind(addr).await?;
37 let relay_addr = conn.local_addr().await?;
38 Ok((conn, relay_addr))
39 }
40}