I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 6635448b authored by zzz's avatar zzz
Browse files

* I2CP: Make separate message ID counters per-destination, use atomic,

         increase max (could have caused "local loopback" problems)
parent baa89c5b
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ import java.util.List; ...@@ -18,6 +18,7 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import net.i2p.client.I2PClient; import net.i2p.client.I2PClient;
import net.i2p.crypto.SessionKeyManager; import net.i2p.crypto.SessionKeyManager;
...@@ -86,7 +87,14 @@ class ClientConnectionRunner { ...@@ -86,7 +87,14 @@ class ClientConnectionRunner {
private boolean _dead; private boolean _dead;
/** For outbound traffic. true if i2cp.messageReliability = "none"; @since 0.8.1 */ /** For outbound traffic. true if i2cp.messageReliability = "none"; @since 0.8.1 */
private boolean _dontSendMSM; private boolean _dontSendMSM;
private final AtomicInteger _messageId; // messageId counter
// Was 32767 since the beginning (04-2004).
// But it's 4 bytes in the I2CP spec and stored as a long in MessageID....
// If this is too low and wraps around, I2CP VerifyUsage could delete the wrong message,
// e.g. on local access
private static final int MAX_MESSAGE_ID = 0x4000000;
/** /**
* Create a new runner against the given socket * Create a new runner against the given socket
* *
...@@ -99,6 +107,7 @@ class ClientConnectionRunner { ...@@ -99,6 +107,7 @@ class ClientConnectionRunner {
_messages = new ConcurrentHashMap(); _messages = new ConcurrentHashMap();
_alreadyProcessed = new ArrayList(); _alreadyProcessed = new ArrayList();
_acceptedPending = new ConcurrentHashSet(); _acceptedPending = new ConcurrentHashSet();
_messageId = new AtomicInteger(_context.random().nextInt());
} }
private static volatile int __id = 0; private static volatile int __id = 0;
...@@ -520,18 +529,9 @@ class ClientConnectionRunner { ...@@ -520,18 +529,9 @@ class ClientConnectionRunner {
} }
} }
// this *should* be mod 65536, but UnsignedInteger is still b0rked. FIXME public int getNextMessageId() {
private final static int MAX_MESSAGE_ID = 32767; // Don't % so we don't get negative IDs
private static volatile int _messageId = RandomSource.getInstance().nextInt(MAX_MESSAGE_ID); // messageId counter return _messageId.incrementAndGet() & (MAX_MESSAGE_ID - 1);
private final static Object _messageIdLock = new Object();
static int getNextMessageId() {
synchronized (_messageIdLock) {
int messageId = (++_messageId)%MAX_MESSAGE_ID;
if (_messageId >= MAX_MESSAGE_ID)
_messageId = 0;
return messageId;
}
} }
/** /**
......
...@@ -36,7 +36,7 @@ class MessageReceivedJob extends JobImpl { ...@@ -36,7 +36,7 @@ class MessageReceivedJob extends JobImpl {
public void runJob() { public void runJob() {
if (_runner.isDead()) return; if (_runner.isDead()) return;
MessageId id = new MessageId(); MessageId id = new MessageId();
id.setMessageId(ClientConnectionRunner.getNextMessageId()); id.setMessageId(_runner.getNextMessageId());
_runner.setPayload(id, _payload); _runner.setPayload(id, _payload);
messageAvailable(id, _payload.getSize()); messageAvailable(id, _payload.getSize());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment