discovery

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2025 License: Apache-2.0, UNKNOWN not legal advice Imports: 0 Imported by: 0

Documentation

Overview

Package discovery contains the p2p peer discovery service (Reactor). The purpose of the peer discovery service is to gather peer lists from known peers, and attempt to fill out open peer connection slots in order to build out a fuller mesh.

The implementation of the peer discovery protocol is relatively simple. In essence, it pings a random peer at a specific interval (3s), for a list of their known peers (max 30). After receiving the list, and verifying it, the node attempts to establish outbound connections to the given peers.

Index

Constants

View Source
const (
	// Channel is the unique channel for the peer discovery protocol
	Channel = byte(0x50)
)

Variables

View Source
var Package = amino.RegisterPackage(amino.NewPackage(
	"github.com/gnolang/gno/tm2/pkg/p2p/discovery",
	"p2p",
	amino.GetCallersDirname(),
).
	WithTypes(
		&Request{},
		&Response{},
	),
)

Functions

This section is empty.

Types

type Message

type Message interface {
	ValidateBasic() error
}

Message is the wrapper for the discovery message

type Option

type Option func(*Reactor)

func WithDiscoveryInterval

func WithDiscoveryInterval(interval time.Duration) Option

WithDiscoveryInterval sets the discovery crawl interval

type Reactor

type Reactor struct {
	// This embed and the usage of "services"
	// like the peer discovery reactor highlight the
	// flipped design of the p2p package.
	// The peer exchange service needs to be instantiated _outside_
	// the p2p module, because of this flipped design.
	// Peers communicate with each other through Reactor channels,
	// which are instantiated outside the p2p module
	p2p.BaseReactor
	// contains filtered or unexported fields
}

Reactor wraps the logic for the peer exchange protocol

func NewReactor

func NewReactor(opts ...Option) *Reactor

NewReactor creates a new peer discovery reactor

func (*Reactor) GetChannels

func (r *Reactor) GetChannels() []*conn.ChannelDescriptor

GetChannels returns the channels associated with peer discovery

func (*Reactor) OnStart

func (r *Reactor) OnStart() error

OnStart runs the peer discovery protocol

func (*Reactor) OnStop

func (r *Reactor) OnStop()

OnStop stops the peer discovery protocol

func (*Reactor) Receive

func (r *Reactor) Receive(chID byte, peer p2p.PeerConn, msgBytes []byte)

Receive handles incoming messages for the peer discovery reactor

type Request

type Request struct{}

Request is the peer discovery request. It is empty by design, since it's used as a notification type

func (*Request) ValidateBasic

func (r *Request) ValidateBasic() error

type Response

type Response struct {
	Peers []*types.NetAddress // the peer set returned by the peer
}

Response is the peer discovery response

func (*Response) ValidateBasic

func (r *Response) ValidateBasic() error

Jump to

Keyboard shortcuts

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