aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2016-10-26 04:20:51 +0000
committerBart Polot <bart@net.in.tum.de>2016-10-26 04:20:51 +0000
commit97ea58bc413551af02172f1f13fc3fcb71198c64 (patch)
tree84da61a71c3c30311c61672d87d256fab17482bd
parent7a5b94705d47b9dccc3b35dfb7d08dc646fe5a33 (diff)
downloadgnunet-97ea58bc413551af02172f1f13fc3fcb71198c64.tar.gz
gnunet-97ea58bc413551af02172f1f13fc3fcb71198c64.zip
Make a copy of the message on connection level only if it needs to be modified (generated by the Tunnel)
-rw-r--r--src/cadet/gnunet-service-cadet_connection.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/cadet/gnunet-service-cadet_connection.c b/src/cadet/gnunet-service-cadet_connection.c
index 47d841f04..e04dcf620 100644
--- a/src/cadet/gnunet-service-cadet_connection.c
+++ b/src/cadet/gnunet-service-cadet_connection.c
@@ -3238,10 +3238,10 @@ GCC_is_direct (struct CadetConnection *c)
3238/** 3238/**
3239 * Internal implementation of the send function. 3239 * Internal implementation of the send function.
3240 * 3240 *
3241 * Sends an already built message on a connection, properly registering 3241 * Sends an completely built message on a connection, properly registering
3242 * all used resources. 3242 * all used resources.
3243 * 3243 *
3244 * @param message Modificable copy of the message to send. 3244 * @param message Message to send.
3245 * @param payload_type Type of payload, in case the message is encrypted. 3245 * @param payload_type Type of payload, in case the message is encrypted.
3246 * @param payload_id ID of the payload (PID, ACK, ...). 3246 * @param payload_id ID of the payload (PID, ACK, ...).
3247 * @param c Connection on which this message is transmitted. 3247 * @param c Connection on which this message is transmitted.
@@ -3255,16 +3255,14 @@ GCC_is_direct (struct CadetConnection *c)
3255 * Invalid on @c cont call. 3255 * Invalid on @c cont call.
3256 */ 3256 */
3257static struct CadetConnectionQueue * 3257static struct CadetConnectionQueue *
3258send_prebuilt_message (struct GNUNET_MessageHeader *message, 3258send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3259 uint16_t payload_type, uint32_t payload_id, 3259 uint16_t payload_type, uint32_t payload_id,
3260 struct CadetConnection *c, int fwd, int force, 3260 struct CadetConnection *c, int fwd, int force,
3261 GCC_sent cont, void *cont_cls) 3261 GCC_sent cont, void *cont_cls)
3262{ 3262{
3263 struct GNUNET_CADET_AX *axmsg;
3264 struct GNUNET_CADET_KX *kmsg;
3265 struct CadetFlowControl *fc; 3263 struct CadetFlowControl *fc;
3266 struct CadetConnectionQueue *q; 3264 struct CadetConnectionQueue *q;
3267 size_t size; 3265 uint16_t size;
3268 uint16_t type; 3266 uint16_t type;
3269 3267
3270 GCC_check_connections (); 3268 GCC_check_connections ();
@@ -3284,9 +3282,6 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message,
3284 switch (type) 3282 switch (type)
3285 { 3283 {
3286 case GNUNET_MESSAGE_TYPE_CADET_AX: 3284 case GNUNET_MESSAGE_TYPE_CADET_AX:
3287 axmsg = (struct GNUNET_CADET_AX *) message;
3288 axmsg->cid = c->id;
3289 axmsg->pid = htonl (GCC_get_pid (c, fwd));
3290 LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n); 3285 LOG (GNUNET_ERROR_TYPE_DEBUG, " Q_N+ %p %u\n", fc, fc->queue_n);
3291 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent); 3286 LOG (GNUNET_ERROR_TYPE_DEBUG, "last pid sent %u\n", fc->last_pid_sent);
3292 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv); 3287 LOG (GNUNET_ERROR_TYPE_DEBUG, " ack recv %u\n", fc->last_ack_recv);
@@ -3294,16 +3289,9 @@ send_prebuilt_message (struct GNUNET_MessageHeader *message,
3294 { 3289 {
3295 fc->queue_n++; 3290 fc->queue_n++;
3296 } 3291 }
3297 else
3298 {
3299 LOG (GNUNET_ERROR_TYPE_DEBUG, " forced msg, Q_N stays the same\n");
3300 }
3301 break; 3292 break;
3302 3293
3303 case GNUNET_MESSAGE_TYPE_CADET_KX: 3294 case GNUNET_MESSAGE_TYPE_CADET_KX:
3304 kmsg = (struct GNUNET_CADET_KX *) message;
3305 kmsg->reserved = htonl (0);
3306 kmsg->cid = c->id;
3307 break; 3295 break;
3308 3296
3309 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE: 3297 case GNUNET_MESSAGE_TYPE_CADET_CONNECTION_CREATE:
@@ -3386,22 +3374,47 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
3386 GCC_sent cont, void *cont_cls) 3374 GCC_sent cont, void *cont_cls)
3387{ 3375{
3388 uint16_t size; 3376 uint16_t size;
3377 uint16_t type;
3378
3379 size = ntohs (message->size);
3380 type = ntohs (message->type);
3389 3381
3390 /* Allocate a copy of the message on the stack, so we can modify it as needed, 3382 /* Allocate a copy of the message on the stack, so we can modify it as needed,
3391 * adding the Connection ID, PID, and other data the Tunnel layer doesn't 3383 * adding the Connection ID, PID, and other data the Tunnel layer doesn't
3392 * have access to. 3384 * have access to.
3393 */ 3385 */
3394 size = ntohs (message->size); 3386 if (GNUNET_MESSAGE_TYPE_CADET_AX == type
3387 || GNUNET_MESSAGE_TYPE_CADET_KX == type)
3395 { 3388 {
3396 struct GNUNET_MessageHeader *copy; 3389 struct GNUNET_MessageHeader *copy;
3397 unsigned char cbuf[size]; 3390 unsigned char cbuf[size];
3398 3391
3399 copy = (struct GNUNET_MessageHeader *)cbuf; 3392 copy = (struct GNUNET_MessageHeader *)cbuf;
3400 GNUNET_memcpy (copy, message, size); 3393 GNUNET_memcpy (copy, message, size);
3394 if (GNUNET_MESSAGE_TYPE_CADET_AX == type)
3395 {
3396 struct GNUNET_CADET_AX *axmsg;
3397
3398 axmsg = (struct GNUNET_CADET_AX *) message;
3399 axmsg->cid = c->id;
3400 axmsg->pid = htonl (GCC_get_pid (c, fwd));
3401 }
3402 else /* case GNUNET_MESSAGE_TYPE_CADET_KX */
3403 {
3404 struct GNUNET_CADET_KX *kmsg;
3405
3406 kmsg = (struct GNUNET_CADET_KX *) message;
3407 kmsg->reserved = htonl (0);
3408 kmsg->cid = c->id;
3409 }
3401 return send_prebuilt_message (copy, payload_type, payload_id, 3410 return send_prebuilt_message (copy, payload_type, payload_id,
3402 c, fwd, force, 3411 c, fwd, force,
3403 cont, cont_cls); 3412 cont, cont_cls);
3404 } 3413 }
3414 return send_prebuilt_message (message, payload_type, payload_id,
3415 c, fwd, force,
3416 cont, cont_cls);
3417
3405} 3418}
3406 3419
3407 3420