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

[tor-commits] [tor/master] hs-v3: Add an handler for the HSPOST command



commit 683fccba8fb4543867435bd83851da821cd7f10e
Author: David Goulet <dgoulet@xxxxxxxxxxxxxx>
Date:   Wed Nov 15 14:34:53 2017 -0500

    hs-v3: Add an handler for the HSPOST command
    
    It is not used yet at this commit.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/hs_control.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/or/hs_control.h |  4 ++++
 2 files changed, 59 insertions(+)

diff --git a/src/or/hs_control.c b/src/or/hs_control.c
index 9a05d936b..1b1fe7857 100644
--- a/src/or/hs_control.c
+++ b/src/or/hs_control.c
@@ -10,6 +10,8 @@
 #include "control.h"
 #include "hs_common.h"
 #include "hs_control.h"
+#include "hs_descriptor.h"
+#include "hs_service.h"
 #include "nodelist.h"
 
 /* Send on the control port the "HS_DESC REQUESTED [...]" event.
@@ -199,3 +201,56 @@ hs_control_desc_event_content(const hs_ident_dir_conn_t *ident,
                                       hsdir_id_digest, body);
 }
 
+/* Handle the "HSPOST [...]" command. The body is an encoded descriptor for
+ * the given onion_address. The descriptor will be uploaded to each directory
+ * in hsdirs_rs. If NULL, the responsible directories for the current time
+ * period will be selected.
+ *
+ * Return -1 on if the descriptor plaintext section is not decodable. Else, 0
+ * on success. */
+int
+hs_control_hspost_command(const char *body, const char *onion_address,
+                          const smartlist_t *hsdirs_rs)
+{
+  int ret = -1;
+  ed25519_public_key_t identity_pk;
+  hs_desc_plaintext_data_t plaintext;
+  smartlist_t *hsdirs = NULL;
+
+  tor_assert(body);
+  tor_assert(onion_address);
+
+  /* This can't fail because we require the caller to pass us a valid onion
+   * address that has passed hs_address_is_valid(). */
+  hs_parse_address(onion_address, &identity_pk, NULL, NULL);
+
+  /* Only decode the plaintext part which is what the directory will do to
+   * validate before caching. */
+  if (hs_desc_decode_plaintext(body, &plaintext) < 0) {
+    goto done;
+  }
+
+  /* No HSDir(s) given, we'll compute what the current ones should be. */
+  if (hsdirs_rs == NULL) {
+    hsdirs = smartlist_new();
+    hs_get_responsible_hsdirs(&plaintext.blinded_pubkey,
+                              hs_get_time_period_num(0),
+                              0, /* Always the current descriptor which uses
+                                  * the first hsdir index. */
+                              0, /* It is for storing on a directory. */
+                              hsdirs);
+    hsdirs_rs = hsdirs;
+  }
+
+  SMARTLIST_FOREACH_BEGIN(hsdirs_rs, const routerstatus_t *, rs) {
+    hs_service_upload_desc_to_dir(body, plaintext.version, &identity_pk,
+                                  &plaintext.blinded_pubkey, rs);
+  } SMARTLIST_FOREACH_END(rs);
+  ret = 0;
+
+ done:
+  /* We don't have ownership of the objects in this list. */
+  smartlist_free(hsdirs);
+  return ret;
+}
+
diff --git a/src/or/hs_control.h b/src/or/hs_control.h
index 35062d4b8..95c46e655 100644
--- a/src/or/hs_control.h
+++ b/src/or/hs_control.h
@@ -44,5 +44,9 @@ void hs_control_desc_event_content(const hs_ident_dir_conn_t *ident,
                                    const char *hsdir_id_digest,
                                    const char *body);
 
+/* Command "HSPOST [...]" */
+int hs_control_hspost_command(const char *body, const char *onion_address,
+                              const smartlist_t *hsdirs_rs);
+
 #endif /* !defined(TOR_HS_CONTROL_H) */
 



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