Browse Source

(possibly incorrect) code to make routers get resolved when they're
inserted into the directory.

Roger: If you can answer the question with your name on it, you may
prevent a segfault before it happens. :)


svn:r277

Nick Mathewson 22 years ago
parent
commit
1d1f46e40d
2 changed files with 32 additions and 2 deletions
  1. 2 0
      src/or/or.h
  2. 30 2
      src/or/routers.c

+ 2 - 0
src/or/or.h

@@ -798,6 +798,8 @@ 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);
+int router_resolve_directory(directory_t *dir);
+
 /* Reads a list of known routers, unsigned. */
 int router_get_list_from_string(char *s);
 /* Exported for debugging */

+ 30 - 2
src/or/routers.c

@@ -518,7 +518,10 @@ static char *find_whitespace(char *s) {
 
 int router_get_list_from_string(char *s) 
 {
-  return router_get_list_from_string_impl(s, &directory);
+  int i;
+  i = router_get_list_from_string_impl(s, &directory);
+  router_resolve_directory(directory);
+  return i;
 }
 
 int router_get_list_from_string_impl(char *s, directory_t **dest) {
@@ -548,7 +551,10 @@ static int router_get_dir_hash(char *s, char *digest)
 
 int router_get_dir_from_string(char *s, crypto_pk_env_t *pkey)
 {
-  return router_get_dir_from_string_impl(s, &directory, pkey);
+  int i;
+  i = router_get_dir_from_string_impl(s, &directory, pkey);
+  router_resolve_directory(directory);
+  return i;
 }
 
 int router_get_dir_from_string_impl(char *s, directory_t **dest,
@@ -678,6 +684,28 @@ router_resolve(routerinfo_t *router)
   return 0;
 }
 
+int 
+router_resolve_directory(directory_t *dir)
+{
+  int i, max;
+  if (!dir)
+    dir = directory;
+
+  max = dir->n_routers;
+  for (i = 0; i < max; ++i) {
+    if (router_resolve(dir->routers[i])) {
+      /* ARMA: Is this the right way to remove a router from the directory? */
+      dir->routers[i]->next = NULL;
+      routerlist_free(dir->routers[i]);
+      dir->routers[i] = dir->routers[--max];
+      dir->routers[max] = NULL;
+      --dir->n_routers;
+    }
+  }
+  
+  return 0;
+}
+
 
 routerinfo_t *router_get_entry_from_string(char **s) {
   directory_token_t tok;