Package net.i2p.router.transport
Class GeoIP
java.lang.Object
net.i2p.router.transport.GeoIP
public class GeoIP extends Object
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)
- Author:
- zzz
-
Field Summary
Fields Modifier and Type Field Description (package private) static StringCOUNTRY_FILE_DEFAULTstatic StringGEOIP_DIR_DEFAULT(package private) static StringGEOIP_FILE_DEFAULTstatic StringGEOIP2_FILE_DEFAULTstatic StringPROP_DEBIAN_GEOIPstatic StringPROP_DEBIAN_GEOIPV6static StringPROP_GEOIP_DIR(package private) static StringPROP_GEOIP_ENABLEDstatic StringPROP_IP_COUNTRY -
Constructor Summary
Constructors Constructor Description GeoIP(I2PAppContext context) -
Method Summary
Modifier and Type Method Description voidadd(byte[] ip)Add to the list needing lookup Public for BundleRouterInfosvoidadd(String ip)Add to the list needing lookup Public for BundleRouterInfosvoidblockingLookup()Blocking lookup of all pending IPs.StringfullName(String code)Get the country for a country code Public for BundleRouterInfos(package private) Stringget(byte[] ip)Get the country for an IP from the cache.Stringget(String ip)Get the country for an IP from the cache.static voidmain(String[] args)(package private) static voidnotifyVersion(I2PAppContext ctx, String subtype, long version)Tell the update manager.voidshutdown()
-
Field Details
-
PROP_GEOIP_ENABLED
- See Also:
- Constant Field Values
-
PROP_GEOIP_DIR
- See Also:
- Constant Field Values
-
GEOIP_DIR_DEFAULT
- See Also:
- Constant Field Values
-
GEOIP_FILE_DEFAULT
- See Also:
- Constant Field Values
-
GEOIP2_FILE_DEFAULT
- See Also:
- Constant Field Values
-
COUNTRY_FILE_DEFAULT
- See Also:
- Constant Field Values
-
PROP_IP_COUNTRY
- See Also:
- Constant Field Values
-
PROP_DEBIAN_GEOIP
- See Also:
- Constant Field Values
-
PROP_DEBIAN_GEOIPV6
- See Also:
- Constant Field Values
-
-
Constructor Details
-
GeoIP
- Parameters:
context- RouterContext in production, I2PAppContext for testing only
-
-
Method Details
-
shutdown
public void shutdown()- Since:
- 0.9.3
-
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 -
notifyVersion
Tell the update manager.- Since:
- 0.9.45
-
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. Public for BundleRouterInfos- Parameters:
ip- IPv4 or IPv6- Returns:
- lower-case code, generally two letters, or null.
-
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
Get the country for a country code Public for BundleRouterInfos- Parameters:
code- two-letter lower case code- Returns:
- untranslated name or null
-
main
-