gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11628 - gnunet/src/transport
Date: Mon, 7 Jun 2010 17:58:54 +0200

Author: wachs
Date: 2010-06-07 17:58:54 +0200 (Mon, 07 Jun 2010)
New Revision: 11628

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


Modified: gnunet/src/transport/plugin_transport_http.c
===================================================================
--- gnunet/src/transport/plugin_transport_http.c        2010-06-07 11:58:17 UTC 
(rev 11627)
+++ gnunet/src/transport/plugin_transport_http.c        2010-06-07 15:58:54 UTC 
(rev 11628)
@@ -216,6 +216,11 @@
   unsigned int is_put_in_progress;
 
   /**
+   * Is there a HTTP/PUT in progress?
+   */
+  unsigned int is_bad_request;
+
+  /**
    * Encoded hash
    */
   struct GNUNET_CRYPTO_HashAsciiEncoded hash;
@@ -415,6 +420,8 @@
 }
 
 
+int serror;
+
 /**
  * Process GET or PUT request received via MHD.  For
  * GET, queue response that will send back our pending
@@ -446,6 +453,7 @@
 
   gn_msg = NULL;
   send_error_to_client = GNUNET_NO;
+
   if ( NULL == *httpSessionCache)
   {
     /* check url for peer identity */
@@ -546,11 +554,30 @@
       cs->is_active = GNUNET_YES;
       return MHD_YES;
     }
+
+    if (cs->is_bad_request == GNUNET_YES)
+    {
+      *upload_data_size = 0;
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Info: size: %u method: %s 
\n",*upload_data_size,method);
+      response = MHD_create_response_from_data (strlen 
(HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
+      if (response == NULL)
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"response NULL\n");
+      res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
+      if (res == MHD_YES)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as 
PUT Response\n");
+        cs->is_bad_request = GNUNET_NO;
+        cs->is_put_in_progress =GNUNET_NO;
+      }
+      else
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as 
PUT Response not sent\n");
+      MHD_destroy_response (response);
+      return MHD_YES;
+    }
+
     if ( *upload_data_size > 0 )
     {
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT URL: `%s'\n",url);
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"PUT Request: %lu bytes: `%s' \n", 
(*upload_data_size), upload_data);
-      /* No data left */
+
       bytes_recv = *upload_data_size ;
       *upload_data_size = 0;
 
@@ -572,25 +599,26 @@
 
       if ( ntohs(gn_msg->size) != bytes_recv )
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Message has incorrect size, is %u 
bytes vs %u recieved'\n",ntohs(gn_msg->size) , bytes_recv);
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet: message has 
incorrect size, is %u bytes in header vs %u recieved\n",ntohs(gn_msg->size) , 
bytes_recv);
         send_error_to_client = GNUNET_YES;
       }
 
-      if ( GNUNET_YES == send_error_to_client)
+      if (send_error_to_client == GNUNET_YES)
       {
-        response = MHD_create_response_from_data (strlen 
(HTTP_PUT_RESPONSE),HTTP_PUT_RESPONSE, MHD_NO, MHD_NO);
-        res = MHD_queue_response (session, MHD_HTTP_BAD_REQUEST, response);
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 400 BAD REQUEST as 
PUT Response\n",HTTP_PUT_RESPONSE, strlen (HTTP_PUT_RESPONSE), res );
-        MHD_destroy_response (response);
-        GNUNET_free (gn_msg);
-        return MHD_NO;
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Malformed GNUnet, should send 
error\n");
+        cs->is_bad_request = GNUNET_YES;
+        return MHD_YES;
       }
+
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Recieved GNUnet message type %u 
size %u and payload %u \n",ntohs (gn_msg->type), ntohs (gn_msg->size), ntohs 
(gn_msg->size)-sizeof(struct GNUNET_MessageHeader));
 
       /* forwarding message to transport */
       plugin->env->receive(plugin->env, &(cs->sender), gn_msg, 1, cs , cs->ip, 
strlen(cs->ip) );
+      GNUNET_free (gn_msg);
       return MHD_YES;
     }
