mwp-fixes #5
@@ -503,7 +503,14 @@ pub const DhtCoordinator = struct {
|
||||
pub fn init(allocator: Allocator, routing_table: *KademliaRoutingTable, local_id: NodeId) DhtCoordinator {
|
||||
// Generate Ed25519 identity keypair for signing
|
||||
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,
|
||||
.routing_table = routing_table,
|
||||
.local_id = local_id,
|
||||
@@ -515,6 +522,8 @@ pub const DhtCoordinator = struct {
|
||||
.peer_rate_limits = std.AutoHashMap(NodeId, PeerRateLimit).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)
|
||||
|
||||
Reference in New Issue
Block a user