- config:

- unused configurations are disabled to avoid wasting resources
pull/1/head
bloved 2021-01-14 15:38:46 +01:00
parent 15ec9f49ac
commit cfabc60645
2 changed files with 28 additions and 8 deletions

View File

@ -69,7 +69,7 @@ func init() {
MyDNS.Addr = zabovString
MyDNS.Net = ZabovType
ZabovConfigs = map[string]ZabovConfig{}
ZabovConfigs = map[string]*ZabovConfig{}
ZabovIPGroups = []ZabovIPGroup{}
ZabovTimetables = map[string]*ZabovTimetable{}
ZabovIPAliases = map[string]string{}
@ -92,10 +92,12 @@ func init() {
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
ZabovConfigs[name] = conf
ZabovConfigs[name] = &conf
ZabovCreateKDB(name)
}
ZabovConfigs["default"].references++
timetables := MyConf["timetables"].(map[string]interface{})
for name, v := range timetables {
@ -113,17 +115,19 @@ func init() {
timetable.cfgout = "default"
}
_, ok := ZabovConfigs[timetable.cfgin]
refConfig, ok := ZabovConfigs[timetable.cfgin]
if !ok {
log.Println("timetable: inexistent cfgin:", timetable.cfgin)
os.Exit(1)
}
_, ok = ZabovConfigs[timetable.cfgout]
refConfig.references++
refConfig, ok = ZabovConfigs[timetable.cfgout]
if !ok {
log.Println("timetable: inexistent cfgout:", timetable.cfgout)
os.Exit(1)
}
refConfig.references++
tables := timetableRaw["tables"].([]interface{})
@ -185,6 +189,15 @@ func init() {
}
groupStruct.cfg = groupMap["cfg"].(string)
groupStruct.timetable = groupMap["timetable"].(string)
if len(groupStruct.cfg) > 0 {
refConfig, ok := ZabovConfigs[groupStruct.cfg]
if !ok {
log.Println("ipgroups: inexistent cfg:", groupStruct.cfg)
os.Exit(1)
} else {
refConfig.references++
}
}
fmt.Println("cfg:", groupStruct.cfg)
fmt.Println("timetable:", groupStruct.timetable)
_, ok := ZabovTimetables[groupStruct.timetable]
@ -201,9 +214,8 @@ func init() {
if localresponder["responder"] != nil {
ZabovLocalResponder = localresponder["responder"].(string)
if len(ZabovLocalResponder) > 0 {
local := ZabovConfig{}
local.ZabovDNSArray = []string{ZabovLocalResponder}
ZabovConfigs["__localresponder__"] = local
local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1}
ZabovConfigs["__localresponder__"] = &local
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
}
}
@ -211,6 +223,13 @@ func init() {
ZabovLocalDomain = localresponder["localdomain"].(string)
}
}
for name, conf := range ZabovConfigs {
if conf.references == 0 {
log.Println("WARNING: disabling unused configuration:", name)
delete(ZabovConfigs, name)
}
}
//fmt.Println("ZabovConfigs:", ZabovConfigs)
//fmt.Println("ZabovTimetables:", ZabovTimetables)
//fmt.Println("ZabovIPAliases:", ZabovIPAliases)

View File

@ -32,10 +32,11 @@ type ZabovConfig struct {
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
references int // contains references to this config; if zero, config shall be removed
}
// ZabovConfigs contains all Zabov configs
var ZabovConfigs map[string]ZabovConfig
var ZabovConfigs map[string]*ZabovConfig
// ZabovIPGroup contains Zabov groups of IPs
type ZabovIPGroup struct {