diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-31 15:29:32 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-31 15:29:32 +0000 |
commit | 2eb3cf57de7d06f53f1a4dbcdcadcad2c9c09e39 (patch) | |
tree | fde9fe16f606ffbbce44a14b7edc32f2235dc401 /src/testbed | |
parent | f432fb9c61777efc0369d71dae9df1ad7e81f1c0 (diff) | |
download | gnunet-2eb3cf57de7d06f53f1a4dbcdcadcad2c9c09e39.tar.gz gnunet-2eb3cf57de7d06f53f1a4dbcdcadcad2c9c09e39.zip |
peer destroy with new operations handling
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 32 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 75 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.h | 23 |
3 files changed, 66 insertions, 64 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index de64b3b49..cb7180882 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -224,18 +224,18 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
224 | const struct | 224 | const struct |
225 | GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) | 225 | GNUNET_TESTBED_GenericOperationSuccessEventMessage *msg) |
226 | { | 226 | { |
227 | struct GNUNET_TESTBED_Operation *op; | 227 | struct OperationContext *opc; |
228 | struct GNUNET_TESTBED_EventInformation *event; | 228 | struct GNUNET_TESTBED_EventInformation *event; |
229 | uint64_t op_id; | 229 | uint64_t op_id; |
230 | 230 | ||
231 | op_id = GNUNET_ntohll (msg->operation_id); | 231 | op_id = GNUNET_ntohll (msg->operation_id); |
232 | LOG_DEBUG ("Operation %ul successful\n", op_id); | 232 | LOG_DEBUG ("Operation %ul successful\n", op_id); |
233 | for (op = c->op_head; NULL != op; op = op->next) | 233 | for (opc = c->ocq_head; NULL != opc; opc = opc->next) |
234 | { | 234 | { |
235 | if (op->operation_id == op_id) | 235 | if (opc->id == op_id) |
236 | break; | 236 | break; |
237 | } | 237 | } |
238 | if (NULL == op) | 238 | if (NULL == opc) |
239 | { | 239 | { |
240 | LOG_DEBUG ("Operation not found\n"); | 240 | LOG_DEBUG ("Operation not found\n"); |
241 | return GNUNET_YES; | 241 | return GNUNET_YES; |
@@ -245,37 +245,29 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
245 | event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation)); | 245 | event = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_EventInformation)); |
246 | if (NULL != event) | 246 | if (NULL != event) |
247 | event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 247 | event->type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
248 | switch (op->type) | 248 | switch (opc->type) |
249 | { | 249 | { |
250 | case OP_PEER_DESTROY: | 250 | case OP_PEER_DESTROY: |
251 | { | 251 | { |
252 | struct PeerDestroyData *data; | 252 | struct GNUNET_TESTBED_Peer *peer; |
253 | 253 | ||
254 | if (NULL != event) | 254 | if (NULL != event) |
255 | { | 255 | { |
256 | event->details.operation_finished.operation = op; | 256 | event->details.operation_finished.operation = opc->op; |
257 | event->details.operation_finished.op_cls = NULL; | 257 | event->details.operation_finished.op_cls = NULL; |
258 | event->details.operation_finished.emsg = NULL; | 258 | event->details.operation_finished.emsg = NULL; |
259 | event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | 259 | event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; |
260 | event->details.operation_finished.op_result.generic = NULL; | 260 | event->details.operation_finished.op_result.generic = NULL; |
261 | } | 261 | } |
262 | data = (struct PeerDestroyData *) op->data; | 262 | peer = opc->data; |
263 | if (NULL != data->peer->details) | 263 | GNUNET_free (peer); |
264 | { | 264 | opc->data = NULL; |
265 | if (NULL != data->peer->details->cfg) | ||
266 | GNUNET_CONFIGURATION_destroy (data->peer->details->cfg); | ||
267 | //PEER_DETAILS | ||
268 | } | ||
269 | GNUNET_free (data->peer); | ||
270 | GNUNET_free (data); | ||
271 | op->data = NULL; | ||
272 | //PEERDESTROYDATA | 265 | //PEERDESTROYDATA |
273 | } | 266 | } |
274 | break; | 267 | break; |
275 | default: | 268 | default: |
276 | GNUNET_assert (0); | 269 | GNUNET_assert (0); |
277 | } | 270 | } |
278 | GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); | ||
279 | if (NULL != event) | 271 | if (NULL != event) |
280 | { | 272 | { |
281 | if (NULL != c->cc) | 273 | if (NULL != c->cc) |
@@ -1354,8 +1346,8 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1354 | GNUNET_TESTBED_operation_release_ (operation); | 1346 | GNUNET_TESTBED_operation_release_ (operation); |
1355 | return; | 1347 | return; |
1356 | case OP_PEER_DESTROY: | 1348 | case OP_PEER_DESTROY: |
1357 | GNUNET_free_non_null (operation->data); | 1349 | GNUNET_TESTBED_operation_release_ (operation); |
1358 | break; | 1350 | return; |
1359 | case OP_PEER_START: | 1351 | case OP_PEER_START: |
1360 | case OP_PEER_STOP: | 1352 | case OP_PEER_STOP: |
1361 | break; | 1353 | break; |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 3ecb38325..4f9fa768c 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -91,6 +91,48 @@ oprelease_peer_create (void *cls) | |||
91 | 91 | ||
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Function to called when a peer destroy operation is ready | ||
95 | * | ||
96 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
97 | */ | ||
98 | static void | ||
99 | opstart_peer_destroy (void *cls) | ||
100 | { | ||
101 | struct OperationContext *opc = cls; | ||
102 | struct GNUNET_TESTBED_Peer *peer; | ||
103 | struct GNUNET_TESTBED_PeerDestroyMessage *msg; | ||
104 | |||
105 | GNUNET_assert (OP_PEER_DESTROY == opc->type); | ||
106 | peer = opc->data; | ||
107 | GNUNET_assert (NULL != peer); | ||
108 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); | ||
109 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); | ||
110 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); | ||
111 | msg->peer_id = htonl (peer->unique_id); | ||
112 | msg->operation_id = GNUNET_htonll (opc->id); | ||
113 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, | ||
114 | opc->c->ocq_tail, opc); | ||
115 | GNUNET_TESTBED_queue_message_ (peer->controller, | ||
116 | (struct GNUNET_MessageHeader *) msg); | ||
117 | } | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Callback which will be called when peer_create type operation is released | ||
122 | * | ||
123 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
124 | */ | ||
125 | static void | ||
126 | oprelease_peer_destroy (void *cls) | ||
127 | { | ||
128 | struct OperationContext *opc = cls; | ||
129 | |||
130 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
131 | GNUNET_free (opc); | ||
132 | } | ||
133 | |||
134 | |||
135 | /** | ||
94 | * Lookup a peer by ID. | 136 | * Lookup a peer by ID. |
95 | * | 137 | * |
96 | * @param id global peer ID assigned to the peer | 138 | * @param id global peer ID assigned to the peer |
@@ -347,27 +389,18 @@ GNUNET_TESTBED_peer_update_configuration (struct GNUNET_TESTBED_Peer *peer, | |||
347 | struct GNUNET_TESTBED_Operation * | 389 | struct GNUNET_TESTBED_Operation * |
348 | GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) | 390 | GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer) |
349 | { | 391 | { |
350 | struct GNUNET_TESTBED_Operation *op; | 392 | struct OperationContext *opc; |
351 | struct PeerDestroyData *data; | 393 | |
352 | struct GNUNET_TESTBED_PeerDestroyMessage *msg; | 394 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
353 | 395 | opc->data = peer; | |
354 | data = GNUNET_malloc (sizeof (struct PeerDestroyData)); | 396 | opc->c = peer->controller; |
355 | data->peer = peer; | 397 | opc->id = peer->controller->operation_counter++; |
356 | op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); | 398 | opc->type = OP_PEER_DESTROY; |
357 | op->operation_id = peer->controller->operation_counter++; | 399 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_destroy, |
358 | op->controller = peer->controller; | 400 | &oprelease_peer_destroy); |
359 | op->type = OP_PEER_DESTROY; | 401 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, |
360 | op->data = data; | 402 | opc->op); |
361 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); | 403 | return opc->op; |
362 | msg->header.size = htons (sizeof (struct GNUNET_TESTBED_PeerDestroyMessage)); | ||
363 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_DESTROYPEER); | ||
364 | msg->peer_id = htonl (peer->unique_id); | ||
365 | msg->operation_id = GNUNET_htonll (op->operation_id); | ||
366 | GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head, | ||
367 | peer->controller->op_tail, op); | ||
368 | GNUNET_TESTBED_queue_message_ (peer->controller, | ||
369 | (struct GNUNET_MessageHeader *) msg); | ||
370 | return op; | ||
371 | } | 404 | } |
372 | 405 | ||
373 | 406 | ||
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index e7c1e9136..72c1c1b58 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h | |||
@@ -31,23 +31,6 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Details about a peer; kept in a separate struct to avoid bloating | ||
35 | * memory consumption everywhere... | ||
36 | */ | ||
37 | struct PeerDetails | ||
38 | { | ||
39 | /** | ||
40 | * Configuration of the peer; NULL if we are not sure what the peer's correct | ||
41 | * configuration actually is; non-NULL if this peer is controlled by this | ||
42 | * process. | ||
43 | */ | ||
44 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
45 | |||
46 | //PEER_DETAILS | ||
47 | }; | ||
48 | |||
49 | |||
50 | /** | ||
51 | * Enumeration of possible states a peer could be in | 34 | * Enumeration of possible states a peer could be in |
52 | */ | 35 | */ |
53 | enum PeerState | 36 | enum PeerState |
@@ -92,12 +75,6 @@ struct GNUNET_TESTBED_Peer | |||
92 | struct GNUNET_TESTBED_Host *host; | 75 | struct GNUNET_TESTBED_Host *host; |
93 | 76 | ||
94 | /** | 77 | /** |
95 | * Internals of the peer for the controlling process; NULL if | ||
96 | * this process is not controlling this peer. | ||
97 | */ | ||
98 | struct PeerDetails *details; | ||
99 | |||
100 | /** | ||
101 | * Globally unique ID of the peer. | 78 | * Globally unique ID of the peer. |
102 | */ | 79 | */ |
103 | uint32_t unique_id; | 80 | uint32_t unique_id; |