-use valid ECC keys for testing
[oweals/gnunet.git] / src / gns / gnunet-gns-helper-service-w32.c
index 198dfb851a2fbfda5d9842484b6e800fa438fbfb..a15b3547c170923536b7a6adb0aaca924eafd27e 100644 (file)
@@ -29,7 +29,7 @@
 #include <gnunet_dnsparser_lib.h>
 #include <gnunet_namestore_service.h>
 #include <gnunet_gns_service.h>
-#include <gnunet_w32nsp_lib.h>
+#include "gnunet_w32nsp_lib.h"
 #include "w32resolver.h"
 #include <nspapi.h>
 #include <unistr.h>
@@ -63,7 +63,7 @@ static struct GNUNET_GNS_Handle *gns;
 
 static struct GNUNET_CRYPTO_ShortHashCode *zone = NULL;
 static struct GNUNET_CRYPTO_ShortHashCode user_zone;
-struct GNUNET_CRYPTO_RsaPrivateKey *shorten_key = NULL;
+struct GNUNET_CRYPTO_EccPrivateKey *shorten_key = NULL;
 
 
 /**
@@ -104,18 +104,11 @@ struct TransmitCallbackContext
    */
   struct GNUNET_MessageHeader *msg;
 
-  size_t msgsize;
-
   /**
    * Handle for the transmission request.
    */
   struct GNUNET_SERVER_TransmitHandle *th;
 
-  /**
-   * Client that we are transmitting to.
-   */
-  struct GNUNET_SERVER_Client *client;
-
 };
 
 
@@ -135,6 +128,7 @@ static struct TransmitCallbackContext *tcc_tail;
  */
 static int cleaning_done;
 
+
 /**
  * Function called to notify a client about the socket
  * begin ready to queue more data.  "buf" will be
@@ -154,19 +148,17 @@ transmit_callback (void *cls, size_t size, void *buf)
 
   tcc->th = NULL;
   GNUNET_CONTAINER_DLL_remove (tcc_head, tcc_tail, tcc);
-  msize = tcc->msgsize;
+  msize = ntohs (tcc->msg->size);
   if (size == 0)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 _("Transmission to client failed!\n"));
-    GNUNET_SERVER_client_drop (tcc->client);
     GNUNET_free (tcc->msg);
     GNUNET_free (tcc);
     return 0;
   }
   GNUNET_assert (size >= msize);
   memcpy (buf, tcc->msg, msize);
-  GNUNET_SERVER_client_drop (tcc->client);
   GNUNET_free (tcc->msg);
   GNUNET_free (tcc);
   return msize;
@@ -180,7 +172,8 @@ transmit_callback (void *cls, size_t size, void *buf)
  * @param msg message to transmit, will be freed!
  */
 static void
-transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg, size_t msgsize)
+transmit (struct GNUNET_SERVER_Client *client, 
+         struct GNUNET_MessageHeader *msg)
 {
   struct TransmitCallbackContext *tcc;
 
@@ -188,34 +181,32 @@ transmit (struct GNUNET_SERVER_Client *client, struct GNUNET_MessageHeader *msg,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                 _("Shutdown in progress, aborting transmission.\n"));
-    GNUNET_SERVER_client_drop (client);
     GNUNET_free (msg);
     return;
   }
   tcc = GNUNET_malloc (sizeof (struct TransmitCallbackContext));
   tcc->msg = msg;
-  tcc->msgsize = msgsize;
-  tcc->client = client;
   if (NULL ==
       (tcc->th =
-       GNUNET_SERVER_notify_transmit_ready (client, msgsize,
+       GNUNET_SERVER_notify_transmit_ready (client, 
+                                           ntohs (msg->size),
                                             GNUNET_TIME_UNIT_FOREVER_REL,
                                             &transmit_callback, tcc)))
   {
     GNUNET_break (0);
-    GNUNET_SERVER_client_drop (client);
     GNUNET_free (msg);
     GNUNET_free (tcc);
     return;
   }
-  GNUNET_SERVER_client_keep (client);
   GNUNET_CONTAINER_DLL_insert (tcc_head, tcc_tail, tcc);
 }
 
