package autonatv2

import "github.com/libp2p/go-libp2p/p2p/protocol/autonatv2"

Index

Constants

const (
	ServiceName      = "libp2p.autonatv2"
	DialBackProtocol = "/libp2p/autonat/2/dial-back"
	DialProtocol     = "/libp2p/autonat/2/dial-request"
)

Variables

var (
	ErrNoValidPeers = errors.New("no valid peers for autonat v2")
	ErrDialRefused  = errors.New("dial refused")
)

Types

type AutoNAT

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

AutoNAT implements the AutoNAT v2 client and server. Users can check reachability for their addresses using the CheckReachability method. The server provides amplification attack prevention and rate limiting.

func New

func New(host host.Host, dialerHost host.Host, opts ...AutoNATOption) (*AutoNAT, error)

New returns a new AutoNAT instance. host and dialerHost should have the same dialing capabilities. In case the host doesn't support a transport, dial back requests for address for that transport will be ignored.

func (*AutoNAT) Close

func (an *AutoNAT) Close()

func (*AutoNAT) GetReachability

func (an *AutoNAT) GetReachability(ctx context.Context, reqs []Request) (Result, error)

GetReachability makes a single dial request for checking reachability for requested addresses

func (*AutoNAT) Start

func (an *AutoNAT) Start() error

type AutoNATOption

type AutoNATOption func(s *autoNATSettings) error

func WithMetricsTracer

func WithMetricsTracer(m MetricsTracer) AutoNATOption

func WithServerRateLimit

func WithServerRateLimit(rpm, perPeerRPM, dialDataRPM int, maxConcurrentRequestsPerPeer int) AutoNATOption

type EventDialRequestCompleted

type EventDialRequestCompleted struct {
	Error            error
	ResponseStatus   pb.DialResponse_ResponseStatus
	DialStatus       pb.DialStatus
	DialDataRequired bool
	DialedAddr       ma.Multiaddr
}

type MetricsTracer

type MetricsTracer interface {
	CompletedRequest(EventDialRequestCompleted)
}

func NewMetricsTracer

func NewMetricsTracer(reg prometheus.Registerer) MetricsTracer

type Request

type Request struct {
	// Addr is the multiaddr to verify
	Addr ma.Multiaddr
	// SendDialData indicates whether to send dial data if the server requests it for Addr
	SendDialData bool
}

Request is the request to verify reachability of a single address

type Result

type Result struct {
	// Addr is the dialed address
	Addr ma.Multiaddr
	// Reachability of the dialed address
	Reachability network.Reachability
	// Status is the outcome of the dialback
	Status pb.DialStatus
}

Result is the result of the CheckReachability call

Source Files

autonat.go client.go metrics.go msg_reader.go options.go server.go

Directories

PathSynopsis
p2p/protocol/autonatv2/pb
Version
v0.41.1 (latest)
Published
Mar 24, 2025
Platform
linux/amd64
Imports
25 packages
Last checked
3 weeks ago

Tools for package owners.