[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] hs-v3: Implement HS_DESC UPLOAD event



commit c7050eaa16ca8c46c2cea81cc2f4d405ccf15968
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Fri Nov 10 14:48:52 2017 -0500

    hs-v3: Implement HS_DESC UPLOAD event
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/control.c     | 15 ++++++++++++---
 src/or/control.h     |  3 ++-
 src/or/hs_control.c  | 29 +++++++++++++++++++++++++++++
 src/or/hs_control.h  |  6 ++++++
 src/or/hs_service.c  |  5 ++++-
 src/or/rendservice.c |  4 ++--
 6 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/src/or/control.c b/src/or/control.c
index 15edc1f24..0e41aab5e 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -7286,17 +7286,26 @@ control_event_hs_descriptor_created(const char *onion_address,
 void
 control_event_hs_descriptor_upload(const char *onion_address,
                                    const char *id_digest,
-                                   const char *desc_id)
+                                   const char *desc_id,
+                                   const char *hsdir_index)
 {
+  char *hsdir_index_field = NULL;
+
   if (BUG(!onion_address || !id_digest || !desc_id)) {
     return;
   }
 
+  if (hsdir_index) {
+    tor_asprintf(&hsdir_index_field, " HSDIR_INDEX=%s", hsdir_index);
+  }
+
   send_control_event(EVENT_HS_DESC,
-                     "650 HS_DESC UPLOAD %s UNKNOWN %s %s\r\n",
+                     "650 HS_DESC UPLOAD %s UNKNOWN %s %s%s\r\n",
                      onion_address,
                      node_describe_longname_by_id(id_digest),
-                     desc_id);
+                     desc_id,
+                     hsdir_index_field ? hsdir_index_field : "");
+  tor_free(hsdir_index_field);
 }
 
 /** send HS_DESC event after got response from hs directory.
diff --git a/src/or/control.h b/src/or/control.h
index c11f6a07b..23f6eed8e 100644
--- a/src/or/control.h
+++ b/src/or/control.h
@@ -125,7 +125,8 @@ void control_event_hs_descriptor_created(const char *onion_address,
                                          int replica);
 void control_event_hs_descriptor_upload(const char *onion_address,
                                         const char *desc_id,
-                                        const char *hs_dir);
+                                        const char *hs_dir,
+                                        const char *hsdir_index);
 void control_event_hs_descriptor_upload_end(const char *action,
                                             const char *onion_address,
                                             const char *hs_dir,
diff --git a/src/or/hs_control.c b/src/or/hs_control.c
index ea010605b..09dbbeba4 100644
--- a/src/or/hs_control.c
+++ b/src/or/hs_control.c
@@ -125,3 +125,32 @@ hs_control_desc_event_created(const char *onion_address,
   control_event_hs_descriptor_created(onion_address, base64_blinded_pk, -1);
 }
 
+/* Send on the control port the "HS_DESC UPLOAD [...]" event.
+ *
+ * Using the onion address of the descriptor's service, the HSDir identity
+ * digest, the blinded public key of the descriptor as a descriptor ID and the
+ * HSDir index for this particular request. None can be NULL. */
+void
+hs_control_desc_event_upload(const char *onion_address,
+                             const char *hsdir_id_digest,
+                             const ed25519_public_key_t *blinded_pk,
+                             const uint8_t *hsdir_index)
+{
+  char base64_blinded_pk[ED25519_BASE64_LEN + 1];
+
+  tor_assert(onion_address);
+  tor_assert(hsdir_id_digest);
+  tor_assert(blinded_pk);
+  tor_assert(hsdir_index);
+
+  /* Build base64 encoded blinded key. */
+  IF_BUG_ONCE(ed25519_public_to_base64(base64_blinded_pk, blinded_pk) < 0) {
+    return;
+  }
+
+  control_event_hs_descriptor_upload(onion_address, hsdir_id_digest,
+                                     base64_blinded_pk,
+                                     hex_str((const char *) hsdir_index,
+                                             DIGEST256_LEN));
+}
+
diff --git a/src/or/hs_control.h b/src/or/hs_control.h
index 3b117f19c..e10a300d7 100644
--- a/src/or/hs_control.h
+++ b/src/or/hs_control.h
@@ -29,5 +29,11 @@ void hs_control_desc_event_received(const hs_ident_dir_conn_t *ident,
 void hs_control_desc_event_created(const char *onion_address,
                                    const ed25519_public_key_t *blinded_pk);
 
+/* Event "HS_DESC UPLOAD [...]" */
+void hs_control_desc_event_upload(const char *onion_address,
+                                  const char *hsdir_id_digest,
+                                  const ed25519_public_key_t *blinded_pk,
+                                  const uint8_t *hsdir_index);
+
 #endif /* !defined(TOR_HS_CONTROL_H) */
 
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index 65df5b269..4f0465da4 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -2267,9 +2267,12 @@ upload_descriptor_to_hsdir(const hs_service_t *service,
              desc->desc->plaintext_data.revision_counter,
              safe_str_client(node_describe(hsdir)),
              safe_str_client(hex_str((const char *) index, 32)));
+
+    /* Fire a UPLOAD control port event. */
+    hs_control_desc_event_upload(service->onion_address, hsdir->identity,
+                                 &desc->blinded_kp.pubkey, index);
   }
 
-  /* XXX: Inform control port of the upload event (#20699). */
  end:
   tor_free(encoded_desc);
   return;
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 8eb533490..1e745d0fd 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -3574,7 +3574,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
                           "directories to post descriptors to.");
         control_event_hs_descriptor_upload(service_id,
                                            "UNKNOWN",
-                                           "UNKNOWN");
+                                           "UNKNOWN", NULL);
         goto done;
       }
     }
@@ -3629,7 +3629,7 @@ directory_post_to_hs_dir(rend_service_descriptor_t *renddesc,
                hs_dir->or_port);
       control_event_hs_descriptor_upload(service_id,
                                          hs_dir->identity_digest,
-                                         desc_id_base32);
+                                         desc_id_base32, NULL);
       tor_free(hs_dir_ip);
       /* Remember successful upload to this router for next time. */
       if (!smartlist_contains_digest(successful_uploads,



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits