gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r38207 - gnunet/src/cadet


From: gnunet
Subject: [GNUnet-SVN] r38207 - gnunet/src/cadet
Date: Wed, 26 Oct 2016 06:20:51 +0200

Author: bartpolot
Date: 2016-10-26 06:20:51 +0200 (Wed, 26 Oct 2016)
New Revision: 38207

Modified:
   gnunet/src/cadet/gnunet-service-cadet_connection.c
Log:
Make a copy of the message on connection level only if it needs to be modified 
(generated by the Tunnel)

Modified: gnunet/src/cadet/gnunet-service-cadet_connection.c
===================================================================
--- gnunet/src/cadet/gnunet-service-cadet_connection.c  2016-10-26 04:20:49 UTC 
(rev 38206)
+++ gnunet/src/cadet/gnunet-service-cadet_connection.c  2016-10-26 04:20:51 UTC 
(rev 38207)
@@ -3238,10 +3238,10 @@
 /**
  * Internal implementation of the send function.
  *
- * Sends an already built message on a connection, properly registering
+ * Sends an completely built message on a connection, properly registering
  * all used resources.
  *
- * @param message Modificable copy of the message to send.
+ * @param message Message to send.
  * @param payload_type Type of payload, in case the message is encrypted.
  * @param payload_id ID of the payload (PID, ACK, ...).
  * @param c Connection on which this message is transmitted.
@@ -3255,16 +3255,14 @@
  *         Invalid on @c cont call.
  */
 static struct CadetConnectionQueue *
-send_prebuilt_message (struct GNUNET_MessageHeader *message,
+send_prebuilt_message (const struct GNUNET_MessageHeader *message,
                        uint16_t payload_type, uint32_t payload_id,
                        struct CadetConnection *c, int fwd, int force,
                        GCC_sent cont, void *cont_cls)
 {
-  struct GNUNET_CADET_AX        *axmsg;
-  struct GNUNET_CADET_KX        *kmsg;
   struct CadetFlowControl *fc;
   struct CadetConnectionQueue *q;
-  size_t size;
+  uint16_t size;
   uint16_t type;
 
   GCC_check_connections ();
@@ -3284,9 +3282,6 @@
   switch (type)
   {
     case GNUNET_MESSAGE_TYPE_CADET_AX:
-      axmsg = (struct GNUNET_CADET_AX *) message;
-      axmsg->cid = c->id;
-      axmsg->pid = htonl (GCC_get_pid (c, fwd));
       LOG (GNUNET_ERROR_TYPE_DEBUG, "  Q_N+ %p %u\n", fc, fc->queue_n);
       LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent);
       LOG (GNUNET_ERROR_TYPE_DEBUG, "     ack recv %u\n", fc->last_ack_recv);
@@ -3294,16 +3289,9 @@
       {
         fc->queue_n++;
       }
-      else
-      {
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "  forced msg, Q_N stays the same\n");
-      }
       break;
 
     case GNUNET_MESSAGE_TYPE_CADET_KX:
-      kmsg = (struct GNUNET_CADET_KX *) message;
-      kmsg->reserved = htonl (0);
-      kmsg->cid = c->id;
       break;
 
     case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE:
@@ -3386,12 +3374,17 @@
                            GCC_sent cont, void *cont_cls)
 {
   uint16_t size;
+  uint16_t type;
 
+  size = ntohs (message->size);
+  type = ntohs (message->type);
+
   /* Allocate a copy of the message on the stack, so we can modify it as 
needed,
    * adding the Connection ID, PID, and other data the Tunnel layer doesn't
    * have access to.
    */
-  size = ntohs (message->size);
+  if (GNUNET_MESSAGE_TYPE_CADET_AX == type
+      || GNUNET_MESSAGE_TYPE_CADET_KX == type)
   {
     struct GNUNET_MessageHeader *copy;
     unsigned char cbuf[size];
@@ -3398,10 +3391,30 @@
 
     copy = (struct GNUNET_MessageHeader *)cbuf;
     GNUNET_memcpy (copy, message, size);
+    if (GNUNET_MESSAGE_TYPE_CADET_AX == type)
+    {
+      struct GNUNET_CADET_AX        *axmsg;
+
+      axmsg = (struct GNUNET_CADET_AX *) message;
+      axmsg->cid = c->id;
+      axmsg->pid = htonl (GCC_get_pid (c, fwd));
+    }
+    else /* case GNUNET_MESSAGE_TYPE_CADET_KX */
+    {
+      struct GNUNET_CADET_KX        *kmsg;
+
+      kmsg = (struct GNUNET_CADET_KX *) message;
+      kmsg->reserved = htonl (0);
+      kmsg->cid = c->id;
+    }
     return send_prebuilt_message (copy, payload_type, payload_id,
-                                  c, fwd, force,
-                                  cont, cont_cls);
+                                c, fwd, force,
+                                cont, cont_cls);
   }
+  return send_prebuilt_message (message, payload_type, payload_id,
+                                c, fwd, force,
+                                cont, cont_cls);
+
 }
 
 




reply via email to

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