exchanger

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2016 License: Apache-2.0 Imports: 6 Imported by: 7

Documentation

Overview

Package exchanger provides DNS exchanger decorators and other utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decorator

type Decorator func(Exchanger) Exchanger

A Decorator adds a layer of behaviour to a given Exchanger.

var IgnoreErrTruncated Decorator = func(ex Exchanger) Exchanger {
	return Func(func(m *dns.Msg, a string) (r *dns.Msg, rtt time.Duration, err error) {
		r, rtt, err = ex.Exchange(m, a)
		if err == dns.ErrTruncated {

			err = nil
		}
		return
	})
}

IgnoreErrTruncated is a Decorator which causes dns.ErrTruncated to be ignored

func ErrorLogging

func ErrorLogging(l *log.Logger) Decorator

ErrorLogging returns a Decorator which logs an Exchanger's errors to the given logger.

func Instrumentation

func Instrumentation(total, success, failure logging.Counter) Decorator

Instrumentation returns a Decorator which instruments an Exchanger with the given counters.

type Exchanger

type Exchanger interface {
	// Exchange performs an synchronous query. It sends the message m to the address
	// contained in addr (host:port) and waits for a reply.
	Exchange(m *dns.Msg, addr string) (r *dns.Msg, rtt time.Duration, err error)
}

Exchanger is an interface capturing a dns.Client Exchange method.

func Decorate

func Decorate(ex Exchanger, ds ...Decorator) Exchanger

Decorate decorates an Exchanger with the given Decorators.

type ForwardError added in v0.4.0

type ForwardError struct {
	Addrs []string
	Proto string
}

A ForwardError is returned by Forwarders when they can't forward.

func (ForwardError) Error added in v0.4.0

func (e ForwardError) Error() string

Error implements the error interface.

type Forwarder added in v0.4.0

type Forwarder func(*dns.Msg, string) (*dns.Msg, error)

A Forwarder is a DNS message forwarder that transparently proxies messages to DNS servers.

func NewForwarder added in v0.4.0

func NewForwarder(addrs []string, exs map[string]Exchanger) Forwarder

NewForwarder returns a new Forwarder for the given addrs with the given Exchangers map which maps network protocols to Exchangers.

Every message will be exchanged with each address until no error is returned. If no addresses or no matching protocol exchanger exist, a *ForwardError will be returned.

func (Forwarder) Forward added in v0.4.0

func (f Forwarder) Forward(m *dns.Msg, proto string) (*dns.Msg, error)

Forward is an utility method that calls f itself.

type Func

type Func func(*dns.Msg, string) (*dns.Msg, time.Duration, error)

Func is a function type that implements the Exchanger interface.

func (Func) Exchange

func (f Func) Exchange(m *dns.Msg, addr string) (*dns.Msg, time.Duration, error)

Exchange implements the Exchanger interface.

Jump to

Keyboard shortcuts

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