aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-24 16:15:02 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-24 16:15:02 +0000
commit0f4bee916929a41fd6cc516cd6276685d283d706 (patch)
tree351ee64a09deccd3bcfb994d9d84550ff2789e45
parent227d261c1ff256be9dea7bf98e5e07f7875dcde0 (diff)
downloadgnunet-0f4bee916929a41fd6cc516cd6276685d283d706.tar.gz
gnunet-0f4bee916929a41fd6cc516cd6276685d283d706.zip
improving r17722
-rw-r--r--src/transport/gnunet-service-transport.c17
-rw-r--r--src/transport/gnunet-service-transport_clients.c15
-rw-r--r--src/transport/transport.h11
-rw-r--r--src/transport/transport_api.c10
4 files changed, 24 insertions, 29 deletions
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,
154 struct GNUNET_TIME_Relative ret; 154 struct GNUNET_TIME_Relative ret;
155 int do_forward; 155 int do_forward;
156 struct InboundMessage *im; 156 struct InboundMessage *im;
157 size_t size = sizeof (struct InboundMessage) + ntohs (message->size); 157 size_t size = sizeof (struct InboundMessage) + ntohs (message->size) + sizeof (struct GNUNET_ATS_Information) * ats_count;
158 char buf[size]; 158 char buf[size];
159 memset (&buf, 0, size); 159 struct GNUNET_ATS_Information *ap;
160 160
161 ret = GNUNET_TIME_UNIT_ZERO; 161 ret = GNUNET_TIME_UNIT_ZERO;
162 do_forward = GNUNET_SYSERR; 162 do_forward = GNUNET_SYSERR;
@@ -169,9 +169,11 @@ process_payload (const struct GNUNET_PeerIdentity *peer,
169 im = (struct InboundMessage*) buf; 169 im = (struct InboundMessage*) buf;
170 im->header.size = htons (size); 170 im->header.size = htons (size);
171 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 171 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
172 im->ats_count = htonl (0); 172 im->ats_count = htonl (ats_count);
173 memcpy (&(im->peer), peer, sizeof (struct GNUNET_PeerIdentity)); 173 im->peer = *peer;
174 memcpy (&im[1], message, ntohs (message->size)); 174 ap = (struct GNUNET_ATS_Information*) &im[1];
175 memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
176 memcpy (&ap[ats_count], message, ntohs (message->size));
175 177
176 switch (do_forward) 178 switch (do_forward)
177 { 179 {
@@ -454,14 +456,15 @@ neighbours_connect_notification (void *cls,
454 size_t len = sizeof (struct ConnectInfoMessage) + 456 size_t len = sizeof (struct ConnectInfoMessage) +
455 ats_count * sizeof (struct GNUNET_ATS_Information); 457 ats_count * sizeof (struct GNUNET_ATS_Information);
456 char buf[len]; 458 char buf[len];
457 memset (&buf, 0, len);
458 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; 459 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
460 struct GNUNET_ATS_Information *ap;
459 461
460 connect_msg->header.size = htons (sizeof (buf)); 462 connect_msg->header.size = htons (sizeof (buf));
461 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 463 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
462 connect_msg->ats_count = htonl (ats_count); 464 connect_msg->ats_count = htonl (ats_count);
463 connect_msg->id = *peer; 465 connect_msg->id = *peer;
464 memcpy (&connect_msg->ats, &connect_msg->ats, 466 ap = (struct GNUNET_ATS_Information *) &connect_msg[1];
467 memcpy (ap, ats,
465 ats_count * sizeof (struct GNUNET_ATS_Information)); 468 ats_count * sizeof (struct GNUNET_ATS_Information));
466 GST_clients_broadcast (&connect_msg->header, GNUNET_NO); 469 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
467} 470}
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,
336{ 336{
337 struct TransportClient *tc = cls; 337 struct TransportClient *tc = cls;
338 struct ConnectInfoMessage *cim; 338 struct ConnectInfoMessage *cim;
339 size_t size; 339 struct GNUNET_ATS_Information *ap;
340 size_t size =
341 sizeof (struct ConnectInfoMessage) +
342 ats_count * sizeof (struct GNUNET_ATS_Information);
343 char buf[size];
340 344
341 size =
342 sizeof (struct ConnectInfoMessage) +
343 ats_count * sizeof (struct GNUNET_ATS_Information);
344 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 345 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
345 cim = GNUNET_malloc (size); 346 cim = (struct ConnectInfoMessage*) buf;
346 cim->header.size = htons (size); 347 cim->header.size = htons (size);
347 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 348 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
348 cim->ats_count = htonl (ats_count); 349 cim->ats_count = htonl (ats_count);
349 cim->id = *peer; 350 cim->id = *peer;
350 memcpy (&cim->ats, ats, 351 ap = (struct GNUNET_ATS_Information *) &cim[1];
352 memcpy (ap, ats,
351 ats_count * sizeof (struct GNUNET_ATS_Information)); 353 ats_count * sizeof (struct GNUNET_ATS_Information));
352 unicast (tc, &cim->header, GNUNET_NO); 354 unicast (tc, &cim->header, GNUNET_NO);
353 GNUNET_free (cim);
354} 355}
355 356
356 357
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
110 * Identity of the new neighbour. 110 * Identity of the new neighbour.
111 */ 111 */
112 struct GNUNET_PeerIdentity id; 112 struct GNUNET_PeerIdentity id;
113
114 /**
115 * First of the ATS information blocks (we must have at least
116 * one due to the 0-termination requirement).
117 */
118 struct GNUNET_ATS_Information ats;
119}; 113};
120 114
121 115
@@ -216,11 +210,6 @@ struct InboundMessage
216 */ 210 */
217 struct GNUNET_PeerIdentity peer; 211 struct GNUNET_PeerIdentity peer;
218 212
219 /**
220 * First of the ATS information blocks (we must have at least
221 * one due to the 0-termination requirement).
222 */
223 struct GNUNET_ATS_Information ats;
224}; 213};
225 214
226 215
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)
405 const struct GNUNET_MessageHeader *imm; 405 const struct GNUNET_MessageHeader *imm;
406 const struct SendOkMessage *okm; 406 const struct SendOkMessage *okm;
407 const struct QuotaSetMessage *qm; 407 const struct QuotaSetMessage *qm;
408 const struct GNUNET_ATS_Information *ats;
408 struct GNUNET_TRANSPORT_GetHelloHandle *hwl; 409 struct GNUNET_TRANSPORT_GetHelloHandle *hwl;
409 struct GNUNET_TRANSPORT_GetHelloHandle *next_hwl; 410 struct GNUNET_TRANSPORT_GetHelloHandle *next_hwl;
410 struct Neighbour *n; 411 struct Neighbour *n;
@@ -472,6 +473,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
472 GNUNET_break (0); 473 GNUNET_break (0);
473 break; 474 break;
474 } 475 }
476 ats = (const struct GNUNET_ATS_Information*) &cim[1];
475#if DEBUG_TRANSPORT_API 477#if DEBUG_TRANSPORT_API
476 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n", 478 LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message for `%4s'.\n",
477 "CONNECT", GNUNET_i2s (&cim->id)); 479 "CONNECT", GNUNET_i2s (&cim->id));
@@ -484,7 +486,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
484 } 486 }
485 n = neighbour_add (h, &cim->id); 487 n = neighbour_add (h, &cim->id);
486 if (h->nc_cb != NULL) 488 if (h->nc_cb != NULL)
487 h->nc_cb (h->cls, &n->id, &cim->ats, ats_count); 489 h->nc_cb (h->cls, &n->id, ats, ats_count);
488 break; 490 break;
489 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT: 491 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
490 if (size != sizeof (struct DisconnectInfoMessage)) 492 if (size != sizeof (struct DisconnectInfoMessage))
@@ -545,8 +547,8 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
545 } 547 }
546 im = (const struct InboundMessage *) msg; 548 im = (const struct InboundMessage *) msg;
547 ats_count = ntohl (im->ats_count); 549 ats_count = ntohl (im->ats_count);
548 imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]); 550 ats = (const struct GNUNET_ATS_Information*) &im[1];
549 551 imm = (const struct GNUNET_MessageHeader *) &ats[ats_count];
550 if (ntohs (imm->size) + sizeof (struct InboundMessage) + 552 if (ntohs (imm->size) + sizeof (struct InboundMessage) +
551 ats_count * sizeof (struct GNUNET_ATS_Information) != size) 553 ats_count * sizeof (struct GNUNET_ATS_Information) != size)
552 { 554 {
@@ -564,7 +566,7 @@ demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
564 break; 566 break;
565 } 567 }
566 if (h->rec != NULL) 568 if (h->rec != NULL)
567 h->rec (h->cls, &im->peer, imm, &im->ats, ats_count); 569 h->rec (h->cls, &im->peer, imm, ats, ats_count);
568 break; 570 break;
569 case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA: 571 case GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA:
570#if DEBUG_TRANSPORT_API 572#if DEBUG_TRANSPORT_API