when picking unverified routers, skip those with bad uptime or

bad bandwidth, depending on what properties you care about


svn:r2302
This commit is contained in:
Roger Dingledine 2004-08-20 21:34:36 +00:00
parent 7979c0277d
commit 79df0aa18a
3 changed files with 26 additions and 5 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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);