Documentation ¶
Overview ¶
Package limiter implements connection and rate limiters for teleport
Index ¶
Constants ¶
const ( DefaultMaxNumberOfUsers = 100000 DefaultRate = 100000000 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConnectionsLimiter ¶
type ConnectionsLimiter struct { *connlimit.ConnLimiter *sync.Mutex // contains filtered or unexported fields }
ConnectionsLimiter is a network connection limiter and tracker
func NewConnectionsLimiter ¶
func NewConnectionsLimiter(config LimiterConfig) (*ConnectionsLimiter, error)
NewConnectionsLimiter returns new connection limiter, in case if connection limits are not set, they won't be tracked
func (*ConnectionsLimiter) AcquireConnection ¶
func (l *ConnectionsLimiter) AcquireConnection(token string) error
AcquireConnection acquires connection and bumps counter
func (*ConnectionsLimiter) ReleaseConnection ¶
func (l *ConnectionsLimiter) ReleaseConnection(token string)
ReleaseConnection decrements the counter
func (*ConnectionsLimiter) WrapHandle ¶
func (l *ConnectionsLimiter) WrapHandle(h http.Handler)
WrapHandle adds connection limiter to the handle
type Limiter ¶
type Limiter struct { // ConnectionsLimiter limits simultaneous connection *ConnectionsLimiter // contains filtered or unexported fields }
Limiter helps limiting connections and request rates
func NewLimiter ¶
func NewLimiter(config LimiterConfig) (*Limiter, error)
NewLimiter returns new rate and connection limiter
func (*Limiter) RegisterRequest ¶
type LimiterConfig ¶
type LimiterConfig struct { // Rates set ups rate limits Rates []Rate // MaxConnections configures maximum number of connections MaxConnections int64 // MaxNumberOfUsers controls maximum number of simultaneously active users MaxNumberOfUsers int // Clock is an optional parameter, if not set, will use system time Clock timetools.TimeProvider }
LimiterConfig sets up rate limits and configuration limits parameters
func (*LimiterConfig) SetEnv ¶
func (l *LimiterConfig) SetEnv(v string) error
SetEnv reads LimiterConfig from JSON string
type RateLimiter ¶
type RateLimiter struct { *ratelimit.TokenLimiter *sync.Mutex // contains filtered or unexported fields }
RateLimiter controls connection rate, it uses token bucket algo https://en.wikipedia.org/wiki/Token_bucket
func NewRateLimiter ¶
func NewRateLimiter(config LimiterConfig) (*RateLimiter, error)
NewRateLimiter returns new request rate controller
func (*RateLimiter) RegisterRequest ¶
func (l *RateLimiter) RegisterRequest(token string) error
RegisterRequest increases number of requests for the provided token Returns error if there are too many requests with the provided token
func (*RateLimiter) WrapHandle ¶
func (l *RateLimiter) WrapHandle(h http.Handler)
Add rate limiter to the handle