diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-10-08 09:46:43 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-10-08 09:46:43 +0000 |
commit | a0e0fd42ad49f1cd3972e78cc521bcfb67d7b6cb (patch) | |
tree | f8b6bbfbe5f96dd642d9b228b46fbd06e2f95d16 /src/testbed | |
parent | f9c608be4f7d14ec08f633cc26c8c5e5d78d8648 (diff) | |
download | gnunet-a0e0fd42ad49f1cd3972e78cc521bcfb67d7b6cb.tar.gz gnunet-a0e0fd42ad49f1cd3972e78cc521bcfb67d7b6cb.zip |
- fix peer reconfiguration when the peer is already stopped
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed_peers.c | 63 |
1 files changed, 51 insertions, 12 deletions
diff --git a/src/testbed/gnunet-service-testbed_peers.c b/src/testbed/gnunet-service-testbed_peers.c index 959229543..274360978 100644 --- a/src/testbed/gnunet-service-testbed_peers.c +++ b/src/testbed/gnunet-service-testbed_peers.c | |||
@@ -780,6 +780,32 @@ GST_free_prcq () | |||
780 | 780 | ||
781 | 781 | ||
782 | /** | 782 | /** |
783 | * Update peer configuration | ||
784 | * | ||
785 | * @param peer the peer to update | ||
786 | * @param cfg the new configuration | ||
787 | * @return error message (freshly allocated); NULL upon success | ||
788 | */ | ||
789 | static char * | ||
790 | update_peer_config (struct Peer *peer, | ||
791 | struct GNUNET_CONFIGURATION_Handle *cfg) | ||
792 | { | ||
793 | char *emsg; | ||
794 | |||
795 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | ||
796 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | ||
797 | peer->details.local.cfg = cfg; | ||
798 | emsg = NULL; | ||
799 | peer->details.local.peer | ||
800 | = GNUNET_TESTING_peer_configure (GST_context->system, | ||
801 | peer->details.local.cfg, peer->id, | ||
802 | NULL /* Peer id */ , | ||
803 | &emsg); | ||
804 | return emsg; | ||
805 | } | ||
806 | |||
807 | |||
808 | /** | ||
783 | * Callback to inform whether the peer is running or stopped. | 809 | * Callback to inform whether the peer is running or stopped. |
784 | * | 810 | * |
785 | * @param cls the closure given to GNUNET_TESTING_peer_stop_async() | 811 | * @param cls the closure given to GNUNET_TESTING_peer_stop_async() |
@@ -797,25 +823,16 @@ prc_stop_cb (void *cls, struct GNUNET_TESTING_Peer *p, int success) | |||
797 | GNUNET_assert (VALID_PEER_ID (prc->peer_id)); | 823 | GNUNET_assert (VALID_PEER_ID (prc->peer_id)); |
798 | peer = GST_peer_list [prc->peer_id]; | 824 | peer = GST_peer_list [prc->peer_id]; |
799 | GNUNET_assert (GNUNET_NO == peer->is_remote); | 825 | GNUNET_assert (GNUNET_NO == peer->is_remote); |
800 | GNUNET_TESTING_peer_destroy (peer->details.local.peer); | 826 | emsg = update_peer_config (peer, prc->cfg); |
801 | GNUNET_CONFIGURATION_destroy (peer->details.local.cfg); | ||
802 | peer->details.local.cfg = prc->cfg; | ||
803 | prc->cfg = NULL; | 827 | prc->cfg = NULL; |
804 | prc->stopped = 1; | 828 | prc->stopped = 1; |
805 | emsg = NULL; | 829 | if (NULL != emsg) |
806 | peer->details.local.peer | ||
807 | = GNUNET_TESTING_peer_configure (GST_context->system, | ||
808 | peer->details.local.cfg, peer->id, | ||
809 | NULL /* Peer id */ , | ||
810 | &emsg); | ||
811 | if (NULL == peer->details.local.peer) | ||
812 | { | 830 | { |
813 | GST_send_operation_fail_msg (prc->client, prc->op_id, emsg); | 831 | GST_send_operation_fail_msg (prc->client, prc->op_id, emsg); |
814 | goto cleanup; | 832 | goto cleanup; |
815 | } | 833 | } |
816 | if (GNUNET_OK != start_peer (peer)) | 834 | if (GNUNET_OK != start_peer (peer)) |
817 | { | 835 | { |
818 | |||
819 | GST_send_operation_fail_msg (prc->client, prc->op_id, | 836 | GST_send_operation_fail_msg (prc->client, prc->op_id, |
820 | "Failed to start reconfigured peer"); | 837 | "Failed to start reconfigured peer"); |
821 | goto cleanup; | 838 | goto cleanup; |
@@ -846,6 +863,7 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client, | |||
846 | struct GNUNET_CONFIGURATION_Handle *cfg; | 863 | struct GNUNET_CONFIGURATION_Handle *cfg; |
847 | struct ForwardedOperationContext *fopc; | 864 | struct ForwardedOperationContext *fopc; |
848 | struct PeerReconfigureContext *prc; | 865 | struct PeerReconfigureContext *prc; |
866 | char *emsg; | ||
849 | uint64_t op_id; | 867 | uint64_t op_id; |
850 | uint32_t peer_id; | 868 | uint32_t peer_id; |
851 | uint16_t msize; | 869 | uint16_t msize; |
@@ -912,14 +930,35 @@ GST_handle_peer_reconfigure (void *cls, struct GNUNET_SERVER_Client *client, | |||
912 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 930 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
913 | return; | 931 | return; |
914 | } | 932 | } |
933 | if (GNUNET_NO == peer->details.local.is_running) | ||
934 | { | ||
935 | emsg = update_peer_config (peer, cfg); | ||
936 | if (NULL != emsg) | ||
937 | GST_send_operation_fail_msg (client, op_id, emsg); | ||
938 | GST_send_operation_success_msg (client, op_id); | ||
939 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
940 | return; | ||
941 | } | ||
915 | prc = GNUNET_malloc (sizeof (struct PeerReconfigureContext)); | 942 | prc = GNUNET_malloc (sizeof (struct PeerReconfigureContext)); |
943 | if (GNUNET_OK != | ||
944 | GNUNET_TESTING_peer_stop_async (peer->details.local.peer, &prc_stop_cb, | ||
945 | prc)) | ||
946 | { | ||
947 | GNUNET_assert (0 < GNUNET_asprintf (&emsg, | ||
948 | "Error trying to stop peer %u asynchronously\n", | ||
949 | peer_id)); | ||
950 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s\n", emsg); | ||
951 | GST_send_operation_fail_msg (client, op_id, emsg); | ||
952 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
953 | GNUNET_free (prc); | ||
954 | return; | ||
955 | } | ||
916 | prc->cfg = cfg; | 956 | prc->cfg = cfg; |
917 | prc->peer_id = peer_id; | 957 | prc->peer_id = peer_id; |
918 | prc->op_id = op_id; | 958 | prc->op_id = op_id; |
919 | prc->client = client; | 959 | prc->client = client; |
920 | GNUNET_SERVER_client_keep (client); | 960 | GNUNET_SERVER_client_keep (client); |
921 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, prc_tail, prc); | 961 | GNUNET_CONTAINER_DLL_insert_tail (prc_head, prc_tail, prc); |
922 | GNUNET_TESTING_peer_stop_async (peer->details.local.peer, prc_stop_cb, prc); | ||
923 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 962 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
924 | } | 963 | } |
925 | 964 | ||