I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit a5a5f7db authored by zzz's avatar zzz
Browse files

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

parent 30f25de4
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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);
......
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++) {
......
......@@ -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++) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment