From b2db84d189c458659516b9ce42529e1b67d09a51 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Thu, 10 Nov 2011 17:45:42 +0000 Subject: [PATCH] Added TTL and packet ID to multicast packets, to avoid eternal retransmission and packet duplication on trees with loops/mutliple paths respectively. --- src/mesh/gnunet-service-mesh.c | 59 +++++++++++++++++++++++++++++++++- src/mesh/mesh_protocol.h | 10 ++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index e3a8b3f0e..26a2b3b54 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -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" @@ -68,9 +69,12 @@ #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, ©->header, NULL, 0); diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 180ba453f..b6c7f1b24 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -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 */ -- 2.25.1