gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r27739 - in gnunet/src: include mesh


From: gnunet
Subject: [GNUnet-SVN] r27739 - in gnunet/src: include mesh
Date: Wed, 3 Jul 2013 19:04:57 +0200

Author: bartpolot
Date: 2013-07-03 19:04:57 +0200 (Wed, 03 Jul 2013)
New Revision: 27739

Modified:
   gnunet/src/include/gnunet_mesh_service.h
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api.c
Log:
- prepare for relaible mesh

Modified: gnunet/src/include/gnunet_mesh_service.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service.h    2013-07-03 17:04:35 UTC (rev 
27738)
+++ gnunet/src/include/gnunet_mesh_service.h    2013-07-03 17:04:57 UTC (rev 
27739)
@@ -229,6 +229,20 @@
 
 
 /**
+ * Turn on/off the reliability of the tunnel.
+ * 
+ * If reliability is on, mesh will resend lost messages, similar to TCP.
+ * If reliability is off, mesh just do best effort, similar to UDP.
+ * 
+ * @param tunnel Tunnel affected.
+ * @param reliable GNUNET_YES to turn reliability on, 
+ *                 GNUNET_NO to have a best effort tunnel (default).
+ */
+void
+GNUNET_MESH_tunnel_reliable (struct GNUNET_MESH_Tunnel *tunnel, int reliable);
+
+
+/**
  * Handle for a transmission request.
  */
 struct GNUNET_MESH_TransmitHandle;

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2013-07-03 17:04:35 UTC (rev 
27738)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2013-07-03 17:04:57 UTC (rev 
27739)
@@ -321,6 +321,11 @@
   int nobuffer;
 
     /**
+     * Is the tunnel reliable?
+     */
+  int reliable;
+
+    /**
      * Force sending ACK? Flag to allow duplicate ACK on POLL.
      */
   int force_ack;
@@ -4322,6 +4327,63 @@
 
 
 /**
+ * Handler for requests of seeting tunnel's reliability policy.
+ *
+ * @param cls Closure (unused).
+ * @param client Identification of the client.
+ * @param message The actual message.
+ */
+static void
+handle_local_tunnel_reliability (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_log (GNUNET_ERROR_TYPE_ERROR, "  tunnel %X not found\n", tid);
+    GNUNET_break (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
+  }
+
+  switch (ntohs(message->type))
+  {
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_RELIABLE:
+          t->reliable = GNUNET_YES;
+          break;
+      case GNUNET_MESSAGE_TYPE_MESH_LOCAL_UNRELIABLE:
+          t->reliable = GNUNET_NO;
+          break;
+      default:
+          GNUNET_break (0);
+  }
+
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+}
+
+
+/**
  * Handler for client traffic directed to one peer
  *
  * @param cls closure
@@ -4733,6 +4795,12 @@
   {&handle_local_tunnel_buffer, NULL,
    GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER,
    sizeof (struct GNUNET_MESH_TunnelMessage)},
+  {&handle_local_tunnel_reliability, NULL,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER,
+   sizeof (struct GNUNET_MESH_TunnelMessage)},
+  {&handle_local_tunnel_reliability, NULL,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER,
+   sizeof (struct GNUNET_MESH_TunnelMessage)},
   {&handle_local_unicast, NULL,
    GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
   {&handle_local_to_origin, NULL,

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2013-07-03 17:04:35 UTC (rev 27738)
+++ gnunet/src/mesh/mesh_api.c  2013-07-03 17:04:57 UTC (rev 27739)
@@ -299,6 +299,11 @@
   int buffering;
 
     /**
+     * Is the tunnel allowed to buffer?
+     */
+  int reliable;
+
+    /**
      * Maximum allowed PID to send (last ACK recevied).
      */
   uint32_t last_ack_recv;
@@ -751,6 +756,9 @@
 
     if (GNUNET_NO == t->buffering)
       GNUNET_MESH_tunnel_buffer (t, GNUNET_NO);
+
+    if (GNUNET_YES == t->reliable)
+      GNUNET_MESH_tunnel_reliable (t, GNUNET_YES);
   }
   return GNUNET_YES;
 }
@@ -1120,7 +1128,6 @@
     break;
     /* Notify of a new data packet in the tunnel */
   case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-  case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
   case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
     process_incoming_data (h, msg);
     break;
@@ -1522,6 +1529,36 @@
 }
 
 
+/**
+ * Turn on/off the reliability of the tunnel.
+ * 
+ * If reliability is on, mesh will resend lost messages, similar to TCP.
+ * If reliability is off, mesh just do best effort, similar to UDP.
+ * 
+ * @param tunnel Tunnel affected.
+ * @param reliable GNUNET_YES to turn reliability on, 
+ *                 GNUNET_NO to have a best effort tunnel (default).
+ */
+void
+GNUNET_MESH_tunnel_reliable (struct GNUNET_MESH_Tunnel *tunnel, int reliable)
+{
+  struct GNUNET_MESH_TunnelMessage msg;
+  struct GNUNET_MESH_Handle *h;
+
+  h = tunnel->mesh;
+  tunnel->reliable = reliable;
+
+  if (GNUNET_YES == reliable)
+    msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_RELIABLE);
+  else
+    msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_UNRELIABLE);
+  msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
+  msg.tunnel_id = htonl (tunnel->tid);
+
+  send_packet (h, &msg.header, NULL);
+}
+
+
 struct GNUNET_MESH_TransmitHandle *
 GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
                                    struct GNUNET_TIME_Relative maxdelay,




reply via email to

[Prev in Thread] Current Thread [Next in Thread]