Skip to content
Closed
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
2 changes: 1 addition & 1 deletion src/handler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/handler/request_call.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use crate::node_info::{NodeAddress, NodeContact};
pub use crate::node_info::NodeContact;
use crate::{
packet::Packet,
rpc::{Request, RequestBody},
Expand Down
22 changes: 11 additions & 11 deletions src/ipmode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ impl IpMode {
}
}

/// Copied from the standard library. See <https://github.com/rust-lang/rust/issues/27709>
/// The current code is behind the `ip` feature.
pub const fn to_ipv4_mapped(ip: &std::net::Ipv6Addr) -> Option<std::net::Ipv4Addr> {
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::*;
Expand Down Expand Up @@ -230,14 +241,3 @@ mod tests {
.test();
}
}

/// Copied from the standard library. See <https://github.com/rust-lang/rust/issues/27709>
/// The current code is behind the `ip` feature.
pub const fn to_ipv4_mapped(ip: &std::net::Ipv6Addr) -> Option<std::net::Ipv4Addr> {
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,
}
}
4 changes: 1 addition & 3 deletions src/kbucket/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
11 changes: 10 additions & 1 deletion src/packet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<const N: usize = 0>: 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;
Expand Down
4 changes: 2 additions & 2 deletions src/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ 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();

let enr_key2 = CombinedKey::generate_secp256k1();
let ip2 = std::net::Ipv4Addr::LOCALHOST;
let enr2 = EnrBuilder::new("v4")
.ip4(ip2)
.udp4(10002)
.udp4(10004)
.build(&enr_key2)
.unwrap();

Expand Down