mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Add bandwidthrate and directory-signer to router/directory format; make unit tests pass.
svn:r1677
This commit is contained in:
@@ -437,8 +437,13 @@ dirserv_dump_directory_to_string(char *s, int maxlen,
|
||||
/* These multiple strlcat calls are inefficient, but dwarfed by the RSA
|
||||
signature.
|
||||
*/
|
||||
if (strlcat(s, "directory-signature\n", maxlen) >= maxlen)
|
||||
if (strlcat(s, "directory-signature ", maxlen) >= maxlen)
|
||||
goto truncated;
|
||||
if (strlcat(s, options.Nickname, maxlen) >= maxlen)
|
||||
goto truncated;
|
||||
if (strlcat(s, "\n", maxlen) >= maxlen)
|
||||
goto truncated;
|
||||
|
||||
|
||||
if (router_get_dir_hash(s,digest)) {
|
||||
log_fn(LOG_WARN,"couldn't compute digest");
|
||||
|
||||
@@ -622,7 +622,7 @@ onion_skin_create(crypto_pk_env_t *dest_router_key,
|
||||
|
||||
/* set meeting point, meeting cookie, etc here. Leave zero for now. */
|
||||
if (crypto_pk_public_hybrid_encrypt(dest_router_key, challenge,
|
||||
ONIONSKIN_CHALLENGE_LEN-CIPHER_KEY_LEN,
|
||||
DH_KEY_LEN,
|
||||
onion_skin_out, PK_PKCS1_OAEP_PADDING, 1)<0)
|
||||
goto err;
|
||||
|
||||
|
||||
@@ -475,9 +475,10 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
|
||||
/* XXXX eventually, don't include link key */
|
||||
result = snprintf(s, maxlen,
|
||||
"router %s %s %d %d %d %d\n"
|
||||
"router %s %s %d %d %d\n"
|
||||
"platform %s\n"
|
||||
"published %s\n"
|
||||
"bandwidth %d %d\n"
|
||||
"onion-key\n%s"
|
||||
"signing-key\n%s",
|
||||
router->nickname,
|
||||
@@ -485,10 +486,10 @@ int router_dump_router_to_string(char *s, int maxlen, routerinfo_t *router,
|
||||
router->or_port,
|
||||
router->socks_port,
|
||||
router->dir_port,
|
||||
(int) router->bandwidthrate,
|
||||
/* XXXBC also write bandwidthburst */
|
||||
router->platform,
|
||||
published,
|
||||
(int) router->bandwidthrate,
|
||||
(int) router->bandwidthburst,
|
||||
onion_pkey, identity_pkey);
|
||||
|
||||
free(onion_pkey);
|
||||
|
||||
@@ -83,7 +83,7 @@ static struct {
|
||||
char *t; int v; arg_syntax s; obj_syntax os; where_syntax ws;
|
||||
} token_table[] = {
|
||||
{ "accept", K_ACCEPT, ARGS, NO_OBJ, RTR_ONLY },
|
||||
{ "directory-signature", K_DIRECTORY_SIGNATURE, NO_ARGS, NEED_OBJ, DIR_ONLY},
|
||||
{ "directory-signature", K_DIRECTORY_SIGNATURE, ARGS, NEED_OBJ, DIR_ONLY},
|
||||
{ "reject", K_REJECT, ARGS, NO_OBJ, RTR_ONLY },
|
||||
{ "router", K_ROUTER, ARGS, NO_OBJ, RTR_ONLY },
|
||||
{ "recommended-software", K_RECOMMENDED_SOFTWARE, ARGS, NO_OBJ, DIR_ONLY },
|
||||
@@ -933,7 +933,7 @@ routerinfo_t *router_get_entry_from_string(const char *s,
|
||||
router->onion_pkey = router->identity_pkey = NULL;
|
||||
ports_set = bw_set = 0;
|
||||
|
||||
if (tok->n_args == 2 || tok->n_args == 6) {
|
||||
if (tok->n_args == 2 || tok->n_args == 5 || tok->n_args == 6) {
|
||||
router->nickname = tor_strdup(tok->args[0]);
|
||||
if (strlen(router->nickname) > MAX_NICKNAME_LEN) {
|
||||
log_fn(LOG_WARN,"Router nickname too long.");
|
||||
@@ -947,15 +947,20 @@ routerinfo_t *router_get_entry_from_string(const char *s,
|
||||
router->address = tor_strdup(tok->args[1]);
|
||||
router->addr = 0;
|
||||
|
||||
if (tok->n_args == 6) {
|
||||
if (tok->n_args >= 5) {
|
||||
router->or_port = atoi(tok->args[2]);
|
||||
router->socks_port = atoi(tok->args[3]);
|
||||
router->dir_port = atoi(tok->args[4]);
|
||||
router->bandwidthrate = atoi(tok->args[5]);
|
||||
ports_set = bw_set = 1;
|
||||
ports_set = 1;
|
||||
/* XXXX Remove this after everyone has moved to 0.0.6 */
|
||||
if (tok->n_args == 6) {
|
||||
router->bandwidthrate = atoi(tok->args[5]);
|
||||
router->bandwidthburst = router->bandwidthrate * 10;
|
||||
bw_set = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_fn(LOG_WARN,"Wrong # of arguments to \"router\"");
|
||||
log_fn(LOG_WARN,"Wrong # of arguments to \"router\" (%d)",tok->n_args);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -979,11 +984,12 @@ routerinfo_t *router_get_entry_from_string(const char *s,
|
||||
log_fn(LOG_WARN,"Redundant bandwidth line");
|
||||
goto err;
|
||||
} else if (tok) {
|
||||
if (tok->n_args < 1) {
|
||||
if (tok->n_args < 2) {
|
||||
log_fn(LOG_WARN,"Not enough arguments to \"bandwidth\"");
|
||||
goto err;
|
||||
}
|
||||
router->bandwidthrate = atoi(tok->args[0]);
|
||||
router->bandwidthburst = atoi(tok->args[1]);
|
||||
bw_set = 1;
|
||||
}
|
||||
|
||||
@@ -1055,16 +1061,6 @@ routerinfo_t *router_get_entry_from_string(const char *s,
|
||||
router->platform = tor_strdup("<unknown>");
|
||||
}
|
||||
|
||||
#if XXXBC
|
||||
router->bandwidthburst = atoi(ARGS[6]);
|
||||
if (!router->bandwidthburst) {
|
||||
log_fn(LOG_WARN,"bandwidthburst unreadable or 0. Failing.");
|
||||
goto err;
|
||||
}
|
||||
#else
|
||||
router->bandwidthburst = 10*router->bandwidthrate;
|
||||
#endif
|
||||
|
||||
log_fn(LOG_DEBUG,"or_port %d, socks_port %d, dir_port %d, bandwidthrate %u, bandwidthburst %u.",
|
||||
router->or_port, router->socks_port, router->dir_port,
|
||||
(unsigned) router->bandwidthrate, (unsigned) router->bandwidthburst);
|
||||
|
||||
@@ -701,7 +701,8 @@ test_dir_format()
|
||||
r1.dir_port = 9003;
|
||||
r1.onion_pkey = pk1;
|
||||
r1.identity_pkey = pk2;
|
||||
r1.bandwidthrate = r1.bandwidthburst = 1000;
|
||||
r1.bandwidthrate = 1000;
|
||||
r1.bandwidthburst = 5000;
|
||||
r1.exit_policy = NULL;
|
||||
r1.nickname = "Magri";
|
||||
r1.platform = tor_strdup(platform);
|
||||
@@ -740,11 +741,12 @@ test_dir_format()
|
||||
memset(buf, 0, 2048);
|
||||
test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
|
||||
|
||||
strcpy(buf2, "router Magri testaddr1.foo.bar 9000 9002 9003 1000\n"
|
||||
strcpy(buf2, "router Magri testaddr1.foo.bar 9000 9002 9003\n"
|
||||
"platform Tor "VERSION" on ");
|
||||
strcat(buf2, get_uname());
|
||||
strcat(buf2, "\n"
|
||||
"published 1970-01-01 00:00:00\n"
|
||||
"bandwidth 1000 5000\n"
|
||||
"onion-key\n");
|
||||
strcat(buf2, pk1_str);
|
||||
strcat(buf2, "signing-key\n");
|
||||
@@ -763,7 +765,7 @@ test_dir_format()
|
||||
test_eq(rp1->socks_port, r1.socks_port);
|
||||
test_eq(rp1->dir_port, r1.dir_port);
|
||||
test_eq(rp1->bandwidthrate, r1.bandwidthrate);
|
||||
// test_eq(rp1->bandwidthburst, r1.bandwidthburst);
|
||||
test_eq(rp1->bandwidthburst, r1.bandwidthburst);
|
||||
test_assert(crypto_pk_cmp_keys(rp1->onion_pkey, pk1) == 0);
|
||||
test_assert(crypto_pk_cmp_keys(rp1->identity_pkey, pk2) == 0);
|
||||
test_assert(rp1->exit_policy == NULL);
|
||||
@@ -903,7 +905,7 @@ main(int c, char**v){
|
||||
test_onion();
|
||||
test_onion_handshake();
|
||||
puts("\n========================= Directory Formats ===============");
|
||||
// add_stream_log(LOG_DEBUG, NULL, stdout);
|
||||
/* add_stream_log(LOG_DEBUG, NULL, stdout); */
|
||||
test_dir_format();
|
||||
puts("\n========================= Rendezvous functionality ========");
|
||||
test_rend_fns();
|
||||
|
||||
Reference in New Issue
Block a user