connection

package
v0.33.21-fix-get-highe... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 13, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultClientTimeout = 3 * time.Second

DefaultClientTimeout is used when making a GRPC request to a collection or 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

func NewCache(
	log zerolog.Logger,
	metrics module.GRPCConnectionPoolMetrics,
	maxSize int,
) (*Cache, error)

NewCache creates a new Cache with the specified maximum size and the underlying LRU cache.

func (*Cache) GetConnected added in v0.33.12

func (c *Cache) GetConnected(
	address string,
	timeout time.Duration,
	networkPubKey crypto.PublicKey,
	connectFn func(string, time.Duration, crypto.PublicKey, *CachedClient) (*grpc.ClientConn, error),
) (*CachedClient, error)

GetConnected returns a CachedClient for the given address that has an active connection. If the address is not in the cache, it creates a new entry and connects.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of CachedClient entries in the cache.

func (*Cache) MaxSize

func (c *Cache) MaxSize() int

MaxSize returns the maximum size of the cache.

type CachedClient

type CachedClient struct {
	// contains filtered or unexported fields
}

CachedClient represents a gRPC client connection that is cached for reuse.

func (*CachedClient) AddRequest added in v0.33.12

func (cc *CachedClient) AddRequest() func()

AddRequest increments the in-flight request counter for the CachedClient. It returns a function that should be called when the request completes to decrement the counter.

func (*CachedClient) Address

func (cc *CachedClient) Address() string

Address returns the address of the remote server.

func (*CachedClient) ClientConn

func (cc *CachedClient) ClientConn() *grpc.ClientConn

ClientConn returns the underlying gRPC client connection.

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.

func (*CachedClient) CloseRequested added in v0.33.12

func (cc *CachedClient) CloseRequested() bool

CloseRequested returns true if the CachedClient has been marked for closure.

func (*CachedClient) Invalidate added in v0.33.12

func (cc *CachedClient) Invalidate()

Invalidate removes the CachedClient from the cache and closes 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(
	logger zerolog.Logger,
	metrics module.AccessMetrics,
	cache *Cache,
	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,
	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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL