Merge branch 'master' of ssh://gnunet.org/gnunet
[oweals/gnunet.git] / src / cadet / gnunet-cadet-profiler.c
index 7128d9d7c3a99464407adeac2977da1f39aa102c..15da05b6d4aa529add44b9bbce034cefa6865f74 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     Copyright (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011 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
@@ -147,7 +147,12 @@ struct CadetPeer
   /**
    * Task to do the next ping.
    */
-  struct GNUNET_SCHEDULER_Task * ping_task;
+  struct GNUNET_SCHEDULER_Task *ping_task;
+
+  /**
+   * NTR operation for the next ping.
+   */
+  struct GNUNET_CADET_TransmitHandle *ping_ntr;
 
   float mean[number_rounds];
   float var[number_rounds];
@@ -179,7 +184,7 @@ static struct GNUNET_TESTBED_Operation *stats_op;
 /**
  * Operation to get peer ids.
  */
-struct CadetPeer *peers;
+static struct CadetPeer *peers;
 
 /**
  * Peer ids counter.
@@ -206,20 +211,15 @@ static unsigned long long peers_pinging;
  */
 static struct GNUNET_CADET_TEST_Context *test_ctx;
 
-/**
- * Task called to shutdown test.
- */
-static struct GNUNET_SCHEDULER_Task * shutdown_handle;
-
 /**
  * Task called to disconnect peers, before shutdown.
  */
-static struct GNUNET_SCHEDULER_Task * disconnect_task;
+static struct GNUNET_SCHEDULER_Task *disconnect_task;
 
 /**
  * Task to perform tests
  */
-static struct GNUNET_SCHEDULER_Task * test_task;
+static struct GNUNET_SCHEDULER_Task *test_task;
 
 /**
  * Round number.
@@ -241,6 +241,11 @@ static unsigned int peers_warmup;
  */
 static int test_finished;
 
+/**
+ * Task running each round of the benchmark.
+ */
+static struct GNUNET_SCHEDULER_Task *round_task;
+
 
 /**
  * START THE TEST ITSELF, AS WE ARE CONNECTED TO THE CADET SERVICES.
@@ -249,10 +254,9 @@ static int test_finished;
  * on callback funtion ch.
  *
  * @param cls Closure (unsued).
- * @param tc Task Context.
  */
 static void
-start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
+start_test (void *cls);
 
 
 /**
@@ -310,34 +314,20 @@ show_end_data (void)
 }
 
 
-/**
- * Shut down peergroup, clean up.
- *
- * @param cls Closure (unused).
- * @param tc Task Context.
- */
-static void
-shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Ending test.\n");
-  shutdown_handle = NULL;
-}
-
-
 /**
  * Disconnect from cadet services af all peers, call shutdown.
  *
  * @param cls Closure (unused).
- * @param tc Task Context.
  */
 static void
-disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+disconnect_cadet_peers (void *cls)
 {
   long line = (long) cls;
   unsigned int i;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "disconnecting cadet service, called from line %ld\n", line);
+              "disconnecting cadet service, called from line %ld\n",
+             line);
   disconnect_task = NULL;
   for (i = 0; i < peers_total; i++)
   {
@@ -349,28 +339,56 @@ disconnect_cadet_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc
 
     if (NULL != peers[i].ch)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: channel %p\n", i, peers[i].ch);
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 "%u: channel %p\n", i, peers[i].ch);
       GNUNET_CADET_channel_destroy (peers[i].ch);
     }
     if (NULL != peers[i].warmup_ch)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: warmup channel %p\n",
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 "%u: warmup channel %p\n",
                   i, peers[i].warmup_ch);
       GNUNET_CADET_channel_destroy (peers[i].warmup_ch);
     }
     if (NULL != peers[i].incoming_ch)
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u: incoming channel %p\n",
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                 "%u: incoming channel %p\n",
                   i, peers[i].incoming_ch);
       GNUNET_CADET_channel_destroy (peers[i].incoming_ch);
     }
   }
   GNUNET_CADET_TEST_cleanup (test_ctx);
