- fix 2699
[oweals/gnunet.git] / src / gns / gnunet-service-gns_resolver.c
index 76eb46df0ed50e6c939318c6ce65d400f9615c6f..627be0b1726dccb67688aca052d8f695a3124781 100644 (file)
@@ -29,7 +29,6 @@
 #include "gnunet_dns_service.h"
 #include "gnunet_dht_service.h"
 #include "gnunet_namestore_service.h"
-#include "gnunet_vpn_service.h"
 #include "gnunet_dns_service.h"
 #include "gnunet_resolver_service.h"
 #include "gnunet_dnsparser_lib.h"
 #include "block_gns.h"
 #include "gns.h"
 #include "gnunet-service-gns_resolver.h"
+#ifndef WINDOWS
+#include "gnunet_vpn_service.h"
+#endif
+
 
 /**
  * Default DHT timeout
  */
 static struct GNUNET_NAMESTORE_Handle *namestore_handle;
 
+#ifndef WINDOWS
 /**
  * Our handle to the vpn service
  */
 static struct GNUNET_VPN_Handle *vpn_handle;
+#endif
 
 /**
  * Resolver handle to the dht
@@ -428,7 +433,7 @@ process_auth_discovery_dht_result (void* cls,
     {
       for (i=0; i < num_records; i++)
       {
-        if ((strcmp (name, "+") == 0) &&
+        if ((strcmp (name, GNUNET_GNS_MASTERZONE_STR) == 0) &&
             (rd[i].record_type == GNUNET_GNS_RECORD_PSEU))
         {
           /* found pseu */
@@ -544,7 +549,7 @@ process_zone_to_name_discover (void *cls,
   {
     gph->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
                                     &gph->auth->zone,
-                                    "+",
+                                    GNUNET_GNS_MASTERZONE_STR,
                                     GNUNET_GNS_RECORD_PSEU,
                                     &process_auth_discovery_ns_result,
                                     gph);
@@ -658,33 +663,6 @@ gns_resolver_init (struct GNUNET_NAMESTORE_Handle *nh,
   return GNUNET_OK;
 }
 
-
-/**
- * Cleanup ns tasks
- *
- * @param cls closure to iterator
- * @param node heap nodes
- * @param element the namestorebgtask
- * @param cost heap cost
- * @return always GNUNET_YES
- */
-static int
-cleanup_pending_ns_tasks (void* cls,
-                          struct GNUNET_CONTAINER_HeapNode *node,
-                          void *element,
-                          GNUNET_CONTAINER_HeapCostType cost)
-{
-  struct NamestoreBGTask *nbg = element;
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP: Terminating ns task\n");
-  GNUNET_NAMESTORE_cancel (nbg->qe);
-
-  GNUNET_CONTAINER_heap_remove_node (node);
-  return GNUNET_YES;
-}
-
-
 /**
  * finish lookup
  *
@@ -700,38 +678,6 @@ finish_lookup (struct ResolverHandle *rh,
                const struct GNUNET_NAMESTORE_RecordData *rd);
 
 
-/**
- * Cleanup background lookups FIXME get rid of this?? YES this doesn't do
- * anything! => find in code and remove all references to the heap
- *
- * @param cls closure to iterator
- * @param node heap nodes
- * @param element the resolver handle
- * @param cost heap cost
- * @return always GNUNET_YES
- */
-static int
-cleanup_pending_background_queries (void* cls,
-                                    struct GNUNET_CONTAINER_HeapNode *node,
-                                    void *element,
-                                    GNUNET_CONTAINER_HeapCostType cost)
-{
-  struct ResolverHandle *rh = element;
-
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP-%llu: Terminating background lookup\n",
-             rh->id);
-  GNUNET_CONTAINER_heap_remove_node (node);
-  if (0 == GNUNET_CONTAINER_heap_get_size (dht_lookup_heap))
-  {
-    GNUNET_CONTAINER_heap_iterate (ns_task_heap,
-                                  &cleanup_pending_ns_tasks,
-                                  NULL);    
-  }
-  return GNUNET_YES;
-}
-
-
 /**
  * Helper function to free resolver handle
  *
@@ -772,6 +718,8 @@ free_resolver_handle (struct ResolverHandle* rh)
     GNUNET_RESOLVER_request_cancel (rh->dns_resolver_handle);
   if (NULL != rh->rd.data)
     GNUNET_free ((void*)(rh->rd.data));
+  if (NULL != rh->dht_heap_node)
+    GNUNET_CONTAINER_heap_remove_node (rh->dht_heap_node);
   GNUNET_free (rh);
 }
 
@@ -804,8 +752,9 @@ finish_get_auth (struct ResolverHandle *rh,
 void
 gns_resolver_cleanup ()
 {
-  unsigned int s;
   struct GetPseuAuthorityHandle *tmp;
+  struct ResolverHandle *rh;
+  struct NamestoreBGTask *nbg;
 
   while (NULL != (tmp = gph_head))
   {
@@ -840,21 +789,21 @@ gns_resolver_cleanup ()
     finish_get_auth (nah_head, nah_head->proc_cls);
   }
 
-  s = GNUNET_CONTAINER_heap_get_size (dht_lookup_heap);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_CLEANUP: %u pending background queries to terminate\n", 
-             s);
-  if (0 != s)
-    GNUNET_CONTAINER_heap_iterate (dht_lookup_heap,
-                                   &cleanup_pending_background_queries,
-                                   NULL);
-  else if (0 != GNUNET_CONTAINER_heap_get_size (ns_task_heap))
+  while (NULL != (rh = GNUNET_CONTAINER_heap_remove_root(dht_lookup_heap)))
+  {
+      GNUNET_free (rh);
+  }
+  GNUNET_CONTAINER_heap_destroy (dht_lookup_heap);
+  dht_lookup_heap = NULL;
+
+  while (NULL != (nbg = GNUNET_CONTAINER_heap_remove_root(ns_task_heap)))
   {
-    GNUNET_CONTAINER_heap_iterate (ns_task_heap,
-                                   &cleanup_pending_ns_tasks,
-                                   NULL);
+      GNUNET_NAMESTORE_cancel (nbg->qe);
+      GNUNET_free (nbg);
   }
-  // FIXME: what about freeing the heaps themselves?
+  GNUNET_CONTAINER_heap_destroy (ns_task_heap);
+  ns_task_heap = NULL;
+
 }
 
 
@@ -1296,6 +1245,7 @@ process_record_result_ns (void* cls,
 }
 
 
+#ifndef WINDOWS
 /**
  * VPN redirect result callback
  *
@@ -1361,6 +1311,7 @@ process_record_result_vpn (void* cls, int af, const void *address)
              rh->id);
   rh->proc (rh->proc_cls, rh, 0, NULL);
 }
+#endif
 
 
 /**
@@ -1391,7 +1342,8 @@ handle_record_vpn (void* cls, struct ResolverHandle *rh,
 
   /* results found yay */
   GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
