new method of cleaning lists, hopefully much faster
This commit is contained in:
parent
ff9cc1349f
commit
7349960421
@ -27,7 +27,7 @@ func cleanBadDomains(domains []string) []string {
|
|||||||
total = len(domains)
|
total = len(domains)
|
||||||
list = []string{}
|
list = []string{}
|
||||||
for _, blocklistItem := range domains {
|
for _, blocklistItem := range domains {
|
||||||
if len([]rune(blocklistItem)) > 255 {
|
if len([]rune(blocklistItem)) > 250 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
list = append(list, blocklistItem)
|
list = append(list, blocklistItem)
|
||||||
@ -37,26 +37,20 @@ func cleanBadDomains(domains []string) []string {
|
|||||||
|
|
||||||
// remove allow-listed matches
|
// remove allow-listed matches
|
||||||
total = len(domains)
|
total = len(domains)
|
||||||
list = []string{}
|
|
||||||
for _, blocklistItem := range domains {
|
|
||||||
var match bool
|
|
||||||
|
|
||||||
for _, allowlistItem := range config.Config.AllowLists {
|
for _, allowedItem := range config.Config.AllowLists {
|
||||||
r, err := regexp.Compile(allowlistItem)
|
for k, v := range domains {
|
||||||
|
r, err := regexp.Compile(allowedItem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERROR] Allow list item (%s) is not valid regex: %v\n", allowlistItem, err)
|
log.Printf("[ERROR] Allow list item (%s) is not valid regex: %v\n", allowedItem, err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if r.MatchString(blocklistItem) {
|
if r.MatchString(v) {
|
||||||
match = true
|
domains = removeStringFromSlice(domains, k)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !match {
|
|
||||||
list = append(list, blocklistItem)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
domains = list
|
|
||||||
log.Printf("[INFO] Allowed hosts removed: %d\n", total-len(domains))
|
log.Printf("[INFO] Allowed hosts removed: %d\n", total-len(domains))
|
||||||
|
|
||||||
log.Printf("[INFO] Total domains in list at end: %d.\n", len(domains))
|
log.Printf("[INFO] Total domains in list at end: %d.\n", len(domains))
|
||||||
|
@ -160,7 +160,7 @@ func initialize() {
|
|||||||
log.Printf("[DEBUG] configuration value set: EXPIRE = %v\n", config.Config.ZoneConfig.Expire)
|
log.Printf("[DEBUG] configuration value set: EXPIRE = %v\n", config.Config.ZoneConfig.Expire)
|
||||||
log.Printf("[DEBUG] configuration value set: MINIMUM = %v\n", config.Config.ZoneConfig.Minimum)
|
log.Printf("[DEBUG] configuration value set: MINIMUM = %v\n", config.Config.ZoneConfig.Minimum)
|
||||||
log.Printf("[DEBUG] configuration value set: NS1 = %v\n", ns1)
|
log.Printf("[DEBUG] configuration value set: NS1 = %v\n", ns1)
|
||||||
log.Printf("[DEBUG] configuration value set: NS1 = %v\n", ns2)
|
log.Printf("[DEBUG] configuration value set: NS2 = %v\n", ns2)
|
||||||
log.Printf("[DEBUG] configuration value set: CONFIG_FILE = %v\n", config.ConfigFileLocation)
|
log.Printf("[DEBUG] configuration value set: CONFIG_FILE = %v\n", config.ConfigFileLocation)
|
||||||
|
|
||||||
// read config file
|
// read config file
|
||||||
|
@ -9,3 +9,8 @@ func timeTrack(start time.Time, name string) {
|
|||||||
elapsed := time.Since(start)
|
elapsed := time.Since(start)
|
||||||
log.Printf("[TRACE] Function %s took %s\n", name, elapsed)
|
log.Printf("[TRACE] Function %s took %s\n", name, elapsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeStringFromSlice(s []string, i int) []string {
|
||||||
|
s[i] = s[len(s)-1]
|
||||||
|
return s[:len(s)-1]
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user