gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r27870 - in gnunet/src: include mesh
Date: Wed, 10 Jul 2013 13:57:16 +0200

Author: bartpolot
Date: 2013-07-10 13:57:16 +0200 (Wed, 10 Jul 2013)
New Revision: 27870

Modified:
   gnunet/src/include/gnunet_constants.h
   gnunet/src/include/gnunet_protocols.h
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh.h
   gnunet/src/mesh/mesh_api.c
   gnunet/src/mesh/mesh_common.c
Log:
- simplified MESH client<->service API as per suggestions in bug #2934

Modified: gnunet/src/include/gnunet_constants.h
===================================================================
--- gnunet/src/include/gnunet_constants.h       2013-07-10 11:39:54 UTC (rev 
27869)
+++ gnunet/src/include/gnunet_constants.h       2013-07-10 11:57:16 UTC (rev 
27870)
@@ -49,7 +49,7 @@
  * After how long do we consider a connection to a peer dead
  * if we don't receive messages from the peer?
  */
-#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_MINUTES, 5)
+#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_YEARS, 5)
 
 /**
  * How long do we delay reading more from a peer after a quota violation?
@@ -61,7 +61,7 @@
  * even if we assume that the service commonly does not
  * respond instantly (DNS, Database, etc.).
  */
-#define GNUNET_CONSTANTS_SERVICE_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_MINUTES, 10)
+#define GNUNET_CONSTANTS_SERVICE_TIMEOUT GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_YEARS, 10)
 
 /**
  * How long do we delay messages to get larger packet sizes (CORKing)?

Modified: gnunet/src/include/gnunet_protocols.h
===================================================================
--- gnunet/src/include/gnunet_protocols.h       2013-07-10 11:39:54 UTC (rev 
27869)
+++ gnunet/src/include/gnunet_protocols.h       2013-07-10 11:57:16 UTC (rev 
27870)
@@ -862,6 +862,11 @@
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY   274
 
 /**
+ * Payload client <-> service
+ */
+#define GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA             275
+
+/**
  * Local ACK for data.
  */
 #define GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK              286

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2013-07-10 11:39:54 UTC (rev 
27869)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2013-07-10 11:57:16 UTC (rev 
27870)
@@ -1804,6 +1804,7 @@
   }
   else
   {
+    GNUNET_assert (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI);
     return GNUNET_CONTAINER_multihashmap32_get (c->own_tunnels, tid);
   }
 }
@@ -1972,7 +1973,6 @@
 static void
 send_local_ack (struct MeshTunnel *t,
                 struct MeshClient *c,
-                uint32_t ack,
                 int is_fwd)
 {
   struct GNUNET_MESH_LocalAck msg;
@@ -1980,8 +1980,7 @@
   msg.header.size = htons (sizeof (msg));
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
   msg.tunnel_id = htonl (is_fwd ? t->local_tid : t->local_tid_dest);
-  msg.ack = htonl (ack); 
-  GNUNET_SERVER_notification_context_unicast(nc,
+  GNUNET_SERVER_notification_context_unicast (nc,
                                               c->handle,
                                               &msg.header,
                                               GNUNET_NO);
@@ -2078,6 +2077,8 @@
         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, nobuffer\n");
         return;
       }
+      if (GNUNET_YES == t->reliable && NULL != t->client)
+        tunnel_send_fwd_data_ack (t);
       break;
     case GNUNET_MESSAGE_TYPE_MESH_ACK:
       if (NULL != t->owner && GNUNET_YES == t->reliable)
@@ -2096,11 +2097,12 @@
   }
 
   /* Check if we need to transmit the ACK */
-  if (t->queue_max > t->next_fc.queue_n * 4 &&
+  if (NULL == t->owner && 
+      t->queue_max > t->next_fc.queue_n * 4 &&
       GMC_is_pid_bigger(t->prev_fc.last_ack_sent, t->prev_fc.last_pid_recv) &&
       GNUNET_NO == t->force_ack)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending ACK, buffer free\n");
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Not sending FWD ACK, buffer free\n");
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "  t->qmax: %u, t->qn: %u\n",
                 t->queue_max, t->next_fc.queue_n);
@@ -2124,7 +2126,7 @@
 
   t->prev_fc.last_ack_sent = ack;
   if (NULL != t->owner)
