From: Christian Grothoff Date: Thu, 19 Apr 2012 19:37:03 +0000 (+0000) Subject: -remove ATS 0-termination in NotifyTrafficMessage (#2275) X-Git-Tag: initial-import-from-subversion-38251~13857 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=368629854cbdcdd5ee8c40f3f27e4e77f8e60e90;p=oweals%2Fgnunet.git -remove ATS 0-termination in NotifyTrafficMessage (#2275) --- diff --git a/src/core/core.h b/src/core/core.h index 9b342c3eb..53c828037 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -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 */ }; diff --git a/src/core/core_api.c b/src/core/core_api.c index 1a4b23333..d6cb68213 100644 --- a/src/core/core_api.c +++ b/src/core/core_api.c @@ -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)) diff --git a/src/core/gnunet-service-core_clients.c b/src/core/gnunet-service-core_clients.c index 200f15c8e..621f8604a 100644 --- a/src/core/gnunet-service-core_clients.c +++ b/src/core/gnunet-service-core_clients.c @@ -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)); }