diff options
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/Makefile.am | 3 | ||||
-rw-r--r-- | src/testbed/testbed_api_cmd_controller.c | 294 | ||||
-rw-r--r-- | src/testbed/testbed_api_cmd_peer.c | 249 | ||||
-rw-r--r-- | src/testbed/testbed_api_cmd_service.c | 140 |
4 files changed, 686 insertions, 0 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 7c1e217bb..7a59670cb 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -94,6 +94,9 @@ lib_LTLIBRARIES = \ | |||
94 | libgnunettestbed_la_SOURCES = \ | 94 | libgnunettestbed_la_SOURCES = \ |
95 | testbed_api.c testbed_api.h testbed.h \ | 95 | testbed_api.c testbed_api.h testbed.h \ |
96 | testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ | 96 | testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ |
97 | testbed_api_cmd_controller.c \ | ||
98 | testbed_api_cmd_peer.c \ | ||
99 | testbed_api_cmd_service.c \ | ||
97 | testbed_api_operations.c testbed_api_operations.h \ | 100 | testbed_api_operations.c testbed_api_operations.h \ |
98 | testbed_api_peers.c testbed_api_peers.h \ | 101 | testbed_api_peers.c testbed_api_peers.h \ |
99 | testbed_api_services.c \ | 102 | testbed_api_services.c \ |
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c new file mode 100644 index 000000000..d65f41760 --- /dev/null +++ b/src/testbed/testbed_api_cmd_controller.c | |||
@@ -0,0 +1,294 @@ | |||
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 | /** | ||
35 | * Generic logging shortcut | ||
36 | */ | ||
37 | #define LOG(kind, ...) \ | ||
38 | GNUNET_log (kind, __VA_ARGS__) | ||
39 | |||
40 | |||
41 | /** | ||
42 | * abort task to run on test timed out | ||
43 | * | ||
44 | * @param cls NULL | ||
45 | * @param tc the task context | ||
46 | */ | ||
47 | static void | ||
48 | do_abort (void *cls) | ||
49 | { | ||
50 | struct ControllerState *cs = cls; | ||
51 | |||
52 | if (GNUNET_NO == cs->host_ready) | ||
53 | { | ||
54 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | ||
55 | cs->abort_task = NULL; | ||
56 | GNUNET_TESTBED_shutdown_controller (cs); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * | ||
63 | * | ||
64 | * @param cls closure | ||
65 | * @param cmd current CMD being cleaned up. | ||
66 | */ | ||
67 | static void | ||
68 | controller_cleanup (void *cls, | ||
69 | const struct GNUNET_TESTING_Command *cmd) | ||
70 | { | ||
71 | (void) cls; | ||
72 | } | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Signature of the event handler function called by the | ||
77 | * respective event controller. | ||
78 | * | ||
79 | * @param cls closure | ||
80 | * @param event information about the event | ||
81 | */ | ||
82 | static void | ||
83 | controller_cb (void *cls, | ||
84 | const struct GNUNET_TESTBED_EventInformation *event) | ||
85 | { | ||
86 | struct ControllerState *cs = cls; | ||
87 | |||
88 | if (NULL != event->details.operation_finished.emsg) | ||
89 | { | ||
90 | LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n", | ||
91 | event->details.operation_finished.emsg); | ||
92 | GNUNET_TESTBED_shutdown_controller (cs); | ||
93 | } | ||
94 | else if (NULL == event->details.operation_finished.generic) | ||
95 | { | ||
96 | GNUNET_TESTBED_operation_done (event->op); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | |||
101 | /** | ||
102 | * Callback which will be called to after a host registration succeeded or failed | ||
103 | * | ||
104 | * @param cls the host which has been registered | ||
105 | * @param emsg the error message; NULL if host registration is successful | ||
106 | */ | ||
107 | static void | ||
108 | registration_comp (void *cls, | ||
109 | const char *emsg) | ||
110 | { | ||
111 | struct ControllerState *cs = cls; | ||
112 | |||
113 | if (NULL != emsg) | ||
114 | { | ||
115 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
116 | "There was an error during host registration: %s\n", | ||
117 | emsg); | ||
118 | GNUNET_TESTBED_shutdown_controller (cs); | ||
119 | } | ||
120 | else | ||
121 | { | ||
122 | cs->reg_handle = NULL; | ||
123 | cs->host_ready = GNUNET_YES; | ||
124 | GNUNET_TESTING_interpreter_next (cs->is); | ||
125 | } | ||
126 | } | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Callback to signal successfull startup of the controller process | ||
131 | * | ||
132 | * @param cls the closure from GNUNET_TESTBED_controller_start() | ||
133 | * @param cfg the configuration with which the controller has been started; | ||
134 | * NULL if status is not #GNUNET_OK | ||
135 | * @param status #GNUNET_OK if the startup is successfull; #GNUNET_SYSERR if not, | ||
136 | * GNUNET_TESTBED_controller_stop() shouldn't be called in this case | ||
137 | */ | ||
138 | static void | ||
139 | controller_status_cb (void *cls, | ||
140 | const struct GNUNET_CONFIGURATION_Handle *cfg_, | ||
141 | int status) | ||
142 | { | ||
143 | struct ControllerState *cs = cls; | ||
144 | |||
145 | if (GNUNET_OK != status) | ||
146 | { | ||
147 | cs->cp = NULL; | ||
148 | return; | ||
149 | } | ||
150 | |||
151 | cs->controller = | ||
152 | GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb, | ||
153 | cs); | ||
154 | cs->reg_handle = | ||
155 | GNUNET_TESTBED_register_host (cs->controller, cs->host, ®istration_comp, | ||
156 | cs); | ||
157 | } | ||
158 | |||
159 | |||
160 | static void | ||
161 | controller_run (void *cls, | ||
162 | const struct GNUNET_TESTING_Command *cmd, | ||
163 | struct GNUNET_TESTING_Interpreter *is) | ||
164 | { | ||
165 | struct ControllerState *cs = cls; | ||
166 | |||
167 | cs->is = is; | ||
168 | cs->host = GNUNET_TESTBED_host_create (cs->hostname, cs->username, cs->cfg, | ||
169 | cs->port); | ||
170 | cs->cp = GNUNET_TESTBED_controller_start (cs->trusted_ip, | ||
171 | cs->host, | ||
172 | &controller_status_cb, | ||
173 | cs); | ||
174 | cs->abort_task = | ||
175 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
176 | (GNUNET_TIME_UNIT_MINUTES, 5), | ||
177 | &do_abort, | ||
178 | cs); | ||
179 | } | ||
180 | |||
181 | /** | ||
182 | * | ||
183 | * | ||
184 | * @param cls closure. | ||
185 | * @param[out] ret result | ||
186 | * @param trait name of the trait. | ||
187 | * @param index index number of the object to offer. | ||
188 | * @return #GNUNET_OK on success. | ||
189 | */ | ||
190 | static int | ||
191 | controller_traits (void *cls, | ||
192 | const void **ret, | ||
193 | const char *trait, | ||
194 | unsigned int index) | ||
195 | { | ||
196 | (void) cls; | ||
197 | |||
198 | struct ControllerState *cs = cls; | ||
199 | |||
200 | |||
201 | struct GNUNET_TESTING_Trait traits[] = { | ||
202 | { | ||
203 | .index = 0, | ||
204 | .trait_name = "controller", | ||
205 | .ptr = (const void *) cs->controller, | ||
206 | }, | ||
207 | GNUNET_TESTING_trait_end () | ||
208 | }; | ||
209 | |||
210 | return GNUNET_TESTING_get_trait (traits, | ||
211 | ret, | ||
212 | trait, | ||
213 | index); | ||
214 | return GNUNET_OK; | ||
215 | } | ||
216 | |||
217 | |||
218 | /** | ||
219 | * Offer data from trait | ||
220 | * | ||
221 | * @param cmd command to extract the controller from. | ||
222 | * @param pt pointer to controller. | ||
223 | * @return #GNUNET_OK on success. | ||
224 | */ | ||
225 | int | ||
226 | GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd, | ||
227 | struct GNUNET_TESTBED_Controller ** | ||
228 | controller) | ||
229 | { | ||
230 | return cmd->traits (cmd->cls, | ||
231 | (const void **) controller, | ||
232 | "controller", | ||
233 | (unsigned int) 0); | ||
234 | } | ||
235 | |||
236 | |||
237 | /** | ||
238 | * Shutdown nicely | ||
239 | * | ||
240 | * @param cs controller state. | ||
241 | */ | ||
242 | void | ||
243 | GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs) | ||
244 | { | ||
245 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
246 | "Shutting down...\n"); | ||
247 | |||
248 | cs->controller_going_down = GNUNET_YES; | ||
249 | |||
250 | if (NULL != cs->abort_task) | ||
251 | GNUNET_SCHEDULER_cancel (cs->abort_task); | ||
252 | if (NULL != cs->reg_handle) | ||
253 | GNUNET_TESTBED_cancel_registration (cs->reg_handle); | ||
254 | if (NULL != cs->controller) | ||
255 | GNUNET_TESTBED_controller_disconnect (cs->controller); | ||
256 | if (NULL != cs->cfg) | ||
257 | GNUNET_CONFIGURATION_destroy (cs->cfg); | ||
258 | if (NULL != cs->cp) | ||
259 | GNUNET_TESTBED_controller_stop (cs->cp); | ||
260 | if (NULL != cs->host) | ||
261 | GNUNET_TESTBED_host_destroy (cs->host); | ||
262 | } | ||
263 | |||
264 | |||
265 | |||
266 | struct GNUNET_TESTING_Command | ||
267 | GNUNET_TESTBED_cmd_controller (const char *label, | ||
268 | const char *trusted_ip, | ||
269 | const char *hostname, | ||
270 | const char *username, | ||
271 | uint16_t port, | ||
272 | struct GNUNET_CONFIGURATION_Handle *cfg, | ||
273 | uint64_t event_mask) | ||
274 | { | ||
275 | struct ControllerState *cs; | ||
276 | |||
277 | cs = GNUNET_new (struct ControllerState); | ||
278 | cs->event_mask = event_mask; | ||
279 | cs->trusted_ip = trusted_ip; | ||
280 | cs->hostname = hostname; | ||
281 | cs->username = username; | ||
282 | cs->port = port; | ||
283 | cs->cfg = cfg; | ||
284 | |||
285 | struct GNUNET_TESTING_Command cmd = { | ||
286 | .cls = cs, | ||
287 | .label = label, | ||
288 | .run = &controller_run, | ||
289 | .cleanup = &controller_cleanup, | ||
290 | .traits = &controller_traits | ||
291 | }; | ||
292 | |||
293 | return cmd; | ||
294 | } | ||
diff --git a/src/testbed/testbed_api_cmd_peer.c b/src/testbed/testbed_api_cmd_peer.c new file mode 100644 index 000000000..4a727bc94 --- /dev/null +++ b/src/testbed/testbed_api_cmd_peer.c | |||
@@ -0,0 +1,249 @@ | |||
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_controller.c | ||
24 | * @brief Command to create a controller. | ||
25 | * @author t3sserakt | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testing_ng_lib.h" | ||
30 | #include "gnunet_testbed_ng_service.h" | ||
31 | #include "gnunet-service-testbed.h" | ||
32 | #include "testbed_api_peers.h" | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Generic logging shortcut | ||
37 | */ | ||
38 | #define LOG(kind, ...) \ | ||
39 | GNUNET_log (kind, __VA_ARGS__) | ||
40 | |||
41 | |||
42 | /** | ||
43 | * | ||
44 | * | ||
45 | * @param cls closure. | ||
46 | * @param[out] ret result | ||
47 | * @param trait name of the trait. | ||
48 | * @param index index number of the object to offer. | ||
49 | * @return #GNUNET_OK on success. | ||
50 | */ | ||
51 | static int | ||
52 | peer_traits (void *cls, | ||
53 | const void **ret, | ||
54 | const char *trait, | ||
55 | unsigned int index) | ||
56 | { | ||
57 | (void) cls; | ||
58 | return GNUNET_OK; | ||
59 | } | ||
60 | |||
61 | |||
62 | /** | ||
63 | * | ||
64 | * | ||
65 | * @param cls closure | ||
66 | * @param cmd current CMD being cleaned up. | ||
67 | */ | ||
68 | static void | ||
69 | peer_cleanup (void *cls, | ||
70 | const struct GNUNET_TESTING_Command *cmd) | ||
71 | { | ||
72 | (void) cls; | ||
73 | } | ||
74 | |||
75 | |||
76 | /** | ||
77 | * abort task to run on test timed out | ||
78 | * | ||
79 | * @param cls NULL | ||
80 | * @param tc the task context | ||
81 | */ | ||
82 | static void | ||
83 | do_abort (void *cls) | ||
84 | { | ||
85 | struct PeerCmdState *ps = cls; | ||
86 | |||
87 | if (GNUNET_NO == ps->peer_ready) | ||
88 | { | ||
89 | LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n"); | ||
90 | ps->abort_task = NULL; | ||
91 | GNUNET_TESTBED_shutdown_peer (ps); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | |||
96 | /** | ||
97 | * Functions of this signature are called when a peer has been successfully | ||
98 | * created | ||
99 | * | ||
100 | * @param cls the closure from GNUNET_TESTBED_peer_create() | ||
101 | * @param emsg MAY contain an error description, if starting peer failed. | ||
102 | */ | ||
103 | static void | ||
104 | peer_started_cb (void *cls, | ||
105 | const char *emsg) | ||
106 | { | ||
107 | struct PeerCmdState *ps = cls; | ||
108 | |||
109 | GNUNET_TESTBED_operation_done (ps->operation); | ||
110 | if (NULL == emsg) | ||
111 | { | ||
112 | ps->peer_ready = GNUNET_YES; | ||
113 | GNUNET_TESTING_interpreter_next (ps->is); | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error starting a peer: %s\n", | ||
118 | emsg); | ||
119 | } | ||
120 | |||
121 | } | ||
122 | |||
123 | |||
124 | /** | ||
125 | * Functions of this signature are called when a peer has been successfully | ||
126 | * created | ||
127 | * | ||
128 | * @param cls the closure from GNUNET_TESTBED_peer_create() | ||
129 | * @param peer the handle for the created peer; NULL on any error during | ||
130 | * creation | ||
131 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | ||
132 | */ | ||
133 | static void | ||
134 | peer_create_cb (void *cls, | ||
135 | struct GNUNET_TESTBED_Peer *peer, | ||
136 | const char *emsg) | ||
137 | { | ||
138 | struct PeerCmdState *ps = cls; | ||
139 | |||
140 | ps->peer = peer; | ||
141 | GNUNET_TESTBED_operation_done (ps->operation); | ||
142 | ps->operation = GNUNET_TESTBED_peer_start (NULL, | ||
143 | peer, | ||
144 | &peer_started_cb, | ||
145 | ps); | ||
146 | } | ||
147 | |||
148 | |||
149 | static void | ||
150 | peer_run (void *cls, | ||
151 | const struct GNUNET_TESTING_Command *cmd, | ||
152 | struct GNUNET_TESTING_Interpreter *is) | ||
153 | { | ||
154 | struct PeerCmdState *ps = cls; | ||
155 | const struct GNUNET_TESTING_Command *controller_cmd; | ||
156 | struct GNUNET_TESTBED_Controller *controller; | ||
157 | |||
158 | ps->is = is; | ||
159 | controller_cmd = GNUNET_TESTING_interpreter_lookup_command ( | ||
160 | ps->controller_label); | ||
161 | GNUNET_TESTBED_get_trait_controller (controller_cmd, | ||
162 | &controller); | ||
163 | ps->host = GNUNET_TESTBED_host_create (ps->hostname, ps->username, ps->cfg, | ||
164 | ps->port); | ||
165 | ps->operation = | ||
166 | GNUNET_TESTBED_peer_create (controller, | ||
167 | ps->host, | ||
168 | ps->cfg, | ||
169 | &peer_create_cb, | ||
170 | ps); | ||
171 | |||
172 | ps->abort_task = | ||
173 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
174 | (GNUNET_TIME_UNIT_MINUTES, 5), | ||
175 | &do_abort, | ||
176 | ps); | ||
177 | } | ||
178 | |||
179 | |||
180 | void | ||
181 | peer_stopped_cb (void *cls, | ||
182 | const char *emsg) | ||
183 | { | ||
184 | struct PeerCmdState *ps = cls; | ||
185 | |||
186 | if (NULL != emsg) | ||
187 | { | ||
188 | LOG (GNUNET_ERROR_TYPE_ERROR, "There was an error stopping a peer: %s\n", | ||
189 | emsg); | ||
190 | } | ||
191 | GNUNET_TESTBED_operation_done (ps->operation); | ||
192 | GNUNET_TESTBED_peer_destroy (ps->peer); | ||
193 | } | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Shutdown nicely | ||
198 | * | ||
199 | * @param cs controller state. | ||
200 | */ | ||
201 | void | ||
202 | GNUNET_TESTBED_shutdown_peer (struct PeerCmdState *ps) | ||
203 | { | ||
204 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
205 | "Shutting down...\n"); | ||
206 | |||
207 | ps->peer_going_down = GNUNET_YES; | ||
208 | |||
209 | if (NULL != ps->abort_task) | ||
210 | GNUNET_SCHEDULER_cancel (ps->abort_task); | ||
211 | if (NULL != ps->cfg) | ||
212 | GNUNET_CONFIGURATION_destroy (ps->cfg); | ||
213 | if (NULL != ps->host) | ||
214 | GNUNET_TESTBED_host_destroy (ps->host); | ||
215 | |||
216 | GNUNET_TESTBED_operation_done (ps->operation); | ||
217 | ps->operation = GNUNET_TESTBED_peer_stop (NULL, ps->peer, peer_stopped_cb, | ||
218 | ps); | ||
219 | |||
220 | } | ||
221 | |||
222 | |||
223 | struct GNUNET_TESTING_Command | ||
224 | GNUNET_TESTBED_cmd_peer (const char *label, | ||
225 | const char *controller_label, | ||
226 | const char *hostname, | ||
227 | const char *username, | ||
228 | uint16_t port, | ||
229 | struct GNUNET_CONFIGURATION_Handle *cfg) | ||
230 | { | ||
231 | struct PeerCmdState *ps; | ||
232 | |||
233 | ps = GNUNET_new (struct PeerCmdState); | ||
234 | ps->hostname = hostname; | ||
235 | ps->username = username; | ||
236 | ps->port = port; | ||
237 | ps->cfg = cfg; | ||
238 | ps->controller_label = controller_label; | ||
239 | |||
240 | struct GNUNET_TESTING_Command cmd = { | ||
241 | .cls = ps, | ||
242 | .label = label, | ||
243 | .run = &peer_run, | ||
244 | .cleanup = &peer_cleanup, | ||
245 | .traits = &peer_traits | ||
246 | }; | ||
247 | |||
248 | return cmd; | ||
249 | } | ||
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 | */ | ||
46 | static void | ||
47 | do_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 | */ | ||
65 | static void | ||
66 | 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 | 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 | static void | ||
92 | service_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 | */ | ||
112 | void | ||
113 | GNUNET_TESTBED_shutdown_service (struct ServiceState *cs) | ||
114 | { | ||
115 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
116 | "Shutting down...\n"); | ||
117 | } | ||
118 | |||
119 | |||
120 | struct GNUNET_TESTING_Command | ||
121 | GNUNET_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 | } | ||