aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh-enc.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-08-26 13:41:20 +0000
committerBart Polot <bart@net.in.tum.de>2013-08-26 13:41:20 +0000
commit5a4c0bfabee2d251b31a7279f3bf6f81065442ce (patch)
treee688918e835179f1610103b7f28611a131c8e3bf /src/mesh/gnunet-service-mesh-enc.c
parent57b1e245f665b46f9424a711d99c21d9075b9964 (diff)
downloadgnunet-5a4c0bfabee2d251b31a7279f3bf6f81065442ce.tar.gz
gnunet-5a4c0bfabee2d251b31a7279f3bf6f81065442ce.zip
- separate channel from connection ack counting
Diffstat (limited to 'src/mesh/gnunet-service-mesh-enc.c')
-rw-r--r--src/mesh/gnunet-service-mesh-enc.c206
1 files changed, 123 insertions, 83 deletions
diff --git a/src/mesh/gnunet-service-mesh-enc.c b/src/mesh/gnunet-service-mesh-enc.c
index 41d4f570e..697c51c81 100644
--- a/src/mesh/gnunet-service-mesh-enc.c
+++ b/src/mesh/gnunet-service-mesh-enc.c
@@ -1586,6 +1586,92 @@ tunnel_get_connection (struct MeshTunnel2 *t, int fwd)
1586} 1586}
1587 1587
1588 1588
1589
1590
1591/**
1592 * Is this peer the first one on the connection?
1593 *
1594 * @param c Connection.
1595 * @param fwd Is this about fwd traffic?
1596 *
1597 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
1598 */
1599static int
1600connection_is_origin (struct MeshConnection *c, int fwd)
1601{
1602 if (!fwd && c->own_pos == c->path->length - 1)
1603 return GNUNET_YES;
1604 if (fwd && c->own_pos == 0)
1605 return GNUNET_YES;
1606 return GNUNET_NO;
1607}
1608
1609
1610/**
1611 * Is this peer the last one on the connection?
1612 *
1613 * @param c Connection.
1614 * @param fwd Is this about fwd traffic?
1615 * Note that the ROOT is the terminal for BCK traffic!
1616 *
1617 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
1618 */
1619static int
1620connection_is_terminal (struct MeshConnection *c, int fwd)
1621{
1622 if (fwd && c->own_pos == c->path->length - 1)
1623 return GNUNET_YES;
1624 if (!fwd && c->own_pos == 0)
1625 return GNUNET_YES;
1626 return GNUNET_NO;
1627}
1628
1629
1630/**
1631 * Get free buffer space towards the client on a specific channel.
1632 *
1633 * @param ch Channel.
1634 * @param fwd Is query about FWD traffic?
1635 *
1636 * @return Free buffer space [0 - 64]
1637 */
1638static unsigned int
1639channel_get_buffer (struct MeshChannel *ch, int fwd)
1640{
1641 struct MeshChannelReliability *rel;
1642
1643 rel = fwd ? ch->dest_rel : ch->root_rel;
1644
1645 /* If rel is NULL it means that the end is not yet created,
1646 * most probably is a loopback channel at the point of sending
1647 * the ChannelCreate to itself.
1648 */
1649 if (NULL == rel)
1650 return 64;
1651
1652 return (64 - rel->n_recv);
1653}
1654
1655
1656/**
1657 * Get free buffer space in a connection.
1658 *
1659 * @param c Connection.
1660 * @param fwd Is query about FWD traffic?
1661 *
1662 * @return Free buffer space [0 - max_msgs_queue/max_connections]
1663 */
1664static unsigned int
1665connection_get_buffer (struct MeshConnection *c, int fwd)
1666{
1667 struct MeshFlowControl *fc;
1668
1669 fc = fwd ? &c->fwd_fc : &c->bck_fc;
1670
1671 return (fc->queue_max - fc->queue_n);
1672}
1673
1674
1589/** 1675/**
1590 * Get the total buffer space for a tunnel. 1676 * Get the total buffer space for a tunnel.
1591 */ 1677 */
@@ -1596,13 +1682,42 @@ tunnel_get_buffer (struct MeshTunnel2 *t, int fwd)
1596 struct MeshFlowControl *fc; 1682 struct MeshFlowControl *fc;
1597 unsigned int buffer; 1683 unsigned int buffer;
1598 1684
1599 for (buffer = 0, c = t->connection_head; NULL != c; c = c->next) 1685 c = t->connection_head;
1686 buffer = 0;
1687
1688 if (NULL == c)
1689 {
1690 GNUNET_break (0);
1691 return 0;
1692 }
1693
1694 /* If terminal, return biggest channel buffer */
1695 if (connection_is_terminal (c, fwd))
1696 {
1697 struct MeshChannel *ch;
1698 unsigned int ch_buf;
1699
1700 if (NULL == t->channel_head)
1701 return 64;
1702
1703 for (ch = t->channel_head; NULL != ch; ch = ch->next)
1704 {
1705 ch_buf = channel_get_buffer (ch, fwd);
1706 if (ch_buf > buffer)
1707 buffer = ch_buf;
1708 }
1709 return buffer;
1710 }
1711
1712 /* If not terminal, return sum of connection buffers */
1713 while (NULL != c)
1600 { 1714 {
1601 if (c->state != MESH_CONNECTION_READY) 1715 if (c->state != MESH_CONNECTION_READY)
1602 continue; 1716 continue;
1603 1717
1604 fc = fwd ? &c->fwd_fc : &c->bck_fc; 1718 fc = fwd ? &c->fwd_fc : &c->bck_fc;
1605 buffer += fc->last_ack_recv - fc->last_pid_sent; 1719 buffer += fc->last_ack_recv - fc->last_pid_sent;
1720 c = c->next;
1606 } 1721 }
1607 1722
1608 return buffer; 1723 return buffer;
@@ -2352,45 +2467,6 @@ connection_get_first_message (struct MeshConnection *c, int fwd)
2352 2467
2353 2468
2354/** 2469/**
2355 * Is this peer the first one on the connection?
2356 *
2357 * @param c Connection.
2358 * @param fwd Is this about fwd traffic?
2359 *
2360 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
2361 */
2362static int
2363connection_is_origin (struct MeshConnection *c, int fwd)
2364{
2365 if (!fwd && c->own_pos == c->path->length - 1)
2366 return GNUNET_YES;
2367 if (fwd && c->own_pos == 0)
2368 return GNUNET_YES;
2369 return GNUNET_NO;
2370}
2371
2372
2373/**
2374 * Is this peer the last one on the connection?
2375 *
2376 * @param c Connection.
2377 * @param fwd Is this about fwd traffic?
2378 * Note that the ROOT is the terminal for BCK traffic!
2379 *
2380 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
2381 */
2382static int
2383connection_is_terminal (struct MeshConnection *c, int fwd)
2384{
2385 if (fwd && c->own_pos == c->path->length - 1)
2386 return GNUNET_YES;
2387 if (!fwd && c->own_pos == 0)
2388 return GNUNET_YES;
2389 return GNUNET_NO;
2390}
2391
2392
2393/**
2394 * @brief Re-initiate traffic on this connection if necessary. 2470 * @brief Re-initiate traffic on this connection if necessary.
2395 * 2471 *
2396 * Check if there is traffic queued towards this peer 2472 * Check if there is traffic queued towards this peer
@@ -3657,44 +3733,6 @@ channel_send_connections_ack (struct MeshChannel *ch,
3657 3733
3658 3734
3659/** 3735/**
3660 * Get free buffer space towards the client on a specific channel.
3661 *
3662 * @param ch Channel.
3663 * @param fwd Is query about FWD traffic?
3664 *
3665 * @return Free buffer space [0 - 64]
3666 */
3667static unsigned int
3668channel_get_buffer (struct MeshChannel *ch, int fwd)
3669{
3670 struct MeshChannelReliability *rel;
3671
3672 rel = fwd ? ch->dest_rel : ch->root_rel;
3673
3674 return (64 - rel->n_recv);
3675}
3676
3677
3678/**
3679 * Get free buffer space in a connection.
3680 *
3681 * @param c Connection.
3682 * @param fwd Is query about FWD traffic?
3683 *
3684 * @return Free buffer space [0 - max_msgs_queue/max_connections]
3685 */
3686static unsigned int
3687connection_get_buffer (struct MeshConnection *c, int fwd)
3688{
3689 struct MeshFlowControl *fc;
3690
3691 fc = fwd ? &c->fwd_fc : &c->bck_fc;
3692
3693 return (fc->queue_max - fc->queue_n);
3694}
3695
3696
3697/**
3698 * Send an ACK on the appropriate connection/channel, depending on 3736 * Send an ACK on the appropriate connection/channel, depending on
3699 * the direction and the position of the peer. 3737 * the direction and the position of the peer.
3700 * 3738 *
@@ -3710,7 +3748,7 @@ send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd)
3710 if (NULL == c || connection_is_terminal (c, fwd)) 3748 if (NULL == c || connection_is_terminal (c, fwd))
3711 { 3749 {
3712 GNUNET_assert (NULL != ch); 3750 GNUNET_assert (NULL != ch);
3713 buffer = channel_get_buffer (ch, fwd); 3751 buffer = tunnel_get_buffer (ch->t, fwd);
3714 } 3752 }
3715 else 3753 else
3716 { 3754 {
@@ -3752,8 +3790,8 @@ channel_confirm (struct MeshChannel *ch, int fwd)
3752 struct MeshReliableMessage *next; 3790 struct MeshReliableMessage *next;
3753 3791
3754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3755 " channel confirm %s:%X\n", 3793 " channel confirm %s %s:%X\n",
3756 peer2s (ch->t->peer), ch->gid); 3794 fwd ? "FWD" : "BCK", peer2s (ch->t->peer), ch->gid);
3757 ch->state = MESH_CHANNEL_READY; 3795 ch->state = MESH_CHANNEL_READY;
3758 3796
3759 rel = fwd ? ch->root_rel : ch->dest_rel; 3797 rel = fwd ? ch->root_rel : ch->dest_rel;
@@ -3769,6 +3807,8 @@ channel_confirm (struct MeshChannel *ch, int fwd)
3769 /* TODO return? */ 3807 /* TODO return? */
3770 } 3808 }
3771 } 3809 }
3810 if (GNUNET_NO == rel->client_ready)
3811 send_local_ack (ch, fwd);
3772} 3812}
3773 3813
3774 3814
@@ -5695,7 +5735,7 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
5695 { 5735 {
5696 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO); 5736 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
5697 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n"); 5737 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
5698 connection_send_ack (c, connection_get_buffer (c, fwd), fwd); 5738 send_ack (c, NULL, fwd);
5699 return GNUNET_OK; 5739 return GNUNET_OK;
5700 } 5740 }
5701 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO); 5741 GNUNET_STATISTICS_update (stats, "# messages forwarded", 1, GNUNET_NO);
@@ -5881,7 +5921,7 @@ handle_mesh_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
5881 pid, fc->last_pid_recv); 5921 pid, fc->last_pid_recv);
5882 fc->last_pid_recv = pid; 5922 fc->last_pid_recv = pid;
5883 fwd = fc == &c->fwd_fc; 5923 fwd = fc == &c->fwd_fc;
5884 connection_send_ack (c, connection_get_buffer(c, fwd), fwd); 5924 send_ack (c, NULL, fwd);
5885 5925
5886 return GNUNET_OK; 5926 return GNUNET_OK;
5887} 5927}