-log
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.c
index e0315ed7cd3e4c322ed062e9fc264e8dc0b53378..b33737eba7fd5138bb88484b2e110f9818c28f37 100644 (file)
@@ -171,7 +171,7 @@ struct MeshConnection
   /**
    * ID of the connection.
    */
-  struct GNUNET_HashCode id;
+  struct GNUNET_MeshHash id;
 
   /**
    * State of the connection.
@@ -344,7 +344,23 @@ schedule_next_keepalive (struct MeshConnection *c, int fwd);
 
 
 /**
- * Get string description for tunnel state.
+ * Resets the connection timeout task, some other message has done the
+ * task's job.
+ * - For the first peer on the direction this means to send
+ *   a keepalive or a path confirmation message (either create or ACK).
+ * - For all other peers, this means to destroy the connection,
+ *   due to lack of activity.
+ * Starts the timeout if no timeout was running (connection just created).
+ *
+ * @param c Connection whose timeout to reset.
+ * @param fwd Is this forward?
+ */
+static void
+connection_reset_timeout (struct MeshConnection *c, int fwd);
+
+
+/**
+ * Get string description for tunnel state. Reentrant.
  *
  * @param s Tunnel state.
  *
@@ -397,9 +413,9 @@ fc_init (struct MeshFlowControl *fc)
  * @param cid Connection ID.
  */
 static struct MeshConnection *
-connection_get (const struct GNUNET_HashCode *cid)
+connection_get (const struct GNUNET_MeshHash *cid)
 {
-  return GNUNET_CONTAINER_multihashmap_get (connections, cid);
+  return GNUNET_CONTAINER_multihashmap_get (connections, GM_h2hc (cid));
 }
 
 
@@ -408,16 +424,13 @@ connection_change_state (struct MeshConnection* c,
                          enum MeshConnectionState state)
 {
   LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "Connection %s state was %s\n",
-              GMC_2s (c), GMC_state2s (c->state));
+       "Connection %s state %s -> %s\n",
+       GMC_2s (c), GMC_state2s (c->state), GMC_state2s (state));
   if (MESH_CONNECTION_DESTROYED == c->state)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "state not changing anymore\n");
     return;
   }
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "Connection %s state is now %s\n",
-              GMC_2s (c), GMC_state2s (state));
   c->state = state;
   if (MESH_CONNECTION_READY == state)
     c->create_retry = 1;
@@ -621,6 +634,7 @@ message_sent (void *cls,
              fc->last_pid_sent);
       }
       GMC_send_ack (c, fwd, GNUNET_NO);
+      connection_reset_timeout (c, fwd);
       break;
 
     case GNUNET_MESSAGE_TYPE_MESH_POLL:
@@ -673,21 +687,16 @@ get_prev_hop (const struct MeshConnection *c)
 {
   GNUNET_PEER_Id id;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  get prev hop %s [%u/%u]\n",
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " get prev hop %s [%u/%u]\n",
        GMC_2s (c), c->own_pos, c->path->length);
   if (0 == c->own_pos || c->path->length < 2)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  own pos is zero\n");
     id = c->path->peers[0];
-  }
   else
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  own pos is NOT zero\n");
     id = c->path->peers[c->own_pos - 1];
-  }
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  id: %u\n", id);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  ID: %s\n", GNUNET_i2s (GNUNET_PEER_resolve2 (id)));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  ID: %s (%u)\n",
+       GNUNET_i2s (GNUNET_PEER_resolve2 (id)), id);
+
   return GMP_get_short (id);
 }
 
@@ -704,21 +713,15 @@ get_next_hop (const struct MeshConnection *c)
 {
   GNUNET_PEER_Id id;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  get next hop %s [%u/%u]\n",
+  LOG (GNUNET_ERROR_TYPE_DEBUG, " get next hop %s [%u/%u]\n",
        GMC_2s (c), c->own_pos, c->path->length);
   if ((c->path->length - 1) == c->own_pos || c->path->length < 2)
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  own pos is end\n");
     id = c->path->peers[c->path->length - 1];
-  }
   else
