소스 검색

* Only use flood_count system on ratbox type servers

Bryan Drewery 16 년 전
부모
커밋
ee966e8acb
5개의 변경된 파일59개의 추가작업 그리고 45개의 파일을 삭제
  1. 1 0
      doc/UPDATES
  2. 50 19
      src/mod/server.mod/server.c
  3. 1 0
      src/mod/server.mod/server.h
  4. 6 25
      src/mod/server.mod/servmsg.c
  5. 1 1
      src/set.c

+ 1 - 0
doc/UPDATES

@@ -2,6 +2,7 @@
 * Add set 'msgrate' to define how often to dequeue to the server. (1 or 2 is good)
 * Add set 'msgburst' to define how many commands to burst to server per msgrate.
 * On hybrid/ratbox servers, burst some commands on connect
+* On ratbox type servers, use an optimized queue for better throughput on the queue.
 * Add cmd_play for playing files to irc. (ASCII art gallery exhibition)
 * Utilize CPRIVMSG/CNOTICE if available.
 

+ 50 - 19
src/mod/server.mod/server.c

@@ -95,6 +95,7 @@ static time_t connect_bursting = 0;
 static int real_msgburst = 0;
 static int real_msgrate = 0;
 static int flood_count = 0;
+static bool use_flood_count = 0;
 static egg_timeval_t flood_time = {0, 0};
 static bool use_penalties;
 static int use_fastdeq;
@@ -124,6 +125,9 @@ bind_table_t *BT_ctcr = NULL, *BT_ctcp = NULL, *BT_msgc = NULL;
 
 #define MAXPENALTY 10
 
+// If use_flood_count, don't bother with msgrate, otherwise use the user specified msgrate
+#define MSGRATE (use_flood_count ? DEQ_RATE : msgrate)
+
 /* Maximum messages to store in each queue. */
 static struct msgq_head mq, hq, modeq, aq, cacheq;
 
@@ -167,6 +171,29 @@ static bool burst_mode_ok(const char *msg, size_t len) {
   return 0;
 }
 
