- ack function
authorBart Polot <bart@net.in.tum.de>
Mon, 23 Jul 2012 18:11:06 +0000 (18:11 +0000)
committerBart Polot <bart@net.in.tum.de>
Mon, 23 Jul 2012 18:11:06 +0000 (18:11 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/mesh_protocol.h

index 069893f1370dd4d814036501f985397672e45d5a..dc9dfdb110fc1d4a15d4c2d99a7c3ded6a436f7b 100644 (file)
@@ -2892,6 +2892,7 @@ tunnel_send_multicast_iterator (void *cls, GNUNET_PEER_Id neighbor_id)
             mdata->t);
 }
 
+
 /**
  * Send a message in a tunnel in multicast, sending a copy to each child node
  * down the local one in the tunnel tree.
@@ -2959,6 +2960,33 @@ tunnel_send_multicast (struct MeshTunnel *t,
 }
 
 
+/**
+ * Send an ACK informing the predecessor about the available buffer space.
+ * 
+ * @param t Tunnel on which to send the ACK.
+ */
+static void
+tunnel_send_ack (struct MeshTunnel *t)
+{
+  struct GNUNET_MESH_ACK msg;
+  struct GNUNET_PeerIdentity id;
+  uint32_t count;
+  uint32_t buffer_free;
+
+  msg.header.size = htons (sizeof (msg));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_ACK);
+  msg.tid = htonl (t->id.tid);
+  GNUNET_PEER_resolve(t->id.oid, &msg.oid);
+  count = t->pid - t->skip;
+  buffer_free = t->queue_max - t->queue_n;
+  msg.pid = htonl (count + buffer_free);
+
+  GNUNET_PEER_resolve (tree_get_predecessor (t->tree), &id);
+
+  send_message (&msg.header, &id, t);
+}
+
+
 /**
  * Send a message to all peers in this tunnel that the tunnel is no longer
  * valid.
@@ -2977,6 +3005,7 @@ tunnel_send_destroy (struct MeshTunnel *t)
   tunnel_send_multicast (t, &msg.header, GNUNET_NO);
 }
 
+
 /**
  * Cancel all transmissions towards a neighbor that belong to a certain tunnel.
  *
@@ -3487,16 +3516,21 @@ queue_send (void *cls, size_t size, void *buf)
     }
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*********   size ok\n");
 
+    t = queue->tunnel;
+    t->queue_n--;
+
     /* Fill buf */
     switch (queue->type)
     {
         case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*********   unicast\n");
             data_size = send_core_data_raw (queue->cls, size, buf);
+            // tunnel_send_ack (t); FIXME: might be not real unicast!
             break;
         case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*********   multicast\n");
             data_size = send_core_data_multicast(queue->cls, size, buf);
+            tunnel_send_ack (t); // FIXME max speed behavior. implement min!!
             break;
         case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
             GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*********   path create\n");
@@ -3512,9 +3546,6 @@ queue_send (void *cls, size_t size, void *buf)
             data_size = 0;
     }
 
-    t = queue->tunnel;
-    t->queue_n--;
-
     /* Free queue, but cls was freed by send_core_* */
     queue_destroy(queue, GNUNET_NO);
 
@@ -4025,6 +4056,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
                 "  it's for us! sending to clients...\n");
     GNUNET_STATISTICS_update (stats, "# unicast received", 1, GNUNET_NO);
     send_subscribed_clients (message, (struct GNUNET_MessageHeader *) &msg[1]);
+    tunnel_send_ack (t); // FIXME send after client processes the packet
     return GNUNET_OK;
   }
   ttl = ntohl (msg->ttl);
index 37f2ffb72dbd72faf33375c2f9d152fc0fdc49d0..c21d101100d974000483b2b4dba10fde4df6dde7 100644 (file)
@@ -210,13 +210,10 @@ struct GNUNET_MESH_ACK
   struct GNUNET_PeerIdentity oid;
 
     /**
-     * Sender of the message.
+     * Maximum packet ID authorized.
      */
-  struct GNUNET_PeerIdentity sender;
+  uint32_t pid;
 
-    /**
-     * Payload follows
-     */
 };
 
 /**