gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r17727 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r17727 - gnunet/src/transport
Date: Mon, 24 Oct 2011 18:15:02 +0200

Author: grothoff
Date: 2011-10-24 18:15:02 +0200 (Mon, 24 Oct 2011)
New Revision: 17727

Modified:
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/transport/gnunet-service-transport_clients.c
   gnunet/src/transport/transport.h
   gnunet/src/transport/transport_api.c
Log:
improving r17722

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2011-10-24 15:20:25 UTC 
(rev 17726)
+++ gnunet/src/transport/gnunet-service-transport.c     2011-10-24 16:15:02 UTC 
(rev 17727)
@@ -154,9 +154,9 @@
   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 @@
   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 @@
   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);
 }

Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2011-10-24 
15:20:25 UTC (rev 17726)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2011-10-24 
16:15:02 UTC (rev 17727)
@@ -336,21 +336,22 @@
 {
   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);
 }
 
 

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2011-10-24 15:20:25 UTC (rev 17726)
+++ gnunet/src/transport/transport.h    2011-10-24 16:15:02 UTC (rev 17727)
@@ -110,12 +110,6 @@
    * 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 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;
 };
 
 

Modified: gnunet/src/transport/transport_api.c
===================================================================
--- gnunet/src/transport/transport_api.c        2011-10-24 15:20:25 UTC (rev 
17726)
+++ gnunet/src/transport/transport_api.c        2011-10-24 16:15:02 UTC (rev 
17727)
@@ -405,6 +405,7 @@
   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 @@
       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 @@
     }
     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 @@
     }
     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 @@
       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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]