Documentation ¶
Index ¶
- Variables
- func NewDecayer(cfg *DecayerCfg, mgr *Manager) (*decayer, error)
- type CMInfo
- type DecayerCfg
- type Manager
- func (cm *Manager) Close() error
- func (cm *Manager) Connected(n network.Network, c network.Stream)
- func (cm *Manager) Disconnected(n network.Network, c network.Stream)
- func (cm *Manager) GetInfo() CMInfo
- func (cm *Manager) GetTagInfo(p peer.ID) *connmgr.TagInfo
- func (cm *Manager) HasStream(n network.Network, pid peer.ID) (network.Stream, error)
- func (cm *Manager) IsProtected(id peer.ID, tag string) (protected bool)
- func (cm *Manager) Protect(id peer.ID, tag string)
- func (d Manager) RegisterDecayingTag(name string, interval time.Duration, decayFn connmgr.DecayFn, ...) (connmgr.DecayingTag, error)
- func (cm *Manager) TagPeer(p peer.ID, tag string, val int)
- func (cm *Manager) TrimOpenConns(_ context.Context)
- func (cm *Manager) Unprotect(id peer.ID, tag string) (protected bool)
- func (cm *Manager) UntagPeer(p peer.ID, tag string)
- func (cm *Manager) UpsertTag(p peer.ID, tag string, upsert func(int) int)
- type Option
Constants ¶
This section is empty.
Variables ¶
var DefaultResolution = 1 * time.Minute
DefaultResolution is the default resolution of the decay tracker.
Functions ¶
func NewDecayer ¶
func NewDecayer(cfg *DecayerCfg, mgr *Manager) (*decayer, error)
NewDecayer creates a new decaying tag registry.
Types ¶
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 Manager, as well as status data.
type DecayerCfg ¶
DecayerCfg is the configuration object for the Decayer.
func (*DecayerCfg) WithDefaults ¶
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 Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager 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 ¶
NewConnManager creates a new Manager 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.
func (*Manager) Connected ¶
Connected is called by notifiers to inform that a new connection has been established. The notifee updates the Manager to start tracking the connection. If the new connection count exceeds the high watermark, a trim may be triggered.
func (*Manager) Disconnected ¶
Disconnected is called by notifiers to inform that an existing connection has been closed or terminated. The notifee updates the Manager accordingly to stop tracking the connection, and performs housekeeping.
func (*Manager) GetInfo ¶
GetInfo returns the configuration and status data for this connection manager.
func (*Manager) GetTagInfo ¶
GetTagInfo is called to fetch the tag information associated with a given peer, nil is returned if p refers to an unknown peer.
func (*Manager) IsProtected ¶
func (Manager) RegisterDecayingTag ¶
func (*Manager) TrimOpenConns ¶
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.
type Option ¶
type Option func(*config) error
Option represents an option for the basic connection manager.
func DecayerConfig ¶
func DecayerConfig(opts *DecayerCfg) Option
DecayerConfig applies a configuration for the decayer.
func WithGracePeriod ¶
WithGracePeriod sets the grace period. The grace period is the time a newly opened connection is given before it becomes subject to pruning.
func WithSilencePeriod ¶
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.