gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r16573 - gnunet-gtk/src/setup


From: gnunet
Subject: [GNUnet-SVN] r16573 - gnunet-gtk/src/setup
Date: Mon, 15 Aug 2011 19:40:28 +0200

Author: grothoff
Date: 2011-08-15 19:40:28 +0200 (Mon, 15 Aug 2011)
New Revision: 16573

Added:
   gnunet-gtk/src/setup/gnunet-setup-transport-test.c
   gnunet-gtk/src/setup/gnunet-setup-transport-test.h
Modified:
   gnunet-gtk/src/setup/Makefile.am
   gnunet-gtk/src/setup/gnunet-setup-options.c
   gnunet-gtk/src/setup/gnunet-setup-options.h
   gnunet-gtk/src/setup/gnunet-setup-transport-http.c
   gnunet-gtk/src/setup/gnunet-setup-transport-https.c
   gnunet-gtk/src/setup/gnunet-setup-transport-tcp.c
   gnunet-gtk/src/setup/gnunet-setup-transport-udp.c
   gnunet-gtk/src/setup/gnunet-setup-transport.c
   gnunet-gtk/src/setup/gnunet-setup.c
Log:
eliminate SCHEDULER_run, simplify code

Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am    2011-08-15 16:58:56 UTC (rev 16572)
+++ gnunet-gtk/src/setup/Makefile.am    2011-08-15 17:40:28 UTC (rev 16573)
@@ -17,6 +17,7 @@
   gnunet-setup.c gnunet-setup.h \
   gnunet-setup-options.c gnunet-setup-options.h \
   gnunet-setup-transport-plugins.c \
+  gnunet-setup-transport-test.c gnunet-setup-transport-test.h \
   gnunet-setup-transport-http.c \
   gnunet-setup-transport-https.c \
   gnunet-setup-transport-tcp.c \

Modified: gnunet-gtk/src/setup/gnunet-setup-options.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-options.c 2011-08-15 16:58:56 UTC (rev 
16572)
+++ gnunet-gtk/src/setup/gnunet-setup-options.c 2011-08-15 17:40:28 UTC (rev 
16573)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file src/gnunet-setup-options.c
+ * @file src/setup/gnunet-setup-options.c
  * @brief configuration details
  * @author Christian Grothoff
  */

Modified: gnunet-gtk/src/setup/gnunet-setup-options.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-options.h 2011-08-15 16:58:56 UTC (rev 
16572)
+++ gnunet-gtk/src/setup/gnunet-setup-options.h 2011-08-15 17:40:28 UTC (rev 
16573)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file src/gnunet-setup-options.h
+ * @file src/setup/gnunet-setup-options.h
  * @brief configuration details
  * @author Christian Grothoff
  */

Modified: gnunet-gtk/src/setup/gnunet-setup-transport-http.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-http.c  2011-08-15 16:58:56 UTC 
(rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-http.c  2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -19,158 +19,27 @@
 */
 
 /**
- * @file src/gnunet-setup-transport-http.c
+ * @file src/setup/gnunet-setup-transport-http.c
  * @brief support for HTTP configuration
  * @author Christian Grothoff
  */
 #include "gnunet-setup.h"
 #include <gnunet/gnunet_resolver_service.h>
 #include <gnunet/gnunet_nat_lib.h>
+#include "gnunet-setup-transport-test.h"
 
-/**
- * How long do we wait for the NAT test to report success?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 /**
- * Handle to the active NAT test.
- */
-static struct GNUNET_NAT_Test *tst;
-
-/**
- * Task identifier for the timeout.
- */
-static GNUNET_SCHEDULER_TaskIdentifier tsk;
-
-
-/**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
- *
- * @param cls closure (unused)
- * @param success currently always GNUNET_OK
- */
-static void
-result_callback (void *cls,
-                int success)
-{
-  int *ok = cls;
-
-  *ok = success;
-  GNUNET_SCHEDULER_cancel (tsk);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
- *
- * @param cls closure (unused)
- * @param tc scheduler callback
- */
-static void
-fail_timeout (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  
-  GNUNET_assert (NULL != tst);
-  *ok = GNUNET_NO;
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Main function for the NAT test.
- *
- * @param cls the 'int*' for the result
- * @param tc scheduler context
- */
-static void 
-test (void *cls,
-      const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  unsigned long long bnd_port;
-  unsigned long long adv_port;
-
-  GNUNET_assert (NULL != cfg);
-  GNUNET_RESOLVER_connect (cfg);
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-http",
-                                            "PORT",
-                                            &bnd_port))
-    {
-      GNUNET_break (0);
-      return;
-    }
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-http",
-                                            "ADVERTISED_PORT",
-                                            &adv_port))
-    adv_port = bnd_port;
-  tst = GNUNET_NAT_test_start (cfg,
-                              GNUNET_YES,
-                              (uint16_t) bnd_port,
-                              (uint16_t) adv_port,
-                              &result_callback,
-                              ok);
-  if (NULL == tst)
-    {
-      *ok = GNUNET_SYSERR;
-      return;
-    }
-  tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                     &fail_timeout,
-                                     ok);
-}
-
-/**
  * Function called whenever the user wants to test the
  * HTTP configuration.
  */
 void
 GNUNET_setup_transport_http_test_button_clicked_cb ()
 {
-  GtkWidget *w;
-  int ok;
-  struct GNUNET_OS_Process *resolver;
-
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
-  GNUNET_assert (NULL == tst);
-  w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_http_test_success_image"));
-  gtk_widget_hide (w);
-  resolver = GNUNET_OS_start_process (NULL, NULL,
-                                     "gnunet-service-resolver", 
-                                     "gnunet-service-resolver", NULL);
-  ok = GNUNET_NO;
-  GNUNET_SCHEDULER_run (&test, &ok);
-  if (NULL != resolver)
-    {
-      GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
-      GNUNET_OS_process_close (resolver);
-    }
-  if (GNUNET_YES != ok)
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_http_test_fail_image"));
-      gtk_widget_show (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_http_test_success_image"));
-      gtk_widget_hide (w);
-    }
-  else
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_http_test_fail_image"));
-      gtk_widget_hide (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_http_test_success_image"));
-      gtk_widget_show (w);
-    }
+  GNUNET_setup_transport_test ("transport-http",
+                              GNUNET_YES,
+                              "GNUNET_setup_transport_http_test_success_image",
+                              "GNUNET_setup_transport_http_test_fail_image");
 }
 
 

Modified: gnunet-gtk/src/setup/gnunet-setup-transport-https.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-https.c 2011-08-15 16:58:56 UTC 
(rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-https.c 2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -19,158 +19,27 @@
 */
 
 /**
- * @file src/gnunet-setup-transport-https.c
+ * @file src/setup/gnunet-setup-transport-https.c
  * @brief support for HTTPS configuration
  * @author Christian Grothoff
  */
 #include "gnunet-setup.h"
 #include <gnunet/gnunet_resolver_service.h>
 #include <gnunet/gnunet_nat_lib.h>
+#include "gnunet-setup-transport-test.h"
 
-/**
- * How long do we wait for the NAT test to report success?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 /**
- * Handle to the active NAT test.
- */
-static struct GNUNET_NAT_Test *tst;
-
-/**
- * Task identifier for the timeout.
- */
-static GNUNET_SCHEDULER_TaskIdentifier tsk;
-
-
-/**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
- *
- * @param cls closure (unused)
- * @param success currently always GNUNET_OK
- */
-static void
-result_callback (void *cls,
-                int success)
-{
-  int *ok = cls;
-
-  *ok = success;
-  GNUNET_SCHEDULER_cancel (tsk);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
- *
- * @param cls closure (unused)
- * @param tc scheduler callback
- */
-static void
-fail_timeout (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  
-  GNUNET_assert (NULL != tst);
-  *ok = GNUNET_NO;
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Main function for the NAT test.
- *
- * @param cls the 'int*' for the result
- * @param tc scheduler context
- */
-static void 
-test (void *cls,
-      const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  unsigned long long bnd_port;
-  unsigned long long adv_port;
-
-  GNUNET_assert (NULL != cfg);
-  GNUNET_RESOLVER_connect (cfg);
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-https",
-                                            "PORT",
-                                            &bnd_port))
-    {
-      GNUNET_break (0);
-      return;
-    }
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-https",
-                                            "ADVERTISED_PORT",
-                                            &adv_port))
-    adv_port = bnd_port;
-  tst = GNUNET_NAT_test_start (cfg,
-                              GNUNET_YES,
-                              (uint16_t) bnd_port,
-                              (uint16_t) adv_port,
-                              &result_callback,
-                              ok);
-  if (NULL == tst)
-    {
-      *ok = GNUNET_SYSERR;
-      return;
-    }
-  tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                     &fail_timeout,
-                                     ok);
-}
-
-/**
  * Function called whenever the user wants to test the
  * HTTPS configuration.
  */
 void
 GNUNET_setup_transport_https_test_button_clicked_cb ()
 {
-  GtkWidget *w;
-  int ok;
-  struct GNUNET_OS_Process *resolver;
-
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
-  GNUNET_assert (NULL == tst);
-  w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_https_test_success_image"));
-  gtk_widget_hide (w);
-  resolver = GNUNET_OS_start_process (NULL, NULL,
-                                     "gnunet-service-resolver", 
-                                     "gnunet-service-resolver", NULL);
-  ok = GNUNET_NO;
-  GNUNET_SCHEDULER_run (&test, &ok);
-  if (NULL != resolver)
-    {
-      GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
-      GNUNET_OS_process_close (resolver);
-    }
-  if (GNUNET_YES != ok)
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_https_test_fail_image"));
-      gtk_widget_show (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_https_test_success_image"));
-      gtk_widget_hide (w);
-    }
-  else
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_https_test_fail_image"));
-      gtk_widget_hide (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_https_test_success_image"));
-      gtk_widget_show (w);
-    }
+  GNUNET_setup_transport_test ("transport-https",
+                              GNUNET_YES,
+                              
"GNUNET_setup_transport_https_test_success_image",
+                              "GNUNET_setup_transport_https_test_fail_image");
 }
 
 

