gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r29047 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r29047 - gnunet/src/mesh
Date: Fri, 6 Sep 2013 04:58:26 +0200

Author: bartpolot
Date: 2013-09-06 04:58:26 +0200 (Fri, 06 Sep 2013)
New Revision: 29047

Modified:
   gnunet/src/mesh/gnunet-service-mesh-enc.c
Log:
- multiple fixes for connection-less loopback traffic


Modified: gnunet/src/mesh/gnunet-service-mesh-enc.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-09-05 18:48:00 UTC (rev 
29046)
+++ gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-09-06 02:58:26 UTC (rev 
29047)
@@ -1219,15 +1219,6 @@
 
 
 /**
- * Send all cached messages that we can, tunnel is online.
- *
- * @param t Tunnel that holds the messages.
- * @param fwd Is this fwd?
- */
-static void
-tunnel_send_queued_data (struct MeshTunnel2 *t, int fwd);
-
-/**
  * Dummy function to separate declarations from definitions in function list.
  */
 void
@@ -1633,9 +1624,9 @@
 static int
 connection_is_origin (struct MeshConnection *c, int fwd)
 {
-  if (!fwd && c->own_pos == c->path->length - 1)
+  if (!fwd && c->path->length - 1 == c->own_pos )
     return GNUNET_YES;
-  if (fwd && c->own_pos == 0)
+  if (fwd && 0 == c->own_pos)
     return GNUNET_YES;
   return GNUNET_NO;
 }
@@ -1653,16 +1644,12 @@
 static int
 connection_is_terminal (struct MeshConnection *c, int fwd)
 {
-  if (fwd && c->own_pos == c->path->length - 1)
-    return GNUNET_YES;
-  if (!fwd && c->own_pos == 0)
-    return GNUNET_YES;
-  return GNUNET_NO;
+  return connection_is_origin (c, !fwd);
 }
 
 
 /**
- * Is the recipient client for this channel on this peer?
+ * Is the root client for this channel on this peer?
  *
  * @param ch Channel.
  * @param fwd Is this for fwd traffic?
@@ -1670,14 +1657,30 @@
  * @return GNUNET_YES in case it is.
  */
 static int
+channel_is_origin (struct MeshChannel *ch, int fwd)
+{
+  struct MeshClient *c;
+
+  c = fwd ? ch->root : ch->dest;
+  return NULL != c;
+}
+
+
+/**
+ * Is the destination client for this channel on this peer?
+ *
+ * @param ch Channel.
+ * @param fwd Is this for fwd traffic?
+ *
+ * @return GNUNET_YES in case it is.
+ */
+static int
 channel_is_terminal (struct MeshChannel *ch, int fwd)
 {
-  if (NULL == ch->t || NULL == ch->t->connection_head)
-  {
-    GNUNET_break (0);
-    return GNUNET_NO;
-  }
-  return connection_is_terminal (ch->t->connection_head, fwd);
+  struct MeshClient *c;
+
+  c = fwd ? ch->dest : ch->root;
+  return NULL != c;
 }
 
 
@@ -1744,14 +1747,8 @@
   c = t->connection_head;
   buffer = 0;
 
-  if (NULL == c)
-  {
-    GNUNET_break (0);
-    return 0;
-  }
-
   /* If terminal, return biggest channel buffer */
-  if (connection_is_terminal (c, fwd))
+  if (NULL == c || connection_is_terminal (c, fwd))
   {
     struct MeshChannel *ch;
     unsigned int ch_buf;
@@ -1989,12 +1986,12 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  %s\n",
               GNUNET_MESH_DEBUG_M2S (ntohs (message->type)));
 
-  if (channel_is_terminal (ch, fwd))
+  if (channel_is_terminal (ch, fwd) || ch->t->peer->id == myid)
   {
     handle_decrypted (ch->t, message, fwd);
     return;
   }
