aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib.rs
blob: f956f9821695e00eff5516b1ab427b2fb9fa3b29 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Allow nested if-let until we migrate to let-chains
#![allow(clippy::collapsible_if)]

//! # tesseras-dht
//!
//! NAT-aware Kademlia DHT library for peer-to-peer
//! networks.
//!
//! `tesseras-dht` provides:
//!
//! - **Distributed key-value storage** via Kademlia
//!   (iterative FIND_NODE, FIND_VALUE, STORE)
//! - **NAT traversal** via DTUN (hole-punching) and
//!   proxy relay (symmetric NAT)
//! - **Reliable transport** (RDP) over UDP
//! - **Datagram transport** with automatic fragmentation
//!
//! ## Quick start
//!
//! ```rust,no_run
//! use tesseras_dht::{Node, NatState};
//!
//! let mut node = Node::bind(10000).unwrap();
//! node.set_nat_state(NatState::Global);
//! node.join("bootstrap.example.com", 10000).unwrap();
//!
//! // Store and retrieve values
//! node.put(b"key", b"value", 300, false);
//!
//! // Event loop
//! loop {
//!     node.poll().unwrap();
//!     # break;
//! }
//! ```
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────┐
//! │            Node (facade)              │
//! │  ┌──────┐ ┌────────┐ ┌──────────────┐  │
//! │  │ DHT  │ │Routing │ │   Storage    │  │
//! │  │      │ │ Table  │ │  (DhtStorage)│  │
//! │  └──────┘ └────────┘ └──────────────┘  │
//! │  ┌──────┐ ┌────────┐ ┌──────────────┐  │
//! │  │ DTUN │ │  NAT   │ │    Proxy     │  │
//! │  │      │ │Detector│ │              │  │
//! │  └──────┘ └────────┘ └──────────────┘  │
//! │  ┌──────┐ ┌────────┐ ┌──────────────┐  │
//! │  │ RDP  │ │ Dgram  │ │   Timers     │  │
//! │  └──────┘ └────────┘ └──────────────┘  │
//! │  ┌──────────────────────────────────┐   │
//! │  │     NetLoop (mio / kqueue)      │   │
//! │  └──────────────────────────────────┘   │
//! └─────────────────────────────────────────┘
//! ```
//!
//! ## Security (OpenBSD)
//!
//! Sandboxing with pledge(2) and unveil(2) is an
//! application-level concern. Call them in your binary
//! after binding the socket. The library only needs
//! `"stdio inet dns"` promises.

/// Address advertisement protocol.
pub mod advertise;
/// Ban list for misbehaving peers.
pub mod banlist;
/// Node configuration.
pub mod config;
/// Ed25519 identity and packet signing.
pub mod crypto;
/// Datagram transport with fragmentation/reassembly.
pub mod dgram;
/// Kademlia DHT storage and iterative queries.
pub mod dht;
/// Distributed tunnel for NAT traversal.
pub mod dtun;
/// Error types.
pub mod error;
/// Event types for typed callback integration.
pub mod event;
/// Packet dispatch and message handlers.
mod handlers;
/// 256-bit node identity.
pub mod id;
/// Node metrics and observability.
pub mod metrics;
/// Wire message body parsing and writing.
pub mod msg;
/// NAT type detection (STUN-like echo protocol).
pub mod nat;
/// Network send helpers and query management.
mod net;
/// Main facade: the [`Node`].
pub mod node;
/// Peer node database.
pub mod peers;
/// Persistence traits for data and routing table.
pub mod persist;
/// Proxy relay for symmetric NAT nodes.
pub mod proxy;
/// Per-IP rate limiting.
pub mod ratelimit;
/// Reliable Datagram Protocol (RDP).
pub mod rdp;
/// Kademlia routing table with k-buckets.
pub mod routing;
/// UDP I/O via mio (kqueue on OpenBSD).
pub mod socket;
/// Store acknowledgment tracking.
pub mod store_track;
/// OpenBSD arc4random_buf(3) for secure random bytes.
pub mod sys;
/// Timer wheel for scheduling callbacks.
pub mod timer;
/// On-the-wire binary protocol (header, message types).
pub mod wire;

// Re-export the main types for convenience.
pub use error::Error;
pub use id::NodeId;
pub use nat::NatState;

// Re-export sha2 for downstream crates.
pub use sha2;
pub use node::Node;