gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r28640 - gnunet/src/mesh
Date: Thu, 15 Aug 2013 05:58:48 +0200

Author: bartpolot
Date: 2013-08-15 05:58:48 +0200 (Thu, 15 Aug 2013)
New Revision: 28640

Modified:
   gnunet/src/mesh/gnunet-service-mesh-enc.c
Log:
- add generic tid/cid filling, ack processing


Modified: gnunet/src/mesh/gnunet-service-mesh-enc.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-08-15 03:58:21 UTC (rev 
28639)
+++ gnunet/src/mesh/gnunet-service-mesh-enc.c   2013-08-15 03:58:48 UTC (rev 
28640)
@@ -525,6 +525,16 @@
      * Only present (non-NULL) at the destination of a tunnel.
      */
   struct MeshChannelReliability *bck_rel;
+
+    /**
+     * Is the root prevented from sending more data? (We "owe" him an ACK).
+     */
+  int blocked_fwd;
+
+    /**
+     * Is the dest prevented from sending more data? (We "owe" him an ACK).
+     */
+  int blocked_bck;
 };
 
 
@@ -760,11 +770,6 @@
      * ID of the client, mainly for debug messages
      */
   unsigned int id;
-
-    /**
-     * Is this client prevented from sending more data? (We "owe" him an ACK).
-     */
-  int blocked;
 };
 
 
@@ -1470,6 +1475,10 @@
 {
   struct GNUNET_MESH_LocalAck msg;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "send local %s ack on %s:%X towards %p\n",
+              fwd ? "FWD" : "BCK", GNUNET_h2s (&ch->t->id), ch->gid, c);
+
   if (NULL == c
       || ( fwd && (0 == ch->lid_root || c != ch->root))
       || (!fwd && (0 == ch->lid_dest || c != ch->dest)) )
@@ -1484,7 +1493,10 @@
                                               c->handle,
                                               &msg.header,
                                               GNUNET_NO);
-  c->blocked = GNUNET_NO;
+  if (fwd)
+    ch->blocked_fwd = GNUNET_NO;
+  else
+    ch->blocked_bck = GNUNET_NO;
 }
 
 
@@ -1637,22 +1649,46 @@
   memcpy (data, message, size);
   type = ntohs (message->type);
 
-  if (GNUNET_MESSAGE_TYPE_MESH_FWD == type ||
-      GNUNET_MESSAGE_TYPE_MESH_BCK == type)
+  switch (type)
   {
-    struct GNUNET_MESH_Encrypted *msg;
+    struct GNUNET_MESH_Encrypted *emsg;
+    struct GNUNET_MESH_ACK       *amsg;
+    struct GNUNET_MESH_Poll      *pmsg;
     uint32_t ttl;
 
-    msg = (struct GNUNET_MESH_Encrypted *) data;
-    ttl = ntohl (msg->ttl);
-    if (0 == ttl)
-    {
-      GNUNET_break_op (0);
-      return;
-    }
-    msg->ttl = htonl (ttl - 1);
-    msg->pid = htonl (fwd ? c->fwd_fc.next_pid++ : c->bck_fc.next_pid++);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " pid %u\n", ntohl (msg->pid));
+    case GNUNET_MESSAGE_TYPE_MESH_FWD:
+    case GNUNET_MESSAGE_TYPE_MESH_BCK:
+      emsg = (struct GNUNET_MESH_Encrypted *) data;
+      ttl = ntohl (emsg->ttl);
+      if (0 == ttl)
+      {
+        GNUNET_break_op (0);
+        return;
+      }
+      emsg->tid = c->t->id;
+      emsg->cid = htonl (c->id);
+      emsg->ttl = htonl (ttl - 1);
+      emsg->pid = htonl (fwd ? c->fwd_fc.next_pid++ : c->bck_fc.next_pid++);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " pid %u\n", ntohl (emsg->pid));
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_ACK:
+      amsg = (struct GNUNET_MESH_ACK *) data;
+      amsg->tid = c->t->id;
+      amsg->cid = htonl (c->id);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ack %u\n", ntohl (amsg->ack));
+      break;
+
+    case GNUNET_MESSAGE_TYPE_MESH_POLL:
+      pmsg = (struct GNUNET_MESH_Poll *) data;
+      pmsg->tid = c->t->id;
+      pmsg->cid = htonl (c->id);
+      pmsg->pid = htonl (fwd ? c->fwd_fc.last_pid_sent : 
c->bck_fc.last_pid_sent);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " poll %u\n", ntohl (pmsg->pid));
+      break;
+
+    default:
+      GNUNET_break (0);
   }
 
   queue_add (data,
@@ -2631,7 +2667,6 @@
 
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_POLL);
   msg.header.size = htons (sizeof (msg));
