Disable retrying of intel fetching

sync.Once cannot be refreshed while executing.
This commit is contained in:
Daniel 2021-08-23 23:12:53 +02:00
parent 9c72fcfa40
commit b3f7ed8586

View file

@ -97,7 +97,7 @@ type Entity struct {
reverseResolveOnce sync.Once reverseResolveOnce sync.Once
loadDomainListOnce sync.Once loadDomainListOnce sync.Once
loadIPListOnce sync.Once loadIPListOnce sync.Once
loadCoutryListOnce sync.Once loadCountryListOnce sync.Once
loadAsnListOnce sync.Once loadAsnListOnce sync.Once
} }
@ -148,7 +148,7 @@ func (e *Entity) ResetLists() {
e.checkCNAMEs = false e.checkCNAMEs = false
e.loadDomainListOnce = sync.Once{} e.loadDomainListOnce = sync.Once{}
e.loadIPListOnce = sync.Once{} e.loadIPListOnce = sync.Once{}
e.loadCoutryListOnce = sync.Once{} e.loadCountryListOnce = sync.Once{}
e.loadAsnListOnce = sync.Once{} e.loadAsnListOnce = sync.Once{}
} }
@ -313,7 +313,7 @@ func (e *Entity) getDomainLists(ctx context.Context) {
return return
} }
var err error log.Tracer(ctx).Tracef("intel: loading domain list for %s", domain)
e.loadDomainListOnce.Do(func() { e.loadDomainListOnce.Do(func() {
var domainsToInspect = []string{domain} var domainsToInspect = []string{domain}
@ -324,6 +324,7 @@ func (e *Entity) getDomainLists(ctx context.Context) {
var domains []string var domains []string
if e.resolveSubDomainLists { if e.resolveSubDomainLists {
log.Tracer(ctx).Trace("intel: subdomain filtering enabled, checking all subdomains too")
for _, domain := range domainsToInspect { for _, domain := range domainsToInspect {
subdomains := splitDomain(domain) subdomains := splitDomain(domain)
domains = append(domains, subdomains...) domains = append(domains, subdomains...)
@ -335,9 +336,7 @@ func (e *Entity) getDomainLists(ctx context.Context) {
domains = makeDistinct(domains) domains = makeDistinct(domains)
for _, d := range domains { for _, d := range domains {
log.Tracer(ctx).Tracef("intel: loading domain list for %s", d) list, err := filterlists.LookupDomain(d)
var list []string
list, err = filterlists.LookupDomain(d)
if err != nil { if err != nil {
log.Tracer(ctx).Errorf("intel: failed to get domain blocklists for %s: %s", d, err) log.Tracer(ctx).Errorf("intel: failed to get domain blocklists for %s: %s", d, err)
e.ListsError = err.Error() e.ListsError = err.Error()
@ -348,10 +347,6 @@ func (e *Entity) getDomainLists(ctx context.Context) {
} }
e.domainListLoaded = true e.domainListLoaded = true
}) })
if err != nil {
e.loadDomainListOnce = sync.Once{}
}
} }
func splitDomain(domain string) []string { func splitDomain(domain string) []string {
@ -397,7 +392,6 @@ func (e *Entity) getASNLists(ctx context.Context) {
if err != nil { if err != nil {
log.Tracer(ctx).Errorf("intel: failed to get ASN blocklist for %d: %s", asn, err) log.Tracer(ctx).Errorf("intel: failed to get ASN blocklist for %d: %s", asn, err)
e.ListsError = err.Error() e.ListsError = err.Error()
e.loadAsnListOnce = sync.Once{}
return return
} }
@ -417,12 +411,11 @@ func (e *Entity) getCountryLists(ctx context.Context) {
} }
log.Tracer(ctx).Tracef("intel: loading country list for %s", country) log.Tracer(ctx).Tracef("intel: loading country list for %s", country)
e.loadCoutryListOnce.Do(func() { e.loadCountryListOnce.Do(func() {
list, err := filterlists.LookupCountry(country) list, err := filterlists.LookupCountry(country)
if err != nil { if err != nil {
log.Tracer(ctx).Errorf("intel: failed to load country blocklist for %s: %s", country, err) log.Tracer(ctx).Errorf("intel: failed to load country blocklist for %s: %s", country, err)
e.ListsError = err.Error() e.ListsError = err.Error()
e.loadCoutryListOnce = sync.Once{}
return return
} }
@ -453,13 +446,12 @@ func (e *Entity) getIPLists(ctx context.Context) {
log.Tracer(ctx).Tracef("intel: loading IP list for %s", ip) log.Tracer(ctx).Tracef("intel: loading IP list for %s", ip)
e.loadIPListOnce.Do(func() { e.loadIPListOnce.Do(func() {
list, err := filterlists.LookupIP(ip) list, err := filterlists.LookupIP(ip)
if err != nil { if err != nil {
log.Tracer(ctx).Errorf("intel: failed to get IP blocklist for %s: %s", ip.String(), err) log.Tracer(ctx).Errorf("intel: failed to get IP blocklist for %s: %s", ip.String(), err)
e.ListsError = err.Error() e.ListsError = err.Error()
e.loadIPListOnce = sync.Once{}
return return
} }
e.ipListLoaded = true e.ipListLoaded = true
e.mergeList(ip.String(), list) e.mergeList(ip.String(), list)
}) })