-  {
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "  own pos is NOT end\n");
     id = c->path->peers[c->own_pos + 1];
-  }
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  id: %u\n", id);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  ID: %s\n", GNUNET_i2s (GNUNET_PEER_resolve2 (id)));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  ID: %s (%u)\n",
+       GNUNET_i2s (GNUNET_PEER_resolve2 (id)), id);
 
   return GMP_get_short (id);
 }
@@ -784,8 +787,8 @@ send_connection_ack (struct MeshConnection *connection, int fwd)
   struct MeshTunnel3 *t;
 
   t = connection->t;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection %s ACK\n",
-       GM_f2s (!fwd));
+  LOG (GNUNET_ERROR_TYPE_INFO, "=> {%18s ACK} on connection %s\n",
+       GM_f2s (!fwd), GMC_2s (connection));
   GMP_queue_add (get_hop (connection, fwd), NULL,
                  GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK,
                  sizeof (struct GNUNET_MESH_ConnectionACK),
@@ -833,7 +836,7 @@ send_broken (struct MeshConnection *c,
  * @param peer Peer to notify (neighbor who sent the connection).
  */
 static void
-send_broken2 (struct GNUNET_HashCode *connection_id,
+send_broken2 (struct GNUNET_MeshHash *connection_id,
              const struct GNUNET_PeerIdentity *id1,
              const struct GNUNET_PeerIdentity *id2,
              GNUNET_PEER_Id peer_id)
@@ -841,6 +844,9 @@ send_broken2 (struct GNUNET_HashCode *connection_id,
   struct GNUNET_MESH_ConnectionBroken *msg;
   struct MeshPeer *neighbor;
 
+  LOG (GNUNET_ERROR_TYPE_INFO, "=> BROKEN on unknown connection %s\n",
+       GNUNET_h2s (GM_h2hc (connection_id)));
+
   msg = GNUNET_new (struct GNUNET_MESH_ConnectionBroken);
   msg->header.size = htons (sizeof (struct GNUNET_MESH_ConnectionBroken));
   msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN);
@@ -863,23 +869,22 @@ send_broken2 (struct GNUNET_HashCode *connection_id,
  * @param fwd Is this a FWD keepalive? (owner -> dest).
  */
 static void
-connection_keepalive (struct MeshConnection *c, int fwd)
+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));
+  GNUNET_STATISTICS_update (stats, "# keepalives sent", 1, GNUNET_NO);
 
-  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));
 }
 
 
@@ -928,7 +933,7 @@ connection_maintain (struct MeshConnection *c, int fwd)
       connection_recreate (c, fwd);
       break;
     case MESH_CONNECTION_READY:
-      connection_keepalive (c, fwd);
+      send_connection_keepalive (c, fwd);
       break;
     default:
       break;
@@ -936,50 +941,64 @@ connection_maintain (struct MeshConnection *c, int fwd)
 }
 
 
+
 /**
- * Keep the connection alive in the FWD direction.
+ * Keep the connection alive.
  *
- * @param cls Closure (connection to keepalive).
- * @param tc TaskContext.
+ * @param c Connection to keep alive.
+ * @param fwd Direction.
+ * @param shutdown Are we shutting down? (Don't send traffic)
+ *                 Non-zero value for true, not necessarily GNUNET_YES.
  */
 static void
-connection_fwd_keepalive (void *cls,
-                          const struct GNUNET_SCHEDULER_TaskContext *tc)
+connection_keepalive (struct MeshConnection *c, int fwd, int shutdown)
 {
-  struct MeshConnection *c = cls;
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "%s keepalive for %s\n",
+       GM_f2s (fwd), GMC_2s (c));
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "FWD keepalive for %s\n", GMC_2s (c));
-  c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
+  if (fwd)
+    c->fwd_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
+  else
+    c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
+
+  if (GNUNET_NO != shutdown)
     return;
 
