diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-08-07 12:03:36 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-08-07 12:03:36 +0000 |
commit | 9ea2094c766b8a62bcfb8eebbda7746009750387 (patch) | |
tree | 3561436e2de7e9029b87d378b76c34bc8e2ed1f1 /src/sensor | |
parent | 8e1a28b80f0b6b2d2a5354400a40a1394fa9f6cf (diff) | |
download | gnunet-9ea2094c766b8a62bcfb8eebbda7746009750387.tar.gz gnunet-9ea2094c766b8a62bcfb8eebbda7746009750387.zip |
minor fix
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/gnunet-service-sensor.c | 22 | ||||
-rw-r--r-- | src/sensor/gnunet-service-sensor_update.c | 35 | ||||
-rw-r--r-- | src/sensor/sensor.conf.in | 6 | ||||
-rw-r--r-- | src/sensor/sensor_util_lib.c | 28 |
4 files changed, 59 insertions, 32 deletions
diff --git a/src/sensor/gnunet-service-sensor.c b/src/sensor/gnunet-service-sensor.c index 1df300410..4dc366cc1 100644 --- a/src/sensor/gnunet-service-sensor.c +++ b/src/sensor/gnunet-service-sensor.c | |||
@@ -36,6 +36,11 @@ | |||
36 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 36 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Path to sensor definitions directory | ||
40 | */ | ||
41 | static char *sensor_dir; | ||
42 | |||
43 | /** | ||
39 | * Hashmap of loaded sensor definitions | 44 | * Hashmap of loaded sensor definitions |
40 | */ | 45 | */ |
41 | static struct GNUNET_CONTAINER_MultiHashMap *sensors; | 46 | static struct GNUNET_CONTAINER_MultiHashMap *sensors; |
@@ -123,6 +128,11 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
123 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); | 128 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); |
124 | peerstore = NULL; | 129 | peerstore = NULL; |
125 | } | 130 | } |
131 | if (NULL != sensor_dir) | ||
132 | { | ||
133 | GNUNET_free (sensor_dir); | ||
134 | sensor_dir = NULL; | ||
135 | } | ||
126 | GNUNET_SCHEDULER_shutdown (); | 136 | GNUNET_SCHEDULER_shutdown (); |
127 | } | 137 | } |
128 | 138 | ||
@@ -479,7 +489,6 @@ sensor_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
479 | { | 489 | { |
480 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; | 490 | struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls; |
481 | int check_result; | 491 | int check_result; |
482 | char *sensors_dir; | ||
483 | char *process_path; | 492 | char *process_path; |
484 | 493 | ||
485 | sensorinfo->execution_task = | 494 | sensorinfo->execution_task = |
@@ -522,12 +531,11 @@ sensor_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
522 | if (GNUNET_SYSERR == check_result) | 531 | if (GNUNET_SYSERR == check_result) |
523 | { | 532 | { |
524 | //search in sensor directory | 533 | //search in sensor directory |
525 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); | ||
526 | GNUNET_free (process_path); | 534 | GNUNET_free (process_path); |
527 | GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensors_dir, | 535 | GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensor_dir, |
528 | sensorinfo->name, DIR_SEPARATOR_STR, | 536 | sensorinfo->name, DIR_SEPARATOR_STR, |
529 | sensorinfo->ext_process); | 537 | sensorinfo->ext_process); |
530 | GNUNET_free (sensors_dir); | 538 | GNUNET_free (sensor_dir); |
531 | check_result = | 539 | check_result = |
532 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); | 540 | GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL); |
533 | } | 541 | } |
@@ -611,7 +619,7 @@ schedule_all_sensors () | |||
611 | static void | 619 | static void |
612 | start () | 620 | start () |
613 | { | 621 | { |
614 | sensors = GNUNET_SENSOR_load_all_sensors (); | 622 | sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir); |
615 | schedule_all_sensors (); | 623 | schedule_all_sensors (); |
616 | SENSOR_reporting_value_start (cfg, sensors); | 624 | SENSOR_reporting_value_start (cfg, sensors); |
617 | SENSOR_reporting_anomaly_start (cfg, sensors); | 625 | SENSOR_reporting_anomaly_start (cfg, sensors); |
@@ -640,6 +648,10 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
640 | }; | 648 | }; |
641 | 649 | ||
642 | cfg = c; | 650 | cfg = c; |
651 | if (GNUNET_OK != | ||
652 | GNUNET_CONFIGURATION_get_value_filename (cfg, "SENSOR", "SENSOR_DIR", | ||
653 | &sensor_dir)) | ||
654 | sensor_dir = GNUNET_SENSOR_get_default_sensor_dir (); | ||
643 | statistics = GNUNET_STATISTICS_create ("sensor", cfg); | 655 | statistics = GNUNET_STATISTICS_create ("sensor", cfg); |
644 | GNUNET_CRYPTO_get_peer_identity (cfg, &peerid); | 656 | GNUNET_CRYPTO_get_peer_identity (cfg, &peerid); |
645 | peerstore = GNUNET_PEERSTORE_connect (cfg); | 657 | peerstore = GNUNET_PEERSTORE_connect (cfg); |
diff --git a/src/sensor/gnunet-service-sensor_update.c b/src/sensor/gnunet-service-sensor_update.c index 1d8b32832..cbc63308d 100644 --- a/src/sensor/gnunet-service-sensor_update.c +++ b/src/sensor/gnunet-service-sensor_update.c | |||
@@ -131,6 +131,11 @@ struct UpdatePoint | |||
131 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 131 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
132 | 132 | ||
133 | /** | 133 | /** |
134 | * Path to sensor definition directory | ||
135 | */ | ||
136 | static char *sensor_dir; | ||
137 | |||
138 | /** | ||
134 | * Hashmap of known sensors | 139 | * Hashmap of known sensors |
135 | */ | 140 | */ |
136 | static struct GNUNET_CONTAINER_MultiHashMap *sensors; | 141 | static struct GNUNET_CONTAINER_MultiHashMap *sensors; |
@@ -249,6 +254,11 @@ SENSOR_update_stop () | |||
249 | GNUNET_CADET_disconnect (cadet); | 254 | GNUNET_CADET_disconnect (cadet); |
250 | cadet = NULL; | 255 | cadet = NULL; |
251 | } | 256 | } |
257 | if (NULL != sensor_dir) | ||
258 | { | ||
259 | GNUNET_free (sensor_dir); | ||
260 | sensor_dir = NULL; | ||
261 | } | ||
252 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module stopped.\n"); | 262 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sensor update module stopped.\n"); |
253 | } | 263 | } |
254 | 264 | ||
@@ -427,7 +437,7 @@ check_for_updates (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
427 | * Function that reads and validates (correctness not connectivity) of available | 437 | * Function that reads and validates (correctness not connectivity) of available |
428 | * sensor update points. | 438 | * sensor update points. |
429 | * | 439 | * |
430 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 440 | * @return number of update points loaded successfully |
431 | */ | 441 | */ |
432 | static int | 442 | static int |
433 | load_update_points () | 443 | load_update_points () |
@@ -439,14 +449,13 @@ load_update_points () | |||
439 | int len; | 449 | int len; |
440 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; | 450 | struct GNUNET_CRYPTO_EddsaPublicKey public_key; |
441 | struct UpdatePoint *up; | 451 | struct UpdatePoint *up; |
452 | int count = 0; | ||
442 | 453 | ||
443 | if (GNUNET_OK != | 454 | if (GNUNET_OK != |
444 | GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS", | 455 | GNUNET_CONFIGURATION_get_value_string (cfg, "sensor", "UPDATE_POINTS", |
445 | &points_list)) | 456 | &points_list)) |
446 | { | 457 | { |
447 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "sensor", | 458 | return 0; |
448 | "UPDATE_POINTS"); | ||
449 | return GNUNET_SYSERR; | ||
450 | } | 459 | } |
451 | points_list_len = strlen (points_list) + 1; | 460 | points_list_len = strlen (points_list) + 1; |
452 | for (i = 0; i < points_list_len; i++) | 461 | for (i = 0; i < points_list_len; i++) |
@@ -478,11 +487,12 @@ load_update_points () | |||
478 | up->expected_sensor_updates = 0; | 487 | up->expected_sensor_updates = 0; |
479 | up->failed = GNUNET_NO; | 488 | up->failed = GNUNET_NO; |
480 | GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up); | 489 | GNUNET_CONTAINER_DLL_insert (up_head, up_tail, up); |
490 | count++; | ||
481 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded update point `%s'.\n", | 491 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded update point `%s'.\n", |
482 | GNUNET_i2s_full (&up->peer_id)); | 492 | GNUNET_i2s_full (&up->peer_id)); |
483 | } | 493 | } |
484 | GNUNET_free (points_list); | 494 | GNUNET_free (points_list); |
485 | return (NULL == up_head) ? GNUNET_SYSERR : GNUNET_OK; | 495 | return count; |
486 | } | 496 | } |
487 | 497 | ||
488 | 498 | ||
@@ -598,7 +608,6 @@ static int | |||
598 | update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size, | 608 | update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size, |
599 | char *scriptname, void *scriptfile, uint16_t scriptfile_size) | 609 | char *scriptname, void *scriptfile, uint16_t scriptfile_size) |
600 | { | 610 | { |
601 | char *sensors_dir; | ||
602 | char *sensor_path; | 611 | char *sensor_path; |
603 | char *script_path; | 612 | char *script_path; |
604 | 613 | ||
@@ -607,8 +616,7 @@ update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size, | |||
607 | "Sensor file size: %d\n" "Script name: %s\n" "Script file size: %d.\n", | 616 | "Sensor file size: %d\n" "Script name: %s\n" "Script file size: %d.\n", |
608 | sensorname, sensorfile_size, (NULL == scriptname) ? "None" : scriptname, | 617 | sensorname, sensorfile_size, (NULL == scriptname) ? "None" : scriptname, |
609 | scriptfile_size); | 618 | scriptfile_size); |
610 | sensors_dir = GNUNET_SENSOR_get_sensor_dir (); | 619 | GNUNET_asprintf (&sensor_path, "%s%s", sensor_dir, sensorname); |
611 | GNUNET_asprintf (&sensor_path, "%s%s", sensors_dir, sensorname); | ||
612 | GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size, | 620 | GNUNET_DISK_fn_write (sensor_path, sensorfile, sensorfile_size, |
613 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ | 621 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ |
614 | | GNUNET_DISK_PERM_OTHER_READ | | 622 | | GNUNET_DISK_PERM_OTHER_READ | |
@@ -627,7 +635,6 @@ update_sensor (char *sensorname, void *sensorfile, uint16_t sensorfile_size, | |||
627 | GNUNET_DISK_PERM_GROUP_EXEC); | 635 | GNUNET_DISK_PERM_GROUP_EXEC); |
628 | GNUNET_free (script_path); | 636 | GNUNET_free (script_path); |
629 | } | 637 | } |
630 | GNUNET_free (sensors_dir); | ||
631 | GNUNET_free (sensor_path); | 638 | GNUNET_free (sensor_path); |
632 | return GNUNET_OK; | 639 | return GNUNET_OK; |
633 | } | 640 | } |
@@ -756,11 +763,16 @@ SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
756 | {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0}, | 763 | {&handle_sensor_full, GNUNET_MESSAGE_TYPE_SENSOR_FULL, 0}, |
757 | {NULL, 0, 0} | 764 | {NULL, 0, 0} |
758 | }; | 765 | }; |
766 | int up_count; | ||
759 | 767 | ||
760 | GNUNET_assert (NULL != s); | 768 | GNUNET_assert (NULL != s); |
761 | cfg = c; | 769 | cfg = c; |
762 | sensors = s; | 770 | sensors = s; |
763 | reset_cb = cb; | 771 | reset_cb = cb; |
772 | if (GNUNET_OK != | ||
773 | GNUNET_CONFIGURATION_get_value_filename (cfg, "SENSOR", "SENSOR_DIR", | ||
774 | &sensor_dir)) | ||
775 | sensor_dir = GNUNET_SENSOR_get_default_sensor_dir (); | ||
764 | cadet = | 776 | cadet = |
765 | GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed, | 777 | GNUNET_CADET_connect (cfg, NULL, NULL, &cadet_channel_destroyed, |
766 | cadet_handlers, NULL); | 778 | cadet_handlers, NULL); |
@@ -770,9 +782,10 @@ SENSOR_update_start (const struct GNUNET_CONFIGURATION_Handle *c, | |||
770 | SENSOR_update_stop (); | 782 | SENSOR_update_stop (); |
771 | return GNUNET_SYSERR; | 783 | return GNUNET_SYSERR; |
772 | } | 784 | } |
773 | if (GNUNET_OK != load_update_points ()) | 785 | up_count = load_update_points (); |
786 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loaded %d update points.\n", up_count); | ||
787 | if (0 == up_count) | ||
774 | { | 788 | { |
775 | LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to load update points.\n"); | ||
776 | SENSOR_update_stop (); | 789 | SENSOR_update_stop (); |
777 | return GNUNET_SYSERR; | 790 | return GNUNET_SYSERR; |
778 | } | 791 | } |
diff --git a/src/sensor/sensor.conf.in b/src/sensor/sensor.conf.in index fcb914afe..60a62b650 100644 --- a/src/sensor/sensor.conf.in +++ b/src/sensor/sensor.conf.in | |||
@@ -5,8 +5,12 @@ UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-sensor.sock | |||
5 | UNIX_MATCH_UID = NO | 5 | UNIX_MATCH_UID = NO |
6 | UNIX_MATCH_GID = YES | 6 | UNIX_MATCH_GID = YES |
7 | 7 | ||
8 | # Path to directory containing sensor definitions. | ||
9 | # If not set, will load from default location. | ||
10 | #SENSOR_DIR = | ||
11 | |||
8 | # Space separated list of trusted peers running update points | 12 | # Space separated list of trusted peers running update points |
9 | #UPDATE_POINTS = NCEKA096482PC84GFTG61EHAVXY3BQDTPB5FANATQD5CDADJ2HP0 | 13 | UPDATE_POINTS = |
10 | 14 | ||
11 | [sensor-analysis] | 15 | [sensor-analysis] |
12 | MODEL = gaussian | 16 | MODEL = gaussian |
diff --git a/src/sensor/sensor_util_lib.c b/src/sensor/sensor_util_lib.c index d12698c3a..136bb288a 100644 --- a/src/sensor/sensor_util_lib.c +++ b/src/sensor/sensor_util_lib.c | |||
@@ -290,7 +290,6 @@ load_sensor_from_cfg (struct GNUNET_CONFIGURATION_Handle *cfg, | |||
290 | sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; | 290 | sensor->execution_task = GNUNET_SCHEDULER_NO_TASK; |
291 | //running | 291 | //running |
292 | sensor->running = GNUNET_NO; | 292 | sensor->running = GNUNET_NO; |
293 | |||
294 | return sensor; | 293 | return sensor; |
295 | } | 294 | } |
296 | 295 | ||
@@ -434,14 +433,14 @@ reload_sensors_dir_cb (void *cls, const char *filename) | |||
434 | } | 433 | } |
435 | 434 | ||
436 | 435 | ||
437 | /* | 436 | /** |
438 | * Get path to the directory containing the sensor definition files with a | 437 | * Get path to the default directory containing the sensor definition files with |
439 | * trailing directory separator. | 438 | * a trailing directory separator. |
440 | * | 439 | * |
441 | * @return sensor files directory full path | 440 | * @return Default sensor files directory full path |
442 | */ | 441 | */ |
443 | char * | 442 | char * |
444 | GNUNET_SENSOR_get_sensor_dir () | 443 | GNUNET_SENSOR_get_default_sensor_dir () |
445 | { | 444 | { |
446 | char *datadir; | 445 | char *datadir; |
447 | char *sensordir; | 446 | char *sensordir; |
@@ -454,27 +453,26 @@ GNUNET_SENSOR_get_sensor_dir () | |||
454 | 453 | ||
455 | 454 | ||
456 | /** | 455 | /** |
457 | * Reads sensor definitions from local data files | 456 | * Reads sensor definitions from given sensor directory. |
458 | * | 457 | * |
458 | * @param sensordir Path to sensor directory. | ||
459 | * @return a multihashmap of loaded sensors | 459 | * @return a multihashmap of loaded sensors |
460 | */ | 460 | */ |
461 | struct GNUNET_CONTAINER_MultiHashMap * | 461 | struct GNUNET_CONTAINER_MultiHashMap * |
462 | GNUNET_SENSOR_load_all_sensors () | 462 | GNUNET_SENSOR_load_all_sensors (char *sensor_dir) |
463 | { | 463 | { |
464 | char *sensordir; | ||
465 | struct GNUNET_CONTAINER_MultiHashMap *sensors; | 464 | struct GNUNET_CONTAINER_MultiHashMap *sensors; |
466 | 465 | ||
466 | GNUNET_assert (NULL != sensor_dir); | ||
467 | sensors = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 467 | sensors = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
468 | sensordir = GNUNET_SENSOR_get_sensor_dir (); | ||
469 | LOG (GNUNET_ERROR_TYPE_INFO, | 468 | LOG (GNUNET_ERROR_TYPE_INFO, |
470 | "Loading sensor definitions from directory `%s'\n", sensordir); | 469 | "Loading sensor definitions from directory `%s'\n", sensor_dir); |
471 | GNUNET_assert (GNUNET_YES == | 470 | GNUNET_assert (GNUNET_YES == |
472 | GNUNET_DISK_directory_test (sensordir, GNUNET_YES)); | 471 | GNUNET_DISK_directory_test (sensor_dir, GNUNET_YES)); |
473 | /* read all files in sensors directory */ | 472 | /* read all files in sensors directory */ |
474 | GNUNET_DISK_directory_scan (sensordir, &reload_sensors_dir_cb, sensors); | 473 | GNUNET_DISK_directory_scan (sensor_dir, &reload_sensors_dir_cb, sensors); |
475 | LOG (GNUNET_ERROR_TYPE_INFO, "Loaded %d sensors from directory `%s'\n", | 474 | LOG (GNUNET_ERROR_TYPE_INFO, "Loaded %d sensors from directory `%s'\n", |
476 | GNUNET_CONTAINER_multihashmap_size (sensors), sensordir); | 475 | GNUNET_CONTAINER_multihashmap_size (sensors), sensor_dir); |
477 | GNUNET_free (sensordir); | ||
478 | return sensors; | 476 | return sensors; |
479 | } | 477 | } |
480 | 478 | ||