connection_limits

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2018 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Limiter manages the automated client connection limits.

func NewLimiter

func NewLimiter() *Limiter

NewLimiter returns a new connection limit handler. The handler is functional, but disabled; it can be enabled via `ApplyConfig`.

func (*Limiter) AddClient

func (cl *Limiter) AddClient(addr net.IP, force bool) error

AddClient adds a client to our population if possible. If we can't, throws an error instead. 'force' is used to add already-existing clients (i.e. ones that are already on the network).

func (*Limiter) ApplyConfig

func (cl *Limiter) ApplyConfig(config LimiterConfig) error

ApplyConfig atomically applies a config update to a connection limit handler

func (*Limiter) RemoveClient

func (cl *Limiter) RemoveClient(addr net.IP)

RemoveClient removes the given address from our population

type LimiterConfig

type LimiterConfig struct {
	Enabled        bool
	CidrLenIPv4    int `yaml:"cidr-len-ipv4"`
	CidrLenIPv6    int `yaml:"cidr-len-ipv6"`
	ConnsPerSubnet int `yaml:"connections-per-subnet"`
	IPsPerSubnet   int `yaml:"ips-per-subnet"` // legacy name for ConnsPerSubnet
	Exempted       []string
}

LimiterConfig controls the automated connection limits.

type ThrottleDetails

type ThrottleDetails struct {
	Start       time.Time
	ClientCount int
}

ThrottleDetails holds the connection-throttling details for a subnet/IP.

type Throttler

type Throttler struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Throttler manages automated client connection throttling.

func NewThrottler

func NewThrottler() *Throttler

NewThrottler returns a new client connection throttler. The throttler is functional, but disabled; it can be enabled via `ApplyConfig`.

func (*Throttler) AddClient

func (ct *Throttler) AddClient(addr net.IP) error

AddClient introduces a new client connection if possible. If we can't, throws an error instead.

func (*Throttler) ApplyConfig

func (ct *Throttler) ApplyConfig(config ThrottlerConfig) error

ApplyConfig atomically applies a config update to a throttler

func (*Throttler) BanDuration

func (ct *Throttler) BanDuration() time.Duration

func (*Throttler) BanMessage

func (ct *Throttler) BanMessage() string

func (*Throttler) ResetFor

func (ct *Throttler) ResetFor(addr net.IP)

ResetFor removes any existing count for the given address.

type ThrottlerConfig

type ThrottlerConfig struct {
	Enabled            bool
	CidrLenIPv4        int           `yaml:"cidr-len-ipv4"`
	CidrLenIPv6        int           `yaml:"cidr-len-ipv6"`
	ConnectionsPerCidr int           `yaml:"max-connections"`
	DurationString     string        `yaml:"duration"`
	Duration           time.Duration `yaml:"duration-time"`
	BanDurationString  string        `yaml:"ban-duration"`
	BanDuration        time.Duration
	BanMessage         string `yaml:"ban-message"`
	Exempted           []string
}

ThrottlerConfig controls the automated connection throttling.

Jump to

Keyboard shortcuts

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