forked from I2P_Developers/i2p.i2p
More: Don't use DataHelper.readLong() for 1-byte reads, for efficiency
This commit is contained in:
@ -585,7 +585,7 @@ class Packet {
|
||||
cur += 4;
|
||||
setAckThrough(DataHelper.fromLong(buffer, cur, 4));
|
||||
cur += 4;
|
||||
int numNacks = (int)DataHelper.fromLong(buffer, cur, 1);
|
||||
int numNacks = buffer[cur] & 0xff;
|
||||
cur++;
|
||||
if (length < 22 + numNacks*4)
|
||||
throw new IllegalArgumentException("Too small with " + numNacks + " nacks: " + length);
|
||||
@ -599,7 +599,7 @@ class Packet {
|
||||
} else {
|
||||
setNacks(null);
|
||||
}
|
||||
setResendDelay((int)DataHelper.fromLong(buffer, cur, 1));
|
||||
setResendDelay(buffer[cur] & 0xff);
|
||||
cur++;
|
||||
setFlags((int)DataHelper.fromLong(buffer, cur, 2));
|
||||
cur += 2;
|
||||
|
@ -215,7 +215,7 @@ public class Certificate extends DataStructureImpl {
|
||||
throw new DataFormatException("Cert is too small [" + source.length + " off=" + offset + "]");
|
||||
|
||||
int cur = offset;
|
||||
_type = (int)DataHelper.fromLong(source, cur, 1);
|
||||
_type = source[cur] & 0xff;
|
||||
cur++;
|
||||
int length = (int)DataHelper.fromLong(source, cur, 2);
|
||||
cur += 2;
|
||||
|
@ -68,7 +68,7 @@ public class DatabaseSearchReplyMessage extends FastI2NPMessageImpl {
|
||||
curIndex += Hash.HASH_LENGTH;
|
||||
//_key = new Hash(keyData);
|
||||
|
||||
int num = (int)DataHelper.fromLong(data, curIndex, 1);
|
||||
int num = data[curIndex] & 0xff;
|
||||
curIndex++;
|
||||
|
||||
_peerHashes.clear();
|
||||
|
@ -209,7 +209,7 @@ public class DeliveryInstructions extends DataStructureImpl {
|
||||
|
||||
public int readBytes(byte data[], int offset) throws DataFormatException {
|
||||
int cur = offset;
|
||||
long flags = DataHelper.fromLong(data, cur, 1);
|
||||
int flags = data[cur] & 0xff;
|
||||
cur++;
|
||||
//if (_log.shouldLog(Log.DEBUG))
|
||||
// _log.debug("Read flags: " + flags + " mode: " + flagMode(flags));
|
||||
|
@ -85,7 +85,7 @@ public abstract class FastI2NPMessageImpl extends I2NPMessageImpl {
|
||||
throw new I2NPMessageException("Payload is too short " + maxLen);
|
||||
int cur = offset;
|
||||
if (type < 0) {
|
||||
type = (int)DataHelper.fromLong(data, cur, 1);
|
||||
type = data[cur] & 0xff;
|
||||
cur++;
|
||||
}
|
||||
_uniqueId = DataHelper.fromLong(data, cur, 4);
|
||||
|
@ -109,7 +109,7 @@ public class I2NPMessageHandler {
|
||||
public int readMessage(byte data[], int offset, int maxLen) throws I2NPMessageException {
|
||||
int cur = offset;
|
||||
// we will assume that maxLen is >= 1 here. It's checked to be >= 16 in readBytes()
|
||||
int type = (int)DataHelper.fromLong(data, cur, 1);
|
||||
int type = data[cur] & 0xff;
|
||||
cur++;
|
||||
_lastReadBegin = System.currentTimeMillis();
|
||||
I2NPMessage msg = I2NPMessageImpl.createMessage(_context, type);
|
||||
|
@ -197,7 +197,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
throw new I2NPMessageException("Payload is too short " + maxLen);
|
||||
int cur = offset;
|
||||
if (type < 0) {
|
||||
type = (int)DataHelper.fromLong(data, cur, 1);
|
||||
type = data[cur] & 0xff;
|
||||
cur++;
|
||||
}
|
||||
_uniqueId = DataHelper.fromLong(data, cur, 4);
|
||||
@ -413,7 +413,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
*/
|
||||
public static I2NPMessage fromRawByteArray(I2PAppContext ctx, byte buffer[], int offset,
|
||||
int len, I2NPMessageHandler handler) throws I2NPMessageException {
|
||||
int type = (int)DataHelper.fromLong(buffer, offset, 1);
|
||||
int type = buffer[offset] & 0xff;
|
||||
offset++;
|
||||
I2NPMessage msg = createMessage(ctx, type);
|
||||
if (msg == null)
|
||||
|
@ -29,7 +29,7 @@ public class VariableTunnelBuildMessage extends TunnelBuildMessage {
|
||||
@Override
|
||||
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException {
|
||||
// message type will be checked in super()
|
||||
int r = (int)DataHelper.fromLong(data, offset, 1);
|
||||
int r = data[offset] & 0xff;
|
||||
if (r <= 0 || r > MAX_RECORD_COUNT)
|
||||
throw new I2NPMessageException("Bad record count " + r);
|
||||
RECORD_COUNT = r;
|
||||
|
@ -31,7 +31,7 @@ public class VariableTunnelBuildReplyMessage extends TunnelBuildReplyMessage {
|
||||
@Override
|
||||
public void readMessage(byte[] data, int offset, int dataSize, int type) throws I2NPMessageException {
|
||||
// message type will be checked in super()
|
||||
int r = (int)DataHelper.fromLong(data, offset, 1);
|
||||
int r = data[offset] & 0xff;
|
||||
if (r <= 0 || r > MAX_RECORD_COUNT)
|
||||
throw new I2NPMessageException("Bad record count " + r);
|
||||
RECORD_COUNT = r;
|
||||
|
@ -75,7 +75,7 @@ public class GarlicMessageParser {
|
||||
private CloveSet readCloveSet(byte data[]) throws DataFormatException {
|
||||
int offset = 0;
|
||||
|
||||
int numCloves = (int)DataHelper.fromLong(data, offset, 1);
|
||||
int numCloves = data[offset] & 0xff;
|
||||
offset++;
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("# cloves to read: " + numCloves);
|
||||
|
@ -120,7 +120,7 @@ public class BuildReplyHandler {
|
||||
return -1;
|
||||
} else {
|
||||
SimpleByteCache.release(h);
|
||||
int rv = (int)DataHelper.fromLong(data, TunnelBuildReplyMessage.RECORD_SIZE - 1, 1);
|
||||
int rv = data[TunnelBuildReplyMessage.RECORD_SIZE - 1] & 0xff;
|
||||
if (log.shouldLog(Log.DEBUG))
|
||||
log.debug(reply.getUniqueId() + ": Verified: " + rv + " for record " + recordNum + "/" + hop);
|
||||
return rv;
|
||||
|
@ -340,7 +340,7 @@ class FragmentHandler {
|
||||
offset += 4;
|
||||
}
|
||||
if (extended) {
|
||||
int extendedSize = (int)DataHelper.fromLong(preprocessed, offset, 1);
|
||||
int extendedSize = preprocessed[offset] & 0xff;
|
||||
offset++;
|
||||
offset += extendedSize; // we don't interpret these yet, but skip them for now
|
||||
}
|
||||
|
Reference in New Issue
Block a user