[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Expire after 5 minutes rend cache failure entries



commit 7dce409802193eed9f8378e11b1c38eeb1127929
Author: David Goulet <dgoulet@xxxxxxxxx>
Date:   Wed Aug 5 14:06:09 2015 -0400

    Expire after 5 minutes rend cache failure entries
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxx>
---
 src/or/main.c      |    4 ++++
 src/or/rendcache.c |   29 +++++++++++++++++++++++++++++
 src/or/rendcache.h |    3 +++
 3 files changed, 36 insertions(+)

diff --git a/src/or/main.c b/src/or/main.c
index 5bff82b..e564e6c 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1488,6 +1488,10 @@ run_scheduled_events(time_t now)
 #define CLEAN_CACHES_INTERVAL (30*60)
     time_to.clean_caches = now + CLEAN_CACHES_INTERVAL;
   }
+  /* We don't keep entries that are more than five minutes old so we try to
+   * clean it as soon as we can since we want to make sure the client waits
+   * as little as possible for reachability reasons. */
+  rend_cache_failure_clean(now);
 
 #define RETRY_DNS_INTERVAL (10*60)
   /* If we're a server and initializing dns failed, retry periodically. */
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index 9be9e24..9a33046 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -225,6 +225,35 @@ rend_cache_free_all(void)
   rend_cache_total_allocation = 0;
 }
 
+/** 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;
+}
+
 /** Removes all old entries from the service descriptor cache.
 */
 void
diff --git a/src/or/rendcache.h b/src/or/rendcache.h
index 98c0f95..0512058 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -18,6 +18,8 @@
 /** How wrong do we assume our clock may be when checking whether hidden
  * services are too old or too new? */
 #define REND_CACHE_MAX_SKEW (24*60*60)
+/** How old do we keep an intro point failure entry in the failure cache? */
+#define REND_CACHE_FAILURE_MAX_AGE (5*60)
 
 /* Do not allow more than this many introduction points in a hidden service
  * descriptor */
@@ -48,6 +50,7 @@ typedef struct rend_cache_failure_t {
 
 void rend_cache_init(void);
 void rend_cache_clean(time_t now);
+void rend_cache_failure_clean(time_t now);
 void rend_cache_clean_v2_descs_as_dir(time_t now, size_t min_to_remove);
 void rend_cache_purge(void);
 void rend_cache_free_all(void);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits