aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-10-19 13:47:57 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-10-19 13:47:57 +0000
commitcde891ff12dc3e7478ca0d8bab5e7d8fdd41c369 (patch)
tree5440b988ec57b476d1c96d71f23d3760757adbd5 /src
parentd3c4c4432ac9e6cfd29af424e752a9dfc5a6a389 (diff)
downloadgnunet-cde891ff12dc3e7478ca0d8bab5e7d8fdd41c369.tar.gz
gnunet-cde891ff12dc3e7478ca0d8bab5e7d8fdd41c369.zip
counting references in overlay connect context
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c77
-rw-r--r--src/testbed/test_testbed_api_topology.c6
-rw-r--r--src/testbed/testbed_api_topology.c2
3 files changed, 70 insertions, 15 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index a344dd87d..895ab34ca 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -2169,6 +2169,33 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
2169 2169
2170 2170
2171/** 2171/**
2172 * Function to destroy a peer
2173 *
2174 * @param the peer structure to destroy
2175 */
2176static void
2177destroy_peer (struct Peer *peer)
2178{
2179 GNUNET_break (0 == peer->reference_cnt);
2180 if (GNUNET_YES == peer->is_remote)
2181 {
2182 peer_list_remove (peer);
2183 GNUNET_free (peer);
2184 return;
2185 }
2186 if (GNUNET_YES == peer->details.local.is_running)
2187 {
2188 GNUNET_TESTING_peer_stop (peer->details.local.peer);
2189 peer->details.local.is_running = GNUNET_NO;
2190 }
2191 GNUNET_TESTING_peer_destroy (peer->details.local.peer);
2192 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
2193 peer_list_remove (peer);
2194 GNUNET_free (peer);
2195}
2196
2197
2198/**
2172 * Callback to be called when forwarded peer destroy operation is successfull. We 2199 * Callback to be called when forwarded peer destroy operation is successfull. We
2173 * have to relay the reply msg back to the client 2200 * have to relay the reply msg back to the client
2174 * 2201 *
@@ -2187,7 +2214,9 @@ peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
2187 { 2214 {
2188 remote_peer = fopc->cls; 2215 remote_peer = fopc->cls;
2189 GNUNET_assert (NULL != remote_peer); 2216 GNUNET_assert (NULL != remote_peer);
2190 peer_list_remove (remote_peer); 2217 remote_peer->destroy_flag = GNUNET_YES;
2218 if (0 == remote_peer->reference_cnt)
2219 destroy_peer (remote_peer);
2191 } 2220 }
2192 dup_msg = GNUNET_copy_message (msg); 2221 dup_msg = GNUNET_copy_message (msg);
2193 queue_message (fopc->client, dup_msg); 2222 queue_message (fopc->client, dup_msg);
@@ -2389,15 +2418,12 @@ handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2389 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2418 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2390 return; 2419 return;
2391 } 2420 }
2392 if (GNUNET_YES == peer->details.local.is_running) 2421 peer->destroy_flag = GNUNET_YES;
2393 { 2422 if (0 == peer->reference_cnt)
2394 GNUNET_TESTING_peer_stop (peer->details.local.peer); 2423 destroy_peer (peer);
2395 peer->details.local.is_running = GNUNET_NO; 2424 else
2396 } 2425 LOG (GNUNET_ERROR_TYPE_WARNING,
2397 GNUNET_TESTING_peer_destroy (peer->details.local.peer); 2426 "Delaying peer destroy as peer is currently in use\n");
2398 GNUNET_CONFIGURATION_destroy (peer->details.local.cfg);
2399 peer_list_remove (peer);
2400 GNUNET_free (peer);
2401 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id)); 2427 send_operation_success_msg (client, GNUNET_ntohll (msg->operation_id));
2402 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2428 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2403} 2429}
@@ -2625,13 +2651,28 @@ cleanup_occ (struct OverlayConnectContext *occ)
2625 if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task) 2651 if (GNUNET_SCHEDULER_NO_TASK != occ->timeout_task)
2626 GNUNET_SCHEDULER_cancel (occ->timeout_task); 2652 GNUNET_SCHEDULER_cancel (occ->timeout_task);
2627 if (NULL != occ->ch) 2653 if (NULL != occ->ch)
2654 {
2628 GNUNET_CORE_disconnect (occ->ch); 2655 GNUNET_CORE_disconnect (occ->ch);
2656 occ->peer->reference_cnt--;
2657 }
2629 if (NULL != occ->ghh) 2658 if (NULL != occ->ghh)
2630 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh); 2659 GNUNET_TRANSPORT_get_hello_cancel (occ->ghh);
2631 if (NULL != occ->p1th) 2660 if (NULL != occ->p1th)
2661 {
2632 GNUNET_TRANSPORT_disconnect (occ->p1th); 2662 GNUNET_TRANSPORT_disconnect (occ->p1th);
2663 occ->peer->reference_cnt--;
2664 }
2633 if (NULL != occ->p2th) 2665 if (NULL != occ->p2th)
2666 {
2634 GNUNET_TRANSPORT_disconnect (occ->p2th); 2667 GNUNET_TRANSPORT_disconnect (occ->p2th);
2668 peer_list[occ->other_peer_id]->reference_cnt--;
2669 if ((GNUNET_YES == peer_list[occ->other_peer_id]->destroy_flag)
2670 && (0 == peer_list[occ->other_peer_id]->reference_cnt))
2671 destroy_peer (peer_list[occ->other_peer_id]);
2672 }
2673 if ((GNUNET_YES == occ->peer->destroy_flag)
2674 && (0 == occ->peer->reference_cnt))
2675 destroy_peer (occ->peer);
2635 GNUNET_CONTAINER_DLL_remove (occq_head, occq_tail, occ); 2676 GNUNET_CONTAINER_DLL_remove (occq_head, occq_tail, occ);
2636 GNUNET_free (occ); 2677 GNUNET_free (occ);
2637} 2678}
@@ -2726,7 +2767,10 @@ overlay_connect_notify (void *cls, const struct GNUNET_PeerIdentity *new_peer,
2726 GNUNET_free_non_null (occ->emsg); 2767 GNUNET_free_non_null (occ->emsg);
2727 occ->emsg = NULL; 2768 occ->emsg = NULL;
2728 if (NULL != occ->p2th) 2769 if (NULL != occ->p2th)
2770 {
2729 GNUNET_TRANSPORT_disconnect (occ->p2th); 2771 GNUNET_TRANSPORT_disconnect (occ->p2th);
2772 peer_list[occ->other_peer_id]->reference_cnt--;
2773 }
2730 occ->p2th = NULL; 2774 occ->p2th = NULL;
2731 LOG_DEBUG ("Peers connected - Sending overlay connect success\n"); 2775 LOG_DEBUG ("Peers connected - Sending overlay connect success\n");
2732 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage)); 2776 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ConnectionEventMessage));
@@ -2847,9 +2891,11 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello)
2847 occ->ghh = NULL; 2891 occ->ghh = NULL;
2848 GNUNET_TRANSPORT_disconnect (occ->p1th); 2892 GNUNET_TRANSPORT_disconnect (occ->p1th);
2849 occ->p1th = NULL; 2893 occ->p1th = NULL;
2894 occ->peer->reference_cnt--;
2850 GNUNET_free_non_null (occ->emsg); 2895 GNUNET_free_non_null (occ->emsg);
2851 if (NULL == occ->peer2_controller) 2896 if (NULL == occ->peer2_controller)
2852 { 2897 {
2898 peer_list[occ->other_peer_id]->reference_cnt++;
2853 occ->p2th = 2899 occ->p2th =
2854 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg, 2900 GNUNET_TRANSPORT_connect (peer_list[occ->other_peer_id]->details.local.cfg,
2855 &occ->other_peer_identity, NULL, NULL, NULL, 2901 &occ->other_peer_identity, NULL, NULL, NULL,
@@ -2894,6 +2940,7 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server,
2894 occ->emsg = NULL; 2940 occ->emsg = NULL;
2895 memcpy (&occ->peer_identity, my_identity, 2941 memcpy (&occ->peer_identity, my_identity,
2896 sizeof (struct GNUNET_PeerIdentity)); 2942 sizeof (struct GNUNET_PeerIdentity));
2943 occ->peer->reference_cnt++;
2897 occ->p1th = 2944 occ->p1th =
2898 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg, 2945 GNUNET_TRANSPORT_connect (occ->peer->details.local.cfg,
2899 &occ->peer_identity, NULL, NULL, NULL, NULL); 2946 &occ->peer_identity, NULL, NULL, NULL, NULL);
@@ -2941,6 +2988,7 @@ overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg)
2941 sizeof (struct GNUNET_PeerIdentity)); 2988 sizeof (struct GNUNET_PeerIdentity));
2942 GNUNET_free_non_null (occ->emsg); 2989 GNUNET_free_non_null (occ->emsg);
2943 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); 2990 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
2991 occ->peer->reference_cnt++;
2944 occ->ch = 2992 occ->ch =
2945 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, 2993 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
2946 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, 2994 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
@@ -3091,12 +3139,16 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
3091 if ((NULL != route_to_peer2_host) 3139 if ((NULL != route_to_peer2_host)
3092 || (peer2_host_id == master_context->host_id)) 3140 || (peer2_host_id == master_context->host_id))
3093 { 3141 {
3142 /* Peer 2 either below us OR with us */
3094 route_to_peer1_host = 3143 route_to_peer1_host =
3095 find_dest_route (peer_list[p1]->details.remote.remote_host_id); 3144 find_dest_route (peer_list[p1]->details.remote.remote_host_id);
3145 /* Because we get this message only if we know where peer 1 is */
3096 GNUNET_assert (NULL != route_to_peer1_host); 3146 GNUNET_assert (NULL != route_to_peer1_host);
3097 if ((peer2_host_id == master_context->host_id) 3147 if ((peer2_host_id == master_context->host_id)
3098 || (route_to_peer2_host->dest != route_to_peer1_host->dest)) 3148 || (route_to_peer2_host->dest != route_to_peer1_host->dest))
3099 { 3149 {
3150 /* Peer2 is either with us OR peer1 and peer2 can be reached through
3151 different gateways */
3100 struct GNUNET_HashCode hash; 3152 struct GNUNET_HashCode hash;
3101 struct RegisteredHostContext *rhc; 3153 struct RegisteredHostContext *rhc;
3102 int skip_focc; 3154 int skip_focc;
@@ -3136,7 +3188,7 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
3136 } 3188 }
3137 else { 3189 else {
3138 /* rhc is now set to the existing one from the hash map by 3190 /* rhc is now set to the existing one from the hash map by
3139 reghost_match_iterator */ 3191 reghost_match_iterator() */
3140 /* if queue is empty then ignore creating focc and proceed with 3192 /* if queue is empty then ignore creating focc and proceed with
3141 normal forwarding */ 3193 normal forwarding */
3142 if (NULL == rhc->focc_dll_head) 3194 if (NULL == rhc->focc_dll_head)
@@ -3254,6 +3306,7 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
3254 &occ->other_peer_identity); 3306 &occ->other_peer_identity);
3255 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ 3307 /* Connect to the core of 1st peer and wait for the 2nd peer to connect */
3256 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); 3308 occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE");
3309 occ->peer->reference_cnt++;
3257 occ->ch = 3310 occ->ch =
3258 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, 3311 GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb,
3259 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, 3312 &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL,
diff --git a/src/testbed/test_testbed_api_topology.c b/src/testbed/test_testbed_api_topology.c
index 8e673d293..6d43e89ae 100644
--- a/src/testbed/test_testbed_api_topology.c
+++ b/src/testbed/test_testbed_api_topology.c
@@ -138,8 +138,10 @@ test_master (void *cls, unsigned int num_peers,
138 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI, 138 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
139 NUM_PEERS); 139 NUM_PEERS);
140 GNUNET_assert (NULL != op); 140 GNUNET_assert (NULL != op);
141 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 141 shutdown_task = GNUNET_SCHEDULER_add_delayed (//GNUNET_TIME_relative_multiply
142 (GNUNET_TIME_UNIT_SECONDS, 120), 142 //(GNUNET_TIME_UNIT_SECONDS,
143 //120),
144 GNUNET_TIME_UNIT_FOREVER_REL,
143 do_shutdown, NULL); 145 do_shutdown, NULL);
144} 146}
145 147
diff --git a/src/testbed/testbed_api_topology.c b/src/testbed/testbed_api_topology.c
index 0e237cde3..adef374db 100644
--- a/src/testbed/testbed_api_topology.c
+++ b/src/testbed/testbed_api_topology.c
@@ -94,7 +94,7 @@ struct TopologyContext
94 /** 94 /**
95 * The size of the link array 95 * The size of the link array
96 */ 96 */
97 unsigned int link_array_size; 97 unsigned int link_array_size;
98 98
99}; 99};
100 100