+
 #define MarshallPtr(ptr, base, type) \
   if (ptr) \
     ptr = (type *) ((char *) ptr - (char *) base)
 
+
 void
 MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
 {
@@ -249,9 +240,11 @@ MarshallWSAQUERYSETW (WSAQUERYSETW *qs, GUID *sc)
   MarshallPtr (qs->lpBlob, qs, BLOB);
 }
 
+
 static void
-process_ip_lookup_result (void* cls, uint32_t rd_count,
-    const struct GNUNET_NAMESTORE_RecordData *rd)
+process_ip_lookup_result (void* cls, 
+                         uint32_t rd_count,
+                         const struct GNUNET_NAMESTORE_RecordData *rd)
 {
   int i, j, csanum;
   struct request *rq = (struct request *) cls;
@@ -274,7 +267,7 @@ process_ip_lookup_result (void* cls, uint32_t rd_count,
     msg = GNUNET_malloc (size);
     msg->header.size = htons (size);
     msg->header.type = htons (GNUNET_MESSAGE_TYPE_W32RESOLVER_RESPONSE);
-    transmit (rq->client, &msg->header, msg->header.size);
+    transmit (rq->client, &msg->header);
     return;
   }
 
@@ -504,9 +497,10 @@ process_ip_lookup_result (void* cls, uint32_t rd_count,
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error in WSAQUERYSETW size calc: expected %lu, got %lu (recalc %lu)\n", size, (unsigned long) ((char *) ptr - (char *) msg), size_recalc);
   }
   MarshallWSAQUERYSETW (qs, &rq->sc);
-  transmit (rq->client, &msg->header, size);
+  transmit (rq->client, &msg->header);
 }
 
+
 static void
 get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
     const wchar_t *name, int af, GUID sc)
@@ -580,7 +574,6 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Lookup launched, waiting for a reply\n");
-    GNUNET_SERVER_client_keep (client);
     GNUNET_SERVER_receive_done (client, GNUNET_OK);
   }
   else
@@ -597,6 +590,7 @@ get_ip_from_hostname (struct GNUNET_SERVER_Client *client,
   }
 }
 
+
 /**
  * Handle GET-message.
  *
@@ -648,7 +642,6 @@ handle_get (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   get_ip_from_hostname (client, hostname, af, sc);
-  return;
 }
 
 
@@ -669,8 +662,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   };
 
   char* keyfile;
-  struct GNUNET_CRYPTO_RsaPrivateKey *key = NULL;
-  struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
+  struct GNUNET_CRYPTO_EccPrivateKey *key = NULL;
+  struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded pkey;
   struct GNUNET_CRYPTO_ShortHashAsciiEncoded zonename;
 
   if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
@@ -684,16 +677,16 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   {
     if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
     {
-      key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
-      GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
+      key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
+      GNUNET_CRYPTO_ecc_key_get_public (key, &pkey);
       GNUNET_CRYPTO_short_hash(&pkey,
-                         sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
+                         sizeof(struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
                          &user_zone);
       zone = &user_zone;
       GNUNET_CRYPTO_short_hash_to_enc (zone, &zonename);
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "Using zone: %s!\n", &zonename);
-      GNUNET_CRYPTO_rsa_key_free(key);
+      GNUNET_CRYPTO_ecc_key_free(key);
     }
     GNUNET_free(keyfile);
   }
@@ -709,7 +702,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   {
     if (GNUNET_YES == GNUNET_DISK_file_test (keyfile))
     {
-      shorten_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
+      shorten_key = GNUNET_CRYPTO_ecc_key_create_from_file (keyfile);
     }
     GNUNET_free(keyfile);
   }
@@ -745,4 +738,4 @@ main (int argc, char *const *argv)
   return ret;
 }
 
-/* end of gnunet-gns.c */
+/* end of gnunet-gns-helper-service-w32.c */