gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r31230 - gnunet/src/gns
Date: Mon, 9 Dec 2013 18:53:21 +0100

Author: LRN
Date: 2013-12-09 18:53:20 +0100 (Mon, 09 Dec 2013)
New Revision: 31230

Modified:
   gnunet/src/gns/Makefile.am
   gnunet/src/gns/gnunet-gns-helper-service-w32.c
   gnunet/src/gns/w32nsp.c
Log:
Update W32 GNS helper and NSP

Modified: gnunet/src/gns/Makefile.am
===================================================================
--- gnunet/src/gns/Makefile.am  2013-12-09 17:47:29 UTC (rev 31229)
+++ gnunet/src/gns/Makefile.am  2013-12-09 17:53:20 UTC (rev 31230)
@@ -153,10 +153,12 @@
   gnunet-gns-helper-service-w32.c
 gnunet_gns_helper_service_w32_LDADD = \
   $(top_builddir)/src/gns/libgnunetgns.la \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
   $(top_builddir)/src/util/libgnunetutil.la \
   $(GN_LIBINTL)
 gnunet_gns_helper_service_w32_DEPENDENCIES = \
   $(top_builddir)/src/util/libgnunetutil.la \
+  $(top_builddir)/src/identity/libgnunetidentity.la \
   libgnunetgns.la
 
 w32nsp_install_SOURCES = \

Modified: gnunet/src/gns/gnunet-gns-helper-service-w32.c
===================================================================
--- gnunet/src/gns/gnunet-gns-helper-service-w32.c      2013-12-09 17:47:29 UTC 
(rev 31229)
+++ gnunet/src/gns/gnunet-gns-helper-service-w32.c      2013-12-09 17:53:20 UTC 
(rev 31230)
@@ -26,6 +26,7 @@
 #define INITGUID
 #include "platform.h"
 #include <gnunet_util_lib.h>
+#include <gnunet_identity_service.h>
 #include <gnunet_dnsparser_lib.h>
 #include <gnunet_namestore_service.h>
 #include <gnunet_gns_service.h>
@@ -54,6 +55,7 @@
   int af;
   wchar_t *name;
   char *u8name;
+  struct GNUNET_GNS_LookupRequest *lookup_request;
 };
 
 /**
@@ -61,12 +63,32 @@
  */
 static struct GNUNET_GNS_Handle *gns;
 
-static struct GNUNET_CRYPTO_EcdsaPublicKey *zone = NULL;
-static struct GNUNET_HashCode user_zone;
-struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_key = NULL;
+/**
+ * Active operation on identity service.
+ */
+static struct GNUNET_IDENTITY_Operation *id_op;
 
