From: Christian Grothoff Date: Mon, 24 Oct 2011 16:15:02 +0000 (+0000) Subject: improving r17722 X-Git-Tag: initial-import-from-subversion-38251~16281 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0f4bee916929a41fd6cc516cd6276685d283d706;p=oweals%2Fgnunet.git improving r17722 --- diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 6a56f6830..a45e49fc5 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -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); } diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 6b07136e8..50bb903c4 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c @@ -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); } diff --git a/src/transport/transport.h b/src/transport/transport.h index f3c4329a9..5bc4bad2b 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -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; }; diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index 0819a5559..2ececc10d 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c @@ -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