reqratelimit

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_SOCKET_SHARE_OF_SHARED_WINDOW = 0.50
	REQUEST_ID_LOG_FIELD_NAME         = "reqID"
)

Variables

This section is empty.

Functions

func NewSharedRateLimitingWindow

func NewSharedRateLimitingWindow(params WindowParameters) *sharedRateLimitingWindow

Types

type IWindow

type IWindow interface {
	AllowRequest(rInfo WindowRequestInfo, logger zerolog.Logger) (ok bool)
}

type Window

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

A Window contains a fixed number of request slots (say N). Rate limiting is performed by informing it about all received requests using the AllowRequest method. The window records the last N requests, even the ones that have not been accepted. See the body of the AllowRequest method for details about the algorithm.

func NewWindow

func NewWindow(params WindowParameters) *Window

func (*Window) AllowRequest

func (window *Window) AllowRequest(rInfo WindowRequestInfo, logger zerolog.Logger) (ok bool)

TODO: treat many HTTP/1.1 connections from same IP as suspicious AllowRequest returns false if the request should be rate limited.

func (*Window) SetIpLevelWindow

func (w *Window) SetIpLevelWindow(window IWindow)

type WindowParameters

type WindowParameters struct {
	Duration     time.Duration
	RequestCount int
}

type WindowRequestInfo

type WindowRequestInfo struct {
	Id                string
	Method            string
	CreationTime      time.Time
	RemoteAddrAndPort netaddr.RemoteAddrWithPort
	RemoteIpAddr      netaddr.RemoteIpAddr
	SentBytes         int
}

Jump to

Keyboard shortcuts

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