-    send_local_ack (t, t->owner, ack, GNUNET_YES);
+    send_local_ack (t, t->owner, GNUNET_YES);
   else if (0 != t->prev_hop)
     send_ack (t, t->prev_hop, ack);
   else
@@ -2196,7 +2198,7 @@
   t->next_fc.last_ack_sent = ack;
 
   if (NULL != t->client)
-    send_local_ack (t, t->client, ack, GNUNET_NO);
+    send_local_ack (t, t->client, GNUNET_NO);
   else if (0 != t->next_hop)
     send_ack (t, t->next_hop, ack);
   else
@@ -2206,38 +2208,55 @@
 
 
 /**
- * Modify the unicast message TID from global to local and send to client.
+ * Modify the mesh message TID from global to local and send to client.
  * 
  * @param t Tunnel on which to send the message.
  * @param msg Message to modify and send.
+ * @param c Client to send to.
+ * @param tid Tunnel ID to use (c can be both owner and client).
  */
 static void
-tunnel_send_client_ucast (struct MeshTunnel *t,
-                          const struct GNUNET_MESH_Data *msg)
+tunnel_send_client_data (struct MeshTunnel *t,
+                         const struct GNUNET_MESH_Data *msg,
+                         struct MeshClient *c, MESH_TunnelNumber tid)
 {
-  struct GNUNET_MESH_Data *copy;
-  uint16_t size = ntohs (msg->header.size);
-  char cbuf[size];
+  struct GNUNET_MESH_LocalData *copy;
+  uint16_t size = ntohs (msg->header.size) - sizeof (struct GNUNET_MESH_Data);
+  char cbuf[size + sizeof (struct GNUNET_MESH_LocalData)];
 
-  if (size < sizeof (struct GNUNET_MESH_Data) +
-             sizeof (struct GNUNET_MessageHeader))
+  if (size < sizeof (struct GNUNET_MessageHeader))
   {
     GNUNET_break_op (0);
     return;
   }
-  if (NULL == t->client)
+  if (NULL == c)
   {
     GNUNET_break (0);
     return;
   }
-  copy = (struct GNUNET_MESH_Data *) cbuf;
-  memcpy (copy, msg, size);
-  copy->tid = htonl (t->local_tid_dest);
-  GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
+  copy = (struct GNUNET_MESH_LocalData *) cbuf;
+  memcpy (&copy[1], &msg[1], size);
+  copy->header.size = htons (sizeof (struct GNUNET_MESH_LocalData) + size);
+  copy->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
+  copy->tid = htonl (tid);
+  GNUNET_SERVER_notification_context_unicast (nc, c->handle,
                                               &copy->header, GNUNET_NO);
 }
 
+/**
+ * Modify the unicast message TID from global to local and send to client.
+ * 
+ * @param t Tunnel on which to send the message.
+ * @param msg Message to modify and send.
+ */
+static void
+tunnel_send_client_ucast (struct MeshTunnel *t,
+                          const struct GNUNET_MESH_Data *msg)
+{
+  tunnel_send_client_data (t, msg, t->client, t->local_tid_dest);
+}
 
+
 /**
  * Modify the to_origin  message TID from global to local and send to client.
  * 
@@ -2248,26 +2267,7 @@
 tunnel_send_client_to_orig (struct MeshTunnel *t,
                             const struct GNUNET_MESH_Data *msg)
 {
-  struct GNUNET_MESH_Data *copy;
-  uint16_t size = ntohs (msg->header.size);
-  char cbuf[size];
-
-  if (size < sizeof (struct GNUNET_MESH_Data) +
-             sizeof (struct GNUNET_MessageHeader))
-  {
-    GNUNET_break_op (0);
-    return;
-  }
-  if (NULL == t->owner)
-  {
-    GNUNET_break (0);
-    return;
-  }
-  copy = (struct GNUNET_MESH_Data *) cbuf;
-  memcpy (cbuf, msg, size);
-  copy->tid = htonl (t->local_tid);
-  GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
-                                              &copy->header, GNUNET_NO);
+  tunnel_send_client_data (t, msg, t->owner, t->local_tid);
 }
 
 
@@ -3664,7 +3664,8 @@
     {
 //       GNUNET_STATISTICS_update (stats, "# duplicate PID", 1, GNUNET_NO);
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  " Pid %u not expected, sending FWD ACK!\n", pid);
+                  " Pid %u not expected (%u), sending FWD ACK!\n",
+                  pid, t->prev_fc.last_pid_recv + 1);
       tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_DATA_ACK);
     }
     return GNUNET_OK;
@@ -4513,24 +4514,25 @@
 
 
 /**
- * Handler for client traffic directed to one peer
+ * Handler for client traffic
  *
  * @param cls closure
  * @param client identification of the client
  * @param message the actual message
  */
 static void
-handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
-                      const struct GNUNET_MessageHeader *message)
+handle_local_data (void *cls, struct GNUNET_SERVER_Client *client,
+                   const struct GNUNET_MessageHeader *message)
 {
+  struct GNUNET_MESH_LocalData *data_msg;
   struct MeshClient *c;
   struct MeshTunnel *t;
-  struct GNUNET_MESH_Data *data_msg;
+  struct MeshFlowControl *fc;
   MESH_TunnelNumber tid;
   size_t size;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got a unicast request from a client!\n");
+              "Got data from a client!\n");
 
   /* Sanity check for client registration */
   if (NULL == (c = client_get (client)))
@@ -4541,12 +4543,11 @@
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  by client %u\n", c->id);
 
-  data_msg = (struct GNUNET_MESH_Data *) message;
+  data_msg = (struct GNUNET_MESH_LocalData *) message;
 
   /* Sanity check for message size */
-  size = ntohs (message->size);
-  if (sizeof (struct GNUNET_MESH_Data) +
-      sizeof (struct GNUNET_MessageHeader) > size)
+  size = ntohs (message->size) - sizeof (struct GNUNET_MESH_LocalData);
+  if (size < sizeof (struct GNUNET_MessageHeader))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -4555,29 +4556,30 @@
 
   /* Tunnel exists? */
   tid = ntohl (data_msg->tid);
-  t = tunnel_get_by_local_id (c, tid);
-  if (NULL == t)
+  if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-
-  /*  Is it a local tunnel? Then, does client own the tunnel? */
-  if (t->owner->handle != client)
+  t = tunnel_get_by_local_id (c, tid);
+  if (NULL == t)
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
 
