aboutsummaryrefslogtreecommitdiff
path: root/src/testing
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing')
-rw-r--r--src/testing/gnunet-testing.c470
-rw-r--r--src/testing/list-keys.c112
-rw-r--r--src/testing/test_testing_peerstartup.c73
-rw-r--r--src/testing/test_testing_peerstartup2.c140
-rw-r--r--src/testing/test_testing_portreservation.c68
-rw-r--r--src/testing/test_testing_servicestartup.c30
-rw-r--r--src/testing/test_testing_sharedservices.c104
-rw-r--r--src/testing/testing.c1474
8 files changed, 1233 insertions, 1238 deletions
diff --git a/src/testing/gnunet-testing.c b/src/testing/gnunet-testing.c
index bc402227c..834cf6cea 100644
--- a/src/testing/gnunet-testing.c
+++ b/src/testing/gnunet-testing.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file testing/gnunet-testing.c 22 * @file testing/gnunet-testing.c
@@ -28,7 +28,7 @@
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30 30
31#define LOG(kind, ...) GNUNET_log_from (kind, "gnunet-testing", __VA_ARGS__) 31#define LOG(kind, ...) GNUNET_log_from(kind, "gnunet-testing", __VA_ARGS__)
32 32
33 33
34/** 34/**
@@ -84,7 +84,7 @@ static struct GNUNET_TESTING_Peer *my_peer;
84 84
85 85
86static int 86static int
87create_unique_cfgs (const char *template, const unsigned int no) 87create_unique_cfgs(const char *template, const unsigned int no)
88{ 88{
89 struct GNUNET_TESTING_System *system; 89 struct GNUNET_TESTING_System *system;
90 int fail; 90 int fail;
@@ -93,76 +93,76 @@ create_unique_cfgs (const char *template, const unsigned int no)
93 struct GNUNET_CONFIGURATION_Handle *cfg_new; 93 struct GNUNET_CONFIGURATION_Handle *cfg_new;
94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl; 94 struct GNUNET_CONFIGURATION_Handle *cfg_tmpl;
95 95
96 if (GNUNET_NO == GNUNET_DISK_file_test (template)) 96 if (GNUNET_NO == GNUNET_DISK_file_test(template))
97 { 97 {
98 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 98 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
99 "Configuration template `%s': file not found\n", 99 "Configuration template `%s': file not found\n",
100 create_cfg_template); 100 create_cfg_template);
101 return 1; 101 return 1;
102 } 102 }
103 cfg_tmpl = GNUNET_CONFIGURATION_create (); 103 cfg_tmpl = GNUNET_CONFIGURATION_create();
104 104
105 /* load template */ 105 /* load template */
106 if ((create_cfg_template != NULL) && 106 if ((create_cfg_template != NULL) &&
107 (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, create_cfg_template))) 107 (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, create_cfg_template)))
108 { 108 {
109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
110 "Could not load template `%s'\n", 110 "Could not load template `%s'\n",
111 create_cfg_template); 111 create_cfg_template);
112 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 112 GNUNET_CONFIGURATION_destroy(cfg_tmpl);
113 113
114 return 1; 114 return 1;
115 } 115 }
116 /* load defaults */ 116 /* load defaults */
117 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg_tmpl, NULL)) 117 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg_tmpl, NULL))
118 { 118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 119 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
120 "Could not load template `%s'\n", 120 "Could not load template `%s'\n",
121 create_cfg_template); 121 create_cfg_template);
122 GNUNET_CONFIGURATION_destroy (cfg_tmpl); 122 GNUNET_CONFIGURATION_destroy(cfg_tmpl);
123 return 1; 123 return 1;
124 } 124 }
125 125
126 fail = GNUNET_NO; 126 fail = GNUNET_NO;
127 system = 127 system =
128 GNUNET_TESTING_system_create ("testing", NULL /* controller */, NULL, NULL); 128 GNUNET_TESTING_system_create("testing", NULL /* controller */, NULL, NULL);
129 for (cur = 0; cur < no; cur++) 129 for (cur = 0; cur < no; cur++)
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Creating configuration no. %u \n",
133 cur);
134 if (create_cfg_template != NULL)
135 GNUNET_asprintf (&cur_file, "%04u-%s", cur, create_cfg_template);
136 else
137 GNUNET_asprintf (&cur_file, "%04u%s", cur, ".conf");
138
139 cfg_new = GNUNET_CONFIGURATION_dup (cfg_tmpl);
140 if (GNUNET_OK != GNUNET_TESTING_configuration_create (system, cfg_new))
141 { 130 {
142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
143 "Could not create another configuration\n"); 132 "Creating configuration no. %u \n",
144 GNUNET_CONFIGURATION_destroy (cfg_new); 133 cur);
145 fail = GNUNET_YES; 134 if (create_cfg_template != NULL)
146 break; 135 GNUNET_asprintf(&cur_file, "%04u-%s", cur, create_cfg_template);
136 else
137 GNUNET_asprintf(&cur_file, "%04u%s", cur, ".conf");
138
139 cfg_new = GNUNET_CONFIGURATION_dup(cfg_tmpl);
140 if (GNUNET_OK != GNUNET_TESTING_configuration_create(system, cfg_new))
141 {
142 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
143 "Could not create another configuration\n");
144 GNUNET_CONFIGURATION_destroy(cfg_new);
145 fail = GNUNET_YES;
146 break;
147 }
148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
149 "Writing configuration no. %u to file `%s' \n",
150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg_new, cur_file))
153 {
154 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
157 fail = GNUNET_YES;
158 }
159 GNUNET_CONFIGURATION_destroy(cfg_new);
160 GNUNET_free(cur_file);
161 if (GNUNET_YES == fail)
162 break;
147 } 163 }
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 164 GNUNET_CONFIGURATION_destroy(cfg_tmpl);
149 "Writing configuration no. %u to file `%s' \n", 165 GNUNET_TESTING_system_destroy(system, GNUNET_NO);
150 cur,
151 cur_file);
152 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg_new, cur_file))
153 {
154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
155 "Failed to write configuration no. %u \n",
156 cur);
157 fail = GNUNET_YES;
158 }
159 GNUNET_CONFIGURATION_destroy (cfg_new);
160 GNUNET_free (cur_file);
161 if (GNUNET_YES == fail)
162 break;
163 }
164 GNUNET_CONFIGURATION_destroy (cfg_tmpl);
165 GNUNET_TESTING_system_destroy (system, GNUNET_NO);
166 if (GNUNET_YES == fail) 166 if (GNUNET_YES == fail)
167 return 1; 167 return 1;
168 return 0; 168 return 0;
@@ -170,40 +170,40 @@ create_unique_cfgs (const char *template, const unsigned int no)
170 170
171 171
172static int 172static int
173create_hostkeys (const unsigned int no) 173create_hostkeys(const unsigned int no)
174{ 174{
175 struct GNUNET_TESTING_System *system; 175 struct GNUNET_TESTING_System *system;
176 struct GNUNET_PeerIdentity id; 176 struct GNUNET_PeerIdentity id;
177 struct GNUNET_DISK_FileHandle *fd; 177 struct GNUNET_DISK_FileHandle *fd;
178 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 178 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
179 179
180 system = GNUNET_TESTING_system_create ("testing", NULL, NULL, NULL); 180 system = GNUNET_TESTING_system_create("testing", NULL, NULL, NULL);
181 pk = GNUNET_TESTING_hostkey_get (system, create_no, &id); 181 pk = GNUNET_TESTING_hostkey_get(system, create_no, &id);
182 if (NULL == pk) 182 if (NULL == pk)
183 { 183 {
184 fprintf (stderr, 184 fprintf(stderr,
185 _ ("Could not extract hostkey %u (offset too large?)\n"), 185 _("Could not extract hostkey %u (offset too large?)\n"),
186 create_no); 186 create_no);
187 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 187 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
188 return 1; 188 return 1;
189 } 189 }
190 (void) GNUNET_DISK_directory_create_for_file (create_hostkey); 190 (void)GNUNET_DISK_directory_create_for_file(create_hostkey);
191 fd = 191 fd =
192 GNUNET_DISK_file_open (create_hostkey, 192 GNUNET_DISK_file_open(create_hostkey,
193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, 193 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
194 GNUNET_DISK_PERM_USER_READ | 194 GNUNET_DISK_PERM_USER_READ |
195 GNUNET_DISK_PERM_USER_WRITE); 195 GNUNET_DISK_PERM_USER_WRITE);
196 GNUNET_assert (fd != NULL); 196 GNUNET_assert(fd != NULL);
197 ret = GNUNET_DISK_file_write (fd, 197 ret = GNUNET_DISK_file_write(fd,
198 pk, 198 pk,
199 sizeof (struct GNUNET_CRYPTO_EddsaPrivateKey)); 199 sizeof(struct GNUNET_CRYPTO_EddsaPrivateKey));
200 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 200 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fd));
201 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,
202 "transport-testing", 202 "transport-testing",
203 "Wrote hostkey to file: `%s'\n", 203 "Wrote hostkey to file: `%s'\n",
204 create_hostkey); 204 create_hostkey);
205 GNUNET_free (pk); 205 GNUNET_free(pk);
206 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 206 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
207 return 0; 207 return 0;
208} 208}
209 209
@@ -215,25 +215,25 @@ create_hostkeys (const unsigned int no)
215 * @param cls unused 215 * @param cls unused
216 */ 216 */
217static void 217static void
218cleanup (void *cls) 218cleanup(void *cls)
219{ 219{
220 if (NULL != tmpfilename) 220 if (NULL != tmpfilename)
221 { 221 {
222 if (0 != unlink (tmpfilename)) 222 if (0 != unlink(tmpfilename))
223 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 223 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING,
224 "unlink", 224 "unlink",
225 tmpfilename); 225 tmpfilename);
226 } 226 }
227 if (NULL != tid) 227 if (NULL != tid)
228 { 228 {
229 GNUNET_SCHEDULER_cancel (tid); 229 GNUNET_SCHEDULER_cancel(tid);
230 tid = NULL; 230 tid = NULL;
231 } 231 }
232 if (NULL != fh) 232 if (NULL != fh)
233 { 233 {
234 GNUNET_DISK_file_close (fh); 234 GNUNET_DISK_file_close(fh);
235 fh = NULL; 235 fh = NULL;
236 } 236 }
237} 237}
238 238
239 239
@@ -243,39 +243,42 @@ cleanup (void *cls)
243 * @param cls unused 243 * @param cls unused
244 */ 244 */
245static void 245static void
246stdin_cb (void *cls) 246stdin_cb(void *cls)
247{ 247{
248 int c; 248 int c;
249 249
250 tid = NULL; 250 tid = NULL;
251 c = getchar (); 251 c = getchar();
252 switch (c) 252 switch (c)
253 { 253 {
254 case EOF: 254 case EOF:
255 case 'q': 255 case 'q':
256 GNUNET_SCHEDULER_shutdown (); 256 GNUNET_SCHEDULER_shutdown();
257 return; 257 return;
258 case 'r': 258
259 if (GNUNET_OK != GNUNET_TESTING_peer_stop (my_peer)) 259 case 'r':
260 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n"); 260 if (GNUNET_OK != GNUNET_TESTING_peer_stop(my_peer))
261 if (GNUNET_OK != GNUNET_TESTING_peer_start (my_peer)) 261 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to stop the peer\n");
262 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n"); 262 if (GNUNET_OK != GNUNET_TESTING_peer_start(my_peer))
263 printf ("restarted\n"); 263 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed to start the peer\n");
264 fflush (stdout); 264 printf("restarted\n");
265 break; 265 fflush(stdout);
266 case '\n': 266 break;
267 case '\r': 267
268 /* ignore whitespace */ 268 case '\n':
269 break; 269 case '\r':
270 default: 270 /* ignore whitespace */
271 fprintf (stderr, 271 break;
272 _ ("Unknown command, use 'q' to quit or 'r' to restart peer\n")); 272
273 break; 273 default:
274 } 274 fprintf(stderr,
275 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 275 _("Unknown command, use 'q' to quit or 'r' to restart peer\n"));
276 fh, 276 break;
277 &stdin_cb, 277 }
278 NULL); 278 tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL,
279 fh,
280 &stdin_cb,
281 NULL);
279} 282}
280 283
281 284
@@ -288,32 +291,32 @@ stdin_cb (void *cls)
288 * @param peer handle to the peer 291 * @param peer handle to the peer
289 */ 292 */
290static void 293static void
291testing_main (void *cls, 294testing_main(void *cls,
292 const struct GNUNET_CONFIGURATION_Handle *cfg, 295 const struct GNUNET_CONFIGURATION_Handle *cfg,
293 struct GNUNET_TESTING_Peer *peer) 296 struct GNUNET_TESTING_Peer *peer)
294{ 297{
295 my_peer = peer; 298 my_peer = peer;
296 if (NULL == (tmpfilename = GNUNET_DISK_mktemp ("gnunet-testing"))) 299 if (NULL == (tmpfilename = GNUNET_DISK_mktemp("gnunet-testing")))
297 { 300 {
298 GNUNET_break (0); 301 GNUNET_break(0);
299 GNUNET_SCHEDULER_shutdown (); 302 GNUNET_SCHEDULER_shutdown();
300 return; 303 return;
301 } 304 }
302 if (GNUNET_SYSERR == 305 if (GNUNET_SYSERR ==
303 GNUNET_CONFIGURATION_write ((struct GNUNET_CONFIGURATION_Handle *) cfg, 306 GNUNET_CONFIGURATION_write((struct GNUNET_CONFIGURATION_Handle *)cfg,
304 tmpfilename)) 307 tmpfilename))
305 { 308 {
306 GNUNET_break (0); 309 GNUNET_break(0);
307 return; 310 return;
308 } 311 }
309 printf ("ok\n%s\n", tmpfilename); 312 printf("ok\n%s\n", tmpfilename);
310 fflush (stdout); 313 fflush(stdout);
311 GNUNET_SCHEDULER_add_shutdown (&cleanup, NULL); 314 GNUNET_SCHEDULER_add_shutdown(&cleanup, NULL);
312 fh = GNUNET_DISK_get_handle_from_native (stdin); 315 fh = GNUNET_DISK_get_handle_from_native(stdin);
313 tid = GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 316 tid = GNUNET_SCHEDULER_add_read_file(GNUNET_TIME_UNIT_FOREVER_REL,
314 fh, 317 fh,
315 &stdin_cb, 318 &stdin_cb,
316 NULL); 319 NULL);
317} 320}
318 321
319 322
@@ -326,43 +329,43 @@ testing_main (void *cls,
326 * @param cfg configuration 329 * @param cfg configuration
327 */ 330 */
328static void 331static void
329run_no_scheduler (void *cls, 332run_no_scheduler(void *cls,
330 char *const *args, 333 char *const *args,
331 const char *cfgfile, 334 const char *cfgfile,
332 const struct GNUNET_CONFIGURATION_Handle *cfg) 335 const struct GNUNET_CONFIGURATION_Handle *cfg)
333{ 336{
334 if (NULL != run_service_name) 337 if (NULL != run_service_name)
335 { 338 {
336 ret = GNUNET_TESTING_service_run ("gnunet_service_test", 339 ret = GNUNET_TESTING_service_run("gnunet_service_test",
337 run_service_name, 340 run_service_name,
338 cfgfile, 341 cfgfile,
339 &testing_main, 342 &testing_main,
340 NULL); 343 NULL);
341 return; 344 return;
342 } 345 }
343 346
344 if (GNUNET_YES == create_cfg) 347 if (GNUNET_YES == create_cfg)
345 {
346 if (create_no > 0)
347 { 348 {
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 349 if (create_no > 0)
349 "Creating %u configuration files based on template `%s'\n", 350 {
350 create_no, 351 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
351 create_cfg_template); 352 "Creating %u configuration files based on template `%s'\n",
352 ret = create_unique_cfgs (create_cfg_template, create_no); 353 create_no,
354 create_cfg_template);
355 ret = create_unique_cfgs(create_cfg_template, create_no);
356 }
357 else
358 {
359 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n");
360 ret = 1;
361 }
353 } 362 }
354 else 363 if (NULL != create_hostkey)
355 { 364 {
356 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Missing arguments! \n"); 365 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no);
357 ret = 1; 366 ret = create_hostkeys(create_no);
358 } 367 }
359 } 368 GNUNET_free_non_null(create_cfg_template);
360 if (NULL != create_hostkey)
361 {
362 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Extracting hostkey %u\n", create_no);
363 ret = create_hostkeys (create_no);
364 }
365 GNUNET_free_non_null (create_cfg_template);
366} 369}
367 370
368 371
@@ -374,45 +377,46 @@ run_no_scheduler (void *cls,
374 * @return 0 ok, 1 on error 377 * @return 0 ok, 1 on error
375 */ 378 */
376int 379int
377main (int argc, char *const *argv) 380main(int argc, char *const *argv)
378{ 381{
379 struct GNUNET_GETOPT_CommandLineOption options[] = 382 struct GNUNET_GETOPT_CommandLineOption options[] =
380 {GNUNET_GETOPT_option_flag ('C', 383 { GNUNET_GETOPT_option_flag('C',
381 "cfg", 384 "cfg",
382 gettext_noop ( 385 gettext_noop(
383 "create unique configuration files"), 386 "create unique configuration files"),
384 &create_cfg), 387 &create_cfg),
385 GNUNET_GETOPT_option_string ( 388 GNUNET_GETOPT_option_string(
386 'k', 389 'k',
387 "key", 390 "key",
388 "FILENAME", 391 "FILENAME",
389 gettext_noop ("extract hostkey file from pre-computed hostkey list"), 392 gettext_noop("extract hostkey file from pre-computed hostkey list"),
390 &create_hostkey), 393 &create_hostkey),
391 394
392 GNUNET_GETOPT_option_uint ( 395 GNUNET_GETOPT_option_uint(
393 'n', 396 'n',
394 "number", 397 "number",
395 "NUMBER", 398 "NUMBER",
396 gettext_noop ( 399 gettext_noop(
397 "number of unique configuration files to create, or number of the hostkey to extract"), 400 "number of unique configuration files to create, or number of the hostkey to extract"),
398 &create_no), 401 &create_no),
399 402
400 403
401 GNUNET_GETOPT_option_string ('t', 404 GNUNET_GETOPT_option_string('t',
402 "template", 405 "template",
403 "FILENAME", 406 "FILENAME",
404 gettext_noop ("configuration template"), 407 gettext_noop("configuration template"),
405 &create_cfg_template), 408 &create_cfg_template),
406 409
407 GNUNET_GETOPT_option_string ( 410 GNUNET_GETOPT_option_string(
408 'r', 411 'r',
409 "run", 412 "run",
410 "SERVICE", 413 "SERVICE",
411 gettext_noop ( 414 gettext_noop(
412 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"), 415 "run the given service, wait on stdin for 'r' (restart) or 'q' (quit)"),
413 &run_service_name), 416 &run_service_name),
414 GNUNET_GETOPT_OPTION_END}; 417 GNUNET_GETOPT_OPTION_END };
415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 418
419 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
416 return 2; 420 return 2;
417 421
418 /* Run without scheduler, because we may want to call 422 /* Run without scheduler, because we may want to call
@@ -421,18 +425,18 @@ main (int argc, char *const *argv)
421 * but beware when extending gnunet-testing. */ 425 * but beware when extending gnunet-testing. */
422 ret = 426 ret =
423 (GNUNET_OK == 427 (GNUNET_OK ==
424 GNUNET_PROGRAM_run2 (argc, 428 GNUNET_PROGRAM_run2(argc,
425 argv, 429 argv,
426 "gnunet-testing", 430 "gnunet-testing",
427 gettext_noop ( 431 gettext_noop(
428 "Command line tool to access the testing library"), 432 "Command line tool to access the testing library"),
429 options, 433 options,
430 &run_no_scheduler, 434 &run_no_scheduler,
431 NULL, 435 NULL,
432 GNUNET_YES)) 436 GNUNET_YES))
433 ? ret 437 ? ret
434 : 1; 438 : 1;
435 GNUNET_free ((void *) argv); 439 GNUNET_free((void *)argv);
436 return ret; 440 return ret;
437} 441}
438 442
diff --git a/src/testing/list-keys.c b/src/testing/list-keys.c
index 39a48d071..37b880b49 100644
--- a/src/testing/list-keys.c
+++ b/src/testing/list-keys.c
@@ -15,10 +15,10 @@ static int result;
15 * @param cfg the configuration file handle 15 * @param cfg the configuration file handle
16 */ 16 */
17static void 17static void
18run (void *cls, 18run(void *cls,
19 char *const *args, 19 char *const *args,
20 const char *cfgfile, 20 const char *cfgfile,
21 const struct GNUNET_CONFIGURATION_Handle *config) 21 const struct GNUNET_CONFIGURATION_Handle *config)
22{ 22{
23 char *idfile; 23 char *idfile;
24 struct GNUNET_DISK_FileHandle *f; 24 struct GNUNET_DISK_FileHandle *f;
@@ -31,79 +31,79 @@ run (void *cls,
31 unsigned int nmax; 31 unsigned int nmax;
32 32
33 if ((NULL == args) || (NULL == args[0])) 33 if ((NULL == args) || (NULL == args[0]))
34 { 34 {
35 fprintf (stderr, "Need the hostkey file\n"); 35 fprintf(stderr, "Need the hostkey file\n");
36 return; 36 return;
37 } 37 }
38 idfile = args[0]; 38 idfile = args[0];
39 if (GNUNET_OK != 39 if (GNUNET_OK !=
40 GNUNET_DISK_file_size (idfile, &fsize, GNUNET_YES, GNUNET_YES)) 40 GNUNET_DISK_file_size(idfile, &fsize, GNUNET_YES, GNUNET_YES))
41 { 41 {
42 GNUNET_break (0); 42 GNUNET_break(0);
43 return; 43 return;
44 } 44 }
45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE)) 45 if (0 != (fsize % GNUNET_TESTING_HOSTKEYFILESIZE))
46 { 46 {
47 fprintf (stderr, _ ("Incorrect hostkey file format: %s\n"), idfile); 47 fprintf(stderr, _("Incorrect hostkey file format: %s\n"), idfile);
48 return; 48 return;
49 } 49 }
50 f = GNUNET_DISK_file_open (idfile, 50 f = GNUNET_DISK_file_open(idfile,
51 GNUNET_DISK_OPEN_READ, 51 GNUNET_DISK_OPEN_READ,
52 GNUNET_DISK_PERM_NONE); 52 GNUNET_DISK_PERM_NONE);
53 if (NULL == f) 53 if (NULL == f)
54 { 54 {
55 GNUNET_break (0); 55 GNUNET_break(0);
56 return; 56 return;
57 } 57 }
58 data = GNUNET_DISK_file_map (f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize); 58 data = GNUNET_DISK_file_map(f, &map, GNUNET_DISK_MAP_TYPE_READ, fsize);
59 if (NULL == data) 59 if (NULL == data)
60 { 60 {
61 GNUNET_break (0); 61 GNUNET_break(0);
62 GNUNET_DISK_file_close (f); 62 GNUNET_DISK_file_close(f);
63 return; 63 return;
64 } 64 }
65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE; 65 nmax = fsize / GNUNET_TESTING_HOSTKEYFILESIZE;
66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++) 66 for (cnt = nskip; cnt < (nskip + nkeys); cnt++)
67 {
68 if (nskip + cnt >= nmax)
69 { 67 {
70 printf ("Max keys %u reached\n", nmax); 68 if (nskip + cnt >= nmax)
71 break; 69 {
70 printf("Max keys %u reached\n", nmax);
71 break;
72 }
73 GNUNET_memcpy(&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public(&pkey, &id.public_key);
77 printf("Key %u: %s\n", cnt, GNUNET_i2s_full(&id));
72 } 78 }
73 GNUNET_memcpy (&pkey,
74 data + (cnt * GNUNET_TESTING_HOSTKEYFILESIZE),
75 GNUNET_TESTING_HOSTKEYFILESIZE);
76 GNUNET_CRYPTO_eddsa_key_get_public (&pkey, &id.public_key);
77 printf ("Key %u: %s\n", cnt, GNUNET_i2s_full (&id));
78 }
79 result = GNUNET_OK; 79 result = GNUNET_OK;
80 GNUNET_DISK_file_unmap (map); 80 GNUNET_DISK_file_unmap(map);
81 GNUNET_DISK_file_close (f); 81 GNUNET_DISK_file_close(f);
82} 82}
83 83
84 84
85int 85int
86main (int argc, char *argv[]) 86main(int argc, char *argv[])
87{ 87{
88 struct GNUNET_GETOPT_CommandLineOption option[] = 88 struct GNUNET_GETOPT_CommandLineOption option[] =
89 {GNUNET_GETOPT_option_uint ('n', 89 { GNUNET_GETOPT_option_uint('n',
90 "num-keys", 90 "num-keys",
91 "COUNT", 91 "COUNT",
92 gettext_noop ("list COUNT number of keys"), 92 gettext_noop("list COUNT number of keys"),
93 &nkeys), 93 &nkeys),
94 GNUNET_GETOPT_OPTION_END}; 94 GNUNET_GETOPT_OPTION_END };
95 int ret; 95 int ret;
96 96
97 result = GNUNET_SYSERR; 97 result = GNUNET_SYSERR;
98 nkeys = 10; 98 nkeys = 10;
99 ret = 99 ret =
100 GNUNET_PROGRAM_run (argc, 100 GNUNET_PROGRAM_run(argc,
101 argv, 101 argv,
102 "list-keys", 102 "list-keys",
103 "Lists the peer IDs corresponding to the given keys file\n", 103 "Lists the peer IDs corresponding to the given keys file\n",
104 option, 104 option,
105 &run, 105 &run,
106 NULL); 106 NULL);
107 if (GNUNET_OK != ret) 107 if (GNUNET_OK != ret)
108 return 1; 108 return 1;
109 if (GNUNET_SYSERR == result) 109 if (GNUNET_SYSERR == result)
diff --git a/src/testing/test_testing_peerstartup.c b/src/testing/test_testing_peerstartup.c
index 241bc63a7..a03e6b596 100644
--- a/src/testing/test_testing_peerstartup.c
+++ b/src/testing/test_testing_peerstartup.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -29,8 +29,8 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind,...) \ 32#define LOG(kind, ...) \
33 GNUNET_log (kind, __VA_ARGS__) 33 GNUNET_log(kind, __VA_ARGS__)
34 34
35/** 35/**
36 * The status of the test 36 * The status of the test
@@ -40,8 +40,7 @@ int status;
40/** 40/**
41 * The testing context 41 * The testing context
42 */ 42 */
43struct TestingContext 43struct TestingContext {
44{
45 /** 44 /**
46 * The testing system 45 * The testing system
47 */ 46 */
@@ -65,21 +64,21 @@ struct TestingContext
65 * @param cls the testing context 64 * @param cls the testing context
66 */ 65 */
67static void 66static void
68do_shutdown (void *cls) 67do_shutdown(void *cls)
69{ 68{
70 struct TestingContext *test_ctx = cls; 69 struct TestingContext *test_ctx = cls;
71 70
72 GNUNET_assert (NULL != test_ctx); 71 GNUNET_assert(NULL != test_ctx);
73 if (NULL != test_ctx->peer) 72 if (NULL != test_ctx->peer)
74 { 73 {
75 (void) GNUNET_TESTING_peer_stop (test_ctx->peer); 74 (void)GNUNET_TESTING_peer_stop(test_ctx->peer);
76 GNUNET_TESTING_peer_destroy (test_ctx->peer); 75 GNUNET_TESTING_peer_destroy(test_ctx->peer);
77 } 76 }
78 if (NULL != test_ctx->cfg) 77 if (NULL != test_ctx->cfg)
79 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 78 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
80 if (NULL != test_ctx->system) 79 if (NULL != test_ctx->system)
81 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 80 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
82 GNUNET_free (test_ctx); 81 GNUNET_free(test_ctx);
83} 82}
84 83
85 84
@@ -87,42 +86,42 @@ do_shutdown (void *cls)
87 * Main point of test execution 86 * Main point of test execution
88 */ 87 */
89static void 88static void
90run (void *cls, char *const *args, const char *cfgfile, 89run(void *cls, char *const *args, const char *cfgfile,
91 const struct GNUNET_CONFIGURATION_Handle *cfg) 90 const struct GNUNET_CONFIGURATION_Handle *cfg)
92{ 91{
93 struct TestingContext *test_ctx; 92 struct TestingContext *test_ctx;
94 char *emsg; 93 char *emsg;
95 struct GNUNET_PeerIdentity id; 94 struct GNUNET_PeerIdentity id;
96 95
97 test_ctx = GNUNET_new (struct TestingContext); 96 test_ctx = GNUNET_new(struct TestingContext);
98 test_ctx->system = 97 test_ctx->system =
99 GNUNET_TESTING_system_create ("test-gnunet-testing", 98 GNUNET_TESTING_system_create("test-gnunet-testing",
100 "127.0.0.1", NULL, NULL); 99 "127.0.0.1", NULL, NULL);
101 emsg = NULL; 100 emsg = NULL;
102 if (NULL == test_ctx->system) 101 if (NULL == test_ctx->system)
103 goto end; 102 goto end;
104 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 103 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
105 test_ctx->peer = 104 test_ctx->peer =
106 GNUNET_TESTING_peer_configure (test_ctx->system, 105 GNUNET_TESTING_peer_configure(test_ctx->system,
107 test_ctx->cfg, 106 test_ctx->cfg,
108 0, &id, &emsg); 107 0, &id, &emsg);
109 if (NULL == test_ctx->peer) 108 if (NULL == test_ctx->peer)
110 { 109 {
111 if (NULL != emsg) 110 if (NULL != emsg)
112 printf ("Test failed upon error: %s", emsg); 111 printf("Test failed upon error: %s", emsg);
113 goto end; 112 goto end;
114 } 113 }
115 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) 114 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer))
116 goto end; 115 goto end;
117 status = GNUNET_OK; 116 status = GNUNET_OK;
118 117
119 end: 118end:
120 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 119 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
121 GNUNET_free_non_null (emsg); 120 GNUNET_free_non_null(emsg);
122} 121}
123 122
124 123
125int main (int argc, char *argv[]) 124int main(int argc, char *argv[])
126{ 125{
127 struct GNUNET_GETOPT_CommandLineOption options[] = { 126 struct GNUNET_GETOPT_CommandLineOption options[] = {
128 GNUNET_GETOPT_OPTION_END 127 GNUNET_GETOPT_OPTION_END
@@ -130,10 +129,10 @@ int main (int argc, char *argv[])
130 129
131 status = GNUNET_SYSERR; 130 status = GNUNET_SYSERR;
132 if (GNUNET_OK != 131 if (GNUNET_OK !=
133 GNUNET_PROGRAM_run (argc, argv, 132 GNUNET_PROGRAM_run(argc, argv,
134 "test_testing_peerstartup", 133 "test_testing_peerstartup",
135 "test case for peerstartup using new testing library", 134 "test case for peerstartup using new testing library",
136 options, &run, NULL)) 135 options, &run, NULL))
137 return 1; 136 return 1;
138 return (GNUNET_OK == status) ? 0 : 1; 137 return (GNUNET_OK == status) ? 0 : 1;
139} 138}
diff --git a/src/testing/test_testing_peerstartup2.c b/src/testing/test_testing_peerstartup2.c
index a077ddcc2..80a3b719a 100644
--- a/src/testing/test_testing_peerstartup2.c
+++ b/src/testing/test_testing_peerstartup2.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -29,19 +29,19 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind,...) \ 32#define LOG(kind, ...) \
33 GNUNET_log (kind, __VA_ARGS__) 33 GNUNET_log(kind, __VA_ARGS__)
34 34
35 35
36#define FAIL_TEST(cond) \ 36#define FAIL_TEST(cond) \
37 do { \ 37 do { \
38 if (!(cond)) { \ 38 if (!(cond)) { \
39 GNUNET_break (0); \ 39 GNUNET_break(0); \
40 if (GNUNET_OK == status) { \ 40 if (GNUNET_OK == status) { \
41 status = GNUNET_SYSERR; \ 41 status = GNUNET_SYSERR; \
42 } \ 42 } \
43 } \ 43 } \
44 } while (0) \ 44 } while (0) \
45 45
46 46
47/** 47/**
@@ -52,8 +52,7 @@ int status;
52/** 52/**
53 * The testing context 53 * The testing context
54 */ 54 */
55struct TestingContext 55struct TestingContext {
56{
57 /** 56 /**
58 * The testing system 57 * The testing system
59 */ 58 */
@@ -83,18 +82,17 @@ struct TestingContext
83 82
84 83
85static void 84static void
86do_shutdown2 (void *cls) 85do_shutdown2(void *cls)
87{ 86{
88 struct TestingContext *test_ctx = cls; 87 struct TestingContext *test_ctx = cls;
89 88
90 if (NULL != test_ctx->peer) 89 if (NULL != test_ctx->peer)
91 GNUNET_TESTING_peer_destroy (test_ctx->peer); 90 GNUNET_TESTING_peer_destroy(test_ctx->peer);
92 if (NULL != test_ctx->cfg) 91 if (NULL != test_ctx->cfg)
93 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 92 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
94 if (NULL != test_ctx->system) 93 if (NULL != test_ctx->system)
95 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 94 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
96 GNUNET_free (test_ctx); 95 GNUNET_free(test_ctx);
97
98} 96}
99 97
100 98
@@ -104,27 +102,29 @@ do_shutdown2 (void *cls)
104 * @param cls the testing context 102 * @param cls the testing context
105 */ 103 */
106static void 104static void
107do_shutdown (void *cls); 105do_shutdown(void *cls);
108 106
109 107
110static void 108static void
111peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success) 109peer_status_cb(void *cls, struct GNUNET_TESTING_Peer *peer, int success)
112{ 110{
113 struct TestingContext *test_ctx = cls; 111 struct TestingContext *test_ctx = cls;
114 112
115 switch (test_ctx->state) 113 switch (test_ctx->state)
116 { 114 {
117 case PEER_INIT: 115 case PEER_INIT:
118 FAIL_TEST (0); 116 FAIL_TEST(0);
119 break; 117 break;
120 case PEER_STARTED: 118
121 FAIL_TEST (GNUNET_YES == success); 119 case PEER_STARTED:
122 test_ctx->state = PEER_STOPPED; 120 FAIL_TEST(GNUNET_YES == success);
123 GNUNET_SCHEDULER_add_now (&do_shutdown2, cls); 121 test_ctx->state = PEER_STOPPED;
124 break; 122 GNUNET_SCHEDULER_add_now(&do_shutdown2, cls);
125 case PEER_STOPPED: 123 break;
126 FAIL_TEST (0); 124
127 } 125 case PEER_STOPPED:
126 FAIL_TEST(0);
127 }
128} 128}
129 129
130 130
@@ -134,20 +134,20 @@ peer_status_cb (void *cls, struct GNUNET_TESTING_Peer *peer, int success)
134 * @param cls the testing context 134 * @param cls the testing context
135 */ 135 */
136static void 136static void
137do_shutdown (void *cls) 137do_shutdown(void *cls)
138{ 138{
139 struct TestingContext *test_ctx = cls; 139 struct TestingContext *test_ctx = cls;
140 140
141 GNUNET_assert (NULL != test_ctx); 141 GNUNET_assert(NULL != test_ctx);
142 if (NULL != test_ctx->peer) 142 if (NULL != test_ctx->peer)
143 { 143 {
144 FAIL_TEST (GNUNET_OK == 144 FAIL_TEST(GNUNET_OK ==
145 GNUNET_TESTING_peer_stop_async (test_ctx->peer, 145 GNUNET_TESTING_peer_stop_async(test_ctx->peer,
146 &peer_status_cb, 146 &peer_status_cb,
147 test_ctx)); 147 test_ctx));
148 } 148 }
149 else 149 else
150 do_shutdown2 (test_ctx); 150 do_shutdown2(test_ctx);
151} 151}
152 152
153 153
@@ -155,51 +155,51 @@ do_shutdown (void *cls)
155 * Main point of test execution 155 * Main point of test execution
156 */ 156 */
157static void 157static void
158run (void *cls, char *const *args, const char *cfgfile, 158run(void *cls, char *const *args, const char *cfgfile,
159 const struct GNUNET_CONFIGURATION_Handle *cfg) 159 const struct GNUNET_CONFIGURATION_Handle *cfg)
160{ 160{
161 struct TestingContext *test_ctx; 161 struct TestingContext *test_ctx;
162 char *emsg; 162 char *emsg;
163 struct GNUNET_PeerIdentity id; 163 struct GNUNET_PeerIdentity id;
164 164
165 test_ctx = GNUNET_new (struct TestingContext); 165 test_ctx = GNUNET_new(struct TestingContext);
166 test_ctx->system = 166 test_ctx->system =
167 GNUNET_TESTING_system_create ("test-gnunet-testing", 167 GNUNET_TESTING_system_create("test-gnunet-testing",
168 "127.0.0.1", NULL, NULL); 168 "127.0.0.1", NULL, NULL);
169 emsg = NULL; 169 emsg = NULL;
170 if (NULL == test_ctx->system) 170 if (NULL == test_ctx->system)
171 goto end; 171 goto end;
172 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 172 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
173 test_ctx->peer = 173 test_ctx->peer =
174 GNUNET_TESTING_peer_configure (test_ctx->system, 174 GNUNET_TESTING_peer_configure(test_ctx->system,
175 test_ctx->cfg, 175 test_ctx->cfg,
176 0, &id, &emsg); 176 0, &id, &emsg);
177 if (NULL == test_ctx->peer) 177 if (NULL == test_ctx->peer)
178 { 178 {
179 if (NULL != emsg) 179 if (NULL != emsg)
180 printf ("Test failed upon error: %s", emsg); 180 printf("Test failed upon error: %s", emsg);
181 goto end; 181 goto end;
182 } 182 }
183 if (GNUNET_OK != GNUNET_TESTING_peer_start (test_ctx->peer)) 183 if (GNUNET_OK != GNUNET_TESTING_peer_start(test_ctx->peer))
184 goto end; 184 goto end;
185 test_ctx->state = PEER_STARTED; 185 test_ctx->state = PEER_STARTED;
186 FAIL_TEST (GNUNET_OK == 186 FAIL_TEST(GNUNET_OK ==
187 GNUNET_TESTING_peer_stop_async (test_ctx->peer, 187 GNUNET_TESTING_peer_stop_async(test_ctx->peer,
188 &peer_status_cb, 188 &peer_status_cb,
189 test_ctx)); 189 test_ctx));
190 GNUNET_TESTING_peer_stop_async_cancel (test_ctx->peer); 190 GNUNET_TESTING_peer_stop_async_cancel(test_ctx->peer);
191 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 191 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
192 &do_shutdown, test_ctx); 192 &do_shutdown, test_ctx);
193 return; 193 return;
194 194
195 end: 195end:
196 FAIL_TEST (0); 196 FAIL_TEST(0);
197 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 197 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
198 GNUNET_free_non_null (emsg); 198 GNUNET_free_non_null(emsg);
199} 199}
200 200
201 201
202int main (int argc, char *argv[]) 202int main(int argc, char *argv[])
203{ 203{
204 struct GNUNET_GETOPT_CommandLineOption options[] = { 204 struct GNUNET_GETOPT_CommandLineOption options[] = {
205 GNUNET_GETOPT_OPTION_END 205 GNUNET_GETOPT_OPTION_END
@@ -207,10 +207,10 @@ int main (int argc, char *argv[])
207 207
208 status = GNUNET_OK; 208 status = GNUNET_OK;
209 if (GNUNET_OK != 209 if (GNUNET_OK !=
210 GNUNET_PROGRAM_run (argc, argv, 210 GNUNET_PROGRAM_run(argc, argv,
211 "test_testing_new_peerstartup", 211 "test_testing_new_peerstartup",
212 "test case for peerstartup using new testing library", 212 "test case for peerstartup using new testing library",
213 options, &run, NULL)) 213 options, &run, NULL))
214 return 1; 214 return 1;
215 return (GNUNET_OK == status) ? 0 : 1; 215 return (GNUNET_OK == status) ? 0 : 1;
216} 216}
diff --git a/src/testing/test_testing_portreservation.c b/src/testing/test_testing_portreservation.c
index 86ecc494a..308d462b7 100644
--- a/src/testing/test_testing_portreservation.c
+++ b/src/testing/test_testing_portreservation.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -29,8 +29,8 @@
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
31 31
32#define LOG(kind,...) \ 32#define LOG(kind, ...) \
33 GNUNET_log (kind, __VA_ARGS__) 33 GNUNET_log(kind, __VA_ARGS__)
34 34
35/** 35/**
36 * The status of the test 36 * The status of the test
@@ -41,46 +41,46 @@ int status;
41 * Main point of test execution 41 * Main point of test execution
42 */ 42 */
43static void 43static void
44run (void *cls, char *const *args, const char *cfgfile, 44run(void *cls, char *const *args, const char *cfgfile,
45 const struct GNUNET_CONFIGURATION_Handle *cfg) 45 const struct GNUNET_CONFIGURATION_Handle *cfg)
46{ 46{
47 struct GNUNET_TESTING_System *system; 47 struct GNUNET_TESTING_System *system;
48 uint16_t new_port1; 48 uint16_t new_port1;
49 uint16_t new_port2; 49 uint16_t new_port2;
50 uint16_t old_port1; 50 uint16_t old_port1;
51 51
52 system = GNUNET_TESTING_system_create ("/tmp/gnunet-testing-new", 52 system = GNUNET_TESTING_system_create("/tmp/gnunet-testing-new",
53 "localhost", NULL, NULL); 53 "localhost", NULL, NULL);
54 GNUNET_assert (NULL != system); 54 GNUNET_assert(NULL != system);
55 new_port1 = GNUNET_TESTING_reserve_port (system); 55 new_port1 = GNUNET_TESTING_reserve_port(system);
56 LOG (GNUNET_ERROR_TYPE_DEBUG, 56 LOG(GNUNET_ERROR_TYPE_DEBUG,
57 "Reserved TCP port %u\n", new_port1); 57 "Reserved TCP port %u\n", new_port1);
58 if (0 == new_port1) 58 if (0 == new_port1)
59 goto end; 59 goto end;
60 new_port2 = GNUNET_TESTING_reserve_port (system); 60 new_port2 = GNUNET_TESTING_reserve_port(system);
61 LOG (GNUNET_ERROR_TYPE_DEBUG, 61 LOG(GNUNET_ERROR_TYPE_DEBUG,
62 "Reserved TCP port %u\n", new_port2); 62 "Reserved TCP port %u\n", new_port2);
63 if (0 == new_port2) 63 if (0 == new_port2)
64 goto end; 64 goto end;
65 GNUNET_assert (new_port1 != new_port2); 65 GNUNET_assert(new_port1 != new_port2);
66 GNUNET_TESTING_release_port (system, new_port1); 66 GNUNET_TESTING_release_port(system, new_port1);
67 old_port1 = new_port1; 67 old_port1 = new_port1;
68 new_port1 = 0; 68 new_port1 = 0;
69 new_port1 = GNUNET_TESTING_reserve_port (system); 69 new_port1 = GNUNET_TESTING_reserve_port(system);
70 LOG (GNUNET_ERROR_TYPE_DEBUG, 70 LOG(GNUNET_ERROR_TYPE_DEBUG,
71 "Reserved TCP port %u\n", new_port1); 71 "Reserved TCP port %u\n", new_port1);
72 GNUNET_assert (0 != new_port1); 72 GNUNET_assert(0 != new_port1);
73 GNUNET_assert (old_port1 == new_port1); 73 GNUNET_assert(old_port1 == new_port1);
74 GNUNET_TESTING_release_port (system, new_port1); 74 GNUNET_TESTING_release_port(system, new_port1);
75 GNUNET_TESTING_release_port (system, new_port2); 75 GNUNET_TESTING_release_port(system, new_port2);
76 status = GNUNET_OK; 76 status = GNUNET_OK;
77 77
78 end: 78end:
79 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 79 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
80} 80}
81 81
82 82
83int main (int argc, char *argv[]) 83int main(int argc, char *argv[])
84{ 84{
85 struct GNUNET_GETOPT_CommandLineOption options[] = { 85 struct GNUNET_GETOPT_CommandLineOption options[] = {
86 GNUNET_GETOPT_OPTION_END 86 GNUNET_GETOPT_OPTION_END
@@ -88,14 +88,14 @@ int main (int argc, char *argv[])
88 88
89 status = GNUNET_SYSERR; 89 status = GNUNET_SYSERR;
90 if (GNUNET_OK != 90 if (GNUNET_OK !=
91 GNUNET_PROGRAM_run (argc, 91 GNUNET_PROGRAM_run(argc,
92 argv, 92 argv,
93 "test_testing_new_portreservation", 93 "test_testing_new_portreservation",
94 "test case for testing port reservation routines" 94 "test case for testing port reservation routines"
95 " from the new testing library API", 95 " from the new testing library API",
96 options, 96 options,
97 &run, 97 &run,
98 NULL)) 98 NULL))
99 return 1; 99 return 1;
100 return (GNUNET_OK == status) ? 0 : 1; 100 return (GNUNET_OK == status) ? 0 : 1;
101} 101}
diff --git a/src/testing/test_testing_servicestartup.c b/src/testing/test_testing_servicestartup.c
index e0cadfb06..18786ea86 100644
--- a/src/testing/test_testing_servicestartup.c
+++ b/src/testing/test_testing_servicestartup.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -28,8 +28,8 @@
28#include "gnunet_testing_lib.h" 28#include "gnunet_testing_lib.h"
29 29
30 30
31#define LOG(kind,...) \ 31#define LOG(kind, ...) \
32 GNUNET_log (kind, __VA_ARGS__) 32 GNUNET_log(kind, __VA_ARGS__)
33 33
34 34
35/** 35/**
@@ -45,28 +45,28 @@ static int test_success;
45 * @param cfg the configuration with which the current testing service is run 45 * @param cfg the configuration with which the current testing service is run
46 */ 46 */
47static void 47static void
48test_run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, 48test_run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
49 struct GNUNET_TESTING_Peer *peer) 49 struct GNUNET_TESTING_Peer *peer)
50{ 50{
51 GNUNET_assert (NULL == cls); 51 GNUNET_assert(NULL == cls);
52 GNUNET_assert (NULL != cfg); 52 GNUNET_assert(NULL != cfg);
53 LOG (GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n"); 53 LOG(GNUNET_ERROR_TYPE_DEBUG, "Service arm started successfully\n");
54 test_success = GNUNET_YES; 54 test_success = GNUNET_YES;
55 GNUNET_SCHEDULER_shutdown (); 55 GNUNET_SCHEDULER_shutdown();
56} 56}
57 57
58 58
59/** 59/**
60 * The main point of execution 60 * The main point of execution
61 */ 61 */
62int main (int argc, char *argv[]) 62int main(int argc, char *argv[])
63{ 63{
64 test_success = GNUNET_NO; 64 test_success = GNUNET_NO;
65 GNUNET_assert (0 == GNUNET_TESTING_service_run ("test-testing-servicestartup", 65 GNUNET_assert(0 == GNUNET_TESTING_service_run("test-testing-servicestartup",
66 "arm", 66 "arm",
67 "test_testing_defaults.conf", 67 "test_testing_defaults.conf",
68 &test_run, 68 &test_run,
69 NULL)); 69 NULL));
70 return (GNUNET_YES == test_success) ? 0 : 1; 70 return (GNUNET_YES == test_success) ? 0 : 1;
71} 71}
72 72
diff --git a/src/testing/test_testing_sharedservices.c b/src/testing/test_testing_sharedservices.c
index e7d285bb9..86e9f017c 100644
--- a/src/testing/test_testing_sharedservices.c
+++ b/src/testing/test_testing_sharedservices.c
@@ -11,7 +11,7 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
@@ -28,8 +28,8 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31#define LOG(kind,...) \ 31#define LOG(kind, ...) \
32 GNUNET_log (kind, __VA_ARGS__) 32 GNUNET_log(kind, __VA_ARGS__)
33 33
34#define NUM_PEERS 4 34#define NUM_PEERS 4
35 35
@@ -41,8 +41,7 @@ int status;
41/** 41/**
42 * The testing context 42 * The testing context
43 */ 43 */
44struct TestingContext 44struct TestingContext {
45{
46 /** 45 /**
47 * The testing system 46 * The testing system
48 */ 47 */
@@ -66,26 +65,26 @@ struct TestingContext
66 * @param cls the testing context 65 * @param cls the testing context
67 */ 66 */
68static void 67static void
69do_shutdown (void *cls) 68do_shutdown(void *cls)
70{ 69{
71 struct TestingContext *test_ctx = cls; 70 struct TestingContext *test_ctx = cls;
72 struct GNUNET_TESTING_Peer *peer; 71 struct GNUNET_TESTING_Peer *peer;
73 unsigned int cnt; 72 unsigned int cnt;
74 73
75 GNUNET_assert (NULL != test_ctx); 74 GNUNET_assert(NULL != test_ctx);
76 for (cnt = 0; cnt < NUM_PEERS; cnt++) 75 for (cnt = 0; cnt < NUM_PEERS; cnt++)
77 { 76 {
78 peer = test_ctx->peers[cnt]; 77 peer = test_ctx->peers[cnt];
79 if (NULL == peer) 78 if (NULL == peer)
80 continue; 79 continue;
81 (void) GNUNET_TESTING_peer_stop (peer); 80 (void)GNUNET_TESTING_peer_stop(peer);
82 GNUNET_TESTING_peer_destroy (peer); 81 GNUNET_TESTING_peer_destroy(peer);
83 } 82 }
84 if (NULL != test_ctx->cfg) 83 if (NULL != test_ctx->cfg)
85 GNUNET_CONFIGURATION_destroy (test_ctx->cfg); 84 GNUNET_CONFIGURATION_destroy(test_ctx->cfg);
86 if (NULL != test_ctx->system) 85 if (NULL != test_ctx->system)
87 GNUNET_TESTING_system_destroy (test_ctx->system, GNUNET_YES); 86 GNUNET_TESTING_system_destroy(test_ctx->system, GNUNET_YES);
88 GNUNET_free (test_ctx); 87 GNUNET_free(test_ctx);
89} 88}
90 89
91 90
@@ -93,72 +92,71 @@ do_shutdown (void *cls)
93 * Main point of test execution 92 * Main point of test execution
94 */ 93 */
95static void 94static void
96run (void *cls, char *const *args, const char *cfgfile, 95run(void *cls, char *const *args, const char *cfgfile,
97 const struct GNUNET_CONFIGURATION_Handle *cfg) 96 const struct GNUNET_CONFIGURATION_Handle *cfg)
98{ 97{
99 struct TestingContext *test_ctx; 98 struct TestingContext *test_ctx;
100 char *emsg; 99 char *emsg;
101 struct GNUNET_PeerIdentity id; 100 struct GNUNET_PeerIdentity id;
102 struct GNUNET_TESTING_SharedService ss[] = { 101 struct GNUNET_TESTING_SharedService ss[] = {
103 {"peerinfo", cfg, 2}, 102 { "peerinfo", cfg, 2 },
104 {NULL, NULL, 0} 103 { NULL, NULL, 0 }
105 }; 104 };
106 struct GNUNET_TESTING_Peer *peer; 105 struct GNUNET_TESTING_Peer *peer;
107 unsigned int cnt; 106 unsigned int cnt;
108 107
109 test_ctx = GNUNET_new (struct TestingContext); 108 test_ctx = GNUNET_new(struct TestingContext);
110 test_ctx->system = 109 test_ctx->system =
111 GNUNET_TESTING_system_create ("test-gnunet-testing", 110 GNUNET_TESTING_system_create("test-gnunet-testing",
112 "127.0.0.1", NULL, ss); 111 "127.0.0.1", NULL, ss);
113 emsg = NULL; 112 emsg = NULL;
114 if (NULL == test_ctx->system) 113 if (NULL == test_ctx->system)
115 goto end; 114 goto end;
116 test_ctx->cfg = GNUNET_CONFIGURATION_dup (cfg); 115 test_ctx->cfg = GNUNET_CONFIGURATION_dup(cfg);
117 for (cnt = 0; cnt < NUM_PEERS; cnt++) 116 for (cnt = 0; cnt < NUM_PEERS; cnt++)
118 {
119 peer = GNUNET_TESTING_peer_configure (test_ctx->system,
120 test_ctx->cfg,
121 0, &id, &emsg);
122 if (NULL == peer)
123 { 117 {
124 if (NULL != emsg) 118 peer = GNUNET_TESTING_peer_configure(test_ctx->system,
125 printf ("Test failed upon error: %s", emsg); 119 test_ctx->cfg,
126 goto end; 120 0, &id, &emsg);
121 if (NULL == peer)
122 {
123 if (NULL != emsg)
124 printf("Test failed upon error: %s", emsg);
125 goto end;
126 }
127 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer))
128 {
129 GNUNET_TESTING_peer_destroy(peer);
130 goto end;
131 }
132 test_ctx->peers[cnt] = peer;
127 } 133 }
128 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer))
129 {
130 GNUNET_TESTING_peer_destroy (peer);
131 goto end;
132 }
133 test_ctx->peers[cnt] = peer;
134 }
135 status = GNUNET_OK; 134 status = GNUNET_OK;
136 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 135 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
137 &do_shutdown, test_ctx); 136 &do_shutdown, test_ctx);
138 return; 137 return;
139 138
140 end: 139end:
141 GNUNET_SCHEDULER_add_now (&do_shutdown, test_ctx); 140 GNUNET_SCHEDULER_add_now(&do_shutdown, test_ctx);
142 GNUNET_free_non_null (emsg); 141 GNUNET_free_non_null(emsg);
143} 142}
144 143
145 144
146int main (int argc, char *argv[]) 145int main(int argc, char *argv[])
147{ 146{
148 struct GNUNET_GETOPT_CommandLineOption options[] = { 147 struct GNUNET_GETOPT_CommandLineOption options[] = {
149 GNUNET_GETOPT_OPTION_END 148 GNUNET_GETOPT_OPTION_END
150 }; 149 };
151 char *const argv2[] = { "test_testing_sharedservices", 150 char *const argv2[] = { "test_testing_sharedservices",
152 "-c", "test_testing_sharedservices.conf", 151 "-c", "test_testing_sharedservices.conf",
153 NULL 152 NULL };
154 };
155 153
156 status = GNUNET_SYSERR; 154 status = GNUNET_SYSERR;
157 if (GNUNET_OK != 155 if (GNUNET_OK !=
158 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 156 GNUNET_PROGRAM_run((sizeof(argv2) / sizeof(char *)) - 1, argv2,
159 "test_testing_sharedservices", 157 "test_testing_sharedservices",
160 "test case for testing service sharing among peers started by testing", 158 "test case for testing service sharing among peers started by testing",
161 options, &run, NULL)) 159 options, &run, NULL))
162 return 1; 160 return 1;
163 return (GNUNET_OK == status) ? 0 : 3; 161 return (GNUNET_OK == status) ? 0 : 3;
164} 162}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index c5c240b37..9c5c32012 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,7 +34,7 @@
34#include "gnunet_arm_service.h" 34#include "gnunet_arm_service.h"
35#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
36 36
37#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log_from(kind, "testing-api", __VA_ARGS__)
38 38
39 39
40/** 40/**
@@ -63,8 +63,7 @@
63#define HIGH_PORT 56000 63#define HIGH_PORT 56000
64 64
65 65
66struct SharedServiceInstance 66struct SharedServiceInstance {
67{
68 struct SharedService *ss; 67 struct SharedService *ss;
69 68
70 char *cfg_fn; 69 char *cfg_fn;
@@ -78,8 +77,7 @@ struct SharedServiceInstance
78 unsigned int n_refs; 77 unsigned int n_refs;
79}; 78};
80 79
81struct SharedService 80struct SharedService {
82{
83 char *sname; 81 char *sname;
84 82
85 struct SharedServiceInstance **instances; 83 struct SharedServiceInstance **instances;
@@ -98,8 +96,7 @@ struct SharedService
98 * Handle for a system on which GNUnet peers are executed; 96 * Handle for a system on which GNUnet peers are executed;
99 * a system is used for reserving unique paths and ports. 97 * a system is used for reserving unique paths and ports.
100 */ 98 */
101struct GNUNET_TESTING_System 99struct GNUNET_TESTING_System {
102{
103 /** 100 /**
104 * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each 101 * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each
105 * GNUNET_HOME. 102 * GNUNET_HOME.
@@ -171,8 +168,7 @@ struct GNUNET_TESTING_System
171/** 168/**
172 * Handle for a GNUnet peer controlled by testing. 169 * Handle for a GNUnet peer controlled by testing.
173 */ 170 */
174struct GNUNET_TESTING_Peer 171struct GNUNET_TESTING_Peer {
175{
176 /** 172 /**
177 * The TESTING system associated with this peer 173 * The TESTING system associated with this peer
178 */ 174 */
@@ -253,56 +249,56 @@ struct GNUNET_TESTING_Peer
253 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error 249 * @return #GNUNET_OK on success; #GNUNET_SYSERR on error
254 */ 250 */
255static int 251static int
256hostkeys_load (struct GNUNET_TESTING_System *system) 252hostkeys_load(struct GNUNET_TESTING_System *system)
257{ 253{
258 uint64_t fs; 254 uint64_t fs;
259 char *data_dir; 255 char *data_dir;
260 char *filename; 256 char *filename;
261 struct GNUNET_DISK_FileHandle *fd; 257 struct GNUNET_DISK_FileHandle *fd;
262 258
263 GNUNET_assert (NULL == system->hostkeys_data); 259 GNUNET_assert(NULL == system->hostkeys_data);
264 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); 260 data_dir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR);
265 GNUNET_asprintf (&filename, "%s/testing_hostkeys.ecc", data_dir); 261 GNUNET_asprintf(&filename, "%s/testing_hostkeys.ecc", data_dir);
266 GNUNET_free (data_dir); 262 GNUNET_free(data_dir);
267 263
268 if (GNUNET_YES != GNUNET_DISK_file_test (filename)) 264 if (GNUNET_YES != GNUNET_DISK_file_test(filename))
269 { 265 {
270 LOG (GNUNET_ERROR_TYPE_ERROR, 266 LOG(GNUNET_ERROR_TYPE_ERROR,
271 _ ("Hostkeys file not found: %s\n"), 267 _("Hostkeys file not found: %s\n"),
272 filename); 268 filename);
273 GNUNET_free (filename); 269 GNUNET_free(filename);
274 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
275 } 271 }
276 /* Check hostkey file size, read entire thing into memory */ 272 /* Check hostkey file size, read entire thing into memory */
277 if (GNUNET_OK != 273 if (GNUNET_OK !=
278 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES)) 274 GNUNET_DISK_file_size(filename, &fs, GNUNET_YES, GNUNET_YES))
279 fs = 0; 275 fs = 0;
280 if (0 == fs) 276 if (0 == fs)
281 { 277 {
282 GNUNET_free (filename); 278 GNUNET_free(filename);
283 return GNUNET_SYSERR; /* File is empty */ 279 return GNUNET_SYSERR; /* File is empty */
284 } 280 }
285 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE)) 281 if (0 != (fs % GNUNET_TESTING_HOSTKEYFILESIZE))
286 { 282 {
287 LOG (GNUNET_ERROR_TYPE_ERROR, 283 LOG(GNUNET_ERROR_TYPE_ERROR,
288 _ ("Incorrect hostkey file format: %s\n"), 284 _("Incorrect hostkey file format: %s\n"),
289 filename); 285 filename);
290 GNUNET_free (filename); 286 GNUNET_free(filename);
291 return GNUNET_SYSERR; 287 return GNUNET_SYSERR;
292 } 288 }
293 fd = GNUNET_DISK_file_open (filename, 289 fd = GNUNET_DISK_file_open(filename,
294 GNUNET_DISK_OPEN_READ, 290 GNUNET_DISK_OPEN_READ,
295 GNUNET_DISK_PERM_NONE); 291 GNUNET_DISK_PERM_NONE);
296 if (NULL == fd) 292 if (NULL == fd)
297 { 293 {
298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 294 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "open", filename);
299 GNUNET_free (filename); 295 GNUNET_free(filename);
300 return GNUNET_SYSERR; 296 return GNUNET_SYSERR;
301 } 297 }
302 GNUNET_free (filename); 298 GNUNET_free(filename);
303 system->hostkeys_data = 299 system->hostkeys_data =
304 GNUNET_DISK_file_map (fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs); 300 GNUNET_DISK_file_map(fd, &system->map, GNUNET_DISK_MAP_TYPE_READ, fs);
305 GNUNET_DISK_file_close (fd); 301 GNUNET_DISK_file_close(fd);
306 if (NULL == system->hostkeys_data) 302 if (NULL == system->hostkeys_data)
307 return GNUNET_SYSERR; 303 return GNUNET_SYSERR;
308 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE; 304 system->total_hostkeys = fs / GNUNET_TESTING_HOSTKEYFILESIZE;
@@ -316,11 +312,11 @@ hostkeys_load (struct GNUNET_TESTING_System *system)
316 * @param system the testing system handle 312 * @param system the testing system handle
317 */ 313 */
318static void 314static void
319hostkeys_unload (struct GNUNET_TESTING_System *system) 315hostkeys_unload(struct GNUNET_TESTING_System *system)
320{ 316{
321 GNUNET_break (NULL != system->hostkeys_data); 317 GNUNET_break(NULL != system->hostkeys_data);
322 system->hostkeys_data = NULL; 318 system->hostkeys_data = NULL;
323 GNUNET_DISK_file_unmap (system->map); 319 GNUNET_DISK_file_unmap(system->map);
324 system->map = NULL; 320 system->map = NULL;
325 system->hostkeys_data = NULL; 321 system->hostkeys_data = NULL;
326 system->total_hostkeys = 0; 322 system->total_hostkeys = 0;
@@ -336,14 +332,14 @@ hostkeys_unload (struct GNUNET_TESTING_System *system)
336 * @param value value of the option 332 * @param value value of the option
337 */ 333 */
338static void 334static void
339cfg_copy_iterator (void *cls, 335cfg_copy_iterator(void *cls,
340 const char *section, 336 const char *section,
341 const char *option, 337 const char *option,
342 const char *value) 338 const char *value)
343{ 339{
344 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls; 340 struct GNUNET_CONFIGURATION_Handle *cfg2 = cls;
345 341
346 GNUNET_CONFIGURATION_set_value_string (cfg2, section, option, value); 342 GNUNET_CONFIGURATION_set_value_string(cfg2, section, option, value);
347} 343}
348 344
349 345
@@ -369,7 +365,7 @@ cfg_copy_iterator (void *cls,
369 * @return handle to this system, NULL on error 365 * @return handle to this system, NULL on error
370 */ 366 */
371struct GNUNET_TESTING_System * 367struct GNUNET_TESTING_System *
372GNUNET_TESTING_system_create_with_portrange ( 368GNUNET_TESTING_system_create_with_portrange(
373 const char *testdir, 369 const char *testdir,
374 const char *trusted_ip, 370 const char *trusted_ip,
375 const char *hostname, 371 const char *hostname,
@@ -382,53 +378,53 @@ GNUNET_TESTING_system_create_with_portrange (
382 struct SharedService *ss; 378 struct SharedService *ss;
383 unsigned int cnt; 379 unsigned int cnt;
384 380
385 GNUNET_assert (NULL != testdir); 381 GNUNET_assert(NULL != testdir);
386 system = GNUNET_new (struct GNUNET_TESTING_System); 382 system = GNUNET_new(struct GNUNET_TESTING_System);
387 if (NULL == (system->tmppath = getenv (GNUNET_TESTING_PREFIX))) 383 if (NULL == (system->tmppath = getenv(GNUNET_TESTING_PREFIX)))
388 system->tmppath = GNUNET_DISK_mkdtemp (testdir); 384 system->tmppath = GNUNET_DISK_mkdtemp(testdir);
389 else 385 else
390 system->tmppath = GNUNET_strdup (system->tmppath); 386 system->tmppath = GNUNET_strdup(system->tmppath);
391 system->lowport = lowport; 387 system->lowport = lowport;
392 system->highport = highport; 388 system->highport = highport;
393 if (NULL == system->tmppath) 389 if (NULL == system->tmppath)
394 { 390 {
395 GNUNET_free (system); 391 GNUNET_free(system);
396 return NULL; 392 return NULL;
397 } 393 }
398 if (NULL != trusted_ip) 394 if (NULL != trusted_ip)
399 system->trusted_ip = GNUNET_strdup (trusted_ip); 395 system->trusted_ip = GNUNET_strdup(trusted_ip);
400 if (NULL != hostname) 396 if (NULL != hostname)
401 system->hostname = GNUNET_strdup (hostname); 397 system->hostname = GNUNET_strdup(hostname);
402 if (GNUNET_OK != hostkeys_load (system)) 398 if (GNUNET_OK != hostkeys_load(system))
403 { 399 {
404 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 400 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
405 return NULL; 401 return NULL;
406 } 402 }
407 if (NULL == shared_services) 403 if (NULL == shared_services)
408 return system; 404 return system;
409 for (cnt = 0; NULL != shared_services[cnt].service; cnt++) 405 for (cnt = 0; NULL != shared_services[cnt].service; cnt++)
410 { 406 {
411 tss = shared_services[cnt]; 407 tss = shared_services[cnt];
412 ss = GNUNET_new (struct SharedService); 408 ss = GNUNET_new(struct SharedService);
413 ss->sname = GNUNET_strdup (tss.service); 409 ss->sname = GNUNET_strdup(tss.service);
414 ss->cfg = GNUNET_CONFIGURATION_create (); 410 ss->cfg = GNUNET_CONFIGURATION_create();
415 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, 411 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg,
416 ss->sname, 412 ss->sname,
417 &cfg_copy_iterator, 413 &cfg_copy_iterator,
418 ss->cfg); 414 ss->cfg);
419 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, 415 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg,
420 "TESTING", 416 "TESTING",
421 &cfg_copy_iterator, 417 &cfg_copy_iterator,
422 ss->cfg); 418 ss->cfg);
423 GNUNET_CONFIGURATION_iterate_section_values (tss.cfg, 419 GNUNET_CONFIGURATION_iterate_section_values(tss.cfg,
424 "PATHS", 420 "PATHS",
425 &cfg_copy_iterator, 421 &cfg_copy_iterator,
426 ss->cfg); 422 ss->cfg);
427 ss->share = tss.share; 423 ss->share = tss.share;
428 GNUNET_array_append (system->shared_services, 424 GNUNET_array_append(system->shared_services,
429 system->n_shared_services, 425 system->n_shared_services,
430 ss); 426 ss);
431 } 427 }
432 return system; 428 return system;
433} 429}
434 430
@@ -454,59 +450,59 @@ GNUNET_TESTING_system_create_with_portrange (
454 * @return handle to this system, NULL on error 450 * @return handle to this system, NULL on error
455 */ 451 */
456struct GNUNET_TESTING_System * 452struct GNUNET_TESTING_System *
457GNUNET_TESTING_system_create ( 453GNUNET_TESTING_system_create(
458 const char *testdir, 454 const char *testdir,
459 const char *trusted_ip, 455 const char *trusted_ip,
460 const char *hostname, 456 const char *hostname,
461 const struct GNUNET_TESTING_SharedService *shared_services) 457 const struct GNUNET_TESTING_SharedService *shared_services)
462{ 458{
463 return GNUNET_TESTING_system_create_with_portrange (testdir, 459 return GNUNET_TESTING_system_create_with_portrange(testdir,
464 trusted_ip, 460 trusted_ip,
465 hostname, 461 hostname,
466 shared_services, 462 shared_services,
467 LOW_PORT, 463 LOW_PORT,
468 HIGH_PORT); 464 HIGH_PORT);
469} 465}
470 466
471 467
472static void 468static void
473cleanup_shared_service_instance (struct SharedServiceInstance *i) 469cleanup_shared_service_instance(struct SharedServiceInstance *i)
474{ 470{
475 if (NULL != i->cfg_fn) 471 if (NULL != i->cfg_fn)
476 { 472 {
477 (void) unlink (i->cfg_fn); 473 (void)unlink(i->cfg_fn);
478 GNUNET_free (i->cfg_fn); 474 GNUNET_free(i->cfg_fn);
479 } 475 }
480 GNUNET_free_non_null (i->unix_sock); 476 GNUNET_free_non_null(i->unix_sock);
481 GNUNET_free_non_null (i->port_str); 477 GNUNET_free_non_null(i->port_str);
482 GNUNET_break (NULL == i->proc); 478 GNUNET_break(NULL == i->proc);
483 GNUNET_break (0 == i->n_refs); 479 GNUNET_break(0 == i->n_refs);
484 GNUNET_free (i); 480 GNUNET_free(i);
485} 481}
486 482
487 483
488static int 484static int
489start_shared_service_instance (struct SharedServiceInstance *i) 485start_shared_service_instance(struct SharedServiceInstance *i)
490{ 486{
491 char *binary; 487 char *binary;
492 char *libexec_binary; 488 char *libexec_binary;
493 489
494 GNUNET_assert (NULL == i->proc); 490 GNUNET_assert(NULL == i->proc);
495 GNUNET_assert (NULL != i->cfg_fn); 491 GNUNET_assert(NULL != i->cfg_fn);
496 (void) GNUNET_asprintf (&binary, "gnunet-service-%s", i->ss->sname); 492 (void)GNUNET_asprintf(&binary, "gnunet-service-%s", i->ss->sname);
497 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); 493 libexec_binary = GNUNET_OS_get_libexec_binary_path(binary);
498 GNUNET_free (binary); 494 GNUNET_free(binary);
499 i->proc = GNUNET_OS_start_process (PIPE_CONTROL, 495 i->proc = GNUNET_OS_start_process(PIPE_CONTROL,
500 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 496 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
501 NULL, 497 NULL,
502 NULL, 498 NULL,
503 NULL, 499 NULL,
504 libexec_binary, 500 libexec_binary,
505 libexec_binary, 501 libexec_binary,
506 "-c", 502 "-c",
507 i->cfg_fn, 503 i->cfg_fn,
508 NULL); 504 NULL);
509 GNUNET_free (libexec_binary); 505 GNUNET_free(libexec_binary);
510 if (NULL == i->proc) 506 if (NULL == i->proc)
511 return GNUNET_SYSERR; 507 return GNUNET_SYSERR;
512 return GNUNET_OK; 508 return GNUNET_OK;
@@ -514,15 +510,15 @@ start_shared_service_instance (struct SharedServiceInstance *i)
514 510
515 511
516static void 512static void
517stop_shared_service_instance (struct SharedServiceInstance *i) 513stop_shared_service_instance(struct SharedServiceInstance *i)
518{ 514{
519 GNUNET_break (0 == i->n_refs); 515 GNUNET_break(0 == i->n_refs);
520 if (0 != GNUNET_OS_process_kill (i->proc, GNUNET_TERM_SIG)) 516 if (0 != GNUNET_OS_process_kill(i->proc, GNUNET_TERM_SIG))
521 LOG (GNUNET_ERROR_TYPE_WARNING, 517 LOG(GNUNET_ERROR_TYPE_WARNING,
522 "Killing shared service instance (%s) failed\n", 518 "Killing shared service instance (%s) failed\n",
523 i->ss->sname); 519 i->ss->sname);
524 (void) GNUNET_OS_process_wait (i->proc); 520 (void)GNUNET_OS_process_wait(i->proc);
525 GNUNET_OS_process_destroy (i->proc); 521 GNUNET_OS_process_destroy(i->proc);
526 i->proc = NULL; 522 i->proc = NULL;
527} 523}
528 524
@@ -535,8 +531,8 @@ stop_shared_service_instance (struct SharedServiceInstance *i)
535 * be removed (clean up on shutdown)? 531 * be removed (clean up on shutdown)?
536 */ 532 */
537void 533void
538GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system, 534GNUNET_TESTING_system_destroy(struct GNUNET_TESTING_System *system,
539 int remove_paths) 535 int remove_paths)
540{ 536{
541 struct SharedService *ss; 537 struct SharedService *ss;
542 struct SharedServiceInstance *i; 538 struct SharedServiceInstance *i;
@@ -544,29 +540,29 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
544 unsigned int i_cnt; 540 unsigned int i_cnt;
545 541
546 if (NULL != system->hostkeys_data) 542 if (NULL != system->hostkeys_data)
547 hostkeys_unload (system); 543 hostkeys_unload(system);
548 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++) 544 for (ss_cnt = 0; ss_cnt < system->n_shared_services; ss_cnt++)
549 {
550 ss = system->shared_services[ss_cnt];
551 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
552 { 545 {
553 i = ss->instances[i_cnt]; 546 ss = system->shared_services[ss_cnt];
554 if (NULL != i->proc) 547 for (i_cnt = 0; i_cnt < ss->n_instances; i_cnt++)
555 stop_shared_service_instance (i); 548 {
556 cleanup_shared_service_instance (i); 549 i = ss->instances[i_cnt];
550 if (NULL != i->proc)
551 stop_shared_service_instance(i);
552 cleanup_shared_service_instance(i);
553 }
554 GNUNET_free_non_null(ss->instances);
555 GNUNET_CONFIGURATION_destroy(ss->cfg);
556 GNUNET_free(ss->sname);
557 GNUNET_free(ss);
557 } 558 }
558 GNUNET_free_non_null (ss->instances); 559 GNUNET_free_non_null(system->shared_services);
559 GNUNET_CONFIGURATION_destroy (ss->cfg);
560 GNUNET_free (ss->sname);
561 GNUNET_free (ss);
562 }
563 GNUNET_free_non_null (system->shared_services);
564 if (GNUNET_YES == remove_paths) 560 if (GNUNET_YES == remove_paths)
565 GNUNET_DISK_directory_remove (system->tmppath); 561 GNUNET_DISK_directory_remove(system->tmppath);
566 GNUNET_free (system->tmppath); 562 GNUNET_free(system->tmppath);
567 GNUNET_free_non_null (system->trusted_ip); 563 GNUNET_free_non_null(system->trusted_ip);
568 GNUNET_free_non_null (system->hostname); 564 GNUNET_free_non_null(system->hostname);
569 GNUNET_free (system); 565 GNUNET_free(system);
570} 566}
571 567
572 568
@@ -577,7 +573,7 @@ GNUNET_TESTING_system_destroy (struct GNUNET_TESTING_System *system,
577 * @return 0 if no free port was available 573 * @return 0 if no free port was available
578 */ 574 */
579uint16_t 575uint16_t
580GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) 576GNUNET_TESTING_reserve_port(struct GNUNET_TESTING_System *system)
581{ 577{
582 struct GNUNET_NETWORK_Handle *socket; 578 struct GNUNET_NETWORK_Handle *socket;
583 struct addrinfo hint; 579 struct addrinfo hint;
@@ -592,14 +588,14 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
592 uint16_t pos; 588 uint16_t pos;
593 589
594 /* 590 /*
595 FIXME: Instead of using getaddrinfo we should try to determine the port 591 FIXME: Instead of using getaddrinfo we should try to determine the port
596 status by the following heurestics. 592 status by the following heurestics.
597 593
598 On systems which support both IPv4 and IPv6, only ports open on both 594 On systems which support both IPv4 and IPv6, only ports open on both
599 address families are considered open. 595 address families are considered open.
600 On system with either IPv4 or IPv6. A port is considered open if it's 596 On system with either IPv4 or IPv6. A port is considered open if it's
601 open in the respective address family 597 open in the respective address family
602 */ 598 */
603 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */ 599 hint.ai_family = AF_UNSPEC; /* IPv4 and IPv6 */
604 hint.ai_socktype = 0; 600 hint.ai_socktype = 0;
605 hint.ai_protocol = 0; 601 hint.ai_protocol = 0;
@@ -611,57 +607,57 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
611 port_buckets = system->reserved_ports; 607 port_buckets = system->reserved_ports;
612 for (index = (system->lowport / 32) + 1; index < (system->highport / 32); 608 for (index = (system->lowport / 32) + 1; index < (system->highport / 32);
613 index++) 609 index++)
614 {
615 xor_image = (UINT32_MAX ^ port_buckets[index]);
616 if (0 == xor_image) /* Ports in the bucket are full */
617 continue;
618 pos = system->lowport % 32;
619 while (pos < 32)
620 { 610 {
621 if (0 == ((xor_image >> pos) & 1U)) 611 xor_image = (UINT32_MAX ^ port_buckets[index]);
622 { 612 if (0 == xor_image) /* Ports in the bucket are full */
623 pos++;
624 continue; 613 continue;
625 } 614 pos = system->lowport % 32;
626 open_port = (index * 32) + pos; 615 while (pos < 32)
627 if (open_port >= system->highport) 616 {
628 return 0; 617 if (0 == ((xor_image >> pos) & 1U))
629 GNUNET_asprintf (&open_port_str, "%u", (unsigned int) open_port); 618 {
630 ret = NULL; 619 pos++;
631 GNUNET_assert (0 == getaddrinfo (NULL, open_port_str, &hint, &ret)); 620 continue;
632 GNUNET_free (open_port_str); 621 }
633 bind_status = GNUNET_NO; 622 open_port = (index * 32) + pos;
634 for (ai = ret; NULL != ai; ai = ai->ai_next) 623 if (open_port >= system->highport)
635 { 624 return 0;
636 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_STREAM, 0); 625 GNUNET_asprintf(&open_port_str, "%u", (unsigned int)open_port);
637 if (NULL == socket) 626 ret = NULL;
638 continue; 627 GNUNET_assert(0 == getaddrinfo(NULL, open_port_str, &hint, &ret));
639 bind_status = 628 GNUNET_free(open_port_str);
640 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); 629 bind_status = GNUNET_NO;
641 GNUNET_NETWORK_socket_close (socket); 630 for (ai = ret; NULL != ai; ai = ai->ai_next)
642 if (GNUNET_OK != bind_status) 631 {
643 break; 632 socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_STREAM, 0);
644 socket = GNUNET_NETWORK_socket_create (ai->ai_family, SOCK_DGRAM, 0); 633 if (NULL == socket)
645 if (NULL == socket) 634 continue;
646 continue; 635 bind_status =
647 bind_status = 636 GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen);
648 GNUNET_NETWORK_socket_bind (socket, ai->ai_addr, ai->ai_addrlen); 637 GNUNET_NETWORK_socket_close(socket);
649 GNUNET_NETWORK_socket_close (socket); 638 if (GNUNET_OK != bind_status)
650 if (GNUNET_OK != bind_status) 639 break;
651 break; 640 socket = GNUNET_NETWORK_socket_create(ai->ai_family, SOCK_DGRAM, 0);
652 } 641 if (NULL == socket)
653 port_buckets[index] |= (1U << pos); /* Set the port bit */ 642 continue;
654 freeaddrinfo (ret); 643 bind_status =
655 if (GNUNET_OK == bind_status) 644 GNUNET_NETWORK_socket_bind(socket, ai->ai_addr, ai->ai_addrlen);
656 { 645 GNUNET_NETWORK_socket_close(socket);
657 LOG (GNUNET_ERROR_TYPE_DEBUG, 646 if (GNUNET_OK != bind_status)
658 "Found a free port %u\n", 647 break;
659 (unsigned int) open_port); 648 }
660 return open_port; 649 port_buckets[index] |= (1U << pos); /* Set the port bit */
661 } 650 freeaddrinfo(ret);
662 pos++; 651 if (GNUNET_OK == bind_status)
652 {
653 LOG(GNUNET_ERROR_TYPE_DEBUG,
654 "Found a free port %u\n",
655 (unsigned int)open_port);
656 return open_port;
657 }
658 pos++;
659 }
663 } 660 }
664 }
665 return 0; 661 return 0;
666} 662}
667 663
@@ -674,8 +670,8 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system)
674 * @param port reserved port to release 670 * @param port reserved port to release
675 */ 671 */
676void 672void
677GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system, 673GNUNET_TESTING_release_port(struct GNUNET_TESTING_System *system,
678 uint16_t port) 674 uint16_t port)
679{ 675{
680 uint32_t *port_buckets; 676 uint32_t *port_buckets;
681 uint16_t bucket; 677 uint16_t bucket;
@@ -684,12 +680,12 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
684 port_buckets = system->reserved_ports; 680 port_buckets = system->reserved_ports;
685 bucket = port / 32; 681 bucket = port / 32;
686 pos = port % 32; 682 pos = port % 32;
687 LOG (GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port); 683 LOG(GNUNET_ERROR_TYPE_DEBUG, "Releasing port %u\n", port);
688 if (0 == (port_buckets[bucket] & (1U << pos))) 684 if (0 == (port_buckets[bucket] & (1U << pos)))
689 { 685 {
690 GNUNET_break (0); /* Port was not reserved by us using reserve_port() */ 686 GNUNET_break(0); /* Port was not reserved by us using reserve_port() */
691 return; 687 return;
692 } 688 }
693 port_buckets[bucket] &= ~(1U << pos); 689 port_buckets[bucket] &= ~(1U << pos);
694} 690}
695 691
@@ -712,27 +708,27 @@ GNUNET_TESTING_release_port (struct GNUNET_TESTING_System *system,
712 * @return NULL on error (not enough keys) 708 * @return NULL on error (not enough keys)
713 */ 709 */
714struct GNUNET_CRYPTO_EddsaPrivateKey * 710struct GNUNET_CRYPTO_EddsaPrivateKey *
715GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system, 711GNUNET_TESTING_hostkey_get(const struct GNUNET_TESTING_System *system,
716 uint32_t key_number, 712 uint32_t key_number,
717 struct GNUNET_PeerIdentity *id) 713 struct GNUNET_PeerIdentity *id)
718{ 714{
719 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key; 715 struct GNUNET_CRYPTO_EddsaPrivateKey *private_key;
720 716
721 if ((NULL == id) || (NULL == system->hostkeys_data)) 717 if ((NULL == id) || (NULL == system->hostkeys_data))
722 return NULL; 718 return NULL;
723 if (key_number >= system->total_hostkeys) 719 if (key_number >= system->total_hostkeys)
724 { 720 {
725 LOG (GNUNET_ERROR_TYPE_ERROR, 721 LOG(GNUNET_ERROR_TYPE_ERROR,
726 _ ("Key number %u does not exist\n"), 722 _("Key number %u does not exist\n"),
727 key_number); 723 key_number);
728 return NULL; 724 return NULL;
729 } 725 }
730 private_key = GNUNET_new (struct GNUNET_CRYPTO_EddsaPrivateKey); 726 private_key = GNUNET_new(struct GNUNET_CRYPTO_EddsaPrivateKey);
731 GNUNET_memcpy (private_key, 727 GNUNET_memcpy(private_key,
732 system->hostkeys_data + 728 system->hostkeys_data +
733 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 729 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
734 GNUNET_TESTING_HOSTKEYFILESIZE); 730 GNUNET_TESTING_HOSTKEYFILESIZE);
735 GNUNET_CRYPTO_eddsa_key_get_public (private_key, &id->public_key); 731 GNUNET_CRYPTO_eddsa_key_get_public(private_key, &id->public_key);
736 return private_key; 732 return private_key;
737} 733}
738 734
@@ -741,8 +737,7 @@ GNUNET_TESTING_hostkey_get (const struct GNUNET_TESTING_System *system,
741 * Structure for holding data to build new configurations from a configuration 737 * Structure for holding data to build new configurations from a configuration
742 * template 738 * template
743 */ 739 */
744struct UpdateContext 740struct UpdateContext {
745{
746 /** 741 /**
747 * The system for which we are building configurations 742 * The system for which we are building configurations
748 */ 743 */
@@ -788,10 +783,10 @@ struct UpdateContext
788 * @param value value of the option 783 * @param value value of the option
789 */ 784 */
790static void 785static void
791update_config (void *cls, 786update_config(void *cls,
792 const char *section, 787 const char *section,
793 const char *option, 788 const char *option,
794 const char *value) 789 const char *value)
795{ 790{
796 struct UpdateContext *uc = cls; 791 struct UpdateContext *uc = cls;
797 unsigned int ival; 792 unsigned int ival;
@@ -804,76 +799,76 @@ update_config (void *cls,
804 799
805 if (GNUNET_OK != uc->status) 800 if (GNUNET_OK != uc->status)
806 return; 801 return;
807 if (! ((0 == strcmp (option, "PORT")) || (0 == strcmp (option, "UNIXPATH")) || 802 if (!((0 == strcmp(option, "PORT")) || (0 == strcmp(option, "UNIXPATH")) ||
808 (0 == strcmp (option, "HOSTNAME")))) 803 (0 == strcmp(option, "HOSTNAME"))))
809 return; 804 return;
810 GNUNET_asprintf (&single_variable, "single_%s_per_host", section); 805 GNUNET_asprintf(&single_variable, "single_%s_per_host", section);
811 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section); 806 GNUNET_asprintf(&per_host_variable, "num_%s_per_host", section);
812 if ((0 == strcmp (option, "PORT")) && (1 == sscanf (value, "%u", &ival))) 807 if ((0 == strcmp(option, "PORT")) && (1 == sscanf(value, "%u", &ival)))
813 {
814 if ((ival != 0) &&
815 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
816 "testing",
817 single_variable)))
818 { 808 {
819 new_port = GNUNET_TESTING_reserve_port (uc->system); 809 if ((ival != 0) &&
820 if (0 == new_port) 810 (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg,
821 { 811 "testing",
822 uc->status = GNUNET_SYSERR; 812 single_variable)))
823 GNUNET_free (single_variable); 813 {
824 GNUNET_free (per_host_variable); 814 new_port = GNUNET_TESTING_reserve_port(uc->system);
825 return; 815 if (0 == new_port)
826 } 816 {
827 GNUNET_snprintf (cval, sizeof (cval), "%u", new_port); 817 uc->status = GNUNET_SYSERR;
828 value = cval; 818 GNUNET_free(single_variable);
829 GNUNET_array_append (uc->ports, uc->nports, new_port); 819 GNUNET_free(per_host_variable);
830 } 820 return;
831 else if ((ival != 0) && 821 }
832 (GNUNET_YES == 822 GNUNET_snprintf(cval, sizeof(cval), "%u", new_port);
833 GNUNET_CONFIGURATION_get_value_yesno (uc->cfg, 823 value = cval;
834 "testing", 824 GNUNET_array_append(uc->ports, uc->nports, new_port);
835 single_variable)) && 825 }
836 GNUNET_CONFIGURATION_get_value_number (uc->cfg, 826 else if ((ival != 0) &&
837 "testing", 827 (GNUNET_YES ==
838 per_host_variable, 828 GNUNET_CONFIGURATION_get_value_yesno(uc->cfg,
839 &num_per_host)) 829 "testing",
840 { 830 single_variable)) &&
841 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */ 831 GNUNET_CONFIGURATION_get_value_number(uc->cfg,
842 /* ival + ctx->fdnum % num_per_host); */ 832 "testing",
843 /* value = cval; */ 833 per_host_variable,
844 GNUNET_break (0); /* FIXME */ 834 &num_per_host))
835 {
836 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
837 /* ival + ctx->fdnum % num_per_host); */
838 /* value = cval; */
839 GNUNET_break(0); /* FIXME */
840 }
845 } 841 }
846 } 842 if (0 == strcmp(option, "UNIXPATH"))
847 if (0 == strcmp (option, "UNIXPATH"))
848 {
849 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno (uc->cfg,
850 "testing",
851 single_variable))
852 { 843 {
853 GNUNET_snprintf (uval, 844 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_yesno(uc->cfg,
854 sizeof (uval), 845 "testing",
855 "%s/%s.sock", 846 single_variable))
856 uc->gnunet_home, 847 {
857 section); 848 GNUNET_snprintf(uval,
858 value = uval; 849 sizeof(uval),
850 "%s/%s.sock",
851 uc->gnunet_home,
852 section);
853 value = uval;
854 }
855 else if ((GNUNET_YES ==
856 GNUNET_CONFIGURATION_get_value_number(uc->cfg,
857 "testing",
858 per_host_variable,
859 &num_per_host)) &&
860 (num_per_host > 0))
861 {
862 GNUNET_break(0); /* FIXME */
863 }
859 } 864 }
860 else if ((GNUNET_YES == 865 if (0 == strcmp(option, "HOSTNAME"))
861 GNUNET_CONFIGURATION_get_value_number (uc->cfg,
862 "testing",
863 per_host_variable,
864 &num_per_host)) &&
865 (num_per_host > 0))
866 { 866 {
867 GNUNET_break (0); /* FIXME */ 867 value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
868 } 868 }
869 } 869 GNUNET_free(single_variable);
870 if (0 == strcmp (option, "HOSTNAME")) 870 GNUNET_free(per_host_variable);
871 { 871 GNUNET_CONFIGURATION_set_value_string(uc->cfg, section, option, value);
872 value = (NULL == uc->system->hostname) ? "localhost" : uc->system->hostname;
873 }
874 GNUNET_free (single_variable);
875 GNUNET_free (per_host_variable);
876 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
877} 872}
878 873
879 874
@@ -885,7 +880,7 @@ update_config (void *cls,
885 * @param section name of the section 880 * @param section name of the section
886 */ 881 */
887static void 882static void
888update_config_sections (void *cls, const char *section) 883update_config_sections(void *cls, const char *section)
889{ 884{
890 struct UpdateContext *uc = cls; 885 struct UpdateContext *uc = cls;
891 char **ikeys; 886 char **ikeys;
@@ -902,98 +897,98 @@ update_config_sections (void *cls, const char *section)
902 /* Ignore certain options from sections. See 897 /* Ignore certain options from sections. See
903 https://gnunet.org/bugs/view.php?id=2476 */ 898 https://gnunet.org/bugs/view.php?id=2476 */
904 if (GNUNET_YES == 899 if (GNUNET_YES ==
905 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "TESTING_IGNORE_KEYS")) 900 GNUNET_CONFIGURATION_have_value(uc->cfg, section, "TESTING_IGNORE_KEYS"))
906 { 901 {
907 GNUNET_assert (GNUNET_YES == 902 GNUNET_assert(GNUNET_YES ==
908 GNUNET_CONFIGURATION_get_value_string (uc->cfg, 903 GNUNET_CONFIGURATION_get_value_string(uc->cfg,
909 section, 904 section,
910 "TESTING_IGNORE_KEYS", 905 "TESTING_IGNORE_KEYS",
911 &val)); 906 &val));
912 ptr = val;
913 for (ikeys_cnt = 0; NULL != (ptr = strstr (ptr, ";")); ikeys_cnt++)
914 ptr++;
915 if (0 == ikeys_cnt)
916 GNUNET_break (0);
917 else
918 {
919 ikeys = GNUNET_malloc ((sizeof (char *)) * ikeys_cnt);
920 ptr = val; 907 ptr = val;
921 for (key = 0; key < ikeys_cnt; key++) 908 for (ikeys_cnt = 0; NULL != (ptr = strstr(ptr, ";")); ikeys_cnt++)
922 {
923 ikeys[key] = ptr;
924 ptr = strstr (ptr, ";");
925 GNUNET_assert (NULL != ptr); /* worked just before... */
926 *ptr = '\0';
927 ptr++; 909 ptr++;
928 } 910 if (0 == ikeys_cnt)
911 GNUNET_break(0);
912 else
913 {
914 ikeys = GNUNET_malloc((sizeof(char *)) * ikeys_cnt);
915 ptr = val;
916 for (key = 0; key < ikeys_cnt; key++)
917 {
918 ikeys[key] = ptr;
919 ptr = strstr(ptr, ";");
920 GNUNET_assert(NULL != ptr); /* worked just before... */
921 *ptr = '\0';
922 ptr++;
923 }
924 }
929 } 925 }
930 }
931 if (0 != ikeys_cnt) 926 if (0 != ikeys_cnt)
932 {
933 for (key = 0; key < ikeys_cnt; key++)
934 {
935 if (NULL != strstr (ikeys[key], "ADVERTISED_PORT"))
936 break;
937 }
938 if ((key == ikeys_cnt) &&
939 (GNUNET_YES ==
940 GNUNET_CONFIGURATION_have_value (uc->cfg, section, "ADVERTISED_PORT")))
941 { 927 {
942 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (uc->cfg, 928 for (key = 0; key < ikeys_cnt; key++)
943 section, 929 {
944 "PORT", 930 if (NULL != strstr(ikeys[key], "ADVERTISED_PORT"))
945 &ptr)) 931 break;
946 { 932 }
947 GNUNET_CONFIGURATION_set_value_string (uc->cfg, 933 if ((key == ikeys_cnt) &&
948 section, 934 (GNUNET_YES ==
949 "ADVERTISED_PORT", 935 GNUNET_CONFIGURATION_have_value(uc->cfg, section, "ADVERTISED_PORT")))
950 ptr); 936 {
951 GNUNET_free (ptr); 937 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(uc->cfg,
952 } 938 section,
953 } 939 "PORT",
954 for (key = 0; key < ikeys_cnt; key++) 940 &ptr))
955 { 941 {
956 if (NULL != strstr (ikeys[key], "ACCEPT_FROM")) 942 GNUNET_CONFIGURATION_set_value_string(uc->cfg,
957 { 943 section,
958 GNUNET_free (ikeys); 944 "ADVERTISED_PORT",
959 GNUNET_free (val); 945 ptr);
960 return; 946 GNUNET_free(ptr);
961 } 947 }
948 }
949 for (key = 0; key < ikeys_cnt; key++)
950 {
951 if (NULL != strstr(ikeys[key], "ACCEPT_FROM"))
952 {
953 GNUNET_free(ikeys);
954 GNUNET_free(val);
955 return;
956 }
957 }
958 GNUNET_free(ikeys);
962 } 959 }
963 GNUNET_free (ikeys); 960 GNUNET_free_non_null(val);
964 }
965 GNUNET_free_non_null (val);
966 ACCEPT_FROM_key = "ACCEPT_FROM"; 961 ACCEPT_FROM_key = "ACCEPT_FROM";
967 if ((NULL != uc->system->trusted_ip) && 962 if ((NULL != uc->system->trusted_ip) &&
968 (NULL != strstr (uc->system->trusted_ip, ":"))) /* IPv6 in use */ 963 (NULL != strstr(uc->system->trusted_ip, ":"))) /* IPv6 in use */
969 ACCEPT_FROM_key = "ACCEPT_FROM6"; 964 ACCEPT_FROM_key = "ACCEPT_FROM6";
970 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (uc->cfg, 965 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string(uc->cfg,
971 section, 966 section,
972 ACCEPT_FROM_key, 967 ACCEPT_FROM_key,
973 &orig_allowed_hosts)) 968 &orig_allowed_hosts))
974 { 969 {
975 orig_allowed_hosts = GNUNET_strdup ("127.0.0.1;"); 970 orig_allowed_hosts = GNUNET_strdup("127.0.0.1;");
976 } 971 }
977 if (NULL == uc->system->trusted_ip) 972 if (NULL == uc->system->trusted_ip)
978 allowed_hosts = GNUNET_strdup (orig_allowed_hosts); 973 allowed_hosts = GNUNET_strdup(orig_allowed_hosts);
979 else 974 else
980 GNUNET_asprintf (&allowed_hosts, 975 GNUNET_asprintf(&allowed_hosts,
981 "%s%s;", 976 "%s%s;",
982 orig_allowed_hosts, 977 orig_allowed_hosts,
983 uc->system->trusted_ip); 978 uc->system->trusted_ip);
984 GNUNET_free (orig_allowed_hosts); 979 GNUNET_free(orig_allowed_hosts);
985 GNUNET_CONFIGURATION_set_value_string (uc->cfg, 980 GNUNET_CONFIGURATION_set_value_string(uc->cfg,
986 section, 981 section,
987 ACCEPT_FROM_key, 982 ACCEPT_FROM_key,
988 allowed_hosts); 983 allowed_hosts);
989 GNUNET_free (allowed_hosts); 984 GNUNET_free(allowed_hosts);
990} 985}
991 986
992 987
993static struct SharedServiceInstance * 988static struct SharedServiceInstance *
994associate_shared_service (struct GNUNET_TESTING_System *system, 989associate_shared_service(struct GNUNET_TESTING_System *system,
995 struct SharedService *ss, 990 struct SharedService *ss,
996 struct GNUNET_CONFIGURATION_Handle *cfg) 991 struct GNUNET_CONFIGURATION_Handle *cfg)
997{ 992{
998 struct SharedServiceInstance *i; 993 struct SharedServiceInstance *i;
999 struct GNUNET_CONFIGURATION_Handle *temp; 994 struct GNUNET_CONFIGURATION_Handle *temp;
@@ -1004,62 +999,62 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1004 if (((0 == ss->share) && (NULL == ss->instances)) || 999 if (((0 == ss->share) && (NULL == ss->instances)) ||
1005 ((0 != ss->share) && 1000 ((0 != ss->share) &&
1006 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share)))) 1001 (ss->n_instances < ((ss->n_peers + ss->share - 1) / ss->share))))
1007 { 1002 {
1008 i = GNUNET_new (struct SharedServiceInstance); 1003 i = GNUNET_new(struct SharedServiceInstance);
1009 i->ss = ss; 1004 i->ss = ss;
1010 (void) GNUNET_asprintf (&gnunet_home, 1005 (void)GNUNET_asprintf(&gnunet_home,
1011 "%s/shared/%s/%u", 1006 "%s/shared/%s/%u",
1012 system->tmppath, 1007 system->tmppath,
1013 ss->sname, 1008 ss->sname,
1014 ss->n_instances); 1009 ss->n_instances);
1015 (void) GNUNET_asprintf (&i->unix_sock, "%s/sock", gnunet_home); 1010 (void)GNUNET_asprintf(&i->unix_sock, "%s/sock", gnunet_home);
1016 port = GNUNET_TESTING_reserve_port (system); 1011 port = GNUNET_TESTING_reserve_port(system);
1017 if (0 == port) 1012 if (0 == port)
1018 { 1013 {
1019 GNUNET_free (gnunet_home); 1014 GNUNET_free(gnunet_home);
1020 cleanup_shared_service_instance (i); 1015 cleanup_shared_service_instance(i);
1021 return NULL; 1016 return NULL;
1017 }
1018 GNUNET_array_append(ss->instances, ss->n_instances, i);
1019 temp = GNUNET_CONFIGURATION_dup(ss->cfg);
1020 (void)GNUNET_asprintf(&i->port_str, "%u", port);
1021 (void)GNUNET_asprintf(&i->cfg_fn, "%s/config", gnunet_home);
1022 GNUNET_CONFIGURATION_set_value_string(temp,
1023 "PATHS",
1024 "GNUNET_HOME",
1025 gnunet_home);
1026 GNUNET_free(gnunet_home);
1027 GNUNET_CONFIGURATION_set_value_string(temp,
1028 ss->sname,
1029 "UNIXPATH",
1030 i->unix_sock);
1031 GNUNET_CONFIGURATION_set_value_string(temp,
1032 ss->sname,
1033 "PORT",
1034 i->port_str);
1035 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write(temp, i->cfg_fn))
1036 {
1037 GNUNET_CONFIGURATION_destroy(temp);
1038 cleanup_shared_service_instance(i);
1039 return NULL;
1040 }
1041 GNUNET_CONFIGURATION_destroy(temp);
1022 } 1042 }
1023 GNUNET_array_append (ss->instances, ss->n_instances, i); 1043 else
1024 temp = GNUNET_CONFIGURATION_dup (ss->cfg);
1025 (void) GNUNET_asprintf (&i->port_str, "%u", port);
1026 (void) GNUNET_asprintf (&i->cfg_fn, "%s/config", gnunet_home);
1027 GNUNET_CONFIGURATION_set_value_string (temp,
1028 "PATHS",
1029 "GNUNET_HOME",
1030 gnunet_home);
1031 GNUNET_free (gnunet_home);
1032 GNUNET_CONFIGURATION_set_value_string (temp,
1033 ss->sname,
1034 "UNIXPATH",
1035 i->unix_sock);
1036 GNUNET_CONFIGURATION_set_value_string (temp,
1037 ss->sname,
1038 "PORT",
1039 i->port_str);
1040 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_write (temp, i->cfg_fn))
1041 { 1044 {
1042 GNUNET_CONFIGURATION_destroy (temp); 1045 GNUNET_assert(NULL != ss->instances);
1043 cleanup_shared_service_instance (i); 1046 GNUNET_assert(0 < ss->n_instances);
1044 return NULL; 1047 i = ss->instances[ss->n_instances - 1];
1045 } 1048 }
1046 GNUNET_CONFIGURATION_destroy (temp); 1049 GNUNET_CONFIGURATION_iterate_section_values(ss->cfg,
1047 } 1050 ss->sname,
1048 else 1051 &cfg_copy_iterator,
1049 { 1052 cfg);
1050 GNUNET_assert (NULL != ss->instances); 1053 GNUNET_CONFIGURATION_set_value_string(cfg,
1051 GNUNET_assert (0 < ss->n_instances); 1054 ss->sname,
1052 i = ss->instances[ss->n_instances - 1]; 1055 "UNIXPATH",
1053 } 1056 i->unix_sock);
1054 GNUNET_CONFIGURATION_iterate_section_values (ss->cfg, 1057 GNUNET_CONFIGURATION_set_value_string(cfg, ss->sname, "PORT", i->port_str);
1055 ss->sname,
1056 &cfg_copy_iterator,
1057 cfg);
1058 GNUNET_CONFIGURATION_set_value_string (cfg,
1059 ss->sname,
1060 "UNIXPATH",
1061 i->unix_sock);
1062 GNUNET_CONFIGURATION_set_value_string (cfg, ss->sname, "PORT", i->port_str);
1063 return i; 1058 return i;
1064} 1059}
1065 1060
@@ -1084,10 +1079,10 @@ associate_shared_service (struct GNUNET_TESTING_System *system,
1084 * be incomplete and should not be used there upon 1079 * be incomplete and should not be used there upon
1085 */ 1080 */
1086static int 1081static int
1087GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system, 1082GNUNET_TESTING_configuration_create_(struct GNUNET_TESTING_System *system,
1088 struct GNUNET_CONFIGURATION_Handle *cfg, 1083 struct GNUNET_CONFIGURATION_Handle *cfg,
1089 uint16_t **ports, 1084 uint16_t **ports,
1090 unsigned int *nports) 1085 unsigned int *nports)
1091{ 1086{
1092 struct UpdateContext uc; 1087 struct UpdateContext uc;
1093 char *default_config; 1088 char *default_config;
@@ -1097,35 +1092,35 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1097 uc.status = GNUNET_OK; 1092 uc.status = GNUNET_OK;
1098 uc.ports = NULL; 1093 uc.ports = NULL;
1099 uc.nports = 0; 1094 uc.nports = 0;
1100 GNUNET_asprintf (&uc.gnunet_home, 1095 GNUNET_asprintf(&uc.gnunet_home,
1101 "%s/%u", 1096 "%s/%u",
1102 system->tmppath, 1097 system->tmppath,
1103 system->path_counter++); 1098 system->path_counter++);
1104 GNUNET_asprintf (&default_config, "%s/config", uc.gnunet_home); 1099 GNUNET_asprintf(&default_config, "%s/config", uc.gnunet_home);
1105 GNUNET_CONFIGURATION_set_value_string (cfg, 1100 GNUNET_CONFIGURATION_set_value_string(cfg,
1106 "PATHS", 1101 "PATHS",
1107 "DEFAULTCONFIG", 1102 "DEFAULTCONFIG",
1108 default_config); 1103 default_config);
1109 GNUNET_CONFIGURATION_set_value_string (cfg, "arm", "CONFIG", default_config); 1104 GNUNET_CONFIGURATION_set_value_string(cfg, "arm", "CONFIG", default_config);
1110 GNUNET_free (default_config); 1105 GNUNET_free(default_config);
1111 GNUNET_CONFIGURATION_set_value_string (cfg, 1106 GNUNET_CONFIGURATION_set_value_string(cfg,
1112 "PATHS", 1107 "PATHS",
1113 "GNUNET_HOME", 1108 "GNUNET_HOME",
1114 uc.gnunet_home); 1109 uc.gnunet_home);
1115 /* make PORTs and UNIXPATHs unique */ 1110 /* make PORTs and UNIXPATHs unique */
1116 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc); 1111 GNUNET_CONFIGURATION_iterate(cfg, &update_config, &uc);
1117 /* allow connections to services from system trusted_ip host */ 1112 /* allow connections to services from system trusted_ip host */
1118 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc); 1113 GNUNET_CONFIGURATION_iterate_sections(cfg, &update_config_sections, &uc);
1119 /* enable loopback-based connections between peers */ 1114 /* enable loopback-based connections between peers */
1120 GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "USE_LOCALADDR", "YES"); 1115 GNUNET_CONFIGURATION_set_value_string(cfg, "nat", "USE_LOCALADDR", "YES");
1121 GNUNET_free (uc.gnunet_home); 1116 GNUNET_free(uc.gnunet_home);
1122 if ((NULL != ports) && (NULL != nports)) 1117 if ((NULL != ports) && (NULL != nports))
1123 { 1118 {
1124 *ports = uc.ports; 1119 *ports = uc.ports;
1125 *nports = uc.nports; 1120 *nports = uc.nports;
1126 } 1121 }
1127 else 1122 else
1128 GNUNET_free_non_null (uc.ports); 1123 GNUNET_free_non_null(uc.ports);
1129 return uc.status; 1124 return uc.status;
1130} 1125}
1131 1126
@@ -1147,10 +1142,10 @@ GNUNET_TESTING_configuration_create_ (struct GNUNET_TESTING_System *system,
1147 * be incomplete and should not be used there upon 1142 * be incomplete and should not be used there upon
1148 */ 1143 */
1149int 1144int
1150GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 1145GNUNET_TESTING_configuration_create(struct GNUNET_TESTING_System *system,
1151 struct GNUNET_CONFIGURATION_Handle *cfg) 1146 struct GNUNET_CONFIGURATION_Handle *cfg)
1152{ 1147{
1153 return GNUNET_TESTING_configuration_create_ (system, cfg, NULL, NULL); 1148 return GNUNET_TESTING_configuration_create_(system, cfg, NULL, NULL);
1154} 1149}
1155 1150
1156 1151
@@ -1168,11 +1163,11 @@ GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
1168 * @return handle to the peer, NULL on error 1163 * @return handle to the peer, NULL on error
1169 */ 1164 */
1170struct GNUNET_TESTING_Peer * 1165struct GNUNET_TESTING_Peer *
1171GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system, 1166GNUNET_TESTING_peer_configure(struct GNUNET_TESTING_System *system,
1172 struct GNUNET_CONFIGURATION_Handle *cfg, 1167 struct GNUNET_CONFIGURATION_Handle *cfg,
1173 uint32_t key_number, 1168 uint32_t key_number,
1174 struct GNUNET_PeerIdentity *id, 1169 struct GNUNET_PeerIdentity *id,
1175 char **emsg) 1170 char **emsg)
1176{ 1171{
1177 struct GNUNET_TESTING_Peer *peer; 1172 struct GNUNET_TESTING_Peer *peer;
1178 struct GNUNET_DISK_FileHandle *fd; 1173 struct GNUNET_DISK_FileHandle *fd;
@@ -1193,141 +1188,141 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1193 if (NULL != emsg) 1188 if (NULL != emsg)
1194 *emsg = NULL; 1189 *emsg = NULL;
1195 if (key_number >= system->total_hostkeys) 1190 if (key_number >= system->total_hostkeys)
1196 { 1191 {
1197 GNUNET_asprintf ( 1192 GNUNET_asprintf(
1198 &emsg_, 1193 &emsg_,
1199 _ ( 1194 _(
1200 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"), 1195 "You attempted to create a testbed with more than %u hosts. Please precompute more hostkeys first.\n"),
1201 (unsigned int) system->total_hostkeys); 1196 (unsigned int)system->total_hostkeys);
1202 goto err_ret; 1197 goto err_ret;
1203 } 1198 }
1204 pk = NULL; 1199 pk = NULL;
1205 if ((NULL != id) && 1200 if ((NULL != id) &&
1206 (NULL == (pk = GNUNET_TESTING_hostkey_get (system, key_number, id)))) 1201 (NULL == (pk = GNUNET_TESTING_hostkey_get(system, key_number, id))))
1207 { 1202 {
1208 GNUNET_asprintf (&emsg_, 1203 GNUNET_asprintf(&emsg_,
1209 _ ("Failed to initialize hostkey for peer %u\n"), 1204 _("Failed to initialize hostkey for peer %u\n"),
1210 (unsigned int) key_number); 1205 (unsigned int)key_number);
1211 goto err_ret; 1206 goto err_ret;
1212 } 1207 }
1213 if (NULL != pk) 1208 if (NULL != pk)
1214 GNUNET_free (pk); 1209 GNUNET_free(pk);
1215 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, "PEER", "PRIVATE_KEY")) 1210 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, "PEER", "PRIVATE_KEY"))
1216 { 1211 {
1217 GNUNET_asprintf ( 1212 GNUNET_asprintf(
1218 &emsg_, 1213 &emsg_,
1219 _ ("PRIVATE_KEY option in PEER section missing in configuration\n")); 1214 _("PRIVATE_KEY option in PEER section missing in configuration\n"));
1220 goto err_ret; 1215 goto err_ret;
1221 } 1216 }
1222 /* Remove sections for shared services */ 1217 /* Remove sections for shared services */
1223 for (cnt = 0; cnt < system->n_shared_services; cnt++) 1218 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1224 { 1219 {
1225 ss = system->shared_services[cnt]; 1220 ss = system->shared_services[cnt];
1226 GNUNET_CONFIGURATION_remove_section (cfg, ss->sname); 1221 GNUNET_CONFIGURATION_remove_section(cfg, ss->sname);
1227 } 1222 }
1228 if (GNUNET_OK != 1223 if (GNUNET_OK !=
1229 GNUNET_TESTING_configuration_create_ (system, cfg, &ports, &nports)) 1224 GNUNET_TESTING_configuration_create_(system, cfg, &ports, &nports))
1230 { 1225 {
1231 GNUNET_asprintf (&emsg_, 1226 GNUNET_asprintf(&emsg_,
1232 _ ("Failed to create configuration for peer " 1227 _("Failed to create configuration for peer "
1233 "(not enough free ports?)\n")); 1228 "(not enough free ports?)\n"));
1234 goto err_ret; 1229 goto err_ret;
1235 } 1230 }
1236 GNUNET_assert (GNUNET_OK == 1231 GNUNET_assert(GNUNET_OK ==
1237 GNUNET_CONFIGURATION_get_value_filename (cfg, 1232 GNUNET_CONFIGURATION_get_value_filename(cfg,
1238 "PEER", 1233 "PEER",
1239 "PRIVATE_KEY", 1234 "PRIVATE_KEY",
1240 &hostkey_filename)); 1235 &hostkey_filename));
1241 fd = GNUNET_DISK_file_open (hostkey_filename, 1236 fd = GNUNET_DISK_file_open(hostkey_filename,
1242 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE, 1237 GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_WRITE,
1243 GNUNET_DISK_PERM_USER_READ | 1238 GNUNET_DISK_PERM_USER_READ |
1244 GNUNET_DISK_PERM_USER_WRITE); 1239 GNUNET_DISK_PERM_USER_WRITE);
1245 if (NULL == fd) 1240 if (NULL == fd)
1246 { 1241 {
1247 GNUNET_asprintf (&emsg_, 1242 GNUNET_asprintf(&emsg_,
1248 _ ("Cannot open hostkey file `%s': %s\n"), 1243 _("Cannot open hostkey file `%s': %s\n"),
1249 hostkey_filename, 1244 hostkey_filename,
1250 strerror (errno)); 1245 strerror(errno));
1251 GNUNET_free (hostkey_filename); 1246 GNUNET_free(hostkey_filename);
1252 goto err_ret; 1247 goto err_ret;
1253 } 1248 }
1254 GNUNET_free (hostkey_filename); 1249 GNUNET_free(hostkey_filename);
1255 if (GNUNET_TESTING_HOSTKEYFILESIZE != 1250 if (GNUNET_TESTING_HOSTKEYFILESIZE !=
1256 GNUNET_DISK_file_write (fd, 1251 GNUNET_DISK_file_write(fd,
1257 system->hostkeys_data + 1252 system->hostkeys_data +
1258 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE), 1253 (key_number * GNUNET_TESTING_HOSTKEYFILESIZE),
1259 GNUNET_TESTING_HOSTKEYFILESIZE)) 1254 GNUNET_TESTING_HOSTKEYFILESIZE))
1260 { 1255 {
1261 GNUNET_asprintf (&emsg_, 1256 GNUNET_asprintf(&emsg_,
1262 _ ("Failed to write hostkey file for peer %u: %s\n"), 1257 _("Failed to write hostkey file for peer %u: %s\n"),
1263 (unsigned int) key_number, 1258 (unsigned int)key_number,
1264 strerror (errno)); 1259 strerror(errno));
1265 GNUNET_DISK_file_close (fd); 1260 GNUNET_DISK_file_close(fd);
1266 goto err_ret; 1261 goto err_ret;
1267 } 1262 }
1268 GNUNET_DISK_file_close (fd); 1263 GNUNET_DISK_file_close(fd);
1269 ss_instances = GNUNET_malloc (sizeof (struct SharedServiceInstance *) * 1264 ss_instances = GNUNET_malloc(sizeof(struct SharedServiceInstance *) *
1270 system->n_shared_services); 1265 system->n_shared_services);
1271 for (cnt = 0; cnt < system->n_shared_services; cnt++) 1266 for (cnt = 0; cnt < system->n_shared_services; cnt++)
1272 {
1273 ss = system->shared_services[cnt];
1274 ss_instances[cnt] = associate_shared_service (system, ss, cfg);
1275 if (NULL == ss_instances[cnt])
1276 { 1267 {
1277 emsg_ = GNUNET_strdup ("FIXME"); 1268 ss = system->shared_services[cnt];
1269 ss_instances[cnt] = associate_shared_service(system, ss, cfg);
1270 if (NULL == ss_instances[cnt])
1271 {
1272 emsg_ = GNUNET_strdup("FIXME");
1273 goto err_ret;
1274 }
1275 }
1276 GNUNET_assert(GNUNET_OK ==
1277 GNUNET_CONFIGURATION_get_value_filename(cfg,
1278 "PATHS",
1279 "DEFAULTCONFIG",
1280 &config_filename));
1281 if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, config_filename))
1282 {
1283 GNUNET_asprintf(&emsg_,
1284 _(
1285 "Failed to write configuration file `%s' for peer %u: %s\n"),
1286 config_filename,
1287 (unsigned int)key_number,
1288 strerror(errno));
1289 GNUNET_free(config_filename);
1278 goto err_ret; 1290 goto err_ret;
1279 } 1291 }
1280 } 1292 peer = GNUNET_new(struct GNUNET_TESTING_Peer);
1281 GNUNET_assert (GNUNET_OK ==
1282 GNUNET_CONFIGURATION_get_value_filename (cfg,
1283 "PATHS",
1284 "DEFAULTCONFIG",
1285 &config_filename));
1286 if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, config_filename))
1287 {
1288 GNUNET_asprintf (&emsg_,
1289 _ (
1290 "Failed to write configuration file `%s' for peer %u: %s\n"),
1291 config_filename,
1292 (unsigned int) key_number,
1293 strerror (errno));
1294 GNUNET_free (config_filename);
1295 goto err_ret;
1296 }
1297 peer = GNUNET_new (struct GNUNET_TESTING_Peer);
1298 peer->ss_instances = ss_instances; 1293 peer->ss_instances = ss_instances;
1299 peer->cfgfile = config_filename; /* Free in peer_destroy */ 1294 peer->cfgfile = config_filename; /* Free in peer_destroy */
1300 peer->cfg = GNUNET_CONFIGURATION_dup (cfg); 1295 peer->cfg = GNUNET_CONFIGURATION_dup(cfg);
1301 libexec_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 1296 libexec_binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
1302 if (GNUNET_SYSERR == 1297 if (GNUNET_SYSERR ==
1303 GNUNET_CONFIGURATION_get_value_string (cfg, 1298 GNUNET_CONFIGURATION_get_value_string(cfg,
1304 "arm", 1299 "arm",
1305 "PREFIX", 1300 "PREFIX",
1306 &peer->main_binary)) 1301 &peer->main_binary))
1307 { 1302 {
1308 /* No prefix */ 1303 /* No prefix */
1309 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); 1304 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1310 peer->args = GNUNET_strdup (""); 1305 peer->args = GNUNET_strdup("");
1311 } 1306 }
1312 else 1307 else
1313 { 1308 {
1314 peer->args = GNUNET_strdup (libexec_binary); 1309 peer->args = GNUNET_strdup(libexec_binary);
1315 } 1310 }
1316 peer->system = system; 1311 peer->system = system;
1317 peer->key_number = key_number; 1312 peer->key_number = key_number;
1318 GNUNET_free (libexec_binary); 1313 GNUNET_free(libexec_binary);
1319 peer->ports = ports; /* Free in peer_destroy */ 1314 peer->ports = ports; /* Free in peer_destroy */
1320 peer->nports = nports; 1315 peer->nports = nports;
1321 return peer; 1316 return peer;
1322 1317
1323err_ret: 1318err_ret:
1324 GNUNET_free_non_null (ss_instances); 1319 GNUNET_free_non_null(ss_instances);
1325 GNUNET_free_non_null (ports); 1320 GNUNET_free_non_null(ports);
1326 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1321 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
1327 if (NULL != emsg) 1322 if (NULL != emsg)
1328 *emsg = emsg_; 1323 *emsg = emsg_;
1329 else 1324 else
1330 GNUNET_free (emsg_); 1325 GNUNET_free(emsg_);
1331 return NULL; 1326 return NULL;
1332} 1327}
1333 1328
@@ -1339,18 +1334,18 @@ err_ret:
1339 * @param id identifier for the daemon, will be set 1334 * @param id identifier for the daemon, will be set
1340 */ 1335 */
1341void 1336void
1342GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer, 1337GNUNET_TESTING_peer_get_identity(struct GNUNET_TESTING_Peer *peer,
1343 struct GNUNET_PeerIdentity *id) 1338 struct GNUNET_PeerIdentity *id)
1344{ 1339{
1345 if (NULL != peer->id) 1340 if (NULL != peer->id)
1346 { 1341 {
1347 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); 1342 GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1348 return; 1343 return;
1349 } 1344 }
1350 peer->id = GNUNET_new (struct GNUNET_PeerIdentity); 1345 peer->id = GNUNET_new(struct GNUNET_PeerIdentity);
1351 GNUNET_free ( 1346 GNUNET_free(
1352 GNUNET_TESTING_hostkey_get (peer->system, peer->key_number, peer->id)); 1347 GNUNET_TESTING_hostkey_get(peer->system, peer->key_number, peer->id));
1353 GNUNET_memcpy (id, peer->id, sizeof (struct GNUNET_PeerIdentity)); 1348 GNUNET_memcpy(id, peer->id, sizeof(struct GNUNET_PeerIdentity));
1354} 1349}
1355 1350
1356 1351
@@ -1361,44 +1356,44 @@ GNUNET_TESTING_peer_get_identity (struct GNUNET_TESTING_Peer *peer,
1361 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. peer already running) 1356 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error (i.e. peer already running)
1362 */ 1357 */
1363int 1358int
1364GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer) 1359GNUNET_TESTING_peer_start(struct GNUNET_TESTING_Peer *peer)
1365{ 1360{
1366 struct SharedServiceInstance *i; 1361 struct SharedServiceInstance *i;
1367 unsigned int cnt; 1362 unsigned int cnt;
1368 1363
1369 if (NULL != peer->main_process) 1364 if (NULL != peer->main_process)
1370 { 1365 {
1371 GNUNET_break (0); 1366 GNUNET_break(0);
1372 return GNUNET_SYSERR;
1373 }
1374 GNUNET_assert (NULL != peer->cfgfile);
1375 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1376 {
1377 i = peer->ss_instances[cnt];
1378 if ((0 == i->n_refs) &&
1379 (GNUNET_SYSERR == start_shared_service_instance (i)))
1380 return GNUNET_SYSERR; 1367 return GNUNET_SYSERR;
1381 i->n_refs++; 1368 }
1382 } 1369 GNUNET_assert(NULL != peer->cfgfile);
1370 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1371 {
1372 i = peer->ss_instances[cnt];
1373 if ((0 == i->n_refs) &&
1374 (GNUNET_SYSERR == start_shared_service_instance(i)))
1375 return GNUNET_SYSERR;
1376 i->n_refs++;
1377 }
1383 peer->main_binary = 1378 peer->main_binary =
1384 GNUNET_CONFIGURATION_expand_dollar (peer->cfg, peer->main_binary); 1379 GNUNET_CONFIGURATION_expand_dollar(peer->cfg, peer->main_binary);
1385 peer->main_process = 1380 peer->main_process =
1386 GNUNET_OS_start_process_s (PIPE_CONTROL, 1381 GNUNET_OS_start_process_s(PIPE_CONTROL,
1387 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 1382 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
1388 NULL, 1383 NULL,
1389 peer->main_binary, 1384 peer->main_binary,
1390 peer->args, 1385 peer->args,
1391 "-c", 1386 "-c",
1392 peer->cfgfile, 1387 peer->cfgfile,
1393 NULL); 1388 NULL);
1394 if (NULL == peer->main_process) 1389 if (NULL == peer->main_process)
1395 { 1390 {
1396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1391 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1397 _ ("Failed to start `%s': %s\n"), 1392 _("Failed to start `%s': %s\n"),
1398 peer->main_binary, 1393 peer->main_binary,
1399 strerror (errno)); 1394 strerror(errno));
1400 return GNUNET_SYSERR; 1395 return GNUNET_SYSERR;
1401 } 1396 }
1402 return GNUNET_OK; 1397 return GNUNET_OK;
1403} 1398}
1404 1399
@@ -1411,26 +1406,26 @@ GNUNET_TESTING_peer_start (struct GNUNET_TESTING_Peer *peer)
1411 * or upon any error while sending SIGTERM 1406 * or upon any error while sending SIGTERM
1412 */ 1407 */
1413int 1408int
1414GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer) 1409GNUNET_TESTING_peer_kill(struct GNUNET_TESTING_Peer *peer)
1415{ 1410{
1416 struct SharedServiceInstance *i; 1411 struct SharedServiceInstance *i;
1417 unsigned int cnt; 1412 unsigned int cnt;
1418 1413
1419 if (NULL == peer->main_process) 1414 if (NULL == peer->main_process)
1420 { 1415 {
1421 GNUNET_break (0); 1416 GNUNET_break(0);
1422 return GNUNET_SYSERR; 1417 return GNUNET_SYSERR;
1423 } 1418 }
1424 if (0 != GNUNET_OS_process_kill (peer->main_process, GNUNET_TERM_SIG)) 1419 if (0 != GNUNET_OS_process_kill(peer->main_process, GNUNET_TERM_SIG))
1425 return GNUNET_SYSERR; 1420 return GNUNET_SYSERR;
1426 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++) 1421 for (cnt = 0; cnt < peer->system->n_shared_services; cnt++)
1427 { 1422 {
1428 i = peer->ss_instances[cnt]; 1423 i = peer->ss_instances[cnt];
1429 GNUNET_assert (0 != i->n_refs); 1424 GNUNET_assert(0 != i->n_refs);
1430 i->n_refs--; 1425 i->n_refs--;
1431 if (0 == i->n_refs) 1426 if (0 == i->n_refs)
1432 stop_shared_service_instance (i); 1427 stop_shared_service_instance(i);
1433 } 1428 }
1434 return GNUNET_OK; 1429 return GNUNET_OK;
1435} 1430}
1436 1431
@@ -1443,17 +1438,17 @@ GNUNET_TESTING_peer_kill (struct GNUNET_TESTING_Peer *peer)
1443 * or upon any error while waiting 1438 * or upon any error while waiting
1444 */ 1439 */
1445int 1440int
1446GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer) 1441GNUNET_TESTING_peer_wait(struct GNUNET_TESTING_Peer *peer)
1447{ 1442{
1448 int ret; 1443 int ret;
1449 1444
1450 if (NULL == peer->main_process) 1445 if (NULL == peer->main_process)
1451 { 1446 {
1452 GNUNET_break (0); 1447 GNUNET_break(0);
1453 return GNUNET_SYSERR; 1448 return GNUNET_SYSERR;
1454 } 1449 }
1455 ret = GNUNET_OS_process_wait (peer->main_process); 1450 ret = GNUNET_OS_process_wait(peer->main_process);
1456 GNUNET_OS_process_destroy (peer->main_process); 1451 GNUNET_OS_process_destroy(peer->main_process);
1457 peer->main_process = NULL; 1452 peer->main_process = NULL;
1458 return ret; 1453 return ret;
1459} 1454}
@@ -1466,11 +1461,11 @@ GNUNET_TESTING_peer_wait (struct GNUNET_TESTING_Peer *peer)
1466 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1461 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1467 */ 1462 */
1468int 1463int
1469GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer) 1464GNUNET_TESTING_peer_stop(struct GNUNET_TESTING_Peer *peer)
1470{ 1465{
1471 if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill (peer)) 1466 if (GNUNET_SYSERR == GNUNET_TESTING_peer_kill(peer))
1472 return GNUNET_SYSERR; 1467 return GNUNET_SYSERR;
1473 if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait (peer)) 1468 if (GNUNET_SYSERR == GNUNET_TESTING_peer_wait(peer))
1474 return GNUNET_SYSERR; 1469 return GNUNET_SYSERR;
1475 return GNUNET_OK; 1470 return GNUNET_OK;
1476} 1471}
@@ -1484,24 +1479,24 @@ GNUNET_TESTING_peer_stop (struct GNUNET_TESTING_Peer *peer)
1484 * #GNUNET_SYSERR on error. 1479 * #GNUNET_SYSERR on error.
1485 */ 1480 */
1486static void 1481static void
1487disconn_status (void *cls, int connected) 1482disconn_status(void *cls, int connected)
1488{ 1483{
1489 struct GNUNET_TESTING_Peer *peer = cls; 1484 struct GNUNET_TESTING_Peer *peer = cls;
1490 1485
1491 if (GNUNET_SYSERR == connected) 1486 if (GNUNET_SYSERR == connected)
1492 { 1487 {
1493 peer->cb (peer->cb_cls, peer, connected); 1488 peer->cb(peer->cb_cls, peer, connected);
1494 return; 1489 return;
1495 } 1490 }
1496 if (GNUNET_YES == connected) 1491 if (GNUNET_YES == connected)
1497 { 1492 {
1498 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_kill (peer)); 1493 GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_kill(peer));
1499 return; 1494 return;
1500 } 1495 }
1501 GNUNET_break (GNUNET_OK == GNUNET_TESTING_peer_wait (peer)); 1496 GNUNET_break(GNUNET_OK == GNUNET_TESTING_peer_wait(peer));
1502 GNUNET_ARM_disconnect (peer->ah); 1497 GNUNET_ARM_disconnect(peer->ah);
1503 peer->ah = NULL; 1498 peer->ah = NULL;
1504 peer->cb (peer->cb_cls, peer, GNUNET_YES); 1499 peer->cb(peer->cb_cls, peer, GNUNET_YES);
1505} 1500}
1506 1501
1507 1502
@@ -1517,13 +1512,13 @@ disconn_status (void *cls, int connected)
1517 * upon any error. 1512 * upon any error.
1518 */ 1513 */
1519int 1514int
1520GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer, 1515GNUNET_TESTING_peer_stop_async(struct GNUNET_TESTING_Peer *peer,
1521 GNUNET_TESTING_PeerStopCallback cb, 1516 GNUNET_TESTING_PeerStopCallback cb,
1522 void *cb_cls) 1517 void *cb_cls)
1523{ 1518{
1524 if (NULL == peer->main_process) 1519 if (NULL == peer->main_process)
1525 return GNUNET_SYSERR; 1520 return GNUNET_SYSERR;
1526 peer->ah = GNUNET_ARM_connect (peer->cfg, &disconn_status, peer); 1521 peer->ah = GNUNET_ARM_connect(peer->cfg, &disconn_status, peer);
1527 if (NULL == peer->ah) 1522 if (NULL == peer->ah)
1528 return GNUNET_SYSERR; 1523 return GNUNET_SYSERR;
1529 peer->cb = cb; 1524 peer->cb = cb;
@@ -1542,10 +1537,10 @@ GNUNET_TESTING_peer_stop_async (struct GNUNET_TESTING_Peer *peer,
1542 * before. 1537 * before.
1543 */ 1538 */
1544void 1539void
1545GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer) 1540GNUNET_TESTING_peer_stop_async_cancel(struct GNUNET_TESTING_Peer *peer)
1546{ 1541{
1547 GNUNET_assert (NULL != peer->ah); 1542 GNUNET_assert(NULL != peer->ah);
1548 GNUNET_ARM_disconnect (peer->ah); 1543 GNUNET_ARM_disconnect(peer->ah);
1549 peer->ah = NULL; 1544 peer->ah = NULL;
1550} 1545}
1551 1546
@@ -1558,28 +1553,28 @@ GNUNET_TESTING_peer_stop_async_cancel (struct GNUNET_TESTING_Peer *peer)
1558 * @param peer peer to destroy 1553 * @param peer peer to destroy
1559 */ 1554 */
1560void 1555void
1561GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer) 1556GNUNET_TESTING_peer_destroy(struct GNUNET_TESTING_Peer *peer)
1562{ 1557{
1563 unsigned int cnt; 1558 unsigned int cnt;
1564 1559
1565 if (NULL != peer->main_process) 1560 if (NULL != peer->main_process)
1566 GNUNET_TESTING_peer_stop (peer); 1561 GNUNET_TESTING_peer_stop(peer);
1567 if (NULL != peer->ah) 1562 if (NULL != peer->ah)
1568 GNUNET_ARM_disconnect (peer->ah); 1563 GNUNET_ARM_disconnect(peer->ah);
1569 GNUNET_free (peer->cfgfile); 1564 GNUNET_free(peer->cfgfile);
1570 if (NULL != peer->cfg) 1565 if (NULL != peer->cfg)
1571 GNUNET_CONFIGURATION_destroy (peer->cfg); 1566 GNUNET_CONFIGURATION_destroy(peer->cfg);
1572 GNUNET_free (peer->main_binary); 1567 GNUNET_free(peer->main_binary);
1573 GNUNET_free (peer->args); 1568 GNUNET_free(peer->args);
1574 GNUNET_free_non_null (peer->id); 1569 GNUNET_free_non_null(peer->id);
1575 GNUNET_free_non_null (peer->ss_instances); 1570 GNUNET_free_non_null(peer->ss_instances);
1576 if (NULL != peer->ports) 1571 if (NULL != peer->ports)
1577 { 1572 {
1578 for (cnt = 0; cnt < peer->nports; cnt++) 1573 for (cnt = 0; cnt < peer->nports; cnt++)
1579 GNUNET_TESTING_release_port (peer->system, peer->ports[cnt]); 1574 GNUNET_TESTING_release_port(peer->system, peer->ports[cnt]);
1580 GNUNET_free (peer->ports); 1575 GNUNET_free(peer->ports);
1581 } 1576 }
1582 GNUNET_free (peer); 1577 GNUNET_free(peer);
1583} 1578}
1584 1579
1585 1580
@@ -1600,20 +1595,19 @@ GNUNET_TESTING_peer_destroy (struct GNUNET_TESTING_Peer *peer)
1600 * @return 0 on success, 1 on error 1595 * @return 0 on success, 1 on error
1601 */ 1596 */
1602int 1597int
1603GNUNET_TESTING_peer_run (const char *testdir, 1598GNUNET_TESTING_peer_run(const char *testdir,
1604 const char *cfgfilename, 1599 const char *cfgfilename,
1605 GNUNET_TESTING_TestMain tm, 1600 GNUNET_TESTING_TestMain tm,
1606 void *tm_cls) 1601 void *tm_cls)
1607{ 1602{
1608 return GNUNET_TESTING_service_run (testdir, "arm", cfgfilename, tm, tm_cls); 1603 return GNUNET_TESTING_service_run(testdir, "arm", cfgfilename, tm, tm_cls);
1609} 1604}
1610 1605
1611 1606
1612/** 1607/**
1613 * Structure for holding service data 1608 * Structure for holding service data
1614 */ 1609 */
1615struct ServiceContext 1610struct ServiceContext {
1616{
1617 /** 1611 /**
1618 * The configuration of the peer in which the service is run 1612 * The configuration of the peer in which the service is run
1619 */ 1613 */
@@ -1642,11 +1636,11 @@ struct ServiceContext
1642 * @param cls the ServiceContext 1636 * @param cls the ServiceContext
1643 */ 1637 */
1644static void 1638static void
1645service_run_main (void *cls) 1639service_run_main(void *cls)
1646{ 1640{
1647 struct ServiceContext *sc = cls; 1641 struct ServiceContext *sc = cls;
1648 1642
1649 sc->tm (sc->tm_cls, sc->cfg, sc->peer); 1643 sc->tm(sc->tm_cls, sc->cfg, sc->peer);
1650} 1644}
1651 1645
1652 1646
@@ -1672,11 +1666,11 @@ service_run_main (void *cls)
1672 * @return 0 on success, 1 on error 1666 * @return 0 on success, 1 on error
1673 */ 1667 */
1674int 1668int
1675GNUNET_TESTING_service_run (const char *testdir, 1669GNUNET_TESTING_service_run(const char *testdir,
1676 const char *service_name, 1670 const char *service_name,
1677 const char *cfgfilename, 1671 const char *cfgfilename,
1678 GNUNET_TESTING_TestMain tm, 1672 GNUNET_TESTING_TestMain tm,
1679 void *tm_cls) 1673 void *tm_cls)
1680{ 1674{
1681 struct ServiceContext sc; 1675 struct ServiceContext sc;
1682 struct GNUNET_TESTING_System *system; 1676 struct GNUNET_TESTING_System *system;
@@ -1685,70 +1679,70 @@ GNUNET_TESTING_service_run (const char *testdir,
1685 char *binary; 1679 char *binary;
1686 char *libexec_binary; 1680 char *libexec_binary;
1687 1681
1688 GNUNET_log_setup (testdir, "WARNING", NULL); 1682 GNUNET_log_setup(testdir, "WARNING", NULL);
1689 system = GNUNET_TESTING_system_create (testdir, "127.0.0.1", NULL, NULL); 1683 system = GNUNET_TESTING_system_create(testdir, "127.0.0.1", NULL, NULL);
1690 if (NULL == system) 1684 if (NULL == system)
1691 return 1; 1685 return 1;
1692 cfg = GNUNET_CONFIGURATION_create (); 1686 cfg = GNUNET_CONFIGURATION_create();
1693 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfgfilename)) 1687 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfgfilename))
1694 { 1688 {
1695 LOG (GNUNET_ERROR_TYPE_ERROR, 1689 LOG(GNUNET_ERROR_TYPE_ERROR,
1696 _ ("Failed to load configuration from %s\n"), 1690 _("Failed to load configuration from %s\n"),
1697 cfgfilename); 1691 cfgfilename);
1698 GNUNET_CONFIGURATION_destroy (cfg); 1692 GNUNET_CONFIGURATION_destroy(cfg);
1699 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1693 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
1700 return 1; 1694 return 1;
1701 } 1695 }
1702 peer = GNUNET_TESTING_peer_configure (system, cfg, 0, NULL, NULL); 1696 peer = GNUNET_TESTING_peer_configure(system, cfg, 0, NULL, NULL);
1703 if (NULL == peer) 1697 if (NULL == peer)
1704 { 1698 {
1705 GNUNET_CONFIGURATION_destroy (cfg); 1699 GNUNET_CONFIGURATION_destroy(cfg);
1706 hostkeys_unload (system); 1700 hostkeys_unload(system);
1707 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1701 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
1708 return 1; 1702 return 1;
1709 } 1703 }
1710 GNUNET_free (peer->main_binary); 1704 GNUNET_free(peer->main_binary);
1711 GNUNET_free (peer->args); 1705 GNUNET_free(peer->args);
1712 GNUNET_asprintf (&binary, "gnunet-service-%s", service_name); 1706 GNUNET_asprintf(&binary, "gnunet-service-%s", service_name);
1713 libexec_binary = GNUNET_OS_get_libexec_binary_path (binary); 1707 libexec_binary = GNUNET_OS_get_libexec_binary_path(binary);
1714 if (GNUNET_SYSERR == 1708 if (GNUNET_SYSERR ==
1715 GNUNET_CONFIGURATION_get_value_string (cfg, 1709 GNUNET_CONFIGURATION_get_value_string(cfg,
1716 service_name, 1710 service_name,
1717 "PREFIX", 1711 "PREFIX",
1718 &peer->main_binary)) 1712 &peer->main_binary))
1719 { 1713 {
1720 /* No prefix */ 1714 /* No prefix */
1721 GNUNET_asprintf (&peer->main_binary, "%s", libexec_binary); 1715 GNUNET_asprintf(&peer->main_binary, "%s", libexec_binary);
1722 peer->args = GNUNET_strdup (""); 1716 peer->args = GNUNET_strdup("");
1723 } 1717 }
1724 else 1718 else
1725 peer->args = GNUNET_strdup (libexec_binary); 1719 peer->args = GNUNET_strdup(libexec_binary);
1726 1720
1727 GNUNET_free (libexec_binary); 1721 GNUNET_free(libexec_binary);
1728 GNUNET_free (binary); 1722 GNUNET_free(binary);
1729 if (GNUNET_OK != GNUNET_TESTING_peer_start (peer)) 1723 if (GNUNET_OK != GNUNET_TESTING_peer_start(peer))
1730 { 1724 {
1731 GNUNET_TESTING_peer_destroy (peer); 1725 GNUNET_TESTING_peer_destroy(peer);
1732 GNUNET_CONFIGURATION_destroy (cfg); 1726 GNUNET_CONFIGURATION_destroy(cfg);
1733 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1727 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
1734 return 1; 1728 return 1;
1735 } 1729 }
1736 sc.cfg = cfg; 1730 sc.cfg = cfg;
1737 sc.tm = tm; 1731 sc.tm = tm;
1738 sc.tm_cls = tm_cls; 1732 sc.tm_cls = tm_cls;
1739 sc.peer = peer; 1733 sc.peer = peer;
1740 GNUNET_SCHEDULER_run (&service_run_main, &sc); /* Scheduler loop */ 1734 GNUNET_SCHEDULER_run(&service_run_main, &sc); /* Scheduler loop */
1741 if ((NULL != peer->main_process) && 1735 if ((NULL != peer->main_process) &&
1742 (GNUNET_OK != GNUNET_TESTING_peer_stop (peer))) 1736 (GNUNET_OK != GNUNET_TESTING_peer_stop(peer)))
1743 { 1737 {
1744 GNUNET_TESTING_peer_destroy (peer); 1738 GNUNET_TESTING_peer_destroy(peer);
1745 GNUNET_CONFIGURATION_destroy (cfg); 1739 GNUNET_CONFIGURATION_destroy(cfg);
1746 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1740 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
1747 return 1; 1741 return 1;
1748 } 1742 }
1749 GNUNET_TESTING_peer_destroy (peer); 1743 GNUNET_TESTING_peer_destroy(peer);
1750 GNUNET_CONFIGURATION_destroy (cfg); 1744 GNUNET_CONFIGURATION_destroy(cfg);
1751 GNUNET_TESTING_system_destroy (system, GNUNET_YES); 1745 GNUNET_TESTING_system_destroy(system, GNUNET_YES);
1752 return 0; 1746 return 0;
1753} 1747}
1754 1748
@@ -1767,22 +1761,22 @@ GNUNET_TESTING_service_run (const char *testdir,
1767 * NULL if argv0 has no '_' 1761 * NULL if argv0 has no '_'
1768 */ 1762 */
1769char * 1763char *
1770GNUNET_TESTING_get_testname_from_underscore (const char *argv0) 1764GNUNET_TESTING_get_testname_from_underscore(const char *argv0)
1771{ 1765{
1772 size_t slen = strlen (argv0) + 1; 1766 size_t slen = strlen(argv0) + 1;
1773 char sbuf[slen]; 1767 char sbuf[slen];
1774 char *ret; 1768 char *ret;
1775 char *dot; 1769 char *dot;
1776 1770
1777 GNUNET_memcpy (sbuf, argv0, slen); 1771 GNUNET_memcpy(sbuf, argv0, slen);
1778 ret = strrchr (sbuf, '_'); 1772 ret = strrchr(sbuf, '_');
1779 if (NULL == ret) 1773 if (NULL == ret)
1780 return NULL; 1774 return NULL;
1781 ret++; /* skip underscore */ 1775 ret++; /* skip underscore */
1782 dot = strchr (ret, '.'); 1776 dot = strchr(ret, '.');
1783 if (NULL != dot) 1777 if (NULL != dot)
1784 *dot = '\0'; 1778 *dot = '\0';
1785 return GNUNET_strdup (ret); 1779 return GNUNET_strdup(ret);
1786} 1780}
1787 1781
1788 1782