util

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HostnameMaxLen = 253 // including the final period, and the non-printed zero octet for root makes 255
	LabelMaxlen    = 60  // See https://stackoverflow.com/questions/32290167/what-is-the-maximum-length-of-a-dns-name
)
View Source
const MaxCachedChunks = 128

Keep at most 128 acked chunks from the other party

View Source
const TypeSocketAce uint16 = 0xFFA0

Variables

View Source
var (
	ErrTooLong  = errors.New("token too long")
	ErrCaseSwap = errors.New("case swap, no need for any further test")
)
View Source
var (
	QueryTypeNull    = dnsmessage.Type(10)
	QueryTypePrivate = dnsmessage.Type(65000)
	QueryTypeTxt     = dnsmessage.TypeTXT
	QueryTypeSrv     = dnsmessage.TypeSRV
	QueryTypeMx      = dnsmessage.TypeMX
	QueryTypeCname   = dnsmessage.TypeCNAME
	QueryTypeAAAA    = dnsmessage.TypeAAAA
	QueryTypeA       = dnsmessage.TypeA
)

Define different query types which can be used

View Source
var (
	ErrInvalidSequenceNumber = errors.New("invalid chunk sequence")
	ErrStreamBroken          = errors.New("stream broken")
	ErrDeadlineExceeded      = errors.New("deadline exceeded")
)
View Source
var DotRegex = regexp.MustCompile("\\.")
View Source
var (
	// DownloadCodecCheck is the hard coded string available on both client and server which
	// is used to check if the downstream codec works properly or not.
	DownloadCodecCheck = []byte(
		"\000\000\000\000\377\377\377\377\125\125\125\125\252\252\252\252" +
			"\201\143\310\322\307\174\262\027\137\117\316\311\111\055\122\041" +
			"\141\251\161\040\045\263\006\163\346\330\104\060\171\120\127\277")
)

Sorted by priority

Functions

func Dotify

func Dotify(buf []byte) (res []byte)

Dotify will include dots every 57 characters

func GetLongestDataString

func GetLongestDataString(domain string) int

GetLongestDataString returns the longest data string available, when all dots and domain are included in the calculation

func NewSocketAcePrivate

func NewSocketAcePrivate() dns.PrivateRdata

func PrepareHostname

func PrepareHostname(data []byte, domain string) ([]byte, error)

PrepareHostname will finalize hostname -- add dots in the name, if needed. It will verify that the total lenght of the hostname does not exiceed HostnameMaxLen and throw an error it it does.

func TypePriority

func TypePriority(rr dns.RR) uint32

TypePriority calculates the supplied type's priority used for sorting

func Undotify

func Undotify(buf string) string

Undotify will remove the dots from the given string

func UnwrapDnsResponse

func UnwrapDnsResponse(q *dns.Msg, domain string) []byte

UnwrapDnsResponse will decode the DNS message and return the bytes in the response

func WrapDnsResponse

func WrapDnsResponse(msg *dns.Msg, data []byte, queryType dnsmessage.Type, domain string) error

WrapDnsResponse will wrap the given data into the specificed message type. It will call one of the other methods to actually do the wrapping

func WrapDnsResponseA

