coremain

package
v4.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2022 License: GPL-3.0 Imports: 27 Imported by: 0

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 {
	Metrics metrics.Registry
	// 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, lg *zap.Logger, m *Mosdns) *BP

NewBP creates a new BP and initials its logger.

func (*BP) Close

func (p *BP) Close() error

func (*BP) GetMetricsReg

func (p *BP) GetMetricsReg() *metrics.Registry

func (*BP) L

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

func (*BP) M

func (p *BP) M() *Mosdns

func (*BP) S

func (p *BP) S() *zap.SugaredLogger

func (*BP) Tag

func (p *BP) Tag() string

func (*BP) Type

func (p *BP) Type() string

type Config

type Config struct {
	Log           mlog.LogConfig                     `yaml:"log"`
	Include       []string                           `yaml:"include"`
	DataProviders []data_provider.DataProviderConfig `yaml:"data_providers"`
	Plugins       []PluginConfig                     `yaml:"plugins"`
	Servers       []ServerConfig                     `yaml:"servers"`
	API           APIConfig                          `yaml:"api"`
}

type ExecutablePlugin

type ExecutablePlugin interface {
	Plugin
	executable_seq.Executable
}

ExecutablePlugin represents a Plugin that is Executable.

type MatcherPlugin

type MatcherPlugin interface {
	Plugin
	executable_seq.Matcher
}

MatcherPlugin represents a Plugin that is a Matcher.

type Mosdns

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

func (*Mosdns) GetDataManager

func (m *Mosdns) GetDataManager() *data_provider.DataManager

func (*Mosdns) GetExecutables

func (m *Mosdns) GetExecutables() map[string]executable_seq.Executable

func (*Mosdns) GetHTTPAPIMux

func (m *Mosdns) GetHTTPAPIMux() *http.ServeMux

GetHTTPAPIMux returns the api http.ServeMux. The pattern "/plugins/plugin_tag/" has been registered if Plugin implements http.Handler interface. Plugin caller should register path that has "/plugins/plugin_tag/" prefix only.

func (*Mosdns) GetMatchers

func (m *Mosdns) GetMatchers() map[string]executable_seq.Matcher

func (*Mosdns) GetPluginMetricsReg

func (m *Mosdns) GetPluginMetricsReg() *metrics.Registry

func (*Mosdns) GetSafeClose

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

func (*Mosdns) GetServerMetricsReg

func (m *Mosdns) GetServerMetricsReg() *metrics.Registry

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
	io.Closer
}

Plugin represents the basic plugin.

func NewPlugin

func NewPlugin(c *PluginConfig, lg *zap.Logger, 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
	Args map[string]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 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.

	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