gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r24657 - in gnunet-gtk: doc src/setup


From: gnunet
Subject: [GNUnet-SVN] r24657 - in gnunet-gtk: doc src/setup
Date: Thu, 1 Nov 2012 17:19:50 +0100

Author: grothoff
Date: 2012-11-01 17:19:50 +0100 (Thu, 01 Nov 2012)
New Revision: 24657

Added:
   gnunet-gtk/src/setup/gnunet-setup-transport.h
Modified:
   gnunet-gtk/doc/gnunet-setup.1
   gnunet-gtk/src/setup/Makefile.am
   gnunet-gtk/src/setup/gnunet-setup-transport.c
   gnunet-gtk/src/setup/gnunet-setup.c
Log:
-improving auto-setup, adding option for non-interactive auto-setup

Modified: gnunet-gtk/doc/gnunet-setup.1
===================================================================
--- gnunet-gtk/doc/gnunet-setup.1       2012-11-01 16:01:39 UTC (rev 24656)
+++ gnunet-gtk/doc/gnunet-setup.1       2012-11-01 16:19:50 UTC (rev 24657)
@@ -15,8 +15,8 @@
 After your peer is configured, gnunet\-setup can also still be useful to 
configure an individual user's GADS zone (if GNS is enabled).  This restricted 
per-user configuration is automatically run if a user "gnunet" exists on your 
system and you do not run gnunet\-setup as "gnunet" or "root".  Using the "\-f" 
option, normal users can force seeing the full set of options, which only makes 
sense if they intend to run their own GNUnet peer on the system (or move the 
generated configuration file to another location afterwards).
 
 .TP
-\fB\-h\fR, \fB\-\-help\fR
-print help page
+\fB\-a\fR, \fB\-\-autoconfig\fR
+try to automatically configure networking for the peer without starting the 
interactive GUI
 .TP
 \fB\-c \fIFILENAME\fR, \fB\-\-config=FILENAME\fR
 load config file (default: ~/.gnunet/gnunet.conf)
@@ -27,6 +27,9 @@
 \fB\-f, \fB\-\-force\-full\-setup\fR
 Display all of the options for a peer even if a user "gnunet" exists but 
gnunet\-setup is not run as that user.
 .TP
+\fB\-h\fR, \fB\-\-help\fR
+print help page
+.TP
 \fB\-v\fR, \fB\-\-version\fR
 print the version number
 .SH NOTES

Modified: gnunet-gtk/src/setup/Makefile.am
===================================================================
--- gnunet-gtk/src/setup/Makefile.am    2012-11-01 16:01:39 UTC (rev 24656)
+++ gnunet-gtk/src/setup/Makefile.am    2012-11-01 16:19:50 UTC (rev 24657)
@@ -19,7 +19,7 @@
   gnunet-setup-transport-https.c \
   gnunet-setup-transport-tcp.c \
   gnunet-setup-transport-udp.c \
-  gnunet-setup-transport.c \
+  gnunet-setup-transport.c gnunet-setup-transport.h \
   gnunet-setup-datastore-plugins.c \
   gnunet-setup-datastore-config.c \
   gnunet-setup-datacache-plugins.c \

Modified: gnunet-gtk/src/setup/gnunet-setup-transport.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport.c       2012-11-01 16:01:39 UTC 
(rev 24656)
+++ gnunet-gtk/src/setup/gnunet-setup-transport.c       2012-11-01 16:19:50 UTC 
(rev 24657)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2010 Christian Grothoff (and other contributing authors)
+     (C) 2010, 2012 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
@@ -22,8 +22,15 @@
  * @file src/setup/gnunet-setup-transport.c
  * @brief support for transport (NAT) configuration
  * @author Christian Grothoff
+ *
+ * TODO:
+ * - cummulate collected information in the context
+ * - implement and refine existing network setup tests
+ * - if NAT detected and all traversal methods fail and no IPv6,
+ *   set transport plugin ports to 0
  */
 #include "gnunet-setup.h"
+#include "gnunet-setup-transport.h"
 #include <gnunet/gnunet_util_lib.h>
 #include <gnunet/gnunet_resolver_service.h>
 #include <gnunet/gnunet_nat_lib.h>
@@ -31,22 +38,108 @@
 /**
  * How long do we wait for the NAT test to report success?
  */
-#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1)
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
 
 /**
- * Handle to the active NAT test.
+ * Phases of the auto configuration.
  */
-static struct GNUNET_NAT_Test *tst;
+enum AutoPhase
+{
+  /**
+   * Initial start value.
+   */
+  AUTO_INIT = 0,
 
+  /**
+   * Test if we are online.
+   */
+  AUTO_ONLINE = 1,
+
+  /**
+   * Test our external IP.
+   */
+  AUTO_EXTERNAL_IP,
+
+  /**
+   * Test our internal IP.
+   */
+  AUTO_LOCAL_IP,
+
+  /**
+   * Test if NAT was punched.
+   */
+  AUTO_NAT_PUNCHED,
+
+  /**
+   * Test if UPnP is working.
+   */
+  AUTO_UPNPC,
+
+  /**
+   * Test if ICMP server works.
+   */
+  AUTO_ICMP_SERVER,
+
+  /**
+   * Test if ICMP client works.
+   */
+  AUTO_ICMP_CLIENT,
+
+  /**
+   * Last phase, we're done.
+   */
+  AUTO_DONE
+  
+};
+
+
 /**
- * Task identifier for the timeout.
+ * Context for the autoconfig test.
  */
-static GNUNET_SCHEDULER_TaskIdentifier tsk;
+struct GNUNET_SetupAutoContext
+{
 
-static struct GNUNET_OS_Process *resolver;
+  /**
+   * Handle to the active NAT test.
+   */
+  struct GNUNET_NAT_Test *tst;
 
+  /**
+   * Function to call when done.
+   */
+  GNUNET_SetupAutoConfigFinished fin_cb;
+  
+  /**
+   * Closure for 'fin_cb'.
+   */
+  void *fin_cb_cls;
+  
+  /**
+   * Handle for active 'GNUNET_NAT_mini_get_external_ipv4'-operation.
+   */
+  struct GNUNET_NAT_ExternalHandle *eh;
 
+  /**
+   * Task identifier for the timeout.
+   */
+  GNUNET_SCHEDULER_TaskIdentifier tsk;
+
+  /**
+   * Where are we in the test?
+   */
+  enum AutoPhase phase;
+
+};
+
+
 /**
+ * Run the next phase of the auto test.
+ */
+static void
+next_phase (struct GNUNET_SetupAutoContext *ac);
+
+
+/**
  * Update the ICMP server button based on the result.
  *
  * @param on GNUNET_YES to enable, GNUNET_NO to disable
@@ -78,16 +171,14 @@
 static void
 result_callback (void *cls, int success)
 {
-  GNUNET_SCHEDULER_cancel (tsk);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
-  if (NULL != resolver)
-  {
-    GNUNET_break (0 == GNUNET_OS_process_kill (resolver, SIGTERM));
-    GNUNET_OS_process_destroy (resolver);
-  }
+  struct GNUNET_SetupAutoContext *ac = cls;
+
+  GNUNET_SCHEDULER_cancel (ac->tsk);
+  ac->tsk = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_NAT_test_stop (ac->tst);
+  ac->tst = NULL;
   update_icmp_server_enable_button (success);
+  next_phase (ac);
 }
 
 
@@ -95,17 +186,20 @@
  * Function called if NAT failed to confirm success.
  * Clean up and update GUI (with failure).
  *
- * @param cls closure (unused)
+ * @param cls closure with setup context
  * @param tc scheduler callback
  */
 static void
 fail_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  GNUNET_assert (NULL != tst);
-  tsk = GNUNET_SCHEDULER_NO_TASK;
-  GNUNET_NAT_test_stop (tst);
-  tst = NULL;
+  struct GNUNET_SetupAutoContext *ac = cls;
+
+  GNUNET_assert (NULL != ac->tst);
+  ac->tsk = GNUNET_SCHEDULER_NO_TASK;
+  GNUNET_NAT_test_stop (ac->tst);
+  ac->tst = NULL;
   update_icmp_server_enable_button (GNUNET_NO);
+  next_phase (ac);
 }
 
 
@@ -118,40 +212,100 @@
 static void
 reversal_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  int *ok = cls;
+  struct GNUNET_SetupAutoContext *ac = cls;
 
   GNUNET_assert (NULL != cfg);
   GNUNET_RESOLVER_connect (cfg);
-  tst = GNUNET_NAT_test_start (cfg, GNUNET_YES, 0, 0, &result_callback, ok);
-  if (NULL == tst)
+  ac->tst = GNUNET_NAT_test_start (cfg, GNUNET_YES, 0, 0, &result_callback, 
ac);
+  if (NULL == ac->tst)
   {
-    *ok = GNUNET_SYSERR;
+    next_phase (ac);
     return;
   }
