Documentation ¶
Index ¶
- func NewNodeValueList[K kad.Key[K]]() *nodeValueList[K]
- type Bootstrap
- type BootstrapConfig
- type BootstrapEvent
- type BootstrapState
- type EventBootstrapMessageFailure
- type EventBootstrapMessageResponse
- type EventBootstrapPoll
- type EventBootstrapStart
- type EventIncludeAddCandidate
- type EventIncludeMessageFailure
- type EventIncludeMessageResponse
- type EventIncludePoll
- type EventProbeAdd
- type EventProbeMessageFailure
- type EventProbeMessageResponse
- type EventProbeNotifyConnectivity
- type EventProbePoll
- type EventProbeRemove
- type Include
- type IncludeConfig
- type IncludeEvent
- type IncludeState
- type Probe
- type ProbeConfig
- type ProbeEvent
- type ProbeState
- type RoutingTableCpl
- type StateBootstrapFinished
- type StateBootstrapIdle
- type StateBootstrapMessage
- type StateBootstrapTimeout
- type StateBootstrapWaiting
- type StateIncludeFindNodeMessage
- type StateIncludeIdle
- type StateIncludeRoutingUpdated
- type StateIncludeWaitingAtCapacity
- type StateIncludeWaitingFull
- type StateIncludeWaitingWithCapacity
- type StateProbeConnectivityCheck
- type StateProbeIdle
- type StateProbeNodeFailure
- type StateProbeWaitingAtCapacity
- type StateProbeWaitingWithCapacity
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewNodeValueList ¶
Types ¶
type Bootstrap ¶
func NewBootstrap ¶
func (*Bootstrap[K, A]) Advance ¶
func (b *Bootstrap[K, A]) Advance(ctx context.Context, ev BootstrapEvent) BootstrapState
Advance advances the state of the bootstrap by attempting to advance its query if running.
type BootstrapConfig ¶
type BootstrapConfig[K kad.Key[K], A kad.Address[A]] struct { Timeout time.Duration // the time to wait before terminating a query that is not making progress RequestConcurrency 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 }
BootstrapConfig specifies optional configuration for a Bootstrap
func DefaultBootstrapConfig ¶
func DefaultBootstrapConfig[K kad.Key[K], A kad.Address[A]]() *BootstrapConfig[K, A]
DefaultBootstrapConfig returns the default configuration options for a Bootstrap. Options may be overridden before passing to NewBootstrap
func (*BootstrapConfig[K, A]) Validate ¶
func (cfg *BootstrapConfig[K, A]) Validate() error
Validate checks the configuration options and returns an error if any have invalid values.
type BootstrapEvent ¶
type BootstrapEvent interface {
// contains filtered or unexported methods
}
BootstrapEvent is an event intended to advance the state of a bootstrap.
type BootstrapState ¶
type BootstrapState interface {
// contains filtered or unexported methods
}
BootstrapState is the state of a bootstrap.
type EventBootstrapMessageFailure ¶
type EventBootstrapMessageFailure[K kad.Key[K]] struct { NodeID kad.NodeID[K] // the node the message was sent to Error error // the error that caused the failure, if any }
EventBootstrapMessageFailure notifiesa bootstrap that an attempt to send a message has failed.
type EventBootstrapMessageResponse ¶
type EventBootstrapMessageResponse[K kad.Key[K], A kad.Address[A]] struct { NodeID kad.NodeID[K] // the node the message was sent to Response kad.Response[K, A] // the message response sent by the node }
EventBootstrapMessageResponse notifies a bootstrap that a sent message has received a successful response.
type EventBootstrapPoll ¶
type EventBootstrapPoll struct{}
EventBootstrapPoll is an event that signals the bootstrap that it can perform housekeeping work such as time out queries.
type EventBootstrapStart ¶
type EventBootstrapStart[K kad.Key[K], A kad.Address[A]] struct { ProtocolID address.ProtocolID Message kad.Request[K, A] KnownClosestNodes []kad.NodeID[K] }
EventBootstrapStart is an event that attempts to start a new bootstrap
type EventIncludeAddCandidate ¶
type EventIncludeAddCandidate[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the candidate node }
EventIncludeAddCandidate notifies that a node should be added to the candidate list
type EventIncludeMessageFailure ¶
type EventIncludeMessageFailure[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the node the message was sent to Error error // the error that caused the failure, if any }
EventIncludeMessageFailure notifiesa include that an attempt to send a message has failed.
type EventIncludeMessageResponse ¶
type EventIncludeMessageResponse[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the node the message was sent to Response kad.Response[K, A] // the message response sent by the node }
EventIncludeMessageResponse notifies a include that a sent message has received a successful response.
type EventIncludePoll ¶
type EventIncludePoll struct{}
EventIncludePoll is an event that signals the include that it can perform housekeeping work such as time out queries.
type EventProbeAdd ¶
EventProbeAdd notifies a probe that a node should be added to its list of nodes.
type EventProbeMessageFailure ¶
type EventProbeMessageFailure[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the node the message was sent to Error error // the error that caused the failure, if any }
EventProbeMessageFailure notifiesa probe that an attempt to send a message has failed.
type EventProbeMessageResponse ¶
type EventProbeMessageResponse[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the node the message was sent to Response kad.Response[K, A] // the message response sent by the node }
EventProbeMessageResponse notifies a probe that a sent message has received a successful response.
type EventProbeNotifyConnectivity ¶
EventProbeNotifyConnectivity notifies a probe that a node has confirmed connectivity from another source such as a query.
type EventProbePoll ¶
type EventProbePoll struct{}
EventProbePoll is an event that signals the probe that it can perform housekeeping work such as time out queries.
type EventProbeRemove ¶
EventProbeRemove notifies a probe that a node should be removed from its list of nodes and the routing table.
type Include ¶
func NewInclude ¶
func (*Include[K, A]) Advance ¶
func (b *Include[K, A]) Advance(ctx context.Context, ev IncludeEvent) IncludeState
Advance advances the state of the include state machine by attempting to advance its query if running.
type IncludeConfig ¶
type IncludeConfig struct { QueueCapacity int // the maximum number of nodes that can be in the candidate queue Concurrency int // the maximum number of include checks that may be in progress at any one time Timeout time.Duration // the time to wait before terminating a check that is not making progress Clock clock.Clock // a clock that may replaced by a mock when testing }
IncludeConfig specifies optional configuration for an Include
func DefaultIncludeConfig ¶
func DefaultIncludeConfig() *IncludeConfig
DefaultIncludeConfig returns the default configuration options for an Include. Options may be overridden before passing to NewInclude
func (*IncludeConfig) Validate ¶
func (cfg *IncludeConfig) Validate() error
Validate checks the configuration options and returns an error if any have invalid values.
type IncludeEvent ¶
type IncludeEvent interface {
// contains filtered or unexported methods
}
IncludeEvent is an event intended to advance the state of a include.
type IncludeState ¶
type IncludeState interface {
// contains filtered or unexported methods
}
IncludeState is the state of a include.
type Probe ¶
The Probe state machine performs regular connectivity checks for nodes in a routing table.
The state machine is notified of a new entry in the routing table via the EventProbeAdd event. This adds the node to an internal list and sets a time for a check to be performed, based on the current time plus a configurable interval.
Connectivity checks are performed in time order, so older nodes are processed first. The connectivity check performed is the same as for the Include state machine: ask the node for closest nodes to itself and confirm that the node returns at least one node in the list of closer nodes. The state machine emits the StateProbeConnectivityCheck state when it wants to check the status of a node.
The state machine expects to be notified either with the EventProbeMessageResponse or the EventProbeMessageFailure events to determine the outcome of the check. If neither are received within a configurable timeout the node is marked as failed.
Nodes that receive a successful response have their next check time updated to the current time plus the configured [ProbeConfig.CheckInterval].
Nodes that fail a connectivity check, or are timed out, are removed from the routing table and from the list of nodes to check. The state machine emits the StateProbeNodeFailure state to notify callers of this event.
The state machine accepts a EventProbePoll event to check for outstanding work such as initiating a new check or timing out an existing one.
The EventProbeRemove event may be used to remove a node from the check list and from the routing table.
The state machine accepts the EventProbeNotifyConnectivity event as a notification that an external system has performed a suitable connectivity check, such as when the node responds to a query. The probe state machine treats these events as if a successful response had been received from a check by advancing the time of the next check.
func NewProbe ¶
func NewProbe[K kad.Key[K], A kad.Address[A]](rt RoutingTableCpl[K, kad.NodeID[K]], cfg *ProbeConfig) (*Probe[K, A], error)
func (*Probe[K, A]) Advance ¶
func (p *Probe[K, A]) Advance(ctx context.Context, ev ProbeEvent) ProbeState
Advance advances the state of the probe state machine by attempting to advance its query if running.
type ProbeConfig ¶
type ProbeConfig struct { CheckInterval time.Duration // the minimum time interval between checks for a node Concurrency int // the maximum number of probe checks that may be in progress at any one time Timeout time.Duration // the time to wait before terminating a check that is not making progress Clock clock.Clock // a clock that may be replaced by a mock when testing }
ProbeConfig specifies optional configuration for a Probe
func DefaultProbeConfig ¶
func DefaultProbeConfig() *ProbeConfig
DefaultProbeConfig returns the default configuration options for a Probe. Options may be overridden before passing to NewProbe
func (*ProbeConfig) Validate ¶
func (cfg *ProbeConfig) Validate() error
Validate checks the configuration options and returns an error if any have invalid values.
type ProbeEvent ¶
type ProbeEvent interface {
// contains filtered or unexported methods
}
ProbeEvent is an event intended to advance the state of a probe.
type ProbeState ¶
type ProbeState interface {
// contains filtered or unexported methods
}
ProbeState is the state of the Probe state machine.
type RoutingTableCpl ¶
type RoutingTableCpl[K kad.Key[K], N kad.NodeID[K]] interface { kad.RoutingTable[K, N] // Cpl returns the longest common prefix length the supplied key shares with the table's key. Cpl(kk K) int // CplSize returns the number of nodes in the table whose longest common prefix with the table's key is of length cpl. CplSize(cpl int) int }
type StateBootstrapFinished ¶
type StateBootstrapFinished struct {
Stats query.QueryStats
}
StateBootstrapFinished indicates that the bootstrap has finished.
type StateBootstrapIdle ¶
type StateBootstrapIdle struct{}
StateBootstrapIdle indicates that the bootstrap is not running its query.
type StateBootstrapMessage ¶
type StateBootstrapMessage[K kad.Key[K], A kad.Address[A]] struct { QueryID query.QueryID NodeID kad.NodeID[K] ProtocolID address.ProtocolID Message kad.Request[K, A] Stats query.QueryStats }
StateBootstrapMessage indicates that the bootstrap query is waiting to message a node.
type StateBootstrapTimeout ¶
type StateBootstrapTimeout struct {
Stats query.QueryStats
}
StateBootstrapTimeout indicates that the bootstrap query has timed out.
type StateBootstrapWaiting ¶
type StateBootstrapWaiting struct {
Stats query.QueryStats
}
StateBootstrapWaiting indicates that the bootstrap query is waiting for a response.
type StateIncludeFindNodeMessage ¶
type StateIncludeFindNodeMessage[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] // the node to send the mssage to }
StateIncludeFindNodeMessage indicates that the include subsystem is waiting to send a find node message a node. A find node message should be sent to the node, with the target being the node's key.
type StateIncludeIdle ¶
type StateIncludeIdle struct{}
StateIncludeIdle indicates that the include is not running its query.
type StateIncludeRoutingUpdated ¶
type StateIncludeRoutingUpdated[K kad.Key[K], A kad.Address[A]] struct { NodeInfo kad.NodeInfo[K, A] }
StateIncludeRoutingUpdated indicates the routing table has been updated with a new node.
type StateIncludeWaitingAtCapacity ¶
type StateIncludeWaitingAtCapacity struct{}
StateIncludeWaitingAtCapacity indicates that the include subsystem is waiting for responses for checks and that the maximum number of concurrent checks has been reached.
type StateIncludeWaitingFull ¶
type StateIncludeWaitingFull struct{}
StateIncludeWaitingFull indicates that the include subsystem is waiting for responses for checks and that the maximum number of queued candidates has been reached.
type StateIncludeWaitingWithCapacity ¶
type StateIncludeWaitingWithCapacity struct{}
StateIncludeWaitingWithCapacity indicates that the include subsystem is waiting for responses for checks but has capacity to perform more.
type StateProbeConnectivityCheck ¶
type StateProbeConnectivityCheck[K kad.Key[K]] struct { NodeID kad.NodeID[K] // the node to send the message to }
StateProbeConnectivityCheck indicates that the probe subsystem is waiting to send a connectivity check to a node. A find node message should be sent to the node, with the target being the node's key.
type StateProbeIdle ¶
type StateProbeIdle struct{}
StateProbeIdle indicates that the probe state machine is not running any checks.
type StateProbeNodeFailure ¶
StateProbeNodeFailure indicates a node has failed a connectivity check been removed from the routing table and the probe list
type StateProbeWaitingAtCapacity ¶
type StateProbeWaitingAtCapacity struct{}
StateProbeWaitingAtCapacity indicates that the probe state machine is waiting for responses for checks and the maximum number of concurrent checks has been reached.
type StateProbeWaitingWithCapacity ¶
type StateProbeWaitingWithCapacity struct{}
StateProbeWaitingWithCapacity indicates that the probe state machine is waiting for responses for checks but has capacity to perform more.