Skip to main content

freenet/
lib.rs

1/// Clients events related logic and type definitions.
2pub(crate) mod client_events;
3
4/// Peer node configuration.
5pub mod config;
6
7/// Handling of contracts and delegates functionality.
8mod contract;
9
10// Re-export for integration tests (tests/ directory needs pub access)
11#[cfg(any(test, feature = "testing", feature = "redb"))]
12pub use contract::storages;
13
14/// Generated messages from the flatbuffers schema for the network monitor.
15pub mod generated;
16
17/// Network messages for transactions.
18mod message;
19
20/// Node configuration, implementations and execution (entry points for the binaries).
21mod node;
22pub use node::{run_local_node, run_network_node, EventLoopExitReason, Node, ShutdownHandle};
23
24/// Network operation/transaction state machines.
25mod operations;
26
27/// Ring connections and routing.
28mod ring;
29
30/// Router implementation.
31mod router;
32
33/// Local server used to communicate with the peer core.
34#[cfg(feature = "websocket")]
35pub mod server;
36
37/// Local network topology management.
38mod topology;
39
40/// Tracing and loging infrastructure. Includes our custom event log register. Tracing collectors, etc.
41#[cfg_attr(test, allow(dead_code))]
42pub mod tracing;
43
44/// Code for communicating with other peers over UDP, handles hole-punching, error handling, etc.
45pub mod transport;
46
47pub mod util;
48
49/// WASM code execution runtime, tailored for the contract and delegate APIs.
50mod wasm_runtime;
51
52/// Deterministic simulation testing framework.
53pub mod simulation;
54
55/// Exports to build a running local node.
56pub mod local_node {
57    use super::*;
58    pub use contract::Executor;
59    pub use contract::OperationMode;
60    pub use node::NodeConfig;
61}
62
63/// Exports for the dev tool.
64pub mod dev_tool {
65    use super::*;
66    pub use crate::config::{Config, GlobalTestMetrics};
67    pub use client_events::{
68        test::MemoryEventsGen, test::NetworkEventGenerator, AuthToken, ClientEventsProxy, ClientId,
69        OpenRequest,
70    };
71    pub use contract::{
72        clear_crdt_contracts, is_crdt_contract, register_crdt_contract, storages::Storage,
73        Executor, OperationMode,
74    };
75    pub use flatbuffers;
76    pub use message::Transaction;
77    pub use node::{
78        testing_impl::{
79            check_convergence_from_logs, run_turmoil_simulation, ChurnConfig, ContractDistribution,
80            ControlledEventChain, ControlledSimulationResult, ConvergedContract, ConvergenceResult,
81            DivergedContract, EventChain, EventSummary, NetworkPeer, NodeLabel, OperationStats,
82            OperationSummary, PeerMessage, PeerStatus, PutOperationStats, RunningNode,
83            ScheduledOperation, SimNetwork, SimOperation, TurmoilConfig, TurmoilResult,
84            UpdateOperationStats,
85        },
86        InitPeerNode, NetworkStats, NodeConfig, PeerId,
87    };
88    pub use ring::Location;
89    pub use transport::{TransportKeypair, TransportPublicKey};
90
91    // Re-export state verification for telemetry-based consistency analysis
92    pub use crate::tracing::state_verifier::{StateAnomaly, StateVerifier, VerificationReport};
93
94    // Re-export topology registry for subscription validation in tests
95    pub use ring::topology_registry::{
96        clear_all_topology_snapshots, clear_current_network_name, clear_topology_snapshots,
97        get_all_topology_snapshots, get_current_network_name, get_topology_snapshot,
98        register_topology_snapshot, set_current_network_name, validate_topology,
99        validate_topology_from_snapshots, ContractSubscription, ProximityViolation,
100        TopologySnapshot, TopologyValidationResult,
101    };
102    pub use wasm_runtime::{
103        ContractStore, DelegateStore, MockStateStorage, Runtime, SecretsStore, StateStore,
104    };
105
106    // Re-export simulation types for test infrastructure
107    pub use crate::simulation::{
108        FaultConfig, FaultConfigBuilder, Partition, SimulationRng, TimeSource, VirtualTime,
109        WakeupId,
110    };
111
112    // Re-export fault injector for mid-simulation fault injection in Turmoil tests
113    pub use crate::node::{get_fault_injector, set_fault_injector, FaultInjectorState};
114
115    // Re-export counter reset functions for deterministic simulation testing
116    pub use crate::client_events::RequestId;
117    pub use crate::contract::reset_event_id_counter;
118    pub use crate::node::reset_channel_id_counter;
119    pub use crate::test_utils::reset_global_node_index;
120    pub use crate::transport::reset_nonce_counter;
121    pub use crate::transport::StreamId;
122}
123
124/// Deadlock detection for parking_lot locks in test builds.
125///
126/// Available when compiled with `--cfg test` (unit tests) or with the `testing`
127/// feature flag (integration tests). Uses parking_lot's `deadlock_detection`
128/// feature to catch Mutex/RwLock deadlocks at runtime.
129#[cfg(any(test, feature = "testing"))]
130pub mod deadlock_detection;
131
132pub mod test_utils;