diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-07 18:24:04 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-07 18:24:04 +0000 |
commit | 605b0e88f6e64ac71a5afb08ce90c909a2807438 (patch) | |
tree | 9b713ebd15b1d3fa68f05ae6d62bebc899448f9a /src/sensordashboard | |
parent | d6e728b2b869ee521216deae75a767165d3e1001 (diff) | |
download | gnunet-605b0e88f6e64ac71a5afb08ce90c909a2807438.tar.gz gnunet-605b0e88f6e64ac71a5afb08ce90c909a2807438.zip |
sensor: merged reporting module
Diffstat (limited to 'src/sensordashboard')
-rw-r--r-- | src/sensordashboard/gnunet-service-sensordashboard.c | 39 |
1 files changed, 13 insertions, 26 deletions
diff --git a/src/sensordashboard/gnunet-service-sensordashboard.c b/src/sensordashboard/gnunet-service-sensordashboard.c index 6c63ad828..732b5a535 100644 --- a/src/sensordashboard/gnunet-service-sensordashboard.c +++ b/src/sensordashboard/gnunet-service-sensordashboard.c | |||
@@ -118,7 +118,7 @@ struct ClientSensorReading | |||
118 | /** | 118 | /** |
119 | * Timestamp of taking the reading | 119 | * Timestamp of taking the reading |
120 | */ | 120 | */ |
121 | uint64_t timestamp; | 121 | struct GNUNET_TIME_Absolute timestamp; |
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Reading value | 124 | * Reading value |
@@ -475,44 +475,33 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
475 | struct GNUNET_CONTAINER_MultiHashMap *sensors) | 475 | struct GNUNET_CONTAINER_MultiHashMap *sensors) |
476 | { | 476 | { |
477 | uint16_t msg_size; | 477 | uint16_t msg_size; |
478 | struct GNUNET_SENSOR_ReadingMessage *rm; | ||
479 | uint16_t sensorname_size; | ||
480 | uint16_t value_size; | 478 | uint16_t value_size; |
481 | void *dummy; | 479 | struct GNUNET_SENSOR_ValueMessage *vm; |
482 | char *sensorname; | ||
483 | struct GNUNET_HashCode key; | ||
484 | struct GNUNET_SENSOR_SensorInfo *sensor; | 480 | struct GNUNET_SENSOR_SensorInfo *sensor; |
485 | struct ClientSensorReading *reading; | 481 | struct ClientSensorReading *reading; |
486 | 482 | ||
487 | msg_size = ntohs (msg->size); | 483 | msg_size = ntohs (msg->size); |
488 | if (msg_size < sizeof (struct GNUNET_SENSOR_ReadingMessage)) | 484 | if (msg_size < sizeof (struct GNUNET_SENSOR_ValueMessage)) |
489 | { | 485 | { |
490 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | 486 | GNUNET_break_op (0); |
491 | return NULL; | 487 | return NULL; |
492 | } | 488 | } |
493 | rm = (struct GNUNET_SENSOR_ReadingMessage *) msg; | 489 | vm = (struct GNUNET_SENSOR_ValueMessage *) msg; |
494 | sensorname_size = ntohs (rm->sensorname_size); | 490 | value_size = ntohs (vm->value_size); |
495 | value_size = ntohs (rm->value_size); | 491 | if ((sizeof (struct GNUNET_SENSOR_ValueMessage) + value_size) != msg_size) |
496 | if ((sizeof (struct GNUNET_SENSOR_ReadingMessage) + sensorname_size + | ||
497 | value_size) != msg_size) | ||
498 | { | 492 | { |
499 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid reading message size.\n"); | 493 | GNUNET_break_op (0); |
500 | return NULL; | 494 | return NULL; |
501 | } | 495 | } |
502 | dummy = &rm[1]; | 496 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &vm->sensorname_hash); |
503 | sensorname = GNUNET_malloc (sensorname_size); | ||
504 | memcpy (sensorname, dummy, sensorname_size); | ||
505 | GNUNET_CRYPTO_hash (sensorname, sensorname_size, &key); | ||
506 | GNUNET_free (sensorname); | ||
507 | sensor = GNUNET_CONTAINER_multihashmap_get (sensors, &key); | ||
508 | if (NULL == sensor) | 497 | if (NULL == sensor) |
509 | { | 498 | { |
510 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 499 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
511 | "Unknown sensor name in reading message.\n"); | 500 | "Unknown sensor name in reading message.\n"); |
512 | return NULL; | 501 | return NULL; |
513 | } | 502 | } |
514 | if ((sensor->version_minor != ntohs (rm->sensorversion_minor)) || | 503 | if ((sensor->version_minor != ntohs (vm->sensorversion_minor)) || |
515 | (sensor->version_major != ntohs (rm->sensorversion_major))) | 504 | (sensor->version_major != ntohs (vm->sensorversion_major))) |
516 | { | 505 | { |
517 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 506 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
518 | "Sensor version mismatch in reading message.\n"); | 507 | "Sensor version mismatch in reading message.\n"); |
@@ -527,11 +516,9 @@ parse_reading_message (const struct GNUNET_MessageHeader *msg, | |||
527 | } | 516 | } |
528 | reading = GNUNET_new (struct ClientSensorReading); | 517 | reading = GNUNET_new (struct ClientSensorReading); |
529 | reading->sensor = sensor; | 518 | reading->sensor = sensor; |
530 | reading->timestamp = GNUNET_be64toh (rm->timestamp); | 519 | reading->timestamp = vm->timestamp; |
531 | reading->value_size = value_size; | 520 | reading->value_size = value_size; |
532 | reading->value = GNUNET_malloc (value_size); | 521 | reading->value = GNUNET_memdup (&vm[1], value_size); |
533 | dummy += sensorname_size; | ||
534 | memcpy (reading->value, dummy, value_size); | ||
535 | return reading; | 522 | return reading; |
536 | } | 523 | } |
537 | 524 | ||