gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [gnunet] branch master updated: make generated ego key avai


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated: make generated ego key available in continuation when creating egos
Date: Wed, 08 May 2019 14:55:03 +0200

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

grothoff pushed a commit to branch master
in repository gnunet.

The following commit(s) were added to refs/heads/master by this push:
     new 1b80ff9ee make generated ego key available in continuation when 
creating egos
1b80ff9ee is described below

commit 1b80ff9ee79b3fbe2028a8c22a01e45e9131cda2
Author: Christian Grothoff <address@hidden>
AuthorDate: Wed May 8 14:54:42 2019 +0200

    make generated ego key available in continuation when creating egos
---
 doc/man/gnunet-identity.1             |  2 ++
 src/identity/gnunet-identity.c        | 24 ++++++++++++++++++++--
 src/identity/identity_api.c           | 38 ++++++++++++++++++++++++++++++-----
 src/identity/plugin_rest_identity.c   | 22 +++++++++++++++++++-
 src/identity/test_identity.c          |  3 +++
 src/identity/test_identity_defaults.c |  3 +++
 src/include/gnunet_identity_service.h | 16 ++++++++++++++-
 7 files changed, 99 insertions(+), 9 deletions(-)

diff --git a/doc/man/gnunet-identity.1 b/doc/man/gnunet-identity.1
index 0163c895b..3f4510d99 100644
--- a/doc/man/gnunet-identity.1
+++ b/doc/man/gnunet-identity.1
@@ -65,6 +65,8 @@ Needs to be used together with option
 Print the help page.
 .It d | \-display
 Display all of our egos.
+.It v | \-verbose
+Be verbose, in particular outputs the public key of freshly created egos.
 .It m | \-monitor
 Run in monitor mode, listing all ouf our egos until CTRL-C is pressed.
 Each ego is listed together with a unique pointer value; if egos are renamed, 
that pointer value remains the same; if egos are deleted, they are listed one 
more time with a name of "<null>".
diff --git a/src/identity/gnunet-identity.c b/src/identity/gnunet-identity.c
index 051f08cd3..583305710 100644
--- a/src/identity/gnunet-identity.c
+++ b/src/identity/gnunet-identity.c
@@ -50,6 +50,11 @@ static int list;
  */
 static int monitor;
 
+/**
+ * Was "verbose" specified?
+ */
+static unsigned int verbose;
+
 /**
  * -C option
  */
@@ -164,22 +169,37 @@ delete_finished (void *cls,
  * Creation operation finished.
  *
  * @param cls pointer to operation handle
+ * @param pk private key of the ego, or NULL on error
  * @param emsg error message, NULL on success
  */
 static void
 create_finished (void *cls,
+                const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
                 const char *emsg)
 {
   struct GNUNET_IDENTITY_Operation **op = cls;
 
   *op = NULL;
-  if (NULL != emsg)
+  if (NULL == pk)
   {
     fprintf (stderr,
             _("Failed to create ego: %s\n"),
             emsg);
     global_ret = 1;
   }
+  else if (verbose)
+  {
+    struct GNUNET_CRYPTO_EcdsaPublicKey pub;
+    char *pubs;
+    
+    GNUNET_CRYPTO_ecdsa_key_get_public (pk,
+                                       &pub);
+    pubs = GNUNET_CRYPTO_ecdsa_public_key_to_string (&pub);
+    fprintf (stdout,
+            "%s\n",
+            pubs);
+    GNUNET_free (pubs);
+  }
   test_finished ();
 }
 
@@ -383,7 +403,7 @@ main (int argc, char *const *argv)
                                  "SUBSYSTEM",
                                  gettext_noop ("set default identity to EGO 
for a subsystem SUBSYSTEM (use together with -e)"),
                                  &set_subsystem),
-
+    GNUNET_GETOPT_option_verbose (&verbose),
     GNUNET_GETOPT_OPTION_END
   };
   int res;
diff --git a/src/identity/identity_api.c b/src/identity/identity_api.c
index a058c5426..f16500ab5 100644
--- a/src/identity/identity_api.c
+++ b/src/identity/identity_api.c
@@ -88,13 +88,24 @@ struct GNUNET_IDENTITY_Operation
 
   /**
    * Continuation to invoke with the result of the transmission; @e cb
-   * will be NULL in this case.
+   * and @e create_cont will be NULL in this case.
    */
   GNUNET_IDENTITY_Continuation cont;
 
+  /**
+   * Continuation to invoke with the result of the transmission; @e cb
+   * and @a cb will be NULL in this case.
+   */
+  GNUNET_IDENTITY_CreateContinuation create_cont;
+
+  /**
+   * Private key to return to @e create_cont, or NULL.
+   */
+  struct GNUNET_CRYPTO_EcdsaPrivateKey *pk;
+  
   /**
    * Continuation to invoke with the result of the transmission for
-   * 'get' operations (@e cont will be NULL in this case).
+   * 'get' operations (@e cont and @a create_cont will be NULL in this case).
    */
   GNUNET_IDENTITY_Callback cb;
 
@@ -259,6 +270,11 @@ reschedule_connect (struct GNUNET_IDENTITY_Handle *h)
               NULL,
               NULL,
               NULL);
+    else if (NULL != op->create_cont)
+      op->create_cont (op->cls,
+                      NULL,
+                      "Failed to communicate with the identity service");
+    GNUNET_free_non_null (op->pk);
     GNUNET_free (op);
   }
   GNUNET_CONTAINER_multihashmap_iterate (h->egos,
@@ -350,6 +366,11 @@ handle_identity_result_code (void *cls,
               str);
   else if (NULL != op->cb)
     op->cb (op->cls, NULL, NULL, NULL);
+  else if (NULL != op->create_cont)
+    op->create_cont (op->cls,
+                    (NULL == str) ? op->pk : NULL,
+                    str);
+  GNUNET_free_non_null (op->pk);
   GNUNET_free (op);
 }
 