Modified: gnunet-gtk/src/setup/gnunet-setup-transport-tcp.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-tcp.c   2011-08-15 16:58:56 UTC 
(rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-tcp.c   2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -19,158 +19,27 @@
 */
 
 /**
- * @file src/gnunet-setup-transport-tcp.c
+ * @file src/setup/gnunet-setup-transport-tcp.c
  * @brief support for TCP configuration
  * @author Christian Grothoff
  */
 #include "gnunet-setup.h"
 #include <gnunet/gnunet_resolver_service.h>
 #include <gnunet/gnunet_nat_lib.h>
+#include "gnunet-setup-transport-test.h"
 
-/**
- * How long do we wait for the NAT test to report success?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 /**
- * Handle to the active NAT test.
- */
-static struct GNUNET_NAT_Test *tst;
-
-/**
- * Task identifier for the timeout.
- */
-static GNUNET_SCHEDULER_TaskIdentifier tsk;
-
-
-/**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
- *
- * @param cls closure (unused)
- * @param success currently always GNUNET_OK
- */
-static void
-result_callback (void *cls,
-                int success)
-{
-  int *ok = cls;
-
-  *ok = success;
-  GNUNET_SCHEDULER_cancel (tsk);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
- *
- * @param cls closure (unused)
- * @param tc scheduler callback
- */
-static void
-fail_timeout (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  
-  GNUNET_assert (NULL != tst);
-  *ok = GNUNET_NO;
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Main function for the NAT test.
- *
- * @param cls the 'int*' for the result
- * @param tc scheduler context
- */
-static void 
-test (void *cls,
-      const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  unsigned long long bnd_port;
-  unsigned long long adv_port;
-
-  GNUNET_assert (NULL != cfg);
-  GNUNET_RESOLVER_connect (cfg);
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-tcp",
-                                            "PORT",
-                                            &bnd_port))
-    {
-      GNUNET_break (0);
-      return;
-    }
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-tcp",
-                                            "ADVERTISED_PORT",
-                                            &adv_port))
-    adv_port = bnd_port;
-  tst = GNUNET_NAT_test_start (cfg,
-                              GNUNET_YES,
-                              (uint16_t) bnd_port,
-                              (uint16_t) adv_port,
-                              &result_callback,
-                              ok);
-  if (NULL == tst)
-    {
-      *ok = GNUNET_SYSERR;
-      return;
-    }
-  tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                     &fail_timeout,
-                                     ok);
-}
-
-/**
  * Function called whenever the user wants to test the
  * TCP configuration.
  */
 void
 GNUNET_setup_transport_tcp_test_button_clicked_cb ()
 {
-  GtkWidget *w;
-  int ok;
-  struct GNUNET_OS_Process *resolver;
-
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
-  GNUNET_assert (NULL == tst);
-  w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_tcp_test_success_image"));
-  gtk_widget_hide (w);
-  resolver = GNUNET_OS_start_process (NULL, NULL,
-                                     "gnunet-service-resolver", 
-                                     "gnunet-service-resolver", NULL);
-  ok = GNUNET_NO;
-  GNUNET_SCHEDULER_run (&test, &ok);
-  if (NULL != resolver)
-    {
-      GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
-      GNUNET_OS_process_close (resolver);
-    }
-  if (GNUNET_YES != ok)
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_tcp_test_fail_image"));
-      gtk_widget_show (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_tcp_test_success_image"));
-      gtk_widget_hide (w);
-    }
-  else
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_tcp_test_fail_image"));
-      gtk_widget_hide (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_tcp_test_success_image"));
-      gtk_widget_show (w);
-    }
+  GNUNET_setup_transport_test ("transport-tcp",
+                              GNUNET_YES,
+                              "GNUNET_setup_transport_tcp_test_success_image",
+                              "GNUNET_setup_transport_tcp_test_fail_image");
 }
 
 

