diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-28 14:17:02 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-28 14:17:02 +0000 |
commit | c721d0136a2746f029744d851d3ea164c3ee1b60 (patch) | |
tree | c852678d3e819c3c70d1bf98a5f9739636b2df38 /src | |
parent | 1c051694d229c10ee0c5ed4a60b4f7b46e972b3e (diff) | |
download | gnunet-c721d0136a2746f029744d851d3ea164c3ee1b60.tar.gz gnunet-c721d0136a2746f029744d851d3ea164c3ee1b60.zip |
allow message chunking in tcp, still not working seemingly due to a problem in server.c, though not sure why so it's probably actually a problem with me
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 2 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 72 |
2 files changed, 46 insertions, 28 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index b8672e99d..62f502068 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1231,7 +1231,7 @@ try_transmission_to_peer (struct NeighborList *neighbor) | |||
1231 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1231 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1232 | mq->specific_peer->addr, | 1232 | mq->specific_peer->addr, |
1233 | mq->specific_peer->addrlen, | 1233 | mq->specific_peer->addrlen, |
1234 | GNUNET_NO, | 1234 | GNUNET_YES, |
1235 | &transmit_send_continuation, mq); | 1235 | &transmit_send_continuation, mq); |
1236 | 1236 | ||
1237 | } | 1237 | } |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 4d936279d..fd6dc7506 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -88,10 +88,16 @@ struct PendingMessage | |||
88 | struct PendingMessage *next; | 88 | struct PendingMessage *next; |
89 | 89 | ||
90 | /** | 90 | /** |
91 | * The pending message, pointer to the end | 91 | * The pending message |
92 | * of this struct, do not free! | ||
93 | */ | 92 | */ |
94 | const struct GNUNET_MessageHeader *msg; | 93 | char *msg; |
94 | |||
95 | /* | ||
96 | * So that the gnunet_transport_service can group messages together, | ||
97 | * these pending messages need to accept a message buffer and size | ||
98 | * instead of just a GNUNET_MessageHeader. | ||
99 | */ | ||
100 | size_t message_size; | ||
95 | 101 | ||
96 | /** | 102 | /** |
97 | * Continuation function to call once the message | 103 | * Continuation function to call once the message |
@@ -298,10 +304,10 @@ create_welcome (struct Plugin *plugin) | |||
298 | struct PendingMessage *pm; | 304 | struct PendingMessage *pm; |
299 | struct WelcomeMessage *welcome; | 305 | struct WelcomeMessage *welcome; |
300 | 306 | ||
301 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 307 | pm = GNUNET_malloc (sizeof (struct PendingMessage)); |
302 | sizeof (struct WelcomeMessage)); | 308 | pm->msg = GNUNET_malloc(sizeof(struct WelcomeMessage)); |
303 | pm->msg = (struct GNUNET_MessageHeader *) &pm[1]; | 309 | welcome = (struct WelcomeMessage *)pm->msg; |
304 | welcome = (struct WelcomeMessage *) &pm[1]; | 310 | pm->message_size = sizeof (struct WelcomeMessage); |
305 | welcome->header.size = htons (sizeof (struct WelcomeMessage)); | 311 | welcome->header.size = htons (sizeof (struct WelcomeMessage)); |
306 | welcome->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); | 312 | welcome->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); |
307 | welcome->clientIdentity = *plugin->env->my_identity; | 313 | welcome->clientIdentity = *plugin->env->my_identity; |
@@ -365,7 +371,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
365 | struct Session *session = cls; | 371 | struct Session *session = cls; |
366 | struct PendingMessage *pm; | 372 | struct PendingMessage *pm; |
367 | char *cbuf; | 373 | char *cbuf; |
368 | uint16_t msize; | 374 | |
369 | size_t ret; | 375 | size_t ret; |
370 | 376 | ||
371 | session->transmit_handle = NULL; | 377 | session->transmit_handle = NULL; |
@@ -384,8 +390,7 @@ do_transmit (void *cls, size_t size, void *buf) | |||
384 | #if DEBUG_TCP | 390 | #if DEBUG_TCP |
385 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 391 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
386 | "tcp", | 392 | "tcp", |
387 | "Failed to transmit message of type %u to `%4s'.\n", | 393 | "Failed to transmit message of to `%4s'.\n", |
388 | ntohs (pm->msg->type), | ||
389 | GNUNET_i2s (&session->target)); | 394 | GNUNET_i2s (&session->target)); |
390 | #endif | 395 | #endif |
391 | if (pm->transmit_cont != NULL) | 396 | if (pm->transmit_cont != NULL) |
@@ -399,12 +404,12 @@ do_transmit (void *cls, size_t size, void *buf) | |||
399 | cbuf = buf; | 404 | cbuf = buf; |
400 | while (NULL != (pm = session->pending_messages)) | 405 | while (NULL != (pm = session->pending_messages)) |
401 | { | 406 | { |
402 | if (size < (msize = ntohs (pm->msg->size))) | 407 | if (size < pm->message_size) |
403 | break; | 408 | break; |
404 | memcpy (cbuf, pm->msg, msize); | 409 | memcpy (cbuf, pm->msg, pm->message_size); |
405 | cbuf += msize; | 410 | cbuf += pm->message_size; |
406 | ret += msize; | 411 | ret += pm->message_size; |
407 | size -= msize; | 412 | size -= pm->message_size; |
408 | session->pending_messages = pm->next; | 413 | session->pending_messages = pm->next; |
409 | if (pm->transmit_cont != NULL) | 414 | if (pm->transmit_cont != NULL) |
410 | pm->transmit_cont (pm->transmit_cont_cls, | 415 | pm->transmit_cont (pm->transmit_cont_cls, |
@@ -437,7 +442,7 @@ process_pending_messages (struct Session *session) | |||
437 | return; | 442 | return; |
438 | session->transmit_handle | 443 | session->transmit_handle |
439 | = GNUNET_SERVER_notify_transmit_ready (session->client, | 444 | = GNUNET_SERVER_notify_transmit_ready (session->client, |
440 | ntohs (pm->msg->size), | 445 | pm->message_size, |
441 | GNUNET_TIME_absolute_get_remaining | 446 | GNUNET_TIME_absolute_get_remaining |
442 | (pm->timeout), | 447 | (pm->timeout), |
443 | &do_transmit, session); | 448 | &do_transmit, session); |
@@ -492,15 +497,16 @@ disconnect_session (struct Session *session) | |||
492 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 497 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
493 | "tcp", | 498 | "tcp", |
494 | pm->transmit_cont != NULL | 499 | pm->transmit_cont != NULL |
495 | ? "Could not deliver message of type %u to `%4s'.\n" | 500 | ? "Could not deliver message to `%4s'.\n" |
496 | : | 501 | : |
497 | "Could not deliver message of type %u to `%4s', notifying.\n", | 502 | "Could not deliver message to `%4s', notifying.\n", |
498 | ntohs (pm->msg->type), GNUNET_i2s (&session->target)); | 503 | GNUNET_i2s (&session->target)); |
499 | #endif | 504 | #endif |
500 | session->pending_messages = pm->next; | 505 | session->pending_messages = pm->next; |
501 | if (NULL != pm->transmit_cont) | 506 | if (NULL != pm->transmit_cont) |
502 | pm->transmit_cont (pm->transmit_cont_cls, | 507 | pm->transmit_cont (pm->transmit_cont_cls, |
503 | &session->target, GNUNET_SYSERR); | 508 | &session->target, GNUNET_SYSERR); |
509 | GNUNET_free(pm->msg); | ||
504 | GNUNET_free (pm); | 510 | GNUNET_free (pm); |
505 | } | 511 | } |
506 | if (GNUNET_NO == session->expecting_welcome) | 512 | if (GNUNET_NO == session->expecting_welcome) |
@@ -581,9 +587,7 @@ tcp_plugin_send (void *cls, | |||
581 | struct PendingMessage *pme; | 587 | struct PendingMessage *pme; |
582 | struct GNUNET_CONNECTION_Handle *sa; | 588 | struct GNUNET_CONNECTION_Handle *sa; |
583 | int af; | 589 | int af; |
584 | uint16_t mlen; | ||
585 | 590 | ||
586 | mlen = msgbuf_size; | ||
587 | session = find_session_by_target (plugin, target); | 591 | session = find_session_by_target (plugin, target); |
588 | if ( (session != NULL) && ((GNUNET_YES == force_address) && | 592 | if ( (session != NULL) && ((GNUNET_YES == force_address) && |
589 | ( (session->connect_alen != addrlen) || | 593 | ( (session->connect_alen != addrlen) || |
@@ -648,10 +652,17 @@ tcp_plugin_send (void *cls, | |||
648 | GNUNET_assert (session != NULL); | 652 | GNUNET_assert (session != NULL); |
649 | GNUNET_assert (session->client != NULL); | 653 | GNUNET_assert (session->client != NULL); |
650 | 654 | ||
655 | #if DEBUG_TCP | ||
656 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
657 | "tcp", | ||
658 | "Creating pending message of size %d\n", | ||
659 | msgbuf_size); | ||
660 | #endif | ||
651 | /* create new message entry */ | 661 | /* create new message entry */ |
652 | pm = GNUNET_malloc (mlen + sizeof (struct PendingMessage)); | 662 | pm = GNUNET_malloc (sizeof (struct PendingMessage)); |
653 | memcpy (&pm[1], msg, mlen); | 663 | pm->msg = GNUNET_malloc(msgbuf_size); |
654 | pm->msg = (const struct GNUNET_MessageHeader*) &pm[1]; | 664 | memcpy (pm->msg, msg, msgbuf_size); |
665 | pm->message_size = msgbuf_size; | ||
655 | pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); | 666 | pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
656 | pm->transmit_cont = cont; | 667 | pm->transmit_cont = cont; |
657 | pm->transmit_cont_cls = cont_cls; | 668 | pm->transmit_cont_cls = cont_cls; |
@@ -674,11 +685,11 @@ tcp_plugin_send (void *cls, | |||
674 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 685 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
675 | "tcp", | 686 | "tcp", |
676 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 687 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
677 | mlen, | 688 | msgbuf_size, |
678 | GNUNET_i2s (target)); | 689 | GNUNET_i2s (target)); |
679 | #endif | 690 | #endif |
680 | process_pending_messages (session); | 691 | process_pending_messages (session); |
681 | return mlen; | 692 | return msgbuf_size; |
682 | } | 693 | } |
683 | 694 | ||
684 | 695 | ||
@@ -1099,8 +1110,15 @@ handle_tcp_data (void *cls, | |||
1099 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 1110 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1100 | "tcp", "Received a welcome, NOT sending to clients!\n"); | 1111 | "tcp", "Received a welcome, NOT sending to clients!\n"); |
1101 | #endif | 1112 | #endif |
1102 | return; /* We don't want to propogate WELCOME messages up! */ | 1113 | return; /* We don't want to propagate WELCOME messages up! */ |
1103 | } | 1114 | } |
1115 | else | ||
1116 | { | ||
1117 | #if DEBUG_TCP | ||
1118 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
1119 | "tcp", "Received DATA message, checking session!\n"); | ||
1120 | #endif | ||
1121 | } | ||
1104 | 1122 | ||
1105 | if ( (NULL == session) || (GNUNET_NO != session->expecting_welcome)) | 1123 | if ( (NULL == session) || (GNUNET_NO != session->expecting_welcome)) |
1106 | { | 1124 | { |