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
fn insert_state(
&mut self,
token: Token,
state: Rc<RefCell<NatState>>
) -> Result<(), (Rc<RefCell<NatState>>, String)>
&mut self,
token: Token,
state: Rc<RefCell<NatState>>
) -> Result<(), (Rc<RefCell<NatState>>, String)>
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
.
fn remove_state(&mut self, token: Token) -> Option<Rc<RefCell<NatState>>>
Remove the state that was previously stored against the token
and return it if
successfully retrieved.
fn state(&mut self, token: Token) -> Option<Rc<RefCell<NatState>>>
Return the state (without removing - just a query) associated with the token
fn set_timeout(
&mut self,
duration: Duration,
timer_detail: NatTimer
) -> Result<Timeout, TimerError>
&mut self,
duration: Duration,
timer_detail: NatTimer
) -> Result<Timeout, TimerError>
Set timeout. User code is expected to have a mio::timer::Timer<NatTimer>
on which the
timeout can be set.
fn cancel_timeout(&mut self, timeout: &Timeout) -> Option<NatTimer>
Cancel the timout
fn new_token(&mut self) -> Token
Give us a new unique token
fn config(&self) -> &Config
Give us the Config
the crate uses to figure out various values and behaviors
fn enc_pk(&self) -> &PublicKey
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.
fn enc_sk(&self) -> &SecretKey
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.
fn sender(&self) -> &Sender<NatMsg>
Obtain a sender for use to send messages into event loop.