Versions in this module Expand all Collapse all v0 v0.0.1 Dec 29, 2025 Changes in this version + const ClassINET + const HeaderLen + const QTypeA + const QTypeAAAA + const UDPMaxLen + func MarshalDomainTo(w io.Writer, domain string) (n int, err error) + func UnmarshalHeader(b []byte, h *Header) error + type AnswerHandler func(domain string, ip netip.Addr) error + type Client struct + func NewClient(proxy proxy.Proxy, config *Config) (*Client, error) + func (c *Client) AddHandler(h AnswerHandler) + func (c *Client) AddRecord(record string) error + func (c *Client) Exchange(reqBytes []byte, clientAddr string, preferTCP bool) ([]byte, error) + func (c *Client) SetServers(domain string, servers []string) + func (c *Client) UpStream(domain string) *UPStream + type Config struct + AlwaysTCP bool + CacheLog bool + CacheSize int + MaxTTL int + MinTTL int + NoAAAA bool + Records []string + Servers []string + Timeout int + type Header struct + ANCOUNT uint16 + ARCOUNT uint16 + Bits uint16 + ID uint16 + NSCOUNT uint16 + QDCOUNT uint16 + func (h *Header) MarshalTo(w io.Writer) (int, error) + func (h *Header) SetAncount(ancount int) + func (h *Header) SetMsgType(qr MsgType) + func (h *Header) SetQdcount(qdcount int) + func (h *Header) SetTC(tc int) + type LruCache struct + func NewLruCache(size int) *LruCache + func (c *LruCache) Get(k string) (v []byte, expired bool) + func (c *LruCache) Set(k string, v []byte, ttl int) + type Message struct + Additional []*RR + Answers []*RR + Authority []*RR + Question *Question + func MakeResponse(domain, ip string, ttl uint32) (*Message, error) + func NewMessage(id uint16, msgType MsgType) *Message + func UnmarshalMessage(b []byte) (*Message, error) + func (m *Message) AddAnswer(rr *RR) error + func (m *Message) Marshal() ([]byte, error) + func (m *Message) MarshalTo(w io.Writer) (n int, err error) + func (m *Message) SetQuestion(q *Question) error + func (m *Message) UnmarshalDomainPointTo(sb *strings.Builder, offset int) error + func (m *Message) UnmarshalDomainTo(sb *strings.Builder, b []byte) (int, error) + func (m *Message) UnmarshalQuestion(b []byte, q *Question) (n int, err error) + func (m *Message) UnmarshalRR(start int, rr *RR) (n int, err error) + type MsgType byte + const QueryMsg + const ResponseMsg + type Question struct + QCLASS uint16 + QNAME string + QTYPE uint16 + func NewQuestion(qtype uint16, domain string) *Question + func (q *Question) MarshalTo(w io.Writer) (n int, err error) + type RR struct + CLASS uint16 + IP netip.Addr + NAME string + RDATA []byte + RDLENGTH uint16 + TTL uint32 + TYPE uint16 + func NewRR() *RR + func (rr *RR) MarshalTo(w io.Writer) (n int, err error) + type Server struct + func NewServer(addr string, p proxy.Proxy, config *Config) (*Server, error) + func (s *Server) ListenAndServeTCP(wg *sync.WaitGroup) + func (s *Server) ListenAndServeUDP(wg *sync.WaitGroup) + func (s *Server) ServePacket(pc net.PacketConn, caddr net.Addr, reqBytes []byte) + func (s *Server) ServeTCP(c net.Conn) + func (s *Server) Start() + type UPStream struct + func NewUPStream(servers []string) *UPStream + func (u *UPStream) Len() int + func (u *UPStream) Server() string + func (u *UPStream) Switch() string + func (u *UPStream) SwitchIf(server string) string