autonat

package
v0.0.0-...-ce94876 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2019 License: MIT, MIT Imports: 14 Imported by: 0

README

go-libp2p-autonat

standard-readme compliant

Ambient NAT discovery

This package provides an ambient NAT autodiscovery service. It allows peers to figure out their NAT dialability situation by using test dial backs through peers providing the AutoNAT service.

Documentation

See https://godoc.org/github.com/libp2p/go-libp2p-autonat

Contribute

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

This repository falls under the IPFS Code of Conduct.

License

MIT

Documentation

Index

Constants

View Source
const AutoNATProto = "/libp2p/autonat/1.0.0"

Variables

View Source
var (
	AutoNATBootDelay       = 15 * time.Second
	AutoNATRetryInterval   = 90 * time.Second
	AutoNATRefreshInterval = 15 * time.Minute
	AutoNATRequestTimeout  = 60 * time.Second
)
View Source
var AutoNATIdentifyDelay = 5 * time.Second

Functions

func IsDialError

func IsDialError(e error) bool

IsDialError returns true if the AutoNAT peer signalled an error dialing back

func IsDialRefused

func IsDialRefused(e error) bool

IsDialRefused returns true if the AutoNAT peer signalled refusal to dial back

Types

type AmbientAutoNAT

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

AmbientAutoNAT is the implementation of ambient NAT autodiscovery

func (*AmbientAutoNAT) ClosedStream

func (as *AmbientAutoNAT) ClosedStream(net inet.Network, s inet.Stream)

func (*AmbientAutoNAT) Connected

func (as *AmbientAutoNAT) Connected(net inet.Network, c inet.Conn)

func (*AmbientAutoNAT) Disconnected

func (as *AmbientAutoNAT) Disconnected(net inet.Network, c inet.Conn)

func (*AmbientAutoNAT) Listen

func (as *AmbientAutoNAT) Listen(net inet.Network, a ma.Multiaddr)

func (*AmbientAutoNAT) ListenClose

func (as *AmbientAutoNAT) ListenClose(net inet.Network, a ma.Multiaddr)

func (*AmbientAutoNAT) OpenedStream

func (as *AmbientAutoNAT) OpenedStream(net inet.Network, s inet.Stream)

func (*AmbientAutoNAT) PublicAddr

func (as *AmbientAutoNAT) PublicAddr() (ma.Multiaddr, error)

func (*AmbientAutoNAT) Status

func (as *AmbientAutoNAT) Status() NATStatus

type AutoNAT

type AutoNAT interface {
	// Status returns the current NAT status
	Status() NATStatus
	// PublicAddr returns the public dial address when NAT status is public and an
	// error otherwise
	PublicAddr() (ma.Multiaddr, error)
}

AutoNAT is the interface for ambient NAT autodiscovery

func NewAutoNAT

func NewAutoNAT(ctx context.Context, h host.Host, getAddrs GetAddrs) AutoNAT

NewAutoNAT creates a new ambient NAT autodiscovery instance attached to a host If getAddrs is nil, h.Addrs will be used

type AutoNATClient

type AutoNATClient interface {
	// DialBack requests from a peer providing AutoNAT services to test dial back
	// and report the address on a successful connection.
	DialBack(ctx context.Context, p peer.ID) (ma.Multiaddr, error)
}

AutoNATClient is a stateless client interface to AutoNAT peers

func NewAutoNATClient

func NewAutoNATClient(h host.Host, getAddrs GetAddrs) AutoNATClient

NewAutoNATClient creates a fresh instance of an AutoNATClient If getAddrs is nil, h.Addrs will be used

type AutoNATError

type AutoNATError struct {
	Status pb.Message_ResponseStatus
	Text   string
}

AutoNATError is the class of errors signalled by AutoNAT services

func (AutoNATError) Error

func (e AutoNATError) Error() string

func (AutoNATError) IsDialError

func (e AutoNATError) IsDialError() bool

func (AutoNATError) IsDialRefused

func (e AutoNATError) IsDialRefused() bool

type GetAddrs

type GetAddrs func() []ma.Multiaddr

GetAddrs is a function that returns the addresses to dial back

type NATStatus

type NATStatus int

NATStatus is the state of NAT as detected by the ambient service.

const (
	// NAT status is unknown; this means that the ambient service has not been
	// able to decide the presence of NAT in the most recent attempt to test
	// dial through known autonat peers.  initial state.
	NATStatusUnknown NATStatus = iota
	// NAT status is publicly dialable
	NATStatusPublic
	// NAT status is private network
	NATStatusPrivate
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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