/**
 * Task run in monitor mode when the user presses CTRL-C to abort.
 * Stops monitoring activity.
 *
 * @param cls Closure (unused).
 * @param tc scheduler context
 */
static void
shutdown_task (void *cls,
               const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
  if (NULL != ch)
  {
    GNUNET_MESH_channel_destroy (ch);
    ch = NULL;
  }
  if (NULL != mh)
  {
    GNUNET_MESH_disconnect (mh);
        mh = NULL;
  }
}
/**
 * Free the provided RemoteSubscriberInfo struct.
 *
 * This function takes care to cancel any pending transmission requests
 * and discard all outstanding messages not delivered to the subscriber
 * yet. Moreover, it destroys the channel connecting us to the subscriber
 * before finally freeing the given RemoteSubscriberInfo struct.
 *
 * @param subscriber pointer to a RemoteSubscriberInfo struct
 */
static void
remote_subscriber_info_free (struct RemoteSubscriberInfo *subscriber)
{
  struct PendingMessage *pm;

  if (NULL != subscriber->transmit_handle)
  {
    GNUNET_MESH_notify_transmit_ready_cancel (subscriber->transmit_handle);
    subscriber->transmit_handle = NULL;
  }
  while (NULL != (pm = subscriber->pending_head))
  {
    GNUNET_CONTAINER_DLL_remove (subscriber->pending_head,
                                 subscriber->pending_tail, pm);
    GNUNET_free (pm->msg);
    GNUNET_free (pm);
  }
  GNUNET_MESH_channel_destroy (subscriber->channel);
  GNUNET_free (subscriber);
}