+/**
+ * Task run in monitor mode when the user presses CTRL-C to abort.
+ * Stops monitoring activity.
+ *
+ * @param cls the 'struct GNUNET_TRANSPORT_PeerIterateContext *'
+ * @param tc scheduler context
+ */
+static void
+shutdown_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct GNUNET_TIME_Relative duration;
+ end = GNUNET_SCHEDULER_NO_TASK;
+ if (GNUNET_SCHEDULER_NO_TASK != op_timeout)
+ {
+ GNUNET_SCHEDULER_cancel (op_timeout);
+ op_timeout = GNUNET_SCHEDULER_NO_TASK;
+ }
+ if (NULL != tc_handle)
+ {
+ GNUNET_TRANSPORT_try_connect_cancel (tc_handle);
+ tc_handle = NULL;
+ }
+ if (NULL != pic)
+ {
+ GNUNET_TRANSPORT_peer_get_active_addresses_cancel (pic);
+ pic = NULL;
+ }
+ if (NULL != th)
+ {
+ GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
+ th = NULL;
+ }
+ if (NULL != handle)
+ {
+ GNUNET_TRANSPORT_disconnect(handle);
+ handle = NULL;
+ }
+ if (NULL != peers)
+ {
+ GNUNET_CONTAINER_multihashmap_destroy (peers);
+ peers = NULL;
+ }
+ if (benchmark_send)
+ {
+ duration = GNUNET_TIME_absolute_get_duration (start_time);
+ FPRINTF (stdout, _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
+ 1000 * traffic_sent / (1 + duration.rel_value), traffic_sent,
+ GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
+ }
+ if (benchmark_receive)
+ {
+ duration = GNUNET_TIME_absolute_get_duration (start_time);
+ FPRINTF (stdout, _("Received %llu bytes/s (%llu bytes in %s)\n"),
+ 1000 * traffic_received / (1 + duration.rel_value),
+ traffic_received,
+ GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
+ }
+}
+
+
+
+static void
+operation_timeout (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ op_timeout = GNUNET_SCHEDULER_NO_TASK;
+ if ((try_connect) || (benchmark_send) || (benchmark_receive))
+ {
+ FPRINTF (stdout, _("Failed to connect to `%s'\n"), GNUNET_h2s_full (&pid.hashPubKey));
+ if (GNUNET_SCHEDULER_NO_TASK != end)
+ GNUNET_SCHEDULER_cancel (end);
+ end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
+ ret = 1;
+ return;
+ }
+}
+
+
+