v1.0.0

Geo Detection

Last updated


This page explains how the GeoLite2 databases are enabled, how IP locations are looked up, cached, and recorded per session, and the known boundaries of geo detection.

Enabling


SettingResult
Both Filepath.CityDB and Filepath.CountryDB emptyNo GeoLite2 instance; geo detection off
Both fail to openLogs a warning; geo detection off
Only CountryDB openscalcGeo requires CityDB, so geo detection is skipped entirely
CityDB opensOn; CountryDB is only a fallback when the City lookup fails

Download the database (GeoLite2-City.mmdb) from MaxMind yourself; this library does not update it.

Lookup and History


StepBehavior
Private IPSkips the database and returns an empty location (no country or city, coordinates 0)
Cachegeo:ip:{ip} keeps the lookup result for 24 hours
Not foundLogged and skipped; the request's geo score is 0
Historygeo:locations:{sid} pushes {ms}:{country code}:{city}:{lat}:{lng}, keeps the last 10, TTL 24 hours

Boundaries


CaseBehavior
One session alternating between private and public IPsPrivate records sit at (0, 0), so switching to a public IP looks like a jump of thousands of kilometers from the Atlantic and may trigger rapid_geo_change
GeoLite2 accuracyCity-level locations can be off by tens of kilometers; different IPs in one city only affect the city-switch count

For the four anomaly checks and impossible-travel examples, see Geo Anomaly Checks.
中文