diff options
Diffstat (limited to 'src/or/rendcommon.c')
-rw-r--r-- | src/or/rendcommon.c | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c index 7965e0fa43..26801af874 100644 --- a/src/or/rendcommon.c +++ b/src/or/rendcommon.c @@ -2,9 +2,14 @@ /* See LICENSE for licensing information */ /* $Id$ */ +/***** + * rendcommon.c: Rendezvous implementation: shared code between + * introducers, services, clients, and rendezvous points. + *****/ + #include "or.h" -/* Free the storage held by 'desc'. +/* Free the storage held by the service descriptor 'desc'. */ void rend_service_descriptor_free(rend_service_descriptor_t *desc) { @@ -66,8 +71,10 @@ rend_encode_service_descriptor(rend_service_descriptor_t *desc, return 0; } -/* malloc a service_descriptor_t and return it. - * return NULL if invalid descriptor or error */ +/* Parse a service descriptor at 'str' (len bytes). On success, + * return a newly alloced service_descriptor_t. On failure, return + * NULL. + */ rend_service_descriptor_t *rend_parse_service_descriptor( const char *str, int len) { @@ -121,8 +128,9 @@ rend_service_descriptor_t *rend_parse_service_descriptor( return NULL; } -/* Sets out to the first 10 bytes of the digest of 'pk', base32 encoded. - * NUL-terminates out. +/* Sets out to the first 10 bytes of the digest of 'pk', base32 + * encoded. NUL-terminates out. (We use this string to identify + * services in directory requests and .onion URLs.) */ int rend_get_service_id(crypto_pk_env_t *pk, char *out) { @@ -139,6 +147,8 @@ int rend_get_service_id(crypto_pk_env_t *pk, char *out) #define REND_CACHE_MAX_AGE (24*60*60) #define REND_CACHE_MAX_SKEW (90*60) +/* Map from service id (as generated by rend_get_service_id) to + * rend_cache_entry_t. */ static strmap_t *rend_cache = NULL; /* Initializes the service descriptor cache. @@ -172,8 +182,9 @@ void rend_cache_clean(void) } } -/* return 1 if query is a valid service id, else return 0. */ -int rend_valid_service_id(char *query) { +/* Return true iff 'query' is a syntactically valid service ID (as + * generated by rend_get_service_id). */ +int rend_valid_service_id(const char *query) { if(strlen(query) != REND_SERVICE_ID_LEN) return 0; @@ -183,7 +194,10 @@ int rend_valid_service_id(char *query) { return 1; } -int rend_cache_lookup_entry(char *query, rend_cache_entry_t **e) +/* If we have a cached rend_cache_entry_t for the service ID 'query', set + * *e to that entry and return 1. Else return 0. + */ +int rend_cache_lookup_entry(const char *query, rend_cache_entry_t **e) { tor_assert(rend_cache); if (!rend_valid_service_id(query)) @@ -199,8 +213,10 @@ int rend_cache_lookup_entry(char *query, rend_cache_entry_t **e) * If it is found, point *desc to it, and write its length into * *desc_len, and return 1. * If it is not found, return 0. + * Note: calls to rend_cache_clean or rend_cache_store may invalidate + * *desc. */ -int rend_cache_lookup_desc(char *query, const char **desc, int *desc_len) +int rend_cache_lookup_desc(const char *query, const char **desc, int *desc_len) { rend_cache_entry_t *e; int r; @@ -211,12 +227,12 @@ int rend_cache_lookup_desc(char *query, const char **desc, int *desc_len) return 1; } - -/* Calculate desc's service id, and store it. - * Return -1 if it's malformed or otherwise rejected and you - * want the caller to fail, else return 0. +/* 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 an older descriptor with the same ID, replace it. + * Returns -1 if it's malformed or otherwise rejected, else return 0. */ -int rend_cache_store(char *desc, int desc_len) +int rend_cache_store(const char *desc, int desc_len) { rend_cache_entry_t *e; rend_service_descriptor_t *parsed; @@ -273,7 +289,8 @@ int rend_cache_store(char *desc, int desc_len) return 0; } -/* Dispatch on rendezvous relay command. */ +/* Called when we get a rendezvous-related relay cell on circuit + * *circ. Dispatch on rendezvous relay command. */ void rend_process_relay_cell(circuit_t *circ, int command, int length, const char *payload) { |