add NAT-PMP for automatic port mapping and external address discovery

This commit is contained in:
2026-02-09 17:05:24 -03:00
parent 7b47ef155c
commit cf5eb0d5fd
11 changed files with 970 additions and 1 deletions

View File

@@ -294,7 +294,16 @@ pub fn main() !void {
found_addr = true;
}
// Second priority: consensus address from IP Reflection (multi-source)
// Second priority: NAT-PMP (automatic port mapping)
if (!found_addr) {
if (p2p_node.tryNatPmpDiscovery(@intCast(port + 1), 3600)) |external_ip| {
mwp_addrs[0] = mwp.Address.initV4(external_ip, port + 1);
std.debug.print(" Using NAT-PMP: {d}.{d}.{d}.{d}:{d}\n", .{ external_ip[0], external_ip[1], external_ip[2], external_ip[3], port + 1 });
found_addr = true;
}
}
// Third priority: consensus address from IP Reflection (multi-source)
if (!found_addr) {
const consensus = p2p_node.getConsensusAddress();
if (consensus.address) |observed| {