Documentation ¶
Index ¶
- Constants
- Variables
- func CreateProtocolIdWithChainIdAndMsgFlag(chainId, msgFlag string) protocol.ID
- func GenMaAddr(addr string) ma.Multiaddr
- 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 DiscoveryConfig
- type LiquidNet
- func (l *LiquidNet) AddAC(chainId string, ac api.AccessControlProvider)
- func (l *LiquidNet) AddSeed(seed string) error
- func (l *LiquidNet) BroadcastWithChainId(chainId string, topic string, data []byte) error
- func (l *LiquidNet) CancelDirectMsgHandle(chainId string, msgFlag string) error
- func (l *LiquidNet) CancelSubscribeWithChainId(chainId string, topic string) error
- func (l *LiquidNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
- func (l *LiquidNet) CryptoConfig() *cryptoConfig
- func (l *LiquidNet) DirectMsgHandle(chainId string, msgFlag string, handler api.DirectMsgHandler) error
- func (l *LiquidNet) ExtensionsConfig() *extensionsConfig
- func (l *LiquidNet) GetNodeUid() string
- func (l *LiquidNet) GetNodeUidByCertId(certId string) (string, error)
- func (l *LiquidNet) HolePunch(pid peer.ID, addr ma.Multiaddr) error
- func (l *LiquidNet) HolePunchConfig() *holePunchConfig
- func (l *LiquidNet) HostConfig() *lHost.HostConfig
- func (l *LiquidNet) InitPubSub(chainId string, maxMessageSize int) error
- func (l *LiquidNet) IsRunning() bool
- func (l *LiquidNet) PubSubConfig() *pubSubConfig
- func (l *LiquidNet) ReVerifyPeers(chainId string)
- func (l *LiquidNet) RefreshSeeds(seeds []string) error
- func (l *LiquidNet) RoutingConfig() *RoutingConfig
- func (l *LiquidNet) SendMsg(chainId string, targetPeer string, msgFlag string, data []byte) error
- func (l *LiquidNet) SetChainCustomTrustRoots(chainId string, roots [][]byte)
- func (l *LiquidNet) SetMsgPriority(msgFlag string, priority uint8)
- func (l *LiquidNet) Start() error
- func (l *LiquidNet) Stop() error
- func (l *LiquidNet) StunCheck(pid peer.ID) (stun.NATDeviceType, stun.NATDeviceType)
- func (l *LiquidNet) StunClientConfig() *stunClientConfig
- func (l *LiquidNet) StunServerConfig() *stunServerConfig
- func (l *LiquidNet) SubscribeWithChainId(chainId string, topic string, handler api.PubSubMsgHandler) error
- type RoutingConfig
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 .
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 GenMaAddr ¶ added in v1.1.0
GenMaAddr converts an address in the form of a string to a multi address object
func InitLogger ¶
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 DiscoveryConfig ¶ added in v1.3.0
type DiscoveryConfig struct { // whether to enable Discovery EnableDiscovery bool }
DiscoveryConfig discovery related configuration
type LiquidNet ¶
type LiquidNet struct {
// contains filtered or unexported fields
}
LiquidNet is an implementation of Net interface with liquid.
func NewLiquidNet ¶
NewLiquidNet create a new LiquidNet instance.
func (*LiquidNet) AddAC ¶
func (l *LiquidNet) AddAC(chainId string, ac api.AccessControlProvider)
AddAC add a AccessControlProvider for revoked validator.
func (*LiquidNet) AddSeed ¶
AddSeed add a seed node addr.
func (*LiquidNet) BroadcastWithChainId ¶
BroadcastWithChainId publish the message to topic, if not subscribe the topic, will return error
func (*LiquidNet) CancelDirectMsgHandle ¶
CancelDirectMsgHandle unregister a DirectMsgHandler.
msgFlag: is a flag used to distinguish msg type.
func (*LiquidNet) CancelSubscribeWithChainId ¶
CancelSubscribeWithChainId cancel subscribe a PubSubTopic with the pub-sub service which id is given chainId.
func (*LiquidNet) ChainNodesInfo ¶
func (l *LiquidNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
ChainNodesInfo return base node info list of chain which id is the given chainId.
func (*LiquidNet) CryptoConfig ¶
func (l *LiquidNet) CryptoConfig() *cryptoConfig
CryptoConfig is the configuration for crypto.
func (*LiquidNet) DirectMsgHandle ¶
func (l *LiquidNet) 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 (*LiquidNet) ExtensionsConfig ¶
func (l *LiquidNet) ExtensionsConfig() *extensionsConfig
ExtensionsConfig is the configuration for extensions.
func (*LiquidNet) GetNodeUidByCertId ¶
GetNodeUidByCertId return node uid which mapped to the given cert id. If unmapped return error.
func (*LiquidNet) HolePunch ¶ added in v1.1.0
HolePunch try hole punch
func (*LiquidNet) HolePunchConfig ¶ added in v1.1.0
func (l *LiquidNet) HolePunchConfig() *holePunchConfig
HolePunchConfig is the configuration for extensions.
func (*LiquidNet) HostConfig ¶
func (l *LiquidNet) HostConfig() *lHost.HostConfig
HostConfig is the configuration of liquid host.
func (*LiquidNet) InitPubSub ¶
InitPubSub will init new PubSub instance with given chainId and maxMessageSize.
func (*LiquidNet) IsRunning ¶
IsRunning return true when the net instance is running.
func (*LiquidNet) PubSubConfig ¶
func (l *LiquidNet) PubSubConfig() *pubSubConfig
PubSubConfig is the configuration of liquid host.
func (*LiquidNet) ReVerifyPeers ¶
ReVerifyPeers will verify permission of peers existed with the access control module of the chain which id is the given chainId.
func (*LiquidNet) RefreshSeeds ¶
RefreshSeeds refresh the seed node addr list.
func (*LiquidNet) RoutingConfig ¶ added in v1.3.0
func (l *LiquidNet) RoutingConfig() *RoutingConfig
RoutingConfig routing related configuration
func (*LiquidNet) SendMsg ¶
SendMsg send msg to the node which id is given string.
msgFlag: is a flag used to distinguish msg type.
func (*LiquidNet) SetChainCustomTrustRoots ¶
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 (*LiquidNet) SetMsgPriority ¶
SetMsgPriority set the priority of the msg flag. If priority control disabled, it is no-op.
func (*LiquidNet) StunCheck ¶ added in v1.1.0
func (l *LiquidNet) StunCheck(pid peer.ID) (stun.NATDeviceType, stun.NATDeviceType)
StunCheck invoke stun func
func (*LiquidNet) StunClientConfig ¶ added in v1.1.0
func (l *LiquidNet) StunClientConfig() *stunClientConfig
StunClientConfig is the configuration for stun.
type RoutingConfig ¶ added in v1.3.0
type RoutingConfig struct { // whether to enable message routing EnableMessageRouting bool // the number of peers selected when message routing forwards messages MessageRoutingForwardPeerCount int // MessageRouting message lifetime in the network,unit:second MessageRoutingMsgLifetime int // MessageRouting's message cache size MessageRoutingMsgCacheMaxSize int }
RoutingConfig routing related configuration