-only notify AFTER sending is really close to finished, not before
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_local.c
index 0fe98f44816c84b20f525f4ea7bfa55282e64cdd..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"
 
@@ -179,6 +179,7 @@ handle_client_connect (void *cls, struct GNUNET_SERVER_Client *client)
 {
   struct MeshClient *c;
 
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "client connected: %p\n", client);
   if (NULL == client)
     return;
   c = GNUNET_new (struct MeshClient);
@@ -554,8 +555,8 @@ handle_ack (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
 
-  /* If client is root, the ACK is going FWD, therefore this is "BCK". */
-  /* If client is dest, the ACK is going BCK, therefore this is "FWD" */
+  /* If client is root, the ACK is going FWD, therefore this is "BCK ACK". */
+  /* If client is dest, the ACK is going BCK, therefore this is "FWD ACK" */
   fwd = chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV;
 
   GMCH_handle_local_ack (ch, fwd);
@@ -572,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,
@@ -725,6 +726,7 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
 void
 GML_init (struct GNUNET_SERVER_Handle *handle)
 {
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "init\n");
   server_handle = handle;
   GNUNET_SERVER_suspend (server_handle);
   ports = GNUNET_CONTAINER_multihashmap32_create (32);
@@ -765,10 +767,10 @@ GML_shutdown (void)
 
 
 /**
- * Get a chennel from a client
+ * Get a channel from a client.
  *
- * @param c the client to check
- * @param chid Channel ID, must be local (> 0x800...)
+ * @param c Client to check.
+ * @param chid Channel ID, must be local (> 0x800...).
  *
  * @return non-NULL if channel exists in the clients lists
  */
@@ -811,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.
@@ -823,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);
 }
@@ -944,10 +950,40 @@ 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.
  *
- * @param ch Channel that was created.
+ * @param c Client to notify.
+ * @param id Channel ID.
+ * @param port Channel's destination port.
+ * @param opt Options (bit array).
+ * @param peer Origin peer.
  */
 void
 GML_send_channel_create (struct MeshClient *c,