aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-04-07 22:18:57 +0000
committerNick Mathewson <nickm@torproject.org>2004-04-07 22:18:57 +0000
commit6649645f0978a88c8bd28a1299d7b65a8e3becf2 (patch)
tree6e724fd9eb7fc22e0b62c4e1f3eea9652d613348
parentb1537e79436ded47784de64ec4ea5b8defa7f65d (diff)
downloadtor-6649645f0978a88c8bd28a1299d7b65a8e3becf2.tar
tor-6649645f0978a88c8bd28a1299d7b65a8e3becf2.tar.gz
Insert a *copy* of our routerinfo into the routerlist.
svn:r1538
-rw-r--r--src/or/or.h1
-rw-r--r--src/or/routerlist.c30
2 files changed, 30 insertions, 1 deletions
diff --git a/src/or/or.h b/src/or/or.h
index c99c9f492..9ecb5c030 100644
--- a/src/or/or.h
+++ b/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);
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 088ad3c92..40710b8a2 100644
--- a/src/or/routerlist.c
+++ b/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;
}