X-Git-Url: https://jfr.im/git/irc/quakenet/newserv.git/blobdiff_plain/a8ba13739ed9325039d2a923222067a608b5759c..440cd7e63ac2b059ea1a467a2e4e2244faf92cb3:/proxyscan/proxyscancache.c diff --git a/proxyscan/proxyscancache.c b/proxyscan/proxyscancache.c index 6c1d0c69..df2a432e 100644 --- a/proxyscan/proxyscancache.c +++ b/proxyscan/proxyscancache.c @@ -19,18 +19,17 @@ void cachehostinit(time_t ri) { cachehost *addcleanhost(time_t timestamp) { cachehost *chp; - int hash; chp=getcachehost(); chp->lastscan=timestamp; chp->proxies=NULL; chp->glineid=0; + chp->lastgline=0; return chp; } void delcachehost(cachehost *chp) { - cachehost **chh; foundproxy *fpp, *nfpp; for (fpp=chp->proxies;fpp;fpp=nfpp) { @@ -45,7 +44,6 @@ void delcachehost(cachehost *chp) { */ cachehost *findcachehost(patricia_node_t *node) { - int hash; cachehost *chp; if( (cachehost *)node->exts[ps_cache_ext] ) { @@ -72,46 +70,44 @@ cachehost *findcachehost(patricia_node_t *node) { */ void dumpcachehosts(void *arg) { - int i; FILE *fp; cachehost *chp; time_t now=time(NULL); foundproxy *fpp; patricia_node_t *node; - if ((fp=fopen("cleanhosts","w"))==NULL) { + if ((fp=fopen("data/cleanhosts","w"))==NULL) { Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for writing!"); return; } - PATRICIA_WALK (iptree->head, node) { + PATRICIA_WALK_CLEAR (iptree->head, node) { if (node->exts[ps_cache_ext] ) { chp = (cachehost *) node->exts[ps_cache_ext]; if (chp) { if (chp->proxies) { if (chp->lastscan < (now-dirtyscaninterval)) { - //derefnode(iptree,node); - //delcachehost(chp); - //node->exts[ps_cache_ext] = NULL; - //continue; + derefnode(iptree,node); + delcachehost(chp); + node->exts[ps_cache_ext] = NULL; } else for (fpp=chp->proxies;fpp;fpp=fpp->next) - fprintf(fp, "%s %lu %u %i %u\n",IPtostr(node->prefix->sin),chp->lastscan,chp->glineid,fpp->type,fpp->port); + fprintf(fp, "%s %lu %u %i %u %lu\n",IPtostr(node->prefix->sin),chp->lastscan,chp->glineid,fpp->type,fpp->port,chp->lastgline); } else { if (chp->lastscan < (now-cleanscaninterval)) { /* Needs rescan anyway, so delete it */ - //derefnode(iptree,node); - //delcachehost(chp); - //node->exts[ps_cache_ext] = NULL; - //continue; + derefnode(iptree,node); + delcachehost(chp); + node->exts[ps_cache_ext] = NULL; } else fprintf(fp,"%s %lu\n",IPtostr(node->prefix->sin),chp->lastscan); } } } - } PATRICIA_WALK_END; - + } PATRICIA_WALK_CLEAR_END; + +// patricia_tidy_tree(iptree); fclose(fp); } @@ -123,7 +119,7 @@ void dumpcachehosts(void *arg) { void loadcachehosts() { FILE *fp; - unsigned long IP,timestamp,glineid,ptype,pport; + unsigned long timestamp,glineid,ptype,pport,lastgline; char buf[512]; cachehost *chp=NULL; foundproxy *fpp; @@ -132,8 +128,9 @@ void loadcachehosts() { struct irc_in_addr sin; unsigned char bits; patricia_node_t *node; + int i=0; - if ((fp=fopen("cleanhosts","r"))==NULL) { + if ((fp=fopen("data/cleanhosts","r"))==NULL) { Error("proxyscan",ERR_ERROR,"Unable to open cleanhosts file for reading!"); return; } @@ -145,7 +142,7 @@ void loadcachehosts() { break; } - res=sscanf(buf,"%s %lu %lu %lu %lu",&ip,×tamp,&glineid,&ptype,&pport); + res=sscanf(buf,"%s %lu %lu %lu %lu %lu",ip,×tamp,&glineid,&ptype,&pport,&lastgline); if (res<2) continue; @@ -155,11 +152,13 @@ void loadcachehosts() { } else { node = refnode(iptree, &sin, bits); if( node ) { + i++; chp=addcleanhost(timestamp); node->exts[ps_cache_ext] = chp; - if (res==5) { + if (res==6) { chp->glineid=glineid; + chp->lastgline=lastgline; fpp=getfoundproxy(); fpp->type=ptype; fpp->port=pport; @@ -169,7 +168,8 @@ void loadcachehosts() { } } } - + + Error("proxyscan",ERR_INFO, "Loaded %d entries from cache", i); } /* @@ -178,7 +178,6 @@ void loadcachehosts() { */ unsigned int cleancount() { - int i; unsigned int total=0; cachehost *chp; patricia_node_t *head, *node; @@ -196,7 +195,6 @@ unsigned int cleancount() { } unsigned int dirtycount() { - int i; unsigned int total=0; cachehost *chp; patricia_node_t *node; @@ -219,7 +217,7 @@ unsigned int dirtycount() { void scanall(int type, int port) { int i; - cachehost *chp, *nchp; + cachehost *chp; nick *np; unsigned int hostmarker; patricia_node_t *node; @@ -240,9 +238,6 @@ void scanall(int type, int port) { np->host->marker=hostmarker; - if (!irc_in_addr_is_ipv4(&np->p_ipaddr)) - continue; - if ((chp=findcachehost(np->ipnode))) chp->marker=1;