diff options
Diffstat (limited to 'src/testbed/testbed_api_cmd_controller.c')
-rw-r--r-- | src/testbed/testbed_api_cmd_controller.c | 203 |
1 files changed, 0 insertions, 203 deletions
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c deleted file mode 100644 index 794b1ccf3..000000000 --- a/src/testbed/testbed_api_cmd_controller.c +++ /dev/null | |||
@@ -1,203 +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 | /** | ||
35 | * Generic logging shortcut | ||
36 | */ | ||
37 | #define LOG(kind, ...) \ | ||
38 | GNUNET_log (kind, __VA_ARGS__) | ||
39 | |||
40 | |||
41 | /** | ||
42 | * | ||
43 | * | ||
44 | * @param cls closure | ||
45 | * @param cmd current CMD being cleaned up. | ||
46 | */ | ||
47 | static void | ||
48 | controller_cleanup (void *cls, | ||
49 | const struct GNUNET_TESTING_Command *cmd) | ||
50 | { | ||
51 | (void) cls; | ||
52 | } | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Signature of the event handler function called by the | ||
57 | * respective event controller. | ||
58 | * | ||
59 | * @param cls closure | ||
60 | * @param event information about the event | ||
61 | */ | ||
62 | static void | ||
63 | controller_cb (void *cls, | ||
64 | const struct GNUNET_TESTBED_EventInformation *event) | ||
65 | { | ||
66 | struct ControllerState *cs = cls; | ||
67 | |||
68 | if (NULL != event->details.operation_finished.emsg) | ||
69 | { | ||
70 | LOG (GNUNET_ERROR_TYPE_ERROR, "There was an operation error: %s\n", | ||
71 | event->details.operation_finished.emsg); | ||
72 | GNUNET_TESTBED_shutdown_controller (cs); | ||
73 | } | ||
74 | else if (NULL == event->details.operation_finished.generic) | ||
75 | { | ||
76 | GNUNET_TESTBED_operation_done (event->op); | ||
77 | } | ||
78 | } | ||
79 | |||
80 | |||
81 | static void | ||
82 | controller_run (void *cls, | ||
83 | const struct GNUNET_TESTING_Command *cmd, | ||
84 | struct GNUNET_TESTING_Interpreter *is) | ||
85 | { | ||
86 | struct ControllerState *cs = cls; | ||
87 | |||
88 | cs->is = is; | ||
89 | |||
90 | cs->controller = | ||
91 | GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb, | ||
92 | cs); | ||
93 | |||
94 | |||
95 | } | ||
96 | |||
97 | /** | ||
98 | * | ||
99 | * | ||
100 | * @param cls closure. | ||
101 | * @param[out] ret result | ||
102 | * @param trait name of the trait. | ||
103 | * @param index index number of the object to offer. | ||
104 | * @return #GNUNET_OK on success. | ||
105 | */ | ||
106 | static int | ||
107 | controller_traits (void *cls, | ||
108 | const void **ret, | ||
109 | const char *trait, | ||
110 | unsigned int index) | ||
111 | { | ||
112 | (void) cls; | ||
113 | |||
114 | struct ControllerState *cs = cls; | ||
115 | |||
116 | |||
117 | struct GNUNET_TESTING_Trait traits[] = { | ||
118 | { | ||
119 | .index = 0, | ||
120 | .trait_name = "controller", | ||
121 | .ptr = (const void *) cs->controller, | ||
122 | }, | ||
123 | GNUNET_TESTING_trait_end () | ||
124 | }; | ||
125 | |||
126 | return GNUNET_TESTING_get_trait (traits, | ||
127 | ret, | ||
128 | trait, | ||
129 | index); | ||
130 | return GNUNET_OK; | ||
131 | } | ||
132 | |||
133 | |||
134 | /** | ||
135 | * Offer data from trait | ||
136 | * | ||
137 | * @param cmd command to extract the controller from. | ||
138 | * @param pt pointer to controller. | ||
139 | * @return #GNUNET_OK on success. | ||
140 | */ | ||
141 | int | ||
142 | GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd, | ||
143 | struct GNUNET_TESTBED_Controller ** | ||
144 | controller) | ||
145 | { | ||
146 | return cmd->traits (cmd->cls, | ||
147 | (const void **) controller, | ||
148 | "controller", | ||
149 | (unsigned int) 0); | ||
150 | } | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Shutdown nicely | ||
155 | * | ||
156 | * @param cs controller state. | ||
157 | */ | ||
158 | void | ||
159 | GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs) | ||
160 | { | ||
161 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
162 | "Shutting down...\n"); | ||
163 | |||
164 | cs->controller_going_down = GNUNET_YES; | ||
165 | |||
166 | if (NULL != cs->abort_task) | ||
167 | GNUNET_SCHEDULER_cancel (cs->abort_task); | ||
168 | if (NULL != cs->reg_handle) | ||
169 | GNUNET_TESTBED_cancel_registration (cs->reg_handle); | ||
170 | if (NULL != cs->controller) | ||
171 | GNUNET_TESTBED_controller_disconnect (cs->controller); | ||
172 | if (NULL != cs->cfg) | ||
173 | GNUNET_CONFIGURATION_destroy (cs->cfg); | ||
174 | if (NULL != cs->cp) | ||
175 | GNUNET_TESTBED_controller_stop (cs->cp); | ||
176 | if (NULL != cs->host) | ||
177 | GNUNET_TESTBED_host_destroy (cs->host); | ||
178 | } | ||
179 | |||
180 | |||
181 | |||
182 | struct GNUNET_TESTING_Command | ||
183 | GNUNET_TESTBED_cmd_controller (const char *label, | ||
184 | const char *host, | ||
185 | uint64_t event_mask) | ||
186 | { | ||
187 | struct ControllerState *cs; | ||
188 | |||
189 | cs = GNUNET_new (struct ControllerState); | ||
190 | cs->event_mask = event_mask; | ||
191 | cs->hostname = host; | ||
192 | |||
193 | |||
194 | struct GNUNET_TESTING_Command cmd = { | ||
195 | .cls = cs, | ||
196 | .label = label, | ||
197 | .run = &controller_run, | ||
198 | .cleanup = &controller_cleanup, | ||
199 | .traits = &controller_traits | ||
200 | }; | ||
201 | |||
202 | return cmd; | ||
203 | } | ||