-  if (NULL != shutdown_handle)
+  GNUNET_SCHEDULER_shutdown ();
+}
+
+
+/**
+ * Shut down peergroup, clean up.
+ *
+ * @param cls Closure (unused).
+ */
+static void
+shutdown_task (void *cls)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "Ending test.\n");
+  if (NULL != disconnect_task)
+  {
+    GNUNET_SCHEDULER_cancel (disconnect_task);
+    disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_cadet_peers,
+                                               (void *) __LINE__);
+  }
+  if (NULL != round_task)
+  {
+    GNUNET_SCHEDULER_cancel (round_task);
+    round_task = NULL;
+  }
+  if (NULL != test_task)
   {
-    GNUNET_SCHEDULER_cancel (shutdown_handle);
+    GNUNET_SCHEDULER_cancel (test_task);
+    test_task = NULL;
   }
-  shutdown_handle = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
 }
 
 
@@ -421,19 +439,24 @@ stats_cont (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
  * @param subsystem name of subsystem that created the statistic
  * @param name the name of the datum
  * @param value the current value
- * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
- * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
+ * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
  */
 static int
-stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
-                const char *subsystem, const char *name,
-                uint64_t value, int is_persistent)
+stats_iterator (void *cls,
+               const struct GNUNET_TESTBED_Peer *peer,
+                const char *subsystem,
+               const char *name,
+                uint64_t value,
+               int is_persistent)
 {
   uint32_t i;
 
   i = GNUNET_TESTBED_get_index (peer);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " STATS %u - %s [%s]: %llu\n",
-              i, subsystem, name, value);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              " STATS %u - %s [%s]: %llu\n",
+              i, subsystem, name,
+              (unsigned long long) value);
 
   return GNUNET_OK;
 }
@@ -443,18 +466,17 @@ stats_iterator (void *cls, const struct GNUNET_TESTBED_Peer *peer,
  * Task check that keepalives were sent and received.
  *
  * @param cls Closure (NULL).
- * @param tc Task Context.
  */
 static void
-collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+collect_stats (void *cls)
 {
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
-  stats_op = GNUNET_TESTBED_get_statistics (peers_total, testbed_handles,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "Start collecting statistics...\n");
+  stats_op = GNUNET_TESTBED_get_statistics (peers_total,
+                                           testbed_handles,
                                             NULL, NULL,
-                                            stats_iterator, stats_cont, NULL);
+                                            &stats_iterator,
+                                           &stats_cont, NULL);
 }
 
 
@@ -462,19 +484,16 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @brief Finish profiler normally. Signal finish and start collecting stats.
  *
  * @param cls Closure (unused).
- * @param tc Task context.
  */
 static void
-finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+finish_profiler (void *cls)
 {
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
   test_finished = GNUNET_YES;
-  show_end_data();
+  show_end_data ();
   GNUNET_SCHEDULER_add_now (&collect_stats, NULL);
 }
 
+
 /**
  * Set the total number of running peers.
  *
@@ -514,9 +533,15 @@ adjust_running_peers (unsigned int target)
                 run ? "arting" : "opping", r, GNUNET_i2s (&peers[r].id));
 
     if (NULL != peers[r].ping_task)
+    {
       GNUNET_SCHEDULER_cancel (peers[r].ping_task);
-    peers[r].ping_task = NULL;
-
+      peers[r].ping_task = NULL;
+    }
+    if (NULL != peers[r].ping_ntr)
+    {
+      GNUNET_CADET_notify_transmit_ready_cancel (peers[r].ping_ntr);
+      peers[r].ping_ntr = NULL;
+    }
     peers[r].up = run;
 
     if (NULL != peers[r].ch)
@@ -542,15 +567,13 @@ adjust_running_peers (unsigned int target)
  * @brief Move to next round.
  *
  * @param cls Closure (round #).
- * @param tc Task context.
  */
 static void
-next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+next_rnd (void *cls)
 {
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ROUND %ld\n", current_round);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "ROUND %u\n",
+              current_round);
   if (0.0 == rounds[current_round])
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finishing\n");
@@ -560,7 +583,9 @@ next_rnd (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   adjust_running_peers (rounds[current_round] * peers_total);
   current_round++;
 
-  GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+  round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+                                            &next_rnd,
+                                            NULL);
 }
 
 
