relay

package
v0.0.0-...-c6f7f91 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceName = "libp2p.relay/v2"

	ReservationTagWeight = 10

	StreamTimeout    = time.Minute
	ConnectTimeout   = 30 * time.Second
	HandshakeTimeout = time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ACLFilter

type ACLFilter interface {
	// AllowReserve returns true if a reservation from a peer with the given peer ID and multiaddr
	// is allowed.
	AllowReserve(p peer.ID, a ma.Multiaddr) bool
	// AllowConnect returns true if a source peer, with a given multiaddr is allowed to connect
	// to a destination peer.
	AllowConnect(src peer.ID, srcAddr ma.Multiaddr, dest peer.ID) bool
}

ACLFilter is an Access Control mechanism for relayed connect.

type MetricsTracer

type MetricsTracer interface {
	// RelayStatus tracks whether the service is currently active
	RelayStatus(enabled bool)

	// ConnectionOpened tracks metrics on opening a relay connection
	ConnectionOpened()
	// ConnectionClosed tracks metrics on closing a relay connection
	ConnectionClosed(d time.Duration)
	// ConnectionRequestHandled tracks metrics on handling a relay connection request
	ConnectionRequestHandled(status pbv2.Status)

	// ReservationAllowed tracks metrics on opening or renewing a relay reservation
	ReservationAllowed(isRenewal bool)
	// ReservationRequestClosed tracks metrics on closing a relay reservation
	ReservationClosed(cnt int)
	// ReservationRequestHandled tracks metrics on handling a relay reservation request
	ReservationRequestHandled(status pbv2.Status)

	// BytesTransferred tracks the total bytes transferred by the relay service
	BytesTransferred(cnt int)
}

MetricsTracer is the interface for tracking metrics for relay service

func NewMetricsTracer

func NewMetricsTracer(opts ...MetricsTracerOption) MetricsTracer

type MetricsTracerOption

type MetricsTracerOption func(*metricsTracerSetting)

type Option

type Option func(*Relay) error

func WithACL

func WithACL(acl ACLFilter) Option

WithACL is a Relay option that supplies an ACLFilter for access control.

func WithInfiniteLimits

func WithInfiniteLimits() Option

WithInfiniteLimits is a Relay option that disables limits.

func WithLimit

func WithLimit(limit *RelayLimit) Option

WithLimit is a Relay option that sets only the relayed connection limits for the relay.

func WithMetricsTracer

func WithMetricsTracer(mt MetricsTracer) Option

WithMetricsTracer is a Relay option that supplies a MetricsTracer for metrics

func WithResources

func WithResources(rc Resources) Option

WithResources is a Relay option that sets specific relay resources for the relay.

type Relay

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

Relay is the (limited) relay service object.

func New

func New(h host.Host, opts ...Option) (*Relay, error)

New constructs a new limited relay that can provide relay services in the given host.

func (*Relay) Close

func (r *Relay) Close() error

type RelayLimit

type RelayLimit struct {
	// Duration is the time limit before resetting a relayed connection; defaults to 2min.
	Duration time.Duration
	// Data is the limit of data relayed (on each direction) before resetting the connection.
	// Defaults to 128KB
	Data int64
}

RelayLimit are the per relayed connection resource limits.

func DefaultLimit

func DefaultLimit() *RelayLimit

DefaultLimit returns a RelayLimit object with the defaults filled in.

type Resources

type Resources struct {
	// Limit is the (optional) relayed connection limits.
	Limit *RelayLimit

	// ReservationTTL is the duration of a new (or refreshed reservation).
	// Defaults to 1hr.
	ReservationTTL time.Duration

	// MaxReservations is the maximum number of active relay slots; defaults to 128.
	MaxReservations int
	// MaxCircuits is the maximum number of open relay connections for each peer; defaults to 16.
	MaxCircuits int
	// BufferSize is the size of the relayed connection buffers; defaults to 2048.
	BufferSize int

	// MaxReservationsPerPeer is the maximum number of reservations originating from the same
	// peer; default is 4.
	MaxReservationsPerPeer int
	// MaxReservationsPerIP is the maximum number of reservations originating from the same
	// IP address; default is 8.
	MaxReservationsPerIP int
	// MaxReservationsPerASN is the maximum number of reservations origination from the same
	// ASN; default is 32
	MaxReservationsPerASN int
}

Resources are the resource limits associated with the relay service.

func DefaultResources

func DefaultResources() Resources

DefaultResources returns a Resources object with the default filled in.

Jump to

Keyboard shortcuts

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