diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-12 11:38:22 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-12 11:38:22 +0000 |
commit | 53d3397bf638156cbbedd9d8da379eb502dc9d83 (patch) | |
tree | f46046fdf3aeb27ea8366ec3f3acdfcb44129240 /src | |
parent | 4ec038ad1cefcec2eaa60af61b8e973c27c4cf09 (diff) | |
download | gnunet-53d3397bf638156cbbedd9d8da379eb502dc9d83.tar.gz gnunet-53d3397bf638156cbbedd9d8da379eb502dc9d83.zip |
sensordashboard: storing received anomaly reports
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_sensor_util_lib.h | 2 | ||||
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 63 |
2 files changed, 60 insertions, 5 deletions
diff --git a/src/include/gnunet_sensor_util_lib.h b/src/include/gnunet_sensor_util_lib.h index c5d4e6697..87ae564fa 100644 --- a/src/include/gnunet_sensor_util_lib.h +++ b/src/include/gnunet_sensor_util_lib.h | |||
@@ -325,7 +325,7 @@ struct GNUNET_SENSOR_AnomalyReportMessage | |||
325 | /** | 325 | /** |
326 | * New anomaly status | 326 | * New anomaly status |
327 | */ | 327 | */ |
328 | uint8_t anomalous; | 328 | uint16_t anomalous; |
329 | 329 | ||
330 | /** | 330 | /** |
331 | * Percentage of neighbors reported the same anomaly | 331 | * Percentage of neighbors reported the same anomaly |
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 732b5a535..7dc1b33d6 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -154,9 +154,16 @@ static struct GNUNET_CADET_Handle *cadet; | |||
154 | static struct GNUNET_PEERSTORE_Handle *peerstore; | 154 | static struct GNUNET_PEERSTORE_Handle *peerstore; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | * Name of this subsystem to be used for peerstore operations | 157 | * Name of the subsystem used to store sensor values received from remote peers |
158 | * in PEERSTORE | ||
158 | */ | 159 | */ |
159 | static char *subsystem = "sensordashboard"; | 160 | static char *values_subsystem = "sensordashboard-values"; |
161 | |||
162 | /** | ||
163 | * Name of the subsystem used to store anomaly reports received from remote | ||
164 | * peers in PEERSTORE | ||
165 | */ | ||
166 | static char *anomalies_subsystem = "sensordashboard-anomalies"; | ||
160 | 167 | ||
161 | /** | 168 | /** |
162 | * Head of a DLL of all connected client peers | 169 | * Head of a DLL of all connected client peers |
@@ -393,6 +400,51 @@ queue_msg (struct GNUNET_MessageHeader *msg, struct ClientPeerContext *cp) | |||
393 | 400 | ||
394 | 401 | ||
395 | /** | 402 | /** |
403 | * Called with any anomaly report received from a peer. | ||
404 | * | ||
405 | * Each time the function must call #GNUNET_CADET_receive_done on the channel | ||
406 | * in order to receive the next message. This doesn't need to be immediate: | ||
407 | * can be delayed if some processing is done on the message. | ||
408 | * | ||
409 | * @param cls Closure (set from #GNUNET_CADET_connect). | ||
410 | * @param channel Connection to the other end. | ||
411 | * @param channel_ctx Place to store local state associated with the channel. | ||
412 | * @param message The actual message. | ||
413 | * @return #GNUNET_OK to keep the channel open, | ||
414 | * #GNUNET_SYSERR to close it (signal serious error). | ||
415 | */ | ||
416 | static int | ||
417 | handle_anomaly_report (void *cls, struct GNUNET_CADET_Channel *channel, | ||
418 | void **channel_ctx, | ||
419 | const struct GNUNET_MessageHeader *message) | ||
420 | { | ||
421 | struct ClientPeerContext *cp = *channel_ctx; | ||
422 | struct GNUNET_SENSOR_AnomalyReportMessage *anomaly_msg; | ||
423 | struct GNUNET_SENSOR_SensorInfo *sensor; | ||
424 | uint16_t anomalous; | ||
425 | struct GNUNET_TIME_Absolute expiry; | ||
426 | |||
427 | anomaly_msg = (struct GNUNET_SENSOR_AnomalyReportMessage *) message; | ||
428 | sensor = | ||
429 | GNUNET_CONTAINER_multihashmap_get (sensors, | ||
430 | &anomaly_msg->sensorname_hash); | ||
431 | if (NULL == sensor) | ||
432 | { | ||
433 | GNUNET_break_op (0); | ||
434 | return GNUNET_SYSERR; | ||
435 | } | ||
436 | anomalous = ntohs (anomaly_msg->anomalous); | ||
437 | expiry = | ||
438 | (GNUNET_YES == | ||
439 | anomalous) ? GNUNET_TIME_UNIT_FOREVER_ABS : GNUNET_TIME_absolute_get (); | ||
440 | GNUNET_PEERSTORE_store (peerstore, anomalies_subsystem, &cp->peerid, | ||
441 | sensor->name, &anomalous, sizeof (anomalous), expiry, | ||
442 | GNUNET_PEERSTORE_STOREOPTION_REPLACE, NULL, NULL); | ||
443 | return GNUNET_OK; | ||
444 | } | ||
445 | |||
446 | |||
447 | /** | ||
396 | * Iterate over defined sensors, creates and sends brief sensor information to | 448 | * Iterate over defined sensors, creates and sends brief sensor information to |
397 | * given client peer over CADET. | 449 | * given client peer over CADET. |
398 | * | 450 | * |
@@ -501,7 +553,7 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
501 | return NULL; | 553 | return NULL; |
502 | } | 554 | } |
503 | if ((sensor->version_minor != ntohs (vm->sensorversion_minor)) || | 555 | if ((sensor->version_minor != ntohs (vm->sensorversion_minor)) || |
504 | (sensor->version_major != ntohs (vm->sensorversion_major))) | 556 | (sensor->version_major != ntohs (vm->sensorversion_major))) |
505 | { | 557 | { |
506 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 558 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
507 | "Sensor version mismatch in reading message.\n"); | 559 | "Sensor version mismatch in reading message.\n"); |
@@ -558,7 +610,7 @@ handle_sensor_reading (void *cls, struct GNUNET_CADET_Channel *channel, | |||
558 | "# Sensor name: `%s'\n" "# Timestamp: %" PRIu64 "\n" | 610 | "# Sensor name: `%s'\n" "# Timestamp: %" PRIu64 "\n" |
559 | "# Value size: %" PRIu64 ".\n", GNUNET_i2s (&cp->peerid), | 611 | "# Value size: %" PRIu64 ".\n", GNUNET_i2s (&cp->peerid), |
560 | reading->sensor->name, reading->timestamp, reading->value_size); | 612 | reading->sensor->name, reading->timestamp, reading->value_size); |
561 | GNUNET_PEERSTORE_store (peerstore, subsystem, &cp->peerid, | 613 | GNUNET_PEERSTORE_store (peerstore, values_subsystem, &cp->peerid, |
562 | reading->sensor->name, reading->value, | 614 | reading->sensor->name, reading->value, |
563 | reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, | 615 | reading->value_size, GNUNET_TIME_UNIT_FOREVER_ABS, |
564 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); | 616 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL); |
@@ -726,6 +778,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
726 | {&handle_sensor_full_req, | 778 | {&handle_sensor_full_req, |
727 | GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ, | 779 | GNUNET_MESSAGE_TYPE_SENSOR_FULL_REQ, |
728 | sizeof (struct GNUNET_MessageHeader)}, | 780 | sizeof (struct GNUNET_MessageHeader)}, |
781 | {&handle_anomaly_report, | ||
782 | GNUNET_MESSAGE_TYPE_SENSOR_ANOMALY_REPORT, | ||
783 | sizeof (struct GNUNET_SENSOR_AnomalyReportMessage)}, | ||
729 | {NULL, 0, 0} | 784 | {NULL, 0, 0} |
730 | }; | 785 | }; |
731 | static uint32_t cadet_ports[] = { | 786 | static uint32_t cadet_ports[] = { |