patch from karsten to complain less when a node loses

its hsdir status


svn:r13037
This commit is contained in:
Roger Dingledine 2008-01-06 01:54:09 +00:00
parent 17036de8b7
commit 5aa7ce2915
2 changed files with 37 additions and 15 deletions

View File

@ -1830,6 +1830,12 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
"'%s:%d'. Malformed rendezvous descriptor?", "'%s:%d'. Malformed rendezvous descriptor?",
escaped(reason), conn->_base.address, conn->_base.port); escaped(reason), conn->_base.address, conn->_base.port);
break; 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: default:
log_warn(LD_REND,"http status %d (%s) response unexpected (server " log_warn(LD_REND,"http status %d (%s) response unexpected (server "
"'%s:%d').", "'%s:%d').",
@ -2719,12 +2725,22 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
/* Handle v2 rendezvous service publish request. */ /* Handle v2 rendezvous service publish request. */
if (options->HidServDirectoryV2 && if (options->HidServDirectoryV2 &&
!strcmpstart(url,"/tor/rendezvous2/publish")) { !strcmpstart(url,"/tor/rendezvous2/publish")) {
if (rend_cache_store_v2_desc_as_dir(body) < 0) { switch (rend_cache_store_v2_desc_as_dir(body)) {
log_warn(LD_REND, "Rejected rend descriptor (length %d) from %s.", case -2:
log_info(LD_REND, "Rejected rend descriptor (length %d) from %s.",
(int)body_len, conn->_base.address); (int)body_len, conn->_base.address);
write_http_status_line(conn, 400, "Invalid service descriptor rejected"); write_http_status_line(conn, 503, "Currently not acting as v2 "
"hidden service directory");
log_info(LD_REND, "Handled v2 rendezvous descriptor post: rejected"); log_info(LD_REND, "Handled v2 rendezvous descriptor post: rejected");
} else { 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"); write_http_status_line(conn, 200, "Service descriptor stored");
log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted"); log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
} }

View File

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