mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-01 08:03:31 +01:00
Unify our "figure out which fingerprints we were downloading" code.
svn:r5077
This commit is contained in:
parent
05bab28c7d
commit
9c2ca40df3
@ -29,7 +29,6 @@ const char directory_c_id[] = "$Id$";
|
|||||||
* - connection_dir_finished_connecting(), called from
|
* - connection_dir_finished_connecting(), called from
|
||||||
* connection_finished_connecting() in connection.c
|
* connection_finished_connecting() in connection.c
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
|
directory_initiate_command_trusted_dir(trusted_dir_server_t *dirserv,
|
||||||
uint8_t purpose, int private_connection,
|
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
|
/* We were trying to download by fingerprint; mark them all has having
|
||||||
* failed, and possibly retry them later.*/
|
* failed, and possibly retry them later.*/
|
||||||
smartlist_t *failed = smartlist_create();
|
smartlist_t *failed = smartlist_create();
|
||||||
/* XXXX NM this splitting logic is duplicated someplace. Fix that. */
|
dir_split_resource_into_fingerprints(conn->requested_resource+3,
|
||||||
smartlist_split_string(failed, conn->requested_resource+3, "+", 0, 0);
|
failed, NULL);
|
||||||
if (smartlist_len(failed)) {
|
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);
|
dir_networkstatus_download_failed(failed);
|
||||||
SMARTLIST_FOREACH(failed, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(failed, char *, cp, tor_free(cp));
|
||||||
}
|
}
|
||||||
@ -968,12 +962,9 @@ connection_dir_client_reached_eof(connection_t *conn)
|
|||||||
}
|
}
|
||||||
if (conn->requested_resource &&
|
if (conn->requested_resource &&
|
||||||
!strcmpstart(conn->requested_resource,"fp/")) {
|
!strcmpstart(conn->requested_resource,"fp/")) {
|
||||||
int n;
|
|
||||||
which = smartlist_create();
|
which = smartlist_create();
|
||||||
smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1);
|
dir_split_resource_into_fingerprints(conn->requested_resource+3,
|
||||||
n = smartlist_len(which);
|
which, NULL);
|
||||||
if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2)
|
|
||||||
((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0';
|
|
||||||
}
|
}
|
||||||
cp = body;
|
cp = body;
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
@ -1016,12 +1007,9 @@ connection_dir_client_reached_eof(connection_t *conn)
|
|||||||
}
|
}
|
||||||
if (conn->requested_resource &&
|
if (conn->requested_resource &&
|
||||||
!strcmpstart(conn->requested_resource,"fp/")) {
|
!strcmpstart(conn->requested_resource,"fp/")) {
|
||||||
int n;
|
|
||||||
which = smartlist_create();
|
which = smartlist_create();
|
||||||
smartlist_split_string(which, conn->requested_resource+3, "+", 0, -1);
|
dir_split_resource_into_fingerprints(conn->requested_resource+3,
|
||||||
n = smartlist_len(which);
|
which, NULL);
|
||||||
if (n && strlen(smartlist_get(which,n-1))==HEX_DIGEST_LEN+2)
|
|
||||||
((char*)smartlist_get(which,n-1))[HEX_DIGEST_LEN] = '\0';
|
|
||||||
}
|
}
|
||||||
if (which)
|
if (which)
|
||||||
n_asked_for = smartlist_len(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! */
|
/* 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -1338,7 +1338,7 @@ dirserv_get_networkstatus_v2(smartlist_t *result,
|
|||||||
log_fn(LOG_WARN, "Client requested 'all' network status objects; we have none.");
|
log_fn(LOG_WARN, "Client requested 'all' network status objects; we have none.");
|
||||||
} else if (!strcmpstart(key, "fp/")) {
|
} else if (!strcmpstart(key, "fp/")) {
|
||||||
smartlist_t *hexdigests = smartlist_create();
|
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,
|
SMARTLIST_FOREACH(hexdigests, char *, cp,
|
||||||
{
|
{
|
||||||
cached_dir_t *cached;
|
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 *hexdigests = smartlist_create();
|
||||||
smartlist_t *digests = smartlist_create();
|
smartlist_t *digests = smartlist_create();
|
||||||
key += strlen("/tor/server/fp/");
|
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,
|
SMARTLIST_FOREACH(hexdigests, char *, cp,
|
||||||
{
|
{
|
||||||
char *d;
|
char *d;
|
||||||
|
@ -1715,6 +1715,8 @@ int connection_dir_finished_connecting(connection_t *conn);
|
|||||||
void connection_dir_request_failed(connection_t *conn);
|
void connection_dir_request_failed(connection_t *conn);
|
||||||
void parse_dir_policy(void);
|
void parse_dir_policy(void);
|
||||||
void free_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 ***************************/
|
/********************************* dirserv.c ***************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user