Documentation ¶
Index ¶
- Constants
- func IsDialError(e error) bool
- func IsDialRefused(e error) bool
- type AddrFunc
- type AmbientAutoNAT
- func (as *AmbientAutoNAT) Close() error
- func (as *AmbientAutoNAT) Connected(net network.Network, c network.Conn)
- func (as *AmbientAutoNAT) Disconnected(net network.Network, c network.Conn)
- func (as *AmbientAutoNAT) Listen(net network.Network, a ma.Multiaddr)
- func (as *AmbientAutoNAT) ListenClose(net network.Network, a ma.Multiaddr)
- func (as *AmbientAutoNAT) Status() network.Reachability
- type AutoNAT
- type Client
- type Error
- type MetricsTracer
- type MetricsTracerOption
- type Option
- func EnableService(dialer network.Network) Option
- func UsingAddresses(addrFunc AddrFunc) Option
- func WithMetricsTracer(mt MetricsTracer) Option
- func WithPeerThrottling(amount int) Option
- func WithReachability(reachability network.Reachability) Option
- func WithSchedule(retryInterval, refreshInterval time.Duration) Option
- func WithThrottling(amount int, interval time.Duration) Option
- func WithoutStartupDelay() Option
- func WithoutThrottling() Option
- type StaticAutoNAT
Constants ¶
const AutoNATProto = "/libp2p/autonat/1.0.0"
AutoNATProto identifies the autonat service protocol
const (
ServiceName = "libp2p.autonat"
)
Variables ¶
This section is empty.
Functions ¶
func IsDialError ¶
IsDialError returns true if the AutoNAT peer signalled an error dialing back
func IsDialRefused ¶
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) Close ¶
func (as *AmbientAutoNAT) Close() error
func (*AmbientAutoNAT) Connected ¶
func (as *AmbientAutoNAT) Connected(net network.Network, c network.Conn)
Connected is part of the network.Notifiee interface
func (*AmbientAutoNAT) Disconnected ¶
func (as *AmbientAutoNAT) Disconnected(net network.Network, c network.Conn)
Disconnected is part of the network.Notifiee interface
func (*AmbientAutoNAT) Listen ¶
func (as *AmbientAutoNAT) Listen(net network.Network, a ma.Multiaddr)
Listen is part of the network.Notifiee interface
func (*AmbientAutoNAT) ListenClose ¶
func (as *AmbientAutoNAT) ListenClose(net network.Network, a ma.Multiaddr)
ListenClose is part of the network.Notifiee interface
func (*AmbientAutoNAT) Status ¶
func (as *AmbientAutoNAT) Status() network.Reachability
Status returns the AutoNAT observed reachability status.
type AutoNAT ¶
type AutoNAT interface { // Status returns the current NAT status Status() network.Reachability io.Closer }
AutoNAT is the interface for NAT autodiscovery
type Client ¶
type Client 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) error }
Client is a stateless client interface to AutoNAT peers
func NewAutoNATClient ¶
func NewAutoNATClient(h host.Host, addrFunc AddrFunc, mt MetricsTracer) Client
NewAutoNATClient creates a fresh instance of an AutoNATClient If addrFunc is nil, h.Addrs will be used
type Error ¶
type Error struct { Status pb.Message_ResponseStatus Text string }
Error wraps errors signalled by AutoNAT services
func (Error) IsDialError ¶
IsDialError returns true if the error was due to a dial back failure
func (Error) IsDialRefused ¶
IsDialRefused returns true if the error was due to a refusal to dial back
type MetricsTracer ¶ added in v0.26.0
type MetricsTracer interface { ReachabilityStatus(status network.Reachability) ReachabilityStatusConfidence(confidence int) ReceivedDialResponse(status pb.Message_ResponseStatus) OutgoingDialResponse(status pb.Message_ResponseStatus) OutgoingDialRefused(reason string) NextProbeTime(t time.Time) }
func NewMetricsTracer ¶ added in v0.26.0
func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer
type MetricsTracerOption ¶ added in v0.26.0
type MetricsTracerOption func(*metricsTracerSetting)
func WithRegisterer ¶ added in v0.26.0
func WithRegisterer(reg prometheus.Registerer) MetricsTracerOption
type Option ¶
type Option func(*config) error
Option is an Autonat option for configuration
func EnableService ¶
EnableService specifies that AutoNAT should be allowed to run a NAT service to help other peers determine their own NAT status. The provided Network should not be the default network/dialer of the host passed to `New`, as the NAT system will need to make parallel connections, and as such will modify both the associated peerstore and terminate connections of this dialer. The dialer provided should be compatible (TCP/UDP) however with the transports of the libp2p network.
func UsingAddresses ¶
UsingAddresses allows overriding which Addresses the AutoNAT client believes are "its own". Useful for testing, or for more exotic port-forwarding scenarios where the host may be listening on different ports than it wants to externally advertise or verify connectability on.
func WithMetricsTracer ¶ added in v0.26.0
func WithMetricsTracer(mt MetricsTracer) Option
WithMetricsTracer uses mt to track autonat metrics
func WithPeerThrottling ¶
WithPeerThrottling specifies a limit for the maximum number of IP checks this node will provide to an individual peer in each `interval`.
func WithReachability ¶
func WithReachability(reachability network.Reachability) Option
WithReachability overrides autonat to simply report an over-ridden reachability status.
func WithSchedule ¶
WithSchedule configures how aggressively probes will be made to verify the address of the host. retryInterval indicates how often probes should be made when the host lacks confidence about its address, while refreshInterval is the schedule of periodic probes when the host believes it knows its steady-state reachability.
func WithThrottling ¶
WithThrottling specifies how many peers (`amount`) it is willing to help ever `interval` amount of time when acting as a server.
func WithoutStartupDelay ¶
func WithoutStartupDelay() Option
WithoutStartupDelay removes the initial delay the NAT subsystem typically uses as a buffer for ensuring that connectivity and guesses as to the hosts local interfaces have settled down during startup.
func WithoutThrottling ¶
func WithoutThrottling() Option
WithoutThrottling indicates that this autonat service should not place restrictions on how many peers it is willing to help when acting as a server.
type StaticAutoNAT ¶
type StaticAutoNAT struct {
// contains filtered or unexported fields
}
StaticAutoNAT is a simple AutoNAT implementation when a single NAT status is desired.
func (*StaticAutoNAT) Close ¶
func (s *StaticAutoNAT) Close() error
func (*StaticAutoNAT) Status ¶
func (s *StaticAutoNAT) Status() network.Reachability
Status returns the AutoNAT observed reachability status.