aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_small_unicast.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh/test_mesh_small_unicast.c')
-rw-r--r--src/mesh/test_mesh_small_unicast.c785
1 files changed, 0 insertions, 785 deletions
diff --git a/src/mesh/test_mesh_small_unicast.c b/src/mesh/test_mesh_small_unicast.c
deleted file mode 100644
index ad5a0fd22..000000000
--- a/src/mesh/test_mesh_small_unicast.c
+++ /dev/null
@@ -1,785 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file mesh/test_mesh_small_unicast.c
22 *
23 * @brief Test for the mesh service: retransmission of unicast traffic.
24 */
25#include "platform.h"
26#include "gnunet_testing_lib.h"
27#include "gnunet_mesh_service_new.h"
28
29#define VERBOSE GNUNET_YES
30#define REMOVE_DIR GNUNET_YES
31
32struct MeshPeer
33{
34 struct MeshPeer *prev;
35
36 struct MeshPeer *next;
37
38 struct GNUNET_TESTING_Daemon *daemon;
39
40 struct GNUNET_MESH_Handle *mesh_handle;
41};
42
43
44struct StatsContext
45{
46 unsigned long long total_mesh_bytes;
47};
48
49
50/**
51 * How long until we give up on connecting the peers?
52 */
53#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500)
54
55/**
56 * Time to wait for stuff that should be rather fast
57 */
58#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
59
60#define OK_GOAL 5
61
62static int ok;
63
64/**
65 * Be verbose
66 */
67static int verbose;
68
69/**
70 * Total number of peers in the test.
71 */
72static unsigned long long num_peers;
73
74/**
75 * Global configuration file
76 */
77static struct GNUNET_CONFIGURATION_Handle *testing_cfg;
78
79/**
80 * Total number of currently running peers.
81 */
82static unsigned long long peers_running;
83
84/**
85 * Total number of connections in the whole network.
86 */
87static unsigned int total_connections;
88
89/**
90 * The currently running peer group.
91 */
92static struct GNUNET_TESTING_PeerGroup *pg;
93
94/**
95 * File to report results to.
96 */
97static struct GNUNET_DISK_FileHandle *output_file;
98
99/**
100 * File to log connection info, statistics to.
101 */
102static struct GNUNET_DISK_FileHandle *data_file;
103
104/**
105 * How many data points to capture before triggering next round?
106 */
107static struct GNUNET_TIME_Relative wait_time;
108
109/**
110 * Task called to disconnect peers.
111 */
112static GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
113
114/**
115 * Task To perform tests
116 */
117static GNUNET_SCHEDULER_TaskIdentifier test_task;
118
119/**
120 * Task called to shutdown test.
121 */
122static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle;
123
124static char *topology_file;
125
126static char *data_filename;
127
128static struct GNUNET_TESTING_Daemon *d1;
129
130static GNUNET_PEER_Id pid1;
131
132static struct GNUNET_TESTING_Daemon *d2;
133
134static struct GNUNET_MESH_Handle *h1;
135
136static struct GNUNET_MESH_Handle *h2;
137
138static struct GNUNET_MESH_Tunnel *t;
139
140static struct GNUNET_MESH_Tunnel *incoming_t;
141
142static uint16_t *mesh_peers;
143
144/**
145 * Check whether peers successfully shut down.
146 */
147static void
148shutdown_callback (void *cls, const char *emsg)
149{
150 if (emsg != NULL)
151 {
152#if VERBOSE
153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n");
154#endif
155 ok--;
156 }
157 else
158 {
159#if VERBOSE
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n");
161#endif
162 }
163}
164
165
166static void
167shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
168{
169#if VERBOSE
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n");
171#endif
172
173 if (disconnect_task != GNUNET_SCHEDULER_NO_TASK)
174 {
175 GNUNET_SCHEDULER_cancel (disconnect_task);
176 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
177 }
178
179 if (data_file != NULL)
180 GNUNET_DISK_file_close (data_file);
181 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
182 GNUNET_CONFIGURATION_destroy (testing_cfg);
183}
184
185
186static void
187disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
188{
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
190 "test: disconnecting mesh service of peers\n");
191 disconnect_task = GNUNET_SCHEDULER_NO_TASK;
192 GNUNET_MESH_disconnect(h1);
193 GNUNET_MESH_disconnect(h2);
194 GNUNET_SCHEDULER_cancel (shutdown_handle);
195 shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL);
196}
197
198
199/**
200 * Transmit ready callback
201 */
202size_t
203tmt_rdy (void *cls, size_t size, void *buf)
204{
205 struct GNUNET_MessageHeader *msg = buf;
206
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tmt_rdy called\n");
208 if (size < sizeof(struct GNUNET_MessageHeader) || NULL == buf)
209 return 0;
210 msg->size = htons (sizeof(struct GNUNET_MessageHeader));
211 msg->type = htons ((long) cls);
212 return sizeof(struct GNUNET_MessageHeader);
213}
214
215
216/**
217 * Function is called whenever a message is received.
218 *
219 * @param cls closure (set from GNUNET_MESH_connect)
220 * @param tunnel connection to the other end
221 * @param tunnel_ctx place to store local state associated with the tunnel
222 * @param sender who sent the message
223 * @param message the actual message
224 * @param atsi performance data for the connection
225 * @return GNUNET_OK to keep the connection open,
226 * GNUNET_SYSERR to close it (signal serious error)
227 */
228int
229data_callback (void *cls,
230 struct GNUNET_MESH_Tunnel * tunnel,
231 void **tunnel_ctx,
232 const struct GNUNET_PeerIdentity *sender,
233 const struct GNUNET_MessageHeader *message,
234 const struct GNUNET_ATS_Information *atsi)
235{
236 long client = (long) cls;
237
238 switch (client)
239 {
240 case 1L:
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "test: Origin client got a response!\n");
243 ok++;
244 GNUNET_MESH_tunnel_destroy (tunnel);
245 GNUNET_SCHEDULER_cancel (disconnect_task);
246 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
247 &disconnect_mesh_peers,
248 NULL);
249 break;
250 case 2L:
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
252 "test: Destination client got a message \n");
253 ok++;
254 GNUNET_MESH_notify_transmit_ready(incoming_t,
255 GNUNET_NO,
256 0,
257 GNUNET_TIME_UNIT_FOREVER_REL,
258 sender,
259 sizeof(struct GNUNET_MessageHeader),
260 &tmt_rdy,
261 (void *) 1L);
262 GNUNET_SCHEDULER_cancel (disconnect_task);
263 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
264 &disconnect_mesh_peers,
265 NULL);
266 break;
267 default:
268 break;
269 }
270 return GNUNET_OK;
271}
272
273
274/**
275 * Handlers, for diverse services
276 */
277static struct GNUNET_MESH_MessageHandler handlers[] = {
278 {&data_callback, 1, sizeof(struct GNUNET_MessageHeader)},
279 {NULL, 0, 0}
280};
281
282
283/**
284 * Method called whenever another peer has added us to a tunnel
285 * the other peer initiated.
286 *
287 * @param cls closure
288 * @param tunnel new handle to the tunnel
289 * @param initiator peer that started the tunnel
290 * @param atsi performance information for the tunnel
291 * @return initial tunnel context for the tunnel
292 * (can be NULL -- that's not an error)
293 */
294static void *
295incoming_tunnel (void *cls,
296 struct GNUNET_MESH_Tunnel * tunnel,
297 const struct GNUNET_PeerIdentity * initiator,
298 const struct GNUNET_ATS_Information * atsi)
299{
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "test: Incoming tunnel from %s\n",
302 GNUNET_i2s(initiator));
303 ok++;
304 incoming_t = tunnel;
305 GNUNET_SCHEDULER_cancel (disconnect_task);
306 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
307 &disconnect_mesh_peers,
308 NULL);
309 return NULL;
310}
311
312/**
313 * Function called whenever an inbound tunnel is destroyed. Should clean up
314 * any associated state.
315 *
316 * @param cls closure (set from GNUNET_MESH_connect)
317 * @param tunnel connection to the other end (henceforth invalid)
318 * @param tunnel_ctx place where local state associated
319 * with the tunnel is stored
320 */
321static void
322tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
323 void *tunnel_ctx)
324{
325 long i = (long) cls;
326
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "test: Incoming tunnel disconnected at peer %d\n",
329 i);
330 if (2L == i)
331 ok++;
332
333 GNUNET_SCHEDULER_cancel (disconnect_task);
334 disconnect_task = GNUNET_SCHEDULER_add_now (&disconnect_mesh_peers, NULL);
335
336 return;
337}
338
339
340/**
341 * Method called whenever a tunnel falls apart.
342 *
343 * @param cls closure
344 * @param peer peer identity the tunnel stopped working with
345 */
346static void
347dh (void *cls, const struct GNUNET_PeerIdentity *peer)
348{
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "test: peer %s disconnected\n",
351 GNUNET_i2s(peer));
352 return;
353}
354
355
356/**
357 * Method called whenever a peer connects to a tunnel.
358 *
359 * @param cls closure
360 * @param peer peer identity the tunnel was created to, NULL on timeout
361 * @param atsi performance data for the connection
362 */
363static void
364ch (void *cls, const struct GNUNET_PeerIdentity *peer,
365 const struct GNUNET_ATS_Information *atsi)
366{
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "test: peer %s connected\n",
369 GNUNET_i2s(peer));
370 if (0 == memcmp(&d2->id, peer, sizeof(d2->id)) && (long) cls == 1L)
371 ok++;
372 if (GNUNET_SCHEDULER_NO_TASK != disconnect_task)
373 {
374 GNUNET_SCHEDULER_cancel (disconnect_task);
375 disconnect_task = GNUNET_SCHEDULER_add_delayed(SHORT_TIME,
376 &disconnect_mesh_peers,
377 NULL);
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Sending data unicast...\n");
379 GNUNET_MESH_notify_transmit_ready(t,
380 GNUNET_NO,
381 0,
382 GNUNET_TIME_UNIT_FOREVER_REL,
383 &d2->id,
384 sizeof(struct GNUNET_MessageHeader),
385 &tmt_rdy,
386 (void *) 1L);
387 }
388 return;
389}
390
391
392static void
393do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394{
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n");
396 GNUNET_MESH_peer_request_connect_add(t, &d2->id);
397 GNUNET_SCHEDULER_cancel (disconnect_task);
398 disconnect_task = GNUNET_SCHEDULER_add_delayed(
399 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30),
400 &disconnect_mesh_peers, NULL);
401}
402
403
404/**
405 * Prototype of a callback function indicating that two peers
406 * are currently connected.
407 *
408 * @param cls closure
409 * @param first peer id for first daemon
410 * @param second peer id for the second daemon
411 * @param distance distance between the connected peers
412 * @param emsg error message (NULL on success)
413 */
414void
415topo_cb (void *cls,
416 const struct GNUNET_PeerIdentity* first,
417 const struct GNUNET_PeerIdentity* second,
418 const char *emsg)
419{
420 GNUNET_PEER_Id p1;
421 GNUNET_PEER_Id p2;
422 struct GNUNET_PeerIdentity id;
423
424 GNUNET_PEER_resolve(1, &id);
425 p1 = GNUNET_PEER_search(first);
426 if (p1 == pid1)
427 {
428 p2 = GNUNET_PEER_search(second);
429 GNUNET_assert(p2 < num_peers);
430 GNUNET_assert(p2 > 0);
431 mesh_peers[p2]++;
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "test: %s IS a neighbor\n",
434 GNUNET_i2s(second));
435 return;
436 }
437 p1 = GNUNET_PEER_search(second);
438 if (p1 == pid1)
439 {
440 p2 = GNUNET_PEER_search(first);
441 GNUNET_assert(p2 < num_peers);
442 GNUNET_assert(p2 > 0);
443 mesh_peers[p2]++;
444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
445 "test: %s IS a neighbor\n",
446 GNUNET_i2s(first));
447 return;
448 }
449}
450
451/**
452 * connect_mesh_service: connect to the mesh service of one of the peers
453 *
454 */
455static void
456connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
457{
458 GNUNET_MESH_ApplicationType app;
459 unsigned int i;
460 struct GNUNET_PeerIdentity id;
461
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n");
463
464 for (i = 1; i <= num_peers; i++)
465 {
466 GNUNET_PEER_resolve(i, &id);
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "test: peer %s has %u conns to d1\n",
469 GNUNET_i2s (&id),
470 mesh_peers[i]);
471 if (mesh_peers[i] == 0)
472 break;
473 }
474 GNUNET_assert (i < num_peers);
475 d2 = GNUNET_TESTING_daemon_get_by_id (pg, &id);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
477 "test: Peer searched: %s\n",
478 GNUNET_i2s (&d2->id));
479 app = (GNUNET_MESH_ApplicationType) 0;
480
481#if VERBOSE
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 "test: connecting to mesh service of peer %s (%u)\n",
484 GNUNET_i2s (&d1->id),
485 mesh_peers[0]);
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
487 "test: connecting to mesh service of peer %s (%u)\n",
488 GNUNET_i2s (&d2->id),
489 i);
490#endif
491 h1 = GNUNET_MESH_connect (d1->cfg,
492 10,
493 (void *) 1L,
494 NULL,
495 &tunnel_cleaner,
496 handlers,
497 &app);
498 h2 = GNUNET_MESH_connect (d2->cfg,
499 10,
500 (void *) 2L,
501 &incoming_tunnel,
502 &tunnel_cleaner,
503 handlers,
504 &app);
505#if VERBOSE
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "test: connected to mesh service of peer %s\n",
508 GNUNET_i2s (&d1->id));
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "test: connected to mesh service of peer %s\n",
511 GNUNET_i2s (&d2->id));
512#endif
513 t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, (void *) 1L);
514 test_task =
515 GNUNET_SCHEDULER_add_delayed(
516 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 6),
517 &do_test, NULL);
518}
519
520
521
522/**
523 * peergroup_ready: start test when all peers are connected
524 * @param cls closure
525 * @param emsg error message
526 */
527static void
528peergroup_ready (void *cls, const char *emsg)
529{
530 char *buf;
531 int buf_len;
532 unsigned int i;
533
534 if (emsg != NULL)
535 {
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "test: Peergroup callback called with error, aborting test!\n");
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "test: Error from testing: `%s'\n", emsg);
540 ok--;
541 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
542 return;
543 }
544#if VERBOSE
545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
546 "************************************************************\n");
547 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
548 "test: Peer Group started successfully!\n");
549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
550 "test: Have %u connections\n",
551 total_connections);
552#endif
553
554 if (data_file != NULL)
555 {
556 buf = NULL;
557 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
558 if (buf_len > 0)
559 GNUNET_DISK_file_write (data_file, buf, buf_len);
560 GNUNET_free (buf);
561 }
562 peers_running = GNUNET_TESTING_daemons_running (pg);
563 for (i = 0; i < num_peers; i++)
564 {
565 d1 = GNUNET_TESTING_daemon_get (pg, i);
566 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
567 "test: %u: %s\n",
568 GNUNET_PEER_intern(&d1->id),
569 GNUNET_i2s (&d1->id));
570 }
571 d1 = GNUNET_TESTING_daemon_get (pg, 0);
572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
573 "test: Peer looking: %s\n",
574 GNUNET_i2s (&d1->id));
575 pid1 = GNUNET_PEER_intern(&d1->id);
576 mesh_peers[pid1] = 100;
577 GNUNET_TESTING_get_topology(pg, &topo_cb, NULL);
578
579 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
580 GNUNET_TIME_UNIT_SECONDS,
581 4),
582 &connect_mesh_service,
583 NULL);
584 disconnect_task =
585 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
586
587}
588
589
590/**
591 * Function that will be called whenever two daemons are connected by
592 * the testing library.
593 *
594 * @param cls closure
595 * @param first peer id for first daemon
596 * @param second peer id for the second daemon
597 * @param distance distance between the connected peers
598 * @param first_cfg config for the first daemon
599 * @param second_cfg config for the second daemon
600 * @param first_daemon handle for the first daemon
601 * @param second_daemon handle for the second daemon
602 * @param emsg error message (NULL on success)
603 */
604static void
605connect_cb (void *cls, const struct GNUNET_PeerIdentity *first,
606 const struct GNUNET_PeerIdentity *second, uint32_t distance,
607 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
608 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
609 struct GNUNET_TESTING_Daemon *first_daemon,
610 struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg)
611{
612 if (emsg == NULL)
613 {
614 total_connections++;
615 }
616 else
617 {
618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
619 "test: Problem with new connection (%s)\n",
620 emsg);
621 }
622
623}
624
625
626/**
627 * run: load configuration options and schedule test to run (start peergroup)
628 * @param cls closure
629 * @param args argv
630 * @param cfgfile configuration file name (can be NULL)
631 * @param cfg configuration handle
632 */
633static void
634run (void *cls, char *const *args, const char *cfgfile,
635 const struct GNUNET_CONFIGURATION_Handle *cfg)
636{
637 char *temp_str;
638 unsigned long long temp_wait;
639 struct GNUNET_TESTING_Host *hosts;
640
641 ok = 0;
642 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
643
644 GNUNET_log_setup ("test_mesh_small_unicast",
645#if VERBOSE
646 "DEBUG",
647#else
648 "WARNING",
649#endif
650 NULL);
651
652#if VERBOSE
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n");
654 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
655 "use_progressbars", "YES");
656#endif
657
658 if (GNUNET_OK !=
659 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
660 "num_peers", &num_peers))
661 {
662 GNUNET_assert (GNUNET_OK ==
663 GNUNET_CONFIGURATION_load (testing_cfg,
664 "test_mesh_small.conf"));
665 if (GNUNET_OK !=
666 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
667 "num_peers", &num_peers))
668 {
669 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
670 "Option TESTING:NUM_PEERS is required!\n");
671 return;
672 }
673 }
674
675 mesh_peers = GNUNET_malloc (sizeof(GNUNET_PEER_Id) * (num_peers + 1));
676
677 if (GNUNET_OK !=
678 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
679 "wait_time", &temp_wait))
680 {
681 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
682 "Option test_mesh_small:wait_time is required!\n");
683 return;
684 }
685
686 if (GNUNET_OK !=
687 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
688 "topology_output_file",
689 &topology_file))
690 {
691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
692 "Option test_mesh_small:topology_output_file is required!\n");
693 return;
694 }
695
696 if (GNUNET_OK !=
697 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
698 "data_output_file",
699 &data_filename))
700 {
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
702 "Option test_mesh_small:data_output_file is required!\n");
703 return;
704 }
705
706 data_file =
707 GNUNET_DISK_file_open (data_filename,
708 GNUNET_DISK_OPEN_READWRITE |
709 GNUNET_DISK_OPEN_CREATE,
710 GNUNET_DISK_PERM_USER_READ |
711 GNUNET_DISK_PERM_USER_WRITE);
712 if (data_file == NULL)
713 {
714 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
715 data_filename);
716 GNUNET_free (data_filename);
717 }
718
719 wait_time =
720 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
721
722 if (GNUNET_YES ==
723 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
724 "output_file", &temp_str))
725 {
726 output_file =
727 GNUNET_DISK_file_open (temp_str,
728 GNUNET_DISK_OPEN_READWRITE |
729 GNUNET_DISK_OPEN_CREATE,
730 GNUNET_DISK_PERM_USER_READ |
731 GNUNET_DISK_PERM_USER_WRITE);
732 if (output_file == NULL)
733 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
734 temp_str);
735 }
736 GNUNET_free_non_null (temp_str);
737
738 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
739
740 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
741 &connect_cb, &peergroup_ready, NULL,
742 hosts);
743 GNUNET_assert (pg != NULL);
744 shutdown_handle =
745 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
746 &shutdown_task, NULL);
747}
748
749
750
751/**
752 * test_mesh_small command line options
753 */
754static struct GNUNET_GETOPT_CommandLineOption options[] = {
755 {'V', "verbose", NULL,
756 gettext_noop ("be verbose (print progress information)"),
757 0, &GNUNET_GETOPT_set_one, &verbose},
758 GNUNET_GETOPT_OPTION_END
759};
760
761
762/**
763 * Main: start test
764 */
765int
766main (int argc, char *argv[])
767{
768 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast",
769 gettext_noop ("Test mesh unicast in a small network."),
770 options, &run, NULL);
771#if REMOVE_DIR
772 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast");
773#endif
774 if (OK_GOAL != ok)
775 {
776 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
777 "test: FAILED! (%d/%d)\n",
778 ok, OK_GOAL);
779 return 1;
780 }
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n");
782 return 0;
783}
784
785/* end of test_mesh_small_unicast.c */