net

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorChainMsgBusBeenBound chain msg bus has been bound
	ErrorChainMsgBusBeenBound = errors.New("chain msg bus has been bound")
	// ErrorNetNotRunning net instance is not running
	ErrorNetNotRunning = errors.New("net instance is not running")
)
View Source
var ErrorNetType = errors.New("error net type")

ErrorNetType error net type

View Source
var GlobalNetLogger protocol.Logger

GlobalNetLogger protocol.Logger

Functions

func CreateFlagWithPrefixAndMsgType

func CreateFlagWithPrefixAndMsgType(prefix string, msgType netPb.NetMsg_MsgType) string

CreateFlagWithPrefixAndMsgType will join prefix with msg type string.

func CreateMsgHandlerForMsgBus

func CreateMsgHandlerForMsgBus(
	netService *NetService,
	topic msgbus.Topic,
	logMsgDescription string,
	msgType netPb.NetMsg_MsgType) func(chainId string, node string, data []byte) error

CreateMsgHandlerForMsgBus func

func HandleMsgBusSubscriberOnMessage

func HandleMsgBusSubscriberOnMessage(
	netService *NetService,
	msgType netPb.NetMsg_MsgType,
	logMsgDescription string,
	message *msgbus.Message) error

HandleMsgBusSubscriberOnMessage is a handler used for msg-bus subscriber OnMessage method.

func NewNetMsg

func NewNetMsg(msg []byte, msgType netPb.NetMsg_MsgType, to string) *netPb.NetMsg

NewNetMsg create a new netPb.NetMsg .

Types

type ConfigWatcher

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

ConfigWatcher is a implementation of protocol.Watcher.

func (*ConfigWatcher) Module

func (cw *ConfigWatcher) Module() string

Module ConfigWatcher

func (*ConfigWatcher) Watch

func (cw *ConfigWatcher) Watch(chainConfig *configPb.ChainConfig) error

Watch ConfigWatcher

type ConsensusMsgSubscriber

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

ConsensusMsgSubscriber is a subscriber implementation subscribe consensus msg for msgbus.

func (*ConsensusMsgSubscriber) OnMessage

func (cms *ConsensusMsgSubscriber) OnMessage(message *msgbus.Message)

OnMessage ConsensusMsgSubscriber

func (*ConsensusMsgSubscriber) OnQuit

func (cms *ConsensusMsgSubscriber) OnQuit()

OnQuit ConsensusMsgSubscriber

type ConsistentMsgSubscriber

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

ConsistentMsgSubscriber is a subscriber implementation subscribe consistent msg for msgbus.

func (*ConsistentMsgSubscriber) OnMessage

func (cms *ConsistentMsgSubscriber) OnMessage(message *msgbus.Message)

OnMessage ConsistentMsgSubscriber

func (*ConsistentMsgSubscriber) OnQuit

func (cms *ConsistentMsgSubscriber) OnQuit()

OnQuit ConsistentMsgSubscriber

type MsgForMsgBusHandler

type MsgForMsgBusHandler func(chainId string, from string, msg []byte) error

MsgForMsgBusHandler is a handler function that receive the msg from net than publish to msg-bus.

type NetContractEventSubscribe

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

NetContractEventSubscribe is a implementation of msgbus.Subscriber

func (*NetContractEventSubscribe) OnMessage

func (n *NetContractEventSubscribe) OnMessage(msg *msgbus.Message)

OnMessage on message

func (*NetContractEventSubscribe) OnQuit

func (n *NetContractEventSubscribe) OnQuit()

OnQuit on quit

type NetFactory

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

NetFactory provide a way to create net instance.

func (*NetFactory) Apply

func (nf *NetFactory) Apply(opts ...NetOption) error

Apply options.

func (*NetFactory) NewNet

func (nf *NetFactory) NewNet(netType protocol.NetType, opts ...NetOption) (protocol.Net, error)

NewNet create a new net instance.

type NetOption

type NetOption func(cfg *NetFactory) error

NetOption is a function apply options to net instance.

func WithBlackAddresses

func WithBlackAddresses(blackAddresses ...string) NetOption

WithBlackAddresses set addresses of the build for blacklist.

func WithBlackNodeIds

