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

[or-cvs] Be more conservative about whether to advertise our dirport.



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

Modified Files:
	router.c test.c 
Log Message:
Be more conservative about whether to advertise our dirport.
The main change is to not advertise if we're running at capacity and
either a) we could hibernate or b) our capacity is low and we're using
a default dirport.


Index: router.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.209
retrieving revision 1.210
diff -u -d -r1.209 -r1.210
--- router.c	23 Sep 2005 08:29:58 -0000	1.209
+++ router.c	29 Sep 2005 06:45:03 -0000	1.210
@@ -404,6 +404,34 @@
          can_reach_dir_port;
 }
 
+/** Look at a variety of factors, and return 0 if we don't want to
+ * advertise the fact that we have a DirPort open. Else return the
+ * DirPort we want to advertise. */
+static int
+decide_to_advertise_dirport(or_options_t *options, routerinfo_t *router)
+{
+  if (!router->dir_port) /* short circuit the rest of the function */
+    return 0;
+  if (authdir_mode(options)) /* always publish */
+    return router->dir_port;
+  if (we_are_hibernating())
+    return 0;
+  if (!check_whether_dirport_reachable())
+    return 0;
+  if (router->bandwidthcapacity >= router->bandwidthrate) {
+    /* check if we might potentially hibernate. */
+    if (options->AccountingMax != 0)
+      return 0;
+    /* also check if we're advertising a small amount, and have
+       a "boring" DirPort. */
+    if (router->bandwidthrate < 50000 && router->dir_port > 1024)
+      return 0;
+  }
+
+  /* Sounds like a great idea. Let's publish it. */
+  return router->dir_port;
+}
+
 /**DOCDOC*/
 void
 consider_testing_reachability(void)
@@ -739,8 +767,7 @@
   ri->nickname = tor_strdup(options->Nickname);
   ri->addr = addr;
   ri->or_port = options->ORPort;
-  ri->dir_port = hibernating ?
-                 0 : options->DirPort;
+  ri->dir_port = options->DirPort;
   ri->published_on = time(NULL);
   ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from main thread */
   ri->identity_pkey = crypto_pk_dup_key(get_identity_key());
@@ -934,8 +961,7 @@
     router->nickname,
     router->address,
     router->or_port,
-    (authdir_mode(options) || check_whether_dirport_reachable()) ?
-      router->dir_port : 0,
+    decide_to_advertise_dirport(options, router),
     router->platform,
     published,
     fingerprint,

Index: test.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.205
retrieving revision 1.206
diff -u -d -r1.205 -r1.206
--- test.c	23 Sep 2005 17:11:20 -0000	1.205
+++ test.c	29 Sep 2005 06:45:03 -0000	1.206
@@ -1216,7 +1216,7 @@
   memset(buf, 0, 2048);
   test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
 
-  strcpy(buf2, "router Magri 18.244.0.1 9000 0 9003\n"
+  strcpy(buf2, "router Magri 18.244.0.1 9000 0 0\n"
          "platform Tor "VERSION" on ");
   strcat(buf2, get_uname());
   strcat(buf2, "\n"
@@ -1246,7 +1246,7 @@
   test_assert(rp1);
   test_streq(rp1->address, r1.address);
   test_eq(rp1->or_port, r1.or_port);
-  test_eq(rp1->dir_port, r1.dir_port);
+  //test_eq(rp1->dir_port, r1.dir_port);
   test_eq(rp1->bandwidthrate, r1.bandwidthrate);
   test_eq(rp1->bandwidthburst, r1.bandwidthburst);
   test_eq(rp1->bandwidthcapacity, r1.bandwidthcapacity);