@@ -761,7 +782,7 @@ GNUNET_IDENTITY_set (struct GNUNET_IDENTITY_Handle *h,
 struct GNUNET_IDENTITY_Operation *
 GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
                        const char *name,
-                       GNUNET_IDENTITY_Continuation cont,
+                       GNUNET_IDENTITY_CreateContinuation cont,
                        void *cont_cls)
 {
   struct GNUNET_IDENTITY_Operation *op;
@@ -780,7 +801,7 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
   }
   op = GNUNET_new (struct GNUNET_IDENTITY_Operation);
   op->h = h;
-  op->cont = cont;
+  op->create_cont = cont;
   op->cls = cont_cls;
   GNUNET_CONTAINER_DLL_insert_tail (h->op_head,
                                    h->op_tail,
@@ -792,7 +813,7 @@ GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *h,
   crm->reserved = htons (0);
   pk = GNUNET_CRYPTO_ecdsa_key_create ();
   crm->private_key = *pk;
-  GNUNET_free (pk);
+  op->pk = pk;
   GNUNET_memcpy (&crm[1],
           name,
           slen);
@@ -924,6 +945,12 @@ GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation 
*op)
 {
   op->cont = NULL;
   op->cb = NULL;
+  op->create_cont = NULL;
+  if (NULL != op->pk)
+  {
+    GNUNET_free (op->pk);
+    op->pk = NULL;
+  }
 }
 
 
@@ -957,6 +984,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle 
*h)
     GNUNET_CONTAINER_DLL_remove (h->op_head,
                                 h->op_tail,
                                 op);
+    GNUNET_free_non_null (op->pk);
     GNUNET_free (op);
   }
   if (NULL != h->mq)
diff --git a/src/identity/plugin_rest_identity.c 
b/src/identity/plugin_rest_identity.c
index 89f590d3e..e6537070a 100644
--- a/src/identity/plugin_rest_identity.c
+++ b/src/identity/plugin_rest_identity.c
@@ -641,6 +641,26 @@ do_finished (void *cls, const char *emsg)
 }
 
 
+/**
+ * Processing finished, when creating an ego.
+ *
+ * @param cls request handle
+ * @param private key of the ego, or NULL on error
+ * @param emsg error message
+ */
+static void
+do_finished_create (void *cls,
+                   const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
+                   const char *emsg)
+{
+  struct RequestHandle *handle = cls;
+
+  (void) pk;
+  do_finished (handle,
+              emsg);
+}
+
+
 /**
  * Processing edit ego with EgoEntry ego_entry
  *
@@ -1014,7 +1034,7 @@ ego_create (struct GNUNET_REST_RequestHandle *con_handle,
   json_decref (data_js);
   handle->response_code = MHD_HTTP_CREATED;
   handle->op = GNUNET_IDENTITY_create (handle->identity_handle, handle->name,
-                                      &do_finished, handle);
+                                      &do_finished_create, handle);
 }
 
 /**
diff --git a/src/identity/test_identity.c b/src/identity/test_identity.c
index cfd759050..163394801 100644
--- a/src/identity/test_identity.c
+++ b/src/identity/test_identity.c
@@ -253,12 +253,15 @@ success_rename_cont (void *cls,
  * Called with events about created ego.
  *
  * @param cls NULL
+ * @param pk private key of the ego, or NULL on error
  * @param emsg error message
  */
 static void
 create_cb (void *cls,
+          const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
           const char *emsg)
 {
+  GNUNET_assert (NULL != pk);
   GNUNET_assert (NULL == emsg);
   op = GNUNET_IDENTITY_rename (h,
                               "test-id",
diff --git a/src/identity/test_identity_defaults.c 
b/src/identity/test_identity_defaults.c
index a7559cd94..bcd75e84c 100644
--- a/src/identity/test_identity_defaults.c
+++ b/src/identity/test_identity_defaults.c
@@ -225,13 +225,16 @@ notification_cb (void *cls,
  * Called with events about created ego.
  *
  * @param cls NULL
+ * @param pk private key of the ego, or NULL on error
  * @param emsg error message
  */
 static void
 create_cb (void *cls,
+          const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk,
           const char *emsg)
 {
   GNUNET_assert (NULL == emsg);
+  GNUNET_assert (NULL != pk);
   op = NULL;
 }
 
diff --git a/src/include/gnunet_identity_service.h 
b/src/include/gnunet_identity_service.h
index 086f924d6..043a71770 100644
--- a/src/include/gnunet_identity_service.h
+++ b/src/include/gnunet_identity_service.h
@@ -214,6 +214,20 @@ void
 GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h);
 
 
+/**
+ * Function called once the requested operation has
+ * been completed.
+ *
+ * @param cls closure
+ * @param pk private key, NULL on error
+ * @param emsg error message, NULL on success
+ */
+typedef void
+(*GNUNET_IDENTITY_CreateContinuation)(void *cls,
+                                     const struct 
GNUNET_CRYPTO_EcdsaPrivateKey *pk,
+                                     const char *emsg);
+
+
 /**
  * Create a new ego with the given name.
  *
@@ -226,7 +240,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle 
*h);
 struct GNUNET_IDENTITY_Operation *
 GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id,
                        const char *name,
-                       GNUNET_IDENTITY_Continuation cont,
+                       GNUNET_IDENTITY_CreateContinuation cont,
                        void *cont_cls);
 
 

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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