- fixes, eliminate malformed data assert
[oweals/gnunet.git] / src / mesh / mesh_common.c
index cfc2f00cec4b4185cf68ac31097e9bc475f1c9d4..59f370e87f96ff40badccb87f8ef7c62eb69fd37 100644 (file)
 */
 
 /**
- * @file mesh/mesh.c
+ * @file mesh/mesh_common.c
  * @brief MESH helper functions
  * @author Bartlomiej Polot
  */
 
 #include "mesh.h"
 
+
+/**
+ * Check if one pid is bigger than other, accounting for overflow.
+ *
+ * @param bigger Argument that should be bigger.
+ * @param smaller Argument that should be smaller.
+ *
+ * @return True if bigger (arg1) has a higher value than smaller (arg 2).
+ */
+int
+GMC_is_pid_bigger (uint32_t bigger, uint32_t smaller)
+{
+    return (GNUNET_YES == PID_OVERFLOW(smaller, bigger) ||
+            (bigger > smaller && GNUNET_NO == PID_OVERFLOW(bigger, smaller)));
+}
+
+/**
+ * Get the higher ACK value out of two values, taking in account overflow.
+ *
+ * @param a First ACK value.
+ * @param b Second ACK value.
+ *
+ * @return Highest ACK value from the two.
+ */
+uint32_t
+GMC_max_pid (uint32_t a, uint32_t b)
+{
+  if (GMC_is_pid_bigger(a, b))
+    return a;
+  return b;
+}
+
+
+/**
+ * Get the lower ACK value out of two values, taking in account overflow.
+ *
+ * @param a First ACK value.
+ * @param b Second ACK value.
+ *
+ * @return Lowest ACK value from the two.
+ */
+uint32_t
+GMC_min_pid (uint32_t a, uint32_t b)
+{
+  if (GMC_is_pid_bigger(a, b))
+    return b;
+  return a;
+}
+
+
 #if !defined(GNUNET_CULL_LOGGING)
 const char *
 GNUNET_MESH_DEBUG_M2S (uint16_t m)