testbed_api_cmd_service.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2021 GNUnet e.V.
  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 testbed/testbed_api_cmd_controller.c
  18. * @brief Command to create a controller.
  19. * @author t3sserakt
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "gnunet_testing_ng_lib.h"
  24. #include "gnunet-service-testbed.h"
  25. #include "testbed_api_hosts.h"
  26. #include "gnunet_testbed_ng_service.h"
  27. /**
  28. * Generic logging shortcut
  29. */
  30. #define LOG(kind, ...) \
  31. GNUNET_log (kind, __VA_ARGS__)
  32. /**
  33. * abort task to run on test timed out
  34. *
  35. * @param cls NULL
  36. * @param tc the task context
  37. */
  38. static void
  39. do_abort (void *cls)
  40. {
  41. struct ServiceState *ss = cls;
  42. if (GNUNET_NO == ss->service_ready)
  43. {
  44. LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
  45. ss->abort_task = NULL;
  46. GNUNET_TESTBED_shutdown_service (ss);
  47. }
  48. }
  49. /**
  50. *
  51. *
  52. * @param cls closure
  53. * @param cmd current CMD being cleaned up.
  54. */
  55. static void
  56. service_cleanup (void *cls,
  57. const struct GNUNET_TESTING_Command *cmd)
  58. {
  59. (void) cls;
  60. }
  61. /**
  62. *
  63. *
  64. * @param cls closure.
  65. * @param[out] ret result
  66. * @param trait name of the trait.
  67. * @param index index number of the object to offer.
  68. * @return #GNUNET_OK on success.
  69. */
  70. static int
  71. service_traits (void *cls,
  72. const void **ret,
  73. const char *trait,
  74. unsigned int index)
  75. {
  76. (void) cls;
  77. return GNUNET_OK;
  78. }
  79. static void
  80. service_run (void *cls,
  81. const struct GNUNET_TESTING_Command *cmd,
  82. struct GNUNET_TESTING_Interpreter *is)
  83. {
  84. struct ServiceState *ss = cls;
  85. // TODO this is unfinished code!
  86. ss->operation =
  87. GNUNET_TESTBED_service_connect (NULL, NULL, NULL,
  88. NULL, NULL,
  89. NULL,
  90. NULL, NULL);
  91. }
  92. /**
  93. * Shutdown nicely
  94. *
  95. * @param cs service state.
  96. */
  97. void
  98. GNUNET_TESTBED_shutdown_service (struct ServiceState *cs)
  99. {
  100. LOG (GNUNET_ERROR_TYPE_DEBUG,
  101. "Shutting down...\n");
  102. }
  103. struct GNUNET_TESTING_Command
  104. GNUNET_TESTBED_cmd_service (const char *label,
  105. const char *peer_label,
  106. const char *servicename)
  107. {
  108. struct ServiceState *ss;
  109. ss = GNUNET_new (struct ServiceState);
  110. ss->servicename = servicename;
  111. ss->peer_label = peer_label;
  112. struct GNUNET_TESTING_Command cmd = {
  113. .cls = ss,
  114. .label = label,
  115. .run = &service_run,
  116. .cleanup = &service_cleanup,
  117. .traits = &service_traits
  118. };
  119. return cmd;
  120. }