Skip to main content

rns_hooks/
engine_access.rs

1/// Trait for querying engine state from within WASM host functions.
2///
3/// `rns-hooks` cannot depend on `rns-core`, so this trait defines the
4/// interface in neutral terms. `rns-net` provides the concrete implementation
5/// via a thin wrapper around `TransportEngine`.
6pub trait EngineAccess {
7    fn has_path(&self, dest: &[u8; 16]) -> bool;
8    fn hops_to(&self, dest: &[u8; 16]) -> Option<u8>;
9    fn next_hop(&self, dest: &[u8; 16]) -> Option<[u8; 16]>;
10    fn is_blackholed(&self, identity: &[u8; 16]) -> bool;
11    fn interface_name(&self, id: u64) -> Option<String>;
12    fn interface_mode(&self, id: u64) -> Option<u8>;
13    fn identity_hash(&self) -> Option<[u8; 16]>;
14    /// Outgoing announce rate for an interface, in millihertz (Hz * 1000).
15    /// Returns None if the interface is not found.
16    fn announce_rate(&self, id: u64) -> Option<i32>;
17    /// Link state as a raw u8: Pending=0, Handshake=1, Active=2, Stale=3, Closed=4.
18    /// Returns None if the link is not found.
19    fn link_state(&self, link_hash: &[u8; 16]) -> Option<u8>;
20}
21
22/// No-op implementation that returns false/None for everything.
23/// Useful for testing hooks in isolation.
24pub struct NullEngine;
25
26impl EngineAccess for NullEngine {
27    fn has_path(&self, _dest: &[u8; 16]) -> bool {
28        false
29    }
30    fn hops_to(&self, _dest: &[u8; 16]) -> Option<u8> {
31        None
32    }
33    fn next_hop(&self, _dest: &[u8; 16]) -> Option<[u8; 16]> {
34        None
35    }
36    fn is_blackholed(&self, _identity: &[u8; 16]) -> bool {
37        false
38    }
39    fn interface_name(&self, _id: u64) -> Option<String> {
40        None
41    }
42    fn interface_mode(&self, _id: u64) -> Option<u8> {
43        None
44    }
45    fn identity_hash(&self) -> Option<[u8; 16]> {
46        None
47    }
48    fn announce_rate(&self, _id: u64) -> Option<i32> {
49        None
50    }
51    fn link_state(&self, _link_hash: &[u8; 16]) -> Option<u8> {
52        None
53    }
54}