-fix ftbfs
[oweals/gnunet.git] / src / sensor / gnunet-service-sensor_reporting.c
index 3b2c08e423f9b5fd581de56463bee4f904f9a3ab..f37735ec1f2c320d06b76ace7ddb3ad48b422939 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C)
+     Copyright (C)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -162,9 +162,9 @@ struct ValueInfo
   struct GNUNET_PEERSTORE_WatchContext *wc;
 
   /**
-   * Collection point reporting task (or #GNUNET_SCHEDULER_NO_TASK)
+   * Collection point reporting task (or NULL)
    */
-  GNUNET_SCHEDULER_TaskIdentifier reporting_task;
+  struct GNUNET_SCHEDULER_Task *reporting_task;
 
 };
 
@@ -237,7 +237,7 @@ struct CadetPeer
   /**
    * Task used to try reconnection to collection point after failure
    */
-  GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
+  struct GNUNET_SCHEDULER_Task * reconnect_task;
 
   /**
    * Are we currently destroying the channel and its context?
@@ -400,10 +400,10 @@ destroy_value_info (struct ValueInfo *vi)
     GNUNET_PEERSTORE_watch_cancel (vi->wc);
     vi->wc = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != vi->reporting_task)
+  if (NULL != vi->reporting_task)
   {
     GNUNET_SCHEDULER_cancel (vi->reporting_task);
-    vi->reporting_task = GNUNET_SCHEDULER_NO_TASK;
+    vi->reporting_task = NULL;
   }
   if (NULL != vi->last_value)
   {
@@ -423,20 +423,33 @@ static void
 destroy_core_peer (struct CorePeer *corep)
 {
   struct AnomalyInfo *ai;
+  struct AnomalyReportingQueueItem *ar_item;
 
-  if (NULL != corep->mq)
-  {
-    GNUNET_MQ_destroy (corep->mq);
-    corep->mq = NULL;
-  }
   ai = ai_head;
   while (NULL != ai)
   {
     GNUNET_assert (NULL != ai->anomalous_neighbors);
     GNUNET_CONTAINER_multipeermap_remove_all (ai->anomalous_neighbors,
                                               corep->peer_id);
+    /* Remove the core peer from any reporting queues */
+    ar_item = ai->reporting_queue_head;
+    while (NULL != ar_item)
+    {
+      if (ar_item->dest_mq == corep->mq)
+      {
+        GNUNET_CONTAINER_DLL_remove (ai->reporting_queue_head,
+                                     ai->reporting_queue_tail, ar_item);
+        break;
+      }
+      ar_item = ar_item->next;
+    }
     ai = ai->next;
   }
+  if (NULL != corep->mq)
+  {
+    GNUNET_MQ_destroy (corep->mq);
+    corep->mq = NULL;
+  }
   GNUNET_free (corep);
 }
 
@@ -450,10 +463,10 @@ static void
 destroy_cadet_peer (struct CadetPeer *cadetp)
 {
   cadetp->destroying = GNUNET_YES;
-  if (GNUNET_SCHEDULER_NO_TASK != cadetp->reconnect_task)
+  if (NULL != cadetp->reconnect_task)
   {
     GNUNET_SCHEDULER_cancel (cadetp->reconnect_task);
-    cadetp->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+    cadetp->reconnect_task = NULL;
   }
   if (NULL != cadetp->mq)
   {
@@ -612,7 +625,7 @@ cp_reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   LOG (GNUNET_ERROR_TYPE_INFO,
        "Retrying connection to collection point `%s'.\n",
        GNUNET_i2s (&cadetp->peer_id));
-  cadetp->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  cadetp->reconnect_task = NULL;
   GNUNET_assert (NULL == cadetp->channel);
   cadetp->channel =
       GNUNET_CADET_channel_create (cadet, cadetp, &cadetp->peer_id,
@@ -727,7 +740,7 @@ get_cadet_peer (struct GNUNET_PeerIdentity pid)
                                    GNUNET_APPLICATION_TYPE_SENSORDASHBOARD,
                                    GNUNET_CADET_OPTION_RELIABLE);
   cadetp->mq = cp_mq_create (cadetp);
-  cadetp->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+  cadetp->reconnect_task = NULL;
   GNUNET_CONTAINER_DLL_insert (cadetp_head, cadetp_tail, cadetp);
   return cadetp;
 }
@@ -873,9 +886,9 @@ update_anomaly_report_pow_block (struct AnomalyInfo *ai)
   arm->anomalous = htons (ai->anomalous);
   arm->anomalous_neighbors =
       (0 ==
-       neighborhood) ? 0 : ((float) GNUNET_CONTAINER_multipeermap_size (ai->
-                                                                        anomalous_neighbors))
-      / neighborhood;
+       neighborhood) ? 0 : ((float)
+                            GNUNET_CONTAINER_multipeermap_size
+                            (ai->anomalous_neighbors)) / neighborhood;
   timestamp = GNUNET_TIME_absolute_get ();
   ai->report_creation_cx =
       GNUNET_SENSOR_crypto_pow_sign (arm,
@@ -968,8 +981,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
   my_anomaly_info = get_anomaly_info_by_sensor (sensor);
   GNUNET_assert (NULL != my_anomaly_info);
   peer_in_anomalous_list =
-      GNUNET_CONTAINER_multipeermap_contains (my_anomaly_info->
-                                              anomalous_neighbors, other);
+      GNUNET_CONTAINER_multipeermap_contains
+      (my_anomaly_info->anomalous_neighbors, other);
   peer_anomalous = ntohs (arm->anomalous);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Received an anomaly update from neighbour `%s' (%d).\n",
@@ -988,8 +1001,8 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
     if (GNUNET_NO == peer_in_anomalous_list)    /* repeated negative report */
       GNUNET_break_op (0);
     else
-      GNUNET_CONTAINER_multipeermap_remove_all (my_anomaly_info->
-                                                anomalous_neighbors, other);
+      GNUNET_CONTAINER_multipeermap_remove_all
+          (my_anomaly_info->anomalous_neighbors, other);
   }
   /* This is important to create an updated block since the data changed */
   update_anomaly_report_pow_block (my_anomaly_info);
@@ -1019,10 +1032,12 @@ handle_anomaly_report (void *cls, const struct GNUNET_PeerIdentity *other,
  * @param cls Closure, ValueInfo struct related to the sensor we are watching
  * @param record PEERSTORE new record, NULL if error
  * @param emsg Error message, NULL if no error
- * @return GNUNET_YES to continue watching
+ * @return #GNUNET_YES to continue watching
  */
 static int
-value_watch_cb (void *cls, struct GNUNET_PEERSTORE_Record *record, char *emsg)
+value_watch_cb (void *cls,
+                const struct GNUNET_PEERSTORE_Record *record,
+                const char *emsg)
 {
   struct ValueInfo *vi = cls;