minor fix
[oweals/gnunet.git] / src / sensor / gnunet-service-sensor.c
1 /*
2      This file is part of GNUnet.
3      (C)
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file sensor/gnunet-service-sensor.c
23  * @brief sensor service implementation
24  * @author Omar Tarabai
25  */
26 #include <inttypes.h>
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "sensor.h"
30 #include "gnunet_statistics_service.h"
31 #include "gnunet_peerstore_service.h"
32
33 /**
34  * Our configuration.
35  */
36 static const struct GNUNET_CONFIGURATION_Handle *cfg;
37
38 /**
39  * Path to sensor definitions directory
40  */
41 static char *sensor_dir;
42
43 /**
44  * Hashmap of loaded sensor definitions
45  */
46 static struct GNUNET_CONTAINER_MultiHashMap *sensors;
47
48 /**
49  * Handle to statistics service
50  */
51 static struct GNUNET_STATISTICS_Handle *statistics;
52
53 /**
54  * Handle to peerstore service
55  */
56 static struct GNUNET_PEERSTORE_Handle *peerstore;
57
58 /**
59  * Service name
60  */
61 static char *subsystem = "sensor";
62
63 /**
64  * My peer id
65  */
66 static struct GNUNET_PeerIdentity peerid;
67
68
69 /**
70  * Resets the service by stopping components, reloading sensors and starting
71  * components. This is needed when we receive new sensor updates.
72  */
73 static void
74 reset ();
75
76
77 /**
78  * Change the state of the sensor.
79  * Write the change to file to make it persistent.
80  *
81  * @param sensor sensor info struct
82  * @param state new enabled state: #GNUNET_YES / #GNUNET_NO
83  */
84 static void
85 set_sensor_enabled (struct GNUNET_SENSOR_SensorInfo *sensor, int state)
86 {
87   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sensor `%s': Setting enabled to %d.\n",
88               sensor->name, state);
89   sensor->enabled = GNUNET_NO;
90   GNUNET_assert (NULL != sensor->cfg);
91   GNUNET_CONFIGURATION_set_value_string (sensor->cfg, sensor->name, "ENABLED",
92                                          (GNUNET_YES == state) ? "YES" : "NO");
93   GNUNET_CONFIGURATION_write (sensor->cfg, sensor->def_file);
94 }
95
96
97 /**
98  * Stops components and destroys sensors
99  */
100 static void
101 stop ()
102 {
103   SENSOR_update_stop ();
104   SENSOR_analysis_stop ();
105   SENSOR_reporting_value_stop ();
106   SENSOR_reporting_anomaly_stop ();
107   GNUNET_SENSOR_destroy_sensors (sensors);
108 }
109
110
111 /**
112  * Task run during shutdown.
113  *
114  * @param cls unused
115  * @param tc unused
116  */
117 static void
118 shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 {
120   stop ();
121   if (NULL != statistics)
122   {
123     GNUNET_STATISTICS_destroy (statistics, GNUNET_YES);
124     statistics = NULL;
125   }
126   if (NULL != peerstore)
127   {
128     GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES);
129     peerstore = NULL;
130   }
131   if (NULL != sensor_dir)
132   {
133     GNUNET_free (sensor_dir);
134     sensor_dir = NULL;
135   }
136   GNUNET_SCHEDULER_shutdown ();
137 }
138
139
140 /**
141  * A client disconnected.  Remove all of its data structure entries.
142  *
143  * @param cls closure, NULL
144  * @param client identification of the client
145  */
146 static void
147 handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
148 {
149 }
150
151
152 /**
153  * Creates a structure with basic sensor info to be sent to a client.
154  *
155  * @param sensor sensor information
156  * @return message ready to be sent to client
157  */
158 static struct SensorInfoMessage *
159 create_sensor_info_msg (struct GNUNET_SENSOR_SensorInfo *sensor)
160 {
161   struct SensorInfoMessage *msg;
162   uint16_t len;
163   size_t name_len;
164   size_t desc_len;
165   char *str_ptr;
166
167   name_len = strlen (sensor->name);
168   if (NULL == sensor->description)
169     desc_len = 0;
170   else
171     desc_len = strlen (sensor->description) + 1;
172   len = 0;
173   len += sizeof (struct SensorInfoMessage);
174   len += name_len;
175   len += desc_len;
176   msg = GNUNET_malloc (len);
177   msg->header.size = htons (len);
178   msg->header.type = htons (GNUNET_MESSAGE_TYPE_SENSOR_INFO);
179   msg->name_len = htons (name_len);
180   msg->description_len = htons (desc_len);
181   msg->version_major = htons (sensor->version_major);
182   msg->version_minor = htons (sensor->version_minor);
183   str_ptr = (char *) &msg[1];
184   memcpy (str_ptr, sensor->name, name_len);
185   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending sensor name (%d): %.*s\n",
186               name_len, name_len, str_ptr);
187   str_ptr += name_len;
188   memcpy (str_ptr, sensor->description, desc_len);
189   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190               "Sending sensor description (%d): %.*s\n", desc_len, desc_len,
191               str_ptr);
192   return msg;
193 }
194
195
196 /**
197  * Handle GET SENSOR message.
198  *
199  * @param cls closure
200  * @param client identification of the client
201  * @param message the actual message
202  */
203 static void
204 handle_get_sensor (void *cls, struct GNUNET_SERVER_Client *client,
205                    const struct GNUNET_MessageHeader *message)
206 {
207   struct GNUNET_SERVER_TransmitContext *tc;
208   char *sensorname;
209   size_t sensorname_len;
210   struct GNUNET_HashCode key;
211   struct GNUNET_SENSOR_SensorInfo *sensorinfo;
212   struct SensorInfoMessage *msg;
213
214   sensorname = (char *) &message[1];
215   sensorname_len = ntohs (message->size) - sizeof (struct GNUNET_MessageHeader);
216   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
217               "`%s' message received for sensor (%d) `%.*s'\n", "GET SENSOR",
218               sensorname_len, sensorname_len, sensorname);
219   tc = GNUNET_SERVER_transmit_context_create (client);
220   GNUNET_CRYPTO_hash (sensorname, sensorname_len, &key);
221   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222               "Created key hash for requested sensor\n");
223   sensorinfo =
224       (struct GNUNET_SENSOR_SensorInfo *)
225       GNUNET_CONTAINER_multihashmap_get (sensors, &key);
226   if (NULL != sensorinfo)
227   {
228     msg = create_sensor_info_msg (sensorinfo);
229     GNUNET_SERVER_transmit_context_append_message (tc,
230                                                    (struct GNUNET_MessageHeader
231                                                     *) msg);
232     GNUNET_free (msg);
233   }
234   else
235     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
236                 "Requested sensor `%.*s' was not found\n", sensorname_len,
237                 sensorname);
238   GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
239                                               GNUNET_MESSAGE_TYPE_SENSOR_END);
240   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
241 }
242
243
244 /**
245  * Iterator for sensors and adds them to transmit context
246  *
247  * @param cls a `struct GNUNET_SERVER_TransmitContext *`
248  * @param key hash of sensor name, key to hashmap
249  * @param value a `struct GNUNET_SENSOR_SensorInfo *`
250  */
251 static int
252 add_sensor_to_tc (void *cls, const struct GNUNET_HashCode *key, void *value)
253 {
254   struct GNUNET_SERVER_TransmitContext *tc = cls;
255   struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
256   struct SensorInfoMessage *msg;
257
258   msg = create_sensor_info_msg (sensorinfo);
259   GNUNET_SERVER_transmit_context_append_message (tc,
260                                                  (struct GNUNET_MessageHeader *)
261                                                  msg);
262
263   GNUNET_free (msg);
264   return GNUNET_YES;
265 }
266
267
268 /**
269  * Handle GET ALL SENSORS message.
270  *
271  * @param cls closure
272  * @param client identification of the client
273  * @param message the actual message
274  */
275 static void
276 handle_get_all_sensors (void *cls, struct GNUNET_SERVER_Client *client,
277                         const struct GNUNET_MessageHeader *message)
278 {
279   struct GNUNET_SERVER_TransmitContext *tc;
280
281   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "`%s' message received.\n",
282               "GET ALL SENSOR");
283   tc = GNUNET_SERVER_transmit_context_create (client);
284   GNUNET_CONTAINER_multihashmap_iterate (sensors, &add_sensor_to_tc, tc);
285   GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
286                                               GNUNET_MESSAGE_TYPE_SENSOR_END);
287   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
288 }
289
290
291 /**
292  * Do a series of checks to determine if sensor should execute
293  *
294  * @return #GNUNET_YES / #GNUNET_NO
295  */
296 static int
297 should_run_sensor (struct GNUNET_SENSOR_SensorInfo *sensorinfo)
298 {
299   struct GNUNET_TIME_Absolute now;
300
301   if (GNUNET_NO == sensorinfo->enabled)
302   {
303     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
304                 "Sensor `%s' is disabled, will not run\n", sensorinfo->name);
305     return GNUNET_NO;
306   }
307   now = GNUNET_TIME_absolute_get ();
308   if (NULL != sensorinfo->start_time &&
309       now.abs_value_us < sensorinfo->start_time->abs_value_us)
310   {
311     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
312                 "Start time for sensor `%s' not reached yet, will not run\n",
313                 sensorinfo->name);
314     return GNUNET_NO;
315   }
316   if (NULL != sensorinfo->end_time &&
317       now.abs_value_us >= sensorinfo->end_time->abs_value_us)
318   {
319     GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Sensor `%s' expired, disabling.\n",
320                 sensorinfo->name);
321     set_sensor_enabled (sensorinfo, GNUNET_NO);
322     return GNUNET_NO;
323   }
324   return GNUNET_YES;
325 }
326
327
328 /**
329  * Callback function to process statistic values
330  *
331  * @param cls `struct GNUNET_SENSOR_SensorInfo *`
332  * @param ss name of subsystem that created the statistic
333  * @param name the name of the datum
334  * @param value the current value
335  * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
336  * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
337  */
338 static int
339 sensor_statistics_iterator (void *cls, const char *ss, const char *name,
340                             uint64_t value, int is_persistent)
341 {
342   struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
343   double dvalue = (double) value;
344   struct GNUNET_TIME_Absolute expiry;
345
346   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
347               "Received a value for sensor `%s': %" PRIu64 "\n",
348               sensorinfo->name, value);
349   expiry = GNUNET_TIME_relative_to_absolute (sensorinfo->lifetime);
350   GNUNET_PEERSTORE_store (peerstore, subsystem, &peerid, sensorinfo->name,
351                           &dvalue, sizeof (dvalue), expiry,
352                           GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
353   return GNUNET_SYSERR;         /* We only want one value */
354 }
355
356
357 /**
358  * Continuation called after sensor gets all gnunet statistics values
359  *
360  * @param cls `struct GNUNET_SENSOR_SensorInfo *`
361  * @param success #GNUNET_OK if statistics were
362  *        successfully obtained, #GNUNET_SYSERR if not.
363  */
364 static void
365 end_sensor_run_stat (void *cls, int success)
366 {
367   struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
368
369   sensorinfo->gnunet_stat_get_handle = NULL;
370   sensorinfo->running = GNUNET_NO;
371 }
372
373
374 /**
375  * Tries to parse a received sensor value to its
376  * expected datatype
377  *
378  * @param value the string value received, should be null terminated
379  * @param sensor sensor information struct
380  * @param ret pointer to parsed value
381  * @return size of new parsed value, 0 for error
382  */
383 static size_t
384 parse_sensor_value (const char *value, struct GNUNET_SENSOR_SensorInfo *sensor,
385                     void **ret)
386 {
387   double *dval;
388   char *endptr;
389
390   *ret = NULL;
391   if ('\0' == *value)
392     return 0;
393   if (0 == strcmp ("numeric", sensor->expected_datatype))
394   {
395     dval = GNUNET_new (double);
396
397     *dval = strtod (value, &endptr);
398     if (value == endptr)
399       return 0;
400     *ret = dval;
401     return sizeof (double);
402   }
403   if (0 == strcmp ("string", sensor->expected_datatype))
404   {
405     *ret = GNUNET_strdup (value);
406     return strlen (value) + 1;
407   }
408   GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409               _
410               ("Unknown value type expected by sensor, this should not happen.\n"));
411   return 0;
412 }
413
414
415 /**
416  * Callback for output of executed sensor process
417  *
418  * @param cls `struct GNUNET_SENSOR_SensorInfo *`
419  * @param line line of output from a command, NULL for the end
420  */
421 static void
422 sensor_process_callback (void *cls, const char *line)
423 {
424   struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
425   void *value;
426   size_t valsize;
427   struct GNUNET_TIME_Absolute expiry;
428
429   if (NULL == line)
430   {
431     GNUNET_OS_command_stop (sensorinfo->ext_cmd);
432     sensorinfo->ext_cmd = NULL;
433     sensorinfo->running = GNUNET_NO;
434     sensorinfo->ext_cmd_value_received = GNUNET_NO;
435     return;
436   }
437   if (GNUNET_YES == sensorinfo->ext_cmd_value_received)
438     return;                     /* We only want one *valid* value */
439   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received a value for sensor `%s': %s\n",
440               sensorinfo->name, line);
441   valsize = parse_sensor_value (line, sensorinfo, &value);
442   if (valsize == 0)             /* invalid value, FIXME: should we disable the sensor now? */
443   {
444     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
445                 _("Received an invalid value for sensor `%s': %s\n"),
446                 sensorinfo->name, line);
447   }
448   else
449   {
450     sensorinfo->ext_cmd_value_received = GNUNET_YES;
451     expiry = GNUNET_TIME_relative_to_absolute (sensorinfo->lifetime);
452     GNUNET_PEERSTORE_store (peerstore, subsystem, &peerid, sensorinfo->name,
453                             value, valsize, expiry,
454                             GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, NULL, NULL);
455     GNUNET_free (value);
456   }
457 }
458
459
460 /**
461  * Checks if the given file is a path
462  *
463  * @return #GNUNET_YES / #GNUNET_NO
464  */
465 static int
466 is_path (char *filename)
467 {
468   size_t filename_len;
469   int i;
470
471   filename_len = strlen (filename);
472   for (i = 0; i < filename_len; i++)
473   {
474     if (DIR_SEPARATOR == filename[i])
475       return GNUNET_YES;
476   }
477   return GNUNET_NO;
478 }
479
480
481 /**
482  * Actual execution of a sensor
483  *
484  * @param cls 'struct SensorInfo'
485  * @param tc unsed
486  */
487 static void
488 sensor_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
489 {
490   struct GNUNET_SENSOR_SensorInfo *sensorinfo = cls;
491   int check_result;
492   char *process_path;
493
494   sensorinfo->execution_task =
495       GNUNET_SCHEDULER_add_delayed (sensorinfo->interval, &sensor_run,
496                                     sensorinfo);
497   if (GNUNET_YES == sensorinfo->running)        //FIXME: should we try to kill?
498   {
499     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
500                 "Sensor `%s' running for too long, will try again next interval\n",
501                 sensorinfo->name);
502     return;
503   }
504   if (GNUNET_NO == should_run_sensor (sensorinfo))
505     return;
506   sensorinfo->running = GNUNET_YES;
507   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
508               "Starting the execution of sensor `%s'\n", sensorinfo->name);
509   if (0 == strcmp ("gnunet-statistics", sensorinfo->source))
510   {
511     sensorinfo->gnunet_stat_get_handle = GNUNET_STATISTICS_get (statistics, sensorinfo->gnunet_stat_service, sensorinfo->gnunet_stat_name, sensorinfo->interval,        //try to get values only for the interval of the sensor
512                                                                 &end_sensor_run_stat,
513                                                                 &sensor_statistics_iterator,
514                                                                 sensorinfo);
515   }
516   else if (0 == strcmp ("process", sensorinfo->source))
517   {
518     if (GNUNET_YES == is_path (sensorinfo->ext_process))
519     {
520       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
521                   _
522                   ("Sensor `%s': External process should not be a path, disabling sensor.\n"),
523                   sensorinfo->name);
524       set_sensor_enabled (sensorinfo, GNUNET_NO);
525       return;
526     }
527     //check if the process exists in $PATH
528     process_path = GNUNET_strdup (sensorinfo->ext_process);
529     check_result =
530         GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL);
531     if (GNUNET_SYSERR == check_result)
532     {
533       //search in sensor directory
534       GNUNET_free (process_path);
535       GNUNET_asprintf (&process_path, "%s%s-files%s%s", sensor_dir,
536                        sensorinfo->name, DIR_SEPARATOR_STR,
537                        sensorinfo->ext_process);
538       GNUNET_free (sensor_dir);
539       check_result =
540           GNUNET_OS_check_helper_binary (process_path, GNUNET_NO, NULL);
541     }
542     if (GNUNET_SYSERR == check_result)
543     {
544       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
545                   _
546                   ("Sensor `%s' process `%s' problem: binary doesn't exist or not executable\n"),
547                   sensorinfo->name, sensorinfo->ext_process);
548       set_sensor_enabled (sensorinfo, GNUNET_NO);
549       sensorinfo->running = GNUNET_NO;
550       GNUNET_free (process_path);
551       return;
552     }
553     sensorinfo->ext_cmd_value_received = GNUNET_NO;
554     sensorinfo->ext_cmd =
555         GNUNET_OS_command_run (&sensor_process_callback, sensorinfo,
556                                GNUNET_TIME_UNIT_FOREVER_REL, process_path,
557                                sensorinfo->ext_process, sensorinfo->ext_args,
558                                NULL);
559     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Process started for sensor `%s'\n",
560                 sensorinfo->name);
561     GNUNET_free (process_path);
562   }
563   else
564   {
565     sensorinfo->running = GNUNET_NO;
566     GNUNET_break (0);           /* shouldn't happen */
567   }
568 }
569
570
571 /**
572  * Starts the execution of a sensor
573  *
574  * @param cls unused
575  * @param key hash of sensor name, key to hashmap (unused)
576  * @param value a `struct GNUNET_SENSOR_SensorInfo *`
577  * @return #GNUNET_YES if we should continue to
578  *         iterate,
579  *         #GNUNET_NO if not.
580  */
581 static int
582 schedule_sensor (void *cls, const struct GNUNET_HashCode *key, void *value)
583 {
584   struct GNUNET_SENSOR_SensorInfo *sensorinfo = value;
585
586   if (GNUNET_NO == should_run_sensor (sensorinfo))
587     return GNUNET_YES;
588   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
589               "Scheduling sensor `%s' to run after %" PRIu64 " microseconds\n",
590               sensorinfo->name, sensorinfo->interval.rel_value_us);
591   if (GNUNET_SCHEDULER_NO_TASK != sensorinfo->execution_task)
592   {
593     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
594                 _
595                 ("Sensor `%s' execution task already set, this should not happen\n"),
596                 sensorinfo->name);
597     return GNUNET_NO;
598   }
599   sensorinfo->execution_task =
600       GNUNET_SCHEDULER_add_delayed (sensorinfo->interval, &sensor_run,
601                                     sensorinfo);
602   return GNUNET_YES;
603 }
604
605
606 /**
607  * Starts the execution of all enabled sensors
608  */
609 static void
610 schedule_all_sensors ()
611 {
612   GNUNET_CONTAINER_multihashmap_iterate (sensors, &schedule_sensor, NULL);
613 }
614
615
616 /**
617  * Loads sensors and starts different service components
618  */
619 static void
620 start ()
621 {
622   sensors = GNUNET_SENSOR_load_all_sensors (sensor_dir);
623   schedule_all_sensors ();
624   SENSOR_reporting_value_start (cfg, sensors);
625   SENSOR_reporting_anomaly_start (cfg, sensors);
626   SENSOR_analysis_start (cfg, sensors);
627   SENSOR_update_start (cfg, sensors, &reset);
628 }
629
630
631 /**
632  * Process statistics requests.
633  *
634  * @param cls closure
635  * @param server the initialized server
636  * @param c configuration to use
637  */
638 static void
639 run (void *cls, struct GNUNET_SERVER_Handle *server,
640      const struct GNUNET_CONFIGURATION_Handle *c)
641 {
642   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
643     {&handle_get_sensor, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GET,
644      0},
645     {&handle_get_all_sensors, NULL, GNUNET_MESSAGE_TYPE_SENSOR_GETALL,
646      sizeof (struct GNUNET_MessageHeader)},
647     {NULL, NULL, 0, 0}
648   };
649
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 ();
655   statistics = GNUNET_STATISTICS_create ("sensor", cfg);
656   GNUNET_CRYPTO_get_peer_identity (cfg, &peerid);
657   peerstore = GNUNET_PEERSTORE_connect (cfg);
658   GNUNET_SERVER_add_handlers (server, handlers);
659   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
660   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
661                                 NULL);
662   start ();
663 }
664
665
666 /**
667  * Resets the service by stopping components, reloading sensors and starting
668  * components. This is needed when we receive new sensor updates.
669  */
670 static void
671 reset ()
672 {
673   stop ();
674   start ();
675 }
676
677
678 /**
679  * The main function for the sensor service.
680  *
681  * @param argc number of arguments from the command line
682  * @param argv command line arguments
683  * @return 0 ok, 1 on error
684  */
685 int
686 main (int argc, char *const *argv)
687 {
688   return (GNUNET_OK ==
689           GNUNET_SERVICE_run (argc, argv, "sensor", GNUNET_SERVICE_OPTION_NONE,
690                               &run, NULL)) ? 0 : 1;
691 }
692
693 /* end of gnunet-service-sensor.c */