-  tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ok);
+  ac->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, ac);
 }
 
+
 /**
- * Test if connection reversal (ICMP method) works.
+ * Test if we are online at all.
+ *
+ * @param ac auto setup context
  */
 static void
-test_connection_reversal ()
+test_online (struct GNUNET_SetupAutoContext *ac)
 {
-  if (NULL != resolver)
-    return;                     /* test already active!? */
-  resolver =
-    GNUNET_OS_start_process (GNUNET_YES, GNUNET_OS_INHERIT_STD_ALL,
-                             NULL, NULL, "gnunet-service-resolver",
-                               "gnunet-service-resolver", NULL);
-  GNUNET_SCHEDULER_add_now (&reversal_test, NULL);
+  // FIXME: not implemented
+  next_phase (ac);
 }
 
 
 /**
+ * Set our external IPv4 address.
+ *
+ * @param cls closure with our setup context
+ * @param addr the address, NULL on errors
+ */
+static void
+set_external_ipv4 (void *cls, const struct in_addr *addr)
+{
+  struct GNUNET_SetupAutoContext *ac = cls;
+  char buf[INET_ADDRSTRLEN];
+  GObject *o;
+
+  ac->eh = NULL;
+  if (NULL == addr)
+  {
+    next_phase (ac);
+    return;
+  }
+  /* enable 'behind nat' */
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             _("Detected external IP `%s'\n"),
+             inet_ntop (AF_INET,
+                        addr,
+                        buf,
+                        sizeof (buf)));
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "BEHIND_NAT", "YES");
+  o = GNUNET_SETUP_get_object ("GNUNET_setup_transport_nat_checkbutton");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (o), TRUE);
+
+  /* set external IP address */
+  if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf)))
+  {
+    GNUNET_break (0);
+    next_phase (ac);
+    return;
+  }
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "EXTERNAL_ADDRESS",
+                                          buf);
+  o = GNUNET_SETUP_get_object 
("GNUNET_setup_transport_external_ip_address_entry");
+  gtk_entry_set_text (GTK_ENTRY (o), buf);
+  next_phase (ac);
+}
+
+
+/**
+ * Determine our external IPv4 address.
+ *
+ * @param ac auto setup context
+ */
+static void
+test_external_ip (struct GNUNET_SetupAutoContext *ac)
+{
+  // FIXME: CPS?
+  /* try to detect external IP */
+  ac->eh = GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT,
+                                             &set_external_ipv4, ac);
+}
+
+
+/**
  * Process list of local IP addresses.  Find and set the
  * one of the default interface.
  *
- * @param cls closure (not used)
+ * @param cls pointer to int to store if we have a non-local IPv6 address
  * @param name name of the interface (can be NULL for unknown)
  * @param isDefault is this presumably the default interface
  * @param addr address of this interface (can be NULL for unknown or 
unassigned)
@@ -165,12 +319,21 @@
       const struct sockaddr *broadcast_addr, const struct sockaddr *netmask,
       socklen_t addrlen)
 {
+  int *have_v6 = cls;
   const struct sockaddr_in *in;
   char buf[INET_ADDRSTRLEN];
   GtkEntry *entry;
 
   if (!isDefault)
     return GNUNET_OK;
+  if ( (sizeof (struct sockaddr_in6) == addrlen) &&
+       (0 != memcmp (&in6addr_loopback, addr,
+                    addrlen)) &&
+       (! IN6_IS_ADDR_LINKLOCAL(addr)) )
+  {
+    *have_v6 = GNUNET_YES;
+    return GNUNET_OK;
+  }
   if (addrlen != sizeof (struct sockaddr_in))
     return GNUNET_OK;
   in = (const struct sockaddr_in *) addr;
@@ -185,11 +348,6 @@
   entry =
       GTK_ENTRY (GNUNET_SETUP_get_object
                  ("GNUNET_setup_transport_internal_ip_entry"));
-  if (entry == NULL)
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
   gtk_entry_set_text (entry, buf);
   /* no need to continue iteration */
   return GNUNET_SYSERR;
@@ -197,80 +355,80 @@
 
 
 /**
- * Set our external IPv4 address.
+ * Determine our local IP addresses; detect internal IP & IPv6-support 
  *
- * @param cls closure
- * @param addr the address, NULL on errors
+ * @param ac auto setup context
  */
 static void
-set_external_ipv4 (void *cls, const struct in_addr *addr)
+test_local_ip (struct GNUNET_SetupAutoContext *ac)
 {
-  char buf[INET_ADDRSTRLEN];
-  GObject *o;
-  GtkEntry *entry;
   GtkToggleButton *button;
+  int have_v6;
 
-  if (NULL != addr)
-  {
-    /* enable 'behind nat' */
-    if (NULL != cfg)
-      GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "BEHIND_NAT", "YES");
-    o = GNUNET_SETUP_get_object ("GNUNET_setup_transport_nat_checkbutton");
-    if (NULL != o)
-    {
-      button = GTK_TOGGLE_BUTTON (o);
-      if (button == NULL)
-      {
-        GNUNET_break (0);
-        return;
-      }
-      gtk_toggle_button_set_active (button, TRUE);
-    }
+  have_v6 = GNUNET_NO;
+  GNUNET_OS_network_interfaces_list (&nipo, &have_v6);
+  button = GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_disable_ipv6_checkbutton"));
+  gtk_toggle_button_set_active (button,
+                               (GNUNET_YES == have_v6) ? FALSE : TRUE);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "DISABLEV6", 
+                                          (GNUNET_YES == have_v6) ? "NO" : 
"YES");
+  next_phase (ac);
+}
 
-    /* set external IP address */
-    if (NULL == inet_ntop (AF_INET, addr, buf, sizeof (buf)))
-    {
-      GNUNET_break (0);
-      return;
-    }
-    if (NULL != cfg)
-      GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "EXTERNAL_ADDRESS",
-                                             buf);
-    o = GNUNET_SETUP_get_object
-        ("GNUNET_setup_transport_external_ip_address_entry");
-    if (NULL != o)
-    {
-      entry = GTK_ENTRY (o);
-      if (entry == NULL)
-      {
-        GNUNET_break (0);
-        return;
-      }
-      gtk_entry_set_text (entry, buf);
-    }
-  }
+
+/**
+ * Test if NAT has been punched
+ *
+ * @param ac auto setup context
+ */
+static void
+test_nat_punched (struct GNUNET_SetupAutoContext *ac)
+{
+  // FIXME: not implemented
+  next_phase (ac);
 }
 
 
 /**
- * User asked for autoconfiguration.  Try the full program.
+ * Test if UPnPC works.
+ *
+ * @param ac auto setup context
  */
-void
-GNUNET_setup_transport_autoconfig_button_clicked_cb ()
+static void
+test_upnpc (struct GNUNET_SetupAutoContext *ac)
 {
+  int have_upnpc;
   GtkToggleButton *button;
+
+  /* test if upnpc is available */
+  button = GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_upnp_enable_checkbutton"));
+  have_upnpc = (GNUNET_SYSERR !=
+               GNUNET_OS_check_helper_binary ("upnpc"));
+  /* FIXME: test if upnpc is actually working, that is, if transports
+     start to work once we use UPnP */
+  gtk_toggle_button_set_active (button,
+                               have_upnpc
+                               ? TRUE
+                               : FALSE);
+  if (NULL != cfg)
+    GNUNET_CONFIGURATION_set_value_string (cfg, "nat", "ENABLE_UPNP", 
+                                          (GNUNET_YES == have_upnpc) ? "YES" : 
"NO");
+  next_phase (ac);
+}
+
+
+/**
+ * Test if ICMP server is working
+ *
+ * @param ac auto setup context
+ */
+static void
+test_icmp_server (struct GNUNET_SetupAutoContext *ac)
+{
   int hns;
-  int hnc;
   char *tmp;
 
-  /* try to detect external IP */
-  (void) GNUNET_NAT_mini_get_external_ipv4 (TIMEOUT, &set_external_ipv4, NULL);
-  /* Try to detect internal IP */
-  GNUNET_OS_network_interfaces_list (&nipo, NULL);
-
-  /* FIXME: do more: test if UPnP works */
-
-  /* test gnunet-helper-nat-server */
   tmp = NULL;
   hns =
       ((GNUNET_OK ==
@@ -282,9 +440,24 @@
         GNUNET_OS_check_helper_binary ("gnunet-helper-nat-server")));
   GNUNET_free_non_null (tmp);
   if (hns)
-    test_connection_reversal ();
+     GNUNET_SCHEDULER_add_now (&reversal_test, ac);
+  else
+    next_phase (ac);
+}
 
