]>
jfr.im git - irc/quakenet/newserv.git/blob - proxyscan/proxyscanqueue.c
3 * Handle the scan queues
7 #include "../irc/irc.h"
8 #include "../core/error.h"
10 pendingscan
*ps_normalqueue
=NULL
;
11 pendingscan
*ps_prioqueue
=NULL
;
12 pendingscan
*ps_normalqueueend
=NULL
;
14 unsigned int normalqueuedscans
=0;
15 unsigned int prioqueuedscans
=0;
17 unsigned long countpendingscan
=0;
19 void queuescan(patricia_node_t
*node
, short scantype
, unsigned short port
, char class, time_t when
) {
20 pendingscan
*psp
, *psp2
;
22 /* check if the IP/port combo is already queued - don't queue up
23 * multiple identical scans
28 if (psp
->node
== node
&& psp
->type
== scantype
&&
29 psp
->port
== port
&& psp
->class == class)
31 /* found it, ignore */
40 if (psp
->node
== node
&& psp
->type
== scantype
&&
41 psp
->port
== port
&& psp
->class == class)
43 /* found it, ignore */
49 /* If there are scans spare, just start it immediately..
50 * provided we're not supposed to wait */
51 if (activescans
< maxscans
&& when
<=time(NULL
) && (ps_start_ts
+120 <= time(NULL
))) {
52 startscan(node
, scantype
, port
, class);
56 /* We have to queue it */
57 if (!(psp
=(struct pendingscan
*)malloc(sizeof(pendingscan
))))
58 Error("proxyscan",ERR_STOP
,"Unable to allocate memory");
72 if (ps_normalqueueend
) {
73 ps_normalqueueend
->next
=psp
;
74 ps_normalqueueend
=psp
;
76 ps_normalqueueend
=ps_normalqueue
=psp
;
80 if (!ps_prioqueue
|| ps_prioqueue
->when
> when
) {
81 psp
->next
=ps_prioqueue
;
84 for (psp2
=ps_prioqueue
; ;psp2
=psp2
->next
) {
85 if (!psp2
->next
|| psp2
->next
->when
> when
) {
86 psp
->next
= psp2
->next
;
95 void startqueuedscans() {
96 pendingscan
*psp
=NULL
;
98 if (ps_start_ts
+120 > time(NULL
))
101 while (activescans
< maxscans
) {
102 if (ps_prioqueue
&& (ps_prioqueue
->when
<= time(NULL
))) {
104 ps_prioqueue
=psp
->next
;
106 } else if (ps_normalqueue
) {
108 ps_normalqueue
=psp
->next
;
110 ps_normalqueueend
=NULL
;
115 startscan(psp
->node
, psp
->type
, psp
->port
, psp
->class);