gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r11769 - gnunet/src/transport
Date: Wed, 16 Jun 2010 17:56:24 +0200

Author: wachs
Date: 2010-06-16 17:56:24 +0200 (Wed, 16 Jun 2010)
New Revision: 11769

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-16 13:10:19 UTC 
(rev 11768)
+++ gnunet/src/transport/plugin_transport_http.c        2010-06-16 15:56:24 UTC 
(rev 11769)
@@ -152,6 +152,8 @@
    * Closure for transmit_cont.
    */
   void *transmit_cont_cls;
+
+  unsigned int http_result_code;
 };
 
 
@@ -586,9 +588,10 @@
       res = MHD_queue_response (session, MHD_HTTP_REQUEST_ENTITY_TOO_LARGE, 
response);
       if (res == MHD_YES)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 ENTITY TOO 
LARGE as PUT Response\n");
+        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sent HTTP/1.1: 413 Request Entity 
Too Large as PUT Response\n");
         cs->is_bad_request = GNUNET_NO;
         cs->is_put_in_progress =GNUNET_NO;
+        cs->pending_inbound_msg->pos = 0;
       }
       MHD_destroy_response (response);
       return MHD_YES;
@@ -801,6 +804,7 @@
 {
   char * tmp;
   unsigned int len = size * nmemb;
+  struct Session * ses = stream;
 
   tmp = GNUNET_malloc (  len+1 );
   memcpy(tmp,ptr,len);
@@ -809,28 +813,26 @@
 #if DEBUG_CURL
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp);
 #endif
-  /*
   if (0==strcmp (tmp,"HTTP/1.1 100 Continue"))
   {
-    res->http_result_code=100;
+    ses->pending_outbound_msg->http_result_code=100;
   }
   if (0==strcmp (tmp,"HTTP/1.1 200 OK"))
   {
-    res->http_result_code=200;
+    ses->pending_outbound_msg->http_result_code=200;
   }
   if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request"))
   {
-    res->http_result_code=400;
+    ses->pending_outbound_msg->http_result_code=400;
   }
   if (0==strcmp (tmp,"HTTP/1.1 404 Not Found"))
   {
-    res->http_result_code=404;
+    ses->pending_outbound_msg->http_result_code=404;
   }
-  if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large"))
+  if (0==strcmp (tmp,"HTTP/1.1 413 Request Entity Too Large"))
   {
-    res->http_result_code=413;
+    ses->pending_outbound_msg->http_result_code=413;
   }
-   */
   GNUNET_free (tmp);
   return size * nmemb;
 }
@@ -849,18 +851,33 @@
   struct Session * ses = ptr;
   struct HTTP_Message * msg = ses->pending_outbound_msg;
   unsigned int bytes_sent;
-
+  unsigned int len;
   bytes_sent = 0;
-  if (msg->len > (size * nmemb))
-    return CURL_READFUNC_ABORT;
 
-  if (( msg->pos < msg->len) && (msg->len < (size * nmemb)))
+  /* data to send */
+  if (( msg->pos < msg->len))
   {
-    memcpy(stream, msg->buf, msg->len);
-    msg->pos = msg->len;
-    bytes_sent = msg->len;
+    /* data fit in buffer */
+    if ((msg->len - msg->pos) <= (size * nmemb))
+    {
+      len = (msg->len - msg->pos);
+      memcpy(stream, &msg->buf[msg->pos], len);
+      msg->pos += len;
+      bytes_sent = len;
+    }
+    else
+    {
+      len = size*nmemb;
+      memcpy(stream, &msg->buf[msg->pos], len);
+      msg->pos += len;
+      bytes_sent = len;
+    }
   }
-
+  /* no data to send */
+  else
+  {
+    bytes_sent = 0;
+  }
   return bytes_sent;
 }
 
@@ -880,7 +897,7 @@
   memcpy( data, stream, size*nmemb);
   data[size*nmemb] = '\0';
   /* Just a dummy print for the response recieved for the PUT message */
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * 
nmemb, data);
+  /* GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Recieved %u bytes: `%s' \n", size * 
nmemb, data); */
   free (data);
   return (size * nmemb);
 
