peermanager

package
v0.1.8-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 11 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionManager

type ConnectionManager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

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

type ConnsInfo struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ConnsInfo stores information about connections such as the number of inbound and outbound connections, etc

func NewConnsInfo

func NewConnsInfo(inbound, outbound int) *ConnsInfo

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

func (i *ConnsInfo) IncInbound()

IncInbound increments inbound count

func (*ConnsInfo) IncOutbound

func (i *ConnsInfo) IncOutbound()

IncOutbound increments outbound count

func (*ConnsInfo) Info

func (i *ConnsInfo) Info() (inbound int, outbound int)

Info returns the number of inbound and outbound connections

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

func NewManager(cfg *config.EngineConfig, localPeer core.Engine, log logger.Logger) *Manager

NewManager creates an instance of the peer manager

func (*Manager) AddAcquainted

func (m *Manager) AddAcquainted(peer core.Engine)

AddAcquainted marks a peer has haven gone passed the handshake step

func (*Manager) AddOrUpdateNode

func (m *Manager) AddOrUpdateNode(n core.Engine)

AddOrUpdateNode adds a peer to peer list if it hasn't been added. It updates the timestamp of existing peers.

func (*Manager) AddPeer

func (m *Manager) AddPeer(peer core.Engine)

AddPeer adds a peer

func (*Manager) AddTimeBan

func (m *Manager) AddTimeBan(peer core.Engine, dur time.Duration)

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

func (m *Manager) CanAcceptNode(node core.Engine, opts ...bool) (bool, error)

CanAcceptNode determines whether we can continue to interact with a given node.

func (*Manager) CleanPeers

func (m *Manager) CleanPeers() int

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

func (m *Manager) ClearConnFailCount(nodeAddr util.NodeAddr)

ClearConnFailCount clears the connection failure count of n

func (*Manager) ConnMgr

func (m *Manager) ConnMgr() *ConnectionManager

ConnMgr gets the connection manager

func (*Manager) ConnectToNode

func (m *Manager) ConnectToNode(node core.Engine) error

ConnectToNode attempts to a Handshake message to a remote node. If successful, it sends a GetAddr message.

func (*Manager) ConnectToPeer

func (m *Manager) ConnectToPeer(peerID string) error

ConnectToPeer attempts to establish a connection to a peer with the given id

func (*Manager) CopyActivePeers

func (m *Manager) CopyActivePeers(limit int) (peers []core.Engine)

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

func (m *Manager) GetAcquaintedPeers() (peers []core.Engine)

GetAcquaintedPeers returns connected and acquainted peers

func (*Manager) GetActivePeers

func (m *Manager) GetActivePeers(limit int) (peers []core.Engine)

GetActivePeers returns active peers. Passing a zero or negative value as limit means no limit is applied.

func (*Manager) GetBanTime

func (m *Manager) GetBanTime(peer core.Engine) time.Time

GetBanTime gets the ban end time of peer

func (*Manager) GetConnFailCount

func (m *Manager) GetConnFailCount(nodeAddr util.NodeAddr) int

GetConnFailCount returns the connection failure count of n

func (*Manager) GetConnectedPeers

func (m *Manager) GetConnectedPeers() (peers []core.Engine)

GetConnectedPeers returns connected peers

func (*Manager) GetLonelyPeers

func (m *Manager) GetLonelyPeers() (peers []core.Engine)

GetLonelyPeers returns the peers that are currently not connected or are connected unacquainted to the local peer.

func (*Manager) GetPeer

func (m *Manager) GetPeer(peerID string) core.Engine

GetPeer returns a peer

func (*Manager) GetPeers

func (m *Manager) GetPeers() (peers []core.Engine)

GetPeers gets all the known peers (connected or unconnected).

func (*Manager) GetRandomActivePeers

func (m *Manager) GetRandomActivePeers(limit int) []core.Engine

GetRandomActivePeers returns a slice of randomly selected peers whose timestamp is within 3 hours ago.

func (*Manager) GetUnconnectedPeers

func (m *Manager) GetUnconnectedPeers() (peers []core.Engine)

GetUnconnectedPeers returns the peers that are currently not connected to the local peer.

func (*Manager) HasDisconnected

func (m *Manager) HasDisconnected(peerAddr util.NodeAddr) error

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

func (m *Manager) IncrConnFailCount(nodeAddr util.NodeAddr)

IncrConnFailCount increases the connection failure count of n

func (*Manager) IsAcquainted

func (m *Manager) IsAcquainted(peer core.Engine) bool

IsAcquainted checks whether the peer passed through the handshake step

func (*Manager) IsActive

func (m *Manager) IsActive(p core.Engine) bool

IsActive returns true of a peer is considered active.

func (*Manager) IsBanned

func (m *Manager) IsBanned(peer core.Engine) bool

IsBanned checks whether a peer has been banned.

func (*Manager) IsLocalNode

func (m *Manager) IsLocalNode(p core.Engine) bool

IsLocalNode checks if a peer is the local peer

func (*Manager) LoadPeers

func (m *Manager) LoadPeers() error

LoadPeers loads peers stored in the local database

func (*Manager) LocalPeer

func (m *Manager) LocalPeer() core.Engine

LocalPeer returns 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) PeerExist

func (m *Manager) PeerExist(peerID string) bool

PeerExist checks whether a peer is a known peer

func (*Manager) Peers

func (m *Manager) Peers() map[string]core.Engine

Peers returns the map of known peers

func (*Manager) RemoveAcquainted

func (m *Manager) RemoveAcquainted(peer core.Engine)

RemoveAcquainted makes a peer unacquainted

func (*Manager) RequirePeers

func (m *Manager) RequirePeers() bool

RequirePeers checks whether we need more peers

func (*Manager) SavePeers

func (m *Manager) SavePeers() error

SavePeers stores active peer addresses

func (*Manager) SetLocalNode

func (m *Manager) SetLocalNode(n core.Engine)

SetLocalNode sets the local node

func (*Manager) SetPeers

func (m *Manager) SetPeers(d map[string]core.Engine)

SetPeers sets the known peers

func (*Manager) Stop

func (m *Manager) Stop()

Stop gracefully stops running routines managed by the manager

func (*Manager) TimeBanIndex

func (m *Manager) TimeBanIndex() map[string]time.Time

TimeBanIndex get the time ban index

Jump to

Keyboard shortcuts

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