-  /* PID should be as expected: client<->service communication */
-  if (ntohl (data_msg->pid) != t->prev_fc.last_pid_recv + 1)
+  /* Is the client in the tunnel? */
+  if ( !( (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV &&
+           t->owner &&
+           t->owner->handle == client)
+         ||
+          (tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV &&
+           t->client && 
+           t->client->handle == client) ) )
   {
     GNUNET_break (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-              "Unicast PID, expected %u, got %u\n",
-              t->prev_fc.last_pid_recv + 1, ntohl (data_msg->pid));
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
@@ -4587,14 +4589,18 @@
    */
   {
     struct GNUNET_MESH_Data *payload;
+    char cbuf[sizeof(struct GNUNET_MESH_Data) + size];
 
+    fc = tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? &t->prev_fc : &t->next_fc;
     if (GNUNET_YES == t->reliable)
     {
       struct MeshSentMessage *copy;
 
-      copy = GNUNET_malloc (sizeof (struct MeshSentMessage) + size);
+      copy = GNUNET_malloc (sizeof (struct MeshSentMessage)
+                            + sizeof(struct GNUNET_MESH_Data)
+                            + size);
       copy->t = t;
-      copy->id = ntohl (data_msg->pid);
+      copy->id = fc->last_pid_recv + 1;
       copy->is_forward = GNUNET_YES;
       copy->retry_timer = GNUNET_TIME_UNIT_MINUTES;
       copy->retry_task = GNUNET_SCHEDULER_add_delayed (copy->retry_timer,
@@ -4616,16 +4622,23 @@
     }
     else
     {
-      static struct GNUNET_MESH_Data data_message;
-      payload = &data_message;
+      payload = (struct GNUNET_MESH_Data *) cbuf;
     }
-    memcpy (payload, data_msg, size);
-    payload->oid = my_full_id;
+    memcpy (&payload[1], &data_msg[1], size);
+    payload->header.size = htons (sizeof (struct GNUNET_MESH_Data) + size);
+    payload->header.type = htons (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ?
+                                  GNUNET_MESSAGE_TYPE_MESH_UNICAST :
+                                  GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
+    GNUNET_PEER_resolve(t->id.oid, &payload->oid);;
     payload->tid = htonl (t->id.tid);
     payload->ttl = htonl (default_ttl);
+    payload->pid = htonl (fc->last_pid_recv + 1);
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "  calling generic handler...\n");
-    handle_mesh_unicast (NULL, &my_full_id, &payload->header);
+    if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
+      handle_mesh_unicast (NULL, &my_full_id, &payload->header);
+    else
+      handle_mesh_to_orig (NULL, &my_full_id, &payload->header);
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "receive done OK\n");
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -4635,140 +4648,6 @@
 
 
 /**
- * Handler for client traffic directed to the origin
- *
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
- */
-static void
-handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
-                        const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_MESH_Data *data_msg;
-  struct MeshFlowControl *fc;
-  struct MeshClient *c;
-  struct MeshTunnel *t;
-  MESH_TunnelNumber tid;
-  size_t size;
-
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Got a ToOrigin request from a 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);
-
-  data_msg = (struct GNUNET_MESH_Data *) message;
-
-  /* Sanity check for message size */
-  size = ntohs (message->size);
-  if (sizeof (struct GNUNET_MESH_Data) +
-      sizeof (struct GNUNET_MessageHeader) > size)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-
-  /* Tunnel exists? */
-  tid = ntohl (data_msg->tid);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  on tunnel %X\n", tid);
-  if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-  t = tunnel_get_by_local_id (c, tid);
-  if (NULL == t)
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tunnel %X unknown.\n", tid);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "  for client %u.\n", c->id);
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-
-  /*  It should be sent by someone who has this as incoming tunnel. */
-  if (t->client != c)
-  {
-    GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-
-  /* PID should be as expected */
-  fc = &t->next_fc;
-  if (ntohl (data_msg->pid) != fc->last_pid_recv + 1)
-  {
-    GNUNET_break (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "To Origin PID, expected %u, got %u\n",
-                fc->last_pid_recv + 1,
-                ntohl (data_msg->pid));
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-    return;
-  }
-
-  /* Ok, everything is correct, send the message
-   * (pretend we got it from a mesh peer)
-   */
-  {
-    struct GNUNET_MESH_Data *payload;
-
-    if (GNUNET_YES == t->reliable)
-    {
-      struct MeshSentMessage *copy;
-
-      copy = GNUNET_malloc (sizeof (struct MeshSentMessage) + size);
-      copy->t = t;
-      copy->id = ntohl (data_msg->pid);
-      copy->is_forward = GNUNET_NO;
-      copy->retry_timer = GNUNET_TIME_UNIT_MINUTES;
-      copy->retry_task = GNUNET_SCHEDULER_add_delayed (copy->retry_timer,
-                                                       
&tunnel_retransmit_message,
-                                                       copy);
-      if (GNUNET_OK !=
-          GNUNET_CONTAINER_multihashmap32_put (t->sent_messages_bck,
-                                               copy->id,
-                                               copy,
-                                               
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
-      {
-        GNUNET_break (0);
-        GNUNET_SCHEDULER_cancel (copy->retry_task);
-        GNUNET_free (copy);
-        GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
-        return;
-      }
-      payload = (struct GNUNET_MESH_Data *) &copy[1];
-    }
-    else
-    {
-      static struct GNUNET_MESH_Data data_message;
-      payload = &data_message;
-    }
-
-    memcpy (payload, data_msg, size);
-    GNUNET_PEER_resolve (t->id.oid, &payload->oid);
-    payload->tid = htonl (t->id.tid);
-    payload->ttl = htonl (default_ttl);
-
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "  calling generic handler...\n");
-    handle_mesh_to_orig (NULL, &my_full_id, &payload->header);
-  }
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
-
-  return;
-}
-
-
-/**
  * Handler for client's ACKs for payload traffic.
  *
  * @param cls Closure (unused).
@@ -4783,7 +4662,6 @@
   struct MeshTunnel *t;
   struct MeshClient *c;
   MESH_TunnelNumber tid;
-  uint32_t ack;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a local ACK\n");
   /* Sanity check for client registration */
@@ -4810,20 +4688,17 @@
     return;
   }
 
-  ack = ntohl (msg->ack);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  ack %u\n", ack);
-
   /* Does client own tunnel? I.E: Is this an ACK for BCK traffic? */
   if (t->owner == c)
   {
     /* The client owns the tunnel, ACK is for data to_origin, send BCK ACK. */
-    t->prev_fc.last_ack_recv = ack;
+    t->prev_fc.last_ack_recv++;
     tunnel_send_bck_ack (t, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
   }
   else
   {
     /* The client doesn't own the tunnel, this ACK is for FWD traffic. */
-    t->next_fc.last_ack_recv = ack;
+    t->next_fc.last_ack_recv++;
     tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
   }
 
@@ -4975,10 +4850,8 @@
   {&handle_local_tunnel_destroy, NULL,
    GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
    sizeof (struct GNUNET_MESH_TunnelMessage)},
-  {&handle_local_unicast, NULL,
-   GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
-  {&handle_local_to_origin, NULL,
-   GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
+  {&handle_local_data, NULL,
+   GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0},
   {&handle_local_ack, NULL,
    GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
    sizeof (struct GNUNET_MESH_LocalAck)},

Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h      2013-07-10 11:39:54 UTC (rev 27869)
+++ gnunet/src/mesh/mesh.h      2013-07-10 11:57:16 UTC (rev 27870)
@@ -197,6 +197,27 @@
 
 
 /**
+ * Message for mesh data traffic.
+ */
+struct GNUNET_MESH_LocalData
+{
+    /**
+     * Type: GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA
+     */
+  struct GNUNET_MessageHeader header;
+
+    /**
+     * TID of the tunnel
+     */
+  uint32_t tid GNUNET_PACKED;
+
+    /**
+     * Payload follows
+     */
+};
+
+
+/**
  * Message to allow the client send more data to the service
  * (always service -> client).
  */
@@ -212,10 +233,6 @@
      */
   MESH_TunnelNumber tunnel_id GNUNET_PACKED;
 
-    /**
-     * ID of the last packet allowed.
-     */
-  uint32_t ack GNUNET_PACKED;
 };
 
 

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2013-07-10 11:39:54 UTC (rev 27869)
+++ gnunet/src/mesh/mesh_api.c  2013-07-10 11:57:16 UTC (rev 27870)
@@ -304,24 +304,10 @@
   int reliable;
 
     /**
-     * Maximum allowed PID to send (last ACK recevied).
+     * Are we allowed to send to the service?
      */
-  uint32_t last_ack_recv;
+  int allow_send;
 
-    /**
-     * Last PID received from the service.
-     */
-  uint32_t last_pid_recv;
-
-  /**
-   * Last packet ID sent to the service.
-   */
-  uint32_t last_pid_sent;
-
-  /**
-   * Last ACK value sent to the service: how much are we willing to accept?
-   */
-  uint32_t last_ack_sent;
 };
 
 
@@ -402,10 +388,9 @@
       LOG (GNUNET_ERROR_TYPE_DEBUG, "#  message internal\n");
       return th->size;
     }
-    if (GNUNET_YES == GMC_is_pid_bigger(t->last_ack_recv, t->last_pid_sent))
+    if (GNUNET_YES == t->allow_send)
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "#  message payload ok (%u =< %u)\n",
-           t->last_pid_sent + 1, t->last_ack_recv);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "#  message payload ok\n");
       return th->size;
     }
   }
