handler

package
v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2021 License: GPL-3.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	PITESExecutable = iota
	PITMatcher
	PITService
)

Variables

This section is empty.

Functions

func DelPlugin

func DelPlugin(tag string)

DelPlugin deletes this plugin. If this plugin is a Service, DelPlugin will call Service.Shutdown(). DelPlugin will panic if Service.Shutdown() returns an err.

func ExecChainNode

func ExecChainNode(ctx context.Context, qCtx *Context, n ExecutableChainNode) error

func GetConfigurablePluginTypes

func GetConfigurablePluginTypes() []string

GetConfigurablePluginTypes returns all plugin types which are configurable. This should only be used in testing or debugging.

func InitAndRegPlugin

func InitAndRegPlugin(c *Config, errIfDup bool) (err error)

InitAndRegPlugin inits and registers this plugin globally. This is a help func of NewPlugin + RegPlugin.

func MustRegPlugin

func MustRegPlugin(p Plugin, errIfDup bool)

MustRegPlugin: see RegPlugin. MustRegPlugin will panic if any err occurred.

func PluginFatalErr

func PluginFatalErr(tag string, msg string)

PluginFatalErr: If a plugin has a fatal err, call this.

func PurgePluginRegister

func PurgePluginRegister()

PurgePluginRegister should only be used in testing.

func RegInitFunc

func RegInitFunc(pluginType string, initFunc NewPluginFunc, argsType NewArgsFunc)

RegInitFunc registers this plugin type. This should only be called in init() from the plugin package. Duplicate plugin types are not allowed.

func RegPlugin

func RegPlugin(p Plugin, errIfDup bool) error

RegPlugin registers Plugin p. If errIfDup is true and Plugin.Tag() is duplicated, an err will be returned. If old plugin is a Service, RegPlugin will call Service.Shutdown(). If this failed, RegPlugin will panic.

func WeakDecode

func WeakDecode(in map[string]interface{}, output interface{}) error

WeakDecode decodes args from config to output.

Types

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) *BP

NewBP creates a new BP and initials its logger.

func (*BP) L

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

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 {
	// 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"`
}

Config represents a plugin config

type Context

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

Context is a query context that pass through plugins A Context will always have a non-nil Q. Context MUST be created by NewContext.

func NewContext

func NewContext(q *dns.Msg, from net.Addr) *Context

NewContext creates a new query Context. q is the query dns msg. It cannot be nil, or NewContext will panic. from is the client net.Addr. It can be nil.

func (*Context) Copy

func (ctx *Context) Copy() *Context

Copy deep copies this Context.

func (*Context) CopyTo

func (ctx *Context) CopyTo(d *Context) *Context

CopyTo deep copies this Context to d.

func (*Context) From

func (ctx *Context) From() net.Addr

From returns the client net.Addr. It might be nil.

func (*Context) Id

func (ctx *Context) Id() uint32

Id returns the Context id. Note: This id is not the dns msg id. It's a unique uint32 growing with the number of query.

func (*Context) InfoField

func (ctx *Context) InfoField() zap.Field

InfoField returns a zap.Field. Just for convenience.

func (*Context) OriginalQuery added in v2.2.1

func (ctx *Context) OriginalQuery() *dns.Msg

OriginalQuery returns the copied original query msg a that created the Context. It always returns a non-nil msg. The returned msg SHOULD NOT be modified.

func (*Context) Q

func (ctx *Context) Q() *dns.Msg

Q returns the query msg. It always returns a non-nil msg.

func (*Context) R

func (ctx *Context) R() *dns.Msg

R returns the response. It might be nil.

func (*Context) SetResponse

func (ctx *Context) SetResponse(r *dns.Msg, status ContextStatus)

SetResponse stores the response r to the context. Note: It just stores the pointer of r. So the caller shouldn't modify or read r after the call.

func (*Context) StartTime

func (ctx *Context) StartTime() time.Time

StartTime returns the time when the Context was created.

func (*Context) Status

func (ctx *Context) Status() ContextStatus

Status returns the context status.

func (*Context) String

func (ctx *Context) String() string

String returns a short summery of its query.

type ContextStatus

type ContextStatus uint8
const (
	ContextStatusWaitingResponse ContextStatus = iota
	ContextStatusResponded
	ContextStatusServerFailed
	ContextStatusDropped
	ContextStatusRejected
)

func (ContextStatus) String

func (status ContextStatus) String() string

type DummyExecutablePlugin

type DummyExecutablePlugin struct {
	*BP
	WantSkip  bool
	WantSleep time.Duration
	WantR     *dns.Msg
	WantErr   error
}

