summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2008-01-06 01:54:09 +0000
committerRoger Dingledine <arma@torproject.org>2008-01-06 01:54:09 +0000
commit5aa7ce2915563d7db290e37edbf2527f620f486c (patch)
treea9e92b55cd1653550a43fe922e9045ab3d8c4ad5
parent17036de8b7d0b33b46d5ee0a7b87b8052992e5d3 (diff)
downloadtor-5aa7ce2915563d7db290e37edbf2527f620f486c.tar.gz
tor-5aa7ce2915563d7db290e37edbf2527f620f486c.zip
patch from karsten to complain less when a node loses
its hsdir status svn:r13037
-rw-r--r--src/or/directory.c32
-rw-r--r--src/or/rendcommon.c20
2 files changed, 37 insertions, 15 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 9d8371951d..aa6e026379 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -1830,6 +1830,12 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
"'%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 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
/* 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;
}
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 2d40941b5b..ad77451eed 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -917,9 +917,10 @@ rend_cache_store(const char *desc, size_t desc_len, int published)
*
* 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 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
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 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
/* 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 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
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;
}