sensor: fixes for proof-of-work, test passes now
[oweals/gnunet.git] / src / sensor / gnunet-service-sensor.c
index ce6fa04fc1698afbb59a24b7da3e951cb539bc84..e8b01ae33d5bfada5ec76fa2621c2a0eaa64dee9 100644 (file)
@@ -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,6 +311,9 @@ 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}
   };