aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/mesh_api.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-07-31 12:11:04 +0000
committerBart Polot <bart@net.in.tum.de>2012-07-31 12:11:04 +0000
commitf2a80a0f56db949321884db148ae59e109263588 (patch)
tree1bbbe0a628593375cd412cb1d0522bc0e384d3a9 /src/mesh/mesh_api.c
parente8e09d1eab1492ee4676aadbfb047386c3ccd466 (diff)
downloadgnunet-f2a80a0f56db949321884db148ae59e109263588.tar.gz
gnunet-f2a80a0f56db949321884db148ae59e109263588.zip
- fix client_tmt_rdy call, refactoring
Diffstat (limited to 'src/mesh/mesh_api.c')
-rw-r--r--src/mesh/mesh_api.c83
1 files changed, 46 insertions, 37 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 307364fef..fe600e37c 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -379,6 +379,31 @@ th_is_payload (struct GNUNET_MESH_TransmitHandle *th)
379 379
380 380
381/** 381/**
382 * Check whether there is any message ready in the queue and find the size.
383 *
384 * @param h Mesh handle.
385 *
386 * @return The size of the first ready message in the queue,
387 * 0 if there is none.
388 */
389static size_t
390message_ready_size (struct GNUNET_MESH_Handle *h)
391{
392 struct GNUNET_MESH_TransmitHandle *th;
393 struct GNUNET_MESH_Tunnel *t;
394
395 for (th = h->th_head; NULL != th; th = th->next)
396 {
397 t = th->tunnel;
398 if (GNUNET_NO == th_is_payload (th) ||
399 (t->max_pid > t->pid || PID_OVERFLOW (t->max_pid, t->pid)))
400 return th->size;
401 }
402 return 0;
403}
404
405
406/**
382 * Get the tunnel handler for the tunnel specified by id from the given handle 407 * Get the tunnel handler for the tunnel specified by id from the given handle
383 * @param h Mesh handle 408 * @param h Mesh handle
384 * @param tid ID of the wanted tunnel 409 * @param tid ID of the wanted tunnel
@@ -498,7 +523,7 @@ destroy_tunnel (struct GNUNET_MESH_Tunnel *t, int call_cleaner)
498 523
499 /* if there are no more pending requests with mesh service, cancel active request */ 524 /* if there are no more pending requests with mesh service, cancel active request */
500 /* Note: this should be unnecessary... */ 525 /* Note: this should be unnecessary... */
501 if ( (NULL == h->th_head) && (NULL != h->th)) 526 if ((0 == message_ready_size (h)) && (NULL != h->th))
502 { 527 {
503 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th); 528 GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
504 h->th = NULL; 529 h->th = NULL;
@@ -604,9 +629,9 @@ timeout_transmission (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
604 if (GNUNET_YES == th_is_payload (th)) 629 if (GNUNET_YES == th_is_payload (th))
605 th->notify (th->notify_cls, 0, NULL); 630 th->notify (th->notify_cls, 0, NULL);
606 GNUNET_free (th); 631 GNUNET_free (th);
607 if ((NULL == mesh->th_head) && (NULL != mesh->th)) 632 if ((0 == message_ready_size (mesh)) && (NULL != mesh->th))
608 { 633 {
609 /* queue empty, no point in asking for transmission */ 634 /* nothing ready to transmit, no point in asking for transmission */
610 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); 635 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th);
611 mesh->th = NULL; 636 mesh->th = NULL;
612 } 637 }
@@ -1113,13 +1138,19 @@ process_ack (struct GNUNET_MESH_Handle *h,
1113 return; 1138 return;
1114 } 1139 }
1115 ack = ntohl (msg->max_pid); 1140 ack = ntohl (msg->max_pid);
1141 LOG (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X, ack %u!\n", t->tid, ack);
1116 if (ack > t->max_pid || PID_OVERFLOW (t->max_pid, ack)) 1142 if (ack > t->max_pid || PID_OVERFLOW (t->max_pid, ack))
1117 t->max_pid = ack; 1143 t->max_pid = ack;
1144 else
1145 return;
1118 if (NULL == h->th && 0 < t->packet_size) 1146 if (NULL == h->th && 0 < t->packet_size)
1147 {
1148 LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n", t->tid, ack);
1119 h->th = 1149 h->th =
1120 GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size, 1150 GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size,
1121 GNUNET_TIME_UNIT_FOREVER_REL, 1151 GNUNET_TIME_UNIT_FOREVER_REL,
1122 GNUNET_YES, &send_callback, h); 1152 GNUNET_YES, &send_callback, h);
1153 }
1123} 1154}
1124 1155
1125 1156
@@ -1320,40 +1351,18 @@ send_callback (void *cls, size_t size, void *buf)
1320 } 1351 }
1321 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize); 1352 LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize);
1322 h->th = NULL; 1353 h->th = NULL;
1323 if (NULL != h->th_head) 1354 size = message_ready_size (h);
1355 if (0 != size)
1324 { 1356 {
1325 int request = GNUNET_NO; 1357 LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", size);
1326 1358 h->th =
1327 LOG (GNUNET_ERROR_TYPE_DEBUG, " head not empty\n"); 1359 GNUNET_CLIENT_notify_transmit_ready (h->client, size,
1328 for (th = h->th_head; NULL != th; th = th->next) 1360 GNUNET_TIME_UNIT_FOREVER_REL,
1329 { 1361 GNUNET_YES, &send_callback, h);
1330 struct GNUNET_MESH_Tunnel *t = th->tunnel; 1362 }
1331 1363 else
1332 LOG (GNUNET_ERROR_TYPE_DEBUG, " [%p] notify: %p, size %u\n", 1364 {
1333 th, th->notify, th->size); 1365 LOG (GNUNET_ERROR_TYPE_DEBUG, " nothing left to transmit\n");
1334 GNUNET_assert (NULL != t);
1335 LOG (GNUNET_ERROR_TYPE_DEBUG, " pid %u, max %u\n", t->pid, t->max_pid);
1336
1337 if (GNUNET_NO == th_is_payload (th) ||
1338 (t->max_pid >= t->pid || PID_OVERFLOW (t->pid, t->max_pid)))
1339 {
1340 request = GNUNET_YES;
1341 break;
1342 }
1343 }
1344
1345 if (GNUNET_YES == request)
1346 {
1347 LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", th->size);
1348 h->th =
1349 GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
1350 GNUNET_TIME_UNIT_FOREVER_REL,
1351 GNUNET_YES, &send_callback, h);
1352 }
1353 else
1354 {
1355 LOG (GNUNET_ERROR_TYPE_DEBUG, " nothing left to transmit\n");
1356 }
1357 } 1366 }
1358 if (GNUNET_NO == h->in_receive) 1367 if (GNUNET_NO == h->in_receive)
1359 { 1368 {
@@ -1989,7 +1998,7 @@ GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle *th)
1989 GNUNET_SCHEDULER_cancel (th->timeout_task); 1998 GNUNET_SCHEDULER_cancel (th->timeout_task);
1990 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th); 1999 GNUNET_CONTAINER_DLL_remove (mesh->th_head, mesh->th_tail, th);
1991 GNUNET_free (th); 2000 GNUNET_free (th);
1992 if ((NULL == mesh->th_head) && (NULL != mesh->th)) 2001 if ((0 == message_ready_size (mesh)) && (NULL != mesh->th))
1993 { 2002 {
1994 /* queue empty, no point in asking for transmission */ 2003 /* queue empty, no point in asking for transmission */
1995 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th); 2004 GNUNET_CLIENT_notify_transmit_ready_cancel (mesh->th);