Router: Move countries.txt file into i2p.jar

This commit is contained in:
zzz
2020-12-26 09:33:13 -05:00
parent 665239fd37
commit 9e18ff1cd1
5 changed files with 14 additions and 24 deletions

View File

@@ -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 ]

View File

@@ -1825,8 +1825,6 @@
<copy file="build/routerconsole.war" todir="pkg-temp/webapps/" />
<copy file="build/addressbook.jar" todir="pkg-temp/lib/" />
<copy file="build/addressbook.war" todir="pkg-temp/webapps/" />
<!-- decapitalized the file in 0.7.8 -->
<copy file="installer/resources/countries.txt" todir="pkg-temp/geoip/" />
<!--
<copy file="installer/resources/public-suffix-list.txt" todir="pkg-temp/geoip/" />
-->
@@ -1844,7 +1842,6 @@
<!-- GeoIP files -->
<target name="prepgeoupdate" depends="prepgeoupdate-unlesspkg" >
<copy file="installer/resources/countries.txt" todir="pkg-temp/geoip/" />
<!--
<copy file="installer/resources/public-suffix-list.txt" todir="pkg-temp/geoip/" />
-->

View File

@@ -433,20 +433,15 @@ public class I2PSSLSocketFactory {
*/
private static void addCountries(I2PAppContext ctx, List<String> 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) {}
}
}

View File

@@ -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) {}
}
}