Module reorganization and clippy cleanup

Move single-consumer modules into node/:
- rate_limit.rs, wire.rs, dns.rs — exclusively used by node subsystem
- Reduces top-level lib.rs from 16 to 13 modules

Split large files into focused subdirectories:
- noise.rs (1475 lines) → noise/{mod, handshake, session, replay, tests}.rs
- tree.rs (1479 lines) → tree/{mod, coordinate, declaration, state, tests}.rs
- bloom.rs (849 lines) → bloom/{mod, filter, state, tests}.rs
- All public APIs re-exported from mod.rs, no external import changes

Remove unused rate_limit defaults:
- HANDSHAKE_TIMEOUT_SECS, MAX_PENDING_INBOUND constants
- Default constructor eliminated in favor of with_params() taking config values

Fix all clippy warnings across codebase:
- Remove .clone() on Copy types, collapse nested ifs, replace match-return-None
  with ?, remove/gate unused code, fix loop indexing, remove unnecessary casts
- Box large PeerSlot enum variants to reduce size disparity
- cargo clippy --all-targets now reports zero warnings
This commit is contained in:
Johnathan Corgan
2026-02-15 15:07:42 +00:00
parent 89bc9cc4b0
commit b8a1f322c2
43 changed files with 3997 additions and 3981 deletions
+6 -5
View File
@@ -120,11 +120,12 @@ async fn test_bloom_filter_star() {
let filter = peer.inbound_filter().unwrap();
// Filter from hub should contain all OTHER spokes
for other in 1..5 {
for (other, other_node) in nodes[1..5].iter().enumerate() {
let other = other + 1; // adjust for slice offset
if other == spoke {
continue;
}
let other_addr = *nodes[other].node.node_addr();
let other_addr = *other_node.node.node_addr();
assert!(
filter.contains(&other_addr),
"Spoke {}'s filter from hub should contain spoke {} (addr={})",
@@ -168,12 +169,12 @@ async fn test_bloom_filter_chain_propagation() {
// Entries propagate through the full chain because each
// intermediate node merges its peer's filter into its outgoing
// filter. Verify all nodes are reachable from the endpoints.
for i in 2..8 {
for (i, addr) in addrs[2..8].iter().enumerate() {
assert!(
filter.contains(&addrs[i]),
filter.contains(addr),
"Node 0's filter from node 1 should contain node {} \
(chain merge propagation)",
i
i + 2
);
}
+5 -4
View File
@@ -100,20 +100,21 @@ async fn test_disconnect_star_hub_departs() {
process_available_packets(&mut nodes).await;
// All spokes should have removed the hub
for spoke_idx in 1..4 {
for (spoke_idx, spoke) in nodes[1..4].iter().enumerate() {
let spoke_idx = spoke_idx + 1; // adjust for slice offset
assert!(
nodes[spoke_idx].node.get_peer(&hub_addr).is_none(),
spoke.node.get_peer(&hub_addr).is_none(),
"Spoke {} should have removed hub",
spoke_idx
);
assert_eq!(
nodes[spoke_idx].node.peer_count(),
spoke.node.peer_count(),
0,
"Spoke {} should have no peers (no spoke-spoke links)",
spoke_idx
);
assert!(
nodes[spoke_idx].node.tree_state().is_root(),
spoke.node.tree_state().is_root(),
"Isolated spoke {} should become root",
spoke_idx
);
+10 -10
View File
@@ -6,7 +6,7 @@ use super::*;
async fn test_two_node_handshake_udp() {
use crate::config::UdpConfig;
use crate::transport::udp::UdpTransport;
use crate::wire::{build_encrypted, build_msg1};
use crate::node::wire::{build_encrypted, build_msg1};
use tokio::time::{timeout, Duration};
// === Setup: Two nodes with UDP transports on localhost ===
@@ -55,7 +55,7 @@ async fn test_two_node_handshake_udp() {
let link_id_a = node_a.allocate_link_id();
let mut conn_a = PeerConnection::outbound(
link_id_a,
peer_b_identity.clone(),
peer_b_identity,
1000,
);
@@ -233,7 +233,7 @@ async fn test_two_node_handshake_udp() {
async fn test_run_rx_loop_handshake() {
use crate::config::UdpConfig;
use crate::transport::udp::UdpTransport;
use crate::wire::build_msg1;
use crate::node::wire::build_msg1;
use tokio::time::Duration;
// === Setup: Two nodes with UDP transports on localhost ===
@@ -287,7 +287,7 @@ async fn test_run_rx_loop_handshake() {
let link_id_a = node_a.allocate_link_id();
let mut conn_a = PeerConnection::outbound(
link_id_a,
peer_b_identity.clone(),
peer_b_identity,
1000,
);
@@ -423,7 +423,7 @@ async fn test_run_rx_loop_handshake() {
async fn test_cross_connection_both_initiate() {
use crate::config::UdpConfig;
use crate::transport::udp::UdpTransport;
use crate::wire::build_msg1;
use crate::node::wire::build_msg1;
use tokio::time::{timeout, Duration};
// === Setup: Two nodes with UDP transports on localhost ===
@@ -474,7 +474,7 @@ async fn test_cross_connection_both_initiate() {
// Node A initiates to Node B
let link_id_a_out = node_a.allocate_link_id();
let mut conn_a = PeerConnection::outbound(link_id_a_out, peer_b_identity.clone(), 1000);
let mut conn_a = PeerConnection::outbound(link_id_a_out, peer_b_identity, 1000);
let our_index_a = node_a.index_allocator.allocate().unwrap();
let our_keypair_a = node_a.identity.keypair();
let noise_msg1_a = conn_a.start_handshake(our_keypair_a, 1000).unwrap();
@@ -495,7 +495,7 @@ async fn test_cross_connection_both_initiate() {
// Node B initiates to Node A
let link_id_b_out = node_b.allocate_link_id();
let mut conn_b = PeerConnection::outbound(link_id_b_out, peer_a_identity.clone(), 1000);
let mut conn_b = PeerConnection::outbound(link_id_b_out, peer_a_identity, 1000);
let our_index_b = node_b.index_allocator.allocate().unwrap();
let our_keypair_b = node_b.identity.keypair();
let noise_msg1_b = conn_b.start_handshake(our_keypair_b, 1000).unwrap();
@@ -595,7 +595,7 @@ async fn test_stale_connection_cleanup() {
// Create outbound connection with a timestamp far in the past
let past_time_ms = 1000; // A very early timestamp
let link_id = node.allocate_link_id();
let mut conn = PeerConnection::outbound(link_id, peer_identity.clone(), past_time_ms);
let mut conn = PeerConnection::outbound(link_id, peer_identity, past_time_ms);
// Allocate session index and set transport info
let our_index = node.index_allocator.allocate().unwrap();
@@ -631,7 +631,7 @@ async fn test_stale_connection_cleanup() {
assert!(!node.pending_outbound.contains_key(&(transport_id, our_index.as_u32())),
"pending_outbound should be cleaned up");
assert_eq!(node.index_allocator.count(), 0, "Session index should be freed");
assert!(node.addr_to_link.get(&(transport_id, remote_addr)).is_none(),
assert!(!node.addr_to_link.contains_key(&(transport_id, remote_addr)),
"addr_to_link should be cleaned up");
}
@@ -650,7 +650,7 @@ async fn test_failed_connection_cleanup() {
.map(|d| d.as_millis() as u64)
.unwrap_or(0);
let link_id = node.allocate_link_id();
let mut conn = PeerConnection::outbound(link_id, peer_identity.clone(), now_ms);
let mut conn = PeerConnection::outbound(link_id, peer_identity, now_ms);
let our_index = node.index_allocator.allocate().unwrap();
let our_keypair = node.identity.keypair();
+1 -1
View File
@@ -46,7 +46,7 @@ pub(super) fn make_completed_connection(
let peer_identity = PeerIdentity::from_pubkey_full(peer_identity_full.pubkey_full());
// Create outbound connection
let mut conn = PeerConnection::outbound(link_id, peer_identity.clone(), current_time_ms);
let mut conn = PeerConnection::outbound(link_id, peer_identity, current_time_ms);
// Run initiator side of handshake
let our_keypair = node.identity.keypair();
+3 -3
View File
@@ -562,7 +562,7 @@ async fn test_routing_reachability_100_nodes() {
.collect();
for node in &mut nodes {
for &(ref addr, ref coords) in &all_coords {
for (addr, coords) in &all_coords {
if addr != node.node.node_addr() {
node.node.coord_cache_mut().insert(*addr, coords.clone(), now_ms);
}
@@ -696,7 +696,7 @@ async fn test_routing_stops_after_peer_removal() {
.collect();
for node in &mut nodes {
for &(ref addr, ref coords) in &all_coords {
for (addr, coords) in &all_coords {
if addr != node.node.node_addr() {
node.node.coord_cache_mut().insert(*addr, coords.clone(), now_ms);
}
@@ -931,7 +931,7 @@ async fn test_routing_source_only_coords_100_nodes() {
// Now compare: inject coords at ALL nodes (full cache) and verify 100%
for node in &mut nodes {
for &(ref addr, ref coords) in &all_coords {
for (addr, coords) in &all_coords {
if addr != node.node.node_addr() {
node.node.coord_cache_mut().insert(*addr, coords.clone(), now_ms);
}
+2 -2
View File
@@ -639,13 +639,13 @@ async fn test_session_100_nodes() {
let fwd_payload = format!("fwd-{}", pair_idx).into_bytes();
let rev_payload = format!("rev-{}", pair_idx).into_bytes();
if delivered_per_node[dst].iter().any(|p| *p == fwd_payload) {
if delivered_per_node[dst].contains(&fwd_payload) {
fwd_delivered += 1;
} else if fwd_missing.len() < 20 {
fwd_missing.push((src, dst));
}
if delivered_per_node[src].iter().any(|p| *p == rev_payload) {
if delivered_per_node[src].contains(&rev_payload) {
rev_delivered += 1;
} else if rev_missing.len() < 20 {
rev_missing.push((src, dst));
+7 -7
View File
@@ -48,7 +48,7 @@ pub(super) async fn make_test_node() -> TestNode {
/// Sends msg1 over UDP. The drain loop will handle msg1 processing,
/// msg2 response, and subsequent TreeAnnounce exchange.
pub(super) async fn initiate_handshake(nodes: &mut [TestNode], i: usize, j: usize) {
use crate::wire::build_msg1;
use crate::node::wire::build_msg1;
// Extract responder info before mutably borrowing initiator
let responder_addr = nodes[j].addr.clone();
@@ -203,19 +203,19 @@ pub(super) fn print_tree_snapshot(label: &str, nodes: &[TestNode]) {
///
/// Returns the number of packets processed.
pub(super) async fn process_available_packets(nodes: &mut [TestNode]) -> usize {
use crate::wire::{DISCRIMINATOR_ENCRYPTED, DISCRIMINATOR_MSG1, DISCRIMINATOR_MSG2};
use crate::node::wire::{DISCRIMINATOR_ENCRYPTED, DISCRIMINATOR_MSG1, DISCRIMINATOR_MSG2};
let mut count = 0;
for i in 0..nodes.len() {
while let Ok(packet) = nodes[i].packet_rx.try_recv() {
for node in nodes.iter_mut() {
while let Ok(packet) = node.packet_rx.try_recv() {
if packet.data.is_empty() {
continue;
}
match packet.data[0] {
DISCRIMINATOR_MSG1 => nodes[i].node.handle_msg1(packet).await,
DISCRIMINATOR_MSG2 => nodes[i].node.handle_msg2(packet).await,
DISCRIMINATOR_MSG1 => node.node.handle_msg1(packet).await,
DISCRIMINATOR_MSG2 => node.node.handle_msg2(packet).await,
DISCRIMINATOR_ENCRYPTED => {
nodes[i].node.handle_encrypted_frame(packet).await
node.node.handle_encrypted_frame(packet).await
}
_ => {}
}
+5 -5
View File
@@ -152,7 +152,7 @@ fn test_node_connection_duplicate() {
let identity = make_peer_identity();
let link_id = LinkId::new(1);
let conn1 = PeerConnection::outbound(link_id, identity.clone(), 1000);
let conn1 = PeerConnection::outbound(link_id, identity, 1000);
let conn2 = PeerConnection::outbound(link_id, identity, 2000);
node.add_connection(conn1).unwrap();
@@ -206,7 +206,7 @@ fn test_node_cross_connection_resolution() {
let node_addr = *identity.node_addr();
node.add_connection(conn1).unwrap();
node.promote_connection(link_id1, identity.clone(), 1500).unwrap();
node.promote_connection(link_id1, identity, 1500).unwrap();
assert_eq!(node.peer_count(), 1);
assert_eq!(node.get_peer(&node_addr).unwrap().link_id(), link_id1);
@@ -447,7 +447,7 @@ fn test_promote_cleans_up_pending_outbound_to_same_peer() {
let pending_link_id = LinkId::new(1);
let pending_time_ms = 1000;
let mut pending_conn =
PeerConnection::outbound(pending_link_id, peer_b_identity.clone(), pending_time_ms);
PeerConnection::outbound(pending_link_id, peer_b_identity, pending_time_ms);
let our_keypair = node.identity.keypair();
let _msg1 = pending_conn.start_handshake(our_keypair, pending_time_ms).unwrap();
@@ -485,7 +485,7 @@ fn test_promote_cleans_up_pending_outbound_to_same_peer() {
let mut completing_conn = PeerConnection::outbound(
completing_link_id,
peer_b_identity.clone(),
peer_b_identity,
completing_time_ms,
);
@@ -519,7 +519,7 @@ fn test_promote_cleans_up_pending_outbound_to_same_peer() {
// --- Promote the completing connection ---
let result = node
.promote_connection(completing_link_id, peer_b_identity.clone(), completing_time_ms)
.promote_connection(completing_link_id, peer_b_identity, completing_time_ms)
.unwrap();
assert!(matches!(result, PromotionResult::Promoted(_)));