Commit c3998e94 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

Call the right signed-directory functions; try to describe the difference...

Call the right signed-directory functions; try to describe the difference between everything; remove some unused interfaces


svn:r276
parent bcfbccb0
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -117,9 +117,11 @@ void directory_set_dirty(void) {

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 @@ int connection_dir_process_inbuf(connection_t *conn) {
      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 */
+32 −31
Original line number Diff line number Diff line
@@ -645,9 +645,8 @@ int dump_router_to_string(char *s, int maxlen, routerinfo_t *router) {

}

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 @@ void dump_directory_to_string(char *s, int maxlen)
  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 @@ void dump_directory_to_string(char *s, int maxlen)
    }
    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,19 +696,32 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
  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);
  cp = s + i;
@@ -725,26 +746,6 @@ dump_signed_directory_to_string_impl(char *s, int maxlen, directory_t *dir,
  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) {
  /* Fork; parent exits. */
  if (fork())
+10 −4
Original line number Diff line number Diff line
@@ -740,10 +740,12 @@ int prepare_for_poll(int *timeout);
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 @@ int router_is_me(uint32_t addr, uint16_t port);
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);