feat(net): auto-map the listen port via UPnP-IGD and NAT-PMP

Behind a home router the client is unreachable for incoming peer
connections, so browsing/downloading firewalled peers (and the
server-brokered connect-back) times out. Add a best-effort port mapper
to the binary crate that, when listening is enabled, makes us reachable:

- NAT-PMP (RFC 6886) hand-rolled on std::net::UdpSocket, zero deps, with
  an injectable gateway address so it is fully testable.
- UPnP-IGD via the blocking igd-next crate as the primary path.
- A background PortMapper that discovers off the main thread (never
  blocks startup), renews at half the lease, and removes the mapping on
  drop. Any failure is non-fatal and logged.
- Maps the EXACT listen port only (we advertise it verbatim via
  SetWaitPort, so a different external port would be unreachable) and
  warns the user to forward manually otherwise.

Wired into the TUI, search, and CLI browse (the P2P modes); chat/rooms/
messaging are server-mediated and skip it. e2e-tested against an
in-process mock NAT-PMP gateway: the map request bytes, response parsing,
result-code/timeout handling, and the full spawn -> map -> drop -> unmap
service lifecycle.
This commit is contained in:
michel
2026-07-19 21:10:15 +02:00
parent e59c2bc199
commit 5ba2f9e181
5 changed files with 1083 additions and 3 deletions
+1
View File
@@ -23,3 +23,4 @@ clap = { version = "4.6.2", features = ["derive", "color", "wrap_help", "env"] }
ratatui = "0.30.2"
color-eyre = "0.6.5"
dotenv = "0.15.0"
igd-next = "0.17"