gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r30145 - gnunet/src/mesh
Date: Fri, 11 Oct 2013 16:07:47 +0200

Author: bartpolot
Date: 2013-10-11 16:07:47 +0200 (Fri, 11 Oct 2013)
New Revision: 30145

Modified:
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.h
Log:
- fix encryption/decryption visisbility


Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-11 13:42:26 UTC 
(rev 30144)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2013-10-11 14:07:47 UTC 
(rev 30145)
@@ -438,7 +438,7 @@
  * @return Previous peer in the connection.
  */
 static struct MeshPeer *
-get_prev_hop (struct MeshConnection *c)
+get_prev_hop (const struct MeshConnection *c)
 {
   GNUNET_PEER_Id id;
 
@@ -459,7 +459,7 @@
  * @return Next peer in the connection.
  */
 static struct MeshPeer *
-get_next_hop (struct MeshConnection *c)
+get_next_hop (const struct MeshConnection *c)
 {
   GNUNET_PEER_Id id;
 
@@ -1305,7 +1305,6 @@
                        int fwd)
 {
   struct MeshConnection *c;
-  struct MeshTunnel3 *t;
   struct MeshPeer *neighbor;
   struct MeshFlowControl *fc;
   uint32_t pid;
@@ -1335,7 +1334,7 @@
     LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING connection unknown\n");
     return GNUNET_OK;
   }
-  t = c->t;
+
   fc = fwd ? &c->bck_fc : &c->fwd_fc;
 
   /* Check if origin is as expected */
@@ -1372,24 +1371,17 @@
   /* Is this message for us? */
   if (GMC_is_terminal (c, fwd))
   {
-    size_t dsize = size - sizeof (struct GNUNET_MESH_Encrypted);
-    char cbuf[dsize];
-    struct GNUNET_MessageHeader *msgh;
-    unsigned int off;
-
     /* TODO signature verification */
     LOG (GNUNET_ERROR_TYPE_DEBUG, "  message for us!\n");
     GNUNET_STATISTICS_update (stats, "# messages received", 1, GNUNET_NO);
 
-    fc->last_pid_recv = pid;
-    tunnel_decrypt (t, cbuf, &msg[1], dsize, msg->iv, fwd);
-    off = 0;
-    while (off < dsize)
+    if (NULL == c->t)
     {
-      msgh = (struct GNUNET_MessageHeader *) &cbuf[off];
-      handle_decrypted (t, msgh, fwd);
-      off += ntohs (msgh->size);
+      GNUNET_break (0);
+      return GNUNET_OK;
     }
+    fc->last_pid_recv = pid;
+    GMT_handle_encrypted (c->t, msg, fwd);
     send_ack (c, NULL, fwd);
     return GNUNET_OK;
   }

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-11 13:42:26 UTC 
(rev 30144)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2013-10-11 14:07:47 UTC 
(rev 30145)
@@ -257,6 +257,48 @@
 }
 
 
+/**
+ * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
+ * Encrypt data with the tunnel key.
+ * Make static?
+ *
+ * @param t Tunnel whose key to use.
+ * @param dst Destination for the GMT_encrypted data.
+ * @param src Source of the plaintext.
+ * @param size Size of the plaintext.
+ * @param iv Initialization Vector to use.
+ * @param fwd Is this a fwd message?
+ */
+static void
+GMT_encrypt (struct MeshTunnel3 *t,
+             void *dst, const void *src,
+             size_t size, uint64_t iv, int fwd)
+{
+  memcpy (dst, src, size);
+}
+
+
+/**
+ * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
+ * Decrypt data with the tunnel key.
+ * Make static?
+ *
+ * @param t Tunnel whose key to use.
+ * @param dst Destination for the plaintext.
+ * @param src Source of the GMT_encrypted data.
+ * @param size Size of the GMT_encrypted data.
+ * @param iv Initialization Vector to use.
+ * @param fwd Is this a fwd message?
+ */
+static void
+GMT_decrypt (struct MeshTunnel3 *t,
+             void *dst, const void *src,
+             size_t size, uint64_t iv, int fwd)
+{
+  memcpy (dst, src, size);
+}
+
+
 void
 handle_data (struct MeshTunnel3 *t,
              const struct GNUNET_MESH_Data *msg,
@@ -417,9 +459,6 @@
   GMCH_handle_destroy (ch, msg, fwd);
 }
 
