connmgr

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 12 Imported by: 0

README

go-libp2p-connmgr

This is a modified version of libp2p/go-libp2p-conmgr

Modifications:

  • Provide context when constructing BasicConnMgr
  • Use wait groups to synchronize goroutines and prevent leaks
  • Switch logging to uber/zap

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultResolution = 1 * time.Minute

DefaultResolution is the default resolution of the decay tracker.

View Source
var SilencePeriod = 10 * time.Second

SilencePeriod does something seems to allow us to silence periodic runs

Functions

func NewDecayer added in v1.2.0

func NewDecayer(cfg *DecayerCfg, mgr *BasicConnMgr) (*decayer, error)

NewDecayer creates a new decaying tag registry.

Types

type BasicConnManagerConfig added in v1.2.0

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

BasicConnManagerConfig is the configuration struct for the basic connection manager.

type BasicConnMgr

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

BasicConnMgr is a ConnManager that trims connections whenever the count exceeds the high watermark. New connections are given a grace period before they're subject to trimming. Trims are automatically run on demand, only if the time from the previous trim is higher than 10 seconds. Furthermore, trims can be explicitly requested through the public interface of this struct (see TrimOpenConns).

See configuration parameters in NewConnManager.

func NewConnManager

func NewConnManager(ctx context.Context, logger *zap.Logger, low, hi int, grace time.Duration, opts ...Option) *BasicConnMgr

func (*BasicConnMgr) Close

func (cm *BasicConnMgr) Close() error

Close is here to satisfy the interface of ConnectionManager previously in the libp2p version this called a cancel func

func (*BasicConnMgr) GetInfo

func (cm *BasicConnMgr) GetInfo() CMInfo

GetInfo returns the configuration and status data for this connection manager.

func (*BasicConnMgr) GetTagInfo

func (cm *BasicConnMgr) GetTagInfo(p peer.ID) *connmgr.TagInfo

GetTagInfo is called to fetch the tag information associated with a given peer, nil is returned if p refers to an unknown peer.

func (*BasicConnMgr) IsProtected added in v1.2.0

func (cm *BasicConnMgr) IsProtected(id peer.ID, tag string) (protected bool)

func (*BasicConnMgr) Notifee

func (cm *BasicConnMgr) Notifee() network.Notifiee

Notifee returns a sink through which Notifiers can inform the BasicConnMgr when events occur. Currently, the notifee only reacts upon connection events {Connected, Disconnected}.

func (*BasicConnMgr) Protect

func (cm *BasicConnMgr) Protect(id peer.ID, tag string)

Protect can be used to mark a peer as protected from connection closing

func (BasicConnMgr) RegisterDecayingTag added in v1.2.0

func (d BasicConnMgr) RegisterDecayingTag(name string, interval time.Duration, decayFn connmgr.DecayFn, bumpFn connmgr.BumpFn) (connmgr.DecayingTag, error)

func (*BasicConnMgr) TagPeer

func (cm *BasicConnMgr) TagPeer(p peer.ID, tag string, val int)

TagPeer is called to associate a string and integer with a given peer.

func (*BasicConnMgr) TrimOpenConns

func (cm *BasicConnMgr) TrimOpenConns(ctx context.Context)

TrimOpenConns closes the connections of as many peers as needed to make the peer count equal the low watermark. Peers are sorted in ascending order based on their total value, pruning those peers with the lowest scores first, as long as they are not within their grace period.

This function blocks until a trim is completed. If a trim is underway, a new one won't be started, and instead it'll wait until that one is completed before returning.

func (*BasicConnMgr) Unprotect

func (cm *BasicConnMgr) Unprotect(id peer.ID, tag string) (protected bool)

Unprotect removes protection status from a peer

func (*BasicConnMgr) UntagPeer

func (cm *BasicConnMgr) UntagPeer(p peer.ID, tag string)

UntagPeer is called to disassociate a string and integer from a given peer.

func (*BasicConnMgr) UpsertTag

func (cm *BasicConnMgr) UpsertTag(p peer.ID, tag string, upsert func(int) int)

UpsertTag is called to insert/update a peer tag

type CMInfo

type CMInfo struct {
	// The low watermark, as described in NewConnManager.
	LowWater int

	// The high watermark, as described in NewConnManager.
	HighWater int

	// The timestamp when the last trim was triggered.
	LastTrim time.Time

	// The configured grace period, as described in NewConnManager.
	GracePeriod time.Duration

	// The current connection count.
	ConnCount int
}

CMInfo holds the configuration for BasicConnMgr, as well as status data.

type DecayerCfg added in v1.2.0

type DecayerCfg struct {
	Resolution time.Duration
	Clock      clock.Clock
}

DecayerCfg is the configuration object for the Decayer.

func (*DecayerCfg) WithDefaults added in v1.2.0

func (cfg *DecayerCfg) WithDefaults() *DecayerCfg

WithDefaults writes the default values on this DecayerConfig instance, and returns itself for chainability.

cfg := (&DecayerCfg{}).WithDefaults()
cfg.Resolution = 30 * time.Second
t := NewDecayer(cfg, cm)

type Option added in v1.2.0

type Option func(*BasicConnManagerConfig) error

Option represents an option for the basic connection manager.

func DecayerConfig added in v1.2.0

func DecayerConfig(opts *DecayerCfg) Option

DecayerConfig applies a configuration for the decayer.

Jump to

Keyboard shortcuts

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