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 ¶
const ( // Channel is the unique channel for the peer discovery protocol Channel = byte(0x50) )
Variables ¶
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 ¶
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 ¶
NewReactor creates a new peer discovery reactor. The store is used to persist discovered peers across restarts.
func (*Reactor) GetChannels ¶
func (r *Reactor) GetChannels() []*conn.ChannelDescriptor
GetChannels returns the channels associated with peer discovery
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 ¶
type Response ¶
type Response struct {
Peers []*types.NetAddress // the peer set returned by the peer
}
Response is the peer discovery response
func (*Response) ValidateBasic ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists discovered peer addresses to disk so they survive node restarts. It is safe for concurrent use.
func NewStore ¶
func NewStore(filePath string, self types.NetAddress, opts ...StoreOption) (*Store, error)
NewStore creates a new peer store backed by the given file path. self is the node's own address and is never stored. Existing peers are loaded from disk on construction.
func (*Store) AddPeers ¶
func (s *Store) AddPeers(addrs ...*types.NetAddress)
AddPeers adds the given peer addresses to the store. The node's own address is ignored, as are nil entries. When the store exceeds its capacity, the oldest entries are evicted.
func (*Store) GetPeers ¶
func (s *Store) GetPeers() []*types.NetAddress
GetPeers returns all stored peer addresses.
type StoreOption ¶
type StoreOption func(*Store)
StoreOption configures the peer Store.
func WithLogger ¶
func WithLogger(logger *slog.Logger) StoreOption
WithLogger sets the store logger.
func WithMaxPeers ¶
func WithMaxPeers(maxPeers int) StoreOption
WithMaxPeers sets the maximum number of peers the store keeps. When the limit is reached, the oldest entries are evicted.