[or-cvs] Insert a *copy* of our routerinfo into the routerlist.

Nick Mathewson nickm at seul.org
Wed Apr 7 22:18:59 UTC 2004


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

Modified Files:
	or.h routerlist.c 
Log Message:
Insert a *copy* of our routerinfo into the routerlist.

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.305
retrieving revision 1.306
diff -u -d -r1.305 -r1.306
--- or.h	7 Apr 2004 22:00:54 -0000	1.305
+++ or.h	7 Apr 2004 22:18:57 -0000	1.306
@@ -998,6 +998,7 @@
 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);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- routerlist.c	7 Apr 2004 21:36:03 -0000	1.57
+++ routerlist.c	7 Apr 2004 22:18:57 -0000	1.58
@@ -367,6 +367,34 @@
   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 @@
 
   i = 0;
   if ((r = router_get_my_routerinfo())) {
-    smartlist_insert(rl->routers, 0, r);
+    smartlist_insert(rl->routers, 0, routerinfo_copy(r));
     ++i;
   }
 



More information about the tor-commits mailing list