diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-05 10:50:56 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-05 10:50:56 +0000 |
commit | 270a6392703fe1cb99f69ed8a35c1be0c864b11f (patch) | |
tree | 1c65d01fefab939684c58757880987d2a00fd060 /src/testbed | |
parent | c09edda8e8071c6e5ca6b76e7c75a7b8402010ed (diff) | |
download | gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.tar.gz gnunet-270a6392703fe1cb99f69ed8a35c1be0c864b11f.zip |
changed testbed API to include convenience callbacks
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/test_testbed_api.c | 95 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_2peers.c | 37 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_controllerlink.c | 4 | ||||
-rw-r--r-- | src/testbed/test_testbed_api_test.c | 64 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 63 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 33 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.h | 42 | ||||
-rw-r--r-- | src/testbed/testbed_api_services.c | 43 |
8 files changed, 241 insertions, 140 deletions
diff --git a/src/testbed/test_testbed_api.c b/src/testbed/test_testbed_api.c index caa3d09fd..529072cee 100644 --- a/src/testbed/test_testbed_api.c +++ b/src/testbed/test_testbed_api.c | |||
@@ -207,6 +207,64 @@ dht_disconnect_adapter (void *cls, void *op_result) | |||
207 | } | 207 | } |
208 | 208 | ||
209 | 209 | ||
210 | /** | ||
211 | * Callback to be called when an operation is completed | ||
212 | * | ||
213 | * @param cls the callback closure from functions generating an operation | ||
214 | * @param op the operation that has been finished | ||
215 | * @param emsg error message in case the operation has failed; will be NULL if | ||
216 | * operation has executed successfully. | ||
217 | */ | ||
218 | static void | ||
219 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | ||
220 | { | ||
221 | switch (sub_test) | ||
222 | { | ||
223 | case PEER_SERVICE_CONNECT: | ||
224 | GNUNET_assert (operation == op); | ||
225 | GNUNET_assert (NULL == emsg); | ||
226 | GNUNET_assert (NULL == cls); | ||
227 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | ||
228 | * disconnect adapter */ | ||
229 | break; | ||
230 | default: | ||
231 | GNUNET_assert (0); | ||
232 | } | ||
233 | } | ||
234 | |||
235 | |||
236 | /** | ||
237 | * Callback to be called when the requested peer information is available | ||
238 | * | ||
239 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
240 | * @param op the operation this callback corresponds to | ||
241 | * @param pinfo the result; will be NULL if the operation has failed | ||
242 | * @param emsg error message if the operation has failed; will be NULL if the | ||
243 | * operation is successfull | ||
244 | */ | ||
245 | static void | ||
246 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op, | ||
247 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
248 | const char *emsg) | ||
249 | { | ||
250 | switch (sub_test) | ||
251 | { | ||
252 | case PEER_GETCONFIG: | ||
253 | GNUNET_assert (NULL != pinfo); | ||
254 | GNUNET_assert (NULL == emsg); | ||
255 | GNUNET_assert (NULL == cb_cls); | ||
256 | GNUNET_assert (operation == op); | ||
257 | GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION == pinfo->pit); | ||
258 | GNUNET_assert (NULL != pinfo->result.cfg); | ||
259 | sub_test = PEER_DESTROY; | ||
260 | GNUNET_TESTBED_operation_done (operation); | ||
261 | operation = GNUNET_TESTBED_peer_destroy (peer); | ||
262 | break; | ||
263 | default: | ||
264 | GNUNET_assert (0); | ||
265 | } | ||
266 | } | ||
267 | |||
210 | 268 | ||
211 | /** | 269 | /** |
212 | * Signature of the event handler function called by the | 270 | * Signature of the event handler function called by the |
@@ -223,25 +281,11 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
223 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 281 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
224 | switch (sub_test) | 282 | switch (sub_test) |
225 | { | 283 | { |
226 | case PEER_GETCONFIG: | ||
227 | GNUNET_assert (event->details.operation_finished.operation == operation); | ||
228 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
229 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
230 | GNUNET_assert (GNUNET_TESTBED_PIT_CONFIGURATION == | ||
231 | event->details.operation_finished.pit); | ||
232 | GNUNET_assert (NULL != event->details.operation_finished.op_result.cfg); | ||
233 | sub_test = PEER_DESTROY; | ||
234 | GNUNET_TESTBED_operation_done (operation); | ||
235 | operation = GNUNET_TESTBED_peer_destroy (peer); | ||
236 | break; | ||
237 | case PEER_DESTROY: | 284 | case PEER_DESTROY: |
238 | GNUNET_assert (event->details.operation_finished.operation == operation); | 285 | GNUNET_assert (event->details.operation_finished.operation == operation); |
239 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 286 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
240 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 287 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
241 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | 288 | GNUNET_assert (NULL == event->details.operation_finished.generic); |
242 | event->details.operation_finished.pit); | ||
243 | GNUNET_assert (NULL == | ||
244 | event->details.operation_finished.op_result.generic); | ||
245 | GNUNET_TESTBED_operation_done (operation); | 289 | GNUNET_TESTBED_operation_done (operation); |
246 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 290 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
247 | break; | 291 | break; |
@@ -249,15 +293,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
249 | GNUNET_assert (event->details.operation_finished.operation == operation); | 293 | GNUNET_assert (event->details.operation_finished.operation == operation); |
250 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 294 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
251 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 295 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
252 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | ||
253 | event->details.operation_finished.pit); | ||
254 | GNUNET_assert (NULL != dht_handle); | 296 | GNUNET_assert (NULL != dht_handle); |
255 | GNUNET_assert (event->details.operation_finished.op_result.generic == | 297 | GNUNET_assert (event->details.operation_finished.generic == dht_handle); |
256 | dht_handle); | ||
257 | GNUNET_TESTBED_operation_done (operation); /* This results in call to | ||
258 | * disconnect adapter */ | ||
259 | break; | 298 | break; |
260 | case OTHER: | 299 | default: |
261 | GNUNET_assert (0); | 300 | GNUNET_assert (0); |
262 | break; | 301 | break; |
263 | } | 302 | } |
@@ -268,8 +307,9 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
268 | GNUNET_assert (OTHER == sub_test); | 307 | GNUNET_assert (OTHER == sub_test); |
269 | GNUNET_TESTBED_operation_done (operation); | 308 | GNUNET_TESTBED_operation_done (operation); |
270 | operation = | 309 | operation = |
271 | GNUNET_TESTBED_service_connect (NULL, peer, "dht", &dht_connect_adapter, | 310 | GNUNET_TESTBED_service_connect (NULL, peer, "dht", &op_comp_cb, NULL, |
272 | &dht_disconnect_adapter, NULL); | 311 | &dht_connect_adapter, |
312 | &dht_disconnect_adapter, NULL); | ||
273 | GNUNET_assert (NULL != operation); | 313 | GNUNET_assert (NULL != operation); |
274 | break; | 314 | break; |
275 | case GNUNET_TESTBED_ET_PEER_STOP: | 315 | case GNUNET_TESTBED_ET_PEER_STOP: |
@@ -278,9 +318,10 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
278 | result = GNUNET_YES; | 318 | result = GNUNET_YES; |
279 | sub_test = PEER_GETCONFIG; | 319 | sub_test = PEER_GETCONFIG; |
280 | GNUNET_TESTBED_operation_done (operation); | 320 | GNUNET_TESTBED_operation_done (operation); |
281 | operation = | 321 | operation = |
282 | GNUNET_TESTBED_peer_get_information (peer, | 322 | GNUNET_TESTBED_peer_get_information (peer, |
283 | GNUNET_TESTBED_PIT_CONFIGURATION); | 323 | GNUNET_TESTBED_PIT_CONFIGURATION, |
324 | &peerinfo_cb, NULL); | ||
284 | break; | 325 | break; |
285 | default: | 326 | default: |
286 | GNUNET_assert (0); /* We should never reach this state */ | 327 | GNUNET_assert (0); /* We should never reach this state */ |
diff --git a/src/testbed/test_testbed_api_2peers.c b/src/testbed/test_testbed_api_2peers.c index e1445d961..63810187b 100644 --- a/src/testbed/test_testbed_api_2peers.c +++ b/src/testbed/test_testbed_api_2peers.c | |||
@@ -196,6 +196,30 @@ do_abort (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
196 | 196 | ||
197 | 197 | ||
198 | /** | 198 | /** |
199 | * Callback to be called when an operation is completed | ||
200 | * | ||
201 | * @param cls the callback closure from functions generating an operation | ||
202 | * @param op the operation that has been finished | ||
203 | * @param emsg error message in case the operation has failed; will be NULL if | ||
204 | * operation has executed successfully. | ||
205 | */ | ||
206 | static void | ||
207 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg) | ||
208 | { | ||
209 | GNUNET_assert (PEERS_STARTED == result); | ||
210 | GNUNET_assert (NULL == peer1.operation); | ||
211 | GNUNET_assert (NULL == peer2.operation); | ||
212 | GNUNET_assert (NULL != common_operation); | ||
213 | GNUNET_TESTBED_operation_done (common_operation); | ||
214 | common_operation = NULL; | ||
215 | result = PEERS_CONNECTED; | ||
216 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
217 | peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer); | ||
218 | peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer); | ||
219 | } | ||
220 | |||
221 | |||
222 | /** | ||
199 | * Signature of the event handler function called by the | 223 | * Signature of the event handler function called by the |
200 | * respective event controller. | 224 | * respective event controller. |
201 | * | 225 | * |
@@ -211,9 +235,7 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
211 | GNUNET_assert (PEERS_STOPPED == result); | 235 | GNUNET_assert (PEERS_STOPPED == result); |
212 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 236 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
213 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 237 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
214 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | 238 | GNUNET_assert (NULL == event->details.operation_finished.generic); |
215 | event->details.operation_finished.pit); | ||
216 | GNUNET_assert (NULL == event->details.operation_finished.op_result.generic); | ||
217 | if (event->details.operation_finished.operation == peer1.operation) | 239 | if (event->details.operation_finished.operation == peer1.operation) |
218 | { | 240 | { |
219 | GNUNET_TESTBED_operation_done (peer1.operation); | 241 | GNUNET_TESTBED_operation_done (peer1.operation); |
@@ -255,7 +277,8 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
255 | { | 277 | { |
256 | result = PEERS_STARTED; | 278 | result = PEERS_STARTED; |
257 | common_operation = | 279 | common_operation = |
258 | GNUNET_TESTBED_overlay_connect (NULL, peer1.peer, peer2.peer); | 280 | GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peer1.peer, |
281 | peer2.peer); | ||
259 | } | 282 | } |
260 | break; | 283 | break; |
261 | case GNUNET_TESTBED_ET_PEER_STOP: | 284 | case GNUNET_TESTBED_ET_PEER_STOP: |
@@ -284,12 +307,6 @@ controller_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event) | |||
284 | GNUNET_assert (NULL != common_operation); | 307 | GNUNET_assert (NULL != common_operation); |
285 | GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && | 308 | GNUNET_assert ((event->details.peer_connect.peer1 == peer1.peer) && |
286 | (event->details.peer_connect.peer2 == peer2.peer)); | 309 | (event->details.peer_connect.peer2 == peer2.peer)); |
287 | GNUNET_TESTBED_operation_done (common_operation); | ||
288 | common_operation = NULL; | ||
289 | result = PEERS_CONNECTED; | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Peers connected\n"); | ||
291 | peer1.operation = GNUNET_TESTBED_peer_stop (peer1.peer); | ||
292 | peer2.operation = GNUNET_TESTBED_peer_stop (peer2.peer); | ||
293 | break; | 310 | break; |
294 | default: | 311 | default: |
295 | GNUNET_assert (0); | 312 | GNUNET_assert (0); |
diff --git a/src/testbed/test_testbed_api_controllerlink.c b/src/testbed/test_testbed_api_controllerlink.c index b10e454de..ee62bf1aa 100644 --- a/src/testbed/test_testbed_api_controllerlink.c +++ b/src/testbed/test_testbed_api_controllerlink.c | |||
@@ -305,9 +305,7 @@ check_operation_success (const struct GNUNET_TESTBED_EventInformation *event) | |||
305 | GNUNET_assert (event->details.operation_finished.operation == op); | 305 | GNUNET_assert (event->details.operation_finished.operation == op); |
306 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | 306 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); |
307 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | 307 | GNUNET_assert (NULL == event->details.operation_finished.emsg); |
308 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC == | 308 | GNUNET_assert (NULL == event->details.operation_finished.generic); |
309 | event->details.operation_finished.pit); | ||
310 | GNUNET_assert (NULL == event->details.operation_finished.op_result.generic); | ||
311 | } | 309 | } |
312 | 310 | ||
313 | 311 | ||
diff --git a/src/testbed/test_testbed_api_test.c b/src/testbed/test_testbed_api_test.c index 43a5628ad..f552d1a78 100644 --- a/src/testbed/test_testbed_api_test.c +++ b/src/testbed/test_testbed_api_test.c | |||
@@ -63,6 +63,52 @@ do_shutdown (void *cls, const const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
63 | 63 | ||
64 | 64 | ||
65 | /** | 65 | /** |
66 | * Callback to be called when the requested peer information is available | ||
67 | * | ||
68 | * @param cb_cls the closure from GNUNET_TETSBED_peer_get_information() | ||
69 | * @param op the operation this callback corresponds to | ||
70 | * @param pinfo the result; will be NULL if the operation has failed | ||
71 | * @param emsg error message if the operation has failed; will be NULL if the | ||
72 | * operation is successfull | ||
73 | */ | ||
74 | static void | ||
75 | peerinfo_cb (void *cb_cls, struct GNUNET_TESTBED_Operation *op_, | ||
76 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
77 | const char *emsg) | ||
78 | { | ||
79 | GNUNET_assert (op == op_); | ||
80 | GNUNET_assert (NULL == cb_cls); | ||
81 | GNUNET_assert (NULL == emsg); | ||
82 | GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == pinfo->pit); | ||
83 | GNUNET_assert (NULL != pinfo->result.id); | ||
84 | GNUNET_TESTBED_operation_done (op); | ||
85 | result = GNUNET_OK; | ||
86 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Callback to be called when an operation is completed | ||
92 | * | ||
93 | * @param cls the callback closure from functions generating an operation | ||
94 | * @param op the operation that has been finished | ||
95 | * @param emsg error message in case the operation has failed; will be NULL if | ||
96 | * operation has executed successfully. | ||
97 | */ | ||
98 | static void | ||
99 | op_comp_cb (void *cls, struct GNUNET_TESTBED_Operation *op_, const char *emsg) | ||
100 | { | ||
101 | GNUNET_assert (NULL == cls); | ||
102 | GNUNET_assert (op == op_); | ||
103 | GNUNET_assert (NULL == emsg); | ||
104 | GNUNET_TESTBED_operation_done (op); | ||
105 | op = GNUNET_TESTBED_peer_get_information (peers[0], | ||
106 | GNUNET_TESTBED_PIT_IDENTITY, | ||
107 | &peerinfo_cb, NULL); | ||
108 | } | ||
109 | |||
110 | |||
111 | /** | ||
66 | * Controller event callback | 112 | * Controller event callback |
67 | * | 113 | * |
68 | * @param cls NULL | 114 | * @param cls NULL |
@@ -76,21 +122,7 @@ controller_event_cb (void *cls, | |||
76 | { | 122 | { |
77 | case GNUNET_TESTBED_ET_CONNECT: | 123 | case GNUNET_TESTBED_ET_CONNECT: |
78 | GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); | 124 | GNUNET_assert (event->details.peer_connect.peer1 == peers[0]); |
79 | GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); | 125 | GNUNET_assert (event->details.peer_connect.peer2 == peers[1]); |
80 | GNUNET_TESTBED_operation_done (op); | ||
81 | op = GNUNET_TESTBED_peer_get_information (peers[0], | ||
82 | GNUNET_TESTBED_PIT_IDENTITY); | ||
83 | break; | ||
84 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
85 | GNUNET_assert (event->details.operation_finished.operation == op); | ||
86 | GNUNET_assert (NULL == event->details.operation_finished.op_cls); | ||
87 | GNUNET_assert (NULL == event->details.operation_finished.emsg); | ||
88 | GNUNET_assert (GNUNET_TESTBED_PIT_IDENTITY == | ||
89 | event->details.operation_finished.pit); | ||
90 | GNUNET_assert (NULL != event->details.operation_finished.op_result.pid); | ||
91 | GNUNET_TESTBED_operation_done (op); | ||
92 | result = GNUNET_OK; | ||
93 | GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
94 | break; | 126 | break; |
95 | default: | 127 | default: |
96 | GNUNET_assert (0); | 128 | GNUNET_assert (0); |
@@ -117,7 +149,7 @@ test_master (void *cls, unsigned int num_peers, | |||
117 | for (peer = 0; peer < num_peers; peer++) | 149 | for (peer = 0; peer < num_peers; peer++) |
118 | GNUNET_assert (NULL != peers_[peer]); | 150 | GNUNET_assert (NULL != peers_[peer]); |
119 | peers = peers_; | 151 | peers = peers_; |
120 | op = GNUNET_TESTBED_overlay_connect (NULL, peers[0], peers[1]); | 152 | op = GNUNET_TESTBED_overlay_connect (NULL, &op_comp_cb, NULL, peers[0], peers[1]); |
121 | } | 153 | } |
122 | 154 | ||
123 | 155 | ||
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 48c55e470..665c19486 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -322,8 +322,7 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
322 | event->details.operation_finished.operation = opc->op; | 322 | event->details.operation_finished.operation = opc->op; |
323 | event->details.operation_finished.op_cls = NULL; | 323 | event->details.operation_finished.op_cls = NULL; |
324 | event->details.operation_finished.emsg = NULL; | 324 | event->details.operation_finished.emsg = NULL; |
325 | event->details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | 325 | event->details.operation_finished.generic = NULL; |
326 | event->details.operation_finished.op_result.generic = NULL; | ||
327 | } | 326 | } |
328 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 327 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
329 | opc->state = OPC_STATE_FINISHED; | 328 | opc->state = OPC_STATE_FINISHED; |
@@ -480,6 +479,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c, | |||
480 | { | 479 | { |
481 | struct OperationContext *opc; | 480 | struct OperationContext *opc; |
482 | struct OverlayConnectData *data; | 481 | struct OverlayConnectData *data; |
482 | GNUNET_TESTBED_OperationCompletionCallback cb; | ||
483 | void *cb_cls; | ||
483 | struct GNUNET_TESTBED_EventInformation event; | 484 | struct GNUNET_TESTBED_EventInformation event; |
484 | uint64_t op_id; | 485 | uint64_t op_id; |
485 | 486 | ||
@@ -507,6 +508,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c, | |||
507 | GNUNET_assert (0); /* Should never reach here */ | 508 | GNUNET_assert (0); /* Should never reach here */ |
508 | break; | 509 | break; |
509 | } | 510 | } |
511 | cb = data->cb; | ||
512 | cb_cls = data->cb_cls; | ||
510 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 513 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
511 | opc->state = OPC_STATE_FINISHED; | 514 | opc->state = OPC_STATE_FINISHED; |
512 | GNUNET_free (data); | 515 | GNUNET_free (data); |
@@ -517,6 +520,8 @@ handle_peer_conevent (struct GNUNET_TESTBED_Controller *c, | |||
517 | if (NULL != c->cc) | 520 | if (NULL != c->cc) |
518 | c->cc (c->cc_cls, &event); | 521 | c->cc (c->cc_cls, &event); |
519 | } | 522 | } |
523 | if (NULL != cb) | ||
524 | cb (cb_cls, opc->op, NULL); | ||
520 | return GNUNET_YES; | 525 | return GNUNET_YES; |
521 | } | 526 | } |
522 | 527 | ||
@@ -538,8 +543,9 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
538 | struct OperationContext *opc; | 543 | struct OperationContext *opc; |
539 | struct GNUNET_TESTBED_Peer *peer; | 544 | struct GNUNET_TESTBED_Peer *peer; |
540 | struct PeerInfoData *data; | 545 | struct PeerInfoData *data; |
541 | struct PeerInfoData2 *response_data; | 546 | struct GNUNET_TESTBED_PeerInformation *pinfo; |
542 | struct GNUNET_TESTBED_EventInformation info; | 547 | GNUNET_TESTBED_PeerInfoCallback cb; |
548 | void *cb_cls; | ||
543 | uint64_t op_id; | 549 | uint64_t op_id; |
544 | 550 | ||
545 | op_id = GNUNET_ntohll (msg->operation_id); | 551 | op_id = GNUNET_ntohll (msg->operation_id); |
@@ -565,52 +571,32 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
565 | peer = data->peer; | 571 | peer = data->peer; |
566 | GNUNET_assert (NULL != peer); | 572 | GNUNET_assert (NULL != peer); |
567 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); | 573 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); |
568 | if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) | 574 | pinfo = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_PeerInformation)); |
569 | { | 575 | pinfo->pit = data->pit; |
570 | LOG_DEBUG ("Skipping operation callback as flag not set\n"); | 576 | cb = data->cb; |
571 | return GNUNET_YES; | 577 | cb_cls = data->cb_cls; |
572 | } | ||
573 | response_data = GNUNET_malloc (sizeof (struct PeerInfoData2)); | ||
574 | response_data->pit = data->pit; | ||
575 | GNUNET_free (data); | 578 | GNUNET_free (data); |
576 | opc->data = NULL; | 579 | opc->data = NULL; |
577 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 580 | switch (pinfo->pit) |
578 | info.details.operation_finished.operation = opc->op; | ||
579 | info.details.operation_finished.op_cls = NULL; | ||
580 | info.details.operation_finished.emsg = NULL; | ||
581 | info.details.operation_finished.pit = response_data->pit; | ||
582 | switch (response_data->pit) | ||
583 | { | 581 | { |
584 | case GNUNET_TESTBED_PIT_IDENTITY: | 582 | case GNUNET_TESTBED_PIT_IDENTITY: |
585 | { | 583 | pinfo->result.id = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
586 | struct GNUNET_PeerIdentity *peer_identity; | 584 | (void) memcpy (pinfo->result.id, &msg->peer_identity, |
587 | 585 | sizeof (struct GNUNET_PeerIdentity)); | |
588 | peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
589 | (void) memcpy (peer_identity, &msg->peer_identity, | ||
590 | sizeof (struct GNUNET_PeerIdentity)); | ||
591 | response_data->details.peer_identity = peer_identity; | ||
592 | info.details.operation_finished.op_result.pid = peer_identity; | ||
593 | } | ||
594 | break; | 586 | break; |
595 | case GNUNET_TESTBED_PIT_CONFIGURATION: | 587 | case GNUNET_TESTBED_PIT_CONFIGURATION: |
596 | response_data->details.cfg = /* Freed in oprelease_peer_getinfo */ | 588 | pinfo->result.cfg = /* Freed in oprelease_peer_getinfo */ |
597 | GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); | 589 | GNUNET_TESTBED_get_config_from_peerinfo_msg_ (msg); |
598 | info.details.operation_finished.op_result.cfg = response_data->details.cfg; | ||
599 | break; | 590 | break; |
600 | case GNUNET_TESTBED_PIT_GENERIC: | 591 | case GNUNET_TESTBED_PIT_GENERIC: |
601 | GNUNET_assert (0); /* never reach here */ | 592 | GNUNET_assert (0); /* never reach here */ |
602 | break; | 593 | break; |
603 | } | 594 | } |
604 | opc->data = response_data; | 595 | opc->data = pinfo; |
605 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | 596 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); |
606 | opc->state = OPC_STATE_FINISHED; | 597 | opc->state = OPC_STATE_FINISHED; |
607 | if (0 != | 598 | if (NULL != cb) |
608 | ((GNUNET_TESTBED_ET_CONNECT | GNUNET_TESTBED_ET_DISCONNECT) & | 599 | cb (cb_cls, opc->op, pinfo, NULL); |
609 | c->event_mask)) | ||
610 | { | ||
611 | if (NULL != c->cc) | ||
612 | c->cc (c->cc_cls, &info); | ||
613 | } | ||
614 | return GNUNET_YES; | 600 | return GNUNET_YES; |
615 | } | 601 | } |
616 | 602 | ||
@@ -676,8 +662,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
676 | event.details.operation_finished.operation = opc->op; | 662 | event.details.operation_finished.operation = opc->op; |
677 | event.details.operation_finished.op_cls = NULL; | 663 | event.details.operation_finished.op_cls = NULL; |
678 | event.details.operation_finished.emsg = emsg; | 664 | event.details.operation_finished.emsg = emsg; |
679 | event.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | 665 | event.details.operation_finished.generic = NULL; |
680 | event.details.operation_finished.op_result.generic = NULL; | ||
681 | c->cc (c->cc_cls, &event); | 666 | c->cc (c->cc_cls, &event); |
682 | } | 667 | } |
683 | return GNUNET_YES; | 668 | return GNUNET_YES; |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index 9ced75973..9465c66bb 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -279,7 +279,7 @@ static void | |||
279 | oprelease_peer_getinfo (void *cls) | 279 | oprelease_peer_getinfo (void *cls) |
280 | { | 280 | { |
281 | struct OperationContext *opc = cls; | 281 | struct OperationContext *opc = cls; |
282 | struct PeerInfoData2 *data; | 282 | struct GNUNET_TESTBED_PeerInformation *data; |
283 | 283 | ||
284 | if (OPC_STATE_FINISHED != opc->state) | 284 | if (OPC_STATE_FINISHED != opc->state) |
285 | { | 285 | { |
@@ -293,10 +293,10 @@ oprelease_peer_getinfo (void *cls) | |||
293 | switch (data->pit) | 293 | switch (data->pit) |
294 | { | 294 | { |
295 | case GNUNET_TESTBED_PIT_CONFIGURATION: | 295 | case GNUNET_TESTBED_PIT_CONFIGURATION: |
296 | GNUNET_CONFIGURATION_destroy (data->details.cfg); | 296 | GNUNET_CONFIGURATION_destroy (data->result.cfg); |
297 | break; | 297 | break; |
298 | case GNUNET_TESTBED_PIT_IDENTITY: | 298 | case GNUNET_TESTBED_PIT_IDENTITY: |
299 | GNUNET_free (data->details.peer_identity); | 299 | GNUNET_free (data->result.id); |
300 | break; | 300 | break; |
301 | default: | 301 | default: |
302 | GNUNET_assert (0); /* We should never reach here */ | 302 | GNUNET_assert (0); /* We should never reach here */ |
@@ -532,16 +532,23 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer) | |||
532 | 532 | ||
533 | 533 | ||
534 | /** | 534 | /** |
535 | * Request information about a peer. | 535 | * Request information about a peer. The controller callback will be called with |
536 | * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this | ||
537 | * operation is available | ||
536 | * | 538 | * |
537 | * @param peer peer to request information about | 539 | * @param peer peer to request information about |
538 | * @param pit desired information | 540 | * @param pit desired information |
541 | * @param cb the convenience callback to be called when results for this | ||
542 | * operation are available | ||
543 | * @param cb_cls the closure for the above callback | ||
539 | * @return handle to the operation | 544 | * @return handle to the operation |
540 | */ | 545 | */ |
541 | struct GNUNET_TESTBED_Operation * | 546 | struct GNUNET_TESTBED_Operation * |
542 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | 547 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, |
543 | enum GNUNET_TESTBED_PeerInformationType | 548 | enum GNUNET_TESTBED_PeerInformationType |
544 | pit) | 549 | pit, |
550 | GNUNET_TESTBED_PeerInfoCallback cb, | ||
551 | void *cb_cls) | ||
545 | { | 552 | { |
546 | struct OperationContext *opc; | 553 | struct OperationContext *opc; |
547 | struct PeerInfoData *data; | 554 | struct PeerInfoData *data; |
@@ -550,6 +557,8 @@ GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | |||
550 | data = GNUNET_malloc (sizeof (struct PeerInfoData)); | 557 | data = GNUNET_malloc (sizeof (struct PeerInfoData)); |
551 | data->peer = peer; | 558 | data->peer = peer; |
552 | data->pit = pit; | 559 | data->pit = pit; |
560 | data->cb = cb; | ||
561 | data->cb_cls = cb_cls; | ||
553 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 562 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
554 | opc->c = peer->controller; | 563 | opc->c = peer->controller; |
555 | opc->data = data; | 564 | opc->data = data; |
@@ -635,13 +644,14 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls, | |||
635 | } | 644 | } |
636 | 645 | ||
637 | 646 | ||
638 | |||
639 | /** | 647 | /** |
640 | * Both peers must have been started before calling this function. | 648 | * Both peers must have been started before calling this function. |
641 | * This function then obtains a HELLO from 'p1', gives it to 'p2' | 649 | * This function then obtains a HELLO from 'p1', gives it to 'p2' |
642 | * and asks 'p2' to connect to 'p1'. | 650 | * and asks 'p2' to connect to 'p1'. |
643 | * | 651 | * |
644 | * @param op_cls closure argument to give with the operation event | 652 | * @param op_cls closure argument to give with the operation event |
653 | * @param cb the callback to call when this operation has finished | ||
654 | * @param cb_cls the closure for the above callback | ||
645 | * @param p1 first peer | 655 | * @param p1 first peer |
646 | * @param p2 second peer | 656 | * @param p2 second peer |
647 | * @return handle to the operation, NULL if connecting these two | 657 | * @return handle to the operation, NULL if connecting these two |
@@ -649,8 +659,11 @@ GNUNET_TESTBED_underlay_configure_link (void *op_cls, | |||
649 | * not running or underlay disallows) | 659 | * not running or underlay disallows) |
650 | */ | 660 | */ |
651 | struct GNUNET_TESTBED_Operation * | 661 | struct GNUNET_TESTBED_Operation * |
652 | GNUNET_TESTBED_overlay_connect (void *op_cls, struct GNUNET_TESTBED_Peer *p1, | 662 | GNUNET_TESTBED_overlay_connect (void *op_cls, |
653 | struct GNUNET_TESTBED_Peer *p2) | 663 | GNUNET_TESTBED_OperationCompletionCallback cb, |
664 | void *cb_cls, | ||
665 | struct GNUNET_TESTBED_Peer *p1, | ||
666 | struct GNUNET_TESTBED_Peer *p2) | ||
654 | { | 667 | { |
655 | struct OperationContext *opc; | 668 | struct OperationContext *opc; |
656 | struct OverlayConnectData *data; | 669 | struct OverlayConnectData *data; |
@@ -660,6 +673,8 @@ GNUNET_TESTBED_overlay_connect (void *op_cls, struct GNUNET_TESTBED_Peer *p1, | |||
660 | data = GNUNET_malloc (sizeof (struct OverlayConnectData)); | 673 | data = GNUNET_malloc (sizeof (struct OverlayConnectData)); |
661 | data->p1 = p1; | 674 | data->p1 = p1; |
662 | data->p2 = p2; | 675 | data->p2 = p2; |
676 | data->cb = cb; | ||
677 | data->cb_cls = cb_cls; | ||
663 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | 678 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
664 | opc->data = data; | 679 | opc->data = data; |
665 | opc->c = p1->controller; | 680 | opc->c = p1->controller; |
diff --git a/src/testbed/testbed_api_peers.h b/src/testbed/testbed_api_peers.h index 21cae976b..16c4ea42f 100644 --- a/src/testbed/testbed_api_peers.h +++ b/src/testbed/testbed_api_peers.h | |||
@@ -146,37 +146,19 @@ struct PeerInfoData | |||
146 | struct GNUNET_TESTBED_Peer *peer; | 146 | struct GNUNET_TESTBED_Peer *peer; |
147 | 147 | ||
148 | /** | 148 | /** |
149 | * The type of peer information requested | 149 | * The Peer info callback to call when this operation has completed |
150 | */ | 150 | */ |
151 | enum GNUNET_TESTBED_PeerInformationType pit; | 151 | GNUNET_TESTBED_PeerInfoCallback cb; |
152 | }; | 152 | |
153 | |||
154 | |||
155 | /** | ||
156 | * Data for the OperationType OP_PEER_INFO | ||
157 | */ | ||
158 | struct PeerInfoData2 | ||
159 | { | ||
160 | /** | 153 | /** |
161 | * The type of peer information requested | 154 | * The closure for peer info callback |
162 | */ | 155 | */ |
163 | enum GNUNET_TESTBED_PeerInformationType pit; | 156 | void *cb_cls; |
164 | 157 | ||
165 | /** | 158 | /** |
166 | * The data from reply | 159 | * The type of peer information requested |
167 | */ | 160 | */ |
168 | union | 161 | enum GNUNET_TESTBED_PeerInformationType pit; |
169 | { | ||
170 | /** | ||
171 | * Configuration handle | ||
172 | */ | ||
173 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
174 | |||
175 | /** | ||
176 | * Peer Identity | ||
177 | */ | ||
178 | struct GNUNET_PeerIdentity *peer_identity; | ||
179 | } details; | ||
180 | }; | 162 | }; |
181 | 163 | ||
182 | 164 | ||
@@ -195,6 +177,16 @@ struct OverlayConnectData | |||
195 | */ | 177 | */ |
196 | struct GNUNET_TESTBED_Peer *p2; | 178 | struct GNUNET_TESTBED_Peer *p2; |
197 | 179 | ||
180 | /** | ||
181 | * The operation completion callback to call once this operation is done | ||
182 | */ | ||
183 | GNUNET_TESTBED_OperationCompletionCallback cb; | ||
184 | |||
185 | /** | ||
186 | * The closure for the above callback | ||
187 | */ | ||
188 | void *cb_cls; | ||
189 | |||
198 | }; | 190 | }; |
199 | 191 | ||
200 | 192 | ||
diff --git a/src/testbed/testbed_api_services.c b/src/testbed/testbed_api_services.c index f37ada310..3e8484022 100644 --- a/src/testbed/testbed_api_services.c +++ b/src/testbed/testbed_api_services.c | |||
@@ -49,9 +49,6 @@ enum State | |||
49 | */ | 49 | */ |
50 | SERVICE_CONNECTED, | 50 | SERVICE_CONNECTED, |
51 | 51 | ||
52 | /** | ||
53 | * | ||
54 | */ | ||
55 | }; | 52 | }; |
56 | 53 | ||
57 | 54 | ||
@@ -111,6 +108,16 @@ struct ServiceConnectData | |||
111 | void *op_result; | 108 | void *op_result; |
112 | 109 | ||
113 | /** | 110 | /** |
111 | * The operation completion callback | ||
112 | */ | ||
113 | GNUNET_TESTBED_OperationCompletionCallback cb; | ||
114 | |||
115 | /** | ||
116 | * The closure for operation completion callback | ||
117 | */ | ||
118 | void *cb_cls; | ||
119 | |||
120 | /** | ||
114 | * State information | 121 | * State information |
115 | */ | 122 | */ |
116 | enum State state; | 123 | enum State state; |
@@ -132,7 +139,13 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
132 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; | 139 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *imsg; |
133 | struct GNUNET_TESTBED_Controller *c; | 140 | struct GNUNET_TESTBED_Controller *c; |
134 | struct GNUNET_TESTBED_EventInformation info; | 141 | struct GNUNET_TESTBED_EventInformation info; |
142 | uint16_t mtype; | ||
135 | 143 | ||
144 | mtype = ntohs (msg->type); | ||
145 | if (GNUNET_MESSAGE_TYPE_TESTBED_OPERATIONEVENT == mtype) | ||
146 | { | ||
147 | GNUNET_assert (0); /* FIXME: Add notification for failure */ | ||
148 | } | ||
136 | imsg = | 149 | imsg = |
137 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; | 150 | (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg; |
138 | data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg); | 151 | data->cfg = GNUNET_TESTBED_get_config_from_peerinfo_msg_ (imsg); |
@@ -141,13 +154,14 @@ configuration_receiver (void *cls, const struct GNUNET_MessageHeader *msg) | |||
141 | info.details.operation_finished.operation = data->operation; | 154 | info.details.operation_finished.operation = data->operation; |
142 | info.details.operation_finished.op_cls = data->op_cls; | 155 | info.details.operation_finished.op_cls = data->op_cls; |
143 | info.details.operation_finished.emsg = NULL; | 156 | info.details.operation_finished.emsg = NULL; |
144 | info.details.operation_finished.pit = GNUNET_TESTBED_PIT_GENERIC; | 157 | info.details.operation_finished.generic = data->op_result; |
145 | info.details.operation_finished.op_result.generic = data->op_result; | ||
146 | c = data->peer->controller; | 158 | c = data->peer->controller; |
147 | data->state = SERVICE_CONNECTED; | 159 | data->state = SERVICE_CONNECTED; |
148 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && | 160 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && |
149 | (NULL != c->cc)) | 161 | (NULL != c->cc)) |
150 | c->cc (c->cc_cls, &info); | 162 | c->cc (c->cc_cls, &info); |
163 | if (NULL != data->cb) | ||
164 | data->cb (data->cb_cls, data->operation, NULL); | ||
151 | } | 165 | } |
152 | 166 | ||
153 | 167 | ||
@@ -214,7 +228,7 @@ oprelease_service_connect (void *cls) | |||
214 | * maintain connections with other systems. The actual service | 228 | * maintain connections with other systems. The actual service |
215 | * handle is then returned via the 'op_result' member in the event | 229 | * handle is then returned via the 'op_result' member in the event |
216 | * callback. The 'ca' callback is used to create the connection | 230 | * callback. The 'ca' callback is used to create the connection |
217 | * when the time is right; the 'da' callback will be used to | 231 | * when the time is right; the 'da' callback will be used to |
218 | * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). | 232 | * destroy the connection (upon 'GNUNET_TESTBED_operation_done'). |
219 | * 'GNUNET_TESTBED_operation_cancel' can be used to abort this | 233 | * 'GNUNET_TESTBED_operation_cancel' can be used to abort this |
220 | * operation until the event callback has been called. | 234 | * operation until the event callback has been called. |
@@ -222,17 +236,22 @@ oprelease_service_connect (void *cls) | |||
222 | * @param op_cls closure to pass in operation event | 236 | * @param op_cls closure to pass in operation event |
223 | * @param peer peer that runs the service | 237 | * @param peer peer that runs the service |
224 | * @param service_name name of the service to connect to | 238 | * @param service_name name of the service to connect to |
239 | * @param cb the callback to call when this operation finishes | ||
240 | * @param cb_cls closure for the above callback | ||
225 | * @param ca helper function to establish the connection | 241 | * @param ca helper function to establish the connection |
226 | * @param da helper function to close the connection | 242 | * @param da helper function to close the connection |
227 | * @param cada_cls closure for ca and da | 243 | * @param cada_cls closure for ca and da |
228 | * @return handle for the operation | 244 | * @return handle for the operation |
229 | */ | 245 | */ |
230 | struct GNUNET_TESTBED_Operation * | 246 | struct GNUNET_TESTBED_Operation * |
231 | GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | 247 | GNUNET_TESTBED_service_connect (void *op_cls, |
232 | const char *service_name, | 248 | struct GNUNET_TESTBED_Peer *peer, |
233 | GNUNET_TESTBED_ConnectAdapter ca, | 249 | const char *service_name, |
234 | GNUNET_TESTBED_DisconnectAdapter da, | 250 | GNUNET_TESTBED_OperationCompletionCallback cb, |
235 | void *cada_cls) | 251 | void *cb_cls, |
252 | GNUNET_TESTBED_ConnectAdapter ca, | ||
253 | GNUNET_TESTBED_DisconnectAdapter da, | ||
254 | void *cada_cls) | ||
236 | { | 255 | { |
237 | struct ServiceConnectData *data; | 256 | struct ServiceConnectData *data; |
238 | 257 | ||
@@ -243,6 +262,8 @@ GNUNET_TESTBED_service_connect (void *op_cls, struct GNUNET_TESTBED_Peer *peer, | |||
243 | data->op_cls = op_cls; | 262 | data->op_cls = op_cls; |
244 | data->peer = peer; | 263 | data->peer = peer; |
245 | data->state = INIT; | 264 | data->state = INIT; |
265 | data->cb = cb; | ||
266 | data->cb_cls = cb_cls; | ||
246 | data->operation = | 267 | data->operation = |
247 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, | 268 | GNUNET_TESTBED_operation_create_ (data, &opstart_service_connect, |
248 | &oprelease_service_connect); | 269 | &oprelease_service_connect); |