diff options
Diffstat (limited to 'src/testing/gnunet-testing.c')
-rw-r--r-- | src/testing/gnunet-testing.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c index e15cacdcd..a6fb3735c 100644 --- a/src/testing/gnunet-testing.c +++ b/src/testing/gnunet-testing.c | |||
@@ -43,6 +43,7 @@ static int create_no; | |||
43 | 43 | ||
44 | static char * create_cfg_template; | 44 | static char * create_cfg_template; |
45 | 45 | ||
46 | static char * create_hostkey_file; | ||
46 | 47 | ||
47 | static int | 48 | static int |
48 | create_unique_cfgs (const char * template, const unsigned int no) | 49 | create_unique_cfgs (const char * template, const unsigned int no) |
@@ -131,27 +132,37 @@ create_hostkeys (const unsigned int no) | |||
131 | uint64_t fs; | 132 | uint64_t fs; |
132 | uint64_t total_hostkeys; | 133 | uint64_t total_hostkeys; |
133 | char *hostkey_data; | 134 | char *hostkey_data; |
134 | char *hostkeyfile; | 135 | char *hostkey_src_file; |
136 | char *hostkey_dest_file; | ||
135 | 137 | ||
136 | /* prepare hostkeys */ | 138 | /* prepare hostkeys */ |
137 | const char *hostkeys_file = "../../contrib/testing_hostkeys.dat"; | 139 | if (create_hostkey_file == NULL) |
140 | hostkey_src_file = "../../contrib/testing_hostkeys.dat"; | ||
141 | else | ||
142 | { | ||
143 | hostkey_src_file = create_hostkey_file; | ||
144 | } | ||
138 | 145 | ||
139 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | 146 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkey_src_file)) |
140 | { | 147 | { |
141 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file!\n")); | 148 | if (create_hostkey_file == NULL) |
149 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file, specify hostkey file with -H!\n")); | ||
150 | else | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Specified hostkey file `%s' not found!\n"), create_hostkey_file); | ||
152 | return 1; | ||
142 | } | 153 | } |
143 | else | 154 | else |
144 | { | 155 | { |
145 | /* Check hostkey file size, read entire thing into memory */ | 156 | /* Check hostkey file size, read entire thing into memory */ |
146 | fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | 157 | fd = GNUNET_DISK_file_open (hostkey_src_file, GNUNET_DISK_OPEN_READ, |
147 | GNUNET_DISK_PERM_NONE); | 158 | GNUNET_DISK_PERM_NONE); |
148 | if (NULL == fd) | 159 | if (NULL == fd) |
149 | { | 160 | { |
150 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_file); | 161 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkey_src_file); |
151 | return 1; | 162 | return 1; |
152 | } | 163 | } |
153 | 164 | ||
154 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | 165 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkey_src_file, &fs, GNUNET_YES)) |
155 | fs = 0; | 166 | fs = 0; |
156 | 167 | ||
157 | if (0 != (fs % HOSTKEYFILESIZE)) | 168 | if (0 != (fs % HOSTKEYFILESIZE)) |
@@ -172,10 +183,10 @@ create_hostkeys (const unsigned int no) | |||
172 | 183 | ||
173 | while (cur < no) | 184 | while (cur < no) |
174 | { | 185 | { |
175 | GNUNET_asprintf (&hostkeyfile, "%04u-hostkey",cur); | 186 | GNUNET_asprintf (&hostkey_dest_file, "%04u-hostkey",cur); |
176 | GNUNET_assert (GNUNET_OK == | 187 | GNUNET_assert (GNUNET_OK == |
177 | GNUNET_DISK_directory_create_for_file (hostkeyfile)); | 188 | GNUNET_DISK_directory_create_for_file (hostkey_dest_file)); |
178 | fd = GNUNET_DISK_file_open (hostkeyfile, | 189 | fd = GNUNET_DISK_file_open (hostkey_dest_file, |
179 | GNUNET_DISK_OPEN_READWRITE | | 190 | GNUNET_DISK_OPEN_READWRITE | |
180 | GNUNET_DISK_OPEN_CREATE, | 191 | GNUNET_DISK_OPEN_CREATE, |
181 | GNUNET_DISK_PERM_USER_READ | | 192 | GNUNET_DISK_PERM_USER_READ | |
@@ -185,8 +196,8 @@ create_hostkeys (const unsigned int no) | |||
185 | GNUNET_DISK_file_write (fd, &hostkey_data[cur * HOSTKEYFILESIZE], HOSTKEYFILESIZE)); | 196 | GNUNET_DISK_file_write (fd, &hostkey_data[cur * HOSTKEYFILESIZE], HOSTKEYFILESIZE)); |
186 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | 197 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); |
187 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 198 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
188 | "Wrote hostkey to file: `%s' \n", hostkeyfile); | 199 | "Wrote hostkey to file: `%s' \n", hostkey_dest_file); |
189 | GNUNET_free (hostkeyfile); | 200 | GNUNET_free (hostkey_dest_file); |
190 | cur ++; | 201 | cur ++; |
191 | } | 202 | } |
192 | 203 | ||
@@ -241,8 +252,10 @@ main (int argc, char *const *argv) | |||
241 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 252 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
242 | {'C', "cfg", NULL, gettext_noop ("create unique configuration files"), | 253 | {'C', "cfg", NULL, gettext_noop ("create unique configuration files"), |
243 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, | 254 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_cfg}, |
244 | {'k', "key", NULL, gettext_noop ("create hostkey files from pre-computed hostkey list"), | 255 | {'k', "key", NULL, gettext_noop ("create hostkey files from pre-computed hostkey list"), |
245 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_hostkey}, | 256 | GNUNET_NO, &GNUNET_GETOPT_set_one, &create_hostkey}, |
257 | {'H', "hostkeys", NULL, gettext_noop ("host key file"), | ||
258 | GNUNET_YES, &GNUNET_GETOPT_set_string, &create_hostkey_file}, | ||
246 | {'n', "number", NULL, gettext_noop ("number of unique configuration files or hostkeys to create"), | 259 | {'n', "number", NULL, gettext_noop ("number of unique configuration files or hostkeys to create"), |
247 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no}, | 260 | GNUNET_YES, &GNUNET_GETOPT_set_uint, &create_no}, |
248 | {'t', "template", NULL, gettext_noop ("configuration template"), | 261 | {'t', "template", NULL, gettext_noop ("configuration template"), |