Improved debug message
[oweals/gnunet.git] / src / mesh / mesh_api.c
index 35bbab3a1a7d83716ed77af8cd072d9bd867884f..bfb9875cfb8835be96b99c4bc880122d0e71f208 100644 (file)
@@ -368,8 +368,10 @@ create_tunnel (struct GNUNET_MESH_Handle *h, MESH_TunnelNumber tid)
  * - Cancels all outgoing traffic for that tunnel, calling respective notifys
  * - Calls cleaner if tunnel was inbound
  * - Frees all memory used
- * @param tid ID of the wanted tunnel
- * @return handle to the required tunnel or NULL if not found
+ *
+ * @param t Pointer to the tunnel.
+ *
+ * @return Handle to the required tunnel or NULL if not found.
  */
 static void
 destroy_tunnel (struct GNUNET_MESH_Tunnel *t)
@@ -757,7 +759,6 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
                         const struct GNUNET_MESH_TunnelNotification *msg)
 {
   struct GNUNET_MESH_Tunnel *t;
-  struct GNUNET_ATS_Information atsi;
   MESH_TunnelNumber tid;
 
   tid = ntohl (msg->tunnel_id);
@@ -778,10 +779,16 @@ process_tunnel_created (struct GNUNET_MESH_Handle *h,
   t->tid = tid;
   if (NULL != h->new_tunnel)
   {
+    struct GNUNET_ATS_Information atsi;
+
     atsi.type = 0;
     atsi.value = 0;
     t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
   }
+#if MESH_API_DEBUG
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: new incoming tunnel %X\n",
+              t->tid);
+#endif
   return;
 }
 
@@ -810,7 +817,9 @@ process_tunnel_destroy (struct GNUNET_MESH_Handle *h,
   {
     GNUNET_break (0);
   }
-
+#if MESH_API_DEBUG
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %u destroyed\n", t->tid);
+#endif
   destroy_tunnel (t);
   return;
 }
@@ -909,6 +918,13 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
   case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
     mcast = (struct GNUNET_MESH_Multicast *) message;
     t = retrieve_tunnel (h, ntohl (mcast->tid));
+#if MESH_API_DEBUG // FIXME debug for #2071
+    if (NULL == t)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "mesh: tunnel %u unknown\n",
+                  ntohl (mcast->tid));
+    }
+#endif
     payload = (struct GNUNET_MessageHeader *) &mcast[1];
     peer = &mcast->oid;
     break;
@@ -1084,6 +1100,8 @@ send_callback (void *cls, size_t size, void *buf)
           mc.header.size = htons (psize);
           mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
           mc.tid = htonl (th->tunnel->tid);
+          mc.mid = 0;
+          mc.ttl = 0;
           memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
           memcpy (cbuf, &mc, sizeof (mc));
         }
@@ -1119,6 +1137,11 @@ send_callback (void *cls, size_t size, void *buf)
     }
     if (th->timeout_task != GNUNET_SCHEDULER_NO_TASK)
       GNUNET_SCHEDULER_cancel (th->timeout_task);
+    if (NULL != th->tunnel)
+    {
+      th->tunnel->mesh->npackets--;
+      th->tunnel->npackets--;
+    }
     GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
     GNUNET_free (th);
     cbuf += psize;
@@ -1303,7 +1326,7 @@ GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
 /**
  * Destroy an existing tunnel.
  *
- * @param tun tunnel handle
+ * @param tunnel tunnel handle
  */
 void
 GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
@@ -1470,6 +1493,7 @@ GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
   uint32_t least_priority;
   size_t overhead;
 
+  GNUNET_assert (NULL != tunnel);
 #if MESH_API_DEBUG
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "mesh: mesh notify transmit ready called\n");