aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-service-testbed.c
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2013-03-11 15:11:37 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2013-03-11 15:11:37 +0000
commit2df86b1055927d16231dba350416d217306b7e8d (patch)
treead6086154033551213d04b286db4fb6564340a60 /src/testbed/gnunet-service-testbed.c
parent2b869471ca92027e0ffa1d8180585055d7698762 (diff)
downloadgnunet-2df86b1055927d16231dba350416d217306b7e8d.tar.gz
gnunet-2df86b1055927d16231dba350416d217306b7e8d.zip
- fix crash after handling SHUTDOWN_PEERS due to forwarded operations using `GST_peer_list'
Diffstat (limited to 'src/testbed/gnunet-service-testbed.c')
-rw-r--r--src/testbed/gnunet-service-testbed.c119
1 files changed, 66 insertions, 53 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index e7e0a5d40..eae4784b5 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -29,6 +29,25 @@
29#include <zlib.h> 29#include <zlib.h>
30 30
31 31
32/**
33 * Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler
34 */
35struct HandlerContext_ShutdownPeers
36{
37 /**
38 * The number of slave we expect to hear from since we forwarded the
39 * GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them
40 */
41 unsigned int nslaves;
42
43 /**
44 * Did we observe a timeout with respect to this operation at any of the
45 * slaves
46 */
47 int timeout;
48};
49
50
32/***********/ 51/***********/
33/* Globals */ 52/* Globals */
34/***********/ 53/***********/
@@ -1973,22 +1992,49 @@ handle_slave_get_config (void *cls, struct GNUNET_SERVER_Client *client,
1973 1992
1974 1993
1975/** 1994/**
1976 * Context data for GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS handler 1995 * Clears the forwarded operations queue
1977 */ 1996 */
1978struct HandlerContext_ShutdownPeers 1997static void
1998clear_fopcq ()
1979{ 1999{
1980 /** 2000 struct ForwardedOperationContext *fopc;
1981 * The number of slave we expect to hear from since we forwarded the 2001
1982 * GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS message to them 2002 while (NULL != (fopc = fopcq_head))
1983 */ 2003 {
1984 unsigned int nslaves; 2004 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
1985 2005 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
1986 /** 2006 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
1987 * Did we observe a timeout with respect to this operation at any of the 2007 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
1988 * slaves 2008 GNUNET_SERVER_client_drop (fopc->client);
1989 */ 2009 switch (fopc->type)
1990 int timeout; 2010 {
1991}; 2011 case OP_PEER_CREATE:
2012 GNUNET_free (fopc->cls);
2013 break;
2014 case OP_SHUTDOWN_PEERS:
2015 {
2016 struct HandlerContext_ShutdownPeers *hc = fopc->cls;
2017
2018 GNUNET_assert (0 < hc->nslaves);
2019 hc->nslaves--;
2020 if (0 == hc->nslaves)
2021 GNUNET_free (hc);
2022 }
2023 break;
2024 case OP_PEER_START:
2025 case OP_PEER_STOP:
2026 case OP_PEER_DESTROY:
2027 case OP_PEER_INFO:
2028 case OP_OVERLAY_CONNECT:
2029 case OP_LINK_CONTROLLERS:
2030 case OP_GET_SLAVE_CONFIG:
2031 break;
2032 case OP_FORWARDED:
2033 GNUNET_assert (0);
2034 };
2035 GNUNET_free (fopc);
2036 }
2037}
1992 2038
1993 2039
1994/** 2040/**
@@ -2098,6 +2144,7 @@ destroy_peers ()
2098 } 2144 }
2099 GNUNET_free_non_null (GST_peer_list); 2145 GNUNET_free_non_null (GST_peer_list);
2100 GST_peer_list = NULL; 2146 GST_peer_list = NULL;
2147 GST_peer_list_size = 0;
2101} 2148}
2102 2149
2103 2150
@@ -2121,6 +2168,10 @@ handle_shutdown_peers (void *cls, struct GNUNET_SERVER_Client *client,
2121 2168
2122 msg = (const struct GNUNET_TESTBED_ShutdownPeersMessage *) message; 2169 msg = (const struct GNUNET_TESTBED_ShutdownPeersMessage *) message;
2123 LOG_DEBUG ("Received SHUTDOWN_PEERS\n"); 2170 LOG_DEBUG ("Received SHUTDOWN_PEERS\n");
2171 /* Stop and destroy all peers */
2172 GST_free_occq ();
2173 GST_free_roccq ();
2174 clear_fopcq ();
2124 /* Forward to all slaves which we have started */ 2175 /* Forward to all slaves which we have started */
2125 op_id = GNUNET_ntohll (msg->operation_id); 2176 op_id = GNUNET_ntohll (msg->operation_id);
2126 hc = GNUNET_malloc (sizeof (struct HandlerContext_ShutdownPeers)); 2177 hc = GNUNET_malloc (sizeof (struct HandlerContext_ShutdownPeers));
@@ -2153,9 +2204,6 @@ handle_shutdown_peers (void *cls, struct GNUNET_SERVER_Client *client,
2153 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt); 2204 GNUNET_CONTAINER_DLL_insert_tail (fopcq_head, fopcq_tail, fo_ctxt);
2154 } 2205 }
2155 LOG_DEBUG ("Shutting down peers\n"); 2206 LOG_DEBUG ("Shutting down peers\n");
2156 /* Stop and destroy all peers */
2157 GST_free_occq ();
2158 GST_free_roccq ();
2159 destroy_peers (); 2207 destroy_peers ();
2160 if (0 == hc->nslaves) 2208 if (0 == hc->nslaves)
2161 { 2209 {
@@ -2234,7 +2282,6 @@ static void
2234shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 2282shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2235{ 2283{
2236 struct LCFContextQueue *lcfq; 2284 struct LCFContextQueue *lcfq;
2237 struct ForwardedOperationContext *fopc;
2238 struct MessageQueue *mq_entry; 2285 struct MessageQueue *mq_entry;
2239 uint32_t id; 2286 uint32_t id;
2240 2287
@@ -2244,41 +2291,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2244 NULL); 2291 NULL);
2245 GNUNET_CONTAINER_multihashmap_destroy (ss_map); 2292 GNUNET_CONTAINER_multihashmap_destroy (ss_map);
2246 /* cleanup any remaining forwarded operations */ 2293 /* cleanup any remaining forwarded operations */
2247 while (NULL != (fopc = fopcq_head)) 2294 clear_fopcq ();
2248 {
2249 GNUNET_CONTAINER_DLL_remove (fopcq_head, fopcq_tail, fopc);
2250 GNUNET_TESTBED_forward_operation_msg_cancel_ (fopc->opc);
2251 if (GNUNET_SCHEDULER_NO_TASK != fopc->timeout_task)
2252 GNUNET_SCHEDULER_cancel (fopc->timeout_task);
2253 GNUNET_SERVER_client_drop (fopc->client);
2254 switch (fopc->type)
2255 {
2256 case OP_PEER_CREATE:
2257 GNUNET_free (fopc->cls);
2258 break;
2259 case OP_SHUTDOWN_PEERS:
2260 {
2261 struct HandlerContext_ShutdownPeers *hc = fopc->cls;
2262
2263 GNUNET_assert (0 < hc->nslaves);
2264 hc->nslaves--;
2265 if (0 == hc->nslaves)
2266 GNUNET_free (hc);
2267 }
2268 break;
2269 case OP_PEER_START:
2270 case OP_PEER_STOP:
2271 case OP_PEER_DESTROY:
2272 case OP_PEER_INFO:
2273 case OP_OVERLAY_CONNECT:
2274 case OP_LINK_CONTROLLERS:
2275 case OP_GET_SLAVE_CONFIG:
2276 break;
2277 case OP_FORWARDED:
2278 GNUNET_assert (0);
2279 };
2280 GNUNET_free (fopc);
2281 }
2282 if (NULL != lcfq_head) 2295 if (NULL != lcfq_head)
2283 { 2296 {
2284 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id) 2297 if (GNUNET_SCHEDULER_NO_TASK != lcf_proc_task_id)