java.lang.Object
net.i2p.router.transport.GeoIP
Manage geoip lookup in a file with the Tor geoip format.
The lookup is expensive, so a lookup is queued with add(). The actual lookup of multiple IPs is fired with lookup(). To get a country for an IP, use get() which returns a lower-case, generally two-letter country code or null.
Everything here uses longs, since Java is signed-only, the file is sorted by unsigned, and we don't store the table in memory (unlike in Blocklist.java, where it's in-memory so we want to be space-efficient).
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault MaxMind ASN database file name.(package private) static final StringDefault country names file name.static final StringDefault GeoIP directory, under the router's base directory.(package private) static final StringDefault geoip file name.static final StringGEOIP2_FILE_DEFAULT.static final StringProperty: whether to refuse tunnels to destinations in our own country.static final StringProperty: the Debian-packaged IPv4 GeoIP database path.static final StringPROP_DEBIAN_GEOIPV6.static final StringProperty: the directory the GeoIP databases are read from.(package private) static final StringProperty: whether GeoIP lookups are enabled.static final StringProperty: the last country an IP was seen in, set for the console.(package private) static final StringNormalize ISP/org names from ASN database (strip suffixes, abbreviate, title-case).Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionvoidadd(byte[] ip) Add to the list needing lookup Public for BundleRouterInfos.voidAdd to the list needing lookup Public for BundleRouterInfos.static voidbanCountry(RouterContext ctx, String country) Bans routers located in a specified country.voidBlocking lookup of all pending IPs.The untranslated country name for a country code.(package private) Stringget(byte[] ip) The country for an IP from the cache.The country for an IP from the cache.Return the current ASN database version.The country code map.Return the country database's build date, size and path, for the console.getOrgName(String ipAddress) The organization name for an IP from the local ASN database.static StringnormalizeOrgName(String raw) Normalize an ISP/org name from the ASN database.(package private) static voidnotifyVersion(I2PAppContext ctx, String subtype, long version) Tell the update manager.(package private) static voidnotifyVersion(I2PAppContext ctx, String subtype, String version) Tell the update manager, with a version string as-is, e.g.voidshutdown()Shutdown and release resources.
Field Details
PROP_GEOIP_ENABLED
Property: whether GeoIP lookups are enabled.- See Also:
PROP_NORMALIZE_ISP
Normalize ISP/org names from ASN database (strip suffixes, abbreviate, title-case).- See Also:
PROP_GEOIP_DIR
Property: the directory the GeoIP databases are read from.- See Also:
GEOIP_DIR_DEFAULT
Default GeoIP directory, under the router's base directory.- See Also:
GEOIP_FILE_DEFAULT
GEOIP2_FILE_DEFAULT
ASN_FILE_DEFAULT
Default MaxMind ASN database file name.- See Also:
COUNTRY_FILE_DEFAULT
Default country names file name.- See Also:
PROP_IP_COUNTRY
Property: the last country an IP was seen in, set for the console.- See Also:
PROP_DEBIAN_GEOIP
Property: the Debian-packaged IPv4 GeoIP database path.- See Also:
PROP_DEBIAN_GEOIPV6
PROP_BLOCK_MY_COUNTRY
Property: whether to refuse tunnels to destinations in our own country.- See Also:
Constructor Details
GeoIP
GeoIP lookup service for IP to country mapping.- Parameters:
context- RouterContext in production, I2PAppContext for testing only
Method Details
shutdown
public void shutdown()Shutdown and release resources.blockingLookup
public void blockingLookup()Blocking lookup of all pending IPs. Results will be added to the table and available via get() after completion.Public for BundleRouterInfos.
getOrgName
normalizeOrgName
Normalize an ISP/org name from the ASN database. Strips suffixes, abbreviates verbose words, title-cases with acronym preservation.- Parameters:
raw- original org name from MMDB- Returns:
- the normalized organisation name, or the input if it was null or empty
getGeoIPBuildInfo
Return the country database's build date, size and path, for the console.- Returns:
- the HTML build info, or a not-found or error message
getASNBuildInfo
Return the current ASN database version.- Returns:
- the HTML build info, or a not-found or error message
notifyVersion
Tell the update manager.- Parameters:
ctx- the application context whose client app manager holds the registered update managersubtype- the updater subtype recorded against the GEOIP update type, e.g. "GeoIP"version- the version number being reported; anything zero or below is ignored
notifyVersion
Tell the update manager, with a version string as-is, e.g. the product version embedded in a database's metadata.- Parameters:
ctx- the application context whose client app manager holds the registered update managersubtype- the updater subtype recorded against the GEOIP update type, e.g. "ASN"version- the version being reported; null or empty is ignored
banCountry
Bans routers located in a specified country.This method iterates through all known routers in the network database and adds those located in the specified country to the banlist. Routers are banned indefinitely with a reason message that reflects whether the application is in 'block my country' mode or 'hidden' mode.
- Parameters:
ctx- the RouterContext instance providing access to network database and banlistcountry- the country code (ISO 3166-1 alpha-2 format) of the country whose routers should be banned
add
Add to the list needing lookup Public for BundleRouterInfos.- Parameters:
ip- IPv4 or IPv6
add
public void add(byte[] ip) Add to the list needing lookup Public for BundleRouterInfos.- Parameters:
ip- IPv4 or IPv6
get
get
The country for an IP from the cache.- Parameters:
ip- IPv4 or IPv6- Returns:
- lower-case code, generally two letters, or null.
fullName
getCountries