selection

package
v0.0.0-...-1974178 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0, BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInboundNeighborSize        = 8
	DefaultOutboundNeighborSize       = 8
	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 {
	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 *events.Event
	// An OutgoingPeering event is triggered, when a valid response of PeeringRequest has been received.
	OutgoingPeering *events.Event
	// An IncomingPeering event is triggered, when a valid PeerRequest has been received.
	IncomingPeering *events.Event
	// A Dropped event is triggered, when a neighbor is dropped or when a drop message is received.
	Dropped *events.Event
}

Events contains all the events that are triggered during the neighbor selection.

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

func NewFilter

func NewFilter() *Filter

func (*Filter) AddCondition

func (f *Filter) AddCondition(c func(p *peer.Peer) bool)

func (*Filter) AddPeer

func (f *Filter) AddPeer(peer identity.ID)

func (*Filter) AddPeers

func (f *Filter) AddPeers(n []*peer.Peer)

func (*Filter) Apply

func (f *Filter) Apply(list []peer.PeerDistance) (filtered []peer.PeerDistance)

func (*Filter) Clean

func (f *Filter) Clean()

func (*Filter) RemovePeer

func (f *Filter) RemovePeer(peer identity.ID)

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

func DropOnUpdate(dropOnUpdate bool) Option

DropOnUpdate sets the Option to drop all neighbors when the salt is updated

func Logger

func Logger(log *logger.Logger) Option

Logger sets the logger

func NeighborValidator

func NeighborValidator(neighborValidator Validator) Option

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

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

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) Close

func (p *Protocol) Close()

Close finalizes the protocol.

func (*Protocol) Events

func (p *Protocol) Events() Events

Events returns all the events that are triggered during the neighbor selection.

func (*Protocol) GetIncomingNeighbors

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

GetIncomingNeighbors returns the current incoming neighbors.

func (*Protocol) GetNeighbors

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

GetNeighbors returns the current neighbors.

func (*Protocol) GetOutgoingNeighbors

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

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

func (p *Protocol) PeeringDrop(to *peer.Peer)

PeeringDrop sends a peering drop message to the given peer, non-blocking and does not wait for any responses.

func (*Protocol) PeeringRequest

func (p *Protocol) PeeringRequest(to *peer.Peer, salt *salt.Salt) (bool, error)

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

func (p *Protocol) RemoveNeighbor(id identity.ID)

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) Start

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

Start starts the actual neighbor selection over the provided Sender.

type SaltUpdatedEvent

type SaltUpdatedEvent struct {
	Public, Private *salt.Salt // the updated salt
}

SaltUpdatedEvent bundles the information sent in the SaltUpdated event.

type Selector

type Selector interface {
	Select(candidates peer.PeerDistance) *peer.Peer
}

type Validator

type Validator interface {
	IsValid(*peer.Peer) bool
}

A Validator checks whether a peer is a valid neighbor

type ValidatorFunc

type ValidatorFunc func(p *peer.Peer) bool

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.

func (ValidatorFunc) IsValid

func (f ValidatorFunc) IsValid(p *peer.Peer) bool

IsValid calls f(p).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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