From 8c70af56ad15dabd7d83b82660831ef7b8d58188 Mon Sep 17 00:00:00 2001 From: kytv Date: Sun, 8 Jan 2012 16:35:53 +0000 Subject: [PATCH 01/12] refreshed patch --- debian/patches/0002-jbigi-soname.patch | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/patches/0002-jbigi-soname.patch b/debian/patches/0002-jbigi-soname.patch index a4f91eacf8..f38d5fb89d 100644 --- a/debian/patches/0002-jbigi-soname.patch +++ b/debian/patches/0002-jbigi-soname.patch @@ -27,6 +27,6 @@ a soname to shut lintian up. rm -f jbigi.o $LIBFILE -$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c || exit 1 +$CC -c $COMPILEFLAGS $INCLUDES ./jbigi/src/jbigi.c || exit 1 - $CC $LINKFLAGS $INCLUDES $INCLUDELIBS -o $LIBFILE jbigi.o $STATICLIBS || exit 1 + $CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS || exit 1 exit 0 From 430ac8323fddb7502b35f515e94c708e36dd861a Mon Sep 17 00:00:00 2001 From: kytv Date: Sun, 8 Jan 2012 19:08:04 +0000 Subject: [PATCH 02/12] Really send HUP signal when called with the graceful parameter --- installer/resources/i2prouter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/installer/resources/i2prouter b/installer/resources/i2prouter index 02b21ac987..eb9c476f68 100644 --- a/installer/resources/i2prouter +++ b/installer/resources/i2prouter @@ -1099,7 +1099,7 @@ graceful() { # Running so try to stop it. # This sends HUP. router.gracefulHUP must be set in router.config, # or else this will do the same as stop. - kill $pid + kill -HUP $pid if [ $? -ne 0 ] then # An explanation for the failure should have been given From 527c4b58c1b41a1f23c9c779e70d8c10a63b6d44 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 8 Jan 2012 19:45:01 +0000 Subject: [PATCH 03/12] Added support for i7 Extreme Edition processors. --- .../src/freenet/support/CPUInformation/IntelInfoImpl.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java index 044088e10a..d469262f88 100644 --- a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java +++ b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java @@ -238,9 +238,15 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo case 10: modelString = "Core i7/i5 (32nm)"; break; + case 11: + modelString = "Core i7/i5 (32nm)"; + break; case 12: modelString = "Core i7 (32nm)"; break; + case 12: + modelString = "Core i7 Extreme Edition (32nm)"; + break; case 14: modelString = "Xeon MP (45nm)"; break; From f5b6d5648915aadc11eb4a889020b828a76f5628 Mon Sep 17 00:00:00 2001 From: dev Date: Sun, 8 Jan 2012 19:54:22 +0000 Subject: [PATCH 04/12] Added support for AMD Bulldozer CPUs. Fixed issue with last commit. --- .../support/CPUInformation/AMDCPUInfo.java | 4 ++++ .../support/CPUInformation/AMDInfoImpl.java | 19 +++++++++++++++++++ .../support/CPUInformation/IntelInfoImpl.java | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/core/java/src/freenet/support/CPUInformation/AMDCPUInfo.java b/core/java/src/freenet/support/CPUInformation/AMDCPUInfo.java index 174bbe4ed8..8d36c2cac7 100644 --- a/core/java/src/freenet/support/CPUInformation/AMDCPUInfo.java +++ b/core/java/src/freenet/support/CPUInformation/AMDCPUInfo.java @@ -43,4 +43,8 @@ public interface AMDCPUInfo extends CPUInfo { * @return true if the CPU present in the machine is at least an 'k8' CPU (Atlhon 64, Opteron etc. and better) */ public boolean IsBobcatCompatible(); + /** + * @return true if the CPU present in the machine is at least a 'bulldozer' CPU + */ + public boolean IsBulldozerCompatible(); } diff --git a/core/java/src/freenet/support/CPUInformation/AMDInfoImpl.java b/core/java/src/freenet/support/CPUInformation/AMDInfoImpl.java index 9b60af9060..222f6e66d8 100644 --- a/core/java/src/freenet/support/CPUInformation/AMDInfoImpl.java +++ b/core/java/src/freenet/support/CPUInformation/AMDInfoImpl.java @@ -13,6 +13,7 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo protected static boolean isAthlonCompatible = false; protected static boolean isAthlon64Compatible = false; protected static boolean isBobcatCompatible = false; + protected static boolean isBulldozerCompatible = false; // If modelString != null, the cpu is considered correctly identified. protected static String modelString = null; @@ -31,6 +32,8 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo public boolean IsBobcatCompatible(){ return isBobcatCompatible; } + public boolean IsBulldozerCompatible(){ return isBulldozerCompatible; } + static { identifyCPU(); @@ -349,6 +352,22 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo break; } } + //Bulldozer + if(CPUID.getCPUFamily() + CPUID.getCPUExtendedFamily() == 21){ + isK6Compatible = true; + isK6_2_Compatible = true; + isK6_3_Compatible = true; + isAthlonCompatible = true; + isAthlon64Compatible = true; + isBobcatCompatible = true; + isBulldozerCompatible = true; + isX64 = true; + switch(CPUID.getCPUModel() + CPUID.getCPUExtendedModel()){ + case 1: + modelString = "Bulldozer FX-6***/FX-8***"; + break; + } + } } public boolean hasX64() diff --git a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java index d469262f88..af2da3b484 100644 --- a/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java +++ b/core/java/src/freenet/support/CPUInformation/IntelInfoImpl.java @@ -244,7 +244,7 @@ class IntelInfoImpl extends CPUIDCPUInfo implements IntelCPUInfo case 12: modelString = "Core i7 (32nm)"; break; - case 12: + case 13: modelString = "Core i7 Extreme Edition (32nm)"; break; case 14: From b09071f20f1d28bda9edf4314dc6f53227288ac0 Mon Sep 17 00:00:00 2001 From: kytv Date: Sun, 8 Jan 2012 23:23:00 +0000 Subject: [PATCH 05/12] update of jbigi scripts - merge mbuild_jbigi.sh into build_jbigi.sh and drop mbuild_jbigi.sh - make build.sh's tests optional - try to determine the locations of JAVA_HOME and I2P --- core/c/jbigi/README | 5 +- core/c/jbigi/build.sh | 125 +++++++++++++++++-------- core/c/jbigi/build_jbigi.sh | 95 +++++++++---------- core/c/jbigi/find-java-home | 24 +++++ core/c/jbigi/mbuild-all.sh | 2 +- core/c/jbigi/mbuild_jbigi.sh | 72 -------------- debian/patches/0002-jbigi-soname.patch | 16 ++-- 7 files changed, 168 insertions(+), 171 deletions(-) create mode 100644 core/c/jbigi/find-java-home delete mode 100755 core/c/jbigi/mbuild_jbigi.sh diff --git a/core/c/jbigi/README b/core/c/jbigi/README index 98cba74c02..9e06381d6d 100644 --- a/core/c/jbigi/README +++ b/core/c/jbigi/README @@ -10,9 +10,10 @@ TODO: Document generated folder structure Linux-specific information: =========================== -Some linux distributions comes bundled with GMP. +Some linux distributions come bundled with GMP. Try 'locate lib/libgmp.so' to see. -If so, install the the libgmp3-dev debian package to get the libgmp headers. + +In Debian/Ubuntu, install the the libgmp3-dev package to get the libgmp headers. Then export I2P=/path/to/your/i2p/install. Then do 'build.sh dynamic'. This will do a quick build using your installed libgmp library and then test it and the jbigi in your I2P installation to see which is faster. diff --git a/core/c/jbigi/build.sh b/core/c/jbigi/build.sh index e511a0fd89..f87932e485 100755 --- a/core/c/jbigi/build.sh +++ b/core/c/jbigi/build.sh @@ -17,63 +17,106 @@ # The resulting library is lib/libjbigi.so # -mkdir -p lib/ -mkdir -p bin/local +rm -rf bin/local +mkdir -p lib bin/local + +# Use 4.3.2 32bit CPUs. +# Use 5.0.2 64bit CPUs. VER=4.3.2 +# If JAVA_HOME isn't set, try to figure it out on our own +[ -z $JAVA_HOME ] && . ./find-java-home +if [ ! -f "$JAVA_HOME/include/jni.h" ]; then + echo "ERROR: Cannot find jni.h! Looked in \"$JAVA_HOME/include/jni.h\"" >&2 + echo "Please set JAVA_HOME to a java home that has the JNI" >&2 + exit 1 +fi + +# Abort script on uncaught errors set -e -if [ "$1" != "dynamic" -a ! -d gmp-$VER ] -then - TAR=gmp-$VER.tar.bz2 - if [ ! -f $TAR ] - then - echo "Downloading ftp://ftp.gmplib.org/pub/gmp-${VER}/gmp-${VER}.tar.bz2" - wget ftp://ftp.gmplib.org/pub/gmp-${VER}/gmp-${VER}.tar.bz2 - fi +download_gmp () +{ +if [ $(which wget) ]; then + echo "Downloading ftp://ftp.gmplib.org/pub/gmp-${VER}/${TAR}" + wget -N --progress=dot ftp://ftp.gmplib.org/pub/gmp-${VER}/${TAR} +else + echo "ERROR: Cannot find wget." >&2 + echo >&2 + echo "Please download ftp://ftp.gmplib.org/pub/gmp-${VER}/${TAR}" >&2 + echo "manually and rerun this script." >&2 + exit 1 +fi +} - echo "Building the jbigi library with GMP Version $VER" +extract_gmp () +{ +tar -xjf ${TAR} > /dev/null 2>&1|| (rm -f ${TAR} && download_gmp && extract_gmp || exit 1) +} - echo "Extracting GMP..." - tar -xjf gmp-$VER.tar.bz2 +TAR=gmp-${VER}.tar.bz2 + +if [ "$1" != "dynamic" -a ! -d gmp-${VER} ]; then + if [ ! -f $TAR ]; then + download_gmp + fi + + echo "Building the jbigi library with GMP Version ${VER}" + echo "Extracting GMP..." + extract_gmp fi cd bin/local echo "Building..." -if [ "$1" != "dynamic" ] -then - case `uname -sr` in - Darwin*) - # --with-pic is required for static linking - ../../gmp-$VER/configure --with-pic;; - *) - # and it's required for ASLR - ../../gmp-$VER/configure --with-pic;; - esac - make - sh ../../build_jbigi.sh static +if [ "$1" != "dynamic" ]; then + case `uname -sr` in + Darwin*) + # --with-pic is required for static linking + ../../gmp-${VER}/configure --with-pic;; + *) + # and it's required for ASLR + ../../gmp-${VER}/configure --with-pic;; + esac + make + sh ../../build_jbigi.sh static else - sh ../../build_jbigi.sh dynamic + shift + sh ../../build_jbigi.sh dynamic fi cp *jbigi???* ../../lib/ echo 'Library copied to lib/' cd ../.. -if [ ! -f $I2P/lib/i2p.jar ] -then - echo "I2P installation not found" - echo "We looked in '$I2P'" - echo "Not running tests against I2P installation without knowing where it is" - echo "Please set the environment variable I2P to the location of your I2P installation (so that \$I2P/lib/i2p.jar works)" - echo "If you do so, this script will run two tests to compare your installed jbigi with the one here you just compiled (to see if there is a marked improvement)" - exit 1 +if [ "$1" != "notest" ]; then + if [ -z "$I2P" ]; then + if [ -r $HOME/i2p/lib/i2p.jar ]; then + I2P="$HOME/i2p" + elif [ -r /usr/share/i2p/lib/i2p.jar ]; then + I2P="/usr/share/i2p" + else + echo "Please set the environment variable \$I2P to run tests." >&2 + fi + fi + + if [ ! -f $I2P/lib/i2p.jar ]; then + echo "I2P installation not found" >&2 + echo "We looked in $I2P" >&2 + echo "Not running tests against I2P installation without knowing where it is." >&2 + echo >&2 + echo "Please set the environment variable I2P to the location of your" + echo "I2P installation (so that \$I2P/lib/i2p.jar works)." >&2 + echo "If you do so, this script will run two tests to compare your" >&2 + echo "installed jbigi with the one here you just compiled to see if" >&2 + echo "there is a marked improvement." >&2 + exit 1 + fi + echo 'Running test with standard I2P installation...' + java -cp $I2P/lib/i2p.jar:$I2P/lib/jbigi.jar net.i2p.util.NativeBigInteger + echo + echo 'Running test with new libjbigi...' + java -Djava.library.path=lib/ -cp $I2P/lib/i2p.jar:$I2P/lib/jbigi.jar net.i2p.util.NativeBigInteger + echo 'If the second run shows better performance, please use the jbigi that you have compiled so that I2P will work better!' + echo "(You can do that just by copying lib/libjbigi.so over the existing libjbigi.so file in \$I2P)" fi -echo 'Running test with standard I2P installation...' -java -cp $I2P/lib/i2p.jar:$I2P/lib/jbigi.jar net.i2p.util.NativeBigInteger -echo -echo 'Running test with new libjbigi...' -java -Djava.library.path=lib/ -cp $I2P/lib/i2p.jar:$I2P/lib/jbigi.jar net.i2p.util.NativeBigInteger -echo 'If the second is better performance, please use the jbigi you have compiled i2p will work better!' -echo '(You can do that just by copying lib/libjbigi.so over the existing libjbigi.so file in $I2P)' diff --git a/core/c/jbigi/build_jbigi.sh b/core/c/jbigi/build_jbigi.sh index b5f45b7dbc..91135d211d 100755 --- a/core/c/jbigi/build_jbigi.sh +++ b/core/c/jbigi/build_jbigi.sh @@ -1,61 +1,62 @@ #!/bin/sh -# When executed in Mingw: Produces an jbigi.dll -# When executed in Linux/FreeBSD: Produces an libjbigi.so -# Darwin produces libjbigi.jnilib, right? - +# When executed in Mingw: Produces a jbigi.dll +# When executed in Linux/FreeBSD: Produces a libjbigi.so +# When executed in OSX: Produces a libjbigi.jnilib CC="gcc" -case `uname -sr` in -MINGW*) - JAVA_HOME="c:/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" - LINKFLAGS="-shared -Wl,--kill-at" - LIBFILE="jbigi.dll";; -CYGWIN*) - JAVA_HOME="c:/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall -mno-cygwin" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" - LINKFLAGS="-shared -Wl,--kill-at" - LIBFILE="jbigi.dll";; -Darwin*) - JAVA_HOME="/Library/Java/Home" - COMPILEFLAGS="-Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include" - LINKFLAGS="-dynamiclib -framework JavaVM" - LIBFILE="libjbigi.jnilib";; -SunOS*) - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/solaris" - LINKFLAGS="-shared -Wl,-soname,libjbigi.so" - LIBFILE="libjbigi.so";; -*) - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" - LINKFLAGS="-shared -Wl,-soname,libjbigi.so" - LIBFILE="libjbigi.so";; -esac - +# If JAVA_HOME isn't set we'll try to figure it out +[ -z $JAVA_HOME ] && . ./find-java-home if [ ! -f "$JAVA_HOME/include/jni.h" ]; then echo "Cannot find jni.h! Looked in '$JAVA_HOME/include/jni.h'" echo "Please set JAVA_HOME to a java home that has the JNI" exit 1 fi -#To link dynamically to GMP (use libgmp.so or gmp.lib), uncomment the first line below -#To link statically to GMP, uncomment the second line below -# Bug!!! Quote *BOTH* or neither! --Sponge -if test "$1" = "dynamic" -then - echo "Building jbigi lib that is dynamically linked to GMP" - LIBPATH="-L.libs" - INCLUDELIBS="-lgmp" +case `uname -s` in +MINGW*) + JAVA_HOME="c:/software/j2sdk1.4.2_05" + COMPILEFLAGS="-Wall" + INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" + LINKFLAGS="-shared -Wl,--kill-at" + LIBFILE="jbigi.dll";; +CYGWIN*) + JAVA_HOME="c:/software/j2sdk1.4.2_05" + COMPILEFLAGS="-Wall -mno-cygwin" + INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" + LINKFLAGS="-shared -Wl,--kill-at" + LIBFILE="jbigi.dll";; +Darwin*) + JAVA_HOME=$(/usr/libexec/java_home) + COMPILEFLAGS="-fPIC -Wall" + INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include" + LINKFLAGS="-dynamiclib -framework JavaVM" + LIBFILE="libjbigi.jnilib";; +SunOS*|OpenBSD*|NetBSD*|FreeBSD*|Linux*) + UNIXTYPE=$(uname -s | tr "[A-Z]" "[a-z]") + if [ $UNIXTYPE = "sunos" ]; then + UNIXTYPE="solaris" + fi + COMPILEFLAGS="-fPIC -Wall" + INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/${UNIXTYPE}" + LINKFLAGS="-shared -Wl,-soname,libjbigi.so" + LIBFILE="libjbigi.so";; +*) + echo "Unsupported system type." + exit 1;; +esac + +if [ "$1" = "dynamic" ] ; then + echo "Building a jbigi lib that is dynamically linked to GMP" + LIBPATH="-L.libs" + INCLUDELIBS="-lgmp" else - echo "Building jbigi lib that is statically linked to GMP" - STATICLIBS=".libs/libgmp.a" + echo "Building a jbigi lib that is statically linked to GMP" + STATICLIBS=".libs/libgmp.a" fi echo "Compiling C code..." rm -f jbigi.o $LIBFILE -$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c -$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS +$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c || exit 1 +$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS || exit 1 + +exit 0 diff --git a/core/c/jbigi/find-java-home b/core/c/jbigi/find-java-home new file mode 100644 index 0000000000..fd069f4a64 --- /dev/null +++ b/core/c/jbigi/find-java-home @@ -0,0 +1,24 @@ +UNIXTYPE=$(uname -s | tr "[A-Z]" "[a-z]") +if [ $UNIXTYPE = "freebsd" ]; then + if [ -d /usr/local/openjdk6 ]; then + JAVA_HOME="/usr/local/openjdk6" + elif [ -d /usr/local/openjdk7 ]; then + JAVA_HOME="/usr/local/openjdk7" + fi +elif [ $UNIXTYPE = "openbsd" ]; then + if [ -d /usr/local/jdk-1.7.0 ]; then + JAVA_HOME="/usr/local/jdk-1.7.0" + fi +elif [ $UNIXTYPE = "netbsd" ]; then + if [ -d /usr/pkg/java/openjdk7 ]; then + JAVA_HOME="/usr/pkg/java/openjdk7" + fi +elif [ $UNIXTYPE = "linux" ] && [ -e /etc/debian_version ]; then + if [ -d /usr/lib/jvm/default-java ]; then + JAVA_HOME="/usr/lib/jvm/default-java" + fi +elif [ $UNIXTYPE = "darwin" ]; then + JAVA_HOME=$(/usr/libexec/java_home) +fi + +export JAVA_HOME diff --git a/core/c/jbigi/mbuild-all.sh b/core/c/jbigi/mbuild-all.sh index c257278caf..711b960df0 100755 --- a/core/c/jbigi/mbuild-all.sh +++ b/core/c/jbigi/mbuild-all.sh @@ -154,7 +154,7 @@ esac make_static () { $ECHO "Attempting .${4} creation for ${3}${5}${2}" - ../../mbuild_jbigi.sh static || return 1 + ../../build_jbigi.sh static || return 1 cp ${3}.${4} ../../lib/net/i2p/util/${3}${5}${2}.${4} return 0 } diff --git a/core/c/jbigi/mbuild_jbigi.sh b/core/c/jbigi/mbuild_jbigi.sh deleted file mode 100755 index 4b05dc4f3c..0000000000 --- a/core/c/jbigi/mbuild_jbigi.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/bin/sh -# When executed in Mingw: Produces a jbigi.dll -# When executed in Linux/FreeBSD: Produces a libjbigi.so -# When executed in OSX: Produces a libjbigi.jnilib -CC="gcc" - -case `uname -s` in -MINGW*) - JAVA_HOME="c:/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" - LINKFLAGS="-shared -Wl,--kill-at" - LIBFILE="jbigi.dll";; -CYGWIN*) - JAVA_HOME="c:/software/j2sdk1.4.2_05" - COMPILEFLAGS="-Wall -mno-cygwin" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include/win32/ -I$JAVA_HOME/include/" - LINKFLAGS="-shared -Wl,--kill-at" - LIBFILE="jbigi.dll";; -Darwin*) - JAVA_HOME=$(/usr/libexec/java_home) - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include" - LINKFLAGS="-dynamiclib -framework JavaVM" - LIBFILE="libjbigi.jnilib";; -SunOS*|OpenBSD*|NetBSD*|FreeBSD*|Linux*) - UNIXTYPE=$(uname -s | tr "[A-Z]" "[a-z]") - if [ $UNIXTYPE = "sunos" ]; then - UNIXTYPE="solaris" - elif [ $UNIXTYPE = "freebsd" ]; then - if [ -d /usr/local/openjdk6 ]; then - JAVA_HOME="/usr/local/openjdk6" - elif [ -d /usr/local/openjdk7 ]; then - JAVA_HOME="/usr/local/openjdk7" - fi - elif [ $UNIXTYPE = "openbsd" ]; then - if [ -d /usr/local/jdk-1.7.0 ]; then - JAVA_HOME="/usr/local/jdk-1.7.0" - fi - elif [ $UNIXTYPE = "netbsd" ]; then - if [ -d /usr/pkg/java/openjdk7 ]; then - JAVA_HOME="/usr/pkg/java/openjdk7" - fi - elif [ $UNIXTYPE = "linux" ] && [ -e /etc/debian_version ]; then - if [ -d /usr/lib/jvm/default-java ]; then - JAVA_HOME="/usr/lib/jvm/default-java" - fi - fi - COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/${UNIXTYPE}" - LINKFLAGS="-shared -Wl,-soname,libjbigi.so" - LIBFILE="libjbigi.so";; -*) - echo "Unsupported system type." - exit 1;; -esac - -if [ "$1" = "dynamic" ] ; then - echo "Building a jbigi lib that is dynamically linked to GMP" - LIBPATH="-L.libs" - INCLUDELIBS="-lgmp" -else - echo "Building a jbigi lib that is statically linked to GMP" - STATICLIBS=".libs/libgmp.a" -fi - -echo "Compiling C code..." -rm -f jbigi.o $LIBFILE -$CC -c $COMPILEFLAGS $INCLUDES ../../jbigi/src/jbigi.c || exit 1 -$CC $LINKFLAGS $INCLUDES -o $LIBFILE jbigi.o $INCLUDELIBS $STATICLIBS || exit 1 - -exit 0 diff --git a/debian/patches/0002-jbigi-soname.patch b/debian/patches/0002-jbigi-soname.patch index f38d5fb89d..09085deb6e 100644 --- a/debian/patches/0002-jbigi-soname.patch +++ b/debian/patches/0002-jbigi-soname.patch @@ -2,18 +2,18 @@ From: Kill Your TV Date: Wed, 11 May 2011 00:12:04 +0000 Subject: jbigi soname -The purpose of this patch is to change the path that mbuild_jbigi.sh +The purpose of this patch is to change the path that build_jbigi.sh expects to find the source files at. At the same time I'm specifying a soname to shut lintian up. --- - core/c/jbigi/mbuild_jbigi.sh | 6 +++--- - 1 files changed, 3 insertions(+), 3 deletions(-) + core/c/jbigi/build_jbigi.sh | 4 +++--- + 1 files changed, 2 insertions(+), 2 deletions(-) ---- a/core/c/jbigi/mbuild_jbigi.sh -+++ b/core/c/jbigi/mbuild_jbigi.sh -@@ -47,7 +47,7 @@ - fi +--- a/core/c/jbigi/build_jbigi.sh ++++ b/core/c/jbigi/build_jbigi.sh +@@ -37,7 +37,7 @@ + UNIXTYPE="solaris" fi COMPILEFLAGS="-fPIC -Wall" - INCLUDES="-I. -I../../jbigi/include -I$JAVA_HOME/include -I$JAVA_HOME/include/${UNIXTYPE}" @@ -21,7 +21,7 @@ a soname to shut lintian up. LINKFLAGS="-shared -Wl,-soname,libjbigi.so" LIBFILE="libjbigi.so";; *) -@@ -66,7 +66,7 @@ +@@ -56,7 +56,7 @@ echo "Compiling C code..." rm -f jbigi.o $LIBFILE From 0f62383aecbbe5d9e9ee394b237bbb4815c748fa Mon Sep 17 00:00:00 2001 From: kytv Date: Sun, 8 Jan 2012 23:25:36 +0000 Subject: [PATCH 06/12] Reference /etc/i2p/wrapper.config when OOM when using Debian packages When I2P terminates with an OOM error, users are advised to update $I2P/wrapper.config. That path isn't accurate for the Debian packages. --- debian/patches/0004-oom-listener.patch | 11 +++++++++++ debian/patches/series | 1 + 2 files changed, 12 insertions(+) create mode 100644 debian/patches/0004-oom-listener.patch diff --git a/debian/patches/0004-oom-listener.patch b/debian/patches/0004-oom-listener.patch new file mode 100644 index 0000000000..f803b8d9ef --- /dev/null +++ b/debian/patches/0004-oom-listener.patch @@ -0,0 +1,11 @@ +--- a/router/java/src/net/i2p/router/tasks/OOMListener.java ++++ b/router/java/src/net/i2p/router/tasks/OOMListener.java +@@ -33,7 +33,7 @@ + // gobble + } + } +- log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in $I2P/wrapper.config"); ++ log.log(Log.CRIT, "To prevent future shutdowns, increase wrapper.java.maxmemory in /etc/i2p/wrapper.config"); + _context.router().shutdown(Router.EXIT_OOM); + } + } diff --git a/debian/patches/series b/debian/patches/series index a289a6ae12..32c3c507a6 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -1,3 +1,4 @@ 0001-path-substitution.patch 0002-jbigi-soname.patch 0003-renaming-jcpuid.patch +0004-oom-listener.patch From 5fd6698d0536e207a7c0e40e24e61665294d0a6c Mon Sep 17 00:00:00 2001 From: kytv Date: Sun, 8 Jan 2012 23:26:39 +0000 Subject: [PATCH 07/12] Refresh patch due to wrapper.config additions --- debian/patches/0001-path-substitution.patch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/debian/patches/0001-path-substitution.patch b/debian/patches/0001-path-substitution.patch index dcbce0253a..f6b6c93107 100644 --- a/debian/patches/0001-path-substitution.patch +++ b/debian/patches/0001-path-substitution.patch @@ -105,7 +105,7 @@ Debian wrapper.config to try to prevent confusion. # Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode. wrapper.java.additional.auto_bits=TRUE -@@ -69,7 +61,7 @@ +@@ -71,7 +63,7 @@ wrapper.java.additional.1=-DloggerFilenameOverride=logs/log-router-@.txt wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true wrapper.java.additional.3=-Dorg.mortbay.xml.XmlParser.NotValidating=true @@ -114,7 +114,7 @@ Debian wrapper.config to try to prevent confusion. wrapper.java.additional.4.stripquotes=TRUE # On some IPv6 enabled systems, I2P and other network-enabled java applications -@@ -139,11 +131,7 @@ +@@ -141,11 +133,7 @@ # tell the router where to find the wrapper log # (change X to the next available number) # wrapper.java.additional.X=-Dwrapper.logfile=/path/to/wrapper.log @@ -127,7 +127,7 @@ Debian wrapper.config to try to prevent confusion. # Format of output for the log file. # The format consists of the tokens 'L' for log level, 'P' for prefix, 'D' for thread, -@@ -205,10 +193,7 @@ +@@ -211,10 +199,7 @@ # you should copy this file, change the location or file name, # and edit the i2prouter script to change the WRAPPER_CONF setting # to point to the new wrapper.config location. @@ -139,7 +139,7 @@ Debian wrapper.config to try to prevent confusion. # pid file for the service monitoring the JVM # # From i2prouter: -@@ -219,10 +204,7 @@ +@@ -225,10 +210,7 @@ # # This means i2prouter looks for './i2p.pid'. # See comments above for wrapper.java.pidfile @@ -151,7 +151,7 @@ Debian wrapper.config to try to prevent confusion. #******************************************************************** # Wrapper General Properties -@@ -239,30 +221,3 @@ +@@ -245,30 +227,3 @@ wrapper.umask=0022 wrapper.java.umask=0022 wrapper.logfile.umask=077 From ce27d69e39d14c19ca8ead6e00ba26f908802ed1 Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 9 Jan 2012 23:57:17 +0000 Subject: [PATCH 08/12] - Add info to error 500 page --- apps/routerconsole/jsp/error500.jsp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/routerconsole/jsp/error500.jsp b/apps/routerconsole/jsp/error500.jsp index c4af35bb1f..56ebe9b177 100644 --- a/apps/routerconsole/jsp/error500.jsp +++ b/apps/routerconsole/jsp/error500.jsp @@ -55,9 +55,14 @@

I2P version: <%=net.i2p.router.RouterVersion.FULL_VERSION%>
Java version: <%=System.getProperty("java.vendor")%> <%=System.getProperty("java.version")%> (<%=System.getProperty("java.runtime.name")%> <%=System.getProperty("java.runtime.version")%>)
+Wrapper version: <%=System.getProperty("wrapper.version", "none")%>
+ + " /> +Server version:
Platform: <%=System.getProperty("os.name")%> <%=System.getProperty("os.arch")%> <%=System.getProperty("os.version")%>
Processor: <%=net.i2p.util.NativeBigInteger.cpuModel()%> (<%=net.i2p.util.NativeBigInteger.cpuType()%>)
Jbigi: <%=net.i2p.util.NativeBigInteger.loadStatus()%>
-Encoding: <%=System.getProperty("file.encoding")%>

+Encoding: <%=System.getProperty("file.encoding")%>
+Charset: <%=java.nio.charset.Charset.defaultCharset().name()%>

<%=intl._("Note that system information, log timestamps, and log messages may provide clues to your location; please review everything you include in a bug report.")%>

From 352c6ba4ba6e5154817a3260d72051da82d284a6 Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 9 Jan 2012 23:58:24 +0000 Subject: [PATCH 09/12] * i2prouter: Don't attempt to translate strings from script --- installer/resources/i2prouter | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/installer/resources/i2prouter b/installer/resources/i2prouter index eb9c476f68..6ee350140e 100644 --- a/installer/resources/i2prouter +++ b/installer/resources/i2prouter @@ -461,10 +461,13 @@ fi gettext() { - "$WRAPPER_CMD" --translate "$1" "$WRAPPER_CONF" 2>/dev/null - if [ $? != 0 ] ; then + # TODO provide translations and call external gettext. + # For now, don't attempt to translate via the wrapper, + # it probably isn't supported in the community edition. + #"$WRAPPER_CMD" --translate "$1" "$WRAPPER_CONF" 2>/dev/null + #if [ $? != 0 ] ; then echo "$1" - fi + #fi } outputFile() { From ad4d73ea0d062f458245cadfb7892d3e63455b9c Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 9 Jan 2012 23:59:58 +0000 Subject: [PATCH 10/12] - Fix class error on wrapper 3.1.1 --- .../i2p/router/web/ConfigServiceHandler.java | 74 +++------------ .../net/i2p/router/web/WrapperListener.java | 89 +++++++++++++++++++ 2 files changed, 103 insertions(+), 60 deletions(-) create mode 100644 apps/routerconsole/java/src/net/i2p/router/web/WrapperListener.java diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java index cf15fee894..3d5797cf2d 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigServiceHandler.java @@ -8,12 +8,9 @@ import net.i2p.apps.systray.UrlLauncher; import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.router.startup.ClientAppConfig; -import net.i2p.util.Log; +import net.i2p.util.VersionComparator; import org.tanukisoftware.wrapper.WrapperManager; -import org.tanukisoftware.wrapper.event.WrapperControlEvent; -import org.tanukisoftware.wrapper.event.WrapperEvent; -import org.tanukisoftware.wrapper.event.WrapperEventListener; /** * Handler to deal with form submissions from the service config form and act @@ -22,9 +19,9 @@ import org.tanukisoftware.wrapper.event.WrapperEventListener; */ public class ConfigServiceHandler extends FormHandler { - private static WrapperEventListener _signalHandler; + private static WrapperListener _wrapperListener; - private static final String PROP_GRACEFUL_HUP = "router.gracefulHUP"; + private static final String LISTENER_AVAILABLE = "3.2.0"; /** * Register two shutdown hooks, one to rekey and/or tell the wrapper we are stopping, @@ -137,16 +134,19 @@ public class ConfigServiceHandler extends FormHandler { /** * Register a handler for signals, - * so we can handle HUP from the wrapper (non-Windows only) + * so we can handle HUP from the wrapper (non-Windows only, wrapper 3.2.0 or higher) * * @since 0.8.13 */ synchronized static void registerSignalHandler(RouterContext ctx) { - if (ctx.hasWrapper() && _signalHandler == null && + if (ctx.hasWrapper() && _wrapperListener == null && !System.getProperty("os.name").startsWith("Win")) { - _signalHandler = new SignalHandler(ctx); - long mask = WrapperEventListener.EVENT_FLAG_CONTROL; - WrapperManager.addWrapperEventListener(_signalHandler, mask); + String wv = System.getProperty("wrapper.version"); + if (wv != null && (new VersionComparator()).compare(wv, LISTENER_AVAILABLE) >= 0) { + try { + _wrapperListener = new WrapperListener(ctx); + } catch (Throwable t) {} + } } } @@ -156,55 +156,9 @@ public class ConfigServiceHandler extends FormHandler { * @since 0.8.13 */ public synchronized static void unregisterSignalHandler() { - if (_signalHandler != null) { - WrapperManager.removeWrapperEventListener(_signalHandler); - _signalHandler = null; - } - } - - /** - * Catch signals. - * The wrapper will potentially forward HUP, USR1, and USR2. - * But USR1 and USR2 are used by the JVM GC and cannot be trapped. - * So we will only get HUP. - * - * @since 0.8.13 - */ - private static class SignalHandler implements WrapperEventListener { - private final RouterContext _ctxt; - - public SignalHandler(RouterContext ctx) { - _ctxt = ctx; - } - - public void fired(WrapperEvent event) { - if (!(event instanceof WrapperControlEvent)) - return; - WrapperControlEvent wce = (WrapperControlEvent) event; - Log log = _ctxt.logManager().getLog(ConfigServiceHandler.class); - if (log.shouldLog(Log.WARN)) - log.warn("Got signal: " + wce.getControlEventName()); - int sig = wce.getControlEvent(); - switch (sig) { - case WrapperManager.WRAPPER_CTRL_HUP_EVENT: - if (_ctxt.getBooleanProperty(PROP_GRACEFUL_HUP)) { - wce.consume(); - if (!(_ctxt.router().gracefulShutdownInProgress() || - _ctxt.router().isFinalShutdownInProgress())) { - System.err.println("WARN: Graceful shutdown initiated by SIGHUP"); - log.logAlways(Log.WARN, "Graceful shutdown initiated by SIGHUP"); - registerWrapperNotifier(_ctxt, Router.EXIT_GRACEFUL, false); - _ctxt.router().shutdownGracefully(); - } - } else { - log.log(Log.CRIT, "Hard shutdown initiated by SIGHUP"); - // JVM will call ShutdownHook if we don't do it ourselves - //wce.consume(); - //registerWrapperNotifier(_ctxt, Router.EXIT_HARD, false); - //_ctxt.router().shutdown(Router.EXIT_HARD); - } - break; - } + if (_wrapperListener != null) { + _wrapperListener.unregister(); + _wrapperListener = null; } } diff --git a/apps/routerconsole/java/src/net/i2p/router/web/WrapperListener.java b/apps/routerconsole/java/src/net/i2p/router/web/WrapperListener.java new file mode 100644 index 0000000000..a2bfd4dbf7 --- /dev/null +++ b/apps/routerconsole/java/src/net/i2p/router/web/WrapperListener.java @@ -0,0 +1,89 @@ +package net.i2p.router.web; + +import net.i2p.router.Router; +import net.i2p.router.RouterContext; +import net.i2p.util.Log; + +import org.tanukisoftware.wrapper.WrapperManager; +import org.tanukisoftware.wrapper.event.WrapperControlEvent; +import org.tanukisoftware.wrapper.event.WrapperEvent; +import org.tanukisoftware.wrapper.event.WrapperEventListener; + +/** + * Listen for events. Requires wrapper 3.2.0 or higher. + * Hides the actual listener so that + * ConfigServiceHandler can have a static field and not die on + * class not found error with wrapper 3.1.1. + * + * @since 0.8.13 + */ +class WrapperListener { + private final RouterContext _context; + private final WrapperEventListener _listener; + + private static final String PROP_GRACEFUL_HUP = "router.gracefulHUP"; + + /** + * Wrapper must be 3.2.0 or higher, or will throw class not found error. + * Registers with the wrapper in the constructor. + */ + public WrapperListener(RouterContext ctx) { + _context = ctx; + _listener = new SignalHandler(ctx); + long mask = WrapperEventListener.EVENT_FLAG_CONTROL; + WrapperManager.addWrapperEventListener(_listener, mask); + } + + /** + * Unregister the handler for signals + */ + public void unregister() { + WrapperManager.removeWrapperEventListener(_listener); + } + + /** + * Catch signals. + * The wrapper will potentially forward HUP, USR1, and USR2. + * But USR1 and USR2 are used by the JVM GC and cannot be trapped. + * So we will only get HUP. + * + * @since 0.8.13 + */ + private static class SignalHandler implements WrapperEventListener { + private final RouterContext _ctxt; + + public SignalHandler(RouterContext ctx) { + _ctxt = ctx; + } + + public void fired(WrapperEvent event) { + if (!(event instanceof WrapperControlEvent)) + return; + WrapperControlEvent wce = (WrapperControlEvent) event; + Log log = _ctxt.logManager().getLog(ConfigServiceHandler.class); + if (log.shouldLog(Log.WARN)) + log.warn("Got signal: " + wce.getControlEventName()); + int sig = wce.getControlEvent(); + switch (sig) { + case WrapperManager.WRAPPER_CTRL_HUP_EVENT: + if (_ctxt.getBooleanPropertyDefaultTrue(PROP_GRACEFUL_HUP)) { + wce.consume(); + if (!(_ctxt.router().gracefulShutdownInProgress() || + _ctxt.router().isFinalShutdownInProgress())) { + System.err.println("WARN: Graceful shutdown initiated by SIGHUP"); + log.logAlways(Log.WARN, "Graceful shutdown initiated by SIGHUP"); + ConfigServiceHandler.registerWrapperNotifier(_ctxt, Router.EXIT_GRACEFUL, false); + _ctxt.router().shutdownGracefully(); + } + } else { + log.log(Log.CRIT, "Hard shutdown initiated by SIGHUP"); + // JVM will call ShutdownHook if we don't do it ourselves + //wce.consume(); + //registerWrapperNotifier(_ctxt, Router.EXIT_HARD, false); + //_ctxt.router().shutdown(Router.EXIT_HARD); + } + break; + } + } + } +} From c6e6a9d36e72d0f12360253e7301aace5c44c837 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 10 Jan 2012 00:02:20 +0000 Subject: [PATCH 11/12] - Add indication on summary bar when in VM comm system --- .../java/src/net/i2p/router/web/SummaryHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java index aa633e65df..5ac51b7a3c 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/SummaryHelper.java @@ -101,6 +101,8 @@ public class SummaryHelper extends HelperBase { } private String reachability() { + if (_context.commSystem().isDummy()) + return "VM Comm System"; if (_context.router().getUptime() > 60*1000 && (!_context.router().gracefulShutdownInProgress()) && !_context.clientManager().isAlive()) return _("ERR-Client Manager I2CP Error - check logs"); // not a router problem but the user should know @@ -180,6 +182,7 @@ public class SummaryHelper extends HelperBase { return _context != null && _context.netDb().isInitialized() && _context.router().getUptime() > 2*60*1000 && + (!_context.commSystem().isDummy()) && _context.commSystem().countActivePeers() <= 0 && _context.netDb().getKnownRouters() > 5; } From 4ad6d699e702ff7c3f4ba01217107fa450bb47e3 Mon Sep 17 00:00:00 2001 From: zzz Date: Tue, 10 Jan 2012 00:05:17 +0000 Subject: [PATCH 12/12] * Router: - Auto-hidden mode for bad countries - Don't put addresses in our RouterInfo when hidden --- .../net/i2p/router/web/ConfigNetHandler.java | 3 +- apps/routerconsole/jsp/confignet.jsp | 1 + history.txt | 11 ++++ .../src/net/i2p/router/CommSystemFacade.java | 8 +++ router/java/src/net/i2p/router/Router.java | 14 ++-- .../src/net/i2p/router/RouterVersion.java | 2 +- .../i2p/router/transport/BadCountries.java | 65 +++++++++++++++++++ .../transport/CommSystemFacadeImpl.java | 16 +++++ .../src/net/i2p/router/transport/GeoIP.java | 9 +++ 9 files changed, 123 insertions(+), 6 deletions(-) create mode 100644 router/java/src/net/i2p/router/transport/BadCountries.java diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java b/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java index 56a2299e4b..8f9a20749c 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ConfigNetHandler.java @@ -140,7 +140,8 @@ public class ConfigNetHandler extends FormHandler { if (!_ratesOnly) { // IP Settings - String oldUdp = _context.getProperty(UDPTransport.PROP_SOURCES, UDPTransport.DEFAULT_SOURCES); + String oldUdp = _context.getProperty(UDPTransport.PROP_SOURCES, + _context.router().isHidden() ? "hidden" : UDPTransport.DEFAULT_SOURCES); String oldUHost = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST, ""); if (_udpAutoIP != null) { String uhost = ""; diff --git a/apps/routerconsole/jsp/confignet.jsp b/apps/routerconsole/jsp/confignet.jsp index 78dd68fda6..e67f6fe3ae 100644 --- a/apps/routerconsole/jsp/confignet.jsp +++ b/apps/routerconsole/jsp/confignet.jsp @@ -157,6 +157,7 @@ <%=intl._("The router is currently testing whether your UDP port is firewalled.")%>
  • <%=intl._("Hidden")%> - <%=intl._("The router is not configured to publish its address, therefore it does not expect incoming connections.")%> + <%=intl._("Hidden mode is automatically enabled for added protection in certain countries.")%>
  • <%=intl._("WARN - Firewalled and Fast")%> - <%=intl._("You have configured I2P to share more than 128KBps of bandwidth, but you are firewalled.")%> <%=intl._("While I2P will work fine in this configuration, if you really have over 128KBps of bandwidth to share, it will be much more helpful to the network if you open your firewall.")%> diff --git a/history.txt b/history.txt index cf153fc660..60c210c2ac 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,14 @@ +2012-01-10 zzz + * Console: + - Add info to error 500 page + - Add indication on summary bar when in VM comm system + - Make graceful the default for HUP (ticket #580) + - Fix class error on wrapper 3.1.1 + * i2prouter: Don't attempt to translate strings from script + * Router: + - Auto-hidden mode for bad countries + - Don't put addresses in our RouterInfo when hidden + 2012-01-08 zzz * Plugins: - Enforce min and max Jetty versions at plugin installation diff --git a/router/java/src/net/i2p/router/CommSystemFacade.java b/router/java/src/net/i2p/router/CommSystemFacade.java index f9644f388e..9bc1ae5356 100644 --- a/router/java/src/net/i2p/router/CommSystemFacade.java +++ b/router/java/src/net/i2p/router/CommSystemFacade.java @@ -61,14 +61,22 @@ public abstract class CommSystemFacade implements Service { public boolean isEstablished(Hash dest) { return false; } public byte[] getIP(Hash dest) { return null; } public void queueLookup(byte[] ip) {} + /** @since 0.8.11 */ public String getOurCountry() { return null; } + + /** @since 0.8.13 */ + public boolean isInBadCountry() { return false; } + public String getCountry(Hash peer) { return null; } public String getCountryName(String code) { return code; } public String renderPeerHTML(Hash peer) { return peer.toBase64().substring(0, 4); } + /** @since 0.8.13 */ + public boolean isDummy() { return true; } + /** * Tell other transports our address changed */ diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index 0e95d8c6eb..084731b7bb 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -241,8 +241,6 @@ public class Router implements RouterClock.ClockShiftListener { String now = Long.toString(System.currentTimeMillis()); _config.put("router.firstInstalled", now); _config.put("router.updateLastInstalled", now); - // only compatible with new i2prouter script - _config.put("router.gracefulHUP", "true"); saveConfig(); } // ********* Start no threads before here ********* // @@ -592,14 +590,22 @@ public class Router implements RouterClock.ClockShiftListener { RouterInfo ri = _routerInfo; if ( (ri != null) && (ri.isHidden()) ) return true; - return _context.getBooleanProperty(PROP_HIDDEN_HIDDEN); + String h = _context.getProperty(PROP_HIDDEN_HIDDEN); + if (h != null) + return Boolean.valueOf(h).booleanValue(); + return _context.commSystem().isInBadCountry(); } /** + * Only called at startup via LoadRouterInfoJob and RebuildRouterInfoJob. + * Not called by periodic RepublishLocalRouterInfoJob. + * We don't want to change the cert on the fly as it changes the router hash. + * RouterInfo.isHidden() checks the capability, but RouterIdentity.isHidden() checks the cert. + * There's no reason to ever add a hidden cert? * @return the certificate for a new RouterInfo - probably a null cert. */ public Certificate createCertificate() { - if (isHidden()) + if (_context.getBooleanProperty(PROP_HIDDEN)) return new Certificate(Certificate.CERTIFICATE_TYPE_HIDDEN, null); return Certificate.NULL_CERT; } diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 87e5bffca0..282c18b422 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 1; + public final static long BUILD = 2; /** for example "-test" */ public final static String EXTRA = ""; diff --git a/router/java/src/net/i2p/router/transport/BadCountries.java b/router/java/src/net/i2p/router/transport/BadCountries.java new file mode 100644 index 0000000000..1431dcb60f --- /dev/null +++ b/router/java/src/net/i2p/router/transport/BadCountries.java @@ -0,0 +1,65 @@ +package net.i2p.router.transport; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Locale; +import java.util.Set; + +/** + * Maintain a list of bad places. + * @since 0.8.13 + */ +abstract class BadCountries { + + private static final Set _countries; + + // zzz.i2p/topics/969 + // List created based on the Press Freedom Index. Those countries with a score of higher than 50 are included: + // http://en.wikipedia.org/wiki/Press_Freedom_Index + // Except: + // I don't really think that is usage of I2P is dangerous in countries from CIS + // General situation is really bad (like in Russia) but people here doesn't have problems with Ecnryption usage. + + static { + String[] c = { + /* Afghanistan */ "AF", + /* Bahrain */ "BH", + /* Brunei */ "BN", + /* Burma */ "MM", + /* China */ "CN", + /* Colombia */ "CO", + /* Cuba */ "CU", + /* Democratic Republic of the Congo */ "CD", + /* Equatorial Guinea */ "GQ", + /* Eritrea */ "ER", + /* Fiji */ "FJ", + /* Honduras */ "HN", + /* Iran */ "IR", + /* Laos */ "LA", + /* Libya */ "LY", + /* Malaysia */ "MY", + /* Nigeria */ "NG", + /* North Korea */ "KP", + /* Pakistan */ "PK", + /* Palestinian Territories */ "PS", + /* Philippines */ "PH", + /* Rwanda */ "RW", + /* Saudi Arabia */ "SA", + /* Somalia */ "SO", + /* Sri Lanka */ "LK", + /* Sudan */ "SD", + /* Swaziland */ "SZ", + /* Syria */ "SY", + /* Thailand */ "TH", + /* Tunisia */ "TN", + /* Vietnam */ "VN", + /* Yemen */ "YE" + }; + _countries = new HashSet(Arrays.asList(c)); + } + + /** @param country non-null, two letter code, case-independent */ + public static boolean contains(String country) { + return _countries.contains(country.toUpperCase(Locale.US)); + } +} diff --git a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java index f4ddab5e44..c1302b9aa5 100644 --- a/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java +++ b/router/java/src/net/i2p/router/transport/CommSystemFacadeImpl.java @@ -176,8 +176,11 @@ public class CommSystemFacadeImpl extends CommSystemFacade { _manager.renderStatusHTML(out, urlBase, sortFlags); } + /** @return non-null, possibly empty */ @Override public Set createAddresses() { + if (_context.router().isHidden()) + return Collections.EMPTY_SET; Map addresses = null; boolean newCreated = false; @@ -450,6 +453,15 @@ public class CommSystemFacadeImpl extends CommSystemFacade { return _context.getProperty(GeoIP.PROP_IP_COUNTRY); } + /** + * Are we in a bad place + * @since 0.8.13 + */ + public boolean isInBadCountry() { + String us = getOurCountry(); + return us != null && (BadCountries.contains(us) || _context.getBooleanProperty("router.forceBadCountry")); + } + /** * Uses the transport IP first because that lookup is fast, * then the SSU IP from the netDb. @@ -517,6 +529,10 @@ public class CommSystemFacadeImpl extends CommSystemFacade { return buf.toString(); } + /** @since 0.8.13 */ + @Override + public boolean isDummy() { return false; } + /** * Translate */ diff --git a/router/java/src/net/i2p/router/transport/GeoIP.java b/router/java/src/net/i2p/router/transport/GeoIP.java index a8c8d04df4..8a97a1f5f3 100644 --- a/router/java/src/net/i2p/router/transport/GeoIP.java +++ b/router/java/src/net/i2p/router/transport/GeoIP.java @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import net.i2p.I2PAppContext; import net.i2p.data.DataHelper; import net.i2p.data.Hash; +import net.i2p.router.Router; import net.i2p.router.RouterContext; import net.i2p.util.ConcurrentHashSet; import net.i2p.util.Log; @@ -283,6 +284,14 @@ class GeoIP { if (country != null && !country.equals(oldCountry)) { _context.router().setConfigSetting(PROP_IP_COUNTRY, country); _context.router().saveConfig(); + if (_context.commSystem().isInBadCountry() && _context.getProperty(Router.PROP_HIDDEN_HIDDEN) == null) { + String name = fullName(country); + if (name == null) + name = country; + _log.logAlways(Log.WARN, "Setting hidden mode to protect you in " + name + + ", you may override on the network configuration page"); + _context.router().rebuildRouterInfo(); + } } /****/ }