coredns/plugin/forward/host.go
Miek Gieben 5b844b5017
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
2018-02-05 22:00:47 +00:00

44 lines
777 B
Go

package forward
import (
"crypto/tls"
"sync"
"time"
"github.com/miekg/dns"
)
type host struct {
addr string
client *dns.Client
tlsConfig *tls.Config
expire time.Duration
fails uint32
sync.RWMutex
checking bool
}
// newHost returns a new host, the fails are set to 1, i.e.
// the first healthcheck must succeed before we use this host.
func newHost(addr string) *host {
return &host{addr: addr, fails: 1, expire: defaultExpire}
}
// setClient sets and configures the dns.Client in host.
func (h *host) SetClient() {
c := new(dns.Client)
c.Net = "udp"
c.ReadTimeout = 2 * time.Second
c.WriteTimeout = 2 * time.Second
if h.tlsConfig != nil {
c.Net = "tcp-tls"
c.TLSConfig = h.tlsConfig
}
h.client = c
}
const defaultExpire = 10 * time.Second