@@ -921,6 +938,7 @@
   curl_easy_setopt(ses->curl_handle, CURLOPT_URL, msg->dest_url);
   curl_easy_setopt(ses->curl_handle, CURLOPT_PUT, 1L);
   curl_easy_setopt(ses->curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
+  curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEHEADER, ses);
   curl_easy_setopt(ses->curl_handle, CURLOPT_READFUNCTION, send_read_callback);
   curl_easy_setopt(ses->curl_handle, CURLOPT_READDATA, ses);
   curl_easy_setopt(ses->curl_handle, CURLOPT_WRITEFUNCTION, 
send_write_callback);
@@ -928,6 +946,7 @@
   curl_easy_setopt(ses->curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) 
msg->len);
   curl_easy_setopt(ses->curl_handle, CURLOPT_TIMEOUT, (long) (timeout.value / 
1000 ));
   curl_easy_setopt(ses->curl_handle, CURLOPT_CONNECTTIMEOUT, 
HTTP_CONNECT_TIMEOUT);
+  curl_easy_setopt(ses->curl_handle, CURLOPT_BUFFERSIZE, 
GNUNET_SERVER_MAX_MESSAGE_SIZE);
 
   mret = curl_multi_add_handle(multi_handle, ses->curl_handle);
   if (mret != CURLM_OK)
@@ -994,16 +1013,26 @@
                     }
                   else
                   {
+
                     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                                "Send to peer `%s' completed.\n", 
GNUNET_i2s(&cs->sender));
+                                "Send to peer `%s' completed with code %u\n", 
GNUNET_i2s(&cs->sender),cs->pending_outbound_msg->http_result_code);
 
                     curl_easy_cleanup(cs->curl_handle);
                     cs->curl_handle=NULL;
 
                     /* Calling transmit continuation  */
                     if (( NULL != cs->pending_outbound_msg) && (NULL != 
cs->pending_outbound_msg->transmit_cont))
-                      cs->pending_outbound_msg->transmit_cont 
(cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK);
-
+                    {
+                      /* HTTP 1xx : Last message before here was informational 
*/
+                      if ((cs->pending_outbound_msg->http_result_code >=100) 
&& (cs->pending_outbound_msg->http_result_code < 200))
+                        cs->pending_outbound_msg->transmit_cont 
(cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK);
+                      /* HTTP 2xx: successful operations */
+                      if ((cs->pending_outbound_msg->http_result_code >=200) 
&& (cs->pending_outbound_msg->http_result_code < 300))
+                        cs->pending_outbound_msg->transmit_cont 
(cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_OK);
+                      /* HTTP 3xx..5xx: error */
+                      if ((cs->pending_outbound_msg->http_result_code >=300) 
&& (cs->pending_outbound_msg->http_result_code < 600))
+                        cs->pending_outbound_msg->transmit_cont 
(cs->pending_outbound_msg->transmit_cont_cls,&cs->sender,GNUNET_SYSERR);
+                    }
                     if (GNUNET_OK != remove_http_message(cs, 
cs->pending_outbound_msg))
                       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message could not 
