- more debug, fixes
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh.c
index 6a2ae46afe7172fbf65d7c7f0b2170b1d0293f47..d2a1c93fbe49daf4b64b0e82f97cbe6835b63562 100644 (file)
@@ -1704,55 +1704,6 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 /******************      GENERAL HELPER FUNCTIONS      ************************/
 /******************************************************************************/
 
-/**
- * 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).
- */
-static int
-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.
- */
-static uint32_t
-max_pid (uint32_t a, uint32_t b)
-{
-  if (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.
- */
-static uint32_t
-min_pid (uint32_t a, uint32_t b)
-{
-  if (is_pid_bigger(a, b))
-    return b;
-  return a;
-}
-
-
 /**
  * Decrements the reference counter and frees all resources if needed
  *
@@ -2089,7 +2040,7 @@ send_client_peer_connected (const struct MeshTunnel *t, const GNUNET_PEER_Id id)
 
 
 /**
- * Notify a the client of a tunnel about how many more
+ * Notify a client of a tunnel about how many more
  * payload packages will we accept on a given tunnel,
  * distinguishing between root and leaf clients.
  *
@@ -3567,7 +3518,7 @@ tunnel_get_children_fwd_ack (struct MeshTunnel *t)
   if (0 == ctx.nchildren)
     return -1LL;
 
-  if (GNUNET_YES == t->nobuffer && is_pid_bigger(ctx.max_child_ack, t->fwd_pid))
+  if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ctx.max_child_ack, t->fwd_pid))
     ctx.max_child_ack = t->fwd_pid + 1; // Might overflow, it's ok.
 
   return (int64_t) ctx.max_child_ack;
@@ -3621,15 +3572,15 @@ tunnel_get_clients_fwd_ack (struct MeshTunnel *t)
   {
     if (-1 == ack ||
         (GNUNET_YES == t->speed_min &&
-         GNUNET_YES == is_pid_bigger (ack, t->clients_fc[i].fwd_ack)) ||
+         GNUNET_YES == GMC_is_pid_bigger (ack, t->clients_fc[i].fwd_ack)) ||
         (GNUNET_NO == t->speed_min &&
-         GNUNET_YES == is_pid_bigger (t->clients_fc[i].fwd_ack, ack)))
+         GNUNET_YES == GMC_is_pid_bigger (t->clients_fc[i].fwd_ack, ack)))
     {
       ack = t->clients_fc[i].fwd_ack;
     }
   }
 
-  if (GNUNET_YES == t->nobuffer && is_pid_bigger(ack, t->fwd_pid))
+  if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ack, t->fwd_pid))
     ack = (uint32_t) t->fwd_pid + 1; // Might overflow, it's ok.
 
   return (uint32_t) ack;
@@ -3661,21 +3612,21 @@ tunnel_get_fwd_ack (struct MeshTunnel *t)
   if (-1 == child_ack)
   {
     // Node has no children, child_ack AND core buffer are irrelevant.
-    GNUNET_break (-1 != client_ack); // No children AND no clients? Not good!
+    GNUNET_break (-1 != client_ack); // No children AND no clients? Not good! // FIXME fc
     return (uint32_t) client_ack;
   }
 
   if (GNUNET_YES == t->speed_min)
   {
-    ack = min_pid ((uint32_t) child_ack, ack);
-    ack = min_pid ((uint32_t) client_ack, ack);
+    ack = GMC_min_pid ((uint32_t) child_ack, ack);
+    ack = GMC_min_pid ((uint32_t) client_ack, ack);
   }
   else
   {
-    ack = max_pid ((uint32_t) child_ack, ack);
-    ack = max_pid ((uint32_t) client_ack, ack);
+    ack = GMC_max_pid ((uint32_t) child_ack, ack);
+    ack = GMC_max_pid ((uint32_t) client_ack, ack);
   }
-  if (GNUNET_YES == t->nobuffer && is_pid_bigger(ack, t->fwd_pid))
+  if (GNUNET_YES == t->nobuffer && GMC_is_pid_bigger(ack, t->fwd_pid))
     ack = t->fwd_pid + 1; // Might overflow 32 bits, it's ok!
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "c %u, bf %u, ch %u, cl %u, ACK: %u\n",
               count, buffer_free, child_ack, client_ack, ack);
@@ -3827,7 +3778,7 @@ tunnel_send_child_bck_ack (void *cls,
   cinfo = tunnel_get_neighbor_fc (t, &peer);
 
   if (cinfo->bck_ack != cinfo->pid &&
-      GNUNET_NO == is_pid_bigger (cinfo->bck_ack, cinfo->pid))
+      GNUNET_NO == GMC_is_pid_bigger (cinfo->bck_ack, cinfo->pid))
     return;
 
   cinfo->bck_ack++;
@@ -3863,6 +3814,9 @@ tunnel_send_clients_bck_ack (struct MeshTunnel *t)
 
       ack = clinfo->bck_pid;
       ack += t->nobuffer ? 1 : INITIAL_WINDOW_SIZE;
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "  sending ack to client %u: %u\n",
+                  t->clients[i]->id, ack);
       send_local_ack(t->clients[i],  t, ack);
       clinfo->bck_ack = ack;
     }
@@ -3884,11 +3838,9 @@ tunnel_send_clients_bck_ack (struct MeshTunnel *t)
 static void
 tunnel_send_bck_ack (struct MeshTunnel *t, uint16_t type)
 {
-  if (NULL != t->owner)
-  {
-    send_client_tunnel_ack (t->owner, t);
-    return;
-  }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Sending BCK ACK on tunnel %u [%u]\n",
+              t->id.oid, t->id.tid);
   /* Is it after data to_origin retransmission? */
   switch (type)
   {
@@ -3902,12 +3854,13 @@ tunnel_send_bck_ack (struct MeshTunnel *t, uint16_t type)
       }
       if (t->bck_queue_max > t->bck_queue_n * 2)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n");
-        return;
+//         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n");
+//         return;
       }
       break;
     case GNUNET_MESSAGE_TYPE_MESH_ACK:
     case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
+      // FIXME fc
       break;
     default:
       GNUNET_break (0);
@@ -5069,7 +5022,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
   }
   t->skip += (pid - t->fwd_pid) - 1;
   t->fwd_pid = pid;
