discover

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2023 License: Apache-2.0, BSD-2-Clause Imports: 22 Imported by: 5

Documentation

Index

Constants

View Source
const (
	DefaultReverifyInterval = 10 * time.Second
	DefaultQueryInterval    = 60 * time.Second
	DefaultMaxManaged       = 1000
	DefaultMaxReplacements  = 10
)

Default values for the global parameters.

View Source
const (
	// PingExpiration is the time until a peer verification expires.
	PingExpiration = 12 * time.Hour
	// MaxPeersInResponse is the maximum number of peers returned in DiscoveryResponse.
	MaxPeersInResponse = 6
	// MaxServices is the maximum number of services a peer can support.
	MaxServices = 5
)

Variables

This section is empty.

Functions

func SetParameters

func SetParameters(param Parameters)

SetParameters sets the global parameters for this package. This function cannot be used concurrently.

Types

type Events

type Events struct {
	// A PeerDiscovered event is triggered, when a new peer has been discovered and verified.
	PeerDiscovered *event.Event[*PeerDiscoveredEvent]
	// A PeerDeleted event is triggered, when a discovered and verified peer could not be re-verified.
	PeerDeleted *event.Event[*PeerDeletedEvent]
}

Events contains all the events that are triggered during the peer discovery.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option modifies discovery related settings.

func Logger

func Logger(log *logger.Logger) Option

Logger sets the logger.

func MasterPeers

func MasterPeers(masterPeers []*peer.Peer) Option

MasterPeers sets the masterPeers to use.

type Parameters

type Parameters struct {
	ReverifyInterval time.Duration // time interval after which the next peer is reverified
	QueryInterval    time.Duration // time interval after which peers are queried for new peers
	MaxManaged       int           // maximum number of peers that can be managed
	MaxReplacements  int           // maximum number of peers kept in the replacement list
}

Parameters holds the parameters that can be configured.

type PeerDeletedEvent

type PeerDeletedEvent struct {
	Peer *peer.Peer // deleted peer
}

PeerDeletedEvent bundles the information of the deleted peer.

type PeerDiscoveredEvent

type PeerDiscoveredEvent struct {
	Peer *peer.Peer // discovered peer
}

PeerDiscoveredEvent bundles the information of the discovered peer.

type Protocol

type Protocol struct {
	server.Protocol
	// contains filtered or unexported fields
}

The Protocol handles the peer discovery. It responds to incoming messages and sends own requests when needed.

func New

func New(local *peer.Local, version uint32, networkID uint32, opts ...Option) *Protocol

New creates a new discovery protocol for the local node with the given protocol version and networkID.

func (*Protocol) Close

func (p *Protocol) Close()

Close finalizes the protocol.

func (*Protocol) DiscoveryRequest

func (p *Protocol) DiscoveryRequest(to *peer.Peer) ([]*peer.Peer, error)

DiscoveryRequest request known peers from the given target. This method blocks until a response is received and the provided peers are returned.

func (*Protocol) EnsureVerified

func (p *Protocol) EnsureVerified(peer *peer.Peer) error

EnsureVerified checks if the given peer has recently sent a Ping; if not, we send a Ping to trigger a verification.

func (*Protocol) Events

func (p *Protocol) Events() *Events

Events returns all the events that are triggered during the peer discovery.

func (*Protocol) GetMasterPeers

func (p *Protocol) GetMasterPeers() []*peer.Peer

GetMasterPeers returns the list of master peers.

func (*Protocol) GetVerifiedPeer

func (p *Protocol) GetVerifiedPeer(id identity.ID) *peer.Peer

GetVerifiedPeer returns the verified peer with the given ID, or nil if no such peer exists.

func (*Protocol) GetVerifiedPeers

func (p *Protocol) GetVerifiedPeers() []*peer.Peer

GetVerifiedPeers returns all the currently managed peers that have been verified at least once.

func (*Protocol) HandleMessage

func (p *Protocol) HandleMessage(s *server.Server, fromAddr *net.UDPAddr, from *identity.Identity, data []byte) (bool, error)

HandleMessage responds to incoming peer discovery messages.

func (*Protocol) IsVerified

func (p *Protocol) IsVerified(id identity.ID, ip net.IP) bool

IsVerified checks whether the given peer has recently been verified a recent enough endpoint proof.

func (*Protocol) Ping

func (p *Protocol) Ping(to *peer.Peer) error

Ping sends a Ping to the specified peer and blocks until a reply is received or timeout.

func (*Protocol) Start

func (p *Protocol) Start(s server.Sender)

Start starts the actual peer discovery over the provided Sender.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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