autorelay

package
v0.27.5 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2023 License: MIT Imports: 22 Imported by: 50

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter(addrs []ma.Multiaddr) []ma.Multiaddr

Filter filters out all relay addresses.

Types

type AutoRelay

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

func NewAutoRelay

func NewAutoRelay(bhost *basic.BasicHost, opts ...Option) (*AutoRelay, error)

func (*AutoRelay) Close

func (r *AutoRelay) Close() error

func (*AutoRelay) Start added in v0.26.0

func (r *AutoRelay) Start()

type AutoRelayHost

type AutoRelayHost struct {
	host.Host
	// contains filtered or unexported fields
}

func NewAutoRelayHost

func NewAutoRelayHost(h host.Host, ar *AutoRelay) *AutoRelayHost

func (*AutoRelayHost) Close

func (h *AutoRelayHost) Close() error

func (*AutoRelayHost) Start added in v0.26.0

func (h *AutoRelayHost) Start()

type ClockWithInstantTimer added in v0.26.4

type ClockWithInstantTimer interface {
	Now() time.Time
	Since(t time.Time) time.Duration
	InstantTimer(when time.Time) InstantTimer
}

ClockWithInstantTimer is a clock that can create timers that trigger at some instant rather than some duration

type InstantTimer added in v0.26.4

type InstantTimer interface {
	Reset(d time.Time) bool
	Stop() bool
	Ch() <-chan time.Time
}

InstantTimer is a timer that triggers at some instant rather than some duration

type MetricsTracer added in v0.27.0

type MetricsTracer interface {
	RelayFinderStatus(isActive bool)

	ReservationEnded(cnt int)
	ReservationOpened(cnt int)
	ReservationRequestFinished(isRefresh bool, err error)

	RelayAddressCount(int)
	RelayAddressUpdated()

	CandidateChecked(supportsCircuitV2 bool)
	CandidateAdded(cnt int)
	CandidateRemoved(cnt int)
	CandidateLoopState(state candidateLoopState)

	ScheduledWorkUpdated(scheduledWork *scheduledWorkTimes)

	DesiredReservations(int)
}

MetricsTracer is the interface for tracking metrics for autorelay

func NewMetricsTracer added in v0.27.0

func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer

type MetricsTracerOption added in v0.27.0

type MetricsTracerOption func(*metricsTracerSetting)

func WithRegisterer added in v0.27.0

func WithRegisterer(reg prometheus.Registerer) MetricsTracerOption

type Option

type Option func(*config) error

func WithBackoff added in v0.19.0

func WithBackoff(d time.Duration) Option

WithBackoff sets the time we wait after failing to obtain a reservation with a candidate.

func WithBootDelay added in v0.19.0

func WithBootDelay(d time.Duration) Option

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.

func WithClock added in v0.22.0

func WithClock(cl ClockWithInstantTimer) Option

func WithMaxCandidateAge added in v0.22.0

func WithMaxCandidateAge(d time.Duration) Option

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.

func WithMaxCandidates added in v0.19.0

func WithMaxCandidates(n int) Option

WithMaxCandidates sets the number of relay candidates that we buffer.

func WithMetricsTracer added in v0.27.0

func WithMetricsTracer(mt MetricsTracer) Option

WithMetricsTracer configures autorelay to use mt to track metrics

func WithMinCandidates added in v0.19.0

func WithMinCandidates(n int) Option

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.

func WithMinInterval added in v0.25.0

func WithMinInterval(interval time.Duration) Option

WithMinInterval sets the minimum interval after which peerSource callback will be called for more candidates even if AutoRelay needs new candidates.

func WithNumRelays added in v0.19.0

func WithNumRelays(n int) Option

WithNumRelays sets the number of relays we strive to obtain reservations with.

func WithPeerSource added in v0.19.0

func WithPeerSource(f PeerSource) Option

WithPeerSource defines a callback for AutoRelay to query for more relay candidates.

func WithStaticRelays

func WithStaticRelays(static []peer.AddrInfo) Option

type PeerSource added in v0.25.0

type PeerSource func(ctx context.Context, num int) <-chan peer.AddrInfo

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.

type RealClock added in v0.26.4

type RealClock struct{}

func (RealClock) InstantTimer added in v0.26.4

func (RealClock) InstantTimer(when time.Time) InstantTimer

func (RealClock) Now added in v0.26.4

func (RealClock) Now() time.Time

func (RealClock) Since added in v0.26.4

func (RealClock) Since(t time.Time) time.Duration

type RealTimer added in v0.26.4

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

func (RealTimer) Ch added in v0.26.4

func (t RealTimer) Ch() <-chan time.Time

func (RealTimer) Reset added in v0.26.4

func (t RealTimer) Reset(d time.Time) bool

func (RealTimer) Stop added in v0.26.4

func (t RealTimer) Stop() bool

Jump to

Keyboard shortcuts

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