forked from I2P_Developers/i2p.i2p
* I2CP: Fix external I2CP apps, including i2ping, caused by 0 nonce value,
broken in 0.9.2 (tickets #799, #801). Allow nonces == 0. Javadocs and cleanups.
This commit is contained in:
@@ -122,6 +122,7 @@ class I2CPMessageProducer {
|
||||
/**
|
||||
* Package up and send the payload to the router for delivery
|
||||
*
|
||||
* @param nonce 0 to 0xffffffff; if 0, the router will not reply with a MessageStatusMessage
|
||||
* @param tag unused - no end-to-end crypto
|
||||
* @param tags unused - no end-to-end crypto
|
||||
* @param key unused - no end-to-end crypto
|
||||
@@ -134,6 +135,8 @@ class I2CPMessageProducer {
|
||||
|
||||
/**
|
||||
* Package up and send the payload to the router for delivery
|
||||
*
|
||||
* @param nonce 0 to 0xffffffff; if 0, the router will not reply with a MessageStatusMessage
|
||||
* @since 0.8.4
|
||||
*/
|
||||
public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload,
|
||||
@@ -160,6 +163,8 @@ class I2CPMessageProducer {
|
||||
|
||||
/**
|
||||
* Package up and send the payload to the router for delivery
|
||||
*
|
||||
* @param nonce 0 to 0xffffffff; if 0, the router will not reply with a MessageStatusMessage
|
||||
* @since 0.9.2
|
||||
*/
|
||||
public void sendMessage(I2PSessionImpl session, Destination dest, long nonce, byte[] payload,
|
||||
|
@@ -309,7 +309,7 @@ class I2PSessionImpl2 extends I2PSessionImpl {
|
||||
|
||||
//if (_log.shouldLog(Log.DEBUG)) _log.debug("before creating nonce");
|
||||
|
||||
long nonce = _context.random().nextInt(Integer.MAX_VALUE);
|
||||
long nonce = _context.random().nextInt(Integer.MAX_VALUE - 1) + 1;
|
||||
//if (_log.shouldLog(Log.DEBUG)) _log.debug("before sync state");
|
||||
MessageState state = new MessageState(_context, nonce, getPrefix());
|
||||
//state.setKey(key);
|
||||
|
@@ -105,17 +105,23 @@ public class SendMessageExpiresMessage extends SendMessageMessage {
|
||||
*/
|
||||
@Override
|
||||
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
|
||||
if ((getSessionId() == null) || (getDestination() == null) || (getPayload() == null) || (getNonce() <= 0))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
int len = 2 + getDestination().size() + getPayload().getSize() + 4 + 4 + DataHelper.DATE_LENGTH;
|
||||
if (_sessionId == null)
|
||||
throw new I2CPMessageException("No session ID");
|
||||
if (_destination == null)
|
||||
throw new I2CPMessageException("No dest");
|
||||
if (_payload == null)
|
||||
throw new I2CPMessageException("No payload");
|
||||
if (_nonce < 0)
|
||||
throw new I2CPMessageException("No nonce");
|
||||
int len = 2 + _destination.size() + _payload.getSize() + 4 + 4 + DataHelper.DATE_LENGTH;
|
||||
|
||||
try {
|
||||
DataHelper.writeLong(out, 4, len);
|
||||
DataHelper.writeLong(out, 1, getType());
|
||||
getSessionId().writeBytes(out);
|
||||
getDestination().writeBytes(out);
|
||||
getPayload().writeBytes(out);
|
||||
DataHelper.writeLong(out, 4, getNonce());
|
||||
DataHelper.writeLong(out, 1, MESSAGE_TYPE);
|
||||
_sessionId.writeBytes(out);
|
||||
_destination.writeBytes(out);
|
||||
_payload.writeBytes(out);
|
||||
DataHelper.writeLong(out, 4, _nonce);
|
||||
_daf.writeBytes(out);
|
||||
} catch (DataFormatException dfe) {
|
||||
throw new I2CPMessageException("Error writing the msg", dfe);
|
||||
@@ -142,12 +148,12 @@ public class SendMessageExpiresMessage extends SendMessageMessage {
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append("[SendMessageMessage: ");
|
||||
buf.append("\n\tSessionId: ").append(getSessionId());
|
||||
buf.append("\n\tNonce: ").append(getNonce());
|
||||
buf.append("\n\tDestination: ").append(getDestination());
|
||||
buf.append("[SendMessageExpiresMessage: ");
|
||||
buf.append("\n\tSessionId: ").append(_sessionId);
|
||||
buf.append("\n\tNonce: ").append(_nonce);
|
||||
buf.append("\n\tDestination: ").append(_destination);
|
||||
buf.append("\n\tExpiration: ").append(getExpiration());
|
||||
buf.append("\n\tPayload: ").append(getPayload());
|
||||
buf.append("\n\tPayload: ").append(_payload);
|
||||
buf.append("]");
|
||||
return buf.toString();
|
||||
}
|
||||
|
@@ -26,10 +26,10 @@ import net.i2p.data.Payload;
|
||||
*/
|
||||
public class SendMessageMessage extends I2CPMessageImpl {
|
||||
public final static int MESSAGE_TYPE = 5;
|
||||
private SessionId _sessionId;
|
||||
private Destination _destination;
|
||||
private Payload _payload;
|
||||
private long _nonce;
|
||||
protected SessionId _sessionId;
|
||||
protected Destination _destination;
|
||||
protected Payload _payload;
|
||||
protected long _nonce;
|
||||
|
||||
public SendMessageMessage() {
|
||||
}
|
||||
@@ -58,10 +58,16 @@ public class SendMessageMessage extends I2CPMessageImpl {
|
||||
_payload = payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 0 to 0xffffffff
|
||||
*/
|
||||
public long getNonce() {
|
||||
return _nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param 0 to 0xffffffff
|
||||
*/
|
||||
public void setNonce(long nonce) {
|
||||
_nonce = nonce;
|
||||
}
|
||||
@@ -109,8 +115,14 @@ public class SendMessageMessage extends I2CPMessageImpl {
|
||||
*/
|
||||
@Override
|
||||
public void writeMessage(OutputStream out) throws I2CPMessageException, IOException {
|
||||
if ((_sessionId == null) || (_destination == null) || (_payload == null) || (_nonce <= 0))
|
||||
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
|
||||
if (_sessionId == null)
|
||||
throw new I2CPMessageException("No session ID");
|
||||
if (_destination == null)
|
||||
throw new I2CPMessageException("No dest");
|
||||
if (_payload == null)
|
||||
throw new I2CPMessageException("No payload");
|
||||
if (_nonce < 0)
|
||||
throw new I2CPMessageException("No nonce");
|
||||
int len = 2 + _destination.size() + _payload.getSize() + 4 + 4;
|
||||
|
||||
try {
|
||||
|
Reference in New Issue
Block a user