Documentation ¶
Index ¶
- type PeerState
- type QueryPeerset
- func (qp *QueryPeerset) GetClosestInStates(states ...PeerState) (result []peer.ID)
- func (qp *QueryPeerset) GetClosestNInStates(n int, states ...PeerState) (result []peer.ID)
- func (qp *QueryPeerset) GetReferrer(p peer.ID) peer.ID
- func (qp *QueryPeerset) GetState(p peer.ID) PeerState
- 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) GetClosestInStates ¶
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 ¶
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.