aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-01-09 18:04:26 +0000
committerBart Polot <bart@net.in.tum.de>2015-01-09 18:04:26 +0000
commitfa92f3290023c93a5503730558b13d60d5ebd2f8 (patch)
tree1b45af5fecd34a48b3d1180a729b18959af65847 /src/cadet
parenta9a9d47e481109341d4f366a3e9a70de34799c84 (diff)
downloadgnunet-fa92f3290023c93a5503730558b13d60d5ebd2f8.tar.gz
gnunet-fa92f3290023c93a5503730558b13d60d5ebd2f8.zip
- fix size handling of payload data
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_api.c17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/cadet/cadet_api.c b/src/cadet/cadet_api.c
index f0d01d8aa..f3d82c7ab 100644
--- a/src/cadet/cadet_api.c
+++ b/src/cadet/cadet_api.c
@@ -28,6 +28,7 @@
28#include "cadet_protocol.h" 28#include "cadet_protocol.h"
29 29
30#define LOG(kind,...) GNUNET_log_from (kind, "cadet-api",__VA_ARGS__) 30#define LOG(kind,...) GNUNET_log_from (kind, "cadet-api",__VA_ARGS__)
31#define DATA_OVERHEAD sizeof(struct GNUNET_CADET_LocalData)
31 32
32/******************************************************************************/ 33/******************************************************************************/
33/************************ DATA STRUCTURES ****************************/ 34/************************ DATA STRUCTURES ****************************/
@@ -360,7 +361,7 @@ th_is_payload (struct GNUNET_CADET_TransmitHandle *th)
360 * 361 *
361 * @param h Cadet handle. 362 * @param h Cadet handle.
362 * 363 *
363 * @return The size of the first ready message in the queue, 364 * @return The size of the first ready message in the queue, including overhead.
364 * 0 if there is none. 365 * 0 if there is none.
365 */ 366 */
366static size_t 367static size_t
@@ -380,7 +381,7 @@ message_ready_size (struct GNUNET_CADET_Handle *h)
380 if (GNUNET_YES == ch->allow_send) 381 if (GNUNET_YES == ch->allow_send)
381 { 382 {
382 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n"); 383 LOG (GNUNET_ERROR_TYPE_DEBUG, "# message payload ok\n");
383 return th->size; 384 return th->size + DATA_OVERHEAD;
384 } 385 }
385 } 386 }
386 return 0; 387 return 0;
@@ -1341,7 +1342,7 @@ send_callback (void *cls, size_t size, void *buf)
1341 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n"); 1342 LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload\n");
1342 if (GNUNET_NO == ch->allow_send) 1343 if (GNUNET_NO == ch->allow_send)
1343 { 1344 {
1344 /* This channel is not ready to transmit yet, try next message */ 1345 /* This channel is not ready to transmit yet, Try the next message */
1345 next = th->next; 1346 next = th->next;
1346 continue; 1347 continue;
1347 } 1348 }
@@ -1349,15 +1350,13 @@ send_callback (void *cls, size_t size, void *buf)
1349 GNUNET_assert (size >= th->size); 1350 GNUNET_assert (size >= th->size);
1350 dmsg = (struct GNUNET_CADET_LocalData *) cbuf; 1351 dmsg = (struct GNUNET_CADET_LocalData *) cbuf;
1351 mh = (struct GNUNET_MessageHeader *) &dmsg[1]; 1352 mh = (struct GNUNET_MessageHeader *) &dmsg[1];
1352 psize = th->notify (th->notify_cls, 1353 psize = th->notify (th->notify_cls, size - DATA_OVERHEAD, mh);
1353 size - sizeof (struct GNUNET_CADET_LocalData),
1354 mh);
1355 1354
1356 if (psize > 0) 1355 if (psize > 0)
1357 { 1356 {
1358 psize += sizeof (struct GNUNET_CADET_LocalData);
1359 GNUNET_assert (size >= psize);
1360 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= psize); 1357 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) <= psize);
1358 psize += DATA_OVERHEAD;
1359 GNUNET_assert (size >= psize);
1361 dmsg->header.size = htons (psize); 1360 dmsg->header.size = htons (psize);
1362 dmsg->id = htonl (ch->chid); 1361 dmsg->id = htonl (ch->chid);
1363 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA); 1362 dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_CADET_LOCAL_DATA);
@@ -1385,9 +1384,9 @@ send_callback (void *cls, size_t size, void *buf)
1385 GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= psize); 1384 GNUNET_assert (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE >= psize);
1386 if (th->timeout_task != NULL) 1385 if (th->timeout_task != NULL)
1387 GNUNET_SCHEDULER_cancel (th->timeout_task); 1386 GNUNET_SCHEDULER_cancel (th->timeout_task);
1387 next = th->next;
1388 GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th); 1388 GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
1389 GNUNET_free (th); 1389 GNUNET_free (th);
1390 next = h->th_head;
1391 nsize = message_ready_size (h); 1390 nsize = message_ready_size (h);
1392 cbuf += psize; 1391 cbuf += psize;
1393 size -= psize; 1392 size -= psize;