@@ -596,7 +621,7 @@ tmt_rdy_pong (void *cls, size_t size, void *buf)
     return 0;
   }
   pong = (struct CadetPingMessage *) buf;
-  memcpy (pong, ping, sizeof (*ping));
+  GNUNET_memcpy (pong, ping, sizeof (*ping));
   pong->header.type = htons (PONG);
 
   GNUNET_free (ping);
@@ -608,26 +633,24 @@ tmt_rdy_pong (void *cls, size_t size, void *buf)
  * @brief Send a ping to destination
  *
  * @param cls Closure (peer).
- * @param tc Task context.
  */
 static void
-ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+ping (void *cls)
 {
-  struct CadetPeer *peer = (struct CadetPeer *) cls;
+  struct CadetPeer *peer = cls;
 
   peer->ping_task = NULL;
-
-  if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
-      || GNUNET_YES == test_finished)
+  if (GNUNET_YES == test_finished)
     return;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u -> %u (%u)\n",
-              get_index (peer), get_index (peer->dest), peer->data_sent);
-
-  GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
-                                      GNUNET_TIME_UNIT_FOREVER_REL,
-                                      sizeof (struct CadetPingMessage),
-                                      &tmt_rdy_ping, peer);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "%u -> %u (%u)\n",
+              get_index (peer),
+             get_index (peer->dest),
+             peer->data_sent);
+  peer->ping_ntr = GNUNET_CADET_notify_transmit_ready (peer->ch, GNUNET_NO,
+                                                      GNUNET_TIME_UNIT_FOREVER_REL,
+                                                      sizeof (struct CadetPingMessage),
+                                                      &tmt_rdy_ping, peer);
 }
 
 /**
@@ -637,12 +660,13 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  * @param tc Task context.
  */
 static void
-pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping)
+pong (struct GNUNET_CADET_Channel *channel,
+      const struct CadetPingMessage *ping)
 {
   struct CadetPingMessage *copy;
 
   copy = GNUNET_new (struct CadetPingMessage);
-  memcpy (copy, ping, sizeof (*ping));
+  *copy = *ping;
   GNUNET_CADET_notify_transmit_ready (channel, GNUNET_NO,
                                      GNUNET_TIME_UNIT_FOREVER_REL,
                                      sizeof (struct CadetPingMessage),
@@ -660,20 +684,27 @@ pong (struct GNUNET_CADET_Channel *channel, const struct CadetPingMessage *ping)
 static size_t
 tmt_rdy_ping (void *cls, size_t size, void *buf)
 {
-  struct CadetPeer *peer = (struct CadetPeer *) cls;
+  struct CadetPeer *peer = cls;
   struct CadetPingMessage *msg = buf;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
+  peer->ping_ntr = NULL;
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "tmt_rdy called, filling buffer\n");
   if (size < sizeof (struct CadetPingMessage) || NULL == buf)
   {
     GNUNET_break (GNUNET_YES == test_finished);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "size %u, buf %p, data_sent %u, data_received %u\n",
-                size, buf, peer->data_sent, peer->data_received);
+                (unsigned int) size,
+                buf,
+                peer->data_sent,
+                peer->data_received);
 
     return 0;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending: msg %d\n", peer->data_sent);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Sending: msg %d\n",
+              peer->data_sent);
   msg->header.size = htons (size);
   msg->header.type = htons (PING);
   msg->counter = htonl (peer->data_sent++);
@@ -704,7 +735,9 @@ ping_handler (void *cls, struct GNUNET_CADET_Channel *channel,
 {
   long n = (long) cls;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u got PING\n", n);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "%u got PING\n",
+              (unsigned int) n);
   GNUNET_CADET_receive_done (channel);
   if (GNUNET_NO == test_finished)
     pong (channel, (struct CadetPingMessage *) message);
@@ -745,7 +778,9 @@ pong_handler (void *cls, struct GNUNET_CADET_Channel *channel,
   latency = GNUNET_TIME_absolute_get_duration (send_time);
   r = ntohl (msg->round_number);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <- %u (%u) latency: %s\n",
-              get_index (peer), get_index (peer->dest), ntohl (msg->counter),
+              get_index (peer),
+              get_index (peer->dest),
+              (uint32_t) ntohl (msg->counter),
               GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_NO));
 
   /* Online variance calculation */
