Version: v0.0.1 Latest Latest

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

Go to latest
Published: Jan 24, 2020 License: AGPL-3.0 Imports: 17 Imported by: 0



Package relay contains the components necessary to implement the "autorelay" feature.

Warning: the internal interfaces are unstable.

System Components: - A discovery service to discover public relays. - An AutoNAT client used to determine if the node is behind a NAT/firewall. - One or more autonat services, instances of `AutoNATServices`. These are used

by the autonat client.

- One or more relays, instances of `RelayHost`. - The AutoRelay service. This is the service that actually:

AutoNATService: AutoNAT:

How it works: - `AutoNATService` instances are instantiated in the bootstrappers (or other

well known publicly reachable hosts)

- `AutoRelay`s are constructed with `libp2p.New(libp2p.Routing(makeDHT))`

They passively discover autonat service instances and test dialability of
their listen address set through them.  When the presence of NAT is detected,
they discover relays through the DHT, connect to some of them and begin
advertising relay addresses.  The new set of addresses is propagated to
connected peers through the `identify/push` protocol.



View Source
const (
	// RelayRendezvous defines the dht rendezvous lookup key
	RelayRendezvous = "/libp2p/relay"


View Source
var (
	// DesiredRelays indicates the minimum number of desired relays
	DesiredRelays = 1

	// BootDelay defines the boot delay for our autorelay
	BootDelay = 20 * time.Second

	// DefaultRelays are the known PL-operated relays
	DefaultRelays = []string{
View Source
var (
	// AdvertiseBootDelay is purposefully long to require some node stability before advertising as a relay
	AdvertiseBootDelay = 15 * time.Minute
	// AdvertiseTTL is the timeout for advertisements
	AdvertiseTTL = 30 * time.Minute


func Advertise(ctx context.Context, advertise cdisc.Advertiser)

Advertise advertises this node as a libp2p relay.

func Filter

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

Filter filters out all relay addresses.


type AutoRelay

type AutoRelay struct {
	// contains filtered or unexported fields

AutoRelay is a Host that uses relays for connectivity when a NAT is detected.

func NewAutoRelay

func NewAutoRelay(ctx context.Context, logger *zap.Logger, bhost *basic.BasicHost, discover cdisc.Discoverer, router routing.PeerRouting, static []peer.AddrInfo) *AutoRelay

NewAutoRelay returns an initialized AutoRelay host

func (*AutoRelay) ClosedStream

func (ar *AutoRelay) ClosedStream(network.Network, network.Stream)

ClosedStream satisfies the network.Notifiee interface

func (*AutoRelay) Connected

func (ar *AutoRelay) Connected(network.Network, network.Conn)

Connected satisfies the network.Notifiee interface

func (*AutoRelay) Disconnected

func (ar *AutoRelay) Disconnected(net network.Network, c network.Conn)

Disconnected satisfies the network.Notifiee interface

func (*AutoRelay) Listen

func (ar *AutoRelay) Listen(network.Network, ma.Multiaddr)

Listen Disconnected satisfies the network.Notifiee interface

func (*AutoRelay) ListenClose

func (ar *AutoRelay) ListenClose(network.Network, ma.Multiaddr)

ListenClose satisfies the network.Notifiee interface

func (*AutoRelay) OpenedStream

func (ar *AutoRelay) OpenedStream(network.Network, network.Stream)

OpenedStream satisfies the network.Notifiee interface

Jump to

Keyboard shortcuts

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