From 6a0ded9c43e7e8407e8944f3e62a9d3d08726062 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 27 Oct 2016 06:18:17 +0000 Subject: [PATCH] Build messages fully in tunnel code, avoid copying in connection layer --- src/cadet/gnunet-service-cadet_connection.c | 33 --------------------- src/cadet/gnunet-service-cadet_tunnel.c | 7 +++-- 2 files changed, 5 insertions(+), 35 deletions(-) diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c index eb13cb637..4a4de2200 100644 --- a/src/cadet/gnunet-service-cadet_connection.c +++ b/src/cadet/gnunet-service-cadet_connection.c @@ -3268,37 +3268,6 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, 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. - */ - char cbuf[size]; - struct GNUNET_MessageHeader *copy = (struct GNUNET_MessageHeader *)cbuf; - - if (GNUNET_MESSAGE_TYPE_CADET_AX == type - || GNUNET_MESSAGE_TYPE_CADET_KX == type) - { - GNUNET_memcpy (copy, message, size); - if (GNUNET_MESSAGE_TYPE_CADET_AX == type) - { - struct GNUNET_CADET_AX *axmsg; - - axmsg = (struct GNUNET_CADET_AX *) copy; - axmsg->cid = c->id; - axmsg->pid = htonl (GCC_get_pid (c, fwd)); - } - else /* case GNUNET_MESSAGE_TYPE_CADET_KX */ - { - struct GNUNET_CADET_KX *kmsg; - - GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_KX == type); - kmsg = (struct GNUNET_CADET_KX *) copy; - kmsg->reserved = htonl (0); - kmsg->cid = c->id; - } - message = copy; - } - GCC_check_connections (); fc = fwd ? &c->fwd_fc : &c->bck_fc; if (0 == fc->queue_max) @@ -3307,8 +3276,6 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, return NULL; } - size = ntohs (message->size); - type = ntohs (message->type); LOG (GNUNET_ERROR_TYPE_INFO, "--> %s (%s %4u) on conn %s (%p) %s [%5u]\n", GC_m2s (type), GC_m2s (payload_type), payload_id, GCC_2s (c), c, diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c index 267070552..26c1ea3d4 100644 --- a/src/cadet/gnunet-service-cadet_tunnel.c +++ b/src/cadet/gnunet-service-cadet_tunnel.c @@ -1406,6 +1406,9 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, } return NULL; /* Drop... */ } + fwd = GCC_is_origin (c, GNUNET_YES); + ax_msg->cid = *GCC_get_id (c); + ax_msg->pid = htonl (GCC_get_pid (c, fwd)); mid = 0; type = ntohs (message->type); @@ -1430,8 +1433,6 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, } LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type)); - fwd = GCC_is_origin (c, GNUNET_YES); - if (NULL == cont) { GNUNET_break (NULL == GCC_send_prebuilt_message (msg, type, mid, c, fwd, @@ -1612,6 +1613,7 @@ send_kx (struct CadetTunnel *t, msg = (struct GNUNET_CADET_KX *) cbuf; msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); msg->header.size = htons (sizeof (struct GNUNET_CADET_KX) + size); + msg->reserved = htonl (0); c = tunnel_get_connection (t); if (NULL == c) { @@ -1622,6 +1624,7 @@ send_kx (struct CadetTunnel *t, } return NULL; } + msg->cid = *GCC_get_id (c); switch (type) { case GNUNET_MESSAGE_TYPE_CADET_AX_KX: -- 2.25.1