Skip to main content

LinkEngine

Struct LinkEngine 

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

The Link Engine manages a single link’s lifecycle.

It follows the action-queue model: methods return Vec<LinkAction> instead of performing I/O directly. The caller dispatches actions.

Implementations§

Source§

impl LinkEngine

Source

pub fn new_initiator( dest_hash: &[u8; 16], hops: u8, mode: LinkMode, mtu: Option<u32>, now: f64, rng: &mut dyn Rng, ) -> (Self, Vec<u8>)

Create a new initiator-side link engine.

Returns (engine, linkrequest_data) — the caller must pack linkrequest_data into a LINKREQUEST packet and send it.

Set link_id from the hashable part of the packed LINKREQUEST packet.

Must be called after packing the LINKREQUEST packet (since link_id depends on the packet’s hashable part).

Source

pub fn new_responder( owner_sig_prv: &Ed25519PrivateKey, owner_sig_pub_bytes: &[u8; 32], linkrequest_data: &[u8], hashable_part: &[u8], dest_hash: &[u8; 16], hops: u8, now: f64, rng: &mut dyn Rng, ) -> Result<(Self, Vec<u8>), LinkError>

Create a new responder-side link engine from an incoming LINKREQUEST.

owner_sig_prv / owner_sig_pub are the destination’s signing keys. Returns (engine, actions) where actions include the LRPROOF data to send.

Source

pub fn handle_lrproof( &mut self, proof_data: &[u8], peer_sig_pub_bytes: &[u8; 32], now: f64, rng: &mut dyn Rng, ) -> Result<(Vec<u8>, Vec<LinkAction>), LinkError>

Handle an incoming LRPROOF (initiator side).

Validates the proof, performs ECDH, derives session key, returns LRRTT data to be encrypted and sent.

Source

pub fn handle_lrrtt( &mut self, encrypted_data: &[u8], now: f64, ) -> Result<Vec<LinkAction>, LinkError>

Handle an incoming LRRTT (responder side).

Decrypts the RTT packet, activates the link.

Source

pub fn encrypt( &self, plaintext: &[u8], rng: &mut dyn Rng, ) -> Result<Vec<u8>, LinkError>

Encrypt plaintext for transmission over this link.

Source

pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, LinkError>

Decrypt ciphertext received on this link.

Source

pub fn build_identify( &self, identity: &Identity, rng: &mut dyn Rng, ) -> Result<Vec<u8>, LinkError>

Build LINKIDENTIFY data (encrypted).

Source

pub fn handle_identify( &mut self, encrypted_data: &[u8], ) -> Result<Vec<LinkAction>, LinkError>

Handle incoming LINKIDENTIFY (encrypted data).

Only responders (non-initiators) can receive LINKIDENTIFY (Python: Link.py:1017).

Source

pub fn record_inbound(&mut self, now: f64) -> Vec<LinkAction>

Record that an inbound packet was received (updates timing).

If the link is STALE, recovers to ACTIVE (Python: Link.py:987-988).

Source

pub fn record_proof(&mut self, now: f64)

Record that a proof was received (updates timing for stale detection).

Source

pub fn record_outbound(&mut self, now: f64, is_keepalive: bool)

Record that an outbound packet was sent (updates timing).

Source

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

Periodic tick: check keepalive, stale, timeouts.

Source

pub fn needs_keepalive(&self, now: f64) -> bool

Check if a keepalive should be sent. Returns true if conditions are met.

Source

pub fn teardown(&mut self) -> Vec<LinkAction>

Tear down the link (initiator-initiated close).

Source

pub fn handle_teardown(&mut self) -> Vec<LinkAction>

Handle incoming teardown (remote close).

Source

pub fn state(&self) -> LinkState

Source

pub fn rtt(&self) -> Option<f64>

Source

pub fn mdu(&self) -> usize

Source

pub fn is_initiator(&self) -> bool

Source

pub fn mode(&self) -> LinkMode

Source

pub fn remote_identity(&self) -> Option<&([u8; 16], [u8; 64])>

Source

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

Source

pub fn keepalive_interval(&self) -> f64

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.