explcitly define the max I2NP message ID value and validate against it

This commit is contained in:
jrandom
2004-06-29 19:28:40 +00:00
committed by zzz
parent 04373c5d1b
commit af81cf2c50
3 changed files with 15 additions and 2 deletions

View File

@ -98,7 +98,18 @@ public class DatabaseStoreMessage extends I2NPMessageImpl {
* @return positive reply token ID, or 0 if no reply is necessary. * @return positive reply token ID, or 0 if no reply is necessary.
*/ */
public long getReplyToken() { return _replyToken; } 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 TunnelId getReplyTunnel() { return _replyTunnel; }
public void setReplyTunnel(TunnelId id) { _replyTunnel = id; } public void setReplyTunnel(TunnelId id) { _replyTunnel = id; }

View File

@ -20,6 +20,8 @@ import net.i2p.data.DataStructure;
* @author jrandom * @author jrandom
*/ */
public interface I2NPMessage extends DataStructure { 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 * Read the body into the data structures, after the initial type byte, using
* the current class's format as defined by the I2NP specification * the current class's format as defined by the I2NP specification

View File

@ -36,7 +36,7 @@ public abstract class I2NPMessageImpl extends DataStructureImpl implements I2NPM
_context = context; _context = context;
_log = context.logManager().getLog(I2NPMessageImpl.class); _log = context.logManager().getLog(I2NPMessageImpl.class);
_expiration = new Date(_context.clock().now() + DEFAULT_EXPIRATION_MS); _expiration = new Date(_context.clock().now() + DEFAULT_EXPIRATION_MS);
_uniqueId = _context.random().nextInt(Integer.MAX_VALUE); _uniqueId = _context.random().nextLong(MAX_ID_VALUE);
} }
/** /**