func WrapDnsResponseA(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseA will wrap the data into a A-type DNS response message

func WrapDnsResponseAAAA

func WrapDnsResponseAAAA(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseAAAA will wrap the data into a AAAA-type DNS response message

func WrapDnsResponseCname

func WrapDnsResponseCname(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseCname will wrap the data into a CNAME-type DNS response message

func WrapDnsResponseMx

func WrapDnsResponseMx(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseMx will wrap the data into a MX-type DNS response message

func WrapDnsResponseNull

func WrapDnsResponseNull(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseNull will wrap the data into a NULL-type DNS response message

func WrapDnsResponsePrivate

func WrapDnsResponsePrivate(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponsePrivate will wrap the data into a PRIVATE-type DNS response message

func WrapDnsResponseSrv

func WrapDnsResponseSrv(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseSrv will wrap the data into a SRV-type DNS response message

func WrapDnsResponseTxt

func WrapDnsResponseTxt(msg *dns.Msg, data []byte, domain string) error

WrapDnsResponseTxt will wrap the data into a TXT-type DNS response message

Types

type DownstreamConfig

type DownstreamConfig struct {
	FragmentSize uint32      // -m max size of downstream fragments (default: autodetect)
	Encoder      enc.Encoder // -O force downstream encoding for -T other than NULL: Base32Encoding, Base64Encoding, Base64uEncoding, Base128Encoding, or (only for TXT:) RawEncoding (default: autodetect)
}

type InQueue

type InQueue struct {
	NextSeqNo uint16 // The id of the next Packet to be written to the queue
	// contains filtered or unexported fields
}

func (*InQueue) Append

func (q *InQueue) Append(val *Packet) error

Try to append the Packet to our byte list. Returns an error if out of order

func (*InQueue) HasData

func (q *InQueue) HasData() bool

HasData returns true if there's any data waiting in the queue to be read

func (*InQueue) Read

func (q *InQueue) Read(p []byte) (n int, err error)

func (*InQueue) SetReadDeadline

func (q *InQueue) SetReadDeadline(t time.Time) error

SetReadDeadline sets the deadline for future Read calls and any currently-blocked Read call. A zero value for t means Read will not time out.

type OutQueue

type OutQueue struct {
	NextSeqNo    uint16       // Next chunk to be put into queue will get this ID
	OnChunkAdded func() error // Callback function when a new chunk is added
	// contains filtered or unexported fields
}

func (*OutQueue) NextChunk

func (q *OutQueue) NextChunk() *Packet

NextChunk will return the first non-acked chunk from the queue. It will return nil if the queue is empty

func (*OutQueue) SetWriteDeadline

func (q *OutQueue) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the deadline for future Write calls and any currently-blocked Write call. Even if write times out, it may return n > 0, indicating that some of the data was successfully written. A zero value for t means Write will not time out.

func (*OutQueue) UpdateAcked

func (q *OutQueue) UpdateAcked(seqNo uint16)

UpdateAcked will add the acked sequence number to the list and remove the chunk from the outboud queue.

func (*OutQueue) Write

func (q *OutQueue) Write(b []byte, mtu uint32) (n int, err error)

Write will create packets out of the given byte stream. Make sure that the writes are as large as possible, otherwise Packet will get quite small.

type Packet

type Packet struct {
	SeqNo uint16 // The sequence number of the chunk.
	Data  []byte // The chunk data
}

Packet represents a part of data exchanged between the client and the server

type QueryTypes

type QueryTypes []dnsmessage.Type

func (QueryTypes) Before

func (qt QueryTypes) Before(q1, q2 dnsmessage.Type) bool

Before returns true if q1 has higher priority than q2

type SocketAcePrivate

type SocketAcePrivate struct {
	Data []byte
}

A crazy new RR type :)

func (*SocketAcePrivate) Copy

func (rd *SocketAcePrivate) Copy(dest dns.PrivateRdata) error

func (*SocketAcePrivate) Len

func (rd *SocketAcePrivate) Len() int

func (*SocketAcePrivate) Pack

func (rd *SocketAcePrivate) Pack(buf []byte) (int, error)

func (*SocketAcePrivate) Parse

func (rd *SocketAcePrivate) Parse(txt []string) error

func (*SocketAcePrivate) String

func (rd *SocketAcePrivate) String() string

func (*SocketAcePrivate) Unpack

func (rd *SocketAcePrivate) Unpack(buf []byte) (int, error)

type UpstreamConfig

type UpstreamConfig struct {
	FragmentSize uint32           // -M max size of upstream hostnames (~100-255, default: 255)
	Encoder      enc.Encoder      // -O force downstream encoding for -T other than NULL: Base32, Base64, Base64u,  Base128, or (only for TXT:) Raw  (default: autodetect)
	QueryType    *dnsmessage.Type // -T force dns type: QueryTypeNull, QueryTypePrivate, QueryTypeTxt, QueryTypeSrv, QueryTypeMx, QueryTypeCname, QueryTypeAAAA, QueryTypeA (default: autodetect)
}

Jump to

Keyboard shortcuts

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