gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11163 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r11163 - gnunet/src/transport
Date: Mon, 3 May 2010 17:06:36 +0200

Author: wachs
Date: 2010-05-03 17:06:36 +0200 (Mon, 03 May 2010)
New Revision: 11163

Modified:
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/plugin_transport_http.c
   gnunet/src/transport/test_plugin_transport_data_http.conf
   gnunet/src/transport/test_plugin_transport_http.c
   gnunet/src/transport/test_transport_api_http_peer1.conf
   gnunet/src/transport/test_transport_api_http_peer2.conf
Log:


Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2010-05-03 14:40:42 UTC (rev 11162)
+++ gnunet/src/transport/Makefile.am    2010-05-03 15:06:36 UTC (rev 11163)
@@ -6,6 +6,12 @@
   WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
 endif
 
+if HAVE_MHD 
+ GN_LIBMHD = -lmicrohttpd
+ HTTP_PLUGIN_LA = libgnunet_plugin_transport_http.la
+ HTTP_PLGUIN_CHECK = test_plugin_transport_http
+endif
+
 if USE_COVERAGE
   AM_CFLAGS = --coverage -O0
 endif
@@ -69,8 +75,8 @@
   libgnunet_plugin_transport_tcp.la \
   libgnunet_plugin_transport_udp.la \
   libgnunet_plugin_transport_udp_nat.la \
+  $(HTTP_PLUGIN_LA) \
   libgnunet_plugin_transport_template.la
-# libgnunet_plugin_transport_http.la  
 # TODO: add http, nat, etc.
 
 libgnunet_plugin_transport_tcp_la_SOURCES = \
@@ -110,6 +116,7 @@
 libgnunet_plugin_transport_udp_nat_la_LDFLAGS = \
  $(GN_PLUGIN_LDFLAGS)
 
+if HAVE_MHD 
 libgnunet_plugin_transport_http_la_SOURCES = \
   plugin_transport_http.c
 libgnunet_plugin_transport_http_la_LIBADD = \
@@ -118,14 +125,15 @@
   $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
   $(top_builddir)/src/util/libgnunetutil.la 
 libgnunet_plugin_transport_http_la_LDFLAGS = \
+ $(GN_LIBMHD) \
  $(GN_PLUGIN_LDFLAGS)
-
+endif
  
 check_PROGRAMS = \
  test_transport_api_tcp \
  test_transport_api_udp \
- test_transport_api_udp_nat \
- test_plugin_transport_http
+ $(HTTP_PLGUIN_CHECK) \ 
+ test_transport_api_udp_nat
 # test_transport_api_http \
 # TODO: add tests for http, nat, etc.
 

Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-03 14:40:42 UTC 
(rev 11162)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-03 15:06:36 UTC 
(rev 11163)
@@ -32,8 +32,10 @@
 #include "gnunet_statistics_service.h"
 #include "gnunet_transport_service.h"
 #include "plugin_transport.h"
+#include "microhttpd.h"
 
-#define DEBUG_HTTP GNUNET_YES
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
 
 /**
  * After how long do we expire an address that we
@@ -42,6 +44,7 @@
  */
 #define LEARNED_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_HOURS, 6)
 
+#define HTTP_TIMEOUT 600
 
 /**
  * Encapsulation of all of the state of the plugin.
@@ -130,6 +133,11 @@
 };
 
 /**
+ * Daemon for listening for new connections.
+ */
+static struct MHD_Daemon *http_daemon;
+
+/**
  * Function that can be used by the transport service to transmit
  * a message using the plugin.
  *
@@ -247,8 +255,48 @@
   return GNUNET_OK;
 }
 
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+acceptPolicyCallback (void *cls,
+                      const struct sockaddr *addr, socklen_t addr_len)
+{
+  return MHD_YES;
+}
 
 /**
+ * Process GET or PUT request received via MHD.  For
+ * GET, queue response that will send back our pending
+ * messages.  For PUT, process incoming data and send
+ * to GNUnet core.  In either case, check if a session
+ * already exists and create a new one if not.
+ */
+static int
+accessHandlerCallback (void *cls,
+                       struct MHD_Connection *session,
+                       const char *url,
+                       const char *method,
+                       const char *version,
+                       const char *upload_data,
+                       size_t * upload_data_size, void **httpSessionCache)
+{
+  return MHD_YES;
+}
+
+/**
+ * MHD is done handling a request.  Cleanup
+ * the respective transport state.
+ */
+static void
+requestCompletedCallback (void *unused,
+                          struct MHD_Connection *session,
+                          void **httpSessionCache)
+{
+
+}
+
+/**
  * Entry point for the plugin.
  */
 void *
