Skip to content

Commit

Permalink
geoip2: add active-checks to queries
Browse files Browse the repository at this point in the history
Add checks for the DB to be active before making a query. This was only
enabled on ASN, now enabled for City and Country queries.
  • Loading branch information
tydavis committed Oct 20, 2021
1 parent 749e8ce commit a510b96
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions targeting/geoip2/geoip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ func (g *GeoIP2) GetCountry(ip net.IP) (country, continent string, netmask int)
g.country.l.RLock()
defer g.country.l.RUnlock()

if !g.country.active {
return "", "", 0
}

c, err := g.country.db.Country(ip)
if err != nil {
log.Printf("Could not lookup country for '%s': %s", ip.String(), err)
Expand Down Expand Up @@ -215,6 +219,10 @@ func (g *GeoIP2) GetLocation(ip net.IP) (l *geo.Location, err error) {
g.city.l.RLock()
defer g.city.l.RUnlock()

if !g.city.active {
return nil, fmt.Errorf("city db not active")
}

c, err := g.city.db.City(ip)
if err != nil {
log.Printf("Could not lookup CountryRegion for '%s': %s", ip.String(), err)
Expand Down

0 comments on commit a510b96

Please sign in to comment.