Documentation ¶
Index ¶
- Constants
- Variables
- type BlackList
- func (b *BlackList) AddIPAndPort(ipAndPort string)
- func (b *BlackList) AddPeerID(pid peer.ID)
- func (b *BlackList) BlackConn(conn network.Connection) bool
- func (b *BlackList) BlackPID(pid peer.ID) bool
- func (b *BlackList) RemoveIPAndPort(ipAndPort string)
- func (b *BlackList) RemovePeerID(pid peer.ID)
- type ConnectionSupervisor
- func (c *ConnectionSupervisor) AttachHost(h host.Host)
- func (c *ConnectionSupervisor) NoticePeerDisconnected(pid peer.ID)
- func (c *ConnectionSupervisor) RemoveAllPeer()
- func (c *ConnectionSupervisor) RemovePeerAddr(pid peer.ID)
- func (c *ConnectionSupervisor) SetPeerAddr(pid peer.ID, addr ma.Multiaddr)
- func (c *ConnectionSupervisor) Start() error
- func (c *ConnectionSupervisor) Stop() error
- type EliminationStrategy
- type LevelConnectionManager
- func (l *LevelConnectionManager) AddHighLevelPeer(pid peer.ID)
- func (l *LevelConnectionManager) AddPeerConnection(pid peer.ID, conn network.Connection) bool
- func (l *LevelConnectionManager) AllPeers() []peer.ID
- func (l *LevelConnectionManager) Allowed(pid peer.ID) bool
- func (l *LevelConnectionManager) AttachHost(h host.Host)
- func (l *LevelConnectionManager) Close() error
- func (l *LevelConnectionManager) Connected(pid peer.ID) bool
- func (l *LevelConnectionManager) CountOfPeers() int
- func (l *LevelConnectionManager) ExistPeerConnection(pid peer.ID, conn network.Connection) bool
- func (l *LevelConnectionManager) MaxCountOfPeersAllowed() int
- func (l *LevelConnectionManager) PeerAllConnection(pid peer.ID) []network.Connection
- func (l *LevelConnectionManager) PeerConnection(pid peer.ID) network.Connection
- func (l *LevelConnectionManager) RemovePeerConnection(pid peer.ID, conn network.Connection) bool
- func (l *LevelConnectionManager) SetMaxCountOfConnectionsEachPeer(max int)
- func (l *LevelConnectionManager) SetMaxCountOfPeers(max int)
- func (l *LevelConnectionManager) SetStrategy(strategy EliminationStrategy)
- type ProtocolExchanger
- func (p *ProtocolExchanger) AttachHost(h host.Host)
- func (p *ProtocolExchanger) ExchangeProtocol(conn network.Connection) (protocols []protocol.ID, err error)
- func (p *ProtocolExchanger) Handle(senderPID peer.ID, msgPayload []byte)
- func (p *ProtocolExchanger) ProtocolID() protocol.ID
- func (p *ProtocolExchanger) PushProtocols(pid peer.ID) error
- type ProtocolManager
- func (p *ProtocolManager) AttachHost(h host.Host)
- func (p *ProtocolManager) CleanPeer(pid peer.ID) error
- func (p *ProtocolManager) Handler(protocolID protocol.ID) handler.MsgPayloadHandler
- func (p *ProtocolManager) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
- func (p *ProtocolManager) Registered(protocolID protocol.ID) bool
- func (p *ProtocolManager) RegisteredAll() []protocol.ID
- func (p *ProtocolManager) SetProtocolSupportedNotifyFunc(notifyFunc manager.ProtocolSupportNotifyFunc) error
- func (p *ProtocolManager) SetProtocolUnsupportedNotifyFunc(notifyFunc manager.ProtocolSupportNotifyFunc) error
- func (p *ProtocolManager) SetSupportedProtocolsOfPeer(pid peer.ID, protocolIDs []protocol.ID) error
- func (p *ProtocolManager) SupportedByPeer(pid peer.ID, protocolID protocol.ID) bool
- func (p *ProtocolManager) SupportedProtocolsOfPeer(pid peer.ID) []protocol.ID
- func (p *ProtocolManager) UnregisterMsgPayloadHandler(protocolID protocol.ID) error
- type ReceiveStreamManager
- func (r *ReceiveStreamManager) AddPeerReceiveStream(conn network.Connection, receiveStream network.ReceiveStream) error
- func (r *ReceiveStreamManager) AttachHost(h host.Host)
- func (r *ReceiveStreamManager) ClosePeerReceiveStreams(pid peer.ID, conn network.Connection) error
- func (r *ReceiveStreamManager) GetConnReceiveStreamCount(conn network.Connection) int
- func (r *ReceiveStreamManager) GetCurrentPeerReceiveStreamCount(pid peer.ID) int
- func (r *ReceiveStreamManager) RemovePeerReceiveStream(conn network.Connection, receiveStream network.ReceiveStream) error
- func (r *ReceiveStreamManager) Reset()
- func (r *ReceiveStreamManager) SetPeerReceiveStreamMaxCount(max int)
- type SendStreamPool
- func (s *SendStreamPool) BorrowStream() (sendStream network.SendStream, err error)
- func (s *SendStreamPool) Close() error
- func (s *SendStreamPool) Connection() network.Connection
- func (s *SendStreamPool) CurrentSize() int
- func (s *SendStreamPool) DropStream(sendStream network.SendStream)
- func (s *SendStreamPool) IdleSize() int
- func (s *SendStreamPool) InitStreams() (err error)
- func (s *SendStreamPool) MaxSize() int
- func (s *SendStreamPool) ReturnStream(sendStream network.SendStream) error
- type SendStreamPoolManager
- func (s *SendStreamPoolManager) AddPeerConnSendStreamPool(pid peer.ID, conn network.Connection, sendStreamPool manager.SendStreamPool) error
- func (s *SendStreamPoolManager) AttachHost(h host.Host)
- func (s *SendStreamPoolManager) GetPeerBestConnSendStreamPool(pid peer.ID) manager.SendStreamPool
- func (s *SendStreamPoolManager) RemovePeerConnAndCloseSendStreamPool(pid peer.ID, conn network.Connection) error
- func (s *SendStreamPoolManager) Reset()
Constants ¶
const ( EliminationStrategyUnknown EliminationStrategy = iota EliminationStrategyRandom EliminationStrategyFIFO EliminationStrategyLIFO DefaultMaxCountOfPeers = 20 DefaultMaxCountOfConnectionsEachPeer = 1 DefaultEliminationStrategy = EliminationStrategyLIFO )
const DefaultTryTimes = 10
const (
ProtocolExchangerProtocolID protocol.ID = "/protocol-exchanger/v0.0.1"
)
Variables ¶
var ( ErrUnknownConnectionDirection = errors.New("unknown connection direction") ErrPushProtocolTimeout = errors.New("push protocol timeout") ErrExchangeProtocolTimeout = errors.New("exchange protocol timeout") ErrProtocolOfExchangerMismatch = errors.New("exchanger protocol mismatch") ErrPayloadTypeMismatch = errors.New("exchanger payload type mismatch") )
var ( ErrProtocolIDRegistered = errors.New("protocol id has registered") ErrProtocolIDNotRegistered = errors.New("protocol id is not registered") )
var ( ErrStreamPoolClosed = errors.New("stream pool closed") ErrNoStreamCanBeBorrowed = errors.New("no stream can be borrowed") ErrInitSizeTooBig = errors.New("init size is too big") )
var ( ErrSendStreamPoolHasSet = errors.New("send stream pool of the connection has been set") ErrSendStreamPoolNotSet = errors.New("send stream pool of the connection has not been set yet") )
var (
ErrMaxReceiveStreamsCountReached = errors.New("max receive streams count reached")
)
Functions ¶
This section is empty.
Types ¶
type BlackList ¶
type BlackList struct {
// contains filtered or unexported fields
}
BlackList is a component that implements the PeerBlackList interface to manage a blacklist of network addresses or peer IDs.
func NewBlacklist ¶
func NewBlacklist() *BlackList
NewBlacklist creates a new instance of the BlackList component.
func (*BlackList) AddIPAndPort ¶
AddIPAndPort adds a network address or IP to the blacklist. The address should be in the format "IP:Port".
func (*BlackList) BlackConn ¶
func (b *BlackList) BlackConn(conn network.Connection) bool
BlackConn checks if the remote peer ID or network address of the given connection is blacklisted. Returns true if the connection is blacklisted, otherwise false.
func (*BlackList) BlackPID ¶
BlackPID checks if a given peer ID is blacklisted. Returns true if the peer ID is blacklisted, otherwise false.
func (*BlackList) RemoveIPAndPort ¶
RemoveIPAndPort removes a network address or IP from the blacklist. If the address does not exist in the blacklist, it is a no-op.
func (*BlackList) RemovePeerID ¶
RemovePeerID removes a peer ID from the blacklist. If the peer ID does not exist in the blacklist, it is a no-op.
type ConnectionSupervisor ¶
type ConnectionSupervisor struct {
// contains filtered or unexported fields
}
ConnectionSupervisor is responsible for managing the connections to necessary peers. It implements the manager.ConnectionSupervisor interface.
func NewConnectionSupervisor ¶
func NewConnectionSupervisor(tryTimes int) *ConnectionSupervisor
NewConnectionSupervisor creates a new instance of ConnectionSupervisor.
func (*ConnectionSupervisor) AttachHost ¶
func (c *ConnectionSupervisor) AttachHost(h host.Host)
func (*ConnectionSupervisor) NoticePeerDisconnected ¶
func (c *ConnectionSupervisor) NoticePeerDisconnected(pid peer.ID)
NoticePeerDisconnected is called when a necessary peer is disconnected.
func (*ConnectionSupervisor) RemoveAllPeer ¶
func (c *ConnectionSupervisor) RemoveAllPeer()
RemoveAllPeer removes all necessary peers.
func (*ConnectionSupervisor) RemovePeerAddr ¶
func (c *ConnectionSupervisor) RemovePeerAddr(pid peer.ID)
RemovePeerAddr removes the Multiaddr of a necessary peer.
func (*ConnectionSupervisor) SetPeerAddr ¶
func (c *ConnectionSupervisor) SetPeerAddr(pid peer.ID, addr ma.Multiaddr)
SetPeerAddr sets the Multiaddr of a necessary peer.
func (*ConnectionSupervisor) Start ¶
func (c *ConnectionSupervisor) Start() error
Start starts the ConnectionSupervisor.
func (*ConnectionSupervisor) Stop ¶
func (c *ConnectionSupervisor) Stop() error
Stop stops the ConnectionSupervisor.
type EliminationStrategy ¶
type EliminationStrategy uint8
EliminationStrategy represents the type of elimination strategy.
func StrToEliminationStrategy ¶
func StrToEliminationStrategy(str string) EliminationStrategy
StrToEliminationStrategy converts a string to the corresponding EliminationStrategy.
func (EliminationStrategy) String ¶
func (e EliminationStrategy) String() string
String returns the string representation of the elimination strategy.
type LevelConnectionManager ¶
type LevelConnectionManager struct {
// contains filtered or unexported fields
}
func NewLevelConnectionManager ¶
func NewLevelConnectionManager() *LevelConnectionManager
func (*LevelConnectionManager) AddHighLevelPeer ¶
func (l *LevelConnectionManager) AddHighLevelPeer(pid peer.ID)
AddHighLevelPeer adds a high-level peer ID to the LevelConnectionManager.
func (*LevelConnectionManager) AddPeerConnection ¶
func (l *LevelConnectionManager) AddPeerConnection(pid peer.ID, conn network.Connection) bool
AddPeerConnection adds a peer connection to the LevelConnectionManager. It acquires a lock to ensure thread safety. It returns true if the connection was successfully added, and false otherwise.
func (*LevelConnectionManager) AllPeers ¶
func (l *LevelConnectionManager) AllPeers() []peer.ID
AllPeers returns a slice containing all the peer IDs of connected peers in the LevelConnectionManager. It acquires a read lock to ensure thread safety.
func (*LevelConnectionManager) Allowed ¶
func (l *LevelConnectionManager) Allowed(pid peer.ID) bool
Allowed checks if a given peer ID is allowed to establish new connections in the LevelConnectionManager. It acquires a read lock to ensure thread safety. It returns true if the peer is allowed, and false otherwise.
func (*LevelConnectionManager) AttachHost ¶
func (l *LevelConnectionManager) AttachHost(h host.Host)
func (*LevelConnectionManager) Close ¶
func (l *LevelConnectionManager) Close() error
Close closes all the connections managed by LevelConnectionManager. It acquires a lock to ensure thread safety. It returns an error if there was a problem closing any of the connections, otherwise, it returns nil.
func (*LevelConnectionManager) Connected ¶
func (l *LevelConnectionManager) Connected(pid peer.ID) bool
Connected checks if a given peer ID is connected in the LevelConnectionManager. It acquires a read lock to ensure thread safety. It returns true if the peer is connected, and false otherwise.
func (*LevelConnectionManager) CountOfPeers ¶
func (l *LevelConnectionManager) CountOfPeers() int
CountOfPeers returns the current count of connected peers in the LevelConnectionManager. It acquires a read lock to ensure thread safety.
func (*LevelConnectionManager) ExistPeerConnection ¶
func (l *LevelConnectionManager) ExistPeerConnection(pid peer.ID, conn network.Connection) bool
ExistPeerConnection checks if a peer connection exists in the LevelConnectionManager. It acquires a lock to ensure thread safety. It returns true if the connection exists, and false otherwise.
func (*LevelConnectionManager) MaxCountOfPeersAllowed ¶
func (l *LevelConnectionManager) MaxCountOfPeersAllowed() int
MaxCountOfPeersAllowed returns the maximum count of peers allowed in the LevelConnectionManager.
func (*LevelConnectionManager) PeerAllConnection ¶
func (l *LevelConnectionManager) PeerAllConnection(pid peer.ID) []network.Connection
PeerAllConnection returns all network.Connections associated with a given peer ID in the LevelConnectionManager. It acquires a read lock to ensure thread safety. It returns a slice of network.Connections if connections exist, otherwise it returns an empty slice.
func (*LevelConnectionManager) PeerConnection ¶
func (l *LevelConnectionManager) PeerConnection(pid peer.ID) network.Connection
PeerConnection returns the network.Connection associated with a given peer ID in the LevelConnectionManager. It acquires a read lock to ensure thread safety. It returns the network.Connection if it exists, otherwise it returns nil.
func (*LevelConnectionManager) RemovePeerConnection ¶
func (l *LevelConnectionManager) RemovePeerConnection(pid peer.ID, conn network.Connection) bool
RemovePeerConnection removes a peer connection from the LevelConnectionManager. It acquires a lock to ensure thread safety. It returns true if the connection was successfully removed, and false otherwise.
func (*LevelConnectionManager) SetMaxCountOfConnectionsEachPeer ¶
func (l *LevelConnectionManager) SetMaxCountOfConnectionsEachPeer(max int)
SetMaxCountOfConnectionsEachPeer sets the maximum count of connections allowed for each peer in the LevelConnectionManager.
func (*LevelConnectionManager) SetMaxCountOfPeers ¶
func (l *LevelConnectionManager) SetMaxCountOfPeers(max int)
SetMaxCountOfPeers sets the maximum count of peers for the LevelConnectionManager.
func (*LevelConnectionManager) SetStrategy ¶
func (l *LevelConnectionManager) SetStrategy(strategy EliminationStrategy)
SetStrategy sets the elimination strategy for the LevelConnectionManager.
type ProtocolExchanger ¶
type ProtocolExchanger struct {
// contains filtered or unexported fields
}
func NewProtocolExchanger ¶
func NewProtocolExchanger(protocolManager manager.ProtocolManager) *ProtocolExchanger
func (*ProtocolExchanger) AttachHost ¶
func (p *ProtocolExchanger) AttachHost(h host.Host)
func (*ProtocolExchanger) ExchangeProtocol ¶
func (p *ProtocolExchanger) ExchangeProtocol(conn network.Connection) (protocols []protocol.ID, err error)
ExchangeProtocol exchanges protocols with a connected network connection. It creates a timeout context and starts a goroutine to perform the protocol exchange. It waits for the exchange to complete or for the timeout to occur. Returns the exchanged protocols or an error if the operation times out.
func (*ProtocolExchanger) Handle ¶
func (p *ProtocolExchanger) Handle(senderPID peer.ID, msgPayload []byte)
Handle is the message payload handler of the exchanger service.
func (*ProtocolExchanger) ProtocolID ¶
func (p *ProtocolExchanger) ProtocolID() protocol.ID
ProtocolID returns the protocol ID of the ProtocolExchanger.
func (*ProtocolExchanger) PushProtocols ¶
func (p *ProtocolExchanger) PushProtocols(pid peer.ID) error
PushProtocols sends a PUSH request to another peer identified by the given peer ID. It manages the synchronization of concurrent PushProtocols calls by using a pushSignalC map. If a PushProtocols call is already in progress for the same peer ID, it delays the execution for a certain period. Returns an error if the PUSH operation times out.
type ProtocolManager ¶
type ProtocolManager struct {
// contains filtered or unexported fields
}
ProtocolManager manages protocols and protocol message handlers for peers.
func NewProtocolManager ¶
func NewProtocolManager(protocolBook store.ProtocolBook) *ProtocolManager
NewProtocolManager creates a new instance of ProtocolManager with the provided ProtocolBook. It initializes the internal fields of the ProtocolManager and returns a value that implements the manager.ProtocolManager interface.
func (*ProtocolManager) AttachHost ¶
func (p *ProtocolManager) AttachHost(h host.Host)
func (*ProtocolManager) CleanPeer ¶
func (p *ProtocolManager) CleanPeer(pid peer.ID) error
CleanPeer removes all records of protocols supported by the peer with the given peer.ID. It notifies the registered callback functions for any unsupported protocols. It returns an error if the cleanup fails.
func (*ProtocolManager) Handler ¶
func (p *ProtocolManager) Handler(protocolID protocol.ID) handler.MsgPayloadHandler
Handler returns the message payload handler associated with the registered protocol. If the protocol is not registered or supported, it returns nil.
func (*ProtocolManager) RegisterMsgPayloadHandler ¶
func (p *ProtocolManager) RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
RegisterMsgPayloadHandler registers a protocol and associates a handler.MsgPayloadHandler with it. It returns an error if the registration fails.
func (*ProtocolManager) Registered ¶
func (p *ProtocolManager) Registered(protocolID protocol.ID) bool
Registered checks if a protocol is registered and supported. It returns true if the protocol is supported, and false otherwise.
func (*ProtocolManager) RegisteredAll ¶
func (p *ProtocolManager) RegisteredAll() []protocol.ID
RegisteredAll returns a list of all registered protocol IDs. It acquires a read lock to safely access the registered protocol IDs and their corresponding handlers. It returns the list of protocol IDs as a slice.
func (*ProtocolManager) SetProtocolSupportedNotifyFunc ¶
func (p *ProtocolManager) SetProtocolSupportedNotifyFunc(notifyFunc manager.ProtocolSupportNotifyFunc) error
SetProtocolSupportedNotifyFunc sets the callback function to be invoked when a protocol is supported by a peer. It returns an error if the setting fails.
func (*ProtocolManager) SetProtocolUnsupportedNotifyFunc ¶
func (p *ProtocolManager) SetProtocolUnsupportedNotifyFunc(notifyFunc manager.ProtocolSupportNotifyFunc) error
SetProtocolUnsupportedNotifyFunc sets the callback function to be invoked when a protocol is unsupported by a peer. It returns an error if the setting fails.
func (*ProtocolManager) SetSupportedProtocolsOfPeer ¶
SetSupportedProtocolsOfPeer stores the protocols supported by the peer with the given peer.ID. It notifies the registered callback functions if there are changes in the supported protocols of the peer. It returns an error if the protocol storage fails.
func (*ProtocolManager) SupportedByPeer ¶
SupportedByPeer checks if a peer with the given peer.ID supports a specific protocol. It returns true if the protocol is supported by the peer, and false otherwise. If the peer is not connected, it returns false.
func (*ProtocolManager) SupportedProtocolsOfPeer ¶
func (p *ProtocolManager) SupportedProtocolsOfPeer(pid peer.ID) []protocol.ID
SupportedProtocolsOfPeer returns a list of protocol.IDs that are supported by the peer with the given peer.ID. If the peer is not connected or doesn't support any protocols, it returns an empty list.
func (*ProtocolManager) UnregisterMsgPayloadHandler ¶
func (p *ProtocolManager) UnregisterMsgPayloadHandler(protocolID protocol.ID) error
UnregisterMsgPayloadHandler unregisters a previously registered protocol. It returns an error if the un-registration fails.
type ReceiveStreamManager ¶
type ReceiveStreamManager struct {
// contains filtered or unexported fields
}
ReceiveStreamManager manages the receive streams for peer connections.
func NewReceiveStreamManager ¶
func NewReceiveStreamManager() *ReceiveStreamManager
NewReceiveStreamManager creates a new instance of the ReceiveStreamManager type that implements the manager.ReceiveStreamManager interface. The returned ReceiveStreamManager can be used to manage receive streams for peer connections.
func (*ReceiveStreamManager) AddPeerReceiveStream ¶
func (r *ReceiveStreamManager) AddPeerReceiveStream( conn network.Connection, receiveStream network.ReceiveStream, ) error
AddPeerReceiveStream adds a receive stream for a specific peer connection.
func (*ReceiveStreamManager) AttachHost ¶
func (r *ReceiveStreamManager) AttachHost(h host.Host)
func (*ReceiveStreamManager) ClosePeerReceiveStreams ¶
func (r *ReceiveStreamManager) ClosePeerReceiveStreams(pid peer.ID, conn network.Connection) error
ClosePeerReceiveStreams closes all receive streams for a specific peer connection.
func (*ReceiveStreamManager) GetConnReceiveStreamCount ¶
func (r *ReceiveStreamManager) GetConnReceiveStreamCount(conn network.Connection) int
GetConnReceiveStreamCount returns the number of receive streams associated with the given network connection.
func (*ReceiveStreamManager) GetCurrentPeerReceiveStreamCount ¶
func (r *ReceiveStreamManager) GetCurrentPeerReceiveStreamCount(pid peer.ID) int
GetCurrentPeerReceiveStreamCount returns the current count of receive streams for a peer.
func (*ReceiveStreamManager) RemovePeerReceiveStream ¶
func (r *ReceiveStreamManager) RemovePeerReceiveStream( conn network.Connection, receiveStream network.ReceiveStream, ) error
RemovePeerReceiveStream removes a receive stream for a specific peer connection.
func (*ReceiveStreamManager) Reset ¶
func (r *ReceiveStreamManager) Reset()
Reset clears all receive streams and counts.
func (*ReceiveStreamManager) SetPeerReceiveStreamMaxCount ¶
func (r *ReceiveStreamManager) SetPeerReceiveStreamMaxCount(max int)
SetPeerReceiveStreamMaxCount sets the maximum count of receive streams for a peer. If max is not a positive value, the ReceiveStreamManager will not limit the number of receive streams per peer.
type SendStreamPool ¶
type SendStreamPool struct {
// contains filtered or unexported fields
}
SendStreamPool is a pool of send streams.
func NewSendStreamPool ¶
func NewSendStreamPool(initSize, maxSize int, conn network.Connection) (*SendStreamPool, error)
NewSendStreamPool creates a new instance of SendStreamPool. It initializes the SendStreamPool with the given initial size, maximum size, connection. If the initial size is greater than the maximum size, it returns an error.
func (*SendStreamPool) BorrowStream ¶
func (s *SendStreamPool) BorrowStream() (sendStream network.SendStream, err error)
BorrowStream borrows a send stream from the SendStreamPool. It acquires a lock, tries to retrieve a send stream from the pool, if none is available and the currentSize is not at the maxSize, it opens a new send stream, if the currentSize is at the maxSize, it returns ErrNoStreamCanBeBorrowed, otherwise, it returns the borrowed send stream.
func (*SendStreamPool) Close ¶
func (s *SendStreamPool) Close() error
Close closes the SendStreamPool.
func (*SendStreamPool) Connection ¶
func (s *SendStreamPool) Connection() network.Connection
Connection returns the network connection associated with the SendStreamPool.
func (*SendStreamPool) CurrentSize ¶
func (s *SendStreamPool) CurrentSize() int
CurrentSize returns the current size of the SendStreamPool.
func (*SendStreamPool) DropStream ¶
func (s *SendStreamPool) DropStream(sendStream network.SendStream)
DropStream closes and drops a send stream from the SendStreamPool. This method should be invoked only when errors are found. It acquires a lock, closes the send stream, decreases the currentSize, and resets the currentSize and idleSize if they become negative.
func (*SendStreamPool) IdleSize ¶
func (s *SendStreamPool) IdleSize() int
IdleSize returns the number of idle send streams in the SendStreamPool.
func (*SendStreamPool) InitStreams ¶
func (s *SendStreamPool) InitStreams() (err error)
InitStreams initializes the send streams in the SendStreamPool. It acquires a lock, opens send streams until the currentSize reaches the initSize, logs the initialization, and starts the expandLoop goroutine.
func (*SendStreamPool) MaxSize ¶
func (s *SendStreamPool) MaxSize() int
MaxSize returns the maximum size of the SendStreamPool.
func (*SendStreamPool) ReturnStream ¶
func (s *SendStreamPool) ReturnStream(sendStream network.SendStream) error
ReturnStream returns a send stream to the SendStreamPool. It acquires a lock, tries to return the send stream to the pool, if the pool is full, it closes the send stream, otherwise, it adds the send stream to the pool.
type SendStreamPoolManager ¶
type SendStreamPoolManager struct {
// contains filtered or unexported fields
}
SendStreamPoolManager manages the send stream pools for peer connections.
func NewSendStreamPoolManager ¶
func NewSendStreamPoolManager() *SendStreamPoolManager
NewSendStreamPoolManager creates a new instance of the SendStreamPoolManager type that implements the manager.SendStreamPoolManager interface. The returned SendStreamPoolManager can be used to manage send stream pools.
func (*SendStreamPoolManager) AddPeerConnSendStreamPool ¶
func (s *SendStreamPoolManager) AddPeerConnSendStreamPool( pid peer.ID, conn network.Connection, sendStreamPool manager.SendStreamPool, ) error
AddPeerConnSendStreamPool adds a send stream pool for a specific peer connection.
func (*SendStreamPoolManager) AttachHost ¶
func (s *SendStreamPoolManager) AttachHost(h host.Host)
func (*SendStreamPoolManager) GetPeerBestConnSendStreamPool ¶
func (s *SendStreamPoolManager) GetPeerBestConnSendStreamPool(pid peer.ID) manager.SendStreamPool
GetPeerBestConnSendStreamPool returns the send stream pool for the peer connection with the most idle streams.
func (*SendStreamPoolManager) RemovePeerConnAndCloseSendStreamPool ¶
func (s *SendStreamPoolManager) RemovePeerConnAndCloseSendStreamPool(pid peer.ID, conn network.Connection) error
RemovePeerConnAndCloseSendStreamPool removes a send stream pool for a specific peer connection and closes the pool.
func (*SendStreamPoolManager) Reset ¶
func (s *SendStreamPoolManager) Reset()
Reset clears all send stream pools.