-  /* test gnunet-helper-nat-client */
+
+/**
+ * Test if ICMP client is working
+ *
+ * @param ac auto setup context
+ */
+static void
+test_icmp_client (struct GNUNET_SetupAutoContext *ac)
+{
+  GtkToggleButton *button;
+  int hnc;
+  char *tmp;
+
   tmp = NULL;
   hnc =
       ((GNUNET_OK ==
@@ -298,12 +471,114 @@
   button =
       GTK_TOGGLE_BUTTON (GNUNET_SETUP_get_object
                          
("GNUNET_setup_transport_icmp_client_enable_checkbutton"));
-  if (button == NULL)
+  gtk_toggle_button_set_active (button, hnc ? TRUE : FALSE);
+  next_phase (ac);
+}
+
+
+/**
+ * User asked for autoconfiguration.  Try the full program.
+ *
+ * @param fin_cb function to call when done
+ * @param fin_cb_cls closure for 'fin_cb'
+ * @return handle for the operation 
+ */
+struct GNUNET_SetupAutoContext *
+GNUNET_setup_transport_autoconfig_start (GNUNET_SetupAutoConfigFinished fin_cb,
+                                        void *fin_cb_cls)
+{
+  struct GNUNET_SetupAutoContext *ac;
+
+  ac = GNUNET_malloc (sizeof (struct GNUNET_SetupAutoContext));
+  ac->fin_cb = fin_cb;
+  ac->fin_cb_cls = fin_cb_cls;
+
+  /* never use loopback addresses if user wanted autoconfiguration */
+  GNUNET_CONFIGURATION_set_value_string (cfg, "nat", 
+                                        "USE_LOCALADDR", 
+                                        "NO");
+  next_phase (ac);
+  return ac;
+}
+
+
+/**
+ * Run the next phase of the auto test.
+ */
+static void
+next_phase (struct GNUNET_SetupAutoContext *ac)
+{
+  ac->phase++;
+  switch (ac->phase)
   {
-    GNUNET_break (0);
+  case AUTO_INIT:
+    GNUNET_assert (0);
+    break;
+  case AUTO_ONLINE:
+    test_online (ac);
+    break;
+  case AUTO_EXTERNAL_IP:
+    test_external_ip (ac);
+    break;
+  case AUTO_LOCAL_IP:
+    test_local_ip (ac);
+    break;
+  case AUTO_NAT_PUNCHED:
+    test_nat_punched (ac);
+    break;
+  case AUTO_UPNPC:
+    test_upnpc (ac);
+    break;
+  case AUTO_ICMP_SERVER:
+    test_icmp_server (ac);
+    break;
+  case AUTO_ICMP_CLIENT:
+    test_icmp_client (ac);
+    break;
+  case AUTO_DONE:
+    ac->fin_cb (ac->fin_cb_cls);
+    GNUNET_free (ac);
     return;
   }
-  gtk_toggle_button_set_active (button, hnc ? TRUE : FALSE);
 }
 
+
+/**
+ * Autoconfiguration test is finished, clear the block so
+ * that it can be run again.
+ *
+ * @param cls pointer to the location that needs to be NULLed
+ */
+static void
+clear_ac (void *cls)
+{
+  struct GNUNET_SetupAutoContext **acp = cls;
+
+  *acp = NULL;
+  gtk_widget_set_sensitive (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_autoconfig_button")),
+                           TRUE);
+}
+
+
+/**
+ * User asked for autoconfiguration.  Try the full program
+ */
+void
+GNUNET_setup_transport_autoconfig_button_clicked_cb ()
+{
+  static struct GNUNET_SetupAutoContext *ac;
+
+  /* make sure only one test is running at a time */
+  if (NULL != ac)
+  {
+    GNUNET_break (0);
+    return; 
+  }
+  gtk_widget_set_sensitive (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_transport_autoconfig_button")),
+                           FALSE);
+  ac = GNUNET_setup_transport_autoconfig_start (&clear_ac,
+                                               &ac);
+}
+
+
 /* end of gnunet-setup-transport.c */

Added: gnunet-gtk/src/setup/gnunet-setup-transport.h
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup-transport.h                               
(rev 0)
+++ gnunet-gtk/src/setup/gnunet-setup-transport.h       2012-11-01 16:19:50 UTC 
(rev 24657)
@@ -0,0 +1,58 @@
+/*
+     This file is part of GNUnet.
+     (C) 2010, 2012 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.h
+ * @brief support for transport (NAT) configuration
+ * @author Christian Grothoff
+ */
+#ifndef GNUNET_SETUP_TRANSPORT_H
+#define GNUNET_SETUP_TRANSPORT_H
+#include "gnunet-setup.h"
+#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_resolver_service.h>
+#include <gnunet/gnunet_nat_lib.h>
+
+/**
+ * Handle for the autoconfig operation.
+ */
+struct GNUNET_SetupAutoContext;
+
+/**
+ * Function called upon completion of the operation.
+ *
+ * @param cls closure
+ */
+typedef void (*GNUNET_SetupAutoConfigFinished)(void *cls);
+
+
+/**
+ * User asked for autoconfiguration.  Try the full program.
+ *
+ * @param fin_cb function to call when done
+ * @param fin_cb_cls closure for 'fin_cb'
+ * @return handle for the operation 
+ */
+struct GNUNET_SetupAutoContext *
+GNUNET_setup_transport_autoconfig_start (GNUNET_SetupAutoConfigFinished fin_cb,
+                                        void *fin_cb_cls);
+
+
+#endif

Modified: gnunet-gtk/src/setup/gnunet-setup.c
===================================================================
--- gnunet-gtk/src/setup/gnunet-setup.c 2012-11-01 16:01:39 UTC (rev 24656)
+++ gnunet-gtk/src/setup/gnunet-setup.c 2012-11-01 16:19:50 UTC (rev 24657)
@@ -24,6 +24,7 @@
  * @author Christian Grothoff
  */
 #include "gnunet-setup.h"
+#include "gnunet-setup-transport.h"
 #include "gnunet-setup-options.h"
 #include "gnunet-setup-gns.h"
 #include <gnunet/gnunet_constants.h>
@@ -64,13 +65,15 @@
 static struct GNUNET_OS_Process *namestore;
 
 /**
- * Flag to enable privilege escalation.
+ * Run autoconfig-only and then exit immediately.
  */
- 
+static int do_autoconfig;
 
 #ifndef MINGW
+/**
+ * Flag to enable privilege escalation.
+ */
 static int do_gksu;
-#endif
 
 /**
  * Show all configuration options, even if we are run
@@ -78,6 +81,7 @@
  * most options should not apply to the normal user.
  */ 
 static int force_full_setup;
+#endif
 
 
 /**
@@ -478,7 +482,21 @@
 }
 #endif
 
+
 /**
+ * Called once the autoconfiguration is done.  Triggers shutdown.
+ * 
+ * @param cls unused
+ */
+static void
+autoconfig_finished_cb (void *cls)
+{
+  GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE,
+                                     &cleanup_task, NULL);    
+}
+
+
+/**
  * Actual main method that sets up the configuration window.
  *
  * @param cls the main loop handle
@@ -579,6 +597,13 @@
     gtk_widget_hide (GTK_WIDGET (GNUNET_SETUP_get_object 
("GNUNET_setup_namestore_vbox")));
   }
 #endif
+  if (do_autoconfig)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+               _("Attempting fully-automatic, non-interactive network 
configuration\n"));
+    GNUNET_setup_transport_autoconfig_start (&autoconfig_finished_cb, NULL);
+    return;
+  }
   gtk_widget_show (main_window);
   gtk_window_present (GTK_WINDOW (main_window));
 }
@@ -595,14 +620,17 @@
 main (int argc, char *const *argv)
 {
   struct GNUNET_GETOPT_CommandLineOption options[] = {
+    { 'a', "autoconfig", NULL,
+      gettext_noop ("attempt automatic configuration of the network and 
instantly exit"),
+      0, &GNUNET_GETOPT_set_one, &do_autoconfig },
 #ifndef MINGW
     { 'e', "elevate-priviledges", NULL,
       gettext_noop ("run as user 'gnunet', if necessary by executing gksu to 
elevate rights"),
       0, &GNUNET_GETOPT_set_one, &do_gksu },
-#endif
     { 'f', "force-full-setup", NULL,
       gettext_noop ("force showing the full set of options, even if 
gnunet-setup is run as a normal user and as a user 'gnunet' exists on the 
system, most options should not apply to the normal user as GNUnet should be 
run by the 'gnunet' user"),
       0, &GNUNET_GETOPT_set_one, &force_full_setup },
+#endif
     GNUNET_GETOPT_OPTION_END
   };
   int ret;




reply via email to

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