diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-11-07 15:06:06 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-11-07 15:06:06 +0000 |
commit | 2c8c933676b54d6479a6446209be93023e012b5d (patch) | |
tree | 47f60d5829d2de046ade70b763dac06b7f0b06ba /src | |
parent | be3c1d4fd439562d75b2496e26ae1bb48eb81b01 (diff) | |
download | gnunet-2c8c933676b54d6479a6446209be93023e012b5d.tar.gz gnunet-2c8c933676b54d6479a6446209be93023e012b5d.zip |
- remove all possible ambiguous 'fwd' parameters in Tunnel API
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh_channel.c | 41 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 4 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.c | 196 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_tunnel.h | 23 |
4 files changed, 187 insertions, 77 deletions
diff --git a/src/mesh/gnunet-service-mesh_channel.c b/src/mesh/gnunet-service-mesh_channel.c index 0c672a091..4b5baa528 100644 --- a/src/mesh/gnunet-service-mesh_channel.c +++ b/src/mesh/gnunet-service-mesh_channel.c | |||
@@ -890,6 +890,15 @@ channel_set_options (struct MeshChannel *ch, uint32_t options) | |||
890 | GNUNET_YES : GNUNET_NO; | 890 | GNUNET_YES : GNUNET_NO; |
891 | } | 891 | } |
892 | 892 | ||
893 | static int | ||
894 | is_loopback (const struct MeshChannel *ch) | ||
895 | { | ||
896 | if (NULL != ch->t) | ||
897 | return GMT_is_loopback (ch->t); | ||
898 | |||
899 | return (NULL != ch->root && NULL != ch->dest); | ||
900 | } | ||
901 | |||
893 | 902 | ||
894 | /** | 903 | /** |
895 | * Handle a loopback message: call the appropriate handler for the message type. | 904 | * Handle a loopback message: call the appropriate handler for the message type. |
@@ -1253,7 +1262,7 @@ GMCH_debug (struct MeshChannel *ch) | |||
1253 | * Mark client as ready and send him any buffered data we could have for him. | 1262 | * Mark client as ready and send him any buffered data we could have for him. |
1254 | * | 1263 | * |
1255 | * @param ch Channel. | 1264 | * @param ch Channel. |
1256 | * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by root and go BCK) | 1265 | * @param fwd Is this a "FWD ACK"? (FWD ACKs are sent by dest and go BCK) |
1257 | */ | 1266 | */ |
1258 | void | 1267 | void |
1259 | GMCH_handle_local_ack (struct MeshChannel *ch, int fwd) | 1268 | GMCH_handle_local_ack (struct MeshChannel *ch, int fwd) |
@@ -1266,7 +1275,17 @@ GMCH_handle_local_ack (struct MeshChannel *ch, int fwd) | |||
1266 | 1275 | ||
1267 | rel->client_ready = GNUNET_YES; | 1276 | rel->client_ready = GNUNET_YES; |
1268 | send_client_buffered_data (ch, c, fwd); | 1277 | send_client_buffered_data (ch, c, fwd); |
1269 | GMT_send_acks (ch->t, fwd); | 1278 | if (is_loopback (ch)) |
1279 | { | ||
1280 | unsigned int buffer; | ||
1281 | |||
1282 | buffer = GMCH_get_buffer (ch, fwd); | ||
1283 | if (0 < buffer) | ||
1284 | GMCH_allow_client (ch, fwd); | ||
1285 | |||
1286 | return; | ||
1287 | } | ||
1288 | GMT_send_connection_acks (ch->t); | ||
1270 | } | 1289 | } |
1271 | 1290 | ||
1272 | 1291 | ||
@@ -1324,7 +1343,15 @@ GMCH_handle_local_data (struct MeshChannel *ch, | |||
1324 | channel_save_copy (ch, &payload->header, fwd); | 1343 | channel_save_copy (ch, &payload->header, fwd); |
1325 | GMCH_send_prebuilt_message (&payload->header, ch, fwd); | 1344 | GMCH_send_prebuilt_message (&payload->header, ch, fwd); |
1326 | 1345 | ||
1327 | if (GMT_get_buffer (ch->t, fwd) > 0) | 1346 | if (is_loopback (ch)) |
1347 | { | ||
1348 | if (GMCH_get_buffer (ch, fwd) > 0); | ||
1349 | send_client_ack (ch, fwd); | ||
1350 | |||
1351 | return GNUNET_OK; | ||
1352 | } | ||
1353 | |||
1354 | if (GMT_get_connections_buffer (ch->t) > 0) | ||
1328 | { | 1355 | { |
1329 | send_client_ack (ch, fwd); | 1356 | send_client_ack (ch, fwd); |
1330 | } | 1357 | } |
@@ -1466,7 +1493,7 @@ GMCH_handle_data (struct MeshChannel *ch, | |||
1466 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ | 1493 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ |
1467 | if (GNUNET_SYSERR == fwd) | 1494 | if (GNUNET_SYSERR == fwd) |
1468 | { | 1495 | { |
1469 | if (NULL != ch->dest && NULL != ch->root) | 1496 | if (is_loopback (ch)) |
1470 | { | 1497 | { |
1471 | /* It is a loopback channel after all... */ | 1498 | /* It is a loopback channel after all... */ |
1472 | GNUNET_break (0); | 1499 | GNUNET_break (0); |
@@ -1554,7 +1581,7 @@ GMCH_handle_data_ack (struct MeshChannel *ch, | |||
1554 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ | 1581 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ |
1555 | if (GNUNET_SYSERR == fwd) | 1582 | if (GNUNET_SYSERR == fwd) |
1556 | { | 1583 | { |
1557 | if (NULL != ch->dest && NULL != ch->root) | 1584 | if (is_loopback (ch)) |
1558 | { | 1585 | { |
1559 | /* It is a loopback channel after all... */ | 1586 | /* It is a loopback channel after all... */ |
1560 | GNUNET_break (0); | 1587 | GNUNET_break (0); |
@@ -1704,7 +1731,7 @@ GMCH_handle_ack (struct MeshChannel *ch, | |||
1704 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ | 1731 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ |
1705 | if (GNUNET_SYSERR == fwd) | 1732 | if (GNUNET_SYSERR == fwd) |
1706 | { | 1733 | { |
1707 | if (NULL != ch->dest && NULL != ch->root) | 1734 | if (is_loopback (ch)) |
1708 | { | 1735 | { |
1709 | /* It is a loopback channel after all... */ | 1736 | /* It is a loopback channel after all... */ |
1710 | GNUNET_break (0); | 1737 | GNUNET_break (0); |
@@ -1737,7 +1764,7 @@ GMCH_handle_destroy (struct MeshChannel *ch, | |||
1737 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ | 1764 | /* If this is a remote (non-loopback) channel, find 'fwd'. */ |
1738 | if (GNUNET_SYSERR == fwd) | 1765 | if (GNUNET_SYSERR == fwd) |
1739 | { | 1766 | { |
1740 | if (NULL != ch->dest && NULL != ch->root) | 1767 | if (is_loopback (ch)) |
1741 | { | 1768 | { |
1742 | /* It is a loopback channel after all... */ | 1769 | /* It is a loopback channel after all... */ |
1743 | GNUNET_break (0); | 1770 | GNUNET_break (0); |
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index d7f035d7e..3dd765a63 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -1818,7 +1818,7 @@ GMC_send_ack (struct MeshConnection *c, int fwd) | |||
1818 | if (GMC_is_terminal (c, fwd)) | 1818 | if (GMC_is_terminal (c, fwd)) |
1819 | { | 1819 | { |
1820 | LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all channels\n"); | 1820 | LOG (GNUNET_ERROR_TYPE_DEBUG, " getting from all channels\n"); |
1821 | buffer = GMT_get_buffer (c->t, fwd); | 1821 | buffer = GMT_get_channels_buffer (c->t); |
1822 | } | 1822 | } |
1823 | else | 1823 | else |
1824 | { | 1824 | { |
@@ -1835,7 +1835,7 @@ GMC_send_ack (struct MeshConnection *c, int fwd) | |||
1835 | if (0 < buffer) | 1835 | if (0 < buffer) |
1836 | { | 1836 | { |
1837 | LOG (GNUNET_ERROR_TYPE_DEBUG, " really sending!\n"); | 1837 | LOG (GNUNET_ERROR_TYPE_DEBUG, " really sending!\n"); |
1838 | GMT_unchoke_channels (c->t, fwd); | 1838 | GMT_unchoke_channels (c->t); |
1839 | } | 1839 | } |
1840 | } | 1840 | } |
1841 | else | 1841 | else |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.c b/src/mesh/gnunet-service-mesh_tunnel.c index 7fbcd7081..977908f35 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.c +++ b/src/mesh/gnunet-service-mesh_tunnel.c | |||
@@ -291,6 +291,82 @@ ping_encryption_size (void) | |||
291 | 291 | ||
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Get the channel's buffer. ONLY FOR NON-LOOPBACK CHANNELS!! | ||
295 | * | ||
296 | * @param tch Tunnel's channel handle. | ||
297 | * | ||
298 | * @return Amount of messages the channel can still buffer towards the client. | ||
299 | */ | ||
300 | static unsigned int | ||
301 | get_channel_buffer (const struct MeshTChannel *tch) | ||
302 | { | ||
303 | int fwd; | ||
304 | |||
305 | /* If channel is outgoing, is origin in the FWD direction and fwd is YES */ | ||
306 | fwd = GMCH_is_origin (tch->ch, GNUNET_YES); | ||
307 | |||
308 | return GMCH_get_buffer (tch->ch, fwd); | ||
309 | } | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Get the channel's allowance status. | ||
314 | * | ||
315 | * @param tch Tunnel's channel handle. | ||
316 | * | ||
317 | * @return #GNUNET_YES if we allowed the client to send data to us. | ||
318 | */ | ||
319 | static int | ||
320 | get_channel_allowed (const struct MeshTChannel *tch) | ||
321 | { | ||
322 | int fwd; | ||
323 | |||
324 | /* If channel is outgoing, is origin in the FWD direction and fwd is YES */ | ||
325 | fwd = GMCH_is_origin (tch->ch, GNUNET_YES); | ||
326 | |||
327 | return GMCH_get_allowed (tch->ch, fwd); | ||
328 | } | ||
329 | |||
330 | |||
331 | /** | ||
332 | * Get the connection's buffer. | ||
333 | * | ||
334 | * @param tc Tunnel's connection handle. | ||
335 | * | ||
336 | * @return Amount of messages the connection can still buffer. | ||
337 | */ | ||
338 | static unsigned int | ||
339 | get_connection_buffer (const struct MeshTConnection *tc) | ||
340 | { | ||
341 | int fwd; | ||
342 | |||
343 | /* If connection is outgoing, is origin in the FWD direction and fwd is YES */ | ||
344 | fwd = GMC_is_origin (tc->c, GNUNET_YES); | ||
345 | |||
346 | return GMC_get_buffer (tc->c, fwd); | ||
347 | } | ||
348 | |||
349 | |||
350 | /** | ||
351 | * Get the connection's allowance. | ||
352 | * | ||
353 | * @param tc Tunnel's connection handle. | ||
354 | * | ||
355 | * @return Amount of messages we have allowed the next peer to send us. | ||
356 | */ | ||
357 | static unsigned int | ||
358 | get_connection_allowed (const struct MeshTConnection *tc) | ||
359 | { | ||
360 | int fwd; | ||
361 | |||
362 | /* If connection is outgoing, is origin in the FWD direction and fwd is YES */ | ||
363 | fwd = GMC_is_origin (tc->c, GNUNET_YES); | ||
364 | |||
365 | return GMC_get_allowed (tc->c, fwd); | ||
366 | } | ||
367 | |||
368 | |||
369 | /** | ||
294 | * Check that a ephemeral key message s well formed and correctly signed. | 370 | * Check that a ephemeral key message s well formed and correctly signed. |
295 | * | 371 | * |
296 | * @param t Tunnel on which the message came. | 372 | * @param t Tunnel on which the message came. |
@@ -454,11 +530,10 @@ tunnel_get_connection (struct MeshTunnel3 *t) | |||
454 | /** | 530 | /** |
455 | * Send all cached messages that we can, tunnel is online. | 531 | * Send all cached messages that we can, tunnel is online. |
456 | * | 532 | * |
457 | * @param t Tunnel that holds the messages. | 533 | * @param t Tunnel that holds the messages. Cannot be loopback. |
458 | * @param fwd Is this fwd? | ||
459 | */ | 534 | */ |
460 | static void | 535 | static void |
461 | send_queued_data (struct MeshTunnel3 *t, int fwd) | 536 | send_queued_data (struct MeshTunnel3 *t) |
462 | { | 537 | { |
463 | struct MeshTunnelQueue *tq; | 538 | struct MeshTunnelQueue *tq; |
464 | struct MeshTunnelQueue *next; | 539 | struct MeshTunnelQueue *next; |
@@ -468,11 +543,13 @@ send_queued_data (struct MeshTunnel3 *t, int fwd) | |||
468 | "GMT_send_queued_data on tunnel %s\n", | 543 | "GMT_send_queued_data on tunnel %s\n", |
469 | GMT_2s (t)); | 544 | GMT_2s (t)); |
470 | 545 | ||
471 | if (NULL == t->channel_head || | 546 | if (GMT_is_loopback (t)) |
472 | GNUNET_NO == GMCH_is_origin (t->channel_head->ch, fwd)) | 547 | { |
548 | GNUNET_break (0); | ||
473 | return; | 549 | return; |
550 | } | ||
474 | 551 | ||
475 | room = GMT_get_buffer (t, fwd); | 552 | room = GMT_get_connections_buffer (t); |
476 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room); | 553 | LOG (GNUNET_ERROR_TYPE_DEBUG, " buffer space: %u\n", room); |
477 | for (tq = t->tq_head; NULL != tq && room > 0; tq = next) | 554 | for (tq = t->tq_head; NULL != tq && room > 0; tq = next) |
478 | { | 555 | { |
@@ -481,7 +558,7 @@ send_queued_data (struct MeshTunnel3 *t, int fwd) | |||
481 | room--; | 558 | room--; |
482 | GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq); | 559 | GNUNET_CONTAINER_DLL_remove (t->tq_head, t->tq_tail, tq); |
483 | GMCH_send_prebuilt_message ((struct GNUNET_MessageHeader *) &tq[1], | 560 | GMCH_send_prebuilt_message ((struct GNUNET_MessageHeader *) &tq[1], |
484 | tq->ch, fwd); | 561 | tq->ch, GMCH_is_origin (tq->ch, GNUNET_YES)); |
485 | 562 | ||
486 | GNUNET_free (tq); | 563 | GNUNET_free (tq); |
487 | } | 564 | } |
@@ -1049,8 +1126,7 @@ handle_pong (struct MeshTunnel3 *t, | |||
1049 | GNUNET_free (t->kx_ctx); | 1126 | GNUNET_free (t->kx_ctx); |
1050 | t->kx_ctx = NULL; | 1127 | t->kx_ctx = NULL; |
1051 | t->state = MESH_TUNNEL3_READY; | 1128 | t->state = MESH_TUNNEL3_READY; |
1052 | send_queued_data (t, GNUNET_YES); | 1129 | send_queued_data (t); |
1053 | send_queued_data (t, GNUNET_NO); | ||
1054 | } | 1130 | } |
1055 | 1131 | ||
1056 | 1132 | ||
@@ -1590,52 +1666,60 @@ enum MeshTunnel3State | |||
1590 | GMT_get_state (struct MeshTunnel3 *t) | 1666 | GMT_get_state (struct MeshTunnel3 *t) |
1591 | { | 1667 | { |
1592 | if (NULL == t) | 1668 | if (NULL == t) |
1669 | { | ||
1670 | GNUNET_break (0); | ||
1593 | return (enum MeshTunnel3State) -1; | 1671 | return (enum MeshTunnel3State) -1; |
1672 | } | ||
1594 | return t->state; | 1673 | return t->state; |
1595 | } | 1674 | } |
1596 | 1675 | ||
1676 | |||
1597 | /** | 1677 | /** |
1598 | * Get the total buffer space for a tunnel. | 1678 | * Get the maximum buffer space for a tunnel towards a local client. |
1599 | * | ||
1600 | * If terminal, use the biggest channel buffer (or 64) if no channel exists. | ||
1601 | * If not terminal, use the sum of all connection buffers. | ||
1602 | * | 1679 | * |
1603 | * @param t Tunnel. | 1680 | * @param t Tunnel. |
1604 | * @param fwd Is this for FWD traffic? | ||
1605 | * | 1681 | * |
1606 | * @return Buffer space offered by all entities (c/ch) in the tunnel. | 1682 | * @return Biggest buffer space offered by any channel in the tunnel. |
1607 | */ | 1683 | */ |
1608 | unsigned int | 1684 | unsigned int |
1609 | GMT_get_buffer (struct MeshTunnel3 *t, int fwd) | 1685 | GMT_get_channels_buffer (struct MeshTunnel3 *t) |
1610 | { | 1686 | { |
1611 | struct MeshTConnection *iter; | 1687 | struct MeshTChannel *iter; |
1612 | unsigned int buffer; | 1688 | unsigned int buffer; |
1689 | unsigned int ch_buf; | ||
1613 | 1690 | ||
1614 | iter = t->connection_head; | 1691 | if (NULL == t->channel_head) |
1615 | buffer = 0; | 1692 | { |
1693 | /* Probably getting buffer for a channel create/handshake. */ | ||
1694 | return 64; | ||
1695 | } | ||
1616 | 1696 | ||
1617 | /* If terminal, return biggest channel buffer */ | 1697 | buffer = 0; |
1618 | if (NULL == iter || GMC_is_terminal (iter->c, fwd)) | 1698 | for (iter = t->channel_head; NULL != iter; iter = iter->next) |
1619 | { | 1699 | { |
1620 | struct MeshTChannel *iter_ch; | 1700 | ch_buf = get_channel_buffer (iter); |
1621 | unsigned int ch_buf; | 1701 | if (ch_buf > buffer) |
1702 | buffer = ch_buf; | ||
1703 | } | ||
1704 | return buffer; | ||
1705 | } | ||
1622 | 1706 | ||
1623 | if (NULL == t->channel_head) | ||
1624 | { | ||
1625 | /* Probably getting buffer for a channel create/handshake. */ | ||
1626 | return 64; | ||
1627 | } | ||
1628 | 1707 | ||
1629 | for (iter_ch = t->channel_head; NULL != iter_ch; iter_ch = iter_ch->next) | 1708 | /** |
1630 | { | 1709 | * Get the total buffer space for a tunnel for P2P traffic. |
1631 | ch_buf = GMCH_get_buffer (iter_ch->ch, fwd); | 1710 | * |
1632 | if (ch_buf > buffer) | 1711 | * @param t Tunnel. |
1633 | buffer = ch_buf; | 1712 | * |
1634 | } | 1713 | * @return Buffer space offered by all connections in the tunnel. |
1635 | return buffer; | 1714 | */ |
1636 | } | 1715 | unsigned int |
1716 | GMT_get_connections_buffer (struct MeshTunnel3 *t) | ||
1717 | { | ||
1718 | struct MeshTConnection *iter; | ||
1719 | unsigned int buffer; | ||
1637 | 1720 | ||
1638 | /* If not terminal, return sum of connection buffers */ | 1721 | iter = t->connection_head; |
1722 | buffer = 0; | ||
1639 | while (NULL != iter) | 1723 | while (NULL != iter) |
1640 | { | 1724 | { |
1641 | if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) | 1725 | if (GMC_get_state (iter->c) != MESH_CONNECTION_READY) |
@@ -1644,7 +1728,7 @@ GMT_get_buffer (struct MeshTunnel3 *t, int fwd) | |||
1644 | continue; | 1728 | continue; |
1645 | } | 1729 | } |
1646 | 1730 | ||
1647 | buffer += GMC_get_buffer (iter->c, fwd); | 1731 | buffer += get_connection_buffer (iter); |
1648 | iter = iter->next; | 1732 | iter = iter->next; |
1649 | } | 1733 | } |
1650 | 1734 | ||
@@ -1694,10 +1778,9 @@ GMT_get_next_chid (struct MeshTunnel3 *t) | |||
1694 | * Send ACK on one or more channels due to buffer in connections. | 1778 | * Send ACK on one or more channels due to buffer in connections. |
1695 | * | 1779 | * |
1696 | * @param t Channel which has some free buffer space. | 1780 | * @param t Channel which has some free buffer space. |
1697 | * @param fwd Is this for FWD traffic? (ACK goes to root) | ||
1698 | */ | 1781 | */ |
1699 | void | 1782 | void |
1700 | GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd) | 1783 | GMT_unchoke_channels (struct MeshTunnel3 *t) |
1701 | { | 1784 | { |
1702 | struct MeshTChannel *iter; | 1785 | struct MeshTChannel *iter; |
1703 | unsigned int buffer; | 1786 | unsigned int buffer; |
@@ -1717,7 +1800,7 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd) | |||
1717 | } | 1800 | } |
1718 | 1801 | ||
1719 | /* Get buffer space */ | 1802 | /* Get buffer space */ |
1720 | buffer = GMT_get_buffer (t, fwd); | 1803 | buffer = GMT_get_connections_buffer (t); |
1721 | if (0 == buffer) | 1804 | if (0 == buffer) |
1722 | { | 1805 | { |
1723 | return; | 1806 | return; |
@@ -1727,7 +1810,7 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd) | |||
1727 | choked_n = 0; | 1810 | choked_n = 0; |
1728 | for (iter = t->channel_head; NULL != iter; iter = iter->next) | 1811 | for (iter = t->channel_head; NULL != iter; iter = iter->next) |
1729 | { | 1812 | { |
1730 | if (GNUNET_NO == GMCH_get_allowed (iter->ch, fwd)) | 1813 | if (GNUNET_NO == get_channel_allowed (iter)) |
1731 | { | 1814 | { |
1732 | choked[choked_n++] = iter->ch; | 1815 | choked[choked_n++] = iter->ch; |
1733 | } | 1816 | } |
@@ -1738,7 +1821,7 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd) | |||
1738 | { | 1821 | { |
1739 | unsigned int r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1822 | unsigned int r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, |
1740 | choked_n); | 1823 | choked_n); |
1741 | GMCH_allow_client (choked[r], fwd); | 1824 | GMCH_allow_client (choked[r], GMCH_is_origin (choked[r], GNUNET_YES)); |
1742 | choked_n--; | 1825 | choked_n--; |
1743 | buffer--; | 1826 | buffer--; |
1744 | choked[r] = choked[choked_n]; | 1827 | choked[r] = choked[choked_n]; |
@@ -1752,10 +1835,9 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd) | |||
1752 | * Iterates all connections of the tunnel and sends ACKs appropriately. | 1835 | * Iterates all connections of the tunnel and sends ACKs appropriately. |
1753 | * | 1836 | * |
1754 | * @param t Tunnel. | 1837 | * @param t Tunnel. |
1755 | * @param fwd Is this in for FWD traffic? (ACK goes dest->root) | ||
1756 | */ | 1838 | */ |
1757 | void | 1839 | void |
1758 | GMT_send_acks (struct MeshTunnel3 *t, int fwd) | 1840 | GMT_send_connection_acks (struct MeshTunnel3 *t) |
1759 | { | 1841 | { |
1760 | struct MeshTConnection *iter; | 1842 | struct MeshTConnection *iter; |
1761 | uint32_t allowed; | 1843 | uint32_t allowed; |
@@ -1764,35 +1846,28 @@ GMT_send_acks (struct MeshTunnel3 *t, int fwd) | |||
1764 | unsigned int cs; | 1846 | unsigned int cs; |
1765 | unsigned int buffer; | 1847 | unsigned int buffer; |
1766 | 1848 | ||
1767 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1849 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1768 | "Tunnel send %s ACKs on %s\n", | 1850 | "Tunnel send connection ACKs on %s\n", |
1769 | fwd ? "FWD" : "BCK", GMT_2s (t)); | 1851 | GMT_2s (t)); |
1770 | 1852 | ||
1771 | if (NULL == t) | 1853 | if (NULL == t) |
1772 | { | 1854 | { |
1773 | GNUNET_break (0); | 1855 | GNUNET_break (0); |
1774 | return; | 1856 | return; |
1775 | } | 1857 | } |
1776 | if (NULL == t->channel_head || | ||
1777 | GNUNET_NO == GMCH_is_origin (t->channel_head->ch, !fwd)) | ||
1778 | { | ||
1779 | GNUNET_break (0); | ||
1780 | return; | ||
1781 | } | ||
1782 | 1858 | ||
1783 | buffer = GMT_get_buffer (t, fwd); | 1859 | buffer = GMT_get_channels_buffer (t); |
1784 | 1860 | ||
1785 | /* Count connections, how many messages are already allowed */ | 1861 | /* Count connections, how many messages are already allowed */ |
1786 | cs = GMT_count_connections (t); | 1862 | cs = GMT_count_connections (t); |
1787 | for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next) | 1863 | for (allowed = 0, iter = t->connection_head; NULL != iter; iter = iter->next) |
1788 | { | 1864 | { |
1789 | allowed += GMC_get_allowed (iter->c, fwd); | 1865 | allowed += get_connection_allowed (iter); |
1790 | } | 1866 | } |
1791 | 1867 | ||
1792 | /* Make sure there is no overflow */ | 1868 | /* Make sure there is no overflow */ |
1793 | if (allowed > buffer) | 1869 | if (allowed > buffer) |
1794 | { | 1870 | { |
1795 | GNUNET_break (0); | ||
1796 | return; | 1871 | return; |
1797 | } | 1872 | } |
1798 | 1873 | ||
@@ -1804,11 +1879,11 @@ GMT_send_acks (struct MeshTunnel3 *t, int fwd) | |||
1804 | allow_per_connection = to_allow/cs; | 1879 | allow_per_connection = to_allow/cs; |
1805 | to_allow -= allow_per_connection; | 1880 | to_allow -= allow_per_connection; |
1806 | cs--; | 1881 | cs--; |
1807 | if (GMC_get_allowed (iter->c, fwd) > 64 / 3) | 1882 | if (get_connection_allowed (iter) > 64 / 3) |
1808 | { | 1883 | { |
1809 | continue; | 1884 | continue; |
1810 | } | 1885 | } |
1811 | GMC_allow (iter->c, buffer, fwd); | 1886 | GMC_allow (iter->c, buffer, GMC_is_origin (iter->c, GNUNET_YES)); |
1812 | } | 1887 | } |
1813 | 1888 | ||
1814 | GNUNET_break (to_allow == 0); | 1889 | GNUNET_break (to_allow == 0); |
@@ -1970,5 +2045,8 @@ GMT_get_path_cost (const struct MeshTunnel3 *t, | |||
1970 | const char * | 2045 | const char * |
1971 | GMT_2s (const struct MeshTunnel3 *t) | 2046 | GMT_2s (const struct MeshTunnel3 *t) |
1972 | { | 2047 | { |
2048 | if (NULL == t) | ||
2049 | return "(NULL)"; | ||
2050 | |||
1973 | return GMP_2s (t->peer); | 2051 | return GMP_2s (t->peer); |
1974 | } \ No newline at end of file | 2052 | } \ No newline at end of file |
diff --git a/src/mesh/gnunet-service-mesh_tunnel.h b/src/mesh/gnunet-service-mesh_tunnel.h index aa4b90329..6f6151ddc 100644 --- a/src/mesh/gnunet-service-mesh_tunnel.h +++ b/src/mesh/gnunet-service-mesh_tunnel.h | |||
@@ -279,17 +279,24 @@ enum MeshTunnel3State | |||
279 | GMT_get_state (struct MeshTunnel3 *t); | 279 | GMT_get_state (struct MeshTunnel3 *t); |
280 | 280 | ||
281 | /** | 281 | /** |
282 | * Get the total buffer space for a tunnel. | 282 | * Get the maximum buffer space for a tunnel towards a local client. |
283 | * | 283 | * |
284 | * FIXME get a ch parameter in case of loopback tunnels | 284 | * @param t Tunnel. |
285 | * | ||
286 | * @return Biggest buffer space offered by any channel in the tunnel. | ||
287 | */ | ||
288 | unsigned int | ||
289 | GMT_get_channels_buffer (struct MeshTunnel3 *t); | ||
290 | |||
291 | /** | ||
292 | * Get the total buffer space for a tunnel for P2P traffic. | ||
285 | * | 293 | * |
286 | * @param t Tunnel. | 294 | * @param t Tunnel. |
287 | * @param fwd Is this for FWD traffic? | ||
288 | * | 295 | * |
289 | * @return Buffer space offered by all connections in the tunnel. | 296 | * @return Buffer space offered by all connections in the tunnel. |
290 | */ | 297 | */ |
291 | unsigned int | 298 | unsigned int |
292 | GMT_get_buffer (struct MeshTunnel3 *t, int fwd); | 299 | GMT_get_connections_buffer (struct MeshTunnel3 *t); |
293 | 300 | ||
294 | /** | 301 | /** |
295 | * Get the tunnel's destination. | 302 | * Get the tunnel's destination. |
@@ -315,10 +322,9 @@ GMT_get_next_chid (struct MeshTunnel3 *t); | |||
315 | * Send ACK on one or more channels due to buffer in connections. | 322 | * Send ACK on one or more channels due to buffer in connections. |
316 | * | 323 | * |
317 | * @param t Channel which has some free buffer space. | 324 | * @param t Channel which has some free buffer space. |
318 | * @param fwd Is this for FWD traffic? (ACK goes to root) | ||
319 | */ | 325 | */ |
320 | void | 326 | void |
321 | GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd); | 327 | GMT_unchoke_channels (struct MeshTunnel3 *t); |
322 | 328 | ||
323 | /** | 329 | /** |
324 | * Send ACK on one or more connections due to buffer space to the client. | 330 | * Send ACK on one or more connections due to buffer space to the client. |
@@ -326,10 +332,9 @@ GMT_unchoke_channels (struct MeshTunnel3 *t, int fwd); | |||
326 | * Iterates all connections of the tunnel and sends ACKs appropriately. | 332 | * Iterates all connections of the tunnel and sends ACKs appropriately. |
327 | * | 333 | * |
328 | * @param t Tunnel which has some free buffer space. | 334 | * @param t Tunnel which has some free buffer space. |
329 | * @param fwd Is this in for FWD traffic? (ACK goes dest->root) | ||
330 | */ | 335 | */ |
331 | void | 336 | void |
332 | GMT_send_acks (struct MeshTunnel3 *t, int fwd); | 337 | GMT_send_connection_acks (struct MeshTunnel3 *t); |
333 | 338 | ||
334 | /** | 339 | /** |
335 | * Sends an already built message on a tunnel, encrypting it and | 340 | * Sends an already built message on a tunnel, encrypting it and |