Documentation ¶
Index ¶
- Constants
- func SetParameters(param Parameters)
- type Events
- type Option
- type Parameters
- type PeerDeletedEvent
- type PeerDiscoveredEvent
- type Protocol
- func (p *Protocol) Close()
- func (p *Protocol) DiscoveryRequest(to *peer.Peer) ([]*peer.Peer, error)
- func (p *Protocol) EnsureVerified(peer *peer.Peer) error
- func (p *Protocol) Events() *Events
- func (p *Protocol) GetMasterPeers() []*peer.Peer
- func (p *Protocol) GetVerifiedPeer(id identity.ID) *peer.Peer
- func (p *Protocol) GetVerifiedPeers() []*peer.Peer
- func (p *Protocol) HandleMessage(s *server.Server, fromAddr *net.UDPAddr, from *identity.Identity, data []byte) (bool, error)
- func (p *Protocol) IsVerified(id identity.ID, ip net.IP) bool
- func (p *Protocol) Ping(to *peer.Peer) error
- func (p *Protocol) Start(s server.Sender)
Constants ¶
const ( DefaultReverifyInterval = 10 * time.Second DefaultQueryInterval = 60 * time.Second DefaultMaxManaged = 1000 DefaultMaxReplacements = 10 )
Default values for the global parameters.
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.Event1[*PeerDiscoveredEvent] // A PeerDeleted event is triggered, when a discovered and verified peer could not be re-verified. PeerDeleted *event.Event1[*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 MasterPeers ¶
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 ¶
PeerDeletedEvent bundles the information of the deleted peer.
type PeerDiscoveredEvent ¶
PeerDiscoveredEvent bundles the information of the discovered peer.
type Protocol ¶
The Protocol handles the peer discovery. It responds to incoming messages and sends own requests when needed.
func New ¶
New creates a new discovery protocol for the local node with the given protocol version and networkID.
func (*Protocol) DiscoveryRequest ¶
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 ¶
EnsureVerified checks if the given peer has recently sent a Ping; if not, we send a Ping to trigger a verification.
func (*Protocol) Events ¶
Events returns all the events that are triggered during the peer discovery.
func (*Protocol) GetMasterPeers ¶
GetMasterPeers returns the list of master peers.
func (*Protocol) GetVerifiedPeer ¶
GetVerifiedPeer returns the verified peer with the given ID, or nil if no such peer exists.
func (*Protocol) GetVerifiedPeers ¶
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 ¶
IsVerified checks whether the given peer has recently been verified a recent enough endpoint proof.