gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 63/70: - remove static variable from did_core


From: gnunet
Subject: [gnunet] 63/70: - remove static variable from did_core
Date: Wed, 31 Aug 2022 18:00:57 +0200

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

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

commit 00047451b7e2e466c0f8b887280054bac3106cbd
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Fri Jul 1 15:41:00 2022 +0200

    - remove static variable from did_core
---
 src/reclaim/did_core.c   | 46 +++++++++++++------------
 src/reclaim/did_helper.c |  8 ++---
 src/reclaim/gnunet-did.c | 89 +++++++++++++++++++++++++-----------------------
 3 files changed, 73 insertions(+), 70 deletions(-)

diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index 2d0a3c525..16bdb0bdb 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -25,15 +25,17 @@
  */
 
 
+// TODO: Expiration time missing in create
+// TODO: Check if ego already has a DID document in create
+// TODO: Store DID document with empty label and own type (maybe DID-Document 
or Json??)
+// TODO: Store DID document as compact JSON in GNS but resolve it with newlines
+
 #include "did_core.h"
 
 // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT
 #define DID_DOCUMENT_LABEL "didd"
 #define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d"
 
-static DID_resolve_callback *resolve_cb;
-static void *closure;
-
 struct DID_resolve_return
 {
   DID_resolve_callback *cb;
@@ -65,24 +67,21 @@ DID_resolve_gns_lookup_cb (
   uint32_t rd_count,
   const struct GNUNET_GNSRECORD_Data *rd)
 {
-  /*
-   * FIXME-MSC: The user may decide to put other records here.
-   * In general I am fine with the constraint here, but not when
-   * we move it to "@"
-   */
-
-  char *didd;
+  char *did_document;
+  DID_resolve_callback *cb = ((struct DID_resolve_return *) cls)->cb;
+  void *cls2 = ((struct DID_resolve_return *) cls)->cls;
+  free (cls);
 
   if (rd_count != 1)
-    resolve_cb (GNUNET_NO, "An ego should only have one DID Document", 
closure);
+    cb (GNUNET_NO, "An ego should only have one DID Document", cls2);
 
   if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
   {
-    didd = (char *) rd[0].data;
-    resolve_cb (GNUNET_OK, didd, closure);
+    did_document = (char *) rd[0].data;
+    cb (GNUNET_OK, did_document, cls2);
   }
   else
-    resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure);
+    cb (GNUNET_NO, "DID Document is not a TXT record\n", cls2);
 }
 
 /**
@@ -103,18 +102,21 @@ DID_resolve (const char *did,
 {
   struct GNUNET_IDENTITY_PublicKey pkey;
 
+  // did, gns_handle and cont must me set
   if ((did == NULL) || (gns_handle == NULL) || (cont == NULL))
     return GNUNET_NO;
 
-  resolve_cb = cont;
-  closure = cls;
-
   if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
     return GNUNET_NO;
 
+  // Create closure for lockup callback
+  struct DID_resolve_return *cls2 = malloc (sizeof(struct DID_resolve_return));
+  cls2->cb = cont;
+  cls2->cls = cls;
+
   GNUNET_GNS_lookup (gns_handle, DID_DOCUMENT_LABEL, &pkey,
                      GNUNET_DNSPARSER_TYPE_TXT,
-                     GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
+                     GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, cls2);
 
   return GNUNET_OK;
 }
@@ -138,14 +140,12 @@ DID_create_did_store_cb (void *cls,
   }
   else
   {
+    // TODO: Log emsg. Not writing it to STDOUT
     printf ("%s\n", emsg);
     cb (GNUNET_NO, (void *) cls2);
   }
 }
 
-// TODO: Expiration time missing
-// TODO: Check if ego already has a DID document
-
 /**
  * @brief Creates a DID and saves DID Document in Namestore.
  *
@@ -169,6 +169,10 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
   struct GNUNET_TIME_Relative expire_time;
   struct GNUNET_GNSRECORD_Data record_data;
 
+  // Ego, namestore_handle and cont must be set
+  if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL))
+    return GNUNET_NO;
+
   // Check if ego has EdDSA key
   GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego,
                                       &pkey);
diff --git a/src/reclaim/did_helper.c b/src/reclaim/did_helper.c
index ff4ced0f2..1c04ede33 100644
--- a/src/reclaim/did_helper.c
+++ b/src/reclaim/did_helper.c
@@ -78,10 +78,6 @@ DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego)
 enum GNUNET_GenericReturnValue
 DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
 {
-  /* FIXME-MSC: I suggest introducing a
-   * #define MAX_DID_LENGTH <something>
-   * here and use it for parsing
-   */
   char pkey_str[MAX_DID_SPECIFIC_IDENTIFIER_LENGTH];
 
   if ((1 != (sscanf (did,
@@ -112,8 +108,8 @@ GNUNET_DID_key_covert_multibase_base64_to_gnunet (char 
*pkey_str)
  */
 char *
 DID_key_covert_gnunet_to_multibase_base64 (struct
-                                                  GNUNET_IDENTITY_PublicKey *
-                                                  pkey)
+                                           GNUNET_IDENTITY_PublicKey *
+                                           pkey)
 {
   struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key;
 
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index c865e8295..55eedfbd7 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -153,48 +153,48 @@ cleanup (void *cls)
  * @param cls closure
  * @param ego the returned ego
  */
-static void
-get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
-{
-  char *did_str;
-
-  if (ego == NULL)
-  {
-    printf ("EGO not found\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-  did_str = DID_identity_to_did (ego);
-
-  printf ("%s\n", did_str);
-
-  GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-  ret = 0;
-  return;
-}
+// static void
+// get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
+// {
+//   char *did_str;
+// 
+//   if (ego == NULL)
+//   {
+//     printf ("EGO not found\n");
+//     GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+//     ret = 1;
+//     return;
+//   }
+//   did_str = DID_identity_to_did (ego);
+// 
+//   printf ("%s\n", did_str);
+// 
+//   GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+//   ret = 0;
+//   return;
+// }
 
 /**
  * @brief Get the DID for a given EGO
  *
  */
-static void
-get_did_for_ego ()
-{
-  if (egoname != NULL)
-  {
-    GNUNET_IDENTITY_ego_lookup (my_cfg,
-                                egoname,
-                                &get_did_for_ego_lookup_cb,
-                                NULL);
-  }
-  else {
-    printf ("Set the EGO argument to get the DID for a given EGO\n");
-    GNUNET_SCHEDULER_add_now (&cleanup, NULL);
-    ret = 1;
-    return;
-  }
-}
+// static void
+// get_did_for_ego ()
+// {
+//   if (egoname != NULL)
+//   {
+//     GNUNET_IDENTITY_ego_lookup (my_cfg,
+//                                 egoname,
+//                                 &get_did_for_ego_lookup_cb,
+//                                 NULL);
+//   }
+//   else {
+//     printf ("Set the EGO argument to get the DID for a given EGO\n");
+//     GNUNET_SCHEDULER_add_now (&cleanup, NULL);
+//     ret = 1;
+//     return;
+//   }
+// }
 
 /**
  * @brief Resolve DID callback. Prints the DID Document to standard out.
@@ -374,7 +374,7 @@ create_did_cb (enum GNUNET_GenericReturnValue status, void 
*cls)
   }
   else
   {
-    printf ("An error occured while creating the DID\n");
+    printf ("An error occured while creating the DID.\n");
     ret = 1;
   }
 
@@ -427,6 +427,7 @@ create_did_ego_lockup_cb (void *cls, struct 
GNUNET_IDENTITY_Ego *ego)
     char *did = DID_identity_to_did (ego);
     void *cls = malloc (strlen (did) + 1);
     strcpy (cls, did);
+    // TODO: Add DID_document argument
     DID_create (ego, NULL, namestore_handle, create_did_cb, cls);
   }
 }
@@ -513,6 +514,8 @@ replace_did_document ()
 static void
 post_ego_iteration (void *cls)
 {
+  // TODO: Check that only one argument is set
+  
   if (1 == replace)
   {
     replace_did_document ();
@@ -633,10 +636,6 @@ main (int argc, char *const argv[])
                                gettext_noop (
                                  "Get the DID Document associated with the 
given DID"),
                                &get),
-    GNUNET_GETOPT_option_flag ('s',
-                               "show",
-                               gettext_noop ("Show the DID for a given ego"),
-                               &show),
     GNUNET_GETOPT_option_flag ('r',
                                "remove",
                                gettext_noop (
@@ -646,9 +645,13 @@ main (int argc, char *const argv[])
                                "replace",
                                gettext_noop ("Replace the DID Document."),
                                &replace),
+    GNUNET_GETOPT_option_flag ('s',
+                               "show",
+                               gettext_noop ("Show the DID for a given ego"),
+                               &show),
     GNUNET_GETOPT_option_flag ('A',
                                "show-all",
-                               gettext_noop ("Replace the DID Document."),
+                               gettext_noop ("Show egos with DIDs"),
                                &show_all),
     GNUNET_GETOPT_option_string ('d',
                                  "did",

-- 
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]