nat

package
v1.8.14 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2022 License: BSD-3-Clause Imports: 14 Imported by: 2 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper struct {
	// contains filtered or unexported fields
}

Mapper attempts to open a set of ports on a router

func NewPortMapper

func NewPortMapper(log logging.Logger, r Router) Mapper

NewPortMapper returns an initialized mapper

func (*Mapper) Map

func (m *Mapper) Map(protocol string, intPort, extPort uint16, desc string, ip ips.DynamicIPPort, updateTime time.Duration)

Map external port [extPort] (exposed to the internet) to internal port [intPort] (where our process is listening) and set [ip]. Does this every [updateTime]. [ip] may be nil.

func (*Mapper) UnmapAllPorts

func (m *Mapper) UnmapAllPorts()

UnmapAllPorts stops mapping all ports from this mapper and attempts to unmap them.

type Router

type Router interface {
	// True iff this router supports NAT
	SupportsNAT() bool
	// Map external port [extPort] to internal port [intPort] for [duration]
	MapPort(protocol string, intPort, extPort uint16, desc string, duration time.Duration) error
	// Undo a port mapping
	UnmapPort(protocol string, intPort, extPort uint16) error
	// Return our external IP
	ExternalIP() (net.IP, error)
}

Router describes the functionality that a network device must support to be able to open ports to an external IP.

func GetRouter

func GetRouter() Router

GetRouter returns a router on the current network.

func NewNoRouter

func NewNoRouter() Router

NewNoRouter returns a router that assumes the network is public

Jump to

Keyboard shortcuts

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