diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-02 08:07:45 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2013-05-02 08:07:45 +0000 |
commit | 260604bbbc16a733158aac296eb1547c98816922 (patch) | |
tree | e0c935fac21f28e77f558cbe53970ae9269b5e6c /src/stream | |
parent | 4f8eb94dac19105be6420dcff8bf23bbc72b0a82 (diff) | |
download | gnunet-260604bbbc16a733158aac296eb1547c98816922.tar.gz gnunet-260604bbbc16a733158aac296eb1547c98816922.zip |
fix #2877: stream doesn't distinguish between the application ports
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/stream.h | 40 | ||||
-rw-r--r-- | src/stream/stream_api.c | 298 |
2 files changed, 147 insertions, 191 deletions
diff --git a/src/stream/stream.h b/src/stream/stream.h index 5c85f8b34..d9ba09f11 100644 --- a/src/stream/stream.h +++ b/src/stream/stream.h | |||
@@ -41,17 +41,20 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
44 | * The stream message header | 44 | * The HELLO message to begin the handshake |
45 | * All messages of STREAM should commonly have this as header | ||
46 | */ | 45 | */ |
47 | struct GNUNET_STREAM_MessageHeader | 46 | struct GNUNET_STREAM_HelloMessage |
48 | { | 47 | { |
49 | /** | 48 | /** |
50 | * The GNUNET message header, types are from GNUNET_MESSAGE_TYPE_STREAM_*-range. | 49 | * Type is GNUNET_MESSAGE_TYPE_STREAM_HELLO |
51 | */ | 50 | */ |
52 | struct GNUNET_MessageHeader header; | 51 | struct GNUNET_MessageHeader header; |
53 | }; | ||
54 | 52 | ||
53 | /** | ||
54 | * The application port number | ||
55 | */ | ||
56 | uint64_t port GNUNET_PACKED;; | ||
57 | }; | ||
55 | 58 | ||
56 | /** | 59 | /** |
57 | * The Data message, should be prefixed with stream header with its type set to | 60 | * The Data message, should be prefixed with stream header with its type set to |
@@ -63,7 +66,7 @@ struct GNUNET_STREAM_DataMessage | |||
63 | /** | 66 | /** |
64 | * Type is GNUNET_MESSAGE_TYPE_STREAM_DATA | 67 | * Type is GNUNET_MESSAGE_TYPE_STREAM_DATA |
65 | */ | 68 | */ |
66 | struct GNUNET_STREAM_MessageHeader header; | 69 | struct GNUNET_MessageHeader header; |
67 | 70 | ||
68 | /** | 71 | /** |
69 | * Sequence number; starts with a random value. (Just in case | 72 | * Sequence number; starts with a random value. (Just in case |
@@ -112,7 +115,7 @@ struct GNUNET_STREAM_AckMessage | |||
112 | /** | 115 | /** |
113 | * Type is GNUNET_MESSAGE_TYPE_STREAM_ACK | 116 | * Type is GNUNET_MESSAGE_TYPE_STREAM_ACK |
114 | */ | 117 | */ |
115 | struct GNUNET_STREAM_MessageHeader header; | 118 | struct GNUNET_MessageHeader header; |
116 | 119 | ||
117 | /** | 120 | /** |
118 | * The sequence number of the next Data Message receiver is | 121 | * The sequence number of the next Data Message receiver is |
@@ -142,7 +145,7 @@ struct GNUNET_STREAM_HelloAckMessage | |||
142 | /** | 145 | /** |
143 | * The stream message header | 146 | * The stream message header |
144 | */ | 147 | */ |
145 | struct GNUNET_STREAM_MessageHeader header; | 148 | struct GNUNET_MessageHeader header; |
146 | 149 | ||
147 | /** | 150 | /** |
148 | * The selected sequence number. Following data tranmissions from the sender | 151 | * The selected sequence number. Following data tranmissions from the sender |
@@ -158,25 +161,6 @@ struct GNUNET_STREAM_HelloAckMessage | |||
158 | uint32_t receiver_window_size GNUNET_PACKED; | 161 | uint32_t receiver_window_size GNUNET_PACKED; |
159 | }; | 162 | }; |
160 | 163 | ||
161 | |||
162 | /** | ||
163 | * The Transmit close message(used to signal transmission is closed) | ||
164 | * FIXME: dead struct? | ||
165 | */ | ||
166 | struct GNUNET_STREAM_TransmitCloseMessage | ||
167 | { | ||
168 | /** | ||
169 | * The stream message header | ||
170 | */ | ||
171 | struct GNUNET_STREAM_MessageHeader header; | ||
172 | |||
173 | /** | ||
174 | * The last sequence number of the packet after which the transmission has | ||
175 | * ended | ||
176 | */ | ||
177 | uint32_t final_sequence_number GNUNET_PACKED; | ||
178 | }; | ||
179 | |||
180 | GNUNET_NETWORK_STRUCT_END | 164 | GNUNET_NETWORK_STRUCT_END |
181 | 165 | ||
182 | 166 | ||
@@ -188,3 +172,5 @@ GNUNET_NETWORK_STRUCT_END | |||
188 | #endif | 172 | #endif |
189 | 173 | ||
190 | #endif /* STREAM.H */ | 174 | #endif /* STREAM.H */ |
175 | |||
176 | /* End of stream.h */ | ||
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index 4042e05cc..28e908105 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -145,7 +145,7 @@ struct MessageQueue | |||
145 | /** | 145 | /** |
146 | * The message | 146 | * The message |
147 | */ | 147 | */ |
148 | struct GNUNET_STREAM_MessageHeader *message; | 148 | struct GNUNET_MessageHeader *message; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Callback to be called when the message is sent | 151 | * Callback to be called when the message is sent |
@@ -313,7 +313,7 @@ struct GNUNET_STREAM_Socket | |||
313 | /** | 313 | /** |
314 | * The application port number (type: uint32_t) | 314 | * The application port number (type: uint32_t) |
315 | */ | 315 | */ |
316 | GNUNET_MESH_ApplicationType app_port; | 316 | GNUNET_MESH_ApplicationType port; |
317 | 317 | ||
318 | /** | 318 | /** |
319 | * The write sequence number to be set incase of testing | 319 | * The write sequence number to be set incase of testing |
@@ -621,12 +621,12 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
621 | GNUNET_NO, /* Corking */ | 621 | GNUNET_NO, /* Corking */ |
622 | socket->mesh_retry_timeout, | 622 | socket->mesh_retry_timeout, |
623 | &socket->other_peer, | 623 | &socket->other_peer, |
624 | ntohs (head->message->header.size), | 624 | ntohs (head->message->size), |
625 | &send_message_notify, | 625 | &send_message_notify, |
626 | socket); | 626 | socket); |
627 | return 0; | 627 | return 0; |
628 | } | 628 | } |
629 | ret = ntohs (head->message->header.size); | 629 | ret = ntohs (head->message->size); |
630 | GNUNET_assert (size >= ret); | 630 | GNUNET_assert (size >= ret); |
631 | memcpy (buf, head->message, ret); | 631 | memcpy (buf, head->message, ret); |
632 | if (NULL != head->finish_cb) | 632 | if (NULL != head->finish_cb) |
@@ -649,7 +649,7 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
649 | GNUNET_NO, /* Corking */ | 649 | GNUNET_NO, /* Corking */ |
650 | socket->mesh_retry_timeout, | 650 | socket->mesh_retry_timeout, |
651 | &socket->other_peer, | 651 | &socket->other_peer, |
652 | ntohs (head->message->header.size), | 652 | ntohs (head->message->size), |
653 | &send_message_notify, | 653 | &send_message_notify, |
654 | socket); | 654 | socket); |
655 | } | 655 | } |
@@ -669,21 +669,19 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
669 | */ | 669 | */ |
670 | static void | 670 | static void |
671 | queue_message (struct GNUNET_STREAM_Socket *socket, | 671 | queue_message (struct GNUNET_STREAM_Socket *socket, |
672 | struct GNUNET_STREAM_MessageHeader *message, | 672 | struct GNUNET_MessageHeader *message, |
673 | SendFinishCallback finish_cb, | 673 | SendFinishCallback finish_cb, |
674 | void *finish_cb_cls, | 674 | void *finish_cb_cls, |
675 | int urgent) | 675 | int urgent) |
676 | { | 676 | { |
677 | struct MessageQueue *queue_entity; | 677 | struct MessageQueue *queue_entity; |
678 | 678 | ||
679 | GNUNET_assert | 679 | GNUNET_assert ((ntohs (message->type) >= GNUNET_MESSAGE_TYPE_STREAM_DATA) |
680 | ((ntohs (message->header.type) >= GNUNET_MESSAGE_TYPE_STREAM_DATA) | 680 | && (ntohs (message->type) |
681 | && (ntohs (message->header.type) <= GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK)); | 681 | <= GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK)); |
682 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 682 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Queueing message of type %d and size %d\n", |
683 | "%s: Queueing message of type %d and size %d\n", | ||
684 | GNUNET_i2s (&socket->other_peer), | 683 | GNUNET_i2s (&socket->other_peer), |
685 | ntohs (message->header.type), | 684 | ntohs (message->type),ntohs (message->size)); |
686 | ntohs (message->header.size)); | ||
687 | GNUNET_assert (NULL != message); | 685 | GNUNET_assert (NULL != message); |
688 | queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); | 686 | queue_entity = GNUNET_malloc (sizeof (struct MessageQueue)); |
689 | queue_entity->message = message; | 687 | queue_entity->message = message; |
@@ -711,7 +709,7 @@ queue_message (struct GNUNET_STREAM_Socket *socket, | |||
711 | GNUNET_NO, /* Corking */ | 709 | GNUNET_NO, /* Corking */ |
712 | socket->mesh_retry_timeout, | 710 | socket->mesh_retry_timeout, |
713 | &socket->other_peer, | 711 | &socket->other_peer, |
714 | ntohs (message->header.size), | 712 | ntohs (message->size), |
715 | &send_message_notify, | 713 | &send_message_notify, |
716 | socket); | 714 | socket); |
717 | } | 715 | } |
@@ -729,14 +727,14 @@ queue_message (struct GNUNET_STREAM_Socket *socket, | |||
729 | */ | 727 | */ |
730 | static void | 728 | static void |
731 | copy_and_queue_message (struct GNUNET_STREAM_Socket *socket, | 729 | copy_and_queue_message (struct GNUNET_STREAM_Socket *socket, |
732 | const struct GNUNET_STREAM_MessageHeader *message, | 730 | const struct GNUNET_MessageHeader *message, |
733 | SendFinishCallback finish_cb, | 731 | SendFinishCallback finish_cb, |
734 | void *finish_cb_cls) | 732 | void *finish_cb_cls) |
735 | { | 733 | { |
736 | struct GNUNET_STREAM_MessageHeader *msg_copy; | 734 | struct GNUNET_MessageHeader *msg_copy; |
737 | uint16_t size; | 735 | uint16_t size; |
738 | 736 | ||
739 | size = ntohs (message->header.size); | 737 | size = ntohs (message->size); |
740 | msg_copy = GNUNET_malloc (size); | 738 | msg_copy = GNUNET_malloc (size); |
741 | memcpy (msg_copy, message, size); | 739 | memcpy (msg_copy, message, size); |
742 | queue_message (socket, msg_copy, finish_cb, finish_cb_cls, GNUNET_NO); | 740 | queue_message (socket, msg_copy, finish_cb, finish_cb_cls, GNUNET_NO); |
@@ -793,9 +791,9 @@ ack_task (void *cls, | |||
793 | return; | 791 | return; |
794 | /* Create the ACK Message */ | 792 | /* Create the ACK Message */ |
795 | ack_msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_AckMessage)); | 793 | ack_msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_AckMessage)); |
796 | ack_msg->header.header.size = htons (sizeof (struct | 794 | ack_msg->header.size = htons (sizeof (struct |
797 | GNUNET_STREAM_AckMessage)); | 795 | GNUNET_STREAM_AckMessage)); |
798 | ack_msg->header.header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_ACK); | 796 | ack_msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_ACK); |
799 | ack_msg->bitmap = GNUNET_htonll (socket->ack_bitmap); | 797 | ack_msg->bitmap = GNUNET_htonll (socket->ack_bitmap); |
800 | ack_msg->base_sequence_number = htonl (socket->read_sequence_number); | 798 | ack_msg->base_sequence_number = htonl (socket->read_sequence_number); |
801 | ack_msg->receive_window_remaining = | 799 | ack_msg->receive_window_remaining = |
@@ -816,7 +814,7 @@ close_msg_retransmission_task (void *cls, | |||
816 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 814 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
817 | { | 815 | { |
818 | struct GNUNET_STREAM_ShutdownHandle *shutdown_handle = cls; | 816 | struct GNUNET_STREAM_ShutdownHandle *shutdown_handle = cls; |
819 | struct GNUNET_STREAM_MessageHeader *msg; | 817 | struct GNUNET_MessageHeader *msg; |
820 | struct GNUNET_STREAM_Socket *socket; | 818 | struct GNUNET_STREAM_Socket *socket; |
821 | 819 | ||
822 | shutdown_handle->close_msg_retransmission_task_id = GNUNET_SCHEDULER_NO_TASK; | 820 | shutdown_handle->close_msg_retransmission_task_id = GNUNET_SCHEDULER_NO_TASK; |
@@ -824,18 +822,18 @@ close_msg_retransmission_task (void *cls, | |||
824 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 822 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
825 | return; | 823 | return; |
826 | socket = shutdown_handle->socket; | 824 | socket = shutdown_handle->socket; |
827 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 825 | msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
828 | msg->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 826 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
829 | switch (shutdown_handle->operation) | 827 | switch (shutdown_handle->operation) |
830 | { | 828 | { |
831 | case SHUT_RDWR: | 829 | case SHUT_RDWR: |
832 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); | 830 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); |
833 | break; | 831 | break; |
834 | case SHUT_RD: | 832 | case SHUT_RD: |
835 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); | 833 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); |
836 | break; | 834 | break; |
837 | case SHUT_WR: | 835 | case SHUT_WR: |
838 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); | 836 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); |
839 | break; | 837 | break; |
840 | default: | 838 | default: |
841 | GNUNET_free (msg); | 839 | GNUNET_free (msg); |
@@ -918,10 +916,10 @@ write_data (struct GNUNET_STREAM_Socket *socket) | |||
918 | while ((packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) && | 916 | while ((packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) && |
919 | (NULL != io_handle->messages[packet]) && | 917 | (NULL != io_handle->messages[packet]) && |
920 | (socket->receiver_window_available | 918 | (socket->receiver_window_available |
921 | >= ntohs (io_handle->messages[packet]->header.header.size))) | 919 | >= ntohs (io_handle->messages[packet]->header.size))) |
922 | { | 920 | { |
923 | socket->receiver_window_available -= | 921 | socket->receiver_window_available -= |
924 | ntohs (io_handle->messages[packet]->header.header.size); | 922 | ntohs (io_handle->messages[packet]->header.size); |
925 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 923 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
926 | "%s: Placing DATA message with sequence %u in send queue\n", | 924 | "%s: Placing DATA message with sequence %u in send queue\n", |
927 | GNUNET_i2s (&socket->other_peer), | 925 | GNUNET_i2s (&socket->other_peer), |
@@ -1150,7 +1148,7 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1150 | uint32_t relative_sequence_number; | 1148 | uint32_t relative_sequence_number; |
1151 | uint16_t size; | 1149 | uint16_t size; |
1152 | 1150 | ||
1153 | size = htons (msg->header.header.size); | 1151 | size = htons (msg->header.size); |
1154 | if (size < sizeof (struct GNUNET_STREAM_DataMessage)) | 1152 | if (size < sizeof (struct GNUNET_STREAM_DataMessage)) |
1155 | { | 1153 | { |
1156 | GNUNET_break_op (0); | 1154 | GNUNET_break_op (0); |
@@ -1208,9 +1206,9 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1208 | return GNUNET_YES; | 1206 | return GNUNET_YES; |
1209 | } | 1207 | } |
1210 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1208 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1211 | "%s: Receiving DATA with sequence number: %u and size: %d from %s\n", | 1209 | "%1$s: Receiving DATA with sequence number: %2$u and size: %3$d from " |
1212 | GNUNET_i2s (&socket->other_peer), ntohl (msg->sequence_number), | 1210 | "%1$s\n", GNUNET_i2s (&socket->other_peer), |
1213 | ntohs (msg->header.header.size), GNUNET_i2s (&socket->other_peer)); | 1211 | ntohl (msg->sequence_number), ntohs (msg->header.size)); |
1214 | /* Check if we have to allocate the buffer */ | 1212 | /* Check if we have to allocate the buffer */ |
1215 | size -= sizeof (struct GNUNET_STREAM_DataMessage); | 1213 | size -= sizeof (struct GNUNET_STREAM_DataMessage); |
1216 | relative_offset = ntohl (msg->offset) - socket->read_offset; | 1214 | relative_offset = ntohl (msg->offset) - socket->read_offset; |
@@ -1460,15 +1458,16 @@ set_state_closed (void *cls, | |||
1460 | * | 1458 | * |
1461 | * @return the generate hello message | 1459 | * @return the generate hello message |
1462 | */ | 1460 | */ |
1463 | static struct GNUNET_STREAM_MessageHeader * | 1461 | static struct GNUNET_MessageHeader * |
1464 | generate_hello (void) | 1462 | generate_hello (struct GNUNET_STREAM_Socket *socket) |
1465 | { | 1463 | { |
1466 | struct GNUNET_STREAM_MessageHeader *msg; | 1464 | struct GNUNET_STREAM_HelloMessage *msg; |
1467 | 1465 | ||
1468 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1466 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloMessage)); |
1469 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO); | 1467 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO); |
1470 | msg->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1468 | msg->header.size = htons (sizeof (struct GNUNET_STREAM_HelloMessage)); |
1471 | return msg; | 1469 | msg->port = GNUNET_htonll ((uint64_t) socket->port); |
1470 | return &msg->header; | ||
1472 | } | 1471 | } |
1473 | 1472 | ||
1474 | 1473 | ||
@@ -1500,9 +1499,9 @@ generate_hello_ack (struct GNUNET_STREAM_Socket *socket, | |||
1500 | (unsigned int) socket->write_sequence_number); | 1499 | (unsigned int) socket->write_sequence_number); |
1501 | } | 1500 | } |
1502 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); | 1501 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); |
1503 | msg->header.header.size = | 1502 | msg->header.size = |
1504 | htons (sizeof (struct GNUNET_STREAM_HelloAckMessage)); | 1503 | htons (sizeof (struct GNUNET_STREAM_HelloAckMessage)); |
1505 | msg->header.header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK); | 1504 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK); |
1506 | msg->sequence_number = htonl (socket->write_sequence_number); | 1505 | msg->sequence_number = htonl (socket->write_sequence_number); |
1507 | msg->receiver_window_size = htonl (RECEIVE_BUFFER_SIZE); | 1506 | msg->receiver_window_size = htonl (RECEIVE_BUFFER_SIZE); |
1508 | return msg; | 1507 | return msg; |
@@ -1537,10 +1536,10 @@ control_retransmission_task (void *cls, | |||
1537 | break; | 1536 | break; |
1538 | case STATE_HELLO_WAIT: | 1537 | case STATE_HELLO_WAIT: |
1539 | if (NULL == socket->lsocket) /* We are client */ | 1538 | if (NULL == socket->lsocket) /* We are client */ |
1540 | queue_message (socket, generate_hello (), NULL, NULL, GNUNET_NO); | 1539 | queue_message (socket, generate_hello (socket), NULL, NULL, GNUNET_NO); |
1541 | else | 1540 | else |
1542 | queue_message (socket, | 1541 | queue_message (socket, |
1543 | (struct GNUNET_STREAM_MessageHeader *) | 1542 | (struct GNUNET_MessageHeader *) |
1544 | generate_hello_ack (socket, GNUNET_NO), NULL, NULL, | 1543 | generate_hello_ack (socket, GNUNET_NO), NULL, NULL, |
1545 | GNUNET_NO); | 1544 | GNUNET_NO); |
1546 | socket->control_retransmission_task_id = | 1545 | socket->control_retransmission_task_id = |
@@ -1550,7 +1549,7 @@ control_retransmission_task (void *cls, | |||
1550 | case STATE_ESTABLISHED: | 1549 | case STATE_ESTABLISHED: |
1551 | if (NULL == socket->lsocket) | 1550 | if (NULL == socket->lsocket) |
1552 | queue_message (socket, | 1551 | queue_message (socket, |
1553 | (struct GNUNET_STREAM_MessageHeader *) | 1552 | (struct GNUNET_MessageHeader *) |
1554 | generate_hello_ack (socket, GNUNET_NO), NULL, NULL, | 1553 | generate_hello_ack (socket, GNUNET_NO), NULL, NULL, |
1555 | GNUNET_NO); | 1554 | GNUNET_NO); |
1556 | else | 1555 | else |
@@ -1726,10 +1725,10 @@ static int | |||
1726 | handle_transmit_close (struct GNUNET_STREAM_Socket *socket, | 1725 | handle_transmit_close (struct GNUNET_STREAM_Socket *socket, |
1727 | struct GNUNET_MESH_Tunnel *tunnel, | 1726 | struct GNUNET_MESH_Tunnel *tunnel, |
1728 | const struct GNUNET_PeerIdentity *sender, | 1727 | const struct GNUNET_PeerIdentity *sender, |
1729 | const struct GNUNET_STREAM_MessageHeader *msg, | 1728 | const struct GNUNET_MessageHeader *msg, |
1730 | const struct GNUNET_ATS_Information*atsi) | 1729 | const struct GNUNET_ATS_Information*atsi) |
1731 | { | 1730 | { |
1732 | struct GNUNET_STREAM_MessageHeader *reply; | 1731 | struct GNUNET_MessageHeader *reply; |
1733 | 1732 | ||
1734 | switch (socket->state) | 1733 | switch (socket->state) |
1735 | { | 1734 | { |
@@ -1744,13 +1743,12 @@ handle_transmit_close (struct GNUNET_STREAM_Socket *socket, | |||
1744 | break; | 1743 | break; |
1745 | } | 1744 | } |
1746 | /* Send TRANSMIT_CLOSE_ACK */ | 1745 | /* Send TRANSMIT_CLOSE_ACK */ |
1747 | reply = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1746 | reply = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
1748 | reply->header.type = | 1747 | reply->type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK); |
1749 | htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK); | 1748 | reply->size = htons (sizeof (struct GNUNET_MessageHeader)); |
1750 | reply->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | ||
1751 | queue_message (socket, reply, NULL, NULL, GNUNET_NO); | 1749 | queue_message (socket, reply, NULL, NULL, GNUNET_NO); |
1752 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received TRANSMIT_CLOSE from %s\n", | 1750 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%1$s: Received TRANSMIT_CLOSE from %1$s\n", |
1753 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); | 1751 | GNUNET_i2s (&socket->other_peer)); |
1754 | switch(socket->state) | 1752 | switch(socket->state) |
1755 | { | 1753 | { |
1756 | case STATE_RECEIVE_CLOSED: | 1754 | case STATE_RECEIVE_CLOSED: |
@@ -1795,7 +1793,7 @@ client_handle_transmit_close (void *cls, | |||
1795 | return handle_transmit_close (socket, | 1793 | return handle_transmit_close (socket, |
1796 | tunnel, | 1794 | tunnel, |
1797 | sender, | 1795 | sender, |
1798 | (struct GNUNET_STREAM_MessageHeader *)message, | 1796 | (struct GNUNET_MessageHeader *)message, |
1799 | atsi); | 1797 | atsi); |
1800 | } | 1798 | } |
1801 | 1799 | ||
@@ -1838,7 +1836,7 @@ static int | |||
1838 | handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | 1836 | handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, |
1839 | struct GNUNET_MESH_Tunnel *tunnel, | 1837 | struct GNUNET_MESH_Tunnel *tunnel, |
1840 | const struct GNUNET_PeerIdentity *sender, | 1838 | const struct GNUNET_PeerIdentity *sender, |
1841 | const struct GNUNET_STREAM_MessageHeader *message, | 1839 | const struct GNUNET_MessageHeader *message, |
1842 | const struct GNUNET_ATS_Information *atsi, | 1840 | const struct GNUNET_ATS_Information *atsi, |
1843 | int operation) | 1841 | int operation) |
1844 | { | 1842 | { |
@@ -1964,7 +1962,7 @@ client_handle_transmit_close_ack (void *cls, | |||
1964 | return handle_generic_close_ack (socket, | 1962 | return handle_generic_close_ack (socket, |
1965 | tunnel, | 1963 | tunnel, |
1966 | sender, | 1964 | sender, |
1967 | (const struct GNUNET_STREAM_MessageHeader *) | 1965 | (const struct GNUNET_MessageHeader *) |
1968 | message, | 1966 | message, |
1969 | atsi, | 1967 | atsi, |
1970 | SHUT_WR); | 1968 | SHUT_WR); |
@@ -1986,10 +1984,10 @@ static int | |||
1986 | handle_receive_close (struct GNUNET_STREAM_Socket *socket, | 1984 | handle_receive_close (struct GNUNET_STREAM_Socket *socket, |
1987 | struct GNUNET_MESH_Tunnel *tunnel, | 1985 | struct GNUNET_MESH_Tunnel *tunnel, |
1988 | const struct GNUNET_PeerIdentity *sender, | 1986 | const struct GNUNET_PeerIdentity *sender, |
1989 | const struct GNUNET_STREAM_MessageHeader *message, | 1987 | const struct GNUNET_MessageHeader *message, |
1990 | const struct GNUNET_ATS_Information *atsi) | 1988 | const struct GNUNET_ATS_Information *atsi) |
1991 | { | 1989 | { |
1992 | struct GNUNET_STREAM_MessageHeader *receive_close_ack; | 1990 | struct GNUNET_MessageHeader *receive_close_ack; |
1993 | 1991 | ||
1994 | switch (socket->state) | 1992 | switch (socket->state) |
1995 | { | 1993 | { |
@@ -2005,12 +2003,10 @@ handle_receive_close (struct GNUNET_STREAM_Socket *socket, | |||
2005 | } | 2003 | } |
2006 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received RECEIVE_CLOSE from %s\n", | 2004 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received RECEIVE_CLOSE from %s\n", |
2007 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); | 2005 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); |
2008 | receive_close_ack = | 2006 | receive_close_ack = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
2009 | GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2007 | receive_close_ack->size = htons (sizeof (struct GNUNET_MessageHeader)); |
2010 | receive_close_ack->header.size = | 2008 | receive_close_ack->type = |
2011 | htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2009 | htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK); |
2012 | receive_close_ack->header.type = | ||
2013 | htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK); | ||
2014 | queue_message (socket, receive_close_ack, NULL, NULL, GNUNET_NO); | 2010 | queue_message (socket, receive_close_ack, NULL, NULL, GNUNET_NO); |
2015 | switch (socket->state) | 2011 | switch (socket->state) |
2016 | { | 2012 | { |
@@ -2057,7 +2053,7 @@ client_handle_receive_close (void *cls, | |||
2057 | handle_receive_close (socket, | 2053 | handle_receive_close (socket, |
2058 | tunnel, | 2054 | tunnel, |
2059 | sender, | 2055 | sender, |
2060 | (const struct GNUNET_STREAM_MessageHeader *) message, | 2056 | (const struct GNUNET_MessageHeader *) message, |
2061 | atsi); | 2057 | atsi); |
2062 | } | 2058 | } |
2063 | 2059 | ||
@@ -2087,7 +2083,7 @@ client_handle_receive_close_ack (void *cls, | |||
2087 | return handle_generic_close_ack (socket, | 2083 | return handle_generic_close_ack (socket, |
2088 | tunnel, | 2084 | tunnel, |
2089 | sender, | 2085 | sender, |
2090 | (const struct GNUNET_STREAM_MessageHeader *) | 2086 | (const struct GNUNET_MessageHeader *) |
2091 | message, | 2087 | message, |
2092 | atsi, | 2088 | atsi, |
2093 | SHUT_RD); | 2089 | SHUT_RD); |
@@ -2109,10 +2105,10 @@ static int | |||
2109 | handle_close (struct GNUNET_STREAM_Socket *socket, | 2105 | handle_close (struct GNUNET_STREAM_Socket *socket, |
2110 | struct GNUNET_MESH_Tunnel *tunnel, | 2106 | struct GNUNET_MESH_Tunnel *tunnel, |
2111 | const struct GNUNET_PeerIdentity *sender, | 2107 | const struct GNUNET_PeerIdentity *sender, |
2112 | const struct GNUNET_STREAM_MessageHeader *message, | 2108 | const struct GNUNET_MessageHeader *message, |
2113 | const struct GNUNET_ATS_Information*atsi) | 2109 | const struct GNUNET_ATS_Information*atsi) |
2114 | { | 2110 | { |
2115 | struct GNUNET_STREAM_MessageHeader *close_ack; | 2111 | struct GNUNET_MessageHeader *close_ack; |
2116 | 2112 | ||
2117 | switch (socket->state) | 2113 | switch (socket->state) |
2118 | { | 2114 | { |
@@ -2128,9 +2124,9 @@ handle_close (struct GNUNET_STREAM_Socket *socket, | |||
2128 | } | 2124 | } |
2129 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received CLOSE from %s\n", | 2125 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s: Received CLOSE from %s\n", |
2130 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); | 2126 | GNUNET_i2s (&socket->other_peer), GNUNET_i2s (&socket->other_peer)); |
2131 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2127 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
2132 | close_ack->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 2128 | close_ack->size = htons (sizeof (struct GNUNET_MessageHeader)); |
2133 | close_ack->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); | 2129 | close_ack->type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); |
2134 | queue_message (socket, close_ack, &set_state_closed, NULL, GNUNET_NO); | 2130 | queue_message (socket, close_ack, &set_state_closed, NULL, GNUNET_NO); |
2135 | if ((STATE_CLOSED == socket->state) || (STATE_CLOSE_WAIT == socket->state)) | 2131 | if ((STATE_CLOSED == socket->state) || (STATE_CLOSE_WAIT == socket->state)) |
2136 | return GNUNET_OK; | 2132 | return GNUNET_OK; |
@@ -2167,7 +2163,7 @@ client_handle_close (void *cls, | |||
2167 | return handle_close (socket, | 2163 | return handle_close (socket, |
2168 | tunnel, | 2164 | tunnel, |
2169 | sender, | 2165 | sender, |
2170 | (const struct GNUNET_STREAM_MessageHeader *) message, | 2166 | (const struct GNUNET_MessageHeader *) message, |
2171 | atsi); | 2167 | atsi); |
2172 | } | 2168 | } |
2173 | 2169 | ||
@@ -2197,7 +2193,7 @@ client_handle_close_ack (void *cls, | |||
2197 | return handle_generic_close_ack (socket, | 2193 | return handle_generic_close_ack (socket, |
2198 | tunnel, | 2194 | tunnel, |
2199 | sender, | 2195 | sender, |
2200 | (const struct GNUNET_STREAM_MessageHeader *) | 2196 | (const struct GNUNET_MessageHeader *) |
2201 | message, | 2197 | message, |
2202 | atsi, | 2198 | atsi, |
2203 | SHUT_RDWR); | 2199 | SHUT_RDWR); |
@@ -2258,8 +2254,11 @@ server_handle_hello (void *cls, | |||
2258 | const struct GNUNET_ATS_Information*atsi) | 2254 | const struct GNUNET_ATS_Information*atsi) |
2259 | { | 2255 | { |
2260 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2256 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2257 | const struct GNUNET_STREAM_HelloMessage *hello; | ||
2261 | struct GNUNET_STREAM_HelloAckMessage *reply; | 2258 | struct GNUNET_STREAM_HelloAckMessage *reply; |
2259 | uint32_t port; | ||
2262 | 2260 | ||
2261 | hello = (const struct GNUNET_STREAM_HelloMessage *) message; | ||
2263 | if (0 != memcmp (sender, | 2262 | if (0 != memcmp (sender, |
2264 | &socket->other_peer, | 2263 | &socket->other_peer, |
2265 | sizeof (struct GNUNET_PeerIdentity))) | 2264 | sizeof (struct GNUNET_PeerIdentity))) |
@@ -2270,11 +2269,19 @@ server_handle_hello (void *cls, | |||
2270 | } | 2269 | } |
2271 | GNUNET_assert (GNUNET_MESSAGE_TYPE_STREAM_HELLO == ntohs (message->type)); | 2270 | GNUNET_assert (GNUNET_MESSAGE_TYPE_STREAM_HELLO == ntohs (message->type)); |
2272 | GNUNET_assert (socket->tunnel == tunnel); | 2271 | GNUNET_assert (socket->tunnel == tunnel); |
2273 | LOG_DEBUG ("%s: Received HELLO from %s\n", GNUNET_i2s (&socket->other_peer), | 2272 | LOG_DEBUG ("%1$s: Received HELLO from %1$s\n", |
2274 | GNUNET_i2s (&socket->other_peer)); | 2273 | GNUNET_i2s (&socket->other_peer)); |
2274 | port = (uint32_t) GNUNET_ntohll (hello->port); | ||
2275 | switch (socket->state) | 2275 | switch (socket->state) |
2276 | { | 2276 | { |
2277 | case STATE_INIT: | 2277 | case STATE_INIT: |
2278 | if (port != socket->port) | ||
2279 | { | ||
2280 | LOG_DEBUG ("Ignoring HELLO for port %u\n", port); | ||
2281 | GNUNET_MESH_tunnel_destroy (tunnel); | ||
2282 | GNUNET_free (socket); | ||
2283 | return GNUNET_OK; | ||
2284 | } | ||
2278 | reply = generate_hello_ack (socket, GNUNET_YES); | 2285 | reply = generate_hello_ack (socket, GNUNET_YES); |
2279 | queue_message (socket, &reply->header, &set_state_hello_wait, NULL, | 2286 | queue_message (socket, &reply->header, &set_state_hello_wait, NULL, |
2280 | GNUNET_NO); | 2287 | GNUNET_NO); |
@@ -2373,7 +2380,7 @@ server_handle_reset (void *cls, | |||
2373 | const struct GNUNET_ATS_Information*atsi) | 2380 | const struct GNUNET_ATS_Information*atsi) |
2374 | { | 2381 | { |
2375 | // struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2382 | // struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2376 | 2383 | /* FIXME */ | |
2377 | return GNUNET_OK; | 2384 | return GNUNET_OK; |
2378 | } | 2385 | } |
2379 | 2386 | ||
@@ -2400,11 +2407,7 @@ server_handle_transmit_close (void *cls, | |||
2400 | { | 2407 | { |
2401 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2408 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2402 | 2409 | ||
2403 | return handle_transmit_close (socket, | 2410 | return handle_transmit_close (socket, tunnel, sender, message, atsi); |
2404 | tunnel, | ||
2405 | sender, | ||
2406 | (struct GNUNET_STREAM_MessageHeader *)message, | ||
2407 | atsi); | ||
2408 | } | 2411 | } |
2409 | 2412 | ||
2410 | 2413 | ||
@@ -2430,12 +2433,7 @@ server_handle_transmit_close_ack (void *cls, | |||
2430 | { | 2433 | { |
2431 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2434 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2432 | 2435 | ||
2433 | return handle_generic_close_ack (socket, | 2436 | return handle_generic_close_ack (socket, tunnel, sender, message, atsi, |
2434 | tunnel, | ||
2435 | sender, | ||
2436 | (const struct GNUNET_STREAM_MessageHeader *) | ||
2437 | message, | ||
2438 | atsi, | ||
2439 | SHUT_WR); | 2437 | SHUT_WR); |
2440 | } | 2438 | } |
2441 | 2439 | ||
@@ -2462,12 +2460,7 @@ server_handle_receive_close (void *cls, | |||
2462 | { | 2460 | { |
2463 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2461 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2464 | 2462 | ||
2465 | return | 2463 | return handle_receive_close (socket, tunnel, sender, message, atsi); |
2466 | handle_receive_close (socket, | ||
2467 | tunnel, | ||
2468 | sender, | ||
2469 | (const struct GNUNET_STREAM_MessageHeader *) message, | ||
2470 | atsi); | ||
2471 | } | 2464 | } |
2472 | 2465 | ||
2473 | 2466 | ||
@@ -2493,12 +2486,7 @@ server_handle_receive_close_ack (void *cls, | |||
2493 | { | 2486 | { |
2494 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2487 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2495 | 2488 | ||
2496 | return handle_generic_close_ack (socket, | 2489 | return handle_generic_close_ack (socket, tunnel, sender, message, atsi, |
2497 | tunnel, | ||
2498 | sender, | ||
2499 | (const struct GNUNET_STREAM_MessageHeader *) | ||
2500 | message, | ||
2501 | atsi, | ||
2502 | SHUT_RD); | 2490 | SHUT_RD); |
2503 | } | 2491 | } |
2504 | 2492 | ||
@@ -2526,11 +2514,7 @@ server_handle_close (void *cls, | |||
2526 | { | 2514 | { |
2527 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2515 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2528 | 2516 | ||
2529 | return handle_close (socket, | 2517 | return handle_close (socket, tunnel, sender, message, atsi); |
2530 | tunnel, | ||
2531 | sender, | ||
2532 | (const struct GNUNET_STREAM_MessageHeader *) message, | ||
2533 | atsi); | ||
2534 | } | 2518 | } |
2535 | 2519 | ||
2536 | 2520 | ||
@@ -2556,12 +2540,7 @@ server_handle_close_ack (void *cls, | |||
2556 | { | 2540 | { |
2557 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 2541 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
2558 | 2542 | ||
2559 | return handle_generic_close_ack (socket, | 2543 | return handle_generic_close_ack (socket, tunnel, sender, message, atsi, |
2560 | tunnel, | ||
2561 | sender, | ||
2562 | (const struct GNUNET_STREAM_MessageHeader *) | ||
2563 | message, | ||
2564 | atsi, | ||
2565 | SHUT_RDWR); | 2544 | SHUT_RDWR); |
2566 | } | 2545 | } |
2567 | 2546 | ||
@@ -2742,8 +2721,9 @@ client_handle_ack (void *cls, | |||
2742 | const struct GNUNET_ATS_Information*atsi) | 2721 | const struct GNUNET_ATS_Information*atsi) |
2743 | { | 2722 | { |
2744 | struct GNUNET_STREAM_Socket *socket = cls; | 2723 | struct GNUNET_STREAM_Socket *socket = cls; |
2745 | const struct GNUNET_STREAM_AckMessage *ack = (const struct GNUNET_STREAM_AckMessage *) message; | 2724 | const struct GNUNET_STREAM_AckMessage *ack; |
2746 | 2725 | ||
2726 | ack = (const struct GNUNET_STREAM_AckMessage *) message; | ||
2747 | return handle_ack (socket, tunnel, sender, ack, atsi); | 2727 | return handle_ack (socket, tunnel, sender, ack, atsi); |
2748 | } | 2728 | } |
2749 | 2729 | ||
@@ -2786,19 +2766,19 @@ static struct GNUNET_MESH_MessageHandler client_message_handlers[] = { | |||
2786 | {&client_handle_hello_ack, GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK, | 2766 | {&client_handle_hello_ack, GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK, |
2787 | sizeof (struct GNUNET_STREAM_HelloAckMessage)}, | 2767 | sizeof (struct GNUNET_STREAM_HelloAckMessage)}, |
2788 | {&client_handle_reset, GNUNET_MESSAGE_TYPE_STREAM_RESET, | 2768 | {&client_handle_reset, GNUNET_MESSAGE_TYPE_STREAM_RESET, |
2789 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2769 | sizeof (struct GNUNET_MessageHeader)}, |
2790 | {&client_handle_transmit_close, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE, | 2770 | {&client_handle_transmit_close, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE, |
2791 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2771 | sizeof (struct GNUNET_MessageHeader)}, |
2792 | {&client_handle_transmit_close_ack, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK, | 2772 | {&client_handle_transmit_close_ack, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK, |
2793 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2773 | sizeof (struct GNUNET_MessageHeader)}, |
2794 | {&client_handle_receive_close, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE, | 2774 | {&client_handle_receive_close, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE, |
2795 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2775 | sizeof (struct GNUNET_MessageHeader)}, |
2796 | {&client_handle_receive_close_ack, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK, | 2776 | {&client_handle_receive_close_ack, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK, |
2797 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2777 | sizeof (struct GNUNET_MessageHeader)}, |
2798 | {&client_handle_close, GNUNET_MESSAGE_TYPE_STREAM_CLOSE, | 2778 | {&client_handle_close, GNUNET_MESSAGE_TYPE_STREAM_CLOSE, |
2799 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2779 | sizeof (struct GNUNET_MessageHeader)}, |
2800 | {&client_handle_close_ack, GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK, | 2780 | {&client_handle_close_ack, GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK, |
2801 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2781 | sizeof (struct GNUNET_MessageHeader)}, |
2802 | {NULL, 0, 0} | 2782 | {NULL, 0, 0} |
2803 | }; | 2783 | }; |
2804 | 2784 | ||
@@ -2812,23 +2792,23 @@ static struct GNUNET_MESH_MessageHandler server_message_handlers[] = { | |||
2812 | {&server_handle_ack, GNUNET_MESSAGE_TYPE_STREAM_ACK, | 2792 | {&server_handle_ack, GNUNET_MESSAGE_TYPE_STREAM_ACK, |
2813 | sizeof (struct GNUNET_STREAM_AckMessage) }, | 2793 | sizeof (struct GNUNET_STREAM_AckMessage) }, |
2814 | {&server_handle_hello, GNUNET_MESSAGE_TYPE_STREAM_HELLO, | 2794 | {&server_handle_hello, GNUNET_MESSAGE_TYPE_STREAM_HELLO, |
2815 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2795 | sizeof (struct GNUNET_STREAM_HelloMessage)}, |
2816 | {&server_handle_hello_ack, GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK, | 2796 | {&server_handle_hello_ack, GNUNET_MESSAGE_TYPE_STREAM_HELLO_ACK, |
2817 | sizeof (struct GNUNET_STREAM_HelloAckMessage)}, | 2797 | sizeof (struct GNUNET_STREAM_HelloAckMessage)}, |
2818 | {&server_handle_reset, GNUNET_MESSAGE_TYPE_STREAM_RESET, | 2798 | {&server_handle_reset, GNUNET_MESSAGE_TYPE_STREAM_RESET, |
2819 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2799 | sizeof (struct GNUNET_MessageHeader)}, |
2820 | {&server_handle_transmit_close, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE, | 2800 | {&server_handle_transmit_close, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE, |
2821 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2801 | sizeof (struct GNUNET_MessageHeader)}, |
2822 | {&server_handle_transmit_close_ack, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK, | 2802 | {&server_handle_transmit_close_ack, GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE_ACK, |
2823 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2803 | sizeof (struct GNUNET_MessageHeader)}, |
2824 | {&server_handle_receive_close, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE, | 2804 | {&server_handle_receive_close, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE, |
2825 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2805 | sizeof (struct GNUNET_MessageHeader)}, |
2826 | {&server_handle_receive_close_ack, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK, | 2806 | {&server_handle_receive_close_ack, GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE_ACK, |
2827 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2807 | sizeof (struct GNUNET_MessageHeader)}, |
2828 | {&server_handle_close, GNUNET_MESSAGE_TYPE_STREAM_CLOSE, | 2808 | {&server_handle_close, GNUNET_MESSAGE_TYPE_STREAM_CLOSE, |
2829 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2809 | sizeof (struct GNUNET_MessageHeader)}, |
2830 | {&server_handle_close_ack, GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK, | 2810 | {&server_handle_close_ack, GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK, |
2831 | sizeof (struct GNUNET_STREAM_MessageHeader)}, | 2811 | sizeof (struct GNUNET_MessageHeader)}, |
2832 | {NULL, 0, 0} | 2812 | {NULL, 0, 0} |
2833 | }; | 2813 | }; |
2834 | 2814 | ||
@@ -2846,7 +2826,7 @@ mesh_peer_connect_callback (void *cls, | |||
2846 | const struct GNUNET_ATS_Information * atsi) | 2826 | const struct GNUNET_ATS_Information * atsi) |
2847 | { | 2827 | { |
2848 | struct GNUNET_STREAM_Socket *socket = cls; | 2828 | struct GNUNET_STREAM_Socket *socket = cls; |
2849 | struct GNUNET_STREAM_MessageHeader *message; | 2829 | struct GNUNET_MessageHeader *message; |
2850 | 2830 | ||
2851 | if (0 != memcmp (peer, | 2831 | if (0 != memcmp (peer, |
2852 | &socket->other_peer, | 2832 | &socket->other_peer, |
@@ -2864,10 +2844,10 @@ mesh_peer_connect_callback (void *cls, | |||
2864 | /* Set state to INIT */ | 2844 | /* Set state to INIT */ |
2865 | socket->state = STATE_INIT; | 2845 | socket->state = STATE_INIT; |
2866 | /* Send HELLO message */ | 2846 | /* Send HELLO message */ |
2867 | message = generate_hello (); | 2847 | message = generate_hello (socket); |
2868 | queue_message (socket, message, &set_state_hello_wait, NULL, GNUNET_NO); | 2848 | queue_message (socket, message, &set_state_hello_wait, NULL, GNUNET_NO); |
2869 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == | 2849 | if (GNUNET_SCHEDULER_NO_TASK != socket->control_retransmission_task_id) |
2870 | socket->control_retransmission_task_id); | 2850 | GNUNET_SCHEDULER_cancel (socket->control_retransmission_task_id); |
2871 | socket->control_retransmission_task_id = | 2851 | socket->control_retransmission_task_id = |
2872 | GNUNET_SCHEDULER_add_delayed (socket->retransmit_timeout, | 2852 | GNUNET_SCHEDULER_add_delayed (socket->retransmit_timeout, |
2873 | &control_retransmission_task, socket); | 2853 | &control_retransmission_task, socket); |
@@ -2887,10 +2867,8 @@ mesh_peer_disconnect_callback (void *cls, | |||
2887 | struct GNUNET_STREAM_Socket *socket=cls; | 2867 | struct GNUNET_STREAM_Socket *socket=cls; |
2888 | 2868 | ||
2889 | /* If the state is SHUTDOWN its ok; else set the state of the socket to SYSERR */ | 2869 | /* If the state is SHUTDOWN its ok; else set the state of the socket to SYSERR */ |
2890 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2870 | LOG_DEBUG ("%1$s: Other peer %1$s disconnected \n", |
2891 | "%s: Other peer %s disconnected \n", | 2871 | GNUNET_i2s (&socket->other_peer)); |
2892 | GNUNET_i2s (&socket->other_peer), | ||
2893 | GNUNET_i2s (&socket->other_peer)); | ||
2894 | } | 2872 | } |
2895 | 2873 | ||
2896 | 2874 | ||
@@ -2915,7 +2893,6 @@ new_tunnel_notify (void *cls, | |||
2915 | 2893 | ||
2916 | /* FIXME: If a tunnel is already created, we should not accept new tunnels | 2894 | /* FIXME: If a tunnel is already created, we should not accept new tunnels |
2917 | from the same peer again until the socket is closed */ | 2895 | from the same peer again until the socket is closed */ |
2918 | |||
2919 | if (GNUNET_NO == lsocket->listening) | 2896 | if (GNUNET_NO == lsocket->listening) |
2920 | { | 2897 | { |
2921 | GNUNET_MESH_tunnel_destroy (tunnel); | 2898 | GNUNET_MESH_tunnel_destroy (tunnel); |
@@ -2926,16 +2903,15 @@ new_tunnel_notify (void *cls, | |||
2926 | socket->tunnel = tunnel; | 2903 | socket->tunnel = tunnel; |
2927 | socket->state = STATE_INIT; | 2904 | socket->state = STATE_INIT; |
2928 | socket->lsocket = lsocket; | 2905 | socket->lsocket = lsocket; |
2906 | socket->port = lsocket->port; | ||
2929 | socket->stat_handle = lsocket->stat_handle; | 2907 | socket->stat_handle = lsocket->stat_handle; |
2930 | socket->retransmit_timeout = lsocket->retransmit_timeout; | 2908 | socket->retransmit_timeout = lsocket->retransmit_timeout; |
2931 | socket->testing_active = lsocket->testing_active; | 2909 | socket->testing_active = lsocket->testing_active; |
2932 | socket->testing_set_write_sequence_number_value = | 2910 | socket->testing_set_write_sequence_number_value = |
2933 | lsocket->testing_set_write_sequence_number_value; | 2911 | lsocket->testing_set_write_sequence_number_value; |
2934 | socket->max_payload_size = lsocket->max_payload_size; | 2912 | socket->max_payload_size = lsocket->max_payload_size; |
2935 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2913 | LOG_DEBUG ("%1$s: Peer %1$s initiated tunnel to us\n", |
2936 | "%s: Peer %s initiated tunnel to us\n", | 2914 | GNUNET_i2s (&socket->other_peer)); |
2937 | GNUNET_i2s (&socket->other_peer), | ||
2938 | GNUNET_i2s (&socket->other_peer)); | ||
2939 | if (NULL != socket->stat_handle) | 2915 | if (NULL != socket->stat_handle) |
2940 | { | 2916 | { |
2941 | GNUNET_STATISTICS_update (socket->stat_handle, | 2917 | GNUNET_STATISTICS_update (socket->stat_handle, |
@@ -2944,7 +2920,6 @@ new_tunnel_notify (void *cls, | |||
2944 | GNUNET_STATISTICS_update (socket->stat_handle, | 2920 | GNUNET_STATISTICS_update (socket->stat_handle, |
2945 | "inbound connections", 1, GNUNET_NO); | 2921 | "inbound connections", 1, GNUNET_NO); |
2946 | } | 2922 | } |
2947 | |||
2948 | return socket; | 2923 | return socket; |
2949 | } | 2924 | } |
2950 | 2925 | ||
@@ -3113,7 +3088,6 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3113 | { | 3088 | { |
3114 | struct GNUNET_STREAM_Socket *socket; | 3089 | struct GNUNET_STREAM_Socket *socket; |
3115 | enum GNUNET_STREAM_Option option; | 3090 | enum GNUNET_STREAM_Option option; |
3116 | GNUNET_MESH_ApplicationType ports[] = {app_port, 0}; | ||
3117 | va_list vargs; | 3091 | va_list vargs; |
3118 | uint16_t payload_size; | 3092 | uint16_t payload_size; |
3119 | 3093 | ||
@@ -3124,6 +3098,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3124 | socket->other_peer = *target; | 3098 | socket->other_peer = *target; |
3125 | socket->open_cb = open_cb; | 3099 | socket->open_cb = open_cb; |
3126 | socket->open_cls = open_cb_cls; | 3100 | socket->open_cls = open_cb_cls; |
3101 | socket->port = app_port; | ||
3127 | /* Set defaults */ | 3102 | /* Set defaults */ |
3128 | socket->retransmit_timeout = TIME_REL_SECS (default_timeout); | 3103 | socket->retransmit_timeout = TIME_REL_SECS (default_timeout); |
3129 | socket->testing_active = GNUNET_NO; | 3104 | socket->testing_active = GNUNET_NO; |
@@ -3165,7 +3140,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
3165 | NULL, /* No inbound tunnel handler */ | 3140 | NULL, /* No inbound tunnel handler */ |
3166 | NULL, /* No in-tunnel cleaner */ | 3141 | NULL, /* No in-tunnel cleaner */ |
3167 | client_message_handlers, | 3142 | client_message_handlers, |
3168 | ports); /* We don't get inbound tunnels */ | 3143 | NULL); /* We don't get inbound tunnels */ |
3169 | if (NULL == socket->mesh) /* Fail if we cannot connect to mesh */ | 3144 | if (NULL == socket->mesh) /* Fail if we cannot connect to mesh */ |
3170 | { | 3145 | { |
3171 | GNUNET_free (socket); | 3146 | GNUNET_free (socket); |
@@ -3204,7 +3179,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3204 | void *completion_cls) | 3179 | void *completion_cls) |
3205 | { | 3180 | { |
3206 | struct GNUNET_STREAM_ShutdownHandle *handle; | 3181 | struct GNUNET_STREAM_ShutdownHandle *handle; |
3207 | struct GNUNET_STREAM_MessageHeader *msg; | 3182 | struct GNUNET_MessageHeader *msg; |
3208 | 3183 | ||
3209 | GNUNET_assert (NULL == socket->shutdown_handle); | 3184 | GNUNET_assert (NULL == socket->shutdown_handle); |
3210 | handle = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ShutdownHandle)); | 3185 | handle = GNUNET_malloc (sizeof (struct GNUNET_STREAM_ShutdownHandle)); |
@@ -3223,8 +3198,8 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3223 | socket); | 3198 | socket); |
3224 | return handle; | 3199 | return handle; |
3225 | } | 3200 | } |
3226 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 3201 | msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader)); |
3227 | msg->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 3202 | msg->size = htons (sizeof (struct GNUNET_MessageHeader)); |
3228 | switch (operation) | 3203 | switch (operation) |
3229 | { | 3204 | { |
3230 | case SHUT_RD: | 3205 | case SHUT_RD: |
@@ -3233,7 +3208,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3233 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3208 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3234 | "Existing read handle should be cancelled before shutting" | 3209 | "Existing read handle should be cancelled before shutting" |
3235 | " down reading\n"); | 3210 | " down reading\n"); |
3236 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); | 3211 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_RECEIVE_CLOSE); |
3237 | queue_message (socket, msg, &set_state_receive_close_wait, NULL, | 3212 | queue_message (socket, msg, &set_state_receive_close_wait, NULL, |
3238 | GNUNET_NO); | 3213 | GNUNET_NO); |
3239 | socket->receive_closed = GNUNET_YES; | 3214 | socket->receive_closed = GNUNET_YES; |
@@ -3244,7 +3219,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3244 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3219 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3245 | "Existing write handle should be cancelled before shutting" | 3220 | "Existing write handle should be cancelled before shutting" |
3246 | " down writing\n"); | 3221 | " down writing\n"); |
3247 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); | 3222 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_TRANSMIT_CLOSE); |
3248 | queue_message (socket, msg, &set_state_transmit_close_wait, NULL, | 3223 | queue_message (socket, msg, &set_state_transmit_close_wait, NULL, |
3249 | GNUNET_NO); | 3224 | GNUNET_NO); |
3250 | socket->transmit_closed = GNUNET_YES; | 3225 | socket->transmit_closed = GNUNET_YES; |
@@ -3259,7 +3234,7 @@ GNUNET_STREAM_shutdown (struct GNUNET_STREAM_Socket *socket, | |||
3259 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3234 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3260 | "Existing read handle should be cancelled before shutting" | 3235 | "Existing read handle should be cancelled before shutting" |
3261 | " down reading\n"); | 3236 | " down reading\n"); |
3262 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); | 3237 | msg->type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE); |
3263 | queue_message (socket, msg, &set_state_close_wait, NULL, GNUNET_NO); | 3238 | queue_message (socket, msg, &set_state_close_wait, NULL, GNUNET_NO); |
3264 | socket->transmit_closed = GNUNET_YES; | 3239 | socket->transmit_closed = GNUNET_YES; |
3265 | socket->receive_closed = GNUNET_YES; | 3240 | socket->receive_closed = GNUNET_YES; |
@@ -3514,11 +3489,11 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, | |||
3514 | void *write_cont_cls) | 3489 | void *write_cont_cls) |
3515 | { | 3490 | { |
3516 | struct GNUNET_STREAM_WriteHandle *io_handle; | 3491 | struct GNUNET_STREAM_WriteHandle *io_handle; |
3517 | struct GNUNET_STREAM_DataMessage *data_msg; | 3492 | struct GNUNET_STREAM_DataMessage *dmsg; |
3518 | const void *sweep; | 3493 | const void *sweep; |
3519 | struct GNUNET_TIME_Relative ack_deadline; | 3494 | struct GNUNET_TIME_Relative ack_deadline; |
3520 | unsigned int num_needed_packets; | 3495 | unsigned int num_needed_packets; |
3521 | unsigned int packet; | 3496 | unsigned int cnt; |
3522 | uint32_t packet_size; | 3497 | uint32_t packet_size; |
3523 | uint32_t payload_size; | 3498 | uint32_t payload_size; |
3524 | uint16_t max_data_packet_size; | 3499 | uint16_t max_data_packet_size; |
@@ -3578,33 +3553,29 @@ GNUNET_STREAM_write (struct GNUNET_STREAM_Socket *socket, | |||
3578 | max_data_packet_size = | 3553 | max_data_packet_size = |
3579 | socket->max_payload_size + sizeof (struct GNUNET_STREAM_DataMessage); | 3554 | socket->max_payload_size + sizeof (struct GNUNET_STREAM_DataMessage); |
3580 | io_handle->max_ack_base_num = socket->write_sequence_number; | 3555 | io_handle->max_ack_base_num = socket->write_sequence_number; |
3581 | for (packet=0; packet < num_needed_packets; packet++) | 3556 | for (cnt=0; cnt < num_needed_packets; cnt++) |
3582 | { | 3557 | { |
3583 | if ((packet + 1) * socket->max_payload_size < size) | 3558 | if ((cnt + 1) * socket->max_payload_size < size) |
3584 | { | 3559 | { |
3585 | payload_size = socket->max_payload_size; | 3560 | payload_size = socket->max_payload_size; |
3586 | packet_size = max_data_packet_size; | 3561 | packet_size = max_data_packet_size; |
3587 | } | 3562 | } |
3588 | else | 3563 | else |
3589 | { | 3564 | { |
3590 | payload_size = size - packet * socket->max_payload_size; | 3565 | payload_size = size - (cnt * socket->max_payload_size); |
3591 | packet_size = | 3566 | packet_size = payload_size + sizeof (struct GNUNET_STREAM_DataMessage); |
3592 | payload_size + sizeof (struct GNUNET_STREAM_DataMessage); | ||
3593 | } | 3567 | } |
3594 | io_handle->messages[packet] = GNUNET_malloc (packet_size); | 3568 | dmsg = GNUNET_malloc (packet_size); |
3595 | io_handle->messages[packet]->header.header.size = htons (packet_size); | 3569 | dmsg->header.size = htons (packet_size); |
3596 | io_handle->messages[packet]->header.header.type = | 3570 | dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_DATA); |
3597 | htons (GNUNET_MESSAGE_TYPE_STREAM_DATA); | 3571 | dmsg->sequence_number = htonl (socket->write_sequence_number++); |
3598 | io_handle->messages[packet]->sequence_number = | 3572 | dmsg->offset = htonl (socket->write_offset); |
3599 | htonl (socket->write_sequence_number++); | ||
3600 | io_handle->messages[packet]->offset = htonl (socket->write_offset); | ||
3601 | /* FIXME: Remove the fixed delay for ack deadline; Set it to the value | 3573 | /* FIXME: Remove the fixed delay for ack deadline; Set it to the value |
3602 | determined from RTT */ | 3574 | determined from RTT */ |
3603 | io_handle->messages[packet]->ack_deadline = | 3575 | dmsg->ack_deadline = GNUNET_TIME_relative_hton (ack_deadline); |
3604 | GNUNET_TIME_relative_hton (ack_deadline); | ||
3605 | data_msg = io_handle->messages[packet]; | ||
3606 | /* Copy data from given buffer to the packet */ | 3576 | /* Copy data from given buffer to the packet */ |
3607 | memcpy (&data_msg[1], sweep, payload_size); | 3577 | memcpy (&dmsg[1], sweep, payload_size); |
3578 | io_handle->messages[cnt] = dmsg; | ||
3608 | sweep += payload_size; | 3579 | sweep += payload_size; |
3609 | socket->write_offset += payload_size; | 3580 | socket->write_offset += payload_size; |
3610 | } | 3581 | } |
@@ -3645,7 +3616,6 @@ probe_data_availability (void *cls, | |||
3645 | } | 3616 | } |
3646 | 3617 | ||
3647 | 3618 | ||
3648 | |||
3649 | /** | 3619 | /** |
3650 | * Tries to read data from the stream. Should not be called when another read | 3620 | * Tries to read data from the stream. Should not be called when another read |
3651 | * handle is present; the existing read handle should be canceled with | 3621 | * handle is present; the existing read handle should be canceled with |