+// Hybrid/ratbox allows bursting 5*8 lines on connect until certain commands are sent, for up to 30 seconds
+/*
+   BAD:
+     JOIN 0
+     MODE #chan b
+     NICK
+     PART
+     KICK
+     CPRIVMSG
+     CNOTICE
+     WHO 0/mask
+     TIME
+     TOPIC
+     INVITE
+     AWAY
+     OPER
+
+   OK:
+     WHO *
+     WHO !
+     WHO #Chan
+     WHO NICK
+*/
 static bool burst_ok(const char* msg, size_t len) {
   if (strstr(msg, "JOIN 0") ||
       (strstr(msg, "MODE") && !burst_mode_ok(msg, len)) ||
@@ -205,8 +232,6 @@ void deq_msg()
   if (serv < 0)
     return;
 
-  msgrate = 100;
-
   if (timeval_diff(&egg_timeval_now, &flood_time) >= 1000) {
     // Increase flood_count by 1 every msg, but decrease by 2 every second, use this to determine an acceptable burst rate
     if (flood_count > 1)
@@ -219,23 +244,26 @@ void deq_msg()
   }
 
   /* now < last_time tested 'cause clock adjustments could mess it up */
-  if (timeval_diff(&egg_timeval_now, &last_time) >= msgrate || now < (last_time.sec - 90)) {
+  if (timeval_diff(&egg_timeval_now, &last_time) >= MSGRATE || now < (last_time.sec - 90)) {
     last_time.sec = egg_timeval_now.sec;
     last_time.usec = egg_timeval_now.usec;
 
     if (burst > 0) {
-      if (flood_count < 5)
-        burst = 0;
-      else if (flood_count < 10)
-        burst -= 4;
-      else if (flood_count < 13)
-        burst -= 3;
-      else if (flood_count < 15)
-        burst -= 2;
-      else
+      if (use_flood_count) {
+        if (flood_count < 5)
+          burst = 0;
+        else if (flood_count < 10)
+          burst -= 4;
+        else if (flood_count < 13)
+          burst -= 3;
+        else if (flood_count < 15)
+          burst -= 2;
+        else
+          --burst;
+        if (burst < 0)
+          burst = 0;
+      } else
         --burst;
-      if (burst < 0)
-        burst = 0;
     }
   } else
     return;
@@ -282,10 +310,10 @@ void deq_msg()
   }
 
   // Do this penalty calc here as it's dependant on burst/flood_count
-  if (!connect_bursting) {
+  if (use_flood_count && !connect_bursting) {
     // The penalty includes a length-based penalty from calc_penalty
 
-    last_time.sec -= (msgrate / 1000); // Remove normal msgrate
+    last_time.sec -= (MSGRATE / 1000); // Remove normal msgrate
     // Add 150ms for each current burst
     last_time.usec += (150*burst) * 1000;
     // Add some penalty for each flood_count
@@ -322,11 +350,14 @@ static void calc_penalty(char * msg, size_t len)
     i = strlen(cmd);
   if (!use_penalties) {
     // Add some penalty for large messages
-    last_time.usec += ((double)i / 300.0) * (1000*1000);
+    if (use_flood_count)
+      last_time.usec += ((double)i / 300.0) * (1000*1000);
+    else
+      last_time.usec += ((double)i / 120.0) * (1000*1000);
     return;
   }
 
-  last_time.sec -= (msgrate / 1000); // Remove normal msgrate
+  last_time.sec -= (MSGRATE / 1000); // Remove normal msgrate
 
   penalty = (1 + i / 100);
   if (!strcasecmp(cmd, "KICK")) {
@@ -1091,7 +1122,7 @@ void server_init()
   egg_timeval_t howlong;
 
   howlong.sec = 0;
-  howlong.usec = 200 * 1000;
+  howlong.usec = DEQ_RATE * 1000;
 
   timer_create_repeater(&howlong, "server_queue", (Function) deq_msg);
   timer_create_secs(1, "server_secondly", (Function) server_secondly);

+ 1 - 0
src/mod/server.mod/server.h

@@ -12,6 +12,7 @@
 
 #define DO_LOST 1
 #define NO_LOST 0
+#define DEQ_RATE 200
 
 #define fixcolon(x)             do {                                    \
         if ((x)[0] == ':')                                              \

+ 6 - 25
src/mod/server.mod/servmsg.c

@@ -255,34 +255,13 @@ got004(char *from, char *msg)
   if (strstr(tmp, "u2.") || strstr(tmp, "Unreeal") || strstr(tmp, "snircd")) {
     putlog(LOG_DEBUG, "*", "Disabling cookies as they are not supported on %s", cursrvname);
     cookies_disabled = true;
-  } else if (strstr(tmp, "hybrid") || strstr(tmp, "ratbox") || strstr(tmp, "Charybdis") || strstr(tmp, "ircd-seven"))
+  } else if (strstr(tmp, "hybrid") || strstr(tmp, "ratbox") || strstr(tmp, "Charybdis") || strstr(tmp, "ircd-seven")) {
     connect_burst = 1;
+    if (!strstr(tmp, "hybrid"))
+      use_flood_count = 1;
+  }
 
   if (!replaying_cache && connect_burst) {
-    // Hybrid/ratbox allows bursting 5*8 lines on connect until certain commands are sent, for up to 30 seconds
-    /*
-       BAD:
-         JOIN 0
-         MODE #chan b
-         NICK
-         PART
-         KICK
-         CPRIVMSG
-         CNOTICE
-         WHO 0/mask
-         TIME
-         TOPIC
-         INVITE
-         AWAY
-         OPER
-
-       OK:
-         WHO *
-         WHO !
-         WHO #Chan
-         WHO NICK
-    */
-
     connect_bursting = now;
     msgburst = SERVER_CONNECT_BURST_RATE;
     msgrate = 200;
@@ -1171,6 +1150,7 @@ static void disconnect_server(int idx, int dolost)
   botuserip[0] = 0; 
   have_cprivmsg = 0;
   have_cnotice = 0;
+  use_flood_count = 0;
   if (dolost) {
     Auth::DeleteAll();
     trying_server = 0;
@@ -1823,6 +1803,7 @@ static void server_dns_callback(int id, void *client_data, const char *host, bd:
     last_time.sec = now - 100;
     last_time.usec = 0;
     end_burstmode();
+    use_flood_count = 0;
     real_msgburst = msgburst;
     real_msgrate = msgrate;
 

+ 1 - 1
src/set.c

@@ -106,7 +106,7 @@ static variable_t vars[] = {
  VAR("msg-op",		msgop,			VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msg-pass",	msgpass,		VAR_WORD|VAR_NOLHUB,				0, 0, NULL),
  VAR("msgburst",	&msgburst,		VAR_INT|VAR_NOLHUB,				1, 90, "5"),
- VAR("msgrate",		&msgrate,		VAR_INT|VAR_NOLHUB,				0, 10000, "2200"),
+ VAR("msgrate",		&msgrate,		VAR_INT|VAR_NOLHUB,				DEQ_RATE, 10000, "2200"),
  VAR("nick",		origbotname,		VAR_WORD|VAR_NOHUB|VAR_NICK|VAR_NODEF,	0, 0, NULL),
  VAR("notify-time",	&ison_time,		VAR_INT|VAR_NOLHUB,				1, 30, "10"),
  VAR("oidentd",		&oidentd,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "0"),