@@ -783,7 +818,8 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
 static void *
 incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
                  const struct GNUNET_PeerIdentity *initiator,
-                 uint32_t port, enum GNUNET_CADET_ChannelOption options)
+                 const struct GNUNET_HashCode *port,
+                  enum GNUNET_CADET_ChannelOption options)
 {
   long n = (long) cls;
   struct CadetPeer *peer;
@@ -792,8 +828,11 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
   GNUNET_assert (NULL != peer);
   if (NULL == peers[n].incoming)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "WARMUP %3u: %u <= %u\n",
-                peers_warmup, n, get_index (peer));
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "WARMUP %3u: %u <= %u\n",
+                peers_warmup,
+                (unsigned int) n,
+                get_index (peer));
     peers_warmup++;
     if (peers_warmup < peers_total)
       return NULL;
@@ -807,8 +846,11 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
   }
   GNUNET_assert (peer == peers[n].incoming);
   GNUNET_assert (peer->dest == &peers[n]);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u <= %u %p\n",
-              n, get_index (peer), channel);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "%u <= %u %p\n",
+              (unsigned int) n,
+              get_index (peer),
+              channel);
   peers[n].incoming_ch = channel;
 
   return NULL;
@@ -824,7 +866,8 @@ incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
  *                   with the channel is stored
  */
 static void
-channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel,
+channel_cleaner (void *cls,
+                const struct GNUNET_CADET_Channel *channel,
                  void *channel_ctx)
 {
   long n = (long) cls;
@@ -865,18 +908,14 @@ select_random_peer (struct CadetPeer *peer)
  * on callback funtion ch.
  *
  * @param cls Closure (unsued).
- * @param tc Task Context.
  */
 static void
-start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+start_test (void *cls)
 {
   enum GNUNET_CADET_ChannelOption flags;
   unsigned long i;
 
   test_task = NULL;
-  if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
-    return;
-
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start profiler\n");
 
   flags = GNUNET_CADET_OPTION_DEFAULT;
@@ -885,15 +924,18 @@ start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
     peers[i].dest = select_random_peer (&peers[i]);
     peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
                                                &peers[i].dest->id,
-                                               1, flags);
+                                               GC_u2h (1), flags);
     if (NULL == peers[i].ch)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
       GNUNET_CADET_TEST_cleanup (test_ctx);
       return;
     }
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%u => %u %p\n",
-                i, get_index (peers[i].dest), peers[i].ch);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                "%lu => %u %p\n",
+                i,
+                get_index (peers[i].dest),
+                peers[i].ch);
     peers[i].ping_task = GNUNET_SCHEDULER_add_delayed (delay_ms_rnd (2000),
                                                        &ping, &peers[i]);
   }
@@ -905,7 +947,9 @@ start_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
                                                                 number_rounds + 1),
                                   &disconnect_cadet_peers,
                                   (void *) __LINE__);
-  GNUNET_SCHEDULER_add_delayed (round_time, &next_rnd, NULL);
+  round_task = GNUNET_SCHEDULER_add_delayed (round_time,
+                                            &next_rnd,
+                                            NULL);
 }
 
 
@@ -925,7 +969,7 @@ warmup (void)
                 i, get_index (peer));
     peers[i].warmup_ch =
       GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
-                                  1, GNUNET_CADET_OPTION_DEFAULT);
+                                  GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
     if (NULL == peers[i].warmup_ch)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
@@ -935,6 +979,7 @@ warmup (void)
   }
 }
 
