gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11179 - gnunet/src/transport
Date: Tue, 4 May 2010 15:18:40 +0200

Author: wachs
Date: 2010-05-04 15:18:40 +0200 (Tue, 04 May 2010)
New Revision: 11179

Modified:
   gnunet/src/transport/Makefile.am
   gnunet/src/transport/plugin_transport_http.c
   gnunet/src/transport/test_plugin_transport_http.c
Log:


Modified: gnunet/src/transport/Makefile.am
===================================================================
--- gnunet/src/transport/Makefile.am    2010-05-04 12:37:45 UTC (rev 11178)
+++ gnunet/src/transport/Makefile.am    2010-05-04 13:18:40 UTC (rev 11179)
@@ -168,6 +168,7 @@
  test_plugin_transport_http.c
 test_plugin_transport_http_LDADD = \
  $(top_builddir)/src/transport/libgnunettransport.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
  $(top_builddir)/src/util/libgnunetutil.la  
 
 

Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-05-04 12:37:45 UTC 
(rev 11178)
+++ gnunet/src/transport/plugin_transport_http.c        2010-05-04 13:18:40 UTC 
(rev 11179)
@@ -125,14 +125,9 @@
    * List of open sessions.
    */
   struct Session *sessions;
+};
 
-  /**
-   * Handle for the statistics service.
-   */
-  struct GNUNET_STATISTICS_Handle *statistics;
 
-};
-
 /**
  * Daemon for listening for new connections.
  */
@@ -268,6 +263,8 @@
 acceptPolicyCallback (void *cls,
                       const struct sockaddr *addr, socklen_t addr_len)
 {
+
+  /* Currently all incoming connections are accepted, so nothing to do here */
   return MHD_YES;
 }
 
@@ -287,6 +284,17 @@
                        const char *upload_data,
                        size_t * upload_data_size, void **httpSessionCache)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"HTTP Daemon has an incoming `%s' 
request from \n",method);
+
+  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);
+  }
+  if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) )
+
   return MHD_YES;
 }
 
@@ -316,7 +324,7 @@
 
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->env = env;
-  plugin->statistics = NULL;
+
   api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
   api->cls = plugin;
   api->send = &http_plugin_send;
@@ -386,6 +394,16 @@
 
   curl_multi = curl_multi_init ();
 
+
+  if (NULL == plugin->env->stats)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                _("Failed to retrieve statistics handle\n"));
+    return NULL;
+  }
+
+  GNUNET_STATISTICS_set ( env->stats, "# PUT requests", 0, GNUNET_NO);
+
   if ( (NULL == http_daemon) || (NULL == curl_multi))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Initializing http plugin failed\n");

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-05-04 12:37:45 UTC 
(rev 11178)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-05-04 13:18:40 UTC 
(rev 11179)
@@ -34,6 +34,7 @@
 #include "gnunet_program_lib.h"
 #include "gnunet_signatures.h"
 #include "plugin_transport.h"
+#include "gnunet_statistics_service.h"
 #include "transport.h"
 
 #define VERBOSE GNUNET_YES
@@ -65,6 +66,12 @@
 struct GNUNET_SCHEDULER_Handle *sched;
 
 /**
+ * Our statistics handle.
+ */
+struct GNUNET_STATISTICS_Handle *stats;
+
+
+/**
  * Our configuration.
  */
 const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -87,8 +94,10 @@
 /**
  * Did the test pass or fail?
  */
-static int ok;
+static int fail;
 
+static GNUNET_SCHEDULER_TaskIdentifier timeout_task;
+
 /**
  * Initialize Environment for this plugin
  */
@@ -129,8 +138,6 @@
                                        api));
   if (my_private_key != NULL)
     GNUNET_CRYPTO_rsa_key_free (my_private_key);
-
-  ok = 0;
 }
 
 /**
@@ -141,29 +148,34 @@
  * isn't enabled (eg. FreeBSD > 4)
  */
 static void
-test_validation ()
+shutdown_clean ()
 {
-  struct sockaddr_in soaddr;
-  memset (&soaddr, 0, sizeof (soaddr));
-#if HAVE_SOCKADDR_IN_SIN_LEN
-  soaddr.sin_len = sizeof (soaddr);
-#endif
-  soaddr.sin_family = AF_INET;
-  soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
-  soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-
-  api->check_address(api->cls,
-      &soaddr, sizeof (soaddr));
-
+  if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
+    GNUNET_SCHEDULER_cancel( sched, timeout_task );
   unload_plugins(env.cls, env.cfg);
 }
 
+/**
+ * Timeout, give up.
+ */
+static void
+timeout_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  timeout_task = GNUNET_SCHEDULER_NO_TASK;
+  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+    return;
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+              "Timeout while executing testcase, test failed.\n");
+  fail = GNUNET_YES;
+  shutdown_clean();
+}
 
 static void
 setup_plugin_environment ()
 {
   env.cfg = cfg;
   env.sched = sched;
+  env.stats = stats;
   env.my_identity = &my_identity;
   env.cls = &env;
   env.receive = &receive;
@@ -190,6 +202,9 @@
 
   sched = s;
   cfg = c;
+
+  timeout_task = GNUNET_SCHEDULER_add_delayed ( sched,  
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), &timeout_error, 
NULL);
+
   /* parse configuration */
   if ((GNUNET_OK !=
        GNUNET_CONFIGURATION_get_value_number (c,
@@ -202,11 +217,14 @@
                                                 "HOSTKEY", &keyfile)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                  _
-                  ("Transport service is lacking key configuration settings.  
Exiting.\n"));
+                  _("Transport service is lacking key configuration settings.  
Exiting.\n"));
       GNUNET_SCHEDULER_shutdown (s);
       return;
     }
+
+
+  stats = GNUNET_STATISTICS_create (sched, "http-transport", cfg);
+
   /*
   max_connect_per_transport = (uint32_t) tneigh;
   my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
@@ -238,10 +256,12 @@
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   _("Failed to load http transport plugin\n"));
-      /* FIXME: set some error code for main */
+      fail = GNUNET_YES;
       return;
+
     }
-  test_validation ();
+  fail = GNUNET_NO;
+  shutdown_clean ();
 }
 
 
@@ -278,16 +298,15 @@
                     "WARNING",
 #endif
                     NULL);
-  ok = 1;                       /* set to fail */
+  fail = GNUNET_YES;
   ret = (GNUNET_OK ==
          GNUNET_PROGRAM_run (5,
                              argv_prog,
                              "test-plugin-transport_http",
-                             "testcase", options, &run, NULL)) ? ok : 1;
+                             "testcase", options, &run, NULL)) ? fail : 1;
   GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-plugin-transport_http");
-  /* FIXME: return correct value */
-  /* return ret; */
-  return GNUNET_NO;
+
+  return fail;
 }
 
 /* end of test_plugin_transport_http.c */





reply via email to

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