-
-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathdns.go
More file actions
31 lines (26 loc) · 539 Bytes
/
dns.go
File metadata and controls
31 lines (26 loc) · 539 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package dht
import (
"sync"
"time"
"github.com/rs/dnscache"
)
var (
// A cache to prevent wasteful/excessive use of DNS when trying to bootstrap.
dnsResolver *dnscache.Resolver
dnsResolverInit sync.Once
)
func dnsResolverRefresher() {
ticker := time.NewTicker(5 * time.Minute)
defer ticker.Stop()
for {
<-ticker.C
dnsResolver.Refresh(false)
}
}
// https://github.com/anacrolix/dht/issues/43
func initDnsResolver() {
dnsResolverInit.Do(func() {
dnsResolver = &dnscache.Resolver{}
go dnsResolverRefresher()
})
}