acceptorwrapper

package
v3.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithWrappers

func WithWrappers(
	a acceptor.Acceptor,
	wrappers ...Wrapper,
) acceptor.Acceptor

WithWrappers walks through wrappers calling Wrapper

Types

type BaseWrapper

type BaseWrapper struct {
	acceptor.Acceptor
	// contains filtered or unexported fields
}

BaseWrapper implements Wrapper by saving the acceptor as an attribute. Conns from acceptor.GetConnChan are processed by wrapConn and forwarded to its own connChan. Any new wrapper can inherit from BaseWrapper and just implement wrapConn.

func NewBaseWrapper

func NewBaseWrapper(wrapConn func(acceptor.PlayerConn) acceptor.PlayerConn) BaseWrapper

NewBaseWrapper returns an instance of BaseWrapper.

func (*BaseWrapper) GetConnChan

func (b *BaseWrapper) GetConnChan() chan acceptor.PlayerConn

GetConnChan returns the wrapper conn chan

func (*BaseWrapper) ListenAndServe

func (b *BaseWrapper) ListenAndServe()

ListenAndServe starts a goroutine that wraps acceptor's conn and calls acceptor's listenAndServe

type RateLimiter

type RateLimiter struct {
	acceptor.PlayerConn
	// contains filtered or unexported fields
}

RateLimiter wraps net.Conn by applying rate limiting and return empty if exceeded. It uses the leaky bucket algorithm (https://en.wikipedia.org/wiki/Leaky_bucket). Here, "limit" is the number of requests it accepts during an "interval" duration. After making a request, a slot is occupied and only freed after "interval" duration. If a new request comes when no slots are available, the buffer from Read is droped and ignored by pitaya. On the client side, this will yield a timeout error and the client must be prepared to handle it.

func NewRateLimiter

func NewRateLimiter(
	reporters []metrics.Reporter,
	conn acceptor.PlayerConn,
	limit int,
	interval time.Duration,
	forceDisable bool,
) *RateLimiter

NewRateLimiter returns an initialized *RateLimiting

func (*RateLimiter) GetNextMessage

func (r *RateLimiter) GetNextMessage() (msg []byte, err error)

GetNextMessage gets the next message in the connection

type RateLimitingWrapper

type RateLimitingWrapper struct {
	BaseWrapper
}

RateLimitingWrapper rate limits for each connection received

func NewRateLimitingWrapper

func NewRateLimitingWrapper(reporters []metrics.Reporter, c config.RateLimitingConfig) *RateLimitingWrapper

NewRateLimitingWrapper returns an instance of *RateLimitingWrapper

func (*RateLimitingWrapper) Wrap

Wrap saves acceptor as an attribute

type Wrapper

type Wrapper interface {
	Wrap(acceptor.Acceptor) acceptor.Acceptor
}

Wrapper has a method that receives an acceptor and the struct that implements must encapsulate it. The main goal is to create a middleware for packets of net.Conn from acceptor.GetConnChan before giving it to serviceHandler.

Jump to

Keyboard shortcuts

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