qpeerset

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 4 Imported by: 6

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) GetClosestInStates added in v0.9.0

func (qp *QueryPeerset) GetClosestInStates(states ...PeerState) (result []peer.ID)

GetClosestInStates returns the peers, which are in one of the given states. The returned peers are sorted in ascending order by their distance to the key.

func (*QueryPeerset) GetClosestNInStates added in v0.9.0

func (qp *QueryPeerset) GetClosestNInStates(n int, states ...PeerState) (result []peer.ID)

GetClosestNInStates returns the closest to the key peers, which are in one of the given states. It returns n peers or less, if fewer peers meet the condition. The returned peers are sorted in ascending order by their distance to the key.

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