func WithBlackNodeIds(blackNodeIds ...string) NetOption

WithBlackNodeIds set ids of the build for blacklist.

func WithCrypto

func WithCrypto(pkMode bool, keyFile string, certFile string) NetOption

WithCrypto set private key file and tls cert file for the net to create connection.

func WithInsecurity

func WithInsecurity(isInsecurity bool) NetOption

WithInsecurity option

func WithListenAddr

func WithListenAddr(addr string) NetOption

WithListenAddr set addr that the local net will listen on.

func WithMaxConnCountAllowed

func WithMaxConnCountAllowed(max int) NetOption

WithMaxConnCountAllowed set max count of connections for each peer that connected to us.

func WithMaxPeerCountAllowed

func WithMaxPeerCountAllowed(max int) NetOption

WithMaxPeerCountAllowed set max count of build that connected to us.

func WithMsgCompression

func WithMsgCompression(enable bool) NetOption

WithMsgCompression set whether compressing the payload when sending msg.

func WithPeerEliminationStrategy

func WithPeerEliminationStrategy(strategy int) NetOption

WithPeerEliminationStrategy set the strategy for eliminating node when the count of build that connected to us reach the max value.

func WithPeerStreamPoolSize

func WithPeerStreamPoolSize(size int) NetOption

WithPeerStreamPoolSize set the max stream pool size for every node that connected to us.

func WithPktEnable

func WithPktEnable(pktEnable bool) NetOption

WithPktEnable option

func WithPriorityControlEnable

func WithPriorityControlEnable(priorityCtrlEnable bool) NetOption

WithPriorityControlEnable config priority controller

func WithPubSubMaxMessageSize

func WithPubSubMaxMessageSize(size int) NetOption

WithPubSubMaxMessageSize set max message size (M) for pub/sub.

func WithReadySignalC

func WithReadySignalC(signalC chan struct{}) NetOption

WithReadySignalC option

func WithSeeds

func WithSeeds(seeds ...string) NetOption

WithSeeds set addresses of discovery service node.

type NetService

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

NetService provide a net service for modules.

func NewNetService

func NewNetService(chainId string, localNet protocol.Net, ac protocol.AccessControlProvider) *NetService

NewNetService create a new net service instance.

func (*NetService) Apply

func (ns *NetService) Apply(opts ...NetServiceOption) error

Apply the net service options given.

func (*NetService) BroadcastMsg

func (ns *NetService) BroadcastMsg(msg []byte, msgType netPb.NetMsg_MsgType) error

BroadcastMsg broadcast a net msg to other nodes belongs to the same chain.

func (*NetService) CancelConsensusSubscribe

func (ns *NetService) CancelConsensusSubscribe(msgType netPb.NetMsg_MsgType) error

CancelConsensusSubscribe stop receiving the msg which type is the given netPb.NetMsg_MsgType that be broadcast with ConsensusBroadcastMsg method by the other consensus node.

func (*NetService) CancelSubscribe

func (ns *NetService) CancelSubscribe(msgType netPb.NetMsg_MsgType) error

CancelSubscribe stop receiving the msg from the pub-sub topic subscribed.

func (*NetService) ConfigWatcher

func (ns *NetService) ConfigWatcher() protocol.Watcher

ConfigWatcher return a implementation of protocol.Watcher. It is used for refreshing the config.

func (*NetService) ConsensusBroadcastMsg

func (ns *NetService) ConsensusBroadcastMsg(msg []byte, msgType netPb.NetMsg_MsgType) error

ConsensusBroadcastMsg only broadcast a net msg to other consensus nodes belongs to the same chain.

func (*NetService) ConsensusSubscribe

func (ns *NetService) ConsensusSubscribe(msgType netPb.NetMsg_MsgType, handler protocol.MsgHandler) error

ConsensusSubscribe create a listener for receiving the msg which type is the given netPb.NetMsg_MsgType that be broadcast with ConsensusBroadcastMsg method by the other consensus node.

func (*NetService) GetChainNodesInfo

func (ns *NetService) GetChainNodesInfo() ([]*protocol.ChainNodeInfo, error)

GetChainNodesInfo return the base info of the nodes connected.

func (*NetService) GetChainNodesInfoProvider

