removing fprintfs -- with bad %fmt statements giving warnings
[oweals/gnunet.git] / src / transport / gnunet-service-transport.c
index e2168b9709aa87f8ad381ae3bfa4a1eb6fda3a49..04c198676a3055a43a8f344fdd0d9ab62834a486 100644 (file)
@@ -2224,6 +2224,9 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
   cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
   cim.distance = htonl (distance);
   cim.latency = GNUNET_TIME_relative_hton (latency);
+  cim.ats_count = htonl(0);
+  cim.ats.type  = htonl(0);
+  cim.ats.value = htonl(0);
   memcpy (&cim.id, peer, sizeof (struct GNUNET_PeerIdentity));
   cpos = clients;
   while (cpos != NULL)
@@ -3383,10 +3386,12 @@ schedule_next_ping (struct ForeignAddressList *fal)
  *
  * @param message the payload
  * @param n peer who claimed to be the sender
+ * @param ats ATS information
+ * @param ats_count numbers of elements following the ats struct (excluding the 0-terminator)
  */
 static void
 handle_payload_message (const struct GNUNET_MessageHeader *message,
-                       struct NeighbourList *n)
+                       struct NeighbourList *n, struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count)
 {
   struct InboundMessage *im;
   struct TransportClient *cpos;
@@ -3441,14 +3446,21 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
                            gettext_noop ("# payload received from other peers"),
                            msize,
                            GNUNET_NO);
+
   /* transmit message to all clients */
-  im = GNUNET_malloc (sizeof (struct InboundMessage) + msize);
-  im->header.size = htons (sizeof (struct InboundMessage) + msize);
+  im = GNUNET_malloc (sizeof (struct InboundMessage) + ats_count * sizeof(struct GNUNET_TRANSPORT_ATS_Information) + msize);
+  im->header.size = htons (sizeof (struct InboundMessage) +  ats_count * sizeof(struct GNUNET_TRANSPORT_ATS_Information) + msize);
   im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
-  im->latency = GNUNET_TIME_relative_hton (n->latency);
   im->peer = n->id;
-  im->distance = ntohl(n->distance);
-  memcpy (&im[1], message, msize);
+  im->ats_count = htonl(ats_count);
+  /* insert ATS elements */
+  memcpy (&(im->ats), ats, ats_count * sizeof(struct GNUNET_TRANSPORT_ATS_Information));
+  /* insert ATS terminator */
+  (&im->ats)[ats_count].type  = htonl(0);
+  (&im->ats)[ats_count].value = htonl(0);
+  /* insert msg after terminator */
+  memcpy (&(&im->ats)[ats_count+1], message, msize);
+
   cpos = clients;
   while (cpos != NULL)
     {
@@ -3669,7 +3681,17 @@ check_pending_validation (void *cls,
          if (NULL != (prem = n->pre_connect_message_buffer))
            {
              n->pre_connect_message_buffer = NULL;
-             handle_payload_message (prem, n);
+             struct GNUNET_TRANSPORT_ATS_Information * ats = GNUNET_malloc(2 * sizeof(struct GNUNET_TRANSPORT_ATS_Information));
+             ats[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+             if (n->latency.rel_value <= UINT32_MAX)
+                 ats[0].value = htonl((uint32_t) n->latency.rel_value);
+             else
+                 ats[0].value = htonl(UINT32_MAX);
+             ats[1].type  = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+             ats[1].value = htonl(n->distance);
+             //handle_payload_message (prem, n, NULL, 0);
+             handle_payload_message (prem, n, ats, 2);
+             GNUNET_free (ats);
              GNUNET_free (prem);
            }
        }
@@ -4674,6 +4696,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   struct ForeignAddressList *peer_address;
   uint16_t msize;
   struct NeighbourList *n;
+  struct GNUNET_TRANSPORT_ATS_Information * ats;
   struct GNUNET_TIME_Relative ret;
   if (is_blacklisted (peer, plugin))
     return GNUNET_TIME_UNIT_FOREVER_REL;
@@ -4759,7 +4782,17 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
          handle_pong (plugin, message, peer, sender_address, sender_address_len);
          break;
        default:
-         handle_payload_message (message, n);
+         ats = GNUNET_malloc(2 * sizeof(struct GNUNET_TRANSPORT_ATS_Information));
+         ats[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
+         if (n->latency.rel_value <= UINT32_MAX)
+                 ats[0].value = htonl((uint32_t) n->latency.rel_value);
+         else
+                 ats[0].value = htonl(UINT32_MAX);
+         ats[1].type  = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+         ats[1].value = htonl(n->distance);
+         //handle_payload_message (message, n, NULL, 0);
+         handle_payload_message (message, n, ats, 2);
+         GNUNET_free(ats);
          break;
        }
     }
@@ -4841,6 +4874,9 @@ handle_start (void *cls,
       /* tell new client about all existing connections */
       cim.header.size = htons (sizeof (struct ConnectInfoMessage));
       cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
+      cim.ats_count = htonl(0);
+      cim.ats.type  = htonl(0);
+      cim.ats.value = htonl(0);
       n = neighbours;
       while (n != NULL)
        {