gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r32542 - gnunet/src/mesh
Date: Thu, 6 Mar 2014 02:36:20 +0100

Author: bartpolot
Date: 2014-03-06 02:36:20 +0100 (Thu, 06 Mar 2014)
New Revision: 32542

Modified:
   gnunet/src/mesh/gnunet-service-mesh_channel.c
   gnunet/src/mesh/gnunet-service-mesh_connection.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.c
   gnunet/src/mesh/gnunet-service-mesh_tunnel.h
   gnunet/src/mesh/mesh_protocol.h
Log:
Move mesh connection keepalive messages inside tunnel encryption to reduce 
information leakage.

Modified: gnunet/src/mesh/gnunet-service-mesh_channel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_channel.c       2014-03-06 01:36:18 UTC 
(rev 32541)
+++ gnunet/src/mesh/gnunet-service-mesh_channel.c       2014-03-06 01:36:20 UTC 
(rev 32542)
@@ -857,8 +857,8 @@
                  struct MeshChannel *ch,
                  int force)
 {
-  GNUNET_break (NULL == GMT_send_prebuilt_message (msg, ch->t, force,
-                                                   NULL, NULL));
+  GNUNET_break (NULL == GMT_send_prebuilt_message (msg, ch->t, NULL,
+                                                   force, NULL, NULL));
 }
 
 
@@ -2290,9 +2290,9 @@
         }
         LOG (GNUNET_ERROR_TYPE_DEBUG, "  new chq: %p\n", chq);
             chq->copy->chq = chq;
-            chq->tq = GMT_send_prebuilt_message (message, ch->t,
-                                          NULL != existing_copy,
-                                          &ch_message_sent, chq);
+            chq->tq = GMT_send_prebuilt_message (message, ch->t, NULL,
+                                                 NULL != existing_copy,
+                                                 &ch_message_sent, chq);
         /* q itself is stored in copy */
         GNUNET_assert (NULL != chq->tq || GNUNET_NO != ch->destroy);
       }
@@ -2329,7 +2329,7 @@
           GNUNET_free (chq->rel->uniq);
         }
       }
-      chq->tq = GMT_send_prebuilt_message (message, ch->t, GNUNET_YES,
+      chq->tq = GMT_send_prebuilt_message (message, ch->t, NULL, GNUNET_YES,
                                            &ch_message_sent, chq);
       if (NULL == chq->tq)
       {

Modified: gnunet/src/mesh/gnunet-service-mesh_connection.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_connection.c    2014-03-06 01:36:18 UTC 
(rev 32541)
+++ gnunet/src/mesh/gnunet-service-mesh_connection.c    2014-03-06 01:36:20 UTC 
(rev 32542)
@@ -857,21 +857,19 @@
 static void
 send_connection_keepalive (struct MeshConnection *c, int fwd)
 {
-  struct GNUNET_MESH_ConnectionKeepAlive *msg;
-  size_t size = sizeof (struct GNUNET_MESH_ConnectionKeepAlive);
-  char cbuf[size];
+  struct GNUNET_MessageHeader msg;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "sending %s keepalive for connection %s]\n",
+  LOG (GNUNET_ERROR_TYPE_INFO,
+       "keepalive %s for connection %s\n",
        GM_f2s (fwd), GMC_2s (c));
 
-  msg = (struct GNUNET_MESH_ConnectionKeepAlive *) cbuf;
-  msg->header.size = htons (size);
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE);
-  msg->cid = c->id;
-  msg->reserved = htonl (0);
+  GNUNET_assert (NULL != c->t);
+  msg.size = htons (sizeof (msg));
+  msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE);
 
-  GMC_send_prebuilt_message (&msg->header, c, fwd, GNUNET_YES, NULL, NULL);
+  GNUNET_assert (NULL ==
+                 GMT_send_prebuilt_message (&msg, c->t, c,
+                                            GNUNET_NO, NULL, NULL));
 }
 
 
