summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoger Dingledine <arma@torproject.org>2005-09-29 06:45:03 +0000
committerRoger Dingledine <arma@torproject.org>2005-09-29 06:45:03 +0000
commit8ae6e1c226d782e493fcfc13475b7974c25e3a35 (patch)
tree3153c4d9fd96a0f2399db2117c55d48a5171eb87
parent3559f821a1ecdcaff98c73fae43ab8c670f675a0 (diff)
downloadtor-8ae6e1c226d782e493fcfc13475b7974c25e3a35.tar.gz
tor-8ae6e1c226d782e493fcfc13475b7974c25e3a35.zip
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. svn:r5148
-rw-r--r--src/or/router.c34
-rw-r--r--src/or/test.c4
2 files changed, 32 insertions, 6 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 333ad1e1bc..28dee45b1c 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -404,6 +404,34 @@ check_whether_dirport_reachable(void)
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 @@ router_rebuild_descriptor(int force)
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_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
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,
diff --git a/src/or/test.c b/src/or/test.c
index 04c269fa19..71be68d3df 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1216,7 +1216,7 @@ test_dir_format(void)
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_dir_format(void)
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);