Documentation ¶
Index ¶
- Constants
- func WithClientTimeoutOption(timeout time.Duration) grpc.DialOption
- type Cache
- func (c *Cache) Add(address string, client *CachedClient) (evicted bool)
- func (c *Cache) Contains(address string) (containKey bool)
- func (c *Cache) Get(address string) (*CachedClient, bool)
- func (c *Cache) GetOrAdd(address string, timeout time.Duration) (*CachedClient, bool)
- func (c *Cache) Len() int
- func (c *Cache) MaxSize() int
- func (c *Cache) Remove(address string) (present bool)
- type CachedClient
- type CircuitBreakerConfig
- type ConnectionFactory
- type ConnectionFactoryImpl
- func (cf *ConnectionFactoryImpl) GetAccessAPIClient(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error)
- func (cf *ConnectionFactoryImpl) GetAccessAPIClientWithPort(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error)
- func (cf *ConnectionFactoryImpl) GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)
- type Manager
- type ProxyConnectionFactory
Constants ¶
const ( AccessClient clientType = iota ExecutionClient )
const DefaultClientTimeout = 3 * time.Second
DefaultClientTimeout is used when making a GRPC request to a collection node or an execution node.
Variables ¶
This section is empty.
Functions ¶
func WithClientTimeoutOption ¶
func WithClientTimeoutOption(timeout time.Duration) grpc.DialOption
WithClientTimeoutOption is a helper function to create a GRPC dial option with the specified client timeout interceptor.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache represents a cache of CachedClient instances with a given maximum size.
func NewCache ¶
NewCache creates a new Cache with the specified maximum size and the underlying LRU cache.
func (*Cache) Add ¶
func (c *Cache) Add(address string, client *CachedClient) (evicted bool)
Add adds a CachedClient to the cache with the given address. It returns a boolean indicating whether an existing entry was evicted.
func (*Cache) Contains ¶
Contains checks if the cache contains an entry with the given address. It returns a boolean indicating whether the address is present in the cache.
func (*Cache) Get ¶
func (c *Cache) Get(address string) (*CachedClient, bool)
Get retrieves the CachedClient for the given address from the cache. It returns the CachedClient and a boolean indicating whether the entry exists in the cache.
func (*Cache) GetOrAdd ¶
GetOrAdd atomically gets the CachedClient for the given address from the cache, or adds a new one if none existed. New entries are added to the cache with their mutex locked. This ensures that the caller gets priority when working with the new client, allowing it to create the underlying connection. Clients retrieved from the cache are returned without modifying their lock.
type CachedClient ¶
type CachedClient struct { ClientConn *grpc.ClientConn Address string // contains filtered or unexported fields }
CachedClient represents a gRPC client connection that is cached for reuse.
func (*CachedClient) Close ¶
func (cc *CachedClient) Close()
Close closes the CachedClient connection. It marks the connection for closure and waits asynchronously for ongoing requests to complete before closing the connection.
type CircuitBreakerConfig ¶
type CircuitBreakerConfig struct { // Enabled specifies whether the circuit breaker is enabled for collection and execution API clients. Enabled bool // RestoreTimeout specifies the duration after which the circuit breaker will restore the connection to the client // after closing it due to failures. RestoreTimeout time.Duration // MaxFailures specifies the maximum number of failed calls to the client that will cause the circuit breaker // to close the connection. MaxFailures uint32 // MaxRequests specifies the maximum number of requests to check if connection restored after timeout. MaxRequests uint32 }
CircuitBreakerConfig is a configuration struct for the circuit breaker.
type ConnectionFactory ¶
type ConnectionFactory interface { // GetAccessAPIClient gets an access API client for the specified address using the default CollectionGRPCPort, networkPubKey is optional, // and it is used for secure gRPC connection. Can be nil for an unsecured connection. // The returned io.Closer should close the connection after the call if no error occurred during client creation. GetAccessAPIClient(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error) // GetAccessAPIClientWithPort gets an access API client for the specified address with port, networkPubKey is optional, // and it is used for secure gRPC connection. Can be nil for an unsecured connection. // The returned io.Closer should close the connection after the call if no error occurred during client creation. GetAccessAPIClientWithPort(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error) // GetExecutionAPIClient gets an execution API client for the specified address using the default ExecutionGRPCPort. // The returned io.Closer should close the connection after the call if no error occurred during client creation. GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error) }
ConnectionFactory is an interface for creating access and execution API clients.
type ConnectionFactoryImpl ¶
type ConnectionFactoryImpl struct { CollectionGRPCPort uint ExecutionGRPCPort uint CollectionNodeGRPCTimeout time.Duration ExecutionNodeGRPCTimeout time.Duration AccessMetrics module.AccessMetrics Log zerolog.Logger Manager Manager }
func (*ConnectionFactoryImpl) GetAccessAPIClient ¶
func (cf *ConnectionFactoryImpl) GetAccessAPIClient(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error)
GetAccessAPIClient gets an access API client for the specified address using the default CollectionGRPCPort. The networkPubKey is the public key used for secure gRPC connection. Can be nil for an unsecured connection. The returned io.Closer should close the connection after the call if no error occurred during client creation.
func (*ConnectionFactoryImpl) GetAccessAPIClientWithPort ¶
func (cf *ConnectionFactoryImpl) GetAccessAPIClientWithPort(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error)
GetAccessAPIClientWithPort gets an access API client for the specified address with port. The networkPubKey is the public key used for secure gRPC connection. Can be nil for an unsecured connection. The returned io.Closer should close the connection after the call if no error occurred during client creation.
func (*ConnectionFactoryImpl) GetExecutionAPIClient ¶
func (cf *ConnectionFactoryImpl) GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)
GetExecutionAPIClient gets an execution API client for the specified address using the default ExecutionGRPCPort. The returned io.Closer should close the connection after the call if no error occurred during client creation.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager provides methods for getting and managing gRPC client connections.
func NewManager ¶
func NewManager( cache *Cache, logger zerolog.Logger, metrics module.AccessMetrics, maxMsgSize uint, circuitBreakerConfig CircuitBreakerConfig, compressorName string, ) Manager
NewManager creates a new Manager with the specified parameters.
func (*Manager) GetConnection ¶
func (m *Manager) GetConnection( grpcAddress string, timeout time.Duration, clientType clientType, networkPubKey crypto.PublicKey, ) (*grpc.ClientConn, io.Closer, error)
GetConnection returns a gRPC client connection for the given grpcAddress and timeout. If a cache is used, it retrieves a cached connection, otherwise creates a new connection. It returns the client connection and an io.Closer to close the connection when done. The networkPubKey is the public key used for creating secure gRPC connection. Can be nil for an unsecured connection.
type ProxyConnectionFactory ¶
type ProxyConnectionFactory struct { ConnectionFactory // contains filtered or unexported fields }
ProxyConnectionFactory wraps an existing ConnectionFactory and allows getting API clients for a target address.
func (*ProxyConnectionFactory) GetAccessAPIClient ¶
func (p *ProxyConnectionFactory) GetAccessAPIClient(address string, networkPubKey crypto.PublicKey) (access.AccessAPIClient, io.Closer, error)
GetAccessAPIClient gets an access API client for a target address using the default CollectionGRPCPort. The networkPubKey is the public key used for a secure gRPC connection. It can be nil for an unsecured connection. The returned io.Closer should close the connection after the call if no error occurred during client creation.
func (*ProxyConnectionFactory) GetExecutionAPIClient ¶
func (p *ProxyConnectionFactory) GetExecutionAPIClient(address string) (execution.ExecutionAPIClient, io.Closer, error)
GetExecutionAPIClient gets an execution API client for a target address using the default ExecutionGRPCPort. The returned io.Closer should close the connection after the call if no error occurred during client creation.