mwp-fixes #5

Merged
mdt merged 6 commits from mwp-fixes into main 2026-02-19 14:53:53 +00:00
10 changed files with 267 additions and 284 deletions
Showing only changes of commit e745f849dc - Show all commits

View File

@@ -503,7 +503,14 @@ pub const DhtCoordinator = struct {
pub fn init(allocator: Allocator, routing_table: *KademliaRoutingTable, local_id: NodeId) DhtCoordinator { pub fn init(allocator: Allocator, routing_table: *KademliaRoutingTable, local_id: NodeId) DhtCoordinator {
// Generate Ed25519 identity keypair for signing // Generate Ed25519 identity keypair for signing
const identity_keypair = Ed25519.KeyPair.generate(); const identity_keypair = Ed25519.KeyPair.generate();
return .{
// SECURITY FIX: Initialize request_id with random value to prevent nonce collisions
// When multiple nodes start simultaneously, they would all start with request_id=1
// causing the replay protection system to detect false positives (DuplicateNonce errors)
var random_start: u64 = undefined;
std.crypto.random.bytes(std.mem.asBytes(&random_start));
var dht = DhtCoordinator{
.allocator = allocator, .allocator = allocator,
.routing_table = routing_table, .routing_table = routing_table,
.local_id = local_id, .local_id = local_id,
@@ -515,6 +522,8 @@ pub const DhtCoordinator = struct {
.peer_rate_limits = std.AutoHashMap(NodeId, PeerRateLimit).init(allocator), .peer_rate_limits = std.AutoHashMap(NodeId, PeerRateLimit).init(allocator),
.discovered_peers = std.AutoHashMap(NodeId, DiscoveredPeer).init(allocator), .discovered_peers = std.AutoHashMap(NodeId, DiscoveredPeer).init(allocator),
}; };
dht.next_request_id.store(random_start, .monotonic);
return dht;
} }
/// Initialize with custom TOFU callback for peer verification (recommended for production) /// Initialize with custom TOFU callback for peer verification (recommended for production)