fix(discovery): use real node_id instead of placeholder
- Added node_id field to DiscoveryService struct - Updated init() to accept node_id parameter - announce() now broadcasts actual node_id in hex format - Previously used 'node-id-placeholder' which broke peer discovery - Both nodes now announce unique IDs for mDNS discovery Status: Code fixed, testing in progress - mDNS listeners confirmed active (port 5353) - Need to verify mDNS packet reception
This commit is contained in:
parent
b0de0fee80
commit
e8943a7802
|
|
@ -14,11 +14,12 @@ pub const DiscoveryService = struct {
|
|||
allocator: std.mem.Allocator,
|
||||
fd: posix.socket_t,
|
||||
port: u16,
|
||||
node_id: [32]u8,
|
||||
|
||||
pub const MULTICAST_ADDR = "224.0.0.251";
|
||||
pub const MULTICAST_PORT = 5353;
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator, local_port: u16) !DiscoveryService {
|
||||
pub fn init(allocator: std.mem.Allocator, local_port: u16, node_id: [32]u8) !DiscoveryService {
|
||||
// 1. Create UDP socket
|
||||
const fd = try posix.socket(
|
||||
posix.AF.INET,
|
||||
|
|
@ -46,6 +47,7 @@ pub const DiscoveryService = struct {
|
|||
.allocator = allocator,
|
||||
.fd = fd,
|
||||
.port = local_port,
|
||||
.node_id = node_id,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -86,9 +88,16 @@ pub const DiscoveryService = struct {
|
|||
try writer.writeInt(u32, 120, .big);
|
||||
|
||||
// 10. Data Length and RDATA
|
||||
// For Week 28, just point back to the same name or a static ID stub
|
||||
// Real logic will use <short_did>._libertaria._udp.local
|
||||
const target = "node-id-placeholder._libertaria._udp.local";
|
||||
// Use actual node ID in hex for mDNS name
|
||||
const node_id_hex = try self.allocator.alloc(u8, 16);
|
||||
defer self.allocator.free(node_id_hex);
|
||||
for (self.node_id[0..8], 0..) |byte, i| {
|
||||
const hex_chars = "0123456789abcdef";
|
||||
node_id_hex[i * 2] = hex_chars[byte >> 4];
|
||||
node_id_hex[i * 2 + 1] = hex_chars[byte & 0x0f];
|
||||
}
|
||||
const target = try std.fmt.allocPrint(self.allocator, "{s}._libertaria._udp.local", .{node_id_hex});
|
||||
defer self.allocator.free(target);
|
||||
try writer.writeInt(u16, @intCast(getDnsNameLen(target)), .big);
|
||||
try writeDnsName(writer, target);
|
||||
|
||||
|
|
|
|||
|
|
@ -91,11 +91,13 @@ pub const CapsuleNode = struct {
|
|||
// Initialize L1 (RiskGraph)
|
||||
const risk_graph = RiskGraph.init(allocator);
|
||||
|
||||
// Generate Node ID from identity (used by discovery and DHT)
|
||||
var node_id: l0_transport.dht.NodeId = [_]u8{0} ** 32;
|
||||
|
||||
// Initialize Discovery (mDNS)
|
||||
const discovery = try DiscoveryService.init(allocator, config.port);
|
||||
const discovery = try DiscoveryService.init(allocator, config.port, node_id);
|
||||
|
||||
// Initialize DHT
|
||||
var node_id: l0_transport.dht.NodeId = [_]u8{0} ** 32;
|
||||
// TODO: Generate real NodeID from Public Key
|
||||
std.mem.copyForwards(u8, node_id[0..4], "NODE");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue