diff options
Diffstat (limited to 'src/testbed/testbed_api_cmd_tng_service.c')
-rw-r--r-- | src/testbed/testbed_api_cmd_tng_service.c | 276 |
1 files changed, 0 insertions, 276 deletions
diff --git a/src/testbed/testbed_api_cmd_tng_service.c b/src/testbed/testbed_api_cmd_tng_service.c deleted file mode 100644 index cce2e14e3..000000000 --- a/src/testbed/testbed_api_cmd_tng_service.c +++ /dev/null | |||
@@ -1,276 +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_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 | */ | ||
46 | static void | ||
47 | do_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 | */ | ||
65 | static void | ||
66 | tng_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 | */ | ||
81 | static int | ||
82 | tng_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 | |||
92 | static void * | ||
93 | notify_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 | |||
111 | static void | ||
112 | notify_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 | */ | ||
131 | static void * | ||
132 | connect_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 | ¬ify_connect, | ||
142 | ¬ify_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 | */ | ||
154 | static void | ||
155 | disconnect_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 | */ | ||
169 | static void | ||
170 | service_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 occurred 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 successful | ||
195 | */ | ||
196 | static void | ||
197 | pi_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 | |||
214 | static void | ||
215 | tng_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 | */ | ||
240 | void | ||
241 | GNUNET_TESTBED_shutdown_service (struct TngState *cs) | ||
242 | { | ||
243 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
244 | "Shutting down...\n"); | ||
245 | } | ||
246 | |||
247 | |||
248 | struct GNUNET_TESTING_Command | ||
249 | GNUNET_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 | } | ||