be removed from session `%s'", GNUNET_i2s(&cs->sender));
 

Modified: gnunet/src/transport/test_plugin_transport_http.c
===================================================================
--- gnunet/src/transport/test_plugin_transport_http.c   2010-06-16 13:10:19 UTC 
(rev 11768)
+++ gnunet/src/transport/test_plugin_transport_http.c   2010-06-16 15:56:24 UTC 
(rev 11769)
@@ -42,7 +42,7 @@
 #include "transport.h"
 #include <curl/curl.h>
 
-#define VERBOSE GNUNET_NO
+#define VERBOSE GNUNET_YES
 #define DEBUG GNUNET_NO
 #define DEBUG_CURL GNUNET_NO
 #define HTTP_BUFFER_SIZE 2048
@@ -305,6 +305,16 @@
 static int fail_msgs_transmited_to_local_addrs;
 
 /**
+ * Test: transmit msg of max. size
+ */
+static int fail_msg_transmited_bigger_max_size;
+
+/**
+ * Test: transmit msg of max. size
+ */
+static int fail_msg_transmited_max_size;
+
+/**
  * Test: connect to peer without peer identification
  */
 static struct HTTP_Transfer test_no_ident;
@@ -362,12 +372,12 @@
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test plugin functions failed\n");
     fail = 1;
   }
-  if ((test_no_ident.test_failed == GNUNET_YES) || 
(test_too_short_ident.test_failed == GNUNET_YES) || 
(test_too_long_ident.test_failed == GNUNET_YES))
+  if ((test_no_ident.test_failed == GNUNET_YES) || 
(test_too_short_ident.test_failed == GNUNET_YES) || 
(test_too_long_ident.test_failed == GNUNET_YES) || 
(test_valid_ident.test_failed == GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test connect with wrong data 
failed\n");
     fail = 1;
   }
-  if ((test_valid_ident.test_failed == GNUNET_YES) || 
(fail_msgs_transmited_to_local_addrs != count_str_addr))
+  if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || 
(fail_msg_transmited_max_size == GNUNET_YES) || 
(fail_msg_transmited_bigger_max_size == GNUNET_YES))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test sending with plugin failed\n");
     fail = 1;
@@ -437,23 +447,29 @@
   struct Plugin_Address * tmp_addr;
   tmp_addr = addr_head;
 
-  while (tmp_addr != NULL)
+  if ((cls == &fail_msgs_transmited_to_local_addrs) && (result == GNUNET_OK))
   {
-    if (cls == tmp_addr)
-     if (result == GNUNET_OK) fail_msgs_transmited_to_local_addrs++;
-    tmp_addr = tmp_addr->next;
+    fail_msgs_transmited_to_local_addrs++;
+    if (fail_msgs_transmited_to_local_addrs == count_str_addr)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message sent to %u 
addresses!\n",fail_msgs_transmited_to_local_addrs);
+    }
+    return;
   }
 
-  if (fail_msgs_transmited_to_local_addrs == count_str_addr)
+  if ((cls == &fail_msg_transmited_bigger_max_size) && (result == 
GNUNET_SYSERR))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not 
sent!\n");
+    fail_msg_transmited_bigger_max_size = GNUNET_NO;
+    return;
+  }
 
+  if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message sent to %u 
addresses!\n",fail_msgs_transmited_to_local_addrs);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size 
succesfully sent!\n",fail_msgs_transmited_to_local_addrs);
+    fail_msg_transmited_max_size = GNUNET_NO;
     shutdown_clean();
   }
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message was sent!\n");
-  fail = GNUNET_NO;
-  //shutdown_clean();
 }
 
 #if 0
@@ -874,7 +890,6 @@
 static void run_connection_tests( )
 {
   char * host_str = NULL;
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO,"Addr: %s\n",test_addr);
   /* resetting buffers */
   buffer_in.size = HTTP_BUFFER_SIZE;
   buffer_in.pos = 0;
@@ -944,15 +959,13 @@
   char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
   char address[INET6_ADDRSTRLEN];
   unsigned int port;
+  unsigned int type = 10;
 
   msg.size=htons(sizeof(struct GNUNET_MessageHeader));
-  msg.type=htons(13);
-  memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
-
   tmp_addr = addr_head;
   /* send a message to all addresses advertised by plugin */
+
   int count = 0;
-
   while (tmp_addr != NULL)
   {
     if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
@@ -972,11 +985,31 @@
         GNUNET_break (0);
         return;
       }
-    api->send(api->cls, &my_identity, tmp, sizeof(struct 
GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, 
GNUNET_YES, &task_send_cont, tmp_addr);
+    msg.type=htons(type);
+    memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
+    api->send(api->cls, &my_identity, tmp, sizeof(struct 
GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, 
GNUNET_YES, &task_send_cont, &fail_msgs_transmited_to_local_addrs);
     tmp_addr = tmp_addr->next;
     count ++;
+    type ++;
   }
 
+  /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE )*/
+  GNUNET_free(tmp);
+  tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE);
+  uint16_t t2 = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE;
+  msg.size = htons(t2);
+  memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
+  api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE, 0, 
TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, 
&fail_msg_transmited_bigger_max_size);
+
+
+  /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1  */
+  GNUNET_free(tmp);
+  tmp = GNUNET_malloc(GNUNET_SERVER_MAX_MESSAGE_SIZE-1);
+  uint16_t t = (uint16_t)GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
+  msg.size = htons(t);
+  memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
+  api->send(api->cls, &my_identity, tmp, GNUNET_SERVER_MAX_MESSAGE_SIZE-1, 0, 
TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_YES, &task_send_cont, 
&fail_msg_transmited_max_size);
+  GNUNET_free(tmp);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n");
 }
 
@@ -1009,6 +1042,7 @@
   fail_notify_address = GNUNET_YES;
   fail_addr_to_str = GNUNET_YES;
   fail_msgs_transmited_to_local_addrs = 0;
+  fail_msg_transmited_max_size = GNUNET_YES;
 
   addr_head = NULL;
   count_str_addr = 0;




reply via email to

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