Trait p2p::Interface [] [src]

pub trait Interface {
    fn insert_state(
        &mut self,
        token: Token,
        state: Rc<RefCell<NatState>>
    ) -> Result<(), (Rc<RefCell<NatState>>, String)>; fn remove_state(&mut self, token: Token) -> Option<Rc<RefCell<NatState>>>; fn state(&mut self, token: Token) -> Option<Rc<RefCell<NatState>>>; fn set_timeout(
        &mut self,
        duration: Duration,
        timer_detail: NatTimer
    ) -> Result<Timeout, TimerError>; fn cancel_timeout(&mut self, timeout: &Timeout) -> Option<NatTimer>; fn new_token(&mut self) -> Token; fn config(&self) -> &Config; fn enc_pk(&self) -> &PublicKey; fn enc_sk(&self) -> &SecretKey; fn sender(&self) -> &Sender<NatMsg>; }

The main trait that our users should implement.

We enlist our expectations from the user code using this trait. This trait object is passed ubiquitously in this crate and also passed back to the user via various callbacks we take to communicate results back to them.

Required Methods

We call this when we want our state to be held before we go back to the event loop. The callee is expected to store this some place (e.g. HashMap<Token, Rc<RefCell<NatState>>>) to be retrieved when mio poll indicates some event associated with the token has occurred. In that case call NatState::ready.

Remove the state that was previously stored against the token and return it if successfully retrieved.

Return the state (without removing - just a query) associated with the token

Set timeout. User code is expected to have a mio::timer::Timer<NatTimer> on which the timeout can be set.

Cancel the timout

Give us a new unique token

Give us the Config the crate uses to figure out various values and behaviors

Hand over a public encryption key. This must be ideally initialised once and must not change in subsequent calls as this is what will be shared with remote contacts for secure communication.

Hand over a reference to secret encryption key. This must be ideally initialised once and must not change in subsequent calls as this is what will be used for secure communication.

Obtain a sender for use to send messages into event loop.

Implementors