autonatv2

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

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

Variables

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

Functions

This section is empty.

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) 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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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