Skip to main content

HolePunchEngine

Struct HolePunchEngine 

Source
pub struct HolePunchEngine { /* private fields */ }
Expand description

The hole-punch state machine for a single link.

Implementations§

Source§

impl HolePunchEngine

Source

pub fn new(link_id: [u8; 16], probe_addr: Option<Endpoint>) -> Self

Create a new engine for the given link. Does not start any session.

Source

pub fn state(&self) -> HolePunchState

Source

pub fn session_id(&self) -> &[u8; 16]

Source

pub fn is_initiator(&self) -> bool

Source

pub fn punch_token(&self) -> &[u8; 32]

Source

pub fn peer_public_endpoint(&self) -> Option<&Endpoint>

Peer’s discovered public endpoint.

Source

pub fn propose( &mut self, derived_key: &[u8], now: f64, rng: &mut dyn Rng, ) -> Result<Vec<HolePunchAction>, HolePunchError>

Propose a direct connection (initiator side).

Per the spec, the initiator first discovers its own public endpoint (Phase 1) before sending the upgrade request.

Transitions: Idle -> Discovering.

Source

pub fn endpoints_discovered( &mut self, public_endpoint: Endpoint, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>

Called when endpoint discovery completes.

For initiator: Discovering -> Proposing (sends UPGRADE_REQUEST with facilitator + our addr). For responder: Discovering -> Punching (sends UPGRADE_READY with our addr, starts punch).

Source

pub fn handle_signal( &mut self, msgtype: u16, payload: &[u8], derived_key: Option<&[u8]>, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>

Handle an incoming signaling message.

derived_key is needed when handling UPGRADE_REQUEST (responder side).

Source

pub fn punch_succeeded( &mut self, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>

Called when the punch phase succeeds.

Transitions: Punching -> Connected.

Source

pub fn punch_failed( &mut self, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>

Called when the punch phase fails.

Transitions: Punching -> Failed.

Source

pub fn tick(&mut self, now: f64) -> Vec<HolePunchAction>

Periodic tick: check timeouts.

Source

pub fn build_reject( link_id: [u8; 16], request_payload: &[u8], reason: u8, ) -> Result<HolePunchAction, HolePunchError>

Build a reject response for a request payload without creating a full session.

Used when the policy rejects all proposals.

Source

pub fn reset(&mut self)

Reset engine back to Idle state for reuse.

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