diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-12 08:40:32 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-05-12 08:40:32 +0000 |
commit | b645cd86afca79fa4c992935e3cc1ddf5e88f166 (patch) | |
tree | 7299de5d5fcdf5c3466ddde3ce03587b80dd82e6 /src | |
parent | f39f235ce3102fc959162e5d6a58ef3f03ed4101 (diff) | |
download | gnunet-b645cd86afca79fa4c992935e3cc1ddf5e88f166.tar.gz gnunet-b645cd86afca79fa4c992935e3cc1ddf5e88f166.zip |
peer ids in logging and indentation
Diffstat (limited to 'src')
-rw-r--r-- | src/stream/stream_api.c | 304 |
1 files changed, 169 insertions, 135 deletions
diff --git a/src/stream/stream_api.c b/src/stream/stream_api.c index e8ba24966..e1fb85190 100644 --- a/src/stream/stream_api.c +++ b/src/stream/stream_api.c | |||
@@ -23,9 +23,6 @@ | |||
23 | * Checks for matching the sender and socket->other_peer in server | 23 | * Checks for matching the sender and socket->other_peer in server |
24 | * message handlers | 24 | * message handlers |
25 | * | 25 | * |
26 | * Decrement PEER intern count during socket close and listen close to free the | ||
27 | * memory used for PEER interning | ||
28 | * | ||
29 | * Add code for write io timeout | 26 | * Add code for write io timeout |
30 | * | 27 | * |
31 | * Include retransmission for control messages | 28 | * Include retransmission for control messages |
@@ -42,7 +39,6 @@ | |||
42 | #include "gnunet_common.h" | 39 | #include "gnunet_common.h" |
43 | #include "gnunet_crypto_lib.h" | 40 | #include "gnunet_crypto_lib.h" |
44 | #include "gnunet_stream_lib.h" | 41 | #include "gnunet_stream_lib.h" |
45 | #include "gnunet_testing_lib.h" | ||
46 | #include "stream_protocol.h" | 42 | #include "stream_protocol.h" |
47 | 43 | ||
48 | #define LOG(kind,...) \ | 44 | #define LOG(kind,...) \ |
@@ -260,6 +256,11 @@ struct GNUNET_STREAM_Socket | |||
260 | struct GNUNET_STREAM_ListenSocket *lsocket; | 256 | struct GNUNET_STREAM_ListenSocket *lsocket; |
261 | 257 | ||
262 | /** | 258 | /** |
259 | * The peer identity of the peer at the other end of the stream | ||
260 | */ | ||
261 | struct GNUNET_PeerIdentity other_peer; | ||
262 | |||
263 | /** | ||
263 | * Task identifier for the read io timeout task | 264 | * Task identifier for the read io timeout task |
264 | */ | 265 | */ |
265 | GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task_id; | 266 | GNUNET_SCHEDULER_TaskIdentifier read_io_timeout_task_id; |
@@ -295,11 +296,6 @@ struct GNUNET_STREAM_Socket | |||
295 | unsigned int retries; | 296 | unsigned int retries; |
296 | 297 | ||
297 | /** | 298 | /** |
298 | * The peer identity of the peer at the other end of the stream | ||
299 | */ | ||
300 | GNUNET_PEER_Id other_peer; | ||
301 | |||
302 | /** | ||
303 | * The application port number (type: uint32_t) | 299 | * The application port number (type: uint32_t) |
304 | */ | 300 | */ |
305 | GNUNET_MESH_ApplicationType app_port; | 301 | GNUNET_MESH_ApplicationType app_port; |
@@ -486,7 +482,6 @@ static size_t | |||
486 | send_message_notify (void *cls, size_t size, void *buf) | 482 | send_message_notify (void *cls, size_t size, void *buf) |
487 | { | 483 | { |
488 | struct GNUNET_STREAM_Socket *socket = cls; | 484 | struct GNUNET_STREAM_Socket *socket = cls; |
489 | struct GNUNET_PeerIdentity target; | ||
490 | struct MessageQueue *head; | 485 | struct MessageQueue *head; |
491 | size_t ret; | 486 | size_t ret; |
492 | 487 | ||
@@ -494,12 +489,12 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
494 | head = socket->queue_head; | 489 | head = socket->queue_head; |
495 | if (NULL == head) | 490 | if (NULL == head) |
496 | return 0; /* just to be safe */ | 491 | return 0; /* just to be safe */ |
497 | GNUNET_PEER_resolve (socket->other_peer, &target); | ||
498 | if (0 == size) /* request timed out */ | 492 | if (0 == size) /* request timed out */ |
499 | { | 493 | { |
500 | socket->retries++; | 494 | socket->retries++; |
501 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 495 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
502 | "Message sending timed out. Retry %d \n", | 496 | "%s: Message sending timed out. Retry %d \n", |
497 | GNUNET_i2s (&socket->other_peer), | ||
503 | socket->retries); | 498 | socket->retries); |
504 | socket->transmit_handle = | 499 | socket->transmit_handle = |
505 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, | 500 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, |
@@ -507,7 +502,7 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
507 | 1, /* Priority */ | 502 | 1, /* Priority */ |
508 | /* FIXME: exponential backoff */ | 503 | /* FIXME: exponential backoff */ |
509 | socket->retransmit_timeout, | 504 | socket->retransmit_timeout, |
510 | &target, | 505 | &socket->other_peer, |
511 | ntohs (head->message->header.size), | 506 | ntohs (head->message->header.size), |
512 | &send_message_notify, | 507 | &send_message_notify, |
513 | socket); | 508 | socket); |
@@ -536,7 +531,7 @@ send_message_notify (void *cls, size_t size, void *buf) | |||
536 | 1, /* Priority */ | 531 | 1, /* Priority */ |
537 | /* FIXME: exponential backoff */ | 532 | /* FIXME: exponential backoff */ |
538 | socket->retransmit_timeout, | 533 | socket->retransmit_timeout, |
539 | &target, | 534 | &socket->other_peer, |
540 | ntohs (head->message->header.size), | 535 | ntohs (head->message->header.size), |
541 | &send_message_notify, | 536 | &send_message_notify, |
542 | socket); | 537 | socket); |
@@ -560,14 +555,14 @@ queue_message (struct GNUNET_STREAM_Socket *socket, | |||
560 | void *finish_cb_cls) | 555 | void *finish_cb_cls) |
561 | { | 556 | { |
562 | struct MessageQueue *queue_entity; | 557 | struct MessageQueue *queue_entity; |
563 | struct GNUNET_PeerIdentity target; | ||
564 | 558 | ||
565 | GNUNET_assert | 559 | GNUNET_assert |
566 | ((ntohs (message->header.type) >= GNUNET_MESSAGE_TYPE_STREAM_DATA) | 560 | ((ntohs (message->header.type) >= GNUNET_MESSAGE_TYPE_STREAM_DATA) |
567 | && (ntohs (message->header.type) <= GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK)); | 561 | && (ntohs (message->header.type) <= GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK)); |
568 | 562 | ||
569 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 563 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
570 | "Queueing message of type %d and size %d\n", | 564 | "%s: Queueing message of type %d and size %d\n", |
565 | GNUNET_i2s (&socket->other_peer), | ||
571 | ntohs (message->header.type), | 566 | ntohs (message->header.type), |
572 | ntohs (message->header.size)); | 567 | ntohs (message->header.size)); |
573 | GNUNET_assert (NULL != message); | 568 | GNUNET_assert (NULL != message); |
@@ -581,13 +576,12 @@ queue_message (struct GNUNET_STREAM_Socket *socket, | |||
581 | if (NULL == socket->transmit_handle) | 576 | if (NULL == socket->transmit_handle) |
582 | { | 577 | { |
583 | socket->retries = 0; | 578 | socket->retries = 0; |
584 | GNUNET_PEER_resolve (socket->other_peer, &target); | ||
585 | socket->transmit_handle = | 579 | socket->transmit_handle = |
586 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, | 580 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, |
587 | 0, /* Corking */ | 581 | 0, /* Corking */ |
588 | 1, /* Priority */ | 582 | 1, /* Priority */ |
589 | socket->retransmit_timeout, | 583 | socket->retransmit_timeout, |
590 | &target, | 584 | &socket->other_peer, |
591 | ntohs (message->header.size), | 585 | ntohs (message->header.size), |
592 | &send_message_notify, | 586 | &send_message_notify, |
593 | socket); | 587 | socket); |
@@ -676,7 +670,7 @@ retransmission_timeout_task (void *cls, | |||
676 | return; | 670 | return; |
677 | 671 | ||
678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 672 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
679 | "Retransmitting DATA...\n"); | 673 | "%s: Retransmitting DATA...\n", GNUNET_i2s (&socket->other_peer)); |
680 | socket->retransmission_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | 674 | socket->retransmission_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; |
681 | write_data (socket); | 675 | write_data (socket); |
682 | } | 676 | } |
@@ -694,15 +688,12 @@ ack_task (void *cls, | |||
694 | { | 688 | { |
695 | struct GNUNET_STREAM_Socket *socket = cls; | 689 | struct GNUNET_STREAM_Socket *socket = cls; |
696 | struct GNUNET_STREAM_AckMessage *ack_msg; | 690 | struct GNUNET_STREAM_AckMessage *ack_msg; |
697 | struct GNUNET_PeerIdentity target; | ||
698 | 691 | ||
699 | if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) | 692 | if (GNUNET_SCHEDULER_REASON_SHUTDOWN == tc->reason) |
700 | { | 693 | { |
701 | return; | 694 | return; |
702 | } | 695 | } |
703 | |||
704 | socket->ack_task_id = GNUNET_SCHEDULER_NO_TASK; | 696 | socket->ack_task_id = GNUNET_SCHEDULER_NO_TASK; |
705 | |||
706 | /* Create the ACK Message */ | 697 | /* Create the ACK Message */ |
707 | ack_msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_AckMessage)); | 698 | ack_msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_AckMessage)); |
708 | ack_msg->header.header.size = htons (sizeof (struct | 699 | ack_msg->header.header.size = htons (sizeof (struct |
@@ -712,16 +703,14 @@ ack_task (void *cls, | |||
712 | ack_msg->base_sequence_number = htonl (socket->read_sequence_number); | 703 | ack_msg->base_sequence_number = htonl (socket->read_sequence_number); |
713 | ack_msg->receive_window_remaining = | 704 | ack_msg->receive_window_remaining = |
714 | htonl (RECEIVE_BUFFER_SIZE - socket->receive_buffer_size); | 705 | htonl (RECEIVE_BUFFER_SIZE - socket->receive_buffer_size); |
715 | |||
716 | socket->ack_msg = ack_msg; | 706 | socket->ack_msg = ack_msg; |
717 | GNUNET_PEER_resolve (socket->other_peer, &target); | ||
718 | /* Request MESH for sending ACK */ | 707 | /* Request MESH for sending ACK */ |
719 | socket->ack_transmit_handle = | 708 | socket->ack_transmit_handle = |
720 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, | 709 | GNUNET_MESH_notify_transmit_ready (socket->tunnel, |
721 | 0, /* Corking */ | 710 | 0, /* Corking */ |
722 | 1, /* Priority */ | 711 | 1, /* Priority */ |
723 | socket->retransmit_timeout, | 712 | socket->retransmit_timeout, |
724 | &target, | 713 | &socket->other_peer, |
725 | ntohs (ack_msg->header.header.size), | 714 | ntohs (ack_msg->header.header.size), |
726 | &send_ack_notify, | 715 | &send_ack_notify, |
727 | socket); | 716 | socket); |
@@ -838,9 +827,9 @@ write_data (struct GNUNET_STREAM_Socket *socket) | |||
838 | packet)) | 827 | packet)) |
839 | { | 828 | { |
840 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 829 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
841 | "Placing DATA message with sequence %u in send queue\n", | 830 | "%s: Placing DATA message with sequence %u in send queue\n", |
831 | GNUNET_i2s (&socket->other_peer), | ||
842 | ntohl (io_handle->messages[packet]->sequence_number)); | 832 | ntohl (io_handle->messages[packet]->sequence_number)); |
843 | |||
844 | copy_and_queue_message (socket, | 833 | copy_and_queue_message (socket, |
845 | &io_handle->messages[packet]->header, | 834 | &io_handle->messages[packet]->header, |
846 | NULL, | 835 | NULL, |
@@ -856,7 +845,8 @@ write_data (struct GNUNET_STREAM_Socket *socket) | |||
856 | socket->receiver_window_available -= | 845 | socket->receiver_window_available -= |
857 | ntohs (io_handle->messages[packet]->header.header.size); | 846 | ntohs (io_handle->messages[packet]->header.header.size); |
858 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 847 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
859 | "Placing DATA message with sequence %u in send queue\n", | 848 | "%s: Placing DATA message with sequence %u in send queue\n", |
849 | GNUNET_i2s (&socket->other_peer), | ||
860 | ntohl (io_handle->messages[packet]->sequence_number)); | 850 | ntohl (io_handle->messages[packet]->sequence_number)); |
861 | copy_and_queue_message (socket, | 851 | copy_and_queue_message (socket, |
862 | &io_handle->messages[packet]->header, | 852 | &io_handle->messages[packet]->header, |
@@ -864,7 +854,6 @@ write_data (struct GNUNET_STREAM_Socket *socket) | |||
864 | NULL); | 854 | NULL); |
865 | packet++; | 855 | packet++; |
866 | } | 856 | } |
867 | |||
868 | if (GNUNET_SCHEDULER_NO_TASK == socket->retransmission_timeout_task_id) | 857 | if (GNUNET_SCHEDULER_NO_TASK == socket->retransmission_timeout_task_id) |
869 | socket->retransmission_timeout_task_id = | 858 | socket->retransmission_timeout_task_id = |
870 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 859 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
@@ -910,37 +899,32 @@ call_read_processor (void *cls, | |||
910 | } | 899 | } |
911 | /* We only call read processor if we have the first packet */ | 900 | /* We only call read processor if we have the first packet */ |
912 | GNUNET_assert (0 < packet); | 901 | GNUNET_assert (0 < packet); |
913 | |||
914 | valid_read_size = | 902 | valid_read_size = |
915 | socket->receive_buffer_boundaries[packet-1] - socket->copy_offset; | 903 | socket->receive_buffer_boundaries[packet-1] - socket->copy_offset; |
916 | |||
917 | GNUNET_assert (0 != valid_read_size); | 904 | GNUNET_assert (0 != valid_read_size); |
918 | |||
919 | /* Cancel the read_io_timeout_task */ | 905 | /* Cancel the read_io_timeout_task */ |
920 | GNUNET_SCHEDULER_cancel (socket->read_io_timeout_task_id); | 906 | GNUNET_SCHEDULER_cancel (socket->read_io_timeout_task_id); |
921 | socket->read_io_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; | 907 | socket->read_io_timeout_task_id = GNUNET_SCHEDULER_NO_TASK; |
922 | |||
923 | /* Call the data processor */ | 908 | /* Call the data processor */ |
924 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 909 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
925 | "Calling read processor\n"); | 910 | "%s: Calling read processor\n", |
911 | GNUNET_i2s (&socket->other_peer)); | ||
926 | read_size = | 912 | read_size = |
927 | socket->read_handle->proc (socket->read_handle->proc_cls, | 913 | socket->read_handle->proc (socket->read_handle->proc_cls, |
928 | socket->status, | 914 | socket->status, |
929 | socket->receive_buffer + socket->copy_offset, | 915 | socket->receive_buffer + socket->copy_offset, |
930 | valid_read_size); | 916 | valid_read_size); |
931 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 917 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
932 | "Read processor read %d bytes\n", | 918 | "%s: Read processor read %d bytes\n", |
933 | read_size); | 919 | GNUNET_i2s (&socket->other_peer), read_size); |
934 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 920 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
935 | "Read processor completed successfully\n"); | 921 | "%s: Read processor completed successfully\n", |
936 | 922 | GNUNET_i2s (&socket->other_peer)); | |
937 | /* Free the read handle */ | 923 | /* Free the read handle */ |
938 | GNUNET_free (socket->read_handle); | 924 | GNUNET_free (socket->read_handle); |
939 | socket->read_handle = NULL; | 925 | socket->read_handle = NULL; |
940 | |||
941 | GNUNET_assert (read_size <= valid_read_size); | 926 | GNUNET_assert (read_size <= valid_read_size); |
942 | socket->copy_offset += read_size; | 927 | socket->copy_offset += read_size; |
943 | |||
944 | /* Determine upto which packet we can remove from the buffer */ | 928 | /* Determine upto which packet we can remove from the buffer */ |
945 | for (packet = 0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) | 929 | for (packet = 0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) |
946 | { | 930 | { |
@@ -952,11 +936,10 @@ call_read_processor (void *cls, | |||
952 | 936 | ||
953 | /* If no packets can be removed we can't move the buffer */ | 937 | /* If no packets can be removed we can't move the buffer */ |
954 | if (0 == packet) return; | 938 | if (0 == packet) return; |
955 | |||
956 | sequence_increase = packet; | 939 | sequence_increase = packet; |
957 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 940 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
958 | "Sequence increase after read processor completion: %u\n", | 941 | "%s: Sequence increase after read processor completion: %u\n", |
959 | sequence_increase); | 942 | GNUNET_i2s (&socket->other_peer), sequence_increase); |
960 | 943 | ||
961 | /* Shift the data in the receive buffer */ | 944 | /* Shift the data in the receive buffer */ |
962 | memmove (socket->receive_buffer, | 945 | memmove (socket->receive_buffer, |
@@ -964,21 +947,16 @@ call_read_processor (void *cls, | |||
964 | + socket->receive_buffer_boundaries[sequence_increase-1], | 947 | + socket->receive_buffer_boundaries[sequence_increase-1], |
965 | socket->receive_buffer_size | 948 | socket->receive_buffer_size |
966 | - socket->receive_buffer_boundaries[sequence_increase-1]); | 949 | - socket->receive_buffer_boundaries[sequence_increase-1]); |
967 | |||
968 | /* Shift the bitmap */ | 950 | /* Shift the bitmap */ |
969 | socket->ack_bitmap = socket->ack_bitmap >> sequence_increase; | 951 | socket->ack_bitmap = socket->ack_bitmap >> sequence_increase; |
970 | |||
971 | /* Set read_sequence_number */ | 952 | /* Set read_sequence_number */ |
972 | socket->read_sequence_number += sequence_increase; | 953 | socket->read_sequence_number += sequence_increase; |
973 | |||
974 | /* Set read_offset */ | 954 | /* Set read_offset */ |
975 | offset_increase = socket->receive_buffer_boundaries[sequence_increase-1]; | 955 | offset_increase = socket->receive_buffer_boundaries[sequence_increase-1]; |
976 | socket->read_offset += offset_increase; | 956 | socket->read_offset += offset_increase; |
977 | |||
978 | /* Fix copy_offset */ | 957 | /* Fix copy_offset */ |
979 | GNUNET_assert (offset_increase <= socket->copy_offset); | 958 | GNUNET_assert (offset_increase <= socket->copy_offset); |
980 | socket->copy_offset -= offset_increase; | 959 | socket->copy_offset -= offset_increase; |
981 | |||
982 | /* Fix relative boundaries */ | 960 | /* Fix relative boundaries */ |
983 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) | 961 | for (packet=0; packet < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH; packet++) |
984 | { | 962 | { |
@@ -1012,7 +990,8 @@ read_io_timeout (void *cls, | |||
1012 | if (socket->read_task_id != GNUNET_SCHEDULER_NO_TASK) | 990 | if (socket->read_task_id != GNUNET_SCHEDULER_NO_TASK) |
1013 | { | 991 | { |
1014 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 992 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1015 | "Read task timedout - Cancelling it\n"); | 993 | "%s: Read task timedout - Cancelling it\n", |
994 | GNUNET_i2s (&socket->other_peer)); | ||
1016 | GNUNET_SCHEDULER_cancel (socket->read_task_id); | 995 | GNUNET_SCHEDULER_cancel (socket->read_task_id); |
1017 | socket->read_task_id = GNUNET_SCHEDULER_NO_TASK; | 996 | socket->read_task_id = GNUNET_SCHEDULER_NO_TASK; |
1018 | } | 997 | } |
@@ -1061,10 +1040,13 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1061 | return GNUNET_SYSERR; | 1040 | return GNUNET_SYSERR; |
1062 | } | 1041 | } |
1063 | 1042 | ||
1064 | if (GNUNET_PEER_search (sender) != socket->other_peer) | 1043 | if (0 != memcmp (sender, |
1044 | &socket->other_peer, | ||
1045 | sizeof (struct GNUNET_PeerIdentity))) | ||
1065 | { | 1046 | { |
1066 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1047 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1067 | "Received DATA from non-confirming peer\n"); | 1048 | "%s: Received DATA from non-confirming peer\n", |
1049 | GNUNET_i2s (&socket->other_peer)); | ||
1068 | return GNUNET_YES; | 1050 | return GNUNET_YES; |
1069 | } | 1051 | } |
1070 | 1052 | ||
@@ -1081,7 +1063,8 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1081 | if ( relative_sequence_number > GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) | 1063 | if ( relative_sequence_number > GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH) |
1082 | { | 1064 | { |
1083 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1065 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1084 | "Ignoring received message with sequence number %u\n", | 1066 | "%s: Ignoring received message with sequence number %u\n", |
1067 | GNUNET_i2s (&socket->other_peer), | ||
1085 | ntohl (msg->sequence_number)); | 1068 | ntohl (msg->sequence_number)); |
1086 | /* Start ACK sending task if one is not already present */ | 1069 | /* Start ACK sending task if one is not already present */ |
1087 | if (GNUNET_SCHEDULER_NO_TASK == socket->ack_task_id) | 1070 | if (GNUNET_SCHEDULER_NO_TASK == socket->ack_task_id) |
@@ -1100,8 +1083,8 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1100 | relative_sequence_number)) | 1083 | relative_sequence_number)) |
1101 | { | 1084 | { |
1102 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1085 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1103 | "Ignoring already received message with sequence " | 1086 | "%s: Ignoring already received message with sequence number %u\n", |
1104 | "number %u\n", | 1087 | GNUNET_i2s (&socket->other_peer), |
1105 | ntohl (msg->sequence_number)); | 1088 | ntohl (msg->sequence_number)); |
1106 | /* Start ACK sending task if one is not already present */ | 1089 | /* Start ACK sending task if one is not already present */ |
1107 | if (GNUNET_SCHEDULER_NO_TASK == socket->ack_task_id) | 1090 | if (GNUNET_SCHEDULER_NO_TASK == socket->ack_task_id) |
@@ -1116,11 +1099,12 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1116 | } | 1099 | } |
1117 | 1100 | ||
1118 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1101 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1119 | "Receiving DATA with sequence number: %u and size: %d from %x\n", | 1102 | "%s: Receiving DATA with sequence number: %u and size: %d from %s\n", |
1103 | GNUNET_i2s (&socket->other_peer), | ||
1120 | ntohl (msg->sequence_number), | 1104 | ntohl (msg->sequence_number), |
1121 | ntohs (msg->header.header.size), | 1105 | ntohs (msg->header.header.size), |
1122 | socket->other_peer); | 1106 | GNUNET_i2s (&socket->other_peer)); |
1123 | 1107 | ||
1124 | /* Check if we have to allocate the buffer */ | 1108 | /* Check if we have to allocate the buffer */ |
1125 | size -= sizeof (struct GNUNET_STREAM_DataMessage); | 1109 | size -= sizeof (struct GNUNET_STREAM_DataMessage); |
1126 | relative_offset = ntohl (msg->offset) - socket->read_offset; | 1110 | relative_offset = ntohl (msg->offset) - socket->read_offset; |
@@ -1136,7 +1120,8 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1136 | else | 1120 | else |
1137 | { | 1121 | { |
1138 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1122 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1139 | "Cannot accommodate packet %d as buffer is full\n", | 1123 | "%s: Cannot accommodate packet %d as buffer is full\n", |
1124 | GNUNET_i2s (&socket->other_peer), | ||
1140 | ntohl (msg->sequence_number)); | 1125 | ntohl (msg->sequence_number)); |
1141 | return GNUNET_YES; | 1126 | return GNUNET_YES; |
1142 | } | 1127 | } |
@@ -1174,8 +1159,9 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1174 | 0))) | 1159 | 0))) |
1175 | { | 1160 | { |
1176 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1161 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1177 | "Scheduling read processor\n"); | 1162 | "%s: Scheduling read processor\n", |
1178 | 1163 | GNUNET_i2s (&socket->other_peer)); | |
1164 | |||
1179 | socket->read_task_id = | 1165 | socket->read_task_id = |
1180 | GNUNET_SCHEDULER_add_now (&call_read_processor, | 1166 | GNUNET_SCHEDULER_add_now (&call_read_processor, |
1181 | socket); | 1167 | socket); |
@@ -1185,7 +1171,8 @@ handle_data (struct GNUNET_STREAM_Socket *socket, | |||
1185 | 1171 | ||
1186 | default: | 1172 | default: |
1187 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1173 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1188 | "Received data message when it cannot be handled\n"); | 1174 | "%s: Received data message when it cannot be handled\n", |
1175 | GNUNET_i2s (&socket->other_peer)); | ||
1189 | break; | 1176 | break; |
1190 | } | 1177 | } |
1191 | return GNUNET_YES; | 1178 | return GNUNET_YES; |
@@ -1232,23 +1219,22 @@ static void | |||
1232 | set_state_established (void *cls, | 1219 | set_state_established (void *cls, |
1233 | struct GNUNET_STREAM_Socket *socket) | 1220 | struct GNUNET_STREAM_Socket *socket) |
1234 | { | 1221 | { |
1235 | struct GNUNET_PeerIdentity initiator_pid; | ||
1236 | |||
1237 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1222 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1238 | "Attaining ESTABLISHED state\n"); | 1223 | "%s: Attaining ESTABLISHED state\n", |
1224 | GNUNET_i2s (&socket->other_peer)); | ||
1239 | socket->write_offset = 0; | 1225 | socket->write_offset = 0; |
1240 | socket->read_offset = 0; | 1226 | socket->read_offset = 0; |
1241 | socket->state = STATE_ESTABLISHED; | 1227 | socket->state = STATE_ESTABLISHED; |
1242 | /* FIXME: What if listen_cb is NULL */ | 1228 | /* FIXME: What if listen_cb is NULL */ |
1243 | if (NULL != socket->lsocket) | 1229 | if (NULL != socket->lsocket) |
1244 | { | 1230 | { |
1245 | GNUNET_PEER_resolve (socket->other_peer, &initiator_pid); | ||
1246 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1231 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1247 | "Calling listen callback\n"); | 1232 | "%s: Calling listen callback\n", |
1233 | GNUNET_i2s (&socket->other_peer)); | ||
1248 | if (GNUNET_SYSERR == | 1234 | if (GNUNET_SYSERR == |
1249 | socket->lsocket->listen_cb (socket->lsocket->listen_cb_cls, | 1235 | socket->lsocket->listen_cb (socket->lsocket->listen_cb_cls, |
1250 | socket, | 1236 | socket, |
1251 | &initiator_pid)) | 1237 | &socket->other_peer)) |
1252 | { | 1238 | { |
1253 | socket->state = STATE_CLOSED; | 1239 | socket->state = STATE_CLOSED; |
1254 | /* FIXME: We should close in a decent way */ | 1240 | /* FIXME: We should close in a decent way */ |
@@ -1273,7 +1259,8 @@ set_state_hello_wait (void *cls, | |||
1273 | { | 1259 | { |
1274 | GNUNET_assert (STATE_INIT == socket->state); | 1260 | GNUNET_assert (STATE_INIT == socket->state); |
1275 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1261 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1276 | "Attaining HELLO_WAIT state\n"); | 1262 | "%s: Attaining HELLO_WAIT state\n", |
1263 | GNUNET_i2s (&socket->other_peer)); | ||
1277 | socket->state = STATE_HELLO_WAIT; | 1264 | socket->state = STATE_HELLO_WAIT; |
1278 | } | 1265 | } |
1279 | 1266 | ||
@@ -1289,7 +1276,8 @@ set_state_close_wait (void *cls, | |||
1289 | struct GNUNET_STREAM_Socket *socket) | 1276 | struct GNUNET_STREAM_Socket *socket) |
1290 | { | 1277 | { |
1291 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1278 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1292 | "Attaing CLOSE_WAIT state\n"); | 1279 | "%s: Attaing CLOSE_WAIT state\n", |
1280 | GNUNET_i2s (&socket->other_peer)); | ||
1293 | socket->state = STATE_CLOSE_WAIT; | 1281 | socket->state = STATE_CLOSE_WAIT; |
1294 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ | 1282 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ |
1295 | socket->receive_buffer = NULL; | 1283 | socket->receive_buffer = NULL; |
@@ -1308,7 +1296,8 @@ set_state_receive_close_wait (void *cls, | |||
1308 | struct GNUNET_STREAM_Socket *socket) | 1296 | struct GNUNET_STREAM_Socket *socket) |
1309 | { | 1297 | { |
1310 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1298 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1311 | "Attaing RECEIVE_CLOSE_WAIT state\n"); | 1299 | "%s: Attaing RECEIVE_CLOSE_WAIT state\n", |
1300 | GNUNET_i2s (&socket->other_peer)); | ||
1312 | socket->state = STATE_RECEIVE_CLOSE_WAIT; | 1301 | socket->state = STATE_RECEIVE_CLOSE_WAIT; |
1313 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ | 1302 | GNUNET_free_non_null (socket->receive_buffer); /* Free the receive buffer */ |
1314 | socket->receive_buffer = NULL; | 1303 | socket->receive_buffer = NULL; |
@@ -1327,7 +1316,8 @@ set_state_transmit_close_wait (void *cls, | |||
1327 | struct GNUNET_STREAM_Socket *socket) | 1316 | struct GNUNET_STREAM_Socket *socket) |
1328 | { | 1317 | { |
1329 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1318 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1330 | "Attaining TRANSMIT_CLOSE_WAIT state\n"); | 1319 | "%s: Attaing TRANSMIT_CLOSE_WAIT state\n", |
1320 | GNUNET_i2s (&socket->other_peer)); | ||
1331 | socket->state = STATE_TRANSMIT_CLOSE_WAIT; | 1321 | socket->state = STATE_TRANSMIT_CLOSE_WAIT; |
1332 | } | 1322 | } |
1333 | 1323 | ||
@@ -1361,7 +1351,8 @@ generate_hello_ack_msg (struct GNUNET_STREAM_Socket *socket) | |||
1361 | socket->write_sequence_number = | 1351 | socket->write_sequence_number = |
1362 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 1352 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); |
1363 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1353 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1364 | "Generated write sequence number %u\n", | 1354 | "%s: Generated write sequence number %u\n", |
1355 | GNUNET_i2s (&socket->other_peer), | ||
1365 | (unsigned int) socket->write_sequence_number); | 1356 | (unsigned int) socket->write_sequence_number); |
1366 | 1357 | ||
1367 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); | 1358 | msg = GNUNET_malloc (sizeof (struct GNUNET_STREAM_HelloAckMessage)); |
@@ -1399,16 +1390,20 @@ client_handle_hello_ack (void *cls, | |||
1399 | const struct GNUNET_STREAM_HelloAckMessage *ack_msg; | 1390 | const struct GNUNET_STREAM_HelloAckMessage *ack_msg; |
1400 | struct GNUNET_STREAM_HelloAckMessage *reply; | 1391 | struct GNUNET_STREAM_HelloAckMessage *reply; |
1401 | 1392 | ||
1402 | if (GNUNET_PEER_search (sender) != socket->other_peer) | 1393 | if (0 != memcmp (sender, |
1394 | &socket->other_peer, | ||
1395 | sizeof (struct GNUNET_PeerIdentity))) | ||
1403 | { | 1396 | { |
1404 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1397 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1405 | "Received HELLO_ACK from non-confirming peer\n"); | 1398 | "%s: Received HELLO_ACK from non-confirming peer\n", |
1399 | GNUNET_i2s (&socket->other_peer)); | ||
1406 | return GNUNET_YES; | 1400 | return GNUNET_YES; |
1407 | } | 1401 | } |
1408 | ack_msg = (const struct GNUNET_STREAM_HelloAckMessage *) message; | 1402 | ack_msg = (const struct GNUNET_STREAM_HelloAckMessage *) message; |
1409 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1403 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1410 | "Received HELLO_ACK from %x\n", | 1404 | "%s: Received HELLO_ACK from %s\n", |
1411 | socket->other_peer); | 1405 | GNUNET_i2s (&socket->other_peer), |
1406 | GNUNET_i2s (&socket->other_peer)); | ||
1412 | 1407 | ||
1413 | GNUNET_assert (socket->tunnel == tunnel); | 1408 | GNUNET_assert (socket->tunnel == tunnel); |
1414 | switch (socket->state) | 1409 | switch (socket->state) |
@@ -1416,7 +1411,8 @@ client_handle_hello_ack (void *cls, | |||
1416 | case STATE_HELLO_WAIT: | 1411 | case STATE_HELLO_WAIT: |
1417 | socket->read_sequence_number = ntohl (ack_msg->sequence_number); | 1412 | socket->read_sequence_number = ntohl (ack_msg->sequence_number); |
1418 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1413 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1419 | "Read sequence number %u\n", | 1414 | "%s: Read sequence number %u\n", |
1415 | GNUNET_i2s (&socket->other_peer), | ||
1420 | (unsigned int) socket->read_sequence_number); | 1416 | (unsigned int) socket->read_sequence_number); |
1421 | socket->receiver_window_available = ntohl (ack_msg->receiver_window_size); | 1417 | socket->receiver_window_available = ntohl (ack_msg->receiver_window_size); |
1422 | reply = generate_hello_ack_msg (socket); | 1418 | reply = generate_hello_ack_msg (socket); |
@@ -1432,8 +1428,9 @@ client_handle_hello_ack (void *cls, | |||
1432 | case STATE_INIT: | 1428 | case STATE_INIT: |
1433 | default: | 1429 | default: |
1434 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1430 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1435 | "Server %x sent HELLO_ACK when in state %d\n", | 1431 | "%s: Server %s sent HELLO_ACK when in state %d\n", |
1436 | socket->other_peer, | 1432 | GNUNET_i2s (&socket->other_peer), |
1433 | GNUNET_i2s (&socket->other_peer), | ||
1437 | socket->state); | 1434 | socket->state); |
1438 | socket->state = STATE_CLOSED; // introduce STATE_ERROR? | 1435 | socket->state = STATE_CLOSED; // introduce STATE_ERROR? |
1439 | return GNUNET_SYSERR; | 1436 | return GNUNET_SYSERR; |
@@ -1565,7 +1562,8 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1565 | if (NULL == shutdown_handle) | 1562 | if (NULL == shutdown_handle) |
1566 | { | 1563 | { |
1567 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1564 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1568 | "Received *CLOSE_ACK when shutdown handle is NULL\n"); | 1565 | "%s: Received CLOSE_ACK when shutdown handle is NULL\n", |
1566 | GNUNET_i2s (&socket->other_peer)); | ||
1569 | return GNUNET_OK; | 1567 | return GNUNET_OK; |
1570 | } | 1568 | } |
1571 | 1569 | ||
@@ -1578,18 +1576,22 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1578 | if (SHUT_RDWR != shutdown_handle->operation) | 1576 | if (SHUT_RDWR != shutdown_handle->operation) |
1579 | { | 1577 | { |
1580 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1578 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1581 | "Received CLOSE_ACK when shutdown handle is not for SHUT_RDWR\n"); | 1579 | "%s: Received CLOSE_ACK when shutdown handle is not for " |
1580 | "SHUT_RDWR\n", | ||
1581 | GNUNET_i2s (&socket->other_peer)); | ||
1582 | return GNUNET_OK; | 1582 | return GNUNET_OK; |
1583 | } | 1583 | } |
1584 | 1584 | ||
1585 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1585 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1586 | "Received CLOSE_ACK from %x\n", | 1586 | "%s: Received CLOSE_ACK from %s\n", |
1587 | socket->other_peer); | 1587 | GNUNET_i2s (&socket->other_peer), |
1588 | GNUNET_i2s (&socket->other_peer)); | ||
1588 | socket->state = STATE_CLOSED; | 1589 | socket->state = STATE_CLOSED; |
1589 | break; | 1590 | break; |
1590 | default: | 1591 | default: |
1591 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1592 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1592 | "Received CLOSE_ACK when in it not expected\n"); | 1593 | "%s: Received CLOSE_ACK when in it not expected\n", |
1594 | GNUNET_i2s (&socket->other_peer)); | ||
1593 | return GNUNET_OK; | 1595 | return GNUNET_OK; |
1594 | } | 1596 | } |
1595 | break; | 1597 | break; |
@@ -1601,18 +1603,22 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1601 | if (SHUT_RD != shutdown_handle->operation) | 1603 | if (SHUT_RD != shutdown_handle->operation) |
1602 | { | 1604 | { |
1603 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1605 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1604 | "Received RECEIVE_CLOSE_ACK when shutdown handle is not for SHUT_RD\n"); | 1606 | "%s: Received RECEIVE_CLOSE_ACK when shutdown handle " |
1607 | "is not for SHUT_RD\n", | ||
1608 | GNUNET_i2s (&socket->other_peer)); | ||
1605 | return GNUNET_OK; | 1609 | return GNUNET_OK; |
1606 | } | 1610 | } |
1607 | 1611 | ||
1608 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1612 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1609 | "Received RECEIVE_CLOSE_ACK from %x\n", | 1613 | "%s: Received RECEIVE_CLOSE_ACK from %s\n", |
1610 | socket->other_peer); | 1614 | GNUNET_i2s (&socket->other_peer), |
1615 | GNUNET_i2s (&socket->other_peer)); | ||
1611 | socket->state = STATE_RECEIVE_CLOSED; | 1616 | socket->state = STATE_RECEIVE_CLOSED; |
1612 | break; | 1617 | break; |
1613 | default: | 1618 | default: |
1614 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1619 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1615 | "Received RECEIVE_CLOSE_ACK when in it not expected\n"); | 1620 | "%s: Received RECEIVE_CLOSE_ACK when in it not expected\n", |
1621 | GNUNET_i2s (&socket->other_peer)); | ||
1616 | return GNUNET_OK; | 1622 | return GNUNET_OK; |
1617 | } | 1623 | } |
1618 | 1624 | ||
@@ -1624,18 +1630,22 @@ handle_generic_close_ack (struct GNUNET_STREAM_Socket *socket, | |||
1624 | if (SHUT_WR != shutdown_handle->operation) | 1630 | if (SHUT_WR != shutdown_handle->operation) |
1625 | { | 1631 | { |
1626 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1632 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1627 | "Received TRANSMIT_CLOSE_ACK when shutdown handle is not for SHUT_WR\n"); | 1633 | "%s: Received TRANSMIT_CLOSE_ACK when shutdown handle " |
1634 | "is not for SHUT_WR\n", | ||
1635 | GNUNET_i2s (&socket->other_peer)); | ||
1628 | return GNUNET_OK; | 1636 | return GNUNET_OK; |
1629 | } | 1637 | } |
1630 | 1638 | ||
1631 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1639 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1632 | "Received TRANSMIT_CLOSE_ACK from %x\n", | 1640 | "%s: Received TRANSMIT_CLOSE_ACK from %s\n", |
1633 | socket->other_peer); | 1641 | GNUNET_i2s (&socket->other_peer), |
1642 | GNUNET_i2s (&socket->other_peer)); | ||
1634 | socket->state = STATE_TRANSMIT_CLOSED; | 1643 | socket->state = STATE_TRANSMIT_CLOSED; |
1635 | break; | 1644 | break; |
1636 | default: | 1645 | default: |
1637 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1646 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1638 | "Received TRANSMIT_CLOSE_ACK when in it not expected\n"); | 1647 | "%s: Received TRANSMIT_CLOSE_ACK when in it not expected\n", |
1648 | GNUNET_i2s (&socket->other_peer)); | ||
1639 | 1649 | ||
1640 | return GNUNET_OK; | 1650 | return GNUNET_OK; |
1641 | } | 1651 | } |
@@ -1719,15 +1729,17 @@ handle_receive_close (struct GNUNET_STREAM_Socket *socket, | |||
1719 | case STATE_LISTEN: | 1729 | case STATE_LISTEN: |
1720 | case STATE_HELLO_WAIT: | 1730 | case STATE_HELLO_WAIT: |
1721 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1731 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1722 | "Ignoring RECEIVE_CLOSE as it cannot be handled now\n"); | 1732 | "%s: Ignoring RECEIVE_CLOSE as it cannot be handled now\n", |
1733 | GNUNET_i2s (&socket->other_peer)); | ||
1723 | return GNUNET_OK; | 1734 | return GNUNET_OK; |
1724 | default: | 1735 | default: |
1725 | break; | 1736 | break; |
1726 | } | 1737 | } |
1727 | 1738 | ||
1728 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1739 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1729 | "Received RECEIVE_CLOSE from %x\n", | 1740 | "%s: Received RECEIVE_CLOSE from %s\n", |
1730 | socket->other_peer); | 1741 | GNUNET_i2s (&socket->other_peer), |
1742 | GNUNET_i2s (&socket->other_peer)); | ||
1731 | receive_close_ack = | 1743 | receive_close_ack = |
1732 | GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1744 | GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); |
1733 | receive_close_ack->header.size = | 1745 | receive_close_ack->header.size = |
@@ -1835,15 +1847,17 @@ handle_close (struct GNUNET_STREAM_Socket *socket, | |||
1835 | case STATE_LISTEN: | 1847 | case STATE_LISTEN: |
1836 | case STATE_HELLO_WAIT: | 1848 | case STATE_HELLO_WAIT: |
1837 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1849 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1838 | "Ignoring RECEIVE_CLOSE as it cannot be handled now\n"); | 1850 | "%s: Ignoring RECEIVE_CLOSE as it cannot be handled now\n", |
1851 | GNUNET_i2s (&socket->other_peer)); | ||
1839 | return GNUNET_OK; | 1852 | return GNUNET_OK; |
1840 | default: | 1853 | default: |
1841 | break; | 1854 | break; |
1842 | } | 1855 | } |
1843 | 1856 | ||
1844 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1857 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1845 | "Received CLOSE from %x\n", | 1858 | "%s: Received CLOSE from %s\n", |
1846 | socket->other_peer); | 1859 | GNUNET_i2s (&socket->other_peer), |
1860 | GNUNET_i2s (&socket->other_peer)); | ||
1847 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1861 | close_ack = GNUNET_malloc (sizeof (struct GNUNET_STREAM_MessageHeader)); |
1848 | close_ack->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); | 1862 | close_ack->header.size = htons (sizeof (struct GNUNET_STREAM_MessageHeader)); |
1849 | close_ack->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); | 1863 | close_ack->header.type = htons (GNUNET_MESSAGE_TYPE_STREAM_CLOSE_ACK); |
@@ -1979,10 +1993,13 @@ server_handle_hello (void *cls, | |||
1979 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; | 1993 | struct GNUNET_STREAM_Socket *socket = *tunnel_ctx; |
1980 | struct GNUNET_STREAM_HelloAckMessage *reply; | 1994 | struct GNUNET_STREAM_HelloAckMessage *reply; |
1981 | 1995 | ||
1982 | if (GNUNET_PEER_search (sender) != socket->other_peer) | 1996 | if (0 != memcmp (sender, |
1997 | &socket->other_peer, | ||
1998 | sizeof (struct GNUNET_PeerIdentity))) | ||
1983 | { | 1999 | { |
1984 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2000 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1985 | "Received HELLO from non-confirming peer\n"); | 2001 | "%s: Received HELLO from non-confirming peer\n", |
2002 | GNUNET_i2s (&socket->other_peer)); | ||
1986 | return GNUNET_YES; | 2003 | return GNUNET_YES; |
1987 | } | 2004 | } |
1988 | 2005 | ||
@@ -1990,8 +2007,9 @@ server_handle_hello (void *cls, | |||
1990 | ntohs (message->type)); | 2007 | ntohs (message->type)); |
1991 | GNUNET_assert (socket->tunnel == tunnel); | 2008 | GNUNET_assert (socket->tunnel == tunnel); |
1992 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2009 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1993 | "Received HELLO from %x\n", | 2010 | "%s: Received HELLO from %s\n", |
1994 | socket->other_peer); | 2011 | GNUNET_i2s (&socket->other_peer), |
2012 | GNUNET_i2s (&socket->other_peer)); | ||
1995 | 2013 | ||
1996 | if (STATE_INIT == socket->state) | 2014 | if (STATE_INIT == socket->state) |
1997 | { | 2015 | { |
@@ -2042,11 +2060,13 @@ server_handle_hello_ack (void *cls, | |||
2042 | if (STATE_HELLO_WAIT == socket->state) | 2060 | if (STATE_HELLO_WAIT == socket->state) |
2043 | { | 2061 | { |
2044 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2062 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2045 | "Received HELLO_ACK from %x\n", | 2063 | "%s: Received HELLO_ACK from %s\n", |
2046 | socket->other_peer); | 2064 | GNUNET_i2s (&socket->other_peer), |
2065 | GNUNET_i2s (&socket->other_peer)); | ||
2047 | socket->read_sequence_number = ntohl (ack_message->sequence_number); | 2066 | socket->read_sequence_number = ntohl (ack_message->sequence_number); |
2048 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2067 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2049 | "Read sequence number %u\n", | 2068 | "%s: Read sequence number %u\n", |
2069 | GNUNET_i2s (&socket->other_peer), | ||
2050 | (unsigned int) socket->read_sequence_number); | 2070 | (unsigned int) socket->read_sequence_number); |
2051 | socket->receiver_window_available = | 2071 | socket->receiver_window_available = |
2052 | ntohl (ack_message->receiver_window_size); | 2072 | ntohl (ack_message->receiver_window_size); |
@@ -2300,10 +2320,13 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2300 | int need_retransmission; | 2320 | int need_retransmission; |
2301 | 2321 | ||
2302 | 2322 | ||
2303 | if (GNUNET_PEER_search (sender) != socket->other_peer) | 2323 | if (0 != memcmp (sender, |
2324 | &socket->other_peer, | ||
2325 | sizeof (struct GNUNET_PeerIdentity))) | ||
2304 | { | 2326 | { |
2305 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2327 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2306 | "Received ACK from non-confirming peer\n"); | 2328 | "%s: Received ACK from non-confirming peer\n", |
2329 | GNUNET_i2s (&socket->other_peer)); | ||
2307 | return GNUNET_YES; | 2330 | return GNUNET_YES; |
2308 | } | 2331 | } |
2309 | 2332 | ||
@@ -2315,7 +2338,8 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2315 | if (NULL == socket->write_handle) | 2338 | if (NULL == socket->write_handle) |
2316 | { | 2339 | { |
2317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2340 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2318 | "Received DATA_ACK when write_handle is NULL\n"); | 2341 | "%s: Received DATA_ACK when write_handle is NULL\n", |
2342 | GNUNET_i2s (&socket->other_peer)); | ||
2319 | return GNUNET_OK; | 2343 | return GNUNET_OK; |
2320 | } | 2344 | } |
2321 | /* FIXME: increment in the base sequence number is breaking current flow | 2345 | /* FIXME: increment in the base sequence number is breaking current flow |
@@ -2324,9 +2348,11 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2324 | - ntohl (ack->base_sequence_number)) < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH)) | 2348 | - ntohl (ack->base_sequence_number)) < GNUNET_STREAM_ACK_BITMAP_BIT_LENGTH)) |
2325 | { | 2349 | { |
2326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2350 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2327 | "Received DATA_ACK with unexpected base sequence number\n"); | 2351 | "%s: Received DATA_ACK with unexpected base sequence number\n", |
2352 | GNUNET_i2s (&socket->other_peer)); | ||
2328 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2353 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2329 | "Current write sequence: %u; Ack's base sequence: %u\n", | 2354 | "%s: Current write sequence: %u; Ack's base sequence: %u\n", |
2355 | GNUNET_i2s (&socket->other_peer), | ||
2330 | socket->write_sequence_number, | 2356 | socket->write_sequence_number, |
2331 | ntohl (ack->base_sequence_number)); | 2357 | ntohl (ack->base_sequence_number)); |
2332 | return GNUNET_OK; | 2358 | return GNUNET_OK; |
@@ -2335,8 +2361,9 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2335 | acks */ | 2361 | acks */ |
2336 | 2362 | ||
2337 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2363 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2338 | "Received DATA_ACK from %x\n", | 2364 | "%s: Received DATA_ACK from %s\n", |
2339 | socket->other_peer); | 2365 | GNUNET_i2s (&socket->other_peer), |
2366 | GNUNET_i2s (&socket->other_peer)); | ||
2340 | 2367 | ||
2341 | /* Cancel the retransmission task */ | 2368 | /* Cancel the retransmission task */ |
2342 | if (GNUNET_SCHEDULER_NO_TASK != socket->retransmission_timeout_task_id) | 2369 | if (GNUNET_SCHEDULER_NO_TASK != socket->retransmission_timeout_task_id) |
@@ -2399,7 +2426,8 @@ handle_ack (struct GNUNET_STREAM_Socket *socket, | |||
2399 | socket->status, | 2426 | socket->status, |
2400 | socket->write_handle->size); | 2427 | socket->write_handle->size); |
2401 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2428 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2402 | "Write completion callback completed\n"); | 2429 | "%s: Write completion callback completed\n", |
2430 | GNUNET_i2s (&socket->other_peer)); | ||
2403 | /* We are done with the write handle - Freeing it */ | 2431 | /* We are done with the write handle - Freeing it */ |
2404 | GNUNET_free (socket->write_handle); | 2432 | GNUNET_free (socket->write_handle); |
2405 | socket->write_handle = NULL; | 2433 | socket->write_handle = NULL; |
@@ -2538,20 +2566,21 @@ mesh_peer_connect_callback (void *cls, | |||
2538 | { | 2566 | { |
2539 | struct GNUNET_STREAM_Socket *socket = cls; | 2567 | struct GNUNET_STREAM_Socket *socket = cls; |
2540 | struct GNUNET_STREAM_MessageHeader *message; | 2568 | struct GNUNET_STREAM_MessageHeader *message; |
2541 | GNUNET_PEER_Id connected_peer; | ||
2542 | |||
2543 | connected_peer = GNUNET_PEER_search (peer); | ||
2544 | 2569 | ||
2545 | if (connected_peer != socket->other_peer) | 2570 | if (0 != memcmp (peer, |
2571 | &socket->other_peer, | ||
2572 | sizeof (struct GNUNET_PeerIdentity))) | ||
2546 | { | 2573 | { |
2547 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2574 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2548 | "A peer which is not our target has connected to our tunnel\n"); | 2575 | "%s: A peer which is not our target has connected to our tunnel\n", |
2576 | GNUNET_i2s(peer)); | ||
2549 | return; | 2577 | return; |
2550 | } | 2578 | } |
2551 | 2579 | ||
2552 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2580 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2553 | "Target peer %x connected\n", | 2581 | "%s: Target peer %s connected\n", |
2554 | connected_peer); | 2582 | GNUNET_i2s (&socket->other_peer), |
2583 | GNUNET_i2s (&socket->other_peer)); | ||
2555 | 2584 | ||
2556 | /* Set state to INIT */ | 2585 | /* Set state to INIT */ |
2557 | socket->state = STATE_INIT; | 2586 | socket->state = STATE_INIT; |
@@ -2588,8 +2617,9 @@ mesh_peer_disconnect_callback (void *cls, | |||
2588 | 2617 | ||
2589 | /* If the state is SHUTDOWN its ok; else set the state of the socket to SYSERR */ | 2618 | /* If the state is SHUTDOWN its ok; else set the state of the socket to SYSERR */ |
2590 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2619 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2591 | "Other peer %x disconnected\n", | 2620 | "%s: Other peer %s disconnected \n", |
2592 | socket->other_peer); | 2621 | GNUNET_i2s (&socket->other_peer), |
2622 | GNUNET_i2s (&socket->other_peer)); | ||
2593 | } | 2623 | } |
2594 | 2624 | ||
2595 | 2625 | ||
@@ -2616,14 +2646,16 @@ new_tunnel_notify (void *cls, | |||
2616 | from the same peer again until the socket is closed */ | 2646 | from the same peer again until the socket is closed */ |
2617 | 2647 | ||
2618 | socket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_Socket)); | 2648 | socket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_Socket)); |
2619 | socket->other_peer = GNUNET_PEER_intern (initiator); | 2649 | socket->other_peer = *initiator; |
2620 | socket->tunnel = tunnel; | 2650 | socket->tunnel = tunnel; |
2621 | socket->session_id = 0; /* FIXME */ | 2651 | socket->session_id = 0; /* FIXME */ |
2622 | socket->state = STATE_INIT; | 2652 | socket->state = STATE_INIT; |
2623 | socket->lsocket = lsocket; | 2653 | socket->lsocket = lsocket; |
2654 | |||
2624 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2655 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2625 | "Peer %x initiated tunnel to us\n", | 2656 | "%s: Peer %s initiated tunnel to us\n", |
2626 | socket->other_peer); | 2657 | GNUNET_i2s (&socket->other_peer), |
2658 | GNUNET_i2s (&socket->other_peer)); | ||
2627 | 2659 | ||
2628 | /* FIXME: Copy MESH handle from lsocket to socket */ | 2660 | /* FIXME: Copy MESH handle from lsocket to socket */ |
2629 | 2661 | ||
@@ -2655,8 +2687,9 @@ tunnel_cleaner (void *cls, | |||
2655 | 2687 | ||
2656 | GNUNET_break_op(0); | 2688 | GNUNET_break_op(0); |
2657 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2689 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2658 | "Peer %x has terminated connection abruptly\n", | 2690 | "%s: Peer %s has terminated connection abruptly\n", |
2659 | socket->other_peer); | 2691 | GNUNET_i2s (&socket->other_peer), |
2692 | GNUNET_i2s (&socket->other_peer)); | ||
2660 | 2693 | ||
2661 | socket->status = GNUNET_STREAM_SHUTDOWN; | 2694 | socket->status = GNUNET_STREAM_SHUTDOWN; |
2662 | 2695 | ||
@@ -2722,15 +2755,13 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2722 | 2755 | ||
2723 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2756 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2724 | "%s\n", __func__); | 2757 | "%s\n", __func__); |
2725 | |||
2726 | socket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_Socket)); | 2758 | socket = GNUNET_malloc (sizeof (struct GNUNET_STREAM_Socket)); |
2727 | socket->other_peer = GNUNET_PEER_intern (target); | 2759 | socket->other_peer = *target; |
2728 | socket->open_cb = open_cb; | 2760 | socket->open_cb = open_cb; |
2729 | socket->open_cls = open_cb_cls; | 2761 | socket->open_cls = open_cb_cls; |
2730 | /* Set defaults */ | 2762 | /* Set defaults */ |
2731 | socket->retransmit_timeout = | 2763 | socket->retransmit_timeout = |
2732 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout); | 2764 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, default_timeout); |
2733 | |||
2734 | va_start (vargs, open_cb_cls); /* Parse variable args */ | 2765 | va_start (vargs, open_cb_cls); /* Parse variable args */ |
2735 | do { | 2766 | do { |
2736 | option = va_arg (vargs, enum GNUNET_STREAM_Option); | 2767 | option = va_arg (vargs, enum GNUNET_STREAM_Option); |
@@ -2769,7 +2800,7 @@ GNUNET_STREAM_open (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2769 | socket); | 2800 | socket); |
2770 | GNUNET_assert (NULL != socket->tunnel); | 2801 | GNUNET_assert (NULL != socket->tunnel); |
2771 | GNUNET_MESH_peer_request_connect_add (socket->tunnel, | 2802 | GNUNET_MESH_peer_request_connect_add (socket->tunnel, |
2772 | target); | 2803 | &socket->other_peer); |
2773 | 2804 | ||
2774 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2805 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2775 | "%s() END\n", __func__); | 2806 | "%s() END\n", __func__); |
@@ -3155,7 +3186,8 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3155 | struct GNUNET_STREAM_IOReadHandle *read_handle; | 3186 | struct GNUNET_STREAM_IOReadHandle *read_handle; |
3156 | 3187 | ||
3157 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3188 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3158 | "%s()\n", | 3189 | "%s: %s()\n", |
3190 | GNUNET_i2s (&socket->other_peer), | ||
3159 | __func__); | 3191 | __func__); |
3160 | 3192 | ||
3161 | /* Return NULL if there is already a read handle; the user has to cancel that | 3193 | /* Return NULL if there is already a read handle; the user has to cancel that |
@@ -3172,7 +3204,8 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3172 | case STATE_CLOSE_WAIT: | 3204 | case STATE_CLOSE_WAIT: |
3173 | proc (proc_cls, GNUNET_STREAM_SHUTDOWN, NULL, 0); | 3205 | proc (proc_cls, GNUNET_STREAM_SHUTDOWN, NULL, 0); |
3174 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3206 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3175 | "%s() END\n", | 3207 | "%s: %s() END\n", |
3208 | GNUNET_i2s (&socket->other_peer), | ||
3176 | __func__); | 3209 | __func__); |
3177 | return NULL; | 3210 | return NULL; |
3178 | default: | 3211 | default: |
@@ -3199,7 +3232,8 @@ GNUNET_STREAM_read (struct GNUNET_STREAM_Socket *socket, | |||
3199 | &read_io_timeout, | 3232 | &read_io_timeout, |
3200 | socket); | 3233 | socket); |
3201 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3234 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3202 | "%s() END\n", | 3235 | "%s: %s() END\n", |
3236 | GNUNET_i2s (&socket->other_peer), | ||
3203 | __func__); | 3237 | __func__); |
3204 | return read_handle; | 3238 | return read_handle; |
3205 | } | 3239 | } |