aboutsummaryrefslogtreecommitdiff
path: root/src/testbed
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-08-01 11:48:20 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-08-01 11:48:20 +0000
commitaeec4593b1ce3a32ad7df1ae0b778ad2cd699d3c (patch)
treeb890238c614c0246412af7104ae7ffa618da3af2 /src/testbed
parent4e952ed52de883f6ad4cc7f964d8a19171c4ac41 (diff)
downloadgnunet-aeec4593b1ce3a32ad7df1ae0b778ad2cd699d3c.tar.gz
gnunet-aeec4593b1ce3a32ad7df1ae0b778ad2cd699d3c.zip
state information for OperationContext
Diffstat (limited to 'src/testbed')
-rw-r--r--src/testbed/testbed_api.c22
-rw-r--r--src/testbed/testbed_api.h31
-rw-r--r--src/testbed/testbed_api_peers.c31
3 files changed, 65 insertions, 19 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c
index f8d8e11fc..11b70382c 100644
--- a/src/testbed/testbed_api.c
+++ b/src/testbed/testbed_api.c
@@ -261,7 +261,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
261 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 261 if (0 != (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
262 event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation)); 262 event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation));
263 if (NULL != event) 263 if (NULL != event)
264 event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; 264 event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED;
265 switch (opc->type) 265 switch (opc->type)
266 { 266 {
267 case OP_PEER_DESTROY: 267 case OP_PEER_DESTROY:
@@ -284,13 +284,15 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c,
284 break; 284 break;
285 default: 285 default:
286 GNUNET_assert (0); 286 GNUNET_assert (0);
287 } 287 }
288 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
289 opc->state = OPC_STATE_FINISHED;
288 if (NULL != event) 290 if (NULL != event)
289 { 291 {
290 if (NULL != c->cc) 292 if (NULL != c->cc)
291 c->cc (c->cc_cls, event); 293 c->cc (c->cc_cls, event);
292 GNUNET_free (event); 294 GNUNET_free (event);
293 } 295 }
294 return GNUNET_YES; 296 return GNUNET_YES;
295} 297}
296 298
@@ -332,7 +334,10 @@ handle_peer_create_success (struct GNUNET_TESTBED_Controller *c,
332 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id)); 334 GNUNET_assert (peer->unique_id == ntohl (msg->peer_id));
333 peer->state = PS_CREATED; 335 peer->state = PS_CREATED;
334 cb = data->cb; 336 cb = data->cb;
335 cls = data->cls; 337 cls = data->cls;
338 GNUNET_free (opc->data);
339 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
340 opc->state = OPC_STATE_FINISHED;
336 if (NULL != cb) 341 if (NULL != cb)
337 cb (cls, peer, NULL); 342 cb (cls, peer, NULL);
338 return GNUNET_YES; 343 return GNUNET_YES;
@@ -383,12 +388,14 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c,
383 default: 388 default:
384 GNUNET_assert (0); /* We should never reach this state */ 389 GNUNET_assert (0); /* We should never reach this state */
385 } 390 }
391 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
392 opc->state = OPC_STATE_FINISHED;
386 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP) 393 if (0 != ((GNUNET_TESTBED_ET_PEER_START | GNUNET_TESTBED_ET_PEER_STOP)
387 & c->event_mask)) 394 & c->event_mask))
388 { 395 {
389 if (NULL != c->cc) 396 if (NULL != c->cc)
390 c->cc (c->cc_cls, &event); 397 c->cc (c->cc_cls, &event);
391 } 398 }
392 return GNUNET_YES; 399 return GNUNET_YES;
393} 400}
394 401
@@ -424,7 +431,6 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
424 peer = data->peer; 431 peer = data->peer;
425 GNUNET_assert (NULL != peer); 432 GNUNET_assert (NULL != peer);
426 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); 433 GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id);
427 opc->completed = GNUNET_YES;
428 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) 434 if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED)))
429 { 435 {
430 LOG_DEBUG ("Skipping operation callback as flag not set\n"); 436 LOG_DEBUG ("Skipping operation callback as flag not set\n");
@@ -482,7 +488,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c,
482 break; 488 break;
483 } 489 }
484 opc->data = response_data; 490 opc->data = response_data;
485 c->cc (c->cc_cls, &info); 491 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
492 opc->state = OPC_STATE_FINISHED;
493 c->cc (c->cc_cls, &info);
486 return GNUNET_YES; 494 return GNUNET_YES;
487} 495}
488 496
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h
index bacb53bb1..4e73c63af 100644
--- a/src/testbed/testbed_api.h
+++ b/src/testbed/testbed_api.h
@@ -113,6 +113,32 @@ struct MessageQueue;
113 */ 113 */
114struct ControllerLink; 114struct ControllerLink;
115 115
116
117/**
118 * Enumeration of states of OperationContext
119 */
120enum OperationContextState
121 {
122 /**
123 * The initial state where the associated operation has just been created
124 * and is waiting in the operation queues to be started
125 */
126 OPC_STATE_INIT = 0,
127
128 /**
129 * The operation has been started. It may occupy some resources which are to
130 * be freed if cancelled.
131 */
132 OPC_STATE_STARTED,
133
134 /**
135 * The operation has finished. The end results of this operation may occupy
136 * some resources which are to be freed by operation_done
137 */
138 OPC_STATE_FINISHED
139 };
140
141
116/** 142/**
117 * Context information for GNUNET_TESTBED_Operation 143 * Context information for GNUNET_TESTBED_Operation
118 */ 144 */
@@ -154,10 +180,9 @@ struct OperationContext
154 enum OperationType type; 180 enum OperationType type;
155 181
156 /** 182 /**
157 * Is this operation completed? (has there been a reply from the service) 183 * The state of the operation
158 */ 184 */
159 int completed; 185 enum OperationContextState state;
160
161}; 186};
162 187
163 188
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c
index b30e2a92c..69c3aaac8 100644
--- a/src/testbed/testbed_api_peers.c
+++ b/src/testbed/testbed_api_peers.c
@@ -54,6 +54,7 @@ opstart_peer_create (void *cls)
54 data = opc->data; 54 data = opc->data;
55 GNUNET_assert (NULL != data); 55 GNUNET_assert (NULL != data);
56 GNUNET_assert (NULL != data->peer); 56 GNUNET_assert (NULL != data->peer);
57 opc->state = OPC_STATE_STARTED;
57 config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size); 58 config = GNUNET_CONFIGURATION_serialize (data->cfg, &c_size);
58 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig); 59 xc_size = GNUNET_TESTBED_compress_config_ (config, c_size, &xconfig);
59 GNUNET_free (config); 60 GNUNET_free (config);
@@ -83,9 +84,12 @@ oprelease_peer_create (void *cls)
83{ 84{
84 struct OperationContext *opc = cls; 85 struct OperationContext *opc = cls;
85 86
86 GNUNET_assert (NULL != opc->data); 87 if (OPC_STATE_FINISHED != opc->state)
87 GNUNET_free (opc->data); 88 {
88 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 89 GNUNET_free (((struct PeerCreateData *) opc->data)->peer);
90 GNUNET_free (opc->data);
91 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
92 }
89 GNUNET_free (opc); 93 GNUNET_free (opc);
90} 94}
91 95
@@ -105,6 +109,7 @@ opstart_peer_destroy (void *cls)
105 GNUNET_assert (OP_PEER_DESTROY == opc->type); 109 GNUNET_assert (OP_PEER_DESTROY == opc->type);
106 peer = opc->data; 110 peer = opc->data;
107 GNUNET_assert (NULL != peer); 111 GNUNET_assert (NULL != peer);
112 opc->state = OPC_STATE_STARTED;
108 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); 113 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
109 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); 114 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage));
110 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); 115 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER);
@@ -126,7 +131,8 @@ oprelease_peer_destroy (void *cls)
126{ 131{
127 struct OperationContext *opc = cls; 132 struct OperationContext *opc = cls;
128 133
129 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 134 if (OPC_STATE_FINISHED != opc->state)
135 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
130 GNUNET_free (opc); 136 GNUNET_free (opc);
131} 137}
132 138
@@ -147,6 +153,7 @@ opstart_peer_start (void *cls)
147 GNUNET_assert (NULL != opc->data); 153 GNUNET_assert (NULL != opc->data);
148 peer = opc->data; 154 peer = opc->data;
149 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state)); 155 GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state));
156 opc->state = OPC_STATE_STARTED;
150 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 157 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
151 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); 158 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStartMessage));
152 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER); 159 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STARTPEER);
@@ -167,7 +174,8 @@ oprelease_peer_start (void *cls)
167{ 174{
168 struct OperationContext *opc = cls; 175 struct OperationContext *opc = cls;
169 176
170 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 177 if (OPC_STATE_FINISHED != opc->state)
178 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
171 GNUNET_free (opc); 179 GNUNET_free (opc);
172} 180}
173 181
@@ -187,6 +195,7 @@ opstart_peer_stop (void *cls)
187 GNUNET_assert (NULL != opc->data); 195 GNUNET_assert (NULL != opc->data);
188 peer = opc->data; 196 peer = opc->data;
189 GNUNET_assert (PS_STARTED == peer->state); 197 GNUNET_assert (PS_STARTED == peer->state);
198 opc->state = OPC_STATE_STARTED;
190 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 199 msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
191 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER); 200 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_STOPPEER);
192 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); 201 msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerStopMessage));
@@ -207,7 +216,8 @@ oprelease_peer_stop (void *cls)
207{ 216{
208 struct OperationContext *opc = cls; 217 struct OperationContext *opc = cls;
209 218
210 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); 219 if (OPC_STATE_FINISHED != opc->state)
220 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
211 GNUNET_free (opc); 221 GNUNET_free (opc);
212} 222}
213 223
@@ -225,7 +235,8 @@ opstart_peer_getinfo (void *cls)
225 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; 235 struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg;
226 236
227 data = opc->data; 237 data = opc->data;
228 GNUNET_assert (NULL != data); 238 GNUNET_assert (NULL != data);
239 opc->state = OPC_STATE_STARTED;
229 msg = GNUNET_malloc (sizeof (struct 240 msg = GNUNET_malloc (sizeof (struct
230 GNUNET_TESTBED_PeerGetConfigurationMessage)); 241 GNUNET_TESTBED_PeerGetConfigurationMessage));
231 msg->header.size = htons 242 msg->header.size = htons
@@ -249,8 +260,11 @@ oprelease_peer_getinfo (void *cls)
249 struct OperationContext *opc = cls; 260 struct OperationContext *opc = cls;
250 struct PeerInfoData2 *data; 261 struct PeerInfoData2 *data;
251 262
252 if (GNUNET_YES != opc->completed) 263 if (OPC_STATE_FINISHED != opc->state)
264 {
253 GNUNET_free_non_null (opc->data); 265 GNUNET_free_non_null (opc->data);
266 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
267 }
254 else 268 else
255 { 269 {
256 data = opc->data; 270 data = opc->data;
@@ -268,7 +282,6 @@ oprelease_peer_getinfo (void *cls)
268 } 282 }
269 GNUNET_free (data); 283 GNUNET_free (data);
270 } 284 }
271 GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc);
272 GNUNET_free (opc); 285 GNUNET_free (opc);
273} 286}
274 287