jbigi: Save and report extracted library name

This commit is contained in:
zzz
2014-10-28 14:50:40 +00:00
parent 0f2affd414
commit 798275608e
2 changed files with 28 additions and 2 deletions

View File

@@ -96,9 +96,11 @@ import net.i2p.crypto.CryptoConstants;
*/ */
public class NativeBigInteger extends BigInteger { public class NativeBigInteger extends BigInteger {
/** did we load the native lib correctly? */ /** did we load the native lib correctly? */
private static boolean _nativeOk = false; private static boolean _nativeOk;
private static String _loadStatus = "uninitialized"; private static String _loadStatus = "uninitialized";
private static String _cpuModel = "uninitialized"; private static String _cpuModel = "uninitialized";
private static String _extractedResource;
/** /**
* do we want to dump some basic success/failure info to stderr during * do we want to dump some basic success/failure info to stderr during
* initialization? this would otherwise use the Log component, but this makes * initialization? this would otherwise use the Log component, but this makes
@@ -340,10 +342,24 @@ public class NativeBigInteger extends BigInteger {
return _nativeOk; return _nativeOk;
} }
/**
* @return A string suitable for display to the user
*/
public static String loadStatus() { public static String loadStatus() {
return _loadStatus; return _loadStatus;
} }
/**
* The name of the library loaded, if known.
* Null if unknown or not loaded.
* Currently non-null only if extracted from jbigi.jar.
*
* @since 0.9.17
*/
public static String getLoadedResourceName() {
return _extractedResource;
}
public static String cpuType() { public static String cpuType() {
if (sCPUType != null) if (sCPUType != null)
return sCPUType; return sCPUType;
@@ -459,6 +475,10 @@ public class NativeBigInteger extends BigInteger {
boolean loaded = loadGeneric("jbigi"); boolean loaded = loadGeneric("jbigi");
if (loaded) { if (loaded) {
_nativeOk = true; _nativeOk = true;
String s = I2PAppContext.getGlobalContext().getProperty("jbigi.loadedResource");
if (s != null)
info("Locally optimized library " + s + " loaded from file");
else
info("Locally optimized native BigInteger library loaded from file"); info("Locally optimized native BigInteger library loaded from file");
} else { } else {
List<String> toTry = getResourceList(); List<String> toTry = getResourceList();
@@ -467,6 +487,7 @@ public class NativeBigInteger extends BigInteger {
debug("trying loadResource " + s); debug("trying loadResource " + s);
if (loadFromResource(s)) { if (loadFromResource(s)) {
_nativeOk = true; _nativeOk = true;
_extractedResource = s;
info("Native BigInteger library " + s + " loaded from resource"); info("Native BigInteger library " + s + " loaded from resource");
break; break;
} }

View File

@@ -49,6 +49,7 @@ import net.i2p.util.FortunaRandomSource;
import net.i2p.util.I2PAppThread; import net.i2p.util.I2PAppThread;
import net.i2p.util.I2PThread; import net.i2p.util.I2PThread;
import net.i2p.util.Log; import net.i2p.util.Log;
import net.i2p.util.NativeBigInteger;
import net.i2p.util.OrderedProperties; import net.i2p.util.OrderedProperties;
import net.i2p.util.SecureFileOutputStream; import net.i2p.util.SecureFileOutputStream;
import net.i2p.util.SimpleByteCache; import net.i2p.util.SimpleByteCache;
@@ -102,6 +103,7 @@ public class Router implements RouterClock.ClockShiftListener {
public final static String PROP_SHUTDOWN_IN_PROGRESS = "__shutdownInProgress"; public final static String PROP_SHUTDOWN_IN_PROGRESS = "__shutdownInProgress";
public final static String DNS_CACHE_TIME = "" + (5*60); public final static String DNS_CACHE_TIME = "" + (5*60);
private static final String EVENTLOG = "eventlog.txt"; private static final String EVENTLOG = "eventlog.txt";
private static final String PROP_JBIGI = "jbigi.loadedResource";
private static final String originalTimeZoneID; private static final String originalTimeZoneID;
static { static {
@@ -750,6 +752,9 @@ public class Router implements RouterClock.ClockShiftListener {
_context.random().nextBoolean(); _context.random().nextBoolean();
// Instantiate to fire up the YK refiller thread // Instantiate to fire up the YK refiller thread
_context.elGamalEngine(); _context.elGamalEngine();
String loaded = NativeBigInteger.getLoadedResourceName();
if (loaded != null)
saveConfig(PROP_JBIGI, loaded);
} }
private void startupQueue() { private void startupQueue() {