-  connection_maintain (c, GNUNET_YES);
+  connection_maintain (c, fwd);
 
   /* Next execution will be scheduled by message_sent */
 }
 
 
 /**
- * Keep the connection alive in the BCK direction.
- *
- * TODO refactor and merge with connection_fwd_keepalive.
+ * Keep the connection alive in the FWD direction.
  *
  * @param cls Closure (connection to keepalive).
  * @param tc TaskContext.
  */
 static void
-connection_bck_keepalive (void *cls,
+connection_fwd_keepalive (void *cls,
                           const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  struct MeshConnection *c = cls;
-
-  c->bck_maintenance_task = GNUNET_SCHEDULER_NO_TASK;
-  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
-    return;
+  connection_keepalive ((struct MeshConnection *) cls,
+                        GNUNET_YES,
+                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
+}
 
-  connection_maintain (c, GNUNET_NO);
 
-  /* Next execution will be scheduled by message_sent */
+/**
+ * Keep the connection alive in the BCK direction.
+ *
+ * @param cls Closure (connection to keepalive).
+ * @param tc TaskContext.
+ */
+static void
+connection_bck_keepalive (void *cls,
+                          const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  connection_keepalive ((struct MeshConnection *) cls,
+                        GNUNET_NO,
+                        tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN);
 }
 
 
@@ -1029,15 +1048,18 @@ schedule_next_keepalive (struct MeshConnection *c, int fwd)
     keepalive_task = &connection_bck_keepalive;
   }
 
-  /* Check that no one scheduled it before us (and alert in that case) */
+  /* Check that no one scheduled it before us */
   if (GNUNET_SCHEDULER_NO_TASK != *task_id)
   {
-    GNUNET_break (0);
+    /* No need for a _break. It can happen for instance when sending a SYNACK
+     * for a duplicate SYN: the first SYNACK scheduled the task. */
     GNUNET_SCHEDULER_cancel (*task_id);
   }
 
   /* Schedule the task */
   *task_id = GNUNET_SCHEDULER_add_delayed (delay, keepalive_task, c);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "next keepalive in %s\n",
+              GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
 }
 
 
