diff options
author | Roger Dingledine <arma@torproject.org> | 2008-06-09 06:33:29 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2008-06-09 06:33:29 +0000 |
commit | 6aeb79af06afcc6d4997ef36544448ba19603d72 (patch) | |
tree | f1bd1544389005a305ea179b0c11ab89adcc1588 /src/or | |
parent | eafb07ec96f7b844dd002d6aa60f42f469f5b3be (diff) | |
download | tor-6aeb79af06afcc6d4997ef36544448ba19603d72.tar.gz tor-6aeb79af06afcc6d4997ef36544448ba19603d72.zip |
report partial bootstrapping progress as we fetch descriptors
svn:r15083
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/directory.c | 2 | ||||
-rw-r--r-- | src/or/or.h | 1 | ||||
-rw-r--r-- | src/or/relay.c | 3 | ||||
-rw-r--r-- | src/or/routerlist.c | 59 |
4 files changed, 52 insertions, 13 deletions
diff --git a/src/or/directory.c b/src/or/directory.c index 7ca7692b4b..27bcfa5a45 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -1304,6 +1304,8 @@ load_downloaded_routers(const char *body, smartlist_t *which, router_load_routers_from_string(body, NULL, SAVED_NOWHERE, which, descriptor_digests, buf); + control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS, + count_loading_descriptors_progress()); } /** We are a client, and we've finished reading the server's diff --git a/src/or/or.h b/src/or/or.h index 73ac742f98..8d68c83801 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -4047,6 +4047,7 @@ void update_extrainfo_downloads(time_t now); int router_have_minimum_dir_info(void); void router_dir_info_changed(void); const char *get_dir_info_status_string(void); +int count_loading_descriptors_progress(void); void router_reset_descriptor_download_failures(void); int router_differences_are_cosmetic(routerinfo_t *r1, routerinfo_t *r2); int routerinfo_incompatible_with_extrainfo(routerinfo_t *ri, extrainfo_t *ei, diff --git a/src/or/relay.c b/src/or/relay.c index 1c2ab79a21..33ee055cea 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -949,7 +949,8 @@ connection_edge_process_relay_cell_not_open( control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_STATUS, 0); break; case DIR_PURPOSE_FETCH_SERVERDESC: - control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS, 0); + control_event_bootstrap(BOOTSTRAP_STATUS_LOADING_DESCRIPTORS, + count_loading_descriptors_progress()); break; } } diff --git a/src/or/routerlist.c b/src/or/routerlist.c index 4f31e350fe..0bc0cc2595 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -4168,6 +4168,52 @@ get_dir_info_status_string(void) return dir_info_status; } +static void +count_usable_descriptors(int *num_present, int *num_usable, + const networkstatus_t *consensus, + or_options_t *options, time_t now) +{ + *num_present = 0, *num_usable=0; + + SMARTLIST_FOREACH(consensus->routerstatus_list, routerstatus_t *, rs, + { + if (client_would_use_router(rs, now, options)) { + ++*num_usable; /* the consensus says we want it. */ + if (router_get_by_descriptor_digest(rs->descriptor_digest)) { + /* we have the descriptor listed in the consensus. */ + ++*num_present; + } + } + }); + + log_debug(LD_DIR, "%d usable, %d present.", *num_usable, *num_present); +} + +int +count_loading_descriptors_progress(void) +{ + int num_present = 0, num_usable=0; + time_t now = time(NULL); + const networkstatus_t *consensus = + networkstatus_get_reasonably_live_consensus(now); + double fraction; + + if (!consensus) + return 0; /* can't count descriptors if we have no list of them */ + + count_usable_descriptors(&num_present, &num_usable, + consensus, get_options(), now); + + if (num_usable == 0) + return 0; /* don't div by 0 */ + fraction = num_present / (num_usable/4.); + if (fraction > 1.0) + return 0; /* it's not the number of descriptors holding us back */ + return BOOTSTRAP_STATUS_LOADING_DESCRIPTORS + + fraction*(BOOTSTRAP_STATUS_CONN_OR-1 - + BOOTSTRAP_STATUS_LOADING_DESCRIPTORS); +} + /** Change the value of have_min_dir_info, setting it true iff we have enough * network and router information to build circuits. Clear the value of * need_to_update_have_min_dir_info. */ @@ -4200,18 +4246,7 @@ update_router_have_minimum_dir_info(void) goto done; } - SMARTLIST_FOREACH(consensus->routerstatus_list, routerstatus_t *, rs, - { - if (client_would_use_router(rs, now, options)) { - ++num_usable; /* the consensus says we want it. */ - if (router_get_by_descriptor_digest(rs->descriptor_digest)) { - /* we have the descriptor listed in the consensus. */ - ++num_present; - } - } - }); - - log_debug(LD_DIR, "%d usable, %d present.", num_usable, num_present); + count_usable_descriptors(&num_present, &num_usable, consensus, options, now); if (num_present < num_usable/4) { tor_snprintf(dir_info_status, sizeof(dir_info_status), |