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>
impl<V: Serialize + Send + Sync + 'static> MailboxConnection<V>
Sourcepub async fn create(
config: AppConfig<V>,
code_length: usize,
) -> Result<Self, WormholeError>
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 configurationcode_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?;Sourcepub async fn create_with_password(
config: AppConfig<V>,
password: &str,
) -> Result<Self, WormholeError>
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 configurationpassword: Free text password which will be appended to the nameplate number to form theCode
§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
Sourcepub async fn connect(
config: AppConfig<V>,
code: Code,
allocate: bool,
) -> Result<Self, WormholeError>
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 configurationcode: TheCoderequired to authorize to connect to an existing mailbox.allocate:true: Allocates aNameplateif it does not exist.false: The call fails with aWormholeError::UnclaimedNameplatewhen theNameplatedoes 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?;Sourcepub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError>
pub async fn shutdown(self, mood: Mood) -> Result<(), WormholeError>
Shut down the connection to the mailbox
§Arguments
mood:Moodshould 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?;