aboutsummaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@ev0ke.net>2015-03-11 14:52:28 -0400
committerDavid Goulet <dgoulet@ev0ke.net>2015-04-21 14:22:54 -0400
commit28cf9f2186a96bba74b0870b95a9fa1630305388 (patch)
tree6cb72af857cfeedb5ac200dece63581af4cb95be /src/or/control.c
parent59f8dced114f20a147a5425ece67d7d44a81867b (diff)
downloadtor-28cf9f2186a96bba74b0870b95a9fa1630305388.tar.gz
tor-28cf9f2186a96bba74b0870b95a9fa1630305388.zip
Control: unbolt rend_data from HS desc event
The HS_DESC event was using rend_data_t from the dir connection to reply the onion address and authentication type. With the new HSFETCH command, it's now possible to fetch a descriptor only using the descriptor id thus resulting in not having an onion address in any HS_DESC event. This patch removes rend_query from the hs desc control functions and replace it by an onion address string and an auth type. On a successful fetch, the service id is taken from the fetched descriptor. For that, an extra parameter is added to "store as a client" function that contains the cache entry stored. This will make the control event functions scale more easily over time if other values not present in rend_data_t are needed since the rend_data from the dir connection might not contained everything we need. Signed-off-by: David Goulet <dgoulet@ev0ke.net>
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c64
1 files changed, 45 insertions, 19 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 9258678e02..d5dc2f5ef3 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -5343,6 +5343,31 @@ node_describe_longname_by_id,(const char *id_digest))
return longname;
}
+
+/** Return either the onion address if the given pointer is a non empty
+ * string else the unknown string. */
+static const char *
+rend_hsaddress_str_or_unknown(const char *onion_address)
+{
+ static const char *str_unknown = "UNKNOWN";
+ const char *str_ret = str_unknown;
+
+ /* No valid pointer, unknown it is. */
+ if (!onion_address) {
+ goto end;
+ }
+ /* Empty onion address thus we don't know, unknown it is. */
+ if (onion_address[0] == '\0') {
+ goto end;
+ }
+ /* All checks are good so return the given onion address. */
+ str_ret = onion_address;
+
+end:
+ return str_ret;
+}
+
+
/** send HS_DESC requested event.
*
* <b>rend_query</b> is used to fetch requested onion address and auth type.
@@ -5363,7 +5388,7 @@ control_event_hs_descriptor_requested(const rend_data_t *rend_query,
send_control_event(EVENT_HS_DESC, ALL_FORMATS,
"650 HS_DESC REQUESTED %s %s %s %s\r\n",
- rend_query->onion_address,
+ rend_hsaddress_str_or_unknown(rend_query->onion_address),
rend_auth_type_to_string(rend_query->auth_type),
node_describe_longname_by_id(id_digest),
desc_id_base32);
@@ -5379,15 +5404,16 @@ control_event_hs_descriptor_requested(const rend_data_t *rend_query,
*/
void
control_event_hs_descriptor_receive_end(const char *action,
- const rend_data_t *rend_query,
+ const char *onion_address,
+ rend_auth_type_t auth_type,
const char *id_digest,
const char *reason)
{
char *reason_field = NULL;
- if (!action || !rend_query || !id_digest) {
- log_warn(LD_BUG, "Called with action==%p, rend_query==%p, "
- "id_digest==%p", action, rend_query, id_digest);
+ if (!action || !id_digest || !onion_address) {
+ log_warn(LD_BUG, "Called with action==%p, id_digest==%p "
+ "onion_address==%p", action, id_digest, onion_address);
return;
}
@@ -5398,8 +5424,8 @@ control_event_hs_descriptor_receive_end(const char *action,
send_control_event(EVENT_HS_DESC, ALL_FORMATS,
"650 HS_DESC %s %s %s %s%s\r\n",
action,
- rend_query->onion_address,
- rend_auth_type_to_string(rend_query->auth_type),
+ rend_hsaddress_str_or_unknown(onion_address),
+ rend_auth_type_to_string(auth_type),
node_describe_longname_by_id(id_digest),
reason_field ? reason_field : "");
@@ -5411,16 +5437,16 @@ control_event_hs_descriptor_receive_end(const char *action,
* called when a we successfully received a hidden service descriptor.
*/
void
-control_event_hs_descriptor_received(const rend_data_t *rend_query,
+control_event_hs_descriptor_received(const char *onion_address,
+ rend_auth_type_t auth_type,
const char *id_digest)
{
- if (!rend_query || !id_digest) {
- log_warn(LD_BUG, "Called with rend_query==%p, id_digest==%p",
- rend_query, id_digest);
+ if (!id_digest) {
+ log_warn(LD_BUG, "Called with id_digest==%p", id_digest);
return;
}
- control_event_hs_descriptor_receive_end("RECEIVED", rend_query,
- id_digest, NULL);
+ control_event_hs_descriptor_receive_end("RECEIVED", onion_address,
+ auth_type, id_digest, NULL);
}
/** Send HS_DESC event to inform controller that query <b>rend_query</b>
@@ -5429,16 +5455,16 @@ control_event_hs_descriptor_received(const rend_data_t *rend_query,
* field.
*/
void
-control_event_hs_descriptor_failed(const rend_data_t *rend_query,
+control_event_hs_descriptor_failed(const char *onion_address,
+ rend_auth_type_t auth_type,
const char *id_digest,
const char *reason)
{
- if (!rend_query || !id_digest) {
- log_warn(LD_BUG, "Called with rend_query==%p, id_digest==%p",
- rend_query, id_digest);
+ if (!id_digest) {
+ log_warn(LD_BUG, "Called with id_digest==%p", id_digest);
return;
}
- control_event_hs_descriptor_receive_end("FAILED", rend_query,
+ control_event_hs_descriptor_receive_end("FAILED", onion_address, auth_type,
id_digest, reason);
}
@@ -5465,7 +5491,7 @@ control_event_hs_descriptor_content(const char *onion_address,
send_control_event(EVENT_HS_DESC_CONTENT, ALL_FORMATS,
"650 %s %s %s %s\r\n%s",
event_name,
- onion_address,
+ rend_hsaddress_str_or_unknown(onion_address),
desc_id,
node_describe_longname_by_id(hsdir_id_digest),
esc_content);