diff options
author | xrs <xrs@mail36.net> | 2020-02-29 14:40:08 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2020-05-21 22:46:48 +0200 |
commit | d25e0e167c2614a55b89c0195dab9f69f9355b7f (patch) | |
tree | ae574ee4ec556e21ae7ac3945fb482361efd9d59 | |
parent | 08db6f95454f01abd27a96e9e331f299b518d3ab (diff) | |
download | gnunet-d25e0e167c2614a55b89c0195dab9f69f9355b7f.tar.gz gnunet-d25e0e167c2614a55b89c0195dab9f69f9355b7f.zip |
two peers on the stage
-rw-r--r-- | src/cadet/test_cadeT.c | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c new file mode 100644 index 000000000..1b74eade2 --- /dev/null +++ b/src/cadet/test_cadeT.c | |||
@@ -0,0 +1,201 @@ | |||
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 | * - setup peer A | ||
30 | * - setup peer B | ||
31 | * - setup cadet on peer B listening on port 1234 | ||
32 | * - create a channel from peer A to B | ||
33 | * - create method to find out session initiator | ||
34 | * - send a message over channel | ||
35 | * - check if message was received | ||
36 | * - breakup the connection without sending 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 | * - yes, with GNUNET_TESTBED_underlay_configure_link | ||
46 | * - how can we test the sublayers of CADET, e.g. connection, tunnel, channel? | ||
47 | * | ||
48 | * Development | ||
49 | * - red -> green -> refactor (cyclic) | ||
50 | */ | ||
51 | #include "platform.h" | ||
52 | #include "gnunet_testbed_service.h" | ||
53 | #include "cadet.h" | ||
54 | |||
55 | #define REQUESTED_PEERS 2 | ||
56 | #define CONFIG "test_cadet.conf" | ||
57 | #define TESTPROGAM_NAME "test-cadet-channel-resumption" | ||
58 | #define PORTNAME "cadet_port" | ||
59 | |||
60 | struct GNUNET_TESTBED_Operation *testbed_to_svc[2]; | ||
61 | |||
62 | /** | ||
63 | * Port name kown by the two peers. | ||
64 | */ | ||
65 | static struct GNUNET_HashCode hashed_portname; | ||
66 | |||
67 | static int test_result = 0; | ||
68 | |||
69 | // FIXME: temp cnt | ||
70 | static int cnt = 0; | ||
71 | |||
72 | /****************************** TEST LOGIC ********************************/ | ||
73 | |||
74 | // TBD | ||
75 | |||
76 | /************************** TESBED MANAGEMENT *****************************/ | ||
77 | |||
78 | static void | ||
79 | shutdown_task (void *cls) | ||
80 | { | ||
81 | for (int i=0; i<REQUESTED_PEERS; i++) | ||
82 | GNUNET_TESTBED_operation_done (testbed_to_svc[i]); | ||
83 | } | ||
84 | |||
85 | static void | ||
86 | disconnect_from_peer (void *cls, | ||
87 | void *op_result) | ||
88 | { | ||
89 | struct GNUNET_CADET_Handle *cadet = op_result; | ||
90 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "disconnect_from_cadet ()\n"); | ||
92 | |||
93 | GNUNET_CADET_disconnect (cadet); | ||
94 | } | ||
95 | |||
96 | static void * | ||
97 | setup_initiating_peer (void *cls, | ||
98 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
99 | { | ||
100 | |||
101 | struct GNUNET_CADET_Handle *cadet; | ||
102 | |||
103 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_initiating_peer()\n"); | ||
104 | |||
105 | cadet = GNUNET_CADET_connect (cfg); | ||
106 | |||
107 | if (NULL == cadet) | ||
108 | GNUNET_SCHEDULER_shutdown (); | ||
109 | |||
110 | return cadet; | ||
111 | } | ||
112 | |||
113 | static void * | ||
114 | handle_port_connects (void *cls, | ||
115 | struct GNUNET_CADET_Channel *channel, | ||
116 | const struct GNUNET_PeerIdentity *source) | ||
117 | { | ||
118 | return NULL; | ||
119 | } | ||
120 | |||
121 | static void | ||
122 | handle_port_disconnects (void *cls, | ||
123 | const struct GNUNET_CADET_Channel *channel) | ||
124 | { | ||
125 | } | ||
126 | |||
127 | static void * | ||
128 | setup_listening_peer (void *cls, | ||
129 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
130 | { | ||
131 | struct GNUNET_CADET_Handle *cadet; | ||
132 | struct GNUNET_CADET_Port *port; | ||
133 | |||
134 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "setup_listening_peer()\n"); | ||
135 | |||
136 | cadet = GNUNET_CADET_connect (cfg); | ||
137 | |||
138 | if (NULL == cadet) | ||
139 | GNUNET_SCHEDULER_shutdown (); | ||
140 | |||
141 | GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname); | ||
142 | port = GNUNET_CADET_open_port (cadet, &hashed_portname, | ||
143 | &handle_port_connects, | ||
144 | NULL, | ||
145 | NULL, | ||
146 | &handle_port_disconnects, | ||
147 | NULL); | ||
148 | |||
149 | return cadet; | ||
150 | } | ||
151 | |||
152 | static void | ||
153 | check_test_readyness (void *cls, | ||
154 | struct GNUNET_TESTBED_Operation *op, | ||
155 | void *ca_result, | ||
156 | const char *emsg) | ||
157 | { | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "check_test_readyness()\n"); | ||
159 | |||
160 | if (2 == ++cnt) | ||
161 | GNUNET_SCHEDULER_shutdown (); | ||
162 | } | ||
163 | |||
164 | static void | ||
165 | connect_to_peers (void *cls, | ||
166 | struct GNUNET_TESTBED_RunHandle *h, | ||
167 | unsigned int num_peers, | ||
168 | struct GNUNET_TESTBED_Peer **peers, | ||
169 | unsigned int links_succeeded, | ||
170 | unsigned int links_failed) | ||
171 | { | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connect_to_peers()\n"); | ||
173 | |||
174 | GNUNET_assert (0 == links_failed); | ||
175 | |||
176 | |||
177 | testbed_to_svc[1] = GNUNET_TESTBED_service_connect (NULL, peers[1], | ||
178 | "cadet", | ||
179 | &check_test_readyness, NULL, | ||
180 | &setup_listening_peer, | ||
181 | &disconnect_from_peer, NULL); | ||
182 | testbed_to_svc[0] = GNUNET_TESTBED_service_connect (NULL, peers[0], | ||
183 | "cadet", | ||
184 | &check_test_readyness, NULL, | ||
185 | &setup_initiating_peer, | ||
186 | &disconnect_from_peer, NULL); | ||
187 | |||
188 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
189 | } | ||
190 | |||
191 | int | ||
192 | main (int argc, char *argv[]) | ||
193 | { | ||
194 | GNUNET_TESTBED_test_run (TESTPROGAM_NAME, | ||
195 | CONFIG, | ||
196 | REQUESTED_PEERS, 0LL, NULL, NULL, | ||
197 | connect_to_peers, NULL); | ||
198 | return test_result; | ||
199 | } | ||
200 | |||
201 | /* end of test_template_api.c */ | ||