liquidnet

package
v1.3.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: 40 Imported by: 4

Documentation

Index

Constants

View Source
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)
)
View Source
const (
	// NetProtocolTemplatePrefix .
	NetProtocolTemplatePrefix = "/net/v0.0.1/chain-"
)

Variables

View Source
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

func CreateProtocolIdWithChainIdAndMsgFlag(chainId, msgFlag string) protocol.ID

CreateProtocolIdWithChainIdAndMsgFlag create a protocol.ID with the chain id and the msg flag given.

func GenMaAddr added in v1.1.0

func GenMaAddr(addr string) ma.Multiaddr

GenMaAddr converts an address in the form of a string to a multi address object

func InitLogger

func InitLogger(globalNetLogger api.Logger, pubSubLogCreator func(chainId string) api.Logger)

InitLogger .

func LoadChainIdAndFlagWithProtocolId

func LoadChainIdAndFlagWithProtocolId(protocolId protocol.ID) (string, string, error)

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

func NewLiquidNet() (*LiquidNet, error)

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

func (l *LiquidNet) AddSeed(seed string) error

AddSeed add a seed node addr.

func (*LiquidNet) BroadcastWithChainId

func (l *LiquidNet) BroadcastWithChainId(chainId string, topic string, data []byte) error

BroadcastWithChainId publish the message to topic, if not subscribe the topic, will return error

func (*LiquidNet) CancelDirectMsgHandle

func (l *LiquidNet) CancelDirectMsgHandle(chainId string, msgFlag string) error

CancelDirectMsgHandle unregister a DirectMsgHandler.

msgFlag: is a flag used to distinguish msg type.

func (*LiquidNet) CancelSubscribeWithChainId

func (l *LiquidNet) CancelSubscribeWithChainId(chainId string, topic string) error

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) GetNodeUid

func (l *LiquidNet) GetNodeUid() string

GetNodeUid get self peer id

func (*LiquidNet) GetNodeUidByCertId

func (l *LiquidNet) GetNodeUidByCertId(certId string) (string, error)

GetNodeUidByCertId return node uid which mapped to the given cert id. If unmapped return error.

func (*LiquidNet) HolePunch added in v1.1.0

func (l *LiquidNet) HolePunch(pid peer.ID, addr ma.Multiaddr) error

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

func (l *LiquidNet) InitPubSub(chainId string, maxMessageSize int) error

InitPubSub will init new PubSub instance with given chainId and maxMessageSize.

func (*LiquidNet) IsRunning

func (l *LiquidNet) IsRunning() bool

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

func (l *LiquidNet) 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 (*LiquidNet) RefreshSeeds

func (l *LiquidNet) RefreshSeeds(seeds []string) error

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

func (l *LiquidNet) SendMsg(chainId string, targetPeer string, msgFlag string, data []byte) error

SendMsg send msg to the node which id is given string.

msgFlag: is a flag used to distinguish msg type.

func (*LiquidNet) SetChainCustomTrustRoots

func (l *LiquidNet) 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 (*LiquidNet) SetMsgPriority

func (l *LiquidNet) SetMsgPriority(msgFlag string, priority uint8)

SetMsgPriority set the priority of the msg flag. If priority control disabled, it is no-op.

func (*LiquidNet) Start

func (l *LiquidNet) Start() error

Start the local net.

func (*LiquidNet) Stop

func (l *LiquidNet) Stop() error

Stop the local net.

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.

func (*LiquidNet) StunServerConfig added in v1.1.0

func (l *LiquidNet) StunServerConfig() *stunServerConfig

StunServerConfig is the configuration for stun.

func (*LiquidNet) SubscribeWithChainId

func (l *LiquidNet) 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.

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

Jump to

Keyboard shortcuts

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