gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet] 26/70: - DID remove


From: gnunet
Subject: [gnunet] 26/70: - DID remove
Date: Wed, 31 Aug 2022 18:00:20 +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 37569e7e94009bd9610c48cb66ade654922f7265
Author: Tristan Schwieren <tristan.schwieren@tum.de>
AuthorDate: Mon Nov 29 11:32:41 2021 +0100

    - DID remove
---
 src/did/gnunet-did.c | 239 +++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 174 insertions(+), 65 deletions(-)

diff --git a/src/did/gnunet-did.c b/src/did/gnunet-did.c
index b9fe25f4a..846ee1906 100644
--- a/src/did/gnunet-did.c
+++ b/src/did/gnunet-did.c
@@ -28,68 +28,56 @@
 #include "gnunet_namestore_service.h"
 #include "gnunet_gns_service.h"
 
+/**
+ * return value
+ */
+static int ret;
+
 /**
  * Attribute Add 
  */
 static char *attr_add;
 
 /**
- * Attribute delete
+ * Attribute remove 
  */
-static char *attr_delete;
+static int *attr_remove;
 
 /**
- * Attribute get
+ *  Attibute get
  */
-static char *attr_value;
+static int *attr_get;
 
-static struct GNUNET_NAMESTORE_Handle *nc;
-static struct GNUNET_GNS_Handle *gns_handle;
-static struct GNUNET_DHT_Handle *dht;
-static struct GNUNET_CONFIGURATRION_Handle *c;
-static unsigned long long max_bg_queries = 100;
+/**
+ * Attribute did
+ */
+static char *attr_did;
 
 /**
- * return value
+ * Attribute did
  */
-static int ret;
+static char *attr_ego;
 
-static void cleanup(void * cls){
-  GNUNET_GNS_disconnect(gns_handle);
-  GNUNET_NAMESTORE_disconnect(nc);
-  GNUNET_SCHEDULER_shutdown();
-}
+static struct GNUNET_GNS_Handle *gns_handle;
+static struct GNUNET_NAMESTORE_Handle *namestore_handle;
+static struct GNUNET_CONFIGURATRION_Handle *c;
 
-static void did_print(
-  void *cls,
-  uint32_t rd_count,
-  const struct GNUNET_GNSRECORD_Data *rd){
-    int i;
-    for(i = 0; i < rd_count; i++){
-      // rd is not always a string
-      printf("%s\n", rd[i].data);
-    }
-    GNUNET_SCHEDULER_add_now(cleanup, NULL);
-  }
+static void resolve_did_document();
+static void add_did_document();
+static void get_pkey_from_attr_did();
+static void print_did_document();
+static void remove_did_document();
+
+// TODO
+// static void get_did_for_ego();
+// static void generate_did_document();
+// static void replace_did_document(); - use remove_did_document and 
add_did_document
+// A method to manipulate did document
+
+// Add a data DID Document type
 
