pub struct Nodes { /* private fields */ }
Expand description
node table.
Implementations§
Source§impl Nodes
impl Nodes
pub fn new() -> Self
Sourcepub fn get_users(
&self,
skip: usize,
limit: usize,
) -> Vec<(String, Vec<SocketAddr>)>
pub fn get_users( &self, skip: usize, limit: usize, ) -> Vec<(String, Vec<SocketAddr>)>
get users name and address.
§Examples
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
assert_eq!(nodes.get_users(0, 10), vec![]);
Sourcepub fn get_node(&self, a: &SocketAddr) -> Option<Node>
pub fn get_node(&self, a: &SocketAddr) -> Option<Node>
get node from name.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels.len(), 0);
assert_eq!(node.ports.len(), 0);
Sourcepub fn get_secret(&self, a: &SocketAddr) -> Option<Arc<[u8; 16]>>
pub fn get_secret(&self, a: &SocketAddr) -> Option<Arc<[u8; 16]>>
get password from address.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
let secret = nodes.get_secret(&addr).unwrap();
assert_eq!(
secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
Sourcepub fn insert(
&self,
addr: &SocketAddr,
realm: &str,
username: &str,
password: &str,
) -> Option<Arc<[u8; 16]>>
pub fn insert( &self, addr: &SocketAddr, realm: &str, username: &str, password: &str, ) -> Option<Arc<[u8; 16]>>
insert node in node table.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels.len(), 0);
assert_eq!(node.ports.len(), 0);
Sourcepub fn push_port(&self, a: &SocketAddr, port: u16) -> Option<()>
pub fn push_port(&self, a: &SocketAddr, port: u16) -> Option<()>
push port to node.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
assert!(nodes.push_port(&addr, 60000).is_some());
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels, vec![]);
assert_eq!(node.ports, vec![60000]);
Sourcepub fn push_channel(&self, a: &SocketAddr, channel: u16) -> Option<()>
pub fn push_channel(&self, a: &SocketAddr, channel: u16) -> Option<()>
push channel to node.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
assert!(nodes.push_channel(&addr, 0x4000).is_some());
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels, vec![0x4000]);
assert_eq!(node.ports, vec![]);
Sourcepub fn set_lifetime(&self, a: &SocketAddr, delay: u32) -> Option<()>
pub fn set_lifetime(&self, a: &SocketAddr, delay: u32) -> Option<()>
set lifetime to node.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
assert!(nodes.set_lifetime(&addr, 600).is_some());
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels, vec![]);
assert_eq!(node.ports, vec![]);
assert!(!node.is_death());
assert!(nodes.set_lifetime(&addr, 0).is_some());
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels, vec![]);
assert_eq!(node.ports, vec![]);
assert!(node.is_death());
Sourcepub fn remove(&self, a: &SocketAddr) -> Option<Node>
pub fn remove(&self, a: &SocketAddr) -> Option<Node>
remove node from address.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
let node = nodes.get_node(&addr).unwrap();
assert_eq!(node.username.as_str(), "test");
assert_eq!(node.password.as_str(), "test");
assert_eq!(
node.secret.as_slice(),
&[
174, 238, 187, 253, 117, 209, 73, 157, 36, 56, 143, 91, 155, 16,
224, 239
]
);
assert_eq!(node.channels, vec![]);
assert_eq!(node.ports, vec![]);
assert!(nodes.remove(&addr).is_some());
assert!(nodes.get_node(&addr).is_none());
Sourcepub fn get_addrs(&self, u: &str) -> Vec<SocketAddr>
pub fn get_addrs(&self, u: &str) -> Vec<SocketAddr>
get node name bound address.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
let addr1 = "127.0.0.1:8081".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
nodes.insert(&addr1, "test", "test", "test");
let ret = nodes.get_addrs("test");
assert_eq!(ret.len(), 2);
assert!(ret[0] == addr || ret[0] == addr1);
assert!(ret[1] == addr || ret[1] == addr1);
Sourcepub fn get_deaths(&self) -> Vec<SocketAddr>
pub fn get_deaths(&self) -> Vec<SocketAddr>
get death node.
§Examples
use std::net::SocketAddr;
use turn_rs::router::nodes::*;
let nodes = Nodes::new();
let addr = "127.0.0.1:8080".parse::<SocketAddr>().unwrap();
nodes.insert(&addr, "test", "test", "test");
assert!(nodes.set_lifetime(&addr, 600).is_some());
assert_eq!(nodes.get_deaths(), vec![]);
assert!(nodes.set_lifetime(&addr, 0).is_some());
assert_eq!(nodes.get_deaths(), vec![addr]);
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Nodes
impl RefUnwindSafe for Nodes
impl Send for Nodes
impl Sync for Nodes
impl Unpin for Nodes
impl UnwindSafe for Nodes
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more