aboutsummaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-08-04 08:17:07 +0300
committerPerttu Ahola <celeron55@gmail.com>2013-08-04 10:44:37 +0300
commite6687be4933e5115d31ade014300648051af5047 (patch)
tree320a1bb7ecf718f604ffe386b1d40d547c41d3e3 /src/connection.cpp
parent8831669505905dd9cd415711063f705d8e7ce02c (diff)
downloadminetest-e6687be4933e5115d31ade014300648051af5047.tar.gz
minetest-e6687be4933e5115d31ade014300648051af5047.tar.bz2
minetest-e6687be4933e5115d31ade014300648051af5047.zip
Fix server getting completely choked up on even a little of DoS
* If client count is unbearable, immediately delete denied clients * Re-prioritize the checking order of things about incoming clients * Remove a huge CPU-wasting exception in ReliablePacketBuffer
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index dd7ff597b..42262846f 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -207,12 +207,13 @@ RPBSearchResult ReliablePacketBuffer::notFound()
{
return m_list.end();
}
-u16 ReliablePacketBuffer::getFirstSeqnum()
+bool ReliablePacketBuffer::getFirstSeqnum(u16 *result)
{
if(empty())
- throw NotFoundException("Buffer is empty");
+ return false;
BufferedPacket p = *m_list.begin();
- return readU16(&p.data[BASE_HEADER_SIZE+1]);
+ *result = readU16(&p.data[BASE_HEADER_SIZE+1]);
+ return true;
}
BufferedPacket ReliablePacketBuffer::popFirst()
{
@@ -700,7 +701,7 @@ void Connection::receive()
bool single_wait_done = false;
- for(;;)
+ for(u32 loop_i=0; loop_i<1000; loop_i++) // Limit in case of DoS
{
try{
/* Check if some buffer has relevant data */
@@ -1245,17 +1246,16 @@ bool Connection::checkIncomingBuffers(Channel *channel, u16 &peer_id,
{
u16 firstseqnum = 0;
// Clear old packets from start of buffer
- try{
for(;;){
- firstseqnum = channel->incoming_reliables.getFirstSeqnum();
+ bool found = channel->incoming_reliables.getFirstSeqnum(&firstseqnum);
+ if(!found)
+ break;
if(seqnum_higher(channel->next_incoming_seqnum, firstseqnum))
channel->incoming_reliables.popFirst();
else
break;
}
// This happens if all packets are old
- }catch(con::NotFoundException)
- {}
if(channel->incoming_reliables.empty() == false)
{