I2NP: Don't call toLong() for 1 byte

This commit is contained in:
zzz
2018-08-04 14:50:33 +00:00
parent 30f25de49b
commit a5a5f7dbde
6 changed files with 8 additions and 15 deletions

View File

@ -103,8 +103,7 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl {
System.arraycopy(_key.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
curIndex += Hash.HASH_LENGTH;
DataHelper.toLong(out, curIndex, 1, _peerHashes.size());
curIndex++;
out[curIndex++] = (byte) _peerHashes.size();
for (int i = 0; i < getNumReplies(); i++) {
System.arraycopy(getReply(i).getData(), 0, out, curIndex, Hash.HASH_LENGTH);
curIndex += Hash.HASH_LENGTH;

View File

@ -411,8 +411,7 @@ public class DeliveryInstructions extends DataStructureImpl {
// _log.debug("Write flags: " + flags + " mode: " + getDeliveryMode()
// + " =?= " + flagMode(flags));
int origOffset = offset;
DataHelper.toLong(target, offset, 1, flags);
offset++;
target[offset++] = (byte) flags;
offset += getAdditionalInfo(target, offset);
return offset - origOffset;
}

View File

@ -150,8 +150,7 @@ public abstract class FastI2NPMessageImpl extends I2NPMessageImpl {
}
int payloadLen = writtenLen - HEADER_LENGTH;
int off = 0;
DataHelper.toLong(buffer, off, 1, getType());
off += 1;
buffer[off++] = (byte) getType();
DataHelper.toLong(buffer, off, 4, _uniqueId);
off += 4;
DataHelper.toLong(buffer, off, DataHelper.DATE_LENGTH, _expiration);

View File

@ -257,8 +257,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
byte[] h = SimpleByteCache.acquire(Hash.HASH_LENGTH);
_context.sha().calculateHash(buffer, off + HEADER_LENGTH, payloadLen, h, 0);
DataHelper.toLong(buffer, off, 1, getType());
off++;
buffer[off++] = (byte) getType();
// Lazy initialization of value
if (_uniqueId < 0) {
@ -300,8 +299,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
public int toRawByteArray(byte buffer[]) {
try {
int off = 0;
DataHelper.toLong(buffer, off, 1, getType());
off += 1;
buffer[off++] = (byte) getType();
// January 19 2038? No, unsigned, good until Feb. 7 2106
// in seconds, round up so we don't lose time every hop
DataHelper.toLong(buffer, off, 4, (_expiration + 500) / 1000);
@ -325,8 +323,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
*/
public int toRawByteArrayNTCP2(byte buffer[], int off) {
try {
DataHelper.toLong(buffer, off, 1, getType());
off += 1;
buffer[off++] = (byte) getType();
// Lazy initialization of value
if (_uniqueId < 0) {
_uniqueId = _context.random().nextLong(MAX_ID_VALUE);

View File

@ -1,7 +1,6 @@
package net.i2p.data.i2np;
import net.i2p.I2PAppContext;
import net.i2p.data.DataHelper;
/**
* Variable number of records.
@ -46,7 +45,7 @@ public class VariableTunnelBuildMessage extends TunnelBuildMessage {
throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
throw new I2NPMessageException("Bad record count " + RECORD_COUNT);
DataHelper.toLong(out, curIndex++, 1, RECORD_COUNT);
out[curIndex++] = (byte) RECORD_COUNT;
// can't call super, written length check will fail
//return super.writeMessageBody(out, curIndex + 1);
for (int i = 0; i < RECORD_COUNT; i++) {

View File

@ -48,7 +48,7 @@ public class VariableTunnelBuildReplyMessage extends TunnelBuildReplyMessage {
throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
throw new I2NPMessageException("Bad record count " + RECORD_COUNT);
DataHelper.toLong(out, curIndex++, 1, RECORD_COUNT);
out[curIndex++] = (byte) RECORD_COUNT;
// can't call super, written length check will fail
//return super.writeMessageBody(out, curIndex + 1);
for (int i = 0; i < RECORD_COUNT; i++) {