diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-10-10 15:47:00 +0000 |
commit | 93085e8a2991fde229400b588a5930e9fcca0d75 (patch) | |
tree | 0384246adbd96fa0138a46ad5fecb777aa40e789 /src/testbed/gnunet-service-testbed_peers.c | |
parent | 2bf962c76bb82c1f38acea42c7bdfb241e2582e7 (diff) | |
download | gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.tar.gz gnunet-93085e8a2991fde229400b588a5930e9fcca0d75.zip |
migrating testbed to new service API
Diffstat (limited to 'src/testbed/gnunet-service-testbed_peers.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_peers.c | 596 |
1 files changed, 322 insertions, 274 deletions
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c index b55f5a8c8..a977b2b9b 100644 --- a/src/testbed/gnunet-service-testbed_peers.c +++ b/src/testbed/gnunet-service-testbed_peers.c | |||
@@ -69,7 +69,7 @@ struct ManageServiceContext | |||
69 | /** | 69 | /** |
70 | * The client which requested to manage the peer's service | 70 | * The client which requested to manage the peer's service |
71 | */ | 71 | */ |
72 | struct GNUNET_SERVER_Client *client; | 72 | struct GNUNET_SERVICE_Client *client; |
73 | 73 | ||
74 | /** | 74 | /** |
75 | * Name of the service. | 75 | * Name of the service. |
@@ -112,7 +112,7 @@ struct PeerReconfigureContext | |||
112 | /** | 112 | /** |
113 | * The client which gave this operation to us | 113 | * The client which gave this operation to us |
114 | */ | 114 | */ |
115 | struct GNUNET_SERVER_Client *client; | 115 | struct GNUNET_SERVICE_Client *client; |
116 | 116 | ||
117 | /** | 117 | /** |
118 | * The configuration handle to use as the new template | 118 | * The configuration handle to use as the new template |
@@ -246,7 +246,8 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
246 | remote_peer = fopc->cls; | 246 | remote_peer = fopc->cls; |
247 | peer_list_add (remote_peer); | 247 | peer_list_add (remote_peer); |
248 | } | 248 | } |
249 | GST_forwarded_operation_reply_relay (fopc, msg); | 249 | GST_forwarded_operation_reply_relay (fopc, |
250 | msg); | ||
250 | } | 251 | } |
251 | 252 | ||
252 | 253 | ||
@@ -278,6 +279,115 @@ GST_destroy_peer (struct Peer *peer) | |||
278 | 279 | ||
279 | 280 | ||
280 | /** | 281 | /** |
282 | * Cleanup the context information created for managing a peer's service | ||
283 | * | ||
284 | * @param mctx the ManageServiceContext | ||
285 | */ | ||
286 | static void | ||
287 | cleanup_mctx (struct ManageServiceContext *mctx) | ||
288 | { | ||
289 | mctx->expired = GNUNET_YES; | ||
290 | GNUNET_CONTAINER_DLL_remove (mctx_head, | ||
291 | mctx_tail, | ||
292 | mctx); | ||
293 | GNUNET_ARM_disconnect (mctx->ah); | ||
294 | GNUNET_assert (0 < mctx->peer->reference_cnt); | ||
295 | mctx->peer->reference_cnt--; | ||
296 | if ( (GNUNET_YES == mctx->peer->destroy_flag) && | ||
297 | (0 == mctx->peer->reference_cnt) ) | ||
298 | GST_destroy_peer (mctx->peer); | ||
299 | GNUNET_free (mctx->service); | ||
300 | GNUNET_free (mctx); | ||
301 | } | ||
302 | |||
303 | |||
304 | /** | ||
305 | * Stops a peer | ||
306 | * | ||
307 | * @param peer the peer to stop | ||
308 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | ||
309 | */ | ||
310 | static int | ||
311 | stop_peer (struct Peer *peer) | ||
312 | { | ||
313 | GNUNET_assert (GNUNET_NO == peer->is_remote); | ||
314 | if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer)) | ||
315 | return GNUNET_SYSERR; | ||
316 | peer->details.local.is_running = GNUNET_NO; | ||
317 | return GNUNET_OK; | ||
318 | } | ||
319 | |||
320 | |||
321 | /** | ||
322 | * Cleans up the given PeerReconfigureContext | ||
323 | * | ||
324 | * @param prc the PeerReconfigureContext | ||
325 | */ | ||
326 | static void | ||
327 | cleanup_prc (struct PeerReconfigureContext *prc) | ||
328 | { | ||
329 | struct Peer *peer; | ||
330 | |||
331 | if (VALID_PEER_ID (prc->peer_id)) | ||
332 | { | ||
333 | peer = GST_peer_list [prc->peer_id]; | ||
334 | if (1 != prc->stopped) | ||
335 | { | ||
336 | GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); | ||
337 | stop_peer (peer); /* Stop the peer synchronously */ | ||
338 | } | ||
339 | } | ||
340 | if (NULL != prc->cfg) | ||
341 | GNUNET_CONFIGURATION_destroy (prc->cfg); | ||
342 | GNUNET_CONTAINER_DLL_remove (prc_head, | ||
343 | prc_tail, | ||
344 | prc); | ||
345 | GNUNET_free (prc); | ||
346 | } | ||
347 | |||
348 | |||
349 | /** | ||
350 | * Notify peers subsystem that @a client disconnected. | ||
351 | * | ||
352 | * @param client the client that disconnected | ||
353 | */ | ||
354 | void | ||
355 | GST_notify_client_disconnect_peers (struct GNUNET_SERVICE_Client *client) | ||
356 | { | ||
357 | struct ForwardedOperationContext *fopc; | ||
358 | struct ForwardedOperationContext *fopcn; | ||
359 | struct ManageServiceContext *mctx; | ||
360 | struct ManageServiceContext *mctxn; | ||
361 | struct PeerReconfigureContext *prc; | ||
362 | struct PeerReconfigureContext *prcn; | ||
363 | |||
364 | for (fopc = fopcq_head; NULL != fopc; fopc = fopcn) | ||
365 | { | ||
366 | fopcn = fopc->next; | ||
367 | if (client == fopc->client) | ||
368 | { | ||
369 | if (OP_PEER_CREATE == fopc->type) | ||
370 | GNUNET_free (fopc->cls); | ||
371 | GNUNET_SCHEDULER_cancel (fopc->timeout_task); | ||
372 | GST_forwarded_operation_timeout (fopc); | ||
373 | } | ||
374 | } | ||
375 | for (mctx = mctx_head; NULL != mctx; mctx = mctxn) | ||
376 | { | ||
377 | mctxn = mctx->next; | ||
378 | if (client == mctx->client) | ||
379 | cleanup_mctx (mctx); | ||
380 | } | ||
381 | for (prc = prc_head; NULL != prc; prc = prcn) | ||
382 | { | ||
383 | prcn = prc->next; | ||
384 | if (client == prc->client) | ||
385 | cleanup_prc (prc); | ||
386 | } | ||
387 | } | ||
388 | |||
389 | |||
390 | /** | ||
281 | * Callback to be called when forwarded peer destroy operation is successfull. We | 391 | * Callback to be called when forwarded peer destroy operation is successfull. We |
282 | * have to relay the reply msg back to the client | 392 | * have to relay the reply msg back to the client |
283 | * | 393 | * |
@@ -299,22 +409,38 @@ peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg) | |||
299 | if (0 == remote_peer->reference_cnt) | 409 | if (0 == remote_peer->reference_cnt) |
300 | GST_destroy_peer (remote_peer); | 410 | GST_destroy_peer (remote_peer); |
301 | } | 411 | } |
302 | GST_forwarded_operation_reply_relay (fopc, msg); | 412 | GST_forwarded_operation_reply_relay (fopc, |
413 | msg); | ||
414 | } | ||
415 | |||
416 | |||
417 | /** | ||
418 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages | ||
419 | * | ||
420 | * @param cls identification of the client | ||
421 | * @param msg the actual message | ||
422 | * @return #GNUNET_OK if @a msg is well-formed | ||
423 | */ | ||
424 | int | ||
425 | check_peer_create (void *cls, | ||
426 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) | ||
427 | { | ||
428 | return GNUNET_OK; /* checked later */ | ||
303 | } | 429 | } |
304 | 430 | ||
305 | 431 | ||
306 | /** | 432 | /** |
307 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages | 433 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_CREATEPEER messages |
308 | * | 434 | * |
309 | * @param cls NULL | 435 | * @param cls identification of the client |
310 | * @param client identification of the client | 436 | * @param msg the actual message |
311 | * @param message the actual message | ||
312 | */ | 437 | */ |
313 | void | 438 | void |
314 | GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | 439 | handle_peer_create (void *cls, |
315 | const struct GNUNET_MessageHeader *message) | 440 | const struct GNUNET_TESTBED_PeerCreateMessage *msg) |
316 | { | 441 | { |
317 | const struct GNUNET_TESTBED_PeerCreateMessage *msg; | 442 | struct GNUNET_SERVICE_Client *client = cls; |
443 | struct GNUNET_MQ_Envelope *env; | ||
318 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; | 444 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage *reply; |
319 | struct GNUNET_CONFIGURATION_Handle *cfg; | 445 | struct GNUNET_CONFIGURATION_Handle *cfg; |
320 | struct ForwardedOperationContext *fo_ctxt; | 446 | struct ForwardedOperationContext *fo_ctxt; |
@@ -323,55 +449,54 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
323 | char *emsg; | 449 | char *emsg; |
324 | uint32_t host_id; | 450 | uint32_t host_id; |
325 | uint32_t peer_id; | 451 | uint32_t peer_id; |
326 | uint16_t msize; | ||
327 | |||
328 | 452 | ||
329 | msize = ntohs (message->size); | ||
330 | if (msize <= sizeof (struct GNUNET_TESTBED_PeerCreateMessage)) | ||
331 | { | ||
332 | GNUNET_break (0); /* We need configuration */ | ||
333 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
334 | return; | ||
335 | } | ||
336 | msg = (const struct GNUNET_TESTBED_PeerCreateMessage *) message; | ||
337 | host_id = ntohl (msg->host_id); | 453 | host_id = ntohl (msg->host_id); |
338 | peer_id = ntohl (msg->peer_id); | 454 | peer_id = ntohl (msg->peer_id); |
339 | if (VALID_PEER_ID (peer_id)) | 455 | if (VALID_PEER_ID (peer_id)) |
340 | { | 456 | { |
341 | (void) GNUNET_asprintf (&emsg, "Peer with ID %u already exists", peer_id); | 457 | (void) GNUNET_asprintf (&emsg, |
342 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 458 | "Peer with ID %u already exists", |
459 | peer_id); | ||
460 | GST_send_operation_fail_msg (client, | ||
461 | GNUNET_ntohll (msg->operation_id), | ||
343 | emsg); | 462 | emsg); |
344 | GNUNET_free (emsg); | 463 | GNUNET_free (emsg); |
345 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 464 | GNUNET_SERVICE_client_continue (client); |
346 | return; | 465 | return; |
347 | } | 466 | } |
348 | if (UINT32_MAX == peer_id) | 467 | if (UINT32_MAX == peer_id) |
349 | { | 468 | { |
350 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 469 | GST_send_operation_fail_msg (client, |
470 | GNUNET_ntohll (msg->operation_id), | ||
351 | "Cannot create peer with given ID"); | 471 | "Cannot create peer with given ID"); |
352 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 472 | GNUNET_SERVICE_client_continue (client); |
353 | return; | 473 | return; |
354 | } | 474 | } |
355 | if (host_id == GST_context->host_id) | 475 | if (host_id == GST_context->host_id) |
356 | { | 476 | { |
357 | /* We are responsible for this peer */ | 477 | /* We are responsible for this peer */ |
358 | cfg = GNUNET_TESTBED_extract_config_ (message); | 478 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); |
359 | if (NULL == cfg) | 479 | if (NULL == cfg) |
360 | { | 480 | { |
361 | GNUNET_break (0); | 481 | GNUNET_break (0); |
362 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 482 | GNUNET_SERVICE_client_drop (client); |
363 | return; | 483 | return; |
364 | } | 484 | } |
365 | GNUNET_CONFIGURATION_set_value_number (cfg, "TESTBED", "PEERID", | 485 | GNUNET_CONFIGURATION_set_value_number (cfg, |
486 | "TESTBED", | ||
487 | "PEERID", | ||
366 | (unsigned long long) peer_id); | 488 | (unsigned long long) peer_id); |
367 | 489 | ||
368 | GNUNET_CONFIGURATION_set_value_number (cfg, "PATHS", "PEERID", | 490 | GNUNET_CONFIGURATION_set_value_number (cfg, |
491 | "PATHS", | ||
492 | "PEERID", | ||
369 | (unsigned long long) peer_id); | 493 | (unsigned long long) peer_id); |
370 | peer = GNUNET_new (struct Peer); | 494 | peer = GNUNET_new (struct Peer); |
371 | peer->is_remote = GNUNET_NO; | 495 | peer->is_remote = GNUNET_NO; |
372 | peer->details.local.cfg = cfg; | 496 | peer->details.local.cfg = cfg; |
373 | peer->id = peer_id; | 497 | peer->id = peer_id; |
374 | LOG_DEBUG ("Creating peer with id: %u\n", (unsigned int) peer->id); | 498 | LOG_DEBUG ("Creating peer with id: %u\n", |
499 | (unsigned int) peer->id); | ||
375 | peer->details.local.peer = | 500 | peer->details.local.peer = |
376 | GNUNET_TESTING_peer_configure (GST_context->system, | 501 | GNUNET_TESTING_peer_configure (GST_context->system, |
377 | peer->details.local.cfg, peer->id, | 502 | peer->details.local.cfg, peer->id, |
@@ -379,24 +504,24 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
379 | &emsg); | 504 | &emsg); |
380 | if (NULL == peer->details.local.peer) | 505 | if (NULL == peer->details.local.peer) |
381 | { | 506 | { |
382 | LOG (GNUNET_ERROR_TYPE_WARNING, "Configuring peer failed: %s\n", emsg); | 507 | LOG (GNUNET_ERROR_TYPE_WARNING, |
508 | "Configuring peer failed: %s\n", | ||
509 | emsg); | ||
383 | GNUNET_free (emsg); | 510 | GNUNET_free (emsg); |
384 | GNUNET_free (peer); | 511 | GNUNET_free (peer); |
385 | GNUNET_break (0); | 512 | GNUNET_break (0); |
386 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 513 | GNUNET_SERVICE_client_drop (client); |
387 | return; | 514 | return; |
388 | } | 515 | } |
389 | peer->details.local.is_running = GNUNET_NO; | 516 | peer->details.local.is_running = GNUNET_NO; |
390 | peer_list_add (peer); | 517 | peer_list_add (peer); |
391 | reply = GNUNET_new (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage); | 518 | env = GNUNET_MQ_msg (reply, |
392 | reply->header.size = | 519 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); |
393 | htons (sizeof (struct GNUNET_TESTBED_PeerCreateSuccessEventMessage)); | ||
394 | reply->header.type = | ||
395 | htons (GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS); | ||
396 | reply->peer_id = msg->peer_id; | 520 | reply->peer_id = msg->peer_id; |
397 | reply->operation_id = msg->operation_id; | 521 | reply->operation_id = msg->operation_id; |
398 | GST_queue_message (client, &reply->header); | 522 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
399 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 523 | env); |
524 | GNUNET_SERVICE_client_continue (client); | ||
400 | return; | 525 | return; |
401 | } | 526 | } |
402 | 527 | ||
@@ -405,7 +530,7 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
405 | if (NULL == route) | 530 | if (NULL == route) |
406 | { | 531 | { |
407 | GNUNET_break (0); | 532 | GNUNET_break (0); |
408 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 533 | GNUNET_SERVICE_client_continue (client); // ? |
409 | return; | 534 | return; |
410 | } | 535 | } |
411 | peer = GNUNET_new (struct Peer); | 536 | peer = GNUNET_new (struct Peer); |
@@ -414,7 +539,6 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
414 | peer->details.remote.slave = GST_slave_list[route->dest]; | 539 | peer->details.remote.slave = GST_slave_list[route->dest]; |
415 | peer->details.remote.remote_host_id = host_id; | 540 | peer->details.remote.remote_host_id = host_id; |
416 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 541 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); |
417 | GNUNET_SERVER_client_keep (client); | ||
418 | fo_ctxt->client = client; | 542 | fo_ctxt->client = client; |
419 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); | 543 | fo_ctxt->operation_id = GNUNET_ntohll (msg->operation_id); |
420 | fo_ctxt->cls = peer; | 544 | fo_ctxt->cls = peer; |
@@ -424,34 +548,34 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
424 | [route->dest]->controller, | 548 | [route->dest]->controller, |
425 | fo_ctxt->operation_id, | 549 | fo_ctxt->operation_id, |
426 | &msg->header, | 550 | &msg->header, |
427 | peer_create_success_cb, fo_ctxt); | 551 | &peer_create_success_cb, |
552 | fo_ctxt); | ||
428 | fo_ctxt->timeout_task = | 553 | fo_ctxt->timeout_task = |
429 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 554 | GNUNET_SCHEDULER_add_delayed (GST_timeout, |
430 | &peer_create_forward_timeout, | 555 | &peer_create_forward_timeout, |
431 | fo_ctxt); | 556 | fo_ctxt); |
432 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt); | 557 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
433 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 558 | fopcq_tail, |
559 | fo_ctxt); | ||
560 | GNUNET_SERVICE_client_continue (client); | ||
434 | } | 561 | } |
435 | 562 | ||
436 | 563 | ||
437 | /** | 564 | /** |
438 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages | 565 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages |
439 | * | 566 | * |
440 | * @param cls NULL | 567 | * @param cls identification of the client |
441 | * @param client identification of the client | 568 | * @param msg the actual message |
442 | * @param message the actual message | ||
443 | */ | 569 | */ |
444 | void | 570 | void |
445 | GST_handle_peer_destroy (void *cls, | 571 | handle_peer_destroy (void *cls, |
446 | struct GNUNET_SERVER_Client *client, | 572 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg) |
447 | const struct GNUNET_MessageHeader *message) | ||
448 | { | 573 | { |
449 | const struct GNUNET_TESTBED_PeerDestroyMessage *msg; | 574 | struct GNUNET_SERVICE_Client *client = cls; |
450 | struct ForwardedOperationContext *fopc; | 575 | struct ForwardedOperationContext *fopc; |
451 | struct Peer *peer; | 576 | struct Peer *peer; |
452 | uint32_t peer_id; | 577 | uint32_t peer_id; |
453 | 578 | ||
454 | msg = (const struct GNUNET_TESTBED_PeerDestroyMessage *) message; | ||
455 | peer_id = ntohl (msg->peer_id); | 579 | peer_id = ntohl (msg->peer_id); |
456 | LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n", | 580 | LOG_DEBUG ("Received peer destory on peer: %u and operation id: %llu\n", |
457 | (unsigned int) peer_id, | 581 | (unsigned int) peer_id, |
@@ -460,9 +584,10 @@ GST_handle_peer_destroy (void *cls, | |||
460 | { | 584 | { |
461 | LOG (GNUNET_ERROR_TYPE_ERROR, | 585 | LOG (GNUNET_ERROR_TYPE_ERROR, |
462 | "Asked to destroy a non existent peer with id: %u\n", peer_id); | 586 | "Asked to destroy a non existent peer with id: %u\n", peer_id); |
463 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 587 | GST_send_operation_fail_msg (client, |
588 | GNUNET_ntohll (msg->operation_id), | ||
464 | "Peer doesn't exist"); | 589 | "Peer doesn't exist"); |
465 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 590 | GNUNET_SERVICE_client_continue (client); |
466 | return; | 591 | return; |
467 | } | 592 | } |
468 | peer = GST_peer_list[peer_id]; | 593 | peer = GST_peer_list[peer_id]; |
@@ -470,7 +595,6 @@ GST_handle_peer_destroy (void *cls, | |||
470 | { | 595 | { |
471 | /* Forward the destory message to sub controller */ | 596 | /* Forward the destory message to sub controller */ |
472 | fopc = GNUNET_new (struct ForwardedOperationContext); | 597 | fopc = GNUNET_new (struct ForwardedOperationContext); |
473 | GNUNET_SERVER_client_keep (client); | ||
474 | fopc->client = client; | 598 | fopc->client = client; |
475 | fopc->cls = peer; | 599 | fopc->cls = peer; |
476 | fopc->type = OP_PEER_DESTROY; | 600 | fopc->type = OP_PEER_DESTROY; |
@@ -478,14 +602,18 @@ GST_handle_peer_destroy (void *cls, | |||
478 | fopc->opc = | 602 | fopc->opc = |
479 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. | 603 | GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. |
480 | slave->controller, | 604 | slave->controller, |
481 | fopc->operation_id, &msg->header, | 605 | fopc->operation_id, |
482 | &peer_destroy_success_cb, fopc); | 606 | &msg->header, |
607 | &peer_destroy_success_cb, | ||
608 | fopc); | ||
483 | fopc->timeout_task = | 609 | fopc->timeout_task = |
484 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 610 | GNUNET_SCHEDULER_add_delayed (GST_timeout, |
485 | &GST_forwarded_operation_timeout, | 611 | &GST_forwarded_operation_timeout, |
486 | fopc); | 612 | fopc); |
487 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc); | 613 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
488 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 614 | fopcq_tail, |
615 | fopc); | ||
616 | GNUNET_SERVICE_client_continue (client); | ||
489 | return; | 617 | return; |
490 | } | 618 | } |
491 | peer->destroy_flag = GNUNET_YES; | 619 | peer->destroy_flag = GNUNET_YES; |
@@ -494,8 +622,9 @@ GST_handle_peer_destroy (void *cls, | |||
494 | else | 622 | else |
495 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 623 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
496 | "Delaying peer destroy as peer is currently in use\n"); | 624 | "Delaying peer destroy as peer is currently in use\n"); |
497 | GST_send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id)); | 625 | GST_send_operation_success_msg (client, |
498 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 626 | GNUNET_ntohll (msg->operation_id)); |
627 | GNUNET_SERVICE_client_continue (client); | ||
499 | } | 628 | } |
500 | 629 | ||
501 | 630 | ||
@@ -517,54 +646,36 @@ start_peer (struct Peer *peer) | |||
517 | 646 | ||
518 | 647 | ||
519 | /** | 648 | /** |
520 | * Stops a peer | 649 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_START_PEER messages |
521 | * | 650 | * |
522 | * @param peer the peer to stop | 651 | * @param cls identification of the client |
523 | * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure | 652 | * @param msg the actual message |
524 | */ | ||
525 | static int | ||
526 | stop_peer (struct Peer *peer) | ||
527 | { | ||
528 | GNUNET_assert (GNUNET_NO == peer->is_remote); | ||
529 | if (GNUNET_OK != GNUNET_TESTING_peer_kill (peer->details.local.peer)) | ||
530 | return GNUNET_SYSERR; | ||
531 | peer->details.local.is_running = GNUNET_NO; | ||
532 | return GNUNET_OK; | ||
533 | } | ||
534 | |||
535 | |||
536 | /** | ||
537 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages | ||
538 | * | ||
539 | * @param cls NULL | ||
540 | * @param client identification of the client | ||
541 | * @param message the actual message | ||
542 | */ | 653 | */ |
543 | void | 654 | void |
544 | GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client, | 655 | handle_peer_start (void *cls, |
545 | const struct GNUNET_MessageHeader *message) | 656 | const struct GNUNET_TESTBED_PeerStartMessage *msg) |
546 | { | 657 | { |
547 | const struct GNUNET_TESTBED_PeerStartMessage *msg; | 658 | struct GNUNET_SERVICE_Client *client = cls; |
659 | struct GNUNET_MQ_Envelope *env; | ||
548 | struct GNUNET_TESTBED_PeerEventMessage *reply; | 660 | struct GNUNET_TESTBED_PeerEventMessage *reply; |
549 | struct ForwardedOperationContext *fopc; | 661 | struct ForwardedOperationContext *fopc; |
550 | struct Peer *peer; | 662 | struct Peer *peer; |
551 | uint32_t peer_id; | 663 | uint32_t peer_id; |
552 | 664 | ||
553 | msg = (const struct GNUNET_TESTBED_PeerStartMessage *) message; | ||
554 | peer_id = ntohl (msg->peer_id); | 665 | peer_id = ntohl (msg->peer_id); |
555 | if (!VALID_PEER_ID (peer_id)) | 666 | if (! VALID_PEER_ID (peer_id)) |
556 | { | 667 | { |
557 | GNUNET_break (0); | 668 | GNUNET_break (0); |
558 | LOG (GNUNET_ERROR_TYPE_ERROR, | 669 | LOG (GNUNET_ERROR_TYPE_ERROR, |
559 | "Asked to start a non existent peer with id: %u\n", peer_id); | 670 | "Asked to start a non existent peer with id: %u\n", |
560 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 671 | peer_id); |
672 | GNUNET_SERVICE_client_continue (client); | ||
561 | return; | 673 | return; |
562 | } | 674 | } |
563 | peer = GST_peer_list[peer_id]; | 675 | peer = GST_peer_list[peer_id]; |
564 | if (GNUNET_YES == peer->is_remote) | 676 | if (GNUNET_YES == peer->is_remote) |
565 | { | 677 | { |
566 | fopc = GNUNET_new (struct ForwardedOperationContext); | 678 | fopc = GNUNET_new (struct ForwardedOperationContext); |
567 | GNUNET_SERVER_client_keep (client); | ||
568 | fopc->client = client; | 679 | fopc->client = client; |
569 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 680 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); |
570 | fopc->type = OP_PEER_START; | 681 | fopc->type = OP_PEER_START; |
@@ -578,58 +689,58 @@ GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client, | |||
578 | GNUNET_SCHEDULER_add_delayed (GST_timeout, | 689 | GNUNET_SCHEDULER_add_delayed (GST_timeout, |
579 | &GST_forwarded_operation_timeout, | 690 | &GST_forwarded_operation_timeout, |
580 | fopc); | 691 | fopc); |
581 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc); | 692 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
582 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 693 | fopcq_tail, |
694 | fopc); | ||
695 | GNUNET_SERVICE_client_continue (client); | ||
583 | return; | 696 | return; |
584 | } | 697 | } |
585 | if (GNUNET_OK != start_peer (peer)) | 698 | if (GNUNET_OK != start_peer (peer)) |
586 | { | 699 | { |
587 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), | 700 | GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), |
588 | "Failed to start"); | 701 | "Failed to start"); |
589 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 702 | GNUNET_SERVICE_client_continue (client); |
590 | return; | 703 | return; |
591 | } | 704 | } |
592 | reply = GNUNET_new (struct GNUNET_TESTBED_PeerEventMessage); | 705 | env = GNUNET_MQ_msg (reply, |
593 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 706 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
594 | reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage)); | ||
595 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START); | 707 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_START); |
596 | reply->host_id = htonl (GST_context->host_id); | 708 | reply->host_id = htonl (GST_context->host_id); |
597 | reply->peer_id = msg->peer_id; | 709 | reply->peer_id = msg->peer_id; |
598 | reply->operation_id = msg->operation_id; | 710 | reply->operation_id = msg->operation_id; |
599 | GST_queue_message (client, &reply->header); | 711 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
600 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 712 | env); |
713 | GNUNET_SERVICE_client_continue (client); | ||
601 | } | 714 | } |
602 | 715 | ||
603 | 716 | ||
604 | /** | 717 | /** |
605 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages | 718 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_STOP_PEER messages |
606 | * | 719 | * |
607 | * @param cls NULL | 720 | * @param cls identification of the client |
608 | * @param client identification of the client | 721 | * @param msg the actual message |
609 | * @param message the actual message | ||
610 | */ | 722 | */ |
611 | void | 723 | void |
612 | GST_handle_peer_stop (void *cls, | 724 | handle_peer_stop (void *cls, |
613 | struct GNUNET_SERVER_Client *client, | 725 | const struct GNUNET_TESTBED_PeerStopMessage *msg) |
614 | const struct GNUNET_MessageHeader *message) | ||
615 | { | 726 | { |
616 | const struct GNUNET_TESTBED_PeerStopMessage *msg; | 727 | struct GNUNET_SERVICE_Client *client = cls; |
728 | struct GNUNET_MQ_Envelope *env; | ||
617 | struct GNUNET_TESTBED_PeerEventMessage *reply; | 729 | struct GNUNET_TESTBED_PeerEventMessage *reply; |
618 | struct ForwardedOperationContext *fopc; | 730 | struct ForwardedOperationContext *fopc; |
619 | struct Peer *peer; | 731 | struct Peer *peer; |
620 | uint32_t peer_id; | 732 | uint32_t peer_id; |
621 | 733 | ||
622 | msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message; | ||
623 | peer_id = ntohl (msg->peer_id); | 734 | peer_id = ntohl (msg->peer_id); |
624 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 735 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
625 | "Received PEER_STOP for peer %u\n", | 736 | "Received PEER_STOP for peer %u\n", |
626 | (unsigned int) peer_id); | 737 | (unsigned int) peer_id); |
627 | if (!VALID_PEER_ID (peer_id)) | 738 | if (! VALID_PEER_ID (peer_id)) |
628 | { | 739 | { |
629 | GST_send_operation_fail_msg (client, | 740 | GST_send_operation_fail_msg (client, |
630 | GNUNET_ntohll (msg->operation_id), | 741 | GNUNET_ntohll (msg->operation_id), |
631 | "Peer not found"); | 742 | "Peer not found"); |
632 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 743 | GNUNET_SERVICE_client_continue (client); |
633 | return; | 744 | return; |
634 | } | 745 | } |
635 | peer = GST_peer_list[peer_id]; | 746 | peer = GST_peer_list[peer_id]; |
@@ -639,7 +750,6 @@ GST_handle_peer_stop (void *cls, | |||
639 | "Forwarding PEER_STOP for peer %u\n", | 750 | "Forwarding PEER_STOP for peer %u\n", |
640 | (unsigned int) peer_id); | 751 | (unsigned int) peer_id); |
641 | fopc = GNUNET_new (struct ForwardedOperationContext); | 752 | fopc = GNUNET_new (struct ForwardedOperationContext); |
642 | GNUNET_SERVER_client_keep (client); | ||
643 | fopc->client = client; | 753 | fopc->client = client; |
644 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 754 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); |
645 | fopc->type = OP_PEER_STOP; | 755 | fopc->type = OP_PEER_STOP; |
@@ -657,7 +767,7 @@ GST_handle_peer_stop (void *cls, | |||
657 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 767 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
658 | fopcq_tail, | 768 | fopcq_tail, |
659 | fopc); | 769 | fopc); |
660 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 770 | GNUNET_SERVICE_client_continue (client); |
661 | return; | 771 | return; |
662 | } | 772 | } |
663 | if (GNUNET_OK != stop_peer (peer)) | 773 | if (GNUNET_OK != stop_peer (peer)) |
@@ -668,38 +778,37 @@ GST_handle_peer_stop (void *cls, | |||
668 | GST_send_operation_fail_msg (client, | 778 | GST_send_operation_fail_msg (client, |
669 | GNUNET_ntohll (msg->operation_id), | 779 | GNUNET_ntohll (msg->operation_id), |
670 | "Peer not running"); | 780 | "Peer not running"); |
671 | GNUNET_SERVER_receive_done (client, | 781 | GNUNET_SERVICE_client_continue (client); |
672 | GNUNET_OK); | ||
673 | return; | 782 | return; |
674 | } | 783 | } |
675 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 784 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
676 | "Peer %u successfully stopped\n", | 785 | "Peer %u successfully stopped\n", |
677 | (unsigned int) peer_id); | 786 | (unsigned int) peer_id); |
678 | reply = GNUNET_new (struct GNUNET_TESTBED_PeerEventMessage); | 787 | env = GNUNET_MQ_msg (reply, |
679 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); | 788 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); |
680 | reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage)); | ||
681 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); | 789 | reply->event_type = htonl (GNUNET_TESTBED_ET_PEER_STOP); |
682 | reply->host_id = htonl (GST_context->host_id); | 790 | reply->host_id = htonl (GST_context->host_id); |
683 | reply->peer_id = msg->peer_id; | 791 | reply->peer_id = msg->peer_id; |
684 | reply->operation_id = msg->operation_id; | 792 | reply->operation_id = msg->operation_id; |
685 | GST_queue_message (client, &reply->header); | 793 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), |
686 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 794 | env); |
795 | GNUNET_SERVICE_client_continue (client); | ||
687 | GNUNET_TESTING_peer_wait (peer->details.local.peer); | 796 | GNUNET_TESTING_peer_wait (peer->details.local.peer); |
688 | } | 797 | } |
689 | 798 | ||
690 | 799 | ||
691 | /** | 800 | /** |
692 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG messages | 801 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_INFORMATION messages |
693 | * | 802 | * |
694 | * @param cls NULL | 803 | * @param cls identification of the client |
695 | * @param client identification of the client | 804 | * @param msg the actual message |
696 | * @param message the actual message | ||
697 | */ | 805 | */ |
698 | void | 806 | void |
699 | GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | 807 | handle_peer_get_config (void *cls, |
700 | const struct GNUNET_MessageHeader *message) | 808 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg) |
701 | { | 809 | { |
702 | const struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 810 | struct GNUNET_SERVICE_Client *client = cls; |
811 | struct GNUNET_MQ_Envelope *env; | ||
703 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply; | 812 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage *reply; |
704 | struct ForwardedOperationContext *fopc; | 813 | struct ForwardedOperationContext *fopc; |
705 | struct Peer *peer; | 814 | struct Peer *peer; |
@@ -708,9 +817,7 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | |||
708 | size_t c_size; | 817 | size_t c_size; |
709 | size_t xc_size; | 818 | size_t xc_size; |
710 | uint32_t peer_id; | 819 | uint32_t peer_id; |
711 | uint16_t msize; | ||
712 | 820 | ||
713 | msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message; | ||
714 | peer_id = ntohl (msg->peer_id); | 821 | peer_id = ntohl (msg->peer_id); |
715 | LOG_DEBUG ("Received GET_CONFIG for peer %u\n", | 822 | LOG_DEBUG ("Received GET_CONFIG for peer %u\n", |
716 | (unsigned int) peer_id); | 823 | (unsigned int) peer_id); |
@@ -719,7 +826,7 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | |||
719 | GST_send_operation_fail_msg (client, | 826 | GST_send_operation_fail_msg (client, |
720 | GNUNET_ntohll (msg->operation_id), | 827 | GNUNET_ntohll (msg->operation_id), |
721 | "Peer not found"); | 828 | "Peer not found"); |
722 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 829 | GNUNET_SERVICE_client_continue (client); |
723 | return; | 830 | return; |
724 | } | 831 | } |
725 | peer = GST_peer_list[peer_id]; | 832 | peer = GST_peer_list[peer_id]; |
@@ -728,7 +835,6 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | |||
728 | LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", | 835 | LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", |
729 | (unsigned int) peer_id); | 836 | (unsigned int) peer_id); |
730 | fopc = GNUNET_new (struct ForwardedOperationContext); | 837 | fopc = GNUNET_new (struct ForwardedOperationContext); |
731 | GNUNET_SERVER_client_keep (client); | ||
732 | fopc->client = client; | 838 | fopc->client = client; |
733 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); | 839 | fopc->operation_id = GNUNET_ntohll (msg->operation_id); |
734 | fopc->type = OP_PEER_INFO; | 840 | fopc->type = OP_PEER_INFO; |
@@ -746,7 +852,7 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | |||
746 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 852 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
747 | fopcq_tail, | 853 | fopcq_tail, |
748 | fopc); | 854 | fopc); |
749 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 855 | GNUNET_SERVICE_client_continue (client); |
750 | return; | 856 | return; |
751 | } | 857 | } |
752 | LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", | 858 | LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", |
@@ -758,47 +864,21 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client, | |||
758 | c_size, | 864 | c_size, |
759 | &xconfig); | 865 | &xconfig); |
760 | GNUNET_free (config); | 866 | GNUNET_free (config); |
761 | msize = | 867 | env = GNUNET_MQ_msg_extra (reply, |
762 | xc_size + | 868 | xc_size, |
763 | sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | 869 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); |
764 | reply = GNUNET_realloc (xconfig, msize); | ||
765 | (void) memmove (&reply[1], reply, xc_size); | ||
766 | reply->header.size = htons (msize); | ||
767 | reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION); | ||
768 | reply->peer_id = msg->peer_id; | 870 | reply->peer_id = msg->peer_id; |
769 | reply->operation_id = msg->operation_id; | 871 | reply->operation_id = msg->operation_id; |
770 | GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer, | 872 | GNUNET_TESTING_peer_get_identity (GST_peer_list[peer_id]->details.local.peer, |
771 | &reply->peer_identity); | 873 | &reply->peer_identity); |
772 | reply->config_size = htons ((uint16_t) c_size); | 874 | reply->config_size = htons ((uint16_t) c_size); |
773 | GST_queue_message (client, &reply->header); | 875 | GNUNET_memcpy (&reply[1], |
774 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 876 | xconfig, |
775 | } | 877 | xc_size); |
776 | 878 | GNUNET_free (xconfig); | |
777 | 879 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | |
778 | /** | 880 | env); |
779 | * Cleans up the given PeerReconfigureContext | 881 | GNUNET_SERVICE_client_continue (client); |
780 | * | ||
781 | * @param prc the PeerReconfigureContext | ||
782 | */ | ||
783 | static void | ||
784 | cleanup_prc (struct PeerReconfigureContext *prc) | ||
785 | { | ||
786 | struct Peer *peer; | ||
787 | |||
788 | if (VALID_PEER_ID (prc->peer_id)) | ||
789 | { | ||
790 | peer = GST_peer_list [prc->peer_id]; | ||
791 | if (1 != prc->stopped) | ||
792 | { | ||
793 | GNUNET_TESTING_peer_stop_async_cancel (peer->details.local.peer); | ||
794 | stop_peer (peer); /* Stop the peer synchronously */ | ||
795 | } | ||
796 | } | ||
797 | if (NULL != prc->cfg) | ||
798 | GNUNET_CONFIGURATION_destroy (prc->cfg); | ||
799 | GNUNET_SERVER_client_drop (prc->client); | ||
800 | GNUNET_CONTAINER_DLL_remove (prc_head, prc_tail, prc); | ||
801 | GNUNET_free (prc); | ||
802 | } | 882 | } |
803 | 883 | ||
804 | 884 | ||
@@ -887,20 +967,33 @@ prc_stop_cb (void *cls, | |||
887 | 967 | ||
888 | 968 | ||
889 | /** | 969 | /** |
970 | * Check #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages. | ||
971 | * | ||
972 | * @param cls identification of the client | ||
973 | * @param msg the actual message | ||
974 | * @return #GNUNET_OK if @a msg is well-formed | ||
975 | */ | ||
976 | int | ||
977 | check_peer_reconfigure (void *cls, | ||
978 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) | ||
979 | { | ||
980 | return GNUNET_OK; /* checked later */ | ||
981 | } | ||
982 | |||
983 | |||
984 | /** | ||
890 | * Handler for #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages. | 985 | * Handler for #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages. |
891 | * Should stop the peer asyncronously, destroy it and create it again with the | 986 | * Should stop the peer asyncronously, destroy it and create it again with the |
892 | * new configuration. | 987 | * new configuration. |
893 | * | 988 | * |
894 | * @param cls NULL | 989 | * @param cls identification of the client |
895 | * @param client identification of the client | 990 | * @param msg the actual message |
896 | * @param message the actual message | ||
897 | */ | 991 | */ |
898 | void | 992 | void |
899 | GST_handle_peer_reconfigure (void *cls, | 993 | handle_peer_reconfigure (void *cls, |
900 | struct GNUNET_SERVER_Client *client, | 994 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg) |
901 | const struct GNUNET_MessageHeader *message) | ||
902 | { | 995 | { |
903 | const struct GNUNET_TESTBED_PeerReconfigureMessage *msg; | 996 | struct GNUNET_SERVICE_Client *client = cls; |
904 | struct Peer *peer; | 997 | struct Peer *peer; |
905 | struct GNUNET_CONFIGURATION_Handle *cfg; | 998 | struct GNUNET_CONFIGURATION_Handle *cfg; |
906 | struct ForwardedOperationContext *fopc; | 999 | struct ForwardedOperationContext *fopc; |
@@ -908,27 +1001,16 @@ GST_handle_peer_reconfigure (void *cls, | |||
908 | char *emsg; | 1001 | char *emsg; |
909 | uint64_t op_id; | 1002 | uint64_t op_id; |
910 | uint32_t peer_id; | 1003 | uint32_t peer_id; |
911 | uint16_t msize; | ||
912 | 1004 | ||
913 | msize = ntohs (message->size); | ||
914 | if (msize <= sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage)) | ||
915 | { | ||
916 | GNUNET_break_op (0); | ||
917 | GNUNET_SERVER_receive_done (client, | ||
918 | GNUNET_SYSERR); | ||
919 | return; | ||
920 | } | ||
921 | msg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) message; | ||
922 | peer_id = ntohl (msg->peer_id); | 1005 | peer_id = ntohl (msg->peer_id); |
923 | op_id = GNUNET_ntohll (msg->operation_id); | 1006 | op_id = GNUNET_ntohll (msg->operation_id); |
924 | if (!VALID_PEER_ID (peer_id)) | 1007 | if (! VALID_PEER_ID (peer_id)) |
925 | { | 1008 | { |
926 | GNUNET_break (0); | 1009 | GNUNET_break (0); |
927 | GST_send_operation_fail_msg (client, | 1010 | GST_send_operation_fail_msg (client, |
928 | op_id, | 1011 | op_id, |
929 | "Peer not found"); | 1012 | "Peer not found"); |
930 | GNUNET_SERVER_receive_done (client, | 1013 | GNUNET_SERVICE_client_continue (client); |
931 | GNUNET_OK); | ||
932 | return; | 1014 | return; |
933 | } | 1015 | } |
934 | peer = GST_peer_list[peer_id]; | 1016 | peer = GST_peer_list[peer_id]; |
@@ -936,7 +1018,6 @@ GST_handle_peer_reconfigure (void *cls, | |||
936 | { | 1018 | { |
937 | LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); | 1019 | LOG_DEBUG ("Forwarding PEER_RECONFIGURE for peer: %u\n", peer_id); |
938 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1020 | fopc = GNUNET_new (struct ForwardedOperationContext); |
939 | GNUNET_SERVER_client_keep (client); | ||
940 | fopc->client = client; | 1021 | fopc->client = client; |
941 | fopc->operation_id = op_id; | 1022 | fopc->operation_id = op_id; |
942 | fopc->type = OP_PEER_RECONFIGURE; | 1023 | fopc->type = OP_PEER_RECONFIGURE; |
@@ -954,7 +1035,7 @@ GST_handle_peer_reconfigure (void *cls, | |||
954 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1035 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
955 | fopcq_tail, | 1036 | fopcq_tail, |
956 | fopc); | 1037 | fopc); |
957 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1038 | GNUNET_SERVICE_client_continue (client); |
958 | return; | 1039 | return; |
959 | } | 1040 | } |
960 | LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", | 1041 | LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", |
@@ -965,8 +1046,7 @@ GST_handle_peer_reconfigure (void *cls, | |||
965 | GST_send_operation_fail_msg (client, | 1046 | GST_send_operation_fail_msg (client, |
966 | op_id, | 1047 | op_id, |
967 | "Peer in use"); | 1048 | "Peer in use"); |
968 | GNUNET_SERVER_receive_done (client, | 1049 | GNUNET_SERVICE_client_continue (client); |
969 | GNUNET_OK); | ||
970 | return; | 1050 | return; |
971 | } | 1051 | } |
972 | if (GNUNET_YES == peer->destroy_flag) | 1052 | if (GNUNET_YES == peer->destroy_flag) |
@@ -975,19 +1055,17 @@ GST_handle_peer_reconfigure (void *cls, | |||
975 | GST_send_operation_fail_msg (client, | 1055 | GST_send_operation_fail_msg (client, |
976 | op_id, | 1056 | op_id, |
977 | "Peer is being destroyed"); | 1057 | "Peer is being destroyed"); |
978 | GNUNET_SERVER_receive_done (client, | 1058 | GNUNET_SERVICE_client_continue (client); |
979 | GNUNET_OK); | ||
980 | return; | 1059 | return; |
981 | } | 1060 | } |
982 | cfg = GNUNET_TESTBED_extract_config_ (message); | 1061 | cfg = GNUNET_TESTBED_extract_config_ (&msg->header); |
983 | if (NULL == cfg) | 1062 | if (NULL == cfg) |
984 | { | 1063 | { |
985 | GNUNET_break (0); | 1064 | GNUNET_break (0); |
986 | GST_send_operation_fail_msg (client, | 1065 | GST_send_operation_fail_msg (client, |
987 | op_id, | 1066 | op_id, |
988 | "Compression error"); | 1067 | "Compression error"); |
989 | GNUNET_SERVER_receive_done (client, | 1068 | GNUNET_SERVICE_client_continue (client); |
990 | GNUNET_OK); | ||
991 | return; | 1069 | return; |
992 | } | 1070 | } |
993 | if (GNUNET_NO == peer->details.local.is_running) | 1071 | if (GNUNET_NO == peer->details.local.is_running) |
@@ -1000,8 +1078,7 @@ GST_handle_peer_reconfigure (void *cls, | |||
1000 | emsg); | 1078 | emsg); |
1001 | GST_send_operation_success_msg (client, | 1079 | GST_send_operation_success_msg (client, |
1002 | op_id); | 1080 | op_id); |
1003 | GNUNET_SERVER_receive_done (client, | 1081 | GNUNET_SERVICE_client_continue (client); |
1004 | GNUNET_OK); | ||
1005 | GNUNET_free_non_null (emsg); | 1082 | GNUNET_free_non_null (emsg); |
1006 | return; | 1083 | return; |
1007 | } | 1084 | } |
@@ -1020,8 +1097,7 @@ GST_handle_peer_reconfigure (void *cls, | |||
1020 | GST_send_operation_fail_msg (client, | 1097 | GST_send_operation_fail_msg (client, |
1021 | op_id, | 1098 | op_id, |
1022 | emsg); | 1099 | emsg); |
1023 | GNUNET_SERVER_receive_done (client, | 1100 | GNUNET_SERVICE_client_continue (client); |
1024 | GNUNET_OK); | ||
1025 | GNUNET_free (prc); | 1101 | GNUNET_free (prc); |
1026 | GNUNET_free (emsg); | 1102 | GNUNET_free (emsg); |
1027 | return; | 1103 | return; |
@@ -1030,36 +1106,10 @@ GST_handle_peer_reconfigure (void *cls, | |||
1030 | prc->peer_id = peer_id; | 1106 | prc->peer_id = peer_id; |
1031 | prc->op_id = op_id; | 1107 | prc->op_id = op_id; |
1032 | prc->client = client; | 1108 | prc->client = client; |
1033 | GNUNET_SERVER_client_keep (client); | ||
1034 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, | 1109 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, |
1035 | prc_tail, | 1110 | prc_tail, |
1036 | prc); | 1111 | prc); |
1037 | GNUNET_SERVER_receive_done (client, | 1112 | GNUNET_SERVICE_client_continue (client); |
1038 | GNUNET_OK); | ||
1039 | } | ||
1040 | |||
1041 | |||
1042 | /** | ||
1043 | * Cleanup the context information created for managing a peer's service | ||
1044 | * | ||
1045 | * @param mctx the ManageServiceContext | ||
1046 | */ | ||
1047 | static void | ||
1048 | cleanup_mctx (struct ManageServiceContext *mctx) | ||
1049 | { | ||
1050 | mctx->expired = GNUNET_YES; | ||
1051 | GNUNET_CONTAINER_DLL_remove (mctx_head, | ||
1052 | mctx_tail, | ||
1053 | mctx); | ||
1054 | GNUNET_SERVER_client_drop (mctx->client); | ||
1055 | GNUNET_ARM_disconnect (mctx->ah); | ||
1056 | GNUNET_assert (0 < mctx->peer->reference_cnt); | ||
1057 | mctx->peer->reference_cnt--; | ||
1058 | if ( (GNUNET_YES == mctx->peer->destroy_flag) | ||
1059 | && (0 == mctx->peer->reference_cnt) ) | ||
1060 | GST_destroy_peer (mctx->peer); | ||
1061 | GNUNET_free (mctx->service); | ||
1062 | GNUNET_free (mctx); | ||
1063 | } | 1113 | } |
1064 | 1114 | ||
1065 | 1115 | ||
@@ -1211,51 +1261,57 @@ service_manage_result_cb (void *cls, | |||
1211 | 1261 | ||
1212 | 1262 | ||
1213 | /** | 1263 | /** |
1214 | * Handler for GNUNET_TESTBED_ManagePeerServiceMessage message | 1264 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE message |
1215 | * | 1265 | * |
1216 | * @param cls NULL | 1266 | * @param cls identification of client |
1217 | * @param client identification of client | 1267 | * @param msg the actual message |
1218 | * @param message the actual message | 1268 | * @return #GNUNET_OK if @a msg is well-formed |
1219 | */ | 1269 | */ |
1220 | void | 1270 | int |
1221 | GST_handle_manage_peer_service (void *cls, | 1271 | check_manage_peer_service (void *cls, |
1222 | struct GNUNET_SERVER_Client *client, | 1272 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) |
1223 | const struct GNUNET_MessageHeader *message) | ||
1224 | { | 1273 | { |
1225 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; | ||
1226 | const char* service; | ||
1227 | struct Peer *peer; | ||
1228 | char *emsg; | ||
1229 | struct GNUNET_ARM_Handle *ah; | ||
1230 | struct ManageServiceContext *mctx; | ||
1231 | struct ForwardedOperationContext *fopc; | ||
1232 | uint64_t op_id; | ||
1233 | uint32_t peer_id; | ||
1234 | uint16_t msize; | 1274 | uint16_t msize; |
1275 | const char* service; | ||
1235 | 1276 | ||
1236 | 1277 | msize = ntohs (msg->header.size); | |
1237 | msize = ntohs (message->size); | ||
1238 | if (msize <= sizeof (struct GNUNET_TESTBED_ManagePeerServiceMessage)) | ||
1239 | { | ||
1240 | GNUNET_break_op (0); | ||
1241 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1242 | return; | ||
1243 | } | ||
1244 | msg = (const struct GNUNET_TESTBED_ManagePeerServiceMessage *) message; | ||
1245 | service = (const char *) &msg[1]; | 1278 | service = (const char *) &msg[1]; |
1246 | if ('\0' != service[msize - sizeof | 1279 | if ('\0' != service[msize - sizeof |
1247 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) | 1280 | (struct GNUNET_TESTBED_ManagePeerServiceMessage) - 1]) |
1248 | { | 1281 | { |
1249 | GNUNET_break_op (0); | 1282 | GNUNET_break_op (0); |
1250 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1283 | return GNUNET_SYSERR; |
1251 | return; | ||
1252 | } | 1284 | } |
1253 | if (1 < msg->start) | 1285 | if (1 < msg->start) |
1254 | { | 1286 | { |
1255 | GNUNET_break_op (0); | 1287 | GNUNET_break_op (0); |
1256 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1288 | return GNUNET_SYSERR; |
1257 | return; | ||
1258 | } | 1289 | } |
1290 | return GNUNET_OK; | ||
1291 | } | ||
1292 | |||
1293 | |||
1294 | /** | ||
1295 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_MANAGE_PEER_SERVICE messages | ||
1296 | * | ||
1297 | * @param cls identification of client | ||
1298 | * @param msg the actual message | ||
1299 | */ | ||
1300 | void | ||
1301 | handle_manage_peer_service (void *cls, | ||
1302 | const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg) | ||
1303 | { | ||
1304 | struct GNUNET_SERVICE_Client *client = cls; | ||
1305 | const char* service; | ||
1306 | struct Peer *peer; | ||
1307 | char *emsg; | ||
1308 | struct GNUNET_ARM_Handle *ah; | ||
1309 | struct ManageServiceContext *mctx; | ||
1310 | struct ForwardedOperationContext *fopc; | ||
1311 | uint64_t op_id; | ||
1312 | uint32_t peer_id; | ||
1313 | |||
1314 | service = (const char *) &msg[1]; | ||
1259 | peer_id = ntohl (msg->peer_id); | 1315 | peer_id = ntohl (msg->peer_id); |
1260 | op_id = GNUNET_ntohll (msg->operation_id); | 1316 | op_id = GNUNET_ntohll (msg->operation_id); |
1261 | LOG_DEBUG ("Received request to manage service %s on peer %u\n", | 1317 | LOG_DEBUG ("Received request to manage service %s on peer %u\n", |
@@ -1277,7 +1333,6 @@ GST_handle_manage_peer_service (void *cls, | |||
1277 | { | 1333 | { |
1278 | /* Forward the destory message to sub controller */ | 1334 | /* Forward the destory message to sub controller */ |
1279 | fopc = GNUNET_new (struct ForwardedOperationContext); | 1335 | fopc = GNUNET_new (struct ForwardedOperationContext); |
1280 | GNUNET_SERVER_client_keep (client); | ||
1281 | fopc->client = client; | 1336 | fopc->client = client; |
1282 | fopc->cls = peer; | 1337 | fopc->cls = peer; |
1283 | fopc->type = OP_MANAGE_SERVICE; | 1338 | fopc->type = OP_MANAGE_SERVICE; |
@@ -1296,7 +1351,7 @@ GST_handle_manage_peer_service (void *cls, | |||
1296 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, | 1351 | GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, |
1297 | fopcq_tail, | 1352 | fopcq_tail, |
1298 | fopc); | 1353 | fopc); |
1299 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1354 | GNUNET_SERVICE_client_continue (client); |
1300 | return; | 1355 | return; |
1301 | } | 1356 | } |
1302 | if (GNUNET_NO == peer->details.local.is_running) | 1357 | if (GNUNET_NO == peer->details.local.is_running) |
@@ -1326,7 +1381,6 @@ GST_handle_manage_peer_service (void *cls, | |||
1326 | peer->reference_cnt++; | 1381 | peer->reference_cnt++; |
1327 | mctx->op_id = op_id; | 1382 | mctx->op_id = op_id; |
1328 | mctx->ah = ah; | 1383 | mctx->ah = ah; |
1329 | GNUNET_SERVER_client_keep (client); | ||
1330 | mctx->client = client; | 1384 | mctx->client = client; |
1331 | mctx->start = msg->start; | 1385 | mctx->start = msg->start; |
1332 | mctx->service = GNUNET_strdup (service); | 1386 | mctx->service = GNUNET_strdup (service); |
@@ -1343,14 +1397,14 @@ GST_handle_manage_peer_service (void *cls, | |||
1343 | GNUNET_ARM_request_service_stop (mctx->ah, service, | 1397 | GNUNET_ARM_request_service_stop (mctx->ah, service, |
1344 | &service_manage_result_cb, | 1398 | &service_manage_result_cb, |
1345 | mctx); | 1399 | mctx); |
1346 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1400 | GNUNET_SERVICE_client_continue (client); |
1347 | return; | 1401 | return; |
1348 | 1402 | ||
1349 | err_ret: | 1403 | err_ret: |
1350 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | 1404 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); |
1351 | GST_send_operation_fail_msg (client, op_id, emsg); | 1405 | GST_send_operation_fail_msg (client, op_id, emsg); |
1352 | GNUNET_free (emsg); | 1406 | GNUNET_free (emsg); |
1353 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1407 | GNUNET_SERVICE_client_continue (client); |
1354 | } | 1408 | } |
1355 | 1409 | ||
1356 | 1410 | ||
@@ -1432,7 +1486,6 @@ shutdown_peers_reply_cb (void *cls, | |||
1432 | GNUNET_free (hc); | 1486 | GNUNET_free (hc); |
1433 | hc = NULL; | 1487 | hc = NULL; |
1434 | } | 1488 | } |
1435 | GNUNET_SERVER_client_drop (fo_ctxt->client); | ||
1436 | GNUNET_CONTAINER_DLL_remove (fopcq_head, | 1489 | GNUNET_CONTAINER_DLL_remove (fopcq_head, |
1437 | fopcq_tail, | 1490 | fopcq_tail, |
1438 | fo_ctxt); | 1491 | fo_ctxt); |
@@ -1443,23 +1496,20 @@ shutdown_peers_reply_cb (void *cls, | |||
1443 | /** | 1496 | /** |
1444 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages | 1497 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages |
1445 | * | 1498 | * |
1446 | * @param cls NULL | 1499 | * @param cls identification of the client |
1447 | * @param client identification of the client | 1500 | * @param msg the actual message |
1448 | * @param message the actual message | ||
1449 | */ | 1501 | */ |
1450 | void | 1502 | void |
1451 | GST_handle_shutdown_peers (void *cls, | 1503 | handle_shutdown_peers (void *cls, |
1452 | struct GNUNET_SERVER_Client *client, | 1504 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg) |
1453 | const struct GNUNET_MessageHeader *message) | ||
1454 | { | 1505 | { |
1455 | const struct GNUNET_TESTBED_ShutdownPeersMessage *msg; | 1506 | struct GNUNET_SERVICE_Client *client = cls; |
1456 | struct HandlerContext_ShutdownPeers *hc; | 1507 | struct HandlerContext_ShutdownPeers *hc; |
1457 | struct Slave *slave; | 1508 | struct Slave *slave; |
1458 | struct ForwardedOperationContext *fo_ctxt; | 1509 | struct ForwardedOperationContext *fo_ctxt; |
1459 | uint64_t op_id; | 1510 | uint64_t op_id; |
1460 | unsigned int cnt; | 1511 | unsigned int cnt; |
1461 | 1512 | ||
1462 | msg = (const struct GNUNET_TESTBED_ShutdownPeersMessage *) message; | ||
1463 | LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); | 1513 | LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); |
1464 | /* Stop and destroy all peers */ | 1514 | /* Stop and destroy all peers */ |
1465 | GST_free_mctxq (); | 1515 | GST_free_mctxq (); |
@@ -1481,7 +1531,6 @@ GST_handle_shutdown_peers (void *cls, | |||
1481 | LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n"); | 1531 | LOG_DEBUG ("Forwarding SHUTDOWN_PEERS\n"); |
1482 | hc->nslaves++; | 1532 | hc->nslaves++; |
1483 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); | 1533 | fo_ctxt = GNUNET_new (struct ForwardedOperationContext); |
1484 | GNUNET_SERVER_client_keep (client); | ||
1485 | fo_ctxt->client = client; | 1534 | fo_ctxt->client = client; |
1486 | fo_ctxt->operation_id = op_id; | 1535 | fo_ctxt->operation_id = op_id; |
1487 | fo_ctxt->cls = hc; | 1536 | fo_ctxt->cls = hc; |
@@ -1504,6 +1553,5 @@ GST_handle_shutdown_peers (void *cls, | |||
1504 | op_id); | 1553 | op_id); |
1505 | GNUNET_free (hc); | 1554 | GNUNET_free (hc); |
1506 | } | 1555 | } |
1507 | GNUNET_SERVER_receive_done (client, | 1556 | GNUNET_SERVICE_client_continue (client); |
1508 | GNUNET_OK); | ||
1509 | } | 1557 | } |