aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/testbed_api_cmd_controller.c1
-rw-r--r--src/testbed/testbed_api_cmd_peer.c40
-rw-r--r--src/testbed/testbed_api_cmd_peer_store.c60
-rw-r--r--src/testbed/testbed_api_cmd_service.c140
-rw-r--r--src/testbed/testbed_api_cmd_tng_connect.c55
-rw-r--r--src/testbed/testbed_api_cmd_tng_service.c276
6 files changed, 427 insertions, 145 deletions
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c
index d65f41760..da23df1ef 100644
--- a/src/testbed/testbed_api_cmd_controller.c
+++ b/src/testbed/testbed_api_cmd_controller.c
@@ -121,7 +121,6 @@ registration_comp (void *cls,
121 { 121 {
122 cs->reg_handle = NULL; 122 cs->reg_handle = NULL;
123 cs->host_ready = GNUNET_YES; 123 cs->host_ready = GNUNET_YES;
124 GNUNET_TESTING_interpreter_next (cs->is);
125 } 124 }
126} 125}
127 126
diff --git a/src/testbed/testbed_api_cmd_peer.c b/src/testbed/testbed_api_cmd_peer.c
index 4a727bc94..2e253e408 100644
--- a/src/testbed/testbed_api_cmd_peer.c
+++ b/src/testbed/testbed_api_cmd_peer.c
@@ -20,8 +20,8 @@
20 20
21 21
22/** 22/**
23 * @file testbed/testbed_api_cmd_controller.c 23 * @file testbed/testbed_api_cmd_peer.c
24 * @brief Command to create a controller. 24 * @brief Command to create a peer.
25 * @author t3sserakt 25 * @author t3sserakt
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
@@ -54,10 +54,43 @@ peer_traits (void *cls,
54 const char *trait, 54 const char *trait,
55 unsigned int index) 55 unsigned int index)
56{ 56{
57 (void) cls; 57 struct PeerCmdState *ps = cls;
58
59 struct GNUNET_TESTING_Trait traits[] = {
60 {
61 .index = 0,
62 .trait_name = "peer",
63 .ptr = (const void *) ps->peer,
64 },
65 GNUNET_TESTING_trait_end ()
66 };
67
68 return GNUNET_TESTING_get_trait (traits,
69 ret,
70 trait,
71 index);
72
58 return GNUNET_OK; 73 return GNUNET_OK;
59} 74}
60 75
76/**
77 * Offer data from trait
78 *
79 * @param cmd command to extract the controller from.
80 * @param peer pointer GNUNET_TESTBED_PEER
81 * @return #GNUNET_OK on success.
82 */
83int
84GNUNET_TESTBED_get_trait_peer (const struct GNUNET_TESTING_Command *cmd,
85 struct GNUNET_TESTBED_Peer **
86 peer)
87{
88 return cmd->traits (cmd->cls,
89 (const void **) peer,
90 "peer",
91 (unsigned int) 0);
92}
93
61 94
62/** 95/**
63* 96*
@@ -110,7 +143,6 @@ peer_started_cb (void *cls,
110 if (NULL == emsg) 143 if (NULL == emsg)
111 { 144 {
112 ps->peer_ready = GNUNET_YES; 145 ps->peer_ready = GNUNET_YES;
113 GNUNET_TESTING_interpreter_next (ps->is);
114 } 146 }
115 else 147 else
116 { 148 {
diff --git a/src/testbed/testbed_api_cmd_peer_store.c b/src/testbed/testbed_api_cmd_peer_store.c
new file mode 100644
index 000000000..fc96f589c
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_peer_store.c
@@ -0,0 +1,60 @@
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_peer_store.c
23 * @brief Command to start the peer store service of a peer.
24 * @author t3sserakt
25 */
26
27
28static void
29service_run (void *cls,
30 const struct GNUNET_TESTING_Command *cmd,
31 struct GNUNET_TESTING_Interpreter *is)
32{
33 struct PeerStoreState *pss = cls;
34
35 pss->psh = GNUNET_PEERSTORE_connect (pss->cfg);
36 GNUNET_TESTING_interpreter_next (ps->is);
37}
38
39
40struct GNUNET_TESTING_Command
41GNUNET_TESTBED_cmd_peer_store (const char *label,
42 struct GNUNET_CONFIGURATION_Handle *cfg)
43{
44
45 struct PeerStoreState *pss;
46
47 pss = GNUNET_new (struct PeerStoreState);
48 pss->cfg = cfg;
49
50 struct GNUNET_TESTING_Command cmd = {
51 .cls = pss,
52 .label = label,
53 .run = &peer_store_run,
54 .cleanup = &peer_store_cleanup,
55 .traits = &peer_store_traits
56 };
57
58 return cmd;
59
60}
diff --git a/src/testbed/testbed_api_cmd_service.c b/src/testbed/testbed_api_cmd_service.c
deleted file mode 100644
index 58b3309de..000000000
--- a/src/testbed/testbed_api_cmd_service.c
+++ /dev/null
@@ -1,140 +0,0 @@
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}
diff --git a/src/testbed/testbed_api_cmd_tng_connect.c b/src/testbed/testbed_api_cmd_tng_connect.c
new file mode 100644
index 000000000..e52cd3c76
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_tng_connect.c
@@ -0,0 +1,55 @@
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/**
23 * @file testbed/testbed_api_cmd_peer.c
24 * @brief Command to create a peer.
25 * @author t3sserakt
26 */
27
28
29static void
30tng_connect_run (void *cls,
31 const struct GNUNET_TESTING_Command *cmd,
32 struct GNUNET_TESTING_Interpreter *is)
33{
34 struct TngConnectState *tcs = cls;
35
36 tcs->ah = GNUNET_TRANSPORT_application_init (tcs->cfg);
37}
38
39struct GNUNET_TESTING_Command
40GNUNET_TESTBED_cmd_tng_connect (const char *label)
41{
42 struct TngConnectState *tcs;
43
44 ts = GNUNET_new (struct TngConnectState);
45
46 struct GNUNET_TESTING_Command cmd = {
47 .cls = tcs,
48 .label = label,
49 .run = &tng_connect_run,
50 .cleanup = &tmg_connect_cleanup,
51 .traits = &tng_connect_traits
52 };
53
54 return cmd;
55}
diff --git a/src/testbed/testbed_api_cmd_tng_service.c b/src/testbed/testbed_api_cmd_tng_service.c
new file mode 100644
index 000000000..f9ef44bad
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_tng_service.c
@@ -0,0 +1,276 @@
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_tng.c
23 * @brief Command to start the transport service of a peer.
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 TngState *ts = cls;
50
51 if (GNUNET_NO == ts->service_ready)
52 {
53 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
54 ts->abort_task = NULL;
55 GNUNET_TESTBED_shutdown_service (ts);
56 }
57}
58
59/**
60*
61*
62* @param cls closure
63* @param cmd current CMD being cleaned up.
64*/
65static void
66tng_service_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
82tng_service_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
91
92static void *
93notify_connect (void *cls,
94 const struct GNUNET_PeerIdentity *peer,
95 struct GNUNET_MQ_Handle *mq)
96{
97 struct TngState *ts = cls;
98
99 if (NULL != emsg)
100 {
101 LOG (GNUNET_ERROR_TYPE_ERROR,
102 "There was an error starting the transport subsystem: %s\n",
103 emsg);
104 }
105 GNUNET_TESTING_interpreter_next (ps->is);
106 return ts->nc (ts->cb_cls);
107
108}
109
110
111static void
112notify_disconnect (void *cls,
113 const struct GNUNET_PeerIdentity *peer,
114 void *handler_cls)
115{
116}
117
118
119
120
121/**
122 * Adapter function called to establish a connection to
123 * a service.
124 *
125 * @param cls closure
126 * @param cfg configuration of the peer to connect to; will be available until
127 * GNUNET_TESTBED_operation_done() is called on the operation returned
128 * from GNUNET_TESTBED_service_connect()
129 * @return service handle to return in 'op_result', NULL on error
130 */
131static void *
132connect_adapter (void *cls,
133 const struct GNUNET_CONFIGURATION_Handle *cfg)
134{
135 struct TngState *ts = cls;
136
137 service_handle = GNUNET_TRANSPORT_core_connect (cfg,
138 ts->peer_identity,
139 ts->handlers,
140 ts,
141 &notify_connect,
142 &notify_disconnect);
143 return service_handle;
144}
145
146
147/**
148 * Adapter function called to destroy a connection to
149 * a service.
150 *
151 * @param cls closure
152 * @param op_result service handle returned from the connect adapter
153 */
154static void
155disconnect_adapter (void *cls,
156 void *op_result)
157{
158}
159
160/**
161 * Callback to be called when a service connect operation is completed
162 *
163 * @param cls the callback closure from functions generating an operation
164 * @param op the operation that has been finished
165 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
166 * @param emsg error message in case the operation has failed; will be NULL if
167 * operation has executed successfully.
168 */
169static void
170service_connect_comp_cb (void *cls,
171 struct GNUNET_TESTBED_Operation *op,
172 void *ca_result,
173 const char *emsg)
174{
175 struct TngState *ts = cls;
176
177 if (NULL != emsg)
178 {
179 LOG (GNUNET_ERROR_TYPE_DEBUG,
180 "An error occured connecting to service %s\n",
181 emsg);
182 GNUNET_TESTBED_operation_done (ts->operation);
183 }
184}
185
186
187/**
188 * Callback to be called when the requested peer information is available
189 *
190 * @param cls the closure from GNUNET_TESTBED_peer_getinformation()
191 * @param op the operation this callback corresponds to
192 * @param pinfo the result; will be NULL if the operation has failed
193 * @param emsg error message if the operation has failed;
194 * NULL if the operation is successfull
195 */
196static void
197pi_cb (void *cls,
198 struct GNUNET_TESTBED_Operation *op,
199 const struct GNUNET_TESTBED_PeerInformation *pinfo,
200 const char *emsg)
201{
202 struct TngState *ts = cls;
203
204 ts->peer_identity = pinfo->id;
205 ts->operation =
206 GNUNET_TESTBED_service_connect (NULL, peer, NULL,
207 &service_connect_comp_cb, ts,
208 &connect_adapter,
209 &disconnect_adapter,
210 ts);
211}
212
213
214static void
215tng_service_run (void *cls,
216 const struct GNUNET_TESTING_Command *cmd,
217 struct GNUNET_TESTING_Interpreter *is)
218{
219 struct TngState *ts = cls;
220 struct GNUNET_TESTBED_Peer *peer;
221 const struct GNUNET_TESTING_Command *peer_cmd;
222
223 ts->is = is;
224 peer_cmd = GNUNET_TESTING_interpreter_lookup_command (
225 ts->peer_label);
226 GNUNET_TESTBED_get_trait_peer (peer_cmd,
227 &peer);
228
229 ts->operation = GNUNET_TESTBED_peer_get_information (peer,
230 GNUNET_TESTBED_PIT_IDENTITY,
231 &pi_cb,
232 ts);
233}
234
235/**
236 * Shutdown nicely
237 *
238 * @param cs service state.
239 */
240void
241GNUNET_TESTBED_shutdown_service (struct TngState *cs)
242{
243 LOG (GNUNET_ERROR_TYPE_DEBUG,
244 "Shutting down...\n");
245}
246
247
248struct GNUNET_TESTING_Command
249GNUNET_TESTBED_cmd_tng_service (const char *label,
250 const char *peer_label,
251 const struct GNUNET_MQ_MessageHandler *handlers,
252 GNUNET_TRANSPORT_NotifyConnect nc,
253 void *cb_cls)
254
255{
256 struct TngState *ts;
257
258 ts = GNUNET_new (struct TngState);
259 ts->servicename = servicename;
260 ts->peer_label = peer_label;
261 ts->handlers = handlers;
262 ts->nc = nc;
263 ts->nd = nd;
264 ts->cb_cls;
265
266
267 struct GNUNET_TESTING_Command cmd = {
268 .cls = ts,
269 .label = label,
270 .run = &tng_service_run,
271 .cleanup = &tmg_service_cleanup,
272 .traits = &tng_service_traits
273 };
274
275 return cmd;
276}