Documentation ¶
Index ¶
- Constants
- Variables
- func CreateProtocolIdWithChainIdAndMsgFlag(chainId, msgFlag string) protocol.ID
- func InitLogger(globalNetLogger api.Logger, pubSubLogCreator func(chainId string) api.Logger)
- func LoadChainIdAndFlagWithProtocolId(protocolId protocol.ID) (string, string, error)
- func SetListenAddrStr(hc *host.HostConfig, listenAddrStr string) error
- type WormholeNet
- func (l *WormholeNet) AddAC(chainId string, ac api.AccessControlProvider)
- func (l *WormholeNet) AddSeed(seed string) error
- func (l *WormholeNet) BroadcastWithChainId(chainId string, topic string, data []byte) error
- func (l *WormholeNet) CancelDirectMsgHandle(chainId string, msgFlag string) error
- func (l *WormholeNet) CancelSubscribeWithChainId(chainId string, topic string) error
- func (l *WormholeNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
- func (l *WormholeNet) CryptoConfig() *cryptoConfig
- func (l *WormholeNet) DirectMsgHandle(chainId string, msgFlag string, handler api.DirectMsgHandler) error
- func (l *WormholeNet) ExtensionsConfig() *extensionsConfig
- func (l *WormholeNet) GetNodeUid() string
- func (l *WormholeNet) GetNodeUidByCertId(certId string) (string, error)
- func (l *WormholeNet) HostConfig() *lHost.HostConfig
- func (l *WormholeNet) InitPubSub(chainId string, maxMessageSize int) error
- func (l *WormholeNet) IsRunning() bool
- func (l *WormholeNet) PubSubConfig() *pubSubConfig
- func (l *WormholeNet) ReVerifyPeers(chainId string)
- func (l *WormholeNet) RefreshSeeds(seeds []string) error
- func (l *WormholeNet) SendMsg(chainId string, targetPeer string, msgFlag string, data []byte) error
- func (l *WormholeNet) SetChainCustomTrustRoots(chainId string, roots [][]byte)
- func (l *WormholeNet) SetMsgPriority(msgFlag string, priority uint8)
- func (l *WormholeNet) Start() error
- func (l *WormholeNet) Stop() error
- func (l *WormholeNet) SubscribeWithChainId(chainId string, topic string, handler api.PubSubMsgHandler) error
Constants ¶
const ( // DefaultMaxPeerCount is the default value for HostConfig.MaxPeerCountAllowed. DefaultMaxPeerCount = 20 // DefaultMaxConnCountEachPeer is the default value for HostConfig.MaxConnCountEachPeerAllowed. DefaultMaxConnCountEachPeer = 1 // DefaultPeerEliminationStrategy is the default value for HostConfig.ConnEliminationStrategy. DefaultPeerEliminationStrategy = 3 // DefaultInitSendStreamSize is the default value for HostConfig.SendStreamPoolInitSize. DefaultInitSendStreamSize = 10 // DefaultSendStreamMaxCount is the default value for HostConfig.SendStreamPoolCap. DefaultSendStreamMaxCount = 100 // DefaultListenAddress is the default value for HostConfig.ListenAddresses. DefaultListenAddress = "/ip4/0.0.0.0/tcp/0" // DefaultPubSubMaxMessageSize is the default value for pubSubConfig.MaxPubMessageSize. DefaultPubSubMaxMessageSize = 50 * (2 << 20) )
const (
NetProtocolTemplatePrefix = "/net/v0.0.1/chain-"
)
Variables ¶
var ( // ErrorPubSubNotExist will be returned when pub-sub service not exist. ErrorPubSubNotExist = errors.New("pub-sub service not exist") // ErrorPubSubExisted will be returned if the pub-sub service exist // when calling InitPubSub method. ErrorPubSubExisted = errors.New("pub-sub service existed") // ErrorTopicSubscribed will be returned if the topic has been // subscribed when calling SubscribeWithChainId method. ErrorTopicSubscribed = errors.New("topic has been subscribed") // ErrorTopicNotSubscribed will be returned if the topic has // not been subscribed when calling CancelSubscribeWithChainId method. ErrorTopicNotSubscribed = errors.New("topic has not been subscribed") // ErrorNotBelongToChain will be returned if the remote node // not belong to chain expected when calling SendMsg method. ErrorNotBelongToChain = errors.New("node not belong to chain") // ErrorWrongAddressOrUnsupported will be returned if the listening // address is wrong or unsupported when calling Start method. ErrorWrongAddressOrUnsupported = errors.New("wrong address or address unsupported") // ErrorNetRunning will be returned if Start method has been called // when calling Start method. ErrorNetRunning = errors.New("net running") )
Functions ¶
func CreateProtocolIdWithChainIdAndMsgFlag ¶
CreateProtocolIdWithChainIdAndMsgFlag create a protocol.ID with the chain id and the msg flag given.
func InitLogger ¶
func LoadChainIdAndFlagWithProtocolId ¶
LoadChainIdAndFlagWithProtocolId resolves the chain id and the msg flag from a protocol.ID given.
func SetListenAddrStr ¶
func SetListenAddrStr(hc *host.HostConfig, listenAddrStr string) error
SetListenAddrStr set the local address will be listening on fot host.HostConfig.
Types ¶
type WormholeNet ¶
type WormholeNet struct {
// contains filtered or unexported fields
}
WormholeNet is an implementation of Net interface with wormhole.
func NewWormholeNet ¶
func NewWormholeNet() (*WormholeNet, error)
NewWormholeNet create a new WormholeNet instance.
func (*WormholeNet) AddAC ¶
func (l *WormholeNet) AddAC(chainId string, ac api.AccessControlProvider)
AddAC add a AccessControlProvider for revoked validator.
func (*WormholeNet) AddSeed ¶
func (l *WormholeNet) AddSeed(seed string) error
AddSeed add a seed node addr.
func (*WormholeNet) BroadcastWithChainId ¶
func (l *WormholeNet) BroadcastWithChainId(chainId string, topic string, data []byte) error
BroadcastWithChainId publish the message to topic, if not subscribe the topic, will return error
func (*WormholeNet) CancelDirectMsgHandle ¶
func (l *WormholeNet) CancelDirectMsgHandle(chainId string, msgFlag string) error
CancelDirectMsgHandle unregister a DirectMsgHandler.
msgFlag: is a flag used to distinguish msg type.
func (*WormholeNet) CancelSubscribeWithChainId ¶
func (l *WormholeNet) CancelSubscribeWithChainId(chainId string, topic string) error
CancelSubscribeWithChainId cancel subscribe a PubSubTopic with the pub-sub service which id is given chainId.
func (*WormholeNet) ChainNodesInfo ¶
func (l *WormholeNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
ChainNodesInfo return base node info list of chain which id is the given chainId.
func (*WormholeNet) CryptoConfig ¶
func (l *WormholeNet) CryptoConfig() *cryptoConfig
CryptoConfig is the configuration for crypto.
func (*WormholeNet) DirectMsgHandle ¶
func (l *WormholeNet) DirectMsgHandle(chainId string, msgFlag string, handler api.DirectMsgHandler) error
DirectMsgHandle register a DirectMsgHandler to the net.
msgFlag: is a flag used to distinguish msg type.
func (*WormholeNet) ExtensionsConfig ¶
func (l *WormholeNet) ExtensionsConfig() *extensionsConfig
ExtensionsConfig is the configuration for extensions.
func (*WormholeNet) GetNodeUid ¶
func (l *WormholeNet) GetNodeUid() string
GetNodeUid get self peer id
func (*WormholeNet) GetNodeUidByCertId ¶
func (l *WormholeNet) GetNodeUidByCertId(certId string) (string, error)
GetNodeUidByCertId return node uid which mapped to the given cert id. If unmapped return error.
func (*WormholeNet) HostConfig ¶
func (l *WormholeNet) HostConfig() *lHost.HostConfig
HostConfig is the configuration of wormhole host.
func (*WormholeNet) InitPubSub ¶
func (l *WormholeNet) InitPubSub(chainId string, maxMessageSize int) error
InitPubSub will init new PubSub instance with given chainId and maxMessageSize.
func (*WormholeNet) IsRunning ¶
func (l *WormholeNet) IsRunning() bool
IsRunning return true when the net instance is running.
func (*WormholeNet) PubSubConfig ¶
func (l *WormholeNet) PubSubConfig() *pubSubConfig
PubSubConfig is the configuration of wormhole host.
func (*WormholeNet) ReVerifyPeers ¶
func (l *WormholeNet) ReVerifyPeers(chainId string)
ReVerifyPeers will verify permission of peers existed with the access control module of the chain which id is the given chainId.
func (*WormholeNet) RefreshSeeds ¶
func (l *WormholeNet) RefreshSeeds(seeds []string) error
RefreshSeeds refresh the seed node addr list.
func (*WormholeNet) SendMsg ¶
SendMsg send msg to the node which id is given string.
msgFlag: is a flag used to distinguish msg type.
func (*WormholeNet) SetChainCustomTrustRoots ¶
func (l *WormholeNet) SetChainCustomTrustRoots(chainId string, roots [][]byte)
SetChainCustomTrustRoots set custom trust roots of chain. In cert permission mode, if it is failed when verifying cert by access control of chains, the cert will be verified by custom trust root pool again.
func (*WormholeNet) SetMsgPriority ¶
func (l *WormholeNet) SetMsgPriority(msgFlag string, priority uint8)
SetMsgPriority set the priority of the msg flag. If priority control disabled, it is no-op.
func (*WormholeNet) SubscribeWithChainId ¶
func (l *WormholeNet) SubscribeWithChainId(chainId string, topic string, handler api.PubSubMsgHandler) error
SubscribeWithChainId register a PubSubMsgHandler to a PubSubTopic with the pub-sub service which id is given chainId.