diff options
author | David Goulet <dgoulet@torproject.org> | 2017-11-10 14:12:34 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-12-05 19:39:46 -0500 |
commit | 3b436d495fc6ad59ff5d9406d7ef17494286c299 (patch) | |
tree | a0238ed65588572666ff9badd541e30f2d22cfd8 | |
parent | 8365de1da3de53fc02d463d78187625d16a5180b (diff) | |
download | tor-3b436d495fc6ad59ff5d9406d7ef17494286c299.tar.gz tor-3b436d495fc6ad59ff5d9406d7ef17494286c299.zip |
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>
-rw-r--r-- | src/or/control.c | 23 | ||||
-rw-r--r-- | src/or/control.h | 3 | ||||
-rw-r--r-- | src/or/directory.c | 2 | ||||
-rw-r--r-- | src/or/hs_control.c | 25 | ||||
-rw-r--r-- | src/or/hs_control.h | 4 |
5 files changed, 57 insertions, 0 deletions
diff --git a/src/or/control.c b/src/or/control.c index 3ba3a4b3a0..a1515da05a 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 4c9adb6818..c11f6a07bd 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 1b6f7500b3..a1d9c8c08a 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 ed77c8e1d5..add62d5832 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 fb8f3859f5..33a96cec01 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) */ |