diff options
-rw-r--r-- | src/include/gnunet_protocols.h | 17 | ||||
-rw-r--r-- | src/include/gnunet_testbed_service.h | 23 | ||||
-rw-r--r-- | src/testbed/testbed.h | 17 | ||||
-rw-r--r-- | src/testbed/testbed_api.c | 139 | ||||
-rw-r--r-- | src/testbed/testbed_api.h | 7 |
5 files changed, 190 insertions, 13 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index 3f19881a3..eb09a44ab 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1595,10 +1595,21 @@ extern "C" | |||
1595 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 482 | 1595 | #define GNUNET_MESSAGE_TYPE_TESTBED_LINK_CONTROLLERS_RESULT 482 |
1596 | 1596 | ||
1597 | /** | 1597 | /** |
1598 | * A controller receiving this message floods it to its directly-connected | ||
1599 | * sub-controllers and then stops and destroys all peers | ||
1600 | */ | ||
1601 | #define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS 483 | ||
1602 | |||
1603 | /** | ||
1604 | * The result of the shutdown peers operation | ||
1605 | */ | ||
1606 | #define GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS_RESULT 484 | ||
1607 | |||
1608 | /** | ||
1598 | * Not really a message, but for careful checks on the testbed messages; Should | 1609 | * Not really a message, but for careful checks on the testbed messages; Should |
1599 | * always be the maximum and never be used to send messages with this type | 1610 | * always be the maximum and never be used to send messages with this type |
1600 | */ | 1611 | */ |
1601 | #define GNUNET_MESSAGE_TYPE_TESTBED_MAX 483 | 1612 | #define GNUNET_MESSAGE_TYPE_TESTBED_MAX 485 |
1602 | 1613 | ||
1603 | /** | 1614 | /** |
1604 | * The initialization message towards gnunet-testbed-helper | 1615 | * The initialization message towards gnunet-testbed-helper |
@@ -1611,9 +1622,9 @@ extern "C" | |||
1611 | #define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 496 | 1622 | #define GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY 496 |
1612 | 1623 | ||
1613 | 1624 | ||
1614 | /** | 1625 | /****************************************************************************** |
1615 | * GNS. FIXME: document! | 1626 | * GNS. FIXME: document! |
1616 | */ | 1627 | *****************************************************************************/ |
1617 | #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 500 | 1628 | #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP 500 |
1618 | 1629 | ||
1619 | #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 501 | 1630 | #define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT 501 |
diff --git a/src/include/gnunet_testbed_service.h b/src/include/gnunet_testbed_service.h index 4ffcde76f..1dbba8fa2 100644 --- a/src/include/gnunet_testbed_service.h +++ b/src/include/gnunet_testbed_service.h | |||
@@ -912,6 +912,29 @@ GNUNET_TESTBED_peer_destroy (struct GNUNET_TESTBED_Peer *peer); | |||
912 | 912 | ||
913 | 913 | ||
914 | /** | 914 | /** |
915 | * Stops and destroys all peers. Is equivalent of calling | ||
916 | * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers, | ||
917 | * except that the peer stop event and operation finished event corresponding to | ||
918 | * the respective functions are not generated. This function should be called | ||
919 | * when there are no other pending operations. If there are pending operations, | ||
920 | * it will return NULL | ||
921 | * | ||
922 | * @param controller the controller to send this message to | ||
923 | * @param op_cls closure for the operation | ||
924 | * @param cb the callback to call when all peers are stopped and destroyed | ||
925 | * @param cb_cls the closure for the callback | ||
926 | * @return operation handle on success; NULL if any pending operations are | ||
927 | * present | ||
928 | */ | ||
929 | struct GNUNET_TESTBED_Operation * | ||
930 | GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *controller, | ||
931 | void *op_cls, | ||
932 | GNUNET_TESTBED_OperationCompletionCallback cb, | ||
933 | void *cb_cls); | ||
934 | |||
935 | |||
936 | |||
937 | /** | ||
915 | * Options for peer connections. | 938 | * Options for peer connections. |
916 | */ | 939 | */ |
917 | enum GNUNET_TESTBED_ConnectOption | 940 | enum GNUNET_TESTBED_ConnectOption |
diff --git a/src/testbed/testbed.h b/src/testbed/testbed.h index c94e6a54b..c9692c088 100644 --- a/src/testbed/testbed.h +++ b/src/testbed/testbed.h | |||
@@ -751,6 +751,23 @@ struct GNUNET_TESTBED_SlaveConfiguration | |||
751 | }; | 751 | }; |
752 | 752 | ||
753 | 753 | ||
754 | /** | ||
755 | * Shutdown peers message | ||
756 | */ | ||
757 | struct GNUNET_TESTBED_ShutdownPeersMessage | ||
758 | { | ||
759 | /** | ||
760 | * Type is GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS | ||
761 | */ | ||
762 | struct GNUNET_MessageHeader header; | ||
763 | |||
764 | /** | ||
765 | * Operation ID | ||
766 | */ | ||
767 | uint64_t operation_id GNUNET_PACKED; | ||
768 | }; | ||
769 | |||
770 | |||
754 | GNUNET_NETWORK_STRUCT_END | 771 | GNUNET_NETWORK_STRUCT_END |
755 | #endif | 772 | #endif |
756 | /* end of testbed.h */ | 773 | /* end of testbed.h */ |
diff --git a/src/testbed/testbed_api.c b/src/testbed/testbed_api.c index 4ea21b3a6..7011e6506 100644 --- a/src/testbed/testbed_api.c +++ b/src/testbed/testbed_api.c | |||
@@ -141,6 +141,23 @@ struct ControllerLinkData | |||
141 | 141 | ||
142 | 142 | ||
143 | /** | 143 | /** |
144 | * Date context for OP_SHUTDOWN_PEERS operations | ||
145 | */ | ||
146 | struct ShutdownPeersData | ||
147 | { | ||
148 | /** | ||
149 | * The operation completion callback to call | ||
150 | */ | ||
151 | GNUNET_TESTBED_OperationCompletionCallback cb; | ||
152 | |||
153 | /** | ||
154 | * The closure for the above callback | ||
155 | */ | ||
156 | void *cb_cls; | ||
157 | }; | ||
158 | |||
159 | |||
160 | /** | ||
144 | * This variable is set to the operation that has been last marked as done. It | 161 | * This variable is set to the operation that has been last marked as done. It |
145 | * is used to verify whether the state associated with an operation is valid | 162 | * is used to verify whether the state associated with an operation is valid |
146 | * after the first notify callback is called. Such checks are necessary for | 163 | * after the first notify callback is called. Such checks are necessary for |
@@ -246,6 +263,15 @@ handle_opsuccess (struct GNUNET_TESTBED_Controller *c, | |||
246 | //PEERDESTROYDATA | 263 | //PEERDESTROYDATA |
247 | } | 264 | } |
248 | break; | 265 | break; |
266 | case OP_SHUTDOWN_PEERS: | ||
267 | { | ||
268 | struct ShutdownPeersData *data; | ||
269 | |||
270 | data = opc->data; | ||
271 | GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */ | ||
272 | opc->data = NULL; | ||
273 | } | ||
274 | break; | ||
249 | default: | 275 | default: |
250 | GNUNET_assert (0); | 276 | GNUNET_assert (0); |
251 | } | 277 | } |
@@ -624,6 +650,15 @@ handle_op_fail_event (struct GNUNET_TESTBED_Controller *c, | |||
624 | case OP_FORWARDED: | 650 | case OP_FORWARDED: |
625 | GNUNET_assert (0); | 651 | GNUNET_assert (0); |
626 | case OP_LINK_CONTROLLERS: /* No secondary callback */ | 652 | case OP_LINK_CONTROLLERS: /* No secondary callback */ |
653 | break; | ||
654 | case OP_SHUTDOWN_PEERS: | ||
655 | { | ||
656 | struct ShutdownPeersData *data; | ||
657 | |||
658 | data = opc->data; | ||
659 | GNUNET_free (data); /* FIXME: Decide whether we call data->op_cb */ | ||
660 | opc->data = NULL; | ||
661 | } | ||
627 | break; | 662 | break; |
628 | default: | 663 | default: |
629 | GNUNET_break (0); | 664 | GNUNET_break (0); |
@@ -831,6 +866,15 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
831 | GNUNET_TESTBED_GenericOperationSuccessEventMessage *) | 866 | GNUNET_TESTBED_GenericOperationSuccessEventMessage *) |
832 | msg); | 867 | msg); |
833 | break; | 868 | break; |
869 | case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT: | ||
870 | GNUNET_assert (msize >= | ||
871 | sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage)); | ||
872 | status = | ||
873 | handle_op_fail_event (c, | ||
874 | (const struct | ||
875 | GNUNET_TESTBED_OperationFailureEventMessage *) | ||
876 | msg); | ||
877 | break; | ||
834 | case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS: | 878 | case GNUNET_MESSAGE_TYPE_TESTBED_CREATE_PEER_SUCCESS: |
835 | GNUNET_assert (msize == | 879 | GNUNET_assert (msize == |
836 | sizeof (struct | 880 | sizeof (struct |
@@ -867,15 +911,6 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
867 | (const struct | 911 | (const struct |
868 | GNUNET_TESTBED_ConnectionEventMessage *) msg); | 912 | GNUNET_TESTBED_ConnectionEventMessage *) msg); |
869 | break; | 913 | break; |
870 | case GNUNET_MESSAGE_TYPE_TESTBED_OPERATION_FAIL_EVENT: | ||
871 | GNUNET_assert (msize >= | ||
872 | sizeof (struct GNUNET_TESTBED_OperationFailureEventMessage)); | ||
873 | status = | ||
874 | handle_op_fail_event (c, | ||
875 | (const struct | ||
876 | GNUNET_TESTBED_OperationFailureEventMessage *) | ||
877 | msg); | ||
878 | break; | ||
879 | case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: | 914 | case GNUNET_MESSAGE_TYPE_TESTBED_SLAVE_CONFIGURATION: |
880 | GNUNET_assert (msize > sizeof (struct GNUNET_TESTBED_SlaveConfiguration)); | 915 | GNUNET_assert (msize > sizeof (struct GNUNET_TESTBED_SlaveConfiguration)); |
881 | status = | 916 | status = |
@@ -1928,4 +1963,90 @@ GNUNET_TESTBED_get_next_op_id (struct GNUNET_TESTBED_Controller * controller) | |||
1928 | } | 1963 | } |
1929 | 1964 | ||
1930 | 1965 | ||
1966 | /** | ||
1967 | * Function called when a shutdown peers operation is ready | ||
1968 | * | ||
1969 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
1970 | */ | ||
1971 | static void | ||
1972 | opstart_shutdown_peers (void *cls) | ||
1973 | { | ||
1974 | struct OperationContext *opc = cls; | ||
1975 | struct GNUNET_TESTBED_ShutdownPeersMessage *msg; | ||
1976 | |||
1977 | opc->state = OPC_STATE_STARTED; | ||
1978 | msg = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)); | ||
1979 | msg->header.size = | ||
1980 | htons (sizeof (struct GNUNET_TESTBED_ShutdownPeersMessage)); | ||
1981 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_SHUTDOWN_PEERS); | ||
1982 | msg->operation_id = GNUNET_htonll (opc->id); | ||
1983 | GNUNET_CONTAINER_DLL_insert_tail (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
1984 | GNUNET_TESTBED_queue_message_ (opc->c, &msg->header); | ||
1985 | } | ||
1986 | |||
1987 | |||
1988 | /** | ||
1989 | * Callback which will be called when shutdown peers operation is released | ||
1990 | * | ||
1991 | * @param cls the closure from GNUNET_TESTBED_operation_create_() | ||
1992 | */ | ||
1993 | static void | ||
1994 | oprelease_shutdown_peers (void *cls) | ||
1995 | { | ||
1996 | struct OperationContext *opc = cls; | ||
1997 | |||
1998 | if (OPC_STATE_FINISHED != opc->state) | ||
1999 | { | ||
2000 | GNUNET_free (opc->data); | ||
2001 | GNUNET_CONTAINER_DLL_remove (opc->c->ocq_head, opc->c->ocq_tail, opc); | ||
2002 | } | ||
2003 | GNUNET_free (opc); | ||
2004 | } | ||
2005 | |||
2006 | |||
2007 | /** | ||
2008 | * Stops and destroys all peers. Is equivalent of calling | ||
2009 | * GNUNET_TESTBED_peer_stop() and GNUNET_TESTBED_peer_destroy() on all peers, | ||
2010 | * except that the peer stop event and operation finished event corresponding to | ||
2011 | * the respective functions are not generated. This function should be called | ||
2012 | * when there are no other pending operations. If there are pending operations, | ||
2013 | * it will return NULL | ||
2014 | * | ||
2015 | * @param controller the controller to send this message to | ||
2016 | * @param op_cls closure for the operation | ||
2017 | * @param cb the callback to call when all peers are stopped and destroyed | ||
2018 | * @param cb_cls the closure for the callback | ||
2019 | * @return operation handle on success; NULL if any pending operations are | ||
2020 | * present | ||
2021 | */ | ||
2022 | struct GNUNET_TESTBED_Operation * | ||
2023 | GNUNET_TESTBED_shutdown_peers (struct GNUNET_TESTBED_Controller *controller, | ||
2024 | void *op_cls, | ||
2025 | GNUNET_TESTBED_OperationCompletionCallback cb, | ||
2026 | void *cb_cls) | ||
2027 | { | ||
2028 | struct OperationContext *opc; | ||
2029 | struct ShutdownPeersData *data; | ||
2030 | |||
2031 | if (NULL != controller->ocq_head) | ||
2032 | return NULL; | ||
2033 | data = GNUNET_malloc (sizeof (struct ShutdownPeersData)); | ||
2034 | data->cb = cb; | ||
2035 | data->cb_cls = cb_cls; | ||
2036 | opc = GNUNET_malloc (sizeof (struct OperationContext)); | ||
2037 | opc->c = controller; | ||
2038 | opc->op_cls = op_cls; | ||
2039 | opc->data = data; | ||
2040 | opc->id = GNUNET_TESTBED_get_next_op_id (controller); | ||
2041 | opc->type = OP_SHUTDOWN_PEERS; | ||
2042 | opc->state = OPC_STATE_INIT; | ||
2043 | opc->op = GNUNET_TESTBED_operation_create_ (opc, &opstart_shutdown_peers, | ||
2044 | &oprelease_shutdown_peers); | ||
2045 | GNUNET_TESTBED_operation_queue_insert_ (opc->c->opq_parallel_operations, | ||
2046 | opc->op); | ||
2047 | GNUNET_TESTBED_operation_begin_wait_ (opc->op); | ||
2048 | return opc->op; | ||
2049 | } | ||
2050 | |||
2051 | |||
1931 | /* end of testbed_api.c */ | 2052 | /* end of testbed_api.c */ |
diff --git a/src/testbed/testbed_api.h b/src/testbed/testbed_api.h index 000aeeda4..65e9efe36 100644 --- a/src/testbed/testbed_api.h +++ b/src/testbed/testbed_api.h | |||
@@ -85,7 +85,12 @@ enum OperationType | |||
85 | /** | 85 | /** |
86 | * Get slave config operation | 86 | * Get slave config operation |
87 | */ | 87 | */ |
88 | OP_GET_SLAVE_CONFIG | 88 | OP_GET_SLAVE_CONFIG, |
89 | |||
90 | /** | ||
91 | * Stop and destroy all peers | ||
92 | */ | ||
93 | OP_SHUTDOWN_PEERS | ||
89 | }; | 94 | }; |
90 | 95 | ||
91 | 96 | ||