+
+
     if ((*upload_data_size == 0) && (cs->is_put_in_progress == GNUNET_YES))
     {
       cs->is_put_in_progress = GNUNET_NO;

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-06-07 11:58:17 UTC 
(rev 11627)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-06-07 15:58:54 UTC 
(rev 11628)
@@ -42,9 +42,9 @@
 #include "transport.h"
 #include <curl/curl.h>
 
-#define VERBOSE GNUNET_NO
-#define DEBUG GNUNET_NO
-#define DEBUG_CURL GNUNET_NO
+#define VERBOSE GNUNET_YES
+#define DEBUG GNUNET_YES
+#define DEBUG_CURL GNUNET_YES
 #define HTTP_BUFFER_SIZE 2048
 
 #define PLUGIN libgnunet_plugin_transport_template
@@ -95,7 +95,7 @@
   /**
    * buffer
    */
-  char *buf;
+  unsigned char buf[HTTP_BUFFER_SIZE];
 
   /**
    * current position in buffer
@@ -127,7 +127,7 @@
   /**
    * buffer for http transfers
    */
-  unsigned char buf[2048];
+  unsigned char buf[HTTP_BUFFER_SIZE];
 
   /**
    * buffer size this transfer
@@ -309,8 +309,22 @@
  */
 static struct HTTP_Transfer test_too_long_ident;
 
+/**
+ * Test: connect to peer and send message bigger then content length
+ */
+static struct HTTP_Transfer test_msg_too_big;
 
 /**
+ * Test: connect to peer and send message bigger GNUNET_SERVER_MAX_MESSAGE_SIZE
+ */
+//static struct HTTP_Transfer test_msg_bigger_max;
+
+/**
+ * Test: connect to peer and send message smaller then content length
+ */
+//static struct HTTP_Transfer test_msg_too_small;
+
+/**
  * Test: connect to peer with valid peer identification
  */
 static struct HTTP_Transfer test_valid_ident;
@@ -386,9 +400,6 @@
 
   GNUNET_SCHEDULER_shutdown(sched);
 
-  GNUNET_free (buffer_in.buf);
-  GNUNET_free (buffer_out.buf);
-
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
   exit(fail);
   return;
@@ -459,14 +470,24 @@
 static size_t send_function (void *stream, size_t size, size_t nmemb, void 
*ptr)
 {
   unsigned int len;
-  struct HTTP_Message  * cbc = ptr;
+  struct HTTP_Transfer * test = (struct HTTP_Transfer *) ptr;
 
-  len = cbc->len;
+  len = buffer_out.len;
 
-  if (( cbc->pos == len) && (len < (size * nmemb)))
+  if (test == &test_msg_too_big)
+  {
+    if (buffer_out.pos > len)
+      return 0;
+    if ( (2*len) < (size * nmemb))
+      memcpy(stream, buffer_out.buf,  2* len);
+    buffer_out.pos = 2* len;
+    return 2* len;
+  }
+
+  if (( buffer_out.pos == len) || (len > (size * nmemb)))
     return 0;
-  memcpy(stream, cbc->buf, len);
-  cbc->pos = len;
+  memcpy(stream, buffer_out.buf, len);
+  buffer_out.pos = len;
   return len;
 }
 
@@ -494,6 +515,7 @@
   memcpy(tmp,ptr,len);
   if (tmp[len-2] == 13)
     tmp[len-2]= '\0';
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Header: `%s'\n"),tmp);
   if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
   {
     res->http_result_code=100;
@@ -698,7 +720,7 @@
   curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
   curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
   curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
-  curl_easy_setopt (curl_handle, CURLOPT_READDATA, &buffer_out);
+  curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
   curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 
buffer_out.len);
   curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30);
   curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
@@ -833,7 +855,7 @@
     /* Connecting to peer without identification */
     host_str = GNUNET_malloc (strlen ("http://localhost:12389/";)+1);
     GNUNET_asprintf (&host_str, "http://localhost:%u/",port);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer 
identification.\n"), host_str);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer 
identification.\n"));
     test_no_ident.test_executed = GNUNET_YES;
     send_data ( &test_no_ident, host_str);
     GNUNET_free (host_str);
@@ -847,7 +869,7 @@
     /* Connecting to peer with too short identification */
     host_str = GNUNET_malloc (strlen ("http://localhost:12389/";) + strlen 
(ident));
     GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short 
peer identification.\n"), host_str);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short 
peer identification.\n"));
     test_too_short_ident.test_executed = GNUNET_YES;
     send_data ( &test_too_short_ident, host_str);
     GNUNET_free (host_str);
@@ -863,7 +885,7 @@
     host_str = GNUNET_malloc (strlen ("http://localhost:12389/";) + strlen 
(ident));
     GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,ident);
 
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long 
peer identification.\n"), host_str);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long 
peer identification.\n"));
     test_too_long_ident.test_executed = GNUNET_YES;
     send_data ( &test_too_long_ident, host_str);
     GNUNET_free (host_str);
@@ -878,14 +900,36 @@
     host_str = GNUNET_malloc (strlen ("http://localhost:12389/";) + strlen 
((const char *) &result));
     GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) 
&result);
 
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer 
identification.\n"), host_str);
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer 
identification.\n"));
     test_valid_ident.test_executed = GNUNET_YES;
     send_data ( &test_valid_ident, host_str);
     GNUNET_free (host_str);
 
     return;
   }
+/*
+  if (test_msg_too_big.test_executed == GNUNET_NO)
+  {
+    struct GNUNET_CRYPTO_HashAsciiEncoded result;
+    unsigned int c;
 
+    GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&result);
+    host_str = GNUNET_malloc (strlen ("http://localhost:12389/";) + strlen 
((const char *) &result));
+    GNUNET_asprintf (&host_str, "http://localhost:%u/%s",port,(char *) 
&result);
+
+    buffer_out.len = 50;
+    c = 0;
+    for (c=0; c<100; c++)
+      buffer_out.buf[c] = 'A';
+
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with message 
bigger content length.\n"));
+    test_msg_too_big.test_executed = GNUNET_YES;
+    send_data ( &test_msg_too_big, host_str);
+    GNUNET_free (host_str);
+
+    return;
+  }
+*/
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
   shutdown_clean();
 }
@@ -1039,12 +1083,10 @@
 
   /* Setting up buffers */
   buffer_in.size = HTTP_BUFFER_SIZE;
-  buffer_in.buf = GNUNET_malloc (HTTP_BUFFER_SIZE);
   buffer_in.pos = 0;
   buffer_in.len = 0;
 
   buffer_out.size = HTTP_BUFFER_SIZE;
-  buffer_out.buf = GNUNET_malloc (HTTP_BUFFER_SIZE);
   buffer_out.pos = 0;
   buffer_out.len = 0;
 
@@ -1066,6 +1108,10 @@
   test_valid_ident.test_executed = GNUNET_NO;
   test_valid_ident.test_failed = GNUNET_YES;
 
+  /* Test: connecting with valid identification */
+  test_msg_too_big.test_executed = GNUNET_NO;
+  test_msg_too_big.test_failed = GNUNET_YES;
+
   run_connection_tests();
 
   /* testing finished */




reply via email to

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