[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.
- [gnunet] 35/70: -test against mb b64, (continued)
- [gnunet] 35/70: -test against mb b64, gnunet, 2022/08/31
- [gnunet] 38/70: -did working replace, generalized remove, refactor, gnunet, 2022/08/31
- [gnunet] 39/70: -did expiration time fix, gnunet, 2022/08/31
- [gnunet] 50/70: - not working test, gnunet, 2022/08/31
- [gnunet] 47/70: -move to reclaim, gnunet, 2022/08/31
- [gnunet] 44/70: -add comments, gnunet, 2022/08/31
- [gnunet] 43/70: -mergefix, gnunet, 2022/08/31
- [gnunet] 36/70: -did not working remove abstraction, gnunet, 2022/08/31
- [gnunet] 45/70: fix bugs, gnunet, 2022/08/31
- [gnunet] 66/70: - DID lib; renamed vars and moved a free, gnunet, 2022/08/31
- [gnunet] 63/70: - remove static variable from did_core,
gnunet <=
- [gnunet] 55/70: - finished DID helper with tests, gnunet, 2022/08/31
- [gnunet] 60/70: - started with DID lib create func, gnunet, 2022/08/31
- [gnunet] 54/70: - default did document test without multibase, gnunet, 2022/08/31
- [gnunet] 68/70: - DID lib; simplify closure, gnunet, 2022/08/31
- [gnunet] 30/70: -DID refactor, uncrustify, not working didd create, gnunet, 2022/08/31
- [gnunet] 31/70: - did not working create, gnunet, 2022/08/31
- [gnunet] 46/70: -code review, gnunet, 2022/08/31
- [gnunet] 53/70: - more tests, gnunet, 2022/08/31
- [gnunet] 61/70: - non working DID lib create func, gnunet, 2022/08/31
- [gnunet] 57/70: - changed did_core header, gnunet, 2022/08/31