Skip to content

NATMap mapping failed, resulting in an observed address error #3057

Closed

Description

@wlynxg
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:

  1. When NAT mapping fails, port 0 will be returned

    return 0

  2. 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.

    extMaddr := h.natmgr.GetMapping(listen)

    extAddr, ok := nmgr.nat.GetMapping(protocol, port)

    if !found {

  3. basic_host replaces the port observed by the observed address with 0

    _, extMaddrNoIP := ma.SplitFirst(extMaddr)

    finalAddrs = append(finalAddrs, ma.Join(ip, extMaddrNoIP))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions