Added TTL and packet ID to multicast packets, to avoid eternal retransmission and...
authorBart Polot <bart@net.in.tum.de>
Thu, 10 Nov 2011 17:45:42 +0000 (17:45 +0000)
committerBart Polot <bart@net.in.tum.de>
Thu, 10 Nov 2011 17:45:42 +0000 (17:45 +0000)
src/mesh/gnunet-service-mesh.c
src/mesh/mesh_protocol.h

index e3a8b3f0e2f968af64671fcf6a816fc1d64c9dc2..26a2b3b54b98cba8cdf3a45eaa348e1b7374337e 100644 (file)
@@ -41,6 +41,7 @@
  * - speed requirement specification (change?) in mesh API -- API call
  * - add ping message
  * - relay corking down to core
+ * - set ttl relative to tree depth
  */
 
 #include "platform.h"
 #define UNACKNOWLEDGED_WAIT     GNUNET_TIME_relative_multiply(\
                                     GNUNET_TIME_UNIT_SECONDS,\
                                     2)
+#define DEFAULT_TTL     64
 
 #define MESH_DEBUG_DHT GNUNET_NO
 
+
+
 /******************************************************************************/
 /************************      DATA STRUCTURES     ****************************/
 /******************************************************************************/
@@ -261,6 +265,11 @@ struct MeshTunnel
      */
   MESH_TunnelNumber local_tid;
 
+    /**
+     * ID of the last multicast packet seen/sent.
+     */
+  uint32_t mid;
+
     /**
      * Last time the tunnel was used
      */
@@ -2012,9 +2021,26 @@ tunnel_send_multicast (struct MeshTunnel *t,
   mdata = GNUNET_malloc (sizeof (struct MeshMulticastData));
   mdata->data_len = ntohs (msg->size);
   mdata->reference_counter = GNUNET_malloc (sizeof (unsigned int));
-  mdata->data = GNUNET_malloc (mdata->data_len);
   mdata->t = t;
+  mdata->data = GNUNET_malloc (mdata->data_len);
   memcpy (mdata->data, msg, mdata->data_len);
+  if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_MESH_MULTICAST)
+  {
+    struct GNUNET_MESH_Multicast *mcast;
+
+    mcast = (struct GNUNET_MESH_Multicast *) mdata->data;
+    mcast->ttl = htonl (ntohl (mcast->ttl) - 1);
+#if MESH_DEBUG
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "MESH:   data packet, ttl: %u\n",
+                ntohl (mcast->ttl));
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "MESH:   not a data packet, no ttl\n");
+#endif
+  }
   if (NULL != t->client)
   {
     mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier));
@@ -2869,6 +2895,23 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
+  if (t->mid == ntohl (msg->mid))
+  {
+    /* FIXME: already seen this packet, log dropping */
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "MESH:  Already seen mid %u, DROPPING!\n",
+                t->mid);
+    return GNUNET_OK;
+  }
+#if MESH_DEBUG
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "MESH:  mid %u not seen yet, forwarding\n",
+                ntohl (msg->mid));
+  }
+#endif
+  t->mid = ntohl (msg->mid);
   tunnel_reset_timeout (t);
 
   /* Transmit to locally interested clients */
@@ -2877,6 +2920,18 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
   {
     send_subscribed_clients (message, &msg[1].header);
   }
+#if MESH_DEBUG
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "MESH:    ttl: %u\n",
+              ntohl (msg->ttl));
+#endif
+  if (ntohl (msg->ttl) == 0)
+  {
+    /* FIXME: ttl is 0, log dropping */
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "MESH:  TTL is 0, DROPPING!\n");
+    return GNUNET_OK;
+  }
   tunnel_send_multicast (t, message);
   return GNUNET_OK;
 }
@@ -4042,6 +4097,8 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
     memcpy (buf, message, ntohs (message->size));
     copy->oid = my_full_id;
     copy->tid = htonl (t->id.tid);
+    copy->ttl = htonl (DEFAULT_TTL);
+    copy->mid = htonl (t->mid + 1);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "MESH:   calling generic handler...\n");
     handle_mesh_data_multicast (client, &my_full_id, &copy->header, NULL, 0);
index 180ba453ffad427c2f0542ba64785c073e1fcae4..b6c7f1b24a9322f0b82698e9cf4c622ab37a2bb3 100644 (file)
@@ -80,6 +80,16 @@ struct GNUNET_MESH_Multicast
      */
   uint32_t tid GNUNET_PACKED;
 
+    /**
+     * Number of hops to live
+     */
+  uint32_t ttl GNUNET_PACKED;
+
+    /**
+     * Unique ID of the packet
+     */
+  uint32_t mid GNUNET_PACKED;
+
     /**
      * OID of the tunnel
      */