Author: durner Date: 2006-07-08 13:45:45 -0700 (Sat, 08 Jul 2006) New Revision: 3105
Modified: branches/GNUnet-0.7.0/src/applications/identity/identity.c Log: Delete old hosts from local hostlist Modified: branches/GNUnet-0.7.0/src/applications/identity/identity.c =================================================================== --- branches/GNUnet-0.7.0/src/applications/identity/identity.c 2006-07-08 19:44:29 UTC (rev 3104) +++ branches/GNUnet-0.7.0/src/applications/identity/identity.c 2006-07-08 20:45:45 UTC (rev 3105) @@ -59,6 +59,10 @@ #define CRON_TRUST_FLUSH_FREQ (5 * cronMINUTES) +#define CRON_DISCARD_HOSTS_INTERVAL (cronDAYS) + +#define CRON_DISCARDS_HOSTS_AFTER (3 * cronMONTHS) + typedef struct { PeerIdentity identity; /** @@ -998,8 +1002,46 @@ } } +/** + * @brief Delete expired hosts + */ +static int discardHostsHelper(const char *filename, + const char *dirname, + void *now) { + char *fn; + struct stat hostStat; + int hostFile; + + fn = (char *) MALLOC(strlen(filename) + strlen(dirname) + 2); + sprintf(fn, "%s%s%s", dirname, DIR_SEPARATOR_STR, filename); + hostFile = fileopen(fn, O_WRONLY); + if (hostFile != -1) { + if (FSTAT(hostFile, &hostStat) == 0) { + CLOSE(hostFile); + + if (hostStat.st_mtime + (CRON_DISCARDS_HOSTS_AFTER / cronSECONDS) < *((time_t *) now)) + UNLINK(fn); + } + } + FREE(fn); + + return OK; +} /** + * @brief scan host directory for expired entries + */ +static void cronDiscardHosts(void *unused) { + time_t timeNow; + + timeNow = time(NULL); + scanDirectory(networkIdDirectory, + &discardHostsHelper, + (void *) &timeNow); +} + + +/** * Provide the Identity service. * * @param capi the core API @@ -1077,6 +1119,10 @@ CRON_TRUST_FLUSH_FREQ, CRON_TRUST_FLUSH_FREQ, NULL); + addCronJob(&cronDiscardHosts, + 0, + CRON_DISCARD_HOSTS_INTERVAL, + NULL); return &id; } @@ -1100,11 +1146,14 @@ 0); } delCronJob(&cronScanDirectoryDataHosts, - CRON_DATA_HOST_FREQ, + CRON_DISCARD_HOSTS_INTERVAL, NULL); delCronJob(&cronFlushTrustBuffer, CRON_TRUST_FLUSH_FREQ, NULL); + delCronJob(&cronDiscardHosts, + CRON_DISCARDS_HOSTS_AFTER, + NULL); cronFlushTrustBuffer(NULL); MUTEX_DESTROY(&lock_); for (i=0;i<numberOfHosts_;i++) { _______________________________________________ GNUnet-SVN mailing list GNUnet-SVN@gnu.org http://lists.gnu.org/mailman/listinfo/gnunet-svn