xvine:fixes
[oweals/gnunet.git] / src / dv / gnunet-service-dv.c
index 8445ab1f57c6e89000aff865f2798dbcd0832043..abade848fe77017d20bfaf0231d0dca918d9f7d5 100644 (file)
@@ -97,7 +97,7 @@ struct Target
 struct RouteMessage
 {
   /**
-   * Type: GNUNET_MESSAGE_TYPE_DV_ROUTE
+   * Type: #GNUNET_MESSAGE_TYPE_DV_ROUTE
    */
   struct GNUNET_MessageHeader header;
 
@@ -145,9 +145,9 @@ struct PendingMessage
   const struct GNUNET_MessageHeader *msg;
 
   /**
-   * Ultimate target for the message.
+   * Next target for the message (a neighbour of ours).
    */
-  struct GNUNET_PeerIdentity ultimate_target;
+  struct GNUNET_PeerIdentity next_target;
 
   /**
    * Unique ID of the message.
@@ -272,7 +272,7 @@ struct DirectNeighbor
   /**
    * The network this peer is in
    */
-  uint32_t network;
+  enum GNUNET_ATS_Network_Type network;
 
   /**
    * Is this neighbor connected at the core level?
@@ -341,7 +341,7 @@ static struct GNUNET_CONTAINER_MultiPeerMap *direct_neighbors;
 /**
  * Hashmap with all routes that we currently support; contains
  * routing information for all peers from distance 2
- * up to distance DEFAULT_FISHEYE_DEPTH.
+ * up to distance #DEFAULT_FISHEYE_DEPTH.
  */
 static struct GNUNET_CONTAINER_MultiPeerMap *all_routes;
 
@@ -444,8 +444,9 @@ send_data_to_plugin (const struct GNUNET_MessageHeader *message,
   size_t size;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Delivering message from peer `%s'\n",
-              GNUNET_i2s (origin));
+              "Delivering message from peer `%s' at distance %u\n",
+              GNUNET_i2s (origin),
+              (unsigned int) distance);
   size = sizeof (struct GNUNET_DV_ReceivedMessage) +
     ntohs (message->size);
   if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
@@ -517,10 +518,11 @@ send_ack_to_plugin (const struct GNUNET_PeerIdentity *target,
 static void
 send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer,
                                uint32_t distance,
-                                uint32_t network)
+                                enum GNUNET_ATS_Network_Type network)
 {
   struct GNUNET_DV_DistanceUpdateMessage du_msg;
 
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Delivering DISTANCE_CHANGED for message about peer `%s'\n",
               GNUNET_i2s (peer));
@@ -528,7 +530,7 @@ send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer,
   du_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED);
   du_msg.distance = htonl (distance);
   du_msg.peer = *peer;
-  du_msg.network = htonl (network);
+  du_msg.network = htonl ((uint32_t) network);
   send_control_to_plugin (&du_msg.header);
 }
 
@@ -542,7 +544,8 @@ send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer,
  */
 static void
 send_connect_to_plugin (const struct GNUNET_PeerIdentity *target,
-                       uint32_t distance, uint32_t network)
+                       uint32_t distance,
+                        enum GNUNET_ATS_Network_Type network)
 {
   struct GNUNET_DV_ConnectMessage cm;
 
@@ -552,7 +555,7 @@ send_connect_to_plugin (const struct GNUNET_PeerIdentity *target,
   cm.header.size = htons (sizeof (cm));
   cm.header.type = htons (GNUNET_MESSAGE_TYPE_DV_CONNECT);
   cm.distance = htonl (distance);
-  cm.network = htonl (network);
+  cm.network = htonl ((uint32_t) network);
   cm.peer = *target;
   send_control_to_plugin (&cm.header);
 }
@@ -613,18 +616,28 @@ core_transmit_notify (void *cls, size_t size, void *buf)
                                  pending);
     memcpy (&cbuf[off], pending->msg, msize);
     if (0 != pending->uid)
-      send_ack_to_plugin (&pending->ultimate_target,
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Acking transmission of %u bytes to %s with plugin\n",
+                  msize,
+                  GNUNET_i2s (&pending->next_target));
+      send_ack_to_plugin (&pending->next_target,
                          pending->uid,
                          GNUNET_NO);
+    }
     GNUNET_free (pending);
     off += msize;
   }
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Transmitting total of %u bytes to %s\n",
+             off,
+             GNUNET_i2s (&dn->peer));
   GNUNET_assert (NULL != core_api);
   if (NULL != dn->pm_head)
     dn->cth =
       GNUNET_CORE_notify_transmit_ready (core_api,
                                         GNUNET_YES /* cork */,
-                                        0 /* priority */,
+                                        GNUNET_CORE_PRIO_BEST_EFFORT,
                                         GNUNET_TIME_UNIT_FOREVER_REL,
                                         &dn->peer,
                                         msize,
@@ -637,10 +650,10 @@ core_transmit_notify (void *cls, size_t size, void *buf)
  * Forward the given payload to the given target.
  *
  * @param target where to send the message
- * @param distance expected (remaining) distance to the target
+ * @param distance distance to the @a sender
  * @param uid unique ID for the message
- * @param ultimate_target ultimate recipient for the message
  * @param sender original sender of the message
+ * @param actual_target ultimate recipient for the message
  * @param payload payload of the message
  */
 static void
@@ -648,7 +661,7 @@ forward_payload (struct DirectNeighbor *target,
                 uint32_t distance,
                 uint32_t uid,
                 const struct GNUNET_PeerIdentity *sender,
-                const struct GNUNET_PeerIdentity *ultimate_target,
+                const struct GNUNET_PeerIdentity *actual_target,
                 const struct GNUNET_MessageHeader *payload)
 {
   struct PendingMessage *pm;
@@ -674,14 +687,14 @@ forward_payload (struct DirectNeighbor *target,
     return;
   }
   pm = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
-  pm->ultimate_target = *ultimate_target;
+  pm->next_target = target->peer;
   pm->uid = uid;
   pm->msg = (const struct GNUNET_MessageHeader *) &pm[1];
   rm = (struct RouteMessage *) &pm[1];
   rm->header.size = htons ((uint16_t) msize);
   rm->header.type = htons (GNUNET_MESSAGE_TYPE_DV_ROUTE);
   rm->distance = htonl (distance);
-  rm->target = target->peer;
+  rm->target = *actual_target;
   rm->sender = *sender;
   memcpy (&rm[1], payload, ntohs (payload->size));
   GNUNET_CONTAINER_DLL_insert_tail (target->pm_head,
@@ -692,7 +705,7 @@ forward_payload (struct DirectNeighbor *target,
   if (NULL == target->cth)
     target->cth = GNUNET_CORE_notify_transmit_ready (core_api,
                                                     GNUNET_YES /* cork */,
-                                                    0 /* priority */,
+                                                    GNUNET_CORE_PRIO_BEST_EFFORT,
                                                     GNUNET_TIME_UNIT_FOREVER_REL,
                                                     &target->peer,
                                                     msize,
@@ -851,7 +864,7 @@ build_set (void *cls)
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                 "Adding peer `%s' with distance %u to SET\n",
                 GNUNET_i2s (&target->peer),
-                ntohl (target->distance));
+                ntohl (target->distance) + 1);
     GNUNET_SET_add_element (neighbor->my_set,
                             &element,
                             &build_set, neighbor);
