Documentation ¶
Index ¶
- Variables
- type AppResponseCallback
- type Client
- func (c *Client) AppGossip(ctx context.Context, appGossipBytes []byte) error
- func (c *Client) AppGossipSpecific(ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte) error
- func (c *Client) AppRequest(ctx context.Context, nodeIDs set.Set[ids.NodeID], appRequestBytes []byte, ...) error
- func (c *Client) AppRequestAny(ctx context.Context, appRequestBytes []byte, onResponse AppResponseCallback) error
- func (c *Client) CrossChainAppRequest(ctx context.Context, chainID ids.ID, appRequestBytes []byte, ...) error
- type CrossChainAppResponseCallback
- type Handler
- type NoOpHandler
- type NodeSampler
- type PeerTracker
- func (p *PeerTracker) Connected(nodeID ids.NodeID, nodeVersion *version.Application)
- func (p *PeerTracker) Disconnected(nodeID ids.NodeID)
- func (p *PeerTracker) GetAnyPeer(minVersion *version.Application) (ids.NodeID, bool)
- func (p *PeerTracker) Size() int
- func (p *PeerTracker) TrackBandwidth(nodeID ids.NodeID, bandwidth float64)
- func (p *PeerTracker) TrackPeer(nodeID ids.NodeID)
- type Peers
- type Router
- func (r *Router) AppGossip(ctx context.Context, nodeID ids.NodeID, gossip []byte) error
- func (r *Router) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, ...) error
- func (r *Router) AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32) error
- func (r *Router) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
- func (r *Router) CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, ...) error
- func (r *Router) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32) error
- func (r *Router) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error
- func (r *Router) RegisterAppProtocol(handlerID uint64, handler Handler, nodeSampler NodeSampler) (*Client, error)
- type SlidingWindowThrottler
- type Throttler
- type ThrottlerHandler
- type ValidatorHandler
- type ValidatorSet
- type Validators
Constants ¶
This section is empty.
Variables ¶
var ( ErrAppRequestFailed = errors.New("app request failed") ErrRequestPending = errors.New("request pending") ErrNoPeers = errors.New("no peers") )
var ( ErrExistingAppProtocol = errors.New("existing app protocol") ErrUnrequestedResponse = errors.New("unrequested response") )
var (
ErrNotValidator = errors.New("not a validator")
)
var (
ErrThrottled = errors.New("throttled")
)
Functions ¶
This section is empty.
Types ¶
type AppResponseCallback ¶
type AppResponseCallback func( ctx context.Context, nodeID ids.NodeID, responseBytes []byte, err error, )
AppResponseCallback is called upon receiving an AppResponse for an AppRequest issued by Client. Callers should check [err] to see whether the AppRequest failed or not.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AppGossipSpecific ¶
func (c *Client) AppGossipSpecific( ctx context.Context, nodeIDs set.Set[ids.NodeID], appGossipBytes []byte, ) error
AppGossipSpecific sends a gossip message to a predetermined set of peers.
func (*Client) AppRequest ¶
func (c *Client) AppRequest( ctx context.Context, nodeIDs set.Set[ids.NodeID], appRequestBytes []byte, onResponse AppResponseCallback, ) error
AppRequest issues an arbitrary request to a node. [onResponse] is invoked upon an error or a response.
func (*Client) AppRequestAny ¶
func (c *Client) AppRequestAny( ctx context.Context, appRequestBytes []byte, onResponse AppResponseCallback, ) error
AppRequestAny issues an AppRequest to an arbitrary node decided by Client. If a specific node needs to be requested, use AppRequest instead. See AppRequest for more docs.
func (*Client) CrossChainAppRequest ¶
func (c *Client) CrossChainAppRequest( ctx context.Context, chainID ids.ID, appRequestBytes []byte, onResponse CrossChainAppResponseCallback, ) error
CrossChainAppRequest sends a cross chain app request to another vm. [onResponse] is invoked upon an error or a response.
type CrossChainAppResponseCallback ¶
type CrossChainAppResponseCallback func( ctx context.Context, chainID ids.ID, responseBytes []byte, err error, )
CrossChainAppResponseCallback is called upon receiving an CrossChainAppResponse for a CrossChainAppRequest issued by Client. Callers should check [err] to see whether the AppRequest failed or not.
type Handler ¶
type Handler interface { // AppGossip is called when handling an AppGossip message. AppGossip( ctx context.Context, nodeID ids.NodeID, gossipBytes []byte, ) // AppRequest is called when handling an AppRequest message. // Returns the bytes for the response corresponding to [requestBytes] AppRequest( ctx context.Context, nodeID ids.NodeID, deadline time.Time, requestBytes []byte, ) ([]byte, error) // CrossChainAppRequest is called when handling a CrossChainAppRequest // message. // Returns the bytes for the response corresponding to [requestBytes] CrossChainAppRequest( ctx context.Context, chainID ids.ID, deadline time.Time, requestBytes []byte, ) ([]byte, error) }
Handler is the server-side logic for virtual machine application protocols.
type NoOpHandler ¶ added in v1.10.9
type NoOpHandler struct{}
NoOpHandler drops all messages
func (NoOpHandler) AppRequest ¶ added in v1.10.9
type NodeSampler ¶ added in v1.10.9
type NodeSampler interface { // Sample returns at most [limit] nodes. This may return fewer nodes if // fewer than [limit] are available. Sample(ctx context.Context, limit int) []ids.NodeID }
NodeSampler samples nodes in network
type PeerTracker ¶ added in v1.10.17
type PeerTracker struct {
// contains filtered or unexported fields
}
Tracks the bandwidth of responses coming from peers, preferring to contact peers with known good bandwidth, connecting to new peers with an exponentially decaying probability.
func NewPeerTracker ¶ added in v1.10.17
func NewPeerTracker( log logging.Logger, metricsNamespace string, registerer prometheus.Registerer, ) (*PeerTracker, error)
func (*PeerTracker) Connected ¶ added in v1.10.17
func (p *PeerTracker) Connected(nodeID ids.NodeID, nodeVersion *version.Application)
Connected should be called when [nodeID] connects to this node
func (*PeerTracker) Disconnected ¶ added in v1.10.17
func (p *PeerTracker) Disconnected(nodeID ids.NodeID)
Disconnected should be called when [nodeID] disconnects from this node
func (*PeerTracker) GetAnyPeer ¶ added in v1.10.17
func (p *PeerTracker) GetAnyPeer(minVersion *version.Application) (ids.NodeID, bool)
TODO get rid of minVersion Returns a peer that we're connected to. If we should track more peers, returns a random peer with version >= [minVersion], if any exist. Otherwise, with probability [randomPeerProbability] returns a random peer from [p.responsivePeers]. With probability [1-randomPeerProbability] returns the peer in [p.bandwidthHeap] with the highest bandwidth.
func (*PeerTracker) Size ¶ added in v1.10.17
func (p *PeerTracker) Size() int
Returns the number of peers the node is connected to.
func (*PeerTracker) TrackBandwidth ¶ added in v1.10.17
func (p *PeerTracker) TrackBandwidth(nodeID ids.NodeID, bandwidth float64)
Record that we observed that [nodeID]'s bandwidth is [bandwidth]. Adds the peer's bandwidth averager to the bandwidth heap.
func (*PeerTracker) TrackPeer ¶ added in v1.10.17
func (p *PeerTracker) TrackPeer(nodeID ids.NodeID)
Record that we sent a request to [nodeID].
type Peers ¶ added in v1.10.9
type Peers struct {
// contains filtered or unexported fields
}
Peers contains a set of nodes that we are connected to.
func (*Peers) Disconnected ¶ added in v1.10.9
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router routes incoming application messages to the corresponding registered app handler. App messages must be made using the registered handler's corresponding Client.
func NewRouter ¶
func NewRouter( log logging.Logger, sender common.AppSender, metrics prometheus.Registerer, namespace string, ) *Router
NewRouter returns a new instance of Router
func (*Router) AppGossip ¶
AppGossip routes an AppGossip message to a Handler based on the handler prefix. The message is dropped if no matching handler can be found.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) AppRequest ¶
func (r *Router) AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte) error
AppRequest routes an AppRequest to a Handler based on the handler prefix. The message is dropped if no matching handler can be found.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) AppRequestFailed ¶
AppRequestFailed routes an AppRequestFailed message to the callback corresponding to requestID.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) AppResponse ¶
func (r *Router) AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
AppResponse routes an AppResponse message to the callback corresponding to requestID.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) CrossChainAppRequest ¶
func (r *Router) CrossChainAppRequest( ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, msg []byte, ) error
CrossChainAppRequest routes a CrossChainAppRequest message to a Handler based on the handler prefix. The message is dropped if no matching handler can be found.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) CrossChainAppRequestFailed ¶
func (r *Router) CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32) error
CrossChainAppRequestFailed routes a CrossChainAppRequestFailed message to the callback corresponding to requestID.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) CrossChainAppResponse ¶
func (r *Router) CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, response []byte) error
CrossChainAppResponse routes a CrossChainAppResponse message to the callback corresponding to requestID.
Any error condition propagated outside Handler application logic is considered fatal
func (*Router) RegisterAppProtocol ¶
func (r *Router) RegisterAppProtocol(handlerID uint64, handler Handler, nodeSampler NodeSampler) (*Client, error)
RegisterAppProtocol reserves an identifier for an application protocol and returns a Client that can be used to send messages for the corresponding protocol.
type SlidingWindowThrottler ¶ added in v1.10.10
type SlidingWindowThrottler struct {
// contains filtered or unexported fields
}
SlidingWindowThrottler is an implementation of the sliding window throttling algorithm.
func NewSlidingWindowThrottler ¶ added in v1.10.10
func NewSlidingWindowThrottler(period time.Duration, limit int) *SlidingWindowThrottler
NewSlidingWindowThrottler returns a new instance of SlidingWindowThrottler. Nodes are throttled if they exceed [limit] messages during an interval of time over [period]. [period] and [limit] should both be > 0.
func (*SlidingWindowThrottler) Handle ¶ added in v1.10.10
func (s *SlidingWindowThrottler) Handle(nodeID ids.NodeID) bool
Handle returns true if the amount of calls received in the last [s.period] time is less than [s.limit]
This is calculated by adding the current period's count to a weighted count of the previous period.
type ThrottlerHandler ¶ added in v1.10.10
type ValidatorHandler ¶ added in v1.10.10
type ValidatorHandler struct { Handler ValidatorSet ValidatorSet Log logging.Logger }
ValidatorHandler drops messages from non-validators
type ValidatorSet ¶ added in v1.10.10
type Validators ¶ added in v1.10.9
type Validators struct {
// contains filtered or unexported fields
}
Validators contains a set of nodes that are staking.
func NewValidators ¶ added in v1.10.9
func NewValidators(log logging.Logger, subnetID ids.ID, validators validators.State, maxValidatorSetStaleness time.Duration) *Validators