Documentation ¶
Index ¶
- type PeerState
- type QueryPeerset
- func (qp *QueryPeerset) GetClosestNotUnreachable(count int) (result []peer.ID)
- func (qp *QueryPeerset) GetHeardPeers() (result []peer.ID)
- func (qp *QueryPeerset) GetReferrer(p peer.ID) peer.ID
- func (qp *QueryPeerset) GetSortedHeard() (result []peer.ID)
- func (qp *QueryPeerset) GetState(p peer.ID) PeerState
- func (qp *QueryPeerset) GetWaitingPeers() (result []peer.ID)
- func (qp *QueryPeerset) NumHeard() int
- func (qp *QueryPeerset) NumWaiting() int
- func (qp *QueryPeerset) SetState(p peer.ID, s PeerState)
- func (qp *QueryPeerset) TryAdd(p, referredBy peer.ID) bool
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.