summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-03-20 21:41:12 +0000
committerNick Mathewson <nickm@torproject.org>2006-03-20 21:41:12 +0000
commit1272485cd4e32bf7fb1eec993e334dc14172040d (patch)
tree3ccb06196d02f8221673546bd2b313e73a197571
parent173b16cd1e01e97e210c921183fa18d15f7dfb02 (diff)
downloadtor-1272485cd4e32bf7fb1eec993e334dc14172040d.tar.gz
tor-1272485cd4e32bf7fb1eec993e334dc14172040d.zip
Make "Fast" based on median capacity, just like "Stable" is based on median uptime.
svn:r6203
-rw-r--r--src/or/dirserv.c51
1 files changed, 34 insertions, 17 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index f0019d5bad..27d94e7555 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1238,7 +1238,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 */
+static uint32_t stable_uptime = 0; /* start at a safe value */
+static uint32_t fast_bandwidth = 0;
/** 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.
@@ -1251,46 +1252,62 @@ dirserv_thinks_router_is_unreliable(routerinfo_t *router,
{
if (need_uptime && router->uptime < stable_uptime)
return 1;
- if (need_capacity &&
- router->bandwidthcapacity < ROUTER_REQUIRED_MIN_BANDWIDTH)
+ if (need_capacity && router->bandwidthcapacity < fast_bandwidth)
return 1;
return 0;
}
static int
-_compare_longs(const void **a, const void **b)
+_compare_uint32(const void **a, const void **b)
{
- long first = **(long **)a, second = **(long **)b;
+ uint32_t first = **(uint32_t **)a, second = **(uint32_t **)b;
if (first < second) return -1;
if (first > second) return 1;
return 0;
}
/** Look through the routerlist, and assign the median uptime
- * of running valid servers to stable_uptime. */
+ * of running valid servers to stable_uptime, and the median bandwidth
+ * capacity to fast_bandwidth. */
static void
-dirserv_compute_stable_uptime(routerlist_t *rl)
+dirserv_compute_performance_thresholds(routerlist_t *rl)
{
- smartlist_t *uptimes = smartlist_create();
- long *up;
+ smartlist_t *uptimes, *bandwidths;
+
+ uptimes = smartlist_create();
+ bandwidths = smartlist_create();
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
if (ri->is_running && ri->is_valid) {
- up = tor_malloc(sizeof(long));
- *up = ri->uptime;
+ uint32_t *up = tor_malloc(sizeof(uint32_t));
+ *up = (uint32_t) ri->uptime;
smartlist_add(uptimes, up);
+ uint32_t *bw = tor_malloc(sizeof(uint32_t));
+ *bw = (uint32_t) ri->bandwidthcapacity;
+ smartlist_add(bandwidths, bw);
}
});
- smartlist_sort(uptimes, _compare_longs);
+ smartlist_sort(uptimes, _compare_uint32);
+ smartlist_sort(bandwidths, _compare_uint32);
+
+ if (smartlist_len(uptimes))
+ stable_uptime = *(uint32_t*)smartlist_get(uptimes,
+ smartlist_len(uptimes)/2);
- stable_uptime = *(long *)smartlist_get(uptimes,
- smartlist_len(uptimes)/2);
+ if (smartlist_len(bandwidths))
+ fast_bandwidth = *(uint32_t*)smartlist_get(bandwidths,
+ smartlist_len(bandwidths)/2);
- log_info(LD_DIRSERV, "Uptime cutoff is %ld seconds.", stable_uptime);
+ log_info(LD_DIRSERV, "Uptime cutoff is %lu seconds.",
+ (unsigned long)stable_uptime);
+ log_info(LD_DIRSERV, "Bandwidth cutoff is %lu bytes.",
+ (unsigned long)fast_bandwidth);
- SMARTLIST_FOREACH(uptimes, long *, up, tor_free(up));
+ SMARTLIST_FOREACH(uptimes, uint32_t *, up, tor_free(up));
+ SMARTLIST_FOREACH(bandwidths, uint32_t *, bw, tor_free(bw));
smartlist_free(uptimes);
+ smartlist_free(bandwidths);
}
/** For authoritative directories only: replace the contents of
@@ -1388,7 +1405,7 @@ generate_v2_networkstatus(void)
ri->is_running = dirserv_thinks_router_is_reachable(ri, now);
});
- dirserv_compute_stable_uptime(rl);
+ dirserv_compute_performance_thresholds(rl);
SMARTLIST_FOREACH(rl->routers, routerinfo_t *, ri, {
if (ri->cache_info.published_on >= cutoff) {