From 7d8b54629029a4b7aea43db6af4cfaf188c856b8 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Fri, 20 Jul 2012 17:46:04 +0000 Subject: [PATCH] - add packet ID to both multicast and unicast --- src/mesh/gnunet-service-mesh.c | 100 +++++++++++++++++++++++++++++---- src/mesh/mesh_api.c | 2 +- src/mesh/mesh_protocol.h | 12 +++- 3 files changed, 100 insertions(+), 14 deletions(-) diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 496520125..8d4f70e34 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -310,11 +310,6 @@ struct MeshTunnel */ MESH_TunnelNumber local_tid_dest; - /** - * Global count ID of the last *multicast* packet seen/sent. - */ - uint32_t mid; - /** * Local count ID of the last packet seen/sent. */ @@ -3986,6 +3981,21 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break_op (0); return GNUNET_OK; } + pid = ntohl (msg->pid); + if (t->pid == pid) + { + /* FIXME: already seen this packet, log dropping */ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + " Already seen mid %u, DROPPING!\n", pid); + return GNUNET_OK; + } + else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + " mid %u not seen yet, forwarding\n", pid); + } + t->skip += (pid - t->pid) - 1; + t->pid = pid; tunnel_reset_timeout (t); pid = GNUNET_PEER_search (&msg->destination); if (pid == myid) @@ -4024,6 +4034,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MESH_Multicast *msg; struct MeshTunnel *t; size_t size; + uint32_t pid; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a multicast packet from %s\n", GNUNET_i2s (peer)); @@ -4043,19 +4054,21 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, GNUNET_break_op (0); return GNUNET_OK; } - if (t->mid == ntohl (msg->mid)) + pid = ntohl (msg->pid); + if (t->pid == pid) { /* FIXME: already seen this packet, log dropping */ GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - " Already seen mid %u, DROPPING!\n", t->mid); + " Already seen mid %u, DROPPING!\n", pid); return GNUNET_OK; } else { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - " mid %u not seen yet, forwarding\n", ntohl (msg->mid)); + " mid %u not seen yet, forwarding\n", pid); } - t->mid = ntohl (msg->mid); + t->skip += (pid - t->pid) - 1; + t->pid = pid; tunnel_reset_timeout (t); /* Transmit to locally interested clients */ @@ -4376,8 +4389,8 @@ path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) msg->oid = my_full_id; msg->tid = htonl (t->id.tid); msg->ttl = htonl (DEFAULT_TTL); - msg->mid = htonl (t->mid + 1); - t->mid++; + msg->pid = htonl (t->pid + 1); + t->pid++; payload = (struct GNUNET_MessageHeader *) &msg[1]; payload->size = htons (sizeof (struct GNUNET_MessageHeader)); payload->type = htons (GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE); @@ -5103,6 +5116,61 @@ handle_local_tunnel_speed (void *cls, struct GNUNET_SERVER_Client *client, } +/** + * Handler for requests of seeting tunnel's buffering policy. + * + * @param cls Closure (unused). + * @param client Identification of the client. + * @param message The actual message. + */ +static void +handle_local_tunnel_buffer (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + struct GNUNET_MESH_TunnelMessage *tunnel_msg; + struct MeshClient *c; + struct MeshTunnel *t; + MESH_TunnelNumber tid; + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got a BUFFER request from client!\n"); + + /* Sanity check for client registration */ + if (NULL == (c = client_get (client))) + { + GNUNET_break (0); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id); + tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; + + /* Retrieve tunnel */ + tid = ntohl (tunnel_msg->tunnel_id); + t = tunnel_get_by_local_id(c, tid); + if (NULL == t) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, " tunnel %X not found\n", tid); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + + switch (ntohs(message->type)) + { + case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER: + t->buffering = GNUNET_YES; + break; + case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER: + t->buffering = GNUNET_NO; + break; + default: + GNUNET_break (0); + } +} + + /** * Handler for connection requests to new peers * @@ -5671,6 +5739,8 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, memcpy (buf, data_msg, size); copy->oid = my_full_id; copy->tid = htonl (t->id.tid); + copy->ttl = htonl (DEFAULT_TTL); + copy->pid = htonl (t->pid + 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " calling generic handler...\n"); handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL, 0); @@ -5828,7 +5898,7 @@ handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client, copy->oid = my_full_id; copy->tid = htonl (t->id.tid); copy->ttl = htonl (DEFAULT_TTL); - copy->mid = htonl (t->mid + 1); + copy->pid = htonl (t->pid + 1); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " calling generic handler...\n"); handle_mesh_data_multicast (client, &my_full_id, ©->header, NULL, 0); @@ -5858,6 +5928,12 @@ static struct GNUNET_SERVER_MessageHandler client_handlers[] = { {&handle_local_tunnel_speed, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX, sizeof (struct GNUNET_MESH_TunnelMessage)}, + {&handle_local_tunnel_buffer, NULL, + GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER, + sizeof (struct GNUNET_MESH_TunnelMessage)}, + {&handle_local_tunnel_buffer, NULL, + GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER, + sizeof (struct GNUNET_MESH_TunnelMessage)}, {&handle_local_connect_add, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD, sizeof (struct GNUNET_MESH_PeerControl)}, diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 052f1c865..da88e4307 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c @@ -1152,7 +1152,7 @@ send_callback (void *cls, size_t size, void *buf) mc.header.size = htons (psize); mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); mc.tid = htonl (th->tunnel->tid); - mc.mid = 0; + mc.pid = 0; mc.ttl = 0; memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); memcpy (cbuf, &mc, sizeof (mc)); diff --git a/src/mesh/mesh_protocol.h b/src/mesh/mesh_protocol.h index 033276e25..f01cb7d98 100644 --- a/src/mesh/mesh_protocol.h +++ b/src/mesh/mesh_protocol.h @@ -90,7 +90,7 @@ struct GNUNET_MESH_Multicast /** * Unique ID of the packet */ - uint32_t mid GNUNET_PACKED; + uint32_t pid GNUNET_PACKED; /** * OID of the tunnel @@ -118,6 +118,16 @@ struct GNUNET_MESH_Unicast */ uint32_t tid GNUNET_PACKED; + /** + * Number of hops to live + */ + uint32_t ttl GNUNET_PACKED; + + /** + * Unique ID of the packet + */ + uint32_t pid GNUNET_PACKED; + /** * OID of the tunnel */ -- 2.25.1