connlimiter

package
v0.0.0-...-b6e3791 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package connlimiter describes a limiter of the number of active stream-connections.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Stop is the point at which the limiter stops accepting new connections.
	// Once the number of active connections reaches this limit, new connections
	// wait for the number to decrease to or below Resume.
	//
	// Stop must be greater than zero and greater than or equal to Resume.
	Stop uint64

	// Resume is the point at which the limiter starts accepting new connections
	// again.
	//
	// Resume must be greater than zero and less than or equal to Stop.
	Resume uint64
}

Config is the configuration structure for the stream-connection limiter.

type Limiter

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

Limiter is the stream-connection limiter.

func New

func New(c *Config) (l *Limiter, err error)

New returns a new *Limiter.

func (*Limiter) Limit

func (l *Limiter) Limit(lsnr net.Listener, srvInfo *dnsserver.ServerInfo) (limited net.Listener)

Limit wraps lsnr to control the number of active connections. srvInfo is used for logging and metrics.

type ListenConfig

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

ListenConfig is a netext.ListenConfig that uses a *Limiter to limit the number of active stream-connections.

func NewListenConfig

func NewListenConfig(c netext.ListenConfig, l *Limiter) (limited *ListenConfig)

NewListenConfig returns a new netext.ListenConfig that uses l to limit the number of active stream-connections.

func (*ListenConfig) Listen

func (c *ListenConfig) Listen(
	ctx context.Context,
	network string,
	address string,
) (l net.Listener, err error)

Listen implements the netext.ListenConfig interface for *ListenConfig. Listen returns a net.Listener wrapped by c's limiter. ctx must contain a dnsserver.ServerInfo.

func (*ListenConfig) ListenPacket

func (c *ListenConfig) ListenPacket(
	ctx context.Context,
	network string,
	address string,
) (conn net.PacketConn, err error)

ListenPacket implements the netext.ListenConfig interface for *ListenConfig.

Jump to

Keyboard shortcuts

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