Documentation ¶
Index ¶
- Constants
- Variables
- func EthFactory() *factory
- func Factory() *factory
- func NewServer(nf nodeFactory, groupConf map[Group]UrlConfig) *rpc.Server
- type CfxClientProvider
- type CfxNode
- type EthClientProvider
- type EthNode
- type Group
- type HealthMonitor
- type LocalRouter
- type Manager
- func (m *Manager) Add(url string)
- func (m *Manager) Distribute(key []byte) Node
- func (m *Manager) Get(url string) Node
- func (m *Manager) HealthyEpoch() uint64
- func (m *Manager) List() []Node
- func (m *Manager) Remove(url string)
- func (m *Manager) ReportEpoch(nodeName string, epoch uint64)
- func (m *Manager) ReportHealthy(nodeName string)
- func (m *Manager) ReportUnhealthy(nodeName string, remind bool, reason error)
- func (m *Manager) Route(key []byte) string
- func (m *Manager) String() string
- type Node
- type NodeRpcRouter
- type RedisRepartitionResolver
- type RedisRouter
- type RepartitionResolver
- type Router
- type SimpleRepartitionResolver
- type Status
- type UrlConfig
- type Web3goClient
Constants ¶
const ( // core space fullnode groups GroupCfxHttp = "cfxhttp" GroupCfxWs = "cfxws" GroupCfxLogs = "cfxlog" GroupCfxArchives = "cfxarchives" // evm space fullnode groups GroupEthHttp = "ethhttp" GroupEthWs = "ethws" GroupEthLogs = "ethlogs" )
Variables ¶
var (
)Functions ¶
Types ¶
type CfxClientProvider ¶
type CfxClientProvider struct {
// contains filtered or unexported fields
}
CfxClientProvider provides core space client by router.
func NewCfxClientProvider ¶
func NewCfxClientProvider(router Router) *CfxClientProvider
func (*CfxClientProvider) GetClientByIP ¶
func (p *CfxClientProvider) GetClientByIP(ctx context.Context) (sdk.ClientOperator, error)
GetClientByIP gets client of normal HTTP group by remote IP address.
func (*CfxClientProvider) GetClientByIPGroup ¶
func (p *CfxClientProvider) GetClientByIPGroup(ctx context.Context, group Group) (sdk.ClientOperator, error)
GetClientByIPGroup gets client of specific group by remote IP address.
type CfxNode ¶
type CfxNode struct { sdk.ClientOperator // contains filtered or unexported fields }
CfxNode represents a core space fullnode with friendly name and health status.
func NewCfxNode ¶
func NewCfxNode(group Group, name, url string, hm HealthMonitor) *CfxNode
NewCfxNode creates an instance of core space fullnode and start to monitor node health in a separate goroutine until node closed.
func (*CfxNode) LatestEpochNumber ¶
LatestEpochNumber returns the latest epoch height of the core space fullnode
type EthClientProvider ¶
type EthClientProvider struct {
// contains filtered or unexported fields
}
EthClientProvider provides evm space client by router.
func NewEthClientProvider ¶
func NewEthClientProvider(router Router) *EthClientProvider
func (*EthClientProvider) GetClientByIP ¶
func (p *EthClientProvider) GetClientByIP(ctx context.Context) (*Web3goClient, error)
GetClientByIP gets client of normal HTTP group by remote IP address.
func (*EthClientProvider) GetClientByIPGroup ¶
func (p *EthClientProvider) GetClientByIPGroup(ctx context.Context, group Group) (*Web3goClient, error)
GetClientByIPGroup gets client of specific group by remote IP address.
func (*EthClientProvider) GetClientRandom ¶
func (p *EthClientProvider) GetClientRandom() (*Web3goClient, error)
type EthNode ¶
EthNode represents an evm space node with friendly name and health status.
func NewEthNode ¶
func NewEthNode(group Group, name, url string, hm HealthMonitor) *EthNode
NewEthNode creates an instance of evm space node and start to monitor node health in a separate goroutine until node closed.
func (*EthNode) LatestEpochNumber ¶
LatestEpochNumber returns the latest block height of the evm space fullnode
type HealthMonitor ¶
type HealthMonitor interface { // HealthyEpoch returns the healthy epoch number among full nodes. // Usually, it is the middle epoch number of all full nodes. HealthyEpoch() uint64 // ReportEpoch fired when epoch changes. ReportEpoch(nodeName string, epoch uint64) // ReportUnhealthy fired when full node becomes unhealthy or unrecovered for a long time. ReportUnhealthy(nodeName string, remind bool, reason error) // ReportHealthy fired when full node becomes healthy. ReportHealthy(nodeName string) }
HealthMonitor is implemented by any objects that support to monitor full node health.
type LocalRouter ¶
type LocalRouter struct {
// contains filtered or unexported fields
}
LocalRouter routes RPC requests based on local hash ring.
func NewLocalRouter ¶
func NewLocalRouter(group2Urls map[Group][]string) *LocalRouter
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages full node cluster, including: 1. Monitor node health and disable/enable full node automatically. 2. Implements Router interface to route RPC requests to different full nodes in manner of consistent hashing.
func NewManager ¶
func NewManagerWithRepartition ¶
func NewManagerWithRepartition(group Group, nf nodeFactory, urls []string, resolver RepartitionResolver) *Manager
func (*Manager) Distribute ¶
Distribute distributes a full node by specified key.
func (*Manager) HealthyEpoch ¶
HealthyEpoch returns the middle epoch height collected from managed cluster nodes, which is also regarded as the overall health epoch height.
func (*Manager) ReportEpoch ¶
ReportEpoch reports latest epoch height of managed node to manager.
func (*Manager) ReportHealthy ¶
ReportHealthy reports healthy status of managed node to manager.
func (*Manager) ReportUnhealthy ¶
ReportUnhealthy reports unhealthy status of managed node to manager.
type Node ¶
type Node interface { consistent.Member Name() string Url() string Status() Status LatestEpochNumber() (uint64, error) Close() }
Node represents a full node with friendly name and health status.
type NodeRpcRouter ¶
type NodeRpcRouter struct {
// contains filtered or unexported fields
}
NodeRpcRouter routes RPC requests via node management RPC service.
func NewNodeRpcRouter ¶
func NewNodeRpcRouter(client *rpc.Client) *NodeRpcRouter
type RedisRepartitionResolver ¶
type RedisRepartitionResolver struct {
// contains filtered or unexported fields
}
RedisRepartitionResolver implements RepartitionResolver
func NewRedisRepartitionResolver ¶
func NewRedisRepartitionResolver(client *redis.Client, ttl time.Duration, keyPrefix string) *RedisRepartitionResolver
func (*RedisRepartitionResolver) Get ¶
func (r *RedisRepartitionResolver) Get(key uint64) (string, bool)
func (*RedisRepartitionResolver) Put ¶
func (r *RedisRepartitionResolver) Put(key uint64, value string)
type RedisRouter ¶
type RedisRouter struct {
// contains filtered or unexported fields
}
RedisRouter routes RPC requests via redis. It should be used together with RedisRepartitionResolver.
func NewRedisRouter ¶
func NewRedisRouter(client *redis.Client) *RedisRouter
type RepartitionResolver ¶
RepartitionResolver is implemented to support repartition when item added or removed in the consistent hash ring.
type Router ¶
type Router interface { // Route returns the full node URL for specified group and key. Route(group Group, key []byte) string }
Router is used to route RPC requests to multiple full nodes.
func MustNewRouter ¶
MustNewRouter creates an instance of Router.
type SimpleRepartitionResolver ¶
type SimpleRepartitionResolver struct {
// contains filtered or unexported fields
}
func NewSimpleRepartitionResolver ¶
func NewSimpleRepartitionResolver(ttl time.Duration) *SimpleRepartitionResolver
func (*SimpleRepartitionResolver) Get ¶
func (r *SimpleRepartitionResolver) Get(key uint64) (string, bool)
func (*SimpleRepartitionResolver) Put ¶
func (r *SimpleRepartitionResolver) Put(key uint64, value string)
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status represents the node status, including current epoch number and health status.
func (*Status) MarshalJSON ¶
MarshalJSON marshals as JSON.
func (*Status) Update ¶
func (s *Status) Update(n Node, monitor HealthMonitor)
Update heartbeats with node and updates health status.
type Web3goClient ¶
func (*Web3goClient) NodeName ¶
func (w3c *Web3goClient) NodeName() string