Documentation
¶
Index ¶
- Variables
- func ComposeRequest(msg *dns.Msg, domain string) (data []byte)
- func DecodeRequestHeader(c Command, req []byte) (remaining []byte, userId uint16, err error)
- func EncodeRequestHeader(c Command, userId uint16) []byte
- func EncodeUserId(userId uint16) string
- func StripDomain(data []byte, domain string) (res []byte)
- type Command
- type ErrorResponse
- type LazyMode
- type PacketRequest
- type PacketResponse
- type Request
- type Response
- type Serializer
- func (cl Serializer) DecodeDnsRequest(request []byte) (Request, error)
- func (cl Serializer) DecodeDnsResponse(msg *dns.Msg) (Response, error)
- func (cl Serializer) DecodeDnsResponseWithParams(msg *dns.Msg, downstream enc.Encoder) (Response, error)
- func (cl Serializer) DetectCommandType(data []byte) *Command
- func (cl Serializer) EncodeDnsRequest(req Request) (*dns.Msg, error)
- func (cl Serializer) EncodeDnsRequestWithParams(req Request, qt dnsmessage.Type, upstream enc.Encoder) (*dns.Msg, error)
- func (cl Serializer) EncodeDnsResponse(resp Response, request *dns.Msg) (*dns.Msg, error)
- func (cl Serializer) EncodeDnsResponseWithParams(resp Response, request *dns.Msg, qt dnsmessage.Type, downstream enc.Encoder) (*dns.Msg, error)
- type SetOptionsRequest
- type SetOptionsResponse
- type TestDownstreamEncoderRequest
- type TestDownstreamEncoderResponse
- type TestDownstreamFragmentSizeRequest
- type TestDownstreamFragmentSizeResponse
- type TestUpstreamEncoderRequest
- type TestUpstreamEncoderResponse
- type VersionRequest
- type VersionResponse
Constants ¶
This section is empty.
Variables ¶
var ( // Command 0123456789abcdef are reserved for user IDs CmdLogin = Command{ Code: 'l', } CmdTestMultiQuery = Command{ Code: 'm', } )
var ( BadVersion = errors.New("BADVER") BadLen = errors.New("BADLEN") BadIp = errors.New("BADIP") BadCommand = errors.New("BADCOMMAND") BadCodec = errors.New("BADCODEC") BadFrag = errors.New("BADFRAG") BadUser = errors.New("BADUSER") BadConn = errors.New("BADCONN") BadServerFull = errors.New("VFUL") NoData = errors.New("VOK") VersionOk = errors.New("VACK") VersionNotOk = errors.New("VNAK") LazyModeOk = errors.New("LACK") ErrTimeout = errors.New("TIMEOUT") )
Declare a few of standard error responses
var BadErrors = []error{ BadVersion, BadLen, BadIp, BadCommand, BadCodec, BadFrag, BadUser, BadConn, BadServerFull, NoData, VersionOk, VersionNotOk, LazyModeOk, ErrTimeout, }
var CmdError = Command{ Code: 'e', NewResponse: func() Response { return &ErrorResponse{} }, }
var CmdPacket = Command{ Code: 'c', NeedsUserId: true, NewRequest: func() Request { return &PacketRequest{} }, NewResponse: func() Response { return &PacketResponse{} }, }
var CmdSetOptions = Command{ Code: 'o', NeedsUserId: true, NewRequest: func() Request { return &SetOptionsRequest{} }, NewResponse: func() Response { return &SetOptionsResponse{} }, }
var CmdTestDownstreamEncoder = Command{ Code: 'y', NewRequest: func() Request { return &TestDownstreamEncoderRequest{} }, NewResponse: func() Response { return &TestDownstreamEncoderResponse{} }, }
var CmdTestDownstreamFragmentSize = Command{ Code: 'r', NeedsUserId: true, NewRequest: func() Request { return &TestDownstreamFragmentSizeRequest{} }, NewResponse: func() Response { return &TestDownstreamFragmentSizeResponse{} }, }
var CmdTestUpstreamEncoder = Command{ Code: 'z', NeedsUserId: true, NewRequest: func() Request { return &TestUpstreamEncoderRequest{} }, NewResponse: func() Response { return &TestUpstreamEncoderResponse{} }, }
var CmdVersion = Command{ Code: 'v', NeedsUserId: false, NewRequest: func() Request { return &VersionRequest{} }, NewResponse: func() Response { return &VersionResponse{} }, }
var Commands = []Command{ CmdVersion, CmdLogin, CmdSetOptions, CmdTestDownstreamFragmentSize, CmdTestDownstreamEncoder, CmdTestUpstreamEncoder, CmdTestMultiQuery, CmdPacket, CmdError, }
var Digits = regexp.MustCompile("^[0-9]{3}")
Functions ¶
func ComposeRequest ¶
ComposeRequest will take a DNS message and recompose it back to a complete request, if multiQuery was used
func DecodeRequestHeader ¶
func EncodeRequestHeader ¶
EncodeRequestHeader will prepare a common request header used by all commands
func EncodeUserId ¶
func StripDomain ¶
StripDomain will remove the domain from the end of data string and return the string without this domain. If the string does not end with the domain, it does nothing.
Types ¶
type Command ¶
type Command struct { Code byte NeedsUserId bool // Defines if the command needs user ID in the query sring or not NewRequest func() Request NewResponse func() Response }
func (Command) IsOfType ¶
IsOfType will check if the supplied string starts with the given command type
func (Command) ValidateType ¶
ValidateType will check if the supplied string starts with the given command type and return an error if its not.
type ErrorResponse ¶
type ErrorResponse struct {
Err error
}
func (*ErrorResponse) Command ¶
func (vr *ErrorResponse) Command() Command
type PacketRequest ¶
func (*PacketRequest) Command ¶
func (vr *PacketRequest) Command() Command
type PacketResponse ¶
func (*PacketResponse) Command ¶
func (vr *PacketResponse) Command() Command
type Request ¶
type Request interface { // Command is the command that this request reffers to Command() Command // Encode will encode this requires into a DNS-compatible query, potentially using the encoder specified. Note that // encoding allways happens in the "hostname/domain" format -- e.g. so you can execute a A, CNAME, or a MX query // whith this. Encode(e enc.Encoder) ([]byte, error) // Decode will decode the data from the query into this object Decode(e enc.Encoder, request []byte) error }
Request represents a (serialized) request to a DNS server
type Response ¶
type Response interface { // Command is the command that this request reffers to Command() Command // EncodeResponse will encode this response into a data stream which can be the sent as a DNS response. Encode(e enc.Encoder) ([]byte, error) // DecodeResponse will take a byte (data) stream and create a response object Decode(e enc.Encoder, response []byte) error }
Response it the response from the DNS server
type Serializer ¶
type Serializer struct { Upstream util.UpstreamConfig Downstream util.DownstreamConfig UseEdns0 bool UseMultiQuery bool UseLazyMode bool Domain string }
func (Serializer) DecodeDnsRequest ¶
func (cl Serializer) DecodeDnsRequest(request []byte) (Request, error)
DecodeDnsRequest will take a DNS message and decode it into one of the DNS requests objects
func (Serializer) DecodeDnsResponse ¶
func (cl Serializer) DecodeDnsResponse(msg *dns.Msg) (Response, error)
DecodeDnsResponse will take a DNS message and decode it into one of the DNS response object
func (Serializer) DecodeDnsResponseWithParams ¶
func (cl Serializer) DecodeDnsResponseWithParams(msg *dns.Msg, downstream enc.Encoder) (Response, error)
DecodeDnsResponse will take a DNS message and decode it into one of the DNS response object
func (Serializer) DetectCommandType ¶
func (cl Serializer) DetectCommandType(data []byte) *Command
DetectCommandType will try to detect the type of command from the given data stream. If it cannot be detected, it returns `nil`.
func (Serializer) EncodeDnsRequest ¶
func (cl Serializer) EncodeDnsRequest(req Request) (*dns.Msg, error)
EncodeDnsRequest will take a Request and encode it as a DNS message
func (Serializer) EncodeDnsRequestWithParams ¶
func (cl Serializer) EncodeDnsRequestWithParams(req Request, qt dnsmessage.Type, upstream enc.Encoder) (*dns.Msg, error)
EncodeDnsRequestWithParams will take a Request and encode it as a DNS message using given (overriden) params
func (Serializer) EncodeDnsResponse ¶
EncodeDnsResponse will take a DNS response and create a DNS message
func (Serializer) EncodeDnsResponseWithParams ¶
func (cl Serializer) EncodeDnsResponseWithParams(resp Response, request *dns.Msg, qt dnsmessage.Type, downstream enc.Encoder) (*dns.Msg, error)
EncodeDnsResponse will take a DNS response and create a DNS message
type SetOptionsRequest ¶
type SetOptionsRequest struct { UserId uint16 LazyMode *bool MultiQuery *bool Closed *bool DownstreamEncoder enc.Encoder UpstreamEncoder enc.Encoder DownstreamFragmentSize *uint32 }
func (*SetOptionsRequest) Command ¶
func (vr *SetOptionsRequest) Command() Command
type SetOptionsResponse ¶
type SetOptionsResponse struct {
Err error
}
func (*SetOptionsResponse) Command ¶
func (vr *SetOptionsResponse) Command() Command
type TestDownstreamEncoderRequest ¶
func (*TestDownstreamEncoderRequest) Command ¶
func (vr *TestDownstreamEncoderRequest) Command() Command
type TestDownstreamEncoderResponse ¶
type TestDownstreamEncoderResponse struct { Data []byte // []byte(util.DownloadCodecCheck) Err error }
func (*TestDownstreamEncoderResponse) Command ¶
func (vr *TestDownstreamEncoderResponse) Command() Command
type TestDownstreamFragmentSizeRequest ¶
func (*TestDownstreamFragmentSizeRequest) Command ¶
func (vr *TestDownstreamFragmentSizeRequest) Command() Command
type TestDownstreamFragmentSizeResponse ¶
func (*TestDownstreamFragmentSizeResponse) Command ¶
func (vr *TestDownstreamFragmentSizeResponse) Command() Command
type TestUpstreamEncoderRequest ¶
func (*TestUpstreamEncoderRequest) Command ¶
func (vr *TestUpstreamEncoderRequest) Command() Command
type TestUpstreamEncoderResponse ¶
func (*TestUpstreamEncoderResponse) Command ¶
func (vr *TestUpstreamEncoderResponse) Command() Command
type VersionRequest ¶
type VersionRequest struct {
ClientVersion uint32
}
func (*VersionRequest) Command ¶
func (vr *VersionRequest) Command() Command
type VersionResponse ¶
func (*VersionResponse) Command ¶
func (vr *VersionResponse) Command() Command