dispatcher

package
v1.4.0-beta3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// MaxUDPSize max udp packet size
	MaxUDPSize = 1480
)

Variables

View Source
var (
	// ErrUpstreamsFailed all upstreams are failed or not respond in time.
	ErrUpstreamsFailed = errors.New("all upstreams failed or not respond in time")
)

Functions

func GenConfig

func GenConfig(p string) error

GenConfig generates a template config to path p.

func SetLoggerLevel added in v1.4.0

func SetLoggerLevel(level logrus.Level)

Types

type BasicServerConfig

type BasicServerConfig struct {
	Addr     string `yaml:"addr"`
	Protocol string `yaml:"protocol"`
	Socks5   string `yaml:"socks5"`

	TCP struct {
		IdleTimeout uint `yaml:"idle_timeout"`
	} `yaml:"tcp"`

	DoT struct {
		ServerName  string `yaml:"server_name"`
		IdleTimeout uint   `yaml:"idle_timeout"`
	} `yaml:"dot"`

	DoH struct {
		URL string `yaml:"url"`
	} `yaml:"doh"`

	// for test and experts only, we add `omitempty`
	InsecureSkipVerify bool `yaml:"insecure_skip_verify,omitempty"`

	Deduplicate          bool `yaml:"deduplicate"`
	MaxConcurrentQueries int  `yaml:"max_concurrent_queries"`

	EDNS0 struct {
		ClientSubnet string `yaml:"client_subnet"`
		OverwriteECS bool   `yaml:"overwrite_ecs"`
	} `yaml:"edns0"`
	Policies struct {
		DenyUnhandlableTypes bool   `yaml:"deny_unhandlable_types"`
		Domain               string `yaml:"domain"`
		DenyErrorRcode       bool   `yaml:"deny_error_rcode"`
		CheckCNAME           bool   `yaml:"check_cname"`
		DenyEmptyIPReply     bool   `yaml:"deny_empty_ip_reply"`
		IP                   string `yaml:"ip"`
	}
}

BasicServerConfig is a basic config for a upstream dns server.

type Config

type Config struct {
	Dispatcher struct {
		Bind  []string `yaml:"bind"`
		Cache struct {
			Size int `yaml:"size"`
		} `yaml:"cache"`
		MinTTL uint32 `yaml:"min_ttl"`
	} `yaml:"dispatcher"`

	Upstream map[string]*BasicServerConfig `yaml:"upstream"`

	CA struct {
		Path []string `yaml:"path"`
	} `yaml:"ca"`
}

Config is config

func LoadConfig

func LoadConfig(p string) (*Config, error)

LoadConfig loads a yaml config from path p.

type Dispatcher

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

Dispatcher represents a dns query dispatcher

func InitDispatcher

func InitDispatcher(conf *Config) (*Dispatcher, error)

InitDispatcher inits a dispatcher from configuration

func (*Dispatcher) ServeDNS

func (d *Dispatcher) ServeDNS(ctx context.Context, q *dns.Msg) (r *dns.Msg, err error)

ServeDNS sends q to upstreams and return first valid result. Note: q will be unsafe to modify even after ServeDNS is returned. (Some goroutine may still be running even after ServeDNS is returned)

func (*Dispatcher) StartServer added in v1.3.1

func (d *Dispatcher) StartServer() error

StartServer starts mos-chinadns. Will always return a non-nil err.

type Upstream

type Upstream interface {
	Exchange(ctx context.Context, q *dns.Msg) (r *dns.Msg, err error)
}

Upstream represents a dns upstream

func NewUpstream

func NewUpstream(sc *BasicServerConfig, rootCAs *x509.CertPool) (Upstream, error)

NewUpstream inits a upstream instance base on the config. rootCAs will be used in dot/doh upstream in tls server verification.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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