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
impl LinkEngine
Sourcepub fn new_initiator(
dest_hash: &[u8; 16],
hops: u8,
mode: LinkMode,
mtu: Option<u32>,
now: f64,
rng: &mut dyn Rng,
) -> (Self, Vec<u8>)
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.
Sourcepub fn set_link_id_from_hashable(
&mut self,
hashable_part: &[u8],
data_len: usize,
)
pub fn set_link_id_from_hashable( &mut self, hashable_part: &[u8], data_len: usize, )
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).
Sourcepub 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>
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.
Sourcepub 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>
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.
Sourcepub fn handle_lrrtt(
&mut self,
encrypted_data: &[u8],
now: f64,
) -> Result<Vec<LinkAction>, LinkError>
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.
Sourcepub fn encrypt(
&self,
plaintext: &[u8],
rng: &mut dyn Rng,
) -> Result<Vec<u8>, LinkError>
pub fn encrypt( &self, plaintext: &[u8], rng: &mut dyn Rng, ) -> Result<Vec<u8>, LinkError>
Encrypt plaintext for transmission over this link.
Sourcepub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, LinkError>
pub fn decrypt(&self, ciphertext: &[u8]) -> Result<Vec<u8>, LinkError>
Decrypt ciphertext received on this link.
Sourcepub fn build_identify(
&self,
identity: &Identity,
rng: &mut dyn Rng,
) -> Result<Vec<u8>, LinkError>
pub fn build_identify( &self, identity: &Identity, rng: &mut dyn Rng, ) -> Result<Vec<u8>, LinkError>
Build LINKIDENTIFY data (encrypted).
Sourcepub fn handle_identify(
&mut self,
encrypted_data: &[u8],
) -> Result<Vec<LinkAction>, LinkError>
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).
Sourcepub fn record_inbound(&mut self, now: f64) -> Vec<LinkAction>
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).
Sourcepub fn record_proof(&mut self, now: f64)
pub fn record_proof(&mut self, now: f64)
Record that a proof was received (updates timing for stale detection).
Sourcepub fn record_outbound(&mut self, now: f64, is_keepalive: bool)
pub fn record_outbound(&mut self, now: f64, is_keepalive: bool)
Record that an outbound packet was sent (updates timing).
Sourcepub fn tick(&mut self, now: f64) -> Vec<LinkAction>
pub fn tick(&mut self, now: f64) -> Vec<LinkAction>
Periodic tick: check keepalive, stale, timeouts.
Sourcepub fn needs_keepalive(&self, now: f64) -> bool
pub fn needs_keepalive(&self, now: f64) -> bool
Check if a keepalive should be sent. Returns true if conditions are met.
Sourcepub fn teardown(&mut self) -> Vec<LinkAction>
pub fn teardown(&mut self) -> Vec<LinkAction>
Tear down the link (initiator-initiated close).
Sourcepub fn handle_teardown(&mut self) -> Vec<LinkAction>
pub fn handle_teardown(&mut self) -> Vec<LinkAction>
Handle incoming teardown (remote close).