-static void
-resolve_didd()
-{
-  char * id_str;
-  struct GNUNET_IDENTITY_PublicKey pkey;
-    if ((1 != (sscanf (attr_value, "did:reclaim:%68s", id_str))) ||
-        (GNUNET_OK !=
-         GNUNET_IDENTITY_public_key_from_string (id_str, &pkey)))
-    {
-      fprintf (stderr, _ ("Invalid DID `%s'\n"), id_str);
-      GNUNET_SCHEDULER_shutdown ();
-      ret = 1;
-      return;
-    }
-
-  // Check the type of retured records
-  GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, 
GNUNET_GNS_LO_DEFAULT, &did_print, NULL);
-}
+
+static void cleanup();
 
 static void
 run (void *cls,
@@ -97,29 +85,45 @@ run (void *cls,
      const char *cfgfile,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-  nc = GNUNET_NAMESTORE_connect(c);
+  gns_handle = GNUNET_GNS_connect(c);
+  namestore_handle = GNUNET_NAMESTORE_connect(c);
 
-  if(nc == NULL){
+  // check if GNS_handle could connect
+  if(gns_handle == NULL){
     ret = 1;
     return;
   }
-
-  gns_handle = GNUNET_GNS_connect(c);
-
-  if(gns_handle == NULL){
+  
+  // check if NAMESTORE_handle could connect
+  if(namestore_handle == NULL){
     ret = 1;
     return;
   }
 
-  if (NULL != attr_value){
-    resolve_didd();
+  // check for more than one argument given
+  //if (NULL != attr_did && NULL != attr_delete ||
+  //    NULL != attr_did && NULL != attr_add ||
+  //    NULL != attr_delete && NULL != attr_add)
+  if(false)
+  {
+    ret = 1;
+    GNUNET_SCHEDULER_add_now(cleanup, NULL);
     return;
   }
-  else {
-    GNUNET_SCHEDULER_add_now(&cleanup, NULL);
-  }
 
-  ret = 0;
+  if (NULL != attr_add) {
+    add_did_document();
+  } else if (NULL != attr_did && 1 == attr_get){
+    resolve_did_document();
+  } else if (NULL != attr_did && 1 == attr_remove) {
+    remove_did_document();
+  } else {
+    // No Argument found
+    printf("No correct argument combination found. Use gnunet-did -h for 
help");
+    ret = 1;
+    GNUNET_SCHEDULER_add_now(cleanup, NULL);
+    return;
+  }
 }
 
 int
@@ -131,16 +135,24 @@ main (int argc, char *const argv[])
                                  "VALUE",
                                  gettext_noop ("Add an DID Document"),
                                  &attr_add),
+    GNUNET_GETOPT_option_flag ('r',
+                              "remove",
+                              gettext_noop ("Remove the DID Document with DID 
from GNUNET"),
+                              &attr_remove),
+    GNUNET_GETOPT_option_flag ('g',
+                              "get",
+                              gettext_noop ("Get the DID Document associated 
with the given DID"),
+                              &attr_get),
     GNUNET_GETOPT_option_string ('d',
-                                 "delete",
-                                 "ID",
-                                 gettext_noop ("Delete the DID Document with 
DID"),
-                                 &attr_delete),
-    GNUNET_GETOPT_option_string ('g',
-                                 "value",
+                                 "did",
+                                 "VALUE",
+                                 gettext_noop ("The DID to work with"),
+                                 &attr_did),
+    GNUNET_GETOPT_option_string ('e',
+                                 "ego",
                                  "VALUE",
-                                 gettext_noop ("Get the DID Document with 
DID"),
-                                 &attr_value),
+                                 gettext_noop ("The EGO to work with"),
+                                 &attr_ego),
     GNUNET_GETOPT_OPTION_END
   };
 
@@ -155,3 +167,100 @@ main (int argc, char *const argv[])
   else
     return ret;
 }
+
+    
+static void
+add_did_document(){
+  printf("Do nothing\n");
+}
+
+static void
+resolve_did_document()
+{
+  struct GNUNET_IDENTITY_PublicKey pkey;
+  get_pkey_from_attr_did(&pkey);
+
+  // TODO: Check the type of returned records
+  GNUNET_GNS_lookup(gns_handle, "didd", &pkey, GNUNET_DNSPARSER_TYPE_TXT, 
GNUNET_GNS_LO_DEFAULT, &print_did_document, NULL);
+}
+
+static void
+get_pkey_from_attr_did(struct GNUNET_IDENTITY_PublicKey * pkey)
+{
+  char id_str[59];
+
+  if ((1 != (sscanf (attr_did, "did:reclaim:%58s", id_str))) ||
+      (GNUNET_OK != GNUNET_IDENTITY_public_key_from_string (id_str, pkey)))
+  {
+    fprintf (stderr, _ ("Invalid DID `%s'\n"), id_str);
+    GNUNET_SCHEDULER_add_now(cleanup, NULL);
+    ret = 1;
+    return;
+  }
+}
+
+static void 
+print_did_document(
+  void *cls,
+  uint32_t rd_count,
+  const struct GNUNET_GNSRECORD_Data *rd)
+{
+  // TODO: Remove "store.sock" at the end of print
+  int i;
+  if (rd_count != 1)
+  {
+    printf("An ego should only have one DID Document");
+    ret = 1;
+    return;
+  }
+
+  printf("%s\n", rd[0].data);
+
+  GNUNET_SCHEDULER_add_now(cleanup, NULL);
+  ret = 0;
+  return;
+}
+
+static void 
+remove_did_document()
+{
+  // Use private key for now
+  // TODO: Use did->pkey->ego->skey or ego->skey to remove did document
+  struct GNUNET_IDENTITY_PublicKey pkey;
+  get_pkey_from_attr_did(&pkey);
+
+  const struct GNUNET_IDENTITY_PrivateKey skey; // get the skey based on the 
pkey in DID
+  const struct GNUNET_GNSRECORD_Data rd; // should be the empty array
+
+  //GNUNET_NAMESTORE_records_store (namestore_handle,
+  //                                *pkey,
+  //                                "didd",
+  //                                0,
+  //                                *rd,
+  //                                &remove_did_callback,
+  //                                NULL);
+
+}
+
+static void
+get_ego_from_attr_ego(struct GNUNET_IDENTITY_Ego * ego)
+{
+  // Use string to get EGO 
+  // GNUNET_IDENTITY_ego_lookup -> GNUNET_IDENTITY_EgoCallback -> ...
+  // Think about how to pass parameter - Functional programming
+}
+
+static void
+remove_did_callback(){
+  printf("DID Document has been removed\n");
+  GNUNET_SCHEDULER_add_now(cleanup, NULL);
+  ret = 0;
+  return;
+}
+
+static void 
+cleanup(void * cls){
+  GNUNET_GNS_disconnect(gns_handle);
+  GNUNET_NAMESTORE_disconnect(namestore_handle);
+  GNUNET_SCHEDULER_shutdown();
+}

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