summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-03-21 10:41:23 -0400
committerNick Mathewson <nickm@torproject.org>2016-03-21 10:41:23 -0400
commitddd30f966a4b186d42650e3b321da8352a19b5f5 (patch)
tree15307d22bca8ec051936472e4fd0cba99f84ad67 /src/or
parent70024ea6c4df8b2fe0c07fe5519d2c9683fc833b (diff)
parente28448a23e06e4bc997e1fdcca5af04a9d20598c (diff)
downloadtor-ddd30f966a4b186d42650e3b321da8352a19b5f5.tar.gz
tor-ddd30f966a4b186d42650e3b321da8352a19b5f5.zip
Merge remote-tracking branch 'arma/ticket18332-try3'
Diffstat (limited to 'src/or')
-rw-r--r--src/or/directory.c35
-rw-r--r--src/or/rendcache.c49
-rw-r--r--src/or/rendcache.h21
-rw-r--r--src/or/rendcommon.c69
-rw-r--r--src/or/rendcommon.h3
5 files changed, 38 insertions, 139 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index e4feda44fc..39fffc749e 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2297,11 +2297,8 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
{
rend_cache_entry_t *entry = NULL;
- switch (rend_cache_store_v2_desc_as_client(body,
- conn->requested_resource, conn->rend_data,
- &entry)) {
- case RCS_BADDESC:
- case RCS_NOTDIR: /* Impossible */
+ if (rend_cache_store_v2_desc_as_client(body,
+ conn->requested_resource, conn->rend_data, &entry) < 0) {
log_warn(LD_REND,"Fetching v2 rendezvous descriptor failed. "
"Retrying at another directory.");
/* We'll retry when connection_about_to_close_connection()
@@ -2309,11 +2306,9 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
SEND_HS_DESC_FAILED_EVENT("BAD_DESC");
SEND_HS_DESC_FAILED_CONTENT();
break;
- case RCS_OKAY:
- default:
- {
+ } else {
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);
rend_get_service_id(entry->parsed->pk, service_id);
@@ -2331,7 +2326,6 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
rend_client_desc_trynow(service_id);
memwipe(service_id, 0, sizeof(service_id));
break;
- }
}
break;
}
@@ -3418,6 +3412,13 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
conn->base_.state = DIR_CONN_STATE_SERVER_WRITING;
+ if (!public_server_mode(options)) {
+ log_info(LD_DIR, "Rejected dir post request from %s "
+ "since we're not a public relay.", conn->base_.address);
+ write_http_status_line(conn, 503, "Not acting as a public relay");
+ goto done;
+ }
+
if (parse_http_url(headers, &url) < 0) {
write_http_status_line(conn, 400, "Bad request");
return 0;
@@ -3427,22 +3428,12 @@ directory_handle_command_post(dir_connection_t *conn, const char *headers,
/* Handle v2 rendezvous service publish request. */
if (connection_dir_is_encrypted(conn) &&
!strcmpstart(url,"/tor/rendezvous2/publish")) {
- switch (rend_cache_store_v2_desc_as_dir(body)) {
- case RCS_NOTDIR:
- log_info(LD_REND, "Rejected v2 rend descriptor (length %d) from %s "
- "since we're not currently a hidden service directory.",
- (int)body_len, conn->base_.address);
- write_http_status_line(conn, 503, "Currently not acting as v2 "
- "hidden service directory");
- break;
- case RCS_BADDESC:
+ if (rend_cache_store_v2_desc_as_dir(body) < 0) {
log_warn(LD_REND, "Rejected v2 rend descriptor (length %d) from %s.",
(int)body_len, conn->base_.address);
write_http_status_line(conn, 400,
"Invalid v2 service descriptor rejected");
- break;
- case RCS_OKAY:
- default:
+ } else {
write_http_status_line(conn, 200, "Service descriptor (v2) stored");
log_info(LD_REND, "Handled v2 rendezvous descriptor post: accepted");
}
diff --git a/src/or/rendcache.c b/src/or/rendcache.c
index cb8c14b756..8b2d3ce6f7 100644
--- a/src/or/rendcache.c
+++ b/src/or/rendcache.c
@@ -483,8 +483,7 @@ rend_cache_clean_v2_descs_as_dir(time_t now, size_t force_remove)
digestmap_iter_get(iter, &key, &val);
ent = val;
if (ent->parsed->timestamp < cutoff ||
- ent->last_served < last_served_cutoff ||
- !hid_serv_responsible_for_desc_id(key)) {
+ ent->last_served < last_served_cutoff) {
char key_base32[REND_DESC_ID_V2_LEN_BASE32 + 1];
base32_encode(key_base32, sizeof(key_base32), key, DIGEST_LEN);
log_info(LD_REND, "Removing descriptor with ID '%s' from cache",
@@ -623,9 +622,11 @@ 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 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.
+ *
+ * We should only call this function for public (e.g. non bridge) relays.
*/
-rend_cache_store_status_t
+int
rend_cache_store_v2_desc_as_dir(const char *desc)
{
const or_options_t *options = get_options();
@@ -642,12 +643,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
time_t now = time(NULL);
tor_assert(rend_cache_v2_dir);
tor_assert(desc);
- if (!hid_serv_acting_as_directory()) {
- /* Cannot store descs, because we are (currently) not acting as
- * hidden service directory. */
- log_info(LD_REND, "Cannot store descs: Not acting as hs dir");
- return RCS_NOTDIR;
- }
while (rend_parse_v2_service_descriptor(&parsed, desc_id, &intro_content,
&intro_size, &encoded_size,
&next_desc, current_desc, 1) >= 0) {
@@ -657,14 +652,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
/* For pretty log statements. */
base32_encode(desc_id_base32, sizeof(desc_id_base32),
desc_id, DIGEST_LEN);
- /* Is desc ID in the range that we are (directly or indirectly) responsible
- * for? */
- if (!hid_serv_responsible_for_desc_id(desc_id)) {
- log_info(LD_REND, "Service descriptor with desc ID %s is not in "
- "interval that we are responsible for.",
- safe_str_client(desc_id_base32));
- goto skip;
- }
/* Is descriptor too old? */
if (parsed->timestamp < now - REND_CACHE_MAX_AGE-REND_CACHE_MAX_SKEW) {
log_info(LD_REND, "Service descriptor with desc ID %s is too old.",
@@ -732,11 +719,11 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
}
if (!number_parsed) {
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.",
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
@@ -746,9 +733,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 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_service_descriptor_t *parsed = NULL;
@@ -759,7 +746,7 @@ rend_cache_store_v2_desc_as_service(const char *desc)
const char *next_desc;
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
rend_cache_entry_t *e;
- rend_cache_store_status_t retval = RCS_BADDESC;
+ int retval = -1;
tor_assert(rend_cache_local_service);
tor_assert(desc);
@@ -802,10 +789,10 @@ rend_cache_store_v2_desc_as_service(const char *desc)
rend_cache_increment_allocation(rend_cache_entry_allocation(e));
log_debug(LD_REND,"Successfully stored rend desc '%s', len %d.",
safe_str_client(service_id), (int)encoded_size);
- return RCS_OKAY;
+ return 0;
okay:
- retval = RCS_OKAY;
+ retval = 0;
err:
rend_service_descriptor_free(parsed);
@@ -826,10 +813,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>,
* reject it.
*
- * Return an appropriate rend_cache_store_status_t. If entry is not NULL,
- * set it with the cache entry pointer of the descriptor.
+ * Return 0 on success, or -1 if we rejected 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,
const char *desc_id_base32,
const rend_data_t *rend_query,
@@ -861,7 +848,7 @@ rend_cache_store_v2_desc_as_client(const char *desc,
char service_id[REND_SERVICE_ID_LEN_BASE32+1];
char want_desc_id[DIGEST_LEN];
rend_cache_entry_t *e;
- rend_cache_store_status_t retval = RCS_BADDESC;
+ int retval = -1;
tor_assert(rend_cache);
tor_assert(desc);
tor_assert(desc_id_base32);
@@ -1008,13 +995,13 @@ rend_cache_store_v2_desc_as_client(const char *desc,
if (entry) {
*entry = e;
}
- return RCS_OKAY;
+ return 0;
okay:
if (entry) {
*entry = e;
}
- retval = RCS_OKAY;
+ retval = 0;
err:
rend_service_descriptor_free(parsed);
diff --git a/src/or/rendcache.h b/src/or/rendcache.h
index 867270f996..0e8b918753 100644
--- a/src/or/rendcache.h
+++ b/src/or/rendcache.h
@@ -64,20 +64,13 @@ int rend_cache_lookup_entry(const char *query, int version,
int rend_cache_lookup_v2_desc_as_service(const char *query,
rend_cache_entry_t **entry_out);
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_NOTDIR = -2, /**< We're not a directory */
- 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);
-rend_cache_store_status_t rend_cache_store_v2_desc_as_service(
- const char *desc);
-rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
- const char *desc_id_base32,
- const rend_data_t *rend_query,
- rend_cache_entry_t **entry);
+
+int rend_cache_store_v2_desc_as_dir(const char *desc);
+int rend_cache_store_v2_desc_as_service(const char *desc);
+int rend_cache_store_v2_desc_as_client(const char *desc,
+ const char *desc_id_base32,
+ const rend_data_t *rend_query,
+ rend_cache_entry_t **entry);
size_t rend_cache_get_total_allocation(void);
void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 603e4f0dd9..438fbc4d9a 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -688,37 +688,6 @@ rend_get_service_id(crypto_pk_t *pk, char *out)
return 0;
}
-/** Determines whether <b>a</b> is in the interval of <b>b</b> (excluded) and
- * <b>c</b> (included) in a circular digest ring; returns 1 if this is the
- * case, and 0 otherwise.
- */
-int
-rend_id_is_in_interval(const char *a, const char *b, const char *c)
-{
- int a_b, b_c, c_a;
- tor_assert(a);
- tor_assert(b);
- tor_assert(c);
-
- /* There are five cases in which a is outside the interval ]b,c]: */
- a_b = tor_memcmp(a,b,DIGEST_LEN);
- if (a_b == 0)
- return 0; /* 1. a == b (b is excluded) */
- b_c = tor_memcmp(b,c,DIGEST_LEN);
- if (b_c == 0)
- return 0; /* 2. b == c (interval is empty) */
- else if (a_b <= 0 && b_c < 0)
- return 0; /* 3. a b c */
- c_a = tor_memcmp(c,a,DIGEST_LEN);
- if (c_a < 0 && a_b <= 0)
- return 0; /* 4. c a b */
- else if (b_c < 0 && c_a < 0)
- return 0; /* 5. b c a */
-
- /* In the other cases (a c b; b a c; c b a), a is inside the interval. */
- return 1;
-}
-
/** Return true iff <b>query</b> is a syntactically valid service ID (as
* generated by rend_get_service_id). */
int
@@ -972,41 +941,3 @@ hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
return smartlist_len(responsible_dirs) ? 0 : -1;
}
-/** Return true if this node is currently acting as hidden service
- * directory, false otherwise. */
-int
-hid_serv_acting_as_directory(void)
-{
- const routerinfo_t *me = router_get_my_routerinfo();
- if (!me)
- return 0;
- return 1;
-}
-
-/** Return true if this node is responsible for storing the descriptor ID
- * in <b>query</b> and false otherwise. */
-MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
- (const char *query))
-{
- const routerinfo_t *me;
- routerstatus_t *last_rs;
- const char *my_id, *last_id;
- int result;
- smartlist_t *responsible;
- if (!hid_serv_acting_as_directory())
- return 0;
- if (!(me = router_get_my_routerinfo()))
- return 0; /* This is redundant, but let's be paranoid. */
- my_id = me->cache_info.identity_digest;
- responsible = smartlist_new();
- if (hid_serv_get_responsible_directories(responsible, query) < 0) {
- smartlist_free(responsible);
- return 0;
- }
- last_rs = smartlist_get(responsible, smartlist_len(responsible)-1);
- last_id = last_rs->identity_digest;
- result = rend_id_is_in_interval(my_id, query, last_id);
- smartlist_free(responsible);
- return result;
-}
-
diff --git a/src/or/rendcommon.h b/src/or/rendcommon.h
index 7d81976013..d67552e405 100644
--- a/src/or/rendcommon.h
+++ b/src/or/rendcommon.h
@@ -53,14 +53,11 @@ int rend_encode_v2_descriptors(smartlist_t *descs_out,
int rend_compute_v2_desc_id(char *desc_id_out, const char *service_id,
const char *descriptor_cookie,
time_t now, uint8_t replica);
-int rend_id_is_in_interval(const char *a, const char *b, const char *c);
void rend_get_descriptor_id_bytes(char *descriptor_id_out,
const char *service_id,
const char *secret_id_part);
int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
const char *id);
-int hid_serv_acting_as_directory(void);
-MOCK_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
rend_data_t *rend_data_dup(const rend_data_t *data);
rend_data_t *rend_data_client_create(const char *onion_address,