propagate from branch 'i2p.i2p.zzz.naming' (head 9626e0df682c8d5f706d2c814158ba451f3ebeb5)

to branch 'i2p.i2p' (head a3969e6c9c4fd5bfd69cd716ce0df191ad2af634)
This commit is contained in:
zzz
2011-05-20 14:12:07 +00:00
154 changed files with 11593 additions and 7472 deletions

View File

@ -38,8 +38,8 @@ public class AsyncFortunaStandalone extends FortunaStandalone implements Runnabl
for (int i = 0; i < _bufferCount; i++)
status[i] = STATUS_NEED_FILL;
_context = context;
context.statManager().createRateStat("prng.bufferWaitTime", "", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } );
context.statManager().createRateStat("prng.bufferFillTime", "", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } );
context.statManager().createRequiredRateStat("prng.bufferWaitTime", "Delay for random number buffer (ms)", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } );
context.statManager().createRequiredRateStat("prng.bufferFillTime", "Time to fill random number buffer (ms)", "Encryption", new long[] { 60*1000, 10*60*1000, 60*60*1000 } );
_log = context.logManager().getLog(AsyncFortunaStandalone.class);
}

View File

@ -16,7 +16,7 @@ package net.i2p;
public class CoreVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = "0.8.4";
public final static String VERSION = "0.8.6";
public static void main(String args[]) {
System.out.println("I2P Core version: " + VERSION);

View File

@ -64,11 +64,11 @@ public class ElGamalEngine {
*
*/
public ElGamalEngine(I2PAppContext context) {
context.statManager().createRateStat("crypto.elGamal.encrypt",
"how long does it take to do a full ElGamal encryption", "Encryption",
context.statManager().createRequiredRateStat("crypto.elGamal.encrypt",
"Time for ElGamal encryption (ms)", "Encryption",
new long[] { 60 * 60 * 1000});
context.statManager().createRateStat("crypto.elGamal.decrypt",
"how long does it take to do a full ElGamal decryption", "Encryption",
context.statManager().createRequiredRateStat("crypto.elGamal.decrypt",
"Time for ElGamal decryption (ms)", "Encryption",
new long[] { 60 * 60 * 1000});
_context = context;
_log = context.logManager().getLog(ElGamalEngine.class);

View File

@ -44,7 +44,7 @@ public class Certificate extends DataStructureImpl {
public final static int CERTIFICATE_TYPE_MULTIPLE = 4;
/**
* Pull from cache or return new
* If null cert, return immutable static instance, else create new
* @throws AIOOBE if not enough bytes
* @since 0.8.3
*/
@ -57,7 +57,7 @@ public class Certificate extends DataStructureImpl {
if (length == 0)
return new Certificate(type, null);
byte[] payload = new byte[length];
System.arraycopy(data, off = 3, payload, 0, length);
System.arraycopy(data, off + 3, payload, 0, length);
return new Certificate(type, payload);
}

View File

@ -823,11 +823,10 @@ public class DataHelper {
* This treats (null == null) as true, (null == (!null)) as false,
* and unequal length arrays as false.
*
* @return Arrays.equals(lhs, rhs)
*/
public final static boolean eq(byte lhs[], byte rhs[]) {
// this appears to be the way Arrays.equals is defined, so all the extra tests are unnecessary?
boolean eq = (((lhs == null) && (rhs == null)) || ((lhs != null) && (rhs != null) && (Arrays.equals(lhs, rhs))));
return eq;
return Arrays.equals(lhs, rhs);
}
/**

View File

@ -21,8 +21,8 @@ import net.i2p.util.Log;
*
*/
public class StatManager {
private Log _log;
private I2PAppContext _context;
private final Log _log;
private final I2PAppContext _context;
/** stat name to FrequencyStat */
private final ConcurrentHashMap<String, FrequencyStat> _frequencyStats;
@ -39,28 +39,8 @@ public class StatManager {
public static final String PROP_STAT_FILTER = "stat.logFilters";
public static final String PROP_STAT_FILE = "stat.logFile";
public static final String DEFAULT_STAT_FILE = "stats.log";
/** default true */
/** default false */
public static final String PROP_STAT_FULL = "stat.full";
public static final String PROP_STAT_REQUIRED = "stat.required";
/**
* These are all the stats published in netDb, plus those required for the operation of
* the router (many in RouterThrottleImpl), plus those that are on graphs.jsp by default,
* plus those used on the summary bar (SummaryHelper.java).
* Wildcard ('*') allowed at end of stat only.
* Ignore all the rest of the stats unless stat.full=true.
*/
public static final String DEFAULT_STAT_REQUIRED =
"bw.recvRate,bw.sendBps,bw.sendRate,client.sendAckTime,clock.skew,crypto.elGamal.encrypt," +
"jobQueue.jobLag,netDb.successTime,peer.failedLookupRate,router.fastPeers," +
"prng.bufferFillTime,prng.bufferWaitTime,router.memoryUsed," +
"transport.receiveMessageSize,transport.sendMessageSize,transport.sendProcessingTime," +
"tunnel.acceptLoad,tunnel.buildRequestTime,tunnel.rejectOverloaded,tunnel.rejectTimeout," +
"tunnel.buildClientExpire,tunnel.buildClientReject,tunnel.buildClientSuccess," +
"tunnel.buildExploratoryExpire,tunnel.buildExploratoryReject,tunnel.buildExploratorySuccess," +
"tunnel.buildRatio.*,tunnel.corruptMessage,tunnel.dropLoad*," +
"tunnel.decryptRequestTime,tunnel.fragmentedDropped,tunnel.participatingMessageCount,"+
"tunnel.participatingTunnels,tunnel.testFailedTime,tunnel.testSuccessTime," +
"tunnel.participatingBandwidth,udp.sendPacketSize,udp.packetsRetransmitted,udp.sendException" ;
/**
* The stat manager should only be constructed and accessed through the
@ -89,6 +69,7 @@ public class StatManager {
/**
* Create a new statistic to monitor the frequency of some event.
* The stat is ONLY created if the stat.full property is true or we are not in the router context.
*
* @param name unique name of the statistic
* @param description simple description of the statistic
@ -97,12 +78,27 @@ public class StatManager {
*/
public void createFrequencyStat(String name, String description, String group, long periods[]) {
if (ignoreStat(name)) return;
createRequiredFrequencyStat(name, description, group, periods);
}
/**
* Create a new statistic to monitor the frequency of some event.
* The stat is always created, independent of the stat.full setting or context.
*
* @param name unique name of the statistic
* @param description simple description of the statistic
* @param group used to group statistics together
* @param periods array of period lengths (in milliseconds)
* @since 0.8.6
*/
public void createRequiredFrequencyStat(String name, String description, String group, long periods[]) {
if (_frequencyStats.containsKey(name)) return;
_frequencyStats.putIfAbsent(name, new FrequencyStat(name, description, group, periods));
}
/**
* Create a new statistic to monitor the average value and confidence of some action.
* The stat is ONLY created if the stat.full property is true or we are not in the router context.
*
* @param name unique name of the statistic
* @param description simple description of the statistic
@ -111,6 +107,20 @@ public class StatManager {
*/
public void createRateStat(String name, String description, String group, long periods[]) {
if (ignoreStat(name)) return;
createRequiredRateStat(name, description, group, periods);
}
/**
* Create a new statistic to monitor the average value and confidence of some action.
* The stat is always created, independent of the stat.full setting or context.
*
* @param name unique name of the statistic
* @param description simple description of the statistic
* @param group used to group statistics together
* @param periods array of period lengths (in milliseconds)
* @since 0.8.6
*/
public void createRequiredRateStat(String name, String description, String group, long periods[]) {
if (_rateStats.containsKey(name)) return;
RateStat rs = new RateStat(name, description, group, periods);
if (_statLog != null) rs.setStatLog(_statLog);
@ -202,20 +212,13 @@ public class StatManager {
public String getStatFile() { return _context.getProperty(PROP_STAT_FILE, DEFAULT_STAT_FILE); }
/**
* Save memory by not creating stats unless they are required for router operation
* Save memory by not creating stats unless they are required for router operation.
* For backward compatibility of any external clients, always returns false if not in router context.
*
* @param statName ignored
* @return true if the stat should be ignored.
*/
public boolean ignoreStat(String statName) {
if (_context.getBooleanProperty(PROP_STAT_FULL))
return false;
String required = _context.getProperty(PROP_STAT_REQUIRED, DEFAULT_STAT_REQUIRED);
String req[] = required.split(",");
for (int i=0; i<req.length; i++) {
if (req[i].equals(statName))
return false;
if (req[i].endsWith("*") && statName.startsWith(req[i].substring(0, req[i].length() - 2)))
return false;
}
return true;
return _context.isRouterContext() && !_context.getBooleanProperty(PROP_STAT_FULL);
}
}

View File

@ -97,7 +97,7 @@ public class Clock implements Timestamper.UpdateListener {
getLog().info("Updating clock offset to " + offsetMs + "ms from " + _offset + "ms");
if (!_statCreated) {
_context.statManager().createRateStat("clock.skew", "How far is the already adjusted clock being skewed?", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*60 });
_context.statManager().createRequiredRateStat("clock.skew", "Clock step adjustment (ms)", "Clock", new long[] { 10*60*1000, 3*60*60*1000, 24*60*60*60 });
_statCreated = true;
}
_context.statManager().addRateData("clock.skew", delta, 0);

View File

@ -357,6 +357,9 @@ public class FileUtil {
* Dump the contents of the given path (relative to the root) to the output
* stream. The path must not go above the root, either - if it does, it will
* throw a FileNotFoundException
*
* Closes the OutputStream out on successful completion
* but leaves it open when throwing IOE.
*/
public static void readFile(String path, String root, OutputStream out) throws IOException {
File rootDir = new File(root);
@ -376,10 +379,10 @@ public class FileUtil {
int read = 0;
while ( (read = in.read(buf)) != -1)
out.write(buf, 0, read);
out.close();
try { out.close(); } catch (IOException ioe) {}
} finally {
if (in != null)
in.close();
try { in.close(); } catch (IOException ioe) {}
}
}

View File

@ -28,8 +28,7 @@ import net.i2p.I2PAppContext;
/**
* <p>BigInteger that takes advantage of the jbigi library for the modPow operation,
* which accounts for a massive segment of the processing cost of asymmetric
* crypto. It also takes advantage of the jbigi library for converting a BigInteger
* value to a double. Sun's implementation of the 'doubleValue()' method is _very_ lousy.
* crypto.
*
* The jbigi library itself is basically just a JNI wrapper around the
* GMP library - a collection of insanely efficient routines for dealing with
@ -64,7 +63,7 @@ import net.i2p.I2PAppContext;
* "net/i2p/util/jbigi-windows-none.dll").</p>
*
* <p>Running this class by itself does a basic unit test and benchmarks the
* NativeBigInteger.modPow/doubleValue vs. the BigInteger.modPow/doubleValue by running a 2Kbit op 100
* NativeBigInteger.modPow vs. the BigInteger.modPow by running a 2Kbit op 100
* times. At the end of each test, if the native implementation is loaded this will output
* something like:</p>
* <pre>
@ -194,14 +193,6 @@ public class NativeBigInteger extends BigInteger {
*/
public native static byte[] nativeModPow(byte base[], byte exponent[], byte modulus[]);
/**
* Converts a BigInteger byte-array to a 'double'
* @param ba Big endian twos complement representation of the BigInteger to convert to a double
* @return The plain double-value represented by 'ba'
* @deprecated unused
*/
public native static double nativeDoubleValue(byte ba[]);
private byte[] cachedBa;
public NativeBigInteger(byte[] val) {
@ -250,12 +241,9 @@ public class NativeBigInteger extends BigInteger {
return cachedBa;
}
/** @deprecated unused */
/** @deprecated unused, does not call native */
@Override
public double doubleValue() {
if (_nativeOk)
return nativeDoubleValue(toByteArray());
else
return super.doubleValue();
}
/**
@ -281,7 +269,7 @@ public class NativeBigInteger extends BigInteger {
}
/**
* <p>Compare the BigInteger.modPow/doubleValue vs the NativeBigInteger.modPow/doubleValue of some
* <p>Compare the BigInteger.modPow vs the NativeBigInteger.modPow of some
* really big (2Kbit) numbers 100 different times and benchmark the
* performance (or shit a brick if they don't match). </p>
*
@ -289,8 +277,6 @@ public class NativeBigInteger extends BigInteger {
public static void main(String args[]) {
_doLog = true;
runModPowTest(100);
// i2p doesn't care about the double values
//runDoubleValueTest(100);
}
/* the sample numbers are elG generator/prime so we can test with reasonable numbers */
@ -361,64 +347,6 @@ public class NativeBigInteger extends BigInteger {
}
}
/********
private static void runDoubleValueTest(int numRuns) {
System.out.println("DEBUG: Warming up the random number generator...");
SecureRandom rand = new SecureRandom();
rand.nextBoolean();
System.out.println("DEBUG: Random number generator warmed up");
BigInteger jg = new BigInteger(_sampleGenerator);
long totalTime = 0;
long javaTime = 0;
int MULTIPLICATOR = 50000; //Run the doubleValue() calls within a loop since they are pretty fast..
int runsProcessed = 0;
for (runsProcessed = 0; runsProcessed < numRuns; runsProcessed++) {
NativeBigInteger g = new NativeBigInteger(_sampleGenerator);
long beforeDoubleValue = System.currentTimeMillis();
double dNative=0;
for(int mult=0;mult<MULTIPLICATOR;mult++)
dNative = g.doubleValue();
long afterDoubleValue = System.currentTimeMillis();
double jval=0;
for(int mult=0;mult<MULTIPLICATOR;mult++)
jval = jg.doubleValue();
long afterJavaDoubleValue = System.currentTimeMillis();
totalTime += (afterDoubleValue - beforeDoubleValue);
javaTime += (afterJavaDoubleValue - afterDoubleValue);
if (dNative!=jval) {
System.err.println("ERROR: [" + runsProcessed + "]\tnative double != java double");
System.err.println("ERROR: native double value: " + dNative);
System.err.println("ERROR: java double value: " + jval);
System.err.println("ERROR: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
break;
} else {
System.out.println("DEBUG: current run time: " + (afterDoubleValue - beforeDoubleValue) + "ms (total: "
+ totalTime + "ms, " + (totalTime / (runsProcessed + 1)) + "ms each)");
}
}
System.out.println("INFO: run time: " + totalTime + "ms (" + (totalTime / (runsProcessed + 1)) + "ms each)");
if (numRuns == runsProcessed)
System.out.println("INFO: " + runsProcessed + " runs complete without any errors");
else
System.out.println("ERROR: " + runsProcessed + " runs until we got an error");
if (_nativeOk) {
System.out.println("native run time: \t" + totalTime + "ms (" + (totalTime / (runsProcessed + 1))
+ "ms each)");
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
System.out.println("native = " + ((totalTime * 100.0d) / (double) javaTime) + "% of pure java time");
} else {
System.out.println("java run time: \t" + javaTime + "ms (" + (javaTime / (runsProcessed + 1)) + "ms each)");
System.out.println("However, we couldn't load the native library, so this doesn't test much");
}
}
*********/
/**
* <p>Do whatever we can to load up the native library backing this BigInteger's native methods.
* If it can find a custom built jbigi.dll / libjbigi.so, it'll use that. Otherwise