X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/0f402ca493cf3e63e2b8f195e7b8c4c9887a8643..8855bb48b449ed06cfd3ce528b3c0a77c37cb24b:/proxyscan/proxyscanqueue.c diff --git a/proxyscan/proxyscanqueue.c b/proxyscan/proxyscanqueue.c index 2ea410af..fae99c5e 100644 --- a/proxyscan/proxyscanqueue.c +++ b/proxyscan/proxyscanqueue.c @@ -5,6 +5,8 @@ #include "proxyscan.h" #include "../irc/irc.h" +#include "../core/error.h" +#include pendingscan *ps_normalqueue=NULL; pendingscan *ps_prioqueue=NULL; @@ -15,55 +17,35 @@ unsigned int prioqueuedscans=0; unsigned long countpendingscan=0; -void queuescan(unsigned int IP, short scantype, unsigned short port, char class, time_t when) { +void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) { pendingscan *psp, *psp2; - /* check if the IP/port combo is already queued - don't queue up - * multiple identical scans + /* we can just blindly queue the scans as node extension cleanhost cache blocks duplicate scans normally. + * Scans may come from: + * a) scan (from an oper) + * b) newnick handler - which ignores clean hosts, only scans new hosts or dirty hosts + * c) adding a new scan type (rare) */ - psp = ps_prioqueue; - while (psp != NULL) - { - if (psp->IP == IP && psp->type == scantype && - psp->port == port && psp->class == class) - { - /* found it, ignore */ - return; - } - psp = psp->next; - } - psp = ps_normalqueue; - while (psp != NULL) - { - if (psp->IP == IP && psp->type == scantype && - psp->port == port && psp->class == class) - { - /* found it, ignore */ - return; - } - psp = psp->next; - } + /* we should never have an internal node */ + assert(node->prefix); + /* reference the node - we either start a or queue a single scan */ + patricia_ref_prefix(node->prefix); /* If there are scans spare, just start it immediately.. * provided we're not supposed to wait */ - if (activescans < maxscans && when<=time(NULL) && (ps_start_ts+120 <= time(NULL))) { - startscan(IP, scantype, port, class); + if (activescans < maxscans && when<=time(NULL) && ps_ready) { + startscan(node, scantype, port, class); return; } /* We have to queue it */ - 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; + if (!(psp=getpendingscan())) + Error("proxyscan",ERR_STOP,"Unable to allocate memory"); + + countpendingscan++; + + psp->node=node; psp->type=scantype; psp->port=port; psp->class=class; @@ -99,9 +81,6 @@ void queuescan(unsigned int IP, short scantype, unsigned short port, char class, void startqueuedscans() { pendingscan *psp=NULL; - if (ps_start_ts+120 > time(NULL)) - return; - while (activescans < maxscans) { if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) { psp=ps_prioqueue; @@ -116,8 +95,8 @@ void startqueuedscans() { } if (psp) { - startscan(psp->IP, psp->type, psp->port, psp->class); - free(psp); + startscan(psp->node, psp->type, psp->port, psp->class); + freependingscan(psp); countpendingscan--; psp=NULL; } else {