diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-04-15 10:33:04 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-04-15 10:33:04 -0400 |
commit | 8837cc266e44f8033f32a7d1a05020e585f034c7 (patch) | |
tree | 1b627b23567a717bad7355f4082f086b0831ae2e /src/or/rendcommon.c | |
parent | 7e6437babcea32c98cb028796bff1f81675b2c3b (diff) | |
parent | 91009dce971655f6b18b5eba5f0c0b48dbd8a737 (diff) | |
download | tor-8837cc266e44f8033f32a7d1a05020e585f034c7.tar.gz tor-8837cc266e44f8033f32a7d1a05020e585f034c7.zip |
Merge remote-tracking branch 'dgoulet/bug14391_026_v2'
Diffstat (limited to 'src/or/rendcommon.c')
-rw-r--r-- | src/or/rendcommon.c | 64 |
1 files changed, 40 insertions, 24 deletions
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index 5711f9e936..775d2b91c3 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -919,36 +919,52 @@ rend_valid_service_id(const char *query) return 1; } -/** If we have a cached rend_cache_entry_t for the service ID <b>query</b> - * with <b>version</b>, set *<b>e</b> to that entry and return 1. - * Else return 0. If <b>version</b> is nonnegative, only return an entry - * in that descriptor format version. Otherwise (if <b>version</b> is - * negative), return the most recent format we have. - */ +/** Lookup in the client cache the given service ID <b>query</b> for + * <b>version</b>. + * + * Return 0 if found and if <b>e</b> is non NULL, set it with the entry + * found. Else, a negative value is returned and <b>e</b> is untouched. + * -EINVAL means that <b>query</b> is not a valid service id. + * -ENOENT means that no entry in the cache was found. */ int rend_cache_lookup_entry(const char *query, int version, rend_cache_entry_t **e) { - char key[REND_SERVICE_ID_LEN_BASE32+2]; /* <version><query>\0 */ + int ret = 0; + char key[REND_SERVICE_ID_LEN_BASE32 + 2]; /* <version><query>\0 */ + rend_cache_entry_t *entry = NULL; + static const int default_version = 2; + tor_assert(rend_cache); - if (!rend_valid_service_id(query)) - return -1; - *e = NULL; - if (version != 0) { - tor_snprintf(key, sizeof(key), "2%s", query); - *e = strmap_get_lc(rend_cache, key); + tor_assert(query); + + if (!rend_valid_service_id(query)) { + ret = -EINVAL; + goto end; } - if (!*e && version != 2) { - tor_snprintf(key, sizeof(key), "0%s", query); - *e = strmap_get_lc(rend_cache, key); + + switch (version) { + case 0: + log_warn(LD_REND, "Cache lookup of a v0 renddesc is deprecated."); + break; + case 2: + /* Default is version 2. */ + default: + tor_snprintf(key, sizeof(key), "%d%s", default_version, query); + entry = strmap_get_lc(rend_cache, key); + break; } - if (!*e) - return 0; - tor_assert((*e)->parsed && (*e)->parsed->intro_nodes); - /* XXX023 hack for now, to return "not found" if there are no intro - * points remaining. See bug 997. */ - if (! rend_client_any_intro_points_usable(*e)) - return 0; - return 1; + if (!entry) { + ret = -ENOENT; + goto end; + } + tor_assert(entry->parsed && entry->parsed->intro_nodes); + + if (e) { + *e = entry; + } + +end: + return ret; } /** Lookup the v2 service descriptor with base32-encoded <b>desc_id</b> and |