diff --git a/src/handler/mod.rs b/src/handler/mod.rs index 625582402..52a47a8a9 100644 --- a/src/handler/mod.rs +++ b/src/handler/mod.rs @@ -471,7 +471,7 @@ impl Handler { trace!("Request queued for node: {}", node_address); self.pending_requests .entry(node_address) - .or_insert_with(Vec::new) + .or_default() .push(PendingRequest { contact, request_id, diff --git a/src/handler/request_call.rs b/src/handler/request_call.rs index b91c7643e..42506aa76 100644 --- a/src/handler/request_call.rs +++ b/src/handler/request_call.rs @@ -1,4 +1,4 @@ -pub use crate::node_info::{NodeAddress, NodeContact}; +pub use crate::node_info::NodeContact; use crate::{ packet::Packet, rpc::{Request, RequestBody}, diff --git a/src/ipmode.rs b/src/ipmode.rs index de66fd195..f2dbe48da 100644 --- a/src/ipmode.rs +++ b/src/ipmode.rs @@ -69,6 +69,17 @@ impl IpMode { } } +/// Copied from the standard library. See +/// The current code is behind the `ip` feature. +pub const fn to_ipv4_mapped(ip: &std::net::Ipv6Addr) -> Option { + match ip.octets() { + [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => { + Some(std::net::Ipv4Addr::new(a, b, c, d)) + } + _ => None, + } +} + #[cfg(test)] mod tests { use super::*; @@ -230,14 +241,3 @@ mod tests { .test(); } } - -/// Copied from the standard library. See -/// The current code is behind the `ip` feature. -pub const fn to_ipv4_mapped(ip: &std::net::Ipv6Addr) -> Option { - match ip.octets() { - [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, a, b, c, d] => { - Some(std::net::Ipv4Addr::new(a, b, c, d)) - } - _ => None, - } -} diff --git a/src/kbucket/entry.rs b/src/kbucket/entry.rs index 1e0304048..97be95de1 100644 --- a/src/kbucket/entry.rs +++ b/src/kbucket/entry.rs @@ -25,9 +25,7 @@ //! representing the nodes participating in the Kademlia DHT. pub use super::{ - bucket::{ - AppliedPending, ConnectionState, InsertResult, Node, NodeStatus, MAX_NODES_PER_BUCKET, - }, + bucket::{AppliedPending, ConnectionState, InsertResult, Node, NodeStatus}, key::*, ConnectionDirection, }; diff --git a/src/packet/mod.rs b/src/packet/mod.rs index f071263bd..ef7ad63c0 100644 --- a/src/packet/mod.rs +++ b/src/packet/mod.rs @@ -29,16 +29,25 @@ pub const MESSAGE_NONCE_LENGTH: usize = 12; /// The Id nonce length (in bytes). pub const ID_NONCE_LENGTH: usize = 16; +pub struct Nat; + +impl ProtocolIdentity<3> for Nat { + const PROTOCOL_ID_BYTES: [u8; 6] = *b"discv5"; + const PROTOCOL_VERSION_BYTES: [u8; 2] = 0x0001_u16.to_be_bytes(); + const IMPLEMENTATION_FEATURES: [u8; 3] = *b"nat"; +} pub struct DefaultProtocolId {} impl ProtocolIdentity for DefaultProtocolId { const PROTOCOL_ID_BYTES: [u8; 6] = *b"discv5"; const PROTOCOL_VERSION_BYTES: [u8; 2] = 0x0001_u16.to_be_bytes(); + const IMPLEMENTATION_FEATURES: [u8; 0] = *b""; } -pub trait ProtocolIdentity { +pub trait ProtocolIdentity: Sync + Send { const PROTOCOL_ID_BYTES: [u8; 6]; const PROTOCOL_VERSION_BYTES: [u8; 2]; + const IMPLEMENTATION_FEATURES: [u8; N]; } pub(crate) const MAX_PACKET_SIZE: usize = 1280; diff --git a/src/service/test.rs b/src/service/test.rs index b2860700e..d02f8394c 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -173,7 +173,7 @@ async fn test_connection_direction_on_inject_session_established() { let ip = std::net::Ipv4Addr::LOCALHOST; let enr = EnrBuilder::new("v4") .ip4(ip) - .udp4(10001) + .udp4(10003) .build(&enr_key1) .unwrap(); @@ -181,7 +181,7 @@ async fn test_connection_direction_on_inject_session_established() { let ip2 = std::net::Ipv4Addr::LOCALHOST; let enr2 = EnrBuilder::new("v4") .ip4(ip2) - .udp4(10002) + .udp4(10004) .build(&enr_key2) .unwrap();