dns

package module
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: GPL-2.0 Imports: 24 Imported by: 57

README

sing-dns

DNS client with caching

License

Copyright (C) 2022 by nekohasekai <contact-sagernet@sekai.icu>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

Documentation

Index

Constants

View Source
const DefaultTTL = 600
View Source
const FixedPacketSize = 16384
View Source
const MimeType = "application/dns-message"

Variables

View Source
var (
	ErrNoRawSupport = E.New("no raw query support by current transport")
	ErrNotCached    = E.New("not cached")
)

Functions

func ContextWithDisableCache

func ContextWithDisableCache(ctx context.Context, val bool) context.Context

func ContextWithRewriteTTL added in v0.1.5

func ContextWithRewriteTTL(ctx context.Context, val uint32) context.Context

func DisableCacheFromContext

func DisableCacheFromContext(ctx context.Context) bool

func NewDialerWrapper

func NewDialerWrapper(dialer N.Dialer, client *Client, transport Transport, strategy DomainStrategy, fallbackDelay time.Duration) N.Dialer

func RegisterTransport

func RegisterTransport(schemes []string, constructor TransportConstructor)

func RewriteTTLFromContext added in v0.1.5

func RewriteTTLFromContext(ctx context.Context) (uint32, bool)

Types

type Client

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

func NewClient

func NewClient(options ClientOptions) *Client

func (*Client) ClearCache added in v0.1.9

func (c *Client) ClearCache()

func (*Client) Exchange

func (c *Client) Exchange(ctx context.Context, transport Transport, message *dns.Msg, strategy DomainStrategy) (*dns.Msg, error)

func (*Client) ExchangeCache added in v0.1.5

func (c *Client) ExchangeCache(ctx context.Context, message *dns.Msg) (*dns.Msg, bool)

func (*Client) Lookup

func (c *Client) Lookup(ctx context.Context, transport Transport, domain string, strategy DomainStrategy) ([]netip.Addr, error)

type ClientOptions added in v0.1.5

type ClientOptions struct {
	DisableCache     bool
	DisableExpire    bool
	IndependentCache bool
	Logger           logger.ContextLogger
}

type DialerWrapper

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

func (*DialerWrapper) DialContext

func (d *DialerWrapper) DialContext(ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error)

func (*DialerWrapper) ListenPacket

func (d *DialerWrapper) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error)

func (*DialerWrapper) Upstream

func (d *DialerWrapper) Upstream() any

type DomainStrategy

type DomainStrategy = uint8
const (
	DomainStrategyAsIS DomainStrategy = iota
	DomainStrategyPreferIPv4
	DomainStrategyPreferIPv6
	DomainStrategyUseIPv4
	DomainStrategyUseIPv6
)

type HTTPSTransport

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

func NewHTTPSTransport

func NewHTTPSTransport(name string, dialer N.Dialer, serverURL string) *HTTPSTransport

func (*HTTPSTransport) Close

func (t *HTTPSTransport) Close() error

func (*HTTPSTransport) Exchange

func (t *HTTPSTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*HTTPSTransport) Lookup

func (t *HTTPSTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*HTTPSTransport) Name added in v0.1.5

func (t *HTTPSTransport) Name() string

func (*HTTPSTransport) Raw

func (t *HTTPSTransport) Raw() bool

func (*HTTPSTransport) Reset added in v0.1.9

func (t *HTTPSTransport) Reset()

func (*HTTPSTransport) Start

func (t *HTTPSTransport) Start() error

type LocalTransport

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

func NewLocalTransport

func NewLocalTransport(name string, dialer N.Dialer) *LocalTransport

func (*LocalTransport) Close

func (t *LocalTransport) Close() error

func (*LocalTransport) Exchange

func (t *LocalTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*LocalTransport) Lookup

func (t *LocalTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*LocalTransport) Name added in v0.1.5

func (t *LocalTransport) Name() string

func (*LocalTransport) Raw

func (t *LocalTransport) Raw() bool

func (*LocalTransport) Reset added in v0.1.9

func (t *LocalTransport) Reset()

func (*LocalTransport) Start

func (t *LocalTransport) Start() error

type RCodeError

type RCodeError uint16
const (
	RCodeSuccess        RCodeError = 0 // NoError
	RCodeFormatError    RCodeError = 1 // FormErr
	RCodeServerFailure  RCodeError = 2 // ServFail
	RCodeNameError      RCodeError = 3 // NXDomain
	RCodeNotImplemented RCodeError = 4 // NotImp
	RCodeRefused        RCodeError = 5 // Refused
)

func (RCodeError) Error

func (e RCodeError) Error() string

type RCodeTransport

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

func NewRCodeTransport

