[cvslog] [CVS] Module eggdrop1.6: Change committed

cvs at eggheads.org cvs at eggheads.org
Sun Mar 14 12:30:27 CST 2010


CVSROOT    : /usr/local/cvsroot
Module     : eggdrop1.6
Commit time: 2010-03-14 18:30:27 UTC
Committer  : Rumen Stoyanov <pseudo at egg6.net>

Modified files:
     doc/Changes1.6 src/patch.h src/mod/uptime.mod/uptime.c

Log message:

Added Brian Greenberg's patch to randomize the uptime update interval.

---------------------- diff included ----------------------
Index: eggdrop1.6/doc/Changes1.6
diff -u eggdrop1.6/doc/Changes1.6:1.73 eggdrop1.6/doc/Changes1.6:1.74
--- eggdrop1.6/doc/Changes1.6:1.73	Sun Mar 14 12:21:59 2010
+++ eggdrop1.6/doc/Changes1.6	Sun Mar 14 12:30:17 2010
@@ -1,4 +1,4 @@
-$Id: Changes1.6,v 1.73 2010/03/14 18:21:59 pseudo Exp $
+$Id: Changes1.6,v 1.74 2010/03/14 18:30:17 pseudo Exp $
 
 Eggdrop Changes (since version 1.6.0)
 
@@ -6,6 +6,11 @@
 
 1.6.20 (CVS):
 
+  - Modified the uptime module to send packets at a random interval, with
+    per-second resolution, to reduce the peak traffic and load on the uptime
+    server.
+    Patch by: grnbrg
+
   - Added a configure option to set the handlen while keeping compatibility with
     the older method of editing eggdrop.h directly.
   - Added a configure option to enable dns debugging and made it default for
Index: eggdrop1.6/src/mod/uptime.mod/uptime.c
diff -u eggdrop1.6/src/mod/uptime.mod/uptime.c:1.38 eggdrop1.6/src/mod/uptime.mod/uptime.c:1.39
--- eggdrop1.6/src/mod/uptime.mod/uptime.c:1.38	Sun Jan  3 07:27:55 2010
+++ eggdrop1.6/src/mod/uptime.mod/uptime.c	Sun Mar 14 12:30:17 2010
@@ -1,5 +1,5 @@
 /*
- * $Id: uptime.c,v 1.38 2010/01/03 13:27:55 pseudo Exp $
+ * $Id: uptime.c,v 1.39 2010/03/14 18:30:17 pseudo Exp $
  *
  * This module reports uptime information about your bot to http://uptime.eggheads.org. The
  * purpose for this is to see how your bot rates against many others (including EnergyMechs
@@ -48,15 +48,23 @@
 #include <unistd.h>
 
 /*
- * both regnr and cookie are unused; however, they both must be here inorder for
+ * regnr is unused; however, it must be here inorder for
  * us to create a proper struct for the uptime server.
+ *
+ * "packets_sent" was originally defined as "cookie",
+ * however this field was deprecated and set to zero
+ * for most versions of the uptime client.  It has been
+ * repurposed and renamed as of uptime v1.3 to reflect 
+ * the number of packets the client thinks it has sent
+ * over the life of the module.  Only the name has changed -
+ * the type (unsigned long) is still the same.
  */
 
 typedef struct PackUp {
   int regnr;
   int pid;
   int type;
-  unsigned long cookie;
+  unsigned long packets_sent;
   unsigned long uptime;
   unsigned long ontime;
   unsigned long now2;
@@ -68,12 +76,20 @@
 
 static Function *global = NULL;
 
-static int hours = 0;
+static int minutes = 0;
+static int seconds = 0;
+static int next_seconds = 0;
+static int next_minutes = 0;
+static int update_interval = 720; /* rand(0..12) hours: ~6 hour average. */
+static time_t next_update = 0;
 static int uptimesock;
 static int uptimecount;
 static unsigned long uptimeip;
 static char uptime_version[48] = "";
 
+void check_secondly(void);
+void check_minutely(void);
+
 static int uptime_expmem()
 {
   return 0;
@@ -81,13 +97,18 @@
 
 static void uptime_report(int idx, int details)
 {
+  int delta_seconds;
+  char *next_update_at;
+  
   if (details) {
-    int size = uptime_expmem();
+    delta_seconds = (int) (next_update - time(NULL));
+    next_update_at = ctime(&next_update);
+    next_update_at[strlen(next_update_at) - 1] = 0;
 
-    dprintf(idx, "    %d uptime packet%s sent\n", uptimecount,
+    dprintf(idx, "      %d uptime packet%s sent\n", uptimecount,
             (uptimecount != 1) ? "s" : "");
-    dprintf(idx, "    Using %d byte%s of memory\n", size,
-            (size != 1) ? "s" : "");
+    dprintf(idx, "      Approximately %-.2f hours until next update "
+            "(at %s)\n", delta_seconds / 3600.0, next_update_at);
   }
 }
 
@@ -119,7 +140,7 @@
   upPack.regnr = 0;  /* unused */
   upPack.pid = 0;    /* must set this later */
   upPack.type = htonl(uptime_type);
-  upPack.cookie = 0; /* unused */
+  upPack.packets_sent = 0; /* reused (abused?) to send our packet count */
   upPack.uptime = 0; /* must set this later */
   uptimecount = 0;
   uptimeip = -1;
@@ -140,6 +161,12 @@
     return ((uptimesock = -1));
   }
   fcntl(uptimesock, F_SETFL, O_NONBLOCK | fcntl(uptimesock, F_GETFL));
+
+  next_minutes = rand() % update_interval; /* Initial update delay */
+  next_seconds = rand() % 59;
+  next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) +
+    next_seconds);
+
   return 0;
 }
 
