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 Details

  • Constructor Details

    • GeoIP

      public GeoIP(I2PAppContext context)
      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

      static void notifyVersion(I2PAppContext ctx, String subtype, long version)
      Tell the update manager.
      Since:
      0.9.45
    • add

      public void add(String ip)
      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

      public String get(String ip)
      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

      String get(byte[] ip)
      Get the country for an IP from the cache.
      Parameters:
      ip - IPv4 or IPv6
      Returns:
      lower-case code, generally two letters, or null.
    • fullName

      public String fullName(String code)
      Get the country for a country code Public for BundleRouterInfos
      Parameters:
      code - two-letter lower case code
      Returns:
      untranslated name or null
    • getCountries

      public Map<String,String> getCountries()
      Get the country code map
      Returns:
      Map of two-letter lower case code to untranslated country name, unmodifiable
      Since:
      0.9.53
    • main

      public static void main(String[] args)