coremain

package
v5.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: GPL-3.0 Imports: 28 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSubCmd

func AddSubCmd(c *cobra.Command)

func DelPluginType

func DelPluginType(typ string)

DelPluginType deletes the init func for this plugin type. It is a noop if pluginType is not registered.

func GetAllPluginTypes

func GetAllPluginTypes() []string

GetAllPluginTypes returns all plugin types which are configurable.

func LoadNewPersetPluginFuncs

func LoadNewPersetPluginFuncs() map[string]NewPersetPluginFunc

func RegNewPersetPluginFunc

func RegNewPersetPluginFunc(tag string, f NewPersetPluginFunc)

func RegNewPluginFunc

func RegNewPluginFunc(typ string, initFunc NewPluginFunc, argsType NewPluginArgsFunc)

RegNewPluginFunc registers the type. If the type has been registered. RegNewPluginFunc will panic.

func Run

func Run() error

func RunMosdns

func RunMosdns(cfg *Config) error

func StartServer

func StartServer(sf *serverFlags) error

Types

type APIConfig

type APIConfig struct {
	HTTP string `yaml:"http"`
}

type BP

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

BP represents a basic plugin, which implements Plugin. It also has an internal logger, for convenience.

func NewBP

func NewBP(tag string, typ string, opts BPOpts) *BP

NewBP creates a new BP and initials its logger.

func (*BP) GetMetricsReg

func (p *BP) GetMetricsReg() prometheus.Registerer

GetMetricsReg return a prometheus.Registerer with a prefix of "mosdns_plugin_${plugin_tag}_]"

func (*BP) L

func (p *BP) L() *zap.Logger

func (*BP) M

func (p *BP) M() *Mosdns

func (*BP) RegAPI

func (p *BP) RegAPI(mux *chi.Mux)

func (*BP) Tag

func (p *BP) Tag() string

func (*BP) Type

func (p *BP) Type() string

type BPOpts

type BPOpts struct {
	Mosdns *Mosdns
	Logger *zap.Logger
}

type BadIPObserverConfig

type BadIPObserverConfig struct {
	Threshold        int    `yaml:"threshold"` // Zero Threshold will disable the bad ip observer.
	Interval         int    `yaml:"interval"`  // (sec) Default is 10.
	TTL              int    `yaml:"ttl"`       // (sec) Default is 600 (10min).
	OnUpdateCallBack string `yaml:"on_update_callback"`
	// IP masks to aggregate an IP range.
	IPv4Mask int `yaml:"ipv4_mask"` // Default is 32.
	IPv6Mask int `yaml:"ipv6_mask"` // Default is 48.
}

BadIPObserverConfig is a copy of ip_observer.BadIPObserverOpts.

func (*BadIPObserverConfig) Init

func (c *BadIPObserverConfig) Init()

type Config

type Config struct {
	Log     mlog.LogConfig `yaml:"log"`
	Include []string       `yaml:"include"`
	Plugins []PluginConfig `yaml:"plugins"`
	API     APIConfig      `yaml:"api"`
}

type Mosdns

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

func NewMosdns

func NewMosdns(cfg *Config) (*Mosdns, error)

func NewTestMosdns

func NewTestMosdns(plugins map[string]Plugin) *Mosdns

func (*Mosdns) GetAPIRouter

func (m *Mosdns) GetAPIRouter() *chi.Mux

func (*Mosdns) GetMetricsReg

func (m *Mosdns) GetMetricsReg() prometheus.Registerer

GetMetricsReg returns a prometheus.Registerer with a prefix of "mosdns_"

func (*Mosdns) GetPlugins

func (m *Mosdns) GetPlugins(tag string) Plugin

func (*Mosdns) GetSafeClose

func (m *Mosdns) GetSafeClose() *safe_close.SafeClose

func (*Mosdns) RegPluginAPI

func (m *Mosdns) RegPluginAPI(tag string, mux *chi.Mux)

type NewPersetPluginFunc

type NewPersetPluginFunc func(bp *BP) (Plugin, error)

type NewPluginArgsFunc

type NewPluginArgsFunc func() interface{}

NewPluginArgsFunc represents a func that creates a new args object.

type NewPluginFunc

type NewPluginFunc func(bp *BP, args interface{}) (p Plugin, err error)

NewPluginFunc represents a func that can init a Plugin. args is the object created by NewPluginArgsFunc.

type Plugin

type Plugin interface {
	Tag() string
	Type() string
}

Plugin represents the basic plugin.

func NewPlugin

func NewPlugin(c *PluginConfig, m *Mosdns) (p Plugin, err error)

NewPlugin initialize a Plugin from c.

type PluginConfig

type PluginConfig struct {
	// Tag, required
	Tag string `yaml:"tag"`

	// Type, required
	Type string `yaml:"type"`

	// Args, might be required by some plugins.
	// The type of Args is depended on RegNewPluginFunc.
	// If it's a map[string]interface{}, it will be converted by mapstruct.
	Args interface{} `yaml:"args"`
}

PluginConfig represents a plugin config

type PluginTypeInfo

type PluginTypeInfo struct {
	NewPlugin NewPluginFunc
	NewArgs   NewPluginArgsFunc
}

func GetPluginType

func GetPluginType(typ string) (PluginTypeInfo, bool)

GetPluginType gets the registered type init func.

type SecurityConfig

type SecurityConfig struct {
	BadIPObserver BadIPObserverConfig `yaml:"bad_ip_observer"`
}

type ServerConfig

type ServerConfig struct {
	Exec      string                  `yaml:"exec"`
	Timeout   uint                    `yaml:"timeout"` // (sec) query timeout.
	Listeners []*ServerListenerConfig `yaml:"listeners"`
}

type ServerListenerConfig

type ServerListenerConfig struct {
	// Protocol: server protocol, can be:
	// "", "udp" -> udp
	// "tcp" -> tcp
	// "dot", "tls" -> dns over tls
	// "doh", "https" -> dns over https (rfc 8844)
	// "http" -> dns over https (rfc 8844) but without tls
	Protocol string `yaml:"protocol"`

	// Addr: server "host:port" addr.
	// Addr cannot be empty.
	Addr string `yaml:"addr"`

	Cert                string `yaml:"cert"`                    // certificate path, used by dot, doh
	Key                 string `yaml:"key"`                     // certificate key path, used by dot, doh
	URLPath             string `yaml:"url_path"`                // used by doh, http. If it's empty, any path will be handled.
	GetUserIPFromHeader string `yaml:"get_user_ip_from_header"` // used by doh, http.
	ProxyProtocol       bool   `yaml:"proxy_protocol"`          // accepting the PROXYProtocol

	IdleTimeout uint `yaml:"idle_timeout"` // (sec) used by tcp, dot, doh as connection idle timeout.
}

Jump to

Keyboard shortcuts

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