2005-07-22 jrandom

* Use the small thread pool for I2PTunnelHTTPServer (already used for
      I2PTunnelServer)
    * Minor memory churn reduction in I2CP
    * Small stats update
This commit is contained in:
jrandom
2005-07-23 00:15:56 +00:00
committed by zzz
parent 45767360ab
commit aeb8f02269
27 changed files with 367 additions and 278 deletions

View File

@@ -216,60 +216,94 @@ public class DeliveryInstructions extends DataStructureImpl {
val = val | fmode;
if (getDelayRequested())
val = val | FLAG_DELAY;
_log.debug("getFlags() = " + val);
if (_log.shouldLog(Log.DEBUG))
_log.debug("getFlags() = " + val);
return val;
}
private byte[] getAdditionalInfo() throws DataFormatException {
ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
try {
if (getEncrypted()) {
if (_encryptionKey == null) throw new DataFormatException("Encryption key is not set");
_encryptionKey.writeBytes(baos);
if (_log.shouldLog(Log.DEBUG))
_log.debug("IsEncrypted");
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Is NOT Encrypted");
}
switch (getDeliveryMode()) {
case FLAG_MODE_LOCAL:
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = local");
break;
case FLAG_MODE_DESTINATION:
if (_destinationHash == null) throw new DataFormatException("Destination hash is not set");
_destinationHash.writeBytes(baos);
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = destination, hash = " + _destinationHash);
break;
case FLAG_MODE_ROUTER:
if (_routerHash == null) throw new DataFormatException("Router hash is not set");
_routerHash.writeBytes(baos);
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = router, routerHash = " + _routerHash);
break;
case FLAG_MODE_TUNNEL:
if ( (_routerHash == null) || (_tunnelId == null) ) throw new DataFormatException("Router hash or tunnel ID is not set");
_routerHash.writeBytes(baos);
_tunnelId.writeBytes(baos);
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = tunnel, tunnelId = " + _tunnelId.getTunnelId()
+ ", routerHash = " + _routerHash);
break;
}
if (getDelayRequested()) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("delay requested: " + getDelaySeconds());
DataHelper.writeLong(baos, 4, getDelaySeconds());
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("delay NOT requested");
}
} catch (IOException ioe) {
throw new DataFormatException("Unable to write out additional info", ioe);
int additionalSize = 0;
if (getEncrypted()) {
if (_encryptionKey == null) throw new DataFormatException("Encryption key is not set");
additionalSize += SessionKey.KEYSIZE_BYTES;
}
return baos.toByteArray();
switch (getDeliveryMode()) {
case FLAG_MODE_LOCAL:
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = local");
break;
case FLAG_MODE_DESTINATION:
if (_destinationHash == null) throw new DataFormatException("Destination hash is not set");
additionalSize += Hash.HASH_LENGTH;
break;
case FLAG_MODE_ROUTER:
if (_routerHash == null) throw new DataFormatException("Router hash is not set");
additionalSize += Hash.HASH_LENGTH;
break;
case FLAG_MODE_TUNNEL:
if ( (_routerHash == null) || (_tunnelId == null) ) throw new DataFormatException("Router hash or tunnel ID is not set");
additionalSize += Hash.HASH_LENGTH;
additionalSize += 4; // tunnelId
break;
}
if (getDelayRequested()) {
additionalSize += 4;
}
byte rv[] = new byte[additionalSize];
int offset = 0;
if (getEncrypted()) {
if (_encryptionKey == null) throw new DataFormatException("Encryption key is not set");
System.arraycopy(_encryptionKey.getData(), 0, rv, offset, SessionKey.KEYSIZE_BYTES);
offset += SessionKey.KEYSIZE_BYTES;
if (_log.shouldLog(Log.DEBUG))
_log.debug("IsEncrypted");
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("Is NOT Encrypted");
}
switch (getDeliveryMode()) {
case FLAG_MODE_LOCAL:
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = local");
break;
case FLAG_MODE_DESTINATION:
if (_destinationHash == null) throw new DataFormatException("Destination hash is not set");
System.arraycopy(_destinationHash.getData(), 0, rv, offset, Hash.HASH_LENGTH);
offset += Hash.HASH_LENGTH;
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = destination, hash = " + _destinationHash);
break;
case FLAG_MODE_ROUTER:
if (_routerHash == null) throw new DataFormatException("Router hash is not set");
System.arraycopy(_routerHash.getData(), 0, rv, offset, Hash.HASH_LENGTH);
offset += Hash.HASH_LENGTH;
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = router, routerHash = " + _routerHash);
break;
case FLAG_MODE_TUNNEL:
if ( (_routerHash == null) || (_tunnelId == null) ) throw new DataFormatException("Router hash or tunnel ID is not set");
System.arraycopy(_routerHash.getData(), 0, rv, offset, Hash.HASH_LENGTH);
offset += Hash.HASH_LENGTH;
DataHelper.toLong(rv, offset, 4, _tunnelId.getTunnelId());
offset += 4;
if (_log.shouldLog(Log.DEBUG))
_log.debug("mode = tunnel, tunnelId = " + _tunnelId.getTunnelId()
+ ", routerHash = " + _routerHash);
break;
}
if (getDelayRequested()) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("delay requested: " + getDelaySeconds());
DataHelper.toLong(rv, offset, 4, getDelaySeconds());
offset += 4;
} else {
if (_log.shouldLog(Log.DEBUG))
_log.debug("delay NOT requested");
}
return rv;
}
public void writeBytes(OutputStream out) throws DataFormatException, IOException {

View File

@@ -107,19 +107,29 @@ public class GarlicClove extends DataStructureImpl {
public void writeBytes(OutputStream out) throws DataFormatException, IOException {
StringBuffer error = new StringBuffer();
if (_instructions == null)
StringBuffer error = null;
if (_instructions == null) {
if (error == null) error = new StringBuffer();
error.append("No instructions ");
if (_msg == null)
}
if (_msg == null) {
if (error == null) error = new StringBuffer();
error.append("No message ");
if (_cloveId < 0)
}
if (_cloveId < 0) {
if (error == null) error = new StringBuffer();
error.append("CloveID < 0 [").append(_cloveId).append("] ");
if (_expiration == null)
}
if (_expiration == null) {
if (error == null) error = new StringBuffer();
error.append("Expiration is null ");
if (_certificate == null)
}
if (_certificate == null) {
if (error == null) error = new StringBuffer();
error.append("Certificate is null ");
}
if (error.length() > 0)
if ( (error != null) && (error.length() > 0) )
throw new DataFormatException(error.toString());
_instructions.writeBytes(out);

View File

@@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
*
*/
public class RouterVersion {
public final static String ID = "$Revision: 1.206 $ $Date: 2005/07/20 14:24:47 $";
public final static String ID = "$Revision: 1.207 $ $Date: 2005/07/21 17:37:15 $";
public final static String VERSION = "0.5.0.7";
public final static long BUILD = 18;
public final static long BUILD = 19;
public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION);
System.out.println("Router ID: " + RouterVersion.ID);

View File

@@ -292,8 +292,8 @@ public class ClientConnectionRunner {
_log.debug("Acking message send [accepted]" + id + " / " + nonce + " for sessionId "
+ _sessionId, new Exception("sendAccepted"));
MessageStatusMessage status = new MessageStatusMessage();
status.setMessageId(id);
status.setSessionId(_sessionId);
status.setMessageId(id.getMessageId());
status.setSessionId(_sessionId.getSessionId());
status.setSize(0L);
status.setNonce(nonce);
status.setStatus(MessageStatusMessage.STATUS_SEND_ACCEPTED);
@@ -491,8 +491,8 @@ public class ClientConnectionRunner {
if (_dead) return;
MessageStatusMessage msg = new MessageStatusMessage();
msg.setMessageId(_messageId);
msg.setSessionId(_sessionId);
msg.setMessageId(_messageId.getMessageId());
msg.setSessionId(_sessionId.getSessionId());
msg.setNonce(2);
msg.setSize(0);
if (_success)

View File

@@ -179,8 +179,8 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
_log.debug("Handling recieve begin: id = " + message.getMessageId());
MessagePayloadMessage msg = new MessagePayloadMessage();
msg.setMessageId(message.getMessageId());
msg.setSessionId(_runner.getSessionId());
Payload payload = _runner.getPayload(message.getMessageId());
msg.setSessionId(_runner.getSessionId().getSessionId());
Payload payload = _runner.getPayload(new MessageId(message.getMessageId()));
if (payload == null) {
if (_log.shouldLog(Log.ERROR))
_log.error("Payload for message id [" + message.getMessageId()
@@ -202,7 +202,7 @@ class ClientMessageEventListener implements I2CPMessageReader.I2CPMessageEventLi
*
*/
private void handleReceiveEnd(I2CPMessageReader reader, ReceiveMessageEndMessage message) {
_runner.removePayload(message.getMessageId());
_runner.removePayload(new MessageId(message.getMessageId()));
}
private void handleDestroySession(I2CPMessageReader reader, DestroySessionMessage message) {

View File

@@ -61,25 +61,27 @@ class ClientWriterRunner implements Runnable {
}
}
public void run() {
List messages = new ArrayList(64);
List messageTimes = new ArrayList(64);
List switchList = null;
while (!_runner.getIsDead()) {
List messages = null;
List messageTimes = null;
synchronized (_dataLock) {
if (_messagesToWrite.size() <= 0)
try { _dataLock.wait(); } catch (InterruptedException ie) {}
if (_messagesToWrite.size() > 0) {
messages = new ArrayList(_messagesToWrite.size());
messageTimes = new ArrayList(_messagesToWriteTimes.size());
messages.addAll(_messagesToWrite);
messageTimes.addAll(_messagesToWriteTimes);
_messagesToWrite.clear();
_messagesToWriteTimes.clear();
switchList = _messagesToWrite;
_messagesToWrite = messages;
messages = switchList;
switchList = _messagesToWriteTimes;
_messagesToWriteTimes = messageTimes;
messageTimes = switchList;
}
}
if (messages != null) {
if (messages.size() > 0) {
for (int i = 0; i < messages.size(); i++) {
I2CPMessage msg = (I2CPMessage)messages.get(i);
Long when = (Long)messageTimes.get(i);
@@ -92,7 +94,9 @@ class ClientWriterRunner implements Runnable {
+ (_context.clock().now()-when.longValue()) + " for "
+ msg.getClass().getName());
}
}
}
messages.clear();
messageTimes.clear();
}
}
}

View File

@@ -56,8 +56,8 @@ class MessageReceivedJob extends JobImpl {
_log.debug("Sending message available: " + id + " to sessionId " + _runner.getSessionId()
+ " (with nonce=1)", new Exception("available"));
MessageStatusMessage msg = new MessageStatusMessage();
msg.setMessageId(id);
msg.setSessionId(_runner.getSessionId());
msg.setMessageId(id.getMessageId());
msg.setSessionId(_runner.getSessionId().getSessionId());
msg.setSize(size);
msg.setNonce(1);
msg.setStatus(MessageStatusMessage.STATUS_AVAILABLE);

View File

@@ -49,6 +49,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
_log = getContext().logManager().getLog(HandleDatabaseLookupMessageJob.class);
getContext().statManager().createRateStat("netDb.lookupsHandled", "How many netDb lookups have we handled?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
getContext().statManager().createRateStat("netDb.lookupsMatched", "How many netDb lookups did we have the data for?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
getContext().statManager().createRateStat("netDb.lookupsMatchedLeaseSet", "How many netDb leaseSet lookups did we have the data for?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
getContext().statManager().createRateStat("netDb.lookupsMatchedReceivedPublished", "How many netDb lookups did we have the data for that were published to us?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
getContext().statManager().createRateStat("netDb.lookupsMatchedLocalClosest", "How many netDb lookups for local data were received where we are the closest peers?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
getContext().statManager().createRateStat("netDb.lookupsMatchedLocalNotClosest", "How many netDb lookups for local data were received where we are NOT the closest peers?", "NetworkDatabase", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
@@ -130,6 +131,7 @@ public class HandleDatabaseLookupMessageJob extends JobImpl {
if (data instanceof LeaseSet) {
msg.setLeaseSet((LeaseSet)data);
msg.setValueType(DatabaseStoreMessage.KEY_TYPE_LEASESET);
getContext().statManager().addRateData("netDb.lookupsMatchedLeaseSet", 1, 0);
} else if (data instanceof RouterInfo) {
msg.setRouterInfo((RouterInfo)data);
msg.setValueType(DatabaseStoreMessage.KEY_TYPE_ROUTERINFO);

View File

@@ -100,6 +100,8 @@ public class ACKSender implements Runnable {
_context.statManager().addRateData("udp.sendACKCount", ackBitfields.size(), 0);
_context.statManager().addRateData("udp.sendACKRemaining", remaining, 0);
now = _context.clock().now();
if (lastSend < 0)
lastSend = now - 1;
_context.statManager().addRateData("udp.ackFrequency", now-lastSend, now-wanted);
//_context.statManager().getStatLog().addData(peer.getRemoteHostId().toString(), "udp.peer.sendACKCount", ackBitfields.size(), 0);
UDPPacket ack = _builder.buildACK(peer, ackBitfields);

View File

@@ -41,7 +41,11 @@ public class PacketHandler {
_context.statManager().createRateStat("udp.handleTime", "How long it takes to handle a received packet after its been pulled off the queue", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.queueTime", "How long after a packet is received can we begin handling it", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.receivePacketSkew", "How long ago after the packet was sent did we receive it", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalid", "How old the packet we dropped due to invalidity was", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalidUnkown", "How old the packet we dropped due to invalidity (unkown type) was", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalidReestablish", "How old the packet we dropped due to invalidity (doesn't use existing key, not an establishment) was", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalidEstablish", "How old the packet we dropped due to invalidity (establishment, bad key) was", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalidInboundEstablish", "How old the packet we dropped due to invalidity (inbound establishment, bad key) was", "udp", new long[] { 10*60*1000, 60*60*1000 });
_context.statManager().createRateStat("udp.droppedInvalidSkew", "How skewed the packet we dropped due to invalidity (valid except bad skew) was", "udp", new long[] { 10*60*1000, 60*60*1000 });
}
public void startup() {
@@ -158,7 +162,7 @@ public class PacketHandler {
} else {
if (_log.shouldLog(Log.WARN))
_log.warn("Validation with existing con failed, and validation as reestablish failed too. DROP");
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidReestablish", packet.getLifetime(), packet.getExpiration());
}
return;
}
@@ -177,7 +181,7 @@ public class PacketHandler {
if (!isValid) {
if (_log.shouldLog(Log.WARN))
_log.warn("Invalid introduction packet received: " + packet, new Exception("path"));
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidEstablish", packet.getLifetime(), packet.getExpiration());
return;
} else {
if (_log.shouldLog(Log.INFO))
@@ -224,7 +228,7 @@ public class PacketHandler {
// on earlier state packets
receivePacket(reader, packet);
} else {
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidInboundEstablish", packet.getLifetime(), packet.getExpiration());
}
}
@@ -283,12 +287,12 @@ public class PacketHandler {
if (skew > GRACE_PERIOD) {
if (_log.shouldLog(Log.WARN))
_log.warn("Packet too far in the future: " + new Date(sendOn/1000) + ": " + packet);
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidSkew", skew, packet.getExpiration());
return;
} else if (skew < 0 - GRACE_PERIOD) {
if (_log.shouldLog(Log.WARN))
_log.warn("Packet too far in the past: " + new Date(sendOn/1000) + ": " + packet);
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidSkew", 0-skew, packet.getExpiration());
return;
}
@@ -324,7 +328,7 @@ public class PacketHandler {
default:
if (_log.shouldLog(Log.WARN))
_log.warn("Unknown payload type: " + reader.readPayloadType());
_context.statManager().addRateData("udp.droppedInvalid", packet.getLifetime(), packet.getExpiration());
_context.statManager().addRateData("udp.droppedInvalidUnknown", packet.getLifetime(), packet.getExpiration());
return;
}
}

View File

@@ -168,9 +168,11 @@ public class UDPSender {
}
long sendTime = _context.clock().now() - before;
_context.statManager().addRateData("udp.socketSendTime", sendTime, packet.getLifetime());
_context.statManager().addRateData("udp.sendBWThrottleTime", afterBW - acquireTime, acquireTime - packet.getBegin());
long throttleTime = afterBW - acquireTime;
if (throttleTime > 10)
_context.statManager().addRateData("udp.sendBWThrottleTime", throttleTime, acquireTime - packet.getBegin());
if (packet.getMarkedType() == 1)
_context.statManager().addRateData("udp.sendACKTime", afterBW - acquireTime, packet.getLifetime());
_context.statManager().addRateData("udp.sendACKTime", throttleTime, packet.getLifetime());
_context.statManager().addRateData("udp.pushTime", packet.getLifetime(), packet.getLifetime());
_context.statManager().addRateData("udp.sendPacketSize", size, packet.getLifetime());
} catch (IOException ioe) {

View File

@@ -128,6 +128,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_expireEvent = new ExpirePeerEvent();
_context.statManager().createRateStat("udp.droppedPeer", "How long ago did we receive from a dropped peer (duration == session lifetime", "udp", new long[] { 60*60*1000, 24*60*60*1000 });
_context.statManager().createRateStat("udp.droppedPeerInactive", "How long ago did we receive from a dropped peer (duration == session lifetime)", "udp", new long[] { 60*60*1000, 24*60*60*1000 });
}
public void startup() {
@@ -315,6 +316,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
boolean addRemotePeerState(PeerState peer) {
if (_log.shouldLog(Log.INFO))
_log.info("Add remote peer state: " + peer);
long oldEstablishedOn = -1;
PeerState oldPeer = null;
if (peer.getRemotePeer() != null) {
synchronized (_peersByIdent) {
@@ -323,6 +325,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
// should we transfer the oldPeer's RTT/RTO/etc? nah
// or perhaps reject the new session? nah,
// using the new one allow easier reconnect
oldEstablishedOn = oldPeer.getKeyEstablishedTime();
}
}
}
@@ -339,6 +342,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if ( (oldPeer != null) && (oldPeer != peer) ) {
//_peersByRemoteHost.put(remoteString, oldPeer);
//return false;
oldEstablishedOn = oldPeer.getKeyEstablishedTime();
}
}
@@ -353,6 +357,8 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
_expireEvent.add(peer);
if (oldEstablishedOn > 0)
_context.statManager().addRateData("udp.alreadyConnected", oldEstablishedOn, 0);
return true;
}
@@ -367,6 +373,9 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
long now = _context.clock().now();
_context.statManager().addRateData("udp.droppedPeer", now - peer.getLastReceiveTime(), now - peer.getKeyEstablishedTime());
_context.shitlist().shitlistRouter(peer.getRemotePeer(), "dropped after too many retries");
} else {
long now = _context.clock().now();
_context.statManager().addRateData("udp.droppedPeerInactive", now - peer.getLastReceiveTime(), now - peer.getKeyEstablishedTime());
}
synchronized (_peersByIdent) {
_peersByIdent.remove(peer.getRemotePeer());