gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29025 - gnunet/src/gns


From: gnunet
Subject: [GNUnet-SVN] r29025 - gnunet/src/gns
Date: Thu, 5 Sep 2013 14:36:43 +0200

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

Modified:
   gnunet/src/gns/gns.conf.in
   gnunet/src/gns/gnunet-gns.c
Log:
-use standard zones in gnunet-gns

Modified: gnunet/src/gns/gns.conf.in
===================================================================
--- gnunet/src/gns/gns.conf.in  2013-09-05 12:14:35 UTC (rev 29024)
+++ gnunet/src/gns/gns.conf.in  2013-09-05 12:36:43 UTC (rev 29025)
@@ -8,9 +8,6 @@
 
 ZONE_DIR = $SERVICEHOME/gns/
 
-# What is the name of the ego that we use for the shorten zone
-SHORTEN_ZONE = shorten
-
 # Should we hijack DNS queries using the Linux firewall? 
 # (this only works on GNU/Linux systems)
 HIJACK_DNS = NO

Modified: gnunet/src/gns/gnunet-gns.c
===================================================================
--- gnunet/src/gns/gnunet-gns.c 2013-09-05 12:14:35 UTC (rev 29024)
+++ gnunet/src/gns/gnunet-gns.c 2013-09-05 12:36:43 UTC (rev 29025)
@@ -79,8 +79,18 @@
  */
 static struct GNUNET_IDENTITY_EgoLookup *el;
 
