package autorelay

Import Path
	github.com/libp2p/go-libp2p/p2p/host/autorelay (on go.dev)

Dependency Relation
	imports 24 packages, and imported by 2 packages


Package-Level Type Names (total 9)
/* sort by: | */
(*AutoRelay) Close() error (*AutoRelay) Start() *AutoRelay : github.com/prometheus/common/expfmt.Closer *AutoRelay : io.Closer func NewAutoRelay(host host.Host, opts ...Option) (*AutoRelay, error)
ClockWithInstantTimer is a clock that can create timers that trigger at some instant rather than some duration ( ClockWithInstantTimer) InstantTimer(when time.Time) InstantTimer ( ClockWithInstantTimer) Now() time.Time ( ClockWithInstantTimer) Since(t time.Time) time.Duration RealClock ClockWithInstantTimer : github.com/hibiken/asynq/internal/timeutil.Clock ClockWithInstantTimer : github.com/pion/stun.Clock ClockWithInstantTimer : github.com/pion/stun/v3.Clock ClockWithInstantTimer : github.com/quic-go/quic-go/internal/congestion.Clock ClockWithInstantTimer : go.uber.org/dig/internal/digclock.Clock func WithClock(cl ClockWithInstantTimer) Option
InstantTimer is a timer that triggers at some instant rather than some duration ( InstantTimer) Ch() <-chan time.Time ( InstantTimer) Reset(d time.Time) bool ( InstantTimer) Stop() bool RealTimer github.com/libp2p/go-libp2p/p2p/net/swarm.InstantTimer (interface) github.com/libp2p/go-libp2p/p2p/net/swarm.RealTimer InstantTimer : github.com/libp2p/go-libp2p/p2p/net/swarm.InstantTimer InstantTimer : google.golang.org/grpc/internal.Timer func ClockWithInstantTimer.InstantTimer(when time.Time) InstantTimer func RealClock.InstantTimer(when time.Time) InstantTimer
MetricsTracer is the interface for tracking metrics for autorelay ( MetricsTracer) CandidateAdded(cnt int) ( MetricsTracer) CandidateChecked(supportsCircuitV2 bool) ( MetricsTracer) CandidateLoopState(state candidateLoopState) ( MetricsTracer) CandidateRemoved(cnt int) ( MetricsTracer) DesiredReservations(int) ( MetricsTracer) RelayAddressCount(int) ( MetricsTracer) RelayAddressUpdated() ( MetricsTracer) RelayFinderStatus(isActive bool) ( MetricsTracer) ReservationEnded(cnt int) ( MetricsTracer) ReservationOpened(cnt int) ( MetricsTracer) ReservationRequestFinished(isRefresh bool, err error) ( MetricsTracer) ScheduledWorkUpdated(scheduledWork *scheduledWorkTimes) func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer func WithMetricsTracer(mt MetricsTracer) Option
func WithRegisterer(reg prometheus.Registerer) MetricsTracerOption func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer
func WithBackoff(d time.Duration) Option func WithBootDelay(d time.Duration) Option func WithClock(cl ClockWithInstantTimer) Option func WithMaxCandidateAge(d time.Duration) Option func WithMaxCandidates(n int) Option func WithMetricsTracer(mt MetricsTracer) Option func WithMinCandidates(n int) Option func WithMinInterval(interval time.Duration) Option func WithNumRelays(n int) Option func WithPeerSource(f PeerSource) Option func WithStaticRelays(static []peer.AddrInfo) Option func NewAutoRelay(host host.Host, opts ...Option) (*AutoRelay, error) func github.com/libp2p/go-libp2p.EnableAutoRelay(opts ...Option) libp2p.Option func github.com/libp2p/go-libp2p.EnableAutoRelayWithPeerSource(peerSource PeerSource, opts ...Option) libp2p.Option func github.com/libp2p/go-libp2p.EnableAutoRelayWithStaticRelays(static []peer.AddrInfo, opts ...Option) libp2p.Option
AutoRelay will call this function when it needs new candidates because it is not connected to the desired number of relays or we get disconnected from one of the relays. Implementations must send *at most* numPeers, and close the channel when they don't intend to provide any more peers. AutoRelay will not call the callback again until the channel is closed. Implementations should send new peers, but may send peers they sent before. AutoRelay implements a per-peer backoff (see WithBackoff). See WithMinInterval for setting the minimum interval between calls to the callback. The context.Context passed may be canceled when AutoRelay feels satisfied, it will be canceled when the node is shutting down. If the context is canceled you MUST close the output channel at some point. func WithPeerSource(f PeerSource) Option func github.com/libp2p/go-libp2p.EnableAutoRelayWithPeerSource(peerSource PeerSource, opts ...Option) libp2p.Option
( RealClock) InstantTimer(when time.Time) InstantTimer ( RealClock) Now() time.Time ( RealClock) Since(t time.Time) time.Duration RealClock : ClockWithInstantTimer RealClock : github.com/hibiken/asynq/internal/timeutil.Clock RealClock : github.com/pion/stun.Clock RealClock : github.com/pion/stun/v3.Clock RealClock : github.com/quic-go/quic-go/internal/congestion.Clock RealClock : go.uber.org/dig/internal/digclock.Clock
( RealTimer) Ch() <-chan time.Time ( RealTimer) Reset(d time.Time) bool ( RealTimer) Stop() bool RealTimer : InstantTimer RealTimer : github.com/libp2p/go-libp2p/p2p/net/swarm.InstantTimer RealTimer : google.golang.org/grpc/internal.Timer
Package-Level Functions (total 14)
func NewAutoRelay(host host.Host, opts ...Option) (*AutoRelay, error)
WithBackoff sets the time we wait after failing to obtain a reservation with a candidate.
WithBootDelay set the boot delay for finding relays. We won't attempt any reservation if we've have less than a minimum number of candidates. This prevents us to connect to the "first best" relay, and allows us to carefully select the relay. However, in case we haven't found enough relays after the boot delay, we use what we have.
WithMaxCandidateAge sets the maximum age of a candidate. When we are connected to the desired number of relays, we don't ask the peer source for new candidates. This can lead to AutoRelay's candidate list becoming outdated, and means we won't be able to quickly establish a new relay connection if our existing connection breaks, if all the candidates have become stale.
WithMaxCandidates sets the number of relay candidates that we buffer.
WithMetricsTracer configures autorelay to use mt to track metrics
WithMinCandidates sets the minimum number of relay candidates we collect before to get a reservation with any of them (unless we've been running for longer than the boot delay). This is to make sure that we don't just randomly connect to the first candidate that we discover.
WithMinInterval sets the minimum interval after which peerSource callback will be called for more candidates even if AutoRelay needs new candidates.
WithNumRelays sets the number of relays we strive to obtain reservations with.
WithPeerSource defines a callback for AutoRelay to query for more relay candidates.