-  if (is_pid_bigger (pid, t->last_fwd_ack))
+  if (GMC_is_pid_bigger (pid, t->last_fwd_ack))
   {
     GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
     GNUNET_break_op (0);
@@ -5104,7 +5057,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
   GNUNET_CONTAINER_multihashmap_iterate (t->children_fc,
                                          &tunnel_add_skip,
                                          &neighbor);
-  if (is_pid_bigger (pid, cinfo->fwd_ack))
+  if (GMC_is_pid_bigger (pid, cinfo->fwd_ack))
   {
     GNUNET_STATISTICS_update (stats, "# unsolicited unicast", 1, GNUNET_NO);
     GNUNET_break_op (0);
@@ -7110,7 +7063,7 @@ handle_local_ack (void *cls, struct GNUNET_SERVER_Client *client,
   t = tunnel_get_by_local_id (c, tid);
   if (NULL == t)
   {
-    GNUNET_break (0);
+    GNUNET_break (0); // FIXME fc
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
@@ -7201,13 +7154,16 @@ static void
 core_init (void *cls, struct GNUNET_CORE_Handle *server,
            const struct GNUNET_PeerIdentity *identity)
 {
+  static int i = 0;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core init\n");
   core_handle = server;
   if (0 != memcmp (identity, &my_full_id, sizeof (my_full_id)) ||
       NULL == server)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Wrong CORE service\n"));
-    GNUNET_SCHEDULER_shutdown ();
+    GNUNET_SCHEDULER_shutdown (); // Try gracefully
+    if (10 < i++)
+      GNUNET_abort(); // Try harder
   }
   return;
 }