diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-09 13:46:21 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-09 13:46:21 +0000 |
commit | e418b158990b8368d4577edc17c75683bb9e087c (patch) | |
tree | 94c970fb413547cc24e1d7f12d9949caae704d6c /src/testbed | |
parent | 2db24ba3a4dc97e08c9eb2c3d0723ab445dcf0c3 (diff) | |
download | gnunet-e418b158990b8368d4577edc17c75683bb9e087c.tar.gz gnunet-e418b158990b8368d4577edc17c75683bb9e087c.zip |
implemented continuations to testbed peer start/stop API
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 12 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 34 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.h | 23 |
3 files changed, 61 insertions, 8 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 665c19486..d83793ac5 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -410,6 +410,9 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c, | |||
410 | { | 410 | { |
411 | struct OperationContext *opc; | 411 | struct OperationContext *opc; |
412 | struct GNUNET_TESTBED_Peer *peer; | 412 | struct GNUNET_TESTBED_Peer *peer; |
413 | struct PeerEventData *data; | ||
414 | GNUNET_TESTBED_PeerChurnCallback pcc; | ||
415 | void *pcc_cls; | ||
413 | struct GNUNET_TESTBED_EventInformation event; | 416 | struct GNUNET_TESTBED_EventInformation event; |
414 | uint64_t op_id; | 417 | uint64_t op_id; |
415 | 418 | ||
@@ -434,7 +437,9 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c, | |||
434 | return GNUNET_YES; | 437 | return GNUNET_YES; |
435 | } | 438 | } |
436 | GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); | 439 | GNUNET_assert ((OP_PEER_START == opc->type) || (OP_PEER_STOP == opc->type)); |
437 | peer = opc->data; | 440 | data = opc->data; |
441 | GNUNET_assert (NULL != data); | ||
442 | peer = data->peer; | ||
438 | GNUNET_assert (NULL != peer); | 443 | GNUNET_assert (NULL != peer); |
439 | event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); | 444 | event.type = (enum GNUNET_TESTBED_EventType) ntohl (msg->event_type); |
440 | switch (event.type) | 445 | switch (event.type) |
@@ -451,6 +456,9 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c, | |||
451 | default: | 456 | default: |
452 | GNUNET_assert (0); /* We should never reach this state */ | 457 | GNUNET_assert (0); /* We should never reach this state */ |
453 | } | 458 | } |
459 | pcc = data->pcc; | ||
460 | pcc_cls = data->pcc_cls; | ||
461 | GNUNET_free (data); | ||
454 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 462 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
455 | opc->state = OPC_STATE_FINISHED; | 463 | opc->state = OPC_STATE_FINISHED; |
456 | if (0 != | 464 | if (0 != |
@@ -460,6 +468,8 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c, | |||
460 | if (NULL != c->cc) | 468 | if (NULL != c->cc) |
461 | c->cc (c->cc_cls, &event); | 469 | c->cc (c->cc_cls, &event); |
462 | } | 470 | } |
471 | if (NULL != pcc) | ||
472 | pcc (pcc_cls, NULL); | ||
463 | return GNUNET_YES; | 473 | return GNUNET_YES; |
464 | } | 474 | } |
465 | 475 | ||
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 86bc6f2e2..fef701f91 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -146,11 +146,14 @@ opstart_peer_start (void *cls) | |||
146 | { | 146 | { |
147 | struct OperationContext *opc = cls; | 147 | struct OperationContext *opc = cls; |
148 | struct GNUNET_TESTBED_PeerStartMessage *msg; | 148 | struct GNUNET_TESTBED_PeerStartMessage *msg; |
149 | struct PeerEventData *data; | ||
149 | struct GNUNET_TESTBED_Peer *peer; | 150 | struct GNUNET_TESTBED_Peer *peer; |
150 | 151 | ||
151 | GNUNET_assert (OP_PEER_START == opc->type); | 152 | GNUNET_assert (OP_PEER_START == opc->type); |
152 | GNUNET_assert (NULL != opc->data); | 153 | GNUNET_assert (NULL != opc->data); |
153 | peer = opc->data; | 154 | data = opc->data; |
155 | GNUNET_assert (NULL != data->peer); | ||
156 | peer = data->peer; | ||
154 | GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state)); | 157 | GNUNET_assert ((PS_CREATED == peer->state) || (PS_STOPPED == peer->state)); |
155 | opc->state = OPC_STATE_STARTED; | 158 | opc->state = OPC_STATE_STARTED; |
156 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); | 159 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStartMessage)); |
@@ -174,7 +177,10 @@ oprelease_peer_start (void *cls) | |||
174 | struct OperationContext *opc = cls; | 177 | struct OperationContext *opc = cls; |
175 | 178 | ||
176 | if (OPC_STATE_FINISHED != opc->state) | 179 | if (OPC_STATE_FINISHED != opc->state) |
180 | { | ||
181 | GNUNET_free (opc->data); | ||
177 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 182 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
183 | } | ||
178 | GNUNET_free (opc); | 184 | GNUNET_free (opc); |
179 | } | 185 | } |
180 | 186 | ||
@@ -189,10 +195,13 @@ opstart_peer_stop (void *cls) | |||
189 | { | 195 | { |
190 | struct OperationContext *opc = cls; | 196 | struct OperationContext *opc = cls; |
191 | struct GNUNET_TESTBED_PeerStopMessage *msg; | 197 | struct GNUNET_TESTBED_PeerStopMessage *msg; |
198 | struct PeerEventData *data; | ||
192 | struct GNUNET_TESTBED_Peer *peer; | 199 | struct GNUNET_TESTBED_Peer *peer; |
193 | 200 | ||
194 | GNUNET_assert (NULL != opc->data); | 201 | GNUNET_assert (NULL != opc->data); |
195 | peer = opc->data; | 202 | data = opc->data; |
203 | GNUNET_assert (NULL != data->peer); | ||
204 | peer = data->peer; | ||
196 | GNUNET_assert (PS_STARTED == peer->state); | 205 | GNUNET_assert (PS_STARTED == peer->state); |
197 | opc->state = OPC_STATE_STARTED; | 206 | opc->state = OPC_STATE_STARTED; |
198 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); | 207 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerStopMessage)); |
@@ -216,7 +225,10 @@ oprelease_peer_stop (void *cls) | |||
216 | struct OperationContext *opc = cls; | 225 | struct OperationContext *opc = cls; |
217 | 226 | ||
218 | if (OPC_STATE_FINISHED != opc->state) | 227 | if (OPC_STATE_FINISHED != opc->state) |
228 | { | ||
229 | GNUNET_free (opc->data); | ||
219 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 230 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
231 | } | ||
220 | GNUNET_free (opc); | 232 | GNUNET_free (opc); |
221 | } | 233 | } |
222 | 234 | ||
@@ -493,11 +505,15 @@ GNUNET_TESTBED_peer_start (struct GNUNET_TESTBED_Peer *peer, | |||
493 | void *pcc_cls) | 505 | void *pcc_cls) |
494 | { | 506 | { |
495 | struct OperationContext *opc; | 507 | struct OperationContext *opc; |
508 | struct PeerEventData *data; | ||
496 | 509 | ||
497 | // FIXME: keep and call pcc! | 510 | data = GNUNET_malloc (sizeof (struct PeerEventData)); |
511 | data->peer = peer; | ||
512 | data->pcc = pcc; | ||
513 | data->pcc_cls = pcc_cls; | ||
498 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 514 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
499 | opc->c = peer->controller; | 515 | opc->c = peer->controller; |
500 | opc->data = peer; | 516 | opc->data = data; |
501 | opc->id = opc->c->operation_counter++; | 517 | opc->id = opc->c->operation_counter++; |
502 | opc->type = OP_PEER_START; | 518 | opc->type = OP_PEER_START; |
503 | opc->op = | 519 | opc->op = |
@@ -525,11 +541,15 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer, | |||
525 | void *pcc_cls) | 541 | void *pcc_cls) |
526 | { | 542 | { |
527 | struct OperationContext *opc; | 543 | struct OperationContext *opc; |
528 | 544 | struct PeerEventData *data; | |
529 | // FIXME: keep and call pcc! | 545 | |
546 | data = GNUNET_malloc (sizeof (struct PeerEventData)); | ||
547 | data->peer = peer; | ||
548 | data->pcc = pcc; | ||
549 | data->pcc_cls = pcc_cls; | ||
530 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 550 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
531 | opc->c = peer->controller; | 551 | opc->c = peer->controller; |
532 | opc->data = peer; | 552 | opc->data = data; |
533 | opc->id = opc->c->operation_counter++; | 553 | opc->id = opc->c->operation_counter++; |
534 | opc->type = OP_PEER_STOP; | 554 | opc->type = OP_PEER_STOP; |
535 | opc->op = | 555 | opc->op = |
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index 4996f1012..357f45e51 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h | |||
@@ -122,6 +122,29 @@ struct PeerCreateData | |||
122 | 122 | ||
123 | 123 | ||
124 | /** | 124 | /** |
125 | * Data for OperationType OP_PEER_START and OP_PEER_STOP | ||
126 | */ | ||
127 | struct PeerEventData | ||
128 | { | ||
129 | /** | ||
130 | * The handle of the peer to start | ||
131 | */ | ||
132 | struct GNUNET_TESTBED_Peer *peer; | ||
133 | |||
134 | /** | ||
135 | * The Peer churn callback to call when this operation is completed | ||
136 | */ | ||
137 | GNUNET_TESTBED_PeerChurnCallback pcc; | ||
138 | |||
139 | /** | ||
140 | * Closure for the above callback | ||
141 | */ | ||
142 | void *pcc_cls; | ||
143 | |||
144 | }; | ||
145 | |||
146 | |||
147 | /** | ||
125 | * Data for the OperationType OP_PEER_DESTROY; | 148 | * Data for the OperationType OP_PEER_DESTROY; |
126 | */ | 149 | */ |
127 | struct PeerDestroyData | 150 | struct PeerDestroyData |