Skip to main content

Crate hashtree_network

Crate hashtree_network 

Source
Expand description

Mesh transport primitives for HashTree.

This crate provides the reusable router, signaling, peer-link, and store layers for hashtree mesh networking. The default production composition uses Nostr websockets for signaling and WebRTC for direct links, but the same abstractions support LAN buses, Bluetooth transports, and simulation.

§Overview

§Example

use hashtree_core::MemoryStore;
use hashtree_network::{MeshStore, MeshStoreConfig};
use nostr_sdk::prelude::*;
use std::sync::Arc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let local_store = Arc::new(MemoryStore::new());
    let config = MeshStoreConfig::default();

    let mut store = MeshStore::new(local_store, config);

    // Generate or load Nostr keys
    let keys = Keys::generate();

    // Start P2P network
    store.start(keys).await?;

    // Now store.get() will try local first, then fetch from peers

    Ok(())
}

Re-exports§

pub use bluetooth::install_mobile_bluetooth_bridge;
pub use bluetooth::BluetoothBackendState;
pub use bluetooth::BluetoothConfig;
pub use bluetooth::BluetoothMesh;
pub use bluetooth::BluetoothPeerRegistrar;
pub use bluetooth::BluetoothRuntimeContext;
pub use bluetooth::MobileBluetoothBridge;
pub use bluetooth_peer::BluetoothFrame;
pub use bluetooth_peer::BluetoothPeer;
pub use cashu::cashu_mint_metadata_path;
pub use cashu::CashuMintMetadataRecord;
pub use cashu::CashuMintMetadataStore;
pub use cashu::CashuQuoteState;
pub use cashu::CashuRoutingConfig;
pub use cashu::ExpectedSettlement;
pub use cashu::NegotiatedQuote;
pub use cashu::CASHU_MINT_METADATA_VERSION;
pub use channel::ChannelError;
pub use channel::LatencyChannel;
pub use channel::MockChannel;
pub use channel::PeerChannel;
pub use local_bus::LocalNostrBus;
pub use local_bus::SharedLocalNostrBus;
pub use manager::PeerClassifier;
pub use manager::PeerEntry as RuntimePeerEntry;
pub use manager::PeerStatus;
pub use manager::WebRTCConfig;
pub use manager::WebRTCManager;
pub use manager::WebRTCState;
pub use mesh_session::forward_mesh_frame_to_sessions;
pub use mesh_session::resolve_root_from_local_buses_with_source;
pub use mesh_session::resolve_root_from_peer_sessions;
pub use mesh_session::MeshSession;
pub use mesh_store_core::build_hedged_wave_plan;
pub use mesh_store_core::normalize_dispatch_config;
pub use mesh_store_core::run_hedged_waves;
pub use mesh_store_core::sync_selector_peers;
pub use mesh_store_core::DataPumpStats;
pub use mesh_store_core::HedgedWaveAction;
pub use mesh_store_core::MeshRoutingConfig;
pub use mesh_store_core::MeshStoreCore;
pub use mesh_store_core::ProductionMeshStore;
pub use mesh_store_core::RequestDispatchConfig;
pub use mesh_store_core::ResponseBehaviorConfig;
pub use mesh_store_core::SimMeshStore;
pub use mock::clear_channel_registry;
pub use mock::MockConnectionFactory;
pub use mock::MockDataChannel;
pub use mock::MockLatencyMode;
pub use mock::MockRelay;
pub use mock::MockRelayTransport;
pub use multicast::MulticastConfig;
pub use multicast::MulticastNostrBus;
pub use nostr::decode_signaling_event;
pub use nostr::encode_signaling_event;
pub use nostr::NostrRelayTransport;
pub use peer::ContentStore;
pub use peer::Peer;
pub use peer::PendingRequest;
pub use peer_selector::peer_principal;
pub use peer_selector::PeerMetadataSnapshot;
pub use peer_selector::PeerSelector;
pub use peer_selector::PeerStats;
pub use peer_selector::PersistedPeerMetadata;
pub use peer_selector::SelectionStrategy;
pub use peer_selector::SelectorSummary;
pub use peer_selector::PEER_METADATA_SNAPSHOT_VERSION;
pub use protocol::bytes_to_hash;
pub use protocol::create_fragment_response;
pub use protocol::create_quote_request;
pub use protocol::create_quote_response_available;
pub use protocol::create_quote_response_unavailable;
pub use protocol::create_request;
pub use protocol::create_request_with_quote;
pub use protocol::create_response;
pub use protocol::encode_chunk;
pub use protocol::encode_payment;
pub use protocol::encode_payment_ack;
pub use protocol::encode_quote_request;
pub use protocol::encode_quote_response;
pub use protocol::encode_request;
pub use protocol::encode_response;
pub use protocol::hash_to_bytes;
pub use protocol::hash_to_key;
pub use protocol::is_fragmented;
pub use protocol::parse_message;
pub use protocol::DataChunk;
pub use protocol::DataMessage;
pub use protocol::DataPayment;
pub use protocol::DataPaymentAck;
pub use protocol::DataQuoteRequest;
pub use protocol::DataQuoteResponse;
pub use protocol::DataRequest;
pub use protocol::DataResponse;
pub use protocol::FRAGMENT_SIZE;
pub use protocol::MSG_TYPE_CHUNK;
pub use protocol::MSG_TYPE_PAYMENT;
pub use protocol::MSG_TYPE_PAYMENT_ACK;
pub use protocol::MSG_TYPE_QUOTE_REQUEST;
pub use protocol::MSG_TYPE_QUOTE_RESPONSE;
pub use protocol::MSG_TYPE_REQUEST;
pub use protocol::MSG_TYPE_RESPONSE;
pub use real_factory::WebRtcPeerLinkFactory;
pub use relay_bridge::MeshEventStore;
pub use relay_bridge::MeshRelayClient;
pub use relay_bridge::SharedMeshEventStore;
pub use relay_bridge::SharedMeshRelayClient;
pub use root_events::build_root_filter;
pub use root_events::hashtree_event_identifier;
pub use root_events::is_hashtree_labeled_event;
pub use root_events::pick_latest_event;
pub use root_events::root_event_from_peer;
pub use root_events::PeerRootEvent;
pub use root_events::HASHTREE_KIND;
pub use root_events::HASHTREE_LABEL;
pub use runtime_control::can_track_source_peer;
pub use runtime_control::cleanup_stale_peers;
pub use runtime_control::create_signaling_event;
pub use runtime_control::dispatch_signaling_message;
pub use runtime_control::forward_mesh_frame_from_runtime;
pub use runtime_control::handle_peer_state_event;
pub use runtime_control::handle_signaling_event;
pub use runtime_control::handle_signaling_message;
pub use runtime_control::PeerStateEvent;
pub use runtime_peer::can_track_signal_path_peer;
pub use runtime_peer::remember_peer_signal_path;
pub use runtime_peer::ConnectionState;
pub use runtime_peer::MeshPeerEntry;
pub use runtime_peer::PeerDirection;
pub use runtime_peer::PeerSignalPath;
pub use runtime_peer::PeerTransport;
pub use runtime_peer::TransportPeerRegistrar;
pub use runtime_state::MeshRuntimeState;
pub use session::MeshPeer;
pub use signaling::MeshRouter;
pub use signaling::PeerEntry;
pub use store::MeshStore;
pub use store::MeshStoreError;
pub use transport::PeerLinkFactory;
pub use transport::SignalingTransport;
pub use transport::TransportError;
pub use types::classifier_channel;
pub use types::decrement_htl_with_policy;
pub use types::is_polite_peer;
pub use types::should_forward;
pub use types::should_forward_htl;
pub use types::validate_mesh_frame;
pub use types::ClassifierRx;
pub use types::ClassifierTx;
pub use types::ClassifyRequest;
pub use types::HtlMode;
pub use types::HtlPolicy;
pub use types::IceCandidate;
pub use types::MeshNostrFrame;
pub use types::MeshNostrPayload;
pub use types::MeshStats;
pub use types::MeshStoreConfig;
pub use types::PeerHTLConfig;
pub use types::PeerId;
pub use types::PeerPool;
pub use types::PeerState;
pub use types::PoolConfig;
pub use types::PoolSettings;
pub use types::SignalingMessage;
pub use types::TimedSeenSet;
pub use types::WebRTCStats;
pub use types::BLOB_REQUEST_POLICY;
pub use types::DATA_CHANNEL_LABEL;
pub use types::DECREMENT_AT_MAX_PROB;
pub use types::DECREMENT_AT_MIN_PROB;
pub use types::MAX_HTL;
pub use types::MESH_DEFAULT_HTL;
pub use types::MESH_EVENT_POLICY;
pub use types::MESH_MAX_HTL;
pub use types::MESH_PROTOCOL;
pub use types::MESH_PROTOCOL_VERSION;
pub use types::MESH_SIGNALING_EVENT_KIND;
pub use types::NOSTR_KIND_HASHTREE;
pub use wifi_aware::install_mobile_wifi_aware_bridge;
pub use wifi_aware::mobile_wifi_aware_bridge;
pub use wifi_aware::MobileWifiAwareBridge;
pub use wifi_aware::WifiAwareConfig;
pub use wifi_aware::WifiAwareEvent;
pub use wifi_aware::WifiAwareNostrBus;
pub use wifi_aware::WIFI_AWARE_SOURCE;

Modules§

bluetooth
bluetooth_peer
cashu
channel
Peer communication channel abstraction
local_bus
manager
WebRTC signaling over Nostr relays
mesh_session
mesh_store_core
Shared routed mesh store core.
mock
Mock implementations for testing and simulation
multicast
nostr
Nostr websocket signaling transport implementation
peer
WebRTC peer connection for hashtree data exchange
peer_selector
Adaptive peer selection based on Freenet patterns
protocol
Wire protocol for hashtree WebRTC data exchange
real_factory
Real WebRTC peer-link factory
relay_bridge
root_events
runtime_control
runtime_peer
runtime_state
session
signaling
Shared signaling logic for peer discovery and connection management.
store
Default production mesh store wrapper.
transport
Signaling and peer-link transport abstractions
types
Mesh transport types for peer-to-peer data exchange.
wifi_aware