aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-11-10 17:45:42 +0000
committerBart Polot <bart@net.in.tum.de>2011-11-10 17:45:42 +0000
commitb2db84d189c458659516b9ce42529e1b67d09a51 (patch)
tree92170c690a2d5a7ecaef0c5917b9b41af338a60a /src/mesh
parent761771af0bfe60b1859b44efc4b526be8f5da8ed (diff)
downloadgnunet-b2db84d189c458659516b9ce42529e1b67d09a51.tar.gz
gnunet-b2db84d189c458659516b9ce42529e1b67d09a51.zip
Added TTL and packet ID to multicast packets, to avoid eternal retransmission and packet duplication on trees with loops/mutliple paths respectively.
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c59
-rw-r--r--src/mesh/mesh_protocol.h10
2 files changed, 68 insertions, 1 deletions
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 @@
41 * - speed requirement specification (change?) in mesh API -- API call 41 * - speed requirement specification (change?) in mesh API -- API call
42 * - add ping message 42 * - add ping message
43 * - relay corking down to core 43 * - relay corking down to core
44 * - set ttl relative to tree depth
44 */ 45 */
45 46
46#include "platform.h" 47#include "platform.h"
@@ -68,9 +69,12 @@
68#define UNACKNOWLEDGED_WAIT GNUNET_TIME_relative_multiply(\ 69#define UNACKNOWLEDGED_WAIT GNUNET_TIME_relative_multiply(\
69 GNUNET_TIME_UNIT_SECONDS,\ 70 GNUNET_TIME_UNIT_SECONDS,\
70 2) 71 2)
72#define DEFAULT_TTL 64
71 73
72#define MESH_DEBUG_DHT GNUNET_NO 74#define MESH_DEBUG_DHT GNUNET_NO
73 75
76
77
74/******************************************************************************/ 78/******************************************************************************/
75/************************ DATA STRUCTURES ****************************/ 79/************************ DATA STRUCTURES ****************************/
76/******************************************************************************/ 80/******************************************************************************/
@@ -262,6 +266,11 @@ struct MeshTunnel
262 MESH_TunnelNumber local_tid; 266 MESH_TunnelNumber local_tid;
263 267
264 /** 268 /**
269 * ID of the last multicast packet seen/sent.
270 */
271 uint32_t mid;
272
273 /**
265 * Last time the tunnel was used 274 * Last time the tunnel was used
266 */ 275 */
267 struct GNUNET_TIME_Absolute timestamp; 276 struct GNUNET_TIME_Absolute timestamp;
@@ -2012,9 +2021,26 @@ tunnel_send_multicast (struct MeshTunnel *t,
2012 mdata = GNUNET_malloc (sizeof (struct MeshMulticastData)); 2021 mdata = GNUNET_malloc (sizeof (struct MeshMulticastData));
2013 mdata->data_len = ntohs (msg->size); 2022 mdata->data_len = ntohs (msg->size);
2014 mdata->reference_counter = GNUNET_malloc (sizeof (unsigned int)); 2023 mdata->reference_counter = GNUNET_malloc (sizeof (unsigned int));
2015 mdata->data = GNUNET_malloc (mdata->data_len);
2016 mdata->t = t; 2024 mdata->t = t;
2025 mdata->data = GNUNET_malloc (mdata->data_len);
2017 memcpy (mdata->data, msg, mdata->data_len); 2026 memcpy (mdata->data, msg, mdata->data_len);
2027 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_MESH_MULTICAST)
2028 {
2029 struct GNUNET_MESH_Multicast *mcast;
2030
2031 mcast = (struct GNUNET_MESH_Multicast *) mdata->data;
2032 mcast->ttl = htonl (ntohl (mcast->ttl) - 1);
2033#if MESH_DEBUG
2034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2035 "MESH: data packet, ttl: %u\n",
2036 ntohl (mcast->ttl));
2037 }
2038 else
2039 {
2040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2041 "MESH: not a data packet, no ttl\n");
2042#endif
2043 }
2018 if (NULL != t->client) 2044 if (NULL != t->client)
2019 { 2045 {
2020 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier)); 2046 mdata->task = GNUNET_malloc (sizeof (GNUNET_SCHEDULER_TaskIdentifier));
@@ -2869,6 +2895,23 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2869 GNUNET_break_op (0); 2895 GNUNET_break_op (0);
2870 return GNUNET_OK; 2896 return GNUNET_OK;
2871 } 2897 }
2898 if (t->mid == ntohl (msg->mid))
2899 {
2900 /* FIXME: already seen this packet, log dropping */
2901 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2902 "MESH: Already seen mid %u, DROPPING!\n",
2903 t->mid);
2904 return GNUNET_OK;
2905 }
2906#if MESH_DEBUG
2907 else
2908 {
2909 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2910 "MESH: mid %u not seen yet, forwarding\n",
2911 ntohl (msg->mid));
2912 }
2913#endif
2914 t->mid = ntohl (msg->mid);
2872 tunnel_reset_timeout (t); 2915 tunnel_reset_timeout (t);
2873 2916
2874 /* Transmit to locally interested clients */ 2917 /* Transmit to locally interested clients */
@@ -2877,6 +2920,18 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
2877 { 2920 {
2878 send_subscribed_clients (message, &msg[1].header); 2921 send_subscribed_clients (message, &msg[1].header);
2879 } 2922 }
2923#if MESH_DEBUG
2924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2925 "MESH: ttl: %u\n",
2926 ntohl (msg->ttl));
2927#endif
2928 if (ntohl (msg->ttl) == 0)
2929 {
2930 /* FIXME: ttl is 0, log dropping */
2931 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2932 "MESH: TTL is 0, DROPPING!\n");
2933 return GNUNET_OK;
2934 }
2880 tunnel_send_multicast (t, message); 2935 tunnel_send_multicast (t, message);
2881 return GNUNET_OK; 2936 return GNUNET_OK;
2882} 2937}
@@ -4042,6 +4097,8 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
4042 memcpy (buf, message, ntohs (message->size)); 4097 memcpy (buf, message, ntohs (message->size));
4043 copy->oid = my_full_id; 4098 copy->oid = my_full_id;
4044 copy->tid = htonl (t->id.tid); 4099 copy->tid = htonl (t->id.tid);
4100 copy->ttl = htonl (DEFAULT_TTL);
4101 copy->mid = htonl (t->mid + 1);
4045 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4046 "MESH: calling generic handler...\n"); 4103 "MESH: calling generic handler...\n");
4047 handle_mesh_data_multicast (client, &my_full_id, &copy->header, NULL, 0); 4104 handle_mesh_data_multicast (client, &my_full_id, &copy->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
@@ -81,6 +81,16 @@ struct GNUNET_MESH_Multicast
81 uint32_t tid GNUNET_PACKED; 81 uint32_t tid GNUNET_PACKED;
82 82
83 /** 83 /**
84 * Number of hops to live
85 */
86 uint32_t ttl GNUNET_PACKED;
87
88 /**
89 * Unique ID of the packet
90 */
91 uint32_t mid GNUNET_PACKED;
92
93 /**
84 * OID of the tunnel 94 * OID of the tunnel
85 */ 95 */
86 struct GNUNET_PeerIdentity oid; 96 struct GNUNET_PeerIdentity oid;