@@ -463,10 +448,7 @@
   {
     t->tid = tid;
   }
-  t->last_ack_recv = (uint32_t) -1;
-  t->last_pid_recv = (uint32_t) -1;
-  t->last_ack_sent = (uint32_t) -1;
-  t->last_pid_sent = (uint32_t) -1;
+  t->allow_send = GNUNET_NO;
   t->buffering = GNUNET_YES;
   return t;
 }
@@ -610,14 +592,10 @@
 {
   struct GNUNET_MESH_LocalAck msg;
 
-  t->last_ack_sent = t->last_pid_recv + 1;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Sending ACK on tunnel %X: %u\n",
-       t->tid, t->last_ack_sent);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending ACK on tunnel %X\n", t->tid);
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK);
   msg.header.size = htons (sizeof (msg));
   msg.tunnel_id = htonl (t->tid);
-  msg.ack = htonl (t->last_ack_sent);
 
 #if DEBUG_ACK
   t->mesh->acks_sent++;
@@ -744,10 +722,7 @@
        */
       continue;
     }
-    t->last_ack_sent = (uint32_t) -1;
-    t->last_pid_sent = (uint32_t) -1;
-    t->last_ack_recv = (uint32_t) -1;
-    t->last_pid_recv = (uint32_t) -1;
+    t->allow_send = GNUNET_NO;
     tmsg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
     tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
     tmsg.tunnel_id = htonl (t->tid);
