aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cadet/Makefile.am6
-rw-r--r--src/cadet/test_cadeT.c141
-rw-r--r--src/cadet/test_cadeT_util.c244
-rw-r--r--src/cadet/test_cadeT_util.h78
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
86if HAVE_TESTING 86if HAVE_TESTING
87check_PROGRAMS = \ 87check_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
145test_cadet_2_channel_resumption_SOURCES = \
146 test_cadeT.c \
147 test_cadeT_util.c test_cadeT_util.h
148test_cadet_2_channel_resumption_LDADD = $(ld_cadet_test_lib)
149
144test_cadet_2_forward_SOURCES = \ 150test_cadet_2_forward_SOURCES = \
145 test_cadet.c 151 test_cadet.c
146test_cadet_2_forward_LDADD = $(ld_cadet_test_lib) 152test_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
64static int kx_initiator;
65static struct GNUNET_TESTBED_UnderlayLinkModel *model;
66
67static void
68send_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
85int
86check_message (void *cls,
87 const struct GNUNET_MessageHeader *message)
88{
89 return GNUNET_OK; /* all is well-formed */
90}
91
92void
93handle_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 */
114void
115run_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
131int
132main (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 */
31static struct GNUNET_TESTBED_Operation *testbed_to_svc[REQUESTED_PEERS];
32
33/**
34 * Testbed operation for requesting peer information.
35 */
36static struct GNUNET_TESTBED_Operation *testbed_info_req[REQUESTED_PEERS];
37
38/**
39 * Port name kown by the two peers.
40 */
41static struct GNUNET_HashCode hashed_portname;
42
43/**
44 * Result of the test.
45 */
46int test_result = 0;
47
48/**
49 * Counter for gathering peerinformation.
50 */
51static int peerinfo_cnt = 0;
52
53/************************** TESBED MANAGEMENT *****************************/
54
55static void
56shutdown_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
67static void
68timeout ()
69{
70 GNUNET_SCHEDULER_shutdown ();
71}
72
73static void
74disconnect_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
84static void
85disconnect_channel (void *cls,
86 const struct GNUNET_CADET_Channel *channel)
87{
88 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
89}
90
91static void *
92setup_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
118static void *
119handle_port_connects (void *cls,
120 struct GNUNET_CADET_Channel *channel,
121 const struct GNUNET_PeerIdentity *source)
122{
123 return NULL;
124}
125
126static void
127handle_port_disconnects (void *cls,
128 const struct GNUNET_CADET_Channel *channel)
129{
130}
131
132static void *
133setup_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
165static void
166check_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
177static int
178peerinfo_complete ()
179{
180 return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO;
181}
182
183static void
184connect_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
211void
212prepare_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
34int test_result;
35
36void prepare_test ();
37
38void run_test ();
39
40void handle_message (void *cls,
41 const struct GNUNET_MessageHeader *msg);
42
43/**
44 * Structure for storing information of testbed peers.
45 */
46struct 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];