mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
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
This commit is contained in:
44
plugin/forward/host.go
Normal file
44
plugin/forward/host.go
Normal file
@@ -0,0 +1,44 @@
|
||||
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
|
||||
Reference in New Issue
Block a user