add UPnP IGD for automatic port mapping and external address discovery

This commit is contained in:
2026-02-09 17:49:44 -03:00
parent cf5eb0d5fd
commit 33730fed8a
13 changed files with 1364 additions and 7 deletions

View File

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