-  
+
   type = fwd ? GNUNET_MESSAGE_TYPE_MESH_FWD : GNUNET_MESSAGE_TYPE_MESH_BCK;
   iv = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_NONCE, UINT64_MAX);
 
@@ -3073,35 +3070,14 @@
   t->state = state;
 }
 
+
 /**
- * Cache a message to be sent once tunnel is online.
+ * Send all cached messages that we can, tunnel is online.
  *
- * @param t Tunnel to hold the message.
- * @param ch Channel the message is about.
- * @param msg Message itself (copy will be made).
+ * @param t Tunnel that holds the messages.
  * @param fwd Is this fwd?
  */
 static void
-tunnel_queue_data (struct MeshTunnel2 *t,
-                   struct MeshChannel *ch,
-                   struct GNUNET_MessageHeader *msg,
-                   int fwd)
-{
-  struct MeshTunnelQueue *tq;
-  uint16_t size = ntohs (msg->size);
-
-  tq = GNUNET_malloc (sizeof (struct MeshTunnelQueue) + size);
-
-  tq->ch = ch;
-  memcpy (&tq[1], msg, size);
-  GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, t->tq_tail, tq);
-
-  if (MESH_TUNNEL_READY == t->state)
-    tunnel_send_queued_data (t, fwd);
-}
-
-
-static void
 tunnel_send_queued_data (struct MeshTunnel2 *t, int fwd)
 {
   struct MeshTunnelQueue *tq;
@@ -3126,7 +3102,35 @@
 }
 
 
+/**
+ * Cache a message to be sent once tunnel is online.
+ *
+ * @param t Tunnel to hold the message.
+ * @param ch Channel the message is about.
+ * @param msg Message itself (copy will be made).
+ * @param fwd Is this fwd?
+ */
 static void
+tunnel_queue_data (struct MeshTunnel2 *t,
+                   struct MeshChannel *ch,
+                   struct GNUNET_MessageHeader *msg,
+                   int fwd)
+{
+  struct MeshTunnelQueue *tq;
+  uint16_t size = ntohs (msg->size);
+
+  tq = GNUNET_malloc (sizeof (struct MeshTunnelQueue) + size);
+
+  tq->ch = ch;
+  memcpy (&tq[1], msg, size);
+  GNUNET_CONTAINER_DLL_insert_tail (t->tq_head, t->tq_tail, tq);
+
+  if (MESH_TUNNEL_READY == t->state)
+    tunnel_send_queued_data (t, fwd);
+}
+
+
+static void
 connection_change_state (struct MeshConnection* c,
                          enum MeshConnectionState state)
 {
@@ -3871,7 +3875,7 @@
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  buffer available: %u\n", buffer);
 
-  if ( (NULL != ch && channel_is_terminal (ch, !fwd)) ||
+  if ( (NULL != ch && channel_is_origin (ch, fwd)) ||
        (NULL != c && connection_is_origin (c, fwd)) )
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  sending on channel...\n");
@@ -6493,6 +6497,14 @@
   {
     peer->tunnel = tunnel_new ();
     peer->tunnel->peer = peer;
+    if (peer->id == myid)
+    {
+      tunnel_change_state (peer->tunnel, MESH_TUNNEL_READY);
+    }
+    else
+    {
+      peer_connect (peer);
+    }
   }
   t = peer->tunnel;
 
@@ -6507,14 +6519,13 @@
   ch->port = ntohl (msg->port);
   channel_set_options (ch, ntohl (msg->opt));
 
-  /* In unreliable channels, we'll use the DLL to buffer data for the root */
+  /* In unreliable channels, we'll use the DLL to buffer BCK data */
   ch->root_rel = GNUNET_new (struct MeshChannelReliability);
   ch->root_rel->ch = ch;
   ch->root_rel->expected_delay = MESH_RETRANSMIT_TIME;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED CHANNEL %s[%x]:%u (%x)\n",
               peer2s (t->peer), ch->gid, ch->port, ch->lid_root);
-  peer_connect (peer);
 
   /* Send create channel */
   {




reply via email to

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