2 This file is part of GNUnet
3 Copyright (C) 2008--2013 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file testbed/test_testbed_underlay.c
23 * @brief testcase binary for testing testbed underlay restrictions
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
28 #include "gnunet_util_lib.h"
29 #include "gnunet_testbed_service.h"
33 * Number of peers we start in this test case
38 * Result of this test case
42 static struct GNUNET_TESTBED_Operation *op;
49 * @param tc scheduler task context
52 do_shutdown (void *cls)
55 GNUNET_TESTBED_operation_done (op);
61 * Callback to be called when an operation is completed
63 * @param cls the callback closure from functions generating an operation
64 * @param op the operation that has been finished
65 * @param emsg error message in case the operation has failed; will be NULL if
66 * operation has executed successfully.
69 overlay_connect_status (void *cls,
70 struct GNUNET_TESTBED_Operation *op_,
73 GNUNET_assert (op_ == op);
74 GNUNET_TESTBED_operation_done (op);
77 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
78 "Peers 0 and 2 should not get connected\n");
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "Peers 0 and 2 not connected: %s. Success!\n", emsg);
85 GNUNET_SCHEDULER_shutdown ();
91 * Signature of a main function for a testcase.
94 * @param h the run handle
95 * @param num_peers number of peers in 'peers'
96 * @param peers_ handle to peers run in the testbed
97 * @param links_succeeded the number of overlay link connection attempts that
99 * @param links_failed the number of overlay link connection attempts that
103 test_master (void *cls,
104 struct GNUNET_TESTBED_RunHandle *h,
105 unsigned int num_peers,
106 struct GNUNET_TESTBED_Peer **peers_,
107 unsigned int links_succeeded,
108 unsigned int links_failed)
110 GNUNET_assert (NULL == cls);
113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failing test due to timeout\n");
114 GNUNET_SCHEDULER_shutdown ();
117 GNUNET_assert (NUM_PEERS == num_peers);
118 op = GNUNET_TESTBED_overlay_connect (NULL,
119 &overlay_connect_status,
123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (
124 GNUNET_TIME_UNIT_SECONDS,
132 * Assumed maximum path length (for the log file name).
134 #define PATH_MAX 4096
142 main (int argc, char **argv)
144 struct GNUNET_CONFIGURATION_Handle *cfg;
149 result = GNUNET_SYSERR;
151 cfg = GNUNET_CONFIGURATION_create ();
152 GNUNET_assert (GNUNET_YES ==
153 GNUNET_CONFIGURATION_parse (cfg,
154 "test_testbed_underlay.conf.in"));
155 if (NULL == getcwd (pwd, PATH_MAX))
157 GNUNET_assert (0 < GNUNET_asprintf (&dbfile, "%s/%s", pwd,
158 "test-underlay.sqlite"));
159 GNUNET_CONFIGURATION_set_value_string (cfg, "TESTBED-UNDERLAY", "DBFILE",
161 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_write
162 (cfg, "test_testbed_underlay.conf"));
163 GNUNET_CONFIGURATION_destroy (cfg);
165 GNUNET_free (dbfile);
167 (void) GNUNET_TESTBED_test_run ("test_testbed_underlay",
168 "test_testbed_underlay.conf", NUM_PEERS,
169 event_mask, NULL, NULL,
171 (void) unlink ("test_testbed_underlay.conf");
172 if (GNUNET_OK != result)