diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-24 09:13:32 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-07-24 09:13:32 +0000 |
commit | a6f6e3422767655790228f5b686a9cf99ed51205 (patch) | |
tree | cb25a24850bcb276943abd7b8ed8c7899a244c71 /src/testbed | |
parent | 882e257afa29bdfa8d0d1e8bd63e40749e361f63 (diff) | |
download | gnunet-a6f6e3422767655790228f5b686a9cf99ed51205.tar.gz gnunet-a6f6e3422767655790228f5b686a9cf99ed51205.zip |
-handling peer get configuration at client
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 553e1404a..466e19339 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -396,6 +396,93 @@ handle_peer_event (struct GNUNET_TESTBED_Controller *c, | |||
396 | 396 | ||
397 | 397 | ||
398 | /** | 398 | /** |
399 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG message from | ||
400 | * controller (testbed service) | ||
401 | * | ||
402 | * @param c the controller handler | ||
403 | * @param msg message received | ||
404 | * @return GNUNET_YES if we can continue receiving from service; GNUNET_NO if | ||
405 | * not | ||
406 | */ | ||
407 | static int | ||
408 | handle_peer_config (struct GNUNET_TESTBED_Controller *c, | ||
409 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *msg) | ||
410 | { | ||
411 | struct GNUNET_TESTBED_Operation *op; | ||
412 | struct GNUNET_TESTBED_Peer *peer; | ||
413 | struct GNUNET_TESTBED_EventInformation info; | ||
414 | uint64_t op_id; | ||
415 | |||
416 | op_id = GNUNET_ntohll (msg->operation_id); | ||
417 | for (op = c->op_head; NULL != op; op = op->next) | ||
418 | { | ||
419 | if (op->operation_id == op_id) | ||
420 | break; | ||
421 | } | ||
422 | if (NULL == op) | ||
423 | { | ||
424 | LOG_DEBUG ("Operation not found"); | ||
425 | return GNUNET_YES; | ||
426 | } | ||
427 | peer = op->data; | ||
428 | GNUNET_assert (NULL != peer); | ||
429 | GNUNET_assert (ntohl (msg->peer_id) == peer->unique_id); | ||
430 | if (0 == (c->event_mask & (1L << GNUNET_TESTBED_ET_OPERATION_FINISHED))) | ||
431 | { | ||
432 | GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); | ||
433 | GNUNET_free (op); | ||
434 | return GNUNET_YES; | ||
435 | } | ||
436 | info.type = GNUNET_TESTBED_ET_OPERATION_FINISHED; | ||
437 | info.details.operation_finished.operation = op; | ||
438 | info.details.operation_finished.op_cls = NULL; | ||
439 | info.details.operation_finished.emsg = NULL; | ||
440 | info.details.operation_finished.pit = op->operation_id; | ||
441 | switch (op->operation_id) | ||
442 | { | ||
443 | case GNUNET_TESTBED_PIT_IDENTITY: | ||
444 | { | ||
445 | struct GNUNET_PeerIdentity *peer_identity; | ||
446 | |||
447 | peer_identity = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | ||
448 | (void) memcpy (peer_identity, &msg->peer_identity, sizeof (struct GNUNET_PeerIdentity)); | ||
449 | info.details.operation_finished.op_result.pid = peer_identity; | ||
450 | } | ||
451 | break; | ||
452 | case GNUNET_TESTBED_PIT_CONFIGURATION: | ||
453 | { | ||
454 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
455 | char *config; | ||
456 | uLong config_size; | ||
457 | int ret; | ||
458 | uint16_t msize; | ||
459 | |||
460 | config_size = (uLong) ntohs (msg->config_size); | ||
461 | config = GNUNET_malloc (config_size); | ||
462 | msize = ntohs (msg->header.size); | ||
463 | msize -= sizeof (struct GNUNET_TESTBED_PeerConfigurationInformationMessage); | ||
464 | if (Z_OK != (ret = uncompress ((Bytef *) config, &config_size, | ||
465 | (const Bytef *) &msg[1], (uLong) msize))) | ||
466 | GNUNET_assert (0); | ||
467 | cfg = GNUNET_CONFIGURATION_create (); | ||
468 | GNUNET_assert (GNUNET_OK == | ||
469 | GNUNET_CONFIGURATION_deserialize (cfg, config, | ||
470 | (size_t) config_size, GNUNET_NO)); | ||
471 | info.details.operation_finished.op_result.cfg = cfg; | ||
472 | } | ||
473 | break; | ||
474 | case GNUNET_TESTBED_PIT_GENERIC: | ||
475 | GNUNET_assert (0); /* never reach here */ | ||
476 | break; | ||
477 | } | ||
478 | c->cc (c->cc_cls, &info); | ||
479 | GNUNET_CONTAINER_DLL_remove (c->op_head, c->op_tail, op); | ||
480 | GNUNET_free (op); | ||
481 | return GNUNET_YES; | ||
482 | } | ||
483 | |||
484 | |||
485 | /** | ||
399 | * Handler for messages from controller (testbed service) | 486 | * Handler for messages from controller (testbed service) |
400 | * | 487 | * |
401 | * @param cls the controller handler | 488 | * @param cls the controller handler |
@@ -437,6 +524,10 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
437 | status = | 524 | status = |
438 | handle_peer_event (c, (const struct GNUNET_TESTBED_PeerEventMessage *) msg); | 525 | handle_peer_event (c, (const struct GNUNET_TESTBED_PeerEventMessage *) msg); |
439 | break; | 526 | break; |
527 | case GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG: | ||
528 | status = | ||
529 | handle_peer_config | ||
530 | (c, (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) msg); | ||
440 | default: | 531 | default: |
441 | GNUNET_break (0); | 532 | GNUNET_break (0); |
442 | } | 533 | } |