Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithPubSubSession(ctx context.Context, session *PubSubSession) context.Context
- func DefaultCfxClientConfig() clientConfig
- func HookMiddlewares(provider *providers.MiddlewarableProvider, url, space string, ...)
- func HookRedirectHttpHeader()
- func MustInit()
- func MustNewCfxClient(url string, options ...ClientOption) *sdk.Client
- func MustNewCfxClientsFromViper(options ...ClientOption) (clients []*sdk.Client)
- func MustNewEthClient(url string, options ...ClientOption) *web3go.Client
- func MustNewEthClientsFromViper(options ...ClientOption) (clients []*web3go.Client)
- func MustNewEthDataCacheClientFromViper() cacheRpc.Interface
- func NewCfxClient(url string, options ...ClientOption) (*sdk.Client, error)
- func NewEthClient(url string, options ...ClientOption) (*web3go.Client, error)
- func Url2NodeName(url string) string
- type CfxCoreClient
- func (c CfxCoreClient) GetBestBlockHash() (types.Hash, error)
- func (c CfxCoreClient) GetClientVersion() (string, error)
- func (c CfxCoreClient) GetEpochNumber(epochs ...*types.Epoch) (*hexutil.Big, error)
- func (c CfxCoreClient) GetGasPrice() (*hexutil.Big, error)
- func (c CfxCoreClient) GetStatus() (types.Status, error)
- type ClientOption
- func WithCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration) ClientOption
- func WithClientHookMetrics(hook bool) ClientOption
- func WithClientMaxConnsPerHost(maxConns int) ClientOption
- func WithClientRequestTimeout(reqTimeout time.Duration) ClientOption
- func WithClientRetryCount(retry int) ClientOption
- func WithClientRetryInterval(retryInterval time.Duration) ClientOption
- type ClientOptioner
- type EthNearHeadCache
- type MiddlewareHookFlag
- type Protocol
- type PubSubLimitConfig
- type PubSubLimitError
- type PubSubLimiter
- type PubSubLimiterStats
- type PubSubSession
- type PubSubSubscriptionPermit
- type Server
- type Web3goClient
Constants ¶
const ( ProtocolHttp = "HTTP" ProtocolWS = "WS" )
Variables ¶
var ( // DefaultShutdownTimeout is default timeout to shutdown RPC server. DefaultShutdownTimeout = 3 * time.Second )
Functions ¶
func ContextWithPubSubSession ¶
func ContextWithPubSubSession(ctx context.Context, session *PubSubSession) context.Context
ContextWithPubSubSession stores the current PubSub session in a request context.
func DefaultCfxClientConfig ¶
func DefaultCfxClientConfig() clientConfig
func HookMiddlewares ¶
func HookMiddlewares(provider *providers.MiddlewarableProvider, url, space string, flags ...MiddlewareHookFlag)
func HookRedirectHttpHeader ¶
func HookRedirectHttpHeader()
HookRedirectHttpHeader registers an event handler before sending client HTTP request, which will forward HTTP headers to the requested RPC service.
func MustNewCfxClient ¶
func MustNewCfxClient(url string, options ...ClientOption) *sdk.Client
func MustNewCfxClientsFromViper ¶
func MustNewCfxClientsFromViper(options ...ClientOption) (clients []*sdk.Client)
func MustNewEthClient ¶
func MustNewEthClient(url string, options ...ClientOption) *web3go.Client
func MustNewEthClientsFromViper ¶
func MustNewEthClientsFromViper(options ...ClientOption) (clients []*web3go.Client)
func NewCfxClient ¶
func NewCfxClient(url string, options ...ClientOption) (*sdk.Client, error)
func NewEthClient ¶
func NewEthClient(url string, options ...ClientOption) (*web3go.Client, error)
func Url2NodeName ¶
Types ¶
type CfxCoreClient ¶
type CfxCoreClient struct {
sdk.ClientOperator
// contains filtered or unexported fields
}
func NewCfxCoreClient ¶
func NewCfxCoreClient(client sdk.ClientOperator) *CfxCoreClient
func (CfxCoreClient) GetBestBlockHash ¶
func (c CfxCoreClient) GetBestBlockHash() (types.Hash, error)
func (CfxCoreClient) GetClientVersion ¶
func (c CfxCoreClient) GetClientVersion() (string, error)
func (CfxCoreClient) GetEpochNumber ¶
func (CfxCoreClient) GetGasPrice ¶
func (c CfxCoreClient) GetGasPrice() (*hexutil.Big, error)
type ClientOption ¶
type ClientOption func(opt ClientOptioner)
func WithCircuitBreaker ¶
func WithCircuitBreaker(maxFail int, failTimeWindow, openColdTime time.Duration) ClientOption
func WithClientHookMetrics ¶
func WithClientHookMetrics(hook bool) ClientOption
func WithClientMaxConnsPerHost ¶
func WithClientMaxConnsPerHost(maxConns int) ClientOption
func WithClientRequestTimeout ¶
func WithClientRequestTimeout(reqTimeout time.Duration) ClientOption
func WithClientRetryCount ¶
func WithClientRetryCount(retry int) ClientOption
func WithClientRetryInterval ¶
func WithClientRetryInterval(retryInterval time.Duration) ClientOption
type ClientOptioner ¶
type EthNearHeadCache ¶
func NewEthNearHeadCacheFromViper ¶
func NewEthNearHeadCacheFromViper(url string) (*EthNearHeadCache, error)
func (*EthNearHeadCache) Close ¶
func (c *EthNearHeadCache) Close()
type MiddlewareHookFlag ¶
type MiddlewareHookFlag int
MiddlewareHookFlag represents the type for middleware hook flags.
const ( // MiddlewareHookNone represents no middleware hooks enabled. MiddlewareHookNone MiddlewareHookFlag = 0 // MiddlewareHookAll enables all middleware hooks. MiddlewareHookAll MiddlewareHookFlag = ^MiddlewareHookFlag(0) // MiddlewareHookLog enables logging middleware hook. MiddlewareHookLog MiddlewareHookFlag = 1 << iota // MiddlewareHookLogMetrics enables metrics logging middleware hook. MiddlewareHookLogMetrics )
type PubSubLimitConfig ¶
type PubSubLimitConfig struct {
MaxConnections int `default:"10000"`
MaxConnectionsPerIP int `default:"20"`
MaxSubscriptions int `default:"50000"`
MaxSubscriptionsPerIP int `default:"100"`
MaxSubscriptionsPerConnection int `default:"20"`
}
PubSubLimitConfig controls resource bounds for WebSocket PubSub traffic. A zero value for any field disables that specific bound.
type PubSubLimitError ¶
PubSubLimitError describes which PubSub resource bound was exceeded.
func (*PubSubLimitError) Error ¶
func (e *PubSubLimitError) Error() string
type PubSubLimiter ¶
type PubSubLimiter struct {
// contains filtered or unexported fields
}
PubSubLimiter tracks WebSocket PubSub connection and subscription quotas.
func NewPubSubLimiter ¶
func NewPubSubLimiter(config PubSubLimitConfig) *PubSubLimiter
NewPubSubLimiter builds a PubSubLimiter with the supplied bounds.
func NewPubSubLimiterFromViper ¶
func NewPubSubLimiterFromViper() *PubSubLimiter
NewPubSubLimiterFromViper builds a PubSubLimiter from requestControl.pubsub.
func (*PubSubLimiter) AcquireConnection ¶
func (l *PubSubLimiter) AcquireConnection(ip string) (*PubSubSession, error)
AcquireConnection reserves quota for one WebSocket connection.
func (*PubSubLimiter) Stats ¶
func (l *PubSubLimiter) Stats() PubSubLimiterStats
Stats returns a consistent copy of current PubSub resource counters.
type PubSubLimiterStats ¶
type PubSubLimiterStats struct {
Connections int
ConnectionsByIP map[string]int
Subscriptions int
SubscriptionsByIP map[string]int
}
PubSubLimiterStats is a snapshot of active PubSub resource usage.
type PubSubSession ¶
type PubSubSession struct {
// contains filtered or unexported fields
}
PubSubSession represents one accepted WebSocket connection.
func PubSubSessionFromContext ¶
func PubSubSessionFromContext(ctx context.Context) (*PubSubSession, bool)
PubSubSessionFromContext returns the current PubSub session from a request context.
func (*PubSubSession) AcquireSubscription ¶
func (s *PubSubSession) AcquireSubscription() (*PubSubSubscriptionPermit, error)
AcquireSubscription reserves quota for one subscription on this WebSocket connection.
func (*PubSubSession) Close ¶
func (s *PubSubSession) Close()
Close releases this WebSocket connection and any remaining subscription quota.
type PubSubSubscriptionPermit ¶
type PubSubSubscriptionPermit struct {
// contains filtered or unexported fields
}
PubSubSubscriptionPermit is the quota permit for one active PubSub subscription.
func (*PubSubSubscriptionPermit) Release ¶
func (permit *PubSubSubscriptionPermit) Release()
Release releases this subscription quota once.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves JSON RPC services.
func MustNewServer ¶
func MustNewServer( name string, rpcs map[string]interface{}, pubSubLimiter *PubSubLimiter, middlewares ...handlers.Middleware, ) *Server
MustNewServer creates an instance of Server with specified RPC services.
type Web3goClient ¶
type Web3goClient struct {
*web3go.Client
util.EthBlockNumberResolver
URL string
Eth ethCacheClient
Trace traceCacheClient
// contains filtered or unexported fields
}
Web3goClient wraps web3go.Client with additional caching and resolution capabilities.
func NewWeb3goClient ¶
func NewWeb3goClient( url string, client *web3go.Client, dataCache cacheRpc.Interface, nearHeadCache *EthNearHeadCache, ) (*Web3goClient, error)
func (Web3goClient) Close ¶
func (w3c Web3goClient) Close()
func (Web3goClient) NodeName ¶
func (w3c Web3goClient) NodeName() string