+/**
+ * Handle for identity service.
+ */
+static struct GNUNET_IDENTITY_Handle *identity;
 
 /**
+ * Public key of the gns-master ego
+ */
+static struct GNUNET_CRYPTO_EcdsaPublicKey gns_master_pubkey;
+
+/**
+ * Private key of the gns-short ego
+ */
+static struct GNUNET_CRYPTO_EcdsaPrivateKey gns_short_privkey;
+
+/**
+ * Set to 1 once egos are obtained.
+ */
+static int got_egos = 0;
+
+/**
  * Task run on shutdown.  Cleans up everything.
  *
  * @param cls unused
@@ -76,6 +98,16 @@
 do_shutdown (void *cls,
             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (NULL != id_op)
+  {
+    GNUNET_IDENTITY_cancel (id_op);
+    id_op = NULL;
+  }
+  if (NULL != identity)
+  {
+    GNUNET_IDENTITY_disconnect (identity);
+    identity = NULL;
+  }
   if (NULL != gns)
   {
     GNUNET_GNS_disconnect (gns);
@@ -131,7 +163,7 @@
 
 /**
  * Function called to notify a client about the socket
- * begin ready to queue more data.  "buf" will be
+ * being ready to queue more data.  "buf" will be
  * NULL and "size" zero if the socket was closed for
  * writing in the meantime.
  *
@@ -242,9 +274,8 @@
 
 
 static void
-process_ip_lookup_result (void* cls,
-                         uint32_t rd_count,
-                         const struct GNUNET_GNSRECORD_Data *rd)
+process_lookup_result (void* cls, uint32_t rd_count,
+    const struct GNUNET_GNSRECORD_Data *rd)
 {
   int i, j, csanum;
   struct request *rq = (struct request *) cls;
@@ -258,8 +289,8 @@
   size_t blobaddrcount = 0;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got lookup result with count %u for rq %p with client %p\n",
-              rd_count, rq, rq->client);
+      "Got lookup result with count %u for rq %p with client %p\n",
+      rd_count, rq, rq->client);
 
   if (rd_count == 0)
   {
@@ -268,6 +299,10 @@
     msg->header.size = htons (size);
     msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
     transmit (rq->client, &msg->header);
+    GNUNET_free_non_null (rq->name);
+    if (rq->u8name)
+      free (rq->u8name);
+    GNUNET_free (rq);
     return;
   }
 
@@ -498,6 +533,10 @@
   }
   MarshallWSAQUERYSETW (qs, &rq->sc);
   transmit (rq->client, &msg->header);
+  GNUNET_free_non_null (rq->name);
+  if (rq->u8name)
+    free (rq->u8name);
+  GNUNET_free (rq);
 }
 
 
@@ -547,11 +586,14 @@
     namelen = 0;
   if (namelen > 0)
     hostname = (char *) u16_to_u8 (name, namelen + 1, NULL, &strl);
+  else
+    hostname = NULL;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "W32 DNS resolver asked to look up %s for `%s'.\n",
               af == AF_INET ? "IPv4" : af == AF_INET6 ? "IPv6" : "anything",
               hostname);
+
   rq = GNUNET_malloc (sizeof (struct request));
   rq->sc = sc;
   rq->client = client;
@@ -569,8 +611,11 @@
               "Launching a lookup for client %p with rq %p\n",
               client, rq);
 
-  if (NULL != GNUNET_GNS_lookup (gns, hostname, zone, rtype,
-      GNUNET_YES, shorten_key, &process_ip_lookup_result, rq))
+  rq->lookup_request = GNUNET_GNS_lookup (gns, hostname, &gns_master_pubkey,
+      rtype, GNUNET_NO /* Use DHT */, &gns_short_privkey, 
&process_lookup_result,
+      rq);
+
+  if (NULL != rq->lookup_request)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Lookup launched, waiting for a reply\n");
@@ -579,12 +624,10 @@
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Lookup was not, disconnecting the client\n");
-    if (namelen)
-    {
-      GNUNET_free (rq->name);
+                "Lookup was not launched, disconnecting the client\n");
+    GNUNET_free_non_null (rq->name);
+    if (rq->u8name)
       free (rq->u8name);
-    }
     GNUNET_free (rq);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
   }
@@ -611,6 +654,16 @@
   const wchar_t *hostname;
   int af;
 
+  if (!got_egos)
+  {
+    /*
+     * FIXME: be done with GNUNET_OK, put the get request into a queue?
+     * or postpone GNUNET_SERVER_add_handlers() until egos are obtained?
+     */
+    GNUNET_SERVER_receive_done (client, GNUNET_NO);
+    return;
+  }
+
   msize = ntohs (message->size);
   if (msize < sizeof (struct GNUNET_W32RESOLVER_GetMessage))
   {
@@ -646,6 +699,69 @@
 
 
 /**
+ * Method called to with the ego we are to use for shortening
+ * during the lookup.
+ *
+ * @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_shorten_cb (void *cls,
+         struct GNUNET_IDENTITY_Ego *ego,
+         void **ctx,
+         const char *name)
+{
+  id_op = NULL;
+  if (NULL == ego)
+  {
+    fprintf (stderr,
+       _("Ego for `gns-short' not found. This is not really fatal, but i'll 
pretend that it is and refuse to perform a lookup.  Did you run 
gnunet-gns-import.sh?\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  gns_short_privkey = *GNUNET_IDENTITY_ego_get_private_key (ego);
+  got_egos = 1;
+}
+
+/**
+ * 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_master_cb (void *cls,
+        struct GNUNET_IDENTITY_Ego *ego,
+        void **ctx,
+        const char *name)
+{
+  id_op = NULL;
+  if (NULL == ego)
+  {
+    fprintf (stderr,
+       _("Ego for `gns-master' not found, cannot perform lookup.  Did you run 
gnunet-gns-import.sh?\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
+  GNUNET_IDENTITY_ego_get_public_key (ego, &gns_master_pubkey);
+  id_op = GNUNET_IDENTITY_get (identity, "gns-short", &identity_shorten_cb,
+      NULL);
+  GNUNET_assert (NULL != id_op);
+}
+
+
+/**
  * Start up gns-helper-w32 service.
  *
  * @param cls closure
@@ -654,65 +770,36 @@
  */
 static void
 run (void *cls, struct GNUNET_SERVER_Handle *server,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+    const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_get, NULL, GNUNET_MESSAGE_TYPE_W32RESOLVER_REQUEST, 0},
     {NULL, NULL, 0, 0}
   };
 
