commit 0a3b2954487480114201758e02b3560e46ea1cca Author: David Goulet dgoulet@torproject.org Date: Tue Nov 7 16:00:40 2017 -0500
hs-v3: Add a lookup service current descriptor function
This will be used by the control port command "GETINFO hs/service/desc/id/<ADDR>" which returns the encoded current descriptor for the given onion address.
Signed-off-by: David Goulet dgoulet@torproject.org --- src/or/hs_service.c | 25 +++++++++++++++++++++++++ src/or/hs_service.h | 2 ++ 2 files changed, 27 insertions(+)
diff --git a/src/or/hs_service.c b/src/or/hs_service.c index 8e2f52dcf..349aa265d 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -2900,6 +2900,31 @@ service_add_fnames_to_list(const hs_service_t *service, smartlist_t *list) /* Public API */ /* ========== */
+/* Using the ed25519 public key pk, find a service for that key and return the + * current encoded descriptor as a newly allocated string or NULL if not + * found. This is used by the control port subsystem. */ +char * +hs_service_lookup_current_desc(const ed25519_public_key_t *pk) +{ + const hs_service_t *service; + + tor_assert(pk); + + service = find_service(hs_service_map, pk); + if (service && service->desc_current) { + char *encoded_desc = NULL; + /* No matter what is the result (which should never be a failure), return + * the encoded variable, if success it will contain the right thing else + * it will be NULL. */ + hs_desc_encode_descriptor(service->desc_current->desc, + &service->desc_current->signing_kp, + &encoded_desc); + return encoded_desc; + } + + return NULL; +} + /* Return the number of service we have configured and usable. */ unsigned int hs_service_get_num_services(void) diff --git a/src/or/hs_service.h b/src/or/hs_service.h index ed1053d85..e78cc4c2b 100644 --- a/src/or/hs_service.h +++ b/src/or/hs_service.h @@ -271,6 +271,8 @@ int hs_service_receive_introduce2(origin_circuit_t *circ,
void hs_service_intro_circ_has_closed(origin_circuit_t *circ);
+char *hs_service_lookup_current_desc(const ed25519_public_key_t *pk); + #ifdef HS_SERVICE_PRIVATE
#ifdef TOR_UNIT_TESTS
tor-commits@lists.torproject.org