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 blob_resolver;
18pub mod cashu;
19pub mod channel;
20pub mod local_bus;
21pub mod mesh_session;
22pub mod mesh_store_core;
23pub mod mock;
24pub mod multicast;
25pub mod nostr;
26pub mod peer_selector;
27pub mod protocol;
28pub mod pubsub_strategy;
29pub mod relay_bridge;
30pub mod root_events;
31pub mod runtime_control;
32pub mod runtime_peer;
33pub mod runtime_state;
34pub mod signaling;
35pub mod transport;
36pub mod types;
37
38pub use blob_resolver::{blob_resolver, BlobResolver, RouteOnlyPeerLinks, RouteOnlySignaling};
39pub use cashu::{
40    cashu_mint_metadata_path, CashuMintMetadataRecord, CashuMintMetadataStore, CashuQuoteState,
41    CashuRoutingConfig, ExpectedSettlement, NegotiatedQuote, CASHU_MINT_METADATA_VERSION,
42};
43pub use channel::{ChannelError, LatencyChannel, MockChannel, PeerChannel};
44pub use local_bus::{LocalNostrBus, SharedLocalNostrBus};
45pub use mesh_session::{
46    forward_mesh_frame_to_sessions, resolve_root_from_local_buses_with_source,
47    resolve_root_from_peer_sessions, MeshSession,
48};
49pub use mesh_store_core::{
50    build_hedged_wave_plan, normalize_dispatch_config, run_hedged_waves, sync_selector_peers,
51    BlobRouteKind, DataPumpStats, HedgedWaveAction, MeshReadSource, MeshRoutingConfig,
52    MeshStoreCore, NamedBlobRoute, PubsubDeliveryMode, PubsubEvent, PubsubPublishStats,
53    RequestDispatchConfig, ResponseBehaviorConfig, SimMeshStore, VerifiedBlockDelivery,
54    VerifiedBlockDeliveryBatch,
55};
56pub use mock::{
57    clear_channel_registry, MockConnectionFactory, MockDataChannel, MockLatencyMode, MockRelay,
58    MockRelayTransport,
59};
60pub use multicast::{MulticastConfig, MulticastNostrBus};
61pub use nostr::{decode_signaling_event, encode_signaling_event, NostrRelayTransport};
62pub use peer_selector::{
63    peer_principal, PeerMetadataSnapshot, PeerSelector, PeerStats, PersistedPeerMetadata,
64    SelectionStrategy, SelectorSummary, PEER_METADATA_SNAPSHOT_VERSION,
65};
66pub use protocol::{
67    bytes_to_hash, create_fragment_response, create_pubsub_frame, create_pubsub_interest,
68    create_pubsub_inventory, create_pubsub_want, create_quote_request,
69    create_quote_response_available, create_quote_response_unavailable, create_request,
70    create_request_with_quote, create_response, encode_chunk, encode_payment, encode_payment_ack,
71    encode_peer_hints, encode_pubsub_frame, encode_pubsub_interest, encode_pubsub_inventory,
72    encode_pubsub_want, encode_quote_request, encode_quote_response, encode_request,
73    encode_response, hash_to_bytes, hash_to_key, is_fragmented, parse_message, DataChunk,
74    DataMessage, DataPayment, DataPaymentAck, DataQuoteRequest, DataQuoteResponse, DataRequest,
75    DataResponse, PeerHints, PubsubFrame, PubsubInterest, PubsubInventory, PubsubWant,
76    FRAGMENT_SIZE, MSG_TYPE_CHUNK, MSG_TYPE_PAYMENT, MSG_TYPE_PAYMENT_ACK, MSG_TYPE_PEER_HINTS,
77    MSG_TYPE_PUBSUB_FRAME, MSG_TYPE_PUBSUB_INTEREST, MSG_TYPE_PUBSUB_INVENTORY,
78    MSG_TYPE_PUBSUB_WANT, MSG_TYPE_QUOTE_REQUEST, MSG_TYPE_QUOTE_RESPONSE, MSG_TYPE_REQUEST,
79    MSG_TYPE_RESPONSE,
80};
81pub use pubsub_strategy::{
82    reciprocal_upload_weight, reciprocal_virtual_finish, select_reciprocal_outbound_job,
83    stable_pubsub_score, OutboundJobCandidate, OutboundJobSelection, PeerTrafficSnapshot,
84    PubsubCandidate, PubsubSchedulerConfig, PubsubSchedulingPolicy, PubsubSelection,
85};
86pub use relay_bridge::{
87    MeshEventStore, MeshRelayClient, SharedMeshEventStore, SharedMeshRelayClient,
88};
89pub use root_events::{
90    build_root_filter, hashtree_event_identifier, hashtree_root_kinds, is_hashtree_labeled_event,
91    is_hashtree_root_kind, pick_latest_event, root_event_from_peer, PeerRootEvent, HASHTREE_KIND,
92    HASHTREE_LABEL, HASHTREE_LEGACY_KIND,
93};
94pub use runtime_control::{
95    can_track_source_peer, cleanup_stale_peers, create_signaling_event, dispatch_signaling_message,
96    forward_mesh_frame_from_runtime, handle_peer_state_event, handle_signaling_event,
97    handle_signaling_message, PeerStateEvent,
98};
99pub use runtime_peer::{
100    can_track_signal_path_peer, remember_peer_signal_path, ConnectionState, MeshPeerEntry,
101    PeerDirection, PeerSignalPath, PeerTransport, TransportPeerRegistrar,
102};
103pub use runtime_state::MeshRuntimeState;
104pub use signaling::{MeshRouter, PeerEntry};
105pub use transport::{PeerLink, PeerLinkFactory, SignalingTransport, TransportError};
106pub use types::{
107    classifier_channel, decrement_htl_with_policy, is_polite_peer, should_forward,
108    should_forward_htl, validate_mesh_frame, ClassifierRx, ClassifierTx, ClassifyRequest, HtlMode,
109    HtlPolicy, IceCandidate, KnownPeerRecord, KnownPeerSnapshot, MeshNostrFrame, MeshNostrPayload,
110    MeshStats, MeshStoreConfig, PeerHTLConfig, PeerId, PeerPool, PeerState, PoolConfig,
111    PoolSettings, SignalingMessage, TimedSeenSet, BLOB_REQUEST_POLICY, DECREMENT_AT_MAX_PROB,
112    DECREMENT_AT_MIN_PROB, MAX_HTL, MESH_DEFAULT_HTL, MESH_EVENT_POLICY, MESH_MAX_HTL,
113    MESH_PROTOCOL, MESH_PROTOCOL_VERSION, MESH_SIGNALING_EVENT_KIND, NOSTR_KIND_HASHTREE,
114};