diff options
Diffstat (limited to 'src/core/gnunet-service-core.c')
-rw-r--r-- | src/core/gnunet-service-core.c | 3685 |
1 files changed, 1768 insertions, 1917 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2e68571a4..95e182448 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -164,7 +164,7 @@ enum PeerStateMachine | |||
164 | * We've sent our session key. | 164 | * We've sent our session key. |
165 | */ | 165 | */ |
166 | PEER_STATE_KEY_SENT, | 166 | PEER_STATE_KEY_SENT, |
167 | 167 | ||
168 | /** | 168 | /** |
169 | * We've received the other peers session key. | 169 | * We've received the other peers session key. |
170 | */ | 170 | */ |
@@ -241,7 +241,7 @@ struct PingMessage | |||
241 | * Message type is CORE_PING. | 241 | * Message type is CORE_PING. |
242 | */ | 242 | */ |
243 | struct GNUNET_MessageHeader header; | 243 | struct GNUNET_MessageHeader header; |
244 | 244 | ||
245 | /** | 245 | /** |
246 | * Seed for the IV | 246 | * Seed for the IV |
247 | */ | 247 | */ |
@@ -271,7 +271,7 @@ struct PongMessage | |||
271 | * Message type is CORE_PONG. | 271 | * Message type is CORE_PONG. |
272 | */ | 272 | */ |
273 | struct GNUNET_MessageHeader header; | 273 | struct GNUNET_MessageHeader header; |
274 | 274 | ||
275 | /** | 275 | /** |
276 | * Seed for the IV | 276 | * Seed for the IV |
277 | */ | 277 | */ |
@@ -489,7 +489,7 @@ struct Neighbour | |||
489 | 489 | ||
490 | /** | 490 | /** |
491 | * Performance data for the peer. | 491 | * Performance data for the peer. |
492 | */ | 492 | */ |
493 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 493 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
494 | 494 | ||
495 | /** | 495 | /** |
@@ -578,7 +578,7 @@ struct Neighbour | |||
578 | 578 | ||
579 | /** | 579 | /** |
580 | * Number of entries in 'ats'. | 580 | * Number of entries in 'ats'. |
581 | */ | 581 | */ |
582 | unsigned int ats_count; | 582 | unsigned int ats_count; |
583 | 583 | ||
584 | /** | 584 | /** |
@@ -601,12 +601,12 @@ struct Neighbour | |||
601 | /** | 601 | /** |
602 | * Available bandwidth in for this peer (current target). | 602 | * Available bandwidth in for this peer (current target). |
603 | */ | 603 | */ |
604 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; | 604 | struct GNUNET_BANDWIDTH_Value32NBO bw_in; |
605 | 605 | ||
606 | /** | 606 | /** |
607 | * Available bandwidth out for this peer (current target). | 607 | * Available bandwidth out for this peer (current target). |
608 | */ | 608 | */ |
609 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; | 609 | struct GNUNET_BANDWIDTH_Value32NBO bw_out; |
610 | 610 | ||
611 | /** | 611 | /** |
612 | * Internal bandwidth limit set for this peer (initially typically | 612 | * Internal bandwidth limit set for this peer (initially typically |
@@ -634,7 +634,7 @@ struct Neighbour | |||
634 | 634 | ||
635 | /** | 635 | /** |
636 | * Are we currently connected to this neighbour? | 636 | * Are we currently connected to this neighbour? |
637 | */ | 637 | */ |
638 | int is_connected; | 638 | int is_connected; |
639 | 639 | ||
640 | }; | 640 | }; |
@@ -731,7 +731,7 @@ struct ClientActiveRequest | |||
731 | * Unique request ID (in big endian). | 731 | * Unique request ID (in big endian). |
732 | */ | 732 | */ |
733 | uint16_t smr_id; | 733 | uint16_t smr_id; |
734 | 734 | ||
735 | }; | 735 | }; |
736 | 736 | ||
737 | 737 | ||
@@ -754,7 +754,7 @@ static struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key; | |||
754 | /** | 754 | /** |
755 | * Bitmap of message types this peer is able to handle. | 755 | * Bitmap of message types this peer is able to handle. |
756 | */ | 756 | */ |
757 | static uint32_t my_type_map[(UINT16_MAX + 1)/32]; | 757 | static uint32_t my_type_map[(UINT16_MAX + 1) / 32]; |
758 | 758 | ||
759 | /** | 759 | /** |
760 | * Handle to peerinfo service. | 760 | * Handle to peerinfo service. |
@@ -821,9 +821,8 @@ static unsigned long long bandwidth_target_out_bps; | |||
821 | */ | 821 | */ |
822 | static void | 822 | static void |
823 | derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | 823 | derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, |
824 | const struct GNUNET_CRYPTO_AesSessionKey *skey, | 824 | const struct GNUNET_CRYPTO_AesSessionKey *skey, |
825 | uint32_t seed, | 825 | uint32_t seed, struct GNUNET_TIME_Absolute creation_time) |
826 | struct GNUNET_TIME_Absolute creation_time) | ||
827 | { | 826 | { |
828 | static const char ctx[] = "authentication key"; | 827 | static const char ctx[] = "authentication key"; |
829 | struct GNUNET_TIME_AbsoluteNBO ctbe; | 828 | struct GNUNET_TIME_AbsoluteNBO ctbe; |
@@ -833,13 +832,10 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
833 | GNUNET_CRYPTO_hmac_derive_key (akey, | 832 | GNUNET_CRYPTO_hmac_derive_key (akey, |
834 | skey, | 833 | skey, |
835 | &seed, | 834 | &seed, |
836 | sizeof(seed), | 835 | sizeof (seed), |
837 | &skey->key, | 836 | &skey->key, |
838 | sizeof(skey->key), | 837 | sizeof (skey->key), |
839 | &ctbe, | 838 | &ctbe, sizeof (ctbe), ctx, sizeof (ctx), NULL); |
840 | sizeof(ctbe), | ||
841 | ctx, | ||
842 | sizeof(ctx), NULL); | ||
843 | } | 839 | } |
844 | 840 | ||
845 | 841 | ||
@@ -848,19 +844,18 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, | |||
848 | */ | 844 | */ |
849 | static void | 845 | static void |
850 | derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 846 | derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
851 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | 847 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, |
852 | const struct GNUNET_PeerIdentity *identity) | 848 | const struct GNUNET_PeerIdentity *identity) |
853 | { | 849 | { |
854 | static const char ctx[] = "initialization vector"; | 850 | static const char ctx[] = "initialization vector"; |
855 | 851 | ||
856 | GNUNET_CRYPTO_aes_derive_iv (iv, | 852 | GNUNET_CRYPTO_aes_derive_iv (iv, |
857 | skey, | 853 | skey, |
858 | &seed, | 854 | &seed, |
859 | sizeof(seed), | 855 | sizeof (seed), |
860 | &identity->hashPubKey.bits, | 856 | &identity->hashPubKey.bits, |
861 | sizeof(identity->hashPubKey.bits), | 857 | sizeof (identity->hashPubKey.bits), |
862 | ctx, | 858 | ctx, sizeof (ctx), NULL); |
863 | sizeof(ctx), NULL); | ||
864 | } | 859 | } |
865 | 860 | ||
866 | /** | 861 | /** |
@@ -868,21 +863,19 @@ derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | |||
868 | */ | 863 | */ |
869 | static void | 864 | static void |
870 | derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | 865 | derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, |
871 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, | 866 | const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed, |
872 | uint32_t challenge, const struct GNUNET_PeerIdentity *identity) | 867 | uint32_t challenge, const struct GNUNET_PeerIdentity *identity) |
873 | { | 868 | { |
874 | static const char ctx[] = "pong initialization vector"; | 869 | static const char ctx[] = "pong initialization vector"; |
875 | 870 | ||
876 | GNUNET_CRYPTO_aes_derive_iv (iv, | 871 | GNUNET_CRYPTO_aes_derive_iv (iv, |
877 | skey, | 872 | skey, |
878 | &seed, | 873 | &seed, |
879 | sizeof(seed), | 874 | sizeof (seed), |
880 | &identity->hashPubKey.bits, | 875 | &identity->hashPubKey.bits, |
881 | sizeof(identity->hashPubKey.bits), | 876 | sizeof (identity->hashPubKey.bits), |
882 | &challenge, | 877 | &challenge, |
883 | sizeof(challenge), | 878 | sizeof (challenge), ctx, sizeof (ctx), NULL); |
884 | ctx, | ||
885 | sizeof(ctx), NULL); | ||
886 | } | 879 | } |
887 | 880 | ||
888 | 881 | ||
@@ -893,11 +886,11 @@ derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv, | |||
893 | * @param n neighbour in question | 886 | * @param n neighbour in question |
894 | * @return absolute timeout | 887 | * @return absolute timeout |
895 | */ | 888 | */ |
896 | static struct GNUNET_TIME_Absolute | 889 | static struct GNUNET_TIME_Absolute |
897 | get_neighbour_timeout (struct Neighbour *n) | 890 | get_neighbour_timeout (struct Neighbour *n) |
898 | { | 891 | { |
899 | return GNUNET_TIME_absolute_add (n->last_activity, | 892 | return GNUNET_TIME_absolute_add (n->last_activity, |
900 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 893 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
901 | } | 894 | } |
902 | 895 | ||
903 | 896 | ||
@@ -905,9 +898,7 @@ get_neighbour_timeout (struct Neighbour *n) | |||
905 | * Helper function for update_preference_sum. | 898 | * Helper function for update_preference_sum. |
906 | */ | 899 | */ |
907 | static int | 900 | static int |
908 | update_preference (void *cls, | 901 | update_preference (void *cls, const GNUNET_HashCode * key, void *value) |
909 | const GNUNET_HashCode *key, | ||
910 | void *value) | ||
911 | { | 902 | { |
912 | unsigned long long *ps = cls; | 903 | unsigned long long *ps = cls; |
913 | struct Neighbour *n = value; | 904 | struct Neighbour *n = value; |
@@ -915,7 +906,7 @@ update_preference (void *cls, | |||
915 | n->current_preference /= 2; | 906 | n->current_preference /= 2; |
916 | *ps += n->current_preference; | 907 | *ps += n->current_preference; |
917 | return GNUNET_OK; | 908 | return GNUNET_OK; |
918 | } | 909 | } |
919 | 910 | ||
920 | 911 | ||
921 | /** | 912 | /** |
@@ -932,13 +923,13 @@ update_preference_sum (unsigned long long inc) | |||
932 | os = preference_sum; | 923 | os = preference_sum; |
933 | preference_sum += inc; | 924 | preference_sum += inc; |
934 | if (preference_sum >= os) | 925 | if (preference_sum >= os) |
935 | return; /* done! */ | 926 | return; /* done! */ |
936 | /* overflow! compensate by cutting all values in half! */ | 927 | /* overflow! compensate by cutting all values in half! */ |
937 | preference_sum = 0; | 928 | preference_sum = 0; |
938 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 929 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
939 | &update_preference, | 930 | &update_preference, &preference_sum); |
940 | &preference_sum); | 931 | GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), |
941 | GNUNET_STATISTICS_set (stats, gettext_noop ("# total peer preference"), preference_sum, GNUNET_NO); | 932 | preference_sum, GNUNET_NO); |
942 | } | 933 | } |
943 | 934 | ||
944 | 935 | ||
@@ -966,19 +957,17 @@ find_neighbour (const struct GNUNET_PeerIdentity *peer) | |||
966 | */ | 957 | */ |
967 | static void | 958 | static void |
968 | send_to_client (struct Client *client, | 959 | send_to_client (struct Client *client, |
969 | const struct GNUNET_MessageHeader *msg, | 960 | const struct GNUNET_MessageHeader *msg, int can_drop) |
970 | int can_drop) | ||
971 | { | 961 | { |
972 | #if DEBUG_CORE_CLIENT | 962 | #if DEBUG_CORE_CLIENT |
973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 963 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
974 | "Preparing to send %u bytes of message of type %u to client.\n", | 964 | "Preparing to send %u bytes of message of type %u to client.\n", |
975 | (unsigned int) ntohs (msg->size), | 965 | (unsigned int) ntohs (msg->size), |
976 | (unsigned int) ntohs (msg->type)); | 966 | (unsigned int) ntohs (msg->type)); |
977 | #endif | 967 | #endif |
978 | GNUNET_SERVER_notification_context_unicast (notifier, | 968 | GNUNET_SERVER_notification_context_unicast (notifier, |
979 | client->client_handle, | 969 | client->client_handle, |
980 | msg, | 970 | msg, can_drop); |
981 | can_drop); | ||
982 | } | 971 | } |
983 | 972 | ||
984 | 973 | ||
@@ -991,26 +980,25 @@ send_to_client (struct Client *client, | |||
991 | * @param options mask to use | 980 | * @param options mask to use |
992 | */ | 981 | */ |
993 | static void | 982 | static void |
994 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, | 983 | send_to_all_clients (const struct GNUNET_MessageHeader *msg, |
995 | int can_drop, | 984 | int can_drop, int options) |
996 | int options) | ||
997 | { | 985 | { |
998 | struct Client *c; | 986 | struct Client *c; |
999 | 987 | ||
1000 | c = clients; | 988 | c = clients; |
1001 | while (c != NULL) | 989 | while (c != NULL) |
990 | { | ||
991 | if (0 != (c->options & options)) | ||
1002 | { | 992 | { |
1003 | if (0 != (c->options & options)) | ||
1004 | { | ||
1005 | #if DEBUG_CORE_CLIENT > 1 | 993 | #if DEBUG_CORE_CLIENT > 1 |
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 994 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1007 | "Sending message of type %u to client.\n", | 995 | "Sending message of type %u to client.\n", |
1008 | (unsigned int) ntohs (msg->type)); | 996 | (unsigned int) ntohs (msg->type)); |
1009 | #endif | 997 | #endif |
1010 | send_to_client (c, msg, can_drop); | 998 | send_to_client (c, msg, can_drop); |
1011 | } | ||
1012 | c = c->next; | ||
1013 | } | 999 | } |
1000 | c = c->next; | ||
1001 | } | ||
1014 | } | 1002 | } |
1015 | 1003 | ||
1016 | 1004 | ||
@@ -1028,27 +1016,23 @@ handle_peer_status_change (struct Neighbour *n) | |||
1028 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 1016 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
1029 | size_t size; | 1017 | size_t size; |
1030 | 1018 | ||
1031 | if ( (! n->is_connected) || | 1019 | if ((!n->is_connected) || (n->status != PEER_STATE_KEY_CONFIRMED)) |
1032 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | ||
1033 | return; | 1020 | return; |
1034 | #if DEBUG_CORE > 1 | 1021 | #if DEBUG_CORE > 1 |
1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1036 | "Peer `%4s' changed status\n", | 1023 | "Peer `%4s' changed status\n", GNUNET_i2s (&n->peer)); |
1037 | GNUNET_i2s (&n->peer)); | ||
1038 | #endif | 1024 | #endif |
1039 | size = sizeof (struct PeerStatusNotifyMessage) + | 1025 | size = sizeof (struct PeerStatusNotifyMessage) + |
1040 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1026 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1041 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1027 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1042 | { | 1028 | { |
1043 | GNUNET_break (0); | 1029 | GNUNET_break (0); |
1044 | /* recovery strategy: throw away performance data */ | 1030 | /* recovery strategy: throw away performance data */ |
1045 | GNUNET_array_grow (n->ats, | 1031 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1046 | n->ats_count, | 1032 | size = sizeof (struct PeerStatusNotifyMessage) + |
1047 | 0); | 1033 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1048 | size = sizeof (struct PeerStatusNotifyMessage) + | 1034 | } |
1049 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1035 | psnm = (struct PeerStatusNotifyMessage *) buf; |
1050 | } | ||
1051 | psnm = (struct PeerStatusNotifyMessage*) buf; | ||
1052 | psnm->header.size = htons (size); | 1036 | psnm->header.size = htons (size); |
1053 | psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE); | 1037 | psnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_STATUS_CHANGE); |
1054 | psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n)); | 1038 | psnm->timeout = GNUNET_TIME_absolute_hton (get_neighbour_timeout (n)); |
@@ -1058,17 +1042,15 @@ handle_peer_status_change (struct Neighbour *n) | |||
1058 | psnm->ats_count = htonl (n->ats_count); | 1042 | psnm->ats_count = htonl (n->ats_count); |
1059 | ats = &psnm->ats; | 1043 | ats = &psnm->ats; |
1060 | memcpy (ats, | 1044 | memcpy (ats, |
1061 | n->ats, | 1045 | n->ats, |
1062 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 1046 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
1063 | ats[n->ats_count].type = htonl (0); | 1047 | ats[n->ats_count].type = htonl (0); |
1064 | ats[n->ats_count].value = htonl (0); | 1048 | ats[n->ats_count].value = htonl (0); |
1065 | send_to_all_clients (&psnm->header, | 1049 | send_to_all_clients (&psnm->header, |
1066 | GNUNET_YES, | 1050 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); |
1067 | GNUNET_CORE_OPTION_SEND_STATUS_CHANGE); | 1051 | GNUNET_STATISTICS_update (stats, |
1068 | GNUNET_STATISTICS_update (stats, | 1052 | gettext_noop ("# peer status changes"), |
1069 | gettext_noop ("# peer status changes"), | 1053 | 1, GNUNET_NO); |
1070 | 1, | ||
1071 | GNUNET_NO); | ||
1072 | } | 1054 | } |
1073 | 1055 | ||
1074 | 1056 | ||
@@ -1088,55 +1070,53 @@ schedule_peer_messages (struct Neighbour *n) | |||
1088 | struct Client *c; | 1070 | struct Client *c; |
1089 | struct MessageEntry *mqe; | 1071 | struct MessageEntry *mqe; |
1090 | unsigned int queue_size; | 1072 | unsigned int queue_size; |
1091 | 1073 | ||
1092 | /* check if neighbour queue is empty enough! */ | 1074 | /* check if neighbour queue is empty enough! */ |
1093 | if (n != &self) | 1075 | if (n != &self) |
1076 | { | ||
1077 | queue_size = 0; | ||
1078 | mqe = n->messages; | ||
1079 | while (mqe != NULL) | ||
1080 | { | ||
1081 | queue_size++; | ||
1082 | mqe = mqe->next; | ||
1083 | } | ||
1084 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | ||
1094 | { | 1085 | { |
1095 | queue_size = 0; | ||
1096 | mqe = n->messages; | ||
1097 | while (mqe != NULL) | ||
1098 | { | ||
1099 | queue_size++; | ||
1100 | mqe = mqe->next; | ||
1101 | } | ||
1102 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | ||
1103 | { | ||
1104 | #if DEBUG_CORE_CLIENT | 1086 | #if DEBUG_CORE_CLIENT |
1105 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1087 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1106 | "Not considering client transmission requests: queue full\n"); | 1088 | "Not considering client transmission requests: queue full\n"); |
1107 | #endif | 1089 | #endif |
1108 | return; /* queue still full */ | 1090 | return; /* queue still full */ |
1109 | } | ||
1110 | /* find highest priority request */ | ||
1111 | pos = n->active_client_request_head; | ||
1112 | car = NULL; | ||
1113 | while (pos != NULL) | ||
1114 | { | ||
1115 | if ( (car == NULL) || | ||
1116 | (pos->priority > car->priority) ) | ||
1117 | car = pos; | ||
1118 | pos = pos->next; | ||
1119 | } | ||
1120 | } | 1091 | } |
1121 | else | 1092 | /* find highest priority request */ |
1093 | pos = n->active_client_request_head; | ||
1094 | car = NULL; | ||
1095 | while (pos != NULL) | ||
1122 | { | 1096 | { |
1123 | car = n->active_client_request_head; | 1097 | if ((car == NULL) || (pos->priority > car->priority)) |
1098 | car = pos; | ||
1099 | pos = pos->next; | ||
1124 | } | 1100 | } |
1101 | } | ||
1102 | else | ||
1103 | { | ||
1104 | car = n->active_client_request_head; | ||
1105 | } | ||
1125 | if (car == NULL) | 1106 | if (car == NULL) |
1126 | return; /* no pending requests */ | 1107 | return; /* no pending requests */ |
1127 | #if DEBUG_CORE_CLIENT | 1108 | #if DEBUG_CORE_CLIENT |
1128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1129 | "Permitting client transmission request to `%s'\n", | 1110 | "Permitting client transmission request to `%s'\n", |
1130 | GNUNET_i2s (&n->peer)); | 1111 | GNUNET_i2s (&n->peer)); |
1131 | #endif | 1112 | #endif |
1132 | c = car->client; | 1113 | c = car->client; |
1133 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1114 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1134 | n->active_client_request_tail, | 1115 | n->active_client_request_tail, car); |
1135 | car); | ||
1136 | GNUNET_assert (GNUNET_YES == | 1116 | GNUNET_assert (GNUNET_YES == |
1137 | GNUNET_CONTAINER_multihashmap_remove (c->requests, | 1117 | GNUNET_CONTAINER_multihashmap_remove (c->requests, |
1138 | &n->peer.hashPubKey, | 1118 | &n->peer.hashPubKey, |
1139 | car)); | 1119 | car)); |
1140 | smr.header.size = htons (sizeof (struct SendMessageReady)); | 1120 | smr.header.size = htons (sizeof (struct SendMessageReady)); |
1141 | smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY); | 1121 | smr.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SEND_READY); |
1142 | smr.size = htons (car->msize); | 1122 | smr.size = htons (car->msize); |
@@ -1160,27 +1140,28 @@ compute_type_map_message () | |||
1160 | struct GNUNET_MessageHeader *hdr; | 1140 | struct GNUNET_MessageHeader *hdr; |
1161 | 1141 | ||
1162 | #ifdef compressBound | 1142 | #ifdef compressBound |
1163 | dlen = compressBound (sizeof(my_type_map)); | 1143 | dlen = compressBound (sizeof (my_type_map)); |
1164 | #else | 1144 | #else |
1165 | dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20; | 1145 | dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20; |
1166 | /* documentation says 100.1% oldSize + 12 bytes, but we | 1146 | /* documentation says 100.1% oldSize + 12 bytes, but we |
1167 | should be able to overshoot by more to be safe */ | 1147 | * should be able to overshoot by more to be safe */ |
1168 | #endif | 1148 | #endif |
1169 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); | 1149 | hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); |
1170 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); | 1150 | hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); |
1171 | tmp = (char*) &hdr[1]; | 1151 | tmp = (char *) &hdr[1]; |
1172 | if ( (Z_OK != compress2 ((Bytef *) tmp, | 1152 | if ((Z_OK != compress2 ((Bytef *) tmp, |
1173 | &dlen, (const Bytef *) my_type_map, sizeof (my_type_map), 9)) || | 1153 | &dlen, (const Bytef *) my_type_map, |
1174 | (dlen >= sizeof(my_type_map)) ) | 1154 | sizeof (my_type_map), 9)) || |
1175 | { | 1155 | (dlen >= sizeof (my_type_map))) |
1176 | dlen = sizeof (my_type_map); | 1156 | { |
1177 | memcpy (tmp, my_type_map, sizeof (my_type_map)); | 1157 | dlen = sizeof (my_type_map); |
1178 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); | 1158 | memcpy (tmp, my_type_map, sizeof (my_type_map)); |
1179 | } | 1159 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); |
1160 | } | ||
1180 | else | 1161 | else |
1181 | { | 1162 | { |
1182 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); | 1163 | hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); |
1183 | } | 1164 | } |
1184 | return hdr; | 1165 | return hdr; |
1185 | } | 1166 | } |
1186 | 1167 | ||
@@ -1194,9 +1175,7 @@ compute_type_map_message () | |||
1194 | * @return always GNUNET_OK | 1175 | * @return always GNUNET_OK |
1195 | */ | 1176 | */ |
1196 | static int | 1177 | static int |
1197 | send_type_map_to_neighbour (void *cls, | 1178 | send_type_map_to_neighbour (void *cls, const GNUNET_HashCode * key, void *value) |
1198 | const GNUNET_HashCode *key, | ||
1199 | void *value) | ||
1200 | { | 1179 | { |
1201 | struct GNUNET_MessageHeader *hdr = cls; | 1180 | struct GNUNET_MessageHeader *hdr = cls; |
1202 | struct Neighbour *n = value; | 1181 | struct Neighbour *n = value; |
@@ -1225,15 +1204,14 @@ send_type_map_to_neighbour (void *cls, | |||
1225 | */ | 1204 | */ |
1226 | static void | 1205 | static void |
1227 | broadcast_my_type_map () | 1206 | broadcast_my_type_map () |
1228 | { | 1207 | { |
1229 | struct GNUNET_MessageHeader *hdr; | 1208 | struct GNUNET_MessageHeader *hdr; |
1230 | 1209 | ||
1231 | if (NULL == neighbours) | 1210 | if (NULL == neighbours) |
1232 | return; | 1211 | return; |
1233 | hdr = compute_type_map_message (); | 1212 | hdr = compute_type_map_message (); |
1234 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 1213 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
1235 | &send_type_map_to_neighbour, | 1214 | &send_type_map_to_neighbour, hdr); |
1236 | hdr); | ||
1237 | GNUNET_free (hdr); | 1215 | GNUNET_free (hdr); |
1238 | } | 1216 | } |
1239 | 1217 | ||
@@ -1243,72 +1221,68 @@ broadcast_my_type_map () | |||
1243 | */ | 1221 | */ |
1244 | static void | 1222 | static void |
1245 | handle_client_send_request (void *cls, | 1223 | handle_client_send_request (void *cls, |
1246 | struct GNUNET_SERVER_Client *client, | 1224 | struct GNUNET_SERVER_Client *client, |
1247 | const struct GNUNET_MessageHeader *message) | 1225 | const struct GNUNET_MessageHeader *message) |
1248 | { | 1226 | { |
1249 | const struct SendMessageRequest *req; | 1227 | const struct SendMessageRequest *req; |
1250 | struct Neighbour *n; | 1228 | struct Neighbour *n; |
1251 | struct Client *c; | 1229 | struct Client *c; |
1252 | struct ClientActiveRequest *car; | 1230 | struct ClientActiveRequest *car; |
1253 | 1231 | ||
1254 | req = (const struct SendMessageRequest*) message; | 1232 | req = (const struct SendMessageRequest *) message; |
1255 | if (0 == memcmp (&req->peer, | 1233 | if (0 == memcmp (&req->peer, |
1256 | &my_identity, | 1234 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
1257 | sizeof (struct GNUNET_PeerIdentity))) | ||
1258 | n = &self; | 1235 | n = &self; |
1259 | else | 1236 | else |
1260 | n = find_neighbour (&req->peer); | 1237 | n = find_neighbour (&req->peer); |
1261 | if ( (n == NULL) || | 1238 | if ((n == NULL) || |
1262 | (GNUNET_YES != n->is_connected) || | 1239 | (GNUNET_YES != n->is_connected) || |
1263 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 1240 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
1264 | { | 1241 | { |
1265 | /* neighbour must have disconnected since request was issued, | 1242 | /* neighbour must have disconnected since request was issued, |
1266 | ignore (client will realize it once it processes the | 1243 | * ignore (client will realize it once it processes the |
1267 | disconnect notification) */ | 1244 | * disconnect notification) */ |
1268 | #if DEBUG_CORE_CLIENT | 1245 | #if DEBUG_CORE_CLIENT |
1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1270 | "Dropped client request for transmission (am disconnected)\n"); | 1247 | "Dropped client request for transmission (am disconnected)\n"); |
1271 | #endif | 1248 | #endif |
1272 | GNUNET_STATISTICS_update (stats, | 1249 | GNUNET_STATISTICS_update (stats, |
1273 | gettext_noop ("# send requests dropped (disconnected)"), | 1250 | gettext_noop |
1274 | 1, | 1251 | ("# send requests dropped (disconnected)"), 1, |
1275 | GNUNET_NO); | 1252 | GNUNET_NO); |
1276 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1253 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1277 | return; | 1254 | return; |
1278 | } | 1255 | } |
1279 | c = clients; | 1256 | c = clients; |
1280 | while ( (c != NULL) && | 1257 | while ((c != NULL) && (c->client_handle != client)) |
1281 | (c->client_handle != client) ) | ||
1282 | c = c->next; | 1258 | c = c->next; |
1283 | if (c == NULL) | 1259 | if (c == NULL) |
1284 | { | 1260 | { |
1285 | /* client did not send INIT first! */ | 1261 | /* client did not send INIT first! */ |
1286 | GNUNET_break (0); | 1262 | GNUNET_break (0); |
1287 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1263 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1288 | return; | 1264 | return; |
1289 | } | 1265 | } |
1290 | if (c->requests == NULL) | 1266 | if (c->requests == NULL) |
1291 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); | 1267 | c->requests = GNUNET_CONTAINER_multihashmap_create (16); |
1292 | #if DEBUG_CORE_CLIENT | 1268 | #if DEBUG_CORE_CLIENT |
1293 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1269 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1294 | "Received client transmission request. queueing\n"); | 1270 | "Received client transmission request. queueing\n"); |
1295 | #endif | 1271 | #endif |
1296 | car = GNUNET_CONTAINER_multihashmap_get (c->requests, | 1272 | car = GNUNET_CONTAINER_multihashmap_get (c->requests, &req->peer.hashPubKey); |
1297 | &req->peer.hashPubKey); | ||
1298 | if (car == NULL) | 1273 | if (car == NULL) |
1299 | { | 1274 | { |
1300 | /* create new entry */ | 1275 | /* create new entry */ |
1301 | car = GNUNET_malloc (sizeof (struct ClientActiveRequest)); | 1276 | car = GNUNET_malloc (sizeof (struct ClientActiveRequest)); |
1302 | GNUNET_assert (GNUNET_OK == | 1277 | GNUNET_assert (GNUNET_OK == |
1303 | GNUNET_CONTAINER_multihashmap_put (c->requests, | 1278 | GNUNET_CONTAINER_multihashmap_put (c->requests, |
1304 | &req->peer.hashPubKey, | 1279 | &req->peer.hashPubKey, |
1305 | car, | 1280 | car, |
1306 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); | 1281 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); |
1307 | GNUNET_CONTAINER_DLL_insert (n->active_client_request_head, | 1282 | GNUNET_CONTAINER_DLL_insert (n->active_client_request_head, |
1308 | n->active_client_request_tail, | 1283 | n->active_client_request_tail, car); |
1309 | car); | 1284 | car->client = c; |
1310 | car->client = c; | 1285 | } |
1311 | } | ||
1312 | car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); | 1286 | car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); |
1313 | car->priority = ntohl (req->priority); | 1287 | car->priority = ntohl (req->priority); |
1314 | car->queue_size = ntohl (req->queue_size); | 1288 | car->queue_size = ntohl (req->queue_size); |
@@ -1324,8 +1298,7 @@ handle_client_send_request (void *cls, | |||
1324 | */ | 1298 | */ |
1325 | static int | 1299 | static int |
1326 | notify_client_about_neighbour (void *cls, | 1300 | notify_client_about_neighbour (void *cls, |
1327 | const GNUNET_HashCode *key, | 1301 | const GNUNET_HashCode * key, void *value) |
1328 | void *value) | ||
1329 | { | 1302 | { |
1330 | struct Client *c = cls; | 1303 | struct Client *c = cls; |
1331 | struct Neighbour *n = value; | 1304 | struct Neighbour *n = value; |
@@ -1335,36 +1308,34 @@ notify_client_about_neighbour (void *cls, | |||
1335 | struct ConnectNotifyMessage *cnm; | 1308 | struct ConnectNotifyMessage *cnm; |
1336 | 1309 | ||
1337 | size = sizeof (struct ConnectNotifyMessage) + | 1310 | size = sizeof (struct ConnectNotifyMessage) + |
1338 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1311 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1339 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1312 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1340 | { | 1313 | { |
1341 | GNUNET_break (0); | 1314 | GNUNET_break (0); |
1342 | /* recovery strategy: throw away performance data */ | 1315 | /* recovery strategy: throw away performance data */ |
1343 | GNUNET_array_grow (n->ats, | 1316 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1344 | n->ats_count, | 1317 | size = sizeof (struct ConnectNotifyMessage) + |
1345 | 0); | 1318 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1346 | size = sizeof (struct ConnectNotifyMessage) + | 1319 | } |
1347 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1320 | cnm = (struct ConnectNotifyMessage *) buf; |
1348 | } | ||
1349 | cnm = (struct ConnectNotifyMessage*) buf; | ||
1350 | cnm->header.size = htons (size); | 1321 | cnm->header.size = htons (size); |
1351 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | 1322 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); |
1352 | cnm->ats_count = htonl (n->ats_count); | 1323 | cnm->ats_count = htonl (n->ats_count); |
1353 | ats = &cnm->ats; | 1324 | ats = &cnm->ats; |
1354 | memcpy (ats, | 1325 | memcpy (ats, |
1355 | n->ats, | 1326 | n->ats, |
1356 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); | 1327 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * n->ats_count); |
1357 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1328 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
1358 | ats[n->ats_count].value = htonl (0); | 1329 | ats[n->ats_count].value = htonl (0); |
1359 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 1330 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
1360 | { | 1331 | { |
1361 | #if DEBUG_CORE_CLIENT | 1332 | #if DEBUG_CORE_CLIENT |
1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1363 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); | 1334 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); |
1364 | #endif | 1335 | #endif |
1365 | cnm->peer = n->peer; | 1336 | cnm->peer = n->peer; |
1366 | send_to_client (c, &cnm->header, GNUNET_NO); | 1337 | send_to_client (c, &cnm->header, GNUNET_NO); |
1367 | } | 1338 | } |
1368 | return GNUNET_OK; | 1339 | return GNUNET_OK; |
1369 | } | 1340 | } |
1370 | 1341 | ||
@@ -1388,28 +1359,27 @@ handle_client_init (void *cls, | |||
1388 | 1359 | ||
1389 | #if DEBUG_CORE_CLIENT | 1360 | #if DEBUG_CORE_CLIENT |
1390 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1361 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1391 | "Client connecting to core service with `%s' message\n", | 1362 | "Client connecting to core service with `%s' message\n", "INIT"); |
1392 | "INIT"); | ||
1393 | #endif | 1363 | #endif |
1394 | /* check that we don't have an entry already */ | 1364 | /* check that we don't have an entry already */ |
1395 | c = clients; | 1365 | c = clients; |
1396 | while (c != NULL) | 1366 | while (c != NULL) |
1397 | { | 1367 | { |
1398 | if (client == c->client_handle) | 1368 | if (client == c->client_handle) |
1399 | { | ||
1400 | GNUNET_break (0); | ||
1401 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1402 | return; | ||
1403 | } | ||
1404 | c = c->next; | ||
1405 | } | ||
1406 | msize = ntohs (message->size); | ||
1407 | if (msize < sizeof (struct InitMessage)) | ||
1408 | { | 1369 | { |
1409 | GNUNET_break (0); | 1370 | GNUNET_break (0); |
1410 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1371 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1411 | return; | 1372 | return; |
1412 | } | 1373 | } |
1374 | c = c->next; | ||
1375 | } | ||
1376 | msize = ntohs (message->size); | ||
1377 | if (msize < sizeof (struct InitMessage)) | ||
1378 | { | ||
1379 | GNUNET_break (0); | ||
1380 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1381 | return; | ||
1382 | } | ||
1413 | GNUNET_SERVER_notification_context_add (notifier, client); | 1383 | GNUNET_SERVER_notification_context_add (notifier, client); |
1414 | im = (const struct InitMessage *) message; | 1384 | im = (const struct InitMessage *) message; |
1415 | types = (const uint16_t *) &im[1]; | 1385 | types = (const uint16_t *) &im[1]; |
@@ -1420,20 +1390,19 @@ handle_client_init (void *cls, | |||
1420 | clients = c; | 1390 | clients = c; |
1421 | c->tcnt = msize / sizeof (uint16_t); | 1391 | c->tcnt = msize / sizeof (uint16_t); |
1422 | c->types = (const uint16_t *) &c[1]; | 1392 | c->types = (const uint16_t *) &c[1]; |
1423 | wtypes = (uint16_t *) &c[1]; | 1393 | wtypes = (uint16_t *) & c[1]; |
1424 | for (i=0;i<c->tcnt;i++) | 1394 | for (i = 0; i < c->tcnt; i++) |
1425 | { | 1395 | { |
1426 | wtypes[i] = ntohs (types[i]); | 1396 | wtypes[i] = ntohs (types[i]); |
1427 | my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32)); | 1397 | my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); |
1428 | } | 1398 | } |
1429 | if (c->tcnt > 0) | 1399 | if (c->tcnt > 0) |
1430 | broadcast_my_type_map (); | 1400 | broadcast_my_type_map (); |
1431 | c->options = ntohl (im->options); | 1401 | c->options = ntohl (im->options); |
1432 | #if DEBUG_CORE_CLIENT | 1402 | #if DEBUG_CORE_CLIENT |
1433 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1403 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1434 | "Client %p is interested in %u message types\n", | 1404 | "Client %p is interested in %u message types\n", |
1435 | c, | 1405 | c, (unsigned int) c->tcnt); |
1436 | (unsigned int) c->tcnt); | ||
1437 | #endif | 1406 | #endif |
1438 | /* send init reply message */ | 1407 | /* send init reply message */ |
1439 | irm.header.size = htons (sizeof (struct InitReplyMessage)); | 1408 | irm.header.size = htons (sizeof (struct InitReplyMessage)); |
@@ -1448,12 +1417,11 @@ handle_client_init (void *cls, | |||
1448 | #endif | 1417 | #endif |
1449 | send_to_client (c, &irm.header, GNUNET_NO); | 1418 | send_to_client (c, &irm.header, GNUNET_NO); |
1450 | if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) | 1419 | if (0 != (c->options & GNUNET_CORE_OPTION_SEND_CONNECT)) |
1451 | { | 1420 | { |
1452 | /* notify new client about existing neighbours */ | 1421 | /* notify new client about existing neighbours */ |
1453 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 1422 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
1454 | ¬ify_client_about_neighbour, | 1423 | ¬ify_client_about_neighbour, c); |
1455 | c); | 1424 | } |
1456 | } | ||
1457 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1425 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1458 | } | 1426 | } |
1459 | 1427 | ||
@@ -1468,8 +1436,7 @@ handle_client_init (void *cls, | |||
1468 | */ | 1436 | */ |
1469 | static int | 1437 | static int |
1470 | destroy_active_client_request (void *cls, | 1438 | destroy_active_client_request (void *cls, |
1471 | const GNUNET_HashCode *key, | 1439 | const GNUNET_HashCode * key, void *value) |
1472 | void *value) | ||
1473 | { | 1440 | { |
1474 | struct ClientActiveRequest *car = value; | 1441 | struct ClientActiveRequest *car = value; |
1475 | struct Neighbour *n; | 1442 | struct Neighbour *n; |
@@ -1479,8 +1446,7 @@ destroy_active_client_request (void *cls, | |||
1479 | n = find_neighbour (&peer); | 1446 | n = find_neighbour (&peer); |
1480 | GNUNET_assert (NULL != n); | 1447 | GNUNET_assert (NULL != n); |
1481 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1448 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1482 | n->active_client_request_tail, | 1449 | n->active_client_request_tail, car); |
1483 | car); | ||
1484 | GNUNET_free (car); | 1450 | GNUNET_free (car); |
1485 | return GNUNET_YES; | 1451 | return GNUNET_YES; |
1486 | } | 1452 | } |
@@ -1504,44 +1470,43 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1504 | return; | 1470 | return; |
1505 | #if DEBUG_CORE_CLIENT | 1471 | #if DEBUG_CORE_CLIENT |
1506 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1472 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Client %p has disconnected from core service.\n", | 1473 | "Client %p has disconnected from core service.\n", client); |
1508 | client); | ||
1509 | #endif | 1474 | #endif |
1510 | prev = NULL; | 1475 | prev = NULL; |
1511 | pos = clients; | 1476 | pos = clients; |
1512 | while (pos != NULL) | 1477 | while (pos != NULL) |
1513 | { | 1478 | { |
1514 | if (client == pos->client_handle) | 1479 | if (client == pos->client_handle) |
1515 | break; | 1480 | break; |
1516 | prev = pos; | 1481 | prev = pos; |
1517 | pos = pos->next; | 1482 | pos = pos->next; |
1518 | } | 1483 | } |
1519 | if (pos == NULL) | 1484 | if (pos == NULL) |
1520 | { | 1485 | { |
1521 | /* client never sent INIT */ | 1486 | /* client never sent INIT */ |
1522 | return; | 1487 | return; |
1523 | } | 1488 | } |
1524 | if (prev == NULL) | 1489 | if (prev == NULL) |
1525 | clients = pos->next; | 1490 | clients = pos->next; |
1526 | else | 1491 | else |
1527 | prev->next = pos->next; | 1492 | prev->next = pos->next; |
1528 | if (pos->requests != NULL) | 1493 | if (pos->requests != NULL) |
1529 | { | 1494 | { |
1530 | GNUNET_CONTAINER_multihashmap_iterate (pos->requests, | 1495 | GNUNET_CONTAINER_multihashmap_iterate (pos->requests, |
1531 | &destroy_active_client_request, | 1496 | &destroy_active_client_request, |
1532 | NULL); | 1497 | NULL); |
1533 | GNUNET_CONTAINER_multihashmap_destroy (pos->requests); | 1498 | GNUNET_CONTAINER_multihashmap_destroy (pos->requests); |
1534 | } | 1499 | } |
1535 | GNUNET_free (pos); | 1500 | GNUNET_free (pos); |
1536 | 1501 | ||
1537 | /* rebuild my_type_map */ | 1502 | /* rebuild my_type_map */ |
1538 | memset (my_type_map, 0, sizeof (my_type_map)); | 1503 | memset (my_type_map, 0, sizeof (my_type_map)); |
1539 | for (pos = clients; NULL != pos; pos = pos->next) | 1504 | for (pos = clients; NULL != pos; pos = pos->next) |
1540 | { | 1505 | { |
1541 | wtypes = (const uint16_t *) &pos[1]; | 1506 | wtypes = (const uint16_t *) &pos[1]; |
1542 | for (i=0;i<pos->tcnt;i++) | 1507 | for (i = 0; i < pos->tcnt; i++) |
1543 | my_type_map[wtypes[i]/32] |= (1 << (wtypes[i] % 32)); | 1508 | my_type_map[wtypes[i] / 32] |= (1 << (wtypes[i] % 32)); |
1544 | } | 1509 | } |
1545 | broadcast_my_type_map (); | 1510 | broadcast_my_type_map (); |
1546 | } | 1511 | } |
1547 | 1512 | ||
@@ -1555,9 +1520,7 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
1555 | * @return GNUNET_OK (continue to iterate) | 1520 | * @return GNUNET_OK (continue to iterate) |
1556 | */ | 1521 | */ |
1557 | static int | 1522 | static int |
1558 | queue_connect_message (void *cls, | 1523 | queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value) |
1559 | const GNUNET_HashCode *key, | ||
1560 | void *value) | ||
1561 | { | 1524 | { |
1562 | struct GNUNET_SERVER_TransmitContext *tc = cls; | 1525 | struct GNUNET_SERVER_TransmitContext *tc = cls; |
1563 | struct Neighbour *n = value; | 1526 | struct Neighbour *n = value; |
@@ -1566,39 +1529,35 @@ queue_connect_message (void *cls, | |||
1566 | size_t size; | 1529 | size_t size; |
1567 | struct ConnectNotifyMessage *cnm; | 1530 | struct ConnectNotifyMessage *cnm; |
1568 | 1531 | ||
1569 | cnm = (struct ConnectNotifyMessage*) buf; | 1532 | cnm = (struct ConnectNotifyMessage *) buf; |
1570 | if (n->status != PEER_STATE_KEY_CONFIRMED) | 1533 | if (n->status != PEER_STATE_KEY_CONFIRMED) |
1571 | return GNUNET_OK; | 1534 | return GNUNET_OK; |
1572 | size = sizeof (struct ConnectNotifyMessage) + | 1535 | size = sizeof (struct ConnectNotifyMessage) + |
1573 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1536 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1574 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 1537 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
1575 | { | 1538 | { |
1576 | GNUNET_break (0); | 1539 | GNUNET_break (0); |
1577 | /* recovery strategy: throw away performance data */ | 1540 | /* recovery strategy: throw away performance data */ |
1578 | GNUNET_array_grow (n->ats, | 1541 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1579 | n->ats_count, | 1542 | size = sizeof (struct PeerStatusNotifyMessage) + |
1580 | 0); | 1543 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
1581 | size = sizeof (struct PeerStatusNotifyMessage) + | 1544 | } |
1582 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 1545 | cnm = (struct ConnectNotifyMessage *) buf; |
1583 | } | ||
1584 | cnm = (struct ConnectNotifyMessage*) buf; | ||
1585 | cnm->header.size = htons (size); | 1546 | cnm->header.size = htons (size); |
1586 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | 1547 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); |
1587 | cnm->ats_count = htonl (n->ats_count); | 1548 | cnm->ats_count = htonl (n->ats_count); |
1588 | ats = &cnm->ats; | 1549 | ats = &cnm->ats; |
1589 | memcpy (ats, | 1550 | memcpy (ats, |
1590 | n->ats, | 1551 | n->ats, |
1591 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | 1552 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); |
1592 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1553 | ats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
1593 | ats[n->ats_count].value = htonl (0); | 1554 | ats[n->ats_count].value = htonl (0); |
1594 | #if DEBUG_CORE_CLIENT | 1555 | #if DEBUG_CORE_CLIENT |
1595 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1556 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1596 | "Sending `%s' message to client.\n", | 1557 | "Sending `%s' message to client.\n", "NOTIFY_CONNECT"); |
1597 | "NOTIFY_CONNECT"); | ||
1598 | #endif | 1558 | #endif |
1599 | cnm->peer = n->peer; | 1559 | cnm->peer = n->peer; |
1600 | GNUNET_SERVER_transmit_context_append_message (tc, | 1560 | GNUNET_SERVER_transmit_context_append_message (tc, &cnm->header); |
1601 | &cnm->header); | ||
1602 | return GNUNET_OK; | 1561 | return GNUNET_OK; |
1603 | } | 1562 | } |
1604 | 1563 | ||
@@ -1612,27 +1571,27 @@ queue_connect_message (void *cls, | |||
1612 | */ | 1571 | */ |
1613 | static void | 1572 | static void |
1614 | handle_client_iterate_peers (void *cls, | 1573 | handle_client_iterate_peers (void *cls, |
1615 | struct GNUNET_SERVER_Client *client, | 1574 | struct GNUNET_SERVER_Client *client, |
1616 | const struct GNUNET_MessageHeader *message) | 1575 | const struct GNUNET_MessageHeader *message) |
1617 | |||
1618 | { | 1576 | { |
1619 | struct GNUNET_MessageHeader done_msg; | 1577 | struct GNUNET_MessageHeader done_msg; |
1620 | struct GNUNET_SERVER_TransmitContext *tc; | 1578 | struct GNUNET_SERVER_TransmitContext *tc; |
1621 | int msize; | 1579 | int msize; |
1580 | |||
1622 | /* notify new client about existing neighbours */ | 1581 | /* notify new client about existing neighbours */ |
1623 | 1582 | ||
1624 | msize = ntohs(message->size); | 1583 | msize = ntohs (message->size); |
1625 | tc = GNUNET_SERVER_transmit_context_create (client); | 1584 | tc = GNUNET_SERVER_transmit_context_create (client); |
1626 | if (msize == sizeof(struct GNUNET_MessageHeader)) | 1585 | if (msize == sizeof (struct GNUNET_MessageHeader)) |
1627 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message, tc); | 1586 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, &queue_connect_message, |
1587 | tc); | ||
1628 | else | 1588 | else |
1629 | GNUNET_break(0); | 1589 | GNUNET_break (0); |
1630 | 1590 | ||
1631 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 1591 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
1632 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); | 1592 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); |
1633 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); | 1593 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); |
1634 | GNUNET_SERVER_transmit_context_run (tc, | 1594 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
1635 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1636 | } | 1595 | } |
1637 | 1596 | ||
1638 | 1597 | ||
@@ -1645,9 +1604,8 @@ handle_client_iterate_peers (void *cls, | |||
1645 | */ | 1604 | */ |
1646 | static void | 1605 | static void |
1647 | handle_client_have_peer (void *cls, | 1606 | handle_client_have_peer (void *cls, |
1648 | struct GNUNET_SERVER_Client *client, | 1607 | struct GNUNET_SERVER_Client *client, |
1649 | const struct GNUNET_MessageHeader *message) | 1608 | const struct GNUNET_MessageHeader *message) |
1650 | |||
1651 | { | 1609 | { |
1652 | struct GNUNET_MessageHeader done_msg; | 1610 | struct GNUNET_MessageHeader done_msg; |
1653 | struct GNUNET_SERVER_TransmitContext *tc; | 1611 | struct GNUNET_SERVER_TransmitContext *tc; |
@@ -1655,15 +1613,13 @@ handle_client_have_peer (void *cls, | |||
1655 | 1613 | ||
1656 | tc = GNUNET_SERVER_transmit_context_create (client); | 1614 | tc = GNUNET_SERVER_transmit_context_create (client); |
1657 | peer = (struct GNUNET_PeerIdentity *) &message[1]; | 1615 | peer = (struct GNUNET_PeerIdentity *) &message[1]; |
1658 | GNUNET_CONTAINER_multihashmap_get_multiple(neighbours, | 1616 | GNUNET_CONTAINER_multihashmap_get_multiple (neighbours, |
1659 | &peer->hashPubKey, | 1617 | &peer->hashPubKey, |
1660 | &queue_connect_message, | 1618 | &queue_connect_message, tc); |
1661 | tc); | ||
1662 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | 1619 | done_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); |
1663 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); | 1620 | done_msg.type = htons (GNUNET_MESSAGE_TYPE_CORE_ITERATE_PEERS_END); |
1664 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); | 1621 | GNUNET_SERVER_transmit_context_append_message (tc, &done_msg); |
1665 | GNUNET_SERVER_transmit_context_run (tc, | 1622 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
1666 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
1667 | } | 1623 | } |
1668 | 1624 | ||
1669 | 1625 | ||
@@ -1676,8 +1632,8 @@ handle_client_have_peer (void *cls, | |||
1676 | */ | 1632 | */ |
1677 | static void | 1633 | static void |
1678 | handle_client_request_info (void *cls, | 1634 | handle_client_request_info (void *cls, |
1679 | struct GNUNET_SERVER_Client *client, | 1635 | struct GNUNET_SERVER_Client *client, |
1680 | const struct GNUNET_MessageHeader *message) | 1636 | const struct GNUNET_MessageHeader *message) |
1681 | { | 1637 | { |
1682 | const struct RequestInfoMessage *rcm; | 1638 | const struct RequestInfoMessage *rcm; |
1683 | struct Client *pos; | 1639 | struct Client *pos; |
@@ -1688,97 +1644,94 @@ handle_client_request_info (void *cls, | |||
1688 | unsigned long long old_preference; | 1644 | unsigned long long old_preference; |
1689 | struct GNUNET_TIME_Relative rdelay; | 1645 | struct GNUNET_TIME_Relative rdelay; |
1690 | 1646 | ||
1691 | rdelay = GNUNET_TIME_relative_get_zero(); | 1647 | rdelay = GNUNET_TIME_relative_get_zero (); |
1692 | #if DEBUG_CORE_CLIENT | 1648 | #if DEBUG_CORE_CLIENT |
1693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1649 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1694 | "Core service receives `%s' request.\n", "REQUEST_INFO"); | 1650 | "Core service receives `%s' request.\n", "REQUEST_INFO"); |
1695 | #endif | 1651 | #endif |
1696 | pos = clients; | 1652 | pos = clients; |
1697 | while (pos != NULL) | 1653 | while (pos != NULL) |
1698 | { | 1654 | { |
1699 | if (client == pos->client_handle) | 1655 | if (client == pos->client_handle) |
1700 | break; | 1656 | break; |
1701 | pos = pos->next; | 1657 | pos = pos->next; |
1702 | } | 1658 | } |
1703 | if (pos == NULL) | 1659 | if (pos == NULL) |
1704 | { | 1660 | { |
1705 | GNUNET_break (0); | 1661 | GNUNET_break (0); |
1706 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1662 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1707 | return; | 1663 | return; |
1708 | } | 1664 | } |
1709 | 1665 | ||
1710 | rcm = (const struct RequestInfoMessage *) message; | 1666 | rcm = (const struct RequestInfoMessage *) message; |
1711 | n = find_neighbour (&rcm->peer); | 1667 | n = find_neighbour (&rcm->peer); |
1712 | memset (&cim, 0, sizeof (cim)); | 1668 | memset (&cim, 0, sizeof (cim)); |
1713 | if ( (n != NULL) && (GNUNET_YES == n->is_connected) ) | 1669 | if ((n != NULL) && (GNUNET_YES == n->is_connected)) |
1670 | { | ||
1671 | want_reserv = ntohl (rcm->reserve_inbound); | ||
1672 | if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | ||
1714 | { | 1673 | { |
1715 | want_reserv = ntohl (rcm->reserve_inbound); | 1674 | n->bw_out_internal_limit = rcm->limit_outbound; |
1716 | if (n->bw_out_internal_limit.value__ != rcm->limit_outbound.value__) | 1675 | if (n->bw_out.value__ != |
1717 | { | 1676 | GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, |
1718 | n->bw_out_internal_limit = rcm->limit_outbound; | 1677 | n->bw_out_external_limit).value__) |
1719 | if (n->bw_out.value__ != GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | 1678 | { |
1720 | n->bw_out_external_limit).value__) | 1679 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, |
1721 | { | 1680 | n->bw_out_external_limit); |
1722 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_internal_limit, | 1681 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, |
1723 | n->bw_out_external_limit); | 1682 | n->bw_out); |
1724 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_recv_window, | 1683 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
1725 | n->bw_out); | 1684 | handle_peer_status_change (n); |
1726 | GNUNET_TRANSPORT_set_quota (transport, | 1685 | } |
1727 | &n->peer, | 1686 | } |
1728 | n->bw_in, | 1687 | if (want_reserv < 0) |
1729 | n->bw_out); | 1688 | { |
1730 | handle_peer_status_change (n); | 1689 | got_reserv = want_reserv; |
1731 | } | 1690 | } |
1732 | } | 1691 | else if (want_reserv > 0) |
1733 | if (want_reserv < 0) | 1692 | { |
1734 | { | 1693 | rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, |
1735 | got_reserv = want_reserv; | 1694 | want_reserv); |
1736 | } | 1695 | if (rdelay.rel_value == 0) |
1737 | else if (want_reserv > 0) | 1696 | got_reserv = want_reserv; |
1738 | { | ||
1739 | rdelay = GNUNET_BANDWIDTH_tracker_get_delay (&n->available_recv_window, | ||
1740 | want_reserv); | ||
1741 | if (rdelay.rel_value == 0) | ||
1742 | got_reserv = want_reserv; | ||
1743 | else | ||
1744 | got_reserv = 0; /* all or nothing */ | ||
1745 | } | ||
1746 | else | 1697 | else |
1747 | got_reserv = 0; | 1698 | got_reserv = 0; /* all or nothing */ |
1748 | GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, | ||
1749 | got_reserv); | ||
1750 | old_preference = n->current_preference; | ||
1751 | n->current_preference += GNUNET_ntohll(rcm->preference_change); | ||
1752 | if (old_preference > n->current_preference) | ||
1753 | { | ||
1754 | /* overflow; cap at maximum value */ | ||
1755 | n->current_preference = ULLONG_MAX; | ||
1756 | } | ||
1757 | update_preference_sum (n->current_preference - old_preference); | ||
1758 | #if DEBUG_CORE_QUOTA | ||
1759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1760 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
1761 | (int) want_reserv, | ||
1762 | GNUNET_i2s (&rcm->peer), | ||
1763 | (int) got_reserv, | ||
1764 | (unsigned long long) rdelay.rel_value); | ||
1765 | #endif | ||
1766 | cim.reserved_amount = htonl (got_reserv); | ||
1767 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
1768 | cim.bw_out = n->bw_out; | ||
1769 | cim.preference = n->current_preference; | ||
1770 | } | 1699 | } |
1771 | else | 1700 | else |
1701 | got_reserv = 0; | ||
1702 | GNUNET_BANDWIDTH_tracker_consume (&n->available_recv_window, got_reserv); | ||
1703 | old_preference = n->current_preference; | ||
1704 | n->current_preference += GNUNET_ntohll (rcm->preference_change); | ||
1705 | if (old_preference > n->current_preference) | ||
1772 | { | 1706 | { |
1773 | /* Technically, this COULD happen (due to asynchronous behavior), | 1707 | /* overflow; cap at maximum value */ |
1774 | but it should be rare, so we should generate an info event | 1708 | n->current_preference = ULLONG_MAX; |
1775 | to help diagnosis of serious errors that might be masked by this */ | ||
1776 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1777 | _("Client asked for preference change with peer `%s', which is not connected!\n"), | ||
1778 | GNUNET_i2s (&rcm->peer)); | ||
1779 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1780 | return; | ||
1781 | } | 1709 | } |
1710 | update_preference_sum (n->current_preference - old_preference); | ||
1711 | #if DEBUG_CORE_QUOTA | ||
1712 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1713 | "Received reservation request for %d bytes for peer `%4s', reserved %d bytes, suggesting delay of %llu ms\n", | ||
1714 | (int) want_reserv, | ||
1715 | GNUNET_i2s (&rcm->peer), | ||
1716 | (int) got_reserv, (unsigned long long) rdelay.rel_value); | ||
1717 | #endif | ||
1718 | cim.reserved_amount = htonl (got_reserv); | ||
1719 | cim.reserve_delay = GNUNET_TIME_relative_hton (rdelay); | ||
1720 | cim.bw_out = n->bw_out; | ||
1721 | cim.preference = n->current_preference; | ||
1722 | } | ||
1723 | else | ||
1724 | { | ||
1725 | /* Technically, this COULD happen (due to asynchronous behavior), | ||
1726 | * but it should be rare, so we should generate an info event | ||
1727 | * to help diagnosis of serious errors that might be masked by this */ | ||
1728 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1729 | _ | ||
1730 | ("Client asked for preference change with peer `%s', which is not connected!\n"), | ||
1731 | GNUNET_i2s (&rcm->peer)); | ||
1732 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1733 | return; | ||
1734 | } | ||
1782 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); | 1735 | cim.header.size = htons (sizeof (struct ConfigurationInfoMessage)); |
1783 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); | 1736 | cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO); |
1784 | cim.peer = rcm->peer; | 1737 | cim.peer = rcm->peer; |
@@ -1806,47 +1759,44 @@ free_neighbour (struct Neighbour *n) | |||
1806 | 1759 | ||
1807 | #if DEBUG_CORE | 1760 | #if DEBUG_CORE |
1808 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1761 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1809 | "Destroying neighbour entry for peer `%4s'\n", | 1762 | "Destroying neighbour entry for peer `%4s'\n", |
1810 | GNUNET_i2s (&n->peer)); | 1763 | GNUNET_i2s (&n->peer)); |
1811 | #endif | 1764 | #endif |
1812 | if (n->pitr != NULL) | 1765 | if (n->pitr != NULL) |
1813 | { | 1766 | { |
1814 | GNUNET_PEERINFO_iterate_cancel (n->pitr); | 1767 | GNUNET_PEERINFO_iterate_cancel (n->pitr); |
1815 | n->pitr = NULL; | 1768 | n->pitr = NULL; |
1816 | } | 1769 | } |
1817 | if (n->skm != NULL) | 1770 | if (n->skm != NULL) |
1818 | { | 1771 | { |
1819 | GNUNET_free (n->skm); | 1772 | GNUNET_free (n->skm); |
1820 | n->skm = NULL; | 1773 | n->skm = NULL; |
1821 | } | 1774 | } |
1822 | while (NULL != (m = n->messages)) | 1775 | while (NULL != (m = n->messages)) |
1823 | { | 1776 | { |
1824 | n->messages = m->next; | 1777 | n->messages = m->next; |
1825 | GNUNET_free (m); | 1778 | GNUNET_free (m); |
1826 | } | 1779 | } |
1827 | while (NULL != (m = n->encrypted_head)) | 1780 | while (NULL != (m = n->encrypted_head)) |
1828 | { | 1781 | { |
1829 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 1782 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
1830 | n->encrypted_tail, | 1783 | GNUNET_free (m); |
1831 | m); | 1784 | } |
1832 | GNUNET_free (m); | ||
1833 | } | ||
1834 | while (NULL != (car = n->active_client_request_head)) | 1785 | while (NULL != (car = n->active_client_request_head)) |
1835 | { | 1786 | { |
1836 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 1787 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
1837 | n->active_client_request_tail, | 1788 | n->active_client_request_tail, car); |
1838 | car); | 1789 | GNUNET_assert (GNUNET_YES == |
1839 | GNUNET_assert (GNUNET_YES == | 1790 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, |
1840 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, | 1791 | &n->peer.hashPubKey, |
1841 | &n->peer.hashPubKey, | 1792 | car)); |
1842 | car)); | 1793 | GNUNET_free (car); |
1843 | GNUNET_free (car); | 1794 | } |
1844 | } | ||
1845 | if (NULL != n->th) | 1795 | if (NULL != n->th) |
1846 | { | 1796 | { |
1847 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); | 1797 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); |
1848 | n->th = NULL; | 1798 | n->th = NULL; |
1849 | } | 1799 | } |
1850 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) | 1800 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) |
1851 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); | 1801 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); |
1852 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 1802 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1855,13 +1805,12 @@ free_neighbour (struct Neighbour *n) | |||
1855 | GNUNET_SCHEDULER_cancel (n->quota_update_task); | 1805 | GNUNET_SCHEDULER_cancel (n->quota_update_task); |
1856 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 1806 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
1857 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 1807 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
1858 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | 1808 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) |
1859 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 1809 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
1860 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 1810 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
1861 | GNUNET_STATISTICS_update (stats, | 1811 | GNUNET_STATISTICS_update (stats, |
1862 | gettext_noop ("# established sessions"), | 1812 | gettext_noop ("# established sessions"), |
1863 | -1, | 1813 | -1, GNUNET_NO); |
1864 | GNUNET_NO); | ||
1865 | GNUNET_array_grow (n->ats, n->ats_count, 0); | 1814 | GNUNET_array_grow (n->ats, n->ats_count, 0); |
1866 | GNUNET_free_non_null (n->public_key); | 1815 | GNUNET_free_non_null (n->public_key); |
1867 | GNUNET_free_non_null (n->pending_ping); | 1816 | GNUNET_free_non_null (n->pending_ping); |
@@ -1893,27 +1842,27 @@ static void process_encrypted_neighbour_queue (struct Neighbour *n); | |||
1893 | */ | 1842 | */ |
1894 | static int | 1843 | static int |
1895 | do_encrypt (struct Neighbour *n, | 1844 | do_encrypt (struct Neighbour *n, |
1896 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, | 1845 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, |
1897 | const void *in, void *out, size_t size) | 1846 | const void *in, void *out, size_t size) |
1898 | { | 1847 | { |
1899 | if (size != (uint16_t) size) | 1848 | if (size != (uint16_t) size) |
1900 | { | 1849 | { |
1901 | GNUNET_break (0); | 1850 | GNUNET_break (0); |
1902 | return GNUNET_NO; | 1851 | return GNUNET_NO; |
1903 | } | 1852 | } |
1904 | GNUNET_assert (size == | 1853 | GNUNET_assert (size == |
1905 | GNUNET_CRYPTO_aes_encrypt (in, | 1854 | GNUNET_CRYPTO_aes_encrypt (in, |
1906 | (uint16_t) size, | 1855 | (uint16_t) size, |
1907 | &n->encrypt_key, | 1856 | &n->encrypt_key, iv, out)); |
1908 | iv, out)); | 1857 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, |
1909 | GNUNET_STATISTICS_update (stats, gettext_noop ("# bytes encrypted"), size, GNUNET_NO); | 1858 | GNUNET_NO); |
1910 | #if DEBUG_CORE > 2 | 1859 | #if DEBUG_CORE > 2 |
1911 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1860 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1912 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", | 1861 | "Encrypted %u bytes for `%4s' using key %u, IV %u\n", |
1913 | (unsigned int) size, | 1862 | (unsigned int) size, |
1914 | GNUNET_i2s (&n->peer), | 1863 | GNUNET_i2s (&n->peer), |
1915 | (unsigned int) n->encrypt_key.crc32, | 1864 | (unsigned int) n->encrypt_key.crc32, |
1916 | GNUNET_CRYPTO_crc32_n (iv, sizeof(iv))); | 1865 | GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); |
1917 | #endif | 1866 | #endif |
1918 | return GNUNET_OK; | 1867 | return GNUNET_OK; |
1919 | } | 1868 | } |
@@ -1925,8 +1874,7 @@ do_encrypt (struct Neighbour *n, | |||
1925 | * | 1874 | * |
1926 | * @param n neighbour to consider discarding | 1875 | * @param n neighbour to consider discarding |
1927 | */ | 1876 | */ |
1928 | static void | 1877 | static void consider_free_neighbour (struct Neighbour *n); |
1929 | consider_free_neighbour (struct Neighbour *n); | ||
1930 | 1878 | ||
1931 | 1879 | ||
1932 | /** | 1880 | /** |
@@ -1937,8 +1885,7 @@ consider_free_neighbour (struct Neighbour *n); | |||
1937 | * @param tc scheduler context (not used) | 1885 | * @param tc scheduler context (not used) |
1938 | */ | 1886 | */ |
1939 | static void | 1887 | static void |
1940 | send_keep_alive (void *cls, | 1888 | send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1941 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1942 | { | 1889 | { |
1943 | struct Neighbour *n = cls; | 1890 | struct Neighbour *n = cls; |
1944 | struct GNUNET_TIME_Relative retry; | 1891 | struct GNUNET_TIME_Relative retry; |
@@ -1956,26 +1903,23 @@ send_keep_alive (void *cls, | |||
1956 | me->priority = PING_PRIORITY; | 1903 | me->priority = PING_PRIORITY; |
1957 | me->size = sizeof (struct PingMessage); | 1904 | me->size = sizeof (struct PingMessage); |
1958 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 1905 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
1959 | n->encrypted_tail, | 1906 | n->encrypted_tail, n->encrypted_tail, me); |
1960 | n->encrypted_tail, | ||
1961 | me); | ||
1962 | pm = (struct PingMessage *) &me[1]; | 1907 | pm = (struct PingMessage *) &me[1]; |
1963 | pm->header.size = htons (sizeof (struct PingMessage)); | 1908 | pm->header.size = htons (sizeof (struct PingMessage)); |
1964 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 1909 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
1965 | pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 1910 | pm->iv_seed = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
1966 | UINT32_MAX); | 1911 | UINT32_MAX); |
1967 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | 1912 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); |
1968 | pp.challenge = n->ping_challenge; | 1913 | pp.challenge = n->ping_challenge; |
1969 | pp.target = n->peer; | 1914 | pp.target = n->peer; |
1970 | #if DEBUG_HANDSHAKE | 1915 | #if DEBUG_HANDSHAKE |
1971 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1972 | "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", | 1917 | "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
1973 | "PING", | 1918 | "PING", |
1974 | (unsigned int) n->ping_challenge, | 1919 | (unsigned int) n->ping_challenge, |
1975 | GNUNET_i2s (&n->peer), | 1920 | GNUNET_i2s (&n->peer), |
1976 | (unsigned int) n->encrypt_key.crc32, | 1921 | (unsigned int) n->encrypt_key.crc32, |
1977 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 1922 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); |
1978 | pm->iv_seed); | ||
1979 | #endif | 1923 | #endif |
1980 | do_encrypt (n, | 1924 | do_encrypt (n, |
1981 | &iv, | 1925 | &iv, |
@@ -1987,11 +1931,9 @@ send_keep_alive (void *cls, | |||
1987 | /* reschedule PING job */ | 1931 | /* reschedule PING job */ |
1988 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); | 1932 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); |
1989 | retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), | 1933 | retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), |
1990 | MIN_PING_FREQUENCY); | 1934 | MIN_PING_FREQUENCY); |
1991 | n->keep_alive_task | 1935 | n->keep_alive_task |
1992 | = GNUNET_SCHEDULER_add_delayed (retry, | 1936 | = GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); |
1993 | &send_keep_alive, | ||
1994 | n); | ||
1995 | 1937 | ||
1996 | } | 1938 | } |
1997 | 1939 | ||
@@ -2003,8 +1945,7 @@ send_keep_alive (void *cls, | |||
2003 | * @param tc scheduler context (not used) | 1945 | * @param tc scheduler context (not used) |
2004 | */ | 1946 | */ |
2005 | static void | 1947 | static void |
2006 | consider_free_task (void *cls, | 1948 | consider_free_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
2007 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
2008 | { | 1949 | { |
2009 | struct Neighbour *n = cls; | 1950 | struct Neighbour *n = cls; |
2010 | 1951 | ||
@@ -2021,33 +1962,29 @@ consider_free_task (void *cls, | |||
2021 | */ | 1962 | */ |
2022 | static void | 1963 | static void |
2023 | consider_free_neighbour (struct Neighbour *n) | 1964 | consider_free_neighbour (struct Neighbour *n) |
2024 | { | 1965 | { |
2025 | struct GNUNET_TIME_Relative left; | 1966 | struct GNUNET_TIME_Relative left; |
2026 | 1967 | ||
2027 | if ( (n->th != NULL) || | 1968 | if ((n->th != NULL) || (n->pitr != NULL) || (GNUNET_YES == n->is_connected)) |
2028 | (n->pitr != NULL) || | 1969 | return; /* no chance */ |
2029 | (GNUNET_YES == n->is_connected) ) | 1970 | |
2030 | return; /* no chance */ | ||
2031 | |||
2032 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); | 1971 | left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); |
2033 | if (left.rel_value > 0) | 1972 | if (left.rel_value > 0) |
2034 | { | 1973 | { |
2035 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 1974 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
2036 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 1975 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
2037 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, | 1976 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (left, |
2038 | &consider_free_task, | 1977 | &consider_free_task, n); |
2039 | n); | 1978 | return; |
2040 | return; | 1979 | } |
2041 | } | ||
2042 | /* actually free the neighbour... */ | 1980 | /* actually free the neighbour... */ |
2043 | GNUNET_assert (GNUNET_YES == | 1981 | GNUNET_assert (GNUNET_YES == |
2044 | GNUNET_CONTAINER_multihashmap_remove (neighbours, | 1982 | GNUNET_CONTAINER_multihashmap_remove (neighbours, |
2045 | &n->peer.hashPubKey, | 1983 | &n->peer.hashPubKey, n)); |
2046 | n)); | ||
2047 | GNUNET_STATISTICS_set (stats, | 1984 | GNUNET_STATISTICS_set (stats, |
2048 | gettext_noop ("# neighbour entries allocated"), | 1985 | gettext_noop ("# neighbour entries allocated"), |
2049 | GNUNET_CONTAINER_multihashmap_size (neighbours), | 1986 | GNUNET_CONTAINER_multihashmap_size (neighbours), |
2050 | GNUNET_NO); | 1987 | GNUNET_NO); |
2051 | free_neighbour (n); | 1988 | free_neighbour (n); |
2052 | } | 1989 | } |
2053 | 1990 | ||
@@ -2062,9 +1999,7 @@ consider_free_neighbour (struct Neighbour *n) | |||
2062 | * @return number of bytes transmitted | 1999 | * @return number of bytes transmitted |
2063 | */ | 2000 | */ |
2064 | static size_t | 2001 | static size_t |
2065 | notify_encrypted_transmit_ready (void *cls, | 2002 | notify_encrypted_transmit_ready (void *cls, size_t size, void *buf) |
2066 | size_t size, | ||
2067 | void *buf) | ||
2068 | { | 2003 | { |
2069 | struct Neighbour *n = cls; | 2004 | struct Neighbour *n = cls; |
2070 | struct MessageEntry *m; | 2005 | struct MessageEntry *m; |
@@ -2074,50 +2009,48 @@ notify_encrypted_transmit_ready (void *cls, | |||
2074 | n->th = NULL; | 2009 | n->th = NULL; |
2075 | m = n->encrypted_head; | 2010 | m = n->encrypted_head; |
2076 | if (m == NULL) | 2011 | if (m == NULL) |
2077 | { | 2012 | { |
2078 | #if DEBUG_CORE | 2013 | #if DEBUG_CORE |
2079 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2080 | "Encrypted message queue empty, no messages added to buffer for `%4s'\n", | 2015 | "Encrypted message queue empty, no messages added to buffer for `%4s'\n", |
2081 | GNUNET_i2s (&n->peer)); | 2016 | GNUNET_i2s (&n->peer)); |
2082 | #endif | 2017 | #endif |
2083 | return 0; | 2018 | return 0; |
2084 | } | 2019 | } |
2085 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 2020 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
2086 | n->encrypted_tail, | ||
2087 | m); | ||
2088 | ret = 0; | 2021 | ret = 0; |
2089 | cbuf = buf; | 2022 | cbuf = buf; |
2090 | if (buf != NULL) | 2023 | if (buf != NULL) |
2091 | { | 2024 | { |
2092 | GNUNET_assert (size >= m->size); | 2025 | GNUNET_assert (size >= m->size); |
2093 | memcpy (cbuf, &m[1], m->size); | 2026 | memcpy (cbuf, &m[1], m->size); |
2094 | ret = m->size; | 2027 | ret = m->size; |
2095 | GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, | 2028 | GNUNET_BANDWIDTH_tracker_consume (&n->available_send_window, m->size); |
2096 | m->size); | ||
2097 | #if DEBUG_CORE | 2029 | #if DEBUG_CORE |
2098 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2099 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", | 2031 | "Copied message of type %u and size %u into transport buffer for `%4s'\n", |
2100 | (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), | 2032 | (unsigned int) |
2101 | (unsigned int) ret, | 2033 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), |
2102 | GNUNET_i2s (&n->peer)); | 2034 | (unsigned int) ret, GNUNET_i2s (&n->peer)); |
2103 | #endif | 2035 | #endif |
2104 | process_encrypted_neighbour_queue (n); | 2036 | process_encrypted_neighbour_queue (n); |
2105 | } | 2037 | } |
2106 | else | 2038 | else |
2107 | { | 2039 | { |
2108 | #if DEBUG_CORE | 2040 | #if DEBUG_CORE |
2109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2110 | "Transmission of message of type %u and size %u failed\n", | 2042 | "Transmission of message of type %u and size %u failed\n", |
2111 | (unsigned int) ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), | 2043 | (unsigned int) |
2112 | (unsigned int) m->size); | 2044 | ntohs (((struct GNUNET_MessageHeader *) &m[1])->type), |
2045 | (unsigned int) m->size); | ||
2113 | #endif | 2046 | #endif |
2114 | } | 2047 | } |
2115 | GNUNET_free (m); | 2048 | GNUNET_free (m); |
2116 | consider_free_neighbour (n); | 2049 | consider_free_neighbour (n); |
2117 | GNUNET_STATISTICS_update (stats, | 2050 | GNUNET_STATISTICS_update (stats, |
2118 | gettext_noop ("# encrypted bytes given to transport"), | 2051 | gettext_noop |
2119 | ret, | 2052 | ("# encrypted bytes given to transport"), ret, |
2120 | GNUNET_NO); | 2053 | GNUNET_NO); |
2121 | return ret; | 2054 | return ret; |
2122 | } | 2055 | } |
2123 | 2056 | ||
@@ -2143,47 +2076,46 @@ static void | |||
2143 | process_encrypted_neighbour_queue (struct Neighbour *n) | 2076 | process_encrypted_neighbour_queue (struct Neighbour *n) |
2144 | { | 2077 | { |
2145 | struct MessageEntry *m; | 2078 | struct MessageEntry *m; |
2146 | 2079 | ||
2147 | if (n->th != NULL) | 2080 | if (n->th != NULL) |
2148 | return; /* request already pending */ | 2081 | return; /* request already pending */ |
2149 | if (GNUNET_YES != n->is_connected) | 2082 | if (GNUNET_YES != n->is_connected) |
2150 | { | 2083 | { |
2151 | GNUNET_break (0); | 2084 | GNUNET_break (0); |
2152 | return; | 2085 | return; |
2153 | } | 2086 | } |
2154 | m = n->encrypted_head; | 2087 | m = n->encrypted_head; |
2155 | if (m == NULL) | 2088 | if (m == NULL) |
2156 | { | 2089 | { |
2157 | /* encrypted queue empty, try plaintext instead */ | 2090 | /* encrypted queue empty, try plaintext instead */ |
2158 | process_plaintext_neighbour_queue (n); | 2091 | process_plaintext_neighbour_queue (n); |
2159 | return; | 2092 | return; |
2160 | } | 2093 | } |
2161 | #if DEBUG_CORE > 1 | 2094 | #if DEBUG_CORE > 1 |
2162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2163 | "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", | 2096 | "Asking transport for transmission of %u bytes to `%4s' in next %llu ms\n", |
2164 | (unsigned int) m->size, | 2097 | (unsigned int) m->size, |
2165 | GNUNET_i2s (&n->peer), | 2098 | GNUNET_i2s (&n->peer), |
2166 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); | 2099 | (unsigned long long) |
2100 | GNUNET_TIME_absolute_get_remaining (m->deadline).rel_value); | ||
2167 | #endif | 2101 | #endif |
2168 | n->th = | 2102 | n->th = |
2169 | GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, | 2103 | GNUNET_TRANSPORT_notify_transmit_ready (transport, &n->peer, |
2170 | m->size, | 2104 | m->size, |
2171 | m->priority, | 2105 | m->priority, |
2172 | GNUNET_TIME_absolute_get_remaining | 2106 | GNUNET_TIME_absolute_get_remaining |
2173 | (m->deadline), | 2107 | (m->deadline), |
2174 | ¬ify_encrypted_transmit_ready, | 2108 | ¬ify_encrypted_transmit_ready, |
2175 | n); | 2109 | n); |
2176 | if (n->th == NULL) | 2110 | if (n->th == NULL) |
2177 | { | 2111 | { |
2178 | /* message request too large or duplicate request */ | 2112 | /* message request too large or duplicate request */ |
2179 | GNUNET_break (0); | 2113 | GNUNET_break (0); |
2180 | /* discard encrypted message */ | 2114 | /* discard encrypted message */ |
2181 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 2115 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, m); |
2182 | n->encrypted_tail, | 2116 | GNUNET_free (m); |
2183 | m); | 2117 | process_encrypted_neighbour_queue (n); |
2184 | GNUNET_free (m); | 2118 | } |
2185 | process_encrypted_neighbour_queue (n); | ||
2186 | } | ||
2187 | } | 2119 | } |
2188 | 2120 | ||
2189 | 2121 | ||
@@ -2201,41 +2133,36 @@ process_encrypted_neighbour_queue (struct Neighbour *n) | |||
2201 | */ | 2133 | */ |
2202 | static int | 2134 | static int |
2203 | do_decrypt (struct Neighbour *n, | 2135 | do_decrypt (struct Neighbour *n, |
2204 | const struct GNUNET_CRYPTO_AesInitializationVector * iv, | 2136 | const struct GNUNET_CRYPTO_AesInitializationVector *iv, |
2205 | const void *in, void *out, size_t size) | 2137 | const void *in, void *out, size_t size) |
2206 | { | 2138 | { |
2207 | if (size != (uint16_t) size) | 2139 | if (size != (uint16_t) size) |
2208 | { | 2140 | { |
2209 | GNUNET_break (0); | 2141 | GNUNET_break (0); |
2210 | return GNUNET_NO; | 2142 | return GNUNET_NO; |
2211 | } | 2143 | } |
2212 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | 2144 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
2213 | (n->status != PEER_STATE_KEY_CONFIRMED)) | 2145 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
2214 | { | 2146 | { |
2215 | GNUNET_break_op (0); | 2147 | GNUNET_break_op (0); |
2216 | return GNUNET_SYSERR; | 2148 | return GNUNET_SYSERR; |
2217 | } | 2149 | } |
2218 | if (size != | 2150 | if (size != |
2219 | GNUNET_CRYPTO_aes_decrypt (in, | 2151 | GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &n->decrypt_key, iv, out)) |
2220 | (uint16_t) size, | 2152 | { |
2221 | &n->decrypt_key, | 2153 | GNUNET_break (0); |
2222 | iv, | 2154 | return GNUNET_SYSERR; |
2223 | out)) | 2155 | } |
2224 | { | 2156 | GNUNET_STATISTICS_update (stats, |
2225 | GNUNET_break (0); | 2157 | gettext_noop ("# bytes decrypted"), |
2226 | return GNUNET_SYSERR; | 2158 | size, GNUNET_NO); |
2227 | } | ||
2228 | GNUNET_STATISTICS_update (stats, | ||
2229 | gettext_noop ("# bytes decrypted"), | ||
2230 | size, | ||
2231 | GNUNET_NO); | ||
2232 | #if DEBUG_CORE > 1 | 2159 | #if DEBUG_CORE > 1 |
2233 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2234 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", | 2161 | "Decrypted %u bytes from `%4s' using key %u, IV %u\n", |
2235 | (unsigned int) size, | 2162 | (unsigned int) size, |
2236 | GNUNET_i2s (&n->peer), | 2163 | GNUNET_i2s (&n->peer), |
2237 | (unsigned int) n->decrypt_key.crc32, | 2164 | (unsigned int) n->decrypt_key.crc32, |
2238 | GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv))); | 2165 | GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); |
2239 | #endif | 2166 | #endif |
2240 | return GNUNET_OK; | 2167 | return GNUNET_OK; |
2241 | } | 2168 | } |
@@ -2270,7 +2197,7 @@ select_messages (struct Neighbour *n, | |||
2270 | struct GNUNET_TIME_Absolute now; | 2197 | struct GNUNET_TIME_Absolute now; |
2271 | struct GNUNET_TIME_Relative delta; | 2198 | struct GNUNET_TIME_Relative delta; |
2272 | uint64_t avail; | 2199 | uint64_t avail; |
2273 | struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */ | 2200 | struct GNUNET_TIME_Relative slack; /* how long could we wait before missing deadlines? */ |
2274 | size_t off; | 2201 | size_t off; |
2275 | uint64_t tsize; | 2202 | uint64_t tsize; |
2276 | unsigned int queue_size; | 2203 | unsigned int queue_size; |
@@ -2281,171 +2208,172 @@ select_messages (struct Neighbour *n, | |||
2281 | /* last entry in linked list of messages processed */ | 2208 | /* last entry in linked list of messages processed */ |
2282 | last = NULL; | 2209 | last = NULL; |
2283 | /* should we remove the entry with the lowest | 2210 | /* should we remove the entry with the lowest |
2284 | priority from consideration for scheduling at the | 2211 | * priority from consideration for scheduling at the |
2285 | end of the loop? */ | 2212 | * end of the loop? */ |
2286 | queue_size = 0; | 2213 | queue_size = 0; |
2287 | tsize = 0; | 2214 | tsize = 0; |
2288 | pos = n->messages; | 2215 | pos = n->messages; |
2289 | while (pos != NULL) | 2216 | while (pos != NULL) |
2290 | { | 2217 | { |
2291 | queue_size++; | 2218 | queue_size++; |
2292 | tsize += pos->size; | 2219 | tsize += pos->size; |
2293 | pos = pos->next; | 2220 | pos = pos->next; |
2294 | } | 2221 | } |
2295 | discard_low_prio = GNUNET_YES; | 2222 | discard_low_prio = GNUNET_YES; |
2296 | while (GNUNET_YES == discard_low_prio) | 2223 | while (GNUNET_YES == discard_low_prio) |
2224 | { | ||
2225 | min = NULL; | ||
2226 | min_prio = UINT_MAX; | ||
2227 | discard_low_prio = GNUNET_NO; | ||
2228 | /* calculate number of bytes available for transmission at time "t" */ | ||
2229 | avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window); | ||
2230 | t = now; | ||
2231 | /* how many bytes have we (hypothetically) scheduled so far */ | ||
2232 | off = 0; | ||
2233 | /* maximum time we can wait before transmitting anything | ||
2234 | * and still make all of our deadlines */ | ||
2235 | slack = GNUNET_TIME_UNIT_FOREVER_REL; | ||
2236 | pos = n->messages; | ||
2237 | /* note that we use "*2" here because we want to look | ||
2238 | * a bit further into the future; much more makes no | ||
2239 | * sense since new message might be scheduled in the | ||
2240 | * meantime... */ | ||
2241 | while ((pos != NULL) && (off < size * 2)) | ||
2297 | { | 2242 | { |
2298 | min = NULL; | 2243 | if (pos->do_transmit == GNUNET_YES) |
2299 | min_prio = UINT_MAX; | 2244 | { |
2300 | discard_low_prio = GNUNET_NO; | 2245 | /* already removed from consideration */ |
2301 | /* calculate number of bytes available for transmission at time "t" */ | 2246 | pos = pos->next; |
2302 | avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window); | 2247 | continue; |
2303 | t = now; | 2248 | } |
2304 | /* how many bytes have we (hypothetically) scheduled so far */ | 2249 | if (discard_low_prio == GNUNET_NO) |
2305 | off = 0; | 2250 | { |
2306 | /* maximum time we can wait before transmitting anything | 2251 | delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline); |
2307 | and still make all of our deadlines */ | 2252 | if (delta.rel_value > 0) |
2308 | slack = GNUNET_TIME_UNIT_FOREVER_REL; | 2253 | { |
2309 | pos = n->messages; | 2254 | // FIXME: HUH? Check! |
2310 | /* note that we use "*2" here because we want to look | 2255 | t = pos->deadline; |
2311 | a bit further into the future; much more makes no | 2256 | avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, |
2312 | sense since new message might be scheduled in the | 2257 | delta); |
2313 | meantime... */ | ||
2314 | while ((pos != NULL) && (off < size * 2)) | ||
2315 | { | ||
2316 | if (pos->do_transmit == GNUNET_YES) | ||
2317 | { | ||
2318 | /* already removed from consideration */ | ||
2319 | pos = pos->next; | ||
2320 | continue; | ||
2321 | } | ||
2322 | if (discard_low_prio == GNUNET_NO) | ||
2323 | { | ||
2324 | delta = GNUNET_TIME_absolute_get_difference (t, pos->deadline); | ||
2325 | if (delta.rel_value > 0) | ||
2326 | { | ||
2327 | // FIXME: HUH? Check! | ||
2328 | t = pos->deadline; | ||
2329 | avail += GNUNET_BANDWIDTH_value_get_available_until (n->bw_out, | ||
2330 | delta); | ||
2331 | } | ||
2332 | if (avail < pos->size) | ||
2333 | { | ||
2334 | // FIXME: HUH? Check! | ||
2335 | discard_low_prio = GNUNET_YES; /* we could not schedule this one! */ | ||
2336 | } | ||
2337 | else | ||
2338 | { | ||
2339 | avail -= pos->size; | ||
2340 | /* update slack, considering both its absolute deadline | ||
2341 | and relative deadlines caused by other messages | ||
2342 | with their respective load */ | ||
2343 | slack = GNUNET_TIME_relative_min (slack, | ||
2344 | GNUNET_BANDWIDTH_value_get_delay_for (n->bw_out, | ||
2345 | avail)); | ||
2346 | if (pos->deadline.abs_value <= now.abs_value) | ||
2347 | { | ||
2348 | /* now or never */ | ||
2349 | slack = GNUNET_TIME_UNIT_ZERO; | ||
2350 | } | ||
2351 | else if (GNUNET_YES == pos->got_slack) | ||
2352 | { | ||
2353 | /* should be soon now! */ | ||
2354 | slack = GNUNET_TIME_relative_min (slack, | ||
2355 | GNUNET_TIME_absolute_get_remaining (pos->slack_deadline)); | ||
2356 | } | ||
2357 | else | ||
2358 | { | ||
2359 | slack = | ||
2360 | GNUNET_TIME_relative_min (slack, | ||
2361 | GNUNET_TIME_absolute_get_difference (now, pos->deadline)); | ||
2362 | pos->got_slack = GNUNET_YES; | ||
2363 | pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, | ||
2364 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY)); | ||
2365 | } | ||
2366 | } | ||
2367 | } | ||
2368 | off += pos->size; | ||
2369 | t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check! | ||
2370 | if (pos->priority <= min_prio) | ||
2371 | { | ||
2372 | /* update min for discard */ | ||
2373 | min_prio = pos->priority; | ||
2374 | min = pos; | ||
2375 | } | ||
2376 | pos = pos->next; | ||
2377 | } | 2258 | } |
2378 | if (discard_low_prio) | 2259 | if (avail < pos->size) |
2379 | { | 2260 | { |
2380 | GNUNET_assert (min != NULL); | 2261 | // FIXME: HUH? Check! |
2381 | /* remove lowest-priority entry from consideration */ | 2262 | discard_low_prio = GNUNET_YES; /* we could not schedule this one! */ |
2382 | min->do_transmit = GNUNET_YES; /* means: discard (for now) */ | ||
2383 | } | 2263 | } |
2384 | last = pos; | 2264 | else |
2265 | { | ||
2266 | avail -= pos->size; | ||
2267 | /* update slack, considering both its absolute deadline | ||
2268 | * and relative deadlines caused by other messages | ||
2269 | * with their respective load */ | ||
2270 | slack = GNUNET_TIME_relative_min (slack, | ||
2271 | GNUNET_BANDWIDTH_value_get_delay_for | ||
2272 | (n->bw_out, avail)); | ||
2273 | if (pos->deadline.abs_value <= now.abs_value) | ||
2274 | { | ||
2275 | /* now or never */ | ||
2276 | slack = GNUNET_TIME_UNIT_ZERO; | ||
2277 | } | ||
2278 | else if (GNUNET_YES == pos->got_slack) | ||
2279 | { | ||
2280 | /* should be soon now! */ | ||
2281 | slack = GNUNET_TIME_relative_min (slack, | ||
2282 | GNUNET_TIME_absolute_get_remaining | ||
2283 | (pos->slack_deadline)); | ||
2284 | } | ||
2285 | else | ||
2286 | { | ||
2287 | slack = | ||
2288 | GNUNET_TIME_relative_min (slack, | ||
2289 | GNUNET_TIME_absolute_get_difference | ||
2290 | (now, pos->deadline)); | ||
2291 | pos->got_slack = GNUNET_YES; | ||
2292 | pos->slack_deadline = GNUNET_TIME_absolute_min (pos->deadline, | ||
2293 | GNUNET_TIME_relative_to_absolute | ||
2294 | (GNUNET_CONSTANTS_MAX_CORK_DELAY)); | ||
2295 | } | ||
2296 | } | ||
2297 | } | ||
2298 | off += pos->size; | ||
2299 | t = GNUNET_TIME_absolute_max (pos->deadline, t); // HUH? Check! | ||
2300 | if (pos->priority <= min_prio) | ||
2301 | { | ||
2302 | /* update min for discard */ | ||
2303 | min_prio = pos->priority; | ||
2304 | min = pos; | ||
2305 | } | ||
2306 | pos = pos->next; | ||
2385 | } | 2307 | } |
2308 | if (discard_low_prio) | ||
2309 | { | ||
2310 | GNUNET_assert (min != NULL); | ||
2311 | /* remove lowest-priority entry from consideration */ | ||
2312 | min->do_transmit = GNUNET_YES; /* means: discard (for now) */ | ||
2313 | } | ||
2314 | last = pos; | ||
2315 | } | ||
2386 | /* guard against sending "tiny" messages with large headers without | 2316 | /* guard against sending "tiny" messages with large headers without |
2387 | urgent deadlines */ | 2317 | * urgent deadlines */ |
2388 | if ( (slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) && | 2318 | if ((slack.rel_value > GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value) && |
2389 | (size > 4 * off) && | 2319 | (size > 4 * off) && (queue_size <= MAX_PEER_QUEUE_SIZE - 2)) |
2390 | (queue_size <= MAX_PEER_QUEUE_SIZE - 2) ) | 2320 | { |
2321 | /* less than 25% of message would be filled with deadlines still | ||
2322 | * being met if we delay by one second or more; so just wait for | ||
2323 | * more data; but do not wait longer than 1s (since we don't want | ||
2324 | * to delay messages for a really long time either). */ | ||
2325 | *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY; | ||
2326 | /* reset do_transmit values for next time */ | ||
2327 | while (pos != last) | ||
2391 | { | 2328 | { |
2392 | /* less than 25% of message would be filled with deadlines still | 2329 | pos->do_transmit = GNUNET_NO; |
2393 | being met if we delay by one second or more; so just wait for | 2330 | pos = pos->next; |
2394 | more data; but do not wait longer than 1s (since we don't want | 2331 | } |
2395 | to delay messages for a really long time either). */ | 2332 | GNUNET_STATISTICS_update (stats, |
2396 | *retry_time = GNUNET_CONSTANTS_MAX_CORK_DELAY; | 2333 | gettext_noop |
2397 | /* reset do_transmit values for next time */ | 2334 | ("# transmissions delayed due to corking"), 1, |
2398 | while (pos != last) | 2335 | GNUNET_NO); |
2399 | { | ||
2400 | pos->do_transmit = GNUNET_NO; | ||
2401 | pos = pos->next; | ||
2402 | } | ||
2403 | GNUNET_STATISTICS_update (stats, | ||
2404 | gettext_noop ("# transmissions delayed due to corking"), | ||
2405 | 1, GNUNET_NO); | ||
2406 | #if DEBUG_CORE | 2336 | #if DEBUG_CORE |
2407 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2408 | "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", | 2338 | "Deferring transmission for %llums due to underfull message buffer size (%u/%u)\n", |
2409 | (unsigned long long) retry_time->rel_value, | 2339 | (unsigned long long) retry_time->rel_value, |
2410 | (unsigned int) off, | 2340 | (unsigned int) off, (unsigned int) size); |
2411 | (unsigned int) size); | ||
2412 | #endif | 2341 | #endif |
2413 | return 0; | 2342 | return 0; |
2414 | } | 2343 | } |
2415 | /* select marked messages (up to size) for transmission */ | 2344 | /* select marked messages (up to size) for transmission */ |
2416 | off = 0; | 2345 | off = 0; |
2417 | pos = n->messages; | 2346 | pos = n->messages; |
2418 | while (pos != last) | 2347 | while (pos != last) |
2348 | { | ||
2349 | if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO)) | ||
2419 | { | 2350 | { |
2420 | if ((pos->size <= size) && (pos->do_transmit == GNUNET_NO)) | 2351 | pos->do_transmit = GNUNET_YES; /* mark for transmission */ |
2421 | { | 2352 | off += pos->size; |
2422 | pos->do_transmit = GNUNET_YES; /* mark for transmission */ | 2353 | size -= pos->size; |
2423 | off += pos->size; | ||
2424 | size -= pos->size; | ||
2425 | #if DEBUG_CORE > 1 | 2354 | #if DEBUG_CORE > 1 |
2426 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2427 | "Selecting message of size %u for transmission\n", | 2356 | "Selecting message of size %u for transmission\n", |
2428 | (unsigned int) pos->size); | 2357 | (unsigned int) pos->size); |
2429 | #endif | 2358 | #endif |
2430 | } | 2359 | } |
2431 | else | 2360 | else |
2432 | { | 2361 | { |
2433 | #if DEBUG_CORE > 1 | 2362 | #if DEBUG_CORE > 1 |
2434 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2363 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2435 | "Not selecting message of size %u for transmission at this time (maximum is %u)\n", | 2364 | "Not selecting message of size %u for transmission at this time (maximum is %u)\n", |
2436 | (unsigned int) pos->size, | 2365 | (unsigned int) pos->size, size); |
2437 | size); | ||
2438 | #endif | 2366 | #endif |
2439 | pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */ | 2367 | pos->do_transmit = GNUNET_NO; /* mark for not transmitting! */ |
2440 | } | ||
2441 | pos = pos->next; | ||
2442 | } | 2368 | } |
2369 | pos = pos->next; | ||
2370 | } | ||
2443 | #if DEBUG_CORE | 2371 | #if DEBUG_CORE |
2444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2372 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2445 | "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", | 2373 | "Selected %llu/%llu bytes of %u/%u plaintext messages for transmission to `%4s'.\n", |
2446 | (unsigned long long) off, (unsigned long long) tsize, | 2374 | (unsigned long long) off, (unsigned long long) tsize, |
2447 | queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, | 2375 | queue_size, (unsigned int) MAX_PEER_QUEUE_SIZE, |
2448 | GNUNET_i2s (&n->peer)); | 2376 | GNUNET_i2s (&n->peer)); |
2449 | #endif | 2377 | #endif |
2450 | return off; | 2378 | return off; |
2451 | } | 2379 | } |
@@ -2468,29 +2396,28 @@ batch_message (struct Neighbour *n, | |||
2468 | char *buf, | 2396 | char *buf, |
2469 | size_t size, | 2397 | size_t size, |
2470 | struct GNUNET_TIME_Absolute *deadline, | 2398 | struct GNUNET_TIME_Absolute *deadline, |
2471 | struct GNUNET_TIME_Relative *retry_time, | 2399 | struct GNUNET_TIME_Relative *retry_time, unsigned int *priority) |
2472 | unsigned int *priority) | ||
2473 | { | 2400 | { |
2474 | char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 2401 | char ntmb[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
2475 | struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage*) ntmb; | 2402 | struct NotifyTrafficMessage *ntm = (struct NotifyTrafficMessage *) ntmb; |
2476 | struct MessageEntry *pos; | 2403 | struct MessageEntry *pos; |
2477 | struct MessageEntry *prev; | 2404 | struct MessageEntry *prev; |
2478 | struct MessageEntry *next; | 2405 | struct MessageEntry *next; |
2479 | size_t ret; | 2406 | size_t ret; |
2480 | 2407 | ||
2481 | ret = 0; | 2408 | ret = 0; |
2482 | *priority = 0; | 2409 | *priority = 0; |
2483 | *deadline = GNUNET_TIME_UNIT_FOREVER_ABS; | 2410 | *deadline = GNUNET_TIME_UNIT_FOREVER_ABS; |
2484 | *retry_time = GNUNET_TIME_UNIT_FOREVER_REL; | 2411 | *retry_time = GNUNET_TIME_UNIT_FOREVER_REL; |
2485 | if (0 == select_messages (n, size, retry_time)) | 2412 | if (0 == select_messages (n, size, retry_time)) |
2486 | { | 2413 | { |
2487 | #if DEBUG_CORE | 2414 | #if DEBUG_CORE |
2488 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2489 | "No messages selected, will try again in %llu ms\n", | 2416 | "No messages selected, will try again in %llu ms\n", |
2490 | retry_time->rel_value); | 2417 | retry_time->rel_value); |
2491 | #endif | 2418 | #endif |
2492 | return 0; | 2419 | return 0; |
2493 | } | 2420 | } |
2494 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); | 2421 | ntm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND); |
2495 | ntm->ats_count = htonl (0); | 2422 | ntm->ats_count = htonl (0); |
2496 | ntm->ats.type = htonl (0); | 2423 | ntm->ats.type = htonl (0); |
@@ -2499,72 +2426,74 @@ batch_message (struct Neighbour *n, | |||
2499 | pos = n->messages; | 2426 | pos = n->messages; |
2500 | prev = NULL; | 2427 | prev = NULL; |
2501 | while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader))) | 2428 | while ((pos != NULL) && (size >= sizeof (struct GNUNET_MessageHeader))) |
2429 | { | ||
2430 | next = pos->next; | ||
2431 | if (GNUNET_YES == pos->do_transmit) | ||
2502 | { | 2432 | { |
2503 | next = pos->next; | 2433 | GNUNET_assert (pos->size <= size); |
2504 | if (GNUNET_YES == pos->do_transmit) | 2434 | /* do notifications */ |
2505 | { | 2435 | /* FIXME: track if we have *any* client that wants |
2506 | GNUNET_assert (pos->size <= size); | 2436 | * full notifications and only do this if that is |
2507 | /* do notifications */ | 2437 | * actually true */ |
2508 | /* FIXME: track if we have *any* client that wants | 2438 | if (pos->size < |
2509 | full notifications and only do this if that is | 2439 | GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) |
2510 | actually true */ | 2440 | { |
2511 | if (pos->size < GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (struct NotifyTrafficMessage)) | 2441 | memcpy (&ntm[1], &pos[1], pos->size); |
2512 | { | 2442 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + |
2513 | memcpy (&ntm[1], &pos[1], pos->size); | 2443 | sizeof (struct GNUNET_MessageHeader)); |
2514 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + | 2444 | send_to_all_clients (&ntm->header, |
2515 | sizeof (struct GNUNET_MessageHeader)); | 2445 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); |
2516 | send_to_all_clients (&ntm->header, | 2446 | } |
2517 | GNUNET_YES, | 2447 | else |
2518 | GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); | 2448 | { |
2519 | } | 2449 | /* message too large for 'full' notifications, we do at |
2520 | else | 2450 | * least the 'hdr' type */ |
2521 | { | 2451 | memcpy (&ntm[1], &pos[1], sizeof (struct GNUNET_MessageHeader)); |
2522 | /* message too large for 'full' notifications, we do at | 2452 | } |
2523 | least the 'hdr' type */ | 2453 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + |
2524 | memcpy (&ntm[1], | 2454 | pos->size); |
2525 | &pos[1], | 2455 | send_to_all_clients (&ntm->header, |
2526 | sizeof (struct GNUNET_MessageHeader)); | 2456 | GNUNET_YES, GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); |
2527 | } | ||
2528 | ntm->header.size = htons (sizeof (struct NotifyTrafficMessage) + | ||
2529 | pos->size); | ||
2530 | send_to_all_clients (&ntm->header, | ||
2531 | GNUNET_YES, | ||
2532 | GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); | ||
2533 | #if DEBUG_HANDSHAKE | 2457 | #if DEBUG_HANDSHAKE |
2534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2458 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2535 | "Encrypting %u bytes with message of type %u and size %u\n", | 2459 | "Encrypting %u bytes with message of type %u and size %u\n", |
2536 | pos->size, | 2460 | pos->size, |
2537 | (unsigned int) ntohs(((const struct GNUNET_MessageHeader*)&pos[1])->type), | 2461 | (unsigned int) |
2538 | (unsigned int) ntohs(((const struct GNUNET_MessageHeader*)&pos[1])->size)); | 2462 | ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), |
2463 | (unsigned int) | ||
2464 | ntohs (((const struct GNUNET_MessageHeader *) | ||
2465 | &pos[1])->size)); | ||
2539 | #endif | 2466 | #endif |
2540 | /* copy for encrypted transmission */ | 2467 | /* copy for encrypted transmission */ |
2541 | memcpy (&buf[ret], &pos[1], pos->size); | 2468 | memcpy (&buf[ret], &pos[1], pos->size); |
2542 | ret += pos->size; | 2469 | ret += pos->size; |
2543 | size -= pos->size; | 2470 | size -= pos->size; |
2544 | *priority += pos->priority; | 2471 | *priority += pos->priority; |
2545 | #if DEBUG_CORE > 1 | 2472 | #if DEBUG_CORE > 1 |
2546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2473 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2547 | "Adding plaintext message of size %u with deadline %llu ms to batch\n", | 2474 | "Adding plaintext message of size %u with deadline %llu ms to batch\n", |
2548 | (unsigned int) pos->size, | 2475 | (unsigned int) pos->size, |
2549 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); | 2476 | (unsigned long long) |
2477 | GNUNET_TIME_absolute_get_remaining (pos->deadline).rel_value); | ||
2550 | #endif | 2478 | #endif |
2551 | deadline->abs_value = GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); | 2479 | deadline->abs_value = |
2552 | GNUNET_free (pos); | 2480 | GNUNET_MIN (deadline->abs_value, pos->deadline.abs_value); |
2553 | if (prev == NULL) | 2481 | GNUNET_free (pos); |
2554 | n->messages = next; | 2482 | if (prev == NULL) |
2555 | else | 2483 | n->messages = next; |
2556 | prev->next = next; | ||
2557 | } | ||
2558 | else | 2484 | else |
2559 | { | 2485 | prev->next = next; |
2560 | prev = pos; | 2486 | } |
2561 | } | 2487 | else |
2562 | pos = next; | 2488 | { |
2489 | prev = pos; | ||
2563 | } | 2490 | } |
2491 | pos = next; | ||
2492 | } | ||
2564 | #if DEBUG_CORE > 1 | 2493 | #if DEBUG_CORE > 1 |
2565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2494 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2566 | "Deadline for message batch is %llu ms\n", | 2495 | "Deadline for message batch is %llu ms\n", |
2567 | GNUNET_TIME_absolute_get_remaining (*deadline).rel_value); | 2496 | GNUNET_TIME_absolute_get_remaining (*deadline).rel_value); |
2568 | #endif | 2497 | #endif |
2569 | return ret; | 2498 | return ret; |
2570 | } | 2499 | } |
@@ -2590,32 +2519,32 @@ discard_expired_messages (struct Neighbour *n) | |||
2590 | now = GNUNET_TIME_absolute_get (); | 2519 | now = GNUNET_TIME_absolute_get (); |
2591 | prev = NULL; | 2520 | prev = NULL; |
2592 | pos = n->messages; | 2521 | pos = n->messages; |
2593 | while (pos != NULL) | 2522 | while (pos != NULL) |
2523 | { | ||
2524 | next = pos->next; | ||
2525 | delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now); | ||
2526 | if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value) | ||
2594 | { | 2527 | { |
2595 | next = pos->next; | ||
2596 | delta = GNUNET_TIME_absolute_get_difference (pos->deadline, now); | ||
2597 | if (delta.rel_value > PAST_EXPIRATION_DISCARD_TIME.rel_value) | ||
2598 | { | ||
2599 | #if DEBUG_CORE | 2528 | #if DEBUG_CORE |
2600 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2529 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
2601 | "Message is %llu ms past due, discarding.\n", | 2530 | "Message is %llu ms past due, discarding.\n", |
2602 | delta.rel_value); | 2531 | delta.rel_value); |
2603 | #endif | 2532 | #endif |
2604 | if (prev == NULL) | 2533 | if (prev == NULL) |
2605 | n->messages = next; | 2534 | n->messages = next; |
2606 | else | ||
2607 | prev->next = next; | ||
2608 | GNUNET_STATISTICS_update (stats, | ||
2609 | gettext_noop ("# messages discarded (expired prior to transmission)"), | ||
2610 | 1, | ||
2611 | GNUNET_NO); | ||
2612 | disc = GNUNET_YES; | ||
2613 | GNUNET_free (pos); | ||
2614 | } | ||
2615 | else | 2535 | else |
2616 | prev = pos; | 2536 | prev->next = next; |
2617 | pos = next; | 2537 | GNUNET_STATISTICS_update (stats, |
2538 | gettext_noop | ||
2539 | ("# messages discarded (expired prior to transmission)"), | ||
2540 | 1, GNUNET_NO); | ||
2541 | disc = GNUNET_YES; | ||
2542 | GNUNET_free (pos); | ||
2618 | } | 2543 | } |
2544 | else | ||
2545 | prev = pos; | ||
2546 | pos = next; | ||
2547 | } | ||
2619 | if (GNUNET_YES == disc) | 2548 | if (GNUNET_YES == disc) |
2620 | schedule_peer_messages (n); | 2549 | schedule_peer_messages (n); |
2621 | } | 2550 | } |
@@ -2656,12 +2585,11 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2656 | 2585 | ||
2657 | #if DEBUG_CORE | 2586 | #if DEBUG_CORE |
2658 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2659 | "Retrying key transmission to `%4s'\n", | 2588 | "Retrying key transmission to `%4s'\n", GNUNET_i2s (&n->peer)); |
2660 | GNUNET_i2s (&n->peer)); | ||
2661 | #endif | 2589 | #endif |
2662 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 2590 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
2663 | n->set_key_retry_frequency = | 2591 | n->set_key_retry_frequency = |
2664 | GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2); | 2592 | GNUNET_TIME_relative_multiply (n->set_key_retry_frequency, 2); |
2665 | send_key (n); | 2593 | send_key (n); |
2666 | } | 2594 | } |
2667 | 2595 | ||
@@ -2676,7 +2604,7 @@ set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2676 | static void | 2604 | static void |
2677 | process_plaintext_neighbour_queue (struct Neighbour *n) | 2605 | process_plaintext_neighbour_queue (struct Neighbour *n) |
2678 | { | 2606 | { |
2679 | char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct EncryptedMessage)]; /* plaintext */ | 2607 | char pbuf[GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE + sizeof (struct EncryptedMessage)]; /* plaintext */ |
2680 | size_t used; | 2608 | size_t used; |
2681 | struct EncryptedMessage *em; /* encrypted message */ | 2609 | struct EncryptedMessage *em; /* encrypted message */ |
2682 | struct EncryptedMessage *ph; /* plaintext header */ | 2610 | struct EncryptedMessage *ph; /* plaintext header */ |
@@ -2688,66 +2616,66 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2688 | struct GNUNET_CRYPTO_AuthKey auth_key; | 2616 | struct GNUNET_CRYPTO_AuthKey auth_key; |
2689 | 2617 | ||
2690 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) | 2618 | if (n->retry_plaintext_task != GNUNET_SCHEDULER_NO_TASK) |
2691 | { | 2619 | { |
2692 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); | 2620 | GNUNET_SCHEDULER_cancel (n->retry_plaintext_task); |
2693 | n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK; | 2621 | n->retry_plaintext_task = GNUNET_SCHEDULER_NO_TASK; |
2694 | } | 2622 | } |
2695 | switch (n->status) | 2623 | switch (n->status) |
2696 | { | 2624 | { |
2697 | case PEER_STATE_DOWN: | 2625 | case PEER_STATE_DOWN: |
2698 | send_key (n); | 2626 | send_key (n); |
2699 | #if DEBUG_CORE | 2627 | #if DEBUG_CORE |
2700 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2628 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2701 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2629 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2702 | GNUNET_i2s(&n->peer)); | 2630 | GNUNET_i2s (&n->peer)); |
2703 | #endif | 2631 | #endif |
2704 | return; | 2632 | return; |
2705 | case PEER_STATE_KEY_SENT: | 2633 | case PEER_STATE_KEY_SENT: |
2706 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) | 2634 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) |
2707 | n->retry_set_key_task | 2635 | n->retry_set_key_task |
2708 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 2636 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
2709 | &set_key_retry_task, n); | 2637 | &set_key_retry_task, n); |
2710 | #if DEBUG_CORE | 2638 | #if DEBUG_CORE |
2711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2712 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2640 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2713 | GNUNET_i2s(&n->peer)); | 2641 | GNUNET_i2s (&n->peer)); |
2714 | #endif | 2642 | #endif |
2715 | return; | 2643 | return; |
2716 | case PEER_STATE_KEY_RECEIVED: | 2644 | case PEER_STATE_KEY_RECEIVED: |
2717 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) | 2645 | if (n->retry_set_key_task == GNUNET_SCHEDULER_NO_TASK) |
2718 | n->retry_set_key_task | 2646 | n->retry_set_key_task |
2719 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 2647 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
2720 | &set_key_retry_task, n); | 2648 | &set_key_retry_task, n); |
2721 | #if DEBUG_CORE | 2649 | #if DEBUG_CORE |
2722 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2723 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", | 2651 | "Not yet connected to `%4s', deferring processing of plaintext messages.\n", |
2724 | GNUNET_i2s(&n->peer)); | 2652 | GNUNET_i2s (&n->peer)); |
2725 | #endif | 2653 | #endif |
2726 | return; | 2654 | return; |
2727 | case PEER_STATE_KEY_CONFIRMED: | 2655 | case PEER_STATE_KEY_CONFIRMED: |
2728 | /* ready to continue */ | 2656 | /* ready to continue */ |
2729 | break; | 2657 | break; |
2730 | } | 2658 | } |
2731 | discard_expired_messages (n); | 2659 | discard_expired_messages (n); |
2732 | if (n->messages == NULL) | 2660 | if (n->messages == NULL) |
2733 | { | 2661 | { |
2734 | #if DEBUG_CORE | 2662 | #if DEBUG_CORE |
2735 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2663 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2736 | "Plaintext message queue for `%4s' is empty.\n", | 2664 | "Plaintext message queue for `%4s' is empty.\n", |
2737 | GNUNET_i2s(&n->peer)); | 2665 | GNUNET_i2s (&n->peer)); |
2738 | #endif | 2666 | #endif |
2739 | return; /* no pending messages */ | 2667 | return; /* no pending messages */ |
2740 | } | 2668 | } |
2741 | if (n->encrypted_head != NULL) | 2669 | if (n->encrypted_head != NULL) |
2742 | { | 2670 | { |
2743 | #if DEBUG_CORE > 2 | 2671 | #if DEBUG_CORE > 2 |
2744 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2672 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2745 | "Encrypted message queue for `%4s' is still full, delaying plaintext processing.\n", | 2673 | "Encrypted message queue for `%4s' is still full, delaying plaintext processing.\n", |
2746 | GNUNET_i2s(&n->peer)); | 2674 | GNUNET_i2s (&n->peer)); |
2747 | #endif | 2675 | #endif |
2748 | return; /* wait for messages already encrypted to be | 2676 | return; /* wait for messages already encrypted to be |
2749 | processed first! */ | 2677 | * processed first! */ |
2750 | } | 2678 | } |
2751 | ph = (struct EncryptedMessage *) pbuf; | 2679 | ph = (struct EncryptedMessage *) pbuf; |
2752 | deadline = GNUNET_TIME_UNIT_FOREVER_ABS; | 2680 | deadline = GNUNET_TIME_UNIT_FOREVER_ABS; |
2753 | priority = 0; | 2681 | priority = 0; |
@@ -2757,25 +2685,26 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2757 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, | 2685 | GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, |
2758 | &deadline, &retry_time, &priority); | 2686 | &deadline, &retry_time, &priority); |
2759 | if (used == sizeof (struct EncryptedMessage)) | 2687 | if (used == sizeof (struct EncryptedMessage)) |
2760 | { | 2688 | { |
2761 | #if DEBUG_CORE > 1 | 2689 | #if DEBUG_CORE > 1 |
2762 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2690 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2763 | "No messages selected for transmission to `%4s' at this time, will try again later.\n", | 2691 | "No messages selected for transmission to `%4s' at this time, will try again later.\n", |
2764 | GNUNET_i2s(&n->peer)); | 2692 | GNUNET_i2s (&n->peer)); |
2765 | #endif | 2693 | #endif |
2766 | /* no messages selected for sending, try again later... */ | 2694 | /* no messages selected for sending, try again later... */ |
2767 | n->retry_plaintext_task = | 2695 | n->retry_plaintext_task = |
2768 | GNUNET_SCHEDULER_add_delayed (retry_time, | 2696 | GNUNET_SCHEDULER_add_delayed (retry_time, |
2769 | &retry_plaintext_processing, n); | 2697 | &retry_plaintext_processing, n); |
2770 | return; | 2698 | return; |
2771 | } | 2699 | } |
2772 | #if DEBUG_CORE_QUOTA | 2700 | #if DEBUG_CORE_QUOTA |
2773 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2701 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2774 | "Sending %u b/s as new limit to peer `%4s'\n", | 2702 | "Sending %u b/s as new limit to peer `%4s'\n", |
2775 | (unsigned int) ntohl (n->bw_in.value__), | 2703 | (unsigned int) ntohl (n->bw_in.value__), GNUNET_i2s (&n->peer)); |
2776 | GNUNET_i2s (&n->peer)); | ||
2777 | #endif | 2704 | #endif |
2778 | ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | 2705 | ph->iv_seed = |
2706 | htonl (GNUNET_CRYPTO_random_u32 | ||
2707 | (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); | ||
2779 | ph->sequence_number = htonl (++n->last_sequence_number_sent); | 2708 | ph->sequence_number = htonl (++n->last_sequence_number_sent); |
2780 | ph->inbound_bw_limit = n->bw_in; | 2709 | ph->inbound_bw_limit = n->bw_in; |
2781 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); | 2710 | ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); |
@@ -2791,39 +2720,35 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2791 | em->iv_seed = ph->iv_seed; | 2720 | em->iv_seed = ph->iv_seed; |
2792 | derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer); | 2721 | derive_iv (&iv, &n->encrypt_key, ph->iv_seed, &n->peer); |
2793 | /* encrypt */ | 2722 | /* encrypt */ |
2794 | #if DEBUG_HANDSHAKE | 2723 | #if DEBUG_HANDSHAKE |
2795 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2724 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2796 | "Encrypting %u bytes of plaintext messages for `%4s' for transmission in %llums.\n", | 2725 | "Encrypting %u bytes of plaintext messages for `%4s' for transmission in %llums.\n", |
2797 | (unsigned int) used - ENCRYPTED_HEADER_SIZE, | 2726 | (unsigned int) used - ENCRYPTED_HEADER_SIZE, |
2798 | GNUNET_i2s(&n->peer), | 2727 | GNUNET_i2s (&n->peer), |
2799 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (deadline).rel_value); | 2728 | (unsigned long long) |
2729 | GNUNET_TIME_absolute_get_remaining (deadline).rel_value); | ||
2800 | #endif | 2730 | #endif |
2801 | GNUNET_assert (GNUNET_OK == | 2731 | GNUNET_assert (GNUNET_OK == |
2802 | do_encrypt (n, | 2732 | do_encrypt (n, |
2803 | &iv, | 2733 | &iv, |
2804 | &ph->sequence_number, | 2734 | &ph->sequence_number, |
2805 | &em->sequence_number, used - ENCRYPTED_HEADER_SIZE)); | 2735 | &em->sequence_number, |
2806 | derive_auth_key (&auth_key, | 2736 | used - ENCRYPTED_HEADER_SIZE)); |
2807 | &n->encrypt_key, | 2737 | derive_auth_key (&auth_key, &n->encrypt_key, ph->iv_seed, |
2808 | ph->iv_seed, | ||
2809 | n->encrypt_key_created); | 2738 | n->encrypt_key_created); |
2810 | GNUNET_CRYPTO_hmac (&auth_key, | 2739 | GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number, |
2811 | &em->sequence_number, | 2740 | used - ENCRYPTED_HEADER_SIZE, &em->hmac); |
2812 | used - ENCRYPTED_HEADER_SIZE, | ||
2813 | &em->hmac); | ||
2814 | #if DEBUG_HANDSHAKE | 2741 | #if DEBUG_HANDSHAKE |
2815 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2816 | "Authenticated %u bytes of ciphertext %u: `%s'\n", | 2743 | "Authenticated %u bytes of ciphertext %u: `%s'\n", |
2817 | used - ENCRYPTED_HEADER_SIZE, | 2744 | used - ENCRYPTED_HEADER_SIZE, |
2818 | GNUNET_CRYPTO_crc32_n (&em->sequence_number, | 2745 | GNUNET_CRYPTO_crc32_n (&em->sequence_number, |
2819 | used - ENCRYPTED_HEADER_SIZE), | 2746 | used - ENCRYPTED_HEADER_SIZE), |
2820 | GNUNET_h2s (&em->hmac)); | 2747 | GNUNET_h2s (&em->hmac)); |
2821 | #endif | 2748 | #endif |
2822 | /* append to transmission list */ | 2749 | /* append to transmission list */ |
2823 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 2750 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
2824 | n->encrypted_tail, | 2751 | n->encrypted_tail, n->encrypted_tail, me); |
2825 | n->encrypted_tail, | ||
2826 | me); | ||
2827 | process_encrypted_neighbour_queue (n); | 2752 | process_encrypted_neighbour_queue (n); |
2828 | schedule_peer_messages (n); | 2753 | schedule_peer_messages (n); |
2829 | } | 2754 | } |
@@ -2838,7 +2763,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n) | |||
2838 | */ | 2763 | */ |
2839 | static void | 2764 | static void |
2840 | neighbour_quota_update (void *cls, | 2765 | neighbour_quota_update (void *cls, |
2841 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 2766 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
2842 | 2767 | ||
2843 | 2768 | ||
2844 | /** | 2769 | /** |
@@ -2849,12 +2774,10 @@ neighbour_quota_update (void *cls, | |||
2849 | static void | 2774 | static void |
2850 | schedule_quota_update (struct Neighbour *n) | 2775 | schedule_quota_update (struct Neighbour *n) |
2851 | { | 2776 | { |
2852 | GNUNET_assert (n->quota_update_task == | 2777 | GNUNET_assert (n->quota_update_task == GNUNET_SCHEDULER_NO_TASK); |
2853 | GNUNET_SCHEDULER_NO_TASK); | ||
2854 | n->quota_update_task | 2778 | n->quota_update_task |
2855 | = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, | 2779 | = GNUNET_SCHEDULER_add_delayed (QUOTA_UPDATE_FREQUENCY, |
2856 | &neighbour_quota_update, | 2780 | &neighbour_quota_update, n); |
2857 | n); | ||
2858 | } | 2781 | } |
2859 | 2782 | ||
2860 | 2783 | ||
@@ -2872,8 +2795,7 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
2872 | 2795 | ||
2873 | #if DEBUG_CORE | 2796 | #if DEBUG_CORE |
2874 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2797 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2875 | "Creating neighbour entry for peer `%4s'\n", | 2798 | "Creating neighbour entry for peer `%4s'\n", GNUNET_i2s (pid)); |
2876 | GNUNET_i2s (pid)); | ||
2877 | #endif | 2799 | #endif |
2878 | n = GNUNET_malloc (sizeof (struct Neighbour)); | 2800 | n = GNUNET_malloc (sizeof (struct Neighbour)); |
2879 | n->peer = *pid; | 2801 | n->peer = *pid; |
@@ -2888,13 +2810,14 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) | |||
2888 | n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; | 2810 | n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; |
2889 | n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, | 2811 | n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, |
2890 | UINT32_MAX); | 2812 | UINT32_MAX); |
2891 | GNUNET_assert (GNUNET_OK == | 2813 | GNUNET_assert (GNUNET_OK == |
2892 | GNUNET_CONTAINER_multihashmap_put (neighbours, | 2814 | GNUNET_CONTAINER_multihashmap_put (neighbours, |
2893 | &n->peer.hashPubKey, | 2815 | &n->peer.hashPubKey, |
2894 | n, | 2816 | n, |
2895 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2817 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2896 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), | 2818 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), |
2897 | GNUNET_CONTAINER_multihashmap_size (neighbours), GNUNET_NO); | 2819 | GNUNET_CONTAINER_multihashmap_size (neighbours), |
2820 | GNUNET_NO); | ||
2898 | neighbour_quota_update (n, NULL); | 2821 | neighbour_quota_update (n, NULL); |
2899 | consider_free_neighbour (n); | 2822 | consider_free_neighbour (n); |
2900 | return n; | 2823 | return n; |
@@ -2917,7 +2840,7 @@ handle_client_send (void *cls, | |||
2917 | struct Neighbour *n; | 2840 | struct Neighbour *n; |
2918 | struct MessageEntry *prev; | 2841 | struct MessageEntry *prev; |
2919 | struct MessageEntry *pos; | 2842 | struct MessageEntry *pos; |
2920 | struct MessageEntry *e; | 2843 | struct MessageEntry *e; |
2921 | struct MessageEntry *min_prio_entry; | 2844 | struct MessageEntry *min_prio_entry; |
2922 | struct MessageEntry *min_prio_prev; | 2845 | struct MessageEntry *min_prio_prev; |
2923 | unsigned int min_prio; | 2846 | unsigned int min_prio; |
@@ -2927,124 +2850,122 @@ handle_client_send (void *cls, | |||
2927 | msize = ntohs (message->size); | 2850 | msize = ntohs (message->size); |
2928 | if (msize < | 2851 | if (msize < |
2929 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) | 2852 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader)) |
2930 | { | 2853 | { |
2931 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2854 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
2932 | "msize is %u, should be at least %u (in %s:%d)\n", | 2855 | "msize is %u, should be at least %u (in %s:%d)\n", |
2933 | msize, | 2856 | msize, |
2934 | sizeof (struct SendMessage) + sizeof (struct GNUNET_MessageHeader), | 2857 | sizeof (struct SendMessage) + |
2935 | __FILE__, __LINE__); | 2858 | sizeof (struct GNUNET_MessageHeader), __FILE__, __LINE__); |
2936 | GNUNET_break (0); | 2859 | GNUNET_break (0); |
2937 | if (client != NULL) | 2860 | if (client != NULL) |
2938 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2861 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2939 | return; | 2862 | return; |
2940 | } | 2863 | } |
2941 | sm = (const struct SendMessage *) message; | 2864 | sm = (const struct SendMessage *) message; |
2942 | msize -= sizeof (struct SendMessage); | 2865 | msize -= sizeof (struct SendMessage); |
2943 | if (0 == memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 2866 | if (0 == |
2944 | { | 2867 | memcmp (&sm->peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
2945 | /* loopback */ | 2868 | { |
2946 | GNUNET_SERVER_mst_receive (mst, | 2869 | /* loopback */ |
2947 | &self, | 2870 | GNUNET_SERVER_mst_receive (mst, |
2948 | (const char*) &sm[1], | 2871 | &self, |
2949 | msize, | 2872 | (const char *) &sm[1], |
2950 | GNUNET_YES, | 2873 | msize, GNUNET_YES, GNUNET_NO); |
2951 | GNUNET_NO); | 2874 | if (client != NULL) |
2952 | if (client != NULL) | 2875 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2953 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2876 | return; |
2954 | return; | 2877 | } |
2955 | } | ||
2956 | n = find_neighbour (&sm->peer); | 2878 | n = find_neighbour (&sm->peer); |
2957 | if ( (n == NULL) || | 2879 | if ((n == NULL) || |
2958 | (GNUNET_YES != n->is_connected) || | 2880 | (GNUNET_YES != n->is_connected) || |
2959 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 2881 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
2960 | { | 2882 | { |
2961 | /* attempt to send message to peer that is not connected anymore | 2883 | /* attempt to send message to peer that is not connected anymore |
2962 | (can happen due to asynchrony) */ | 2884 | * (can happen due to asynchrony) */ |
2963 | GNUNET_STATISTICS_update (stats, | 2885 | GNUNET_STATISTICS_update (stats, |
2964 | gettext_noop ("# messages discarded (disconnected)"), | 2886 | gettext_noop |
2965 | 1, | 2887 | ("# messages discarded (disconnected)"), 1, |
2966 | GNUNET_NO); | 2888 | GNUNET_NO); |
2967 | if (client != NULL) | 2889 | if (client != NULL) |
2968 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2890 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2969 | return; | 2891 | return; |
2970 | } | 2892 | } |
2971 | #if DEBUG_CORE | 2893 | #if DEBUG_CORE |
2972 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2894 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2973 | "Core received `%s' request, queueing %u bytes of plaintext data for transmission to `%4s'.\n", | 2895 | "Core received `%s' request, queueing %u bytes of plaintext data for transmission to `%4s'.\n", |
2974 | "SEND", | 2896 | "SEND", (unsigned int) msize, GNUNET_i2s (&sm->peer)); |
2975 | (unsigned int) msize, | ||
2976 | GNUNET_i2s (&sm->peer)); | ||
2977 | #endif | 2897 | #endif |
2978 | discard_expired_messages (n); | 2898 | discard_expired_messages (n); |
2979 | /* bound queue size */ | 2899 | /* bound queue size */ |
2980 | /* NOTE: this entire block to bound the queue size should be | 2900 | /* NOTE: this entire block to bound the queue size should be |
2981 | obsolete with the new client-request code and the | 2901 | * obsolete with the new client-request code and the |
2982 | 'schedule_peer_messages' mechanism; we still have this code in | 2902 | * 'schedule_peer_messages' mechanism; we still have this code in |
2983 | here for now as a sanity check for the new mechanmism; | 2903 | * here for now as a sanity check for the new mechanmism; |
2984 | ultimately, we should probably simply reject SEND messages that | 2904 | * ultimately, we should probably simply reject SEND messages that |
2985 | are not 'approved' (or provide a new core API for very unreliable | 2905 | * are not 'approved' (or provide a new core API for very unreliable |
2986 | delivery that always sends with priority 0). Food for thought. */ | 2906 | * delivery that always sends with priority 0). Food for thought. */ |
2987 | min_prio = UINT32_MAX; | 2907 | min_prio = UINT32_MAX; |
2988 | min_prio_entry = NULL; | 2908 | min_prio_entry = NULL; |
2989 | min_prio_prev = NULL; | 2909 | min_prio_prev = NULL; |
2990 | queue_size = 0; | 2910 | queue_size = 0; |
2991 | prev = NULL; | 2911 | prev = NULL; |
2992 | pos = n->messages; | 2912 | pos = n->messages; |
2993 | while (pos != NULL) | 2913 | while (pos != NULL) |
2914 | { | ||
2915 | if (pos->priority <= min_prio) | ||
2994 | { | 2916 | { |
2995 | if (pos->priority <= min_prio) | 2917 | min_prio_entry = pos; |
2996 | { | 2918 | min_prio_prev = prev; |
2997 | min_prio_entry = pos; | 2919 | min_prio = pos->priority; |
2998 | min_prio_prev = prev; | ||
2999 | min_prio = pos->priority; | ||
3000 | } | ||
3001 | queue_size++; | ||
3002 | prev = pos; | ||
3003 | pos = pos->next; | ||
3004 | } | 2920 | } |
2921 | queue_size++; | ||
2922 | prev = pos; | ||
2923 | pos = pos->next; | ||
2924 | } | ||
3005 | if (queue_size >= MAX_PEER_QUEUE_SIZE) | 2925 | if (queue_size >= MAX_PEER_QUEUE_SIZE) |
2926 | { | ||
2927 | /* queue full */ | ||
2928 | if (ntohl (sm->priority) <= min_prio) | ||
3006 | { | 2929 | { |
3007 | /* queue full */ | 2930 | /* discard new entry; this should no longer happen! */ |
3008 | if (ntohl(sm->priority) <= min_prio) | 2931 | GNUNET_break (0); |
3009 | { | ||
3010 | /* discard new entry; this should no longer happen! */ | ||
3011 | GNUNET_break (0); | ||
3012 | #if DEBUG_CORE | ||
3013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3014 | "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", | ||
3015 | queue_size, | ||
3016 | (unsigned int) MAX_PEER_QUEUE_SIZE, | ||
3017 | (unsigned int) msize, | ||
3018 | (unsigned int) ntohs (message->type)); | ||
3019 | #endif | ||
3020 | GNUNET_STATISTICS_update (stats, | ||
3021 | gettext_noop ("# discarded CORE_SEND requests"), | ||
3022 | 1, GNUNET_NO); | ||
3023 | |||
3024 | if (client != NULL) | ||
3025 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
3026 | return; | ||
3027 | } | ||
3028 | GNUNET_assert (min_prio_entry != NULL); | ||
3029 | /* discard "min_prio_entry" */ | ||
3030 | #if DEBUG_CORE | 2932 | #if DEBUG_CORE |
3031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2933 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3032 | "Queue full, discarding existing older request\n"); | 2934 | "Queue full (%u/%u), discarding new request (%u bytes of type %u)\n", |
2935 | queue_size, | ||
2936 | (unsigned int) MAX_PEER_QUEUE_SIZE, | ||
2937 | (unsigned int) msize, (unsigned int) ntohs (message->type)); | ||
3033 | #endif | 2938 | #endif |
3034 | GNUNET_STATISTICS_update (stats, gettext_noop ("# discarded lower priority CORE_SEND requests"), 1, GNUNET_NO); | 2939 | GNUNET_STATISTICS_update (stats, |
3035 | if (min_prio_prev == NULL) | 2940 | gettext_noop ("# discarded CORE_SEND requests"), |
3036 | n->messages = min_prio_entry->next; | 2941 | 1, GNUNET_NO); |
3037 | else | 2942 | |
3038 | min_prio_prev->next = min_prio_entry->next; | 2943 | if (client != NULL) |
3039 | GNUNET_free (min_prio_entry); | 2944 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2945 | return; | ||
3040 | } | 2946 | } |
2947 | GNUNET_assert (min_prio_entry != NULL); | ||
2948 | /* discard "min_prio_entry" */ | ||
2949 | #if DEBUG_CORE | ||
2950 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2951 | "Queue full, discarding existing older request\n"); | ||
2952 | #endif | ||
2953 | GNUNET_STATISTICS_update (stats, | ||
2954 | gettext_noop | ||
2955 | ("# discarded lower priority CORE_SEND requests"), | ||
2956 | 1, GNUNET_NO); | ||
2957 | if (min_prio_prev == NULL) | ||
2958 | n->messages = min_prio_entry->next; | ||
2959 | else | ||
2960 | min_prio_prev->next = min_prio_entry->next; | ||
2961 | GNUNET_free (min_prio_entry); | ||
2962 | } | ||
3041 | 2963 | ||
3042 | #if DEBUG_CORE | 2964 | #if DEBUG_CORE |
3043 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2965 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3044 | "Adding transmission request for `%4s' of size %u to queue\n", | 2966 | "Adding transmission request for `%4s' of size %u to queue\n", |
3045 | GNUNET_i2s (&sm->peer), | 2967 | GNUNET_i2s (&sm->peer), (unsigned int) msize); |
3046 | (unsigned int) msize); | 2968 | #endif |
3047 | #endif | ||
3048 | GNUNET_break (0 == ntohl (sm->reserved)); | 2969 | GNUNET_break (0 == ntohl (sm->reserved)); |
3049 | e = GNUNET_malloc (sizeof (struct MessageEntry) + msize); | 2970 | e = GNUNET_malloc (sizeof (struct MessageEntry) + msize); |
3050 | e->deadline = GNUNET_TIME_absolute_ntoh (sm->deadline); | 2971 | e->deadline = GNUNET_TIME_absolute_ntoh (sm->deadline); |
@@ -3058,10 +2979,10 @@ handle_client_send (void *cls, | |||
3058 | prev = NULL; | 2979 | prev = NULL; |
3059 | pos = n->messages; | 2980 | pos = n->messages; |
3060 | while ((pos != NULL) && (pos->deadline.abs_value < e->deadline.abs_value)) | 2981 | while ((pos != NULL) && (pos->deadline.abs_value < e->deadline.abs_value)) |
3061 | { | 2982 | { |
3062 | prev = pos; | 2983 | prev = pos; |
3063 | pos = pos->next; | 2984 | pos = pos->next; |
3064 | } | 2985 | } |
3065 | if (prev == NULL) | 2986 | if (prev == NULL) |
3066 | n->messages = e; | 2987 | n->messages = e; |
3067 | else | 2988 | else |
@@ -3084,46 +3005,41 @@ handle_client_send (void *cls, | |||
3084 | */ | 3005 | */ |
3085 | static void | 3006 | static void |
3086 | handle_client_request_connect (void *cls, | 3007 | handle_client_request_connect (void *cls, |
3087 | struct GNUNET_SERVER_Client *client, | 3008 | struct GNUNET_SERVER_Client *client, |
3088 | const struct GNUNET_MessageHeader *message) | 3009 | const struct GNUNET_MessageHeader *message) |
3089 | { | 3010 | { |
3090 | const struct ConnectMessage *cm = (const struct ConnectMessage*) message; | 3011 | const struct ConnectMessage *cm = (const struct ConnectMessage *) message; |
3091 | struct Neighbour *n; | 3012 | struct Neighbour *n; |
3092 | 3013 | ||
3093 | if (0 == memcmp (&cm->peer, | 3014 | if (0 == memcmp (&cm->peer, |
3094 | &my_identity, | 3015 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3095 | sizeof (struct GNUNET_PeerIdentity))) | 3016 | { |
3096 | { | 3017 | /* In this case a client has asked us to connect to ourselves, not really an error! */ |
3097 | /* In this case a client has asked us to connect to ourselves, not really an error! */ | 3018 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3098 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3019 | return; |
3099 | return; | 3020 | } |
3100 | } | ||
3101 | GNUNET_break (ntohl (cm->reserved) == 0); | 3021 | GNUNET_break (ntohl (cm->reserved) == 0); |
3102 | #if DEBUG_CORE | 3022 | #if DEBUG_CORE |
3103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3023 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3104 | "Core received `%s' request for `%4s', will try to establish connection\n", | 3024 | "Core received `%s' request for `%4s', will try to establish connection\n", |
3105 | "REQUEST_CONNECT", | 3025 | "REQUEST_CONNECT", GNUNET_i2s (&cm->peer)); |
3106 | GNUNET_i2s (&cm->peer)); | ||
3107 | #endif | 3026 | #endif |
3108 | GNUNET_STATISTICS_update (stats, | 3027 | GNUNET_STATISTICS_update (stats, |
3109 | gettext_noop ("# connection requests received"), | 3028 | gettext_noop ("# connection requests received"), |
3110 | 1, | 3029 | 1, GNUNET_NO); |
3111 | GNUNET_NO); | ||
3112 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 3030 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3113 | n = find_neighbour (&cm->peer); | 3031 | n = find_neighbour (&cm->peer); |
3114 | if ( (n == NULL) || | 3032 | if ((n == NULL) || (GNUNET_YES != n->is_connected)) |
3115 | (GNUNET_YES != n->is_connected) ) | 3033 | { |
3116 | { | 3034 | GNUNET_TRANSPORT_try_connect (transport, &cm->peer); |
3117 | GNUNET_TRANSPORT_try_connect (transport, | 3035 | } |
3118 | &cm->peer); | ||
3119 | } | ||
3120 | else | 3036 | else |
3121 | { | 3037 | { |
3122 | GNUNET_STATISTICS_update (stats, | 3038 | GNUNET_STATISTICS_update (stats, |
3123 | gettext_noop ("# connection requests ignored (already connected)"), | 3039 | gettext_noop |
3124 | 1, | 3040 | ("# connection requests ignored (already connected)"), |
3125 | GNUNET_NO); | 3041 | 1, GNUNET_NO); |
3126 | } | 3042 | } |
3127 | } | 3043 | } |
3128 | 3044 | ||
3129 | 3045 | ||
@@ -3153,81 +3069,78 @@ process_hello_retry_send_key (void *cls, | |||
3153 | } | 3069 | } |
3154 | 3070 | ||
3155 | if (peer == NULL) | 3071 | if (peer == NULL) |
3156 | { | 3072 | { |
3157 | #if DEBUG_CORE | 3073 | #if DEBUG_CORE |
3158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3074 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3159 | "Entered `%s' and `%s' is NULL!\n", | 3075 | "Entered `%s' and `%s' is NULL!\n", |
3160 | "process_hello_retry_send_key", | 3076 | "process_hello_retry_send_key", "peer"); |
3161 | "peer"); | ||
3162 | #endif | 3077 | #endif |
3163 | n->pitr = NULL; | 3078 | n->pitr = NULL; |
3164 | if (n->public_key != NULL) | 3079 | if (n->public_key != NULL) |
3165 | { | 3080 | { |
3166 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3081 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3167 | { | 3082 | { |
3168 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3083 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3169 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3084 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3170 | } | 3085 | } |
3171 | GNUNET_STATISTICS_update (stats, | 3086 | GNUNET_STATISTICS_update (stats, |
3172 | gettext_noop ("# SET_KEY messages deferred (need public key)"), | 3087 | gettext_noop |
3173 | -1, | 3088 | ("# SET_KEY messages deferred (need public key)"), |
3174 | GNUNET_NO); | 3089 | -1, GNUNET_NO); |
3175 | send_key (n); | 3090 | send_key (n); |
3176 | } | 3091 | } |
3177 | else | 3092 | else |
3178 | { | 3093 | { |
3179 | #if DEBUG_CORE | 3094 | #if DEBUG_CORE |
3180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3095 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3181 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", | 3096 | "Failed to obtain public key for peer `%4s', delaying processing of SET_KEY\n", |
3182 | GNUNET_i2s (&n->peer)); | 3097 | GNUNET_i2s (&n->peer)); |
3183 | #endif | 3098 | #endif |
3184 | GNUNET_STATISTICS_update (stats, | 3099 | GNUNET_STATISTICS_update (stats, |
3185 | gettext_noop ("# Delayed connecting due to lack of public key"), | 3100 | gettext_noop |
3186 | 1, | 3101 | ("# Delayed connecting due to lack of public key"), |
3187 | GNUNET_NO); | 3102 | 1, GNUNET_NO); |
3188 | if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) | 3103 | if (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) |
3189 | n->retry_set_key_task | 3104 | n->retry_set_key_task |
3190 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 3105 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
3191 | &set_key_retry_task, n); | 3106 | &set_key_retry_task, n); |
3192 | } | ||
3193 | return; | ||
3194 | } | 3107 | } |
3108 | return; | ||
3109 | } | ||
3195 | 3110 | ||
3196 | #if DEBUG_CORE | 3111 | #if DEBUG_CORE |
3197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3198 | "Entered `%s' for peer `%4s'\n", | 3113 | "Entered `%s' for peer `%4s'\n", |
3199 | "process_hello_retry_send_key", | 3114 | "process_hello_retry_send_key", GNUNET_i2s (peer)); |
3200 | GNUNET_i2s (peer)); | ||
3201 | #endif | 3115 | #endif |
3202 | if (n->public_key != NULL) | 3116 | if (n->public_key != NULL) |
3203 | { | 3117 | { |
3204 | /* already have public key, why are we here? */ | 3118 | /* already have public key, why are we here? */ |
3205 | GNUNET_break (0); | 3119 | GNUNET_break (0); |
3206 | return; | 3120 | return; |
3207 | } | 3121 | } |
3208 | 3122 | ||
3209 | #if DEBUG_CORE | 3123 | #if DEBUG_CORE |
3210 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3124 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3211 | "Received new `%s' message for `%4s', initiating key exchange.\n", | 3125 | "Received new `%s' message for `%4s', initiating key exchange.\n", |
3212 | "HELLO", | 3126 | "HELLO", GNUNET_i2s (peer)); |
3213 | GNUNET_i2s (peer)); | ||
3214 | #endif | 3127 | #endif |
3215 | n->public_key = | 3128 | n->public_key = |
3216 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 3129 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
3217 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) | 3130 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) |
3218 | { | 3131 | { |
3219 | GNUNET_STATISTICS_update (stats, | 3132 | GNUNET_STATISTICS_update (stats, |
3220 | gettext_noop ("# Error extracting public key from HELLO"), | 3133 | gettext_noop |
3221 | 1, | 3134 | ("# Error extracting public key from HELLO"), 1, |
3222 | GNUNET_NO); | 3135 | GNUNET_NO); |
3223 | GNUNET_free (n->public_key); | 3136 | GNUNET_free (n->public_key); |
3224 | n->public_key = NULL; | 3137 | n->public_key = NULL; |
3225 | #if DEBUG_CORE | 3138 | #if DEBUG_CORE |
3226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3227 | "GNUNET_HELLO_get_key returned awfully\n"); | 3140 | "GNUNET_HELLO_get_key returned awfully\n"); |
3228 | #endif | 3141 | #endif |
3229 | return; | 3142 | return; |
3230 | } | 3143 | } |
3231 | } | 3144 | } |
3232 | 3145 | ||
3233 | 3146 | ||
@@ -3247,121 +3160,115 @@ send_key (struct Neighbour *n) | |||
3247 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 3160 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
3248 | 3161 | ||
3249 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3162 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3250 | { | 3163 | { |
3251 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3164 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3252 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3165 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3253 | } | 3166 | } |
3254 | if (n->pitr != NULL) | 3167 | if (n->pitr != NULL) |
3255 | { | 3168 | { |
3256 | #if DEBUG_CORE | 3169 | #if DEBUG_CORE |
3257 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3258 | "Key exchange in progress with `%4s'.\n", | 3171 | "Key exchange in progress with `%4s'.\n", |
3259 | GNUNET_i2s (&n->peer)); | 3172 | GNUNET_i2s (&n->peer)); |
3260 | #endif | 3173 | #endif |
3261 | return; /* already in progress */ | 3174 | return; /* already in progress */ |
3262 | } | 3175 | } |
3263 | if (GNUNET_YES != n->is_connected) | 3176 | if (GNUNET_YES != n->is_connected) |
3264 | { | 3177 | { |
3265 | GNUNET_STATISTICS_update (stats, | 3178 | GNUNET_STATISTICS_update (stats, |
3266 | gettext_noop ("# Asking transport to connect (for SET_KEY)"), | 3179 | gettext_noop |
3267 | 1, | 3180 | ("# Asking transport to connect (for SET_KEY)"), |
3268 | GNUNET_NO); | 3181 | 1, GNUNET_NO); |
3269 | GNUNET_TRANSPORT_try_connect (transport, | 3182 | GNUNET_TRANSPORT_try_connect (transport, &n->peer); |
3270 | &n->peer); | 3183 | return; |
3271 | return; | 3184 | } |
3272 | } | ||
3273 | #if DEBUG_CORE | 3185 | #if DEBUG_CORE |
3274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3186 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3275 | "Asked to perform key exchange with `%4s'.\n", | 3187 | "Asked to perform key exchange with `%4s'.\n", |
3276 | GNUNET_i2s (&n->peer)); | 3188 | GNUNET_i2s (&n->peer)); |
3277 | #endif | 3189 | #endif |
3278 | if (n->public_key == NULL) | 3190 | if (n->public_key == NULL) |
3279 | { | 3191 | { |
3280 | /* lookup n's public key, then try again */ | 3192 | /* lookup n's public key, then try again */ |
3281 | #if DEBUG_CORE | 3193 | #if DEBUG_CORE |
3282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3194 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3283 | "Lacking public key for `%4s', trying to obtain one (send_key).\n", | 3195 | "Lacking public key for `%4s', trying to obtain one (send_key).\n", |
3284 | GNUNET_i2s (&n->peer)); | 3196 | GNUNET_i2s (&n->peer)); |
3285 | #endif | 3197 | #endif |
3286 | GNUNET_assert (n->pitr == NULL); | 3198 | GNUNET_assert (n->pitr == NULL); |
3287 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | 3199 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, |
3288 | &n->peer, | 3200 | &n->peer, |
3289 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20), | 3201 | GNUNET_TIME_relative_multiply |
3290 | &process_hello_retry_send_key, n); | 3202 | (GNUNET_TIME_UNIT_SECONDS, 20), |
3291 | return; | 3203 | &process_hello_retry_send_key, n); |
3292 | } | 3204 | return; |
3205 | } | ||
3293 | pos = n->encrypted_head; | 3206 | pos = n->encrypted_head; |
3294 | while (pos != NULL) | 3207 | while (pos != NULL) |
3208 | { | ||
3209 | if (GNUNET_YES == pos->is_setkey) | ||
3295 | { | 3210 | { |
3296 | if (GNUNET_YES == pos->is_setkey) | 3211 | if (pos->sender_status == n->status) |
3297 | { | 3212 | { |
3298 | if (pos->sender_status == n->status) | ||
3299 | { | ||
3300 | #if DEBUG_CORE | 3213 | #if DEBUG_CORE |
3301 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3214 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3302 | "`%s' message for `%4s' queued already\n", | 3215 | "`%s' message for `%4s' queued already\n", |
3303 | "SET_KEY", | 3216 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3304 | GNUNET_i2s (&n->peer)); | ||
3305 | #endif | 3217 | #endif |
3306 | goto trigger_processing; | 3218 | goto trigger_processing; |
3307 | } | 3219 | } |
3308 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, | 3220 | GNUNET_CONTAINER_DLL_remove (n->encrypted_head, n->encrypted_tail, pos); |
3309 | n->encrypted_tail, | 3221 | GNUNET_free (pos); |
3310 | pos); | ||
3311 | GNUNET_free (pos); | ||
3312 | #if DEBUG_CORE | 3222 | #if DEBUG_CORE |
3313 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3314 | "Removing queued `%s' message for `%4s', will create a new one\n", | 3224 | "Removing queued `%s' message for `%4s', will create a new one\n", |
3315 | "SET_KEY", | 3225 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3316 | GNUNET_i2s (&n->peer)); | ||
3317 | #endif | 3226 | #endif |
3318 | break; | 3227 | break; |
3319 | } | ||
3320 | pos = pos->next; | ||
3321 | } | 3228 | } |
3229 | pos = pos->next; | ||
3230 | } | ||
3322 | 3231 | ||
3323 | /* update status */ | 3232 | /* update status */ |
3324 | switch (n->status) | 3233 | switch (n->status) |
3325 | { | 3234 | { |
3326 | case PEER_STATE_DOWN: | 3235 | case PEER_STATE_DOWN: |
3327 | n->status = PEER_STATE_KEY_SENT; | 3236 | n->status = PEER_STATE_KEY_SENT; |
3328 | break; | 3237 | break; |
3329 | case PEER_STATE_KEY_SENT: | 3238 | case PEER_STATE_KEY_SENT: |
3330 | break; | 3239 | break; |
3331 | case PEER_STATE_KEY_RECEIVED: | 3240 | case PEER_STATE_KEY_RECEIVED: |
3332 | break; | 3241 | break; |
3333 | case PEER_STATE_KEY_CONFIRMED: | 3242 | case PEER_STATE_KEY_CONFIRMED: |
3334 | break; | 3243 | break; |
3335 | default: | 3244 | default: |
3336 | GNUNET_break (0); | 3245 | GNUNET_break (0); |
3337 | break; | 3246 | break; |
3338 | } | 3247 | } |
3339 | 3248 | ||
3340 | 3249 | ||
3341 | /* first, set key message */ | 3250 | /* first, set key message */ |
3342 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | 3251 | me = GNUNET_malloc (sizeof (struct MessageEntry) + |
3343 | sizeof (struct SetKeyMessage) + | 3252 | sizeof (struct SetKeyMessage) + |
3344 | sizeof (struct PingMessage)); | 3253 | sizeof (struct PingMessage)); |
3345 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); | 3254 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_SET_KEY_DELAY); |
3346 | me->priority = SET_KEY_PRIORITY; | 3255 | me->priority = SET_KEY_PRIORITY; |
3347 | me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage); | 3256 | me->size = sizeof (struct SetKeyMessage) + sizeof (struct PingMessage); |
3348 | me->is_setkey = GNUNET_YES; | 3257 | me->is_setkey = GNUNET_YES; |
3349 | me->got_slack = GNUNET_YES; /* do not defer this one! */ | 3258 | me->got_slack = GNUNET_YES; /* do not defer this one! */ |
3350 | me->sender_status = n->status; | 3259 | me->sender_status = n->status; |
3351 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 3260 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
3352 | n->encrypted_tail, | 3261 | n->encrypted_tail, n->encrypted_tail, me); |
3353 | n->encrypted_tail, | ||
3354 | me); | ||
3355 | sm = (struct SetKeyMessage *) &me[1]; | 3262 | sm = (struct SetKeyMessage *) &me[1]; |
3356 | sm->header.size = htons (sizeof (struct SetKeyMessage)); | 3263 | sm->header.size = htons (sizeof (struct SetKeyMessage)); |
3357 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); | 3264 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_SET_KEY); |
3358 | sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? | 3265 | sm->sender_status = htonl ((int32_t) ((n->status == PEER_STATE_DOWN) ? |
3359 | PEER_STATE_KEY_SENT : n->status)); | 3266 | PEER_STATE_KEY_SENT : n->status)); |
3360 | sm->purpose.size = | 3267 | sm->purpose.size = |
3361 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 3268 | htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
3362 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 3269 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
3363 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + | 3270 | sizeof (struct GNUNET_CRYPTO_RsaEncryptedData) + |
3364 | sizeof (struct GNUNET_PeerIdentity)); | 3271 | sizeof (struct GNUNET_PeerIdentity)); |
3365 | sm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); | 3272 | sm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY); |
3366 | sm->creation_time = GNUNET_TIME_absolute_hton (n->encrypt_key_created); | 3273 | sm->creation_time = GNUNET_TIME_absolute_hton (n->encrypt_key_created); |
3367 | sm->target = n->peer; | 3274 | sm->target = n->peer; |
@@ -3369,15 +3276,15 @@ send_key (struct Neighbour *n) | |||
3369 | GNUNET_CRYPTO_rsa_encrypt (&n->encrypt_key, | 3276 | GNUNET_CRYPTO_rsa_encrypt (&n->encrypt_key, |
3370 | sizeof (struct | 3277 | sizeof (struct |
3371 | GNUNET_CRYPTO_AesSessionKey), | 3278 | GNUNET_CRYPTO_AesSessionKey), |
3372 | n->public_key, | 3279 | n->public_key, &sm->encrypted_key)); |
3373 | &sm->encrypted_key)); | ||
3374 | GNUNET_assert (GNUNET_OK == | 3280 | GNUNET_assert (GNUNET_OK == |
3375 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, | 3281 | GNUNET_CRYPTO_rsa_sign (my_private_key, &sm->purpose, |
3376 | &sm->signature)); | 3282 | &sm->signature)); |
3377 | pm = (struct PingMessage *) &sm[1]; | 3283 | pm = (struct PingMessage *) &sm[1]; |
3378 | pm->header.size = htons (sizeof (struct PingMessage)); | 3284 | pm->header.size = htons (sizeof (struct PingMessage)); |
3379 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); | 3285 | pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); |
3380 | pm->iv_seed = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 3286 | pm->iv_seed = |
3287 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | ||
3381 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); | 3288 | derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); |
3382 | pp.challenge = n->ping_challenge; | 3289 | pp.challenge = n->ping_challenge; |
3383 | pp.target = n->peer; | 3290 | pp.target = n->peer; |
@@ -3385,11 +3292,10 @@ send_key (struct Neighbour *n) | |||
3385 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3386 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", | 3293 | "Encrypting `%s' and `%s' messages with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", |
3387 | "SET_KEY", "PING", | 3294 | "SET_KEY", "PING", |
3388 | (unsigned int) n->ping_challenge, | 3295 | (unsigned int) n->ping_challenge, |
3389 | GNUNET_i2s (&n->peer), | 3296 | GNUNET_i2s (&n->peer), |
3390 | (unsigned int) n->encrypt_key.crc32, | 3297 | (unsigned int) n->encrypt_key.crc32, |
3391 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3298 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), pm->iv_seed); |
3392 | pm->iv_seed); | ||
3393 | #endif | 3299 | #endif |
3394 | do_encrypt (n, | 3300 | do_encrypt (n, |
3395 | &iv, | 3301 | &iv, |
@@ -3397,24 +3303,25 @@ send_key (struct Neighbour *n) | |||
3397 | &pm->target, | 3303 | &pm->target, |
3398 | sizeof (struct PingMessage) - | 3304 | sizeof (struct PingMessage) - |
3399 | ((void *) &pm->target - (void *) pm)); | 3305 | ((void *) &pm->target - (void *) pm)); |
3400 | GNUNET_STATISTICS_update (stats, | 3306 | GNUNET_STATISTICS_update (stats, |
3401 | gettext_noop ("# SET_KEY and PING messages created"), | 3307 | gettext_noop |
3402 | 1, | 3308 | ("# SET_KEY and PING messages created"), 1, |
3403 | GNUNET_NO); | 3309 | GNUNET_NO); |
3404 | #if DEBUG_CORE | 3310 | #if DEBUG_CORE |
3405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3311 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3406 | "Have %llu ms left for `%s' transmission.\n", | 3312 | "Have %llu ms left for `%s' transmission.\n", |
3407 | (unsigned long long) GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, | 3313 | (unsigned long long) |
3408 | "SET_KEY"); | 3314 | GNUNET_TIME_absolute_get_remaining (me->deadline).rel_value, |
3315 | "SET_KEY"); | ||
3409 | #endif | 3316 | #endif |
3410 | trigger_processing: | 3317 | trigger_processing: |
3411 | /* trigger queue processing */ | 3318 | /* trigger queue processing */ |
3412 | process_encrypted_neighbour_queue (n); | 3319 | process_encrypted_neighbour_queue (n); |
3413 | if ( (n->status != PEER_STATE_KEY_CONFIRMED) && | 3320 | if ((n->status != PEER_STATE_KEY_CONFIRMED) && |
3414 | (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task) ) | 3321 | (GNUNET_SCHEDULER_NO_TASK == n->retry_set_key_task)) |
3415 | n->retry_set_key_task | 3322 | n->retry_set_key_task |
3416 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, | 3323 | = GNUNET_SCHEDULER_add_delayed (n->set_key_retry_frequency, |
3417 | &set_key_retry_task, n); | 3324 | &set_key_retry_task, n); |
3418 | } | 3325 | } |
3419 | 3326 | ||
3420 | 3327 | ||
@@ -3429,9 +3336,9 @@ send_key (struct Neighbour *n) | |||
3429 | */ | 3336 | */ |
3430 | static void | 3337 | static void |
3431 | handle_set_key (struct Neighbour *n, | 3338 | handle_set_key (struct Neighbour *n, |
3432 | const struct SetKeyMessage *m, | 3339 | const struct SetKeyMessage *m, |
3433 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3340 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3434 | uint32_t ats_count); | 3341 | uint32_t ats_count); |
3435 | 3342 | ||
3436 | 3343 | ||
3437 | 3344 | ||
@@ -3462,40 +3369,38 @@ process_hello_retry_handle_set_key (void *cls, | |||
3462 | } | 3369 | } |
3463 | 3370 | ||
3464 | if (peer == NULL) | 3371 | if (peer == NULL) |
3372 | { | ||
3373 | n->skm = NULL; | ||
3374 | n->pitr = NULL; | ||
3375 | if (n->public_key != NULL) | ||
3465 | { | 3376 | { |
3466 | n->skm = NULL; | ||
3467 | n->pitr = NULL; | ||
3468 | if (n->public_key != NULL) | ||
3469 | { | ||
3470 | #if DEBUG_CORE | 3377 | #if DEBUG_CORE |
3471 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3378 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3472 | "Received `%s' for `%4s', continuing processing of `%s' message.\n", | 3379 | "Received `%s' for `%4s', continuing processing of `%s' message.\n", |
3473 | "HELLO", | 3380 | "HELLO", GNUNET_i2s (&n->peer), "SET_KEY"); |
3474 | GNUNET_i2s (&n->peer), | ||
3475 | "SET_KEY"); | ||
3476 | #endif | 3381 | #endif |
3477 | handle_set_key (n, sm, NULL, 0); | 3382 | handle_set_key (n, sm, NULL, 0); |
3478 | } | 3383 | } |
3479 | else | 3384 | else |
3480 | { | 3385 | { |
3481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3386 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3482 | _("Ignoring `%s' message due to lack of public key for peer `%4s' (failed to obtain one).\n"), | 3387 | _ |
3483 | "SET_KEY", | 3388 | ("Ignoring `%s' message due to lack of public key for peer `%4s' (failed to obtain one).\n"), |
3484 | GNUNET_i2s (&n->peer)); | 3389 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3485 | } | ||
3486 | GNUNET_free (sm); | ||
3487 | return; | ||
3488 | } | 3390 | } |
3391 | GNUNET_free (sm); | ||
3392 | return; | ||
3393 | } | ||
3489 | if (n->public_key != NULL) | 3394 | if (n->public_key != NULL) |
3490 | return; /* multiple HELLOs match!? */ | 3395 | return; /* multiple HELLOs match!? */ |
3491 | n->public_key = | 3396 | n->public_key = |
3492 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | 3397 | GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
3493 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) | 3398 | if (GNUNET_OK != GNUNET_HELLO_get_key (hello, n->public_key)) |
3494 | { | 3399 | { |
3495 | GNUNET_break_op (0); | 3400 | GNUNET_break_op (0); |
3496 | GNUNET_free (n->public_key); | 3401 | GNUNET_free (n->public_key); |
3497 | n->public_key = NULL; | 3402 | n->public_key = NULL; |
3498 | } | 3403 | } |
3499 | } | 3404 | } |
3500 | 3405 | ||
3501 | 3406 | ||
@@ -3509,8 +3414,8 @@ process_hello_retry_handle_set_key (void *cls, | |||
3509 | */ | 3414 | */ |
3510 | static void | 3415 | static void |
3511 | update_neighbour_performance (struct Neighbour *n, | 3416 | update_neighbour_performance (struct Neighbour *n, |
3512 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3417 | const struct GNUNET_TRANSPORT_ATS_Information |
3513 | uint32_t ats_count) | 3418 | *ats, uint32_t ats_count) |
3514 | { | 3419 | { |
3515 | uint32_t i; | 3420 | uint32_t i; |
3516 | unsigned int j; | 3421 | unsigned int j; |
@@ -3518,22 +3423,20 @@ update_neighbour_performance (struct Neighbour *n, | |||
3518 | if (ats_count == 0) | 3423 | if (ats_count == 0) |
3519 | return; | 3424 | return; |
3520 | for (i = 0; i < ats_count; i++) | 3425 | for (i = 0; i < ats_count; i++) |
3426 | { | ||
3427 | for (j = 0; j < n->ats_count; j++) | ||
3521 | { | 3428 | { |
3522 | for (j=0;j < n->ats_count; j++) | 3429 | if (n->ats[j].type == ats[i].type) |
3523 | { | 3430 | { |
3524 | if (n->ats[j].type == ats[i].type) | 3431 | n->ats[j].value = ats[i].value; |
3525 | { | 3432 | break; |
3526 | n->ats[j].value = ats[i].value; | 3433 | } |
3527 | break; | ||
3528 | } | ||
3529 | } | ||
3530 | if (j == n->ats_count) | ||
3531 | { | ||
3532 | GNUNET_array_append (n->ats, | ||
3533 | n->ats_count, | ||
3534 | ats[i]); | ||
3535 | } | ||
3536 | } | 3434 | } |
3435 | if (j == n->ats_count) | ||
3436 | { | ||
3437 | GNUNET_array_append (n->ats, n->ats_count, ats[i]); | ||
3438 | } | ||
3439 | } | ||
3537 | } | 3440 | } |
3538 | 3441 | ||
3539 | 3442 | ||
@@ -3548,9 +3451,9 @@ update_neighbour_performance (struct Neighbour *n, | |||
3548 | */ | 3451 | */ |
3549 | static void | 3452 | static void |
3550 | handle_ping (struct Neighbour *n, | 3453 | handle_ping (struct Neighbour *n, |
3551 | const struct PingMessage *m, | 3454 | const struct PingMessage *m, |
3552 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3455 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3553 | uint32_t ats_count) | 3456 | uint32_t ats_count) |
3554 | { | 3457 | { |
3555 | struct PingMessage t; | 3458 | struct PingMessage t; |
3556 | struct PongMessage tx; | 3459 | struct PongMessage tx; |
@@ -3578,37 +3481,32 @@ handle_ping (struct Neighbour *n, | |||
3578 | "PING", | 3481 | "PING", |
3579 | GNUNET_i2s (&t.target), | 3482 | GNUNET_i2s (&t.target), |
3580 | (unsigned int) t.challenge, | 3483 | (unsigned int) t.challenge, |
3581 | (unsigned int) n->decrypt_key.crc32, | 3484 | (unsigned int) n->decrypt_key.crc32, |
3582 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3485 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); |
3583 | m->iv_seed); | ||
3584 | #endif | 3486 | #endif |
3585 | GNUNET_STATISTICS_update (stats, | 3487 | GNUNET_STATISTICS_update (stats, |
3586 | gettext_noop ("# PING messages decrypted"), | 3488 | gettext_noop ("# PING messages decrypted"), |
3587 | 1, | 3489 | 1, GNUNET_NO); |
3588 | GNUNET_NO); | ||
3589 | if (0 != memcmp (&t.target, | 3490 | if (0 != memcmp (&t.target, |
3590 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 3491 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3591 | { | 3492 | { |
3592 | char sender[9]; | 3493 | char sender[9]; |
3593 | char peer[9]; | 3494 | char peer[9]; |
3594 | 3495 | ||
3595 | GNUNET_snprintf(sender, sizeof (sender), "%8s", GNUNET_i2s (&n->peer)); | 3496 | GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&n->peer)); |
3596 | GNUNET_snprintf(peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); | 3497 | GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target)); |
3597 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3598 | _("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), | 3499 | _ |
3599 | sender, | 3500 | ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"), |
3600 | GNUNET_i2s (&my_identity), | 3501 | sender, GNUNET_i2s (&my_identity), peer); |
3601 | peer); | 3502 | GNUNET_break_op (0); |
3602 | GNUNET_break_op (0); | 3503 | return; |
3603 | return; | 3504 | } |
3604 | } | ||
3605 | update_neighbour_performance (n, ats, ats_count); | 3505 | update_neighbour_performance (n, ats, ats_count); |
3606 | me = GNUNET_malloc (sizeof (struct MessageEntry) + | 3506 | me = GNUNET_malloc (sizeof (struct MessageEntry) + |
3607 | sizeof (struct PongMessage)); | 3507 | sizeof (struct PongMessage)); |
3608 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, | 3508 | GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, |
3609 | n->encrypted_tail, | 3509 | n->encrypted_tail, n->encrypted_tail, me); |
3610 | n->encrypted_tail, | ||
3611 | me); | ||
3612 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); | 3510 | me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PONG_DELAY); |
3613 | me->priority = PONG_PRIORITY; | 3511 | me->priority = PONG_PRIORITY; |
3614 | me->size = sizeof (struct PongMessage); | 3512 | me->size = sizeof (struct PongMessage); |
@@ -3618,7 +3516,8 @@ handle_ping (struct Neighbour *n, | |||
3618 | tp = (struct PongMessage *) &me[1]; | 3516 | tp = (struct PongMessage *) &me[1]; |
3619 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); | 3517 | tp->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG); |
3620 | tp->header.size = htons (sizeof (struct PongMessage)); | 3518 | tp->header.size = htons (sizeof (struct PongMessage)); |
3621 | tp->iv_seed = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | 3519 | tp->iv_seed = |
3520 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); | ||
3622 | derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); | 3521 | derive_pong_iv (&iv, &n->encrypt_key, tp->iv_seed, t.challenge, &n->peer); |
3623 | do_encrypt (n, | 3522 | do_encrypt (n, |
3624 | &iv, | 3523 | &iv, |
@@ -3626,18 +3525,16 @@ handle_ping (struct Neighbour *n, | |||
3626 | &tp->challenge, | 3525 | &tp->challenge, |
3627 | sizeof (struct PongMessage) - | 3526 | sizeof (struct PongMessage) - |
3628 | ((void *) &tp->challenge - (void *) tp)); | 3527 | ((void *) &tp->challenge - (void *) tp)); |
3629 | GNUNET_STATISTICS_update (stats, | 3528 | GNUNET_STATISTICS_update (stats, |
3630 | gettext_noop ("# PONG messages created"), | 3529 | gettext_noop ("# PONG messages created"), |
3631 | 1, | 3530 | 1, GNUNET_NO); |
3632 | GNUNET_NO); | ||
3633 | #if DEBUG_HANDSHAKE | 3531 | #if DEBUG_HANDSHAKE |
3634 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3532 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3635 | "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", | 3533 | "Encrypting `%s' with challenge %u using key %u, IV %u (salt %u)\n", |
3636 | "PONG", | 3534 | "PONG", |
3637 | (unsigned int) t.challenge, | 3535 | (unsigned int) t.challenge, |
3638 | (unsigned int) n->encrypt_key.crc32, | 3536 | (unsigned int) n->encrypt_key.crc32, |
3639 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3537 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), tp->iv_seed); |
3640 | tp->iv_seed); | ||
3641 | #endif | 3538 | #endif |
3642 | /* trigger queue processing */ | 3539 | /* trigger queue processing */ |
3643 | process_encrypted_neighbour_queue (n); | 3540 | process_encrypted_neighbour_queue (n); |
@@ -3653,10 +3550,10 @@ handle_ping (struct Neighbour *n, | |||
3653 | * @param ats_count number of entries in ats (excluding 0-termination) | 3550 | * @param ats_count number of entries in ats (excluding 0-termination) |
3654 | */ | 3551 | */ |
3655 | static void | 3552 | static void |
3656 | handle_pong (struct Neighbour *n, | 3553 | handle_pong (struct Neighbour *n, |
3657 | const struct PongMessage *m, | 3554 | const struct PongMessage *m, |
3658 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3555 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3659 | uint32_t ats_count) | 3556 | uint32_t ats_count) |
3660 | { | 3557 | { |
3661 | struct PongMessage t; | 3558 | struct PongMessage t; |
3662 | struct ConnectNotifyMessage *cnm; | 3559 | struct ConnectNotifyMessage *cnm; |
@@ -3673,7 +3570,7 @@ handle_pong (struct Neighbour *n, | |||
3673 | /* mark as garbage, just to be sure */ | 3570 | /* mark as garbage, just to be sure */ |
3674 | memset (&t, 255, sizeof (t)); | 3571 | memset (&t, 255, sizeof (t)); |
3675 | derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, | 3572 | derive_pong_iv (&iv, &n->decrypt_key, m->iv_seed, n->ping_challenge, |
3676 | &my_identity); | 3573 | &my_identity); |
3677 | if (GNUNET_OK != | 3574 | if (GNUNET_OK != |
3678 | do_decrypt (n, | 3575 | do_decrypt (n, |
3679 | &iv, | 3576 | &iv, |
@@ -3681,14 +3578,13 @@ handle_pong (struct Neighbour *n, | |||
3681 | &t.challenge, | 3578 | &t.challenge, |
3682 | sizeof (struct PongMessage) - | 3579 | sizeof (struct PongMessage) - |
3683 | ((void *) &m->challenge - (void *) m))) | 3580 | ((void *) &m->challenge - (void *) m))) |
3684 | { | 3581 | { |
3685 | GNUNET_break_op (0); | 3582 | GNUNET_break_op (0); |
3686 | return; | 3583 | return; |
3687 | } | 3584 | } |
3688 | GNUNET_STATISTICS_update (stats, | 3585 | GNUNET_STATISTICS_update (stats, |
3689 | gettext_noop ("# PONG messages decrypted"), | 3586 | gettext_noop ("# PONG messages decrypted"), |
3690 | 1, | 3587 | 1, GNUNET_NO); |
3691 | GNUNET_NO); | ||
3692 | #if DEBUG_HANDSHAKE | 3588 | #if DEBUG_HANDSHAKE |
3693 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3694 | "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", | 3590 | "Decrypted `%s' from `%4s' with challenge %u using key %u, IV %u (salt %u)\n", |
@@ -3696,115 +3592,107 @@ handle_pong (struct Neighbour *n, | |||
3696 | GNUNET_i2s (&t.target), | 3592 | GNUNET_i2s (&t.target), |
3697 | (unsigned int) t.challenge, | 3593 | (unsigned int) t.challenge, |
3698 | (unsigned int) n->decrypt_key.crc32, | 3594 | (unsigned int) n->decrypt_key.crc32, |
3699 | GNUNET_CRYPTO_crc32_n (&iv, sizeof(iv)), | 3595 | GNUNET_CRYPTO_crc32_n (&iv, sizeof (iv)), m->iv_seed); |
3700 | m->iv_seed); | ||
3701 | #endif | 3596 | #endif |
3702 | if ((0 != memcmp (&t.target, | 3597 | if ((0 != memcmp (&t.target, |
3703 | &n->peer, | 3598 | &n->peer, |
3704 | sizeof (struct GNUNET_PeerIdentity))) || | 3599 | sizeof (struct GNUNET_PeerIdentity))) || |
3705 | (n->ping_challenge != t.challenge)) | 3600 | (n->ping_challenge != t.challenge)) |
3706 | { | 3601 | { |
3707 | /* PONG malformed */ | 3602 | /* PONG malformed */ |
3708 | #if DEBUG_CORE | 3603 | #if DEBUG_CORE |
3709 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3604 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3710 | "Received malformed `%s' wanted sender `%4s' with challenge %u\n", | 3605 | "Received malformed `%s' wanted sender `%4s' with challenge %u\n", |
3711 | "PONG", | 3606 | "PONG", |
3712 | GNUNET_i2s (&n->peer), | 3607 | GNUNET_i2s (&n->peer), (unsigned int) n->ping_challenge); |
3713 | (unsigned int) n->ping_challenge); | 3608 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3714 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3609 | "Received malformed `%s' received from `%4s' with challenge %u\n", |
3715 | "Received malformed `%s' received from `%4s' with challenge %u\n", | 3610 | "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge); |
3716 | "PONG", GNUNET_i2s (&t.target), | ||
3717 | (unsigned int) t.challenge); | ||
3718 | #endif | 3611 | #endif |
3719 | GNUNET_break_op (n->ping_challenge != t.challenge); | 3612 | GNUNET_break_op (n->ping_challenge != t.challenge); |
3720 | return; | 3613 | return; |
3721 | } | 3614 | } |
3722 | switch (n->status) | 3615 | switch (n->status) |
3616 | { | ||
3617 | case PEER_STATE_DOWN: | ||
3618 | GNUNET_break (0); /* should be impossible */ | ||
3619 | return; | ||
3620 | case PEER_STATE_KEY_SENT: | ||
3621 | GNUNET_break (0); /* should be impossible, how did we decrypt? */ | ||
3622 | return; | ||
3623 | case PEER_STATE_KEY_RECEIVED: | ||
3624 | GNUNET_STATISTICS_update (stats, | ||
3625 | gettext_noop | ||
3626 | ("# Session keys confirmed via PONG"), 1, | ||
3627 | GNUNET_NO); | ||
3628 | n->status = PEER_STATE_KEY_CONFIRMED; | ||
3723 | { | 3629 | { |
3724 | case PEER_STATE_DOWN: | 3630 | struct GNUNET_MessageHeader *hdr; |
3725 | GNUNET_break (0); /* should be impossible */ | ||
3726 | return; | ||
3727 | case PEER_STATE_KEY_SENT: | ||
3728 | GNUNET_break (0); /* should be impossible, how did we decrypt? */ | ||
3729 | return; | ||
3730 | case PEER_STATE_KEY_RECEIVED: | ||
3731 | GNUNET_STATISTICS_update (stats, | ||
3732 | gettext_noop ("# Session keys confirmed via PONG"), | ||
3733 | 1, | ||
3734 | GNUNET_NO); | ||
3735 | n->status = PEER_STATE_KEY_CONFIRMED; | ||
3736 | { | ||
3737 | struct GNUNET_MessageHeader *hdr; | ||
3738 | 3631 | ||
3739 | hdr = compute_type_map_message (); | 3632 | hdr = compute_type_map_message (); |
3740 | send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n); | 3633 | send_type_map_to_neighbour (hdr, &n->peer.hashPubKey, n); |
3741 | GNUNET_free (hdr); | 3634 | GNUNET_free (hdr); |
3742 | } | 3635 | } |
3743 | if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) | 3636 | if (n->bw_out_external_limit.value__ != t.inbound_bw_limit.value__) |
3744 | { | 3637 | { |
3745 | n->bw_out_external_limit = t.inbound_bw_limit; | 3638 | n->bw_out_external_limit = t.inbound_bw_limit; |
3746 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | 3639 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, |
3747 | n->bw_out_internal_limit); | 3640 | n->bw_out_internal_limit); |
3748 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, | 3641 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, |
3749 | n->bw_out); | 3642 | n->bw_out); |
3750 | GNUNET_TRANSPORT_set_quota (transport, | 3643 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
3751 | &n->peer, | 3644 | } |
3752 | n->bw_in, | ||
3753 | n->bw_out); | ||
3754 | } | ||
3755 | #if DEBUG_CORE | 3645 | #if DEBUG_CORE |
3756 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3646 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3757 | "Confirmed key via `%s' message for peer `%4s'\n", | 3647 | "Confirmed key via `%s' message for peer `%4s'\n", |
3758 | "PONG", GNUNET_i2s (&n->peer)); | 3648 | "PONG", GNUNET_i2s (&n->peer)); |
3759 | #endif | 3649 | #endif |
3760 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) | 3650 | if (n->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) |
3761 | { | 3651 | { |
3762 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); | 3652 | GNUNET_SCHEDULER_cancel (n->retry_set_key_task); |
3763 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; | 3653 | n->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK; |
3764 | } | 3654 | } |
3765 | update_neighbour_performance (n, ats, ats_count); | 3655 | update_neighbour_performance (n, ats, ats_count); |
3766 | size = sizeof (struct ConnectNotifyMessage) + | 3656 | size = sizeof (struct ConnectNotifyMessage) + |
3767 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 3657 | (n->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
3768 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 3658 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
3769 | { | 3659 | { |
3770 | GNUNET_break (0); | ||
3771 | /* recovery strategy: throw away performance data */ | ||
3772 | GNUNET_array_grow (n->ats, | ||
3773 | n->ats_count, | ||
3774 | 0); | ||
3775 | size = sizeof (struct PeerStatusNotifyMessage) + | ||
3776 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
3777 | } | ||
3778 | cnm = (struct ConnectNotifyMessage*) buf; | ||
3779 | cnm->header.size = htons (size); | ||
3780 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | ||
3781 | cnm->ats_count = htonl (n->ats_count); | ||
3782 | cnm->peer = n->peer; | ||
3783 | mats = &cnm->ats; | ||
3784 | memcpy (mats, | ||
3785 | n->ats, | ||
3786 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
3787 | mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
3788 | mats[n->ats_count].value = htonl (0); | ||
3789 | send_to_all_clients (&cnm->header, | ||
3790 | GNUNET_NO, | ||
3791 | GNUNET_CORE_OPTION_SEND_CONNECT); | ||
3792 | process_encrypted_neighbour_queue (n); | ||
3793 | /* fall-through! */ | ||
3794 | case PEER_STATE_KEY_CONFIRMED: | ||
3795 | n->last_activity = GNUNET_TIME_absolute_get (); | ||
3796 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
3797 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
3798 | n->keep_alive_task | ||
3799 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | ||
3800 | &send_keep_alive, | ||
3801 | n); | ||
3802 | handle_peer_status_change (n); | ||
3803 | break; | ||
3804 | default: | ||
3805 | GNUNET_break (0); | 3660 | GNUNET_break (0); |
3806 | break; | 3661 | /* recovery strategy: throw away performance data */ |
3662 | GNUNET_array_grow (n->ats, n->ats_count, 0); | ||
3663 | size = sizeof (struct PeerStatusNotifyMessage) + | ||
3664 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
3807 | } | 3665 | } |
3666 | cnm = (struct ConnectNotifyMessage *) buf; | ||
3667 | cnm->header.size = htons (size); | ||
3668 | cnm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); | ||
3669 | cnm->ats_count = htonl (n->ats_count); | ||
3670 | cnm->peer = n->peer; | ||
3671 | mats = &cnm->ats; | ||
3672 | memcpy (mats, | ||
3673 | n->ats, | ||
3674 | n->ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); | ||
3675 | mats[n->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | ||
3676 | mats[n->ats_count].value = htonl (0); | ||
3677 | send_to_all_clients (&cnm->header, | ||
3678 | GNUNET_NO, GNUNET_CORE_OPTION_SEND_CONNECT); | ||
3679 | process_encrypted_neighbour_queue (n); | ||
3680 | /* fall-through! */ | ||
3681 | case PEER_STATE_KEY_CONFIRMED: | ||
3682 | n->last_activity = GNUNET_TIME_absolute_get (); | ||
3683 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
3684 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
3685 | n->keep_alive_task | ||
3686 | = | ||
3687 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
3688 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
3689 | 2), &send_keep_alive, n); | ||
3690 | handle_peer_status_change (n); | ||
3691 | break; | ||
3692 | default: | ||
3693 | GNUNET_break (0); | ||
3694 | break; | ||
3695 | } | ||
3808 | } | 3696 | } |
3809 | 3697 | ||
3810 | 3698 | ||
@@ -3818,10 +3706,10 @@ handle_pong (struct Neighbour *n, | |||
3818 | * @param ats_count number of entries in ats (excluding 0-termination) | 3706 | * @param ats_count number of entries in ats (excluding 0-termination) |
3819 | */ | 3707 | */ |
3820 | static void | 3708 | static void |
3821 | handle_set_key (struct Neighbour *n, | 3709 | handle_set_key (struct Neighbour *n, |
3822 | const struct SetKeyMessage *m, | 3710 | const struct SetKeyMessage *m, |
3823 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 3711 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
3824 | uint32_t ats_count) | 3712 | uint32_t ats_count) |
3825 | { | 3713 | { |
3826 | struct SetKeyMessage *m_cpy; | 3714 | struct SetKeyMessage *m_cpy; |
3827 | struct GNUNET_TIME_Absolute t; | 3715 | struct GNUNET_TIME_Absolute t; |
@@ -3836,45 +3724,44 @@ handle_set_key (struct Neighbour *n, | |||
3836 | "SET_KEY", GNUNET_i2s (&n->peer)); | 3724 | "SET_KEY", GNUNET_i2s (&n->peer)); |
3837 | #endif | 3725 | #endif |
3838 | if (n->public_key == NULL) | 3726 | if (n->public_key == NULL) |
3727 | { | ||
3728 | if (n->pitr != NULL) | ||
3839 | { | 3729 | { |
3840 | if (n->pitr != NULL) | ||
3841 | { | ||
3842 | #if DEBUG_CORE | ||
3843 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3844 | "Ignoring `%s' message due to lack of public key for peer (still trying to obtain one).\n", | ||
3845 | "SET_KEY"); | ||
3846 | #endif | ||
3847 | return; | ||
3848 | } | ||
3849 | #if DEBUG_CORE | 3730 | #if DEBUG_CORE |
3850 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3731 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3851 | "Lacking public key for peer, trying to obtain one (handle_set_key).\n"); | 3732 | "Ignoring `%s' message due to lack of public key for peer (still trying to obtain one).\n", |
3733 | "SET_KEY"); | ||
3852 | #endif | 3734 | #endif |
3853 | m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage)); | ||
3854 | memcpy (m_cpy, m, sizeof (struct SetKeyMessage)); | ||
3855 | /* lookup n's public key, then try again */ | ||
3856 | GNUNET_assert (n->skm == NULL); | ||
3857 | n->skm = m_cpy; | ||
3858 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | ||
3859 | &n->peer, | ||
3860 | GNUNET_TIME_UNIT_MINUTES, | ||
3861 | &process_hello_retry_handle_set_key, n); | ||
3862 | GNUNET_STATISTICS_update (stats, | ||
3863 | gettext_noop ("# SET_KEY messages deferred (need public key)"), | ||
3864 | 1, | ||
3865 | GNUNET_NO); | ||
3866 | return; | 3735 | return; |
3867 | } | 3736 | } |
3737 | #if DEBUG_CORE | ||
3738 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3739 | "Lacking public key for peer, trying to obtain one (handle_set_key).\n"); | ||
3740 | #endif | ||
3741 | m_cpy = GNUNET_malloc (sizeof (struct SetKeyMessage)); | ||
3742 | memcpy (m_cpy, m, sizeof (struct SetKeyMessage)); | ||
3743 | /* lookup n's public key, then try again */ | ||
3744 | GNUNET_assert (n->skm == NULL); | ||
3745 | n->skm = m_cpy; | ||
3746 | n->pitr = GNUNET_PEERINFO_iterate (peerinfo, | ||
3747 | &n->peer, | ||
3748 | GNUNET_TIME_UNIT_MINUTES, | ||
3749 | &process_hello_retry_handle_set_key, n); | ||
3750 | GNUNET_STATISTICS_update (stats, | ||
3751 | gettext_noop | ||
3752 | ("# SET_KEY messages deferred (need public key)"), | ||
3753 | 1, GNUNET_NO); | ||
3754 | return; | ||
3755 | } | ||
3868 | if (0 != memcmp (&m->target, | 3756 | if (0 != memcmp (&m->target, |
3869 | &my_identity, | 3757 | &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
3870 | sizeof (struct GNUNET_PeerIdentity))) | 3758 | { |
3871 | { | 3759 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3872 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3760 | _ |
3873 | _("Received `%s' message that was for `%s', not for me. Ignoring.\n"), | 3761 | ("Received `%s' message that was for `%s', not for me. Ignoring.\n"), |
3874 | "SET_KEY", | 3762 | "SET_KEY", GNUNET_i2s (&m->target)); |
3875 | GNUNET_i2s (&m->target)); | 3763 | return; |
3876 | return; | 3764 | } |
3877 | } | ||
3878 | if ((ntohl (m->purpose.size) != | 3765 | if ((ntohl (m->purpose.size) != |
3879 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + | 3766 | sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + |
3880 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | 3767 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + |
@@ -3883,107 +3770,103 @@ handle_set_key (struct Neighbour *n, | |||
3883 | (GNUNET_OK != | 3770 | (GNUNET_OK != |
3884 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, | 3771 | GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_KEY, |
3885 | &m->purpose, &m->signature, n->public_key))) | 3772 | &m->purpose, &m->signature, n->public_key))) |
3886 | { | 3773 | { |
3887 | /* invalid signature */ | 3774 | /* invalid signature */ |
3888 | GNUNET_break_op (0); | 3775 | GNUNET_break_op (0); |
3889 | return; | 3776 | return; |
3890 | } | 3777 | } |
3891 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); | 3778 | t = GNUNET_TIME_absolute_ntoh (m->creation_time); |
3892 | if (((n->status == PEER_STATE_KEY_RECEIVED) || | 3779 | if (((n->status == PEER_STATE_KEY_RECEIVED) || |
3893 | (n->status == PEER_STATE_KEY_CONFIRMED)) && | 3780 | (n->status == PEER_STATE_KEY_CONFIRMED)) && |
3894 | (t.abs_value < n->decrypt_key_created.abs_value)) | 3781 | (t.abs_value < n->decrypt_key_created.abs_value)) |
3895 | { | 3782 | { |
3896 | /* this could rarely happen due to massive re-ordering of | 3783 | /* this could rarely happen due to massive re-ordering of |
3897 | messages on the network level, but is most likely either | 3784 | * messages on the network level, but is most likely either |
3898 | a bug or some adversary messing with us. Report. */ | 3785 | * a bug or some adversary messing with us. Report. */ |
3899 | GNUNET_break_op (0); | 3786 | GNUNET_break_op (0); |
3900 | return; | 3787 | return; |
3901 | } | 3788 | } |
3902 | #if DEBUG_CORE | 3789 | #if DEBUG_CORE |
3903 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3790 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypting key material.\n"); |
3904 | "Decrypting key material.\n"); | 3791 | #endif |
3905 | #endif | ||
3906 | if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, | 3792 | if ((GNUNET_CRYPTO_rsa_decrypt (my_private_key, |
3907 | &m->encrypted_key, | 3793 | &m->encrypted_key, |
3908 | &k, | 3794 | &k, |
3909 | sizeof (struct GNUNET_CRYPTO_AesSessionKey)) | 3795 | sizeof (struct GNUNET_CRYPTO_AesSessionKey)) |
3910 | != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) || | 3796 | != sizeof (struct GNUNET_CRYPTO_AesSessionKey)) || |
3911 | (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) | 3797 | (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k))) |
3912 | { | 3798 | { |
3913 | /* failed to decrypt !? */ | 3799 | /* failed to decrypt !? */ |
3914 | GNUNET_break_op (0); | 3800 | GNUNET_break_op (0); |
3915 | return; | 3801 | return; |
3916 | } | 3802 | } |
3917 | GNUNET_STATISTICS_update (stats, | 3803 | GNUNET_STATISTICS_update (stats, |
3918 | gettext_noop ("# SET_KEY messages decrypted"), | 3804 | gettext_noop ("# SET_KEY messages decrypted"), |
3919 | 1, | 3805 | 1, GNUNET_NO); |
3920 | GNUNET_NO); | ||
3921 | n->decrypt_key = k; | 3806 | n->decrypt_key = k; |
3922 | if (n->decrypt_key_created.abs_value != t.abs_value) | 3807 | if (n->decrypt_key_created.abs_value != t.abs_value) |
3923 | { | 3808 | { |
3924 | /* fresh key, reset sequence numbers */ | 3809 | /* fresh key, reset sequence numbers */ |
3925 | n->last_sequence_number_received = 0; | 3810 | n->last_sequence_number_received = 0; |
3926 | n->last_packets_bitmap = 0; | 3811 | n->last_packets_bitmap = 0; |
3927 | n->decrypt_key_created = t; | 3812 | n->decrypt_key_created = t; |
3928 | } | 3813 | } |
3929 | update_neighbour_performance (n, ats, ats_count); | 3814 | update_neighbour_performance (n, ats, ats_count); |
3930 | sender_status = (enum PeerStateMachine) ntohl (m->sender_status); | 3815 | sender_status = (enum PeerStateMachine) ntohl (m->sender_status); |
3931 | switch (n->status) | 3816 | switch (n->status) |
3817 | { | ||
3818 | case PEER_STATE_DOWN: | ||
3819 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3820 | #if DEBUG_CORE | ||
3821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3822 | "Responding to `%s' with my own key.\n", "SET_KEY"); | ||
3823 | #endif | ||
3824 | send_key (n); | ||
3825 | break; | ||
3826 | case PEER_STATE_KEY_SENT: | ||
3827 | case PEER_STATE_KEY_RECEIVED: | ||
3828 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3829 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | ||
3830 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | ||
3932 | { | 3831 | { |
3933 | case PEER_STATE_DOWN: | ||
3934 | n->status = PEER_STATE_KEY_RECEIVED; | ||
3935 | #if DEBUG_CORE | 3832 | #if DEBUG_CORE |
3936 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3937 | "Responding to `%s' with my own key.\n", "SET_KEY"); | 3834 | "Responding to `%s' with my own key (other peer has status %u).\n", |
3835 | "SET_KEY", (unsigned int) sender_status); | ||
3938 | #endif | 3836 | #endif |
3939 | send_key (n); | 3837 | send_key (n); |
3940 | break; | 3838 | } |
3941 | case PEER_STATE_KEY_SENT: | 3839 | break; |
3942 | case PEER_STATE_KEY_RECEIVED: | 3840 | case PEER_STATE_KEY_CONFIRMED: |
3943 | n->status = PEER_STATE_KEY_RECEIVED; | 3841 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && |
3944 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | 3842 | (sender_status != PEER_STATE_KEY_CONFIRMED)) |
3945 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | 3843 | { |
3946 | { | ||
3947 | #if DEBUG_CORE | ||
3948 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
3949 | "Responding to `%s' with my own key (other peer has status %u).\n", | ||
3950 | "SET_KEY", | ||
3951 | (unsigned int) sender_status); | ||
3952 | #endif | ||
3953 | send_key (n); | ||
3954 | } | ||
3955 | break; | ||
3956 | case PEER_STATE_KEY_CONFIRMED: | ||
3957 | if ((sender_status != PEER_STATE_KEY_RECEIVED) && | ||
3958 | (sender_status != PEER_STATE_KEY_CONFIRMED)) | ||
3959 | { | ||
3960 | #if DEBUG_CORE | 3844 | #if DEBUG_CORE |
3961 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3845 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3962 | "Responding to `%s' with my own key (other peer has status %u), I was already fully up.\n", | 3846 | "Responding to `%s' with my own key (other peer has status %u), I was already fully up.\n", |
3963 | "SET_KEY", | 3847 | "SET_KEY", (unsigned int) sender_status); |
3964 | (unsigned int) sender_status); | ||
3965 | #endif | 3848 | #endif |
3966 | send_key (n); | 3849 | send_key (n); |
3967 | } | ||
3968 | break; | ||
3969 | default: | ||
3970 | GNUNET_break (0); | ||
3971 | break; | ||
3972 | } | 3850 | } |
3851 | break; | ||
3852 | default: | ||
3853 | GNUNET_break (0); | ||
3854 | break; | ||
3855 | } | ||
3973 | if (n->pending_ping != NULL) | 3856 | if (n->pending_ping != NULL) |
3974 | { | 3857 | { |
3975 | ping = n->pending_ping; | 3858 | ping = n->pending_ping; |
3976 | n->pending_ping = NULL; | 3859 | n->pending_ping = NULL; |
3977 | handle_ping (n, ping, NULL, 0); | 3860 | handle_ping (n, ping, NULL, 0); |
3978 | GNUNET_free (ping); | 3861 | GNUNET_free (ping); |
3979 | } | 3862 | } |
3980 | if (n->pending_pong != NULL) | 3863 | if (n->pending_pong != NULL) |
3981 | { | 3864 | { |
3982 | pong = n->pending_pong; | 3865 | pong = n->pending_pong; |
3983 | n->pending_pong = NULL; | 3866 | n->pending_pong = NULL; |
3984 | handle_pong (n, pong, NULL, 0); | 3867 | handle_pong (n, pong, NULL, 0); |
3985 | GNUNET_free (pong); | 3868 | GNUNET_free (pong); |
3986 | } | 3869 | } |
3987 | } | 3870 | } |
3988 | 3871 | ||
3989 | 3872 | ||
@@ -3997,31 +3880,29 @@ handle_set_key (struct Neighbour *n, | |||
3997 | */ | 3880 | */ |
3998 | static void | 3881 | static void |
3999 | send_p2p_message_to_client (struct Neighbour *sender, | 3882 | send_p2p_message_to_client (struct Neighbour *sender, |
4000 | struct Client *client, | 3883 | struct Client *client, const void *m, size_t msize) |
4001 | const void *m, size_t msize) | ||
4002 | { | 3884 | { |
4003 | size_t size = msize + sizeof (struct NotifyTrafficMessage) + | 3885 | size_t size = msize + sizeof (struct NotifyTrafficMessage) + |
4004 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | 3886 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
4005 | char buf[size]; | 3887 | char buf[size]; |
4006 | struct NotifyTrafficMessage *ntm; | 3888 | struct NotifyTrafficMessage *ntm; |
4007 | struct GNUNET_TRANSPORT_ATS_Information *ats; | 3889 | struct GNUNET_TRANSPORT_ATS_Information *ats; |
4008 | 3890 | ||
4009 | GNUNET_assert (GNUNET_YES == sender->is_connected); | 3891 | GNUNET_assert (GNUNET_YES == sender->is_connected); |
4010 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | 3892 | if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE) |
4011 | { | 3893 | { |
4012 | GNUNET_break (0); | 3894 | GNUNET_break (0); |
4013 | /* recovery strategy: throw performance data away... */ | 3895 | /* recovery strategy: throw performance data away... */ |
4014 | GNUNET_array_grow (sender->ats, | 3896 | GNUNET_array_grow (sender->ats, sender->ats_count, 0); |
4015 | sender->ats_count, | 3897 | size = msize + sizeof (struct NotifyTrafficMessage) + |
4016 | 0); | 3898 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); |
4017 | size = msize + sizeof (struct NotifyTrafficMessage) + | 3899 | } |
4018 | (sender->ats_count) * sizeof (struct GNUNET_TRANSPORT_ATS_Information); | ||
4019 | } | ||
4020 | #if DEBUG_CORE | 3900 | #if DEBUG_CORE |
4021 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3901 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4022 | "Core service passes message from `%4s' of type %u to client.\n", | 3902 | "Core service passes message from `%4s' of type %u to client.\n", |
4023 | GNUNET_i2s(&sender->peer), | 3903 | GNUNET_i2s (&sender->peer), |
4024 | (unsigned int) ntohs (((const struct GNUNET_MessageHeader *) m)->type)); | 3904 | (unsigned int) |
3905 | ntohs (((const struct GNUNET_MessageHeader *) m)->type)); | ||
4025 | #endif | 3906 | #endif |
4026 | ntm = (struct NotifyTrafficMessage *) buf; | 3907 | ntm = (struct NotifyTrafficMessage *) buf; |
4027 | ntm->header.size = htons (size); | 3908 | ntm->header.size = htons (size); |
@@ -4030,13 +3911,11 @@ send_p2p_message_to_client (struct Neighbour *sender, | |||
4030 | ntm->peer = sender->peer; | 3911 | ntm->peer = sender->peer; |
4031 | ats = &ntm->ats; | 3912 | ats = &ntm->ats; |
4032 | memcpy (ats, | 3913 | memcpy (ats, |
4033 | sender->ats, | 3914 | sender->ats, |
4034 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); | 3915 | sizeof (struct GNUNET_TRANSPORT_ATS_Information) * sender->ats_count); |
4035 | ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 3916 | ats[sender->ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
4036 | ats[sender->ats_count].value = htonl (0); | 3917 | ats[sender->ats_count].value = htonl (0); |
4037 | memcpy (&ats[sender->ats_count+1], | 3918 | memcpy (&ats[sender->ats_count + 1], m, msize); |
4038 | m, | ||
4039 | msize); | ||
4040 | send_to_client (client, &ntm->header, GNUNET_YES); | 3919 | send_to_client (client, &ntm->header, GNUNET_YES); |
4041 | } | 3920 | } |
4042 | 3921 | ||
@@ -4049,9 +3928,7 @@ send_p2p_message_to_client (struct Neighbour *sender, | |||
4049 | * @param m the message | 3928 | * @param m the message |
4050 | */ | 3929 | */ |
4051 | static void | 3930 | static void |
4052 | deliver_message (void *cls, | 3931 | deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m) |
4053 | void *client, | ||
4054 | const struct GNUNET_MessageHeader *m) | ||
4055 | { | 3932 | { |
4056 | struct Neighbour *sender = client; | 3933 | struct Neighbour *sender = client; |
4057 | size_t msize = ntohs (m->size); | 3934 | size_t msize = ntohs (m->size); |
@@ -4065,66 +3942,61 @@ deliver_message (void *cls, | |||
4065 | type = ntohs (m->type); | 3942 | type = ntohs (m->type); |
4066 | #if DEBUG_CORE > 1 | 3943 | #if DEBUG_CORE > 1 |
4067 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3944 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4068 | "Received encapsulated message of type %u and size %u from `%4s'\n", | 3945 | "Received encapsulated message of type %u and size %u from `%4s'\n", |
4069 | (unsigned int) type, | 3946 | (unsigned int) type, ntohs (m->size), GNUNET_i2s (&sender->peer)); |
4070 | ntohs (m->size), | ||
4071 | GNUNET_i2s (&sender->peer)); | ||
4072 | #endif | 3947 | #endif |
4073 | GNUNET_snprintf (buf, | 3948 | GNUNET_snprintf (buf, |
4074 | sizeof(buf), | 3949 | sizeof (buf), |
4075 | gettext_noop ("# bytes of messages of type %u received"), | 3950 | gettext_noop ("# bytes of messages of type %u received"), |
4076 | (unsigned int) type); | 3951 | (unsigned int) type); |
4077 | GNUNET_STATISTICS_update (stats, | 3952 | GNUNET_STATISTICS_update (stats, buf, msize, GNUNET_NO); |
4078 | buf, | 3953 | if ((GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) || |
4079 | msize, | 3954 | (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type)) |
4080 | GNUNET_NO); | 3955 | { |
4081 | if ( (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP == type) || | 3956 | /* FIXME: update message type map for 'Neighbour' */ |
4082 | (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP == type) ) | 3957 | return; |
4083 | { | 3958 | } |
4084 | /* FIXME: update message type map for 'Neighbour' */ | ||
4085 | return; | ||
4086 | } | ||
4087 | dropped = GNUNET_YES; | 3959 | dropped = GNUNET_YES; |
4088 | cpos = clients; | 3960 | cpos = clients; |
4089 | while (cpos != NULL) | 3961 | while (cpos != NULL) |
3962 | { | ||
3963 | deliver_full = GNUNET_NO; | ||
3964 | if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) | ||
3965 | deliver_full = GNUNET_YES; | ||
3966 | else | ||
4090 | { | 3967 | { |
4091 | deliver_full = GNUNET_NO; | 3968 | for (tpos = 0; tpos < cpos->tcnt; tpos++) |
4092 | if (0 != (cpos->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) | 3969 | { |
3970 | if (type != cpos->types[tpos]) | ||
3971 | continue; | ||
4093 | deliver_full = GNUNET_YES; | 3972 | deliver_full = GNUNET_YES; |
4094 | else | 3973 | break; |
4095 | { | 3974 | } |
4096 | for (tpos = 0; tpos < cpos->tcnt; tpos++) | ||
4097 | { | ||
4098 | if (type != cpos->types[tpos]) | ||
4099 | continue; | ||
4100 | deliver_full = GNUNET_YES; | ||
4101 | break; | ||
4102 | } | ||
4103 | } | ||
4104 | if (GNUNET_YES == deliver_full) | ||
4105 | { | ||
4106 | send_p2p_message_to_client (sender, cpos, m, msize); | ||
4107 | dropped = GNUNET_NO; | ||
4108 | } | ||
4109 | else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND) | ||
4110 | { | ||
4111 | send_p2p_message_to_client (sender, cpos, m, | ||
4112 | sizeof (struct GNUNET_MessageHeader)); | ||
4113 | } | ||
4114 | cpos = cpos->next; | ||
4115 | } | 3975 | } |
4116 | if (dropped == GNUNET_YES) | 3976 | if (GNUNET_YES == deliver_full) |
4117 | { | 3977 | { |
3978 | send_p2p_message_to_client (sender, cpos, m, msize); | ||
3979 | dropped = GNUNET_NO; | ||
3980 | } | ||
3981 | else if (cpos->options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND) | ||
3982 | { | ||
3983 | send_p2p_message_to_client (sender, cpos, m, | ||
3984 | sizeof (struct GNUNET_MessageHeader)); | ||
3985 | } | ||
3986 | cpos = cpos->next; | ||
3987 | } | ||
3988 | if (dropped == GNUNET_YES) | ||
3989 | { | ||
4118 | #if DEBUG_CORE | 3990 | #if DEBUG_CORE |
4119 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3991 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4120 | "Message of type %u from `%4s' not delivered to any client.\n", | 3992 | "Message of type %u from `%4s' not delivered to any client.\n", |
4121 | (unsigned int) type, | 3993 | (unsigned int) type, GNUNET_i2s (&sender->peer)); |
4122 | GNUNET_i2s (&sender->peer)); | ||
4123 | #endif | 3994 | #endif |
4124 | GNUNET_STATISTICS_update (stats, | 3995 | GNUNET_STATISTICS_update (stats, |
4125 | gettext_noop ("# messages not delivered to any client"), | 3996 | gettext_noop |
4126 | 1, GNUNET_NO); | 3997 | ("# messages not delivered to any client"), 1, |
4127 | } | 3998 | GNUNET_NO); |
3999 | } | ||
4128 | } | 4000 | } |
4129 | 4001 | ||
4130 | 4002 | ||
@@ -4140,8 +4012,8 @@ deliver_message (void *cls, | |||
4140 | static void | 4012 | static void |
4141 | handle_encrypted_message (struct Neighbour *n, | 4013 | handle_encrypted_message (struct Neighbour *n, |
4142 | const struct EncryptedMessage *m, | 4014 | const struct EncryptedMessage *m, |
4143 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4015 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
4144 | uint32_t ats_count) | 4016 | uint32_t ats_count) |
4145 | { | 4017 | { |
4146 | size_t size = ntohs (m->header.size); | 4018 | size_t size = ntohs (m->header.size); |
4147 | char buf[size]; | 4019 | char buf[size]; |
@@ -4156,147 +4028,140 @@ handle_encrypted_message (struct Neighbour *n, | |||
4156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4028 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4157 | "Core service receives `%s' request from `%4s'.\n", | 4029 | "Core service receives `%s' request from `%4s'.\n", |
4158 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); | 4030 | "ENCRYPTED_MESSAGE", GNUNET_i2s (&n->peer)); |
4159 | #endif | 4031 | #endif |
4160 | /* validate hash */ | 4032 | /* validate hash */ |
4161 | derive_auth_key (&auth_key, | 4033 | derive_auth_key (&auth_key, |
4162 | &n->decrypt_key, | 4034 | &n->decrypt_key, m->iv_seed, n->decrypt_key_created); |
4163 | m->iv_seed, | ||
4164 | n->decrypt_key_created); | ||
4165 | GNUNET_CRYPTO_hmac (&auth_key, | 4035 | GNUNET_CRYPTO_hmac (&auth_key, |
4166 | &m->sequence_number, | 4036 | &m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &ph); |
4167 | size - ENCRYPTED_HEADER_SIZE, &ph); | ||
4168 | #if DEBUG_HANDSHAKE | 4037 | #if DEBUG_HANDSHAKE |
4169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4170 | "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", | 4039 | "Re-Authenticated %u bytes of ciphertext (`%u'): `%s'\n", |
4171 | (unsigned int) size - ENCRYPTED_HEADER_SIZE, | 4040 | (unsigned int) size - ENCRYPTED_HEADER_SIZE, |
4172 | GNUNET_CRYPTO_crc32_n (&m->sequence_number, | 4041 | GNUNET_CRYPTO_crc32_n (&m->sequence_number, |
4173 | size - ENCRYPTED_HEADER_SIZE), | 4042 | size - ENCRYPTED_HEADER_SIZE), |
4174 | GNUNET_h2s (&ph)); | 4043 | GNUNET_h2s (&ph)); |
4175 | #endif | 4044 | #endif |
4176 | 4045 | ||
4177 | if (0 != memcmp (&ph, | 4046 | if (0 != memcmp (&ph, &m->hmac, sizeof (GNUNET_HashCode))) |
4178 | &m->hmac, | 4047 | { |
4179 | sizeof (GNUNET_HashCode))) | 4048 | /* checksum failed */ |
4180 | { | 4049 | GNUNET_break_op (0); |
4181 | /* checksum failed */ | 4050 | return; |
4182 | GNUNET_break_op (0); | 4051 | } |
4183 | return; | ||
4184 | } | ||
4185 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); | 4052 | derive_iv (&iv, &n->decrypt_key, m->iv_seed, &my_identity); |
4186 | /* decrypt */ | 4053 | /* decrypt */ |
4187 | if (GNUNET_OK != | 4054 | if (GNUNET_OK != |
4188 | do_decrypt (n, | 4055 | do_decrypt (n, |
4189 | &iv, | 4056 | &iv, |
4190 | &m->sequence_number, | 4057 | &m->sequence_number, |
4191 | &buf[ENCRYPTED_HEADER_SIZE], | 4058 | &buf[ENCRYPTED_HEADER_SIZE], size - ENCRYPTED_HEADER_SIZE)) |
4192 | size - ENCRYPTED_HEADER_SIZE)) | ||
4193 | return; | 4059 | return; |
4194 | pt = (struct EncryptedMessage *) buf; | 4060 | pt = (struct EncryptedMessage *) buf; |
4195 | 4061 | ||
4196 | /* validate sequence number */ | 4062 | /* validate sequence number */ |
4197 | snum = ntohl (pt->sequence_number); | 4063 | snum = ntohl (pt->sequence_number); |
4198 | if (n->last_sequence_number_received == snum) | 4064 | if (n->last_sequence_number_received == snum) |
4199 | { | 4065 | { |
4200 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4066 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4201 | "Received duplicate message, ignoring.\n"); | 4067 | "Received duplicate message, ignoring.\n"); |
4202 | /* duplicate, ignore */ | 4068 | /* duplicate, ignore */ |
4203 | GNUNET_STATISTICS_update (stats, | 4069 | GNUNET_STATISTICS_update (stats, |
4204 | gettext_noop ("# bytes dropped (duplicates)"), | 4070 | gettext_noop ("# bytes dropped (duplicates)"), |
4205 | size, | 4071 | size, GNUNET_NO); |
4206 | GNUNET_NO); | 4072 | return; |
4207 | return; | 4073 | } |
4208 | } | ||
4209 | if ((n->last_sequence_number_received > snum) && | 4074 | if ((n->last_sequence_number_received > snum) && |
4210 | (n->last_sequence_number_received - snum > 32)) | 4075 | (n->last_sequence_number_received - snum > 32)) |
4076 | { | ||
4077 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
4078 | "Received ancient out of sequence message, ignoring.\n"); | ||
4079 | /* ancient out of sequence, ignore */ | ||
4080 | GNUNET_STATISTICS_update (stats, | ||
4081 | gettext_noop | ||
4082 | ("# bytes dropped (out of sequence)"), size, | ||
4083 | GNUNET_NO); | ||
4084 | return; | ||
4085 | } | ||
4086 | if (n->last_sequence_number_received > snum) | ||
4087 | { | ||
4088 | unsigned int rotbit = 1 << (n->last_sequence_number_received - snum - 1); | ||
4089 | |||
4090 | if ((n->last_packets_bitmap & rotbit) != 0) | ||
4211 | { | 4091 | { |
4212 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4092 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4213 | "Received ancient out of sequence message, ignoring.\n"); | 4093 | "Received duplicate message, ignoring.\n"); |
4214 | /* ancient out of sequence, ignore */ | ||
4215 | GNUNET_STATISTICS_update (stats, | 4094 | GNUNET_STATISTICS_update (stats, |
4216 | gettext_noop ("# bytes dropped (out of sequence)"), | 4095 | gettext_noop ("# bytes dropped (duplicates)"), |
4217 | size, | 4096 | size, GNUNET_NO); |
4218 | GNUNET_NO); | 4097 | /* duplicate, ignore */ |
4219 | return; | 4098 | return; |
4220 | } | 4099 | } |
4221 | if (n->last_sequence_number_received > snum) | 4100 | n->last_packets_bitmap |= rotbit; |
4222 | { | 4101 | } |
4223 | unsigned int rotbit = | ||
4224 | 1 << (n->last_sequence_number_received - snum - 1); | ||
4225 | if ((n->last_packets_bitmap & rotbit) != 0) | ||
4226 | { | ||
4227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
4228 | "Received duplicate message, ignoring.\n"); | ||
4229 | GNUNET_STATISTICS_update (stats, | ||
4230 | gettext_noop ("# bytes dropped (duplicates)"), | ||
4231 | size, | ||
4232 | GNUNET_NO); | ||
4233 | /* duplicate, ignore */ | ||
4234 | return; | ||
4235 | } | ||
4236 | n->last_packets_bitmap |= rotbit; | ||
4237 | } | ||
4238 | if (n->last_sequence_number_received < snum) | 4102 | if (n->last_sequence_number_received < snum) |
4239 | { | 4103 | { |
4240 | int shift = (snum - n->last_sequence_number_received); | 4104 | int shift = (snum - n->last_sequence_number_received); |
4241 | if (shift >= 8 * sizeof(n->last_packets_bitmap)) | 4105 | |
4242 | n->last_packets_bitmap = 0; | 4106 | if (shift >= 8 * sizeof (n->last_packets_bitmap)) |
4243 | else | 4107 | n->last_packets_bitmap = 0; |
4244 | n->last_packets_bitmap <<= shift; | 4108 | else |
4245 | n->last_sequence_number_received = snum; | 4109 | n->last_packets_bitmap <<= shift; |
4246 | } | 4110 | n->last_sequence_number_received = snum; |
4111 | } | ||
4247 | 4112 | ||
4248 | /* check timestamp */ | 4113 | /* check timestamp */ |
4249 | t = GNUNET_TIME_absolute_ntoh (pt->timestamp); | 4114 | t = GNUNET_TIME_absolute_ntoh (pt->timestamp); |
4250 | if (GNUNET_TIME_absolute_get_duration (t).rel_value > MAX_MESSAGE_AGE.rel_value) | 4115 | if (GNUNET_TIME_absolute_get_duration (t).rel_value > |
4251 | { | 4116 | MAX_MESSAGE_AGE.rel_value) |
4252 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4117 | { |
4253 | _ | 4118 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4254 | ("Message received far too old (%llu ms). Content ignored.\n"), | 4119 | _ |
4255 | GNUNET_TIME_absolute_get_duration (t).rel_value); | 4120 | ("Message received far too old (%llu ms). Content ignored.\n"), |
4256 | GNUNET_STATISTICS_update (stats, | 4121 | GNUNET_TIME_absolute_get_duration (t).rel_value); |
4257 | gettext_noop ("# bytes dropped (ancient message)"), | 4122 | GNUNET_STATISTICS_update (stats, |
4258 | size, | 4123 | gettext_noop |
4259 | GNUNET_NO); | 4124 | ("# bytes dropped (ancient message)"), size, |
4260 | return; | 4125 | GNUNET_NO); |
4261 | } | 4126 | return; |
4127 | } | ||
4262 | 4128 | ||
4263 | /* process decrypted message(s) */ | 4129 | /* process decrypted message(s) */ |
4264 | if (n->bw_out_external_limit.value__ != pt->inbound_bw_limit.value__) | 4130 | if (n->bw_out_external_limit.value__ != pt->inbound_bw_limit.value__) |
4265 | { | 4131 | { |
4266 | #if DEBUG_CORE_SET_QUOTA | 4132 | #if DEBUG_CORE_SET_QUOTA |
4267 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4268 | "Received %u b/s as new inbound limit for peer `%4s'\n", | 4134 | "Received %u b/s as new inbound limit for peer `%4s'\n", |
4269 | (unsigned int) ntohl (pt->inbound_bw_limit.value__), | 4135 | (unsigned int) ntohl (pt->inbound_bw_limit.value__), |
4270 | GNUNET_i2s (&n->peer)); | 4136 | GNUNET_i2s (&n->peer)); |
4271 | #endif | 4137 | #endif |
4272 | n->bw_out_external_limit = pt->inbound_bw_limit; | 4138 | n->bw_out_external_limit = pt->inbound_bw_limit; |
4273 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | 4139 | n->bw_out = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, |
4274 | n->bw_out_internal_limit); | 4140 | n->bw_out_internal_limit); |
4275 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, | 4141 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, |
4276 | n->bw_out); | 4142 | n->bw_out); |
4277 | GNUNET_TRANSPORT_set_quota (transport, | 4143 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4278 | &n->peer, | 4144 | } |
4279 | n->bw_in, | ||
4280 | n->bw_out); | ||
4281 | } | ||
4282 | n->last_activity = GNUNET_TIME_absolute_get (); | 4145 | n->last_activity = GNUNET_TIME_absolute_get (); |
4283 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | 4146 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) |
4284 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 4147 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
4285 | n->keep_alive_task | 4148 | n->keep_alive_task |
4286 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | 4149 | = |
4287 | &send_keep_alive, | 4150 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide |
4288 | n); | 4151 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
4152 | 2), &send_keep_alive, n); | ||
4289 | GNUNET_STATISTICS_update (stats, | 4153 | GNUNET_STATISTICS_update (stats, |
4290 | gettext_noop ("# bytes of payload decrypted"), | 4154 | gettext_noop ("# bytes of payload decrypted"), |
4291 | size - sizeof (struct EncryptedMessage), | 4155 | size - sizeof (struct EncryptedMessage), GNUNET_NO); |
4292 | GNUNET_NO); | ||
4293 | handle_peer_status_change (n); | 4156 | handle_peer_status_change (n); |
4294 | update_neighbour_performance (n, ats, ats_count); | 4157 | update_neighbour_performance (n, ats, ats_count); |
4295 | if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, | 4158 | if (GNUNET_OK != GNUNET_SERVER_mst_receive (mst, |
4296 | n, | 4159 | n, |
4297 | &buf[sizeof (struct EncryptedMessage)], | 4160 | &buf[sizeof |
4298 | size - sizeof (struct EncryptedMessage), | 4161 | (struct EncryptedMessage)], |
4299 | GNUNET_YES, GNUNET_NO)) | 4162 | size - |
4163 | sizeof (struct EncryptedMessage), | ||
4164 | GNUNET_YES, GNUNET_NO)) | ||
4300 | GNUNET_break_op (0); | 4165 | GNUNET_break_op (0); |
4301 | } | 4166 | } |
4302 | 4167 | ||
@@ -4314,8 +4179,8 @@ static void | |||
4314 | handle_transport_receive (void *cls, | 4179 | handle_transport_receive (void *cls, |
4315 | const struct GNUNET_PeerIdentity *peer, | 4180 | const struct GNUNET_PeerIdentity *peer, |
4316 | const struct GNUNET_MessageHeader *message, | 4181 | const struct GNUNET_MessageHeader *message, |
4317 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4182 | const struct GNUNET_TRANSPORT_ATS_Information *ats, |
4318 | uint32_t ats_count) | 4183 | uint32_t ats_count) |
4319 | { | 4184 | { |
4320 | struct Neighbour *n; | 4185 | struct Neighbour *n; |
4321 | struct GNUNET_TIME_Absolute now; | 4186 | struct GNUNET_TIME_Absolute now; |
@@ -4327,134 +4192,130 @@ handle_transport_receive (void *cls, | |||
4327 | #if DEBUG_CORE > 1 | 4192 | #if DEBUG_CORE > 1 |
4328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4193 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4329 | "Received message of type %u from `%4s', demultiplexing.\n", | 4194 | "Received message of type %u from `%4s', demultiplexing.\n", |
4330 | (unsigned int) ntohs (message->type), | 4195 | (unsigned int) ntohs (message->type), GNUNET_i2s (peer)); |
4331 | GNUNET_i2s (peer)); | ||
4332 | #endif | 4196 | #endif |
4333 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 4197 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
4334 | { | 4198 | { |
4335 | GNUNET_break (0); | 4199 | GNUNET_break (0); |
4336 | return; | 4200 | return; |
4337 | } | 4201 | } |
4338 | n = find_neighbour (peer); | 4202 | n = find_neighbour (peer); |
4339 | if ( (n == NULL) || (GNUNET_NO == n->is_connected) ) | 4203 | if ((n == NULL) || (GNUNET_NO == n->is_connected)) |
4340 | { | 4204 | { |
4341 | /* received message from peer that is not connected!? */ | 4205 | /* received message from peer that is not connected!? */ |
4342 | GNUNET_break (0); | 4206 | GNUNET_break (0); |
4343 | return; | 4207 | return; |
4344 | } | 4208 | } |
4345 | changed = GNUNET_NO; | 4209 | changed = GNUNET_NO; |
4346 | up = (n->status == PEER_STATE_KEY_CONFIRMED); | 4210 | up = (n->status == PEER_STATE_KEY_CONFIRMED); |
4347 | type = ntohs (message->type); | 4211 | type = ntohs (message->type); |
4348 | size = ntohs (message->size); | 4212 | size = ntohs (message->size); |
4349 | switch (type) | 4213 | switch (type) |
4214 | { | ||
4215 | case GNUNET_MESSAGE_TYPE_CORE_SET_KEY: | ||
4216 | if (size != sizeof (struct SetKeyMessage)) | ||
4217 | { | ||
4218 | GNUNET_break_op (0); | ||
4219 | return; | ||
4220 | } | ||
4221 | GNUNET_STATISTICS_update (stats, | ||
4222 | gettext_noop ("# session keys received"), | ||
4223 | 1, GNUNET_NO); | ||
4224 | handle_set_key (n, (const struct SetKeyMessage *) message, ats, ats_count); | ||
4225 | break; | ||
4226 | case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: | ||
4227 | if (size < sizeof (struct EncryptedMessage) + | ||
4228 | sizeof (struct GNUNET_MessageHeader)) | ||
4229 | { | ||
4230 | GNUNET_break_op (0); | ||
4231 | return; | ||
4232 | } | ||
4233 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | ||
4234 | (n->status != PEER_STATE_KEY_CONFIRMED)) | ||
4350 | { | 4235 | { |
4351 | case GNUNET_MESSAGE_TYPE_CORE_SET_KEY: | ||
4352 | if (size != sizeof (struct SetKeyMessage)) | ||
4353 | { | ||
4354 | GNUNET_break_op (0); | ||
4355 | return; | ||
4356 | } | ||
4357 | GNUNET_STATISTICS_update (stats, | 4236 | GNUNET_STATISTICS_update (stats, |
4358 | gettext_noop ("# session keys received"), | 4237 | gettext_noop |
4359 | 1, | 4238 | ("# failed to decrypt message (no session key)"), |
4360 | GNUNET_NO); | 4239 | 1, GNUNET_NO); |
4361 | handle_set_key (n, | 4240 | send_key (n); |
4362 | (const struct SetKeyMessage *) message, | 4241 | return; |
4363 | ats, ats_count); | 4242 | } |
4364 | break; | 4243 | handle_encrypted_message (n, |
4365 | case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE: | 4244 | (const struct EncryptedMessage *) message, |
4366 | if (size < sizeof (struct EncryptedMessage) + | 4245 | ats, ats_count); |
4367 | sizeof (struct GNUNET_MessageHeader)) | 4246 | break; |
4368 | { | 4247 | case GNUNET_MESSAGE_TYPE_CORE_PING: |
4369 | GNUNET_break_op (0); | 4248 | if (size != sizeof (struct PingMessage)) |
4370 | return; | 4249 | { |
4371 | } | 4250 | GNUNET_break_op (0); |
4372 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | 4251 | return; |
4373 | (n->status != PEER_STATE_KEY_CONFIRMED)) | 4252 | } |
4374 | { | 4253 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"), |
4375 | GNUNET_STATISTICS_update (stats, | 4254 | 1, GNUNET_NO); |
4376 | gettext_noop ("# failed to decrypt message (no session key)"), | 4255 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
4377 | 1, | 4256 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
4378 | GNUNET_NO); | 4257 | { |
4379 | send_key (n); | ||
4380 | return; | ||
4381 | } | ||
4382 | handle_encrypted_message (n, | ||
4383 | (const struct EncryptedMessage *) message, | ||
4384 | ats, ats_count); | ||
4385 | break; | ||
4386 | case GNUNET_MESSAGE_TYPE_CORE_PING: | ||
4387 | if (size != sizeof (struct PingMessage)) | ||
4388 | { | ||
4389 | GNUNET_break_op (0); | ||
4390 | return; | ||
4391 | } | ||
4392 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PING messages received"), 1, GNUNET_NO); | ||
4393 | if ((n->status != PEER_STATE_KEY_RECEIVED) && | ||
4394 | (n->status != PEER_STATE_KEY_CONFIRMED)) | ||
4395 | { | ||
4396 | #if DEBUG_CORE > 1 | 4258 | #if DEBUG_CORE > 1 |
4397 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4398 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", | 4260 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", |
4399 | "PING", GNUNET_i2s (&n->peer)); | 4261 | "PING", GNUNET_i2s (&n->peer)); |
4400 | #endif | 4262 | #endif |
4401 | GNUNET_free_non_null (n->pending_ping); | 4263 | GNUNET_free_non_null (n->pending_ping); |
4402 | n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage)); | 4264 | n->pending_ping = GNUNET_malloc (sizeof (struct PingMessage)); |
4403 | memcpy (n->pending_ping, message, sizeof (struct PingMessage)); | 4265 | memcpy (n->pending_ping, message, sizeof (struct PingMessage)); |
4404 | return; | 4266 | return; |
4405 | } | 4267 | } |
4406 | handle_ping (n, (const struct PingMessage *) message, | 4268 | handle_ping (n, (const struct PingMessage *) message, ats, ats_count); |
4407 | ats, ats_count); | 4269 | break; |
4408 | break; | 4270 | case GNUNET_MESSAGE_TYPE_CORE_PONG: |
4409 | case GNUNET_MESSAGE_TYPE_CORE_PONG: | 4271 | if (size != sizeof (struct PongMessage)) |
4410 | if (size != sizeof (struct PongMessage)) | 4272 | { |
4411 | { | 4273 | GNUNET_break_op (0); |
4412 | GNUNET_break_op (0); | 4274 | return; |
4413 | return; | 4275 | } |
4414 | } | 4276 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"), |
4415 | GNUNET_STATISTICS_update (stats, gettext_noop ("# PONG messages received"), 1, GNUNET_NO); | 4277 | 1, GNUNET_NO); |
4416 | if ( (n->status != PEER_STATE_KEY_RECEIVED) && | 4278 | if ((n->status != PEER_STATE_KEY_RECEIVED) && |
4417 | (n->status != PEER_STATE_KEY_CONFIRMED) ) | 4279 | (n->status != PEER_STATE_KEY_CONFIRMED)) |
4418 | { | 4280 | { |
4419 | #if DEBUG_CORE > 1 | 4281 | #if DEBUG_CORE > 1 |
4420 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4282 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4421 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", | 4283 | "Core service receives `%s' request from `%4s' but have not processed key; marking as pending.\n", |
4422 | "PONG", GNUNET_i2s (&n->peer)); | 4284 | "PONG", GNUNET_i2s (&n->peer)); |
4423 | #endif | 4285 | #endif |
4424 | GNUNET_free_non_null (n->pending_pong); | 4286 | GNUNET_free_non_null (n->pending_pong); |
4425 | n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage)); | 4287 | n->pending_pong = GNUNET_malloc (sizeof (struct PongMessage)); |
4426 | memcpy (n->pending_pong, message, sizeof (struct PongMessage)); | 4288 | memcpy (n->pending_pong, message, sizeof (struct PongMessage)); |
4427 | return; | ||
4428 | } | ||
4429 | handle_pong (n, (const struct PongMessage *) message, | ||
4430 | ats, ats_count); | ||
4431 | break; | ||
4432 | default: | ||
4433 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4434 | _("Unsupported message of type %u received.\n"), | ||
4435 | (unsigned int) type); | ||
4436 | return; | 4289 | return; |
4437 | } | 4290 | } |
4291 | handle_pong (n, (const struct PongMessage *) message, ats, ats_count); | ||
4292 | break; | ||
4293 | default: | ||
4294 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
4295 | _("Unsupported message of type %u received.\n"), | ||
4296 | (unsigned int) type); | ||
4297 | return; | ||
4298 | } | ||
4438 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 4299 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
4300 | { | ||
4301 | now = GNUNET_TIME_absolute_get (); | ||
4302 | n->last_activity = now; | ||
4303 | changed = GNUNET_YES; | ||
4304 | if (!up) | ||
4439 | { | 4305 | { |
4440 | now = GNUNET_TIME_absolute_get (); | 4306 | GNUNET_STATISTICS_update (stats, |
4441 | n->last_activity = now; | 4307 | gettext_noop ("# established sessions"), |
4442 | changed = GNUNET_YES; | 4308 | 1, GNUNET_NO); |
4443 | if (!up) | 4309 | n->time_established = now; |
4444 | { | ||
4445 | GNUNET_STATISTICS_update (stats, | ||
4446 | gettext_noop ("# established sessions"), | ||
4447 | 1, | ||
4448 | GNUNET_NO); | ||
4449 | n->time_established = now; | ||
4450 | } | ||
4451 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
4452 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
4453 | n->keep_alive_task | ||
4454 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), | ||
4455 | &send_keep_alive, | ||
4456 | n); | ||
4457 | } | 4310 | } |
4311 | if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) | ||
4312 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | ||
4313 | n->keep_alive_task | ||
4314 | = | ||
4315 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide | ||
4316 | (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | ||
4317 | 2), &send_keep_alive, n); | ||
4318 | } | ||
4458 | if (changed) | 4319 | if (changed) |
4459 | handle_peer_status_change (n); | 4320 | handle_peer_status_change (n); |
4460 | } | 4321 | } |
@@ -4469,7 +4330,7 @@ handle_transport_receive (void *cls, | |||
4469 | */ | 4330 | */ |
4470 | static void | 4331 | static void |
4471 | neighbour_quota_update (void *cls, | 4332 | neighbour_quota_update (void *cls, |
4472 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 4333 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
4473 | { | 4334 | { |
4474 | struct Neighbour *n = cls; | 4335 | struct Neighbour *n = cls; |
4475 | struct GNUNET_BANDWIDTH_Value32NBO q_in; | 4336 | struct GNUNET_BANDWIDTH_Value32NBO q_in; |
@@ -4484,27 +4345,28 @@ neighbour_quota_update (void *cls, | |||
4484 | 4345 | ||
4485 | #if DEBUG_CORE > 1 | 4346 | #if DEBUG_CORE > 1 |
4486 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4347 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4487 | "Neighbour quota update calculation running for peer `%4s'\n", | 4348 | "Neighbour quota update calculation running for peer `%4s'\n", |
4488 | GNUNET_i2s (&n->peer)); | 4349 | GNUNET_i2s (&n->peer)); |
4489 | #endif | 4350 | #endif |
4490 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; | 4351 | n->quota_update_task = GNUNET_SCHEDULER_NO_TASK; |
4491 | /* calculate relative preference among all neighbours; | 4352 | /* calculate relative preference among all neighbours; |
4492 | divides by a bit more to avoid division by zero AND to | 4353 | * divides by a bit more to avoid division by zero AND to |
4493 | account for possibility of new neighbours joining any time | 4354 | * account for possibility of new neighbours joining any time |
4494 | AND to convert to double... */ | 4355 | * AND to convert to double... */ |
4495 | neighbour_count = GNUNET_CONTAINER_multihashmap_size (neighbours); | 4356 | neighbour_count = GNUNET_CONTAINER_multihashmap_size (neighbours); |
4496 | if (neighbour_count == 0) | 4357 | if (neighbour_count == 0) |
4497 | return; | 4358 | return; |
4498 | if (preference_sum == 0) | 4359 | if (preference_sum == 0) |
4499 | { | 4360 | { |
4500 | pref_rel = 1.0 / (double) neighbour_count; | 4361 | pref_rel = 1.0 / (double) neighbour_count; |
4501 | } | 4362 | } |
4502 | else | 4363 | else |
4503 | { | 4364 | { |
4504 | pref_rel = (double) n->current_preference / preference_sum; | 4365 | pref_rel = (double) n->current_preference / preference_sum; |
4505 | } | 4366 | } |
4506 | need_per_peer = GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, | 4367 | need_per_peer = |
4507 | GNUNET_TIME_UNIT_SECONDS); | 4368 | GNUNET_BANDWIDTH_value_get_available_until (MIN_BANDWIDTH_PER_PEER, |
4369 | GNUNET_TIME_UNIT_SECONDS); | ||
4508 | need_per_second = need_per_peer * neighbour_count; | 4370 | need_per_second = need_per_peer * neighbour_count; |
4509 | 4371 | ||
4510 | /* calculate inbound bandwidth per peer */ | 4372 | /* calculate inbound bandwidth per peer */ |
@@ -4528,43 +4390,45 @@ neighbour_quota_update (void *cls, | |||
4528 | q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); | 4390 | q_out = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); |
4529 | n->bw_out_internal_limit = q_out; | 4391 | n->bw_out_internal_limit = q_out; |
4530 | 4392 | ||
4531 | q_out_min = GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, n->bw_out_internal_limit); | 4393 | q_out_min = |
4394 | GNUNET_BANDWIDTH_value_min (n->bw_out_external_limit, | ||
4395 | n->bw_out_internal_limit); | ||
4532 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out); | 4396 | GNUNET_BANDWIDTH_tracker_update_quota (&n->available_send_window, n->bw_out); |
4533 | 4397 | ||
4534 | /* check if we want to disconnect for good due to inactivity */ | 4398 | /* check if we want to disconnect for good due to inactivity */ |
4535 | if ( (GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > 0) && | 4399 | if ((GNUNET_TIME_absolute_get_duration (get_neighbour_timeout (n)).rel_value > |
4536 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value) ) | 4400 | 0) && |
4537 | { | 4401 | (GNUNET_TIME_absolute_get_duration (n->time_established).rel_value > |
4402 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value)) | ||
4403 | { | ||
4538 | #if DEBUG_CORE | 4404 | #if DEBUG_CORE |
4539 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4405 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4540 | "Forcing disconnect of `%4s' due to inactivity\n", | 4406 | "Forcing disconnect of `%4s' due to inactivity\n", |
4541 | GNUNET_i2s (&n->peer)); | 4407 | GNUNET_i2s (&n->peer)); |
4542 | #endif | 4408 | #endif |
4543 | q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */ | 4409 | q_in = GNUNET_BANDWIDTH_value_init (0); /* force disconnect */ |
4544 | } | 4410 | } |
4545 | #if DEBUG_CORE_QUOTA | 4411 | #if DEBUG_CORE_QUOTA |
4546 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4547 | "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", | 4413 | "Current quota for `%4s' is %u/%llu b/s in (old: %u b/s) / %u out (%u internal)\n", |
4548 | GNUNET_i2s (&n->peer), | 4414 | GNUNET_i2s (&n->peer), |
4549 | (unsigned int) ntohl (q_in.value__), | 4415 | (unsigned int) ntohl (q_in.value__), |
4550 | bandwidth_target_out_bps, | 4416 | bandwidth_target_out_bps, |
4551 | (unsigned int) ntohl (n->bw_in.value__), | 4417 | (unsigned int) ntohl (n->bw_in.value__), |
4552 | (unsigned int) ntohl (n->bw_out.value__), | 4418 | (unsigned int) ntohl (n->bw_out.value__), |
4553 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); | 4419 | (unsigned int) ntohl (n->bw_out_internal_limit.value__)); |
4554 | #endif | 4420 | #endif |
4555 | if ((n->bw_in.value__ != q_in.value__) || (n->bw_out.value__ != q_out_min.value__)) | 4421 | if ((n->bw_in.value__ != q_in.value__) || |
4556 | { | 4422 | (n->bw_out.value__ != q_out_min.value__)) |
4557 | if (n->bw_in.value__ != q_in.value__) | 4423 | { |
4558 | n->bw_in = q_in; | 4424 | if (n->bw_in.value__ != q_in.value__) |
4559 | if (n->bw_out.value__ != q_out_min.value__) | 4425 | n->bw_in = q_in; |
4560 | n->bw_out = q_out_min; | 4426 | if (n->bw_out.value__ != q_out_min.value__) |
4561 | if (GNUNET_YES == n->is_connected) | 4427 | n->bw_out = q_out_min; |
4562 | GNUNET_TRANSPORT_set_quota (transport, | 4428 | if (GNUNET_YES == n->is_connected) |
4563 | &n->peer, | 4429 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4564 | n->bw_in, | 4430 | handle_peer_status_change (n); |
4565 | n->bw_out); | 4431 | } |
4566 | handle_peer_status_change (n); | ||
4567 | } | ||
4568 | schedule_quota_update (n); | 4432 | schedule_quota_update (n); |
4569 | } | 4433 | } |
4570 | 4434 | ||
@@ -4581,52 +4445,45 @@ neighbour_quota_update (void *cls, | |||
4581 | static void | 4445 | static void |
4582 | handle_transport_notify_connect (void *cls, | 4446 | handle_transport_notify_connect (void *cls, |
4583 | const struct GNUNET_PeerIdentity *peer, | 4447 | const struct GNUNET_PeerIdentity *peer, |
4584 | const struct GNUNET_TRANSPORT_ATS_Information *ats, | 4448 | const struct GNUNET_TRANSPORT_ATS_Information |
4585 | uint32_t ats_count) | 4449 | *ats, uint32_t ats_count) |
4586 | { | 4450 | { |
4587 | struct Neighbour *n; | 4451 | struct Neighbour *n; |
4588 | 4452 | ||
4589 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 4453 | if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
4590 | { | 4454 | { |
4591 | GNUNET_break (0); | 4455 | GNUNET_break (0); |
4592 | return; | 4456 | return; |
4593 | } | 4457 | } |
4594 | n = find_neighbour (peer); | 4458 | n = find_neighbour (peer); |
4595 | if (n != NULL) | 4459 | if (n != NULL) |
4460 | { | ||
4461 | if (GNUNET_YES == n->is_connected) | ||
4596 | { | 4462 | { |
4597 | if (GNUNET_YES == n->is_connected) | 4463 | /* duplicate connect notification!? */ |
4598 | { | 4464 | GNUNET_break (0); |
4599 | /* duplicate connect notification!? */ | 4465 | return; |
4600 | GNUNET_break (0); | ||
4601 | return; | ||
4602 | } | ||
4603 | } | 4466 | } |
4467 | } | ||
4604 | else | 4468 | else |
4605 | { | 4469 | { |
4606 | n = create_neighbour (peer); | 4470 | n = create_neighbour (peer); |
4607 | } | 4471 | } |
4608 | GNUNET_STATISTICS_update (stats, | 4472 | GNUNET_STATISTICS_update (stats, |
4609 | gettext_noop ("# peers connected (transport)"), | 4473 | gettext_noop ("# peers connected (transport)"), |
4610 | 1, | 4474 | 1, GNUNET_NO); |
4611 | GNUNET_NO); | 4475 | n->is_connected = GNUNET_YES; |
4612 | n->is_connected = GNUNET_YES; | ||
4613 | update_neighbour_performance (n, ats, ats_count); | 4476 | update_neighbour_performance (n, ats, ats_count); |
4614 | GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, | 4477 | GNUNET_BANDWIDTH_tracker_init (&n->available_send_window, |
4615 | n->bw_out, | 4478 | n->bw_out, MAX_WINDOW_TIME_S); |
4616 | MAX_WINDOW_TIME_S); | ||
4617 | GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, | 4479 | GNUNET_BANDWIDTH_tracker_init (&n->available_recv_window, |
4618 | n->bw_in, | 4480 | n->bw_in, MAX_WINDOW_TIME_S); |
4619 | MAX_WINDOW_TIME_S); | ||
4620 | #if DEBUG_CORE | 4481 | #if DEBUG_CORE |
4621 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4482 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4622 | "Received connection from `%4s'.\n", | 4483 | "Received connection from `%4s'.\n", GNUNET_i2s (&n->peer)); |
4623 | GNUNET_i2s (&n->peer)); | ||
4624 | #endif | 4484 | #endif |
4625 | GNUNET_TRANSPORT_set_quota (transport, | 4485 | GNUNET_TRANSPORT_set_quota (transport, &n->peer, n->bw_in, n->bw_out); |
4626 | &n->peer, | 4486 | send_key (n); |
4627 | n->bw_in, | ||
4628 | n->bw_out); | ||
4629 | send_key (n); | ||
4630 | } | 4487 | } |
4631 | 4488 | ||
4632 | 4489 | ||
@@ -4648,67 +4505,65 @@ handle_transport_notify_disconnect (void *cls, | |||
4648 | 4505 | ||
4649 | #if DEBUG_CORE | 4506 | #if DEBUG_CORE |
4650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4507 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4651 | "Peer `%4s' disconnected from us; received notification from transport.\n", | 4508 | "Peer `%4s' disconnected from us; received notification from transport.\n", |
4652 | GNUNET_i2s (peer)); | 4509 | GNUNET_i2s (peer)); |
4653 | #endif | 4510 | #endif |
4654 | n = find_neighbour (peer); | 4511 | n = find_neighbour (peer); |
4655 | if (n == NULL) | 4512 | if (n == NULL) |
4656 | { | 4513 | { |
4657 | GNUNET_break (0); | 4514 | GNUNET_break (0); |
4658 | return; | 4515 | return; |
4659 | } | 4516 | } |
4660 | GNUNET_break (n->is_connected == GNUNET_YES); | 4517 | GNUNET_break (n->is_connected == GNUNET_YES); |
4661 | if (n->status == PEER_STATE_KEY_CONFIRMED) | 4518 | if (n->status == PEER_STATE_KEY_CONFIRMED) |
4662 | { | 4519 | { |
4663 | cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); | 4520 | cnm.header.size = htons (sizeof (struct DisconnectNotifyMessage)); |
4664 | cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); | 4521 | cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); |
4665 | cnm.reserved = htonl (0); | 4522 | cnm.reserved = htonl (0); |
4666 | cnm.peer = *peer; | 4523 | cnm.peer = *peer; |
4667 | send_to_all_clients (&cnm.header, GNUNET_NO, GNUNET_CORE_OPTION_SEND_DISCONNECT); | 4524 | send_to_all_clients (&cnm.header, GNUNET_NO, |
4668 | GNUNET_STATISTICS_update (stats, | 4525 | GNUNET_CORE_OPTION_SEND_DISCONNECT); |
4669 | gettext_noop ("# established sessions"), | 4526 | GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"), |
4670 | -1, | 4527 | -1, GNUNET_NO); |
4671 | GNUNET_NO); | 4528 | } |
4672 | } | ||
4673 | 4529 | ||
4674 | /* On transport disconnect transport doesn't cancel requests, so must do so here. */ | 4530 | /* On transport disconnect transport doesn't cancel requests, so must do so here. */ |
4675 | if (n->th != NULL) | 4531 | if (n->th != NULL) |
4676 | { | 4532 | { |
4677 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); | 4533 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); |
4678 | n->th = NULL; | 4534 | n->th = NULL; |
4679 | } | 4535 | } |
4680 | if (GNUNET_SCHEDULER_NO_TASK != n->keep_alive_task) | 4536 | if (GNUNET_SCHEDULER_NO_TASK != n->keep_alive_task) |
4681 | { | 4537 | { |
4682 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); | 4538 | GNUNET_SCHEDULER_cancel (n->keep_alive_task); |
4683 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; | 4539 | n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; |
4684 | } | 4540 | } |
4685 | n->is_connected = GNUNET_NO; | 4541 | n->is_connected = GNUNET_NO; |
4686 | n->status = PEER_STATE_DOWN; | 4542 | n->status = PEER_STATE_DOWN; |
4687 | while (NULL != (car = n->active_client_request_head)) | 4543 | while (NULL != (car = n->active_client_request_head)) |
4688 | { | 4544 | { |
4689 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, | 4545 | GNUNET_CONTAINER_DLL_remove (n->active_client_request_head, |
4690 | n->active_client_request_tail, | 4546 | n->active_client_request_tail, car); |
4691 | car); | 4547 | GNUNET_assert (GNUNET_YES == |
4692 | GNUNET_assert (GNUNET_YES == | 4548 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, |
4693 | GNUNET_CONTAINER_multihashmap_remove (car->client->requests, | 4549 | &n->peer.hashPubKey, |
4694 | &n->peer.hashPubKey, | 4550 | car)); |
4695 | car)); | 4551 | GNUNET_free (car); |
4696 | GNUNET_free (car); | 4552 | } |
4697 | } | ||
4698 | 4553 | ||
4699 | GNUNET_STATISTICS_update (stats, | 4554 | GNUNET_STATISTICS_update (stats, |
4700 | gettext_noop ("# peers connected (transport)"), | 4555 | gettext_noop ("# peers connected (transport)"), |
4701 | -1, | 4556 | -1, GNUNET_NO); |
4702 | GNUNET_NO); | ||
4703 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) | 4557 | if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) |
4704 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); | 4558 | GNUNET_SCHEDULER_cancel (n->dead_clean_task); |
4705 | left = GNUNET_TIME_relative_subtract (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 4559 | left = |
4706 | GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT); | 4560 | GNUNET_TIME_relative_subtract (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
4707 | n->last_activity = GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), | 4561 | GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT); |
4708 | left); | 4562 | n->last_activity = |
4709 | n->dead_clean_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, | 4563 | GNUNET_TIME_absolute_subtract (GNUNET_TIME_absolute_get (), left); |
4710 | &consider_free_task, | 4564 | n->dead_clean_task = |
4711 | n); | 4565 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_DISCONNECT_SESSION_TIMEOUT, |
4566 | &consider_free_task, n); | ||
4712 | } | 4567 | } |
4713 | 4568 | ||
4714 | 4569 | ||
@@ -4716,9 +4571,7 @@ handle_transport_notify_disconnect (void *cls, | |||
4716 | * Wrapper around 'free_neighbour'; helper for 'cleaning_task'. | 4571 | * Wrapper around 'free_neighbour'; helper for 'cleaning_task'. |
4717 | */ | 4572 | */ |
4718 | static int | 4573 | static int |
4719 | free_neighbour_helper (void *cls, | 4574 | free_neighbour_helper (void *cls, const GNUNET_HashCode * key, void *value) |
4720 | const GNUNET_HashCode *key, | ||
4721 | void *value) | ||
4722 | { | 4575 | { |
4723 | struct Neighbour *n = value; | 4576 | struct Neighbour *n = value; |
4724 | 4577 | ||
@@ -4737,18 +4590,17 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4737 | struct Client *c; | 4590 | struct Client *c; |
4738 | 4591 | ||
4739 | #if DEBUG_CORE | 4592 | #if DEBUG_CORE |
4740 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); |
4741 | "Core service shutting down.\n"); | ||
4742 | #endif | 4594 | #endif |
4743 | GNUNET_assert (transport != NULL); | 4595 | GNUNET_assert (transport != NULL); |
4744 | GNUNET_TRANSPORT_disconnect (transport); | 4596 | GNUNET_TRANSPORT_disconnect (transport); |
4745 | transport = NULL; | 4597 | transport = NULL; |
4746 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, | 4598 | GNUNET_CONTAINER_multihashmap_iterate (neighbours, |
4747 | &free_neighbour_helper, | 4599 | &free_neighbour_helper, NULL); |
4748 | NULL); | ||
4749 | GNUNET_CONTAINER_multihashmap_destroy (neighbours); | 4600 | GNUNET_CONTAINER_multihashmap_destroy (neighbours); |
4750 | neighbours = NULL; | 4601 | neighbours = NULL; |
4751 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), 0, GNUNET_NO); | 4602 | GNUNET_STATISTICS_set (stats, gettext_noop ("# neighbour entries allocated"), |
4603 | 0, GNUNET_NO); | ||
4752 | GNUNET_SERVER_notification_context_destroy (notifier); | 4604 | GNUNET_SERVER_notification_context_destroy (notifier); |
4753 | notifier = NULL; | 4605 | notifier = NULL; |
4754 | while (NULL != (c = clients)) | 4606 | while (NULL != (c = clients)) |
@@ -4784,7 +4636,8 @@ run (void *cls, | |||
4784 | sizeof (struct GNUNET_MessageHeader)}, | 4636 | sizeof (struct GNUNET_MessageHeader)}, |
4785 | {&handle_client_have_peer, NULL, | 4637 | {&handle_client_have_peer, NULL, |
4786 | GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED, | 4638 | GNUNET_MESSAGE_TYPE_CORE_PEER_CONNECTED, |
4787 | sizeof (struct GNUNET_MessageHeader) + sizeof(struct GNUNET_PeerIdentity)}, | 4639 | sizeof (struct GNUNET_MessageHeader) + |
4640 | sizeof (struct GNUNET_PeerIdentity)}, | ||
4788 | {&handle_client_request_info, NULL, | 4641 | {&handle_client_request_info, NULL, |
4789 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO, | 4642 | GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO, |
4790 | sizeof (struct RequestInfoMessage)}, | 4643 | sizeof (struct RequestInfoMessage)}, |
@@ -4800,49 +4653,48 @@ run (void *cls, | |||
4800 | }; | 4653 | }; |
4801 | char *keyfile; | 4654 | char *keyfile; |
4802 | 4655 | ||
4803 | cfg = c; | 4656 | cfg = c; |
4804 | /* parse configuration */ | 4657 | /* parse configuration */ |
4805 | if ( | 4658 | if ((GNUNET_OK != |
4806 | (GNUNET_OK != | 4659 | GNUNET_CONFIGURATION_get_value_number (c, |
4807 | GNUNET_CONFIGURATION_get_value_number (c, | 4660 | "CORE", |
4808 | "CORE", | 4661 | "TOTAL_QUOTA_IN", |
4809 | "TOTAL_QUOTA_IN", | 4662 | &bandwidth_target_in_bps)) || |
4810 | &bandwidth_target_in_bps)) || | 4663 | (GNUNET_OK != |
4811 | (GNUNET_OK != | 4664 | GNUNET_CONFIGURATION_get_value_number (c, |
4812 | GNUNET_CONFIGURATION_get_value_number (c, | 4665 | "CORE", |
4813 | "CORE", | 4666 | "TOTAL_QUOTA_OUT", |
4814 | "TOTAL_QUOTA_OUT", | 4667 | &bandwidth_target_out_bps)) || |
4815 | &bandwidth_target_out_bps)) || | 4668 | (GNUNET_OK != |
4816 | (GNUNET_OK != | 4669 | GNUNET_CONFIGURATION_get_value_filename (c, |
4817 | GNUNET_CONFIGURATION_get_value_filename (c, | 4670 | "GNUNETD", |
4818 | "GNUNETD", | 4671 | "HOSTKEY", &keyfile))) |
4819 | "HOSTKEY", &keyfile))) | 4672 | { |
4820 | { | 4673 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4674 | _ |
4822 | _ | 4675 | ("Core service is lacking key configuration settings. Exiting.\n")); |
4823 | ("Core service is lacking key configuration settings. Exiting.\n")); | 4676 | GNUNET_SCHEDULER_shutdown (); |
4824 | GNUNET_SCHEDULER_shutdown (); | 4677 | return; |
4825 | return; | 4678 | } |
4826 | } | ||
4827 | peerinfo = GNUNET_PEERINFO_connect (cfg); | 4679 | peerinfo = GNUNET_PEERINFO_connect (cfg); |
4828 | if (NULL == peerinfo) | 4680 | if (NULL == peerinfo) |
4829 | { | 4681 | { |
4830 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4682 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4831 | _("Could not access PEERINFO service. Exiting.\n")); | 4683 | _("Could not access PEERINFO service. Exiting.\n")); |
4832 | GNUNET_SCHEDULER_shutdown (); | 4684 | GNUNET_SCHEDULER_shutdown (); |
4833 | GNUNET_free (keyfile); | 4685 | GNUNET_free (keyfile); |
4834 | return; | 4686 | return; |
4835 | } | 4687 | } |
4836 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); | 4688 | my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); |
4837 | GNUNET_free (keyfile); | 4689 | GNUNET_free (keyfile); |
4838 | if (my_private_key == NULL) | 4690 | if (my_private_key == NULL) |
4839 | { | 4691 | { |
4840 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 4692 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
4841 | _("Core service could not access hostkey. Exiting.\n")); | 4693 | _("Core service could not access hostkey. Exiting.\n")); |
4842 | GNUNET_PEERINFO_disconnect (peerinfo); | 4694 | GNUNET_PEERINFO_disconnect (peerinfo); |
4843 | GNUNET_SCHEDULER_shutdown (); | 4695 | GNUNET_SCHEDULER_shutdown (); |
4844 | return; | 4696 | return; |
4845 | } | 4697 | } |
4846 | neighbours = GNUNET_CONTAINER_multihashmap_create (128); | 4698 | neighbours = GNUNET_CONTAINER_multihashmap_create (128); |
4847 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); | 4699 | GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); |
4848 | GNUNET_CRYPTO_hash (&my_public_key, | 4700 | GNUNET_CRYPTO_hash (&my_public_key, |
@@ -4853,12 +4705,12 @@ run (void *cls, | |||
4853 | self.status = PEER_STATE_KEY_CONFIRMED; | 4705 | self.status = PEER_STATE_KEY_CONFIRMED; |
4854 | self.is_connected = GNUNET_YES; | 4706 | self.is_connected = GNUNET_YES; |
4855 | /* setup notification */ | 4707 | /* setup notification */ |
4856 | notifier = GNUNET_SERVER_notification_context_create (server, | 4708 | notifier = GNUNET_SERVER_notification_context_create (server, |
4857 | MAX_NOTIFY_QUEUE); | 4709 | MAX_NOTIFY_QUEUE); |
4858 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); | 4710 | GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); |
4859 | /* setup transport connection */ | 4711 | /* setup transport connection */ |
4860 | transport = GNUNET_TRANSPORT_connect (cfg, | 4712 | transport = GNUNET_TRANSPORT_connect (cfg, |
4861 | &my_identity, | 4713 | &my_identity, |
4862 | NULL, | 4714 | NULL, |
4863 | &handle_transport_receive, | 4715 | &handle_transport_receive, |
4864 | &handle_transport_notify_connect, | 4716 | &handle_transport_notify_connect, |
@@ -4866,15 +4718,15 @@ run (void *cls, | |||
4866 | GNUNET_assert (NULL != transport); | 4718 | GNUNET_assert (NULL != transport); |
4867 | stats = GNUNET_STATISTICS_create ("core", cfg); | 4719 | stats = GNUNET_STATISTICS_create ("core", cfg); |
4868 | 4720 | ||
4869 | GNUNET_STATISTICS_set (stats, | 4721 | GNUNET_STATISTICS_set (stats, |
4870 | gettext_noop ("# discarded CORE_SEND requests"), | 4722 | gettext_noop ("# discarded CORE_SEND requests"), |
4871 | 0, GNUNET_NO); | 4723 | 0, GNUNET_NO); |
4872 | GNUNET_STATISTICS_set (stats, | 4724 | GNUNET_STATISTICS_set (stats, |
4873 | gettext_noop ("# discarded lower priority CORE_SEND requests"), | 4725 | gettext_noop |
4874 | 0, GNUNET_NO); | 4726 | ("# discarded lower priority CORE_SEND requests"), 0, |
4727 | GNUNET_NO); | ||
4875 | 4728 | ||
4876 | mst = GNUNET_SERVER_mst_create (&deliver_message, | 4729 | mst = GNUNET_SERVER_mst_create (&deliver_message, NULL); |
4877 | NULL); | ||
4878 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 4730 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, |
4879 | &cleaning_task, NULL); | 4731 | &cleaning_task, NULL); |
4880 | /* process client requests */ | 4732 | /* process client requests */ |
@@ -4899,8 +4751,7 @@ main (int argc, char *const *argv) | |||
4899 | GNUNET_SERVICE_run (argc, | 4751 | GNUNET_SERVICE_run (argc, |
4900 | argv, | 4752 | argv, |
4901 | "core", | 4753 | "core", |
4902 | GNUNET_SERVICE_OPTION_NONE, | 4754 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; |
4903 | &run, NULL)) ? 0 : 1; | ||
4904 | } | 4755 | } |
4905 | 4756 | ||
4906 | /* end of gnunet-service-core.c */ | 4757 | /* end of gnunet-service-core.c */ |