summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-12-15 20:44:15 +0000
committerNick Mathewson <nickm@torproject.org>2005-12-15 20:44:15 +0000
commitce71b17224a10dec18c4d54f5d2bb00ffe368030 (patch)
tree62484cb43ed63a9f5ddd71d7b62753c816a245a6 /src/or
parent7b2b9af4eb4711846a2150fc34dc59a6ef8aaa5f (diff)
downloadtor-ce71b17224a10dec18c4d54f5d2bb00ffe368030.tar.gz
tor-ce71b17224a10dec18c4d54f5d2bb00ffe368030.zip
Clean fake_status a bit. Switch from has_fetched_directory to have_minimum_dir_info, and make the latter function smarter.
svn:r5591
Diffstat (limited to 'src/or')
-rw-r--r--src/or/circuituse.c12
-rw-r--r--src/or/directory.c4
-rw-r--r--src/or/main.c20
-rw-r--r--src/or/or.h5
-rw-r--r--src/or/routerlist.c53
5 files changed, 55 insertions, 39 deletions
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 8568e3eb36..5ac6442326 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -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.
*/
diff --git a/src/or/directory.c b/src/or/directory.c
index b2244e53f7..db4e0f0649 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -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. */
}
}
diff --git a/src/or/main.c b/src/or/main.c
index ba4cd92a21..77c9820d1b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -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,
diff --git a/src/or/or.h b/src/or/or.h
index e716c209b0..29fa512b92 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -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);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 408a712350..8d8523178d 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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