mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 14:51:11 +01:00
Clean fake_status a bit. Switch from has_fetched_directory to have_minimum_dir_info, and make the latter function smarter.
svn:r5591
This commit is contained in:
parent
7b2b9af4eb
commit
ce71b17224
5 changed files with 55 additions and 39 deletions
|
@ -19,7 +19,6 @@ const char circuituse_c_id[] =
|
|||
/********* START VARIABLES **********/
|
||||
|
||||
extern circuit_t *global_circuitlist; /* from circuitlist.c */
|
||||
extern int has_fetched_directory; /* from main.c */
|
||||
|
||||
/********* END VARIABLES ************/
|
||||
|
||||
|
@ -423,7 +422,7 @@ circuit_build_needed_circs(time_t now)
|
|||
connection_ap_attach_pending();
|
||||
|
||||
/* make sure any hidden services have enough intro points */
|
||||
if (has_fetched_directory)
|
||||
if (router_have_minimum_dir_info())
|
||||
rend_services_introduce();
|
||||
|
||||
if (time_to_new_circuit < now) {
|
||||
|
@ -769,8 +768,9 @@ circuit_launch_by_extend_info(uint8_t purpose, extend_info_t *extend_info,
|
|||
{
|
||||
circuit_t *circ;
|
||||
|
||||
if (!has_fetched_directory) {
|
||||
debug(LD_CIRC,"Haven't fetched directory yet; canceling circuit launch.");
|
||||
if (!router_have_minimum_dir_info()) {
|
||||
debug(LD_CIRC,"Haven't fetched enough directory info yet; canceling "
|
||||
"circuit launch.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -899,7 +899,7 @@ circuit_get_open_circ_or_launch(connection_t *conn,
|
|||
return 1; /* we're happy */
|
||||
}
|
||||
|
||||
if (!has_fetched_directory) {
|
||||
if (!router_have_minimum_dir_info()) {
|
||||
if (!connection_get_by_type(CONN_TYPE_DIR)) {
|
||||
notice(LD_APP|LD_DIR,"Application request when we're believed to be "
|
||||
"offline. Optimistically trying directory fetches again.");
|
||||
|
@ -910,7 +910,7 @@ circuit_get_open_circ_or_launch(connection_t *conn,
|
|||
/* XXXX011 NM This should be a generic "retry all directory fetches". */
|
||||
directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
|
||||
}
|
||||
/* the stream will be dealt with when has_fetched_directory 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()
|
||||
* kills it.
|
||||
*/
|
||||
|
|
|
@ -212,7 +212,9 @@ directory_get_from_dirserver(uint8_t purpose, const char *resource,
|
|||
/* anybody with a non-zero dirport will do. Disregard firewalls. */
|
||||
rs = router_pick_directory_server(1, 0, need_v2_support,
|
||||
retry_if_no_servers);
|
||||
/* XXXX If no rs, fall back to trusted dir servers? -NM */
|
||||
/* If we have any hope of building an indirect conn, we know some router
|
||||
* decriptors. If (rs==NULL), we can't build circuits anyway, so
|
||||
* there's no point in falling back to the authorities in this case. */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,11 +57,6 @@ static smartlist_t *closeable_connection_lst = NULL;
|
|||
|
||||
static int nfds=0; /**< Number of connections currently active. */
|
||||
|
||||
/** We set this to 1 when we've fetched a dir, to know whether to complain
|
||||
* yet about unrecognized nicknames in entrynodes, exitnodes, etc.
|
||||
* Also, we don't try building circuits unless this is 1. */
|
||||
int has_fetched_directory=0;
|
||||
|
||||
/** We set this to 1 when we've opened a circuit, so we can print a log
|
||||
* entry to inform the user that Tor is working. */
|
||||
int has_completed_circuit=0;
|
||||
|
@ -513,9 +508,7 @@ void
|
|||
directory_all_unreachable(time_t now)
|
||||
{
|
||||
connection_t *conn;
|
||||
/* XXXX011 NM Update this to reflect new directories? */
|
||||
|
||||
has_fetched_directory=0;
|
||||
stats_n_seconds_working=0; /* reset it */
|
||||
|
||||
while ((conn = connection_get_by_type_state(CONN_TYPE_AP,
|
||||
|
@ -574,13 +567,6 @@ directory_info_has_arrived(time_t now, int from_cache)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!has_fetched_directory) {
|
||||
log(LOG_NOTICE, LD_DIR, "We have enough directory information to "
|
||||
"build circuits.");
|
||||
}
|
||||
|
||||
has_fetched_directory=1;
|
||||
|
||||
if (server_mode(options) &&
|
||||
!we_are_hibernating()) { /* connect to the appropriate routers */
|
||||
if (!authdir_mode(options))
|
||||
|
@ -704,6 +690,7 @@ run_scheduled_events(time_t now)
|
|||
static time_t time_to_add_entropy = 0;
|
||||
or_options_t *options = get_options();
|
||||
int i;
|
||||
int have_dir_info;
|
||||
|
||||
/** 0. See if we've been asked to shut down and our timeout has
|
||||
* expired; or if our bandwidth limits are exhausted and we
|
||||
|
@ -861,7 +848,8 @@ run_scheduled_events(time_t now)
|
|||
* that became dirty more than MaxCircuitDirtiness seconds ago,
|
||||
* and we make a new circ if there are no clean circuits.
|
||||
*/
|
||||
if (has_fetched_directory && !we_are_hibernating())
|
||||
have_dir_info = router_have_minimum_dir_info();
|
||||
if (have_dir_info && !we_are_hibernating())
|
||||
circuit_build_needed_circs(now);
|
||||
|
||||
/** 5. We do housekeeping for each connection... */
|
||||
|
@ -883,7 +871,7 @@ run_scheduled_events(time_t now)
|
|||
circuit_close_all_marked();
|
||||
|
||||
/** 7. And upload service descriptors if necessary. */
|
||||
if (has_fetched_directory && !we_are_hibernating())
|
||||
if (have_dir_info && !we_are_hibernating())
|
||||
rend_consider_services_upload(now);
|
||||
|
||||
/** 8. and blow away any connections that need to die. have to do this now,
|
||||
|
|
|
@ -2195,7 +2195,10 @@ typedef struct trusted_dir_server_t {
|
|||
int n_networkstatus_failures; /**< How many times have we asked for this
|
||||
* server's network-status unsuccessfully? */
|
||||
routerstatus_t fake_status; /**< Used when we need to pass this trusted
|
||||
* dir_server_t as a routerstatus_t. */
|
||||
* dir_server_t to directory_initiate_command_*
|
||||
* as a routerstatus_t. Not updated by the
|
||||
* router-status management code!
|
||||
**/
|
||||
} trusted_dir_server_t;
|
||||
|
||||
int router_reload_router_list(void);
|
||||
|
|
|
@ -46,8 +46,6 @@ static smartlist_t *trusted_dir_servers = NULL;
|
|||
/** Global list of all of the routers that we know about. */
|
||||
static routerlist_t *routerlist = NULL;
|
||||
|
||||
extern int has_fetched_directory; /* from main.c */
|
||||
|
||||
/** Global list of all of the current network_status documents that we know
|
||||
* about. This list is kept sorted by published_on. */
|
||||
static smartlist_t *networkstatus_list = NULL;
|
||||
|
@ -497,8 +495,12 @@ mark_all_trusteddirservers_up(void)
|
|||
if (trusted_dir_servers) {
|
||||
SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, dir,
|
||||
{
|
||||
local_routerstatus_t *rs;
|
||||
dir->is_running = 1;
|
||||
dir->n_networkstatus_failures = 0;
|
||||
rs = router_get_combined_status_by_digest(dir->digest);
|
||||
if (rs)
|
||||
rs->status.is_running = 1;
|
||||
});
|
||||
}
|
||||
last_networkstatus_download_attempted = 0;
|
||||
|
@ -573,6 +575,7 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list,
|
|||
{
|
||||
routerinfo_t *router;
|
||||
smartlist_t *nickname_list;
|
||||
int have_dir_info = router_have_minimum_dir_info();
|
||||
|
||||
if (!list)
|
||||
return; /* nothing to do */
|
||||
|
@ -607,7 +610,7 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list,
|
|||
}
|
||||
} else {
|
||||
if (!warned) {
|
||||
log_fn(has_fetched_directory ? LOG_WARN : LOG_INFO, LD_CONFIG,
|
||||
log_fn(have_dir_info ? LOG_WARN : LOG_INFO, LD_CONFIG,
|
||||
"Nickname list includes '%s' which isn't a known router.",nick);
|
||||
smartlist_add(warned_nicknames, tor_strdup(nick));
|
||||
}
|
||||
|
@ -2559,10 +2562,6 @@ add_trusted_dir_server(const char *nickname, const char *address,
|
|||
strlcpy(ent->fake_status.nickname, nickname,
|
||||
sizeof(ent->fake_status.nickname));
|
||||
ent->fake_status.dir_port = ent->dir_port;
|
||||
ent->fake_status.is_running = 1;
|
||||
ent->fake_status.is_named = 1;
|
||||
ent->fake_status.is_valid = 1;
|
||||
ent->fake_status.is_v2_dir = 1;
|
||||
|
||||
smartlist_add(trusted_dir_servers, ent);
|
||||
}
|
||||
|
@ -3308,19 +3307,43 @@ update_router_descriptor_downloads(time_t now)
|
|||
/** Return true iff we have enough networkstatus and router information to
|
||||
* start building circuits. Right now, this means "at least 2 networkstatus
|
||||
* documents, and at least 1/4 of expected routers." */
|
||||
//XXX should consider whether we have enough exiting nodes here.
|
||||
//and also consider if they're too "old"?
|
||||
int
|
||||
router_have_minimum_dir_info(void)
|
||||
{
|
||||
int tot = 0, avg;
|
||||
if (!networkstatus_list || smartlist_len(networkstatus_list)<2 ||
|
||||
!routerlist)
|
||||
return 0;
|
||||
int tot = 0, any_running = 0;
|
||||
int n_ns, res, avg;
|
||||
static int have_enough = 0;
|
||||
if (!networkstatus_list || !routerlist) {
|
||||
res = 0;
|
||||
goto done;
|
||||
}
|
||||
n_ns = smartlist_len(networkstatus_list);
|
||||
if (n_ns<2) {
|
||||
res = 0;
|
||||
goto done;
|
||||
}
|
||||
SMARTLIST_FOREACH(networkstatus_list, networkstatus_t *, ns,
|
||||
tot += smartlist_len(ns->entries));
|
||||
avg = tot / smartlist_len(networkstatus_list);
|
||||
return smartlist_len(routerlist->routers) > (avg/4);
|
||||
avg = tot / n_ns;
|
||||
SMARTLIST_FOREACH(routerstatus_list, local_routerstatus_t *, rs,
|
||||
{
|
||||
if (rs->status.is_running) {
|
||||
any_running = 1;
|
||||
break;
|
||||
}
|
||||
});
|
||||
res = smartlist_len(routerlist->routers) > (avg/4) && any_running;
|
||||
done:
|
||||
if (res && !have_enough) {
|
||||
log(LOG_NOTICE, LD_DIR,
|
||||
"We now have enough directory information to build circuits.");
|
||||
}
|
||||
if (!res && !have_enough) {
|
||||
log(LOG_NOTICE, LD_DIR, "Our directory information is no longer up-to-date "
|
||||
"enough to build circuits.");
|
||||
}
|
||||
have_enough = res;
|
||||
return res;
|
||||
}
|
||||
|
||||
/** Reset the descriptor download failure count on all routers, so that we
|
||||
|
|
Loading…
Add table
Reference in a new issue