From dc77cdf01400837a2ac87b04bd0eb41e66bff848 Mon Sep 17 00:00:00 2001 From: DeFiDude <59237470+DeFiDude@users.noreply.github.com> Date: Wed, 18 Nov 2026 12:48:00 -0700 Subject: [PATCH] stamps: stamp announces and path requests by default --- crates/rns-runtime/src/destination_stamper.rs | 108 +++++++++++++++++- crates/rns-runtime/src/interface_factory.rs | 17 +-- crates/rns-runtime/src/link_manager.rs | 5 + crates/rns-runtime/src/probe.rs | 1 + crates/rns-runtime/src/reticulum.rs | 62 ++++++++++ .../src/reticulum/tests/concurrent_start.rs | 14 ++- .../src/reticulum/tests/tunnels.rs | 1 + crates/rns-runtime/src/shared_instance.rs | 4 +- crates/rns-transport/src/actor/mod.rs | 13 +++ crates/rns-transport/src/actor/outbound.rs | 8 +- .../src/actor/path_request_admission.rs | 29 +++-- .../src/actor/tests/discovery_api.rs | 1 + .../src/actor/tests/discovery_public_api.rs | 1 + .../src/actor/tests/slow_media_discovery.rs | 1 + crates/rns-transport/src/stamps.rs | 26 +++-- 15 files changed, 251 insertions(+), 40 deletions(-) diff --git a/crates/rns-runtime/src/destination_stamper.rs b/crates/rns-runtime/src/destination_stamper.rs index 91214c3..e46bd5d 100644 --- a/crates/rns-runtime/src/destination_stamper.rs +++ b/crates/rns-runtime/src/destination_stamper.rs @@ -52,7 +52,7 @@ fn settings() -> Settings { .unwrap_or_default() } -/// The configured process stamp policy, or the 1.6.0 defaults. +/// The configured process stamp policy, or the defaults. pub fn policy() -> StampPolicy { settings().policy } @@ -439,3 +439,109 @@ pub async fn announce_packet( ) .map(Some) } + +/// Tests share the process stamp settings. Each `init` writes them, so starts +/// run alongside each other but never alongside a test that holds a guard, and +/// leave destination stamping off. +#[cfg(test)] +pub(crate) mod test_settings { + use std::future::Future; + use std::path::PathBuf; + + use rns_transport::stamps::StampPolicy; + use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; + + static LOCK: RwLock<()> = RwLock::const_new(()); + + fn unstamped_policy() -> StampPolicy { + StampPolicy { + stamp_destinations: false, + ..StampPolicy::default() + } + } + + /// Destination stamping off while held. + pub(crate) async fn unstamped() -> RwLockWriteGuard<'static, ()> { + let guard = LOCK.write().await; + super::configure(unstamped_policy(), None); + guard + } + + pub(crate) fn blocking_unstamped() -> RwLockWriteGuard<'static, ()> { + blocking_exclusive(unstamped_policy(), None) + } + + /// These settings while held. + pub(crate) fn blocking_exclusive( + policy: StampPolicy, + storage_dir: Option, + ) -> RwLockWriteGuard<'static, ()> { + let guard = LOCK.blocking_write(); + super::configure(policy, storage_dir); + guard + } + + /// Held across a start; dropping it leaves destination stamping off. + pub(crate) struct Starting { + _guard: RwLockReadGuard<'static, ()>, + } + + impl Drop for Starting { + fn drop(&mut self) { + super::configure(unstamped_policy(), None); + } + } + + pub(crate) async fn starting() -> Starting { + Starting { + _guard: LOCK.read().await, + } + } + + pub(crate) async fn around_init(init: F) -> F::Output { + let _starting = starting().await; + init.await + } +} + +#[cfg(test)] +mod tests { + use super::*; + use rns_identity::destination::DestType; + + #[test] + fn default_policy_holds_announces_until_a_stamp_meets_the_target() { + let _settings = test_settings::blocking_exclusive(StampPolicy::default(), None); + let identity = Identity::new(); + let mut destination = Destination::new( + Some(&identity), + Direction::In, + DestType::Single, + "test.default.stamping", + ) + .unwrap(); + let mut stamps = DestinationStamps::new(); + assert!(matches!( + stamps.admit(&destination, &identity, false, 1u8), + Admission::Queued + )); + drop(stamps); + + destination.set_destination_stamp([7; NETWORK_STAMP_SIZE], 24.5); + let mut stamps = DestinationStamps::new(); + assert!(matches!( + stamps.admit(&destination, &identity, false, 2u8), + Admission::Queued + )); + drop(stamps); + + destination.set_destination_stamp([7; NETWORK_STAMP_SIZE], 25.0); + let mut stamps = DestinationStamps::new(); + let Admission::Ready(3u8, Some(ext)) = stamps.admit(&destination, &identity, false, 3u8) + else { + panic!("a held stamp at the target announces at once"); + }; + assert_eq!(ext.stamp, [7; NETWORK_STAMP_SIZE]); + assert_eq!(ext.lr_cost, 12.5); + } +} diff --git a/crates/rns-runtime/src/interface_factory.rs b/crates/rns-runtime/src/interface_factory.rs index b34b8a8..c19ea9f 100644 --- a/crates/rns-runtime/src/interface_factory.rs +++ b/crates/rns-runtime/src/interface_factory.rs @@ -4220,14 +4220,15 @@ mod tests { crate::lifecycle::ShutdownSignal, ) { let shutdown = crate::lifecycle::ShutdownSignal::new(); - let handle = crate::reticulum::init( - Some(dir.path().to_str().unwrap()), - Some(dir.path().join("sockets")), - shutdown.clone(), - std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true)), - ) - .await - .unwrap(); + let handle = + crate::destination_stamper::test_settings::around_init(crate::reticulum::init( + Some(dir.path().to_str().unwrap()), + Some(dir.path().join("sockets")), + shutdown.clone(), + std::sync::Arc::new(std::sync::atomic::AtomicBool::new(true)), + )) + .await + .unwrap(); (handle, shutdown) } diff --git a/crates/rns-runtime/src/link_manager.rs b/crates/rns-runtime/src/link_manager.rs index b783a90..83cbdc1 100644 --- a/crates/rns-runtime/src/link_manager.rs +++ b/crates/rns-runtime/src/link_manager.rs @@ -9799,6 +9799,7 @@ mod tests { #[test] fn path_response_announce_request_sends_attached_path_response() { + let _stamps = crate::destination_stamper::test_settings::blocking_unstamped(); let (tx, mut rx) = mpsc::channel(16); let (_event_tx, event_rx) = mpsc::channel(16); @@ -9864,6 +9865,7 @@ mod tests { #[test] fn path_response_announce_retries_after_transport_ingress_saturation() { + let _stamps = crate::destination_stamper::test_settings::blocking_unstamped(); let (tx, mut rx) = mpsc::channel(1); tx.try_send(TransportMessage::DeregisterDestination { hash: [0x44; 16] }) .unwrap(); @@ -9912,6 +9914,7 @@ mod tests { #[test] fn path_response_announces_carry_default_app_data() { + let _stamps = crate::destination_stamper::test_settings::blocking_unstamped(); let (tx, mut rx) = mpsc::channel(16); let (_event_tx, event_rx) = mpsc::channel(16); @@ -9969,6 +9972,7 @@ mod tests { #[test] fn destination_commands_announce_and_change_link_acceptance() { + let _stamps = crate::destination_stamper::test_settings::blocking_unstamped(); let (transport_tx, mut transport_rx) = mpsc::channel(16); let (_event_tx, event_rx) = mpsc::channel(16); let identity = Identity::new(); @@ -10027,6 +10031,7 @@ mod tests { #[test] fn default_announce_command_uses_owned_destination() { + let _stamps = crate::destination_stamper::test_settings::blocking_unstamped(); let (transport_tx, mut transport_rx) = mpsc::channel(16); let (_event_tx, event_rx) = mpsc::channel(16); let identity = Identity::new(); diff --git a/crates/rns-runtime/src/probe.rs b/crates/rns-runtime/src/probe.rs index 2186c71..dacc7e2 100644 --- a/crates/rns-runtime/src/probe.rs +++ b/crates/rns-runtime/src/probe.rs @@ -714,6 +714,7 @@ mod tests { #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn responder_sends_attached_path_response_announce() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let (tx, mut rx) = mpsc::channel::(16); let identity = Identity::new(); diff --git a/crates/rns-runtime/src/reticulum.rs b/crates/rns-runtime/src/reticulum.rs index 60e0cee..e4cf789 100644 --- a/crates/rns-runtime/src/reticulum.rs +++ b/crates/rns-runtime/src/reticulum.rs @@ -11343,6 +11343,62 @@ mod tests { mod paths_and_filters; mod tunnels; + // These shadow the entry points for every test here: each start writes the + // process destination-stamp settings (destination_stamper::test_settings). + async fn init( + configdir: Option<&str>, + socket_dir: Option, + shutdown: ShutdownSignal, + is_foreground: Arc, + ) -> Result { + crate::destination_stamper::test_settings::around_init(super::init( + configdir, + socket_dir, + shutdown, + is_foreground, + )) + .await + } + + async fn init_with_options( + configdir: Option<&str>, + socket_dir: Option, + shutdown: ShutdownSignal, + is_foreground: Arc, + options: InitOptions, + ) -> Result { + crate::destination_stamper::test_settings::around_init(super::init_with_options( + configdir, + socket_dir, + shutdown, + is_foreground, + options, + )) + .await + } + + #[cfg(feature = "rnode-tcp")] + async fn init_with_options_and_rnode_startup_options( + configdir: Option<&str>, + socket_dir: Option, + shutdown: ShutdownSignal, + is_foreground: Arc, + options: InitOptions, + rnode_startup_options: rns_interface::rnode::RNodeStartupOptions, + ) -> Result { + crate::destination_stamper::test_settings::around_init( + super::init_with_options_and_rnode_startup_options( + configdir, + socket_dir, + shutdown, + is_foreground, + options, + rnode_startup_options, + ), + ) + .await + } + #[test] fn processes_starting_together_end_with_one_transport_identity() { let dir = tempfile::tempdir().unwrap(); @@ -14917,6 +14973,7 @@ loglevel = 7 #[tokio::test(start_paused = true)] async fn discovery_publisher_registers_selected_signer_and_multiple_services() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); use rns_interface::traits::InterfaceMode; let mut runs = Vec::new(); @@ -14994,6 +15051,7 @@ loglevel = 7 /// of announcing at once, so a flapping address cannot flood announces. #[tokio::test(start_paused = true)] async fn discovery_publisher_announces_a_learned_address_on_its_interval() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); use rns_interface::traits::InterfaceMode; let (handle, actor) = discovery_actor(); @@ -15039,6 +15097,7 @@ loglevel = 7 #[tokio::test(start_paused = true)] async fn discovery_publisher_recovers_eligibility_fifo_and_services_attached_path_requests() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); use rns_interface::traits::InterfaceMode; let (mut handle, actor) = discovery_actor(); @@ -15157,6 +15216,7 @@ loglevel = 7 #[tokio::test(start_paused = true)] async fn discovery_publisher_recalls_pending_service_when_it_goes_offline() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); struct CountedStamper(AtomicU64); impl DiscoveryStamper for CountedStamper { @@ -15284,6 +15344,7 @@ loglevel = 7 #[tokio::test(start_paused = true)] async fn discovery_publisher_sends_once_when_admitted_during_generation() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); let (handle, actor) = discovery_actor(); let (tx, mut sink) = @@ -15389,6 +15450,7 @@ loglevel = 7 #[tokio::test(start_paused = true)] async fn discovery_enable_is_single_owner_and_clients_do_not_publish() { + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let _clock = drive_paused_clock(); use rns_interface::traits::InterfaceMode; let (mut handle, actor) = discovery_actor(); diff --git a/crates/rns-runtime/src/reticulum/tests/concurrent_start.rs b/crates/rns-runtime/src/reticulum/tests/concurrent_start.rs index c5857ab..681cac6 100644 --- a/crates/rns-runtime/src/reticulum/tests/concurrent_start.rs +++ b/crates/rns-runtime/src/reticulum/tests/concurrent_start.rs @@ -74,10 +74,18 @@ async fn start_two_unreachable_clients( client("Reachable", "127.0.0.1", port), ), ); + // Time the start alone, not the wait for the stamp settings. + let _starting = crate::destination_stamper::test_settings::starting().await; let started = std::time::Instant::now(); - let handle = start(&dir, options) - .await - .expect("unreachable servers do not fail start-up"); + let handle = super::super::init_with_options( + Some(dir.to_str().unwrap()), + None, + ShutdownSignal::new(), + Arc::new(AtomicBool::new(true)), + options, + ) + .await + .expect("unreachable servers do not fail start-up"); let elapsed = started.elapsed(); assert!( handle.startup_interface_failures().is_empty(), diff --git a/crates/rns-runtime/src/reticulum/tests/tunnels.rs b/crates/rns-runtime/src/reticulum/tests/tunnels.rs index 76c6bee..445b2d7 100644 --- a/crates/rns-runtime/src/reticulum/tests/tunnels.rs +++ b/crates/rns-runtime/src/reticulum/tests/tunnels.rs @@ -1181,6 +1181,7 @@ async fn a_rust_hub_restores_a_reconnecting_rust_clients_paths() { .is_some(), "the client connects" ); + let _stamps = crate::destination_stamper::test_settings::unstamped().await; let destination = client .register_destination( Identity::new(), diff --git a/crates/rns-runtime/src/shared_instance.rs b/crates/rns-runtime/src/shared_instance.rs index b80ad41..43ab78a 100644 --- a/crates/rns-runtime/src/shared_instance.rs +++ b/crates/rns-runtime/src/shared_instance.rs @@ -531,7 +531,7 @@ mod tests { policy: InstancePolicy, options: InitOptions, ) -> Result { - reticulum::init_with_policy( + crate::destination_stamper::test_settings::around_init(reticulum::init_with_policy( self.0.to_str(), None, ShutdownSignal::new(), @@ -539,7 +539,7 @@ mod tests { options, Default::default(), policy, - ) + )) .await } } diff --git a/crates/rns-transport/src/actor/mod.rs b/crates/rns-transport/src/actor/mod.rs index 555c0db..5bf014e 100644 --- a/crates/rns-transport/src/actor/mod.rs +++ b/crates/rns-transport/src/actor/mod.rs @@ -11237,6 +11237,7 @@ mod tests { #[test] fn on_path_request_broadcasts_python_sized_leaf_payload() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (gateway, mut gateway_rx) = make_test_interface("gateway"); actor.interfaces.insert(1, gateway); @@ -11271,6 +11272,7 @@ mod tests { #[test] fn path_request_options_attach_interface_tag_and_recursive_gate() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (first, mut first_rx) = make_test_interface("first"); let (second, mut second_rx) = make_test_interface("second"); actor.interfaces.insert(1, first); @@ -11298,6 +11300,7 @@ mod tests { #[test] fn explicit_path_request_sends_even_when_path_is_known() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (gateway, mut gateway_rx) = make_test_interface("gateway"); actor.interfaces.insert(1, gateway); @@ -11319,6 +11322,7 @@ mod tests { #[test] fn await_path_requests_unknown_path_before_waiting() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (gateway, mut gateway_rx) = make_test_interface("gateway"); actor.interfaces.insert(1, gateway); @@ -11340,6 +11344,7 @@ mod tests { #[test] fn transport_path_request_includes_identity_and_sixteen_byte_tag() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; actor.is_transport_enabled = true; actor.transport_identity_hash = Some([0x44; 16]); let (gateway, mut gateway_rx) = make_test_interface("gateway"); @@ -11657,6 +11662,7 @@ mod tests { #[test] fn pr_ingress_burst_does_not_block_local_client_forwarding() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (mut local_client, _local_rx) = make_test_interface("SharedInstanceServer/client_6"); local_client.role = InterfaceRole::LocalClient; @@ -11771,6 +11777,7 @@ mod tests { #[test] fn outgoing_path_request_frequency_counts_direct_forwarded_and_recursive_sends() { let (mut direct, _tx) = TransportActor::new(); + direct.stamp_policy.stamp_prs = false; let (direct_iface, mut direct_rx) = make_test_interface("direct"); direct.interfaces.insert(1, direct_iface); direct.on_path_request([0x10; 16]); @@ -11788,6 +11795,7 @@ mod tests { ); let (mut forwarded, _tx) = TransportActor::new(); + forwarded.stamp_policy.stamp_prs = false; let (mut local_client, _local_rx) = make_test_interface("SharedInstanceServer/client_7"); local_client.role = InterfaceRole::LocalClient; forwarded.interfaces.insert(1, local_client); @@ -11808,6 +11816,7 @@ mod tests { ); let (mut recursive, _tx) = TransportActor::new(); + recursive.stamp_policy.stamp_prs = false; recursive.is_transport_enabled = true; let (mut requestor, _requestor_rx) = make_test_interface("requestor"); requestor.mode = InterfaceMode::Gateway; @@ -11837,6 +11846,7 @@ mod tests { #[test] fn recursive_path_request_rewrites_requestor_transport_id() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; actor.is_transport_enabled = true; actor.transport_identity_hash = Some([0x44; 16]); @@ -12035,6 +12045,7 @@ mod tests { #[test] fn queued_discovery_prs_emit_at_throttle_cadence() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (iface, mut rx) = make_test_interface("gateway"); actor.interfaces.insert(1, iface); let now = now_f64(); @@ -12064,6 +12075,7 @@ mod tests { #[test] fn queued_discovery_pr_skips_blocked_interface() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (iface_a, mut rx_a) = make_test_interface("a"); actor.interfaces.insert(1, iface_a); let (iface_b, mut rx_b) = make_test_interface("b"); @@ -12720,6 +12732,7 @@ mod tests { #[test] fn local_client_path_request_forwards_without_transport_mode() { let (mut actor, _tx) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; let (mut local_client, _local_rx) = make_test_interface("SharedInstanceServer/client_4"); local_client.role = InterfaceRole::LocalClient; actor.interfaces.insert(1, local_client); diff --git a/crates/rns-transport/src/actor/outbound.rs b/crates/rns-transport/src/actor/outbound.rs index f401eb4..041d1ee 100644 --- a/crates/rns-transport/src/actor/outbound.rs +++ b/crates/rns-transport/src/actor/outbound.rs @@ -1567,6 +1567,7 @@ mod path_request_stamp_tests { #[test] fn without_enforcement_unstamped_requests_are_counted_and_relayed_as_received() { let (mut actor, _a, mut b) = actor_with_two_interfaces(true); + actor.stamp_policy.stamp_prs = false; let data = hex::decode(STAMPED_TAG_1).unwrap()[..PR_LENGTH].to_vec(); actor.handle_inbound_path_request(&data, 1); assert_eq!(received(&actor, 1), 1); @@ -1574,9 +1575,8 @@ mod path_request_stamp_tests { } #[test] - fn a_stamping_transport_relays_unstamped_requests_with_the_lenient_marker() { + fn a_default_transport_relays_unstamped_requests_with_the_lenient_marker() { let (mut actor, _a, mut b) = actor_with_two_interfaces(true); - actor.stamp_policy.stamp_prs = true; let data = hex::decode(STAMPED_TAG_1).unwrap()[..PR_LENGTH].to_vec(); actor.handle_inbound_path_request(&data, 1); let relayed = payload(&b.try_recv().expect("relayed without waiting for a stamp")); @@ -1589,6 +1589,7 @@ mod path_request_stamp_tests { #[test] fn unstamped_emission_carries_the_transport_id_on_a_leaf() { let (mut actor, mut a, _b) = actor_with_two_interfaces(false); + actor.stamp_policy.stamp_prs = false; actor.on_path_request([0x77; 16]); let sent = payload(&a.try_recv().expect("sent")); assert_eq!(sent.len(), PR_LENGTH); @@ -1596,9 +1597,8 @@ mod path_request_stamp_tests { } #[test] - fn stamped_emission_waits_for_the_stamper_then_uses_the_cached_stamp() { + fn default_emission_waits_for_the_stamper_then_uses_the_cached_stamp() { let (mut actor, mut a, _b) = actor_with_two_interfaces(false); - actor.stamp_policy.stamp_prs = true; actor.stamp_policy.pr_value = 4.0; let dest = [0x77; 16]; let tag = [0x55; 16]; diff --git a/crates/rns-transport/src/actor/path_request_admission.rs b/crates/rns-transport/src/actor/path_request_admission.rs index b9a67c0..62de72d 100644 --- a/crates/rns-transport/src/actor/path_request_admission.rs +++ b/crates/rns-transport/src/actor/path_request_admission.rs @@ -24,6 +24,13 @@ pub(super) struct PendingAdmission { mod tests { use super::*; + /// Admission is independent of path-request stamping. + fn unstamped_actor() -> TransportActor { + let (mut actor, _) = TransportActor::new(); + actor.stamp_policy.stamp_prs = false; + actor + } + fn interface( actor: &mut TransportActor, id: InterfaceId, @@ -53,7 +60,7 @@ mod tests { #[test] fn full_driver_preserves_tag_without_spending_path_or_airtime_budget() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); fill(&actor, 1); let dest = [0xD1; 16]; @@ -81,7 +88,7 @@ mod tests { #[test] fn partial_admission_retries_only_failed_interface() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut blocked = interface(&mut actor, 1, 1); let mut ready = interface(&mut actor, 2, 8); fill(&actor, 1); @@ -99,7 +106,7 @@ mod tests { #[test] fn refused_target_does_not_extend_healthy_recovery_discovery_cooldown() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let handle = actor.path_recovery_handle(); let mut blocked = interface(&mut actor, 1, 1); let mut ready = interface(&mut actor, 2, 8); @@ -150,7 +157,7 @@ mod tests { #[test] fn deadline_and_new_signed_route_retire_unadmitted_bytes() { for new_route in [false, true] { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); fill(&actor, 1); let dest = [0xD3; 16]; @@ -174,7 +181,7 @@ mod tests { #[test] fn replacement_or_closed_interface_cannot_inherit_old_queued_request() { for replace in [false, true] { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let radio = interface(&mut actor, 1, 1); fill(&actor, 1); actor.on_path_request([0xD4; 16]); @@ -194,7 +201,7 @@ mod tests { #[test] fn recursive_operation_retirement_cancels_pending_egress() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); fill(&actor, 1); let dest = [0xD5; 16]; @@ -212,7 +219,7 @@ mod tests { #[test] fn admission_inventory_is_bounded_and_clear_shared_retires_it() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let _radio = interface(&mut actor, 1, 1); fill(&actor, 1); for i in 0..MAX_PENDING_ADMISSIONS + 32 { @@ -231,7 +238,7 @@ mod tests { #[test] fn initial_policy_veto_and_missing_target_do_not_create_retry_or_sent_state() { - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); actor.interfaces.get_mut(&1).unwrap().announce_allowed_at = now_f64() + 120.0; actor.send_path_request([0xD7; 16], 1, None, true); @@ -247,7 +254,7 @@ mod tests { fn admission_review_round_robin_reaches_recovered_interface_behind_full_slice() { let start = now_f64(); let _clock = crate::test_clock::Clock::at(start); - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let _blocked = interface(&mut actor, 1, 1); let mut recovering = interface(&mut actor, 2, 1); fill(&actor, 1); @@ -326,7 +333,7 @@ mod tests { for release_at_deadline in [false, true] { let start = now_f64(); let clock = crate::test_clock::Clock::at(start); - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); fill(&actor, 1); let dest = [0xE3; 16]; @@ -395,7 +402,7 @@ mod tests { for change in 0..=5 { let start = now_f64(); let clock = crate::test_clock::Clock::at(start); - let (mut actor, _) = TransportActor::new(); + let mut actor = unstamped_actor(); let mut radio = interface(&mut actor, 1, 1); fill(&actor, 1); let dest = [0xE4; 16]; diff --git a/crates/rns-transport/src/actor/tests/discovery_api.rs b/crates/rns-transport/src/actor/tests/discovery_api.rs index 521eae3..e10f3ff 100644 --- a/crates/rns-transport/src/actor/tests/discovery_api.rs +++ b/crates/rns-transport/src/actor/tests/discovery_api.rs @@ -5,6 +5,7 @@ use crate::path_discovery::DiscoveryError; fn relay() -> (TransportActor, Vec>) { let (mut actor, _) = TransportActor::new(); actor.is_transport_enabled = true; + actor.stamp_policy.stamp_prs = false; let mut receivers = Vec::new(); for id in 1..=3 { let (mut entry, rx) = make_test_interface("discovery API"); diff --git a/crates/rns-transport/src/actor/tests/discovery_public_api.rs b/crates/rns-transport/src/actor/tests/discovery_public_api.rs index 5dd3a89..d808ab7 100644 --- a/crates/rns-transport/src/actor/tests/discovery_public_api.rs +++ b/crates/rns-transport/src/actor/tests/discovery_public_api.rs @@ -5,6 +5,7 @@ use crate::path_discovery::DiscoveryError; fn actor() -> (TransportActor, Vec>) { let (mut actor, _) = TransportActor::new(); actor.is_transport_enabled = true; + actor.stamp_policy.stamp_prs = false; let mut receivers = Vec::new(); for id in 1..=3 { let (tx, rx) = mpsc::channel(64); diff --git a/crates/rns-transport/src/actor/tests/slow_media_discovery.rs b/crates/rns-transport/src/actor/tests/slow_media_discovery.rs index 776dce6..24204c2 100644 --- a/crates/rns-transport/src/actor/tests/slow_media_discovery.rs +++ b/crates/rns-transport/src/actor/tests/slow_media_discovery.rs @@ -5,6 +5,7 @@ use super::*; fn relay() -> TransportActor { let (mut actor, _) = TransportActor::new(); actor.is_transport_enabled = true; + actor.stamp_policy.stamp_prs = false; actor.transport_identity_hash = Some([0x44; 16]); actor } diff --git a/crates/rns-transport/src/stamps.rs b/crates/rns-transport/src/stamps.rs index 5bfe98f..817cca6 100644 --- a/crates/rns-transport/src/stamps.rs +++ b/crates/rns-transport/src/stamps.rs @@ -1,15 +1,15 @@ //! Network stamp policy: the switches and costs Python keeps on `Transport`. //! //! Python reference: `RNS/Transport.py` and the `[stamps]` parser in -//! `RNS/Reticulum.py` (1.6.0). +//! `RNS/Reticulum.py` (1.6.1). pub use rns_identity::stamps::{LINK_COST_CAP, STAMP_COST_CAP}; /// Lower bound for `lr_stamp_timeout` and `pr_stamp_timeout`, in seconds. pub const STAMP_TIMEOUT_FLOOR: f64 = 0.020; -/// Not configurable in Python 1.6.0. +/// Not configurable in Python 1.6.1. pub const STAMPER_PR_QUEUE_LENGTH: usize = 32; -/// Not configurable in Python 1.6.0. +/// Not configurable in Python 1.6.1. pub const STAMPER_AN_QUEUE_LENGTH: usize = 32; /// Effective stamp generation and enforcement policy for one instance. @@ -21,9 +21,9 @@ pub struct StampPolicy { pub stamps_enforced: bool, /// Python `LR_STAMPS_ENFORCED`. pub lr_stamps_enforced: bool, - /// Python `STAMP_DESTINATIONS`. + /// Python `STAMP_DESTINATIONS`, on by default since 1.6.1. pub stamp_destinations: bool, - /// Python `STAMP_PRS`. + /// Python `STAMP_PRS`, on by default since 1.6.1. pub stamp_prs: bool, /// Python `STAMP_LRS`. pub stamp_lrs: bool, @@ -51,8 +51,8 @@ impl Default for StampPolicy { stamps_enabled: true, stamps_enforced: false, lr_stamps_enforced: false, - stamp_destinations: false, - stamp_prs: false, + stamp_destinations: true, + stamp_prs: true, stamp_lrs: true, always_stamp_lrs: false, destination_cost: 23.5, @@ -131,8 +131,8 @@ mod tests { assert!(p.stamps_enabled); assert!(!p.stamps_enforced); assert!(!p.lr_stamps_enforced); - assert!(!p.stamp_destinations); - assert!(!p.stamp_prs); + assert!(p.stamp_destinations); + assert!(p.stamp_prs); assert!(p.stamp_lrs); assert!(!p.always_stamp_lrs); assert_eq!(p.destination_cost, 23.5); @@ -163,14 +163,18 @@ mod tests { #[test] fn switches_set_python_flags() { - let mut p = StampPolicy::default(); + let mut p = StampPolicy { + stamp_destinations: false, + stamp_prs: false, + stamp_lrs: false, + ..StampPolicy::default() + }; p.enable_stamping(); assert!(p.stamp_destinations && p.stamp_prs && p.stamp_lrs); assert!(!p.stamps_enforced && !p.lr_stamps_enforced); let mut p = StampPolicy::default(); p.enforce(); assert!(p.stamps_enforced && p.lr_stamps_enforced); - assert!(!p.stamp_destinations && !p.stamp_prs); } #[test]