Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrRequestFailed = errors.New("request failed")
)
Functions ¶
func NewPeerTracker ¶
func NewPeerTracker() *peerTracker
Types ¶
type Network ¶
type Network interface { validators.Connector common.AppHandler // SendAppRequestAny synchronously 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 *version.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 // Gossip sends given gossip message to peers Gossip(gossip []byte) error // SendCrossChainRequest sends a message to given chainID notifying handler when there's a response or timeout SendCrossChainRequest(ctx context.Context, chainID ids.ID, 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() // SetGossipHandler sets the provided gossip handler as the gossip handler SetGossipHandler(handler message.GossipHandler) // SetRequestHandler sets the provided request handler as the request handler SetRequestHandler(handler message.RequestHandler) // SetCrossChainHandler sets the provided cross chain request handler as the cross chain request handler SetCrossChainRequestHandler(handler message.CrossChainRequestHandler) // Size returns the size of the network in number of connected peers Size() uint32 // 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) // 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 }
type NetworkClient ¶
type NetworkClient interface { // SendAppRequestAny 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. SendAppRequestAny(ctx context.Context, minVersion *version.Application, request []byte) ([]byte, ids.NodeID, error) // SendAppRequest synchronously sends request to the selected nodeID // Returns response bytes, and ErrRequestFailed if the request should be retried. SendAppRequest(ctx context.Context, nodeID ids.NodeID, request []byte) ([]byte, error) // SendCrossChainRequest sends a request to a specific blockchain running on this node. // Returns response bytes, and ErrRequestFailed if the request failed. SendCrossChainRequest(ctx context.Context, chainID ids.ID, request []byte) ([]byte, error) // Gossip sends given gossip message to peers Gossip(gossip []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) }
NetworkClient defines ability to send request / response through the Network
func NewNetworkClient ¶
func NewNetworkClient(network Network) NetworkClient
NewNetworkClient returns Client for a given network
Click to show internal directories.
Click to hide internal directories.