Documentation ¶
Index ¶
- Constants
- func SetParameters(param Parameters)
- type DiscoverProtocol
- type DroppedEvent
- type Events
- type Filter
- type Neighborhood
- func (nh *Neighborhood) Add(toAdd peer.PeerDistance) bool
- func (nh *Neighborhood) GetNumPeers() int
- func (nh *Neighborhood) GetPeers() []*peer.Peer
- func (nh *Neighborhood) IsFull() bool
- func (nh *Neighborhood) RemovePeer(id identity.ID) *peer.Peer
- func (nh *Neighborhood) Select(candidates []peer.PeerDistance) peer.PeerDistance
- func (nh *Neighborhood) String() string
- func (nh *Neighborhood) UpdateDistance(anchor, salt []byte)
- type Option
- func DropOnUpdate(dropOnUpdate bool) Option
- func Logger(log *logger.Logger) Option
- func ManaFunc(manaFunc mana.Func) Option
- func NeighborBlockDuration(blockDuration time.Duration) Option
- func NeighborSkipTimeout(skipTimeout time.Duration) Option
- func NeighborValidator(neighborValidator Validator) Option
- func R(r int) Option
- func Ro(ro float64) Option
- func UseMana(useMana bool) Option
- type Parameters
- type PeeringEvent
- type Protocol
- func (p *Protocol) BlockNeighbor(id identity.ID, ttl ...time.Duration)
- func (p *Protocol) Close()
- func (p *Protocol) Events() *Events
- func (p *Protocol) GetIncomingNeighbors() []*peer.Peer
- func (p *Protocol) GetNeighbors() []*peer.Peer
- func (p *Protocol) GetOutgoingNeighbors() []*peer.Peer
- func (p *Protocol) HandleMessage(s *server.Server, fromAddr *net.UDPAddr, from *identity.Identity, data []byte) (bool, error)
- func (p *Protocol) PeeringDrop(to *peer.Peer)
- func (p *Protocol) PeeringRequest(to *peer.Peer, salt *salt.Salt) (bool, error)
- func (p *Protocol) RemoveNeighbor(id identity.ID)
- func (p *Protocol) Start(s server.Sender)
- func (p *Protocol) UnblockNeighbor(id identity.ID)
- type SaltUpdatedEvent
- type Selector
- type Validator
- type ValidatorFunc
Constants ¶
const ( DefaultInboundNeighborSize = 4 DefaultOutboundNeighborSize = 4 DefaultSaltLifetime = 2 * time.Hour DefaultOutboundUpdateInterval = 1 * time.Second DefaultFullOutboundUpdateInterval = 1 * time.Minute )
Default values for the global parameters.
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 DiscoverProtocol ¶
type DiscoverProtocol interface { IsVerified(identity.ID, net.IP) bool EnsureVerified(*peer.Peer) error GetVerifiedPeer(identity.ID) *peer.Peer GetVerifiedPeers() []*peer.Peer }
DiscoverProtocol specifies the methods from the peer discovery that are required.
type DroppedEvent ¶
type DroppedEvent struct { Peer *peer.Peer DroppedID identity.ID // ID of the peer that gets dropped. }
DroppedEvent bundles the information sent in Dropped events.
type Events ¶
type Events struct { // A SaltUpdated event is triggered, when the private and public salt were updated. SaltUpdated *event.Event[*SaltUpdatedEvent] // An OutgoingPeering event is triggered, when a valid response of PeeringRequest has been received. OutgoingPeering *event.Event[*PeeringEvent] // An IncomingPeering event is triggered, when a valid PeerRequest has been received. IncomingPeering *event.Event[*PeeringEvent] // A Dropped event is triggered, when a neighbor is dropped or when a drop message is received. Dropped *event.Event[*DroppedEvent] }
Events contains all the events that are triggered during the neighbor selection.
type Filter ¶
type Filter struct {
// contains filtered or unexported fields
}
func (*Filter) Apply ¶
func (f *Filter) Apply(list []peer.PeerDistance) (filtered []peer.PeerDistance)
func (*Filter) RemovePeer ¶
type Neighborhood ¶
type Neighborhood struct {
// contains filtered or unexported fields
}
func NewNeighborhood ¶
func NewNeighborhood(size int) *Neighborhood
func (*Neighborhood) Add ¶
func (nh *Neighborhood) Add(toAdd peer.PeerDistance) bool
Add tries to add a new peer with distance to the neighborhood. It returns true, if the peer was added, or false if the neighborhood was full.
func (*Neighborhood) GetNumPeers ¶
func (nh *Neighborhood) GetNumPeers() int
func (*Neighborhood) GetPeers ¶
func (nh *Neighborhood) GetPeers() []*peer.Peer
func (*Neighborhood) IsFull ¶
func (nh *Neighborhood) IsFull() bool
func (*Neighborhood) RemovePeer ¶
func (nh *Neighborhood) RemovePeer(id identity.ID) *peer.Peer
RemovePeer removes the peer with the given ID from the neighborhood. It returns the peer that was removed or nil of no such peer exists.
func (*Neighborhood) Select ¶
func (nh *Neighborhood) Select(candidates []peer.PeerDistance) peer.PeerDistance
func (*Neighborhood) String ¶
func (nh *Neighborhood) String() string
func (*Neighborhood) UpdateDistance ¶
func (nh *Neighborhood) UpdateDistance(anchor, salt []byte)
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
An Option configures the peer selection.
func DropOnUpdate ¶
DropOnUpdate sets the Option to drop all neighbors when the salt is updated.
func NeighborBlockDuration ¶
NeighborBlockDuration sets the amount of time a peer should remain in the blocklist.
func NeighborSkipTimeout ¶
NeighborSkipTimeout sets the amount of time for which we should skip the peer and don't try to connect with it after any problem encountered with that peer.
func NeighborValidator ¶
NeighborValidator sets the potential neighbor validator.
type Parameters ¶
type Parameters struct { InboundNeighborSize int // number of inbound neighbors OutboundNeighborSize int // number of outbound neighbors SaltLifetime time.Duration // lifetime of the private and public local salt OutboundUpdateInterval time.Duration // time interval after which the outbound neighbors are checked FullOutboundUpdateInterval time.Duration // time after which the full outbound neighbors are updated }
Parameters holds the parameters that can be configured.
type PeeringEvent ¶
type PeeringEvent struct { Peer *peer.Peer // peering partner Status bool // true, when the peering partner has accepted the request Distance uint32 // the distance between the peers }
PeeringEvent bundles the information sent in the OutgoingPeering and IncomingPeering event.
type Protocol ¶
The Protocol handles the neighbor selection. It responds to incoming messages and sends own requests when needed.
func New ¶
func New(local *peer.Local, disc DiscoverProtocol, opts ...Option) *Protocol
New creates a new neighbor selection protocol.
func (*Protocol) BlockNeighbor ¶
BlockNeighbor does everything the RemoveNeighbor() does, but it also adds the neighbor to the blocklist for certain amount of time to prevent future peering.
func (*Protocol) Events ¶
Events returns all the events that are triggered during the neighbor selection.
func (*Protocol) GetIncomingNeighbors ¶
GetIncomingNeighbors returns the current incoming neighbors.
func (*Protocol) GetNeighbors ¶
GetNeighbors returns the current neighbors.
func (*Protocol) GetOutgoingNeighbors ¶
GetOutgoingNeighbors returns the current outgoing neighbors.
func (*Protocol) HandleMessage ¶
func (p *Protocol) HandleMessage(s *server.Server, fromAddr *net.UDPAddr, from *identity.Identity, data []byte) (bool, error)
HandleMessage responds to incoming neighbor selection messages.
func (*Protocol) PeeringDrop ¶
PeeringDrop sends a peering drop message to the given peer, non-blocking and does not wait for any responses.
func (*Protocol) PeeringRequest ¶
PeeringRequest sends a PeeringRequest to the given peer. This method blocks until a response is received and the status answer is returned.
func (*Protocol) RemoveNeighbor ¶
RemoveNeighbor removes the peer with the given id from the incoming and outgoing neighbors. If such a peer was actually contained in anyone of the neighbor sets, the corresponding event is triggered and the corresponding peering drop is sent. Otherwise the call is ignored.
func (*Protocol) UnblockNeighbor ¶
UnblockNeighbor removes the neighbor from the blocklist to allow future peering.
type SaltUpdatedEvent ¶
SaltUpdatedEvent bundles the information sent in the SaltUpdated event.
type ValidatorFunc ¶
The ValidatorFunc type is an adapter to allow the use of ordinary functions as neighbor validators. If f is a function with the appropriate signature, ValidatorFunc(f) is a Validator that calls f.