diff --git a/Cargo.lock b/Cargo.lock index d36e502eca..43b6e84c5b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7519,7 +7519,10 @@ dependencies = [ "nym-common", "nym-crypto", "nym-lp-data", + "nym-node", "nym-sphinx", + "nym-sphinx-addressing", + "nym-sphinx-params", "rand 0.8.6", "rand_distr", "serde", diff --git a/Cargo.toml b/Cargo.toml index 089008a9f4..3cd65fcf36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -197,7 +197,6 @@ default-members = [ "service-providers/network-requester", "tools/internal/localnet-orchestrator", "tools/nymvisor", - "tools/internal/localnet-orchestrator", ] exclude = ["contracts", "nym-wallet", "cpu-cycles"] diff --git a/nym-node/Cargo.toml b/nym-node/Cargo.toml index a53c8dcc92..dc86f34a4c 100644 --- a/nym-node/Cargo.toml +++ b/nym-node/Cargo.toml @@ -148,6 +148,8 @@ nym-test-utils = { workspace = true } [features] tokio-console = ["console-subscriber", "nym-task/tokio-tracing"] otel = ["nym-bin-common/otel-otlp", "dep:opentelemetry", "dep:opentelemetry_sdk"] +mix-sim = [] +defaul = ["mix-sim"] [lints] workspace = true diff --git a/nym-node/src/node/lp/data/handler/mod.rs b/nym-node/src/node/lp/data/handler/mod.rs index 707d107fb3..1356da5504 100644 --- a/nym-node/src/node/lp/data/handler/mod.rs +++ b/nym-node/src/node/lp/data/handler/mod.rs @@ -33,8 +33,8 @@ use tokio::time::interval; use tracing::*; pub mod error; -pub(crate) mod messages; -mod pipeline; +pub mod messages; +pub mod pipeline; mod processing; const PIPELINE_TICKING_DURATION: Duration = Duration::from_millis(1); diff --git a/nym-node/src/node/lp/data/handler/pipeline/mod.rs b/nym-node/src/node/lp/data/handler/pipeline/mod.rs index e5ddd84706..99e3739f24 100644 --- a/nym-node/src/node/lp/data/handler/pipeline/mod.rs +++ b/nym-node/src/node/lp/data/handler/pipeline/mod.rs @@ -12,4 +12,4 @@ mod nymnode; mod wire; pub(crate) use mixing_node::MixingNodeDataPipeline; -pub(crate) use nymnode::NymNodeDataPipeline; +pub use nymnode::NymNodeDataPipeline; diff --git a/nym-node/src/node/lp/data/handler/pipeline/nymnode.rs b/nym-node/src/node/lp/data/handler/pipeline/nymnode.rs index 2547cd4eb4..e58d7408e4 100644 --- a/nym-node/src/node/lp/data/handler/pipeline/nymnode.rs +++ b/nym-node/src/node/lp/data/handler/pipeline/nymnode.rs @@ -29,14 +29,14 @@ use crate::node::{ routing_filter::RoutingFilter, }; -pub(crate) struct NymNodeDataPipeline { +pub struct NymNodeDataPipeline { state: Arc, gateway_state: Arc, wire: WirePipeline, } impl NymNodeDataPipeline { - pub(crate) fn new( + pub fn new( state: Arc, gateway_state: Arc, rng: R, diff --git a/nym-node/src/node/lp/data/mod.rs b/nym-node/src/node/lp/data/mod.rs index f6f79d512b..5270ed0d34 100644 --- a/nym-node/src/node/lp/data/mod.rs +++ b/nym-node/src/node/lp/data/mod.rs @@ -19,7 +19,7 @@ pub(crate) const PACKET_BUFFER_SIZE: usize = 100; pub mod handler; mod listener; -pub(crate) mod shared; +pub mod shared; pub struct LpDataSetup { listener: LpDataListener, @@ -49,13 +49,8 @@ impl LpDataSetup { shutdown.clone_shutdown_token(), ); - let handler = LpDataHandler::new( - shared_state, - gateway_state, - input_rx, - output_tx, - &shutdown, - )?; + let handler = + LpDataHandler::new(shared_state, gateway_state, input_rx, output_tx, &shutdown)?; Ok(LpDataSetup { listener, diff --git a/nym-node/src/node/lp/data/shared.rs b/nym-node/src/node/lp/data/shared.rs index 45599e8ea0..7418810444 100644 --- a/nym-node/src/node/lp/data/shared.rs +++ b/nym-node/src/node/lp/data/shared.rs @@ -24,7 +24,7 @@ use std::{ use tracing::{Span, warn}; #[derive(Clone, Copy)] -pub(crate) struct ProcessingConfig { +pub struct ProcessingConfig { pub(crate) maximum_packet_delay: Duration, pub(crate) client_forwarding_enabled: bool, } @@ -39,24 +39,24 @@ impl ProcessingConfig { } /// Shared state for LP data connections -pub(crate) struct SharedLpDataState { +pub struct SharedLpDataState { /// LP configuration (for timestamp validation, etc.) - pub lp_config: LpConfig, + pub(crate) lp_config: LpConfig, - pub processing_config: ProcessingConfig, + pub(crate) processing_config: ProcessingConfig, - pub sphinx_keys: ActiveSphinxKeys, + pub(crate) sphinx_keys: ActiveSphinxKeys, - pub replay_protection_filter: ReplayProtectionBloomfilters, + pub(crate) replay_protection_filter: ReplayProtectionBloomfilters, - pub message_reconstructor: MessageReconstructor, + pub(crate) message_reconstructor: MessageReconstructor, - pub routing_filter: NetworkRoutingFilter, + pub(crate) routing_filter: NetworkRoutingFilter, /// Metrics collection - pub metrics: NymNodeMetrics, + pub(crate) metrics: NymNodeMetrics, - pub shutdown_token: ShutdownToken, + pub(crate) shutdown_token: ShutdownToken, } impl SharedLpDataState { @@ -192,12 +192,12 @@ impl SharedLpDataState { /// /// Only constructed and consumed when the node operates in a client-forwarding /// role (entry/exit). -pub(crate) struct SharedGatewayLpDataState { +pub struct SharedGatewayLpDataState { pub(crate) cached_topology: CachedFullTopology, } impl SharedGatewayLpDataState { - pub fn new(cached_topology: CachedFullTopology) -> Self { + pub(crate) fn new(cached_topology: CachedFullTopology) -> Self { Self { cached_topology } } @@ -206,3 +206,47 @@ impl SharedGatewayLpDataState { false } } + +#[cfg(feature = "mix-sim")] +impl SharedLpDataState { + /// Build a [`SharedLpDataState`] for use in a discrete simulator. + /// + /// Initialises the state with: + /// - the provided x25519 private key as the only sphinx key (rotation 0), + /// - replay protection disabled, + /// - the testnet routing filter (allows all destinations), + /// - client forwarding enabled, + /// - fresh metrics and a never-firing shutdown token. + pub fn new_for_simulation( + sphinx_private_key: nym_crypto::asymmetric::x25519::PrivateKey, + ) -> Self { + use crate::node::key_rotation::active_keys::ActiveSphinxKeys; + use crate::node::key_rotation::key::SphinxPrivateKey; + use crate::node::replay_protection::bloomfilter::ReplayProtectionBloomfilters; + use crate::node::routing_filter::network_filter::NetworkRoutingFilter; + + let primary = SphinxPrivateKey::import(sphinx_private_key, 0); + SharedLpDataState { + lp_config: LpConfig::default(), + processing_config: ProcessingConfig { + maximum_packet_delay: Duration::from_secs(10), + client_forwarding_enabled: true, + }, + sphinx_keys: ActiveSphinxKeys::new_loaded(primary, None), + replay_protection_filter: ReplayProtectionBloomfilters::new_disabled(), + message_reconstructor: MessageReconstructor::default(), + routing_filter: NetworkRoutingFilter::new_empty(true), + metrics: NymNodeMetrics::default(), + shutdown_token: ShutdownToken::new(), + } + } +} + +#[cfg(feature = "mix-sim")] +impl SharedGatewayLpDataState { + pub fn new_for_simulation() -> Self { + Self { + cached_topology: CachedFullTopology::new_empty(), + } + } +}