@@ -831,7 +806,7 @@
   if (NULL != h->new_tunnel)
   {
     t = create_tunnel (h, tid);
-    t->last_ack_sent = 0;
+    t->allow_send = GNUNET_NO;
     t->peer = GNUNET_PEER_intern (&msg->peer);
     t->mesh = h;
     t->tid = tid;
@@ -907,50 +882,28 @@
   const struct GNUNET_MESH_MessageHandler *handler;
   const struct GNUNET_PeerIdentity *peer;
   struct GNUNET_PeerIdentity id;
-  struct GNUNET_MESH_Data *dmsg;
+  struct GNUNET_MESH_LocalData *dmsg;
   struct GNUNET_MESH_Tunnel *t;
   unsigned int i;
-  uint32_t pid;
   uint16_t type;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
-  type = ntohs (message->type);
-  switch (type)
-  {
-  case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-  case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
-    dmsg = (struct GNUNET_MESH_Data *) message;
 
-    t = retrieve_tunnel (h, ntohl (dmsg->tid));
-    payload = (struct GNUNET_MessageHeader *) &dmsg[1];
-    GNUNET_PEER_resolve (t->peer, &id);
-    peer = &id;
-    pid = ntohl (dmsg->pid);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  %s data on tunnel %s [%X]\n",
-         type == GNUNET_MESSAGE_TYPE_MESH_UNICAST ? "fwd" : "bck",
-         GNUNET_i2s (peer), ntohl (dmsg->tid));
-    break;
-  default:
-    GNUNET_break (0);
-    return;
-  }
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  pid %u\n", pid);
+  dmsg = (struct GNUNET_MESH_LocalData *) message;
+
+  t = retrieve_tunnel (h, ntohl (dmsg->tid));
+  payload = (struct GNUNET_MessageHeader *) &dmsg[1];
+  GNUNET_PEER_resolve (t->peer, &id);
+  peer = &id;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  %s data on tunnel %s [%X]\n",
+       t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? "fwd" : "bck",
+       GNUNET_i2s (peer), ntohl (dmsg->tid));
   if (NULL == t)
   {
     /* Tunnel was ignored/destroyed, probably service didn't get it yet */
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  ignored!\n");
     return;
   }
-  if (GNUNET_YES ==
-      GMC_is_pid_bigger(pid, t->last_ack_sent))
-  {
-    GNUNET_break (0);
-    LOG (GNUNET_ERROR_TYPE_DEBUG,
-         "  unauthorized message! (%u, ACK %u)\n",
-         pid, t->last_ack_sent);
-    // FIXME fc what now? accept? reject?
-  }
-  t->last_pid_recv = pid;
   type = ntohs (payload->type);
   for (i = 0; i < h->n_handlers; i++)
   {
@@ -988,7 +941,6 @@
   struct GNUNET_MESH_LocalAck *msg;
   struct GNUNET_MESH_Tunnel *t;
   MESH_TunnelNumber tid;
-  uint32_t ack;
 
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
   h->acks_recv++;
@@ -1000,15 +952,11 @@
     LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown tunnel %X\n", tid);
     return;
   }
