*/
static int use_tcp;
+/**
+ * If we do auto-configuration, should we write the result
+ * to a file?
+ */
+static int write_cfg;
+
+/**
+ * Configuration filename.
+ */
+static const char *cfg_file;
+
+/**
+ * Original configuration.
+ */
+static const struct GNUNET_CONFIGURATION_Handle *cfg;
+
/**
* Protocol to use.
*/
const char *option,
const char *value)
{
+ struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
+
PRINTF ("%s: %s\n",
option,
value);
+ if (NULL != new_cfg)
+ GNUNET_CONFIGURATION_set_value_string (new_cfg,
+ section,
+ option,
+ value);
}
{
const char *nat_type;
char unknown_type[64];
+ struct GNUNET_CONFIGURATION_Handle *new_cfg;
ah = NULL;
switch (type)
break;
}
- PRINTF ("NAT status: %s/%s\n",
- GNUNET_NAT_status2string (result),
- nat_type);
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ "NAT status: %s/%s\n",
+ GNUNET_NAT_status2string (result),
+ nat_type);
+
+ /* Shortcut: if there are no changes suggested, bail out early. */
+ if (GNUNET_NO ==
+ GNUNET_CONFIGURATION_is_dirty (diff))
+ {
+ test_finished ();
+ return;
+ }
+ /* Apply diff to original configuration and show changes
+ to the user */
+ new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
+
if (NULL != diff)
{
- PRINTF ("SUGGESTED CHANGES:\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ _("Suggested configuration changes:\n"));
GNUNET_CONFIGURATION_iterate_section_values (diff,
"nat",
&auto_conf_iter,
- NULL);
+ 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) )
+ {
+ struct GNUNET_CONFIGURATION_Handle *def_cfg;
+
+ GNUNET_CONFIGURATION_set_value_string (new_cfg,
+ "ARM",
+ "CONFIG",
+ NULL);
+ def_cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_break (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (def_cfg,
+ NULL));
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_write_diffs (def_cfg,
+ new_cfg,
+ cfg_file))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ _("Failed to write configuration to `%s'\n"),
+ cfg_file);
+ global_ret = 1;
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+ _("Wrote updated configuration to `%s'\n"),
+ cfg_file);
+ }
+ GNUNET_CONFIGURATION_destroy (def_cfg);
}
- // FIXME: have option to save config
+
+ if (NULL != new_cfg)
+ GNUNET_CONFIGURATION_destroy (new_cfg);
test_finished ();
}
struct sockaddr *remote_sa;
size_t local_len;
size_t remote_len;
+
+ cfg_file = cfgfile;
+ cfg = c;
if (use_tcp && use_udp)
{
{'u', "udp", NULL,
gettext_noop ("use UDP"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &use_udp },
+ {'w', "write", NULL,
+ gettext_noop ("write configuration file (for autoconfiguration)"),
+ GNUNET_NO, &GNUNET_GETOPT_set_one, &write_cfg },
GNUNET_GETOPT_OPTION_END
};