manage

package
v1.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package manage p2p manage

Index

Constants

This section is empty.

Variables

View Source
var CacheLimit int32 = 50

CacheLimit cachebuffer

Functions

This section is empty.

Types

type ConnManager

type ConnManager struct {
	// contains filtered or unexported fields
}

ConnManager p2p connection manager

func NewConnManager

func NewConnManager(ctx context.Context, host core.Host, rt *kb.RoutingTable, tracker *metrics.BandwidthCounter, cfg *p2pty.P2PSubConfig) *ConnManager

NewConnManager new connection manager

func (*ConnManager) AddNeighbors

func (s *ConnManager) AddNeighbors(pr *peer.AddrInfo)

AddNeighbors add neighbors by peer info

func (*ConnManager) BandTrackerByProtocol

func (s *ConnManager) BandTrackerByProtocol() *types.NetProtocolInfos

BandTrackerByProtocol returns all protocols band info

func (*ConnManager) BoundSize

func (s *ConnManager) BoundSize() (insize int, outsize int)

BoundSize get in out conn bound size

func (*ConnManager) CheckDirection

func (s *ConnManager) CheckDirection(pid peer.ID) network.Direction

CheckDirection 检查连接的节点ID是被连接的还是主动连接的

func (*ConnManager) Delete

func (s *ConnManager) Delete(pid peer.ID)

Delete delete peer by id

func (*ConnManager) FetchConnPeers

func (s *ConnManager) FetchConnPeers() []peer.ID

FetchConnPeers 获取连接的Peer's ID 这个连接包含被连接的peer以及主动连接的peer.

func (*ConnManager) FetchNearestPeers

func (s *ConnManager) FetchNearestPeers(count int) []peer.ID

FetchNearestPeers fetch nearest peer ids

func (*ConnManager) GetNetRate

func (s *ConnManager) GetNetRate() metrics.Stats

GetNetRate get rateinfo

func (*ConnManager) InBounds

func (s *ConnManager) InBounds() []peer.ID

InBounds get in bounds conn peers

func (*ConnManager) IsNeighbors

func (s *ConnManager) IsNeighbors(pid peer.ID) bool

IsNeighbors check is neighbors by id

func (*ConnManager) MonitorAllPeers

func (s *ConnManager) MonitorAllPeers()

MonitorAllPeers monitory all peers

func (*ConnManager) OutBounds

func (s *ConnManager) OutBounds() []peer.ID

OutBounds get out bounds conn peers

func (*ConnManager) RateCalculate

func (s *ConnManager) RateCalculate(ratebytes float64) string

RateCalculate means bytes sent / received per second.

func (*ConnManager) Size

func (s *ConnManager) Size() int

Size connections size

type Conngater

type Conngater struct {
	// contains filtered or unexported fields
}

Conngater gater struct data

func NewConnGater

func NewConnGater(h *host.Host, limit int32, cache *TimeCache, whitPeers []*peer.AddrInfo) *Conngater

NewConnGater connect gater

func (*Conngater) InterceptAccept

func (s *Conngater) InterceptAccept(n network.ConnMultiaddrs) (allow bool)

InterceptAccept tests whether an incipient inbound connection is allowed.

func (*Conngater) InterceptAddrDial

func (s *Conngater) InterceptAddrDial(_ peer.ID, m multiaddr.Multiaddr) (allow bool)

InterceptAddrDial tests whether we're permitted to dial the specified multiaddr for the given peer.

func (*Conngater) InterceptPeerDial

func (s *Conngater) InterceptPeerDial(p peer.ID) (allow bool)

InterceptPeerDial tests whether we're permitted to Dial the specified peer.

func (*Conngater) InterceptSecured

func (s *Conngater) InterceptSecured(_ network.Direction, _ peer.ID, n network.ConnMultiaddrs) (allow bool)

InterceptSecured tests whether a given connection, now authenticated, is allowed.

func (*Conngater) InterceptUpgraded

func (s *Conngater) InterceptUpgraded(n network.Conn) (allow bool, reason control.DisconnectReason)

InterceptUpgraded tests whether a fully capable connection is allowed.

type PeerInfoManager

type PeerInfoManager struct {
	// contains filtered or unexported fields
}

PeerInfoManager peer info manager

func NewPeerInfoManager

func NewPeerInfoManager(ctx context.Context, host host.Host, cli queue.Client) *PeerInfoManager

NewPeerInfoManager new peer info manager

func (*PeerInfoManager) Fetch

func (p *PeerInfoManager) Fetch(pid peer.ID) *types.Peer

Fetch returns info of given peer

func (*PeerInfoManager) FetchAll

func (p *PeerInfoManager) FetchAll() []*types.Peer

FetchAll returns all peers info

func (*PeerInfoManager) PeerHeight

func (p *PeerInfoManager) PeerHeight(pid peer.ID) int64

PeerHeight returns block height of given peer

func (*PeerInfoManager) PeerMaxHeight

func (p *PeerInfoManager) PeerMaxHeight() int64

PeerMaxHeight returns max block height of all connected peers.

func (*PeerInfoManager) Refresh

func (p *PeerInfoManager) Refresh(peer *types.Peer)

Refresh refreshes peer info

type TimeCache

type TimeCache struct {
	Q *list.List
	M map[string]time.Time
	// contains filtered or unexported fields
}

TimeCache data struct

func NewTimeCache

func NewTimeCache(ctx context.Context, span time.Duration) *TimeCache

NewTimeCache new time cache obj.

func (*TimeCache) Add

func (tc *TimeCache) Add(s string, lifetime time.Duration)

Add add key

func (*TimeCache) Has

func (tc *TimeCache) Has(s string) bool

Has check key

Jump to

Keyboard shortcuts

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