+
 /**
  * Callback to be called when the requested peer information is available
  *
@@ -946,9 +991,9 @@ warmup (void)
  */
 static void
 peer_id_cb (void *cls,
-       struct GNUNET_TESTBED_Operation *op,
-       const struct GNUNET_TESTBED_PeerInformation *pinfo,
-       const char *emsg)
+           struct GNUNET_TESTBED_Operation *op,
+           const struct GNUNET_TESTBED_PeerInformation *pinfo,
+           const char *emsg)
 {
   long n = (long) cls;
 
@@ -959,8 +1004,10 @@ peer_id_cb (void *cls,
     return;
   }
   peers[n].id = *(pinfo->result.id);
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, " %u  id: %s\n",
-              n, GNUNET_i2s (&peers[n].id));
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "%ld  id: %s\n",
+              n,
+              GNUNET_i2s (&peers[n].id));
   GNUNET_break (GNUNET_OK ==
                 GNUNET_CONTAINER_multipeermap_put (ids, &peers[n].id, &peers[n],
                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
@@ -987,6 +1034,7 @@ peer_id_cb (void *cls,
                                             &start_test, NULL);
 }
 
+
 /**
  * test main: start test when all peers are connected
  *
@@ -1005,7 +1053,8 @@ tmain (void *cls,
 {
   unsigned long i;
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test main\n");
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "test main\n");
   test_ctx = ctx;
   GNUNET_assert (peers_total == num_peers);
   peers_running = num_peers;
@@ -1013,11 +1062,12 @@ tmain (void *cls,
   disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
                                                   &disconnect_cadet_peers,
                                                   (void *) __LINE__);
-  shutdown_handle = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
-                                                  &shutdown_task, NULL);
+  GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
   for (i = 0; i < peers_total; i++)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "requesting id %ld\n", i);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+               "requesting id %ld\n",
+               i);
     peers[i].up = GNUNET_YES;
     peers[i].cadet = cadetes[i];
     peers[i].op =
@@ -1036,32 +1086,42 @@ tmain (void *cls,
 int
 main (int argc, char *argv[])
 {
-  static uint32_t ports[2];
+  static const struct GNUNET_HashCode *ports[2];
   const char *config_file;
 
   config_file = ".profiler.conf";
 
   if (4 > argc)
   {
-    fprintf (stderr, "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n", argv[0]);
-    fprintf (stderr, "example: %s 30s 16 1 Y\n", argv[0]);
+    fprintf (stderr,
+            "usage: %s ROUND_TIME PEERS PINGS [DO_WARMUP]\n",
+            argv[0]);
+    fprintf (stderr,
+            "example: %s 30s 16 1 Y\n",
+            argv[0]);
     return 1;
   }
 
-  if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[1], &round_time))
+  if (GNUNET_OK !=
+      GNUNET_STRINGS_fancy_time_to_relative (argv[1],
+                                            &round_time))
   {
-    fprintf (stderr, "%s is not a valid time\n", argv[1]);
+    fprintf (stderr,
+            "%s is not a valid time\n",
+            argv[1]);
     return 1;
   }
 
   peers_total = atoll (argv[2]);
   if (2 > peers_total)
   {
-    fprintf (stderr, "%s peers is not valid (> 2)\n", argv[1]);
+    fprintf (stderr,
+            "%s peers is not valid (> 2)\n",
+            argv[1]);
     return 1;
   }
-  peers = GNUNET_malloc (sizeof (struct CadetPeer) * peers_total);
-
+  peers = GNUNET_new_array (peers_total,
+                           struct CadetPeer);
   peers_pinging = atoll (argv[3]);
 
   if (peers_total < 2 * peers_pinging)
@@ -1073,11 +1133,12 @@ main (int argc, char *argv[])
 
   do_warmup = (5 > argc || argv[4][0] != 'N');
 
-  ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total, GNUNET_YES);
+  ids = GNUNET_CONTAINER_multipeermap_create (2 * peers_total,
+                                             GNUNET_YES);
   GNUNET_assert (NULL != ids);
   p_ids = 0;
   test_finished = GNUNET_NO;
-  ports[0] = 1;
+  ports[0] = GC_u2h (1);
   ports[1] = 0;
   GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
                         &tmain, NULL, /* tmain cls */
@@ -1089,4 +1150,3 @@ main (int argc, char *argv[])
 }
 
 /* end of gnunet-cadet-profiler.c */
-