Repository navigation
Description
Version Information
github.com/libp2p/go-libp2p v0.37.0
I found that my libp2p node's address list had a NATMap address with port 0 and an observed address with port 0.
2024-11-21T09:15:44.482Z DEBUG net/identify identify/id.go:486 sending snapshot {"seq": 7, "protocols": ["/ipfs/id/1.0.0","/ipfs/id/push/1.0.0","/ipfs/ping/1.0.0","/libp2p/circuit/relay/0.2.0/stop"], "addrs": [...,"/ip4/100.64.138.163/tcp/0","/ip4/100.64.138.163/udp/0/quic-v1/webtransport/certhash/uEiAO2S9URsYyw-LBGIJytw3zQbw8pvXgomESq3PLp31PVg/certhash/uEiCxf6Zi2SitEayX9jE50_APDrBMbfR5m-U6F7HcBMnkFw","/ip4/{observed ip}/tcp/0",...]}
At the same time, I found that my NAT mapping had the following error due to too many mapped addresses:
2024-11-21T09:15:42.049Z WARN nat nat/nat.go:239 failed to establish port mapping: SOAP fault. Code: s:Client | Explanation: UPnPError | Detail: <UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>501</errorCode><errorDescription>Port mapping table id full !</errorDescription></UPnPError>
After debugging, I found that the problem is caused by:
-
When NAT mapping fails, port 0 will be returned
Line 245 in 288868c
return 0 -
When basic_host calls AllAddrs, it gets the mapping address from natmgr, and natmrg gets the mapping address from nat. However, nat does not determine the mapping failure, resulting in port 0 being returned.
go-libp2p/p2p/host/basic/basic_host.go
Line 902 in 288868c
extMaddr := h.natmgr.GetMapping(listen)
go-libp2p/p2p/host/basic/natmgr.go
Line 269 in 288868c
extAddr, ok := nmgr.nat.GetMapping(protocol, port)
Line 110 in 288868c
if !found { -
basic_host replaces the port observed by the observed address with 0
go-libp2p/p2p/host/basic/basic_host.go
Line 943 in 288868c
_, extMaddrNoIP := ma.SplitFirst(extMaddr)
go-libp2p/p2p/host/basic/basic_host.go
Line 952 in 288868c
finalAddrs = append(finalAddrs, ma.Join(ip, extMaddrNoIP))
Activity
nat: ignore mapping if external port is 0
nat: ignore mapping if external port is 0