aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_cmd_service.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_cmd_service.c')
-rw-r--r--src/testbed/testbed_api_cmd_service.c140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/testbed/testbed_api_cmd_service.c b/src/testbed/testbed_api_cmd_service.c
new file mode 100644
index 000000000..58b3309de
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_service.c
@@ -0,0 +1,140 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/testbed_api_cmd_controller.c
23 * @brief Command to create a controller.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet-service-testbed.h"
30#include "testbed_api_hosts.h"
31#include "gnunet_testbed_ng_service.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) \
37 GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * abort task to run on test timed out
42 *
43 * @param cls NULL
44 * @param tc the task context
45 */
46static void
47do_abort (void *cls)
48{
49 struct ServiceState *ss = cls;
50
51 if (GNUNET_NO == ss->service_ready)
52 {
53 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54 ss->abort_task = NULL;
55 GNUNET_TESTBED_shutdown_service (ss);
56 }
57}
58
59/**
60*
61*
62* @param cls closure
63* @param cmd current CMD being cleaned up.
64*/
65static void
66service_cleanup (void *cls,
67 const struct GNUNET_TESTING_Command *cmd)
68{
69 (void) cls;
70}
71
72/**
73*
74*
75* @param cls closure.
76* @param[out] ret result
77* @param trait name of the trait.
78* @param index index number of the object to offer.
79* @return #GNUNET_OK on success.
80*/
81static int
82service_traits (void *cls,
83 const void **ret,
84 const char *trait,
85 unsigned int index)
86{
87 (void) cls;
88 return GNUNET_OK;
89}
90
91static void
92service_run (void *cls,
93 const struct GNUNET_TESTING_Command *cmd,
94 struct GNUNET_TESTING_Interpreter *is)
95{
96 struct ServiceState *ss = cls;
97
98 // TODO this is unfinished code!
99 ss->operation =
100 GNUNET_TESTBED_service_connect (NULL, NULL, NULL,
101 NULL, NULL,
102 NULL,
103 NULL, NULL);
104
105}
106
107/**
108 * Shutdown nicely
109 *
110 * @param cs service state.
111 */
112void
113GNUNET_TESTBED_shutdown_service (struct ServiceState *cs)
114{
115 LOG (GNUNET_ERROR_TYPE_DEBUG,
116 "Shutting down...\n");
117}
118
119
120struct GNUNET_TESTING_Command
121GNUNET_TESTBED_cmd_service (const char *label,
122 const char *peer_label,
123 const char *servicename)
124{
125 struct ServiceState *ss;
126
127 ss = GNUNET_new (struct ServiceState);
128 ss->servicename = servicename;
129 ss->peer_label = peer_label;
130
131 struct GNUNET_TESTING_Command cmd = {
132 .cls = ss,
133 .label = label,
134 .run = &service_run,
135 .cleanup = &service_cleanup,
136 .traits = &service_traits
137 };
138
139 return cmd;
140}