diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-01 11:12:31 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-08-01 11:12:31 +0000 |
commit | 3ae8db6962c66af1e23545eb41fb670b0fef379c (patch) | |
tree | 7cbd24f8cc13556db98ca4d620ee83344c58e756 /src/testbed | |
parent | 9ba1ca17bcb1f5f2c6d161cd36b03c6dc3461204 (diff) | |
download | gnunet-3ae8db6962c66af1e23545eb41fb670b0fef379c.tar.gz gnunet-3ae8db6962c66af1e23545eb41fb670b0fef379c.zip |
peer info with new operations handling
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 44 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 5 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 92 |
3 files changed, 88 insertions, 53 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 21ade1cea..f8d8e11fc 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -406,7 +406,7 @@ static int | |||
406 | handle_peer_config (struct GNUNET_TESTBED_Controller *c, | 406 | handle_peer_config (struct GNUNET_TESTBED_Controller *c, |
407 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | 407 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) |
408 | { | 408 | { |
409 | struct GNUNET_TESTBED_Operation *op; | 409 | struct OperationContext *opc; |
410 | struct GNUNET_TESTBED_Peer *peer; | 410 | struct GNUNET_TESTBED_Peer *peer; |
411 | struct PeerInfoData *data; | 411 | struct PeerInfoData *data; |
412 | struct PeerInfoData2 *response_data; | 412 | struct PeerInfoData2 *response_data; |
@@ -414,32 +414,28 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
414 | uint64_t op_id; | 414 | uint64_t op_id; |
415 | 415 | ||
416 | op_id = GNUNET_ntohll (msg->operation_id); | 416 | op_id = GNUNET_ntohll (msg->operation_id); |
417 | for (op = c->op_head; NULL != op; op = op->next) | 417 | if (NULL == (opc = find_opc (c, op_id))) |
418 | { | ||
419 | if (op->operation_id == op_id) | ||
420 | break; | ||
421 | } | ||
422 | if (NULL == op) | ||
423 | { | 418 | { |
424 | LOG_DEBUG ("Operation not found"); | 419 | LOG_DEBUG ("Operation not found\n"); |
425 | return GNUNET_YES; | 420 | return GNUNET_YES; |
426 | } | 421 | } |
427 | data = op->data; | 422 | data = opc->data; |
428 | GNUNET_assert (NULL != data); | 423 | GNUNET_assert (NULL != data); |
429 | peer = data->peer; | 424 | peer = data->peer; |
430 | GNUNET_assert (NULL != peer); | 425 | GNUNET_assert (NULL != peer); |
431 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); | 426 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); |
427 | opc->completed = GNUNET_YES; | ||
432 | if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) | 428 | if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) |
433 | { | 429 | { |
434 | LOG_DEBUG ("Skipping operation callback as flag not set\n"); | 430 | LOG_DEBUG ("Skipping operation callback as flag not set\n"); |
435 | GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); | ||
436 | return GNUNET_YES; | 431 | return GNUNET_YES; |
437 | } | 432 | } |
438 | response_data = GNUNET_malloc (sizeof (struct PeerInfoData2)); | 433 | response_data = GNUNET_malloc (sizeof (struct PeerInfoData2)); |
439 | response_data->pit = data->pit; | 434 | response_data->pit = data->pit; |
440 | GNUNET_free (data); | 435 | GNUNET_free (data); |
436 | opc->data = NULL; | ||
441 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | 437 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; |
442 | info.details.operation_finished.operation = op; | 438 | info.details.operation_finished.operation = opc->op; |
443 | info.details.operation_finished.op_cls = NULL; | 439 | info.details.operation_finished.op_cls = NULL; |
444 | info.details.operation_finished.emsg = NULL; | 440 | info.details.operation_finished.emsg = NULL; |
445 | info.details.operation_finished.pit = response_data->pit; | 441 | info.details.operation_finished.pit = response_data->pit; |
@@ -471,7 +467,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
471 | if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, | 467 | if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, |
472 | (const Bytef *) &msg[1], (uLong) msize))) | 468 | (const Bytef *) &msg[1], (uLong) msize))) |
473 | GNUNET_assert (0); | 469 | GNUNET_assert (0); |
474 | cfg = GNUNET_CONFIGURATION_create (); | 470 | cfg = GNUNET_CONFIGURATION_create (); /* Freed in oprelease_peer_getinfo */ |
475 | GNUNET_assert (GNUNET_OK == | 471 | GNUNET_assert (GNUNET_OK == |
476 | GNUNET_CONFIGURATION_deserialize (cfg, config, | 472 | GNUNET_CONFIGURATION_deserialize (cfg, config, |
477 | (size_t) config_size, | 473 | (size_t) config_size, |
@@ -485,8 +481,7 @@ handle_peer_config (struct GNUNET_TESTBED_Controller *c, | |||
485 | GNUNET_assert (0); /* never reach here */ | 481 | GNUNET_assert (0); /* never reach here */ |
486 | break; | 482 | break; |
487 | } | 483 | } |
488 | op->data = response_data; | 484 | opc->data = response_data; |
489 | GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); | ||
490 | c->cc (c->cc_cls, &info); | 485 | c->cc (c->cc_cls, &info); |
491 | return GNUNET_YES; | 486 | return GNUNET_YES; |
492 | } | 487 | } |
@@ -1352,28 +1347,9 @@ GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | |||
1352 | case OP_PEER_DESTROY: | 1347 | case OP_PEER_DESTROY: |
1353 | case OP_PEER_START: | 1348 | case OP_PEER_START: |
1354 | case OP_PEER_STOP: | 1349 | case OP_PEER_STOP: |
1350 | case OP_PEER_INFO: | ||
1355 | GNUNET_TESTBED_operation_release_ (operation); | 1351 | GNUNET_TESTBED_operation_release_ (operation); |
1356 | return; | 1352 | return; |
1357 | case OP_PEER_INFO: | ||
1358 | { | ||
1359 | struct PeerInfoData2 *data; | ||
1360 | |||
1361 | data = operation->data; | ||
1362 | switch (data->pit) | ||
1363 | { | ||
1364 | case GNUNET_TESTBED_PIT_IDENTITY: | ||
1365 | GNUNET_free (data->details.peer_identity); | ||
1366 | break; | ||
1367 | case GNUNET_TESTBED_PIT_CONFIGURATION: | ||
1368 | GNUNET_CONFIGURATION_destroy (data->details.cfg); | ||
1369 | break; | ||
1370 | case GNUNET_TESTBED_PIT_GENERIC: | ||
1371 | GNUNET_assert (0); /* never reach here */ | ||
1372 | break; | ||
1373 | } | ||
1374 | } | ||
1375 | GNUNET_free_non_null (operation->data); | ||
1376 | break; | ||
1377 | case OP_OVERLAY_CONNECT: | 1353 | case OP_OVERLAY_CONNECT: |
1378 | GNUNET_free_non_null (operation->data); | 1354 | GNUNET_free_non_null (operation->data); |
1379 | break; | 1355 | break; |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index 9d0d8076d..bacb53bb1 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -153,6 +153,11 @@ struct OperationContext | |||
153 | */ | 153 | */ |
154 | enum OperationType type; | 154 | enum OperationType type; |
155 | 155 | ||
156 | /** | ||
157 | * Is this operation completed? (has there been a reply from the service) | ||
158 | */ | ||
159 | int completed; | ||
160 | |||
156 | }; | 161 | }; |
157 | 162 | ||
158 | 163 | ||
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index ca4e46e39..b30e2a92c 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -213,6 +213,68 @@ oprelease_peer_stop (void *cls) | |||
213 | 213 | ||
214 | 214 | ||
215 | /** | 215 | /** |
216 | * Function to called when a peer get information operation is ready | ||
217 | * | ||
218 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
219 | */ | ||
220 | static void | ||
221 | opstart_peer_getinfo (void *cls) | ||
222 | { | ||
223 | struct OperationContext *opc = cls; | ||
224 | struct PeerInfoData *data; | ||
225 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | ||
226 | |||
227 | data = opc->data; | ||
228 | GNUNET_assert (NULL != data); | ||
229 | msg = GNUNET_malloc (sizeof (struct | ||
230 | GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
231 | msg->header.size = htons | ||
232 | (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
233 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG); | ||
234 | msg->peer_id = htonl (data->peer->unique_id); | ||
235 | msg->operation_id = GNUNET_htonll (opc->id); | ||
236 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
237 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | ||
238 | } | ||
239 | |||
240 | |||
241 | /** | ||
242 | * Callback which will be called when peer stop type operation is released | ||
243 | * | ||
244 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
245 | */ | ||
246 | static void | ||
247 | oprelease_peer_getinfo (void *cls) | ||
248 | { | ||
249 | struct OperationContext *opc = cls; | ||
250 | struct PeerInfoData2 *data; | ||
251 | |||
252 | if (GNUNET_YES != opc->completed) | ||
253 | GNUNET_free_non_null (opc->data); | ||
254 | else | ||
255 | { | ||
256 | data = opc->data; | ||
257 | GNUNET_assert (NULL != data); | ||
258 | switch (data->pit) | ||
259 | { | ||
260 | case GNUNET_TESTBED_PIT_CONFIGURATION: | ||
261 | GNUNET_CONFIGURATION_destroy (data->details.cfg); | ||
262 | break; | ||
263 | case GNUNET_TESTBED_PIT_IDENTITY: | ||
264 | GNUNET_free (data->details.peer_identity); | ||
265 | break; | ||
266 | default: | ||
267 | GNUNET_assert (0); /* We should never reach here */ | ||
268 | } | ||
269 | GNUNET_free (data); | ||
270 | } | ||
271 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
272 | GNUNET_free (opc); | ||
273 | } | ||
274 | |||
275 | |||
276 | |||
277 | /** | ||
216 | * Lookup a peer by ID. | 278 | * Lookup a peer by ID. |
217 | * | 279 | * |
218 | * @param id global peer ID assigned to the peer | 280 | * @param id global peer ID assigned to the peer |
@@ -398,30 +460,22 @@ struct GNUNET_TESTBED_Operation * | |||
398 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, | 460 | GNUNET_TESTBED_peer_get_information (struct GNUNET_TESTBED_Peer *peer, |
399 | enum GNUNET_TESTBED_PeerInformationType pit) | 461 | enum GNUNET_TESTBED_PeerInformationType pit) |
400 | { | 462 | { |
401 | struct GNUNET_TESTBED_PeerGetConfigurationMessage *msg; | 463 | struct OperationContext *opc; |
402 | struct GNUNET_TESTBED_Operation *op; | ||
403 | struct PeerInfoData *data; | 464 | struct PeerInfoData *data; |
404 | 465 | ||
405 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); | 466 | GNUNET_assert (GNUNET_TESTBED_PIT_GENERIC != pit); |
406 | data = GNUNET_malloc (sizeof (struct PeerInfoData)); | 467 | data = GNUNET_malloc (sizeof (struct PeerInfoData)); |
407 | data->peer = peer; | 468 | data->peer = peer; |
408 | data->pit = pit; | 469 | data->pit = pit; |
409 | op = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Operation)); | 470 | opc = GNUNET_malloc (sizeof (struct OperationContext)); |
410 | op->type = OP_PEER_INFO; | 471 | opc->c = peer->controller; |
411 | op->operation_id = peer->controller->operation_counter++; | 472 | opc->data = data; |
412 | op->controller = peer->controller; | 473 | opc->type = OP_PEER_INFO; |
413 | op->data = data; | 474 | opc->id = opc->c->operation_counter++; |
414 | msg = GNUNET_malloc (sizeof (struct | 475 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_peer_getinfo, |
415 | GNUNET_TESTBED_PeerGetConfigurationMessage)); | 476 | &oprelease_peer_getinfo); |
416 | msg->header.size = htons | 477 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_peer_create, opc->op); |
417 | (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | 478 | return opc->op; |
418 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG); | ||
419 | msg->peer_id = htonl (peer->unique_id); | ||
420 | msg->operation_id = GNUNET_htonll (op->operation_id); | ||
421 | GNUNET_CONTAINER_DLL_insert_tail (peer->controller->op_head, | ||
422 | peer->controller->op_tail, op); | ||
423 | GNUNET_TESTBED_queue_message_ (peer->controller, &msg->header); | ||
424 | return op; | ||
425 | } | 479 | } |
426 | 480 | ||
427 | 481 | ||