diff options
author | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-01 15:41:00 +0200 |
---|---|---|
committer | Tristan Schwieren <tristan.schwieren@tum.de> | 2022-07-01 15:41:00 +0200 |
commit | 00047451b7e2e466c0f8b887280054bac3106cbd (patch) | |
tree | f35d4307faee58b7db083cbcb6556ad3c608cfe3 /src/reclaim | |
parent | 2c8ab6b923a99e5a97cfca0185f1d300cb774f08 (diff) | |
download | gnunet-00047451b7e2e466c0f8b887280054bac3106cbd.tar.gz gnunet-00047451b7e2e466c0f8b887280054bac3106cbd.zip |
- remove static variable from did_core
Diffstat (limited to 'src/reclaim')
-rw-r--r-- | src/reclaim/did_core.c | 46 | ||||
-rw-r--r-- | src/reclaim/did_helper.c | 8 | ||||
-rw-r--r-- | 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 @@ | |||
25 | */ | 25 | */ |
26 | 26 | ||
27 | 27 | ||
28 | // TODO: Expiration time missing in create | ||
29 | // TODO: Check if ego already has a DID document in create | ||
30 | // TODO: Store DID document with empty label and own type (maybe DID-Document or Json??) | ||
31 | // TODO: Store DID document as compact JSON in GNS but resolve it with newlines | ||
32 | |||
28 | #include "did_core.h" | 33 | #include "did_core.h" |
29 | 34 | ||
30 | // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT | 35 | // #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT |
31 | #define DID_DOCUMENT_LABEL "didd" | 36 | #define DID_DOCUMENT_LABEL "didd" |
32 | #define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d" | 37 | #define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d" |
33 | 38 | ||
34 | static DID_resolve_callback *resolve_cb; | ||
35 | static void *closure; | ||
36 | |||
37 | struct DID_resolve_return | 39 | struct DID_resolve_return |
38 | { | 40 | { |
39 | DID_resolve_callback *cb; | 41 | DID_resolve_callback *cb; |
@@ -65,24 +67,21 @@ DID_resolve_gns_lookup_cb ( | |||
65 | uint32_t rd_count, | 67 | uint32_t rd_count, |
66 | const struct GNUNET_GNSRECORD_Data *rd) | 68 | const struct GNUNET_GNSRECORD_Data *rd) |
67 | { | 69 | { |
68 | /* | 70 | char *did_document; |
69 | * FIXME-MSC: The user may decide to put other records here. | 71 | DID_resolve_callback *cb = ((struct DID_resolve_return *) cls)->cb; |
70 | * In general I am fine with the constraint here, but not when | 72 | void *cls2 = ((struct DID_resolve_return *) cls)->cls; |
71 | * we move it to "@" | 73 | free (cls); |
72 | */ | ||
73 | |||
74 | char *didd; | ||
75 | 74 | ||
76 | if (rd_count != 1) | 75 | if (rd_count != 1) |
77 | resolve_cb (GNUNET_NO, "An ego should only have one DID Document", closure); | 76 | cb (GNUNET_NO, "An ego should only have one DID Document", cls2); |
78 | 77 | ||
79 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) | 78 | if (rd[0].record_type == GNUNET_DNSPARSER_TYPE_TXT) |
80 | { | 79 | { |
81 | didd = (char *) rd[0].data; | 80 | did_document = (char *) rd[0].data; |
82 | resolve_cb (GNUNET_OK, didd, closure); | 81 | cb (GNUNET_OK, did_document, cls2); |
83 | } | 82 | } |
84 | else | 83 | else |
85 | resolve_cb (GNUNET_NO, "DID Document is not a TXT record\n", closure); | 84 | cb (GNUNET_NO, "DID Document is not a TXT record\n", cls2); |
86 | } | 85 | } |
87 | 86 | ||
88 | /** | 87 | /** |
@@ -103,18 +102,21 @@ DID_resolve (const char *did, | |||
103 | { | 102 | { |
104 | struct GNUNET_IDENTITY_PublicKey pkey; | 103 | struct GNUNET_IDENTITY_PublicKey pkey; |
105 | 104 | ||
105 | // did, gns_handle and cont must me set | ||
106 | if ((did == NULL) || (gns_handle == NULL) || (cont == NULL)) | 106 | if ((did == NULL) || (gns_handle == NULL) || (cont == NULL)) |
107 | return GNUNET_NO; | 107 | return GNUNET_NO; |
108 | 108 | ||
109 | resolve_cb = cont; | ||
110 | closure = cls; | ||
111 | |||
112 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) | 109 | if (GNUNET_OK != DID_did_to_pkey (did, &pkey)) |
113 | return GNUNET_NO; | 110 | return GNUNET_NO; |
114 | 111 | ||
112 | // Create closure for lockup callback | ||
113 | struct DID_resolve_return *cls2 = malloc (sizeof(struct DID_resolve_return)); | ||
114 | cls2->cb = cont; | ||
115 | cls2->cls = cls; | ||
116 | |||
115 | GNUNET_GNS_lookup (gns_handle, DID_DOCUMENT_LABEL, &pkey, | 117 | GNUNET_GNS_lookup (gns_handle, DID_DOCUMENT_LABEL, &pkey, |
116 | GNUNET_DNSPARSER_TYPE_TXT, | 118 | GNUNET_DNSPARSER_TYPE_TXT, |
117 | GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL); | 119 | GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, cls2); |
118 | 120 | ||
119 | return GNUNET_OK; | 121 | return GNUNET_OK; |
120 | } | 122 | } |
@@ -138,14 +140,12 @@ DID_create_did_store_cb (void *cls, | |||
138 | } | 140 | } |
139 | else | 141 | else |
140 | { | 142 | { |
143 | // TODO: Log emsg. Not writing it to STDOUT | ||
141 | printf ("%s\n", emsg); | 144 | printf ("%s\n", emsg); |
142 | cb (GNUNET_NO, (void *) cls2); | 145 | cb (GNUNET_NO, (void *) cls2); |
143 | } | 146 | } |
144 | } | 147 | } |
145 | 148 | ||
146 | // TODO: Expiration time missing | ||
147 | // TODO: Check if ego already has a DID document | ||
148 | |||
149 | /** | 149 | /** |
150 | * @brief Creates a DID and saves DID Document in Namestore. | 150 | * @brief Creates a DID and saves DID Document in Namestore. |
151 | * | 151 | * |
@@ -169,6 +169,10 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego, | |||
169 | struct GNUNET_TIME_Relative expire_time; | 169 | struct GNUNET_TIME_Relative expire_time; |
170 | struct GNUNET_GNSRECORD_Data record_data; | 170 | struct GNUNET_GNSRECORD_Data record_data; |
171 | 171 | ||
172 | // Ego, namestore_handle and cont must be set | ||
173 | if ((ego == NULL) || (namestore_handle == NULL) || (cont == NULL)) | ||
174 | return GNUNET_NO; | ||
175 | |||
172 | // Check if ego has EdDSA key | 176 | // Check if ego has EdDSA key |
173 | GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego, | 177 | GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) ego, |
174 | &pkey); | 178 | &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) | |||
78 | enum GNUNET_GenericReturnValue | 78 | enum GNUNET_GenericReturnValue |
79 | DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey) | 79 | DID_did_to_pkey (const char *did, struct GNUNET_IDENTITY_PublicKey *pkey) |
80 | { | 80 | { |
81 | /* FIXME-MSC: I suggest introducing a | ||
82 | * #define MAX_DID_LENGTH <something> | ||
83 | * here and use it for parsing | ||
84 | */ | ||
85 | char pkey_str[MAX_DID_SPECIFIC_IDENTIFIER_LENGTH]; | 81 | char pkey_str[MAX_DID_SPECIFIC_IDENTIFIER_LENGTH]; |
86 | 82 | ||
87 | if ((1 != (sscanf (did, | 83 | if ((1 != (sscanf (did, |
@@ -112,8 +108,8 @@ GNUNET_DID_key_covert_multibase_base64_to_gnunet (char *pkey_str) | |||
112 | */ | 108 | */ |
113 | char * | 109 | char * |
114 | DID_key_covert_gnunet_to_multibase_base64 (struct | 110 | DID_key_covert_gnunet_to_multibase_base64 (struct |
115 | GNUNET_IDENTITY_PublicKey * | 111 | GNUNET_IDENTITY_PublicKey * |
116 | pkey) | 112 | pkey) |
117 | { | 113 | { |
118 | struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key; | 114 | struct GNUNET_CRYPTO_EddsaPublicKey pubkey = pkey->eddsa_key; |
119 | 115 | ||
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) | |||
153 | * @param cls closure | 153 | * @param cls closure |
154 | * @param ego the returned ego | 154 | * @param ego the returned ego |
155 | */ | 155 | */ |
156 | static void | 156 | // static void |
157 | get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | 157 | // get_did_for_ego_lookup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) |
158 | { | 158 | // { |
159 | char *did_str; | 159 | // char *did_str; |
160 | 160 | // | |
161 | if (ego == NULL) | 161 | // if (ego == NULL) |
162 | { | 162 | // { |
163 | printf ("EGO not found\n"); | 163 | // printf ("EGO not found\n"); |
164 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 164 | // GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
165 | ret = 1; | 165 | // ret = 1; |
166 | return; | 166 | // return; |
167 | } | 167 | // } |
168 | did_str = DID_identity_to_did (ego); | 168 | // did_str = DID_identity_to_did (ego); |
169 | 169 | // | |
170 | printf ("%s\n", did_str); | 170 | // printf ("%s\n", did_str); |
171 | 171 | // | |
172 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 172 | // GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
173 | ret = 0; | 173 | // ret = 0; |
174 | return; | 174 | // return; |
175 | } | 175 | // } |
176 | 176 | ||
177 | /** | 177 | /** |
178 | * @brief Get the DID for a given EGO | 178 | * @brief Get the DID for a given EGO |
179 | * | 179 | * |
180 | */ | 180 | */ |
181 | static void | 181 | // static void |
182 | get_did_for_ego () | 182 | // get_did_for_ego () |
183 | { | 183 | // { |
184 | if (egoname != NULL) | 184 | // if (egoname != NULL) |
185 | { | 185 | // { |
186 | GNUNET_IDENTITY_ego_lookup (my_cfg, | 186 | // GNUNET_IDENTITY_ego_lookup (my_cfg, |
187 | egoname, | 187 | // egoname, |
188 | &get_did_for_ego_lookup_cb, | 188 | // &get_did_for_ego_lookup_cb, |
189 | NULL); | 189 | // NULL); |
190 | } | 190 | // } |
191 | else { | 191 | // else { |
192 | printf ("Set the EGO argument to get the DID for a given EGO\n"); | 192 | // printf ("Set the EGO argument to get the DID for a given EGO\n"); |
193 | GNUNET_SCHEDULER_add_now (&cleanup, NULL); | 193 | // GNUNET_SCHEDULER_add_now (&cleanup, NULL); |
194 | ret = 1; | 194 | // ret = 1; |
195 | return; | 195 | // return; |
196 | } | 196 | // } |
197 | } | 197 | // } |
198 | 198 | ||
199 | /** | 199 | /** |
200 | * @brief Resolve DID callback. Prints the DID Document to standard out. | 200 | * @brief Resolve DID callback. Prints the DID Document to standard out. |
@@ -374,7 +374,7 @@ create_did_cb (enum GNUNET_GenericReturnValue status, void *cls) | |||
374 | } | 374 | } |
375 | else | 375 | else |
376 | { | 376 | { |
377 | printf ("An error occured while creating the DID\n"); | 377 | printf ("An error occured while creating the DID.\n"); |
378 | ret = 1; | 378 | ret = 1; |
379 | } | 379 | } |
380 | 380 | ||
@@ -427,6 +427,7 @@ create_did_ego_lockup_cb (void *cls, struct GNUNET_IDENTITY_Ego *ego) | |||
427 | char *did = DID_identity_to_did (ego); | 427 | char *did = DID_identity_to_did (ego); |
428 | void *cls = malloc (strlen (did) + 1); | 428 | void *cls = malloc (strlen (did) + 1); |
429 | strcpy (cls, did); | 429 | strcpy (cls, did); |
430 | // TODO: Add DID_document argument | ||
430 | DID_create (ego, NULL, namestore_handle, create_did_cb, cls); | 431 | DID_create (ego, NULL, namestore_handle, create_did_cb, cls); |
431 | } | 432 | } |
432 | } | 433 | } |
@@ -513,6 +514,8 @@ replace_did_document () | |||
513 | static void | 514 | static void |
514 | post_ego_iteration (void *cls) | 515 | post_ego_iteration (void *cls) |
515 | { | 516 | { |
517 | // TODO: Check that only one argument is set | ||
518 | |||
516 | if (1 == replace) | 519 | if (1 == replace) |
517 | { | 520 | { |
518 | replace_did_document (); | 521 | replace_did_document (); |
@@ -633,10 +636,6 @@ main (int argc, char *const argv[]) | |||
633 | gettext_noop ( | 636 | gettext_noop ( |
634 | "Get the DID Document associated with the given DID"), | 637 | "Get the DID Document associated with the given DID"), |
635 | &get), | 638 | &get), |
636 | GNUNET_GETOPT_option_flag ('s', | ||
637 | "show", | ||
638 | gettext_noop ("Show the DID for a given ego"), | ||
639 | &show), | ||
640 | GNUNET_GETOPT_option_flag ('r', | 639 | GNUNET_GETOPT_option_flag ('r', |
641 | "remove", | 640 | "remove", |
642 | gettext_noop ( | 641 | gettext_noop ( |
@@ -646,9 +645,13 @@ main (int argc, char *const argv[]) | |||
646 | "replace", | 645 | "replace", |
647 | gettext_noop ("Replace the DID Document."), | 646 | gettext_noop ("Replace the DID Document."), |
648 | &replace), | 647 | &replace), |
648 | GNUNET_GETOPT_option_flag ('s', | ||
649 | "show", | ||
650 | gettext_noop ("Show the DID for a given ego"), | ||
651 | &show), | ||
649 | GNUNET_GETOPT_option_flag ('A', | 652 | GNUNET_GETOPT_option_flag ('A', |
650 | "show-all", | 653 | "show-all", |
651 | gettext_noop ("Replace the DID Document."), | 654 | gettext_noop ("Show egos with DIDs"), |
652 | &show_all), | 655 | &show_all), |
653 | GNUNET_GETOPT_option_string ('d', | 656 | GNUNET_GETOPT_option_string ('d', |
654 | "did", | 657 | "did", |