@@ -1263,25 +1285,22 @@ connection_bck_timeout (void *cls,
 static void
 connection_reset_timeout (struct MeshConnection *c, int fwd)
 {
-  GNUNET_SCHEDULER_TaskIdentifier *ti;
-  GNUNET_SCHEDULER_Task f;
-
-  ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task;
-
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Connection %s reset timeout\n", GM_f2s (fwd));
 
-  if (GNUNET_SCHEDULER_NO_TASK != *ti)
-    GNUNET_SCHEDULER_cancel (*ti);
-
   if (GMC_is_origin (c, fwd)) /* Startpoint */
   {
-    f = fwd ? &connection_fwd_keepalive : &connection_bck_keepalive;
-    *ti = GNUNET_SCHEDULER_add_delayed (refresh_connection_time, f, c);
+    schedule_next_keepalive (c, fwd);
   }
   else /* Relay, endpoint. */
   {
     struct GNUNET_TIME_Relative delay;
+    GNUNET_SCHEDULER_TaskIdentifier *ti;
+    GNUNET_SCHEDULER_Task f;
 
+    ti = fwd ? &c->fwd_maintenance_task : &c->bck_maintenance_task;
+
+    if (GNUNET_SCHEDULER_NO_TASK != *ti)
+      GNUNET_SCHEDULER_cancel (*ti);
     delay = GNUNET_TIME_relative_multiply (refresh_connection_time, 4);
     f = fwd ? &connection_fwd_timeout : &connection_bck_timeout;
     *ti = GNUNET_SCHEDULER_add_delayed (delay, f, c);
@@ -1447,6 +1466,24 @@ build_path_from_peer_ids (struct GNUNET_PeerIdentity *peers,
   return path;
 }
 
+
+/**
+ * Log receipt of message on stderr (INFO level).
+ *
+ * @param message Message received.
+ * @param peer Peer who sent the message.
+ * @param hash Connection ID.
+ */
+static void
+log_message (const struct GNUNET_MessageHeader *message,
+             const struct GNUNET_PeerIdentity *peer,
+             const struct GNUNET_MeshHash *hash)
+{
+  LOG (GNUNET_ERROR_TYPE_INFO, "<- %s on connection %s from %s\n",
+       GM_m2s (ntohs (message->type)), GNUNET_h2s (GM_h2hc (hash)),
+       GNUNET_i2s (peer));
+}
+
 /******************************************************************************/
 /********************************    API    ***********************************/
 /******************************************************************************/
@@ -1467,7 +1504,7 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
 {
   struct GNUNET_MESH_ConnectionCreate *msg;
   struct GNUNET_PeerIdentity *id;
-  struct GNUNET_HashCode *cid;
+  struct GNUNET_MeshHash *cid;
   struct MeshPeerPath *path;
   struct MeshPeer *dest_peer;
   struct MeshPeer *orig_peer;
@@ -1475,9 +1512,6 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
   unsigned int own_pos;
   uint16_t size;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection create msg\n");
-
   /* Check size */
   size = ntohs (message->size);
   if (size < sizeof (struct GNUNET_MESH_ConnectionCreate))
@@ -1504,9 +1538,9 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
   /* Get parameters */
   msg = (struct GNUNET_MESH_ConnectionCreate *) message;
   cid = &msg->cid;
+  log_message (message, peer, cid);
   id = (struct GNUNET_PeerIdentity *) &msg[1];
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "    connection %s (%s->).\n",
-       GNUNET_h2s (cid), GNUNET_i2s (id));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "    origin: %s\n", GNUNET_i2s (id));
 
   /* Create connection */
   c = connection_get (cid);
@@ -1602,11 +1636,8 @@ GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
   enum MeshConnectionState oldstate;
   int fwd;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection ACK msg\n");
   msg = (struct GNUNET_MESH_ConnectionACK *) message;
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  on connection %s\n",
-              GNUNET_h2s (&msg->cid));
+  log_message (message, peer, &msg->cid);
   c = connection_get (&msg->cid);
   if (NULL == c)
   {
@@ -1728,9 +1759,8 @@ GMC_handle_broken (void* cls,
   struct MeshConnection *c;
   int fwd;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "Received a CONNECTION BROKEN msg from %s\n", GNUNET_i2s (id));
   msg = (struct GNUNET_MESH_ConnectionBroken *) message;
+  log_message (message, id, &msg->cid);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  regarding %s\n",
               GNUNET_i2s (&msg->peer1));
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  regarding %s\n",
@@ -1782,12 +1812,7 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
   int fwd;
 
   msg = (struct GNUNET_MESH_ConnectionDestroy *) message;
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "Got a CONNECTION DESTROY message from %s\n",
-              GNUNET_i2s (peer));
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-              "  for connection %s\n",
-              GNUNET_h2s (&msg->cid));
+  log_message (message, peer, &msg->cid);
   c = connection_get (&msg->cid);
   if (NULL == c)
   {
@@ -1844,10 +1869,11 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
   GNUNET_PEER_Id peer_id;
   uint32_t pid;
   uint32_t ttl;
-  uint16_t type;
   size_t size;
   int fwd;
 
+  log_message (&msg->header, peer, &msg->cid);
+
   /* Check size */
   size = ntohs (msg->header.size);
   if (size <
@@ -1857,22 +1883,18 @@ handle_mesh_encrypted (const struct GNUNET_PeerIdentity *peer,
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-  type = ntohs (msg->header.type);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message (#%u) from %s\n",
-       GM_m2s (type), ntohl (msg->pid), GNUNET_i2s (peer));
 
   /* Check connection */
   c = connection_get (&msg->cid);
   if (NULL == c)
   {
     GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING enc on unknown connection %s\n",
-         GNUNET_h2s (&msg->cid));
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "enc on unknown connection %s\n",
+         GNUNET_h2s (GM_h2hc (&msg->cid)));
     return GNUNET_OK;
   }
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "  on connection %s\n", GMC_2s (c));
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "  connection %s\n", GMC_2s (c));
 
   /* Check if origin is as expected */
   neighbor = get_prev_hop (c);
