[or-cvs] Add bandwidthrate and directory-signer to router/directory ...

Nick Mathewson nickm at seul.org
Wed Apr 21 21:56:22 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv27469/src/or

Modified Files:
      Tag: tor-0_0_6incompat
	dirserv.c onion.c router.c routerlist.c test.c 
Log Message:
Add bandwidthrate and directory-signer to router/directory format; make unit tests pass.

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.37
retrieving revision 1.37.2.1
diff -u -d -r1.37 -r1.37.2.1
--- dirserv.c	13 Apr 2004 20:06:08 -0000	1.37
+++ dirserv.c	21 Apr 2004 21:56:20 -0000	1.37.2.1
@@ -437,8 +437,13 @@
   /* 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");

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.154.2.1
retrieving revision 1.154.2.2
diff -u -d -r1.154.2.1 -r1.154.2.2
--- onion.c	17 Apr 2004 01:37:27 -0000	1.154.2.1
+++ onion.c	21 Apr 2004 21:56:20 -0000	1.154.2.2
@@ -622,7 +622,7 @@
 
   /* 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;
 

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.26.2.3
retrieving revision 1.26.2.4
diff -u -d -r1.26.2.3 -r1.26.2.4
--- router.c	18 Apr 2004 23:27:02 -0000	1.26.2.3
+++ router.c	21 Apr 2004 21:56:20 -0000	1.26.2.4
@@ -475,9 +475,10 @@
 
   /* 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 @@
     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);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.60.2.1
retrieving revision 1.60.2.2
diff -u -d -r1.60.2.1 -r1.60.2.2
--- routerlist.c	17 Apr 2004 01:37:28 -0000	1.60.2.1
+++ routerlist.c	21 Apr 2004 21:56:20 -0000	1.60.2.2
@@ -83,7 +83,7 @@
   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 @@
   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 @@
     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 @@
     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 @@
     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);

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.81.2.1
retrieving revision 1.81.2.2
diff -u -d -r1.81.2.1 -r1.81.2.2
--- test.c	17 Apr 2004 01:37:28 -0000	1.81.2.1
+++ test.c	21 Apr 2004 21:56:20 -0000	1.81.2.2
@@ -701,7 +701,8 @@
   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 @@
   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_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 @@
   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();



More information about the tor-commits mailing list