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.(*BasicConnMgr) CheckLimit(systemLimit connmgr.GetConnLimiter) error(*BasicConnMgr) Close() error ForceTrim trims connections down to the low watermark ignoring silence period, grace period,
or protected status. It prioritizes closing Unprotected connections. If after closing all
unprotected connections, we still have more than lowWaterMark connections, it'll close
protected connections. GetInfo returns the configuration and status data for this connection manager. GetTagInfo is called to fetch the tag information associated with a given
peer, nil is returned if p refers to an unknown peer.(*BasicConnMgr) IsProtected(id peer.ID, tag string) (protected bool) Notifee returns a sink through which Notifiers can inform the BasicConnMgr when
events occur. Currently, the notifee only reacts upon connection events
{Connected, Disconnected}.(*BasicConnMgr) Protect(id peer.ID, tag string)( BasicConnMgr) RegisterDecayingTag(name string, interval time.Duration, decayFn connmgr.DecayFn, bumpFn connmgr.BumpFn) (connmgr.DecayingTag, error) TagPeer is called to associate a string and integer with a given peer. 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.(*BasicConnMgr) Unprotect(id peer.ID, tag string) (protected bool) UntagPeer is called to disassociate a string and integer from a given peer. UpsertTag is called to insert/update a peer tag
*BasicConnMgr : github.com/libp2p/go-libp2p/core/connmgr.ConnManager
*BasicConnMgr : github.com/libp2p/go-libp2p/core/connmgr.Decayer
*BasicConnMgr : github.com/prometheus/common/expfmt.Closer
*BasicConnMgr : io.Closer
func NewConnManager(low, hi int, opts ...Option) (*BasicConnMgr, error)
func NewDecayer(cfg *DecayerCfg, mgr *BasicConnMgr) (*decayer, error)
CMInfo holds the configuration for BasicConnMgr, as well as status data. The current connection count. The configured grace period, as described in NewConnManager. The high watermark, as described in NewConnManager. The timestamp when the last trim was triggered. The low watermark, as described in NewConnManager.
func (*BasicConnMgr).GetInfo() CMInfo
DecayerCfg is the configuration object for the Decayer.Clockclock.ClockResolutiontime.Duration 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)
func (*DecayerCfg).WithDefaults() *DecayerCfg
func DecayerConfig(opts *DecayerCfg) Option
func NewDecayer(cfg *DecayerCfg, mgr *BasicConnMgr) (*decayer, error)
DecayerConfig applies a configuration for the decayer.
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.
NewDecayer creates a new decaying tag registry.
WithClock sets the internal clock impl
WithGracePeriod sets the grace period.
The grace period is the time a newly opened connection is given before it becomes
subject to pruning.
WithSilencePeriod sets the silence period.
The connection manager will perform a cleanup once per silence period
if the number of connections surpasses the high watermark.
Package-Level Variables (only one)
DefaultResolution is the default resolution of the decay tracker.
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.