Struct Nodes

Source
pub struct Nodes { /* private fields */ }
Expand description

node table.

Implementations§

Source§

impl Nodes

Source

pub fn new() -> Self

Source

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![]);
Source

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);
Source

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
    ]
);
Source

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);
Source

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]);
Source

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![]);
Source

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());
Source

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());
Source

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);
Source

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§

Source§

impl Default for Nodes

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V