autonat

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0, MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

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

AutoNATProto is the libp2p autonat protocol name

Variables

View Source
var (
	// AutoNATBootDelay defines the boot delay
	AutoNATBootDelay = 15 * time.Second
	// AutoNATRetryInterval defines the retry interval
	AutoNATRetryInterval = 90 * time.Second
	// AutoNATRefreshInterval defines the refresh interval
	AutoNATRefreshInterval = 15 * time.Minute
	// AutoNATRequestTimeout defines the request timeout
	AutoNATRequestTimeout = 30 * time.Second
)
View Source
var AutoNATIdentifyDelay = 5 * time.Second

AutoNATIdentifyDelay is the default delay before running autonat identification

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 network.Network, s network.Stream)

ClosedStream satisfies the network.Notifiee interface

func (*AmbientAutoNAT) Connected

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

Connected satisfies the network.Notifiee interface

func (*AmbientAutoNAT) Disconnected

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

Disconnected satisfies the network.Notifiee interface

func (*AmbientAutoNAT) Listen

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

Listen satisfies the network.Notifiee interface

func (*AmbientAutoNAT) ListenClose

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

ListenClose satisfies the network.Notifiee interface

func (*AmbientAutoNAT) OpenedStream

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

OpenedStream satisfies the network.Notifiee interface

func (*AmbientAutoNAT) PublicAddr

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

PublicAddr returns the publicly accessibel address for this autonat instance

func (*AmbientAutoNAT) Status

func (as *AmbientAutoNAT) Status() NATStatus

Status returns the autonat status

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, logger *zap.Logger, 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 Error

type Error struct {
	Status pb.Message_ResponseStatus
	Text   string
}

Error is the class of errors signalled by AutoNAT services

func (Error) Error

func (e Error) Error() string

func (Error) IsDialError

func (e Error) IsDialError() bool

IsDialError returns whether or not the error is a dial error

func (Error) IsDialRefused

func (e Error) IsDialRefused() bool

IsDialRefused returns whether or not the error is a dial refused error

type GetAddrs

type GetAddrs func() []ma.Multiaddr

GetAddrs is a function that returns the addresses to dial back

type NATClient

type NATClient 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)
}

NATClient is a stateless client interface to AutoNAT peers

func NewAutoNATClient

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

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

type NATStatus

type NATStatus int

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

const (
	// NATStatusUnknown 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
	// NATStatusPublic indicates the peer is on a publicly accessible network
	NATStatusPublic
	// NATStatusPrivate indicates the peer is not on a publicly accessible network
	NATStatusPrivate
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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