Struct MailboxConnection

Source
pub struct MailboxConnection<V: Serialize + Send + Sync + 'static> { /* private fields */ }
Expand description

Establishing Wormhole connection

You can send and receive arbitrary messages in form of byte slices over it, using Wormhole::send and Wormhole::receive. Everything else (including encryption) will be handled for you.

To create a wormhole, use the mailbox connection created via MailboxConnection::create or MailboxConnection::connect with the Wormhole::connect method. Typically, the sender side connects without a code (which will create one), and the receiver side has one (the user entered it, who got it from the sender).

§Clean shutdown

TODO A MailboxConnection contains a RendezvousServer which is connected to the mailbox

Implementations§

Source§

impl<V: Serialize + Send + Sync + 'static> MailboxConnection<V>

Source

pub async fn create( config: AppConfig<V>, code_length: usize, ) -> Result<Self, WormholeError>

Create a connection to a mailbox which is configured with a Code starting with the nameplate and by a given number of wordlist based random words.

§Arguments
  • config: Application configuration
  • code_length: number of words used for the password. The words are taken from the default wordlist.
§Examples
use magic_wormhole::{transfer::APP_CONFIG, AppConfig, MailboxConnection};
let config = APP_CONFIG;
let mailbox_connection = MailboxConnection::create(config, 2).await?;
Source

pub async fn create_with_password( config: AppConfig<V>, password: &str, ) -> Result<Self, WormholeError>

Create a connection to a mailbox which is configured with a Code containing the nameplate and the given password.

§Arguments
  • config: Application configuration
  • password: Free text password which will be appended to the nameplate number to form the Code
§Examples
use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection};
let config = APP_CONFIG;
let mailbox_connection =
    MailboxConnection::create_with_password(config, "secret".parse()?).await?;

TODO: Replace this with create_with_validated_password

Source

pub async fn connect( config: AppConfig<V>, code: Code, allocate: bool, ) -> Result<Self, WormholeError>

Create a connection to a mailbox defined by a Code which contains the Nameplate and the password to authorize the access.

§Arguments
  • config: Application configuration
  • code: The Code required to authorize to connect to an existing mailbox.
  • allocate:
    • true: Allocates a Nameplate if it does not exist.
    • false: The call fails with a WormholeError::UnclaimedNameplate when the Nameplate does not exist.
§Examples
use magic_wormhole::{transfer::APP_CONFIG, Code, MailboxConnection, Nameplate};
let config = APP_CONFIG;
let code = "5-password".parse()?;
let mailbox_connection = MailboxConnection::connect(config, code, false).await?;
Source

pub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError>

Shut down the connection to the mailbox

§Arguments
  • mood: Mood should give a hint of the reason of the shutdown
§Examples
return async_std::task::block_on(async {
use magic_wormhole::{transfer::APP_CONFIG, MailboxConnection, Mood};
let config = APP_CONFIG;
let mailbox_connection = MailboxConnection::create_with_password(config, "secret-code-password".parse()?)
    .await?;
mailbox_connection.shutdown(Mood::Happy).await?;
Source

pub fn welcome(&self) -> Option<&str>

The welcome message received from the mailbox server

Source

pub fn mailbox(&self) -> &Mailbox

The mailbox id of the created mailbox

Source

pub fn code(&self) -> &Code

The Code that was used to connect to the mailbox.

Auto Trait Implementations§

§

impl<V> !Freeze for MailboxConnection<V>

§

impl<V> !RefUnwindSafe for MailboxConnection<V>

§

impl<V> Send for MailboxConnection<V>

§

impl<V> Sync for MailboxConnection<V>

§

impl<V> Unpin for MailboxConnection<V>
where V: Unpin,

§

impl<V> !UnwindSafe for MailboxConnection<V>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,