psyc/social: local join flag; social service: leave place, save _file
[oweals/gnunet.git] / src / pt / test_gnunet_vpn.c
index d2d1666253a70d58aa7c50d2291e549970a4c995..b5bc1395ba6018bb9be4c22019888b4a9d4b2188 100644 (file)
@@ -14,8 +14,8 @@
 
      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.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
  * @author Christian Grothoff
  */
 #include "platform.h"
+#if HAVE_CURL_CURL_H
 #include <curl/curl.h>
+#elif HAVE_GNURL_CURL_H
+#include <gnurl/curl.h>
+#endif
 #include <microhttpd.h>
 #include "gnunet_vpn_service.h"
 #include "gnunet_testing_lib.h"
@@ -167,19 +171,8 @@ do_shutdown ()
  * Function to run the HTTP client.
  */
 static void
-curl_main (void);
-
-
-static void
-curl_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
-  curl_task_id = NULL;
-  curl_main ();
-}
-
-
-static void
-curl_main ()
+curl_main (void *cls,
+           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   fd_set rs;
   fd_set ws;
@@ -192,6 +185,7 @@ curl_main ()
   int running;
   struct CURLMsg *msg;
 
+  curl_task_id = NULL;
   max = 0;
   FD_ZERO (&rs);
   FD_ZERO (&ws);
@@ -241,7 +235,7 @@ curl_main ()
   GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1);
   curl_task_id =
       GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay,
-                                   &nrs, &nws, &curl_task, NULL);
+                                   &nrs, &nws, &curl_main, NULL);
 }
 
 
@@ -270,9 +264,16 @@ allocation_cb (void *cls, int af, const void *address)
     GNUNET_SCHEDULER_shutdown ();
     return;
   }
-  GNUNET_asprintf (&url, "http://%s:%u/hello_world",
-                   inet_ntop (af, address, ips, sizeof (ips)),
-                   (unsigned int) PORT);
+  if (AF_INET6 == af)
+    GNUNET_asprintf (&url,
+                     "http://[%s]:%u/hello_world",
+                     inet_ntop (af, address, ips, sizeof (ips)),
+                     (unsigned int) PORT);
+  else
+    GNUNET_asprintf (&url,
+                     "http://%s:%u/hello_world",
+                     inet_ntop (af, address, ips, sizeof (ips)),
+                     (unsigned int) PORT);
   curl = curl_easy_init ();
   curl_easy_setopt (curl, CURLOPT_URL, url);
   curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, &copy_buffer);
@@ -281,13 +282,17 @@ allocation_cb (void *cls, int af, const void *address)
   curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L);
   curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L);
   curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1);
+  curl_easy_setopt (curl, CURLOPT_VERBOSE, 0);
 
   multi = curl_multi_init ();
   GNUNET_assert (multi != NULL);
   GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl));
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Beginning HTTP download from `%s'\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Beginning HTTP download from `%s'\n",
               url);
-  curl_main ();
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                &curl_main,
+                                NULL);
 }
 
 
@@ -406,7 +411,8 @@ main (int argc, char *const *argv)
   {
     GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "access",
                               "/dev/net/tun");
-    fprintf (stderr, "WARNING: System unable to run test, skipping.\n");
+    fprintf (stderr,
+             "WARNING: System unable to run test, skipping.\n");
     return 0;
   }
 #endif
@@ -430,7 +436,8 @@ main (int argc, char *const *argv)
   type = strstr (bin, "-");
   if (NULL == type)
   {
-    fprintf (stderr, "invalid binary name\n");
+    fprintf (stderr,
+             "invalid binary name\n");
     return 1;
   }
   type++;