Assorted fixes to router Junit tests for changes in the source

This commit is contained in:
str4d
2012-11-05 21:31:40 +00:00
parent f57d91ac16
commit 4d8973b0a5
6 changed files with 29 additions and 23 deletions

View File

@ -29,7 +29,7 @@ public class DateMessage extends I2NPMessageImpl {
public long getNow() { return _now; } public long getNow() { return _now; }
public void setNow(long now) { _now = now; } public void setNow(long now) { _now = now; }
public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException { public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException {
if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message"); if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message");
int curIndex = offset; int curIndex = offset;

View File

@ -49,7 +49,6 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
public static final long MAX_NONCE_VALUE = ((1l << 32l) - 1l); public static final long MAX_NONCE_VALUE = ((1l << 32l) - 1l);
private static final Hash INVALID_HASH = new Hash(new byte[Hash.HASH_LENGTH]); // all 0s private static final Hash INVALID_HASH = new Hash(new byte[Hash.HASH_LENGTH]); // all 0s
private static final TunnelId INVALID_TUNNEL = TunnelId.INVALID;
public TunnelCreateMessage(I2PAppContext context) { public TunnelCreateMessage(I2PAppContext context) {
super(context); super(context);
@ -83,7 +82,7 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
public Properties getOptions() { return _options; } public Properties getOptions() { return _options; }
public void setOptions(Properties opts) { _options = opts; } public void setOptions(Properties opts) { _options = opts; }
public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException { public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException {
if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message"); if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message");
if (DataHelper.eq(INVALID_HASH.getData(), 0, data, offset, Hash.HASH_LENGTH)) { if (DataHelper.eq(INVALID_HASH.getData(), 0, data, offset, Hash.HASH_LENGTH)) {
@ -161,9 +160,13 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
length += SessionKey.KEYSIZE_BYTES; // layerKey length += SessionKey.KEYSIZE_BYTES; // layerKey
length += SessionKey.KEYSIZE_BYTES; // ivKey length += SessionKey.KEYSIZE_BYTES; // ivKey
if (_optionsCache == null) if (_optionsCache == null) {
try {
_optionsCache = DataHelper.toProperties(_options); _optionsCache = DataHelper.toProperties(_options);
length += _optionsCache.length; length += _optionsCache.length;
} catch (DataFormatException dfe) {
}
}
length += Hash.HASH_LENGTH; // replyGateway length += Hash.HASH_LENGTH; // replyGateway
length += 4; // replyTunnel length += 4; // replyTunnel
@ -200,8 +203,13 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
System.arraycopy(_ivKey.getData(), 0, data, offset, SessionKey.KEYSIZE_BYTES); System.arraycopy(_ivKey.getData(), 0, data, offset, SessionKey.KEYSIZE_BYTES);
offset += SessionKey.KEYSIZE_BYTES; offset += SessionKey.KEYSIZE_BYTES;
if (_optionsCache == null) if (_optionsCache == null) {
try {
_optionsCache = DataHelper.toProperties(_options); _optionsCache = DataHelper.toProperties(_options);
} catch (DataFormatException dfe) {
throw new I2NPMessageException("Error reading the options", dfe);
}
}
System.arraycopy(_optionsCache, 0, data, offset, _optionsCache.length); System.arraycopy(_optionsCache, 0, data, offset, _optionsCache.length);
offset += _optionsCache.length; offset += _optionsCache.length;

View File

@ -50,7 +50,7 @@ public class TunnelCreateStatusMessage extends I2NPMessageImpl {
public long getNonce() { return _nonce; } public long getNonce() { return _nonce; }
public void setNonce(long nonce) { _nonce = nonce; } public void setNonce(long nonce) { _nonce = nonce; }
public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException, IOException { public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException {
if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message"); if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message");
int curIndex = offset; int curIndex = offset;

View File

@ -237,7 +237,7 @@ public class SSUDemo {
public int getType() { return MESSAGE_TYPE; } public int getType() { return MESSAGE_TYPE; }
protected int calculateWrittenLength() { return _data.length; } protected int calculateWrittenLength() { return _data.length; }
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException, IOException { public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException {
_data = new byte[dataSize]; _data = new byte[dataSize];
System.arraycopy(data, offset, _data, 0, dataSize); System.arraycopy(data, offset, _data, 0, dataSize);
} }

View File

@ -12,6 +12,7 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import net.i2p.data.SessionKey; import net.i2p.data.SessionKey;
import net.i2p.data.SessionTag;
import net.i2p.data.i2np.GarlicMessage; import net.i2p.data.i2np.GarlicMessage;
import net.i2p.router.Job; import net.i2p.router.Job;
import net.i2p.router.JobImpl; import net.i2p.router.JobImpl;
@ -38,7 +39,7 @@ public class SendGarlicJob extends JobImpl {
private MessageSelector _replySelector; private MessageSelector _replySelector;
private GarlicMessage _message; private GarlicMessage _message;
private SessionKey _wrappedKey; private SessionKey _wrappedKey;
private Set _wrappedTags; private Set<SessionTag> _wrappedTags;
/** /**
* *

View File

@ -50,16 +50,15 @@ public class BuildMessageTest {
_replyTunnel = 42; _replyTunnel = 42;
// populate and encrypt the message // populate and encrypt the message
BuildMessageGenerator gen = new BuildMessageGenerator();
TunnelBuildMessage msg = new TunnelBuildMessage(ctx); TunnelBuildMessage msg = new TunnelBuildMessage(ctx);
for (int i = 0; i < BuildMessageGenerator.ORDER.length; i++) { for (int i = 0; i < order.size(); i++) {
int hop = ((Integer)order.get(i)).intValue(); int hop = ((Integer)order.get(i)).intValue();
PublicKey key = null; PublicKey key = null;
if (hop < _pubKeys.length) if (hop < _pubKeys.length)
key = _pubKeys[hop]; key = _pubKeys[hop];
gen.createRecord(i, hop, msg, cfg, _replyRouter, _replyTunnel, ctx, key); BuildMessageGenerator.createRecord(i, hop, msg, cfg, _replyRouter, _replyTunnel, ctx, key);
} }
gen.layeredEncrypt(ctx, msg, cfg, order); BuildMessageGenerator.layeredEncrypt(ctx, msg, cfg, order);
log.debug("\n================================================================" + log.debug("\n================================================================" +
"\nMessage fully encrypted" + "\nMessage fully encrypted" +
@ -87,9 +86,8 @@ public class BuildMessageTest {
long now = (ctx.clock().now() / (60l*60l*1000l)) * (60*60*1000); long now = (ctx.clock().now() / (60l*60l*1000l)) * (60*60*1000);
int ourSlot = -1; int ourSlot = -1;
BuildResponseRecord resp = new BuildResponseRecord(); byte reply[] = BuildResponseRecord.create(ctx, 0, req.readReplyKey(), req.readReplyIV(), -1);
byte reply[] = resp.create(ctx, 0, req.readReplyKey(), req.readReplyIV(), -1); for (int j = 0; j < TunnelBuildMessage.MAX_RECORD_COUNT; j++) {
for (int j = 0; j < TunnelBuildMessage.RECORD_COUNT; j++) {
if (msg.getRecord(j) == null) { if (msg.getRecord(j) == null) {
ourSlot = j; ourSlot = j;
msg.setRecord(j, new ByteArray(reply)); msg.setRecord(j, new ByteArray(reply));
@ -111,11 +109,10 @@ public class BuildMessageTest {
// now all of the replies are populated, toss 'em into a reply message and handle it // now all of the replies are populated, toss 'em into a reply message and handle it
TunnelBuildReplyMessage reply = new TunnelBuildReplyMessage(ctx); TunnelBuildReplyMessage reply = new TunnelBuildReplyMessage(ctx);
for (int i = 0; i < TunnelBuildMessage.RECORD_COUNT; i++) for (int i = 0; i < TunnelBuildMessage.MAX_RECORD_COUNT; i++)
reply.setRecord(i, msg.getRecord(i)); reply.setRecord(i, msg.getRecord(i));
BuildReplyHandler handler = new BuildReplyHandler(); int statuses[] = BuildReplyHandler.decrypt(ctx, reply, cfg, order);
int statuses[] = handler.decrypt(ctx, reply, cfg, order);
if (statuses == null) throw new RuntimeException("bar"); if (statuses == null) throw new RuntimeException("bar");
boolean allAgree = true; boolean allAgree = true;
for (int i = 0; i < cfg.getLength(); i++) { for (int i = 0; i < cfg.getLength(); i++) {