Added: gnunet-gtk/src/setup/gnunet-setup-transport-test.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-test.c                          
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-test.c  2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -0,0 +1,199 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/setup/gnunet-setup-transport-test.c
+ * @brief support for testing transport configurations
+ * @author Christian Grothoff
+ */
+#include "gnunet-setup.h"
+#include <gnunet/gnunet_resolver_service.h>
+#include <gnunet/gnunet_nat_lib.h>
+
+/**
+ * How long do we wait for the NAT test to report success?
+ */
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+
+
+struct TestContext
+{
+
+  /**
+   * Handle to the active NAT test.
+   */
+  struct GNUNET_NAT_Test *tst;
+
+  /**
+   * Task identifier for the timeout.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier tsk;
+
+  /**
+   * Name of widget to show on success.
+   */ 
+  const char *success_image;
+                           
+  /**
+   * Name of widget to show on failure.
+   */
+  const char *failure_image;
+
+};
+
+
+/**
+ * Display the result of the test.
+ *
+ * @param tc test context
+ * @param result GNUNET_YES on success
+ */
+static void
+display_test_result (struct TestContext *tc,
+                    int result)
+{
+  GObject *w;
+
+  if (GNUNET_YES != result)
+    {
+      w = GNUNET_SETUP_get_object (tc->failure_image);
+      if (NULL != w)
+       gtk_widget_show (GTK_WIDGET (w));
+      w = GNUNET_SETUP_get_object (tc->success_image);
+      if (NULL != w)     
+       gtk_widget_hide (GTK_WIDGET (w));
+    }
+  else
+    {
+      w = GNUNET_SETUP_get_object (tc->failure_image);
+      if (NULL != w)     
+       gtk_widget_hide (GTK_WIDGET (w));
+      w = GNUNET_SETUP_get_object (tc->success_image);
+      if (NULL != w)
+       gtk_widget_show (GTK_WIDGET (w));
+    }
+  if (GNUNET_SCHEDULER_NO_TASK != tc->tsk)
+    {
+      GNUNET_SCHEDULER_cancel (tc->tsk);
+      tc->tsk = GNUNET_SCHEDULER_NO_TASK;
+    }
+  if (NULL != tc->tst)
+    {
+      GNUNET_NAT_test_stop (tc->tst);
+      tc->tst = NULL;
+    }
+  GNUNET_free (tc);
+}
+
+
+/**
+ * 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);
+}
+
+
+/**
+ * Function called whenever the user wants to test a
+ * transport configuration.
+ *
+ * @param section_name section with the port numbers
+ * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP
+ * @param success_image image to show on success
+ * @param failure_image image to show on failure
+ */
+void
+GNUNET_setup_transport_test (const char *section_name,
+                            int is_tcp,
+                            const char *success_image,
+                            const char *failure_image)
+{
+  struct TestContext *tc;
+  unsigned long long bnd_port;
+  unsigned long long adv_port;
+  GtkWidget *w;
+
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg, 
+                                            section_name,
+                                            "PORT",
+                                            &bnd_port))
+    {
+      GNUNET_break (0);
+      return;
+    }
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (cfg, 
+                                            section_name,
+                                            "ADVERTISED_PORT",
+                                            &adv_port))
+    adv_port = bnd_port;
+  tc = GNUNET_malloc (sizeof (struct TestContext));
+  tc->success_image = success_image;
+  tc->failure_image = failure_image;
+  w = GTK_WIDGET (GNUNET_SETUP_get_object (success_image));
+  gtk_widget_hide (w);
+  GNUNET_assert (NULL != cfg);
+  GNUNET_RESOLVER_connect (cfg);
+  tc->tst = GNUNET_NAT_test_start (cfg,
+                                  is_tcp,
+                                  (uint16_t) bnd_port,
+                                  (uint16_t) adv_port,
+                                  &result_callback,
+                                  tc);
+  if (NULL == tc->tst)
+    {
+      display_test_result (tc, GNUNET_SYSERR);
+      return;
+    }
+  tc->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
+                                         &fail_timeout,
+                                         tc);
+}
+
+/* end of gnunet-setup-transport-test.c */

