diff options
author | 2018-02-05 22:00:47 +0000 | |
---|---|---|
committer | 2018-02-05 22:00:47 +0000 | |
commit | 5b844b5017f004fffa83157041e8ffd3ac085c92 (patch) | |
tree | cbf86bb06cd42f720037a0e473ce2d1cba4036af /plugin/forward/proxy.go | |
parent | fb1cafe5fa54935361a5cc9a7e3308a738225126 (diff) | |
download | coredns-5b844b5017f004fffa83157041e8ffd3ac085c92.tar.gz coredns-5b844b5017f004fffa83157041e8ffd3ac085c92.tar.zst coredns-5b844b5017f004fffa83157041e8ffd3ac085c92.zip |
plugin/forward: add it (#1447)
* plugin/forward: add it
This moves coredns/forward into CoreDNS. Fixes as a few bugs, adds a
policy option and more tests to the plugin.
Update the documentation, test IPv6 address and add persistent tests.
* Always use random policy when spraying
* include scrub fix here as well
* use correct var name
* Code review
* go vet
* Move logging to metrcs
* Small readme updates
* Fix readme
Diffstat (limited to 'plugin/forward/proxy.go')
-rw-r--r-- | plugin/forward/proxy.go | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/plugin/forward/proxy.go b/plugin/forward/proxy.go new file mode 100644 index 000000000..c89490374 --- /dev/null +++ b/plugin/forward/proxy.go @@ -0,0 +1,77 @@ +package forward + +import ( + "crypto/tls" + "sync" + "time" + + "github.com/miekg/dns" +) + +// Proxy defines an upstream host. +type Proxy struct { + host *host + + transport *transport + + // copied from Forward. + hcInterval time.Duration + forceTCP bool + + stop chan bool + + sync.RWMutex +} + +// NewProxy returns a new proxy. +func NewProxy(addr string) *Proxy { + host := newHost(addr) + + p := &Proxy{ + host: host, + hcInterval: hcDuration, + stop: make(chan bool), + transport: newTransport(host), + } + return p +} + +// SetTLSConfig sets the TLS config in the lower p.host. +func (p *Proxy) SetTLSConfig(cfg *tls.Config) { p.host.tlsConfig = cfg } + +// SetExpire sets the expire duration in the lower p.host. +func (p *Proxy) SetExpire(expire time.Duration) { p.host.expire = expire } + +func (p *Proxy) close() { p.stop <- true } + +// Dial connects to the host in p with the configured transport. +func (p *Proxy) Dial(proto string) (*dns.Conn, error) { return p.transport.Dial(proto) } + +// Yield returns the connection to the pool. +func (p *Proxy) Yield(c *dns.Conn) { p.transport.Yield(c) } + +// Down returns if this proxy is up or down. +func (p *Proxy) Down(maxfails uint32) bool { return p.host.down(maxfails) } + +func (p *Proxy) healthCheck() { + + // stop channel + p.host.SetClient() + + p.host.Check() + tick := time.NewTicker(p.hcInterval) + for { + select { + case <-tick.C: + p.host.Check() + case <-p.stop: + return + } + } +} + +const ( + dialTimeout = 4 * time.Second + timeout = 2 * time.Second + hcDuration = 500 * time.Millisecond +) |