diff options
Diffstat (limited to 'src/testbed/testbed_api_services.c')
-rw-r--r-- | src/testbed/testbed_api_services.c | 129 |
1 files changed, 64 insertions, 65 deletions
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index c2b74e580..ee4a65817 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -32,8 +32,7 @@ | |||
32 | /** | 32 | /** |
33 | * States for Service connect operations | 33 | * States for Service connect operations |
34 | */ | 34 | */ |
35 | enum State | 35 | enum State { |
36 | { | ||
37 | /** | 36 | /** |
38 | * Initial state | 37 | * Initial state |
39 | */ | 38 | */ |
@@ -54,8 +53,7 @@ enum State | |||
54 | /** | 53 | /** |
55 | * Data accessed during service connections | 54 | * Data accessed during service connections |
56 | */ | 55 | */ |
57 | struct ServiceConnectData | 56 | struct ServiceConnectData { |
58 | { | ||
59 | /** | 57 | /** |
60 | * helper function callback to establish the connection | 58 | * helper function callback to establish the connection |
61 | */ | 59 | */ |
@@ -120,7 +118,6 @@ struct ServiceConnectData | |||
120 | * State information | 118 | * State information |
121 | */ | 119 | */ |
122 | enum State state; | 120 | enum State state; |
123 | |||
124 | }; | 121 | }; |
125 | 122 | ||
126 | 123 | ||
@@ -132,7 +129,7 @@ struct ServiceConnectData | |||
132 | * @param msg message received, NULL on timeout or fatal error | 129 | * @param msg message received, NULL on timeout or fatal error |
133 | */ | 130 | */ |
134 | static void | 131 | static void |
135 | configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | 132 | configuration_receiver(void *cls, const struct GNUNET_MessageHeader *msg) |
136 | { | 133 | { |
137 | struct ServiceConnectData *data = cls; | 134 | struct ServiceConnectData *data = cls; |
138 | struct GNUNET_TESTBED_Controller *c; | 135 | struct GNUNET_TESTBED_Controller *c; |
@@ -141,26 +138,26 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
141 | uint16_t mtype; | 138 | uint16_t mtype; |
142 | 139 | ||
143 | c = data->peer->controller; | 140 | c = data->peer->controller; |
144 | mtype = ntohs (msg->type); | 141 | mtype = ntohs(msg->type); |
145 | emsg = NULL; | 142 | emsg = NULL; |
146 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 143 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
147 | info.op = data->operation; | 144 | info.op = data->operation; |
148 | info.op_cls = data->op_cls; | 145 | info.op_cls = data->op_cls; |
149 | if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) | 146 | if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT == mtype) |
150 | { | 147 | { |
151 | emsg = | 148 | emsg = |
152 | GNUNET_TESTBED_parse_error_string_ ((const struct | 149 | GNUNET_TESTBED_parse_error_string_((const struct |
153 | GNUNET_TESTBED_OperationFailureEventMessage | 150 | GNUNET_TESTBED_OperationFailureEventMessage |
154 | *) msg); | 151 | *)msg); |
155 | if (NULL == emsg) | 152 | if (NULL == emsg) |
156 | emsg = "Unknown error"; | 153 | emsg = "Unknown error"; |
157 | info.details.operation_finished.emsg = emsg; | 154 | info.details.operation_finished.emsg = emsg; |
158 | info.details.operation_finished.generic = NULL; | 155 | info.details.operation_finished.generic = NULL; |
159 | goto call_cb; | 156 | goto call_cb; |
160 | } | 157 | } |
161 | data->cfg = GNUNET_TESTBED_extract_config_ (msg); | 158 | data->cfg = GNUNET_TESTBED_extract_config_(msg); |
162 | GNUNET_assert (NULL == data->op_result); | 159 | GNUNET_assert(NULL == data->op_result); |
163 | data->op_result = data->ca (data->cada_cls, data->cfg); | 160 | data->op_result = data->ca(data->cada_cls, data->cfg); |
164 | info.details.operation_finished.emsg = NULL; | 161 | info.details.operation_finished.emsg = NULL; |
165 | info.details.operation_finished.generic = data->op_result; | 162 | info.details.operation_finished.generic = data->op_result; |
166 | data->state = SERVICE_CONNECTED; | 163 | data->state = SERVICE_CONNECTED; |
@@ -168,9 +165,9 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
168 | call_cb: | 165 | call_cb: |
169 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && | 166 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && |
170 | (NULL != c->cc)) | 167 | (NULL != c->cc)) |
171 | c->cc (c->cc_cls, &info); | 168 | c->cc(c->cc_cls, &info); |
172 | if (NULL != data->cb) | 169 | if (NULL != data->cb) |
173 | data->cb (data->cb_cls, data->operation, data->op_result, emsg); | 170 | data->cb(data->cb_cls, data->operation, data->op_result, emsg); |
174 | } | 171 | } |
175 | 172 | ||
176 | 173 | ||
@@ -180,23 +177,23 @@ call_cb: | |||
180 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 177 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
181 | */ | 178 | */ |
182 | static void | 179 | static void |
183 | opstart_service_connect (void *cls) | 180 | opstart_service_connect(void *cls) |
184 | { | 181 | { |
185 | struct ServiceConnectData *data = cls; | 182 | struct ServiceConnectData *data = cls; |
186 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 183 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; |
187 | struct GNUNET_TESTBED_Controller *c; | 184 | struct GNUNET_TESTBED_Controller *c; |
188 | uint64_t op_id; | 185 | uint64_t op_id; |
189 | 186 | ||
190 | GNUNET_assert (NULL != data); | 187 | GNUNET_assert(NULL != data); |
191 | GNUNET_assert (NULL != data->peer); | 188 | GNUNET_assert(NULL != data->peer); |
192 | c = data->peer->controller; | 189 | c = data->peer->controller; |
193 | op_id = GNUNET_TESTBED_get_next_op_id (c); | 190 | op_id = GNUNET_TESTBED_get_next_op_id(c); |
194 | msg = | 191 | msg = |
195 | GNUNET_TESTBED_generate_peergetconfig_msg_ (data->peer->unique_id, op_id); | 192 | GNUNET_TESTBED_generate_peergetconfig_msg_(data->peer->unique_id, op_id); |
196 | data->opc = | 193 | data->opc = |
197 | GNUNET_TESTBED_forward_operation_msg_ (c, op_id, &msg->header, | 194 | GNUNET_TESTBED_forward_operation_msg_(c, op_id, &msg->header, |
198 | &configuration_receiver, data); | 195 | &configuration_receiver, data); |
199 | GNUNET_free (msg); | 196 | GNUNET_free(msg); |
200 | data->state = CFG_REQUEST_QUEUED; | 197 | data->state = CFG_REQUEST_QUEUED; |
201 | } | 198 | } |
202 | 199 | ||
@@ -208,26 +205,28 @@ opstart_service_connect (void *cls) | |||
208 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | 205 | * @param cls the closure from GNUNET_TESTBED_operation_create_() |
209 | */ | 206 | */ |
210 | static void | 207 | static void |
211 | oprelease_service_connect (void *cls) | 208 | oprelease_service_connect(void *cls) |
212 | { | 209 | { |
213 | struct ServiceConnectData *data = cls; | 210 | struct ServiceConnectData *data = cls; |
214 | 211 | ||
215 | switch (data->state) | 212 | switch (data->state) |
216 | { | 213 | { |
217 | case INIT: | 214 | case INIT: |
218 | break; | 215 | break; |
219 | case CFG_REQUEST_QUEUED: | 216 | |
220 | GNUNET_assert (NULL != data->opc); | 217 | case CFG_REQUEST_QUEUED: |
221 | GNUNET_TESTBED_forward_operation_msg_cancel_ (data->opc); | 218 | GNUNET_assert(NULL != data->opc); |
222 | break; | 219 | GNUNET_TESTBED_forward_operation_msg_cancel_(data->opc); |
223 | case SERVICE_CONNECTED: | 220 | break; |
224 | GNUNET_assert (NULL != data->cfg); | 221 | |
225 | GNUNET_CONFIGURATION_destroy (data->cfg); | 222 | case SERVICE_CONNECTED: |
226 | if (NULL != data->da) | 223 | GNUNET_assert(NULL != data->cfg); |
227 | data->da (data->cada_cls, data->op_result); | 224 | GNUNET_CONFIGURATION_destroy(data->cfg); |
228 | break; | 225 | if (NULL != data->da) |
229 | } | 226 | data->da(data->cada_cls, data->op_result); |
230 | GNUNET_free (data); | 227 | break; |
228 | } | ||
229 | GNUNET_free(data); | ||
231 | } | 230 | } |
232 | 231 | ||
233 | 232 | ||
@@ -253,17 +252,17 @@ oprelease_service_connect (void *cls) | |||
253 | * @return handle for the operation | 252 | * @return handle for the operation |
254 | */ | 253 | */ |
255 | struct GNUNET_TESTBED_Operation * | 254 | struct GNUNET_TESTBED_Operation * |
256 | GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | 255 | GNUNET_TESTBED_service_connect(void *op_cls, struct GNUNET_TESTBED_Peer *peer, |
257 | const char *service_name, | 256 | const char *service_name, |
258 | GNUNET_TESTBED_ServiceConnectCompletionCallback | 257 | GNUNET_TESTBED_ServiceConnectCompletionCallback |
259 | cb, void *cb_cls, | 258 | cb, void *cb_cls, |
260 | GNUNET_TESTBED_ConnectAdapter ca, | 259 | GNUNET_TESTBED_ConnectAdapter ca, |
261 | GNUNET_TESTBED_DisconnectAdapter da, | 260 | GNUNET_TESTBED_DisconnectAdapter da, |
262 | void *cada_cls) | 261 | void *cada_cls) |
263 | { | 262 | { |
264 | struct ServiceConnectData *data; | 263 | struct ServiceConnectData *data; |
265 | 264 | ||
266 | data = GNUNET_new (struct ServiceConnectData); | 265 | data = GNUNET_new(struct ServiceConnectData); |
267 | data->ca = ca; | 266 | data->ca = ca; |
268 | data->da = da; | 267 | data->da = da; |
269 | data->cada_cls = cada_cls; | 268 | data->cada_cls = cada_cls; |
@@ -273,15 +272,15 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | |||
273 | data->cb = cb; | 272 | data->cb = cb; |
274 | data->cb_cls = cb_cls; | 273 | data->cb_cls = cb_cls; |
275 | data->operation = | 274 | data->operation = |
276 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, | 275 | GNUNET_TESTBED_operation_create_(data, &opstart_service_connect, |
277 | &oprelease_service_connect); | 276 | &oprelease_service_connect); |
278 | GNUNET_TESTBED_operation_queue_insert_ (peer-> | 277 | GNUNET_TESTBED_operation_queue_insert_(peer-> |
279 | controller->opq_parallel_service_connections, | 278 | controller->opq_parallel_service_connections, |
280 | data->operation); | 279 | data->operation); |
281 | GNUNET_TESTBED_operation_queue_insert_ (peer-> | 280 | GNUNET_TESTBED_operation_queue_insert_(peer-> |
282 | controller->opq_parallel_operations, | 281 | controller->opq_parallel_operations, |
283 | data->operation); | 282 | data->operation); |
284 | GNUNET_TESTBED_operation_begin_wait_ (data->operation); | 283 | GNUNET_TESTBED_operation_begin_wait_(data->operation); |
285 | return data->operation; | 284 | return data->operation; |
286 | } | 285 | } |
287 | 286 | ||