Commit 6649645f authored by Nick Mathewson's avatar Nick Mathewson 🐘
Browse files

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


svn:r1538
parent b1537e79
Loading
Loading
Loading
Loading
+1 −0
Changes for src/or/or.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -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
Changes for src/or/routerlist.c: 29 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -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;
  }