@@ -2241,71 +2239,6 @@
 
 
 /**
- * Core handler for mesh keepalives.
- *
- * @param cls closure
- * @param message message
- * @param peer peer identity this notification is about
- * @return GNUNET_OK to keep the connection open,
- *         GNUNET_SYSERR to close it (signal serious error)
- *
- * TODO: Check who we got this from, to validate route.
- */
-int
-GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
-                      const struct GNUNET_MessageHeader *message)
-{
-  struct GNUNET_MESH_ConnectionKeepAlive *msg;
-  struct MeshConnection *c;
-  struct MeshPeer *neighbor;
-  GNUNET_PEER_Id peer_id;
-  int fwd;
-
-  msg = (struct GNUNET_MESH_ConnectionKeepAlive *) message;
-  log_message (message, peer, &msg->cid);
-  c = connection_get (&msg->cid);
-  if (NULL == c)
-  {
-    GNUNET_STATISTICS_update (stats, "# keepalive on unknown connection", 1,
-                              GNUNET_NO);
-    return GNUNET_OK;
-  }
-
-  /* Check if origin is as expected TODO refactor and reuse */
-  peer_id = GNUNET_PEER_search (peer);
-  neighbor = get_prev_hop (c);
-  if (peer_id == GMP_get_short_id (neighbor))
-  {
-    fwd = GNUNET_YES;
-  }
-  else
-  {
-    neighbor = get_next_hop (c);
-    if (peer_id == GMP_get_short_id (neighbor))
-    {
-      fwd = GNUNET_NO;
-    }
-    else
-    {
-      GNUNET_break_op (0);
-      return GNUNET_OK;
-    }
-  }
-
-  connection_change_state (c, MESH_CONNECTION_READY);
-  connection_reset_timeout (c, fwd);
-
-  if (GMC_is_terminal (c, fwd))
-    return GNUNET_OK;
-
-  GNUNET_STATISTICS_update (stats, "# keepalives forwarded", 1, GNUNET_NO);
-  GMC_send_prebuilt_message (message, c, fwd, GNUNET_YES, NULL, NULL);
-
-  return GNUNET_OK;
-}
-
-
-/**
  * Send an ACK on the appropriate connection/channel, depending on
  * the direction and the position of the peer.
  *

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2014-03-06 01:36:18 UTC 
(rev 32541)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.c        2014-03-06 01:36:20 UTC 
(rev 32542)
@@ -724,6 +724,7 @@
  *
  * @param message Message to send. Function modifies it.
  * @param t Tunnel on which this message is transmitted.
+ * @param c Connection to use (autoselect if NULL).
  * @param force Force the tunnel to take the message (buffer overfill).
  * @param cont Continuation to call once message is really sent.
  * @param cont_cls Closure for @c cont.
@@ -735,12 +736,11 @@
  */
 static struct MeshTunnel3Queue *
 send_prebuilt_message (const struct GNUNET_MessageHeader *message,
-                       struct MeshTunnel3 *t, int force,
-                       GMT_sent cont, void *cont_cls,
+                       struct MeshTunnel3 *t, struct MeshConnection *c,
+                       int force, GMT_sent cont, void *cont_cls,
                        struct MeshTunnel3Queue *existing_q)
 {
   struct MeshTunnel3Queue *tq;
-  struct MeshConnection *c;
   struct GNUNET_MESH_Encrypted *msg;
   size_t size = ntohs (message->size);
   char cbuf[sizeof (struct GNUNET_MESH_Encrypted) + size];
@@ -776,8 +776,9 @@
   msg->iv = iv;
   GNUNET_assert (t_encrypt (t, &msg[1], message, size, iv) == size);
   msg->header.size = htons (sizeof (struct GNUNET_MESH_Encrypted) + size);
-  c = tunnel_get_connection (t);
   if (NULL == c)
+    c = tunnel_get_connection (t);
+  if (NULL == c)
   {
     if (GNUNET_SCHEDULER_NO_TASK != t->destroy_task
         || MESH_TUNNEL3_SEARCHING != t->cstate)
@@ -868,7 +869,7 @@
     next = tqd->next;
     room--;
     send_prebuilt_message ((struct GNUNET_MessageHeader *) &tqd[1],
-                           tqd->t, GNUNET_YES,
+                           tqd->t, NULL, GNUNET_YES,
                            NULL != tqd->tq ? tqd->tq->cont : NULL,
                            NULL != tqd->tq ? tqd->tq->cont_cls : NULL,
                            tqd->tq);
@@ -1179,7 +1180,7 @@
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "WARNING destroying unknown channel %u on tunnel %s\n",
        gid, GMT_2s (t));
-  send_prebuilt_message (&msg.header, t, GNUNET_YES, NULL, NULL, NULL);
+  send_prebuilt_message (&msg.header, t, NULL, GNUNET_YES, NULL, NULL, NULL);
 }
 
 
