aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/test_cadeT.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/test_cadeT.c')
-rw-r--r--src/cadet/test_cadeT.c247
1 files changed, 6 insertions, 241 deletions
diff --git a/src/cadet/test_cadeT.c b/src/cadet/test_cadeT.c
index d4688273b..58b6db543 100644
--- a/src/cadet/test_cadeT.c
+++ b/src/cadet/test_cadeT.c
@@ -52,258 +52,23 @@
52#include "platform.h" 52#include "platform.h"
53#include "gnunet_testbed_service.h" 53#include "gnunet_testbed_service.h"
54#include "cadet.h" 54#include "cadet.h"
55#include <test_cadeT_util.h>
55 56
56#define REQUESTED_PEERS 2
57#define CONFIG "test_cadet.conf" 57#define CONFIG "test_cadet.conf"
58#define TESTPROGAM_NAME "test-cadet-channel-resumption" 58#define TESTPROGAM_NAME "test-cadet-channel-resumption"
59#define TIMEOUT_IN_SEC 5
60#define PORTNAME "cadet_port"
61
62/**
63 * Testbed operation for connecting to the services.
64 */
65static struct GNUNET_TESTBED_Operation *testbed_to_svc[2];
66
67/**
68 * Testbed operation for requesting peer information.
69 */
70static struct GNUNET_TESTBED_Operation *testbed_info_req[2];
71
72/**
73 * Port name kown by the two peers.
74 */
75static struct GNUNET_HashCode hashed_portname;
76
77/**
78 * Result of the test.
79 */
80static int test_result = 0;
81
82/**
83 * Counter for gathering peerinformation.
84 */
85static int peerinfo_cnt = 0;
86
87/**
88 * Structure for storing information of testbed peers.
89 */
90struct TEST_PEERS
91{
92 /**
93 * Index of the peer.
94 */
95 int idx;
96
97 /**
98 * Peer Identity.
99 */
100 struct GNUNET_PeerIdentity id;
101
102 /**
103 * Handle of TESTBED peer.
104 */
105 struct GNUNET_TESTBED_Peer *testbed_peer;
106
107 /**
108 * Testbed management is finished and test peer is ready for test logic.
109 */
110 int ready;
111
112 /**
113 * Channel of initiating peer.
114 */
115 struct GNUNET_CADET_Channel *channel;
116
117 /**
118 * CADET handle.
119 */
120 struct GNUNET_CADET_Handle *cadet;
121
122} test_peers[2];
123
124 59
125/****************************** TEST LOGIC ********************************/ 60/****************************** TEST LOGIC ********************************/
126 61
127// TBD 62void
128 63run_test ()
129/************************** TESBED MANAGEMENT *****************************/
130
131static void
132shutdown_task (void *cls)
133{
134 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
135
136 for (int i=0; i<REQUESTED_PEERS; i++)
137 GNUNET_TESTBED_operation_done (testbed_to_svc[i]);
138}
139
140static void
141timeout ()
142{
143 GNUNET_SCHEDULER_shutdown ();
144}
145
146static void
147disconnect_from_peer (void *cls,
148 void *op_result)
149{
150 struct GNUNET_CADET_Handle *cadet = op_result;
151
152 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
153
154 GNUNET_CADET_disconnect (cadet);
155}
156
157static void
158disconnect_channel (void *cls,
159 const struct GNUNET_CADET_Channel *channel)
160{ 64{
161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__); 65 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
162}
163
164static void *
165setup_initiating_peer (void *cls,
166 const struct GNUNET_CONFIGURATION_Handle *cfg)
167{
168 struct GNUNET_CADET_Handle *cadet;
169 struct GNUNET_CADET_Channel *channel;
170
171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
172
173 cadet = GNUNET_CADET_connect (cfg);
174 test_peers[0].cadet = cadet;
175
176 if (NULL == cadet)
177 GNUNET_SCHEDULER_shutdown ();
178
179 channel = GNUNET_CADET_channel_create (cadet,
180 NULL,
181 &test_peers[1].id,
182 &hashed_portname,
183 NULL,
184 &disconnect_channel,
185 NULL);
186 test_peers[0].channel = channel;
187
188 return cadet;
189}
190
191static void *
192handle_port_connects (void *cls,
193 struct GNUNET_CADET_Channel *channel,
194 const struct GNUNET_PeerIdentity *source)
195{
196 return NULL;
197}
198
199static void
200handle_port_disconnects (void *cls,
201 const struct GNUNET_CADET_Channel *channel)
202{
203}
204
205static void *
206setup_listening_peer (void *cls,
207 const struct GNUNET_CONFIGURATION_Handle *cfg)
208{
209 struct GNUNET_CADET_Handle *cadet;
210 struct GNUNET_CADET_Port *port;
211
212 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
213
214 cadet = GNUNET_CADET_connect (cfg);
215 test_peers[1].cadet = cadet;
216 66
217 if (NULL == cadet) 67 /**
218 GNUNET_SCHEDULER_shutdown (); 68 * Do testing here.
219 69 */
220 GNUNET_CRYPTO_hash (PORTNAME, sizeof(PORTNAME), &hashed_portname);
221 port = GNUNET_CADET_open_port (cadet, &hashed_portname,
222 &handle_port_connects,
223 NULL,
224 NULL,
225 &handle_port_disconnects,
226 NULL);
227
228 return cadet;
229}
230
231static void
232check_test_readyness (void *cls,
233 struct GNUNET_TESTBED_Operation *op,
234 void *ca_result,
235 const char *emsg)
236{
237 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
238}
239
240
241static int
242peerinfo_complete ()
243{
244 return (REQUESTED_PEERS == ++peerinfo_cnt) ? GNUNET_YES : GNUNET_NO;
245}
246
247static void
248connect_to_service (void *cb_cls,
249 struct GNUNET_TESTBED_Operation *op,
250 const struct GNUNET_TESTBED_PeerInformation *pinfo,
251 const char *emsg)
252{
253 struct TEST_PEERS *test_peer = cb_cls;
254
255 // Store peer ID.
256 test_peer->id = *(pinfo->result.id);
257
258 if (peerinfo_complete())
259 {
260 testbed_to_svc[1] =
261 GNUNET_TESTBED_service_connect (NULL, test_peers[1].testbed_peer,
262 "cadet",
263 &check_test_readyness, NULL,
264 &setup_listening_peer,
265 &disconnect_from_peer, NULL);
266 testbed_to_svc[0] =
267 GNUNET_TESTBED_service_connect (NULL, test_peers[0].testbed_peer,
268 "cadet",
269 &check_test_readyness, NULL,
270 &setup_initiating_peer,
271 &disconnect_from_peer, NULL);
272 }
273} 70}
274 71
275static void
276connect_to_peers (void *cls,
277 struct GNUNET_TESTBED_RunHandle *h,
278 unsigned int num_peers,
279 struct GNUNET_TESTBED_Peer **peers,
280 unsigned int links_succeeded,
281 unsigned int links_failed)
282{
283 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "%s\n", __func__);
284
285 GNUNET_assert (0 == links_failed);
286
287 for (int i=0; i<num_peers; i++)
288 {
289 test_peers[i].ready = GNUNET_NO;
290 test_peers[i].idx = i;
291 test_peers[i].testbed_peer = peers[i];
292 }
293
294 testbed_info_req[0] = GNUNET_TESTBED_peer_get_information (peers[0],
295 GNUNET_TESTBED_PIT_IDENTITY,
296 &connect_to_service,
297 &test_peers[0]);
298 testbed_info_req[1] = GNUNET_TESTBED_peer_get_information (peers[1],
299 GNUNET_TESTBED_PIT_IDENTITY,
300 &connect_to_service,
301 &test_peers[1]);
302
303 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
304 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, TIMEOUT_IN_SEC),
305 &timeout, NULL);
306}
307 72
308int 73int
309main (int argc, char *argv[]) 74main (int argc, char *argv[])