2 This file is part of GNUnet.
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file sensor/gnunet-service-sensor.c
23 * @brief sensor service implementation
24 * @author Omar Tarabai
28 #include "gnunet_util_lib.h"
32 * Minimum sensor execution interval (in seconds)
34 #define MIN_INTERVAL 30
37 * Structure containing sensor definition
48 * Path to definition file
53 * First part of version number
55 uint16_t version_major;
58 * Second part of version number
60 uint16_t version_minor;
68 * Sensor currently enabled
73 * Category under which the sensor falls (e.g. tcp, datastore)
78 * When does the sensor become active
80 struct GNUNET_TIME_Absolute *start_time;
83 * When does the sensor expire
85 struct GNUNET_TIME_Absolute *end_time;
88 * Time interval to collect sensor information (e.g. every 1 min)
90 struct GNUNET_TIME_Relative interval;
93 * Lifetime of an information sample after which it is deleted from storage
95 struct GNUNET_TIME_Relative lifetime;
98 * A set of required peer capabilities for the sensor to collect meaningful information (e.g. ipv6)
103 * Either "gnunet-statistics" or external "process"
108 * Name of the GNUnet service that is the source for the gnunet-statistics entry
110 char *gnunet_stat_service;
113 * Name of the gnunet-statistics entry
115 char *gnunet_stat_name;
118 * Handle to statistics get request (OR GNUNET_SCHEDULER_NO_TASK)
120 struct GNUNET_STATISTICS_GetHandle *gnunet_stat_get_handle;
123 * Name of the external process to be executed
128 * Arguments to be passed to the external process
133 * The output datatype to be expected
135 char *expected_datatype;
138 * Peer-identity of peer running collection point
140 struct GNUNET_PeerIdentity *collection_point;
143 * Time interval to send sensor information to collection point (e.g. every 30 mins)
145 struct GNUNET_TIME_Relative *collection_interval;
148 * Flag specifying if value is to be communicated to the p2p network
153 * Time interval to communicate value to the p2p network
155 struct GNUNET_TIME_Relative *p2p_interval;
158 * Execution task (OR GNUNET_SCHEDULER_NO_TASK)
160 GNUNET_SCHEDULER_TaskIdentifier execution_task;
167 static const struct GNUNET_CONFIGURATION_Handle *cfg;
170 * Hashmap of loaded sensor definitions
172 struct GNUNET_CONTAINER_MultiHashMap *sensors;
175 * Supported sources of sensor information
177 static const char *sources[] = { "gnunet-statistics", "process", NULL };
180 * Supported datatypes of sensor information
182 static const char *datatypes[] = { "uint64", "double", "string", NULL };
185 * Handle to statistics service
187 struct GNUNET_STATISTICS_Handle *statistics;
190 * Remove sensor execution from scheduler
193 * @param key hash of sensor name, key to hashmap
194 * @param value a 'struct SensorInfo *'
195 * @return #GNUNET_YES if we should continue to
199 int unschedule_sensor(void *cls,
200 const struct GNUNET_HashCode *key, void *value)
202 struct SensorInfo *sensorinfo = value;
204 if(NULL != sensorinfo->gnunet_stat_get_handle)
206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Canceling a statistics get request for sensor `%s'\n", sensorinfo->name);
207 GNUNET_STATISTICS_get_cancel(sensorinfo->gnunet_stat_get_handle);
209 if(GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task)
211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unscheduling sensor `%s'\n", sensorinfo->name);
212 GNUNET_SCHEDULER_cancel(sensorinfo->execution_task);
218 * Task run during shutdown.
224 shutdown_task (void *cls,
225 const struct GNUNET_SCHEDULER_TaskContext *tc)
227 GNUNET_CONTAINER_multihashmap_iterate(sensors, &unschedule_sensor, NULL);
228 if(NULL != statistics)
229 GNUNET_STATISTICS_destroy(statistics, GNUNET_YES);
230 GNUNET_SCHEDULER_shutdown();
235 * A client disconnected. Remove all of its data structure entries.
237 * @param cls closure, NULL
238 * @param client identification of the client
241 handle_client_disconnect (void *cls,
242 struct GNUNET_SERVER_Client
248 * Parses a version number string into major and minor
250 * @param version full version string
251 * @param major pointer to parsed major value
252 * @param minor pointer to parsed minor value
253 * @return #GNUNET_OK if parsing went ok, #GNUNET_SYSERROR in case of error
256 version_parse(char *version, uint16_t *major, uint16_t *minor)
261 for(; isdigit(*version); version++)
264 majorval += *version - '0';
267 return GNUNET_SYSERR;
269 for(; isdigit(*version); version++)
272 minorval += *version - '0';
275 return GNUNET_SYSERR;
283 * Load sensor definition from configuration
285 * @param cfg configuration handle
286 * @param sectionname configuration section containing definition
288 static struct SensorInfo *
289 load_sensor_from_cfg(struct GNUNET_CONFIGURATION_Handle *cfg, const char *sectionname)
291 struct SensorInfo *sensor;
295 unsigned long long time_sec;
297 sensor = GNUNET_new(struct SensorInfo);
299 sensor->name = GNUNET_strdup(sectionname);
301 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "VERSION", &version_str))
303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor version\n"));
307 if(GNUNET_OK != version_parse(version_str, &(sensor->version_major), &(sensor->version_minor)))
309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Invalid sensor version number, format should be major.minor\n"));
311 GNUNET_free(version_str);
314 GNUNET_free(version_str);
316 GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "DESCRIPTION", &sensor->description);
318 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "CATEGORY", &sensor->category) ||
319 NULL == sensor->category)
321 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor category\n"));
326 if(GNUNET_NO == GNUNET_CONFIGURATION_get_value_yesno(cfg, sectionname, "ENABLED"))
327 sensor->enabled = GNUNET_NO;
329 sensor->enabled = GNUNET_YES;
331 sensor->start_time = NULL;
332 if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "START_TIME", &starttime_str))
334 GNUNET_STRINGS_fancy_time_to_absolute(starttime_str, sensor->start_time);
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Start time loaded: `%s'. Parsed: %d\n", starttime_str, (NULL != sensor->start_time));
336 GNUNET_free(starttime_str);
339 sensor->end_time = NULL;
340 if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "END_TIME", &endtime_str))
342 GNUNET_STRINGS_fancy_time_to_absolute(endtime_str, sensor->end_time);
343 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "End time loaded: `%s'. Parsed: %d\n", endtime_str, (NULL != sensor->end_time));
344 GNUNET_free(endtime_str);
347 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "INTERVAL", &time_sec))
349 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor run interval\n"));
353 if(time_sec < MIN_INTERVAL)
355 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Sensor run interval too low (%" PRIu64 " < %d)\n"),
356 time_sec, MIN_INTERVAL);
360 sensor->interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec);
361 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Interval loaded: %" PRIu64 "\n", sensor->interval.rel_value_us);
363 if(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, sectionname, "LIFETIME", &time_sec))
365 sensor->lifetime = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, time_sec);
366 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Lifetime loaded: %" PRIu64 "\n", sensor->lifetime.rel_value_us);
369 sensor->lifetime = GNUNET_TIME_UNIT_FOREVER_REL;
372 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_choice(cfg, sectionname, "SOURCE", sources, &sensor->source))
374 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor source\n"));
378 if(sources[0] == sensor->source) //gnunet-statistics
380 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "GNUNET_STAT_SERVICE", &sensor->gnunet_stat_service) ||
381 GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "GNUNET_STAT_NAME", &sensor->gnunet_stat_name))
383 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor gnunet-statistics source information\n"));
387 sensor->gnunet_stat_get_handle = NULL;
389 else if(sources[1] == sensor->source) //process
391 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "EXT_PROCESS", &sensor->ext_process))
393 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor process name\n"));
397 GNUNET_CONFIGURATION_get_value_string(cfg, sectionname, "EXT_ARGS", &sensor->ext_args);
400 if(GNUNET_OK != GNUNET_CONFIGURATION_get_value_choice(cfg, sectionname, "EXPECTED_DATATYPE", datatypes, &sensor->expected_datatype))
402 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error reading sensor expected datatype\n"));
406 if(sources[0] == sensor->source && datatypes[0] != sensor->expected_datatype)
408 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Invalid expected datatype, gnunet-statistics returns uint64 values\n"));
412 //TODO: reporting mechanism
414 sensor->execution_task = GNUNET_SCHEDULER_NO_TASK;
420 * Load sensor definition from file
422 * @param filename full path to file containing sensor definition
424 static struct SensorInfo *
425 load_sensor_from_file(const char *filename)
427 struct GNUNET_CONFIGURATION_Handle *sensorcfg;
428 const char *filebasename;
429 struct SensorInfo *sensor;
432 if(GNUNET_YES != GNUNET_DISK_file_test(filename))
434 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to access sensor file: %s\n"), filename);
437 //load file as configuration
438 sensorcfg = GNUNET_CONFIGURATION_create();
439 if(GNUNET_SYSERR == GNUNET_CONFIGURATION_parse(sensorcfg, filename))
441 GNUNET_CONFIGURATION_destroy(sensorcfg);
442 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to load sensor definition: %s\n"), filename);
445 //configuration section should be the same as filename
446 filebasename = GNUNET_STRINGS_get_short_name(filename);
447 sensor = load_sensor_from_cfg(sensorcfg, filebasename);
448 sensor->def_file = GNUNET_strdup(filename);
450 GNUNET_CONFIGURATION_destroy(sensorcfg);
456 * Compares version numbers of two sensors
458 * @param s1 first sensor
459 * @param s2 second sensor
460 * @return 1: s1 > s2, 0: s1 == s2, -1: s1 < s2
463 sensor_version_compare(struct SensorInfo *s1, struct SensorInfo *s2)
465 if(s1->version_major == s2->version_major)
466 return (s1->version_minor < s2->version_minor) ? -1 : (s1->version_minor > s2->version_minor);
468 return (s1->version_major < s2->version_major) ? -1 : (s1->version_major > s2->version_major);
472 * Adds a new sensor to given hashmap.
473 * If the same name exist, compares versions and update if old.
475 * @param sensor Sensor structure to add
476 * @param map Hashmap to add to
477 * @return #GNUNET_YES if added, #GNUNET_NO if not added which is not necessarily an error
480 add_sensor_to_hashmap(struct SensorInfo *sensor, struct GNUNET_CONTAINER_MultiHashMap *map)
482 struct GNUNET_HashCode key;
483 struct SensorInfo *existing;
485 GNUNET_CRYPTO_hash(sensor->name, strlen(sensor->name), &key);
486 existing = GNUNET_CONTAINER_multihashmap_get(map, &key);
487 if(NULL != existing) //sensor with same name already exists
489 if(sensor_version_compare(existing, sensor) >= 0) //same or newer version already exist
491 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Sensor `%s' already exists with same or newer version\n"), sensor->name);
496 GNUNET_CONTAINER_multihashmap_remove(map, &key, existing); //remove the old version
497 GNUNET_free(existing);
498 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Upgrading sensor `%s' to a newer version\n"), sensor->name);
501 if(GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put(map, &key, sensor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
503 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error adding new sensor `%s' to global hashmap, this should not happen\n"), sensor->name);
511 * Iterating over files in sensors directory
514 * @param filename complete filename (absolute path)
515 * @return #GNUNET_OK to continue to iterate,
516 * #GNUNET_NO to stop iteration with no error,
517 * #GNUNET_SYSERR to abort iteration with error!
520 reload_sensors_dir_cb(void *cls, const char *filename)
522 struct SensorInfo *sensor;
524 sensor = load_sensor_from_file(filename);
527 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Error loading sensor from file: %s\n"), filename);
530 if(GNUNET_YES == add_sensor_to_hashmap(sensor, sensors))
531 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Sensor `%s' added to global hashmap\n"), sensor->name);
533 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, ("Could not add sensor `%s' to global hashmap\n"), sensor->name);
539 * Get path to the directory containing the sensor definition files
541 * @return sensor files directory
549 datadir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR);
550 GNUNET_asprintf(&sensordir, "%ssensors%s",
551 datadir, DIR_SEPARATOR_STR);
557 * Reads sensor definitions from data files
566 sensordir = get_sensor_dir();
567 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Reloading sensor definitions from directory `%s'\n"), sensordir);
568 GNUNET_assert(GNUNET_YES == GNUNET_DISK_directory_test(sensordir, GNUNET_YES));
570 //read all files in sensors directory
571 filesfound = GNUNET_DISK_directory_scan(sensordir, &reload_sensors_dir_cb, NULL);
572 GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Loaded %d/%d sensors from directory `%s'\n"),
573 GNUNET_CONTAINER_multihashmap_size(sensors), filesfound, sensordir);
577 * Creates a structure with basic sensor info to be sent to a client
579 * @param sensor sensor information
580 * @return message ready to be sent to client
582 static struct SensorInfoMessage *
583 create_sensor_info_msg(struct SensorInfo *sensor)
585 struct SensorInfoMessage *msg;
591 name_len = strlen(sensor->name);
592 if(NULL == sensor->description)
595 desc_len = strlen(sensor->description);
597 len += sizeof(struct SensorInfoMessage);
600 msg = GNUNET_malloc(len);
601 msg->header.size = htons(len);
602 msg->header.type = htons(GNUNET_MESSAGE_TYPE_SENSOR_INFO);
603 msg->name_len = htons(name_len);
604 msg->description_len = htons(desc_len);
605 msg->version_major = htons(sensor->version_major);
606 msg->version_minor = htons(sensor->version_minor);
607 str_ptr = (char*) &msg[1];
608 memcpy(str_ptr, sensor->name, name_len);
609 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending sensor name (%d): %.*s\n",
610 name_len, name_len, str_ptr);
612 memcpy(str_ptr, sensor->description, desc_len);
613 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending sensor description (%d): %.*s\n",
614 desc_len, desc_len, str_ptr);
620 * Handle GET SENSOR message.
623 * @param client identification of the client
624 * @param message the actual message
627 handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client,
628 const struct GNUNET_MessageHeader *message)
630 struct GNUNET_SERVER_TransmitContext *tc;
632 size_t sensorname_len;
633 struct GNUNET_HashCode key;
634 struct SensorInfo *sensorinfo;
635 struct SensorInfoMessage *msg;
637 sensorname = (char *)&message[1];
638 sensorname_len = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader);
639 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received for sensor (%d) `%.*s'\n",
640 "GET SENSOR", sensorname_len, sensorname_len, sensorname);
641 tc = GNUNET_SERVER_transmit_context_create (client);
642 GNUNET_CRYPTO_hash(sensorname, sensorname_len, &key);
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created key hash for requested sensor\n");
644 sensorinfo = (struct SensorInfo *)GNUNET_CONTAINER_multihashmap_get(sensors, &key);
645 if(NULL != sensorinfo)
647 msg = create_sensor_info_msg(sensorinfo);
648 GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)msg);
652 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Requested sensor `%.*s' was not found\n",
653 sensorname_len, sensorname);
654 GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_SENSOR_END);
655 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
659 * Iterator for sensors and adds them to transmit context
661 * @param cls a 'struct GNUNET_SERVER_TransmitContext *'
662 * @param key hash of sensor name, key to hashmap
663 * @param value a 'struct SensorInfo *'
665 int add_sensor_to_tc(void *cls,
666 const struct GNUNET_HashCode *key, void *value)
668 struct GNUNET_SERVER_TransmitContext *tc = cls;
669 struct SensorInfo *sensorinfo = value;
670 struct SensorInfoMessage *msg;
672 msg = create_sensor_info_msg(sensorinfo);
673 GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)msg);
681 * Handle GET ALL SENSORS message.
684 * @param client identification of the client
685 * @param message the actual message
688 handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client,
689 const struct GNUNET_MessageHeader *message)
691 struct GNUNET_SERVER_TransmitContext *tc;
693 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received.\n",
695 tc = GNUNET_SERVER_transmit_context_create (client);
696 GNUNET_CONTAINER_multihashmap_iterate(sensors, &add_sensor_to_tc, tc);
697 GNUNET_SERVER_transmit_context_append_data(tc, NULL, 0, GNUNET_MESSAGE_TYPE_SENSOR_END);
698 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
702 * Do a series of checks to determine if sensor should execute
704 * @return #GNUNET_YES / #GNUNET_NO
707 should_run_sensor(struct SensorInfo *sensorinfo)
709 struct GNUNET_TIME_Absolute now;
711 if(GNUNET_NO == sensorinfo->enabled)
713 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Sensor `%s' is disabled, will not run\n", sensorinfo->name);
716 now = GNUNET_TIME_absolute_get();
717 if(NULL != sensorinfo->start_time
718 && now.abs_value_us < sensorinfo->start_time->abs_value_us)
720 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start time for sensor `%s' not reached yet, will not run\n", sensorinfo->name);
723 if(NULL != sensorinfo->end_time
724 && now.abs_value_us >= sensorinfo->end_time->abs_value_us)
726 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "End time for sensor `%s' passed, will not run\n", sensorinfo->name);
733 * Callback function to process statistic values
735 * @param cls 'struct SensorInfo *'
736 * @param subsystem name of subsystem that created the statistic
737 * @param name the name of the datum
738 * @param value the current value
739 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
740 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
742 int sensor_statistics_iterator (void *cls,
743 const char *subsystem,
748 struct SensorInfo *sensorinfo = cls;
750 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %" PRIu64 "\n", sensorinfo->name, value);
755 * Actual execution of a sensor
757 * @param cls 'struct SensorInfo'
761 run_sensor (void *cls,
762 const struct GNUNET_SCHEDULER_TaskContext * tc)
764 struct SensorInfo *sensorinfo = cls;
766 sensorinfo->execution_task = GNUNET_SCHEDULER_NO_TASK;
767 if(GNUNET_NO == should_run_sensor(sensorinfo))
769 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo);
770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting the execution of sensor `%s'\n", sensorinfo->name);
771 if(sources[0] == sensorinfo->source) //gnunet-statistics
773 if(NULL == statistics)
774 statistics = GNUNET_STATISTICS_create("sensor", cfg);
775 GNUNET_STATISTICS_get(statistics,
776 sensorinfo->gnunet_stat_service,
777 sensorinfo->gnunet_stat_name,
778 GNUNET_TIME_UNIT_FOREVER_REL,
780 &sensor_statistics_iterator,
786 * Starts the execution of a sensor
789 * @param key hash of sensor name, key to hashmap
790 * @param value a 'struct SensorInfo *'
791 * @return #GNUNET_YES if we should continue to
795 int schedule_sensor(void *cls,
796 const struct GNUNET_HashCode *key, void *value)
798 struct SensorInfo *sensorinfo = value;
800 if(GNUNET_NO == should_run_sensor(sensorinfo))
802 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Scheduling sensor `%s' to run after %" PRIu64 " microseconds\n",
803 sensorinfo->name, sensorinfo->interval.rel_value_us);
804 if(GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task)
806 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sensor `%s' execution task already set, this should not happen\n", sensorinfo->name);
809 sensorinfo->execution_task = GNUNET_SCHEDULER_add_delayed(sensorinfo->interval, &run_sensor, sensorinfo);
814 * Starts the execution of all enabled sensors
818 schedule_all_sensors()
820 GNUNET_CONTAINER_multihashmap_iterate(sensors, &schedule_sensor, NULL);
824 * Process statistics requests.
827 * @param server the initialized server
828 * @param c configuration to use
832 struct GNUNET_SERVER_Handle *server,
833 const struct GNUNET_CONFIGURATION_Handle *c)
835 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
836 {&handle_get_sensor, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GET,
838 {&handle_get_all_sensors, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GETALL,
839 sizeof (struct GNUNET_MessageHeader)},
844 sensors = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO);
846 schedule_all_sensors();
847 GNUNET_SERVER_add_handlers (server, handlers);
848 GNUNET_SERVER_disconnect_notify (server,
849 &handle_client_disconnect,
851 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
858 * The main function for the sensor service.
860 * @param argc number of arguments from the command line
861 * @param argv command line arguments
862 * @return 0 ok, 1 on error
865 main (int argc, char *const *argv)
868 GNUNET_SERVICE_run (argc,
871 GNUNET_SERVICE_OPTION_NONE,
872 &run, NULL)) ? 0 : 1;
875 /* end of gnunet-service-sensor.c */