gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r15898 - gnunet-setup/src


From: gnunet
Subject: [GNUnet-SVN] r15898 - gnunet-setup/src
Date: Fri, 8 Jul 2011 18:12:33 +0200

Author: grothoff
Date: 2011-07-08 18:12:33 +0200 (Fri, 08 Jul 2011)
New Revision: 15898

Added:
   gnunet-setup/src/gnunet-setup-transport-http.c
   gnunet-setup/src/gnunet-setup-transport-https.c
Modified:
   gnunet-setup/src/Makefile.am
Log:
add testing for http/https

Modified: gnunet-setup/src/Makefile.am
===================================================================
--- gnunet-setup/src/Makefile.am        2011-07-08 16:09:47 UTC (rev 15897)
+++ gnunet-setup/src/Makefile.am        2011-07-08 16:12:33 UTC (rev 15898)
@@ -11,6 +11,8 @@
   gnunet-setup.c gnunet-setup.h \
   gnunet-setup-options.c gnunet-setup-options.h \
   gnunet-setup-transport-plugins.c \
+  gnunet-setup-transport-http.c \
+  gnunet-setup-transport-https.c \
   gnunet-setup-transport-tcp.c \
   gnunet-setup-transport-udp.c \
   gnunet-setup-transport.c \

Copied: gnunet-setup/src/gnunet-setup-transport-http.c (from rev 15894, 
gnunet-setup/src/gnunet-setup-transport-tcp.c)
===================================================================
--- gnunet-setup/src/gnunet-setup-transport-http.c                              
(rev 0)
+++ gnunet-setup/src/gnunet-setup-transport-http.c      2011-07-08 16:12:33 UTC 
(rev 15898)
@@ -0,0 +1,182 @@
+/*
+     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/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>
+
+/**
+ * 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 (gtk_builder_get_object (builder,
+                                         
"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 (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_http_test_fail_image"));
+      gtk_widget_show (w);
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_http_test_success_image"));
+      gtk_widget_hide (w);
+    }
+  else
+    {
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_http_test_fail_image"));
+      gtk_widget_hide (w);
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_http_test_success_image"));
+      gtk_widget_show (w);
+    }
+}
+
+
+/* end of gnunet-setup-transport-http.c */

Copied: gnunet-setup/src/gnunet-setup-transport-https.c (from rev 15894, 
gnunet-setup/src/gnunet-setup-transport-tcp.c)
===================================================================
--- gnunet-setup/src/gnunet-setup-transport-https.c                             
(rev 0)
+++ gnunet-setup/src/gnunet-setup-transport-https.c     2011-07-08 16:12:33 UTC 
(rev 15898)
@@ -0,0 +1,182 @@
+/*
+     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/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>
+
+/**
+ * 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 (gtk_builder_get_object (builder,
+                                         
"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 (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_https_test_fail_image"));
+      gtk_widget_show (w);
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_https_test_success_image"));
+      gtk_widget_hide (w);
+    }
+  else
+    {
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_https_test_fail_image"));
+      gtk_widget_hide (w);
+      w = GTK_WIDGET (gtk_builder_get_object (builder,
+                                             
"GNUNET_setup_transport_https_test_success_image"));
+      gtk_widget_show (w);
+    }
+}
+
+
+/* end of gnunet-setup-transport-https.c */




reply via email to

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