From 05d0b705734b43d1986be2b999de904676f854c0 Mon Sep 17 00:00:00 2001 From: Roger Dingledine Date: Tue, 4 Jul 2006 03:31:27 +0000 Subject: [PATCH] Get rid of the router_retry_connections notion. Now routers no longer try to rebuild long-term connections to directory authorities, and directory authorities no longer try to rebuild long-term connections to all servers. We still don't hang up connections in these two cases though -- we need to look at it more carefully to avoid flapping, and we likely need to wait til 0.1.1.x is obsolete. svn:r6712 --- src/or/dirserv.c | 33 +++++++++++++++++++++++ src/or/main.c | 14 ++++------ src/or/or.h | 2 +- src/or/router.c | 68 ++++++------------------------------------------ 4 files changed, 47 insertions(+), 70 deletions(-) diff --git a/src/or/dirserv.c b/src/or/dirserv.c index f36dee5cb9..ed70440c57 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -1784,6 +1784,39 @@ dirserv_orconn_tls_done(const char *address, } } +/** Auth dir server only: if try_all is 1, launch connections to + * all known routers; else we want to load balance such that we only + * try a few connections per call. + * + * The load balancing is such that if we get called once every ten + * seconds, we will cycle through all the tests in 1280 seconds (a + * bit over 20 minutes). + */ +void +dirserv_test_reachability(int try_all) +{ + time_t now = time(NULL); + routerlist_t *rl = router_get_routerlist(); + static char ctr = 0; + + SMARTLIST_FOREACH(rl->routers, routerinfo_t *, router, { + const char *id_digest = router->cache_info.identity_digest; + if (router_is_me(router)) + continue; + if (try_all || (((uint8_t)id_digest[0]) % 128) == ctr) { + log_debug(LD_OR,"Testing reachability of %s at %s:%u.", + router->nickname, router->address, router->or_port); + /* Remember when we started trying to determine reachability */ + if (!router->testing_since) + router->testing_since = now; + connection_or_connect(router->addr, router->or_port, + id_digest); + } + }); + if (!try_all) /* increment ctr */ + ctr = (ctr + 1) % 128; +} + /** When we're spooling data onto our outbuf, add more whenever we dip * below this threshold. */ #define DIRSERV_BUFFER_MIN 16384 diff --git a/src/or/main.c b/src/or/main.c index d331c961cc..bb562a5723 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -568,13 +568,9 @@ directory_info_has_arrived(time_t now, int from_cache) return; } - if (server_mode(options) && - !we_are_hibernating()) { /* connect to the appropriate routers */ - if (!authdir_mode(options)) - router_retry_connections(0, 1); - if (!from_cache && has_completed_circuit) - consider_testing_reachability(); - } + if (server_mode(options) && !we_are_hibernating() && + !from_cache && has_completed_circuit) + consider_testing_reachability(); } /** Perform regular maintenance tasks for a single connection. This @@ -782,7 +778,7 @@ run_scheduled_events(time_t now) if (now % 10 == 0 && authdir_mode(options) && !we_are_hibernating()) { /* try to determine reachability */ - router_retry_connections(1, 0); + dirserv_test_reachability(0); } /** 2. Periodically, we consider getting a new directory, getting a @@ -1134,7 +1130,7 @@ do_main_loop(void) if (authdir_mode(get_options())) { /* the directory is already here, run startup things */ - router_retry_connections(1, 1); + dirserv_test_reachability(1); } if (server_mode(get_options())) { diff --git a/src/or/or.h b/src/or/or.h index 113fda026f..f419a7a259 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -1956,6 +1956,7 @@ void dirserv_orconn_tls_done(const char *address, const char *digest_rcvd, const char *nickname, int as_advertised); +void dirserv_test_reachability(int try_all); int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg, int complain); int dirserv_would_reject_router(routerstatus_t *rs); @@ -2271,7 +2272,6 @@ int server_mode(or_options_t *options); int advertised_server_mode(void); int proxy_mode(or_options_t *options); -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 43a1834dd0..813069803d 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -372,8 +372,7 @@ init_keys(void) (uint16_t)options->DirPort, digest, options->V1AuthoritativeDir); } - /* success */ - return 0; + return 0; /* success */ } /* Keep track of whether we should upload our server descriptor, @@ -385,13 +384,12 @@ static int can_reach_or_port = 0; /** Whether we can reach our DirPort from the outside. */ static int can_reach_dir_port = 0; -/** Return 1 if or port is known reachable; else return 0. */ +/** Return 1 if ORPort is known reachable; else return 0. */ int check_whether_orport_reachable(void) { or_options_t *options = get_options(); - return clique_mode(options) || - options->AssumeReachable || + return options->AssumeReachable || can_reach_or_port; } @@ -473,11 +471,10 @@ void router_orport_found_reachable(void) { if (!can_reach_or_port) { - if (!clique_mode(get_options())) - log_notice(LD_OR,"Self-testing indicates your ORPort is reachable from " - "the outside. Excellent.%s", - get_options()->PublishServerDescriptor ? - " Publishing server descriptor." : ""); + log_notice(LD_OR,"Self-testing indicates your ORPort is reachable from " + "the outside. Excellent.%s", + get_options()->PublishServerDescriptor ? + " Publishing server descriptor." : ""); can_reach_or_port = 1; mark_my_descriptor_dirty(); consider_publishable_server(1); @@ -611,58 +608,9 @@ consider_publishable_server(int force) } /* - * Clique maintenance + * Clique maintenance -- to be phased out. */ -/** OR only: if in clique mode, try to open connections to all of the - * other ORs we know about. Otherwise, open connections to those we - * think are in clique mode. - * - * If testing_reachability 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 try_all - * is 0, we want to load balance such that we only try a few connections - * per call. - * - * The load balancing is such that if we get called once every ten - * seconds, we will cycle through all the tests in 1280 seconds (a - * bit over 20 minutes). - */ -void -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)); - - SMARTLIST_FOREACH(rl->routers, routerinfo_t *, router, { - const char *id_digest = router->cache_info.identity_digest; - if (router_is_me(router)) - continue; - if (!clique_mode(options) && !router_is_clique_mode(router)) - continue; - if ((testing_reachability && - (try_all || (((uint8_t)id_digest[0]) % 128) == ctr)) || - (!testing_reachability && - !connection_or_get_by_identity_digest(id_digest))) { - log_debug(LD_OR,"%sconnecting to %s at %s:%u.", - clique_mode(options) ? "(forced) " : "", - router->nickname, router->address, router->or_port); - /* Remember when we started trying to determine reachability */ - if (!router->testing_since) - router->testing_since = now; - connection_or_connect(router->addr, router->or_port, - 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 * other ORs. */ int