api: make config structs non-exhaustive and the outbound module private

This commit is contained in:
DeFiDude committed 2026-11-13 11:25:03 -07:00
1 parent d508f19b77
commit 747aa966f6
5 files changed
+182 -145

No files matched your search

+116 -74
View File
@@ -6466,6 +6466,63 @@ mod tests {
}
use super::*;
/// Returns once the actor has handled everything already in its mailbox.
async fn actor_settled(tx: &mpsc::Sender<TransportMessage>) {
let (response_tx, response_rx) = tokio::sync::oneshot::channel();
tx.send(TransportMessage::Rpc {
query: rns_transport::messages::TransportQuery::GetLinkCount,
response_tx,
})
.await
.unwrap();
response_rx.await.unwrap();
}
/// A signed announce heard on `interface_id`, which gives the actor a
/// one-hop path to the returned destination.
fn heard_announce(
interface_id: u64,
owner: &rns_transport::InterfaceOwner,
) -> ([u8; 16], TransportMessage) {
let identity = rns_identity::identity::Identity::new();
let app = "lxmf.test.path";
let dest = rns_identity::destination::Destination::hash_from_name_and_identity(
app,
Some(&identity.hash),
);
let announce =
rns_identity::announce::AnnounceData::create(&identity, app, None, None).unwrap();
let header = rns_wire::header::PacketHeader {
flags: rns_wire::flags::PacketFlags {
header_type: rns_wire::flags::HeaderType::Header1,
context_flag: false,
transport_type: rns_wire::flags::TransportType::Broadcast,
destination_type: rns_wire::flags::DestinationType::Single,
packet_type: rns_wire::flags::PacketType::Announce,
},
hops: 0,
transport_id: None,
destination_hash: dest,
context: rns_wire::context::PacketContext::None,
};
let mut raw = header.pack();
raw.extend(announce.pack());
let event = TransportMessage::InterfaceEvent {
interface_id,
owner: owner.clone(),
message: Box::new(TransportMessage::Inbound(
rns_transport::messages::InboundPacket {
raw: raw.into(),
interface_id,
rssi: None,
snr: None,
q: None,
},
)),
};
(dest, event)
}
use std::collections::HashMap;
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -6807,20 +6864,21 @@ mod tests {
use rns_transport::actor::TransportActor;
use rns_transport::constants::{InterfaceDirection, InterfaceMode};
use rns_transport::messages::InterfaceEntry;
let (mut actor, actor_tx) = TransportActor::new();
let (actor, actor_tx) = TransportActor::new();
let (driver_tx, _driver_rx) = mpsc::channel(8);
actor.interfaces.insert(
7,
InterfaceEntry::new(
"bind cancellation".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
),
let entry = InterfaceEntry::new(
"bind cancellation".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
);
let interface_owner = actor.interfaces[&7].owner.id();
let entry_owner = entry.owner.clone();
actor_tx
.try_send(TransportMessage::RegisterInterface { id: 7, entry })
.unwrap();
let interface_owner = entry_owner.id();
let dispatch = actor.link_endpoint_dispatch_handle();
let (tx, mut rx) = mpsc::channel(32);
let mut mgr = LinkDeliveryManager::new(tx, None, None);
@@ -6847,6 +6905,7 @@ mod tests {
assert!(mgr.pending_endpoint_binds.is_empty());
assert!(!mgr.pending.contains_key(&link_id));
let task = tokio::spawn(actor.run());
actor_settled(&actor_tx).await;
let (lifecycle_tx, _lifecycle_rx) = mpsc::unbounded_channel();
let receipt = dispatch
.try_bind(
@@ -6884,30 +6943,28 @@ mod tests {
use rns_transport::actor::TransportActor;
use rns_transport::constants::{InterfaceDirection, InterfaceMode};
use rns_transport::messages::InterfaceEntry;
use rns_transport::path_table::PathEntry;
// Cancel the first before LRPROOF, after LRPROOF but before exact bind
// publication, or cancel only the middle queued message.
for mode in 0..3 {
let (mut actor, tx) = TransportActor::new();
let (actor, tx) = TransportActor::new();
let (driver_tx, mut driver_rx) = mpsc::channel(8);
let dest = [0x38; 16];
actor.interfaces.insert(
7,
InterfaceEntry::new(
"queued cancellation".into(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
),
let entry = InterfaceEntry::new(
"queued cancellation".into(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
);
actor
.path_table
.insert(dest, PathEntry::new(None, 1, 7, InterfaceMode::Full));
let interface_owner = actor.interfaces[&7].owner.id();
let entry_owner = entry.owner.clone();
tx.try_send(TransportMessage::RegisterInterface { id: 7, entry })
.unwrap();
let (dest, heard) = heard_announce(7, &entry_owner);
tx.try_send(heard).unwrap();
let interface_owner = entry_owner.id();
let dispatch = actor.link_endpoint_dispatch_handle();
let task = tokio::spawn(actor.run());
actor_settled(&tx).await;
let mut mgr = LinkDeliveryManager::new(tx.clone(), None, None);
mgr.set_link_endpoint_dispatch_handle(dispatch);
let mut messages = [
@@ -7005,28 +7062,26 @@ mod tests {
use rns_transport::actor::TransportActor;
use rns_transport::constants::{InterfaceDirection, InterfaceMode};
use rns_transport::messages::{InterfaceEntry, TimerTick};
use rns_transport::path_table::PathEntry;
let (mut actor, tx) = TransportActor::new();
let (actor, tx) = TransportActor::new();
let (driver_tx, mut driver_rx) = mpsc::channel(1);
let dest = [0x94; 16];
actor.interfaces.insert(
7,
InterfaceEntry::new(
"bounded test driver".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
),
let entry = InterfaceEntry::new(
"bounded test driver".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
);
actor
.path_table
.insert(dest, PathEntry::new(None, 1, 7, InterfaceMode::Full));
let interface_owner = actor.interfaces[&7].owner.id();
let entry_owner = entry.owner.clone();
tx.try_send(TransportMessage::RegisterInterface { id: 7, entry })
.unwrap();
let (dest, heard) = heard_announce(7, &entry_owner);
tx.try_send(heard).unwrap();
let interface_owner = entry_owner.id();
let handle = actor.link_endpoint_dispatch_handle();
let actor_task = tokio::spawn(actor.run());
actor_settled(&tx).await;
let identity = Ed25519PrivateKey::generate();
let mut identity_pub = [0; 64];
identity_pub[32..].copy_from_slice(&identity.public_key().to_bytes());
@@ -7095,14 +7150,7 @@ mod tests {
// Propagation uploads are never identified, even with identity keys.
assert_eq!(header.context, rns_wire::context::PacketContext::Lrrtt);
responder.receive_rtt_packet(&rtt[offset..]).unwrap();
tx.send(TransportMessage::Tick(TimerTick {
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs_f64(),
}))
.await
.unwrap();
tx.send(TransportMessage::Tick(TimerTick)).await.unwrap();
if cancel {
assert!(
tokio::time::timeout(Duration::from_millis(50), driver_rx.recv())
@@ -8038,23 +8086,24 @@ mod tests {
use rns_transport::constants::{InterfaceDirection, InterfaceMode};
use rns_transport::messages::{InterfaceEntry, TimerTick};
for mode in 0..4 {
let (mut actor, tx) = TransportActor::new();
let (actor, tx) = TransportActor::new();
let (driver_tx, mut driver_rx) = mpsc::channel(1);
driver_tx.try_send(Bytes::from_static(b"occupied")).unwrap();
actor.interfaces.insert(
7,
InterfaceEntry::new(
"cancelled backchannel driver".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
),
let entry = InterfaceEntry::new(
"cancelled backchannel driver".to_string(),
InterfaceMode::Full,
InterfaceDirection::bidirectional(),
3_515,
500,
driver_tx,
);
let interface_owner = actor.interfaces[&7].owner.id();
let entry_owner = entry.owner.clone();
tx.try_send(TransportMessage::RegisterInterface { id: 7, entry })
.unwrap();
let interface_owner = entry_owner.id();
let dispatch = actor.link_endpoint_dispatch_handle();
let actor_task = tokio::spawn(actor.run());
actor_settled(&tx).await;
let link_id = [0x59; 16];
let dest = [0x5A; 16];
let (lifecycle_tx, _lifecycle_rx) = mpsc::unbounded_channel();
@@ -8153,14 +8202,7 @@ mod tests {
)
.unwrap();
assert_eq!(driver_rx.recv().await.unwrap(), b"occupied"[..]);
tx.send(TransportMessage::Tick(TimerTick {
timestamp: std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.unwrap()
.as_secs_f64(),
}))
.await
.unwrap();
tx.send(TransportMessage::Tick(TimerTick)).await.unwrap();
assert_eq!(
tokio::time::timeout(Duration::from_secs(2), driver_rx.recv())
.await
+7 -2
View File
@@ -29,8 +29,11 @@ use crate::stamper;
use crate::ticket::{Ticket, TicketStore};
use crate::types::PropagationTransientId;
pub mod outbound;
pub use outbound::{MediumSnapshot, RouteInfo, attempt_due, attempt_limit, schedule_attempt};
mod outbound;
pub use outbound::{
MediumSnapshot, RouteInfo, attempt_due, attempt_limit, opportunistic_receipt_timeout,
schedule_attempt,
};
/// Outstanding inbound admission reservation. Return it to the same router
/// instance that issued it; its counter is not unique across router instances.
@@ -74,6 +77,7 @@ impl OutboundTicketIntent {
/// Additional settings live in [`RouterConfigExt`] behind the `ext` field.
/// Embedders must pass relevant policy to their transport and propagation owners.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RouterConfig {
pub propagation_enabled: bool,
pub autopeer: bool,
@@ -93,6 +97,7 @@ pub struct RouterConfig {
///
/// Additional routing, admission and propagation settings with a [`Default`] implementation.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RouterConfigExt {
pub autopeer_maxdepth: usize,
pub propagation_cost_min: f64,
+26 -32
View File
@@ -5927,7 +5927,7 @@ impl LxmdRunner {
};
let mut raw = header.pack();
raw.extend_from_slice(&payload);
let timeout = lxmf_core::router::outbound::opportunistic_receipt_timeout(
let timeout = lxmf_core::router::opportunistic_receipt_timeout(
self.medium.route(&dest_hash),
message.receipt_timeout,
);
@@ -7475,10 +7475,8 @@ mod tests {
let (tx, _driver) = transport_that_heard(&announce).await;
let temp = tempfile::tempdir().unwrap();
initialize_storage_namespace(temp.path()).unwrap();
let config = DaemonConfig {
outbound_propagation_node: Some(node_hex.clone()),
..DaemonConfig::default()
};
let mut config = DaemonConfig::default();
config.outbound_propagation_node = Some(node_hex.clone());
let mut runner = LxmdRunner::new(config, temp.path(), tx, None).unwrap();
let deadline = Instant::now() + Duration::from_secs(5);
@@ -7700,20 +7698,19 @@ mod tests {
response_tx,
} = message
{
let entry = rns_transport::messages::PathTableRpcEntry {
hash: neighbour,
timestamp: now_f64(),
via: Some(neighbour),
hops: 0,
expires: now_f64() + 600.0,
value: None,
used: 0.0,
lr_cost: None,
interface: String::new(),
interface_id: 1,
interface_mode: rns_transport::constants::InterfaceMode::Full,
interface_role: Default::default(),
};
let mut entry = rns_transport::messages::PathTableRpcEntry::default();
entry.hash = neighbour;
entry.timestamp = now_f64();
entry.via = Some(neighbour);
entry.hops = 0;
entry.expires = now_f64() + 600.0;
entry.value = None;
entry.used = 0.0;
entry.lr_cost = None;
entry.interface = String::new();
entry.interface_id = 1;
entry.interface_mode = rns_transport::constants::InterfaceMode::Full;
entry.interface_role = Default::default();
let _ = response_tx.send(TransportQueryResponse::PathTable(vec![entry]));
return;
}
@@ -7762,14 +7759,13 @@ mod tests {
&& dest == recipient_hash
{
// Announce app data whose feature list lacks SF_COMPRESSION.
let entry = rns_transport::messages::RecalledDestinationRpcEntry {
dest_hash: recipient_hash,
public_key: recipient.get_public_key(),
app_data: Some(vec![0x93, 0xc4, 0x01, b'n', 0xc0, 0x90]),
ratchet: None,
hops: 1,
timestamp: now_f64(),
};
let mut entry = rns_transport::messages::RecalledDestinationRpcEntry::default();
entry.dest_hash = recipient_hash;
entry.public_key = recipient.get_public_key();
entry.app_data = Some(vec![0x93, 0xc4, 0x01, b'n', 0xc0, 0x90]);
entry.ratchet = None;
entry.hops = 1;
entry.timestamp = now_f64();
let _ = response_tx.send(TransportQueryResponse::RecalledDestination(Some(entry)));
answered = true;
}
@@ -8593,11 +8589,9 @@ mod tests {
std::process::id()
));
let (tx, _rx) = mpsc::channel::<TransportMessage>(64);
let config = DaemonConfig {
stamp_cost: Some(12.0),
enforce_stamps,
..Default::default()
};
let mut config = DaemonConfig::default();
config.stamp_cost = Some(12.0);
config.enforce_stamps = enforce_stamps;
initialize_storage_namespace(&temp).unwrap();
let mut runner = LxmdRunner::new(config, &temp, tx, None).expect("runner");
let raw = runner
+21 -23
View File
@@ -7,7 +7,7 @@ pub use lxmf_core::handlers::PnLimit;
use lxmf_core::propagation_admission::{
PN_DEFAULT_MAX_INBOUND_SYNCS, PN_MIN_MAX_INBOUND_SYNCS, PnInboundAdmissionConfig,
};
use lxmf_core::router::{LxmRouter, RouterConfig, RouterConfigExt};
use lxmf_core::router::{LxmRouter, RouterConfig};
use rns_runtime::config::{Config, ConfigSection};
/// Normalized view of Python `lxmd.apply_config()` behavior.
@@ -410,6 +410,7 @@ fn parse_static_peer(raw: &str) -> Result<[u8; 16], DaemonConfigError> {
/// Daemon configuration parsed from an INI config file.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct DaemonConfig {
pub display_name: Option<String>,
pub node_name: Option<String>,
@@ -490,28 +491,25 @@ impl Default for DaemonConfig {
impl DaemonConfig {
pub fn to_router_config(&self) -> RouterConfig {
RouterConfig {
propagation_enabled: self.propagation_enabled,
autopeer: self.autopeer,
max_peers: self.max_peers,
propagation_limit_kb: self.propagation_limit_kb,
delivery_limit_kb: self.delivery_transfer_max_accepted_size,
sync_limit_kb: self.sync_limit_kb,
propagation_stamp_cost: self.propagation_stamp_cost,
propagation_stamp_flex: self.propagation_stamp_flex,
stamp_cost: self.stamp_cost,
ext: RouterConfigExt {
autopeer_maxdepth: self.autopeer_maxdepth,
peering_cost: self.peering_cost,
max_peering_cost: self.max_peering_cost,
auth_required: self.auth_required,
message_storage_limit: self.message_storage_limit,
name: self.node_name.clone(),
from_static_only: self.from_static_only,
pn_stamp_throttle: self.pn_stamp_throttle,
..Default::default()
},
}
let mut config = RouterConfig::default();
config.propagation_enabled = self.propagation_enabled;
config.autopeer = self.autopeer;
config.max_peers = self.max_peers;
config.propagation_limit_kb = self.propagation_limit_kb;
config.delivery_limit_kb = self.delivery_transfer_max_accepted_size;
config.sync_limit_kb = self.sync_limit_kb;
config.propagation_stamp_cost = self.propagation_stamp_cost;
config.propagation_stamp_flex = self.propagation_stamp_flex;
config.stamp_cost = self.stamp_cost;
config.ext.autopeer_maxdepth = self.autopeer_maxdepth;
config.ext.peering_cost = self.peering_cost;
config.ext.max_peering_cost = self.max_peering_cost;
config.ext.auth_required = self.auth_required;
config.ext.message_storage_limit = self.message_storage_limit;
config.ext.name = self.node_name.clone();
config.ext.from_static_only = self.from_static_only;
config.ext.pn_stamp_throttle = self.pn_stamp_throttle;
config
}
/// Python `max(0, propagation_stamp_cost - propagation_stamp_cost_flexibility)`.
+12 -14
View File
@@ -963,16 +963,16 @@ mod tests {
TransportQuery::RecallDestination { dest } if dest == remote_destination_hash
));
response_tx
.send(TransportQueryResponse::RecalledDestination(Some(
RecalledDestinationRpcEntry {
dest_hash: remote_destination_hash,
public_key,
app_data: None,
ratchet: None,
hops: 2,
timestamp: 1.0,
},
)))
.send(TransportQueryResponse::RecalledDestination(Some({
let mut entry = RecalledDestinationRpcEntry::default();
entry.dest_hash = remote_destination_hash;
entry.public_key = public_key;
entry.app_data = None;
entry.ratchet = None;
entry.hops = 2;
entry.timestamp = 1.0;
entry
})))
.expect("return resolved identity");
assert!(transport_rx.try_recv().is_err());
});
@@ -1104,10 +1104,8 @@ mod tests {
use lxmf_core::peer::LxmPeer;
use lxmf_core::router::{LxmRouter, RouterConfig};
let mut config = RouterConfig {
propagation_enabled: true,
..Default::default()
};
let mut config = RouterConfig::default();
config.propagation_enabled = true;
config.delivery_limit_kb = 0.38;
config.ext.message_storage_limit = Some(500_000_000);
let mut router = LxmRouter::new(config);