Merge branch 'master' of gnunet.org:gnunet
[oweals/gnunet.git] / src / topology / test_gnunet_daemon_topology.c
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009, 2012 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 /**
19  * @file topology/test_gnunet_daemon_topology.c
20  * @brief testcase for topology maintenance code
21  */
22 #include "platform.h"
23 #include "gnunet_testbed_service.h"
24
25
26 #define NUM_PEERS 8
27
28 /**
29  * How long until we give up on connecting the peers?
30  */
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
32
33
34 static int ok;
35
36 static unsigned int connect_left;
37
38
39 static void
40 notify_connect_complete (void *cls,
41                          struct GNUNET_TESTBED_Operation *op,
42                          const char *emsg)
43 {
44   GNUNET_TESTBED_operation_done (op);
45   if (NULL != emsg)
46   {
47     FPRINTF (stderr, "Failed to connect two peers: %s\n", emsg);
48     GNUNET_SCHEDULER_shutdown ();
49     ok = 1;
50     return;
51   }
52   connect_left--;
53   if (0 == connect_left)
54   {
55     /* FIXME: check that topology adds a few more links
56      * in addition to those that were seeded */
57     GNUNET_SCHEDULER_shutdown ();
58   }
59 }
60
61
62 static void
63 do_connect (void *cls,
64             struct GNUNET_TESTBED_RunHandle *h,
65             unsigned int num_peers,
66             struct GNUNET_TESTBED_Peer **peers,
67             unsigned int links_succeeded,
68             unsigned int links_failed)
69 {
70   unsigned int i;
71
72   GNUNET_assert (NUM_PEERS == num_peers);
73   for (i=0;i<num_peers-1;i++)
74     {
75       connect_left++;
76       GNUNET_TESTBED_overlay_connect (NULL,
77                                       &notify_connect_complete, NULL,
78                                       peers[i], peers[i+1]);
79     }
80 }
81
82
83 int
84 main (int argc, char *argv[])
85 {
86   (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology",
87                                   "test_gnunet_daemon_topology_data.conf",
88                                   NUM_PEERS,
89                                   0, NULL, NULL,
90                                   &do_connect, NULL);
91   GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology");
92   return ok;
93 }
94
95 /* end of test_gnunet_daemon_topology.c */