aboutsummaryrefslogtreecommitdiff
path: root/src/setup/gnunet-setup-gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/setup/gnunet-setup-gns.c')
-rw-r--r--src/setup/gnunet-setup-gns.c127
1 files changed, 89 insertions, 38 deletions
diff --git a/src/setup/gnunet-setup-gns.c b/src/setup/gnunet-setup-gns.c
index eb7aa67e..7e15c69f 100644
--- a/src/setup/gnunet-setup-gns.c
+++ b/src/setup/gnunet-setup-gns.c
@@ -27,6 +27,7 @@
27#include "gnunet-setup-gns.h" 27#include "gnunet-setup-gns.h"
28#include "gnunet-setup-gns-edit.h" 28#include "gnunet-setup-gns-edit.h"
29#include <gnunet/gnunet_gns_service.h> 29#include <gnunet/gnunet_gns_service.h>
30#include <gnunet/gnunet_identity_service.h>
30#include <gnunet/gnunet_namestore_service.h> 31#include <gnunet/gnunet_namestore_service.h>
31#include <gnunet/gnunet_dnsparser_lib.h> 32#include <gnunet/gnunet_dnsparser_lib.h>
32 33
@@ -358,6 +359,17 @@ static char *current_pseudonym;
358 */ 359 */
359static const char *current_zone_option; 360static const char *current_zone_option;
360 361
362/**
363 * Connection to identity service.
364 */
365static struct GNUNET_IDENTITY_Handle *identity;
366
367/**
368 * Request for our ego.
369 */
370static struct GNUNET_IDENTITY_Operation *id_op;
371
372
361 373
362#if HAVE_QRENCODE_H 374#if HAVE_QRENCODE_H
363#include <qrencode.h> 375#include <qrencode.h>
@@ -1906,56 +1918,52 @@ zone_iteration_proc (void *cls,
1906} 1918}
1907 1919
1908 1920
1909/** 1921/**
1910 * Load a particular zone into the main tree view. 1922 * Method called to inform about the egos of this peer. Called
1923 * when we are doing a #load_zone operation and are getting the
1924 * private key of the new zone to edit.
1911 * 1925 *
1912 * @param zonename name of the option in the configuration file 1926 * When used with #GNUNET_IDENTITY_create or #GNUNET_IDENTITY_get,
1913 * with the name of the file with the private key of the 1927 * this function is only called ONCE, and 'NULL' being passed in
1914 * zone to load 1928 * @a ego does indicate an error (i.e. name is taken or no default
1929 * value is known). If @a ego is non-NULL and if '*ctx'
1930 * is set in those callbacks, the value WILL be passed to a subsequent
1931 * call to the identity callback of #GNUNET_IDENTITY_connect (if
1932 * that one was not NULL).
1933 *
1934 * @param cls closure with the 'const char *' zonename
1935 * @param ego ego handle
1936 * @param ctx context for application to store data for this ego
1937 * (during the lifetime of this process, initially NULL)
1938 * @param name name assigned by the user for this ego,
1939 * NULL if the user just deleted the ego and it
1940 * must thus no longer be used
1915 */ 1941 */
1916static void 1942static void
1917load_zone (const char *zonename) 1943identity_cb (void *cls,
1944 struct GNUNET_IDENTITY_Ego *ego,
1945 void **ctx,
1946 const char *name)
1918{ 1947{
1919 char *keyfile; 1948 const char *zonename = cls;
1920 struct GNUNET_CRYPTO_EccPrivateKey *pk;
1921 char *emsg; 1949 char *emsg;
1922 char *label; 1950 char *label;
1923 GtkTreeIter toplevel; 1951 GtkTreeIter toplevel;
1924 1952
1925 /* clear previous zone */
1926 if (NULL != zmon)
1927 {
1928 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
1929 zmon = NULL;
1930 }
1931 clear_zone_view ();
1932 current_zone_option = zonename;
1933
1934 /* setup crypto keys */ 1953 /* setup crypto keys */
1935 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 1954 if (NULL == ego)
1936 "gns",
1937 zonename,
1938 &keyfile))
1939 { 1955 {
1940 GNUNET_asprintf (&emsg, 1956 GNUNET_asprintf (&emsg,
1941 _("Option `%s' missing in section `%s'\n"), 1957 _("Default zone for `%s' not set; did you run gnunet-gns-import.sh?\n"),
1942 zonename, "gns"); 1958 zonename);
1943 show_error_message (_("Failed to load zone"), 1959 show_error_message (_("Failed to load zone"),
1944 emsg); 1960 emsg);
1945 GNUNET_free (emsg); 1961 GNUNET_free (emsg);
1946 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox"))); 1962 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox")));
1947 return; 1963 return;
1948 } 1964 }
1949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Using `%s'\n", keyfile); 1965 pkey = GNUNET_new (struct GNUNET_CRYPTO_EccPrivateKey);
1950 pk = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile); 1966 *pkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
1951 GNUNET_free (keyfile);
1952 if (NULL == pk)
1953 {
1954 show_error_message (_("Failed to load zone"), NULL);
1955 gtk_widget_show (GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_gns_zone_selection_hbuttonbox")));
1956 return;
1957 }
1958 pkey = pk;
1959 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey); 1967 GNUNET_CRYPTO_ecc_key_get_public (pkey, &pubkey);
1960 label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"), 1968 label = g_markup_printf_escaped (_("<b>Editing zone %s</b>"),
1961 GNUNET_NAMESTORE_z2s (&pubkey)); 1969 GNUNET_NAMESTORE_z2s (&pubkey));
@@ -1977,7 +1985,7 @@ load_zone (const char *zonename)
1977#if HAVE_QRENCODE_H 1985#if HAVE_QRENCODE_H
1978 setup_qrcode (); 1986 setup_qrcode ();
1979#endif 1987#endif
1980 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pk, 1988 zmon = GNUNET_NAMESTORE_zone_monitor_start (cfg, pkey,
1981 &zone_iteration_proc, 1989 &zone_iteration_proc,
1982 &zone_sync_proc, 1990 &zone_sync_proc,
1983 NULL); 1991 NULL);
@@ -1985,6 +1993,38 @@ load_zone (const char *zonename)
1985 1993
1986 1994
1987/** 1995/**
1996 * Load a particular zone into the main tree view.
1997 *
1998 * @param zonename name of the option in the configuration file
1999 * with the name of the file with the private key of the
2000 * zone to load
2001 */
2002static void
2003load_zone (const char *zonename)
2004{
2005 /* clear previous zone */
2006 if (NULL != zmon)
2007 {
2008 GNUNET_NAMESTORE_zone_monitor_stop (zmon);
2009 zmon = NULL;
2010 }
2011 if (NULL != id_op)
2012 {
2013 GNUNET_IDENTITY_cancel (id_op);
2014 id_op = NULL;
2015 }
2016 clear_zone_view ();
2017 current_zone_option = zonename;
2018 GNUNET_free_non_null (pkey);
2019 pkey = NULL;
2020 id_op = GNUNET_IDENTITY_get (identity,
2021 zonename,
2022 &identity_cb,
2023 (void *) zonename);
2024}
2025
2026
2027/**
1988 * A different zone was selected in the zone toggle bar. Load the 2028 * A different zone was selected in the zone toggle bar. Load the
1989 * appropriate zone. 2029 * appropriate zone.
1990 * 2030 *
@@ -1996,7 +2036,7 @@ GNUNET_setup_gns_shorten_zone_selection_radiobutton_toggled_cb (GtkToggleButton
1996 gpointer user_data) 2036 gpointer user_data)
1997{ 2037{
1998 if (gtk_toggle_button_get_active (togglebutton)) 2038 if (gtk_toggle_button_get_active (togglebutton))
1999 load_zone ("SHORTEN_ZONEKEY"); 2039 load_zone ("short-zone");
2000} 2040}
2001 2041
2002 2042
@@ -2012,7 +2052,7 @@ GNUNET_setup_gns_private_zone_selection_radiobutton_toggled_cb (GtkToggleButton
2012 gpointer user_data) 2052 gpointer user_data)
2013{ 2053{
2014 if (gtk_toggle_button_get_active (togglebutton)) 2054 if (gtk_toggle_button_get_active (togglebutton))
2015 load_zone ("PRIVATE_ZONEKEY"); 2055 load_zone ("private-zone");
2016} 2056}
2017 2057
2018 2058
@@ -2028,7 +2068,7 @@ GNUNET_setup_gns_master_zone_selection_radiobutton_toggled_cb (GtkToggleButton *
2028 gpointer user_data) 2068 gpointer user_data)
2029{ 2069{
2030 if (gtk_toggle_button_get_active (togglebutton)) 2070 if (gtk_toggle_button_get_active (togglebutton))
2031 load_zone ("ZONEKEY"); 2071 load_zone ("master-zone");
2032} 2072}
2033 2073
2034 2074
@@ -2051,11 +2091,12 @@ GNUNET_SETUP_gns_init ()
2051 g_free (label); 2091 g_free (label);
2052 return; 2092 return;
2053 } 2093 }
2094 identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
2054 ts = GTK_TREE_STORE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_treestore")); 2095 ts = GTK_TREE_STORE (GNUNET_SETUP_get_object ("GNUNET_setup_gns_treestore"));
2055 tv = GTK_TREE_VIEW (GNUNET_SETUP_get_object ("GNUNET_setup_gns_main_treeview")); 2096 tv = GTK_TREE_VIEW (GNUNET_SETUP_get_object ("GNUNET_setup_gns_main_treeview"));
2056 tm = GTK_TREE_MODEL (ts); 2097 tm = GTK_TREE_MODEL (ts);
2057 n2r = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO); 2098 n2r = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
2058 load_zone ("ZONEKEY"); 2099 load_zone ("master-zone");
2059} 2100}
2060 2101
2061 2102
@@ -2119,6 +2160,16 @@ GNUNET_SETUP_gns_done ()
2119 GNUNET_free (current_pseudonym); 2160 GNUNET_free (current_pseudonym);
2120 current_pseudonym = NULL; 2161 current_pseudonym = NULL;
2121 } 2162 }
2163 if (NULL != id_op)
2164 {
2165 GNUNET_IDENTITY_cancel (id_op);
2166 id_op = NULL;
2167 }
2168 if (NULL != identity)
2169 {
2170 GNUNET_IDENTITY_disconnect (identity);
2171 identity = NULL;
2172 }
2122} 2173}
2123 2174
2124 2175