convert fs publish to MQ
[oweals/gnunet.git] / src / core / gnunet-service-core_clients.c
index bcbb56ef3d9a5d3d802aa258b688b0e42f823942..c2198848fea452ac4d67f65e7895cd8902bf0453 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2009, 2010, 2011 GNUnet e.V.
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -14,8 +14,8 @@
 
      You should have received a copy of the GNU General Public License
      along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
 */
 
 /**
@@ -29,6 +29,7 @@
 #include "gnunet_transport_service.h"
 #include "gnunet-service-core.h"
 #include "gnunet-service-core_clients.h"
+#include "gnunet-service-core_neighbours.h"
 #include "gnunet-service-core_sessions.h"
 #include "gnunet-service-core_typemap.h"
 #include "core.h"
@@ -43,7 +44,7 @@
 
 
 /**
- * Data structure for each client connected to the core service.
+ * Data structure for each client connected to the CORE service.
  */
 struct GSC_Client
 {
@@ -64,14 +65,14 @@ struct GSC_Client
 
   /**
    * Array of the types of messages this peer cares
-   * about (with "tcnt" entries).  Allocated as part
+   * about (with @e tcnt entries).  Allocated as part
    * of this client struct, do not free!
    */
   const uint16_t *types;
 
   /**
    * Map of peer identities to active transmission requests of this
-   * client to the peer (of type 'struct GSC_ClientActiveRequest').
+   * client to the peer (of type `struct GSC_ClientActiveRequest`).
    */
   struct GNUNET_CONTAINER_MultiPeerMap *requests;
 
@@ -88,7 +89,7 @@ struct GSC_Client
 
   /**
    * Number of types of incoming messages this client
-   * specifically cares about.  Size of the "types" array.
+   * specifically cares about.  Size of the @e types array.
    */
   unsigned int tcnt;
 
@@ -149,7 +150,8 @@ find_client (struct GNUNET_SERVER_Client *client)
  */
 static void
 send_to_client (struct GSC_Client *client,
-                const struct GNUNET_MessageHeader *msg, int can_drop)
+                const struct GNUNET_MessageHeader *msg,
+                int can_drop)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Preparing to send %u bytes of message of type %u to client.\n",
@@ -190,15 +192,16 @@ GSC_CLIENTS_send_to_client (struct GNUNET_SERVER_Client *client,
  *
  * @param type message type
  * @param c client to test
- * @return GNUNET_YES if 'c' is interested, GNUNET_NO if not.
+ * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not.
  */
 static int
 type_match (uint16_t type, struct GSC_Client *c)
 {
   unsigned int i;
 
-  if (c->tcnt == 0)
-    return GNUNET_YES;          /* peer without handlers matches ALL */
+  if (c->tcnt == 0 && c->options != 0)
+    return GNUNET_YES;          /* peer without handlers and inbound/outbond
+                                  callbacks matches ALL */
   for (i = 0; i < c->tcnt; i++)
     if (type == c->types[i])
       return GNUNET_YES;
@@ -219,13 +222,15 @@ type_match (uint16_t type, struct GSC_Client *c)
  */
 static void
 send_to_all_clients (const struct GNUNET_PeerIdentity *partner,
-                     const struct GNUNET_MessageHeader *msg, int can_drop,
-                     uint32_t options, uint16_t type)
+                     const struct GNUNET_MessageHeader *msg,
+                     int can_drop,
+                     uint32_t options,
+                     uint16_t type)
 {
   struct GSC_Client *c;
   int tm;
 
-  for (c = client_head; c != NULL; c = c->next)
+  for (c = client_head; NULL != c; c = c->next)
   {
     tm = type_match (type, c);
     if (!  ( (0 != (c->options & options)) ||
@@ -255,14 +260,15 @@ send_to_all_clients (const struct GNUNET_PeerIdentity *partner,
 
 
 /**
- * Handle CORE_INIT request.
+ * Handle #GNUNET_MESSAGE_TYPE_CORE_INIT request.
  *
  * @param cls unused
- * @param client new client that sent INIT
- * @param message the 'struct InitMessage' (presumably)
+ * @param client new client that sent #GNUNET_MESSAGE_TYPE_CORE_INIT
+ * @param message the `struct InitMessage` (presumably)
  */
 static void
-handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
+handle_client_init (void *cls,
+                    struct GNUNET_SERVER_Client *client,
                     const struct GNUNET_MessageHeader *message)
 {
   const struct InitMessage *im;
@@ -324,14 +330,15 @@ handle_client_init (void *cls, struct GNUNET_SERVER_Client *client,
 
 
 /**
- * Handle CORE_SEND_REQUEST message.
+ * Handle #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST message.
  *
  * @param cls unused
- * @param client new client that sent CORE_SEND_REQUEST
- * @param message the 'struct SendMessageRequest' (presumably)
+ * @param client new client that sent a #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
+ * @param message the `struct SendMessageRequest` (presumably)
  */
 static void
-handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
+handle_client_send_request (void *cls,
+                            struct GNUNET_SERVER_Client *client,
                             const struct GNUNET_MessageHeader *message)
 {
   const struct SendMessageRequest *req;
@@ -341,23 +348,26 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
 
   req = (const struct SendMessageRequest *) message;
   c = find_client (client);
-  if (c == NULL)
+  if (NULL == c)
   {
     /* client did not send INIT first! */
     GNUNET_break (0);
-    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_SYSERR);
     return;
   }
-  if (c->requests == NULL)
-    c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO);
+  if (NULL == c->requests)
+    c->requests = GNUNET_CONTAINER_multipeermap_create (16,
+                                                        GNUNET_NO);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Client asked for transmission to `%s'\n",
               GNUNET_i2s (&req->peer));
   is_loopback =
       (0 ==
-       memcmp (&req->peer, &GSC_my_identity,
+       memcmp (&req->peer,
+               &GSC_my_identity,
                sizeof (struct GNUNET_PeerIdentity)));
-  if ((!is_loopback) &&
+  if ((! is_loopback) &&
       (GNUNET_YES !=
        GNUNET_CONTAINER_multipeermap_contains (c->connectmap,
                                                &req->peer)))
@@ -369,15 +379,17 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
                               gettext_noop
                               ("# send requests dropped (disconnected)"), 1,
                               GNUNET_NO);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_OK);
     return;
   }
 
-  car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer);
-  if (car == NULL)
+  car = GNUNET_CONTAINER_multipeermap_get (c->requests,
+                                           &req->peer);
+  if (NULL == car)
   {
     /* create new entry */
-    car = GNUNET_malloc (sizeof (struct GSC_ClientActiveRequest));
+    car = GNUNET_new (struct GSC_ClientActiveRequest);
     GNUNET_assert (GNUNET_OK ==
                    GNUNET_CONTAINER_multipeermap_put (c->requests,
                                                       &req->peer,
@@ -387,11 +399,21 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
   }
   else
   {
+    /* dequeue and recycle memory from pending request, there can only
+       be at most one per client and peer */
+    GNUNET_STATISTICS_update (GSC_stats,
+                              gettext_noop
+                              ("# dequeuing CAR (duplicate request)"), 1,
+                              GNUNET_NO);
     GSC_SESSIONS_dequeue_request (car);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Transmission request to `%s' was a duplicate!\n",
+                GNUNET_i2s (&req->peer));
   }
   car->target = req->peer;
+  car->received_time = GNUNET_TIME_absolute_get ();
   car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline);
-  car->priority = ntohl (req->priority);
+  car->priority = (enum GNUNET_CORE_Priority) ntohl (req->priority);
   car->msize = ntohs (req->size);
   car->smr_id = req->smr_id;
   car->was_solicited = GNUNET_NO;
@@ -408,7 +430,7 @@ handle_client_send_request (void *cls, struct GNUNET_SERVER_Client *client,
 
 
 /**
- * Closure for the 'client_tokenizer_callback'.
+ * Closure for the #client_tokenizer_callback().
  */
 struct TokenizerContext
 {
@@ -418,6 +440,11 @@ struct TokenizerContext
    */
   struct GSC_ClientActiveRequest *car;
 
+  /**
+   * How important is this message.
+   */
+  enum GNUNET_CORE_Priority priority;
+
   /**
    * Is corking allowed (set only once we have the real message).
    */
@@ -427,24 +454,26 @@ struct TokenizerContext
 
 
 /**
- * Handle CORE_SEND request.
+ * Handle #GNUNET_MESSAGE_TYPE_CORE_SEND request.
  *
  * @param cls unused
  * @param client the client issuing the request
- * @param message the "struct SendMessage"
+ * @param message the `struct SendMessage`
  */
 static void
-handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
+handle_client_send (void *cls,
+                    struct GNUNET_SERVER_Client *client,
                     const struct GNUNET_MessageHeader *message)
 {
   const struct SendMessage *sm;
   struct GSC_Client *c;
   struct TokenizerContext tc;
   uint16_t msize;
+  struct GNUNET_TIME_Relative delay;
+  struct GNUNET_TIME_Relative overdue;
 
   msize = ntohs (message->size);
-  if (msize <
-      sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader))
+  if (msize < sizeof (struct SendMessage))
   {
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -454,15 +483,16 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
   msize -= sizeof (struct SendMessage);
   GNUNET_break (0 == ntohl (sm->reserved));
   c = find_client (client);
-  if (c == NULL)
+  if (NULL == c)
   {
     /* client did not send INIT first! */
     GNUNET_break (0);
     GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
     return;
   }
-  tc.car =
-      GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer);
+  tc.car
+    = GNUNET_CONTAINER_multipeermap_get (c->requests,
+                                         &sm->peer);
   if (NULL == tc.car)
   {
     /* Must have been that we first approved the request, then got disconnected
@@ -474,25 +504,44 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
                               gettext_noop
                               ("# messages discarded (session disconnected)"),
                               1, GNUNET_NO);
-    GNUNET_SERVER_receive_done (client, GNUNET_OK);
+    GNUNET_SERVER_receive_done (client,
+                                GNUNET_OK);
     return;
   }
+  delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time);
+  overdue = GNUNET_TIME_absolute_get_duration (tc.car->deadline);
+  tc.cork = ntohl (sm->cork);
+  tc.priority = (enum GNUNET_CORE_Priority) ntohl (sm->priority);
+  if (overdue.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Client waited %s for transmission of %u bytes to `%s'%s\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES),
+                msize,
+                GNUNET_i2s (&sm->peer),
+                tc.cork ? "" : " (corked)");
+  else
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Client waited %s for transmission of %u bytes to `%s'%s\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES),
+                msize,
+                GNUNET_i2s (&sm->peer),
+                tc.cork ? "" : " (corked)");
+
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multipeermap_remove (c->requests,
                                                        &sm->peer,
                                                        tc.car));
-  tc.cork = ntohl (sm->cork);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Client asked for transmission of %u bytes to `%s' %s\n", msize,
-              GNUNET_i2s (&sm->peer), tc.cork ? "now" : "");
-  GNUNET_SERVER_mst_receive (client_mst, &tc, (const char *) &sm[1], msize,
-                             GNUNET_YES, GNUNET_NO);
-  if (0 !=
-      memcmp (&tc.car->target, &GSC_my_identity,
-              sizeof (struct GNUNET_PeerIdentity)))
-    GSC_SESSIONS_dequeue_request (tc.car);
+  GNUNET_SERVER_mst_receive (client_mst, &tc,
+                             (const char *) &sm[1],
+                             msize,
+                             GNUNET_YES,
+                             GNUNET_NO);
+  GSC_SESSIONS_dequeue_request (tc.car);
   GNUNET_free (tc.car);
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
+  GNUNET_SERVER_receive_done (client,
+                              GNUNET_OK);
 }
 
 
@@ -503,11 +552,12 @@ handle_client_send (void *cls, struct GNUNET_SERVER_Client *client,
  * or other CLIENT (for loopback).
  *
  * @param cls closure
- * @param client reservation request ('struct GSC_ClientActiveRequest')
+ * @param client reservation request (`struct GSC_ClientActiveRequest`)
  * @param message the actual message
  */
 static int
-client_tokenizer_callback (void *cls, void *client,
+client_tokenizer_callback (void *cls,
+                           void *client,
                            const struct GNUNET_MessageHeader *message)
 {
   struct TokenizerContext *tc = client;
@@ -517,9 +567,13 @@ client_tokenizer_callback (void *cls, void *client,
   GNUNET_snprintf (buf, sizeof (buf),
                   gettext_noop ("# bytes of messages of type %u received"),
                   (unsigned int) ntohs (message->type));
-  GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO);  
+  GNUNET_STATISTICS_update (GSC_stats,
+                            buf,
+                            ntohs (message->size),
+                            GNUNET_NO);
   if (0 ==
-      memcmp (&car->target, &GSC_my_identity,
+      memcmp (&car->target,
+              &GSC_my_identity,
               sizeof (struct GNUNET_PeerIdentity)))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -536,20 +590,24 @@ client_tokenizer_callback (void *cls, void *client,
                                 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
     GSC_CLIENTS_deliver_message (&GSC_my_identity, message,
                                 sizeof (struct GNUNET_MessageHeader),
-                                GNUNET_CORE_OPTION_SEND_HDR_INBOUND);    
+                                GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
   }
   else
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Delivering message of type %u to %s\n", ntohs (message->type),
+                "Delivering message of type %u and size %u to %s\n",
+                ntohs (message->type), ntohs (message->size),
                 GNUNET_i2s (&car->target));
     GSC_CLIENTS_deliver_message (&car->target, message,
                                 ntohs (message->size),
                                 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
     GSC_CLIENTS_deliver_message (&car->target, message,
                                 sizeof (struct GNUNET_MessageHeader),
-                                GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);  
-    GSC_SESSIONS_transmit (car, message, tc->cork);
+                                GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
+    GSC_SESSIONS_transmit (car,
+                           message,
+                           tc->cork,
+                           tc->priority);
   }
   return GNUNET_OK;
 }
@@ -560,11 +618,11 @@ client_tokenizer_callback (void *cls, void *client,
  *
  * @param cls NULL
  * @param key identity of peer for which this is an active request
- * @param value the 'struct GSC_ClientActiveRequest' to free
+ * @param value the `struct GSC_ClientActiveRequest` to free
  * @return #GNUNET_YES (continue iteration)
  */
 static int
-destroy_active_client_request (void *cls, 
+destroy_active_client_request (void *cls,
                               const struct GNUNET_PeerIdentity *key,
                                void *value)
 {
@@ -588,14 +646,16 @@ destroy_active_client_request (void *cls,
  * @param client identification of the client
  */
 static void
-handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
+handle_client_disconnect (void *cls,
+                          struct GNUNET_SERVER_Client *client)
 {
   struct GSC_Client *c;
 
-  if (client == NULL)
+  if (NULL == client)
     return;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Client %p has disconnected from core service.\n", client);
+              "Client %p has disconnected from core service.\n",
+              client);
   c = find_client (client);
   if (c == NULL)
     return;                     /* client never sent INIT */
@@ -631,6 +691,8 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
 {
   struct GSC_Client *c;
   struct SendMessageReady smr;
+  struct GNUNET_TIME_Relative delay;
+  struct GNUNET_TIME_Relative left;
 
   c = car->client_handle;
   if (GNUNET_YES !=
@@ -639,12 +701,26 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
   {
     /* connection has gone down since, drop request */
     GNUNET_assert (0 !=
-                   memcmp (&car->target, &GSC_my_identity,
+                   memcmp (&car->target,
+                           &GSC_my_identity,
                            sizeof (struct GNUNET_PeerIdentity)));
     GSC_SESSIONS_dequeue_request (car);
-    GSC_CLIENTS_reject_request (car);
+    GSC_CLIENTS_reject_request (car,
+                                GNUNET_NO);
     return;
   }
+  delay = GNUNET_TIME_absolute_get_duration (car->received_time);
+  left = GNUNET_TIME_absolute_get_duration (car->deadline);
+  if (left.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                "Client waited %s for permission to transmit to `%s'%s (priority %u)\n",
+                GNUNET_STRINGS_relative_time_to_string (delay,
+                                                        GNUNET_YES),
+                GNUNET_i2s (&car->target),
+                (0 == left.rel_value_us)
+                ? " (past deadline)"
+                : "",
+                car->priority);
   smr.header.size = htons (sizeof (struct SendMessageReady));
   smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
   smr.size = htons (car->msize);
@@ -655,21 +731,28 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
 
 
 /**
- * Tell a client that we will never be ready to receive the
- * given message in time (disconnect or timeout).
+ * We will never be ready to transmit the given message in (disconnect
+ * or invalid request).  Frees resources associated with @a car.  We
+ * don't explicitly tell the client, he'll learn with the disconnect
+ * (or violated the protocol).
  *
  * @param car request that now permanently failed; the
  *        responsibility for the handle is now returned
  *        to CLIENTS (SESSIONS is done with it).
+ * @param drop_client #GNUNET_YES if the client violated the protocol
+ *        and we should thus drop the connection
  */
 void
-GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
+GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
+                            int drop_client)
 {
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multipeermap_remove (car->
                                                        client_handle->requests,
                                                        &car->target,
                                                        car));
+  if (GNUNET_YES == drop_client)
+    GNUNET_SERVER_client_disconnect (car->client_handle->client_handle);
   GNUNET_free (car);
 }
 
@@ -681,13 +764,12 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car)
  *
  * @param client client to notify
  * @param neighbour identity of the neighbour that changed status
- * @param tmap_old previous type map for the neighbour, NULL for disconnect
+ * @param tmap_old previous type map for the neighbour, NULL for connect
  * @param tmap_new updated type map for the neighbour, NULL for disconnect
  */
 void
 GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
-                                           const struct GNUNET_PeerIdentity
-                                           *neighbour,
+                                           const struct GNUNET_PeerIdentity *neighbour,
                                            const struct GSC_TypeMap *tmap_old,
                                            const struct GSC_TypeMap *tmap_new)
 {
@@ -723,7 +805,8 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
     cnm->header.size = htons (size);
     cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
     cnm->reserved = htonl (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message to client.\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Sending `%s' message to client.\n",
                 "NOTIFY_CONNECT");
     cnm->peer = *neighbour;
     send_to_client (client, &cnm->header, GNUNET_NO);
@@ -753,19 +836,18 @@ GSC_CLIENTS_notify_client_about_neighbour (struct GSC_Client *client,
  * or types processed by the respective peer.
  *
  * @param neighbour identity of the neighbour that changed status
- * @param tmap_old previous type map for the neighbour, NULL for disconnect
+ * @param tmap_old previous type map for the neighbour, NULL for connect
  * @param tmap_new updated type map for the neighbour, NULL for disconnect
  */
 void
-GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
-                                            *neighbour,
+GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity *neighbour,
                                             const struct GSC_TypeMap *tmap_old,
                                             const struct GSC_TypeMap *tmap_new)
 {
   struct GSC_Client *c;
 
-  for (c = client_head; c != NULL; c = c->next)
-    GSC_CLIENTS_notify_client_about_neighbour (c, neighbour, 
+  for (c = client_head; NULL != c; c = c->next)
+    GSC_CLIENTS_notify_client_about_neighbour (c, neighbour,
                                                tmap_old, tmap_new);
 }
 
@@ -784,7 +866,7 @@ GSC_CLIENTS_notify_clients_about_neighbour (const struct GNUNET_PeerIdentity
 void
 GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
                              const struct GNUNET_MessageHeader *msg,
-                             uint16_t msize, 
+                             uint16_t msize,
                              uint32_t options)
 {
   size_t size = msize + sizeof (struct NotifyTrafficMessage);
@@ -801,8 +883,9 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
          (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ))
     return; /* no client cares about this message notification */
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Core service passes message from `%4s' of type %u to client.\n",
-              GNUNET_i2s (sender), (unsigned int) ntohs (msg->type));
+              "Core service passes message from `%s' of type %u to client.\n",
+              GNUNET_i2s (sender),
+              (unsigned int) ntohs (msg->type));
   GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type));
   ntm = (struct NotifyTrafficMessage *) buf;
   ntm->header.size = htons (size);
@@ -811,8 +894,13 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
   else
     ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
   ntm->peer = *sender;
-  memcpy (&ntm[1], msg, msize);
-  send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
+  memcpy (&ntm[1],
+          msg,
+          msize);
+  send_to_all_clients (sender,
+                       &ntm->header,
+                       GNUNET_YES,
+                       options,
                        ntohs (msg->type));
 }
 
@@ -828,8 +916,8 @@ GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
   static const struct GNUNET_SERVER_MessageHandler handlers[] = {
     {&handle_client_init, NULL,
      GNUNET_MESSAGE_TYPE_CORE_INIT, 0},
-    {&GSC_SESSIONS_handle_client_iterate_peers, NULL,
-     GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS,
+    {&GSC_KX_handle_client_monitor_peers, NULL,
+     GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
      sizeof (struct GNUNET_MessageHeader)},
     {&handle_client_send_request, NULL,
      GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
@@ -843,7 +931,8 @@ GSC_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
   client_mst = GNUNET_SERVER_mst_create (&client_tokenizer_callback, NULL);
   notifier =
       GNUNET_SERVER_notification_context_create (server, MAX_NOTIFY_QUEUE);
-  GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
+  GNUNET_SERVER_disconnect_notify (server,
+                                   &handle_client_disconnect, NULL);
   GNUNET_SERVER_add_handlers (server, handlers);
 }