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)

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `(package private) static String` | `COUNTRY_FILE_DEFAULT`
    `static String` | `GEOIP_DIR_DEFAULT`
    `(package private) static String` | `GEOIP_FILE_DEFAULT`
    `static String` | `GEOIP2_FILE_DEFAULT`
    `static String` | `PROP_BLOCK_MY_COUNTRY`
    `static String` | `PROP_DEBIAN_GEOIP`
    `static String` | `PROP_DEBIAN_GEOIPV6`
    `static String` | `PROP_GEOIP_DIR`
    `(package private) static String` | `PROP_GEOIP_ENABLED`
    `static String` | `PROP_IP_COUNTRY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `GeoIP(I2PAppContext context)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(byte[] ip)` Add to the list needing lookup Public for BundleRouterInfos
    `void` | `add(String ip)` Add to the list needing lookup Public for BundleRouterInfos
    `static void` | `banCountry(RouterContext ctx, String country)` Bans routers located in a specified country.
    `void` | `blockingLookup()` Blocking lookup of all pending IPs.
    `String` | `fullName(String code)` Get the country for a country code Public for BundleRouterInfos
    `(package private) String` | `get(byte[] ip)` Get the country for an IP from the cache.
    `String` | `get(String ip)` Get the country for an IP from the cache.
    `Map<String,String>` | `getCountries()` Get the country code map
    `String` | `getGeoIPBuildInfo()` Return the current GeoIP database version
    `static void` | `main(String[] args)`
    `(package private) static void` | `notifyVersion(I2PAppContext ctx, String subtype, long version)` Tell the update manager.
    `void` | `shutdown()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### COUNTRY_FILE_DEFAULT

          static final String COUNTRY_FILE_DEFAULT

      See Also:
        Constant Field Values

    - #### GEOIP_DIR_DEFAULT

          public static final String GEOIP_DIR_DEFAULT

      See Also:
        Constant Field Values

    - #### GEOIP_FILE_DEFAULT

          static final String GEOIP_FILE_DEFAULT

      See Also:
        Constant Field Values

    - #### GEOIP2_FILE_DEFAULT

          public static final String GEOIP2_FILE_DEFAULT

      See Also:
        Constant Field Values

    - #### PROP_BLOCK_MY_COUNTRY

          public static final String PROP_BLOCK_MY_COUNTRY

      See Also:
        Constant Field Values

    - #### PROP_DEBIAN_GEOIP

          public static final String PROP_DEBIAN_GEOIP

      See Also:
        Constant Field Values

    - #### PROP_DEBIAN_GEOIPV6

          public static final String PROP_DEBIAN_GEOIPV6

      See Also:
        Constant Field Values

    - #### PROP_GEOIP_DIR

          public static final String PROP_GEOIP_DIR

      See Also:
        Constant Field Values

    - #### PROP_GEOIP_ENABLED

          static final String PROP_GEOIP_ENABLED

      See Also:
        Constant Field Values

    - #### PROP_IP_COUNTRY

          public static final String PROP_IP_COUNTRY

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### GeoIP

          public GeoIP(I2PAppContext context)

      Parameters:
        `context` - RouterContext in production, I2PAppContext for testing only

  - ### Method Detail

    - #### add

          public void add(byte[] ip)

      Add to the list needing lookup Public for BundleRouterInfos
      Parameters:
        `ip` - IPv4 or IPv6

    - #### add

          public void add(String ip)

      Add to the list needing lookup Public for BundleRouterInfos
      Parameters:
        `ip` - IPv4 or IPv6

    - #### banCountry

          public static void banCountry(RouterContext ctx,
                                        String country)

      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 banlist
        `country` - the country code (ISO 3166-1 alpha-2 format) of the country whose routers should be banned

    - #### 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

    - #### 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

    - #### 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.

    - #### 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.

    - #### getCountries

          public Map<String,String> getCountries()

      Get the country code map
      Returns:
        Map of two-letter lower case code to untranslated country name, unmodifiable

    - #### getGeoIPBuildInfo

          public String getGeoIPBuildInfo()

      Return the current GeoIP database version

    - #### main

          public static void main(String[] args)

    - #### notifyVersion

          static void notifyVersion(I2PAppContext ctx,
                                    String subtype,
                                    long version)

      Tell the update manager.

    - #### shutdown

          public void shutdown()