2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file testing/test_testing_group_remote.c
22 * @brief testcase for testing remote and local starting and connecting
23 * of hosts from the testing library. The test_testing_data_remote.conf
24 * file should be modified if this testcase is intended to be used.
27 #include "gnunet_testing_lib.h"
29 #define VERBOSE GNUNET_YES
33 * How long until we give up on connecting the peers?
35 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
37 #define DEFAULT_NUM_PEERS 8;
41 static int peers_left;
43 static int peers_failed;
45 static struct GNUNET_TESTING_PeerGroup *pg;
47 static unsigned long long num_peers;
51 * Check whether peers successfully shut down.
54 shutdown_callback (void *cls, const char *emsg)
59 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
67 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
68 "All peers successfully shut down!\n");
76 const struct GNUNET_PeerIdentity *id,
77 const struct GNUNET_CONFIGURATION_Handle *cfg,
78 struct GNUNET_TESTING_Daemon *d, const char *emsg)
88 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
91 else if (peers_failed == peers_left)
93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
94 "Too many peers failed, ending test!\n");
95 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
103 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
105 struct GNUNET_TESTING_Host *hosts;
106 struct GNUNET_TESTING_Host *hostpos;
107 struct GNUNET_TESTING_Host *temphost;
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
120 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
122 num_peers = DEFAULT_NUM_PEERS;
124 GNUNET_assert (num_peers > 0 && num_peers < (unsigned long long) -1);
126 GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
132 if (hostfile != NULL)
134 if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
135 GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
136 | GNUNET_DISK_PERM_USER_WRITE);
137 if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 "Could not open file specified for host list, ending test!");
142 GNUNET_free (hostfile);
146 data = GNUNET_malloc_large (frstat.st_size);
147 GNUNET_assert (data != NULL);
148 if (frstat.st_size !=
149 GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
151 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
152 "Could not read file %s specified for host list, ending test!",
154 GNUNET_free (hostfile);
159 GNUNET_free_non_null (hostfile);
163 while (count < frstat.st_size)
166 if (count >= frstat.st_size)
169 /* if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count])) */
170 if (((data[count] == '\n')) && (buf != &data[count]))
173 temphost = GNUNET_malloc (sizeof (struct GNUNET_TESTING_Host));
175 sscanf (buf, "%a[a-zA-Z0-9]@%a[a-zA-Z0-9.]:%hd",
176 &temphost->username, &temphost->hostname,
180 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
181 "Successfully read host %s, port %d and user %s from file\n",
182 temphost->hostname, temphost->port,
187 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
188 "Error reading line `%s' in hostfile\n", buf);
189 GNUNET_free (temphost);
190 buf = &data[count + 1];
193 /* temphost->hostname = buf; */
194 temphost->next = hosts;
196 buf = &data[count + 1];
198 else if ((data[count] == '\n') || (data[count] == '\0'))
199 buf = &data[count + 1];
203 peers_left = num_peers;
204 pg = GNUNET_TESTING_daemons_start (cfg,
205 peers_left, /* Total number of peers */
206 peers_left, /* Number of outstanding connections */
207 peers_left, /* Number of parallel ssh connections, or peers being started at once */
210 NULL, &my_cb, NULL, NULL, NULL, hosts);
212 while (hostpos != NULL)
214 temphost = hostpos->next;
215 GNUNET_free (hostpos->hostname);
216 GNUNET_free (hostpos->username);
217 GNUNET_free (hostpos);
220 GNUNET_free_non_null (data);
221 GNUNET_assert (pg != NULL);
228 char *const argv[] = { "test-testing",
230 "test_testing_data_remote.conf",
236 struct GNUNET_GETOPT_CommandLineOption options[] = {
237 GNUNET_GETOPT_OPTION_END
239 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
240 argv, "test-testing-group", "nohelp",
246 main (int argc, char *argv[])
250 GNUNET_log_setup ("test-testing-group",
259 * Still need to remove the base testing directory here,
260 * because group starts will create subdirectories under this
261 * main dir. However, we no longer need to sleep, as the
262 * shutdown sequence won't return until everything is cleaned
265 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-testing");
269 /* end of test_testing_group.c */