gnunet-daemon-experimentation.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2009 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file experimentation/gnunet-daemon-experimentation.c
  19. * @brief experimentation daemon
  20. * @author Christian Grothoff
  21. * @author Matthias Wachs
  22. */
  23. #include "platform.h"
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet_core_service.h"
  26. #include "gnunet_statistics_service.h"
  27. #include "gnunet-daemon-experimentation.h"
  28. /**
  29. * Statistics handle shared between components
  30. */
  31. struct GNUNET_STATISTICS_Handle *GED_stats;
  32. /**
  33. * Configuration handle shared between components
  34. */
  35. struct GNUNET_CONFIGURATION_Handle *GED_cfg;
  36. /**
  37. * Task run during shutdown to stop all submodules of the experimentation daemon.
  38. *
  39. * @param cls unused
  40. * @param tc unused
  41. */
  42. static void
  43. shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  44. {
  45. GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Experimentation daemon shutting down ...\n"));
  46. GED_scheduler_stop ();
  47. GED_nodes_stop ();
  48. GED_experiments_stop ();
  49. GED_storage_stop ();
  50. GED_capabilities_stop ();
  51. }
  52. /**
  53. * Function starting all submodules of the experimentation daemon.
  54. *
  55. * @param cls always NULL
  56. * @param args temaining command line arguments
  57. * @param cfgfile configuration file used
  58. * @param cfg configuration handle
  59. */
  60. static void
  61. run (void *cls, char *const *args, const char *cfgfile,
  62. const struct GNUNET_CONFIGURATION_Handle *cfg)
  63. {
  64. GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Experimentation daemon starting ...\n"));
  65. GED_cfg = (struct GNUNET_CONFIGURATION_Handle *) cfg;
  66. GED_stats = GNUNET_STATISTICS_create ("experimentation", cfg);
  67. if (NULL == GED_stats)
  68. {
  69. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to create statistics!\n"));
  70. return;
  71. }
  72. GED_capabilities_start ();
  73. GED_storage_start ();
  74. if (GNUNET_SYSERR == GED_experiments_start ())
  75. {
  76. GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
  77. return;
  78. }
  79. GED_nodes_start ();
  80. GED_scheduler_start ();
  81. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
  82. NULL);
  83. }
  84. /**
  85. * The main function for the experimentation daemon.
  86. *
  87. * @param argc number of arguments from the command line
  88. * @param argv command line arguments
  89. * @return 0 ok, 1 on error
  90. */
  91. int
  92. main (int argc, char *const *argv)
  93. {
  94. static const struct GNUNET_GETOPT_CommandLineOption options[] = {
  95. GNUNET_GETOPT_OPTION_END
  96. };
  97. return (GNUNET_OK ==
  98. GNUNET_PROGRAM_run (argc, argv, "experimentation",
  99. _("GNUnet experimentation daemon"), options,
  100. &run, NULL)) ? 0 : 1;
  101. }
  102. /* end of gnunet-daemon-experimentation.c */