turn_driver

Trait Hooks

Source
pub trait Hooks {
    // Provided methods
    fn auth<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        session: &'life1 SessionAddr,
        username: &'life2 str,
        realm: &'life3 str,
        nonce: &'life4 str,
    ) -> Pin<Box<dyn Future<Output = Option<&str>> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait { ... }
    fn on<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        event: &'life1 Events,
        realm: &'life2 str,
        nonce: &'life3 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: Sync + 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
}
Expand description

Abstraction that handles turn server communication with the outside world

struct HooksImpl;

#[async_trait]
impl Hooks for HooksImpl {
    async fn auth(&self, addr: SocketAddr, name: String, realm: String, rid: String) -> Option<&str> {
        get_password(username).await // Pretend this function exists
    }

    async fn on(&self, event: Events, realm: String, rid: String) {
        println!("event={:?}, realm={}, rid={}", event, realm, rid)
    }
}

Provided Methods§

Source

fn auth<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, session: &'life1 SessionAddr, username: &'life2 str, realm: &'life3 str, nonce: &'life4 str, ) -> Pin<Box<dyn Future<Output = Option<&str>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

When the turn server needs to authenticate the current user, hooks only needs to find the key according to the username and other information of the current session and return it

Source

fn on<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, event: &'life1 Events, realm: &'life2 str, nonce: &'life3 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Called when the turn server pushes an event

Implementors§