pub struct HolePunchEngine { /* private fields */ }Expand description
The hole-punch state machine for a single link.
Implementations§
Source§impl HolePunchEngine
impl HolePunchEngine
Sourcepub fn new(link_id: [u8; 16], probe_addr: Option<Endpoint>) -> Self
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.
pub fn state(&self) -> HolePunchState
pub fn session_id(&self) -> &[u8; 16]
pub fn is_initiator(&self) -> bool
pub fn punch_token(&self) -> &[u8; 32]
Sourcepub fn peer_public_endpoint(&self) -> Option<&Endpoint>
pub fn peer_public_endpoint(&self) -> Option<&Endpoint>
Peer’s discovered public endpoint.
Sourcepub fn propose(
&mut self,
derived_key: &[u8],
now: f64,
rng: &mut dyn Rng,
) -> Result<Vec<HolePunchAction>, HolePunchError>
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.
Sourcepub fn endpoints_discovered(
&mut self,
public_endpoint: Endpoint,
now: f64,
) -> Result<Vec<HolePunchAction>, HolePunchError>
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).
Sourcepub fn handle_signal(
&mut self,
msgtype: u16,
payload: &[u8],
derived_key: Option<&[u8]>,
now: f64,
) -> Result<Vec<HolePunchAction>, HolePunchError>
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).
Sourcepub fn punch_succeeded(
&mut self,
now: f64,
) -> Result<Vec<HolePunchAction>, HolePunchError>
pub fn punch_succeeded( &mut self, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>
Called when the punch phase succeeds.
Transitions: Punching -> Connected.
Sourcepub fn punch_failed(
&mut self,
now: f64,
) -> Result<Vec<HolePunchAction>, HolePunchError>
pub fn punch_failed( &mut self, now: f64, ) -> Result<Vec<HolePunchAction>, HolePunchError>
Called when the punch phase fails.
Transitions: Punching -> Failed.
Sourcepub fn tick(&mut self, now: f64) -> Vec<HolePunchAction>
pub fn tick(&mut self, now: f64) -> Vec<HolePunchAction>
Periodic tick: check timeouts.
Sourcepub fn build_reject(
link_id: [u8; 16],
request_payload: &[u8],
reason: u8,
) -> Result<HolePunchAction, HolePunchError>
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.