mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
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
This commit is contained in:
parent
3559f821a1
commit
8ae6e1c226
@ -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,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user