diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 01:06:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 01:06:56 +0000 |
commit | 53f0f13a919c33f6bfcb7823ee4908084b259f20 (patch) | |
tree | bb018f7df1bd3d677d9fa41656ff44957a83a43c /src | |
parent | c0b81510ffe194dc662c3a6267d5e66a69873c4b (diff) | |
download | gnunet-53f0f13a919c33f6bfcb7823ee4908084b259f20.tar.gz gnunet-53f0f13a919c33f6bfcb7823ee4908084b259f20.zip |
-towards nicer transport-testing lib
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/Makefile.am | 1 | ||||
-rw-r--r-- | src/transport/test_quota_compliance.c | 447 | ||||
-rw-r--r-- | src/transport/test_transport_api.c | 398 | ||||
-rw-r--r-- | src/transport/transport-testing-loggers.c | 76 | ||||
-rw-r--r-- | src/transport/transport-testing-main.c | 435 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 329 |
6 files changed, 1082 insertions, 604 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 721e05d83..43a87ed33 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -152,6 +152,7 @@ lib_LTLIBRARIES = \ | |||
152 | libgnunettransporttesting_la_SOURCES = \ | 152 | libgnunettransporttesting_la_SOURCES = \ |
153 | transport-testing.c transport-testing.h \ | 153 | transport-testing.c transport-testing.h \ |
154 | transport-testing-filenames.c \ | 154 | transport-testing-filenames.c \ |
155 | transport-testing-loggers.c \ | ||
155 | transport-testing-main.c | 156 | transport-testing-main.c |
156 | libgnunettransporttesting_la_LIBADD = \ | 157 | libgnunettransporttesting_la_LIBADD = \ |
157 | libgnunettransport.la \ | 158 | libgnunettransport.la \ |
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 59dbd45e0..87833ff83 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2011 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -41,39 +41,18 @@ | |||
41 | 41 | ||
42 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 42 | #define DURATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
43 | 43 | ||
44 | static char *test_source; | ||
45 | 44 | ||
46 | static char *test_plugin; | 45 | static struct GNUNET_SCHEDULER_Task *measure_task; |
47 | |||
48 | static char *test_name; | ||
49 | |||
50 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
51 | |||
52 | static struct GNUNET_SCHEDULER_Task * measure_task; | ||
53 | |||
54 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
55 | |||
56 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
57 | |||
58 | struct GNUNET_TRANSPORT_TESTING_PeerContext *sender; | ||
59 | |||
60 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver; | ||
61 | 46 | ||
62 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 47 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
63 | 48 | ||
64 | char *cfg_file_p1; | 49 | static char *gen_cfgs[2]; |
65 | char *gen_cfg_p2; | ||
66 | unsigned long long quota_in_p1; | ||
67 | unsigned long long quota_out_p1; | ||
68 | 50 | ||
69 | char *cfg_file_p2; | 51 | static unsigned long long quota_in[] = { 10000, 10000 }; |
70 | char *gen_cfg_p1; | ||
71 | unsigned long long quota_in_p2; | ||
72 | unsigned long long quota_out_p2; | ||
73 | 52 | ||
74 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 53 | static unsigned long long quota_out[] = { 10000, 10000 }; |
75 | 54 | ||
76 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | 55 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
77 | 56 | ||
78 | 57 | ||
79 | /* | 58 | /* |
@@ -100,9 +79,6 @@ GNUNET_NETWORK_STRUCT_END | |||
100 | static int msg_scheduled; | 79 | static int msg_scheduled; |
101 | static int msg_sent; | 80 | static int msg_sent; |
102 | 81 | ||
103 | static int test_failed; | ||
104 | static int test_connected; | ||
105 | |||
106 | static unsigned long long total_bytes_sent; | 82 | static unsigned long long total_bytes_sent; |
107 | 83 | ||
108 | static struct GNUNET_TIME_Absolute start_time; | 84 | static struct GNUNET_TIME_Absolute start_time; |
@@ -119,82 +95,59 @@ static struct GNUNET_TIME_Absolute start_time; | |||
119 | 95 | ||
120 | 96 | ||
121 | static void | 97 | static void |
122 | end () | 98 | report () |
123 | { | 99 | { |
124 | unsigned long long delta; | 100 | unsigned long long delta; |
125 | unsigned long long datarate; | 101 | unsigned long long datarate; |
126 | 102 | ||
127 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
128 | |||
129 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; | 103 | delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; |
130 | datarate = (total_bytes_sent * 1000 * 1000) / delta; | 104 | datarate = (total_bytes_sent * 1000 * 1000) / delta; |
131 | 105 | ||
132 | FPRINTF (stderr, "Throughput was %llu b/s\n", datarate); | 106 | FPRINTF (stderr, |
107 | "Throughput was %llu b/s\n", | ||
108 | datarate); | ||
133 | 109 | ||
134 | test_failed = GNUNET_NO; | 110 | if (datarate > quota_in[1]) |
135 | if (datarate > quota_in_p2) | ||
136 | { | 111 | { |
137 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
138 | "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", | 113 | "Datarate of %llu b/s higher than allowed inbound quota of %llu b/s\n", |
139 | datarate, quota_in_p2); | 114 | datarate, |
140 | test_failed = GNUNET_YES; | 115 | quota_in[1]); |
116 | ccc->global_ret = GNUNET_SYSERR; | ||
141 | } | 117 | } |
142 | if (datarate > quota_out_p1) | 118 | if (datarate > quota_out[0]) |
143 | { | 119 | { |
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
145 | "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", | 121 | "Datarate of %llu b/s higher than allowed outbound quota of %llu b/s\n", |
146 | datarate, quota_out_p1); | 122 | datarate, |
147 | test_failed = GNUNET_YES; | 123 | quota_out[0]); |
124 | ccc->global_ret = GNUNET_SYSERR; | ||
148 | } | 125 | } |
149 | if (test_failed == GNUNET_NO) | 126 | if (GNUNET_OK == ccc->global_ret) |
150 | { | 127 | { |
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
152 | "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", | 129 | "Datarate of %llu b/s complied to allowed outbound quota of %llu b/s and inbound quota of %llu b/s\n", |
153 | datarate, quota_out_p1, quota_in_p2); | 130 | datarate, |
131 | quota_out[0], | ||
132 | quota_in[1]); | ||
154 | } | 133 | } |
155 | |||
156 | if (die_task != NULL) | ||
157 | GNUNET_SCHEDULER_cancel (die_task); | ||
158 | |||
159 | if (th != NULL) | ||
160 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
161 | th = NULL; | ||
162 | |||
163 | if (cc != NULL) | ||
164 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
165 | |||
166 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
167 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
168 | |||
169 | } | 134 | } |
170 | 135 | ||
136 | |||
171 | static void | 137 | static void |
172 | end_badly () | 138 | custom_shutdown (void *cls) |
173 | { | 139 | { |
174 | die_task = NULL; | 140 | if (NULL != measure_task) |
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 141 | { |
176 | |||
177 | if (measure_task != NULL) | ||
178 | GNUNET_SCHEDULER_cancel (measure_task); | 142 | GNUNET_SCHEDULER_cancel (measure_task); |
179 | 143 | measure_task = NULL; | |
180 | if (test_connected == GNUNET_YES) | 144 | } |
181 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got connected\n"); | 145 | if (NULL != th) |
182 | else | 146 | { |
183 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers got NOT connected\n"); | ||
184 | |||
185 | if (th != NULL) | ||
186 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 147 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
187 | th = NULL; | 148 | th = NULL; |
188 | 149 | } | |
189 | if (cc != NULL) | 150 | report (); |
190 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
191 | |||
192 | if (p1 != NULL) | ||
193 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
194 | if (p2 != NULL) | ||
195 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
196 | |||
197 | test_failed = GNUNET_YES; | ||
198 | } | 151 | } |
199 | 152 | ||
200 | 153 | ||
@@ -210,33 +163,35 @@ get_size (unsigned int iter) | |||
210 | 163 | ||
211 | static void | 164 | static void |
212 | notify_receive (void *cls, | 165 | notify_receive (void *cls, |
213 | const struct GNUNET_PeerIdentity *peer, | 166 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
167 | const struct GNUNET_PeerIdentity *sender, | ||
214 | const struct GNUNET_MessageHeader *message) | 168 | const struct GNUNET_MessageHeader *message) |
215 | { | 169 | { |
216 | const struct TestMessage *hdr; | 170 | const struct TestMessage *hdr; |
217 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
218 | 171 | ||
219 | hdr = (const struct TestMessage *) message; | 172 | hdr = (const struct TestMessage *) message; |
220 | if (MTYPE != ntohs (message->type)) | 173 | if (MTYPE != ntohs (message->type)) |
221 | return; | 174 | return; |
222 | 175 | ||
223 | { | 176 | { |
224 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 177 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
225 | 178 | ||
226 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 179 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
227 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", | 180 | "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", |
228 | p->no, | 181 | receiver->no, |
229 | ps, | 182 | ps, |
230 | ntohl (hdr->num), | 183 | ntohl (hdr->num), |
231 | ntohs (message->size), | 184 | ntohs (message->size), |
232 | GNUNET_i2s (peer)); | 185 | GNUNET_i2s (sender)); |
233 | GNUNET_free (ps); | 186 | GNUNET_free (ps); |
234 | } | 187 | } |
235 | } | 188 | } |
236 | 189 | ||
237 | 190 | ||
238 | static size_t | 191 | static size_t |
239 | notify_ready (void *cls, size_t size, void *buf) | 192 | notify_ready (void *cls, |
193 | size_t size, | ||
194 | void *buf) | ||
240 | { | 195 | { |
241 | static int n; | 196 | static int n; |
242 | char *cbuf = buf; | 197 | char *cbuf = buf; |
@@ -245,15 +200,13 @@ notify_ready (void *cls, size_t size, void *buf) | |||
245 | unsigned int ret; | 200 | unsigned int ret; |
246 | 201 | ||
247 | th = NULL; | 202 | th = NULL; |
248 | if (buf == NULL) | 203 | if (NULL == buf) |
249 | { | 204 | { |
250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 205 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
251 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", | 206 | "Timeout occurred while waiting for transmit_ready for message %u of %u\n", |
252 | msg_scheduled, TOTAL_MSGS); | 207 | msg_scheduled, TOTAL_MSGS); |
253 | if (NULL != die_task) | 208 | GNUNET_SCHEDULER_shutdown (); |
254 | GNUNET_SCHEDULER_cancel (die_task); | 209 | ccc->global_ret = GNUNET_SYSERR; |
255 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
256 | test_failed = 1; | ||
257 | return 0; | 210 | return 0; |
258 | } | 211 | } |
259 | 212 | ||
@@ -276,11 +229,14 @@ notify_ready (void *cls, size_t size, void *buf) | |||
276 | if (n % 5000 == 0) | 229 | if (n % 5000 == 0) |
277 | { | 230 | { |
278 | #endif | 231 | #endif |
279 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); | 232 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
280 | 233 | ||
281 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
282 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", | 235 | "Sending message %u of size %u from peer %u (`%4s') -> peer %u (`%s') !\n", |
283 | n, s, sender->no, GNUNET_i2s (&sender->id), receiver->no, | 236 | n, s, |
237 | ccc->p[1]->no, | ||
238 | GNUNET_i2s (&ccc->p[1]->id), | ||
239 | ccc->p[0]->no, | ||
284 | receiver_s); | 240 | receiver_s); |
285 | GNUNET_free (receiver_s); | 241 | GNUNET_free (receiver_s); |
286 | #if 0 | 242 | #if 0 |
@@ -295,60 +251,56 @@ notify_ready (void *cls, size_t size, void *buf) | |||
295 | if (n < TOTAL_MSGS) | 251 | if (n < TOTAL_MSGS) |
296 | { | 252 | { |
297 | if (th == NULL) | 253 | if (th == NULL) |
298 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, s, | 254 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
255 | &ccc->p[0]->id, | ||
256 | s, | ||
299 | TIMEOUT_TRANSMIT, | 257 | TIMEOUT_TRANSMIT, |
300 | ¬ify_ready, NULL); | 258 | ¬ify_ready, |
259 | NULL); | ||
301 | msg_scheduled = n; | 260 | msg_scheduled = n; |
302 | } | 261 | } |
303 | if (n % 5000 == 0) | 262 | if (n % 5000 == 0) |
304 | { | 263 | { |
305 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
306 | "Returning total message block of size %u\n", ret); | 265 | "Returning total message block of size %u\n", |
266 | ret); | ||
307 | } | 267 | } |
308 | total_bytes_sent += ret; | 268 | total_bytes_sent += ret; |
309 | if (n == TOTAL_MSGS) | 269 | if (n == TOTAL_MSGS) |
310 | { | 270 | { |
311 | FPRINTF (stderr, "%s", "\n"); | 271 | FPRINTF (stderr, "%s", "\n"); |
312 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n"); | 272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
273 | "All messages sent\n"); | ||
313 | } | 274 | } |
314 | return ret; | 275 | return ret; |
315 | } | 276 | } |
316 | 277 | ||
317 | 278 | ||
318 | static void | 279 | static void |
319 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 280 | notify_disconnect (void *cls, |
320 | { | 281 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
321 | 282 | const struct GNUNET_PeerIdentity *other) | |
322 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
323 | |||
324 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
325 | "Peer %u (`%4s') connected to us!\n", | ||
326 | p->no, | ||
327 | GNUNET_i2s (peer)); | ||
328 | } | ||
329 | |||
330 | |||
331 | static void | ||
332 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
333 | { | 283 | { |
334 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 284 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
335 | 285 | me, | |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 286 | other); |
337 | "Peer %u (`%4s') disconnected!\n", | ||
338 | p->no, | ||
339 | GNUNET_i2s (peer)); | ||
340 | if (th != NULL) | 287 | if (th != NULL) |
288 | { | ||
341 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 289 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
342 | th = NULL; | 290 | th = NULL; |
343 | 291 | } | |
344 | } | 292 | } |
345 | 293 | ||
294 | |||
346 | static void | 295 | static void |
347 | sendtask () | 296 | sendtask () |
348 | { | 297 | { |
349 | start_time = GNUNET_TIME_absolute_get (); | 298 | start_time = GNUNET_TIME_absolute_get (); |
350 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, get_size (0), | 299 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
351 | TIMEOUT_TRANSMIT, ¬ify_ready, | 300 | &ccc->p[0]->id, |
301 | get_size (0), | ||
302 | TIMEOUT_TRANSMIT, | ||
303 | ¬ify_ready, | ||
352 | NULL); | 304 | NULL); |
353 | } | 305 | } |
354 | 306 | ||
@@ -359,86 +311,54 @@ measure (void *cls) | |||
359 | static int counter; | 311 | static int counter; |
360 | 312 | ||
361 | measure_task = NULL; | 313 | measure_task = NULL; |
362 | |||
363 | counter++; | 314 | counter++; |
364 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) | 315 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) |
365 | { | 316 | { |
366 | FPRINTF (stderr, "%s", ".\n"); | 317 | FPRINTF (stderr, "%s", ".\n"); |
367 | GNUNET_SCHEDULER_add_now (&end, NULL); | 318 | GNUNET_SCHEDULER_shutdown (); |
368 | } | 319 | return; |
369 | else | ||
370 | { | ||
371 | FPRINTF (stderr, "%s", "."); | ||
372 | measure_task = | ||
373 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); | ||
374 | } | 320 | } |
321 | FPRINTF (stderr, "%s", "."); | ||
322 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
323 | &measure, | ||
324 | NULL); | ||
375 | } | 325 | } |
376 | 326 | ||
377 | 327 | ||
378 | static void | 328 | static void |
379 | testing_connect_cb (void *cls) | 329 | start_task (void *cls) |
380 | { | ||
381 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
384 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
385 | GNUNET_free (p1_c); | ||
386 | |||
387 | cc = NULL; | ||
388 | test_connected = GNUNET_YES; | ||
389 | |||
390 | measure_task = | ||
391 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &measure, NULL); | ||
392 | GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
393 | |||
394 | } | ||
395 | |||
396 | |||
397 | static void | ||
398 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
399 | { | 330 | { |
400 | static int started; | 331 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
401 | 332 | &measure, | |
402 | started++; | ||
403 | |||
404 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
405 | GNUNET_i2s (&p->id)); | ||
406 | |||
407 | if (started != 2) | ||
408 | return; | ||
409 | |||
410 | test_connected = GNUNET_NO; | ||
411 | |||
412 | sender = p2; | ||
413 | receiver = p1; | ||
414 | |||
415 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&sender->id)); | ||
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
417 | "Test tries to send from %u (%s) -> peer %u (%s)\n", sender->no, | ||
418 | sender_c, receiver->no, GNUNET_i2s (&receiver->id)); | ||
419 | GNUNET_free (sender_c); | ||
420 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, | ||
421 | NULL); | 333 | NULL); |
422 | 334 | GNUNET_SCHEDULER_add_now (&sendtask, | |
335 | NULL); | ||
423 | } | 336 | } |
424 | 337 | ||
338 | |||
425 | static char * | 339 | static char * |
426 | generate_config (char *cfg_file, unsigned long long quota_in, | 340 | generate_config (const char *cfg_file, |
341 | unsigned long long quota_in, | ||
427 | unsigned long long quota_out) | 342 | unsigned long long quota_out) |
428 | { | 343 | { |
429 | char *in_name; | 344 | char *in_name; |
430 | char *out_name; | 345 | char *out_name; |
431 | char *fname = NULL; | 346 | char *fname = NULL; |
432 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); | 347 | struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); |
433 | int c; | ||
434 | 348 | ||
435 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, cfg_file)); | 349 | GNUNET_assert (GNUNET_OK == |
436 | GNUNET_asprintf (&fname, "q_in_%llu_q_out_%llu_%s", quota_in, quota_out, | 350 | GNUNET_CONFIGURATION_load (cfg, |
351 | cfg_file)); | ||
352 | GNUNET_asprintf (&fname, | ||
353 | "q_in_%llu_q_out_%llu_%s", | ||
354 | quota_in, | ||
355 | quota_out, | ||
437 | cfg_file); | 356 | cfg_file); |
438 | 357 | GNUNET_CONFIGURATION_set_value_string (cfg, | |
439 | GNUNET_CONFIGURATION_set_value_string (cfg, "PATHS", "DEFAULTCONFIG", fname); | 358 | "PATHS", |
440 | 359 | "DEFAULTCONFIG", | |
441 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 360 | fname); |
361 | for (int c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | ||
442 | { | 362 | { |
443 | GNUNET_asprintf (&in_name, | 363 | GNUNET_asprintf (&in_name, |
444 | "%s_QUOTA_IN", | 364 | "%s_QUOTA_IN", |
@@ -446,138 +366,101 @@ generate_config (char *cfg_file, unsigned long long quota_in, | |||
446 | GNUNET_asprintf (&out_name, | 366 | GNUNET_asprintf (&out_name, |
447 | "%s_QUOTA_OUT", | 367 | "%s_QUOTA_OUT", |
448 | GNUNET_ATS_print_network_type (c)); | 368 | GNUNET_ATS_print_network_type (c)); |
449 | GNUNET_CONFIGURATION_set_value_number (cfg, "ats", in_name, quota_in); | 369 | GNUNET_CONFIGURATION_set_value_number (cfg, |
450 | GNUNET_CONFIGURATION_set_value_number (cfg, "ats", out_name, quota_out); | 370 | "ats", |
371 | in_name, | ||
372 | quota_in); | ||
373 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
374 | "ats", | ||
375 | out_name, | ||
376 | quota_out); | ||
451 | GNUNET_free (in_name); | 377 | GNUNET_free (in_name); |
452 | GNUNET_free (out_name); | 378 | GNUNET_free (out_name); |
453 | } | 379 | } |
454 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write (cfg, fname)); | 380 | GNUNET_assert (GNUNET_OK == |
381 | GNUNET_CONFIGURATION_write (cfg, | ||
382 | fname)); | ||
455 | GNUNET_CONFIGURATION_destroy (cfg); | 383 | GNUNET_CONFIGURATION_destroy (cfg); |
456 | return fname; | 384 | return fname; |
457 | } | 385 | } |
458 | 386 | ||
459 | static void | ||
460 | run_measurement (unsigned long long p1_quota_in, | ||
461 | unsigned long long p1_quota_out, | ||
462 | unsigned long long p2_quota_in, | ||
463 | unsigned long long p2_quota_out) | ||
464 | { | ||
465 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
466 | |||
467 | /* setting ATS quota */ | ||
468 | quota_out_p1 = p1_quota_out; | ||
469 | gen_cfg_p1 = generate_config (cfg_file_p1, p1_quota_in, p1_quota_out); | ||
470 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", | ||
471 | gen_cfg_p1); | ||
472 | |||
473 | quota_in_p2 = p2_quota_in; | ||
474 | gen_cfg_p2 = generate_config (cfg_file_p2, p2_quota_in, p2_quota_out); | ||
475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Generated config file `%s'\n", | ||
476 | gen_cfg_p2); | ||
477 | |||
478 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p1, 1, ¬ify_receive, | ||
479 | ¬ify_connect, ¬ify_disconnect, | ||
480 | &start_cb, NULL); | ||
481 | |||
482 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, gen_cfg_p2, 2, ¬ify_receive, | ||
483 | ¬ify_connect, ¬ify_disconnect, | ||
484 | &start_cb, NULL); | ||
485 | |||
486 | if ((p1 == NULL) || (p2 == NULL)) | ||
487 | { | ||
488 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
489 | if (die_task != NULL) | ||
490 | GNUNET_SCHEDULER_cancel (die_task); | ||
491 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
492 | return; | ||
493 | } | ||
494 | } | ||
495 | |||
496 | 387 | ||
497 | static void | 388 | static int |
498 | run (void *cls, char *const *args, const char *cfgfile, | 389 | check (void *cls, |
499 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 390 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
391 | const char *test_plugin_, | ||
392 | const char *test_name_, | ||
393 | unsigned int num_peers, | ||
394 | char *cfg_files[]) | ||
500 | { | 395 | { |
501 | unsigned long long p1_quota_in = 10000; | 396 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
502 | unsigned long long p1_quota_out = 10000; | 397 | .connect_continuation = &start_task, |
503 | unsigned long long p2_quota_in = 10000; | 398 | .config_file = "test_quota_compliance_data.conf", |
504 | unsigned long long p2_quota_out = 10000; | 399 | .rec = ¬ify_receive, |
400 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, | ||
401 | .nd = ¬ify_disconnect, | ||
402 | .shutdown_task = &custom_shutdown, | ||
403 | .timeout = TIMEOUT | ||
404 | }; | ||
405 | ccc = &my_ccc; | ||
505 | 406 | ||
506 | if (NULL != strstr (test_name, "asymmetric")) | 407 | if (NULL != strstr (test_name_, |
408 | "asymmetric")) | ||
507 | { | 409 | { |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 410 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
509 | "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", | 411 | "Running asymmetric test with sending peer unlimited, receiving peer (in/out): %llu/%llu b/s \n", |
510 | p2_quota_in, p2_quota_out); | 412 | quota_in[1], |
511 | p1_quota_out = 1024 * 1024 * 1024; | 413 | quota_out[1]); |
512 | p1_quota_in = 1024 * 1024 * 1024; | 414 | quota_out[0] = 1024 * 1024 * 1024; |
415 | quota_in[0] = 1024 * 1024 * 1024; | ||
513 | } | 416 | } |
514 | else | 417 | else |
515 | { | 418 | { |
516 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 419 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
517 | "Running symmetric test with (in/out) %llu/%llu b/s \n", | 420 | "Running symmetric test with (in/out) %llu/%llu b/s \n", |
518 | p2_quota_in, p2_quota_out); | 421 | quota_in[1], |
422 | quota_out[1]); | ||
423 | } | ||
424 | for (unsigned int i=0;i<2;i++) | ||
425 | { | ||
426 | gen_cfgs[i] = generate_config (cfg_files[i], | ||
427 | quota_in[i], | ||
428 | quota_out[i]); | ||
429 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
430 | "Generated config file `%s'\n", | ||
431 | gen_cfgs[i]); | ||
519 | } | 432 | } |
520 | run_measurement (p1_quota_in, p1_quota_out, p2_quota_in, p2_quota_out); | ||
521 | } | ||
522 | |||
523 | static int | ||
524 | check () | ||
525 | { | ||
526 | static char *argv[] = { "test_transport-quota-compliance", | ||
527 | "-c", | ||
528 | "test_quota_compliance_data.conf", | ||
529 | NULL | ||
530 | }; | ||
531 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
532 | GNUNET_GETOPT_OPTION_END | ||
533 | }; | ||
534 | 433 | ||
535 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | 434 | return GNUNET_TRANSPORT_TESTING_connect_check (&my_ccc, |
536 | "nohelp", options, &run, NULL); | 435 | tth_, |
537 | return test_failed; | 436 | test_plugin_, |
437 | test_name_, | ||
438 | num_peers, | ||
439 | gen_cfgs); | ||
538 | } | 440 | } |
539 | 441 | ||
442 | |||
540 | int | 443 | int |
541 | main (int argc, char *argv[]) | 444 | main (int argc, char *argv[]) |
542 | { | 445 | { |
543 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 446 | if (GNUNET_OK != |
544 | 447 | GNUNET_TRANSPORT_TESTING_main (2, | |
545 | GNUNET_log_setup (test_name, | 448 | &check, |
546 | "WARNING", | 449 | NULL)) |
547 | NULL); | ||
548 | |||
549 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | ||
550 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source); | ||
551 | |||
552 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
553 | |||
554 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
555 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
556 | |||
557 | check (); | ||
558 | |||
559 | GNUNET_free (cfg_file_p1); | ||
560 | GNUNET_free (cfg_file_p2); | ||
561 | |||
562 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p1)) | ||
563 | { | 450 | { |
564 | GNUNET_DISK_directory_remove (gen_cfg_p1); | 451 | GNUNET_break (0); |
565 | GNUNET_free (gen_cfg_p1); | 452 | return 1; |
566 | } | 453 | } |
567 | 454 | for (unsigned int i=0;i<2;i++) | |
568 | if (GNUNET_YES == GNUNET_DISK_file_test (gen_cfg_p2)) | ||
569 | { | 455 | { |
570 | GNUNET_DISK_directory_remove (gen_cfg_p2); | 456 | if ( (NULL != gen_cfgs[0]) && |
571 | GNUNET_free (gen_cfg_p2); | 457 | (GNUNET_YES == GNUNET_DISK_file_test (gen_cfgs[0])) ) |
458 | { | ||
459 | GNUNET_DISK_directory_remove (gen_cfgs[0]); | ||
460 | GNUNET_free (gen_cfgs[0]); | ||
461 | } | ||
572 | } | 462 | } |
573 | 463 | return 0; | |
574 | GNUNET_free (test_source); | ||
575 | GNUNET_free (test_plugin); | ||
576 | GNUNET_free (test_name); | ||
577 | |||
578 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
579 | |||
580 | return test_failed; | ||
581 | } | 464 | } |
582 | 465 | ||
583 | 466 | ||
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 9983356de..bb10116e2 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -44,169 +44,80 @@ | |||
44 | 44 | ||
45 | #define TEST_MESSAGE_TYPE 12345 | 45 | #define TEST_MESSAGE_TYPE 12345 |
46 | 46 | ||
47 | static char *test_source; | ||
48 | 47 | ||
49 | static char *test_plugin; | 48 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
50 | |||
51 | static char *test_name; | ||
52 | |||
53 | static int ok; | ||
54 | |||
55 | static int s_started; | ||
56 | |||
57 | static int s_connected; | ||
58 | |||
59 | static int s_sending; | ||
60 | |||
61 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
62 | |||
63 | static struct GNUNET_SCHEDULER_Task * send_task; | ||
64 | |||
65 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
66 | |||
67 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
68 | |||
69 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
70 | 49 | ||
71 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 50 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
72 | 51 | ||
73 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
74 | |||
75 | static char *cfg_file_p1; | ||
76 | |||
77 | static char *cfg_file_p2; | ||
78 | |||
79 | |||
80 | static void | ||
81 | end () | ||
82 | { | ||
83 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stopping peers\n"); | ||
84 | |||
85 | if (send_task != NULL) | ||
86 | GNUNET_SCHEDULER_cancel (send_task); | ||
87 | |||
88 | if (die_task != NULL) | ||
89 | GNUNET_SCHEDULER_cancel (die_task); | ||
90 | |||
91 | if (th != NULL) | ||
92 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
93 | th = NULL; | ||
94 | |||
95 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
96 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
97 | } | ||
98 | |||
99 | 52 | ||
100 | static void | 53 | static void |
101 | end_badly (void *cls) | 54 | custom_shutdown (void *cls) |
102 | { | 55 | { |
103 | die_task = NULL; | 56 | if (NULL != th) |
104 | |||
105 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fail! Stopping peers\n"); | ||
106 | |||
107 | |||
108 | if (send_task != NULL) | ||
109 | GNUNET_SCHEDULER_cancel (send_task); | ||
110 | |||
111 | if (cc != NULL) | ||
112 | { | 57 | { |
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | ||
114 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
115 | cc = NULL; | ||
116 | } | ||
117 | |||
118 | if (th != NULL) | ||
119 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 58 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
59 | th = NULL; | ||
60 | } | ||
120 | else | 61 | else |
121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | 62 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
122 | 63 | "Peers were not ready to send data\n"); | |
123 | if (s_started == GNUNET_NO) | ||
124 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were not started \n")); | ||
125 | else | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were started \n")); | ||
127 | |||
128 | if (s_connected == GNUNET_NO) | ||
129 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not connected\n")); | ||
130 | else | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were connected\n")); | ||
132 | |||
133 | if (s_sending == GNUNET_NO) | ||
134 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | ||
135 | else | ||
136 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were ready to send data\n")); | ||
137 | |||
138 | th = NULL; | ||
139 | |||
140 | if (p1 != NULL) | ||
141 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
142 | else | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); | ||
144 | if (p2 != NULL) | ||
145 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
146 | else | ||
147 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); | ||
148 | |||
149 | ok = GNUNET_SYSERR; | ||
150 | } | 64 | } |
151 | 65 | ||
152 | 66 | ||
153 | static void | 67 | static void |
154 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 68 | notify_receive (void *cls, |
69 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
70 | const struct GNUNET_PeerIdentity *sender, | ||
155 | const struct GNUNET_MessageHeader *message) | 71 | const struct GNUNET_MessageHeader *message) |
156 | { | 72 | { |
157 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 73 | { |
158 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 74 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
159 | |||
160 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
161 | t = p1; | ||
162 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
163 | t = p2; | ||
164 | GNUNET_assert (t != NULL); | ||
165 | |||
166 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
167 | 75 | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 76 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
169 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 77 | "Peer %u (`%4s') received message of type %d and size %u size from peer %s!\n", |
170 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | 78 | receiver->no, |
171 | GNUNET_i2s (&t->id)); | 79 | ps, |
172 | GNUNET_free (ps); | 80 | ntohs (message->type), |
81 | ntohs (message->size), | ||
82 | GNUNET_i2s (sender)); | ||
83 | GNUNET_free (ps); | ||
84 | } | ||
173 | 85 | ||
174 | if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && | 86 | if ((TEST_MESSAGE_TYPE == ntohs (message->type)) && |
175 | (TEST_MESSAGE_SIZE == ntohs (message->size))) | 87 | (TEST_MESSAGE_SIZE == ntohs (message->size))) |
176 | { | 88 | { |
177 | ok = 0; | 89 | ccc->global_ret = GNUNET_OK; |
178 | end (); | 90 | GNUNET_SCHEDULER_shutdown (); |
179 | } | 91 | } |
180 | else | 92 | else |
181 | { | 93 | { |
182 | GNUNET_break (0); | 94 | GNUNET_break (0); |
183 | ok = 1; | 95 | ccc->global_ret = GNUNET_SYSERR; |
184 | end (); | 96 | GNUNET_SCHEDULER_shutdown (); |
185 | } | 97 | } |
186 | } | 98 | } |
187 | 99 | ||
188 | 100 | ||
189 | static size_t | 101 | static size_t |
190 | notify_ready (void *cls, size_t size, void *buf) | 102 | notify_ready (void *cls, |
103 | size_t size, | ||
104 | void *buf) | ||
191 | { | 105 | { |
192 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 106 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
193 | struct GNUNET_MessageHeader *hdr; | 107 | struct GNUNET_MessageHeader *hdr; |
194 | 108 | ||
195 | th = NULL; | 109 | th = NULL; |
196 | |||
197 | if (buf == NULL) | 110 | if (buf == NULL) |
198 | { | 111 | { |
199 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 112 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
200 | "Timeout occurred while waiting for transmit_ready\n"); | 113 | "Timeout occurred while waiting for transmit_ready\n"); |
201 | if (NULL != die_task) | 114 | GNUNET_SCHEDULER_shutdown (); |
202 | GNUNET_SCHEDULER_cancel (die_task); | 115 | ccc->global_ret = 42; |
203 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
204 | ok = 42; | ||
205 | return 0; | 116 | return 0; |
206 | } | 117 | } |
207 | 118 | ||
208 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | 119 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); |
209 | if (buf != NULL) | 120 | if (NULL != buf) |
210 | { | 121 | { |
211 | memset (buf, '\0', TEST_MESSAGE_SIZE); | 122 | memset (buf, '\0', TEST_MESSAGE_SIZE); |
212 | hdr = buf; | 123 | hdr = buf; |
@@ -214,222 +125,83 @@ notify_ready (void *cls, size_t size, void *buf) | |||
214 | hdr->type = htons (TEST_MESSAGE_TYPE); | 125 | hdr->type = htons (TEST_MESSAGE_TYPE); |
215 | } | 126 | } |
216 | 127 | ||
217 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | ||
218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
219 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
220 | p2->no, ps, ntohs (hdr->type), ntohs (hdr->size), p->no, | ||
221 | GNUNET_i2s (&p->id)); | ||
222 | GNUNET_free (ps); | ||
223 | |||
224 | return TEST_MESSAGE_SIZE; | ||
225 | } | ||
226 | |||
227 | |||
228 | static void | ||
229 | sendtask (void *cls) | ||
230 | { | ||
231 | send_task = NULL; | ||
232 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
233 | |||
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
235 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
236 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); | ||
237 | GNUNET_free (receiver_s); | ||
238 | s_sending = GNUNET_YES; | ||
239 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, | ||
240 | TIMEOUT_TRANSMIT, ¬ify_ready, | ||
241 | p1); | ||
242 | } | ||
243 | |||
244 | |||
245 | static void | ||
246 | notify_connect (void *cls, | ||
247 | const struct GNUNET_PeerIdentity *peer) | ||
248 | { | ||
249 | static int c; | ||
250 | |||
251 | c++; | ||
252 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
253 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
254 | |||
255 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
256 | t = p1; | ||
257 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
258 | t = p2; | ||
259 | GNUNET_assert (t != NULL); | ||
260 | |||
261 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
262 | |||
263 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
264 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | ||
265 | t->no, GNUNET_i2s (peer)); | ||
266 | GNUNET_free (ps); | ||
267 | } | ||
268 | |||
269 | |||
270 | static void | ||
271 | notify_disconnect (void *cls, | ||
272 | const struct GNUNET_PeerIdentity *peer) | ||
273 | { | ||
274 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
275 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
276 | |||
277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
278 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", | ||
279 | p->no, | ||
280 | ps, | ||
281 | GNUNET_i2s (peer)); | ||
282 | GNUNET_free (ps); | ||
283 | |||
284 | if (th != NULL) | ||
285 | { | 128 | { |
286 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 129 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); |
287 | th = NULL; | 130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
131 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
132 | ccc->p[1]->no, | ||
133 | ps, | ||
134 | ntohs (hdr->type), | ||
135 | ntohs (hdr->size), | ||
136 | p->no, | ||
137 | GNUNET_i2s (&p->id)); | ||
138 | GNUNET_free (ps); | ||
288 | } | 139 | } |
140 | return TEST_MESSAGE_SIZE; | ||
289 | } | 141 | } |
290 | 142 | ||
291 | 143 | ||
292 | static void | 144 | static void |
293 | testing_connect_cb (void *cls) | 145 | sendtask (void *cls) |
294 | { | ||
295 | cc = NULL; | ||
296 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
297 | |||
298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
299 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
300 | GNUNET_free (p1_c); | ||
301 | |||
302 | s_connected = GNUNET_YES; | ||
303 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
304 | } | ||
305 | |||
306 | |||
307 | static void | ||
308 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | ||
309 | void *cls) | ||
310 | { | 146 | { |
311 | static int started; | ||
312 | |||
313 | started++; | ||
314 | |||
315 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
316 | "Peer %u (`%s') started\n", | ||
317 | p->no, | ||
318 | GNUNET_i2s (&p->id)); | ||
319 | if (started != 2) | ||
320 | return; | ||
321 | s_started = GNUNET_YES; | ||
322 | { | 147 | { |
323 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 148 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
324 | 149 | ||
325 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 150 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
326 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | 151 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
327 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | 152 | ccc->p[1]->no, |
328 | GNUNET_free (sender_c); | 153 | GNUNET_i2s (&ccc->p[1]->id), |
154 | ccc->p[0]->no, | ||
155 | receiver_s); | ||
156 | GNUNET_free (receiver_s); | ||
329 | } | 157 | } |
330 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | 158 | ccc->global_ret = GNUNET_SYSERR; |
331 | p2, | 159 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, |
332 | &testing_connect_cb, | 160 | &ccc->p[0]->id, |
333 | NULL); | 161 | TEST_MESSAGE_SIZE, |
162 | TIMEOUT_TRANSMIT, | ||
163 | ¬ify_ready, | ||
164 | ccc->p[0]); | ||
334 | } | 165 | } |
335 | 166 | ||
336 | 167 | ||
337 | static void | 168 | static void |
338 | run (void *cls, | 169 | notify_disconnect (void *cls, |
339 | char *const *args, | 170 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
340 | const char *cfgfile, | 171 | const struct GNUNET_PeerIdentity *other) |
341 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
342 | { | 172 | { |
343 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 173 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
344 | &end_badly, | 174 | me, |
345 | NULL); | 175 | other); |
346 | 176 | if (NULL != th) | |
347 | s_started = GNUNET_NO; | ||
348 | s_connected = GNUNET_NO; | ||
349 | s_sending = GNUNET_NO; | ||
350 | |||
351 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, | ||
352 | ¬ify_receive, ¬ify_connect, | ||
353 | ¬ify_disconnect, &start_cb, | ||
354 | NULL); | ||
355 | |||
356 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
357 | ¬ify_receive, ¬ify_connect, | ||
358 | ¬ify_disconnect, &start_cb, | ||
359 | NULL); | ||
360 | |||
361 | if ((p1 == NULL) || (p2 == NULL)) | ||
362 | { | 177 | { |
363 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 178 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
364 | "Fail! Could not start peers!\n"); | 179 | th = NULL; |
365 | if (die_task != NULL) | ||
366 | GNUNET_SCHEDULER_cancel (die_task); | ||
367 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
368 | return; | ||
369 | } | 180 | } |
370 | } | 181 | } |
371 | 182 | ||
372 | 183 | ||
373 | static int | ||
374 | check () | ||
375 | { | ||
376 | static char *const argv[] = { | ||
377 | "test-transport-api", | ||
378 | "-c", | ||
379 | "test_transport_api_data.conf", | ||
380 | NULL | ||
381 | }; | ||
382 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
383 | GNUNET_GETOPT_OPTION_END | ||
384 | }; | ||
385 | |||
386 | send_task = NULL; | ||
387 | |||
388 | ok = 1; | ||
389 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
390 | argv, | ||
391 | test_name, | ||
392 | "nohelp", | ||
393 | options, | ||
394 | &run, | ||
395 | &ok); | ||
396 | |||
397 | return ok; | ||
398 | } | ||
399 | |||
400 | |||
401 | int | 184 | int |
402 | main (int argc, char *argv[]) | 185 | main (int argc, |
186 | char *argv[]) | ||
403 | { | 187 | { |
404 | int ret; | 188 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
405 | 189 | .connect_continuation = &sendtask, | |
406 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 190 | .config_file = "test_transport_api_data.conf", |
407 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | 191 | .rec = ¬ify_receive, |
408 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | 192 | .nc = &GNUNET_TRANSPORT_TESTING_log_connect, |
409 | test_source); | 193 | .nd = ¬ify_disconnect, |
410 | 194 | .shutdown_task = &custom_shutdown, | |
411 | GNUNET_log_setup (test_name, | 195 | .timeout = TIMEOUT |
412 | "WARNING", | 196 | }; |
413 | NULL); | ||
414 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
415 | |||
416 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], | ||
417 | 1); | ||
418 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], | ||
419 | 2); | ||
420 | |||
421 | ret = check (); | ||
422 | |||
423 | GNUNET_free (cfg_file_p1); | ||
424 | GNUNET_free (cfg_file_p2); | ||
425 | |||
426 | GNUNET_free (test_source); | ||
427 | GNUNET_free (test_plugin); | ||
428 | GNUNET_free (test_name); | ||
429 | |||
430 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
431 | 197 | ||
432 | return ret; | 198 | ccc = &my_ccc; |
199 | if (GNUNET_OK != | ||
200 | GNUNET_TRANSPORT_TESTING_main (2, | ||
201 | &GNUNET_TRANSPORT_TESTING_connect_check, | ||
202 | ccc)) | ||
203 | return 1; | ||
204 | return 0; | ||
433 | } | 205 | } |
434 | 206 | ||
435 | /* end of test_transport_api.c */ | 207 | /* end of test_transport_api.c */ |
diff --git a/src/transport/transport-testing-loggers.c b/src/transport/transport-testing-loggers.c new file mode 100644 index 000000000..de9fa91c1 --- /dev/null +++ b/src/transport/transport-testing-loggers.c | |||
@@ -0,0 +1,76 @@ | |||
1 | |||
2 | /* | ||
3 | This file is part of GNUnet. | ||
4 | Copyright (C) 2016 GNUnet e.V. | ||
5 | |||
6 | GNUnet is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published | ||
8 | by the Free Software Foundation; either version 3, or (at your | ||
9 | option) any later version. | ||
10 | |||
11 | GNUnet is distributed in the hope that it will be useful, but | ||
12 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with GNUnet; see the file COPYING. If not, write to the | ||
18 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
19 | Boston, MA 02110-1301, USA. | ||
20 | */ | ||
21 | /** | ||
22 | * @file transport-testing-loggers.c | ||
23 | * @brief convenience functions for logging common events in tests | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "transport-testing.h" | ||
27 | |||
28 | |||
29 | /** | ||
30 | * Log a connect event. | ||
31 | * | ||
32 | * @param cls NULL | ||
33 | * @param me peer that had the event | ||
34 | * @param other peer that connected. | ||
35 | */ | ||
36 | void | ||
37 | GNUNET_TRANSPORT_TESTING_log_connect (void *cls, | ||
38 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
39 | const struct GNUNET_PeerIdentity *other) | ||
40 | { | ||
41 | char *ps; | ||
42 | |||
43 | ps = GNUNET_strdup (GNUNET_i2s (&me->id)); | ||
44 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
45 | "Peer %s connected to %u (%s)!\n", | ||
46 | GNUNET_i2s (other), | ||
47 | me->no, | ||
48 | ps); | ||
49 | GNUNET_free (ps); | ||
50 | } | ||
51 | |||
52 | |||
53 | |||
54 | /** | ||
55 | * Log a disconnect event. | ||
56 | * | ||
57 | * @param cls NULL | ||
58 | * @param me peer that had the event | ||
59 | * @param other peer that disconnected. | ||
60 | */ | ||
61 | void | ||
62 | GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, | ||
63 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
64 | const struct GNUNET_PeerIdentity *other) | ||
65 | { | ||
66 | char *ps; | ||
67 | |||
68 | ps = GNUNET_strdup (GNUNET_i2s (&me->id)); | ||
69 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
70 | "Peer `%s' disconnected from %u (%s)!\n", | ||
71 | GNUNET_i2s (other), | ||
72 | me->no, | ||
73 | ps); | ||
74 | } | ||
75 | |||
76 | /* end of transport-testing-loggers.c */ | ||
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c index 9cda749fe..8dfd51074 100644 --- a/src/transport/transport-testing-main.c +++ b/src/transport/transport-testing-main.c | |||
@@ -26,6 +26,401 @@ | |||
26 | 26 | ||
27 | 27 | ||
28 | /** | 28 | /** |
29 | * Closure for #connect_cb. | ||
30 | */ | ||
31 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList | ||
32 | { | ||
33 | /** | ||
34 | * Stored in a DLL. | ||
35 | */ | ||
36 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *next; | ||
37 | |||
38 | /** | ||
39 | * Stored in a DLL. | ||
40 | */ | ||
41 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *prev; | ||
42 | |||
43 | /** | ||
44 | * Overall context we are in. | ||
45 | */ | ||
46 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
47 | |||
48 | /** | ||
49 | * Connect request this is about. | ||
50 | */ | ||
51 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; | ||
52 | |||
53 | /** | ||
54 | * Peer being connected. | ||
55 | */ | ||
56 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
57 | |||
58 | /** | ||
59 | * Peer being connected. | ||
60 | */ | ||
61 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
62 | |||
63 | }; | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Shutdown function for the test. Stops all peers. | ||
68 | * | ||
69 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` | ||
70 | */ | ||
71 | static void | ||
72 | do_shutdown (void *cls) | ||
73 | { | ||
74 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | ||
75 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; | ||
76 | |||
77 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
78 | "Testcase shutting down\n"); | ||
79 | if (NULL != ccc->shutdown_task) | ||
80 | ccc->shutdown_task (ccc->shutdown_task_cls); | ||
81 | if (NULL != ccc->timeout_task) | ||
82 | { | ||
83 | GNUNET_SCHEDULER_cancel (ccc->timeout_task); | ||
84 | ccc->timeout_task = NULL; | ||
85 | } | ||
86 | while (NULL != (crl = ccc->crl_head)) | ||
87 | { | ||
88 | GNUNET_CONTAINER_DLL_remove (ccc->crl_head, | ||
89 | ccc->crl_tail, | ||
90 | crl); | ||
91 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (crl->cr); | ||
92 | GNUNET_free (crl); | ||
93 | } | ||
94 | for (unsigned int i=0;i<ccc->num_peers;i++) | ||
95 | { | ||
96 | GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]); | ||
97 | ccc->p[i] = NULL; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | |||
102 | /** | ||
103 | * Testcase hit timeout, shut it down with error. | ||
104 | * | ||
105 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` | ||
106 | */ | ||
107 | static void | ||
108 | do_timeout (void *cls) | ||
109 | { | ||
110 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | ||
111 | |||
112 | ccc->timeout_task = NULL; | ||
113 | GNUNET_break (0); /* signal timeout */ | ||
114 | ccc->global_ret = GNUNET_SYSERR; | ||
115 | GNUNET_SCHEDULER_shutdown (); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * Internal data structure. Closure for | ||
121 | * #connect_cb, #disconnect_cb, #my_nc and #start_cb. | ||
122 | * Allows us to identify which peer this is about. | ||
123 | */ | ||
124 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext | ||
125 | { | ||
126 | /** | ||
127 | * Overall context of the callback. | ||
128 | */ | ||
129 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
130 | |||
131 | /** | ||
132 | * Offset of the peer this is about. | ||
133 | */ | ||
134 | unsigned int off; | ||
135 | }; | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Function called when we connected two peers. | ||
140 | * Once we have gotten to the clique, launch | ||
141 | * test-specific logic. | ||
142 | * | ||
143 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` | ||
144 | */ | ||
145 | static void | ||
146 | connect_cb (void *cls) | ||
147 | { | ||
148 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; | ||
149 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; | ||
150 | |||
151 | GNUNET_CONTAINER_DLL_remove (ccc->crl_head, | ||
152 | ccc->crl_tail, | ||
153 | crl); | ||
154 | { | ||
155 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id)); | ||
156 | |||
157 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
158 | "Peers connected: %u (%s) <-> %u (%s)\n", | ||
159 | crl->p1->no, | ||
160 | p1_c, | ||
161 | crl->p2->no, | ||
162 | GNUNET_i2s (&crl->p2->id)); | ||
163 | GNUNET_free (p1_c); | ||
164 | GNUNET_free (crl); | ||
165 | } | ||
166 | if (NULL == ccc->crl_head) | ||
167 | { | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
169 | "All connections UP, launching custom test logic.\n"); | ||
170 | GNUNET_SCHEDULER_add_now (ccc->connect_continuation, | ||
171 | ccc->connect_continuation_cls); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | |||
176 | /** | ||
177 | * Find peer by peer ID. | ||
178 | * | ||
179 | * @param ccc context to search | ||
180 | * @param peer peer to look for | ||
181 | * @return NULL if @a peer was not found | ||
182 | */ | ||
183 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | ||
184 | GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | ||
185 | const struct GNUNET_PeerIdentity *peer) | ||
186 | { | ||
187 | for (unsigned int i=0;i<ccc->num_peers;i++) | ||
188 | if ( (NULL != ccc->p[i]) && | ||
189 | (0 == memcmp (peer, | ||
190 | &ccc->p[i]->id, | ||
191 | sizeof (*peer))) ) | ||
192 | return ccc->p[i]; | ||
193 | return NULL; | ||
194 | } | ||
195 | |||
196 | |||
197 | /** | ||
198 | * Wrapper around peers connecting. Calls client's nc function. | ||
199 | * | ||
200 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | ||
201 | * @param peer peer we got connected to | ||
202 | */ | ||
203 | static void | ||
204 | my_nc (void *cls, | ||
205 | const struct GNUNET_PeerIdentity *peer) | ||
206 | { | ||
207 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | ||
208 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | ||
209 | |||
210 | if (NULL != ccc->nc) | ||
211 | ccc->nc (ccc->cls, | ||
212 | ccc->p[ipi->off], | ||
213 | peer); | ||
214 | } | ||
215 | |||
216 | |||
217 | |||
218 | /** | ||
219 | * Wrapper around peers disconnecting. Calls client's nd function. | ||
220 | * | ||
221 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | ||
222 | * @param peer peer we got disconnected from | ||
223 | */ | ||
224 | static void | ||
225 | my_nd (void *cls, | ||
226 | const struct GNUNET_PeerIdentity *peer) | ||
227 | { | ||
228 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | ||
229 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | ||
230 | |||
231 | if (NULL != ccc->nd) | ||
232 | ccc->nd (ccc->cls, | ||
233 | ccc->p[ipi->off], | ||
234 | peer); | ||
235 | } | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Wrapper around receiving data. Calls client's rec function. | ||
240 | * | ||
241 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | ||
242 | * @param peer peer we got a message from | ||
243 | * @param message message we received | ||
244 | */ | ||
245 | static void | ||
246 | my_rec (void *cls, | ||
247 | const struct GNUNET_PeerIdentity *peer, | ||
248 | const struct GNUNET_MessageHeader *message) | ||
249 | { | ||
250 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | ||
251 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | ||
252 | |||
253 | if (NULL != ccc->rec) | ||
254 | ccc->rec (ccc->cls, | ||
255 | ccc->p[ipi->off], | ||
256 | peer, | ||
257 | message); | ||
258 | } | ||
259 | |||
260 | |||
261 | /** | ||
262 | * Function called once we have successfully launched a peer. | ||
263 | * Once all peers have been launched, we connect all of them | ||
264 | * in a clique. | ||
265 | * | ||
266 | * @param p peer that was launched (redundant, kill ASAP) | ||
267 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` | ||
268 | */ | ||
269 | static void | ||
270 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | ||
271 | void *cls) | ||
272 | { | ||
273 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; | ||
274 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; | ||
275 | |||
276 | ccc->started++; | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
278 | "Peer %u (`%s') started\n", | ||
279 | p->no, | ||
280 | GNUNET_i2s (&p->id)); | ||
281 | if (ccc->started != ccc->num_peers) | ||
282 | return; | ||
283 | |||
284 | for (unsigned int i=0;i<ccc->num_peers;i++) | ||
285 | for (unsigned int j=i+1;j<ccc->num_peers;j++) | ||
286 | { | ||
287 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; | ||
288 | |||
289 | crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); | ||
290 | GNUNET_CONTAINER_DLL_insert (ccc->crl_head, | ||
291 | ccc->crl_tail, | ||
292 | crl); | ||
293 | crl->ccc = ccc; | ||
294 | crl->p1 = ccc->p[i]; | ||
295 | crl->p2 = ccc->p[j]; | ||
296 | { | ||
297 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); | ||
298 | |||
299 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
300 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
301 | ccc->p[0]->no, | ||
302 | sender_c, | ||
303 | ccc->p[1]->no, | ||
304 | GNUNET_i2s (&ccc->p[1]->id)); | ||
305 | GNUNET_free (sender_c); | ||
306 | } | ||
307 | crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers (ccc->p[i], | ||
308 | ccc->p[j], | ||
309 | &connect_cb, | ||
310 | crl); | ||
311 | } | ||
312 | } | ||
313 | |||
314 | |||
315 | /** | ||
316 | * Function run from #GNUNET_TRANSPORT_TESTING_connect_check | ||
317 | * once the scheduler is up. Should launch the peers and | ||
318 | * then in the continuations try to connect them. | ||
319 | * | ||
320 | * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` | ||
321 | * @param args ignored | ||
322 | * @param cfgfile ignored | ||
323 | * @param cfg configuration | ||
324 | */ | ||
325 | static void | ||
326 | connect_check_run (void *cls, | ||
327 | char *const *args, | ||
328 | const char *cfgfile, | ||
329 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
330 | { | ||
331 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | ||
332 | int ok; | ||
333 | |||
334 | ccc->cfg = cfg; | ||
335 | ccc->timeout_task = GNUNET_SCHEDULER_add_delayed (ccc->timeout, | ||
336 | &do_timeout, | ||
337 | ccc); | ||
338 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
339 | ccc); | ||
340 | ok = GNUNET_OK; | ||
341 | for (unsigned int i=0;i<ccc->num_peers;i++) | ||
342 | { | ||
343 | ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, | ||
344 | ccc->cfg_files[i], | ||
345 | i + 1, | ||
346 | &my_rec, | ||
347 | &my_nc, | ||
348 | &my_nd, | ||
349 | &start_cb, | ||
350 | &ccc->ip[i]); | ||
351 | if (NULL == ccc->p[i]) | ||
352 | ok = GNUNET_SYSERR; | ||
353 | } | ||
354 | if (GNUNET_OK != ok) | ||
355 | { | ||
356 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
357 | "Fail! Could not start peers!\n"); | ||
358 | GNUNET_SCHEDULER_shutdown (); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | |||
363 | /** | ||
364 | * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback. | ||
365 | * Starts and connects the two peers, then invokes the | ||
366 | * `connect_continuation` from @a cls. Sets up a timeout to | ||
367 | * abort the test, and a shutdown handler to clean up properly | ||
368 | * on exit. | ||
369 | * | ||
370 | * @param cls closure of type `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | ||
371 | * @param tth_ initialized testing handle | ||
372 | * @param test_plugin_ name of the plugin | ||
373 | * @param test_name_ name of the test | ||
374 | * @param num_peers number of entries in the @a cfg_file array | ||
375 | * @param cfg_files array of names of configuration files for the peers | ||
376 | * @return #GNUNET_SYSERR on error | ||
377 | */ | ||
378 | int | ||
379 | GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | ||
380 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | ||
381 | const char *test_plugin_, | ||
382 | const char *test_name_, | ||
383 | unsigned int num_peers, | ||
384 | char *cfg_files[]) | ||
385 | { | ||
386 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
387 | GNUNET_GETOPT_OPTION_END | ||
388 | }; | ||
389 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; | ||
390 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; | ||
391 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; | ||
392 | char * argv[] = { | ||
393 | (char *) test_name_, | ||
394 | "-c", | ||
395 | (char *) ccc->config_file, | ||
396 | NULL | ||
397 | }; | ||
398 | |||
399 | ccc->num_peers = num_peers; | ||
400 | ccc->cfg_files = cfg_files; | ||
401 | ccc->test_plugin = test_plugin_; | ||
402 | ccc->test_name = test_name_; | ||
403 | ccc->tth = tth_; | ||
404 | ccc->global_ret = GNUNET_OK; | ||
405 | ccc->p = p; | ||
406 | ccc->ip = ip; | ||
407 | for (unsigned int i=0;i<num_peers;i++) | ||
408 | { | ||
409 | ip[i].off = i; | ||
410 | ip[i].ccc = ccc; | ||
411 | } | ||
412 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | ||
413 | argv, | ||
414 | test_name_, | ||
415 | "nohelp", | ||
416 | options, | ||
417 | &connect_check_run, | ||
418 | ccc); | ||
419 | return ccc->global_ret; | ||
420 | } | ||
421 | |||
422 | |||
423 | /** | ||
29 | * Setup testcase. Calls @a check with the data the test needs. | 424 | * Setup testcase. Calls @a check with the data the test needs. |
30 | * | 425 | * |
31 | * @param argv0 binary name (argv[0]) | 426 | * @param argv0 binary name (argv[0]) |
@@ -42,7 +437,45 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
42 | GNUNET_TRANSPORT_TESTING_CheckCallback check, | 437 | GNUNET_TRANSPORT_TESTING_CheckCallback check, |
43 | void *check_cls) | 438 | void *check_cls) |
44 | { | 439 | { |
45 | return GNUNET_SYSERR; | 440 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; |
441 | char *test_name; | ||
442 | char *test_source; | ||
443 | char *test_plugin; | ||
444 | char *cfg_names[num_peers]; | ||
445 | int ret; | ||
446 | |||
447 | ret = GNUNET_OK; | ||
448 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0); | ||
449 | GNUNET_log_setup (test_name, | ||
450 | "WARNING", | ||
451 | NULL); | ||
452 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (filename); | ||
453 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv0, | ||
454 | test_source); | ||
455 | for (unsigned int i=0;i<num_peers;i++) | ||
456 | cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0, | ||
457 | i+1); | ||
458 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
459 | if (NULL == tth) | ||
460 | { | ||
461 | ret = GNUNET_SYSERR; | ||
462 | } | ||
463 | else | ||
464 | { | ||
465 | ret = check (check_cls, | ||
466 | tth, | ||
467 | test_plugin, | ||
468 | test_name, | ||
469 | num_peers, | ||
470 | cfg_names); | ||
471 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
472 | } | ||
473 | for (unsigned int i=0;i<num_peers;i++) | ||
474 | GNUNET_free (cfg_names[i]); | ||
475 | GNUNET_free (test_source); | ||
476 | GNUNET_free (test_plugin); | ||
477 | GNUNET_free (test_name); | ||
478 | return ret; | ||
46 | } | 479 | } |
47 | 480 | ||
48 | /* end of transport-testing-main.c */ | 481 | /* end of transport-testing-main.c */ |
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index fc017e377..842c88374 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -33,6 +33,8 @@ | |||
33 | #include "gnunet_testing_lib.h" | 33 | #include "gnunet_testing_lib.h" |
34 | 34 | ||
35 | 35 | ||
36 | /* ************* Basic functions for starting/stopping/connecting *********** */ | ||
37 | |||
36 | /** | 38 | /** |
37 | * Context for a single peer | 39 | * Context for a single peer |
38 | */ | 40 | */ |
@@ -47,12 +49,16 @@ struct GNUNET_TRANSPORT_TESTING_Handle; | |||
47 | /** | 49 | /** |
48 | * Callback when two peers are connected and both have called the connect callback | 50 | * Callback when two peers are connected and both have called the connect callback |
49 | * to notify clients about a new peer | 51 | * to notify clients about a new peer |
52 | * | ||
53 | * @param p FIXME: remove ASAP. | ||
54 | * @param cls closure | ||
50 | */ | 55 | */ |
51 | typedef void | 56 | typedef void |
52 | (*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 57 | (*GNUNET_TRANSPORT_TESTING_StartCallback) (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
53 | void *cls); | 58 | void *cls); |
54 | 59 | ||
55 | 60 | ||
61 | |||
56 | /** | 62 | /** |
57 | * Context for a single peer | 63 | * Context for a single peer |
58 | */ | 64 | */ |
@@ -150,17 +156,54 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext | |||
150 | */ | 156 | */ |
151 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest | 157 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest |
152 | { | 158 | { |
159 | /** | ||
160 | * Kept in a DLL. | ||
161 | */ | ||
153 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; | 162 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *next; |
163 | |||
164 | /** | ||
165 | * Kept in a DLL. | ||
166 | */ | ||
154 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; | 167 | struct GNUNET_TRANSPORT_TESTING_ConnectRequest *prev; |
168 | |||
169 | /** | ||
170 | * Peer we want to connect. | ||
171 | */ | ||
155 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | 172 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; |
173 | |||
174 | /** | ||
175 | * Peer we want to connect. | ||
176 | */ | ||
156 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | 177 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; |
178 | |||
179 | /** | ||
180 | * Task by which we accomplish the connection. | ||
181 | */ | ||
157 | struct GNUNET_SCHEDULER_Task *tct; | 182 | struct GNUNET_SCHEDULER_Task *tct; |
183 | |||
184 | /** | ||
185 | * Handle by which we ask ATS to faciliate the connection. | ||
186 | */ | ||
158 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | 187 | struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; |
188 | |||
189 | /** | ||
190 | * Handle by which we inform the peer about the HELLO of | ||
191 | * the other peer. | ||
192 | */ | ||
159 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; | 193 | struct GNUNET_TRANSPORT_OfferHelloHandle *oh; |
194 | |||
195 | /** | ||
196 | * Function to call upon completion. | ||
197 | */ | ||
160 | GNUNET_SCHEDULER_TaskCallback cb; | 198 | GNUNET_SCHEDULER_TaskCallback cb; |
199 | |||
200 | /** | ||
201 | * Closure for @e cb. | ||
202 | */ | ||
161 | void *cb_cls; | 203 | void *cb_cls; |
162 | int p1_c; | 204 | |
163 | int p2_c; | 205 | int p1_c; // dead? |
206 | int p2_c; // dead? | ||
164 | }; | 207 | }; |
165 | 208 | ||
166 | 209 | ||
@@ -290,25 +333,264 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont | |||
290 | void | 333 | void |
291 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); | 334 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); |
292 | 335 | ||
336 | |||
293 | /* ********************** high-level process functions *************** */ | 337 | /* ********************** high-level process functions *************** */ |
294 | 338 | ||
295 | 339 | ||
296 | /** | 340 | /** |
341 | * Function called once the peers have been launched and | ||
342 | * connected by #GNUNET_TRANSPORT_TESTING_connect_check(). | ||
343 | * | ||
344 | * @param cls closure | ||
345 | * @param num_peers size of the @a p array | ||
346 | * @param p the peers that were launched | ||
347 | */ | ||
348 | typedef void | ||
349 | (*GNUNET_TRANSPORT_TESTING_ConnectContinuation)(void *cls, | ||
350 | unsigned int num_peers, | ||
351 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p[]); | ||
352 | |||
353 | |||
354 | /** | ||
355 | * Internal data structure. | ||
356 | */ | ||
357 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList; | ||
358 | |||
359 | /** | ||
360 | * Internal data structure. | ||
361 | */ | ||
362 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext; | ||
363 | |||
364 | |||
365 | /** | ||
366 | * Function called by the transport for each received message. | ||
367 | * | ||
368 | * @param cls closure | ||
369 | * @param receiver receiver of the message | ||
370 | * @param sender sender of the message | ||
371 | * @param message the message | ||
372 | */ | ||
373 | typedef void | ||
374 | (*GNUNET_TRANSPORT_TESTING_ReceiveCallback) (void *cls, | ||
375 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
376 | const struct GNUNET_PeerIdentity *sender, | ||
377 | const struct GNUNET_MessageHeader *message); | ||
378 | |||
379 | |||
380 | /** | ||
381 | * Function called to notify transport users that another | ||
382 | * peer connected to us. | ||
383 | * | ||
384 | * @param cls closure | ||
385 | * @param me peer experiencing the event | ||
386 | * @param other peer that connected to @a me | ||
387 | */ | ||
388 | typedef void | ||
389 | (*GNUNET_TRANSPORT_TESTING_NotifyConnect) (void *cls, | ||
390 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
391 | const struct GNUNET_PeerIdentity *other); | ||
392 | |||
393 | |||
394 | /** | ||
395 | * Function called to notify transport users that another | ||
396 | * peer disconnected from us. | ||
397 | * | ||
398 | * @param cls closure | ||
399 | * @param me peer experiencing the event | ||
400 | * @param other peer that disconnected from @a me | ||
401 | */ | ||
402 | typedef void | ||
403 | (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (void *cls, | ||
404 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
405 | const struct GNUNET_PeerIdentity *other); | ||
406 | |||
407 | |||
408 | /** | ||
409 | * Closure that must be passed to | ||
410 | * #GNUNET_TRANSPORT_TESTING_connect_check. | ||
411 | */ | ||
412 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext | ||
413 | { | ||
414 | |||
415 | /** | ||
416 | * How should we continue after the connect? | ||
417 | */ | ||
418 | GNUNET_SCHEDULER_TaskCallback connect_continuation; | ||
419 | |||
420 | /** | ||
421 | * Closure for @e connect_continuation. | ||
422 | */ | ||
423 | void *connect_continuation_cls; | ||
424 | |||
425 | /** | ||
426 | * Which configuration file should we pass to the | ||
427 | * #GNUNET_PROGRAM_run() of the testcase? | ||
428 | */ | ||
429 | const char *config_file; | ||
430 | |||
431 | /** | ||
432 | * Receiver argument to give for peers we start. | ||
433 | */ | ||
434 | GNUNET_TRANSPORT_TESTING_ReceiveCallback rec; | ||
435 | |||
436 | /** | ||
437 | * Notify connect argument to give for peers we start. | ||
438 | */ | ||
439 | GNUNET_TRANSPORT_TESTING_NotifyConnect nc; | ||
440 | |||
441 | /** | ||
442 | * Notify disconnect argument to give for peers we start. | ||
443 | */ | ||
444 | GNUNET_TRANSPORT_TESTING_NotifyDisconnect nd; | ||
445 | |||
446 | /** | ||
447 | * Closure for @e rec, @e nc and @e nd. | ||
448 | */ | ||
449 | void *cls; | ||
450 | |||
451 | /** | ||
452 | * Custom task to run on shutdown. | ||
453 | */ | ||
454 | GNUNET_SCHEDULER_TaskCallback shutdown_task; | ||
455 | |||
456 | /** | ||
457 | * Closure for @e shutdown_task. | ||
458 | */ | ||
459 | void *shutdown_task_cls; | ||
460 | |||
461 | /** | ||
462 | * When should the testcase time out? | ||
463 | */ | ||
464 | struct GNUNET_TIME_Relative timeout; | ||
465 | |||
466 | /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */ | ||
467 | |||
468 | /** | ||
469 | * Number of peers involved in the test. | ||
470 | */ | ||
471 | unsigned int num_peers; | ||
472 | |||
473 | /** | ||
474 | * Configuration files we have, array with @e num_peers entries. | ||
475 | */ | ||
476 | char **cfg_files; | ||
477 | |||
478 | /** | ||
479 | * Array with @e num_peers entries. | ||
480 | */ | ||
481 | struct GNUNET_TRANSPORT_TESTING_PeerContext **p; | ||
482 | |||
483 | /** | ||
484 | * Name of the plugin. | ||
485 | */ | ||
486 | const char *test_plugin; | ||
487 | |||
488 | /** | ||
489 | * Name of the testcase. | ||
490 | */ | ||
491 | const char *test_name; | ||
492 | |||
493 | /** | ||
494 | * Configuration object for the testcase. | ||
495 | */ | ||
496 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
497 | |||
498 | /** | ||
499 | * Main testing handle. | ||
500 | */ | ||
501 | struct GNUNET_TRANSPORT_TESTING_Handle *tth; | ||
502 | |||
503 | /** | ||
504 | * Result from the main function, set to #GNUNET_OK on success. | ||
505 | * Clients should set to #GNUNET_SYSERR to indicate test failure. | ||
506 | */ | ||
507 | int global_ret; | ||
508 | |||
509 | /* ******* internal state, clients should not mess with this **** */ | ||
510 | |||
511 | /** | ||
512 | * Task run on timeout. | ||
513 | */ | ||
514 | struct GNUNET_SCHEDULER_Task *timeout_task; | ||
515 | |||
516 | /** | ||
517 | * Number of peers that have been started. | ||
518 | */ | ||
519 | unsigned int started; | ||
520 | |||
521 | /** | ||
522 | * DLL of active connect requests. | ||
523 | */ | ||
524 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_head; | ||
525 | |||
526 | /** | ||
527 | * DLL of active connect requests. | ||
528 | */ | ||
529 | struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl_tail; | ||
530 | |||
531 | /** | ||
532 | * Array with @e num_peers entries. | ||
533 | */ | ||
534 | struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ip; | ||
535 | |||
536 | }; | ||
537 | |||
538 | |||
539 | /** | ||
540 | * Find peer by peer ID. | ||
541 | * | ||
542 | * @param ccc context to search | ||
543 | * @param peer peer to look for | ||
544 | * @return NULL if @a peer was not found | ||
545 | */ | ||
546 | struct GNUNET_TRANSPORT_TESTING_PeerContext * | ||
547 | GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, | ||
548 | const struct GNUNET_PeerIdentity *peer); | ||
549 | |||
550 | |||
551 | /** | ||
552 | * Common implementation of the #GNUNET_TRANSPORT_TESTING_CheckCallback. | ||
553 | * Starts and connects the two peers, then invokes the | ||
554 | * `connect_continuation` from @a cls. Sets up a timeout to | ||
555 | * abort the test, and a shutdown handler to clean up properly | ||
556 | * on exit. | ||
557 | * | ||
558 | * @param cls closure of type `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` | ||
559 | * @param tth_ initialized testing handle | ||
560 | * @param test_plugin_ name of the plugin | ||
561 | * @param test_name_ name of the test | ||
562 | * @param num_peers number of entries in the @a cfg_file array | ||
563 | * @param cfg_files array of names of configuration files for the peers | ||
564 | * @return #GNUNET_SYSERR on error | ||
565 | */ | ||
566 | int | ||
567 | GNUNET_TRANSPORT_TESTING_connect_check (void *cls, | ||
568 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, | ||
569 | const char *test_plugin_, | ||
570 | const char *test_name_, | ||
571 | unsigned int num_peers, | ||
572 | char *cfg_files[]); | ||
573 | |||
574 | |||
575 | /** | ||
297 | * Main function of a testcase. Called with the initial setup data | 576 | * Main function of a testcase. Called with the initial setup data |
298 | * for the test as derived from the source name and the binary name. | 577 | * for the test as derived from the source name and the binary name. |
299 | * | 578 | * |
300 | * @param cls closure | 579 | * @param cls closure |
301 | * @param tth initialized testing handle | 580 | * @param tth_ initialized testing handle |
302 | * @param test_plugin name of the plugin (if available) | 581 | * @param test_plugin_ name of the plugin |
582 | * @param test_name_ name of the test | ||
303 | * @param num_peers number of entries in the @a cfg_file array | 583 | * @param num_peers number of entries in the @a cfg_file array |
304 | * @param cfg_files array of names of configuration files for the peers | 584 | * @param cfg_files array of names of configuration files for the peers |
585 | * @return #GNUNET_SYSERR on error | ||
305 | */ | 586 | */ |
306 | typedef void | 587 | typedef int |
307 | (*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, | 588 | (*GNUNET_TRANSPORT_TESTING_CheckCallback)(void *cls, |
308 | struct GNUNET_TRANSPORT_TESTING_Handle *tth, | 589 | struct GNUNET_TRANSPORT_TESTING_Handle *tth_, |
309 | const char *test_plugin, | 590 | const char *test_plugin_, |
591 | const char *test_name_, | ||
310 | unsigned int num_peers, | 592 | unsigned int num_peers, |
311 | const char *cfg_files[]); | 593 | char *cfg_files[]); |
312 | 594 | ||
313 | 595 | ||
314 | /** | 596 | /** |
@@ -341,6 +623,37 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, | |||
341 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) | 623 | GNUNET_TRANSPORT_TESTING_main_ (argv[0], __FILE__, num_peers, check, check_cls) |
342 | 624 | ||
343 | 625 | ||
626 | |||
627 | /* ********************** log-only convenience functions ************* */ | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Log a connect event. | ||
632 | * | ||
633 | * @param cls NULL | ||
634 | * @param me peer that had the event | ||
635 | * @param other peer that connected. | ||
636 | */ | ||
637 | void | ||
638 | GNUNET_TRANSPORT_TESTING_log_connect (void *cls, | ||
639 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
640 | const struct GNUNET_PeerIdentity *other); | ||
641 | |||
642 | |||
643 | /** | ||
644 | * Log a disconnect event. | ||
645 | * | ||
646 | * @param cls NULL | ||
647 | * @param me peer that had the event | ||
648 | * @param other peer that disconnected. | ||
649 | */ | ||
650 | void | ||
651 | GNUNET_TRANSPORT_TESTING_log_disconnect (void *cls, | ||
652 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
653 | const struct GNUNET_PeerIdentity *other); | ||
654 | |||
655 | |||
656 | |||
344 | /* ********************** low-level filename functions *************** */ | 657 | /* ********************** low-level filename functions *************** */ |
345 | 658 | ||
346 | 659 | ||