Help us shape the future of Go! Take the 2026 Go Developer Survey

proxy

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2018 License: Unlicense Imports: 17 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	UDPListenAddr *net.UDPAddr // if nil, then it does not listen for UDP
	TCPListenAddr *net.TCPAddr // if nil, then it does not listen for TCP

	TLSListenAddr *net.TCPAddr // if nil, then it does not listen for TLS (DoT)
	TLSConfig     *tls.Config  // necessary for listening for TLS

	Ratelimit          int      // max number of requests per second from a given IP (0 to disable)
	RatelimitWhitelist []string // a list of whitelisted client IP addresses

	RefuseAny bool // if true, refuse ANY requests

	CacheEnabled bool // cache status

	Upstreams []upstream.Upstream // list of upstreams
	Handler   Handler             // custom middleware (optional)
}

Config contains all the fields necessary for proxy configuration

type DNSContext

type DNSContext struct {
	Proto       string            // "udp", "tcp", "tls", "https"
	Req         *dns.Msg          // DNS request
	Res         *dns.Msg          // DNS response from an upstream
	Conn        net.Conn          // underlying client connection
	Addr        net.Addr          // client address
	Upstream    upstream.Upstream // upstream that was chosen
	UpstreamIdx int               // upstream index
}

DNSContext represents a DNS request message context

type Handler

type Handler interface {
	// ServeDNS can modify the DNSContext instance in any way
	// and should call next.ServeDNS to continue the execution
	ServeDNS(d *DNSContext, next Handler) error
}

Handler is an optional middleware interface

type Proxy

type Proxy struct {
	sync.RWMutex
	Config
	// contains filtered or unexported fields
}

Proxy combines the proxy server state and configuration

func (*Proxy) ServeDNS

func (p *Proxy) ServeDNS(d *DNSContext, next Handler) error

ServeDNS is a Handler implementation. If there is a custom middleware supplied, *p will be passed to it

func (*Proxy) Start

func (p *Proxy) Start() error

Start initializes the proxy server and starts listening

func (*Proxy) Stop

func (p *Proxy) Stop() error

Stop stops the proxy server including all its listeners

Jump to

Keyboard shortcuts

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