simple

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: 28 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultEliminationStrategy = LIFO

DefaultEliminationStrategy is the default strategy for elimination.

View Source
const DefaultMaxConnCountEachPeerAllowed = 1

DefaultMaxConnCountEachPeerAllowed is the default max connections count of each peer allowed.

View Source
const DefaultMaxPeerCountAllow = 20

DefaultMaxPeerCountAllow is the default max peer count allowed.

View Source
const DefaultTryTimes = 50

DefaultTryTimes default try times

View Source
const (
	// ProtocolExchangerProtocolID is the protocol.ID for exchanger.
	ProtocolExchangerProtocolID protocol.ID = "/protocol-exchanger/v0.0.1"
)

Variables

View Source
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")
)
View Source
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")
)
View Source
var (
	// ErrConnExist will be returned when connection already exist.
	ErrConnExist = errors.New("conn exist")
	// ErrConnNotExist will be returned if connection not exist.
	ErrConnNotExist = errors.New("conn not exist")
)
View Source
var (
	// ErrReceiveStreamsCountReachMax will be returned when the count of receive streams reach the maximum value.
	ErrReceiveStreamsCountReachMax = errors.New("receive streams count reach the maximum value")
)

Functions

func NewAddrBook added in v1.3.0

func NewAddrBook() store.AddrBook

NewAddrBook create a new addBook.

func NewBlackList

func NewBlackList() blacklist.BlackList

NewBlackList create a new *simpleBlacklist instance.

func NewConnSupervisor

func NewConnSupervisor(h host.Host, logger api.Logger) mgr.ConnSupervisor

NewConnSupervisor create a new *connSupervisor instance.

func NewReceiveStreamManager

func NewReceiveStreamManager(peerReceiveStreamMaxCount int32) mgr.ReceiveStreamManager

NewReceiveStreamManager create a new simple mgr.ReceiveStreamManager instance.

func NewSendStreamPoolManager

func NewSendStreamPoolManager(connMgr mgr.ConnMgr, log api.Logger) mgr.SendStreamPoolManager

NewSendStreamPoolManager create a simple implementation instance of mgr.SendStreamPoolManager interface.

func NewSimplePeerStore

func NewSimplePeerStore(localPid peer.ID) store.PeerStore

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.

func NewSimpleStreamPool

func NewSimpleStreamPool(
	initSize, cap int32, conn network.Conn, host host.Host, log api.Logger) (mgr.SendStreamPool, error)

NewSimpleStreamPool create a new simple mgr.SendStreamPool instance.

func NewSingleStreamPool added in v1.3.0

func NewSingleStreamPool(conn network.Conn, host host.Host, log api.Logger) (mgr.SendStreamPool, error)

NewSingleStreamPool create a new mgr.SendStreamPool . SingleStreamPool have only one stream close stream will not influence conn but only stream

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

func (*GroupMulticastMgr) SendToGroupAsync

func (cm *GroupMulticastMgr) SendToGroupAsync(groupName string, protocolID protocol.ID, data []byte)

SendToGroupAsync .

func (*GroupMulticastMgr) SendToGroupSync

func (cm *GroupMulticastMgr) SendToGroupSync(groupName string, protocolID protocol.ID, data []byte) error

SendToGroupSync Send To GroupSync

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

func (cm *LevelConnManager) AddPeerConn(pid peer.ID, conn network.Conn) bool

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

func (cm *LevelConnManager) Close() error

Close connection manager

func (*LevelConnManager) ExistPeerConn

func (cm *LevelConnManager) ExistPeerConn(pid peer.ID, conn network.Conn) bool

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

func (cm *LevelConnManager) RemovePeerConn(pid peer.ID, conn network.Conn) bool

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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