Unify our "figure out which fingerprints we were downloading" code.

svn:r5077
This commit is contained in:
Nick Mathewson 2005-09-16 04:42:45 +00:00
parent 05bab28c7d
commit 9c2ca40df3
3 changed files with 29 additions and 20 deletions

View File

@ -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;
}
}
}

View File

@ -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;

View File

@ -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 ***************************/