Make rend_cache_store() use the same return error codes as its v2

equivalent: I got a lonely "Failed to fetch rendezvous descriptor."
in my log file, even when the connection worked.


svn:r17028
This commit is contained in:
Roger Dingledine 2008-10-02 07:32:13 +00:00
parent e24b812a32
commit e7f5a07ff4
2 changed files with 14 additions and 10 deletions

View File

@ -1946,15 +1946,16 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
(int)body_len, status_code, escaped(reason)); (int)body_len, status_code, escaped(reason));
switch (status_code) { switch (status_code) {
case 200: case 200:
if (rend_cache_store(body, body_len, 0) < 0) { if (rend_cache_store(body, body_len, 0) < -1) {
log_warn(LD_REND,"Failed to fetch rendezvous descriptor."); log_warn(LD_REND,"Failed to parse rendezvous descriptor.");
/* Any pending rendezvous attempts will notice when /* Any pending rendezvous attempts will notice when
* connection_about_to_close_connection() * connection_about_to_close_connection()
* cleans this dir conn up. */ * cleans this dir conn up. */
/* We could retry. But since v0 descriptors are going out of /* We could retry. But since v0 descriptors are going out of
* style, it isn't worth the hassle. We'll do better in v2. */ * style, it isn't worth the hassle. We'll do better in v2. */
} else { } else {
/* success. notify pending connections about this. */ /* Success, or at least there's a v2 descriptor already
* present. Notify pending connections about this. */
conn->_base.purpose = DIR_PURPOSE_HAS_FETCHED_RENDDESC; conn->_base.purpose = DIR_PURPOSE_HAS_FETCHED_RENDDESC;
rend_client_desc_trynow(conn->rend_data->onion_address, -1); rend_client_desc_trynow(conn->rend_data->onion_address, -1);
} }

View File

@ -1027,9 +1027,12 @@ rend_cache_lookup_v2_desc_as_dir(const char *desc_id, const char **desc)
* If we are acting as client due to the published flag and have any v2 * 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 * descriptor with the same ID, reject this one in order to not get
* confused with having both versions for the same service. * 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 * Return -2 if it's malformed or otherwise rejected; return -1 if we
* it's novel. The published flag tells us if we store the descriptor * already have a v2 descriptor here; 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
* in our role as directory (1) or if we cache it as client (0). * in our role as directory (1) or if we cache it as client (0).
*/ */
int int
@ -1045,25 +1048,25 @@ rend_cache_store(const char *desc, size_t desc_len, int published)
parsed = rend_parse_service_descriptor(desc,desc_len); parsed = rend_parse_service_descriptor(desc,desc_len);
if (!parsed) { if (!parsed) {
log_warn(LD_PROTOCOL,"Couldn't parse service descriptor."); log_warn(LD_PROTOCOL,"Couldn't parse service descriptor.");
return -1; return -2;
} }
if (rend_get_service_id(parsed->pk, query)<0) { if (rend_get_service_id(parsed->pk, query)<0) {
log_warn(LD_BUG,"Couldn't compute service ID."); log_warn(LD_BUG,"Couldn't compute service ID.");
rend_service_descriptor_free(parsed); rend_service_descriptor_free(parsed);
return -1; return -2;
} }
now = time(NULL); now = time(NULL);
if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) { if (parsed->timestamp < now-REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
log_fn(LOG_PROTOCOL_WARN, LD_REND, log_fn(LOG_PROTOCOL_WARN, LD_REND,
"Service descriptor %s is too old.", safe_str(query)); "Service descriptor %s is too old.", safe_str(query));
rend_service_descriptor_free(parsed); rend_service_descriptor_free(parsed);
return -1; return -2;
} }
if (parsed->timestamp > now+REND_CACHE_MAX_SKEW) { if (parsed->timestamp > now+REND_CACHE_MAX_SKEW) {
log_fn(LOG_PROTOCOL_WARN, LD_REND, log_fn(LOG_PROTOCOL_WARN, LD_REND,
"Service descriptor %s is too far in the future.", safe_str(query)); "Service descriptor %s is too far in the future.", safe_str(query));
rend_service_descriptor_free(parsed); rend_service_descriptor_free(parsed);
return -1; return -2;
} }
/* Do we have a v2 descriptor and fetched this descriptor as a client? */ /* Do we have a v2 descriptor and fetched this descriptor as a client? */
tor_snprintf(key, sizeof(key), "2%s", query); tor_snprintf(key, sizeof(key), "2%s", query);