allow empty/NULL context message
[oweals/gnunet.git] / src / transport / gnunet-transport-profiler.c
index e33a71d17a73caf2902786b6533b93df84fd16b2..af47c5c567c4c7da16ed597b6f98a5f24181a2c9 100644 (file)
@@ -1,6 +1,6 @@
 /*
  This file is part of GNUnet.
- Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2011-2015 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
@@ -122,7 +122,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg;
 /**
  * Try_connect handle
  */
-static struct GNUNET_TRANSPORT_TryConnectHandle *tc_handle;
+static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh;
 
 static struct Iteration *ihead;
 
@@ -145,11 +145,6 @@ static struct GNUNET_TRANSPORT_Blacklist *bl_handle;
  */
 static struct GNUNET_PeerIdentity pid;
 
-/**
- * Task scheduled for cleanup / termination of the process.
- */
-static struct GNUNET_SCHEDULER_Task * end;
-
 /**
  * Selected level of verbosity.
  */
@@ -161,11 +156,9 @@ static int verbosity;
  * Stops monitoring activity.
  *
  * @param cls NULL
- * @param tc scheduler context
  */
 static void
-shutdown_task (void *cls,
-               const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
 {
   struct Iteration *icur;
   struct Iteration *inext;
@@ -177,17 +170,16 @@ shutdown_task (void *cls,
   float stddev_rate;
   float stddev_duration;
 
-  if (NULL != tc_handle)
+  if (NULL != ats_sh)
   {
-    GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
-    tc_handle = NULL;
+    GNUNET_ATS_connectivity_suggest_cancel (ats_sh);
+    ats_sh = NULL;
   }
   if (NULL != th)
   {
     GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
     th = NULL;
   }
-
   if (NULL != bl_handle )
   {
     GNUNET_TRANSPORT_blacklist_cancel (bl_handle);
@@ -383,9 +375,7 @@ iteration_done ()
   if (it_count == benchmark_iterations)
   {
     benchmark_running = GNUNET_NO;
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+    GNUNET_SCHEDULER_shutdown ();
     return;
   }
   else
@@ -406,10 +396,13 @@ static void
 notify_connect (void *cls,
                 const struct GNUNET_PeerIdentity *peer)
 {
-  if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
+  if (0 != memcmp (&pid,
+                   peer,
+                   sizeof(struct GNUNET_PeerIdentity)))
   {
     FPRINTF (stdout,
-        _("Connected to different peer `%s'\n"), GNUNET_i2s (&pid));
+             _("Connected to different peer `%s'\n"),
+             GNUNET_i2s (&pid));
     return;
   }
 
@@ -417,13 +410,6 @@ notify_connect (void *cls,
     FPRINTF (stdout,
         _("Successfully connected to `%s'\n"),
         GNUNET_i2s (&pid));
-
-  if (NULL != tc_handle)
-  {
-    GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
-    tc_handle = NULL;
-  }
-
   iteration_start ();
 }
 
@@ -476,49 +462,16 @@ notify_receive (void *cls,
 }
 
 
-static void
-try_connect_cb (void *cls,
-                const int result)
-{
-  static int retries = 0;
-
-  if (GNUNET_OK == result)
-  {
-    tc_handle = NULL;
-    return;
-  }
-
-  retries++;
-  if (retries < 10)
-  {
-    if (verbosity > 0)
-      FPRINTF (stdout, _("Retrying to connect to `%s'\n"), GNUNET_i2s (&pid));
-
-    tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb,
-        NULL);
-  }
-  else
-  {
-    FPRINTF (stderr,
-             "%s",
-             _("Failed to send connect request to transport service\n"));
-    if (NULL != end)
-      GNUNET_SCHEDULER_cancel (end);
-    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
-    ret = 1;
-    return;
-  }
-}
-
-
 static int
-blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
+blacklist_cb (void *cls,
+              const struct GNUNET_PeerIdentity *peer)
 {
   if (0 != memcmp (&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
   {
     if (verbosity > 0)
       FPRINTF (stdout,
-          _("Denying connection to `%s'\n"), GNUNET_i2s (peer));
+               _("Denying connection to `%s'\n"),
+               GNUNET_i2s (peer));
     return GNUNET_SYSERR;
   }
 
@@ -607,13 +560,11 @@ testservice_task (void *cls, int result)
   bl_handle = GNUNET_TRANSPORT_blacklist (cfg,
                                           &blacklist_cb,
                                           NULL);
-  tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid,
-                                            &try_connect_cb,
-                                            NULL);
-
-  end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                      &shutdown_task,
-                                      NULL);
+  ats_sh = GNUNET_ATS_connectivity_suggest (ats,
+                                            &pid,
+                                            1);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
+                                NULL);
 }