aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesh/gnunet-service-mesh.c73
-rw-r--r--src/mesh/mesh.h36
-rw-r--r--src/mesh/mesh_common.c52
3 files changed, 99 insertions, 62 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);
diff --git a/src/mesh/mesh.h b/src/mesh/mesh.h
index f67a25d5f..7a1c59484 100644
--- a/src/mesh/mesh.h
+++ b/src/mesh/mesh.h
@@ -311,6 +311,42 @@ enum MeshPeerState
311 311
312 312
313/** 313/**
314 * Check if one pid is bigger than other, accounting for overflow.
315 *
316 * @param bigger Argument that should be bigger.
317 * @param smaller Argument that should be smaller.
318 *
319 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
320 */
321int
322GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller);
323
324
325/**
326 * Get the higher ACK value out of two values, taking in account overflow.
327 *
328 * @param a First ACK value.
329 * @param b Second ACK value.
330 *
331 * @return Highest ACK value from the two.
332 */
333uint32_t
334GMC_max_pid (uint32_t a, uint32_t b);
335
336
337/**
338 * Get the lower ACK value out of two values, taking in account overflow.
339 *
340 * @param a First ACK value.
341 * @param b Second ACK value.
342 *
343 * @return Lowest ACK value from the two.
344 */
345uint32_t
346GMC_min_pid (uint32_t a, uint32_t b);
347
348
349/**
314 * Convert a message type into a string to help debug 350 * Convert a message type into a string to help debug
315 * Generated with: 351 * Generated with:
316 * FIND: "#define ([^ ]+)[ ]*([0-9]+)" 352 * FIND: "#define ([^ ]+)[ ]*([0-9]+)"
diff --git a/src/mesh/mesh_common.c b/src/mesh/mesh_common.c
index cfc2f00ce..59f370e87 100644
--- a/src/mesh/mesh_common.c
+++ b/src/mesh/mesh_common.c
@@ -19,13 +19,63 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file mesh/mesh.c 22 * @file mesh/mesh_common.c
23 * @brief MESH helper functions 23 * @brief MESH helper functions
24 * @author Bartlomiej Polot 24 * @author Bartlomiej Polot
25 */ 25 */
26 26
27#include "mesh.h" 27#include "mesh.h"
28 28
29
30/**
31 * Check if one pid is bigger than other, accounting for overflow.
32 *
33 * @param bigger Argument that should be bigger.
34 * @param smaller Argument that should be smaller.
35 *
36 * @return True if bigger (arg1) has a higher value than smaller (arg 2).
37 */
38int
39GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
40{
41 return (GNUNET_YES == PID_OVERFLOW(smaller, bigger) ||
42 (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller)));
43}
44
45/**
46 * Get the higher ACK value out of two values, taking in account overflow.
47 *
48 * @param a First ACK value.
49 * @param b Second ACK value.
50 *
51 * @return Highest ACK value from the two.
52 */
53uint32_t
54GMC_max_pid (uint32_t a, uint32_t b)
55{
56 if (GMC_is_pid_bigger(a, b))
57 return a;
58 return b;
59}
60
61
62/**
63 * Get the lower ACK value out of two values, taking in account overflow.
64 *
65 * @param a First ACK value.
66 * @param b Second ACK value.
67 *
68 * @return Lowest ACK value from the two.
69 */
70uint32_t
71GMC_min_pid (uint32_t a, uint32_t b)
72{
73 if (GMC_is_pid_bigger(a, b))
74 return b;
75 return a;
76}
77
78
29#if !defined(GNUNET_CULL_LOGGING) 79#if !defined(GNUNET_CULL_LOGGING)
30const char * 80const char *
31GNUNET_MESH_DEBUG_M2S (uint16_t m) 81GNUNET_MESH_DEBUG_M2S (uint16_t m)