gnunet-peerstore.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C)
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file peerstore/gnunet-peerstore.c
  18. * @brief peerstore tool
  19. * @author Omar Tarabai
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "gnunet_peerstore_service.h"
  24. static int ret;
  25. /*
  26. * Handle to PEERSTORE service
  27. */
  28. static struct GNUNET_PEERSTORE_Handle *peerstore_handle;
  29. /**
  30. * Run on shutdown
  31. *
  32. * @param cls unused
  33. */
  34. static void
  35. shutdown_task (void *cls)
  36. {
  37. if (NULL != peerstore_handle)
  38. {
  39. GNUNET_PEERSTORE_disconnect (peerstore_handle, GNUNET_YES);
  40. peerstore_handle = NULL;
  41. }
  42. }
  43. /**
  44. * Main function that will be run by the scheduler.
  45. *
  46. * @param cls closure
  47. * @param args remaining command-line arguments
  48. * @param cfgfile name of the configuration file used (for saving, can be NULL!)
  49. * @param cfg configuration
  50. */
  51. static void
  52. run (void *cls,
  53. char *const *args,
  54. const char *cfgfile,
  55. const struct GNUNET_CONFIGURATION_Handle *cfg)
  56. {
  57. GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
  58. NULL);
  59. peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
  60. GNUNET_assert (NULL != peerstore_handle);
  61. ret = 0;
  62. }
  63. /**
  64. * The main function to peerstore.
  65. *
  66. * @param argc number of arguments from the command line
  67. * @param argv command line arguments
  68. * @return 0 ok, 1 on error
  69. */
  70. int
  71. main (int argc, char *const *argv)
  72. {
  73. static const struct GNUNET_GETOPT_CommandLineOption options[] = {
  74. GNUNET_GETOPT_OPTION_END
  75. };
  76. return (GNUNET_OK ==
  77. GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]",
  78. gettext_noop ("peerstore"), options, &run,
  79. NULL)) ? ret : 1;
  80. }
  81. /* end of gnunet-peerstore.c */