pub struct TransportEngine { /* private fields */ }Expand description
The core transport/routing engine.
Maintains routing tables and processes packets without performing any I/O.
Returns Vec<TransportAction> that the caller must execute.
Implementations§
Source§impl TransportEngine
impl TransportEngine
pub fn handle_path_request( &mut self, data: &[u8], interface_id: InterfaceId, now: f64, ) -> Vec<TransportAction>
Sourcepub fn stamp_prs(&self) -> bool
pub fn stamp_prs(&self) -> bool
Whether this node stamps the path requests it emits and the unstamped
ones it forwards for local clients (Transport.STAMP_PRS).
Sourcepub fn stamp_requirements(&self) -> StampRequirements
pub fn stamp_requirements(&self) -> StampRequirements
Stamp requirements applied to received announces and path requests.
Sourcepub fn destination_filter(&self) -> &DestinationTypeFilter
pub fn destination_filter(&self) -> &DestinationTypeFilter
Destination type filter applied to received announces.
Sourcepub fn destination_filter_mut(&mut self) -> &mut DestinationTypeFilter
pub fn destination_filter_mut(&mut self) -> &mut DestinationTypeFilter
Mutable access to the destination type filter, for [filter] and
the wants_destination_type RPC calls.
Sourcepub fn set_stamp_requirements(&mut self, requirements: StampRequirements)
pub fn set_stamp_requirements(&mut self, requirements: StampRequirements)
Override the compile-time STAMPS_ENFORCED, DESTINATION_COST and
PR_COST defaults, as the [stamps] config section does upstream.
Sourcepub fn build_path_request(
&self,
destination_hash: &[u8; 16],
tag: &[u8],
ext_payload: Option<&[u8; 16]>,
) -> Option<Vec<u8>>
pub fn build_path_request( &self, destination_hash: &[u8; 16], tag: &[u8], ext_payload: Option<&[u8; 16]>, ) -> Option<Vec<u8>>
Build a path request frame for destination_hash as this node emits
it: destination_hash || transport_id || tag, plus the optional stamp
extension payload.
This is the frame Transport.request_path sends, with or without the
ext_payload a stamper job produced.
Source§impl TransportEngine
impl TransportEngine
Sourcepub fn persistence_snapshot(&self) -> TransportStateSnapshot
pub fn persistence_snapshot(&self) -> TransportStateSnapshot
Copy the restart-relevant portion of transport state.
Sourcepub fn restore_persistence_snapshot<F>(
&mut self,
snapshot: TransportStateSnapshot,
now: f64,
announce_lookup: F,
) -> RestoreStats
pub fn restore_persistence_snapshot<F>( &mut self, snapshot: TransportStateSnapshot, now: f64, announce_lookup: F, ) -> RestoreStats
Restore state after interfaces and the announce cache are available.
Source§impl TransportEngine
impl TransportEngine
Sourcepub fn lowest_interface_bitrate(&self) -> Option<u64>
pub fn lowest_interface_bitrate(&self) -> Option<u64>
Return the slowest positive bitrate among registered interfaces.
Returns None when no registered interface advertises a usable
bitrate.
Sourcepub fn medium_path_timeout(&self) -> f64
pub fn medium_path_timeout(&self) -> f64
Estimate a path-request round-trip timeout for the slowest medium.
The estimate covers two MTU transmissions at the slowest registered positive bitrate plus the per-hop link-establishment allowance. It is zero when no usable interface bitrate is known.
pub fn path_table_entries( &self, ) -> impl Iterator<Item = (&[u8; 16], &PathEntry)>
pub fn path_table_sets(&self) -> impl Iterator<Item = (&[u8; 16], &PathSet)>
pub fn interface_count(&self) -> usize
pub fn link_table_count(&self) -> usize
pub fn active_link_count(&self) -> usize
pub fn is_unvalidated_link_packet<B: AsRef<[u8]>>( &self, packet: &RawPacket<B>, ) -> bool
Sourcepub fn is_packet_filter_protocol_violation<B: AsRef<[u8]>>(
&self,
packet: &RawPacket<B>,
interface: InterfaceId,
) -> bool
pub fn is_packet_filter_protocol_violation<B: AsRef<[u8]>>( &self, packet: &RawPacket<B>, interface: InterfaceId, ) -> bool
Classify packet-filter rejections that are peer protocol violations.
pub fn path_table_count(&self) -> usize
pub fn announce_table_count(&self) -> usize
pub fn reverse_table_count(&self) -> usize
pub fn held_announces_count(&self) -> usize
pub fn packet_hashlist_len(&self) -> usize
Sourcepub fn prefetch_packet_hash(&self, packet_hash: &[u8; 32])
pub fn prefetch_packet_hash(&self, packet_hash: &[u8; 32])
Start loading the deduplication state for packet_hash, so the
inbound filter’s lookup of a just-decoded packet overlaps that cache
miss with the driver’s admission checks. It has no other effect.
pub fn announce_sig_cache_len(&self) -> usize
pub fn rate_limiter_count(&self) -> usize
pub fn blackholed_count(&self) -> usize
pub fn tunnel_count(&self) -> usize
pub fn discovery_path_requests_count(&self) -> usize
pub fn announce_queue_count(&self) -> usize
pub fn nonempty_announce_queue_count(&self) -> usize
pub fn queued_announce_count(&self) -> usize
pub fn queued_announce_bytes(&self) -> usize
pub fn announce_queue_interface_cap_drop_count(&self) -> u64
pub fn local_destinations_count(&self) -> usize
pub fn rate_limiter(&self) -> &AnnounceRateLimiter
pub fn interface_info(&self, id: &InterfaceId) -> Option<&InterfaceInfo>
Sourcepub fn out_capable_interfaces(&self) -> impl Iterator<Item = InterfaceId> + '_
pub fn out_capable_interfaces(&self) -> impl Iterator<Item = InterfaceId> + '_
The registered interfaces that can send.
pub fn redirect_path( &mut self, dest_hash: &[u8; 16], interface: InterfaceId, now: f64, )
pub fn inject_path(&mut self, dest_hash: [u8; 16], entry: PathEntry)
pub fn drop_path(&mut self, dest_hash: &[u8; 16]) -> bool
pub fn drop_all_via(&mut self, transport_hash: &[u8; 16]) -> usize
pub fn drop_paths_for_interface(&mut self, interface: InterfaceId) -> usize
pub fn drop_reverse_for_interface(&mut self, interface: InterfaceId) -> usize
pub fn drop_links_for_interface(&mut self, interface: InterfaceId) -> usize
pub fn drop_announce_queues(&mut self)
pub fn void_queues(&mut self)
pub fn identity_hash(&self) -> Option<&[u8; 16]>
pub fn transport_enabled(&self) -> bool
pub fn config(&self) -> &TransportConfig
pub fn set_packet_hashlist_max_entries(&mut self, max_entries: usize)
pub fn get_path_table(&self, max_hops: Option<u8>) -> Vec<PathTableRow> ⓘ
Sourcepub fn path_pool_counts(&self) -> (usize, usize)
pub fn path_pool_counts(&self) -> (usize, usize)
Return (total destinations, never-used destinations) in the path pool.
Sourcepub fn link_distribution(&self) -> Vec<([u8; 16], usize, usize)>
pub fn link_distribution(&self) -> Vec<([u8; 16], usize, usize)>
Count active and validated links per destination hash.
pub fn get_rate_table(&self) -> Vec<RateTableRow> ⓘ
pub fn get_blackholed(&self) -> Vec<([u8; 16], f64, f64, Option<String>)>
pub fn active_destination_hashes(&self) -> BTreeSet<[u8; 16]>
pub fn path_destination_cap_evict_count(&self) -> usize
pub fn active_packet_hashes(&self) -> Vec<[u8; 32]>
pub fn cull_rate_limiter( &mut self, active: &BTreeSet<[u8; 16]>, now: f64, ttl_secs: f64, ) -> usize
pub fn update_interface_freq(&mut self, id: InterfaceId, ia_freq: f64)
pub fn update_interface_freqs( &mut self, id: InterfaceId, ia_freq: f64, ip_freq: f64, op_freq: f64, op_samples: usize, )
pub fn held_announce_count(&self, interface: &InterfaceId) -> usize
pub fn burst_active(&self, interface: &InterfaceId) -> bool
pub fn burst_activated(&self, interface: &InterfaceId) -> f64
pub fn pr_burst_active(&self, interface: &InterfaceId) -> bool
pub fn pr_burst_activated(&self, interface: &InterfaceId) -> f64
Sourcepub fn seed_table_hashing(&mut self, rng: &mut dyn Rng)
pub fn seed_table_hashing(&mut self, rng: &mut dyn Rng)
Key the hashing of tables indexed by packet hashes, the reverse table
and the deduplication table, with seeds drawn from rng. Packet hashes are chosen by whoever crafts the packets,
so without a secret seed a sender could grind packets into one probe
sequence and make every lookup in that table linear. Call this once
with a cryptographic RNG after creating the engine; until then the
tables use a fixed public seed.
Source§impl TransportEngine
impl TransportEngine
pub fn new(config: TransportConfig) -> Self
pub fn register_interface(&mut self, info: InterfaceInfo)
pub fn deregister_interface(&mut self, id: InterfaceId)
pub fn register_destination(&mut self, dest_hash: [u8; 16], dest_type: u8)
pub fn deregister_destination(&mut self, dest_hash: &[u8; 16])
pub fn has_path(&self, dest_hash: &[u8; 16]) -> bool
pub fn hops_to(&self, dest_hash: &[u8; 16]) -> Option<u8>
pub fn next_hop(&self, dest_hash: &[u8; 16]) -> Option<[u8; 16]>
pub fn next_hop_interface(&self, dest_hash: &[u8; 16]) -> Option<InterfaceId>
Sourcepub fn mark_path_unresponsive(
&mut self,
dest_hash: &[u8; 16],
receiving_interface: Option<InterfaceId>,
)
pub fn mark_path_unresponsive( &mut self, dest_hash: &[u8; 16], receiving_interface: Option<InterfaceId>, )
Mark a path as unresponsive.
If receiving_interface is provided and points to a MODE_BOUNDARY interface,
the marking is skipped — boundary interfaces must not poison path tables.
(Python Transport.py: mark_path_unknown/unresponsive boundary exemption)
pub fn mark_path_responsive(&mut self, dest_hash: &[u8; 16])
pub fn path_is_unresponsive(&self, dest_hash: &[u8; 16]) -> bool
pub fn expire_path(&mut self, dest_hash: &[u8; 16])
pub fn register_link(&mut self, link_id: [u8; 16], entry: LinkEntry)
pub fn validate_link(&mut self, link_id: &[u8; 16])
pub fn remove_link(&mut self, link_id: &[u8; 16])
Sourcepub fn link_rebalance_destination(
&self,
link_id: &[u8; 16],
packet_hops: u8,
receiving_interface: InterfaceId,
) -> Option<[u8; 16]>
pub fn link_rebalance_destination( &self, link_id: &[u8; 16], packet_hops: u8, receiving_interface: InterfaceId, ) -> Option<[u8; 16]>
Return the destination whose unvalidated link route can be rebalanced by a mismatched-hop LRPROOF received from its recorded next hop.
Sourcepub fn inbound_lrproof_rebalance_candidate(
&self,
raw: &[u8],
receiving_interface: InterfaceId,
) -> Option<LrproofRebalanceCandidate>
pub fn inbound_lrproof_rebalance_candidate( &self, raw: &[u8], receiving_interface: InterfaceId, ) -> Option<LrproofRebalanceCandidate>
Parse and filter an inbound frame before offering it for LRPROOF path rebalancing. The returned hops are the post-ingress metric used by the normal transport pipeline.
pub fn decoded_lrproof_rebalance_candidate( &self, decoded: &DecodedPacket, receiving_interface: InterfaceId, ) -> Option<LrproofRebalanceCandidate>
Sourcepub fn rebalance_link_path_from_lrproof(
&mut self,
link_id: &[u8; 16],
packet_hops: u8,
receiving_interface: InterfaceId,
proof_data: &[u8],
destination_sig_pub_bytes: &[u8; 32],
) -> bool
pub fn rebalance_link_path_from_lrproof( &mut self, link_id: &[u8; 16], packet_hops: u8, receiving_interface: InterfaceId, proof_data: &[u8], destination_sig_pub_bytes: &[u8; 32], ) -> bool
Validate a mismatched-hop LRPROOF and update the relay link route and destination path atomically enough for normal proof routing to resume.
The engine is exclusively borrowed for the whole operation, so the link and path mutations need neither separate path-table locks nor repeated map lookups. A path can legitimately be absent; that does not invalidate the authenticated link-route update.
Sourcepub fn rebalance_destination_path_hops(
&mut self,
destination_hash: &[u8; 16],
packet_hops: u8,
) -> bool
pub fn rebalance_destination_path_hops( &mut self, destination_hash: &[u8; 16], packet_hops: u8, ) -> bool
Update the current path metric after a terminus validates an LRPROOF.
Sourcepub fn blackhole_identity(
&mut self,
identity_hash: [u8; 16],
now: f64,
duration_hours: Option<f64>,
reason: Option<String>,
)
pub fn blackhole_identity( &mut self, identity_hash: [u8; 16], now: f64, duration_hours: Option<f64>, reason: Option<String>, )
Add an identity hash to the blackhole list.
identity_hash is the 16-byte identity hash to blackhole. now is the
current Unix timestamp. If duration_hours is Some and greater than
zero, the entry expires after that many hours; otherwise it does not
expire. reason is optional descriptive text retained with the entry.
Sourcepub fn unblackhole_identity(&mut self, identity_hash: &[u8; 16]) -> bool
pub fn unblackhole_identity(&mut self, identity_hash: &[u8; 16]) -> bool
Remove an identity hash from the blackhole list.
Returns true if an entry was removed, or false if the identity was
not blackholed.
Sourcepub fn is_blackholed(&self, identity_hash: &[u8; 16], now: f64) -> bool
pub fn is_blackholed(&self, identity_hash: &[u8; 16], now: f64) -> bool
Check if an identity hash is blackholed (and not expired).
Sourcepub fn blackholed_entries(
&self,
) -> impl Iterator<Item = (&[u8; 16], &BlackholeEntry)>
pub fn blackholed_entries( &self, ) -> impl Iterator<Item = (&[u8; 16], &BlackholeEntry)>
Get all blackhole entries (for queries).
Sourcepub fn handle_tunnel(
&mut self,
tunnel_id: [u8; 32],
interface: InterfaceId,
now: f64,
) -> Vec<TransportAction>
pub fn handle_tunnel( &mut self, tunnel_id: [u8; 32], interface: InterfaceId, now: f64, ) -> Vec<TransportAction>
Handle a validated tunnel synthesis — create new or reattach.
Returns actions for any restored paths.
Sourcepub fn synthesize_tunnel(
&self,
identity: &Identity,
interface_id: InterfaceId,
rng: &mut dyn Rng,
) -> Vec<TransportAction>
pub fn synthesize_tunnel( &self, identity: &Identity, interface_id: InterfaceId, rng: &mut dyn Rng, ) -> Vec<TransportAction>
Synthesize a tunnel on an interface.
identity: the transport identity (must have private key for signing)
interface_id: which interface to send the synthesis on
rng: random number generator
Returns TunnelSynthesize action to send the synthesis packet.
Sourcepub fn void_tunnel_interface(&mut self, tunnel_id: &[u8; 32])
pub fn void_tunnel_interface(&mut self, tunnel_id: &[u8; 32])
Void a tunnel’s interface connection (tunnel disconnected).
Sourcepub fn tunnel_table(&self) -> &TunnelTable
pub fn tunnel_table(&self) -> &TunnelTable
Access the tunnel table for queries.
Source§impl TransportEngine
impl TransportEngine
Sourcepub fn accepts_inbound_frame(&self, frame: InboundFrame<'_>) -> bool
pub fn accepts_inbound_frame(&self, frame: InboundFrame<'_>) -> bool
Return whether an inbound frame passes parsing, hop, and packet filtering. This does not mutate deduplication or routing state.
Sourcepub fn handle_inbound(
&mut self,
frame: InboundFrame<'_>,
rng: &mut dyn Rng,
) -> Vec<TransportAction>
pub fn handle_inbound( &mut self, frame: InboundFrame<'_>, rng: &mut dyn Rng, ) -> Vec<TransportAction>
Process an inbound raw packet from a network interface.
Returns a list of actions for the caller to execute.
pub fn handle_inbound_with_announce_queue( &mut self, frame: InboundFrame<'_>, rng: &mut dyn Rng, announce_queue: Option<&mut AnnounceVerifyQueue>, ) -> Vec<TransportAction>
Sourcepub fn decode_inbound(
&self,
raw: PacketBytes,
) -> Result<DecodedPacket, PacketError>
pub fn decode_inbound( &self, raw: PacketBytes, ) -> Result<DecodedPacket, PacketError>
Decode an inbound frame for handle_decoded_inbound_with_announce_queue.
Link traffic that this node only forwards, in a context the packet
filter admits without consulting deduplication, is not hashed: no
step that handles it reads the hash. Its hash cannot reject any later
packet either, since a packet with the same hash has the same context.
Nor is a resource part, part request or resource proof for a local
link (see RawPacket::is_unhashed_link_resource); its delivery
carries a zeroed hash. DecodedPacket::packet_hash reports whether hashing was
deferred.
It takes ownership of the wire bytes, which the decoded packet keeps.
Sourcepub fn handle_decoded_inbound_with_announce_queue(
&mut self,
frame: DecodedInboundFrame,
rng: &mut dyn Rng,
announce_queue: Option<&mut AnnounceVerifyQueue>,
) -> Vec<TransportAction>
pub fn handle_decoded_inbound_with_announce_queue( &mut self, frame: DecodedInboundFrame, rng: &mut dyn Rng, announce_queue: Option<&mut AnnounceVerifyQueue>, ) -> Vec<TransportAction>
Recheck current routing/filter state and consume a previously decoded frame.
Sourcepub fn handle_decoded_inbound_into(
&mut self,
frame: DecodedInboundFrame,
rng: &mut dyn Rng,
announce_queue: Option<&mut AnnounceVerifyQueue>,
actions: &mut Vec<TransportAction>,
)
pub fn handle_decoded_inbound_into( &mut self, frame: DecodedInboundFrame, rng: &mut dyn Rng, announce_queue: Option<&mut AnnounceVerifyQueue>, actions: &mut Vec<TransportAction>, )
Self::handle_decoded_inbound_with_announce_queue, appending the
actions to actions so a caller can reuse one buffer across packets.
pub fn accepts_decoded_packet( &self, decoded: &DecodedPacket, iface: InterfaceId, ) -> bool
pub fn complete_verified_announce( &mut self, pending: PendingAnnounce, validated: ValidatedAnnounce, sig_cache_key: [u8; 32], now: f64, rng: &mut dyn Rng, ) -> Vec<TransportAction>
pub fn clear_failed_verified_announce( &mut self, _sig_cache_key: [u8; 32], _now: f64, )
pub fn announce_sig_cache_contains(&self, sig_cache_key: &[u8; 32]) -> bool
Source§impl TransportEngine
impl TransportEngine
Sourcepub fn tick(&mut self, now: f64, rng: &mut dyn Rng) -> Vec<TransportAction>
pub fn tick(&mut self, now: f64, rng: &mut dyn Rng) -> Vec<TransportAction>
Periodic maintenance. Call regularly (e.g., every 250ms).
Sourcepub fn queue_path_rediscovery(
&mut self,
destination_hash: [u8; 16],
skip_interface: Option<InterfaceId>,
now: f64,
)
pub fn queue_path_rediscovery( &mut self, destination_hash: [u8; 16], skip_interface: Option<InterfaceId>, now: f64, )
Queue a path rediscovery request for destination_hash, skipping
skip_interface, unless one is already queued or the queue is full.
Source§impl TransportEngine
impl TransportEngine
Sourcepub fn handle_outbound<B: PacketStorage>(
&mut self,
packet: &RawPacket<B>,
dest_type: u8,
attached_interface: Option<InterfaceId>,
now: f64,
) -> Vec<TransportAction>
pub fn handle_outbound<B: PacketStorage>( &mut self, packet: &RawPacket<B>, dest_type: u8, attached_interface: Option<InterfaceId>, now: f64, ) -> Vec<TransportAction>
Route an outbound packet.
Sourcepub fn handle_outbound_into<B: PacketStorage>(
&mut self,
packet: &RawPacket<B>,
dest_type: u8,
attached_interface: Option<InterfaceId>,
now: f64,
actions: &mut Vec<TransportAction>,
)
pub fn handle_outbound_into<B: PacketStorage>( &mut self, packet: &RawPacket<B>, dest_type: u8, attached_interface: Option<InterfaceId>, now: f64, actions: &mut Vec<TransportAction>, )
Self::handle_outbound, appending the actions to actions so a
caller can reuse one buffer across packets.