nat

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package nat performs network address translation and provides helpers for routing ports.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mapper

type Mapper interface {
	MapPort(newInternalPort, newExternalPort uint16) error
	UnmapAllPorts() error
}

Mapper maps port

func NewDefaultMapper

func NewDefaultMapper(
	log logging.Logger,
	router Router,
	networkProtocol NetworkProtocol,
	mappingNames string,
) Mapper

NewDefaultMapper returns a new mapper that can map ports on a router with default settings

func NewMapper

func NewMapper(
	log logging.Logger,
	router Router,
	networkProtocol NetworkProtocol,
	mappingNames string,
	mappingTimeout time.Duration,
	mappingUpdateInterval time.Duration,
) Mapper

NewMapper returns a new mapper that can map ports on a router

type NetworkProtocol

type NetworkProtocol string

NetworkProtocol is a protocol that will be used through a port

const (
	TCP NetworkProtocol = "TCP"
	UDP NetworkProtocol = "UDP"
)

Available protocol

type Router

type Router interface {
	// mapPort creates a mapping between a port on the local computer to an
	// external port on the router.
	//
	// The mappingName is something displayed on the router, so it is included
	// for completeness.
	MapPort(
		networkProtocol NetworkProtocol,
		newInternalPort uint16,
		newExternalPort uint16,
		mappingName string,
		mappingDuration time.Duration) error

	// UnmapPort clears a mapping that was previous made by a call to MapPort
	UnmapPort(
		networkProtocol NetworkProtocol,
		internalPort uint16,
		externalPort uint16) error

	// Returns the routers IP address on the network the router considers
	// external
	IP() (net.IP, error)
}

Router provides a standard NAT router functions. Specifically, allowing the fetching of public IPs and port forwarding to this computer.

func NewRouter

func NewRouter() Router

NewRouter returns a new router discovered on the local network

Jump to

Keyboard shortcuts

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