Переглянути джерело

authorities do not replace server descriptors where nothing semantically relevant has changed since the last upload.

svn:r5240
Nick Mathewson 20 роки тому
батько
коміт
972b7512c7
3 змінених файлів з 29 додано та 6 видалено
  1. 1 1
      src/or/directory.c
  2. 14 1
      src/or/dirserv.c
  3. 14 4
      src/or/routerlist.c

+ 1 - 1
src/or/directory.c

@@ -1441,7 +1441,7 @@ directory_handle_command_post(connection_t *conn, char *headers,
   if (!authdir_mode(get_options())) {
     /* we just provide cached directories; we don't want to
      * receive anything. */
-    write_http_status_line(conn, 400, "Nonauthoritative directory does not not store server descriptors.");
+    write_http_status_line(conn, 400, "Nonauthoritative directory does not accept posted server descriptors.");
     return 0;
   }
 

+ 14 - 1
src/or/dirserv.c

@@ -439,7 +439,7 @@ int
 dirserv_add_descriptor(const char *desc, const char **msg)
 {
   int r;
-  routerinfo_t *ri = NULL;
+  routerinfo_t *ri = NULL, *ri_old = NULL;
   tor_assert(msg);
   *msg = NULL;
 
@@ -450,6 +450,19 @@ dirserv_add_descriptor(const char *desc, const char **msg)
     *msg = "Rejected: Couldn't parse server descriptor.";
     return -2;
   }
+  /* Check whether this descriptor is semantically identical to the last one
+   * from this server.  (We do this here and not in router_add_to_routerlist
+   * because we want to be able to accept the newest router descriptor that
+   * another authority has, so we all converge on the same one.) */
+  ri_old = router_get_by_digest(ri->identity_digest);
+  if (ri_old && ri_old->published_on < ri->published_on &&
+      router_differences_are_cosmetic(ri_old, ri)) {
+    log_fn(LOG_INFO,
+           "Not replacing descriptor from '%s'; differences are cosmetic.",
+           ri->nickname);
+    *msg = "Not replacing router descriptor; no information has changed since the last one with this identity.";
+    return 0;
+  }
   if ((r = router_add_to_routerlist(ri, msg, 0))<0) {
     return r == -1 ? 0 : -1;
   } else {

+ 14 - 4
src/or/routerlist.c

@@ -2533,8 +2533,6 @@ routers_update_status_from_networkstatus(smartlist_t *routers, int reset_failure
   if (!routerstatus_list)
     return;
 
-  log_fn(LOG_NOTICE, "Here, %d %d", reset_failures, assume_recognized);
-
   SMARTLIST_FOREACH(routers, routerinfo_t *, router,
   {
     rs = router_get_combined_status_by_digest(router->identity_digest);
@@ -2864,11 +2862,19 @@ router_reset_descriptor_download_failures(void)
 int
 router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2)
 {
+  tor_assert(r1 && r2);
+
   /* post-0.1.1.6 servers know what they're doing. */
   if (tor_version_as_new_as(r1->platform, "0.1.1.6-alpha") ||
       tor_version_as_new_as(r1->platform, "0.1.1.6-alpha"))
     return 0;
 
+  if (r1->published_on > r2->published_on) {
+    routerinfo_t *ri_tmp = r2;
+    r2 = r1;
+    r1 = ri_tmp;
+  }
+
   /* If any key fields differ, they're different. */
   if (strcasecmp(r1->address, r2->address) ||
       strcasecmp(r1->nickname, r2->nickname) ||
@@ -2901,8 +2907,12 @@ router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2)
     return 0;
 
   /* Did more than 6 hours pass? */
-  if (r1->published_on + 6*60*60 < r2->published_on ||
-      r2->published_on + 6*60*60 < r1->published_on)
+  if (r1->published_on + 6*60*60 < r2->published_on)
+    return 0;
+
+  /* Did uptime fail to increase by approximately the amount we would think,
+   * give or take 30 minutes? */
+  if (abs(r2->uptime - (r1->uptime + (r2->published_on-r1->published_on)))>30*60)
     return 0;
 
   /* Otherwise, the difference is cosmetic. */