@@ -926,7 +939,7 @@ handle_direct_connect (struct DirectNeighbor *neighbor)
     }
     else
       neighbor->initiate_task = GNUNET_SCHEDULER_add_now (&initiate_set_union,
-                                                       neighbor);
+                                                          neighbor);
   }
   else
   {
@@ -969,6 +982,7 @@ handle_core_connect (void *cls,
                                                peer);
   if (NULL != neighbor)
   {
+    GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != neighbor->network);
     GNUNET_break (GNUNET_YES != neighbor->connected);
     neighbor->connected = GNUNET_YES;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1014,6 +1028,33 @@ free_targets (void *cls,
 }
 
 
+/**
+ * Add a new route to the given @a target via the given @a neighbor.
+ *
+ * @param target the target of the route
+ * @param neighbor the next hop for communicating with the @a target
+ */
+static void
+add_new_route (struct Target *target,
+               struct DirectNeighbor *neighbor)
+{
+  struct Route *route;
+
+  route = GNUNET_new (struct Route);
+  route->next_hop = neighbor;
+  route->target.peer = target->peer;
+  allocate_route (route, ntohl (target->distance) + 1);
+  GNUNET_assert (GNUNET_YES ==
+                GNUNET_CONTAINER_multipeermap_put (all_routes,
+                                                   &route->target.peer,
+                                                   route,
+                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  send_connect_to_plugin (&route->target.peer,
+                          ntohl (route->target.distance),
+                          neighbor->network);
+}
+
+
 /**
  * Multipeerhmap iterator for checking if a given route is
  * (now) useful to this peer.
@@ -1055,18 +1096,7 @@ check_possible_route (void *cls,
   }
   if (ntohl (target->distance) >= DEFAULT_FISHEYE_DEPTH)
     return GNUNET_YES; /* distance is too large to be interesting */
-  route = GNUNET_new (struct Route);
-  route->next_hop = neighbor;
-  route->target.peer = target->peer;
-  allocate_route (route, ntohl (target->distance) + 1);
-  GNUNET_assert (GNUNET_YES ==
-                GNUNET_CONTAINER_multipeermap_put (all_routes,
-                                                   &route->target.peer,
-                                                   route,
-                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
-  send_connect_to_plugin (&route->target.peer,
-                          ntohl (route->target.distance),
-                          neighbor->network);
+  add_new_route (target, neighbor);
   return GNUNET_YES;
 }
 
@@ -1156,7 +1186,7 @@ get_atsi_distance (const struct GNUNET_ATS_Information *atsi,
  * @param atsi_count number of entries in atsi
  * @return connected transport network
  */
-static uint32_t
+static enum GNUNET_ATS_Network_Type
 get_atsi_network (const struct GNUNET_ATS_Information *atsi,
                    uint32_t atsi_count)
 {
@@ -1164,7 +1194,7 @@ get_atsi_network (const struct GNUNET_ATS_Information *atsi,
 
   for (i = 0; i < atsi_count; i++)
     if (ntohl (atsi[i].type) == GNUNET_ATS_NETWORK_TYPE)
-      return ntohl (atsi[i].value);
+      return (enum GNUNET_ATS_Network_Type) ntohl (atsi[i].value);
   return GNUNET_ATS_NET_UNSPECIFIED;
 }
 
@@ -1272,7 +1302,10 @@ handle_direct_disconnect (struct DirectNeighbor *neighbor)
  *
  * @param cls closure
  * @param address the address
- * @param active is this address in active use
+ * @param active #GNUNET_YES if this address is actively used
+ *        to maintain a connection to a peer;
+ *        #GNUNET_NO if the address is not actively used;
+ *        #GNUNET_SYSERR if this address is no longer available for ATS
  * @param bandwidth_out assigned outbound bandwidth for the connection
  * @param bandwidth_in assigned inbound bandwidth for the connection
  * @param ats performance data for the address (as far as known)
@@ -1289,20 +1322,28 @@ handle_ats_update (void *cls,
 {
   struct DirectNeighbor *neighbor;
   uint32_t distance;
-  uint32_t network = GNUNET_ATS_NET_UNSPECIFIED;
+  enum GNUNET_ATS_Network_Type network = GNUNET_ATS_NET_UNSPECIFIED;
+
+  if (NULL == address)
+  {
+    /* ATS service temporarily disconnected */
+    return;
+  }
 
-  if (GNUNET_NO == active)
+  if (GNUNET_YES != active)
+  {
+    // FIXME: handle disconnect/inactive case too!
     return;
+  }
   distance = get_atsi_distance (ats, ats_count);
   network = get_atsi_network (ats, ats_count);
-
+  GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
   /* check if entry exists */
   neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
                                                &address->peer);
   if (NULL != neighbor)
   {
-    if (GNUNET_ATS_NET_UNSPECIFIED != network)
-      neighbor->network = network;
+    neighbor->network = network;
     if (neighbor->distance == distance)
       return; /* nothing new to see here, move along */
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1510,28 +1551,30 @@ handle_set_union_result (void *cls,
                         enum GNUNET_SET_Status status)
 {
   struct DirectNeighbor *neighbor = cls;
+  struct DirectNeighbor *dn;
   struct Target *target;
   char *status_str;
 
-  switch (status) {
-    case GNUNET_SET_STATUS_OK:
-      status_str = "GNUNET_SET_STATUS_OK";
-      break;
-    case GNUNET_SET_STATUS_TIMEOUT:
-      status_str = "GNUNET_SET_STATUS_TIMEOUT";
-      break;
-    case GNUNET_SET_STATUS_FAILURE:
-      status_str = "GNUNET_SET_STATUS_FAILURE";
-      break;
-    case GNUNET_SET_STATUS_HALF_DONE:
-      status_str = "GNUNET_SET_STATUS_HALF_DONE";
-      break;
-    case GNUNET_SET_STATUS_DONE:
-      status_str = "GNUNET_SET_STATUS_DONE";
-      break;
-    default:
-      status_str = "UNDEFINED";
-      break;
+  switch (status)
+  {
+  case GNUNET_SET_STATUS_OK:
+    status_str = "GNUNET_SET_STATUS_OK";
+    break;
+  case GNUNET_SET_STATUS_TIMEOUT:
+    status_str = "GNUNET_SET_STATUS_TIMEOUT";
+    break;
+  case GNUNET_SET_STATUS_FAILURE:
+    status_str = "GNUNET_SET_STATUS_FAILURE";
+    break;
+  case GNUNET_SET_STATUS_HALF_DONE:
+    status_str = "GNUNET_SET_STATUS_HALF_DONE";
+    break;
+  case GNUNET_SET_STATUS_DONE:
+    status_str = "GNUNET_SET_STATUS_DONE";
+    break;
+  default:
+    status_str = "UNDEFINED";
+    break;
   }
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1545,9 +1588,7 @@ handle_set_union_result (void *cls,
       GNUNET_break_op (0);
       return;
     }
-    if (GNUNET_YES ==
-        GNUNET_CONTAINER_multipeermap_contains (direct_neighbors,
-                                                &((struct Target *) element->data)->peer))
+    if ( (NULL != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, &((struct Target *) element->data)->peer))) && (DIRECT_NEIGHBOR_COST == dn->distance) )
     {
       /* this is a direct neighbor of ours, we do not care about routes
          to this peer */
@@ -1744,68 +1785,164 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer,
   const struct RouteMessage *rm;
   const struct GNUNET_MessageHeader *payload;
   struct Route *route;
+  struct DirectNeighbor *neighbor;
+  struct DirectNeighbor *dn;
+  struct Target *target;
+  uint32_t distance;
+  char me[5];
+  char src[5];
+  char prev[5];
+  char dst[5];
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Handling DV message\n");
   if (ntohs (message->size) < sizeof (struct RouteMessage) + sizeof (struct GNUNET_MessageHeader))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
   rm = (const struct RouteMessage *) message;
+  distance = ntohl (rm->distance);
   payload = (const struct GNUNET_MessageHeader *) &rm[1];
   if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size))
   {
     GNUNET_break_op (0);
     return GNUNET_SYSERR;
   }
+  strncpy (prev, GNUNET_i2s (peer), 4);
+  strncpy (me, GNUNET_i2s (&my_identity), 4);
+  strncpy (src, GNUNET_i2s (&rm->sender), 4);
+  strncpy (dst, GNUNET_i2s (&rm->target), 4);
+  prev[4] = me[4] = src[4] = dst[4] = '\0';
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+             "Handling DV message with %u bytes payload of type %u from %s to %s routed by %s to me (%s @ hop %u)\n",
+              ntohs (message->size) - sizeof (struct RouteMessage),
+              ntohs (payload->type),
+              src, dst,
+              prev, me,
+              (unsigned int) distance + 1);
+
   if (0 == memcmp (&rm->target,
                   &my_identity,
                   sizeof (struct GNUNET_PeerIdentity)))
   {
+    if ((NULL
+        != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+            &rm->sender))) && (DIRECT_NEIGHBOR_COST == dn->distance))
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Discarding DV message, as %s is a direct neighbor\n",
+                  GNUNET_i2s (&rm->sender));
+      GNUNET_STATISTICS_update (stats,
+                                "# messages discarded (direct neighbor)",
+                                1, GNUNET_NO);
+      return GNUNET_OK;
+    }
     /* message is for me, check reverse route! */
     route = GNUNET_CONTAINER_multipeermap_get (all_routes,
                                               &rm->sender);
-    if (NULL == route)
+    if ( (NULL == route) &&
+         (distance < DEFAULT_FISHEYE_DEPTH) )
     {
-      /* don't have reverse route, drop */
-      GNUNET_STATISTICS_update (stats,
-                               "# message discarded (no reverse route)",
-                               1, GNUNET_NO);
-      return GNUNET_OK;
+      /* don't have reverse route yet, learn it! */
+      neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+                                                    peer);
+      if (NULL == neighbor)
+      {
+        GNUNET_break (0);
+        return GNUNET_SYSERR;
+      }
+      target = GNUNET_new (struct Target);
+      target->peer = rm->sender;
+      target->distance = htonl (distance);
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "Learning sender %s at distance %u from delivery!\n",
+                  GNUNET_i2s (&rm->sender),
+                  (unsigned int) distance + 1);
+      if (NULL == neighbor->neighbor_table)
+        neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+      if (GNUNET_YES !=
+          GNUNET_CONTAINER_multipeermap_put (neighbor->neighbor_table,
+                                             &target->peer,
+                                             target,
+                                             GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+      {
+        GNUNET_break_op (0);
+        GNUNET_free (target);
+        return GNUNET_SYSERR;
+      }
+      add_new_route (target, neighbor);
     }
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-               "Delivering %u bytes to myself!\n",
-               ntohs (payload->size));
+               "Delivering %u bytes from %s to myself!\n",
+               ntohs (payload->size),
+                GNUNET_i2s (&rm->sender));
     send_data_to_plugin (payload,
                         &rm->sender,
-                        ntohl (route->target.distance));
+                        1 + distance);
     return GNUNET_OK;
   }
