forked from I2P_Developers/i2p.i2p
I2NP: Don't call toLong() for 1 byte
This commit is contained in:
@ -103,8 +103,7 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl {
|
|||||||
|
|
||||||
System.arraycopy(_key.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
System.arraycopy(_key.getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||||
curIndex += Hash.HASH_LENGTH;
|
curIndex += Hash.HASH_LENGTH;
|
||||||
DataHelper.toLong(out, curIndex, 1, _peerHashes.size());
|
out[curIndex++] = (byte) _peerHashes.size();
|
||||||
curIndex++;
|
|
||||||
for (int i = 0; i < getNumReplies(); i++) {
|
for (int i = 0; i < getNumReplies(); i++) {
|
||||||
System.arraycopy(getReply(i).getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
System.arraycopy(getReply(i).getData(), 0, out, curIndex, Hash.HASH_LENGTH);
|
||||||
curIndex += Hash.HASH_LENGTH;
|
curIndex += Hash.HASH_LENGTH;
|
||||||
|
@ -411,8 +411,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
|||||||
// _log.debug("Write flags: " + flags + " mode: " + getDeliveryMode()
|
// _log.debug("Write flags: " + flags + " mode: " + getDeliveryMode()
|
||||||
// + " =?= " + flagMode(flags));
|
// + " =?= " + flagMode(flags));
|
||||||
int origOffset = offset;
|
int origOffset = offset;
|
||||||
DataHelper.toLong(target, offset, 1, flags);
|
target[offset++] = (byte) flags;
|
||||||
offset++;
|
|
||||||
offset += getAdditionalInfo(target, offset);
|
offset += getAdditionalInfo(target, offset);
|
||||||
return offset - origOffset;
|
return offset - origOffset;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,7 @@ public abstract class FastI2NPMessageImpl extends I2NPMessageImpl {
|
|||||||
}
|
}
|
||||||
int payloadLen = writtenLen - HEADER_LENGTH;
|
int payloadLen = writtenLen - HEADER_LENGTH;
|
||||||
int off = 0;
|
int off = 0;
|
||||||
DataHelper.toLong(buffer, off, 1, getType());
|
buffer[off++] = (byte) getType();
|
||||||
off += 1;
|
|
||||||
DataHelper.toLong(buffer, off, 4, _uniqueId);
|
DataHelper.toLong(buffer, off, 4, _uniqueId);
|
||||||
off += 4;
|
off += 4;
|
||||||
DataHelper.toLong(buffer, off, DataHelper.DATE_LENGTH, _expiration);
|
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);
|
byte[] h = SimpleByteCache.acquire(Hash.HASH_LENGTH);
|
||||||
_context.sha().calculateHash(buffer, off + HEADER_LENGTH, payloadLen, h, 0);
|
_context.sha().calculateHash(buffer, off + HEADER_LENGTH, payloadLen, h, 0);
|
||||||
|
|
||||||
DataHelper.toLong(buffer, off, 1, getType());
|
buffer[off++] = (byte) getType();
|
||||||
off++;
|
|
||||||
|
|
||||||
// Lazy initialization of value
|
// Lazy initialization of value
|
||||||
if (_uniqueId < 0) {
|
if (_uniqueId < 0) {
|
||||||
@ -300,8 +299,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
|||||||
public int toRawByteArray(byte buffer[]) {
|
public int toRawByteArray(byte buffer[]) {
|
||||||
try {
|
try {
|
||||||
int off = 0;
|
int off = 0;
|
||||||
DataHelper.toLong(buffer, off, 1, getType());
|
buffer[off++] = (byte) getType();
|
||||||
off += 1;
|
|
||||||
// January 19 2038? No, unsigned, good until Feb. 7 2106
|
// January 19 2038? No, unsigned, good until Feb. 7 2106
|
||||||
// in seconds, round up so we don't lose time every hop
|
// in seconds, round up so we don't lose time every hop
|
||||||
DataHelper.toLong(buffer, off, 4, (_expiration + 500) / 1000);
|
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) {
|
public int toRawByteArrayNTCP2(byte buffer[], int off) {
|
||||||
try {
|
try {
|
||||||
DataHelper.toLong(buffer, off, 1, getType());
|
buffer[off++] = (byte) getType();
|
||||||
off += 1;
|
|
||||||
// Lazy initialization of value
|
// Lazy initialization of value
|
||||||
if (_uniqueId < 0) {
|
if (_uniqueId < 0) {
|
||||||
_uniqueId = _context.random().nextLong(MAX_ID_VALUE);
|
_uniqueId = _context.random().nextLong(MAX_ID_VALUE);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package net.i2p.data.i2np;
|
package net.i2p.data.i2np;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.data.DataHelper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Variable number of records.
|
* Variable number of records.
|
||||||
@ -46,7 +45,7 @@ public class VariableTunnelBuildMessage extends TunnelBuildMessage {
|
|||||||
throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
|
throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
|
||||||
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
|
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
|
||||||
throw new I2NPMessageException("Bad record count " + 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
|
// can't call super, written length check will fail
|
||||||
//return super.writeMessageBody(out, curIndex + 1);
|
//return super.writeMessageBody(out, curIndex + 1);
|
||||||
for (int i = 0; i < RECORD_COUNT; i++) {
|
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 + ")");
|
throw new I2NPMessageException("Not large enough (too short by " + remaining + ")");
|
||||||
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
|
if (RECORD_COUNT <= 0 || RECORD_COUNT > MAX_RECORD_COUNT)
|
||||||
throw new I2NPMessageException("Bad record count " + 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
|
// can't call super, written length check will fail
|
||||||
//return super.writeMessageBody(out, curIndex + 1);
|
//return super.writeMessageBody(out, curIndex + 1);
|
||||||
for (int i = 0; i < RECORD_COUNT; i++) {
|
for (int i = 0; i < RECORD_COUNT; i++) {
|
||||||
|
Reference in New Issue
Block a user