From 2805388a4c744b83b2bc6348766c19f09529135f Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 20 Feb 2020 15:42:22 +0000
Subject: [PATCH] GeoIP: Add unknown and Kosovo country codes for db-ip.com
 (ticket #2692) https://db-ip.com/faq.php

---
 installer/resources/continents.txt                  | 1 +
 installer/resources/countries.txt                   | 1 +
 router/java/src/net/i2p/router/transport/GeoIP.java | 6 ++++--
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/installer/resources/continents.txt b/installer/resources/continents.txt
index 4a7750b700..5a0abe3802 100644
--- a/installer/resources/continents.txt
+++ b/installer/resources/continents.txt
@@ -248,6 +248,7 @@ VN,AS
 VU,OC
 WF,OC
 WS,OC
+XK,EU
 YE,AS
 YT,AF
 ZA,AF
diff --git a/installer/resources/countries.txt b/installer/resources/countries.txt
index 9702197ef5..f3dff7efe4 100644
--- a/installer/resources/countries.txt
+++ b/installer/resources/countries.txt
@@ -254,6 +254,7 @@ VN,Vietnam
 VU,Vanuatu
 WF,Wallis and Futuna
 WS,Samoa
+XK,Kosovo
 YE,Yemen
 YT,Mayotte
 ZA,South Africa
diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java
index ce77b9c4ca..a22fa37588 100644
--- a/router/java/src/net/i2p/router/transport/GeoIP.java
+++ b/router/java/src/net/i2p/router/transport/GeoIP.java
@@ -84,6 +84,8 @@ public class GeoIP {
     private static final boolean ENABLE_DEBIAN = !DISABLE_DEBIAN && !(SystemVersion.isWindows() || SystemVersion.isAndroid());
     /** maxmind API */
     private static final String UNKNOWN_COUNTRY_CODE = "--";
+    /** db-ip.com https://db-ip.com/faq.php */
+    private static final String UNKNOWN_COUNTRY_CODE2 = "ZZ";
 
     /**
      *  @param context RouterContext in production, I2PAppContext for testing only
@@ -223,7 +225,7 @@ public class GeoIP {
                                 String ipv4 = toV4(ipl);
                                 // returns upper case or null
                                 String uc = dbr.country(ipv4);
-                                if (uc != null) {
+                                if (uc != null && !uc.equals(UNKNOWN_COUNTRY_CODE2)) {
                                     String lc = uc.toLowerCase(Locale.US);
                                     String cached = _codeCache.get(lc);
                                     if (cached == null)
@@ -294,7 +296,7 @@ public class GeoIP {
                                 String ipv6 = toV6(ipl);
                                 // returns upper case or null
                                 String uc = dbr.country(ipv6);
-                                if (uc != null) {
+                                if (uc != null && !uc.equals(UNKNOWN_COUNTRY_CODE2)) {
                                     String lc = uc.toLowerCase(Locale.US);
                                     String cached = _codeCache.get(lc);
                                     if (cached == null)
-- 
GitLab