Documentation ¶
Index ¶
- Constants
- Variables
- func NewPeerSendMsgHandler(hostContext context.Context, pid peer.ID, s network.Stream, ...) *peerSendMsgHandler
- func NewStreamReadHandlerFunc(ln *LibP2pNet) func(stream network.Stream)
- func SetupDiscovery(host *LibP2pHost, readySignalC chan struct{}, enableDHTBootstrapProvider bool, ...) error
- type BlackList
- func (b *BlackList) AddIPAndPort(ip string, port int)
- func (b *BlackList) AddPeerId(pid peer.ID)
- func (b *BlackList) ContainsIPAndPort(ip string, port int) bool
- func (b *BlackList) ContainsPeerId(pid peer.ID) bool
- func (b *BlackList) RemoveIPAndPort(ip string, port int)
- func (b *BlackList) RemovePeerId(pid peer.ID)
- type ConnGater
- func (cg *ConnGater) InterceptAccept(cm network.ConnMultiaddrs) bool
- func (cg *ConnGater) InterceptAddrDial(p peer.ID, mu multiaddr.Multiaddr) bool
- func (cg *ConnGater) InterceptPeerDial(p peer.ID) bool
- func (cg *ConnGater) InterceptSecured(d network.Direction, p peer.ID, cm network.ConnMultiaddrs) bool
- func (cg *ConnGater) InterceptUpgraded(c network.Conn) (bool, control.DisconnectReason)
- type ConnSupervisor
- type LibP2pHost
- type LibP2pNet
- func (ln *LibP2pNet) AddAC(chainId string, ac api.AccessControlProvider)
- func (ln *LibP2pNet) AddSeed(seed string) error
- func (ln *LibP2pNet) BroadcastWithChainId(chainId string, topic string, data []byte) error
- func (ln *LibP2pNet) CancelDirectMsgHandle(chainId string, msgFlag string) error
- func (ln *LibP2pNet) CancelSubscribeWithChainId(chainId string, topic string) error
- func (ln *LibP2pNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
- func (ln *LibP2pNet) DirectMsgHandle(chainId string, msgFlag string, handler api.DirectMsgHandler) error
- func (ln *LibP2pNet) GetNodeUid() string
- func (ln *LibP2pNet) GetNodeUidByCertId(certId string) (string, error)
- func (ln *LibP2pNet) InitPubSub(chainId string, maxMessageSize int) error
- func (ln *LibP2pNet) IsConnected(nodeId string) bool
- func (ln *LibP2pNet) IsRunning() bool
- func (ln *LibP2pNet) Prepare() *LibP2pNetPrepare
- func (ln *LibP2pNet) ReVerifyPeers(chainId string)
- func (ln *LibP2pNet) RefreshSeeds(seeds []string) error
- func (ln *LibP2pNet) SendMsg(chainId string, node string, msgFlag string, data []byte) error
- func (ln *LibP2pNet) SetChainCustomTrustRoots(chainId string, roots [][]byte)
- func (ln *LibP2pNet) SetCompressMsgBytes(enable bool)
- func (ln *LibP2pNet) SetMsgPriority(msgFlag string, priority uint8)
- func (ln *LibP2pNet) Start() error
- func (ln *LibP2pNet) Stop() error
- func (ln *LibP2pNet) SubscribeWithChainId(chainId string, topic string, handler api.PubSubMsgHandler) error
- type LibP2pNetPrepare
- func (l *LibP2pNetPrepare) AddBlackAddress(address string)
- func (l *LibP2pNetPrepare) AddBlackPeerId(pid string)
- func (l *LibP2pNetPrepare) AddBootstrapsPeer(bootstrapAddr string)
- func (l *LibP2pNetPrepare) SetCert(certPem []byte)
- func (l *LibP2pNetPrepare) SetEncCert(certPem []byte)
- func (l *LibP2pNetPrepare) SetEncKey(keyPem []byte)
- func (l *LibP2pNetPrepare) SetIsInsecurity(isInsecurity bool)
- func (l *LibP2pNetPrepare) SetKey(keyPem []byte)
- func (l *LibP2pNetPrepare) SetListenAddr(listenAddr string)
- func (l *LibP2pNetPrepare) SetMaxPeerCountAllow(maxPeerCountAllow int)
- func (l *LibP2pNetPrepare) SetPeerEliminationStrategy(peerEliminationStrategy int)
- func (l *LibP2pNetPrepare) SetPeerStreamPoolSize(peerStreamPoolSize int)
- func (l *LibP2pNetPrepare) SetPktEnable(pktEnable bool)
- func (l *LibP2pNetPrepare) SetPriorityCtrlEnable(priorityCtrlEnable bool)
- func (l *LibP2pNetPrepare) SetPubKeyModeEnable(pkModeEnable bool)
- func (l *LibP2pNetPrepare) SetPubSubMaxMsgSize(pubSubMaxMsgSize int)
- func (l *LibP2pNetPrepare) SetReadySignalC(readySignalC chan struct{})
- type LibP2pPubSub
- func (ps *LibP2pPubSub) AddWhitelistPeer(pid peer.ID) error
- func (ps *LibP2pPubSub) GetTopic(name string) (*pubsub.Topic, error)
- func (ps *LibP2pPubSub) Publish(topic string, data []byte) error
- func (ps *LibP2pPubSub) RemoveWhitelistPeer(pid peer.ID) error
- func (ps *LibP2pPubSub) Start() error
- func (ps *LibP2pPubSub) Subscribe(topic string) (*pubsub.Subscription, error)
- type MessageHandlerDistributor
- type PeerConnManager
- func (cm *PeerConnManager) AddAsHighLevelPeer(peerId peer.ID)
- func (cm *PeerConnManager) AddConn(pid peer.ID, conn network.Conn) bool
- func (cm *PeerConnManager) CanConnect(pid peer.ID) bool
- func (cm *PeerConnManager) ClearHighLevelPeer()
- func (cm *PeerConnManager) ConnCount() int
- func (cm *PeerConnManager) GetConn(pid peer.ID) network.Conn
- func (cm *PeerConnManager) GetConns(pid peer.ID) []network.Conn
- func (cm *PeerConnManager) IsConnected(pid peer.ID) bool
- func (cm *PeerConnManager) IsHighLevel(peerId peer.ID) bool
- func (cm *PeerConnManager) RemoveConn(pid peer.ID, conn network.Conn) bool
- func (cm *PeerConnManager) RemoveHighLevelPeer(peerId peer.ID)
- func (cm *PeerConnManager) SetMaxSize(maxSize int)
- func (cm *PeerConnManager) SetStrategy(strategy int)
Constants ¶
const ( // DefaultTryTimes is the default try times. Max timeout is 10m10s. DefaultTryTimes = 15 // DefaultTryTimesAfterMaxTime is the default try times after max timeout, which is 90 days. DefaultTryTimesAfterMaxTime = 6 * 24 * 90 )
const ( // DefaultLibp2pListenAddress is the default address that libp2p will listen on. DefaultLibp2pListenAddress = "/ip4/0.0.0.0/tcp/0" // DefaultLibp2pServiceTag is the default service tag for discovery service finding. DefaultLibp2pServiceTag = "chainmaker-libp2p-net" // MaxReadBuff max []byte to make once MaxReadBuff = 1 << 34 // 17G )
const ( // Random Random eliminationStrategy = iota + 1 // FIFO FIRST_IN_FIRST_OUT FIFO // LIFO LAST_IN_FIRST_OUT LIFO )
const DefaultEliminationStrategy = LIFO
DefaultEliminationStrategy is the default strategy for elimination.
const (
// DefaultLibp2pPubSubMaxMessageSize is the default max message size for pub-sub.
DefaultLibp2pPubSubMaxMessageSize = 50 << 20
)
const DefaultMaxPeerCountAllow = 100
DefaultMaxPeerCountAllow is the default max peer count allow.
DefaultMessageSendTimeout is the default timeout for sending msg.
MsgPID is the protocol.ID of chainmaker net msg.
Variables ¶
var ( ErrorPubSubNotExist = errors.New("pub-sub service not exist") ErrorPubSubExisted = errors.New("pub-sub service existed") ErrorTopicSubscribed = errors.New("topic has been subscribed") ErrorSendMsgIncompletely = errors.New("send msg incompletely") ErrorNotConnected = errors.New("node not connected") ErrorNotBelongToChain = errors.New("node not belong to chain") )
var Config *netConfig
Functions ¶
func NewPeerSendMsgHandler ¶ added in v1.2.1
func NewStreamReadHandlerFunc ¶
NewStreamReadHandlerFunc create new function for listening stream reading.
func SetupDiscovery ¶
func SetupDiscovery(host *LibP2pHost, readySignalC chan struct{}, enableDHTBootstrapProvider bool, bootstraps []string, log protocol.Logger) error
SetupDiscovery . @Description: setup a discovery service. @param host: @param readySignalC: @param enableDHTBootstrapProvider: @param bootstraps: @param log: @return error:
Types ¶
type BlackList ¶
type BlackList struct {
// contains filtered or unexported fields
}
BlackList is a blacklist for controlling nodes connection.
func NewBlackList ¶
func NewBlackList() *BlackList
NewBlackList . @Description: create new BlackList instance. @return *BlackList:
func (*BlackList) AddIPAndPort ¶
AddIPAndPort . @Description: add new IP and Port record to blacklist.
If you want to control IP only, set port=0 pls.
@receiver b @param ip: @param port:
func (*BlackList) AddPeerId ¶
AddPeerId . @Description: add new peer.ID to blacklist. @receiver b @param pid:
func (*BlackList) ContainsIPAndPort ¶
ContainsIPAndPort . @Description: return whether IP and Port exist in blacklist.
If not found ip+port, but found ip only, return true.
@receiver b @param ip: @param port: @return bool:
func (*BlackList) ContainsPeerId ¶
ContainsPeerId . @Description: return whether peer.ID given exist in blacklist. @receiver b @param pid: @return bool:
func (*BlackList) RemoveIPAndPort ¶
RemoveIPAndPort . @Description: remove IP and Port record from blacklist. @receiver b @param ip: @param port:
type ConnGater ¶
type ConnGater struct {
// contains filtered or unexported fields
}
ConnGater is an implementation of ConnectionGater interface.
func NewConnGater ¶
func NewConnGater( connManager *PeerConnManager, blackList *BlackList, memberStatusValidator *common.MemberStatusValidator, log protocol.Logger) *ConnGater
NewConnGater . @Description: @param connManager: @param blackList: @param memberStatusValidator: @param log: @return *ConnGater:
func (*ConnGater) InterceptAccept ¶
func (cg *ConnGater) InterceptAccept(cm network.ConnMultiaddrs) bool
InterceptAccept will be checked first when other peer connect to us.
func (*ConnGater) InterceptAddrDial ¶
InterceptAddrDial . @Description: @receiver cg @param p: @param mu: @return bool:
func (*ConnGater) InterceptPeerDial ¶
InterceptPeerDial . @Description: @receiver cg @param p: @return bool:
type ConnSupervisor ¶
type ConnSupervisor struct {
// contains filtered or unexported fields
}
ConnSupervisor is a connections supervisor.
type LibP2pHost ¶
type LibP2pHost struct {
// contains filtered or unexported fields
}
LibP2pHost is a libP2pHost which use libp2p as local net provider.
func NewLibP2pHost ¶
func NewLibP2pHost(ctx context.Context, log protocol.Logger) *LibP2pHost
NewLibP2pHost create new LibP2pHost instance.
func (*LibP2pHost) DHT ¶ added in v1.2.1
func (lh *LibP2pHost) DHT() *dht.IpfsDHT
DHT is libp2p.peerDHT
func (*LibP2pHost) HasConnected ¶
func (lh *LibP2pHost) HasConnected(peerId peer.ID) bool
HasConnected return true if the peer which id is the peerId given has connected. Otherwise return false.
func (*LibP2pHost) IsRunning ¶
func (lh *LibP2pHost) IsRunning() bool
IsRunning return true when libp2p has started up.Otherwise return false.
type LibP2pNet ¶
type LibP2pNet struct {
// contains filtered or unexported fields
}
LibP2pNet is an implementation of net.Net interface.
func NewLibP2pNet ¶
NewLibP2pNet create a new LibP2pNet instance.
func (*LibP2pNet) AddAC ¶
func (ln *LibP2pNet) AddAC(chainId string, ac api.AccessControlProvider)
func (*LibP2pNet) AddSeed ¶
AddSeed add a seed node address. It can be a consensus node address.
func (*LibP2pNet) BroadcastWithChainId ¶
BroadcastWithChainId broadcast a msg to the given topic of the target chain which id is the given chainId .
func (*LibP2pNet) CancelDirectMsgHandle ¶
CancelDirectMsgHandle unregister a DirectMsgHandler for handling msg received.
func (*LibP2pNet) CancelSubscribeWithChainId ¶
CancelSubscribeWithChainId cancel subscribing the given topic of the target chain which id is the given chainId.
func (*LibP2pNet) ChainNodesInfo ¶
func (ln *LibP2pNet) ChainNodesInfo(chainId string) ([]*api.ChainNodeInfo, error)
ChainNodesInfo
func (*LibP2pNet) DirectMsgHandle ¶
func (ln *LibP2pNet) DirectMsgHandle(chainId string, msgFlag string, handler api.DirectMsgHandler) error
DirectMsgHandle register a DirectMsgHandler for handling msg received.
func (*LibP2pNet) GetNodeUid ¶
GetNodeUid is the unique id of node.
func (*LibP2pNet) GetNodeUidByCertId ¶
GetNodeUidByCertId
func (*LibP2pNet) InitPubSub ¶
InitPubSub will create new LibP2pPubSub instance for LibP2pNet with setting pub-sub uid to the given chainId .
func (*LibP2pNet) IsConnected ¶ added in v1.2.1
func (*LibP2pNet) Prepare ¶
func (ln *LibP2pNet) Prepare() *LibP2pNetPrepare
func (*LibP2pNet) ReVerifyPeers ¶
ReVerifyPeers will verify permission of peers existed with the access control module of the chain which id is the given chainId.
func (*LibP2pNet) RefreshSeeds ¶
RefreshSeeds reset addresses of seed nodes with given.
func (*LibP2pNet) SendMsg ¶
SendMsg send a msg to the given node belong to the given chain.
func (*LibP2pNet) 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 (*LibP2pNet) SetMsgPriority ¶
type LibP2pNetPrepare ¶
type LibP2pNetPrepare struct {
// contains filtered or unexported fields
}
LibP2pNetPrepare prepare the config options.
func (*LibP2pNetPrepare) AddBlackAddress ¶
func (l *LibP2pNetPrepare) AddBlackAddress(address string)
AddBlackAddress add a black address to blacklist.
example: 192.168.1.14:8080 example: 192.168.1.14
func (*LibP2pNetPrepare) AddBlackPeerId ¶
func (l *LibP2pNetPrepare) AddBlackPeerId(pid string)
AddBlackPeerId add a black node id to blacklist.
example: QmcQHCuAXaFkbcsPUj7e37hXXfZ9DdN7bozseo5oX4qiC4
func (*LibP2pNetPrepare) AddBootstrapsPeer ¶
func (l *LibP2pNetPrepare) AddBootstrapsPeer(bootstrapAddr string)
AddBootstrapsPeer . @Description: add a node address for connecting directly.
It can be a seed node address or a consensus node address.
@receiver l @param bootstrapAddr:
func (*LibP2pNetPrepare) SetCert ¶
func (l *LibP2pNetPrepare) SetCert(certPem []byte)
SetCert . @Description: set cert with pem bytes. @receiver l @param certPem:
func (*LibP2pNetPrepare) SetEncCert ¶ added in v1.2.0
func (l *LibP2pNetPrepare) SetEncCert(certPem []byte)
SetEncCert . @Description: set cert with pem bytes. @receiver l @param certPem:
func (*LibP2pNetPrepare) SetEncKey ¶ added in v1.2.0
func (l *LibP2pNetPrepare) SetEncKey(keyPem []byte)
SetEncKey . @Description: set private key with pem bytes. @receiver l @param keyPem:
func (*LibP2pNetPrepare) SetIsInsecurity ¶
func (l *LibP2pNetPrepare) SetIsInsecurity(isInsecurity bool)
SetIsInsecurity . @Description: @receiver l @param isInsecurity:
func (*LibP2pNetPrepare) SetKey ¶
func (l *LibP2pNetPrepare) SetKey(keyPem []byte)
SetKey . @Description: set private key with pem bytes. @receiver l @param keyPem:
func (*LibP2pNetPrepare) SetListenAddr ¶
func (l *LibP2pNetPrepare) SetListenAddr(listenAddr string)
SetListenAddr set address that the net will listen on.
example: /ip4/127.0.0.1/tcp/10001
func (*LibP2pNetPrepare) SetMaxPeerCountAllow ¶
func (l *LibP2pNetPrepare) SetMaxPeerCountAllow(maxPeerCountAllow int)
SetMaxPeerCountAllow . @Description: set max count of nodes that allow to connect to us. @receiver l @param maxPeerCountAllow:
func (*LibP2pNetPrepare) SetPeerEliminationStrategy ¶
func (l *LibP2pNetPrepare) SetPeerEliminationStrategy(peerEliminationStrategy int)
SetPeerEliminationStrategy . @Description: set the strategy for eliminating when reach the max count. @receiver l @param peerEliminationStrategy:
func (*LibP2pNetPrepare) SetPeerStreamPoolSize ¶
func (l *LibP2pNetPrepare) SetPeerStreamPoolSize(peerStreamPoolSize int)
SetPeerStreamPoolSize . @Description: set stream pool max size of each peer. @receiver l @param peerStreamPoolSize:
func (*LibP2pNetPrepare) SetPktEnable ¶
func (l *LibP2pNetPrepare) SetPktEnable(pktEnable bool)
SetPktEnable . @Description: @receiver l @param pktEnable:
func (*LibP2pNetPrepare) SetPriorityCtrlEnable ¶
func (l *LibP2pNetPrepare) SetPriorityCtrlEnable(priorityCtrlEnable bool)
SetPriorityCtrlEnable . @Description: @receiver l @param priorityCtrlEnable:
func (*LibP2pNetPrepare) SetPubKeyModeEnable ¶
func (l *LibP2pNetPrepare) SetPubKeyModeEnable(pkModeEnable bool)
SetPubKeyModeEnable . @Description: set whether to use public key mode of permission. @receiver l @param pkModeEnable:
func (*LibP2pNetPrepare) SetPubSubMaxMsgSize ¶
func (l *LibP2pNetPrepare) SetPubSubMaxMsgSize(pubSubMaxMsgSize int)
SetPubSubMaxMsgSize . @Description: set max msg size for pub-sub service.(M) @receiver l @param pubSubMaxMsgSize:
func (*LibP2pNetPrepare) SetReadySignalC ¶
func (l *LibP2pNetPrepare) SetReadySignalC(readySignalC chan struct{})
SetReadySignalC . @Description: @receiver l @param readySignalC:
type LibP2pPubSub ¶
type LibP2pPubSub struct {
// contains filtered or unexported fields
}
LibP2pPubSub is a pub-sub service implementation.
func NewPubsub ¶
func NewPubsub(pubsubUid string, host *LibP2pHost, maxMessageSize int) (*LibP2pPubSub, error)
NewPubsub . @Description: create a new LibP2pPubSub instance. @param pubsubUid: @param host: @param maxMessageSize: @return *LibP2pPubSub: @return error:
func (*LibP2pPubSub) AddWhitelistPeer ¶
func (ps *LibP2pPubSub) AddWhitelistPeer(pid peer.ID) error
AddWhitelistPeer . @Description: add a peer.ID to pubsub white list. @receiver ps @param pid: @return error:
func (*LibP2pPubSub) GetTopic ¶
func (ps *LibP2pPubSub) GetTopic(name string) (*pubsub.Topic, error)
GetTopic . @Description: get a topic with the name given. @receiver ps @param name: @return *pubsub.Topic: @return error:
func (*LibP2pPubSub) Publish ¶
func (ps *LibP2pPubSub) Publish(topic string, data []byte) error
Publish . @Description: a msg to the topic. @receiver ps @param topic: @param data: @return error:
func (*LibP2pPubSub) RemoveWhitelistPeer ¶
func (ps *LibP2pPubSub) RemoveWhitelistPeer(pid peer.ID) error
RemoveWhitelistPeer . @Description: remove a peer.ID to pubsub white list. @receiver ps @param pid: @return error:
func (*LibP2pPubSub) Start ¶
func (ps *LibP2pPubSub) Start() error
Start . @Description: @receiver ps @return error:
func (*LibP2pPubSub) Subscribe ¶
func (ps *LibP2pPubSub) Subscribe(topic string) (*pubsub.Subscription, error)
Subscribe . @Description: Subscribe a topic. @receiver ps @param topic: @return *pubsub.Subscription: @return error:
type MessageHandlerDistributor ¶
type MessageHandlerDistributor struct {
// contains filtered or unexported fields
}
MessageHandlerDistributor is a MessageHandler distributor.
type PeerConnManager ¶
type PeerConnManager struct {
// contains filtered or unexported fields
}
PeerConnManager is a connection manager of peers.
func NewPeerConnManager ¶
func NewPeerConnManager(log protocol.Logger) *PeerConnManager
NewPeerConnManager create a new PeerConnManager.
func (*PeerConnManager) AddAsHighLevelPeer ¶
func (cm *PeerConnManager) AddAsHighLevelPeer(peerId peer.ID)
AddAsHighLevelPeer add a peer id as high level peer.
func (*PeerConnManager) AddConn ¶
AddConn add a connection.
func (*PeerConnManager) CanConnect ¶
func (cm *PeerConnManager) CanConnect(pid peer.ID) bool
CanConnect return true if peer can connect to self. Otherwise, return false.
func (*PeerConnManager) ClearHighLevelPeer ¶
func (cm *PeerConnManager) ClearHighLevelPeer()
ClearHighLevelPeer clear all high level peer id records.
func (*PeerConnManager) ConnCount ¶
func (cm *PeerConnManager) ConnCount() int
ConnCount return the count num of connections.
func (*PeerConnManager) GetConn ¶
func (cm *PeerConnManager) GetConn(pid peer.ID) network.Conn
GetConn return a connection for peer.
func (*PeerConnManager) GetConns ¶ added in v1.1.0
func (cm *PeerConnManager) GetConns(pid peer.ID) []network.Conn
GetConns return a connection for peer.
func (*PeerConnManager) IsConnected ¶
func (cm *PeerConnManager) IsConnected(pid peer.ID) bool
IsConnected return true if peer has connected. Otherwise, return false.
func (*PeerConnManager) IsHighLevel ¶
func (cm *PeerConnManager) IsHighLevel(peerId peer.ID) bool
IsHighLevel return true if the peer which is high-level (consensus & seeds) node. Otherwise, return false.
func (*PeerConnManager) RemoveConn ¶
RemoveConn remove a connection.
func (*PeerConnManager) RemoveHighLevelPeer ¶
func (cm *PeerConnManager) RemoveHighLevelPeer(peerId peer.ID)
RemoveHighLevelPeer remove a high level peer id.
func (*PeerConnManager) SetMaxSize ¶
func (cm *PeerConnManager) SetMaxSize(maxSize int)
SetMaxSize set max count of peers allowed. If not set, default is 20.
func (*PeerConnManager) SetStrategy ¶
func (cm *PeerConnManager) SetStrategy(strategy int)
SetStrategy set the elimination strategy. If not set, default is LIFO.
Source Files ¶
- alarm_bell.go
- libp2p_blacklist.go
- libp2p_config.go
- libp2p_connection_gater.go
- libp2p_connection_supervisor.go
- libp2p_discovery.go
- libp2p_host.go
- libp2p_message_handler_distributor.go
- libp2p_net.go
- libp2p_net_prepare.go
- libp2p_peer_connection_manager.go
- libp2p_peer_manager.go
- libp2p_peer_sendmsg_handler.go
- libp2p_pkt_adapter.go
- libp2p_pubsub.go