-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.go
85 lines (64 loc) · 1.43 KB
/
setup.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package block
import (
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/coredns/caddy"
"sync"
"time"
)
var doOnce sync.Once
var super_api = false
var gDbPath = TEST_PREFIX + "/state/dns/dns.db"
func init() { plugin.Register("block", setup) }
func setup(c *caddy.Controller) error {
superapi_enabled := false
c.Next()
if c.NextArg() {
arg := c.Val()
if arg == "enable_superapi" {
superapi_enabled = true
} else {
return plugin.Error("block", c.ArgErr())
}
}
block := New()
block.superapi_enabled = superapi_enabled
c.OnStartup(func() error {
block.setupDB(gDbPath)
doOnce.Do(func() {
//Multiple server instances could be running, but the plugin only needs
//one instance to download and refresh the list
go func() {
//spr is enabled
if block.superapi_enabled {
block.loadSPRConfig()
}
if block.superapi_enabled {
block.runAPI()
}
retries := 3
for retries > 0 {
block.download()
time.Sleep(time.Second * 10)
if !block.ShouldRetryRefresh() {
break
}
retries--
time.Sleep(time.Minute * 5)
}
}()
go func() { block.refresh() }()
go func() { block.refreshTags() }()
})
return nil
})
c.OnShutdown(func() error {
close(block.stop)
return nil
})
dnsserver.GetConfig(c).AddPlugin(func(next plugin.Handler) plugin.Handler {
block.Next = next
return block
})
return nil
}