Added: gnunet-gtk/src/setup/gnunet-setup-transport-test.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-test.h                          
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-test.h  2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -0,0 +1,44 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010, 2011 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file src/setup/gnunet-setup-transport-test.c
+ * @brief support for testing transport configurations
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_SETUP_TRANSPORT_TEST_H
+#define GNUNET_SETUP_TRANSPORT_TEST_H
+
+/**
+ * Function called whenever the user wants to test a
+ * transport configuration.
+ *
+ * @param section_name section with the port numbers
+ * @param is_tcp GNUNET_YES for TCP, GNUNET_NO for UDP
+ * @param success_image image to show on success
+ * @param failure_image image to show on failure
+ */
+void
+GNUNET_setup_transport_test (const char *section_name,
+                            int is_tcp,
+                            const char *success_image,
+                            const char *failure_image);
+
+#endif

Modified: gnunet-gtk/src/setup/gnunet-setup-transport-udp.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport-udp.c   2011-08-15 16:58:56 UTC 
(rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup-transport-udp.c   2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -19,157 +19,29 @@
 */
 
 /**
- * @file src/gnunet-setup-transport-udp.c
+ * @file src/setup/gnunet-setup-transport-udp.c
  * @brief support for UDP configuration
  * @author Christian Grothoff
  */
 #include "gnunet-setup.h"
 #include <gnunet/gnunet_resolver_service.h>
 #include <gnunet/gnunet_nat_lib.h>
+#include "gnunet-setup-transport-test.h"
 
-/**
- * How long do we wait for the NAT test to report success?
- */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
 
 /**
- * Handle to the active NAT test.
- */
-static struct GNUNET_NAT_Test *tst;
-
-/**
- * Task identifier for the timeout.
- */
-static GNUNET_SCHEDULER_TaskIdentifier tsk;
-
-
-/**
- * Function called by NAT on success.
- * Clean up and update GUI (with success).
- *
- * @param cls closure (unused)
- * @param success currently always GNUNET_OK
- */
-static void
-result_callback (void *cls,
-                int success)
-{
-  int *ok = cls;
-
-  *ok = success;
-  GNUNET_SCHEDULER_cancel (tsk);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Function called if NAT failed to confirm success.
- * Clean up and update GUI (with failure).
- *
- * @param cls closure (unused)
- * @param tc scheduler callback
- */
-static void
-fail_timeout (void *cls,
-             const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-
-  *ok = GNUNET_NO;
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-}
-
-
-/**
- * Main function for the NAT test.
- *
- * @param cls the 'int*' for the result
- * @param tc scheduler context
- */
-static void 
-test (void *cls,
-      const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  int *ok = cls;
-  unsigned long long bnd_port;
-  unsigned long long adv_port;
-
-  GNUNET_assert (NULL != cfg);
-  GNUNET_RESOLVER_connect (cfg);
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-udp",
-                                            "PORT",
-                                            &bnd_port))
-    {
-      GNUNET_break (0);
-      return;
-    }
-  if (GNUNET_OK !=
-      GNUNET_CONFIGURATION_get_value_number (cfg, 
-                                            "transport-udp",
-                                            "ADVERTISED_PORT",
-                                            &adv_port))
-    adv_port = bnd_port;
-  tst = GNUNET_NAT_test_start (cfg,
-                              GNUNET_NO,
-                              (uint16_t) bnd_port,
-                              (uint16_t) adv_port,
-                              &result_callback,
-                              ok);
-  if (NULL == tst)
-    {
-      *ok = GNUNET_SYSERR;
-      return;
-    }
-  tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
-                                     &fail_timeout,
-                                     ok);
-}
-
-/**
  * Function called whenever the user wants to test the
  * UDP configuration.
  */
 void
 GNUNET_setup_transport_udp_test_button_clicked_cb ()
 {
-  GtkWidget *w;
-  int ok;
-  struct GNUNET_OS_Process *resolver;
 
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == tsk);
-  GNUNET_assert (NULL == tst);
-  w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_udp_test_success_image"));
-  gtk_widget_hide (w);
-  resolver = GNUNET_OS_start_process (NULL, NULL,
-                                     "gnunet-service-resolver", 
-                                     "gnunet-service-resolver", NULL);
-  ok = GNUNET_NO;
-  GNUNET_SCHEDULER_run (&test, &ok);
-  if (NULL != resolver)
-    {
-      GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
-      GNUNET_OS_process_close (resolver);
-    }
-  if (GNUNET_YES != ok)
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_udp_test_fail_image"));
-      gtk_widget_show (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_udp_test_success_image"));
-      gtk_widget_hide (w);
-    }
-  else
-    {
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_udp_test_fail_image"));
-      gtk_widget_hide (w);
-      w = GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_udp_test_success_image"));
-      gtk_widget_show (w);
-    }
+  GNUNET_setup_transport_test ("transport-udp",
+                              GNUNET_NO,
+                              "GNUNET_setup_transport_udp_test_success_image",
+                              "GNUNET_setup_transport_udp_test_fail_image");
+
 }
 
 

