예제 #1
0
파일: rendclient.c 프로젝트: dezelin/tor
/** Purge all potentially remotely-detectable state held in the hidden
 * service client code.  Called on SIGNAL NEWNYM. */
void
rend_client_purge_state(void)
{
  rend_cache_purge();
  rend_client_cancel_descriptor_fetches();
  rend_client_purge_last_hid_serv_requests();
}
예제 #2
0
static void
test_rend_cache_store_v2_desc_as_dir(void *data)
{
  (void)data;
  int ret;
  rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
  char *service_id = NULL;

  NS_MOCK(router_get_my_routerinfo);

  rend_cache_init();

  // Test when we can't parse the descriptor
  mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
  ret = rend_cache_store_v2_desc_as_dir("unparseable");
  tt_int_op(ret, OP_EQ, -1);

  // Test when we have an old descriptor
  generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
  ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
  tt_int_op(ret, OP_EQ, 0);

  rend_encoded_v2_service_descriptor_free(desc_holder);
  tor_free(service_id);

  // Test when we have a descriptor in the future
  generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
  ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
  tt_int_op(ret, OP_EQ, 0);

  rend_encoded_v2_service_descriptor_free(desc_holder);
  tor_free(service_id);

  // Test when two descriptors
  generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
  ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
  tt_int_op(ret, OP_EQ, 0);

  rend_encoded_v2_service_descriptor_free(desc_holder);
  tor_free(service_id);

  // Test when asking for hidden service statistics  HiddenServiceStatistics
  rend_cache_purge();
  generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
  get_options_mutable()->HiddenServiceStatistics = 1;
  ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
  tt_int_op(ret, OP_EQ, 0);

 done:
  NS_UNMOCK(router_get_my_routerinfo);
  rend_encoded_v2_service_descriptor_free(desc_holder);
  tor_free(service_id);
  rend_cache_free_all();
  tor_free(mock_routerinfo);
}
예제 #3
0
static void
test_rend_cache_purge(void *data)
{
  (void)data;

  // Deals with a NULL rend_cache
  rend_cache_purge();
  tt_assert(rend_cache);
  tt_assert(strmap_size(rend_cache) == 0);

  // Deals with existing rend_cache
  rend_cache_free_all();
  rend_cache_init();
  tt_assert(rend_cache);
  tt_assert(strmap_size(rend_cache) == 0);

  rend_cache_purge();
  tt_assert(rend_cache);
  tt_assert(strmap_size(rend_cache) == 0);

 done:
  rend_cache_free_all();
}
예제 #4
0
static void
test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
{
  (void)data;

  int ret;
  rend_service_descriptor_t *generated = NULL;
  smartlist_t *descs = smartlist_new();
  time_t t;
  char *service_id = NULL;
  rend_encoded_v2_service_descriptor_t *desc_holder_newer;
  rend_encoded_v2_service_descriptor_t *desc_holder_older;

  NS_MOCK(router_get_my_routerinfo);

  rend_cache_init();

  t = time(NULL);

  create_descriptor(&generated, &service_id, 3);
  generated->timestamp = t + RECENT_TIME;
  rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
                             REND_NO_AUTH, NULL, NULL);
  desc_holder_newer = ((rend_encoded_v2_service_descriptor_t *)
                       smartlist_get(descs, 0));
  smartlist_set(descs, 0, NULL);
  SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
                    rend_encoded_v2_service_descriptor_free(d));
  smartlist_free(descs);
  descs = smartlist_new();

  generated->timestamp = (t + RECENT_TIME) - 20;
  rend_encode_v2_descriptors(descs, generated, t + RECENT_TIME, 0,
                             REND_NO_AUTH, NULL, NULL);
  desc_holder_older = ((rend_encoded_v2_service_descriptor_t *)
                       smartlist_get(descs, 0));
  smartlist_set(descs, 0, NULL);

  // Test when we have a newer descriptor stored
  mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
  rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
  ret = rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
  tt_int_op(ret, OP_EQ, 0);

  // Test when we have an old descriptor stored
  rend_cache_purge();
  rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
  ret = rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
  tt_int_op(ret, OP_EQ, 0);

 done:
  NS_UNMOCK(router_get_my_routerinfo);
  rend_cache_free_all();
  rend_service_descriptor_free(generated);
  tor_free(service_id);
  SMARTLIST_FOREACH(descs, rend_encoded_v2_service_descriptor_t *, d,
                    rend_encoded_v2_service_descriptor_free(d));
  smartlist_free(descs);
  rend_encoded_v2_service_descriptor_free(desc_holder_newer);
  rend_encoded_v2_service_descriptor_free(desc_holder_older);
  tor_free(mock_routerinfo);
}