diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-10 20:33:02 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-10 20:33:02 +0000 |
commit | d0e3840931750ca4bf4848d950ab9a0c0b5022bc (patch) | |
tree | 68c15adfa369df0b33dbf32395838b920c9d9330 /src/testbed | |
parent | 9bd27b49f6c13af2d539e3114be122805fea8312 (diff) | |
download | gnunet-d0e3840931750ca4bf4848d950ab9a0c0b5022bc.tar.gz gnunet-d0e3840931750ca4bf4848d950ab9a0c0b5022bc.zip |
cleanup when operations fail
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/testbed_api.c | 74 | ||||
-rw-r--r-- | src/testbed/testbed_api_peers.c | 7 |
2 files changed, 60 insertions, 21 deletions
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index fcbff7004..c1709333e 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -626,10 +626,9 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
626 | *msg) | 626 | *msg) |
627 | { | 627 | { |
628 | struct OperationContext *opc; | 628 | struct OperationContext *opc; |
629 | char *emsg; | 629 | const char *emsg; |
630 | uint64_t op_id; | 630 | uint64_t op_id; |
631 | struct GNUNET_TESTBED_EventInformation event; | 631 | struct GNUNET_TESTBED_EventInformation event; |
632 | uint16_t msize; | ||
633 | 632 | ||
634 | op_id = GNUNET_ntohll (msg->operation_id); | 633 | op_id = GNUNET_ntohll (msg->operation_id); |
635 | if (NULL == (opc = find_opc (c, op_id))) | 634 | if (NULL == (opc = find_opc (c, op_id))) |
@@ -637,6 +636,7 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
637 | LOG_DEBUG ("Operation not found\n"); | 636 | LOG_DEBUG ("Operation not found\n"); |
638 | return GNUNET_YES; | 637 | return GNUNET_YES; |
639 | } | 638 | } |
639 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
640 | if (OP_FORWARDED == opc->type) | 640 | if (OP_FORWARDED == opc->type) |
641 | { | 641 | { |
642 | struct ForwardedOperationData *fo_data; | 642 | struct ForwardedOperationData *fo_data; |
@@ -644,26 +644,22 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
644 | fo_data = opc->data; | 644 | fo_data = opc->data; |
645 | if (NULL != fo_data->cc) | 645 | if (NULL != fo_data->cc) |
646 | fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); | 646 | fo_data->cc (fo_data->cc_cls, (const struct GNUNET_MessageHeader *) msg); |
647 | GNUNET_CONTAINER_DLL_remove (c->ocq_head, c->ocq_tail, opc); | ||
648 | GNUNET_free (fo_data); | 647 | GNUNET_free (fo_data); |
649 | GNUNET_free (opc); | 648 | GNUNET_free (opc); |
650 | return GNUNET_YES; | 649 | return GNUNET_YES; |
651 | } | 650 | } |
652 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
653 | opc->state = OPC_STATE_FINISHED; | 651 | opc->state = OPC_STATE_FINISHED; |
654 | switch (opc->type) | 652 | emsg = GNUNET_TESTBED_parse_error_string_ (msg); |
655 | { | 653 | if (NULL == emsg) |
656 | /* FIXME: Cleanup the data pointer depending on the type of opc */ | 654 | emsg = "Unknown error"; |
657 | default: | 655 | if (OP_PEER_INFO == opc->type) |
658 | GNUNET_break (0); | ||
659 | } | ||
660 | msize = ntohs (msg->header.size); | ||
661 | emsg = NULL; | ||
662 | if (msize > sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage)) | ||
663 | { | 656 | { |
664 | msize -= sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); | 657 | struct PeerInfoData *data; |
665 | emsg = (char *) &msg[1]; | 658 | data = opc->data; |
666 | GNUNET_assert ('\0' == emsg[msize - 1]); | 659 | if (NULL != data->cb) |
660 | data->cb (data->cb_cls, opc->op, NULL, emsg); | ||
661 | GNUNET_free (data); | ||
662 | return GNUNET_YES; /* We do not call controller callback for peer info */ | ||
667 | } | 663 | } |
668 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && | 664 | if ((0 != (GNUNET_TESTBED_ET_OPERATION_FINISHED & c->event_mask)) && |
669 | (NULL != c->cc)) | 665 | (NULL != c->cc)) |
@@ -675,6 +671,48 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
675 | event.details.operation_finished.generic = NULL; | 671 | event.details.operation_finished.generic = NULL; |
676 | c->cc (c->cc_cls, &event); | 672 | c->cc (c->cc_cls, &event); |
677 | } | 673 | } |
674 | switch (opc->type) | ||
675 | { | ||
676 | case OP_PEER_CREATE: | ||
677 | { | ||
678 | struct PeerCreateData *data; | ||
679 | data = opc->data; | ||
680 | GNUNET_free (data->peer); | ||
681 | if (NULL != data->cb) | ||
682 | data->cb (data->cls, NULL, emsg); | ||
683 | GNUNET_free (data); | ||
684 | } | ||
685 | break; | ||
686 | case OP_PEER_START: | ||
687 | case OP_PEER_STOP: | ||
688 | { | ||
689 | struct PeerEventData *data; | ||
690 | data = opc->data; | ||
691 | if (NULL != data->pcc) | ||
692 | data->pcc (data->pcc_cls, emsg); | ||
693 | GNUNET_free (data); | ||
694 | } | ||
695 | break; | ||
696 | case OP_PEER_DESTROY: | ||
697 | break; | ||
698 | case OP_PEER_INFO: | ||
699 | GNUNET_assert (0); | ||
700 | case OP_OVERLAY_CONNECT: | ||
701 | { | ||
702 | struct OverlayConnectData *data; | ||
703 | data = opc->data; | ||
704 | if (NULL != data->cb) | ||
705 | data->cb (data->cb_cls, opc->op, emsg); | ||
706 | GNUNET_free (data); | ||
707 | } | ||
708 | break; | ||
709 | case OP_FORWARDED: | ||
710 | GNUNET_assert (0); | ||
711 | case OP_LINK_CONTROLLERS: /* No secondary callback */ | ||
712 | break; | ||
713 | default: | ||
714 | GNUNET_break (0); | ||
715 | } | ||
678 | return GNUNET_YES; | 716 | return GNUNET_YES; |
679 | } | 717 | } |
680 | 718 | ||
@@ -1760,7 +1798,7 @@ GNUNET_TESTBED_get_config_from_peerinfo_msg_ (const struct | |||
1760 | 1798 | ||
1761 | 1799 | ||
1762 | /** | 1800 | /** |
1763 | * Checks the integrity of the OpeationFailureEventMessage and if good returns | 1801 | * Checks the integrity of the OperationFailureEventMessage and if good returns |
1764 | * the error message it contains. | 1802 | * the error message it contains. |
1765 | * | 1803 | * |
1766 | * @param msg the OperationFailureEventMessage | 1804 | * @param msg the OperationFailureEventMessage |
@@ -1775,7 +1813,7 @@ GNUNET_TESTBED_parse_error_string_ (const struct | |||
1775 | const char *emsg; | 1813 | const char *emsg; |
1776 | 1814 | ||
1777 | msize = ntohs (msg->header.size); | 1815 | msize = ntohs (msg->header.size); |
1778 | if (sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage) == msize) | 1816 | if (sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage) >= msize) |
1779 | return NULL; | 1817 | return NULL; |
1780 | msize -= sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); | 1818 | msize -= sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage); |
1781 | emsg = (const char *) &msg[1]; | 1819 | emsg = (const char *) &msg[1]; |
diff --git a/src/testbed/testbed_api_peers.c b/src/testbed/testbed_api_peers.c index fef701f91..b5f55b8f8 100644 --- a/src/testbed/testbed_api_peers.c +++ b/src/testbed/testbed_api_peers.c | |||
@@ -562,9 +562,10 @@ GNUNET_TESTBED_peer_stop (struct GNUNET_TESTBED_Peer *peer, | |||
562 | 562 | ||
563 | 563 | ||
564 | /** | 564 | /** |
565 | * Request information about a peer. The controller callback will be called with | 565 | * Request information about a peer. The controller callback will not be called |
566 | * event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this | 566 | * with event type GNUNET_TESTBED_ET_OPERATION_FINISHED when result for this |
567 | * operation is available | 567 | * operation is available. Instead, the GNUNET_TESTBED_PeerInfoCallback() will |
568 | * be called. | ||
568 | * | 569 | * |
569 | * @param peer peer to request information about | 570 | * @param peer peer to request information about |
570 | * @param pit desired information | 571 | * @param pit desired information |