Documentation ¶
Index ¶
- type ConnectionManager
- func (m *ConnectionManager) ClosedStream(nt net.Network, s net.Stream)
- func (m *ConnectionManager) Connected(n net.Network, conn net.Conn)
- func (m *ConnectionManager) Disconnected(n net.Network, conn net.Conn)
- func (m *ConnectionManager) GetConnsCount() *ConnsInfo
- func (m *ConnectionManager) Listen(net.Network, ma.Multiaddr)
- func (m *ConnectionManager) ListenClose(net.Network, ma.Multiaddr)
- func (m *ConnectionManager) Manage()
- func (m *ConnectionManager) OpenedStream(n net.Network, s net.Stream)
- func (m *ConnectionManager) SetConnsInfo(info *ConnsInfo)
- type ConnsInfo
- type Manager
- func (m *Manager) AddAcquainted(peer core.Engine)
- func (m *Manager) AddOrUpdateNode(n core.Engine)
- func (m *Manager) AddPeer(peer core.Engine)
- func (m *Manager) AddTimeBan(peer core.Engine, dur time.Duration)
- func (m *Manager) CanAcceptNode(node core.Engine, opts ...bool) (bool, error)
- func (m *Manager) CleanPeers() int
- func (m *Manager) ClearConnFailCount(nodeAddr util.NodeAddr)
- func (m *Manager) ConnMgr() *ConnectionManager
- func (m *Manager) ConnectToNode(node core.Engine) error
- func (m *Manager) ConnectToPeer(peerID string) error
- func (m *Manager) CopyActivePeers(limit int) (peers []core.Engine)
- func (m *Manager) ForgetPeers()
- func (m *Manager) GetAcquaintedPeers() (peers []core.Engine)
- func (m *Manager) GetActivePeers(limit int) (peers []core.Engine)
- func (m *Manager) GetBanTime(peer core.Engine) time.Time
- func (m *Manager) GetConnFailCount(nodeAddr util.NodeAddr) int
- func (m *Manager) GetConnectedPeers() (peers []core.Engine)
- func (m *Manager) GetLonelyPeers() (peers []core.Engine)
- func (m *Manager) GetPeer(peerID string) core.Engine
- func (m *Manager) GetPeers() (peers []core.Engine)
- func (m *Manager) GetRandomActivePeers(limit int) []core.Engine
- func (m *Manager) GetUnconnectedPeers() (peers []core.Engine)
- func (m *Manager) HasDisconnected(peerAddr util.NodeAddr) error
- func (m *Manager) IncrConnFailCount(nodeAddr util.NodeAddr)
- func (m *Manager) IsAcquainted(peer core.Engine) bool
- func (m *Manager) IsActive(p core.Engine) bool
- func (m *Manager) IsBanned(peer core.Engine) bool
- func (m *Manager) IsLocalNode(p core.Engine) bool
- func (m *Manager) LoadPeers() error
- func (m *Manager) LocalPeer() core.Engine
- func (m *Manager) Manage()
- func (m *Manager) PeerExist(peerID string) bool
- func (m *Manager) Peers() map[string]core.Engine
- func (m *Manager) RemoveAcquainted(peer core.Engine)
- func (m *Manager) RequirePeers() bool
- func (m *Manager) SavePeers() error
- func (m *Manager) SetLocalNode(n core.Engine)
- func (m *Manager) SetPeers(d map[string]core.Engine)
- func (m *Manager) Stop()
- func (m *Manager) TimeBanIndex() map[string]time.Time
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionManager ¶
ConnectionManager manages the active connections ensuring the required number of connections at any given time is maintained
func NewConnMrg ¶
func NewConnMrg(m *Manager, log logger.Logger) *ConnectionManager
NewConnMrg creates a new connection manager
func (*ConnectionManager) ClosedStream ¶
func (m *ConnectionManager) ClosedStream(nt net.Network, s net.Stream)
ClosedStream is called when a stream is openned
func (*ConnectionManager) Connected ¶
func (m *ConnectionManager) Connected(n net.Network, conn net.Conn)
Connected is called when a connection is opened. Check inbound and outbound connection count state and close connections when limits are reached.
func (*ConnectionManager) Disconnected ¶
func (m *ConnectionManager) Disconnected(n net.Network, conn net.Conn)
Disconnected is called when a connection is closed. Update the connection count and inform the peer manager of the disconnection event.
func (*ConnectionManager) GetConnsCount ¶
func (m *ConnectionManager) GetConnsCount() *ConnsInfo
GetConnsCount gets the inbound and outbound connections count.
func (*ConnectionManager) Listen ¶
func (m *ConnectionManager) Listen(net.Network, ma.Multiaddr)
Listen is called when hosts starts listening on an address
func (*ConnectionManager) ListenClose ¶
func (m *ConnectionManager) ListenClose(net.Network, ma.Multiaddr)
ListenClose is called when host stops listening on an address
func (*ConnectionManager) Manage ¶
func (m *ConnectionManager) Manage()
Manage starts connection management
func (*ConnectionManager) OpenedStream ¶
func (m *ConnectionManager) OpenedStream(n net.Network, s net.Stream)
OpenedStream is called when a stream is openned
func (*ConnectionManager) SetConnsInfo ¶
func (m *ConnectionManager) SetConnsInfo(info *ConnsInfo)
SetConnsInfo sets the connections information. Only used in tests.
type ConnsInfo ¶
ConnsInfo stores information about connections such as the number of inbound and outbound connections, etc
func NewConnsInfo ¶
NewConnsInfo creates an instance of ConnsInfo
func (*ConnsInfo) DecrInbound ¶
func (i *ConnsInfo) DecrInbound()
DecrInbound decrements outbound count
func (*ConnsInfo) DecrOutbound ¶
func (i *ConnsInfo) DecrOutbound()
DecrOutbound decrements outbound count
func (*ConnsInfo) IncOutbound ¶
func (i *ConnsInfo) IncOutbound()
IncOutbound increments outbound count
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages known peers connected to the local peer. It is responsible for initiating and managing peers according to the current protocol and engine rules.
func NewManager ¶
NewManager creates an instance of the peer manager
func (*Manager) AddAcquainted ¶
AddAcquainted marks a peer has haven gone passed the handshake step
func (*Manager) AddOrUpdateNode ¶
AddOrUpdateNode adds a peer to peer list if it hasn't been added. It updates the timestamp of existing peers.
func (*Manager) AddTimeBan ¶
AddTimeBan stores a time a peer is considered banned from outbound or inbound communication. If an existing entry exist for peer, add dur to it.
func (*Manager) CanAcceptNode ¶
CanAcceptNode determines whether we can continue to interact with a given node.
func (*Manager) CleanPeers ¶
CleanPeers removes old peers from the list of peers known by the local peer. Typically, we remove peers based on their active status. It returns the number of peers removed
func (*Manager) ClearConnFailCount ¶
ClearConnFailCount clears the connection failure count of n
func (*Manager) ConnMgr ¶
func (m *Manager) ConnMgr() *ConnectionManager
ConnMgr gets the connection manager
func (*Manager) ConnectToNode ¶
ConnectToNode attempts to a Handshake message to a remote node. If successful, it sends a GetAddr message.
func (*Manager) ConnectToPeer ¶
ConnectToPeer attempts to establish a connection to a peer with the given id
func (*Manager) CopyActivePeers ¶
CopyActivePeers is like GetActivePeers but a different slice is returned
func (*Manager) ForgetPeers ¶
func (m *Manager) ForgetPeers()
ForgetPeers deletes peers in memory and on disk
func (*Manager) GetAcquaintedPeers ¶
GetAcquaintedPeers returns connected and acquainted peers
func (*Manager) GetActivePeers ¶
GetActivePeers returns active peers. Passing a zero or negative value as limit means no limit is applied.
func (*Manager) GetBanTime ¶
GetBanTime gets the ban end time of peer
func (*Manager) GetConnFailCount ¶
GetConnFailCount returns the connection failure count of n
func (*Manager) GetConnectedPeers ¶
GetConnectedPeers returns connected peers
func (*Manager) GetLonelyPeers ¶
GetLonelyPeers returns the peers that are currently not connected or are connected unacquainted to the local peer.
func (*Manager) GetRandomActivePeers ¶
GetRandomActivePeers returns a slice of randomly selected peers whose timestamp is within 3 hours ago.
func (*Manager) GetUnconnectedPeers ¶
GetUnconnectedPeers returns the peers that are currently not connected to the local peer.
func (*Manager) HasDisconnected ¶
HasDisconnected is called with a address belonging to a peer that had just disconnected. It will set the last seen time of the peer to an hour ago to to quicken the time to clean up. The peer may reconnect before clean up.
func (*Manager) IncrConnFailCount ¶
IncrConnFailCount increases the connection failure count of n
func (*Manager) IsAcquainted ¶
IsAcquainted checks whether the peer passed through the handshake step
func (*Manager) IsLocalNode ¶
IsLocalNode checks if a peer is the local peer
func (*Manager) Manage ¶
func (m *Manager) Manage()
Manage starts managing peer connections. Load peers that were serialized and stored in database. Start connection manager Start periodic self advertisement to other peers Start periodic clean up of known peer list Start periodic ping messages to peers
func (*Manager) RemoveAcquainted ¶
RemoveAcquainted makes a peer unacquainted
func (*Manager) RequirePeers ¶
RequirePeers checks whether we need more peers
func (*Manager) SetLocalNode ¶
SetLocalNode sets the local node