aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-08-12 10:57:54 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-08-12 10:57:54 +0000
commit4ec038ad1cefcec2eaa60af61b8e973c27c4cf09 (patch)
tree237bdb6ee9103831ee12ec3417c972fdf48e364f
parentd26fff163ec1d081db3293daf9dd566e74f3fde5 (diff)
downloadgnunet-4ec038ad1cefcec2eaa60af61b8e973c27c4cf09.tar.gz
gnunet-4ec038ad1cefcec2eaa60af61b8e973c27c4cf09.zip
sensor: force fake anomaly
-rw-r--r--src/include/gnunet_sensor_service.h17
-rw-r--r--src/sensor/gnunet-service-sensor.c31
-rw-r--r--src/sensor/gnunet-service-sensor_reporting.c1
-rw-r--r--src/sensor/sensor_api.c9
4 files changed, 55 insertions, 3 deletions
diff --git a/src/include/gnunet_sensor_service.h b/src/include/gnunet_sensor_service.h
index a31b20e52..59e4248ab 100644
--- a/src/include/gnunet_sensor_service.h
+++ b/src/include/gnunet_sensor_service.h
@@ -145,6 +145,23 @@ GNUNET_SENSOR_iterate (struct GNUNET_SENSOR_Handle *h,
145 GNUNET_SENSOR_SensorIterateCB callback, 145 GNUNET_SENSOR_SensorIterateCB callback,
146 void *callback_cls); 146 void *callback_cls);
147 147
148
149/**
150 * Force an anomaly status change on a given sensor. If the sensor reporting
151 * module is running, this will trigger the usual reporting logic, therefore,
152 * please only use this in a test environment.
153 *
154 * Also, if the sensor analysis module is running, it might conflict and cause
155 * undefined behaviour if it detects a real anomaly.
156 *
157 * @param h Service handle
158 * @param sensor_name Sensor name to set the anomaly status
159 * @param anomalous The desired status: #GNUNET_YES / #GNUNET_NO
160 */
161void
162GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h, char *sensor_name,
163 int anomalous);
164
148#if 0 /* keep Emacsens' auto-indent happy */ 165#if 0 /* keep Emacsens' auto-indent happy */
149{ 166{
150#endif 167#endif
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c
index ce6fa04fc..02bc00a1a 100644
--- a/src/sensor/gnunet-service-sensor.c
+++ b/src/sensor/gnunet-service-sensor.c
@@ -109,6 +109,34 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 109
110 110
111/** 111/**
112 * Handle a force anomaly request from client.
113 *
114 * @param cls closure
115 * @param client identification of the client
116 * @param message the actual message
117 */
118static void
119handle_anomaly_force (void *cls, struct GNUNET_SERVER_Client *client,
120 const struct GNUNET_MessageHeader *message)
121{
122 struct ForceAnomalyMessage *anomaly_msg;
123 struct GNUNET_SENSOR_SensorInfo *sensor;
124
125 anomaly_msg = (struct ForceAnomalyMessage *) message;
126 sensor =
127 GNUNET_CONTAINER_multihashmap_get (sensors,
128 &anomaly_msg->sensor_name_hash);
129 if (NULL == sensor)
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
132 "Force anomaly message received for a sensor we don't have.\n");
133 return;
134 }
135 SENSOR_reporting_anomaly_update (sensor, ntohs (anomaly_msg->anomalous));
136}
137
138
139/**
112 * Creates a structure with basic sensor info to be sent to a client. 140 * Creates a structure with basic sensor info to be sent to a client.
113 * 141 *
114 * @param sensor sensor information 142 * @param sensor sensor information
@@ -281,6 +309,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
281 0}, 309 0},
282 {&handle_get_all_sensors, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GETALL, 310 {&handle_get_all_sensors, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GETALL,
283 sizeof (struct GNUNET_MessageHeader)}, 311 sizeof (struct GNUNET_MessageHeader)},
312 {
313 &handle_anomaly_force, NULL, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_FORCE,
314 sizeof (struct ForceAnomalyMessage)},
284 {NULL, NULL, 0, 0} 315 {NULL, NULL, 0, 0}
285 }; 316 };
286 317
diff --git a/src/sensor/gnunet-service-sensor_reporting.c b/src/sensor/gnunet-service-sensor_reporting.c
index 611f0d73d..a9d5d2e30 100644
--- a/src/sensor/gnunet-service-sensor_reporting.c
+++ b/src/sensor/gnunet-service-sensor_reporting.c
@@ -811,6 +811,7 @@ SENSOR_reporting_anomaly_update (struct GNUNET_SENSOR_SensorInfo *sensor,
811 send_anomaly_report (corep->mq, ai); 811 send_anomaly_report (corep->mq, ai);
812 corep = corep->next; 812 corep = corep->next;
813 } 813 }
814 /* Report change to collection point if need */
814 if (NULL != ai->sensor->collection_point && 815 if (NULL != ai->sensor->collection_point &&
815 GNUNET_YES == ai->sensor->report_anomalies) 816 GNUNET_YES == ai->sensor->report_anomalies)
816 { 817 {
diff --git a/src/sensor/sensor_api.c b/src/sensor/sensor_api.c
index b7ee55fb6..9a18427d0 100644
--- a/src/sensor/sensor_api.c
+++ b/src/sensor/sensor_api.c
@@ -426,13 +426,16 @@ GNUNET_SENSOR_iterate (struct GNUNET_SENSOR_Handle *h,
426 * @param anomalous The desired status: #GNUNET_YES / #GNUNET_NO 426 * @param anomalous The desired status: #GNUNET_YES / #GNUNET_NO
427 */ 427 */
428void 428void
429GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h, 429GNUNET_SENSOR_force_anomaly (struct GNUNET_SENSOR_Handle *h, char *sensor_name,
430 char *sensor_name, int anomalous) 430 int anomalous)
431{ 431{
432 struct ForceAnomalyMessage *msg; 432 struct ForceAnomalyMessage *msg;
433 struct GNUNET_MQ_Envelope *ev; 433 struct GNUNET_MQ_Envelope *ev;
434 434
435 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT); 435 ev = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_FORCE);
436 GNUNET_CRYPTO_hash (sensor_name, strlen (sensor_name) + 1,
437 &msg->sensor_name_hash);
438 msg->anomalous = htons (anomalous);
436 GNUNET_MQ_send (h->mq, ev); 439 GNUNET_MQ_send (h->mq, ev);
437} 440}
438 441