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.

Used by the signaling class to notify task that the peer handshake is done.

This is the point where the task can take over.

Return supported message types.

Incoming messages with accepted types will be passed to the task. Otherwise, the message is dropped.

TODO: Implement this

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 protocol name.

Return the task data used for negotiation in the auth message.

This method can be called by the user to close the connection.

Implementations

Returns true if the boxed type is the same as T

Returns some reference to the boxed value if it is of type T, or None if it isn’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.

Returns some mutable reference to the boxed value if it is of type T, or None if it isn’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.

Returns the boxed value if it is of type T, or Err(Self) if it isn’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.

Implementors