func (ns *NetService) GetChainNodesInfoProvider() protocol.ChainNodesInfoProvider

GetChainNodesInfoProvider return a protocol.ChainNodesInfoProvider.

func (*NetService) GetNodeUidByCertId

func (ns *NetService) GetNodeUidByCertId(certId string) (string, error)

GetNodeUidByCertId return the id of the node connected to us which mapped to tls cert id given. node id and tls cert id relation will be mapped after connection created success.

func (*NetService) NetConfigSubscribe

func (ns *NetService) NetConfigSubscribe() msgbus.Subscriber

NetConfigSubscribe ConfigWatcher return a implementation of protocol.Watcher. It is used for refreshing the config.

func (*NetService) ReceiveMsg

func (ns *NetService) ReceiveMsg(msgType netPb.NetMsg_MsgType, handler protocol.MsgHandler) error

ReceiveMsg create a listener for receiving the msg which type is the given netPb.NetMsg_MsgType that be sent with ConsensusBroadcastMsg method by the other consensus node.

func (*NetService) SendMsg

func (ns *NetService) SendMsg(msg []byte, msgType netPb.NetMsg_MsgType, to ...string) error

SendMsg send a net msg to the nodes which node ids are the given strings.

func (*NetService) Start

func (ns *NetService) Start() error

Start the net-service.

func (*NetService) Stop

func (ns *NetService) Stop() error

Stop the net-service.

func (*NetService) Subscribe

func (ns *NetService) Subscribe(msgType netPb.NetMsg_MsgType, handler protocol.MsgHandler) error

Subscribe a pub-sub topic for receiving the msg that be broadcast by the other node.

func (*NetService) VmWatcher

func (ns *NetService) VmWatcher() protocol.VmWatcher

VmWatcher return an implementation of protocol.VmWatcher. It is used for refreshing revoked peer which use revoked tls cert.

type NetServiceFactory

type NetServiceFactory struct {
}

NetServiceFactory is a net service instance factory.

func (*NetServiceFactory) NewNetService

func (nsf *NetServiceFactory) NewNetService(
	net protocol.Net,
	chainId string,
	ac protocol.AccessControlProvider,
	chainConf protocol.ChainConf,
	opts ...NetServiceOption) (protocol.NetService, error)

NewNetService create a new net service instance.

type NetServiceOption

type NetServiceOption func(ns *NetService) error

NetServiceOption is a net service option.

func WithConsensusNodeUid

func WithConsensusNodeUid(consensusNodeUid ...string) NetServiceOption

WithConsensusNodeUid set the consensus node id list for net service. This list will be used for broadcast consensus msg to consensus build.

func WithMsgBus

func WithMsgBus(msgBus msgbus.MessageBus) NetServiceOption

WithMsgBus set msg-bus.

type SyncBlockMsgSubscriber

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

SyncBlockMsgSubscriber is a subscriber implementation subscribe sync block msg for msgbus.

func (*SyncBlockMsgSubscriber) OnMessage

func (cms *SyncBlockMsgSubscriber) OnMessage(message *msgbus.Message)

OnMessage SyncBlockMsgSubscriber

func (*SyncBlockMsgSubscriber) OnQuit

func (cms *SyncBlockMsgSubscriber) OnQuit()

OnQuit SyncBlockMsgSubscriber

type TxPoolMsgSubscriber

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

TxPoolMsgSubscriber is a subscriber implementation subscribe tx pool msg for msgbus.

func (*TxPoolMsgSubscriber) OnMessage

func (cms *TxPoolMsgSubscriber) OnMessage(message *msgbus.Message)

OnMessage TxPoolMsgSubscriber

func (*TxPoolMsgSubscriber) OnQuit

func (cms *TxPoolMsgSubscriber) OnQuit()

OnQuit TxPoolMsgSubscriber

type VmWatcher

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

VmWatcher NetService callback certificate management

func (*VmWatcher) Callback

func (v *VmWatcher) Callback(contractName string, _ []byte) error

Callback VmWatcher

func (*VmWatcher) ContractNames

func (v *VmWatcher) ContractNames() []string

ContractNames VmWatcher

func (*VmWatcher) Module

func (v *VmWatcher) Module() string

Module VmWatcher

Jump to

Keyboard shortcuts

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