diff options
-rw-r--r-- | src/cadet/Makefile.am | 6 | ||||
-rw-r--r-- | src/cadet/test_cadeT.c | 141 | ||||
-rw-r--r-- | src/cadet/test_cadeT_util.c | 244 | ||||
-rw-r--r-- | src/cadet/test_cadeT_util.h | 78 |
4 files changed, 469 insertions, 0 deletions
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index 2289a2d96..80a2d113d 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -85,6 +85,7 @@ endif | |||
85 | 85 | ||
86 | if HAVE_TESTING | 86 | if HAVE_TESTING |
87 | check_PROGRAMS = \ | 87 | check_PROGRAMS = \ |
88 | test_cadet_2_channel_resumption \ | ||
88 | test_cadet_local_mq \ | 89 | test_cadet_local_mq \ |
89 | test_cadet_2_forward \ | 90 | test_cadet_2_forward \ |
90 | test_cadet_2_forward \ | 91 | test_cadet_2_forward \ |
@@ -141,6 +142,11 @@ dep_cadet_test_lib = \ | |||
141 | libgnunetcadettest.la \ | 142 | libgnunetcadettest.la \ |
142 | $(top_builddir)/src/statistics/libgnunetstatistics.la | 143 | $(top_builddir)/src/statistics/libgnunetstatistics.la |
143 | 144 | ||
145 | test_cadet_2_channel_resumption_SOURCES = \ | ||
146 | test_cadeT.c \ | ||
147 | test_cadeT_util.c test_cadeT_util.h | ||
148 | test_cadet_2_channel_resumption_LDADD = $(ld_cadet_test_lib) | ||
149 | |||
144 | test_cadet_2_forward_SOURCES = \ | 150 | test_cadet_2_forward_SOURCES = \ |
145 | test_cadet.c | 151 | test_cadet.c |
146 | test_cadet_2_forward_LDADD = $(ld_cadet_test_lib) | 152 | test_cadet_2_forward_LDADD = $(ld_cadet_test_lib) |
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c new file mode 100644 index 000000000..97f315167 --- /dev/null +++ b/src/cadet/test_cadeT.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file cadet/test_cadeT.c | ||
22 | * @brief testcase for cadet.c | ||
23 | * @author xrs | ||
24 | * | ||
25 | * Goal: | ||
26 | * - test session resumption after a hard channel breakup | ||
27 | * | ||
28 | * ToDos: | ||
29 | * x setup peer A | ||
30 | * x setup peer B | ||
31 | * x setup cadet on peer B listening on port "cadet_port" | ||
32 | * x create a channel from peer A to B | ||
33 | * x create method to find out KX initiator | ||
34 | * x send a message over channel | ||
35 | * x check if message was received | ||
36 | * - breakup the connection without the receiver receiving a channel destroy message | ||
37 | * - assert tunnel is down | ||
38 | * - resume channel (second handshake for tunnel) | ||
39 | * - send second message over channel | ||
40 | * - check if message was receveived | ||
41 | * - end test | ||
42 | * | ||
43 | * Questions: | ||
44 | * - can we simulate hard breakups with TESTBED? | ||
45 | * - GNUNET_TESTBED_underlay_configure_link not implemented | ||
46 | * - GNUNET_TESTBED_underlaylinkmodel_set_link not usable | ||
47 | * - GNUNET_TESTBED_peer_stop evokes standard service disconnect | ||
48 | * - how can we test the sublayers of CADET, e.g. connection, tunnel, channel? | ||
49 | * | ||
50 | * Development | ||
51 | * - red -> green -> refactor (cyclic) | ||
52 | * - be aware of Continuation Passing Style (CPS) programming | ||
53 | */ | ||
54 | #include "platform.h" | ||
55 | #include "gnunet_testbed_service.h" | ||
56 | #include "cadet.h" | ||
57 | #include <test_cadeT_util.h> | ||
58 | |||
59 | #define CONFIG "test_cadet.conf" | ||
60 | #define TESTPROGAM_NAME "test-cadet-channel-resumption" | ||
61 | |||
62 | /****************************** TEST LOGIC ********************************/ | ||
63 | |||
64 | static int kx_initiator; | ||
65 | static struct GNUNET_TESTBED_UnderlayLinkModel *model; | ||
66 | |||
67 | static void | ||
68 | send_message () | ||
69 | { | ||
70 | struct GNUNET_MQ_Envelope *envelope; | ||
71 | struct GNUNET_MessageHeader *msg; | ||
72 | int *data; | ||
73 | |||
74 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
75 | |||
76 | envelope = GNUNET_MQ_msg_extra (msg, 10000, | ||
77 | GNUNET_MESSAGE_TYPE_DUMMY); | ||
78 | data = (int *) &msg[1]; | ||
79 | *data = 1000; | ||
80 | |||
81 | GNUNET_MQ_send (GNUNET_CADET_get_mq (test_peers[0].channel), | ||
82 | envelope); | ||
83 | } | ||
84 | |||
85 | int | ||
86 | check_message (void *cls, | ||
87 | const struct GNUNET_MessageHeader *message) | ||
88 | { | ||
89 | return GNUNET_OK; /* all is well-formed */ | ||
90 | } | ||
91 | |||
92 | void | ||
93 | handle_message (void *cls, | ||
94 | const struct GNUNET_MessageHeader *msg) | ||
95 | { | ||
96 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
97 | |||
98 | /* | ||
99 | model = GNUNET_TESTBED_underlaylinkmodel_create (test_peers[1].testbed_peer, | ||
100 | GNUNET_TESTBED_UNDERLAYLINKMODELTYPE_BLACKLIST); | ||
101 | GNUNET_TESTBED_underlaylinkmodel_set_link (model, | ||
102 | test_peers[0].testbed_peer, | ||
103 | 0, 100, 0); | ||
104 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s: Modified link model.\n", __func__); | ||
105 | */ | ||
106 | send_message(); | ||
107 | } | ||
108 | |||
109 | /** | ||
110 | * This function is called after all testbed management is done and the | ||
111 | * testbed peers are ready for the actual test logic. | ||
112 | * Use struct test_peers[i] to control the peers. | ||
113 | */ | ||
114 | void | ||
115 | run_test () | ||
116 | { | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
118 | |||
119 | kx_initiator = (0 < GNUNET_memcmp (&test_peers[0].id, &test_peers[1].id)) ? 1 : 0; | ||
120 | |||
121 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
122 | "KX initiator is peer %s (idx:%i)\n", | ||
123 | GNUNET_i2s (&test_peers[kx_initiator].id), | ||
124 | kx_initiator); | ||
125 | |||
126 | for (int i=0; i<10; i++) | ||
127 | send_message(); | ||
128 | } | ||
129 | |||
130 | |||
131 | int | ||
132 | main (int argc, char *argv[]) | ||
133 | { | ||
134 | GNUNET_TESTBED_test_run (TESTPROGAM_NAME, | ||
135 | CONFIG, | ||
136 | REQUESTED_PEERS, 0LL, NULL, NULL, | ||
137 | prepare_test, NULL); | ||
138 | return test_result; | ||
139 | } | ||
140 | |||
141 | /* end of test_template_api.c */ | ||
diff --git a/src/cadet/test_cadeT_util.c b/src/cadet/test_cadeT_util.c new file mode 100644 index 000000000..f2082a006 --- /dev/null +++ b/src/cadet/test_cadeT_util.c | |||
@@ -0,0 +1,244 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file cadet/test_cadeT_util.c | ||
22 | * @brief testcase for cadet.c | ||
23 | * @author xrs | ||
24 | */ | ||
25 | |||
26 | #include <test_cadeT_util.h> | ||
27 | |||
28 | /** | ||
29 | * Testbed operation for connecting to the services. | ||
30 | */ | ||
31 | static struct GNUNET_TESTBED_Operation *testbed_to_svc[REQUESTED_PEERS]; | ||
32 | |||
33 | /** | ||
34 | * Testbed operation for requesting peer information. | ||
35 | */ | ||
36 | static struct GNUNET_TESTBED_Operation *testbed_info_req[REQUESTED_PEERS]; | ||
37 | |||
38 | /** | ||
39 | * Port name kown by the two peers. | ||
40 | */ | ||
41 | static struct GNUNET_HashCode hashed_portname; | ||
42 | |||
43 | /** | ||
44 | * Result of the test. | ||
45 | */ | ||
46 | int test_result = 0; | ||
47 | |||
48 | /** | ||
49 | * Counter for gathering peerinformation. | ||
50 | */ | ||
51 | static int peerinfo_cnt = 0; | ||
52 | |||
53 | /************************** TESBED MANAGEMENT *****************************/ | ||
54 | |||
55 | static void | ||
56 | shutdown_task (void *cls) | ||
57 | { | ||
58 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
59 | |||
60 | for (int i=0; i<REQUESTED_PEERS; i++) | ||
61 | { | ||
62 | GNUNET_TESTBED_operation_done (testbed_to_svc[i]); | ||
63 | GNUNET_TESTBED_operation_done (testbed_info_req[i]); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | static void | ||
68 | timeout () | ||
69 | { | ||
70 | GNUNET_SCHEDULER_shutdown (); | ||
71 | } | ||
72 | |||
73 | static void | ||
74 | disconnect_from_peer (void *cls, | ||
75 | void *op_result) | ||
76 | { | ||
77 | struct GNUNET_CADET_Handle *cadet = op_result; | ||
78 | |||
79 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
80 | |||
81 | GNUNET_CADET_disconnect (cadet); | ||
82 | } | ||
83 | |||
84 | static void | ||
85 | disconnect_channel (void *cls, | ||
86 | const struct GNUNET_CADET_Channel *channel) | ||
87 | { | ||
88 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
89 | } | ||
90 | |||
91 | static void * | ||
92 | setup_initiating_peer (void *cls, | ||
93 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
94 | { | ||
95 | struct GNUNET_CADET_Handle *cadet; | ||
96 | struct GNUNET_CADET_Channel *channel; | ||
97 | |||
98 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
99 | |||
100 | cadet = GNUNET_CADET_connect (cfg); | ||
101 | test_peers[0].cadet = cadet; | ||
102 | |||
103 | if (NULL == cadet) | ||
104 | GNUNET_SCHEDULER_shutdown (); | ||
105 | |||
106 | channel = GNUNET_CADET_channel_create (cadet, | ||
107 | NULL, | ||
108 | &test_peers[1].id, | ||
109 | &hashed_portname, | ||
110 | NULL, | ||
111 | &disconnect_channel, | ||
112 | NULL); | ||
113 | test_peers[0].channel = channel; | ||
114 | |||
115 | return cadet; | ||
116 | } | ||
117 | |||
118 | static void * | ||
119 | handle_port_connects (void *cls, | ||
120 | struct GNUNET_CADET_Channel *channel, | ||
121 | const struct GNUNET_PeerIdentity *source) | ||
122 | { | ||
123 | return NULL; | ||
124 | } | ||
125 | |||
126 | static void | ||
127 | handle_port_disconnects (void *cls, | ||
128 | const struct GNUNET_CADET_Channel *channel) | ||
129 | { | ||
130 | } | ||
131 | |||
132 | static void * | ||
133 | setup_listening_peer (void *cls, | ||
134 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
135 | { | ||
136 | struct GNUNET_CADET_Handle *cadet; | ||
137 | struct GNUNET_CADET_Port *port; | ||
138 | struct GNUNET_MQ_MessageHandler msg_handlers[] = { | ||
139 | GNUNET_MQ_hd_fixed_size (message, | ||
140 | GNUNET_MESSAGE_TYPE_DUMMY, | ||
141 | struct GNUNET_MessageHeader, | ||
142 | NULL), | ||
143 | GNUNET_MQ_handler_end () | ||
144 | }; | ||
145 | |||
146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
147 | |||
148 | cadet = GNUNET_CADET_connect (cfg); | ||
149 | test_peers[1].cadet = cadet; | ||
150 | |||
151 | if (NULL == cadet) | ||
152 | GNUNET_SCHEDULER_shutdown (); | ||
153 | |||
154 | GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname); | ||
155 | port = GNUNET_CADET_open_port (cadet, &hashed_portname, | ||
156 | &handle_port_connects, | ||
157 | NULL, | ||
158 | NULL, | ||
159 | &handle_port_disconnects, | ||
160 | msg_handlers); | ||
161 | |||
162 | return cadet; | ||
163 | } | ||
164 | |||
165 | static void | ||
166 | check_test_readyness (void *cls, | ||
167 | struct GNUNET_TESTBED_Operation *op, | ||
168 | void *ca_result, | ||
169 | const char *emsg) | ||
170 | { | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
172 | |||
173 | if (NULL != test_peers[0].cadet && NULL != test_peers[1].cadet) | ||
174 | run_test(); | ||
175 | } | ||
176 | |||
177 | static int | ||
178 | peerinfo_complete () | ||
179 | { | ||
180 | return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO; | ||
181 | } | ||
182 | |||
183 | static void | ||
184 | connect_to_service (void *cb_cls, | ||
185 | struct GNUNET_TESTBED_Operation *op, | ||
186 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
187 | const char *emsg) | ||
188 | { | ||
189 | struct TEST_PEERS *test_peer = cb_cls; | ||
190 | |||
191 | // Store peer ID. | ||
192 | test_peer->id = *(pinfo->result.id); | ||
193 | |||
194 | if (peerinfo_complete()) | ||
195 | { | ||
196 | testbed_to_svc[1] = | ||
197 | GNUNET_TESTBED_service_connect (NULL, test_peers[1].testbed_peer, | ||
198 | "cadet", | ||
199 | &check_test_readyness, NULL, | ||
200 | &setup_listening_peer, | ||
201 | &disconnect_from_peer, NULL); | ||
202 | testbed_to_svc[0] = | ||
203 | GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer, | ||
204 | "cadet", | ||
205 | &check_test_readyness, NULL, | ||
206 | &setup_initiating_peer, | ||
207 | &disconnect_from_peer, NULL); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | void | ||
212 | prepare_test (void *cls, | ||
213 | struct GNUNET_TESTBED_RunHandle *h, | ||
214 | unsigned int num_peers, | ||
215 | struct GNUNET_TESTBED_Peer **peers, | ||
216 | unsigned int links_succeeded, | ||
217 | unsigned int links_failed) | ||
218 | { | ||
219 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); | ||
220 | |||
221 | GNUNET_assert (GNUNET_NO == links_failed); | ||
222 | GNUNET_assert (REQUESTED_PEERS == num_peers); | ||
223 | |||
224 | for (int i=0; i<REQUESTED_PEERS; i++) | ||
225 | { | ||
226 | test_peers[i].ready = GNUNET_NO; | ||
227 | test_peers[i].idx = i; | ||
228 | test_peers[i].testbed_peer = peers[i]; | ||
229 | } | ||
230 | |||
231 | testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0], | ||
232 | GNUNET_TESTBED_PIT_IDENTITY, | ||
233 | &connect_to_service, | ||
234 | &test_peers[0]); | ||
235 | testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1], | ||
236 | GNUNET_TESTBED_PIT_IDENTITY, | ||
237 | &connect_to_service, | ||
238 | &test_peers[1]); | ||
239 | |||
240 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
241 | |||
242 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT_IN_SEC), | ||
243 | &timeout, NULL); | ||
244 | } | ||
diff --git a/src/cadet/test_cadeT_util.h b/src/cadet/test_cadeT_util.h new file mode 100644 index 000000000..1c85abab6 --- /dev/null +++ b/src/cadet/test_cadeT_util.h | |||
@@ -0,0 +1,78 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file cadet/test_cadeT_util.h | ||
22 | * @brief testcase for cadet.c | ||
23 | * @author xrs | ||
24 | */ | ||
25 | |||
26 | #include "platform.h" | ||
27 | #include "gnunet_testbed_service.h" | ||
28 | #include "cadet.h" | ||
29 | |||
30 | #define REQUESTED_PEERS 2 | ||
31 | #define TIMEOUT_IN_SEC 5 | ||
32 | #define PORTNAME "cadet_port" | ||
33 | |||
34 | int test_result; | ||
35 | |||
36 | void prepare_test (); | ||
37 | |||
38 | void run_test (); | ||
39 | |||
40 | void handle_message (void *cls, | ||
41 | const struct GNUNET_MessageHeader *msg); | ||
42 | |||
43 | /** | ||
44 | * Structure for storing information of testbed peers. | ||
45 | */ | ||
46 | struct TEST_PEERS | ||
47 | { | ||
48 | /** | ||
49 | * Index of the peer. | ||
50 | */ | ||
51 | int idx; | ||
52 | |||
53 | /** | ||
54 | * Peer Identity. | ||
55 | */ | ||
56 | struct GNUNET_PeerIdentity id; | ||
57 | |||
58 | /** | ||
59 | * Handle of TESTBED peer. | ||
60 | */ | ||
61 | struct GNUNET_TESTBED_Peer *testbed_peer; | ||
62 | |||
63 | /** | ||
64 | * Testbed management is finished and test peer is ready for test logic. | ||
65 | */ | ||
66 | int ready; | ||
67 | |||
68 | /** | ||
69 | * Channel of initiating peer. | ||
70 | */ | ||
71 | struct GNUNET_CADET_Channel *channel; | ||
72 | |||
73 | /** | ||
74 | * CADET handle. | ||
75 | */ | ||
76 | struct GNUNET_CADET_Handle *cadet; | ||
77 | |||
78 | } test_peers[REQUESTED_PEERS]; | ||