diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-12-25 14:07:10 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-12-25 14:07:10 +0100 |
commit | 92d278e49fff3d202e827a78b2e58f3ca9e2b6ec (patch) | |
tree | f38aeddeb3a235d73c9ddff4bb368498e27311a5 /src/transport/transport-testing2.c | |
parent | 6e489113f724f19d683963be0382d61291a5bef9 (diff) | |
download | gnunet-92d278e49fff3d202e827a78b2e58f3ca9e2b6ec.tar.gz gnunet-92d278e49fff3d202e827a78b2e58f3ca9e2b6ec.zip |
allow multiple iterations, more code cleanup
Diffstat (limited to 'src/transport/transport-testing2.c')
-rw-r--r-- | src/transport/transport-testing2.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c index 558bf007f..22a767fce 100644 --- a/src/transport/transport-testing2.c +++ b/src/transport/transport-testing2.c | |||
@@ -370,9 +370,9 @@ handle_incoming_msg (void *cls, | |||
370 | { | 370 | { |
371 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 371 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
372 | struct GNUNET_MessageHeader *msg; | 372 | struct GNUNET_MessageHeader *msg; |
373 | msg = (struct GNUNET_MessageHeader *)&inc_msg[1]; | 373 | msg = (struct GNUNET_MessageHeader *) &inc_msg[1]; |
374 | size_t payload_len = ntohs (msg->size) - sizeof (struct | 374 | size_t payload_len = ntohs (msg->size) - sizeof (struct |
375 | GNUNET_MessageHeader); | 375 | GNUNET_MessageHeader); |
376 | 376 | ||
377 | if (NULL != tc_h->incoming_msg_cb) | 377 | if (NULL != tc_h->incoming_msg_cb) |
378 | { | 378 | { |
@@ -536,7 +536,6 @@ connect_cb (void *cls, | |||
536 | struct GNUNET_MQ_Handle *mq) | 536 | struct GNUNET_MQ_Handle *mq) |
537 | { | 537 | { |
538 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 538 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
539 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; | ||
540 | 539 | ||
541 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); | 540 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); |
542 | tc_h->client = client; | 541 | tc_h->client = client; |
@@ -545,13 +544,18 @@ connect_cb (void *cls, | |||
545 | if (NULL == tc_h->queue_head) | 544 | if (NULL == tc_h->queue_head) |
546 | return tc_h; | 545 | return tc_h; |
547 | /* Iterate over queues. They are yet to be opened. Request opening. */ | 546 | /* Iterate over queues. They are yet to be opened. Request opening. */ |
548 | while (NULL != (tc_queue_iter = tc_h->queue_head)) | 547 | for (struct |
548 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter = | ||
549 | tc_h->queue_head; | ||
550 | NULL != tc_queue_iter; | ||
551 | tc_queue_iter = tc_queue_iter->next) | ||
549 | { | 552 | { |
550 | if (NULL == tc_queue_iter->open_queue_env) | 553 | if (NULL == tc_queue_iter->open_queue_env) |
551 | continue; | 554 | continue; |
552 | /* Send the previously created mq envelope to request the creation of the | 555 | /* Send the previously created mq envelope to request the creation of the |
553 | * queue. */ | 556 | * queue. */ |
554 | GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); | 557 | GNUNET_MQ_send (tc_h->c_mq, |
558 | tc_queue_iter->open_queue_env); | ||
555 | tc_queue_iter->open_queue_env = NULL; | 559 | tc_queue_iter->open_queue_env = NULL; |
556 | } | 560 | } |
557 | return tc_h; | 561 | return tc_h; |
@@ -576,6 +580,7 @@ disconnect_cb (void *cls, | |||
576 | tc_h->client = NULL; | 580 | tc_h->client = NULL; |
577 | } | 581 | } |
578 | 582 | ||
583 | |||
579 | /** | 584 | /** |
580 | * Message was transmitted. Process the request. | 585 | * Message was transmitted. Process the request. |
581 | * | 586 | * |
@@ -588,11 +593,10 @@ handle_send_message_ack (void *cls, | |||
588 | { | 593 | { |
589 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 594 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
590 | GNUNET_SERVICE_client_continue (tc_h->client); | 595 | GNUNET_SERVICE_client_continue (tc_h->client); |
591 | //NOP | 596 | // NOP |
592 | } | 597 | } |
593 | 598 | ||
594 | 599 | ||
595 | |||
596 | /** | 600 | /** |
597 | * @brief Start the communicator part of the transport service | 601 | * @brief Start the communicator part of the transport service |
598 | * | 602 | * |
@@ -650,11 +654,11 @@ transport_communicator_start ( | |||
650 | 654 | ||
651 | 655 | ||
652 | tc_h->sh = GNUNET_SERVICE_start ("transport", | 656 | tc_h->sh = GNUNET_SERVICE_start ("transport", |
653 | tc_h->cfg, | 657 | tc_h->cfg, |
654 | &connect_cb, | 658 | &connect_cb, |
655 | &disconnect_cb, | 659 | &disconnect_cb, |
656 | tc_h, | 660 | tc_h, |
657 | mh); | 661 | mh); |
658 | GNUNET_assert (NULL != tc_h->sh); | 662 | GNUNET_assert (NULL != tc_h->sh); |
659 | } | 663 | } |
660 | 664 | ||
@@ -680,11 +684,12 @@ shutdown_process (struct GNUNET_OS_Process *proc) | |||
680 | GNUNET_OS_process_destroy (proc); | 684 | GNUNET_OS_process_destroy (proc); |
681 | } | 685 | } |
682 | 686 | ||
687 | |||
683 | static void | 688 | static void |
684 | shutdown_communicator (void *cls) | 689 | shutdown_communicator (void *cls) |
685 | { | 690 | { |
686 | struct GNUNET_OS_Process *proc = cls; | 691 | struct GNUNET_OS_Process *proc = cls; |
687 | shutdown_process(proc); | 692 | shutdown_process (proc); |
688 | } | 693 | } |
689 | 694 | ||
690 | 695 | ||
@@ -721,6 +726,7 @@ communicator_start ( | |||
721 | GNUNET_free (binary); | 726 | GNUNET_free (binary); |
722 | } | 727 | } |
723 | 728 | ||
729 | |||
724 | /** | 730 | /** |
725 | * @brief Task run at shutdown to kill communicator and clean up | 731 | * @brief Task run at shutdown to kill communicator and clean up |
726 | * | 732 | * |
@@ -747,15 +753,15 @@ nat_start ( | |||
747 | LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n"); | 753 | LOG (GNUNET_ERROR_TYPE_DEBUG, "nat_start\n"); |
748 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat"); | 754 | binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-nat"); |
749 | tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_YES, | 755 | tc_h->nat_proc = GNUNET_OS_start_process (GNUNET_YES, |
750 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, | 756 | GNUNET_OS_INHERIT_STD_OUT_AND_ERR, |
751 | NULL, | 757 | NULL, |
752 | NULL, | 758 | NULL, |
753 | NULL, | 759 | NULL, |
754 | binary, | 760 | binary, |
755 | "gnunet-service-nat", | 761 | "gnunet-service-nat", |
756 | "-c", | 762 | "-c", |
757 | tc_h->cfg_filename, | 763 | tc_h->cfg_filename, |
758 | NULL); | 764 | NULL); |
759 | if (NULL == tc_h->nat_proc) | 765 | if (NULL == tc_h->nat_proc) |
760 | { | 766 | { |
761 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!"); | 767 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start NAT!"); |
@@ -766,14 +772,13 @@ nat_start ( | |||
766 | } | 772 | } |
767 | 773 | ||
768 | 774 | ||
769 | |||
770 | static void | 775 | static void |
771 | do_shutdown (void *cls) | 776 | do_shutdown (void *cls) |
772 | { | 777 | { |
773 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | 778 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; |
774 | shutdown_communicator(tc_h->c_proc); | 779 | shutdown_communicator (tc_h->c_proc); |
775 | shutdown_service(tc_h->sh); | 780 | shutdown_service (tc_h->sh); |
776 | shutdown_nat(tc_h->nat_proc); | 781 | shutdown_nat (tc_h->nat_proc); |
777 | } | 782 | } |
778 | 783 | ||
779 | 784 | ||
@@ -836,6 +841,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | |||
836 | return tc_h; | 841 | return tc_h; |
837 | } | 842 | } |
838 | 843 | ||
844 | |||
839 | /** | 845 | /** |
840 | * @brief Instruct communicator to open a queue | 846 | * @brief Instruct communicator to open a queue |
841 | * | 847 | * |
@@ -924,5 +930,6 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send | |||
924 | memcpy (&msg[1], mh, inbox_size); | 930 | memcpy (&msg[1], mh, inbox_size); |
925 | GNUNET_free (mh); | 931 | GNUNET_free (mh); |
926 | GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); | 932 | GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); |
933 | // GNUNET_assert (0); // FIXME: not iplemented! | ||
927 | return tc_t; | 934 | return tc_t; |
928 | } | 935 | } |