aboutsummaryrefslogtreecommitdiff
path: root/src/or/control.c
diff options
context:
space:
mode:
authorQingping Hou <dave2008713@gmail.com>2013-10-09 11:13:06 -0400
committerQingping Hou <dave2008713@gmail.com>2014-01-29 22:23:57 -0500
commit29c18f5b71d73a03b9895fbbf97a3a5a16099a50 (patch)
tree3e59a10e4a958de118075a05aebd298db5f40993 /src/or/control.c
parent3b38fd87e812a104f835af59abeda012928e21b7 (diff)
downloadtor-29c18f5b71d73a03b9895fbbf97a3a5a16099a50.tar
tor-29c18f5b71d73a03b9895fbbf97a3a5a16099a50.tar.gz
add hidden service descriptor async control event
Diffstat (limited to 'src/or/control.c')
-rw-r--r--src/or/control.c92
1 files changed, 91 insertions, 1 deletions
diff --git a/src/or/control.c b/src/or/control.c
index 49212de65..42fbf2f91 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -940,6 +940,7 @@ static const struct control_event_t control_event_table[] = {
{ EVENT_TB_EMPTY, "TB_EMPTY" },
{ EVENT_CIRC_BANDWIDTH_USED, "CIRC_BW" },
{ EVENT_TRANSPORT_LAUNCHED, "TRANSPORT_LAUNCHED" },
+ { EVENT_HS_DESC, "HS_DESC" },
{ 0, NULL },
};
@@ -1549,7 +1550,7 @@ munge_extrainfo_into_routerinfo(const char *ri_body,
outp += router_sig-ri_body;
for (i=0; i < 2; ++i) {
- const char *kwd = i?"\nwrite-history ":"\nread-history ";
+ const char *kwd = i ? "\nwrite-history " : "\nread-history ";
const char *cp, *eol;
if (!(cp = tor_memstr(ei_body, ei_len, kwd)))
continue;
@@ -4998,6 +4999,95 @@ control_event_transport_launched(const char *mode, const char *transport_name,
mode, transport_name, fmt_addr(addr), port);
}
+/** Convert rendezvous auth type to string for HS_DESC control events
+ */
+const char *
+rend_auth_type_to_string(rend_auth_type_t auth_type)
+{
+ const char *str;
+
+ switch (auth_type) {
+ case REND_NO_AUTH:
+ str = "NO_AUTH";
+ break;
+ case REND_BASIC_AUTH:
+ str = "BASIC_AUTH";
+ break;
+ case REND_STEALTH_AUTH:
+ str = "STEALTH_AUTH";
+ break;
+ default:
+ str = "UNKNOWN";
+ }
+
+ return str;
+}
+
+/** send HS_DESC requested event.
+ *
+ * <b>rend_query</b> is used to fetch requested onion address and auth type.
+ * <b>hs_dir</b> is the description of contacting hs directory.
+ * <b>desc_id_base32</b> is the ID of requested hs descriptor.
+ */
+void
+control_event_hs_descriptor_requested(const rend_data_t *rend_query,
+ const char *hs_dir,
+ const char *desc_id_base32)
+{
+ tor_assert(hs_dir);
+ send_control_event(EVENT_HS_DESC, ALL_FORMATS,
+ "650 HS_DESC REQUESTED %s %s %s %s\r\n",
+ rend_query->onion_address,
+ rend_auth_type_to_string(rend_query->auth_type),
+ hs_dir,
+ desc_id_base32);
+}
+
+/** send HS_DESC event after got response from hs directory.
+ *
+ * NOTE: this is an internal function used by following functions:
+ * control_event_hs_descriptor_received
+ * control_event_hs_descriptor_failed
+ *
+ * So do not call this function directly.
+ */
+void
+control_event_hs_descriptor_receive_end(const char *action,
+ const rend_data_t *rend_query,
+ const char *hs_dir)
+{
+ send_control_event(EVENT_HS_DESC, ALL_FORMATS,
+ "650 HS_DESC %s %s %s %s\r\n",
+ action,
+ rend_query->onion_address,
+ rend_auth_type_to_string(rend_query->auth_type),
+ hs_dir);
+}
+
+/** send HS_DESC RECEIVED event
+ *
+ * called when a we successfully received a hidden service descriptor.
+ */
+void
+control_event_hs_descriptor_received(const rend_data_t *rend_query,
+ const char *hs_dir)
+{
+ tor_assert(hs_dir);
+ control_event_hs_descriptor_receive_end("RECEIVED", rend_query, hs_dir);
+}
+
+/** send HS_DESC FAILED event
+ *
+ * called when request for hidden service descriptor returned failure.
+ */
+void
+control_event_hs_descriptor_failed(const rend_data_t *rend_query,
+ const char *hs_dir)
+{
+ tor_assert(hs_dir);
+ control_event_hs_descriptor_receive_end("FAILED", rend_query, hs_dir);
+}
+
/** Free any leftover allocated memory of the control.c subsystem. */
void
control_free_all(void)