connlimit

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 2 Imported by: 0 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

Overview

Package connlimit provides per-IP connection limiting. It prevents a single client IP from consuming all proxy resources via many concurrent connections (e.g. HTTP flood, slow-read attacks). It is a self-contained leaf (stdlib only, no Culvert coupling) extracted from the flat package main per ADR-0002.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnLimiter

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

ConnLimiter tracks active connections per client IP.

func New

func New() *ConnLimiter

New returns a ConnLimiter with the default per-IP cap, initially disabled.

func (*ConnLimiter) Acquire

func (cl *ConnLimiter) Acquire(ip string) bool

Acquire increments the connection count for ip. Returns false if the limit is exceeded (caller should reject the request).

func (*ConnLimiter) ActiveConns

func (cl *ConnLimiter) ActiveConns(ip string) int64

ActiveConns returns the current connection count for an IP (testing).

func (*ConnLimiter) ActiveIPs

func (cl *ConnLimiter) ActiveIPs() int

ActiveIPs returns the number of IPs currently tracked.

func (*ConnLimiter) Disable

func (cl *ConnLimiter) Disable()

Disable turns off connection limiting.

func (*ConnLimiter) Enable

func (cl *ConnLimiter) Enable(maxPerIP int)

Enable turns on connection limiting.

func (*ConnLimiter) Enabled

func (cl *ConnLimiter) Enabled() bool

Enabled reports whether connection limiting is currently active.

func (*ConnLimiter) MaxPerIP

func (cl *ConnLimiter) MaxPerIP() int

MaxPerIP returns the current per-IP limit.

func (*ConnLimiter) Release

func (cl *ConnLimiter) Release(ip string)

Release decrements the connection count for ip.

Jump to

Keyboard shortcuts

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