Skip to content

Commit e6687be

Browse files
committedAug 4, 2013
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
1 parent 8831669 commit e6687be

File tree

4 files changed

+229
-168
lines changed

4 files changed

+229
-168
lines changed
 

‎src/connection.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,13 @@ RPBSearchResult ReliablePacketBuffer::notFound()
207207
{
208208
return m_list.end();
209209
}
210-
u16 ReliablePacketBuffer::getFirstSeqnum()
210+
bool ReliablePacketBuffer::getFirstSeqnum(u16 *result)
211211
{
212212
if(empty())
213-
throw NotFoundException("Buffer is empty");
213+
return false;
214214
BufferedPacket p = *m_list.begin();
215-
return readU16(&p.data[BASE_HEADER_SIZE+1]);
215+
*result = readU16(&p.data[BASE_HEADER_SIZE+1]);
216+
return true;
216217
}
217218
BufferedPacket ReliablePacketBuffer::popFirst()
218219
{
@@ -700,7 +701,7 @@ void Connection::receive()
700701

701702
bool single_wait_done = false;
702703

703-
for(;;)
704+
for(u32 loop_i=0; loop_i<1000; loop_i++) // Limit in case of DoS
704705
{
705706
try{
706707
/* Check if some buffer has relevant data */
@@ -1245,17 +1246,16 @@ bool Connection::checkIncomingBuffers(Channel *channel, u16 &peer_id,
12451246
{
12461247
u16 firstseqnum = 0;
12471248
// Clear old packets from start of buffer
1248-
try{
12491249
for(;;){
1250-
firstseqnum = channel->incoming_reliables.getFirstSeqnum();
1250+
bool found = channel->incoming_reliables.getFirstSeqnum(&firstseqnum);
1251+
if(!found)
1252+
break;
12511253
if(seqnum_higher(channel->next_incoming_seqnum, firstseqnum))
12521254
channel->incoming_reliables.popFirst();
12531255
else
12541256
break;
12551257
}
12561258
// This happens if all packets are old
1257-
}catch(con::NotFoundException)
1258-
{}
12591259

12601260
if(channel->incoming_reliables.empty() == false)
12611261
{

‎src/connection.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class ReliablePacketBuffer
281281
u32 size();
282282
RPBSearchResult findPacket(u16 seqnum);
283283
RPBSearchResult notFound();
284-
u16 getFirstSeqnum();
284+
bool getFirstSeqnum(u16 *result);
285285
BufferedPacket popFirst();
286286
BufferedPacket popSeqnum(u16 seqnum);
287287
void insert(BufferedPacket &p);

0 commit comments

Comments
 (0)
Please sign in to comment.