diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-25 16:42:42 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-01-25 16:42:42 +0000 |
commit | fe25fb0534c0a1cf363ac3588c18cad391907e34 (patch) | |
tree | 3d387e16086613570ff1a0c7e0fcfd3715c6a9c6 /src/testbed/gnunet-service-testbed_oc.c | |
parent | c948ca49394b18d53818e8870442d44390260837 (diff) | |
download | gnunet-fe25fb0534c0a1cf363ac3588c18cad391907e34.tar.gz gnunet-fe25fb0534c0a1cf363ac3588c18cad391907e34.zip |
bound overlay connect operation execution to limited number of open file descriptors
Diffstat (limited to 'src/testbed/gnunet-service-testbed_oc.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_oc.c | 124 |
1 files changed, 86 insertions, 38 deletions
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index 000e670b6..5beac2842 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c | |||
@@ -127,6 +127,11 @@ struct OverlayConnectContext | |||
127 | struct OperationContext *opc; | 127 | struct OperationContext *opc; |
128 | 128 | ||
129 | /** | 129 | /** |
130 | * The local operation we create for this overlay connection | ||
131 | */ | ||
132 | struct GNUNET_TESTBED_Operation *lop; | ||
133 | |||
134 | /** | ||
130 | * Controller of peer 2; NULL if the peer is local | 135 | * Controller of peer 2; NULL if the peer is local |
131 | */ | 136 | */ |
132 | struct GNUNET_TESTBED_Controller *peer2_controller; | 137 | struct GNUNET_TESTBED_Controller *peer2_controller; |
@@ -370,6 +375,11 @@ GST_process_next_focc (struct RegisteredHostContext *rhc) | |||
370 | static void | 375 | static void |
371 | cleanup_occ (struct OverlayConnectContext *occ) | 376 | cleanup_occ (struct OverlayConnectContext *occ) |
372 | { | 377 | { |
378 | if (NULL != occ->lop) | ||
379 | { | ||
380 | GNUNET_TESTBED_operation_release_ (occ->lop); | ||
381 | return; | ||
382 | } | ||
373 | LOG_DEBUG ("0x%llx: Cleaning up occ\n", occ->op_id); | 383 | LOG_DEBUG ("0x%llx: Cleaning up occ\n", occ->op_id); |
374 | GNUNET_free_non_null (occ->emsg); | 384 | GNUNET_free_non_null (occ->emsg); |
375 | GNUNET_free_non_null (occ->hello); | 385 | GNUNET_free_non_null (occ->hello); |
@@ -413,6 +423,7 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
413 | (0 == GST_peer_list[occ->other_peer_id]->reference_cnt)) | 423 | (0 == GST_peer_list[occ->other_peer_id]->reference_cnt)) |
414 | GST_destroy_peer (GST_peer_list[occ->other_peer_id]); | 424 | GST_destroy_peer (GST_peer_list[occ->other_peer_id]); |
415 | GNUNET_CONTAINER_DLL_remove (occq_head, occq_tail, occ); | 425 | GNUNET_CONTAINER_DLL_remove (occq_head, occq_tail, occ); |
426 | GNUNET_assert (NULL == occ->lop); | ||
416 | GNUNET_free (occ); | 427 | GNUNET_free (occ); |
417 | } | 428 | } |
418 | 429 | ||
@@ -445,6 +456,7 @@ timeout_overlay_connect (void *cls, | |||
445 | { | 456 | { |
446 | struct OverlayConnectContext *occ = cls; | 457 | struct OverlayConnectContext *occ = cls; |
447 | 458 | ||
459 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task); | ||
448 | occ->timeout_task = GNUNET_SCHEDULER_NO_TASK; | 460 | occ->timeout_task = GNUNET_SCHEDULER_NO_TASK; |
449 | LOG (GNUNET_ERROR_TYPE_WARNING, | 461 | LOG (GNUNET_ERROR_TYPE_WARNING, |
450 | "0x%llx: Timeout while connecting peers %u and %u\n", occ->op_id, | 462 | "0x%llx: Timeout while connecting peers %u and %u\n", occ->op_id, |
@@ -851,6 +863,58 @@ error_return: | |||
851 | 863 | ||
852 | 864 | ||
853 | /** | 865 | /** |
866 | * Callback which will be called when overlay connect operation is started | ||
867 | * | ||
868 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
869 | */ | ||
870 | static void | ||
871 | opstart_overlay_connect (void *cls) | ||
872 | { | ||
873 | struct OverlayConnectContext *occ = cls; | ||
874 | |||
875 | const struct GNUNET_CORE_MessageHandler no_handlers[] = { | ||
876 | {NULL, 0, 0} | ||
877 | }; | ||
878 | |||
879 | GNUNET_assert (NULL != occ->lop); | ||
880 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ | ||
881 | occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); | ||
882 | GNUNET_asprintf (&occ->emsg, | ||
883 | "0x%llx: Timeout while connecting to CORE of peer with " | ||
884 | "id: %u", occ->op_id, occ->peer_id); | ||
885 | occ->peer->reference_cnt++; | ||
886 | occ->ch = | ||
887 | GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, | ||
888 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, | ||
889 | GNUNET_NO, no_handlers); | ||
890 | if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task) | ||
891 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
892 | if (NULL == occ->ch) | ||
893 | occ->timeout_task = | ||
894 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
895 | else | ||
896 | occ->timeout_task = | ||
897 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_overlay_connect, occ); | ||
898 | } | ||
899 | |||
900 | |||
901 | /** | ||
902 | * Callback which will be called when overlay connect operation is released | ||
903 | * | ||
904 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
905 | */ | ||
906 | static void | ||
907 | oprelease_overlay_connect (void *cls) | ||
908 | { | ||
909 | struct OverlayConnectContext *occ = cls; | ||
910 | |||
911 | GNUNET_assert (NULL != occ->lop); | ||
912 | occ->lop = NULL; | ||
913 | cleanup_occ (occ); | ||
914 | } | ||
915 | |||
916 | |||
917 | /** | ||
854 | * Callback to be called when forwarded get peer config operation as part of | 918 | * Callback to be called when forwarded get peer config operation as part of |
855 | * overlay connect is successfull. Connection to Peer 1's core is made and is | 919 | * overlay connect is successfull. Connection to Peer 1's core is made and is |
856 | * checked for new connection from peer 2 | 920 | * checked for new connection from peer 2 |
@@ -864,32 +928,28 @@ overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg) | |||
864 | struct OverlayConnectContext *occ = cls; | 928 | struct OverlayConnectContext *occ = cls; |
865 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; | 929 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; |
866 | 930 | ||
867 | const struct GNUNET_CORE_MessageHandler no_handlers[] = { | ||
868 | {NULL, 0, 0} | ||
869 | }; | ||
870 | |||
871 | occ->opc = NULL; | 931 | occ->opc = NULL; |
872 | if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type)) | 932 | if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type)) |
873 | goto error_return; | 933 | { |
934 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
935 | occ->timeout_task = | ||
936 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
937 | } | ||
874 | cmsg = | 938 | cmsg = |
875 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; | 939 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; |
876 | memcpy (&occ->other_peer_identity, &cmsg->peer_identity, | 940 | memcpy (&occ->other_peer_identity, &cmsg->peer_identity, |
877 | sizeof (struct GNUNET_PeerIdentity)); | 941 | sizeof (struct GNUNET_PeerIdentity)); |
878 | GNUNET_free_non_null (occ->emsg); | 942 | GNUNET_free_non_null (occ->emsg); |
879 | GNUNET_asprintf (&occ->emsg, "0x%llx: Timeout while connecting to CORE", | 943 | occ->emsg = NULL; |
880 | occ->op_id); | 944 | GNUNET_assert (NULL == occ->lop); |
881 | occ->peer->reference_cnt++; | 945 | occ->lop = |
882 | occ->ch = | 946 | GNUNET_TESTBED_operation_create_ (occ, &opstart_overlay_connect, |
883 | GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, | 947 | &oprelease_overlay_connect); |
884 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, | 948 | /* This operation needs in total 2 connections (one to core and one to |
885 | GNUNET_NO, no_handlers); | 949 | * transport) */ |
886 | if (NULL == occ->ch) | 950 | GNUNET_TESTBED_operation_queue_insert2_ (GST_opq_openfds, occ->lop, 2); |
887 | goto error_return; | 951 | GNUNET_TESTBED_operation_begin_wait_ (occ->lop); |
888 | return; | 952 | return; |
889 | |||
890 | error_return: | ||
891 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
892 | occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
893 | } | 953 | } |
894 | 954 | ||
895 | 955 | ||
@@ -991,10 +1051,6 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
991 | const struct GNUNET_MessageHeader *message) | 1051 | const struct GNUNET_MessageHeader *message) |
992 | { | 1052 | { |
993 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; | 1053 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; |
994 | |||
995 | const struct GNUNET_CORE_MessageHandler no_handlers[] = { | ||
996 | {NULL, 0, 0} | ||
997 | }; | ||
998 | struct Peer *peer; | 1054 | struct Peer *peer; |
999 | struct OverlayConnectContext *occ; | 1055 | struct OverlayConnectContext *occ; |
1000 | struct GNUNET_TESTBED_Controller *peer2_controller; | 1056 | struct GNUNET_TESTBED_Controller *peer2_controller; |
@@ -1189,6 +1245,7 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1189 | GNUNET_asprintf (&occ->emsg, | 1245 | GNUNET_asprintf (&occ->emsg, |
1190 | "0x%llx: Timeout while getting peer identity of peer " | 1246 | "0x%llx: Timeout while getting peer identity of peer " |
1191 | "with id: %u", occ->op_id, occ->other_peer_id); | 1247 | "with id: %u", occ->op_id, occ->other_peer_id); |
1248 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->timeout_task); | ||
1192 | occ->timeout_task = | 1249 | occ->timeout_task = |
1193 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_overlay_connect, occ); | 1250 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_overlay_connect, occ); |
1194 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1251 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
@@ -1197,22 +1254,13 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1197 | GNUNET_TESTING_peer_get_identity (GST_peer_list[occ->other_peer_id]-> | 1254 | GNUNET_TESTING_peer_get_identity (GST_peer_list[occ->other_peer_id]-> |
1198 | details.local.peer, | 1255 | details.local.peer, |
1199 | &occ->other_peer_identity); | 1256 | &occ->other_peer_identity); |
1200 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ | 1257 | occ->lop = |
1201 | occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); | 1258 | GNUNET_TESTBED_operation_create_ (occ, &opstart_overlay_connect, |
1202 | GNUNET_asprintf (&occ->emsg, | 1259 | &oprelease_overlay_connect); |
1203 | "0x%llx: Timeout while connecting to CORE of peer with " | 1260 | /* This operation needs in total 2 connections (one to core and one to |
1204 | "id: %u", occ->op_id, occ->peer_id); | 1261 | * transport) */ |
1205 | occ->peer->reference_cnt++; | 1262 | GNUNET_TESTBED_operation_queue_insert2_ (GST_opq_openfds, occ->lop, 2); |
1206 | occ->ch = | 1263 | GNUNET_TESTBED_operation_begin_wait_ (occ->lop); |
1207 | GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, | ||
1208 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, | ||
1209 | GNUNET_NO, no_handlers); | ||
1210 | if (NULL == occ->ch) | ||
1211 | occ->timeout_task = | ||
1212 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
1213 | else | ||
1214 | occ->timeout_task = | ||
1215 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, &timeout_overlay_connect, occ); | ||
1216 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1264 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1217 | } | 1265 | } |
1218 | 1266 | ||