pex

package
v1.1.0-dev.1 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package PEX (Peer exchange) handles all the logic necessary for nodes to share information about their peers to other nodes. Specifically, this is the exchange of addresses that a peer can use to discover more peers within the network.

The PEX reactor is a continuous service which periodically requests addresses and serves addresses to other peers. There are two versions of this service aligning with the two p2p frameworks that Tendermint currently supports.

The reactor is embedded with the new p2p stack and uses the peer manager to advertise peers as well as add new peers to the peer store. The V2 reactor passes a different set of proto messages which include a list of [urls](https://golang.org/pkg/net/url/#URL).These can be used to save a set of endpoints that each peer uses. The V2 reactor has backwards compatibility with V1. It can also handle V1 messages.

The reactor is able to tweak the intensity of it's search by decreasing or increasing the interval between each request. It tracks connected peers via a linked list, sending a request to the node at the front of the list and adding it to the back of the list once a response is received. Using this method, a node is able to spread out the load of requesting peers across all the peers it is currently connected with.

With each inbound set of addresses, the reactor monitors the amount of new addresses to already seen addresses and uses the information to dynamically build a picture of the size of the network in order to ascertain how often the node needs to search for new peers.

Index

Constants

View Source
const (
	// PexChannel is a channel for PEX messages
	PexChannel = 0x00
)

Variables

This section is empty.

Functions

func ChannelDescriptor

func ChannelDescriptor() *conn.ChannelDescriptor

TODO: We should decide whether we want channel descriptors to be housed within each reactor (as they are now) or, considering that the reactor doesn't really need to care about the channel descriptors, if they should be housed in the node module.

Types

type Reactor

type Reactor struct {
	service.BaseService
	// contains filtered or unexported fields
}

The peer exchange or PEX reactor supports the peer manager by sending requests to other peers for addresses that can be given to the peer manager and at the same time advertises addresses to peers that need more.

The reactor is able to tweak the intensity of it's search by decreasing or increasing the interval between each request. It tracks connected peers via a linked list, sending a request to the node at the front of the list and adding it to the back of the list once a response is received.

func NewReactor

func NewReactor(
	logger log.Logger,
	peerManager *p2p.PeerManager,
	channelCreator p2p.ChannelCreator,
	peerEvents p2p.PeerEventSubscriber,
) *Reactor

NewReactor returns a reference to a new reactor.

func (*Reactor) OnStart

func (r *Reactor) OnStart(ctx context.Context) error

OnStart starts separate go routines for each p2p Channel and listens for envelopes on each. In addition, it also listens for peer updates and handles messages on that p2p channel accordingly. The caller must be sure to execute OnStop to ensure the outbound p2p Channels are closed.

func (*Reactor) OnStop

func (r *Reactor) OnStop()

OnStop stops the reactor by signaling to all spawned goroutines to exit and blocking until they all exit.

Jump to

Keyboard shortcuts

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