From 9e18ff1cd1c1c50346523fd18b8b6c26b5f78118 Mon Sep 17 00:00:00 2001 From: zzz Date: Sat, 26 Dec 2020 09:33:13 -0500 Subject: [PATCH] Router: Move countries.txt file into i2p.jar --- .../java/bundle-messages-countries.sh | 4 ++-- build.xml | 3 --- .../src/net/i2p/util/I2PSSLSocketFactory.java | 16 ++++++---------- {installer => core}/resources/countries.txt | 0 .../java/src/net/i2p/router/transport/GeoIP.java | 15 ++++++--------- 5 files changed, 14 insertions(+), 24 deletions(-) rename {installer => core}/resources/countries.txt (100%) diff --git a/apps/routerconsole/java/bundle-messages-countries.sh b/apps/routerconsole/java/bundle-messages-countries.sh index 5d8198744..d851802f1 100755 --- a/apps/routerconsole/java/bundle-messages-countries.sh +++ b/apps/routerconsole/java/bundle-messages-countries.sh @@ -33,9 +33,9 @@ fi # set LG2 to the language you need in environment variables to enable this # -# generate strings/Countries.java from ../../../installer/resources/countries.txt +# generate strings/Countries.java from ../../../core/resources/countries.txt # -CFILE=../../../installer/resources/countries.txt +CFILE=../../../core/resources/countries.txt # add ../java/ so the refs will work in the po file JFILE=../java/build/Countries.java if [ $CFILE -nt $JFILE -o ! -s $JFILE ] diff --git a/build.xml b/build.xml index bf27fd748..30e40cd5b 100644 --- a/build.xml +++ b/build.xml @@ -1825,8 +1825,6 @@ - - @@ -1844,7 +1842,6 @@ - diff --git a/core/java/src/net/i2p/util/I2PSSLSocketFactory.java b/core/java/src/net/i2p/util/I2PSSLSocketFactory.java index 406b289fe..45a007d16 100644 --- a/core/java/src/net/i2p/util/I2PSSLSocketFactory.java +++ b/core/java/src/net/i2p/util/I2PSSLSocketFactory.java @@ -433,20 +433,15 @@ public class I2PSSLSocketFactory { */ private static void addCountries(I2PAppContext ctx, List tlds) { Log log = ctx.logManager().getLog(I2PSSLSocketFactory.class); - String geoDir = ctx.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT); - File geoFile = new File(geoDir); - if (!geoFile.isAbsolute()) - geoFile = new File(ctx.getBaseDir(), geoDir); - geoFile = new File(geoFile, COUNTRY_FILE_DEFAULT); - if (!geoFile.exists()) { + InputStream is = I2PSSLSocketFactory.class.getResourceAsStream("/net/i2p/util/resources/" + COUNTRY_FILE_DEFAULT); + if (is == null) { if (log.shouldWarn()) - log.warn("Country file not found: " + geoFile.getAbsolutePath()); + log.warn("Country file not found"); return; } BufferedReader br = null; try { - br = new BufferedReader(new InputStreamReader( - new FileInputStream(geoFile), "UTF-8")); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; int i = 0; while ( (line = br.readLine()) != null) { @@ -460,10 +455,11 @@ public class I2PSSLSocketFactory { } catch (IndexOutOfBoundsException ioobe) {} } if (log.shouldInfo()) - log.info("Loaded " + i + " TLDs from " + geoFile.getAbsolutePath()); + log.info("Loaded " + i + " TLDs from " + COUNTRY_FILE_DEFAULT); } catch (IOException ioe) { log.error("Error reading the Country File", ioe); } finally { + try { is.close(); } catch (IOException ioe) {} if (br != null) try { br.close(); } catch (IOException ioe) {} } } diff --git a/installer/resources/countries.txt b/core/resources/countries.txt similarity index 100% rename from installer/resources/countries.txt rename to core/resources/countries.txt diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index aa25524fb..7862d9799 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -9,6 +9,7 @@ import java.io.BufferedWriter; import java.io.IOException; import java.io.File; import java.io.FileInputStream; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; @@ -520,20 +521,15 @@ public class GeoIP { * */ private void readCountryFile() { - String geoDir = _context.getProperty(PROP_GEOIP_DIR, GEOIP_DIR_DEFAULT); - File geoFile = new File(geoDir); - if (!geoFile.isAbsolute()) - geoFile = new File(_context.getBaseDir(), geoDir); - geoFile = new File(geoFile, COUNTRY_FILE_DEFAULT); - if (!geoFile.exists()) { + InputStream is = GeoIP.class.getResourceAsStream("/net/i2p/util/resources/" + COUNTRY_FILE_DEFAULT); + if (is == null) { if (_log.shouldLog(Log.WARN)) - _log.warn("Country file not found: " + geoFile.getAbsolutePath()); + _log.warn("Country file not found"); return; } BufferedReader br = null; try { - br = new BufferedReader(new InputStreamReader( - new FileInputStream(geoFile), "UTF-8")); + br = new BufferedReader(new InputStreamReader(is, "UTF-8")); String line = null; while ( (line = br.readLine()) != null) { try { @@ -551,6 +547,7 @@ public class GeoIP { if (_log.shouldLog(Log.ERROR)) _log.error("Error reading the Country File", ioe); } finally { + try { is.close(); } catch (IOException ioe) {} if (br != null) try { br.close(); } catch (IOException ioe) {} } }