@@ -257,6 +305,8 @@
   struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
   struct GNUNET_TRANSPORT_PluginFunctions *api;
   struct Plugin *plugin;
+  long long unsigned int port;
+  int use_ipv6;
 
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->env = env;
@@ -267,7 +317,73 @@
   api->disconnect = &http_plugin_disconnect;
   api->address_pretty_printer = &http_plugin_address_pretty_printer;
   api->check_address = &http_plugin_address_suggested;
-  return api;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
+  /* Reading port number from config file */
+  if ((GNUNET_OK !=
+       GNUNET_CONFIGURATION_get_value_number (env->cfg,
+                                              "transport-http",
+                                              "PORT",
+                                              &port)) ||
+      (port > 65535) )
+    {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+                       "http",
+                       _
+                       ("Require valid port number for service `%s' in 
configuration!\n"),
+                       "transport-http");
+      return NULL;
+    }
+  use_ipv6 = GNUNET_YES;
+  use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno  (env->cfg, 
"transport-http","USE_IPV6");
+  if ((http_daemon == NULL) && (port != 0))
+    {
+      if ( use_ipv6 == GNUNET_YES)
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon could not started, 
http plugin not working\n");
+          http_daemon = MHD_start_daemon (MHD_USE_IPv6,
+                                         port,
+                                         &acceptPolicyCallback,
+                                         NULL, &accessHandlerCallback, NULL,
+                                         MHD_OPTION_CONNECTION_TIMEOUT,
+                                         (unsigned int) HTTP_TIMEOUT,
+                                         MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+                                         (unsigned int) 
GNUNET_SERVER_MAX_MESSAGE_SIZE,
+                                         MHD_OPTION_CONNECTION_LIMIT,
+                                         (unsigned int) 128,
+                                         MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+                                         (unsigned int) 8,
+                                         MHD_OPTION_NOTIFY_COMPLETED,
+                                         &requestCompletedCallback, NULL,
+                                         MHD_OPTION_END);
+        }
+      else
+        {
+          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting MHD on port %u with 
IPv6 disabled\n",port);
+          http_daemon = MHD_start_daemon (MHD_NO_FLAG,
+                                         port,
+                                         &acceptPolicyCallback,
+                                         NULL, &accessHandlerCallback, NULL,
+                                         MHD_OPTION_CONNECTION_TIMEOUT,
+                                         (unsigned int) HTTP_TIMEOUT,
+                                         MHD_OPTION_CONNECTION_MEMORY_LIMIT,
+                                         (unsigned int) 
GNUNET_SERVER_MAX_MESSAGE_SIZE,
+                                         MHD_OPTION_CONNECTION_LIMIT,
+                                         (unsigned int) 128,
+                                         MHD_OPTION_PER_IP_CONNECTION_LIMIT,
+                                         (unsigned int) 8,
+                                         MHD_OPTION_NOTIFY_COMPLETED,
+                                         &requestCompletedCallback, NULL,
+                                         MHD_OPTION_END);
+        }
+    }
+  if ( NULL != http_daemon )
+    return api;
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,"Starting MHD on port %u with IPv6 
disabled\n",port);
+    return NULL;
+  }
 }
 
 
@@ -280,6 +396,13 @@
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
 
