- merge with master
[oweals/gnunet.git] / src / gns / gns_api.c
index 8f821f7154e44099b61bd5a00a73982e43e849f7..84c4ae189f3ee760450062b39309285fbfc67be4 100644 (file)
@@ -181,6 +181,9 @@ mq_error_handler (void *cls,
 {
   struct GNUNET_GNS_Handle *handle = cls;
 
+  LOG (GNUNET_ERROR_TYPE_WARNING,
+       "Problem with message queue. error: %i\n",
+       error);
   force_reconnect (handle);
 }
 
@@ -193,7 +196,7 @@ mq_error_handler (void *cls,
  */
 static int
 check_result (void *cls,
-              const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg)
+              const struct LookupResultMessage *lookup_msg)
 {
   size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
   uint32_t rd_count = ntohl (lookup_msg->rd_count);
@@ -220,7 +223,7 @@ check_result (void *cls,
  */
 static void
 handle_result (void *cls,
-               const struct GNUNET_GNS_ClientLookupResultMessage *lookup_msg)
+               const struct LookupResultMessage *lookup_msg)
 {
   struct GNUNET_GNS_Handle *handle = cls;
   size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
@@ -241,10 +244,7 @@ handle_result (void *cls,
     return;
   proc = lr->lookup_proc;
   proc_cls = lr->proc_cls;
-  GNUNET_CONTAINER_DLL_remove (handle->lookup_head,
-                               handle->lookup_tail,
-                               lr);
-  GNUNET_free (lr);
+  
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_GNSRECORD_records_deserialize (mlen,
                                                        (const char*) &lookup_msg[1],
@@ -253,6 +253,12 @@ handle_result (void *cls,
   proc (proc_cls,
         rd_count,
         rd);
+  GNUNET_CONTAINER_DLL_remove (handle->lookup_head,
+                               handle->lookup_tail,
+                               lr);
+  if (NULL != lr->env)
+    GNUNET_MQ_discard (lr->env);
+  GNUNET_free (lr);
 }
 
 
@@ -264,11 +270,11 @@ handle_result (void *cls,
 static void
 reconnect (struct GNUNET_GNS_Handle *handle)
 {
-  GNUNET_MQ_hd_var_size (result,
-                         GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT,
-                         struct GNUNET_GNS_ClientLookupResultMessage);
   struct GNUNET_MQ_MessageHandler handlers[] = {
-    make_result_handler (handle),
+    GNUNET_MQ_hd_var_size (result,
+                           GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT,
+                           struct LookupResultMessage,
+                           handle),
     GNUNET_MQ_handler_end ()
   };
   struct GNUNET_GNS_LookupRequest *lh;
@@ -276,7 +282,7 @@ reconnect (struct GNUNET_GNS_Handle *handle)
   GNUNET_assert (NULL == handle->mq);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Trying to connect to GNS\n");
-  handle->mq = GNUNET_CLIENT_connecT (handle->cfg,
+  handle->mq = GNUNET_CLIENT_connect (handle->cfg,
                                       "gns",
                                       handlers,
                                       &mq_error_handler,
@@ -361,23 +367,21 @@ GNUNET_GNS_lookup_cancel (struct GNUNET_GNS_LookupRequest *lr)
  * @param zone the zone to start the resolution in
  * @param type the record type to look up
  * @param options local options for the lookup
- * @param shorten_zone_key the private key of the shorten zone (can be NULL)
  * @param proc processor to call on result
  * @param proc_cls closure for @a proc
  * @return handle to the get request
  */
 struct GNUNET_GNS_LookupRequest*
 GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
-                  const char *name,
-                  const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
-                  uint32_t type,
-                  enum GNUNET_GNS_LocalOptions options,
-                  const struct GNUNET_CRYPTO_EcdsaPrivateKey *shorten_zone_key,
-                  GNUNET_GNS_LookupResultProcessor proc,
-                  void *proc_cls)
+                   const char *name,
+                   const struct GNUNET_CRYPTO_EcdsaPublicKey *zone,
+                   uint32_t type,
+                   enum GNUNET_GNS_LocalOptions options,
+                   GNUNET_GNS_LookupResultProcessor proc,
+                   void *proc_cls)
 {
   /* IPC to shorten gns names, return shorten_handle */
-  struct GNUNET_GNS_ClientLookupMessage *lookup_msg;
+  struct LookupMessage *lookup_msg;
   struct GNUNET_GNS_LookupRequest *lr;
   size_t nlen;
 
@@ -390,7 +394,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
        "Trying to lookup `%s' in GNS\n",
        name);
   nlen = strlen (name) + 1;
-  if (nlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*lr))
+  if (nlen >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*lr))
   {
     GNUNET_break (0);
     return NULL;
@@ -407,14 +411,9 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
   lookup_msg->options = htons ((uint16_t) options);
   lookup_msg->zone = *zone;
   lookup_msg->type = htonl (type);
-  if (NULL != shorten_zone_key)
-  {
-    lookup_msg->have_key = htons (GNUNET_YES);
-    lookup_msg->shorten_key = *shorten_zone_key;
-  }
-  memcpy (&lookup_msg[1],
-          name,
-          nlen);
+  GNUNET_memcpy (&lookup_msg[1],
+                 name,
+                 nlen);
   GNUNET_CONTAINER_DLL_insert (handle->lookup_head,
                                handle->lookup_tail,
                                lr);
@@ -424,5 +423,4 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
   return lr;
 }
 
-
 /* end of gns_api.c */