Browse Source

Insert a *copy* of our routerinfo into the routerlist.

svn:r1538
Nick Mathewson 20 years ago
parent
commit
6649645f09
2 changed files with 30 additions and 1 deletions
  1. 1 0
      src/or/or.h
  2. 29 1
      src/or/routerlist.c

+ 1 - 0
src/or/or.h

@@ -998,6 +998,7 @@ routerinfo_t *router_get_by_link_pk(crypto_pk_env_t *pk);
 routerinfo_t *router_get_by_nickname(char *nickname);
 void router_get_routerlist(routerlist_t **prouterlist);
 void routerinfo_free(routerinfo_t *router);
+routerinfo_t *routerinfo_copy(const routerinfo_t *router);
 int router_version_supports_rendezvous(routerinfo_t *router);
 void router_add_nonrendezvous_to_list(smartlist_t *sl);
 void router_mark_as_down(char *nickname);

+ 29 - 1
src/or/routerlist.c

@@ -367,6 +367,34 @@ void routerinfo_free(routerinfo_t *router)
   free(router);
 }
 
+routerinfo_t *routerinfo_copy(const routerinfo_t *router)
+{
+  routerinfo_t *r;
+  struct exit_policy_t **e, *tmp;
+
+  r = tor_malloc(sizeof(routerinfo_t));
+  memcpy(r, router, sizeof(routerinfo_t));
+
+  r->address = tor_strdup(r->address);
+  r->nickname = tor_strdup(r->nickname);
+  r->platform = tor_strdup(r->platform);
+  if (r->onion_pkey)
+    r->onion_pkey = crypto_pk_dup_key(r->onion_pkey);
+  if (r->link_pkey)
+    r->link_pkey = crypto_pk_dup_key(r->link_pkey);
+  if (r->identity_pkey)
+    r->identity_pkey = crypto_pk_dup_key(r->identity_pkey);
+  e = &r->exit_policy;
+  while (*e) {
+    tmp = tor_malloc(sizeof(struct exit_policy_t));
+    memcpy(tmp,*e,sizeof(struct exit_policy_t));
+    *e = tmp;
+    (*e)->string = tor_strdup((*e)->string);
+    e = & ((*e)->next);
+  }
+  return r;
+}
+
 static void routerlist_free(routerlist_t *rl)
 {
   SMARTLIST_FOREACH(rl->routers, routerinfo_t *, r,
@@ -523,7 +551,7 @@ router_resolve_routerlist(routerlist_t *rl)
 
   i = 0;
   if ((r = router_get_my_routerinfo())) {
-    smartlist_insert(rl->routers, 0, r);
+    smartlist_insert(rl->routers, 0, routerinfo_copy(r));
     ++i;
   }