]> jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanqueue.c
91febc841bcc697f3153df849ee2ee82c899f977
[irc/quakenet/newserv.git] / proxyscan / proxyscanqueue.c
1
2 /*
3 * Handle the scan queues
4 */
5
6 #include "proxyscan.h"
7 #include "../irc/irc.h"
8 #include "../core/error.h"
9
10 pendingscan *ps_normalqueue=NULL;
11 pendingscan *ps_prioqueue=NULL;
12 pendingscan *ps_normalqueueend=NULL;
13
14 unsigned int normalqueuedscans=0;
15 unsigned int prioqueuedscans=0;
16
17 unsigned long countpendingscan=0;
18
19 void queuescan(patricia_node_t *node, short scantype, unsigned short port, char class, time_t when) {
20 pendingscan *psp, *psp2;
21
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)
27 */
28
29 /* If there are scans spare, just start it immediately..
30 * provided we're not supposed to wait */
31 if (activescans < maxscans && when<=time(NULL) && ps_ready) {
32 startscan(node, scantype, port, class);
33 return;
34 }
35
36 /* We have to queue it */
37 if (!(psp=getpendingscan()))
38 Error("proxyscan",ERR_STOP,"Unable to allocate memory");
39
40 countpendingscan++;
41
42 psp->node=node;
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
75 void startqueuedscans() {
76 pendingscan *psp=NULL;
77
78 while (activescans < maxscans) {
79 if (ps_prioqueue && (ps_prioqueue->when <= time(NULL))) {
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) {
92 startscan(psp->node, psp->type, psp->port, psp->class);
93 freependingscan(psp);
94 countpendingscan--;
95 psp=NULL;
96 } else {
97 break;
98 }
99 }
100 }
101
102