qpeerset

package
v0.7.5-0...-0a200ac Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PeerState

type PeerState int

PeerState describes the state of a peer ID during the lifecycle of an individual lookup.

const (
	// PeerHeard is applied to peers which have not been queried yet.
	PeerHeard PeerState = iota
	// PeerWaiting is applied to peers that are currently being queried.
	PeerWaiting
	// PeerQueried is applied to peers who have been queried and a response was retrieved successfully.
	PeerQueried
	// PeerUnreachable is applied to peers who have been queried and a response was not retrieved successfully.
	PeerUnreachable
)

type QueryPeerset

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

QueryPeerset maintains the state of a Kademlia asynchronous lookup. The lookup state is a set of peers, each labeled with a peer state.

func NewQueryPeerset

func NewQueryPeerset(key string) *QueryPeerset

NewQueryPeerset creates a new empty set of peers. key is the target key of the lookup that this peer set is for.

func (*QueryPeerset) GetClosestNotUnreachable

func (qp *QueryPeerset) GetClosestNotUnreachable(count int) (result []peer.ID)

GetClosestNotUnreachable returns the closest to the key peers, which are not in state PeerUnreachable. It returns count peers or less, if fewer peers meet the condition.

func (*QueryPeerset) GetHeardPeers

func (qp *QueryPeerset) GetHeardPeers() (result []peer.ID)

GetHeardPeers returns a slice of all peers in state PeerHeard, in an undefined order.

func (*QueryPeerset) GetReferrer

func (qp *QueryPeerset) GetReferrer(p peer.ID) peer.ID

GetReferrer returns the peer that referred us to the peer p. If p is not in the peerset, GetReferrer panics.

func (*QueryPeerset) GetSortedHeard

func (qp *QueryPeerset) GetSortedHeard() (result []peer.ID)

GetSortedHeard returns a slice of all peers in state PeerHeard, ordered by ascending distance to the target key.

func (*QueryPeerset) GetState

func (qp *QueryPeerset) GetState(p peer.ID) PeerState

GetState returns the state of peer p. If p is not in the peerset, GetState panics.

func (*QueryPeerset) GetWaitingPeers

func (qp *QueryPeerset) GetWaitingPeers() (result []peer.ID)

GetWaitingPeers returns a slice of all peers in state PeerWaiting, in an undefined order.

func (*QueryPeerset) NumHeard

func (qp *QueryPeerset) NumHeard() int

NumHeard returns the number of peers in state PeerHeard.

func (*QueryPeerset) NumWaiting

func (qp *QueryPeerset) NumWaiting() int

NumWaiting returns the number of peers in state PeerWaiting.

func (*QueryPeerset) SetState

func (qp *QueryPeerset) SetState(p peer.ID, s PeerState)

SetState sets the state of peer p to s. If p is not in the peerset, SetState panics.

func (*QueryPeerset) TryAdd

func (qp *QueryPeerset) TryAdd(p, referredBy peer.ID) bool

TryAdd adds the peer p to the peer set. If the peer is already present, no action is taken. Otherwise, the peer is added with state set to PeerHeard. TryAdd returns true iff the peer was not already present.

Jump to

Keyboard shortcuts

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