@@ -1552,6 +1553,10 @@
 
   switch (type)
   {
+    case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
+      /* Do nothing, connection aleady got updated. */
+      break;
+
     case GNUNET_MESSAGE_TYPE_MESH_DATA:
       /* Don't send hop ACK, wait for client to ACK */
       handle_data (t, (struct GNUNET_MESH_Data *) msgh, fwd);
@@ -1585,7 +1590,7 @@
 
     default:
       GNUNET_break_op (0);
-      LOG (GNUNET_ERROR_TYPE_DEBUG,
+      LOG (GNUNET_ERROR_TYPE_WARNING,
            "end-to-end message not known (%u)\n",
            ntohs (msgh->type));
       GMT_debug (t);
@@ -2506,10 +2511,11 @@
 
 /**
  * Sends an already built message on a tunnel, encrypting it and
- * choosing the best connection.
+ * choosing the best connection if not provided.
  *
  * @param message Message to send. Function modifies it.
  * @param t Tunnel on which this message is transmitted.
+ * @param c Connection to use (autoselect if NULL).
  * @param force Force the tunnel to take the message (buffer overfill).
  * @param cont Continuation to call once message is really sent.
  * @param cont_cls Closure for @c cont.
@@ -2518,10 +2524,10 @@
  */
 struct MeshTunnel3Queue *
 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
-                           struct MeshTunnel3 *t, int force,
-                           GMT_sent cont, void *cont_cls)
+                           struct MeshTunnel3 *t, struct MeshConnection *c,
+                           int force, GMT_sent cont, void *cont_cls)
 {
-  return send_prebuilt_message (message, t, force, cont, cont_cls, NULL);
+  return send_prebuilt_message (message, t, c, force, cont, cont_cls, NULL);
 }
 
 

Modified: gnunet/src/mesh/gnunet-service-mesh_tunnel.h
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2014-03-06 01:36:18 UTC 
(rev 32541)
+++ gnunet/src/mesh/gnunet-service-mesh_tunnel.h        2014-03-06 01:36:20 UTC 
(rev 32542)
@@ -419,6 +419,7 @@
  *
  * @param message Message to send. Function modifies it.
  * @param t Tunnel on which this message is transmitted.
+ * @param c Connection to use (autoselect if NULL).
  * @param force Force the tunnel to take the message (buffer overfill).
  * @param cont Continuation to call once message is really sent.
  * @param cont_cls Closure for @c cont.
@@ -427,8 +428,8 @@
  */
 struct MeshTunnel3Queue *
 GMT_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
-                           struct MeshTunnel3 *t, int force,
-                           GMT_sent cont, void *cont_cls);
+                           struct MeshTunnel3 *t, struct MeshConnection *c,
+                           int force, GMT_sent cont, void *cont_cls);
 
 /**
  * Is the tunnel directed towards the local peer?

Modified: gnunet/src/mesh/mesh_protocol.h
===================================================================
--- gnunet/src/mesh/mesh_protocol.h     2014-03-06 01:36:18 UTC (rev 32541)
+++ gnunet/src/mesh/mesh_protocol.h     2014-03-06 01:36:20 UTC (rev 32542)
@@ -455,29 +455,6 @@
 };
 
 
-/**
- * Message to keep a connection alive.
- */
-struct GNUNET_MESH_ConnectionKeepAlive
-{
-  /**
-   * Type: GNUNET_MESSAGE_TYPE_MESH_(FWD|BCK)_KEEPALIVE
-   */
-  struct GNUNET_MessageHeader header;
-
-  /**
-   * Always 0.
-   */
-  uint32_t reserved GNUNET_PACKED;
-
-  /**
-   * ID of the connection.
-   */
-  struct GNUNET_HashCode cid;
-};
-
-
-
 GNUNET_NETWORK_STRUCT_END
 
 #if 0                           /* keep Emacsens' auto-indent happy */




reply via email to

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