internal

package
v0.0.0-...-bcd5820 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultResponseChannelBuffer is the buffer size for response channels that chain clients together.
	DefaultResponseChannelBuffer = 100
	DefaultDNSPort               = 53
	DefaultJitterInMs            = 200
)
View Source
const (
	// DefaultBurstSize specifies the burst size for the token bucket rate limiter.
	// Even a small burst size suffices to make the performance much better in certain cases
	DefaultBurstSize = 5
)

Variables

View Source
var ErrUnkownKey = fmt.Errorf("unkown key")
View Source
var NewId = func() uint16 {
	var output uint16
	err := binary.Read(rand.Reader, binary.BigEndian, &output)
	if err != nil {
		panic("generating random id failed: " + err.Error())
	}

	return output
}

NewId generates a random id. Can be overwritten for unit testing purposes

Functions

func CreateWireMessage

func CreateWireMessage(q client.Question, disableEDNS0 bool, udpSize uint16, do bool) *dns.Msg

func ErrorResponse

func ErrorResponse(correlationId uuid.UUID, connId uuid.UUID,
	nameServerIp client.Address,
	responseAddr string,
	rtt time.Duration,
	tcp bool,
	err error) client.Response

func FormatWithPort

func FormatWithPort(ip client.Address, port uint16) string

func MessageResponse

func MessageResponse(correlationId uuid.UUID,
	connId uuid.UUID,
	nameServerIp client.Address,
	responseAddr string,
	responseMsg *dns.Msg,
	rtt time.Duration,
	tcp bool) client.Response

func SetTCPKeepalive

func SetTCPKeepalive(msgToSend *dns.Msg, keepAlive time.Duration)

func UnsolicitedResponse

func UnsolicitedResponse(
	connId uuid.UUID,
	responseAddr string,
	responseMsg *dns.Msg,
	tcp bool) client.Response

UnsolicitedResponse creates a response for an unsolicited or late message. Unsolicited messages are messages that cannot be correlated to a request, either because the request has already timed out, because the data was never requested in the first place, because the server set the wrong dns id in the response header or because the request has already been answered (duplicated response)

Types

type ConnectionReusingClient

type ConnectionReusingClient struct {
	UDPClient client.DNSClientDecorator
	TCPClient client.DNSClientDecorator
	// contains filtered or unexported fields
}

ConnectionReusingClient does a fan-out by sending UDP requests to a udp.Client and tcp requests to a tcp.Client. It fans-in the responses and exposes them via ResponseChan()

func (*ConnectionReusingClient) Enqueue

func (c *ConnectionReusingClient) Enqueue(correlationId uuid.UUID, q client.Question, ip client.Address, sendOpts client.SendOpts)

func (*ConnectionReusingClient) ResponseChan

func (c *ConnectionReusingClient) ResponseChan() <-chan client.Response

func (*ConnectionReusingClient) Start

type MessageIdGenerator

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

MessageIdGenerator generates 16-bit message ids. It is stateful, to ensure that no duplicates are inflight. A cooldown period ensures that ids are not reused for a certain time, in order to minimize the probability of faulty correlations.

func NewIdGen

func NewIdGen() *MessageIdGenerator

NewIdGen creates a new MessageIdGenerator

func (*MessageIdGenerator) GetFreeMessageID

func (gen *MessageIdGenerator) GetFreeMessageID() uint16

GetFreeMessageID generates a messageId that guaranteed to have no collisions with other IDs generated by this method UNLESS they have been released GetFreeMessageID never returns 0.

func (*MessageIdGenerator) InflightIDs

func (gen *MessageIdGenerator) InflightIDs() []uint16

InflightIDs returns a list of all message IDs that are currently in use.

func (*MessageIdGenerator) ReleaseMessageID

func (gen *MessageIdGenerator) ReleaseMessageID(msgID uint16) bool

ReleaseMessageID releases an id acquired by GetMessageId so that it might be reused Returns true if an entry was released, false if the msgID was not present in the map.

type RateLimitingClient

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

RateLimitingClient ensures that the total number of concurrent requests as well as the concurrent requests per server are limited.

func NewClient

func NewClient(innerClient client.DNSClientDecorator,
	maxQueriesPerSecondPerIP int64,
	maxInflightPerIP int64,
	rateLimitTimeout time.Duration,
	log zerolog.Logger) *RateLimitingClient

func (*RateLimitingClient) Enqueue

func (c *RateLimitingClient) Enqueue(correlationId uuid.UUID, q client.Question, ip client.Address, sendOpts client.SendOpts)

func (*RateLimitingClient) ResponseChan

func (c *RateLimitingClient) ResponseChan() <-chan client.Response

func (*RateLimitingClient) Start

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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