Documentation
¶
Overview ¶
Package grpc provides nodes grpc connection utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotVersionedWatcher = fmt.Errorf("client watcher is not versioned")
ErrNotVersionedWatcher is an error returned when versioned specific methods are called for a non-versioned client.
Functions ¶
This section is empty.
Types ¶
type ConnWithNodeMeta ¶
type ConnWithNodeMeta struct {
*grpc.ClientConn
Node *node.Node
}
ConnWithNodeMeta is a gRPC client connection together with node metadata.
type NodeSelectionFeedback ¶
type NodeSelectionFeedback struct {
// ID is the node identifier.
ID signature.PublicKey
// Bad being non-nil signals that the currently selected node is bad and contains the reason
// that lead to the decision.
Bad error
}
NodeSelectionFeedback is feedback to the node selection policy.
type NodeSelectionPolicy ¶
type NodeSelectionPolicy interface {
// UpdateNodes updates the set of available nodes.
UpdateNodes([]signature.PublicKey)
// UpdatePolicy submits feedback to the policy which can cause the policy to update its current
// node selection.
UpdatePolicy(feedback NodeSelectionFeedback)
// Pick picks a node from the set of available nodes accoording to the policy.
Pick() signature.PublicKey
}
NodeSelectionPolicy is a node selection policy.
func NewRoundRobinNodeSelectionPolicy ¶
func NewRoundRobinNodeSelectionPolicy() NodeSelectionPolicy
NewRoundRobinNodeSelectionPolicy creates a new round-robin node selection policy.
type NodesClient ¶
type NodesClient interface {
// GetConnections returns the set of connections to nodes.
GetConnections() []*grpc.ClientConn
// GetConnectionsWithMeta returns the set of connections to nodes including node metadata
// for each connection.
GetConnectionsWithMeta() []*ConnWithNodeMeta
// GetConnectionsMap returns the set of connections to nodes including node metadata
// for each connection.
GetConnectionsMap() map[signature.PublicKey]*ConnWithNodeMeta
// GetConnection returns a connection based on the configured node selection policy.
//
// If no connections are available this method will return nil.
GetConnection() *grpc.ClientConn
// UpdateNodeSelectionPolicy submits feedback to the policy which can cause the policy to update
// its current node selection.
UpdateNodeSelectionPolicy(feedback NodeSelectionFeedback)
// EnsureVersion waits for the client to be fully synced to the given watcher version.
//
// When client is using a non-versioned watcher, this method should return ErrNotVersionedWatcher error.
EnsureVersion(ctx context.Context, version int64) error
// Initialized returns a channel that will be closed once the first connection is available.
Initialized() <-chan struct{}
}
NodesClient is a node gRPC client interface. It automatically maintains gRPC connections to all nodes as directed by the node watcher.
func NewNodesClient ¶
func NewNodesClient(ctx context.Context, nw nodes.NodeDescriptorLookup, options ...Option) (NodesClient, error)
NewNodesClient creates a new nodes gRPC client.
type Option ¶
type Option func(nc *nodesClient)
Option is an option for NewNodesClient.
func WithClientAuthentication ¶
WithClientAuthentication is an option for configuring client authentication on TLS connections.
func WithCloseDelay ¶
WithCloseDelay is an option for configuring the connection close delay after rotating a connection.
If not configured it defaults to 5 seconds.
func WithNodeSelectionPolicy ¶
func WithNodeSelectionPolicy(policy NodeSelectionPolicy) Option
WithNodeSelectionPolicy is an option for configuring the node selection policy.
If not configured it defaults to the round-robin policy.