Commit e24d540d authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

We no longer need dirserv_load_from_directory_string, so ...

We no longer need dirserv_load_from_directory_string, so  dirserv_add_descriptor no longer has to keep track of where each descriptor ends.


svn:r4861
parent 208bdf5f
Loading
Loading
Loading
Loading
+1 −2
Changes for src/or/directory.c: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -1188,8 +1188,7 @@ directory_handle_command_post(connection_t *conn, char *headers,

  if (!strcmp(url,"/tor/")) { /* server descriptor post */
    const char *msg;
    cp = body;
    switch (dirserv_add_descriptor(&cp, &msg)) {
    switch (dirserv_add_descriptor(body, &msg)) {
      case -2:
      case -1:
        /* malformed descriptor, or something wrong */
+7 −25
Changes for src/or/dirserv.c: 7 added lines, 25 removed lines.
Original line number Diff line number Diff line
@@ -324,11 +324,9 @@ dirserv_wants_to_reject_router(routerinfo_t *ri, int *verified,



/** Parse the server descriptor at *desc and maybe insert it into the
 * list of server descriptors, and (if the descriptor is well-formed)
 * advance *desc immediately past the descriptor's end.  Set msg to a
 * message that should be passed back to the origin of this descriptor, or
 * to NULL.
/** Parse the server descriptor at desc and maybe insert it into the list of
 * server descriptors.  Set msg to a message that should be passed back to the
 * origin of this descriptor, or to NULL.
 *
 * Return 1 if descriptor is well-formed and accepted;
 *  0 if well-formed and server is unapproved but accepted;
@@ -336,33 +334,15 @@ dirserv_wants_to_reject_router(routerinfo_t *ri, int *verified,
 * -2 if we can't find a router descriptor in *desc.
 */
int
dirserv_add_descriptor(const char **desc, const char **msg)
dirserv_add_descriptor(const char *desc, const char **msg)
{
  routerinfo_t *ri = NULL;
  char *start, *end;
  char *desc_tmp = NULL;
  size_t desc_len;
  tor_assert(msg);
  *msg = NULL;

  start = strstr(*desc, "router ");
  if (!start) {
    log_fn(LOG_WARN, "no 'router' line found. This is not a descriptor.");
    return -2;
  }
  if ((end = strstr(start+6, "\nrouter "))) {
    ++end; /* Include NL. */
  } else if ((end = strstr(start+6, "\ndirectory-signature"))) {
    ++end;
  } else {
    end = start+strlen(start);
  }
  desc_len = end-start;
  desc_tmp = tor_strndup(start, desc_len); /* Is this strndup still needed???*/

  /* Check: is the descriptor syntactically valid? */
  ri = router_parse_entry_from_string(desc_tmp, NULL);
  tor_free(desc_tmp);
  ri = router_parse_entry_from_string(desc, NULL);
  if (!ri) {
    log(LOG_WARN, "Couldn't parse descriptor");
    *msg = "Rejected: Couldn't parse server descriptor.";
@@ -470,6 +450,7 @@ directory_set_dirty()
    runningrouters_is_dirty = now;
}

#if 0
/** Load all descriptors from a directory stored in the string
 * <b>dir</b>.
 */
@@ -489,6 +470,7 @@ dirserv_load_from_directory_string(const char *dir)
  }
  return 0;
}
#endif

/**
 * Allocate and return a description of the status of the server <b>desc</b>,
+1 −2
Changes for src/or/or.h: 1 added line, 2 removed lines.
Original line number Diff line number Diff line
@@ -1628,9 +1628,8 @@ int dirserv_parse_fingerprint_file(const char *fname);
int dirserv_router_fingerprint_is_known(const routerinfo_t *router);
void dirserv_free_fingerprint_list(void);
const char *dirserv_get_nickname_by_digest(const char *digest);
int dirserv_add_descriptor(const char **desc, const char **msg);
int dirserv_add_descriptor(const char *desc, const char **msg);
char *dirserver_getinfo_unregistered(const char *question);
int dirserv_load_from_directory_string(const char *dir);
void dirserv_free_descriptors(void);
int list_server_status(smartlist_t *routers, char **router_status_out);
void dirserv_log_unreachable_servers(time_t now);
+2 −0
Changes for src/or/routerlist.c: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -1076,11 +1076,13 @@ router_load_routerlist_from_directory(const char *s,
    control_event_descriptors_changed(routerlist->routers);
  }
  router_normalize_routerlist(routerlist);
#if 0
  if (get_options()->AuthoritativeDir) {
    /* Learn about the descriptors in the directory. */
    dirserv_load_from_directory_string(s);
//XXXRD
  }
#endif
  return 0;
}

+2 −4
Changes for src/or/test.c: 2 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -1283,11 +1283,9 @@ test_dir_format(void)
  r1.published_on = time(NULL);
  r2.published_on = time(NULL)-3*60*60;
  test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
  cp = buf;
  test_eq(dirserv_add_descriptor((const char**)&cp,&m), 1);
  test_eq(dirserv_add_descriptor(buf,&m), 1);
  test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
  cp = buf;
  test_eq(dirserv_add_descriptor((const char**)&cp,&m), 1);
  test_eq(dirserv_add_descriptor(buf,&m), 1);
  get_options()->Nickname = tor_strdup("DirServer");
  test_assert(!dirserv_dump_directory_to_string(&cp,pk3));
  test_assert(!router_parse_routerlist_from_directory(cp, &dir1, pk3, 1, 0));