gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated: hello: Fix #9043 again. modify API to re


From: gnunet
Subject: [gnunet] branch master updated: hello: Fix #9043 again. modify API to re-use signatures and expiration of URIs (semi-consistent)
Date: Mon, 05 Aug 2024 22:42:46 +0200

This is an automated email from the git hooks/post-receive script.

martin-schanzenbach pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 3692d8be3 hello: Fix #9043 again. modify API to re-use signatures and 
expiration of URIs (semi-consistent)
3692d8be3 is described below

commit 3692d8be32158439948b381a3d361965c4a4cb97
Author: Martin Schanzenbach <schanzen@gnunet.org>
AuthorDate: Mon Aug 5 22:42:12 2024 +0200

    hello: Fix #9043 again. modify API to re-use signatures and expiration of 
URIs (semi-consistent)
---
 src/cli/peerstore/gnunet-peerstore.c |  52 ++++++++++++---
 src/lib/hello/hello-uri.c            | 119 +++++++++++++++++++++++------------
 2 files changed, 123 insertions(+), 48 deletions(-)

diff --git a/src/cli/peerstore/gnunet-peerstore.c 
b/src/cli/peerstore/gnunet-peerstore.c
index 293deb8e3..f5c05fd9b 100644
--- a/src/cli/peerstore/gnunet-peerstore.c
+++ b/src/cli/peerstore/gnunet-peerstore.c
@@ -24,6 +24,9 @@
  * @author Omar Tarabai
  */
 #include "gnunet_common.h"
+#include "gnunet_dht_service.h"
+#include "gnunet_scheduler_lib.h"
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #include "gnunet_hello_uri_lib.h"
 #include "gnunet_util_lib.h"
@@ -46,6 +49,8 @@ static int export_own_hello_uri;
 
 static int print_hellos;
 
+static char *import_uri;
+
 /**
  * Run on shutdown
  *
@@ -114,6 +119,7 @@ hello_iter (void *cls, const struct GNUNET_PEERSTORE_Record 
*record,
       printf ("%s\n", url);
       GNUNET_free (url);
       GNUNET_PEERSTORE_iteration_stop (iter_ctx);
+      GNUNET_HELLO_builder_free (hb);
       GNUNET_SCHEDULER_shutdown ();
       return;
     }
@@ -123,10 +129,23 @@ hello_iter (void *cls, const struct 
GNUNET_PEERSTORE_Record *record,
     printf ("`%s':\n", GNUNET_i2s (pid));
     GNUNET_HELLO_builder_iterate (hb, &print_hello_addrs, NULL);
   }
+  GNUNET_HELLO_builder_free (hb);
   GNUNET_PEERSTORE_iteration_next (iter_ctx, 1);
 }
 
 
+static void
+hello_store_success (void *cls, int success)
+{
+  if (GNUNET_OK != success)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Storing hello uri failed\n");
+  }
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+
 /**
  * Main function that will be run by the scheduler.
  *
@@ -141,18 +160,30 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
+  struct GNUNET_HELLO_Builder *hb;
+  struct GNUNET_MQ_Envelope *env;
 
   GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
                                  NULL);
-  if (!print_hellos && !export_own_hello_uri)
+  peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
+  GNUNET_assert (NULL != peerstore_handle);
+  if (NULL != import_uri)
+  {
+    hb = GNUNET_HELLO_builder_from_url (import_uri);
+    env = GNUNET_HELLO_builder_to_env (hb, NULL, GNUNET_TIME_UNIT_ZERO);
+    GNUNET_PEERSTORE_hello_add (peerstore_handle,
+                                GNUNET_MQ_env_get_msg (env),
+                                &hello_store_success, NULL);
+    GNUNET_HELLO_builder_free (hb);
+    return;
+  }
+  if (! print_hellos && ! export_own_hello_uri)
   {
     fprintf (stderr, "No arguments provided\n");
-    GNUNET_SCHEDULER_shutdown();
+    GNUNET_SCHEDULER_shutdown ();
     ret = 1;
     return;
   }
-  peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
-  GNUNET_assert (NULL != peerstore_handle);
   my_private_key =
     GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
   GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
@@ -179,12 +210,19 @@ main (int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
     GNUNET_GETOPT_option_flag ('H',
-                               "hello-uri",
-                               gettext_noop ("Print a HELLO URI for our peer 
identity"),
+                               "export-hello-uri",
+                               gettext_noop (
+                                 "Print a HELLO URI for our peer identity"),
                                &export_own_hello_uri),
+    GNUNET_GETOPT_option_string ('I',
+                                 "import-hello",
+                                 gettext_noop ("Import a HELLO URI"),
+                                 "URI",
+                                 &import_uri),
     GNUNET_GETOPT_option_flag ('D',
                                "dump",
-                               gettext_noop ("List all known HELLOs in 
peerstore"),
+                               gettext_noop (
+                                 "List all known HELLOs in peerstore"),
                                &print_hellos),
     GNUNET_GETOPT_OPTION_END
   };
diff --git a/src/lib/hello/hello-uri.c b/src/lib/hello/hello-uri.c
index add4ef7fc..b7c177387 100644
--- a/src/lib/hello/hello-uri.c
+++ b/src/lib/hello/hello-uri.c
@@ -34,6 +34,7 @@
  *   that does this to create bootstrap HELLOs shipped with
  *   the TGZ.
  */
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #include "gnunet_signatures.h"
 #include "gnunet_hello_uri_lib.h"
@@ -223,6 +224,20 @@ struct GNUNET_HELLO_Builder
    */
   unsigned int a_length;
 
