aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/gnunet-service-mesh.c
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-08-09 15:53:34 +0000
committerBart Polot <bart@net.in.tum.de>2012-08-09 15:53:34 +0000
commitb4cff6524c9bb24cac04d748511d995f82e30e81 (patch)
tree8ec5f12b9a2d3b64c595fbe6b6aaa84fc2179274 /src/mesh/gnunet-service-mesh.c
parent199fcee43e61846660fa6c8ef2a03381052d2921 (diff)
downloadgnunet-b4cff6524c9bb24cac04d748511d995f82e30e81.tar.gz
gnunet-b4cff6524c9bb24cac04d748511d995f82e30e81.zip
- refactoring
Diffstat (limited to 'src/mesh/gnunet-service-mesh.c')
-rw-r--r--src/mesh/gnunet-service-mesh.c73
1 files changed, 12 insertions, 61 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 6a2ae46af..4cd0aff8e 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -1705,55 +1705,6 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1705/******************************************************************************/ 1705/******************************************************************************/
1706 1706
1707/** 1707/**
1708 * Check if one pid is bigger than other, accounting for overflow.
1709 *
1710 * @param bigger Argument that should be bigger.
1711 * @param smaller Argument that should be smaller.
1712 *
1713 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
1714 */
1715static int
1716is_pid_bigger (uint32_t bigger, uint32_t smaller)
1717{
1718 return (GNUNET_YES == PID_OVERFLOW(smaller, bigger) ||
1719 (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller)));
1720}
1721
1722/**
1723 * Get the higher ACK value out of two values, taking in account overflow.
1724 *
1725 * @param a First ACK value.
1726 * @param b Second ACK value.
1727 *
1728 * @return Highest ACK value from the two.
1729 */
1730static uint32_t
1731max_pid (uint32_t a, uint32_t b)
1732{
1733 if (is_pid_bigger(a, b))
1734 return a;
1735 return b;
1736}
1737
1738
1739/**
1740 * Get the lower ACK value out of two values, taking in account overflow.
1741 *
1742 * @param a First ACK value.
1743 * @param b Second ACK value.
1744 *
1745 * @return Lowest ACK value from the two.
1746 */
1747static uint32_t
1748min_pid (uint32_t a, uint32_t b)
1749{
1750 if (is_pid_bigger(a, b))
1751 return b;
1752 return a;
1753}
1754
1755
1756/**
1757 * Decrements the reference counter and frees all resources if needed 1708 * Decrements the reference counter and frees all resources if needed
1758 * 1709 *
1759 * @param mesh_data Data Descriptor used in a multicast message. 1710 * @param mesh_data Data Descriptor used in a multicast message.
@@ -3567,7 +3518,7 @@ tunnel_get_children_fwd_ack (struct MeshTunnel *t)
3567 if (0 == ctx.nchildren) 3518 if (0 == ctx.nchildren)
3568 return -1LL; 3519 return -1LL;
3569 3520
3570 if (GNUNET_YES == t->nobuffer && is_pid_bigger(ctx.max_child_ack, t->fwd_pid)) 3521 if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ctx.max_child_ack, t->fwd_pid))
3571 ctx.max_child_ack = t->fwd_pid + 1; // Might overflow, it's ok. 3522 ctx.max_child_ack = t->fwd_pid + 1; // Might overflow, it's ok.
3572 3523
3573 return (int64_t) ctx.max_child_ack; 3524 return (int64_t) ctx.max_child_ack;
@@ -3621,15 +3572,15 @@ tunnel_get_clients_fwd_ack (struct MeshTunnel *t)
3621 { 3572 {
3622 if (-1 == ack || 3573 if (-1 == ack ||
3623 (GNUNET_YES == t->speed_min && 3574 (GNUNET_YES == t->speed_min &&
3624 GNUNET_YES == is_pid_bigger (ack, t->clients_fc[i].fwd_ack)) || 3575 GNUNET_YES == GMC_is_pid_bigger (ack, t->clients_fc[i].fwd_ack)) ||
3625 (GNUNET_NO == t->speed_min && 3576 (GNUNET_NO == t->speed_min &&
3626 GNUNET_YES == is_pid_bigger (t->clients_fc[i].fwd_ack, ack))) 3577 GNUNET_YES == GMC_is_pid_bigger (t->clients_fc[i].fwd_ack, ack)))
3627 { 3578 {
3628 ack = t->clients_fc[i].fwd_ack; 3579 ack = t->clients_fc[i].fwd_ack;
3629 } 3580 }
3630 } 3581 }
3631 3582
3632 if (GNUNET_YES == t->nobuffer && is_pid_bigger(ack, t->fwd_pid)) 3583 if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ack, t->fwd_pid))
3633 ack = (uint32_t) t->fwd_pid + 1; // Might overflow, it's ok. 3584 ack = (uint32_t) t->fwd_pid + 1; // Might overflow, it's ok.
3634 3585
3635 return (uint32_t) ack; 3586 return (uint32_t) ack;
@@ -3667,15 +3618,15 @@ tunnel_get_fwd_ack (struct MeshTunnel *t)
3667 3618
3668 if (GNUNET_YES == t->speed_min) 3619 if (GNUNET_YES == t->speed_min)
3669 { 3620 {
3670 ack = min_pid ((uint32_t) child_ack, ack); 3621 ack = GMC_min_pid ((uint32_t) child_ack, ack);
3671 ack = min_pid ((uint32_t) client_ack, ack); 3622 ack = GMC_min_pid ((uint32_t) client_ack, ack);
3672 } 3623 }
3673 else 3624 else
3674 { 3625 {
3675 ack = max_pid ((uint32_t) child_ack, ack); 3626 ack = GMC_max_pid ((uint32_t) child_ack, ack);
3676 ack = max_pid ((uint32_t) client_ack, ack); 3627 ack = GMC_max_pid ((uint32_t) client_ack, ack);
3677 } 3628 }
3678 if (GNUNET_YES == t->nobuffer && is_pid_bigger(ack, t->fwd_pid)) 3629 if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ack, t->fwd_pid))
3679 ack = t->fwd_pid + 1; // Might overflow 32 bits, it's ok! 3630 ack = t->fwd_pid + 1; // Might overflow 32 bits, it's ok!
3680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "c %u, bf %u, ch %u, cl %u, ACK: %u\n", 3631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "c %u, bf %u, ch %u, cl %u, ACK: %u\n",
3681 count, buffer_free, child_ack, client_ack, ack); 3632 count, buffer_free, child_ack, client_ack, ack);
@@ -3827,7 +3778,7 @@ tunnel_send_child_bck_ack (void *cls,
3827 cinfo = tunnel_get_neighbor_fc (t, &peer); 3778 cinfo = tunnel_get_neighbor_fc (t, &peer);
3828 3779
3829 if (cinfo->bck_ack != cinfo->pid && 3780 if (cinfo->bck_ack != cinfo->pid &&
3830 GNUNET_NO == is_pid_bigger (cinfo->bck_ack, cinfo->pid)) 3781 GNUNET_NO == GMC_is_pid_bigger (cinfo->bck_ack, cinfo->pid))
3831 return; 3782 return;
3832 3783
3833 cinfo->bck_ack++; 3784 cinfo->bck_ack++;
@@ -5069,7 +5020,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5069 } 5020 }
5070 t->skip += (pid - t->fwd_pid) - 1; 5021 t->skip += (pid - t->fwd_pid) - 1;
5071 t->fwd_pid = pid; 5022 t->fwd_pid = pid;
5072 if (is_pid_bigger (pid, t->last_fwd_ack)) 5023 if (GMC_is_pid_bigger (pid, t->last_fwd_ack))
5073 { 5024 {
5074 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO); 5025 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
5075 GNUNET_break_op (0); 5026 GNUNET_break_op (0);
@@ -5104,7 +5055,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5104 GNUNET_CONTAINER_multihashmap_iterate (t->children_fc, 5055 GNUNET_CONTAINER_multihashmap_iterate (t->children_fc,
5105 &tunnel_add_skip, 5056 &tunnel_add_skip,
5106 &neighbor); 5057 &neighbor);
5107 if (is_pid_bigger (pid, cinfo->fwd_ack)) 5058 if (GMC_is_pid_bigger (pid, cinfo->fwd_ack))
5108 { 5059 {
5109 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO); 5060 GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
5110 GNUNET_break_op (0); 5061 GNUNET_break_op (0);