nat

package
v0.0.0-...-08de2ff Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2023 License: MIT Imports: 8 Imported by: 0

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

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

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

func (*NAT) RemoveMapping

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.

Jump to

Keyboard shortcuts

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