diff options
-rw-r--r-- | src/ats/plugin_ats2_simple.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_hello_lib.h | 4 | ||||
-rw-r--r-- | src/include/gnunet_peerstore_service.h | 12 | ||||
-rw-r--r-- | src/include/gnunet_transport_communication_service.h | 22 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 460 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 692 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 117 | ||||
-rw-r--r-- | src/transport/gnunet-service-tng.c | 294 | ||||
-rw-r--r-- | src/transport/transport.h | 6 | ||||
-rw-r--r-- | src/transport/transport_api2_communication.c | 23 |
10 files changed, 849 insertions, 785 deletions
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c index dacd2e122..449b50fb7 100644 --- a/src/ats/plugin_ats2_simple.c +++ b/src/ats/plugin_ats2_simple.c | |||
@@ -500,7 +500,7 @@ watch_cb (void *cls, | |||
500 | return; | 500 | return; |
501 | } | 501 | } |
502 | if (0 != strcmp (record->key, | 502 | if (0 != strcmp (record->key, |
503 | GNUNET_HELLO_PEERSTORE_KEY)) | 503 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) |
504 | { | 504 | { |
505 | GNUNET_break (0); | 505 | GNUNET_break (0); |
506 | return; | 506 | return; |
@@ -590,7 +590,7 @@ peer_add (struct SimpleHandle *h, | |||
590 | p->wc = GNUNET_PEERSTORE_watch (h->ps, | 590 | p->wc = GNUNET_PEERSTORE_watch (h->ps, |
591 | "transport", | 591 | "transport", |
592 | &p->pid, | 592 | &p->pid, |
593 | GNUNET_HELLO_PEERSTORE_KEY, | 593 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, |
594 | &watch_cb, | 594 | &watch_cb, |
595 | p); | 595 | p); |
596 | GNUNET_assert (GNUNET_YES == | 596 | GNUNET_assert (GNUNET_YES == |
diff --git a/src/include/gnunet_hello_lib.h b/src/include/gnunet_hello_lib.h index 5e2190cc6..c46e847f1 100644 --- a/src/include/gnunet_hello_lib.h +++ b/src/include/gnunet_hello_lib.h | |||
@@ -478,10 +478,6 @@ GNUNET_HELLO_parse_uri (const char *uri, | |||
478 | /* NG API */ | 478 | /* NG API */ |
479 | #include "gnunet_nt_lib.h" | 479 | #include "gnunet_nt_lib.h" |
480 | 480 | ||
481 | /** | ||
482 | * Key used for storing HELLOs in the peerstore | ||
483 | */ | ||
484 | #define GNUNET_HELLO_PEERSTORE_KEY "hello" | ||
485 | 481 | ||
486 | /** | 482 | /** |
487 | * Build address record by signing raw information with private key. | 483 | * Build address record by signing raw information with private key. |
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h index 31567c004..1d7e2259a 100644 --- a/src/include/gnunet_peerstore_service.h +++ b/src/include/gnunet_peerstore_service.h | |||
@@ -43,6 +43,18 @@ extern "C" | |||
43 | #endif | 43 | #endif |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | |||
47 | /** | ||
48 | * Key used for storing addresses in URL format in the peerstore | ||
49 | */ | ||
50 | #define GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY "transport-address" | ||
51 | |||
52 | /** | ||
53 | * Key used for storing HELLOs in the peerstore | ||
54 | */ | ||
55 | #define GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY "transport-address" | ||
56 | |||
57 | |||
46 | /** | 58 | /** |
47 | * Options for storing values in PEERSTORE | 59 | * Options for storing values in PEERSTORE |
48 | */ | 60 | */ |
diff --git a/src/include/gnunet_transport_communication_service.h b/src/include/gnunet_transport_communication_service.h index b3dfccc9a..b4a0ce9c8 100644 --- a/src/include/gnunet_transport_communication_service.h +++ b/src/include/gnunet_transport_communication_service.h | |||
@@ -121,7 +121,7 @@ enum GNUNET_TRANSPORT_CommunicatorCharacteristics { | |||
121 | */ | 121 | */ |
122 | typedef void | 122 | typedef void |
123 | (*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls, | 123 | (*GNUNET_TRANSPORT_CommunicatorNotify) (void *cls, |
124 | const struct GNUNET_PeerIdentity *sender, | 124 | const struct GNUNET_PeerIdentity *sender, |
125 | const struct GNUNET_MessageHeader *msg); | 125 | const struct GNUNET_MessageHeader *msg); |
126 | 126 | ||
127 | 127 | ||
@@ -144,12 +144,12 @@ typedef void | |||
144 | struct GNUNET_TRANSPORT_CommunicatorHandle * | 144 | struct GNUNET_TRANSPORT_CommunicatorHandle * |
145 | GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 145 | GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, |
146 | const char *config_section_name, | 146 | const char *config_section_name, |
147 | const char *addr_prefix, | 147 | const char *addr_prefix, |
148 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, | 148 | enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, |
149 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, | 149 | GNUNET_TRANSPORT_CommunicatorMqInit mq_init, |
150 | void *mq_init_cls, | 150 | void *mq_init_cls, |
151 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb, | 151 | GNUNET_TRANSPORT_CommunicatorNotify notify_cb, |
152 | void *notify_cb_cls); | 152 | void *notify_cb_cls); |
153 | 153 | ||
154 | 154 | ||
155 | /** | 155 | /** |
@@ -184,6 +184,9 @@ typedef void | |||
184 | * @param sender presumed sender of the message (details to be checked | 184 | * @param sender presumed sender of the message (details to be checked |
185 | * by higher layers) | 185 | * by higher layers) |
186 | * @param msg the message | 186 | * @param msg the message |
187 | * @param expected_addr_validity how long does the communicator believe it | ||
188 | * will continue to be able to receive messages from the same address | ||
189 | * on which it received this message? | ||
187 | * @param cb function to call once handling the message is done, NULL if | 190 | * @param cb function to call once handling the message is done, NULL if |
188 | * flow control is not supported by this communicator | 191 | * flow control is not supported by this communicator |
189 | * @param cb_cls closure for @a cb | 192 | * @param cb_cls closure for @a cb |
@@ -197,6 +200,7 @@ int | |||
197 | GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle, | 200 | GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle, |
198 | const struct GNUNET_PeerIdentity *sender, | 201 | const struct GNUNET_PeerIdentity *sender, |
199 | const struct GNUNET_MessageHeader *msg, | 202 | const struct GNUNET_MessageHeader *msg, |
203 | struct GNUNET_TIME_Relative expected_addr_validity, | ||
200 | GNUNET_TRANSPORT_MessageCompletedCallback cb, | 204 | GNUNET_TRANSPORT_MessageCompletedCallback cb, |
201 | void *cb_cls); | 205 | void *cb_cls); |
202 | 206 | ||
@@ -251,9 +255,9 @@ struct GNUNET_TRANSPORT_QueueHandle * | |||
251 | GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 255 | GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
252 | const struct GNUNET_PeerIdentity *peer, | 256 | const struct GNUNET_PeerIdentity *peer, |
253 | const char *address, | 257 | const char *address, |
254 | uint32_t mtu, | 258 | uint32_t mtu, |
255 | enum GNUNET_NetworkType nt, | 259 | enum GNUNET_NetworkType nt, |
256 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 260 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
257 | struct GNUNET_MQ_Handle *mq); | 261 | struct GNUNET_MQ_Handle *mq); |
258 | 262 | ||
259 | 263 | ||
@@ -320,9 +324,9 @@ GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIde | |||
320 | */ | 324 | */ |
321 | void | 325 | void |
322 | GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 326 | GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
323 | const struct GNUNET_PeerIdentity *pid, | 327 | const struct GNUNET_PeerIdentity *pid, |
324 | const char *comm, | 328 | const char *comm, |
325 | const struct GNUNET_MessageHeader *header); | 329 | const struct GNUNET_MessageHeader *header); |
326 | 330 | ||
327 | 331 | ||
328 | #if 0 /* keep Emacsens' auto-indent happy */ | 332 | #if 0 /* keep Emacsens' auto-indent happy */ |
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 95719852c..a8f88c5e4 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -43,6 +43,12 @@ | |||
43 | #include "gnunet_transport_communication_service.h" | 43 | #include "gnunet_transport_communication_service.h" |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How long do we believe our addresses to remain up (before | ||
47 | * the other peer should revalidate). | ||
48 | */ | ||
49 | #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) | ||
50 | |||
51 | /** | ||
46 | * How many messages do we keep at most in the queue to the | 52 | * How many messages do we keep at most in the queue to the |
47 | * transport service before we start to drop (default, | 53 | * transport service before we start to drop (default, |
48 | * can be changed via the configuration file). | 54 | * can be changed via the configuration file). |
@@ -582,8 +588,8 @@ queue_destroy (struct Queue *queue) | |||
582 | struct GNUNET_MQ_Handle *mq; | 588 | struct GNUNET_MQ_Handle *mq; |
583 | 589 | ||
584 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Disconnecting queue for peer `%s'\n", | 591 | "Disconnecting queue for peer `%s'\n", |
586 | GNUNET_i2s (&queue->target)); | 592 | GNUNET_i2s (&queue->target)); |
587 | if (NULL != (mq = queue->mq)) | 593 | if (NULL != (mq = queue->mq)) |
588 | { | 594 | { |
589 | queue->mq = NULL; | 595 | queue->mq = NULL; |
@@ -599,9 +605,9 @@ queue_destroy (struct Queue *queue) | |||
599 | &queue->target, | 605 | &queue->target, |
600 | queue)); | 606 | queue)); |
601 | GNUNET_STATISTICS_set (stats, | 607 | GNUNET_STATISTICS_set (stats, |
602 | "# queues active", | 608 | "# queues active", |
603 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 609 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
604 | GNUNET_NO); | 610 | GNUNET_NO); |
605 | if (NULL != queue->read_task) | 611 | if (NULL != queue->read_task) |
606 | { | 612 | { |
607 | GNUNET_SCHEDULER_cancel (queue->read_task); | 613 | GNUNET_SCHEDULER_cancel (queue->read_task); |
@@ -622,9 +628,9 @@ queue_destroy (struct Queue *queue) | |||
622 | GNUNET_free (queue); | 628 | GNUNET_free (queue); |
623 | if (NULL == listen_task) | 629 | if (NULL == listen_task) |
624 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 630 | listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
625 | listen_sock, | 631 | listen_sock, |
626 | &listen_cb, | 632 | &listen_cb, |
627 | NULL); | 633 | NULL); |
628 | } | 634 | } |
629 | 635 | ||
630 | 636 | ||
@@ -645,18 +651,18 @@ calculate_hmac (struct GNUNET_HashCode *hmac_secret, | |||
645 | struct GNUNET_HashCode mac; | 651 | struct GNUNET_HashCode mac; |
646 | 652 | ||
647 | GNUNET_CRYPTO_hmac_raw (hmac_secret, | 653 | GNUNET_CRYPTO_hmac_raw (hmac_secret, |
648 | sizeof (struct GNUNET_HashCode), | 654 | sizeof (struct GNUNET_HashCode), |
649 | buf, | 655 | buf, |
650 | buf_size, | 656 | buf_size, |
651 | &mac); | 657 | &mac); |
652 | /* truncate to `struct GNUNET_ShortHashCode` */ | 658 | /* truncate to `struct GNUNET_ShortHashCode` */ |
653 | memcpy (smac, | 659 | memcpy (smac, |
654 | &mac, | 660 | &mac, |
655 | sizeof (struct GNUNET_ShortHashCode)); | 661 | sizeof (struct GNUNET_ShortHashCode)); |
656 | /* ratchet hmac key */ | 662 | /* ratchet hmac key */ |
657 | GNUNET_CRYPTO_hash (hmac_secret, | 663 | GNUNET_CRYPTO_hash (hmac_secret, |
658 | sizeof (struct GNUNET_HashCode), | 664 | sizeof (struct GNUNET_HashCode), |
659 | hmac_secret); | 665 | hmac_secret); |
660 | } | 666 | } |
661 | 667 | ||
662 | 668 | ||
@@ -728,15 +734,15 @@ queue_read (void *cls); | |||
728 | */ | 734 | */ |
729 | static void | 735 | static void |
730 | core_read_finished_cb (void *cls, | 736 | core_read_finished_cb (void *cls, |
731 | int success) | 737 | int success) |
732 | { | 738 | { |
733 | struct Queue *queue = cls; | 739 | struct Queue *queue = cls; |
734 | 740 | ||
735 | if (GNUNET_OK != success) | 741 | if (GNUNET_OK != success) |
736 | GNUNET_STATISTICS_update (stats, | 742 | GNUNET_STATISTICS_update (stats, |
737 | "# messages lost in communicator API towards CORE", | 743 | "# messages lost in communicator API towards CORE", |
738 | 1, | 744 | 1, |
739 | GNUNET_NO); | 745 | GNUNET_NO); |
740 | queue->backpressure--; | 746 | queue->backpressure--; |
741 | /* handle deferred queue destruction */ | 747 | /* handle deferred queue destruction */ |
742 | if ( (queue->destroyed) && | 748 | if ( (queue->destroyed) && |
@@ -750,9 +756,9 @@ core_read_finished_cb (void *cls, | |||
750 | if (NULL == queue->read_task) | 756 | if (NULL == queue->read_task) |
751 | queue->read_task | 757 | queue->read_task |
752 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (queue->timeout), | 758 | = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining (queue->timeout), |
753 | queue->sock, | 759 | queue->sock, |
754 | &queue_read, | 760 | &queue_read, |
755 | queue); | 761 | queue); |
756 | } | 762 | } |
757 | 763 | ||
758 | 764 | ||
@@ -767,8 +773,8 @@ core_read_finished_cb (void *cls, | |||
767 | */ | 773 | */ |
768 | static void | 774 | static void |
769 | pass_plaintext_to_core (struct Queue *queue, | 775 | pass_plaintext_to_core (struct Queue *queue, |
770 | const void *plaintext, | 776 | const void *plaintext, |
771 | size_t plaintext_len) | 777 | size_t plaintext_len) |
772 | { | 778 | { |
773 | const struct GNUNET_MessageHeader *hdr = plaintext; | 779 | const struct GNUNET_MessageHeader *hdr = plaintext; |
774 | int ret; | 780 | int ret; |
@@ -781,18 +787,19 @@ pass_plaintext_to_core (struct Queue *queue, | |||
781 | return; | 787 | return; |
782 | } | 788 | } |
783 | ret = GNUNET_TRANSPORT_communicator_receive (ch, | 789 | ret = GNUNET_TRANSPORT_communicator_receive (ch, |
784 | &queue->target, | 790 | &queue->target, |
785 | hdr, | 791 | hdr, |
786 | &core_read_finished_cb, | 792 | ADDRESS_VALIDITY_PERIOD, |
787 | queue); | 793 | &core_read_finished_cb, |
794 | queue); | ||
788 | if (GNUNET_OK == ret) | 795 | if (GNUNET_OK == ret) |
789 | queue->backpressure++; | 796 | queue->backpressure++; |
790 | GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ | 797 | GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ |
791 | if (GNUNET_SYSERR == ret) | 798 | if (GNUNET_SYSERR == ret) |
792 | GNUNET_STATISTICS_update (stats, | 799 | GNUNET_STATISTICS_update (stats, |
793 | "# bytes lost due to CORE not running", | 800 | "# bytes lost due to CORE not running", |
794 | plaintext_len, | 801 | plaintext_len, |
795 | GNUNET_NO); | 802 | GNUNET_NO); |
796 | } | 803 | } |
797 | 804 | ||
798 | 805 | ||
@@ -815,45 +822,45 @@ setup_cipher (const struct GNUNET_HashCode *dh, | |||
815 | char ctr[128/8]; | 822 | char ctr[128/8]; |
816 | 823 | ||
817 | gcry_cipher_open (cipher, | 824 | gcry_cipher_open (cipher, |
818 | GCRY_CIPHER_AES256 /* low level: go for speed */, | 825 | GCRY_CIPHER_AES256 /* low level: go for speed */, |
819 | GCRY_CIPHER_MODE_CTR, | 826 | GCRY_CIPHER_MODE_CTR, |
820 | 0 /* flags */); | 827 | 0 /* flags */); |
821 | GNUNET_assert (GNUNET_YES == | 828 | GNUNET_assert (GNUNET_YES == |
822 | GNUNET_CRYPTO_kdf (key, | 829 | GNUNET_CRYPTO_kdf (key, |
823 | sizeof (key), | 830 | sizeof (key), |
824 | "TCP-key", | 831 | "TCP-key", |
825 | strlen ("TCP-key"), | 832 | strlen ("TCP-key"), |
826 | dh, | 833 | dh, |
827 | sizeof (*dh), | 834 | sizeof (*dh), |
828 | pid, | 835 | pid, |
829 | sizeof (*pid), | 836 | sizeof (*pid), |
830 | NULL, 0)); | 837 | NULL, 0)); |
831 | gcry_cipher_setkey (*cipher, | 838 | gcry_cipher_setkey (*cipher, |
832 | key, | 839 | key, |
833 | sizeof (key)); | 840 | sizeof (key)); |
834 | GNUNET_assert (GNUNET_YES == | 841 | GNUNET_assert (GNUNET_YES == |
835 | GNUNET_CRYPTO_kdf (ctr, | 842 | GNUNET_CRYPTO_kdf (ctr, |
836 | sizeof (ctr), | 843 | sizeof (ctr), |
837 | "TCP-ctr", | 844 | "TCP-ctr", |
838 | strlen ("TCP-ctr"), | 845 | strlen ("TCP-ctr"), |
839 | dh, | 846 | dh, |
840 | sizeof (*dh), | 847 | sizeof (*dh), |
841 | pid, | 848 | pid, |
842 | sizeof (*pid), | 849 | sizeof (*pid), |
843 | NULL, 0)); | 850 | NULL, 0)); |
844 | gcry_cipher_setctr (*cipher, | 851 | gcry_cipher_setctr (*cipher, |
845 | ctr, | 852 | ctr, |
846 | sizeof (ctr)); | 853 | sizeof (ctr)); |
847 | GNUNET_assert (GNUNET_YES == | 854 | GNUNET_assert (GNUNET_YES == |
848 | GNUNET_CRYPTO_kdf (hmac_key, | 855 | GNUNET_CRYPTO_kdf (hmac_key, |
849 | sizeof (struct GNUNET_HashCode), | 856 | sizeof (struct GNUNET_HashCode), |
850 | "TCP-hmac", | 857 | "TCP-hmac", |
851 | strlen ("TCP-hmac"), | 858 | strlen ("TCP-hmac"), |
852 | dh, | 859 | dh, |
853 | sizeof (*dh), | 860 | sizeof (*dh), |
854 | pid, | 861 | pid, |
855 | sizeof (*pid), | 862 | sizeof (*pid), |
856 | NULL, 0)); | 863 | NULL, 0)); |
857 | } | 864 | } |
858 | 865 | ||
859 | 866 | ||
@@ -870,12 +877,12 @@ setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, | |||
870 | struct GNUNET_HashCode dh; | 877 | struct GNUNET_HashCode dh; |
871 | 878 | ||
872 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, | 879 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, |
873 | ephemeral, | 880 | ephemeral, |
874 | &dh); | 881 | &dh); |
875 | setup_cipher (&dh, | 882 | setup_cipher (&dh, |
876 | &my_identity, | 883 | &my_identity, |
877 | &queue->in_cipher, | 884 | &queue->in_cipher, |
878 | &queue->in_hmac); | 885 | &queue->in_hmac); |
879 | } | 886 | } |
880 | 887 | ||
881 | 888 | ||
@@ -901,9 +908,9 @@ do_rekey (struct Queue *queue, | |||
901 | thp.monotonic_time = rekey->monotonic_time; | 908 | thp.monotonic_time = rekey->monotonic_time; |
902 | if (GNUNET_OK != | 909 | if (GNUNET_OK != |
903 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, | 910 | GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, |
904 | &thp.purpose, | 911 | &thp.purpose, |
905 | &rekey->sender_sig, | 912 | &rekey->sender_sig, |
906 | &queue->target.public_key)) | 913 | &queue->target.public_key)) |
907 | { | 914 | { |
908 | GNUNET_break (0); | 915 | GNUNET_break (0); |
909 | queue_finish (queue); | 916 | queue_finish (queue); |
@@ -912,7 +919,7 @@ do_rekey (struct Queue *queue, | |||
912 | gcry_cipher_close (queue->in_cipher); | 919 | gcry_cipher_close (queue->in_cipher); |
913 | queue->rekeyed = GNUNET_YES; | 920 | queue->rekeyed = GNUNET_YES; |
914 | setup_in_cipher (&rekey->ephemeral, | 921 | setup_in_cipher (&rekey->ephemeral, |
915 | queue); | 922 | queue); |
916 | } | 923 | } |
917 | 924 | ||
918 | 925 | ||
@@ -954,16 +961,16 @@ try_handle_plaintext (struct Queue *queue) | |||
954 | ntohs (hdr->size), | 961 | ntohs (hdr->size), |
955 | &tmac); | 962 | &tmac); |
956 | if (0 != memcmp (&tmac, | 963 | if (0 != memcmp (&tmac, |
957 | &box->hmac, | 964 | &box->hmac, |
958 | sizeof (tmac))) | 965 | sizeof (tmac))) |
959 | { | 966 | { |
960 | GNUNET_break_op (0); | 967 | GNUNET_break_op (0); |
961 | queue_finish (queue); | 968 | queue_finish (queue); |
962 | return 0; | 969 | return 0; |
963 | } | 970 | } |
964 | pass_plaintext_to_core (queue, | 971 | pass_plaintext_to_core (queue, |
965 | (const void *) &box[1], | 972 | (const void *) &box[1], |
966 | ntohs (hdr->size)); | 973 | ntohs (hdr->size)); |
967 | size = ntohs (hdr->size) + sizeof (*box); | 974 | size = ntohs (hdr->size) + sizeof (*box); |
968 | break; | 975 | break; |
969 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: | 976 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY: |
@@ -1013,8 +1020,8 @@ try_handle_plaintext (struct Queue *queue) | |||
1013 | sizeof (rekeyz), | 1020 | sizeof (rekeyz), |
1014 | &tmac); | 1021 | &tmac); |
1015 | if (0 != memcmp (&tmac, | 1022 | if (0 != memcmp (&tmac, |
1016 | &fin->hmac, | 1023 | &fin->hmac, |
1017 | sizeof (tmac))) | 1024 | sizeof (tmac))) |
1018 | { | 1025 | { |
1019 | GNUNET_break_op (0); | 1026 | GNUNET_break_op (0); |
1020 | queue_finish (queue); | 1027 | queue_finish (queue); |
@@ -1047,24 +1054,24 @@ queue_read (void *cls) | |||
1047 | 1054 | ||
1048 | queue->read_task = NULL; | 1055 | queue->read_task = NULL; |
1049 | rcvd = GNUNET_NETWORK_socket_recv (queue->sock, | 1056 | rcvd = GNUNET_NETWORK_socket_recv (queue->sock, |
1050 | &queue->cread_buf[queue->cread_off], | 1057 | &queue->cread_buf[queue->cread_off], |
1051 | BUF_SIZE - queue->cread_off); | 1058 | BUF_SIZE - queue->cread_off); |
1052 | if (-1 == rcvd) | 1059 | if (-1 == rcvd) |
1053 | { | 1060 | { |
1054 | if ( (EAGAIN != errno) && | 1061 | if ( (EAGAIN != errno) && |
1055 | (EINTR != errno) ) | 1062 | (EINTR != errno) ) |
1056 | { | 1063 | { |
1057 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, | 1064 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, |
1058 | "recv"); | 1065 | "recv"); |
1059 | queue_finish (queue); | 1066 | queue_finish (queue); |
1060 | return; | 1067 | return; |
1061 | } | 1068 | } |
1062 | /* try again */ | 1069 | /* try again */ |
1063 | queue->read_task | 1070 | queue->read_task |
1064 | = GNUNET_SCHEDULER_add_read_net (left, | 1071 | = GNUNET_SCHEDULER_add_read_net (left, |
1065 | queue->sock, | 1072 | queue->sock, |
1066 | &queue_read, | 1073 | &queue_read, |
1067 | queue); | 1074 | queue); |
1068 | return; | 1075 | return; |
1069 | } | 1076 | } |
1070 | if (0 != rcvd) | 1077 | if (0 != rcvd) |
@@ -1074,16 +1081,16 @@ queue_read (void *cls) | |||
1074 | (queue->cread_off > 0) ) | 1081 | (queue->cread_off > 0) ) |
1075 | { | 1082 | { |
1076 | size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off, | 1083 | size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off, |
1077 | queue->cread_off); | 1084 | queue->cread_off); |
1078 | size_t done; | 1085 | size_t done; |
1079 | size_t total; | 1086 | size_t total; |
1080 | 1087 | ||
1081 | GNUNET_assert (0 == | 1088 | GNUNET_assert (0 == |
1082 | gcry_cipher_decrypt (queue->in_cipher, | 1089 | gcry_cipher_decrypt (queue->in_cipher, |
1083 | &queue->pread_buf[queue->pread_off], | 1090 | &queue->pread_buf[queue->pread_off], |
1084 | max, | 1091 | max, |
1085 | queue->cread_buf, | 1092 | queue->cread_buf, |
1086 | max)); | 1093 | max)); |
1087 | queue->pread_off += max; | 1094 | queue->pread_off += max; |
1088 | total = 0; | 1095 | total = 0; |
1089 | while ( (GNUNET_NO == queue->rekeyed) && | 1096 | while ( (GNUNET_NO == queue->rekeyed) && |
@@ -1095,8 +1102,8 @@ queue_read (void *cls) | |||
1095 | avoided if we pass 'total' into try_handle_plaintext() | 1102 | avoided if we pass 'total' into try_handle_plaintext() |
1096 | and use it at an offset into the buffer there! */ | 1103 | and use it at an offset into the buffer there! */ |
1097 | memmove (queue->pread_buf, | 1104 | memmove (queue->pread_buf, |
1098 | &queue->pread_buf[done], | 1105 | &queue->pread_buf[done], |
1099 | queue->pread_off - done); | 1106 | queue->pread_off - done); |
1100 | queue->pread_off -= done; | 1107 | queue->pread_off -= done; |
1101 | total += done; | 1108 | total += done; |
1102 | } | 1109 | } |
@@ -1111,8 +1118,8 @@ queue_read (void *cls) | |||
1111 | queue->rekeyed = GNUNET_NO; | 1118 | queue->rekeyed = GNUNET_NO; |
1112 | } | 1119 | } |
1113 | memmove (queue->cread_buf, | 1120 | memmove (queue->cread_buf, |
1114 | &queue->cread_buf[max], | 1121 | &queue->cread_buf[max], |
1115 | queue->cread_off - max); | 1122 | queue->cread_off - max); |
1116 | queue->cread_off -= max; | 1123 | queue->cread_off -= max; |
1117 | } | 1124 | } |
1118 | 1125 | ||
@@ -1126,17 +1133,17 @@ queue_read (void *cls) | |||
1126 | /* continue reading */ | 1133 | /* continue reading */ |
1127 | queue->read_task | 1134 | queue->read_task |
1128 | = GNUNET_SCHEDULER_add_read_net (left, | 1135 | = GNUNET_SCHEDULER_add_read_net (left, |
1129 | queue->sock, | 1136 | queue->sock, |
1130 | &queue_read, | 1137 | &queue_read, |
1131 | queue); | 1138 | queue); |
1132 | } | 1139 | } |
1133 | return; | 1140 | return; |
1134 | } | 1141 | } |
1135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1136 | "Queue %p was idle for %s, disconnecting\n", | 1143 | "Queue %p was idle for %s, disconnecting\n", |
1137 | queue, | 1144 | queue, |
1138 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1145 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1139 | GNUNET_YES)); | 1146 | GNUNET_YES)); |
1140 | queue_finish (queue); | 1147 | queue_finish (queue); |
1141 | } | 1148 | } |
1142 | 1149 | ||
@@ -1150,7 +1157,7 @@ queue_read (void *cls) | |||
1150 | */ | 1157 | */ |
1151 | static struct sockaddr * | 1158 | static struct sockaddr * |
1152 | tcp_address_to_sockaddr (const char *bindto, | 1159 | tcp_address_to_sockaddr (const char *bindto, |
1153 | socklen_t *sock_len) | 1160 | socklen_t *sock_len) |
1154 | { | 1161 | { |
1155 | struct sockaddr *in; | 1162 | struct sockaddr *in; |
1156 | unsigned int port; | 1163 | unsigned int port; |
@@ -1159,24 +1166,24 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1159 | char *cp; | 1166 | char *cp; |
1160 | 1167 | ||
1161 | if (1 == SSCANF (bindto, | 1168 | if (1 == SSCANF (bindto, |
1162 | "%u%1s", | 1169 | "%u%1s", |
1163 | &port, | 1170 | &port, |
1164 | dummy)) | 1171 | dummy)) |
1165 | { | 1172 | { |
1166 | /* interpreting value as just a PORT number */ | 1173 | /* interpreting value as just a PORT number */ |
1167 | if (port > UINT16_MAX) | 1174 | if (port > UINT16_MAX) |
1168 | { | 1175 | { |
1169 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1170 | "BINDTO specification `%s' invalid: value too large for port\n", | 1177 | "BINDTO specification `%s' invalid: value too large for port\n", |
1171 | bindto); | 1178 | bindto); |
1172 | return NULL; | 1179 | return NULL; |
1173 | } | 1180 | } |
1174 | if ( (GNUNET_NO == | 1181 | if ( (GNUNET_NO == |
1175 | GNUNET_NETWORK_test_pf (PF_INET6)) || | 1182 | GNUNET_NETWORK_test_pf (PF_INET6)) || |
1176 | (GNUNET_YES == | 1183 | (GNUNET_YES == |
1177 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1184 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1178 | COMMUNICATOR_CONFIG_SECTION, | 1185 | COMMUNICATOR_CONFIG_SECTION, |
1179 | "DISABLE_V6")) ) | 1186 | "DISABLE_V6")) ) |
1180 | { | 1187 | { |
1181 | struct sockaddr_in *i4; | 1188 | struct sockaddr_in *i4; |
1182 | 1189 | ||
@@ -1206,25 +1213,25 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1206 | *colon = '\0'; | 1213 | *colon = '\0'; |
1207 | colon++; | 1214 | colon++; |
1208 | if (1 == SSCANF (colon, | 1215 | if (1 == SSCANF (colon, |
1209 | "%u%1s", | 1216 | "%u%1s", |
1210 | &port, | 1217 | &port, |
1211 | dummy)) | 1218 | dummy)) |
1212 | { | 1219 | { |
1213 | /* interpreting value as just a PORT number */ | 1220 | /* interpreting value as just a PORT number */ |
1214 | if (port > UINT16_MAX) | 1221 | if (port > UINT16_MAX) |
1215 | { | 1222 | { |
1216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1223 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1217 | "BINDTO specification `%s' invalid: value too large for port\n", | 1224 | "BINDTO specification `%s' invalid: value too large for port\n", |
1218 | bindto); | 1225 | bindto); |
1219 | GNUNET_free (cp); | 1226 | GNUNET_free (cp); |
1220 | return NULL; | 1227 | return NULL; |
1221 | } | 1228 | } |
1222 | } | 1229 | } |
1223 | else | 1230 | else |
1224 | { | 1231 | { |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1226 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | 1233 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", |
1227 | bindto); | 1234 | bindto); |
1228 | GNUNET_free (cp); | 1235 | GNUNET_free (cp); |
1229 | return NULL; | 1236 | return NULL; |
1230 | } | 1237 | } |
@@ -1239,12 +1246,12 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1239 | struct sockaddr_in v4; | 1246 | struct sockaddr_in v4; |
1240 | 1247 | ||
1241 | if (1 == inet_pton (AF_INET, | 1248 | if (1 == inet_pton (AF_INET, |
1242 | cp, | 1249 | cp, |
1243 | &v4)) | 1250 | &v4)) |
1244 | { | 1251 | { |
1245 | v4.sin_port = htons ((uint16_t) port); | 1252 | v4.sin_port = htons ((uint16_t) port); |
1246 | in = GNUNET_memdup (&v4, | 1253 | in = GNUNET_memdup (&v4, |
1247 | sizeof (v4)); | 1254 | sizeof (v4)); |
1248 | *sock_len = sizeof (v4); | 1255 | *sock_len = sizeof (v4); |
1249 | GNUNET_free (cp); | 1256 | GNUNET_free (cp); |
1250 | return in; | 1257 | return in; |
@@ -1263,12 +1270,12 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1263 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ | 1270 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ |
1264 | } | 1271 | } |
1265 | if (1 == inet_pton (AF_INET6, | 1272 | if (1 == inet_pton (AF_INET6, |
1266 | start, | 1273 | start, |
1267 | &v6)) | 1274 | &v6)) |
1268 | { | 1275 | { |
1269 | v6.sin6_port = htons ((uint16_t) port); | 1276 | v6.sin6_port = htons ((uint16_t) port); |
1270 | in = GNUNET_memdup (&v6, | 1277 | in = GNUNET_memdup (&v6, |
1271 | sizeof (v6)); | 1278 | sizeof (v6)); |
1272 | *sock_len = sizeof (v6); | 1279 | *sock_len = sizeof (v6); |
1273 | GNUNET_free (cp); | 1280 | GNUNET_free (cp); |
1274 | return in; | 1281 | return in; |
@@ -1292,20 +1299,19 @@ setup_out_cipher (struct Queue *queue) | |||
1292 | struct GNUNET_HashCode dh; | 1299 | struct GNUNET_HashCode dh; |
1293 | 1300 | ||
1294 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, | 1301 | GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, |
1295 | &queue->target.public_key, | 1302 | &queue->target.public_key, |
1296 | &dh); | 1303 | &dh); |
1297 | /* we don't need the private key anymore, drop it! */ | 1304 | /* we don't need the private key anymore, drop it! */ |
1298 | memset (&queue->ephemeral, | 1305 | memset (&queue->ephemeral, |
1299 | 0, | 1306 | 0, |
1300 | sizeof (queue->ephemeral)); | 1307 | sizeof (queue->ephemeral)); |
1301 | setup_cipher (&dh, | 1308 | setup_cipher (&dh, |
1302 | &queue->target, | 1309 | &queue->target, |
1303 | &queue->out_cipher, | 1310 | &queue->out_cipher, |
1304 | &queue->out_hmac); | 1311 | &queue->out_hmac); |
1305 | |||
1306 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); | 1312 | queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); |
1307 | queue->rekey_left_bytes = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 1313 | queue->rekey_left_bytes = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
1308 | REKEY_MAX_BYTES); | 1314 | REKEY_MAX_BYTES); |
1309 | } | 1315 | } |
1310 | 1316 | ||
1311 | 1317 | ||
@@ -1323,14 +1329,14 @@ inject_rekey (struct Queue *queue) | |||
1323 | 1329 | ||
1324 | GNUNET_assert (0 == queue->pwrite_off); | 1330 | GNUNET_assert (0 == queue->pwrite_off); |
1325 | memset (&rekey, | 1331 | memset (&rekey, |
1326 | 0, | 1332 | 0, |
1327 | sizeof (rekey)); | 1333 | sizeof (rekey)); |
1328 | GNUNET_assert (GNUNET_OK == | 1334 | GNUNET_assert (GNUNET_OK == |
1329 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | 1335 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); |
1330 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); | 1336 | rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); |
1331 | rekey.header.size = ntohs (sizeof (rekey)); | 1337 | rekey.header.size = ntohs (sizeof (rekey)); |
1332 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, | 1338 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, |
1333 | &rekey.ephemeral); | 1339 | &rekey.ephemeral); |
1334 | rekey.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | 1340 | rekey.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); |
1335 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); | 1341 | thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); |
1336 | thp.purpose.size = htonl (sizeof (thp)); | 1342 | thp.purpose.size = htonl (sizeof (thp)); |
@@ -1339,16 +1345,16 @@ inject_rekey (struct Queue *queue) | |||
1339 | thp.ephemeral = rekey.ephemeral; | 1345 | thp.ephemeral = rekey.ephemeral; |
1340 | thp.monotonic_time = rekey.monotonic_time; | 1346 | thp.monotonic_time = rekey.monotonic_time; |
1341 | GNUNET_assert (GNUNET_OK == | 1347 | GNUNET_assert (GNUNET_OK == |
1342 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 1348 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1343 | &thp.purpose, | 1349 | &thp.purpose, |
1344 | &rekey.sender_sig)); | 1350 | &rekey.sender_sig)); |
1345 | calculate_hmac (&queue->out_hmac, | 1351 | calculate_hmac (&queue->out_hmac, |
1346 | &rekey, | 1352 | &rekey, |
1347 | sizeof (rekey), | 1353 | sizeof (rekey), |
1348 | &rekey.hmac); | 1354 | &rekey.hmac); |
1349 | memcpy (queue->pwrite_buf, | 1355 | memcpy (queue->pwrite_buf, |
1350 | &rekey, | 1356 | &rekey, |
1351 | sizeof (rekey)); | 1357 | sizeof (rekey)); |
1352 | queue->rekey_state = GNUNET_YES; | 1358 | queue->rekey_state = GNUNET_YES; |
1353 | } | 1359 | } |
1354 | 1360 | ||
@@ -1380,14 +1386,14 @@ queue_write (void *cls) | |||
1380 | 1386 | ||
1381 | queue->write_task = NULL; | 1387 | queue->write_task = NULL; |
1382 | sent = GNUNET_NETWORK_socket_send (queue->sock, | 1388 | sent = GNUNET_NETWORK_socket_send (queue->sock, |
1383 | queue->cwrite_buf, | 1389 | queue->cwrite_buf, |
1384 | queue->cwrite_off); | 1390 | queue->cwrite_off); |
1385 | if ( (-1 == sent) && | 1391 | if ( (-1 == sent) && |
1386 | (EAGAIN != errno) && | 1392 | (EAGAIN != errno) && |
1387 | (EINTR != errno) ) | 1393 | (EINTR != errno) ) |
1388 | { | 1394 | { |
1389 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1395 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
1390 | "send"); | 1396 | "send"); |
1391 | queue_destroy (queue); | 1397 | queue_destroy (queue); |
1392 | return; | 1398 | return; |
1393 | } | 1399 | } |
@@ -1396,8 +1402,8 @@ queue_write (void *cls) | |||
1396 | size_t usent = (size_t) sent; | 1402 | size_t usent = (size_t) sent; |
1397 | 1403 | ||
1398 | memmove (queue->cwrite_buf, | 1404 | memmove (queue->cwrite_buf, |
1399 | &queue->cwrite_buf[usent], | 1405 | &queue->cwrite_buf[usent], |
1400 | queue->cwrite_off - usent); | 1406 | queue->cwrite_off - usent); |
1401 | reschedule_queue_timeout (queue); | 1407 | reschedule_queue_timeout (queue); |
1402 | } | 1408 | } |
1403 | /* can we encrypt more? (always encrypt full messages, needed | 1409 | /* can we encrypt more? (always encrypt full messages, needed |
@@ -1405,11 +1411,11 @@ queue_write (void *cls) | |||
1405 | if (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE) | 1411 | if (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE) |
1406 | { | 1412 | { |
1407 | GNUNET_assert (0 == | 1413 | GNUNET_assert (0 == |
1408 | gcry_cipher_encrypt (queue->out_cipher, | 1414 | gcry_cipher_encrypt (queue->out_cipher, |
1409 | &queue->cwrite_buf[queue->cwrite_off], | 1415 | &queue->cwrite_buf[queue->cwrite_off], |
1410 | queue->pwrite_off, | 1416 | queue->pwrite_off, |
1411 | queue->pwrite_buf, | 1417 | queue->pwrite_buf, |
1412 | queue->pwrite_off)); | 1418 | queue->pwrite_off)); |
1413 | if (queue->rekey_left_bytes > queue->pwrite_off) | 1419 | if (queue->rekey_left_bytes > queue->pwrite_off) |
1414 | queue->rekey_left_bytes -= queue->pwrite_off; | 1420 | queue->rekey_left_bytes -= queue->pwrite_off; |
1415 | else | 1421 | else |
@@ -1442,9 +1448,9 @@ queue_write (void *cls) | |||
1442 | if (0 < queue->cwrite_off) | 1448 | if (0 < queue->cwrite_off) |
1443 | queue->write_task | 1449 | queue->write_task |
1444 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1450 | = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1445 | queue->sock, | 1451 | queue->sock, |
1446 | &queue_write, | 1452 | &queue_write, |
1447 | queue); | 1453 | queue); |
1448 | } | 1454 | } |
1449 | 1455 | ||
1450 | 1456 | ||
@@ -1458,8 +1464,8 @@ queue_write (void *cls) | |||
1458 | */ | 1464 | */ |
1459 | static void | 1465 | static void |
1460 | mq_send (struct GNUNET_MQ_Handle *mq, | 1466 | mq_send (struct GNUNET_MQ_Handle *mq, |
1461 | const struct GNUNET_MessageHeader *msg, | 1467 | const struct GNUNET_MessageHeader *msg, |
1462 | void *impl_state) | 1468 | void *impl_state) |
1463 | { | 1469 | { |
1464 | struct Queue *queue = impl_state; | 1470 | struct Queue *queue = impl_state; |
1465 | uint16_t msize = ntohs (msg->size); | 1471 | uint16_t msize = ntohs (msg->size); |
@@ -1476,12 +1482,12 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1476 | msize, | 1482 | msize, |
1477 | &box.hmac); | 1483 | &box.hmac); |
1478 | memcpy (&queue->pread_buf[queue->pread_off], | 1484 | memcpy (&queue->pread_buf[queue->pread_off], |
1479 | &box, | 1485 | &box, |
1480 | sizeof (box)); | 1486 | sizeof (box)); |
1481 | queue->pread_off += sizeof (box); | 1487 | queue->pread_off += sizeof (box); |
1482 | memcpy (&queue->pread_buf[queue->pread_off], | 1488 | memcpy (&queue->pread_buf[queue->pread_off], |
1483 | msg, | 1489 | msg, |
1484 | msize); | 1490 | msize); |
1485 | queue->pread_off += msize; | 1491 | queue->pread_off += msize; |
1486 | GNUNET_assert (NULL != queue->sock); | 1492 | GNUNET_assert (NULL != queue->sock); |
1487 | if (NULL == queue->write_task) | 1493 | if (NULL == queue->write_task) |
@@ -1489,7 +1495,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1489 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1495 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1490 | queue->sock, | 1496 | queue->sock, |
1491 | &queue_write, | 1497 | &queue_write, |
1492 | queue); | 1498 | queue); |
1493 | } | 1499 | } |
1494 | 1500 | ||
1495 | 1501 | ||
@@ -1503,7 +1509,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
1503 | */ | 1509 | */ |
1504 | static void | 1510 | static void |
1505 | mq_destroy (struct GNUNET_MQ_Handle *mq, | 1511 | mq_destroy (struct GNUNET_MQ_Handle *mq, |
1506 | void *impl_state) | 1512 | void *impl_state) |
1507 | { | 1513 | { |
1508 | struct Queue *queue = impl_state; | 1514 | struct Queue *queue = impl_state; |
1509 | 1515 | ||
@@ -1523,7 +1529,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, | |||
1523 | */ | 1529 | */ |
1524 | static void | 1530 | static void |
1525 | mq_cancel (struct GNUNET_MQ_Handle *mq, | 1531 | mq_cancel (struct GNUNET_MQ_Handle *mq, |
1526 | void *impl_state) | 1532 | void *impl_state) |
1527 | { | 1533 | { |
1528 | struct Queue *queue = impl_state; | 1534 | struct Queue *queue = impl_state; |
1529 | 1535 | ||
@@ -1543,14 +1549,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, | |||
1543 | */ | 1549 | */ |
1544 | static void | 1550 | static void |
1545 | mq_error (void *cls, | 1551 | mq_error (void *cls, |
1546 | enum GNUNET_MQ_Error error) | 1552 | enum GNUNET_MQ_Error error) |
1547 | { | 1553 | { |
1548 | struct Queue *queue = cls; | 1554 | struct Queue *queue = cls; |
1549 | 1555 | ||
1550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1556 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1551 | "MQ error in queue to %s: %d\n", | 1557 | "MQ error in queue to %s: %d\n", |
1552 | GNUNET_i2s (&queue->target), | 1558 | GNUNET_i2s (&queue->target), |
1553 | (int) error); | 1559 | (int) error); |
1554 | queue_finish (queue); | 1560 | queue_finish (queue); |
1555 | } | 1561 | } |
1556 | 1562 | ||
@@ -1567,26 +1573,26 @@ boot_queue (struct Queue *queue, | |||
1567 | enum GNUNET_TRANSPORT_ConnectionStatus cs) | 1573 | enum GNUNET_TRANSPORT_ConnectionStatus cs) |
1568 | { | 1574 | { |
1569 | queue->nt = GNUNET_NT_scanner_get_type (is, | 1575 | queue->nt = GNUNET_NT_scanner_get_type (is, |
1570 | queue->address, | 1576 | queue->address, |
1571 | queue->address_len); | 1577 | queue->address_len); |
1572 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, | 1578 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, |
1573 | &queue->target, | 1579 | &queue->target, |
1574 | queue, | 1580 | queue, |
1575 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1581 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1576 | GNUNET_STATISTICS_set (stats, | 1582 | GNUNET_STATISTICS_set (stats, |
1577 | "# queues active", | 1583 | "# queues active", |
1578 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 1584 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
1579 | GNUNET_NO); | 1585 | GNUNET_NO); |
1580 | queue->timeout | 1586 | queue->timeout |
1581 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1587 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1582 | queue->mq | 1588 | queue->mq |
1583 | = GNUNET_MQ_queue_for_callbacks (&mq_send, | 1589 | = GNUNET_MQ_queue_for_callbacks (&mq_send, |
1584 | &mq_destroy, | 1590 | &mq_destroy, |
1585 | &mq_cancel, | 1591 | &mq_cancel, |
1586 | queue, | 1592 | queue, |
1587 | NULL, | 1593 | NULL, |
1588 | &mq_error, | 1594 | &mq_error, |
1589 | queue); | 1595 | queue); |
1590 | { | 1596 | { |
1591 | char *foreign_addr; | 1597 | char *foreign_addr; |
1592 | 1598 | ||
@@ -1594,29 +1600,29 @@ boot_queue (struct Queue *queue, | |||
1594 | { | 1600 | { |
1595 | case AF_INET: | 1601 | case AF_INET: |
1596 | GNUNET_asprintf (&foreign_addr, | 1602 | GNUNET_asprintf (&foreign_addr, |
1597 | "%s-%s", | 1603 | "%s-%s", |
1598 | COMMUNICATOR_ADDRESS_PREFIX, | 1604 | COMMUNICATOR_ADDRESS_PREFIX, |
1599 | GNUNET_a2s(queue->address, | 1605 | GNUNET_a2s(queue->address, |
1600 | queue->address_len)); | 1606 | queue->address_len)); |
1601 | break; | 1607 | break; |
1602 | case AF_INET6: | 1608 | case AF_INET6: |
1603 | GNUNET_asprintf (&foreign_addr, | 1609 | GNUNET_asprintf (&foreign_addr, |
1604 | "%s-%s", | 1610 | "%s-%s", |
1605 | COMMUNICATOR_ADDRESS_PREFIX, | 1611 | COMMUNICATOR_ADDRESS_PREFIX, |
1606 | GNUNET_a2s(queue->address, | 1612 | GNUNET_a2s(queue->address, |
1607 | queue->address_len)); | 1613 | queue->address_len)); |
1608 | break; | 1614 | break; |
1609 | default: | 1615 | default: |
1610 | GNUNET_assert (0); | 1616 | GNUNET_assert (0); |
1611 | } | 1617 | } |
1612 | queue->qh | 1618 | queue->qh |
1613 | = GNUNET_TRANSPORT_communicator_mq_add (ch, | 1619 | = GNUNET_TRANSPORT_communicator_mq_add (ch, |
1614 | &queue->target, | 1620 | &queue->target, |
1615 | foreign_addr, | 1621 | foreign_addr, |
1616 | 0 /* no MTU */, | 1622 | 0 /* no MTU */, |
1617 | queue->nt, | 1623 | queue->nt, |
1618 | cs, | 1624 | cs, |
1619 | queue->mq); | 1625 | queue->mq); |
1620 | GNUNET_free (foreign_addr); | 1626 | GNUNET_free (foreign_addr); |
1621 | } | 1627 | } |
1622 | } | 1628 | } |
@@ -1640,8 +1646,8 @@ transmit_kx (struct Queue *queue, | |||
1640 | struct TCPConfirmation tc; | 1646 | struct TCPConfirmation tc; |
1641 | 1647 | ||
1642 | memcpy (queue->cwrite_buf, | 1648 | memcpy (queue->cwrite_buf, |
1643 | epub, | 1649 | epub, |
1644 | sizeof (*epub)); | 1650 | sizeof (*epub)); |
1645 | queue->cwrite_off = sizeof (epub); | 1651 | queue->cwrite_off = sizeof (epub); |
1646 | /* compute 'tc' and append in encrypted format to cwrite_buf */ | 1652 | /* compute 'tc' and append in encrypted format to cwrite_buf */ |
1647 | tc.sender = my_identity; | 1653 | tc.sender = my_identity; |
@@ -1653,15 +1659,15 @@ transmit_kx (struct Queue *queue, | |||
1653 | ths.ephemeral = *epub; | 1659 | ths.ephemeral = *epub; |
1654 | ths.monotonic_time = tc.monotonic_time; | 1660 | ths.monotonic_time = tc.monotonic_time; |
1655 | GNUNET_assert (GNUNET_OK == | 1661 | GNUNET_assert (GNUNET_OK == |
1656 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 1662 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
1657 | &ths.purpose, | 1663 | &ths.purpose, |
1658 | &tc.sender_sig)); | 1664 | &tc.sender_sig)); |
1659 | GNUNET_assert (0 == | 1665 | GNUNET_assert (0 == |
1660 | gcry_cipher_encrypt (queue->out_cipher, | 1666 | gcry_cipher_encrypt (queue->out_cipher, |
1661 | &queue->cwrite_buf[queue->cwrite_off], | 1667 | &queue->cwrite_buf[queue->cwrite_off], |
1662 | sizeof (tc), | 1668 | sizeof (tc), |
1663 | &tc, | 1669 | &tc, |
1664 | sizeof (tc))); | 1670 | sizeof (tc))); |
1665 | queue->cwrite_off += sizeof (tc); | 1671 | queue->cwrite_off += sizeof (tc); |
1666 | } | 1672 | } |
1667 | 1673 | ||
@@ -1681,10 +1687,10 @@ start_initial_kx_out (struct Queue *queue) | |||
1681 | GNUNET_assert (GNUNET_OK == | 1687 | GNUNET_assert (GNUNET_OK == |
1682 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); | 1688 | GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); |
1683 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, | 1689 | GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, |
1684 | &epub); | 1690 | &epub); |
1685 | setup_out_cipher (queue); | 1691 | setup_out_cipher (queue); |
1686 | transmit_kx (queue, | 1692 | transmit_kx (queue, |
1687 | &epub); | 1693 | &epub); |
1688 | } | 1694 | } |
1689 | 1695 | ||
1690 | 1696 | ||
@@ -1701,17 +1707,17 @@ start_initial_kx_out (struct Queue *queue) | |||
1701 | */ | 1707 | */ |
1702 | static int | 1708 | static int |
1703 | decrypt_and_check_tc (struct Queue *queue, | 1709 | decrypt_and_check_tc (struct Queue *queue, |
1704 | struct TCPConfirmation *tc, | 1710 | struct TCPConfirmation *tc, |
1705 | char *ibuf) | 1711 | char *ibuf) |
1706 | { | 1712 | { |
1707 | struct TcpHandshakeSignature ths; | 1713 | struct TcpHandshakeSignature ths; |
1708 | 1714 | ||
1709 | GNUNET_assert (0 == | 1715 | GNUNET_assert (0 == |
1710 | gcry_cipher_decrypt (queue->in_cipher, | 1716 | gcry_cipher_decrypt (queue->in_cipher, |
1711 | tc, | 1717 | tc, |
1712 | sizeof (*tc), | 1718 | sizeof (*tc), |
1713 | &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)], | 1719 | &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)], |
1714 | sizeof (tc))); | 1720 | sizeof (tc))); |
1715 | ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); | 1721 | ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); |
1716 | ths.purpose.size = htonl (sizeof (ths)); | 1722 | ths.purpose.size = htonl (sizeof (ths)); |
1717 | ths.sender = tc->sender; | 1723 | ths.sender = tc->sender; |
@@ -1721,9 +1727,9 @@ decrypt_and_check_tc (struct Queue *queue, | |||
1721 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); | 1727 | sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); |
1722 | ths.monotonic_time = tc->monotonic_time; | 1728 | ths.monotonic_time = tc->monotonic_time; |
1723 | return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, | 1729 | return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, |
1724 | &ths.purpose, | 1730 | &ths.purpose, |
1725 | &tc->sender_sig, | 1731 | &tc->sender_sig, |
1726 | &tc->sender.public_key); | 1732 | &tc->sender.public_key); |
1727 | } | 1733 | } |
1728 | 1734 | ||
1729 | 1735 | ||
@@ -1738,8 +1744,8 @@ free_proto_queue (struct ProtoQueue *pq) | |||
1738 | GNUNET_NETWORK_socket_close (pq->sock); | 1744 | GNUNET_NETWORK_socket_close (pq->sock); |
1739 | GNUNET_free (pq->address); | 1745 | GNUNET_free (pq->address); |
1740 | GNUNET_CONTAINER_DLL_remove (proto_head, | 1746 | GNUNET_CONTAINER_DLL_remove (proto_head, |
1741 | proto_tail, | 1747 | proto_tail, |
1742 | pq); | 1748 | pq); |
1743 | GNUNET_free (pq); | 1749 | GNUNET_free (pq); |
1744 | } | 1750 | } |
1745 | 1751 | ||
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index f101d2d75..1db5bba6b 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -69,6 +69,12 @@ | |||
69 | #define INTERFACE_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | 69 | #define INTERFACE_SCAN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
70 | 70 | ||
71 | /** | 71 | /** |
72 | * How long do we believe our addresses to remain up (before | ||
73 | * the other peer should revalidate). | ||
74 | */ | ||
75 | #define ADDRESS_VALIDITY_PERIOD GNUNET_TIME_UNIT_HOURS | ||
76 | |||
77 | /** | ||
72 | * AES key size. | 78 | * AES key size. |
73 | */ | 79 | */ |
74 | #define AES_KEY_SIZE (256/8) | 80 | #define AES_KEY_SIZE (256/8) |
@@ -964,11 +970,11 @@ sender_destroy (struct SenderAddress *sender) | |||
964 | &sender->target, | 970 | &sender->target, |
965 | sender)); | 971 | sender)); |
966 | GNUNET_assert (sender == | 972 | GNUNET_assert (sender == |
967 | GNUNET_CONTAINER_heap_remove_node (sender->hn)); | 973 | GNUNET_CONTAINER_heap_remove_node (sender->hn)); |
968 | GNUNET_STATISTICS_set (stats, | 974 | GNUNET_STATISTICS_set (stats, |
969 | "# senders active", | 975 | "# senders active", |
970 | GNUNET_CONTAINER_multipeermap_size (senders), | 976 | GNUNET_CONTAINER_multipeermap_size (senders), |
971 | GNUNET_NO); | 977 | GNUNET_NO); |
972 | GNUNET_free (sender->address); | 978 | GNUNET_free (sender->address); |
973 | GNUNET_free (sender); | 979 | GNUNET_free (sender); |
974 | } | 980 | } |
@@ -992,22 +998,22 @@ get_iv_key (const struct GNUNET_HashCode *msec, | |||
992 | char res[AES_KEY_SIZE + AES_IV_SIZE]; | 998 | char res[AES_KEY_SIZE + AES_IV_SIZE]; |
993 | 999 | ||
994 | GNUNET_CRYPTO_hkdf (res, | 1000 | GNUNET_CRYPTO_hkdf (res, |
995 | sizeof (res), | 1001 | sizeof (res), |
996 | GCRY_MD_SHA512, | 1002 | GCRY_MD_SHA512, |
997 | GCRY_MD_SHA256, | 1003 | GCRY_MD_SHA256, |
998 | &sid, | 1004 | &sid, |
999 | sizeof (sid), | 1005 | sizeof (sid), |
1000 | msec, | 1006 | msec, |
1001 | sizeof (*msec), | 1007 | sizeof (*msec), |
1002 | "UDP-IV-KEY", | 1008 | "UDP-IV-KEY", |
1003 | strlen ("UDP-IV-KEY"), | 1009 | strlen ("UDP-IV-KEY"), |
1004 | NULL, 0); | 1010 | NULL, 0); |
1005 | memcpy (key, | 1011 | memcpy (key, |
1006 | res, | 1012 | res, |
1007 | AES_KEY_SIZE); | 1013 | AES_KEY_SIZE); |
1008 | memcpy (iv, | 1014 | memcpy (iv, |
1009 | &res[AES_KEY_SIZE], | 1015 | &res[AES_KEY_SIZE], |
1010 | AES_IV_SIZE); | 1016 | AES_IV_SIZE); |
1011 | } | 1017 | } |
1012 | 1018 | ||
1013 | 1019 | ||
@@ -1022,7 +1028,7 @@ reschedule_sender_timeout (struct SenderAddress *sender) | |||
1022 | sender->timeout | 1028 | sender->timeout |
1023 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1029 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1024 | GNUNET_CONTAINER_heap_update_cost (sender->hn, | 1030 | GNUNET_CONTAINER_heap_update_cost (sender->hn, |
1025 | sender->timeout.abs_value_us); | 1031 | sender->timeout.abs_value_us); |
1026 | } | 1032 | } |
1027 | 1033 | ||
1028 | 1034 | ||
@@ -1091,16 +1097,16 @@ static void | |||
1091 | calculate_cmac (struct SharedSecret *ss) | 1097 | calculate_cmac (struct SharedSecret *ss) |
1092 | { | 1098 | { |
1093 | GNUNET_CRYPTO_hkdf (&ss->cmac, | 1099 | GNUNET_CRYPTO_hkdf (&ss->cmac, |
1094 | sizeof (ss->cmac), | 1100 | sizeof (ss->cmac), |
1095 | GCRY_MD_SHA512, | 1101 | GCRY_MD_SHA512, |
1096 | GCRY_MD_SHA256, | 1102 | GCRY_MD_SHA256, |
1097 | "CMAC", | 1103 | "CMAC", |
1098 | strlen ("CMAC"), | 1104 | strlen ("CMAC"), |
1099 | &ss->master, | 1105 | &ss->master, |
1100 | sizeof (ss->master), | 1106 | sizeof (ss->master), |
1101 | "UDP-CMAC", | 1107 | "UDP-CMAC", |
1102 | strlen ("UDP-CMAC"), | 1108 | strlen ("UDP-CMAC"), |
1103 | NULL, 0); | 1109 | NULL, 0); |
1104 | } | 1110 | } |
1105 | 1111 | ||
1106 | 1112 | ||
@@ -1114,8 +1120,8 @@ calculate_cmac (struct SharedSecret *ss) | |||
1114 | */ | 1120 | */ |
1115 | static void | 1121 | static void |
1116 | pass_plaintext_to_core (struct SenderAddress *sender, | 1122 | pass_plaintext_to_core (struct SenderAddress *sender, |
1117 | const void *plaintext, | 1123 | const void *plaintext, |
1118 | size_t plaintext_len) | 1124 | size_t plaintext_len) |
1119 | { | 1125 | { |
1120 | const struct GNUNET_MessageHeader *hdr = plaintext; | 1126 | const struct GNUNET_MessageHeader *hdr = plaintext; |
1121 | 1127 | ||
@@ -1126,10 +1132,11 @@ pass_plaintext_to_core (struct SenderAddress *sender, | |||
1126 | ntohs (hdr->size), | 1132 | ntohs (hdr->size), |
1127 | GNUNET_NO); | 1133 | GNUNET_NO); |
1128 | (void) GNUNET_TRANSPORT_communicator_receive (ch, | 1134 | (void) GNUNET_TRANSPORT_communicator_receive (ch, |
1129 | &sender->target, | 1135 | &sender->target, |
1130 | hdr, | 1136 | hdr, |
1131 | NULL /* no flow control possible */, | 1137 | ADDRESS_VALIDITY_PERIOD, |
1132 | NULL); | 1138 | NULL /* no flow control possible */, |
1139 | NULL); | ||
1133 | /* move on to next message, if any */ | 1140 | /* move on to next message, if any */ |
1134 | plaintext_len -= ntohs (hdr->size); | 1141 | plaintext_len -= ntohs (hdr->size); |
1135 | if (plaintext_len < sizeof (*hdr)) | 1142 | if (plaintext_len < sizeof (*hdr)) |
@@ -1137,9 +1144,9 @@ pass_plaintext_to_core (struct SenderAddress *sender, | |||
1137 | hdr = plaintext + ntohs (hdr->size); | 1144 | hdr = plaintext + ntohs (hdr->size); |
1138 | } | 1145 | } |
1139 | GNUNET_STATISTICS_update (stats, | 1146 | GNUNET_STATISTICS_update (stats, |
1140 | "# bytes padding discarded", | 1147 | "# bytes padding discarded", |
1141 | plaintext_len, | 1148 | plaintext_len, |
1142 | GNUNET_NO); | 1149 | GNUNET_NO); |
1143 | } | 1150 | } |
1144 | 1151 | ||
1145 | 1152 | ||
@@ -1153,26 +1160,26 @@ pass_plaintext_to_core (struct SenderAddress *sender, | |||
1153 | */ | 1160 | */ |
1154 | static void | 1161 | static void |
1155 | setup_cipher (const struct GNUNET_HashCode *msec, | 1162 | setup_cipher (const struct GNUNET_HashCode *msec, |
1156 | uint32_t serial, | 1163 | uint32_t serial, |
1157 | gcry_cipher_hd_t *cipher) | 1164 | gcry_cipher_hd_t *cipher) |
1158 | { | 1165 | { |
1159 | char key[AES_KEY_SIZE]; | 1166 | char key[AES_KEY_SIZE]; |
1160 | char iv[AES_IV_SIZE]; | 1167 | char iv[AES_IV_SIZE]; |
1161 | 1168 | ||
1162 | gcry_cipher_open (cipher, | 1169 | gcry_cipher_open (cipher, |
1163 | GCRY_CIPHER_AES256 /* low level: go for speed */, | 1170 | GCRY_CIPHER_AES256 /* low level: go for speed */, |
1164 | GCRY_CIPHER_MODE_GCM, | 1171 | GCRY_CIPHER_MODE_GCM, |
1165 | 0 /* flags */); | 1172 | 0 /* flags */); |
1166 | get_iv_key (msec, | 1173 | get_iv_key (msec, |
1167 | serial, | 1174 | serial, |
1168 | key, | 1175 | key, |
1169 | iv); | 1176 | iv); |
1170 | gcry_cipher_setkey (*cipher, | 1177 | gcry_cipher_setkey (*cipher, |
1171 | key, | 1178 | key, |
1172 | sizeof (key)); | 1179 | sizeof (key)); |
1173 | gcry_cipher_setiv (*cipher, | 1180 | gcry_cipher_setiv (*cipher, |
1174 | iv, | 1181 | iv, |
1175 | sizeof (iv)); | 1182 | sizeof (iv)); |
1176 | } | 1183 | } |
1177 | 1184 | ||
1178 | 1185 | ||
@@ -1190,33 +1197,33 @@ setup_cipher (const struct GNUNET_HashCode *msec, | |||
1190 | */ | 1197 | */ |
1191 | static int | 1198 | static int |
1192 | try_decrypt (const struct SharedSecret *ss, | 1199 | try_decrypt (const struct SharedSecret *ss, |
1193 | const char tag[GCM_TAG_SIZE], | 1200 | const char tag[GCM_TAG_SIZE], |
1194 | uint32_t serial, | 1201 | uint32_t serial, |
1195 | const char *in_buf, | 1202 | const char *in_buf, |
1196 | size_t in_buf_size, | 1203 | size_t in_buf_size, |
1197 | char *out_buf) | 1204 | char *out_buf) |
1198 | { | 1205 | { |
1199 | gcry_cipher_hd_t cipher; | 1206 | gcry_cipher_hd_t cipher; |
1200 | 1207 | ||
1201 | setup_cipher (&ss->master, | 1208 | setup_cipher (&ss->master, |
1202 | serial, | 1209 | serial, |
1203 | &cipher); | 1210 | &cipher); |
1204 | GNUNET_assert (0 == | 1211 | GNUNET_assert (0 == |
1205 | gcry_cipher_decrypt (cipher, | 1212 | gcry_cipher_decrypt (cipher, |
1206 | out_buf, | 1213 | out_buf, |
1207 | in_buf_size, | 1214 | in_buf_size, |
1208 | in_buf, | 1215 | in_buf, |
1209 | in_buf_size)); | 1216 | in_buf_size)); |
1210 | if (0 != | 1217 | if (0 != |
1211 | gcry_cipher_checktag (cipher, | 1218 | gcry_cipher_checktag (cipher, |
1212 | tag, | 1219 | tag, |
1213 | GCM_TAG_SIZE)) | 1220 | GCM_TAG_SIZE)) |
1214 | { | 1221 | { |
1215 | gcry_cipher_close (cipher); | 1222 | gcry_cipher_close (cipher); |
1216 | GNUNET_STATISTICS_update (stats, | 1223 | GNUNET_STATISTICS_update (stats, |
1217 | "# AEAD authentication failures", | 1224 | "# AEAD authentication failures", |
1218 | 1, | 1225 | 1, |
1219 | GNUNET_NO); | 1226 | GNUNET_NO); |
1220 | return GNUNET_SYSERR; | 1227 | return GNUNET_SYSERR; |
1221 | } | 1228 | } |
1222 | gcry_cipher_close (cipher); | 1229 | gcry_cipher_close (cipher); |
@@ -1237,8 +1244,8 @@ setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) | |||
1237 | 1244 | ||
1238 | ss = GNUNET_new (struct SharedSecret); | 1245 | ss = GNUNET_new (struct SharedSecret); |
1239 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, | 1246 | GNUNET_CRYPTO_eddsa_ecdh (my_private_key, |
1240 | ephemeral, | 1247 | ephemeral, |
1241 | &ss->master); | 1248 | &ss->master); |
1242 | return ss; | 1249 | return ss; |
1243 | } | 1250 | } |
1244 | 1251 | ||
@@ -1258,18 +1265,18 @@ setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, | |||
1258 | 1265 | ||
1259 | ss = GNUNET_new (struct SharedSecret); | 1266 | ss = GNUNET_new (struct SharedSecret); |
1260 | GNUNET_CRYPTO_ecdh_eddsa (ephemeral, | 1267 | GNUNET_CRYPTO_ecdh_eddsa (ephemeral, |
1261 | &receiver->target.public_key, | 1268 | &receiver->target.public_key, |
1262 | &ss->master); | 1269 | &ss->master); |
1263 | calculate_cmac (ss); | 1270 | calculate_cmac (ss); |
1264 | ss->receiver = receiver; | 1271 | ss->receiver = receiver; |
1265 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, | 1272 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, |
1266 | receiver->ss_tail, | 1273 | receiver->ss_tail, |
1267 | ss); | 1274 | ss); |
1268 | receiver->num_secrets++; | 1275 | receiver->num_secrets++; |
1269 | GNUNET_STATISTICS_update (stats, | 1276 | GNUNET_STATISTICS_update (stats, |
1270 | "# Secrets active", | 1277 | "# Secrets active", |
1271 | 1, | 1278 | 1, |
1272 | GNUNET_NO); | 1279 | GNUNET_NO); |
1273 | return ss; | 1280 | return ss; |
1274 | } | 1281 | } |
1275 | 1282 | ||
@@ -1297,8 +1304,8 @@ setup_receiver_mq (struct ReceiverAddress *receiver); | |||
1297 | */ | 1304 | */ |
1298 | static int | 1305 | static int |
1299 | handle_ack (void *cls, | 1306 | handle_ack (void *cls, |
1300 | const struct GNUNET_PeerIdentity *pid, | 1307 | const struct GNUNET_PeerIdentity *pid, |
1301 | void *value) | 1308 | void *value) |
1302 | { | 1309 | { |
1303 | const struct UDPAck *ack = cls; | 1310 | const struct UDPAck *ack = cls; |
1304 | struct ReceiverAddress *receiver = value; | 1311 | struct ReceiverAddress *receiver = value; |
@@ -1309,8 +1316,8 @@ handle_ack (void *cls, | |||
1309 | ss = ss->next) | 1316 | ss = ss->next) |
1310 | { | 1317 | { |
1311 | if (0 == memcmp (&ack->cmac, | 1318 | if (0 == memcmp (&ack->cmac, |
1312 | &ss->cmac, | 1319 | &ss->cmac, |
1313 | sizeof (struct GNUNET_HashCode))) | 1320 | sizeof (struct GNUNET_HashCode))) |
1314 | { | 1321 | { |
1315 | uint32_t allowed; | 1322 | uint32_t allowed; |
1316 | 1323 | ||
@@ -1318,21 +1325,21 @@ handle_ack (void *cls, | |||
1318 | 1325 | ||
1319 | if (allowed > ss->sequence_allowed) | 1326 | if (allowed > ss->sequence_allowed) |
1320 | { | 1327 | { |
1321 | receiver->acks_available += (allowed - ss->sequence_allowed); | 1328 | receiver->acks_available += (allowed - ss->sequence_allowed); |
1322 | if ((allowed - ss->sequence_allowed) | 1329 | if ((allowed - ss->sequence_allowed) |
1323 | == receiver->acks_available) | 1330 | == receiver->acks_available) |
1324 | { | 1331 | { |
1325 | /* we just incremented from zero => MTU change! */ | 1332 | /* we just incremented from zero => MTU change! */ |
1326 | setup_receiver_mq (receiver); | 1333 | setup_receiver_mq (receiver); |
1327 | } | 1334 | } |
1328 | ss->sequence_allowed = allowed; | 1335 | ss->sequence_allowed = allowed; |
1329 | /* move ss to head to avoid discarding it anytime soon! */ | 1336 | /* move ss to head to avoid discarding it anytime soon! */ |
1330 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, | 1337 | GNUNET_CONTAINER_DLL_remove (receiver->ss_head, |
1331 | receiver->ss_tail, | 1338 | receiver->ss_tail, |
1332 | ss); | 1339 | ss); |
1333 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, | 1340 | GNUNET_CONTAINER_DLL_insert (receiver->ss_head, |
1334 | receiver->ss_tail, | 1341 | receiver->ss_tail, |
1335 | ss); | 1342 | ss); |
1336 | } | 1343 | } |
1337 | return GNUNET_NO; | 1344 | return GNUNET_NO; |
1338 | } | 1345 | } |
@@ -1351,8 +1358,8 @@ handle_ack (void *cls, | |||
1351 | */ | 1358 | */ |
1352 | static void | 1359 | static void |
1353 | try_handle_plaintext (struct SenderAddress *sender, | 1360 | try_handle_plaintext (struct SenderAddress *sender, |
1354 | const void *buf, | 1361 | const void *buf, |
1355 | size_t buf_size) | 1362 | size_t buf_size) |
1356 | { | 1363 | { |
1357 | const struct GNUNET_MessageHeader *hdr | 1364 | const struct GNUNET_MessageHeader *hdr |
1358 | = (const struct GNUNET_MessageHeader *) buf; | 1365 | = (const struct GNUNET_MessageHeader *) buf; |
@@ -1370,23 +1377,23 @@ try_handle_plaintext (struct SenderAddress *sender, | |||
1370 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: | 1377 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: |
1371 | /* lookup master secret by 'cmac', then update sequence_max */ | 1378 | /* lookup master secret by 'cmac', then update sequence_max */ |
1372 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, | 1379 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, |
1373 | &sender->target, | 1380 | &sender->target, |
1374 | &handle_ack, | 1381 | &handle_ack, |
1375 | (void *) ack); | 1382 | (void *) ack); |
1376 | /* There could be more messages after the ACK, handle those as well */ | 1383 | /* There could be more messages after the ACK, handle those as well */ |
1377 | buf += ntohs (hdr->size); | 1384 | buf += ntohs (hdr->size); |
1378 | buf_size -= ntohs (hdr->size); | 1385 | buf_size -= ntohs (hdr->size); |
1379 | pass_plaintext_to_core (sender, | 1386 | pass_plaintext_to_core (sender, |
1380 | buf, | 1387 | buf, |
1381 | buf_size); | 1388 | buf_size); |
1382 | break; | 1389 | break; |
1383 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: | 1390 | case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: |
1384 | /* skip padding */ | 1391 | /* skip padding */ |
1385 | break; | 1392 | break; |
1386 | default: | 1393 | default: |
1387 | pass_plaintext_to_core (sender, | 1394 | pass_plaintext_to_core (sender, |
1388 | buf, | 1395 | buf, |
1389 | buf_size); | 1396 | buf_size); |
1390 | } | 1397 | } |
1391 | } | 1398 | } |
1392 | 1399 | ||
@@ -1413,7 +1420,7 @@ consider_ss_ack (struct SharedSecret *ss) | |||
1413 | 1420 | ||
1414 | while (ss->active_kce_count < KCN_TARGET) | 1421 | while (ss->active_kce_count < KCN_TARGET) |
1415 | kce_generate (ss, | 1422 | kce_generate (ss, |
1416 | ++ss->sequence_allowed); | 1423 | ++ss->sequence_allowed); |
1417 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); | 1424 | ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); |
1418 | ack.header.size = htons (sizeof (ack)); | 1425 | ack.header.size = htons (sizeof (ack)); |
1419 | ack.sequence_max = htonl (ss->sequence_allowed); | 1426 | ack.sequence_max = htonl (ss->sequence_allowed); |
@@ -1435,8 +1442,8 @@ consider_ss_ack (struct SharedSecret *ss) | |||
1435 | */ | 1442 | */ |
1436 | static void | 1443 | static void |
1437 | decrypt_box (const struct UDPBox *box, | 1444 | decrypt_box (const struct UDPBox *box, |
1438 | size_t box_len, | 1445 | size_t box_len, |
1439 | struct KeyCacheEntry *kce) | 1446 | struct KeyCacheEntry *kce) |
1440 | { | 1447 | { |
1441 | struct SharedSecret *ss = kce->ss; | 1448 | struct SharedSecret *ss = kce->ss; |
1442 | char out_buf[box_len - sizeof (*box)]; | 1449 | char out_buf[box_len - sizeof (*box)]; |
@@ -1444,11 +1451,11 @@ decrypt_box (const struct UDPBox *box, | |||
1444 | GNUNET_assert (NULL != ss->sender); | 1451 | GNUNET_assert (NULL != ss->sender); |
1445 | if (GNUNET_OK != | 1452 | if (GNUNET_OK != |
1446 | try_decrypt (ss, | 1453 | try_decrypt (ss, |
1447 | box->gcm_tag, | 1454 | box->gcm_tag, |
1448 | kce->sequence_number, | 1455 | kce->sequence_number, |
1449 | (const char *) &box[1], | 1456 | (const char *) &box[1], |
1450 | sizeof (out_buf), | 1457 | sizeof (out_buf), |
1451 | out_buf)) | 1458 | out_buf)) |
1452 | { | 1459 | { |
1453 | GNUNET_STATISTICS_update (stats, | 1460 | GNUNET_STATISTICS_update (stats, |
1454 | "# Decryption failures with valid KCE", | 1461 | "# Decryption failures with valid KCE", |
@@ -1459,12 +1466,12 @@ decrypt_box (const struct UDPBox *box, | |||
1459 | } | 1466 | } |
1460 | kce_destroy (kce); | 1467 | kce_destroy (kce); |
1461 | GNUNET_STATISTICS_update (stats, | 1468 | GNUNET_STATISTICS_update (stats, |
1462 | "# bytes decrypted with BOX", | 1469 | "# bytes decrypted with BOX", |
1463 | sizeof (out_buf), | 1470 | sizeof (out_buf), |
1464 | GNUNET_NO); | 1471 | GNUNET_NO); |
1465 | try_handle_plaintext (ss->sender, | 1472 | try_handle_plaintext (ss->sender, |
1466 | out_buf, | 1473 | out_buf, |
1467 | sizeof (out_buf)); | 1474 | sizeof (out_buf)); |
1468 | consider_ss_ack (ss); | 1475 | consider_ss_ack (ss); |
1469 | } | 1476 | } |
1470 | 1477 | ||
@@ -1501,16 +1508,16 @@ struct SearchContext | |||
1501 | */ | 1508 | */ |
1502 | static int | 1509 | static int |
1503 | find_sender_by_address (void *cls, | 1510 | find_sender_by_address (void *cls, |
1504 | const struct GNUNET_PeerIdentity *key, | 1511 | const struct GNUNET_PeerIdentity *key, |
1505 | void *value) | 1512 | void *value) |
1506 | { | 1513 | { |
1507 | struct SearchContext *sc = cls; | 1514 | struct SearchContext *sc = cls; |
1508 | struct SenderAddress *sender = value; | 1515 | struct SenderAddress *sender = value; |
1509 | 1516 | ||
1510 | if ( (sender->address_len == sc->address_len) && | 1517 | if ( (sender->address_len == sc->address_len) && |
1511 | (0 == memcmp (sender->address, | 1518 | (0 == memcmp (sender->address, |
1512 | sc->address, | 1519 | sc->address, |
1513 | sender->address_len)) ) | 1520 | sender->address_len)) ) |
1514 | { | 1521 | { |
1515 | sc->sender = sender; | 1522 | sc->sender = sender; |
1516 | return GNUNET_NO; /* stop iterating! */ | 1523 | return GNUNET_NO; /* stop iterating! */ |
@@ -1532,8 +1539,8 @@ find_sender_by_address (void *cls, | |||
1532 | */ | 1539 | */ |
1533 | static struct SenderAddress * | 1540 | static struct SenderAddress * |
1534 | setup_sender (const struct GNUNET_PeerIdentity *target, | 1541 | setup_sender (const struct GNUNET_PeerIdentity *target, |
1535 | const struct sockaddr *address, | 1542 | const struct sockaddr *address, |
1536 | socklen_t address_len) | 1543 | socklen_t address_len) |
1537 | { | 1544 | { |
1538 | struct SenderAddress *sender; | 1545 | struct SenderAddress *sender; |
1539 | struct SearchContext sc = { | 1546 | struct SearchContext sc = { |
@@ -1543,9 +1550,9 @@ setup_sender (const struct GNUNET_PeerIdentity *target, | |||
1543 | }; | 1550 | }; |
1544 | 1551 | ||
1545 | GNUNET_CONTAINER_multipeermap_get_multiple (senders, | 1552 | GNUNET_CONTAINER_multipeermap_get_multiple (senders, |
1546 | target, | 1553 | target, |
1547 | &find_sender_by_address, | 1554 | &find_sender_by_address, |
1548 | &sc); | 1555 | &sc); |
1549 | if (NULL != sc.sender) | 1556 | if (NULL != sc.sender) |
1550 | { | 1557 | { |
1551 | reschedule_sender_timeout (sc.sender); | 1558 | reschedule_sender_timeout (sc.sender); |
@@ -1554,27 +1561,27 @@ setup_sender (const struct GNUNET_PeerIdentity *target, | |||
1554 | sender = GNUNET_new (struct SenderAddress); | 1561 | sender = GNUNET_new (struct SenderAddress); |
1555 | sender->target = *target; | 1562 | sender->target = *target; |
1556 | sender->address = GNUNET_memdup (address, | 1563 | sender->address = GNUNET_memdup (address, |
1557 | address_len); | 1564 | address_len); |
1558 | sender->address_len = address_len; | 1565 | sender->address_len = address_len; |
1559 | (void) GNUNET_CONTAINER_multipeermap_put (senders, | 1566 | (void) GNUNET_CONTAINER_multipeermap_put (senders, |
1560 | &sender->target, | 1567 | &sender->target, |
1561 | sender, | 1568 | sender, |
1562 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 1569 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1563 | GNUNET_STATISTICS_set (stats, | 1570 | GNUNET_STATISTICS_set (stats, |
1564 | "# senders active", | 1571 | "# senders active", |
1565 | GNUNET_CONTAINER_multipeermap_size (receivers), | 1572 | GNUNET_CONTAINER_multipeermap_size (receivers), |
1566 | GNUNET_NO); | 1573 | GNUNET_NO); |
1567 | sender->timeout | 1574 | sender->timeout |
1568 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1575 | = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1569 | sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, | 1576 | sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, |
1570 | sender, | 1577 | sender, |
1571 | sender->timeout.abs_value_us); | 1578 | sender->timeout.abs_value_us); |
1572 | sender->nt = GNUNET_NT_scanner_get_type (is, | 1579 | sender->nt = GNUNET_NT_scanner_get_type (is, |
1573 | address, | 1580 | address, |
1574 | address_len); | 1581 | address_len); |
1575 | if (NULL == timeout_task) | 1582 | if (NULL == timeout_task) |
1576 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, | 1583 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, |
1577 | NULL); | 1584 | NULL); |
1578 | return sender; | 1585 | return sender; |
1579 | } | 1586 | } |
1580 | 1587 | ||
@@ -1759,11 +1766,11 @@ sock_read (void *cls) | |||
1759 | ss = setup_shared_secret_dec (&kx->ephemeral); | 1766 | ss = setup_shared_secret_dec (&kx->ephemeral); |
1760 | if (GNUNET_OK != | 1767 | if (GNUNET_OK != |
1761 | try_decrypt (ss, | 1768 | try_decrypt (ss, |
1762 | kx->gcm_tag, | 1769 | kx->gcm_tag, |
1763 | 0, | 1770 | 0, |
1764 | &buf[sizeof (*kx)], | 1771 | &buf[sizeof (*kx)], |
1765 | sizeof (pbuf), | 1772 | sizeof (pbuf), |
1766 | pbuf)) | 1773 | pbuf)) |
1767 | { | 1774 | { |
1768 | GNUNET_free (ss); | 1775 | GNUNET_free (ss); |
1769 | GNUNET_STATISTICS_update (stats, | 1776 | GNUNET_STATISTICS_update (stats, |
@@ -1774,8 +1781,8 @@ sock_read (void *cls) | |||
1774 | } | 1781 | } |
1775 | uc = (const struct UDPConfirmation *) pbuf; | 1782 | uc = (const struct UDPConfirmation *) pbuf; |
1776 | if (GNUNET_OK != | 1783 | if (GNUNET_OK != |
1777 | verify_confirmation (&kx->ephemeral, | 1784 | verify_confirmation (&kx->ephemeral, |
1778 | uc)) | 1785 | uc)) |
1779 | { | 1786 | { |
1780 | GNUNET_break_op (0); | 1787 | GNUNET_break_op (0); |
1781 | GNUNET_free (ss); | 1788 | GNUNET_free (ss); |
@@ -1787,24 +1794,24 @@ sock_read (void *cls) | |||
1787 | } | 1794 | } |
1788 | calculate_cmac (ss); | 1795 | calculate_cmac (ss); |
1789 | sender = setup_sender (&uc->sender, | 1796 | sender = setup_sender (&uc->sender, |
1790 | (const struct sockaddr *) &sa, | 1797 | (const struct sockaddr *) &sa, |
1791 | salen); | 1798 | salen); |
1792 | ss->sender = sender; | 1799 | ss->sender = sender; |
1793 | GNUNET_CONTAINER_DLL_insert (sender->ss_head, | 1800 | GNUNET_CONTAINER_DLL_insert (sender->ss_head, |
1794 | sender->ss_tail, | 1801 | sender->ss_tail, |
1795 | ss); | 1802 | ss); |
1796 | sender->num_secrets++; | 1803 | sender->num_secrets++; |
1797 | GNUNET_STATISTICS_update (stats, | 1804 | GNUNET_STATISTICS_update (stats, |
1798 | "# Secrets active", | 1805 | "# Secrets active", |
1799 | 1, | 1806 | 1, |
1800 | GNUNET_NO); | 1807 | GNUNET_NO); |
1801 | GNUNET_STATISTICS_update (stats, | 1808 | GNUNET_STATISTICS_update (stats, |
1802 | "# messages decrypted without BOX", | 1809 | "# messages decrypted without BOX", |
1803 | 1, | 1810 | 1, |
1804 | GNUNET_NO); | 1811 | GNUNET_NO); |
1805 | try_handle_plaintext (sender, | 1812 | try_handle_plaintext (sender, |
1806 | &uc[1], | 1813 | &uc[1], |
1807 | sizeof (pbuf) - sizeof (*uc)); | 1814 | sizeof (pbuf) - sizeof (*uc)); |
1808 | consider_ss_ack (ss); | 1815 | consider_ss_ack (ss); |
1809 | if (sender->num_secrets > MAX_SECRETS) | 1816 | if (sender->num_secrets > MAX_SECRETS) |
1810 | secret_destroy (sender->ss_tail); | 1817 | secret_destroy (sender->ss_tail); |
@@ -1821,7 +1828,7 @@ sock_read (void *cls) | |||
1821 | */ | 1828 | */ |
1822 | static struct sockaddr * | 1829 | static struct sockaddr * |
1823 | udp_address_to_sockaddr (const char *bindto, | 1830 | udp_address_to_sockaddr (const char *bindto, |
1824 | socklen_t *sock_len) | 1831 | socklen_t *sock_len) |
1825 | { | 1832 | { |
1826 | struct sockaddr *in; | 1833 | struct sockaddr *in; |
1827 | unsigned int port; | 1834 | unsigned int port; |
@@ -1830,24 +1837,24 @@ udp_address_to_sockaddr (const char *bindto, | |||
1830 | char *cp; | 1837 | char *cp; |
1831 | 1838 | ||
1832 | if (1 == SSCANF (bindto, | 1839 | if (1 == SSCANF (bindto, |
1833 | "%u%1s", | 1840 | "%u%1s", |
1834 | &port, | 1841 | &port, |
1835 | dummy)) | 1842 | dummy)) |
1836 | { | 1843 | { |
1837 | /* interpreting value as just a PORT number */ | 1844 | /* interpreting value as just a PORT number */ |
1838 | if (port > UINT16_MAX) | 1845 | if (port > UINT16_MAX) |
1839 | { | 1846 | { |
1840 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1847 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1841 | "BINDTO specification `%s' invalid: value too large for port\n", | 1848 | "BINDTO specification `%s' invalid: value too large for port\n", |
1842 | bindto); | 1849 | bindto); |
1843 | return NULL; | 1850 | return NULL; |
1844 | } | 1851 | } |
1845 | if ( (GNUNET_NO == | 1852 | if ( (GNUNET_NO == |
1846 | GNUNET_NETWORK_test_pf (PF_INET6)) || | 1853 | GNUNET_NETWORK_test_pf (PF_INET6)) || |
1847 | (GNUNET_YES == | 1854 | (GNUNET_YES == |
1848 | GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1855 | GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1849 | COMMUNICATOR_CONFIG_SECTION, | 1856 | COMMUNICATOR_CONFIG_SECTION, |
1850 | "DISABLE_V6")) ) | 1857 | "DISABLE_V6")) ) |
1851 | { | 1858 | { |
1852 | struct sockaddr_in *i4; | 1859 | struct sockaddr_in *i4; |
1853 | 1860 | ||
@@ -1877,16 +1884,16 @@ udp_address_to_sockaddr (const char *bindto, | |||
1877 | *colon = '\0'; | 1884 | *colon = '\0'; |
1878 | colon++; | 1885 | colon++; |
1879 | if (1 == SSCANF (colon, | 1886 | if (1 == SSCANF (colon, |
1880 | "%u%1s", | 1887 | "%u%1s", |
1881 | &port, | 1888 | &port, |
1882 | dummy)) | 1889 | dummy)) |
1883 | { | 1890 | { |
1884 | /* interpreting value as just a PORT number */ | 1891 | /* interpreting value as just a PORT number */ |
1885 | if (port > UINT16_MAX) | 1892 | if (port > UINT16_MAX) |
1886 | { | 1893 | { |
1887 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1894 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1888 | "BINDTO specification `%s' invalid: value too large for port\n", | 1895 | "BINDTO specification `%s' invalid: value too large for port\n", |
1889 | bindto); | 1896 | bindto); |
1890 | GNUNET_free (cp); | 1897 | GNUNET_free (cp); |
1891 | return NULL; | 1898 | return NULL; |
1892 | } | 1899 | } |
@@ -1894,8 +1901,8 @@ udp_address_to_sockaddr (const char *bindto, | |||
1894 | else | 1901 | else |
1895 | { | 1902 | { |
1896 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1903 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1897 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", | 1904 | "BINDTO specification `%s' invalid: last ':' not followed by number\n", |
1898 | bindto); | 1905 | bindto); |
1899 | GNUNET_free (cp); | 1906 | GNUNET_free (cp); |
1900 | return NULL; | 1907 | return NULL; |
1901 | } | 1908 | } |
@@ -1915,7 +1922,7 @@ udp_address_to_sockaddr (const char *bindto, | |||
1915 | { | 1922 | { |
1916 | v4.sin_port = htons ((uint16_t) port); | 1923 | v4.sin_port = htons ((uint16_t) port); |
1917 | in = GNUNET_memdup (&v4, | 1924 | in = GNUNET_memdup (&v4, |
1918 | sizeof (v4)); | 1925 | sizeof (v4)); |
1919 | *sock_len = sizeof (v4); | 1926 | *sock_len = sizeof (v4); |
1920 | GNUNET_free (cp); | 1927 | GNUNET_free (cp); |
1921 | return in; | 1928 | return in; |
@@ -1934,12 +1941,12 @@ udp_address_to_sockaddr (const char *bindto, | |||
1934 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ | 1941 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ |
1935 | } | 1942 | } |
1936 | if (1 == inet_pton (AF_INET6, | 1943 | if (1 == inet_pton (AF_INET6, |
1937 | start, | 1944 | start, |
1938 | &v6)) | 1945 | &v6)) |
1939 | { | 1946 | { |
1940 | v6.sin6_port = htons ((uint16_t) port); | 1947 | v6.sin6_port = htons ((uint16_t) port); |
1941 | in = GNUNET_memdup (&v6, | 1948 | in = GNUNET_memdup (&v6, |
1942 | sizeof (v6)); | 1949 | sizeof (v6)); |
1943 | *sock_len = sizeof (v6); | 1950 | *sock_len = sizeof (v6); |
1944 | GNUNET_free (cp); | 1951 | GNUNET_free (cp); |
1945 | return in; | 1952 | return in; |
@@ -1960,14 +1967,14 @@ udp_address_to_sockaddr (const char *bindto, | |||
1960 | */ | 1967 | */ |
1961 | static void | 1968 | static void |
1962 | do_pad (gcry_cipher_hd_t out_cipher, | 1969 | do_pad (gcry_cipher_hd_t out_cipher, |
1963 | char *dgram, | 1970 | char *dgram, |
1964 | size_t pad_size) | 1971 | size_t pad_size) |
1965 | { | 1972 | { |
1966 | char pad[pad_size]; | 1973 | char pad[pad_size]; |
1967 | 1974 | ||
1968 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 1975 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |
1969 | pad, | 1976 | pad, |
1970 | sizeof (pad)); | 1977 | sizeof (pad)); |
1971 | if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader)) | 1978 | if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader)) |
1972 | { | 1979 | { |
1973 | struct GNUNET_MessageHeader hdr = { | 1980 | struct GNUNET_MessageHeader hdr = { |
@@ -1980,11 +1987,11 @@ do_pad (gcry_cipher_hd_t out_cipher, | |||
1980 | sizeof (hdr)); | 1987 | sizeof (hdr)); |
1981 | } | 1988 | } |
1982 | GNUNET_assert (0 == | 1989 | GNUNET_assert (0 == |
1983 | gcry_cipher_encrypt (out_cipher, | 1990 | gcry_cipher_encrypt (out_cipher, |
1984 | dgram, | 1991 | dgram, |
1985 | sizeof (pad), | 1992 | sizeof (pad), |
1986 | pad, | 1993 | pad, |
1987 | sizeof (pad))); | 1994 | sizeof (pad))); |
1988 | } | 1995 | } |
1989 | 1996 | ||
1990 | 1997 | ||
@@ -1998,8 +2005,8 @@ do_pad (gcry_cipher_hd_t out_cipher, | |||
1998 | */ | 2005 | */ |
1999 | static void | 2006 | static void |
2000 | mq_send (struct GNUNET_MQ_Handle *mq, | 2007 | mq_send (struct GNUNET_MQ_Handle *mq, |
2001 | const struct GNUNET_MessageHeader *msg, | 2008 | const struct GNUNET_MessageHeader *msg, |
2002 | void *impl_state) | 2009 | void *impl_state) |
2003 | { | 2010 | { |
2004 | struct ReceiverAddress *receiver = impl_state; | 2011 | struct ReceiverAddress *receiver = impl_state; |
2005 | uint16_t msize = ntohs (msg->size); | 2012 | uint16_t msize = ntohs (msg->size); |
@@ -2021,21 +2028,21 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2021 | struct InitialKX kx; | 2028 | struct InitialKX kx; |
2022 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; | 2029 | struct GNUNET_CRYPTO_EcdhePrivateKey epriv; |
2023 | char dgram[receiver->mtu + | 2030 | char dgram[receiver->mtu + |
2024 | sizeof (uc) + | 2031 | sizeof (uc) + |
2025 | sizeof (kx)]; | 2032 | sizeof (kx)]; |
2026 | size_t dpos; | 2033 | size_t dpos; |
2027 | gcry_cipher_hd_t out_cipher; | 2034 | gcry_cipher_hd_t out_cipher; |
2028 | struct SharedSecret *ss; | 2035 | struct SharedSecret *ss; |
2029 | 2036 | ||
2030 | /* setup key material */ | 2037 | /* setup key material */ |
2031 | GNUNET_assert (GNUNET_OK == | 2038 | GNUNET_assert (GNUNET_OK == |
2032 | GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); | 2039 | GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); |
2033 | 2040 | ||
2034 | ss = setup_shared_secret_enc (&epriv, | 2041 | ss = setup_shared_secret_enc (&epriv, |
2035 | receiver); | 2042 | receiver); |
2036 | setup_cipher (&ss->master, | 2043 | setup_cipher (&ss->master, |
2037 | 0, | 2044 | 0, |
2038 | &out_cipher); | 2045 | &out_cipher); |
2039 | /* compute 'uc' */ | 2046 | /* compute 'uc' */ |
2040 | uc.sender = my_identity; | 2047 | uc.sender = my_identity; |
2041 | uc.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); | 2048 | uc.monotonic_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); |
@@ -2047,26 +2054,26 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2047 | &uhs.ephemeral); | 2054 | &uhs.ephemeral); |
2048 | uhs.monotonic_time = uc.monotonic_time; | 2055 | uhs.monotonic_time = uc.monotonic_time; |
2049 | GNUNET_assert (GNUNET_OK == | 2056 | GNUNET_assert (GNUNET_OK == |
2050 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 2057 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
2051 | &uhs.purpose, | 2058 | &uhs.purpose, |
2052 | &uc.sender_sig)); | 2059 | &uc.sender_sig)); |
2053 | /* Leave space for kx */ | 2060 | /* Leave space for kx */ |
2054 | dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey); | 2061 | dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey); |
2055 | /* Append encrypted uc to dgram */ | 2062 | /* Append encrypted uc to dgram */ |
2056 | GNUNET_assert (0 == | 2063 | GNUNET_assert (0 == |
2057 | gcry_cipher_encrypt (out_cipher, | 2064 | gcry_cipher_encrypt (out_cipher, |
2058 | &dgram[dpos], | 2065 | &dgram[dpos], |
2059 | sizeof (uc), | 2066 | sizeof (uc), |
2060 | &uc, | 2067 | &uc, |
2061 | sizeof (uc))); | 2068 | sizeof (uc))); |
2062 | dpos += sizeof (uc); | 2069 | dpos += sizeof (uc); |
2063 | /* Append encrypted payload to dgram */ | 2070 | /* Append encrypted payload to dgram */ |
2064 | GNUNET_assert (0 == | 2071 | GNUNET_assert (0 == |
2065 | gcry_cipher_encrypt (out_cipher, | 2072 | gcry_cipher_encrypt (out_cipher, |
2066 | &dgram[dpos], | 2073 | &dgram[dpos], |
2067 | msize, | 2074 | msize, |
2068 | msg, | 2075 | msg, |
2069 | msize)); | 2076 | msize)); |
2070 | dpos += msize; | 2077 | dpos += msize; |
2071 | do_pad (out_cipher, | 2078 | do_pad (out_cipher, |
2072 | &dgram[dpos], | 2079 | &dgram[dpos], |
@@ -2074,21 +2081,21 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2074 | /* Datagram starts with kx */ | 2081 | /* Datagram starts with kx */ |
2075 | kx.ephemeral = uhs.ephemeral; | 2082 | kx.ephemeral = uhs.ephemeral; |
2076 | GNUNET_assert (0 == | 2083 | GNUNET_assert (0 == |
2077 | gcry_cipher_gettag (out_cipher, | 2084 | gcry_cipher_gettag (out_cipher, |
2078 | kx.gcm_tag, | 2085 | kx.gcm_tag, |
2079 | sizeof (kx.gcm_tag))); | 2086 | sizeof (kx.gcm_tag))); |
2080 | gcry_cipher_close (out_cipher); | 2087 | gcry_cipher_close (out_cipher); |
2081 | memcpy (dgram, | 2088 | memcpy (dgram, |
2082 | &kx, | 2089 | &kx, |
2083 | sizeof (kx)); | 2090 | sizeof (kx)); |
2084 | if (-1 == | 2091 | if (-1 == |
2085 | GNUNET_NETWORK_socket_sendto (udp_sock, | 2092 | GNUNET_NETWORK_socket_sendto (udp_sock, |
2086 | dgram, | 2093 | dgram, |
2087 | sizeof (dgram), | 2094 | sizeof (dgram), |
2088 | receiver->address, | 2095 | receiver->address, |
2089 | receiver->address_len)) | 2096 | receiver->address_len)) |
2090 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2097 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2091 | "send"); | 2098 | "send"); |
2092 | GNUNET_MQ_impl_send_continue (mq); | 2099 | GNUNET_MQ_impl_send_continue (mq); |
2093 | return; | 2100 | return; |
2094 | } /* End of KX encryption method */ | 2101 | } /* End of KX encryption method */ |
@@ -2116,34 +2123,34 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2116 | /* Append encrypted payload to dgram */ | 2123 | /* Append encrypted payload to dgram */ |
2117 | dpos = sizeof (struct UDPBox); | 2124 | dpos = sizeof (struct UDPBox); |
2118 | GNUNET_assert (0 == | 2125 | GNUNET_assert (0 == |
2119 | gcry_cipher_encrypt (out_cipher, | 2126 | gcry_cipher_encrypt (out_cipher, |
2120 | &dgram[dpos], | 2127 | &dgram[dpos], |
2121 | msize, | 2128 | msize, |
2122 | msg, | 2129 | msg, |
2123 | msize)); | 2130 | msize)); |
2124 | dpos += msize; | 2131 | dpos += msize; |
2125 | do_pad (out_cipher, | 2132 | do_pad (out_cipher, |
2126 | &dgram[dpos], | 2133 | &dgram[dpos], |
2127 | sizeof (dgram) - dpos); | 2134 | sizeof (dgram) - dpos); |
2128 | GNUNET_assert (0 == | 2135 | GNUNET_assert (0 == |
2129 | gcry_cipher_gettag (out_cipher, | 2136 | gcry_cipher_gettag (out_cipher, |
2130 | box->gcm_tag, | 2137 | box->gcm_tag, |
2131 | sizeof (box->gcm_tag))); | 2138 | sizeof (box->gcm_tag))); |
2132 | gcry_cipher_close (out_cipher); | 2139 | gcry_cipher_close (out_cipher); |
2133 | if (-1 == | 2140 | if (-1 == |
2134 | GNUNET_NETWORK_socket_sendto (udp_sock, | 2141 | GNUNET_NETWORK_socket_sendto (udp_sock, |
2135 | dgram, | 2142 | dgram, |
2136 | sizeof (dgram), | 2143 | sizeof (dgram), |
2137 | receiver->address, | 2144 | receiver->address, |
2138 | receiver->address_len)) | 2145 | receiver->address_len)) |
2139 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2146 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2140 | "send"); | 2147 | "send"); |
2141 | GNUNET_MQ_impl_send_continue (mq); | 2148 | GNUNET_MQ_impl_send_continue (mq); |
2142 | receiver->acks_available--; | 2149 | receiver->acks_available--; |
2143 | if (0 == receiver->acks_available) | 2150 | if (0 == receiver->acks_available) |
2144 | { | 2151 | { |
2145 | /* We have no more ACKs => MTU change! */ | 2152 | /* We have no more ACKs => MTU change! */ |
2146 | setup_receiver_mq (receiver); | 2153 | setup_receiver_mq (receiver); |
2147 | } | 2154 | } |
2148 | return; | 2155 | return; |
2149 | } | 2156 | } |
@@ -2162,7 +2169,7 @@ mq_send (struct GNUNET_MQ_Handle *mq, | |||
2162 | */ | 2169 | */ |
2163 | static void | 2170 | static void |
2164 | mq_destroy (struct GNUNET_MQ_Handle *mq, | 2171 | mq_destroy (struct GNUNET_MQ_Handle *mq, |
2165 | void *impl_state) | 2172 | void *impl_state) |
2166 | { | 2173 | { |
2167 | struct ReceiverAddress *receiver = impl_state; | 2174 | struct ReceiverAddress *receiver = impl_state; |
2168 | 2175 | ||
@@ -2182,7 +2189,7 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, | |||
2182 | */ | 2189 | */ |
2183 | static void | 2190 | static void |
2184 | mq_cancel (struct GNUNET_MQ_Handle *mq, | 2191 | mq_cancel (struct GNUNET_MQ_Handle *mq, |
2185 | void *impl_state) | 2192 | void *impl_state) |
2186 | { | 2193 | { |
2187 | /* Cancellation is impossible with UDP; bail */ | 2194 | /* Cancellation is impossible with UDP; bail */ |
2188 | GNUNET_assert (0); | 2195 | GNUNET_assert (0); |
@@ -2200,14 +2207,14 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, | |||
2200 | */ | 2207 | */ |
2201 | static void | 2208 | static void |
2202 | mq_error (void *cls, | 2209 | mq_error (void *cls, |
2203 | enum GNUNET_MQ_Error error) | 2210 | enum GNUNET_MQ_Error error) |
2204 | { | 2211 | { |
2205 | struct ReceiverAddress *receiver = cls; | 2212 | struct ReceiverAddress *receiver = cls; |
2206 | 2213 | ||
2207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2214 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2208 | "MQ error in queue to %s: %d\n", | 2215 | "MQ error in queue to %s: %d\n", |
2209 | GNUNET_i2s (&receiver->target), | 2216 | GNUNET_i2s (&receiver->target), |
2210 | (int) error); | 2217 | (int) error); |
2211 | receiver_destroy (receiver); | 2218 | receiver_destroy (receiver); |
2212 | } | 2219 | } |
2213 | 2220 | ||
@@ -2266,20 +2273,20 @@ setup_receiver_mq (struct ReceiverAddress *receiver) | |||
2266 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ | 2273 | 1404 (IPv4 + Box) bytes, depending on circumstances... */ |
2267 | receiver->mq | 2274 | receiver->mq |
2268 | = GNUNET_MQ_queue_for_callbacks (&mq_send, | 2275 | = GNUNET_MQ_queue_for_callbacks (&mq_send, |
2269 | &mq_destroy, | 2276 | &mq_destroy, |
2270 | &mq_cancel, | 2277 | &mq_cancel, |
2271 | receiver, | 2278 | receiver, |
2272 | NULL, | 2279 | NULL, |
2273 | &mq_error, | 2280 | &mq_error, |
2274 | receiver); | 2281 | receiver); |
2275 | receiver->qh | 2282 | receiver->qh |
2276 | = GNUNET_TRANSPORT_communicator_mq_add (ch, | 2283 | = GNUNET_TRANSPORT_communicator_mq_add (ch, |
2277 | &receiver->target, | 2284 | &receiver->target, |
2278 | receiver->foreign_addr, | 2285 | receiver->foreign_addr, |
2279 | receiver->mtu, | 2286 | receiver->mtu, |
2280 | receiver->nt, | 2287 | receiver->nt, |
2281 | GNUNET_TRANSPORT_CS_OUTBOUND, | 2288 | GNUNET_TRANSPORT_CS_OUTBOUND, |
2282 | receiver->mq); | 2289 | receiver->mq); |
2283 | } | 2290 | } |
2284 | 2291 | ||
2285 | 2292 | ||
@@ -2287,7 +2294,10 @@ setup_receiver_mq (struct ReceiverAddress *receiver) | |||
2287 | * Setup a receiver for transmission. Setup the MQ processing and | 2294 | * Setup a receiver for transmission. Setup the MQ processing and |
2288 | * inform transport that the queue is ready. | 2295 | * inform transport that the queue is ready. |
2289 | * | 2296 | * |
2290 | * @param | 2297 | * @param target which peer are we talking to |
2298 | * @param address address of the peer | ||
2299 | * @param address_len number of bytes in @a address | ||
2300 | * @return handle for the address | ||
2291 | */ | 2301 | */ |
2292 | static struct ReceiverAddress * | 2302 | static struct ReceiverAddress * |
2293 | receiver_setup (const struct GNUNET_PeerIdentity *target, | 2303 | receiver_setup (const struct GNUNET_PeerIdentity *target, |
@@ -2323,7 +2333,7 @@ receiver_setup (const struct GNUNET_PeerIdentity *target, | |||
2323 | 2333 | ||
2324 | if (NULL == timeout_task) | 2334 | if (NULL == timeout_task) |
2325 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, | 2335 | timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, |
2326 | NULL); | 2336 | NULL); |
2327 | return receiver; | 2337 | return receiver; |
2328 | } | 2338 | } |
2329 | 2339 | ||
@@ -2347,8 +2357,8 @@ receiver_setup (const struct GNUNET_PeerIdentity *target, | |||
2347 | */ | 2357 | */ |
2348 | static int | 2358 | static int |
2349 | mq_init (void *cls, | 2359 | mq_init (void *cls, |
2350 | const struct GNUNET_PeerIdentity *peer, | 2360 | const struct GNUNET_PeerIdentity *peer, |
2351 | const char *address) | 2361 | const char *address) |
2352 | { | 2362 | { |
2353 | struct ReceiverAddress *receiver; | 2363 | struct ReceiverAddress *receiver; |
2354 | const char *path; | 2364 | const char *path; |
@@ -2356,18 +2366,18 @@ mq_init (void *cls, | |||
2356 | socklen_t in_len; | 2366 | socklen_t in_len; |
2357 | 2367 | ||
2358 | if (0 != strncmp (address, | 2368 | if (0 != strncmp (address, |
2359 | COMMUNICATOR_ADDRESS_PREFIX "-", | 2369 | COMMUNICATOR_ADDRESS_PREFIX "-", |
2360 | strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) | 2370 | strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) |
2361 | { | 2371 | { |
2362 | GNUNET_break_op (0); | 2372 | GNUNET_break_op (0); |
2363 | return GNUNET_SYSERR; | 2373 | return GNUNET_SYSERR; |
2364 | } | 2374 | } |
2365 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; | 2375 | path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; |
2366 | in = udp_address_to_sockaddr (path, | 2376 | in = udp_address_to_sockaddr (path, |
2367 | &in_len); | 2377 | &in_len); |
2368 | receiver = receiver_setup (peer, | 2378 | receiver = receiver_setup (peer, |
2369 | in, | 2379 | in, |
2370 | in_len); | 2380 | in_len); |
2371 | (void) receiver; | 2381 | (void) receiver; |
2372 | return GNUNET_OK; | 2382 | return GNUNET_OK; |
2373 | } | 2383 | } |
@@ -2383,8 +2393,8 @@ mq_init (void *cls, | |||
2383 | */ | 2393 | */ |
2384 | static int | 2394 | static int |
2385 | get_receiver_delete_it (void *cls, | 2395 | get_receiver_delete_it (void *cls, |
2386 | const struct GNUNET_PeerIdentity *target, | 2396 | const struct GNUNET_PeerIdentity *target, |
2387 | void *value) | 2397 | void *value) |
2388 | { | 2398 | { |
2389 | struct ReceiverAddress *receiver = value; | 2399 | struct ReceiverAddress *receiver = value; |
2390 | 2400 | ||
@@ -2405,8 +2415,8 @@ get_receiver_delete_it (void *cls, | |||
2405 | */ | 2415 | */ |
2406 | static int | 2416 | static int |
2407 | get_sender_delete_it (void *cls, | 2417 | get_sender_delete_it (void *cls, |
2408 | const struct GNUNET_PeerIdentity *target, | 2418 | const struct GNUNET_PeerIdentity *target, |
2409 | void *value) | 2419 | void *value) |
2410 | { | 2420 | { |
2411 | struct SenderAddress *sender = value; | 2421 | struct SenderAddress *sender = value; |
2412 | 2422 | ||
@@ -2449,11 +2459,11 @@ do_shutdown (void *cls) | |||
2449 | udp_sock = NULL; | 2459 | udp_sock = NULL; |
2450 | } | 2460 | } |
2451 | GNUNET_CONTAINER_multipeermap_iterate (receivers, | 2461 | GNUNET_CONTAINER_multipeermap_iterate (receivers, |
2452 | &get_receiver_delete_it, | 2462 | &get_receiver_delete_it, |
2453 | NULL); | 2463 | NULL); |
2454 | GNUNET_CONTAINER_multipeermap_destroy (receivers); | 2464 | GNUNET_CONTAINER_multipeermap_destroy (receivers); |
2455 | GNUNET_CONTAINER_multipeermap_iterate (senders, | 2465 | GNUNET_CONTAINER_multipeermap_iterate (senders, |
2456 | &get_sender_delete_it, | 2466 | &get_sender_delete_it, |
2457 | NULL); | 2467 | NULL); |
2458 | GNUNET_CONTAINER_multipeermap_destroy (senders); | 2468 | GNUNET_CONTAINER_multipeermap_destroy (senders); |
2459 | GNUNET_CONTAINER_multishortmap_destroy (key_cache); | 2469 | GNUNET_CONTAINER_multishortmap_destroy (key_cache); |
@@ -2472,7 +2482,7 @@ do_shutdown (void *cls) | |||
2472 | if (NULL != stats) | 2482 | if (NULL != stats) |
2473 | { | 2483 | { |
2474 | GNUNET_STATISTICS_destroy (stats, | 2484 | GNUNET_STATISTICS_destroy (stats, |
2475 | GNUNET_NO); | 2485 | GNUNET_NO); |
2476 | stats = NULL; | 2486 | stats = NULL; |
2477 | } | 2487 | } |
2478 | if (NULL != my_private_key) | 2488 | if (NULL != my_private_key) |
@@ -2482,8 +2492,8 @@ do_shutdown (void *cls) | |||
2482 | } | 2492 | } |
2483 | if (NULL != is) | 2493 | if (NULL != is) |
2484 | { | 2494 | { |
2485 | GNUNET_NT_scanner_done (is); | 2495 | GNUNET_NT_scanner_done (is); |
2486 | is = NULL; | 2496 | is = NULL; |
2487 | } | 2497 | } |
2488 | } | 2498 | } |
2489 | 2499 | ||
@@ -2513,9 +2523,9 @@ enc_notify_cb (void *cls, | |||
2513 | } | 2523 | } |
2514 | ack = (const struct UDPAck *) msg; | 2524 | ack = (const struct UDPAck *) msg; |
2515 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, | 2525 | GNUNET_CONTAINER_multipeermap_get_multiple (receivers, |
2516 | sender, | 2526 | sender, |
2517 | &handle_ack, | 2527 | &handle_ack, |
2518 | (void *) ack); | 2528 | (void *) ack); |
2519 | } | 2529 | } |
2520 | 2530 | ||
2521 | 2531 | ||
@@ -2534,11 +2544,11 @@ enc_notify_cb (void *cls, | |||
2534 | */ | 2544 | */ |
2535 | static void | 2545 | static void |
2536 | nat_address_cb (void *cls, | 2546 | nat_address_cb (void *cls, |
2537 | void **app_ctx, | 2547 | void **app_ctx, |
2538 | int add_remove, | 2548 | int add_remove, |
2539 | enum GNUNET_NAT_AddressClass ac, | 2549 | enum GNUNET_NAT_AddressClass ac, |
2540 | const struct sockaddr *addr, | 2550 | const struct sockaddr *addr, |
2541 | socklen_t addrlen) | 2551 | socklen_t addrlen) |
2542 | { | 2552 | { |
2543 | char *my_addr; | 2553 | char *my_addr; |
2544 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; | 2554 | struct GNUNET_TRANSPORT_AddressIdentifier *ai; |
@@ -2556,9 +2566,9 @@ nat_address_cb (void *cls, | |||
2556 | addr, | 2566 | addr, |
2557 | addrlen); | 2567 | addrlen); |
2558 | ai = GNUNET_TRANSPORT_communicator_address_add (ch, | 2568 | ai = GNUNET_TRANSPORT_communicator_address_add (ch, |
2559 | my_addr, | 2569 | my_addr, |
2560 | nt, | 2570 | nt, |
2561 | GNUNET_TIME_UNIT_FOREVER_REL); | 2571 | GNUNET_TIME_UNIT_FOREVER_REL); |
2562 | GNUNET_free (my_addr); | 2572 | GNUNET_free (my_addr); |
2563 | *app_ctx = ai; | 2573 | *app_ctx = ai; |
2564 | } | 2574 | } |
@@ -2584,7 +2594,7 @@ ifc_broadcast (void *cls) | |||
2584 | 2594 | ||
2585 | delay = BROADCAST_FREQUENCY; | 2595 | delay = BROADCAST_FREQUENCY; |
2586 | delay.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 2596 | delay.rel_value_us = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, |
2587 | delay.rel_value_us); | 2597 | delay.rel_value_us); |
2588 | bi->broadcast_task | 2598 | bi->broadcast_task |
2589 | = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, | 2599 | = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, |
2590 | &ifc_broadcast, | 2600 | &ifc_broadcast, |
@@ -2598,29 +2608,29 @@ ifc_broadcast (void *cls) | |||
2598 | ssize_t sent; | 2608 | ssize_t sent; |
2599 | 2609 | ||
2600 | if (GNUNET_OK != | 2610 | if (GNUNET_OK != |
2601 | GNUNET_NETWORK_socket_setsockopt (udp_sock, | 2611 | GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2602 | SOL_SOCKET, | 2612 | SOL_SOCKET, |
2603 | SO_BROADCAST, | 2613 | SO_BROADCAST, |
2604 | &yes, | 2614 | &yes, |
2605 | sizeof (int))) | 2615 | sizeof (int))) |
2606 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2616 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2607 | "setsockopt"); | 2617 | "setsockopt"); |
2608 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, | 2618 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2609 | &bi->bcm, | 2619 | &bi->bcm, |
2610 | sizeof (bi->bcm), | 2620 | sizeof (bi->bcm), |
2611 | bi->ba, | 2621 | bi->ba, |
2612 | bi->salen); | 2622 | bi->salen); |
2613 | if (-1 == sent) | 2623 | if (-1 == sent) |
2614 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2624 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2615 | "sendto"); | 2625 | "sendto"); |
2616 | if (GNUNET_OK != | 2626 | if (GNUNET_OK != |
2617 | GNUNET_NETWORK_socket_setsockopt (udp_sock, | 2627 | GNUNET_NETWORK_socket_setsockopt (udp_sock, |
2618 | SOL_SOCKET, | 2628 | SOL_SOCKET, |
2619 | SO_BROADCAST, | 2629 | SO_BROADCAST, |
2620 | &no, | 2630 | &no, |
2621 | sizeof (int))) | 2631 | sizeof (int))) |
2622 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2632 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2623 | "setsockopt"); | 2633 | "setsockopt"); |
2624 | break; | 2634 | break; |
2625 | } | 2635 | } |
2626 | case AF_INET6: | 2636 | case AF_INET6: |
@@ -2634,14 +2644,14 @@ ifc_broadcast (void *cls) | |||
2634 | dst.sin6_scope_id = ((struct sockaddr_in6*) bi->ba)->sin6_scope_id; | 2644 | dst.sin6_scope_id = ((struct sockaddr_in6*) bi->ba)->sin6_scope_id; |
2635 | 2645 | ||
2636 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, | 2646 | sent = GNUNET_NETWORK_socket_sendto (udp_sock, |
2637 | &bi->bcm, | 2647 | &bi->bcm, |
2638 | sizeof (bi->bcm), | 2648 | sizeof (bi->bcm), |
2639 | (const struct sockaddr *) | 2649 | (const struct sockaddr *) |
2640 | &dst, | 2650 | &dst, |
2641 | sizeof (dst)); | 2651 | sizeof (dst)); |
2642 | if (-1 == sent) | 2652 | if (-1 == sent) |
2643 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2653 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2644 | "sendto"); | 2654 | "sendto"); |
2645 | break; | 2655 | break; |
2646 | } | 2656 | } |
2647 | default: | 2657 | default: |
@@ -2679,8 +2689,8 @@ iface_proc (void *cls, | |||
2679 | (void) cls; | 2689 | (void) cls; |
2680 | (void) netmask; | 2690 | (void) netmask; |
2681 | network = GNUNET_NT_scanner_get_type (is, | 2691 | network = GNUNET_NT_scanner_get_type (is, |
2682 | addr, | 2692 | addr, |
2683 | addrlen); | 2693 | addrlen); |
2684 | if (GNUNET_NT_LOOPBACK == network) | 2694 | if (GNUNET_NT_LOOPBACK == network) |
2685 | { | 2695 | { |
2686 | /* Broadcasting on loopback does not make sense */ | 2696 | /* Broadcasting on loopback does not make sense */ |
@@ -2691,9 +2701,9 @@ iface_proc (void *cls, | |||
2691 | for (bi = bi_head; NULL != bi; bi = bi->next) | 2701 | for (bi = bi_head; NULL != bi; bi = bi->next) |
2692 | { | 2702 | { |
2693 | if ( (bi->salen == addrlen) && | 2703 | if ( (bi->salen == addrlen) && |
2694 | (0 == memcmp (addr, | 2704 | (0 == memcmp (addr, |
2695 | bi->sa, | 2705 | bi->sa, |
2696 | addrlen)) ) | 2706 | addrlen)) ) |
2697 | { | 2707 | { |
2698 | bi->found = GNUNET_YES; | 2708 | bi->found = GNUNET_YES; |
2699 | return GNUNET_OK; | 2709 | return GNUNET_OK; |
@@ -2709,10 +2719,10 @@ iface_proc (void *cls, | |||
2709 | 2719 | ||
2710 | bi = GNUNET_new (struct BroadcastInterface); | 2720 | bi = GNUNET_new (struct BroadcastInterface); |
2711 | bi->sa = GNUNET_memdup (addr, | 2721 | bi->sa = GNUNET_memdup (addr, |
2712 | addrlen); | 2722 | addrlen); |
2713 | if (NULL != broadcast_addr) | 2723 | if (NULL != broadcast_addr) |
2714 | bi->ba = GNUNET_memdup (broadcast_addr, | 2724 | bi->ba = GNUNET_memdup (broadcast_addr, |
2715 | addrlen); | 2725 | addrlen); |
2716 | bi->salen = addrlen; | 2726 | bi->salen = addrlen; |
2717 | bi->found = GNUNET_YES; | 2727 | bi->found = GNUNET_YES; |
2718 | bi->bcm.sender = my_identity; | 2728 | bi->bcm.sender = my_identity; |
@@ -2720,17 +2730,17 @@ iface_proc (void *cls, | |||
2720 | ubs.purpose.size = htonl (sizeof (ubs)); | 2730 | ubs.purpose.size = htonl (sizeof (ubs)); |
2721 | ubs.sender = my_identity; | 2731 | ubs.sender = my_identity; |
2722 | GNUNET_CRYPTO_hash (addr, | 2732 | GNUNET_CRYPTO_hash (addr, |
2723 | addrlen, | 2733 | addrlen, |
2724 | &ubs.h_address); | 2734 | &ubs.h_address); |
2725 | GNUNET_assert (GNUNET_OK == | 2735 | GNUNET_assert (GNUNET_OK == |
2726 | GNUNET_CRYPTO_eddsa_sign (my_private_key, | 2736 | GNUNET_CRYPTO_eddsa_sign (my_private_key, |
2727 | &ubs.purpose, | 2737 | &ubs.purpose, |
2728 | &bi->bcm.sender_sig)); | 2738 | &bi->bcm.sender_sig)); |
2729 | bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, | 2739 | bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, |
2730 | bi); | 2740 | bi); |
2731 | GNUNET_CONTAINER_DLL_insert (bi_head, | 2741 | GNUNET_CONTAINER_DLL_insert (bi_head, |
2732 | bi_tail, | 2742 | bi_tail, |
2733 | bi); | 2743 | bi); |
2734 | if ( (AF_INET6 == addr->sa_family) && | 2744 | if ( (AF_INET6 == addr->sa_family) && |
2735 | (NULL != broadcast_addr) ) | 2745 | (NULL != broadcast_addr) ) |
2736 | { | 2746 | { |
@@ -2740,7 +2750,7 @@ iface_proc (void *cls, | |||
2740 | 2750 | ||
2741 | GNUNET_assert (1 == | 2751 | GNUNET_assert (1 == |
2742 | inet_pton (AF_INET6, | 2752 | inet_pton (AF_INET6, |
2743 | "FF05::13B", | 2753 | "FF05::13B", |
2744 | &bi->mcreq.ipv6mr_multiaddr)); | 2754 | &bi->mcreq.ipv6mr_multiaddr)); |
2745 | 2755 | ||
2746 | /* http://tools.ietf.org/html/rfc2553#section-5.2: | 2756 | /* http://tools.ietf.org/html/rfc2553#section-5.2: |
@@ -2760,10 +2770,10 @@ iface_proc (void *cls, | |||
2760 | if (GNUNET_OK != | 2770 | if (GNUNET_OK != |
2761 | GNUNET_NETWORK_socket_setsockopt | 2771 | GNUNET_NETWORK_socket_setsockopt |
2762 | (udp_sock, | 2772 | (udp_sock, |
2763 | IPPROTO_IPV6, | 2773 | IPPROTO_IPV6, |
2764 | IPV6_JOIN_GROUP, | 2774 | IPV6_JOIN_GROUP, |
2765 | &bi->mcreq, | 2775 | &bi->mcreq, |
2766 | sizeof (bi->mcreq))) | 2776 | sizeof (bi->mcreq))) |
2767 | { | 2777 | { |
2768 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 2778 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, |
2769 | "setsockopt"); | 2779 | "setsockopt"); |
@@ -2789,7 +2799,7 @@ do_broadcast (void *cls) | |||
2789 | bi = bi->next) | 2799 | bi = bi->next) |
2790 | bi->found = GNUNET_NO; | 2800 | bi->found = GNUNET_NO; |
2791 | GNUNET_OS_network_interfaces_list (&iface_proc, | 2801 | GNUNET_OS_network_interfaces_list (&iface_proc, |
2792 | NULL); | 2802 | NULL); |
2793 | for (struct BroadcastInterface *bi = bi_head; | 2803 | for (struct BroadcastInterface *bi = bi_head; |
2794 | NULL != bi; | 2804 | NULL != bi; |
2795 | bi = bin) | 2805 | bi = bin) |
@@ -2800,8 +2810,8 @@ do_broadcast (void *cls) | |||
2800 | } | 2810 | } |
2801 | broadcast_task | 2811 | broadcast_task |
2802 | = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, | 2812 | = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, |
2803 | &do_broadcast, | 2813 | &do_broadcast, |
2804 | NULL); | 2814 | NULL); |
2805 | } | 2815 | } |
2806 | 2816 | ||
2807 | 2817 | ||
@@ -2829,10 +2839,10 @@ run (void *cls, | |||
2829 | cfg = c; | 2839 | cfg = c; |
2830 | if (GNUNET_OK != | 2840 | if (GNUNET_OK != |
2831 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 2841 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
2832 | COMMUNICATOR_CONFIG_SECTION, | 2842 | COMMUNICATOR_CONFIG_SECTION, |
2833 | "BINDTO", | 2843 | "BINDTO", |
2834 | &bindto)) | 2844 | &bindto)) |
2835 | { | 2845 | { |
2836 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 2846 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
2837 | COMMUNICATOR_CONFIG_SECTION, | 2847 | COMMUNICATOR_CONFIG_SECTION, |
2838 | "BINDTO"); | 2848 | "BINDTO"); |
@@ -2996,7 +3006,7 @@ main (int argc, | |||
2996 | 3006 | ||
2997 | if (GNUNET_OK != | 3007 | if (GNUNET_OK != |
2998 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 3008 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
2999 | &argc, &argv)) | 3009 | &argc, &argv)) |
3000 | return 2; | 3010 | return 2; |
3001 | 3011 | ||
3002 | ret = | 3012 | ret = |
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index d30acbd5f..642703f29 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -634,21 +634,21 @@ mq_error (void *cls, | |||
634 | */ | 634 | */ |
635 | static struct Queue * | 635 | static struct Queue * |
636 | setup_queue (const struct GNUNET_PeerIdentity *target, | 636 | setup_queue (const struct GNUNET_PeerIdentity *target, |
637 | enum GNUNET_TRANSPORT_ConnectionStatus cs, | 637 | enum GNUNET_TRANSPORT_ConnectionStatus cs, |
638 | const struct sockaddr_un *un, | 638 | const struct sockaddr_un *un, |
639 | socklen_t un_len) | 639 | socklen_t un_len) |
640 | { | 640 | { |
641 | struct Queue *queue; | 641 | struct Queue *queue; |
642 | 642 | ||
643 | queue = GNUNET_new (struct Queue); | 643 | queue = GNUNET_new (struct Queue); |
644 | queue->target = *target; | 644 | queue->target = *target; |
645 | queue->address = GNUNET_memdup (un, | 645 | queue->address = GNUNET_memdup (un, |
646 | un_len); | 646 | un_len); |
647 | queue->address_len = un_len; | 647 | queue->address_len = un_len; |
648 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, | 648 | (void) GNUNET_CONTAINER_multipeermap_put (queue_map, |
649 | &queue->target, | 649 | &queue->target, |
650 | queue, | 650 | queue, |
651 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 651 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
652 | GNUNET_STATISTICS_set (stats, | 652 | GNUNET_STATISTICS_set (stats, |
653 | "# queues active", | 653 | "# queues active", |
654 | GNUNET_CONTAINER_multipeermap_size (queue_map), | 654 | GNUNET_CONTAINER_multipeermap_size (queue_map), |
@@ -656,37 +656,37 @@ setup_queue (const struct GNUNET_PeerIdentity *target, | |||
656 | queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 656 | queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
657 | queue->timeout_task | 657 | queue->timeout_task |
658 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 658 | = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
659 | &queue_timeout, | 659 | &queue_timeout, |
660 | queue); | 660 | queue); |
661 | queue->mq | 661 | queue->mq |
662 | = GNUNET_MQ_queue_for_callbacks (&mq_send, | 662 | = GNUNET_MQ_queue_for_callbacks (&mq_send, |
663 | &mq_destroy, | 663 | &mq_destroy, |
664 | &mq_cancel, | 664 | &mq_cancel, |
665 | queue, | 665 | queue, |
666 | NULL, | 666 | NULL, |
667 | &mq_error, | 667 | &mq_error, |
668 | queue); | 668 | queue); |
669 | { | 669 | { |
670 | char *foreign_addr; | 670 | char *foreign_addr; |
671 | 671 | ||
672 | if ('\0' == un->sun_path[0]) | 672 | if ('\0' == un->sun_path[0]) |
673 | GNUNET_asprintf (&foreign_addr, | 673 | GNUNET_asprintf (&foreign_addr, |
674 | "%s-@%s", | 674 | "%s-@%s", |
675 | COMMUNICATOR_ADDRESS_PREFIX, | 675 | COMMUNICATOR_ADDRESS_PREFIX, |
676 | &un->sun_path[1]); | 676 | &un->sun_path[1]); |
677 | else | 677 | else |
678 | GNUNET_asprintf (&foreign_addr, | 678 | GNUNET_asprintf (&foreign_addr, |
679 | "%s-%s", | 679 | "%s-%s", |
680 | COMMUNICATOR_ADDRESS_PREFIX, | 680 | COMMUNICATOR_ADDRESS_PREFIX, |
681 | un->sun_path); | 681 | un->sun_path); |
682 | queue->qh | 682 | queue->qh |
683 | = GNUNET_TRANSPORT_communicator_mq_add (ch, | 683 | = GNUNET_TRANSPORT_communicator_mq_add (ch, |
684 | &queue->target, | 684 | &queue->target, |
685 | foreign_addr, | 685 | foreign_addr, |
686 | UNIX_MTU, | 686 | UNIX_MTU, |
687 | GNUNET_NT_LOOPBACK, | 687 | GNUNET_NT_LOOPBACK, |
688 | cs, | 688 | cs, |
689 | queue->mq); | 689 | queue->mq); |
690 | GNUNET_free (foreign_addr); | 690 | GNUNET_free (foreign_addr); |
691 | } | 691 | } |
692 | return queue; | 692 | return queue; |
@@ -718,16 +718,16 @@ receive_complete_cb (void *cls, | |||
718 | delivering_messages--; | 718 | delivering_messages--; |
719 | if (GNUNET_OK != success) | 719 | if (GNUNET_OK != success) |
720 | GNUNET_STATISTICS_update (stats, | 720 | GNUNET_STATISTICS_update (stats, |
721 | "# transport transmission failures", | 721 | "# transport transmission failures", |
722 | 1, | 722 | 1, |
723 | GNUNET_NO); | 723 | GNUNET_NO); |
724 | GNUNET_assert (NULL != unix_sock); | 724 | GNUNET_assert (NULL != unix_sock); |
725 | if ( (NULL == read_task) && | 725 | if ( (NULL == read_task) && |
726 | (delivering_messages < max_queue_length) ) | 726 | (delivering_messages < max_queue_length) ) |
727 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 727 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
728 | unix_sock, | 728 | unix_sock, |
729 | &select_read_cb, | 729 | &select_read_cb, |
730 | NULL); | 730 | NULL); |
731 | } | 731 | } |
732 | 732 | ||
733 | 733 | ||
@@ -751,16 +751,16 @@ select_read_cb (void *cls) | |||
751 | 751 | ||
752 | GNUNET_assert (NULL != unix_sock); | 752 | GNUNET_assert (NULL != unix_sock); |
753 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 753 | read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
754 | unix_sock, | 754 | unix_sock, |
755 | &select_read_cb, | 755 | &select_read_cb, |
756 | NULL); | 756 | NULL); |
757 | addrlen = sizeof (un); | 757 | addrlen = sizeof (un); |
758 | memset (&un, | 758 | memset (&un, |
759 | 0, | 759 | 0, |
760 | sizeof (un)); | 760 | sizeof (un)); |
761 | ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, | 761 | ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, |
762 | buf, | 762 | buf, |
763 | sizeof (buf), | 763 | sizeof (buf), |
764 | (struct sockaddr *) &un, | 764 | (struct sockaddr *) &un, |
765 | &addrlen); | 765 | &addrlen); |
766 | if ( (-1 == ret) && | 766 | if ( (-1 == ret) && |
@@ -774,9 +774,9 @@ select_read_cb (void *cls) | |||
774 | return; | 774 | return; |
775 | } | 775 | } |
776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
777 | "Read %d bytes from socket %s\n", | 777 | "Read %d bytes from socket %s\n", |
778 | (int) ret, | 778 | (int) ret, |
779 | un.sun_path); | 779 | un.sun_path); |
780 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 780 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
781 | msg = (struct UNIXMessage *) buf; | 781 | msg = (struct UNIXMessage *) buf; |
782 | msize = ntohs (msg->header.size); | 782 | msize = ntohs (msg->header.size); |
@@ -787,13 +787,13 @@ select_read_cb (void *cls) | |||
787 | return; | 787 | return; |
788 | } | 788 | } |
789 | queue = lookup_queue (&msg->sender, | 789 | queue = lookup_queue (&msg->sender, |
790 | &un, | 790 | &un, |
791 | addrlen); | 791 | addrlen); |
792 | if (NULL == queue) | 792 | if (NULL == queue) |
793 | queue = setup_queue (&msg->sender, | 793 | queue = setup_queue (&msg->sender, |
794 | GNUNET_TRANSPORT_CS_INBOUND, | 794 | GNUNET_TRANSPORT_CS_INBOUND, |
795 | &un, | 795 | &un, |
796 | addrlen); | 796 | addrlen); |
797 | else | 797 | else |
798 | reschedule_queue_timeout (queue); | 798 | reschedule_queue_timeout (queue); |
799 | if (NULL == queue) | 799 | if (NULL == queue) |
@@ -821,16 +821,17 @@ select_read_cb (void *cls) | |||
821 | sizeof (al_hdr)); | 821 | sizeof (al_hdr)); |
822 | csize = ntohs (al_hdr.size); | 822 | csize = ntohs (al_hdr.size); |
823 | if ( (csize < sizeof (struct GNUNET_MessageHeader)) || | 823 | if ( (csize < sizeof (struct GNUNET_MessageHeader)) || |
824 | (csize > tsize - offset)) | 824 | (csize > tsize - offset)) |
825 | { | 825 | { |
826 | GNUNET_break_op (0); | 826 | GNUNET_break_op (0); |
827 | break; | 827 | break; |
828 | } | 828 | } |
829 | ret = GNUNET_TRANSPORT_communicator_receive (ch, | 829 | ret = GNUNET_TRANSPORT_communicator_receive (ch, |
830 | &msg->sender, | 830 | &msg->sender, |
831 | currhdr, | 831 | currhdr, |
832 | &receive_complete_cb, | 832 | GNUNET_TIME_UNIT_FOREVER_REL, |
833 | NULL); | 833 | &receive_complete_cb, |
834 | NULL); | ||
834 | if (GNUNET_SYSERR == ret) | 835 | if (GNUNET_SYSERR == ret) |
835 | return; /* transport not up */ | 836 | return; /* transport not up */ |
836 | if (GNUNET_NO == ret) | 837 | if (GNUNET_NO == ret) |
@@ -898,16 +899,16 @@ mq_init (void *cls, | |||
898 | return GNUNET_OK; | 899 | return GNUNET_OK; |
899 | } | 900 | } |
900 | queue = setup_queue (peer, | 901 | queue = setup_queue (peer, |
901 | GNUNET_TRANSPORT_CS_OUTBOUND, | 902 | GNUNET_TRANSPORT_CS_OUTBOUND, |
902 | un, | 903 | un, |
903 | un_len); | 904 | un_len); |
904 | GNUNET_free (un); | 905 | GNUNET_free (un); |
905 | if (NULL == queue) | 906 | if (NULL == queue) |
906 | { | 907 | { |
907 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 908 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
908 | "Failed to setup queue to %s at `%s'\n", | 909 | "Failed to setup queue to %s at `%s'\n", |
909 | GNUNET_i2s (peer), | 910 | GNUNET_i2s (peer), |
910 | path); | 911 | path); |
911 | return GNUNET_NO; | 912 | return GNUNET_NO; |
912 | } | 913 | } |
913 | return GNUNET_OK; | 914 | return GNUNET_OK; |
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index ecff6b6e1..342b4c2bc 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -33,14 +33,6 @@ | |||
33 | * transport-to-transport traffic) | 33 | * transport-to-transport traffic) |
34 | * | 34 | * |
35 | * Implement next: | 35 | * Implement next: |
36 | * - address validation: what is our plan here? | ||
37 | * #1 Peerstore only gets 'validated' addresses | ||
38 | * #2 transport should use validation to also establish | ||
39 | * effective flow control (for uni-directional transports!) | ||
40 | * #3 only validated addresses are selected for scheduling; that | ||
41 | * also ensures we know the RTT | ||
42 | * #4 to ensure flow control and RTT are OK, we always do the | ||
43 | * 'validation', even if address comes from PEERSTORE??? | ||
44 | * - ACK handling / retransmission | 36 | * - ACK handling / retransmission |
45 | * - track RTT, distance, loss, etc. | 37 | * - track RTT, distance, loss, etc. |
46 | * - DV data structures: | 38 | * - DV data structures: |
@@ -67,7 +59,7 @@ | |||
67 | * Design realizations / discussion: | 59 | * Design realizations / discussion: |
68 | * - communicators do flow control by calling MQ "notify sent" | 60 | * - communicators do flow control by calling MQ "notify sent" |
69 | * when 'ready'. They determine flow implicitly (i.e. TCP blocking) | 61 | * when 'ready'. They determine flow implicitly (i.e. TCP blocking) |
70 | * or explicitly via background channel FC ACKs. As long as the | 62 | * or explicitly via backchannel FC ACKs. As long as the |
71 | * channel is not full, they may 'notify sent' even if the other | 63 | * channel is not full, they may 'notify sent' even if the other |
72 | * peer has not yet confirmed receipt. The other peer confirming | 64 | * peer has not yet confirmed receipt. The other peer confirming |
73 | * is _only_ for FC, not for more reliable transmission; reliable | 65 | * is _only_ for FC, not for more reliable transmission; reliable |
@@ -1236,7 +1228,6 @@ enum PendingMessageType | |||
1236 | */ | 1228 | */ |
1237 | PMT_ACKNOWLEDGEMENT = 3 | 1229 | PMT_ACKNOWLEDGEMENT = 3 |
1238 | 1230 | ||
1239 | |||
1240 | }; | 1231 | }; |
1241 | 1232 | ||
1242 | 1233 | ||
@@ -1658,11 +1649,6 @@ struct ValidationState | |||
1658 | struct GNUNET_PEERSTORE_StoreContext *sc; | 1649 | struct GNUNET_PEERSTORE_StoreContext *sc; |
1659 | 1650 | ||
1660 | /** | 1651 | /** |
1661 | * Network type (presumably) associated with @e address. NEEDED? | ||
1662 | */ | ||
1663 | enum GNUNET_NetworkType nt; | ||
1664 | |||
1665 | /** | ||
1666 | * We are technically ready to send the challenge, but we are waiting for | 1652 | * We are technically ready to send the challenge, but we are waiting for |
1667 | * the respective queue to become available for transmission. | 1653 | * the respective queue to become available for transmission. |
1668 | */ | 1654 | */ |
@@ -1671,8 +1657,6 @@ struct ValidationState | |||
1671 | }; | 1657 | }; |
1672 | 1658 | ||
1673 | 1659 | ||
1674 | |||
1675 | |||
1676 | /** | 1660 | /** |
1677 | * Head of linked list of all clients to this service. | 1661 | * Head of linked list of all clients to this service. |
1678 | */ | 1662 | */ |
@@ -2133,7 +2117,7 @@ core_send_connect_info (struct TransportClient *tc, | |||
2133 | cim->quota_out = quota_out; | 2117 | cim->quota_out = quota_out; |
2134 | cim->id = *pid; | 2118 | cim->id = *pid; |
2135 | GNUNET_MQ_send (tc->mq, | 2119 | GNUNET_MQ_send (tc->mq, |
2136 | env); | 2120 | env); |
2137 | } | 2121 | } |
2138 | 2122 | ||
2139 | 2123 | ||
@@ -2967,6 +2951,15 @@ static void | |||
2967 | route_message (const struct GNUNET_PeerIdentity *target, | 2951 | route_message (const struct GNUNET_PeerIdentity *target, |
2968 | struct GNUNET_MessageHeader *hdr) | 2952 | struct GNUNET_MessageHeader *hdr) |
2969 | { | 2953 | { |
2954 | // FIXME: this one is tricky: | ||
2955 | // - we could try a direct, reliable channel | ||
2956 | // - if that is unavailable / for load balancing, we may try: | ||
2957 | // * multiple (?) direct unreliable channels - depending on loss rate? | ||
2958 | // * some (?) DV channels - if above unavailable / too lossy? | ||
2959 | // * _random_ other peers ("broadcasting") in hope of *discovering* | ||
2960 | // a path back! - if all else fails | ||
2961 | // => need more on DV first! | ||
2962 | |||
2970 | // FIXME: send hdr to target, free hdr (possibly using DV, possibly broadcasting) | 2963 | // FIXME: send hdr to target, free hdr (possibly using DV, possibly broadcasting) |
2971 | GNUNET_free (hdr); | 2964 | GNUNET_free (hdr); |
2972 | } | 2965 | } |
@@ -3096,20 +3089,29 @@ static void | |||
3096 | store_pi (void *cls) | 3089 | store_pi (void *cls) |
3097 | { | 3090 | { |
3098 | struct AddressListEntry *ale = cls; | 3091 | struct AddressListEntry *ale = cls; |
3092 | void *addr; | ||
3093 | size_t addr_len; | ||
3099 | struct GNUNET_TIME_Absolute expiration; | 3094 | struct GNUNET_TIME_Absolute expiration; |
3100 | 3095 | ||
3101 | ale->st = NULL; | 3096 | ale->st = NULL; |
3102 | expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); | 3097 | expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); |
3098 | GNUNET_HELLO_sign_address (ale->address, | ||
3099 | ale->nt, | ||
3100 | expiration, | ||
3101 | GST_my_private_key, | ||
3102 | &addr, | ||
3103 | &addr_len); | ||
3103 | ale->sc = GNUNET_PEERSTORE_store (peerstore, | 3104 | ale->sc = GNUNET_PEERSTORE_store (peerstore, |
3104 | "transport", | 3105 | "transport", |
3105 | &GST_my_identity, | 3106 | &GST_my_identity, |
3106 | GNUNET_HELLO_PEERSTORE_KEY, | 3107 | GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, |
3107 | ale->address, | 3108 | addr, |
3108 | strlen (ale->address) + 1, | 3109 | addr_len, |
3109 | expiration, | 3110 | expiration, |
3110 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | 3111 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, |
3111 | &peerstore_store_own_cb, | 3112 | &peerstore_store_own_cb, |
3112 | ale); | 3113 | ale); |
3114 | GNUNET_free (addr); | ||
3113 | if (NULL == ale->sc) | 3115 | if (NULL == ale->sc) |
3114 | { | 3116 | { |
3115 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3117 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -3359,7 +3361,7 @@ send_fragment_ack (struct ReassemblyContext *rc) | |||
3359 | ack->reassembly_timeout | 3361 | ack->reassembly_timeout |
3360 | = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); | 3362 | = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)); |
3361 | route_message (&rc->neighbour->pid, | 3363 | route_message (&rc->neighbour->pid, |
3362 | &ack->header); | 3364 | &ack->header); |
3363 | rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; | 3365 | rc->avg_ack_delay = GNUNET_TIME_UNIT_ZERO; |
3364 | rc->num_acks = 0; | 3366 | rc->num_acks = 0; |
3365 | rc->extra_acks = 0LLU; | 3367 | rc->extra_acks = 0LLU; |
@@ -3425,10 +3427,10 @@ handle_fragment_box (void *cls, | |||
3425 | rc, | 3427 | rc, |
3426 | rc->reassembly_timeout.abs_value_us); | 3428 | rc->reassembly_timeout.abs_value_us); |
3427 | GNUNET_assert (GNUNET_OK == | 3429 | GNUNET_assert (GNUNET_OK == |
3428 | GNUNET_CONTAINER_multishortmap_put (n->reassembly_map, | 3430 | GNUNET_CONTAINER_multishortmap_put (n->reassembly_map, |
3429 | &rc->msg_uuid, | 3431 | &rc->msg_uuid, |
3430 | rc, | 3432 | rc, |
3431 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 3433 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
3432 | target = (char *) &rc[1]; | 3434 | target = (char *) &rc[1]; |
3433 | rc->bitfield = (uint8_t *) (target + rc->msg_size); | 3435 | rc->bitfield = (uint8_t *) (target + rc->msg_size); |
3434 | rc->msg_missing = rc->msg_size; | 3436 | rc->msg_missing = rc->msg_size; |
@@ -3601,14 +3603,14 @@ handle_reliability_box (void *cls, | |||
3601 | ack->header.size = htons (sizeof (*ack) + | 3603 | ack->header.size = htons (sizeof (*ack) + |
3602 | sizeof (struct GNUNET_ShortHashCode)); | 3604 | sizeof (struct GNUNET_ShortHashCode)); |
3603 | memcpy (&ack[1], | 3605 | memcpy (&ack[1], |
3604 | &rb->msg_uuid, | 3606 | &rb->msg_uuid, |
3605 | sizeof (struct GNUNET_ShortHashCode)); | 3607 | sizeof (struct GNUNET_ShortHashCode)); |
3606 | route_message (&cmc->im.sender, | 3608 | route_message (&cmc->im.sender, |
3607 | &ack->header); | 3609 | &ack->header); |
3608 | } | 3610 | } |
3609 | /* continue with inner message */ | 3611 | /* continue with inner message */ |
3610 | demultiplex_with_cmc (cmc, | 3612 | demultiplex_with_cmc (cmc, |
3611 | inbox); | 3613 | inbox); |
3612 | } | 3614 | } |
3613 | 3615 | ||
3614 | 3616 | ||
@@ -3846,8 +3848,37 @@ handle_validation_challenge (void *cls, | |||
3846 | const struct TransportValidationChallenge *tvc) | 3848 | const struct TransportValidationChallenge *tvc) |
3847 | { | 3849 | { |
3848 | struct CommunicatorMessageContext *cmc = cls; | 3850 | struct CommunicatorMessageContext *cmc = cls; |
3851 | struct TransportValidationResponse *tvr; | ||
3852 | |||
3853 | if (cmc->total_hops > 0) | ||
3854 | { | ||
3855 | /* DV routing is not allowed for validation challenges! */ | ||
3856 | GNUNET_break_op (0); | ||
3857 | finish_cmc_handling (cmc); | ||
3858 | return; | ||
3859 | } | ||
3860 | tvr = GNUNET_new (struct TransportValidationResponse); | ||
3861 | tvr->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); | ||
3862 | tvr->header.size = htons (sizeof (*tvr)); | ||
3863 | tvr->challenge = tvc->challenge; | ||
3864 | tvr->origin_time = tvc->sender_time; | ||
3865 | tvr->validity_duration = cmc->im.expected_address_validity; | ||
3866 | { | ||
3867 | /* create signature */ | ||
3868 | struct TransportValidationPS tvp = { | ||
3869 | .purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), | ||
3870 | .purpose.size = htonl (sizeof (tvp)), | ||
3871 | .validity_duration = tvr->validity_duration, | ||
3872 | .challenge = tvc->challenge | ||
3873 | }; | ||
3849 | 3874 | ||
3850 | // FIXME: sign challenge and try to get it back to the origin! | 3875 | GNUNET_assert (GNUNET_OK == |
3876 | GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, | ||
3877 | &tvp.purpose, | ||
3878 | &tvr->signature)); | ||
3879 | } | ||
3880 | route_message (&cmc->im.sender, | ||
3881 | &tvr->header); | ||
3851 | finish_cmc_handling (cmc); | 3882 | finish_cmc_handling (cmc); |
3852 | } | 3883 | } |
3853 | 3884 | ||
@@ -4054,15 +4085,14 @@ handle_validation_response (void *cls, | |||
4054 | vs->sc = GNUNET_PEERSTORE_store (peerstore, | 4085 | vs->sc = GNUNET_PEERSTORE_store (peerstore, |
4055 | "transport", | 4086 | "transport", |
4056 | &cmc->im.sender, | 4087 | &cmc->im.sender, |
4057 | GNUNET_HELLO_PEERSTORE_KEY, | 4088 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, |
4058 | vs->address, | 4089 | vs->address, |
4059 | strlen (vs->address) + 1, | 4090 | strlen (vs->address) + 1, |
4060 | vs->valid_until, | 4091 | vs->valid_until, |
4061 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, | 4092 | GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, |
4062 | &peerstore_store_validation_cb, | 4093 | &peerstore_store_validation_cb, |
4063 | vs); | 4094 | vs); |
4064 | // FIXME: now that we know that the address is *valid*, | 4095 | // FIXME: should we find the matching queue and update the RTT? |
4065 | // do we need to trigger _using_ it for something? | ||
4066 | finish_cmc_handling (cmc); | 4096 | finish_cmc_handling (cmc); |
4067 | } | 4097 | } |
4068 | 4098 | ||
@@ -5183,97 +5213,6 @@ handle_queue_create_fail (void *cls, | |||
5183 | 5213 | ||
5184 | 5214 | ||
5185 | /** | 5215 | /** |
5186 | * Function called by PEERSTORE for each matching record. | ||
5187 | * | ||
5188 | * @param cls closure | ||
5189 | * @param record peerstore record information | ||
5190 | * @param emsg error message, or NULL if no errors | ||
5191 | */ | ||
5192 | static void | ||
5193 | handle_hello (void *cls, | ||
5194 | const struct GNUNET_PEERSTORE_Record *record, | ||
5195 | const char *emsg) | ||
5196 | { | ||
5197 | struct PeerRequest *pr = cls; | ||
5198 | const char *val; | ||
5199 | |||
5200 | if (NULL != emsg) | ||
5201 | { | ||
5202 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5203 | "Got failure from PEERSTORE: %s\n", | ||
5204 | emsg); | ||
5205 | return; | ||
5206 | } | ||
5207 | val = record->value; | ||
5208 | if ( (0 == record->value_size) || | ||
5209 | ('\0' != val[record->value_size - 1]) ) | ||
5210 | { | ||
5211 | GNUNET_break (0); | ||
5212 | return; | ||
5213 | } | ||
5214 | suggest_to_connect (&pr->pid, | ||
5215 | (const char *) record->value); | ||
5216 | } | ||
5217 | |||
5218 | |||
5219 | /** | ||
5220 | * We have received a `struct ExpressPreferenceMessage` from an application client. | ||
5221 | * | ||
5222 | * @param cls handle to the client | ||
5223 | * @param msg the start message | ||
5224 | */ | ||
5225 | static void | ||
5226 | handle_suggest (void *cls, | ||
5227 | const struct ExpressPreferenceMessage *msg) | ||
5228 | { | ||
5229 | struct TransportClient *tc = cls; | ||
5230 | struct PeerRequest *pr; | ||
5231 | |||
5232 | if (CT_NONE == tc->type) | ||
5233 | { | ||
5234 | tc->type = CT_APPLICATION; | ||
5235 | tc->details.application.requests | ||
5236 | = GNUNET_CONTAINER_multipeermap_create (16, | ||
5237 | GNUNET_YES); | ||
5238 | } | ||
5239 | if (CT_APPLICATION != tc->type) | ||
5240 | { | ||
5241 | GNUNET_break (0); | ||
5242 | GNUNET_SERVICE_client_drop (tc->client); | ||
5243 | return; | ||
5244 | } | ||
5245 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5246 | "Client suggested we talk to %s with preference %d at rate %u\n", | ||
5247 | GNUNET_i2s (&msg->peer), | ||
5248 | (int) ntohl (msg->pk), | ||
5249 | (int) ntohl (msg->bw.value__)); | ||
5250 | pr = GNUNET_new (struct PeerRequest); | ||
5251 | pr->tc = tc; | ||
5252 | pr->pid = msg->peer; | ||
5253 | pr->bw = msg->bw; | ||
5254 | pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); | ||
5255 | if (GNUNET_YES != | ||
5256 | GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests, | ||
5257 | &pr->pid, | ||
5258 | pr, | ||
5259 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
5260 | { | ||
5261 | GNUNET_break (0); | ||
5262 | GNUNET_free (pr); | ||
5263 | GNUNET_SERVICE_client_drop (tc->client); | ||
5264 | return; | ||
5265 | } | ||
5266 | pr->wc = GNUNET_PEERSTORE_watch (peerstore, | ||
5267 | "transport", | ||
5268 | &pr->pid, | ||
5269 | GNUNET_HELLO_PEERSTORE_KEY, | ||
5270 | &handle_hello, | ||
5271 | pr); | ||
5272 | GNUNET_SERVICE_client_continue (tc->client); | ||
5273 | } | ||
5274 | |||
5275 | |||
5276 | /** | ||
5277 | * We have received a `struct ExpressPreferenceMessage` from an application client. | 5216 | * We have received a `struct ExpressPreferenceMessage` from an application client. |
5278 | * | 5217 | * |
5279 | * @param cls handle to the client | 5218 | * @param cls handle to the client |
@@ -5374,13 +5313,11 @@ check_known_address (void *cls, | |||
5374 | * @param pid peer the @a address is for | 5313 | * @param pid peer the @a address is for |
5375 | * @param address an address to reach @a pid (presumably) | 5314 | * @param address an address to reach @a pid (presumably) |
5376 | * @param expiration when did @a pid claim @a address will become invalid | 5315 | * @param expiration when did @a pid claim @a address will become invalid |
5377 | * @param nt network type of @a address | ||
5378 | */ | 5316 | */ |
5379 | static void | 5317 | static void |
5380 | start_address_validation (const struct GNUNET_PeerIdentity *pid, | 5318 | start_address_validation (const struct GNUNET_PeerIdentity *pid, |
5381 | const char *address, | 5319 | const char *address, |
5382 | struct GNUNET_TIME_Absolute expiration, | 5320 | struct GNUNET_TIME_Absolute expiration) |
5383 | enum GNUNET_NetworkType nt) | ||
5384 | { | 5321 | { |
5385 | struct GNUNET_TIME_Absolute now; | 5322 | struct GNUNET_TIME_Absolute now; |
5386 | struct ValidationState *vs; | 5323 | struct ValidationState *vs; |
@@ -5389,10 +5326,8 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
5389 | .vs = NULL | 5326 | .vs = NULL |
5390 | }; | 5327 | }; |
5391 | 5328 | ||
5392 | |||
5393 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 5329 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) |
5394 | return; /* expired */ | 5330 | return; /* expired */ |
5395 | |||
5396 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 5331 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, |
5397 | pid, | 5332 | pid, |
5398 | &check_known_address, | 5333 | &check_known_address, |
@@ -5421,7 +5356,6 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
5421 | &vs->challenge, | 5356 | &vs->challenge, |
5422 | sizeof (vs->challenge)); | 5357 | sizeof (vs->challenge)); |
5423 | vs->address = GNUNET_strdup (address); | 5358 | vs->address = GNUNET_strdup (address); |
5424 | vs->nt = nt; | ||
5425 | GNUNET_assert (GNUNET_YES == | 5359 | GNUNET_assert (GNUNET_YES == |
5426 | GNUNET_CONTAINER_multipeermap_put (validation_map, | 5360 | GNUNET_CONTAINER_multipeermap_put (validation_map, |
5427 | &vs->pid, | 5361 | &vs->pid, |
@@ -5433,6 +5367,98 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
5433 | 5367 | ||
5434 | 5368 | ||
5435 | /** | 5369 | /** |
5370 | * Function called by PEERSTORE for each matching record. | ||
5371 | * | ||
5372 | * @param cls closure | ||
5373 | * @param record peerstore record information | ||
5374 | * @param emsg error message, or NULL if no errors | ||
5375 | */ | ||
5376 | static void | ||
5377 | handle_hello (void *cls, | ||
5378 | const struct GNUNET_PEERSTORE_Record *record, | ||
5379 | const char *emsg) | ||
5380 | { | ||
5381 | struct PeerRequest *pr = cls; | ||
5382 | const char *val; | ||
5383 | |||
5384 | if (NULL != emsg) | ||
5385 | { | ||
5386 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
5387 | "Got failure from PEERSTORE: %s\n", | ||
5388 | emsg); | ||
5389 | return; | ||
5390 | } | ||
5391 | val = record->value; | ||
5392 | if ( (0 == record->value_size) || | ||
5393 | ('\0' != val[record->value_size - 1]) ) | ||
5394 | { | ||
5395 | GNUNET_break (0); | ||
5396 | return; | ||
5397 | } | ||
5398 | start_address_validation (&pr->pid, | ||
5399 | (const char *) record->value, | ||
5400 | record->expiry); | ||
5401 | } | ||
5402 | |||
5403 | |||
5404 | /** | ||
5405 | * We have received a `struct ExpressPreferenceMessage` from an application client. | ||
5406 | * | ||
5407 | * @param cls handle to the client | ||
5408 | * @param msg the start message | ||
5409 | */ | ||
5410 | static void | ||
5411 | handle_suggest (void *cls, | ||
5412 | const struct ExpressPreferenceMessage *msg) | ||
5413 | { | ||
5414 | struct TransportClient *tc = cls; | ||
5415 | struct PeerRequest *pr; | ||
5416 | |||
5417 | if (CT_NONE == tc->type) | ||
5418 | { | ||
5419 | tc->type = CT_APPLICATION; | ||
5420 | tc->details.application.requests | ||
5421 | = GNUNET_CONTAINER_multipeermap_create (16, | ||
5422 | GNUNET_YES); | ||
5423 | } | ||
5424 | if (CT_APPLICATION != tc->type) | ||
5425 | { | ||
5426 | GNUNET_break (0); | ||
5427 | GNUNET_SERVICE_client_drop (tc->client); | ||
5428 | return; | ||
5429 | } | ||
5430 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5431 | "Client suggested we talk to %s with preference %d at rate %u\n", | ||
5432 | GNUNET_i2s (&msg->peer), | ||
5433 | (int) ntohl (msg->pk), | ||
5434 | (int) ntohl (msg->bw.value__)); | ||
5435 | pr = GNUNET_new (struct PeerRequest); | ||
5436 | pr->tc = tc; | ||
5437 | pr->pid = msg->peer; | ||
5438 | pr->bw = msg->bw; | ||
5439 | pr->pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); | ||
5440 | if (GNUNET_YES != | ||
5441 | GNUNET_CONTAINER_multipeermap_put (tc->details.application.requests, | ||
5442 | &pr->pid, | ||
5443 | pr, | ||
5444 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | ||
5445 | { | ||
5446 | GNUNET_break (0); | ||
5447 | GNUNET_free (pr); | ||
5448 | GNUNET_SERVICE_client_drop (tc->client); | ||
5449 | return; | ||
5450 | } | ||
5451 | pr->wc = GNUNET_PEERSTORE_watch (peerstore, | ||
5452 | "transport", | ||
5453 | &pr->pid, | ||
5454 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, | ||
5455 | &handle_hello, | ||
5456 | pr); | ||
5457 | GNUNET_SERVICE_client_continue (tc->client); | ||
5458 | } | ||
5459 | |||
5460 | |||
5461 | /** | ||
5436 | * Given another peers address, consider checking it for validity | 5462 | * Given another peers address, consider checking it for validity |
5437 | * and then adding it to the Peerstore. | 5463 | * and then adding it to the Peerstore. |
5438 | * | 5464 | * |
@@ -5465,8 +5491,7 @@ handle_address_consider_verify (void *cls, | |||
5465 | } | 5491 | } |
5466 | start_address_validation (&hdr->peer, | 5492 | start_address_validation (&hdr->peer, |
5467 | address, | 5493 | address, |
5468 | expiration, | 5494 | expiration); |
5469 | nt); | ||
5470 | GNUNET_free (address); | 5495 | GNUNET_free (address); |
5471 | GNUNET_SERVICE_client_continue (tc->client); | 5496 | GNUNET_SERVICE_client_continue (tc->client); |
5472 | } | 5497 | } |
@@ -5504,8 +5529,7 @@ handle_request_hello_validation (void *cls, | |||
5504 | 5529 | ||
5505 | start_address_validation (&m->peer, | 5530 | start_address_validation (&m->peer, |
5506 | (const char *) &m[1], | 5531 | (const char *) &m[1], |
5507 | GNUNET_TIME_absolute_ntoh (m->expiration), | 5532 | GNUNET_TIME_absolute_ntoh (m->expiration)); |
5508 | (enum GNUNET_NetworkType) ntohl (m->nt)); | ||
5509 | GNUNET_SERVICE_client_continue (tc->client); | 5533 | GNUNET_SERVICE_client_continue (tc->client); |
5510 | } | 5534 | } |
5511 | 5535 | ||
diff --git a/src/transport/transport.h b/src/transport/transport.h index 7e0d9c2d4..b9c61f306 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -743,6 +743,12 @@ struct GNUNET_TRANSPORT_IncomingMessage | |||
743 | uint64_t fc_id GNUNET_PACKED; | 743 | uint64_t fc_id GNUNET_PACKED; |
744 | 744 | ||
745 | /** | 745 | /** |
746 | * How long does the communicator believe the address on which | ||
747 | * the message was received to remain valid? | ||
748 | */ | ||
749 | struct GNUNET_TIME_RelativeNBO expected_address_validity; | ||
750 | |||
751 | /** | ||
746 | * Sender identifier. | 752 | * Sender identifier. |
747 | */ | 753 | */ |
748 | struct GNUNET_PeerIdentity sender; | 754 | struct GNUNET_PeerIdentity sender; |
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c index 33092fb2a..6d497c967 100644 --- a/src/transport/transport_api2_communication.c +++ b/src/transport/transport_api2_communication.c | |||
@@ -906,6 +906,9 @@ GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHa | |||
906 | * @param sender presumed sender of the message (details to be checked | 906 | * @param sender presumed sender of the message (details to be checked |
907 | * by higher layers) | 907 | * by higher layers) |
908 | * @param msg the message | 908 | * @param msg the message |
909 | * @param expected_addr_validity how long does the communicator believe it | ||
910 | * will continue to be able to receive messages from the same address | ||
911 | * on which it received this message? | ||
909 | * @param cb function to call once handling the message is done, NULL if | 912 | * @param cb function to call once handling the message is done, NULL if |
910 | * flow control is not supported by this communicator | 913 | * flow control is not supported by this communicator |
911 | * @param cb_cls closure for @a cb | 914 | * @param cb_cls closure for @a cb |
@@ -919,6 +922,7 @@ int | |||
919 | GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, | 922 | GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, |
920 | const struct GNUNET_PeerIdentity *sender, | 923 | const struct GNUNET_PeerIdentity *sender, |
921 | const struct GNUNET_MessageHeader *msg, | 924 | const struct GNUNET_MessageHeader *msg, |
925 | struct GNUNET_TIME_Relative expected_addr_validity, | ||
922 | GNUNET_TRANSPORT_MessageCompletedCallback cb, | 926 | GNUNET_TRANSPORT_MessageCompletedCallback cb, |
923 | void *cb_cls) | 927 | void *cb_cls) |
924 | { | 928 | { |
@@ -932,24 +936,25 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl | |||
932 | (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length) ) | 936 | (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length) ) |
933 | { | 937 | { |
934 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 938 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
935 | "Dropping message: transprot is too slow, queue length %llu exceeded\n", | 939 | "Dropping message: transprot is too slow, queue length %llu exceeded\n", |
936 | ch->max_queue_length); | 940 | ch->max_queue_length); |
937 | return GNUNET_NO; | 941 | return GNUNET_NO; |
938 | } | 942 | } |
939 | 943 | ||
940 | msize = ntohs (msg->size); | 944 | msize = ntohs (msg->size); |
941 | env = GNUNET_MQ_msg_extra (im, | 945 | env = GNUNET_MQ_msg_extra (im, |
942 | msize, | 946 | msize, |
943 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); | 947 | GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); |
944 | if (NULL == env) | 948 | if (NULL == env) |
945 | { | 949 | { |
946 | GNUNET_break (0); | 950 | GNUNET_break (0); |
947 | return GNUNET_SYSERR; | 951 | return GNUNET_SYSERR; |
948 | } | 952 | } |
953 | im->expected_address_validity = GNUNET_TIME_relative_hton (expected_addr_validity); | ||
949 | im->sender = *sender; | 954 | im->sender = *sender; |
950 | memcpy (&im[1], | 955 | memcpy (&im[1], |
951 | msg, | 956 | msg, |
952 | msize); | 957 | msize); |
953 | if (NULL != cb) | 958 | if (NULL != cb) |
954 | { | 959 | { |
955 | struct FlowControl *fc; | 960 | struct FlowControl *fc; |
@@ -962,11 +967,11 @@ GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandl | |||
962 | fc->cb = cb; | 967 | fc->cb = cb; |
963 | fc->cb_cls = cb_cls; | 968 | fc->cb_cls = cb_cls; |
964 | GNUNET_CONTAINER_DLL_insert (ch->fc_head, | 969 | GNUNET_CONTAINER_DLL_insert (ch->fc_head, |
965 | ch->fc_tail, | 970 | ch->fc_tail, |
966 | fc); | 971 | fc); |
967 | } | 972 | } |
968 | GNUNET_MQ_send (ch->mq, | 973 | GNUNET_MQ_send (ch->mq, |
969 | env); | 974 | env); |
970 | return GNUNET_OK; | 975 | return GNUNET_OK; |
971 | } | 976 | } |
972 | 977 | ||