-remove ATS 0-termination in NotifyTrafficMessage (#2275)
authorChristian Grothoff <christian@grothoff.org>
Thu, 19 Apr 2012 19:37:03 +0000 (19:37 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 19 Apr 2012 19:37:03 +0000 (19:37 +0000)
src/core/core.h
src/core/core_api.c
src/core/gnunet-service-core_clients.c

index 9b342c3ebf8f760fbe1662a18f6ed9df9ce1b33a..53c828037ced7b696942cdbf1d711a8823bf04f0 100644 (file)
@@ -222,12 +222,11 @@ struct NotifyTrafficMessage
    */
   struct GNUNET_PeerIdentity peer;
 
-  /**
-   * First of the ATS information blocks (we must have at least
-   * one due to the 0-termination requirement).
+  /* Followed by ATS information blocks:
+   * struct GNUNET_ATS_Information ats[ats_count]
    */
-  struct GNUNET_ATS_Information ats;
 
+  /* Followed by payload (message or just header), variable size */
 };
 
 
index 1a4b233336fa0edbc0edbdb2d42232dce4623ba8..d6cb682138e9c9d48f8e16f9ad3c95a8c1489638 100644 (file)
@@ -907,19 +907,18 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       return;
     }
     ntm = (const struct NotifyTrafficMessage *) msg;
-
     ats_count = ntohl (ntm->ats_count);
     if ((msize <
          sizeof (struct NotifyTrafficMessage) +
          ats_count * sizeof (struct GNUNET_ATS_Information) +
-         sizeof (struct GNUNET_MessageHeader)) ||
-        (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
+         sizeof (struct GNUNET_MessageHeader)) )
     {
       GNUNET_break (0);
       reconnect_later (h);
       return;
     }
-    em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
+    ats = (const struct GNUNET_ATS_Information*) &ntm[1];
+    em = (const struct GNUNET_MessageHeader *) &ats[ats_count];
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Received message of type %u and size %u from peer `%4s'\n",
          ntohs (em->type), ntohs (em->size), GNUNET_i2s (&ntm->peer));
@@ -954,7 +953,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
        return;
       }
       if (GNUNET_OK !=
-          h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
+          h->handlers[hpos].callback (h->cls, &ntm->peer, em, ats,
                                       ats_count))
       {
         /* error in processing, do not process other messages! */
@@ -962,7 +961,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       }
     }
     if (NULL != h->inbound_notify)
-      h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
+      h->inbound_notify (h->cls, &ntm->peer, em, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
     if (msize < sizeof (struct NotifyTrafficMessage))
@@ -982,14 +981,14 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     if ((msize <
          sizeof (struct NotifyTrafficMessage) +
          ats_count * sizeof (struct GNUNET_ATS_Information) +
-         sizeof (struct GNUNET_MessageHeader)) ||
-        (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
+         sizeof (struct GNUNET_MessageHeader)) )
     {
       GNUNET_break (0);
       reconnect_later (h);
       return;
     }
-    em = (const struct GNUNET_MessageHeader *) &(&ntm->ats)[ats_count + 1];
+    ats = (const struct GNUNET_ATS_Information*) &ntm[1];    
+    em = (const struct GNUNET_MessageHeader *) &ats[ats_count];
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Received notification about transmission to `%s'.\n",
          GNUNET_i2s (&ntm->peer));
@@ -1007,7 +1006,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       GNUNET_break (0);
       break;
     }
-    h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
+    h->outbound_notify (h->cls, &ntm->peer, em, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
     if (msize != sizeof (struct SendMessageReady))
index 200f15c8e28b2e62a50271d357f3a56687a31937..621f8604a210b9036c14185c6f9fd8b511306727 100644 (file)
@@ -846,11 +846,9 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
     ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND);
   ntm->ats_count = htonl (atsi_count);
   ntm->peer = *sender;
-  a = &ntm->ats;
+  a = (struct GNUNET_ATS_Information*) &ntm[1];
   memcpy (a, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
-  a[atsi_count].type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
-  a[atsi_count].value = htonl (0);
-  memcpy (&a[atsi_count + 1], msg, msize);
+  memcpy (&a[atsi_count], msg, msize);
   send_to_all_clients (sender, &ntm->header, GNUNET_YES, options,
                        ntohs (msg->type));
 }