+  /**
+   * The signature (may have been provided)
+   */
+  struct GNUNET_CRYPTO_EddsaSignature sig;
+
+  /**
+   * GNUNET_YES if signature is set
+   */
+  int signature_set;
+
+  /**
+   * Expiration time parsed
+   */
+  struct GNUNET_TIME_Absolute et;
 };
 
 /**
@@ -496,10 +511,10 @@ GNUNET_HELLO_builder_from_url (const char *url)
   const char *s1;
   const char *s2;
   struct GNUNET_PeerIdentity pid;
-  struct GNUNET_CRYPTO_EddsaSignature sig;
   struct GNUNET_TIME_Absolute et;
   size_t len;
   struct GNUNET_HELLO_Builder *b;
+  struct GNUNET_CRYPTO_EddsaSignature sig;
 
   if (0 != strncasecmp (url,
                         "gnunet://hello/",
@@ -556,6 +571,9 @@ GNUNET_HELLO_builder_from_url (const char *url)
   }
 
   b = GNUNET_HELLO_builder_new (&pid);
+  b->et = et;
+  b->sig = sig;
+  b->signature_set = GNUNET_YES;
   len = strlen (q);
   while (len > 0)
   {
@@ -615,7 +633,7 @@ GNUNET_HELLO_builder_from_url (const char *url)
 
     ret = verify_hello (b,
                         et,
-                        &sig);
+                        &b->sig);
     GNUNET_break (GNUNET_SYSERR != ret);
     if (GNUNET_OK != ret)
     {
@@ -627,41 +645,6 @@ GNUNET_HELLO_builder_from_url (const char *url)
 }
 
 
-struct GNUNET_MQ_Envelope *
-GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
-                             const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
-                             struct GNUNET_TIME_Relative expiration_time)
-{
-  struct GNUNET_MQ_Envelope *env;
-  struct HelloUriMessage *msg;
-  size_t blen;
-
-  if (builder->a_length > UINT16_MAX)
-  {
-    GNUNET_break (0);
-    return NULL;
-  }
-  blen = 0;
-  GNUNET_assert (GNUNET_NO ==
-                 GNUNET_HELLO_builder_to_block (builder,
-                                                priv,
-                                                NULL,
-                                                &blen,
-                                                expiration_time));
-  env = GNUNET_MQ_msg_extra (msg,
-                             blen,
-                             GNUNET_MESSAGE_TYPE_HELLO_URI);
-  msg->url_counter = htons ((uint16_t) builder->a_length);
-  GNUNET_assert (GNUNET_OK ==
-                 GNUNET_HELLO_builder_to_block (builder,
-                                                priv,
-                                                &msg[1],
-                                                &blen,
-                                                expiration_time));
-  return env;
-}
-
-
 struct GNUNET_MessageHeader *
 GNUNET_HELLO_builder_to_dht_hello_msg (
   const struct GNUNET_HELLO_Builder *builder,
@@ -809,10 +792,19 @@ GNUNET_HELLO_builder_to_block (const struct 
GNUNET_HELLO_Builder *builder,
   else
     et = GNUNET_TIME_relative_to_timestamp (expiration_time);
   bh.expiration_time = GNUNET_TIME_absolute_hton (et.abs_time);
-  sign_hello (builder,
-              et,
-              priv,
-              &bh.sig);
+  if (NULL != priv)
+  {
+    sign_hello (builder,
+                et,
+                priv,
+                &bh.sig);
+  }
+  else
+  {
+    GNUNET_assert (GNUNET_YES == builder->signature_set);
+    bh.expiration_time = GNUNET_TIME_absolute_hton (builder->et);
+    bh.sig = builder->sig;
+  }
   memcpy (block,
           &bh,
           sizeof (bh));
@@ -831,6 +823,51 @@ GNUNET_HELLO_builder_to_block (const struct 
GNUNET_HELLO_Builder *builder,
 }
 
 
+struct GNUNET_MQ_Envelope *
+GNUNET_HELLO_builder_to_env_ (const struct GNUNET_HELLO_Builder *builder,
+                              const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
+                              struct GNUNET_TIME_Relative expiration_time,
+                              const struct GNUNET_CRYPTO_EddsaSignature *sig)
+{
+  struct GNUNET_MQ_Envelope *env;
+  struct HelloUriMessage *msg;
+  size_t blen;
+
+  if (builder->a_length > UINT16_MAX)
+  {
+    GNUNET_break (0);
+    return NULL;
+  }
+  blen = 0;
+  GNUNET_assert (GNUNET_NO ==
+                 GNUNET_HELLO_builder_to_block (builder,
+                                                priv,
+                                                NULL,
+                                                &blen,
+                                                expiration_time));
+  env = GNUNET_MQ_msg_extra (msg,
+                             blen,
+                             GNUNET_MESSAGE_TYPE_HELLO_URI);
+  msg->url_counter = htons ((uint16_t) builder->a_length);
+  GNUNET_assert (GNUNET_OK ==
+                 GNUNET_HELLO_builder_to_block (builder,
+                                                priv,
+                                                &msg[1],
+                                                &blen,
+                                                expiration_time));
+  return env;
+}
+
+
+struct GNUNET_MQ_Envelope *
+GNUNET_HELLO_builder_to_env (const struct GNUNET_HELLO_Builder *builder,
+                             const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
+                             struct GNUNET_TIME_Relative expiration_time)
+{
+  return GNUNET_HELLO_builder_to_env_ (builder, priv, expiration_time, NULL);
+}
+
+
 enum GNUNET_GenericReturnValue
 GNUNET_HELLO_builder_add_address (struct GNUNET_HELLO_Builder *builder,
                                   const char *address)

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]