Add best-effort geolocation to the IP lookup from geojs and DB-IP City Lite (closes #239)
check / check (push) Successful in 1m13s
check / check (push) Successful in 1m13s
Each result gains `geo`. One request to geojs carries every address, 1 second in all. On a timeout, an error or an answer with no country, city or coordinates, the lookup reads DB-IP City Lite, downloaded monthly into the state directory. geojs answers stay in memory (250,000, least recently used dropped) and in a new `cache.db` table for 7 days. Judgement call: a reserved address goes to neither source, and its `geo` is null. Judgement call: `updated` for DB-IP is when the copy was downloaded. Deviation: the cache is SQLite, by sneak's words. Model: opus-5-5
This commit is contained in:
1 parent
b2553f044d
commit
dfc3945bc0
16 files changed
+2372
-22
No files matched your search
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
"git.eeqj.de/sneak/routewatch/internal/config"
|
||||
"git.eeqj.de/sneak/routewatch/internal/database"
|
||||
"git.eeqj.de/sneak/routewatch/internal/geo"
|
||||
"git.eeqj.de/sneak/routewatch/internal/iplist"
|
||||
"git.eeqj.de/sneak/routewatch/internal/logger"
|
||||
"git.eeqj.de/sneak/routewatch/internal/routetable"
|
||||
@@ -63,6 +64,12 @@ type PTRResolver interface {
|
||||
LookupAddr(ctx context.Context, addr string) ([]string, error)
|
||||
}
|
||||
|
||||
// GeoLocator finds where addresses are, as *geo.Locator does. It returns one
|
||||
// entry for each address, nil when no source answers.
|
||||
type GeoLocator interface {
|
||||
Lookup(ctx context.Context, addrs []netip.Addr) []*geo.Location
|
||||
}
|
||||
|
||||
// Server provides HTTP endpoints for status monitoring
|
||||
type Server struct {
|
||||
router *chi.Mux
|
||||
@@ -86,6 +93,10 @@ type Server struct {
|
||||
// ptrResolver looks up the IP lookup's PTR names. SetPTRResolver sets it.
|
||||
ptrResolver PTRResolver
|
||||
|
||||
// geoLocator finds where the IP lookup's addresses are. SetGeoLocator
|
||||
// sets it.
|
||||
geoLocator GeoLocator
|
||||
|
||||
// cards is the copy of the home page's cards that the pages serve, nil
|
||||
// until the server first works them out
|
||||
cards atomic.Pointer[homeCards]
|
||||
@@ -209,6 +220,12 @@ func (s *Server) SetPTRResolver(resolver PTRResolver) {
|
||||
s.ptrResolver = resolver
|
||||
}
|
||||
|
||||
// SetGeoLocator sets what finds where the IP lookup's addresses are. Call it
|
||||
// before Start: the handlers read it without a lock.
|
||||
func (s *Server) SetGeoLocator(locator GeoLocator) {
|
||||
s.geoLocator = locator
|
||||
}
|
||||
|
||||
// SetASNFetcher sets the ASN WHOIS fetcher for on-demand lookups. Call it
|
||||
// before Start: the handlers read the fetcher without a lock.
|
||||
func (s *Server) SetASNFetcher(fetcher ASNFetcher) {
|
||||
|
||||
Reference in new issue
Block a user