Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/target/
tests/node/node_modules/
.sisyphus
.vogon_poetry/
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libudx/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libudx"
version = "1.0.1"
version = "1.1.0"
edition.workspace = true
license.workspace = true
rust-version.workspace = true
Expand Down
1 change: 1 addition & 0 deletions libudx/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Errors returned by libudx operations.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum UdxError {
/// A libuv/udx numeric error code. Retained for API compatibility with
/// the former FFI backend; the native implementation returns [`Io`](Self::Io)
Expand Down
1 change: 1 addition & 0 deletions libudx/src/native/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub const FLAG_DESTROY: u8 = 0x10;
pub const FLAG_HEARTBEAT: u8 = 0x20;

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum HeaderError {
#[error("packet too short: {0} bytes (minimum {HEADER_SIZE})")]
TooShort(usize),
Expand Down
4 changes: 2 additions & 2 deletions peeroxide-dht/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "peeroxide-dht"
version = "1.0.1"
version = "1.1.0"
edition.workspace = true
license.workspace = true
rust-version.workspace = true
Expand All @@ -15,7 +15,7 @@ all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
libudx = { path = "../libudx", version = "1.0.1" }
libudx = { path = "../libudx", version = "1.1.0" }
tokio = { workspace = true }
tracing = { workspace = true }
thiserror = { workspace = true }
Expand Down
23 changes: 11 additions & 12 deletions peeroxide-dht/examples/relay_soak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,16 @@ async fn main() {
)
.init();

let config = HyperDhtConfig {
dht: DhtConfig {
bootstrap: DEFAULT_BOOTSTRAP
.iter()
.map(|s| (*s).to_string())
.collect(),
ephemeral: Some(false),
firewalled: false,
..DhtConfig::default()
},
..HyperDhtConfig::default()
};
let mut dht_config = DhtConfig::default();
dht_config.bootstrap = DEFAULT_BOOTSTRAP
.iter()
.map(|s| (*s).to_string())
.collect();
dht_config.ephemeral = Some(false);
dht_config.firewalled = false;

let mut config = HyperDhtConfig::default();
config.dht = dht_config;

let runtime = UdxRuntime::new().expect("failed to create UDX runtime");
let (join_handle, handle, mut server_rx) =
Expand Down Expand Up @@ -85,6 +83,7 @@ async fn main() {
);
let _ = reply_tx.send(None);
}
_ => {}
}
}
});
Expand Down
1 change: 1 addition & 0 deletions peeroxide-dht/src/blind_relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn decode_unpair_from_slice(data: &[u8]) -> c::Result<UnpairMessage> {

/// Errors that can occur while using the blind relay client.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum RelayError {
/// A Protomux operation failed while opening, sending, or receiving.
#[error("protomux error: {0}")]
Expand Down
1 change: 1 addition & 0 deletions peeroxide-dht/src/compact_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use thiserror::Error;

/// Errors returned by compact encoding operations
#[derive(Error, Debug)]
#[non_exhaustive]
pub enum EncodingError {
#[error("out of bounds: need {need} bytes, have {have}")]
/// The buffer did not contain enough bytes
Expand Down
1 change: 1 addition & 0 deletions peeroxide-dht/src/holepuncher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::socket_pool::{coerce_firewall, random_port, SocketPool, SocketRef};

const BIRTHDAY_SOCKETS: usize = 256;

#[non_exhaustive]
pub enum HolepunchEvent {
Connected {
addr: SocketAddr,
Expand Down
18 changes: 18 additions & 0 deletions peeroxide-dht/src/hyperdht.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ fn is_addr_private(host: &str) -> bool {

#[derive(Debug, Error)]
/// Errors returned by HyperDHT operations.
#[non_exhaustive]
pub enum HyperDhtError {
/// Error propagated from the underlying DHT client.
#[error("DHT error: {0}")]
Expand Down Expand Up @@ -135,6 +136,7 @@ pub enum HyperDhtError {

#[derive(Debug)]
/// Events forwarded to server-side listeners.
#[non_exhaustive]
pub enum ServerEvent {
/// A peer handshake request that may need local server handling.
PeerHandshake {
Expand Down Expand Up @@ -215,6 +217,7 @@ impl KeyPair {

#[derive(Debug, Clone)]
/// Result from a LOOKUP query.
#[non_exhaustive]
pub struct LookupResult {
/// Node that returned the lookup result.
pub from: Ipv4Peer,
Expand All @@ -226,13 +229,15 @@ pub struct LookupResult {

#[derive(Debug, Clone)]
/// Result from an ANNOUNCE operation.
#[non_exhaustive]
pub struct AnnounceResult {
/// Closest nodes contacted during the announce.
pub closest_nodes: Vec<Ipv4Peer>,
}

#[derive(Debug, Clone)]
/// Result from an immutable put operation.
#[non_exhaustive]
pub struct ImmutablePutResult {
/// Content hash used as the target key.
pub hash: [u8; 32],
Expand All @@ -242,6 +247,7 @@ pub struct ImmutablePutResult {

#[derive(Debug, Clone)]
/// Result from a mutable put operation.
#[non_exhaustive]
pub struct MutablePutResult {
/// Public key used as the mutable record key.
pub public_key: [u8; 32],
Expand All @@ -255,6 +261,7 @@ pub struct MutablePutResult {

#[derive(Debug, Clone)]
/// Result from a mutable get operation.
#[non_exhaustive]
pub struct MutableGetResult {
/// Retrieved value bytes.
pub value: Vec<u8>,
Expand All @@ -268,6 +275,7 @@ pub struct MutableGetResult {

#[derive(Debug, Clone)]
/// Metadata needed to establish a peer connection.
#[non_exhaustive]
pub struct ConnectResult {
/// Remote peer's public key.
pub remote_public_key: [u8; 32],
Expand All @@ -289,6 +297,7 @@ pub struct ConnectResult {
///
/// Wraps a [`SecretStream`] over a UDX transport, keeping the underlying
/// socket alive for the connection's lifetime.
#[non_exhaustive]
pub struct PeerConnection {
/// Encrypted bidirectional stream to the peer.
pub stream: SecretStream<UdxAsyncStream>,
Expand Down Expand Up @@ -349,13 +358,21 @@ impl fmt::Debug for PeerConnection {
}

/// Configuration used by the server-side handshake and holepunch handler.
#[non_exhaustive]
pub struct ServerConfig {
/// Server identity key pair.
pub key_pair: KeyPair,
/// Firewall mode advertised to connecting peers.
pub firewall: u64,
}

impl ServerConfig {
/// Create a new server configuration.
pub fn new(key_pair: KeyPair, firewall: u64) -> Self {
Self { key_pair, firewall }
}
}

// ── Bootstrap defaults ────────────────────────────────────────────────────────

/// The three public HyperDHT bootstrap nodes (from `hyperdht/lib/constants.js`).
Expand All @@ -372,6 +389,7 @@ pub const DEFAULT_BOOTSTRAP: [&str; 3] = [

#[derive(Debug, Clone, Default)]
/// Configuration for a HyperDHT instance.
#[non_exhaustive]
pub struct HyperDhtConfig {
/// DHT transport and bootstrap settings.
pub dht: DhtConfig,
Expand Down
1 change: 1 addition & 0 deletions peeroxide-dht/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const DEFAULT_RETRIES: u32 = 3;
// ── Errors ────────────────────────────────────────────────────────────────────

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum IoError {
#[error("UDP error: {0}")]
Udx(#[from] libudx::UdxError),
Expand Down
1 change: 1 addition & 0 deletions peeroxide-dht/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const PROTOCOL_NAME_IK: &[u8] = b"Noise_IK_Ed25519_ChaChaPoly_BLAKE2b";

/// Errors that can occur during a Noise protocol handshake.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum NoiseError {
/// The provided public key could not be decompressed to a valid curve point.
#[error("invalid public key")]
Expand Down
2 changes: 2 additions & 0 deletions peeroxide-dht/src/noise_wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Blake2bMac256 = Blake2bMac<U32>;

/// Errors from the [`NoiseWrap`] handshake layer.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum NoiseWrapError {
/// The underlying Noise IK handshake failed.
#[error("noise handshake failed: {0}")]
Expand All @@ -40,6 +41,7 @@ pub enum NoiseWrapError {

/// Final output after a completed NoiseWrap handshake.
#[derive(Clone, Debug)]
#[non_exhaustive]
pub struct NoiseWrapResult {
/// Whether this side initiated the handshake.
pub is_initiator: bool,
Expand Down
2 changes: 2 additions & 0 deletions peeroxide-dht/src/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const MAX_RELAY_ADDRESSES: usize = 3;

/// Configuration for the `Persistent` storage.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct PersistentConfig {
pub max_records: usize,
pub max_record_age: Duration,
Expand Down Expand Up @@ -70,6 +71,7 @@ pub struct IncomingHyperRequest {
}

/// What the handler wants to send back.
#[non_exhaustive]
pub enum HandlerReply {
/// Reply with an optional value and token / closer nodes.
Value(Option<Vec<u8>>),
Expand Down
2 changes: 2 additions & 0 deletions peeroxide-dht/src/protomux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const MAX_BATCH: usize = 8 * 1024 * 1024;

#[derive(Debug, Error)]
/// Errors returned by the Protomux encoder, decoder, and channel runtime.
#[non_exhaustive]
pub enum ProtomuxError {
/// Encoding failed while serializing a frame.
#[error("encoding error: {0}")]
Expand Down Expand Up @@ -380,6 +381,7 @@ pub trait FramedStream: Send + 'static {

/// Events dispatched to individual channel handles.
#[derive(Debug)]
#[non_exhaustive]
pub enum ChannelEvent {
/// Remote opened the channel (with optional handshake data).
Opened {
Expand Down
2 changes: 2 additions & 0 deletions peeroxide-dht/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub(crate) struct QueryNode {

/// A reply from a node that made it into the `closest_replies` set.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct QueryReply {
/// The peer that replied.
pub from: Ipv4Peer,
Expand All @@ -53,6 +54,7 @@ pub struct QueryReply {

/// The final result of a completed query.
#[derive(Debug)]
#[non_exhaustive]
pub struct QueryResult {
/// Up to K closest nodes found, sorted by XOR distance to target.
pub closest_replies: Vec<QueryReply>,
Expand Down
6 changes: 6 additions & 0 deletions peeroxide-dht/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::messages::Ipv4Peer;
const DEFAULT_FORWARD_TTL: Duration = Duration::from_secs(30);

#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum RouterError {
#[error("bad handshake reply")]
BadHandshakeReply,
Expand All @@ -22,6 +23,7 @@ pub enum RouterError {
pub type Result<T> = std::result::Result<T, RouterError>;

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct HandshakeResult {
pub noise: Vec<u8>,
pub relayed: bool,
Expand All @@ -30,6 +32,7 @@ pub struct HandshakeResult {
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct HolepunchResult {
pub from: Ipv4Peer,
pub to: Ipv4Peer,
Expand All @@ -38,6 +41,7 @@ pub struct HolepunchResult {
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum HandshakeAction {
Reply(Vec<u8>),
Relay { value: Vec<u8>, to: Ipv4Peer },
Expand All @@ -47,6 +51,7 @@ pub enum HandshakeAction {
}

#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum HolepunchAction {
Reply { value: Vec<u8>, to: Ipv4Peer },
Relay { value: Vec<u8>, to: Ipv4Peer },
Expand All @@ -57,6 +62,7 @@ pub enum HolepunchAction {
Drop,
}

#[non_exhaustive]
pub struct ForwardEntry {
pub relay: Option<Ipv4Peer>,
pub has_server: bool,
Expand Down
4 changes: 4 additions & 0 deletions peeroxide-dht/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const ERR_UNKNOWN_COMMAND: u64 = 1;

#[derive(Debug, Error)]
/// Errors returned by [`DhtHandle`] and [`spawn`].
#[non_exhaustive]
pub enum DhtError {
/// Underlying I/O failed.
#[error("IO error: {0}")]
Expand All @@ -63,6 +64,7 @@ pub enum DhtError {

/// Configuration for creating a DHT node.
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct DhtConfig {
/// Bootstrap node addresses.
pub bootstrap: Vec<String>,
Expand Down Expand Up @@ -96,6 +98,7 @@ impl Default for DhtConfig {

#[derive(Debug, Clone)]
/// Response to a ping request.
#[non_exhaustive]
pub struct PingResponse {
/// Remote peer that replied.
pub from: Ipv4Peer,
Expand All @@ -107,6 +110,7 @@ pub struct PingResponse {

#[derive(Debug, Clone)]
/// Data returned from a DHT request.
#[non_exhaustive]
pub struct ResponseData {
/// Remote peer that replied.
pub from: Ipv4Peer,
Expand Down
Loading
Loading