Documentation ¶
Index ¶
- Constants
- Variables
- func NewAddrBook() store.AddrBook
- func NewBlackList() blacklist.BlackList
- func NewConnSupervisor(h host.Host, logger api.Logger) mgr.ConnSupervisor
- func NewReceiveStreamManager(peerReceiveStreamMaxCount int32) mgr.ReceiveStreamManager
- func NewSendStreamPoolManager(connMgr mgr.ConnMgr, log api.Logger) mgr.SendStreamPoolManager
- func NewSimplePeerStore(localPid peer.ID) store.PeerStore
- func NewSimpleProtocolExchanger(host host.Host, protocolMgr mgr.ProtocolManager, logger api.Logger) mgr.ProtocolExchanger
- func NewSimpleProtocolMgr(localPID peer.ID, protocolBook store.ProtocolBook) mgr.ProtocolManager
- func NewSimpleStreamPool(initSize, cap int32, conn network.Conn, host host.Host, log api.Logger) (mgr.SendStreamPool, error)
- func NewSingleStreamPool(conn network.Conn, host host.Host, log api.Logger) (mgr.SendStreamPool, error)
- type EliminationStrategy
- type GroupMulticastMgr
- func (cm *GroupMulticastMgr) AddPeerToGroup(groupName string, peers ...peer.ID)
- func (cm *GroupMulticastMgr) GroupSize(groupName string) int
- func (cm *GroupMulticastMgr) InGroup(groupName string, peer peer.ID) bool
- func (cm *GroupMulticastMgr) RemoveGroup(groupName string)
- func (cm *GroupMulticastMgr) RemovePeerFromGroup(groupName string, peers ...peer.ID)
- func (cm *GroupMulticastMgr) SendToGroupAsync(groupName string, protocolID protocol.ID, data []byte)
- func (cm *GroupMulticastMgr) SendToGroupSync(groupName string, protocolID protocol.ID, data []byte) error
- type LevelConnManager
- func (cm *LevelConnManager) AddAsHighLevelPeer(peerId peer.ID)
- func (cm *LevelConnManager) AddPeerConn(pid peer.ID, conn network.Conn) bool
- func (cm *LevelConnManager) AllPeer() []peer.ID
- func (cm *LevelConnManager) ClearHighLevelPeer()
- func (cm *LevelConnManager) Close() error
- func (cm *LevelConnManager) ExistPeerConn(pid peer.ID, conn network.Conn) bool
- func (cm *LevelConnManager) ExpendConn(pid peer.ID)
- func (cm *LevelConnManager) GetPeerAllConn(pid peer.ID) []network.Conn
- func (cm *LevelConnManager) GetPeerConn(pid peer.ID) network.Conn
- func (cm *LevelConnManager) IsAllowed(pid peer.ID) bool
- func (cm *LevelConnManager) IsConnected(pid peer.ID) bool
- func (cm *LevelConnManager) IsHighLevel(peerId peer.ID) bool
- func (cm *LevelConnManager) MaxPeerCountAllowed() int
- func (cm *LevelConnManager) PeerCount() int
- func (cm *LevelConnManager) RemoveHighLevelPeer(peerId peer.ID)
- func (cm *LevelConnManager) RemovePeerConn(pid peer.ID, conn network.Conn) bool
- func (cm *LevelConnManager) SetMaxConnCountEachPeerAllowed(max int)
- func (cm *LevelConnManager) SetMaxPeerCountAllowed(max int)
- func (cm *LevelConnManager) SetStrategy(strategy EliminationStrategy)
- type SimplePeerStore
Constants ¶
const DefaultEliminationStrategy = LIFO
DefaultEliminationStrategy is the default strategy for elimination.
const DefaultMaxConnCountEachPeerAllowed = 1
DefaultMaxConnCountEachPeerAllowed is the default max connections count of each peer allowed.
const DefaultMaxPeerCountAllow = 20
DefaultMaxPeerCountAllow is the default max peer count allowed.
const DefaultTryTimes = 50
DefaultTryTimes default try times
Variables ¶
var ( // ErrProtocolIDRegistered will be returned if protocol id has registered // when calling RegisterMsgPayloadHandler method. ErrProtocolIDRegistered = errors.New("protocol id has registered") // ErrProtocolIDNotRegistered will be returned if protocol id has not been registered // when calling UnregisterMsgPayloadHandler method. ErrProtocolIDNotRegistered = errors.New("protocol id is not registered") // ErrPushProtocolTimeout will be returned if protocol pushing timeout. ErrPushProtocolTimeout = errors.New("push protocol timeout") // ErrProtocolOfExchangerMismatch will be returned if the protocol of exchanger mismatch. ErrProtocolOfExchangerMismatch = errors.New("exchanger protocol mismatch") )
var ( // ErrStreamPoolClosed will be returned if stream pool closed. ErrStreamPoolClosed = errors.New("stream pool closed") // ErrNoStreamCanBeBorrowed will be returned if no stream can be borrowed. ErrNoStreamCanBeBorrowed = errors.New("no stream can be borrowed") )
Functions ¶
func NewAddrBook ¶ added in v1.3.0
NewAddrBook create a new addBook.
func NewBlackList ¶
NewBlackList create a new *simpleBlacklist instance.
func NewConnSupervisor ¶
NewConnSupervisor create a new *connSupervisor instance.
func NewReceiveStreamManager ¶
func NewReceiveStreamManager(peerReceiveStreamMaxCount int32) mgr.ReceiveStreamManager
NewReceiveStreamManager create a new simple mgr.ReceiveStreamManager instance.
func NewSendStreamPoolManager ¶
NewSendStreamPoolManager create a simple implementation instance of mgr.SendStreamPoolManager interface.
func NewSimplePeerStore ¶
NewSimplePeerStore create a simple store.PeerStore instance.
func NewSimpleProtocolExchanger ¶
func NewSimpleProtocolExchanger( host host.Host, protocolMgr mgr.ProtocolManager, logger api.Logger) mgr.ProtocolExchanger
NewSimpleProtocolExchanger create a new simple mgr.ProtocolExchanger instance.
func NewSimpleProtocolMgr ¶
func NewSimpleProtocolMgr(localPID peer.ID, protocolBook store.ProtocolBook) mgr.ProtocolManager
NewSimpleProtocolMgr create a new simple mgr.ProtocolManager instance.
Types ¶
type EliminationStrategy ¶
type EliminationStrategy string
EliminationStrategy is strategy for eliminating connected peer
const ( // Unknown elimination strategy Unknown EliminationStrategy = "UNKNOWN" // Random elimination strategy Random EliminationStrategy = "RANDOM" // FIFO FIRST_IN_FIRST_OUT elimination strategy FIFO EliminationStrategy = "FIFO" // LIFO LAST_IN_FIRST_OUT elimination strategy LIFO EliminationStrategy = "LIFO" )
func EliminationStrategyFromInt ¶
func EliminationStrategyFromInt(strategy int) EliminationStrategy
EliminationStrategyFromInt get EliminationStrategy with a int value. 1.Random, 2.FIFO, 3.LIFO
type GroupMulticastMgr ¶
type GroupMulticastMgr struct {
// contains filtered or unexported fields
}
GroupMulticastMgr is an implementation of groupmulticast.GroupMulticast interface.
func NewGroupMulticastMgr ¶
func NewGroupMulticastMgr(logger api.Logger, host host.Host) *GroupMulticastMgr
NewGroupMulticastMgr .
func (*GroupMulticastMgr) AddPeerToGroup ¶
func (cm *GroupMulticastMgr) AddPeerToGroup(groupName string, peers ...peer.ID)
AddPeerToGroup Add PeerToGroup
func (*GroupMulticastMgr) GroupSize ¶
func (cm *GroupMulticastMgr) GroupSize(groupName string) int
GroupSize Group Size
func (*GroupMulticastMgr) InGroup ¶
func (cm *GroupMulticastMgr) InGroup(groupName string, peer peer.ID) bool
InGroup In Group
func (*GroupMulticastMgr) RemoveGroup ¶
func (cm *GroupMulticastMgr) RemoveGroup(groupName string)
RemoveGroup Remove Group
func (*GroupMulticastMgr) RemovePeerFromGroup ¶
func (cm *GroupMulticastMgr) RemovePeerFromGroup(groupName string, peers ...peer.ID)
RemovePeerFromGroup Remove PeerFromGroup
type LevelConnManager ¶
type LevelConnManager struct {
// contains filtered or unexported fields
}
LevelConnManager is a connection manager of peers.
func NewLevelConnManager ¶
func NewLevelConnManager(logger api.Logger, h host.Host) *LevelConnManager
NewLevelConnManager create a new LevelConnManager.
func (*LevelConnManager) AddAsHighLevelPeer ¶
func (cm *LevelConnManager) AddAsHighLevelPeer(peerId peer.ID)
AddAsHighLevelPeer add a peer id as high level peer.
func (*LevelConnManager) AddPeerConn ¶
AddPeerConn add a connection. if the maximum number of connections is reached, the connection elimination strategy will be executed
func (*LevelConnManager) AllPeer ¶
func (cm *LevelConnManager) AllPeer() []peer.ID
AllPeer return peer id list of all peers connected.
func (*LevelConnManager) ClearHighLevelPeer ¶
func (cm *LevelConnManager) ClearHighLevelPeer()
ClearHighLevelPeer clear all high level peer id records.
func (*LevelConnManager) ExistPeerConn ¶
ExistPeerConn return whether connection exist.
func (*LevelConnManager) ExpendConn ¶
func (cm *LevelConnManager) ExpendConn(pid peer.ID)
ExpendConn try to establish a new connection with peer if the count of connections does not reach the max.
func (*LevelConnManager) GetPeerAllConn ¶
func (cm *LevelConnManager) GetPeerAllConn(pid peer.ID) []network.Conn
GetPeerAllConn return all connections of peer.
func (*LevelConnManager) GetPeerConn ¶
func (cm *LevelConnManager) GetPeerConn(pid peer.ID) network.Conn
GetPeerConn return a connection of peer.
func (*LevelConnManager) IsAllowed ¶
func (cm *LevelConnManager) IsAllowed(pid peer.ID) bool
IsAllowed return true if peer can connect to self. Otherwise, return false.
func (*LevelConnManager) IsConnected ¶
func (cm *LevelConnManager) IsConnected(pid peer.ID) bool
IsConnected return true if peer has connected. Otherwise, return false.
func (*LevelConnManager) IsHighLevel ¶
func (cm *LevelConnManager) IsHighLevel(peerId peer.ID) bool
IsHighLevel return true if the peer which is high-level (consensus & seeds) node. Otherwise, return false.
func (*LevelConnManager) MaxPeerCountAllowed ¶
func (cm *LevelConnManager) MaxPeerCountAllowed() int
MaxPeerCountAllowed return max peer count allowed .
func (*LevelConnManager) PeerCount ¶
func (cm *LevelConnManager) PeerCount() int
PeerCount return the count num of peers.
func (*LevelConnManager) RemoveHighLevelPeer ¶
func (cm *LevelConnManager) RemoveHighLevelPeer(peerId peer.ID)
RemoveHighLevelPeer remove a high level peer id.
func (*LevelConnManager) RemovePeerConn ¶
RemovePeerConn remove a connection.
func (*LevelConnManager) SetMaxConnCountEachPeerAllowed ¶
func (cm *LevelConnManager) SetMaxConnCountEachPeerAllowed(max int)
SetMaxConnCountEachPeerAllowed set max connections count of each peer allowed. If not set, default is 1.
func (*LevelConnManager) SetMaxPeerCountAllowed ¶
func (cm *LevelConnManager) SetMaxPeerCountAllowed(max int)
SetMaxPeerCountAllowed set max count of peers allowed. If not set, default is 20.
func (*LevelConnManager) SetStrategy ¶
func (cm *LevelConnManager) SetStrategy(strategy EliminationStrategy)
SetStrategy set the elimination strategy. If not set, default is LIFO.
type SimplePeerStore ¶
type SimplePeerStore struct { store.ProtocolBook store.AddrBook }
SimplePeerStore is a simple implementation of store.PeerStore interface. It wrapped with a *protocolBook and a *addrBook.