/**
* 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
/**
* Configuration filename.
- */
+ */
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?
/**
* 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.
const char *value)
{
struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
-
+
PRINTF ("%s: %s\n",
option,
value);
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))
/* 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;
{
nt = NULL;
PRINTF ("NAT test result: %s\n",
- GNUNET_NAT_status2string (result));
+ GNUNET_NAT_AUTO_status2string (result));
test_finished ();
}
{
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;
}
}
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)
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
{'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 },