From 2524a7a69d93fffc3a80112b317b3f364143dd62 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Thu, 20 Feb 2020 16:44:18 +0000
Subject: [PATCH] GeoIP: Prefer more recent of mmdb or Debian files if we have
 both

---
 router/java/src/net/i2p/router/transport/GeoIP.java | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java
index a22fa37588..2fc2f0f31a 100644
--- a/router/java/src/net/i2p/router/transport/GeoIP.java
+++ b/router/java/src/net/i2p/router/transport/GeoIP.java
@@ -186,7 +186,11 @@ public class GeoIP {
                 if (search.length > 0) {
                     Arrays.sort(search);
                     File f = new File(_context.getProperty(PROP_DEBIAN_GEOIP, DEBIAN_GEOIP_FILE));
-                    if (ENABLE_DEBIAN && f.exists()) {
+                    // if we have both, prefer the most recent.
+                    // The Debian data can be pretty old.
+                    // For now, we use the file date, we don't open it up to get the metadata.
+                    if (ENABLE_DEBIAN && f.exists() &&
+                        (geoip2 == null || f.lastModified() > geoip2.lastModified())) {
                         // Maxmind v1 database
                         LookupService ls = null;
                         try {
@@ -255,7 +259,8 @@ public class GeoIP {
                 if (search.length > 0) {
                     Arrays.sort(search);
                     File f = new File(_context.getProperty(PROP_DEBIAN_GEOIPV6, DEBIAN_GEOIPV6_FILE));
-                    if (ENABLE_DEBIAN && f.exists()) {
+                    if (ENABLE_DEBIAN && f.exists() &&
+                        (geoip2 == null || f.lastModified() > geoip2.lastModified())) {
                         // Maxmind v1 database
                         LookupService ls = null;
                         try {
-- 
GitLab