func NewRCodeTransport(name string, code string) (*RCodeTransport, error)

func (*RCodeTransport) Close

func (t *RCodeTransport) Close() error

func (*RCodeTransport) Exchange

func (t *RCodeTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*RCodeTransport) Lookup

func (t *RCodeTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*RCodeTransport) Name added in v0.1.5

func (t *RCodeTransport) Name() string

func (*RCodeTransport) Raw

func (t *RCodeTransport) Raw() bool

func (*RCodeTransport) Reset added in v0.1.9

func (t *RCodeTransport) Reset()

func (*RCodeTransport) Start

func (t *RCodeTransport) Start() error

type TCPTransport

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

func NewTCPTransport

func NewTCPTransport(name string, ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr) (*TCPTransport, error)

func (*TCPTransport) Close

func (t *TCPTransport) Close() error

func (*TCPTransport) DialContext

func (t *TCPTransport) DialContext(ctx context.Context) (net.Conn, error)

func (*TCPTransport) Exchange

func (t *TCPTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*TCPTransport) Lookup

func (t *TCPTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*TCPTransport) Name added in v0.1.5

func (t *TCPTransport) Name() string

func (*TCPTransport) Raw

func (t *TCPTransport) Raw() bool

func (*TCPTransport) ReadMessage

func (t *TCPTransport) ReadMessage(conn net.Conn) (*dns.Msg, error)

func (*TCPTransport) Reset added in v0.1.9

func (t *TCPTransport) Reset()

func (*TCPTransport) Start

func (t *TCPTransport) Start() error

func (*TCPTransport) WriteMessage

func (t *TCPTransport) WriteMessage(conn net.Conn, message *dns.Msg) error

type TLSTransport

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

func NewTLSTransport

func NewTLSTransport(name string, ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr) (*TLSTransport, error)

func (*TLSTransport) Close

func (t *TLSTransport) Close() error

func (*TLSTransport) DialContext

func (t *TLSTransport) DialContext(ctx context.Context) (net.Conn, error)

func (*TLSTransport) Exchange

func (t *TLSTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*TLSTransport) Lookup

func (t *TLSTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*TLSTransport) Name added in v0.1.5

func (t *TLSTransport) Name() string

func (*TLSTransport) Raw

func (t *TLSTransport) Raw() bool

func (*TLSTransport) ReadMessage

func (t *TLSTransport) ReadMessage(conn net.Conn) (*dns.Msg, error)

func (*TLSTransport) Reset added in v0.1.9

func (t *TLSTransport) Reset()

func (*TLSTransport) Start

func (t *TLSTransport) Start() error

func (*TLSTransport) WriteMessage

func (t *TLSTransport) WriteMessage(conn net.Conn, message *dns.Msg) error

type Transport

type Transport interface {
	Name() string
	Start() error
	Reset()
	Close() error
	Raw() bool
	Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)
	Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)
}

func CreateHTTPSTransport

func CreateHTTPSTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

func CreateLocalTransport

func CreateLocalTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

func CreateRCodeTransport

func CreateRCodeTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

func CreateTCPTransport

func CreateTCPTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

func CreateTLSTransport

func CreateTLSTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

func CreateTransport

func CreateTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, address string) (Transport, error)

func CreateUDPTransport

func CreateUDPTransport(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

type TransportConstructor

type TransportConstructor = func(name string, ctx context.Context, logger logger.ContextLogger, dialer N.Dialer, link string) (Transport, error)

type UDPTransport

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

func NewUDPTransport

func NewUDPTransport(name string, ctx context.Context, dialer N.Dialer, serverAddr M.Socksaddr) (*UDPTransport, error)

func (*UDPTransport) Close

func (t *UDPTransport) Close() error

func (*UDPTransport) DialContext

func (t *UDPTransport) DialContext(ctx context.Context) (net.Conn, error)

func (*UDPTransport) Exchange

func (t *UDPTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.Msg, error)

func (*UDPTransport) Lookup

func (t *UDPTransport) Lookup(ctx context.Context, domain string, strategy DomainStrategy) ([]netip.Addr, error)

func (*UDPTransport) Name added in v0.1.5

func (t *UDPTransport) Name() string

func (*UDPTransport) Raw

func (t *UDPTransport) Raw() bool

func (*UDPTransport) ReadMessage

func (t *UDPTransport) ReadMessage(conn net.Conn) (*dns.Msg, error)

func (*UDPTransport) Reset added in v0.1.9

func (t *UDPTransport) Reset()

func (*UDPTransport) Start

func (t *UDPTransport) Start() error

func (*UDPTransport) WriteMessage

func (t *UDPTransport) WriteMessage(conn net.Conn, message *dns.Msg) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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