-  ack = ntohl (msg->ack);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  on tunnel %X, ack %u!\n", t->tid, ack);
-  if (GNUNET_YES == GMC_is_pid_bigger(ack, t->last_ack_recv))
-    t->last_ack_recv = ack;
-  else
-    return;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  on tunnel %X!\n", t->tid);
+  t->allow_send = GNUNET_YES;
   if (NULL == h->th && 0 < t->packet_size)
   {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  tmt rdy was NULL, requesting!\n", t->tid, 
ack);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "  tmt rdy was NULL, requesting!\n");
     h->th =
         GNUNET_CLIENT_notify_transmit_ready (h->client, t->packet_size,
                                              GNUNET_TIME_UNIT_FOREVER_REL,
@@ -1135,8 +1083,7 @@
     process_tunnel_destroy (h, (struct GNUNET_MESH_TunnelMessage *) msg);
     break;
     /* Notify of a new data packet in the tunnel */
-  case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-  case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+  case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA:
     process_incoming_data (h, msg);
     break;
   case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
@@ -1211,46 +1158,35 @@
     t = th->tunnel;
     if (GNUNET_YES == th_is_payload (th))
     {
-      struct GNUNET_MESH_Data *dmsg;
+      struct GNUNET_MESH_LocalData *dmsg;
       struct GNUNET_MessageHeader *mh;
 
       LOG (GNUNET_ERROR_TYPE_DEBUG, "#  payload\n");
-      if (GNUNET_NO == GMC_is_pid_bigger (t->last_ack_recv, t->last_pid_sent))
+      if (GNUNET_NO == t->allow_send)
       {
         /* This tunnel is not ready to transmit yet, try next message */
         next = th->next;
         continue;
       }
       t->packet_size = 0;
+      t->allow_send = GNUNET_NO;
       GNUNET_assert (size >= th->size);
-      dmsg = (struct GNUNET_MESH_Data *) cbuf;
+      dmsg = (struct GNUNET_MESH_LocalData *) cbuf;
       mh = (struct GNUNET_MessageHeader *) &dmsg[1];
       psize = th->notify (th->notify_cls,
-                          size - sizeof (struct GNUNET_MESH_Data),
+                          size - sizeof (struct GNUNET_MESH_LocalData),
                           mh);
       if (psize > 0)
       {
-        psize += sizeof (struct GNUNET_MESH_Data);
+        psize += sizeof (struct GNUNET_MESH_LocalData);
         GNUNET_assert (size >= psize);
         dmsg->header.size = htons (psize);
         dmsg->tid = htonl (t->tid);
-        dmsg->pid = htonl (t->last_pid_sent + 1);
-        dmsg->ttl = 0;
-        memset (&dmsg->oid, 0, sizeof (struct GNUNET_PeerIdentity));
-        t->last_pid_sent++;
       }
-      if (t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
-      {
-        dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "#  to origin, type %s\n",
-             GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
-      }
-      else
-      {
-        dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "#  unicast, type %s\n",
-             GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
-      }
+      dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
+      LOG (GNUNET_ERROR_TYPE_DEBUG, "#  payload type %s\n",
+           GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
+
     }
     else
     {
@@ -1491,7 +1427,7 @@
   msg.port = htonl (port);
   msg.peer = *peer;
   msg.options = 0;
-  t->last_ack_sent = 0;
+  t->allow_send = 0;
   send_packet (h, &msg.header, t);
   return t;
 }
@@ -1575,6 +1511,7 @@
   GNUNET_assert (NULL != tunnel);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "MESH NOTIFY TRANSMIT READY\n");
   LOG (GNUNET_ERROR_TYPE_DEBUG, "    on tunnel %X\n", tunnel->tid);
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "    allow_send %d\n", tunnel->allow_send);
   if (tunnel->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
     LOG (GNUNET_ERROR_TYPE_DEBUG, "    to origin\n");
   else
@@ -1585,7 +1522,7 @@
   th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
   th->tunnel = tunnel;
   th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
-  th->size = notify_size + sizeof (struct GNUNET_MESH_Data);
+  th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData);
   tunnel->packet_size = th->size;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "    total size %u\n", th->size);
   th->notify = notify;
@@ -1593,7 +1530,7 @@
   add_to_queue (tunnel->mesh, th);
   if (NULL != tunnel->mesh->th)
     return th;
-  if (!GMC_is_pid_bigger (tunnel->last_ack_recv, tunnel->last_pid_sent))
+  if (GNUNET_NO == tunnel->allow_send)
     return th;
   LOG (GNUNET_ERROR_TYPE_DEBUG, "    call client notify tmt rdy\n");
   tunnel->mesh->th =

Modified: gnunet/src/mesh/mesh_common.c
===================================================================
--- gnunet/src/mesh/mesh_common.c       2013-07-10 11:39:54 UTC (rev 27869)
+++ gnunet/src/mesh/mesh_common.c       2013-07-10 11:57:16 UTC (rev 27870)
@@ -136,6 +136,11 @@
     case 274: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY";
 
       /**
+       * Local payload traffic
+       */
+    case 275: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA";
+
+      /**
        * Local ACK for data.
        */
     case 286: return "GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK";




reply via email to

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