diff options
Diffstat (limited to 'src/transport/gnunet-communicator-tcp.c')
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 460 |
1 files changed, 233 insertions, 227 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 95719852c..a8f88c5e4 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -43,6 +43,12 @@ | |||
43 | #include "gnunet_transport_communication_service.h" | 43 | #include "gnunet_transport_communication_service.h" |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How long do we believe our addresses to remain up (before | ||
47 | * the other peer should revalidate). | ||
48 | */ | ||
49 | #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
50 | |||
51 | /** | ||
46 | * How many messages do we keep at most in the queue to the | 52 | * How many messages do we keep at most in the queue to the |
47 | * transport service before we start to drop (default, | 53 | * transport service before we start to drop (default, |
48 | * can be changed via the configuration file). | 54 | * can be changed via the configuration file). |
@@ -582,8 +588,8 @@ queue_destroy (struct Queue *queue) | |||
582 | struct GNUNET_MQ_Handle *mq; | 588 | struct GNUNET_MQ_Handle *mq; |
583 | 589 | ||
584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Disconnecting queue for peer `%s'\n", | 591 | "Disconnecting queue for peer `%s'\n", |
586 | GNUNET_i2s (&queue->target)); | 592 | GNUNET_i2s (&queue->target)); |
587 | if (NULL != (mq = queue->mq)) | 593 | if (NULL != (mq = queue->mq)) |
588 | { | 594 | { |
589 | queue->mq = NULL; | 595 | queue->mq = NULL; |
@@ -599,9 +605,9 @@ queue_destroy (struct Queue *queue) | |||
599 | &queue->target, | 605 | &queue->target, |
600 | queue)); | 606 | queue)); |
601 | GNUNET_STATISTICS_set (stats, | 607 | GNUNET_STATISTICS_set (stats, |
602 | "# queues active", | 608 | "# queues active", |
603 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 609 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
604 | GNUNET_NO); | 610 | GNUNET_NO); |
605 | if (NULL != queue->read_task) | 611 | if (NULL != queue->read_task) |
606 | { | 612 | { |
607 | GNUNET_SCHEDULER_cancel (queue->read_task); | 613 | GNUNET_SCHEDULER_cancel (queue->read_task); |
@@ -622,9 +628,9 @@ queue_destroy (struct Queue *queue) | |||
622 | GNUNET_free (queue); | 628 | GNUNET_free (queue); |
623 | if (NULL == listen_task) | 629 | if (NULL == listen_task) |
624 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 630 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
625 | listen_sock, | 631 | listen_sock, |
626 | &listen_cb, | 632 | &listen_cb, |
627 | NULL); | 633 | NULL); |
628 | } | 634 | } |
629 | 635 | ||
630 | 636 | ||
@@ -645,18 +651,18 @@ calculate_hmac (struct GNUNET_HashCode *hmac_secret, | |||
645 | struct GNUNET_HashCode mac; | 651 | struct GNUNET_HashCode mac; |
646 | 652 | ||
647 | GNUNET_CRYPTO_hmac_raw (hmac_secret, | 653 | GNUNET_CRYPTO_hmac_raw (hmac_secret, |
648 | sizeof (struct GNUNET_HashCode), | 654 | sizeof (struct GNUNET_HashCode), |
649 | buf, | 655 | buf, |
650 | buf_size, | 656 | buf_size, |
651 | &mac); | 657 | &mac); |
652 | /* truncate to `struct GNUNET_ShortHashCode` */ | 658 | /* truncate to `struct GNUNET_ShortHashCode` */ |
653 | memcpy (smac, | 659 | memcpy (smac, |
654 | &mac, | 660 | &mac, |
655 | sizeof (struct GNUNET_ShortHashCode)); | 661 | sizeof (struct GNUNET_ShortHashCode)); |
656 | /* ratchet hmac key */ | 662 | /* ratchet hmac key */ |
657 | GNUNET_CRYPTO_hash (hmac_secret, | 663 | GNUNET_CRYPTO_hash (hmac_secret, |
658 | sizeof (struct GNUNET_HashCode), | 664 | sizeof (struct GNUNET_HashCode), |
659 | hmac_secret); | 665 | hmac_secret); |
660 | } | 666 | } |
661 | 667 | ||
662 | 668 | ||
@@ -728,15 +734,15 @@ queue_read (void *cls); | |||
728 | */ | 734 | */ |
729 | static void | 735 | static void |
730 | core_read_finished_cb (void *cls, | 736 | core_read_finished_cb (void *cls, |
731 | int success) | 737 | int success) |
732 | { | 738 | { |
733 | struct Queue *queue = cls; | 739 | struct Queue *queue = cls; |
734 | 740 | ||
735 | if (GNUNET_OK != success) | 741 | if (GNUNET_OK != success) |
736 | GNUNET_STATISTICS_update (stats, | 742 | GNUNET_STATISTICS_update (stats, |
737 | "# messages lost in communicator API towards CORE", | 743 | "# messages lost in communicator API towards CORE", |
738 | 1, | 744 | 1, |
739 | GNUNET_NO); | 745 | GNUNET_NO); |
740 | queue->backpressure--; | 746 | queue->backpressure--; |
741 | /* handle deferred queue destruction */ | 747 | /* handle deferred queue destruction */ |
742 | if ( (queue->destroyed) && | 748 | if ( (queue->destroyed) && |
@@ -750,9 +756,9 @@ core_read_finished_cb (void *cls, | |||
750 | if (NULL == queue->read_task) | 756 | if (NULL == queue->read_task) |
751 | queue->read_task | 757 | queue->read_task |
752 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (queue->timeout), | 758 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (queue->timeout), |
753 | queue->sock, | 759 | queue->sock, |
754 | &queue_read, | 760 | &queue_read, |
755 | queue); | 761 | queue); |
756 | } | 762 | } |
757 | 763 | ||
758 | 764 | ||
@@ -767,8 +773,8 @@ core_read_finished_cb (void *cls, | |||
767 | */ | 773 | */ |
768 | static void | 774 | static void |
769 | pass_plaintext_to_core (struct Queue *queue, | 775 | pass_plaintext_to_core (struct Queue *queue, |
770 | const void *plaintext, | 776 | const void *plaintext, |
771 | size_t plaintext_len) | 777 | size_t plaintext_len) |
772 | { | 778 | { |
773 | const struct GNUNET_MessageHeader *hdr = plaintext; | 779 | const struct GNUNET_MessageHeader *hdr = plaintext; |
774 | int ret; | 780 | int ret; |
@@ -781,18 +787,19 @@ pass_plaintext_to_core (struct Queue *queue, | |||
781 | return; | 787 | return; |
782 | } | 788 | } |
783 | ret = GNUNET_TRANSPORT_communicator_receive (ch, | 789 | ret = GNUNET_TRANSPORT_communicator_receive (ch, |
784 | &queue->target, | 790 | &queue->target, |
785 | hdr, | 791 | hdr, |
786 | &core_read_finished_cb, | 792 | ADDRESS_VALIDITY_PERIOD, |
787 | queue); | 793 | &core_read_finished_cb, |
794 | queue); | ||
788 | if (GNUNET_OK == ret) | 795 | if (GNUNET_OK == ret) |
789 | queue->backpressure++; | 796 | queue->backpressure++; |
790 | GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ | 797 | GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ |
791 | if (GNUNET_SYSERR == ret) | 798 | if (GNUNET_SYSERR == ret) |
792 | GNUNET_STATISTICS_update (stats, | 799 | GNUNET_STATISTICS_update (stats, |
793 | "# bytes lost due to CORE not running", | 800 | "# bytes lost due to CORE not running", |
794 | plaintext_len, | 801 | plaintext_len, |
795 | GNUNET_NO); | 802 | GNUNET_NO); |
796 | } | 803 | } |
797 | 804 | ||
798 | 805 | ||
@@ -815,45 +822,45 @@ setup_cipher (const struct GNUNET_HashCode *dh, | |||
815 | char ctr[128/8]; | 822 | char ctr[128/8]; |
816 | 823 | ||
817 | gcry_cipher_open (cipher, | 824 | gcry_cipher_open (cipher, |
818 | GCRY_CIPHER_AES256 /* low level: go for speed */, | 825 | GCRY_CIPHER_AES256 /* low level: go for speed */, |
819 | GCRY_CIPHER_MODE_CTR, | 826 | GCRY_CIPHER_MODE_CTR, |
820 | 0 /* flags */); | 827 | 0 /* flags */); |
821 | GNUNET_assert (GNUNET_YES == | 828 | GNUNET_assert (GNUNET_YES == |
822 | GNUNET_CRYPTO_kdf (key, | 829 | GNUNET_CRYPTO_kdf (key, |
823 | sizeof (key), | 830 | sizeof (key), |
824 | "TCP-key", | 831 | "TCP-key", |
825 | strlen ("TCP-key"), | 832 | strlen ("TCP-key"), |
826 | dh, | 833 | dh, |
827 | sizeof (*dh), | 834 | sizeof (*dh), |
828 | pid, | 835 | pid, |
829 | sizeof (*pid), | 836 | sizeof (*pid), |
830 | NULL, 0)); | 837 | NULL, 0)); |
831 | gcry_cipher_setkey (*cipher, | 838 | gcry_cipher_setkey (*cipher, |
832 | key, | 839 | key, |
833 | sizeof (key)); | 840 | sizeof (key)); |
834 | GNUNET_assert (GNUNET_YES == | 841 | GNUNET_assert (GNUNET_YES == |
835 | GNUNET_CRYPTO_kdf (ctr, | 842 | GNUNET_CRYPTO_kdf (ctr, |
836 | sizeof (ctr), | 843 | sizeof (ctr), |
837 | "TCP-ctr", | 844 | "TCP-ctr", |
838 | strlen ("TCP-ctr"), | 845 | strlen ("TCP-ctr"), |
839 | dh, | 846 | dh, |
840 | sizeof (*dh), | 847 | sizeof (*dh), |
841 | pid, | 848 | pid, |
842 | sizeof (*pid), | 849 | sizeof (*pid), |
843 | NULL, 0)); | 850 | NULL, 0)); |
844 | gcry_cipher_setctr (*cipher, | 851 | gcry_cipher_setctr (*cipher, |
845 | ctr, | 852 | ctr, |
846 | sizeof (ctr)); | 853 | sizeof (ctr)); |
847 | GNUNET_assert (GNUNET_YES == | 854 | GNUNET_assert (GNUNET_YES == |
848 | GNUNET_CRYPTO_kdf (hmac_key, | 855 | GNUNET_CRYPTO_kdf (hmac_key, |
849 | sizeof (struct GNUNET_HashCode), | 856 | sizeof (struct GNUNET_HashCode), |
850 | "TCP-hmac", | 857 | "TCP-hmac", |
851 | strlen ("TCP-hmac"), | 858 | strlen ("TCP-hmac"), |
852 | dh, | 859 | dh, |
853 | sizeof (*dh), | 860 | sizeof (*dh), |
854 | pid, | 861 | pid, |
855 | sizeof (*pid), | 862 | sizeof (*pid), |
856 | NULL, 0)); | 863 | NULL, 0)); |
857 | } | 864 | } |
858 | 865 | ||
859 | 866 | ||
@@ -870,12 +877,12 @@ setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | |||
870 | struct GNUNET_HashCode dh; | 877 | struct GNUNET_HashCode dh; |
871 | 878 | ||
872 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, | 879 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, |
873 | ephemeral, | 880 | ephemeral, |
874 | &dh); | 881 | &dh); |
875 | setup_cipher (&dh, | 882 | setup_cipher (&dh, |
876 | &my_identity, | 883 | &my_identity, |
877 | &queue->in_cipher, | 884 | &queue->in_cipher, |
878 | &queue->in_hmac); | 885 | &queue->in_hmac); |
879 | } | 886 | } |
880 | 887 | ||
881 | 888 | ||
@@ -901,9 +908,9 @@ do_rekey (struct Queue *queue, | |||
901 | thp.monotonic_time = rekey->monotonic_time; | 908 | thp.monotonic_time = rekey->monotonic_time; |
902 | if (GNUNET_OK != | 909 | if (GNUNET_OK != |
903 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, | 910 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, |
904 | &thp.purpose, | 911 | &thp.purpose, |
905 | &rekey->sender_sig, | 912 | &rekey->sender_sig, |
906 | &queue->target.public_key)) | 913 | &queue->target.public_key)) |
907 | { | 914 | { |
908 | GNUNET_break (0); | 915 | GNUNET_break (0); |
909 | queue_finish (queue); | 916 | queue_finish (queue); |
@@ -912,7 +919,7 @@ do_rekey (struct Queue *queue, | |||
912 | gcry_cipher_close (queue->in_cipher); | 919 | gcry_cipher_close (queue->in_cipher); |
913 | queue->rekeyed = GNUNET_YES; | 920 | queue->rekeyed = GNUNET_YES; |
914 | setup_in_cipher (&rekey->ephemeral, | 921 | setup_in_cipher (&rekey->ephemeral, |
915 | queue); | 922 | queue); |
916 | } | 923 | } |
917 | 924 | ||
918 | 925 | ||
@@ -954,16 +961,16 @@ try_handle_plaintext (struct Queue *queue) | |||
954 | ntohs (hdr->size), | 961 | ntohs (hdr->size), |
955 | &tmac); | 962 | &tmac); |
956 | if (0 != memcmp (&tmac, | 963 | if (0 != memcmp (&tmac, |
957 | &box->hmac, | 964 | &box->hmac, |
958 | sizeof (tmac))) | 965 | sizeof (tmac))) |
959 | { | 966 | { |
960 | GNUNET_break_op (0); | 967 | GNUNET_break_op (0); |
961 | queue_finish (queue); | 968 | queue_finish (queue); |
962 | return 0; | 969 | return 0; |
963 | } | 970 | } |
964 | pass_plaintext_to_core (queue, | 971 | pass_plaintext_to_core (queue, |
965 | (const void *) &box[1], | 972 | (const void *) &box[1], |
966 | ntohs (hdr->size)); | 973 | ntohs (hdr->size)); |
967 | size = ntohs (hdr->size) + sizeof (*box); | 974 | size = ntohs (hdr->size) + sizeof (*box); |
968 | break; | 975 | break; |
969 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: | 976 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: |
@@ -1013,8 +1020,8 @@ try_handle_plaintext (struct Queue *queue) | |||
1013 | sizeof (rekeyz), | 1020 | sizeof (rekeyz), |
1014 | &tmac); | 1021 | &tmac); |
1015 | if (0 != memcmp (&tmac, | 1022 | if (0 != memcmp (&tmac, |
1016 | &fin->hmac, | 1023 | &fin->hmac, |
1017 | sizeof (tmac))) | 1024 | sizeof (tmac))) |
1018 | { | 1025 | { |
1019 | GNUNET_break_op (0); | 1026 | GNUNET_break_op (0); |
1020 | queue_finish (queue); | 1027 | queue_finish (queue); |
@@ -1047,24 +1054,24 @@ queue_read (void *cls) | |||
1047 | 1054 | ||
1048 | queue->read_task = NULL; | 1055 | queue->read_task = NULL; |
1049 | rcvd = GNUNET_NETWORK_socket_recv (queue->sock, | 1056 | rcvd = GNUNET_NETWORK_socket_recv (queue->sock, |
1050 | &queue->cread_buf[queue->cread_off], | 1057 | &queue->cread_buf[queue->cread_off], |
1051 | BUF_SIZE - queue->cread_off); | 1058 | BUF_SIZE - queue->cread_off); |
1052 | if (-1 == rcvd) | 1059 | if (-1 == rcvd) |
1053 | { | 1060 | { |
1054 | if ( (EAGAIN != errno) && | 1061 | if ( (EAGAIN != errno) && |
1055 | (EINTR != errno) ) | 1062 | (EINTR != errno) ) |
1056 | { | 1063 | { |
1057 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, | 1064 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, |
1058 | "recv"); | 1065 | "recv"); |
1059 | queue_finish (queue); | 1066 | queue_finish (queue); |
1060 | return; | 1067 | return; |
1061 | } | 1068 | } |
1062 | /* try again */ | 1069 | /* try again */ |
1063 | queue->read_task | 1070 | queue->read_task |
1064 | = GNUNET_SCHEDULER_add_read_net (left, | 1071 | = GNUNET_SCHEDULER_add_read_net (left, |
1065 | queue->sock, | 1072 | queue->sock, |
1066 | &queue_read, | 1073 | &queue_read, |
1067 | queue); | 1074 | queue); |
1068 | return; | 1075 | return; |
1069 | } | 1076 | } |
1070 | if (0 != rcvd) | 1077 | if (0 != rcvd) |
@@ -1074,16 +1081,16 @@ queue_read (void *cls) | |||
1074 | (queue->cread_off > 0) ) | 1081 | (queue->cread_off > 0) ) |
1075 | { | 1082 | { |
1076 | size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off, | 1083 | size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off, |
1077 | queue->cread_off); | 1084 | queue->cread_off); |
1078 | size_t done; | 1085 | size_t done; |
1079 | size_t total; | 1086 | size_t total; |
1080 | 1087 | ||
1081 | GNUNET_assert (0 == | 1088 | GNUNET_assert (0 == |
1082 | gcry_cipher_decrypt (queue->in_cipher, | 1089 | gcry_cipher_decrypt (queue->in_cipher, |
1083 | &queue->pread_buf[queue->pread_off], | 1090 | &queue->pread_buf[queue->pread_off], |
1084 | max, | 1091 | max, |
1085 | queue->cread_buf, | 1092 | queue->cread_buf, |
1086 | max)); | 1093 | max)); |
1087 | queue->pread_off += max; | 1094 | queue->pread_off += max; |
1088 | total = 0; | 1095 | total = 0; |
1089 | while ( (GNUNET_NO == queue->rekeyed) && | 1096 | while ( (GNUNET_NO == queue->rekeyed) && |
@@ -1095,8 +1102,8 @@ queue_read (void *cls) | |||
1095 | avoided if we pass 'total' into try_handle_plaintext() | 1102 | avoided if we pass 'total' into try_handle_plaintext() |
1096 | and use it at an offset into the buffer there! */ | 1103 | and use it at an offset into the buffer there! */ |
1097 | memmove (queue->pread_buf, | 1104 | memmove (queue->pread_buf, |
1098 | &queue->pread_buf[done], | 1105 | &queue->pread_buf[done], |
1099 | queue->pread_off - done); | 1106 | queue->pread_off - done); |
1100 | queue->pread_off -= done; | 1107 | queue->pread_off -= done; |
1101 | total += done; | 1108 | total += done; |
1102 | } | 1109 | } |
@@ -1111,8 +1118,8 @@ queue_read (void *cls) | |||
1111 | queue->rekeyed = GNUNET_NO; | 1118 | queue->rekeyed = GNUNET_NO; |
1112 | } | 1119 | } |
1113 | memmove (queue->cread_buf, | 1120 | memmove (queue->cread_buf, |
1114 | &queue->cread_buf[max], | 1121 | &queue->cread_buf[max], |
1115 | queue->cread_off - max); | 1122 | queue->cread_off - max); |
1116 | queue->cread_off -= max; | 1123 | queue->cread_off -= max; |
1117 | } | 1124 | } |
1118 | 1125 | ||
@@ -1126,17 +1133,17 @@ queue_read (void *cls) | |||
1126 | /* continue reading */ | 1133 | /* continue reading */ |
1127 | queue->read_task | 1134 | queue->read_task |
1128 | = GNUNET_SCHEDULER_add_read_net (left, | 1135 | = GNUNET_SCHEDULER_add_read_net (left, |
1129 | queue->sock, | 1136 | queue->sock, |
1130 | &queue_read, | 1137 | &queue_read, |
1131 | queue); | 1138 | queue); |
1132 | } | 1139 | } |
1133 | return; | 1140 | return; |
1134 | } | 1141 | } |
1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1136 | "Queue %p was idle for %s, disconnecting\n", | 1143 | "Queue %p was idle for %s, disconnecting\n", |
1137 | queue, | 1144 | queue, |
1138 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1145 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1139 | GNUNET_YES)); | 1146 | GNUNET_YES)); |
1140 | queue_finish (queue); | 1147 | queue_finish (queue); |
1141 | } | 1148 | } |
1142 | 1149 | ||
@@ -1150,7 +1157,7 @@ queue_read (void *cls) | |||
1150 | */ | 1157 | */ |
1151 | static struct sockaddr * | 1158 | static struct sockaddr * |
1152 | tcp_address_to_sockaddr (const char *bindto, | 1159 | tcp_address_to_sockaddr (const char *bindto, |
1153 | socklen_t *sock_len) | 1160 | socklen_t *sock_len) |
1154 | { | 1161 | { |
1155 | struct sockaddr *in; | 1162 | struct sockaddr *in; |
1156 | unsigned int port; | 1163 | unsigned int port; |
@@ -1159,24 +1166,24 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1159 | char *cp; | 1166 | char *cp; |
1160 | 1167 | ||
1161 | if (1 == SSCANF (bindto, | 1168 | if (1 == SSCANF (bindto, |
1162 | "%u%1s", | 1169 | "%u%1s", |
1163 | &port, | 1170 | &port, |
1164 | dummy)) | 1171 | dummy)) |
1165 | { | 1172 | { |
1166 | /* interpreting value as just a PORT number */ | 1173 | /* interpreting value as just a PORT number */ |
1167 | if (port > UINT16_MAX) | 1174 | if (port > UINT16_MAX) |
1168 | { | 1175 | { |
1169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1170 | "BINDTO specification `%s' invalid: value too large for port\n", | 1177 | "BINDTO specification `%s' invalid: value too large for port\n", |
1171 | bindto); | 1178 | bindto); |
1172 | return NULL; | 1179 | return NULL; |
1173 | } | 1180 | } |
1174 | if ( (GNUNET_NO == | 1181 | if ( (GNUNET_NO == |
1175 | GNUNET_NETWORK_test_pf (PF_INET6)) || | 1182 | GNUNET_NETWORK_test_pf (PF_INET6)) || |
1176 | (GNUNET_YES == | 1183 | (GNUNET_YES == |
1177 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1184 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1178 | COMMUNICATOR_CONFIG_SECTION, | 1185 | COMMUNICATOR_CONFIG_SECTION, |
1179 | "DISABLE_V6")) ) | 1186 | "DISABLE_V6")) ) |
1180 | { | 1187 | { |
1181 | struct sockaddr_in *i4; | 1188 | struct sockaddr_in *i4; |
1182 | 1189 | ||
@@ -1206,25 +1213,25 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1206 | *colon = '\0'; | 1213 | *colon = '\0'; |
1207 | colon++; | 1214 | colon++; |
1208 | if (1 == SSCANF (colon, | 1215 | if (1 == SSCANF (colon, |
1209 | "%u%1s", | 1216 | "%u%1s", |
1210 | &port, | 1217 | &port, |
1211 | dummy)) | 1218 | dummy)) |
1212 | { | 1219 | { |
1213 | /* interpreting value as just a PORT number */ | 1220 | /* interpreting value as just a PORT number */ |
1214 | if (port > UINT16_MAX) | 1221 | if (port > UINT16_MAX) |
1215 | { | 1222 | { |
1216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1223 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1217 | "BINDTO specification `%s' invalid: value too large for port\n", | 1224 | "BINDTO specification `%s' invalid: value too large for port\n", |
1218 | bindto); | 1225 | bindto); |
1219 | GNUNET_free (cp); | 1226 | GNUNET_free (cp); |
1220 | return NULL; | 1227 | return NULL; |
1221 | } | 1228 | } |
1222 | } | 1229 | } |
1223 | else | 1230 | else |
1224 | { | 1231 | { |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1226 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | 1233 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", |
1227 | bindto); | 1234 | bindto); |
1228 | GNUNET_free (cp); | 1235 | GNUNET_free (cp); |
1229 | return NULL; | 1236 | return NULL; |
1230 | } | 1237 | } |
@@ -1239,12 +1246,12 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1239 | struct sockaddr_in v4; | 1246 | struct sockaddr_in v4; |
1240 | 1247 | ||
1241 | if (1 == inet_pton (AF_INET, | 1248 | if (1 == inet_pton (AF_INET, |
1242 | cp, | 1249 | cp, |
1243 | &v4)) | 1250 | &v4)) |
1244 | { | 1251 | { |
1245 | v4.sin_port = htons ((uint16_t) port); | 1252 | v4.sin_port = htons ((uint16_t) port); |
1246 | in = GNUNET_memdup (&v4, | 1253 | in = GNUNET_memdup (&v4, |
1247 | sizeof (v4)); | 1254 | sizeof (v4)); |
1248 | *sock_len = sizeof (v4); | 1255 | *sock_len = sizeof (v4); |
1249 | GNUNET_free (cp); | 1256 | GNUNET_free (cp); |
1250 | return in; | 1257 | return in; |
@@ -1263,12 +1270,12 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1263 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ | 1270 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ |
1264 | } | 1271 | } |
1265 | if (1 == inet_pton (AF_INET6, | 1272 | if (1 == inet_pton (AF_INET6, |
1266 | start, | 1273 | start, |
1267 | &v6)) | 1274 | &v6)) |
1268 | { | 1275 | { |
1269 | v6.sin6_port = htons ((uint16_t) port); | 1276 | v6.sin6_port = htons ((uint16_t) port); |
1270 | in = GNUNET_memdup (&v6, | 1277 | in = GNUNET_memdup (&v6, |
1271 | sizeof (v6)); | 1278 | sizeof (v6)); |
1272 | *sock_len = sizeof (v6); | 1279 | *sock_len = sizeof (v6); |
1273 | GNUNET_free (cp); | 1280 | GNUNET_free (cp); |
1274 | return in; | 1281 | return in; |
@@ -1292,20 +1299,19 @@ setup_out_cipher (struct Queue *queue) | |||
1292 | struct GNUNET_HashCode dh; | 1299 | struct GNUNET_HashCode dh; |
1293 | 1300 | ||
1294 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, | 1301 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, |
1295 | &queue->target.public_key, | 1302 | &queue->target.public_key, |
1296 | &dh); | 1303 | &dh); |
1297 | /* we don't need the private key anymore, drop it! */ | 1304 | /* we don't need the private key anymore, drop it! */ |
1298 | memset (&queue->ephemeral, | 1305 | memset (&queue->ephemeral, |
1299 | 0, | 1306 | 0, |
1300 | sizeof (queue->ephemeral)); | 1307 | sizeof (queue->ephemeral)); |
1301 | setup_cipher (&dh, | 1308 | setup_cipher (&dh, |
1302 | &queue->target, | 1309 | &queue->target, |
1303 | &queue->out_cipher, | 1310 | &queue->out_cipher, |
1304 | &queue->out_hmac); | 1311 | &queue->out_hmac); |
1305 | |||
1306 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); | 1312 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); |
1307 | queue->rekey_left_bytes = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1313 | queue->rekey_left_bytes = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1308 | REKEY_MAX_BYTES); | 1314 | REKEY_MAX_BYTES); |
1309 | } | 1315 | } |
1310 | 1316 | ||
1311 | 1317 | ||
@@ -1323,14 +1329,14 @@ inject_rekey (struct Queue *queue) | |||
1323 | 1329 | ||
1324 | GNUNET_assert (0 == queue->pwrite_off); | 1330 | GNUNET_assert (0 == queue->pwrite_off); |
1325 | memset (&rekey, | 1331 | memset (&rekey, |
1326 | 0, | 1332 | 0, |
1327 | sizeof (rekey)); | 1333 | sizeof (rekey)); |
1328 | GNUNET_assert (GNUNET_OK == | 1334 | GNUNET_assert (GNUNET_OK == |
1329 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | 1335 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); |
1330 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); | 1336 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); |
1331 | rekey.header.size = ntohs (sizeof (rekey)); | 1337 | rekey.header.size = ntohs (sizeof (rekey)); |
1332 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, | 1338 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, |
1333 | &rekey.ephemeral); | 1339 | &rekey.ephemeral); |
1334 | rekey.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | 1340 | rekey.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); |
1335 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); | 1341 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); |
1336 | thp.purpose.size = htonl (sizeof (thp)); | 1342 | thp.purpose.size = htonl (sizeof (thp)); |
@@ -1339,16 +1345,16 @@ inject_rekey (struct Queue *queue) | |||
1339 | thp.ephemeral = rekey.ephemeral; | 1345 | thp.ephemeral = rekey.ephemeral; |
1340 | thp.monotonic_time = rekey.monotonic_time; | 1346 | thp.monotonic_time = rekey.monotonic_time; |
1341 | GNUNET_assert (GNUNET_OK == | 1347 | GNUNET_assert (GNUNET_OK == |
1342 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 1348 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1343 | &thp.purpose, | 1349 | &thp.purpose, |
1344 | &rekey.sender_sig)); | 1350 | &rekey.sender_sig)); |
1345 | calculate_hmac (&queue->out_hmac, | 1351 | calculate_hmac (&queue->out_hmac, |
1346 | &rekey, | 1352 | &rekey, |
1347 | sizeof (rekey), | 1353 | sizeof (rekey), |
1348 | &rekey.hmac); | 1354 | &rekey.hmac); |
1349 | memcpy (queue->pwrite_buf, | 1355 | memcpy (queue->pwrite_buf, |
1350 | &rekey, | 1356 | &rekey, |
1351 | sizeof (rekey)); | 1357 | sizeof (rekey)); |
1352 | queue->rekey_state = GNUNET_YES; | 1358 | queue->rekey_state = GNUNET_YES; |
1353 | } | 1359 | } |
1354 | 1360 | ||
@@ -1380,14 +1386,14 @@ queue_write (void *cls) | |||
1380 | 1386 | ||
1381 | queue->write_task = NULL; | 1387 | queue->write_task = NULL; |
1382 | sent = GNUNET_NETWORK_socket_send (queue->sock, | 1388 | sent = GNUNET_NETWORK_socket_send (queue->sock, |
1383 | queue->cwrite_buf, | 1389 | queue->cwrite_buf, |
1384 | queue->cwrite_off); | 1390 | queue->cwrite_off); |
1385 | if ( (-1 == sent) && | 1391 | if ( (-1 == sent) && |
1386 | (EAGAIN != errno) && | 1392 | (EAGAIN != errno) && |
1387 | (EINTR != errno) ) | 1393 | (EINTR != errno) ) |
1388 | { | 1394 | { |
1389 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1395 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
1390 | "send"); | 1396 | "send"); |
1391 | queue_destroy (queue); | 1397 | queue_destroy (queue); |
1392 | return; | 1398 | return; |
1393 | } | 1399 | } |
@@ -1396,8 +1402,8 @@ queue_write (void *cls) | |||
1396 | size_t usent = (size_t) sent; | 1402 | size_t usent = (size_t) sent; |
1397 | 1403 | ||
1398 | memmove (queue->cwrite_buf, | 1404 | memmove (queue->cwrite_buf, |
1399 | &queue->cwrite_buf[usent], | 1405 | &queue->cwrite_buf[usent], |
1400 | queue->cwrite_off - usent); | 1406 | queue->cwrite_off - usent); |
1401 | reschedule_queue_timeout (queue); | 1407 | reschedule_queue_timeout (queue); |
1402 | } | 1408 | } |
1403 | /* can we encrypt more? (always encrypt full messages, needed | 1409 | /* can we encrypt more? (always encrypt full messages, needed |
@@ -1405,11 +1411,11 @@ queue_write (void *cls) | |||
1405 | if (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE) | 1411 | if (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE) |
1406 | { | 1412 | { |
1407 | GNUNET_assert (0 == | 1413 | GNUNET_assert (0 == |
1408 | gcry_cipher_encrypt (queue->out_cipher, | 1414 | gcry_cipher_encrypt (queue->out_cipher, |
1409 | &queue->cwrite_buf[queue->cwrite_off], | 1415 | &queue->cwrite_buf[queue->cwrite_off], |
1410 | queue->pwrite_off, | 1416 | queue->pwrite_off, |
1411 | queue->pwrite_buf, | 1417 | queue->pwrite_buf, |
1412 | queue->pwrite_off)); | 1418 | queue->pwrite_off)); |
1413 | if (queue->rekey_left_bytes > queue->pwrite_off) | 1419 | if (queue->rekey_left_bytes > queue->pwrite_off) |
1414 | queue->rekey_left_bytes -= queue->pwrite_off; | 1420 | queue->rekey_left_bytes -= queue->pwrite_off; |
1415 | else | 1421 | else |
@@ -1442,9 +1448,9 @@ queue_write (void *cls) | |||
1442 | if (0 < queue->cwrite_off) | 1448 | if (0 < queue->cwrite_off) |
1443 | queue->write_task | 1449 | queue->write_task |
1444 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1450 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1445 | queue->sock, | 1451 | queue->sock, |
1446 | &queue_write, | 1452 | &queue_write, |
1447 | queue); | 1453 | queue); |
1448 | } | 1454 | } |
1449 | 1455 | ||
1450 | 1456 | ||
@@ -1458,8 +1464,8 @@ queue_write (void *cls) | |||
1458 | */ | 1464 | */ |
1459 | static void | 1465 | static void |
1460 | mq_send (struct GNUNET_MQ_Handle *mq, | 1466 | mq_send (struct GNUNET_MQ_Handle *mq, |
1461 | const struct GNUNET_MessageHeader *msg, | 1467 | const struct GNUNET_MessageHeader *msg, |
1462 | void *impl_state) | 1468 | void *impl_state) |
1463 | { | 1469 | { |
1464 | struct Queue *queue = impl_state; | 1470 | struct Queue *queue = impl_state; |
1465 | uint16_t msize = ntohs (msg->size); | 1471 | uint16_t msize = ntohs (msg->size); |
@@ -1476,12 +1482,12 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1476 | msize, | 1482 | msize, |
1477 | &box.hmac); | 1483 | &box.hmac); |
1478 | memcpy (&queue->pread_buf[queue->pread_off], | 1484 | memcpy (&queue->pread_buf[queue->pread_off], |
1479 | &box, | 1485 | &box, |
1480 | sizeof (box)); | 1486 | sizeof (box)); |
1481 | queue->pread_off += sizeof (box); | 1487 | queue->pread_off += sizeof (box); |
1482 | memcpy (&queue->pread_buf[queue->pread_off], | 1488 | memcpy (&queue->pread_buf[queue->pread_off], |
1483 | msg, | 1489 | msg, |
1484 | msize); | 1490 | msize); |
1485 | queue->pread_off += msize; | 1491 | queue->pread_off += msize; |
1486 | GNUNET_assert (NULL != queue->sock); | 1492 | GNUNET_assert (NULL != queue->sock); |
1487 | if (NULL == queue->write_task) | 1493 | if (NULL == queue->write_task) |
@@ -1489,7 +1495,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1489 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1495 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1490 | queue->sock, | 1496 | queue->sock, |
1491 | &queue_write, | 1497 | &queue_write, |
1492 | queue); | 1498 | queue); |
1493 | } | 1499 | } |
1494 | 1500 | ||
1495 | 1501 | ||
@@ -1503,7 +1509,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1503 | */ | 1509 | */ |
1504 | static void | 1510 | static void |
1505 | mq_destroy (struct GNUNET_MQ_Handle *mq, | 1511 | mq_destroy (struct GNUNET_MQ_Handle *mq, |
1506 | void *impl_state) | 1512 | void *impl_state) |
1507 | { | 1513 | { |
1508 | struct Queue *queue = impl_state; | 1514 | struct Queue *queue = impl_state; |
1509 | 1515 | ||
@@ -1523,7 +1529,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, | |||
1523 | */ | 1529 | */ |
1524 | static void | 1530 | static void |
1525 | mq_cancel (struct GNUNET_MQ_Handle *mq, | 1531 | mq_cancel (struct GNUNET_MQ_Handle *mq, |
1526 | void *impl_state) | 1532 | void *impl_state) |
1527 | { | 1533 | { |
1528 | struct Queue *queue = impl_state; | 1534 | struct Queue *queue = impl_state; |
1529 | 1535 | ||
@@ -1543,14 +1549,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, | |||
1543 | */ | 1549 | */ |
1544 | static void | 1550 | static void |
1545 | mq_error (void *cls, | 1551 | mq_error (void *cls, |
1546 | enum GNUNET_MQ_Error error) | 1552 | enum GNUNET_MQ_Error error) |
1547 | { | 1553 | { |
1548 | struct Queue *queue = cls; | 1554 | struct Queue *queue = cls; |
1549 | 1555 | ||
1550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1556 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1551 | "MQ error in queue to %s: %d\n", | 1557 | "MQ error in queue to %s: %d\n", |
1552 | GNUNET_i2s (&queue->target), | 1558 | GNUNET_i2s (&queue->target), |
1553 | (int) error); | 1559 | (int) error); |
1554 | queue_finish (queue); | 1560 | queue_finish (queue); |
1555 | } | 1561 | } |
1556 | 1562 | ||
@@ -1567,26 +1573,26 @@ boot_queue (struct Queue *queue, | |||
1567 | enum GNUNET_TRANSPORT_ConnectionStatus cs) | 1573 | enum GNUNET_TRANSPORT_ConnectionStatus cs) |
1568 | { | 1574 | { |
1569 | queue->nt = GNUNET_NT_scanner_get_type (is, | 1575 | queue->nt = GNUNET_NT_scanner_get_type (is, |
1570 | queue->address, | 1576 | queue->address, |
1571 | queue->address_len); | 1577 | queue->address_len); |
1572 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, | 1578 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, |
1573 | &queue->target, | 1579 | &queue->target, |
1574 | queue, | 1580 | queue, |
1575 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1581 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1576 | GNUNET_STATISTICS_set (stats, | 1582 | GNUNET_STATISTICS_set (stats, |
1577 | "# queues active", | 1583 | "# queues active", |
1578 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 1584 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
1579 | GNUNET_NO); | 1585 | GNUNET_NO); |
1580 | queue->timeout | 1586 | queue->timeout |
1581 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1587 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1582 | queue->mq | 1588 | queue->mq |
1583 | = GNUNET_MQ_queue_for_callbacks (&mq_send, | 1589 | = GNUNET_MQ_queue_for_callbacks (&mq_send, |
1584 | &mq_destroy, | 1590 | &mq_destroy, |
1585 | &mq_cancel, | 1591 | &mq_cancel, |
1586 | queue, | 1592 | queue, |
1587 | NULL, | 1593 | NULL, |
1588 | &mq_error, | 1594 | &mq_error, |
1589 | queue); | 1595 | queue); |
1590 | { | 1596 | { |
1591 | char *foreign_addr; | 1597 | char *foreign_addr; |
1592 | 1598 | ||
@@ -1594,29 +1600,29 @@ boot_queue (struct Queue *queue, | |||
1594 | { | 1600 | { |
1595 | case AF_INET: | 1601 | case AF_INET: |
1596 | GNUNET_asprintf (&foreign_addr, | 1602 | GNUNET_asprintf (&foreign_addr, |
1597 | "%s-%s", | 1603 | "%s-%s", |
1598 | COMMUNICATOR_ADDRESS_PREFIX, | 1604 | COMMUNICATOR_ADDRESS_PREFIX, |
1599 | GNUNET_a2s(queue->address, | 1605 | GNUNET_a2s(queue->address, |
1600 | queue->address_len)); | 1606 | queue->address_len)); |
1601 | break; | 1607 | break; |
1602 | case AF_INET6: | 1608 | case AF_INET6: |
1603 | GNUNET_asprintf (&foreign_addr, | 1609 | GNUNET_asprintf (&foreign_addr, |
1604 | "%s-%s", | 1610 | "%s-%s", |
1605 | COMMUNICATOR_ADDRESS_PREFIX, | 1611 | COMMUNICATOR_ADDRESS_PREFIX, |
1606 | GNUNET_a2s(queue->address, | 1612 | GNUNET_a2s(queue->address, |
1607 | queue->address_len)); | 1613 | queue->address_len)); |
1608 | break; | 1614 | break; |
1609 | default: | 1615 | default: |
1610 | GNUNET_assert (0); | 1616 | GNUNET_assert (0); |
1611 | } | 1617 | } |
1612 | queue->qh | 1618 | queue->qh |
1613 | = GNUNET_TRANSPORT_communicator_mq_add (ch, | 1619 | = GNUNET_TRANSPORT_communicator_mq_add (ch, |
1614 | &queue->target, | 1620 | &queue->target, |
1615 | foreign_addr, | 1621 | foreign_addr, |
1616 | 0 /* no MTU */, | 1622 | 0 /* no MTU */, |
1617 | queue->nt, | 1623 | queue->nt, |
1618 | cs, | 1624 | cs, |
1619 | queue->mq); | 1625 | queue->mq); |
1620 | GNUNET_free (foreign_addr); | 1626 | GNUNET_free (foreign_addr); |
1621 | } | 1627 | } |
1622 | } | 1628 | } |
@@ -1640,8 +1646,8 @@ transmit_kx (struct Queue *queue, | |||
1640 | struct TCPConfirmation tc; | 1646 | struct TCPConfirmation tc; |
1641 | 1647 | ||
1642 | memcpy (queue->cwrite_buf, | 1648 | memcpy (queue->cwrite_buf, |
1643 | epub, | 1649 | epub, |
1644 | sizeof (*epub)); | 1650 | sizeof (*epub)); |
1645 | queue->cwrite_off = sizeof (epub); | 1651 | queue->cwrite_off = sizeof (epub); |
1646 | /* compute 'tc' and append in encrypted format to cwrite_buf */ | 1652 | /* compute 'tc' and append in encrypted format to cwrite_buf */ |
1647 | tc.sender = my_identity; | 1653 | tc.sender = my_identity; |
@@ -1653,15 +1659,15 @@ transmit_kx (struct Queue *queue, | |||
1653 | ths.ephemeral = *epub; | 1659 | ths.ephemeral = *epub; |
1654 | ths.monotonic_time = tc.monotonic_time; | 1660 | ths.monotonic_time = tc.monotonic_time; |
1655 | GNUNET_assert (GNUNET_OK == | 1661 | GNUNET_assert (GNUNET_OK == |
1656 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 1662 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1657 | &ths.purpose, | 1663 | &ths.purpose, |
1658 | &tc.sender_sig)); | 1664 | &tc.sender_sig)); |
1659 | GNUNET_assert (0 == | 1665 | GNUNET_assert (0 == |
1660 | gcry_cipher_encrypt (queue->out_cipher, | 1666 | gcry_cipher_encrypt (queue->out_cipher, |
1661 | &queue->cwrite_buf[queue->cwrite_off], | 1667 | &queue->cwrite_buf[queue->cwrite_off], |
1662 | sizeof (tc), | 1668 | sizeof (tc), |
1663 | &tc, | 1669 | &tc, |
1664 | sizeof (tc))); | 1670 | sizeof (tc))); |
1665 | queue->cwrite_off += sizeof (tc); | 1671 | queue->cwrite_off += sizeof (tc); |
1666 | } | 1672 | } |
1667 | 1673 | ||
@@ -1681,10 +1687,10 @@ start_initial_kx_out (struct Queue *queue) | |||
1681 | GNUNET_assert (GNUNET_OK == | 1687 | GNUNET_assert (GNUNET_OK == |
1682 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | 1688 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); |
1683 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, | 1689 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, |
1684 | &epub); | 1690 | &epub); |
1685 | setup_out_cipher (queue); | 1691 | setup_out_cipher (queue); |
1686 | transmit_kx (queue, | 1692 | transmit_kx (queue, |
1687 | &epub); | 1693 | &epub); |
1688 | } | 1694 | } |
1689 | 1695 | ||
1690 | 1696 | ||
@@ -1701,17 +1707,17 @@ start_initial_kx_out (struct Queue *queue) | |||
1701 | */ | 1707 | */ |
1702 | static int | 1708 | static int |
1703 | decrypt_and_check_tc (struct Queue *queue, | 1709 | decrypt_and_check_tc (struct Queue *queue, |
1704 | struct TCPConfirmation *tc, | 1710 | struct TCPConfirmation *tc, |
1705 | char *ibuf) | 1711 | char *ibuf) |
1706 | { | 1712 | { |
1707 | struct TcpHandshakeSignature ths; | 1713 | struct TcpHandshakeSignature ths; |
1708 | 1714 | ||
1709 | GNUNET_assert (0 == | 1715 | GNUNET_assert (0 == |
1710 | gcry_cipher_decrypt (queue->in_cipher, | 1716 | gcry_cipher_decrypt (queue->in_cipher, |
1711 | tc, | 1717 | tc, |
1712 | sizeof (*tc), | 1718 | sizeof (*tc), |
1713 | &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)], | 1719 | &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)], |
1714 | sizeof (tc))); | 1720 | sizeof (tc))); |
1715 | ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); | 1721 | ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); |
1716 | ths.purpose.size = htonl (sizeof (ths)); | 1722 | ths.purpose.size = htonl (sizeof (ths)); |
1717 | ths.sender = tc->sender; | 1723 | ths.sender = tc->sender; |
@@ -1721,9 +1727,9 @@ decrypt_and_check_tc (struct Queue *queue, | |||
1721 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 1727 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
1722 | ths.monotonic_time = tc->monotonic_time; | 1728 | ths.monotonic_time = tc->monotonic_time; |
1723 | return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, | 1729 | return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, |
1724 | &ths.purpose, | 1730 | &ths.purpose, |
1725 | &tc->sender_sig, | 1731 | &tc->sender_sig, |
1726 | &tc->sender.public_key); | 1732 | &tc->sender.public_key); |
1727 | } | 1733 | } |
1728 | 1734 | ||
1729 | 1735 | ||
@@ -1738,8 +1744,8 @@ free_proto_queue (struct ProtoQueue *pq) | |||
1738 | GNUNET_NETWORK_socket_close (pq->sock); | 1744 | GNUNET_NETWORK_socket_close (pq->sock); |
1739 | GNUNET_free (pq->address); | 1745 | GNUNET_free (pq->address); |
1740 | GNUNET_CONTAINER_DLL_remove (proto_head, | 1746 | GNUNET_CONTAINER_DLL_remove (proto_head, |
1741 | proto_tail, | 1747 | proto_tail, |
1742 | pq); | 1748 | pq); |
1743 | GNUNET_free (pq); | 1749 | GNUNET_free (pq); |
1744 | } | 1750 | } |
1745 | 1751 | ||