-try with finished
[oweals/gnunet.git] / src / hostlist / test_gnunet_daemon_hostlist_reconnect.c
index ff625cf8eb9423fb5e15e17f76faca596e15c22c..92cd7fcc593efb073447fe4d1a025b29080869bf 100644 (file)
@@ -28,7 +28,7 @@
 #include "gnunet_arm_service.h"
 #include "gnunet_transport_service.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_EXTRA_LOGGING
 
 #define START_ARM GNUNET_YES
 
@@ -47,6 +47,7 @@ struct PeerContext
   struct GNUNET_CONFIGURATION_Handle *cfg;
   struct GNUNET_TRANSPORT_Handle *th;
   struct GNUNET_MessageHeader *hello;
+  struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
 #if START_ARM
   struct GNUNET_OS_Process *arm_proc;
 #endif
@@ -60,11 +61,21 @@ static struct PeerContext p2;
 static void
 clean_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
+  if (NULL != p1.ghh)
+  {
+    GNUNET_TRANSPORT_get_hello_cancel (p1.ghh);
+    p1.ghh = NULL;
+  }
   if (p1.th != NULL)
   {
     GNUNET_TRANSPORT_disconnect (p1.th);
     p1.th = NULL;
   }
+  if (NULL != p2.ghh)
+  {
+    GNUNET_TRANSPORT_get_hello_cancel (p2.ghh);
+    p2.ghh = NULL;
+  }
   if (p2.th != NULL)
   {
     GNUNET_TRANSPORT_disconnect (p2.th);
@@ -97,13 +108,12 @@ timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  */
 static void
 notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
-                const struct GNUNET_TRANSPORT_ATS_Information *ats,
-                uint32_t ats_count)
+                const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
 {
   if (peer == NULL)
     return;
 #if VERBOSE
-  fprintf (stderr, "Peer %s connected\n", GNUNET_i2s (peer));
+  FPRINTF (stderr, "Peer %s connected\n", GNUNET_i2s (peer));
 #endif
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected, shutting down.\n");
   ok = 0;
@@ -121,7 +131,8 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
 {
   struct PeerContext *p = cls;
 
-  GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p);
+  GNUNET_TRANSPORT_get_hello_cancel (p->ghh);
+  p->ghh = NULL;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Received HELLO, starting hostlist service.\n");
 }
@@ -144,7 +155,7 @@ setup_peer (struct PeerContext *p, const char *cfgname)
   p->th =
       GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, &notify_connect, NULL);
   GNUNET_assert (p->th != NULL);
-  GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
+  p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
 }
 
 
@@ -241,10 +252,10 @@ main (int argc, char *argv[])
   ret = check ();
   if (ret == 0)
   {
-    fprintf (stderr, ".");
+    FPRINTF (stderr, "%s",  ".");
     /* now do it again */
     ret = check ();
-    fprintf (stderr, ".\n");
+    FPRINTF (stderr, "%s",  ".\n");
   }
   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-1");
   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-hostlist-peer-2");