diff options
author | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 19:35:11 +0200 |
---|---|---|
committer | Martin Schanzenbach <schanzen@gnunet.org> | 2023-10-18 19:35:11 +0200 |
commit | ddfee3f564bff9c5d5719af3132d7869b8783ec4 (patch) | |
tree | e6fd7801fe6808797f3418bf081ab68d5a5ec27b /src/transport/test_communicator_basic.c | |
parent | 852718c2473e41bc01ada0d53ad93c7da78e6ec8 (diff) | |
download | gnunet-ddfee3f564bff9c5d5719af3132d7869b8783ec4.tar.gz gnunet-ddfee3f564bff9c5d5719af3132d7869b8783ec4.zip |
BUILD: more more components into new structure; ftbfs fix
Diffstat (limited to 'src/transport/test_communicator_basic.c')
-rw-r--r-- | src/transport/test_communicator_basic.c | 1224 |
1 files changed, 0 insertions, 1224 deletions
diff --git a/src/transport/test_communicator_basic.c b/src/transport/test_communicator_basic.c deleted file mode 100644 index fdbad0957..000000000 --- a/src/transport/test_communicator_basic.c +++ /dev/null | |||
@@ -1,1224 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2019 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 | /** | ||
22 | * @file transport/test_communicator_basic.c | ||
23 | * @brief test the communicators | ||
24 | * @author Julius Bünger | ||
25 | * @author Martin Schanzenbach | ||
26 | */ | ||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "transport-testing-communicator.h" | ||
30 | #include "gnunet_ats_transport_service.h" | ||
31 | #include "gnunet_signatures.h" | ||
32 | #include "gnunet_testing_lib.h" | ||
33 | #include "transport.h" | ||
34 | #include "gnunet_statistics_service.h" | ||
35 | |||
36 | #include <inttypes.h> | ||
37 | |||
38 | |||
39 | #define LOG(kind, ...) GNUNET_log_from (kind, \ | ||
40 | "test_transport_communicator", \ | ||
41 | __VA_ARGS__) | ||
42 | |||
43 | #define NUM_PEERS 2 | ||
44 | |||
45 | static struct GNUNET_SCHEDULER_Task *to_task[NUM_PEERS]; | ||
46 | |||
47 | static int queue_est = GNUNET_NO; | ||
48 | |||
49 | static struct GNUNET_PeerIdentity peer_id[NUM_PEERS]; | ||
50 | |||
51 | static char *communicator_binary; | ||
52 | |||
53 | static struct | ||
54 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS]; | ||
55 | |||
56 | static struct GNUNET_CONFIGURATION_Handle *cfg_peers[NUM_PEERS]; | ||
57 | |||
58 | static struct GNUNET_STATISTICS_Handle *stats[NUM_PEERS]; | ||
59 | |||
60 | static char *cfg_peers_name[NUM_PEERS]; | ||
61 | |||
62 | static int finished[NUM_PEERS]; | ||
63 | |||
64 | static int ret; | ||
65 | |||
66 | static int bidirect = GNUNET_NO; | ||
67 | |||
68 | static size_t long_message_size; | ||
69 | |||
70 | static struct GNUNET_TIME_Absolute start_short[NUM_PEERS]; | ||
71 | |||
72 | static struct GNUNET_TIME_Absolute start_long[NUM_PEERS]; | ||
73 | |||
74 | static struct GNUNET_TIME_Absolute timeout[NUM_PEERS]; | ||
75 | |||
76 | // static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *my_tc; | ||
77 | |||
78 | static char *communicator_name; | ||
79 | |||
80 | static char *test_name; | ||
81 | |||
82 | static struct GNUNET_STATISTICS_GetHandle *box_stats[NUM_PEERS]; | ||
83 | |||
84 | static struct GNUNET_STATISTICS_GetHandle *rekey_stats[NUM_PEERS]; | ||
85 | |||
86 | #define TEST_SECTION "test-setup" | ||
87 | |||
88 | #define SHORT_MESSAGE_SIZE 128 | ||
89 | |||
90 | #define LONG_MESSAGE_SIZE 32000 /* FIXME */ | ||
91 | |||
92 | #define ALLOWED_PACKET_LOSS 91 | ||
93 | |||
94 | #define BURST_PACKETS 5000 | ||
95 | |||
96 | #define TOTAL_ITERATIONS 1 | ||
97 | |||
98 | #define PEER_A 0 | ||
99 | |||
100 | #define PEER_B 1 | ||
101 | |||
102 | static unsigned int iterations_left[NUM_PEERS]; | ||
103 | |||
104 | #define TIMEOUT_MULTIPLIER 1 | ||
105 | |||
106 | #define DELAY \ | ||
107 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS,200) | ||
108 | |||
109 | #define SHORT_BURST_WINDOW \ | ||
110 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) | ||
111 | |||
112 | #define LONG_BURST_WINDOW \ | ||
113 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,2) | ||
114 | |||
115 | enum TestPhase | ||
116 | { | ||
117 | TP_INIT, | ||
118 | TP_BURST_SHORT, | ||
119 | TP_BURST_LONG, | ||
120 | TP_SIZE_CHECK | ||
121 | }; | ||
122 | |||
123 | static unsigned int phase_short[NUM_PEERS]; | ||
124 | |||
125 | static unsigned int phase_long[NUM_PEERS]; | ||
126 | |||
127 | static unsigned int phase_size[NUM_PEERS]; | ||
128 | |||
129 | static long long unsigned int allowed_packet_loss_short; | ||
130 | |||
131 | static long long unsigned int allowed_packet_loss_long; | ||
132 | |||
133 | static long long unsigned int burst_packets_short; | ||
134 | |||
135 | static long long unsigned int burst_packets_long; | ||
136 | |||
137 | static long long unsigned int delay_long_value; | ||
138 | |||
139 | static long long unsigned int delay_short_value; | ||
140 | |||
141 | static struct GNUNET_TIME_Relative delay_short; | ||
142 | |||
143 | static struct GNUNET_TIME_Relative delay_long; | ||
144 | |||
145 | static size_t num_sent_short[NUM_PEERS]; | ||
146 | |||
147 | static size_t num_sent_long[NUM_PEERS]; | ||
148 | |||
149 | static size_t num_sent_size[NUM_PEERS]; | ||
150 | |||
151 | static uint32_t ack[NUM_PEERS]; | ||
152 | |||
153 | static enum TestPhase phase[NUM_PEERS]; | ||
154 | |||
155 | static size_t num_received_short[NUM_PEERS]; | ||
156 | |||
157 | static size_t num_received_long[NUM_PEERS]; | ||
158 | |||
159 | static size_t num_received_size[NUM_PEERS]; | ||
160 | |||
161 | static uint64_t avg_latency[NUM_PEERS]; | ||
162 | |||
163 | static void | ||
164 | communicator_available_cb ( | ||
165 | void *cls, | ||
166 | struct | ||
167 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
168 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | ||
169 | char *address_prefix) | ||
170 | { | ||
171 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
172 | "Communicator available. (cc: %u, prefix: %s)\n", | ||
173 | cc, | ||
174 | address_prefix); | ||
175 | } | ||
176 | |||
177 | |||
178 | static void | ||
179 | open_queue (void *cls) | ||
180 | { | ||
181 | const char *address = cls; | ||
182 | |||
183 | if (NULL != tc_hs[PEER_A]->c_mq) | ||
184 | { | ||
185 | queue_est = GNUNET_YES; | ||
186 | GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[PEER_A], | ||
187 | &peer_id[PEER_B], | ||
188 | address); | ||
189 | } | ||
190 | else | ||
191 | { | ||
192 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
193 | &open_queue, | ||
194 | (void *) address); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | |||
199 | static void | ||
200 | add_address_cb ( | ||
201 | void *cls, | ||
202 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
203 | const char *address, | ||
204 | struct GNUNET_TIME_Relative expiration, | ||
205 | uint32_t aid, | ||
206 | enum GNUNET_NetworkType nt) | ||
207 | { | ||
208 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
209 | "New address. (addr: %s, expir: %s, ID: %" PRIu32 ", nt: %u\n", | ||
210 | address, | ||
211 | GNUNET_STRINGS_relative_time_to_string (expiration, | ||
212 | GNUNET_NO), | ||
213 | aid, | ||
214 | (int) nt); | ||
215 | // addresses[1] = GNUNET_strdup (address); | ||
216 | if ((0 == strcmp ((char*) cls, cfg_peers_name[PEER_B])) && | ||
217 | (GNUNET_NO == queue_est)) | ||
218 | { | ||
219 | open_queue ((void *) address); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | |||
224 | /** | ||
225 | * @brief Callback that informs whether the requested queue will be | ||
226 | * established | ||
227 | * | ||
228 | * Implements #GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback. | ||
229 | * | ||
230 | * @param cls Closure - unused | ||
231 | * @param tc_h Communicator handle - unused | ||
232 | * @param will_try #GNUNET_YES if queue will be established | ||
233 | * #GNUNET_NO if queue will not be established (bogous address) | ||
234 | */ | ||
235 | static void | ||
236 | queue_create_reply_cb ( | ||
237 | void *cls, | ||
238 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
239 | int will_try) | ||
240 | { | ||
241 | (void) cls; | ||
242 | (void) tc_h; | ||
243 | if (GNUNET_YES == will_try) | ||
244 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "Queue will be established!\n"); | ||
246 | else | ||
247 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
248 | "Queue won't be established (bougus address?)!\n"); | ||
249 | } | ||
250 | |||
251 | |||
252 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | ||
253 | handle_backchannel_cb (void *cls, | ||
254 | struct GNUNET_MessageHeader *msg, | ||
255 | struct GNUNET_PeerIdentity *pid) | ||
256 | { | ||
257 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
258 | |||
259 | (void) tc_h; | ||
260 | (void) msg; | ||
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Handling BC message...\n"); | ||
262 | if (0 == memcmp (&peer_id[PEER_A], pid, sizeof (*pid))) | ||
263 | return tc_hs[PEER_A]; | ||
264 | else | ||
265 | return tc_hs[PEER_B]; | ||
266 | } | ||
267 | |||
268 | |||
269 | static char* | ||
270 | make_payload (size_t payload_size) | ||
271 | { | ||
272 | struct GNUNET_TIME_Absolute ts; | ||
273 | struct GNUNET_TIME_AbsoluteNBO ts_n; | ||
274 | char *payload = GNUNET_malloc (payload_size); | ||
275 | |||
276 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
277 | "Making payload of size %lu\n", payload_size); | ||
278 | GNUNET_assert (payload_size >= 8); // So that out timestamp fits | ||
279 | ts = GNUNET_TIME_absolute_get (); | ||
280 | ts_n = GNUNET_TIME_absolute_hton (ts); | ||
281 | memset (payload, 'a', payload_size); | ||
282 | memcpy (payload, &ts_n, sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
283 | return payload; | ||
284 | } | ||
285 | |||
286 | |||
287 | static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * | ||
288 | get_tc_h (unsigned int peer_nr) | ||
289 | { | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "Got peer %u\n", | ||
292 | peer_nr); | ||
293 | |||
294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
295 | "Handle %p peer 0\n", | ||
296 | tc_hs[0]); | ||
297 | |||
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "Handle %p peer 1\n", | ||
300 | tc_hs[1]); | ||
301 | |||
302 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "Handle %p get\n", | ||
304 | tc_hs[peer_nr]); | ||
305 | |||
306 | return tc_hs[peer_nr]; | ||
307 | } | ||
308 | |||
309 | |||
310 | static unsigned int | ||
311 | get_peer_nr_from_tc (struct | ||
312 | GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | ||
313 | { | ||
314 | if (tc_h == get_tc_h (0)) | ||
315 | return PEER_A; | ||
316 | else | ||
317 | return PEER_B; | ||
318 | } | ||
319 | |||
320 | |||
321 | static unsigned int | ||
322 | get_peer_nr (void *cls, unsigned int get_the_other_one) | ||
323 | { | ||
324 | if (0 == strcmp ((char*) cls, cfg_peers_name[0])) | ||
325 | return get_the_other_one ? PEER_B : PEER_A; | ||
326 | else | ||
327 | return get_the_other_one ? PEER_A : PEER_B; | ||
328 | } | ||
329 | |||
330 | |||
331 | static void | ||
332 | process_statistics_box_done (void *cls, int success) | ||
333 | { | ||
334 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
335 | unsigned int peer_nr; | ||
336 | |||
337 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
338 | |||
339 | if (NULL != box_stats[peer_nr]) | ||
340 | box_stats[peer_nr] = NULL; | ||
341 | if (NULL == rekey_stats[peer_nr]) | ||
342 | { | ||
343 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
344 | "Finished\n"); | ||
345 | GNUNET_SCHEDULER_shutdown (); | ||
346 | } | ||
347 | } | ||
348 | |||
349 | |||
350 | static void | ||
351 | process_statistics_rekey_done (void *cls, int success) | ||
352 | { | ||
353 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
354 | unsigned int peer_nr; | ||
355 | |||
356 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
357 | |||
358 | if (NULL != rekey_stats[peer_nr]) | ||
359 | rekey_stats[peer_nr] = NULL; | ||
360 | if (NULL == box_stats[peer_nr]) | ||
361 | { | ||
362 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
363 | "Finished\n"); | ||
364 | GNUNET_SCHEDULER_shutdown (); | ||
365 | } | ||
366 | } | ||
367 | |||
368 | |||
369 | static int | ||
370 | process_statistics (void *cls, | ||
371 | const char *subsystem, | ||
372 | const char *name, | ||
373 | uint64_t value, | ||
374 | int is_persistent) | ||
375 | { | ||
376 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
377 | "Statistic: Name %s and value %lu\n", | ||
378 | name, | ||
379 | value); | ||
380 | if ((0 == strcmp ("rekey", test_name)) && (0 == strcmp ( | ||
381 | "# rekeying successful", | ||
382 | name)) && (0 == value)) | ||
383 | { | ||
384 | ret = 2; | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
386 | "No successful rekeying!\n"); | ||
387 | GNUNET_SCHEDULER_shutdown (); | ||
388 | } | ||
389 | if ((0 == strcmp ("backchannel", test_name)) && | ||
390 | (0 == strcmp ( | ||
391 | "# messages decrypted with BOX", | ||
392 | name)) | ||
393 | && (9000 > value)) | ||
394 | { | ||
395 | ret = 2; | ||
396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
397 | "Not enough BOX messages! (want: %u, have %llu)\n", | ||
398 | 9000, value); | ||
399 | GNUNET_SCHEDULER_shutdown (); | ||
400 | } | ||
401 | if ((0 == strcmp ("rekey", test_name)) && | ||
402 | (0 == strcmp ( | ||
403 | "# messages decrypted with BOX", | ||
404 | name)) | ||
405 | && (6000 > value)) | ||
406 | { | ||
407 | ret = 2; | ||
408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
409 | "Not enough BOX messages! (want: %u, have %llu)\n", | ||
410 | 6000, value); | ||
411 | GNUNET_SCHEDULER_shutdown (); | ||
412 | } | ||
413 | return GNUNET_OK; | ||
414 | } | ||
415 | |||
416 | |||
417 | static void | ||
418 | short_test (void *cls); | ||
419 | |||
420 | static void | ||
421 | short_test_cb (void *cls) | ||
422 | { | ||
423 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
424 | unsigned int peer_nr; | ||
425 | char *payload; | ||
426 | |||
427 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
428 | |||
429 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
430 | "short_test_cb %u/%u for peer %u and handle %p\n", | ||
431 | (unsigned int) num_sent_short[peer_nr], | ||
432 | (unsigned int) num_received_short[peer_nr], | ||
433 | peer_nr, | ||
434 | tc_h); | ||
435 | payload = make_payload (SHORT_MESSAGE_SIZE); | ||
436 | num_sent_short[peer_nr]++; | ||
437 | if (burst_packets_short == num_sent_short[peer_nr]) | ||
438 | tc_h->cont = NULL; | ||
439 | else | ||
440 | tc_h->cont = short_test; | ||
441 | tc_h->cont_cls = cls; | ||
442 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, | ||
443 | NULL, | ||
444 | cls, | ||
445 | payload, | ||
446 | SHORT_MESSAGE_SIZE); | ||
447 | GNUNET_free (payload); | ||
448 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( | ||
449 | GNUNET_TIME_relative_multiply ( | ||
450 | GNUNET_TIME_UNIT_SECONDS, | ||
451 | TIMEOUT_MULTIPLIER)); | ||
452 | } | ||
453 | |||
454 | |||
455 | static void | ||
456 | short_test (void *cls) | ||
457 | { | ||
458 | GNUNET_SCHEDULER_add_delayed (delay_short, | ||
459 | &short_test_cb, | ||
460 | cls); | ||
461 | } | ||
462 | |||
463 | |||
464 | static void | ||
465 | size_test (void *cls) | ||
466 | { | ||
467 | unsigned int peer_nr; | ||
468 | char *payload; | ||
469 | size_t max_size = 64000; | ||
470 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
471 | |||
472 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
473 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
474 | "size_test_cb %u\n", | ||
475 | (unsigned int) num_sent_size[peer_nr]); | ||
476 | GNUNET_assert (TP_SIZE_CHECK == phase[peer_nr]); | ||
477 | if (LONG_MESSAGE_SIZE != long_message_size) | ||
478 | max_size = long_message_size; | ||
479 | if (ack[peer_nr] + 10 > max_size) | ||
480 | return; /* Leave some room for our protocol, so not 2^16 exactly */ | ||
481 | ack[peer_nr] += 10; | ||
482 | payload = make_payload (ack[peer_nr]); | ||
483 | num_sent_size[peer_nr]++; | ||
484 | if (ack[peer_nr] >= max_size) | ||
485 | tc_h->cont = NULL; | ||
486 | else | ||
487 | tc_h->cont = size_test; | ||
488 | tc_h->cont_cls = cls; | ||
489 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, | ||
490 | NULL, | ||
491 | cls, | ||
492 | payload, | ||
493 | ack[peer_nr]); | ||
494 | GNUNET_free (payload); | ||
495 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( | ||
496 | GNUNET_TIME_relative_multiply ( | ||
497 | GNUNET_TIME_UNIT_SECONDS, | ||
498 | TIMEOUT_MULTIPLIER)); | ||
499 | } | ||
500 | |||
501 | |||
502 | static void | ||
503 | long_test (void *cls); | ||
504 | |||
505 | static void | ||
506 | long_test_cb (void *cls) | ||
507 | { | ||
508 | unsigned int peer_nr; | ||
509 | char *payload; | ||
510 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
511 | |||
512 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
513 | |||
514 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
515 | "long_test_cb %u/%u\n", | ||
516 | (unsigned int) num_sent_long[peer_nr], | ||
517 | (unsigned int) num_received_long[peer_nr]); | ||
518 | payload = make_payload (long_message_size); | ||
519 | num_sent_long[peer_nr]++; | ||
520 | if (burst_packets_long == num_sent_long[peer_nr]) | ||
521 | tc_h->cont = NULL; | ||
522 | else | ||
523 | tc_h->cont = long_test; | ||
524 | tc_h->cont_cls = cls; | ||
525 | GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_h, | ||
526 | NULL, | ||
527 | cls, | ||
528 | payload, | ||
529 | long_message_size); | ||
530 | GNUNET_free (payload); | ||
531 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( | ||
532 | GNUNET_TIME_relative_multiply ( | ||
533 | GNUNET_TIME_UNIT_SECONDS, | ||
534 | TIMEOUT_MULTIPLIER)); | ||
535 | } | ||
536 | |||
537 | |||
538 | static void | ||
539 | long_test (void *cls) | ||
540 | { | ||
541 | GNUNET_SCHEDULER_add_delayed (delay_long, | ||
542 | &long_test_cb, | ||
543 | cls); | ||
544 | } | ||
545 | |||
546 | |||
547 | static void | ||
548 | choose_phase (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) | ||
549 | { | ||
550 | unsigned int peer_nr; | ||
551 | |||
552 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
553 | |||
554 | if (GNUNET_YES == phase_short[peer_nr]) | ||
555 | { | ||
556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
557 | "Choose phase short with peer %u and Handle %p\n", | ||
558 | peer_nr, | ||
559 | tc_h); | ||
560 | phase[peer_nr] = TP_BURST_SHORT; | ||
561 | start_short[peer_nr] = GNUNET_TIME_absolute_get (); | ||
562 | short_test (tc_h); | ||
563 | } | ||
564 | else if (GNUNET_YES == phase_long[peer_nr]) | ||
565 | { | ||
566 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
567 | "Choose phase long with peer %u\n", | ||
568 | peer_nr); | ||
569 | phase[peer_nr] = TP_BURST_LONG; | ||
570 | start_long[peer_nr] = GNUNET_TIME_absolute_get (); | ||
571 | long_test (tc_h); | ||
572 | } | ||
573 | else if (GNUNET_YES == phase_size[peer_nr]) | ||
574 | { | ||
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
576 | "Choose phase size\n"); | ||
577 | phase[peer_nr] = TP_SIZE_CHECK; | ||
578 | size_test (tc_h); | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", | ||
583 | test_name)) | ||
584 | || (0 == strcmp ( | ||
585 | "backchannel", | ||
586 | test_name))) ) | ||
587 | { | ||
588 | if (NULL != box_stats[peer_nr]) | ||
589 | GNUNET_STATISTICS_get_cancel (box_stats[peer_nr]); | ||
590 | box_stats[peer_nr] = GNUNET_STATISTICS_get (stats[1], | ||
591 | "C-UDP", | ||
592 | "# messages decrypted with BOX", | ||
593 | process_statistics_box_done, | ||
594 | &process_statistics, | ||
595 | tc_h); | ||
596 | if (NULL != rekey_stats[peer_nr]) | ||
597 | GNUNET_STATISTICS_get_cancel (rekey_stats[peer_nr]); | ||
598 | rekey_stats[peer_nr] = GNUNET_STATISTICS_get (stats[0], | ||
599 | "C-UDP", | ||
600 | "# rekeying successful", | ||
601 | process_statistics_rekey_done, | ||
602 | &process_statistics, | ||
603 | tc_h); | ||
604 | } | ||
605 | else | ||
606 | { | ||
607 | if ((GNUNET_NO == bidirect) || (((PEER_A == peer_nr) && | ||
608 | finished[PEER_B]) || ((PEER_B == | ||
609 | peer_nr) && | ||
610 | finished | ||
611 | [PEER_A]))) | ||
612 | { | ||
613 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
614 | "Finished\n"); | ||
615 | GNUNET_SCHEDULER_shutdown (); | ||
616 | } | ||
617 | finished[peer_nr] = GNUNET_YES; | ||
618 | } | ||
619 | } | ||
620 | } | ||
621 | |||
622 | |||
623 | static void | ||
624 | finish_phase_long (unsigned int peer_nr) | ||
625 | { | ||
626 | static struct GNUNET_TIME_Relative duration; | ||
627 | |||
628 | duration = GNUNET_TIME_absolute_get_duration (start_long[peer_nr]); | ||
629 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
630 | "Long size packet test for peer %u done.\n", | ||
631 | peer_nr); | ||
632 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( | ||
633 | (long_message_size * num_received_long[peer_nr] * 1000 * 1000) | ||
634 | / duration. | ||
635 | rel_value_us); | ||
636 | |||
637 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
638 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | ||
639 | (unsigned long) num_received_long[peer_nr], | ||
640 | (unsigned long) num_sent_long[peer_nr], | ||
641 | (unsigned long long) duration.rel_value_us, | ||
642 | goodput, | ||
643 | (unsigned long long) avg_latency[peer_nr]); | ||
644 | GNUNET_free (goodput); | ||
645 | ack[peer_nr] = 0; | ||
646 | // phase = TP_SIZE_CHECK; | ||
647 | // num_received = 0; | ||
648 | // num_sent_long = 0; | ||
649 | avg_latency[peer_nr] = 0; | ||
650 | // size_test (NULL); | ||
651 | phase_long[peer_nr] = GNUNET_NO; | ||
652 | choose_phase (get_tc_h (peer_nr)); | ||
653 | } | ||
654 | |||
655 | |||
656 | static void | ||
657 | finish_phase_short (unsigned int peer_nr) | ||
658 | { | ||
659 | static struct GNUNET_TIME_Relative duration; | ||
660 | |||
661 | duration = GNUNET_TIME_absolute_get_duration (start_short[peer_nr]); | ||
662 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
663 | "Short size packet test for peer %u done.\n", | ||
664 | peer_nr); | ||
665 | char *goodput = GNUNET_STRINGS_byte_size_fancy ( | ||
666 | (SHORT_MESSAGE_SIZE * num_received_short[peer_nr] * 1000 * 1000) | ||
667 | / duration.rel_value_us); | ||
668 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
669 | "%lu/%lu packets in %llu us (%s/s) -- avg latency: %llu us\n", | ||
670 | (unsigned long) num_received_short[peer_nr], | ||
671 | (unsigned long) num_sent_short[peer_nr], | ||
672 | (unsigned long long) duration.rel_value_us, | ||
673 | goodput, | ||
674 | (unsigned long long) avg_latency[peer_nr]); | ||
675 | GNUNET_free (goodput); | ||
676 | // start_long = GNUNET_TIME_absolute_get (); | ||
677 | // phase = TP_BURST_LONG; | ||
678 | // num_sent_short = 0; | ||
679 | avg_latency[peer_nr] = 0; | ||
680 | // num_received = 0; | ||
681 | phase_short[peer_nr] = GNUNET_NO; | ||
682 | choose_phase (get_tc_h (peer_nr)); | ||
683 | // long_test (NULL); | ||
684 | } | ||
685 | |||
686 | |||
687 | static void | ||
688 | latency_timeout (void *cls) | ||
689 | { | ||
690 | |||
691 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; | ||
692 | unsigned int peer_nr; | ||
693 | size_t num_sent = 0; | ||
694 | size_t num_received = 0; | ||
695 | |||
696 | peer_nr = get_peer_nr_from_tc (tc_h); | ||
697 | to_task[peer_nr] = NULL; | ||
698 | |||
699 | switch (phase[peer_nr]) | ||
700 | { | ||
701 | case TP_INIT: | ||
702 | GNUNET_assert (0); | ||
703 | break; | ||
704 | case TP_BURST_SHORT: | ||
705 | num_sent = num_sent_short[peer_nr]; | ||
706 | num_received = num_received_short[peer_nr]; | ||
707 | if ((num_sent_short[peer_nr] == burst_packets_short) && | ||
708 | (num_received_short[peer_nr] > | ||
709 | burst_packets_short | ||
710 | / 100 | ||
711 | * | ||
712 | allowed_packet_loss_short) ) | ||
713 | { | ||
714 | finish_phase_short (peer_nr); | ||
715 | to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr], | ||
716 | &latency_timeout, | ||
717 | cls); | ||
718 | return; | ||
719 | } | ||
720 | break; | ||
721 | case TP_BURST_LONG: | ||
722 | num_sent = num_sent_long[peer_nr]; | ||
723 | num_received = num_received_long[peer_nr]; | ||
724 | if ((num_sent_long[peer_nr] == burst_packets_long) && | ||
725 | (num_received_long[peer_nr] > | ||
726 | burst_packets_long | ||
727 | / 100 | ||
728 | * | ||
729 | allowed_packet_loss_long) ) | ||
730 | { | ||
731 | finish_phase_long (peer_nr); | ||
732 | to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr], | ||
733 | &latency_timeout, | ||
734 | cls); | ||
735 | return; | ||
736 | } | ||
737 | break; | ||
738 | case TP_SIZE_CHECK: | ||
739 | num_sent = num_sent_size[peer_nr]; | ||
740 | num_received = num_received_size[peer_nr]; | ||
741 | break; | ||
742 | } | ||
743 | if (GNUNET_TIME_absolute_get_remaining (timeout[peer_nr]).rel_value_us > 0) | ||
744 | { | ||
745 | to_task[peer_nr] = GNUNET_SCHEDULER_add_at (timeout[peer_nr], | ||
746 | &latency_timeout, | ||
747 | cls); | ||
748 | return; | ||
749 | } | ||
750 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
751 | "Latency too high. Test failed. (Phase: %d. Sent: %lu, Received: %lu)\n", | ||
752 | phase[peer_nr], num_sent, num_received); | ||
753 | ret = 2; | ||
754 | GNUNET_SCHEDULER_shutdown (); | ||
755 | } | ||
756 | |||
757 | |||
758 | /** | ||
759 | * @brief Handle opening of queue | ||
760 | * | ||
761 | * Issues sending of test data | ||
762 | * | ||
763 | * Implements #GNUNET_TRANSPORT_TESTING_AddQueueCallback | ||
764 | * | ||
765 | * @param cls Closure | ||
766 | * @param tc_h Communicator handle | ||
767 | * @param tc_queue Handle to newly opened queue | ||
768 | */ | ||
769 | static void | ||
770 | add_queue_cb (void *cls, | ||
771 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
772 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue * | ||
773 | tc_queue, | ||
774 | size_t mtu) | ||
775 | { | ||
776 | |||
777 | unsigned int peer_nr; | ||
778 | |||
779 | peer_nr = get_peer_nr (cls, GNUNET_NO); | ||
780 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
781 | "Handle %p add %u %u\n", | ||
782 | tc_h, | ||
783 | peer_nr, | ||
784 | get_peer_nr_from_tc (tc_h)); | ||
785 | if ((GNUNET_NO == bidirect) && (0 != strcmp ((char*) cls, cfg_peers_name[0]))) | ||
786 | { | ||
787 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
788 | "Queue available at receiving peer\n"); | ||
789 | return; // TODO? | ||
790 | } | ||
791 | else if (TP_INIT != phase[peer_nr]) | ||
792 | return; | ||
793 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
794 | "Queue established, starting test...\n"); | ||
795 | if (UINT16_MAX != mtu) /* Message header overhead */ | ||
796 | long_message_size = mtu - sizeof(struct GNUNET_TRANSPORT_SendMessageTo) | ||
797 | - sizeof(struct GNUNET_MessageHeader); | ||
798 | else | ||
799 | long_message_size = LONG_MESSAGE_SIZE; | ||
800 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( | ||
801 | GNUNET_TIME_relative_multiply ( | ||
802 | GNUNET_TIME_UNIT_SECONDS, | ||
803 | TIMEOUT_MULTIPLIER)); | ||
804 | GNUNET_assert (NULL == to_task[peer_nr]); | ||
805 | to_task[peer_nr] = GNUNET_SCHEDULER_add_delayed ( | ||
806 | GNUNET_TIME_relative_multiply ( | ||
807 | GNUNET_TIME_UNIT_SECONDS, | ||
808 | TIMEOUT_MULTIPLIER), | ||
809 | &latency_timeout, | ||
810 | tc_h); | ||
811 | choose_phase (tc_h); | ||
812 | } | ||
813 | |||
814 | |||
815 | static void | ||
816 | update_avg_latency (const char *payload, unsigned int peer_nr) | ||
817 | { | ||
818 | struct GNUNET_TIME_AbsoluteNBO *ts_n; | ||
819 | struct GNUNET_TIME_Absolute ts; | ||
820 | struct GNUNET_TIME_Relative latency; | ||
821 | size_t num_received = 0; | ||
822 | |||
823 | ts_n = (struct GNUNET_TIME_AbsoluteNBO *) payload; | ||
824 | ts = GNUNET_TIME_absolute_ntoh (*ts_n); | ||
825 | latency = GNUNET_TIME_absolute_get_duration (ts); | ||
826 | |||
827 | switch (phase[peer_nr]) | ||
828 | { | ||
829 | case TP_INIT: | ||
830 | GNUNET_assert (0); | ||
831 | break; | ||
832 | case TP_BURST_SHORT: | ||
833 | num_received = num_received_short[peer_nr]; | ||
834 | break; | ||
835 | case TP_BURST_LONG: | ||
836 | num_received = num_received_long[peer_nr]; | ||
837 | break; | ||
838 | case TP_SIZE_CHECK: | ||
839 | num_received = num_received_size[peer_nr]; | ||
840 | break; | ||
841 | } | ||
842 | if (1 >= num_received) | ||
843 | avg_latency[peer_nr] = latency.rel_value_us; | ||
844 | else | ||
845 | avg_latency[peer_nr] = ((avg_latency[peer_nr] * (num_received - 1)) | ||
846 | + latency.rel_value_us) | ||
847 | / num_received; | ||
848 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
849 | "Latency of received packet by peer %u: %s with avg latency %lu\n", | ||
850 | peer_nr, | ||
851 | GNUNET_STRINGS_relative_time_to_string (latency, | ||
852 | GNUNET_YES), | ||
853 | avg_latency[peer_nr]); | ||
854 | } | ||
855 | |||
856 | |||
857 | static void | ||
858 | load_phase_config () | ||
859 | { | ||
860 | |||
861 | phase_short[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | ||
862 | TEST_SECTION, | ||
863 | "PHASE_SHORT"); | ||
864 | if (GNUNET_SYSERR == phase_short[0]) | ||
865 | phase_short[0] = GNUNET_YES; | ||
866 | |||
867 | phase_short[1] = phase_short[0]; | ||
868 | |||
869 | phase_long[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | ||
870 | TEST_SECTION, | ||
871 | "PHASE_LONG"); | ||
872 | |||
873 | if (GNUNET_SYSERR == phase_long[0]) | ||
874 | phase_long[0] = GNUNET_YES; | ||
875 | |||
876 | phase_long[1] = phase_long[0]; | ||
877 | |||
878 | phase_size[0] = GNUNET_CONFIGURATION_get_value_yesno (cfg_peers[0], | ||
879 | TEST_SECTION, | ||
880 | "PHASE_SIZE"); | ||
881 | |||
882 | if (GNUNET_SYSERR == phase_size[0]) | ||
883 | phase_size[0] = GNUNET_YES; | ||
884 | |||
885 | phase_size[1] = phase_size[0]; | ||
886 | } | ||
887 | |||
888 | |||
889 | /** | ||
890 | * @brief Handle an incoming message | ||
891 | * | ||
892 | * Implements #GNUNET_TRANSPORT_TESTING_IncomingMessageCallback | ||
893 | |||
894 | * @param cls Closure | ||
895 | * @param tc_h Handle to the receiving communicator | ||
896 | * @param msg Received message | ||
897 | */ | ||
898 | static void | ||
899 | incoming_message_cb ( | ||
900 | void *cls, | ||
901 | struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, | ||
902 | const char *payload, | ||
903 | size_t payload_len) | ||
904 | { | ||
905 | unsigned int peer_nr; | ||
906 | |||
907 | |||
908 | peer_nr = get_peer_nr (cls, GNUNET_YES); | ||
909 | |||
910 | if ((GNUNET_NO == bidirect) && (0 != strcmp ((char*) cls, | ||
911 | cfg_peers_name[NUM_PEERS - 1]))) | ||
912 | { | ||
913 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
914 | "unexpected receiver...\n"); | ||
915 | return; | ||
916 | } | ||
917 | /* Reset timeout */ | ||
918 | timeout[peer_nr] = GNUNET_TIME_relative_to_absolute ( | ||
919 | GNUNET_TIME_relative_multiply ( | ||
920 | GNUNET_TIME_UNIT_SECONDS, | ||
921 | TIMEOUT_MULTIPLIER)); | ||
922 | switch (phase[peer_nr]) | ||
923 | { | ||
924 | case TP_INIT: | ||
925 | GNUNET_break (0); | ||
926 | break; | ||
927 | case TP_BURST_SHORT: | ||
928 | { | ||
929 | GNUNET_assert (SHORT_MESSAGE_SIZE == payload_len); | ||
930 | num_received_short[peer_nr]++; | ||
931 | |||
932 | update_avg_latency (payload, peer_nr); | ||
933 | if ((num_sent_short[peer_nr] == burst_packets_short) && | ||
934 | (num_received_short[peer_nr] == | ||
935 | burst_packets_short)) | ||
936 | { | ||
937 | finish_phase_short (peer_nr); | ||
938 | } | ||
939 | break; | ||
940 | } | ||
941 | case TP_BURST_LONG: | ||
942 | { | ||
943 | if (long_message_size != payload_len) | ||
944 | { | ||
945 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
946 | "Ignoring packet with wrong length (have: %lu, want: %lu)\n", | ||
947 | payload_len, long_message_size); | ||
948 | return; // Ignore | ||
949 | } | ||
950 | num_received_long[peer_nr]++; | ||
951 | |||
952 | update_avg_latency (payload, peer_nr); | ||
953 | if ((num_sent_long[peer_nr] == burst_packets_long) && | ||
954 | (num_received_long[peer_nr] > | ||
955 | burst_packets_long)) | ||
956 | { | ||
957 | finish_phase_long (peer_nr); | ||
958 | } | ||
959 | break; | ||
960 | } | ||
961 | case TP_SIZE_CHECK: | ||
962 | { | ||
963 | size_t max_size = 64000; | ||
964 | |||
965 | GNUNET_assert (TP_SIZE_CHECK == phase[peer_nr]); | ||
966 | if (LONG_MESSAGE_SIZE != long_message_size) | ||
967 | max_size = long_message_size; | ||
968 | num_received_size[peer_nr]++; | ||
969 | update_avg_latency (payload, peer_nr); | ||
970 | if ((GNUNET_YES == phase_size[peer_nr]) && (num_received_size[peer_nr] >= | ||
971 | (max_size) / 10) ) | ||
972 | { | ||
973 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
974 | "Size packet test for peer %u done.\n", | ||
975 | peer_nr); | ||
976 | LOG (GNUNET_ERROR_TYPE_MESSAGE, | ||
977 | "%lu/%lu packets -- avg latency: %llu us\n", | ||
978 | (unsigned long) num_received_size[peer_nr], | ||
979 | (unsigned long) num_sent_size[peer_nr], | ||
980 | (unsigned long long) avg_latency[peer_nr]); | ||
981 | iterations_left[peer_nr]--; | ||
982 | phase_size[peer_nr] = GNUNET_NO; | ||
983 | if (0 != iterations_left[peer_nr]) | ||
984 | { | ||
985 | // start_short = GNUNET_TIME_absolute_get (); | ||
986 | // phase = TP_BURST_SHORT; | ||
987 | num_received_size[peer_nr] = 0; | ||
988 | num_sent_size[peer_nr] = 0; | ||
989 | avg_latency[peer_nr] = 0; | ||
990 | num_sent_short[peer_nr] = 0; | ||
991 | num_sent_long[peer_nr] = 0; | ||
992 | num_received_short[peer_nr] = 0; | ||
993 | num_received_long[peer_nr] = 0; | ||
994 | // short_test (NULL); | ||
995 | if (((PEER_A == peer_nr) && finished[PEER_B]) || ((PEER_B == | ||
996 | peer_nr) && | ||
997 | finished[PEER_A])) | ||
998 | { | ||
999 | load_phase_config (); | ||
1000 | } | ||
1001 | } | ||
1002 | choose_phase (get_tc_h (peer_nr)); | ||
1003 | } | ||
1004 | break; | ||
1005 | } | ||
1006 | } | ||
1007 | } | ||
1008 | |||
1009 | |||
1010 | static void | ||
1011 | do_shutdown (void *cls) | ||
1012 | { | ||
1013 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1014 | "shutting down test.\n"); | ||
1015 | |||
1016 | for (unsigned int i = 0; i < NUM_PEERS; i++) | ||
1017 | { | ||
1018 | if (NULL != box_stats[i]) | ||
1019 | { | ||
1020 | GNUNET_STATISTICS_get_cancel (box_stats[i]); | ||
1021 | box_stats[i] = NULL; | ||
1022 | } | ||
1023 | if (NULL != rekey_stats[i]) | ||
1024 | { | ||
1025 | GNUNET_STATISTICS_get_cancel (rekey_stats[i]); | ||
1026 | rekey_stats[i] = NULL; | ||
1027 | } | ||
1028 | if (NULL != to_task[i]) | ||
1029 | { | ||
1030 | GNUNET_SCHEDULER_cancel (to_task[i]); | ||
1031 | to_task[i] = NULL; | ||
1032 | } | ||
1033 | GNUNET_TRANSPORT_TESTING_transport_communicator_service_stop (tc_hs[i]); | ||
1034 | GNUNET_STATISTICS_destroy (stats[i], GNUNET_NO); | ||
1035 | } | ||
1036 | } | ||
1037 | |||
1038 | |||
1039 | /** | ||
1040 | * @brief Main function called by the scheduler | ||
1041 | * | ||
1042 | * @param cls Closure - Handle to confiation | ||
1043 | */ | ||
1044 | static void | ||
1045 | run (void *cls) | ||
1046 | { | ||
1047 | ret = 0; | ||
1048 | // num_received = 0; | ||
1049 | // num_sent = 0; | ||
1050 | for (unsigned int i = 0; i < NUM_PEERS; i++) | ||
1051 | { | ||
1052 | tc_hs[i] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( | ||
1053 | "transport", | ||
1054 | communicator_binary, | ||
1055 | cfg_peers_name[i], | ||
1056 | &peer_id[i], | ||
1057 | &communicator_available_cb, | ||
1058 | &add_address_cb, | ||
1059 | &queue_create_reply_cb, | ||
1060 | &add_queue_cb, | ||
1061 | &incoming_message_cb, | ||
1062 | &handle_backchannel_cb, | ||
1063 | cfg_peers_name[i]); /* cls */ | ||
1064 | |||
1065 | if ((0 == strcmp ("udp", communicator_name)) && ((0 == strcmp ("rekey", | ||
1066 | test_name)) | ||
1067 | || | ||
1068 | (0 == strcmp ( | ||
1069 | "backchannel", | ||
1070 | test_name))) ) | ||
1071 | { | ||
1072 | stats[i] = GNUNET_STATISTICS_create ("C-UDP", | ||
1073 | cfg_peers[i]); | ||
1074 | } | ||
1075 | else if ((0 == strcmp ("bidirect", test_name))) | ||
1076 | { | ||
1077 | bidirect = GNUNET_YES; | ||
1078 | } | ||
1079 | } | ||
1080 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
1081 | NULL); | ||
1082 | } | ||
1083 | |||
1084 | |||
1085 | int | ||
1086 | main (int argc, | ||
1087 | char *const *argv) | ||
1088 | { | ||
1089 | struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; | ||
1090 | char *test_mode; | ||
1091 | char *cfg_peer; | ||
1092 | |||
1093 | iterations_left[0] = TOTAL_ITERATIONS; | ||
1094 | iterations_left[1] = TOTAL_ITERATIONS; | ||
1095 | phase[0] = TP_INIT; | ||
1096 | phase[1] = TP_INIT; | ||
1097 | ret = 1; | ||
1098 | test_name = GNUNET_STRINGS_get_suffix_from_binary_name (argv[0]); | ||
1099 | communicator_name = strchr (test_name, '-'); | ||
1100 | communicator_name[0] = '\0'; | ||
1101 | communicator_name++; | ||
1102 | test_mode = test_name; | ||
1103 | |||
1104 | GNUNET_asprintf (&communicator_binary, | ||
1105 | "gnunet-communicator-%s", | ||
1106 | communicator_name); | ||
1107 | |||
1108 | if (GNUNET_OK != | ||
1109 | GNUNET_log_setup ("test_communicator_basic", | ||
1110 | "DEBUG", | ||
1111 | NULL)) | ||
1112 | { | ||
1113 | fprintf (stderr, "Unable to setup log\n"); | ||
1114 | GNUNET_break (0); | ||
1115 | return 2; | ||
1116 | } | ||
1117 | for (unsigned int i = 0; i < NUM_PEERS; i++) | ||
1118 | { | ||
1119 | GNUNET_asprintf ((&cfg_peer), | ||
1120 | "test_communicator_%s_%s_peer%u.conf", | ||
1121 | communicator_name, test_mode, i + 1); | ||
1122 | cfg_peers_name[i] = cfg_peer; | ||
1123 | cfg_peers[i] = GNUNET_CONFIGURATION_create (); | ||
1124 | if (GNUNET_YES == | ||
1125 | GNUNET_DISK_file_test (cfg_peers_name[i])) | ||
1126 | { | ||
1127 | if (GNUNET_SYSERR == | ||
1128 | GNUNET_CONFIGURATION_load (cfg_peers[i], | ||
1129 | cfg_peers_name[i])) | ||
1130 | { | ||
1131 | fprintf (stderr, | ||
1132 | "Malformed configuration file `%s', exiting ...\n", | ||
1133 | cfg_peers_name[i]); | ||
1134 | return 1; | ||
1135 | } | ||
1136 | } | ||
1137 | else | ||
1138 | { | ||
1139 | if (GNUNET_SYSERR == | ||
1140 | GNUNET_CONFIGURATION_load (cfg_peers[i], | ||
1141 | NULL)) | ||
1142 | { | ||
1143 | fprintf (stderr, | ||
1144 | "Configuration file %s does not exist, exiting ...\n", | ||
1145 | cfg_peers_name[i]); | ||
1146 | return 1; | ||
1147 | } | ||
1148 | } | ||
1149 | private_key = | ||
1150 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg_peers[i]); | ||
1151 | if (NULL == private_key) | ||
1152 | { | ||
1153 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1154 | "Unable to get peer ID\n"); | ||
1155 | return 1; | ||
1156 | } | ||
1157 | GNUNET_CRYPTO_eddsa_key_get_public (private_key, | ||
1158 | &peer_id[i].public_key); | ||
1159 | GNUNET_free (private_key); | ||
1160 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1161 | "Identity of peer %u is %s\n", | ||
1162 | i, | ||
1163 | GNUNET_i2s_full (&peer_id[i])); | ||
1164 | } | ||
1165 | if (GNUNET_OK != | ||
1166 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1167 | TEST_SECTION, | ||
1168 | "ALLOWED_PACKET_LOSS_SHORT", | ||
1169 | &allowed_packet_loss_short)) | ||
1170 | allowed_packet_loss_short = ALLOWED_PACKET_LOSS; | ||
1171 | if (GNUNET_OK != | ||
1172 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1173 | TEST_SECTION, | ||
1174 | "ALLOWED_PACKET_LOSS_LONG", | ||
1175 | &allowed_packet_loss_long)) | ||
1176 | allowed_packet_loss_long = ALLOWED_PACKET_LOSS; | ||
1177 | if (GNUNET_OK != | ||
1178 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1179 | TEST_SECTION, | ||
1180 | "BURST_PACKETS_SHORT", | ||
1181 | &burst_packets_short)) | ||
1182 | burst_packets_short = BURST_PACKETS; | ||
1183 | if (GNUNET_OK != | ||
1184 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1185 | TEST_SECTION, | ||
1186 | "BURST_PACKETS_LONG", | ||
1187 | &burst_packets_long)) | ||
1188 | burst_packets_long = BURST_PACKETS; | ||
1189 | if (GNUNET_OK != | ||
1190 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1191 | TEST_SECTION, | ||
1192 | "DELAY_SHORT", | ||
1193 | &delay_short_value)) | ||
1194 | delay_short = DELAY; | ||
1195 | else | ||
1196 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, | ||
1197 | delay_short_value); | ||
1198 | if (GNUNET_OK != | ||
1199 | GNUNET_CONFIGURATION_get_value_number (cfg_peers[0], | ||
1200 | TEST_SECTION, | ||
1201 | "DELAY_SHORT", | ||
1202 | &delay_long_value)) | ||
1203 | delay_long = DELAY; | ||
1204 | else | ||
1205 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MICROSECONDS, | ||
1206 | delay_long_value); | ||
1207 | load_phase_config (); | ||
1208 | LOG (GNUNET_ERROR_TYPE_MESSAGE, "Starting test...\n"); | ||
1209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1210 | "argv[0]: %s\n", | ||
1211 | argv[0]); | ||
1212 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1213 | "test_name: %s\n", | ||
1214 | test_name); | ||
1215 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1216 | "communicator_name: %s\n", | ||
1217 | communicator_name); | ||
1218 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1219 | "communicator_binary: %s\n", | ||
1220 | communicator_binary); | ||
1221 | GNUNET_SCHEDULER_run (&run, | ||
1222 | NULL); | ||
1223 | return ret; | ||
1224 | } | ||