forked from I2P_Developers/i2p.i2p
propagate from branch 'i2p.i2p.zzz.test4' (head 7b50b6c3d48da68078a86a53e55e2c18f55685e8)
to branch 'i2p.i2p' (head ebce577e19b70c281daacc5277f98e9bb2bb9630)
This commit is contained in:
@@ -21,20 +21,51 @@
|
||||
<target name="compile" depends="depend">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<javac srcdir="./src" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" classpath="${javac.classpath}" >
|
||||
<javac srcdir="./src" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="false"
|
||||
destdir="./build/obj" classpath="${javac.classpath}" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compileTest">
|
||||
<mkdir dir="./build" />
|
||||
<mkdir dir="./build/obj" />
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on" destdir="./build/obj" >
|
||||
<!-- junit classes are in ant runtime -->
|
||||
<javac srcdir="./src:./test" debug="true" source="1.5" target="1.5" deprecation="on"
|
||||
includeAntRuntime="true"
|
||||
destdir="./build/obj" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
<target name="jar" depends="compile">
|
||||
<jar destfile="./build/i2p.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
|
||||
<target name="jar" depends="compile, jarUpToDate" unless="jar.uptodate" >
|
||||
<exec executable="mtn" outputproperty="workspace.changes" errorproperty="mtn.error2" failifexecutionfails="false" >
|
||||
<arg value="list" />
|
||||
<arg value="changed" />
|
||||
<arg value="." />
|
||||
</exec>
|
||||
<!-- \n in an attribute value generates an invalid manifest -->
|
||||
<exec executable="tr" inputstring="${workspace.changes}" outputproperty="workspace.changes.tr" errorproperty="mtn.error2" failifexecutionfails="false" >
|
||||
<arg value="-s" />
|
||||
<arg value="[:space:]" />
|
||||
<arg value="," />
|
||||
</exec>
|
||||
<jar destfile="./build/i2p.jar" basedir="./build/obj" includes="**/*.class" >
|
||||
<manifest>
|
||||
<attribute name="Build-Date" value="${build.timestamp}" />
|
||||
<attribute name="Base-Revision" value="${workspace.version}" />
|
||||
<attribute name="Workspace-Changes" value="${workspace.changes.tr}" />
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="jarUpToDate" >
|
||||
<uptodate property="jar.uptodate" targetfile="build/i2p.jar" >
|
||||
<srcfiles dir= "build/obj" includes="**/*.class" />
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="jarTest" depends="compileTest">
|
||||
<jar destfile="./build/i2ptest.jar" basedir="./build/obj" includes="**/*.class" />
|
||||
</target>
|
||||
@@ -49,6 +80,7 @@
|
||||
<cobertura-instrument todir="./build/obj_test">
|
||||
<fileset dir="./build/obj">
|
||||
<include name="**/*.class"/>
|
||||
<exclude name="**/*Test.class" />
|
||||
</fileset>
|
||||
</cobertura-instrument>
|
||||
</target>
|
||||
|
||||
@@ -16,7 +16,7 @@ package net.i2p;
|
||||
public class CoreVersion {
|
||||
/** deprecated */
|
||||
public final static String ID = "Monotone";
|
||||
public final static String VERSION = "0.8.3";
|
||||
public final static String VERSION = "0.8.4";
|
||||
|
||||
public static void main(String args[]) {
|
||||
System.out.println("I2P Core version: " + VERSION);
|
||||
|
||||
@@ -30,10 +30,10 @@ public final class I2PDatagramDissector {
|
||||
|
||||
private static Log _log = new Log(I2PDatagramDissector.class);
|
||||
|
||||
private static int DGRAM_BUFSIZE = 32768;
|
||||
private static final int DGRAM_BUFSIZE = 32768;
|
||||
|
||||
private DSAEngine dsaEng = DSAEngine.getInstance();
|
||||
private SHA256Generator hashGen = SHA256Generator.getInstance();
|
||||
private final DSAEngine dsaEng = DSAEngine.getInstance();
|
||||
private final SHA256Generator hashGen = SHA256Generator.getInstance();
|
||||
|
||||
private Hash rxHash = null;
|
||||
|
||||
@@ -41,7 +41,7 @@ public final class I2PDatagramDissector {
|
||||
|
||||
private Destination rxDest;
|
||||
|
||||
private byte[] rxPayload = new byte[DGRAM_BUFSIZE];
|
||||
private final byte[] rxPayload = new byte[DGRAM_BUFSIZE];
|
||||
|
||||
private int rxPayloadLen = 0;
|
||||
|
||||
@@ -63,36 +63,36 @@ public final class I2PDatagramDissector {
|
||||
public void loadI2PDatagram(byte[] dgram) throws DataFormatException {
|
||||
ByteArrayInputStream dgStream = new ByteArrayInputStream(dgram);
|
||||
byte[] rxTrimmedPayload;
|
||||
|
||||
// set invalid(very important!)
|
||||
this.valid = false;
|
||||
|
||||
|
||||
// set invalid(very important!)
|
||||
this.valid = false;
|
||||
|
||||
try {
|
||||
rxDest = new Destination();
|
||||
rxSign = new Signature();
|
||||
|
||||
// read destination
|
||||
|
||||
// read destination
|
||||
rxDest.readBytes(dgStream);
|
||||
|
||||
// read signature
|
||||
|
||||
// read signature
|
||||
rxSign.readBytes(dgStream);
|
||||
|
||||
// read payload
|
||||
|
||||
// read payload
|
||||
rxPayloadLen = dgStream.read(rxPayload);
|
||||
|
||||
// calculate the hash of the payload
|
||||
|
||||
// calculate the hash of the payload
|
||||
this.rxHash = hashGen.calculateHash(rxPayload, 0, rxPayloadLen);
|
||||
assert this.hashGen.calculateHash(this.extractPayload()).equals(this.rxHash);
|
||||
assert this.hashGen.calculateHash(this.extractPayload()).equals(this.rxHash);
|
||||
} catch (IOException e) {
|
||||
_log.error("Caught IOException - INCONSISTENT STATE!", e);
|
||||
} catch(AssertionError e) {
|
||||
_log.error("Assertion failed!", e);
|
||||
}
|
||||
|
||||
_log.error("Assertion failed!", e);
|
||||
}
|
||||
|
||||
//_log.debug("Datagram payload size: " + rxPayloadLen + "; content:\n"
|
||||
// + HexDump.dump(rxPayload, 0, rxPayloadLen));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the payload carried by an I2P repliable datagram (previously loaded
|
||||
* with the loadI2PDatagram() method), verifying the datagram signature.
|
||||
@@ -106,7 +106,7 @@ public final class I2PDatagramDissector {
|
||||
|
||||
return this.extractPayload();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the sender of an I2P repliable datagram (previously loaded with the
|
||||
* loadI2PDatagram() method), verifying the datagram signature.
|
||||
@@ -118,23 +118,23 @@ public final class I2PDatagramDissector {
|
||||
public Destination getSender() throws I2PInvalidDatagramException {
|
||||
this.verifySignature();
|
||||
|
||||
return this.extractSender();
|
||||
return this.extractSender();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the hash of the payload of an I2P repliable datagram (previously
|
||||
* loaded with the loadI2PDatagram() method), verifying the datagram
|
||||
* signature.
|
||||
* @return The hash of the payload of the I2P repliable datagram
|
||||
* @throws I2PInvalidDatagramException if the signature verification fails
|
||||
*/
|
||||
public Hash getHash() throws I2PInvalidDatagramException {
|
||||
// make sure it has a valid signature
|
||||
this.verifySignature();
|
||||
|
||||
return this.extractHash();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the hash of the payload of an I2P repliable datagram (previously
|
||||
* loaded with the loadI2PDatagram() method), verifying the datagram
|
||||
* signature.
|
||||
* @return The hash of the payload of the I2P repliable datagram
|
||||
* @throws I2PInvalidDatagramException if the signature verification fails
|
||||
*/
|
||||
public Hash getHash() throws I2PInvalidDatagramException {
|
||||
// make sure it has a valid signature
|
||||
this.verifySignature();
|
||||
|
||||
return this.extractHash();
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the payload carried by an I2P repliable datagram (previously
|
||||
* loaded with the loadI2PDatagram() method), without verifying the
|
||||
@@ -145,10 +145,10 @@ public final class I2PDatagramDissector {
|
||||
public byte[] extractPayload() {
|
||||
byte[] retPayload = new byte[this.rxPayloadLen];
|
||||
System.arraycopy(this.rxPayload, 0, retPayload, 0, this.rxPayloadLen);
|
||||
|
||||
|
||||
return retPayload;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extract the sender of an I2P repliable datagram (previously loaded with
|
||||
* the loadI2PDatagram() method), without verifying the datagram signature.
|
||||
@@ -168,31 +168,30 @@ public final class I2PDatagramDissector {
|
||||
|
||||
return retDest;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the hash of the payload of an I2P repliable datagram (previously
|
||||
* loaded with the loadI2PDatagram() method), without verifying the datagram
|
||||
* signature.
|
||||
* @return The hash of the payload of the I2P repliable datagram
|
||||
*/
|
||||
public Hash extractHash() {
|
||||
return this.rxHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the hash of the payload of an I2P repliable datagram (previously
|
||||
* loaded with the loadI2PDatagram() method), without verifying the datagram
|
||||
* signature.
|
||||
* @return The hash of the payload of the I2P repliable datagram
|
||||
*/
|
||||
public Hash extractHash() {
|
||||
return this.rxHash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify the signature of this datagram (previously loaded with the
|
||||
* loadI2PDatagram() method)
|
||||
* @throws I2PInvalidDatagramException if the signature is invalid
|
||||
* @throws I2PInvalidDatagramException if the signature is invalid
|
||||
*/
|
||||
public void verifySignature() throws I2PInvalidDatagramException {
|
||||
// first check if it already got validated
|
||||
if(this.valid)
|
||||
return;
|
||||
|
||||
if (rxSign == null || rxSign.getData() == null ||
|
||||
rxDest == null || rxDest.getSigningPublicKey() == null)
|
||||
if (rxSign == null || rxSign.getData() == null || rxDest == null || rxDest.getSigningPublicKey() == null)
|
||||
throw new I2PInvalidDatagramException("Datagram not yet read");
|
||||
|
||||
|
||||
// now validate
|
||||
if (!this.dsaEng.verifySignature(rxSign, rxHash.getData(), rxDest.getSigningPublicKey()))
|
||||
throw new I2PInvalidDatagramException("Incorrect I2P repliable datagram signature");
|
||||
|
||||
@@ -28,15 +28,15 @@ public final class I2PDatagramMaker {
|
||||
|
||||
private static Log _log = new Log(I2PDatagramMaker.class);
|
||||
|
||||
private static int DGRAM_BUFSIZE = 32768;
|
||||
private static final int DGRAM_BUFSIZE = 32768;
|
||||
|
||||
private SHA256Generator hashGen = SHA256Generator.getInstance();
|
||||
private DSAEngine dsaEng = DSAEngine.getInstance();
|
||||
private final SHA256Generator hashGen = SHA256Generator.getInstance();
|
||||
private final DSAEngine dsaEng = DSAEngine.getInstance();
|
||||
|
||||
private SigningPrivateKey sxPrivKey = null;
|
||||
private byte[] sxDestBytes = null;
|
||||
|
||||
private ByteArrayOutputStream sxDGram = new ByteArrayOutputStream(DGRAM_BUFSIZE);
|
||||
private final ByteArrayOutputStream sxDGram = new ByteArrayOutputStream(DGRAM_BUFSIZE);
|
||||
|
||||
/**
|
||||
* Construct a new I2PDatagramMaker that will be able to create I2P
|
||||
@@ -70,12 +70,12 @@ public final class I2PDatagramMaker {
|
||||
|
||||
try {
|
||||
sxDGram.write(sxDestBytes);
|
||||
|
||||
|
||||
dsaEng.sign(hashGen.calculateHash(payload).toByteArray(),
|
||||
sxPrivKey).writeBytes(sxDGram);
|
||||
|
||||
|
||||
sxDGram.write(payload);
|
||||
|
||||
|
||||
return sxDGram.toByteArray();
|
||||
} catch (IOException e) {
|
||||
_log.error("Caught IOException", e);
|
||||
|
||||
@@ -16,10 +16,10 @@ package net.i2p.client.datagram;
|
||||
public class I2PInvalidDatagramException extends Exception {
|
||||
|
||||
public I2PInvalidDatagramException() {
|
||||
super();
|
||||
super();
|
||||
}
|
||||
|
||||
public I2PInvalidDatagramException(String s) {
|
||||
super(s);
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,6 +179,7 @@ public class DataHelper {
|
||||
* @param props source
|
||||
* @return new offset
|
||||
*/
|
||||
@Deprecated
|
||||
public static int toProperties(byte target[], int offset, Properties props) throws DataFormatException, IOException {
|
||||
if (props != null) {
|
||||
OrderedProperties p = new OrderedProperties();
|
||||
@@ -219,6 +220,7 @@ public class DataHelper {
|
||||
* @param target returned Properties
|
||||
* @return new offset
|
||||
*/
|
||||
@Deprecated
|
||||
public static int fromProperties(byte source[], int offset, Properties target) throws DataFormatException, IOException {
|
||||
int size = (int)fromLong(source, offset, 2);
|
||||
offset += 2;
|
||||
@@ -254,6 +256,7 @@ public class DataHelper {
|
||||
*
|
||||
* @throws RuntimeException if either is too long.
|
||||
*/
|
||||
@Deprecated
|
||||
public static byte[] toProperties(Properties opts) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(2);
|
||||
@@ -544,6 +547,7 @@ public class DataHelper {
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static byte[] toDate(Date date) throws IllegalArgumentException {
|
||||
if (date == null)
|
||||
return toLong(DATE_LENGTH, 0L);
|
||||
@@ -678,6 +682,7 @@ public class DataHelper {
|
||||
* @throws IOException if there is an IO error writing the boolean
|
||||
* @deprecated unused
|
||||
*/
|
||||
@Deprecated
|
||||
public static void writeBoolean(OutputStream out, Boolean bool)
|
||||
throws DataFormatException, IOException {
|
||||
if (bool == null)
|
||||
@@ -689,6 +694,7 @@ public class DataHelper {
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static Boolean fromBoolean(byte data[], int offset) {
|
||||
if (data[offset] == BOOLEAN_TRUE)
|
||||
return Boolean.TRUE;
|
||||
@@ -699,11 +705,13 @@ public class DataHelper {
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static void toBoolean(byte data[], int offset, boolean value) {
|
||||
data[offset] = (value ? BOOLEAN_TRUE : BOOLEAN_FALSE);
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static void toBoolean(byte data[], int offset, Boolean value) {
|
||||
if (value == null)
|
||||
data[offset] = BOOLEAN_UNKNOWN;
|
||||
@@ -712,12 +720,16 @@ public class DataHelper {
|
||||
}
|
||||
|
||||
/** deprecated - used only in DatabaseLookupMessage */
|
||||
@Deprecated
|
||||
public static final byte BOOLEAN_TRUE = 0x1;
|
||||
/** deprecated - used only in DatabaseLookupMessage */
|
||||
@Deprecated
|
||||
public static final byte BOOLEAN_FALSE = 0x0;
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static final byte BOOLEAN_UNKNOWN = 0x2;
|
||||
/** @deprecated unused */
|
||||
@Deprecated
|
||||
public static final int BOOLEAN_LENGTH = 1;
|
||||
|
||||
//
|
||||
@@ -780,6 +792,7 @@ public class DataHelper {
|
||||
* Compare two integers, really just for consistency.
|
||||
* @deprecated inefficient
|
||||
*/
|
||||
@Deprecated
|
||||
public final static boolean eq(int lhs, int rhs) {
|
||||
return lhs == rhs;
|
||||
}
|
||||
@@ -788,6 +801,7 @@ public class DataHelper {
|
||||
* Compare two longs, really just for consistency.
|
||||
* @deprecated inefficient
|
||||
*/
|
||||
@Deprecated
|
||||
public final static boolean eq(long lhs, long rhs) {
|
||||
return lhs == rhs;
|
||||
}
|
||||
@@ -796,6 +810,7 @@ public class DataHelper {
|
||||
* Compare two bytes, really just for consistency.
|
||||
* @deprecated inefficient
|
||||
*/
|
||||
@Deprecated
|
||||
public final static boolean eq(byte lhs, byte rhs) {
|
||||
return lhs == rhs;
|
||||
}
|
||||
@@ -974,6 +989,7 @@ public class DataHelper {
|
||||
* @return true if the line was read, false if eof was reached before a
|
||||
* newline was found
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean readLine(InputStream in, StringBuffer buf) throws IOException {
|
||||
return readLine(in, buf, null);
|
||||
}
|
||||
@@ -987,6 +1003,7 @@ public class DataHelper {
|
||||
* Warning - 8KB line length limit as of 0.7.13, @throws IOException if exceeded
|
||||
* @deprecated use StringBuilder version
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean readLine(InputStream in, StringBuffer buf, Sha256Standalone hash) throws IOException {
|
||||
int c = -1;
|
||||
int i = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DateAndFlags extends DataStructureImpl {
|
||||
/**
|
||||
* @param flags 0 - 65535
|
||||
*/
|
||||
public DateAndFlags(int flags, long date) {
|
||||
public DateAndFlags(long date, int flags) {
|
||||
_flags = flags;
|
||||
_date = date;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class DateAndFlags extends DataStructureImpl {
|
||||
/**
|
||||
* @param flags 0 - 65535
|
||||
*/
|
||||
public DateAndFlags(int flags, Date date) {
|
||||
public DateAndFlags(Date date, int flags) {
|
||||
_flags = flags;
|
||||
_date = date.getTime();
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import net.i2p.data.i2cp.I2CPMessageReader;
|
||||
import net.i2p.util.I2PThread;
|
||||
|
||||
/**
|
||||
* Get messages off an In-JVM queue, zero-copy
|
||||
* Get messages off an In-JVM queue, zero-copy.
|
||||
*
|
||||
* @author zzz
|
||||
* @since 0.8.3
|
||||
@@ -13,6 +13,9 @@ import net.i2p.util.I2PThread;
|
||||
public class QueuedI2CPMessageReader extends I2CPMessageReader {
|
||||
private final I2CPMessageQueue in;
|
||||
|
||||
/**
|
||||
* Creates a new instance of this QueuedMessageReader and spawns a pumper thread.
|
||||
*/
|
||||
public QueuedI2CPMessageReader(I2CPMessageQueue in, I2CPMessageEventListener lsnr) {
|
||||
super(lsnr);
|
||||
this.in = in;
|
||||
@@ -25,13 +28,19 @@ public class QueuedI2CPMessageReader extends I2CPMessageReader {
|
||||
public QueuedI2CPMessageReaderRunner() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Shuts the pumper down.
|
||||
*/
|
||||
@Override
|
||||
public void cancelRunner() {
|
||||
super.cancelRunner();
|
||||
_readerThread.interrupt();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pumps messages from the incoming message queue to the listener.
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
while (_stayAlive) {
|
||||
@@ -40,11 +49,15 @@ public class QueuedI2CPMessageReader extends I2CPMessageReader {
|
||||
I2CPMessage msg = null;
|
||||
try {
|
||||
msg = in.take();
|
||||
if (msg.getType() == PoisonI2CPMessage.MESSAGE_TYPE)
|
||||
if (msg.getType() == PoisonI2CPMessage.MESSAGE_TYPE) {
|
||||
_listener.disconnected(QueuedI2CPMessageReader.this);
|
||||
cancelRunner();
|
||||
else
|
||||
} else {
|
||||
_listener.messageReceived(QueuedI2CPMessageReader.this, msg);
|
||||
} catch (InterruptedException ie) {}
|
||||
}
|
||||
} catch (InterruptedException ie) {
|
||||
// hint that we probably should check the continue running flag
|
||||
}
|
||||
}
|
||||
// ??? unused
|
||||
if (_stayAlive && !_doRun) {
|
||||
|
||||
@@ -54,7 +54,7 @@ public class StatManager {
|
||||
"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.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*," +
|
||||
|
||||
@@ -5,10 +5,10 @@ import java.util.List;
|
||||
import net.i2p.I2PAppContext;
|
||||
|
||||
class Executor implements Runnable {
|
||||
private I2PAppContext _context;
|
||||
private final I2PAppContext _context;
|
||||
private Log _log;
|
||||
private final List _readyEvents;
|
||||
private SimpleStore runn;
|
||||
private final SimpleStore runn;
|
||||
|
||||
public Executor(I2PAppContext ctx, Log log, List events, SimpleStore x) {
|
||||
_context = ctx;
|
||||
@@ -31,9 +31,10 @@ class Executor implements Runnable {
|
||||
try {
|
||||
evt.timeReached();
|
||||
} catch (Throwable t) {
|
||||
log("wtf, event borked: " + evt, t);
|
||||
log("Executing task " + evt + " exited unexpectedly, please report", t);
|
||||
}
|
||||
long time = _context.clock().now() - before;
|
||||
// FIXME _log won't be non-null unless we already had a CRIT
|
||||
if ( (time > 1000) && (_log != null) && (_log.shouldLog(Log.WARN)) )
|
||||
_log.warn("wtf, event execution took " + time + ": " + evt);
|
||||
}
|
||||
|
||||
@@ -30,10 +30,10 @@ public class SimpleScheduler {
|
||||
public static SimpleScheduler getInstance() { return _instance; }
|
||||
private static final int MIN_THREADS = 2;
|
||||
private static final int MAX_THREADS = 4;
|
||||
private I2PAppContext _context;
|
||||
private Log _log;
|
||||
private ScheduledThreadPoolExecutor _executor;
|
||||
private String _name;
|
||||
private final I2PAppContext _context;
|
||||
private final Log _log;
|
||||
private final ScheduledThreadPoolExecutor _executor;
|
||||
private final String _name;
|
||||
private int _count;
|
||||
private final int _threads;
|
||||
|
||||
@@ -42,7 +42,6 @@ public class SimpleScheduler {
|
||||
_context = I2PAppContext.getGlobalContext();
|
||||
_log = _context.logManager().getLog(SimpleScheduler.class);
|
||||
_name = name;
|
||||
_count = 0;
|
||||
long maxMemory = Runtime.getRuntime().maxMemory();
|
||||
_threads = (int) Math.max(MIN_THREADS, Math.min(MAX_THREADS, 1 + (maxMemory / (32*1024*1024))));
|
||||
_executor = new ScheduledThreadPoolExecutor(_threads, new CustomThreadFactory());
|
||||
@@ -139,7 +138,7 @@ public class SimpleScheduler {
|
||||
try {
|
||||
_timedEvent.timeReached();
|
||||
} catch (Throwable t) {
|
||||
_log.log(Log.CRIT, _name + " wtf, event borked: " + _timedEvent, t);
|
||||
_log.log(Log.CRIT, _name + ": Scheduled task " + _timedEvent + " exited unexpectedly, please report", t);
|
||||
}
|
||||
long time = System.currentTimeMillis() - before;
|
||||
if (time > 1000 && _log.shouldLog(Log.WARN))
|
||||
|
||||
@@ -14,6 +14,8 @@ import net.i2p.I2PAppContext;
|
||||
* appropriate time. The method that is fired however should NOT block (otherwise
|
||||
* they b0rk the timer).
|
||||
*
|
||||
* WARNING - Deprecated.
|
||||
* This is an inefficient mess. Use SimpleScheduler or SimpleTimer2 if possible.
|
||||
*/
|
||||
public class SimpleTimer {
|
||||
private static final SimpleTimer _instance = new SimpleTimer();
|
||||
|
||||
@@ -29,10 +29,10 @@ public class SimpleTimer2 {
|
||||
public static SimpleTimer2 getInstance() { return _instance; }
|
||||
private static final int MIN_THREADS = 2;
|
||||
private static final int MAX_THREADS = 4;
|
||||
private I2PAppContext _context;
|
||||
private final I2PAppContext _context;
|
||||
private static Log _log; // static so TimedEvent can use it
|
||||
private ScheduledThreadPoolExecutor _executor;
|
||||
private String _name;
|
||||
private final ScheduledThreadPoolExecutor _executor;
|
||||
private final String _name;
|
||||
private int _count;
|
||||
private final int _threads;
|
||||
|
||||
@@ -223,7 +223,7 @@ public class SimpleTimer2 {
|
||||
try {
|
||||
timeReached();
|
||||
} catch (Throwable t) {
|
||||
_log.log(Log.CRIT, _pool + " wtf, event borked: " + this, t);
|
||||
_log.log(Log.CRIT, _pool + ": Timed task " + this + " exited unexpectedly, please report", t);
|
||||
}
|
||||
long time = System.currentTimeMillis() - before;
|
||||
if (time > 500 && _log.shouldLog(Log.WARN))
|
||||
|
||||
@@ -25,4 +25,50 @@ public class LeaseSetTest extends StructureTest {
|
||||
return leaseSet;
|
||||
}
|
||||
public DataStructure createStructureToRead() { return new LeaseSet(); }
|
||||
|
||||
public void testGetLeaseInvalid() {
|
||||
// create test subject
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// should contain no leases now..
|
||||
try {
|
||||
assertNull(subj.getLease(0));
|
||||
} catch(RuntimeException exc) {
|
||||
// all good
|
||||
}
|
||||
|
||||
// this shouldn't work either
|
||||
try {
|
||||
assertNull(subj.getLease(-1));
|
||||
} catch(RuntimeException exc) {
|
||||
// all good
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddLeaseNull() {
|
||||
// create test subject
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// now add an null lease
|
||||
try {
|
||||
subj.addLease(null);
|
||||
fail("Failed at failing.");
|
||||
} catch(IllegalArgumentException exc) {
|
||||
// all good
|
||||
}
|
||||
}
|
||||
|
||||
public void testAddLeaseInvalid() {
|
||||
// create test subject
|
||||
LeaseSet subj = new LeaseSet();
|
||||
|
||||
// try to add completely invalid lease(ie. no data)
|
||||
try {
|
||||
subj.addLease(new Lease());
|
||||
fail("Failed at failing.");
|
||||
} catch(IllegalArgumentException exc) {
|
||||
// all good
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ public class RouterAddressTest extends StructureTest {
|
||||
addr.setOptions(options);
|
||||
addr.setTransportStyle("Blah");
|
||||
assertFalse(addr.equals(null));
|
||||
assertFalse(addr.equals(""));
|
||||
}
|
||||
|
||||
public void testToString(){
|
||||
@@ -73,5 +74,7 @@ public class RouterAddressTest extends StructureTest {
|
||||
addr.setOptions(options);
|
||||
addr.setTransportStyle("Blah");
|
||||
addr.toString();
|
||||
addr.setOptions(null);
|
||||
addr.toString();
|
||||
}
|
||||
}
|
||||
|
||||
96
core/java/test/net/i2p/data/SimpleDataStructureTest.java
Normal file
96
core/java/test/net/i2p/data/SimpleDataStructureTest.java
Normal file
@@ -0,0 +1,96 @@
|
||||
package net.i2p.data;
|
||||
/*
|
||||
* free (adj.): unencumbered; not under the control of others
|
||||
* Written by jrandom in 2003 and released into the public domain
|
||||
* with no warranty of any kind, either expressed or implied.
|
||||
* It probably won't make your computer catch on fire, or eat
|
||||
* your children, but it might. Use at your own risk.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test harness for the simple data structure
|
||||
*
|
||||
* @author welterde
|
||||
*/
|
||||
public class SimpleDataStructureTest extends TestCase {
|
||||
|
||||
public void testSetDataImmutable() throws Exception {
|
||||
// create new test subject
|
||||
TestStruct struct = new TestStruct();
|
||||
|
||||
// try to set null object.. should not fail..
|
||||
struct.setData(null);
|
||||
|
||||
// set data to something
|
||||
struct.setData(new byte[3]);
|
||||
|
||||
// now setting it to null should fail
|
||||
try {
|
||||
struct.setData(null);
|
||||
fail("Should not have allowed us to change this..");
|
||||
} catch(RuntimeException exc) {
|
||||
// all good
|
||||
}
|
||||
|
||||
// setting it to something non-null should fail as well.
|
||||
try {
|
||||
struct.setData(new byte[3]);
|
||||
fail("Should not have allowed us to change this..");
|
||||
} catch(RuntimeException exc) {
|
||||
// all good
|
||||
}
|
||||
}
|
||||
|
||||
public void testReadBytesImmutable() throws Exception {
|
||||
// create new test subject
|
||||
TestStruct struct = new TestStruct();
|
||||
|
||||
// load some data using setData
|
||||
struct.setData(new byte[3]);
|
||||
|
||||
// now try to load via readBytes
|
||||
try {
|
||||
struct.readBytes(null);
|
||||
fail("blah blah blah..");
|
||||
} catch(RuntimeException exc) {
|
||||
// all good
|
||||
}
|
||||
}
|
||||
|
||||
public void testToBase64Safe() throws Exception {
|
||||
// create new test subject
|
||||
TestStruct struct = new TestStruct();
|
||||
|
||||
// now try to get the Base64.. should not throw an exception, but should not be an empty string either
|
||||
assertNull(struct.toBase64());
|
||||
}
|
||||
|
||||
public void testCalculateHashSafe() throws Exception {
|
||||
// create new test subject
|
||||
TestStruct struct = new TestStruct();
|
||||
|
||||
// now try to get the hash.. should not throw an exception
|
||||
assertNull(struct.calculateHash());
|
||||
}
|
||||
|
||||
public void testHashCodeSafe() throws Exception {
|
||||
// create new test subject
|
||||
TestStruct struct = new TestStruct();
|
||||
|
||||
// just make sure it doesn't explode in our face
|
||||
struct.hashCode();
|
||||
}
|
||||
|
||||
public class TestStruct extends SimpleDataStructure {
|
||||
public int length() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.i2p.stat;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -7,7 +8,7 @@ import junit.framework.TestCase;
|
||||
|
||||
public class RateTest extends TestCase {
|
||||
public void testRate() throws Exception{
|
||||
Rate rate = new Rate(1000);
|
||||
Rate rate = new Rate(5000);
|
||||
for (int i = 0; i < 50; i++) {
|
||||
Thread.sleep(20);
|
||||
rate.addData(i * 100, 20);
|
||||
@@ -19,10 +20,10 @@ public class RateTest extends TestCase {
|
||||
byte data[] = buf.toString().getBytes();
|
||||
|
||||
Properties props = new Properties();
|
||||
props.load(new java.io.ByteArrayInputStream(data));
|
||||
props.load(new ByteArrayInputStream(data));
|
||||
|
||||
Rate r = new Rate(props, "rate.test", true);
|
||||
|
||||
assertEquals(r, rate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.i2p.stat;
|
||||
|
||||
public class SizeTest {
|
||||
public class SizeMeasure {
|
||||
public static void main(String args[]) {
|
||||
testRateSize(100); //117KB
|
||||
testRateSize(100000); // 4.5MB
|
||||
@@ -82,28 +82,37 @@ public class LogSettingsTest extends TestCase {
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("DEBUG" + ": debug");
|
||||
log.info("DEBUG" + ": info");
|
||||
log.warn("DEBUG" + ": warn");
|
||||
log.error("DEBUG" + ": error");
|
||||
log.log(Log.CRIT, "DEBUG" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
String l5 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*DEBUG: debug") &&
|
||||
l2.matches(".*DEBUG: info") &&
|
||||
l3.matches(".*DEBUG: warn") &&
|
||||
l4.matches(".*DEBUG: error") &&
|
||||
l5.matches(".*DEBUG: crit")
|
||||
);
|
||||
try {
|
||||
log.debug("DEBUG" + ": debug");
|
||||
log.info("DEBUG" + ": info");
|
||||
log.warn("DEBUG" + ": warn");
|
||||
log.error("DEBUG" + ": error");
|
||||
log.log(Log.CRIT, "DEBUG" + ": crit");
|
||||
|
||||
// Wait for the LogWriter to flush, then write extra stuff so
|
||||
// the test doesn't hang on failure
|
||||
try { Thread.sleep(12*1000); } catch (InterruptedException ie) {}
|
||||
for (int i = 0; i < 5; i++)
|
||||
pout.println("");
|
||||
pout.flush();
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
String l5 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*DEBUG: debug") &&
|
||||
l2.matches(".*DEBUG: info") &&
|
||||
l3.matches(".*DEBUG: warn") &&
|
||||
l4.matches(".*DEBUG: error") &&
|
||||
l5.matches(".*DEBUG: crit")
|
||||
);
|
||||
} finally {
|
||||
System.setOut(systemOut);
|
||||
pout.close();
|
||||
}
|
||||
|
||||
System.setOut(systemOut);
|
||||
|
||||
}
|
||||
|
||||
@@ -122,26 +131,35 @@ public class LogSettingsTest extends TestCase {
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("INFO" + ": debug");
|
||||
log.info("INFO" + ": info");
|
||||
log.warn("INFO" + ": warn");
|
||||
log.error("INFO" + ": error");
|
||||
log.log(Log.CRIT, "INFO" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*INFO: info") &&
|
||||
l2.matches(".*INFO: warn") &&
|
||||
l3.matches(".*INFO: error") &&
|
||||
l4.matches(".*INFO: crit")
|
||||
);
|
||||
try {
|
||||
log.debug("INFO" + ": debug");
|
||||
log.info("INFO" + ": info");
|
||||
log.warn("INFO" + ": warn");
|
||||
log.error("INFO" + ": error");
|
||||
log.log(Log.CRIT, "INFO" + ": crit");
|
||||
|
||||
// Wait for the LogWriter to flush, then write extra stuff so
|
||||
// the test doesn't hang on failure
|
||||
try { Thread.sleep(12*1000); } catch (InterruptedException ie) {}
|
||||
for (int i = 0; i < 4; i++)
|
||||
pout.println("");
|
||||
pout.flush();
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
String l4 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*INFO: info") &&
|
||||
l2.matches(".*INFO: warn") &&
|
||||
l3.matches(".*INFO: error") &&
|
||||
l4.matches(".*INFO: crit")
|
||||
);
|
||||
} finally {
|
||||
System.setOut(systemOut);
|
||||
pout.close();
|
||||
}
|
||||
|
||||
System.setOut(systemOut);
|
||||
|
||||
}
|
||||
|
||||
@@ -160,24 +178,33 @@ public class LogSettingsTest extends TestCase {
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("WARN" + ": debug");
|
||||
log.info("WARN" + ": info");
|
||||
log.warn("WARN" + ": warn");
|
||||
log.error("WARN" + ": error");
|
||||
log.log(Log.CRIT, "WARN" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*WARN: warn") &&
|
||||
l2.matches(".*WARN: error") &&
|
||||
l3.matches(".*WARN: crit")
|
||||
);
|
||||
try {
|
||||
log.debug("WARN" + ": debug");
|
||||
log.info("WARN" + ": info");
|
||||
log.warn("WARN" + ": warn");
|
||||
log.error("WARN" + ": error");
|
||||
log.log(Log.CRIT, "WARN" + ": crit");
|
||||
|
||||
// Wait for the LogWriter to flush, then write extra stuff so
|
||||
// the test doesn't hang on failure
|
||||
try { Thread.sleep(12*1000); } catch (InterruptedException ie) {}
|
||||
for (int i = 0; i < 3; i++)
|
||||
pout.println("");
|
||||
pout.flush();
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
String l3 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*WARN: warn") &&
|
||||
l2.matches(".*WARN: error") &&
|
||||
l3.matches(".*WARN: crit")
|
||||
);
|
||||
} finally {
|
||||
System.setOut(systemOut);
|
||||
pout.close();
|
||||
}
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
public void testError() throws IOException{
|
||||
@@ -195,22 +222,31 @@ public class LogSettingsTest extends TestCase {
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("ERROR" + ": debug");
|
||||
log.info("ERROR" + ": info");
|
||||
log.warn("ERROR" + ": warn");
|
||||
log.error("ERROR" + ": error");
|
||||
log.log(Log.CRIT, "ERROR" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*ERROR: error") &&
|
||||
l2.matches(".*ERROR: crit")
|
||||
);
|
||||
try {
|
||||
log.debug("ERROR" + ": debug");
|
||||
log.info("ERROR" + ": info");
|
||||
log.warn("ERROR" + ": warn");
|
||||
log.error("ERROR" + ": error");
|
||||
log.log(Log.CRIT, "ERROR" + ": crit");
|
||||
|
||||
// Wait for the LogWriter to flush, then write extra stuff so
|
||||
// the test doesn't hang on failure
|
||||
try { Thread.sleep(12*1000); } catch (InterruptedException ie) {}
|
||||
for (int i = 0; i < 2; i++)
|
||||
pout.println("");
|
||||
pout.flush();
|
||||
String l1 = in.readLine();
|
||||
String l2 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*ERROR: error") &&
|
||||
l2.matches(".*ERROR: crit")
|
||||
);
|
||||
} finally {
|
||||
System.setOut(systemOut);
|
||||
pout.close();
|
||||
}
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
public void testCrit() throws IOException {
|
||||
@@ -228,21 +264,29 @@ public class LogSettingsTest extends TestCase {
|
||||
|
||||
System.setOut(pout);
|
||||
|
||||
log.debug("CRIT" + ": debug");
|
||||
log.info("CRIT" + ": info");
|
||||
log.warn("CRIT" + ": warn");
|
||||
log.error("CRIT" + ": error");
|
||||
log.log(Log.CRIT, "CRIT" + ": crit");
|
||||
_context.logManager().shutdown();
|
||||
|
||||
String l1 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*CRIT: crit")
|
||||
);
|
||||
try {
|
||||
log.debug("CRIT" + ": debug");
|
||||
log.info("CRIT" + ": info");
|
||||
log.warn("CRIT" + ": warn");
|
||||
log.error("CRIT" + ": error");
|
||||
log.log(Log.CRIT, "CRIT" + ": crit");
|
||||
|
||||
// Wait for the LogWriter to flush, then write extra stuff so
|
||||
// the test doesn't hang on failure
|
||||
try { Thread.sleep(12*1000); } catch (InterruptedException ie) {}
|
||||
pout.println("");
|
||||
pout.flush();
|
||||
String l1 = in.readLine();
|
||||
|
||||
assertTrue(
|
||||
l1.matches(".*CRIT: crit")
|
||||
);
|
||||
} finally {
|
||||
System.setOut(systemOut);
|
||||
pout.close();
|
||||
}
|
||||
|
||||
System.setOut(systemOut);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user