aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-05-28 15:53:38 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-05-28 15:53:38 +0000
commitdd0683bcbd7f3f7b9a607f07c58be9cc1d722cd9 (patch)
treef0061d231ba9ceaf6585263dde0d8d160e4881a9 /src
parent585609670e08b923a1ebd173d0b671d0de0e1424 (diff)
downloadgnunet-dd0683bcbd7f3f7b9a607f07c58be9cc1d722cd9.tar.gz
gnunet-dd0683bcbd7f3f7b9a607f07c58be9cc1d722cd9.zip
-configuration from template
Diffstat (limited to 'src')
-rw-r--r--src/testing/test_testing_defaults.conf2
-rw-r--r--src/testing/testing_new.c181
2 files changed, 169 insertions, 14 deletions
diff --git a/src/testing/test_testing_defaults.conf b/src/testing/test_testing_defaults.conf
index f8b3af280..ba7e269a6 100644
--- a/src/testing/test_testing_defaults.conf
+++ b/src/testing/test_testing_defaults.conf
@@ -75,4 +75,4 @@ AUTOSTART = NO
75AUTOSTART = NO 75AUTOSTART = NO
76 76
77[lockmanager] 77[lockmanager]
78AUTOSTART = NO \ No newline at end of file 78AUTOSTART = NO
diff --git a/src/testing/testing_new.c b/src/testing/testing_new.c
index ba12e065a..ecbe0d2bb 100644
--- a/src/testing/testing_new.c
+++ b/src/testing/testing_new.c
@@ -30,8 +30,7 @@
30 * 30 *
31 */ 31 */
32#include "platform.h" 32#include "platform.h"
33#include "gnunet_disk_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_network_lib.h"
35#include "gnunet_testing_lib-new.h" 34#include "gnunet_testing_lib-new.h"
36 35
37#define LOG(kind,...) \ 36#define LOG(kind,...) \
@@ -99,11 +98,6 @@ struct GNUNET_TESTING_System
99 * we never re-use path counters. 98 * we never re-use path counters.
100 */ 99 */
101 uint32_t path_counter; 100 uint32_t path_counter;
102
103 /**
104 * Last used port number
105 */
106
107}; 101};
108 102
109 103
@@ -413,6 +407,155 @@ GNUNET_TESTING_hostkey_get (uint32_t key_number,
413 407
414 408
415/** 409/**
410 * Structure for holding data to build new configurations from a configuration
411 * template
412 */
413struct UpdateContext
414{
415 /**
416 * The system for which we are building configurations
417 */
418 struct GNUNET_TESTING_System *system;
419
420 /**
421 * The original configuration template
422 */
423 const struct GNUNET_CONFIGURATION_Handle *orig;
424
425 /**
426 * The configuration we are building
427 */
428 struct GNUNET_CONFIGURATION_Handle *cfg;
429
430 /**
431 * build status - to signal error while building a configuration
432 */
433 int status;
434};
435
436
437/**
438 * Function to iterate over options. Copies
439 * the options to the target configuration,
440 * updating PORT values as needed.
441 *
442 * @param cls the UpdateContext
443 * @param section name of the section
444 * @param option name of the option
445 * @param value value of the option
446 */
447static void
448update_config (void *cls, const char *section, const char *option,
449 const char *value)
450{
451 struct UpdateContext *uc = cls;
452 unsigned int ival;
453 char cval[12];
454 char uval[128];
455 char *single_variable;
456 char *per_host_variable;
457 unsigned long long num_per_host;
458 uint16_t new_port;
459
460 if (GNUNET_OK != uc->status)
461 return;
462 GNUNET_asprintf (&single_variable, "single_%s_per_host", section);
463 GNUNET_asprintf (&per_host_variable, "num_%s_per_host", section);
464 if ((0 == strcmp (option, "PORT")) && (1 == SSCANF (value, "%u", &ival)))
465 {
466 if ((ival != 0) &&
467 (GNUNET_YES !=
468 GNUNET_CONFIGURATION_get_value_yesno (uc->orig, "testing",
469 single_variable)))
470 {
471 /* FIXME: What about UDP? */
472 new_port = GNUNET_TESTING_reserve_port (uc->system, GNUNET_YES);
473 if (0 == new_port)
474 {
475 uc->status = GNUNET_SYSERR;
476 return;
477 }
478 GNUNET_snprintf (cval, sizeof (cval), "%u", new_port);
479 value = cval;
480 }
481 else if ((ival != 0) &&
482 (GNUNET_YES ==
483 GNUNET_CONFIGURATION_get_value_yesno (uc->orig, "testing",
484 single_variable)) &&
485 GNUNET_CONFIGURATION_get_value_number (uc->orig, "testing",
486 per_host_variable,
487 &num_per_host))
488 {
489 /* GNUNET_snprintf (cval, sizeof (cval), "%u", */
490 /* ival + ctx->fdnum % num_per_host); */
491 /* value = cval; */
492 GNUNET_break (0); /* FIXME */
493 }
494 }
495 if (0 == strcmp (option, "UNIXPATH"))
496 {
497 if (GNUNET_YES !=
498 GNUNET_CONFIGURATION_get_value_yesno (uc->orig, "testing",
499 single_variable))
500 {
501 GNUNET_snprintf (uval, sizeof (uval), "%s-%s-%u",
502 uc->system->tmppath,
503 section,
504 uc->system->path_counter++);
505 value = uval;
506 }
507 else if ((GNUNET_YES ==
508 GNUNET_CONFIGURATION_get_value_number (uc->orig, "testing",
509 per_host_variable,
510 &num_per_host)) &&
511 (num_per_host > 0))
512 {
513 GNUNET_break(0); /* FIXME */
514 }
515 }
516 if ((0 == strcmp (option, "HOSTNAME")) && (NULL != uc->system->controller))
517 {
518 value = uc->system->controller;
519 }
520 GNUNET_free (single_variable);
521 GNUNET_free (per_host_variable);
522 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, option, value);
523}
524
525
526/**
527 * Section iterator to set ACCEPT_FROM in all sections
528 *
529 * @param cls the UpdateContext
530 * @param section name of the section
531 */
532static void
533update_config_sections (void *cls,
534 const char *section)
535{
536 struct UpdateContext *uc = cls;
537 char *orig_allowed_hosts;
538 char *allowed_hosts;
539
540 if (GNUNET_OK !=
541 GNUNET_CONFIGURATION_get_value_string (uc->orig, section, "ACCEPT_FROM",
542 &orig_allowed_hosts))
543 {
544 orig_allowed_hosts = "127.0.0.1;";
545 }
546 if (NULL == uc->system->controller)
547 allowed_hosts = GNUNET_strdup (orig_allowed_hosts);
548 else
549 GNUNET_asprintf (&allowed_hosts, "%s %s;", orig_allowed_hosts,
550 uc->system->controller);
551 GNUNET_CONFIGURATION_set_value_string (uc->cfg, section, "ACCEPT_FROM",
552 allowed_hosts);
553 GNUNET_free (allowed_hosts);
554
555}
556
557
558/**
416 * Create a new configuration using the given configuration 559 * Create a new configuration using the given configuration
417 * as a template; ports and paths will be modified to select 560 * as a template; ports and paths will be modified to select
418 * available ports on the local system. If we run 561 * available ports on the local system. If we run
@@ -422,15 +565,27 @@ GNUNET_TESTING_hostkey_get (uint32_t key_number,
422 * by 'GNUNET_TESTING_peer_configure'. 565 * by 'GNUNET_TESTING_peer_configure'.
423 * 566 *
424 * @param system system to use to coordinate resource usage 567 * @param system system to use to coordinate resource usage
425 * @param cfg template configuration to update 568 * @param cfg template configuration
426 * @return GNUNET_OK on success, GNUNET_SYSERR on error 569 * @return the new configuration; NULL upon error;
427 */ 570 */
428int 571struct GNUNET_CONFIGURATION_Handle *
429GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system, 572GNUNET_TESTING_configuration_create (struct GNUNET_TESTING_System *system,
430 struct GNUNET_CONFIGURATION_Handle *cfg) 573 const struct GNUNET_CONFIGURATION_Handle *cfg)
431{ 574{
432 GNUNET_break (0); 575 struct UpdateContext uc;
433 return GNUNET_SYSERR; 576
577 uc.system = system;
578 uc.orig = cfg;
579 uc.cfg = GNUNET_CONFIGURATION_create ();
580 GNUNET_CONFIGURATION_iterate (cfg, &update_config, &uc);
581 if (GNUNET_OK != uc.status)
582 {
583 GNUNET_CONFIGURATION_destroy (uc.cfg);
584 return NULL;
585 }
586 GNUNET_CONFIGURATION_iterate_sections (cfg, &update_config_sections, &uc);
587 /* FIXME: add other options which enable communication with controller */
588 return uc.cfg;
434} 589}
435 590
436 591