forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p' (head 5d56a7eb371dddb9336e596bda69f99c91294b05)
to branch 'i2p.i2p.str4d.ui' (head 3aeafcdb5c0ffbc9c77f574558f8438d3e81133e)
This commit is contained in:
@@ -453,6 +453,30 @@ class AMDInfoImpl extends CPUIDCPUInfo implements AMDCPUInfo
|
||||
modelString = "Jaguar";
|
||||
}
|
||||
break;
|
||||
|
||||
//Ryzen 7 (model 1), Ryzen 5 TBD
|
||||
// untested
|
||||
case 23: {
|
||||
// Quote wikipedia:
|
||||
// Zen is a clean sheet design that differs from the long-standing Bulldozer architecture.
|
||||
// All models support: x87, MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, AES, CLMUL,
|
||||
// AVX, AVX2, FMA, CVT16/F16C, ABM, BMI1, BMI2, SHA.
|
||||
isK6Compatible = true;
|
||||
isK6_2_Compatible = true;
|
||||
isK6_3_Compatible = true;
|
||||
isAthlonCompatible = true;
|
||||
isAthlon64Compatible = true;
|
||||
// Pending testing of the bulldozer jbigi
|
||||
//isPiledriverCompatible = true;
|
||||
//isSteamrollerCompatible = true;
|
||||
//isExcavatorCompatible = true;
|
||||
//isBulldozerCompatible = true;
|
||||
if (model == 1)
|
||||
modelString = "Ryzen 7";
|
||||
else
|
||||
modelString = "Ryzen model " + model;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return modelString;
|
||||
}
|
||||
|
||||
@@ -51,11 +51,8 @@ public class CPUID {
|
||||
private static boolean _doLog = System.getProperty("jcpuid.dontLog") == null &&
|
||||
I2PAppContext.getGlobalContext().isRouterContext();
|
||||
|
||||
private static final boolean isX86 = System.getProperty("os.arch").contains("86") ||
|
||||
System.getProperty("os.arch").equals("amd64");
|
||||
private static final boolean isX86 = SystemVersion.isX86();
|
||||
private static final boolean isWindows = SystemVersion.isWindows();
|
||||
private static final String libPrefix = isWindows ? "" : "lib";
|
||||
private static final String libSuffix = isWindows ? ".dll" : ".so";
|
||||
private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
|
||||
private static final boolean isKFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("kfreebsd");
|
||||
private static final boolean isFreebsd = (!isKFreebsd) && System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
|
||||
@@ -304,13 +301,15 @@ public class CPUID {
|
||||
*/
|
||||
public static CPUInfo getInfo() throws UnknownCPUException
|
||||
{
|
||||
if(!_nativeOk)
|
||||
throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the jcpuid dll/so.");
|
||||
if(!_nativeOk) {
|
||||
throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the " +
|
||||
getLibraryPrefix() + "jcpuid " + getLibrarySuffix() + " file.");
|
||||
}
|
||||
String id = getCPUVendorID();
|
||||
if(id.equals("CentaurHauls"))
|
||||
return new VIAInfoImpl();
|
||||
if(!isX86)
|
||||
throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPU's only");
|
||||
throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPUs only.");
|
||||
if(id.equals("AuthenticAMD"))
|
||||
return new AMDInfoImpl();
|
||||
if(id.equals("GenuineIntel"))
|
||||
@@ -321,9 +320,23 @@ public class CPUID {
|
||||
|
||||
public static void main(String args[])
|
||||
{
|
||||
_doLog = true;
|
||||
if(!_nativeOk){
|
||||
System.out.println("**Failed to retrieve CPUInfo. Please verify the existence of jcpuid dll/so**");
|
||||
_doLog = true; // this is too late to log anything from above
|
||||
String path = System.getProperty("java.library.path");
|
||||
String name = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
|
||||
System.out.println("Native library search path: " + path);
|
||||
if (_nativeOk) {
|
||||
String sep = System.getProperty("path.separator");
|
||||
String[] paths = DataHelper.split(path, sep);
|
||||
for (String p : paths) {
|
||||
File f = new File(p, name);
|
||||
if (f.exists()) {
|
||||
System.out.println("Found native library: " + f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Failed to retrieve CPUInfo. Please verify the existence of the " +
|
||||
name + " file in the library path, or set -Djava.library.path=. in the command line");
|
||||
}
|
||||
System.out.println("JCPUID Version: " + _jcpuidVersion);
|
||||
System.out.println(" **CPUInfo**");
|
||||
@@ -498,12 +511,22 @@ public class CPUID {
|
||||
*
|
||||
*/
|
||||
private static final boolean loadFromResource() {
|
||||
// Mac info:
|
||||
// Through 0.9.25, we had a libjcpuid-x86_64-osx.jnilib and a libjcpuid-x86-osx.jnilib file.
|
||||
// As of 0.9.26, we have a single libjcpuid-x86_64-osx.jnilib fat binary that has both 64- and 32-bit support.
|
||||
// For updates, the 0.9.27 update contained the new jbigi.jar.
|
||||
// However, in rare cases, a user may have skipped that update, going straight
|
||||
// from 0.9.26 to 0.9.28. Since we can't be sure, always try both for Mac.
|
||||
// getResourceName64() returns non-null for 64-bit OR for 32-bit Mac.
|
||||
|
||||
// try 64 bit first, if getResourceName64() returns non-null
|
||||
String resourceName = getResourceName64();
|
||||
if (resourceName != null) {
|
||||
boolean success = extractLoadAndCopy(resourceName);
|
||||
if (success)
|
||||
return true;
|
||||
if (_doLog)
|
||||
System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
|
||||
}
|
||||
|
||||
// now try 32 bit
|
||||
@@ -511,7 +534,6 @@ public class CPUID {
|
||||
boolean success = extractLoadAndCopy(resourceName);
|
||||
if (success)
|
||||
return true;
|
||||
|
||||
if (_doLog)
|
||||
System.err.println("WARNING: Resource name [" + resourceName + "] was not found");
|
||||
return false;
|
||||
@@ -531,7 +553,7 @@ public class CPUID {
|
||||
return false;
|
||||
File outFile = null;
|
||||
FileOutputStream fos = null;
|
||||
String filename = libPrefix + "jcpuid" + libSuffix;
|
||||
String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix();
|
||||
try {
|
||||
InputStream libStream = resource.openStream();
|
||||
outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename);
|
||||
@@ -571,17 +593,20 @@ public class CPUID {
|
||||
/** @return non-null */
|
||||
private static final String getResourceName()
|
||||
{
|
||||
return getLibraryPrefix()+getLibraryMiddlePart()+"."+getLibrarySuffix();
|
||||
return getLibraryPrefix() + getLibraryMiddlePart() + getLibrarySuffix();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null if not on a 64 bit platform
|
||||
* @return null if not on a 64 bit platform (except Mac)
|
||||
* @since 0.8.7
|
||||
*/
|
||||
private static final String getResourceName64() {
|
||||
if (!is64)
|
||||
// As of GMP 6,
|
||||
// libjcpuid-x86_64-osx.jnilib file is a fat binary that contains both 64- and 32-bit binaries
|
||||
// See loadFromResource() for more info.
|
||||
if (!is64 && !isMac)
|
||||
return null;
|
||||
return getLibraryPrefix() + get64LibraryMiddlePart() + "." + getLibrarySuffix();
|
||||
return getLibraryPrefix() + get64LibraryMiddlePart() + getLibrarySuffix();
|
||||
}
|
||||
|
||||
private static final String getLibraryPrefix()
|
||||
@@ -597,8 +622,14 @@ public class CPUID {
|
||||
return "jcpuid-x86-windows"; // The convention on Windows
|
||||
if(isMac) {
|
||||
if(isX86) {
|
||||
return "jcpuid-x86-osx"; // The convention on Intel Macs
|
||||
// As of GMP6,
|
||||
// our libjcpuid-x86_64.osx.jnilib is a fat binary,
|
||||
// with the 32-bit lib in it also.
|
||||
// Not sure if that was on purpose...
|
||||
return "jcpuid-x86_64-osx"; // The convention on Intel Macs
|
||||
}
|
||||
// this will fail, we don't have any ppc libs, but we can't return null here.
|
||||
return "jcpuid-ppc-osx";
|
||||
}
|
||||
if(isKFreebsd)
|
||||
return "jcpuid-x86-kfreebsd"; // The convention on kfreebsd...
|
||||
@@ -631,6 +662,8 @@ public class CPUID {
|
||||
if(isX86){
|
||||
return "jcpuid-x86_64-osx";
|
||||
}
|
||||
// this will fail, we don't have any ppc libs, but we can't return null here.
|
||||
return "jcpuid-ppc_64-osx";
|
||||
}
|
||||
if(isSunos)
|
||||
return "jcpuid-x86_64-solaris";
|
||||
@@ -641,10 +674,10 @@ public class CPUID {
|
||||
private static final String getLibrarySuffix()
|
||||
{
|
||||
if(isWindows)
|
||||
return "dll";
|
||||
return ".dll";
|
||||
if(isMac)
|
||||
return "jnilib";
|
||||
return ".jnilib";
|
||||
else
|
||||
return "so";
|
||||
return ".so";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.app.ClientAppManager;
|
||||
import net.i2p.app.ClientAppManagerImpl;
|
||||
import net.i2p.client.naming.NamingService;
|
||||
import net.i2p.crypto.AESEngine;
|
||||
import net.i2p.crypto.CryptixAESEngine;
|
||||
@@ -116,6 +117,7 @@ public class I2PAppContext {
|
||||
private final File _appDir;
|
||||
private volatile File _tmpDir;
|
||||
private final Random _tmpDirRand = new Random();
|
||||
private final ClientAppManager _appManager;
|
||||
// split up big lock on this to avoid deadlocks
|
||||
private final Object _lock1 = new Object(), _lock2 = new Object(), _lock3 = new Object(), _lock4 = new Object(),
|
||||
_lock5 = new Object(), _lock6 = new Object(), _lock7 = new Object(), _lock8 = new Object(),
|
||||
@@ -198,6 +200,7 @@ public class I2PAppContext {
|
||||
_overrideProps.putAll(envProps);
|
||||
_shutdownTasks = new ConcurrentHashSet<Runnable>(32);
|
||||
_portMapper = new PortMapper(this);
|
||||
_appManager = isRouterContext() ? null : new ClientAppManagerImpl(this);
|
||||
|
||||
/*
|
||||
* Directories. These are all set at instantiation and will not be changed by
|
||||
@@ -1007,11 +1010,14 @@ public class I2PAppContext {
|
||||
}
|
||||
|
||||
/**
|
||||
* The RouterAppManager in RouterContext, null always in I2PAppContext
|
||||
* @return null always
|
||||
* As of 0.9.30, returns non-null in I2PAppContext, null in RouterContext.
|
||||
* Prior to that, returned null always.
|
||||
* Overridden in RouterContext to return the RouterAppManager.
|
||||
*
|
||||
* @return As of 0.9.30, returns non-null in I2PAppContext, null in RouterContext
|
||||
* @since 0.9.11, in RouterContext since 0.9.4
|
||||
*/
|
||||
public ClientAppManager clientAppManager() {
|
||||
return null;
|
||||
return _appManager;
|
||||
}
|
||||
}
|
||||
|
||||
67
core/java/src/net/i2p/app/ClientAppManagerImpl.java
Normal file
67
core/java/src/net/i2p/app/ClientAppManagerImpl.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package net.i2p.app;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
|
||||
/**
|
||||
* A simple ClientAppManager that supports register/unregister only,
|
||||
* so that client apps may find each other in AppContext.
|
||||
* See RouterAppManager for the real thing in RouterContext.
|
||||
*
|
||||
* @since 0.9.30
|
||||
*/
|
||||
public class ClientAppManagerImpl implements ClientAppManager {
|
||||
|
||||
// registered name to client
|
||||
protected final ConcurrentHashMap<String, ClientApp> _registered;
|
||||
|
||||
public ClientAppManagerImpl(I2PAppContext ctx) {
|
||||
_registered = new ConcurrentHashMap<String, ClientApp>(8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*
|
||||
* @param app non-null
|
||||
* @param state non-null
|
||||
* @param message may be null
|
||||
* @param e may be null
|
||||
*/
|
||||
public void notify(ClientApp app, ClientAppState state, String message, Exception e) {}
|
||||
|
||||
/**
|
||||
* Register with the manager under the given name,
|
||||
* so that other clients may find it.
|
||||
* Only required for apps used by other apps.
|
||||
*
|
||||
* @param app non-null
|
||||
* @return true if successful, false if duplicate name
|
||||
*/
|
||||
public boolean register(ClientApp app) {
|
||||
return _registered.putIfAbsent(app.getName(), app) == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister with the manager. Name must be the same as that from register().
|
||||
* Only required for apps used by other apps.
|
||||
*
|
||||
* @param app non-null
|
||||
*/
|
||||
public void unregister(ClientApp app) {
|
||||
_registered.remove(app.getName(), app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registered app.
|
||||
* Only used for apps finding other apps.
|
||||
* Do not hold a static reference.
|
||||
* If you only need to find a port, use the PortMapper instead.
|
||||
*
|
||||
* @param name non-null
|
||||
* @return client app or null
|
||||
*/
|
||||
public ClientApp getRegisteredApp(String name) {
|
||||
return _registered.get(name);
|
||||
}
|
||||
}
|
||||
@@ -272,8 +272,10 @@ public interface I2PSession {
|
||||
public List<I2PSession> getSubsessions();
|
||||
|
||||
/**
|
||||
* Actually connect the session and start receiving/sending messages
|
||||
*
|
||||
* Actually connect the session and start receiving/sending messages.
|
||||
* Connecting a primary session will not automatically connect subsessions.
|
||||
* Connecting a subsession will automatically connect the primary session
|
||||
* if not previously connected.
|
||||
*/
|
||||
public void connect() throws I2PSessionException;
|
||||
|
||||
|
||||
@@ -548,6 +548,10 @@ public abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2
|
||||
* Disconnect / destroy from another thread may be called simultaneously and
|
||||
* will (should?) interrupt the connect.
|
||||
*
|
||||
* Connecting a primary session will not automatically connect subsessions.
|
||||
* Connecting a subsession will automatically connect the primary session
|
||||
* if not previously connected.
|
||||
*
|
||||
* @throws I2PSessionException if there is a configuration error or the router is
|
||||
* not reachable
|
||||
*/
|
||||
|
||||
@@ -93,6 +93,9 @@ class SubSession extends I2PSessionMuxedImpl {
|
||||
* Disconnect / destroy from another thread may be called simultaneously and
|
||||
* will (should?) interrupt the connect.
|
||||
*
|
||||
* Connecting a subsession will automatically connect the primary session
|
||||
* if not previously connected.
|
||||
*
|
||||
* @throws I2PSessionException if there is a configuration error or the router is
|
||||
* not reachable
|
||||
*/
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -418,10 +419,10 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
// version 3 -> version 4
|
||||
// support multiple destinations per hostname
|
||||
if (VersionComparator.comp(_version, "4") < 0) {
|
||||
// Upgrade of 4K entry DB on RPi 2 is over 2 1/2 minutes, disable for now
|
||||
if (SystemVersion.isAndroid() || SystemVersion.isARM()) {
|
||||
// Upgrade of 4K entry DB on RPi 2 is over 2 1/2 minutes, probably worse on Android, disable for now
|
||||
if (SystemVersion.isAndroid()) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("Deferring upgrade to version 4 on Android/ARM");
|
||||
_log.warn("Deferring upgrade to version 4 on Android");
|
||||
return true;
|
||||
}
|
||||
SkipList<String, Properties> hdr = _bf.getIndex(INFO_SKIPLIST, _stringSerializer, _infoSerializer);
|
||||
@@ -1291,6 +1292,132 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Export in a hosts.txt format.
|
||||
* Output is sorted.
|
||||
* Caller must close writer.
|
||||
*
|
||||
* @param options If non-null and contains the key "list", get
|
||||
* from that list (default "hosts.txt", NOT all lists)
|
||||
* Key "search": return only those matching substring
|
||||
* Key "startsWith": return only those starting with
|
||||
* ("[0-9]" allowed)
|
||||
* Key "beginWith": start here in the iteration
|
||||
* @since 0.9.30 override NamingService to add stored authentication strings
|
||||
*/
|
||||
@Override
|
||||
public void export(Writer out, Properties options) throws IOException {
|
||||
String listname = FALLBACK_LIST;
|
||||
String search = null;
|
||||
String startsWith = null;
|
||||
String beginWith = null;
|
||||
if (options != null) {
|
||||
String ln = options.getProperty("list");
|
||||
if (ln != null)
|
||||
listname = ln;
|
||||
search = options.getProperty("search");
|
||||
startsWith = options.getProperty("startsWith");
|
||||
beginWith = options.getProperty("beginWith");
|
||||
if (beginWith == null && startsWith != null) {
|
||||
if (startsWith.equals("[0-9]"))
|
||||
beginWith = "0";
|
||||
else
|
||||
beginWith = startsWith;
|
||||
}
|
||||
}
|
||||
out.write("# Address book: ");
|
||||
out.write(getName());
|
||||
out.write(" (" + listname + ')');
|
||||
final String nl = System.getProperty("line.separator", "\n");
|
||||
out.write(nl);
|
||||
out.write("# Exported: ");
|
||||
out.write((new Date()).toString());
|
||||
out.write(nl);
|
||||
synchronized(_bf) {
|
||||
if (_isClosed)
|
||||
return;
|
||||
try {
|
||||
SkipList<String, DestEntry> sl = _bf.getIndex(listname, _stringSerializer, _destSerializer);
|
||||
if (sl == null) {
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("No skiplist found for lookup in " + listname);
|
||||
return;
|
||||
}
|
||||
if (beginWith == null && search == null) {
|
||||
int sz = sl.size();
|
||||
if (sz <= 0) {
|
||||
out.write("# No entries");
|
||||
out.write(nl);
|
||||
return;
|
||||
}
|
||||
if (sz > 1) {
|
||||
// actually not right due to multidest
|
||||
out.write("# " + sz + " entries");
|
||||
out.write(nl);
|
||||
}
|
||||
}
|
||||
SkipIterator<String, DestEntry> iter;
|
||||
if (beginWith != null)
|
||||
iter = sl.find(beginWith);
|
||||
else
|
||||
iter = sl.iterator();
|
||||
int cnt = 0;
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.nextKey();
|
||||
if (startsWith != null) {
|
||||
if (startsWith.equals("[0-9]")) {
|
||||
if (key.charAt(0) > '9')
|
||||
break;
|
||||
} else if (!key.startsWith(startsWith)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
DestEntry de = iter.next();
|
||||
if (!validate(key, de, listname))
|
||||
continue;
|
||||
if (search != null && key.indexOf(search) < 0)
|
||||
continue;
|
||||
int dsz = de.destList != null ? de.destList.size() : 1;
|
||||
// new non-DSA dest is put first, so put in reverse
|
||||
// order so importers will see the older dest first
|
||||
for (int i = dsz - 1; i >= 0; i--) {
|
||||
Properties p;
|
||||
Destination d;
|
||||
if (i == 0) {
|
||||
p = de.props;
|
||||
d = de.dest;
|
||||
} else {
|
||||
p = de.propsList.get(i);
|
||||
d = de.destList.get(i);
|
||||
}
|
||||
out.write(key);
|
||||
out.write('=');
|
||||
out.write(d.toBase64());
|
||||
if (p != null)
|
||||
SingleFileNamingService.writeOptions(p, out);
|
||||
out.write(nl);
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
if (beginWith != null || search != null) {
|
||||
if (cnt <= 0) {
|
||||
out.write("# No entries");
|
||||
out.write(nl);
|
||||
return;
|
||||
}
|
||||
if (cnt > 1) {
|
||||
out.write("# " + cnt + " entries");
|
||||
out.write(nl);
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException re) {
|
||||
throw new IOException("DB lookup error", re);
|
||||
} finally {
|
||||
deleteInvalid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param options If non-null and contains the key "list", get
|
||||
* from that list (default "hosts.txt", NOT all lists)
|
||||
@@ -1578,6 +1705,11 @@ public class BlockfileNamingService extends DummyNamingService {
|
||||
}
|
||||
storedOptions.remove(i);
|
||||
removeReverseEntry(hostname, d);
|
||||
if (options != null) {
|
||||
String list = options.getProperty("list");
|
||||
if (list != null)
|
||||
storedOptions.get(0).setProperty("list", list);
|
||||
}
|
||||
return put(hostname, newDests, storedOptions, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,9 +268,9 @@ public class SingleFileNamingService extends NamingService {
|
||||
* Does not write a newline.
|
||||
*
|
||||
* @param options non-null
|
||||
* @since 0.9.26
|
||||
* @since 0.9.26, package private since 0.9.30
|
||||
*/
|
||||
private static void writeOptions(Properties options, Writer out) throws IOException {
|
||||
static void writeOptions(Properties options, Writer out) throws IOException {
|
||||
boolean started = false;
|
||||
for (Map.Entry<Object, Object> e : options.entrySet()) {
|
||||
String k = (String) e.getKey();
|
||||
|
||||
@@ -116,11 +116,7 @@ public final class KeyGenerator {
|
||||
|
||||
/** @since 0.9.8 */
|
||||
private static final boolean DEFAULT_USE_LONG_EXPONENT =
|
||||
NativeBigInteger.isNative() &&
|
||||
SystemVersion.is64Bit() &&
|
||||
!SystemVersion.isGNU() &&
|
||||
!SystemVersion.isApache() &&
|
||||
!SystemVersion.isARM();
|
||||
!SystemVersion.isSlow();
|
||||
|
||||
/**
|
||||
* @deprecated use getElGamalExponentSize() which allows override in the properties
|
||||
|
||||
@@ -422,10 +422,11 @@ public final class KeyStoreUtil {
|
||||
} catch (CertificateExpiredException cee) {
|
||||
String s = "Rejecting expired X509 Certificate: " + file.getAbsolutePath();
|
||||
// Android often has old system certs
|
||||
if (SystemVersion.isAndroid())
|
||||
// our SSL certs may be old also
|
||||
//if (SystemVersion.isAndroid())
|
||||
warn(s, cee);
|
||||
else
|
||||
error(s, cee);
|
||||
//else
|
||||
// error(s, cee);
|
||||
return false;
|
||||
} catch (CertificateNotYetValidException cnyve) {
|
||||
error("Rejecting X509 Certificate not yet valid: " + file.getAbsolutePath(), cnyve);
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.i2p.data.SigningPublicKey;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
import net.i2p.util.VersionComparator;
|
||||
import net.i2p.util.ZipFileComment;
|
||||
//import net.i2p.util.ZipFileComment;
|
||||
|
||||
/**
|
||||
* <p>Handles DSA signing and verification of update files.
|
||||
@@ -611,9 +611,10 @@ riCe6OlAEiNpcc6mMyIYYWFICbrDFTrDR3wXqwc/Jkcx6L5VVWoagpSzbo3yGhc=
|
||||
*
|
||||
* @since 0.8.8
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private boolean verifyVersionMatch(File signedFile) {
|
||||
try {
|
||||
String zipComment = ZipFileComment.getComment(signedFile, VERSION_BYTES, HEADER_BYTES);
|
||||
String zipComment = net.i2p.util.ZipFileComment.getComment(signedFile, VERSION_BYTES, HEADER_BYTES);
|
||||
return zipComment.equals(_newVersion);
|
||||
} catch (IOException ioe) {}
|
||||
return false;
|
||||
|
||||
@@ -46,6 +46,7 @@ import net.i2p.util.OrderedProperties;
|
||||
import net.i2p.util.ReusableGZIPInputStream;
|
||||
import net.i2p.util.ReusableGZIPOutputStream;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
import net.i2p.util.SystemVersion;
|
||||
import net.i2p.util.Translate;
|
||||
|
||||
/**
|
||||
@@ -55,6 +56,9 @@ import net.i2p.util.Translate;
|
||||
*/
|
||||
public class DataHelper {
|
||||
|
||||
/** See storeProps(). 600-750 ms on RPi. */
|
||||
private static final boolean SHOULD_SYNC = !(SystemVersion.isAndroid() || SystemVersion.isARM());
|
||||
|
||||
/**
|
||||
* Map of String to itself to cache common
|
||||
* keys in RouterInfo, RouterAddress, and BlockfileNamingService properties.
|
||||
@@ -68,9 +72,9 @@ public class DataHelper {
|
||||
"cost", "host", "port",
|
||||
// SSU RouterAddress options
|
||||
"key", "mtu",
|
||||
"ihost0", "iport0", "ikey0", "itag0",
|
||||
"ihost1", "iport1", "ikey1", "itag1",
|
||||
"ihost2", "iport2", "ikey2", "itag2",
|
||||
"ihost0", "iport0", "ikey0", "itag0", "iexp0",
|
||||
"ihost1", "iport1", "ikey1", "itag1", "iexp1",
|
||||
"ihost2", "iport2", "ikey2", "itag2", "iexp2",
|
||||
// RouterInfo options
|
||||
"caps", "coreVersion", "netId", "router.version",
|
||||
"netdb.knownLeaseSets", "netdb.knownRouters",
|
||||
@@ -514,8 +518,10 @@ public class DataHelper {
|
||||
}
|
||||
out.println(name + "=" + val);
|
||||
}
|
||||
out.flush();
|
||||
fos.getFD().sync();
|
||||
if (SHOULD_SYNC) {
|
||||
out.flush();
|
||||
fos.getFD().sync();
|
||||
}
|
||||
out.close();
|
||||
if (out.checkError()) {
|
||||
out = null;
|
||||
|
||||
@@ -34,7 +34,10 @@ public class BuildTime {
|
||||
private static final long _latestTime;
|
||||
private static final long YEARS_25 = 25L*365*24*60*60*1000;
|
||||
/** update this periodically */
|
||||
private static final String EARLIEST = "2016-02-19 12:00:00 UTC";
|
||||
private static final String EARLIEST = "2017-03-27 12:00:00 UTC";
|
||||
// fallback if parse fails ticket #1976
|
||||
// date -d 201x-xx-xx +%s
|
||||
private static final long EARLIEST_LONG = 1490587200 * 1000L;
|
||||
|
||||
static {
|
||||
// this is the standard format of build.timestamp as set in the top-level build.xml
|
||||
@@ -45,12 +48,15 @@ public class BuildTime {
|
||||
try {
|
||||
Date date = fmt.parse(EARLIEST);
|
||||
if (date == null)
|
||||
throw new RuntimeException("BuildTime FAIL");
|
||||
min = date.getTime();
|
||||
min = EARLIEST_LONG;
|
||||
else
|
||||
min = date.getTime();
|
||||
} catch (ParseException pe) {
|
||||
System.out.println("BuildTime FAIL");
|
||||
pe.printStackTrace();
|
||||
throw new RuntimeException("BuildTime FAIL", pe);
|
||||
// Old Android, ticket #1976
|
||||
//pe.printStackTrace();
|
||||
//throw new RuntimeException("BuildTime FAIL", pe);
|
||||
min = EARLIEST_LONG;
|
||||
}
|
||||
long max = min + YEARS_25;
|
||||
long build = getBuildTime(fmt, "i2p.jar");
|
||||
|
||||
@@ -87,7 +87,7 @@ public final class ByteCache {
|
||||
if (cache == null) {
|
||||
cache = new ByteCache(cacheSize, size);
|
||||
_caches.put(sz, cache);
|
||||
; }
|
||||
}
|
||||
cache.resize(cacheSize);
|
||||
//I2PAppContext.getGlobalContext().logManager().getLog(ByteCache.class).error("ByteCache size: " + size + " max: " + cacheSize, new Exception("from"));
|
||||
return cache;
|
||||
|
||||
@@ -108,12 +108,13 @@ public class FortunaRandomSource extends RandomSource implements EntropyHarveste
|
||||
|
||||
// get at least 4 extra bits if possible for better
|
||||
// distribution after the %
|
||||
// No extra needed if power of two.
|
||||
int numBits;
|
||||
if (n > 0xfffff)
|
||||
if (n > 0x100000)
|
||||
numBits = 31;
|
||||
else if (n > 0xfff)
|
||||
else if (n > 0x1000)
|
||||
numBits = 24;
|
||||
else if (n > 0xf)
|
||||
else if (n > 0x10)
|
||||
numBits = 16;
|
||||
else
|
||||
numBits = 8;
|
||||
|
||||
@@ -209,6 +209,9 @@ public class NativeBigInteger extends BigInteger {
|
||||
* Really this could be represented by a DAG, but the benefits don't
|
||||
* outweigh the implementation time.
|
||||
*/
|
||||
|
||||
// none -> {"none"), since 0.9.30
|
||||
private final static String[] JBIGI_COMPAT_LIST_NONE = {JBIGI_OPTIMIZATION_X86};
|
||||
private final static String[] JBIGI_COMPAT_LIST_PPC = {JBIGI_OPTIMIZATION_PPC};
|
||||
private final static String[] JBIGI_COMPAT_LIST_ARM = {JBIGI_OPTIMIZATION_ARM_CORTEX_A15, JBIGI_OPTIMIZATION_ARM_CORTEX_A9, JBIGI_OPTIMIZATION_ARM_CORTEX_A8,
|
||||
JBIGI_OPTIMIZATION_ARM_CORTEX_A7, JBIGI_OPTIMIZATION_ARM_CORTEX_A5, JBIGI_OPTIMIZATION_ARM_ARMV7,
|
||||
@@ -231,11 +234,14 @@ public class NativeBigInteger extends BigInteger {
|
||||
private final static String[] JBIGI_COMPAT_LIST_INTEL_CORE = {JBIGI_OPTIMIZATION_COREI_BWL, JBIGI_OPTIMIZATION_COREI_HWL, JBIGI_OPTIMIZATION_COREI_SBR,
|
||||
JBIGI_OPTIMIZATION_COREI, JBIGI_OPTIMIZATION_CORE2, JBIGI_OPTIMIZATION_PENTIUMM,
|
||||
JBIGI_OPTIMIZATION_PENTIUM3, JBIGI_OPTIMIZATION_X86};
|
||||
|
||||
/**
|
||||
* The mapping between CPU architecture and its compatibility list.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private final static HashMap<String, String[]> JBIGI_COMPAT_MAP = new HashMap<String, String[]>() {{
|
||||
// none -> {"none"), since 0.9.30
|
||||
put(JBIGI_OPTIMIZATION_X86, JBIGI_COMPAT_LIST_NONE);
|
||||
put(JBIGI_OPTIMIZATION_PPC, JBIGI_COMPAT_LIST_PPC);
|
||||
|
||||
put(JBIGI_OPTIMIZATION_ARM_ARMV5, JBIGI_COMPAT_LIST_ARM);
|
||||
@@ -406,10 +412,11 @@ public class NativeBigInteger extends BigInteger {
|
||||
if (intelcpu.IsPentiumCompatible())
|
||||
return JBIGI_OPTIMIZATION_PENTIUM;
|
||||
}
|
||||
return null;
|
||||
} catch (UnknownCPUException e) {
|
||||
return null;
|
||||
}
|
||||
// always try "none" if we don't know the x86 type,
|
||||
// in case of CPUID fail or not finding compatibility above
|
||||
return JBIGI_OPTIMIZATION_X86;
|
||||
} else if (_isArm) {
|
||||
if (_isWin)
|
||||
return null;
|
||||
@@ -739,9 +746,25 @@ public class NativeBigInteger extends BigInteger {
|
||||
*/
|
||||
public static void main(String args[]) {
|
||||
_doLog = true;
|
||||
String path = System.getProperty("java.library.path");
|
||||
String name = _libPrefix + "jbigi" + _libSuffix;
|
||||
System.out.println("Native library search path: " + path);
|
||||
if (_nativeOk) {
|
||||
String sep = System.getProperty("path.separator");
|
||||
String[] paths = DataHelper.split(path, sep);
|
||||
for (String p : paths) {
|
||||
File f = new File(p, name);
|
||||
if (f.exists()) {
|
||||
System.out.println("Found native library: " + f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
System.out.println("Failed to load native library. Please verify the existence of the " +
|
||||
name + " file in the library path, or set -Djava.library.path=. in the command line");
|
||||
}
|
||||
boolean nativeOnly = args.length > 0 && args[0].equals("-n");
|
||||
if (nativeOnly && !_nativeOk) {
|
||||
System.out.println("Failed to load native library");
|
||||
System.exit(1);
|
||||
}
|
||||
if (_nativeOk) {
|
||||
@@ -959,7 +982,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
List<String> toTry = getResourceList();
|
||||
debug("loadResource list to try is: " + toTry);
|
||||
for (String s : toTry) {
|
||||
System.out.println("trying to load resource: " + s);
|
||||
debug("Trying to load resource " + s);
|
||||
if (loadFromResource(s)) {
|
||||
_nativeOk = true;
|
||||
_extractedResource = s;
|
||||
@@ -1092,7 +1115,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
//URL resource = NativeBigInteger.class.getClassLoader().getResource(resourceName);
|
||||
URL resource = ClassLoader.getSystemResource(resourceName);
|
||||
if (resource == null) {
|
||||
System.out.println("Resource name [" + resourceName + "] was not found");
|
||||
info("Resource name [" + resourceName + "] was not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1107,15 +1130,15 @@ public class NativeBigInteger extends BigInteger {
|
||||
fos.close();
|
||||
fos = null;
|
||||
System.load(outFile.getAbsolutePath()); //System.load requires an absolute path to the lib
|
||||
System.out.println("Loaded library: " + resource);
|
||||
info("Loaded library: " + resource);
|
||||
} catch (UnsatisfiedLinkError ule) {
|
||||
// don't include the exception in the message - too much
|
||||
System.out.println("Failed to load the resource " + resourceName + " - not a valid library for this platform");
|
||||
warn("Failed to load the resource " + resourceName + " - not a valid library for this platform");
|
||||
if (outFile != null)
|
||||
outFile.delete();
|
||||
return false;
|
||||
} catch (IOException ioe) {
|
||||
System.out.println("Problem writing out the temporary native library data: " + ioe.toString());
|
||||
warn("Problem writing out the temporary native library data: " + ioe);
|
||||
if (outFile != null)
|
||||
outFile.delete();
|
||||
return false;
|
||||
@@ -1141,6 +1164,7 @@ public class NativeBigInteger extends BigInteger {
|
||||
return Collections.emptyList();
|
||||
List<String> rv = new ArrayList<String>(20);
|
||||
String primary = getMiddleName2(true);
|
||||
// primary may be null
|
||||
String[] compatList = JBIGI_COMPAT_MAP.get(primary);
|
||||
|
||||
if (primary != null && compatList == null) {
|
||||
@@ -1222,12 +1246,14 @@ public class NativeBigInteger extends BigInteger {
|
||||
/**
|
||||
* @return may be null if optimized is true; returns jbigi-xxx-none if optimize is false
|
||||
*/
|
||||
/****
|
||||
private static final String getMiddleName(boolean optimized) {
|
||||
String m2 = getMiddleName2(optimized);
|
||||
if (m2 == null)
|
||||
return null;
|
||||
return getMiddleName1() + m2;
|
||||
}
|
||||
****/
|
||||
|
||||
/**
|
||||
* @return may be null if optimized is true; returns "none" if optimize is false
|
||||
|
||||
@@ -39,6 +39,7 @@ public abstract class SystemVersion {
|
||||
private static final boolean _is64;
|
||||
private static final boolean _hasWrapper = System.getProperty("wrapper.version") != null;
|
||||
private static final boolean _isLinuxService;
|
||||
private static final boolean _isSlow;
|
||||
|
||||
private static final boolean _oneDotSix;
|
||||
private static final boolean _oneDotSeven;
|
||||
@@ -69,6 +70,7 @@ public abstract class SystemVersion {
|
||||
_isLinuxService = !_isWin && !_isMac && !_isAndroid &&
|
||||
(DAEMON_USER.equals(System.getProperty("user.name")) ||
|
||||
(_isGentoo && GENTOO_USER.equals(System.getProperty("user.name"))));
|
||||
_isSlow = _isAndroid || _isApache || _isArm || _isGNU || getMaxMemory() < 48*1024*1024L;
|
||||
|
||||
int sdk = 0;
|
||||
if (_isAndroid) {
|
||||
@@ -153,6 +155,18 @@ public abstract class SystemVersion {
|
||||
return _isX86;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our best guess on whether this is a slow architecture / OS / JVM,
|
||||
* using some simple heuristics.
|
||||
*
|
||||
* @since 0.9.30
|
||||
*/
|
||||
public static boolean isSlow() {
|
||||
// we don't put the NBI call in the static field,
|
||||
// to prevent a circular initialization with NBI.
|
||||
return _isSlow || !NativeBigInteger.isNative();
|
||||
}
|
||||
|
||||
/**
|
||||
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0
|
||||
* as it handles Android also, where java.version = "0".
|
||||
@@ -290,6 +304,7 @@ public abstract class SystemVersion {
|
||||
System.out.println("Linux Svc: " + isLinuxService());
|
||||
System.out.println("Mac : " + isMac());
|
||||
System.out.println("OpenJDK : " + isOpenJDK());
|
||||
System.out.println("Slow : " + isSlow());
|
||||
System.out.println("Windows : " + isWindows());
|
||||
System.out.println("Wrapper : " + hasWrapper());
|
||||
System.out.println("x86 : " + isX86());
|
||||
|
||||
@@ -19,8 +19,10 @@ import net.i2p.data.DataHelper;
|
||||
* http://www.flattermann.net/2009/01/read-a-zip-file-comment-with-java/
|
||||
* Beerware.
|
||||
*
|
||||
* since 0.8.8
|
||||
* @deprecated scheduled for removal late 2017, not for external use
|
||||
* @since 0.8.8
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class ZipFileComment {
|
||||
|
||||
private static final int BLOCK_LEN = 22;
|
||||
|
||||
Reference in New Issue
Block a user