Skip to content

Commit 1335ba5

Browse files
committed
Switch to EnableNAT to make it much more explicit, default is now disabled
1 parent 37b5011 commit 1335ba5

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

client.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,14 +258,17 @@ func createHost(_ context.Context, hostOpts []libp2p.Option, config Config, rela
258258
),
259259
)
260260

261-
// Only enable NAT traversal features if not disabled
262-
// NAT features can cause data races in tests due to libp2p's NAT manager using non-thread-safe global state
263-
if !config.DisableNAT {
261+
// Enable NAT features only if explicitly enabled
262+
// UPnP/NAT-PMP scans the local gateway which triggers network scanning alerts
263+
if config.EnableNAT {
264264
hostOpts = append(hostOpts,
265265
libp2p.NATPortMap(),
266266
libp2p.EnableNATService(),
267267
libp2p.EnableHolePunching(),
268268
)
269+
log.Infof("UPnP/NAT-PMP enabled (will scan local gateway for port mapping)")
270+
} else {
271+
log.Infof("UPnP/NAT-PMP disabled (production safe default)")
269272
}
270273

271274
hostOpts = append(hostOpts,

config.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,13 @@ type Config struct {
9898
// The cleanup frequency trades off between memory usage (stale records) and CPU usage.
9999
DHTCleanupInterval time.Duration
100100

101-
// DisableNAT disables NAT traversal features (UPnP/NAT-PMP port mapping, NAT service, hole punching).
102-
// Set to true in test environments where NAT traversal is not needed and can cause data races
103-
// due to libp2p's NAT manager using non-thread-safe global state.
104-
// Default: false (NAT features enabled)
105-
DisableNAT bool
101+
// EnableNAT enables UPnP/NAT-PMP automatic port mapping features.
102+
// When true, the node will scan the local gateway (e.g., 10.0.0.1) to configure port forwarding.
103+
// IMPORTANT: This triggers network scanning alerts on shared hosting (Hetzner, AWS, etc.).
104+
// Only enable for local development behind a home router/NAT.
105+
// Default: false (NAT features disabled for production safety)
106+
// Note: Hole punching (relay-based NAT traversal) remains enabled and doesn't scan local network.
107+
EnableNAT bool
106108

107109
// EnableMDNS enables multicast DNS peer discovery on the local network.
108110
// When true, the node broadcasts mDNS queries to discover peers on the same LAN.

0 commit comments

Comments
 (0)