improving r17722
authorChristian Grothoff <christian@grothoff.org>
Mon, 24 Oct 2011 16:15:02 +0000 (16:15 +0000)
committerChristian Grothoff <christian@grothoff.org>
Mon, 24 Oct 2011 16:15:02 +0000 (16:15 +0000)
src/transport/gnunet-service-transport.c
src/transport/gnunet-service-transport_clients.c
src/transport/transport.h
src/transport/transport_api.c

index 6a56f6830b2d35401f960be33f14a23716375a87..a45e49fc50a32b27f9c9688f66cec6a1012d635a 100644 (file)
@@ -154,9 +154,9 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
   struct GNUNET_TIME_Relative ret;
   int do_forward;
   struct InboundMessage *im;
-  size_t size = sizeof (struct InboundMessage) + ntohs (message->size);
+  size_t size = sizeof (struct InboundMessage) + ntohs (message->size) + sizeof (struct GNUNET_ATS_Information) * ats_count;
   char buf[size];
-  memset (&buf, 0, size);
+  struct GNUNET_ATS_Information *ap;
   
   ret = GNUNET_TIME_UNIT_ZERO;
   do_forward = GNUNET_SYSERR;
@@ -169,9 +169,11 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
   im = (struct InboundMessage*) buf;    
   im->header.size = htons (size);
   im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
-  im->ats_count = htonl (0);
-  memcpy (&(im->peer), peer, sizeof (struct GNUNET_PeerIdentity));
-  memcpy (&im[1], message, ntohs (message->size));
+  im->ats_count = htonl (ats_count);
+  im->peer = *peer;
+  ap = (struct GNUNET_ATS_Information*) &im[1];
+  memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
+  memcpy (&ap[ats_count], message, ntohs (message->size));
 
   switch (do_forward)
   {
@@ -454,14 +456,15 @@ neighbours_connect_notification (void *cls,
   size_t len = sizeof (struct ConnectInfoMessage) +
       ats_count * sizeof (struct GNUNET_ATS_Information);
   char buf[len];
-  memset (&buf, 0, len);
   struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
+  struct GNUNET_ATS_Information *ap;
 
   connect_msg->header.size = htons (sizeof (buf));
   connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
   connect_msg->ats_count = htonl (ats_count);
   connect_msg->id = *peer;
-  memcpy (&connect_msg->ats, &connect_msg->ats,
+  ap = (struct GNUNET_ATS_Information *) &connect_msg[1];
+  memcpy (ap, ats,
           ats_count * sizeof (struct GNUNET_ATS_Information));
   GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
 }
index 6b07136e8dfa1debeac296aacb5d3aa82bfbfb39..50bb903c4858eb79d89dc9cdded033db4119f729 100644 (file)
@@ -336,21 +336,22 @@ notify_client_about_neighbour (void *cls,
 {
   struct TransportClient *tc = cls;
   struct ConnectInfoMessage *cim;
-  size_t size;
+  struct GNUNET_ATS_Information *ap;
+  size_t size =
+    sizeof (struct ConnectInfoMessage) +
+    ats_count * sizeof (struct GNUNET_ATS_Information);
+  char buf[size];
 
-  size =
-      sizeof (struct ConnectInfoMessage) +
-      ats_count * sizeof (struct GNUNET_ATS_Information);
   GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
-  cim = GNUNET_malloc (size);
+  cim = (struct ConnectInfoMessage*) buf;
   cim->header.size = htons (size);
   cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
   cim->ats_count = htonl (ats_count);
   cim->id = *peer;
-  memcpy (&cim->ats, ats,
+  ap = (struct GNUNET_ATS_Information *) &cim[1];
+  memcpy (ap, ats,
           ats_count * sizeof (struct GNUNET_ATS_Information));
   unicast (tc, &cim->header, GNUNET_NO);
-  GNUNET_free (cim);
 }
 
 
index f3c4329a90214204e15307189c75e29a1dc52922..5bc4bad2b378ad437c474aba1e5bc297f65e482c 100644 (file)
@@ -110,12 +110,6 @@ struct ConnectInfoMessage
    * Identity of the new neighbour.
    */
   struct GNUNET_PeerIdentity id;
-
-  /**
-   * First of the ATS information blocks (we must have at least
-   * one due to the 0-termination requirement).
-   */
-  struct GNUNET_ATS_Information ats;
 };
 
 
@@ -216,11 +210,6 @@ struct InboundMessage
    */
   struct GNUNET_PeerIdentity peer;
 
-  /**
-   * First of the ATS information blocks (we must have at least
-   * one due to the 0-termination requirement).
-   */
-  struct GNUNET_ATS_Information ats;
 };
 
 
index 0819a55597f6bb903d059c96b5b3d8bb8ab6853e..2ececc10da107a7822d48f45c9bbd80a2268d37c 100644 (file)
@@ -405,6 +405,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
   const struct GNUNET_MessageHeader *imm;
   const struct SendOkMessage *okm;
   const struct QuotaSetMessage *qm;
+  const struct GNUNET_ATS_Information *ats;
   struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
   struct GNUNET_TRANSPORT_GetHelloHandle *next_hwl;
   struct Neighbour *n;
@@ -472,6 +473,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
       GNUNET_break (0);
       break;
     }
+    ats = (const struct GNUNET_ATS_Information*) &cim[1];
 #if DEBUG_TRANSPORT_API
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
          "CONNECT", GNUNET_i2s (&cim->id));
@@ -484,7 +486,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
     }
     n = neighbour_add (h, &cim->id);
     if (h->nc_cb != NULL)
-      h->nc_cb (h->cls, &n->id, &cim->ats, ats_count);
+      h->nc_cb (h->cls, &n->id, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
     if (size != sizeof (struct DisconnectInfoMessage))
@@ -545,8 +547,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
     }
     im = (const struct InboundMessage *) msg;
     ats_count = ntohl (im->ats_count);
-    imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]);
-
+    ats = (const struct GNUNET_ATS_Information*) &im[1];
+    imm = (const struct GNUNET_MessageHeader *) &ats[ats_count];
     if (ntohs (imm->size) + sizeof (struct InboundMessage) +
         ats_count * sizeof (struct GNUNET_ATS_Information) != size)
     {
@@ -564,7 +566,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
       break;
     }
     if (h->rec != NULL)
-      h->rec (h->cls, &im->peer, imm, &im->ats, ats_count);
+      h->rec (h->cls, &im->peer, imm, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
 #if DEBUG_TRANSPORT_API