summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2004-08-20 21:34:36 +0000
committerRoger Dingledine <arma@torproject.org>2004-08-20 21:34:36 +0000
commit79df0aa18a8d37cb81a7df0c4223ec8b49b2cca2 (patch)
treee7114bf5005c115146d415166015fc21d9ea951f
parent7979c0277d84889f331716f5a65d56bd01378775 (diff)
downloadtor-79df0aa18a8d37cb81a7df0c4223ec8b49b2cca2.tar.gz
tor-79df0aa18a8d37cb81a7df0c4223ec8b49b2cca2.zip
when picking unverified routers, skip those with bad uptime or
bad bandwidth, depending on what properties you care about svn:r2302
-rw-r--r--src/or/circuitbuild.c4
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerlist.c26
3 files changed, 26 insertions, 5 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 9102e490a6..12b2afe908 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -847,7 +847,9 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
continue; /* skip routers that are known to be down */
}
if(!router->is_verified &&
- !(options._AllowUnverified & ALLOW_UNVERIFIED_EXIT)) {
+ (!(options._AllowUnverified & ALLOW_UNVERIFIED_EXIT) ||
+ router_is_unreliable_router(router, 1, 1))) {
+ /* if it's unverified, and either we don't want it or it's unsuitable */
n_supported[i] = -1;
log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- unverified router.",
router->nickname, i);
diff --git a/src/or/or.h b/src/or/or.h
index 8d52eb8a28..a5cac7bce2 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1397,6 +1397,7 @@ struct smartlist_t;
void add_nickname_list_to_smartlist(struct smartlist_t *sl, const char *list, int warn_if_down);
routerinfo_t *routerlist_find_my_routerinfo(void);
int router_nickname_matches(routerinfo_t *router, const char *nickname);
+int router_is_unreliable_router(routerinfo_t *router, int need_uptime, int need_bw);
routerinfo_t *routerlist_sl_choose_by_bandwidth(smartlist_t *sl);
routerinfo_t *router_choose_random_node(char *preferred, char *excluded,
struct smartlist_t *excludedsmartlist,
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index d2e93ee226..ed932dc417 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -193,7 +193,8 @@ add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, int warn_if_do
* <b>sl</b>.
*/
static void
-router_add_running_routers_to_smartlist(smartlist_t *sl, int allow_unverified)
+router_add_running_routers_to_smartlist(smartlist_t *sl, int allow_unverified,
+ int preferuptime, int preferbandwidth)
{
routerinfo_t *router;
int i;
@@ -204,7 +205,12 @@ router_add_running_routers_to_smartlist(smartlist_t *sl, int allow_unverified)
for(i=0;i<smartlist_len(routerlist->routers);i++) {
router = smartlist_get(routerlist->routers, i);
if(router->is_running &&
- (allow_unverified || router->is_verified)) {
+ (router->is_verified ||
+ (allow_unverified &&
+ !router_is_unreliable_router(router, preferuptime, preferbandwidth)))) {
+ /* If it's running, and either it's verified or we're ok picking
+ * unverified routers and this one is suitable.
+ */
smartlist_add(sl, router);
}
}
@@ -230,6 +236,17 @@ routerlist_find_my_routerinfo(void) {
* reliability-critical node positions.
*/
#define ROUTER_REQUIRED_MIN_UPTIME 3600 /* an hour */
+#define ROUTER_REQUIRED_MIN_BANDWIDTH 10000
+
+int
+router_is_unreliable_router(routerinfo_t *router, int need_uptime, int need_bw)
+{
+ if(need_uptime && router->uptime < ROUTER_REQUIRED_MIN_UPTIME)
+ return 1;
+ if(need_bw && router->bandwidthcapacity < ROUTER_REQUIRED_MIN_BANDWIDTH)
+ return 1;
+ return 0;
+}
static void
routerlist_sl_remove_unreliable_routers(smartlist_t *sl)
@@ -239,7 +256,7 @@ routerlist_sl_remove_unreliable_routers(smartlist_t *sl)
for (i = 0; i < smartlist_len(sl); ++i) {
router = smartlist_get(sl, i);
- if(router->uptime < ROUTER_REQUIRED_MIN_UPTIME) {
+ if(router_is_unreliable_router(router, 1, 0)) {
log(LOG_DEBUG, "Router %s has insufficient uptime; deleting.",
router->nickname);
smartlist_del(sl, i--);
@@ -324,7 +341,8 @@ routerinfo_t *router_choose_random_node(char *preferred, char *excluded,
smartlist_free(sl);
if(!choice && !strict) {
sl = smartlist_create();
- router_add_running_routers_to_smartlist(sl, allow_unverified);
+ router_add_running_routers_to_smartlist(sl, allow_unverified,
+ preferuptime, preferbandwidth);
smartlist_subtract(sl,excludednodes);
if(excludedsmartlist)
smartlist_subtract(sl,excludedsmartlist);