forked from I2P_Developers/i2p.i2p
Assorted fixes to router Junit tests for changes in the source
This commit is contained in:
@ -29,7 +29,7 @@ public class DateMessage extends I2NPMessageImpl {
|
||||
public long getNow() { return _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");
|
||||
int curIndex = offset;
|
||||
|
||||
|
@ -49,7 +49,6 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
|
||||
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 TunnelId INVALID_TUNNEL = TunnelId.INVALID;
|
||||
|
||||
public TunnelCreateMessage(I2PAppContext context) {
|
||||
super(context);
|
||||
@ -83,7 +82,7 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
|
||||
public Properties getOptions() { return _options; }
|
||||
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 (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; // ivKey
|
||||
|
||||
if (_optionsCache == null)
|
||||
_optionsCache = DataHelper.toProperties(_options);
|
||||
length += _optionsCache.length;
|
||||
if (_optionsCache == null) {
|
||||
try {
|
||||
_optionsCache = DataHelper.toProperties(_options);
|
||||
length += _optionsCache.length;
|
||||
} catch (DataFormatException dfe) {
|
||||
}
|
||||
}
|
||||
|
||||
length += Hash.HASH_LENGTH; // replyGateway
|
||||
length += 4; // replyTunnel
|
||||
@ -200,8 +203,13 @@ public class TunnelCreateMessage extends I2NPMessageImpl {
|
||||
System.arraycopy(_ivKey.getData(), 0, data, offset, SessionKey.KEYSIZE_BYTES);
|
||||
offset += SessionKey.KEYSIZE_BYTES;
|
||||
|
||||
if (_optionsCache == null)
|
||||
_optionsCache = DataHelper.toProperties(_options);
|
||||
if (_optionsCache == null) {
|
||||
try {
|
||||
_optionsCache = DataHelper.toProperties(_options);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2NPMessageException("Error reading the options", dfe);
|
||||
}
|
||||
}
|
||||
System.arraycopy(_optionsCache, 0, data, offset, _optionsCache.length);
|
||||
offset += _optionsCache.length;
|
||||
|
||||
|
@ -50,7 +50,7 @@ public class TunnelCreateStatusMessage extends I2NPMessageImpl {
|
||||
public long getNonce() { return _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");
|
||||
int curIndex = offset;
|
||||
|
||||
|
@ -237,7 +237,7 @@ public class SSUDemo {
|
||||
|
||||
public int getType() { return MESSAGE_TYPE; }
|
||||
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];
|
||||
System.arraycopy(data, offset, _data, 0, dataSize);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.SessionTag;
|
||||
import net.i2p.data.i2np.GarlicMessage;
|
||||
import net.i2p.router.Job;
|
||||
import net.i2p.router.JobImpl;
|
||||
@ -38,7 +39,7 @@ public class SendGarlicJob extends JobImpl {
|
||||
private MessageSelector _replySelector;
|
||||
private GarlicMessage _message;
|
||||
private SessionKey _wrappedKey;
|
||||
private Set _wrappedTags;
|
||||
private Set<SessionTag> _wrappedTags;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -50,16 +50,15 @@ public class BuildMessageTest {
|
||||
_replyTunnel = 42;
|
||||
|
||||
// populate and encrypt the message
|
||||
BuildMessageGenerator gen = new BuildMessageGenerator();
|
||||
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();
|
||||
PublicKey key = null;
|
||||
if (hop < _pubKeys.length)
|
||||
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================================================================" +
|
||||
"\nMessage fully encrypted" +
|
||||
@ -86,10 +85,9 @@ public class BuildMessageTest {
|
||||
long time = req.readRequestTime();
|
||||
long now = (ctx.clock().now() / (60l*60l*1000l)) * (60*60*1000);
|
||||
int ourSlot = -1;
|
||||
|
||||
BuildResponseRecord resp = new BuildResponseRecord();
|
||||
byte reply[] = resp.create(ctx, 0, req.readReplyKey(), req.readReplyIV(), -1);
|
||||
for (int j = 0; j < TunnelBuildMessage.RECORD_COUNT; j++) {
|
||||
|
||||
byte reply[] = BuildResponseRecord.create(ctx, 0, req.readReplyKey(), req.readReplyIV(), -1);
|
||||
for (int j = 0; j < TunnelBuildMessage.MAX_RECORD_COUNT; j++) {
|
||||
if (msg.getRecord(j) == null) {
|
||||
ourSlot = j;
|
||||
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
|
||||
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));
|
||||
|
||||
BuildReplyHandler handler = new BuildReplyHandler();
|
||||
int statuses[] = handler.decrypt(ctx, reply, cfg, order);
|
||||
|
||||
int statuses[] = BuildReplyHandler.decrypt(ctx, reply, cfg, order);
|
||||
if (statuses == null) throw new RuntimeException("bar");
|
||||
boolean allAgree = true;
|
||||
for (int i = 0; i < cfg.getLength(); i++) {
|
||||
|
Reference in New Issue
Block a user