+  if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+                                                   &rm->sender)) &&
+       (NULL == GNUNET_CONTAINER_multipeermap_get (all_routes,
+                                                   &rm->sender)) )
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Learning sender %s at distance %u from forwarding!\n",
+                GNUNET_i2s (&rm->sender),
+                1 + distance);
+    neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+                                                  peer);
+    if (NULL == neighbor)
+    {
+      GNUNET_break (0);
+      return GNUNET_SYSERR;
+    }
+    target = GNUNET_new (struct Target);
+    target->peer = rm->sender;
+    target->distance = htonl (distance);
+    if (NULL == neighbor->neighbor_table)
+      neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
+    if (GNUNET_YES !=
+        GNUNET_CONTAINER_multipeermap_put (neighbor->neighbor_table,
+                                           &target->peer,
+                                           target,
+                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+    {
+      GNUNET_break_op (0);
+      GNUNET_free (target);
+    }
+    add_new_route (target, neighbor);
+  }
+
   route = GNUNET_CONTAINER_multipeermap_get (all_routes,
                                             &rm->target);
   if (NULL == route)
   {
-    GNUNET_STATISTICS_update (stats,
-                             "# messages discarded (no route)",
-                             1, GNUNET_NO);
-    return GNUNET_OK;
+    neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+                                                  &rm->target);
+    if (NULL == neighbor)
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                  "No route to %s, not routing %u bytes!\n",
+                  GNUNET_i2s (&rm->target),
+                  ntohs (payload->size));
+      GNUNET_STATISTICS_update (stats,
+                                "# messages discarded (no route)",
+                                1, GNUNET_NO);
+      return GNUNET_OK;
+    }
   }
