explcitly define the max I2NP message ID value and validate against it
This commit is contained in:
@ -98,7 +98,18 @@ public class DatabaseStoreMessage extends I2NPMessageImpl {
|
||||
* @return positive reply token ID, or 0 if no reply is necessary.
|
||||
*/
|
||||
public long getReplyToken() { return _replyToken; }
|
||||
public void setReplyToken(long token) { _replyToken = token; }
|
||||
/**
|
||||
* Update the reply token.
|
||||
*
|
||||
* @throws IllegalArgumentException if the token is out of range (min=0, max=I2NPMessage.MAX_ID_VALUE)
|
||||
*/
|
||||
public void setReplyToken(long token) throws IllegalArgumentException {
|
||||
if (token > I2NPMessage.MAX_ID_VALUE)
|
||||
throw new IllegalArgumentException("Token too large: " + token + " (max=" + I2NPMessage.MAX_ID_VALUE + ")");
|
||||
else if (token < 0)
|
||||
throw new IllegalArgumentException("Token too small: " + token);
|
||||
_replyToken = token;
|
||||
}
|
||||
|
||||
public TunnelId getReplyTunnel() { return _replyTunnel; }
|
||||
public void setReplyTunnel(TunnelId id) { _replyTunnel = id; }
|
||||
|
@ -20,6 +20,8 @@ import net.i2p.data.DataStructure;
|
||||
* @author jrandom
|
||||
*/
|
||||
public interface I2NPMessage extends DataStructure {
|
||||
final long MAX_ID_VALUE = (1l<<32l)-1l;
|
||||
|
||||
/**
|
||||
* Read the body into the data structures, after the initial type byte, using
|
||||
* the current class's format as defined by the I2NP specification
|
||||
|
@ -36,7 +36,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
|
||||
_context = context;
|
||||
_log = context.logManager().getLog(I2NPMessageImpl.class);
|
||||
_expiration = new Date(_context.clock().now() + DEFAULT_EXPIRATION_MS);
|
||||
_uniqueId = _context.random().nextInt(Integer.MAX_VALUE);
|
||||
_uniqueId = _context.random().nextLong(MAX_ID_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user