gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34145 - in gnunet/src: include sensor


From: gnunet
Subject: [GNUnet-SVN] r34145 - in gnunet/src: include sensor
Date: Tue, 12 Aug 2014 12:57:54 +0200

Author: otarabai
Date: 2014-08-12 12:57:54 +0200 (Tue, 12 Aug 2014)
New Revision: 34145

Modified:
   gnunet/src/include/gnunet_sensor_service.h
   gnunet/src/sensor/gnunet-service-sensor.c
   gnunet/src/sensor/gnunet-service-sensor_reporting.c
   gnunet/src/sensor/sensor_api.c
Log:
sensor: force fake anomaly


Modified: gnunet/src/include/gnunet_sensor_service.h
===================================================================
--- gnunet/src/include/gnunet_sensor_service.h  2014-08-11 18:39:39 UTC (rev 
34144)
+++ gnunet/src/include/gnunet_sensor_service.h  2014-08-12 10:57:54 UTC (rev 
34145)
@@ -145,6 +145,23 @@
                                GNUNET_SENSOR_SensorIterateCB callback,
                                void *callback_cls);
 
+
+/**
+ * Force an anomaly status change on a given sensor. If the sensor reporting
+ * module is running, this will trigger the usual reporting logic, therefore,
+ * please only use this in a test environment.
+ *
+ * Also, if the sensor analysis module is running, it might conflict and cause
+ * undefined behaviour if it detects a real anomaly.
+ *
+ * @param h Service handle
+ * @param sensor_name Sensor name to set the anomaly status
+ * @param anomalous The desired status: #GNUNET_YES / #GNUNET_NO
+ */
+void
+GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h, char *sensor_name,
+                             int anomalous);
+
 #if 0                           /* keep Emacsens' auto-indent happy */
 {
 #endif

Modified: gnunet/src/sensor/gnunet-service-sensor.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor.c   2014-08-11 18:39:39 UTC (rev 
34144)
+++ gnunet/src/sensor/gnunet-service-sensor.c   2014-08-12 10:57:54 UTC (rev 
34145)
@@ -109,6 +109,34 @@
 
 
 /**
+ * Handle a force anomaly request from client.
+ *
+ * @param cls closure
+ * @param client identification of the client
+ * @param message the actual message
+ */
+static void
+handle_anomaly_force (void *cls, struct GNUNET_SERVER_Client *client,
+                      const struct GNUNET_MessageHeader *message)
+{
+  struct ForceAnomalyMessage *anomaly_msg;
+  struct GNUNET_SENSOR_SensorInfo *sensor;
+
+  anomaly_msg = (struct ForceAnomalyMessage *) message;
+  sensor =
+      GNUNET_CONTAINER_multihashmap_get (sensors,
+                                         &anomaly_msg->sensor_name_hash);
+  if (NULL == sensor)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Force anomaly message received for a sensor we don't 
have.\n");
+    return;
+  }
+  SENSOR_reporting_anomaly_update (sensor, ntohs (anomaly_msg->anomalous));
+}
+
+
+/**
  * Creates a structure with basic sensor info to be sent to a client.
  *
  * @param sensor sensor information
@@ -281,6 +309,9 @@
      0},
     {&handle_get_all_sensors, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GETALL,
      sizeof (struct GNUNET_MessageHeader)},
+    {
+     &handle_anomaly_force, NULL, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_FORCE,
+     sizeof (struct ForceAnomalyMessage)},
     {NULL, NULL, 0, 0}
   };
 

Modified: gnunet/src/sensor/gnunet-service-sensor_reporting.c
===================================================================
--- gnunet/src/sensor/gnunet-service-sensor_reporting.c 2014-08-11 18:39:39 UTC 
(rev 34144)
+++ gnunet/src/sensor/gnunet-service-sensor_reporting.c 2014-08-12 10:57:54 UTC 
(rev 34145)
@@ -811,6 +811,7 @@
     send_anomaly_report (corep->mq, ai);
     corep = corep->next;
   }
+  /* Report change to collection point if need */
   if (NULL != ai->sensor->collection_point &&
       GNUNET_YES == ai->sensor->report_anomalies)
   {

Modified: gnunet/src/sensor/sensor_api.c
===================================================================
--- gnunet/src/sensor/sensor_api.c      2014-08-11 18:39:39 UTC (rev 34144)
+++ gnunet/src/sensor/sensor_api.c      2014-08-12 10:57:54 UTC (rev 34145)
@@ -426,13 +426,16 @@
  * @param anomalous The desired status: #GNUNET_YES / #GNUNET_NO
  */
 void
-GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h,
-    char *sensor_name, int anomalous)
+GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h, char *sensor_name,
+                             int anomalous)
 {
   struct ForceAnomalyMessage *msg;
   struct GNUNET_MQ_Envelope *ev;
 
-  ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT);
+  ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_FORCE);
+  GNUNET_CRYPTO_hash (sensor_name, strlen (sensor_name) + 1,
+                      &msg->sensor_name_hash);
+  msg->anomalous = htons (anomalous);
   GNUNET_MQ_send (h->mq, ev);
 }
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]