Trait saltyrtc_client::tasks::Task
source · [−]pub trait Task: Debug + Any {
fn init(
&mut self,
data: &Option<HashMap<String, Value>>
) -> Result<(), Error>;
fn start(
&mut self,
outgoing_tx: UnboundedSender<TaskMessage>,
incoming_rx: UnboundedReceiver<TaskMessage>,
disconnect_tx: OneshotSender<Option<CloseCode>>
);
fn supported_types(&self) -> &'static [&'static str];
fn send_signaling_message(&self, payload: &[u8]);
fn name(&self) -> Cow<'static, str>;
fn data(&self) -> Option<HashMap<String, Value>>;
fn close(&mut self, reason: CloseCode);
}
Expand description
An interface that needs to be implemented by every signaling task.
A task defines how data is exchanged after the server- and peer-handshake have been completed.
Communication Client ↔ Task
The primary communication between the client and a task is through the
channels passed to the start
method:
outgoing_tx
: This is the sending end for outgoing task / application / close messages. The task should put messages that the user wants to send through the established connection into this outgoing channel sender.incoming_rx
: This is the receiving end for incoming task / application / close messages. The task should take messages from this incoming channel receiver and pass them to the user.disconnect_tx
: This oneshot channel is used to give the task a way to close the connection.
Depending on the task specification, application messages may be passed to the user or may be discarded.
Required Methods
Initialize the task with the task data from the peer, sent in the Auth
message.
The task should keep track internally whether it has been initialized or not.
sourcefn start(
&mut self,
outgoing_tx: UnboundedSender<TaskMessage>,
incoming_rx: UnboundedReceiver<TaskMessage>,
disconnect_tx: OneshotSender<Option<CloseCode>>
)
fn start(
&mut self,
outgoing_tx: UnboundedSender<TaskMessage>,
incoming_rx: UnboundedReceiver<TaskMessage>,
disconnect_tx: OneshotSender<Option<CloseCode>>
)
Used by the signaling class to notify task that the peer handshake is done.
This is the point where the task can take over.
sourcefn supported_types(&self) -> &'static [&'static str]
fn supported_types(&self) -> &'static [&'static str]
Return supported message types.
Incoming messages with accepted types will be passed to the task. Otherwise, the message is dropped.
TODO: Implement this
sourcefn send_signaling_message(&self, payload: &[u8])
fn send_signaling_message(&self, payload: &[u8])
Send bytes through the task signaling channel.
This method should only be called after the handover.
Note that the data passed in to this method should not already be encrypted. Otherwise, data will be encrypted twice.
Return the task data used for negotiation in the auth
message.
Implementations
sourceimpl dyn Task
impl dyn Task
sourcepub fn downcast_ref<T: Task>(&self) -> Option<&T>
pub fn downcast_ref<T: Task>(&self) -> Option<&T>
Returns some reference to the boxed value if it is of type T
, or
None
if it isn’t.
sourcepub unsafe fn downcast_ref_unchecked<T: Task>(&self) -> &T
pub unsafe fn downcast_ref_unchecked<T: Task>(&self) -> &T
Returns a reference to the boxed value, blindly assuming it to be of type T
.
If you are not absolutely certain of T
, you must not call this.
sourcepub fn downcast_mut<T: Task>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: Task>(&mut self) -> Option<&mut T>
Returns some mutable reference to the boxed value if it is of type T
, or
None
if it isn’t.
sourcepub unsafe fn downcast_mut_unchecked<T: Task>(&mut self) -> &mut T
pub unsafe fn downcast_mut_unchecked<T: Task>(&mut self) -> &mut T
Returns a mutable reference to the boxed value, blindly assuming it to be of type T
.
If you are not absolutely certain of T
, you must not call this.
sourceimpl dyn Task
impl dyn Task
sourcepub fn downcast<T: Task>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
pub fn downcast<T: Task>(self: Box<Self>) -> Result<Box<T>, Box<Self>>
Returns the boxed value if it is of type T
, or Err(Self)
if it isn’t.
sourcepub unsafe fn downcast_unchecked<T: Task>(self: Box<Self>) -> Box<T>
pub unsafe fn downcast_unchecked<T: Task>(self: Box<Self>) -> Box<T>
Returns the boxed value, blindly assuming it to be of type T
.
If you are not absolutely certain of T
, you must not call this.