+/**
+ * Handle for identity service.
+ */
+static struct GNUNET_IDENTITY_Handle *identity;
 
 /**
+ * Active operation on identity service.
+ */
+static struct GNUNET_IDENTITY_Operation *id_op;
+
+
+/**
  * Task run on shutdown.  Cleans up everything.
  *
  * @param cls unused
@@ -95,11 +105,21 @@
     GNUNET_IDENTITY_ego_lookup_cancel (el);
     el = NULL;
   }
+  if (NULL != id_op)
+  {
+    GNUNET_IDENTITY_cancel (id_op);
+    id_op = NULL;
+  }
   if (NULL != lookup_request)
   {
     GNUNET_GNS_lookup_cancel (lookup_request);
     lookup_request = NULL;
   }
+  if (NULL != identity)
+  {
+    GNUNET_IDENTITY_disconnect (identity);
+    identity = NULL;
+  }
   if (NULL != gns)
   {
     GNUNET_GNS_disconnect (gns);
@@ -190,31 +210,32 @@
 
 
 /** 
- * Method called to with the ego we are to use for the lookup.
+ * Method called to with the ego we are to use for shortening
+ * during the lookup.
  *
- * @param cls closure with the `struct GNUNET_CRYPTO_EccPublicKey`
+ * @param cls closure contains the public key to use
  * @param ego ego handle, NULL if not found
+ * @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 
-shorten_cb (void *cls,
-           const struct GNUNET_IDENTITY_Ego *ego)
+identity_shorten_cb (void *cls,
+                    struct GNUNET_IDENTITY_Ego *ego,
+                    void **ctx,
+                    const char *name)
 {
-  struct GNUNET_CRYPTO_EccPublicKey *pkey = cls;
-  const struct GNUNET_CRYPTO_EccPrivateKey *shorten_key;
+  struct GNUNET_CRYPTO_EccPublicKey *pkeym = cls;
 
-  el = NULL;
+  id_op = NULL;
   if (NULL == ego) 
-  {
-    fprintf (stderr,
-            _("Shorten zone not found (looking up without shortening)\n"));
-    shorten_key = NULL;
-  }
+    lookup_with_keys (pkeym, NULL);
   else
-  {
-    shorten_key = GNUNET_IDENTITY_ego_get_private_key (ego);
-  }
-  lookup_with_keys (pkey, shorten_key);
-  GNUNET_free_non_null (pkey);
+    lookup_with_keys (pkeym,
+                     GNUNET_IDENTITY_ego_get_private_key (ego));
+  GNUNET_free (pkeym);
 }
 
 
@@ -228,59 +249,83 @@
 lookup_with_public_key (const struct GNUNET_CRYPTO_EccPublicKey *pkey)
 {
   struct GNUNET_CRYPTO_EccPublicKey *pkeym;
-  char *szone;
 
-  if (GNUNET_OK != 
-      GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
-                                              "SHORTEN_ZONE", &szone))
+  GNUNET_assert (NULL != pkey);
+  pkeym = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey);
+  *pkeym = *pkey;
+  id_op = GNUNET_IDENTITY_get (identity,
+                              "shorten-zone",
+                              &identity_shorten_cb,
+                              pkeym);
+  if (NULL == id_op)
   {
+    GNUNET_break (0);
     lookup_with_keys (pkey, NULL);
-    return;
   }
-  if (NULL == pkey)
+}
+
+
+/** 
+ * Method called to with the ego we are to use for the lookup,
+ * when the ego is determined by a name.
+ *
+ * @param cls closure (NULL, unused)
+ * @param ego ego handle, NULL if not found
+ */
+static void 
+identity_zone_cb (void *cls,
+                 const struct GNUNET_IDENTITY_Ego *ego)
+{
+  struct GNUNET_CRYPTO_EccPublicKey pkey;
+
+  el = NULL;
+  if (NULL == ego) 
   {
-    pkeym = NULL;
+    fprintf (stderr,
+            _("Ego for `%s' not found, cannot perform lookup.\n"),
+            zone_ego_name);
+    GNUNET_SCHEDULER_shutdown ();
   }
   else
   {
-    pkeym = GNUNET_new (struct GNUNET_CRYPTO_EccPublicKey);
-    *pkeym = *pkey;
+    GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
+    lookup_with_public_key (&pkey);
   }
-  el = GNUNET_IDENTITY_ego_lookup (cfg, 
-                                  szone,
-                                  &shorten_cb,
-                                  pkeym);
-  GNUNET_free (szone);
+  GNUNET_free_non_null (zone_ego_name);
+  zone_ego_name = NULL;
 }
 
 
 /** 
- * Method called to with the ego we are to use for the lookup.
+ * Method called to with the ego we are to use for the lookup,
+ * when the ego is the one for the default master zone.
  *
  * @param cls closure (NULL, unused)
  * @param ego ego handle, NULL if not found
+ * @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 
-identity_cb (void *cls,
-            const struct GNUNET_IDENTITY_Ego *ego)
+identity_master_cb (void *cls,
+                   struct GNUNET_IDENTITY_Ego *ego,
+                   void **ctx,
+                   const char *name)
 {
   struct GNUNET_CRYPTO_EccPublicKey pkey;
 
-  el = NULL;
+  id_op = NULL;
   if (NULL == ego) 
   {
     fprintf (stderr,
-            _("Ego `%s' not found\n"),
-            zone_ego_name);
-    GNUNET_free (zone_ego_name);
-    zone_ego_name = NULL;
+            _("Ego for `master-zone' not found, cannot perform lookup.  Did 
you run gnunet-gns-import.sh?\n"));
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
   GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
   lookup_with_public_key (&pkey);
-  GNUNET_free (zone_ego_name);
-  zone_ego_name = NULL;
 }
 
 
@@ -300,6 +345,7 @@
 
   cfg = c;
   gns = GNUNET_GNS_connect (cfg);
+  identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
   if (NULL == gns)
   {
     fprintf (stderr,
@@ -328,7 +374,7 @@
   {
     el = GNUNET_IDENTITY_ego_lookup (cfg, 
                                     zone_ego_name,
-                                    &identity_cb,
+                                    &identity_zone_cb,
                                     NULL);
     return;
   }
@@ -344,10 +390,11 @@
   }
   else
   {
-    fprintf (stderr,
-            _("I need a zone (`-p' or `-z' option) to resolve this name\n"));
-    GNUNET_SCHEDULER_shutdown ();
-    return;
+    id_op = GNUNET_IDENTITY_get (identity,
+                                "master-zone",
+                                &identity_master_cb,
+                                NULL);
+    GNUNET_assert (NULL != id_op);
   }
 }
 




reply via email to

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