GNUnet 0.22.2
gnunet-testbed.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 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 FORp 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
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testbed_lib.h"
29
30
31#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testbed", __VA_ARGS__)
32
33
37static int ret;
38
42static unsigned int create_no;
43
48
49
50static int
51create_unique_cfgs (const char *template,
52 const unsigned int no)
53{
54 struct GNUNET_TESTBED_System *system;
55 int fail;
56 char *cur_file;
57 struct GNUNET_CONFIGURATION_Handle *cfg_new;
58 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
59
60 if (GNUNET_NO == GNUNET_DISK_file_test (template))
61 {
63 "Configuration template `%s': file not found\n",
65 return 1;
66 }
68
69 /* load template */
70 if ((create_cfg_template != NULL) &&
71 (GNUNET_OK !=
74 {
76 "Could not load template `%s'\n",
79
80 return 1;
81 }
82 /* load defaults */
83 if (GNUNET_OK !=
85 NULL))
86 {
88 "Could not load template `%s'\n",
91 return 1;
92 }
93
94 fail = GNUNET_NO;
95 system =
97 NULL /* controller */,
98 NULL);
99 for (unsigned int cur = 0; cur < no; cur++)
100 {
102 "Creating configuration no. %u \n",
103 cur);
104 if (create_cfg_template != NULL)
105 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
106 else
107 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
108
109 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
110 if (GNUNET_OK !=
112 cfg_new,
113 NULL,
114 NULL))
115 {
117 "Could not create another configuration\n");
119 fail = GNUNET_YES;
120 break;
121 }
123 "Writing configuration no. %u to file `%s' \n",
124 cur,
125 cur_file);
126 if (GNUNET_OK !=
128 cur_file))
129 {
131 "Failed to write configuration no. %u \n",
132 cur);
133 fail = GNUNET_YES;
134 }
136 GNUNET_free (cur_file);
137 if (GNUNET_YES == fail)
138 break;
139 }
142 false);
143 if (GNUNET_YES == fail)
144 return 1;
145 return 0;
146}
147
148
157static void
159 char *const *args,
160 const char *cfgfile,
161 const struct GNUNET_CONFIGURATION_Handle *cfg)
162{
163 if (create_no > 0)
164 {
166 "Creating %u configuration files based on template `%s'\n",
167 create_no,
170 create_no);
171 }
172 else
173 {
175 "Missing arguments!\n");
176 ret = 1;
177 }
178}
179
180
188int
189main (int argc, char *const *argv)
190{
193 'n',
194 "number",
195 "NUMBER",
196 gettext_noop ("number of unique configuration files to create"),
197 &create_no),
199 't',
200 "template",
201 "FILENAME",
202 gettext_noop ("configuration template"),
205 };
206
207 ret =
208 (GNUNET_OK ==
210 argc,
211 argv,
212 "gnunet-testing",
214 "Command line tool to access the testing library"),
215 options,
217 NULL,
218 GNUNET_YES))
219 ? ret
220 : 1;
221 return ret;
222}
223
224
225/* end of gnunet-testbed.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static void run_no_scheduler(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be running without scheduler.
static int ret
Final status code.
static unsigned int create_no
Number of config files to create.
int main(int argc, char *const *argv)
The main function.
static int create_unique_cfgs(const char *template, const unsigned int no)
static char * create_cfg_template
Filename of the config template to be written.
struct GNUNET_TESTBED_System * GNUNET_TESTBED_system_create(const char *testdir, const char *trusted_ip, const char *hostname)
Create a system handle.
Definition: testbed.c:136
void GNUNET_TESTBED_system_destroy(struct GNUNET_TESTBED_System *system, bool remove_paths)
Free system resources.
Definition: testbed.c:150
enum GNUNET_GenericReturnValue GNUNET_TESTBED_configuration_create(struct GNUNET_TESTBED_System *system, struct GNUNET_CONFIGURATION_Handle *cfg, uint16_t **ports, unsigned int *nports)
Create a new configuration using the given configuration as a template; ports and paths will be modif...
Definition: testbed.c:532
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_create(const struct GNUNET_OS_ProjectData *pd)
Create a new configuration object.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_load(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Load configuration.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_write(struct GNUNET_CONFIGURATION_Handle *cfg, const char *filename)
Write configuration file.
enum GNUNET_GenericReturnValue GNUNET_DISK_file_test(const char *fil)
Check that fil corresponds to a filename (of a file that exists and that is not a directory).
Definition: disk.c:520
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:132
Definition of a command line option.
Handle for a system on which GNUnet peers are executed; a system is used for reserving unique paths a...
Definition: testbed.c:54