/*
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
*/
static struct GNUNET_CONTAINER_MultiHashMap *sensors;
+/**
+ * Start the monitoring module ?
+ */
+static int start_monitoring;
+
+/**
+ * Start the analysis module ?
+ */
+static int start_analysis;
+
+/**
+ * Start the reporting module ?
+ */
+static int start_reporting;
+
+/**
+ * Start the update module ?
+ */
+static int start_update;
+
/**
* Resets the service by stopping components, reloading sensors and starting
static void
stop ()
{
- SENSOR_update_stop ();
- SENSOR_analysis_stop ();
- SENSOR_reporting_stop ();
- SENSOR_monitoring_stop ();
+ if (GNUNET_YES == start_update)
+ SENSOR_update_stop ();
+ if (GNUNET_YES == start_analysis)
+ SENSOR_analysis_stop ();
+ if (GNUNET_YES == start_reporting)
+ SENSOR_reporting_stop ();
+ if (GNUNET_YES == start_monitoring)
+ SENSOR_monitoring_stop ();
GNUNET_SENSOR_destroy_sensors (sensors);
}
}
+/**
+ * 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.
*
start ()
{
sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir);
- SENSOR_monitoring_start (cfg, sensors);
- SENSOR_reporting_start (cfg, sensors);
- SENSOR_analysis_start (cfg, sensors);
- SENSOR_update_start (cfg, sensors, &reset);
+ if (GNUNET_YES == start_monitoring)
+ SENSOR_monitoring_start (cfg, sensors);
+ if (GNUNET_YES == start_reporting)
+ SENSOR_reporting_start (cfg, sensors);
+ if (GNUNET_YES == start_analysis)
+ SENSOR_analysis_start (cfg, sensors);
+ if (GNUNET_YES == start_update)
+ SENSOR_update_start (cfg, sensors, &reset);
}
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 ();
}
+ start_monitoring = GNUNET_YES;
+ start_analysis = GNUNET_YES;
+ start_reporting = GNUNET_YES;
+ start_update = GNUNET_YES;
+ if (GNUNET_NO ==
+ 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"))
+ {
+ start_reporting = GNUNET_NO;
+ }
+ if (GNUNET_NO ==
+ 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"))
+ {
+ start_update = GNUNET_NO;
+ }
GNUNET_SERVER_add_handlers (server, handlers);
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
NULL);