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

[or-cvs] r13037: patch from karsten to complain less when a node loses its hs (tor/trunk/src/or)



Author: arma
Date: 2008-01-05 20:54:09 -0500 (Sat, 05 Jan 2008)
New Revision: 13037

Modified:
   tor/trunk/src/or/directory.c
   tor/trunk/src/or/rendcommon.c
Log:
patch from karsten to complain less when a node loses
its hsdir status


Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c	2008-01-06 01:14:11 UTC (rev 13036)
+++ tor/trunk/src/or/directory.c	2008-01-06 01:54:09 UTC (rev 13037)
@@ -1830,6 +1830,12 @@
                  "'%s:%d'. Malformed rendezvous descriptor?",
                  escaped(reason), conn->_base.address, conn->_base.port);
         break;
+      case 503:
+        log_info(LD_REND,"http status 503 (%s) response from dirserver "
+                 "'%s:%d'. Node is (currently) not acting as v2 hidden "
+                 "service directory.",
+                 escaped(reason), conn->_base.address, conn->_base.port);
+        break;
       default:
         log_warn(LD_REND,"http status %d (%s) response unexpected (server "
                  "'%s:%d').",
@@ -2719,14 +2725,24 @@
   /* Handle v2 rendezvous service publish request. */
   if (options->HidServDirectoryV2 &&
       !strcmpstart(url,"/tor/rendezvous2/publish")) {
-    if (rend_cache_store_v2_desc_as_dir(body) < 0) {
-      log_warn(LD_REND, "Rejected rend descriptor (length %d) from %s.",
-             (int)body_len, conn->_base.address);
-      write_http_status_line(conn, 400, "Invalid service descriptor rejected");
-      log_info(LD_REND, "Handled v2 rendezvous descriptor post: rejected");
-    } else {
-      write_http_status_line(conn, 200, "Service descriptor stored");
-      log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
+    switch (rend_cache_store_v2_desc_as_dir(body)) {
+      case -2:
+        log_info(LD_REND, "Rejected rend descriptor (length %d) from %s.",
+                 (int)body_len, conn->_base.address);
+        write_http_status_line(conn, 503, "Currently not acting as v2 "
+                               "hidden service directory");
+        log_info(LD_REND, "Handled v2 rendezvous descriptor post: rejected");
+        break;
+      case -1:
+        log_info(LD_REND, "Rejected rend descriptor (length %d) from %s.",
+                 (int)body_len, conn->_base.address);
+        write_http_status_line(conn, 400, "Invalid service descriptor "
+                                          "rejected");
+        log_info(LD_REND, "Handled v2 rendezvous descriptor post: rejected");
+        break;
+      default:
+        write_http_status_line(conn, 200, "Service descriptor stored");
+        log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
     }
     goto done;
   }

Modified: tor/trunk/src/or/rendcommon.c
===================================================================
--- tor/trunk/src/or/rendcommon.c	2008-01-06 01:14:11 UTC (rev 13036)
+++ tor/trunk/src/or/rendcommon.c	2008-01-06 01:54:09 UTC (rev 13037)
@@ -917,9 +917,10 @@
  *
  * If we have a newer descriptor with the same ID, ignore this one.
  * If we have an older descriptor with the same ID, replace it.
- * Return -1 if it's malformed or otherwise rejected; return 0 if
- * it's the same or older than one we've already got; return 1 if
- * it's novel.
+ * Return -2 if we are not acting as hidden service directory;
+ * return -1 if the descriptor(s) were not parsable; return 0 if all
+ * descriptors are the same or older than those we've already got;
+ * return a positive number for the number of novel stored descriptors.
  */
 int
 rend_cache_store_v2_desc_as_dir(const char *desc)
@@ -930,7 +931,7 @@
   size_t intro_size;
   size_t encoded_size;
   char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
-  int number_stored = 0;
+  int number_parsed = 0, number_stored = 0;
   const char *current_desc = desc;
   const char *next_desc;
   rend_cache_entry_t *e;
@@ -941,11 +942,12 @@
     /* Cannot store descs, because we are (currently) not acting as
      * hidden service directory. */
     log_info(LD_REND, "Cannot store descs: Not acting as hs dir");
-    return -1;
+    return -2;
   }
   while (rend_parse_v2_service_descriptor(&parsed, desc_id, &intro_content,
                                           &intro_size, &encoded_size,
                                           &next_desc, current_desc) >= 0) {
+    number_parsed++;
     /* We don't care about the introduction points. */
     tor_free(intro_content);
     /* For pretty log statements. */
@@ -1012,8 +1014,12 @@
         strcmpstart(current_desc, "rendezvous-service-descriptor "))
       break;
   }
-  log_info(LD_REND, "Parsed and added %d descriptor%s.",
-           number_stored, number_stored != 1 ? "s" : "");
+  if (!number_parsed) {
+    log_info(LD_REND, "Could not parse any descriptor.");
+    return -1;
+  }
+  log_info(LD_REND, "Parsed %d and added %d descriptor%s.",
+           number_parsed, number_stored, number_stored != 1 ? "s" : "");
   return number_stored;
 }