[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] when picking unverified routers, skip those with bad uptime...



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	circuitbuild.c or.h routerlist.c 
Log Message:
when picking unverified routers, skip those with bad uptime or
bad bandwidth, depending on what properties you care about


Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/src/or/circuitbuild.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- circuitbuild.c	18 Aug 2004 20:35:11 -0000	1.32
+++ circuitbuild.c	20 Aug 2004 21:34:36 -0000	1.33
@@ -847,7 +847,9 @@
       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);

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.414
retrieving revision 1.415
diff -u -d -r1.414 -r1.415
--- or.h	18 Aug 2004 11:20:15 -0000	1.414
+++ or.h	20 Aug 2004 21:34:36 -0000	1.415
@@ -1397,6 +1397,7 @@
 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,

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -d -r1.132 -r1.133
--- routerlist.c	18 Aug 2004 21:13:58 -0000	1.132
+++ routerlist.c	20 Aug 2004 21:34:36 -0000	1.133
@@ -193,7 +193,8 @@
  * <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 @@
   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 @@
  * 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 @@
 
   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 @@
   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);