Documentation ¶
Index ¶
- Constants
- Variables
- func CreateWireMessage(q client.Question, disableEDNS0 bool, udpSize uint16, do bool) *dns.Msg
- func ErrorResponse(correlationId uuid.UUID, connId uuid.UUID, nameServerIp client.Address, ...) client.Response
- func FormatWithPort(ip client.Address, port uint16) string
- func MessageResponse(correlationId uuid.UUID, connId uuid.UUID, nameServerIp client.Address, ...) client.Response
- func SetTCPKeepalive(msgToSend *dns.Msg, keepAlive time.Duration)
- func UnsolicitedResponse(connId uuid.UUID, responseAddr string, responseMsg *dns.Msg, tcp bool) client.Response
- type ConnectionReusingClient
- type MessageIdGenerator
- type RateLimitingClient
Constants ¶
const ( // DefaultResponseChannelBuffer is the buffer size for response channels that chain clients together. DefaultResponseChannelBuffer = 100 DefaultDNSPort = 53 DefaultJitterInMs = 200 )
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 ¶
var ErrUnkownKey = fmt.Errorf("unkown key")
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 ErrorResponse ¶
func MessageResponse ¶
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 NewReusingClient ¶
func NewReusingClient(udpClient client.DNSClientDecorator, tcpClient client.DNSClientDecorator) *ConnectionReusingClient
func (*ConnectionReusingClient) ResponseChan ¶
func (c *ConnectionReusingClient) ResponseChan() <-chan client.Response
func (*ConnectionReusingClient) Start ¶
func (c *ConnectionReusingClient) Start(ctx context.Context) *ConnectionReusingClient
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 (*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) ResponseChan ¶
func (c *RateLimitingClient) ResponseChan() <-chan client.Response
func (*RateLimitingClient) Start ¶
func (c *RateLimitingClient) Start(ctx context.Context) *RateLimitingClient