gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r23745 - in gnunet/src: include stream


From: gnunet
Subject: [GNUnet-SVN] r23745 - in gnunet/src: include stream
Date: Tue, 11 Sep 2012 11:37:27 +0200

Author: harsha
Date: 2012-09-11 11:37:27 +0200 (Tue, 11 Sep 2012)
New Revision: 23745

Modified:
   gnunet/src/include/gnunet_stream_lib.h
   gnunet/src/stream/stream_api.c
   gnunet/src/stream/test_stream_big.c
   gnunet/src/stream/test_stream_sequence_wraparound.c
Log:
stream option to set packet size

Modified: gnunet/src/include/gnunet_stream_lib.h
===================================================================
--- gnunet/src/include/gnunet_stream_lib.h      2012-09-10 22:17:19 UTC (rev 
23744)
+++ gnunet/src/include/gnunet_stream_lib.h      2012-09-11 09:37:27 UTC (rev 
23745)
@@ -129,7 +129,14 @@
      * GNUNET_STREAM_ListenSuccessCallback. The callback is only called if
      * listen is successful
      */
-    GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS
+    GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
+
+    /**
+     * Option to set the maximum packet size in bytes of a stream data
+     * packets. Takes an uint16_t as argument. Note that this should be less
+     * than 64000 bytes and greater than 64 bytes. Default is 64000 bytes.
+     */
+    GNUNET_STREAM_OPTION_MAX_PACKET_SIZE
   };
 
 

Modified: gnunet/src/stream/stream_api.c
===================================================================
--- gnunet/src/stream/stream_api.c      2012-09-10 22:17:19 UTC (rev 23744)
+++ gnunet/src/stream/stream_api.c      2012-09-11 09:37:27 UTC (rev 23745)
@@ -63,7 +63,7 @@
 /**
  * The maximum packet size of a stream packet
  */
-#define MAX_PACKET_SIZE 512//64000
+#define MAX_PACKET_SIZE 64000
 
 /**
  * Receive buffer
@@ -71,12 +71,6 @@
 #define RECEIVE_BUFFER_SIZE 4096000
 
 /**
- * The maximum payload a data message packet can carry
- */
-static const size_t max_payload_size = 
-  MAX_PACKET_SIZE - sizeof (struct GNUNET_STREAM_DataMessage);
-
-/**
  * states in the Protocol
  */
 enum State
@@ -367,6 +361,16 @@
    * The offset upto which user has read from the received buffer
    */
   uint32_t copy_offset;
+
+  /**
+   * The maximum packet size this stream handle will give to mesh
+   */
+  uint16_t max_packet_size;
+
+  /**
+   * The maximum size of the data message payload this stream handle can send
+   */
+  uint16_t max_payload_size;
 };
 
 
@@ -439,6 +443,12 @@
    * The write sequence number to be set incase of testing
    */
   uint32_t testing_set_write_sequence_number_value;
+
+  /**
+   * The maximum packet size this stream handle will give to mesh
+   */
+  uint16_t max_packet_size;
+
 };
 
 
@@ -2765,12 +2775,6 @@
 
   if (GNUNET_NO == lsocket->listening)
   {
-//     FIXME: socket uninitalized
-//     FIXME: cannot use GNUNET_i2s twice in same call (static buffer)
-//     LOG (GNUNET_ERROR_TYPE_DEBUG,
-//          "%s: Destroying tunnel from peer %s as we don't have the lock\n",
-//          GNUNET_i2s (&socket->other_peer),
-//          GNUNET_i2s (&socket->other_peer));
     GNUNET_MESH_tunnel_destroy (tunnel);
     return NULL;
   }
@@ -2783,7 +2787,10 @@
   socket->retransmit_timeout = lsocket->retransmit_timeout;
   socket->testing_active = lsocket->testing_active;
   socket->testing_set_write_sequence_number_value =
-    lsocket->testing_set_write_sequence_number_value;    
+      lsocket->testing_set_write_sequence_number_value;
+  socket->max_packet_size = lsocket->max_packet_size;
+  socket->max_payload_size =
+      socket->max_packet_size - sizeof (struct GNUNET_STREAM_DataMessage);
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "%s: Peer %s initiated tunnel to us\n", 
        GNUNET_i2s (&socket->other_peer),
@@ -2955,6 +2962,7 @@
   /* Set defaults */
   socket->retransmit_timeout = TIME_REL_SECS (default_timeout);
   socket->testing_active = GNUNET_NO;
+  socket->max_packet_size = MAX_PACKET_SIZE; 
   va_start (vargs, open_cb_cls); /* Parse variable args */
   do {
     option = va_arg (vargs, enum GNUNET_STREAM_Option);
@@ -2976,11 +2984,18 @@
     case GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS:
       GNUNET_break (0);          /* Option irrelevant in STREAM_open */
       break;
+    case GNUNET_STREAM_OPTION_MAX_PACKET_SIZE:
+      socket->max_packet_size = (uint16_t) va_arg (vargs, unsigned int);
+      if (socket->max_packet_size > MAX_PACKET_SIZE)
+       socket->max_packet_size = MAX_PACKET_SIZE;
+      break;
     case GNUNET_STREAM_OPTION_END:
       break;
     }
   } while (GNUNET_STREAM_OPTION_END != option);
   va_end (vargs);               /* End of variable args parsing */
