diff --git a/config.toml b/config.toml index 1fb17413e..80f88c967 100644 --- a/config.toml +++ b/config.toml @@ -29,10 +29,10 @@ [turn] -# Turn server IP address. +# Turn server host. # # Default: -# ip = "127.0.0.1" +# host = "localhost" # Turn server port. # diff --git a/jason/demo/minikube.vals.yaml b/jason/demo/minikube.vals.yaml index facbe7576..2db89efdf 100644 --- a/jason/demo/minikube.vals.yaml +++ b/jason/demo/minikube.vals.yaml @@ -7,6 +7,9 @@ server: image: tag: dev pullPolicy: IfNotPresent + conf: + turn: + host: medea-demo.test coturn: image: diff --git a/jason/demo/staging.vals.yaml b/jason/demo/staging.vals.yaml index f889f0370..3589ac3f3 100644 --- a/jason/demo/staging.vals.yaml +++ b/jason/demo/staging.vals.yaml @@ -11,7 +11,7 @@ server: server: bind_port: 9980 turn: - ip: 178.162.214.89 + host: demo.medea.stg.t11913.org pass: changeme coturn: diff --git a/src/conf/mod.rs b/src/conf/mod.rs index 454df6f9b..dc10a2b83 100644 --- a/src/conf/mod.rs +++ b/src/conf/mod.rs @@ -236,17 +236,17 @@ mod tests { fn turn_conf() { let default_conf = Conf::default(); - env::set_var("MEDEA_TURN.IP", "5.5.5.5"); + env::set_var("MEDEA_TURN.HOST", "example.com"); env::set_var("MEDEA_TURN.PORT", "1234"); let env_conf = Conf::parse().unwrap(); - assert_ne!(default_conf.turn.ip, env_conf.turn.ip); + assert_ne!(default_conf.turn.host, env_conf.turn.host); assert_ne!(default_conf.turn.port, env_conf.turn.port); - assert_eq!(env_conf.turn.ip, Ipv4Addr::new(5, 5, 5, 5)); + assert_eq!(env_conf.turn.host, "example.com"); assert_eq!(env_conf.turn.port, 1234); - assert_eq!(env_conf.turn.addr(), "5.5.5.5:1234".parse().unwrap()); + assert_eq!(env_conf.turn.addr(), "example.com:1234"); } #[test] diff --git a/src/conf/turn.rs b/src/conf/turn.rs index 3b6d23c48..4a6bc373a 100644 --- a/src/conf/turn.rs +++ b/src/conf/turn.rs @@ -1,7 +1,8 @@ //! STUN/TURN server settings. use std::{ - net::{IpAddr, Ipv4Addr, SocketAddr, ToSocketAddrs as _}, + borrow::Cow, + net::{IpAddr, Ipv4Addr}, time::Duration, }; @@ -14,9 +15,9 @@ use smart_default::SmartDefault; pub struct Turn { /// Database settings pub db: Db, - /// IP address STUN/TURN server. Defaults to `127.0.0.1`. - #[default(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)))] - pub ip: IpAddr, + /// Host of STUN/TURN server. Defaults to `localhost`. + #[default = "localhost"] + pub host: Cow<'static, str>, /// Port to connect TURN server. Defaults to `3478`. #[default = 3478] pub port: u16, @@ -29,14 +30,10 @@ pub struct Turn { } impl Turn { - /// Builds [`SocketAddr`] from `ip` and `port`. + /// Builds [`String`] addr from `host` and `port`. #[inline] - pub fn addr(&self) -> SocketAddr { - (self.ip, self.port) - .to_socket_addrs() - .unwrap() - .next() - .unwrap() + pub fn addr(&self) -> String { + format!("{}:{}", self.host, self.port) } } diff --git a/src/media/ice_user.rs b/src/media/ice_user.rs index 4a569736c..ba0de8129 100644 --- a/src/media/ice_user.rs +++ b/src/media/ice_user.rs @@ -1,5 +1,3 @@ -use std::net::SocketAddr; - use medea_client_api_proto::IceServer; use crate::signalling::RoomId; @@ -8,7 +6,7 @@ use crate::signalling::RoomId; #[derive(Clone, Debug)] pub struct IceUser { /// Address of Turn server. - address: SocketAddr, + address: String, /// Username for authorization. user: String, /// Password for authorization. @@ -22,7 +20,7 @@ pub struct IceUser { impl IceUser { /// Build new non static [`IceUser`]. pub fn build( - address: SocketAddr, + address: String, room_id: RoomId, name: &str, pass: String, @@ -36,7 +34,7 @@ impl IceUser { } /// Build new static [`IceUser`]. - pub fn new(address: SocketAddr, user: String, pass: String) -> Self { + pub fn new(address: String, user: String, pass: String) -> Self { Self { address, user, @@ -65,7 +63,7 @@ impl IceUser { vec![stun, turn] } - pub fn address(&self) -> &SocketAddr { + pub fn address(&self) -> &str { &self.address } diff --git a/src/turn/service.rs b/src/turn/service.rs index 6da86c82d..70050deec 100644 --- a/src/turn/service.rs +++ b/src/turn/service.rs @@ -1,4 +1,4 @@ -use std::{fmt, net::SocketAddr, sync::Arc}; +use std::{fmt, sync::Arc}; use actix::{ fut::wrap_future, Actor, ActorFuture, Addr, Context, Handler, MailboxError, @@ -141,7 +141,7 @@ struct Service { /// TurnAuthRepo password. db_pass: String, /// Turn server address. - turn_address: SocketAddr, + turn_address: String, /// Turn server static user. turn_username: String, /// Turn server static user password. @@ -199,7 +199,7 @@ impl Service { fn static_user(&mut self) -> IceUser { if self.static_user.is_none() { self.static_user.replace(IceUser::new( - self.turn_address, + self.turn_address.clone(), self.turn_username.clone(), self.turn_password.clone(), )); @@ -233,25 +233,27 @@ impl Handler for Service { _ctx: &mut Self::Context, ) -> Self::Result { let ice_user = IceUser::build( - self.turn_address, + self.turn_address.clone(), msg.room_id, &msg.member_id.to_string(), self.new_password(TURN_PASS_LEN), ); - Box::new(self.turn_db.insert(&ice_user).into_actor(self).then( - move |result, act, _| { - wrap_future(match result { - Ok(_) => ok(ice_user), - Err(e) => match msg.policy { - UnreachablePolicy::ReturnErr => err(e.into()), - UnreachablePolicy::ReturnStatic => { - ok(act.static_user()) - } - }, - }) - }, - )) + Box::new( + self.turn_db.insert(&ice_user).into_actor(self).then( + move |result, act, _| { + wrap_future(match result { + Ok(_) => ok(ice_user), + Err(e) => match msg.policy { + UnreachablePolicy::ReturnErr => err(e.into()), + UnreachablePolicy::ReturnStatic => { + ok(act.static_user()) + } + }, + }) + }, + ), + ) } } @@ -315,5 +317,4 @@ pub mod test { pub fn new_turn_auth_service_mock() -> Arc { Arc::new(TurnAuthServiceMock {}) } - }