diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/transport/gnunet-communicator-udp.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/transport/gnunet-communicator-udp.c')
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 2214 |
1 files changed, 1114 insertions, 1100 deletions
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 228540b81..2d9fabfec 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -67,7 +67,7 @@ | |||
67 | * How often do we scan for changes to our network interfaces? | 67 | * How often do we scan for changes to our network interfaces? |
68 | */ | 68 | */ |
69 | #define INTERFACE_SCAN_FREQUENCY \ | 69 | #define INTERFACE_SCAN_FREQUENCY \ |
70 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 70 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * How long do we believe our addresses to remain up (before | 73 | * How long do we believe our addresses to remain up (before |
@@ -156,7 +156,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
156 | * the specified sender. If possible, the receiver should respond with | 156 | * the specified sender. If possible, the receiver should respond with |
157 | * a `struct UDPAck` (possibly via backchannel). | 157 | * a `struct UDPAck` (possibly via backchannel). |
158 | */ | 158 | */ |
159 | struct UdpHandshakeSignature { | 159 | struct UdpHandshakeSignature |
160 | { | ||
160 | /** | 161 | /** |
161 | * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE | 162 | * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE |
162 | */ | 163 | */ |
@@ -189,7 +190,8 @@ struct UdpHandshakeSignature { | |||
189 | * "Plaintext" header at beginning of KX message. Followed | 190 | * "Plaintext" header at beginning of KX message. Followed |
190 | * by encrypted `struct UDPConfirmation`. | 191 | * by encrypted `struct UDPConfirmation`. |
191 | */ | 192 | */ |
192 | struct InitialKX { | 193 | struct InitialKX |
194 | { | ||
193 | /** | 195 | /** |
194 | * Ephemeral key for KX. | 196 | * Ephemeral key for KX. |
195 | */ | 197 | */ |
@@ -207,7 +209,8 @@ struct InitialKX { | |||
207 | * Encrypted continuation of UDP initial handshake, followed | 209 | * Encrypted continuation of UDP initial handshake, followed |
208 | * by message header with payload. | 210 | * by message header with payload. |
209 | */ | 211 | */ |
210 | struct UDPConfirmation { | 212 | struct UDPConfirmation |
213 | { | ||
211 | /** | 214 | /** |
212 | * Sender's identity | 215 | * Sender's identity |
213 | */ | 216 | */ |
@@ -234,7 +237,8 @@ struct UDPConfirmation { | |||
234 | * UDP key acknowledgement. May be sent via backchannel. Allows the | 237 | * UDP key acknowledgement. May be sent via backchannel. Allows the |
235 | * sender to use `struct UDPBox` with the acknowledge key henceforth. | 238 | * sender to use `struct UDPBox` with the acknowledge key henceforth. |
236 | */ | 239 | */ |
237 | struct UDPAck { | 240 | struct UDPAck |
241 | { | ||
238 | /** | 242 | /** |
239 | * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK. | 243 | * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK. |
240 | */ | 244 | */ |
@@ -261,7 +265,8 @@ struct UDPAck { | |||
261 | * be just any global peer -- an attacker must have at least | 265 | * be just any global peer -- an attacker must have at least |
262 | * shared a LAN with the peer they're pretending to be here. | 266 | * shared a LAN with the peer they're pretending to be here. |
263 | */ | 267 | */ |
264 | struct UdpBroadcastSignature { | 268 | struct UdpBroadcastSignature |
269 | { | ||
265 | /** | 270 | /** |
266 | * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST | 271 | * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST |
267 | */ | 272 | */ |
@@ -285,7 +290,8 @@ struct UdpBroadcastSignature { | |||
285 | * recognized in LAN as GNUnet peers if this feature is enabled | 290 | * recognized in LAN as GNUnet peers if this feature is enabled |
286 | * anyway. Also, the entire message is in cleartext. | 291 | * anyway. Also, the entire message is in cleartext. |
287 | */ | 292 | */ |
288 | struct UDPBroadcast { | 293 | struct UDPBroadcast |
294 | { | ||
289 | /** | 295 | /** |
290 | * Sender's peer identity. | 296 | * Sender's peer identity. |
291 | */ | 297 | */ |
@@ -303,7 +309,8 @@ struct UDPBroadcast { | |||
303 | * UDP message box. Always sent encrypted, only allowed after | 309 | * UDP message box. Always sent encrypted, only allowed after |
304 | * the receiver sent a `struct UDPAck` for the base key! | 310 | * the receiver sent a `struct UDPAck` for the base key! |
305 | */ | 311 | */ |
306 | struct UDPBox { | 312 | struct UDPBox |
313 | { | ||
307 | /** | 314 | /** |
308 | * Key and IV identification code. KDF applied to an acknowledged | 315 | * Key and IV identification code. KDF applied to an acknowledged |
309 | * base key and a sequence number. Sequence numbers must be used | 316 | * base key and a sequence number. Sequence numbers must be used |
@@ -336,7 +343,8 @@ struct SharedSecret; | |||
336 | * Pre-generated "kid" code (key and IV identification code) to | 343 | * Pre-generated "kid" code (key and IV identification code) to |
337 | * quickly derive master key for a `struct UDPBox`. | 344 | * quickly derive master key for a `struct UDPBox`. |
338 | */ | 345 | */ |
339 | struct KeyCacheEntry { | 346 | struct KeyCacheEntry |
347 | { | ||
340 | /** | 348 | /** |
341 | * Kept in a DLL. | 349 | * Kept in a DLL. |
342 | */ | 350 | */ |
@@ -383,7 +391,8 @@ struct ReceiverAddress; | |||
383 | /** | 391 | /** |
384 | * Shared secret we generated for a particular sender or receiver. | 392 | * Shared secret we generated for a particular sender or receiver. |
385 | */ | 393 | */ |
386 | struct SharedSecret { | 394 | struct SharedSecret |
395 | { | ||
387 | /** | 396 | /** |
388 | * Kept in a DLL. | 397 | * Kept in a DLL. |
389 | */ | 398 | */ |
@@ -448,7 +457,8 @@ struct SharedSecret { | |||
448 | * Information we track per sender address we have recently been | 457 | * Information we track per sender address we have recently been |
449 | * in contact with (we decrypt messages from the sender). | 458 | * in contact with (we decrypt messages from the sender). |
450 | */ | 459 | */ |
451 | struct SenderAddress { | 460 | struct SenderAddress |
461 | { | ||
452 | /** | 462 | /** |
453 | * To whom are we talking to. | 463 | * To whom are we talking to. |
454 | */ | 464 | */ |
@@ -500,7 +510,8 @@ struct SenderAddress { | |||
500 | * Information we track per receiving address we have recently been | 510 | * Information we track per receiving address we have recently been |
501 | * in contact with (encryption to receiver). | 511 | * in contact with (encryption to receiver). |
502 | */ | 512 | */ |
503 | struct ReceiverAddress { | 513 | struct ReceiverAddress |
514 | { | ||
504 | /** | 515 | /** |
505 | * To whom are we talking to. | 516 | * To whom are we talking to. |
506 | */ | 517 | */ |
@@ -578,7 +589,8 @@ struct ReceiverAddress { | |||
578 | /** | 589 | /** |
579 | * Interface we broadcast our presence on. | 590 | * Interface we broadcast our presence on. |
580 | */ | 591 | */ |
581 | struct BroadcastInterface { | 592 | struct BroadcastInterface |
593 | { | ||
582 | /** | 594 | /** |
583 | * Kept in a DLL. | 595 | * Kept in a DLL. |
584 | */ | 596 | */ |
@@ -739,25 +751,25 @@ static uint16_t my_port; | |||
739 | * @param bi entity to close down | 751 | * @param bi entity to close down |
740 | */ | 752 | */ |
741 | static void | 753 | static void |
742 | bi_destroy(struct BroadcastInterface *bi) | 754 | bi_destroy (struct BroadcastInterface *bi) |
743 | { | 755 | { |
744 | if (AF_INET6 == bi->sa->sa_family) | 756 | if (AF_INET6 == bi->sa->sa_family) |
757 | { | ||
758 | /* Leave the multicast group */ | ||
759 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | ||
760 | IPPROTO_IPV6, | ||
761 | IPV6_LEAVE_GROUP, | ||
762 | &bi->mcreq, | ||
763 | sizeof(bi->mcreq))) | ||
745 | { | 764 | { |
746 | /* Leave the multicast group */ | 765 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
747 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, | ||
748 | IPPROTO_IPV6, | ||
749 | IPV6_LEAVE_GROUP, | ||
750 | &bi->mcreq, | ||
751 | sizeof(bi->mcreq))) | ||
752 | { | ||
753 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | ||
754 | } | ||
755 | } | 766 | } |
756 | GNUNET_CONTAINER_DLL_remove(bi_head, bi_tail, bi); | 767 | } |
757 | GNUNET_SCHEDULER_cancel(bi->broadcast_task); | 768 | GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi); |
758 | GNUNET_free(bi->sa); | 769 | GNUNET_SCHEDULER_cancel (bi->broadcast_task); |
759 | GNUNET_free_non_null(bi->ba); | 770 | GNUNET_free (bi->sa); |
760 | GNUNET_free(bi); | 771 | GNUNET_free_non_null (bi->ba); |
772 | GNUNET_free (bi); | ||
761 | } | 773 | } |
762 | 774 | ||
763 | 775 | ||
@@ -767,35 +779,35 @@ bi_destroy(struct BroadcastInterface *bi) | |||
767 | * @param receiver entity to close down | 779 | * @param receiver entity to close down |
768 | */ | 780 | */ |
769 | static void | 781 | static void |
770 | receiver_destroy(struct ReceiverAddress *receiver) | 782 | receiver_destroy (struct ReceiverAddress *receiver) |
771 | { | 783 | { |
772 | struct GNUNET_MQ_Handle *mq; | 784 | struct GNUNET_MQ_Handle *mq; |
773 | 785 | ||
774 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
775 | "Disconnecting receiver for peer `%s'\n", | 787 | "Disconnecting receiver for peer `%s'\n", |
776 | GNUNET_i2s(&receiver->target)); | 788 | GNUNET_i2s (&receiver->target)); |
777 | if (NULL != (mq = receiver->mq)) | 789 | if (NULL != (mq = receiver->mq)) |
778 | { | 790 | { |
779 | receiver->mq = NULL; | 791 | receiver->mq = NULL; |
780 | GNUNET_MQ_destroy(mq); | 792 | GNUNET_MQ_destroy (mq); |
781 | } | 793 | } |
782 | if (NULL != receiver->qh) | 794 | if (NULL != receiver->qh) |
783 | { | 795 | { |
784 | GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); | 796 | GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); |
785 | receiver->qh = NULL; | 797 | receiver->qh = NULL; |
786 | } | 798 | } |
787 | GNUNET_assert(GNUNET_YES == | 799 | GNUNET_assert (GNUNET_YES == |
788 | GNUNET_CONTAINER_multipeermap_remove(receivers, | 800 | GNUNET_CONTAINER_multipeermap_remove (receivers, |
789 | &receiver->target, | 801 | &receiver->target, |
790 | receiver)); | 802 | receiver)); |
791 | GNUNET_assert(receiver == GNUNET_CONTAINER_heap_remove_node(receiver->hn)); | 803 | GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn)); |
792 | GNUNET_STATISTICS_set(stats, | 804 | GNUNET_STATISTICS_set (stats, |
793 | "# receivers active", | 805 | "# receivers active", |
794 | GNUNET_CONTAINER_multipeermap_size(receivers), | 806 | GNUNET_CONTAINER_multipeermap_size (receivers), |
795 | GNUNET_NO); | 807 | GNUNET_NO); |
796 | GNUNET_free(receiver->address); | 808 | GNUNET_free (receiver->address); |
797 | GNUNET_free(receiver->foreign_addr); | 809 | GNUNET_free (receiver->foreign_addr); |
798 | GNUNET_free(receiver); | 810 | GNUNET_free (receiver); |
799 | } | 811 | } |
800 | 812 | ||
801 | 813 | ||
@@ -805,16 +817,16 @@ receiver_destroy(struct ReceiverAddress *receiver) | |||
805 | * @param kce the key cache entry | 817 | * @param kce the key cache entry |
806 | */ | 818 | */ |
807 | static void | 819 | static void |
808 | kce_destroy(struct KeyCacheEntry *kce) | 820 | kce_destroy (struct KeyCacheEntry *kce) |
809 | { | 821 | { |
810 | struct SharedSecret *ss = kce->ss; | 822 | struct SharedSecret *ss = kce->ss; |
811 | 823 | ||
812 | ss->active_kce_count--; | 824 | ss->active_kce_count--; |
813 | GNUNET_CONTAINER_DLL_remove(ss->kce_head, ss->kce_tail, kce); | 825 | GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce); |
814 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove(key_cache, | 826 | GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache, |
815 | &kce->kid, | 827 | &kce->kid, |
816 | kce)); | 828 | kce)); |
817 | GNUNET_free(kce); | 829 | GNUNET_free (kce); |
818 | } | 830 | } |
819 | 831 | ||
820 | 832 | ||
@@ -826,24 +838,24 @@ kce_destroy(struct KeyCacheEntry *kce) | |||
826 | * @param kid[out] where to write the key ID | 838 | * @param kid[out] where to write the key ID |
827 | */ | 839 | */ |
828 | static void | 840 | static void |
829 | get_kid(const struct GNUNET_HashCode *msec, | 841 | get_kid (const struct GNUNET_HashCode *msec, |
830 | uint32_t serial, | 842 | uint32_t serial, |
831 | struct GNUNET_ShortHashCode *kid) | 843 | struct GNUNET_ShortHashCode *kid) |
832 | { | 844 | { |
833 | uint32_t sid = htonl(serial); | 845 | uint32_t sid = htonl (serial); |
834 | 846 | ||
835 | GNUNET_CRYPTO_hkdf(kid, | 847 | GNUNET_CRYPTO_hkdf (kid, |
836 | sizeof(*kid), | 848 | sizeof(*kid), |
837 | GCRY_MD_SHA512, | 849 | GCRY_MD_SHA512, |
838 | GCRY_MD_SHA256, | 850 | GCRY_MD_SHA256, |
839 | &sid, | 851 | &sid, |
840 | sizeof(sid), | 852 | sizeof(sid), |
841 | msec, | 853 | msec, |
842 | sizeof(*msec), | 854 | sizeof(*msec), |
843 | "UDP-KID", | 855 | "UDP-KID", |
844 | strlen("UDP-KID"), | 856 | strlen ("UDP-KID"), |
845 | NULL, | 857 | NULL, |
846 | 0); | 858 | 0); |
847 | } | 859 | } |
848 | 860 | ||
849 | 861 | ||
@@ -854,26 +866,26 @@ get_kid(const struct GNUNET_HashCode *msec, | |||
854 | * @param seq sequence number for the key cache entry | 866 | * @param seq sequence number for the key cache entry |
855 | */ | 867 | */ |
856 | static void | 868 | static void |
857 | kce_generate(struct SharedSecret *ss, uint32_t seq) | 869 | kce_generate (struct SharedSecret *ss, uint32_t seq) |
858 | { | 870 | { |
859 | struct KeyCacheEntry *kce; | 871 | struct KeyCacheEntry *kce; |
860 | 872 | ||
861 | GNUNET_assert(0 < seq); | 873 | GNUNET_assert (0 < seq); |
862 | kce = GNUNET_new(struct KeyCacheEntry); | 874 | kce = GNUNET_new (struct KeyCacheEntry); |
863 | kce->ss = ss; | 875 | kce->ss = ss; |
864 | kce->sequence_number = seq; | 876 | kce->sequence_number = seq; |
865 | get_kid(&ss->master, seq, &kce->kid); | 877 | get_kid (&ss->master, seq, &kce->kid); |
866 | GNUNET_CONTAINER_DLL_insert(ss->kce_head, ss->kce_tail, kce); | 878 | GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce); |
867 | ss->active_kce_count++; | 879 | ss->active_kce_count++; |
868 | (void)GNUNET_CONTAINER_multishortmap_put( | 880 | (void) GNUNET_CONTAINER_multishortmap_put ( |
869 | key_cache, | 881 | key_cache, |
870 | &kce->kid, | 882 | &kce->kid, |
871 | kce, | 883 | kce, |
872 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 884 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
873 | GNUNET_STATISTICS_set(stats, | 885 | GNUNET_STATISTICS_set (stats, |
874 | "# KIDs active", | 886 | "# KIDs active", |
875 | GNUNET_CONTAINER_multishortmap_size(key_cache), | 887 | GNUNET_CONTAINER_multishortmap_size (key_cache), |
876 | GNUNET_NO); | 888 | GNUNET_NO); |
877 | } | 889 | } |
878 | 890 | ||
879 | 891 | ||
@@ -883,31 +895,31 @@ kce_generate(struct SharedSecret *ss, uint32_t seq) | |||
883 | * @param ss shared secret to destroy | 895 | * @param ss shared secret to destroy |
884 | */ | 896 | */ |
885 | static void | 897 | static void |
886 | secret_destroy(struct SharedSecret *ss) | 898 | secret_destroy (struct SharedSecret *ss) |
887 | { | 899 | { |
888 | struct SenderAddress *sender; | 900 | struct SenderAddress *sender; |
889 | struct ReceiverAddress *receiver; | 901 | struct ReceiverAddress *receiver; |
890 | struct KeyCacheEntry *kce; | 902 | struct KeyCacheEntry *kce; |
891 | 903 | ||
892 | if (NULL != (sender = ss->sender)) | 904 | if (NULL != (sender = ss->sender)) |
893 | { | 905 | { |
894 | GNUNET_CONTAINER_DLL_remove(sender->ss_head, sender->ss_tail, ss); | 906 | GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); |
895 | sender->num_secrets--; | 907 | sender->num_secrets--; |
896 | } | 908 | } |
897 | if (NULL != (receiver = ss->receiver)) | 909 | if (NULL != (receiver = ss->receiver)) |
898 | { | 910 | { |
899 | GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss); | 911 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); |
900 | receiver->num_secrets--; | 912 | receiver->num_secrets--; |
901 | receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); | 913 | receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); |
902 | } | 914 | } |
903 | while (NULL != (kce = ss->kce_head)) | 915 | while (NULL != (kce = ss->kce_head)) |
904 | kce_destroy(kce); | 916 | kce_destroy (kce); |
905 | GNUNET_STATISTICS_update(stats, "# Secrets active", -1, GNUNET_NO); | 917 | GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO); |
906 | GNUNET_STATISTICS_set(stats, | 918 | GNUNET_STATISTICS_set (stats, |
907 | "# KIDs active", | 919 | "# KIDs active", |
908 | GNUNET_CONTAINER_multishortmap_size(key_cache), | 920 | GNUNET_CONTAINER_multishortmap_size (key_cache), |
909 | GNUNET_NO); | 921 | GNUNET_NO); |
910 | GNUNET_free(ss); | 922 | GNUNET_free (ss); |
911 | } | 923 | } |
912 | 924 | ||
913 | 925 | ||
@@ -918,18 +930,18 @@ secret_destroy(struct SharedSecret *ss) | |||
918 | * @param sender entity to close down | 930 | * @param sender entity to close down |
919 | */ | 931 | */ |
920 | static void | 932 | static void |
921 | sender_destroy(struct SenderAddress *sender) | 933 | sender_destroy (struct SenderAddress *sender) |
922 | { | 934 | { |
923 | GNUNET_assert( | 935 | GNUNET_assert ( |
924 | GNUNET_YES == | 936 | GNUNET_YES == |
925 | GNUNET_CONTAINER_multipeermap_remove(senders, &sender->target, sender)); | 937 | GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender)); |
926 | GNUNET_assert(sender == GNUNET_CONTAINER_heap_remove_node(sender->hn)); | 938 | GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn)); |
927 | GNUNET_STATISTICS_set(stats, | 939 | GNUNET_STATISTICS_set (stats, |
928 | "# senders active", | 940 | "# senders active", |
929 | GNUNET_CONTAINER_multipeermap_size(senders), | 941 | GNUNET_CONTAINER_multipeermap_size (senders), |
930 | GNUNET_NO); | 942 | GNUNET_NO); |
931 | GNUNET_free(sender->address); | 943 | GNUNET_free (sender->address); |
932 | GNUNET_free(sender); | 944 | GNUNET_free (sender); |
933 | } | 945 | } |
934 | 946 | ||
935 | 947 | ||
@@ -942,28 +954,28 @@ sender_destroy(struct SenderAddress *sender) | |||
942 | * @param iv[out] where to write the IV | 954 | * @param iv[out] where to write the IV |
943 | */ | 955 | */ |
944 | static void | 956 | static void |
945 | get_iv_key(const struct GNUNET_HashCode *msec, | 957 | get_iv_key (const struct GNUNET_HashCode *msec, |
946 | uint32_t serial, | 958 | uint32_t serial, |
947 | char key[AES_KEY_SIZE], | 959 | char key[AES_KEY_SIZE], |
948 | char iv[AES_IV_SIZE]) | 960 | char iv[AES_IV_SIZE]) |
949 | { | 961 | { |
950 | uint32_t sid = htonl(serial); | 962 | uint32_t sid = htonl (serial); |
951 | char res[AES_KEY_SIZE + AES_IV_SIZE]; | 963 | char res[AES_KEY_SIZE + AES_IV_SIZE]; |
952 | 964 | ||
953 | GNUNET_CRYPTO_hkdf(res, | 965 | GNUNET_CRYPTO_hkdf (res, |
954 | sizeof(res), | 966 | sizeof(res), |
955 | GCRY_MD_SHA512, | 967 | GCRY_MD_SHA512, |
956 | GCRY_MD_SHA256, | 968 | GCRY_MD_SHA256, |
957 | &sid, | 969 | &sid, |
958 | sizeof(sid), | 970 | sizeof(sid), |
959 | msec, | 971 | msec, |
960 | sizeof(*msec), | 972 | sizeof(*msec), |
961 | "UDP-IV-KEY", | 973 | "UDP-IV-KEY", |
962 | strlen("UDP-IV-KEY"), | 974 | strlen ("UDP-IV-KEY"), |
963 | NULL, | 975 | NULL, |
964 | 0); | 976 | 0); |
965 | memcpy(key, res, AES_KEY_SIZE); | 977 | memcpy (key, res, AES_KEY_SIZE); |
966 | memcpy(iv, &res[AES_KEY_SIZE], AES_IV_SIZE); | 978 | memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE); |
967 | } | 979 | } |
968 | 980 | ||
969 | 981 | ||
@@ -973,11 +985,11 @@ get_iv_key(const struct GNUNET_HashCode *msec, | |||
973 | * @param sender address for which the timeout should be rescheduled | 985 | * @param sender address for which the timeout should be rescheduled |
974 | */ | 986 | */ |
975 | static void | 987 | static void |
976 | reschedule_sender_timeout(struct SenderAddress *sender) | 988 | reschedule_sender_timeout (struct SenderAddress *sender) |
977 | { | 989 | { |
978 | sender->timeout = | 990 | sender->timeout = |
979 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 991 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
980 | GNUNET_CONTAINER_heap_update_cost(sender->hn, sender->timeout.abs_value_us); | 992 | GNUNET_CONTAINER_heap_update_cost (sender->hn, sender->timeout.abs_value_us); |
981 | } | 993 | } |
982 | 994 | ||
983 | 995 | ||
@@ -987,12 +999,12 @@ reschedule_sender_timeout(struct SenderAddress *sender) | |||
987 | * @param receiver address for which the timeout should be rescheduled | 999 | * @param receiver address for which the timeout should be rescheduled |
988 | */ | 1000 | */ |
989 | static void | 1001 | static void |
990 | reschedule_receiver_timeout(struct ReceiverAddress *receiver) | 1002 | reschedule_receiver_timeout (struct ReceiverAddress *receiver) |
991 | { | 1003 | { |
992 | receiver->timeout = | 1004 | receiver->timeout = |
993 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1005 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
994 | GNUNET_CONTAINER_heap_update_cost(receiver->hn, | 1006 | GNUNET_CONTAINER_heap_update_cost (receiver->hn, |
995 | receiver->timeout.abs_value_us); | 1007 | receiver->timeout.abs_value_us); |
996 | } | 1008 | } |
997 | 1009 | ||
998 | 1010 | ||
@@ -1002,7 +1014,7 @@ reschedule_receiver_timeout(struct ReceiverAddress *receiver) | |||
1002 | * @param cls unused, NULL | 1014 | * @param cls unused, NULL |
1003 | */ | 1015 | */ |
1004 | static void | 1016 | static void |
1005 | check_timeouts(void *cls) | 1017 | check_timeouts (void *cls) |
1006 | { | 1018 | { |
1007 | struct GNUNET_TIME_Relative st; | 1019 | struct GNUNET_TIME_Relative st; |
1008 | struct GNUNET_TIME_Relative rt; | 1020 | struct GNUNET_TIME_Relative rt; |
@@ -1010,27 +1022,27 @@ check_timeouts(void *cls) | |||
1010 | struct ReceiverAddress *receiver; | 1022 | struct ReceiverAddress *receiver; |
1011 | struct SenderAddress *sender; | 1023 | struct SenderAddress *sender; |
1012 | 1024 | ||
1013 | (void)cls; | 1025 | (void) cls; |
1014 | timeout_task = NULL; | 1026 | timeout_task = NULL; |
1015 | rt = GNUNET_TIME_UNIT_FOREVER_REL; | 1027 | rt = GNUNET_TIME_UNIT_FOREVER_REL; |
1016 | while (NULL != (receiver = GNUNET_CONTAINER_heap_peek(receivers_heap))) | 1028 | while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap))) |
1017 | { | 1029 | { |
1018 | rt = GNUNET_TIME_absolute_get_remaining(receiver->timeout); | 1030 | rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); |
1019 | if (0 != rt.rel_value_us) | 1031 | if (0 != rt.rel_value_us) |
1020 | break; | 1032 | break; |
1021 | receiver_destroy(receiver); | 1033 | receiver_destroy (receiver); |
1022 | } | 1034 | } |
1023 | st = GNUNET_TIME_UNIT_FOREVER_REL; | 1035 | st = GNUNET_TIME_UNIT_FOREVER_REL; |
1024 | while (NULL != (sender = GNUNET_CONTAINER_heap_peek(senders_heap))) | 1036 | while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap))) |
1025 | { | 1037 | { |
1026 | st = GNUNET_TIME_absolute_get_remaining(sender->timeout); | 1038 | st = GNUNET_TIME_absolute_get_remaining (sender->timeout); |
1027 | if (0 != st.rel_value_us) | 1039 | if (0 != st.rel_value_us) |
1028 | break; | 1040 | break; |
1029 | sender_destroy(sender); | 1041 | sender_destroy (sender); |
1030 | } | 1042 | } |
1031 | delay = GNUNET_TIME_relative_min(rt, st); | 1043 | delay = GNUNET_TIME_relative_min (rt, st); |
1032 | if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) | 1044 | if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) |
1033 | timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &check_timeouts, NULL); | 1045 | timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL); |
1034 | } | 1046 | } |
1035 | 1047 | ||
1036 | 1048 | ||
@@ -1040,20 +1052,20 @@ check_timeouts(void *cls) | |||
1040 | * @param ss[in,out] data structure to complete | 1052 | * @param ss[in,out] data structure to complete |
1041 | */ | 1053 | */ |
1042 | static void | 1054 | static void |
1043 | calculate_cmac(struct SharedSecret *ss) | 1055 | calculate_cmac (struct SharedSecret *ss) |
1044 | { | 1056 | { |
1045 | GNUNET_CRYPTO_hkdf(&ss->cmac, | 1057 | GNUNET_CRYPTO_hkdf (&ss->cmac, |
1046 | sizeof(ss->cmac), | 1058 | sizeof(ss->cmac), |
1047 | GCRY_MD_SHA512, | 1059 | GCRY_MD_SHA512, |
1048 | GCRY_MD_SHA256, | 1060 | GCRY_MD_SHA256, |
1049 | "CMAC", | 1061 | "CMAC", |
1050 | strlen("CMAC"), | 1062 | strlen ("CMAC"), |
1051 | &ss->master, | 1063 | &ss->master, |
1052 | sizeof(ss->master), | 1064 | sizeof(ss->master), |
1053 | "UDP-CMAC", | 1065 | "UDP-CMAC", |
1054 | strlen("UDP-CMAC"), | 1066 | strlen ("UDP-CMAC"), |
1055 | NULL, | 1067 | NULL, |
1056 | 0); | 1068 | 0); |
1057 | } | 1069 | } |
1058 | 1070 | ||
1059 | 1071 | ||
@@ -1066,36 +1078,36 @@ calculate_cmac(struct SharedSecret *ss) | |||
1066 | * @param plaintext_len number of bytes of plaintext received | 1078 | * @param plaintext_len number of bytes of plaintext received |
1067 | */ | 1079 | */ |
1068 | static void | 1080 | static void |
1069 | pass_plaintext_to_core(struct SenderAddress *sender, | 1081 | pass_plaintext_to_core (struct SenderAddress *sender, |
1070 | const void *plaintext, | 1082 | const void *plaintext, |
1071 | size_t plaintext_len) | 1083 | size_t plaintext_len) |
1072 | { | 1084 | { |
1073 | const struct GNUNET_MessageHeader *hdr = plaintext; | 1085 | const struct GNUNET_MessageHeader *hdr = plaintext; |
1074 | 1086 | ||
1075 | while (ntohs(hdr->size) < plaintext_len) | 1087 | while (ntohs (hdr->size) < plaintext_len) |
1076 | { | 1088 | { |
1077 | GNUNET_STATISTICS_update(stats, | 1089 | GNUNET_STATISTICS_update (stats, |
1078 | "# bytes given to core", | 1090 | "# bytes given to core", |
1079 | ntohs(hdr->size), | 1091 | ntohs (hdr->size), |
1080 | GNUNET_NO); | 1092 | GNUNET_NO); |
1081 | (void) | 1093 | (void) |
1082 | GNUNET_TRANSPORT_communicator_receive(ch, | 1094 | GNUNET_TRANSPORT_communicator_receive (ch, |
1083 | &sender->target, | 1095 | &sender->target, |
1084 | hdr, | 1096 | hdr, |
1085 | ADDRESS_VALIDITY_PERIOD, | 1097 | ADDRESS_VALIDITY_PERIOD, |
1086 | NULL /* no flow control possible */ | 1098 | NULL /* no flow control possible */ |
1087 | , | 1099 | , |
1088 | NULL); | 1100 | NULL); |
1089 | /* move on to next message, if any */ | 1101 | /* move on to next message, if any */ |
1090 | plaintext_len -= ntohs(hdr->size); | 1102 | plaintext_len -= ntohs (hdr->size); |
1091 | if (plaintext_len < sizeof(*hdr)) | 1103 | if (plaintext_len < sizeof(*hdr)) |
1092 | break; | 1104 | break; |
1093 | hdr = plaintext + ntohs(hdr->size); | 1105 | hdr = plaintext + ntohs (hdr->size); |
1094 | } | 1106 | } |
1095 | GNUNET_STATISTICS_update(stats, | 1107 | GNUNET_STATISTICS_update (stats, |
1096 | "# bytes padding discarded", | 1108 | "# bytes padding discarded", |
1097 | plaintext_len, | 1109 | plaintext_len, |
1098 | GNUNET_NO); | 1110 | GNUNET_NO); |
1099 | } | 1111 | } |
1100 | 1112 | ||
1101 | 1113 | ||
@@ -1108,20 +1120,20 @@ pass_plaintext_to_core(struct SenderAddress *sender, | |||
1108 | * @param cipher[out] cipher to initialize | 1120 | * @param cipher[out] cipher to initialize |
1109 | */ | 1121 | */ |
1110 | static void | 1122 | static void |
1111 | setup_cipher(const struct GNUNET_HashCode *msec, | 1123 | setup_cipher (const struct GNUNET_HashCode *msec, |
1112 | uint32_t serial, | 1124 | uint32_t serial, |
1113 | gcry_cipher_hd_t *cipher) | 1125 | gcry_cipher_hd_t *cipher) |
1114 | { | 1126 | { |
1115 | char key[AES_KEY_SIZE]; | 1127 | char key[AES_KEY_SIZE]; |
1116 | char iv[AES_IV_SIZE]; | 1128 | char iv[AES_IV_SIZE]; |
1117 | 1129 | ||
1118 | gcry_cipher_open(cipher, | 1130 | gcry_cipher_open (cipher, |
1119 | GCRY_CIPHER_AES256 /* low level: go for speed */, | 1131 | GCRY_CIPHER_AES256 /* low level: go for speed */, |
1120 | GCRY_CIPHER_MODE_GCM, | 1132 | GCRY_CIPHER_MODE_GCM, |
1121 | 0 /* flags */); | 1133 | 0 /* flags */); |
1122 | get_iv_key(msec, serial, key, iv); | 1134 | get_iv_key (msec, serial, key, iv); |
1123 | gcry_cipher_setkey(*cipher, key, sizeof(key)); | 1135 | gcry_cipher_setkey (*cipher, key, sizeof(key)); |
1124 | gcry_cipher_setiv(*cipher, iv, sizeof(iv)); | 1136 | gcry_cipher_setiv (*cipher, iv, sizeof(iv)); |
1125 | } | 1137 | } |
1126 | 1138 | ||
1127 | 1139 | ||
@@ -1138,29 +1150,29 @@ setup_cipher(const struct GNUNET_HashCode *msec, | |||
1138 | * @return #GNUNET_OK on success | 1150 | * @return #GNUNET_OK on success |
1139 | */ | 1151 | */ |
1140 | static int | 1152 | static int |
1141 | try_decrypt(const struct SharedSecret *ss, | 1153 | try_decrypt (const struct SharedSecret *ss, |
1142 | const char tag[GCM_TAG_SIZE], | 1154 | const char tag[GCM_TAG_SIZE], |
1143 | uint32_t serial, | 1155 | uint32_t serial, |
1144 | const char *in_buf, | 1156 | const char *in_buf, |
1145 | size_t in_buf_size, | 1157 | size_t in_buf_size, |
1146 | char *out_buf) | 1158 | char *out_buf) |
1147 | { | 1159 | { |
1148 | gcry_cipher_hd_t cipher; | 1160 | gcry_cipher_hd_t cipher; |
1149 | 1161 | ||
1150 | setup_cipher(&ss->master, serial, &cipher); | 1162 | setup_cipher (&ss->master, serial, &cipher); |
1151 | GNUNET_assert( | 1163 | GNUNET_assert ( |
1152 | 0 == | 1164 | 0 == |
1153 | gcry_cipher_decrypt(cipher, out_buf, in_buf_size, in_buf, in_buf_size)); | 1165 | gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size)); |
1154 | if (0 != gcry_cipher_checktag(cipher, tag, GCM_TAG_SIZE)) | 1166 | if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE)) |
1155 | { | 1167 | { |
1156 | gcry_cipher_close(cipher); | 1168 | gcry_cipher_close (cipher); |
1157 | GNUNET_STATISTICS_update(stats, | 1169 | GNUNET_STATISTICS_update (stats, |
1158 | "# AEAD authentication failures", | 1170 | "# AEAD authentication failures", |
1159 | 1, | 1171 | 1, |
1160 | GNUNET_NO); | 1172 | GNUNET_NO); |
1161 | return GNUNET_SYSERR; | 1173 | return GNUNET_SYSERR; |
1162 | } | 1174 | } |
1163 | gcry_cipher_close(cipher); | 1175 | gcry_cipher_close (cipher); |
1164 | return GNUNET_OK; | 1176 | return GNUNET_OK; |
1165 | } | 1177 | } |
1166 | 1178 | ||
@@ -1172,12 +1184,12 @@ try_decrypt(const struct SharedSecret *ss, | |||
1172 | * @return new shared secret | 1184 | * @return new shared secret |
1173 | */ | 1185 | */ |
1174 | static struct SharedSecret * | 1186 | static struct SharedSecret * |
1175 | setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) | 1187 | setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) |
1176 | { | 1188 | { |
1177 | struct SharedSecret *ss; | 1189 | struct SharedSecret *ss; |
1178 | 1190 | ||
1179 | ss = GNUNET_new(struct SharedSecret); | 1191 | ss = GNUNET_new (struct SharedSecret); |
1180 | GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &ss->master); | 1192 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master); |
1181 | return ss; | 1193 | return ss; |
1182 | } | 1194 | } |
1183 | 1195 | ||
@@ -1190,20 +1202,20 @@ setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) | |||
1190 | * @return new shared secret | 1202 | * @return new shared secret |
1191 | */ | 1203 | */ |
1192 | static struct SharedSecret * | 1204 | static struct SharedSecret * |
1193 | setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, | 1205 | setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, |
1194 | struct ReceiverAddress *receiver) | 1206 | struct ReceiverAddress *receiver) |
1195 | { | 1207 | { |
1196 | struct SharedSecret *ss; | 1208 | struct SharedSecret *ss; |
1197 | 1209 | ||
1198 | ss = GNUNET_new(struct SharedSecret); | 1210 | ss = GNUNET_new (struct SharedSecret); |
1199 | GNUNET_CRYPTO_ecdh_eddsa(ephemeral, | 1211 | GNUNET_CRYPTO_ecdh_eddsa (ephemeral, |
1200 | &receiver->target.public_key, | 1212 | &receiver->target.public_key, |
1201 | &ss->master); | 1213 | &ss->master); |
1202 | calculate_cmac(ss); | 1214 | calculate_cmac (ss); |
1203 | ss->receiver = receiver; | 1215 | ss->receiver = receiver; |
1204 | GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss); | 1216 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); |
1205 | receiver->num_secrets++; | 1217 | receiver->num_secrets++; |
1206 | GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); | 1218 | GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); |
1207 | return ss; | 1219 | return ss; |
1208 | } | 1220 | } |
1209 | 1221 | ||
@@ -1216,7 +1228,7 @@ setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, | |||
1216 | * @param receiver receiver to setup MQ for | 1228 | * @param receiver receiver to setup MQ for |
1217 | */ | 1229 | */ |
1218 | static void | 1230 | static void |
1219 | setup_receiver_mq(struct ReceiverAddress *receiver); | 1231 | setup_receiver_mq (struct ReceiverAddress *receiver); |
1220 | 1232 | ||
1221 | 1233 | ||
1222 | /** | 1234 | /** |
@@ -1230,36 +1242,36 @@ setup_receiver_mq(struct ReceiverAddress *receiver); | |||
1230 | * @return #GNUNET_YES to continue to iterate | 1242 | * @return #GNUNET_YES to continue to iterate |
1231 | */ | 1243 | */ |
1232 | static int | 1244 | static int |
1233 | handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | 1245 | handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
1234 | { | 1246 | { |
1235 | const struct UDPAck *ack = cls; | 1247 | const struct UDPAck *ack = cls; |
1236 | struct ReceiverAddress *receiver = value; | 1248 | struct ReceiverAddress *receiver = value; |
1237 | 1249 | ||
1238 | (void)pid; | 1250 | (void) pid; |
1239 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) | 1251 | for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) |
1252 | { | ||
1253 | if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) | ||
1240 | { | 1254 | { |
1241 | if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode))) | 1255 | uint32_t allowed; |
1256 | |||
1257 | allowed = ntohl (ack->sequence_max); | ||
1258 | |||
1259 | if (allowed > ss->sequence_allowed) | ||
1260 | { | ||
1261 | receiver->acks_available += (allowed - ss->sequence_allowed); | ||
1262 | if ((allowed - ss->sequence_allowed) == receiver->acks_available) | ||
1242 | { | 1263 | { |
1243 | uint32_t allowed; | 1264 | /* we just incremented from zero => MTU change! */ |
1244 | 1265 | setup_receiver_mq (receiver); | |
1245 | allowed = ntohl(ack->sequence_max); | ||
1246 | |||
1247 | if (allowed > ss->sequence_allowed) | ||
1248 | { | ||
1249 | receiver->acks_available += (allowed - ss->sequence_allowed); | ||
1250 | if ((allowed - ss->sequence_allowed) == receiver->acks_available) | ||
1251 | { | ||
1252 | /* we just incremented from zero => MTU change! */ | ||
1253 | setup_receiver_mq(receiver); | ||
1254 | } | ||
1255 | ss->sequence_allowed = allowed; | ||
1256 | /* move ss to head to avoid discarding it anytime soon! */ | ||
1257 | GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss); | ||
1258 | GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss); | ||
1259 | } | ||
1260 | return GNUNET_NO; | ||
1261 | } | 1266 | } |
1267 | ss->sequence_allowed = allowed; | ||
1268 | /* move ss to head to avoid discarding it anytime soon! */ | ||
1269 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); | ||
1270 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); | ||
1271 | } | ||
1272 | return GNUNET_NO; | ||
1262 | } | 1273 | } |
1274 | } | ||
1263 | return GNUNET_YES; | 1275 | return GNUNET_YES; |
1264 | } | 1276 | } |
1265 | 1277 | ||
@@ -1273,41 +1285,41 @@ handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
1273 | * @param buf_size number of bytes in @a buf | 1285 | * @param buf_size number of bytes in @a buf |
1274 | */ | 1286 | */ |
1275 | static void | 1287 | static void |
1276 | try_handle_plaintext(struct SenderAddress *sender, | 1288 | try_handle_plaintext (struct SenderAddress *sender, |
1277 | const void *buf, | 1289 | const void *buf, |
1278 | size_t buf_size) | 1290 | size_t buf_size) |
1279 | { | 1291 | { |
1280 | const struct GNUNET_MessageHeader *hdr = | 1292 | const struct GNUNET_MessageHeader *hdr = |
1281 | (const struct GNUNET_MessageHeader *)buf; | 1293 | (const struct GNUNET_MessageHeader *) buf; |
1282 | const struct UDPAck *ack = (const struct UDPAck *)buf; | 1294 | const struct UDPAck *ack = (const struct UDPAck *) buf; |
1283 | uint16_t type; | 1295 | uint16_t type; |
1284 | 1296 | ||
1285 | if (sizeof(*hdr) > buf_size) | 1297 | if (sizeof(*hdr) > buf_size) |
1286 | return; /* not even a header */ | 1298 | return; /* not even a header */ |
1287 | if (ntohs(hdr->size) > buf_size) | 1299 | if (ntohs (hdr->size) > buf_size) |
1288 | return; /* not even a header */ | 1300 | return; /* not even a header */ |
1289 | type = ntohs(hdr->type); | 1301 | type = ntohs (hdr->type); |
1290 | switch (type) | 1302 | switch (type) |
1291 | { | 1303 | { |
1292 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: | 1304 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: |
1293 | /* lookup master secret by 'cmac', then update sequence_max */ | 1305 | /* lookup master secret by 'cmac', then update sequence_max */ |
1294 | GNUNET_CONTAINER_multipeermap_get_multiple(receivers, | 1306 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, |
1295 | &sender->target, | 1307 | &sender->target, |
1296 | &handle_ack, | 1308 | &handle_ack, |
1297 | (void *)ack); | 1309 | (void *) ack); |
1298 | /* There could be more messages after the ACK, handle those as well */ | 1310 | /* There could be more messages after the ACK, handle those as well */ |
1299 | buf += ntohs(hdr->size); | 1311 | buf += ntohs (hdr->size); |
1300 | buf_size -= ntohs(hdr->size); | 1312 | buf_size -= ntohs (hdr->size); |
1301 | pass_plaintext_to_core(sender, buf, buf_size); | 1313 | pass_plaintext_to_core (sender, buf, buf_size); |
1302 | break; | 1314 | break; |
1303 | 1315 | ||
1304 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: | 1316 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: |
1305 | /* skip padding */ | 1317 | /* skip padding */ |
1306 | break; | 1318 | break; |
1307 | 1319 | ||
1308 | default: | 1320 | default: |
1309 | pass_plaintext_to_core(sender, buf, buf_size); | 1321 | pass_plaintext_to_core (sender, buf, buf_size); |
1310 | } | 1322 | } |
1311 | } | 1323 | } |
1312 | 1324 | ||
1313 | 1325 | ||
@@ -1320,29 +1332,29 @@ try_handle_plaintext(struct SenderAddress *sender, | |||
1320 | * @param ss shared secret to generate ACKs for | 1332 | * @param ss shared secret to generate ACKs for |
1321 | */ | 1333 | */ |
1322 | static void | 1334 | static void |
1323 | consider_ss_ack(struct SharedSecret *ss) | 1335 | consider_ss_ack (struct SharedSecret *ss) |
1324 | { | 1336 | { |
1325 | GNUNET_assert(NULL != ss->sender); | 1337 | GNUNET_assert (NULL != ss->sender); |
1326 | /* drop ancient KeyCacheEntries */ | 1338 | /* drop ancient KeyCacheEntries */ |
1327 | while ((NULL != ss->kce_head) && | 1339 | while ((NULL != ss->kce_head) && |
1328 | (MAX_SQN_DELTA < | 1340 | (MAX_SQN_DELTA < |
1329 | ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) | 1341 | ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) |
1330 | kce_destroy(ss->kce_tail); | 1342 | kce_destroy (ss->kce_tail); |
1331 | if (ss->active_kce_count < KCN_THRESHOLD) | 1343 | if (ss->active_kce_count < KCN_THRESHOLD) |
1332 | { | 1344 | { |
1333 | struct UDPAck ack; | 1345 | struct UDPAck ack; |
1334 | 1346 | ||
1335 | while (ss->active_kce_count < KCN_TARGET) | 1347 | while (ss->active_kce_count < KCN_TARGET) |
1336 | kce_generate(ss, ++ss->sequence_allowed); | 1348 | kce_generate (ss, ++ss->sequence_allowed); |
1337 | ack.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); | 1349 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); |
1338 | ack.header.size = htons(sizeof(ack)); | 1350 | ack.header.size = htons (sizeof(ack)); |
1339 | ack.sequence_max = htonl(ss->sequence_allowed); | 1351 | ack.sequence_max = htonl (ss->sequence_allowed); |
1340 | ack.cmac = ss->cmac; | 1352 | ack.cmac = ss->cmac; |
1341 | GNUNET_TRANSPORT_communicator_notify(ch, | 1353 | GNUNET_TRANSPORT_communicator_notify (ch, |
1342 | &ss->sender->target, | 1354 | &ss->sender->target, |
1343 | COMMUNICATOR_ADDRESS_PREFIX, | 1355 | COMMUNICATOR_ADDRESS_PREFIX, |
1344 | &ack.header); | 1356 | &ack.header); |
1345 | } | 1357 | } |
1346 | } | 1358 | } |
1347 | 1359 | ||
1348 | 1360 | ||
@@ -1354,42 +1366,43 @@ consider_ss_ack(struct SharedSecret *ss) | |||
1354 | * @param kce key index to decrypt @a box | 1366 | * @param kce key index to decrypt @a box |
1355 | */ | 1367 | */ |
1356 | static void | 1368 | static void |
1357 | decrypt_box(const struct UDPBox *box, | 1369 | decrypt_box (const struct UDPBox *box, |
1358 | size_t box_len, | 1370 | size_t box_len, |
1359 | struct KeyCacheEntry *kce) | 1371 | struct KeyCacheEntry *kce) |
1360 | { | 1372 | { |
1361 | struct SharedSecret *ss = kce->ss; | 1373 | struct SharedSecret *ss = kce->ss; |
1362 | char out_buf[box_len - sizeof(*box)]; | 1374 | char out_buf[box_len - sizeof(*box)]; |
1363 | 1375 | ||
1364 | GNUNET_assert(NULL != ss->sender); | 1376 | GNUNET_assert (NULL != ss->sender); |
1365 | if (GNUNET_OK != try_decrypt(ss, | 1377 | if (GNUNET_OK != try_decrypt (ss, |
1366 | box->gcm_tag, | 1378 | box->gcm_tag, |
1367 | kce->sequence_number, | 1379 | kce->sequence_number, |
1368 | (const char *)&box[1], | 1380 | (const char *) &box[1], |
1369 | sizeof(out_buf), | 1381 | sizeof(out_buf), |
1370 | out_buf)) | 1382 | out_buf)) |
1371 | { | 1383 | { |
1372 | GNUNET_STATISTICS_update(stats, | 1384 | GNUNET_STATISTICS_update (stats, |
1373 | "# Decryption failures with valid KCE", | 1385 | "# Decryption failures with valid KCE", |
1374 | 1, | 1386 | 1, |
1375 | GNUNET_NO); | 1387 | GNUNET_NO); |
1376 | kce_destroy(kce); | 1388 | kce_destroy (kce); |
1377 | return; | 1389 | return; |
1378 | } | 1390 | } |
1379 | kce_destroy(kce); | 1391 | kce_destroy (kce); |
1380 | GNUNET_STATISTICS_update(stats, | 1392 | GNUNET_STATISTICS_update (stats, |
1381 | "# bytes decrypted with BOX", | 1393 | "# bytes decrypted with BOX", |
1382 | sizeof(out_buf), | 1394 | sizeof(out_buf), |
1383 | GNUNET_NO); | 1395 | GNUNET_NO); |
1384 | try_handle_plaintext(ss->sender, out_buf, sizeof(out_buf)); | 1396 | try_handle_plaintext (ss->sender, out_buf, sizeof(out_buf)); |
1385 | consider_ss_ack(ss); | 1397 | consider_ss_ack (ss); |
1386 | } | 1398 | } |
1387 | 1399 | ||
1388 | 1400 | ||
1389 | /** | 1401 | /** |
1390 | * Closure for #find_sender_by_address() | 1402 | * Closure for #find_sender_by_address() |
1391 | */ | 1403 | */ |
1392 | struct SearchContext { | 1404 | struct SearchContext |
1405 | { | ||
1393 | /** | 1406 | /** |
1394 | * Address we are looking for. | 1407 | * Address we are looking for. |
1395 | */ | 1408 | */ |
@@ -1416,19 +1429,19 @@ struct SearchContext { | |||
1416 | * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found | 1429 | * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found |
1417 | */ | 1430 | */ |
1418 | static int | 1431 | static int |
1419 | find_sender_by_address(void *cls, | 1432 | find_sender_by_address (void *cls, |
1420 | const struct GNUNET_PeerIdentity *key, | 1433 | const struct GNUNET_PeerIdentity *key, |
1421 | void *value) | 1434 | void *value) |
1422 | { | 1435 | { |
1423 | struct SearchContext *sc = cls; | 1436 | struct SearchContext *sc = cls; |
1424 | struct SenderAddress *sender = value; | 1437 | struct SenderAddress *sender = value; |
1425 | 1438 | ||
1426 | if ((sender->address_len == sc->address_len) && | 1439 | if ((sender->address_len == sc->address_len) && |
1427 | (0 == memcmp(sender->address, sc->address, sender->address_len))) | 1440 | (0 == memcmp (sender->address, sc->address, sender->address_len))) |
1428 | { | 1441 | { |
1429 | sc->sender = sender; | 1442 | sc->sender = sender; |
1430 | return GNUNET_NO; /* stop iterating! */ | 1443 | return GNUNET_NO; /* stop iterating! */ |
1431 | } | 1444 | } |
1432 | return GNUNET_YES; | 1445 | return GNUNET_YES; |
1433 | } | 1446 | } |
1434 | 1447 | ||
@@ -1445,45 +1458,45 @@ find_sender_by_address(void *cls, | |||
1445 | * decrypting data from @a target | 1458 | * decrypting data from @a target |
1446 | */ | 1459 | */ |
1447 | static struct SenderAddress * | 1460 | static struct SenderAddress * |
1448 | setup_sender(const struct GNUNET_PeerIdentity *target, | 1461 | setup_sender (const struct GNUNET_PeerIdentity *target, |
1449 | const struct sockaddr *address, | 1462 | const struct sockaddr *address, |
1450 | socklen_t address_len) | 1463 | socklen_t address_len) |
1451 | { | 1464 | { |
1452 | struct SenderAddress *sender; | 1465 | struct SenderAddress *sender; |
1453 | struct SearchContext sc = { .address = address, | 1466 | struct SearchContext sc = { .address = address, |
1454 | .address_len = address_len, | 1467 | .address_len = address_len, |
1455 | .sender = NULL }; | 1468 | .sender = NULL }; |
1456 | 1469 | ||
1457 | GNUNET_CONTAINER_multipeermap_get_multiple(senders, | 1470 | GNUNET_CONTAINER_multipeermap_get_multiple (senders, |
1458 | target, | 1471 | target, |
1459 | &find_sender_by_address, | 1472 | &find_sender_by_address, |
1460 | &sc); | 1473 | &sc); |
1461 | if (NULL != sc.sender) | 1474 | if (NULL != sc.sender) |
1462 | { | 1475 | { |
1463 | reschedule_sender_timeout(sc.sender); | 1476 | reschedule_sender_timeout (sc.sender); |
1464 | return sc.sender; | 1477 | return sc.sender; |
1465 | } | 1478 | } |
1466 | sender = GNUNET_new(struct SenderAddress); | 1479 | sender = GNUNET_new (struct SenderAddress); |
1467 | sender->target = *target; | 1480 | sender->target = *target; |
1468 | sender->address = GNUNET_memdup(address, address_len); | 1481 | sender->address = GNUNET_memdup (address, address_len); |
1469 | sender->address_len = address_len; | 1482 | sender->address_len = address_len; |
1470 | (void)GNUNET_CONTAINER_multipeermap_put( | 1483 | (void) GNUNET_CONTAINER_multipeermap_put ( |
1471 | senders, | 1484 | senders, |
1472 | &sender->target, | 1485 | &sender->target, |
1473 | sender, | 1486 | sender, |
1474 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1487 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1475 | GNUNET_STATISTICS_set(stats, | 1488 | GNUNET_STATISTICS_set (stats, |
1476 | "# senders active", | 1489 | "# senders active", |
1477 | GNUNET_CONTAINER_multipeermap_size(receivers), | 1490 | GNUNET_CONTAINER_multipeermap_size (receivers), |
1478 | GNUNET_NO); | 1491 | GNUNET_NO); |
1479 | sender->timeout = | 1492 | sender->timeout = |
1480 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1493 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1481 | sender->hn = GNUNET_CONTAINER_heap_insert(senders_heap, | 1494 | sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, |
1482 | sender, | 1495 | sender, |
1483 | sender->timeout.abs_value_us); | 1496 | sender->timeout.abs_value_us); |
1484 | sender->nt = GNUNET_NT_scanner_get_type(is, address, address_len); | 1497 | sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len); |
1485 | if (NULL == timeout_task) | 1498 | if (NULL == timeout_task) |
1486 | timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); | 1499 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); |
1487 | return sender; | 1500 | return sender; |
1488 | } | 1501 | } |
1489 | 1502 | ||
@@ -1496,21 +1509,22 @@ setup_sender(const struct GNUNET_PeerIdentity *target, | |||
1496 | * @return #GNUNET_OK if signature is valid | 1509 | * @return #GNUNET_OK if signature is valid |
1497 | */ | 1510 | */ |
1498 | static int | 1511 | static int |
1499 | verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | 1512 | verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, |
1500 | const struct UDPConfirmation *uc) | 1513 | const struct UDPConfirmation *uc) |
1501 | { | 1514 | { |
1502 | struct UdpHandshakeSignature uhs; | 1515 | struct UdpHandshakeSignature uhs; |
1503 | 1516 | ||
1504 | uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); | 1517 | uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); |
1505 | uhs.purpose.size = htonl(sizeof(uhs)); | 1518 | uhs.purpose.size = htonl (sizeof(uhs)); |
1506 | uhs.sender = uc->sender; | 1519 | uhs.sender = uc->sender; |
1507 | uhs.receiver = my_identity; | 1520 | uhs.receiver = my_identity; |
1508 | uhs.ephemeral = *ephemeral; | 1521 | uhs.ephemeral = *ephemeral; |
1509 | uhs.monotonic_time = uc->monotonic_time; | 1522 | uhs.monotonic_time = uc->monotonic_time; |
1510 | return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, | 1523 | return GNUNET_CRYPTO_eddsa_verify ( |
1511 | &uhs.purpose, | 1524 | GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, |
1512 | &uc->sender_sig, | 1525 | &uhs.purpose, |
1513 | &uc->sender.public_key); | 1526 | &uc->sender_sig, |
1527 | &uc->sender.public_key); | ||
1514 | } | 1528 | } |
1515 | 1529 | ||
1516 | 1530 | ||
@@ -1523,30 +1537,30 @@ verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | |||
1523 | * @return string representation of @a address | 1537 | * @return string representation of @a address |
1524 | */ | 1538 | */ |
1525 | static char * | 1539 | static char * |
1526 | sockaddr_to_udpaddr_string(const struct sockaddr *address, | 1540 | sockaddr_to_udpaddr_string (const struct sockaddr *address, |
1527 | socklen_t address_len) | 1541 | socklen_t address_len) |
1528 | { | 1542 | { |
1529 | char *ret; | 1543 | char *ret; |
1530 | 1544 | ||
1531 | switch (address->sa_family) | 1545 | switch (address->sa_family) |
1532 | { | 1546 | { |
1533 | case AF_INET: | 1547 | case AF_INET: |
1534 | GNUNET_asprintf(&ret, | 1548 | GNUNET_asprintf (&ret, |
1535 | "%s-%s", | 1549 | "%s-%s", |
1536 | COMMUNICATOR_ADDRESS_PREFIX, | 1550 | COMMUNICATOR_ADDRESS_PREFIX, |
1537 | GNUNET_a2s(address, address_len)); | 1551 | GNUNET_a2s (address, address_len)); |
1538 | break; | 1552 | break; |
1539 | 1553 | ||
1540 | case AF_INET6: | 1554 | case AF_INET6: |
1541 | GNUNET_asprintf(&ret, | 1555 | GNUNET_asprintf (&ret, |
1542 | "%s-%s", | 1556 | "%s-%s", |
1543 | COMMUNICATOR_ADDRESS_PREFIX, | 1557 | COMMUNICATOR_ADDRESS_PREFIX, |
1544 | GNUNET_a2s(address, address_len)); | 1558 | GNUNET_a2s (address, address_len)); |
1545 | break; | 1559 | break; |
1546 | 1560 | ||
1547 | default: | 1561 | default: |
1548 | GNUNET_assert(0); | 1562 | GNUNET_assert (0); |
1549 | } | 1563 | } |
1550 | return ret; | 1564 | return ret; |
1551 | } | 1565 | } |
1552 | 1566 | ||
@@ -1557,87 +1571,87 @@ sockaddr_to_udpaddr_string(const struct sockaddr *address, | |||
1557 | * @param cls NULL | 1571 | * @param cls NULL |
1558 | */ | 1572 | */ |
1559 | static void | 1573 | static void |
1560 | sock_read(void *cls) | 1574 | sock_read (void *cls) |
1561 | { | 1575 | { |
1562 | struct sockaddr_storage sa; | 1576 | struct sockaddr_storage sa; |
1563 | socklen_t salen = sizeof(sa); | 1577 | socklen_t salen = sizeof(sa); |
1564 | char buf[UINT16_MAX]; | 1578 | char buf[UINT16_MAX]; |
1565 | ssize_t rcvd; | 1579 | ssize_t rcvd; |
1566 | 1580 | ||
1567 | (void)cls; | 1581 | (void) cls; |
1568 | read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 1582 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1569 | udp_sock, | 1583 | udp_sock, |
1570 | &sock_read, | 1584 | &sock_read, |
1571 | NULL); | 1585 | NULL); |
1572 | rcvd = GNUNET_NETWORK_socket_recvfrom(udp_sock, | 1586 | rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock, |
1573 | buf, | 1587 | buf, |
1574 | sizeof(buf), | 1588 | sizeof(buf), |
1575 | (struct sockaddr *)&sa, | 1589 | (struct sockaddr *) &sa, |
1576 | &salen); | 1590 | &salen); |
1577 | if (-1 == rcvd) | 1591 | if (-1 == rcvd) |
1578 | { | 1592 | { |
1579 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv"); | 1593 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); |
1580 | return; | 1594 | return; |
1581 | } | 1595 | } |
1582 | 1596 | ||
1583 | /* first, see if it is a UDPBox */ | 1597 | /* first, see if it is a UDPBox */ |
1584 | if (rcvd > sizeof(struct UDPBox)) | 1598 | if (rcvd > sizeof(struct UDPBox)) |
1585 | { | 1599 | { |
1586 | const struct UDPBox *box; | 1600 | const struct UDPBox *box; |
1587 | struct KeyCacheEntry *kce; | 1601 | struct KeyCacheEntry *kce; |
1588 | 1602 | ||
1589 | box = (const struct UDPBox *)buf; | 1603 | box = (const struct UDPBox *) buf; |
1590 | kce = GNUNET_CONTAINER_multishortmap_get(key_cache, &box->kid); | 1604 | kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid); |
1591 | if (NULL != kce) | 1605 | if (NULL != kce) |
1592 | { | 1606 | { |
1593 | decrypt_box(box, (size_t)rcvd, kce); | 1607 | decrypt_box (box, (size_t) rcvd, kce); |
1594 | return; | 1608 | return; |
1595 | } | ||
1596 | } | 1609 | } |
1610 | } | ||
1597 | 1611 | ||
1598 | /* next, check if it is a broadcast */ | 1612 | /* next, check if it is a broadcast */ |
1599 | if (sizeof(struct UDPBroadcast) == rcvd) | 1613 | if (sizeof(struct UDPBroadcast) == rcvd) |
1614 | { | ||
1615 | const struct UDPBroadcast *ub; | ||
1616 | struct UdpBroadcastSignature uhs; | ||
1617 | |||
1618 | ub = (const struct UDPBroadcast *) buf; | ||
1619 | uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); | ||
1620 | uhs.purpose.size = htonl (sizeof(uhs)); | ||
1621 | uhs.sender = ub->sender; | ||
1622 | GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address); | ||
1623 | if (GNUNET_OK == | ||
1624 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, | ||
1625 | &uhs.purpose, | ||
1626 | &ub->sender_sig, | ||
1627 | &ub->sender.public_key)) | ||
1600 | { | 1628 | { |
1601 | const struct UDPBroadcast *ub; | 1629 | char *addr_s; |
1602 | struct UdpBroadcastSignature uhs; | 1630 | enum GNUNET_NetworkType nt; |
1603 | 1631 | ||
1604 | ub = (const struct UDPBroadcast *)buf; | 1632 | addr_s = |
1605 | uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); | 1633 | sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen); |
1606 | uhs.purpose.size = htonl(sizeof(uhs)); | 1634 | GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO); |
1607 | uhs.sender = ub->sender; | 1635 | /* use our own mechanism to determine network type */ |
1608 | GNUNET_CRYPTO_hash(&sa, salen, &uhs.h_address); | 1636 | nt = |
1609 | if (GNUNET_OK == | 1637 | GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen); |
1610 | GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, | 1638 | GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s); |
1611 | &uhs.purpose, | 1639 | GNUNET_free (addr_s); |
1612 | &ub->sender_sig, | 1640 | return; |
1613 | &ub->sender.public_key)) | ||
1614 | { | ||
1615 | char *addr_s; | ||
1616 | enum GNUNET_NetworkType nt; | ||
1617 | |||
1618 | addr_s = | ||
1619 | sockaddr_to_udpaddr_string((const struct sockaddr *)&sa, salen); | ||
1620 | GNUNET_STATISTICS_update(stats, "# broadcasts received", 1, GNUNET_NO); | ||
1621 | /* use our own mechanism to determine network type */ | ||
1622 | nt = | ||
1623 | GNUNET_NT_scanner_get_type(is, (const struct sockaddr *)&sa, salen); | ||
1624 | GNUNET_TRANSPORT_application_validate(ah, &ub->sender, nt, addr_s); | ||
1625 | GNUNET_free(addr_s); | ||
1626 | return; | ||
1627 | } | ||
1628 | /* continue with KX, mostly for statistics... */ | ||
1629 | } | 1641 | } |
1642 | /* continue with KX, mostly for statistics... */ | ||
1643 | } | ||
1630 | 1644 | ||
1631 | 1645 | ||
1632 | /* finally, test if it is a KX */ | 1646 | /* finally, test if it is a KX */ |
1633 | if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX)) | 1647 | if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX)) |
1634 | { | 1648 | { |
1635 | GNUNET_STATISTICS_update(stats, | 1649 | GNUNET_STATISTICS_update (stats, |
1636 | "# messages dropped (no kid, too small for KX)", | 1650 | "# messages dropped (no kid, too small for KX)", |
1637 | 1, | 1651 | 1, |
1638 | GNUNET_NO); | 1652 | GNUNET_NO); |
1639 | return; | 1653 | return; |
1640 | } | 1654 | } |
1641 | 1655 | ||
1642 | { | 1656 | { |
1643 | const struct InitialKX *kx; | 1657 | const struct InitialKX *kx; |
@@ -1646,48 +1660,48 @@ sock_read(void *cls) | |||
1646 | const struct UDPConfirmation *uc; | 1660 | const struct UDPConfirmation *uc; |
1647 | struct SenderAddress *sender; | 1661 | struct SenderAddress *sender; |
1648 | 1662 | ||
1649 | kx = (const struct InitialKX *)buf; | 1663 | kx = (const struct InitialKX *) buf; |
1650 | ss = setup_shared_secret_dec(&kx->ephemeral); | 1664 | ss = setup_shared_secret_dec (&kx->ephemeral); |
1651 | if (GNUNET_OK != try_decrypt(ss, | 1665 | if (GNUNET_OK != try_decrypt (ss, |
1652 | kx->gcm_tag, | 1666 | kx->gcm_tag, |
1653 | 0, | 1667 | 0, |
1654 | &buf[sizeof(*kx)], | 1668 | &buf[sizeof(*kx)], |
1655 | sizeof(pbuf), | 1669 | sizeof(pbuf), |
1656 | pbuf)) | 1670 | pbuf)) |
1657 | { | 1671 | { |
1658 | GNUNET_free(ss); | 1672 | GNUNET_free (ss); |
1659 | GNUNET_STATISTICS_update( | 1673 | GNUNET_STATISTICS_update ( |
1660 | stats, | 1674 | stats, |
1661 | "# messages dropped (no kid, AEAD decryption failed)", | 1675 | "# messages dropped (no kid, AEAD decryption failed)", |
1662 | 1, | 1676 | 1, |
1663 | GNUNET_NO); | 1677 | GNUNET_NO); |
1664 | return; | 1678 | return; |
1665 | } | 1679 | } |
1666 | uc = (const struct UDPConfirmation *)pbuf; | 1680 | uc = (const struct UDPConfirmation *) pbuf; |
1667 | if (GNUNET_OK != verify_confirmation(&kx->ephemeral, uc)) | 1681 | if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc)) |
1668 | { | 1682 | { |
1669 | GNUNET_break_op(0); | 1683 | GNUNET_break_op (0); |
1670 | GNUNET_free(ss); | 1684 | GNUNET_free (ss); |
1671 | GNUNET_STATISTICS_update(stats, | 1685 | GNUNET_STATISTICS_update (stats, |
1672 | "# messages dropped (sender signature invalid)", | 1686 | "# messages dropped (sender signature invalid)", |
1673 | 1, | 1687 | 1, |
1674 | GNUNET_NO); | 1688 | GNUNET_NO); |
1675 | return; | 1689 | return; |
1676 | } | 1690 | } |
1677 | calculate_cmac(ss); | 1691 | calculate_cmac (ss); |
1678 | sender = setup_sender(&uc->sender, (const struct sockaddr *)&sa, salen); | 1692 | sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen); |
1679 | ss->sender = sender; | 1693 | ss->sender = sender; |
1680 | GNUNET_CONTAINER_DLL_insert(sender->ss_head, sender->ss_tail, ss); | 1694 | GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss); |
1681 | sender->num_secrets++; | 1695 | sender->num_secrets++; |
1682 | GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO); | 1696 | GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); |
1683 | GNUNET_STATISTICS_update(stats, | 1697 | GNUNET_STATISTICS_update (stats, |
1684 | "# messages decrypted without BOX", | 1698 | "# messages decrypted without BOX", |
1685 | 1, | 1699 | 1, |
1686 | GNUNET_NO); | 1700 | GNUNET_NO); |
1687 | try_handle_plaintext(sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); | 1701 | try_handle_plaintext (sender, &uc[1], sizeof(pbuf) - sizeof(*uc)); |
1688 | consider_ss_ack(ss); | 1702 | consider_ss_ack (ss); |
1689 | if (sender->num_secrets > MAX_SECRETS) | 1703 | if (sender->num_secrets > MAX_SECRETS) |
1690 | secret_destroy(sender->ss_tail); | 1704 | secret_destroy (sender->ss_tail); |
1691 | } | 1705 | } |
1692 | } | 1706 | } |
1693 | 1707 | ||
@@ -1700,7 +1714,7 @@ sock_read(void *cls) | |||
1700 | * @return converted bindto specification | 1714 | * @return converted bindto specification |
1701 | */ | 1715 | */ |
1702 | static struct sockaddr * | 1716 | static struct sockaddr * |
1703 | udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) | 1717 | udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) |
1704 | { | 1718 | { |
1705 | struct sockaddr *in; | 1719 | struct sockaddr *in; |
1706 | unsigned int port; | 1720 | unsigned int port; |
@@ -1708,88 +1722,88 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) | |||
1708 | char *colon; | 1722 | char *colon; |
1709 | char *cp; | 1723 | char *cp; |
1710 | 1724 | ||
1711 | if (1 == sscanf(bindto, "%u%1s", &port, dummy)) | 1725 | if (1 == sscanf (bindto, "%u%1s", &port, dummy)) |
1726 | { | ||
1727 | /* interpreting value as just a PORT number */ | ||
1728 | if (port > UINT16_MAX) | ||
1712 | { | 1729 | { |
1713 | /* interpreting value as just a PORT number */ | 1730 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1714 | if (port > UINT16_MAX) | 1731 | "BINDTO specification `%s' invalid: value too large for port\n", |
1715 | { | 1732 | bindto); |
1716 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1733 | return NULL; |
1717 | "BINDTO specification `%s' invalid: value too large for port\n", | 1734 | } |
1718 | bindto); | 1735 | if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) || |
1719 | return NULL; | 1736 | (GNUNET_YES == |
1720 | } | 1737 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1721 | if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) || | 1738 | COMMUNICATOR_CONFIG_SECTION, |
1722 | (GNUNET_YES == | 1739 | "DISABLE_V6"))) |
1723 | GNUNET_CONFIGURATION_get_value_yesno(cfg, | 1740 | { |
1724 | COMMUNICATOR_CONFIG_SECTION, | 1741 | struct sockaddr_in *i4; |
1725 | "DISABLE_V6"))) | ||
1726 | { | ||
1727 | struct sockaddr_in *i4; | ||
1728 | 1742 | ||
1729 | i4 = GNUNET_malloc(sizeof(struct sockaddr_in)); | 1743 | i4 = GNUNET_malloc (sizeof(struct sockaddr_in)); |
1730 | i4->sin_family = AF_INET; | 1744 | i4->sin_family = AF_INET; |
1731 | i4->sin_port = htons((uint16_t)port); | 1745 | i4->sin_port = htons ((uint16_t) port); |
1732 | *sock_len = sizeof(struct sockaddr_in); | 1746 | *sock_len = sizeof(struct sockaddr_in); |
1733 | in = (struct sockaddr *)i4; | 1747 | in = (struct sockaddr *) i4; |
1734 | } | 1748 | } |
1735 | else | 1749 | else |
1736 | { | 1750 | { |
1737 | struct sockaddr_in6 *i6; | 1751 | struct sockaddr_in6 *i6; |
1738 | 1752 | ||
1739 | i6 = GNUNET_malloc(sizeof(struct sockaddr_in6)); | 1753 | i6 = GNUNET_malloc (sizeof(struct sockaddr_in6)); |
1740 | i6->sin6_family = AF_INET6; | 1754 | i6->sin6_family = AF_INET6; |
1741 | i6->sin6_port = htons((uint16_t)port); | 1755 | i6->sin6_port = htons ((uint16_t) port); |
1742 | *sock_len = sizeof(struct sockaddr_in6); | 1756 | *sock_len = sizeof(struct sockaddr_in6); |
1743 | in = (struct sockaddr *)i6; | 1757 | in = (struct sockaddr *) i6; |
1744 | } | ||
1745 | return in; | ||
1746 | } | 1758 | } |
1747 | cp = GNUNET_strdup(bindto); | 1759 | return in; |
1748 | colon = strrchr(cp, ':'); | 1760 | } |
1761 | cp = GNUNET_strdup (bindto); | ||
1762 | colon = strrchr (cp, ':'); | ||
1749 | if (NULL != colon) | 1763 | if (NULL != colon) |
1764 | { | ||
1765 | /* interpet value after colon as port */ | ||
1766 | *colon = '\0'; | ||
1767 | colon++; | ||
1768 | if (1 == sscanf (colon, "%u%1s", &port, dummy)) | ||
1750 | { | 1769 | { |
1751 | /* interpet value after colon as port */ | 1770 | /* interpreting value as just a PORT number */ |
1752 | *colon = '\0'; | 1771 | if (port > UINT16_MAX) |
1753 | colon++; | 1772 | { |
1754 | if (1 == sscanf(colon, "%u%1s", &port, dummy)) | 1773 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1755 | { | 1774 | "BINDTO specification `%s' invalid: value too large for port\n", |
1756 | /* interpreting value as just a PORT number */ | 1775 | bindto); |
1757 | if (port > UINT16_MAX) | 1776 | GNUNET_free (cp); |
1758 | { | 1777 | return NULL; |
1759 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1778 | } |
1760 | "BINDTO specification `%s' invalid: value too large for port\n", | ||
1761 | bindto); | ||
1762 | GNUNET_free(cp); | ||
1763 | return NULL; | ||
1764 | } | ||
1765 | } | ||
1766 | else | ||
1767 | { | ||
1768 | GNUNET_log( | ||
1769 | GNUNET_ERROR_TYPE_ERROR, | ||
1770 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | ||
1771 | bindto); | ||
1772 | GNUNET_free(cp); | ||
1773 | return NULL; | ||
1774 | } | ||
1775 | } | 1779 | } |
1776 | else | 1780 | else |
1777 | { | 1781 | { |
1778 | /* interpret missing port as 0, aka pick any free one */ | 1782 | GNUNET_log ( |
1779 | port = 0; | 1783 | GNUNET_ERROR_TYPE_ERROR, |
1784 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | ||
1785 | bindto); | ||
1786 | GNUNET_free (cp); | ||
1787 | return NULL; | ||
1780 | } | 1788 | } |
1789 | } | ||
1790 | else | ||
1791 | { | ||
1792 | /* interpret missing port as 0, aka pick any free one */ | ||
1793 | port = 0; | ||
1794 | } | ||
1781 | { | 1795 | { |
1782 | /* try IPv4 */ | 1796 | /* try IPv4 */ |
1783 | struct sockaddr_in v4; | 1797 | struct sockaddr_in v4; |
1784 | 1798 | ||
1785 | if (1 == inet_pton(AF_INET, cp, &v4)) | 1799 | if (1 == inet_pton (AF_INET, cp, &v4)) |
1786 | { | 1800 | { |
1787 | v4.sin_port = htons((uint16_t)port); | 1801 | v4.sin_port = htons ((uint16_t) port); |
1788 | in = GNUNET_memdup(&v4, sizeof(v4)); | 1802 | in = GNUNET_memdup (&v4, sizeof(v4)); |
1789 | *sock_len = sizeof(v4); | 1803 | *sock_len = sizeof(v4); |
1790 | GNUNET_free(cp); | 1804 | GNUNET_free (cp); |
1791 | return in; | 1805 | return in; |
1792 | } | 1806 | } |
1793 | } | 1807 | } |
1794 | { | 1808 | { |
1795 | /* try IPv6 */ | 1809 | /* try IPv6 */ |
@@ -1797,22 +1811,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) | |||
1797 | const char *start; | 1811 | const char *start; |
1798 | 1812 | ||
1799 | start = cp; | 1813 | start = cp; |
1800 | if (('[' == *cp) && (']' == cp[strlen(cp) - 1])) | 1814 | if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) |
1801 | { | 1815 | { |
1802 | start++; /* skip over '[' */ | 1816 | start++; /* skip over '[' */ |
1803 | cp[strlen(cp) - 1] = '\0'; /* eat ']' */ | 1817 | cp[strlen (cp) - 1] = '\0'; /* eat ']' */ |
1804 | } | 1818 | } |
1805 | if (1 == inet_pton(AF_INET6, start, &v6)) | 1819 | if (1 == inet_pton (AF_INET6, start, &v6)) |
1806 | { | 1820 | { |
1807 | v6.sin6_port = htons((uint16_t)port); | 1821 | v6.sin6_port = htons ((uint16_t) port); |
1808 | in = GNUNET_memdup(&v6, sizeof(v6)); | 1822 | in = GNUNET_memdup (&v6, sizeof(v6)); |
1809 | *sock_len = sizeof(v6); | 1823 | *sock_len = sizeof(v6); |
1810 | GNUNET_free(cp); | 1824 | GNUNET_free (cp); |
1811 | return in; | 1825 | return in; |
1812 | } | 1826 | } |
1813 | } | 1827 | } |
1814 | /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ | 1828 | /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ |
1815 | GNUNET_free(cp); | 1829 | GNUNET_free (cp); |
1816 | return NULL; | 1830 | return NULL; |
1817 | } | 1831 | } |
1818 | 1832 | ||
@@ -1825,22 +1839,22 @@ udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len) | |||
1825 | * @param pad_size number of bytes of padding to append | 1839 | * @param pad_size number of bytes of padding to append |
1826 | */ | 1840 | */ |
1827 | static void | 1841 | static void |
1828 | do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) | 1842 | do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) |
1829 | { | 1843 | { |
1830 | char pad[pad_size]; | 1844 | char pad[pad_size]; |
1831 | 1845 | ||
1832 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad)); | 1846 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad)); |
1833 | if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader)) | 1847 | if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader)) |
1834 | { | 1848 | { |
1835 | struct GNUNET_MessageHeader hdr = | 1849 | struct GNUNET_MessageHeader hdr = |
1836 | { .size = htons(sizeof(pad)), | 1850 | { .size = htons (sizeof(pad)), |
1837 | .type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) }; | 1851 | .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) }; |
1838 | 1852 | ||
1839 | memcpy(pad, &hdr, sizeof(hdr)); | 1853 | memcpy (pad, &hdr, sizeof(hdr)); |
1840 | } | 1854 | } |
1841 | GNUNET_assert( | 1855 | GNUNET_assert ( |
1842 | 0 == | 1856 | 0 == |
1843 | gcry_cipher_encrypt(out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); | 1857 | gcry_cipher_encrypt (out_cipher, dgram, sizeof(pad), pad, sizeof(pad))); |
1844 | } | 1858 | } |
1845 | 1859 | ||
1846 | 1860 | ||
@@ -1853,123 +1867,123 @@ do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) | |||
1853 | * @param impl_state our `struct ReceiverAddress` | 1867 | * @param impl_state our `struct ReceiverAddress` |
1854 | */ | 1868 | */ |
1855 | static void | 1869 | static void |
1856 | mq_send(struct GNUNET_MQ_Handle *mq, | 1870 | mq_send (struct GNUNET_MQ_Handle *mq, |
1857 | const struct GNUNET_MessageHeader *msg, | 1871 | const struct GNUNET_MessageHeader *msg, |
1858 | void *impl_state) | 1872 | void *impl_state) |
1859 | { | 1873 | { |
1860 | struct ReceiverAddress *receiver = impl_state; | 1874 | struct ReceiverAddress *receiver = impl_state; |
1861 | uint16_t msize = ntohs(msg->size); | 1875 | uint16_t msize = ntohs (msg->size); |
1862 | 1876 | ||
1863 | GNUNET_assert(mq == receiver->mq); | 1877 | GNUNET_assert (mq == receiver->mq); |
1864 | if (msize > receiver->mtu) | 1878 | if (msize > receiver->mtu) |
1865 | { | 1879 | { |
1866 | GNUNET_break(0); | 1880 | GNUNET_break (0); |
1867 | receiver_destroy(receiver); | 1881 | receiver_destroy (receiver); |
1868 | return; | 1882 | return; |
1869 | } | 1883 | } |
1870 | reschedule_receiver_timeout(receiver); | 1884 | reschedule_receiver_timeout (receiver); |
1871 | 1885 | ||
1872 | if (0 == receiver->acks_available) | 1886 | if (0 == receiver->acks_available) |
1873 | { | 1887 | { |
1874 | /* use KX encryption method */ | 1888 | /* use KX encryption method */ |
1875 | struct UdpHandshakeSignature uhs; | 1889 | struct UdpHandshakeSignature uhs; |
1876 | struct UDPConfirmation uc; | 1890 | struct UDPConfirmation uc; |
1877 | struct InitialKX kx; | 1891 | struct InitialKX kx; |
1878 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; | 1892 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; |
1879 | char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; | 1893 | char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)]; |
1880 | size_t dpos; | 1894 | size_t dpos; |
1881 | gcry_cipher_hd_t out_cipher; | 1895 | gcry_cipher_hd_t out_cipher; |
1882 | struct SharedSecret *ss; | 1896 | struct SharedSecret *ss; |
1883 | 1897 | ||
1884 | /* setup key material */ | 1898 | /* setup key material */ |
1885 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2(&epriv)); | 1899 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); |
1886 | 1900 | ||
1887 | ss = setup_shared_secret_enc(&epriv, receiver); | 1901 | ss = setup_shared_secret_enc (&epriv, receiver); |
1888 | setup_cipher(&ss->master, 0, &out_cipher); | 1902 | setup_cipher (&ss->master, 0, &out_cipher); |
1889 | /* compute 'uc' */ | 1903 | /* compute 'uc' */ |
1890 | uc.sender = my_identity; | 1904 | uc.sender = my_identity; |
1891 | uc.monotonic_time = | 1905 | uc.monotonic_time = |
1892 | GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg)); | 1906 | GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); |
1893 | uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); | 1907 | uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); |
1894 | uhs.purpose.size = htonl(sizeof(uhs)); | 1908 | uhs.purpose.size = htonl (sizeof(uhs)); |
1895 | uhs.sender = my_identity; | 1909 | uhs.sender = my_identity; |
1896 | uhs.receiver = receiver->target; | 1910 | uhs.receiver = receiver->target; |
1897 | GNUNET_CRYPTO_ecdhe_key_get_public(&epriv, &uhs.ephemeral); | 1911 | GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral); |
1898 | uhs.monotonic_time = uc.monotonic_time; | 1912 | uhs.monotonic_time = uc.monotonic_time; |
1899 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, | 1913 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1900 | &uhs.purpose, | 1914 | &uhs.purpose, |
1901 | &uc.sender_sig)); | 1915 | &uc.sender_sig)); |
1902 | /* Leave space for kx */ | 1916 | /* Leave space for kx */ |
1903 | dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey); | 1917 | dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey); |
1904 | /* Append encrypted uc to dgram */ | 1918 | /* Append encrypted uc to dgram */ |
1905 | GNUNET_assert(0 == gcry_cipher_encrypt(out_cipher, | 1919 | GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher, |
1906 | &dgram[dpos], | 1920 | &dgram[dpos], |
1907 | sizeof(uc), | 1921 | sizeof(uc), |
1908 | &uc, | 1922 | &uc, |
1909 | sizeof(uc))); | 1923 | sizeof(uc))); |
1910 | dpos += sizeof(uc); | 1924 | dpos += sizeof(uc); |
1911 | /* Append encrypted payload to dgram */ | 1925 | /* Append encrypted payload to dgram */ |
1912 | GNUNET_assert( | 1926 | GNUNET_assert ( |
1913 | 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); | 1927 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); |
1914 | dpos += msize; | 1928 | dpos += msize; |
1915 | do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | 1929 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); |
1916 | /* Datagram starts with kx */ | 1930 | /* Datagram starts with kx */ |
1917 | kx.ephemeral = uhs.ephemeral; | 1931 | kx.ephemeral = uhs.ephemeral; |
1918 | GNUNET_assert( | 1932 | GNUNET_assert ( |
1919 | 0 == gcry_cipher_gettag(out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); | 1933 | 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag))); |
1920 | gcry_cipher_close(out_cipher); | 1934 | gcry_cipher_close (out_cipher); |
1921 | memcpy(dgram, &kx, sizeof(kx)); | 1935 | memcpy (dgram, &kx, sizeof(kx)); |
1922 | if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, | 1936 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, |
1923 | dgram, | 1937 | dgram, |
1924 | sizeof(dgram), | 1938 | sizeof(dgram), |
1925 | receiver->address, | 1939 | receiver->address, |
1926 | receiver->address_len)) | 1940 | receiver->address_len)) |
1927 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); | 1941 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); |
1928 | GNUNET_MQ_impl_send_continue(mq); | 1942 | GNUNET_MQ_impl_send_continue (mq); |
1929 | return; | 1943 | return; |
1930 | } /* End of KX encryption method */ | 1944 | } /* End of KX encryption method */ |
1931 | 1945 | ||
1932 | /* begin "BOX" encryption method, scan for ACKs from tail! */ | 1946 | /* begin "BOX" encryption method, scan for ACKs from tail! */ |
1933 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) | 1947 | for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) |
1948 | { | ||
1949 | if (ss->sequence_used < ss->sequence_allowed) | ||
1934 | { | 1950 | { |
1935 | if (ss->sequence_used < ss->sequence_allowed) | 1951 | char dgram[sizeof(struct UDPBox) + receiver->mtu]; |
1936 | { | 1952 | struct UDPBox *box; |
1937 | char dgram[sizeof(struct UDPBox) + receiver->mtu]; | 1953 | gcry_cipher_hd_t out_cipher; |
1938 | struct UDPBox *box; | 1954 | size_t dpos; |
1939 | gcry_cipher_hd_t out_cipher; | 1955 | |
1940 | size_t dpos; | 1956 | box = (struct UDPBox *) dgram; |
1941 | 1957 | ss->sequence_used++; | |
1942 | box = (struct UDPBox *)dgram; | 1958 | get_kid (&ss->master, ss->sequence_used, &box->kid); |
1943 | ss->sequence_used++; | 1959 | setup_cipher (&ss->master, ss->sequence_used, &out_cipher); |
1944 | get_kid(&ss->master, ss->sequence_used, &box->kid); | 1960 | /* Append encrypted payload to dgram */ |
1945 | setup_cipher(&ss->master, ss->sequence_used, &out_cipher); | 1961 | dpos = sizeof(struct UDPBox); |
1946 | /* Append encrypted payload to dgram */ | 1962 | GNUNET_assert ( |
1947 | dpos = sizeof(struct UDPBox); | 1963 | 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); |
1948 | GNUNET_assert( | 1964 | dpos += msize; |
1949 | 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize)); | 1965 | do_pad (out_cipher, &dgram[dpos], sizeof(dgram) - dpos); |
1950 | dpos += msize; | 1966 | GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, |
1951 | do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos); | 1967 | box->gcm_tag, |
1952 | GNUNET_assert(0 == gcry_cipher_gettag(out_cipher, | 1968 | sizeof(box->gcm_tag))); |
1953 | box->gcm_tag, | 1969 | gcry_cipher_close (out_cipher); |
1954 | sizeof(box->gcm_tag))); | 1970 | if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, |
1955 | gcry_cipher_close(out_cipher); | 1971 | dgram, |
1956 | if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock, | 1972 | sizeof(dgram), |
1957 | dgram, | 1973 | receiver->address, |
1958 | sizeof(dgram), | 1974 | receiver->address_len)) |
1959 | receiver->address, | 1975 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); |
1960 | receiver->address_len)) | 1976 | GNUNET_MQ_impl_send_continue (mq); |
1961 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send"); | 1977 | receiver->acks_available--; |
1962 | GNUNET_MQ_impl_send_continue(mq); | 1978 | if (0 == receiver->acks_available) |
1963 | receiver->acks_available--; | 1979 | { |
1964 | if (0 == receiver->acks_available) | 1980 | /* We have no more ACKs => MTU change! */ |
1965 | { | 1981 | setup_receiver_mq (receiver); |
1966 | /* We have no more ACKs => MTU change! */ | 1982 | } |
1967 | setup_receiver_mq(receiver); | 1983 | return; |
1968 | } | ||
1969 | return; | ||
1970 | } | ||
1971 | } | 1984 | } |
1972 | GNUNET_assert(0); | 1985 | } |
1986 | GNUNET_assert (0); | ||
1973 | } | 1987 | } |
1974 | 1988 | ||
1975 | 1989 | ||
@@ -1982,15 +1996,15 @@ mq_send(struct GNUNET_MQ_Handle *mq, | |||
1982 | * @param impl_state our `struct ReceiverAddress` | 1996 | * @param impl_state our `struct ReceiverAddress` |
1983 | */ | 1997 | */ |
1984 | static void | 1998 | static void |
1985 | mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) | 1999 | mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) |
1986 | { | 2000 | { |
1987 | struct ReceiverAddress *receiver = impl_state; | 2001 | struct ReceiverAddress *receiver = impl_state; |
1988 | 2002 | ||
1989 | if (mq == receiver->mq) | 2003 | if (mq == receiver->mq) |
1990 | { | 2004 | { |
1991 | receiver->mq = NULL; | 2005 | receiver->mq = NULL; |
1992 | receiver_destroy(receiver); | 2006 | receiver_destroy (receiver); |
1993 | } | 2007 | } |
1994 | } | 2008 | } |
1995 | 2009 | ||
1996 | 2010 | ||
@@ -2001,10 +2015,10 @@ mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
2001 | * @param impl_state our `struct RecvierAddress` | 2015 | * @param impl_state our `struct RecvierAddress` |
2002 | */ | 2016 | */ |
2003 | static void | 2017 | static void |
2004 | mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) | 2018 | mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) |
2005 | { | 2019 | { |
2006 | /* Cancellation is impossible with UDP; bail */ | 2020 | /* Cancellation is impossible with UDP; bail */ |
2007 | GNUNET_assert(0); | 2021 | GNUNET_assert (0); |
2008 | } | 2022 | } |
2009 | 2023 | ||
2010 | 2024 | ||
@@ -2018,15 +2032,15 @@ mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state) | |||
2018 | * @param error error code | 2032 | * @param error error code |
2019 | */ | 2033 | */ |
2020 | static void | 2034 | static void |
2021 | mq_error(void *cls, enum GNUNET_MQ_Error error) | 2035 | mq_error (void *cls, enum GNUNET_MQ_Error error) |
2022 | { | 2036 | { |
2023 | struct ReceiverAddress *receiver = cls; | 2037 | struct ReceiverAddress *receiver = cls; |
2024 | 2038 | ||
2025 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2039 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2026 | "MQ error in queue to %s: %d\n", | 2040 | "MQ error in queue to %s: %d\n", |
2027 | GNUNET_i2s(&receiver->target), | 2041 | GNUNET_i2s (&receiver->target), |
2028 | (int)error); | 2042 | (int) error); |
2029 | receiver_destroy(receiver); | 2043 | receiver_destroy (receiver); |
2030 | } | 2044 | } |
2031 | 2045 | ||
2032 | 2046 | ||
@@ -2038,63 +2052,63 @@ mq_error(void *cls, enum GNUNET_MQ_Error error) | |||
2038 | * @param receiver receiver to setup MQ for | 2052 | * @param receiver receiver to setup MQ for |
2039 | */ | 2053 | */ |
2040 | static void | 2054 | static void |
2041 | setup_receiver_mq(struct ReceiverAddress *receiver) | 2055 | setup_receiver_mq (struct ReceiverAddress *receiver) |
2042 | { | 2056 | { |
2043 | size_t base_mtu; | 2057 | size_t base_mtu; |
2044 | 2058 | ||
2045 | if (NULL != receiver->qh) | 2059 | if (NULL != receiver->qh) |
2046 | { | 2060 | { |
2047 | GNUNET_TRANSPORT_communicator_mq_del(receiver->qh); | 2061 | GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); |
2048 | receiver->qh = NULL; | 2062 | receiver->qh = NULL; |
2049 | } | 2063 | } |
2050 | GNUNET_assert(NULL == receiver->mq); | 2064 | GNUNET_assert (NULL == receiver->mq); |
2051 | switch (receiver->address->sa_family) | 2065 | switch (receiver->address->sa_family) |
2052 | { | 2066 | { |
2053 | case AF_INET: | 2067 | case AF_INET: |
2054 | base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ | 2068 | base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ |
2055 | - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ | 2069 | - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */ |
2056 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; | 2070 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; |
2057 | break; | 2071 | break; |
2058 | 2072 | ||
2059 | case AF_INET6: | 2073 | case AF_INET6: |
2060 | base_mtu = 1280 /* Minimum MTU required by IPv6 */ | 2074 | base_mtu = 1280 /* Minimum MTU required by IPv6 */ |
2061 | - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ | 2075 | - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */ |
2062 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; | 2076 | - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */; |
2063 | break; | 2077 | break; |
2064 | 2078 | ||
2065 | default: | 2079 | default: |
2066 | GNUNET_assert(0); | 2080 | GNUNET_assert (0); |
2067 | break; | 2081 | break; |
2068 | } | 2082 | } |
2069 | if (0 == receiver->acks_available) | 2083 | if (0 == receiver->acks_available) |
2070 | { | 2084 | { |
2071 | /* MTU based on full KX messages */ | 2085 | /* MTU based on full KX messages */ |
2072 | receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ | 2086 | receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */ |
2073 | - sizeof(struct UDPConfirmation); /* 104 */ | 2087 | - sizeof(struct UDPConfirmation); /* 104 */ |
2074 | } | 2088 | } |
2075 | else | 2089 | else |
2076 | { | 2090 | { |
2077 | /* MTU based on BOXed messages */ | 2091 | /* MTU based on BOXed messages */ |
2078 | receiver->mtu = base_mtu - sizeof(struct UDPBox); | 2092 | receiver->mtu = base_mtu - sizeof(struct UDPBox); |
2079 | } | 2093 | } |
2080 | /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to | 2094 | /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to |
2081 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ | 2095 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ |
2082 | if (NULL == receiver->mq) | 2096 | if (NULL == receiver->mq) |
2083 | receiver->mq = GNUNET_MQ_queue_for_callbacks(&mq_send, | 2097 | receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, |
2084 | &mq_destroy, | 2098 | &mq_destroy, |
2085 | &mq_cancel, | 2099 | &mq_cancel, |
2086 | receiver, | 2100 | receiver, |
2087 | NULL, | 2101 | NULL, |
2088 | &mq_error, | 2102 | &mq_error, |
2089 | receiver); | 2103 | receiver); |
2090 | receiver->qh = | 2104 | receiver->qh = |
2091 | GNUNET_TRANSPORT_communicator_mq_add(ch, | 2105 | GNUNET_TRANSPORT_communicator_mq_add (ch, |
2092 | &receiver->target, | 2106 | &receiver->target, |
2093 | receiver->foreign_addr, | 2107 | receiver->foreign_addr, |
2094 | receiver->mtu, | 2108 | receiver->mtu, |
2095 | receiver->nt, | 2109 | receiver->nt, |
2096 | GNUNET_TRANSPORT_CS_OUTBOUND, | 2110 | GNUNET_TRANSPORT_CS_OUTBOUND, |
2097 | receiver->mq); | 2111 | receiver->mq); |
2098 | } | 2112 | } |
2099 | 2113 | ||
2100 | 2114 | ||
@@ -2117,47 +2131,47 @@ setup_receiver_mq(struct ReceiverAddress *receiver) | |||
2117 | * invalid | 2131 | * invalid |
2118 | */ | 2132 | */ |
2119 | static int | 2133 | static int |
2120 | mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | 2134 | mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) |
2121 | { | 2135 | { |
2122 | struct ReceiverAddress *receiver; | 2136 | struct ReceiverAddress *receiver; |
2123 | const char *path; | 2137 | const char *path; |
2124 | struct sockaddr *in; | 2138 | struct sockaddr *in; |
2125 | socklen_t in_len; | 2139 | socklen_t in_len; |
2126 | 2140 | ||
2127 | if (0 != strncmp(address, | 2141 | if (0 != strncmp (address, |
2128 | COMMUNICATOR_ADDRESS_PREFIX "-", | 2142 | COMMUNICATOR_ADDRESS_PREFIX "-", |
2129 | strlen(COMMUNICATOR_ADDRESS_PREFIX "-"))) | 2143 | strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) |
2130 | { | 2144 | { |
2131 | GNUNET_break_op(0); | 2145 | GNUNET_break_op (0); |
2132 | return GNUNET_SYSERR; | 2146 | return GNUNET_SYSERR; |
2133 | } | 2147 | } |
2134 | path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")]; | 2148 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; |
2135 | in = udp_address_to_sockaddr(path, &in_len); | 2149 | in = udp_address_to_sockaddr (path, &in_len); |
2136 | 2150 | ||
2137 | receiver = GNUNET_new(struct ReceiverAddress); | 2151 | receiver = GNUNET_new (struct ReceiverAddress); |
2138 | receiver->address = in; | 2152 | receiver->address = in; |
2139 | receiver->address_len = in_len; | 2153 | receiver->address_len = in_len; |
2140 | receiver->target = *peer; | 2154 | receiver->target = *peer; |
2141 | receiver->nt = GNUNET_NT_scanner_get_type(is, in, in_len); | 2155 | receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len); |
2142 | (void)GNUNET_CONTAINER_multipeermap_put( | 2156 | (void) GNUNET_CONTAINER_multipeermap_put ( |
2143 | receivers, | 2157 | receivers, |
2144 | &receiver->target, | 2158 | &receiver->target, |
2145 | receiver, | 2159 | receiver, |
2146 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2160 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2147 | receiver->timeout = | 2161 | receiver->timeout = |
2148 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2162 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2149 | receiver->hn = GNUNET_CONTAINER_heap_insert(receivers_heap, | 2163 | receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, |
2150 | receiver, | 2164 | receiver, |
2151 | receiver->timeout.abs_value_us); | 2165 | receiver->timeout.abs_value_us); |
2152 | GNUNET_STATISTICS_set(stats, | 2166 | GNUNET_STATISTICS_set (stats, |
2153 | "# receivers active", | 2167 | "# receivers active", |
2154 | GNUNET_CONTAINER_multipeermap_size(receivers), | 2168 | GNUNET_CONTAINER_multipeermap_size (receivers), |
2155 | GNUNET_NO); | 2169 | GNUNET_NO); |
2156 | receiver->foreign_addr = | 2170 | receiver->foreign_addr = |
2157 | sockaddr_to_udpaddr_string(receiver->address, receiver->address_len); | 2171 | sockaddr_to_udpaddr_string (receiver->address, receiver->address_len); |
2158 | setup_receiver_mq(receiver); | 2172 | setup_receiver_mq (receiver); |
2159 | if (NULL == timeout_task) | 2173 | if (NULL == timeout_task) |
2160 | timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL); | 2174 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); |
2161 | return GNUNET_OK; | 2175 | return GNUNET_OK; |
2162 | } | 2176 | } |
2163 | 2177 | ||
@@ -2171,15 +2185,15 @@ mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
2171 | * @return #GNUNET_OK to continue to iterate | 2185 | * @return #GNUNET_OK to continue to iterate |
2172 | */ | 2186 | */ |
2173 | static int | 2187 | static int |
2174 | get_receiver_delete_it(void *cls, | 2188 | get_receiver_delete_it (void *cls, |
2175 | const struct GNUNET_PeerIdentity *target, | 2189 | const struct GNUNET_PeerIdentity *target, |
2176 | void *value) | 2190 | void *value) |
2177 | { | 2191 | { |
2178 | struct ReceiverAddress *receiver = value; | 2192 | struct ReceiverAddress *receiver = value; |
2179 | 2193 | ||
2180 | (void)cls; | 2194 | (void) cls; |
2181 | (void)target; | 2195 | (void) target; |
2182 | receiver_destroy(receiver); | 2196 | receiver_destroy (receiver); |
2183 | return GNUNET_OK; | 2197 | return GNUNET_OK; |
2184 | } | 2198 | } |
2185 | 2199 | ||
@@ -2193,15 +2207,15 @@ get_receiver_delete_it(void *cls, | |||
2193 | * @return #GNUNET_OK to continue to iterate | 2207 | * @return #GNUNET_OK to continue to iterate |
2194 | */ | 2208 | */ |
2195 | static int | 2209 | static int |
2196 | get_sender_delete_it(void *cls, | 2210 | get_sender_delete_it (void *cls, |
2197 | const struct GNUNET_PeerIdentity *target, | 2211 | const struct GNUNET_PeerIdentity *target, |
2198 | void *value) | 2212 | void *value) |
2199 | { | 2213 | { |
2200 | struct SenderAddress *sender = value; | 2214 | struct SenderAddress *sender = value; |
2201 | 2215 | ||
2202 | (void)cls; | 2216 | (void) cls; |
2203 | (void)target; | 2217 | (void) target; |
2204 | sender_destroy(sender); | 2218 | sender_destroy (sender); |
2205 | return GNUNET_OK; | 2219 | return GNUNET_OK; |
2206 | } | 2220 | } |
2207 | 2221 | ||
@@ -2212,64 +2226,64 @@ get_sender_delete_it(void *cls, | |||
2212 | * @param cls NULL (always) | 2226 | * @param cls NULL (always) |
2213 | */ | 2227 | */ |
2214 | static void | 2228 | static void |
2215 | do_shutdown(void *cls) | 2229 | do_shutdown (void *cls) |
2216 | { | 2230 | { |
2217 | if (NULL != nat) | 2231 | if (NULL != nat) |
2218 | { | 2232 | { |
2219 | GNUNET_NAT_unregister(nat); | 2233 | GNUNET_NAT_unregister (nat); |
2220 | nat = NULL; | 2234 | nat = NULL; |
2221 | } | 2235 | } |
2222 | while (NULL != bi_head) | 2236 | while (NULL != bi_head) |
2223 | bi_destroy(bi_head); | 2237 | bi_destroy (bi_head); |
2224 | if (NULL != broadcast_task) | 2238 | if (NULL != broadcast_task) |
2225 | { | 2239 | { |
2226 | GNUNET_SCHEDULER_cancel(broadcast_task); | 2240 | GNUNET_SCHEDULER_cancel (broadcast_task); |
2227 | broadcast_task = NULL; | 2241 | broadcast_task = NULL; |
2228 | } | 2242 | } |
2229 | if (NULL != read_task) | 2243 | if (NULL != read_task) |
2230 | { | 2244 | { |
2231 | GNUNET_SCHEDULER_cancel(read_task); | 2245 | GNUNET_SCHEDULER_cancel (read_task); |
2232 | read_task = NULL; | 2246 | read_task = NULL; |
2233 | } | 2247 | } |
2234 | if (NULL != udp_sock) | 2248 | if (NULL != udp_sock) |
2235 | { | 2249 | { |
2236 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(udp_sock)); | 2250 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock)); |
2237 | udp_sock = NULL; | 2251 | udp_sock = NULL; |
2238 | } | 2252 | } |
2239 | GNUNET_CONTAINER_multipeermap_iterate(receivers, | 2253 | GNUNET_CONTAINER_multipeermap_iterate (receivers, |
2240 | &get_receiver_delete_it, | 2254 | &get_receiver_delete_it, |
2241 | NULL); | 2255 | NULL); |
2242 | GNUNET_CONTAINER_multipeermap_destroy(receivers); | 2256 | GNUNET_CONTAINER_multipeermap_destroy (receivers); |
2243 | GNUNET_CONTAINER_multipeermap_iterate(senders, &get_sender_delete_it, NULL); | 2257 | GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL); |
2244 | GNUNET_CONTAINER_multipeermap_destroy(senders); | 2258 | GNUNET_CONTAINER_multipeermap_destroy (senders); |
2245 | GNUNET_CONTAINER_multishortmap_destroy(key_cache); | 2259 | GNUNET_CONTAINER_multishortmap_destroy (key_cache); |
2246 | GNUNET_CONTAINER_heap_destroy(senders_heap); | 2260 | GNUNET_CONTAINER_heap_destroy (senders_heap); |
2247 | GNUNET_CONTAINER_heap_destroy(receivers_heap); | 2261 | GNUNET_CONTAINER_heap_destroy (receivers_heap); |
2248 | if (NULL != ch) | 2262 | if (NULL != ch) |
2249 | { | 2263 | { |
2250 | GNUNET_TRANSPORT_communicator_disconnect(ch); | 2264 | GNUNET_TRANSPORT_communicator_disconnect (ch); |
2251 | ch = NULL; | 2265 | ch = NULL; |
2252 | } | 2266 | } |
2253 | if (NULL != ah) | 2267 | if (NULL != ah) |
2254 | { | 2268 | { |
2255 | GNUNET_TRANSPORT_application_done(ah); | 2269 | GNUNET_TRANSPORT_application_done (ah); |
2256 | ah = NULL; | 2270 | ah = NULL; |
2257 | } | 2271 | } |
2258 | if (NULL != stats) | 2272 | if (NULL != stats) |
2259 | { | 2273 | { |
2260 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 2274 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
2261 | stats = NULL; | 2275 | stats = NULL; |
2262 | } | 2276 | } |
2263 | if (NULL != my_private_key) | 2277 | if (NULL != my_private_key) |
2264 | { | 2278 | { |
2265 | GNUNET_free(my_private_key); | 2279 | GNUNET_free (my_private_key); |
2266 | my_private_key = NULL; | 2280 | my_private_key = NULL; |
2267 | } | 2281 | } |
2268 | if (NULL != is) | 2282 | if (NULL != is) |
2269 | { | 2283 | { |
2270 | GNUNET_NT_scanner_done(is); | 2284 | GNUNET_NT_scanner_done (is); |
2271 | is = NULL; | 2285 | is = NULL; |
2272 | } | 2286 | } |
2273 | } | 2287 | } |
2274 | 2288 | ||
2275 | 2289 | ||
@@ -2283,24 +2297,24 @@ do_shutdown(void *cls) | |||
2283 | * @param msg payload | 2297 | * @param msg payload |
2284 | */ | 2298 | */ |
2285 | static void | 2299 | static void |
2286 | enc_notify_cb(void *cls, | 2300 | enc_notify_cb (void *cls, |
2287 | const struct GNUNET_PeerIdentity *sender, | 2301 | const struct GNUNET_PeerIdentity *sender, |
2288 | const struct GNUNET_MessageHeader *msg) | 2302 | const struct GNUNET_MessageHeader *msg) |
2289 | { | 2303 | { |
2290 | const struct UDPAck *ack; | 2304 | const struct UDPAck *ack; |
2291 | 2305 | ||
2292 | (void)cls; | 2306 | (void) cls; |
2293 | if ((ntohs(msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || | 2307 | if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || |
2294 | (ntohs(msg->size) != sizeof(struct UDPAck))) | 2308 | (ntohs (msg->size) != sizeof(struct UDPAck))) |
2295 | { | 2309 | { |
2296 | GNUNET_break_op(0); | 2310 | GNUNET_break_op (0); |
2297 | return; | 2311 | return; |
2298 | } | 2312 | } |
2299 | ack = (const struct UDPAck *)msg; | 2313 | ack = (const struct UDPAck *) msg; |
2300 | GNUNET_CONTAINER_multipeermap_get_multiple(receivers, | 2314 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, |
2301 | sender, | 2315 | sender, |
2302 | &handle_ack, | 2316 | &handle_ack, |
2303 | (void *)ack); | 2317 | (void *) ack); |
2304 | } | 2318 | } |
2305 | 2319 | ||
2306 | 2320 | ||
@@ -2318,39 +2332,39 @@ enc_notify_cb(void *cls, | |||
2318 | * @param addrlen actual length of the @a addr | 2332 | * @param addrlen actual length of the @a addr |
2319 | */ | 2333 | */ |
2320 | static void | 2334 | static void |
2321 | nat_address_cb(void *cls, | 2335 | nat_address_cb (void *cls, |
2322 | void **app_ctx, | 2336 | void **app_ctx, |
2323 | int add_remove, | 2337 | int add_remove, |
2324 | enum GNUNET_NAT_AddressClass ac, | 2338 | enum GNUNET_NAT_AddressClass ac, |
2325 | const struct sockaddr *addr, | 2339 | const struct sockaddr *addr, |
2326 | socklen_t addrlen) | 2340 | socklen_t addrlen) |
2327 | { | 2341 | { |
2328 | char *my_addr; | 2342 | char *my_addr; |
2329 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; | 2343 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; |
2330 | 2344 | ||
2331 | if (GNUNET_YES == add_remove) | 2345 | if (GNUNET_YES == add_remove) |
2332 | { | 2346 | { |
2333 | enum GNUNET_NetworkType nt; | 2347 | enum GNUNET_NetworkType nt; |
2334 | 2348 | ||
2335 | GNUNET_asprintf(&my_addr, | 2349 | GNUNET_asprintf (&my_addr, |
2336 | "%s-%s", | 2350 | "%s-%s", |
2337 | COMMUNICATOR_ADDRESS_PREFIX, | 2351 | COMMUNICATOR_ADDRESS_PREFIX, |
2338 | GNUNET_a2s(addr, addrlen)); | 2352 | GNUNET_a2s (addr, addrlen)); |
2339 | nt = GNUNET_NT_scanner_get_type(is, addr, addrlen); | 2353 | nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); |
2340 | ai = | 2354 | ai = |
2341 | GNUNET_TRANSPORT_communicator_address_add(ch, | 2355 | GNUNET_TRANSPORT_communicator_address_add (ch, |
2342 | my_addr, | 2356 | my_addr, |
2343 | nt, | 2357 | nt, |
2344 | GNUNET_TIME_UNIT_FOREVER_REL); | 2358 | GNUNET_TIME_UNIT_FOREVER_REL); |
2345 | GNUNET_free(my_addr); | 2359 | GNUNET_free (my_addr); |
2346 | *app_ctx = ai; | 2360 | *app_ctx = ai; |
2347 | } | 2361 | } |
2348 | else | 2362 | else |
2349 | { | 2363 | { |
2350 | ai = *app_ctx; | 2364 | ai = *app_ctx; |
2351 | GNUNET_TRANSPORT_communicator_address_remove(ai); | 2365 | GNUNET_TRANSPORT_communicator_address_remove (ai); |
2352 | *app_ctx = NULL; | 2366 | *app_ctx = NULL; |
2353 | } | 2367 | } |
2354 | } | 2368 | } |
2355 | 2369 | ||
2356 | 2370 | ||
@@ -2360,69 +2374,69 @@ nat_address_cb(void *cls, | |||
2360 | * @param cls a `struct BroadcastInterface` | 2374 | * @param cls a `struct BroadcastInterface` |
2361 | */ | 2375 | */ |
2362 | static void | 2376 | static void |
2363 | ifc_broadcast(void *cls) | 2377 | ifc_broadcast (void *cls) |
2364 | { | 2378 | { |
2365 | struct BroadcastInterface *bi = cls; | 2379 | struct BroadcastInterface *bi = cls; |
2366 | struct GNUNET_TIME_Relative delay; | 2380 | struct GNUNET_TIME_Relative delay; |
2367 | 2381 | ||
2368 | delay = BROADCAST_FREQUENCY; | 2382 | delay = BROADCAST_FREQUENCY; |
2369 | delay.rel_value_us = | 2383 | delay.rel_value_us = |
2370 | GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); | 2384 | GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); |
2371 | bi->broadcast_task = | 2385 | bi->broadcast_task = |
2372 | GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); | 2386 | GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); |
2373 | 2387 | ||
2374 | switch (bi->sa->sa_family) | 2388 | switch (bi->sa->sa_family) |
2375 | { | 2389 | { |
2376 | case AF_INET: { | 2390 | case AF_INET: { |
2377 | static int yes = 1; | 2391 | static int yes = 1; |
2378 | static int no = 0; | 2392 | static int no = 0; |
2379 | ssize_t sent; | 2393 | ssize_t sent; |
2380 | 2394 | ||
2381 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, | 2395 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2382 | SOL_SOCKET, | 2396 | SOL_SOCKET, |
2383 | SO_BROADCAST, | 2397 | SO_BROADCAST, |
2384 | &yes, | 2398 | &yes, |
2385 | sizeof(int))) | 2399 | sizeof(int))) |
2386 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 2400 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
2387 | sent = GNUNET_NETWORK_socket_sendto(udp_sock, | 2401 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2388 | &bi->bcm, | 2402 | &bi->bcm, |
2389 | sizeof(bi->bcm), | 2403 | sizeof(bi->bcm), |
2390 | bi->ba, | 2404 | bi->ba, |
2391 | bi->salen); | 2405 | bi->salen); |
2392 | if (-1 == sent) | 2406 | if (-1 == sent) |
2393 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); | 2407 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); |
2394 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, | 2408 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2395 | SOL_SOCKET, | 2409 | SOL_SOCKET, |
2396 | SO_BROADCAST, | 2410 | SO_BROADCAST, |
2397 | &no, | 2411 | &no, |
2398 | sizeof(int))) | 2412 | sizeof(int))) |
2399 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | 2413 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
2400 | break; | 2414 | break; |
2401 | } | 2415 | } |
2402 | 2416 | ||
2403 | case AF_INET6: { | 2417 | case AF_INET6: { |
2404 | ssize_t sent; | 2418 | ssize_t sent; |
2405 | struct sockaddr_in6 dst; | 2419 | struct sockaddr_in6 dst; |
2406 | 2420 | ||
2407 | dst.sin6_family = AF_INET6; | 2421 | dst.sin6_family = AF_INET6; |
2408 | dst.sin6_port = htons(my_port); | 2422 | dst.sin6_port = htons (my_port); |
2409 | dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; | 2423 | dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; |
2410 | dst.sin6_scope_id = ((struct sockaddr_in6 *)bi->ba)->sin6_scope_id; | 2424 | dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; |
2411 | 2425 | ||
2412 | sent = GNUNET_NETWORK_socket_sendto(udp_sock, | 2426 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2413 | &bi->bcm, | 2427 | &bi->bcm, |
2414 | sizeof(bi->bcm), | 2428 | sizeof(bi->bcm), |
2415 | (const struct sockaddr *)&dst, | 2429 | (const struct sockaddr *) &dst, |
2416 | sizeof(dst)); | 2430 | sizeof(dst)); |
2417 | if (-1 == sent) | 2431 | if (-1 == sent) |
2418 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto"); | 2432 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); |
2419 | break; | 2433 | break; |
2420 | } | 2434 | } |
2421 | 2435 | ||
2422 | default: | 2436 | default: |
2423 | GNUNET_break(0); | 2437 | GNUNET_break (0); |
2424 | break; | 2438 | break; |
2425 | } | 2439 | } |
2426 | } | 2440 | } |
2427 | 2441 | ||
2428 | 2442 | ||
@@ -2441,90 +2455,90 @@ ifc_broadcast(void *cls) | |||
2441 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort | 2455 | * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort |
2442 | */ | 2456 | */ |
2443 | static int | 2457 | static int |
2444 | iface_proc(void *cls, | 2458 | iface_proc (void *cls, |
2445 | const char *name, | 2459 | const char *name, |
2446 | int isDefault, | 2460 | int isDefault, |
2447 | const struct sockaddr *addr, | 2461 | const struct sockaddr *addr, |
2448 | const struct sockaddr *broadcast_addr, | 2462 | const struct sockaddr *broadcast_addr, |
2449 | const struct sockaddr *netmask, | 2463 | const struct sockaddr *netmask, |
2450 | socklen_t addrlen) | 2464 | socklen_t addrlen) |
2451 | { | 2465 | { |
2452 | struct BroadcastInterface *bi; | 2466 | struct BroadcastInterface *bi; |
2453 | enum GNUNET_NetworkType network; | 2467 | enum GNUNET_NetworkType network; |
2454 | struct UdpBroadcastSignature ubs; | 2468 | struct UdpBroadcastSignature ubs; |
2455 | 2469 | ||
2456 | (void)cls; | 2470 | (void) cls; |
2457 | (void)netmask; | 2471 | (void) netmask; |
2458 | if (NULL == addr) | 2472 | if (NULL == addr) |
2459 | return GNUNET_YES; /* need to know our address! */ | 2473 | return GNUNET_YES; /* need to know our address! */ |
2460 | network = GNUNET_NT_scanner_get_type(is, addr, addrlen); | 2474 | network = GNUNET_NT_scanner_get_type (is, addr, addrlen); |
2461 | if (GNUNET_NT_LOOPBACK == network) | 2475 | if (GNUNET_NT_LOOPBACK == network) |
2462 | { | 2476 | { |
2463 | /* Broadcasting on loopback does not make sense */ | 2477 | /* Broadcasting on loopback does not make sense */ |
2464 | return GNUNET_YES; | 2478 | return GNUNET_YES; |
2465 | } | 2479 | } |
2466 | for (bi = bi_head; NULL != bi; bi = bi->next) | 2480 | for (bi = bi_head; NULL != bi; bi = bi->next) |
2481 | { | ||
2482 | if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen))) | ||
2467 | { | 2483 | { |
2468 | if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen))) | 2484 | bi->found = GNUNET_YES; |
2469 | { | 2485 | return GNUNET_OK; |
2470 | bi->found = GNUNET_YES; | ||
2471 | return GNUNET_OK; | ||
2472 | } | ||
2473 | } | 2486 | } |
2487 | } | ||
2474 | 2488 | ||
2475 | if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr)) | 2489 | if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr)) |
2476 | return GNUNET_OK; /* broadcast_addr is required for IPv6! */ | 2490 | return GNUNET_OK; /* broadcast_addr is required for IPv6! */ |
2477 | if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket)) | 2491 | if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket)) |
2478 | return GNUNET_OK; /* not using IPv6 */ | 2492 | return GNUNET_OK; /* not using IPv6 */ |
2479 | 2493 | ||
2480 | bi = GNUNET_new(struct BroadcastInterface); | 2494 | bi = GNUNET_new (struct BroadcastInterface); |
2481 | bi->sa = GNUNET_memdup(addr, addrlen); | 2495 | bi->sa = GNUNET_memdup (addr, addrlen); |
2482 | if (NULL != broadcast_addr) | 2496 | if (NULL != broadcast_addr) |
2483 | bi->ba = GNUNET_memdup(broadcast_addr, addrlen); | 2497 | bi->ba = GNUNET_memdup (broadcast_addr, addrlen); |
2484 | bi->salen = addrlen; | 2498 | bi->salen = addrlen; |
2485 | bi->found = GNUNET_YES; | 2499 | bi->found = GNUNET_YES; |
2486 | bi->bcm.sender = my_identity; | 2500 | bi->bcm.sender = my_identity; |
2487 | ubs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); | 2501 | ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); |
2488 | ubs.purpose.size = htonl(sizeof(ubs)); | 2502 | ubs.purpose.size = htonl (sizeof(ubs)); |
2489 | ubs.sender = my_identity; | 2503 | ubs.sender = my_identity; |
2490 | GNUNET_CRYPTO_hash(addr, addrlen, &ubs.h_address); | 2504 | GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address); |
2491 | GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key, | 2505 | GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, |
2492 | &ubs.purpose, | 2506 | &ubs.purpose, |
2493 | &bi->bcm.sender_sig)); | 2507 | &bi->bcm.sender_sig)); |
2494 | bi->broadcast_task = GNUNET_SCHEDULER_add_now(&ifc_broadcast, bi); | 2508 | bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi); |
2495 | GNUNET_CONTAINER_DLL_insert(bi_head, bi_tail, bi); | 2509 | GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi); |
2496 | if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr)) | 2510 | if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr)) |
2511 | { | ||
2512 | /* Create IPv6 multicast request */ | ||
2513 | const struct sockaddr_in6 *s6 = | ||
2514 | (const struct sockaddr_in6 *) broadcast_addr; | ||
2515 | |||
2516 | GNUNET_assert ( | ||
2517 | 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); | ||
2518 | |||
2519 | /* http://tools.ietf.org/html/rfc2553#section-5.2: | ||
2520 | * | ||
2521 | * IPV6_JOIN_GROUP | ||
2522 | * | ||
2523 | * Join a multicast group on a specified local interface. If the | ||
2524 | * interface index is specified as 0, the kernel chooses the local | ||
2525 | * interface. For example, some kernels look up the multicast | ||
2526 | * group in the normal IPv6 routing table and using the resulting | ||
2527 | * interface; we do this for each interface, so no need to use | ||
2528 | * zero (anymore...). | ||
2529 | */ | ||
2530 | bi->mcreq.ipv6mr_interface = s6->sin6_scope_id; | ||
2531 | |||
2532 | /* Join the multicast group */ | ||
2533 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, | ||
2534 | IPPROTO_IPV6, | ||
2535 | IPV6_JOIN_GROUP, | ||
2536 | &bi->mcreq, | ||
2537 | sizeof(bi->mcreq))) | ||
2497 | { | 2538 | { |
2498 | /* Create IPv6 multicast request */ | 2539 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); |
2499 | const struct sockaddr_in6 *s6 = | ||
2500 | (const struct sockaddr_in6 *)broadcast_addr; | ||
2501 | |||
2502 | GNUNET_assert( | ||
2503 | 1 == inet_pton(AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr)); | ||
2504 | |||
2505 | /* http://tools.ietf.org/html/rfc2553#section-5.2: | ||
2506 | * | ||
2507 | * IPV6_JOIN_GROUP | ||
2508 | * | ||
2509 | * Join a multicast group on a specified local interface. If the | ||
2510 | * interface index is specified as 0, the kernel chooses the local | ||
2511 | * interface. For example, some kernels look up the multicast | ||
2512 | * group in the normal IPv6 routing table and using the resulting | ||
2513 | * interface; we do this for each interface, so no need to use | ||
2514 | * zero (anymore...). | ||
2515 | */ | ||
2516 | bi->mcreq.ipv6mr_interface = s6->sin6_scope_id; | ||
2517 | |||
2518 | /* Join the multicast group */ | ||
2519 | if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock, | ||
2520 | IPPROTO_IPV6, | ||
2521 | IPV6_JOIN_GROUP, | ||
2522 | &bi->mcreq, | ||
2523 | sizeof(bi->mcreq))) | ||
2524 | { | ||
2525 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt"); | ||
2526 | } | ||
2527 | } | 2540 | } |
2541 | } | ||
2528 | return GNUNET_OK; | 2542 | return GNUNET_OK; |
2529 | } | 2543 | } |
2530 | 2544 | ||
@@ -2535,23 +2549,23 @@ iface_proc(void *cls, | |||
2535 | * @param cls NULL, unused | 2549 | * @param cls NULL, unused |
2536 | */ | 2550 | */ |
2537 | static void | 2551 | static void |
2538 | do_broadcast(void *cls) | 2552 | do_broadcast (void *cls) |
2539 | { | 2553 | { |
2540 | struct BroadcastInterface *bin; | 2554 | struct BroadcastInterface *bin; |
2541 | 2555 | ||
2542 | (void)cls; | 2556 | (void) cls; |
2543 | for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next) | 2557 | for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next) |
2544 | bi->found = GNUNET_NO; | 2558 | bi->found = GNUNET_NO; |
2545 | GNUNET_OS_network_interfaces_list(&iface_proc, NULL); | 2559 | GNUNET_OS_network_interfaces_list (&iface_proc, NULL); |
2546 | for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin) | 2560 | for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin) |
2547 | { | 2561 | { |
2548 | bin = bi->next; | 2562 | bin = bi->next; |
2549 | if (GNUNET_NO == bi->found) | 2563 | if (GNUNET_NO == bi->found) |
2550 | bi_destroy(bi); | 2564 | bi_destroy (bi); |
2551 | } | 2565 | } |
2552 | broadcast_task = GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, | 2566 | broadcast_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, |
2553 | &do_broadcast, | 2567 | &do_broadcast, |
2554 | NULL); | 2568 | NULL); |
2555 | } | 2569 | } |
2556 | 2570 | ||
2557 | 2571 | ||
@@ -2564,10 +2578,10 @@ do_broadcast(void *cls) | |||
2564 | * @param c configuration | 2578 | * @param c configuration |
2565 | */ | 2579 | */ |
2566 | static void | 2580 | static void |
2567 | run(void *cls, | 2581 | run (void *cls, |
2568 | char *const *args, | 2582 | char *const *args, |
2569 | const char *cfgfile, | 2583 | const char *cfgfile, |
2570 | const struct GNUNET_CONFIGURATION_Handle *c) | 2584 | const struct GNUNET_CONFIGURATION_Handle *c) |
2571 | { | 2585 | { |
2572 | char *bindto; | 2586 | char *bindto; |
2573 | struct sockaddr *in; | 2587 | struct sockaddr *in; |
@@ -2575,143 +2589,143 @@ run(void *cls, | |||
2575 | struct sockaddr_storage in_sto; | 2589 | struct sockaddr_storage in_sto; |
2576 | socklen_t sto_len; | 2590 | socklen_t sto_len; |
2577 | 2591 | ||
2578 | (void)cls; | 2592 | (void) cls; |
2579 | cfg = c; | 2593 | cfg = c; |
2580 | if (GNUNET_OK != | 2594 | if (GNUNET_OK != |
2581 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 2595 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
2582 | COMMUNICATOR_CONFIG_SECTION, | 2596 | COMMUNICATOR_CONFIG_SECTION, |
2583 | "BINDTO", | 2597 | "BINDTO", |
2584 | &bindto)) | 2598 | &bindto)) |
2585 | { | 2599 | { |
2586 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 2600 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
2587 | COMMUNICATOR_CONFIG_SECTION, | 2601 | COMMUNICATOR_CONFIG_SECTION, |
2588 | "BINDTO"); | 2602 | "BINDTO"); |
2589 | return; | 2603 | return; |
2590 | } | 2604 | } |
2591 | 2605 | ||
2592 | in = udp_address_to_sockaddr(bindto, &in_len); | 2606 | in = udp_address_to_sockaddr (bindto, &in_len); |
2593 | if (NULL == in) | 2607 | if (NULL == in) |
2594 | { | 2608 | { |
2595 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 2609 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2596 | "Failed to setup UDP socket address with path `%s'\n", | 2610 | "Failed to setup UDP socket address with path `%s'\n", |
2597 | bindto); | 2611 | bindto); |
2598 | GNUNET_free(bindto); | 2612 | GNUNET_free (bindto); |
2599 | return; | 2613 | return; |
2600 | } | 2614 | } |
2601 | udp_sock = | 2615 | udp_sock = |
2602 | GNUNET_NETWORK_socket_create(in->sa_family, SOCK_DGRAM, IPPROTO_UDP); | 2616 | GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP); |
2603 | if (NULL == udp_sock) | 2617 | if (NULL == udp_sock) |
2604 | { | 2618 | { |
2605 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); | 2619 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
2606 | GNUNET_free(in); | 2620 | GNUNET_free (in); |
2607 | GNUNET_free(bindto); | 2621 | GNUNET_free (bindto); |
2608 | return; | 2622 | return; |
2609 | } | 2623 | } |
2610 | if (AF_INET6 == in->sa_family) | 2624 | if (AF_INET6 == in->sa_family) |
2611 | have_v6_socket = GNUNET_YES; | 2625 | have_v6_socket = GNUNET_YES; |
2612 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind(udp_sock, in, in_len)) | 2626 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len)) |
2613 | { | 2627 | { |
2614 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto); | 2628 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); |
2615 | GNUNET_NETWORK_socket_close(udp_sock); | 2629 | GNUNET_NETWORK_socket_close (udp_sock); |
2616 | udp_sock = NULL; | 2630 | udp_sock = NULL; |
2617 | GNUNET_free(in); | 2631 | GNUNET_free (in); |
2618 | GNUNET_free(bindto); | 2632 | GNUNET_free (bindto); |
2619 | return; | 2633 | return; |
2620 | } | 2634 | } |
2621 | /* We might have bound to port 0, allowing the OS to figure it out; | 2635 | /* We might have bound to port 0, allowing the OS to figure it out; |
2622 | thus, get the real IN-address from the socket */ | 2636 | thus, get the real IN-address from the socket */ |
2623 | sto_len = sizeof(in_sto); | 2637 | sto_len = sizeof(in_sto); |
2624 | if (0 != getsockname(GNUNET_NETWORK_get_fd(udp_sock), | 2638 | if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock), |
2625 | (struct sockaddr *)&in_sto, | 2639 | (struct sockaddr *) &in_sto, |
2626 | &sto_len)) | 2640 | &sto_len)) |
2627 | { | 2641 | { |
2628 | memcpy(&in_sto, in, in_len); | 2642 | memcpy (&in_sto, in, in_len); |
2629 | sto_len = in_len; | 2643 | sto_len = in_len; |
2630 | } | 2644 | } |
2631 | GNUNET_free(in); | 2645 | GNUNET_free (in); |
2632 | GNUNET_free(bindto); | 2646 | GNUNET_free (bindto); |
2633 | in = (struct sockaddr *)&in_sto; | 2647 | in = (struct sockaddr *) &in_sto; |
2634 | in_len = sto_len; | 2648 | in_len = sto_len; |
2635 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2636 | "Bound to `%s'\n", | 2650 | "Bound to `%s'\n", |
2637 | GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len)); | 2651 | GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); |
2638 | switch (in->sa_family) | 2652 | switch (in->sa_family) |
2639 | { | 2653 | { |
2640 | case AF_INET: | 2654 | case AF_INET: |
2641 | my_port = ntohs(((struct sockaddr_in *)in)->sin_port); | 2655 | my_port = ntohs (((struct sockaddr_in *) in)->sin_port); |
2642 | break; | 2656 | break; |
2643 | 2657 | ||
2644 | case AF_INET6: | 2658 | case AF_INET6: |
2645 | my_port = ntohs(((struct sockaddr_in6 *)in)->sin6_port); | 2659 | my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port); |
2646 | break; | 2660 | break; |
2647 | 2661 | ||
2648 | default: | 2662 | default: |
2649 | GNUNET_break(0); | 2663 | GNUNET_break (0); |
2650 | my_port = 0; | 2664 | my_port = 0; |
2651 | } | 2665 | } |
2652 | stats = GNUNET_STATISTICS_create("C-UDP", cfg); | 2666 | stats = GNUNET_STATISTICS_create ("C-UDP", cfg); |
2653 | senders = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); | 2667 | senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
2654 | receivers = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES); | 2668 | receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); |
2655 | senders_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2669 | senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2656 | receivers_heap = | 2670 | receivers_heap = |
2657 | GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN); | 2671 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
2658 | key_cache = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_YES); | 2672 | key_cache = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_YES); |
2659 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); | 2673 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
2660 | is = GNUNET_NT_scanner_init(); | 2674 | is = GNUNET_NT_scanner_init (); |
2661 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg); | 2675 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); |
2662 | if (NULL == my_private_key) | 2676 | if (NULL == my_private_key) |
2663 | { | 2677 | { |
2664 | GNUNET_log( | 2678 | GNUNET_log ( |
2665 | GNUNET_ERROR_TYPE_ERROR, | 2679 | GNUNET_ERROR_TYPE_ERROR, |
2666 | _( | 2680 | _ ( |
2667 | "Transport service is lacking key configuration settings. Exiting.\n")); | 2681 | "Transport service is lacking key configuration settings. Exiting.\n")); |
2668 | GNUNET_SCHEDULER_shutdown(); | 2682 | GNUNET_SCHEDULER_shutdown (); |
2669 | return; | 2683 | return; |
2670 | } | 2684 | } |
2671 | GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key); | 2685 | GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); |
2672 | /* start reading */ | 2686 | /* start reading */ |
2673 | read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL, | 2687 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
2674 | udp_sock, | 2688 | udp_sock, |
2675 | &sock_read, | 2689 | &sock_read, |
2676 | NULL); | ||
2677 | ch = GNUNET_TRANSPORT_communicator_connect(cfg, | ||
2678 | COMMUNICATOR_CONFIG_SECTION, | ||
2679 | COMMUNICATOR_ADDRESS_PREFIX, | ||
2680 | GNUNET_TRANSPORT_CC_UNRELIABLE, | ||
2681 | &mq_init, | ||
2682 | NULL, | ||
2683 | &enc_notify_cb, | ||
2684 | NULL); | 2690 | NULL); |
2691 | ch = GNUNET_TRANSPORT_communicator_connect (cfg, | ||
2692 | COMMUNICATOR_CONFIG_SECTION, | ||
2693 | COMMUNICATOR_ADDRESS_PREFIX, | ||
2694 | GNUNET_TRANSPORT_CC_UNRELIABLE, | ||
2695 | &mq_init, | ||
2696 | NULL, | ||
2697 | &enc_notify_cb, | ||
2698 | NULL); | ||
2685 | if (NULL == ch) | 2699 | if (NULL == ch) |
2686 | { | 2700 | { |
2687 | GNUNET_break(0); | 2701 | GNUNET_break (0); |
2688 | GNUNET_SCHEDULER_shutdown(); | 2702 | GNUNET_SCHEDULER_shutdown (); |
2689 | return; | 2703 | return; |
2690 | } | 2704 | } |
2691 | ah = GNUNET_TRANSPORT_application_init(cfg); | 2705 | ah = GNUNET_TRANSPORT_application_init (cfg); |
2692 | if (NULL == ah) | 2706 | if (NULL == ah) |
2693 | { | 2707 | { |
2694 | GNUNET_break(0); | 2708 | GNUNET_break (0); |
2695 | GNUNET_SCHEDULER_shutdown(); | 2709 | GNUNET_SCHEDULER_shutdown (); |
2696 | return; | 2710 | return; |
2697 | } | 2711 | } |
2698 | /* start broadcasting */ | 2712 | /* start broadcasting */ |
2699 | if (GNUNET_YES != | 2713 | if (GNUNET_YES != |
2700 | GNUNET_CONFIGURATION_get_value_yesno(cfg, | 2714 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
2701 | COMMUNICATOR_CONFIG_SECTION, | 2715 | COMMUNICATOR_CONFIG_SECTION, |
2702 | "DISABLE_BROADCAST")) | 2716 | "DISABLE_BROADCAST")) |
2703 | { | 2717 | { |
2704 | broadcast_task = GNUNET_SCHEDULER_add_now(&do_broadcast, NULL); | 2718 | broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL); |
2705 | } | 2719 | } |
2706 | nat = GNUNET_NAT_register(cfg, | 2720 | nat = GNUNET_NAT_register (cfg, |
2707 | COMMUNICATOR_CONFIG_SECTION, | 2721 | COMMUNICATOR_CONFIG_SECTION, |
2708 | IPPROTO_UDP, | 2722 | IPPROTO_UDP, |
2709 | 1 /* one address */, | 2723 | 1 /* one address */, |
2710 | (const struct sockaddr **)&in, | 2724 | (const struct sockaddr **) &in, |
2711 | &in_len, | 2725 | &in_len, |
2712 | &nat_address_cb, | 2726 | &nat_address_cb, |
2713 | NULL /* FIXME: support reversal: #5529 */, | 2727 | NULL /* FIXME: support reversal: #5529 */, |
2714 | NULL /* closure */); | 2728 | NULL /* closure */); |
2715 | } | 2729 | } |
2716 | 2730 | ||
2717 | 2731 | ||
@@ -2723,26 +2737,26 @@ run(void *cls, | |||
2723 | * @return 0 ok, 1 on error | 2737 | * @return 0 ok, 1 on error |
2724 | */ | 2738 | */ |
2725 | int | 2739 | int |
2726 | main(int argc, char *const *argv) | 2740 | main (int argc, char *const *argv) |
2727 | { | 2741 | { |
2728 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 2742 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
2729 | GNUNET_GETOPT_OPTION_END | 2743 | GNUNET_GETOPT_OPTION_END |
2730 | }; | 2744 | }; |
2731 | int ret; | 2745 | int ret; |
2732 | 2746 | ||
2733 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 2747 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
2734 | return 2; | 2748 | return 2; |
2735 | 2749 | ||
2736 | ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, | 2750 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, |
2737 | argv, | 2751 | argv, |
2738 | "gnunet-communicator-udp", | 2752 | "gnunet-communicator-udp", |
2739 | _("GNUnet UDP communicator"), | 2753 | _ ("GNUnet UDP communicator"), |
2740 | options, | 2754 | options, |
2741 | &run, | 2755 | &run, |
2742 | NULL)) | 2756 | NULL)) |
2743 | ? 0 | 2757 | ? 0 |
2744 | : 1; | 2758 | : 1; |
2745 | GNUNET_free((void *)argv); | 2759 | GNUNET_free ((void *) argv); |
2746 | return ret; | 2760 | return ret; |
2747 | } | 2761 | } |
2748 | 2762 | ||