diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-18 12:58:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-18 12:58:16 +0000 |
commit | 41fb4bc77ef852602063c1723366314ccbefc0a6 (patch) | |
tree | 0d06aaa0076c543c9a073828c04c6c699f8778c4 /src/ats/gnunet-service-ats_addresses.c | |
parent | 9fae47e9f9555b5d7a10b86b7f2de5cd9e6c0c1c (diff) | |
download | gnunet-41fb4bc77ef852602063c1723366314ccbefc0a6.tar.gz gnunet-41fb4bc77ef852602063c1723366314ccbefc0a6.zip |
always use a slot, even if the session is NULL, simplify logic and document what still needs to be fixed
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 182 |
1 files changed, 56 insertions, 126 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 7c9c921cc..abdc40c59 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -482,7 +482,7 @@ free_address (struct ATS_Address *addr) | |||
482 | * @param plugin_addr address | 482 | * @param plugin_addr address |
483 | * @param plugin_addr_len address length | 483 | * @param plugin_addr_len address length |
484 | * @param local_address_info additional local info for the address | 484 | * @param local_address_info additional local info for the address |
485 | * @param session_id session identifier, can be 0 | 485 | * @param session_id session identifier, can never be 0 |
486 | * @return the ATS_Address | 486 | * @return the ATS_Address |
487 | */ | 487 | */ |
488 | static struct ATS_Address * | 488 | static struct ATS_Address * |
@@ -493,9 +493,9 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
493 | uint32_t local_address_info, | 493 | uint32_t local_address_info, |
494 | uint32_t session_id) | 494 | uint32_t session_id) |
495 | { | 495 | { |
496 | struct ATS_Address *aa = NULL; | 496 | struct ATS_Address *aa; |
497 | int c1; | 497 | unsigned int c1; |
498 | int c2; | 498 | unsigned int c2; |
499 | 499 | ||
500 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); | 500 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); |
501 | aa->peer = *peer; | 501 | aa->peer = *peer; |
@@ -505,10 +505,6 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
505 | aa->plugin = GNUNET_strdup (plugin_name); | 505 | aa->plugin = GNUNET_strdup (plugin_name); |
506 | aa->session_id = session_id; | 506 | aa->session_id = session_id; |
507 | aa->local_address_info = local_address_info; | 507 | aa->local_address_info = local_address_info; |
508 | aa->assigned_bw_out = 0; | ||
509 | aa->assigned_bw_in = 0; | ||
510 | aa->last_notified_bw_out = 0; | ||
511 | aa->last_notified_bw_in = 0; | ||
512 | 508 | ||
513 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | 509 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) |
514 | { | 510 | { |
@@ -535,7 +531,7 @@ struct CompareAddressContext | |||
535 | 531 | ||
536 | 532 | ||
537 | /** | 533 | /** |
538 | * Comapre addresses | 534 | * Comapre addresses. |
539 | * | 535 | * |
540 | * @param cls a CompareAddressContext containin the source address | 536 | * @param cls a CompareAddressContext containin the source address |
541 | * @param key peer id | 537 | * @param key peer id |
@@ -654,10 +650,9 @@ find_equivalent_address (struct GAS_Addresses_Handle *handle, | |||
654 | * @param plugin_addr plugin address | 650 | * @param plugin_addr plugin address |
655 | * @param plugin_addr_len length of the plugin address | 651 | * @param plugin_addr_len length of the plugin address |
656 | * @param local_address_info the local address for the address | 652 | * @param local_address_info the local address for the address |
657 | * @param session_id session id, can be 0 | 653 | * @param session_id session id, can never be 0 |
658 | * @return an ATS_address or NULL | 654 | * @return an ATS_address or NULL |
659 | */ | 655 | */ |
660 | |||
661 | static struct ATS_Address * | 656 | static struct ATS_Address * |
662 | find_exact_address (struct GAS_Addresses_Handle *handle, | 657 | find_exact_address (struct GAS_Addresses_Handle *handle, |
663 | const struct GNUNET_PeerIdentity *peer, | 658 | const struct GNUNET_PeerIdentity *peer, |
@@ -724,7 +719,7 @@ get_property_cb (void *cls, const struct ATS_Address *address) | |||
724 | * | 719 | * |
725 | * @param address the address | 720 | * @param address the address |
726 | * @param type the type to extract in HBO | 721 | * @param type the type to extract in HBO |
727 | * @return the value in HBO or GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist | 722 | * @return the value in HBO or #GNUNET_ATS_VALUE_UNDEFINED in HBO if value does not exist |
728 | */ | 723 | */ |
729 | static int | 724 | static int |
730 | get_performance_info (struct ATS_Address *address, uint32_t type) | 725 | get_performance_info (struct ATS_Address *address, uint32_t type) |
@@ -791,15 +786,15 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
791 | local_address_info, session_id); | 786 | local_address_info, session_id); |
792 | atsi_delta = NULL; | 787 | atsi_delta = NULL; |
793 | disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, | 788 | disassemble_ats_information (new_address, atsi, atsi_count, &atsi_delta, |
794 | &atsi_delta_count); | 789 | &atsi_delta_count); |
795 | GNUNET_free_non_null(atsi_delta); | 790 | GNUNET_free_non_null (atsi_delta); |
796 | addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); | 791 | addr_net = get_performance_info (new_address, GNUNET_ATS_NETWORK_TYPE); |
797 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) | 792 | if (GNUNET_ATS_VALUE_UNDEFINED == addr_net) |
798 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; | 793 | addr_net = GNUNET_ATS_NET_UNSPECIFIED; |
799 | 794 | ||
800 | /* Get existing address or address with session == 0 */ | 795 | /* Get existing address or address with session == 0 */ |
801 | existing_address = find_equivalent_address (handle, peer, new_address); | 796 | existing_address = find_equivalent_address (handle, peer, new_address); |
802 | if (existing_address == NULL ) | 797 | if (existing_address == NULL) |
803 | { | 798 | { |
804 | /* Add a new address */ | 799 | /* Add a new address */ |
805 | new_address->t_added = GNUNET_TIME_absolute_get(); | 800 | new_address->t_added = GNUNET_TIME_absolute_get(); |
@@ -957,21 +952,29 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
957 | 952 | ||
958 | if (GNUNET_NO == handle->running) | 953 | if (GNUNET_NO == handle->running) |
959 | return; | 954 | return; |
960 | 955 | GNUNET_assert (NULL != handle->addresses); | |
961 | GNUNET_assert(NULL != handle->addresses); | ||
962 | 956 | ||
963 | /* Get existing address */ | 957 | /* Get existing address */ |
964 | aa = find_exact_address (handle, peer, plugin_name, plugin_addr, | 958 | aa = find_exact_address (handle, peer, plugin_name, plugin_addr, |
965 | plugin_addr_len, local_address_info, session_id); | 959 | plugin_addr_len, |
966 | if (aa == NULL ) | 960 | local_address_info, |
961 | session_id); | ||
962 | if (aa == NULL) | ||
963 | { | ||
964 | GNUNET_break (0); | ||
967 | return; | 965 | return; |
966 | } | ||
968 | if (NULL == aa->solver_information) | 967 | if (NULL == aa->solver_information) |
968 | { | ||
969 | GNUNET_break (0); | ||
969 | return; | 970 | return; |
971 | } | ||
970 | 972 | ||
971 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 973 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
972 | "Received `%s' for peer `%s' address \n", | 974 | "Received `%s' for peer `%s' address \n", |
973 | "ADDRESS UPDATE", | 975 | "ADDRESS UPDATE", |
974 | GNUNET_i2s (peer), aa); | 976 | GNUNET_i2s (peer), |
977 | aa); | ||
975 | 978 | ||
976 | /* Update address */ | 979 | /* Update address */ |
977 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | 980 | aa->t_last_activity = GNUNET_TIME_absolute_get(); |
@@ -1047,11 +1050,7 @@ struct DestroyContext | |||
1047 | 1050 | ||
1048 | 1051 | ||
1049 | /** | 1052 | /** |
1050 | * Delete an address | 1053 | * Delete an address. |
1051 | * | ||
1052 | * If session != 0, just the session is deleted, the address itself still exists | ||
1053 | * If session == 0, remove full address | ||
1054 | * If session == 0 and addrlen == 0, destroy inbound address | ||
1055 | * | 1054 | * |
1056 | * @param cls unused | 1055 | * @param cls unused |
1057 | * @param key unused | 1056 | * @param key unused |
@@ -1072,102 +1071,32 @@ destroy_by_session_id (void *cls, | |||
1072 | memcmp (&aa->peer, | 1071 | memcmp (&aa->peer, |
1073 | &des->peer, | 1072 | &des->peer, |
1074 | sizeof (struct GNUNET_PeerIdentity))); | 1073 | sizeof (struct GNUNET_PeerIdentity))); |
1075 | if (0 == des->session_id) | 1074 | if ( (0 != strcmp (des->plugin, aa->plugin)) || |
1076 | { | 1075 | (aa->addr_len != des->addr_len) || |
1077 | /* Session == 0, remove full address */ | 1076 | (0 != memcmp (des->addr, aa->addr, aa->addr_len))) |
1078 | if ((0 == strcmp (des->plugin, aa->plugin)) | 1077 | return GNUNET_OK; /* wrong entry */ |
1079 | && (aa->addr_len == des->addr_len) | 1078 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1080 | && (0 == memcmp (des->addr, aa->addr, aa->addr_len))) | 1079 | "Deleting full address for peer `%s' session %u %p\n", |
1081 | { | 1080 | GNUNET_i2s (&aa->peer), |
1082 | 1081 | aa->session_id, | |
1083 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1082 | aa); |
1084 | "Deleting full address for peer `%s' session %u %p\n", | 1083 | /* Notify solver about deletion */ |
1085 | GNUNET_i2s (&aa->peer), | 1084 | GNUNET_assert (GNUNET_YES == |
1086 | aa->session_id, | 1085 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, |
1087 | aa); | 1086 | &aa->peer, |
1088 | /* Notify solver about deletion */ | 1087 | aa)); |
1089 | GNUNET_assert (GNUNET_YES == | 1088 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); |
1090 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, | 1089 | GAS_performance_notify_all_clients (&aa->peer, |
1091 | &aa->peer, | 1090 | aa->plugin, |
1092 | aa)); | 1091 | aa->addr, |
1093 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); | 1092 | aa->addr_len, |
1094 | GAS_performance_notify_all_clients (&aa->peer, | 1093 | GNUNET_SYSERR, |
1095 | aa->plugin, | 1094 | NULL, 0, |
1096 | aa->addr, | 1095 | zero_bw, |
1097 | aa->addr_len, | 1096 | zero_bw); |
1098 | GNUNET_SYSERR, | 1097 | free_address (aa); |
1099 | NULL, 0, | 1098 | dc->result = GNUNET_NO; |
1100 | zero_bw, | 1099 | return GNUNET_OK; /* Continue iteration */ |
1101 | zero_bw); | ||
1102 | free_address (aa); | ||
1103 | dc->result = GNUNET_NO; | ||
1104 | return GNUNET_OK; /* Continue iteration */ | ||
1105 | } | ||
1106 | } | ||
1107 | else | ||
1108 | { | ||
1109 | /* Session != 0, just remove session */ | ||
1110 | if (aa->session_id != des->session_id) | ||
1111 | return GNUNET_OK; /* irrelevant */ | ||
1112 | |||
1113 | if ((aa->session_id != 0) && (0 != strcmp (des->plugin, aa->plugin))) | ||
1114 | { | ||
1115 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1116 | "Different plugins during removal: `%s' vs `%s' \n", | ||
1117 | des->plugin, | ||
1118 | aa->plugin); | ||
1119 | GNUNET_break (0); | ||
1120 | return GNUNET_OK; | ||
1121 | } | ||
1122 | if (GNUNET_HELLO_ADDRESS_INFO_INBOUND == | ||
1123 | (aa->local_address_info && GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | ||
1124 | { | ||
1125 | /* Inbound connection died, delete full address */ | ||
1126 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1127 | "Deleting inbound address for peer `%s': `%s' session %u\n", | ||
1128 | GNUNET_i2s (&aa->peer), | ||
1129 | aa->plugin, | ||
1130 | aa->session_id); | ||
1131 | |||
1132 | /* Notify solver about deletion */ | ||
1133 | GNUNET_assert(GNUNET_YES == | ||
1134 | GNUNET_CONTAINER_multipeermap_remove (handle->addresses, | ||
1135 | &aa->peer, aa)); | ||
1136 | handle->env.sf.s_del (handle->solver, aa, GNUNET_NO); | ||
1137 | GAS_performance_notify_all_clients (&aa->peer, | ||
1138 | aa->plugin, | ||
1139 | aa->addr, | ||
1140 | aa->addr_len, | ||
1141 | GNUNET_SYSERR, | ||
1142 | NULL, 0, | ||
1143 | zero_bw, | ||
1144 | zero_bw); | ||
1145 | free_address (aa); | ||
1146 | dc->result = GNUNET_NO; | ||
1147 | return GNUNET_OK; /* Continue iteration */ | ||
1148 | } | ||
1149 | else | ||
1150 | { | ||
1151 | /* Session died */ | ||
1152 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1153 | "Deleting session for peer `%s': `%s' %u\n", | ||
1154 | GNUNET_i2s (&aa->peer), | ||
1155 | aa->plugin, aa->session_id); | ||
1156 | /* Notify solver to delete session */ | ||
1157 | handle->env.sf.s_del (handle->solver, aa, GNUNET_YES); | ||
1158 | aa->session_id = 0; | ||
1159 | GAS_performance_notify_all_clients (&aa->peer, | ||
1160 | aa->plugin, | ||
1161 | aa->addr, | ||
1162 | aa->addr_len, | ||
1163 | GNUNET_NO, | ||
1164 | NULL, 0, | ||
1165 | zero_bw, | ||
1166 | zero_bw); | ||
1167 | return GNUNET_OK; | ||
1168 | } | ||
1169 | } | ||
1170 | return GNUNET_OK; | ||
1171 | } | 1100 | } |
1172 | 1101 | ||
1173 | 1102 | ||
@@ -1180,7 +1109,7 @@ destroy_by_session_id (void *cls, | |||
1180 | * @param plugin_addr plugin address | 1109 | * @param plugin_addr plugin address |
1181 | * @param plugin_addr_len length of the plugin address in @a plugin_addr | 1110 | * @param plugin_addr_len length of the plugin address in @a plugin_addr |
1182 | * @param local_address_info the local address for the address | 1111 | * @param local_address_info the local address for the address |
1183 | * @param session_id session id, can be 0 | 1112 | * @param session_id session id, can never be 0 |
1184 | */ | 1113 | */ |
1185 | void | 1114 | void |
1186 | GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | 1115 | GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, |
@@ -1207,6 +1136,7 @@ GAS_addresses_destroy (struct GAS_Addresses_Handle *handle, | |||
1207 | session_id); | 1136 | session_id); |
1208 | if (NULL == ea) | 1137 | if (NULL == ea) |
1209 | { | 1138 | { |
1139 | GNUNET_break (0); | ||
1210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1140 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1211 | "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", | 1141 | "Tried to destroy unknown address for peer `%s' `%s' session id %u\n", |
1212 | GNUNET_i2s (peer), | 1142 | GNUNET_i2s (peer), |
@@ -1323,7 +1253,7 @@ GAS_addresses_in_use (struct GAS_Addresses_Handle *handle, | |||
1323 | */ | 1253 | */ |
1324 | void | 1254 | void |
1325 | GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, | 1255 | GAS_addresses_request_address_cancel (struct GAS_Addresses_Handle *handle, |
1326 | const struct GNUNET_PeerIdentity *peer) | 1256 | const struct GNUNET_PeerIdentity *peer) |
1327 | { | 1257 | { |
1328 | struct GAS_Addresses_Suggestion_Requests *cur = handle->pending_requests_head; | 1258 | struct GAS_Addresses_Suggestion_Requests *cur = handle->pending_requests_head; |
1329 | 1259 | ||