nat

package
v0.41.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2025 License: MIT Imports: 9 Imported by: 11

Documentation

Index

Constants

View Source
const CacheTime = 15 * time.Second

CacheTime is the time a mapping will cache an external address for

View Source
const MappingDuration = time.Minute

MappingDuration is a default port mapping duration. Port mappings are renewed every (MappingDuration / 3)

Variables

View Source
var ErrNoMapping = errors.New("mapping not established")

ErrNoMapping signals no mapping exists for an address

Functions

This section is empty.

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

func DiscoverNAT(ctx context.Context) (*NAT, error)

DiscoverNAT looks for a NAT device in the network and returns an object that can manage port mappings.

func (*NAT) AddMapping added in v0.28.0

func (nat *NAT) AddMapping(ctx context.Context, protocol string, port int) error

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

func (nat *NAT) Close() error

Close shuts down all port mappings. NAT can no longer be used.

func (*NAT) GetMapping added in v0.28.0

func (nat *NAT) GetMapping(protocol string, port int) (addr netip.AddrPort, found bool)

func (*NAT) RemoveMapping added in v0.28.0

func (nat *NAT) RemoveMapping(ctx context.Context, protocol string, port int) error

RemoveMapping removes a port mapping. It blocks until the NAT has removed the mapping.

Directories

Path Synopsis
internal
nat
Package nat implements NAT handling facilities
Package nat implements NAT handling facilities

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL