gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 58/70: - missing lib bug


From: gnunet
Subject: [gnunet] 58/70: - missing lib bug
Date: Wed, 31 Aug 2022 18:00:52 +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 47e7cc4fd4c9341926f0cd4aca2b38e9cd5aba7e
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Mon Jun 27 18:32:01 2022 +0200

    - missing lib bug
---
 src/reclaim/Makefile.am  |  7 +++--
 src/reclaim/did_core.c   | 75 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/reclaim/did_core.h   |  5 ++--
 src/reclaim/did_helper.c |  8 +++---
 src/reclaim/did_helper.h |  4 +--
 src/reclaim/gnunet-did.c | 52 ++++++++++++++++++++++-----------
 6 files changed, 123 insertions(+), 28 deletions(-)

diff --git a/src/reclaim/Makefile.am b/src/reclaim/Makefile.am
index 89c361585..8e17bf5f3 100644
--- a/src/reclaim/Makefile.am
+++ b/src/reclaim/Makefile.am
@@ -141,14 +141,17 @@ libgnunetreclaim_la_LDFLAGS = \
 
 libgnunetdid_la_SOURCES = \
   did_helper.c \
-  did_helper.h
+  did_helper.h \
+  did_core.h \
+  did_core.c
 libgnunetdid_la_LIBADD = \
        $(top_builddir)/src/util/libgnunetutil.la \
        $(top_builddir)/src/gns/libgnunetgns.la \
        $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
        $(top_builddir)/src/identity/libgnunetidentity.la \
        $(top_builddir)/src/namestore/libgnunetnamestore.la \
-       -ljansson
+       -ljansson \
+  $(GN_LIBINTL) $(XLIB)
 libgnunetdid_la_LDFLAGS = \
   $(GN_LIB_LDFLAGS)   \
   -version-info 0:0:0
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index 74c715651..d6ee33f93 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -20,9 +20,80 @@
 
 /**
  * @file reclaim/did_core.c
- * @brief Core functionality for DID 
+ * @brief Core functionality for DID
  * @author Tristan Schwieren
  */
 
 
-#include "did_core.h"
\ No newline at end of file
+#include "did_core.h"
+
+static DID_resolve_callback *resolve_cb;
+static DID_action_callback *action_cb;
+static void *closure;
+
+/**
+ * @brief GNS lookup callback. Calls the given callback function 
+ * and gives it the DID Document.
+ * Fails if there is more than one DID record.
+ *
+ * @param cls closure
+ * @param rd_count number of records in rd
+ * @param rd the records in the reply
+ */
+static void
+DID_resolve_gns_lookup_cb (
+  void *cls,
+  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;
+
+  if (rd_count != 1)
+    resolve_cb (GNUNET_NO, "An ego should only have one DID Document", 
closure);
+
+  if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
+  {
+    didd = (char *) rd[0].data;
+    resolve_cb (GNUNET_NO, didd, closure);
+  }
+  else
+    resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure);
+}
+
+/**
+ * @brief Resolve a DID.
+ * Calls the given callback function with the resolved DID Document and the 
given closure.
+ * If the did can not be resolved did_document is NULL.
+ *
+ * @param did DID that is resolved
+ * @param gns_handle pointer to gns handle.
+ * @param cont callback function
+ * @param cls closure
+ */
+enum GNUNET_GenericReturnValue
+DID_resolve (const char *did,
+             struct GNUNET_GNS_Handle *gns_handle,
+             DID_resolve_callback *cont,
+             void *cls)
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+
+  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;
+
+  GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
+                     GNUNET_DNSPARSER_TYPE_TXT,
+                     GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
+}
\ No newline at end of file
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
index 6a1c23bc8..21a7cbd89 100644
--- a/src/reclaim/did_core.h
+++ b/src/reclaim/did_core.h
@@ -34,14 +34,15 @@
 
 /**
  * @brief Signature of a callback function that is called after a did has been 
resolved.
- * did_document is NULL if DID can not be resolved.
+ * did_document contains an Error message if DID can not be resolved.
  * Calls the given callback function with the resolved DID Document and the 
given closure.
  * If the did can not be resolved did_document is NULL.
+ * @param status Equals GNUNET_OK if DID Docuemnt has been resolved
  * @param did_document resolved DID Document
  * @param cls previsouly given closure
  */
 typedef void
