aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2006-01-02 03:32:55 +0000
committerRoger Dingledine <arma@torproject.org>2006-01-02 03:32:55 +0000
commit2efa0567777fe269b396c08061736648152d20c8 (patch)
treeefb8d17bc134b4b941e91605a562c18116c6b48a
parent4868d77ab8e8cd1e31e6051822236749c9a8fee4 (diff)
downloadtor-2efa0567777fe269b396c08061736648152d20c8.tar
tor-2efa0567777fe269b396c08061736648152d20c8.tar.gz
make the "stable" flag in network-status be the median of the uptimes
of running valid servers. that way the cutoff adapts to the stability of the network as a whole. svn:r5693
-rw-r--r--src/or/dirserv.c62
-rw-r--r--src/or/or.h9
2 files changed, 54 insertions, 17 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index a787f919b..5b119deff 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1220,6 +1220,8 @@ should_generate_v2_networkstatus(void)
the_v2_networkstatus_is_dirty + DIR_REGEN_SLACK_TIME < time(NULL);
}
+long stable_uptime = 0; /* start at a safe value */
+
/** Return 1 if <b>router</b> is not suitable for these parameters, else 0.
* If <b>need_uptime</b> is non-zero, we require a minimum uptime.
* If <b>need_capacity</b> is non-zero, we require a minimum advertised
@@ -1229,7 +1231,7 @@ static int
dirserv_thinks_router_is_unreliable(routerinfo_t *router,
int need_uptime, int need_capacity)
{
- if (need_uptime && router->uptime < ROUTER_REQUIRED_MIN_UPTIME)
+ if (need_uptime && router->uptime < stable_uptime)
return 1;
if (need_capacity &&
router->bandwidthcapacity < ROUTER_REQUIRED_MIN_BANDWIDTH)
@@ -1237,6 +1239,42 @@ dirserv_thinks_router_is_unreliable(routerinfo_t *router,
return 0;
}
+static int
+_compare_longs(const void **a, const void **b)
+{
+ long first = **(long **)a, second = **(long **)b;
+ if (first < second) return -1;
+ if (first > second) return 1;
+ return 0;
+}
+
+/** Look through the routerlist, and assign the median uptime
+ * of running verified servers to stable_uptime. */
+void
+dirserv_compute_stable_uptime(routerlist_t *rl)
+{
+ smartlist_t *uptimes = smartlist_create();
+ long *up;
+
+ SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
+ if (ri->is_running && ri->is_verified) {
+ up = tor_malloc(sizeof(long));
+ *up = ri->uptime;
+ smartlist_add(uptimes, up);
+ }
+ });
+
+ smartlist_sort(uptimes, _compare_longs);
+
+ stable_uptime = *(long *)smartlist_get(uptimes,
+ smartlist_len(uptimes)/2);
+
+ info(LD_DIRSERV, "Uptime cutoff is %ld seconds.", stable_uptime);
+
+ SMARTLIST_FOREACH(uptimes, long *, up, tor_free(up));
+ smartlist_free(uptimes);
+}
+
/** For authoritative directories only: replace the contents of
* <b>the_v2_networkstatus</b> with a newly generated network status
* object. */
@@ -1325,11 +1363,21 @@ generate_v2_networkstatus(void)
outp = status + strlen(status);
endp = status + len;
+ /* precompute this part, since we need it to decide what "stable"
+ * means. */
+ SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
+ ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
+ });
+
+ dirserv_compute_stable_uptime(rl);
+
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
int f_exit = router_is_general_exit(ri);
- int f_stable = !dirserv_thinks_router_is_unreliable(ri, 1, 0);
- int f_fast = !dirserv_thinks_router_is_unreliable(ri, 0, 1);
- int f_running;
+ int f_stable = ri->is_stable =
+ !dirserv_thinks_router_is_unreliable(ri, 1, 0);
+ int f_fast = ri->is_fast =
+ !dirserv_thinks_router_is_unreliable(ri, 0, 1);
+ int f_running = ri->is_running; /* computed above */
int f_authority = router_digest_is_trusted_dir(
ri->cache_info.identity_digest);
int f_named = naming && ri->is_named;
@@ -1340,12 +1388,6 @@ generate_v2_networkstatus(void)
tor_version_as_new_as(ri->platform,"0.1.1.9-alpha");
char identity64[BASE64_DIGEST_LEN+1];
char digest64[BASE64_DIGEST_LEN+1];
- if (options->AuthoritativeDir) {
- ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
- ri->is_fast = f_fast;
- ri->is_stable = f_stable;
- }
- f_running = ri->is_running;
format_iso_time(published, ri->cache_info.published_on);
diff --git a/src/or/or.h b/src/or/or.h
index 5a284f1c3..8aa3c6e33 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -2244,15 +2244,10 @@ void add_nickname_list_to_smartlist(smartlist_t *sl, const char *list,
routerinfo_t *routerlist_find_my_routerinfo(void);
int exit_policy_implicitly_allows_local_networks(addr_policy_t *policy,
int warn);
-
-/** How many seconds a router must be up before we'll use it for
- * reliability-critical node positions.
- */
-#define ROUTER_REQUIRED_MIN_UPTIME (24*3600) /* a day */
-#define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
-
routerinfo_t *router_find_exact_exit_enclave(const char *address,
uint16_t port);
+
+#define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
int router_is_unreliable(routerinfo_t *router, int need_uptime,
int need_capacity);
routerinfo_t *routerlist_sl_choose_by_bandwidth(smartlist_t *sl);