[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r13265: patch "15" from karsten: don't retry a v2 renddesc fetch if (tor/trunk/src/or)
Author: arma
Date: 2008-01-24 17:49:14 -0500 (Thu, 24 Jan 2008)
New Revision: 13265
Modified:
tor/trunk/src/or/directory.c
tor/trunk/src/or/rendcommon.c
Log:
patch "15" from karsten: don't retry a v2 renddesc fetch
if we have a perfectly good v0 renddesc.
Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c 2008-01-24 22:47:39 UTC (rev 13264)
+++ tor/trunk/src/or/directory.c 2008-01-24 22:49:14 UTC (rev 13265)
@@ -1798,16 +1798,27 @@
(int)body_len, status_code, escaped(reason));
switch (status_code) {
case 200:
- if (rend_cache_store_v2_desc_as_client(body, NULL) < 0) {
- log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
- "Retrying at another directory.");
- /* We'll retry when connection_about_to_close_connection()
- * cleans this dir conn up. */
- } else {
- /* success. notify pending connections about this. */
- log_info(LD_REND, "Successfully fetched rendezvous descriptor.");
- conn->_base.purpose = DIR_PURPOSE_HAS_FETCHED_RENDDESC;
- rend_client_desc_here(conn->rend_query);
+ switch (rend_cache_store_v2_desc_as_client(body, NULL)) {
+ case -2:
+ log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
+ "Retrying at another directory.");
+ /* We'll retry when connection_about_to_close_connection()
+ * cleans this dir conn up. */
+ break;
+ case -1:
+ /* We already have a v0 descriptor here. Ignoring this one
+ * and _not_ performing another request. */
+ log_info(LD_REND, "Successfully fetched v2 rendezvous "
+ "descriptor, but we already have a v0 descriptor.");
+ conn->_base.purpose = DIR_PURPOSE_HAS_FETCHED_RENDDESC;
+ break;
+ default:
+ /* success. notify pending connections about this. */
+ log_info(LD_REND, "Successfully fetched v2 rendezvous "
+ "descriptor.");
+ conn->_base.purpose = DIR_PURPOSE_HAS_FETCHED_RENDDESC;
+ rend_client_desc_here(conn->rend_query);
+ break;
}
break;
case 404:
Modified: tor/trunk/src/or/rendcommon.c
===================================================================
--- tor/trunk/src/or/rendcommon.c 2008-01-24 22:47:39 UTC (rev 13264)
+++ tor/trunk/src/or/rendcommon.c 2008-01-24 22:49:14 UTC (rev 13265)
@@ -830,8 +830,11 @@
}
/** Parse *desc, calculate its service id, and store it in the cache.
- * If we have a newer descriptor with the same ID, ignore this one.
+ * If we have a newer v0 descriptor with the same ID, ignore this one.
* If we have an older descriptor with the same ID, replace it.
+ * If we are acting as client due to the published flag and have any v2
+ * descriptor with the same ID, reject this one in order to not get
+ * confused with having both versions for the same service.
* 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. The published flag tells us if we store the descriptor
@@ -857,7 +860,6 @@
rend_service_descriptor_free(parsed);
return -1;
}
- tor_snprintf(key, sizeof(key), "0%s", query);
now = time(NULL);
if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
log_fn(LOG_PROTOCOL_WARN, LD_REND,
@@ -871,10 +873,18 @@
rend_service_descriptor_free(parsed);
return -1;
}
+ /* Do we have a v2 descriptor and fetched this descriptor as a client? */
+ tor_snprintf(key, sizeof(key), "2%s", query);
+ if (!published && strmap_get_lc(rend_cache, key)) {
+ log_info(LD_REND, "We already have a v2 descriptor for service %s.",
+ safe_str(query));
+ return -1;
+ }
/* report novel publication to statistics */
if (published && options->HSAuthorityRecordStats) {
hs_usage_note_publish_total(query, now);
}
+ tor_snprintf(key, sizeof(key), "0%s", query);
e = (rend_cache_entry_t*) strmap_get_lc(rend_cache, key);
if (e && e->parsed->timestamp > parsed->timestamp) {
log_info(LD_REND,"We already have a newer service descriptor %s with the "
@@ -1028,11 +1038,13 @@
* <b>NULL</b> if decryption is not necessary), and store the descriptor to
* the local cache under its version and service id.
*
- * If we have a newer descriptor with the same ID, ignore this one.
+ * If we have a newer v2 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.
+ * If we have any v0 descriptor with the same ID, reject this one in order
+ * to not get confused with having both versions for the same service.
+ * Return -2 if it's malformed or otherwise rejected; return -1 if we
+ * already have a v0 descriptor here; return 0 if it's the same or older
+ * than one we've already got; return 1 if it's novel.
*/
int
rend_cache_store_v2_desc_as_client(const char *desc,
@@ -1072,14 +1084,14 @@
if (parsed) rend_service_descriptor_free(parsed);
tor_free(intro_content);
log_warn(LD_REND, "Could not parse descriptor.");
- return -1;
+ return -2;
}
/* Compute service ID from public key. */
if (rend_get_service_id(parsed->pk, service_id)<0) {
log_warn(LD_REND, "Couldn't compute service ID.");
rend_service_descriptor_free(parsed);
tor_free(intro_content);
- return -1;
+ return -2;
}
/* Decode/decrypt introduction points. */
if (intro_content) {
@@ -1088,7 +1100,7 @@
log_warn(LD_PROTOCOL,"Couldn't decode/decrypt introduction points.");
rend_service_descriptor_free(parsed);
tor_free(intro_content);
- return -1;
+ return -2;
}
} else {
parsed->intro_nodes = smartlist_create();
@@ -1100,13 +1112,20 @@
log_warn(LD_REND, "Service descriptor with service ID %s is too old.",
service_id);
rend_service_descriptor_free(parsed);
- return -1;
+ return -2;
}
/* Is descriptor too far in the future? */
if (parsed->timestamp > now + REND_CACHE_MAX_SKEW) {
log_warn(LD_REND, "Service descriptor with service ID %s is too far in "
"the future.", service_id);
rend_service_descriptor_free(parsed);
+ return -2;
+ }
+ /* Do we have a v0 descriptor? */
+ tor_snprintf(key, sizeof(key), "0%s", service_id);
+ if (strmap_get_lc(rend_cache, key)) {
+ log_info(LD_REND, "We already have a v0 descriptor for service ID %s.",
+ service_id);
return -1;
}
/* Do we already have a newer descriptor? */