diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-27 16:15:33 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-27 16:15:33 +0000 |
commit | f27f46409ec33cef42379006d561d33a2ae44682 (patch) | |
tree | 0d32d879b31feb0d9aa0d19e44b41a2146cb1973 /src/testbed | |
parent | 3a4870624812ac4286624d3946981cac6aef4e67 (diff) | |
download | gnunet-f27f46409ec33cef42379006d561d33a2ae44682.tar.gz gnunet-f27f46409ec33cef42379006d561d33a2ae44682.zip |
convert testbed_api to MQ (not perfect, but working)
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed_oc.c | 9 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_controllerlink.c | 46 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 507 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 78 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.c | 84 | ||||
-rw-r--r-- | src/testbed/testbed_api_hosts.h | 47 |
6 files changed, 345 insertions, 426 deletions
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index 55dd5cad9..44f408764 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c | |||
@@ -1716,12 +1716,6 @@ rocc_hello_sent_cb (void *cls) | |||
1716 | rocc); | 1716 | rocc); |
1717 | return; | 1717 | return; |
1718 | } | 1718 | } |
1719 | if (GNUNET_SCHEDULER_REASON_READ_READY != tc->reason) | ||
1720 | { | ||
1721 | GNUNET_break (0); | ||
1722 | return; | ||
1723 | } | ||
1724 | |||
1725 | rocc->tcc.cgh_p2_ats = | 1719 | rocc->tcc.cgh_p2_ats = |
1726 | GST_connection_pool_get_handle (rocc->peer->id, | 1720 | GST_connection_pool_get_handle (rocc->peer->id, |
1727 | rocc->peer->details.local.cfg, | 1721 | rocc->peer->details.local.cfg, |
@@ -1752,7 +1746,8 @@ attempt_connect_task (void *cls) | |||
1752 | rocc->ohh = | 1746 | rocc->ohh = |
1753 | GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_, | 1747 | GNUNET_TRANSPORT_offer_hello (rocc->tcc.th_, |
1754 | rocc->hello, | 1748 | rocc->hello, |
1755 | rocc_hello_sent_cb, rocc); | 1749 | &rocc_hello_sent_cb, |
1750 | rocc); | ||
1756 | if (NULL == rocc->ohh) | 1751 | if (NULL == rocc->ohh) |
1757 | rocc->attempt_connect_task_id = | 1752 | rocc->attempt_connect_task_id = |
1758 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 1753 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index fd876a07f..699a18215 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c | |||
@@ -244,7 +244,7 @@ static struct GNUNET_CONFIGURATION_Handle *cfg3; | |||
244 | /** | 244 | /** |
245 | * Abort task | 245 | * Abort task |
246 | */ | 246 | */ |
247 | static struct GNUNET_SCHEDULER_Task * abort_task; | 247 | static struct GNUNET_SCHEDULER_Task *abort_task; |
248 | 248 | ||
249 | /** | 249 | /** |
250 | * Operation handle for linking controllers | 250 | * Operation handle for linking controllers |
@@ -274,17 +274,17 @@ static struct GNUNET_TESTBED_Peer *master_peer; | |||
274 | /** | 274 | /** |
275 | * The handle for whether a host is habitable or not | 275 | * The handle for whether a host is habitable or not |
276 | */ | 276 | */ |
277 | struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle; | 277 | static struct GNUNET_TESTBED_HostHabitableCheckHandle *hc_handle; |
278 | 278 | ||
279 | /** | 279 | /** |
280 | * The task handle for the delay task | 280 | * The task handle for the delay task |
281 | */ | 281 | */ |
282 | struct GNUNET_SCHEDULER_Task * delay_task_id; | 282 | static struct GNUNET_SCHEDULER_Task *delay_task_id; |
283 | 283 | ||
284 | /** | 284 | /** |
285 | * Event mask | 285 | * Event mask |
286 | */ | 286 | */ |
287 | uint64_t event_mask; | 287 | static uint64_t event_mask; |
288 | 288 | ||
289 | /** | 289 | /** |
290 | * Global testing status | 290 | * Global testing status |
@@ -300,7 +300,7 @@ static enum Stage result; | |||
300 | if (NULL != abort_task) \ | 300 | if (NULL != abort_task) \ |
301 | GNUNET_SCHEDULER_cancel (abort_task); \ | 301 | GNUNET_SCHEDULER_cancel (abort_task); \ |
302 | abort_task = NULL; \ | 302 | abort_task = NULL; \ |
303 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); \ | 303 | GNUNET_SCHEDULER_shutdown (); \ |
304 | return; \ | 304 | return; \ |
305 | } \ | 305 | } \ |
306 | } while (0) | 306 | } while (0) |
@@ -323,6 +323,11 @@ do_shutdown (void *cls) | |||
323 | } | 323 | } |
324 | if (NULL != hc_handle) | 324 | if (NULL != hc_handle) |
325 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); | 325 | GNUNET_TESTBED_is_host_habitable_cancel (hc_handle); |
326 | if (NULL != op) | ||
327 | { | ||
328 | GNUNET_TESTBED_operation_done (op); | ||
329 | op = NULL; | ||
330 | } | ||
326 | if (NULL != mc) | 331 | if (NULL != mc) |
327 | GNUNET_TESTBED_controller_disconnect (mc); | 332 | GNUNET_TESTBED_controller_disconnect (mc); |
328 | if (NULL != cp) | 333 | if (NULL != cp) |
@@ -352,9 +357,11 @@ do_shutdown (void *cls) | |||
352 | static void | 357 | static void |
353 | do_abort (void *cls) | 358 | do_abort (void *cls) |
354 | { | 359 | { |
355 | LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n"); | 360 | LOG (GNUNET_ERROR_TYPE_WARNING, |
361 | "Aborting in stage %d\n", | ||
362 | result); | ||
356 | abort_task = NULL; | 363 | abort_task = NULL; |
357 | do_shutdown (cls); | 364 | GNUNET_SCHEDULER_shutdown (); |
358 | } | 365 | } |
359 | 366 | ||
360 | 367 | ||
@@ -423,7 +430,9 @@ delay_task (void *cls) | |||
423 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | 430 | * @param emsg NULL if peer is not NULL; else MAY contain the error description |
424 | */ | 431 | */ |
425 | static void | 432 | static void |
426 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | 433 | peer_create_cb (void *cls, |
434 | struct GNUNET_TESTBED_Peer *peer, | ||
435 | const char *emsg) | ||
427 | { | 436 | { |
428 | FAIL_TEST (NULL != peer); | 437 | FAIL_TEST (NULL != peer); |
429 | FAIL_TEST (NULL == emsg); | 438 | FAIL_TEST (NULL == emsg); |
@@ -445,12 +454,13 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | |||
445 | result = SLAVE2_PEER_CREATE_SUCCESS; | 454 | result = SLAVE2_PEER_CREATE_SUCCESS; |
446 | slave2_peer = peer; | 455 | slave2_peer = peer; |
447 | GNUNET_TESTBED_operation_done (op); | 456 | GNUNET_TESTBED_operation_done (op); |
457 | op = NULL; | ||
448 | delay_task_id = | 458 | delay_task_id = |
449 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 459 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
450 | (GNUNET_TIME_UNIT_SECONDS, 1), | 460 | (GNUNET_TIME_UNIT_SECONDS, 1), |
451 | &delay_task, | 461 | &delay_task, |
452 | NULL); | 462 | NULL); |
453 | break; | 463 | return; |
454 | case SLAVE3_STARTED: | 464 | case SLAVE3_STARTED: |
455 | result = SLAVE3_PEER_CREATE_SUCCESS; | 465 | result = SLAVE3_PEER_CREATE_SUCCESS; |
456 | slave3_peer = peer; | 466 | slave3_peer = peer; |
@@ -490,7 +500,8 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) | |||
490 | * @param event information about the event | 500 | * @param event information about the event |
491 | */ | 501 | */ |
492 | static void | 502 | static void |
493 | controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | 503 | controller_cb (void *cls, |
504 | const struct GNUNET_TESTBED_EventInformation *event) | ||
494 | { | 505 | { |
495 | switch (result) | 506 | switch (result) |
496 | { | 507 | { |
@@ -516,6 +527,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
516 | FAIL_TEST (event->details.peer_start.host == host); | 527 | FAIL_TEST (event->details.peer_start.host == host); |
517 | FAIL_TEST (event->details.peer_start.peer == master_peer); | 528 | FAIL_TEST (event->details.peer_start.peer == master_peer); |
518 | GNUNET_TESTBED_operation_done (op); | 529 | GNUNET_TESTBED_operation_done (op); |
530 | op = NULL; | ||
519 | result = MASTER_PEER_START_SUCCESS; | 531 | result = MASTER_PEER_START_SUCCESS; |
520 | slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); | 532 | slave = GNUNET_TESTBED_host_create_with_id (1, "127.0.0.1", NULL, cfg, 0); |
521 | FAIL_TEST (NULL != slave); | 533 | FAIL_TEST (NULL != slave); |
@@ -622,7 +634,6 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
622 | case SLAVE3_REGISTERED: | 634 | case SLAVE3_REGISTERED: |
623 | check_operation_success (event); | 635 | check_operation_success (event); |
624 | GNUNET_TESTBED_operation_done (op); | 636 | GNUNET_TESTBED_operation_done (op); |
625 | op = NULL; | ||
626 | result = SLAVE3_STARTED; | 637 | result = SLAVE3_STARTED; |
627 | op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); | 638 | op = GNUNET_TESTBED_peer_create (mc, slave3, cfg, peer_create_cb, NULL); |
628 | FAIL_TEST (NULL != op); | 639 | FAIL_TEST (NULL != op); |
@@ -642,9 +653,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
642 | result = SUCCESS; | 653 | result = SUCCESS; |
643 | GNUNET_TESTBED_operation_done (op); | 654 | GNUNET_TESTBED_operation_done (op); |
644 | op = NULL; | 655 | op = NULL; |
645 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 656 | GNUNET_SCHEDULER_shutdown (); |
646 | &do_shutdown, | ||
647 | NULL); | ||
648 | break; | 657 | break; |
649 | default: | 658 | default: |
650 | FAIL_TEST (0); | 659 | FAIL_TEST (0); |
@@ -740,10 +749,11 @@ status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, | |||
740 | * @param cls NULL | 749 | * @param cls NULL |
741 | * @param host the host whose status is being reported; will be NULL if the host | 750 | * @param host the host whose status is being reported; will be NULL if the host |
742 | * given to GNUNET_TESTBED_is_host_habitable() is NULL | 751 | * given to GNUNET_TESTBED_is_host_habitable() is NULL |
743 | * @param status GNUNET_YES if it is habitable; GNUNET_NO if not | 752 | * @param status #GNUNET_YES if it is habitable; #GNUNET_NO if not |
744 | */ | 753 | */ |
745 | static void | 754 | static void |
746 | host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host, | 755 | host_habitable_cb (void *cls, |
756 | const struct GNUNET_TESTBED_Host *_host, | ||
747 | int status) | 757 | int status) |
748 | { | 758 | { |
749 | hc_handle = NULL; | 759 | hc_handle = NULL; |
@@ -755,7 +765,7 @@ host_habitable_cb (void *cls, const struct GNUNET_TESTBED_Host *_host, | |||
755 | "Skipping test\n"); | 765 | "Skipping test\n"); |
756 | GNUNET_SCHEDULER_cancel (abort_task); | 766 | GNUNET_SCHEDULER_cancel (abort_task); |
757 | abort_task = NULL; | 767 | abort_task = NULL; |
758 | (void) GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 768 | GNUNET_SCHEDULER_shutdown (); |
759 | result = SKIP; | 769 | result = SKIP; |
760 | return; | 770 | return; |
761 | } | 771 | } |
@@ -799,6 +809,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
799 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 809 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
800 | (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, | 810 | (GNUNET_TIME_UNIT_MINUTES, 5), &do_abort, |
801 | NULL); | 811 | NULL); |
812 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
813 | NULL); | ||
802 | } | 814 | } |
803 | 815 | ||
804 | 816 | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 9b8066412..aad5055ef 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -67,28 +67,6 @@ | |||
67 | 67 | ||
68 | 68 | ||
69 | /** | 69 | /** |
70 | * The message queue for sending messages to the controller service | ||
71 | */ | ||
72 | struct MessageQueue | ||
73 | { | ||
74 | /** | ||
75 | * The message to be sent | ||
76 | */ | ||
77 | struct GNUNET_MessageHeader *msg; | ||
78 | |||
79 | /** | ||
80 | * next pointer for DLL | ||
81 | */ | ||
82 | struct MessageQueue *next; | ||
83 | |||
84 | /** | ||
85 | * prev pointer for DLL | ||
86 | */ | ||
87 | struct MessageQueue *prev; | ||
88 | }; | ||
89 | |||
90 | |||
91 | /** | ||
92 | * Context data for forwarded Operation | 70 | * Context data for forwarded Operation |
93 | */ | 71 | */ |
94 | struct ForwardedOperationData | 72 | struct ForwardedOperationData |
@@ -272,12 +250,13 @@ struct SearchContext | |||
272 | * @param cls the serach context | 250 | * @param cls the serach context |
273 | * @param key current key code | 251 | * @param key current key code |
274 | * @param value value in the hash map | 252 | * @param value value in the hash map |
275 | * @return GNUNET_YES if we should continue to | 253 | * @return #GNUNET_YES if we should continue to iterate, |
276 | * iterate, | 254 | * #GNUNET_NO if not. |
277 | * GNUNET_NO if not. | ||
278 | */ | 255 | */ |
279 | static int | 256 | static int |
280 | opc_search_iterator (void *cls, uint32_t key, void *value) | 257 | opc_search_iterator (void *cls, |
258 | uint32_t key, | ||
259 | void *value) | ||
281 | { | 260 | { |
282 | struct SearchContext *sc = cls; | 261 | struct SearchContext *sc = cls; |
283 | struct OperationContext *opc = value; | 262 | struct OperationContext *opc = value; |
@@ -358,6 +337,85 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | |||
358 | } | 337 | } |
359 | 338 | ||
360 | 339 | ||
340 | |||
341 | /** | ||
342 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message is well-formed. | ||
343 | * | ||
344 | * @param cls the controller handler | ||
345 | * @param msg message received | ||
346 | * @return #GNUNET_OK if message is well-formed | ||
347 | */ | ||
348 | static int | ||
349 | check_add_host_confirm (void *cls, | ||
350 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) | ||
351 | { | ||
352 | const char *emsg; | ||
353 | uint16_t msg_size; | ||
354 | |||
355 | msg_size = ntohs (msg->header.size) - sizeof (*msg); | ||
356 | if (0 == msg_size) | ||
357 | return GNUNET_OK; | ||
358 | /* We have an error message */ | ||
359 | emsg = (const char *) &msg[1]; | ||
360 | if ('\0' != emsg[msg_size - 1]) | ||
361 | { | ||
362 | GNUNET_break (0); | ||
363 | return GNUNET_SYSERR; | ||
364 | } | ||
365 | return GNUNET_OK; | ||
366 | } | ||
367 | |||
368 | |||
369 | /** | ||
370 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
371 | * controller (testbed service) | ||
372 | * | ||
373 | * @param cls the controller handler | ||
374 | * @param msg message received | ||
375 | */ | ||
376 | static void | ||
377 | handle_add_host_confirm (void *cls, | ||
378 | const struct GNUNET_TESTBED_HostConfirmedMessage *msg) | ||
379 | { | ||
380 | struct GNUNET_TESTBED_Controller *c = cls; | ||
381 | struct GNUNET_TESTBED_HostRegistrationHandle *rh = c->rh; | ||
382 | const char *emsg; | ||
383 | uint16_t msg_size; | ||
384 | |||
385 | if (NULL == rh) | ||
386 | return; | ||
387 | if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) | ||
388 | { | ||
389 | LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", | ||
390 | GNUNET_TESTBED_host_get_id_ (rh->host), | ||
391 | ntohl (msg->host_id)); | ||
392 | return; | ||
393 | } | ||
394 | c->rh = NULL; | ||
395 | msg_size = ntohs (msg->header.size) - sizeof (*msg); | ||
396 | if (0 == msg_size) | ||
397 | { | ||
398 | LOG_DEBUG ("Host %u successfully registered\n", | ||
399 | ntohl (msg->host_id)); | ||
400 | GNUNET_TESTBED_mark_host_registered_at_ (rh->host, | ||
401 | c); | ||
402 | rh->cc (rh->cc_cls, | ||
403 | NULL); | ||
404 | GNUNET_free (rh); | ||
405 | return; | ||
406 | } | ||
407 | /* We have an error message */ | ||
408 | emsg = (const char *) &msg[1]; | ||
409 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
410 | _("Adding host %u failed with error: %s\n"), | ||
411 | ntohl (msg->host_id), | ||
412 | emsg); | ||
413 | rh->cc (rh->cc_cls, | ||
414 | emsg); | ||
415 | GNUNET_free (rh); | ||
416 | } | ||
417 | |||
418 | |||
361 | /** | 419 | /** |
362 | * Handler for forwarded operations | 420 | * Handler for forwarded operations |
363 | * | 421 | * |
@@ -690,6 +748,22 @@ handle_peer_conevent (void *cls, | |||
690 | 748 | ||
691 | 749 | ||
692 | /** | 750 | /** |
751 | * Validate #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from | ||
752 | * controller (testbed service) | ||
753 | * | ||
754 | * @param c the controller handler | ||
755 | * @param msg message received | ||
756 | */ | ||
757 | static int | ||
758 | check_peer_config (void *cls, | ||
759 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | ||
760 | { | ||
761 | /* anything goes? */ | ||
762 | return GNUNET_OK; | ||
763 | } | ||
764 | |||
765 | |||
766 | /** | ||
693 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from | 767 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION message from |
694 | * controller (testbed service) | 768 | * controller (testbed service) |
695 | * | 769 | * |
@@ -698,8 +772,7 @@ handle_peer_conevent (void *cls, | |||
698 | */ | 772 | */ |
699 | static void | 773 | static void |
700 | handle_peer_config (void *cls, | 774 | handle_peer_config (void *cls, |
701 | const struct | 775 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) |
702 | GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | ||
703 | { | 776 | { |
704 | struct GNUNET_TESTBED_Controller *c = cls; | 777 | struct GNUNET_TESTBED_Controller *c = cls; |
705 | struct OperationContext *opc; | 778 | struct OperationContext *opc; |
@@ -718,8 +791,9 @@ handle_peer_config (void *cls, | |||
718 | } | 791 | } |
719 | if (OP_FORWARDED == opc->type) | 792 | if (OP_FORWARDED == opc->type) |
720 | { | 793 | { |
721 | handle_forwarded_operation_msg (c, opc, | 794 | handle_forwarded_operation_msg (c, |
722 | (const struct GNUNET_MessageHeader *) msg); | 795 | opc, |
796 | &msg->header); | ||
723 | return; | 797 | return; |
724 | } | 798 | } |
725 | data = opc->data; | 799 | data = opc->data; |
@@ -761,6 +835,23 @@ handle_peer_config (void *cls, | |||
761 | 835 | ||
762 | 836 | ||
763 | /** | 837 | /** |
838 | * Validate #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from | ||
839 | * controller (testbed service) | ||
840 | * | ||
841 | * @param c the controller handler | ||
842 | * @param msg message received | ||
843 | * @return #GNUNET_OK if message is well-formed | ||
844 | */ | ||
845 | static int | ||
846 | check_op_fail_event (void *cls, | ||
847 | const struct GNUNET_TESTBED_OperationFailureEventMessage *msg) | ||
848 | { | ||
849 | /* we accept anything as a valid error message */ | ||
850 | return GNUNET_OK; | ||
851 | } | ||
852 | |||
853 | |||
854 | /** | ||
764 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from | 855 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT message from |
765 | * controller (testbed service) | 856 | * controller (testbed service) |
766 | * | 857 | * |
@@ -917,6 +1008,23 @@ GNUNET_TESTBED_generate_slavegetconfig_msg_ (uint64_t op_id, uint32_t slave_id) | |||
917 | } | 1008 | } |
918 | 1009 | ||
919 | 1010 | ||
1011 | |||
1012 | /** | ||
1013 | * Validate #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_INFORMATION message from | ||
1014 | * controller (testbed service) | ||
1015 | * | ||
1016 | * @param c the controller handler | ||
1017 | * @param msg message received | ||
1018 | */ | ||
1019 | static int | ||
1020 | check_slave_config (void *cls, | ||
1021 | const struct GNUNET_TESTBED_SlaveConfiguration *msg) | ||
1022 | { | ||
1023 | /* anything goes? */ | ||
1024 | return GNUNET_OK; | ||
1025 | } | ||
1026 | |||
1027 | |||
920 | /** | 1028 | /** |
921 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION message from controller | 1029 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION message from controller |
922 | * (testbed service) | 1030 | * (testbed service) |
@@ -963,6 +1071,23 @@ handle_slave_config (void *cls, | |||
963 | 1071 | ||
964 | 1072 | ||
965 | /** | 1073 | /** |
1074 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller | ||
1075 | * (testbed service) | ||
1076 | * | ||
1077 | * @param c the controller handler | ||
1078 | * @param msg message received | ||
1079 | * @return #GNUNET_OK if @a msg is well-formed | ||
1080 | */ | ||
1081 | static int | ||
1082 | check_link_controllers_result (void *cls, | ||
1083 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) | ||
1084 | { | ||
1085 | /* actual check to be implemented */ | ||
1086 | return GNUNET_OK; | ||
1087 | } | ||
1088 | |||
1089 | |||
1090 | /** | ||
966 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller | 1091 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT message from controller |
967 | * (testbed service) | 1092 | * (testbed service) |
968 | * | 1093 | * |
@@ -971,8 +1096,7 @@ handle_slave_config (void *cls, | |||
971 | */ | 1096 | */ |
972 | static void | 1097 | static void |
973 | handle_link_controllers_result (void *cls, | 1098 | handle_link_controllers_result (void *cls, |
974 | const struct | 1099 | const struct GNUNET_TESTBED_ControllerLinkResponse *msg) |
975 | GNUNET_TESTBED_ControllerLinkResponse *msg) | ||
976 | { | 1100 | { |
977 | struct GNUNET_TESTBED_Controller *c = cls; | 1101 | struct GNUNET_TESTBED_Controller *c = cls; |
978 | struct OperationContext *opc; | 1102 | struct OperationContext *opc; |
@@ -1056,8 +1180,8 @@ handle_link_controllers_result (void *cls, | |||
1056 | * down signalling an error (message malformed) | 1180 | * down signalling an error (message malformed) |
1057 | */ | 1181 | */ |
1058 | static int | 1182 | static int |
1059 | check_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | 1183 | check_barrier_status (void *cls, |
1060 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 1184 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
1061 | { | 1185 | { |
1062 | uint16_t msize; | 1186 | uint16_t msize; |
1063 | uint16_t name_len; | 1187 | uint16_t name_len; |
@@ -1097,14 +1221,15 @@ check_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
1097 | /** | 1221 | /** |
1098 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages | 1222 | * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS messages |
1099 | * | 1223 | * |
1100 | * @param c the controller handle to determine the connection this message | 1224 | * @param cls the controller handle to determine the connection this message |
1101 | * belongs to | 1225 | * belongs to |
1102 | * @param msg the barrier status message | 1226 | * @param msg the barrier status message |
1103 | */ | 1227 | */ |
1104 | static void | 1228 | static void |
1105 | handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | 1229 | handle_barrier_status (void *cls, |
1106 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) | 1230 | const struct GNUNET_TESTBED_BarrierStatusMsg *msg) |
1107 | { | 1231 | { |
1232 | struct GNUNET_TESTBED_Controller *c = cls; | ||
1108 | struct GNUNET_TESTBED_Barrier *barrier; | 1233 | struct GNUNET_TESTBED_Barrier *barrier; |
1109 | char *emsg; | 1234 | char *emsg; |
1110 | const char *name; | 1235 | const char *name; |
@@ -1159,191 +1284,18 @@ handle_barrier_status_ (struct GNUNET_TESTBED_Controller *c, | |||
1159 | 1284 | ||
1160 | 1285 | ||
1161 | /** | 1286 | /** |
1162 | * Handler for messages from controller (testbed service) | ||
1163 | * | ||
1164 | * @param cls the controller handler | ||
1165 | * @param msg message received, NULL on timeout or fatal error | ||
1166 | */ | ||
1167 | static void | ||
1168 | message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | ||
1169 | { | ||
1170 | struct GNUNET_TESTBED_Controller *c = cls; | ||
1171 | int status; | ||
1172 | uint16_t msize; | ||
1173 | |||
1174 | c->in_receive = GNUNET_NO; | ||
1175 | /* FIXME: Add checks for message integrity */ | ||
1176 | if (NULL == msg) | ||
1177 | { | ||
1178 | LOG_DEBUG ("Receive timed out or connection to service dropped\n"); | ||
1179 | return; | ||
1180 | } | ||
1181 | msize = ntohs (msg->size); | ||
1182 | switch (ntohs (msg->type)) | ||
1183 | { | ||
1184 | case GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS: | ||
1185 | GNUNET_assert (msize >= | ||
1186 | sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)); | ||
1187 | status = | ||
1188 | GNUNET_TESTBED_host_handle_addhostconfirm_ | ||
1189 | (c, (const struct GNUNET_TESTBED_HostConfirmedMessage*) msg); | ||
1190 | break; | ||
1191 | case GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS: | ||
1192 | GNUNET_assert (msize == | ||
1193 | sizeof (struct | ||
1194 | GNUNET_TESTBED_GenericOperationSuccessEventMessage)); | ||
1195 | handle_opsuccess (c, | ||
1196 | (const struct | ||
1197 | GNUNET_TESTBED_GenericOperationSuccessEventMessage *) | ||
1198 | msg); | ||
1199 | status = GNUNET_YES; | ||
1200 | break; | ||
1201 | case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT: | ||
1202 | GNUNET_assert (msize >= | ||
1203 | sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage)); | ||
1204 | handle_op_fail_event (c, | ||
1205 | (const struct | ||
1206 | GNUNET_TESTBED_OperationFailureEventMessage *) | ||
1207 | msg); | ||
1208 | status = GNUNET_YES; | ||
1209 | break; | ||
1210 | case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS: | ||
1211 | GNUNET_assert (msize == | ||
1212 | sizeof (struct | ||
1213 | GNUNET_TESTBED_PeerCreateSuccessEventMessage)); | ||
1214 | handle_peer_create_success (c, | ||
1215 | (const struct | ||
1216 | GNUNET_TESTBED_PeerCreateSuccessEventMessage | ||
1217 | *) msg); | ||
1218 | status = GNUNET_YES; | ||
1219 | break; | ||
1220 | case GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT: | ||
1221 | GNUNET_assert (msize == sizeof (struct GNUNET_TESTBED_PeerEventMessage)); | ||
1222 | handle_peer_event (c, | ||
1223 | (const struct GNUNET_TESTBED_PeerEventMessage *) | ||
1224 | msg); | ||
1225 | |||
1226 | status = GNUNET_YES; | ||
1227 | break; | ||
1228 | case GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION: | ||
1229 | GNUNET_assert (msize >= | ||
1230 | sizeof (struct | ||
1231 | GNUNET_TESTBED_PeerConfigurationInformationMessage)); | ||
1232 | handle_peer_config (c, | ||
1233 | (const struct | ||
1234 | GNUNET_TESTBED_PeerConfigurationInformationMessage | ||
1235 | *) msg); | ||
1236 | status = GNUNET_YES; | ||
1237 | |||
1238 | break; | ||
1239 | case GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT: | ||
1240 | GNUNET_assert (msize == | ||
1241 | sizeof (struct GNUNET_TESTBED_ConnectionEventMessage)); | ||
1242 | handle_peer_conevent (c, | ||
1243 | (const struct | ||
1244 | GNUNET_TESTBED_ConnectionEventMessage *) msg); | ||
1245 | status = GNUNET_YES; | ||
1246 | break; | ||
1247 | case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: | ||
1248 | GNUNET_assert (msize > sizeof (struct GNUNET_TESTBED_SlaveConfiguration)); | ||
1249 | handle_slave_config (c, | ||
1250 | (const struct GNUNET_TESTBED_SlaveConfiguration *) | ||
1251 | msg); | ||
1252 | status = GNUNET_YES; | ||
1253 | break; | ||
1254 | case GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT: | ||
1255 | handle_link_controllers_result (c, | ||
1256 | (const struct | ||
1257 | GNUNET_TESTBED_ControllerLinkResponse | ||
1258 | *) msg); | ||
1259 | status = GNUNET_YES; | ||
1260 | break; | ||
1261 | case GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS: | ||
1262 | status = check_barrier_status_ (c, | ||
1263 | (const struct GNUNET_TESTBED_BarrierStatusMsg *) msg); | ||
1264 | if (GNUNET_OK == status) | ||
1265 | handle_barrier_status_ (c, | ||
1266 | (const struct | ||
1267 | GNUNET_TESTBED_BarrierStatusMsg *) | ||
1268 | msg); | ||
1269 | break; | ||
1270 | default: | ||
1271 | GNUNET_assert (0); | ||
1272 | } | ||
1273 | if ((GNUNET_OK == status) && (GNUNET_NO == c->in_receive)) | ||
1274 | { | ||
1275 | c->in_receive = GNUNET_YES; | ||
1276 | GNUNET_CLIENT_receive (c->client, &message_handler, c, | ||
1277 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1278 | } | ||
1279 | } | ||
1280 | |||
1281 | |||
1282 | /** | ||
1283 | * Function called to notify a client about the connection begin ready to queue | ||
1284 | * more data. "buf" will be NULL and "size" zero if the connection was closed | ||
1285 | * for writing in the meantime. | ||
1286 | * | ||
1287 | * @param cls closure | ||
1288 | * @param size number of bytes available in buf | ||
1289 | * @param buf where the callee should write the message | ||
1290 | * @return number of bytes written to buf | ||
1291 | */ | ||
1292 | static size_t | ||
1293 | transmit_ready_notify (void *cls, size_t size, void *buf) | ||
1294 | { | ||
1295 | struct GNUNET_TESTBED_Controller *c = cls; | ||
1296 | struct MessageQueue *mq_entry; | ||
1297 | |||
1298 | c->th = NULL; | ||
1299 | mq_entry = c->mq_head; | ||
1300 | GNUNET_assert (NULL != mq_entry); | ||
1301 | if ((0 == size) && (NULL == buf)) /* Timeout */ | ||
1302 | { | ||
1303 | LOG_DEBUG ("Message sending timed out -- retrying\n"); | ||
1304 | c->th = | ||
1305 | GNUNET_CLIENT_notify_transmit_ready (c->client, | ||
1306 | ntohs (mq_entry->msg->size), | ||
1307 | TIMEOUT_REL, GNUNET_YES, | ||
1308 | &transmit_ready_notify, c); | ||
1309 | return 0; | ||
1310 | } | ||
1311 | GNUNET_assert (ntohs (mq_entry->msg->size) <= size); | ||
1312 | size = ntohs (mq_entry->msg->size); | ||
1313 | memcpy (buf, mq_entry->msg, size); | ||
1314 | LOG_DEBUG ("Message of type: %u and size: %u sent\n", | ||
1315 | ntohs (mq_entry->msg->type), size); | ||
1316 | GNUNET_free (mq_entry->msg); | ||
1317 | GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, mq_entry); | ||
1318 | GNUNET_free (mq_entry); | ||
1319 | mq_entry = c->mq_head; | ||
1320 | if (NULL != mq_entry) | ||
1321 | c->th = | ||
1322 | GNUNET_CLIENT_notify_transmit_ready (c->client, | ||
1323 | ntohs (mq_entry->msg->size), | ||
1324 | TIMEOUT_REL, GNUNET_YES, | ||
1325 | &transmit_ready_notify, c); | ||
1326 | if (GNUNET_NO == c->in_receive) | ||
1327 | { | ||
1328 | c->in_receive = GNUNET_YES; | ||
1329 | GNUNET_CLIENT_receive (c->client, &message_handler, c, | ||
1330 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1331 | } | ||
1332 | return size; | ||
1333 | } | ||
1334 | |||
1335 | |||
1336 | /** | ||
1337 | * Queues a message in send queue for sending to the service | 1287 | * Queues a message in send queue for sending to the service |
1338 | * | 1288 | * |
1339 | * @param controller the handle to the controller | 1289 | * @param controller the handle to the controller |
1340 | * @param msg the message to queue | 1290 | * @param msg the message to queue |
1291 | * @deprecated | ||
1341 | */ | 1292 | */ |
1342 | void | 1293 | void |
1343 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | 1294 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, |
1344 | struct GNUNET_MessageHeader *msg) | 1295 | struct GNUNET_MessageHeader *msg) |
1345 | { | 1296 | { |
1346 | struct MessageQueue *mq_entry; | 1297 | struct GNUNET_MQ_Envelope *env; |
1298 | struct GNUNET_MessageHeader *m2; | ||
1347 | uint16_t type; | 1299 | uint16_t type; |
1348 | uint16_t size; | 1300 | uint16_t size; |
1349 | 1301 | ||
@@ -1351,19 +1303,13 @@ GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | |||
1351 | size = ntohs (msg->size); | 1303 | size = ntohs (msg->size); |
1352 | GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && | 1304 | GNUNET_assert ((GNUNET_MESSAGE_TYPE_TESTBED_INIT <= type) && |
1353 | (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); | 1305 | (GNUNET_MESSAGE_TYPE_TESTBED_MAX > type)); |
1354 | mq_entry = GNUNET_new (struct MessageQueue); | 1306 | env = GNUNET_MQ_msg_extra (m2, |
1355 | mq_entry->msg = msg; | 1307 | size - sizeof (*m2), |
1356 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1308 | type); |
1357 | "Queueing message of type %u, size %u for sending\n", type, | 1309 | memcpy (m2, msg, size); |
1358 | ntohs (msg->size)); | 1310 | GNUNET_free (msg); |
1359 | GNUNET_CONTAINER_DLL_insert_tail (controller->mq_head, controller->mq_tail, | 1311 | GNUNET_MQ_send (controller->mq, |
1360 | mq_entry); | 1312 | env); |
1361 | if (NULL == controller->th) | ||
1362 | controller->th = | ||
1363 | GNUNET_CLIENT_notify_transmit_ready (controller->client, size, | ||
1364 | TIMEOUT_REL, GNUNET_YES, | ||
1365 | &transmit_ready_notify, | ||
1366 | controller); | ||
1367 | } | 1313 | } |
1368 | 1314 | ||
1369 | 1315 | ||
@@ -1527,6 +1473,28 @@ oprelease_get_slave_config (void *cls) | |||
1527 | 1473 | ||
1528 | 1474 | ||
1529 | /** | 1475 | /** |
1476 | * Generic error handler, called with the appropriate error code and | ||
1477 | * the same closure specified at the creation of the message queue. | ||
1478 | * Not every message queue implementation supports an error handler. | ||
1479 | * | ||
1480 | * @param cls closure, a `struct GNUNET_TESTBED_Controller *` | ||
1481 | * @param error error code | ||
1482 | */ | ||
1483 | static void | ||
1484 | mq_error_handler (void *cls, | ||
1485 | enum GNUNET_MQ_Error error) | ||
1486 | { | ||
1487 | /* struct GNUNET_TESTBED_Controller *c = cls; */ | ||
1488 | |||
1489 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1490 | "Encountered MQ error: %d\n", | ||
1491 | error); | ||
1492 | /* now what? */ | ||
1493 | GNUNET_SCHEDULER_shutdown (); /* seems most reasonable */ | ||
1494 | } | ||
1495 | |||
1496 | |||
1497 | /** | ||
1530 | * Start a controller process using the given configuration at the | 1498 | * Start a controller process using the given configuration at the |
1531 | * given host. | 1499 | * given host. |
1532 | * | 1500 | * |
@@ -1547,7 +1515,51 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1547 | GNUNET_TESTBED_ControllerCallback cc, | 1515 | GNUNET_TESTBED_ControllerCallback cc, |
1548 | void *cc_cls) | 1516 | void *cc_cls) |
1549 | { | 1517 | { |
1550 | struct GNUNET_TESTBED_Controller *controller; | 1518 | GNUNET_MQ_hd_var_size (add_host_confirm, |
1519 | GNUNET_MESSAGE_TYPE_TESTBED_ADD_HOST_SUCCESS, | ||
1520 | struct GNUNET_TESTBED_HostConfirmedMessage); | ||
1521 | GNUNET_MQ_hd_fixed_size (peer_conevent, | ||
1522 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_CONNECT_EVENT, | ||
1523 | struct GNUNET_TESTBED_ConnectionEventMessage); | ||
1524 | GNUNET_MQ_hd_fixed_size (opsuccess, | ||
1525 | GNUNET_MESSAGE_TYPE_TESTBED_GENERIC_OPERATION_SUCCESS, | ||
1526 | struct GNUNET_TESTBED_GenericOperationSuccessEventMessage); | ||
1527 | GNUNET_MQ_hd_var_size (op_fail_event, | ||
1528 | GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT, | ||
1529 | struct GNUNET_TESTBED_OperationFailureEventMessage); | ||
1530 | GNUNET_MQ_hd_fixed_size (peer_create_success, | ||
1531 | GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS, | ||
1532 | struct GNUNET_TESTBED_PeerCreateSuccessEventMessage); | ||
1533 | GNUNET_MQ_hd_fixed_size (peer_event, | ||
1534 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT, | ||
1535 | struct GNUNET_TESTBED_PeerEventMessage); | ||
1536 | GNUNET_MQ_hd_var_size (peer_config, | ||
1537 | GNUNET_MESSAGE_TYPE_TESTBED_PEER_INFORMATION, | ||
1538 | struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | ||
1539 | GNUNET_MQ_hd_var_size (slave_config, | ||
1540 | GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION, | ||
1541 | struct GNUNET_TESTBED_SlaveConfiguration); | ||
1542 | GNUNET_MQ_hd_var_size (link_controllers_result, | ||
1543 | GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, | ||
1544 | struct GNUNET_TESTBED_ControllerLinkResponse); | ||
1545 | GNUNET_MQ_hd_var_size (barrier_status, | ||
1546 | GNUNET_MESSAGE_TYPE_TESTBED_BARRIER_STATUS, | ||
1547 | const struct GNUNET_TESTBED_BarrierStatusMsg); | ||
1548 | struct GNUNET_TESTBED_Controller *controller | ||
1549 | = GNUNET_new (struct GNUNET_TESTBED_Controller); | ||
1550 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
1551 | make_add_host_confirm_handler (controller), | ||
1552 | make_peer_conevent_handler (controller), | ||
1553 | make_opsuccess_handler (controller), | ||
1554 | make_op_fail_event_handler (controller), | ||
1555 | make_peer_create_success_handler (controller), | ||
1556 | make_peer_event_handler (controller), | ||
1557 | make_peer_config_handler (controller), | ||
1558 | make_slave_config_handler (controller), | ||
1559 | make_link_controllers_result_handler (controller), | ||
1560 | make_barrier_status_handler (controller), | ||
1561 | GNUNET_MQ_handler_end () | ||
1562 | }; | ||
1551 | struct GNUNET_TESTBED_InitMessage *msg; | 1563 | struct GNUNET_TESTBED_InitMessage *msg; |
1552 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 1564 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
1553 | const char *controller_hostname; | 1565 | const char *controller_hostname; |
@@ -1562,6 +1574,7 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1562 | &max_parallel_operations)) | 1574 | &max_parallel_operations)) |
1563 | { | 1575 | { |
1564 | GNUNET_break (0); | 1576 | GNUNET_break (0); |
1577 | GNUNET_free (controller); | ||
1565 | return NULL; | 1578 | return NULL; |
1566 | } | 1579 | } |
1567 | if (GNUNET_OK != | 1580 | if (GNUNET_OK != |
@@ -1570,6 +1583,7 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1570 | &max_parallel_service_connections)) | 1583 | &max_parallel_service_connections)) |
1571 | { | 1584 | { |
1572 | GNUNET_break (0); | 1585 | GNUNET_break (0); |
1586 | GNUNET_free (controller); | ||
1573 | return NULL; | 1587 | return NULL; |
1574 | } | 1588 | } |
1575 | if (GNUNET_OK != | 1589 | if (GNUNET_OK != |
@@ -1578,16 +1592,21 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1578 | &max_parallel_topology_config_operations)) | 1592 | &max_parallel_topology_config_operations)) |
1579 | { | 1593 | { |
1580 | GNUNET_break (0); | 1594 | GNUNET_break (0); |
1595 | GNUNET_free (controller); | ||
1581 | return NULL; | 1596 | return NULL; |
1582 | } | 1597 | } |
1583 | controller = GNUNET_new (struct GNUNET_TESTBED_Controller); | ||
1584 | controller->cc = cc; | 1598 | controller->cc = cc; |
1585 | controller->cc_cls = cc_cls; | 1599 | controller->cc_cls = cc_cls; |
1586 | controller->event_mask = event_mask; | 1600 | controller->event_mask = event_mask; |
1587 | controller->cfg = GNUNET_CONFIGURATION_dup (cfg); | 1601 | controller->cfg = GNUNET_CONFIGURATION_dup (cfg); |
1588 | controller->client = GNUNET_CLIENT_connect ("testbed", controller->cfg); | 1602 | controller->mq = GNUNET_CLIENT_connecT (controller->cfg, |
1589 | if (NULL == controller->client) | 1603 | "testbed", |
1604 | handlers, | ||
1605 | &mq_error_handler, | ||
1606 | controller); | ||
1607 | if (NULL == controller->mq) | ||
1590 | { | 1608 | { |
1609 | GNUNET_break (0); | ||
1591 | GNUNET_TESTBED_controller_disconnect (controller); | 1610 | GNUNET_TESTBED_controller_disconnect (controller); |
1592 | return NULL; | 1611 | return NULL; |
1593 | } | 1612 | } |
@@ -1629,9 +1648,8 @@ GNUNET_TESTBED_controller_connect (struct GNUNET_TESTBED_Host *host, | |||
1629 | * @param cls closure | 1648 | * @param cls closure |
1630 | * @param key current key code | 1649 | * @param key current key code |
1631 | * @param value value in the hash map | 1650 | * @param value value in the hash map |
1632 | * @return GNUNET_YES if we should continue to | 1651 | * @return #GNUNET_YES if we should continue to iterate, |
1633 | * iterate, | 1652 | * #GNUNET_NO if not. |
1634 | * GNUNET_NO if not. | ||
1635 | */ | 1653 | */ |
1636 | static int | 1654 | static int |
1637 | opc_free_iterator (void *cls, uint32_t key, void *value) | 1655 | opc_free_iterator (void *cls, uint32_t key, void *value) |
@@ -1658,20 +1676,11 @@ opc_free_iterator (void *cls, uint32_t key, void *value) | |||
1658 | void | 1676 | void |
1659 | GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) | 1677 | GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) |
1660 | { | 1678 | { |
1661 | struct MessageQueue *mq_entry; | 1679 | if (NULL != c->mq) |
1662 | |||
1663 | if (NULL != c->th) | ||
1664 | GNUNET_CLIENT_notify_transmit_ready_cancel (c->th); | ||
1665 | /* Clear the message queue */ | ||
1666 | while (NULL != (mq_entry = c->mq_head)) | ||
1667 | { | 1680 | { |
1668 | GNUNET_CONTAINER_DLL_remove (c->mq_head, c->mq_tail, | 1681 | GNUNET_MQ_destroy (c->mq); |
1669 | mq_entry); | 1682 | c->mq = NULL; |
1670 | GNUNET_free (mq_entry->msg); | ||
1671 | GNUNET_free (mq_entry); | ||
1672 | } | 1683 | } |
1673 | if (NULL != c->client) | ||
1674 | GNUNET_CLIENT_disconnect (c->client); | ||
1675 | if (NULL != c->host) | 1684 | if (NULL != c->host) |
1676 | GNUNET_TESTBED_deregister_host_at_ (c->host, c); | 1685 | GNUNET_TESTBED_deregister_host_at_ (c->host, c); |
1677 | GNUNET_CONFIGURATION_destroy (c->cfg); | 1686 | GNUNET_CONFIGURATION_destroy (c->cfg); |
@@ -1703,7 +1712,8 @@ GNUNET_TESTBED_controller_disconnect (struct GNUNET_TESTBED_Controller *c) | |||
1703 | * @return the size of the xconfig | 1712 | * @return the size of the xconfig |
1704 | */ | 1713 | */ |
1705 | size_t | 1714 | size_t |
1706 | GNUNET_TESTBED_compress_config_ (const char *config, size_t size, | 1715 | GNUNET_TESTBED_compress_config_ (const char *config, |
1716 | size_t size, | ||
1707 | char **xconfig) | 1717 | char **xconfig) |
1708 | { | 1718 | { |
1709 | size_t xsize; | 1719 | size_t xsize; |
@@ -2002,6 +2012,8 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
2002 | * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, | 2012 | * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS, |
2003 | * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, | 2013 | * #GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT, |
2004 | * | 2014 | * |
2015 | * FIXME: This API is incredibly ugly. | ||
2016 | * | ||
2005 | * @param msg the message containing compressed configuration | 2017 | * @param msg the message containing compressed configuration |
2006 | * @return handle to the parsed configuration; NULL upon error while parsing the message | 2018 | * @return handle to the parsed configuration; NULL upon error while parsing the message |
2007 | */ | 2019 | */ |
@@ -2407,7 +2419,4 @@ GNUNET_TESTBED_barrier_cancel (struct GNUNET_TESTBED_Barrier *barrier) | |||
2407 | } | 2419 | } |
2408 | 2420 | ||
2409 | 2421 | ||
2410 | |||
2411 | |||
2412 | |||
2413 | /* end of testbed_api.c */ | 2422 | /* end of testbed_api.c */ |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index cd3358c9a..82ff5918f 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -105,33 +105,28 @@ enum OperationType | |||
105 | }; | 105 | }; |
106 | 106 | ||
107 | 107 | ||
108 | /** | ||
109 | * The message queue for sending messages to the controller service | ||
110 | */ | ||
111 | struct MessageQueue; | ||
112 | |||
113 | 108 | ||
114 | /** | 109 | /** |
115 | * Enumeration of states of OperationContext | 110 | * Enumeration of states of OperationContext |
116 | */ | 111 | */ |
117 | enum OperationContextState | 112 | enum OperationContextState |
118 | { | 113 | { |
119 | /** | 114 | /** |
120 | * The initial state where the associated operation has just been created | 115 | * The initial state where the associated operation has just been created |
121 | * and is waiting in the operation queues to be started | 116 | * and is waiting in the operation queues to be started |
122 | */ | 117 | */ |
123 | OPC_STATE_INIT = 0, | 118 | OPC_STATE_INIT = 0, |
124 | 119 | ||
125 | /** | 120 | /** |
126 | * The operation has been started. It may occupy some resources which are to | 121 | * The operation has been started. It may occupy some resources which are to |
127 | * be freed if cancelled. | 122 | * be freed if cancelled. |
128 | */ | 123 | */ |
129 | OPC_STATE_STARTED, | 124 | OPC_STATE_STARTED, |
130 | 125 | ||
131 | /** | 126 | /** |
132 | * The operation has finished. The end results of this operation may occupy | 127 | * The operation has finished. The end results of this operation may occupy |
133 | * some resources which are to be freed by operation_done | 128 | * some resources which are to be freed by operation_done |
134 | */ | 129 | */ |
135 | OPC_STATE_FINISHED | 130 | OPC_STATE_FINISHED |
136 | }; | 131 | }; |
137 | 132 | ||
@@ -219,24 +214,9 @@ struct GNUNET_TESTBED_Controller | |||
219 | struct GNUNET_CONFIGURATION_Handle *cfg; | 214 | struct GNUNET_CONFIGURATION_Handle *cfg; |
220 | 215 | ||
221 | /** | 216 | /** |
222 | * The client connection handle to the controller service | 217 | * The message queue to the controller service |
223 | */ | ||
224 | struct GNUNET_CLIENT_Connection *client; | ||
225 | |||
226 | /** | ||
227 | * The head of the message queue | ||
228 | */ | ||
229 | struct MessageQueue *mq_head; | ||
230 | |||
231 | /** | ||
232 | * The tail of the message queue | ||
233 | */ | 218 | */ |
234 | struct MessageQueue *mq_tail; | 219 | struct GNUNET_MQ_Handle *mq; |
235 | |||
236 | /** | ||
237 | * The client transmit handle | ||
238 | */ | ||
239 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
240 | 220 | ||
241 | /** | 221 | /** |
242 | * The host registration handle; NULL if no current registration requests are | 222 | * The host registration handle; NULL if no current registration requests are |
@@ -286,11 +266,6 @@ struct GNUNET_TESTBED_Controller | |||
286 | uint64_t event_mask; | 266 | uint64_t event_mask; |
287 | 267 | ||
288 | /** | 268 | /** |
289 | * Did we start the receive loop yet? | ||
290 | */ | ||
291 | int in_receive; | ||
292 | |||
293 | /** | ||
294 | * The operation id counter. use current value and increment | 269 | * The operation id counter. use current value and increment |
295 | */ | 270 | */ |
296 | uint32_t operation_counter; | 271 | uint32_t operation_counter; |
@@ -341,6 +316,7 @@ struct GNUNET_TESTBED_Barrier | |||
341 | * | 316 | * |
342 | * @param controller the handle to the controller | 317 | * @param controller the handle to the controller |
343 | * @param msg the message to queue | 318 | * @param msg the message to queue |
319 | * @deprecated | ||
344 | */ | 320 | */ |
345 | void | 321 | void |
346 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, | 322 | GNUNET_TESTBED_queue_message_ (struct GNUNET_TESTBED_Controller *controller, |
@@ -382,7 +358,8 @@ GNUNET_TESTBED_remove_opc_ (const struct GNUNET_TESTBED_Controller *c, | |||
382 | * @return the size of the xconfig | 358 | * @return the size of the xconfig |
383 | */ | 359 | */ |
384 | size_t | 360 | size_t |
385 | GNUNET_TESTBED_compress_config_ (const char *config, size_t size, | 361 | GNUNET_TESTBED_compress_config_ (const char *config, |
362 | size_t size, | ||
386 | char **xconfig); | 363 | char **xconfig); |
387 | 364 | ||
388 | 365 | ||
@@ -397,7 +374,8 @@ GNUNET_TESTBED_compress_config_ (const char *config, size_t size, | |||
397 | */ | 374 | */ |
398 | char * | 375 | char * |
399 | GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | 376 | GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, |
400 | size_t *size, size_t *xsize); | 377 | size_t *size, |
378 | size_t *xsize); | ||
401 | 379 | ||
402 | 380 | ||
403 | /** | 381 | /** |
@@ -414,9 +392,9 @@ GNUNET_TESTBED_compress_cfg_ (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
414 | * @return the initialization message | 392 | * @return the initialization message |
415 | */ | 393 | */ |
416 | struct GNUNET_TESTBED_HelperInit * | 394 | struct GNUNET_TESTBED_HelperInit * |
417 | GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, const char *hostname, | 395 | GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, |
418 | const struct GNUNET_CONFIGURATION_Handle | 396 | const char *hostname, |
419 | *cfg); | 397 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
420 | 398 | ||
421 | 399 | ||
422 | /** | 400 | /** |
@@ -434,8 +412,8 @@ GNUNET_TESTBED_create_helper_init_msg_ (const char *cname, const char *hostname, | |||
434 | * operation | 412 | * operation |
435 | */ | 413 | */ |
436 | struct OperationContext * | 414 | struct OperationContext * |
437 | GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller | 415 | GNUNET_TESTBED_forward_operation_msg_ (struct GNUNET_TESTBED_Controller *controller, |
438 | *controller, uint64_t operation_id, | 416 | uint64_t operation_id, |
439 | const struct GNUNET_MessageHeader *msg, | 417 | const struct GNUNET_MessageHeader *msg, |
440 | GNUNET_CLIENT_MessageHandler cc, | 418 | GNUNET_CLIENT_MessageHandler cc, |
441 | void *cc_cls); | 419 | void *cc_cls); |
@@ -453,8 +431,8 @@ GNUNET_TESTBED_forward_operation_msg_cancel_ (struct OperationContext *opc); | |||
453 | /** | 431 | /** |
454 | * Generates configuration by uncompressing configuration in given message. The | 432 | * Generates configuration by uncompressing configuration in given message. The |
455 | * given message should be of the following types: | 433 | * given message should be of the following types: |
456 | * GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG, | 434 | * #GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG, |
457 | * GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG | 435 | * #GNUNET_MESSAGE_TYPE_TESTBED_SLAVECONFIG |
458 | * | 436 | * |
459 | * @param msg the message containing compressed configuration | 437 | * @param msg the message containing compressed configuration |
460 | * @return handle to the parsed configuration | 438 | * @return handle to the parsed configuration |
@@ -471,9 +449,7 @@ GNUNET_TESTBED_extract_config_ (const struct GNUNET_MessageHeader *msg); | |||
471 | * @return the error message | 449 | * @return the error message |
472 | */ | 450 | */ |
473 | const char * | 451 | const char * |
474 | GNUNET_TESTBED_parse_error_string_ (const struct | 452 | GNUNET_TESTBED_parse_error_string_ (const struct GNUNET_TESTBED_OperationFailureEventMessage *msg); |
475 | GNUNET_TESTBED_OperationFailureEventMessage | ||
476 | *msg); | ||
477 | 453 | ||
478 | 454 | ||
479 | /** | 455 | /** |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 5b1df615e..4e14a4d4d 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -1385,33 +1385,6 @@ GNUNET_TESTBED_is_host_habitable_cancel (struct | |||
1385 | 1385 | ||
1386 | 1386 | ||
1387 | /** | 1387 | /** |
1388 | * handle for host registration | ||
1389 | */ | ||
1390 | struct GNUNET_TESTBED_HostRegistrationHandle | ||
1391 | { | ||
1392 | /** | ||
1393 | * The host being registered | ||
1394 | */ | ||
1395 | struct GNUNET_TESTBED_Host *host; | ||
1396 | |||
1397 | /** | ||
1398 | * The controller at which this host is being registered | ||
1399 | */ | ||
1400 | struct GNUNET_TESTBED_Controller *c; | ||
1401 | |||
1402 | /** | ||
1403 | * The Registartion completion callback | ||
1404 | */ | ||
1405 | GNUNET_TESTBED_HostRegistrationCompletion cc; | ||
1406 | |||
1407 | /** | ||
1408 | * The closure for above callback | ||
1409 | */ | ||
1410 | void *cc_cls; | ||
1411 | }; | ||
1412 | |||
1413 | |||
1414 | /** | ||
1415 | * Register a host with the controller | 1388 | * Register a host with the controller |
1416 | * | 1389 | * |
1417 | * @param controller the controller handle | 1390 | * @param controller the controller handle |
@@ -1537,63 +1510,6 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | |||
1537 | 1510 | ||
1538 | 1511 | ||
1539 | /** | 1512 | /** |
1540 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
1541 | * controller (testbed service) | ||
1542 | * | ||
1543 | * @param c the controller handler | ||
1544 | * @param msg message received | ||
1545 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
1546 | * not | ||
1547 | */ | ||
1548 | int | ||
1549 | GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c, | ||
1550 | const struct | ||
1551 | GNUNET_TESTBED_HostConfirmedMessage | ||
1552 | *msg) | ||
1553 | { | ||
1554 | struct GNUNET_TESTBED_HostRegistrationHandle *rh; | ||
1555 | char *emsg; | ||
1556 | uint16_t msg_size; | ||
1557 | |||
1558 | rh = c->rh; | ||
1559 | if (NULL == rh) | ||
1560 | { | ||
1561 | return GNUNET_OK; | ||
1562 | } | ||
1563 | if (GNUNET_TESTBED_host_get_id_ (rh->host) != ntohl (msg->host_id)) | ||
1564 | { | ||
1565 | LOG_DEBUG ("Mismatch in host id's %u, %u of host confirm msg\n", | ||
1566 | GNUNET_TESTBED_host_get_id_ (rh->host), ntohl (msg->host_id)); | ||
1567 | return GNUNET_OK; | ||
1568 | } | ||
1569 | c->rh = NULL; | ||
1570 | msg_size = ntohs (msg->header.size); | ||
1571 | if (sizeof (struct GNUNET_TESTBED_HostConfirmedMessage) == msg_size) | ||
1572 | { | ||
1573 | LOG_DEBUG ("Host %u successfully registered\n", ntohl (msg->host_id)); | ||
1574 | GNUNET_TESTBED_mark_host_registered_at_ (rh->host, c); | ||
1575 | rh->cc (rh->cc_cls, NULL); | ||
1576 | GNUNET_free (rh); | ||
1577 | return GNUNET_OK; | ||
1578 | } | ||
1579 | /* We have an error message */ | ||
1580 | emsg = (char *) &msg[1]; | ||
1581 | if ('\0' != | ||
1582 | emsg[msg_size - sizeof (struct GNUNET_TESTBED_HostConfirmedMessage)]) | ||
1583 | { | ||
1584 | GNUNET_break (0); | ||
1585 | GNUNET_free (rh); | ||
1586 | return GNUNET_NO; | ||
1587 | } | ||
1588 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Adding host %u failed with error: %s\n"), | ||
1589 | ntohl (msg->host_id), emsg); | ||
1590 | rh->cc (rh->cc_cls, emsg); | ||
1591 | GNUNET_free (rh); | ||
1592 | return GNUNET_OK; | ||
1593 | } | ||
1594 | |||
1595 | |||
1596 | /** | ||
1597 | * Resolves the hostname of the host to an ip address | 1513 | * Resolves the hostname of the host to an ip address |
1598 | * | 1514 | * |
1599 | * @param host the host whose hostname is to be resolved | 1515 | * @param host the host whose hostname is to be resolved |
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h index e58da1961..2e53e1c64 100644 --- a/src/testbed/testbed_api_hosts.h +++ b/src/testbed/testbed_api_hosts.h | |||
@@ -24,8 +24,8 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | 26 | ||
27 | #ifndef NEW_TESTING_API_HOSTS_H | 27 | #ifndef TESTBED_API_HOSTS_H |
28 | #define NEW_TESTING_API_HOSTS_H | 28 | #define TESTBED_API_HOSTS_H |
29 | 29 | ||
30 | //#include "gnunet_testbed_service.h" | 30 | //#include "gnunet_testbed_service.h" |
31 | //#include "testbed_helper.h" | 31 | //#include "testbed_helper.h" |
@@ -33,6 +33,33 @@ | |||
33 | 33 | ||
34 | 34 | ||
35 | /** | 35 | /** |
36 | * handle for host registration | ||
37 | */ | ||
38 | struct GNUNET_TESTBED_HostRegistrationHandle | ||
39 | { | ||
40 | /** | ||
41 | * The host being registered | ||
42 | */ | ||
43 | struct GNUNET_TESTBED_Host *host; | ||
44 | |||
45 | /** | ||
46 | * The controller at which this host is being registered | ||
47 | */ | ||
48 | struct GNUNET_TESTBED_Controller *c; | ||
49 | |||
50 | /** | ||
51 | * The Registartion completion callback | ||
52 | */ | ||
53 | GNUNET_TESTBED_HostRegistrationCompletion cc; | ||
54 | |||
55 | /** | ||
56 | * The closure for above callback | ||
57 | */ | ||
58 | void *cc_cls; | ||
59 | }; | ||
60 | |||
61 | |||
62 | /** | ||
36 | * Lookup a host by ID. | 63 | * Lookup a host by ID. |
37 | * | 64 | * |
38 | * @param id global host ID assigned to the host; 0 is | 65 | * @param id global host ID assigned to the host; 0 is |
@@ -164,22 +191,6 @@ GNUNET_TESTBED_host_queue_oc_ (struct GNUNET_TESTBED_Host *h, | |||
164 | 191 | ||
165 | 192 | ||
166 | /** | 193 | /** |
167 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOSTCONFIRM message from | ||
168 | * controller (testbed service) | ||
169 | * | ||
170 | * @param c the controller handler | ||
171 | * @param msg message received | ||
172 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
173 | * not | ||
174 | */ | ||
175 | int | ||
176 | GNUNET_TESTBED_host_handle_addhostconfirm_ (struct GNUNET_TESTBED_Controller *c, | ||
177 | const struct | ||
178 | GNUNET_TESTBED_HostConfirmedMessage | ||
179 | *msg); | ||
180 | |||
181 | |||
182 | /** | ||
183 | * Sends termination signal to the controller's helper process | 194 | * Sends termination signal to the controller's helper process |
184 | * | 195 | * |
185 | * @param cproc the handle to the controller's helper process | 196 | * @param cproc the handle to the controller's helper process |