fix /tmp removal
[oweals/gnunet.git] / src / gns / gns_api.c
index b9b95b7c20fd5cc24e92e9e11ae162d036d6b090..ff67f0205250f1b941b55c6608f788e59534bb4d 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2009-2013, 2016 GNUnet e.V.
+     Copyright (C) 2009-2013, 2016, 2018 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -31,7 +31,7 @@
 #include "gnunet_protocols.h"
 #include "gnunet_dht_service.h"
 #include "gns.h"
-#include "gnunet_gns_service.h"
+#include "gns_api.h"
 
 
 #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
@@ -80,50 +80,6 @@ struct GNUNET_GNS_LookupRequest
 };
 
 
-/**
- * Connection to the GNS service.
- */
-struct GNUNET_GNS_Handle
-{
-
-  /**
-   * Configuration to use.
-   */
-  const struct GNUNET_CONFIGURATION_Handle *cfg;
-
-  /**
-   * Connection to service (if available).
-   */
-  struct GNUNET_MQ_Handle *mq;
-
-  /**
-   * Head of linked list of active lookup requests.
-   */
-  struct GNUNET_GNS_LookupRequest *lookup_head;
-
-  /**
-   * Tail of linked list of active lookup requests.
-   */
-  struct GNUNET_GNS_LookupRequest *lookup_tail;
-
-  /**
-   * Reconnect task
-   */
-  struct GNUNET_SCHEDULER_Task *reconnect_task;
-
-  /**
-   * How long do we wait until we try to reconnect?
-   */
-  struct GNUNET_TIME_Relative reconnect_backoff;
-
-  /**
-   * Request Id generator.  Incremented by one for each request.
-   */
-  uint32_t r_id_gen;
-
-};
-
-
 /**
  * Reconnect to GNS service.
  *
@@ -181,6 +137,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);
 }
 
@@ -198,7 +157,8 @@ check_result (void *cls,
   size_t mlen = ntohs (lookup_msg->header.size) - sizeof (*lookup_msg);
   uint32_t rd_count = ntohl (lookup_msg->rd_count);
   struct GNUNET_GNSRECORD_Data rd[rd_count];
-
+  
+  (void) cls;
   if (GNUNET_SYSERR ==
       GNUNET_GNSRECORD_records_deserialize (mlen,
                                             (const char*) &lookup_msg[1],
@@ -241,10 +201,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 +210,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);
 }
 
 
@@ -276,7 +239,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,20 +324,18 @@ 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 LookupMessage *lookup_msg;
@@ -390,7 +351,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 +368,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;
-  }
   GNUNET_memcpy (&lookup_msg[1],
-          name,
-          nlen);
+                 name,
+                 nlen);
   GNUNET_CONTAINER_DLL_insert (handle->lookup_head,
                                handle->lookup_tail,
                                lr);