func (*DummyExecutablePlugin) Exec

type DummyMatcherPlugin

type DummyMatcherPlugin struct {
	*BP
	Matched bool
	WantErr error
}

func (*DummyMatcherPlugin) Match

func (d *DummyMatcherPlugin) Match(_ context.Context, _ *Context) (matched bool, err error)

type DummyServicePlugin

type DummyServicePlugin struct {
	*BP
	WantShutdownErr error
}

func (*DummyServicePlugin) Shutdown

func (d *DummyServicePlugin) Shutdown() error

type Executable

type Executable interface {
	Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
}

Executable represents something that is executable.

type ExecutableChainNode

type ExecutableChainNode interface {
	Executable
	LinkedListNode
}

ExecutableChainNode represents a node in a executable chain.

func FirstNode

FirstNode returns the first node of chain of n.

func LastNode added in v2.2.0

LastNode returns the Latest node of chain of n.

func WrapExecutable

func WrapExecutable(e Executable) ExecutableChainNode

WrapExecutable wraps a Executable to a ExecutableChainNode.

type ExecutableNodeWrapper

type ExecutableNodeWrapper struct {
	Executable
	NodeLinker
}

ExecutableNodeWrapper wraps a Executable to a ExecutableChainNode.

type ExecutablePlugin

type ExecutablePlugin interface {
	Plugin
	Executable
}

ExecutablePlugin represents a Plugin that is Executable.

type LinkedListNode

type LinkedListNode interface {
	Previous() ExecutableChainNode
	Next() ExecutableChainNode
	LinkPrevious(n ExecutableChainNode)
	LinkNext(n ExecutableChainNode)
}

type Matcher

type Matcher interface {
	Match(ctx context.Context, qCtx *Context) (matched bool, err error)
}

Matcher represents a matcher that can match a certain patten in Context.

type MatcherPlugin

type MatcherPlugin interface {
	Plugin
	Matcher
}

MatcherPlugin represents a Plugin that is a Matcher.

type NewArgsFunc

type NewArgsFunc func() interface{}

NewArgsFunc 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 NewArgsFunc.

type NodeLinker

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

NodeLinker implements LinkedListNode.

func (*NodeLinker) LinkNext

func (l *NodeLinker) LinkNext(n ExecutableChainNode)

func (*NodeLinker) LinkPrevious

func (l *NodeLinker) LinkPrevious(n ExecutableChainNode)

func (*NodeLinker) Next

func (l *NodeLinker) Next() ExecutableChainNode

func (*NodeLinker) Previous

func (l *NodeLinker) Previous() ExecutableChainNode

type Plugin

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

Plugin represents the basic plugin.

func GetPluginAll

func GetPluginAll() []Plugin

GetPluginAll returns all registered plugins. This should only be used in testing or debugging.

func NewPlugin

func NewPlugin(c *Config) (p Plugin, err error)

NewPlugin creates a registered Plugin from c.

type PluginError

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

func NewPluginError

func NewPluginError(tag string, err error) *PluginError

func (*PluginError) Error

func (e *PluginError) Error() string

func (*PluginError) Is

func (e *PluginError) Is(target error) bool

func (*PluginError) Unwrap

func (e *PluginError) Unwrap() error

type PluginInterfaceType

type PluginInterfaceType uint8

type PluginWrapper

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

PluginWrapper wraps the original plugin to avoid extremely frequently interface conversion. To access the original plugin, use PluginWrapper.GetPlugin() Note: PluginWrapper not implements Executable. It automatically converts Executable to ESExecutable.

func GetPlugin

func GetPlugin(tag string) (p *PluginWrapper, err error)

GetPlugin returns the plugin. If the tag is not registered, an err will be returned. Also see PluginWrapper.

func NewPluginWrapper

func NewPluginWrapper(gp Plugin) *PluginWrapper

func (*PluginWrapper) Exec

func (w *PluginWrapper) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error

func (*PluginWrapper) GetPlugin

func (w *PluginWrapper) GetPlugin() Plugin

func (*PluginWrapper) Is

func (*PluginWrapper) Match

func (w *PluginWrapper) Match(ctx context.Context, qCtx *Context) (matched bool, err error)

func (*PluginWrapper) Shutdown

func (w *PluginWrapper) Shutdown() error

type Service

type Service interface {
	// Shutdown and release resources.
	Shutdown() error
}

Service represents a background service.

type ServicePlugin

type ServicePlugin interface {
	Plugin
	Service
}

ServicePlugin represents a Plugin that is a Service.

Jump to

Keyboard shortcuts

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