aboutsummaryrefslogtreecommitdiff
path: root/src/or/router.c
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 /src/or/router.c
parent3559f821a1ecdcaff98c73fae43ab8c670f675a0 (diff)
downloadtor-8ae6e1c226d782e493fcfc13475b7974c25e3a35.tar
tor-8ae6e1c226d782e493fcfc13475b7974c25e3a35.tar.gz
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
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/or/router.c b/src/or/router.c
index 333ad1e1b..28dee45b1 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,