2004-11-01 jrandom

* Increase the tunnel test timeout rapidly if our tunnels are failing.
    * Honor message expirations for some tunnel jobs that were prematurely
      expired.
    * Streamline memory usage with temporary object caches and more efficient
      serialization for SHA256 calculation, logging, and both I2CP and I2NP
      message handling.
    * Fix some situations where we forward messages too eagerly.  For a
      request at the tunnel endpoint, if the tunnel is inbound and the target
      is remote, honor the message by tunnel routing the data rather than
      sending it directly to the requested location.
This commit is contained in:
jrandom
2004-11-01 13:31:29 +00:00
committed by zzz
parent 65d415fade
commit c19355a7b2
26 changed files with 917 additions and 167 deletions
+5
View File
@@ -71,6 +71,11 @@ public class TunnelId extends DataStructureImpl {
if (_tunnelId < 0) throw new DataFormatException("Invalid tunnel ID: " + _tunnelId);
DataHelper.writeLong(out, 4, _tunnelId);
}
public int writeBytes(byte target[], int offset) throws DataFormatException {
if (_tunnelId < 0) throw new DataFormatException("Invalid tunnel ID: " + _tunnelId);
DataHelper.toLong(target, offset, 4, _tunnelId);
return 4;
}
public boolean equals(Object obj) {
if ( (obj == null) || !(obj instanceof TunnelId))
@@ -12,6 +12,7 @@ package net.i2p.data.i2cp;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.i2p.data.DataFormatException;
import net.i2p.data.DataHelper;
@@ -75,6 +76,15 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
}
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
throw new RuntimeException("go away, we dont want any");
}
/**
* Write out the full message to the stream, including the 4 byte size and 1
* byte type header.
*
*/
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
if (_sessionId == null)
throw new I2CPMessageException("Unable to write out the message, as the session ID has not been defined");
if (_messageId == null)
@@ -82,15 +92,17 @@ public class MessagePayloadMessage extends I2CPMessageImpl {
if (_payload == null)
throw new I2CPMessageException("Unable to write out the message, as the payload has not been defined");
ByteArrayOutputStream os = new ByteArrayOutputStream(512);
int size = 2 + 4 + 4 + _payload.getSize();
try {
_sessionId.writeBytes(os);
_messageId.writeBytes(os);
_payload.writeBytes(os);
DataHelper.writeLong(out, 4, size);
DataHelper.writeLong(out, 1, getType());
DataHelper.writeLong(out, 2, _sessionId.getSessionId());
DataHelper.writeLong(out, 4, _messageId.getMessageId());
DataHelper.writeLong(out, 4, _payload.getSize());
out.write(_payload.getEncryptedData());
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Error writing out the message data", dfe);
throw new I2CPMessageException("Unable to write the message length or type", dfe);
}
return os.toByteArray();
}
public int getType() {
@@ -75,6 +75,19 @@ public class SendMessageMessage extends I2CPMessageImpl {
}
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
if (true) throw new IllegalStateException("wtf, do not run me");
}
/**
* Read the body into the data structures
*
*/
public void readMessage(InputStream in, int length, int type) throws I2CPMessageException, IOException {
if (type != getType())
throw new I2CPMessageException("Invalid message type (found: " + type + " supported: " + getType()
+ " class: " + getClass().getName() + ")");
if (length < 0) throw new IOException("Negative payload size");
try {
_sessionId = new SessionId();
_sessionId.readBytes(in);