natt

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: MIT Imports: 18 Imported by: 0

README

go-libp2p-natt

Documentation

Index

Constants

View Source
const CacheTime = time.Second * 15

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

View Source
const MappingDuration = time.Second * 60

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

Variables

View Source
var (
	//ErrShouldHaveIPAddress ...
	ErrShouldHaveIPAddress = errors.New("error machine should have an assigned IP address")
	//ErrNoNATDeviceFound ...
	ErrNoNATDeviceFound = errors.New("error no NAT devices found")
	//ErrCreatingHost ...
	ErrCreatingHost = errors.New("error creating host")
	//ErrCantUpdateBroadcastAddress ...
	ErrCantUpdateBroadcastAddress = errors.New("error cant update broadcast address")
	//ErrCantConnectToNATDiscoverAddress ...
	ErrCantConnectToNATDiscoverAddress = errors.New("error cant connect to NAT discover address")
	// ErrNoMapping signals no mapping exists for an address
	ErrNoMapping = errors.New("mapping not established")
	// ErrCantGetExternalAddress ...
	ErrCantGetExternalAddress = errors.New("error cant get external address")
)

Functions

func GetOutboundIP

func GetOutboundIP() net.IP

Get preferred outbound ip of this machine

Types

type Host

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

func CreateHost

func CreateHost(port int, NATdiscoverAddr string) (*Host, error)

func (*Host) GetBroadcastAddrInfo

func (h *Host) GetBroadcastAddrInfo() string

func (*Host) GetHost

func (h *Host) GetHost() host.Host

func (*Host) GetHostID

func (h *Host) GetHostID() peer.ID

func (*Host) GetInternalPort

func (h *Host) GetInternalPort() int

func (*Host) GetMapping added in v1.0.1

func (h *Host) GetMapping() Mapping

func (*Host) GetNATDevice added in v1.0.1

func (h *Host) GetNATDevice() *NAT

func (*Host) GetNATType

func (h *Host) GetNATType() network.Reachability

func (*Host) Quit

func (h *Host) Quit()

type Mapping added in v1.0.0

type Mapping interface {
	// NAT returns the NAT object this Mapping belongs to.
	NAT() *NAT

	// Protocol returns the protocol of this port mapping. This is either
	// "tcp" or "udp" as no other protocols are likely to be NAT-supported.
	Protocol() string

	// InternalPort returns the internal device port. Mapping will continue to
	// try to map InternalPort() to an external facing port.
	InternalPort() int

	// ExternalPort returns the external facing port. If the mapping is not
	// established, port will be 0
	ExternalPort() int

	// ExternalAddr returns the external facing address. If the mapping is not
	// established, addr will be nil, and and ErrNoMapping will be returned.
	ExternalAddr() (addr net.Addr, err error)

	// Close closes the port mapping
	Close() error
}

Mapping represents a port mapping in a NAT.

type NAT added in v1.0.0

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 added in v1.0.0

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) Close added in v1.0.0

func (nat *NAT) Close() error

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

func (*NAT) GetInternalAddress added in v1.0.0

func (nat *NAT) GetInternalAddress() (addr net.IP, err error)

func (*NAT) Mappings added in v1.0.0

func (nat *NAT) Mappings() []Mapping

Mappings returns a slice of all NAT mappings

func (*NAT) NewMapping added in v1.0.0

func (nat *NAT) NewMapping(protocol string, port int) (Mapping, error)

NewMapping attempts to construct a mapping on protocol and internal port It will also periodically renew the mapping until the returned Mapping -- or its parent NAT -- is Closed.

May not succeed, and mappings may change over time; NAT devices may not respect our port requests, and even lie. Clients should not store the mapped results, but rather always poll our object for the latest mappings.

func (*NAT) Process added in v1.0.0

func (nat *NAT) Process() goprocess.Process

Process returns the nat's life-cycle manager, for making it listen to close signals.

Jump to

Keyboard shortcuts

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