gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29026 - gnunet-gtk/src/setup


From: gnunet
Subject: [GNUnet-SVN] r29026 - gnunet-gtk/src/setup
Date: Thu, 5 Sep 2013 14:36:49 +0200

Author: grothoff
Date: 2013-09-05 14:36:49 +0200 (Thu, 05 Sep 2013)
New Revision: 29026

Modified:
   gnunet-gtk/src/setup/Makefile.am
   gnunet-gtk/src/setup/gnunet-setup-gns.c
Log:
-use identity service when editing a zone (#3014)

Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am    2013-09-05 12:36:43 UTC (rev 29025)
+++ gnunet-gtk/src/setup/Makefile.am    2013-09-05 12:36:49 UTC (rev 29026)
@@ -35,6 +35,7 @@
   @GTK_LIBS@ @GNUNET_LIBS@ @GLADE_LIBS@ @QR_LIBS@ \
   $(WINLIBS) \
   -lgnunetutil -lgnunetnat -lgnunetnamestore -lgnunetdnsparser \
+  -lgnunetidentity \
   $(INTLLIBS) 
 gnunet_setup_CFLAGS = \
   @GTK_CFLAGS@ \

Modified: gnunet-gtk/src/setup/gnunet-setup-gns.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-gns.c     2013-09-05 12:36:43 UTC (rev 
29025)
+++ gnunet-gtk/src/setup/gnunet-setup-gns.c     2013-09-05 12:36:49 UTC (rev 
29026)
@@ -27,6 +27,7 @@
 #include "gnunet-setup-gns.h"
 #include "gnunet-setup-gns-edit.h"
 #include <gnunet/gnunet_gns_service.h>
+#include <gnunet/gnunet_identity_service.h>
 #include <gnunet/gnunet_namestore_service.h>
 #include <gnunet/gnunet_dnsparser_lib.h>
 
@@ -358,7 +359,18 @@
  */
 static const char *current_zone_option;
 
+/**
+ * Connection to identity service.
+ */
+static struct GNUNET_IDENTITY_Handle *identity;
 
+/**
+ * Request for our ego.
+ */
+static struct GNUNET_IDENTITY_Operation *id_op;
+
+
+
 #if HAVE_QRENCODE_H
 #include <qrencode.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -1906,56 +1918,52 @@
 }
 
 
-/**
- * Load a particular zone into the main tree view.
+/** 
+ * Method called to inform about the egos of this peer.  Called
+ * when we are doing a #load_zone operation and are getting the
+ * private key of the new zone to edit.
  *
- * @param zonename name of the option in the configuration file
- *        with the name of the file with the private key of the
- *        zone to load
+ * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
+ * this function is only called ONCE, and 'NULL' being passed in
+ * @a ego does indicate an error (i.e. name is taken or no default
+ * value is known).  If @a ego is non-NULL and if '*ctx'
+ * is set in those callbacks, the value WILL be passed to a subsequent
+ * call to the identity callback of #GNUNET_IDENTITY_connect (if 
+ * that one was not NULL).
+ *
+ * @param cls closure with the 'const char *' zonename
+ * @param ego ego handle
+ * @param ctx context for application to store data for this ego
+ *                 (during the lifetime of this process, initially NULL)
+ * @param name name assigned by the user for this ego,
+ *                   NULL if the user just deleted the ego and it
+ *                   must thus no longer be used
  */
 static void
