2006-02-20 jrandom
* Major SSU and router tuning to reduce contention, memory usage, and GC churn. There are still issues to be worked out, but this should be a substantial improvement. * Modified the optional netDb harvester task to support choosing whether to use (non-anonymous) direct connections or (anonymous) exploratory tunnels to do the harvesting. Harvesting itself is enabled via the advanced config "netDb.shouldHarvest=true" (default is false) and the connection type can be chosen via "netDb.harvestDirectly=false" (default is false).
This commit is contained in:
@ -140,6 +140,7 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
loadConfig(options);
|
||||
_sessionId = null;
|
||||
_leaseSet = null;
|
||||
_context.statManager().createRateStat("client.availableMessages", "How many messages are available for the current client", "ClientMessages", new long[] { 60*1000, 10*60*1000 });
|
||||
}
|
||||
|
||||
/**
|
||||
@ -299,11 +300,17 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
*
|
||||
*/
|
||||
public byte[] receiveMessage(int msgId) throws I2PSessionException {
|
||||
int remaining = 0;
|
||||
MessagePayloadMessage msg = null;
|
||||
synchronized (_availableMessages) {
|
||||
msg = (MessagePayloadMessage) _availableMessages.remove(new Long(msgId));
|
||||
remaining = _availableMessages.size();
|
||||
}
|
||||
_context.statManager().addRateData("client.availableMessages", remaining, 0);
|
||||
if (msg == null) {
|
||||
_log.error("Receive message " + msgId + " had no matches, remaining=" + remaining);
|
||||
return null;
|
||||
}
|
||||
if (msg == null) return null;
|
||||
return msg.getPayload().getUnencryptedData();
|
||||
}
|
||||
|
||||
@ -339,9 +346,13 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
* Recieve a payload message and let the app know its available
|
||||
*/
|
||||
public void addNewMessage(MessagePayloadMessage msg) {
|
||||
Long mid = new Long(msg.getMessageId());
|
||||
int avail = 0;
|
||||
synchronized (_availableMessages) {
|
||||
_availableMessages.put(new Long(msg.getMessageId()), msg);
|
||||
_availableMessages.put(mid, msg);
|
||||
avail = _availableMessages.size();
|
||||
}
|
||||
_context.statManager().addRateData("client.availableMessages", avail, 0);
|
||||
long id = msg.getMessageId();
|
||||
byte data[] = msg.getPayload().getUnencryptedData();
|
||||
if ((data == null) || (data.length <= 0)) {
|
||||
@ -354,20 +365,23 @@ abstract class I2PSessionImpl implements I2PSession, I2CPMessageReader.I2CPMessa
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info(getPrefix() + "Notified availability for session " + _sessionId + ", message " + id);
|
||||
}
|
||||
SimpleTimer.getInstance().addEvent(new VerifyUsage(id), 30*1000);
|
||||
SimpleTimer.getInstance().addEvent(new VerifyUsage(mid), 30*1000);
|
||||
}
|
||||
private class VerifyUsage implements SimpleTimer.TimedEvent {
|
||||
private long _msgId;
|
||||
public VerifyUsage(long id) { _msgId = id; }
|
||||
private Long _msgId;
|
||||
public VerifyUsage(Long id) { _msgId = id; }
|
||||
public void timeReached() {
|
||||
MessagePayloadMessage removed = null;
|
||||
int remaining = 0;
|
||||
synchronized (_availableMessages) {
|
||||
removed = (MessagePayloadMessage)_availableMessages.remove(new Long(_msgId));
|
||||
removed = (MessagePayloadMessage)_availableMessages.remove(_msgId);
|
||||
remaining = _availableMessages.size();
|
||||
}
|
||||
if (removed != null) {
|
||||
_log.log(Log.CRIT, "Message NOT removed! id=" + _msgId + ": " + removed + ": remaining: " + remaining);
|
||||
_context.statManager().addRateData("client.availableMessages", remaining, 0);
|
||||
}
|
||||
if (removed != null)
|
||||
_log.log(Log.CRIT, "Message NOT removed! id=" + _msgId + ": " + removed);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class AvailabilityNotifier implements Runnable {
|
||||
|
@ -283,11 +283,12 @@ public class ElGamalAESEngine {
|
||||
try {
|
||||
SessionKey newKey = null;
|
||||
Hash readHash = null;
|
||||
List tags = new ArrayList();
|
||||
List tags = null;
|
||||
|
||||
//ByteArrayInputStream bais = new ByteArrayInputStream(decrypted);
|
||||
int cur = 0;
|
||||
long numTags = DataHelper.fromLong(decrypted, cur, 2);
|
||||
if (numTags > 0) tags = new ArrayList((int)numTags);
|
||||
cur += 2;
|
||||
//_log.debug("# tags: " + numTags);
|
||||
if ((numTags < 0) || (numTags > 200)) throw new Exception("Invalid number of session tags");
|
||||
@ -326,7 +327,8 @@ public class ElGamalAESEngine {
|
||||
|
||||
if (eq) {
|
||||
// everything matches. w00t.
|
||||
foundTags.addAll(tags);
|
||||
if (tags != null)
|
||||
foundTags.addAll(tags);
|
||||
if (newKey != null) foundKey.setData(newKey.getData());
|
||||
return unencrData;
|
||||
}
|
||||
@ -610,4 +612,4 @@ public class ElGamalAESEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ public class ElGamalEngine {
|
||||
(ybytes.length > 257 ? 257 : ybytes.length));
|
||||
System.arraycopy(dbytes, 0, out, (dbytes.length < 257 ? 514 - dbytes.length : 257),
|
||||
(dbytes.length > 257 ? 257 : dbytes.length));
|
||||
/*
|
||||
StringBuffer buf = new StringBuffer(1024);
|
||||
buf.append("Timing\n");
|
||||
buf.append("0-1: ").append(t1 - t0).append('\n');
|
||||
@ -142,6 +143,7 @@ public class ElGamalEngine {
|
||||
buf.append("8-9: ").append(t9 - t8).append('\n');
|
||||
buf.append("9-10: ").append(t10 - t9).append('\n');
|
||||
//_log.debug(buf.toString());
|
||||
*/
|
||||
long end = _context.clock().now();
|
||||
|
||||
long diff = end - start;
|
||||
|
@ -151,15 +151,17 @@ public class I2CPMessageReader {
|
||||
_log.debug("After handling the newly received message");
|
||||
}
|
||||
} catch (I2CPMessageException ime) {
|
||||
_log.error("Error handling message", ime);
|
||||
_log.warn("Error handling message", ime);
|
||||
_listener.readError(I2CPMessageReader.this, ime);
|
||||
cancelRunner();
|
||||
} catch (IOException ioe) {
|
||||
_log.error("IO Error handling message", ioe);
|
||||
_log.warn("IO Error handling message", ioe);
|
||||
_listener.disconnected(I2CPMessageReader.this);
|
||||
cancelRunner();
|
||||
} catch (Throwable t) {
|
||||
_log.log(Log.CRIT, "Unhandled error reading I2CP stream", t);
|
||||
} catch (OutOfMemoryError oom) {
|
||||
throw oom;
|
||||
} catch (Exception e) {
|
||||
_log.log(Log.CRIT, "Unhandled error reading I2CP stream", e);
|
||||
_listener.disconnected(I2CPMessageReader.this);
|
||||
cancelRunner();
|
||||
}
|
||||
|
@ -45,6 +45,10 @@ public class SimpleTimer {
|
||||
}
|
||||
}
|
||||
|
||||
public void reschedule(TimedEvent event, long timeoutMs) {
|
||||
addEvent(event, timeoutMs, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue up the given event to be fired no sooner than timeoutMs from now.
|
||||
* However, if this event is already scheduled, the event will be scheduled
|
||||
@ -52,7 +56,12 @@ public class SimpleTimer {
|
||||
* timeout. If this is not the desired behavior, call removeEvent first.
|
||||
*
|
||||
*/
|
||||
public void addEvent(TimedEvent event, long timeoutMs) {
|
||||
public void addEvent(TimedEvent event, long timeoutMs) { addEvent(event, timeoutMs, true); }
|
||||
/**
|
||||
* @param useEarliestEventTime if its already scheduled, use the earlier of the
|
||||
* two timeouts, else use the later
|
||||
*/
|
||||
public void addEvent(TimedEvent event, long timeoutMs, boolean useEarliestTime) {
|
||||
int totalEvents = 0;
|
||||
long now = System.currentTimeMillis();
|
||||
long eventTime = now + timeoutMs;
|
||||
@ -61,11 +70,20 @@ public class SimpleTimer {
|
||||
// remove the old scheduled position, then reinsert it
|
||||
Long oldTime = (Long)_eventTimes.get(event);
|
||||
if (oldTime != null) {
|
||||
if (oldTime.longValue() < eventTime) {
|
||||
_events.notifyAll();
|
||||
return; // already scheduled for sooner than requested
|
||||
if (useEarliestTime) {
|
||||
if (oldTime.longValue() < eventTime) {
|
||||
_events.notifyAll();
|
||||
return; // already scheduled for sooner than requested
|
||||
} else {
|
||||
_events.remove(oldTime);
|
||||
}
|
||||
} else {
|
||||
_events.remove(oldTime);
|
||||
if (oldTime.longValue() > eventTime) {
|
||||
_events.notifyAll();
|
||||
return; // already scheduled for later than the given period
|
||||
} else {
|
||||
_events.remove(oldTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
while (_events.containsKey(time))
|
||||
|
Reference in New Issue
Block a user