@@ -1972,30 +1994,27 @@ handle_mesh_kx (const struct GNUNET_PeerIdentity *peer,
   struct MeshPeer *neighbor;
   GNUNET_PEER_Id peer_id;
   size_t size;
-  uint16_t type;
   int fwd;
 
+  log_message (&msg->header, peer, &msg->cid);
+
   /* Check size */
   size = ntohs (msg->header.size);
   if (size <
-      sizeof (struct GNUNET_MESH_Encrypted) +
+      sizeof (struct GNUNET_MESH_KX) +
       sizeof (struct GNUNET_MessageHeader))
   {
     GNUNET_break_op (0);
     return GNUNET_OK;
   }
-  type = ntohs (msg->header.type);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "got a %s message from %s\n",
-       GM_m2s (type), GNUNET_i2s (peer));
 
   /* Check connection */
   c = connection_get (&msg->cid);
   if (NULL == c)
   {
     GNUNET_STATISTICS_update (stats, "# unknown connection", 1, GNUNET_NO);
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "WARNING kx on unknown connection %s\n",
-         GNUNET_h2s (&msg->cid));
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "kx on unknown connection %s\n",
+         GNUNET_h2s (GM_h2hc (&msg->cid)));
     return GNUNET_OK;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, " on connection %s\n", GMC_2s (c));
@@ -2116,13 +2135,9 @@ GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
   uint32_t ack;
   int fwd;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK packet from %s!\n",
-              GNUNET_i2s (peer));
   msg = (struct GNUNET_MESH_ACK *) message;
-
+  log_message (message, peer, &msg->cid);
   c = connection_get (&msg->cid);
-
   if (NULL == c)
   {
     GNUNET_STATISTICS_update (stats, "# ack on unknown connection", 1,
@@ -2193,22 +2208,16 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
   uint32_t pid;
   int fwd;
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n");
-  LOG (GNUNET_ERROR_TYPE_DEBUG,
-       "Got a POLL message from %s!\n",
-       GNUNET_i2s (peer));
-
   msg = (struct GNUNET_MESH_Poll *) message;
-
+  log_message (message, peer, &msg->cid);
   c = connection_get (&msg->cid);
-
   if (NULL == c)
   {
     GNUNET_STATISTICS_update (stats, "# poll on unknown connection", 1,
                               GNUNET_NO);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "WARNING POLL message on unknown connection %s!\n",
-         GNUNET_h2s (&msg->cid));
+         GNUNET_h2s (GM_h2hc (&msg->cid)));
     return GNUNET_OK;
   }
 
@@ -2244,73 +2253,6 @@ GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
 }
 
 
