* move "dnsServer" to "config"
This commit is contained in:
parent
001b4b981f
commit
af21a5f17b
|
@ -70,6 +70,7 @@ type configuration struct {
|
||||||
versionCheckJSON []byte
|
versionCheckJSON []byte
|
||||||
versionCheckLastTime time.Time
|
versionCheckLastTime time.Time
|
||||||
|
|
||||||
|
dnsServer *dnsforward.Server
|
||||||
dhcpServer dhcpd.Server
|
dhcpServer dhcpd.Server
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
httpsServer HTTPSServer
|
httpsServer HTTPSServer
|
||||||
|
|
|
@ -172,7 +172,7 @@ func handleQueryLogDisable(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
|
func handleQueryLog(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
data := dnsServer.GetQueryLog()
|
data := config.dnsServer.GetQueryLog()
|
||||||
|
|
||||||
jsonVal, err := json.Marshal(data)
|
jsonVal, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -189,7 +189,7 @@ func handleQueryLog(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
func handleStatsTop(w http.ResponseWriter, r *http.Request) {
|
func handleStatsTop(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
s := dnsServer.GetStatsTop()
|
s := config.dnsServer.GetStatsTop()
|
||||||
|
|
||||||
// use manual json marshalling because we want maps to be sorted by value
|
// use manual json marshalling because we want maps to be sorted by value
|
||||||
statsJSON := bytes.Buffer{}
|
statsJSON := bytes.Buffer{}
|
||||||
|
@ -236,7 +236,7 @@ func handleStatsTop(w http.ResponseWriter, r *http.Request) {
|
||||||
// handleStatsReset resets the stats caches
|
// handleStatsReset resets the stats caches
|
||||||
func handleStatsReset(w http.ResponseWriter, r *http.Request) {
|
func handleStatsReset(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
dnsServer.PurgeStats()
|
config.dnsServer.PurgeStats()
|
||||||
_, err := fmt.Fprintf(w, "OK\n")
|
_, err := fmt.Fprintf(w, "OK\n")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusInternalServerError, "Couldn't write body: %s", err)
|
httpError(w, http.StatusInternalServerError, "Couldn't write body: %s", err)
|
||||||
|
@ -246,7 +246,7 @@ func handleStatsReset(w http.ResponseWriter, r *http.Request) {
|
||||||
// handleStats returns aggregated stats data for the 24 hours
|
// handleStats returns aggregated stats data for the 24 hours
|
||||||
func handleStats(w http.ResponseWriter, r *http.Request) {
|
func handleStats(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Tracef("%s %v", r.Method, r.URL)
|
log.Tracef("%s %v", r.Method, r.URL)
|
||||||
summed := dnsServer.GetAggregatedStats()
|
summed := config.dnsServer.GetAggregatedStats()
|
||||||
|
|
||||||
statsJSON, err := json.Marshal(summed)
|
statsJSON, err := json.Marshal(summed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -293,7 +293,7 @@ func handleStatsHistory(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := dnsServer.GetStatsHistory(timeUnit, startTime, endTime)
|
data, err := config.dnsServer.GetStatsHistory(timeUnit, startTime, endTime)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, http.StatusBadRequest, "Cannot get stats history: %s", err)
|
httpError(w, http.StatusBadRequest, "Cannot get stats history: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -709,7 +709,7 @@ func handleFilteringRemoveURL(w http.ResponseWriter, r *http.Request) {
|
||||||
// Stop DNS server:
|
// Stop DNS server:
|
||||||
// we close urlfilter object which in turn closes file descriptors to filter files.
|
// we close urlfilter object which in turn closes file descriptors to filter files.
|
||||||
// Otherwise, Windows won't allow us to remove the file which is being currently used.
|
// Otherwise, Windows won't allow us to remove the file which is being currently used.
|
||||||
_ = dnsServer.Stop()
|
_ = config.dnsServer.Stop()
|
||||||
|
|
||||||
// go through each element and delete if url matches
|
// go through each element and delete if url matches
|
||||||
config.Lock()
|
config.Lock()
|
||||||
|
@ -968,7 +968,7 @@ func handleDOH(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsServer.ServeHTTP(w, r)
|
config.dnsServer.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------
|
// ------------------------
|
||||||
|
|
16
home/dns.go
16
home/dns.go
|
@ -17,8 +17,6 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dnsServer *dnsforward.Server
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
rdnsTimeout = 3 * time.Second // max time to wait for rDNS response
|
rdnsTimeout = 3 * time.Second // max time to wait for rDNS response
|
||||||
)
|
)
|
||||||
|
@ -43,7 +41,7 @@ func initDNSServer(baseDir string) {
|
||||||
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsServer = dnsforward.NewServer(baseDir)
|
config.dnsServer = dnsforward.NewServer(baseDir)
|
||||||
|
|
||||||
bindhost := config.DNS.BindHost
|
bindhost := config.DNS.BindHost
|
||||||
if config.DNS.BindHost == "0.0.0.0" {
|
if config.DNS.BindHost == "0.0.0.0" {
|
||||||
|
@ -64,7 +62,7 @@ func initDNSServer(baseDir string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func isRunning() bool {
|
func isRunning() bool {
|
||||||
return dnsServer != nil && dnsServer.IsRunning()
|
return config.dnsServer != nil && config.dnsServer.IsRunning()
|
||||||
}
|
}
|
||||||
|
|
||||||
func beginAsyncRDNS(ip string) {
|
func beginAsyncRDNS(ip string) {
|
||||||
|
@ -242,12 +240,12 @@ func startDNSServer() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
}
|
}
|
||||||
err = dnsServer.Start(&newconfig)
|
err = config.dnsServer.Start(&newconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
}
|
}
|
||||||
|
|
||||||
top := dnsServer.GetStatsTop()
|
top := config.dnsServer.GetStatsTop()
|
||||||
for k := range top.Clients {
|
for k := range top.Clients {
|
||||||
beginAsyncRDNS(k)
|
beginAsyncRDNS(k)
|
||||||
}
|
}
|
||||||
|
@ -256,11 +254,11 @@ func startDNSServer() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func reconfigureDNSServer() error {
|
func reconfigureDNSServer() error {
|
||||||
config, err := generateServerConfig()
|
newconfig, err := generateServerConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
}
|
}
|
||||||
err = dnsServer.Reconfigure(&config)
|
err = config.dnsServer.Reconfigure(&newconfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
}
|
}
|
||||||
|
@ -273,7 +271,7 @@ func stopDNSServer() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err := dnsServer.Stop()
|
err := config.dnsServer.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errorx.Decorate(err, "Couldn't stop forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't stop forwarding DNS server")
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,7 @@ func refreshFiltersIfNecessary(force bool) int {
|
||||||
|
|
||||||
stopped := false
|
stopped := false
|
||||||
if updateCount != 0 {
|
if updateCount != 0 {
|
||||||
_ = dnsServer.Stop()
|
_ = config.dnsServer.Stop()
|
||||||
stopped = true
|
stopped = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue