pub struct UdpHolePuncher { /* private fields */ }
Expand description

High level management interface for UDP NAT Hole Punchers

See Wikipedia and ‘Peer-to-Peer Communication Across Network Address Translators’.

A node can have multiple Hole Punchers (punchers) at a time, each one with a unique name and working with a different peer puncher in a remote node.

For a puncher to work a (e.g. from ‘alice’ to ‘bob’, using rendezvous service ‘zurg’) the remote node will also need to create its own puncher (e.g. from ‘bob’ to ‘alice’, using ‘zurg’).

Warnings

This UDP NAT Hole Puncher implementation is currently a prototype. No guarantees are provided.

UDP and NAT Hole Punching are unreliable protocols. Expect send and receive failures.

Example

use ockam_transport_udp::{UdpHolePuncher, UdpTransport, UDP};

// Create transport
UdpTransport::create(ctx).await?;

// Create a NAT hole from us 'alice' to them 'bob' using
// the Rendezvous service 'zurg' at public IP address `192.168.1.10:4000`
let rendezvous_route = route![(UDP, "192.168.1.10:4000"), "zurg"];
let mut puncher = UdpHolePuncher::create(ctx, "alice", "bob", rendezvous_route).await?;

// Note: For this to work, 'bob' will likewise need to create a hole thru to us

// Wait for hole to open.
// Note that the hole could close at anytime. If the hole closes, the
// puncher will automatically try to re-open it.
puncher.wait_for_hole_open().await?;

// Try to send a message to a remote 'echoer' via our puncher
ctx.send(route![puncher.address(), "echoer"], "Góðan daginn".to_string()).await?;

Implementations§

source§

impl UdpHolePuncher

source

pub async fn create<S: AsRef<str>, R: Into<Route>>( ctx: &mut Context, puncher_name: S, peer_puncher_name: S, rendezvous_route: R ) -> Result<UdpHolePuncher>

Create a new UDP NAT Hole Puncher

source

pub async fn wait_for_hole_open(&mut self) -> Result<()>

Wait until Hole Puncher successfully opens a hole to the peer or a timeout

Note that the hole could close at anytime. If the hole closes, the puncher will automatically try to re-open it.

Timeout is the same as that of Context::receive().

source

pub fn address(&self) -> Address

Address of this UDP NAT Hole Puncher’s worker.

Auto Trait Implementations§

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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.
§

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

§

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