make progress towards retrying our bridges when they're all

down and we get a new socks request


svn:r10967
This commit is contained in:
Roger Dingledine 2007-07-29 04:38:21 +00:00
parent afcc3a4785
commit eca2a30060
3 changed files with 47 additions and 15 deletions

View File

@ -294,7 +294,7 @@ origin_circuit_init(uint8_t purpose, int onehop_tunnel,
return circ; return circ;
} }
/** Build a new circuit for <b>purpose</b>. If <b>info</b> /** Build a new circuit for <b>purpose</b>. If <b>exit</b>
* is defined, then use that as your exit router, else choose a suitable * is defined, then use that as your exit router, else choose a suitable
* exit node. * exit node.
* *
@ -2860,17 +2860,19 @@ learned_bridge_descriptor(routerinfo_t *ri)
int int
any_bridge_descriptors_known(void) any_bridge_descriptors_known(void)
{ {
tor_assert(get_options()->UseBridges);
return choose_random_entry(NULL)!=NULL ? 1 : 0; return choose_random_entry(NULL)!=NULL ? 1 : 0;
} }
#if 0
/** Return 1 if we have at least one descriptor for a bridge and /** Return 1 if we have at least one descriptor for a bridge and
* all descriptors we know are down. Else return 0. */ * all descriptors we know are down. Else return 0. If <b>act</b> is
int * 1, then mark the down bridges up; else just observe and report. */
all_bridges_down(void) static int
bridges_retry_helper(int act)
{ {
routerinfo_t *ri; routerinfo_t *ri;
int any_known = 0; int any_known = 0;
int any_running = 0;
if (!entry_guards) if (!entry_guards)
entry_guards = smartlist_create(); entry_guards = smartlist_create();
SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e, SMARTLIST_FOREACH(entry_guards, entry_guard_t *, e,
@ -2879,12 +2881,31 @@ all_bridges_down(void)
if (ri && ri->purpose == ROUTER_PURPOSE_BRIDGE) { if (ri && ri->purpose == ROUTER_PURPOSE_BRIDGE) {
any_known = 1; any_known = 1;
if (ri->is_running) if (ri->is_running)
return 0; /* some bridge is both known and running */ any_running = 1; /* some bridge is both known and running */
else if (act) { /* mark it for retry */
ri->is_running = 1;
e->can_retry = 1;
e->bad_since = 0;
}
} }
}); });
return any_known; return any_known && !any_running;
}
/** Do we know any descriptors for our bridges, and are they all
* down? */
int
bridges_should_be_retried(void)
{
return bridges_retry_helper(0);
}
/** Mark all down known bridges up. */
void
bridges_retry_all(void)
{
bridges_retry_helper(1);
} }
#endif
/** Release all storage held by the list of entry guards and related /** Release all storage held by the list of entry guards and related
* memory structs. */ * memory structs. */

View File

@ -813,8 +813,9 @@ circuit_launch_by_router(uint8_t purpose, int onehop_tunnel,
return circ; return circ;
} }
/** Launch a new circuit with purpose <b>purpose</b> and exit node <b>info</b> /** Launch a new circuit with purpose <b>purpose</b> and exit node
* (or NULL to select a random exit node). If <b>need_uptime</b> is true, * <b>extend_info</b> (or NULL to select a random exit node).
* If <b>need_uptime</b> is true,
* choose among routers with high uptime. If <b>need_capacity</b> is true, * choose among routers with high uptime. If <b>need_capacity</b> is true,
* choose among routers with high bandwidth. If <b>internal</b> is true, the * choose among routers with high bandwidth. If <b>internal</b> is true, the
* last hop need not be an exit node. Return the newly allocated circuit on * last hop need not be an exit node. Return the newly allocated circuit on
@ -942,6 +943,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
int check_exit_policy; int check_exit_policy;
int need_uptime, need_internal; int need_uptime, need_internal;
int want_onehop; int want_onehop;
or_options_t *options = get_options();
tor_assert(conn); tor_assert(conn);
tor_assert(circp); tor_assert(circp);
@ -952,7 +954,7 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
want_onehop = conn->socks_request->command == SOCKS_COMMAND_CONNECT_DIR; want_onehop = conn->socks_request->command == SOCKS_COMMAND_CONNECT_DIR;
need_uptime = (conn->socks_request->command == SOCKS_COMMAND_CONNECT) && need_uptime = (conn->socks_request->command == SOCKS_COMMAND_CONNECT) &&
smartlist_string_num_isin(get_options()->LongLivedPorts, smartlist_string_num_isin(options->LongLivedPorts,
conn->socks_request->port); conn->socks_request->port);
need_internal = desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL; need_internal = desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL;
@ -966,10 +968,17 @@ circuit_get_open_circ_or_launch(edge_connection_t *conn,
if (!want_onehop && !router_have_minimum_dir_info()) { if (!want_onehop && !router_have_minimum_dir_info()) {
if (!connection_get_by_type(CONN_TYPE_DIR)) { if (!connection_get_by_type(CONN_TYPE_DIR)) {
log_notice(LD_APP|LD_DIR, if (options->UseBridges && bridges_should_be_retried()) {
"Application request when we're believed to be " log_notice(LD_APP|LD_DIR,
"offline. Optimistically trying directory fetches again."); "Application request when we're believed to be "
routerlist_retry_directory_downloads(time(NULL)); "offline. Optimistically trying known bridges again.");
bridges_retry_all();
} else if (!options->UseBridges || any_bridge_descriptors_known()) {
log_notice(LD_APP|LD_DIR,
"Application request when we're believed to be "
"offline. Optimistically trying directory fetches again.");
routerlist_retry_directory_downloads(time(NULL));
}
} }
/* the stream will be dealt with when router_have_minimum_dir_info becomes /* the stream will be dealt with when router_have_minimum_dir_info becomes
* 1, or when all directory attempts fail and directory_all_unreachable() * 1, or when all directory attempts fail and directory_all_unreachable()

View File

@ -2264,6 +2264,8 @@ void bridge_add_from_config(uint32_t addr, uint16_t port, char *digest);
void fetch_bridge_descriptors(time_t now); void fetch_bridge_descriptors(time_t now);
void learned_bridge_descriptor(routerinfo_t *ri); void learned_bridge_descriptor(routerinfo_t *ri);
int any_bridge_descriptors_known(void); int any_bridge_descriptors_known(void);
int bridges_should_be_retried(void);
void bridges_retry_all(void);
void entry_guards_free_all(void); void entry_guards_free_all(void);