rbl: parallelize IP checks against blacklists using goroutines
This commit is contained in:
parent
0176c3803d
commit
56e6494a75
1 changed files with 15 additions and 6 deletions
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.happydns.org/happyDeliver/internal/api"
|
"git.happydns.org/happyDeliver/internal/api"
|
||||||
|
|
@ -155,18 +156,26 @@ func (r *DNSListChecker) CheckEmail(email *EmailMessage) *DNSListResults {
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
|
||||||
// CheckIP checks a single IP address against all configured lists
|
// CheckIP checks a single IP address against all configured lists in parallel
|
||||||
func (r *DNSListChecker) CheckIP(ip string) ([]api.BlacklistCheck, int, error) {
|
func (r *DNSListChecker) CheckIP(ip string) ([]api.BlacklistCheck, int, error) {
|
||||||
if !r.isPublicIP(ip) {
|
if !r.isPublicIP(ip) {
|
||||||
return nil, 0, fmt.Errorf("invalid or non-public IP address: %s", ip)
|
return nil, 0, fmt.Errorf("invalid or non-public IP address: %s", ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
var checks []api.BlacklistCheck
|
checks := make([]api.BlacklistCheck, len(r.Lists))
|
||||||
listedCount := 0
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
for _, list := range r.Lists {
|
for i, list := range r.Lists {
|
||||||
check := r.checkIP(ip, list)
|
wg.Add(1)
|
||||||
checks = append(checks, check)
|
go func(i int, list string) {
|
||||||
|
defer wg.Done()
|
||||||
|
checks[i] = r.checkIP(ip, list)
|
||||||
|
}(i, list)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
listedCount := 0
|
||||||
|
for _, check := range checks {
|
||||||
if check.Listed {
|
if check.Listed {
|
||||||
listedCount++
|
listedCount++
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue