[or-cvs] make the "stable" flag in network-status be the median of t...

arma at seul.org arma at seul.org
Mon Jan 2 03:32:57 UTC 2006


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv17170

Modified Files:
	dirserv.c or.h 
Log Message:
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.


Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.282
retrieving revision 1.283
diff -u -p -d -r1.282 -r1.283
--- dirserv.c	15 Dec 2005 21:39:38 -0000	1.282
+++ dirserv.c	2 Jan 2006 03:32:55 -0000	1.283
@@ -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(rout
   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);
 

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.771
retrieving revision 1.772
diff -u -p -d -r1.771 -r1.772
--- or.h	31 Dec 2005 11:52:13 -0000	1.771
+++ or.h	2 Jan 2006 03:32:55 -0000	1.772
@@ -2244,15 +2244,10 @@ void add_nickname_list_to_smartlist(smar
 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);



More information about the tor-commits mailing list