commit 3b436d495fc6ad59ff5d9406d7ef17494286c299 Author: David Goulet dgoulet@torproject.org Date: Fri Nov 10 14:12:34 2017 -0500
hs-v3: Implement HS_DESC RECEIVED event
Adds a v3 specific function to handle a received event.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/or/control.c | 23 +++++++++++++++++++++++ src/or/control.h | 3 +++ src/or/directory.c | 2 ++ src/or/hs_control.c | 25 +++++++++++++++++++++++++ src/or/hs_control.h | 4 ++++ 5 files changed, 57 insertions(+)
diff --git a/src/or/control.c b/src/or/control.c index 3ba3a4b3a..a1515da05 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -7398,6 +7398,29 @@ control_event_hsv2_descriptor_received(const char *onion_address, tor_free(desc_id_field); }
+/* Send HS_DESC RECEIVED event + * + * Called when we successfully received a hidden service descriptor. */ +void +control_event_hsv3_descriptor_received(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest) +{ + char *desc_id_field = NULL; + + if (BUG(!onion_address || !desc_id || !hsdir_id_digest)) { + return; + } + + /* Because DescriptorID is an optional positional value, we need to add a + * whitespace before in order to not be next to the HsDir value. */ + tor_asprintf(&desc_id_field, " %s", desc_id); + + event_hs_descriptor_receive_end("RECEIVED", onion_address, desc_id_field, + REND_NO_AUTH, hsdir_id_digest, NULL); + tor_free(desc_id_field); +} + /** send HS_DESC UPLOADED event * * called when we successfully uploaded a hidden service descriptor. diff --git a/src/or/control.h b/src/or/control.h index 4c9adb681..c11f6a07b 100644 --- a/src/or/control.h +++ b/src/or/control.h @@ -144,6 +144,9 @@ void control_event_hsv3_descriptor_failed(const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *reason); +void control_event_hsv3_descriptor_received(const char *onion_address, + const char *desc_id, + const char *hsdir_id_digest); void control_event_hs_descriptor_upload_failed(const char *hs_dir, const char *onion_address, const char *reason); diff --git a/src/or/directory.c b/src/or/directory.c index 1b6f7500b..a1d9c8c08 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -3098,6 +3098,8 @@ handle_response_fetch_hsdesc_v3(dir_connection_t *conn, log_info(LD_REND, "Stored hidden service descriptor successfully."); TO_CONN(conn)->purpose = DIR_PURPOSE_HAS_FETCHED_HSDESC; hs_client_desc_has_arrived(conn->hs_ident); + /* Fire control port RECEIVED event. */ + hs_control_desc_event_received(conn->hs_ident, conn->identity_digest); } break; case 404: diff --git a/src/or/hs_control.c b/src/or/hs_control.c index ed77c8e1d..add62d583 100644 --- a/src/or/hs_control.c +++ b/src/or/hs_control.c @@ -77,3 +77,28 @@ hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, hsdir_id_digest, reason); }
+/* Send on the control port the "HS_DESC RECEIVED [...]" event. + * + * Using a directory connection identifier and the HSDir identity digest. + * None can be NULL. */ +void +hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest) +{ + char onion_address[HS_SERVICE_ADDR_LEN_BASE32 + 1]; + char base64_blinded_pk[ED25519_BASE64_LEN + 1]; + + tor_assert(ident); + tor_assert(hsdir_id_digest); + + /* Build onion address and encoded blinded key. */ + IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, + &ident->blinded_pk) < 0) { + return; + } + hs_build_address(&ident->identity_pk, HS_VERSION_THREE, onion_address); + + control_event_hsv3_descriptor_received(onion_address, base64_blinded_pk, + hsdir_id_digest); +} + diff --git a/src/or/hs_control.h b/src/or/hs_control.h index fb8f3859f..33a96cec0 100644 --- a/src/or/hs_control.h +++ b/src/or/hs_control.h @@ -21,5 +21,9 @@ void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest, const char *reason);
+/* Event "HS_DESC RECEIVED [...]" */ +void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, + const char *hsdir_id_digest); + #endif /* !defined(TOR_HS_CONTROL_H) */
tor-commits@lists.torproject.org