backend

package
v0.0.0-...-259ffdc Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2015 License: GPL-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// The text the backend will serve to a successful hello message
	Banner string

	// The protocol version negotiated with the remote end
	ProtocolVersion int
	// contains filtered or unexported fields
}

func New

func New(r io.Reader, w io.Writer, banner string) *Backend

Build a new backend object. The banner is reported to the client upon successful negotiation; the io can be anything.

func (*Backend) Negotiate

func (b *Backend) Negotiate() error

Does initial handshake with peer. Returns nil, or an error Note that the pipebackend protocol documentation states that if negotiation fails, the process should retry, not exit itself.

func (*Backend) Run

func (b *Backend) Run(callback Callback) error

Reads lines in a loop, processing them by executing the provided callback and writing appropriate output in response, sequentially, until we hit an error or our IO hits EOF

type Callback

type Callback func(b *Backend, q *Query) ([]*Response, error)

A callback of this type is executed whenever a query is received. If an error is returned, the responses are ignored and the error text is returned to the backend. Otherwise, the responses are serialised and sent back in order.

type Query

type Query struct {
	ProtocolVersion   int
	QName             string
	QClass            string
	QType             string
	Id                string
	RemoteIpAddress   string
	LocalIpAddress    string
	EdnsSubnetAddress string
}

Represents a query received by the backend. Certain fields may be blank, depending on negotiated protocol version - which is stored in ProtocolVersion

QName, QClass, QType, Id and RemoteIpAddress are present in all versions LocalIpAddress was added in version 2 EdnsSubnetAddress was added in version 3

func (*Query) String

func (q *Query) String() (string, error)

type Response

type Response struct {
	ProtocolVersion int
	ScopeBits       string
	Auth            string
	QName           string
	QClass          string
	QType           string
	TTL             string
	Id              string
	Content         string
}

A response to be sent back in answer to a query. Again, some fields may be blank, depending on protocol version.

QName, QClass, QType, TTL, Id and Content are present in all versions No additions in version 2 ScopeBits and Auth were added in version 3

func (*Response) String

func (r *Response) String() (string, error)

Gives the response in a serialized form suitable for squirting on the wire

Jump to

Keyboard shortcuts

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