gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11189 - gnunet/src/transport
Date: Wed, 5 May 2010 10:58:03 +0200

Author: wachs
Date: 2010-05-05 10:58:03 +0200 (Wed, 05 May 2010)
New Revision: 11189

Modified:
   gnunet/src/transport/plugin_transport_http.c
Log:


Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-05 08:55:11 UTC 
(rev 11188)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-05 08:58:03 UTC 
(rev 11189)
@@ -122,11 +122,17 @@
   struct GNUNET_TRANSPORT_PluginEnvironment *env;
 
   /**
+   * Handle to the network service.
+   */
+  struct GNUNET_SERVICE_Context *service;
+
+  /**
    * List of open sessions.
    */
   struct Session *sessions;
 };
 
+static struct Plugin *plugin;
 
 /**
  * Daemon for listening for new connections.
@@ -134,6 +140,11 @@
 static struct MHD_Daemon *http_daemon;
 
 /**
+ * Our primary task for http
+ */
+static GNUNET_SCHEDULER_TaskIdentifier http_task;
+
+/**
  * Curl multi for managing client operations.
  */
 static CURLM *curl_multi;
@@ -263,7 +274,7 @@
 acceptPolicyCallback (void *cls,
                       const struct sockaddr *addr, socklen_t addr_len)
 {
-
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG," Incoming connection \n");
   /* Currently all incoming connections are accepted, so nothing to do here */
   return MHD_YES;
 }
@@ -286,17 +297,22 @@
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' 
request from \n",method);
 
+  /* Find out if session exists, otherwise create one */
+
+  /* Is it a PUT or a GET request */
   if ( 0 == strcmp (MHD_HTTP_METHOD_PUT, method) )
-    {
-      /* PUT method here */
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got PUT Request with size %u 
\n",upload_data_size);
-      
-      // GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT 
requests"), 1, GNUNET_NO);
-    }
+  {
+    /* PUT method here */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got PUT Request with size %u 
\n",upload_data_size);
+
+    GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# PUT 
requests"), 1, GNUNET_NO);
+  }
   if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
-    {
-      /* FIXME */
-    }
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Got GET Request with size %u 
\n",upload_data_size);
+    GNUNET_STATISTICS_update( plugin->env->stats , gettext_noop("# GET 
requests"), 1, GNUNET_NO);
+  }
+
   return MHD_YES;
 }
 
@@ -312,7 +328,89 @@
 
 }
 
+
 /**
+ * Function that queries MHD's select sets and
+ * starts the task waiting for them.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier prepare_daemon (struct MHD_Daemon 
*daemon_handle);
+/**
+ * Call MHD to process pending requests and then go back
+ * and schedule the next run.
+ */
+static void
+run_daemon (void *cls,
+            const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  struct MHD_Daemon *daemon_handle = cls;
+
+  if (daemon_handle == http_daemon)
+    http_task = GNUNET_SCHEDULER_NO_TASK;
+
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+  GNUNET_assert (MHD_YES == MHD_run (daemon_handle));
+  if (daemon_handle == http_daemon)
+    http_task = prepare_daemon (daemon_handle);
+
+}
+
+/**
+ * Function that queries MHD's select sets and
+ * starts the task waiting for them.
+ */
+static GNUNET_SCHEDULER_TaskIdentifier
+prepare_daemon (struct MHD_Daemon *daemon_handle)
+{
+  GNUNET_SCHEDULER_TaskIdentifier ret;
+  fd_set rs;
+  fd_set ws;
+  fd_set es;
+  struct GNUNET_NETWORK_FDSet *wrs;
+  struct GNUNET_NETWORK_FDSet *wws;
+  struct GNUNET_NETWORK_FDSet *wes;
+  int max;
+  unsigned long long timeout;
+  int haveto;
+  struct GNUNET_TIME_Relative tv;
+
+  FD_ZERO(&rs);
+  FD_ZERO(&ws);
+  FD_ZERO(&es);
+  wrs = GNUNET_NETWORK_fdset_create ();
+  wes = GNUNET_NETWORK_fdset_create ();
+  wws = GNUNET_NETWORK_fdset_create ();
+  max = -1;
+  GNUNET_assert (MHD_YES ==
+                 MHD_get_fdset (daemon_handle,
+                                &rs,
+                                &ws,
+                                &es,
+                                &max));
+  haveto = MHD_get_timeout (daemon_handle, &timeout);
+  if (haveto == MHD_YES)
+    tv.value = (uint64_t) timeout;
+  else
+    tv = GNUNET_TIME_UNIT_FOREVER_REL;
+  GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max);
+  GNUNET_NETWORK_fdset_copy_native (wws, &ws, max);
+  GNUNET_NETWORK_fdset_copy_native (wes, &es, max);
+  ret = GNUNET_SCHEDULER_add_select (plugin->env->sched,
+                                     GNUNET_SCHEDULER_PRIORITY_HIGH,
+                                     GNUNET_SCHEDULER_NO_TASK,
+                                     tv,
+                                     wrs,
+                                     wws,
+                                     &run_daemon,
+                                     daemon_handle);
+  GNUNET_NETWORK_fdset_destroy (wrs);
+  GNUNET_NETWORK_fdset_destroy (wws);
+  GNUNET_NETWORK_fdset_destroy (wes);
+  return ret;
+}
+
+
+/**
  * Entry point for the plugin.
  */
 void *
@@ -320,8 +418,8 @@
 {
   struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
   struct GNUNET_TRANSPORT_PluginFunctions *api;
-  struct Plugin *plugin;
   long long unsigned int port;
+  struct GNUNET_SERVICE_Context *service;
   int use_ipv6;
 
   plugin = GNUNET_malloc (sizeof (struct Plugin));
@@ -334,6 +432,18 @@
   api->address_pretty_printer = &http_plugin_address_pretty_printer;
   api->check_address = &http_plugin_address_suggested;
 
+  /*
+  service = GNUNET_SERVICE_start ("transport-http", env->sched, env->cfg);
+  if (service == NULL)
+    {
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+                       "http",
+                       _("Failed to start service for `%s' transport 
plugin.\n"),
+                       "http");
+      return NULL;
+    }
+  plugin->service = service;
+  */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Starting http plugin...\n");
   /* Reading port number from config file */
   if ((GNUNET_OK !=
@@ -397,6 +507,8 @@
 
   curl_multi = curl_multi_init ();
 
+  if (http_daemon != NULL)
+    http_task = prepare_daemon (http_daemon);
 
   if (NULL == plugin->env->stats)
   {
@@ -407,6 +519,7 @@
   }
 
   GNUNET_STATISTICS_set ( env->stats, "# PUT requests", 0, GNUNET_NO);
+  GNUNET_STATISTICS_set ( env->stats, "# GET requests", 0, GNUNET_NO);
 
   if ( (NULL == http_daemon) || (NULL == curl_multi))
   {
@@ -438,7 +551,7 @@
   curl_multi = NULL;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Shutting down http plugin...\n");
-
+  /* GNUNET_SERVICE_stop (plugin->service); */
   GNUNET_free (plugin);
   GNUNET_free (api);
   return NULL;





reply via email to

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