diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-09-16 04:42:45 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-09-16 04:42:45 +0000 |
commit | 9c2ca40df3b84c66a55d273ddea4cbc765476da6 (patch) | |
tree | dfb75170682a76ac6d84f10f148b7df1690d9767 | |
parent | 05bab28c7d9a60d14b2bd880b793e645eb6cc3cd (diff) | |
download | tor-9c2ca40df3b84c66a55d273ddea4cbc765476da6.tar tor-9c2ca40df3b84c66a55d273ddea4cbc765476da6.tar.gz |
Unify our "figure out which fingerprints we were downloading" code.
svn:r5077
-rw-r--r-- | src/or/directory.c | 43 | ||||
-rw-r--r-- | src/or/dirserv.c | 4 | ||||
-rw-r--r-- | src/or/or.h | 2 |
3 files changed, 29 insertions, 20 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 993d77c88..5cabfa334 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -29,7 +29,6 @@ const char directory_c_id[] = "$Id$"; * - connection_dir_finished_connecting(), called from * connection_finished_connecting() in connection.c */ - static void directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv, uint8_t purpose, int private_connection, @@ -305,14 +304,9 @@ connection_dir_download_networkstatus_failed(connection_t *conn) /* We were trying to download by fingerprint; mark them all has having * failed, and possibly retry them later.*/ smartlist_t *failed = smartlist_create(); - /* XXXX NM this splitting logic is duplicated someplace. Fix that. */ - smartlist_split_string(failed, conn->requested_resource+3, "+", 0, 0); + dir_split_resource_into_fingerprints(conn->requested_resource+3, + failed, NULL); if (smartlist_len(failed)) { - char *last = smartlist_get(failed,smartlist_len(failed)-1); - size_t last_len = strlen(last); - if (!strcmp(last+last_len-2, ".z")) - last[last_len-2] = '\0'; - dir_networkstatus_download_failed(failed); SMARTLIST_FOREACH(failed, char *, cp, tor_free(cp)); } @@ -968,12 +962,9 @@ connection_dir_client_reached_eof(connection_t *conn) } if (conn->requested_resource && !strcmpstart(conn->requested_resource,"fp/")) { - int n; which = smartlist_create(); - smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1); - n = smartlist_len(which); - if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2) - ((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0'; + dir_split_resource_into_fingerprints(conn->requested_resource+3, + which, NULL); } cp = body; while (*cp) { @@ -1016,12 +1007,9 @@ connection_dir_client_reached_eof(connection_t *conn) } if (conn->requested_resource && !strcmpstart(conn->requested_resource,"fp/")) { - int n; which = smartlist_create(); - smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1); - n = smartlist_len(which); - if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2) - ((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0'; + dir_split_resource_into_fingerprints(conn->requested_resource+3, + which, NULL); } if (which) n_asked_for = smartlist_len(which); @@ -1586,3 +1574,22 @@ dir_routerdesc_download_failed(smartlist_t *failed) /* XXXX writeme! Give up after a while! */ } +/* DOCDOC */ +int +dir_split_resource_into_fingerprints(const char *resource, + smartlist_t *fp_out, int *compressed_out) +{ + smartlist_split_string(fp_out, resource, "+", 0, 0); + if (compressed_out) + *compressed_out = 0; + if (smartlist_len(fp_out)) { + char *last = smartlist_get(fp_out,smartlist_len(fp_out)-1); + size_t last_len = strlen(last); + if (last_len > 2 && !strcmp(last+last_len-2, ".z")) { + last[last_len-2] = '\0'; + if (compressed_out) + *compressed_out = 1; + } + } +} + diff --git a/src/or/dirserv.c b/src/or/dirserv.c index ae43a7df8..e62978f14 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1338,7 +1338,7 @@ dirserv_get_networkstatus_v2(smartlist_t *result, log_fn(LOG_WARN, "Client requested 'all' network status objects; we have none."); } else if (!strcmpstart(key, "fp/")) { smartlist_t *hexdigests = smartlist_create(); - smartlist_split_string(hexdigests, key+3, "+", 0, 0); + dir_split_resource_into_fingerprints(key+3, hexdigests, NULL); SMARTLIST_FOREACH(hexdigests, char *, cp, { cached_dir_t *cached; @@ -1384,7 +1384,7 @@ dirserv_get_routerdescs(smartlist_t *descs_out, const char *key) smartlist_t *hexdigests = smartlist_create(); smartlist_t *digests = smartlist_create(); key += strlen("/tor/server/fp/"); - smartlist_split_string(hexdigests, key, "+", 0, 0); + dir_split_resource_into_fingerprints(key, hexdigests, NULL); SMARTLIST_FOREACH(hexdigests, char *, cp, { char *d; diff --git a/src/or/or.h b/src/or/or.h index 030ed64f6..209653ac1 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1715,6 +1715,8 @@ int connection_dir_finished_connecting(connection_t *conn); void connection_dir_request_failed(connection_t *conn); void parse_dir_policy(void); void free_dir_policy(void); +int dir_split_resource_into_fingerprints(const char *resource, + smartlist_t *fp_out, int *compresseed_out); /********************************* dirserv.c ***************************/ |