diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-07-24 14:27:25 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-07-24 14:27:25 +0000 |
commit | eaeb4e371a1ad8d3a7b3b85ad54e99afdfc106d9 (patch) | |
tree | 025d5a6b999d94d586efdfd2e14d89d20c41bcfb /src | |
parent | 2b1af57c696d62b6be7b179eabdb4b4a0c0d4b6d (diff) | |
download | gnunet-eaeb4e371a1ad8d3a7b3b85ad54e99afdfc106d9.tar.gz gnunet-eaeb4e371a1ad8d3a7b3b85ad54e99afdfc106d9.zip |
sensor: minor fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_sensor_util_lib.h | 17 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor-analysis.c | 6 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor-reporting.c | 20 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor.c | 108 | ||||
-rw-r--r-- | src/sensor/sensor_util_lib.c | 179 | ||||
-rw-r--r-- | src/sensor/sensors/peerstore-memory | 4 | ||||
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 106 |
7 files changed, 232 insertions, 208 deletions
diff --git a/src/include/gnunet_sensor_util_lib.h b/src/include/gnunet_sensor_util_lib.h index 54066decb..780b88cda 100644 --- a/src/include/gnunet_sensor_util_lib.h +++ b/src/include/gnunet_sensor_util_lib.h | |||
@@ -38,7 +38,7 @@ extern "C" | |||
38 | /** | 38 | /** |
39 | * Structure containing sensor definition | 39 | * Structure containing sensor definition |
40 | */ | 40 | */ |
41 | struct SensorInfo | 41 | struct GNUNET_SENSOR_SensorInfo |
42 | { | 42 | { |
43 | 43 | ||
44 | /** | 44 | /** |
@@ -196,7 +196,7 @@ struct GNUNET_SENSOR_Reading | |||
196 | /** | 196 | /** |
197 | * Sensor this reading is related to | 197 | * Sensor this reading is related to |
198 | */ | 198 | */ |
199 | struct SensorInfo *sensor; | 199 | struct GNUNET_SENSOR_SensorInfo *sensor; |
200 | 200 | ||
201 | /** | 201 | /** |
202 | * Timestamp of taking the reading | 202 | * Timestamp of taking the reading |
@@ -257,8 +257,10 @@ struct GNUNET_SENSOR_ReadingMessage | |||
257 | uint16_t value_size; | 257 | uint16_t value_size; |
258 | 258 | ||
259 | }; | 259 | }; |
260 | |||
260 | GNUNET_NETWORK_STRUCT_END | 261 | GNUNET_NETWORK_STRUCT_END |
261 | 262 | ||
263 | |||
262 | /** | 264 | /** |
263 | * Reads sensor definitions from local data files | 265 | * Reads sensor definitions from local data files |
264 | * | 266 | * |
@@ -267,6 +269,7 @@ GNUNET_NETWORK_STRUCT_END | |||
267 | struct GNUNET_CONTAINER_MultiHashMap * | 269 | struct GNUNET_CONTAINER_MultiHashMap * |
268 | GNUNET_SENSOR_load_all_sensors (); | 270 | GNUNET_SENSOR_load_all_sensors (); |
269 | 271 | ||
272 | |||
270 | /* | 273 | /* |
271 | * Get path to the directory containing the sensor definition files | 274 | * Get path to the directory containing the sensor definition files |
272 | * | 275 | * |
@@ -275,16 +278,6 @@ GNUNET_SENSOR_load_all_sensors (); | |||
275 | char * | 278 | char * |
276 | GNUNET_SENSOR_get_sensor_dir (); | 279 | GNUNET_SENSOR_get_sensor_dir (); |
277 | 280 | ||
278 | /** | ||
279 | * Parses a sensor reading message struct | ||
280 | * | ||
281 | * @param msg message header received | ||
282 | * @param sensors multihashmap of loaded sensors | ||
283 | * @return sensor reading struct or NULL if error | ||
284 | */ | ||
285 | struct GNUNET_SENSOR_Reading * | ||
286 | GNUNET_SENSOR_parse_reading_message (const struct GNUNET_MessageHeader *msg, | ||
287 | struct GNUNET_CONTAINER_MultiHashMap *sensors); | ||
288 | 281 | ||
289 | /** | 282 | /** |
290 | * Destroys a group of sensors in a hashmap and the hashmap itself | 283 | * Destroys a group of sensors in a hashmap and the hashmap itself |
diff --git a/src/sensor/gnunet-service-sensor-analysis.c b/src/sensor/gnunet-service-sensor-analysis.c index bb0e2d505..4b99045ff 100644 --- a/src/sensor/gnunet-service-sensor-analysis.c +++ b/src/sensor/gnunet-service-sensor-analysis.c | |||
@@ -51,7 +51,7 @@ struct SensorModel | |||
51 | /* | 51 | /* |
52 | * Pointer to sensor info structure | 52 | * Pointer to sensor info structure |
53 | */ | 53 | */ |
54 | struct SensorInfo *sensor; | 54 | struct GNUNET_SENSOR_SensorInfo *sensor; |
55 | 55 | ||
56 | /* | 56 | /* |
57 | * Watcher of sensor values | 57 | * Watcher of sensor values |
@@ -190,7 +190,7 @@ sensor_watcher (void *cls, | |||
190 | * | 190 | * |
191 | * @param cls unused | 191 | * @param cls unused |
192 | * @param key unused | 192 | * @param key unused |
193 | * @param value a 'struct SensorInfo *' with sensor information | 193 | * @param value a 'struct GNUNET_SENSOR_SensorInfo *' with sensor information |
194 | * @return #GNUNET_YES to continue iterations | 194 | * @return #GNUNET_YES to continue iterations |
195 | */ | 195 | */ |
196 | static int | 196 | static int |
@@ -198,7 +198,7 @@ init_sensor_model (void *cls, | |||
198 | const struct GNUNET_HashCode *key, | 198 | const struct GNUNET_HashCode *key, |
199 | void *value) | 199 | void *value) |
200 | { | 200 | { |
201 | struct SensorInfo *sensor = value; | 201 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
202 | struct SensorModel *sensor_model; | 202 | struct SensorModel *sensor_model; |
203 | 203 | ||
204 | if (0 != strcmp("numeric", sensor->expected_datatype)) | 204 | if (0 != strcmp("numeric", sensor->expected_datatype)) |
diff --git a/src/sensor/gnunet-service-sensor-reporting.c b/src/sensor/gnunet-service-sensor-reporting.c index 2292649e2..0a422002f 100644 --- a/src/sensor/gnunet-service-sensor-reporting.c +++ b/src/sensor/gnunet-service-sensor-reporting.c | |||
@@ -57,7 +57,7 @@ struct ReportingContext | |||
57 | /** | 57 | /** |
58 | * Sensor information | 58 | * Sensor information |
59 | */ | 59 | */ |
60 | struct SensorInfo *sensor; | 60 | struct GNUNET_SENSOR_SensorInfo *sensor; |
61 | 61 | ||
62 | /** | 62 | /** |
63 | * Collection point reporting task | 63 | * Collection point reporting task |
@@ -393,7 +393,7 @@ report_collection_point (void *cls, | |||
393 | const struct GNUNET_SCHEDULER_TaskContext* tc) | 393 | const struct GNUNET_SCHEDULER_TaskContext* tc) |
394 | { | 394 | { |
395 | struct ReportingContext *rc = cls; | 395 | struct ReportingContext *rc = cls; |
396 | struct SensorInfo *sensor = rc->sensor; | 396 | struct GNUNET_SENSOR_SensorInfo *sensor = rc->sensor; |
397 | struct CadetChannelContext *cc; | 397 | struct CadetChannelContext *cc; |
398 | struct GNUNET_SENSOR_ReadingMessage *msg; | 398 | struct GNUNET_SENSOR_ReadingMessage *msg; |
399 | size_t msg_size; | 399 | size_t msg_size; |
@@ -446,8 +446,8 @@ report_collection_point (void *cls, | |||
446 | */ | 446 | */ |
447 | static int | 447 | static int |
448 | sensor_watch_cb (void *cls, | 448 | sensor_watch_cb (void *cls, |
449 | struct GNUNET_PEERSTORE_Record *record, | 449 | struct GNUNET_PEERSTORE_Record *record, |
450 | char *emsg) | 450 | char *emsg) |
451 | { | 451 | { |
452 | struct ReportingContext *rc = cls; | 452 | struct ReportingContext *rc = cls; |
453 | 453 | ||
@@ -477,15 +477,15 @@ sensor_watch_cb (void *cls, | |||
477 | * | 477 | * |
478 | * @param cls unused | 478 | * @param cls unused |
479 | * @param key unused | 479 | * @param key unused |
480 | * @param value a 'struct SensorInfo *' with sensor information | 480 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` with sensor information |
481 | * @return #GNUNET_YES to continue iterations | 481 | * @return #GNUNET_YES to continue iterations |
482 | */ | 482 | */ |
483 | static int | 483 | static int |
484 | init_sensor_reporting (void *cls, | 484 | init_sensor_reporting (void *cls, |
485 | const struct GNUNET_HashCode *key, | 485 | const struct GNUNET_HashCode *key, |
486 | void *value) | 486 | void *value) |
487 | { | 487 | { |
488 | struct SensorInfo *sensor = value; | 488 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
489 | struct ReportingContext *rc; | 489 | struct ReportingContext *rc; |
490 | 490 | ||
491 | if (NULL == sensor->collection_point && | 491 | if (NULL == sensor->collection_point && |
@@ -548,8 +548,8 @@ cadet_channel_destroyed (void *cls, | |||
548 | if (GNUNET_YES == cc->destroying) | 548 | if (GNUNET_YES == cc->destroying) |
549 | return; | 549 | return; |
550 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 550 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
551 | "Received a `channel destroyed' notification from CADET, " | 551 | "Received a `channel destroyed' notification from CADET, " |
552 | "cleaning up.\n"); | 552 | "cleaning up.\n"); |
553 | GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc); | 553 | GNUNET_CONTAINER_DLL_remove (cc_head, cc_tail, cc); |
554 | cc->c = NULL; | 554 | cc->c = NULL; |
555 | destroy_cadet_channel_context (cc); | 555 | destroy_cadet_channel_context (cc); |
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c index 261758595..794ba0b06 100644 --- a/src/sensor/gnunet-service-sensor.c +++ b/src/sensor/gnunet-service-sensor.c | |||
@@ -61,22 +61,25 @@ char *subsystem = "sensor"; | |||
61 | struct GNUNET_PeerIdentity peerid; | 61 | struct GNUNET_PeerIdentity peerid; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * Disable a sensor | 64 | * Change the state of the sensor. |
65 | * Sensor will not run again unless | 65 | * Write the change to file to make it persistent. |
66 | * explicitly enabled or reloaded | ||
67 | * | 66 | * |
68 | * @param sensor sensor information | 67 | * @param sensor sensor info struct |
68 | * @param state new enabled state: #GNUNET_YES / #GNUNET_NO | ||
69 | */ | 69 | */ |
70 | static void set_sensor_enabled(struct SensorInfo *sensor, int state) | 70 | static void |
71 | set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state) | ||
71 | { | 72 | { |
72 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 73 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
73 | "Sensor `%s': Setting enabled to %d.\n", | 74 | "Sensor `%s': Setting enabled to %d.\n", |
74 | sensor->name, state); | 75 | sensor->name, state); |
75 | sensor->enabled = GNUNET_NO; | 76 | sensor->enabled = GNUNET_NO; |
76 | GNUNET_assert(NULL != sensor->cfg); | 77 | GNUNET_assert (NULL != sensor->cfg); |
77 | GNUNET_CONFIGURATION_set_value_string(sensor->cfg, sensor->name, "ENABLED", | 78 | GNUNET_CONFIGURATION_set_value_string (sensor->cfg, |
78 | (GNUNET_YES == state)?"YES":"NO"); | 79 | sensor->name, |
79 | GNUNET_CONFIGURATION_write(sensor->cfg, sensor->def_file); | 80 | "ENABLED", |
81 | (GNUNET_YES == state) ? "YES" : "NO"); | ||
82 | GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file); | ||
80 | } | 83 | } |
81 | 84 | ||
82 | /** | 85 | /** |
@@ -87,23 +90,23 @@ static void set_sensor_enabled(struct SensorInfo *sensor, int state) | |||
87 | */ | 90 | */ |
88 | static void | 91 | static void |
89 | shutdown_task (void *cls, | 92 | shutdown_task (void *cls, |
90 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 93 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
91 | { | 94 | { |
92 | SENSOR_update_stop (); | 95 | //SENSOR_update_stop (); |
93 | SENSOR_reporting_stop(); | 96 | SENSOR_reporting_stop (); |
94 | SENSOR_analysis_stop(); | 97 | SENSOR_analysis_stop (); |
95 | GNUNET_SENSOR_destroy_sensors (sensors); | 98 | GNUNET_SENSOR_destroy_sensors (sensors); |
96 | if(NULL != statistics) | 99 | if (NULL != statistics) |
97 | { | 100 | { |
98 | GNUNET_STATISTICS_destroy(statistics, GNUNET_YES); | 101 | GNUNET_STATISTICS_destroy (statistics, GNUNET_YES); |
99 | statistics = NULL; | 102 | statistics = NULL; |
100 | } | 103 | } |
101 | if(NULL != peerstore) | 104 | if (NULL != peerstore) |
102 | { | 105 | { |
103 | GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_YES); | 106 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); |
104 | peerstore = NULL; | 107 | peerstore = NULL; |
105 | } | 108 | } |
106 | GNUNET_SCHEDULER_shutdown(); | 109 | GNUNET_SCHEDULER_shutdown (); |
107 | } | 110 | } |
108 | 111 | ||
109 | 112 | ||
@@ -115,19 +118,18 @@ shutdown_task (void *cls, | |||
115 | */ | 118 | */ |
116 | static void | 119 | static void |
117 | handle_client_disconnect (void *cls, | 120 | handle_client_disconnect (void *cls, |
118 | struct GNUNET_SERVER_Client | 121 | struct GNUNET_SERVER_Client *client) |
119 | * client) | ||
120 | { | 122 | { |
121 | } | 123 | } |
122 | 124 | ||
123 | /** | 125 | /** |
124 | * Creates a structure with basic sensor info to be sent to a client | 126 | * Creates a structure with basic sensor info to be sent to a client. |
125 | * | 127 | * |
126 | * @param sensor sensor information | 128 | * @param sensor sensor information |
127 | * @return message ready to be sent to client | 129 | * @return message ready to be sent to client |
128 | */ | 130 | */ |
129 | static struct SensorInfoMessage * | 131 | static struct SensorInfoMessage * |
130 | create_sensor_info_msg(struct SensorInfo *sensor) | 132 | create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor) |
131 | { | 133 | { |
132 | struct SensorInfoMessage *msg; | 134 | struct SensorInfoMessage *msg; |
133 | uint16_t len; | 135 | uint16_t len; |
@@ -171,14 +173,15 @@ create_sensor_info_msg(struct SensorInfo *sensor) | |||
171 | * @param message the actual message | 173 | * @param message the actual message |
172 | */ | 174 | */ |
173 | static void | 175 | static void |
174 | handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client, | 176 | handle_get_sensor (void *cls, |
175 | const struct GNUNET_MessageHeader *message) | 177 | struct GNUNET_SERVER_Client *client, |
178 | const struct GNUNET_MessageHeader *message) | ||
176 | { | 179 | { |
177 | struct GNUNET_SERVER_TransmitContext *tc; | 180 | struct GNUNET_SERVER_TransmitContext *tc; |
178 | char *sensorname; | 181 | char *sensorname; |
179 | size_t sensorname_len; | 182 | size_t sensorname_len; |
180 | struct GNUNET_HashCode key; | 183 | struct GNUNET_HashCode key; |
181 | struct SensorInfo *sensorinfo; | 184 | struct GNUNET_SENSOR_SensorInfo *sensorinfo; |
182 | struct SensorInfoMessage *msg; | 185 | struct SensorInfoMessage *msg; |
183 | 186 | ||
184 | sensorname = (char *)&message[1]; | 187 | sensorname = (char *)&message[1]; |
@@ -188,7 +191,7 @@ handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client, | |||
188 | tc = GNUNET_SERVER_transmit_context_create (client); | 191 | tc = GNUNET_SERVER_transmit_context_create (client); |
189 | GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key); | 192 | GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key); |
190 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n"); | 193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n"); |
191 | sensorinfo = (struct SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key); | 194 | sensorinfo = (struct GNUNET_SENSOR_SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key); |
192 | if(NULL != sensorinfo) | 195 | if(NULL != sensorinfo) |
193 | { | 196 | { |
194 | msg = create_sensor_info_msg(sensorinfo); | 197 | msg = create_sensor_info_msg(sensorinfo); |
@@ -205,15 +208,16 @@ handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client, | |||
205 | /** | 208 | /** |
206 | * Iterator for sensors and adds them to transmit context | 209 | * Iterator for sensors and adds them to transmit context |
207 | * | 210 | * |
208 | * @param cls a 'struct GNUNET_SERVER_TransmitContext *' | 211 | * @param cls a `struct GNUNET_SERVER_TransmitContext *` |
209 | * @param key hash of sensor name, key to hashmap | 212 | * @param key hash of sensor name, key to hashmap |
210 | * @param value a 'struct SensorInfo *' | 213 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` |
211 | */ | 214 | */ |
212 | int add_sensor_to_tc(void *cls, | 215 | int add_sensor_to_tc (void *cls, |
213 | const struct GNUNET_HashCode *key, void *value) | 216 | const struct GNUNET_HashCode *key, |
217 | void *value) | ||
214 | { | 218 | { |
215 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 219 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
216 | struct SensorInfo *sensorinfo = value; | 220 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; |
217 | struct SensorInfoMessage *msg; | 221 | struct SensorInfoMessage *msg; |
218 | 222 | ||
219 | msg = create_sensor_info_msg(sensorinfo); | 223 | msg = create_sensor_info_msg(sensorinfo); |
@@ -251,7 +255,7 @@ handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client, | |||
251 | * @return #GNUNET_YES / #GNUNET_NO | 255 | * @return #GNUNET_YES / #GNUNET_NO |
252 | */ | 256 | */ |
253 | static int | 257 | static int |
254 | should_run_sensor(struct SensorInfo *sensorinfo) | 258 | should_run_sensor(struct GNUNET_SENSOR_SensorInfo *sensorinfo) |
255 | { | 259 | { |
256 | struct GNUNET_TIME_Absolute now; | 260 | struct GNUNET_TIME_Absolute now; |
257 | 261 | ||
@@ -280,7 +284,7 @@ should_run_sensor(struct SensorInfo *sensorinfo) | |||
280 | /** | 284 | /** |
281 | * Callback function to process statistic values | 285 | * Callback function to process statistic values |
282 | * | 286 | * |
283 | * @param cls 'struct SensorInfo *' | 287 | * @param cls `struct GNUNET_SENSOR_SensorInfo *` |
284 | * @param subsystem name of subsystem that created the statistic | 288 | * @param subsystem name of subsystem that created the statistic |
285 | * @param name the name of the datum | 289 | * @param name the name of the datum |
286 | * @param value the current value | 290 | * @param value the current value |
@@ -293,7 +297,7 @@ int sensor_statistics_iterator (void *cls, | |||
293 | uint64_t value, | 297 | uint64_t value, |
294 | int is_persistent) | 298 | int is_persistent) |
295 | { | 299 | { |
296 | struct SensorInfo *sensorinfo = cls; | 300 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
297 | double dvalue = (double)value; | 301 | double dvalue = (double)value; |
298 | struct GNUNET_TIME_Absolute expiry; | 302 | struct GNUNET_TIME_Absolute expiry; |
299 | 303 | ||
@@ -315,13 +319,13 @@ int sensor_statistics_iterator (void *cls, | |||
315 | /** | 319 | /** |
316 | * Continuation called after sensor gets all gnunet statistics values | 320 | * Continuation called after sensor gets all gnunet statistics values |
317 | * | 321 | * |
318 | * @param cls 'struct SensorInfo *' | 322 | * @param cls `struct GNUNET_SENSOR_SensorInfo *` |
319 | * @param success #GNUNET_OK if statistics were | 323 | * @param success #GNUNET_OK if statistics were |
320 | * successfully obtained, #GNUNET_SYSERR if not. | 324 | * successfully obtained, #GNUNET_SYSERR if not. |
321 | */ | 325 | */ |
322 | void end_sensor_run_stat (void *cls, int success) | 326 | void end_sensor_run_stat (void *cls, int success) |
323 | { | 327 | { |
324 | struct SensorInfo *sensorinfo = cls; | 328 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
325 | 329 | ||
326 | sensorinfo->gnunet_stat_get_handle = NULL; | 330 | sensorinfo->gnunet_stat_get_handle = NULL; |
327 | sensorinfo->running = GNUNET_NO; | 331 | sensorinfo->running = GNUNET_NO; |
@@ -337,7 +341,9 @@ void end_sensor_run_stat (void *cls, int success) | |||
337 | * @return size of new parsed value, 0 for error | 341 | * @return size of new parsed value, 0 for error |
338 | */ | 342 | */ |
339 | static size_t | 343 | static size_t |
340 | parse_sensor_value (const char *value, struct SensorInfo* sensor, void **ret) | 344 | parse_sensor_value (const char *value, |
345 | struct GNUNET_SENSOR_SensorInfo *sensor, | ||
346 | void **ret) | ||
341 | { | 347 | { |
342 | double *dval; | 348 | double *dval; |
343 | char *endptr; | 349 | char *endptr; |
@@ -367,12 +373,12 @@ parse_sensor_value (const char *value, struct SensorInfo* sensor, void **ret) | |||
367 | /** | 373 | /** |
368 | * Callback for output of executed sensor process | 374 | * Callback for output of executed sensor process |
369 | * | 375 | * |
370 | * @param cls 'struct SensorInfo *' | 376 | * @param cls `struct GNUNET_SENSOR_SensorInfo *` |
371 | * @param line line of output from a command, NULL for the end | 377 | * @param line line of output from a command, NULL for the end |
372 | */ | 378 | */ |
373 | void sensor_process_callback (void *cls, const char *line) | 379 | void sensor_process_callback (void *cls, const char *line) |
374 | { | 380 | { |
375 | struct SensorInfo *sensorinfo = cls; | 381 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
376 | void *value; | 382 | void *value; |
377 | size_t valsize; | 383 | size_t valsize; |
378 | struct GNUNET_TIME_Absolute expiry; | 384 | struct GNUNET_TIME_Absolute expiry; |
@@ -443,7 +449,7 @@ void | |||
443 | sensor_run (void *cls, | 449 | sensor_run (void *cls, |
444 | const struct GNUNET_SCHEDULER_TaskContext * tc) | 450 | const struct GNUNET_SCHEDULER_TaskContext * tc) |
445 | { | 451 | { |
446 | struct SensorInfo *sensorinfo = cls; | 452 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
447 | int check_result; | 453 | int check_result; |
448 | char *sensors_dir; | 454 | char *sensors_dir; |
449 | char *process_path; | 455 | char *process_path; |
@@ -530,7 +536,7 @@ sensor_run (void *cls, | |||
530 | * | 536 | * |
531 | * @param cls unused | 537 | * @param cls unused |
532 | * @param key hash of sensor name, key to hashmap (unused) | 538 | * @param key hash of sensor name, key to hashmap (unused) |
533 | * @param value a 'struct SensorInfo *' | 539 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` |
534 | * @return #GNUNET_YES if we should continue to | 540 | * @return #GNUNET_YES if we should continue to |
535 | * iterate, | 541 | * iterate, |
536 | * #GNUNET_NO if not. | 542 | * #GNUNET_NO if not. |
@@ -538,7 +544,7 @@ sensor_run (void *cls, | |||
538 | int schedule_sensor(void *cls, | 544 | int schedule_sensor(void *cls, |
539 | const struct GNUNET_HashCode *key, void *value) | 545 | const struct GNUNET_HashCode *key, void *value) |
540 | { | 546 | { |
541 | struct SensorInfo *sensorinfo = value; | 547 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = value; |
542 | 548 | ||
543 | if(GNUNET_NO == should_run_sensor(sensorinfo)) | 549 | if(GNUNET_NO == should_run_sensor(sensorinfo)) |
544 | return GNUNET_YES; | 550 | return GNUNET_YES; |
@@ -589,17 +595,17 @@ run (void *cls, | |||
589 | schedule_all_sensors(); | 595 | schedule_all_sensors(); |
590 | SENSOR_analysis_start(c, sensors); | 596 | SENSOR_analysis_start(c, sensors); |
591 | SENSOR_reporting_start(c, sensors); | 597 | SENSOR_reporting_start(c, sensors); |
592 | SENSOR_update_start (c, sensors); | 598 | //SENSOR_update_start (c, sensors); |
593 | statistics = GNUNET_STATISTICS_create("sensor", cfg); | 599 | statistics = GNUNET_STATISTICS_create("sensor", cfg); |
594 | GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); | 600 | GNUNET_CRYPTO_get_peer_identity(cfg, &peerid); |
595 | peerstore = GNUNET_PEERSTORE_connect(cfg); | 601 | peerstore = GNUNET_PEERSTORE_connect(cfg); |
596 | GNUNET_SERVER_add_handlers (server, handlers); | 602 | GNUNET_SERVER_add_handlers (server, handlers); |
597 | GNUNET_SERVER_disconnect_notify (server, | 603 | GNUNET_SERVER_disconnect_notify (server, |
598 | &handle_client_disconnect, | 604 | &handle_client_disconnect, |
599 | NULL); | 605 | NULL); |
600 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 606 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
601 | &shutdown_task, | 607 | &shutdown_task, |
602 | NULL); | 608 | NULL); |
603 | } | 609 | } |
604 | 610 | ||
605 | 611 | ||
@@ -617,8 +623,8 @@ main (int argc, char *const *argv) | |||
617 | GNUNET_SERVICE_run (argc, | 623 | GNUNET_SERVICE_run (argc, |
618 | argv, | 624 | argv, |
619 | "sensor", | 625 | "sensor", |
620 | GNUNET_SERVICE_OPTION_NONE, | 626 | GNUNET_SERVICE_OPTION_NONE, |
621 | &run, NULL)) ? 0 : 1; | 627 | &run, NULL)) ? 0 : 1; |
622 | } | 628 | } |
623 | 629 | ||
624 | /* end of gnunet-service-sensor.c */ | 630 | /* end of gnunet-service-sensor.c */ |
diff --git a/src/sensor/sensor_util_lib.c b/src/sensor/sensor_util_lib.c index 40cdfef30..b77ba48fc 100644 --- a/src/sensor/sensor_util_lib.c +++ b/src/sensor/sensor_util_lib.c | |||
@@ -87,10 +87,10 @@ version_parse(char *version, uint16_t *major, uint16_t *minor) | |||
87 | * @param cfg configuration handle | 87 | * @param cfg configuration handle |
88 | * @param sectionname configuration section containing definition | 88 | * @param sectionname configuration section containing definition |
89 | */ | 89 | */ |
90 | static struct SensorInfo * | 90 | static struct GNUNET_SENSOR_SensorInfo * |
91 | load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectionname) | 91 | load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectionname) |
92 | { | 92 | { |
93 | struct SensorInfo *sensor; | 93 | struct GNUNET_SENSOR_SensorInfo *sensor; |
94 | char *version_str; | 94 | char *version_str; |
95 | char *starttime_str; | 95 | char *starttime_str; |
96 | char *endtime_str; | 96 | char *endtime_str; |
@@ -98,7 +98,7 @@ load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectio | |||
98 | char *dummy; | 98 | char *dummy; |
99 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | 99 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; |
100 | 100 | ||
101 | sensor = GNUNET_new(struct SensorInfo); | 101 | sensor = GNUNET_new(struct GNUNET_SENSOR_SensorInfo); |
102 | //name | 102 | //name |
103 | sensor->name = GNUNET_strdup(sectionname); | 103 | sensor->name = GNUNET_strdup(sectionname); |
104 | //version | 104 | //version |
@@ -260,12 +260,12 @@ load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectio | |||
260 | * | 260 | * |
261 | * @param filename full path to file containing sensor definition | 261 | * @param filename full path to file containing sensor definition |
262 | */ | 262 | */ |
263 | static struct SensorInfo * | 263 | static struct GNUNET_SENSOR_SensorInfo * |
264 | load_sensor_from_file(const char *filename) | 264 | load_sensor_from_file(const char *filename) |
265 | { | 265 | { |
266 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; | 266 | struct GNUNET_CONFIGURATION_Handle *sensorcfg; |
267 | const char *filebasename; | 267 | const char *filebasename; |
268 | struct SensorInfo *sensor; | 268 | struct GNUNET_SENSOR_SensorInfo *sensor; |
269 | 269 | ||
270 | //test file | 270 | //test file |
271 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) | 271 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) |
@@ -303,9 +303,10 @@ load_sensor_from_file(const char *filename) | |||
303 | * @return 1: s1 > s2, 0: s1 == s2, -1: s1 < s2 | 303 | * @return 1: s1 > s2, 0: s1 == s2, -1: s1 < s2 |
304 | */ | 304 | */ |
305 | static int | 305 | static int |
306 | sensor_version_compare(struct SensorInfo *s1, struct SensorInfo *s2) | 306 | sensor_version_compare (struct GNUNET_SENSOR_SensorInfo *s1, |
307 | struct GNUNET_SENSOR_SensorInfo *s2) | ||
307 | { | 308 | { |
308 | if(s1->version_major == s2->version_major) | 309 | if (s1->version_major == s2->version_major) |
309 | return (s1->version_minor < s2->version_minor) ? -1 : (s1->version_minor > s2->version_minor); | 310 | return (s1->version_minor < s2->version_minor) ? -1 : (s1->version_minor > s2->version_minor); |
310 | else | 311 | else |
311 | return (s1->version_major < s2->version_major) ? -1 : (s1->version_major > s2->version_major); | 312 | return (s1->version_major < s2->version_major) ? -1 : (s1->version_major > s2->version_major); |
@@ -317,13 +318,15 @@ sensor_version_compare(struct SensorInfo *s1, struct SensorInfo *s2) | |||
317 | * | 318 | * |
318 | * @param sensor Sensor structure to add | 319 | * @param sensor Sensor structure to add |
319 | * @param map Hashmap to add to | 320 | * @param map Hashmap to add to |
320 | * @return #GNUNET_YES if added, #GNUNET_NO if not added which is not necessarily an error | 321 | * @return #GNUNET_YES if added |
322 | * #GNUNET_NO if not added which is not necessarily an error | ||
321 | */ | 323 | */ |
322 | static int | 324 | static int |
323 | add_sensor_to_hashmap(struct SensorInfo *sensor, struct GNUNET_CONTAINER_MultiHashMap *map) | 325 | add_sensor_to_hashmap (struct GNUNET_SENSOR_SensorInfo *sensor, |
326 | struct GNUNET_CONTAINER_MultiHashMap *map) | ||
324 | { | 327 | { |
325 | struct GNUNET_HashCode key; | 328 | struct GNUNET_HashCode key; |
326 | struct SensorInfo *existing; | 329 | struct GNUNET_SENSOR_SensorInfo *existing; |
327 | 330 | ||
328 | GNUNET_CRYPTO_hash(sensor->name, strlen(sensor->name) + 1, &key); | 331 | GNUNET_CRYPTO_hash(sensor->name, strlen(sensor->name) + 1, &key); |
329 | existing = GNUNET_CONTAINER_multihashmap_get(map, &key); | 332 | existing = GNUNET_CONTAINER_multihashmap_get(map, &key); |
@@ -331,19 +334,25 @@ add_sensor_to_hashmap(struct SensorInfo *sensor, struct GNUNET_CONTAINER_MultiHa | |||
331 | { | 334 | { |
332 | if(sensor_version_compare(existing, sensor) >= 0) //same or newer version already exist | 335 | if(sensor_version_compare(existing, sensor) >= 0) //same or newer version already exist |
333 | { | 336 | { |
334 | LOG (GNUNET_ERROR_TYPE_INFO, _("Sensor `%s' already exists with same or newer version\n"), sensor->name); | 337 | LOG (GNUNET_ERROR_TYPE_INFO, |
338 | _("Sensor `%s' already exists with same or newer version\n"), | ||
339 | sensor->name); | ||
335 | return GNUNET_NO; | 340 | return GNUNET_NO; |
336 | } | 341 | } |
337 | else | 342 | else |
338 | { | 343 | { |
339 | GNUNET_CONTAINER_multihashmap_remove(map, &key, existing); //remove the old version | 344 | GNUNET_CONTAINER_multihashmap_remove(map, &key, existing); //remove the old version |
340 | GNUNET_free(existing); | 345 | GNUNET_free(existing); |
341 | LOG (GNUNET_ERROR_TYPE_INFO, "Upgrading sensor `%s' to a newer version\n", sensor->name); | 346 | LOG (GNUNET_ERROR_TYPE_INFO, |
347 | "Upgrading sensor `%s' to a newer version\n", | ||
348 | sensor->name); | ||
342 | } | 349 | } |
343 | } | 350 | } |
344 | if(GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(map, &key, sensor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 351 | if(GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(map, &key, sensor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
345 | { | 352 | { |
346 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Error adding new sensor `%s' to global hashmap, this should not happen\n"), sensor->name); | 353 | LOG (GNUNET_ERROR_TYPE_ERROR, |
354 | _("Error adding new sensor `%s' to global hashmap.\n"), | ||
355 | sensor->name); | ||
347 | return GNUNET_NO; | 356 | return GNUNET_NO; |
348 | } | 357 | } |
349 | 358 | ||
@@ -361,7 +370,7 @@ static int | |||
361 | reload_sensors_dir_cb(void *cls, const char *filename) | 370 | reload_sensors_dir_cb(void *cls, const char *filename) |
362 | { | 371 | { |
363 | struct GNUNET_CONTAINER_MultiHashMap *sensors = cls; | 372 | struct GNUNET_CONTAINER_MultiHashMap *sensors = cls; |
364 | struct SensorInfo *sensor; | 373 | struct GNUNET_SENSOR_SensorInfo *sensor; |
365 | 374 | ||
366 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) | 375 | if(GNUNET_YES != GNUNET_DISK_file_test(filename)) |
367 | return GNUNET_OK; | 376 | return GNUNET_OK; |
@@ -423,131 +432,61 @@ GNUNET_SENSOR_load_all_sensors () | |||
423 | return sensors; | 432 | return sensors; |
424 | } | 433 | } |
425 | 434 | ||
426 | /** | ||
427 | * Parses a sensor reading message struct | ||
428 | * | ||
429 | * @param msg message header received | ||
430 | * @param sensors multihashmap of loaded sensors | ||
431 | * @return sensor reading struct or NULL if error | ||
432 | */ | ||
433 | struct GNUNET_SENSOR_Reading * | ||
434 | GNUNET_SENSOR_parse_reading_message (const struct GNUNET_MessageHeader *msg, | ||
435 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | ||
436 | { | ||
437 | uint16_t msg_size; | ||
438 | struct GNUNET_SENSOR_ReadingMessage *rm; | ||
439 | uint16_t sensorname_size; | ||
440 | uint16_t value_size; | ||
441 | void *dummy; | ||
442 | char *sensorname; | ||
443 | struct GNUNET_HashCode key; | ||
444 | struct SensorInfo *sensor; | ||
445 | struct GNUNET_SENSOR_Reading *reading; | ||
446 | |||
447 | msg_size = ntohs (msg->size); | ||
448 | if (msg_size < sizeof (struct GNUNET_SENSOR_ReadingMessage)) | ||
449 | { | ||
450 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | ||
451 | return NULL; | ||
452 | } | ||
453 | rm = (struct GNUNET_SENSOR_ReadingMessage *)msg; | ||
454 | sensorname_size = ntohs (rm->sensorname_size); | ||
455 | value_size = ntohs (rm->value_size); | ||
456 | if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) | ||
457 | + sensorname_size + value_size) != msg_size) | ||
458 | { | ||
459 | LOG (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | ||
460 | return NULL; | ||
461 | } | ||
462 | dummy = &rm[1]; | ||
463 | sensorname = GNUNET_malloc (sensorname_size); | ||
464 | memcpy (sensorname, dummy, sensorname_size); | ||
465 | GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key); | ||
466 | GNUNET_free (sensorname); | ||
467 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); | ||
468 | if (NULL == sensor) | ||
469 | { | ||
470 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
471 | "Unknown sensor name in reading message.\n"); | ||
472 | return NULL; | ||
473 | } | ||
474 | if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || | ||
475 | (sensor->version_major != ntohs (rm->sensorversion_major))) | ||
476 | { | ||
477 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
478 | "Sensor version mismatch in reading message.\n"); | ||
479 | return NULL; | ||
480 | } | ||
481 | if (0 == strcmp (sensor->expected_datatype, "numeric") && | ||
482 | sizeof (double) != value_size) | ||
483 | { | ||
484 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
485 | "Invalid value size for a numerical sensor.\n"); | ||
486 | return NULL; | ||
487 | } | ||
488 | reading = GNUNET_new (struct GNUNET_SENSOR_Reading); | ||
489 | reading->sensor = sensor; | ||
490 | reading->timestamp = GNUNET_be64toh (rm->timestamp); | ||
491 | reading->value_size = value_size; | ||
492 | reading->value = GNUNET_malloc (value_size); | ||
493 | dummy += sensorname_size; | ||
494 | memcpy (reading->value, dummy, value_size); | ||
495 | return reading; | ||
496 | } | ||
497 | 435 | ||
498 | /** | 436 | /** |
499 | * Remove sensor execution from scheduler | 437 | * Remove sensor execution from scheduler |
500 | * | 438 | * |
501 | * @param cls unused | 439 | * @param cls unused |
502 | * @param key hash of sensor name, key to hashmap | 440 | * @param key hash of sensor name, key to hashmap |
503 | * @param value a 'struct SensorInfo *' | 441 | * @param value a `struct GNUNET_SENSOR_SensorInfo *` |
504 | * @return #GNUNET_YES if we should continue to | 442 | * @return #GNUNET_YES if we should continue to |
505 | * iterate, | 443 | * iterate, |
506 | * #GNUNET_NO if not. | 444 | * #GNUNET_NO if not. |
507 | */ | 445 | */ |
508 | static int destroy_sensor(void *cls, | 446 | static int destroy_sensor(void *cls, |
509 | const struct GNUNET_HashCode *key, void *value) | 447 | const struct GNUNET_HashCode *key, |
448 | void *value) | ||
510 | { | 449 | { |
511 | struct SensorInfo *sensorinfo = value; | 450 | struct GNUNET_SENSOR_SensorInfo *sensor = value; |
512 | 451 | ||
513 | if(GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task) | 452 | if(GNUNET_SCHEDULER_NO_TASK != sensor->execution_task) |
514 | { | 453 | { |
515 | GNUNET_SCHEDULER_cancel(sensorinfo->execution_task); | 454 | GNUNET_SCHEDULER_cancel(sensor->execution_task); |
516 | sensorinfo->execution_task = GNUNET_SCHEDULER_NO_TASK; | 455 | sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; |
517 | } | 456 | } |
518 | if(NULL != sensorinfo->gnunet_stat_get_handle) | 457 | if(NULL != sensor->gnunet_stat_get_handle) |
519 | { | 458 | { |
520 | GNUNET_STATISTICS_get_cancel(sensorinfo->gnunet_stat_get_handle); | 459 | GNUNET_STATISTICS_get_cancel(sensor->gnunet_stat_get_handle); |
521 | sensorinfo->gnunet_stat_get_handle = NULL; | 460 | sensor->gnunet_stat_get_handle = NULL; |
522 | } | 461 | } |
523 | if(NULL != sensorinfo->ext_cmd) | 462 | if(NULL != sensor->ext_cmd) |
524 | { | 463 | { |
525 | GNUNET_OS_command_stop(sensorinfo->ext_cmd); | 464 | GNUNET_OS_command_stop(sensor->ext_cmd); |
526 | sensorinfo->ext_cmd = NULL; | 465 | sensor->ext_cmd = NULL; |
527 | } | 466 | } |
528 | if(NULL != sensorinfo->cfg) | 467 | if(NULL != sensor->cfg) |
529 | GNUNET_CONFIGURATION_destroy(sensorinfo->cfg); | 468 | GNUNET_CONFIGURATION_destroy(sensor->cfg); |
530 | if(NULL != sensorinfo->name) | 469 | if(NULL != sensor->name) |
531 | GNUNET_free(sensorinfo->name); | 470 | GNUNET_free (sensor->name); |
532 | if(NULL != sensorinfo->def_file) | 471 | if(NULL != sensor->def_file) |
533 | GNUNET_free(sensorinfo->def_file); | 472 | GNUNET_free (sensor->def_file); |
534 | if(NULL != sensorinfo->description) | 473 | if(NULL != sensor->description) |
535 | GNUNET_free(sensorinfo->description); | 474 | GNUNET_free (sensor->description); |
536 | if(NULL != sensorinfo->category) | 475 | if(NULL != sensor->category) |
537 | GNUNET_free(sensorinfo->category); | 476 | GNUNET_free (sensor->category); |
538 | if(NULL != sensorinfo->capabilities) | 477 | if(NULL != sensor->capabilities) |
539 | GNUNET_free(sensorinfo->capabilities); | 478 | GNUNET_free (sensor->capabilities); |
540 | if(NULL != sensorinfo->gnunet_stat_service) | 479 | if(NULL != sensor->gnunet_stat_service) |
541 | GNUNET_free(sensorinfo->gnunet_stat_service); | 480 | GNUNET_free (sensor->gnunet_stat_service); |
542 | if(NULL != sensorinfo->gnunet_stat_name) | 481 | if(NULL != sensor->gnunet_stat_name) |
543 | GNUNET_free(sensorinfo->gnunet_stat_name); | 482 | GNUNET_free (sensor->gnunet_stat_name); |
544 | if(NULL != sensorinfo->ext_process) | 483 | if(NULL != sensor->ext_process) |
545 | GNUNET_free(sensorinfo->ext_process); | 484 | GNUNET_free (sensor->ext_process); |
546 | if(NULL != sensorinfo->ext_args) | 485 | if(NULL != sensor->ext_args) |
547 | GNUNET_free(sensorinfo->ext_args); | 486 | GNUNET_free (sensor->ext_args); |
548 | if (NULL != sensorinfo->collection_point) | 487 | if (NULL != sensor->collection_point) |
549 | GNUNET_free (sensorinfo->collection_point); | 488 | GNUNET_free (sensor->collection_point); |
550 | GNUNET_free(sensorinfo); | 489 | GNUNET_free (sensor); |
551 | return GNUNET_YES; | 490 | return GNUNET_YES; |
552 | } | 491 | } |
553 | 492 | ||
diff --git a/src/sensor/sensors/peerstore-memory b/src/sensor/sensors/peerstore-memory index 814e73d8d..380fe0cec 100644 --- a/src/sensor/sensors/peerstore-memory +++ b/src/sensor/sensors/peerstore-memory | |||
@@ -25,8 +25,8 @@ EXT_PROCESS = peerstore-memory.sh | |||
25 | EXPECTED_DATATYPE = numeric | 25 | EXPECTED_DATATYPE = numeric |
26 | 26 | ||
27 | # Reporting mechanism | 27 | # Reporting mechanism |
28 | #COLLECTION_POINT = NCEKA096482PC84GFTG61EHAVXY3BQDTPB5FANATQD5CDADJ2HP0 | 28 | COLLECTION_POINT = NCEKA096482PC84GFTG61EHAVXY3BQDTPB5FANATQD5CDADJ2HP0 |
29 | #COLLECTION_INTERVAL = 7200 | 29 | COLLECTION_INTERVAL = 61 |
30 | 30 | ||
31 | P2P_REPORT = NO | 31 | P2P_REPORT = NO |
32 | #P2P_INTERVAL = | 32 | #P2P_INTERVAL = |
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 26cc421fc..5cec7e636 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -59,6 +59,11 @@ struct ClientPeerContext | |||
59 | */ | 59 | */ |
60 | struct GNUNET_CADET_Channel *ch; | 60 | struct GNUNET_CADET_Channel *ch; |
61 | 61 | ||
62 | /** | ||
63 | * Are we in the process of destroying this context? | ||
64 | */ | ||
65 | int destroying; | ||
66 | |||
62 | }; | 67 | }; |
63 | 68 | ||
64 | 69 | ||
@@ -101,6 +106,7 @@ static struct ClientPeerContext *cp_tail; | |||
101 | static void | 106 | static void |
102 | destroy_clientpeer (struct ClientPeerContext *cp) | 107 | destroy_clientpeer (struct ClientPeerContext *cp) |
103 | { | 108 | { |
109 | cp->destroying = GNUNET_YES; | ||
104 | if (NULL != cp->ch) | 110 | if (NULL != cp->ch) |
105 | { | 111 | { |
106 | GNUNET_CADET_channel_destroy (cp->ch); | 112 | GNUNET_CADET_channel_destroy (cp->ch); |
@@ -109,6 +115,7 @@ destroy_clientpeer (struct ClientPeerContext *cp) | |||
109 | GNUNET_free (cp); | 115 | GNUNET_free (cp); |
110 | } | 116 | } |
111 | 117 | ||
118 | |||
112 | /** | 119 | /** |
113 | * Task run during shutdown. | 120 | * Task run during shutdown. |
114 | * | 121 | * |
@@ -138,9 +145,10 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
138 | peerstore = NULL; | 145 | peerstore = NULL; |
139 | } | 146 | } |
140 | GNUNET_SENSOR_destroy_sensors (sensors); | 147 | GNUNET_SENSOR_destroy_sensors (sensors); |
141 | GNUNET_SCHEDULER_shutdown(); | 148 | GNUNET_SCHEDULER_shutdown (); |
142 | } | 149 | } |
143 | 150 | ||
151 | |||
144 | /** | 152 | /** |
145 | * Function called whenever a channel is destroyed. Should clean up | 153 | * Function called whenever a channel is destroyed. Should clean up |
146 | * any associated state. | 154 | * any associated state. |
@@ -159,11 +167,14 @@ cadet_channel_destroyed (void *cls, | |||
159 | { | 167 | { |
160 | struct ClientPeerContext *cp = channel_ctx; | 168 | struct ClientPeerContext *cp = channel_ctx; |
161 | 169 | ||
170 | if (GNUNET_YES == cp->destroying) | ||
171 | return; | ||
162 | cp->ch = NULL; | 172 | cp->ch = NULL; |
163 | GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp); | 173 | GNUNET_CONTAINER_DLL_remove (cp_head, cp_tail, cp); |
164 | destroy_clientpeer (cp); | 174 | destroy_clientpeer (cp); |
165 | } | 175 | } |
166 | 176 | ||
177 | |||
167 | /** | 178 | /** |
168 | * Method called whenever another peer has added us to a channel | 179 | * Method called whenever another peer has added us to a channel |
169 | * the other peer initiated. | 180 | * the other peer initiated. |
@@ -193,10 +204,85 @@ cadet_channel_created (void *cls, | |||
193 | cp = GNUNET_new (struct ClientPeerContext); | 204 | cp = GNUNET_new (struct ClientPeerContext); |
194 | cp->peerid = *initiator; | 205 | cp->peerid = *initiator; |
195 | cp->ch = channel; | 206 | cp->ch = channel; |
207 | cp->destroying = GNUNET_NO; | ||
196 | GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp); | 208 | GNUNET_CONTAINER_DLL_insert (cp_head, cp_tail, cp); |
197 | return cp; | 209 | return cp; |
198 | } | 210 | } |
199 | 211 | ||
212 | |||
213 | /** | ||
214 | * Parses a sensor reading message struct | ||
215 | * | ||
216 | * @param msg message header received | ||
217 | * @param sensors multihashmap of loaded sensors | ||
218 | * @return sensor reading struct or NULL if error | ||
219 | */ | ||
220 | static struct GNUNET_SENSOR_Reading * | ||
221 | parse_reading_message (const struct GNUNET_MessageHeader *msg, | ||
222 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | ||
223 | { | ||
224 | uint16_t msg_size; | ||
225 | struct GNUNET_SENSOR_ReadingMessage *rm; | ||
226 | uint16_t sensorname_size; | ||
227 | uint16_t value_size; | ||
228 | void *dummy; | ||
229 | char *sensorname; | ||
230 | struct GNUNET_HashCode key; | ||
231 | struct GNUNET_SENSOR_SensorInfo *sensor; | ||
232 | struct GNUNET_SENSOR_Reading *reading; | ||
233 | |||
234 | msg_size = ntohs (msg->size); | ||
235 | if (msg_size < sizeof (struct GNUNET_SENSOR_ReadingMessage)) | ||
236 | { | ||
237 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | ||
238 | return NULL; | ||
239 | } | ||
240 | rm = (struct GNUNET_SENSOR_ReadingMessage *)msg; | ||
241 | sensorname_size = ntohs (rm->sensorname_size); | ||
242 | value_size = ntohs (rm->value_size); | ||
243 | if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) | ||
244 | + sensorname_size + value_size) != msg_size) | ||
245 | { | ||
246 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | ||
247 | return NULL; | ||
248 | } | ||
249 | dummy = &rm[1]; | ||
250 | sensorname = GNUNET_malloc (sensorname_size); | ||
251 | memcpy (sensorname, dummy, sensorname_size); | ||
252 | GNUNET_CRYPTO_hash(sensorname, sensorname_size, &key); | ||
253 | GNUNET_free (sensorname); | ||
254 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); | ||
255 | if (NULL == sensor) | ||
256 | { | ||
257 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
258 | "Unknown sensor name in reading message.\n"); | ||
259 | return NULL; | ||
260 | } | ||
261 | if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || | ||
262 | (sensor->version_major != ntohs (rm->sensorversion_major))) | ||
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
265 | "Sensor version mismatch in reading message.\n"); | ||
266 | return NULL; | ||
267 | } | ||
268 | if (0 == strcmp (sensor->expected_datatype, "numeric") && | ||
269 | sizeof (double) != value_size) | ||
270 | { | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
272 | "Invalid value size for a numerical sensor.\n"); | ||
273 | return NULL; | ||
274 | } | ||
275 | reading = GNUNET_new (struct GNUNET_SENSOR_Reading); | ||
276 | reading->sensor = sensor; | ||
277 | reading->timestamp = GNUNET_be64toh (rm->timestamp); | ||
278 | reading->value_size = value_size; | ||
279 | reading->value = GNUNET_malloc (value_size); | ||
280 | dummy += sensorname_size; | ||
281 | memcpy (reading->value, dummy, value_size); | ||
282 | return reading; | ||
283 | } | ||
284 | |||
285 | |||
200 | /** | 286 | /** |
201 | * Called with any sensor reading messages received from CADET. | 287 | * Called with any sensor reading messages received from CADET. |
202 | * | 288 | * |
@@ -217,15 +303,15 @@ handle_sensor_reading (void *cls, | |||
217 | void **channel_ctx, | 303 | void **channel_ctx, |
218 | const struct GNUNET_MessageHeader *message) | 304 | const struct GNUNET_MessageHeader *message) |
219 | { | 305 | { |
220 | struct GNUNET_PeerIdentity *peer = *channel_ctx; | 306 | struct ClientPeerContext *cp = *channel_ctx; |
221 | struct GNUNET_SENSOR_Reading *reading; | 307 | struct GNUNET_SENSOR_Reading *reading; |
222 | 308 | ||
223 | reading = GNUNET_SENSOR_parse_reading_message (message, sensors); | 309 | reading = parse_reading_message (message, sensors); |
224 | if (NULL == reading) | 310 | if (NULL == reading) |
225 | { | 311 | { |
226 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 312 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
227 | "Received an invalid sensor reading from peer `%s'\n", | 313 | "Received an invalid sensor reading from peer `%s'\n", |
228 | GNUNET_i2s (peer)); | 314 | GNUNET_i2s (&cp->peerid)); |
229 | return GNUNET_SYSERR; | 315 | return GNUNET_SYSERR; |
230 | } | 316 | } |
231 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -233,13 +319,13 @@ handle_sensor_reading (void *cls, | |||
233 | "# Sensor name: `%s'\n" | 319 | "# Sensor name: `%s'\n" |
234 | "# Timestamp: %" PRIu64 "\n" | 320 | "# Timestamp: %" PRIu64 "\n" |
235 | "# Value size: %" PRIu64 ".\n", | 321 | "# Value size: %" PRIu64 ".\n", |
236 | GNUNET_i2s (peer), | 322 | GNUNET_i2s (&cp->peerid), |
237 | reading->sensor->name, | 323 | reading->sensor->name, |
238 | reading->timestamp, | 324 | reading->timestamp, |
239 | reading->value_size); | 325 | reading->value_size); |
240 | GNUNET_PEERSTORE_store (peerstore, subsystem, peer, reading->sensor->name, | 326 | GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid, |
241 | reading->value, reading->value_size, | 327 | reading->sensor->name, reading->value, |
242 | GNUNET_TIME_UNIT_FOREVER_ABS, | 328 | reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, |
243 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); | 329 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
244 | GNUNET_free (reading->value); | 330 | GNUNET_free (reading->value); |
245 | GNUNET_free (reading); | 331 | GNUNET_free (reading); |
@@ -286,7 +372,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
286 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 372 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
287 | { | 373 | { |
288 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 374 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { |
289 | {NULL, NULL, 0, 0} | 375 | {NULL, NULL, 0, 0} |
290 | }; | 376 | }; |
291 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { | 377 | static struct GNUNET_CADET_MessageHandler cadet_handlers[] = { |
292 | {&handle_sensor_reading, | 378 | {&handle_sensor_reading, |
@@ -309,7 +395,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
309 | &cadet_channel_destroyed, | 395 | &cadet_channel_destroyed, |
310 | cadet_handlers, | 396 | cadet_handlers, |
311 | cadet_ports); | 397 | cadet_ports); |
312 | if(NULL == cadet) | 398 | if (NULL == cadet) |
313 | { | 399 | { |
314 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 400 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
315 | _("Failed to connect to `%s' service.\n"), "CADET"); | 401 | _("Failed to connect to `%s' service.\n"), "CADET"); |