]> jfr.im git - solanum.git/blobdiff - src/packet.c
Make flood control settings configurable by those who know exactly what they're doing.
[solanum.git] / src / packet.c
index 054f41670e295117363f21850593b13d652b5546..6f14aa927aca82a2ce225edbb52480384f71827b 100644 (file)
 #include "ircd.h"
 #include "parse.h"
 #include "packet.h"
-#include "irc_string.h"
+#include "match.h"
 #include "hook.h"
 #include "send.h"
 
 static char readBuf[READBUF_SIZE];
 static void client_dopacket(struct Client *client_p, char *buffer, size_t length);
 
-
 /*
  * parse_client_queued - parse client queued messages
  */
@@ -124,6 +123,9 @@ parse_client_queued(struct Client *client_p)
                        {
                                if(client_p->localClient->sent_parsed >= client_p->localClient->allow_read)
                                        break;
+                               /* spb: Add second layer of throttling to n lines per second, even during burst */
+                               if(client_p->localClient->actually_read >= ConfigFileEntry.client_flood_burst_rate)
+                                       break;
                        }
 
                        /* allow opers 4 times the amount of messages as users. why 4?
@@ -142,7 +144,9 @@ parse_client_queued(struct Client *client_p)
                        client_dopacket(client_p, readBuf, dolen);
                        if(IsAnyDead(client_p))
                                return;
-                       client_p->localClient->sent_parsed++;
+
+                       client_p->localClient->sent_parsed += ConfigFileEntry.client_flood_message_time;
+                       client_p->localClient->actually_read++;
                }
        }
 }
@@ -165,63 +169,61 @@ flood_endgrace(struct Client *client_p)
        client_p->localClient->sent_parsed = 0;
 }
 
-/*\r
- * flood_recalc\r
- *\r
- * recalculate the number of allowed flood lines. this should be called\r
- * once a second on any given client. We then attempt to flush some data.\r
- */\r
-void\r
-flood_recalc(void *unused)\r
-{\r
-       rb_dlink_node *ptr, *next;\r
-       struct Client *client_p;\r
-\r
-       RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)\r
-       {\r
-               client_p = ptr->data;\r
-\r
-               if(unlikely(IsMe(client_p)))\r
-                       continue;\r
-                       \r
-               if(unlikely(client_p->localClient == NULL))\r
-                       continue;\r
-               \r
-               if(IsFloodDone(client_p))\r
-                       client_p->localClient->sent_parsed -= 2;\r
-               else\r
-                       client_p->localClient->sent_parsed = 0;\r
-                       \r
-               if(client_p->localClient->sent_parsed < 0)\r
-                       client_p->localClient->sent_parsed = 0;\r
-\r
-               if(--client_p->localClient->actually_read < 0)\r
-                       client_p->localClient->actually_read = 0;\r
-\r
-               parse_client_queued(client_p);\r
-               \r
-               if(unlikely(IsAnyDead(client_p)))\r
-                       continue;\r
-\r
-       }\r
-\r
-       RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)\r
-       {\r
-               client_p = ptr->data;\r
-\r
-               if(client_p->localClient == NULL)\r
-                       continue;\r
-\r
-               client_p->localClient->sent_parsed--;\r
-\r
-               if(client_p->localClient->sent_parsed < 0)\r
-                       client_p->localClient->sent_parsed = 0;\r
-\r
-               if(--client_p->localClient->actually_read < 0)\r
-                       client_p->localClient->actually_read = 0;\r
-\r
-               parse_client_queued(client_p);\r
-       }\r
+/*
+ * flood_recalc
+ *
+ * recalculate the number of allowed flood lines. this should be called
+ * once a second on any given client. We then attempt to flush some data.
+ */
+void
+flood_recalc(void *unused)
+{
+       rb_dlink_node *ptr, *next;
+       struct Client *client_p;
+
+       RB_DLINK_FOREACH_SAFE(ptr, next, lclient_list.head)
+       {
+               client_p = ptr->data;
+
+               if(rb_unlikely(IsMe(client_p)))
+                       continue;
+                       
+               if(rb_unlikely(client_p->localClient == NULL))
+                       continue;
+               
+               if(IsFloodDone(client_p))
+                       client_p->localClient->sent_parsed -= ConfigFileEntry.client_flood_message_num;
+               else
+                       client_p->localClient->sent_parsed = 0;
+                       
+               if(client_p->localClient->sent_parsed < 0)
+                       client_p->localClient->sent_parsed = 0;
+
+               client_p->localClient->actually_read = 0;
+
+               parse_client_queued(client_p);
+               
+               if(rb_unlikely(IsAnyDead(client_p)))
+                       continue;
+
+       }
+
+       RB_DLINK_FOREACH_SAFE(ptr, next, unknown_list.head)
+       {
+               client_p = ptr->data;
+
+               if(client_p->localClient == NULL)
+                       continue;
+
+               client_p->localClient->sent_parsed--;
+
+               if(client_p->localClient->sent_parsed < 0)
+                       client_p->localClient->sent_parsed = 0;
+
+               client_p->localClient->actually_read = 0;
+
+               parse_client_queued(client_p);
+       }
 }
 
 /*
@@ -231,7 +233,6 @@ void
 read_packet(rb_fde_t * F, void *data)
 {
        struct Client *client_p = data;
-       struct LocalUser *lclient_p = client_p->localClient;
        int length = 0;
        int lbuf_len;
 
@@ -252,17 +253,16 @@ read_packet(rb_fde_t * F, void *data)
                 */
                length = rb_read(client_p->localClient->F, readBuf, READBUF_SIZE);
 
-               if(length <= 0)
+               if(length < 0)
                {
                        if(rb_ignore_errno(errno))
-                       {
                                rb_setselect(client_p->localClient->F, 
                                                RB_SELECT_READ, read_packet, client_p);
-                       else
+                       else
                                error_exit_client(client_p, length);
                        return;
                }
-               if(length == 0)
+               else if(length == 0)
                {
                        error_exit_client(client_p, length);
                        return;
@@ -289,8 +289,6 @@ read_packet(rb_fde_t * F, void *data)
 
                lbuf_len = rb_linebuf_parse(&client_p->localClient->buf_recvq, readBuf, length, binary);
 
-               lclient_p->actually_read += lbuf_len;
-
                if(IsAnyDead(client_p))
                        return;
                        
@@ -302,7 +300,7 @@ read_packet(rb_fde_t * F, void *data)
                        
                /* Check to make sure we're not flooding */
                if(!IsAnyServer(client_p) &&
-                  (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood))
+                  (rb_linebuf_alloclen(&client_p->localClient->buf_recvq) > ConfigFileEntry.client_flood_max_lines))
                {
                        if(!(ConfigFileEntry.no_oper_flood && IsOper(client_p)))
                        {