utils

package
v0.22.1 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2020 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4UdpMaxPayload = 1472 // MTU 1500 - 20 IPv4 header - 8 udp header
	IPv6UdpMaxPayload = 1452 // MTU 1500 - 40 IPv6 header - 8 udp header
)

Variables

This section is empty.

Functions

func GenerateCertificate added in v0.21.0

func GenerateCertificate(dnsName string) (cert tls.Certificate, err error)

GenerateCertificate generates a ecdsa certificate with given dnsName. This should only use in test.

func GetIPFromAddr added in v0.15.0

func GetIPFromAddr(addr net.Addr) (ip net.IP)

GetIPFromAddr returns net.IP from net.Addr. Will return nil if no ip address can be parsed.

func GetMsgBuf

func GetMsgBuf(size int) []byte

func GetMsgBufFor

func GetMsgBufFor(m *dns.Msg) ([]byte, error)

func GetMsgKey added in v0.17.1

func GetMsgKey(m *dns.Msg) (string, error)

GetMsgKey unpacks m and set its id to 0.

func GetTimer

func GetTimer(t time.Duration) *time.Timer

func LoadCertPool added in v0.21.0

func LoadCertPool(certs []string) (*x509.CertPool, error)

LoadCertPool reads and loads certificates in certs.

func ParseAddr added in v0.15.0

func ParseAddr(addr string) (protocol, host string)

ParseAddr splits addr to protocol and host.

func ReadMsgFromTCP

func ReadMsgFromTCP(c io.Reader) (m *dns.Msg, n int, err error)

ReadMsgFromTCP reads msg from a tcp connection. n represents how many bytes are read from c.

func ReadMsgFromUDP

func ReadMsgFromUDP(c io.Reader, bufSize int) (m *dns.Msg, n int, err error)

func ReadUDPMsgFrom

func ReadUDPMsgFrom(c net.PacketConn, bufSize int) (m *dns.Msg, from net.Addr, n int, err error)

func ReleaseMsgBuf

func ReleaseMsgBuf(buf []byte)

func ReleaseTimer

func ReleaseTimer(timer *time.Timer)

func RemoveComment added in v0.21.0

func RemoveComment(s, symbol string) string

RemoveComment removes comment after "symbol".

func ResetAndDrainTimer

func ResetAndDrainTimer(timer *time.Timer, d time.Duration)

func SplitLine added in v0.21.0

func SplitLine(s string) []string

SplitLine extracts words from s.

func TryAddPort added in v0.15.0

func TryAddPort(host string, port uint16) string

TryAddPort add port to host if host does not has an port suffix.

func WriteMsgToTCP

func WriteMsgToTCP(c io.Writer, m *dns.Msg) (n int, err error)

WriteMsgToTCP writes m to c. n represents how many bytes are wrote to c. This includes 2 bytes tcp header.

func WriteMsgToUDP

func WriteMsgToUDP(c io.Writer, m *dns.Msg) (n int, err error)

func WriteRawMsgToTCP

func WriteRawMsgToTCP(c io.Writer, b []byte) (n int, err error)

WriteRawMsgToTCP writes b to c. n represents how many bytes are wrote to c. This includes 2 bytes tcp header.

func WriteRawMsgToUDP

func WriteRawMsgToUDP(c io.Writer, b []byte) (n int, err error)

func WriteUDPMsgTo

func WriteUDPMsgTo(m *dns.Msg, c net.PacketConn, to net.Addr) (n int, err error)

Types

type Allocator

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

func NewAllocator

func NewAllocator() *Allocator

NewAllocator initiates a []byte allocator for dns.Msg less than 65536 bytes, the waste(memory fragmentation) of space allocation is guaranteed to be no more than 50%.

func (*Allocator) Get

func (alloc *Allocator) Get(size int) []byte

Get a []byte from pool with most appropriate cap

func (*Allocator) Put

func (alloc *Allocator) Put(buf []byte)

Put returns a []byte to pool for future use, which the cap must be exactly 2^n

type ExchangeSingleFlightGroup added in v0.21.0

type ExchangeSingleFlightGroup struct {
	singleflight.Group
}

func (*ExchangeSingleFlightGroup) Exchange added in v0.21.0

func (g *ExchangeSingleFlightGroup) Exchange(ctx context.Context, q *dns.Msg, exchange exchangeFunc) (r *dns.Msg, err error)

type LoadOnceCache

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

func NewCache

func NewCache() *LoadOnceCache

func (*LoadOnceCache) Load

func (c *LoadOnceCache) Load(key string) (interface{}, bool)

func (*LoadOnceCache) LoadFromCacheOrRawDisk

func (c *LoadOnceCache) LoadFromCacheOrRawDisk(file string) (interface{}, []byte, error)

func (*LoadOnceCache) Put

func (c *LoadOnceCache) Put(key string, data interface{}, ttl time.Duration)

func (*LoadOnceCache) Remove

func (c *LoadOnceCache) Remove(key string)

type NetAddr added in v0.17.1

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

NetAddr implements net.Addr interface.

func NewNetAddr added in v0.17.1

func NewNetAddr(str string, network string) *NetAddr

func (*NetAddr) Network added in v0.17.1

func (n *NetAddr) Network() string

func (*NetAddr) String added in v0.17.1

func (n *NetAddr) String() string

Jump to

Keyboard shortcuts

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