connmgr

package module
v0.3.23 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: MIT Imports: 9 Imported by: 0

README

go-libp2p-connmgr

Coverage Status Travis CI

A package to help manage connections in go-libp2p

Table of Contents

Install

make install

Examples

// TODO:

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Whyrusleeping

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicConnMgr added in v0.3.3

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(low, hi int, grace time.Duration) *BasicConnMgr

NewConnManager creates a new BasicConnMgr with the provided params:

  • lo and hi are watermarks governing the number of connections that'll be maintained. When the peer count exceeds the 'high watermark', as many peers will be pruned (and their connections terminated) until 'low watermark' peers remain.
  • grace is the amount of time a newly opened connection is given before it becomes subject to pruning.

func (*BasicConnMgr) GetInfo added in v0.3.3

func (cm *BasicConnMgr) GetInfo() CMInfo

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

func (*BasicConnMgr) GetTagInfo added in v0.3.3

func (cm *BasicConnMgr) GetTagInfo(p peer.ID) *ifconnmgr.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) Notifee added in v0.3.3

func (cm *BasicConnMgr) Notifee() inet.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) TagPeer added in v0.3.3

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 added in v0.3.3

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.

func (*BasicConnMgr) UntagPeer added in v0.3.3

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

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

type CMInfo added in v0.3.3

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.

Jump to

Keyboard shortcuts

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