diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-09-27 20:46:30 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-09-27 20:46:30 +0000 |
commit | b5c8a8ae53c141c14651485794999910d0168be8 (patch) | |
tree | 5a698b0cdf8502c9c945cd9f70cb00e1a96d9625 /src/or/routerparse.c | |
parent | 2050b31bb90861c6cbf8cfc54299f5a7f10609a2 (diff) | |
download | tor-b5c8a8ae53c141c14651485794999910d0168be8.tar tor-b5c8a8ae53c141c14651485794999910d0168be8.tar.gz |
r15422@catbus: nickm | 2007-09-27 16:42:35 -0400
Use descriptor annotations to record the source, download t time, and purpose of every descriptor we add to the store. The remaining to-do item is to stop setting do_not_cache on bridges.
svn:r11680
Diffstat (limited to 'src/or/routerparse.c')
-rw-r--r-- | src/or/routerparse.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 761e6176d..adf6ca314 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -1015,6 +1015,7 @@ router_parse_entry_from_string(const char *s, const char *end, directory_token_t *tok; struct in_addr in; const char *start_of_annotations, *cp; + size_t prepend_len = prepend_annotations ? strlen(prepend_annotations) : 0; tor_assert(!allow_annotations || !prepend_annotations); @@ -1068,17 +1069,12 @@ router_parse_entry_from_string(const char *s, const char *end, goto err; } - tok = smartlist_get(tokens,0); - if (tok->tp != K_ROUTER) { - log_warn(LD_DIR,"Entry does not start with \"router\""); - goto err; - } + tok = find_first_by_keyword(tokens, K_ROUTER); tor_assert(tok->n_args >= 5); router = tor_malloc_zero(sizeof(routerinfo_t)); router->routerlist_index = -1; - router->cache_info.annotations_len = s-start_of_annotations + - (prepend_annotations ? strlen(prepend_annotations) : 0) ; + router->cache_info.annotations_len = s-start_of_annotations + prepend_len; router->cache_info.signed_descriptor_len = end-s; if (cache_copy) { size_t len = router->cache_info.signed_descriptor_len + @@ -1086,11 +1082,12 @@ router_parse_entry_from_string(const char *s, const char *end, char *cp = router->cache_info.signed_descriptor_body = tor_malloc(len+1); if (prepend_annotations) { - strlcpy(cp, prepend_annotations, len+1); - cp += strlen(prepend_annotations); + memcpy(cp, prepend_annotations, prepend_len); + cp += prepend_len; } - memcpy(cp, s, end-s); - cp[len] = '\0'; + memcpy(cp, start_of_annotations, end-start_of_annotations); + router->cache_info.signed_descriptor_body[len] = '\0'; + tor_assert(strlen(router->cache_info.signed_descriptor_body) == len); } memcpy(router->cache_info.signed_descriptor_digest, digest, DIGEST_LEN); @@ -1116,8 +1113,6 @@ router_parse_entry_from_string(const char *s, const char *end, router->bandwidthrate = tor_parse_long(tok->args[0],10,0,INT_MAX,NULL,NULL); - /* Set purpose XXXX020 NM NM*/ - if (!router->bandwidthrate) { log_warn(LD_DIR, "bandwidthrate %s unreadable or 0. Failing.", escaped(tok->args[0])); @@ -1129,6 +1124,13 @@ router_parse_entry_from_string(const char *s, const char *end, tor_parse_long(tok->args[2],10,0,INT_MAX,NULL,NULL); /* XXXX020 we don't error-check these values? -RD */ + if ((tok = find_first_by_keyword(tokens, A_PURPOSE))) { + tor_assert(tok->n_args); + router->purpose = router_purpose_from_string(tok->args[0]); + } else { + router->purpose = ROUTER_PURPOSE_GENERAL; + } + if ((tok = find_first_by_keyword(tokens, K_UPTIME))) { tor_assert(tok->n_args >= 1); router->uptime = tor_parse_long(tok->args[0],10,0,LONG_MAX,NULL,NULL); |