-             "GNS_PHASE_REC_VPN-%llu: Record resolved from VPN!", rh->id);
+             "GNS_PHASE_REC_VPN-%llu: Record resolved from VPN!\n",
+            rh->id);
 
   finish_lookup(rh, rlh, rd_count, rd);
 }
@@ -1860,6 +1812,7 @@ resolve_record_vpn (struct ResolverHandle *rh,
     af = AF_INET;
   else
     af = AF_INET6;
+#ifndef WINDOWS
   if (NULL == vpn_handle)
   {
     vpn_handle = GNUNET_VPN_connect (cfg);
@@ -1880,6 +1833,11 @@ resolve_record_vpn (struct ResolverHandle *rh,
                                                GNUNET_TIME_UNIT_FOREVER_ABS, //FIXME
                                                &process_record_result_vpn,
                                                rh);
+#else
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Error connecting to VPN (not available on W32 yet)\n");
+  finish_lookup (rh, rh->proc_cls, 0, NULL);  
+#endif
 }
 
 
@@ -2346,7 +2304,7 @@ process_delegation_result_dht (void* cls,
     /* Check for key revocation and delegate */
     rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
                                     &rh->authority,
-                                    "+",
+                                    GNUNET_GNS_MASTERZONE_STR,
                                     GNUNET_GNS_RECORD_REV,
                                     &process_pkey_revocation_result_ns,
                                     rh);
@@ -2487,7 +2445,7 @@ finish_lookup (struct ResolverHandle *rh,
     
     GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
                "GNS_POSTPROCESS: Postprocessing\n");
-    if (0 == strcmp(rh->name, "+"))
+    if (0 == strcmp(rh->name, GNUNET_GNS_MASTERZONE_STR))
       repl_string = rlh->name;
     else
       repl_string = rlh->name+strlen(rh->name)+1;
@@ -2647,7 +2605,7 @@ handle_record_ns (void* cls, struct ResolverHandle *rh,
     check_dht = GNUNET_NO;
   }
   
-  if ((0 != strcmp (rh->name, "+")) && (GNUNET_YES == is_srv (rh->name)))
+  if ((0 != strcmp (rh->name, GNUNET_GNS_MASTERZONE_STR)) && (GNUNET_YES == is_srv (rh->name)))
       check_dht = GNUNET_NO;
 
   if (GNUNET_YES == rh->only_cached)
@@ -3269,7 +3227,7 @@ process_delegation_result_ns (void* cls,
     /* Check for key revocation and delegate */
     rh->namestore_task = GNUNET_NAMESTORE_lookup_record (namestore_handle,
                                                         &rh->authority,
-                                                        "+",
+                                                        GNUNET_GNS_MASTERZONE_STR,
                                                         GNUNET_GNS_RECORD_REV,
                                                         &process_pkey_revocation_result_ns,
                                                         rh);
@@ -3478,8 +3436,8 @@ gns_resolver_lookup_record (struct GNUNET_CRYPTO_ShortHashCode zone,
     else
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  "Cannot handle this TLD %s\n", string_hash);
-      
+                  _("Not a GADS TLD: `%s'\n"), 
+                 name);      
       if (GNUNET_SCHEDULER_NO_TASK != rh->timeout_task)
         GNUNET_SCHEDULER_cancel (rh->timeout_task);
       GNUNET_CONTAINER_DLL_remove (rlh_head, rlh_tail, rh);