+/**
+ * Function called by NAT on success.
+ * Clean up and update GUI (with success).
+ *
+ * @param cls test context
+ * @param success currently always GNUNET_OK
+ */
+static void
+result_callback (void *cls, int success)
+{
+ struct TestContext *tc = cls;
+
+ display_test_result (tc, success);
+}
+
+
+/**
+ * Function called if NAT failed to confirm success.
+ * Clean up and update GUI (with failure).
+ *
+ * @param cls test context
+ * @param tc scheduler callback
+ */
+static void
+fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ struct TestContext *tstc = cls;
+
+ tstc->tsk = GNUNET_SCHEDULER_NO_TASK;
+ display_test_result (tstc, GNUNET_NO);
+}
+
+
+/**
+ * Test our plugin's configuration (NAT traversal, etc.).
+ *
+ * @param cfg configuration to test
+ */
+static void
+do_test_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg)
+{
+ char *plugins;
+ char *tok;
+ unsigned long long bnd_port;
+ unsigned long long adv_port;
+ struct TestContext *tc;
+
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "transport", "plugins",
+ &plugins))
+ {
+ FPRINTF (stderr,
+ "%s",
+ _
+ ("No transport plugins configured, peer will never communicate\n"));
+ ret = 4;
+ return;
+ }
+ for (tok = strtok (plugins, " "); tok != NULL; tok = strtok (NULL, " "))
+ {
+ char section[12 + strlen (tok)];
+
+ GNUNET_snprintf (section, sizeof (section), "transport-%s", tok);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg, section, "PORT", &bnd_port))
+ {
+ FPRINTF (stderr,
+ _("No port configured for plugin `%s', cannot test it\n"), tok);
+ continue;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg, section, "ADVERTISED_PORT",
+ &adv_port))
+ adv_port = bnd_port;
+ if (NULL == resolver)
+ resolver =
+ GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_OUT_AND_ERR, NULL, NULL, "gnunet-service-resolver",
+ "gnunet-service-resolver", NULL);
+ resolver_users++;
+ GNUNET_RESOLVER_connect (cfg);
+ tc = GNUNET_malloc (sizeof (struct TestContext));
+ tc->name = GNUNET_strdup (tok);
+ tc->tst =
+ GNUNET_NAT_test_start (cfg,
+ (0 ==
+ strcasecmp (tok,
+ "udp")) ? GNUNET_NO : GNUNET_YES,
+ (uint16_t) bnd_port, (uint16_t) adv_port,
+ &result_callback, tc);
+ if (NULL == tc->tst)
+ {
+ display_test_result (tc, GNUNET_SYSERR);
+ continue;
+ }
+ tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, tc);
+ }
+ GNUNET_free (plugins);
+}
+