gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 59/70: - DID resolve using DID lib


From: gnunet
Subject: [gnunet] 59/70: - DID resolve using DID lib
Date: Wed, 31 Aug 2022 18:00:53 +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 ec36e49c337b336ed46b1e7d3f26aafce2be008b
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Tue Jun 28 15:33:43 2022 +0200

    - DID resolve using DID lib
---
 src/reclaim/did_core.c   |  9 +++--
 src/reclaim/gnunet-did.c | 94 ++++++++++--------------------------------------
 2 files changed, 25 insertions(+), 78 deletions(-)

diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index d6ee33f93..5cecc2972 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -27,6 +27,9 @@
 
 #include "did_core.h"
 
+// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT
+#define DID_DOCUMENT_LABEL "didd"
+
 static DID_resolve_callback *resolve_cb;
 static DID_action_callback *action_cb;
 static void *closure;
@@ -60,7 +63,7 @@ DID_resolve_gns_lookup_cb (
   if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
   {
     didd = (char *) rd[0].data;
-    resolve_cb (GNUNET_NO, didd, closure);
+    resolve_cb (GNUNET_OK, didd, closure);
   }
   else
     resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure);
@@ -93,7 +96,9 @@ DID_resolve (const char *did,
   if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
     return GNUNET_NO;
 
-  GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
+  GNUNET_GNS_lookup (gns_handle, DID_DOCUMENT_LABEL, &pkey,
                      GNUNET_DNSPARSER_TYPE_TXT,
                      GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
+
+  return GNUNET_OK;
 }
\ No newline at end of file
diff --git a/src/reclaim/gnunet-did.c b/src/reclaim/gnunet-did.c
index 2ba12e8eb..3629c22f8 100644
--- a/src/reclaim/gnunet-did.c
+++ b/src/reclaim/gnunet-did.c
@@ -147,7 +147,6 @@ cleanup (void *cls)
   GNUNET_SCHEDULER_shutdown ();
 }
 
-
 /**
  * @brief Callback for ego loockup of get_did_for_ego()
  *
@@ -197,73 +196,16 @@ get_did_for_ego ()
   }
 }
 
-
-/**
- * @brief Get the public key from did attribute given by the user
- *
- * @param pkey place to write the public key to
- */
-static void
-get_pkey_from_attr_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[59];
-
-  if ((1 != (sscanf (did, GNUNET_DID_METHOD_PREFIX "%58s", pkey_str))) ||
-      (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (pkey_str, pkey)))
-  {
-    fprintf (stderr, _ ("Invalid DID `%s'\n"), pkey_str);
-    GNUNET_SCHEDULER_add_now (cleanup, NULL);
-    ret = 1;
-    return;
-  }
-}
-
 /**
- * @brief GNS lookup callback. Prints the DID Document to standard out.
- * Fails if there is more than one DID record.
+ * @brief Resolve DID callback. Prints the DID Document to standard out.
+ * Prints error message if resolve fails
  *
  * @param cls closure
  * @param rd_count number of records in @a rd
  * @param rd the records in the reply
  */
 static void
-print_did_document (
-  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 "@"
-   */
-  if (rd_count != 1)
-  {
-    printf ("An ego should only have one DID Document\n");
-    GNUNET_SCHEDULER_add_now (cleanup, NULL);
-    ret = 1;
-    return;
-  }
-
-  if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
-  {
-    printf ("%s\n", (char *) rd[0].data);
-  }
-  else {
-    printf ("DID Document is not a TXT record\n");
-  }
-
-  GNUNET_SCHEDULER_add_now (cleanup, NULL);
-  ret = 0;
-  return;
-}
-
-static void
-print_did_document2(
+print_did_document(
   enum GNUNET_GenericReturnValue status,
   char *did_document, 
   void *cls
@@ -285,23 +227,23 @@ print_did_document2(
 static void
 resolve_did_document ()
 {
-  // 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;
-  // }
-
-  // get_pkey_from_attr_did (&pkey);
+  struct GNUNET_IDENTITY_PublicKey pkey;
 
-  // GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
-  //                    GNUNET_DNSPARSER_TYPE_TXT,
-  //                    GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
+  if (did == NULL)
+  {
+    printf ("Set DID option to resolve DID\n");
+    GNUNET_SCHEDULER_add_now (cleanup, NULL);
+    ret = 1;
+    return;
+  }
 
-  DID_resolve(did, gns_handle, print_did_document2, NULL);
+  if (GNUNET_OK != DID_resolve(did, gns_handle, print_did_document, NULL))
+  {
+    printf("An error occured while resoling the DID\n");
+    GNUNET_SCHEDULER_add_now(cleanup, NULL);
+    ret = 0;
+    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]