Improve flood control a bit
authorManuel Nickschas <sputnick@quassel-irc.org>
Tue, 17 Mar 2009 21:46:18 +0000 (22:46 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 17 Mar 2009 21:48:28 +0000 (22:48 +0100)
* Increase token refill rate to 2.2 seconds, should be safer
* Empty send queue on disconnect so we don't get flooded off again

This still needs some love; a bunch of very long lines still causes Excess Flood in
Freenode. I suspect we'll have to introduce a byte rate limit in addition to the line
rate limit :/

src/core/corenetwork.cpp
src/core/corenetwork.h

index dedd819..b89c403 100644 (file)
@@ -192,6 +192,7 @@ void CoreNetwork::disconnectFromIrc(bool requested, const QString &reason, bool
     _autoReconnectCount = 0; // prohibiting auto reconnect
   }
   disablePingTimeout();
+  _msgQueue.clear();
 
   IrcUser *me_ = me();
   if(me_) {
@@ -327,10 +328,10 @@ void CoreNetwork::socketInitialized() {
   }
 
   // TokenBucket to avoid sending too much at once
-  _messagesPerSecond = 1;
+  _messageDelay = 2200;    // this seems to be a safe value (2.2 seconds delay)
   _burstSize = 5;
-  _tokenBucket = 5; // init with a full bucket
-  _tokenBucketTimer.start(_messagesPerSecond * 1000);
+  _tokenBucket = _burstSize; // init with a full bucket
+  _tokenBucketTimer.start(_messageDelay);
 
   if(!server.password.isEmpty()) {
     putRawLine(serverEncode(QString("PASS %1").arg(server.password)));
@@ -341,6 +342,7 @@ void CoreNetwork::socketInitialized() {
 
 void CoreNetwork::socketDisconnected() {
   disablePingTimeout();
+  _msgQueue.clear();
 
   _autoWhoCycleTimer.stop();
   _autoWhoTimer.stop();
index 0a07af9..095e0fe 100644 (file)
@@ -190,7 +190,7 @@ private:
   QTimer _autoWhoTimer, _autoWhoCycleTimer;
 
   QTimer _tokenBucketTimer;
-  int _messagesPerSecond;   // token refill speed
+  int _messageDelay;        // token refill speed in ms
   int _burstSize;           // size of the token bucket
   int _tokenBucket;         // the virtual bucket that holds the tokens
   QList<QByteArray> _msgQueue;