throttle

package
v0.0.0-...-ca7774d Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ratelimit is a generated GoMock package.

Package ratelimit is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Monitor

func Monitor(lim *Limiter, stats stats.Stats, interval time.Duration)

Monitor the number of active queries and record it in the stats as a percentage of the maximum allowed.

Types

type Handler

type Handler struct {
	Next plugin.Handler
	// contains filtered or unexported fields
}

Handler is a plugin.Handler that limits how many queries are currently being processed. It should be the first handler in the chain, and must be used with the associated Reader.

Handler does not provide an absolute guarantee, because each query is marked as "completed" just _before_ its goroutine terminates.

func NewHandler

func NewHandler(lim *Limiter) *Handler

NewHandler initializes a new concurrency-limiting Handler.

func (*Handler) Attach

func (h *Handler) Attach(s *dns.Server)

Attach connects this handler to a Server's message processing path. This method must be called before the server starts.

func (*Handler) DecorateReader

func (h *Handler) DecorateReader(inner dns.Reader) dns.Reader

DecorateReader is a dns.DecorateReader.

func (*Handler) MsgAcceptFunc

func (h *Handler) MsgAcceptFunc(dh dns.Header) dns.MsgAcceptAction

MsgAcceptFunc is a dns.MsgAcceptFunc.

func (*Handler) MsgInvalid

func (h *Handler) MsgInvalid([]byte, error)

MsgInvalid is a dns.MsgInvalidFunc.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the handler's name.

func (*Handler) ServeDNS

func (h *Handler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

type Limiter

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

Limiter is a wrapped Semaphore that exposes a counter.

func NewLimiter

func NewLimiter(maxWorkers int) (*Limiter, error)

NewLimiter initializes a new concurrency-limiting Limiter.

func (*Limiter) Count

func (l *Limiter) Count() int64

Count returns the number of currently active queries. Only for monitoring.

type MockHandler

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

MockHandler is a mock of Handler interface.

func NewMockHandler

func NewMockHandler(ctrl *gomock.Controller) *MockHandler

NewMockHandler creates a new mock instance.

func (*MockHandler) EXPECT

func (m *MockHandler) EXPECT() *MockHandlerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockHandler) Name

func (m *MockHandler) Name() string

Name mocks base method.

func (*MockHandler) ServeDNS

func (m *MockHandler) ServeDNS(arg0 context.Context, arg1 dns.ResponseWriter, arg2 *dns.Msg) (int, error)

ServeDNS mocks base method.

type MockHandlerMockRecorder

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

MockHandlerMockRecorder is the mock recorder for MockHandler.

func (*MockHandlerMockRecorder) Name

func (mr *MockHandlerMockRecorder) Name() *gomock.Call

Name indicates an expected call of Name.

func (*MockHandlerMockRecorder) ServeDNS

func (mr *MockHandlerMockRecorder) ServeDNS(arg0, arg1, arg2 interface{}) *gomock.Call

ServeDNS indicates an expected call of ServeDNS.

type MockPacketConnReader

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

MockPacketConnReader is a mock of PacketConnReader interface.

func NewMockPacketConnReader

func NewMockPacketConnReader(ctrl *gomock.Controller) *MockPacketConnReader

NewMockPacketConnReader creates a new mock instance.

func (*MockPacketConnReader) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockPacketConnReader) ReadPacketConn

func (m *MockPacketConnReader) ReadPacketConn(arg0 net.PacketConn, arg1 time.Duration) ([]byte, net.Addr, error)

ReadPacketConn mocks base method.

func (*MockPacketConnReader) ReadTCP

func (m *MockPacketConnReader) ReadTCP(arg0 net.Conn, arg1 time.Duration) ([]byte, error)

ReadTCP mocks base method.

func (*MockPacketConnReader) ReadUDP

func (m *MockPacketConnReader) ReadUDP(arg0 *net.UDPConn, arg1 time.Duration) ([]byte, *dns.SessionUDP, error)

ReadUDP mocks base method.

type MockPacketConnReaderMockRecorder

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

MockPacketConnReaderMockRecorder is the mock recorder for MockPacketConnReader.

func (*MockPacketConnReaderMockRecorder) ReadPacketConn

func (mr *MockPacketConnReaderMockRecorder) ReadPacketConn(arg0, arg1 interface{}) *gomock.Call

ReadPacketConn indicates an expected call of ReadPacketConn.

func (*MockPacketConnReaderMockRecorder) ReadTCP

func (mr *MockPacketConnReaderMockRecorder) ReadTCP(arg0, arg1 interface{}) *gomock.Call

ReadTCP indicates an expected call of ReadTCP.

func (*MockPacketConnReaderMockRecorder) ReadUDP

func (mr *MockPacketConnReaderMockRecorder) ReadUDP(arg0, arg1 interface{}) *gomock.Call

ReadUDP indicates an expected call of ReadUDP.

type Reader

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

Reader is a dns.Reader that blocks when the concurrency exceeds some threshold.

func (*Reader) ReadPacketConn

func (r *Reader) ReadPacketConn(conn net.PacketConn, timeout time.Duration) ([]byte, net.Addr, error)

ReadPacketConn implements dns.PacketConnReader.

func (*Reader) ReadTCP

func (r *Reader) ReadTCP(conn net.Conn, timeout time.Duration) ([]byte, error)

ReadTCP implements dns.Reader.

func (*Reader) ReadUDP

func (r *Reader) ReadUDP(conn *net.UDPConn, timeout time.Duration) ([]byte, *dns.SessionUDP, error)

ReadUDP implements dns.Reader.

Jump to

Keyboard shortcuts

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