]> jfr.im git - irc/quakenet/newserv.git/commitdiff
changed memory allocation functions for queues as there's no need for us to
authorDan <redacted>
Tue, 6 Sep 2005 22:43:00 +0000 (23:43 +0100)
committerDan <redacted>
Tue, 6 Sep 2005 22:43:00 +0000 (23:43 +0100)
eat up loads of ram during burst and never give it back (~75mb ram wasted) -
use boring old plain linked list.

added functions to show checking speed (average of previous 60 second block)

Report memory usage from the above in 'status' command

proxyscan/proxyscan.c
proxyscan/proxyscan.h
proxyscan/proxyscanqueue.c

index f106d6b2f866d822ab8a68f352b6cd0c966a1e5a..eab2cabd51aa74f11f526124f5a7fc61d8c6c29e 100644 (file)
@@ -57,6 +57,10 @@ unsigned int ps_mailip;
 unsigned int ps_mailport;
 sstring *ps_mailname;
 
+unsigned long scanspermin;
+unsigned long tempscanspermin=0;
+unsigned long lastscants=0;
+
 nick *proxyscannick;
 
 FILE *ps_logfile;
@@ -122,6 +126,9 @@ void _init(void) {
   starttime=time(NULL);
   glinedhosts=0;
 
+  scanspermin=0;
+  lastscants=time(NULL);
+
   /* Listen port */
   cfgstr=getcopyconfigitem("proxyscan","port","9999",6);
   listenport=strtol(cfgstr->content,NULL,10);
@@ -215,6 +222,7 @@ void _init(void) {
   proxyscan_addscantype(STYPE_HTTP, 63809);
   proxyscan_addscantype(STYPE_HTTP, 63000);
   proxyscan_addscantype(STYPE_SOCKS4, 559);
+  proxyscan_addscantype(STYPE_SOCKS4, 29992);
   
   /* Schedule saves */
   schedulerecurring(time(NULL)+3600,0,3600,&dumpcachehosts,NULL);
@@ -420,6 +428,24 @@ scan *findscan(int fd) {
 
 void startscan(unsigned int IP, int type, int port, int class) {
   scan *sp;
+
+  float scantmp;
+
+  if (scansdone>maxscans)
+  {
+    /* ignore the first maxscans as this will skew our scans per second! */
+    tempscanspermin++;
+    if ((lastscants+60) <= time(NULL))
+    {
+      /* ok, at least 60 seconds has passed, calculate the scans per minute figure */
+      scantmp = time(NULL) - lastscants;
+      scantmp = tempscanspermin / scantmp;
+      scantmp = (scantmp * 60);
+      scanspermin = scantmp;
+      lastscants = time(NULL);
+      tempscanspermin = 0;
+    }
+  }
   
   sp=getscan();
   
@@ -767,7 +793,11 @@ void proxyscandostatus(nick *np) {
   sendnoticetouser(proxyscannick,np,"Total scans completed:  %d",scansdone);
   sendnoticetouser(proxyscannick,np,"Total hosts glined:     %d",glinedhosts);
 
+  sendnoticetouser(proxyscannick,np,"pendingscan structures: %lu x %lu bytes = %lu bytes total",countpendingscan,
+       sizeof(pendingscan), (countpendingscan * sizeof(pendingscan)));
+
   sendnoticetouser(proxyscannick,np,"Currently active scans: %d/%d",activescans,maxscans);
+  sendnoticetouser(proxyscannick,np,"Processing speed:       %lu scans per minute",scanspermin);
   sendnoticetouser(proxyscannick,np,"Normal queued scans:    %d",normalqueuedscans);
   sendnoticetouser(proxyscannick,np,"Timed queued scans:     %d",prioqueuedscans);
   sendnoticetouser(proxyscannick,np,"'Clean' cached hosts:   %d",cleancount());
index ddaa8b30d59b25f532c8899a2a253ac4b029d535..09e2e6f5f162c1750134868aa1899df30d710b54 100644 (file)
@@ -97,6 +97,10 @@ extern int brokendb;
 extern unsigned int normalqueuedscans;
 extern unsigned int prioqueuedscans;
 
+extern unsigned long countpendingscan;
+
+extern unsigned long scanspermin;
+
 /* proxyscancache.c */
 cachehost *addcleanhost(unsigned long IP, time_t timestamp);
 cachehost *findcachehost(unsigned long IP);
index f4ba2423b5a31841259ff601f816da31f99dc5f7..427bf9b94bd5fc2df381f14a25973dca35e4aebb 100644 (file)
@@ -4,6 +4,7 @@
  */
 
 #include "proxyscan.h"
+#include "../irc/irc.h"
 
 pendingscan *ps_normalqueue=NULL;
 pendingscan *ps_prioqueue=NULL;
@@ -12,6 +13,8 @@ pendingscan *ps_normalqueueend=NULL;
 unsigned int normalqueuedscans=0;
 unsigned int prioqueuedscans=0;
 
+unsigned long countpendingscan=0;
+
 void queuescan(unsigned int IP, short scantype, unsigned short port, char class, time_t when) {
   pendingscan *psp, *psp2;
   
@@ -23,7 +26,16 @@ void queuescan(unsigned int IP, short scantype, unsigned short port, char class,
   }
 
   /* We have to queue it */
-  psp=getpendingscan();
+  psp = (struct pendingscan *) malloc(sizeof(pendingscan));
+  if (!psp)
+  {
+    /* shutdown due to no memory */
+    irc_send("%s SQ %s 0 :Out of memory - exiting.",mynumeric->content,myserver->content);
+    irc_disconnected();
+    exit(0);
+  } else {
+    countpendingscan++;
+  }
   psp->IP=IP;
   psp->type=scantype;
   psp->port=port;
@@ -75,7 +87,8 @@ void startqueuedscans() {
     
     if (psp) {
       startscan(psp->IP, psp->type, psp->port, psp->class);
-      freependingscan(psp);
+      free(psp);
+      countpendingscan--;
       psp=NULL;
     } else {
       break;