Modified: gnunet-gtk/src/setup/gnunet-setup-transport.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport.c       2011-08-15 16:58:56 UTC 
(rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup-transport.c       2011-08-15 17:40:28 UTC 
(rev 16573)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file src/gnunet-setup-transport.c
+ * @file src/setup/gnunet-setup-transport.c
  * @brief support for transport (NAT) configuration
  * @author Christian Grothoff
  */
@@ -67,7 +67,6 @@
 }
 
 
-
 /**
  * Function called by NAT on success.
  * Clean up and update GUI (with success).
@@ -146,6 +145,8 @@
 static void
 test_connection_reversal ()
 {
+  if (NULL != resolver)
+    return; /* test already active!? */
   resolver = GNUNET_OS_start_process (NULL, NULL,
                                      "gnunet-service-resolver", 
                                      "gnunet-service-resolver", NULL);
@@ -271,8 +272,6 @@
   if (hns)    
     test_connection_reversal ();    
 
-    
-
   /* test gnunet-helper-nat-client */
   tmp = NULL;
   hnc = ( (GNUNET_OK ==

Modified: gnunet-gtk/src/setup/gnunet-setup.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup.c 2011-08-15 16:58:56 UTC (rev 16572)
+++ gnunet-gtk/src/setup/gnunet-setup.c 2011-08-15 17:40:28 UTC (rev 16573)
@@ -19,7 +19,7 @@
 */
 
 /**
- * @file src/gnunet-setup.c
+ * @file src/setup/gnunet-setup.c
  * @brief Main function of gnunet-setup
  * @author Christian Grothoff
  */
@@ -56,6 +56,12 @@
 static int gret;
 
 /**
+ * Resolver process handle.
+ */
+struct GNUNET_OS_Process *resolver;
+
+
+/**
  * Get an object from the main window.
  *
  * @param name name of the object
@@ -64,6 +70,8 @@
 GObject *
 GNUNET_SETUP_get_object (const char *name)
 {
+  if (NULL == ml)
+    return NULL;
   return GNUNET_GTK_main_loop_get_object (ml, name);
 }
 
@@ -305,6 +313,13 @@
     gret = 1;    
   GNUNET_CONFIGURATION_destroy (cfgDefault);
   GNUNET_CONFIGURATION_destroy (cfg);
+  cfg = NULL;
+  if (NULL != resolver)
+    {
+      GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
+      GNUNET_OS_process_close (resolver);
+      resolver = NULL;
+    }
 }
 
 
@@ -324,7 +339,9 @@
   cfg = GNUNET_CONFIGURATION_create ();
   (void) GNUNET_CONFIGURATION_load (cfg, cfgName);
   main_window = GTK_WIDGET (GNUNET_SETUP_get_object ("GNUNET_setup_dialog"));
-
+  resolver = GNUNET_OS_start_process (NULL, NULL,
+                                     "gnunet-service-resolver", 
+                                     "gnunet-service-resolver", NULL);
   load_options ();
   gtk_widget_show (main_window);
   gtk_window_present (GTK_WINDOW (main_window));




reply via email to

[Prev in Thread] Current Thread [Next in Thread]