示例#1
0
/* Unittest cleanup function: Cleanup the fake network. */
static int
fake_network_cleanup(const struct testcase_t *testcase, void *ptr)
{
  (void) testcase;
  (void) ptr;

  routerlist_free_all();
  nodelist_free_all();
  entry_guards_free_all();
  or_state_free(dummy_state);

  return 1; /* NOP */
}
示例#2
0
/** Create routerstatuses and signed vote.
 * Create routerstatuses using *vrs_gen* and add them to global routerlist.
 * Next, create signed vote using *sign_skey* and *vote*, which should have
 * predefined header fields.
 * Setting *clear_rl* clears the global routerlist before adding the new
 * routers.
 * Return the signed vote, same as *vote_out*. Save the number of routers added
 * in *n_vrs*.
 */
networkstatus_t *
dir_common_add_rs_and_parse(networkstatus_t *vote, networkstatus_t **vote_out,
                       vote_routerstatus_t * (*vrs_gen)(int idx, time_t now),
                       crypto_pk_t *sign_skey, int *n_vrs, time_t now,
                       int clear_rl)
{
  vote_routerstatus_t *vrs;
  char *v_text=NULL;
  const char *msg=NULL;
  int idx;
  was_router_added_t router_added = -1;
  *vote_out = NULL;

  if (clear_rl) {
    nodelist_free_all();
    routerlist_free_all();
  }

  idx = 0;
  do {
    vrs = vrs_gen(idx, now);
    if (vrs) {
      smartlist_add(vote->routerstatus_list, vrs);
      router_added =
        router_add_to_routerlist(dir_common_generate_ri_from_rs(vrs),
                                 &msg,0,0);
      tt_assert(router_added >= 0);
      ++idx;
    }
  } while (vrs);
  *n_vrs = idx;

  /* dump the vote and try to parse it. */
  v_text = format_networkstatus_vote(sign_skey, vote);
  tt_assert(v_text);
  *vote_out = networkstatus_parse_vote_from_string(v_text, NULL, NS_TYPE_VOTE);

 done:
  if (v_text)
    tor_free(v_text);

  return *vote_out;
}