Documentation
¶
Index ¶
- func IsNetworkRequest(requestID uint32) bool
- func NewPeerTracker() *peerTracker
- type AppHandler
- type AppSender
- type Network
- type P2PSenderAdapter
- func (a *P2PSenderAdapter) SendAppRequest(nodeID ids.NodeID, requestID uint32, request []byte) error
- func (a *P2PSenderAdapter) SendAppResponse(nodeID ids.NodeID, requestID uint32, response []byte) error
- func (a *P2PSenderAdapter) SendCrossChainAppRequest(chainID ids.ID, requestID uint32, request []byte) error
- func (a *P2PSenderAdapter) SendCrossChainAppResponse(chainID ids.ID, requestID uint32, response []byte) error
- type SyncedNetworkClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNetworkRequest ¶
IsNetworkRequest checks if the given requestID is a request for this network handler (even-numbered requestIDs) SDK requests are odd-numbered requestIDs (see invariant: https://github.com/luxfi/node/blob/v1.13.0/network/p2p/router.go#L83)
func NewPeerTracker ¶
func NewPeerTracker() *peerTracker
Types ¶
type AppHandler ¶
type AppHandler interface {
AppRequest(ctx context.Context, nodeID ids.NodeID, requestID uint32, deadline time.Time, request []byte) error
AppResponse(ctx context.Context, nodeID ids.NodeID, requestID uint32, response []byte) error
AppRequestFailed(ctx context.Context, nodeID ids.NodeID, requestID uint32, appErr *p2p.Error) error
AppGossip(ctx context.Context, nodeID ids.NodeID, msg []byte) error
CrossChainAppRequest(ctx context.Context, chainID ids.ID, requestID uint32, deadline time.Time, msg []byte) error
CrossChainAppResponse(ctx context.Context, chainID ids.ID, requestID uint32, msg []byte) error
CrossChainAppRequestFailed(ctx context.Context, chainID ids.ID, requestID uint32, appErr *p2p.Error) error
}
AppHandler handles application-level messages
type AppSender ¶
type AppSender interface {
SendAppRequest(nodeID ids.NodeID, requestID uint32, request []byte) error
SendAppResponse(nodeID ids.NodeID, requestID uint32, response []byte) error
SendCrossChainAppRequest(chainID ids.ID, requestID uint32, request []byte) error
SendCrossChainAppResponse(chainID ids.ID, requestID uint32, response []byte) error
}
AppSender provides the interface for sending application-level messages
func NewP2PSenderAdapter ¶ added in v0.15.54
NewP2PSenderAdapter creates an adapter that wraps p2p.Sender
type Network ¶
type Network interface {
validators.Connector
AppHandler
SyncedNetworkClient
// SendAppRequestAny sends request to an arbitrary peer with a
// node version greater than or equal to minVersion.
// Returns the ID of the chosen peer, and an error if the request could not
// be sent to a peer with the desired [minVersion].
SendAppRequestAny(ctx context.Context, minVersion *consensusversion.Application, message []byte, handler message.ResponseHandler) (ids.NodeID, error)
// SendAppRequest sends message to given nodeID, notifying handler when there's a response or timeout
SendAppRequest(ctx context.Context, nodeID ids.NodeID, message []byte, handler message.ResponseHandler) error
// Shutdown stops all peer channel listeners and marks the node to have stopped
// n.Start() can be called again but the peers will have to be reconnected
// by calling OnPeerConnected for each peer
Shutdown()
// SetRequestHandler sets the provided request handler as the request handler
SetRequestHandler(handler message.RequestHandler)
// Size returns the size of the network in number of connected peers
Size() uint32
// NewClient returns a client to send messages with for the given protocol
NewClient(protocol uint64, options ...p2p.ClientOption) *p2p.Client
// AddHandler registers a server handler for an application protocol
AddHandler(protocol uint64, handler p2p.Handler) error
P2PValidators() *p2p.Validators
}
func NewNetwork ¶
func NewNetwork( ctx *consensuscontext.Context, appSender AppSender, codec codec.Manager, maxActiveAppRequests int64, registerer prometheus.Registerer, ) (Network, error)
type P2PSenderAdapter ¶ added in v0.15.54
type P2PSenderAdapter struct {
// contains filtered or unexported fields
}
P2PSenderAdapter adapts p2p.Sender to network.AppSender
func (*P2PSenderAdapter) SendAppRequest ¶ added in v0.15.54
func (a *P2PSenderAdapter) SendAppRequest(nodeID ids.NodeID, requestID uint32, request []byte) error
SendAppRequest sends to a single node via p2p.Sender
func (*P2PSenderAdapter) SendAppResponse ¶ added in v0.15.54
func (a *P2PSenderAdapter) SendAppResponse(nodeID ids.NodeID, requestID uint32, response []byte) error
SendAppResponse forwards response via p2p.Sender
func (*P2PSenderAdapter) SendCrossChainAppRequest ¶ added in v0.15.54
func (a *P2PSenderAdapter) SendCrossChainAppRequest(chainID ids.ID, requestID uint32, request []byte) error
SendCrossChainAppRequest - cross-chain not supported via p2p.Sender
func (*P2PSenderAdapter) SendCrossChainAppResponse ¶ added in v0.15.54
func (a *P2PSenderAdapter) SendCrossChainAppResponse(chainID ids.ID, requestID uint32, response []byte) error
SendCrossChainAppResponse - cross-chain not supported via p2p.Sender
type SyncedNetworkClient ¶
type SyncedNetworkClient interface {
// SendSyncedAppRequestAny synchronously sends request to an arbitrary peer with a
// node version greater than or equal to minVersion.
// Returns response bytes, the ID of the chosen peer, and ErrRequestFailed if
// the request should be retried.
SendSyncedAppRequestAny(ctx context.Context, minVersion *consensusversion.Application, request []byte) ([]byte, ids.NodeID, error)
// SendSyncedAppRequest synchronously sends request to the selected nodeID
// Returns response bytes, and ErrRequestFailed if the request should be retried.
SendSyncedAppRequest(ctx context.Context, nodeID ids.NodeID, request []byte) ([]byte, error)
// TrackBandwidth should be called for each valid request with the bandwidth
// (length of response divided by request time), and with 0 if the response is invalid.
TrackBandwidth(nodeID ids.NodeID, bandwidth float64)
}
SyncedNetworkClient defines ability to send request / response through the Network