+  socket->max_payload_size = 
+      socket->max_packet_size - sizeof (struct GNUNET_STREAM_DataMessage);
   socket->mesh = GNUNET_MESH_connect (cfg, /* the configuration handle */
                                       socket, /* cls */
                                       NULL, /* No inbound tunnel handler */
@@ -3220,6 +3235,7 @@
   lsocket->retransmit_timeout = TIME_REL_SECS (default_timeout);
   lsocket->testing_active = GNUNET_NO;
   lsocket->listen_ok_cb = NULL;
+  lsocket->max_packet_size = MAX_PACKET_SIZE;
   listen_timeout = TIME_REL_SECS (60); /* A minute for listen timeout */  
   va_start (vargs, listen_cb_cls);
   do {
@@ -3243,6 +3259,11 @@
       lsocket->listen_ok_cb = va_arg (vargs,
                                       GNUNET_STREAM_ListenSuccessCallback);
       break;
+    case GNUNET_STREAM_OPTION_MAX_PACKET_SIZE:
+      lsocket->max_packet_size = (uint16_t) va_arg (vargs, unsigned int);
+      if (lsocket->max_packet_size > MAX_PACKET_SIZE)
+       lsocket->max_packet_size = MAX_PACKET_SIZE;
+      break;
     case GNUNET_STREAM_OPTION_END:
       break;
     }
@@ -3355,9 +3376,10 @@
     break;
   }
 
-  if (GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH * max_payload_size < size)
-    size = GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH  * max_payload_size;
-  num_needed_packets = (size + (max_payload_size - 1)) / max_payload_size;
+  if (GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH * socket->max_payload_size < size)
+    size = GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH  * socket->max_payload_size;
+  num_needed_packets =
+      (size + (socket->max_payload_size - 1)) / socket->max_payload_size;
   io_handle = GNUNET_malloc (sizeof (struct GNUNET_STREAM_IOWriteHandle));
   io_handle->socket = socket;
   io_handle->write_cont = write_cont;
@@ -3370,16 +3392,16 @@
   /* Divide the given buffer into packets for sending */
   for (packet=0; packet < num_needed_packets; packet++)
   {
-    if ((packet + 1) * max_payload_size < size) 
+    if ((packet + 1) * socket->max_payload_size < size) 
     {
-      payload_size = max_payload_size;
-      packet_size = MAX_PACKET_SIZE;
+      payload_size = socket->max_payload_size;
+      packet_size = socket->max_packet_size;
     }
     else 
     {
-      payload_size = size - packet * max_payload_size;
-      packet_size =  payload_size + sizeof (struct
-                                            GNUNET_STREAM_DataMessage); 
+      payload_size = size - packet * socket->max_payload_size;
+      packet_size = 
+         payload_size + sizeof (struct GNUNET_STREAM_DataMessage);
     }
     io_handle->messages[packet] = GNUNET_malloc (packet_size);
     io_handle->messages[packet]->header.header.size = htons (packet_size);

Modified: gnunet/src/stream/test_stream_big.c
===================================================================
--- gnunet/src/stream/test_stream_big.c 2012-09-10 22:17:19 UTC (rev 23744)
+++ gnunet/src/stream/test_stream_big.c 2012-09-11 09:37:27 UTC (rev 23745)
@@ -144,7 +144,7 @@
 
   peer = (struct PeerData *) cls;
   GNUNET_assert (GNUNET_STREAM_OK == status);
-  GNUNET_assert (size < DATA_SIZE);
+  GNUNET_assert (size <= DATA_SIZE);
   peer->bytes_wrote += size;
 
   if (peer->bytes_wrote < DATA_SIZE) /* Have more data to send */
@@ -152,7 +152,7 @@
       peer->io_write_handle =
         GNUNET_STREAM_write (peer->socket,
                              ((void *) data) + peer->bytes_wrote,
-                             DATA_SIZE - peer->bytes_wrote,
+                            sizeof (data) - peer->bytes_wrote,
                              GNUNET_TIME_relative_multiply
                              (GNUNET_TIME_UNIT_SECONDS, 5),
                              &write_completion,
@@ -190,7 +190,7 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Generation of random data complete\n");
   peer->io_write_handle = GNUNET_STREAM_write (peer->socket,
                                                data,
-                                               DATA_SIZE,
+                                               sizeof (data),
                                                GNUNET_TIME_relative_multiply
                                                (GNUNET_TIME_UNIT_SECONDS, 10),
                                                &write_completion,

Modified: gnunet/src/stream/test_stream_sequence_wraparound.c
===================================================================
--- gnunet/src/stream/test_stream_sequence_wraparound.c 2012-09-10 22:17:19 UTC 
(rev 23744)
+++ gnunet/src/stream/test_stream_sequence_wraparound.c 2012-09-11 09:37:27 UTC 
(rev 23745)
@@ -142,7 +142,7 @@
 
   peer = (struct PeerData *) cls;
   GNUNET_assert (GNUNET_STREAM_OK == status);
-  GNUNET_assert (size < DATA_SIZE);
+  GNUNET_assert (size <= DATA_SIZE);
   peer->bytes_wrote += size;
 
   if (peer->bytes_wrote < DATA_SIZE) /* Have more data to send */




reply via email to

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