-only notify AFTER sending is really close to finished, not before
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_local.c
index b310c39dd90397223297aaa15b377270ad5b5e36..eab222481351d5bfb05dbb7ca05d116202c5a35a 100644 (file)
@@ -24,8 +24,8 @@
 
 #include "gnunet_statistics_service.h"
 
-#include "mesh_enc.h"
-#include "mesh_protocol_enc.h" // GNUNET_MESH_Data is shared
+#include "mesh.h"
+#include "mesh_protocol.h" /* GNUNET_MESH_Data is shared */
 
 #include "gnunet-service-mesh_local.h"
 
@@ -573,7 +573,7 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
  * @param key Key (hashed tunnel ID, unused).
  * @param value Tunnel info.
  *
- * @return GNUNET_YES, to keep iterating.
+ * @return #GNUNET_YES, to keep iterating.
  */
 // static int
 // monitor_all_tunnels_iterator (void *cls,
@@ -813,7 +813,7 @@ GML_channel_add (struct MeshClient *client,
 
 
 /**
- * Remove a channel from a client
+ * Remove a channel from a client.
  *
  * @param client Client.
  * @param chid Channel ID.
@@ -825,9 +825,13 @@ GML_channel_remove (struct MeshClient *client,
                     struct MeshChannel *ch)
 {
   if (GNUNET_MESH_LOCAL_CHANNEL_ID_SERV <= chid)
-    GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels, chid, ch);
+    GNUNET_break (GNUNET_YES ==
+                  GNUNET_CONTAINER_multihashmap32_remove (client->incoming_channels,
+                                                          chid, ch));
   else if (GNUNET_MESH_LOCAL_CHANNEL_ID_CLI <= chid)
-    GNUNET_CONTAINER_multihashmap32_remove (client->own_channels, chid, ch);
+    GNUNET_break (GNUNET_YES ==
+                  GNUNET_CONTAINER_multihashmap32_remove (client->own_channels,
+                                                          chid, ch));
   else
     GNUNET_break (0);
 }
@@ -946,6 +950,32 @@ GML_send_ack (struct MeshClient *c, MESH_ChannelNumber id)
 }
 
 
+/**
+ * Build a local channel NACK message and send it to a local client.
+ *
+ * @param c Client to whom send the NACK.
+ * @param id Channel ID to use
+ */
+void
+GML_send_nack (struct MeshClient *c, MESH_ChannelNumber id)
+{
+  struct GNUNET_MESH_LocalAck msg;
+
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+              "send local nack on %X towards %p\n",
+              id, c);
+
+  msg.header.size = htons (sizeof (msg));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK);
+  msg.channel_id = htonl (id);
+  GNUNET_SERVER_notification_context_unicast (nc,
+                                              c->handle,
+                                              &msg.header,
+                                              GNUNET_NO);
+
+}
+
+
 /**
  * Notify the client that a new incoming channel was created.
  *