+  if (http_daemon != NULL)
+  {
+    MHD_stop_daemon (http_daemon);
+    http_daemon = NULL;
+  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Shutting down http plugin...\n");
+
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;

Modified: gnunet/src/transport/test_plugin_transport_data_http.conf
===================================================================
--- gnunet/src/transport/test_plugin_transport_data_http.conf   2010-05-03 
14:40:42 UTC (rev 11162)
+++ gnunet/src/transport/test_plugin_transport_data_http.conf   2010-05-03 
15:06:36 UTC (rev 11163)
@@ -1,24 +1,8 @@
 [PATHS]
-SERVICEHOME = /tmp/test-gnunetd-plugin-transport_http/
+DEFAULTCONFIG = test_transport_api_tcp_peer1.conf
+SERVICEHOME = /tmp/test-gnunetd-transport-peer-1/
 
-[resolver]
-PORT = 2364
-
-[transport]
-PORT = 2365
-PLUGINS = http
-
-[arm]
-PORT = 2366
-
-[statistics]
-PORT = 2367
-
-[transport-udp]
-PORT = 2368
-
-[peerinfo]
-PORT = 2369
-
-[testing]
-WEAKRANDOM = YES
+[transport-http]
+PORT = 12389
+DEBUG = YES
+USE_IPV6 = NO
\ No newline at end of file

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-03 14:40:42 UTC 
(rev 11162)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-03 15:06:36 UTC 
(rev 11163)
@@ -36,7 +36,8 @@
 #include "plugin_transport.h"
 #include "transport.h"
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
 
 /**
  * How long until we give up on transmitting the message?
@@ -124,7 +125,7 @@
 unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
 {
   GNUNET_assert (NULL ==
-                 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp",
+                 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_http",
                                        api));
   if (my_private_key != NULL)
     GNUNET_CRYPTO_rsa_key_free (my_private_key);
@@ -143,7 +144,6 @@
 test_validation ()
 {
   struct sockaddr_in soaddr;
-
   memset (&soaddr, 0, sizeof (soaddr));
 #if HAVE_SOCKADDR_IN_SIN_LEN
   soaddr.sin_len = sizeof (soaddr);
@@ -207,6 +207,7 @@
       GNUNET_SCHEDULER_shutdown (s);
       return;
     }
+  /*
   max_connect_per_transport = (uint32_t) tneigh;
   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
   GNUNET_free (keyfile);
@@ -220,14 +221,18 @@
     }
   GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
   GNUNET_CRYPTO_hash (&my_public_key,
-                      sizeof (my_public_key), &my_identity.hashPubKey);
+                      sizeof (my_public_key), &my_identity.hashPubKey);*/
 
   /* load plugins... */
   setup_plugin_environment ();
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading http transport plugin\n"));
+
   GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
 
   api = GNUNET_PLUGIN_load (libname, &env);
+  if (api != NULL )
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Loading transport plugin for http `%s' successful\n",libname);
+
   GNUNET_free (libname);
   if (api == NULL)
     {

Modified: gnunet/src/transport/test_transport_api_http_peer1.conf
===================================================================
--- gnunet/src/transport/test_transport_api_http_peer1.conf     2010-05-03 
14:40:42 UTC (rev 11162)
+++ gnunet/src/transport/test_transport_api_http_peer1.conf     2010-05-03 
15:06:36 UTC (rev 11163)
@@ -1,5 +1,6 @@
 [transport-http]
-PORT = 12368
+#PORT = 12368
+DEBUG=YES
 
 [fs]
 ALLOW_SHUTDOWN = YES

Modified: gnunet/src/transport/test_transport_api_http_peer2.conf
===================================================================
--- gnunet/src/transport/test_transport_api_http_peer2.conf     2010-05-03 
14:40:42 UTC (rev 11162)
+++ gnunet/src/transport/test_transport_api_http_peer2.conf     2010-05-03 
15:06:36 UTC (rev 11163)
@@ -1,5 +1,6 @@
 [transport-http]
 PORT = 22368
+DEBUG = YES
 
 [fs]
 ALLOW_SHUTDOWN = YES
@@ -49,7 +50,7 @@
 
 [transport]
 PLUGINS = http
-#DEBUG = YES
+DEBUG = YES
 # PREFIX = 
 ALLOW_SHUTDOWN = YES
 ACCEPT_FROM6 = ::1;





reply via email to

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