-  DID_resolve_callback (char *did_document, void *cls);
+  DID_resolve_callback (enum GNUNET_GenericReturnValue status, char 
*did_document, void *cls);
 
 /**
  * @brief Signature of a callback function that is called after a did has been 
removed
diff --git a/src/reclaim/did_helper.c b/src/reclaim/did_helper.c
index 0cc400c09..ff4ced0f2 100644
--- a/src/reclaim/did_helper.c
+++ b/src/reclaim/did_helper.c
@@ -75,8 +75,8 @@ DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego)
 /**
  * @brief Return the public key of a DID
  */
-int
-DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
+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>
@@ -92,10 +92,10 @@ DID_did_to_pkey (char *did, struct 
GNUNET_IDENTITY_PublicKey *pkey)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not decode given DID: %s\n",
                 did);
-    return 1;
+    return GNUNET_NO;
   }
 
-  return 0;
+  return GNUNET_OK;
 }
 
 /**
diff --git a/src/reclaim/did_helper.h b/src/reclaim/did_helper.h
index 729d0d835..c3ee457af 100644
--- a/src/reclaim/did_helper.h
+++ b/src/reclaim/did_helper.h
@@ -45,8 +45,8 @@ DID_identity_to_did (struct GNUNET_IDENTITY_Ego *ego);
 /**
  * @brief Return the public key of a DID
  */
-int
-DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
+enum GNUNET_GenericReturnValue
+DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
 
 // /**
 //  * @brief Convert a base 64 encoded public key to a GNUNET key
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index 435aad3fe..2ba12e8eb 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -39,6 +39,7 @@
 #include "gnunet_gns_service.h"
 #include "gnunet_gnsrecord_lib.h"
 #include "did_helper.h"
+#include "did_core.h"
 #include "jansson.h"
 
 #define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d"
@@ -165,7 +166,7 @@ get_did_for_ego_lookup_cb (void *cls, struct 
GNUNET_IDENTITY_Ego *ego)
     ret = 1;
     return;
   }
-  did_str = GNUNET_DID_identity_to_did (ego);
+  did_str = DID_identity_to_did (ego);
 
   printf ("%s\n", did_str);
 
@@ -261,27 +262,46 @@ print_did_document (
   return;
 }
 
+static void
+print_did_document2(
+  enum GNUNET_GenericReturnValue status,
+  char *did_document, 
+  void *cls
+)
+{
+  if (GNUNET_OK == status)
+    printf("%s\n", did_document);
+  else 
+    printf("An error occured: %s\n", did_document);
+
+  GNUNET_SCHEDULER_add_now (cleanup, NULL);
+  ret = 0;
+  return;
+}
+
 /**
  * @brief Resolve a DID given by the user.
  */
 static void
 resolve_did_document ()
 {
-  struct GNUNET_IDENTITY_PublicKey pkey;
+  // struct GNUNET_IDENTITY_PublicKey pkey;
 
-  if (did == NULL)
-  {
-    printf ("Set DID option to resolve DID\n");
-    GNUNET_SCHEDULER_add_now (cleanup, NULL);
-    ret = 1;
-    return;
-  }
+  // if (did == NULL)
+  // {
+  //   printf ("Set DID option to resolve DID\n");
+  //   GNUNET_SCHEDULER_add_now (cleanup, NULL);
+  //   ret = 1;
+  //   return;
+  // }
+
+  // get_pkey_from_attr_did (&pkey);
 
-  get_pkey_from_attr_did (&pkey);
+  // GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
+  //                    GNUNET_DNSPARSER_TYPE_TXT,
+  //                    GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
 
-  GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
-                     GNUNET_DNSPARSER_TYPE_TXT,
-                     GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
+  DID_resolve(did, gns_handle, print_did_document2, NULL);
 }
 
 
@@ -486,7 +506,7 @@ create_did_ego_lockup_cb (void *cls, struct 
GNUNET_IDENTITY_Ego *ego)
   }
   else {
     // Generate DID Docuement from public key
-    didd_str = GNUNET_DID_pkey_to_did_document (&pkey);
+    didd_str = DID_pkey_to_did_document (&pkey);
   }
 
   // Print DID Document to stdout
@@ -650,7 +670,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
   }
   if (1 == show_all)
   {
-    did_str = GNUNET_DID_identity_to_did (ego);
+    did_str = DID_identity_to_did (ego);
     printf ("%s\n", did_str);
     GNUNET_free (did_str);
     return;
@@ -659,7 +679,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
   {
     if (0 == strncmp (name, egoname, strlen (egoname)))
     {
-      did_str = GNUNET_DID_identity_to_did (ego);
+      did_str = DID_identity_to_did (ego);
       printf ("%s\n", did_str);
       GNUNET_free (did_str);
       return;

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