diff options
-rw-r--r-- | config.def.h | 7 | ||||
-rw-r--r-- | pacredir.c | 21 | ||||
-rw-r--r-- | pacredir.h | 6 |
3 files changed, 22 insertions, 12 deletions
diff --git a/config.def.h b/config.def.h index c81672e..e698261 100644 --- a/config.def.h +++ b/config.def.h @@ -49,9 +49,10 @@ /* this is where pacman stores its local copy of db files */ #define SYNCPATH "/var/lib/pacman/sync" -/* This defines when a host is queried again after a bad request - * default is 600 seconds (10 minutes) */ -#define BADTIME 60 * 10 +/* This defines the initial time in seconds after which a host is queried + * again after a bad request. Time is doubled after every subsequent + * request. */ +#define BADTIME 30 #endif /* _CONFIG_H */ @@ -93,8 +93,10 @@ int add_host(const char * host, const char * type) { tmphosts->host = strdup(host); tmphosts->pacserve.online = 0; tmphosts->pacserve.bad = 0; + tmphosts->pacserve.badcount = 0; tmphosts->pacdbserve.online = 0; tmphosts->pacdbserve.bad = 0; + tmphosts->pacdbserve.badcount = 0; tmphosts->next = malloc(sizeof(struct hosts)); tmphosts->next->host = NULL; tmphosts->next->next = NULL; @@ -103,11 +105,11 @@ update: if (strcmp(type, PACSERVE) == 0) { tmphosts->pacserve.online = 1; request.port = PORT_PACSERVE; - request.bad = &tmphosts->pacserve.bad; + request.service = &tmphosts->pacserve; } else if (strcmp(type, PACDBSERVE) == 0) { tmphosts->pacdbserve.online = 1; request.port = PORT_PACDBSERVE; - request.bad = &tmphosts->pacdbserve.bad; + request.service = &tmphosts->pacdbserve; } /* do a first request and let get_http_code() set the bad status */ @@ -245,10 +247,15 @@ static void * get_http_code(void * data) { write_log(stderr, "Could not connect to server %s on port %d.\n", request->host, request->port); request->http_code = 0; request->last_modified = 0; - *request->bad = tv.tv_sec; + request->service->bad = tv.tv_sec; + request->service->badcount++; return NULL; + } else { + request->service->bad = 0; + request->service->badcount = 0; } + /* get http status code */ if ((res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &(request->http_code))) != CURLE_OK) { write_log(stderr, "curl_easy_getinfo() failed: %s\n", curl_easy_strerror(res)); @@ -337,8 +344,8 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char * gettimeofday(&tv, NULL); /* skip host if offline or had a bad request within last BADTIME seconds */ - if ((dbfile == 1 && (tmphosts->pacdbserve.online == 0 || tmphosts->pacdbserve.bad + BADTIME > tv.tv_sec)) || - (dbfile == 0 && (tmphosts->pacserve.online == 0 || tmphosts->pacserve.bad + BADTIME > tv.tv_sec))) { + if ((dbfile == 1 && (tmphosts->pacdbserve.online == 0 || tmphosts->pacdbserve.bad + tmphosts->pacdbserve.badcount * BADTIME > tv.tv_sec)) || + (dbfile == 0 && (tmphosts->pacserve.online == 0 || tmphosts->pacserve.bad + tmphosts->pacserve.bad * BADTIME > tv.tv_sec))) { tmphosts = tmphosts->next; continue; } @@ -357,10 +364,10 @@ static int ahc_echo(void * cls, struct MHD_Connection * connection, const char * request->host = tmphosts->host; if (dbfile == 1) { request->port = PORT_PACDBSERVE; - request->bad = &(tmphosts->pacdbserve.bad); + request->service = &(tmphosts->pacdbserve); } else { request->port = PORT_PACSERVE; - request->bad = &(tmphosts->pacserve.bad); + request->service = &(tmphosts->pacserve); } request->url = get_url(tmphosts->host, dbfile == 1 ? PORT_PACDBSERVE : PORT_PACSERVE, basename); request->http_code = 0; @@ -14,6 +14,8 @@ struct services { uint8_t online; /* unix timestamp of last bad request */ __time_t bad; + /* count the number of bad requests */ + unsigned int badcount; }; /* hosts */ @@ -41,8 +43,8 @@ struct request { const char * host; /* port */ uint16_t port; - /* pointer to bad */ - __time_t * bad; + /* pointer to service */ + struct services * service; /* url */ char * url; /* HTTP status code */ |