mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
simplify rend_cache_store_status_t back to a boolean
it used to be a tri-state, but now it's just a bi-state, so we can take out all the machinery like the enum.
This commit is contained in:
parent
dc500c8cb4
commit
edeba3d472
@ -2297,10 +2297,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
|||||||
{
|
{
|
||||||
rend_cache_entry_t *entry = NULL;
|
rend_cache_entry_t *entry = NULL;
|
||||||
|
|
||||||
switch (rend_cache_store_v2_desc_as_client(body,
|
if (rend_cache_store_v2_desc_as_client(body,
|
||||||
conn->requested_resource, conn->rend_data,
|
conn->requested_resource, conn->rend_data, &entry) < 0) {
|
||||||
&entry)) {
|
|
||||||
case RCS_BADDESC:
|
|
||||||
log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
|
log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
|
||||||
"Retrying at another directory.");
|
"Retrying at another directory.");
|
||||||
/* We'll retry when connection_about_to_close_connection()
|
/* We'll retry when connection_about_to_close_connection()
|
||||||
@ -2308,11 +2306,9 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
|||||||
SEND_HS_DESC_FAILED_EVENT("BAD_DESC");
|
SEND_HS_DESC_FAILED_EVENT("BAD_DESC");
|
||||||
SEND_HS_DESC_FAILED_CONTENT();
|
SEND_HS_DESC_FAILED_CONTENT();
|
||||||
break;
|
break;
|
||||||
case RCS_OKAY:
|
} else {
|
||||||
default:
|
|
||||||
{
|
|
||||||
char service_id[REND_SERVICE_ID_LEN_BASE32 + 1];
|
char service_id[REND_SERVICE_ID_LEN_BASE32 + 1];
|
||||||
/* Should never be NULL here for an OKAY returned code. */
|
/* Should never be NULL here if we found the descriptor. */
|
||||||
tor_assert(entry);
|
tor_assert(entry);
|
||||||
rend_get_service_id(entry->parsed->pk, service_id);
|
rend_get_service_id(entry->parsed->pk, service_id);
|
||||||
|
|
||||||
@ -2331,7 +2327,6 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
|
|||||||
memwipe(service_id, 0, sizeof(service_id));
|
memwipe(service_id, 0, sizeof(service_id));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 404:
|
case 404:
|
||||||
@ -3426,15 +3421,12 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
|
|||||||
/* Handle v2 rendezvous service publish request. */
|
/* Handle v2 rendezvous service publish request. */
|
||||||
if (connection_dir_is_encrypted(conn) &&
|
if (connection_dir_is_encrypted(conn) &&
|
||||||
!strcmpstart(url,"/tor/rendezvous2/publish")) {
|
!strcmpstart(url,"/tor/rendezvous2/publish")) {
|
||||||
switch (rend_cache_store_v2_desc_as_dir(body)) {
|
if (rend_cache_store_v2_desc_as_dir(body) < 0) {
|
||||||
case RCS_BADDESC:
|
|
||||||
log_warn(LD_REND, "Rejected v2 rend descriptor (length %d) from %s.",
|
log_warn(LD_REND, "Rejected v2 rend descriptor (length %d) from %s.",
|
||||||
(int)body_len, conn->base_.address);
|
(int)body_len, conn->base_.address);
|
||||||
write_http_status_line(conn, 400,
|
write_http_status_line(conn, 400,
|
||||||
"Invalid v2 service descriptor rejected");
|
"Invalid v2 service descriptor rejected");
|
||||||
break;
|
} else {
|
||||||
case RCS_OKAY:
|
|
||||||
default:
|
|
||||||
write_http_status_line(conn, 200, "Service descriptor (v2) stored");
|
write_http_status_line(conn, 200, "Service descriptor (v2) stored");
|
||||||
log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
|
log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
|
||||||
}
|
}
|
||||||
|
@ -622,9 +622,9 @@ rend_cache_lookup_v2_desc_as_dir(const char *desc_id, const char **desc)
|
|||||||
* If we have a newer descriptor with the same ID, ignore this one.
|
* If we have a newer descriptor with the same ID, ignore this one.
|
||||||
* If we have an older descriptor with the same ID, replace it.
|
* If we have an older descriptor with the same ID, replace it.
|
||||||
*
|
*
|
||||||
* Return an appropriate rend_cache_store_status_t.
|
* Return 0 on success, or -1 if we couldn't parse any of them.
|
||||||
*/
|
*/
|
||||||
rend_cache_store_status_t
|
int
|
||||||
rend_cache_store_v2_desc_as_dir(const char *desc)
|
rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||||
{
|
{
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
@ -717,11 +717,11 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
|||||||
}
|
}
|
||||||
if (!number_parsed) {
|
if (!number_parsed) {
|
||||||
log_info(LD_REND, "Could not parse any descriptor.");
|
log_info(LD_REND, "Could not parse any descriptor.");
|
||||||
return RCS_BADDESC;
|
return -1;
|
||||||
}
|
}
|
||||||
log_info(LD_REND, "Parsed %d and added %d descriptor%s.",
|
log_info(LD_REND, "Parsed %d and added %d descriptor%s.",
|
||||||
number_parsed, number_stored, number_stored != 1 ? "s" : "");
|
number_parsed, number_stored, number_stored != 1 ? "s" : "");
|
||||||
return RCS_OKAY;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Parse the v2 service descriptor in <b>desc</b> and store it to the
|
/** Parse the v2 service descriptor in <b>desc</b> and store it to the
|
||||||
@ -731,9 +731,9 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
|||||||
* If we have a newer descriptor with the same ID, ignore this one.
|
* If we have a newer descriptor with the same ID, ignore this one.
|
||||||
* If we have an older descriptor with the same ID, replace it.
|
* If we have an older descriptor with the same ID, replace it.
|
||||||
*
|
*
|
||||||
* Return an appropriate rend_cache_store_status_t.
|
* Return 0 on success, or -1 if we couldn't understand the descriptor.
|
||||||
*/
|
*/
|
||||||
rend_cache_store_status_t
|
int
|
||||||
rend_cache_store_v2_desc_as_service(const char *desc)
|
rend_cache_store_v2_desc_as_service(const char *desc)
|
||||||
{
|
{
|
||||||
rend_service_descriptor_t *parsed = NULL;
|
rend_service_descriptor_t *parsed = NULL;
|
||||||
@ -744,7 +744,7 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
|||||||
const char *next_desc;
|
const char *next_desc;
|
||||||
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
||||||
rend_cache_entry_t *e;
|
rend_cache_entry_t *e;
|
||||||
rend_cache_store_status_t retval = RCS_BADDESC;
|
int retval = -1;
|
||||||
tor_assert(rend_cache_local_service);
|
tor_assert(rend_cache_local_service);
|
||||||
tor_assert(desc);
|
tor_assert(desc);
|
||||||
|
|
||||||
@ -787,10 +787,10 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
|||||||
rend_cache_increment_allocation(rend_cache_entry_allocation(e));
|
rend_cache_increment_allocation(rend_cache_entry_allocation(e));
|
||||||
log_debug(LD_REND,"Successfully stored rend desc '%s', len %d.",
|
log_debug(LD_REND,"Successfully stored rend desc '%s', len %d.",
|
||||||
safe_str_client(service_id), (int)encoded_size);
|
safe_str_client(service_id), (int)encoded_size);
|
||||||
return RCS_OKAY;
|
return 0;
|
||||||
|
|
||||||
okay:
|
okay:
|
||||||
retval = RCS_OKAY;
|
retval = 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
rend_service_descriptor_free(parsed);
|
rend_service_descriptor_free(parsed);
|
||||||
@ -811,10 +811,10 @@ rend_cache_store_v2_desc_as_service(const char *desc)
|
|||||||
* If the descriptor's descriptor ID doesn't match <b>desc_id_base32</b>,
|
* If the descriptor's descriptor ID doesn't match <b>desc_id_base32</b>,
|
||||||
* reject it.
|
* reject it.
|
||||||
*
|
*
|
||||||
* Return an appropriate rend_cache_store_status_t. If entry is not NULL,
|
* Return 0 on success, or -1 if we rejected the descriptor.
|
||||||
* set it with the cache entry pointer of the descriptor.
|
* If entry is not NULL, set it with the cache entry pointer of the descriptor.
|
||||||
*/
|
*/
|
||||||
rend_cache_store_status_t
|
int
|
||||||
rend_cache_store_v2_desc_as_client(const char *desc,
|
rend_cache_store_v2_desc_as_client(const char *desc,
|
||||||
const char *desc_id_base32,
|
const char *desc_id_base32,
|
||||||
const rend_data_t *rend_query,
|
const rend_data_t *rend_query,
|
||||||
@ -846,7 +846,7 @@ rend_cache_store_v2_desc_as_client(const char *desc,
|
|||||||
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
|
||||||
char want_desc_id[DIGEST_LEN];
|
char want_desc_id[DIGEST_LEN];
|
||||||
rend_cache_entry_t *e;
|
rend_cache_entry_t *e;
|
||||||
rend_cache_store_status_t retval = RCS_BADDESC;
|
int retval = -1;
|
||||||
tor_assert(rend_cache);
|
tor_assert(rend_cache);
|
||||||
tor_assert(desc);
|
tor_assert(desc);
|
||||||
tor_assert(desc_id_base32);
|
tor_assert(desc_id_base32);
|
||||||
@ -993,13 +993,13 @@ rend_cache_store_v2_desc_as_client(const char *desc,
|
|||||||
if (entry) {
|
if (entry) {
|
||||||
*entry = e;
|
*entry = e;
|
||||||
}
|
}
|
||||||
return RCS_OKAY;
|
return 0;
|
||||||
|
|
||||||
okay:
|
okay:
|
||||||
if (entry) {
|
if (entry) {
|
||||||
*entry = e;
|
*entry = e;
|
||||||
}
|
}
|
||||||
retval = RCS_OKAY;
|
retval = 0;
|
||||||
|
|
||||||
err:
|
err:
|
||||||
rend_service_descriptor_free(parsed);
|
rend_service_descriptor_free(parsed);
|
||||||
|
@ -64,16 +64,10 @@ int rend_cache_lookup_entry(const char *query, int version,
|
|||||||
int rend_cache_lookup_v2_desc_as_service(const char *query,
|
int rend_cache_lookup_v2_desc_as_service(const char *query,
|
||||||
rend_cache_entry_t **entry_out);
|
rend_cache_entry_t **entry_out);
|
||||||
int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
|
int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
|
||||||
/** Return value from rend_cache_store_v2_desc_as_{dir,client}. */
|
|
||||||
typedef enum {
|
|
||||||
RCS_BADDESC = -1, /**< This descriptor is no good. */
|
|
||||||
RCS_OKAY = 0 /**< All worked as expected */
|
|
||||||
} rend_cache_store_status_t;
|
|
||||||
|
|
||||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_dir(const char *desc);
|
int rend_cache_store_v2_desc_as_dir(const char *desc);
|
||||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_service(
|
int rend_cache_store_v2_desc_as_service(const char *desc);
|
||||||
const char *desc);
|
int rend_cache_store_v2_desc_as_client(const char *desc,
|
||||||
rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
|
|
||||||
const char *desc_id_base32,
|
const char *desc_id_base32,
|
||||||
const rend_data_t *rend_query,
|
const rend_data_t *rend_query,
|
||||||
rend_cache_entry_t **entry);
|
rend_cache_entry_t **entry);
|
||||||
|
@ -427,7 +427,7 @@ test_dir_handle_get_rendezvous2_on_encrypted_conn_success(void *data)
|
|||||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||||
|
|
||||||
tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
|
tt_int_op(rend_cache_store_v2_desc_as_dir(desc_holder->desc_str),
|
||||||
OP_EQ, RCS_OKAY);
|
OP_EQ, 0);
|
||||||
|
|
||||||
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
|
base32_encode(desc_id_base32, sizeof(desc_id_base32), desc_holder->desc_id,
|
||||||
DIGEST_LEN);
|
DIGEST_LEN);
|
||||||
|
@ -91,7 +91,7 @@ test_rend_cache_lookup_entry(void *data)
|
|||||||
static void
|
static void
|
||||||
test_rend_cache_store_v2_desc_as_client(void *data)
|
test_rend_cache_store_v2_desc_as_client(void *data)
|
||||||
{
|
{
|
||||||
rend_cache_store_status_t ret;
|
int ret;
|
||||||
rend_data_t *mock_rend_query;
|
rend_data_t *mock_rend_query;
|
||||||
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||||
rend_cache_entry_t *entry = NULL;
|
rend_cache_entry_t *entry = NULL;
|
||||||
@ -112,7 +112,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
&entry);
|
&entry);
|
||||||
|
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
tt_assert(entry);
|
tt_assert(entry);
|
||||||
tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str));
|
tt_int_op(entry->len, OP_EQ, strlen(desc_holder->desc_str));
|
||||||
tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
|
tt_str_op(entry->desc, OP_EQ, desc_holder->desc_str);
|
||||||
@ -124,7 +124,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
/* desc_holder->desc_str, */
|
/* desc_holder->desc_str, */
|
||||||
/* "3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG", */
|
/* "3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG3TOOLONG", */
|
||||||
/* &mock_rend_query, NULL); */
|
/* &mock_rend_query, NULL); */
|
||||||
/* tt_int_op(ret, OP_EQ, RCS_BADDESC); */
|
/* tt_int_op(ret, OP_EQ, -1); */
|
||||||
|
|
||||||
// Test bad base32 failure
|
// Test bad base32 failure
|
||||||
// This causes an assertion failure if we're running with assertions.
|
// This causes an assertion failure if we're running with assertions.
|
||||||
@ -132,13 +132,13 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
#ifdef DISABLE_ASSERTS_IN_UNIT_TESTS
|
#ifdef DISABLE_ASSERTS_IN_UNIT_TESTS
|
||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
"!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
|
"!xqunszqnaolrrfmtzgaki7mxelgvkj", mock_rend_query, NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Test invalid descriptor
|
// Test invalid descriptor
|
||||||
ret = rend_cache_store_v2_desc_as_client("invalid descriptor",
|
ret = rend_cache_store_v2_desc_as_client("invalid descriptor",
|
||||||
"3xqunszqnaolrrfmtzgaki7mxelgvkje", mock_rend_query, NULL);
|
"3xqunszqnaolrrfmtzgaki7mxelgvkje", mock_rend_query, NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
|
|
||||||
// TODO: it doesn't seem to be possible to test invalid service ID condition.
|
// TODO: it doesn't seem to be possible to test invalid service ID condition.
|
||||||
// that means it is likely not possible to have that condition without
|
// that means it is likely not possible to have that condition without
|
||||||
@ -152,7 +152,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32,
|
desc_id_base32,
|
||||||
mock_rend_query, NULL);
|
mock_rend_query, NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
rend_data_free(mock_rend_query);
|
rend_data_free(mock_rend_query);
|
||||||
|
|
||||||
@ -163,7 +163,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
desc_id_base32[0]--;
|
desc_id_base32[0]--;
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32,
|
desc_id_base32,
|
||||||
mock_rend_query, NULL);
|
mock_rend_query, NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
// Test too new descriptor (in the future)
|
// Test too new descriptor (in the future)
|
||||||
@ -198,7 +198,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
// Test when a descriptor is already in the cache
|
// Test when a descriptor is already in the cache
|
||||||
@ -217,12 +217,12 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
&entry);
|
&entry);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
tt_assert(entry);
|
tt_assert(entry);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
// Test successful run when we have REND_BASIC_AUTH but not cookie
|
// Test successful run when we have REND_BASIC_AUTH but not cookie
|
||||||
@ -260,7 +260,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
@ -277,7 +277,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
// Test when we have too many intro points
|
// Test when we have too many intro points
|
||||||
@ -293,7 +293,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||||
@ -305,7 +305,7 @@ test_rend_cache_store_v2_desc_as_client(void *data)
|
|||||||
static void
|
static void
|
||||||
test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
||||||
{
|
{
|
||||||
rend_cache_store_status_t ret;
|
int ret;
|
||||||
rend_data_t *mock_rend_query;
|
rend_data_t *mock_rend_query;
|
||||||
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
char desc_id_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
|
||||||
rend_service_descriptor_t *generated = NULL;
|
rend_service_descriptor_t *generated = NULL;
|
||||||
@ -350,7 +350,7 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder_older->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
rend_cache_free_all();
|
rend_cache_free_all();
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ test_rend_cache_store_v2_desc_as_client_with_different_time(void *data)
|
|||||||
ret = rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
|
ret = rend_cache_store_v2_desc_as_client(desc_holder_newer->desc_str,
|
||||||
desc_id_base32, mock_rend_query,
|
desc_id_base32, mock_rend_query,
|
||||||
NULL);
|
NULL);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
rend_encoded_v2_service_descriptor_free(desc_holder_newer);
|
rend_encoded_v2_service_descriptor_free(desc_holder_newer);
|
||||||
@ -446,7 +446,7 @@ static void
|
|||||||
test_rend_cache_store_v2_desc_as_dir(void *data)
|
test_rend_cache_store_v2_desc_as_dir(void *data)
|
||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
rend_cache_store_status_t ret;
|
int ret;
|
||||||
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
|
rend_encoded_v2_service_descriptor_t *desc_holder = NULL;
|
||||||
char *service_id = NULL;
|
char *service_id = NULL;
|
||||||
|
|
||||||
@ -457,12 +457,12 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
|||||||
// Test when we can't parse the descriptor
|
// Test when we can't parse the descriptor
|
||||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||||
ret = rend_cache_store_v2_desc_as_dir("unparseable");
|
ret = rend_cache_store_v2_desc_as_dir("unparseable");
|
||||||
tt_int_op(ret, OP_EQ, RCS_BADDESC);
|
tt_int_op(ret, OP_EQ, -1);
|
||||||
|
|
||||||
// Test when we have an old descriptor
|
// Test when we have an old descriptor
|
||||||
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
|
generate_desc(TIME_IN_THE_PAST, &desc_holder, &service_id, 3);
|
||||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||||
tor_free(service_id);
|
tor_free(service_id);
|
||||||
@ -470,7 +470,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
|||||||
// Test when we have a descriptor in the future
|
// Test when we have a descriptor in the future
|
||||||
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
||||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||||
tor_free(service_id);
|
tor_free(service_id);
|
||||||
@ -478,7 +478,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
|||||||
// Test when two descriptors
|
// Test when two descriptors
|
||||||
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
generate_desc(TIME_IN_THE_FUTURE, &desc_holder, &service_id, 3);
|
||||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
rend_encoded_v2_service_descriptor_free(desc_holder);
|
rend_encoded_v2_service_descriptor_free(desc_holder);
|
||||||
tor_free(service_id);
|
tor_free(service_id);
|
||||||
@ -488,7 +488,7 @@ test_rend_cache_store_v2_desc_as_dir(void *data)
|
|||||||
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
generate_desc(RECENT_TIME, &desc_holder, &service_id, 3);
|
||||||
get_options_mutable()->HiddenServiceStatistics = 1;
|
get_options_mutable()->HiddenServiceStatistics = 1;
|
||||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
NS_UNMOCK(router_get_my_routerinfo);
|
NS_UNMOCK(router_get_my_routerinfo);
|
||||||
@ -503,7 +503,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
|||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
rend_cache_store_status_t ret;
|
int ret;
|
||||||
rend_service_descriptor_t *generated = NULL;
|
rend_service_descriptor_t *generated = NULL;
|
||||||
smartlist_t *descs = smartlist_new();
|
smartlist_t *descs = smartlist_new();
|
||||||
time_t t;
|
time_t t;
|
||||||
@ -540,13 +540,13 @@ test_rend_cache_store_v2_desc_as_dir_with_different_time(void *data)
|
|||||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||||
rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
|
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);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
// Test when we have an old descriptor stored
|
// Test when we have an old descriptor stored
|
||||||
rend_cache_purge();
|
rend_cache_purge();
|
||||||
rend_cache_store_v2_desc_as_dir(desc_holder_older->desc_str);
|
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);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder_newer->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
NS_UNMOCK(router_get_my_routerinfo);
|
NS_UNMOCK(router_get_my_routerinfo);
|
||||||
@ -566,7 +566,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
|||||||
{
|
{
|
||||||
(void)data;
|
(void)data;
|
||||||
|
|
||||||
rend_cache_store_status_t ret;
|
int ret;
|
||||||
rend_service_descriptor_t *generated = NULL;
|
rend_service_descriptor_t *generated = NULL;
|
||||||
smartlist_t *descs = smartlist_new();
|
smartlist_t *descs = smartlist_new();
|
||||||
time_t t;
|
time_t t;
|
||||||
@ -605,7 +605,7 @@ test_rend_cache_store_v2_desc_as_dir_with_different_content(void *data)
|
|||||||
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
mock_routerinfo = tor_malloc(sizeof(routerinfo_t));
|
||||||
rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
|
rend_cache_store_v2_desc_as_dir(desc_holder_one->desc_str);
|
||||||
ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
|
ret = rend_cache_store_v2_desc_as_dir(desc_holder_two->desc_str);
|
||||||
tt_int_op(ret, OP_EQ, RCS_OKAY);
|
tt_int_op(ret, OP_EQ, 0);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
NS_UNMOCK(router_get_my_routerinfo);
|
NS_UNMOCK(router_get_my_routerinfo);
|
||||||
|
Loading…
Reference in New Issue
Block a user