-  char* keyfile;
-  struct GNUNET_CRYPTO_EcdsaPrivateKey *key = NULL;
-  struct GNUNET_CRYPTO_EcdsaPublicKey pkey;
-  struct GNUNET_CRYPTO_HashAsciiEncoded zonename;
-
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
-                                                           "ZONEKEY", 
&keyfile))
+  gns = GNUNET_GNS_connect (cfg);
+  if (NULL == gns)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "No private key for root zone found, using default!\n");
-    zone = NULL;
+    fprintf (stderr, _("Failed to connect to GNS\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
-  else
-  {
-    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
-    {
-      key = GNUNET_CRYPTO_ecdsa_key_create_from_file (keyfile);
-      GNUNET_CRYPTO_ecdsa_key_get_public (key, &pkey);
-      GNUNET_CRYPTO_hash (&pkey, sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey),
-                          &user_zone);
-      GNUNET_CRYPTO_hash_to_enc (&user_zone, &zonename);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                  "Using zone: %s!\n", &zonename);
-      GNUNET_free(key);
-    }
-    GNUNET_free(keyfile);
-  }
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
+      NULL);
 
-  if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
-                                                   "SHORTEN_ZONEKEY", 
&keyfile))
+  identity = GNUNET_IDENTITY_connect (cfg, NULL, NULL);
+  if (NULL == identity)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "No shorten key found!\n");
-    shorten_key = NULL;
+    fprintf (stderr, _("Failed to connect to identity service\n"));
+    GNUNET_SCHEDULER_shutdown ();
+    return;
   }
-  else
-  {
-    if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
-    {
-      shorten_key = GNUNET_CRYPTO_ecdsa_key_create_from_file (keyfile);
-    }
-    GNUNET_free(keyfile);
-  }
 
-  gns = GNUNET_GNS_connect (cfg);
-  if (gns == NULL)
-    return;
+  id_op = GNUNET_IDENTITY_get (identity, "gns-master", &identity_master_cb,
+      NULL);
+  GNUNET_assert (NULL != id_op);
 
   GNUNET_SERVER_add_handlers (server, handlers);
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown,
-                                NULL);
-
 }
 
 
@@ -728,12 +815,9 @@
 {
   int ret;
 
-  ret =
-      (GNUNET_OK ==
-       GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32", 
GNUNET_SERVICE_OPTION_NONE,
-                           &run, NULL)) ? 0 : 1;
-
-  return ret;
+  ret = GNUNET_SERVICE_run (argc, argv, "gns-helper-service-w32",
+      GNUNET_SERVICE_OPTION_NONE, &run, NULL);
+  return (GNUNET_OK == ret) ? 0 : 1;
 }
 
 /* end of gnunet-gns-helper-service-w32.c */

Modified: gnunet/src/gns/w32nsp.c
===================================================================
--- gnunet/src/gns/w32nsp.c     2013-12-09 17:47:29 UTC (rev 31229)
+++ gnunet/src/gns/w32nsp.c     2013-12-09 17:53:20 UTC (rev 31230)
@@ -337,10 +337,10 @@
     {
       wchar_t *s = lpqsRestrictions->lpszServiceInstanceName;
       size_t len = wcslen (s);
-      if (len >= 4 && wcscmp (&s[len - 4], L"zkey") == 0)
+      if (len >= 5 && wcscmp (&s[len - 5], L".zkey") == 0)
       {
       }
-      else if (len >= 4 && wcscmp (&s[len - 4], L"gnu") == 0)
+      else if (len >= 4 && wcscmp (&s[len - 4], L".gnu") == 0)
       {
       }
       else




reply via email to

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