* move "controlLock" mutex to "config"
This commit is contained in:
parent
d51f43e27a
commit
2682adca39
|
@ -53,6 +53,7 @@ type configuration struct {
|
|||
disableUpdate bool // If set, don't check for updates
|
||||
appSignalChannel chan os.Signal
|
||||
clients clientsContainer
|
||||
controlLock sync.Mutex
|
||||
|
||||
BindHost string `yaml:"bind_host"` // BindHost is the IP address of the HTTP server to bind to
|
||||
BindPort int `yaml:"bind_port"` // BindPort is the port the HTTP server
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/AdguardTeam/AdGuardHome/dnsforward"
|
||||
|
@ -40,8 +39,6 @@ var client = &http.Client{
|
|||
Transport: transport,
|
||||
}
|
||||
|
||||
var controlLock sync.Mutex
|
||||
|
||||
// ----------------
|
||||
// helper functions
|
||||
// ----------------
|
||||
|
|
|
@ -17,13 +17,13 @@ type accessListJSON struct {
|
|||
func handleAccessList(w http.ResponseWriter, r *http.Request) {
|
||||
log.Tracef("%s %v", r.Method, r.URL)
|
||||
|
||||
controlLock.Lock()
|
||||
config.controlLock.Lock()
|
||||
j := accessListJSON{
|
||||
AllowedClients: config.DNS.AllowedClients,
|
||||
DisallowedClients: config.DNS.DisallowedClients,
|
||||
BlockedHosts: config.DNS.BlockedHosts,
|
||||
}
|
||||
controlLock.Unlock()
|
||||
config.controlLock.Unlock()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(j)
|
||||
|
|
|
@ -73,10 +73,10 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
now := time.Now()
|
||||
if !req.RecheckNow {
|
||||
controlLock.Lock()
|
||||
config.controlLock.Lock()
|
||||
cached := now.Sub(versionCheckLastTime) <= versionCheckPeriod && len(versionCheckJSON) != 0
|
||||
data := versionCheckJSON
|
||||
controlLock.Unlock()
|
||||
config.controlLock.Unlock()
|
||||
|
||||
if cached {
|
||||
log.Tracef("Returning cached data")
|
||||
|
@ -103,10 +103,10 @@ func handleGetVersionJSON(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
controlLock.Lock()
|
||||
config.controlLock.Lock()
|
||||
versionCheckLastTime = now
|
||||
versionCheckJSON = body
|
||||
controlLock.Unlock()
|
||||
config.controlLock.Unlock()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_, err = w.Write(getVersionResp(body))
|
||||
|
|
|
@ -35,8 +35,8 @@ func ensure(method string, handler func(http.ResponseWriter, *http.Request)) fun
|
|||
}
|
||||
|
||||
if method == "POST" || method == "PUT" || method == "DELETE" {
|
||||
controlLock.Lock()
|
||||
defer controlLock.Unlock()
|
||||
config.controlLock.Lock()
|
||||
defer config.controlLock.Unlock()
|
||||
}
|
||||
|
||||
handler(w, r)
|
||||
|
|
Loading…
Reference in New Issue