aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-06-27 18:32:01 +0200
committerTristan Schwieren <tristan.schwieren@tum.de>2022-06-27 18:32:01 +0200
commit47e7cc4fd4c9341926f0cd4aca2b38e9cd5aba7e (patch)
treeb3e75ccb67c3fcd077aeabce6231a798d2493fdf /src/reclaim
parentbc05f5201575ac97edbfedbc77d780fd6db558d6 (diff)
downloadgnunet-47e7cc4fd4c9341926f0cd4aca2b38e9cd5aba7e.tar.gz
gnunet-47e7cc4fd4c9341926f0cd4aca2b38e9cd5aba7e.zip
- missing lib bug
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/Makefile.am7
-rw-r--r--src/reclaim/did_core.c75
-rw-r--r--src/reclaim/did_core.h5
-rw-r--r--src/reclaim/did_helper.c8
-rw-r--r--src/reclaim/did_helper.h4
-rw-r--r--src/reclaim/gnunet-did.c52
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 = \
141 141
142libgnunetdid_la_SOURCES = \ 142libgnunetdid_la_SOURCES = \
143 did_helper.c \ 143 did_helper.c \
144 did_helper.h 144 did_helper.h \
145 did_core.h \
146 did_core.c
145libgnunetdid_la_LIBADD = \ 147libgnunetdid_la_LIBADD = \
146 $(top_builddir)/src/util/libgnunetutil.la \ 148 $(top_builddir)/src/util/libgnunetutil.la \
147 $(top_builddir)/src/gns/libgnunetgns.la \ 149 $(top_builddir)/src/gns/libgnunetgns.la \
148 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 150 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
149 $(top_builddir)/src/identity/libgnunetidentity.la \ 151 $(top_builddir)/src/identity/libgnunetidentity.la \
150 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 152 $(top_builddir)/src/namestore/libgnunetnamestore.la \
151 -ljansson 153 -ljansson \
154 $(GN_LIBINTL) $(XLIB)
152libgnunetdid_la_LDFLAGS = \ 155libgnunetdid_la_LDFLAGS = \
153 $(GN_LIB_LDFLAGS) \ 156 $(GN_LIB_LDFLAGS) \
154 -version-info 0:0:0 157 -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 @@
20 20
21/** 21/**
22 * @file reclaim/did_core.c 22 * @file reclaim/did_core.c
23 * @brief Core functionality for DID 23 * @brief Core functionality for DID
24 * @author Tristan Schwieren 24 * @author Tristan Schwieren
25 */ 25 */
26 26
27 27
28#include "did_core.h" \ No newline at end of file 28#include "did_core.h"
29
30static DID_resolve_callback *resolve_cb;
31static DID_action_callback *action_cb;
32static void *closure;
33
34/**
35 * @brief GNS lookup callback. Calls the given callback function
36 * and gives it the DID Document.
37 * Fails if there is more than one DID record.
38 *
39 * @param cls closure
40 * @param rd_count number of records in rd
41 * @param rd the records in the reply
42 */
43static void
44DID_resolve_gns_lookup_cb (
45 void *cls,
46 uint32_t rd_count,
47 const struct GNUNET_GNSRECORD_Data *rd)
48{
49 /*
50 * FIXME-MSC: The user may decide to put other records here.
51 * In general I am fine with the constraint here, but not when
52 * we move it to "@"
53 */
54
55 char *didd;
56
57 if (rd_count != 1)
58 resolve_cb (GNUNET_NO, "An ego should only have one DID Document", closure);
59
60 if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT)
61 {
62 didd = (char *) rd[0].data;
63 resolve_cb (GNUNET_NO, didd, closure);
64 }
65 else
66 resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure);
67}
68
69/**
70 * @brief Resolve a DID.
71 * Calls the given callback function with the resolved DID Document and the given closure.
72 * If the did can not be resolved did_document is NULL.
73 *
74 * @param did DID that is resolved
75 * @param gns_handle pointer to gns handle.
76 * @param cont callback function
77 * @param cls closure
78 */
79enum GNUNET_GenericReturnValue
80DID_resolve (const char *did,
81 struct GNUNET_GNS_Handle *gns_handle,
82 DID_resolve_callback *cont,
83 void *cls)
84{
85 struct GNUNET_IDENTITY_PublicKey pkey;
86
87 if ((did == NULL) || (gns_handle == NULL) || (cont == NULL))
88 return GNUNET_NO;
89
90 resolve_cb = cont;
91 closure = cls;
92
93 if (GNUNET_OK != DID_did_to_pkey (did, &pkey))
94 return GNUNET_NO;
95
96 GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
97 GNUNET_DNSPARSER_TYPE_TXT,
98 GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
99} \ 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 @@
34 34
35/** 35/**
36 * @brief Signature of a callback function that is called after a did has been resolved. 36 * @brief Signature of a callback function that is called after a did has been resolved.
37 * did_document is NULL if DID can not be resolved. 37 * did_document contains an Error message if DID can not be resolved.
38 * Calls the given callback function with the resolved DID Document and the given closure. 38 * Calls the given callback function with the resolved DID Document and the given closure.
39 * If the did can not be resolved did_document is NULL. 39 * If the did can not be resolved did_document is NULL.
40 * @param status Equals GNUNET_OK if DID Docuemnt has been resolved
40 * @param did_document resolved DID Document 41 * @param did_document resolved DID Document
41 * @param cls previsouly given closure 42 * @param cls previsouly given closure
42 */ 43 */
43typedef void 44typedef void
44 DID_resolve_callback (char *did_document, void *cls); 45 DID_resolve_callback (enum GNUNET_GenericReturnValue status, char *did_document, void *cls);
45 46
46/** 47/**
47 * @brief Signature of a callback function that is called after a did has been removed 48 * @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)
75/** 75/**
76 * @brief Return the public key of a DID 76 * @brief Return the public key of a DID
77 */ 77 */
78int 78enum GNUNET_GenericReturnValue
79DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey) 79DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
80{ 80{
81 /* FIXME-MSC: I suggest introducing a 81 /* FIXME-MSC: I suggest introducing a
82 * #define MAX_DID_LENGTH <something> 82 * #define MAX_DID_LENGTH <something>
@@ -92,10 +92,10 @@ DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey)
92 { 92 {
93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not decode given DID: %s\n", 93 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not decode given DID: %s\n",
94 did); 94 did);
95 return 1; 95 return GNUNET_NO;
96 } 96 }
97 97
98 return 0; 98 return GNUNET_OK;
99} 99}
100 100
101/** 101/**
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);
45/** 45/**
46 * @brief Return the public key of a DID 46 * @brief Return the public key of a DID
47 */ 47 */
48int 48enum GNUNET_GenericReturnValue
49DID_did_to_pkey (char *did, struct GNUNET_IDENTITY_PublicKey *pkey); 49DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey);
50 50
51// /** 51// /**
52// * @brief Convert a base 64 encoded public key to a GNUNET key 52// * @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 @@
39#include "gnunet_gns_service.h" 39#include "gnunet_gns_service.h"
40#include "gnunet_gnsrecord_lib.h" 40#include "gnunet_gnsrecord_lib.h"
41#include "did_helper.h" 41#include "did_helper.h"
42#include "did_core.h"
42#include "jansson.h" 43#include "jansson.h"
43 44
44#define GNUNET_DID_DEFAULT_DID_DOCUMENT_EXPIRATION_TIME "1d" 45#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)
165 ret = 1; 166 ret = 1;
166 return; 167 return;
167 } 168 }
168 did_str = GNUNET_DID_identity_to_did (ego); 169 did_str = DID_identity_to_did (ego);
169 170
170 printf ("%s\n", did_str); 171 printf ("%s\n", did_str);
171 172
@@ -261,27 +262,46 @@ print_did_document (
261 return; 262 return;
262} 263}
263 264
265static void
266print_did_document2(
267 enum GNUNET_GenericReturnValue status,
268 char *did_document,
269 void *cls
270)
271{
272 if (GNUNET_OK == status)
273 printf("%s\n", did_document);
274 else
275 printf("An error occured: %s\n", did_document);
276
277 GNUNET_SCHEDULER_add_now (cleanup, NULL);
278 ret = 0;
279 return;
280}
281
264/** 282/**
265 * @brief Resolve a DID given by the user. 283 * @brief Resolve a DID given by the user.
266 */ 284 */
267static void 285static void
268resolve_did_document () 286resolve_did_document ()
269{ 287{
270 struct GNUNET_IDENTITY_PublicKey pkey; 288 // struct GNUNET_IDENTITY_PublicKey pkey;
271 289
272 if (did == NULL) 290 // if (did == NULL)
273 { 291 // {
274 printf ("Set DID option to resolve DID\n"); 292 // printf ("Set DID option to resolve DID\n");
275 GNUNET_SCHEDULER_add_now (cleanup, NULL); 293 // GNUNET_SCHEDULER_add_now (cleanup, NULL);
276 ret = 1; 294 // ret = 1;
277 return; 295 // return;
278 } 296 // }
297
298 // get_pkey_from_attr_did (&pkey);
279 299
280 get_pkey_from_attr_did (&pkey); 300 // GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey,
301 // GNUNET_DNSPARSER_TYPE_TXT,
302 // GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
281 303
282 GNUNET_GNS_lookup (gns_handle, GNUNET_GNS_EMPTY_LABEL_AT, &pkey, 304 DID_resolve(did, gns_handle, print_did_document2, NULL);
283 GNUNET_DNSPARSER_TYPE_TXT,
284 GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
285} 305}
286 306
287 307
@@ -486,7 +506,7 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego)
486 } 506 }
487 else { 507 else {
488 // Generate DID Docuement from public key 508 // Generate DID Docuement from public key
489 didd_str = GNUNET_DID_pkey_to_did_document (&pkey); 509 didd_str = DID_pkey_to_did_document (&pkey);
490 } 510 }
491 511
492 // Print DID Document to stdout 512 // Print DID Document to stdout
@@ -650,7 +670,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
650 } 670 }
651 if (1 == show_all) 671 if (1 == show_all)
652 { 672 {
653 did_str = GNUNET_DID_identity_to_did (ego); 673 did_str = DID_identity_to_did (ego);
654 printf ("%s\n", did_str); 674 printf ("%s\n", did_str);
655 GNUNET_free (did_str); 675 GNUNET_free (did_str);
656 return; 676 return;
@@ -659,7 +679,7 @@ process_dids (void *cls, struct GNUNET_IDENTITY_Ego *ego,
659 { 679 {
660 if (0 == strncmp (name, egoname, strlen (egoname))) 680 if (0 == strncmp (name, egoname, strlen (egoname)))
661 { 681 {
662 did_str = GNUNET_DID_identity_to_did (ego); 682 did_str = DID_identity_to_did (ego);
663 printf ("%s\n", did_str); 683 printf ("%s\n", did_str);
664 GNUNET_free (did_str); 684 GNUNET_free (did_str);
665 return; 685 return;