aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/man/gnunet-nat.14
-rw-r--r--src/include/gnunet_configuration_lib.h2
-rw-r--r--src/nat/gnunet-nat.c92
3 files changed, 91 insertions, 7 deletions
diff --git a/doc/man/gnunet-nat.1 b/doc/man/gnunet-nat.1
index a43223fa8..9cc8b1237 100644
--- a/doc/man/gnunet-nat.1
+++ b/doc/man/gnunet-nat.1
@@ -58,6 +58,10 @@ Use TCP.
58.IP "\-u, \-\-udp" 58.IP "\-u, \-\-udp"
59Use UDP. 59Use UDP.
60 60
61.B
62.IP "\-w, \-\-write"
63Write configuration to configuration file, useful in combination with autoconfiguration (\-a).
64
61.SH BUGS 65.SH BUGS
62Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org> 66Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org>
63 67
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index 945f3ca59..746dea61f 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -89,7 +89,7 @@ GNUNET_CONFIGURATION_load (struct GNUNET_CONFIGURATION_Handle *cfg,
89 89
90/** 90/**
91 * Load default configuration. This function will parse the 91 * Load default configuration. This function will parse the
92 * defaults from the given defaults_d directory. 92 * defaults from the given @a defaults_d directory.
93 * 93 *
94 * @param cfg configuration to update 94 * @param cfg configuration to update
95 * @param defaults_d directory with the defaults 95 * @param defaults_d directory with the defaults
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index 7d10167ce..f3e26ffb1 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -59,6 +59,22 @@ static int listen_reversal;
59static int use_tcp; 59static int use_tcp;
60 60
61/** 61/**
62 * If we do auto-configuration, should we write the result
63 * to a file?
64 */
65static int write_cfg;
66
67/**
68 * Configuration filename.
69 */
70static const char *cfg_file;
71
72/**
73 * Original configuration.
74 */
75static const struct GNUNET_CONFIGURATION_Handle *cfg;
76
77/**
62 * Protocol to use. 78 * Protocol to use.
63 */ 79 */
64static uint8_t proto; 80static uint8_t proto;
@@ -149,9 +165,16 @@ auto_conf_iter (void *cls,
149 const char *option, 165 const char *option,
150 const char *value) 166 const char *value)
151{ 167{
168 struct GNUNET_CONFIGURATION_Handle *new_cfg = cls;
169
152 PRINTF ("%s: %s\n", 170 PRINTF ("%s: %s\n",
153 option, 171 option,
154 value); 172 value);
173 if (NULL != new_cfg)
174 GNUNET_CONFIGURATION_set_value_string (new_cfg,
175 section,
176 option,
177 value);
155} 178}
156 179
157 180
@@ -172,6 +195,7 @@ auto_config_cb (void *cls,
172{ 195{
173 const char *nat_type; 196 const char *nat_type;
174 char unknown_type[64]; 197 char unknown_type[64];
198 struct GNUNET_CONFIGURATION_Handle *new_cfg;
175 199
176 ah = NULL; 200 ah = NULL;
177 switch (type) 201 switch (type)
@@ -196,19 +220,69 @@ auto_config_cb (void *cls,
196 break; 220 break;
197 } 221 }
198 222
199 PRINTF ("NAT status: %s/%s\n", 223 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
200 GNUNET_NAT_status2string (result), 224 "NAT status: %s/%s\n",
201 nat_type); 225 GNUNET_NAT_status2string (result),
226 nat_type);
227
228 /* Shortcut: if there are no changes suggested, bail out early. */
229 if (GNUNET_NO ==
230 GNUNET_CONFIGURATION_is_dirty (diff))
231 {
232 test_finished ();
233 return;
234 }
202 235
236 /* Apply diff to original configuration and show changes
237 to the user */
238 new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL;
239
203 if (NULL != diff) 240 if (NULL != diff)
204 { 241 {
205 PRINTF ("SUGGESTED CHANGES:\n"); 242 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
243 _("Suggested configuration changes:\n"));
206 GNUNET_CONFIGURATION_iterate_section_values (diff, 244 GNUNET_CONFIGURATION_iterate_section_values (diff,
207 "nat", 245 "nat",
208 &auto_conf_iter, 246 &auto_conf_iter,
209 NULL); 247 new_cfg);
248 }
249
250 /* If desired, write configuration to file; we write only the
251 changes to the defaults to keep things compact. */
252 if ( (write_cfg) &&
253 (NULL != diff) )
254 {
255 struct GNUNET_CONFIGURATION_Handle *def_cfg;
256
257 GNUNET_CONFIGURATION_set_value_string (new_cfg,
258 "ARM",
259 "CONFIG",
260 NULL);
261 def_cfg = GNUNET_CONFIGURATION_create ();
262 GNUNET_break (GNUNET_OK ==
263 GNUNET_CONFIGURATION_load (def_cfg,
264 NULL));
265 if (GNUNET_OK !=
266 GNUNET_CONFIGURATION_write_diffs (def_cfg,
267 new_cfg,
268 cfg_file))
269 {
270 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
271 _("Failed to write configuration to `%s'\n"),
272 cfg_file);
273 global_ret = 1;
274 }
275 else
276 {
277 GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
278 _("Wrote updated configuration to `%s'\n"),
279 cfg_file);
280 }
281 GNUNET_CONFIGURATION_destroy (def_cfg);
210 } 282 }
211 // FIXME: have option to save config 283
284 if (NULL != new_cfg)
285 GNUNET_CONFIGURATION_destroy (new_cfg);
212 test_finished (); 286 test_finished ();
213} 287}
214 288
@@ -387,6 +461,9 @@ run (void *cls,
387 struct sockaddr *remote_sa; 461 struct sockaddr *remote_sa;
388 size_t local_len; 462 size_t local_len;
389 size_t remote_len; 463 size_t remote_len;
464
465 cfg_file = cfgfile;
466 cfg = c;
390 467
391 if (use_tcp && use_udp) 468 if (use_tcp && use_udp)
392 { 469 {
@@ -631,6 +708,9 @@ main (int argc,
631 {'u', "udp", NULL, 708 {'u', "udp", NULL,
632 gettext_noop ("use UDP"), 709 gettext_noop ("use UDP"),
633 GNUNET_NO, &GNUNET_GETOPT_set_one, &use_udp }, 710 GNUNET_NO, &GNUNET_GETOPT_set_one, &use_udp },
711 {'w', "write", NULL,
712 gettext_noop ("write configuration file (for autoconfiguration)"),
713 GNUNET_NO, &GNUNET_GETOPT_set_one, &write_cfg },
634 GNUNET_GETOPT_OPTION_END 714 GNUNET_GETOPT_OPTION_END
635 }; 715 };
636 716