Skip to main content

hashtree_network/
lib.rs

1//! Mesh transport primitives for HashTree.
2//!
3//! This crate provides the reusable router, signaling, peer-link, and store
4//! layers for hashtree mesh networking. Production transports live outside this
5//! crate; the core abstractions here are intentionally transport-neutral so the
6//! same logic can be driven by FIPS, local mocks, Nostr relay fixtures, or other
7//! byte-link implementations.
8//!
9//! # Overview
10//!
11//! - **Storage Backend**: Any [`hashtree_core::Store`] implementation
12//! - **Peer Discovery**: Any [`SignalingTransport`] implementation
13//! - **Data Exchange**: Any [`PeerLink`] / [`PeerLinkFactory`] implementation
14//! - **Protocol**: Request/response with hash-based addressing
15//! - **Adaptive Selection**: Intelligent peer selection based on performance
16//!
17pub mod cashu;
18pub mod channel;
19pub mod local_bus;
20pub mod mesh_session;
21pub mod mesh_store_core;
22pub mod mock;
23pub mod multicast;
24pub mod nostr;
25pub mod peer_selector;
26pub mod protocol;
27pub mod pubsub_strategy;
28pub mod relay_bridge;
29pub mod root_events;
30pub mod runtime_control;
31pub mod runtime_peer;
32pub mod runtime_state;
33pub mod signaling;
34pub mod transport;
35pub mod types;
36
37pub use cashu::{
38    cashu_mint_metadata_path, CashuMintMetadataRecord, CashuMintMetadataStore, CashuQuoteState,
39    CashuRoutingConfig, ExpectedSettlement, NegotiatedQuote, CASHU_MINT_METADATA_VERSION,
40};
41pub use channel::{ChannelError, LatencyChannel, MockChannel, PeerChannel};
42pub use local_bus::{LocalNostrBus, SharedLocalNostrBus};
43pub use mesh_session::{
44    forward_mesh_frame_to_sessions, resolve_root_from_local_buses_with_source,
45    resolve_root_from_peer_sessions, MeshSession,
46};
47pub use mesh_store_core::{
48    build_hedged_wave_plan, normalize_dispatch_config, run_hedged_waves, sync_selector_peers,
49    DataPumpStats, HedgedWaveAction, MeshReadSource, MeshRoutingConfig, MeshStoreCore,
50    PubsubDeliveryMode, PubsubEvent, PubsubPublishStats, RequestDispatchConfig,
51    ResponseBehaviorConfig, SimMeshStore,
52};
53pub use mock::{
54    clear_channel_registry, MockConnectionFactory, MockDataChannel, MockLatencyMode, MockRelay,
55    MockRelayTransport,
56};
57pub use multicast::{MulticastConfig, MulticastNostrBus};
58pub use nostr::{decode_signaling_event, encode_signaling_event, NostrRelayTransport};
59pub use peer_selector::{
60    peer_principal, PeerMetadataSnapshot, PeerSelector, PeerStats, PersistedPeerMetadata,
61    SelectionStrategy, SelectorSummary, PEER_METADATA_SNAPSHOT_VERSION,
62};
63pub use protocol::{
64    bytes_to_hash, create_fragment_response, create_pubsub_frame, create_pubsub_interest,
65    create_pubsub_inventory, create_pubsub_want, create_quote_request,
66    create_quote_response_available, create_quote_response_unavailable, create_request,
67    create_request_with_quote, create_response, encode_chunk, encode_payment, encode_payment_ack,
68    encode_peer_hints, encode_pubsub_frame, encode_pubsub_interest, encode_pubsub_inventory,
69    encode_pubsub_want, encode_quote_request, encode_quote_response, encode_request,
70    encode_response, hash_to_bytes, hash_to_key, is_fragmented, parse_message, DataChunk,
71    DataMessage, DataPayment, DataPaymentAck, DataQuoteRequest, DataQuoteResponse, DataRequest,
72    DataResponse, PeerHints, PubsubFrame, PubsubInterest, PubsubInventory, PubsubWant,
73    FRAGMENT_SIZE, MSG_TYPE_CHUNK, MSG_TYPE_PAYMENT, MSG_TYPE_PAYMENT_ACK, MSG_TYPE_PEER_HINTS,
74    MSG_TYPE_PUBSUB_FRAME, MSG_TYPE_PUBSUB_INTEREST, MSG_TYPE_PUBSUB_INVENTORY,
75    MSG_TYPE_PUBSUB_WANT, MSG_TYPE_QUOTE_REQUEST, MSG_TYPE_QUOTE_RESPONSE, MSG_TYPE_REQUEST,
76    MSG_TYPE_RESPONSE,
77};
78pub use pubsub_strategy::{
79    reciprocal_upload_weight, reciprocal_virtual_finish, select_reciprocal_outbound_job,
80    stable_pubsub_score, OutboundJobCandidate, OutboundJobSelection, PeerTrafficSnapshot,
81    PubsubCandidate, PubsubSchedulerConfig, PubsubSchedulingPolicy, PubsubSelection,
82};
83pub use relay_bridge::{
84    MeshEventStore, MeshRelayClient, SharedMeshEventStore, SharedMeshRelayClient,
85};
86pub use root_events::{
87    build_root_filter, hashtree_event_identifier, is_hashtree_labeled_event, pick_latest_event,
88    root_event_from_peer, PeerRootEvent, HASHTREE_KIND, HASHTREE_LABEL,
89};
90pub use runtime_control::{
91    can_track_source_peer, cleanup_stale_peers, create_signaling_event, dispatch_signaling_message,
92    forward_mesh_frame_from_runtime, handle_peer_state_event, handle_signaling_event,
93    handle_signaling_message, PeerStateEvent,
94};
95pub use runtime_peer::{
96    can_track_signal_path_peer, remember_peer_signal_path, ConnectionState, MeshPeerEntry,
97    PeerDirection, PeerSignalPath, PeerTransport, TransportPeerRegistrar,
98};
99pub use runtime_state::MeshRuntimeState;
100pub use signaling::{MeshRouter, PeerEntry};
101pub use transport::{PeerLink, PeerLinkFactory, SignalingTransport, TransportError};
102pub use types::{
103    classifier_channel, decrement_htl_with_policy, is_polite_peer, should_forward,
104    should_forward_htl, validate_mesh_frame, ClassifierRx, ClassifierTx, ClassifyRequest, HtlMode,
105    HtlPolicy, IceCandidate, KnownPeerRecord, KnownPeerSnapshot, MeshNostrFrame, MeshNostrPayload,
106    MeshStats, MeshStoreConfig, PeerHTLConfig, PeerId, PeerPool, PeerState, PoolConfig,
107    PoolSettings, SignalingMessage, TimedSeenSet, BLOB_REQUEST_POLICY, DECREMENT_AT_MAX_PROB,
108    DECREMENT_AT_MIN_PROB, MAX_HTL, MESH_DEFAULT_HTL, MESH_EVENT_POLICY, MESH_MAX_HTL,
109    MESH_PROTOCOL, MESH_PROTOCOL_VERSION, MESH_SIGNALING_EVENT_KIND, NOSTR_KIND_HASHTREE,
110};