-  if (ntohl (route->target.distance) > ntohl (rm->distance) + 1)
+  else
   {
-    GNUNET_STATISTICS_update (stats,
-                             "# messages discarded (target too far)",
-                             1, GNUNET_NO);
-    return GNUNET_OK;
+    neighbor = route->next_hop;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Forwarding message to %s\n",
-             GNUNET_i2s (&rm->target));
-  forward_payload (route->next_hop,
-                  ntohl (route->target.distance),
+             GNUNET_i2s (&neighbor->peer));
+  forward_payload (neighbor,
+                  distance + 1,
                   0,
-                  &rm->target,
                   &rm->sender,
+                  &rm->target,
                   payload);
   return GNUNET_OK;
 }
@@ -1847,6 +1984,10 @@ handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client,
   if (NULL == route)
   {
     /* got disconnected */
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "No route to %s, dropping local message of type %u\n",
+                GNUNET_i2s (&msg->target),
+                ntohs (payload->type));
     GNUNET_STATISTICS_update (stats,
                              "# local messages discarded (no route)",
                              1, GNUNET_NO);
@@ -1855,15 +1996,16 @@ handle_dv_send_message (void *cls, struct GNUNET_SERVER_Client *client,
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Forwarding %u bytes to %s\n",
+             "Forwarding %u bytes of type %u to %s\n",
              ntohs (payload->size),
+              ntohs (payload->type),
              GNUNET_i2s (&msg->target));
 
   forward_payload (route->next_hop,
-                  ntohl (route->target.distance),
+                  0 /* first hop, distance is zero */,
                   htonl (msg->uid),
-                  &msg->target,
                   &my_identity,
+                  &msg->target,
                   payload);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
@@ -2033,9 +2175,9 @@ shutdown_task (void *cls,
  * @return #GNUNET_OK (continue to iterate)
  */
 static int
-add_route (void *cls,
-          const struct GNUNET_PeerIdentity *key,
-          void *value)
+notify_client_about_route (void *cls,
+                           const struct GNUNET_PeerIdentity *key,
+                           void *value)
 {
   struct GNUNET_SERVER_Client *client = cls;
   struct Route *route = value;
@@ -2070,7 +2212,7 @@ handle_start (void *cls, struct GNUNET_SERVER_Client *client,
   GNUNET_SERVER_notification_context_add (nc, client);
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
   GNUNET_CONTAINER_multipeermap_iterate (all_routes,
-                                        &add_route,
+                                        &notify_client_about_route,
                                         client);
 }