@@ -160,6 +187,8 @@
   }
 
   uptimecount++;
+  upPack.packets_sent = htonl(uptimecount); /* Tell the server how many 
+					       uptime packets we've sent. */
   upPack.now2 = htonl(time(NULL));
   upPack.ontime = 0;
 
@@ -187,9 +216,13 @@
   len = sizeof(upPack) + strlen(botnetnick) + strlen(servhost) +
         strlen(uptime_version);
   mem = (PackUp *) nmalloc(len);
+  egg_bzero(mem, len); /* mem *should* be completely filled before it's
+                             * sent to the server.  But belt-and-suspenders
+                             * is always good.
+                             */
   my_memcpy(mem, &upPack, sizeof(upPack));
   sprintf(mem->string, "%s %s %s", botnetnick, servhost, uptime_version);
-  egg_memset(&sai, 0, sizeof(sai));
+  egg_bzero(&sai, sizeof(sai));
   sai.sin_family = AF_INET;
   sai.sin_addr.s_addr = uptimeip;
   sai.sin_port = htons(uptime_port);
@@ -199,18 +232,40 @@
   return len;
 }
 
-void check_hourly()
+void check_minutely()
 {
-  hours++;
-  if (hours == 6) {
+  minutes++;
+  if (minutes >= next_minutes) { 
+    /* We're down to zero minutes.  Now do the seconds. */
+    del_hook(HOOK_MINUTELY, (Function) check_minutely);
+    add_hook(HOOK_SECONDLY, (Function) check_secondly);
+  }
+}
+
+void check_secondly()
+{
+  seconds++;
+  if (seconds >= next_seconds) {  /* DING! */
+    del_hook(HOOK_SECONDLY, (Function) check_secondly);
+    
     send_uptime();
-    hours = 0;
+
+    minutes = 0; /* Reset for the next countdown. */
+    seconds = 0;
+    next_minutes = rand() % update_interval;
+    next_seconds = rand() % 59;
+    next_update = (time_t) ((time(NULL) / 60 * 60) + (next_minutes * 60) +
+      next_seconds);
+
+    /* Go back to checking every minute. */
+    add_hook(HOOK_MINUTELY, (Function) check_minutely);
   }
 }
 
 static char *uptime_close()
 {
-  return "You cannot unload the uptime module (doing so will reset your stats).";
+  return "You cannot unload the uptime module "
+         "(doing so will reset your stats).";
 }
 
 EXPORT_SCOPE char *uptime_start(Function *);
@@ -227,14 +282,14 @@
   if (global_funcs) {
     global = global_funcs;
 
-    module_register(MODULE_NAME, uptime_table, 1, 2);
+    module_register(MODULE_NAME, uptime_table, 1, 3);
     if (!module_depend(MODULE_NAME, "eggdrop", 106, 11)) {
       module_undepend(MODULE_NAME);
       return "This module requires Eggdrop 1.6.11 or later.";
     }
 
     add_help_reference("uptime.help");
-    add_hook(HOOK_HOURLY, (Function) check_hourly);
+    add_hook(HOOK_MINUTELY, (Function) check_minutely);
     init_uptime();
   }
   return NULL;
Index: eggdrop1.6/src/patch.h
diff -u eggdrop1.6/src/patch.h:1.1241 eggdrop1.6/src/patch.h:1.1242
--- eggdrop1.6/src/patch.h:1.1241	Sun Mar 14 12:21:59 2010
+++ eggdrop1.6/src/patch.h	Sun Mar 14 12:30:17 2010
@@ -10,7 +10,7 @@
  * statement, leave the rest of the file alone, this allows better
  * overlapping patches.
  *
- * $Id: patch.h,v 1.1241 2010/03/14 18:21:59 pseudo Exp $
+ * $Id: patch.h,v 1.1242 2010/03/14 18:30:17 pseudo Exp $
  */
 /*
  * Copyright (C) 1997 Robey Pointer
@@ -41,12 +41,12 @@
  *
  *
  */
-patch("1268590469");            /* current unixtime */
+patch("1268591186");            /* current unixtime */
 /*
  *
  *
  */
-patch("acdnshandlen");
+patch("uptime_randomize");
 /*
  *
  *
----------------------- End of diff -----------------------


More information about the Changes mailing list