aboutsummaryrefslogtreecommitdiff
path: root/src/network/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/network/connection.cpp')
-rw-r--r--src/network/connection.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/network/connection.cpp b/src/network/connection.cpp
index 6fb676f25..f2cdbe435 100644
--- a/src/network/connection.cpp
+++ b/src/network/connection.cpp
@@ -1040,7 +1040,9 @@ bool UDPPeer::processReliableSendCommand(
- BASE_HEADER_SIZE
- RELIABLE_HEADER_SIZE;
- sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512);
+ if (c.data.getSize() >= MAX_RELIABLE_WINDOW_SIZE*512)
+ return false;
+// sanity_check(c.data.getSize() < MAX_RELIABLE_WINDOW_SIZE*512);
std::list<SharedBuffer<u8>> originals;
u16 split_sequence_number = chan.readNextSplitSeqNum();
@@ -1140,7 +1142,7 @@ void UDPPeer::RunCommandQueues(
for (Channel &channel : channels) {
unsigned int commands_processed = 0;
- if ((!channel.queued_commands.empty()) &&
+ while ((!channel.queued_commands.empty()) &&
(channel.queued_reliables.size() < maxtransfer) &&
(commands_processed < maxcommands)) {
try {
@@ -1157,6 +1159,7 @@ void UDPPeer::RunCommandQueues(
<< " Failed to queue packets for peer_id: " << c->peer_id
<< ", delaying sending of " << c->data.getSize()
<< " bytes" << std::endl);
+ break;
}
}
catch (ItemNotFoundException &e) {
@@ -1544,24 +1547,31 @@ u16 Connection::createPeer(Address& sender, MTProtocols protocol, int fd)
// Get a unique peer id (2 or higher)
session_t peer_id_new = m_next_remote_peer_id;
- u16 overflow = MAX_UDP_PEERS;
+// u16 overflow = MAX_UDP_PEERS;
/*
Find an unused peer id
*/
MutexAutoLock lock(m_peers_mutex);
bool out_of_ids = false;
- for(;;) {
+ session_t peer_id_start = peer_id_new;
+ while (1) {
// Check if exists
if (m_peers.find(peer_id_new) == m_peers.end())
break;
- // Check for overflow
- if (peer_id_new == overflow) {
+// // Check for overflow
+// if (peer_id_new == overflow) {
+// out_of_ids = true;
+// break;
+// }
+ peer_id_new++; // Unsigned overflow is indeed defined, and works as expected
+
+ // Proper overflow check
+ if (peer_id_start == peer_id_new) {
out_of_ids = true;
break;
}
- peer_id_new++;
}
if (out_of_ids) {