X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fnat-auto%2Fgnunet-nat-auto.c;h=5eb0a4be3fe93d4c95db5e3a2cc1bb82fc0fc52c;hb=79fb947eb8fba243ea65e19b40b65e04f8806865;hp=3b9a5fa946538395e79a81abee0043b09cc40283;hpb=80e1315b56f559db60499f5373e90c293c5ab065;p=oweals%2Fgnunet.git diff --git a/src/nat-auto/gnunet-nat-auto.c b/src/nat-auto/gnunet-nat-auto.c index 3b9a5fa94..5eb0a4be3 100644 --- a/src/nat-auto/gnunet-nat-auto.c +++ b/src/nat-auto/gnunet-nat-auto.c @@ -37,7 +37,7 @@ static int global_ret; /** * Handle to ongoing autoconfiguration. */ -static struct GNUNET_NAT_AutoHandle *ah; +static struct GNUNET_NAT_AUTO_AutoHandle *ah; /** * If we do auto-configuration, should we write the result @@ -47,7 +47,7 @@ static int write_cfg; /** * Configuration filename. - */ + */ static const char *cfg_file; /** @@ -56,16 +56,9 @@ static const char *cfg_file; static const struct GNUNET_CONFIGURATION_Handle *cfg; /** - * Address we are bound to (in test), or should bind to - * (if #do_stun is set). - */ -static char *bind_addr; - -/** - * External IP address and port to use for the test. - * If not set, use #bind_addr. + * Adapter we are supposed to test. */ -static char *extern_addr; +static char *section_name; /** * Should we run autoconfiguration? @@ -75,7 +68,7 @@ static unsigned int do_auto; /** * Handle to a NAT test operation. */ -static struct GNUNET_NAT_Test *nt; +static struct GNUNET_NAT_AUTO_Test *nt; /** * Flag set to 1 if we use IPPROTO_UDP. @@ -122,7 +115,7 @@ auto_conf_iter (void *cls, const char *value) { struct GNUNET_CONFIGURATION_Handle *new_cfg = cls; - + PRINTF ("%s: %s\n", option, value); @@ -178,9 +171,12 @@ auto_config_cb (void *cls, GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "NAT status: %s/%s\n", - GNUNET_NAT_status2string (result), + GNUNET_NAT_AUTO_status2string (result), nat_type); + if (NULL == diff) + return; + /* Shortcut: if there are no changes suggested, bail out early. */ if (GNUNET_NO == GNUNET_CONFIGURATION_is_dirty (diff)) @@ -192,21 +188,17 @@ auto_config_cb (void *cls, /* Apply diff to original configuration and show changes to the user */ new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL; - - if (NULL != diff) - { - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - _("Suggested configuration changes:\n")); - GNUNET_CONFIGURATION_iterate_section_values (diff, - "nat", - &auto_conf_iter, - new_cfg); - } + + GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, + _("Suggested configuration changes:\n")); + GNUNET_CONFIGURATION_iterate_section_values (diff, + "nat", + &auto_conf_iter, + new_cfg); /* If desired, write configuration to file; we write only the changes to the defaults to keep things compact. */ - if ( (write_cfg) && - (NULL != diff) ) + if (write_cfg) { struct GNUNET_CONFIGURATION_Handle *def_cfg; @@ -256,7 +248,7 @@ test_report_cb (void *cls, { nt = NULL; PRINTF ("NAT test result: %s\n", - GNUNET_NAT_status2string (result)); + GNUNET_NAT_AUTO_status2string (result)); test_finished (); } @@ -271,12 +263,12 @@ do_shutdown (void *cls) { if (NULL != ah) { - GNUNET_NAT_autoconfig_cancel (ah); + GNUNET_NAT_AUTO_autoconfig_cancel (ah); ah = NULL; } if (NULL != nt) { - GNUNET_NAT_test_stop (nt); + GNUNET_NAT_AUTO_test_stop (nt); nt = NULL; } } @@ -296,20 +288,17 @@ run (void *cls, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) { - struct sockaddr_in bind_sa; - struct sockaddr_in extern_sa; - cfg_file = cfgfile; cfg = c; - + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); if (do_auto) { - ah = GNUNET_NAT_autoconfig_start (c, - &auto_config_cb, - NULL); + ah = GNUNET_NAT_AUTO_autoconfig_start (c, + &auto_config_cb, + NULL); } if (use_tcp && use_udp) @@ -327,54 +316,20 @@ run (void *cls, if (use_udp) proto = IPPROTO_UDP; - if (NULL != bind_addr) - { - if (GNUNET_OK != - GNUNET_STRINGS_to_address_ipv4 (bind_addr, - strlen (bind_addr), - &bind_sa)) - { - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "Invalid socket address `%s'\n", - bind_addr); - global_ret = 1; - return; - } - } - if (NULL != extern_addr) - { - if (GNUNET_OK != - GNUNET_STRINGS_to_address_ipv4 (extern_addr, - strlen (extern_addr), - &extern_sa)) - { - GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, - "Invalid socket address `%s'\n", - extern_addr); - global_ret = 1; - return; - } - } - - if (NULL != bind_addr) + if (NULL != section_name) { - if (NULL == extern_addr) - extern_sa = bind_sa; - nt = GNUNET_NAT_test_start (c, - proto, - bind_sa.sin_addr, - ntohs (bind_sa.sin_port), - extern_sa.sin_addr, - ntohs (extern_sa.sin_port), - &test_report_cb, - NULL); + nt = GNUNET_NAT_AUTO_test_start (c, + proto, + section_name, + &test_report_cb, + NULL); } test_finished (); } /** - * Main function of gnunet-nat + * Main function of gnunet-nat-auto * * @param argc number of command-line arguments * @param argv command line @@ -388,12 +343,9 @@ main (int argc, {'a', "auto", NULL, gettext_noop ("run autoconfiguration"), GNUNET_NO, &GNUNET_GETOPT_set_one, &do_auto }, - {'b', "bind", "ADDRESS", - gettext_noop ("which IP and port are we bound to"), - GNUNET_YES, &GNUNET_GETOPT_set_string, &bind_addr }, - {'e', "external", "ADDRESS", - gettext_noop ("which external IP and port should be used to test"), - GNUNET_YES, &GNUNET_GETOPT_set_string, &extern_addr }, + {'S', "section", "NAME", + gettext_noop ("section name providing the configuration for the adapter"), + GNUNET_YES, &GNUNET_GETOPT_set_string, §ion_name }, {'t', "tcp", NULL, gettext_noop ("use TCP"), GNUNET_NO, &GNUNET_GETOPT_set_one, &use_tcp },