summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-01-10 07:21:01 +0000
committerRoger Dingledine <arma@torproject.org>2006-01-10 07:21:01 +0000
commitc8e6003412300a235ae51d959d8a9bea63724a90 (patch)
treeb83a0fdb682a19a03337ee28826b68d1d1e92c03
parent43a4f8c7f301a9e83214b9cbff856b378edfe66b (diff)
downloadtor-c8e6003412300a235ae51d959d8a9bea63724a90.tar.gz
tor-c8e6003412300a235ae51d959d8a9bea63724a90.zip
balance the reachability testing so a smidgen of it happens
every 10 seconds. this way we don't try to do 500 tls's at once every 20 minutes. svn:r5763
-rw-r--r--src/or/dirserv.c4
-rw-r--r--src/or/main.c17
-rw-r--r--src/or/or.h2
-rw-r--r--src/or/router.c19
4 files changed, 25 insertions, 17 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 95cb6ae019..097dad7e7d 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -686,8 +686,8 @@ list_single_server_status(routerinfo_t *desc, int is_live)
return tor_strdup(buf);
}
-#define REACHABLE_TIMEOUT (60*60) /* an hour */
-/* Make sure this is 3 times the value of get_dir_fetch_period() */
+#define REACHABLE_TIMEOUT (90*60) /* ninety minutes */
+/* Make sure this is at least 3 times the value of get_dir_fetch_period() */
/** Treat a router as alive if
* - It's me, and I'm not hibernating.
diff --git a/src/or/main.c b/src/or/main.c
index 81e0770d6c..adddcbfb10 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -523,7 +523,7 @@ directory_all_unreachable(time_t now)
}
/**
- * Return the interval to wait betweeen directory downloads, in seconds.
+ * Return the interval to wait between directory downloads, in seconds.
*/
static INLINE int
get_dir_fetch_period(or_options_t *options)
@@ -573,7 +573,7 @@ directory_info_has_arrived(time_t now, int from_cache)
if (server_mode(options) &&
!we_are_hibernating()) { /* connect to the appropriate routers */
if (!authdir_mode(options))
- router_retry_connections(0);
+ router_retry_connections(0, 1);
if (!from_cache)
consider_testing_reachability();
}
@@ -768,6 +768,11 @@ run_scheduled_events(time_t now)
if (accounting_is_enabled(options))
accounting_run_housekeeping(now);
+ if (now % 10 == 0 && authdir_mode(options) && !we_are_hibernating()) {
+ /* try to determine reachability */
+ router_retry_connections(1, 0);
+ }
+
/** 2. Periodically, we consider getting a new directory, getting a
* new running-routers list, and/or force-uploading our descriptor
* (if we've passed our internal checks). */
@@ -776,12 +781,6 @@ run_scheduled_events(time_t now)
routerlist_remove_old_routers();
networkstatus_list_clean(now);
- if (authdir_mode(options)) {
- if (!we_are_hibernating()) { /* try to determine reachability */
- router_retry_connections(1);
- }
- }
-
/* Only caches actually need to fetch directories now. */
if (options->DirPort && !options->V1AuthoritativeDir) {
directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL, 1);
@@ -1108,7 +1107,7 @@ do_main_loop(void)
if (authdir_mode(get_options())) {
/* the directory is already here, run startup things */
- router_retry_connections(1);
+ router_retry_connections(1, 1);
}
if (server_mode(get_options())) {
diff --git a/src/or/or.h b/src/or/or.h
index 80e5cf91f4..49f3bace51 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2195,7 +2195,7 @@ int server_mode(or_options_t *options);
int advertised_server_mode(void);
int proxy_mode(or_options_t *options);
-void router_retry_connections(int force);
+void router_retry_connections(int testing_reachability, int try_all);
int router_is_clique_mode(routerinfo_t *router);
void router_upload_dir_desc_to_dirservers(int force);
void mark_my_descriptor_dirty_if_older_than(time_t when);
diff --git a/src/or/router.c b/src/or/router.c
index f3600ec94e..916b18a119 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -610,15 +610,20 @@ consider_publishable_server(time_t now, int force)
* other ORs we know about. Otherwise, open connections to those we
* think are in clique mode.
*
- * If <b>force</b> is zero, only open the connection if we don't already
- * have one.
+ * If <b>testing_reachability</b> is 0, try to open the connections
+ * but only if we don't already have one. If it's 1, then we're an
+ * auth dir server, and we should try to connect regardless of
+ * whether we already have a connection open -- but if <b>try_all</b>
+ * is 0, we want to load balance such that we only try a few connections
+ * per call.
*/
void
-router_retry_connections(int force)
+router_retry_connections(int testing_reachability, int try_all)
{
time_t now = time(NULL);
routerlist_t *rl = router_get_routerlist();
or_options_t *options = get_options();
+ static char ctr = 0;
tor_assert(server_mode(options));
@@ -628,8 +633,10 @@ router_retry_connections(int force)
continue;
if (!clique_mode(options) && !router_is_clique_mode(router))
continue;
- if (force ||
- !connection_or_get_by_identity_digest(id_digest)) {
+ if ((testing_reachability &&
+ (try_all || (((uint8_t)id_digest[0]) % 128) == ctr)) ||
+ (!testing_reachability &&
+ !connection_or_get_by_identity_digest(id_digest))) {
debug(LD_OR,"%sconnecting to %s at %s:%u.",
clique_mode(options) ? "(forced) " : "",
router->nickname, router->address, router->or_port);
@@ -640,6 +647,8 @@ router_retry_connections(int force)
id_digest);
}
});
+ if (testing_reachability && !try_all) /* increment ctr */
+ ctr = (ctr + 1) % 128;
}
/** Return true iff this OR should try to keep connections open to all