[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Call the right signed-directory functions; try to describe ...



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

Modified Files:
	directory.c main.c or.h 
Log Message:
Call the right signed-directory functions; try to describe the difference between everything; remove some unused interfaces

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- directory.c	7 May 2003 21:42:17 -0000	1.10
+++ directory.c	8 May 2003 03:36:53 -0000	1.11
@@ -117,9 +117,11 @@
 
 void directory_rebuild(void) {
   if(directory_dirty) {
-/* NICK: This is where the dirserver makes a new <the_directory,directorylen>
- * (or whatever it'll be called in the future) pair. */
-    dump_directory_to_string(the_directory, MAX_DIR_SIZE);
+    if (dump_signed_directory_to_string(the_directory, MAX_DIR_SIZE,
+                                        get_signing_privatekey())) {
+      log(LOG_ERR, "Error writing directory");
+      return;
+    }
     log(LOG_INFO,"New directory:\n%s",the_directory);
     directorylen = strlen(the_directory);
     directory_dirty = 0;
@@ -144,9 +146,7 @@
       log(LOG_DEBUG,"connection_dir_process_inbuf(): Empty directory. Ignoring.");
       return -1;
     }
-/* NICK: This is where the client parses, checks-the-signature-of, etc the
- * new directory. conn->pkey is the signing key of the directory server we chose. */
-    if(router_get_list_from_string(the_directory) < 0) {
+    if(router_get_dir_from_string(the_directory, conn->pkey) < 0) {
       log(LOG_DEBUG,"connection_dir_process_inbuf(): ...but parsing failed. Ignoring.");
     }
     if(options.ORPort) { /* connect to them all */

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- main.c	7 May 2003 22:40:03 -0000	1.57
+++ main.c	8 May 2003 03:36:53 -0000	1.58
@@ -645,9 +645,8 @@
 
 }
 
-void dump_directory_to_string(char *s, int maxlen) 
-{
-  directory_t dir;
+static int 
+build_directory(directory_t *dir) {
   routerinfo_t **routers = NULL;
   connection_t *conn;
   routerinfo_t *router;
@@ -656,7 +655,7 @@
   routers = (routerinfo_t**) malloc(sizeof(routerinfo_t*) * (nfds+1));
   if (!routers) {
     /* freak out XXX */
-    return;
+    return -1;
   }
   if (my_routerinfo) {
     routers[n++] = my_routerinfo;
@@ -675,10 +674,19 @@
     }
     routers[n++] = router;
   }
-  dir.routers = routers;
-  dir.n_routers = n;
+  dir->routers = routers;
+  dir->n_routers = n;
+  return 0;
+}
 
-  dump_directory_to_string_impl(s, maxlen, &dir);
+int
+dump_signed_directory_to_string(char *s, int maxlen,
+                                crypto_pk_env_t *private_key)
+{
+  directory_t dir;
+  if (!build_directory(&dir))
+    return -1;
+  return dump_signed_directory_to_string_impl(s, maxlen, &dir, private_key);  
 }
 
 int
@@ -688,18 +696,31 @@
   char *cp;
   char digest[20];
   char signature[128];
-  int i;
+  int i, written;
+  routerinfo_t *router;
   strncpy(s, 
           "signed-directory\n"
           "client-software x y z\n" /* XXX make this real */
           "server-software a b c\n\n" /* XXX make this real */
           , maxlen);
+  for (i = 0; i < dir->n_routers; ++i) {
+    router = dir->routers[i];
+    written = dump_router_to_string(s, maxlen, router);
+
+    if(written < 0) { 
+      log(LOG_ERR,"dump_directory_to_string(): tried to exceed string length.");
+      s[maxlen-1] = 0; /* make sure it's null terminated */
+      return -1;
+    }
+    
+    maxlen -= written;
+    s += written;
+  }
+
+
   /* These multiple strlen calls are inefficient, but dwarfed by the RSA
      signature.
   */
-  i = strlen(s); 
-
-  dump_directory_to_string_impl(s+i, maxlen-i, dir);
   i = strlen(s);
   strncat(s, "directory-signature\n", maxlen-i);
   i = strlen(s);
@@ -723,26 +744,6 @@
   strcat(cp, "-----END SIGNATURE-----\n");
 
   return 0;
-}
-
-void dump_directory_to_string_impl(char *s, int maxlen, directory_t *directory) {
-  int i;
-  routerinfo_t *router;
-  int written;
-
-  for (i = 0; i < directory->n_routers; ++i) {
-    router = directory->routers[i];
-    written = dump_router_to_string(s, maxlen, router);
-
-    if(written < 0) { 
-      log(LOG_ERR,"dump_directory_to_string(): tried to exceed string length.");
-      s[maxlen-1] = 0; /* make sure it's null terminated */
-      return;
-    }
-
-    maxlen -= written;
-    s += written;
-  }
 }
 
 void daemonize(void) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.79
retrieving revision 1.80
diff -u -d -r1.79 -r1.80
--- or.h	7 May 2003 22:40:03 -0000	1.79
+++ or.h	8 May 2003 03:36:53 -0000	1.80
@@ -740,10 +740,12 @@
 int do_main_loop(void);
 
 void dumpstats(void);
-void dump_directory_to_string(char *s, int maxlen);
-void dump_directory_to_string_impl(char *s, int maxlen, directory_t *directory);
-int dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir, crypto_pk_env_t *private_key);
-                                         
+int dump_signed_directory_to_string(char *s, int maxlen, 
+                                    crypto_pk_env_t *private_key);
+/* Exported for debugging */
+int dump_signed_directory_to_string_impl(char *s, int maxlen, 
+                                         directory_t *dir, 
+                                         crypto_pk_env_t *private_key); 
 
 int main(int argc, char *argv[]);
 
@@ -796,9 +798,13 @@
 void router_forget_router(uint32_t addr, uint16_t port);
 int router_get_list_from_file(char *routerfile);
 int router_resolve(routerinfo_t *router);
+/* Reads a list of known routers, unsigned. */
 int router_get_list_from_string(char *s);
+/* Exported for debugging */
 int router_get_list_from_string_impl(char *s, directory_t **dest);
+/* Reads a signed directory. */
 int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey);
+/* Exported or debugging */
 int router_get_dir_from_string_impl(char *s, directory_t **dest,
                                     crypto_pk_env_t *pkey);
 routerinfo_t *router_get_entry_from_string(char **s);