-fix ftbfs
[oweals/gnunet.git] / src / sensor / gnunet-service-sensor.c
index b404d48063cbd50ad2eb7fffa68739b890e910d1..c162ca21ce5e941cac820b4ca40827c5a6b1b0db 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
@@ -108,6 +108,36 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 }
 
 
+/**
+ * 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");
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+  SENSOR_reporting_anomaly_update (sensor, ntohs (anomaly_msg->anomalous));
+  GNUNET_SERVER_receive_done (client, GNUNET_YES);
+}
+
+
 /**
  * Creates a structure with basic sensor info to be sent to a client.
  *
@@ -281,12 +311,15 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
      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}
   };
 
   cfg = c;
   if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_filename (cfg, "SENSOR", "SENSOR_DIR",
+      GNUNET_CONFIGURATION_get_value_filename (cfg, "sensor", "SENSOR_DIR",
                                                &sensor_dir))
   {
     sensor_dir = GNUNET_SENSOR_get_default_sensor_dir ();
@@ -296,22 +329,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   start_reporting = GNUNET_YES;
   start_update = GNUNET_YES;
   if (GNUNET_NO ==
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "SENSOR", "START_MONITORING"))
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "sensor", "START_MONITORING"))
   {
     start_monitoring = GNUNET_NO;
   }
   if (GNUNET_NO ==
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "SENSOR", "START_REPORTING"))
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "sensor", "START_REPORTING"))
   {
     start_reporting = GNUNET_NO;
   }
   if (GNUNET_NO ==
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "SENSOR", "START_ANALYSIS"))
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "sensor", "START_ANALYSIS"))
   {
     start_analysis = GNUNET_NO;
   }
   if (GNUNET_NO ==
-      GNUNET_CONFIGURATION_get_value_yesno (cfg, "SENSOR", "START_UPDATE"))
+      GNUNET_CONFIGURATION_get_value_yesno (cfg, "sensor", "START_UPDATE"))
   {
     start_update = GNUNET_NO;
   }