-  msg.pid = htonl (fc->last_pid_sent);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " *** pid (%u)!\n", fc->last_pid_sent);
   send_prebuilt_message_connection (&msg.header, c, NULL, fc == &c->fwd_fc);
   fc->poll_time = GNUNET_TIME_STD_BACKOFF (fc->poll_time);
@@ -3487,7 +3522,7 @@
 
 
 /**
- * Send an ACK to a client is needed.
+ * Send an ACK to a client if needed.
  *
  * @param ch Channel this is regarding.
  * @param fwd Is this about fwd traffic? (ACk goes the opposite direction).
@@ -3496,12 +3531,24 @@
 channel_send_client_ack (struct MeshChannel *ch, int fwd)
 {
   struct MeshClient *c;
+  int blocked;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Channel send client %s ack on %s:%X\n",
+              fwd ? "FWD" : "BCK", GNUNET_h2s (&ch->t->id), ch->gid);
+
+  /* Check for buffer space */
+  if (0 >= tunnel_get_buffer (ch->t, fwd))
+    return;
+
   /* Client to receive the ACK (fwd indicates traffic to be ACK'd) */
   c = fwd ? ch->root : ch->dest;
 
-  if (GNUNET_YES == c->blocked)
+  blocked = fwd ? ch->blocked_fwd : ch->blocked_bck;
+  if (GNUNET_YES == blocked)
     send_local_ack (ch, c, fwd);
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client not blocked\n");
 }
 
 
@@ -3523,7 +3570,7 @@
   unsigned int cs;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Channel send %s ack on %s:%X\n",
+              "Channel send connection %s ack on %s:%X\n",
               fwd ? "FWD" : "BCK", GNUNET_h2s (&ch->t->id), ch->gid);
 
   /* Count connections, how many messages are already allowed */
@@ -3774,6 +3821,20 @@
     return NULL;
   }
 
+//   char salt[] = "salt";
+//   GNUNET_CRYPTO_kdf (&t->e_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
+//                      salt, sizeof (salt),
+//                      &t->e_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
+//                      &my_full_id, sizeof (struct GNUNET_PeerIdentity),
+//                      GNUNET_PEER_resolve2 (t->peer->id), sizeof (struct 
GNUNET_PeerIdentity),
+//                      NULL);
+//   GNUNET_CRYPTO_kdf (&t->d_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
+//                      salt, sizeof (salt),
+//                      &t->d_key, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
+//                      GNUNET_PEER_resolve2 (t->peer->id), sizeof (struct 
GNUNET_PeerIdentity),
+//                      &my_full_id, sizeof (struct GNUNET_PeerIdentity),
+//                      NULL);
+
   return t;
 }
 
@@ -4042,6 +4103,8 @@
   ch->root = owner;
   ch->lid_root = lid_root;
   ch->t = t;
+  ch->blocked_fwd = GNUNET_YES;
+  ch->blocked_bck = GNUNET_YES;
 
   GNUNET_CONTAINER_DLL_insert (t->channel_head, t->channel_tail, ch);
 
@@ -4427,9 +4490,6 @@
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                   "*   raw: %s\n",
                   GNUNET_MESH_DEBUG_M2S (queue->type));
-      /* Fall through */
-    case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
-    case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
       data_size = send_core_data_raw (queue->cls, size, buf);
       msg = (struct GNUNET_MessageHeader *) buf;
       type = ntohs (msg->type);
@@ -4448,6 +4508,13 @@
       else
         data_size = send_core_data_raw (queue->cls, size, buf);
       break;
+    case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
+    case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
+    case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_CREATE:
+    case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
+      /* This should be encapsulted */
+      GNUNET_break (0);
+      break;
     default:
       GNUNET_break (0);
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "*   type unknown: %u\n",
@@ -6072,7 +6139,6 @@
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "  by client %u\n", c->id);
-  c->blocked = GNUNET_YES;
 
   msg = (struct GNUNET_MESH_LocalData *) message;
 
@@ -6110,6 +6176,11 @@
     return;
   }
 
+  if (fwd)
+    ch->blocked_fwd = GNUNET_YES;
+  else
+    ch->blocked_bck = GNUNET_YES;
+
   /* Ok, everything is correct, send the message
    * (pretend we got it from a mesh peer)
    */




reply via email to

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