diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed_peers.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_peers.c | 1630 |
1 files changed, 819 insertions, 811 deletions
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c index b88812e7e..743c7e849 100644 --- a/src/testbed/gnunet-service-testbed_peers.c +++ b/src/testbed/gnunet-service-testbed_peers.c | |||
@@ -1,22 +1,22 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | 3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 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, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | 21 | ||
22 | /** | 22 | /** |
@@ -44,8 +44,7 @@ unsigned int GST_num_local_peers; | |||
44 | /** | 44 | /** |
45 | * Context information to manage peers' services | 45 | * Context information to manage peers' services |
46 | */ | 46 | */ |
47 | struct ManageServiceContext | 47 | struct ManageServiceContext { |
48 | { | ||
49 | /** | 48 | /** |
50 | * DLL next ptr | 49 | * DLL next ptr |
51 | */ | 50 | */ |
@@ -97,8 +96,7 @@ struct ManageServiceContext | |||
97 | /** | 96 | /** |
98 | * Context information for peer re-configure operations | 97 | * Context information for peer re-configure operations |
99 | */ | 98 | */ |
100 | struct PeerReconfigureContext | 99 | struct PeerReconfigureContext { |
101 | { | ||
102 | /** | 100 | /** |
103 | * DLL next for inclusoin in peer reconfigure operations list | 101 | * DLL next for inclusoin in peer reconfigure operations list |
104 | */ | 102 | */ |
@@ -166,11 +164,11 @@ static struct ManageServiceContext *mctx_tail; | |||
166 | * @param peer the peer to add | 164 | * @param peer the peer to add |
167 | */ | 165 | */ |
168 | static void | 166 | static void |
169 | peer_list_add (struct Peer *peer) | 167 | peer_list_add(struct Peer *peer) |
170 | { | 168 | { |
171 | if (peer->id >= GST_peer_list_size) | 169 | if (peer->id >= GST_peer_list_size) |
172 | GST_array_grow_large_enough (GST_peer_list, GST_peer_list_size, peer->id); | 170 | GST_array_grow_large_enough(GST_peer_list, GST_peer_list_size, peer->id); |
173 | GNUNET_assert (NULL == GST_peer_list[peer->id]); | 171 | GNUNET_assert(NULL == GST_peer_list[peer->id]); |
174 | GST_peer_list[peer->id] = peer; | 172 | GST_peer_list[peer->id] = peer; |
175 | if (GNUNET_NO == peer->is_remote) | 173 | if (GNUNET_NO == peer->is_remote) |
176 | GST_num_local_peers++; | 174 | GST_num_local_peers++; |
@@ -183,7 +181,7 @@ peer_list_add (struct Peer *peer) | |||
183 | * @param peer the peer to be removed | 181 | * @param peer the peer to be removed |
184 | */ | 182 | */ |
185 | static void | 183 | static void |
186 | peer_list_remove (struct Peer *peer) | 184 | peer_list_remove(struct Peer *peer) |
187 | { | 185 | { |
188 | unsigned int orig_size; | 186 | unsigned int orig_size; |
189 | uint32_t id; | 187 | uint32_t id; |
@@ -193,21 +191,21 @@ peer_list_remove (struct Peer *peer) | |||
193 | GST_peer_list[peer->id] = NULL; | 191 | GST_peer_list[peer->id] = NULL; |
194 | orig_size = GST_peer_list_size; | 192 | orig_size = GST_peer_list_size; |
195 | while (GST_peer_list_size >= LIST_GROW_STEP) | 193 | while (GST_peer_list_size >= LIST_GROW_STEP) |
196 | { | 194 | { |
197 | for (id = GST_peer_list_size - 1; | 195 | for (id = GST_peer_list_size - 1; |
198 | (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); | 196 | (id >= GST_peer_list_size - LIST_GROW_STEP) && (id != UINT32_MAX); |
199 | id--) | 197 | id--) |
200 | if (NULL != GST_peer_list[id]) | 198 | if (NULL != GST_peer_list[id]) |
199 | break; | ||
200 | if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) | ||
201 | break; | 201 | break; |
202 | if (id != ((GST_peer_list_size - LIST_GROW_STEP) - 1)) | 202 | GST_peer_list_size -= LIST_GROW_STEP; |
203 | break; | 203 | } |
204 | GST_peer_list_size -= LIST_GROW_STEP; | ||
205 | } | ||
206 | if (orig_size == GST_peer_list_size) | 204 | if (orig_size == GST_peer_list_size) |
207 | return; | 205 | return; |
208 | GST_peer_list = | 206 | GST_peer_list = |
209 | GNUNET_realloc (GST_peer_list, | 207 | GNUNET_realloc(GST_peer_list, |
210 | sizeof (struct Peer *) * GST_peer_list_size); | 208 | sizeof(struct Peer *) * GST_peer_list_size); |
211 | } | 209 | } |
212 | 210 | ||
213 | 211 | ||
@@ -218,12 +216,12 @@ peer_list_remove (struct Peer *peer) | |||
218 | * @param cls the FowardedOperationContext | 216 | * @param cls the FowardedOperationContext |
219 | */ | 217 | */ |
220 | static void | 218 | static void |
221 | peer_create_forward_timeout (void *cls) | 219 | peer_create_forward_timeout(void *cls) |
222 | { | 220 | { |
223 | struct ForwardedOperationContext *fopc = cls; | 221 | struct ForwardedOperationContext *fopc = cls; |
224 | 222 | ||
225 | GNUNET_free (fopc->cls); | 223 | GNUNET_free(fopc->cls); |
226 | GST_forwarded_operation_timeout (fopc); | 224 | GST_forwarded_operation_timeout(fopc); |
227 | } | 225 | } |
228 | 226 | ||
229 | 227 | ||
@@ -235,19 +233,19 @@ peer_create_forward_timeout (void *cls) | |||
235 | * @param msg the peer create success message | 233 | * @param msg the peer create success message |
236 | */ | 234 | */ |
237 | static void | 235 | static void |
238 | peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | 236 | peer_create_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) |
239 | { | 237 | { |
240 | struct ForwardedOperationContext *fopc = cls; | 238 | struct ForwardedOperationContext *fopc = cls; |
241 | struct Peer *remote_peer; | 239 | struct Peer *remote_peer; |
242 | 240 | ||
243 | if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) | 241 | if (ntohs(msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS) |
244 | { | 242 | { |
245 | GNUNET_assert (NULL != fopc->cls); | 243 | GNUNET_assert(NULL != fopc->cls); |
246 | remote_peer = fopc->cls; | 244 | remote_peer = fopc->cls; |
247 | peer_list_add (remote_peer); | 245 | peer_list_add(remote_peer); |
248 | } | 246 | } |
249 | GST_forwarded_operation_reply_relay (fopc, | 247 | GST_forwarded_operation_reply_relay(fopc, |
250 | msg); | 248 | msg); |
251 | } | 249 | } |
252 | 250 | ||
253 | 251 | ||
@@ -257,24 +255,24 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
257 | * @param peer the peer structure to destroy | 255 | * @param peer the peer structure to destroy |
258 | */ | 256 | */ |
259 | void | 257 | void |
260 | GST_destroy_peer (struct Peer *peer) | 258 | GST_destroy_peer(struct Peer *peer) |
261 | { | 259 | { |
262 | GNUNET_break (0 == peer->reference_cnt); | 260 | GNUNET_break(0 == peer->reference_cnt); |
263 | if (GNUNET_YES == peer->is_remote) | 261 | if (GNUNET_YES == peer->is_remote) |
264 | { | 262 | { |
265 | peer_list_remove (peer); | 263 | peer_list_remove(peer); |
266 | GNUNET_free (peer); | 264 | GNUNET_free(peer); |
267 | return; | 265 | return; |
268 | } | 266 | } |
269 | if (GNUNET_YES == peer->details.local.is_running) | 267 | if (GNUNET_YES == peer->details.local.is_running) |
270 | { | 268 | { |
271 | GNUNET_TESTING_peer_stop (peer->details.local.peer); | 269 | GNUNET_TESTING_peer_stop(peer->details.local.peer); |
272 | peer->details.local.is_running = GNUNET_NO; | 270 | peer->details.local.is_running = GNUNET_NO; |
273 | } | 271 | } |
274 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 272 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); |
275 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 273 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); |
276 | peer_list_remove (peer); | 274 | peer_list_remove(peer); |
277 | GNUNET_free (peer); | 275 | GNUNET_free(peer); |
278 | } | 276 | } |
279 | 277 | ||
280 | 278 | ||
@@ -284,20 +282,20 @@ GST_destroy_peer (struct Peer *peer) | |||
284 | * @param mctx the ManageServiceContext | 282 | * @param mctx the ManageServiceContext |
285 | */ | 283 | */ |
286 | static void | 284 | static void |
287 | cleanup_mctx (struct ManageServiceContext *mctx) | 285 | cleanup_mctx(struct ManageServiceContext *mctx) |
288 | { | 286 | { |
289 | mctx->expired = GNUNET_YES; | 287 | mctx->expired = GNUNET_YES; |
290 | GNUNET_CONTAINER_DLL_remove (mctx_head, | 288 | GNUNET_CONTAINER_DLL_remove(mctx_head, |
291 | mctx_tail, | 289 | mctx_tail, |
292 | mctx); | 290 | mctx); |
293 | GNUNET_ARM_disconnect (mctx->ah); | 291 | GNUNET_ARM_disconnect(mctx->ah); |
294 | GNUNET_assert (0 < mctx->peer->reference_cnt); | 292 | GNUNET_assert(0 < mctx->peer->reference_cnt); |
295 | mctx->peer->reference_cnt--; | 293 | mctx->peer->reference_cnt--; |
296 | if ( (GNUNET_YES == mctx->peer->destroy_flag) && | 294 | if ((GNUNET_YES == mctx->peer->destroy_flag) && |
297 | (0 == mctx->peer->reference_cnt) ) | 295 | (0 == mctx->peer->reference_cnt)) |
298 | GST_destroy_peer (mctx->peer); | 296 | GST_destroy_peer(mctx->peer); |
299 | GNUNET_free (mctx->service); | 297 | GNUNET_free(mctx->service); |
300 | GNUNET_free (mctx); | 298 | GNUNET_free(mctx); |
301 | } | 299 | } |
302 | 300 | ||
303 | 301 | ||
@@ -308,10 +306,10 @@ cleanup_mctx (struct ManageServiceContext *mctx) | |||
308 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 306 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
309 | */ | 307 | */ |
310 | static int | 308 | static int |
311 | stop_peer (struct Peer *peer) | 309 | stop_peer(struct Peer *peer) |
312 | { | 310 | { |
313 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 311 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
314 | if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer)) | 312 | if (GNUNET_OK != GNUNET_TESTING_peer_kill(peer->details.local.peer)) |
315 | return GNUNET_SYSERR; | 313 | return GNUNET_SYSERR; |
316 | peer->details.local.is_running = GNUNET_NO; | 314 | peer->details.local.is_running = GNUNET_NO; |
317 | return GNUNET_OK; | 315 | return GNUNET_OK; |
@@ -324,25 +322,25 @@ stop_peer (struct Peer *peer) | |||
324 | * @param prc the PeerReconfigureContext | 322 | * @param prc the PeerReconfigureContext |
325 | */ | 323 | */ |
326 | static void | 324 | static void |
327 | cleanup_prc (struct PeerReconfigureContext *prc) | 325 | cleanup_prc(struct PeerReconfigureContext *prc) |
328 | { | 326 | { |
329 | struct Peer *peer; | 327 | struct Peer *peer; |
330 | 328 | ||
331 | if (VALID_PEER_ID (prc->peer_id)) | 329 | if (VALID_PEER_ID(prc->peer_id)) |
332 | { | ||
333 | peer = GST_peer_list [prc->peer_id]; | ||
334 | if (1 != prc->stopped) | ||
335 | { | 330 | { |
336 | GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); | 331 | peer = GST_peer_list [prc->peer_id]; |
337 | stop_peer (peer); /* Stop the peer synchronously */ | 332 | if (1 != prc->stopped) |
333 | { | ||
334 | GNUNET_TESTING_peer_stop_async_cancel(peer->details.local.peer); | ||
335 | stop_peer(peer); /* Stop the peer synchronously */ | ||
336 | } | ||
338 | } | 337 | } |
339 | } | ||
340 | if (NULL != prc->cfg) | 338 | if (NULL != prc->cfg) |
341 | GNUNET_CONFIGURATION_destroy (prc->cfg); | 339 | GNUNET_CONFIGURATION_destroy(prc->cfg); |
342 | GNUNET_CONTAINER_DLL_remove (prc_head, | 340 | GNUNET_CONTAINER_DLL_remove(prc_head, |
343 | prc_tail, | 341 | prc_tail, |
344 | prc); | 342 | prc); |
345 | GNUNET_free (prc); | 343 | GNUNET_free(prc); |
346 | } | 344 | } |
347 | 345 | ||
348 | 346 | ||
@@ -352,7 +350,7 @@ cleanup_prc (struct PeerReconfigureContext *prc) | |||
352 | * @param client the client that disconnected | 350 | * @param client the client that disconnected |
353 | */ | 351 | */ |
354 | void | 352 | void |
355 | GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | 353 | GST_notify_client_disconnect_peers(struct GNUNET_SERVICE_Client *client) |
356 | { | 354 | { |
357 | struct ForwardedOperationContext *fopc; | 355 | struct ForwardedOperationContext *fopc; |
358 | struct ForwardedOperationContext *fopcn; | 356 | struct ForwardedOperationContext *fopcn; |
@@ -362,28 +360,28 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | |||
362 | struct PeerReconfigureContext *prcn; | 360 | struct PeerReconfigureContext *prcn; |
363 | 361 | ||
364 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | 362 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) |
365 | { | ||
366 | fopcn = fopc->next; | ||
367 | if (client == fopc->client) | ||
368 | { | 363 | { |
369 | if (OP_PEER_CREATE == fopc->type) | 364 | fopcn = fopc->next; |
370 | GNUNET_free (fopc->cls); | 365 | if (client == fopc->client) |
371 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | 366 | { |
372 | GST_forwarded_operation_timeout (fopc); | 367 | if (OP_PEER_CREATE == fopc->type) |
368 | GNUNET_free(fopc->cls); | ||
369 | GNUNET_SCHEDULER_cancel(fopc->timeout_task); | ||
370 | GST_forwarded_operation_timeout(fopc); | ||
371 | } | ||
373 | } | 372 | } |
374 | } | ||
375 | for (mctx = mctx_head; NULL != mctx; mctx = mctxn) | 373 | for (mctx = mctx_head; NULL != mctx; mctx = mctxn) |
376 | { | 374 | { |
377 | mctxn = mctx->next; | 375 | mctxn = mctx->next; |
378 | if (client == mctx->client) | 376 | if (client == mctx->client) |
379 | cleanup_mctx (mctx); | 377 | cleanup_mctx(mctx); |
380 | } | 378 | } |
381 | for (prc = prc_head; NULL != prc; prc = prcn) | 379 | for (prc = prc_head; NULL != prc; prc = prcn) |
382 | { | 380 | { |
383 | prcn = prc->next; | 381 | prcn = prc->next; |
384 | if (client == prc->client) | 382 | if (client == prc->client) |
385 | cleanup_prc (prc); | 383 | cleanup_prc(prc); |
386 | } | 384 | } |
387 | } | 385 | } |
388 | 386 | ||
389 | 387 | ||
@@ -395,22 +393,22 @@ GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | |||
395 | * @param msg the peer create success message | 393 | * @param msg the peer create success message |
396 | */ | 394 | */ |
397 | static void | 395 | static void |
398 | peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | 396 | peer_destroy_success_cb(void *cls, const struct GNUNET_MessageHeader *msg) |
399 | { | 397 | { |
400 | struct ForwardedOperationContext *fopc = cls; | 398 | struct ForwardedOperationContext *fopc = cls; |
401 | struct Peer *remote_peer; | 399 | struct Peer *remote_peer; |
402 | 400 | ||
403 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == | 401 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS == |
404 | ntohs (msg->type)) | 402 | ntohs(msg->type)) |
405 | { | 403 | { |
406 | remote_peer = fopc->cls; | 404 | remote_peer = fopc->cls; |
407 | GNUNET_assert (NULL != remote_peer); | 405 | GNUNET_assert(NULL != remote_peer); |
408 | remote_peer->destroy_flag = GNUNET_YES; | 406 | remote_peer->destroy_flag = GNUNET_YES; |
409 | if (0 == remote_peer->reference_cnt) | 407 | if (0 == remote_peer->reference_cnt) |
410 | GST_destroy_peer (remote_peer); | 408 | GST_destroy_peer(remote_peer); |
411 | } | 409 | } |
412 | GST_forwarded_operation_reply_relay (fopc, | 410 | GST_forwarded_operation_reply_relay(fopc, |
413 | msg); | 411 | msg); |
414 | } | 412 | } |
415 | 413 | ||
416 | 414 | ||
@@ -422,8 +420,8 @@ peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
422 | * @return #GNUNET_OK if @a msg is well-formed | 420 | * @return #GNUNET_OK if @a msg is well-formed |
423 | */ | 421 | */ |
424 | int | 422 | int |
425 | check_peer_create (void *cls, | 423 | check_peer_create(void *cls, |
426 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) | 424 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) |
427 | { | 425 | { |
428 | return GNUNET_OK; /* checked later */ | 426 | return GNUNET_OK; /* checked later */ |
429 | } | 427 | } |
@@ -436,8 +434,8 @@ check_peer_create (void *cls, | |||
436 | * @param msg the actual message | 434 | * @param msg the actual message |
437 | */ | 435 | */ |
438 | void | 436 | void |
439 | handle_peer_create (void *cls, | 437 | handle_peer_create(void *cls, |
440 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) | 438 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) |
441 | { | 439 | { |
442 | struct GNUNET_SERVICE_Client *client = cls; | 440 | struct GNUNET_SERVICE_Client *client = cls; |
443 | struct GNUNET_MQ_Envelope *env; | 441 | struct GNUNET_MQ_Envelope *env; |
@@ -450,114 +448,114 @@ handle_peer_create (void *cls, | |||
450 | uint32_t host_id; | 448 | uint32_t host_id; |
451 | uint32_t peer_id; | 449 | uint32_t peer_id; |
452 | 450 | ||
453 | host_id = ntohl (msg->host_id); | 451 | host_id = ntohl(msg->host_id); |
454 | peer_id = ntohl (msg->peer_id); | 452 | peer_id = ntohl(msg->peer_id); |
455 | if (VALID_PEER_ID (peer_id)) | 453 | if (VALID_PEER_ID(peer_id)) |
456 | { | 454 | { |
457 | (void) GNUNET_asprintf (&emsg, | 455 | (void)GNUNET_asprintf(&emsg, |
458 | "Peer with ID %u already exists", | 456 | "Peer with ID %u already exists", |
459 | peer_id); | 457 | peer_id); |
460 | GST_send_operation_fail_msg (client, | 458 | GST_send_operation_fail_msg(client, |
461 | GNUNET_ntohll (msg->operation_id), | 459 | GNUNET_ntohll(msg->operation_id), |
462 | emsg); | 460 | emsg); |
463 | GNUNET_free (emsg); | 461 | GNUNET_free(emsg); |
464 | GNUNET_SERVICE_client_continue (client); | 462 | GNUNET_SERVICE_client_continue(client); |
465 | return; | 463 | return; |
466 | } | 464 | } |
467 | if (UINT32_MAX == peer_id) | 465 | if (UINT32_MAX == peer_id) |
468 | { | ||
469 | GST_send_operation_fail_msg (client, | ||
470 | GNUNET_ntohll (msg->operation_id), | ||
471 | "Cannot create peer with given ID"); | ||
472 | GNUNET_SERVICE_client_continue (client); | ||
473 | return; | ||
474 | } | ||
475 | if (host_id == GST_context->host_id) | ||
476 | { | ||
477 | /* We are responsible for this peer */ | ||
478 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); | ||
479 | if (NULL == cfg) | ||
480 | { | 466 | { |
481 | GNUNET_break (0); | 467 | GST_send_operation_fail_msg(client, |
482 | GNUNET_SERVICE_client_drop (client); | 468 | GNUNET_ntohll(msg->operation_id), |
469 | "Cannot create peer with given ID"); | ||
470 | GNUNET_SERVICE_client_continue(client); | ||
483 | return; | 471 | return; |
484 | } | 472 | } |
485 | GNUNET_CONFIGURATION_set_value_number (cfg, | 473 | if (host_id == GST_context->host_id) |
486 | "TESTBED", | ||
487 | "PEERID", | ||
488 | (unsigned long long) peer_id); | ||
489 | |||
490 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
491 | "PATHS", | ||
492 | "PEERID", | ||
493 | (unsigned long long) peer_id); | ||
494 | peer = GNUNET_new (struct Peer); | ||
495 | peer->is_remote = GNUNET_NO; | ||
496 | peer->details.local.cfg = cfg; | ||
497 | peer->id = peer_id; | ||
498 | LOG_DEBUG ("Creating peer with id: %u\n", | ||
499 | (unsigned int) peer->id); | ||
500 | peer->details.local.peer = | ||
501 | GNUNET_TESTING_peer_configure (GST_context->system, | ||
502 | peer->details.local.cfg, peer->id, | ||
503 | NULL /* Peer id */ , | ||
504 | &emsg); | ||
505 | if (NULL == peer->details.local.peer) | ||
506 | { | 474 | { |
507 | LOG (GNUNET_ERROR_TYPE_WARNING, | 475 | /* We are responsible for this peer */ |
508 | "Configuring peer failed: %s\n", | 476 | cfg = GNUNET_TESTBED_extract_config_(&msg->header); |
509 | emsg); | 477 | if (NULL == cfg) |
510 | GNUNET_free (emsg); | 478 | { |
511 | GNUNET_free (peer); | 479 | GNUNET_break(0); |
512 | GNUNET_break (0); | 480 | GNUNET_SERVICE_client_drop(client); |
513 | GNUNET_SERVICE_client_drop (client); | 481 | return; |
482 | } | ||
483 | GNUNET_CONFIGURATION_set_value_number(cfg, | ||
484 | "TESTBED", | ||
485 | "PEERID", | ||
486 | (unsigned long long)peer_id); | ||
487 | |||
488 | GNUNET_CONFIGURATION_set_value_number(cfg, | ||
489 | "PATHS", | ||
490 | "PEERID", | ||
491 | (unsigned long long)peer_id); | ||
492 | peer = GNUNET_new(struct Peer); | ||
493 | peer->is_remote = GNUNET_NO; | ||
494 | peer->details.local.cfg = cfg; | ||
495 | peer->id = peer_id; | ||
496 | LOG_DEBUG("Creating peer with id: %u\n", | ||
497 | (unsigned int)peer->id); | ||
498 | peer->details.local.peer = | ||
499 | GNUNET_TESTING_peer_configure(GST_context->system, | ||
500 | peer->details.local.cfg, peer->id, | ||
501 | NULL /* Peer id */, | ||
502 | &emsg); | ||
503 | if (NULL == peer->details.local.peer) | ||
504 | { | ||
505 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
506 | "Configuring peer failed: %s\n", | ||
507 | emsg); | ||
508 | GNUNET_free(emsg); | ||
509 | GNUNET_free(peer); | ||
510 | GNUNET_break(0); | ||
511 | GNUNET_SERVICE_client_drop(client); | ||
512 | return; | ||
513 | } | ||
514 | peer->details.local.is_running = GNUNET_NO; | ||
515 | peer_list_add(peer); | ||
516 | env = GNUNET_MQ_msg(reply, | ||
517 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); | ||
518 | reply->peer_id = msg->peer_id; | ||
519 | reply->operation_id = msg->operation_id; | ||
520 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), | ||
521 | env); | ||
522 | GNUNET_SERVICE_client_continue(client); | ||
514 | return; | 523 | return; |
515 | } | 524 | } |
516 | peer->details.local.is_running = GNUNET_NO; | ||
517 | peer_list_add (peer); | ||
518 | env = GNUNET_MQ_msg (reply, | ||
519 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); | ||
520 | reply->peer_id = msg->peer_id; | ||
521 | reply->operation_id = msg->operation_id; | ||
522 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | ||
523 | env); | ||
524 | GNUNET_SERVICE_client_continue (client); | ||
525 | return; | ||
526 | } | ||
527 | 525 | ||
528 | /* Forward peer create request */ | 526 | /* Forward peer create request */ |
529 | route = GST_find_dest_route (host_id); | 527 | route = GST_find_dest_route(host_id); |
530 | if (NULL == route) | 528 | if (NULL == route) |
531 | { | 529 | { |
532 | GNUNET_break (0); | 530 | GNUNET_break(0); |
533 | GNUNET_SERVICE_client_continue (client); // ? | 531 | GNUNET_SERVICE_client_continue(client); // ? |
534 | return; | 532 | return; |
535 | } | 533 | } |
536 | peer = GNUNET_new (struct Peer); | 534 | peer = GNUNET_new(struct Peer); |
537 | peer->is_remote = GNUNET_YES; | 535 | peer->is_remote = GNUNET_YES; |
538 | peer->id = peer_id; | 536 | peer->id = peer_id; |
539 | peer->details.remote.slave = GST_slave_list[route->dest]; | 537 | peer->details.remote.slave = GST_slave_list[route->dest]; |
540 | peer->details.remote.remote_host_id = host_id; | 538 | peer->details.remote.remote_host_id = host_id; |
541 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 539 | fo_ctxt = GNUNET_new(struct ForwardedOperationContext); |
542 | fo_ctxt->client = client; | 540 | fo_ctxt->client = client; |
543 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); | 541 | fo_ctxt->operation_id = GNUNET_ntohll(msg->operation_id); |
544 | fo_ctxt->cls = peer; | 542 | fo_ctxt->cls = peer; |
545 | fo_ctxt->type = OP_PEER_CREATE; | 543 | fo_ctxt->type = OP_PEER_CREATE; |
546 | fo_ctxt->opc = | 544 | fo_ctxt->opc = |
547 | GNUNET_TESTBED_forward_operation_msg_ (GST_slave_list | 545 | GNUNET_TESTBED_forward_operation_msg_(GST_slave_list |
548 | [route->dest]->controller, | 546 | [route->dest]->controller, |
549 | fo_ctxt->operation_id, | 547 | fo_ctxt->operation_id, |
550 | &msg->header, | 548 | &msg->header, |
551 | &peer_create_success_cb, | 549 | &peer_create_success_cb, |
552 | fo_ctxt); | 550 | fo_ctxt); |
553 | fo_ctxt->timeout_task = | 551 | fo_ctxt->timeout_task = |
554 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 552 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
555 | &peer_create_forward_timeout, | 553 | &peer_create_forward_timeout, |
556 | fo_ctxt); | 554 | fo_ctxt); |
557 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 555 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
558 | fopcq_tail, | 556 | fopcq_tail, |
559 | fo_ctxt); | 557 | fo_ctxt); |
560 | GNUNET_SERVICE_client_continue (client); | 558 | GNUNET_SERVICE_client_continue(client); |
561 | } | 559 | } |
562 | 560 | ||
563 | 561 | ||
@@ -568,63 +566,63 @@ handle_peer_create (void *cls, | |||
568 | * @param msg the actual message | 566 | * @param msg the actual message |
569 | */ | 567 | */ |
570 | void | 568 | void |
571 | handle_peer_destroy (void *cls, | 569 | handle_peer_destroy(void *cls, |
572 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg) | 570 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg) |
573 | { | 571 | { |
574 | struct GNUNET_SERVICE_Client *client = cls; | 572 | struct GNUNET_SERVICE_Client *client = cls; |
575 | struct ForwardedOperationContext *fopc; | 573 | struct ForwardedOperationContext *fopc; |
576 | struct Peer *peer; | 574 | struct Peer *peer; |
577 | uint32_t peer_id; | 575 | uint32_t peer_id; |
578 | 576 | ||
579 | peer_id = ntohl (msg->peer_id); | 577 | peer_id = ntohl(msg->peer_id); |
580 | LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n", | 578 | LOG_DEBUG("Received peer destory on peer: %u and operation id: %llu\n", |
581 | (unsigned int) peer_id, | 579 | (unsigned int)peer_id, |
582 | (unsigned long long) GNUNET_ntohll (msg->operation_id)); | 580 | (unsigned long long)GNUNET_ntohll(msg->operation_id)); |
583 | if (!VALID_PEER_ID (peer_id)) | 581 | if (!VALID_PEER_ID(peer_id)) |
584 | { | 582 | { |
585 | LOG (GNUNET_ERROR_TYPE_ERROR, | 583 | LOG(GNUNET_ERROR_TYPE_ERROR, |
586 | "Asked to destroy a non existent peer with id: %u\n", peer_id); | 584 | "Asked to destroy a non existent peer with id: %u\n", peer_id); |
587 | GST_send_operation_fail_msg (client, | 585 | GST_send_operation_fail_msg(client, |
588 | GNUNET_ntohll (msg->operation_id), | 586 | GNUNET_ntohll(msg->operation_id), |
589 | "Peer doesn't exist"); | 587 | "Peer doesn't exist"); |
590 | GNUNET_SERVICE_client_continue (client); | 588 | GNUNET_SERVICE_client_continue(client); |
591 | return; | 589 | return; |
592 | } | 590 | } |
593 | peer = GST_peer_list[peer_id]; | 591 | peer = GST_peer_list[peer_id]; |
594 | if (GNUNET_YES == peer->is_remote) | 592 | if (GNUNET_YES == peer->is_remote) |
595 | { | 593 | { |
596 | /* Forward the destory message to sub controller */ | 594 | /* Forward the destory message to sub controller */ |
597 | fopc = GNUNET_new (struct ForwardedOperationContext); | 595 | fopc = GNUNET_new(struct ForwardedOperationContext); |
598 | fopc->client = client; | 596 | fopc->client = client; |
599 | fopc->cls = peer; | 597 | fopc->cls = peer; |
600 | fopc->type = OP_PEER_DESTROY; | 598 | fopc->type = OP_PEER_DESTROY; |
601 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 599 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
602 | fopc->opc = | 600 | fopc->opc = |
603 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 601 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
604 | slave->controller, | 602 | slave->controller, |
605 | fopc->operation_id, | 603 | fopc->operation_id, |
606 | &msg->header, | 604 | &msg->header, |
607 | &peer_destroy_success_cb, | 605 | &peer_destroy_success_cb, |
608 | fopc); | 606 | fopc); |
609 | fopc->timeout_task = | 607 | fopc->timeout_task = |
610 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 608 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
611 | &GST_forwarded_operation_timeout, | 609 | &GST_forwarded_operation_timeout, |
612 | fopc); | 610 | fopc); |
613 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 611 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
614 | fopcq_tail, | 612 | fopcq_tail, |
615 | fopc); | 613 | fopc); |
616 | GNUNET_SERVICE_client_continue (client); | 614 | GNUNET_SERVICE_client_continue(client); |
617 | return; | 615 | return; |
618 | } | 616 | } |
619 | peer->destroy_flag = GNUNET_YES; | 617 | peer->destroy_flag = GNUNET_YES; |
620 | if (0 == peer->reference_cnt) | 618 | if (0 == peer->reference_cnt) |
621 | GST_destroy_peer (peer); | 619 | GST_destroy_peer(peer); |
622 | else | 620 | else |
623 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 621 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
624 | "Delaying peer destroy as peer is currently in use\n"); | 622 | "Delaying peer destroy as peer is currently in use\n"); |
625 | GST_send_operation_success_msg (client, | 623 | GST_send_operation_success_msg(client, |
626 | GNUNET_ntohll (msg->operation_id)); | 624 | GNUNET_ntohll(msg->operation_id)); |
627 | GNUNET_SERVICE_client_continue (client); | 625 | GNUNET_SERVICE_client_continue(client); |
628 | } | 626 | } |
629 | 627 | ||
630 | 628 | ||
@@ -635,10 +633,10 @@ handle_peer_destroy (void *cls, | |||
635 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 633 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure |
636 | */ | 634 | */ |
637 | static int | 635 | static int |
638 | start_peer (struct Peer *peer) | 636 | start_peer(struct Peer *peer) |
639 | { | 637 | { |
640 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 638 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
641 | if (GNUNET_OK != GNUNET_TESTING_peer_start (peer->details.local.peer)) | 639 | if (GNUNET_OK != GNUNET_TESTING_peer_start(peer->details.local.peer)) |
642 | return GNUNET_SYSERR; | 640 | return GNUNET_SYSERR; |
643 | peer->details.local.is_running = GNUNET_YES; | 641 | peer->details.local.is_running = GNUNET_YES; |
644 | return GNUNET_OK; | 642 | return GNUNET_OK; |
@@ -652,8 +650,8 @@ start_peer (struct Peer *peer) | |||
652 | * @param msg the actual message | 650 | * @param msg the actual message |
653 | */ | 651 | */ |
654 | void | 652 | void |
655 | handle_peer_start (void *cls, | 653 | handle_peer_start(void *cls, |
656 | const struct GNUNET_TESTBED_PeerStartMessage *msg) | 654 | const struct GNUNET_TESTBED_PeerStartMessage *msg) |
657 | { | 655 | { |
658 | struct GNUNET_SERVICE_Client *client = cls; | 656 | struct GNUNET_SERVICE_Client *client = cls; |
659 | struct GNUNET_MQ_Envelope *env; | 657 | struct GNUNET_MQ_Envelope *env; |
@@ -662,55 +660,55 @@ handle_peer_start (void *cls, | |||
662 | struct Peer *peer; | 660 | struct Peer *peer; |
663 | uint32_t peer_id; | 661 | uint32_t peer_id; |
664 | 662 | ||
665 | peer_id = ntohl (msg->peer_id); | 663 | peer_id = ntohl(msg->peer_id); |
666 | if (! VALID_PEER_ID (peer_id)) | 664 | if (!VALID_PEER_ID(peer_id)) |
667 | { | 665 | { |
668 | GNUNET_break (0); | 666 | GNUNET_break(0); |
669 | LOG (GNUNET_ERROR_TYPE_ERROR, | 667 | LOG(GNUNET_ERROR_TYPE_ERROR, |
670 | "Asked to start a non existent peer with id: %u\n", | 668 | "Asked to start a non existent peer with id: %u\n", |
671 | peer_id); | 669 | peer_id); |
672 | GNUNET_SERVICE_client_continue (client); | 670 | GNUNET_SERVICE_client_continue(client); |
673 | return; | 671 | return; |
674 | } | 672 | } |
675 | peer = GST_peer_list[peer_id]; | 673 | peer = GST_peer_list[peer_id]; |
676 | if (GNUNET_YES == peer->is_remote) | 674 | if (GNUNET_YES == peer->is_remote) |
677 | { | 675 | { |
678 | fopc = GNUNET_new (struct ForwardedOperationContext); | 676 | fopc = GNUNET_new(struct ForwardedOperationContext); |
679 | fopc->client = client; | 677 | fopc->client = client; |
680 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 678 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
681 | fopc->type = OP_PEER_START; | 679 | fopc->type = OP_PEER_START; |
682 | fopc->opc = | 680 | fopc->opc = |
683 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 681 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
684 | slave->controller, | 682 | slave->controller, |
685 | fopc->operation_id, &msg->header, | 683 | fopc->operation_id, &msg->header, |
686 | &GST_forwarded_operation_reply_relay, | 684 | &GST_forwarded_operation_reply_relay, |
687 | fopc); | 685 | fopc); |
688 | fopc->timeout_task = | 686 | fopc->timeout_task = |
689 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 687 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
690 | &GST_forwarded_operation_timeout, | 688 | &GST_forwarded_operation_timeout, |
691 | fopc); | 689 | fopc); |
692 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 690 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
693 | fopcq_tail, | 691 | fopcq_tail, |
694 | fopc); | 692 | fopc); |
695 | GNUNET_SERVICE_client_continue (client); | 693 | GNUNET_SERVICE_client_continue(client); |
696 | return; | 694 | return; |
697 | } | 695 | } |
698 | if (GNUNET_OK != start_peer (peer)) | 696 | if (GNUNET_OK != start_peer(peer)) |
699 | { | 697 | { |
700 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 698 | GST_send_operation_fail_msg(client, GNUNET_ntohll(msg->operation_id), |
701 | "Failed to start"); | 699 | "Failed to start"); |
702 | GNUNET_SERVICE_client_continue (client); | 700 | GNUNET_SERVICE_client_continue(client); |
703 | return; | 701 | return; |
704 | } | 702 | } |
705 | env = GNUNET_MQ_msg (reply, | 703 | env = GNUNET_MQ_msg(reply, |
706 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 704 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
707 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START); | 705 | reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_START); |
708 | reply->host_id = htonl (GST_context->host_id); | 706 | reply->host_id = htonl(GST_context->host_id); |
709 | reply->peer_id = msg->peer_id; | 707 | reply->peer_id = msg->peer_id; |
710 | reply->operation_id = msg->operation_id; | 708 | reply->operation_id = msg->operation_id; |
711 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 709 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
712 | env); | 710 | env); |
713 | GNUNET_SERVICE_client_continue (client); | 711 | GNUNET_SERVICE_client_continue(client); |
714 | } | 712 | } |
715 | 713 | ||
716 | 714 | ||
@@ -721,8 +719,8 @@ handle_peer_start (void *cls, | |||
721 | * @param msg the actual message | 719 | * @param msg the actual message |
722 | */ | 720 | */ |
723 | void | 721 | void |
724 | handle_peer_stop (void *cls, | 722 | handle_peer_stop(void *cls, |
725 | const struct GNUNET_TESTBED_PeerStopMessage *msg) | 723 | const struct GNUNET_TESTBED_PeerStopMessage *msg) |
726 | { | 724 | { |
727 | struct GNUNET_SERVICE_Client *client = cls; | 725 | struct GNUNET_SERVICE_Client *client = cls; |
728 | struct GNUNET_MQ_Envelope *env; | 726 | struct GNUNET_MQ_Envelope *env; |
@@ -731,69 +729,69 @@ handle_peer_stop (void *cls, | |||
731 | struct Peer *peer; | 729 | struct Peer *peer; |
732 | uint32_t peer_id; | 730 | uint32_t peer_id; |
733 | 731 | ||
734 | peer_id = ntohl (msg->peer_id); | 732 | peer_id = ntohl(msg->peer_id); |
735 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 733 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
736 | "Received PEER_STOP for peer %u\n", | 734 | "Received PEER_STOP for peer %u\n", |
737 | (unsigned int) peer_id); | 735 | (unsigned int)peer_id); |
738 | if (! VALID_PEER_ID (peer_id)) | 736 | if (!VALID_PEER_ID(peer_id)) |
739 | { | 737 | { |
740 | GST_send_operation_fail_msg (client, | 738 | GST_send_operation_fail_msg(client, |
741 | GNUNET_ntohll (msg->operation_id), | 739 | GNUNET_ntohll(msg->operation_id), |
742 | "Peer not found"); | 740 | "Peer not found"); |
743 | GNUNET_SERVICE_client_continue (client); | 741 | GNUNET_SERVICE_client_continue(client); |
744 | return; | 742 | return; |
745 | } | 743 | } |
746 | peer = GST_peer_list[peer_id]; | 744 | peer = GST_peer_list[peer_id]; |
747 | if (GNUNET_YES == peer->is_remote) | 745 | if (GNUNET_YES == peer->is_remote) |
748 | { | 746 | { |
749 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 747 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
750 | "Forwarding PEER_STOP for peer %u\n", | 748 | "Forwarding PEER_STOP for peer %u\n", |
751 | (unsigned int) peer_id); | 749 | (unsigned int)peer_id); |
752 | fopc = GNUNET_new (struct ForwardedOperationContext); | 750 | fopc = GNUNET_new(struct ForwardedOperationContext); |
753 | fopc->client = client; | 751 | fopc->client = client; |
754 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 752 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
755 | fopc->type = OP_PEER_STOP; | 753 | fopc->type = OP_PEER_STOP; |
756 | fopc->opc = | 754 | fopc->opc = |
757 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 755 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
758 | slave->controller, | 756 | slave->controller, |
759 | fopc->operation_id, | 757 | fopc->operation_id, |
760 | &msg->header, | 758 | &msg->header, |
761 | &GST_forwarded_operation_reply_relay, | 759 | &GST_forwarded_operation_reply_relay, |
762 | fopc); | 760 | fopc); |
763 | fopc->timeout_task = | 761 | fopc->timeout_task = |
764 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 762 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
765 | &GST_forwarded_operation_timeout, | 763 | &GST_forwarded_operation_timeout, |
766 | fopc); | 764 | fopc); |
767 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 765 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
768 | fopcq_tail, | 766 | fopcq_tail, |
769 | fopc); | 767 | fopc); |
770 | GNUNET_SERVICE_client_continue (client); | 768 | GNUNET_SERVICE_client_continue(client); |
771 | return; | 769 | return; |
772 | } | 770 | } |
773 | if (GNUNET_OK != stop_peer (peer)) | 771 | if (GNUNET_OK != stop_peer(peer)) |
774 | { | 772 | { |
775 | LOG (GNUNET_ERROR_TYPE_WARNING, | 773 | LOG(GNUNET_ERROR_TYPE_WARNING, |
776 | "Stopping peer %u failed\n", | 774 | "Stopping peer %u failed\n", |
777 | (unsigned int) peer_id); | 775 | (unsigned int)peer_id); |
778 | GST_send_operation_fail_msg (client, | 776 | GST_send_operation_fail_msg(client, |
779 | GNUNET_ntohll (msg->operation_id), | 777 | GNUNET_ntohll(msg->operation_id), |
780 | "Peer not running"); | 778 | "Peer not running"); |
781 | GNUNET_SERVICE_client_continue (client); | 779 | GNUNET_SERVICE_client_continue(client); |
782 | return; | 780 | return; |
783 | } | 781 | } |
784 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 782 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
785 | "Peer %u successfully stopped\n", | 783 | "Peer %u successfully stopped\n", |
786 | (unsigned int) peer_id); | 784 | (unsigned int)peer_id); |
787 | env = GNUNET_MQ_msg (reply, | 785 | env = GNUNET_MQ_msg(reply, |
788 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 786 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
789 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); | 787 | reply->event_type = htonl(GNUNET_TESTBED_ET_PEER_STOP); |
790 | reply->host_id = htonl (GST_context->host_id); | 788 | reply->host_id = htonl(GST_context->host_id); |
791 | reply->peer_id = msg->peer_id; | 789 | reply->peer_id = msg->peer_id; |
792 | reply->operation_id = msg->operation_id; | 790 | reply->operation_id = msg->operation_id; |
793 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 791 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
794 | env); | 792 | env); |
795 | GNUNET_SERVICE_client_continue (client); | 793 | GNUNET_SERVICE_client_continue(client); |
796 | GNUNET_TESTING_peer_wait (peer->details.local.peer); | 794 | GNUNET_TESTING_peer_wait(peer->details.local.peer); |
797 | } | 795 | } |
798 | 796 | ||
799 | 797 | ||
@@ -804,8 +802,8 @@ handle_peer_stop (void *cls, | |||
804 | * @param msg the actual message | 802 | * @param msg the actual message |
805 | */ | 803 | */ |
806 | void | 804 | void |
807 | handle_peer_get_config (void *cls, | 805 | handle_peer_get_config(void *cls, |
808 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) | 806 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) |
809 | { | 807 | { |
810 | struct GNUNET_SERVICE_Client *client = cls; | 808 | struct GNUNET_SERVICE_Client *client = cls; |
811 | struct GNUNET_MQ_Envelope *env; | 809 | struct GNUNET_MQ_Envelope *env; |
@@ -818,67 +816,67 @@ handle_peer_get_config (void *cls, | |||
818 | size_t xc_size; | 816 | size_t xc_size; |
819 | uint32_t peer_id; | 817 | uint32_t peer_id; |
820 | 818 | ||
821 | peer_id = ntohl (msg->peer_id); | 819 | peer_id = ntohl(msg->peer_id); |
822 | LOG_DEBUG ("Received GET_CONFIG for peer %u\n", | 820 | LOG_DEBUG("Received GET_CONFIG for peer %u\n", |
823 | (unsigned int) peer_id); | 821 | (unsigned int)peer_id); |
824 | if (!VALID_PEER_ID (peer_id)) | 822 | if (!VALID_PEER_ID(peer_id)) |
825 | { | 823 | { |
826 | GST_send_operation_fail_msg (client, | 824 | GST_send_operation_fail_msg(client, |
827 | GNUNET_ntohll (msg->operation_id), | 825 | GNUNET_ntohll(msg->operation_id), |
828 | "Peer not found"); | 826 | "Peer not found"); |
829 | GNUNET_SERVICE_client_continue (client); | 827 | GNUNET_SERVICE_client_continue(client); |
830 | return; | 828 | return; |
831 | } | 829 | } |
832 | peer = GST_peer_list[peer_id]; | 830 | peer = GST_peer_list[peer_id]; |
833 | if (GNUNET_YES == peer->is_remote) | 831 | if (GNUNET_YES == peer->is_remote) |
834 | { | 832 | { |
835 | LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", | 833 | LOG_DEBUG("Forwarding PEER_GET_CONFIG for peer: %u\n", |
836 | (unsigned int) peer_id); | 834 | (unsigned int)peer_id); |
837 | fopc = GNUNET_new (struct ForwardedOperationContext); | 835 | fopc = GNUNET_new(struct ForwardedOperationContext); |
838 | fopc->client = client; | 836 | fopc->client = client; |
839 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 837 | fopc->operation_id = GNUNET_ntohll(msg->operation_id); |
840 | fopc->type = OP_PEER_INFO; | 838 | fopc->type = OP_PEER_INFO; |
841 | fopc->opc = | 839 | fopc->opc = |
842 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 840 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
843 | slave->controller, | 841 | slave->controller, |
844 | fopc->operation_id, | 842 | fopc->operation_id, |
845 | &msg->header, | 843 | &msg->header, |
846 | &GST_forwarded_operation_reply_relay, | 844 | &GST_forwarded_operation_reply_relay, |
847 | fopc); | 845 | fopc); |
848 | fopc->timeout_task = | 846 | fopc->timeout_task = |
849 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 847 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
850 | &GST_forwarded_operation_timeout, | 848 | &GST_forwarded_operation_timeout, |
851 | fopc); | 849 | fopc); |
852 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 850 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
853 | fopcq_tail, | 851 | fopcq_tail, |
854 | fopc); | 852 | fopc); |
855 | GNUNET_SERVICE_client_continue (client); | 853 | GNUNET_SERVICE_client_continue(client); |
856 | return; | 854 | return; |
857 | } | 855 | } |
858 | LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", | 856 | LOG_DEBUG("Received PEER_GET_CONFIG for peer: %u\n", |
859 | peer_id); | 857 | peer_id); |
860 | config = | 858 | config = |
861 | GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg, | 859 | GNUNET_CONFIGURATION_serialize(GST_peer_list[peer_id]->details.local.cfg, |
862 | &c_size); | 860 | &c_size); |
863 | xc_size = GNUNET_TESTBED_compress_config_ (config, | 861 | xc_size = GNUNET_TESTBED_compress_config_(config, |
864 | c_size, | 862 | c_size, |
865 | &xconfig); | 863 | &xconfig); |
866 | GNUNET_free (config); | 864 | GNUNET_free(config); |
867 | env = GNUNET_MQ_msg_extra (reply, | 865 | env = GNUNET_MQ_msg_extra(reply, |
868 | xc_size, | 866 | xc_size, |
869 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); | 867 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); |
870 | reply->peer_id = msg->peer_id; | 868 | reply->peer_id = msg->peer_id; |
871 | reply->operation_id = msg->operation_id; | 869 | reply->operation_id = msg->operation_id; |
872 | GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer, | 870 | GNUNET_TESTING_peer_get_identity(GST_peer_list[peer_id]->details.local.peer, |
873 | &reply->peer_identity); | 871 | &reply->peer_identity); |
874 | reply->config_size = htons ((uint16_t) c_size); | 872 | reply->config_size = htons((uint16_t)c_size); |
875 | GNUNET_memcpy (&reply[1], | 873 | GNUNET_memcpy(&reply[1], |
876 | xconfig, | 874 | xconfig, |
877 | xc_size); | 875 | xc_size); |
878 | GNUNET_free (xconfig); | 876 | GNUNET_free(xconfig); |
879 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 877 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
880 | env); | 878 | env); |
881 | GNUNET_SERVICE_client_continue (client); | 879 | GNUNET_SERVICE_client_continue(client); |
882 | } | 880 | } |
883 | 881 | ||
884 | 882 | ||
@@ -886,10 +884,10 @@ handle_peer_get_config (void *cls, | |||
886 | * Cleans up the Peer reconfigure context list | 884 | * Cleans up the Peer reconfigure context list |
887 | */ | 885 | */ |
888 | void | 886 | void |
889 | GST_free_prcq () | 887 | GST_free_prcq() |
890 | { | 888 | { |
891 | while (NULL != prc_head) | 889 | while (NULL != prc_head) |
892 | cleanup_prc (prc_head); | 890 | cleanup_prc(prc_head); |
893 | } | 891 | } |
894 | 892 | ||
895 | 893 | ||
@@ -901,21 +899,21 @@ GST_free_prcq () | |||
901 | * @return error message (freshly allocated); NULL upon success | 899 | * @return error message (freshly allocated); NULL upon success |
902 | */ | 900 | */ |
903 | static char * | 901 | static char * |
904 | update_peer_config (struct Peer *peer, | 902 | update_peer_config(struct Peer *peer, |
905 | struct GNUNET_CONFIGURATION_Handle *cfg) | 903 | struct GNUNET_CONFIGURATION_Handle *cfg) |
906 | { | 904 | { |
907 | char *emsg; | 905 | char *emsg; |
908 | 906 | ||
909 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 907 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); |
910 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 908 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); |
911 | peer->details.local.cfg = cfg; | 909 | peer->details.local.cfg = cfg; |
912 | emsg = NULL; | 910 | emsg = NULL; |
913 | peer->details.local.peer | 911 | peer->details.local.peer |
914 | = GNUNET_TESTING_peer_configure (GST_context->system, | 912 | = GNUNET_TESTING_peer_configure(GST_context->system, |
915 | peer->details.local.cfg, | 913 | peer->details.local.cfg, |
916 | peer->id, | 914 | peer->id, |
917 | NULL /* Peer id */ , | 915 | NULL /* Peer id */, |
918 | &emsg); | 916 | &emsg); |
919 | return emsg; | 917 | return emsg; |
920 | } | 918 | } |
921 | 919 | ||
@@ -929,39 +927,39 @@ update_peer_config (struct Peer *peer, | |||
929 | * error | 927 | * error |
930 | */ | 928 | */ |
931 | static void | 929 | static void |
932 | prc_stop_cb (void *cls, | 930 | prc_stop_cb(void *cls, |
933 | struct GNUNET_TESTING_Peer *p, | 931 | struct GNUNET_TESTING_Peer *p, |
934 | int success) | 932 | int success) |
935 | { | 933 | { |
936 | struct PeerReconfigureContext *prc = cls; | 934 | struct PeerReconfigureContext *prc = cls; |
937 | struct Peer *peer; | 935 | struct Peer *peer; |
938 | char *emsg; | 936 | char *emsg; |
939 | 937 | ||
940 | GNUNET_assert (VALID_PEER_ID (prc->peer_id)); | 938 | GNUNET_assert(VALID_PEER_ID(prc->peer_id)); |
941 | peer = GST_peer_list [prc->peer_id]; | 939 | peer = GST_peer_list [prc->peer_id]; |
942 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 940 | GNUNET_assert(GNUNET_NO == peer->is_remote); |
943 | emsg = update_peer_config (peer, prc->cfg); | 941 | emsg = update_peer_config(peer, prc->cfg); |
944 | prc->cfg = NULL; | 942 | prc->cfg = NULL; |
945 | prc->stopped = 1; | 943 | prc->stopped = 1; |
946 | if (NULL != emsg) | 944 | if (NULL != emsg) |
947 | { | 945 | { |
948 | GST_send_operation_fail_msg (prc->client, | 946 | GST_send_operation_fail_msg(prc->client, |
949 | prc->op_id, | 947 | prc->op_id, |
950 | emsg); | 948 | emsg); |
951 | goto cleanup; | 949 | goto cleanup; |
952 | } | 950 | } |
953 | if (GNUNET_OK != start_peer (peer)) | 951 | if (GNUNET_OK != start_peer(peer)) |
954 | { | 952 | { |
955 | GST_send_operation_fail_msg (prc->client, | 953 | GST_send_operation_fail_msg(prc->client, |
956 | prc->op_id, | 954 | prc->op_id, |
957 | "Failed to start reconfigured peer"); | 955 | "Failed to start reconfigured peer"); |
958 | goto cleanup; | 956 | goto cleanup; |
959 | } | 957 | } |
960 | GST_send_operation_success_msg (prc->client, | 958 | GST_send_operation_success_msg(prc->client, |
961 | prc->op_id); | 959 | prc->op_id); |
962 | 960 | ||
963 | cleanup: | 961 | cleanup: |
964 | cleanup_prc (prc); | 962 | cleanup_prc(prc); |
965 | return; | 963 | return; |
966 | } | 964 | } |
967 | 965 | ||
@@ -974,8 +972,8 @@ prc_stop_cb (void *cls, | |||
974 | * @return #GNUNET_OK if @a msg is well-formed | 972 | * @return #GNUNET_OK if @a msg is well-formed |
975 | */ | 973 | */ |
976 | int | 974 | int |
977 | check_peer_reconfigure (void *cls, | 975 | check_peer_reconfigure(void *cls, |
978 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) | 976 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) |
979 | { | 977 | { |
980 | return GNUNET_OK; /* checked later */ | 978 | return GNUNET_OK; /* checked later */ |
981 | } | 979 | } |
@@ -990,8 +988,8 @@ check_peer_reconfigure (void *cls, | |||
990 | * @param msg the actual message | 988 | * @param msg the actual message |
991 | */ | 989 | */ |
992 | void | 990 | void |
993 | handle_peer_reconfigure (void *cls, | 991 | handle_peer_reconfigure(void *cls, |
994 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) | 992 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) |
995 | { | 993 | { |
996 | struct GNUNET_SERVICE_Client *client = cls; | 994 | struct GNUNET_SERVICE_Client *client = cls; |
997 | struct Peer *peer; | 995 | struct Peer *peer; |
@@ -1002,114 +1000,114 @@ handle_peer_reconfigure (void *cls, | |||
1002 | uint64_t op_id; | 1000 | uint64_t op_id; |
1003 | uint32_t peer_id; | 1001 | uint32_t peer_id; |
1004 | 1002 | ||
1005 | peer_id = ntohl (msg->peer_id); | 1003 | peer_id = ntohl(msg->peer_id); |
1006 | op_id = GNUNET_ntohll (msg->operation_id); | 1004 | op_id = GNUNET_ntohll(msg->operation_id); |
1007 | if (! VALID_PEER_ID (peer_id)) | 1005 | if (!VALID_PEER_ID(peer_id)) |
1008 | { | 1006 | { |
1009 | GNUNET_break (0); | 1007 | GNUNET_break(0); |
1010 | GST_send_operation_fail_msg (client, | 1008 | GST_send_operation_fail_msg(client, |
1011 | op_id, | 1009 | op_id, |
1012 | "Peer not found"); | 1010 | "Peer not found"); |
1013 | GNUNET_SERVICE_client_continue (client); | 1011 | GNUNET_SERVICE_client_continue(client); |
1014 | return; | 1012 | return; |
1015 | } | 1013 | } |
1016 | peer = GST_peer_list[peer_id]; | 1014 | peer = GST_peer_list[peer_id]; |
1017 | if (GNUNET_YES == peer->is_remote) | 1015 | if (GNUNET_YES == peer->is_remote) |
1018 | { | 1016 | { |
1019 | LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); | 1017 | LOG_DEBUG("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); |
1020 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1018 | fopc = GNUNET_new(struct ForwardedOperationContext); |
1021 | fopc->client = client; | 1019 | fopc->client = client; |
1022 | fopc->operation_id = op_id; | 1020 | fopc->operation_id = op_id; |
1023 | fopc->type = OP_PEER_RECONFIGURE; | 1021 | fopc->type = OP_PEER_RECONFIGURE; |
1024 | fopc->opc = | 1022 | fopc->opc = |
1025 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 1023 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
1026 | slave->controller, | 1024 | slave->controller, |
1027 | fopc->operation_id, | 1025 | fopc->operation_id, |
1028 | &msg->header, | 1026 | &msg->header, |
1029 | &GST_forwarded_operation_reply_relay, | 1027 | &GST_forwarded_operation_reply_relay, |
1030 | fopc); | 1028 | fopc); |
1031 | fopc->timeout_task = | 1029 | fopc->timeout_task = |
1032 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1030 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1033 | &GST_forwarded_operation_timeout, | 1031 | &GST_forwarded_operation_timeout, |
1034 | fopc); | 1032 | fopc); |
1035 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1033 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1036 | fopcq_tail, | 1034 | fopcq_tail, |
1037 | fopc); | 1035 | fopc); |
1038 | GNUNET_SERVICE_client_continue (client); | 1036 | GNUNET_SERVICE_client_continue(client); |
1039 | return; | 1037 | return; |
1040 | } | 1038 | } |
1041 | LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", | 1039 | LOG_DEBUG("Received PEER_RECONFIGURE for peer %u\n", |
1042 | (unsigned int) peer_id); | 1040 | (unsigned int)peer_id); |
1043 | if (0 < peer->reference_cnt) | 1041 | if (0 < peer->reference_cnt) |
1044 | { | 1042 | { |
1045 | GNUNET_break (0); | 1043 | GNUNET_break(0); |
1046 | GST_send_operation_fail_msg (client, | 1044 | GST_send_operation_fail_msg(client, |
1047 | op_id, | 1045 | op_id, |
1048 | "Peer in use"); | 1046 | "Peer in use"); |
1049 | GNUNET_SERVICE_client_continue (client); | 1047 | GNUNET_SERVICE_client_continue(client); |
1050 | return; | 1048 | return; |
1051 | } | 1049 | } |
1052 | if (GNUNET_YES == peer->destroy_flag) | 1050 | if (GNUNET_YES == peer->destroy_flag) |
1053 | { | 1051 | { |
1054 | GNUNET_break (0); | 1052 | GNUNET_break(0); |
1055 | GST_send_operation_fail_msg (client, | 1053 | GST_send_operation_fail_msg(client, |
1056 | op_id, | 1054 | op_id, |
1057 | "Peer is being destroyed"); | 1055 | "Peer is being destroyed"); |
1058 | GNUNET_SERVICE_client_continue (client); | 1056 | GNUNET_SERVICE_client_continue(client); |
1059 | return; | 1057 | return; |
1060 | } | 1058 | } |
1061 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); | 1059 | cfg = GNUNET_TESTBED_extract_config_(&msg->header); |
1062 | if (NULL == cfg) | 1060 | if (NULL == cfg) |
1063 | { | 1061 | { |
1064 | GNUNET_break (0); | 1062 | GNUNET_break(0); |
1065 | GST_send_operation_fail_msg (client, | 1063 | GST_send_operation_fail_msg(client, |
1066 | op_id, | 1064 | op_id, |
1067 | "Compression error"); | 1065 | "Compression error"); |
1068 | GNUNET_SERVICE_client_continue (client); | 1066 | GNUNET_SERVICE_client_continue(client); |
1069 | return; | 1067 | return; |
1070 | } | 1068 | } |
1071 | if (GNUNET_NO == peer->details.local.is_running) | 1069 | if (GNUNET_NO == peer->details.local.is_running) |
1072 | { | 1070 | { |
1073 | emsg = update_peer_config (peer, | 1071 | emsg = update_peer_config(peer, |
1074 | cfg); | 1072 | cfg); |
1075 | if (NULL != emsg) | 1073 | if (NULL != emsg) |
1076 | GST_send_operation_fail_msg (client, | 1074 | GST_send_operation_fail_msg(client, |
1077 | op_id, | 1075 | op_id, |
1078 | emsg); | 1076 | emsg); |
1079 | GST_send_operation_success_msg (client, | 1077 | GST_send_operation_success_msg(client, |
1080 | op_id); | 1078 | op_id); |
1081 | GNUNET_SERVICE_client_continue (client); | 1079 | GNUNET_SERVICE_client_continue(client); |
1082 | GNUNET_free_non_null (emsg); | 1080 | GNUNET_free_non_null(emsg); |
1083 | return; | 1081 | return; |
1084 | } | 1082 | } |
1085 | prc = GNUNET_new (struct PeerReconfigureContext); | 1083 | prc = GNUNET_new(struct PeerReconfigureContext); |
1086 | if (GNUNET_OK != | 1084 | if (GNUNET_OK != |
1087 | GNUNET_TESTING_peer_stop_async (peer->details.local.peer, | 1085 | GNUNET_TESTING_peer_stop_async(peer->details.local.peer, |
1088 | &prc_stop_cb, | 1086 | &prc_stop_cb, |
1089 | prc)) | 1087 | prc)) |
1090 | { | 1088 | { |
1091 | GNUNET_assert (0 < GNUNET_asprintf (&emsg, | 1089 | GNUNET_assert(0 < GNUNET_asprintf(&emsg, |
1092 | "Error trying to stop peer %u asynchronously\n", | 1090 | "Error trying to stop peer %u asynchronously\n", |
1093 | peer_id)); | 1091 | peer_id)); |
1094 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1092 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1095 | "%s\n", | 1093 | "%s\n", |
1096 | emsg); | 1094 | emsg); |
1097 | GST_send_operation_fail_msg (client, | 1095 | GST_send_operation_fail_msg(client, |
1098 | op_id, | 1096 | op_id, |
1099 | emsg); | 1097 | emsg); |
1100 | GNUNET_SERVICE_client_continue (client); | 1098 | GNUNET_SERVICE_client_continue(client); |
1101 | GNUNET_free (prc); | 1099 | GNUNET_free(prc); |
1102 | GNUNET_free (emsg); | 1100 | GNUNET_free(emsg); |
1103 | return; | 1101 | return; |
1104 | } | 1102 | } |
1105 | prc->cfg = cfg; | 1103 | prc->cfg = cfg; |
1106 | prc->peer_id = peer_id; | 1104 | prc->peer_id = peer_id; |
1107 | prc->op_id = op_id; | 1105 | prc->op_id = op_id; |
1108 | prc->client = client; | 1106 | prc->client = client; |
1109 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, | 1107 | GNUNET_CONTAINER_DLL_insert_tail(prc_head, |
1110 | prc_tail, | 1108 | prc_tail, |
1111 | prc); | 1109 | prc); |
1112 | GNUNET_SERVICE_client_continue (client); | 1110 | GNUNET_SERVICE_client_continue(client); |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | 1113 | ||
@@ -1117,10 +1115,10 @@ handle_peer_reconfigure (void *cls, | |||
1117 | * Frees the ManageServiceContext queue | 1115 | * Frees the ManageServiceContext queue |
1118 | */ | 1116 | */ |
1119 | void | 1117 | void |
1120 | GST_free_mctxq () | 1118 | GST_free_mctxq() |
1121 | { | 1119 | { |
1122 | while (NULL != mctx_head) | 1120 | while (NULL != mctx_head) |
1123 | cleanup_mctx (mctx_head); | 1121 | cleanup_mctx(mctx_head); |
1124 | } | 1122 | } |
1125 | 1123 | ||
1126 | 1124 | ||
@@ -1131,15 +1129,16 @@ GST_free_mctxq () | |||
1131 | * @return a string interpretation of the request status | 1129 | * @return a string interpretation of the request status |
1132 | */ | 1130 | */ |
1133 | static const char * | 1131 | static const char * |
1134 | arm_req_string (enum GNUNET_ARM_RequestStatus rs) | 1132 | arm_req_string(enum GNUNET_ARM_RequestStatus rs) |
1135 | { | 1133 | { |
1136 | switch (rs) | 1134 | switch (rs) |
1137 | { | 1135 | { |
1138 | case GNUNET_ARM_REQUEST_SENT_OK: | 1136 | case GNUNET_ARM_REQUEST_SENT_OK: |
1139 | return _("Message was sent successfully"); | 1137 | return _("Message was sent successfully"); |
1140 | case GNUNET_ARM_REQUEST_DISCONNECTED: | 1138 | |
1141 | return _("We disconnected from ARM before we could send a request"); | 1139 | case GNUNET_ARM_REQUEST_DISCONNECTED: |
1142 | } | 1140 | return _("We disconnected from ARM before we could send a request"); |
1141 | } | ||
1143 | return _("Unknown request status"); | 1142 | return _("Unknown request status"); |
1144 | } | 1143 | } |
1145 | 1144 | ||
@@ -1151,31 +1150,40 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs) | |||
1151 | * @return a string interpretation | 1150 | * @return a string interpretation |
1152 | */ | 1151 | */ |
1153 | static const char * | 1152 | static const char * |
1154 | arm_ret_string (enum GNUNET_ARM_Result result) | 1153 | arm_ret_string(enum GNUNET_ARM_Result result) |
1155 | { | 1154 | { |
1156 | switch (result) | 1155 | switch (result) |
1157 | { | 1156 | { |
1158 | case GNUNET_ARM_RESULT_STOPPED: | 1157 | case GNUNET_ARM_RESULT_STOPPED: |
1159 | return _("%s is stopped"); | 1158 | return _("%s is stopped"); |
1160 | case GNUNET_ARM_RESULT_STARTING: | 1159 | |
1161 | return _("%s is starting"); | 1160 | case GNUNET_ARM_RESULT_STARTING: |
1162 | case GNUNET_ARM_RESULT_STOPPING: | 1161 | return _("%s is starting"); |
1163 | return _("%s is stopping"); | 1162 | |
1164 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: | 1163 | case GNUNET_ARM_RESULT_STOPPING: |
1165 | return _("%s is starting already"); | 1164 | return _("%s is stopping"); |
1166 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: | 1165 | |
1167 | return _("%s is stopping already"); | 1166 | case GNUNET_ARM_RESULT_IS_STARTING_ALREADY: |
1168 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: | 1167 | return _("%s is starting already"); |
1169 | return _("%s is started already"); | 1168 | |
1170 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: | 1169 | case GNUNET_ARM_RESULT_IS_STOPPING_ALREADY: |
1171 | return _("%s is stopped already"); | 1170 | return _("%s is stopping already"); |
1172 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | 1171 | |
1173 | return _("%s service is not known to ARM"); | 1172 | case GNUNET_ARM_RESULT_IS_STARTED_ALREADY: |
1174 | case GNUNET_ARM_RESULT_START_FAILED: | 1173 | return _("%s is started already"); |
1175 | return _("%s service failed to start"); | 1174 | |
1176 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | 1175 | case GNUNET_ARM_RESULT_IS_STOPPED_ALREADY: |
1177 | return _("%s service can't be started because ARM is shutting down"); | 1176 | return _("%s is stopped already"); |
1178 | } | 1177 | |
1178 | case GNUNET_ARM_RESULT_IS_NOT_KNOWN: | ||
1179 | return _("%s service is not known to ARM"); | ||
1180 | |||
1181 | case GNUNET_ARM_RESULT_START_FAILED: | ||
1182 | return _("%s service failed to start"); | ||
1183 | |||
1184 | case GNUNET_ARM_RESULT_IN_SHUTDOWN: | ||
1185 | return _("%s service can't be started because ARM is shutting down"); | ||
1186 | } | ||
1179 | return _("%.s Unknown result code."); | 1187 | return _("%.s Unknown result code."); |
1180 | } | 1188 | } |
1181 | 1189 | ||
@@ -1191,9 +1199,9 @@ arm_ret_string (enum GNUNET_ARM_Result result) | |||
1191 | * @param result result of the operation | 1199 | * @param result result of the operation |
1192 | */ | 1200 | */ |
1193 | static void | 1201 | static void |
1194 | service_manage_result_cb (void *cls, | 1202 | service_manage_result_cb(void *cls, |
1195 | enum GNUNET_ARM_RequestStatus rs, | 1203 | enum GNUNET_ARM_RequestStatus rs, |
1196 | enum GNUNET_ARM_Result result) | 1204 | enum GNUNET_ARM_Result result) |
1197 | { | 1205 | { |
1198 | struct ManageServiceContext *mctx = cls; | 1206 | struct ManageServiceContext *mctx = cls; |
1199 | char *emsg; | 1207 | char *emsg; |
@@ -1202,55 +1210,55 @@ service_manage_result_cb (void *cls, | |||
1202 | if (GNUNET_YES == mctx->expired) | 1210 | if (GNUNET_YES == mctx->expired) |
1203 | return; | 1211 | return; |
1204 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) | 1212 | if (GNUNET_ARM_REQUEST_SENT_OK != rs) |
1205 | { | 1213 | { |
1206 | GNUNET_asprintf (&emsg, | 1214 | GNUNET_asprintf(&emsg, |
1207 | "Error communicating with Peer %u's ARM: %s", | 1215 | "Error communicating with Peer %u's ARM: %s", |
1208 | mctx->peer->id, | 1216 | mctx->peer->id, |
1209 | arm_req_string (rs)); | 1217 | arm_req_string(rs)); |
1210 | goto ret; | 1218 | goto ret; |
1211 | } | 1219 | } |
1212 | if (1 == mctx->start) | 1220 | if (1 == mctx->start) |
1213 | goto service_start_check; | 1221 | goto service_start_check; |
1214 | if (! ((GNUNET_ARM_RESULT_STOPPED == result) | 1222 | if (!((GNUNET_ARM_RESULT_STOPPED == result) |
1215 | || (GNUNET_ARM_RESULT_STOPPING == result) | 1223 | || (GNUNET_ARM_RESULT_STOPPING == result) |
1216 | || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) | 1224 | || (GNUNET_ARM_RESULT_IS_STOPPING_ALREADY == result) |
1217 | || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)) ) | 1225 | || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result))) |
1218 | { | 1226 | { |
1219 | /* stopping a service failed */ | 1227 | /* stopping a service failed */ |
1220 | GNUNET_asprintf (&emsg, | 1228 | GNUNET_asprintf(&emsg, |
1221 | arm_ret_string (result), | 1229 | arm_ret_string(result), |
1222 | mctx->service); | 1230 | mctx->service); |
1223 | goto ret; | 1231 | goto ret; |
1224 | } | 1232 | } |
1225 | /* service stopped successfully */ | 1233 | /* service stopped successfully */ |
1226 | goto ret; | 1234 | goto ret; |
1227 | 1235 | ||
1228 | service_start_check: | 1236 | service_start_check: |
1229 | if (! ((GNUNET_ARM_RESULT_STARTING == result) | 1237 | if (!((GNUNET_ARM_RESULT_STARTING == result) |
1230 | || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) | 1238 | || (GNUNET_ARM_RESULT_IS_STARTING_ALREADY == result) |
1231 | || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)) ) | 1239 | || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result))) |
1232 | { | 1240 | { |
1233 | /* starting a service failed */ | 1241 | /* starting a service failed */ |
1234 | GNUNET_asprintf (&emsg, | 1242 | GNUNET_asprintf(&emsg, |
1235 | arm_ret_string (result), | 1243 | arm_ret_string(result), |
1236 | mctx->service); | 1244 | mctx->service); |
1237 | goto ret; | 1245 | goto ret; |
1238 | } | 1246 | } |
1239 | /* service started successfully */ | 1247 | /* service started successfully */ |
1240 | 1248 | ||
1241 | ret: | 1249 | ret: |
1242 | if (NULL != emsg) | 1250 | if (NULL != emsg) |
1243 | { | 1251 | { |
1244 | LOG_DEBUG ("%s\n", emsg); | 1252 | LOG_DEBUG("%s\n", emsg); |
1245 | GST_send_operation_fail_msg (mctx->client, | 1253 | GST_send_operation_fail_msg(mctx->client, |
1246 | mctx->op_id, | 1254 | mctx->op_id, |
1247 | emsg); | 1255 | emsg); |
1248 | } | 1256 | } |
1249 | else | 1257 | else |
1250 | GST_send_operation_success_msg (mctx->client, | 1258 | GST_send_operation_success_msg(mctx->client, |
1251 | mctx->op_id); | 1259 | mctx->op_id); |
1252 | GNUNET_free_non_null (emsg); | 1260 | GNUNET_free_non_null(emsg); |
1253 | cleanup_mctx (mctx); | 1261 | cleanup_mctx(mctx); |
1254 | } | 1262 | } |
1255 | 1263 | ||
1256 | 1264 | ||
@@ -1262,25 +1270,25 @@ service_manage_result_cb (void *cls, | |||
1262 | * @return #GNUNET_OK if @a msg is well-formed | 1270 | * @return #GNUNET_OK if @a msg is well-formed |
1263 | */ | 1271 | */ |
1264 | int | 1272 | int |
1265 | check_manage_peer_service (void *cls, | 1273 | check_manage_peer_service(void *cls, |
1266 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) | 1274 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) |
1267 | { | 1275 | { |
1268 | uint16_t msize; | 1276 | uint16_t msize; |
1269 | const char* service; | 1277 | const char* service; |
1270 | 1278 | ||
1271 | msize = ntohs (msg->header.size); | 1279 | msize = ntohs(msg->header.size); |
1272 | service = (const char *) &msg[1]; | 1280 | service = (const char *)&msg[1]; |
1273 | if ('\0' != service[msize - sizeof | 1281 | if ('\0' != service[msize - sizeof |
1274 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) | 1282 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) |
1275 | { | 1283 | { |
1276 | GNUNET_break_op (0); | 1284 | GNUNET_break_op(0); |
1277 | return GNUNET_SYSERR; | 1285 | return GNUNET_SYSERR; |
1278 | } | 1286 | } |
1279 | if (1 < msg->start) | 1287 | if (1 < msg->start) |
1280 | { | 1288 | { |
1281 | GNUNET_break_op (0); | 1289 | GNUNET_break_op(0); |
1282 | return GNUNET_SYSERR; | 1290 | return GNUNET_SYSERR; |
1283 | } | 1291 | } |
1284 | return GNUNET_OK; | 1292 | return GNUNET_OK; |
1285 | } | 1293 | } |
1286 | 1294 | ||
@@ -1292,8 +1300,8 @@ check_manage_peer_service (void *cls, | |||
1292 | * @param msg the actual message | 1300 | * @param msg the actual message |
1293 | */ | 1301 | */ |
1294 | void | 1302 | void |
1295 | handle_manage_peer_service (void *cls, | 1303 | handle_manage_peer_service(void *cls, |
1296 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) | 1304 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) |
1297 | { | 1305 | { |
1298 | struct GNUNET_SERVICE_Client *client = cls; | 1306 | struct GNUNET_SERVICE_Client *client = cls; |
1299 | const char* service; | 1307 | const char* service; |
@@ -1305,100 +1313,100 @@ handle_manage_peer_service (void *cls, | |||
1305 | uint64_t op_id; | 1313 | uint64_t op_id; |
1306 | uint32_t peer_id; | 1314 | uint32_t peer_id; |
1307 | 1315 | ||
1308 | service = (const char *) &msg[1]; | 1316 | service = (const char *)&msg[1]; |
1309 | peer_id = ntohl (msg->peer_id); | 1317 | peer_id = ntohl(msg->peer_id); |
1310 | op_id = GNUNET_ntohll (msg->operation_id); | 1318 | op_id = GNUNET_ntohll(msg->operation_id); |
1311 | LOG_DEBUG ("Received request to manage service %s on peer %u\n", | 1319 | LOG_DEBUG("Received request to manage service %s on peer %u\n", |
1312 | service, (unsigned int) peer_id); | 1320 | service, (unsigned int)peer_id); |
1313 | if ((GST_peer_list_size <= peer_id) | 1321 | if ((GST_peer_list_size <= peer_id) |
1314 | || (NULL == (peer = GST_peer_list[peer_id]))) | 1322 | || (NULL == (peer = GST_peer_list[peer_id]))) |
1315 | { | 1323 | { |
1316 | GNUNET_asprintf (&emsg, "Asked to manage service of a non existent peer " | 1324 | GNUNET_asprintf(&emsg, "Asked to manage service of a non existent peer " |
1317 | "with id: %u", peer_id); | 1325 | "with id: %u", peer_id); |
1318 | goto err_ret; | 1326 | goto err_ret; |
1319 | } | 1327 | } |
1320 | if (0 == strcasecmp ("arm", service)) | 1328 | if (0 == strcasecmp("arm", service)) |
1321 | { | 1329 | { |
1322 | emsg = GNUNET_strdup ("Cannot start/stop peer's ARM service. " | 1330 | emsg = GNUNET_strdup("Cannot start/stop peer's ARM service. " |
1323 | "Use peer start/stop for that"); | 1331 | "Use peer start/stop for that"); |
1324 | goto err_ret; | 1332 | goto err_ret; |
1325 | } | 1333 | } |
1326 | if (GNUNET_YES == peer->is_remote) | 1334 | if (GNUNET_YES == peer->is_remote) |
1327 | { | 1335 | { |
1328 | /* Forward the destory message to sub controller */ | 1336 | /* Forward the destory message to sub controller */ |
1329 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1337 | fopc = GNUNET_new(struct ForwardedOperationContext); |
1330 | fopc->client = client; | 1338 | fopc->client = client; |
1331 | fopc->cls = peer; | 1339 | fopc->cls = peer; |
1332 | fopc->type = OP_MANAGE_SERVICE; | 1340 | fopc->type = OP_MANAGE_SERVICE; |
1333 | fopc->operation_id = op_id; | 1341 | fopc->operation_id = op_id; |
1334 | fopc->opc = | 1342 | fopc->opc = |
1335 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 1343 | GNUNET_TESTBED_forward_operation_msg_(peer->details.remote. |
1336 | slave->controller, | 1344 | slave->controller, |
1337 | fopc->operation_id, | 1345 | fopc->operation_id, |
1338 | &msg->header, | 1346 | &msg->header, |
1339 | &GST_forwarded_operation_reply_relay, | 1347 | &GST_forwarded_operation_reply_relay, |
1340 | fopc); | 1348 | fopc); |
1341 | fopc->timeout_task = | 1349 | fopc->timeout_task = |
1342 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 1350 | GNUNET_SCHEDULER_add_delayed(GST_timeout, |
1343 | &GST_forwarded_operation_timeout, | 1351 | &GST_forwarded_operation_timeout, |
1344 | fopc); | 1352 | fopc); |
1345 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1353 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1346 | fopcq_tail, | 1354 | fopcq_tail, |
1347 | fopc); | 1355 | fopc); |
1348 | GNUNET_SERVICE_client_continue (client); | 1356 | GNUNET_SERVICE_client_continue(client); |
1349 | return; | 1357 | return; |
1350 | } | 1358 | } |
1351 | if (GNUNET_NO == peer->details.local.is_running) | 1359 | if (GNUNET_NO == peer->details.local.is_running) |
1352 | { | 1360 | { |
1353 | emsg = GNUNET_strdup ("Peer not running\n"); | 1361 | emsg = GNUNET_strdup("Peer not running\n"); |
1354 | goto err_ret; | 1362 | goto err_ret; |
1355 | } | 1363 | } |
1356 | if ((0 != peer->reference_cnt) | 1364 | if ((0 != peer->reference_cnt) |
1357 | && ( (0 == strcasecmp ("core", service)) | 1365 | && ((0 == strcasecmp("core", service)) |
1358 | || (0 == strcasecmp ("transport", service)) ) ) | 1366 | || (0 == strcasecmp("transport", service)))) |
1359 | { | 1367 | { |
1360 | GNUNET_asprintf (&emsg, "Cannot stop %s service of peer with id: %u " | 1368 | GNUNET_asprintf(&emsg, "Cannot stop %s service of peer with id: %u " |
1361 | "since it is required by existing operations", | 1369 | "since it is required by existing operations", |
1362 | service, peer_id); | 1370 | service, peer_id); |
1363 | goto err_ret; | 1371 | goto err_ret; |
1364 | } | 1372 | } |
1365 | ah = GNUNET_ARM_connect (peer->details.local.cfg, NULL, NULL); | 1373 | ah = GNUNET_ARM_connect(peer->details.local.cfg, NULL, NULL); |
1366 | if (NULL == ah) | 1374 | if (NULL == ah) |
1367 | { | 1375 | { |
1368 | GNUNET_asprintf (&emsg, | 1376 | GNUNET_asprintf(&emsg, |
1369 | "Cannot connect to ARM service of peer with id: %u", | 1377 | "Cannot connect to ARM service of peer with id: %u", |
1370 | peer_id); | 1378 | peer_id); |
1371 | goto err_ret; | 1379 | goto err_ret; |
1372 | } | 1380 | } |
1373 | mctx = GNUNET_new (struct ManageServiceContext); | 1381 | mctx = GNUNET_new(struct ManageServiceContext); |
1374 | mctx->peer = peer; | 1382 | mctx->peer = peer; |
1375 | peer->reference_cnt++; | 1383 | peer->reference_cnt++; |
1376 | mctx->op_id = op_id; | 1384 | mctx->op_id = op_id; |
1377 | mctx->ah = ah; | 1385 | mctx->ah = ah; |
1378 | mctx->client = client; | 1386 | mctx->client = client; |
1379 | mctx->start = msg->start; | 1387 | mctx->start = msg->start; |
1380 | mctx->service = GNUNET_strdup (service); | 1388 | mctx->service = GNUNET_strdup(service); |
1381 | GNUNET_CONTAINER_DLL_insert_tail (mctx_head, | 1389 | GNUNET_CONTAINER_DLL_insert_tail(mctx_head, |
1382 | mctx_tail, | 1390 | mctx_tail, |
1383 | mctx); | 1391 | mctx); |
1384 | if (1 == mctx->start) | 1392 | if (1 == mctx->start) |
1385 | GNUNET_ARM_request_service_start (mctx->ah, | 1393 | GNUNET_ARM_request_service_start(mctx->ah, |
1386 | service, | 1394 | service, |
1387 | GNUNET_OS_INHERIT_STD_ERR, | 1395 | GNUNET_OS_INHERIT_STD_ERR, |
1388 | &service_manage_result_cb, | ||
1389 | mctx); | ||
1390 | else | ||
1391 | GNUNET_ARM_request_service_stop (mctx->ah, service, | ||
1392 | &service_manage_result_cb, | 1396 | &service_manage_result_cb, |
1393 | mctx); | 1397 | mctx); |
1394 | GNUNET_SERVICE_client_continue (client); | 1398 | else |
1399 | GNUNET_ARM_request_service_stop(mctx->ah, service, | ||
1400 | &service_manage_result_cb, | ||
1401 | mctx); | ||
1402 | GNUNET_SERVICE_client_continue(client); | ||
1395 | return; | 1403 | return; |
1396 | 1404 | ||
1397 | err_ret: | 1405 | err_ret: |
1398 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 1406 | LOG(GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); |
1399 | GST_send_operation_fail_msg (client, op_id, emsg); | 1407 | GST_send_operation_fail_msg(client, op_id, emsg); |
1400 | GNUNET_free (emsg); | 1408 | GNUNET_free(emsg); |
1401 | GNUNET_SERVICE_client_continue (client); | 1409 | GNUNET_SERVICE_client_continue(client); |
1402 | } | 1410 | } |
1403 | 1411 | ||
1404 | 1412 | ||
@@ -1406,7 +1414,7 @@ handle_manage_peer_service (void *cls, | |||
1406 | * Stops and destroys all peers | 1414 | * Stops and destroys all peers |
1407 | */ | 1415 | */ |
1408 | void | 1416 | void |
1409 | GST_destroy_peers () | 1417 | GST_destroy_peers() |
1410 | { | 1418 | { |
1411 | struct Peer *peer; | 1419 | struct Peer *peer; |
1412 | unsigned int id; | 1420 | unsigned int id; |
@@ -1414,34 +1422,34 @@ GST_destroy_peers () | |||
1414 | if (NULL == GST_peer_list) | 1422 | if (NULL == GST_peer_list) |
1415 | return; | 1423 | return; |
1416 | for (id = 0; id < GST_peer_list_size; id++) | 1424 | for (id = 0; id < GST_peer_list_size; id++) |
1417 | { | 1425 | { |
1418 | peer = GST_peer_list[id]; | 1426 | peer = GST_peer_list[id]; |
1419 | if (NULL == peer) | 1427 | if (NULL == peer) |
1420 | continue; | 1428 | continue; |
1421 | /* If destroy flag is set it means that this peer should have been | 1429 | /* If destroy flag is set it means that this peer should have been |
1422 | * destroyed by a context which we destroy before */ | 1430 | * destroyed by a context which we destroy before */ |
1423 | GNUNET_break (GNUNET_NO == peer->destroy_flag); | 1431 | GNUNET_break(GNUNET_NO == peer->destroy_flag); |
1424 | /* counter should be zero as we free all contexts before */ | 1432 | /* counter should be zero as we free all contexts before */ |
1425 | GNUNET_break (0 == peer->reference_cnt); | 1433 | GNUNET_break(0 == peer->reference_cnt); |
1426 | if ((GNUNET_NO == peer->is_remote) && | 1434 | if ((GNUNET_NO == peer->is_remote) && |
1427 | (GNUNET_YES == peer->details.local.is_running)) | 1435 | (GNUNET_YES == peer->details.local.is_running)) |
1428 | GNUNET_TESTING_peer_kill (peer->details.local.peer); | 1436 | GNUNET_TESTING_peer_kill(peer->details.local.peer); |
1429 | } | 1437 | } |
1430 | for (id = 0; id < GST_peer_list_size; id++) | 1438 | for (id = 0; id < GST_peer_list_size; id++) |
1431 | { | ||
1432 | peer = GST_peer_list[id]; | ||
1433 | if (NULL == peer) | ||
1434 | continue; | ||
1435 | if (GNUNET_NO == peer->is_remote) | ||
1436 | { | 1439 | { |
1437 | if (GNUNET_YES == peer->details.local.is_running) | 1440 | peer = GST_peer_list[id]; |
1438 | GNUNET_TESTING_peer_wait (peer->details.local.peer); | 1441 | if (NULL == peer) |
1439 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 1442 | continue; |
1440 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | 1443 | if (GNUNET_NO == peer->is_remote) |
1444 | { | ||
1445 | if (GNUNET_YES == peer->details.local.is_running) | ||
1446 | GNUNET_TESTING_peer_wait(peer->details.local.peer); | ||
1447 | GNUNET_TESTING_peer_destroy(peer->details.local.peer); | ||
1448 | GNUNET_CONFIGURATION_destroy(peer->details.local.cfg); | ||
1449 | } | ||
1450 | GNUNET_free(peer); | ||
1441 | } | 1451 | } |
1442 | GNUNET_free (peer); | 1452 | GNUNET_free_non_null(GST_peer_list); |
1443 | } | ||
1444 | GNUNET_free_non_null (GST_peer_list); | ||
1445 | GST_peer_list = NULL; | 1453 | GST_peer_list = NULL; |
1446 | GST_peer_list_size = 0; | 1454 | GST_peer_list_size = 0; |
1447 | } | 1455 | } |
@@ -1456,34 +1464,34 @@ GST_destroy_peers () | |||
1456 | * @param msg the message to relay | 1464 | * @param msg the message to relay |
1457 | */ | 1465 | */ |
1458 | static void | 1466 | static void |
1459 | shutdown_peers_reply_cb (void *cls, | 1467 | shutdown_peers_reply_cb(void *cls, |
1460 | const struct GNUNET_MessageHeader *msg) | 1468 | const struct GNUNET_MessageHeader *msg) |
1461 | { | 1469 | { |
1462 | struct ForwardedOperationContext *fo_ctxt = cls; | 1470 | struct ForwardedOperationContext *fo_ctxt = cls; |
1463 | struct HandlerContext_ShutdownPeers *hc; | 1471 | struct HandlerContext_ShutdownPeers *hc; |
1464 | 1472 | ||
1465 | hc = fo_ctxt->cls; | 1473 | hc = fo_ctxt->cls; |
1466 | GNUNET_assert (0 < hc->nslaves); | 1474 | GNUNET_assert(0 < hc->nslaves); |
1467 | hc->nslaves--; | 1475 | hc->nslaves--; |
1468 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != | 1476 | if (GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS != |
1469 | ntohs (msg->type)) | 1477 | ntohs(msg->type)) |
1470 | hc->timeout = GNUNET_YES; | 1478 | hc->timeout = GNUNET_YES; |
1471 | if (0 == hc->nslaves) | 1479 | if (0 == hc->nslaves) |
1472 | { | 1480 | { |
1473 | if (GNUNET_YES == hc->timeout) | 1481 | if (GNUNET_YES == hc->timeout) |
1474 | GST_send_operation_fail_msg (fo_ctxt->client, | 1482 | GST_send_operation_fail_msg(fo_ctxt->client, |
1475 | fo_ctxt->operation_id, | 1483 | fo_ctxt->operation_id, |
1476 | "Timeout at a slave controller"); | 1484 | "Timeout at a slave controller"); |
1477 | else | 1485 | else |
1478 | GST_send_operation_success_msg (fo_ctxt->client, | 1486 | GST_send_operation_success_msg(fo_ctxt->client, |
1479 | fo_ctxt->operation_id); | 1487 | fo_ctxt->operation_id); |
1480 | GNUNET_free (hc); | 1488 | GNUNET_free(hc); |
1481 | hc = NULL; | 1489 | hc = NULL; |
1482 | } | 1490 | } |
1483 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | 1491 | GNUNET_CONTAINER_DLL_remove(fopcq_head, |
1484 | fopcq_tail, | 1492 | fopcq_tail, |
1485 | fo_ctxt); | 1493 | fo_ctxt); |
1486 | GNUNET_free (fo_ctxt); | 1494 | GNUNET_free(fo_ctxt); |
1487 | } | 1495 | } |
1488 | 1496 | ||
1489 | 1497 | ||
@@ -1494,8 +1502,8 @@ shutdown_peers_reply_cb (void *cls, | |||
1494 | * @param msg the actual message | 1502 | * @param msg the actual message |
1495 | */ | 1503 | */ |
1496 | void | 1504 | void |
1497 | handle_shutdown_peers (void *cls, | 1505 | handle_shutdown_peers(void *cls, |
1498 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) | 1506 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) |
1499 | { | 1507 | { |
1500 | struct GNUNET_SERVICE_Client *client = cls; | 1508 | struct GNUNET_SERVICE_Client *client = cls; |
1501 | struct HandlerContext_ShutdownPeers *hc; | 1509 | struct HandlerContext_ShutdownPeers *hc; |
@@ -1504,48 +1512,48 @@ handle_shutdown_peers (void *cls, | |||
1504 | uint64_t op_id; | 1512 | uint64_t op_id; |
1505 | unsigned int cnt; | 1513 | unsigned int cnt; |
1506 | 1514 | ||
1507 | LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); | 1515 | LOG_DEBUG("Received SHUTDOWN_PEERS\n"); |
1508 | /* Stop and destroy all peers */ | 1516 | /* Stop and destroy all peers */ |
1509 | GST_free_mctxq (); | 1517 | GST_free_mctxq(); |
1510 | GST_free_occq (); | 1518 | GST_free_occq(); |
1511 | GST_free_roccq (); | 1519 | GST_free_roccq(); |
1512 | GST_clear_fopcq (); | 1520 | GST_clear_fopcq(); |
1513 | /* Forward to all slaves which we have started */ | 1521 | /* Forward to all slaves which we have started */ |
1514 | op_id = GNUNET_ntohll (msg->operation_id); | 1522 | op_id = GNUNET_ntohll(msg->operation_id); |
1515 | hc = GNUNET_new (struct HandlerContext_ShutdownPeers); | 1523 | hc = GNUNET_new(struct HandlerContext_ShutdownPeers); |
1516 | /* FIXME: have a better implementation where we track which slaves are | 1524 | /* FIXME: have a better implementation where we track which slaves are |
1517 | started by this controller */ | 1525 | started by this controller */ |
1518 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) | 1526 | for (cnt = 0; cnt < GST_slave_list_size; cnt++) |
1519 | { | 1527 | { |
1520 | slave = GST_slave_list[cnt]; | 1528 | slave = GST_slave_list[cnt]; |
1521 | if (NULL == slave) | 1529 | if (NULL == slave) |
1522 | continue; | 1530 | continue; |
1523 | if (NULL == slave->controller_proc) /* We didn't start the slave */ | 1531 | if (NULL == slave->controller_proc) /* We didn't start the slave */ |
1524 | continue; | 1532 | continue; |
1525 | LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n"); | 1533 | LOG_DEBUG("Forwarding SHUTDOWN_PEERS\n"); |
1526 | hc->nslaves++; | 1534 | hc->nslaves++; |
1527 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 1535 | fo_ctxt = GNUNET_new(struct ForwardedOperationContext); |
1528 | fo_ctxt->client = client; | 1536 | fo_ctxt->client = client; |
1529 | fo_ctxt->operation_id = op_id; | 1537 | fo_ctxt->operation_id = op_id; |
1530 | fo_ctxt->cls = hc; | 1538 | fo_ctxt->cls = hc; |
1531 | fo_ctxt->type = OP_SHUTDOWN_PEERS; | 1539 | fo_ctxt->type = OP_SHUTDOWN_PEERS; |
1532 | fo_ctxt->opc = | 1540 | fo_ctxt->opc = |
1533 | GNUNET_TESTBED_forward_operation_msg_ (slave->controller, | 1541 | GNUNET_TESTBED_forward_operation_msg_(slave->controller, |
1534 | fo_ctxt->operation_id, | 1542 | fo_ctxt->operation_id, |
1535 | &msg->header, | 1543 | &msg->header, |
1536 | shutdown_peers_reply_cb, | 1544 | shutdown_peers_reply_cb, |
1537 | fo_ctxt); | 1545 | fo_ctxt); |
1538 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1546 | GNUNET_CONTAINER_DLL_insert_tail(fopcq_head, |
1539 | fopcq_tail, | 1547 | fopcq_tail, |
1540 | fo_ctxt); | 1548 | fo_ctxt); |
1541 | } | 1549 | } |
1542 | LOG_DEBUG ("Shutting down peers\n"); | 1550 | LOG_DEBUG("Shutting down peers\n"); |
1543 | GST_destroy_peers (); | 1551 | GST_destroy_peers(); |
1544 | if (0 == hc->nslaves) | 1552 | if (0 == hc->nslaves) |
1545 | { | 1553 | { |
1546 | GST_send_operation_success_msg (client, | 1554 | GST_send_operation_success_msg(client, |
1547 | op_id); | 1555 | op_id); |
1548 | GNUNET_free (hc); | 1556 | GNUNET_free(hc); |
1549 | } | 1557 | } |
1550 | GNUNET_SERVICE_client_continue (client); | 1558 | GNUNET_SERVICE_client_continue(client); |
1551 | } | 1559 | } |