commit b71a9b60cc0c29899637acc0610cb87c56869c1e Author: David Goulet dgoulet@torproject.org Date: Fri Nov 10 14:34:41 2017 -0500
hs-v3: Implement HS_DESC CREATED event
This makes the REPLICA= field optional for the control port event. A v2 service will always pass it and v3 is ignored.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/or/control.c | 16 ++++++++++++---- src/or/hs_control.c | 23 +++++++++++++++++++++++ src/or/hs_control.h | 4 ++++ src/or/hs_service.c | 4 ++++ 4 files changed, 43 insertions(+), 4 deletions(-)
diff --git a/src/or/control.c b/src/or/control.c index a1515da05..15edc1f24 100644 --- a/src/or/control.c +++ b/src/or/control.c @@ -7252,21 +7252,29 @@ get_desc_id_from_query(const rend_data_t *rend_data, const char *hsdir_fp) * * <b>onion_address</b> is service address. * <b>desc_id</b> is the descriptor ID. - * <b>replica</b> is the the descriptor replica number. + * <b>replica</b> is the the descriptor replica number. If it is negative, it + * is ignored. */ void control_event_hs_descriptor_created(const char *onion_address, const char *desc_id, int replica) { + char *replica_field = NULL; + if (BUG(!onion_address || !desc_id)) { return; }
+ if (replica >= 0) { + tor_asprintf(&replica_field, " REPLICA=%d", replica); + } + send_control_event(EVENT_HS_DESC, - "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s " - "REPLICA=%d\r\n", - onion_address, desc_id, replica); + "650 HS_DESC CREATED %s UNKNOWN UNKNOWN %s%s\r\n", + onion_address, desc_id, + replica_field ? replica_field : ""); + tor_free(replica_field); }
/** send HS_DESC upload event. diff --git a/src/or/hs_control.c b/src/or/hs_control.c index add62d583..ea010605b 100644 --- a/src/or/hs_control.c +++ b/src/or/hs_control.c @@ -102,3 +102,26 @@ hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, hsdir_id_digest); }
+/* Send on the control port the "HS_DESC CREATED [...]" event. + * + * Using the onion address of the descriptor's service and the blinded public + * key of the descriptor as a descriptor ID. None can be NULL. */ +void +hs_control_desc_event_created(const char *onion_address, + const ed25519_public_key_t *blinded_pk) +{ + char base64_blinded_pk[ED25519_BASE64_LEN + 1]; + + tor_assert(onion_address); + tor_assert(blinded_pk); + + /* Build base64 encoded blinded key. */ + IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) { + return; + } + + /* Version 3 doesn't use the replica number in its descriptor ID computation + * so we pass negative value so the control port subsystem can ignore it. */ + control_event_hs_descriptor_created(onion_address, base64_blinded_pk, -1); +} + diff --git a/src/or/hs_control.h b/src/or/hs_control.h index 33a96cec0..3b117f19c 100644 --- a/src/or/hs_control.h +++ b/src/or/hs_control.h @@ -25,5 +25,9 @@ void hs_control_desc_event_failed(const hs_ident_dir_conn_t *ident, void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident, const char *hsdir_id_digest);
+/* Event "HS_DESC CREATED [...]" */ +void hs_control_desc_event_created(const char *onion_address, + const ed25519_public_key_t *blinded_pk); + #endif /* !defined(TOR_HS_CONTROL_H) */
diff --git a/src/or/hs_service.c b/src/or/hs_service.c index a659a126f..65df5b269 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -30,6 +30,7 @@ #include "hs_circuit.h" #include "hs_common.h" #include "hs_config.h" +#include "hs_control.h" #include "hs_circuit.h" #include "hs_descriptor.h" #include "hs_ident.h" @@ -1431,6 +1432,9 @@ build_service_descriptor(hs_service_t *service, time_t now,
/* Assign newly built descriptor to the next slot. */ *desc_out = desc; + /* Fire a CREATED control port event. */ + hs_control_desc_event_created(service->onion_address, + &desc->blinded_kp.pubkey); return;
err: