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

[or-cvs] r11545: bugfix on r11110: Fix a bug that made servers send a "404 No (in tor/trunk: . src/or)



Author: arma
Date: 2007-09-20 18:08:40 -0400 (Thu, 20 Sep 2007)
New Revision: 11545

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/or/dirserv.c
Log:
bugfix on r11110:
Fix a bug that made servers send a "404 Not found" in response to
attempts to fetch their server descriptor. This caused Tor servers
to take many minutes to establish reachability for their DirPort,
and it totally crippled bridges. Bugfix on 0.2.0.5-alpha.



Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-09-20 22:02:38 UTC (rev 11544)
+++ tor/trunk/ChangeLog	2007-09-20 22:08:40 UTC (rev 11545)
@@ -51,6 +51,10 @@
       connections: they specify their chosen rendezvous point by identity
       digest rather than by (potentially ambiguous) nickname. These
       changes could speed up hidden service connections dramatically.
+    - Fix a bug that made servers send a "404 Not found" in response to
+      attempts to fetch their server descriptor. This caused Tor servers
+      to take many minutes to establish reachability for their DirPort,
+      and it totally crippled bridges. Bugfix on 0.2.0.5-alpha.
 
   o Minor bugfixes:
     - When generating information telling us how to extend to a given

Modified: tor/trunk/src/or/dirserv.c
===================================================================
--- tor/trunk/src/or/dirserv.c	2007-09-20 22:02:38 UTC (rev 11544)
+++ tor/trunk/src/or/dirserv.c	2007-09-20 22:08:40 UTC (rev 11545)
@@ -2766,30 +2766,54 @@
   return found_any;
 }
 
+/** Return the cache-info for identity fingerprint <b>fp</b>, or
+ * its extra-info document if <b>extrainfo</b> is true. Return
+ * NULL if not found or if the descriptor is older than
+ * <b>publish_cutoff</b>. */
+static signed_descriptor_t *
+get_signed_descriptor_by_fp(const char *fp, int extrainfo,
+                            time_t publish_cutoff)
+{
+  if (router_digest_is_me(fp)) {
+    if (extrainfo)
+      return &(router_get_my_extrainfo()->cache_info);
+    else
+      return &(router_get_my_routerinfo()->cache_info);
+  } else {
+    routerinfo_t *ri = router_get_by_digest(fp);
+    if (ri &&
+        ri->cache_info.published_on > publish_cutoff) {
+      if (extrainfo)
+        return extrainfo_get_by_descriptor_digest(
+                                     ri->cache_info.extra_info_digest);
+      else
+        return &ri->cache_info;
+    }
+  }
+  return NULL;
+}
+
 /** Return true iff we have any of the docments (extrainfo or routerdesc)
  * specified by the fingerprints in <b>fps</b> and <b>spool_src</b>.  Used to
  * decide whether to send a 404.  */
 int
 dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src)
 {
+  time_t publish_cutoff = time(NULL)-ROUTER_MAX_AGE_TO_PUBLISH;
   SMARTLIST_FOREACH(fps, const char *, fp, {
       switch (spool_src)
       {
         case DIR_SPOOL_EXTRA_BY_DIGEST:
           if (extrainfo_get_by_descriptor_digest(fp)) return 1;
           break;
-        case DIR_SPOOL_EXTRA_BY_FP: {
-          routerinfo_t *ri = router_get_by_digest(fp);
-          if (ri && extrainfo_get_by_descriptor_digest(
-                                      ri->cache_info.extra_info_digest))
-            return 1;
-          }
-          break;
         case DIR_SPOOL_SERVER_BY_DIGEST:
           if (router_get_by_descriptor_digest(fp)) return 1;
           break;
+        case DIR_SPOOL_EXTRA_BY_FP:
         case DIR_SPOOL_SERVER_BY_FP:
-          if (router_get_by_digest(fp)) return 1;
+          if (get_signed_descriptor_by_fp(fp,
+                spool_src == DIR_SPOOL_EXTRA_BY_FP, publish_cutoff))
+            return 1;
           break;
       }
   });
@@ -2867,22 +2891,7 @@
     char *fp = smartlist_pop_last(conn->fingerprint_stack);
     signed_descriptor_t *sd = NULL;
     if (by_fp) {
-      if (router_digest_is_me(fp)) {
-        if (extra)
-          sd = &(router_get_my_extrainfo()->cache_info);
-        else
-          sd = &(router_get_my_routerinfo()->cache_info);
-      } else {
-        routerinfo_t *ri = router_get_by_digest(fp);
-        if (ri &&
-            ri->cache_info.published_on > publish_cutoff) {
-          if (extra)
-            sd = extrainfo_get_by_descriptor_digest(
-                                         ri->cache_info.extra_info_digest);
-          else
-            sd = &ri->cache_info;
-        }
-      }
+      sd = get_signed_descriptor_by_fp(fp, extra, publish_cutoff);
     } else {
       sd = extra ? extrainfo_get_by_descriptor_digest(fp)
         : router_get_by_descriptor_digest(fp);