]> jfr.im git - irc/quakenet/newserv.git/blame - proxyscan/proxyscanqueue.c
HELPMOD2: Ignore friends in lamer control
[irc/quakenet/newserv.git] / proxyscan / proxyscanqueue.c
CommitLineData
905c2ba2 1
2/*
3 * Handle the scan queues
4 */
5
6#include "proxyscan.h"
92f1d9e3 7#include "../irc/irc.h"
b8dc4a0e 8#include "../core/error.h"
905c2ba2 9
10pendingscan *ps_normalqueue=NULL;
11pendingscan *ps_prioqueue=NULL;
12pendingscan *ps_normalqueueend=NULL;
13
14unsigned int normalqueuedscans=0;
15unsigned int prioqueuedscans=0;
16
92f1d9e3
D
17unsigned long countpendingscan=0;
18
557c8cb2 19void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) {
905c2ba2 20 pendingscan *psp, *psp2;
761a4596 21
7ab80d0c
P
22 /* we can just blindly queue the scans as node extension cleanhost cache blocks duplicate scans normally.
23 * Scans may come from:
24 * a) scan <node> (from an oper)
25 * b) newnick handler - which ignores clean hosts, only scans new hosts or dirty hosts
26 * c) adding a new scan type (rare)
761a4596 27 */
905c2ba2 28
29 /* If there are scans spare, just start it immediately..
30 * provided we're not supposed to wait */
7ab80d0c 31 if (activescans < maxscans && when<=time(NULL) && ps_ready) {
557c8cb2 32 startscan(node, scantype, port, class);
905c2ba2 33 return;
34 }
35
36 /* We have to queue it */
7ab80d0c 37 if (!(psp=getpendingscan()))
b8dc4a0e 38 Error("proxyscan",ERR_STOP,"Unable to allocate memory");
39
40 countpendingscan++;
41
557c8cb2 42 psp->node=node;
905c2ba2 43 psp->type=scantype;
44 psp->port=port;
45 psp->class=class;
46 psp->when=when;
47 psp->next=NULL;
48
49 if (!when) {
50 /* normal queue */
51 normalqueuedscans++;
52 if (ps_normalqueueend) {
53 ps_normalqueueend->next=psp;
54 ps_normalqueueend=psp;
55 } else {
56 ps_normalqueueend=ps_normalqueue=psp;
57 }
58 } else {
59 prioqueuedscans++;
60 if (!ps_prioqueue || ps_prioqueue->when > when) {
61 psp->next=ps_prioqueue;
62 ps_prioqueue=psp;
63 } else {
64 for (psp2=ps_prioqueue; ;psp2=psp2->next) {
65 if (!psp2->next || psp2->next->when > when) {
66 psp->next = psp2->next;
67 psp2->next = psp;
68 break;
69 }
70 }
71 }
72 }
73}
74
75void startqueuedscans() {
76 pendingscan *psp=NULL;
77
78 while (activescans < maxscans) {
761a4596 79 if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) {
905c2ba2 80 psp=ps_prioqueue;
81 ps_prioqueue=psp->next;
82 prioqueuedscans--;
83 } else if (ps_normalqueue) {
84 psp=ps_normalqueue;
85 ps_normalqueue=psp->next;
86 if (!ps_normalqueue)
87 ps_normalqueueend=NULL;
88 normalqueuedscans--;
89 }
90
91 if (psp) {
557c8cb2 92 startscan(psp->node, psp->type, psp->port, psp->class);
7ab80d0c 93 freependingscan(psp);
92f1d9e3 94 countpendingscan--;
905c2ba2 95 psp=NULL;
96 } else {
97 break;
98 }
99 }
100}
101
102