various cleanups, javadocs, logging
This commit is contained in:
@ -99,9 +99,9 @@ public class MessageInputStream extends InputStream {
|
||||
}
|
||||
}
|
||||
private long[] locked_getNacks() {
|
||||
List ids = null;
|
||||
List<Long> ids = null;
|
||||
for (long i = _highestReadyBlockId + 1; i < _highestBlockId; i++) {
|
||||
Long l = new Long(i);
|
||||
Long l = Long.valueOf(i);
|
||||
if (_notYetReadyBlocks.containsKey(l)) {
|
||||
// ACK
|
||||
} else {
|
||||
@ -113,7 +113,7 @@ public class MessageInputStream extends InputStream {
|
||||
if (ids != null) {
|
||||
long rv[] = new long[ids.size()];
|
||||
for (int i = 0; i < rv.length; i++)
|
||||
rv[i] = ((Long)ids.get(i)).longValue();
|
||||
rv[i] = ids.get(i).longValue();
|
||||
return rv;
|
||||
} else {
|
||||
return null;
|
||||
|
@ -11,6 +11,7 @@ import net.i2p.data.ByteArray;
|
||||
* needs to be done (e.g. write(foo); toByteArray();), call releaseBuffer
|
||||
* to put the buffer back into the cache.
|
||||
*
|
||||
* @deprecated unused
|
||||
*/
|
||||
public class CachingByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
private ByteCache _cache;
|
||||
|
@ -66,6 +66,22 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
throw new DataFormatException("Bad bytes", ime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the header, then read the rest into buffer, then call
|
||||
* readMessage in the implemented message type
|
||||
*
|
||||
* Specifically:
|
||||
* 1 byte type (if caller didn't read already, as specified by the type param
|
||||
* 4 byte ID
|
||||
* 8 byte expiration
|
||||
* 2 byte size
|
||||
* 1 byte checksum
|
||||
* size bytes of payload (read by readMessage() in implementation)
|
||||
*
|
||||
* @param type the message type or -1 if we should read it here
|
||||
* @param buffer temp buffer to use
|
||||
*/
|
||||
public int readBytes(InputStream in, int type, byte buffer[]) throws I2NPMessageException, IOException {
|
||||
try {
|
||||
if (type < 0)
|
||||
@ -268,6 +284,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
*/
|
||||
|
||||
|
||||
/** used by SSU only */
|
||||
public int toRawByteArray(byte buffer[]) {
|
||||
verifyUnwritten();
|
||||
if (RAW_FULL_SIZE)
|
||||
@ -298,9 +315,13 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
}
|
||||
|
||||
|
||||
/*****
|
||||
public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset, int len) throws I2NPMessageException {
|
||||
return fromRawByteArray(ctx, buffer, offset, len, new I2NPMessageHandler(ctx));
|
||||
}
|
||||
*****/
|
||||
|
||||
/** used by SSU only */
|
||||
public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset, int len, I2NPMessageHandler handler) throws I2NPMessageException {
|
||||
int type = (int)DataHelper.fromLong(buffer, offset, 1);
|
||||
offset++;
|
||||
|
@ -126,7 +126,7 @@ public class OutNetMessage {
|
||||
}
|
||||
return ZERO;
|
||||
}
|
||||
private static final Long ZERO = new Long(0);
|
||||
private static final Long ZERO = Long.valueOf(0);
|
||||
private void locked_initTimestamps() {
|
||||
if (_timestamps == null) {
|
||||
_timestamps = new HashMap(8);
|
||||
|
@ -772,8 +772,8 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
private long acquiredOn;
|
||||
|
||||
PrepBuffer() {
|
||||
unencrypted = new byte[16*1024];
|
||||
base = new byte[16*1024];
|
||||
unencrypted = new byte[BUFFER_SIZE];
|
||||
base = new byte[BUFFER_SIZE];
|
||||
pad = new byte[16];
|
||||
crc = new Adler32();
|
||||
}
|
||||
@ -1033,7 +1033,7 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
/** _decryptBlockBuf contains another cleartext block of I2NP to parse */
|
||||
private boolean recvUnencryptedI2NP() {
|
||||
_curReadState.receiveBlock(_decryptBlockBuf);
|
||||
if (_curReadState.getSize() > 16*1024) {
|
||||
if (_curReadState.getSize() > BUFFER_SIZE) {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("I2NP message too big - size: " + _curReadState.getSize() + " Dropping " + toString());
|
||||
_context.statManager().addRateData("ntcp.corruptTooLargeI2NP", _curReadState.getSize(), getUptime());
|
||||
@ -1112,7 +1112,8 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
return obj == this;
|
||||
}
|
||||
|
||||
private final static List _i2npHandlers = new ArrayList(4);
|
||||
private static final int MAX_HANDLERS = 4;
|
||||
private final static List _i2npHandlers = new ArrayList(MAX_HANDLERS);
|
||||
private final static I2NPMessageHandler acquireHandler(RouterContext ctx) {
|
||||
I2NPMessageHandler rv = null;
|
||||
synchronized (_i2npHandlers) {
|
||||
@ -1125,7 +1126,7 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
}
|
||||
private static void releaseHandler(I2NPMessageHandler handler) {
|
||||
synchronized (_i2npHandlers) {
|
||||
if (_i2npHandlers.size() < 4)
|
||||
if (_i2npHandlers.size() < MAX_HANDLERS)
|
||||
_i2npHandlers.add(handler);
|
||||
}
|
||||
}
|
||||
@ -1137,13 +1138,13 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
byte data[];
|
||||
ByteArrayInputStream bais;
|
||||
public DataBuf() {
|
||||
data = new byte[16*1024];
|
||||
data = new byte[BUFFER_SIZE];
|
||||
bais = new ByteArrayInputStream(data);
|
||||
}
|
||||
}
|
||||
|
||||
private static int MAX_DATA_READ_BUFS = 16;
|
||||
private final static List _dataReadBufs = new ArrayList(16);
|
||||
private static final int MAX_DATA_READ_BUFS = 16;
|
||||
private final static List _dataReadBufs = new ArrayList(MAX_DATA_READ_BUFS);
|
||||
private static DataBuf acquireReadBuf() {
|
||||
synchronized (_dataReadBufs) {
|
||||
if (_dataReadBufs.size() > 0)
|
||||
@ -1178,7 +1179,7 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
_crc = new Adler32();
|
||||
init();
|
||||
}
|
||||
public void init() {
|
||||
private void init() {
|
||||
_size = -1;
|
||||
_nextWrite = 0;
|
||||
_expectedCrc = -1;
|
||||
@ -1268,11 +1269,15 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
I2NPMessage read = h.readMessage(_dataBuf.bais);
|
||||
long timeToRecv = System.currentTimeMillis() - _stateBegin;
|
||||
releaseHandler(h);
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("I2NP message " + _messagesRead + "/" + (read != null ? read.getUniqueId() : 0)
|
||||
+ " received after " + timeToRecv + " with " + _size +"/"+ (_blocks*16) + " bytes on " + toString());
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("I2NP message " + _messagesRead + "/" + (read != null ? read.getUniqueId() : 0)
|
||||
+ " received after " + timeToRecv + " with " + _size +"/"+ (_blocks*16) + " bytes on " + NTCPConnection.this.toString());
|
||||
_context.statManager().addRateData("ntcp.receiveTime", timeToRecv, timeToRecv);
|
||||
_context.statManager().addRateData("ntcp.receiveSize", _size, timeToRecv);
|
||||
|
||||
// FIXME move end of try block here.
|
||||
// On the input side, move releaseHandler() and init() to a finally block.
|
||||
|
||||
if (read != null) {
|
||||
_transport.messageReceived(read, _remotePeer, null, timeToRecv, _size);
|
||||
if (_messagesRead <= 0)
|
||||
@ -1283,23 +1288,27 @@ public class NTCPConnection implements FIFOBandwidthLimiter.CompleteListener {
|
||||
// get it ready for the next I2NP message
|
||||
init();
|
||||
} catch (IOException ioe) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Error parsing I2NP message", ioe);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error parsing I2NP message", ioe);
|
||||
_context.statManager().addRateData("ntcp.corruptI2NPIOE", 1, getUptime());
|
||||
close();
|
||||
// handler and databuf are lost
|
||||
return;
|
||||
} catch (I2NPMessageException ime) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Error parsing I2NP message", ime);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Error parsing I2NP message", ime);
|
||||
_context.statManager().addRateData("ntcp.corruptI2NPIME", 1, getUptime());
|
||||
close();
|
||||
// handler and databuf are lost
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("CRC incorrect for message " + _messagesRead + " (calc=" + val + " expected=" + _expectedCrc + ") size=" + _size + " blocks " + _blocks);
|
||||
_context.statManager().addRateData("ntcp.corruptI2NPCRC", 1, getUptime());
|
||||
// should we try to read in the message and keep going?
|
||||
close();
|
||||
// databuf is lost
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import net.i2p.util.ConcurrentHashSet;
|
||||
|
||||
/**
|
||||
* waste lots of RAM
|
||||
*
|
||||
* @deprecated unused
|
||||
*/
|
||||
class HashSetIVValidator implements IVValidator {
|
||||
private final Set<ByteArray> _received;
|
||||
|
@ -32,9 +32,11 @@ public class HopProcessor {
|
||||
static final int IV_LENGTH = 16;
|
||||
private static final ByteCache _cache = ByteCache.getInstance(128, IV_LENGTH);
|
||||
|
||||
/** @deprecated unused */
|
||||
public HopProcessor(I2PAppContext ctx, HopConfig config) {
|
||||
this(ctx, config, createValidator());
|
||||
}
|
||||
|
||||
public HopProcessor(I2PAppContext ctx, HopConfig config, IVValidator validator) {
|
||||
_context = ctx;
|
||||
_log = ctx.logManager().getLog(HopProcessor.class);
|
||||
@ -42,6 +44,7 @@ public class HopProcessor {
|
||||
_validator = validator;
|
||||
}
|
||||
|
||||
/** @deprecated unused */
|
||||
protected static IVValidator createValidator() {
|
||||
// yeah, we'll use an O(1) validator later (e.g. bloom filter)
|
||||
return new HashSetIVValidator();
|
||||
@ -88,10 +91,10 @@ public class HopProcessor {
|
||||
encrypt(orig, offset, length);
|
||||
updateIV(orig, offset);
|
||||
}
|
||||
if (_log.shouldLog(Log.DEBUG)) {
|
||||
//if (_log.shouldLog(Log.DEBUG)) {
|
||||
//_log.debug("Data after processing: " + Base64.encode(orig, IV_LENGTH, orig.length - IV_LENGTH));
|
||||
//_log.debug("IV sent: " + Base64.encode(orig, 0, IV_LENGTH));
|
||||
}
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,9 @@ public class PumpedTunnelGateway extends TunnelGateway {
|
||||
* scheduling a later delayed flush as necessary. this allows the gw.add call to
|
||||
* go quickly, rather than blocking its callers on potentially substantial
|
||||
* processing.
|
||||
*
|
||||
* @param queueBuf Empty list for convenience, to use as a temporary buffer.
|
||||
* Must be empty when called; will always be emptied before return.
|
||||
*/
|
||||
void pump(List<Pending> queueBuf) {
|
||||
synchronized (_prequeue) {
|
||||
|
Reference in New Issue
Block a user