forked from I2P_Developers/i2p.i2p
I2NP:
- Set lookup type flags even if no reply tunnel specified - Reduce object churn when writing some messages
This commit is contained in:
@ -70,8 +70,7 @@ public class DataMessage extends FastI2NPMessageImpl {
|
||||
out[curIndex++] = 0x0;
|
||||
out[curIndex++] = 0x0;
|
||||
} else {
|
||||
byte len[] = DataHelper.toLong(4, _data.length);
|
||||
System.arraycopy(len, 0, out, curIndex, 4);
|
||||
DataHelper.toLong(out, curIndex, 4, _data.length);
|
||||
curIndex += 4;
|
||||
System.arraycopy(_data, 0, out, curIndex, _data.length);
|
||||
curIndex += _data.length;
|
||||
|
@ -404,33 +404,33 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
System.arraycopy(_fromHash.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
// Generate the flag byte
|
||||
byte flag;
|
||||
if (_replyKey != null)
|
||||
flag = FLAG_ENCRYPT;
|
||||
else
|
||||
flag = 0;
|
||||
switch (_type) {
|
||||
case LS:
|
||||
flag |= FLAG_TYPE_LS;
|
||||
break;
|
||||
case RI:
|
||||
flag |= FLAG_TYPE_RI;
|
||||
break;
|
||||
case EXPL:
|
||||
flag |= FLAG_TYPE_EXPL;
|
||||
break;
|
||||
case ANY:
|
||||
default:
|
||||
// lookup type bits are 0
|
||||
break;
|
||||
}
|
||||
if (_replyTunnel != null) {
|
||||
byte flag = FLAG_TUNNEL;
|
||||
if (_replyKey != null)
|
||||
flag |= FLAG_ENCRYPT;
|
||||
switch (_type) {
|
||||
case LS:
|
||||
flag |= FLAG_TYPE_LS;
|
||||
break;
|
||||
case RI:
|
||||
flag |= FLAG_TYPE_RI;
|
||||
break;
|
||||
case EXPL:
|
||||
flag |= FLAG_TYPE_EXPL;
|
||||
break;
|
||||
case ANY:
|
||||
default:
|
||||
// flag is 0
|
||||
break;
|
||||
}
|
||||
flag |= FLAG_TUNNEL;
|
||||
out[curIndex++] = flag;
|
||||
byte id[] = DataHelper.toLong(4, _replyTunnel.getTunnelId());
|
||||
System.arraycopy(id, 0, out, curIndex, 4);
|
||||
DataHelper.toLong(out, curIndex, 4, _replyTunnel.getTunnelId());
|
||||
curIndex += 4;
|
||||
} else if (_replyKey != null) {
|
||||
out[curIndex++] = FLAG_ENCRYPT;
|
||||
} else {
|
||||
out[curIndex++] = 0x00;
|
||||
out[curIndex++] = flag;
|
||||
}
|
||||
if ( (_dontIncludePeers == null) || (_dontIncludePeers.isEmpty()) ) {
|
||||
out[curIndex++] = 0x0;
|
||||
@ -439,9 +439,8 @@ public class DatabaseLookupMessage extends FastI2NPMessageImpl {
|
||||
int size = _dontIncludePeers.size();
|
||||
if (size > MAX_NUM_PEERS)
|
||||
throw new I2NPMessageException("Too many peers: " + size);
|
||||
byte len[] = DataHelper.toLong(2, size);
|
||||
out[curIndex++] = len[0];
|
||||
out[curIndex++] = len[1];
|
||||
DataHelper.toLong(out, curIndex, 2, size);
|
||||
curIndex += 2;
|
||||
for (Hash peer : _dontIncludePeers) {
|
||||
System.arraycopy(peer.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
|
@ -103,8 +103,8 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl {
|
||||
|
||||
System.arraycopy(_key.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
byte len[] = DataHelper.toLong(1, _peerHashes.size());
|
||||
out[curIndex++] = len[0];
|
||||
DataHelper.toLong(out, curIndex, 1, _peerHashes.size());
|
||||
curIndex++;
|
||||
for (int i = 0; i < getNumReplies(); i++) {
|
||||
System.arraycopy(getReply(i).getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
|
@ -204,16 +204,14 @@ public class DatabaseStoreMessage extends FastI2NPMessageImpl {
|
||||
System.arraycopy(getKey().getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
out[curIndex++] = (byte) type;
|
||||
byte tok[] = DataHelper.toLong(4, _replyToken);
|
||||
System.arraycopy(tok, 0, out, curIndex, 4);
|
||||
DataHelper.toLong(out, curIndex, 4, _replyToken);
|
||||
curIndex += 4;
|
||||
|
||||
if (_replyToken > 0) {
|
||||
long replyTunnel = 0;
|
||||
if (_replyTunnel != null)
|
||||
replyTunnel = _replyTunnel.getTunnelId();
|
||||
byte id[] = DataHelper.toLong(4, replyTunnel);
|
||||
System.arraycopy(id, 0, out, curIndex, 4);
|
||||
DataHelper.toLong(out, curIndex, 4, replyTunnel);
|
||||
curIndex += 4;
|
||||
System.arraycopy(_replyGateway.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
@ -221,9 +219,8 @@ public class DatabaseStoreMessage extends FastI2NPMessageImpl {
|
||||
|
||||
// _byteCache initialized in calculateWrittenLength
|
||||
if (type == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
|
||||
byte len[] = DataHelper.toLong(2, _byteCache.length);
|
||||
out[curIndex++] = len[0];
|
||||
out[curIndex++] = len[1];
|
||||
DataHelper.toLong(out, curIndex, 2, _byteCache.length);
|
||||
curIndex += 2;
|
||||
}
|
||||
System.arraycopy(_byteCache, 0, out, curIndex, _byteCache.length);
|
||||
curIndex += _byteCache.length;
|
||||
|
@ -54,8 +54,7 @@ public class GarlicMessage extends FastI2NPMessageImpl {
|
||||
}
|
||||
/** write the message body to the output array, starting at the given index */
|
||||
protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException {
|
||||
byte len[] = DataHelper.toLong(4, _data.length);
|
||||
System.arraycopy(len, 0, out, curIndex, 4);
|
||||
DataHelper.toLong(out, curIndex, 4, _data.length);
|
||||
curIndex += 4;
|
||||
System.arraycopy(_data, 0, out, curIndex, _data.length);
|
||||
curIndex += _data.length;
|
||||
|
Reference in New Issue
Block a user