aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed_peers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-service-testbed_peers.c')
-rw-r--r--src/testbed/gnunet-service-testbed_peers.c276
1 files changed, 187 insertions, 89 deletions
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c
index 9c12c25a6..b55f5a8c8 100644
--- a/src/testbed/gnunet-service-testbed_peers.c
+++ b/src/testbed/gnunet-service-testbed_peers.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008--2013 GNUnet e.V. 3 Copyright (C) 2008--2013, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -72,6 +72,11 @@ struct ManageServiceContext
72 struct GNUNET_SERVER_Client *client; 72 struct GNUNET_SERVER_Client *client;
73 73
74 /** 74 /**
75 * Name of the service.
76 */
77 char *service;
78
79 /**
75 * The operation id of the associated request 80 * The operation id of the associated request
76 */ 81 */
77 uint64_t op_id; 82 uint64_t op_id;
@@ -421,7 +426,8 @@ GST_handle_peer_create (void *cls, struct GNUNET_SERVER_Client *client,
421 &msg->header, 426 &msg->header,
422 peer_create_success_cb, fo_ctxt); 427 peer_create_success_cb, fo_ctxt);
423 fo_ctxt->timeout_task = 428 fo_ctxt->timeout_task =
424 GNUNET_SCHEDULER_add_delayed (GST_timeout, &peer_create_forward_timeout, 429 GNUNET_SCHEDULER_add_delayed (GST_timeout,
430 &peer_create_forward_timeout,
425 fo_ctxt); 431 fo_ctxt);
426 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt); 432 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
427 GNUNET_SERVER_receive_done (client, GNUNET_OK); 433 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -475,7 +481,8 @@ GST_handle_peer_destroy (void *cls,
475 fopc->operation_id, &msg->header, 481 fopc->operation_id, &msg->header,
476 &peer_destroy_success_cb, fopc); 482 &peer_destroy_success_cb, fopc);
477 fopc->timeout_task = 483 fopc->timeout_task =
478 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 484 GNUNET_SCHEDULER_add_delayed (GST_timeout,
485 &GST_forwarded_operation_timeout,
479 fopc); 486 fopc);
480 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc); 487 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
481 GNUNET_SERVER_receive_done (client, GNUNET_OK); 488 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -568,7 +575,8 @@ GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
568 &GST_forwarded_operation_reply_relay, 575 &GST_forwarded_operation_reply_relay,
569 fopc); 576 fopc);
570 fopc->timeout_task = 577 fopc->timeout_task =
571 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 578 GNUNET_SCHEDULER_add_delayed (GST_timeout,
579 &GST_forwarded_operation_timeout,
572 fopc); 580 fopc);
573 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc); 581 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
574 GNUNET_SERVER_receive_done (client, GNUNET_OK); 582 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -594,14 +602,15 @@ GST_handle_peer_start (void *cls, struct GNUNET_SERVER_Client *client,
594 602
595 603
596/** 604/**
597 * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages 605 * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER messages
598 * 606 *
599 * @param cls NULL 607 * @param cls NULL
600 * @param client identification of the client 608 * @param client identification of the client
601 * @param message the actual message 609 * @param message the actual message
602 */ 610 */
603void 611void
604GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client, 612GST_handle_peer_stop (void *cls,
613 struct GNUNET_SERVER_Client *client,
605 const struct GNUNET_MessageHeader *message) 614 const struct GNUNET_MessageHeader *message)
606{ 615{
607 const struct GNUNET_TESTBED_PeerStopMessage *msg; 616 const struct GNUNET_TESTBED_PeerStopMessage *msg;
@@ -612,10 +621,13 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
612 621
613 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message; 622 msg = (const struct GNUNET_TESTBED_PeerStopMessage *) message;
614 peer_id = ntohl (msg->peer_id); 623 peer_id = ntohl (msg->peer_id);
615 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PEER_STOP for peer %u\n", peer_id); 624 LOG (GNUNET_ERROR_TYPE_DEBUG,
625 "Received PEER_STOP for peer %u\n",
626 (unsigned int) peer_id);
616 if (!VALID_PEER_ID (peer_id)) 627 if (!VALID_PEER_ID (peer_id))
617 { 628 {
618 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 629 GST_send_operation_fail_msg (client,
630 GNUNET_ntohll (msg->operation_id),
619 "Peer not found"); 631 "Peer not found");
620 GNUNET_SERVER_receive_done (client, GNUNET_OK); 632 GNUNET_SERVER_receive_done (client, GNUNET_OK);
621 return; 633 return;
@@ -623,8 +635,9 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
623 peer = GST_peer_list[peer_id]; 635 peer = GST_peer_list[peer_id];
624 if (GNUNET_YES == peer->is_remote) 636 if (GNUNET_YES == peer->is_remote)
625 { 637 {
626 LOG (GNUNET_ERROR_TYPE_DEBUG, "Forwarding PEER_STOP for peer %u\n", 638 LOG (GNUNET_ERROR_TYPE_DEBUG,
627 peer_id); 639 "Forwarding PEER_STOP for peer %u\n",
640 (unsigned int) peer_id);
628 fopc = GNUNET_new (struct ForwardedOperationContext); 641 fopc = GNUNET_new (struct ForwardedOperationContext);
629 GNUNET_SERVER_client_keep (client); 642 GNUNET_SERVER_client_keep (client);
630 fopc->client = client; 643 fopc->client = client;
@@ -633,25 +646,35 @@ GST_handle_peer_stop (void *cls, struct GNUNET_SERVER_Client *client,
633 fopc->opc = 646 fopc->opc =
634 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. 647 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
635 slave->controller, 648 slave->controller,
636 fopc->operation_id, &msg->header, 649 fopc->operation_id,
650 &msg->header,
637 &GST_forwarded_operation_reply_relay, 651 &GST_forwarded_operation_reply_relay,
638 fopc); 652 fopc);
639 fopc->timeout_task = 653 fopc->timeout_task =
640 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 654 GNUNET_SCHEDULER_add_delayed (GST_timeout,
655 &GST_forwarded_operation_timeout,
656 fopc);
657 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
658 fopcq_tail,
641 fopc); 659 fopc);
642 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
643 GNUNET_SERVER_receive_done (client, GNUNET_OK); 660 GNUNET_SERVER_receive_done (client, GNUNET_OK);
644 return; 661 return;
645 } 662 }
646 if (GNUNET_OK != stop_peer (peer)) 663 if (GNUNET_OK != stop_peer (peer))
647 { 664 {
648 LOG (GNUNET_ERROR_TYPE_WARNING, "Stopping peer %u failed\n", peer_id); 665 LOG (GNUNET_ERROR_TYPE_WARNING,
649 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 666 "Stopping peer %u failed\n",
667 (unsigned int) peer_id);
668 GST_send_operation_fail_msg (client,
669 GNUNET_ntohll (msg->operation_id),
650 "Peer not running"); 670 "Peer not running");
651 GNUNET_SERVER_receive_done (client, GNUNET_OK); 671 GNUNET_SERVER_receive_done (client,
672 GNUNET_OK);
652 return; 673 return;
653 } 674 }
654 LOG (GNUNET_ERROR_TYPE_DEBUG, "Peer %u successfully stopped\n", peer_id); 675 LOG (GNUNET_ERROR_TYPE_DEBUG,
676 "Peer %u successfully stopped\n",
677 (unsigned int) peer_id);
655 reply = GNUNET_new (struct GNUNET_TESTBED_PeerEventMessage); 678 reply = GNUNET_new (struct GNUNET_TESTBED_PeerEventMessage);
656 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT); 679 reply->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_PEER_EVENT);
657 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage)); 680 reply->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerEventMessage));
@@ -689,10 +712,12 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
689 712
690 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message; 713 msg = (const struct GNUNET_TESTBED_PeerGetConfigurationMessage *) message;
691 peer_id = ntohl (msg->peer_id); 714 peer_id = ntohl (msg->peer_id);
692 LOG_DEBUG ("Received GET_CONFIG for peer %u\n", peer_id); 715 LOG_DEBUG ("Received GET_CONFIG for peer %u\n",
716 (unsigned int) peer_id);
693 if (!VALID_PEER_ID (peer_id)) 717 if (!VALID_PEER_ID (peer_id))
694 { 718 {
695 GST_send_operation_fail_msg (client, GNUNET_ntohll (msg->operation_id), 719 GST_send_operation_fail_msg (client,
720 GNUNET_ntohll (msg->operation_id),
696 "Peer not found"); 721 "Peer not found");
697 GNUNET_SERVER_receive_done (client, GNUNET_OK); 722 GNUNET_SERVER_receive_done (client, GNUNET_OK);
698 return; 723 return;
@@ -700,7 +725,8 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
700 peer = GST_peer_list[peer_id]; 725 peer = GST_peer_list[peer_id];
701 if (GNUNET_YES == peer->is_remote) 726 if (GNUNET_YES == peer->is_remote)
702 { 727 {
703 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n", peer_id); 728 LOG_DEBUG ("Forwarding PEER_GET_CONFIG for peer: %u\n",
729 (unsigned int) peer_id);
704 fopc = GNUNET_new (struct ForwardedOperationContext); 730 fopc = GNUNET_new (struct ForwardedOperationContext);
705 GNUNET_SERVER_client_keep (client); 731 GNUNET_SERVER_client_keep (client);
706 fopc->client = client; 732 fopc->client = client;
@@ -709,21 +735,28 @@ GST_handle_peer_get_config (void *cls, struct GNUNET_SERVER_Client *client,
709 fopc->opc = 735 fopc->opc =
710 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. 736 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
711 slave->controller, 737 slave->controller,
712 fopc->operation_id, &msg->header, 738 fopc->operation_id,
739 &msg->header,
713 &GST_forwarded_operation_reply_relay, 740 &GST_forwarded_operation_reply_relay,
714 fopc); 741 fopc);
715 fopc->timeout_task = 742 fopc->timeout_task =
716 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 743 GNUNET_SCHEDULER_add_delayed (GST_timeout,
744 &GST_forwarded_operation_timeout,
745 fopc);
746 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
747 fopcq_tail,
717 fopc); 748 fopc);
718 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
719 GNUNET_SERVER_receive_done (client, GNUNET_OK); 749 GNUNET_SERVER_receive_done (client, GNUNET_OK);
720 return; 750 return;
721 } 751 }
722 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n", peer_id); 752 LOG_DEBUG ("Received PEER_GET_CONFIG for peer: %u\n",
753 peer_id);
723 config = 754 config =
724 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg, 755 GNUNET_CONFIGURATION_serialize (GST_peer_list[peer_id]->details.local.cfg,
725 &c_size); 756 &c_size);
726 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 757 xc_size = GNUNET_TESTBED_compress_config_ (config,
758 c_size,
759 &xconfig);
727 GNUNET_free (config); 760 GNUNET_free (config);
728 msize = 761 msize =
729 xc_size + 762 xc_size +
@@ -799,7 +832,8 @@ update_peer_config (struct Peer *peer,
799 emsg = NULL; 832 emsg = NULL;
800 peer->details.local.peer 833 peer->details.local.peer
801 = GNUNET_TESTING_peer_configure (GST_context->system, 834 = GNUNET_TESTING_peer_configure (GST_context->system,
802 peer->details.local.cfg, peer->id, 835 peer->details.local.cfg,
836 peer->id,
803 NULL /* Peer id */ , 837 NULL /* Peer id */ ,
804 &emsg); 838 &emsg);
805 return emsg; 839 return emsg;
@@ -811,11 +845,13 @@ update_peer_config (struct Peer *peer,
811 * 845 *
812 * @param cls the closure given to GNUNET_TESTING_peer_stop_async() 846 * @param cls the closure given to GNUNET_TESTING_peer_stop_async()
813 * @param p the respective peer whose status is being reported 847 * @param p the respective peer whose status is being reported
814 * @param success GNUNET_YES if the peer is stopped; GNUNET_SYSERR upon any 848 * @param success #GNUNET_YES if the peer is stopped; #GNUNET_SYSERR upon any
815 * error 849 * error
816 */ 850 */
817static void 851static void
818prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success) 852prc_stop_cb (void *cls,
853 struct GNUNET_TESTING_Peer *p,
854 int success)
819{ 855{
820 struct PeerReconfigureContext *prc = cls; 856 struct PeerReconfigureContext *prc = cls;
821 struct Peer *peer; 857 struct Peer *peer;
@@ -829,16 +865,20 @@ prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success)
829 prc->stopped = 1; 865 prc->stopped = 1;
830 if (NULL != emsg) 866 if (NULL != emsg)
831 { 867 {
832 GST_send_operation_fail_msg (prc->client, prc->op_id, emsg); 868 GST_send_operation_fail_msg (prc->client,
869 prc->op_id,
870 emsg);
833 goto cleanup; 871 goto cleanup;
834 } 872 }
835 if (GNUNET_OK != start_peer (peer)) 873 if (GNUNET_OK != start_peer (peer))
836 { 874 {
837 GST_send_operation_fail_msg (prc->client, prc->op_id, 875 GST_send_operation_fail_msg (prc->client,
876 prc->op_id,
838 "Failed to start reconfigured peer"); 877 "Failed to start reconfigured peer");
839 goto cleanup; 878 goto cleanup;
840 } 879 }
841 GST_send_operation_success_msg (prc->client, prc->op_id); 880 GST_send_operation_success_msg (prc->client,
881 prc->op_id);
842 882
843 cleanup: 883 cleanup:
844 cleanup_prc (prc); 884 cleanup_prc (prc);
@@ -847,7 +887,7 @@ prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success)
847 887
848 888
849/** 889/**
850 * Handler for GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages. 890 * Handler for #GNUNET_MESSAGE_TYPDE_TESTBED_RECONFIGURE_PEER type messages.
851 * Should stop the peer asyncronously, destroy it and create it again with the 891 * Should stop the peer asyncronously, destroy it and create it again with the
852 * new configuration. 892 * new configuration.
853 * 893 *
@@ -856,7 +896,8 @@ prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success)
856 * @param message the actual message 896 * @param message the actual message
857 */ 897 */
858void 898void
859GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client, 899GST_handle_peer_reconfigure (void *cls,
900 struct GNUNET_SERVER_Client *client,
860 const struct GNUNET_MessageHeader *message) 901 const struct GNUNET_MessageHeader *message)
861{ 902{
862 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg; 903 const struct GNUNET_TESTBED_PeerReconfigureMessage *msg;
@@ -873,7 +914,8 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
873 if (msize <= sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage)) 914 if (msize <= sizeof (struct GNUNET_TESTBED_PeerReconfigureMessage))
874 { 915 {
875 GNUNET_break_op (0); 916 GNUNET_break_op (0);
876 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 917 GNUNET_SERVER_receive_done (client,
918 GNUNET_SYSERR);
877 return; 919 return;
878 } 920 }
879 msg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) message; 921 msg = (const struct GNUNET_TESTBED_PeerReconfigureMessage *) message;
@@ -882,8 +924,11 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
882 if (!VALID_PEER_ID (peer_id)) 924 if (!VALID_PEER_ID (peer_id))
883 { 925 {
884 GNUNET_break (0); 926 GNUNET_break (0);
885 GST_send_operation_fail_msg (client, op_id, "Peer not found"); 927 GST_send_operation_fail_msg (client,
886 GNUNET_SERVER_receive_done (client, GNUNET_OK); 928 op_id,
929 "Peer not found");
930 GNUNET_SERVER_receive_done (client,
931 GNUNET_OK);
887 return; 932 return;
888 } 933 }
889 peer = GST_peer_list[peer_id]; 934 peer = GST_peer_list[peer_id];
@@ -898,60 +943,85 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
898 fopc->opc = 943 fopc->opc =
899 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. 944 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
900 slave->controller, 945 slave->controller,
901 fopc->operation_id, &msg->header, 946 fopc->operation_id,
947 &msg->header,
902 &GST_forwarded_operation_reply_relay, 948 &GST_forwarded_operation_reply_relay,
903 fopc); 949 fopc);
904 fopc->timeout_task = 950 fopc->timeout_task =
905 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 951 GNUNET_SCHEDULER_add_delayed (GST_timeout,
952 &GST_forwarded_operation_timeout,
953 fopc);
954 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
955 fopcq_tail,
906 fopc); 956 fopc);
907 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
908 GNUNET_SERVER_receive_done (client, GNUNET_OK); 957 GNUNET_SERVER_receive_done (client, GNUNET_OK);
909 return; 958 return;
910 } 959 }
911 LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n", peer_id); 960 LOG_DEBUG ("Received PEER_RECONFIGURE for peer %u\n",
961 (unsigned int) peer_id);
912 if (0 < peer->reference_cnt) 962 if (0 < peer->reference_cnt)
913 { 963 {
914 GNUNET_break (0); 964 GNUNET_break (0);
915 GST_send_operation_fail_msg (client, op_id, "Peer in use"); 965 GST_send_operation_fail_msg (client,
916 GNUNET_SERVER_receive_done (client, GNUNET_OK); 966 op_id,
967 "Peer in use");
968 GNUNET_SERVER_receive_done (client,
969 GNUNET_OK);
917 return; 970 return;
918 } 971 }
919 if (GNUNET_YES == peer->destroy_flag) 972 if (GNUNET_YES == peer->destroy_flag)
920 { 973 {
921 GNUNET_break (0); 974 GNUNET_break (0);
922 GST_send_operation_fail_msg (client, op_id, "Peer is being destroyed"); 975 GST_send_operation_fail_msg (client,
923 GNUNET_SERVER_receive_done (client, GNUNET_OK); 976 op_id,
977 "Peer is being destroyed");
978 GNUNET_SERVER_receive_done (client,
979 GNUNET_OK);
924 return; 980 return;
925 } 981 }
926 cfg = GNUNET_TESTBED_extract_config_ (message); 982 cfg = GNUNET_TESTBED_extract_config_ (message);
927 if (NULL == cfg) 983 if (NULL == cfg)
928 { 984 {
929 GNUNET_break (0); 985 GNUNET_break (0);
930 GST_send_operation_fail_msg (client, op_id, "Compression error"); 986 GST_send_operation_fail_msg (client,
931 GNUNET_SERVER_receive_done (client, GNUNET_OK); 987 op_id,
988 "Compression error");
989 GNUNET_SERVER_receive_done (client,
990 GNUNET_OK);
932 return; 991 return;
933 } 992 }
934 if (GNUNET_NO == peer->details.local.is_running) 993 if (GNUNET_NO == peer->details.local.is_running)
935 { 994 {
936 emsg = update_peer_config (peer, cfg); 995 emsg = update_peer_config (peer,
996 cfg);
937 if (NULL != emsg) 997 if (NULL != emsg)
938 GST_send_operation_fail_msg (client, op_id, emsg); 998 GST_send_operation_fail_msg (client,
939 GST_send_operation_success_msg (client, op_id); 999 op_id,
940 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1000 emsg);
1001 GST_send_operation_success_msg (client,
1002 op_id);
1003 GNUNET_SERVER_receive_done (client,
1004 GNUNET_OK);
941 GNUNET_free_non_null (emsg); 1005 GNUNET_free_non_null (emsg);
942 return; 1006 return;
943 } 1007 }
944 prc = GNUNET_new (struct PeerReconfigureContext); 1008 prc = GNUNET_new (struct PeerReconfigureContext);
945 if (GNUNET_OK != 1009 if (GNUNET_OK !=
946 GNUNET_TESTING_peer_stop_async (peer->details.local.peer, &prc_stop_cb, 1010 GNUNET_TESTING_peer_stop_async (peer->details.local.peer,
1011 &prc_stop_cb,
947 prc)) 1012 prc))
948 { 1013 {
949 GNUNET_assert (0 < GNUNET_asprintf (&emsg, 1014 GNUNET_assert (0 < GNUNET_asprintf (&emsg,
950 "Error trying to stop peer %u asynchronously\n", 1015 "Error trying to stop peer %u asynchronously\n",
951 peer_id)); 1016 peer_id));
952 LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); 1017 LOG (GNUNET_ERROR_TYPE_ERROR,
953 GST_send_operation_fail_msg (client, op_id, emsg); 1018 "%s\n",
954 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1019 emsg);
1020 GST_send_operation_fail_msg (client,
1021 op_id,
1022 emsg);
1023 GNUNET_SERVER_receive_done (client,
1024 GNUNET_OK);
955 GNUNET_free (prc); 1025 GNUNET_free (prc);
956 GNUNET_free (emsg); 1026 GNUNET_free (emsg);
957 return; 1027 return;
@@ -961,8 +1031,11 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client,
961 prc->op_id = op_id; 1031 prc->op_id = op_id;
962 prc->client = client; 1032 prc->client = client;
963 GNUNET_SERVER_client_keep (client); 1033 GNUNET_SERVER_client_keep (client);
964 GNUNET_CONTAINER_DLL_insert_tail (prc_head, prc_tail, prc); 1034 GNUNET_CONTAINER_DLL_insert_tail (prc_head,
965 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1035 prc_tail,
1036 prc);
1037 GNUNET_SERVER_receive_done (client,
1038 GNUNET_OK);
966} 1039}
967 1040
968 1041
@@ -975,14 +1048,17 @@ static void
975cleanup_mctx (struct ManageServiceContext *mctx) 1048cleanup_mctx (struct ManageServiceContext *mctx)
976{ 1049{
977 mctx->expired = GNUNET_YES; 1050 mctx->expired = GNUNET_YES;
978 GNUNET_CONTAINER_DLL_remove (mctx_head, mctx_tail, mctx); 1051 GNUNET_CONTAINER_DLL_remove (mctx_head,
1052 mctx_tail,
1053 mctx);
979 GNUNET_SERVER_client_drop (mctx->client); 1054 GNUNET_SERVER_client_drop (mctx->client);
980 GNUNET_ARM_disconnect_and_free (mctx->ah); 1055 GNUNET_ARM_disconnect (mctx->ah);
981 GNUNET_assert (0 < mctx->peer->reference_cnt); 1056 GNUNET_assert (0 < mctx->peer->reference_cnt);
982 mctx->peer->reference_cnt--; 1057 mctx->peer->reference_cnt--;
983 if ( (GNUNET_YES == mctx->peer->destroy_flag) 1058 if ( (GNUNET_YES == mctx->peer->destroy_flag)
984 && (0 == mctx->peer->reference_cnt) ) 1059 && (0 == mctx->peer->reference_cnt) )
985 GST_destroy_peer (mctx->peer); 1060 GST_destroy_peer (mctx->peer);
1061 GNUNET_free (mctx->service);
986 GNUNET_free (mctx); 1062 GNUNET_free (mctx);
987} 1063}
988 1064
@@ -999,7 +1075,7 @@ GST_free_mctxq ()
999 1075
1000 1076
1001/** 1077/**
1002 * Returns a string interpretation of 'rs' 1078 * Returns a string interpretation of @a rs.
1003 * 1079 *
1004 * @param rs the request status from ARM 1080 * @param rs the request status from ARM
1005 * @return a string interpretation of the request status 1081 * @return a string interpretation of the request status
@@ -1017,8 +1093,6 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs)
1017 return _("We disconnected from ARM before we could send a request"); 1093 return _("We disconnected from ARM before we could send a request");
1018 case GNUNET_ARM_REQUEST_BUSY: 1094 case GNUNET_ARM_REQUEST_BUSY:
1019 return _("ARM API is busy"); 1095 return _("ARM API is busy");
1020 case GNUNET_ARM_REQUEST_TOO_LONG:
1021 return _("Request doesn't fit into a message");
1022 case GNUNET_ARM_REQUEST_TIMEOUT: 1096 case GNUNET_ARM_REQUEST_TIMEOUT:
1023 return _("Request timed out"); 1097 return _("Request timed out");
1024 } 1098 }
@@ -1027,7 +1101,7 @@ arm_req_string (enum GNUNET_ARM_RequestStatus rs)
1027 1101
1028 1102
1029/** 1103/**
1030 * Returns a string interpretation of the 'result' 1104 * Returns a string interpretation of the @a result.
1031 * 1105 *
1032 * @param result the arm result 1106 * @param result the arm result
1033 * @return a string interpretation 1107 * @return a string interpretation
@@ -1066,17 +1140,16 @@ arm_ret_string (enum GNUNET_ARM_Result result)
1066 * Function called in response to a start/stop request. 1140 * Function called in response to a start/stop request.
1067 * Will be called when request was not sent successfully, 1141 * Will be called when request was not sent successfully,
1068 * or when a reply comes. If the request was not sent successfully, 1142 * or when a reply comes. If the request was not sent successfully,
1069 * 'rs' will indicate that, and 'service' and 'result' will be undefined. 1143 * @a rs will indicate that, and @a result will be undefined.
1070 * 1144 *
1071 * @param cls ManageServiceContext 1145 * @param cls ManageServiceContext
1072 * @param rs status of the request 1146 * @param rs status of the request
1073 * @param service service name
1074 * @param result result of the operation 1147 * @param result result of the operation
1075 */ 1148 */
1076static void 1149static void
1077service_manage_result_cb (void *cls, 1150service_manage_result_cb (void *cls,
1078 enum GNUNET_ARM_RequestStatus rs, 1151 enum GNUNET_ARM_RequestStatus rs,
1079 const char *service, enum GNUNET_ARM_Result result) 1152 enum GNUNET_ARM_Result result)
1080{ 1153{
1081 struct ManageServiceContext *mctx = cls; 1154 struct ManageServiceContext *mctx = cls;
1082 char *emsg; 1155 char *emsg;
@@ -1086,8 +1159,10 @@ service_manage_result_cb (void *cls,
1086 return; 1159 return;
1087 if (GNUNET_ARM_REQUEST_SENT_OK != rs) 1160 if (GNUNET_ARM_REQUEST_SENT_OK != rs)
1088 { 1161 {
1089 GNUNET_asprintf (&emsg, "Error communicating with Peer %u's ARM: %s", 1162 GNUNET_asprintf (&emsg,
1090 mctx->peer->id, arm_req_string (rs)); 1163 "Error communicating with Peer %u's ARM: %s",
1164 mctx->peer->id,
1165 arm_req_string (rs));
1091 goto ret; 1166 goto ret;
1092 } 1167 }
1093 if (1 == mctx->start) 1168 if (1 == mctx->start)
@@ -1098,7 +1173,9 @@ service_manage_result_cb (void *cls,
1098 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)) ) 1173 || (GNUNET_ARM_RESULT_IS_STOPPED_ALREADY == result)) )
1099 { 1174 {
1100 /* stopping a service failed */ 1175 /* stopping a service failed */
1101 GNUNET_asprintf (&emsg, arm_ret_string (result), service); 1176 GNUNET_asprintf (&emsg,
1177 arm_ret_string (result),
1178 mctx->service);
1102 goto ret; 1179 goto ret;
1103 } 1180 }
1104 /* service stopped successfully */ 1181 /* service stopped successfully */
@@ -1110,7 +1187,9 @@ service_manage_result_cb (void *cls,
1110 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)) ) 1187 || (GNUNET_ARM_RESULT_IS_STARTED_ALREADY == result)) )
1111 { 1188 {
1112 /* starting a service failed */ 1189 /* starting a service failed */
1113 GNUNET_asprintf (&emsg, arm_ret_string (result), service); 1190 GNUNET_asprintf (&emsg,
1191 arm_ret_string (result),
1192 mctx->service);
1114 goto ret; 1193 goto ret;
1115 } 1194 }
1116 /* service started successfully */ 1195 /* service started successfully */
@@ -1119,10 +1198,13 @@ service_manage_result_cb (void *cls,
1119 if (NULL != emsg) 1198 if (NULL != emsg)
1120 { 1199 {
1121 LOG_DEBUG ("%s\n", emsg); 1200 LOG_DEBUG ("%s\n", emsg);
1122 GST_send_operation_fail_msg (mctx->client, mctx->op_id, emsg); 1201 GST_send_operation_fail_msg (mctx->client,
1202 mctx->op_id,
1203 emsg);
1123 } 1204 }
1124 else 1205 else
1125 GST_send_operation_success_msg (mctx->client, mctx->op_id); 1206 GST_send_operation_success_msg (mctx->client,
1207 mctx->op_id);
1126 GNUNET_free_non_null (emsg); 1208 GNUNET_free_non_null (emsg);
1127 cleanup_mctx (mctx); 1209 cleanup_mctx (mctx);
1128} 1210}
@@ -1136,7 +1218,8 @@ service_manage_result_cb (void *cls,
1136 * @param message the actual message 1218 * @param message the actual message
1137 */ 1219 */
1138void 1220void
1139GST_handle_manage_peer_service (void *cls, struct GNUNET_SERVER_Client *client, 1221GST_handle_manage_peer_service (void *cls,
1222 struct GNUNET_SERVER_Client *client,
1140 const struct GNUNET_MessageHeader *message) 1223 const struct GNUNET_MessageHeader *message)
1141{ 1224{
1142 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg; 1225 const struct GNUNET_TESTBED_ManagePeerServiceMessage *msg;
@@ -1202,13 +1285,17 @@ GST_handle_manage_peer_service (void *cls, struct GNUNET_SERVER_Client *client,
1202 fopc->opc = 1285 fopc->opc =
1203 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote. 1286 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.
1204 slave->controller, 1287 slave->controller,
1205 fopc->operation_id, &msg->header, 1288 fopc->operation_id,
1289 &msg->header,
1206 &GST_forwarded_operation_reply_relay, 1290 &GST_forwarded_operation_reply_relay,
1207 fopc); 1291 fopc);
1208 fopc->timeout_task = 1292 fopc->timeout_task =
1209 GNUNET_SCHEDULER_add_delayed (GST_timeout, &GST_forwarded_operation_timeout, 1293 GNUNET_SCHEDULER_add_delayed (GST_timeout,
1294 &GST_forwarded_operation_timeout,
1295 fopc);
1296 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1297 fopcq_tail,
1210 fopc); 1298 fopc);
1211 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fopc);
1212 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1299 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1213 return; 1300 return;
1214 } 1301 }
@@ -1242,17 +1329,19 @@ GST_handle_manage_peer_service (void *cls, struct GNUNET_SERVER_Client *client,
1242 GNUNET_SERVER_client_keep (client); 1329 GNUNET_SERVER_client_keep (client);
1243 mctx->client = client; 1330 mctx->client = client;
1244 mctx->start = msg->start; 1331 mctx->start = msg->start;
1245 GNUNET_CONTAINER_DLL_insert_tail (mctx_head, mctx_tail, mctx); 1332 mctx->service = GNUNET_strdup (service);
1333 GNUNET_CONTAINER_DLL_insert_tail (mctx_head,
1334 mctx_tail,
1335 mctx);
1246 if (1 == mctx->start) 1336 if (1 == mctx->start)
1247 GNUNET_ARM_request_service_start (mctx->ah, service, 1337 GNUNET_ARM_request_service_start (mctx->ah,
1338 service,
1248 GNUNET_OS_INHERIT_STD_ERR, 1339 GNUNET_OS_INHERIT_STD_ERR,
1249 GST_timeout, 1340 &service_manage_result_cb,
1250 service_manage_result_cb,
1251 mctx); 1341 mctx);
1252 else 1342 else
1253 GNUNET_ARM_request_service_stop (mctx->ah, service, 1343 GNUNET_ARM_request_service_stop (mctx->ah, service,
1254 GST_timeout, 1344 &service_manage_result_cb,
1255 service_manage_result_cb,
1256 mctx); 1345 mctx);
1257 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1346 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1258 return; 1347 return;
@@ -1334,28 +1423,33 @@ shutdown_peers_reply_cb (void *cls,
1334 if (0 == hc->nslaves) 1423 if (0 == hc->nslaves)
1335 { 1424 {
1336 if (GNUNET_YES == hc->timeout) 1425 if (GNUNET_YES == hc->timeout)
1337 GST_send_operation_fail_msg (fo_ctxt->client, fo_ctxt->operation_id, 1426 GST_send_operation_fail_msg (fo_ctxt->client,
1427 fo_ctxt->operation_id,
1338 "Timeout at a slave controller"); 1428 "Timeout at a slave controller");
1339 else 1429 else
1340 GST_send_operation_success_msg (fo_ctxt->client, fo_ctxt->operation_id); 1430 GST_send_operation_success_msg (fo_ctxt->client,
1431 fo_ctxt->operation_id);
1341 GNUNET_free (hc); 1432 GNUNET_free (hc);
1342 hc = NULL; 1433 hc = NULL;
1343 } 1434 }
1344 GNUNET_SERVER_client_drop (fo_ctxt->client); 1435 GNUNET_SERVER_client_drop (fo_ctxt->client);
1345 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fo_ctxt); 1436 GNUNET_CONTAINER_DLL_remove (fopcq_head,
1437 fopcq_tail,
1438 fo_ctxt);
1346 GNUNET_free (fo_ctxt); 1439 GNUNET_free (fo_ctxt);
1347} 1440}
1348 1441
1349 1442
1350/** 1443/**
1351 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages 1444 * Handler for #GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS messages
1352 * 1445 *
1353 * @param cls NULL 1446 * @param cls NULL
1354 * @param client identification of the client 1447 * @param client identification of the client
1355 * @param message the actual message 1448 * @param message the actual message
1356 */ 1449 */
1357void 1450void
1358GST_handle_shutdown_peers (void *cls, struct GNUNET_SERVER_Client *client, 1451GST_handle_shutdown_peers (void *cls,
1452 struct GNUNET_SERVER_Client *client,
1359 const struct GNUNET_MessageHeader *message) 1453 const struct GNUNET_MessageHeader *message)
1360{ 1454{
1361 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg; 1455 const struct GNUNET_TESTBED_ShutdownPeersMessage *msg;
@@ -1398,14 +1492,18 @@ GST_handle_shutdown_peers (void *cls, struct GNUNET_SERVER_Client *client,
1398 &msg->header, 1492 &msg->header,
1399 shutdown_peers_reply_cb, 1493 shutdown_peers_reply_cb,
1400 fo_ctxt); 1494 fo_ctxt);
1401 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt); 1495 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head,
1496 fopcq_tail,
1497 fo_ctxt);
1402 } 1498 }
1403 LOG_DEBUG ("Shutting down peers\n"); 1499 LOG_DEBUG ("Shutting down peers\n");
1404 GST_destroy_peers (); 1500 GST_destroy_peers ();
1405 if (0 == hc->nslaves) 1501 if (0 == hc->nslaves)
1406 { 1502 {
1407 GST_send_operation_success_msg (client, op_id); 1503 GST_send_operation_success_msg (client,
1504 op_id);
1408 GNUNET_free (hc); 1505 GNUNET_free (hc);
1409 } 1506 }
1410 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1507 GNUNET_SERVER_receive_done (client,
1508 GNUNET_OK);
1411} 1509}