package nat
import "github.com/libp2p/go-libp2p/p2p/net/nat"
Index ¶
- Constants
- Variables
- type NAT
- func DiscoverNAT(ctx context.Context) (*NAT, error)
- func (nat *NAT) AddMapping(ctx context.Context, protocol string, port int) error
- func (nat *NAT) Close() error
- func (nat *NAT) GetMapping(protocol string, port int) (addr netip.AddrPort, found bool)
- func (nat *NAT) RemoveMapping(ctx context.Context, protocol string, port int) error
Constants ¶
CacheTime is the time a mapping will cache an external address for
MappingDuration is a default port mapping duration. Port mappings are renewed every (MappingDuration / 3)
Variables ¶
ErrNoMapping signals no mapping exists for an address
Types ¶
type NAT ¶
type NAT struct {
// contains filtered or unexported fields
}
NAT is an object that manages address port mappings in NATs (Network Address Translators). It is a long-running service that will periodically renew port mappings, and keep an up-to-date list of all the external addresses.
func DiscoverNAT ¶
DiscoverNAT looks for a NAT device in the network and returns an object that can manage port mappings.
func (*NAT) AddMapping ¶
AddMapping attempts to construct a mapping on protocol and internal port. It blocks until a mapping was established. Once added, it periodically renews the mapping.
May not succeed, and mappings may change over time; NAT devices may not respect our port requests, and even lie.
func (*NAT) Close ¶
Close shuts down all port mappings. NAT can no longer be used.
func (*NAT) GetMapping ¶
func (*NAT) RemoveMapping ¶
RemoveMapping removes a port mapping. It blocks until the NAT has removed the mapping.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
p2p/net/nat/internal |
- Version
- v0.42.0 (latest)
- Published
- Jun 18, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 3 weeks ago –
Tools for package owners.