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) {
*/
cachehost *findcachehost(patricia_node_t *node) {
- int hash;
cachehost *chp;
if( (cachehost *)node->exts[ps_cache_ext] ) {
*/
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);
}
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;
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;
}
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;
} 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;
}
}
}
-
+
+ Error("proxyscan",ERR_INFO, "Loaded %d entries from cache", i);
}
/*
*/
unsigned int cleancount() {
- int i;
unsigned int total=0;
cachehost *chp;
patricia_node_t *head, *node;
}
unsigned int dirtycount() {
- int i;
unsigned int total=0;
cachehost *chp;
patricia_node_t *node;
void scanall(int type, int port) {
int i;
- cachehost *chp, *nchp;
+ cachehost *chp;
nick *np;
unsigned int hostmarker;
patricia_node_t *node;
np->host->marker=hostmarker;
- if (!irc_in_addr_is_ipv4(&np->p_ipaddr))
- continue;
-
if ((chp=findcachehost(np->ipnode)))
chp->marker=1;