nat

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2020 License: MIT Imports: 8 Imported by: 0

README

go-libp2p-nat

Travis CI Discourse posts

NAT port mapping library for go-libp2p.

Table of Contents

Install

make install

Usage

# TODO

Contribute

PRs are welcome! Feel free to join in. All welcome. Open an issue!

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to libp2p are subject to the IPFS Code of Conduct.

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson


The last gx published version of this module was: 0.8.13: QmRbx7DYHgw3uNn2RuU2nv9Bdh96ZdtT65CG1CGPNRQcGZ

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 DefaultTimeout = nat.DefaultTimeout

DefaultTimeout for discovering nat

View Source
var (
	// ErrNoMapping signals no mapping exists for an address
	ErrNoMapping = errors.New("mapping not established")
)

Functions

This section is empty.

Types

type Mapping

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

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, timeout time.Duration, logger *zap.Logger) (*NAT, error)

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

func (*NAT) Close

func (nat *NAT) Close() error

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

func (*NAT) Mappings

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

Mappings returns a slice of all NAT mappings

func (*NAT) NewMapping

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.

Jump to

Keyboard shortcuts

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