-/**
- * 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 (GNUNET_ERROR_TYPE_DEBUG, "got a keepalive packet from %s\n",
-              GNUNET_i2s (peer));
-
-  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.
@@ -2447,7 +2389,7 @@ GMC_shutdown (void)
 
 
 struct MeshConnection *
-GMC_new (const struct GNUNET_HashCode *cid,
+GMC_new (const struct GNUNET_MeshHash *cid,
          struct MeshTunnel3 *t,
          struct MeshPeerPath *p,
          unsigned int own_pos)
@@ -2458,7 +2400,7 @@ GMC_new (const struct GNUNET_HashCode *cid,
   c->id = *cid;
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONTAINER_multihashmap_put (connections,
-                                                    &c->id, c,
+                                                    GMC_get_h (c), c,
                                                     GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   fc_init (&c->fwd_fc);
   fc_init (&c->bck_fc);
@@ -2550,7 +2492,8 @@ GMC_destroy (struct MeshConnection *c)
   }
 
   GNUNET_break (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_remove (connections, &c->id, c));
+                GNUNET_CONTAINER_multihashmap_remove (connections,
+                                                      GMC_get_h (c), c));
 
   GNUNET_STATISTICS_update (stats, "# connections", -1, GNUNET_NO);
   GNUNET_free (c);
@@ -2563,13 +2506,27 @@ GMC_destroy (struct MeshConnection *c)
  *
  * @return ID of the connection.
  */
-const struct GNUNET_HashCode *
+const struct GNUNET_MeshHash *
 GMC_get_id (const struct MeshConnection *c)
 {
   return &c->id;
 }
 
 
+/**
+ * Get the connection ID.
+ *
+ * @param c Connection to get the ID from.
+ *
+ * @return ID of the connection.
+ */
+const struct GNUNET_HashCode *
+GMC_get_h (const struct MeshConnection *c)
+{
+  return GM_h2hc (&c->id);
+}
+
+
 /**
  * Get the connection path.
  *
@@ -2824,8 +2781,8 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
   data = GNUNET_malloc (size);
   memcpy (data, message, size);
   type = ntohs (message->type);
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send %s (%u bytes) on connection %s\n",
-       GM_m2s (type), size, GMC_2s (c));
+  LOG (GNUNET_ERROR_TYPE_INFO, "-> %s on connection %s (%u bytes)\n",
+       GM_m2s (type), GMC_2s (c), size);
 
   fc = fwd ? &c->fwd_fc : &c->bck_fc;
   droppable = GNUNET_NO == force;
@@ -2891,18 +2848,18 @@ GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_DESTROY:
       dmsg = (struct GNUNET_MESH_ConnectionDestroy *) data;
       dmsg->cid = c->id;
-      dmsg->reserved = 0;
       break;
 
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_BROKEN:
       bmsg = (struct GNUNET_MESH_ConnectionBroken *) data;
       bmsg->cid = c->id;
-      bmsg->reserved = 0;
       break;
 
+    case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
+      GNUNET_break (0);
+      /* falltrough */
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE:
     case GNUNET_MESSAGE_TYPE_MESH_CONNECTION_ACK:
-    case GNUNET_MESSAGE_TYPE_MESH_KEEPALIVE:
       break;
 
     default:
@@ -2982,7 +2939,9 @@ GMC_send_create (struct MeshConnection *connection)
   size = sizeof (struct GNUNET_MESH_ConnectionCreate);
   size += connection->path->length * sizeof (struct GNUNET_PeerIdentity);
 
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Send connection create\n");
+  LOG (GNUNET_ERROR_TYPE_INFO, "=> %s on connection %s  (%u bytes)\n",
+       GM_m2s (GNUNET_MESSAGE_TYPE_MESH_CONNECTION_CREATE),
+       GMC_2s (connection), size);
   LOG (GNUNET_ERROR_TYPE_DEBUG, "  C_P+ %p %u (create)\n",
        connection, connection->pending_messages);
   connection->pending_messages++;
@@ -3102,8 +3061,8 @@ GMC_2s (const struct MeshConnection *c)
   {
     static char buf[128];
 
-    sprintf (buf, "%s (->%s)", GNUNET_h2s (&c->id), GMT_2s (c->t));
+    sprintf (buf, "%s (->%s)", GNUNET_h2s (GM_h2hc (GMC_get_id(c))), GMT_2s (c->t));
     return buf;
   }
-  return GNUNET_h2s (&c->id);
+  return GNUNET_h2s (GM_h2hc (&c->id));
 }