propagate from branch 'i2p.i2p.zzz.test4' (head 7b50b6c3d48da68078a86a53e55e2c18f55685e8)

to branch 'i2p.i2p' (head ebce577e19b70c281daacc5277f98e9bb2bb9630)
This commit is contained in:
zzz
2011-03-08 13:31:57 +00:00
183 changed files with 30058 additions and 11421 deletions

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.3";
public final static String VERSION = "0.8.4";
public static void main(String args[]) {
System.out.println("I2P Core version: " + VERSION);

View File

@ -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");

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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();
}

View File

@ -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) {

View File

@ -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*," +

View File

@ -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);
}

View File

@ -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))

View File

@ -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();

View File

@ -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))