- Set lookup type flags even if no reply tunnel specified
- Reduce object churn when writing some messages
This commit is contained in:
zzz
2014-11-15 17:45:14 +00:00
parent 7f72830ec8
commit 279e102d7a
5 changed files with 33 additions and 39 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;