diff options
author | Bart Polot <bart@net.in.tum.de> | 2016-10-27 06:18:17 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2016-10-27 06:18:17 +0000 |
commit | 6a0ded9c43e7e8407e8944f3e62a9d3d08726062 (patch) | |
tree | a17e9de6151e135c2c1c0b58e01a18b063fb99c1 | |
parent | 13776e033db3631575c7be41c4b457b90e166fbe (diff) | |
download | gnunet-6a0ded9c43e7e8407e8944f3e62a9d3d08726062.tar.gz gnunet-6a0ded9c43e7e8407e8944f3e62a9d3d08726062.zip |
Build messages fully in tunnel code, avoid copying in connection layer
-rw-r--r-- | src/cadet/gnunet-service-cadet_connection.c | 33 | ||||
-rw-r--r-- | 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, | |||
3268 | size = ntohs (message->size); | 3268 | size = ntohs (message->size); |
3269 | type = ntohs (message->type); | 3269 | type = ntohs (message->type); |
3270 | 3270 | ||
3271 | /* Allocate a copy of the message on the stack, so we can modify it as needed, | ||
3272 | * adding the Connection ID, PID, and other data the Tunnel layer doesn't | ||
3273 | * have access to. | ||
3274 | */ | ||
3275 | char cbuf[size]; | ||
3276 | struct GNUNET_MessageHeader *copy = (struct GNUNET_MessageHeader *)cbuf; | ||
3277 | |||
3278 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type | ||
3279 | || GNUNET_MESSAGE_TYPE_CADET_KX == type) | ||
3280 | { | ||
3281 | GNUNET_memcpy (copy, message, size); | ||
3282 | if (GNUNET_MESSAGE_TYPE_CADET_AX == type) | ||
3283 | { | ||
3284 | struct GNUNET_CADET_AX *axmsg; | ||
3285 | |||
3286 | axmsg = (struct GNUNET_CADET_AX *) copy; | ||
3287 | axmsg->cid = c->id; | ||
3288 | axmsg->pid = htonl (GCC_get_pid (c, fwd)); | ||
3289 | } | ||
3290 | else /* case GNUNET_MESSAGE_TYPE_CADET_KX */ | ||
3291 | { | ||
3292 | struct GNUNET_CADET_KX *kmsg; | ||
3293 | |||
3294 | GNUNET_assert (GNUNET_MESSAGE_TYPE_CADET_KX == type); | ||
3295 | kmsg = (struct GNUNET_CADET_KX *) copy; | ||
3296 | kmsg->reserved = htonl (0); | ||
3297 | kmsg->cid = c->id; | ||
3298 | } | ||
3299 | message = copy; | ||
3300 | } | ||
3301 | |||
3302 | GCC_check_connections (); | 3271 | GCC_check_connections (); |
3303 | fc = fwd ? &c->fwd_fc : &c->bck_fc; | 3272 | fc = fwd ? &c->fwd_fc : &c->bck_fc; |
3304 | if (0 == fc->queue_max) | 3273 | if (0 == fc->queue_max) |
@@ -3307,8 +3276,6 @@ GCC_send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
3307 | return NULL; | 3276 | return NULL; |
3308 | } | 3277 | } |
3309 | 3278 | ||
3310 | size = ntohs (message->size); | ||
3311 | type = ntohs (message->type); | ||
3312 | LOG (GNUNET_ERROR_TYPE_INFO, | 3279 | LOG (GNUNET_ERROR_TYPE_INFO, |
3313 | "--> %s (%s %4u) on conn %s (%p) %s [%5u]\n", | 3280 | "--> %s (%s %4u) on conn %s (%p) %s [%5u]\n", |
3314 | GC_m2s (type), GC_m2s (payload_type), payload_id, GCC_2s (c), c, | 3281 | 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, | |||
1406 | } | 1406 | } |
1407 | return NULL; /* Drop... */ | 1407 | return NULL; /* Drop... */ |
1408 | } | 1408 | } |
1409 | fwd = GCC_is_origin (c, GNUNET_YES); | ||
1410 | ax_msg->cid = *GCC_get_id (c); | ||
1411 | ax_msg->pid = htonl (GCC_get_pid (c, fwd)); | ||
1409 | 1412 | ||
1410 | mid = 0; | 1413 | mid = 0; |
1411 | type = ntohs (message->type); | 1414 | type = ntohs (message->type); |
@@ -1430,8 +1433,6 @@ send_prebuilt_message (const struct GNUNET_MessageHeader *message, | |||
1430 | } | 1433 | } |
1431 | LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type)); | 1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, "type %s\n", GC_m2s (type)); |
1432 | 1435 | ||
1433 | fwd = GCC_is_origin (c, GNUNET_YES); | ||
1434 | |||
1435 | if (NULL == cont) | 1436 | if (NULL == cont) |
1436 | { | 1437 | { |
1437 | GNUNET_break (NULL == GCC_send_prebuilt_message (msg, type, mid, c, fwd, | 1438 | GNUNET_break (NULL == GCC_send_prebuilt_message (msg, type, mid, c, fwd, |
@@ -1612,6 +1613,7 @@ send_kx (struct CadetTunnel *t, | |||
1612 | msg = (struct GNUNET_CADET_KX *) cbuf; | 1613 | msg = (struct GNUNET_CADET_KX *) cbuf; |
1613 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); | 1614 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX); |
1614 | msg->header.size = htons (sizeof (struct GNUNET_CADET_KX) + size); | 1615 | msg->header.size = htons (sizeof (struct GNUNET_CADET_KX) + size); |
1616 | msg->reserved = htonl (0); | ||
1615 | c = tunnel_get_connection (t); | 1617 | c = tunnel_get_connection (t); |
1616 | if (NULL == c) | 1618 | if (NULL == c) |
1617 | { | 1619 | { |
@@ -1622,6 +1624,7 @@ send_kx (struct CadetTunnel *t, | |||
1622 | } | 1624 | } |
1623 | return NULL; | 1625 | return NULL; |
1624 | } | 1626 | } |
1627 | msg->cid = *GCC_get_id (c); | ||
1625 | switch (type) | 1628 | switch (type) |
1626 | { | 1629 | { |
1627 | case GNUNET_MESSAGE_TYPE_CADET_AX_KX: | 1630 | case GNUNET_MESSAGE_TYPE_CADET_AX_KX: |