-load_zone (const char *zonename)
+identity_cb (void *cls,
+            struct GNUNET_IDENTITY_Ego *ego,
+            void **ctx,
+            const char *name)
 {
-  char *keyfile;
-  struct GNUNET_CRYPTO_EccPrivateKey *pk;
+  const char *zonename = cls;
   char *emsg;
   char *label;
   GtkTreeIter toplevel;
 
-  /* clear previous zone */
-  if (NULL != zmon)
-  {
-    GNUNET_NAMESTORE_zone_monitor_stop (zmon);
-    zmon = NULL;
-  }
-  clear_zone_view ();
-  current_zone_option = zonename;
-
   /* setup crypto keys */
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg,
-                                                            "gns",
-                                                            zonename,
-                                                            &keyfile))
+  if (NULL == ego)
   {
     GNUNET_asprintf (&emsg, 
-                    _("Option `%s' missing in section `%s'\n"), 
-                    zonename, "gns");
+                    _("Default zone for `%s' not set; did you run 
gnunet-gns-import.sh?\n"), 
+                    zonename);
     show_error_message (_("Failed to load zone"),
                        emsg);
     GNUNET_free (emsg);
     gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_zone_selection_hbuttonbox")));
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using `%s'\n", keyfile);
-  pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
-  GNUNET_free (keyfile);
-  if (NULL == pk)
-  {
-    show_error_message (_("Failed to load zone"), NULL);
-    gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_zone_selection_hbuttonbox")));
-    return;
-  }
-  pkey = pk;
+  pkey = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
+  *pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
   GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
   label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"),
                                   GNUNET_NAMESTORE_z2s (&pubkey));
@@ -1977,7 +1985,7 @@
 #if HAVE_QRENCODE_H
   setup_qrcode ();
 #endif
-  zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pk,
+  zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pkey,
                                              &zone_iteration_proc,
                                              &zone_sync_proc,
                                              NULL);
@@ -1985,6 +1993,38 @@
 
 
 /**
+ * Load a particular zone into the main tree view.
+ *
+ * @param zonename name of the option in the configuration file
+ *        with the name of the file with the private key of the
+ *        zone to load
+ */
+static void
+load_zone (const char *zonename)
+{
+  /* clear previous zone */
+  if (NULL != zmon)
+  {
+    GNUNET_NAMESTORE_zone_monitor_stop (zmon);
+    zmon = NULL;
+  }
+  if (NULL != id_op)
+  {
+    GNUNET_IDENTITY_cancel (id_op);
+    id_op = NULL;
+  }
+  clear_zone_view ();
+  current_zone_option = zonename;
+  GNUNET_free_non_null (pkey);
+  pkey = NULL;
+  id_op = GNUNET_IDENTITY_get (identity,
+                              zonename,
+                              &identity_cb,
+                              (void *) zonename);
+}
+
+
+/**
  * A different zone was selected in the zone toggle bar.  Load the
  * appropriate zone.
  *
@@ -1996,7 +2036,7 @@
                                                                gpointer 
user_data)
 {
   if (gtk_toggle_button_get_active (togglebutton))
-    load_zone ("SHORTEN_ZONEKEY");
+    load_zone ("short-zone");
 }
 
 
@@ -2012,7 +2052,7 @@
                                                                gpointer 
user_data)
 {
   if (gtk_toggle_button_get_active (togglebutton))
-    load_zone ("PRIVATE_ZONEKEY");
+    load_zone ("private-zone");
 }
 
 
@@ -2028,7 +2068,7 @@
                                                               gpointer 
user_data)
 {
   if (gtk_toggle_button_get_active (togglebutton))
-    load_zone ("ZONEKEY");
+    load_zone ("master-zone");
 }
 
 
@@ -2051,11 +2091,12 @@
     g_free (label);                      
     return;
   }
+  identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
   ts = GTK_TREE_STORE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_treestore"));
   tv = GTK_TREE_VIEW (GNUNET_SETUP_get_object 
("GNUNET_setup_gns_main_treeview"));
   tm = GTK_TREE_MODEL (ts);  
   n2r = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
-  load_zone ("ZONEKEY");
+  load_zone ("master-zone");
 }
 
 
@@ -2119,6 +2160,16 @@
     GNUNET_free (current_pseudonym);
     current_pseudonym = NULL;
   }
+  if (NULL != id_op)
+  {
+    GNUNET_IDENTITY_cancel (id_op);
+    id_op = NULL;
+  }
+  if (NULL != identity)
+  {
+    GNUNET_IDENTITY_disconnect (identity);
+    identity = NULL;
+  }
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]