diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-05 00:53:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-05 00:53:22 +0000 |
commit | 15dd8e6cc1199d611d804853e134882bf13b234a (patch) | |
tree | 7cc90886eabe8d0ffa397a319e12a87042d0ba28 /src/ats/gnunet-service-ats_addresses.c | |
parent | bf6a2c9deeff7a3b384eb029d8267d6099066df3 (diff) | |
download | gnunet-15dd8e6cc1199d611d804853e134882bf13b234a.tar.gz gnunet-15dd8e6cc1199d611d804853e134882bf13b234a.zip |
Various changes:
- removed "in_use" from being passed to ATS, no
longer needed as we tell ATS when we cannot
follow a suggestion by removing the address;
simplifies the code a lot
- better handling of state machine, fallback to
primary session if address switch to new
session timed out
- nicer logging
- more comments
- new testcase failures, because of
#3652, #3651 and #3650 (or more that i missed).
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 167 |
1 files changed, 24 insertions, 143 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8b38120cc..1d2c9d3e5 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2011 Christian Grothoff (and other contributing authors) | 3 | (C) 2011-2015 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -37,7 +37,7 @@ | |||
37 | 37 | ||
38 | /** | 38 | /** |
39 | * NOTE: Do not change this documentation. This documentation is based on | 39 | * NOTE: Do not change this documentation. This documentation is based on |
40 | * gnunet.org:/vcs/fsnsg/ats-paper.git/tech-doku/ats-tech-guide.tex | 40 | * gnunet.org:/vcs/fsnsg/2014-p2p-ats.git/tech-doku/ats-tech-guide.tex |
41 | * use build_txt.sh to generate plaintext output | 41 | * use build_txt.sh to generate plaintext output |
42 | * | 42 | * |
43 | * 1 ATS addresses : ATS address management | 43 | * 1 ATS addresses : ATS address management |
@@ -192,22 +192,10 @@ | |||
192 | * available it will not respond at all If the client is not interested | 192 | * available it will not respond at all If the client is not interested |
193 | * anymore, it has to cancel the address suggestion request. | 193 | * anymore, it has to cancel the address suggestion request. |
194 | * | 194 | * |
195 | * 1.7.6 Suggestions blocks and reset | 195 | * 1.7.6 Address lifecycle |
196 | * | ||
197 | * After suggesting an address it is blocked for ATS_BLOCKING_DELTA sec. to | ||
198 | * prevent the client from being thrashed. If the client requires immediately | ||
199 | * it can reset this block using GAS_addresses_handle_backoff_reset. | ||
200 | * | ||
201 | * 1.7.7 Marking address in use | ||
202 | * | ||
203 | * The client can notify addresses that it successfully uses an address and | ||
204 | * wants this address to be kept by calling GSA_address_in_use. Adresses will | ||
205 | * mark the address as used an notify the solver about the use. | ||
206 | * | ||
207 | * 1.7.8 Address lifecycle | ||
208 | * | 196 | * |
209 | * * (add address) | 197 | * * (add address) |
210 | * * (updated address) || (address in use) | 198 | * * (updated address) |
211 | * * (delete address) | 199 | * * (delete address) |
212 | * | 200 | * |
213 | * 1.8 Bandwidth assignment | 201 | * 1.8 Bandwidth assignment |
@@ -302,7 +290,9 @@ static int ats_mode; | |||
302 | static void *solver; | 290 | static void *solver; |
303 | 291 | ||
304 | /** | 292 | /** |
305 | * Address suggestion requests DLL head | 293 | * Address suggestion requests DLL head. |
294 | * FIXME: This must become a Multipeermap! O(n) operations | ||
295 | * galore instead of O(1)!!! | ||
306 | */ | 296 | */ |
307 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_head; | 297 | static struct GAS_Addresses_Suggestion_Requests *pending_requests_head; |
308 | 298 | ||
@@ -1086,66 +1076,6 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
1086 | 1076 | ||
1087 | 1077 | ||
1088 | /** | 1078 | /** |
1089 | * Notification about active use of an address. | ||
1090 | * in_use == #GNUNET_YES: | ||
1091 | * This address is used to maintain an active connection with a peer. | ||
1092 | * in_use == #GNUNET_NO: | ||
1093 | * This address is no longer used to maintain an active connection with a peer. | ||
1094 | * | ||
1095 | * Note: can only be called with in_use == #GNUNET_NO if called with #GNUNET_YES | ||
1096 | * before | ||
1097 | * | ||
1098 | * @param peer peer | ||
1099 | * @param session_id session id, can be 0 | ||
1100 | * @param in_use #GNUNET_YES if #GNUNET_NO FIXME | ||
1101 | * @return #GNUNET_SYSERR on failure (address unknown ...) | ||
1102 | */ | ||
1103 | int | ||
1104 | GAS_addresses_in_use (const struct GNUNET_PeerIdentity *peer, | ||
1105 | uint32_t session_id, | ||
1106 | int in_use) | ||
1107 | { | ||
1108 | struct ATS_Address *ea; | ||
1109 | |||
1110 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1111 | "Received `%s' for peer `%s'\n", | ||
1112 | "ADDRESS IN USE", | ||
1113 | GNUNET_i2s (peer)); | ||
1114 | if (GNUNET_NO == running) | ||
1115 | return GNUNET_SYSERR; | ||
1116 | ea = find_exact_address (peer, | ||
1117 | session_id); | ||
1118 | if (NULL == ea) | ||
1119 | { | ||
1120 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1121 | "Trying to set unknown address `%s' `%u' to %s \n", | ||
1122 | GNUNET_i2s (peer), | ||
1123 | session_id, | ||
1124 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
1125 | GNUNET_break (0); | ||
1126 | return GNUNET_SYSERR; | ||
1127 | } | ||
1128 | if (ea->used == in_use) | ||
1129 | { | ||
1130 | GNUNET_break (0); | ||
1131 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
1132 | "Address in use called multiple times for peer `%s': %s -> %s \n", | ||
1133 | GNUNET_i2s (peer), | ||
1134 | (GNUNET_NO == ea->used) ? "NO" : "YES", | ||
1135 | (GNUNET_NO == in_use) ? "NO" : "YES"); | ||
1136 | return GNUNET_SYSERR; | ||
1137 | } | ||
1138 | /* Tell solver about update */ | ||
1139 | ea->used = in_use; | ||
1140 | ea->t_last_activity = GNUNET_TIME_absolute_get(); | ||
1141 | env.sf.s_address_update_inuse (solver, | ||
1142 | ea, | ||
1143 | ea->used); | ||
1144 | return GNUNET_OK; | ||
1145 | } | ||
1146 | |||
1147 | |||
1148 | /** | ||
1149 | * Cancel address suggestions for a peer | 1079 | * Cancel address suggestions for a peer |
1150 | * | 1080 | * |
1151 | * @param peer the peer id | 1081 | * @param peer the peer id |
@@ -1169,16 +1099,15 @@ GAS_addresses_request_address_cancel (const struct GNUNET_PeerIdentity *peer) | |||
1169 | 1099 | ||
1170 | if (NULL == cur) | 1100 | if (NULL == cur) |
1171 | { | 1101 | { |
1172 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1102 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1173 | "No address requests pending for peer `%s', cannot remove!\n", | 1103 | "No address requests pending for peer `%s', cannot remove!\n", |
1174 | GNUNET_i2s (peer)); | 1104 | GNUNET_i2s (peer)); |
1175 | return; | 1105 | return; |
1176 | } | 1106 | } |
1177 | env.sf.s_get_stop (solver, peer); | 1107 | env.sf.s_get_stop (solver, peer); |
1178 | GAS_addresses_handle_backoff_reset (peer); | 1108 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1179 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1109 | "Removed request pending for peer `%s\n", |
1180 | "Removed request pending for peer `%s\n", | 1110 | GNUNET_i2s (peer)); |
1181 | GNUNET_i2s (peer)); | ||
1182 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, | 1111 | GNUNET_CONTAINER_DLL_remove (pending_requests_head, |
1183 | pending_requests_tail, | 1112 | pending_requests_tail, |
1184 | cur); | 1113 | cur); |
@@ -1213,10 +1142,10 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | |||
1213 | if (NULL == cur) | 1142 | if (NULL == cur) |
1214 | { | 1143 | { |
1215 | cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests); | 1144 | cur = GNUNET_new (struct GAS_Addresses_Suggestion_Requests); |
1216 | cur->id = (*peer); | 1145 | cur->id = *peer; |
1217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1146 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1218 | "Adding new address suggestion request for `%s'\n", | 1147 | "Adding new address suggestion request for `%s'\n", |
1219 | GNUNET_i2s (peer)); | 1148 | GNUNET_i2s (peer)); |
1220 | GNUNET_CONTAINER_DLL_insert (pending_requests_head, | 1149 | GNUNET_CONTAINER_DLL_insert (pending_requests_head, |
1221 | pending_requests_tail, | 1150 | pending_requests_tail, |
1222 | cur); | 1151 | cur); |
@@ -1249,55 +1178,6 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | |||
1249 | aa->block_interval); | 1178 | aa->block_interval); |
1250 | } | 1179 | } |
1251 | 1180 | ||
1252 | /** | ||
1253 | * Iterator to reset address blocking | ||
1254 | * | ||
1255 | * @param cls not used | ||
1256 | * @param key the peer | ||
1257 | * @param value the address to reset | ||
1258 | * @return #GNUNET_OK to continue | ||
1259 | */ | ||
1260 | static int | ||
1261 | reset_address_it (void *cls, | ||
1262 | const struct GNUNET_PeerIdentity *key, | ||
1263 | void *value) | ||
1264 | { | ||
1265 | struct ATS_Address *aa = value; | ||
1266 | |||
1267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1268 | "Resetting interval for peer `%s' address %p from %llu to 0\n", | ||
1269 | GNUNET_i2s (&aa->peer), | ||
1270 | aa, | ||
1271 | aa->block_interval); | ||
1272 | aa->blocked_until = GNUNET_TIME_UNIT_ZERO_ABS; | ||
1273 | aa->block_interval = GNUNET_TIME_UNIT_ZERO; | ||
1274 | return GNUNET_OK; | ||
1275 | } | ||
1276 | |||
1277 | |||
1278 | /** | ||
1279 | * Reset suggestion backoff for a peer | ||
1280 | * | ||
1281 | * Suggesting addresses is blocked for ATS_BLOCKING_DELTA. Blocking can be | ||
1282 | * reset using this function | ||
1283 | * | ||
1284 | * @param peer the peer id | ||
1285 | */ | ||
1286 | void | ||
1287 | GAS_addresses_handle_backoff_reset (const struct GNUNET_PeerIdentity *peer) | ||
1288 | { | ||
1289 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1290 | "Received `%s' for peer `%s'\n", | ||
1291 | "RESET BACKOFF", | ||
1292 | GNUNET_i2s (peer)); | ||
1293 | |||
1294 | GNUNET_break(GNUNET_SYSERR != | ||
1295 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, | ||
1296 | peer, | ||
1297 | &reset_address_it, | ||
1298 | NULL)); | ||
1299 | } | ||
1300 | |||
1301 | 1181 | ||
1302 | /** | 1182 | /** |
1303 | * Solver information callback | 1183 | * Solver information callback |
@@ -1741,7 +1621,9 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
1741 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 1621 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); |
1742 | 1622 | ||
1743 | for (cur = pending_requests_head;NULL != cur; cur = cur->next) | 1623 | for (cur = pending_requests_head;NULL != cur; cur = cur->next) |
1744 | if (0 == memcmp (&address->peer, &cur->id, sizeof(cur->id))) | 1624 | if (0 == memcmp (&address->peer, |
1625 | &cur->id, | ||
1626 | sizeof(cur->id))) | ||
1745 | break; /* we have an address request pending*/ | 1627 | break; /* we have an address request pending*/ |
1746 | if (NULL == cur) | 1628 | if (NULL == cur) |
1747 | { | 1629 | { |
@@ -1891,10 +1773,10 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1891 | GNUNET_asprintf (&plugin, | 1773 | GNUNET_asprintf (&plugin, |
1892 | "libgnunet_plugin_ats_%s", | 1774 | "libgnunet_plugin_ats_%s", |
1893 | plugin_short); | 1775 | plugin_short); |
1894 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1776 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1895 | _("Initializing solver `%s '`%s'\n"), | 1777 | "Initializing solver `%s '`%s'\n", |
1896 | plugin_short, | 1778 | plugin_short, |
1897 | plugin); | 1779 | plugin); |
1898 | if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) | 1780 | if (NULL == (solver = GNUNET_PLUGIN_load (plugin, &env))) |
1899 | { | 1781 | { |
1900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1782 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1904,7 +1786,6 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1904 | } | 1786 | } |
1905 | 1787 | ||
1906 | GNUNET_assert (NULL != env.sf.s_add); | 1788 | GNUNET_assert (NULL != env.sf.s_add); |
1907 | GNUNET_assert (NULL != env.sf.s_address_update_inuse); | ||
1908 | GNUNET_assert (NULL != env.sf.s_address_update_property); | 1789 | GNUNET_assert (NULL != env.sf.s_address_update_property); |
1909 | GNUNET_assert (NULL != env.sf.s_address_update_session); | 1790 | GNUNET_assert (NULL != env.sf.s_address_update_session); |
1910 | GNUNET_assert (NULL != env.sf.s_address_update_network); | 1791 | GNUNET_assert (NULL != env.sf.s_address_update_network); |