Documentation ¶
Index ¶
- type ClosestNodesIter
- type EventPoolAddFindCloserQuery
- type EventPoolAddQuery
- type EventPoolNodeFailure
- type EventPoolNodeResponse
- type EventPoolPoll
- type EventPoolStopQuery
- type EventQueryCancel
- type EventQueryNodeFailure
- type EventQueryNodeResponse
- type EventQueryPoll
- type NodeIter
- type NodeState
- type NodeStatus
- type Pool
- type PoolConfig
- type PoolEvent
- type PoolState
- type Query
- func NewFindCloserQuery[K kad.Key[K], N kad.NodeID[K], M coordt.Message](self N, id coordt.QueryID, target K, iter NodeIter[K, N], ...) (*Query[K, N, M], error)
- func NewQuery[K kad.Key[K], N kad.NodeID[K], M coordt.Message](self N, id coordt.QueryID, target K, msg M, iter NodeIter[K, N], ...) (*Query[K, N, M], error)
- type QueryConfig
- type QueryEvent
- type QueryState
- type QueryStats
- type SequentialIter
- type StateNodeFailed
- type StateNodeNotContacted
- type StateNodeSucceeded
- type StateNodeUnresponsive
- type StateNodeWaiting
- type StatePoolFindCloser
- type StatePoolIdle
- type StatePoolQueryFinished
- type StatePoolQueryTimeout
- type StatePoolSendMessage
- type StatePoolWaitingAtCapacity
- type StatePoolWaitingWithCapacity
- type StateQueryFindCloser
- type StateQueryFinished
- type StateQuerySendMessage
- type StateQueryWaitingAtCapacity
- type StateQueryWaitingWithCapacity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClosestNodesIter ¶
type ClosestNodesIter[K kad.Key[K], N kad.NodeID[K]] struct { // contains filtered or unexported fields }
A ClosestNodesIter iterates nodes in order of ascending distance from a key.
func NewClosestNodesIter ¶
func NewClosestNodesIter[K kad.Key[K], N kad.NodeID[K]](target K) *ClosestNodesIter[K, N]
NewClosestNodesIter creates a new ClosestNodesIter
func (*ClosestNodesIter[K, N]) Add ¶
func (iter *ClosestNodesIter[K, N]) Add(ni *NodeStatus[K, N])
func (*ClosestNodesIter[K, N]) Each ¶
func (iter *ClosestNodesIter[K, N]) Each(ctx context.Context, fn func(context.Context, *NodeStatus[K, N]) bool) bool
func (*ClosestNodesIter[K, N]) Find ¶
func (iter *ClosestNodesIter[K, N]) Find(k K) (*NodeStatus[K, N], bool)
type EventPoolAddFindCloserQuery ¶
type EventPoolAddFindCloserQuery[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID // the id to use for the new query Target K // the target key for the query Seed []N // an initial set of close nodes the query should use NumResults int // the minimum number of nodes to successfully contact before considering iteration complete }
EventPoolAddQuery is an event that attempts to add a new query that finds closer nodes to a target key.
type EventPoolAddQuery ¶
type EventPoolAddQuery[K kad.Key[K], N kad.NodeID[K], M coordt.Message] struct { QueryID coordt.QueryID // the id to use for the new query Target K // the target key for the query Message M // message to be sent to each node Seed []N // an initial set of close nodes the query should use NumResults int // the minimum number of nodes to successfully contact before considering iteration complete }
EventPoolAddQuery is an event that attempts to add a new query that sends a message.
type EventPoolNodeFailure ¶
type EventPoolNodeFailure[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID // the id of the query that sent the message NodeID N // the node the message was sent to Error error // the error that caused the failure, if any }
EventPoolNodeFailure notifies a Pool that an attempt to contact a node has failed.
type EventPoolNodeResponse ¶
type EventPoolNodeResponse[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID // the id of the query that sent the message NodeID N // the node the message was sent to CloserNodes []N // the closer nodes sent by the node }
EventPoolNodeResponse notifies a Pool that an attempt to contact a node has received a successful response.
type EventPoolPoll ¶
type EventPoolPoll struct{}
EventPoolPoll is an event that signals the pool that it can perform housekeeping work such as time out queries.
type EventPoolStopQuery ¶
type EventPoolStopQuery struct {
QueryID coordt.QueryID // the id of the query that should be stopped
}
EventPoolStopQuery notifies a Pool to stop a query.
type EventQueryCancel ¶
type EventQueryCancel struct{}
EventQueryMessageResponse notifies a query to stop all work and enter the finished state.
type EventQueryNodeFailure ¶
type EventQueryNodeFailure[K kad.Key[K], N kad.NodeID[K]] struct { NodeID N // the node the message was sent to Error error // the error that caused the failure, if any }
EventQueryNodeFailure notifies a Query that an attempt to to contact a node has failed.
type EventQueryNodeResponse ¶
type EventQueryNodeResponse[K kad.Key[K], N kad.NodeID[K]] struct { NodeID N // the node the message was sent to CloserNodes []N // the closer nodes sent by the node }
EventQueryNodeResponse notifies a Query that an attempt to contact a node has received a successful response.
type EventQueryPoll ¶
type EventQueryPoll struct{}
EventQueryPoll is an event that signals a Query that it can perform housekeeping work.
type NodeIter ¶
type NodeIter[K kad.Key[K], N kad.NodeID[K]] interface { // Add adds node information to the iterator Add(*NodeStatus[K, N]) // Find returns the node information corresponding to the given Kademlia key Find(K) (*NodeStatus[K, N], bool) // Each applies fn to each entry in the iterator in order. Each stops and returns true if fn returns true. // Otherwise, Each returns false when there are no further entries. Each(ctx context.Context, fn func(context.Context, *NodeStatus[K, N]) bool) bool }
A NodeIter iterates nodes according to some strategy.
type NodeStatus ¶
type Pool ¶
type Pool[K kad.Key[K], N kad.NodeID[K], M coordt.Message] struct { // contains filtered or unexported fields }
type PoolConfig ¶
type PoolConfig struct { Concurrency int // the maximum number of queries that may be waiting for message responses at any one time Timeout time.Duration // the time to wait before terminating a query that is not making progress Replication int // the 'k' parameter defined by Kademlia QueryConcurrency int // the maximum number of concurrent requests that each query may have in flight RequestTimeout time.Duration // the timeout queries should use for contacting a single node Clock clock.Clock // a clock that may replaced by a mock when testing }
PoolConfig specifies optional configuration for a Pool
func DefaultPoolConfig ¶
func DefaultPoolConfig() *PoolConfig
DefaultPoolConfig returns the default configuration options for a Pool. Options may be overridden before passing to NewPool
func (*PoolConfig) Validate ¶
func (cfg *PoolConfig) Validate() error
Validate checks the configuration options and returns an error if any have invalid values.
type PoolEvent ¶
type PoolEvent interface {
// contains filtered or unexported methods
}
PoolEvent is an event intended to advance the state of a pool.
type Query ¶
type Query[K kad.Key[K], N kad.NodeID[K], M coordt.Message] struct { // contains filtered or unexported fields }
func NewFindCloserQuery ¶
func (*Query[K, N, M]) Advance ¶
func (q *Query[K, N, M]) Advance(ctx context.Context, ev QueryEvent) (out QueryState)
type QueryConfig ¶
type QueryConfig struct { Concurrency int // the maximum number of concurrent requests that may be in flight NumResults int // the minimum number of nodes to successfully contact before considering iteration complete RequestTimeout time.Duration // the timeout for contacting a single node Clock clock.Clock // a clock that may replaced by a mock when testing }
QueryConfig specifies optional configuration for a Query
func DefaultQueryConfig ¶
func DefaultQueryConfig() *QueryConfig
DefaultQueryConfig returns the default configuration options for a Query. Options may be overridden before passing to NewQuery
func (*QueryConfig) Validate ¶
func (cfg *QueryConfig) Validate() error
Validate checks the configuration options and returns an error if any have invalid values.
type QueryEvent ¶
type QueryEvent interface {
// contains filtered or unexported methods
}
type QueryState ¶
type QueryState interface {
// contains filtered or unexported methods
}
type QueryStats ¶
type SequentialIter ¶
type SequentialIter[K kad.Key[K], N kad.NodeID[K]] struct { // contains filtered or unexported fields }
A SequentialIter iterates nodes in the order they were added to the iterator.
func NewSequentialIter ¶
func NewSequentialIter[K kad.Key[K], N kad.NodeID[K]]() *SequentialIter[K, N]
NewSequentialIter creates a new SequentialIter
func (*SequentialIter[K, N]) Add ¶
func (iter *SequentialIter[K, N]) Add(ni *NodeStatus[K, N])
func (*SequentialIter[K, N]) Each ¶
func (iter *SequentialIter[K, N]) Each(ctx context.Context, fn func(context.Context, *NodeStatus[K, N]) bool) bool
func (*SequentialIter[K, N]) Find ¶
func (iter *SequentialIter[K, N]) Find(k K) (*NodeStatus[K, N], bool)
Find returns the node information corresponding to the given Kademlia key. It uses a linear search which makes it unsuitable for large numbers of entries.
type StateNodeFailed ¶
type StateNodeFailed struct{}
StateNodeFailed indicates that the attempt to contact the node failed.
type StateNodeNotContacted ¶
type StateNodeNotContacted struct{}
StateNodeNotContacted indicates that the node has not been contacted yet.
type StateNodeSucceeded ¶
type StateNodeSucceeded struct{}
StateNodeSucceeded indicates that the attempt to contact the node succeeded.
type StateNodeUnresponsive ¶
type StateNodeUnresponsive struct{}
StateNodeUnresponsive indicates that the node did not respond within the configured timeout.
type StateNodeWaiting ¶
StateNodeWaiting indicates that a query is waiting for a response from the node.
type StatePoolFindCloser ¶
type StatePoolFindCloser[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID Target K // the key that the query wants to find closer nodes for NodeID N // the node to send the message to Stats QueryStats }
StatePoolFindCloser indicates that a pool query wants to send a find closer nodes message to a node.
type StatePoolIdle ¶
type StatePoolIdle struct{}
StatePoolIdle indicates that the pool is idle, i.e. there are no queries to process.
type StatePoolQueryFinished ¶
type StatePoolQueryFinished[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID Stats QueryStats ClosestNodes []N }
StatePoolQueryFinished indicates that a query has finished.
type StatePoolQueryTimeout ¶
type StatePoolQueryTimeout struct { QueryID coordt.QueryID Stats QueryStats }
StatePoolQueryTimeout indicates that a query has timed out.
type StatePoolSendMessage ¶
type StatePoolSendMessage[K kad.Key[K], N kad.NodeID[K], M coordt.Message] struct { QueryID coordt.QueryID NodeID N // the node to send the message to Message M Stats QueryStats }
StatePoolSendMessage indicates that a pool query wants to send a message to a node.
type StatePoolWaitingAtCapacity ¶
type StatePoolWaitingAtCapacity struct{}
StatePoolWaitingAtCapacity indicates that at least one query is waiting for results and the pool has reached its maximum number of concurrent queries.
type StatePoolWaitingWithCapacity ¶
type StatePoolWaitingWithCapacity struct{}
StatePoolWaitingWithCapacity indicates that at least one query is waiting for results but capacity to start more is available.
type StateQueryFindCloser ¶
type StateQueryFindCloser[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID Target K // the key that the query wants to find closer nodes for NodeID N // the node to send the message to Stats QueryStats }
StateQueryFindCloser indicates that the Query wants to send a find closer nodes message to a node.
type StateQueryFinished ¶
type StateQueryFinished[K kad.Key[K], N kad.NodeID[K]] struct { QueryID coordt.QueryID Stats QueryStats ClosestNodes []N // contains the closest nodes to the target key that were found }
StateQueryFinished indicates that the Query has finished.
type StateQuerySendMessage ¶
type StateQuerySendMessage[K kad.Key[K], N kad.NodeID[K], M coordt.Message] struct { QueryID coordt.QueryID NodeID N // the node to send the message to Message M Stats QueryStats }
StateQuerySendMessage indicates that the Query wants to send a message to a node.
type StateQueryWaitingAtCapacity ¶
type StateQueryWaitingAtCapacity struct { QueryID coordt.QueryID Stats QueryStats }
StateQueryWaitingAtCapacity indicates that the Query is waiting for results and is at capacity.
type StateQueryWaitingWithCapacity ¶
type StateQueryWaitingWithCapacity struct { QueryID coordt.QueryID Stats QueryStats }
StateQueryWaitingWithCapacity indicates that the Query is waiting for results but has no further nodes to contact.