static void test_rend_cache_failure_intro_entry_free(void *data) { (void)data; rend_cache_failure_intro_t *entry; // Handles a null argument rend_cache_failure_intro_entry_free(NULL); // Handles a non-null argument entry = rend_cache_failure_intro_entry_new(INTRO_POINT_FAILURE_TIMEOUT); rend_cache_failure_intro_entry_free(entry); }
/** Helper: free a rend cache failure object. */ static void rend_cache_failure_entry_free(rend_cache_failure_t *entry) { if (entry == NULL) { return; } /* Free and remove every intro failure object. */ DIGESTMAP_FOREACH_MODIFY(entry->intro_failures, key, rend_cache_failure_intro_t *, e) { rend_cache_failure_intro_entry_free(e); MAP_DEL_CURRENT(key); } DIGESTMAP_FOREACH_END; tor_free(entry); }
/** Remove all entries that re REND_CACHE_FAILURE_MAX_AGE old. This is * called every second. * * We have to clean these regurlarly else if for whatever reasons an hidden * service goes offline and a client tries to connect to it during that * time, a failure entry is created and the client will be unable to connect * for a while even though the service has return online. */ void rend_cache_failure_clean(time_t now) { time_t cutoff = now - REND_CACHE_FAILURE_MAX_AGE; STRMAP_FOREACH_MODIFY(rend_cache_failure, key, rend_cache_failure_t *, ent) { /* Free and remove every intro failure object that match the cutoff. */ DIGESTMAP_FOREACH_MODIFY(ent->intro_failures, ip_key, rend_cache_failure_intro_t *, ip_ent) { if (ip_ent->created_ts < cutoff) { rend_cache_failure_intro_entry_free(ip_ent); MAP_DEL_CURRENT(ip_key); } } DIGESTMAP_FOREACH_END; /* If the entry is now empty of intro point failures, remove it. */ if (digestmap_isempty(ent->intro_failures)) { rend_cache_failure_entry_free(ent); MAP_DEL_CURRENT(key); } } STRMAP_FOREACH_END;
static void rend_cache_failure_intro_entry_free_(void *entry) { rend_cache_failure_intro_entry_free(entry); }