-/******************************************************************************/
-/********************************    API    
***********************************/
-/******************************************************************************/
 
 /**
  * Demultiplex by message type and call appropriate handler for a message
@@ -429,10 +468,10 @@
  * @param msgh Message header.
  * @param fwd Is this message fwd?
  */
-void
-GMT_handle_decrypted (struct MeshTunnel3 *t,
-                      const struct GNUNET_MessageHeader *msgh,
-                      int fwd)
+static void
+handle_GMT_decrypted (struct MeshTunnel3 *t,
+                  const struct GNUNET_MessageHeader *msgh,
+                  int fwd)
 {
   uint16_t type;
 
@@ -478,8 +517,42 @@
   }
 }
 
+/******************************************************************************/
+/********************************    API    
***********************************/
+/******************************************************************************/
 
+
 /**
+ * Decrypt and demultiplex by message type. Call appropriate handler
+ * for every message.
+ *
+ * @param t Tunnel this message came on.
+ * @param msgh Encrypted message.
+ * @param fwd Is this message fwd?
+ */
+void
+GMT_handle_GMT_encrypted (struct MeshTunnel3 *t,
+                      const struct GNUNET_MESH_Encrypted *msg,
+                      int fwd)
+{
+  size_t size = ntohs (msg->header.size);
+  size_t payload_size = size - sizeof (struct GNUNET_MESH_Encrypted);
+  char cbuf[payload_size];
+  struct GNUNET_MessageHeader *msgh;
+  unsigned int off;
+
+  GMT_decrypt (t, cbuf, &msg[1], payload_size, msg->iv, fwd);
+  off = 0;
+  while (off < payload_size)
+  {
+    msgh = (struct GNUNET_MessageHeader *) &cbuf[off];
+    handle_GMT_decrypted (t, msgh, fwd);
+    off += ntohs (msgh->size);
+  }
+}
+
+
+/**
  * Cache a message to be sent once tunnel is online.
  *
  * @param t Tunnel to hold the message.
@@ -868,48 +941,6 @@
 
 
 /**
- * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
- * Encrypt data with the tunnel key.
- * Make static?
- *
- * @param t Tunnel whose key to use.
- * @param dst Destination for the encrypted data.
- * @param src Source of the plaintext.
- * @param size Size of the plaintext.
- * @param iv Initialization Vector to use.
- * @param fwd Is this a fwd message?
- */
-void
-GMT_encrypt (struct MeshTunnel3 *t,
-             void *dst, const void *src,
-             size_t size, uint64_t iv, int fwd)
-{
-  memcpy (dst, src, size);
-}
-
-
-/**
- * FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME FIXME
- * Decrypt data with the tunnel key.
- * Make static?
- *
- * @param t Tunnel whose key to use.
- * @param dst Destination for the plaintext.
- * @param src Source of the encrypted data.
- * @param size Size of the encrypted data.
- * @param iv Initialization Vector to use.
- * @param fwd Is this a fwd message?
- */
-void
-GMT_decrypt (struct MeshTunnel3 *t,
-             void *dst, const void *src,
-             size_t size, uint64_t iv, int fwd)
-{
-  memcpy (dst, src, size);
-}
-
-
-/**
  * Count established (ready) connections of a tunnel.
  *
  * @param t Tunnel on which to count.
@@ -1056,7 +1087,7 @@
 
 
 /**
- * Sends an already built message on a tunnel, encrypting it and
+ * Sends an already built message on a tunnel, GMT_encrypting it and
  * choosing the best connection.
  *
  * @param message Message to send. Function modifies it.

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2013-10-11 13:42:26 UTC 
(rev 30144)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2013-10-11 14:07:47 UTC 
(rev 30145)
@@ -79,6 +79,7 @@
 
 #include "gnunet-service-mesh_channel.h"
 #include "gnunet-service-mesh_connection.h"
+#include "gnunet-service-mesh_peer.h"
 
 
 
/******************************************************************************/
@@ -197,6 +198,19 @@
 struct MeshChannel *
 GMT_get_channel (struct MeshTunnel3 *t, MESH_ChannelNumber chid);
 
+/**
+ * Decrypt and demultiplex by message type. Call appropriate handler
+ * for a message
+ * towards a channel of a local tunnel.
+ *
+ * @param t Tunnel this message came on.
+ * @param msgh Message header.
+ * @param fwd Is this message fwd?
+ */
+void
+GMT_handle_encrypted (struct MeshTunnel3 *t,
+                      const struct GNUNET_MESH_Encrypted *msg,
+                      int fwd);
 
 /**
  * Cache a message to be sent once tunnel is online.




reply via email to

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