refactor; no actual changes

This commit is contained in:
Roger Dingledine 2010-09-23 22:10:13 -04:00
parent 09a715bb72
commit 127f37ad29
3 changed files with 15 additions and 25 deletions

View File

@ -3209,7 +3209,7 @@ entry_guard_set_status(entry_guard_t *e, routerinfo_t *ri,
char buf[HEX_DIGEST_LEN+1]; char buf[HEX_DIGEST_LEN+1];
int changed = 0; int changed = 0;
tor_assert(options); tor_assert(options); /* dead code */
*reason = NULL; *reason = NULL;
@ -3468,9 +3468,8 @@ add_an_entry_guard(routerinfo_t *chosen, int reset_status)
/** If the use of entry guards is configured, choose more entry guards /** If the use of entry guards is configured, choose more entry guards
* until we have enough in the list. */ * until we have enough in the list. */
static void static void
pick_entry_guards(void) pick_entry_guards(or_options_t *options)
{ {
or_options_t *options = get_options();
int changed = 0; int changed = 0;
tor_assert(entry_guards); tor_assert(entry_guards);
@ -3502,10 +3501,9 @@ entry_guard_free(entry_guard_t *e)
* or which was selected by a version of Tor that's known to select * or which was selected by a version of Tor that's known to select
* entry guards badly. */ * entry guards badly. */
static int static int
remove_obsolete_entry_guards(void) remove_obsolete_entry_guards(time_t now)
{ {
int changed = 0, i; int changed = 0, i;
time_t now = time(NULL);
for (i = 0; i < smartlist_len(entry_guards); ++i) { for (i = 0; i < smartlist_len(entry_guards); ++i) {
entry_guard_t *entry = smartlist_get(entry_guards, i); entry_guard_t *entry = smartlist_get(entry_guards, i);
@ -3565,11 +3563,10 @@ remove_obsolete_entry_guards(void)
* long that we don't think they'll come up again. Return 1 if we * long that we don't think they'll come up again. Return 1 if we
* removed any, or 0 if we did nothing. */ * removed any, or 0 if we did nothing. */
static int static int
remove_dead_entry_guards(void) remove_dead_entry_guards(time_t now)
{ {
char dbuf[HEX_DIGEST_LEN+1]; char dbuf[HEX_DIGEST_LEN+1];
char tbuf[ISO_TIME_LEN+1]; char tbuf[ISO_TIME_LEN+1];
time_t now = time(NULL);
int i; int i;
int changed = 0; int changed = 0;
@ -3604,23 +3601,18 @@ remove_dead_entry_guards(void)
* think that things are unlisted. * think that things are unlisted.
*/ */
void void
entry_guards_compute_status(void) entry_guards_compute_status(or_options_t *options, time_t now)
{ {
time_t now;
int changed = 0; int changed = 0;
int severity = LOG_DEBUG; int severity = LOG_DEBUG;
or_options_t *options;
digestmap_t *reasons; digestmap_t *reasons;
if (! entry_guards) if (! entry_guards)
return; return;
options = get_options();
if (options->EntryNodes) /* reshuffle the entry guard list if needed */ if (options->EntryNodes) /* reshuffle the entry guard list if needed */
entry_nodes_should_be_added(); entry_nodes_should_be_added();
now = time(NULL);
reasons = digestmap_new(); reasons = digestmap_new();
SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry) SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, entry)
{ {
@ -3636,7 +3628,7 @@ entry_guards_compute_status(void)
} }
SMARTLIST_FOREACH_END(entry); SMARTLIST_FOREACH_END(entry);
if (remove_dead_entry_guards()) if (remove_dead_entry_guards(now))
changed = 1; changed = 1;
severity = changed ? LOG_DEBUG : LOG_INFO; severity = changed ? LOG_DEBUG : LOG_INFO;
@ -3801,9 +3793,8 @@ entry_nodes_should_be_added(void)
/** Add all nodes in EntryNodes that aren't currently guard nodes to the list /** Add all nodes in EntryNodes that aren't currently guard nodes to the list
* of guard nodes, at the front. */ * of guard nodes, at the front. */
static void static void
entry_guards_prepend_from_config(void) entry_guards_prepend_from_config(or_options_t *options)
{ {
or_options_t *options = get_options();
smartlist_t *entry_routers, *entry_fps; smartlist_t *entry_routers, *entry_fps;
smartlist_t *old_entry_guards_on_list, *old_entry_guards_not_on_list; smartlist_t *old_entry_guards_on_list, *old_entry_guards_not_on_list;
tor_assert(entry_guards); tor_assert(entry_guards);
@ -3931,11 +3922,11 @@ choose_random_entry(cpath_build_state_t *state)
entry_guards = smartlist_create(); entry_guards = smartlist_create();
if (should_add_entry_nodes) if (should_add_entry_nodes)
entry_guards_prepend_from_config(); entry_guards_prepend_from_config(options);
if (!entry_list_is_constrained(options) && if (!entry_list_is_constrained(options) &&
smartlist_len(entry_guards) < options->NumEntryGuards) smartlist_len(entry_guards) < options->NumEntryGuards)
pick_entry_guards(); pick_entry_guards(options);
retry: retry:
smartlist_clear(live_entry_guards); smartlist_clear(live_entry_guards);
@ -4164,7 +4155,7 @@ entry_guards_parse_state(or_state_t *state, int set, char **msg)
entry_guards_dirty = 0; entry_guards_dirty = 0;
/* XXX022 hand new_entry_guards to this func, and move it up a /* XXX022 hand new_entry_guards to this func, and move it up a
* few lines, so we don't have to re-dirty it */ * few lines, so we don't have to re-dirty it */
if (remove_obsolete_entry_guards()) if (remove_obsolete_entry_guards(now))
entry_guards_dirty = 1; entry_guards_dirty = 1;
} }
digestmap_free(added_by, _tor_free); digestmap_free(added_by, _tor_free);
@ -4469,9 +4460,8 @@ retry_bridge_descriptor_fetch_directly(const char *digest)
* descriptor, fetch a new copy of its descriptor -- either directly * descriptor, fetch a new copy of its descriptor -- either directly
* from the bridge or via a bridge authority. */ * from the bridge or via a bridge authority. */
void void
fetch_bridge_descriptors(time_t now) fetch_bridge_descriptors(or_options_t *options, time_t now)
{ {
or_options_t *options = get_options();
int num_bridge_auths = get_n_authorities(BRIDGE_AUTHORITY); int num_bridge_auths = get_n_authorities(BRIDGE_AUTHORITY);
int ask_bridge_directly; int ask_bridge_directly;
int can_use_bridge_authority; int can_use_bridge_authority;

View File

@ -49,7 +49,7 @@ void extend_info_free(extend_info_t *info);
routerinfo_t *build_state_get_exit_router(cpath_build_state_t *state); routerinfo_t *build_state_get_exit_router(cpath_build_state_t *state);
const char *build_state_get_exit_nickname(cpath_build_state_t *state); const char *build_state_get_exit_nickname(cpath_build_state_t *state);
void entry_guards_compute_status(void); void entry_guards_compute_status(or_options_t *options, time_t now);
int entry_guard_register_connect_status(const char *digest, int succeeded, int entry_guard_register_connect_status(const char *digest, int succeeded,
int mark_relay_status, time_t now); int mark_relay_status, time_t now);
void entry_nodes_should_be_added(void); void entry_nodes_should_be_added(void);
@ -68,7 +68,7 @@ learned_router_identity(tor_addr_t *addr, uint16_t port, const char *digest);
void bridge_add_from_config(const tor_addr_t *addr, uint16_t port, void bridge_add_from_config(const tor_addr_t *addr, uint16_t port,
char *digest); char *digest);
void retry_bridge_descriptor_fetch_directly(const char *digest); void retry_bridge_descriptor_fetch_directly(const char *digest);
void fetch_bridge_descriptors(time_t now); void fetch_bridge_descriptors(or_options_t *options, time_t now);
void learned_bridge_descriptor(routerinfo_t *ri, int from_cache); void learned_bridge_descriptor(routerinfo_t *ri, int from_cache);
int any_bridge_descriptors_known(void); int any_bridge_descriptors_known(void);
int any_pending_bridge_descriptor_fetches(void); int any_pending_bridge_descriptor_fetches(void);

View File

@ -710,7 +710,7 @@ directory_info_has_arrived(time_t now, int from_cache)
/* if we have enough dir info, then update our guard status with /* if we have enough dir info, then update our guard status with
* whatever we just learned. */ * whatever we just learned. */
entry_guards_compute_status(); entry_guards_compute_status(options, now);
/* Don't even bother trying to get extrainfo until the rest of our /* Don't even bother trying to get extrainfo until the rest of our
* directory info is up-to-date */ * directory info is up-to-date */
if (options->DownloadExtraInfo) if (options->DownloadExtraInfo)
@ -912,7 +912,7 @@ run_scheduled_events(time_t now)
update_router_descriptor_downloads(now); update_router_descriptor_downloads(now);
update_extrainfo_downloads(now); update_extrainfo_downloads(now);
if (options->UseBridges) if (options->UseBridges)
fetch_bridge_descriptors(now); fetch_bridge_descriptors(options, now);
if (router_have_minimum_dir_info()) if (router_have_minimum_dir_info())
time_to_try_getting_descriptors = now + LAZY_DESCRIPTOR_RETRY_INTERVAL; time_to_try_getting_descriptors = now + LAZY_DESCRIPTOR_RETRY_INTERVAL;
else else