diff options
Diffstat (limited to 'src/ats')
41 files changed, 9665 insertions, 9641 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h index 7c9559495..3501860f3 100644 --- a/src/ats/ats.h +++ b/src/ats/ats.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats.h | 21 | * @file ats/ats.h |
22 | * @brief automatic transport selection messages | 22 | * @brief automatic transport selection messages |
@@ -34,9 +34,7 @@ | |||
34 | * Flag used to indicate which type of client is connecting | 34 | * Flag used to indicate which type of client is connecting |
35 | * to the ATS service. | 35 | * to the ATS service. |
36 | */ | 36 | */ |
37 | enum StartFlag | 37 | enum StartFlag { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * This is a scheduling client (aka transport service) | 39 | * This is a scheduling client (aka transport service) |
42 | */ | 40 | */ |
@@ -67,8 +65,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
67 | * First message any client sends to ATS, used to self-identify | 65 | * First message any client sends to ATS, used to self-identify |
68 | * (what type of client this is). | 66 | * (what type of client this is). |
69 | */ | 67 | */ |
70 | struct ClientStartMessage | 68 | struct ClientStartMessage { |
71 | { | ||
72 | /** | 69 | /** |
73 | * Type is #GNUNET_MESSAGE_TYPE_ATS_START. | 70 | * Type is #GNUNET_MESSAGE_TYPE_ATS_START. |
74 | */ | 71 | */ |
@@ -85,8 +82,7 @@ struct ClientStartMessage | |||
85 | * Connectivity client to ATS service: we would like to have | 82 | * Connectivity client to ATS service: we would like to have |
86 | * address suggestions for this peer. | 83 | * address suggestions for this peer. |
87 | */ | 84 | */ |
88 | struct RequestAddressMessage | 85 | struct RequestAddressMessage { |
89 | { | ||
90 | /** | 86 | /** |
91 | * Type is #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS or | 87 | * Type is #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS or |
92 | * #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL to stop | 88 | * #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL to stop |
@@ -109,8 +105,7 @@ struct RequestAddressMessage | |||
109 | /** | 105 | /** |
110 | * Scheduling client to ATS service: here is another address you can use. | 106 | * Scheduling client to ATS service: here is another address you can use. |
111 | */ | 107 | */ |
112 | struct AddressAddMessage | 108 | struct AddressAddMessage { |
113 | { | ||
114 | /** | 109 | /** |
115 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD. | 110 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD. |
116 | */ | 111 | */ |
@@ -152,7 +147,6 @@ struct AddressAddMessage | |||
152 | * - char address[address_length] | 147 | * - char address[address_length] |
153 | * - char plugin_name[plugin_name_length] (including '\0'-termination). | 148 | * - char plugin_name[plugin_name_length] (including '\0'-termination). |
154 | */ | 149 | */ |
155 | |||
156 | }; | 150 | }; |
157 | 151 | ||
158 | 152 | ||
@@ -160,8 +154,7 @@ struct AddressAddMessage | |||
160 | * Message used to notify ATS that the performance | 154 | * Message used to notify ATS that the performance |
161 | * characteristics for an address have changed. | 155 | * characteristics for an address have changed. |
162 | */ | 156 | */ |
163 | struct AddressUpdateMessage | 157 | struct AddressUpdateMessage { |
164 | { | ||
165 | /** | 158 | /** |
166 | * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE. | 159 | * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE. |
167 | */ | 160 | */ |
@@ -183,7 +176,6 @@ struct AddressUpdateMessage | |||
183 | * Performance properties of the address. | 176 | * Performance properties of the address. |
184 | */ | 177 | */ |
185 | struct GNUNET_ATS_PropertiesNBO properties; | 178 | struct GNUNET_ATS_PropertiesNBO properties; |
186 | |||
187 | }; | 179 | }; |
188 | 180 | ||
189 | 181 | ||
@@ -192,8 +184,7 @@ struct AddressUpdateMessage | |||
192 | * was destroyed and must thus henceforth no longer be considered | 184 | * was destroyed and must thus henceforth no longer be considered |
193 | * for scheduling. | 185 | * for scheduling. |
194 | */ | 186 | */ |
195 | struct AddressDestroyedMessage | 187 | struct AddressDestroyedMessage { |
196 | { | ||
197 | /** | 188 | /** |
198 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED. | 189 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED. |
199 | */ | 190 | */ |
@@ -210,7 +201,6 @@ struct AddressDestroyedMessage | |||
210 | * to find the session faster). | 201 | * to find the session faster). |
211 | */ | 202 | */ |
212 | struct GNUNET_PeerIdentity peer; | 203 | struct GNUNET_PeerIdentity peer; |
213 | |||
214 | }; | 204 | }; |
215 | 205 | ||
216 | 206 | ||
@@ -218,8 +208,7 @@ struct AddressDestroyedMessage | |||
218 | * Message sent by ATS service to client to confirm that it is done | 208 | * Message sent by ATS service to client to confirm that it is done |
219 | * using the given session ID. | 209 | * using the given session ID. |
220 | */ | 210 | */ |
221 | struct GNUNET_ATS_SessionReleaseMessage | 211 | struct GNUNET_ATS_SessionReleaseMessage { |
222 | { | ||
223 | /** | 212 | /** |
224 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE. | 213 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE. |
225 | */ | 214 | */ |
@@ -245,8 +234,7 @@ struct GNUNET_ATS_SessionReleaseMessage | |||
245 | * identified by the given @e session_id for the given @e peer with | 234 | * identified by the given @e session_id for the given @e peer with |
246 | * the given @e bandwidth_in and @e bandwidth_out limits from now on. | 235 | * the given @e bandwidth_in and @e bandwidth_out limits from now on. |
247 | */ | 236 | */ |
248 | struct AddressSuggestionMessage | 237 | struct AddressSuggestionMessage { |
249 | { | ||
250 | /** | 238 | /** |
251 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. | 239 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. |
252 | */ | 240 | */ |
@@ -274,15 +262,13 @@ struct AddressSuggestionMessage | |||
274 | * How much bandwidth we are allowed for receiving. | 262 | * How much bandwidth we are allowed for receiving. |
275 | */ | 263 | */ |
276 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | 264 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; |
277 | |||
278 | }; | 265 | }; |
279 | 266 | ||
280 | 267 | ||
281 | /** | 268 | /** |
282 | * | 269 | * |
283 | */ | 270 | */ |
284 | struct PeerInformationMessage | 271 | struct PeerInformationMessage { |
285 | { | ||
286 | /** | 272 | /** |
287 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION | 273 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION |
288 | */ | 274 | */ |
@@ -338,15 +324,13 @@ struct PeerInformationMessage | |||
338 | * - char address[address_length] | 324 | * - char address[address_length] |
339 | * - char plugin_name[plugin_name_length] (including '\0'-termination). | 325 | * - char plugin_name[plugin_name_length] (including '\0'-termination). |
340 | */ | 326 | */ |
341 | |||
342 | }; | 327 | }; |
343 | 328 | ||
344 | 329 | ||
345 | /** | 330 | /** |
346 | * Client to service: please give us an overview of the addresses. | 331 | * Client to service: please give us an overview of the addresses. |
347 | */ | 332 | */ |
348 | struct AddressListRequestMessage | 333 | struct AddressListRequestMessage { |
349 | { | ||
350 | /** | 334 | /** |
351 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST | 335 | * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST |
352 | */ | 336 | */ |
@@ -367,15 +351,13 @@ struct AddressListRequestMessage | |||
367 | * #GNUNET_NO to only return addresses that are in use. | 351 | * #GNUNET_NO to only return addresses that are in use. |
368 | */ | 352 | */ |
369 | int32_t all GNUNET_PACKED; | 353 | int32_t all GNUNET_PACKED; |
370 | |||
371 | }; | 354 | }; |
372 | 355 | ||
373 | 356 | ||
374 | /** | 357 | /** |
375 | * | 358 | * |
376 | */ | 359 | */ |
377 | struct ReservationRequestMessage | 360 | struct ReservationRequestMessage { |
378 | { | ||
379 | /** | 361 | /** |
380 | * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST | 362 | * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST |
381 | */ | 363 | */ |
@@ -396,8 +378,7 @@ struct ReservationRequestMessage | |||
396 | /** | 378 | /** |
397 | * | 379 | * |
398 | */ | 380 | */ |
399 | struct ReservationResultMessage | 381 | struct ReservationResultMessage { |
400 | { | ||
401 | /** | 382 | /** |
402 | * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT | 383 | * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT |
403 | */ | 384 | */ |
@@ -424,9 +405,7 @@ struct ReservationResultMessage | |||
424 | * Variable-size entry in a `struct ChangePreferenceMessage` or | 405 | * Variable-size entry in a `struct ChangePreferenceMessage` or |
425 | * `struct FeedbackPreferenceMessage`. | 406 | * `struct FeedbackPreferenceMessage`. |
426 | */ | 407 | */ |
427 | struct PreferenceInformation | 408 | struct PreferenceInformation { |
428 | { | ||
429 | |||
430 | /** | 409 | /** |
431 | * An `enum GNUNET_ATS_PreferenceKind` in NBO. | 410 | * An `enum GNUNET_ATS_PreferenceKind` in NBO. |
432 | */ | 411 | */ |
@@ -437,15 +416,13 @@ struct PreferenceInformation | |||
437 | * preference_kind being expressed. | 416 | * preference_kind being expressed. |
438 | */ | 417 | */ |
439 | float preference_value GNUNET_PACKED; | 418 | float preference_value GNUNET_PACKED; |
440 | |||
441 | }; | 419 | }; |
442 | 420 | ||
443 | 421 | ||
444 | /** | 422 | /** |
445 | * Client to ATS: I have a performance preference for a peer. | 423 | * Client to ATS: I have a performance preference for a peer. |
446 | */ | 424 | */ |
447 | struct ChangePreferenceMessage | 425 | struct ChangePreferenceMessage { |
448 | { | ||
449 | /** | 426 | /** |
450 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE. | 427 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE. |
451 | */ | 428 | */ |
@@ -470,8 +447,7 @@ struct ChangePreferenceMessage | |||
470 | /** | 447 | /** |
471 | * Message containing application feedback for a peer | 448 | * Message containing application feedback for a peer |
472 | */ | 449 | */ |
473 | struct FeedbackPreferenceMessage | 450 | struct FeedbackPreferenceMessage { |
474 | { | ||
475 | /** | 451 | /** |
476 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK. | 452 | * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK. |
477 | */ | 453 | */ |
diff --git a/src/ats/ats2.h b/src/ats/ats2.h index ad9b0a3da..723a8440d 100644 --- a/src/ats/ats2.h +++ b/src/ats/ats2.h | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats2.h | 21 | * @file ats/ats2.h |
22 | * @brief automatic transport selection messages | 22 | * @brief automatic transport selection messages |
@@ -36,9 +36,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
36 | /** | 36 | /** |
37 | * ATS performance characteristics for an address. | 37 | * ATS performance characteristics for an address. |
38 | */ | 38 | */ |
39 | struct PropertiesNBO | 39 | struct PropertiesNBO { |
40 | { | ||
41 | |||
42 | /** | 40 | /** |
43 | * Delay. Time between when the time packet is sent and the packet | 41 | * Delay. Time between when the time packet is sent and the packet |
44 | * arrives. FOREVER if we did not (successfully) measure yet. | 42 | * arrives. FOREVER if we did not (successfully) measure yet. |
@@ -101,7 +99,6 @@ struct PropertiesNBO | |||
101 | * A `enum GNUNET_TRANSPORT_CommunicatorCharacteristics` in NBO. | 99 | * A `enum GNUNET_TRANSPORT_CommunicatorCharacteristics` in NBO. |
102 | */ | 100 | */ |
103 | uint32_t cc; | 101 | uint32_t cc; |
104 | |||
105 | }; | 102 | }; |
106 | 103 | ||
107 | 104 | ||
@@ -109,8 +106,7 @@ struct PropertiesNBO | |||
109 | * Application client to ATS service: we would like to have | 106 | * Application client to ATS service: we would like to have |
110 | * address suggestions for this peer. | 107 | * address suggestions for this peer. |
111 | */ | 108 | */ |
112 | struct ExpressPreferenceMessage | 109 | struct ExpressPreferenceMessage { |
113 | { | ||
114 | /** | 110 | /** |
115 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SUGGEST or | 111 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SUGGEST or |
116 | * #GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL to stop | 112 | * #GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL to stop |
@@ -133,15 +129,13 @@ struct ExpressPreferenceMessage | |||
133 | * How much bandwidth in bytes/second does the application expect? | 129 | * How much bandwidth in bytes/second does the application expect? |
134 | */ | 130 | */ |
135 | struct GNUNET_BANDWIDTH_Value32NBO bw; | 131 | struct GNUNET_BANDWIDTH_Value32NBO bw; |
136 | |||
137 | }; | 132 | }; |
138 | 133 | ||
139 | 134 | ||
140 | /** | 135 | /** |
141 | * Transport client to ATS service: here is another session you can use. | 136 | * Transport client to ATS service: here is another session you can use. |
142 | */ | 137 | */ |
143 | struct SessionAddMessage | 138 | struct SessionAddMessage { |
144 | { | ||
145 | /** | 139 | /** |
146 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or | 140 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or |
147 | * #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY | 141 | * #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY |
@@ -167,7 +161,6 @@ struct SessionAddMessage | |||
167 | /* followed by: | 161 | /* followed by: |
168 | * - char * address (including '\0'-termination). | 162 | * - char * address (including '\0'-termination). |
169 | */ | 163 | */ |
170 | |||
171 | }; | 164 | }; |
172 | 165 | ||
173 | 166 | ||
@@ -175,8 +168,7 @@ struct SessionAddMessage | |||
175 | * Message used to notify ATS that the performance | 168 | * Message used to notify ATS that the performance |
176 | * characteristics for an session have changed. | 169 | * characteristics for an session have changed. |
177 | */ | 170 | */ |
178 | struct SessionUpdateMessage | 171 | struct SessionUpdateMessage { |
179 | { | ||
180 | /** | 172 | /** |
181 | * Message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE. | 173 | * Message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE. |
182 | */ | 174 | */ |
@@ -198,7 +190,6 @@ struct SessionUpdateMessage | |||
198 | * Performance properties of the session. | 190 | * Performance properties of the session. |
199 | */ | 191 | */ |
200 | struct PropertiesNBO properties; | 192 | struct PropertiesNBO properties; |
201 | |||
202 | }; | 193 | }; |
203 | 194 | ||
204 | 195 | ||
@@ -207,8 +198,7 @@ struct SessionUpdateMessage | |||
207 | * was destroyed and must thus henceforth no longer be considered | 198 | * was destroyed and must thus henceforth no longer be considered |
208 | * for scheduling. | 199 | * for scheduling. |
209 | */ | 200 | */ |
210 | struct SessionDelMessage | 201 | struct SessionDelMessage { |
211 | { | ||
212 | /** | 202 | /** |
213 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL. | 203 | * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL. |
214 | */ | 204 | */ |
@@ -225,7 +215,6 @@ struct SessionDelMessage | |||
225 | * to find the session faster). | 215 | * to find the session faster). |
226 | */ | 216 | */ |
227 | struct GNUNET_PeerIdentity peer; | 217 | struct GNUNET_PeerIdentity peer; |
228 | |||
229 | }; | 218 | }; |
230 | 219 | ||
231 | 220 | ||
@@ -234,8 +223,7 @@ struct SessionDelMessage | |||
234 | * identified by the given @e session_id for the given @e peer with | 223 | * identified by the given @e session_id for the given @e peer with |
235 | * the given @e bandwidth_in and @e bandwidth_out limits from now on. | 224 | * the given @e bandwidth_in and @e bandwidth_out limits from now on. |
236 | */ | 225 | */ |
237 | struct SessionAllocationMessage | 226 | struct SessionAllocationMessage { |
238 | { | ||
239 | /** | 227 | /** |
240 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION. | 228 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION. |
241 | */ | 229 | */ |
@@ -263,7 +251,6 @@ struct SessionAllocationMessage | |||
263 | * How much bandwidth we are allowed for receiving. | 251 | * How much bandwidth we are allowed for receiving. |
264 | */ | 252 | */ |
265 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; | 253 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; |
266 | |||
267 | }; | 254 | }; |
268 | 255 | ||
269 | 256 | ||
@@ -271,8 +258,7 @@ struct SessionAllocationMessage | |||
271 | * ATS Service suggests to the transport service to try the address | 258 | * ATS Service suggests to the transport service to try the address |
272 | * for the given @e peer. | 259 | * for the given @e peer. |
273 | */ | 260 | */ |
274 | struct AddressSuggestionMessage | 261 | struct AddressSuggestionMessage { |
275 | { | ||
276 | /** | 262 | /** |
277 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. | 263 | * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. |
278 | */ | 264 | */ |
diff --git a/src/ats/ats_api2_application.c b/src/ats/ats_api2_application.c index 444ac3ae3..2a21a116a 100644 --- a/src/ats/ats_api2_application.c +++ b/src/ats/ats_api2_application.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api2_application.c | 21 | * @file ats/ats_api2_application.c |
22 | * @brief enable clients to ask ATS about establishing connections to peers | 22 | * @brief enable clients to ask ATS about establishing connections to peers |
@@ -28,14 +28,13 @@ | |||
28 | #include "ats2.h" | 28 | #include "ats2.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Handle for ATS address suggestion requests. | 35 | * Handle for ATS address suggestion requests. |
36 | */ | 36 | */ |
37 | struct GNUNET_ATS_ApplicationSuggestHandle | 37 | struct GNUNET_ATS_ApplicationSuggestHandle { |
38 | { | ||
39 | /** | 38 | /** |
40 | * ID of the peer for which address suggestion was requested. | 39 | * ID of the peer for which address suggestion was requested. |
41 | */ | 40 | */ |
@@ -61,9 +60,7 @@ struct GNUNET_ATS_ApplicationSuggestHandle | |||
61 | /** | 60 | /** |
62 | * Handle to the ATS subsystem for application management. | 61 | * Handle to the ATS subsystem for application management. |
63 | */ | 62 | */ |
64 | struct GNUNET_ATS_ApplicationHandle | 63 | struct GNUNET_ATS_ApplicationHandle { |
65 | { | ||
66 | |||
67 | /** | 64 | /** |
68 | * Our configuration. | 65 | * Our configuration. |
69 | */ | 66 | */ |
@@ -99,7 +96,7 @@ struct GNUNET_ATS_ApplicationHandle | |||
99 | * @param ch handle to use to re-connect. | 96 | * @param ch handle to use to re-connect. |
100 | */ | 97 | */ |
101 | static void | 98 | static void |
102 | reconnect (struct GNUNET_ATS_ApplicationHandle *ch); | 99 | reconnect(struct GNUNET_ATS_ApplicationHandle *ch); |
103 | 100 | ||
104 | 101 | ||
105 | /** | 102 | /** |
@@ -108,12 +105,12 @@ reconnect (struct GNUNET_ATS_ApplicationHandle *ch); | |||
108 | * @param cls handle to use to re-connect. | 105 | * @param cls handle to use to re-connect. |
109 | */ | 106 | */ |
110 | static void | 107 | static void |
111 | reconnect_task (void *cls) | 108 | reconnect_task(void *cls) |
112 | { | 109 | { |
113 | struct GNUNET_ATS_ApplicationHandle *ch = cls; | 110 | struct GNUNET_ATS_ApplicationHandle *ch = cls; |
114 | 111 | ||
115 | ch->task = NULL; | 112 | ch->task = NULL; |
116 | reconnect (ch); | 113 | reconnect(ch); |
117 | } | 114 | } |
118 | 115 | ||
119 | 116 | ||
@@ -123,17 +120,17 @@ reconnect_task (void *cls) | |||
123 | * @param ch our handle | 120 | * @param ch our handle |
124 | */ | 121 | */ |
125 | static void | 122 | static void |
126 | force_reconnect (struct GNUNET_ATS_ApplicationHandle *ch) | 123 | force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch) |
127 | { | 124 | { |
128 | if (NULL != ch->mq) | 125 | if (NULL != ch->mq) |
129 | { | 126 | { |
130 | GNUNET_MQ_destroy (ch->mq); | 127 | GNUNET_MQ_destroy(ch->mq); |
131 | ch->mq = NULL; | 128 | ch->mq = NULL; |
132 | } | 129 | } |
133 | ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); | 130 | ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); |
134 | ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, | 131 | ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, |
135 | &reconnect_task, | 132 | &reconnect_task, |
136 | ch); | 133 | ch); |
137 | } | 134 | } |
138 | 135 | ||
139 | 136 | ||
@@ -145,15 +142,15 @@ force_reconnect (struct GNUNET_ATS_ApplicationHandle *ch) | |||
145 | * @param error details about the error | 142 | * @param error details about the error |
146 | */ | 143 | */ |
147 | static void | 144 | static void |
148 | error_handler (void *cls, | 145 | error_handler(void *cls, |
149 | enum GNUNET_MQ_Error error) | 146 | enum GNUNET_MQ_Error error) |
150 | { | 147 | { |
151 | struct GNUNET_ATS_ApplicationHandle *ch = cls; | 148 | struct GNUNET_ATS_ApplicationHandle *ch = cls; |
152 | 149 | ||
153 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 150 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
154 | "ATS connection died (code %d), reconnecting\n", | 151 | "ATS connection died (code %d), reconnecting\n", |
155 | (int) error); | 152 | (int)error); |
156 | force_reconnect (ch); | 153 | force_reconnect(ch); |
157 | } | 154 | } |
158 | 155 | ||
159 | 156 | ||
@@ -167,9 +164,9 @@ error_handler (void *cls, | |||
167 | * failure (message queue no longer exists) | 164 | * failure (message queue no longer exists) |
168 | */ | 165 | */ |
169 | static int | 166 | static int |
170 | transmit_suggestion (void *cls, | 167 | transmit_suggestion(void *cls, |
171 | const struct GNUNET_PeerIdentity *peer, | 168 | const struct GNUNET_PeerIdentity *peer, |
172 | void *value) | 169 | void *value) |
173 | { | 170 | { |
174 | struct GNUNET_ATS_ApplicationHandle *ch = cls; | 171 | struct GNUNET_ATS_ApplicationHandle *ch = cls; |
175 | struct GNUNET_ATS_ApplicationSuggestHandle *sh = value; | 172 | struct GNUNET_ATS_ApplicationSuggestHandle *sh = value; |
@@ -178,12 +175,12 @@ transmit_suggestion (void *cls, | |||
178 | 175 | ||
179 | if (NULL == ch->mq) | 176 | if (NULL == ch->mq) |
180 | return GNUNET_SYSERR; | 177 | return GNUNET_SYSERR; |
181 | ev = GNUNET_MQ_msg (m, | 178 | ev = GNUNET_MQ_msg(m, |
182 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST); | 179 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST); |
183 | m->pk = htonl ((uint32_t) sh->pk); | 180 | m->pk = htonl((uint32_t)sh->pk); |
184 | m->bw = sh->bw; | 181 | m->bw = sh->bw; |
185 | m->peer = *peer; | 182 | m->peer = *peer; |
186 | GNUNET_MQ_send (ch->mq, ev); | 183 | GNUNET_MQ_send(ch->mq, ev); |
187 | return GNUNET_OK; | 184 | return GNUNET_OK; |
188 | } | 185 | } |
189 | 186 | ||
@@ -194,26 +191,26 @@ transmit_suggestion (void *cls, | |||
194 | * @param ch handle to use to re-connect. | 191 | * @param ch handle to use to re-connect. |
195 | */ | 192 | */ |
196 | static void | 193 | static void |
197 | reconnect (struct GNUNET_ATS_ApplicationHandle *ch) | 194 | reconnect(struct GNUNET_ATS_ApplicationHandle *ch) |
198 | { | 195 | { |
199 | static const struct GNUNET_MQ_MessageHandler handlers[] = { | 196 | static const struct GNUNET_MQ_MessageHandler handlers[] = { |
200 | { NULL, 0, 0 } | 197 | { NULL, 0, 0 } |
201 | }; | 198 | }; |
202 | 199 | ||
203 | GNUNET_assert (NULL == ch->mq); | 200 | GNUNET_assert(NULL == ch->mq); |
204 | ch->mq = GNUNET_CLIENT_connect (ch->cfg, | 201 | ch->mq = GNUNET_CLIENT_connect(ch->cfg, |
205 | "ats", | 202 | "ats", |
206 | handlers, | 203 | handlers, |
207 | &error_handler, | 204 | &error_handler, |
208 | ch); | 205 | ch); |
209 | if (NULL == ch->mq) | 206 | if (NULL == ch->mq) |
210 | { | 207 | { |
211 | force_reconnect (ch); | 208 | force_reconnect(ch); |
212 | return; | 209 | return; |
213 | } | 210 | } |
214 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | 211 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, |
215 | &transmit_suggestion, | 212 | &transmit_suggestion, |
216 | ch); | 213 | ch); |
217 | } | 214 | } |
218 | 215 | ||
219 | 216 | ||
@@ -224,15 +221,15 @@ reconnect (struct GNUNET_ATS_ApplicationHandle *ch) | |||
224 | * @return ats application handle, NULL on error | 221 | * @return ats application handle, NULL on error |
225 | */ | 222 | */ |
226 | struct GNUNET_ATS_ApplicationHandle * | 223 | struct GNUNET_ATS_ApplicationHandle * |
227 | GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | 224 | GNUNET_ATS_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg) |
228 | { | 225 | { |
229 | struct GNUNET_ATS_ApplicationHandle *ch; | 226 | struct GNUNET_ATS_ApplicationHandle *ch; |
230 | 227 | ||
231 | ch = GNUNET_new (struct GNUNET_ATS_ApplicationHandle); | 228 | ch = GNUNET_new(struct GNUNET_ATS_ApplicationHandle); |
232 | ch->cfg = cfg; | 229 | ch->cfg = cfg; |
233 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, | 230 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, |
234 | GNUNET_YES); | 231 | GNUNET_YES); |
235 | reconnect (ch); | 232 | reconnect(ch); |
236 | return ch; | 233 | return ch; |
237 | } | 234 | } |
238 | 235 | ||
@@ -247,13 +244,13 @@ GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
247 | * @return #GNUNET_OK (continue to iterate) | 244 | * @return #GNUNET_OK (continue to iterate) |
248 | */ | 245 | */ |
249 | static int | 246 | static int |
250 | free_sug_handle (void *cls, | 247 | free_sug_handle(void *cls, |
251 | const struct GNUNET_PeerIdentity *key, | 248 | const struct GNUNET_PeerIdentity *key, |
252 | void *value) | 249 | void *value) |
253 | { | 250 | { |
254 | struct GNUNET_ATS_ApplicationSuggestHandle *cur = value; | 251 | struct GNUNET_ATS_ApplicationSuggestHandle *cur = value; |
255 | 252 | ||
256 | GNUNET_free (cur); | 253 | GNUNET_free(cur); |
257 | return GNUNET_OK; | 254 | return GNUNET_OK; |
258 | } | 255 | } |
259 | 256 | ||
@@ -264,23 +261,23 @@ free_sug_handle (void *cls, | |||
264 | * @param ch handle to release | 261 | * @param ch handle to release |
265 | */ | 262 | */ |
266 | void | 263 | void |
267 | GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch) | 264 | GNUNET_ATS_application_done(struct GNUNET_ATS_ApplicationHandle *ch) |
268 | { | 265 | { |
269 | if (NULL != ch->mq) | 266 | if (NULL != ch->mq) |
270 | { | 267 | { |
271 | GNUNET_MQ_destroy (ch->mq); | 268 | GNUNET_MQ_destroy(ch->mq); |
272 | ch->mq = NULL; | 269 | ch->mq = NULL; |
273 | } | 270 | } |
274 | if (NULL != ch->task) | 271 | if (NULL != ch->task) |
275 | { | 272 | { |
276 | GNUNET_SCHEDULER_cancel (ch->task); | 273 | GNUNET_SCHEDULER_cancel(ch->task); |
277 | ch->task = NULL; | 274 | ch->task = NULL; |
278 | } | 275 | } |
279 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | 276 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, |
280 | &free_sug_handle, | 277 | &free_sug_handle, |
281 | NULL); | 278 | NULL); |
282 | GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); | 279 | GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); |
283 | GNUNET_free (ch); | 280 | GNUNET_free(ch); |
284 | } | 281 | } |
285 | 282 | ||
286 | 283 | ||
@@ -298,31 +295,31 @@ GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch) | |||
298 | * @return suggest handle, NULL if a request is already pending | 295 | * @return suggest handle, NULL if a request is already pending |
299 | */ | 296 | */ |
300 | struct GNUNET_ATS_ApplicationSuggestHandle * | 297 | struct GNUNET_ATS_ApplicationSuggestHandle * |
301 | GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch, | 298 | GNUNET_ATS_application_suggest(struct GNUNET_ATS_ApplicationHandle *ch, |
302 | const struct GNUNET_PeerIdentity *peer, | 299 | const struct GNUNET_PeerIdentity *peer, |
303 | enum GNUNET_MQ_PreferenceKind pk, | 300 | enum GNUNET_MQ_PreferenceKind pk, |
304 | struct GNUNET_BANDWIDTH_Value32NBO bw) | 301 | struct GNUNET_BANDWIDTH_Value32NBO bw) |
305 | { | 302 | { |
306 | struct GNUNET_ATS_ApplicationSuggestHandle *s; | 303 | struct GNUNET_ATS_ApplicationSuggestHandle *s; |
307 | 304 | ||
308 | s = GNUNET_new (struct GNUNET_ATS_ApplicationSuggestHandle); | 305 | s = GNUNET_new(struct GNUNET_ATS_ApplicationSuggestHandle); |
309 | s->ch = ch; | 306 | s->ch = ch; |
310 | s->id = *peer; | 307 | s->id = *peer; |
311 | s->pk = pk; | 308 | s->pk = pk; |
312 | s->bw = bw; | 309 | s->bw = bw; |
313 | (void) GNUNET_CONTAINER_multipeermap_put (ch->sug_requests, | 310 | (void)GNUNET_CONTAINER_multipeermap_put(ch->sug_requests, |
314 | &s->id, | 311 | &s->id, |
315 | s, | 312 | s, |
316 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 313 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 314 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
318 | "Requesting ATS to suggest address for `%s'\n", | 315 | "Requesting ATS to suggest address for `%s'\n", |
319 | GNUNET_i2s (peer)); | 316 | GNUNET_i2s(peer)); |
320 | if (NULL == ch->mq) | 317 | if (NULL == ch->mq) |
321 | return s; | 318 | return s; |
322 | GNUNET_assert (GNUNET_OK == | 319 | GNUNET_assert(GNUNET_OK == |
323 | transmit_suggestion (ch, | 320 | transmit_suggestion(ch, |
324 | &s->id, | 321 | &s->id, |
325 | s)); | 322 | s)); |
326 | return s; | 323 | return s; |
327 | } | 324 | } |
328 | 325 | ||
@@ -333,32 +330,32 @@ GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch, | |||
333 | * @param sh handle to stop | 330 | * @param sh handle to stop |
334 | */ | 331 | */ |
335 | void | 332 | void |
336 | GNUNET_ATS_application_suggest_cancel (struct GNUNET_ATS_ApplicationSuggestHandle *sh) | 333 | GNUNET_ATS_application_suggest_cancel(struct GNUNET_ATS_ApplicationSuggestHandle *sh) |
337 | { | 334 | { |
338 | struct GNUNET_ATS_ApplicationHandle *ch = sh->ch; | 335 | struct GNUNET_ATS_ApplicationHandle *ch = sh->ch; |
339 | struct GNUNET_MQ_Envelope *ev; | 336 | struct GNUNET_MQ_Envelope *ev; |
340 | struct ExpressPreferenceMessage *m; | 337 | struct ExpressPreferenceMessage *m; |
341 | 338 | ||
342 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 339 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
343 | "Telling ATS we no longer care for an address for `%s'\n", | 340 | "Telling ATS we no longer care for an address for `%s'\n", |
344 | GNUNET_i2s (&sh->id)); | 341 | GNUNET_i2s(&sh->id)); |
345 | GNUNET_assert (GNUNET_OK == | 342 | GNUNET_assert(GNUNET_OK == |
346 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, | 343 | GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, |
347 | &sh->id, | 344 | &sh->id, |
348 | sh)); | 345 | sh)); |
349 | if (NULL == ch->mq) | 346 | if (NULL == ch->mq) |
350 | { | 347 | { |
351 | GNUNET_free (sh); | 348 | GNUNET_free(sh); |
352 | return; | 349 | return; |
353 | } | 350 | } |
354 | ev = GNUNET_MQ_msg (m, | 351 | ev = GNUNET_MQ_msg(m, |
355 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL); | 352 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL); |
356 | m->pk = htonl ((uint32_t) sh->pk); | 353 | m->pk = htonl((uint32_t)sh->pk); |
357 | m->bw = sh->bw; | 354 | m->bw = sh->bw; |
358 | m->peer = sh->id; | 355 | m->peer = sh->id; |
359 | GNUNET_MQ_send (ch->mq, | 356 | GNUNET_MQ_send(ch->mq, |
360 | ev); | 357 | ev); |
361 | GNUNET_free (sh); | 358 | GNUNET_free(sh); |
362 | } | 359 | } |
363 | 360 | ||
364 | 361 | ||
diff --git a/src/ats/ats_api2_transport.c b/src/ats/ats_api2_transport.c index e73b2daa8..441e7c8c2 100644 --- a/src/ats/ats_api2_transport.c +++ b/src/ats/ats_api2_transport.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api2_transport.c | 21 | * @file ats/ats_api2_transport.c |
22 | * @brief address suggestions and bandwidth allocation | 22 | * @brief address suggestions and bandwidth allocation |
@@ -27,7 +27,7 @@ | |||
27 | #include "gnunet_ats_transport_service.h" | 27 | #include "gnunet_ats_transport_service.h" |
28 | #include "ats2.h" | 28 | #include "ats2.h" |
29 | 29 | ||
30 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__) | 30 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-transport-api", __VA_ARGS__) |
31 | 31 | ||
32 | 32 | ||
33 | /** | 33 | /** |
@@ -35,9 +35,7 @@ | |||
35 | * doesn't matter if we have a session, any session that ATS is | 35 | * doesn't matter if we have a session, any session that ATS is |
36 | * allowed to suggest right now should be tracked. | 36 | * allowed to suggest right now should be tracked. |
37 | */ | 37 | */ |
38 | struct GNUNET_ATS_SessionRecord | 38 | struct GNUNET_ATS_SessionRecord { |
39 | { | ||
40 | |||
41 | /** | 39 | /** |
42 | * Transport handle this session record belongs to. | 40 | * Transport handle this session record belongs to. |
43 | */ | 41 | */ |
@@ -75,16 +73,13 @@ struct GNUNET_ATS_SessionRecord | |||
75 | * messages. | 73 | * messages. |
76 | */ | 74 | */ |
77 | uint32_t slot; | 75 | uint32_t slot; |
78 | |||
79 | }; | 76 | }; |
80 | 77 | ||
81 | 78 | ||
82 | /** | 79 | /** |
83 | * Handle to the ATS subsystem for bandwidth/transport transport information. | 80 | * Handle to the ATS subsystem for bandwidth/transport transport information. |
84 | */ | 81 | */ |
85 | struct GNUNET_ATS_TransportHandle | 82 | struct GNUNET_ATS_TransportHandle { |
86 | { | ||
87 | |||
88 | /** | 83 | /** |
89 | * Our configuration. | 84 | * Our configuration. |
90 | */ | 85 | */ |
@@ -129,7 +124,6 @@ struct GNUNET_ATS_TransportHandle | |||
129 | * Reconnect backoff delay. | 124 | * Reconnect backoff delay. |
130 | */ | 125 | */ |
131 | struct GNUNET_TIME_Relative backoff; | 126 | struct GNUNET_TIME_Relative backoff; |
132 | |||
133 | }; | 127 | }; |
134 | 128 | ||
135 | 129 | ||
@@ -141,18 +135,18 @@ struct GNUNET_ATS_TransportHandle | |||
141 | * @param hbo value read | 135 | * @param hbo value read |
142 | */ | 136 | */ |
143 | static void | 137 | static void |
144 | properties_hton (struct PropertiesNBO *nbo, | 138 | properties_hton(struct PropertiesNBO *nbo, |
145 | const struct GNUNET_ATS_Properties *hbo) | 139 | const struct GNUNET_ATS_Properties *hbo) |
146 | { | 140 | { |
147 | nbo->delay = GNUNET_TIME_relative_hton (hbo->delay); | 141 | nbo->delay = GNUNET_TIME_relative_hton(hbo->delay); |
148 | nbo->goodput_out = htonl (hbo->goodput_out); | 142 | nbo->goodput_out = htonl(hbo->goodput_out); |
149 | nbo->goodput_in = htonl (hbo->goodput_in); | 143 | nbo->goodput_in = htonl(hbo->goodput_in); |
150 | nbo->utilization_out = htonl (hbo->utilization_out); | 144 | nbo->utilization_out = htonl(hbo->utilization_out); |
151 | nbo->utilization_in = htonl (hbo->utilization_in); | 145 | nbo->utilization_in = htonl(hbo->utilization_in); |
152 | nbo->distance = htonl (hbo->distance); | 146 | nbo->distance = htonl(hbo->distance); |
153 | nbo->mtu = htonl (hbo->mtu); | 147 | nbo->mtu = htonl(hbo->mtu); |
154 | nbo->nt = htonl ((uint32_t) hbo->nt); | 148 | nbo->nt = htonl((uint32_t)hbo->nt); |
155 | nbo->cc = htonl ((uint32_t) hbo->cc); | 149 | nbo->cc = htonl((uint32_t)hbo->cc); |
156 | } | 150 | } |
157 | 151 | ||
158 | 152 | ||
@@ -162,7 +156,7 @@ properties_hton (struct PropertiesNBO *nbo, | |||
162 | * @param sh handle to use to re-connect. | 156 | * @param sh handle to use to re-connect. |
163 | */ | 157 | */ |
164 | static void | 158 | static void |
165 | reconnect (struct GNUNET_ATS_TransportHandle *ath); | 159 | reconnect(struct GNUNET_ATS_TransportHandle *ath); |
166 | 160 | ||
167 | 161 | ||
168 | /** | 162 | /** |
@@ -171,12 +165,12 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath); | |||
171 | * @param cls handle to use to re-connect. | 165 | * @param cls handle to use to re-connect. |
172 | */ | 166 | */ |
173 | static void | 167 | static void |
174 | reconnect_task (void *cls) | 168 | reconnect_task(void *cls) |
175 | { | 169 | { |
176 | struct GNUNET_ATS_TransportHandle *ath = cls; | 170 | struct GNUNET_ATS_TransportHandle *ath = cls; |
177 | 171 | ||
178 | ath->task = NULL; | 172 | ath->task = NULL; |
179 | reconnect (ath); | 173 | reconnect(ath); |
180 | } | 174 | } |
181 | 175 | ||
182 | 176 | ||
@@ -186,20 +180,20 @@ reconnect_task (void *cls) | |||
186 | * @param ath our handle | 180 | * @param ath our handle |
187 | */ | 181 | */ |
188 | static void | 182 | static void |
189 | force_reconnect (struct GNUNET_ATS_TransportHandle *ath) | 183 | force_reconnect(struct GNUNET_ATS_TransportHandle *ath) |
190 | { | 184 | { |
191 | if (NULL != ath->mq) | 185 | if (NULL != ath->mq) |
192 | { | 186 | { |
193 | GNUNET_MQ_destroy (ath->mq); | 187 | GNUNET_MQ_destroy(ath->mq); |
194 | ath->mq = NULL; | 188 | ath->mq = NULL; |
195 | } | 189 | } |
196 | /* FIXME: do we tell transport service about disconnect events? CON: | 190 | /* FIXME: do we tell transport service about disconnect events? CON: |
197 | initially ATS will have a really screwed picture of the world and | 191 | initially ATS will have a really screwed picture of the world and |
198 | the rapid change would be bad. PRO: if we don't, ATS and | 192 | the rapid change would be bad. PRO: if we don't, ATS and |
199 | transport may disagree about the allocation for a while... | 193 | transport may disagree about the allocation for a while... |
200 | For now: lazy: do nothing. */ | 194 | For now: lazy: do nothing. */ |
201 | ath->backoff = GNUNET_TIME_STD_BACKOFF (ath->backoff); | 195 | ath->backoff = GNUNET_TIME_STD_BACKOFF(ath->backoff); |
202 | ath->task = GNUNET_SCHEDULER_add_delayed (ath->backoff, | 196 | ath->task = GNUNET_SCHEDULER_add_delayed(ath->backoff, |
203 | &reconnect_task, | 197 | &reconnect_task, |
204 | ath); | 198 | ath); |
205 | } | 199 | } |
@@ -212,11 +206,11 @@ force_reconnect (struct GNUNET_ATS_TransportHandle *ath) | |||
212 | * @param m message received | 206 | * @param m message received |
213 | */ | 207 | */ |
214 | static int | 208 | static int |
215 | check_ats_address_suggestion (void *cls, | 209 | check_ats_address_suggestion(void *cls, |
216 | const struct AddressSuggestionMessage *m) | 210 | const struct AddressSuggestionMessage *m) |
217 | { | 211 | { |
218 | (void) cls; | 212 | (void)cls; |
219 | GNUNET_MQ_check_zero_termination (m); | 213 | GNUNET_MQ_check_zero_termination(m); |
220 | return GNUNET_SYSERR; | 214 | return GNUNET_SYSERR; |
221 | } | 215 | } |
222 | 216 | ||
@@ -228,13 +222,13 @@ check_ats_address_suggestion (void *cls, | |||
228 | * @param m message received | 222 | * @param m message received |
229 | */ | 223 | */ |
230 | static void | 224 | static void |
231 | handle_ats_address_suggestion (void *cls, | 225 | handle_ats_address_suggestion(void *cls, |
232 | const struct AddressSuggestionMessage *m) | 226 | const struct AddressSuggestionMessage *m) |
233 | { | 227 | { |
234 | struct GNUNET_ATS_TransportHandle *ath = cls; | 228 | struct GNUNET_ATS_TransportHandle *ath = cls; |
235 | const char *address = (const char *) &m[1]; | 229 | const char *address = (const char *)&m[1]; |
236 | 230 | ||
237 | ath->suggest_cb (ath->suggest_cb_cls, | 231 | ath->suggest_cb(ath->suggest_cb_cls, |
238 | &m->peer, | 232 | &m->peer, |
239 | address); | 233 | address); |
240 | } | 234 | } |
@@ -243,8 +237,7 @@ handle_ats_address_suggestion (void *cls, | |||
243 | /** | 237 | /** |
244 | * Closure for #match_session_cb. | 238 | * Closure for #match_session_cb. |
245 | */ | 239 | */ |
246 | struct FindContext | 240 | struct FindContext { |
247 | { | ||
248 | /** | 241 | /** |
249 | * Key to look for. | 242 | * Key to look for. |
250 | */ | 243 | */ |
@@ -266,19 +259,19 @@ struct FindContext | |||
266 | * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching | 259 | * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching |
267 | */ | 260 | */ |
268 | static int | 261 | static int |
269 | match_session_cb (void *cls, | 262 | match_session_cb(void *cls, |
270 | const struct GNUNET_PeerIdentity *pid, | 263 | const struct GNUNET_PeerIdentity *pid, |
271 | void *value) | 264 | void *value) |
272 | { | 265 | { |
273 | struct FindContext *fc = cls; | 266 | struct FindContext *fc = cls; |
274 | struct GNUNET_ATS_SessionRecord *sr = value; | 267 | struct GNUNET_ATS_SessionRecord *sr = value; |
275 | 268 | ||
276 | (void) pid; | 269 | (void)pid; |
277 | if (fc->session_id == sr->slot) | 270 | if (fc->session_id == sr->slot) |
278 | { | 271 | { |
279 | fc->sr = sr; | 272 | fc->sr = sr; |
280 | return GNUNET_NO; | 273 | return GNUNET_NO; |
281 | } | 274 | } |
282 | return GNUNET_YES; | 275 | return GNUNET_YES; |
283 | } | 276 | } |
284 | 277 | ||
@@ -293,18 +286,19 @@ match_session_cb (void *cls, | |||
293 | * @return NULL if no such record exists | 286 | * @return NULL if no such record exists |
294 | */ | 287 | */ |
295 | static struct GNUNET_ATS_SessionRecord * | 288 | static struct GNUNET_ATS_SessionRecord * |
296 | find_session (struct GNUNET_ATS_TransportHandle *ath, | 289 | find_session(struct GNUNET_ATS_TransportHandle *ath, |
297 | uint32_t session_id, | 290 | uint32_t session_id, |
298 | const struct GNUNET_PeerIdentity *pid) | 291 | const struct GNUNET_PeerIdentity *pid) |
299 | { | 292 | { |
300 | struct FindContext fc = { | 293 | struct FindContext fc = { |
301 | .session_id = session_id, | 294 | .session_id = session_id, |
302 | .sr = NULL | 295 | .sr = NULL |
303 | }; | 296 | }; |
304 | GNUNET_CONTAINER_multipeermap_get_multiple (ath->records, | 297 | |
305 | pid, | 298 | GNUNET_CONTAINER_multipeermap_get_multiple(ath->records, |
306 | &match_session_cb, | 299 | pid, |
307 | &fc); | 300 | &match_session_cb, |
301 | &fc); | ||
308 | return fc.sr; | 302 | return fc.sr; |
309 | } | 303 | } |
310 | 304 | ||
@@ -316,34 +310,34 @@ find_session (struct GNUNET_ATS_TransportHandle *ath, | |||
316 | * @param m message received | 310 | * @param m message received |
317 | */ | 311 | */ |
318 | static void | 312 | static void |
319 | handle_ats_session_allocation (void *cls, | 313 | handle_ats_session_allocation(void *cls, |
320 | const struct SessionAllocationMessage *m) | 314 | const struct SessionAllocationMessage *m) |
321 | { | 315 | { |
322 | struct GNUNET_ATS_TransportHandle *ath = cls; | 316 | struct GNUNET_ATS_TransportHandle *ath = cls; |
323 | struct GNUNET_ATS_SessionRecord *ar; | 317 | struct GNUNET_ATS_SessionRecord *ar; |
324 | uint32_t session_id; | 318 | uint32_t session_id; |
325 | 319 | ||
326 | session_id = ntohl (m->session_id); | 320 | session_id = ntohl(m->session_id); |
327 | ar = find_session (ath, | 321 | ar = find_session(ath, |
328 | session_id, | 322 | session_id, |
329 | &m->peer); | 323 | &m->peer); |
330 | if (NULL == ar) | 324 | if (NULL == ar) |
331 | { | 325 | { |
332 | /* this can (rarely) happen if ATS changes an sessiones allocation | 326 | /* this can (rarely) happen if ATS changes an sessiones allocation |
333 | just when the transport service deleted it */ | 327 | just when the transport service deleted it */ |
334 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 328 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
335 | "Allocation ignored, session unknown\n"); | 329 | "Allocation ignored, session unknown\n"); |
336 | return; | 330 | return; |
337 | } | 331 | } |
338 | ath->backoff = GNUNET_TIME_UNIT_ZERO; | 332 | ath->backoff = GNUNET_TIME_UNIT_ZERO; |
339 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 333 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
340 | "ATS allocates bandwidth for peer `%s' using address %s\n", | 334 | "ATS allocates bandwidth for peer `%s' using address %s\n", |
341 | GNUNET_i2s (&ar->pid), | 335 | GNUNET_i2s(&ar->pid), |
342 | ar->address); | 336 | ar->address); |
343 | ath->alloc_cb (ath->alloc_cb_cls, | 337 | ath->alloc_cb(ath->alloc_cb_cls, |
344 | ar->session, | 338 | ar->session, |
345 | m->bandwidth_out, | 339 | m->bandwidth_out, |
346 | m->bandwidth_in); | 340 | m->bandwidth_in); |
347 | } | 341 | } |
348 | 342 | ||
349 | 343 | ||
@@ -355,15 +349,15 @@ handle_ats_session_allocation (void *cls, | |||
355 | * @param error details about the error | 349 | * @param error details about the error |
356 | */ | 350 | */ |
357 | static void | 351 | static void |
358 | error_handler (void *cls, | 352 | error_handler(void *cls, |
359 | enum GNUNET_MQ_Error error) | 353 | enum GNUNET_MQ_Error error) |
360 | { | 354 | { |
361 | struct GNUNET_ATS_TransportHandle *ath = cls; | 355 | struct GNUNET_ATS_TransportHandle *ath = cls; |
362 | 356 | ||
363 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 357 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
364 | "ATS connection died (code %d), reconnecting\n", | 358 | "ATS connection died (code %d), reconnecting\n", |
365 | (int) error); | 359 | (int)error); |
366 | force_reconnect (ath); | 360 | force_reconnect(ath); |
367 | } | 361 | } |
368 | 362 | ||
369 | 363 | ||
@@ -374,7 +368,7 @@ error_handler (void *cls, | |||
374 | * @param ar the session to inform the ATS service about | 368 | * @param ar the session to inform the ATS service about |
375 | */ | 369 | */ |
376 | static void | 370 | static void |
377 | send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar) | 371 | send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar) |
378 | { | 372 | { |
379 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; | 373 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; |
380 | struct GNUNET_MQ_Envelope *ev; | 374 | struct GNUNET_MQ_Envelope *ev; |
@@ -383,26 +377,26 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar) | |||
383 | 377 | ||
384 | if (NULL == ath->mq) | 378 | if (NULL == ath->mq) |
385 | return; /* disconnected, skip for now */ | 379 | return; /* disconnected, skip for now */ |
386 | alen = strlen (ar->address) + 1; | 380 | alen = strlen(ar->address) + 1; |
387 | ev = GNUNET_MQ_msg_extra (m, | 381 | ev = GNUNET_MQ_msg_extra(m, |
388 | alen, | 382 | alen, |
389 | (NULL == ar->session) | 383 | (NULL == ar->session) |
390 | ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY | 384 | ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY |
391 | : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD); | 385 | : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD); |
392 | m->peer = ar->pid; | 386 | m->peer = ar->pid; |
393 | m->session_id = htonl (ar->slot); | 387 | m->session_id = htonl(ar->slot); |
394 | properties_hton (&m->properties, | 388 | properties_hton(&m->properties, |
395 | &ar->properties); | 389 | &ar->properties); |
396 | GNUNET_memcpy (&m[1], | 390 | GNUNET_memcpy(&m[1], |
397 | ar->address, | 391 | ar->address, |
398 | alen); | 392 | alen); |
399 | 393 | ||
400 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 394 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
401 | "Adding address `%s' for peer `%s'\n", | 395 | "Adding address `%s' for peer `%s'\n", |
402 | ar->address, | 396 | ar->address, |
403 | GNUNET_i2s (&ar->pid)); | 397 | GNUNET_i2s(&ar->pid)); |
404 | GNUNET_MQ_send (ath->mq, | 398 | GNUNET_MQ_send(ath->mq, |
405 | ev); | 399 | ev); |
406 | } | 400 | } |
407 | 401 | ||
408 | 402 | ||
@@ -415,15 +409,15 @@ send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar) | |||
415 | * @return #GNUNET_OK | 409 | * @return #GNUNET_OK |
416 | */ | 410 | */ |
417 | static int | 411 | static int |
418 | send_add_session_cb (void *cls, | 412 | send_add_session_cb(void *cls, |
419 | const struct GNUNET_PeerIdentity *pid, | 413 | const struct GNUNET_PeerIdentity *pid, |
420 | void *value) | 414 | void *value) |
421 | { | 415 | { |
422 | struct GNUNET_ATS_SessionRecord *ar = value; | 416 | struct GNUNET_ATS_SessionRecord *ar = value; |
423 | 417 | ||
424 | (void) cls; | 418 | (void)cls; |
425 | (void) pid; | 419 | (void)pid; |
426 | send_add_session_message (ar); | 420 | send_add_session_message(ar); |
427 | return GNUNET_OK; | 421 | return GNUNET_OK; |
428 | } | 422 | } |
429 | 423 | ||
@@ -434,43 +428,43 @@ send_add_session_cb (void *cls, | |||
434 | * @param ath handle to use to re-connect. | 428 | * @param ath handle to use to re-connect. |
435 | */ | 429 | */ |
436 | static void | 430 | static void |
437 | reconnect (struct GNUNET_ATS_TransportHandle *ath) | 431 | reconnect(struct GNUNET_ATS_TransportHandle *ath) |
438 | { | 432 | { |
439 | struct GNUNET_MQ_MessageHandler handlers[] = { | 433 | struct GNUNET_MQ_MessageHandler handlers[] = { |
440 | GNUNET_MQ_hd_var_size (ats_address_suggestion, | 434 | GNUNET_MQ_hd_var_size(ats_address_suggestion, |
441 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, | 435 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, |
442 | struct AddressSuggestionMessage, | 436 | struct AddressSuggestionMessage, |
443 | ath), | 437 | ath), |
444 | GNUNET_MQ_hd_fixed_size (ats_session_allocation, | 438 | GNUNET_MQ_hd_fixed_size(ats_session_allocation, |
445 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION, | 439 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION, |
446 | struct SessionAllocationMessage, | 440 | struct SessionAllocationMessage, |
447 | ath), | 441 | ath), |
448 | GNUNET_MQ_handler_end () | 442 | GNUNET_MQ_handler_end() |
449 | }; | 443 | }; |
450 | struct GNUNET_MQ_Envelope *ev; | 444 | struct GNUNET_MQ_Envelope *ev; |
451 | struct GNUNET_MessageHeader *init; | 445 | struct GNUNET_MessageHeader *init; |
452 | 446 | ||
453 | GNUNET_assert (NULL == ath->mq); | 447 | GNUNET_assert(NULL == ath->mq); |
454 | ath->mq = GNUNET_CLIENT_connect (ath->cfg, | 448 | ath->mq = GNUNET_CLIENT_connect(ath->cfg, |
455 | "ats", | 449 | "ats", |
456 | handlers, | 450 | handlers, |
457 | &error_handler, | 451 | &error_handler, |
458 | ath); | 452 | ath); |
459 | if (NULL == ath->mq) | 453 | if (NULL == ath->mq) |
460 | { | 454 | { |
461 | GNUNET_break (0); | 455 | GNUNET_break(0); |
462 | force_reconnect (ath); | 456 | force_reconnect(ath); |
463 | return; | 457 | return; |
464 | } | 458 | } |
465 | ev = GNUNET_MQ_msg (init, | 459 | ev = GNUNET_MQ_msg(init, |
466 | GNUNET_MESSAGE_TYPE_ATS_START); | 460 | GNUNET_MESSAGE_TYPE_ATS_START); |
467 | GNUNET_MQ_send (ath->mq, | 461 | GNUNET_MQ_send(ath->mq, |
468 | ev); | 462 | ev); |
469 | if (NULL == ath->mq) | 463 | if (NULL == ath->mq) |
470 | return; | 464 | return; |
471 | GNUNET_CONTAINER_multipeermap_iterate (ath->records, | 465 | GNUNET_CONTAINER_multipeermap_iterate(ath->records, |
472 | &send_add_session_cb, | 466 | &send_add_session_cb, |
473 | ath); | 467 | ath); |
474 | } | 468 | } |
475 | 469 | ||
476 | 470 | ||
@@ -485,23 +479,23 @@ reconnect (struct GNUNET_ATS_TransportHandle *ath) | |||
485 | * @return ats context | 479 | * @return ats context |
486 | */ | 480 | */ |
487 | struct GNUNET_ATS_TransportHandle * | 481 | struct GNUNET_ATS_TransportHandle * |
488 | GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 482 | GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg, |
489 | GNUNET_ATS_AllocationCallback alloc_cb, | 483 | GNUNET_ATS_AllocationCallback alloc_cb, |
490 | void *alloc_cb_cls, | 484 | void *alloc_cb_cls, |
491 | GNUNET_ATS_SuggestionCallback suggest_cb, | 485 | GNUNET_ATS_SuggestionCallback suggest_cb, |
492 | void *suggest_cb_cls) | 486 | void *suggest_cb_cls) |
493 | { | 487 | { |
494 | struct GNUNET_ATS_TransportHandle *ath; | 488 | struct GNUNET_ATS_TransportHandle *ath; |
495 | 489 | ||
496 | ath = GNUNET_new (struct GNUNET_ATS_TransportHandle); | 490 | ath = GNUNET_new(struct GNUNET_ATS_TransportHandle); |
497 | ath->cfg = cfg; | 491 | ath->cfg = cfg; |
498 | ath->suggest_cb = suggest_cb; | 492 | ath->suggest_cb = suggest_cb; |
499 | ath->suggest_cb_cls = suggest_cb_cls; | 493 | ath->suggest_cb_cls = suggest_cb_cls; |
500 | ath->alloc_cb = alloc_cb; | 494 | ath->alloc_cb = alloc_cb; |
501 | ath->alloc_cb_cls = alloc_cb_cls; | 495 | ath->alloc_cb_cls = alloc_cb_cls; |
502 | ath->records = GNUNET_CONTAINER_multipeermap_create (128, | 496 | ath->records = GNUNET_CONTAINER_multipeermap_create(128, |
503 | GNUNET_YES); | 497 | GNUNET_YES); |
504 | reconnect (ath); | 498 | reconnect(ath); |
505 | return ath; | 499 | return ath; |
506 | } | 500 | } |
507 | 501 | ||
@@ -515,15 +509,15 @@ GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
515 | * @return #GNUNET_OK | 509 | * @return #GNUNET_OK |
516 | */ | 510 | */ |
517 | static int | 511 | static int |
518 | free_record (void *cls, | 512 | free_record(void *cls, |
519 | const struct GNUNET_PeerIdentity *pid, | 513 | const struct GNUNET_PeerIdentity *pid, |
520 | void *value) | 514 | void *value) |
521 | { | 515 | { |
522 | struct GNUNET_ATS_SessionRecord *ar = value; | 516 | struct GNUNET_ATS_SessionRecord *ar = value; |
523 | 517 | ||
524 | (void) cls; | 518 | (void)cls; |
525 | (void) pid; | 519 | (void)pid; |
526 | GNUNET_free (ar); | 520 | GNUNET_free(ar); |
527 | return GNUNET_OK; | 521 | return GNUNET_OK; |
528 | } | 522 | } |
529 | 523 | ||
@@ -534,23 +528,23 @@ free_record (void *cls, | |||
534 | * @param ath handle to release | 528 | * @param ath handle to release |
535 | */ | 529 | */ |
536 | void | 530 | void |
537 | GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath) | 531 | GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath) |
538 | { | 532 | { |
539 | if (NULL != ath->mq) | 533 | if (NULL != ath->mq) |
540 | { | 534 | { |
541 | GNUNET_MQ_destroy (ath->mq); | 535 | GNUNET_MQ_destroy(ath->mq); |
542 | ath->mq = NULL; | 536 | ath->mq = NULL; |
543 | } | 537 | } |
544 | if (NULL != ath->task) | 538 | if (NULL != ath->task) |
545 | { | 539 | { |
546 | GNUNET_SCHEDULER_cancel (ath->task); | 540 | GNUNET_SCHEDULER_cancel(ath->task); |
547 | ath->task = NULL; | 541 | ath->task = NULL; |
548 | } | 542 | } |
549 | GNUNET_CONTAINER_multipeermap_iterate (ath->records, | 543 | GNUNET_CONTAINER_multipeermap_iterate(ath->records, |
550 | &free_record, | 544 | &free_record, |
551 | NULL); | 545 | NULL); |
552 | GNUNET_CONTAINER_multipeermap_destroy (ath->records); | 546 | GNUNET_CONTAINER_multipeermap_destroy(ath->records); |
553 | GNUNET_free (ath); | 547 | GNUNET_free(ath); |
554 | } | 548 | } |
555 | 549 | ||
556 | 550 | ||
@@ -569,55 +563,56 @@ GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath) | |||
569 | * on error (i.e. ATS knows this exact session already) | 563 | * on error (i.e. ATS knows this exact session already) |
570 | */ | 564 | */ |
571 | struct GNUNET_ATS_SessionRecord * | 565 | struct GNUNET_ATS_SessionRecord * |
572 | GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath, | 566 | GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath, |
573 | const struct GNUNET_PeerIdentity *pid, | 567 | const struct GNUNET_PeerIdentity *pid, |
574 | const char *address, | 568 | const char *address, |
575 | struct GNUNET_ATS_Session *session, | 569 | struct GNUNET_ATS_Session *session, |
576 | const struct GNUNET_ATS_Properties *prop) | 570 | const struct GNUNET_ATS_Properties *prop) |
577 | { | 571 | { |
578 | struct GNUNET_ATS_SessionRecord *ar; | 572 | struct GNUNET_ATS_SessionRecord *ar; |
579 | uint32_t s; | 573 | uint32_t s; |
580 | size_t alen; | 574 | size_t alen; |
581 | 575 | ||
582 | if (NULL == address) | 576 | if (NULL == address) |
583 | { | 577 | { |
584 | /* we need a valid address */ | 578 | /* we need a valid address */ |
585 | GNUNET_break (0); | 579 | GNUNET_break(0); |
586 | return NULL; | 580 | return NULL; |
587 | } | 581 | } |
588 | alen = strlen (address) + 1; | 582 | alen = strlen(address) + 1; |
589 | if ( (alen + sizeof (struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | 583 | if ((alen + sizeof(struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) || |
590 | (alen >= GNUNET_MAX_MESSAGE_SIZE) ) | 584 | (alen >= GNUNET_MAX_MESSAGE_SIZE)) |
591 | { | 585 | { |
592 | /* address too large for us, this should not happen */ | 586 | /* address too large for us, this should not happen */ |
593 | GNUNET_break (0); | 587 | GNUNET_break(0); |
594 | return NULL; | 588 | return NULL; |
595 | } | 589 | } |
596 | 590 | ||
597 | /* Spin 's' until we find an unused session ID for this pid */ | 591 | /* Spin 's' until we find an unused session ID for this pid */ |
598 | for (s = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 592 | for (s = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
599 | UINT32_MAX); | 593 | UINT32_MAX); |
600 | NULL != find_session (ath, | 594 | NULL != find_session(ath, |
601 | s, | 595 | s, |
602 | pid); | 596 | pid); |
603 | s++) ; | 597 | s++) |
604 | 598 | ; | |
605 | alen = strlen (address) + 1; | 599 | |
606 | ar = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionRecord) + alen); | 600 | alen = strlen(address) + 1; |
601 | ar = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionRecord) + alen); | ||
607 | ar->ath = ath; | 602 | ar->ath = ath; |
608 | ar->slot = s; | 603 | ar->slot = s; |
609 | ar->session = session; | 604 | ar->session = session; |
610 | ar->address = (const char *) &ar[1]; | 605 | ar->address = (const char *)&ar[1]; |
611 | ar->pid = *pid; | 606 | ar->pid = *pid; |
612 | ar->properties = *prop; | 607 | ar->properties = *prop; |
613 | memcpy (&ar[1], | 608 | memcpy(&ar[1], |
614 | address, | 609 | address, |
615 | alen); | 610 | alen); |
616 | (void) GNUNET_CONTAINER_multipeermap_put (ath->records, | 611 | (void)GNUNET_CONTAINER_multipeermap_put(ath->records, |
617 | &ar->pid, | 612 | &ar->pid, |
618 | ar, | 613 | ar, |
619 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 614 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
620 | send_add_session_message (ar); | 615 | send_add_session_message(ar); |
621 | return ar; | 616 | return ar; |
622 | } | 617 | } |
623 | 618 | ||
@@ -634,28 +629,28 @@ GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath, | |||
634 | * @param prop performance data for the session | 629 | * @param prop performance data for the session |
635 | */ | 630 | */ |
636 | void | 631 | void |
637 | GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar, | 632 | GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar, |
638 | const struct GNUNET_ATS_Properties *prop) | 633 | const struct GNUNET_ATS_Properties *prop) |
639 | { | 634 | { |
640 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; | 635 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; |
641 | struct GNUNET_MQ_Envelope *ev; | 636 | struct GNUNET_MQ_Envelope *ev; |
642 | struct SessionUpdateMessage *m; | 637 | struct SessionUpdateMessage *m; |
643 | 638 | ||
644 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 639 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
645 | "Updating address `%s' for peer `%s'\n", | 640 | "Updating address `%s' for peer `%s'\n", |
646 | ar->address, | 641 | ar->address, |
647 | GNUNET_i2s (&ar->pid)); | 642 | GNUNET_i2s(&ar->pid)); |
648 | ar->properties = *prop; | 643 | ar->properties = *prop; |
649 | if (NULL == ath->mq) | 644 | if (NULL == ath->mq) |
650 | return; /* disconnected, skip for now */ | 645 | return; /* disconnected, skip for now */ |
651 | ev = GNUNET_MQ_msg (m, | 646 | ev = GNUNET_MQ_msg(m, |
652 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE); | 647 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE); |
653 | m->session_id = htonl (ar->slot); | 648 | m->session_id = htonl(ar->slot); |
654 | m->peer = ar->pid; | 649 | m->peer = ar->pid; |
655 | properties_hton (&m->properties, | 650 | properties_hton(&m->properties, |
656 | &ar->properties); | 651 | &ar->properties); |
657 | GNUNET_MQ_send (ath->mq, | 652 | GNUNET_MQ_send(ath->mq, |
658 | ev); | 653 | ev); |
659 | } | 654 | } |
660 | 655 | ||
661 | 656 | ||
@@ -667,24 +662,24 @@ GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar, | |||
667 | * @param ar session record to drop | 662 | * @param ar session record to drop |
668 | */ | 663 | */ |
669 | void | 664 | void |
670 | GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar) | 665 | GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar) |
671 | { | 666 | { |
672 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; | 667 | struct GNUNET_ATS_TransportHandle *ath = ar->ath; |
673 | struct GNUNET_MQ_Envelope *ev; | 668 | struct GNUNET_MQ_Envelope *ev; |
674 | struct SessionDelMessage *m; | 669 | struct SessionDelMessage *m; |
675 | 670 | ||
676 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 671 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
677 | "Deleting address `%s' for peer `%s'\n", | 672 | "Deleting address `%s' for peer `%s'\n", |
678 | ar->address, | 673 | ar->address, |
679 | GNUNET_i2s (&ar->pid)); | 674 | GNUNET_i2s(&ar->pid)); |
680 | if (NULL == ath->mq) | 675 | if (NULL == ath->mq) |
681 | return; | 676 | return; |
682 | ev = GNUNET_MQ_msg (m, | 677 | ev = GNUNET_MQ_msg(m, |
683 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL); | 678 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL); |
684 | m->session_id = htonl (ar->slot); | 679 | m->session_id = htonl(ar->slot); |
685 | m->peer = ar->pid; | 680 | m->peer = ar->pid; |
686 | GNUNET_MQ_send (ath->mq, | 681 | GNUNET_MQ_send(ath->mq, |
687 | ev); | 682 | ev); |
688 | } | 683 | } |
689 | 684 | ||
690 | 685 | ||
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c index d1295d04d..2ff734c25 100644 --- a/src/ats/ats_api_connectivity.c +++ b/src/ats/ats_api_connectivity.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api_connectivity.c | 21 | * @file ats/ats_api_connectivity.c |
22 | * @brief enable clients to ask ATS about establishing connections to peers | 22 | * @brief enable clients to ask ATS about establishing connections to peers |
@@ -28,14 +28,13 @@ | |||
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Handle for ATS address suggestion requests. | 35 | * Handle for ATS address suggestion requests. |
36 | */ | 36 | */ |
37 | struct GNUNET_ATS_ConnectivitySuggestHandle | 37 | struct GNUNET_ATS_ConnectivitySuggestHandle { |
38 | { | ||
39 | /** | 38 | /** |
40 | * ID of the peer for which address suggestion was requested. | 39 | * ID of the peer for which address suggestion was requested. |
41 | */ | 40 | */ |
@@ -56,9 +55,7 @@ struct GNUNET_ATS_ConnectivitySuggestHandle | |||
56 | /** | 55 | /** |
57 | * Handle to the ATS subsystem for connectivity management. | 56 | * Handle to the ATS subsystem for connectivity management. |
58 | */ | 57 | */ |
59 | struct GNUNET_ATS_ConnectivityHandle | 58 | struct GNUNET_ATS_ConnectivityHandle { |
60 | { | ||
61 | |||
62 | /** | 59 | /** |
63 | * Our configuration. | 60 | * Our configuration. |
64 | */ | 61 | */ |
@@ -94,7 +91,7 @@ struct GNUNET_ATS_ConnectivityHandle | |||
94 | * @param ch handle to use to re-connect. | 91 | * @param ch handle to use to re-connect. |
95 | */ | 92 | */ |
96 | static void | 93 | static void |
97 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch); | 94 | reconnect(struct GNUNET_ATS_ConnectivityHandle *ch); |
98 | 95 | ||
99 | 96 | ||
100 | /** | 97 | /** |
@@ -103,12 +100,12 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch); | |||
103 | * @param cls handle to use to re-connect. | 100 | * @param cls handle to use to re-connect. |
104 | */ | 101 | */ |
105 | static void | 102 | static void |
106 | reconnect_task (void *cls) | 103 | reconnect_task(void *cls) |
107 | { | 104 | { |
108 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 105 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
109 | 106 | ||
110 | ch->task = NULL; | 107 | ch->task = NULL; |
111 | reconnect (ch); | 108 | reconnect(ch); |
112 | } | 109 | } |
113 | 110 | ||
114 | 111 | ||
@@ -118,17 +115,17 @@ reconnect_task (void *cls) | |||
118 | * @param ch our handle | 115 | * @param ch our handle |
119 | */ | 116 | */ |
120 | static void | 117 | static void |
121 | force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | 118 | force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) |
122 | { | 119 | { |
123 | if (NULL != ch->mq) | 120 | if (NULL != ch->mq) |
124 | { | 121 | { |
125 | GNUNET_MQ_destroy (ch->mq); | 122 | GNUNET_MQ_destroy(ch->mq); |
126 | ch->mq = NULL; | 123 | ch->mq = NULL; |
127 | } | 124 | } |
128 | ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); | 125 | ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); |
129 | ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, | 126 | ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, |
130 | &reconnect_task, | 127 | &reconnect_task, |
131 | ch); | 128 | ch); |
132 | } | 129 | } |
133 | 130 | ||
134 | 131 | ||
@@ -140,15 +137,15 @@ force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | |||
140 | * @param error details about the error | 137 | * @param error details about the error |
141 | */ | 138 | */ |
142 | static void | 139 | static void |
143 | error_handler (void *cls, | 140 | error_handler(void *cls, |
144 | enum GNUNET_MQ_Error error) | 141 | enum GNUNET_MQ_Error error) |
145 | { | 142 | { |
146 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 143 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
147 | 144 | ||
148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 145 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
149 | "ATS connection died (code %d), reconnecting\n", | 146 | "ATS connection died (code %d), reconnecting\n", |
150 | (int) error); | 147 | (int)error); |
151 | force_reconnect (ch); | 148 | force_reconnect(ch); |
152 | } | 149 | } |
153 | 150 | ||
154 | 151 | ||
@@ -162,9 +159,9 @@ error_handler (void *cls, | |||
162 | * failure (message queue no longer exists) | 159 | * failure (message queue no longer exists) |
163 | */ | 160 | */ |
164 | static int | 161 | static int |
165 | transmit_suggestion (void *cls, | 162 | transmit_suggestion(void *cls, |
166 | const struct GNUNET_PeerIdentity *peer, | 163 | const struct GNUNET_PeerIdentity *peer, |
167 | void *value) | 164 | void *value) |
168 | { | 165 | { |
169 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; | 166 | struct GNUNET_ATS_ConnectivityHandle *ch = cls; |
170 | struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value; | 167 | struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value; |
@@ -173,10 +170,10 @@ transmit_suggestion (void *cls, | |||
173 | 170 | ||
174 | if (NULL == ch->mq) | 171 | if (NULL == ch->mq) |
175 | return GNUNET_SYSERR; | 172 | return GNUNET_SYSERR; |
176 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); | 173 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); |
177 | m->strength = htonl (sh->strength); | 174 | m->strength = htonl(sh->strength); |
178 | m->peer = *peer; | 175 | m->peer = *peer; |
179 | GNUNET_MQ_send (ch->mq, ev); | 176 | GNUNET_MQ_send(ch->mq, ev); |
180 | return GNUNET_OK; | 177 | return GNUNET_OK; |
181 | } | 178 | } |
182 | 179 | ||
@@ -187,33 +184,33 @@ transmit_suggestion (void *cls, | |||
187 | * @param ch handle to use to re-connect. | 184 | * @param ch handle to use to re-connect. |
188 | */ | 185 | */ |
189 | static void | 186 | static void |
190 | reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | 187 | reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) |
191 | { | 188 | { |
192 | static const struct GNUNET_MQ_MessageHandler handlers[] = | 189 | static const struct GNUNET_MQ_MessageHandler handlers[] = |
193 | { { NULL, 0, 0 } }; | 190 | { { NULL, 0, 0 } }; |
194 | struct GNUNET_MQ_Envelope *ev; | 191 | struct GNUNET_MQ_Envelope *ev; |
195 | struct ClientStartMessage *init; | 192 | struct ClientStartMessage *init; |
196 | 193 | ||
197 | GNUNET_assert (NULL == ch->mq); | 194 | GNUNET_assert(NULL == ch->mq); |
198 | ch->mq = GNUNET_CLIENT_connect (ch->cfg, | 195 | ch->mq = GNUNET_CLIENT_connect(ch->cfg, |
199 | "ats", | 196 | "ats", |
200 | handlers, | 197 | handlers, |
201 | &error_handler, | 198 | &error_handler, |
202 | ch); | 199 | ch); |
203 | if (NULL == ch->mq) | 200 | if (NULL == ch->mq) |
204 | { | 201 | { |
205 | force_reconnect (ch); | 202 | force_reconnect(ch); |
206 | return; | 203 | return; |
207 | } | 204 | } |
208 | ev = GNUNET_MQ_msg (init, | 205 | ev = GNUNET_MQ_msg(init, |
209 | GNUNET_MESSAGE_TYPE_ATS_START); | 206 | GNUNET_MESSAGE_TYPE_ATS_START); |
210 | init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION); | 207 | init->start_flag = htonl(START_FLAG_CONNECTION_SUGGESTION); |
211 | GNUNET_MQ_send (ch->mq, ev); | 208 | GNUNET_MQ_send(ch->mq, ev); |
212 | if (NULL == ch->mq) | 209 | if (NULL == ch->mq) |
213 | return; | 210 | return; |
214 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | 211 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, |
215 | &transmit_suggestion, | 212 | &transmit_suggestion, |
216 | ch); | 213 | ch); |
217 | } | 214 | } |
218 | 215 | ||
219 | 216 | ||
@@ -224,15 +221,15 @@ reconnect (struct GNUNET_ATS_ConnectivityHandle *ch) | |||
224 | * @return ats connectivity handle, NULL on error | 221 | * @return ats connectivity handle, NULL on error |
225 | */ | 222 | */ |
226 | struct GNUNET_ATS_ConnectivityHandle * | 223 | struct GNUNET_ATS_ConnectivityHandle * |
227 | GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | 224 | GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg) |
228 | { | 225 | { |
229 | struct GNUNET_ATS_ConnectivityHandle *ch; | 226 | struct GNUNET_ATS_ConnectivityHandle *ch; |
230 | 227 | ||
231 | ch = GNUNET_new (struct GNUNET_ATS_ConnectivityHandle); | 228 | ch = GNUNET_new(struct GNUNET_ATS_ConnectivityHandle); |
232 | ch->cfg = cfg; | 229 | ch->cfg = cfg; |
233 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, | 230 | ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, |
234 | GNUNET_YES); | 231 | GNUNET_YES); |
235 | reconnect (ch); | 232 | reconnect(ch); |
236 | return ch; | 233 | return ch; |
237 | } | 234 | } |
238 | 235 | ||
@@ -247,13 +244,13 @@ GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
247 | * @return #GNUNET_OK (continue to iterate) | 244 | * @return #GNUNET_OK (continue to iterate) |
248 | */ | 245 | */ |
249 | static int | 246 | static int |
250 | free_sug_handle (void *cls, | 247 | free_sug_handle(void *cls, |
251 | const struct GNUNET_PeerIdentity *key, | 248 | const struct GNUNET_PeerIdentity *key, |
252 | void *value) | 249 | void *value) |
253 | { | 250 | { |
254 | struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; | 251 | struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; |
255 | 252 | ||
256 | GNUNET_free (cur); | 253 | GNUNET_free(cur); |
257 | return GNUNET_OK; | 254 | return GNUNET_OK; |
258 | } | 255 | } |
259 | 256 | ||
@@ -264,23 +261,23 @@ free_sug_handle (void *cls, | |||
264 | * @param ch handle to release | 261 | * @param ch handle to release |
265 | */ | 262 | */ |
266 | void | 263 | void |
267 | GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch) | 264 | GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch) |
268 | { | 265 | { |
269 | if (NULL != ch->mq) | 266 | if (NULL != ch->mq) |
270 | { | 267 | { |
271 | GNUNET_MQ_destroy (ch->mq); | 268 | GNUNET_MQ_destroy(ch->mq); |
272 | ch->mq = NULL; | 269 | ch->mq = NULL; |
273 | } | 270 | } |
274 | if (NULL != ch->task) | 271 | if (NULL != ch->task) |
275 | { | 272 | { |
276 | GNUNET_SCHEDULER_cancel (ch->task); | 273 | GNUNET_SCHEDULER_cancel(ch->task); |
277 | ch->task = NULL; | 274 | ch->task = NULL; |
278 | } | 275 | } |
279 | GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, | 276 | GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, |
280 | &free_sug_handle, | 277 | &free_sug_handle, |
281 | NULL); | 278 | NULL); |
282 | GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); | 279 | GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); |
283 | GNUNET_free (ch); | 280 | GNUNET_free(ch); |
284 | } | 281 | } |
285 | 282 | ||
286 | 283 | ||
@@ -296,36 +293,36 @@ GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch) | |||
296 | * @return suggest handle, NULL if a request is already pending | 293 | * @return suggest handle, NULL if a request is already pending |
297 | */ | 294 | */ |
298 | struct GNUNET_ATS_ConnectivitySuggestHandle * | 295 | struct GNUNET_ATS_ConnectivitySuggestHandle * |
299 | GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, | 296 | GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, |
300 | const struct GNUNET_PeerIdentity *peer, | 297 | const struct GNUNET_PeerIdentity *peer, |
301 | uint32_t strength) | 298 | uint32_t strength) |
302 | { | 299 | { |
303 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; | 300 | struct GNUNET_ATS_ConnectivitySuggestHandle *s; |
304 | 301 | ||
305 | s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle); | 302 | s = GNUNET_new(struct GNUNET_ATS_ConnectivitySuggestHandle); |
306 | s->ch = ch; | 303 | s->ch = ch; |
307 | s->id = *peer; | 304 | s->id = *peer; |
308 | s->strength = strength; | 305 | s->strength = strength; |
309 | if (GNUNET_OK != | 306 | if (GNUNET_OK != |
310 | GNUNET_CONTAINER_multipeermap_put (ch->sug_requests, | 307 | GNUNET_CONTAINER_multipeermap_put(ch->sug_requests, |
311 | &s->id, | 308 | &s->id, |
312 | s, | 309 | s, |
313 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) | 310 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) |
314 | { | 311 | { |
315 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 312 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
316 | "Not requesting ATS to suggest address for `%s', request already pending\n", | 313 | "Not requesting ATS to suggest address for `%s', request already pending\n", |
317 | GNUNET_i2s (peer)); | 314 | GNUNET_i2s(peer)); |
318 | GNUNET_free (s); | 315 | GNUNET_free(s); |
319 | return NULL; | 316 | return NULL; |
320 | } | 317 | } |
321 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 318 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
322 | "Requesting ATS to suggest address for `%s'\n", | 319 | "Requesting ATS to suggest address for `%s'\n", |
323 | GNUNET_i2s (peer)); | 320 | GNUNET_i2s(peer)); |
324 | if (NULL == ch->mq) | 321 | if (NULL == ch->mq) |
325 | return s; | 322 | return s; |
326 | (void) transmit_suggestion (ch, | 323 | (void)transmit_suggestion(ch, |
327 | &s->id, | 324 | &s->id, |
328 | s); | 325 | s); |
329 | return s; | 326 | return s; |
330 | } | 327 | } |
331 | 328 | ||
@@ -336,30 +333,30 @@ GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, | |||
336 | * @param sh handle to stop | 333 | * @param sh handle to stop |
337 | */ | 334 | */ |
338 | void | 335 | void |
339 | GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh) | 336 | GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh) |
340 | { | 337 | { |
341 | struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; | 338 | struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; |
342 | struct GNUNET_MQ_Envelope *ev; | 339 | struct GNUNET_MQ_Envelope *ev; |
343 | struct RequestAddressMessage *m; | 340 | struct RequestAddressMessage *m; |
344 | 341 | ||
345 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 342 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
346 | "Telling ATS we no longer care for an address for `%s'\n", | 343 | "Telling ATS we no longer care for an address for `%s'\n", |
347 | GNUNET_i2s (&sh->id)); | 344 | GNUNET_i2s(&sh->id)); |
348 | GNUNET_assert (GNUNET_OK == | 345 | GNUNET_assert(GNUNET_OK == |
349 | GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, | 346 | GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, |
350 | &sh->id, | 347 | &sh->id, |
351 | sh)); | 348 | sh)); |
352 | if (NULL == ch->mq) | 349 | if (NULL == ch->mq) |
353 | { | 350 | { |
354 | GNUNET_free (sh); | 351 | GNUNET_free(sh); |
355 | return; | 352 | return; |
356 | } | 353 | } |
357 | ev = GNUNET_MQ_msg (m, | 354 | ev = GNUNET_MQ_msg(m, |
358 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); | 355 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); |
359 | m->strength = htonl (0); | 356 | m->strength = htonl(0); |
360 | m->peer = sh->id; | 357 | m->peer = sh->id; |
361 | GNUNET_MQ_send (ch->mq, ev); | 358 | GNUNET_MQ_send(ch->mq, ev); |
362 | GNUNET_free (sh); | 359 | GNUNET_free(sh); |
363 | } | 360 | } |
364 | 361 | ||
365 | 362 | ||
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c index 0954c02d5..b30093f4c 100644 --- a/src/ats/ats_api_performance.c +++ b/src/ats/ats_api_performance.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010, 2011, 2016 GNUnet e.V. | 3 | Copyright (C) 2010, 2011, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -28,15 +28,13 @@ | |||
28 | #include "ats.h" | 28 | #include "ats.h" |
29 | 29 | ||
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-performance-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-performance-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Linked list of pending reservations. | 35 | * Linked list of pending reservations. |
36 | */ | 36 | */ |
37 | struct GNUNET_ATS_ReservationContext | 37 | struct GNUNET_ATS_ReservationContext { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Kept in a DLL. | 39 | * Kept in a DLL. |
42 | */ | 40 | */ |
@@ -82,9 +80,7 @@ struct GNUNET_ATS_ReservationContext | |||
82 | /** | 80 | /** |
83 | * Linked list of pending reservations. | 81 | * Linked list of pending reservations. |
84 | */ | 82 | */ |
85 | struct GNUNET_ATS_AddressListHandle | 83 | struct GNUNET_ATS_AddressListHandle { |
86 | { | ||
87 | |||
88 | /** | 84 | /** |
89 | * Kept in a DLL. | 85 | * Kept in a DLL. |
90 | */ | 86 | */ |
@@ -135,9 +131,7 @@ struct GNUNET_ATS_AddressListHandle | |||
135 | /** | 131 | /** |
136 | * ATS Handle to obtain and/or modify performance information. | 132 | * ATS Handle to obtain and/or modify performance information. |
137 | */ | 133 | */ |
138 | struct GNUNET_ATS_PerformanceHandle | 134 | struct GNUNET_ATS_PerformanceHandle { |
139 | { | ||
140 | |||
141 | /** | 135 | /** |
142 | * Our configuration. | 136 | * Our configuration. |
143 | */ | 137 | */ |
@@ -215,7 +209,7 @@ struct GNUNET_ATS_PerformanceHandle | |||
215 | * @param ph handle to use to re-connect. | 209 | * @param ph handle to use to re-connect. |
216 | */ | 210 | */ |
217 | static void | 211 | static void |
218 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | 212 | reconnect(struct GNUNET_ATS_PerformanceHandle *ph); |
219 | 213 | ||
220 | 214 | ||
221 | /** | 215 | /** |
@@ -224,12 +218,12 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph); | |||
224 | * @param cls handle to use to re-connect. | 218 | * @param cls handle to use to re-connect. |
225 | */ | 219 | */ |
226 | static void | 220 | static void |
227 | reconnect_task (void *cls) | 221 | reconnect_task(void *cls) |
228 | { | 222 | { |
229 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 223 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
230 | 224 | ||
231 | ph->task = NULL; | 225 | ph->task = NULL; |
232 | reconnect (ph); | 226 | reconnect(ph); |
233 | } | 227 | } |
234 | 228 | ||
235 | 229 | ||
@@ -239,58 +233,58 @@ reconnect_task (void *cls) | |||
239 | * @param ph handle to reconnect | 233 | * @param ph handle to reconnect |
240 | */ | 234 | */ |
241 | static void | 235 | static void |
242 | do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | 236 | do_reconnect(struct GNUNET_ATS_PerformanceHandle *ph) |
243 | { | 237 | { |
244 | struct GNUNET_ATS_ReservationContext *rc; | 238 | struct GNUNET_ATS_ReservationContext *rc; |
245 | struct GNUNET_ATS_AddressListHandle *alh; | 239 | struct GNUNET_ATS_AddressListHandle *alh; |
246 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; | 240 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; |
247 | 241 | ||
248 | if (NULL != ph->mq) | 242 | if (NULL != ph->mq) |
249 | { | 243 | { |
250 | GNUNET_MQ_destroy (ph->mq); | 244 | GNUNET_MQ_destroy(ph->mq); |
251 | ph->mq = NULL; | 245 | ph->mq = NULL; |
252 | } | 246 | } |
253 | while (NULL != (rc = ph->reservation_head)) | 247 | while (NULL != (rc = ph->reservation_head)) |
254 | { | 248 | { |
255 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 249 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
256 | ph->reservation_tail, | 250 | ph->reservation_tail, |
257 | rc); | 251 | rc); |
258 | if (NULL != rc->rcb) | 252 | if (NULL != rc->rcb) |
259 | rc->rcb (rc->rcb_cls, | 253 | rc->rcb(rc->rcb_cls, |
260 | NULL, | 254 | NULL, |
261 | 0, | 255 | 0, |
262 | GNUNET_TIME_UNIT_FOREVER_REL); | 256 | GNUNET_TIME_UNIT_FOREVER_REL); |
263 | GNUNET_free (rc); | 257 | GNUNET_free(rc); |
264 | } | 258 | } |
265 | bandwidth_zero.value__ = htonl (0); | 259 | bandwidth_zero.value__ = htonl(0); |
266 | while (NULL != (alh = ph->addresslist_head)) | 260 | while (NULL != (alh = ph->addresslist_head)) |
267 | { | 261 | { |
268 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 262 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
269 | ph->addresslist_tail, | 263 | ph->addresslist_tail, |
270 | alh); | 264 | alh); |
271 | if (NULL != alh->cb) | 265 | if (NULL != alh->cb) |
272 | alh->cb (alh->cb_cls, | 266 | alh->cb(alh->cb_cls, |
273 | NULL, | 267 | NULL, |
274 | GNUNET_NO, | 268 | GNUNET_NO, |
275 | bandwidth_zero, | 269 | bandwidth_zero, |
276 | bandwidth_zero, | 270 | bandwidth_zero, |
277 | NULL); | 271 | NULL); |
278 | GNUNET_free (alh); | 272 | GNUNET_free(alh); |
279 | } | 273 | } |
280 | if (NULL != ph->addr_info_cb) | 274 | if (NULL != ph->addr_info_cb) |
281 | { | 275 | { |
282 | /* Indicate reconnect */ | 276 | /* Indicate reconnect */ |
283 | ph->addr_info_cb (ph->addr_info_cb_cls, | 277 | ph->addr_info_cb(ph->addr_info_cb_cls, |
284 | NULL, | 278 | NULL, |
285 | GNUNET_NO, | 279 | GNUNET_NO, |
286 | bandwidth_zero, | 280 | bandwidth_zero, |
287 | bandwidth_zero, | 281 | bandwidth_zero, |
288 | NULL); | 282 | NULL); |
289 | } | 283 | } |
290 | ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff); | 284 | ph->backoff = GNUNET_TIME_STD_BACKOFF(ph->backoff); |
291 | ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff, | 285 | ph->task = GNUNET_SCHEDULER_add_delayed(ph->backoff, |
292 | &reconnect_task, | 286 | &reconnect_task, |
293 | ph); | 287 | ph); |
294 | } | 288 | } |
295 | 289 | ||
296 | 290 | ||
@@ -302,25 +296,25 @@ do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
302 | * @return #GNUNET_OK if the message was well-formed | 296 | * @return #GNUNET_OK if the message was well-formed |
303 | */ | 297 | */ |
304 | static int | 298 | static int |
305 | check_peer_information (void *cls, | 299 | check_peer_information(void *cls, |
306 | const struct PeerInformationMessage *pi) | 300 | const struct PeerInformationMessage *pi) |
307 | { | 301 | { |
308 | const char *plugin_address; | 302 | const char *plugin_address; |
309 | const char *plugin_name; | 303 | const char *plugin_name; |
310 | uint16_t plugin_address_length; | 304 | uint16_t plugin_address_length; |
311 | uint16_t plugin_name_length; | 305 | uint16_t plugin_name_length; |
312 | 306 | ||
313 | plugin_address_length = ntohs (pi->address_length); | 307 | plugin_address_length = ntohs(pi->address_length); |
314 | plugin_name_length = ntohs (pi->plugin_name_length); | 308 | plugin_name_length = ntohs(pi->plugin_name_length); |
315 | plugin_address = (const char *) &pi[1]; | 309 | plugin_address = (const char *)&pi[1]; |
316 | plugin_name = &plugin_address[plugin_address_length]; | 310 | plugin_name = &plugin_address[plugin_address_length]; |
317 | if ( (plugin_address_length + plugin_name_length | 311 | if ((plugin_address_length + plugin_name_length |
318 | + sizeof(struct PeerInformationMessage) != ntohs (pi->header.size)) || | 312 | + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || |
319 | (plugin_name[plugin_name_length - 1] != '\0')) | 313 | (plugin_name[plugin_name_length - 1] != '\0')) |
320 | { | 314 | { |
321 | GNUNET_break(0); | 315 | GNUNET_break(0); |
322 | return GNUNET_SYSERR; | 316 | return GNUNET_SYSERR; |
323 | } | 317 | } |
324 | return GNUNET_OK; | 318 | return GNUNET_OK; |
325 | } | 319 | } |
326 | 320 | ||
@@ -333,8 +327,8 @@ check_peer_information (void *cls, | |||
333 | * @return #GNUNET_OK if the message was well-formed | 327 | * @return #GNUNET_OK if the message was well-formed |
334 | */ | 328 | */ |
335 | static void | 329 | static void |
336 | handle_peer_information (void *cls, | 330 | handle_peer_information(void *cls, |
337 | const struct PeerInformationMessage *pi) | 331 | const struct PeerInformationMessage *pi) |
338 | { | 332 | { |
339 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 333 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
340 | const char *plugin_address; | 334 | const char *plugin_address; |
@@ -346,24 +340,24 @@ handle_peer_information (void *cls, | |||
346 | 340 | ||
347 | if (NULL == ph->addr_info_cb) | 341 | if (NULL == ph->addr_info_cb) |
348 | return; | 342 | return; |
349 | plugin_address_length = ntohs (pi->address_length); | 343 | plugin_address_length = ntohs(pi->address_length); |
350 | addr_active = (int) ntohl (pi->address_active); | 344 | addr_active = (int)ntohl(pi->address_active); |
351 | plugin_address = (const char *) &pi[1]; | 345 | plugin_address = (const char *)&pi[1]; |
352 | plugin_name = &plugin_address[plugin_address_length]; | 346 | plugin_name = &plugin_address[plugin_address_length]; |
353 | 347 | ||
354 | GNUNET_ATS_properties_ntoh (&prop, | 348 | GNUNET_ATS_properties_ntoh(&prop, |
355 | &pi->properties); | 349 | &pi->properties); |
356 | address.peer = pi->peer; | 350 | address.peer = pi->peer; |
357 | address.local_info = (enum GNUNET_HELLO_AddressInfo) ntohl (pi->address_local_info); | 351 | address.local_info = (enum GNUNET_HELLO_AddressInfo)ntohl(pi->address_local_info); |
358 | address.address = plugin_address; | 352 | address.address = plugin_address; |
359 | address.address_length = plugin_address_length; | 353 | address.address_length = plugin_address_length; |
360 | address.transport_name = plugin_name; | 354 | address.transport_name = plugin_name; |
361 | ph->addr_info_cb (ph->addr_info_cb_cls, | 355 | ph->addr_info_cb(ph->addr_info_cb_cls, |
362 | &address, | 356 | &address, |
363 | addr_active, | 357 | addr_active, |
364 | pi->bandwidth_out, | 358 | pi->bandwidth_out, |
365 | pi->bandwidth_in, | 359 | pi->bandwidth_in, |
366 | &prop); | 360 | &prop); |
367 | } | 361 | } |
368 | 362 | ||
369 | 363 | ||
@@ -374,48 +368,48 @@ handle_peer_information (void *cls, | |||
374 | * @param rr the message | 368 | * @param rr the message |
375 | */ | 369 | */ |
376 | static void | 370 | static void |
377 | handle_reservation_result (void *cls, | 371 | handle_reservation_result(void *cls, |
378 | const struct ReservationResultMessage *rr) | 372 | const struct ReservationResultMessage *rr) |
379 | { | 373 | { |
380 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 374 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
381 | struct GNUNET_ATS_ReservationContext *rc; | 375 | struct GNUNET_ATS_ReservationContext *rc; |
382 | int32_t amount; | 376 | int32_t amount; |
383 | 377 | ||
384 | amount = ntohl (rr->amount); | 378 | amount = ntohl(rr->amount); |
385 | rc = ph->reservation_head; | 379 | rc = ph->reservation_head; |
386 | if (0 != GNUNET_memcmp (&rr->peer, | 380 | if (0 != GNUNET_memcmp(&rr->peer, |
387 | &rc->peer)) | 381 | &rc->peer)) |
388 | { | 382 | { |
389 | GNUNET_break(0); | 383 | GNUNET_break(0); |
390 | reconnect (ph); | 384 | reconnect(ph); |
391 | return; | 385 | return; |
392 | } | 386 | } |
393 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 387 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
394 | ph->reservation_tail, | 388 | ph->reservation_tail, |
395 | rc); | 389 | rc); |
396 | if ( (0 == amount) || | 390 | if ((0 == amount) || |
397 | (NULL != rc->rcb) ) | 391 | (NULL != rc->rcb)) |
398 | { | 392 | { |
399 | /* tell client if not cancelled */ | 393 | /* tell client if not cancelled */ |
400 | if (NULL != rc->rcb) | 394 | if (NULL != rc->rcb) |
401 | rc->rcb (rc->rcb_cls, | 395 | rc->rcb(rc->rcb_cls, |
402 | &rr->peer, | 396 | &rr->peer, |
403 | amount, | 397 | amount, |
404 | GNUNET_TIME_relative_ntoh (rr->res_delay)); | 398 | GNUNET_TIME_relative_ntoh(rr->res_delay)); |
405 | GNUNET_free (rc); | 399 | GNUNET_free(rc); |
406 | return; | 400 | return; |
407 | } | 401 | } |
408 | /* amount non-zero, but client cancelled, consider undo! */ | 402 | /* amount non-zero, but client cancelled, consider undo! */ |
409 | if (GNUNET_YES != rc->undo) | 403 | if (GNUNET_YES != rc->undo) |
410 | { | 404 | { |
411 | GNUNET_free (rc); | 405 | GNUNET_free(rc); |
412 | return; /* do not try to undo failed undos or negative amounts */ | 406 | return; /* do not try to undo failed undos or negative amounts */ |
413 | } | 407 | } |
414 | GNUNET_free (rc); | 408 | GNUNET_free(rc); |
415 | (void) GNUNET_ATS_reserve_bandwidth (ph, | 409 | (void)GNUNET_ATS_reserve_bandwidth(ph, |
416 | &rr->peer, | 410 | &rr->peer, |
417 | -amount, | 411 | -amount, |
418 | NULL, NULL); | 412 | NULL, NULL); |
419 | } | 413 | } |
420 | 414 | ||
421 | 415 | ||
@@ -427,25 +421,25 @@ handle_reservation_result (void *cls, | |||
427 | * @return #GNUNET_OK if the message was well-formed | 421 | * @return #GNUNET_OK if the message was well-formed |
428 | */ | 422 | */ |
429 | static int | 423 | static int |
430 | check_address_list (void *cls, | 424 | check_address_list(void *cls, |
431 | const struct PeerInformationMessage *pi) | 425 | const struct PeerInformationMessage *pi) |
432 | { | 426 | { |
433 | const char *plugin_address; | 427 | const char *plugin_address; |
434 | const char *plugin_name; | 428 | const char *plugin_name; |
435 | uint16_t plugin_address_length; | 429 | uint16_t plugin_address_length; |
436 | uint16_t plugin_name_length; | 430 | uint16_t plugin_name_length; |
437 | 431 | ||
438 | plugin_address_length = ntohs (pi->address_length); | 432 | plugin_address_length = ntohs(pi->address_length); |
439 | plugin_name_length = ntohs (pi->plugin_name_length); | 433 | plugin_name_length = ntohs(pi->plugin_name_length); |
440 | plugin_address = (const char *) &pi[1]; | 434 | plugin_address = (const char *)&pi[1]; |
441 | plugin_name = &plugin_address[plugin_address_length]; | 435 | plugin_name = &plugin_address[plugin_address_length]; |
442 | if ( (plugin_address_length + plugin_name_length | 436 | if ((plugin_address_length + plugin_name_length |
443 | + sizeof (struct PeerInformationMessage) != ntohs (pi->header.size)) || | 437 | + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || |
444 | (plugin_name[plugin_name_length - 1] != '\0') ) | 438 | (plugin_name[plugin_name_length - 1] != '\0')) |
445 | { | 439 | { |
446 | GNUNET_break(0); | 440 | GNUNET_break(0); |
447 | return GNUNET_SYSERR; | 441 | return GNUNET_SYSERR; |
448 | } | 442 | } |
449 | return GNUNET_OK; | 443 | return GNUNET_OK; |
450 | } | 444 | } |
451 | 445 | ||
@@ -458,8 +452,8 @@ check_address_list (void *cls, | |||
458 | * @param pi the message | 452 | * @param pi the message |
459 | */ | 453 | */ |
460 | static void | 454 | static void |
461 | handle_address_list (void *cls, | 455 | handle_address_list(void *cls, |
462 | const struct PeerInformationMessage *pi) | 456 | const struct PeerInformationMessage *pi) |
463 | { | 457 | { |
464 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 458 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
465 | struct GNUNET_ATS_AddressListHandle *alh; | 459 | struct GNUNET_ATS_AddressListHandle *alh; |
@@ -475,67 +469,67 @@ handle_address_list (void *cls, | |||
475 | uint32_t active; | 469 | uint32_t active; |
476 | uint32_t id; | 470 | uint32_t id; |
477 | 471 | ||
478 | id = ntohl (pi->id); | 472 | id = ntohl(pi->id); |
479 | active = ntohl (pi->address_active); | 473 | active = ntohl(pi->address_active); |
480 | plugin_address_length = ntohs (pi->address_length); | 474 | plugin_address_length = ntohs(pi->address_length); |
481 | plugin_name_length = ntohs (pi->plugin_name_length); | 475 | plugin_name_length = ntohs(pi->plugin_name_length); |
482 | plugin_address = (const char *) &pi[1]; | 476 | plugin_address = (const char *)&pi[1]; |
483 | plugin_name = &plugin_address[plugin_address_length]; | 477 | plugin_name = &plugin_address[plugin_address_length]; |
484 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 478 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
485 | "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n", | 479 | "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n", |
486 | GNUNET_i2s (&pi->peer), | 480 | GNUNET_i2s(&pi->peer), |
487 | plugin_name); | 481 | plugin_name); |
488 | 482 | ||
489 | next = ph->addresslist_head; | 483 | next = ph->addresslist_head; |
490 | while (NULL != (alh = next)) | 484 | while (NULL != (alh = next)) |
491 | { | 485 | { |
492 | next = alh->next; | 486 | next = alh->next; |
493 | if (alh->id == id) | 487 | if (alh->id == id) |
494 | break; | 488 | break; |
495 | } | 489 | } |
496 | if (NULL == alh) | 490 | if (NULL == alh) |
497 | return; /* was canceled */ | 491 | return; /* was canceled */ |
498 | 492 | ||
499 | memset (&allzeros, '\0', sizeof (allzeros)); | 493 | memset(&allzeros, '\0', sizeof(allzeros)); |
500 | if ( (0 == GNUNET_is_zero (&pi->peer)) && | 494 | if ((0 == GNUNET_is_zero(&pi->peer)) && |
501 | (0 == plugin_name_length) && | 495 | (0 == plugin_name_length) && |
502 | (0 == plugin_address_length) ) | 496 | (0 == plugin_address_length)) |
503 | { | 497 | { |
504 | /* Done */ | 498 | /* Done */ |
505 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 499 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
506 | "Received last message for ATS_ADDRESSLIST_RESPONSE\n"); | 500 | "Received last message for ATS_ADDRESSLIST_RESPONSE\n"); |
507 | bandwidth_zero.value__ = htonl (0); | 501 | bandwidth_zero.value__ = htonl(0); |
508 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 502 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
509 | ph->addresslist_tail, | 503 | ph->addresslist_tail, |
510 | alh); | 504 | alh); |
511 | if (NULL != alh->cb) | 505 | if (NULL != alh->cb) |
512 | alh->cb (alh->cb_cls, | 506 | alh->cb(alh->cb_cls, |
513 | NULL, | 507 | NULL, |
514 | GNUNET_NO, | 508 | GNUNET_NO, |
515 | bandwidth_zero, | 509 | bandwidth_zero, |
516 | bandwidth_zero, | 510 | bandwidth_zero, |
517 | NULL); | 511 | NULL); |
518 | GNUNET_free (alh); | 512 | GNUNET_free(alh); |
519 | return; | 513 | return; |
520 | } | 514 | } |
521 | 515 | ||
522 | address.peer = pi->peer; | 516 | address.peer = pi->peer; |
523 | address.address = plugin_address; | 517 | address.address = plugin_address; |
524 | address.address_length = plugin_address_length; | 518 | address.address_length = plugin_address_length; |
525 | address.transport_name = plugin_name; | 519 | address.transport_name = plugin_name; |
526 | if ( ( (GNUNET_YES == alh->all_addresses) || | 520 | if (((GNUNET_YES == alh->all_addresses) || |
527 | (GNUNET_YES == active) ) && | 521 | (GNUNET_YES == active)) && |
528 | (NULL != alh->cb) ) | 522 | (NULL != alh->cb)) |
529 | { | 523 | { |
530 | GNUNET_ATS_properties_ntoh (&prop, | 524 | GNUNET_ATS_properties_ntoh(&prop, |
531 | &pi->properties); | 525 | &pi->properties); |
532 | alh->cb (alh->cb_cls, | 526 | alh->cb(alh->cb_cls, |
533 | &address, | 527 | &address, |
534 | active, | 528 | active, |
535 | pi->bandwidth_out, | 529 | pi->bandwidth_out, |
536 | pi->bandwidth_in, | 530 | pi->bandwidth_in, |
537 | &prop); | 531 | &prop); |
538 | } | 532 | } |
539 | } | 533 | } |
540 | 534 | ||
541 | 535 | ||
@@ -548,12 +542,12 @@ handle_address_list (void *cls, | |||
548 | * @param error error code | 542 | * @param error error code |
549 | */ | 543 | */ |
550 | static void | 544 | static void |
551 | mq_error_handler (void *cls, | 545 | mq_error_handler(void *cls, |
552 | enum GNUNET_MQ_Error error) | 546 | enum GNUNET_MQ_Error error) |
553 | { | 547 | { |
554 | struct GNUNET_ATS_PerformanceHandle *ph = cls; | 548 | struct GNUNET_ATS_PerformanceHandle *ph = cls; |
555 | 549 | ||
556 | do_reconnect (ph); | 550 | do_reconnect(ph); |
557 | } | 551 | } |
558 | 552 | ||
559 | 553 | ||
@@ -563,41 +557,41 @@ mq_error_handler (void *cls, | |||
563 | * @param ph handle to use to re-connect. | 557 | * @param ph handle to use to re-connect. |
564 | */ | 558 | */ |
565 | static void | 559 | static void |
566 | reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | 560 | reconnect(struct GNUNET_ATS_PerformanceHandle *ph) |
567 | { | 561 | { |
568 | struct GNUNET_MQ_MessageHandler handlers[] = { | 562 | struct GNUNET_MQ_MessageHandler handlers[] = { |
569 | GNUNET_MQ_hd_var_size (peer_information, | 563 | GNUNET_MQ_hd_var_size(peer_information, |
570 | GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, | 564 | GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, |
571 | struct PeerInformationMessage, | 565 | struct PeerInformationMessage, |
572 | ph), | 566 | ph), |
573 | GNUNET_MQ_hd_fixed_size (reservation_result, | 567 | GNUNET_MQ_hd_fixed_size(reservation_result, |
574 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, | 568 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, |
575 | struct ReservationResultMessage, | 569 | struct ReservationResultMessage, |
576 | ph), | 570 | ph), |
577 | GNUNET_MQ_hd_var_size (address_list, | 571 | GNUNET_MQ_hd_var_size(address_list, |
578 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, | 572 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, |
579 | struct PeerInformationMessage, | 573 | struct PeerInformationMessage, |
580 | ph), | 574 | ph), |
581 | GNUNET_MQ_handler_end () | 575 | GNUNET_MQ_handler_end() |
582 | }; | 576 | }; |
583 | struct GNUNET_MQ_Envelope *env; | 577 | struct GNUNET_MQ_Envelope *env; |
584 | struct ClientStartMessage *init; | 578 | struct ClientStartMessage *init; |
585 | 579 | ||
586 | GNUNET_assert (NULL == ph->mq); | 580 | GNUNET_assert(NULL == ph->mq); |
587 | ph->mq = GNUNET_CLIENT_connect (ph->cfg, | 581 | ph->mq = GNUNET_CLIENT_connect(ph->cfg, |
588 | "ats", | 582 | "ats", |
589 | handlers, | 583 | handlers, |
590 | &mq_error_handler, | 584 | &mq_error_handler, |
591 | ph); | 585 | ph); |
592 | if (NULL == ph->mq) | 586 | if (NULL == ph->mq) |
593 | return; | 587 | return; |
594 | env = GNUNET_MQ_msg (init, | 588 | env = GNUNET_MQ_msg(init, |
595 | GNUNET_MESSAGE_TYPE_ATS_START); | 589 | GNUNET_MESSAGE_TYPE_ATS_START); |
596 | init->start_flag = htonl ( (NULL == ph->addr_info_cb) | 590 | init->start_flag = htonl((NULL == ph->addr_info_cb) |
597 | ? START_FLAG_PERFORMANCE_NO_PIC | 591 | ? START_FLAG_PERFORMANCE_NO_PIC |
598 | : START_FLAG_PERFORMANCE_WITH_PIC); | 592 | : START_FLAG_PERFORMANCE_WITH_PIC); |
599 | GNUNET_MQ_send (ph->mq, | 593 | GNUNET_MQ_send(ph->mq, |
600 | env); | 594 | env); |
601 | } | 595 | } |
602 | 596 | ||
603 | 597 | ||
@@ -606,27 +600,27 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph) | |||
606 | * | 600 | * |
607 | * @param cfg configuration to use | 601 | * @param cfg configuration to use |
608 | * @param addr_info_cb callback called when performance characteristics for | 602 | * @param addr_info_cb callback called when performance characteristics for |
609 | * an address change | 603 | * an address change |
610 | * @param addr_info_cb_cls closure for @a addr_info_cb | 604 | * @param addr_info_cb_cls closure for @a addr_info_cb |
611 | * @return ats performance context | 605 | * @return ats performance context |
612 | */ | 606 | */ |
613 | struct GNUNET_ATS_PerformanceHandle * | 607 | struct GNUNET_ATS_PerformanceHandle * |
614 | GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 608 | GNUNET_ATS_performance_init(const struct GNUNET_CONFIGURATION_Handle *cfg, |
615 | GNUNET_ATS_AddressInformationCallback addr_info_cb, | 609 | GNUNET_ATS_AddressInformationCallback addr_info_cb, |
616 | void *addr_info_cb_cls) | 610 | void *addr_info_cb_cls) |
617 | { | 611 | { |
618 | struct GNUNET_ATS_PerformanceHandle *ph; | 612 | struct GNUNET_ATS_PerformanceHandle *ph; |
619 | 613 | ||
620 | ph = GNUNET_new (struct GNUNET_ATS_PerformanceHandle); | 614 | ph = GNUNET_new(struct GNUNET_ATS_PerformanceHandle); |
621 | ph->cfg = cfg; | 615 | ph->cfg = cfg; |
622 | ph->addr_info_cb = addr_info_cb; | 616 | ph->addr_info_cb = addr_info_cb; |
623 | ph->addr_info_cb_cls = addr_info_cb_cls; | 617 | ph->addr_info_cb_cls = addr_info_cb_cls; |
624 | reconnect (ph); | 618 | reconnect(ph); |
625 | if (NULL == ph->mq) | 619 | if (NULL == ph->mq) |
626 | { | 620 | { |
627 | GNUNET_free (ph); | 621 | GNUNET_free(ph); |
628 | return NULL; | 622 | return NULL; |
629 | } | 623 | } |
630 | return ph; | 624 | return ph; |
631 | } | 625 | } |
632 | 626 | ||
@@ -637,37 +631,37 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
637 | * @param ph handle | 631 | * @param ph handle |
638 | */ | 632 | */ |
639 | void | 633 | void |
640 | GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | 634 | GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph) |
641 | { | 635 | { |
642 | struct GNUNET_ATS_ReservationContext *rc; | 636 | struct GNUNET_ATS_ReservationContext *rc; |
643 | struct GNUNET_ATS_AddressListHandle *alh; | 637 | struct GNUNET_ATS_AddressListHandle *alh; |
644 | 638 | ||
645 | while (NULL != (alh = ph->addresslist_head)) | 639 | while (NULL != (alh = ph->addresslist_head)) |
646 | { | 640 | { |
647 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 641 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
648 | ph->addresslist_tail, | 642 | ph->addresslist_tail, |
649 | alh); | 643 | alh); |
650 | GNUNET_free (alh); | 644 | GNUNET_free(alh); |
651 | } | 645 | } |
652 | while (NULL != (rc = ph->reservation_head)) | 646 | while (NULL != (rc = ph->reservation_head)) |
653 | { | 647 | { |
654 | GNUNET_CONTAINER_DLL_remove (ph->reservation_head, | 648 | GNUNET_CONTAINER_DLL_remove(ph->reservation_head, |
655 | ph->reservation_tail, | 649 | ph->reservation_tail, |
656 | rc); | 650 | rc); |
657 | GNUNET_break (NULL == rc->rcb); | 651 | GNUNET_break(NULL == rc->rcb); |
658 | GNUNET_free (rc); | 652 | GNUNET_free(rc); |
659 | } | 653 | } |
660 | if (NULL != ph->task) | 654 | if (NULL != ph->task) |
661 | { | 655 | { |
662 | GNUNET_SCHEDULER_cancel (ph->task); | 656 | GNUNET_SCHEDULER_cancel(ph->task); |
663 | ph->task = NULL; | 657 | ph->task = NULL; |
664 | } | 658 | } |
665 | if (NULL != ph->mq) | 659 | if (NULL != ph->mq) |
666 | { | 660 | { |
667 | GNUNET_MQ_destroy (ph->mq); | 661 | GNUNET_MQ_destroy(ph->mq); |
668 | ph->mq = NULL; | 662 | ph->mq = NULL; |
669 | } | 663 | } |
670 | GNUNET_free (ph); | 664 | GNUNET_free(ph); |
671 | } | 665 | } |
672 | 666 | ||
673 | 667 | ||
@@ -686,11 +680,11 @@ GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph) | |||
686 | * @deprecated will be replaced soon | 680 | * @deprecated will be replaced soon |
687 | */ | 681 | */ |
688 | struct GNUNET_ATS_ReservationContext * | 682 | struct GNUNET_ATS_ReservationContext * |
689 | GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | 683 | GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, |
690 | const struct GNUNET_PeerIdentity *peer, | 684 | const struct GNUNET_PeerIdentity *peer, |
691 | int32_t amount, | 685 | int32_t amount, |
692 | GNUNET_ATS_ReservationCallback rcb, | 686 | GNUNET_ATS_ReservationCallback rcb, |
693 | void *rcb_cls) | 687 | void *rcb_cls) |
694 | { | 688 | { |
695 | struct GNUNET_ATS_ReservationContext *rc; | 689 | struct GNUNET_ATS_ReservationContext *rc; |
696 | struct GNUNET_MQ_Envelope *env; | 690 | struct GNUNET_MQ_Envelope *env; |
@@ -698,23 +692,23 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
698 | 692 | ||
699 | if (NULL == ph->mq) | 693 | if (NULL == ph->mq) |
700 | return NULL; | 694 | return NULL; |
701 | rc = GNUNET_new (struct GNUNET_ATS_ReservationContext); | 695 | rc = GNUNET_new(struct GNUNET_ATS_ReservationContext); |
702 | rc->size = amount; | 696 | rc->size = amount; |
703 | rc->peer = *peer; | 697 | rc->peer = *peer; |
704 | rc->rcb = rcb; | 698 | rc->rcb = rcb; |
705 | rc->rcb_cls = rcb_cls; | 699 | rc->rcb_cls = rcb_cls; |
706 | if ( (NULL != rcb) && | 700 | if ((NULL != rcb) && |
707 | (amount > 0) ) | 701 | (amount > 0)) |
708 | rc->undo = GNUNET_YES; | 702 | rc->undo = GNUNET_YES; |
709 | GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head, | 703 | GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, |
710 | ph->reservation_tail, | 704 | ph->reservation_tail, |
711 | rc); | 705 | rc); |
712 | env = GNUNET_MQ_msg (m, | 706 | env = GNUNET_MQ_msg(m, |
713 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); | 707 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); |
714 | m->amount = htonl (amount); | 708 | m->amount = htonl(amount); |
715 | m->peer = *peer; | 709 | m->peer = *peer; |
716 | GNUNET_MQ_send (ph->mq, | 710 | GNUNET_MQ_send(ph->mq, |
717 | env); | 711 | env); |
718 | return rc; | 712 | return rc; |
719 | } | 713 | } |
720 | 714 | ||
@@ -725,7 +719,7 @@ GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph, | |||
725 | * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call | 719 | * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call |
726 | */ | 720 | */ |
727 | void | 721 | void |
728 | GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | 722 | GNUNET_ATS_reserve_bandwidth_cancel(struct GNUNET_ATS_ReservationContext *rc) |
729 | { | 723 | { |
730 | rc->rcb = NULL; | 724 | rc->rcb = NULL; |
731 | } | 725 | } |
@@ -744,11 +738,11 @@ GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc) | |||
744 | * @return ats performance context | 738 | * @return ats performance context |
745 | */ | 739 | */ |
746 | struct GNUNET_ATS_AddressListHandle* | 740 | struct GNUNET_ATS_AddressListHandle* |
747 | GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | 741 | GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph, |
748 | const struct GNUNET_PeerIdentity *peer, | 742 | const struct GNUNET_PeerIdentity *peer, |
749 | int all, | 743 | int all, |
750 | GNUNET_ATS_AddressInformationCallback infocb, | 744 | GNUNET_ATS_AddressInformationCallback infocb, |
751 | void *infocb_cls) | 745 | void *infocb_cls) |
752 | { | 746 | { |
753 | struct GNUNET_ATS_AddressListHandle *alh; | 747 | struct GNUNET_ATS_AddressListHandle *alh; |
754 | struct GNUNET_MQ_Envelope *env; | 748 | struct GNUNET_MQ_Envelope *env; |
@@ -757,36 +751,36 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | |||
757 | if (NULL == ph->mq) | 751 | if (NULL == ph->mq) |
758 | return NULL; | 752 | return NULL; |
759 | if (NULL == infocb) | 753 | if (NULL == infocb) |
760 | { | 754 | { |
761 | GNUNET_break (0); | 755 | GNUNET_break(0); |
762 | return NULL; | 756 | return NULL; |
763 | } | 757 | } |
764 | alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle); | 758 | alh = GNUNET_new(struct GNUNET_ATS_AddressListHandle); |
765 | alh->id = ph->id++; | 759 | alh->id = ph->id++; |
766 | alh->cb = infocb; | 760 | alh->cb = infocb; |
767 | alh->cb_cls = infocb_cls; | 761 | alh->cb_cls = infocb_cls; |
768 | alh->ph = ph; | 762 | alh->ph = ph; |
769 | alh->all_addresses = all; | 763 | alh->all_addresses = all; |
770 | if (NULL == peer) | 764 | if (NULL == peer) |
771 | { | 765 | { |
772 | alh->all_peers = GNUNET_YES; | 766 | alh->all_peers = GNUNET_YES; |
773 | } | 767 | } |
774 | else | 768 | else |
775 | { | 769 | { |
776 | alh->all_peers = GNUNET_NO; | 770 | alh->all_peers = GNUNET_NO; |
777 | alh->peer = *peer; | 771 | alh->peer = *peer; |
778 | } | 772 | } |
779 | GNUNET_CONTAINER_DLL_insert (ph->addresslist_head, | 773 | GNUNET_CONTAINER_DLL_insert(ph->addresslist_head, |
780 | ph->addresslist_tail, | 774 | ph->addresslist_tail, |
781 | alh); | 775 | alh); |
782 | env = GNUNET_MQ_msg (m, | 776 | env = GNUNET_MQ_msg(m, |
783 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); | 777 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); |
784 | m->all = htonl (all); | 778 | m->all = htonl(all); |
785 | m->id = htonl (alh->id); | 779 | m->id = htonl(alh->id); |
786 | if (NULL != peer) | 780 | if (NULL != peer) |
787 | m->peer = *peer; | 781 | m->peer = *peer; |
788 | GNUNET_MQ_send (ph->mq, | 782 | GNUNET_MQ_send(ph->mq, |
789 | env); | 783 | env); |
790 | return alh; | 784 | return alh; |
791 | } | 785 | } |
792 | 786 | ||
@@ -797,14 +791,14 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph, | |||
797 | * @param alh the handle of the request to cancel | 791 | * @param alh the handle of the request to cancel |
798 | */ | 792 | */ |
799 | void | 793 | void |
800 | GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *alh) | 794 | GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle *alh) |
801 | { | 795 | { |
802 | struct GNUNET_ATS_PerformanceHandle *ph = alh->ph; | 796 | struct GNUNET_ATS_PerformanceHandle *ph = alh->ph; |
803 | 797 | ||
804 | GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, | 798 | GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, |
805 | ph->addresslist_tail, | 799 | ph->addresslist_tail, |
806 | alh); | 800 | alh); |
807 | GNUNET_free (alh); | 801 | GNUNET_free(alh); |
808 | } | 802 | } |
809 | 803 | ||
810 | 804 | ||
@@ -815,7 +809,7 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl | |||
815 | * @return a string or NULL if invalid | 809 | * @return a string or NULL if invalid |
816 | */ | 810 | */ |
817 | const char * | 811 | const char * |
818 | GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type) | 812 | GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type) |
819 | { | 813 | { |
820 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; | 814 | const char *prefs[] = GNUNET_ATS_PreferenceTypeString; |
821 | 815 | ||
@@ -834,9 +828,9 @@ GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type) | |||
834 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes | 828 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
835 | */ | 829 | */ |
836 | void | 830 | void |
837 | GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, | 831 | GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, |
838 | const struct GNUNET_PeerIdentity *peer, | 832 | const struct GNUNET_PeerIdentity *peer, |
839 | ...) | 833 | ...) |
840 | { | 834 | { |
841 | struct GNUNET_MQ_Envelope *env; | 835 | struct GNUNET_MQ_Envelope *env; |
842 | struct ChangePreferenceMessage *m; | 836 | struct ChangePreferenceMessage *m; |
@@ -850,54 +844,58 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
850 | count = 0; | 844 | count = 0; |
851 | va_start(ap, peer); | 845 | va_start(ap, peer); |
852 | while (GNUNET_ATS_PREFERENCE_END != | 846 | while (GNUNET_ATS_PREFERENCE_END != |
853 | (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 847 | (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
854 | { | ||
855 | switch (kind) | ||
856 | { | 848 | { |
857 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 849 | switch (kind) |
858 | count++; | 850 | { |
859 | (void) va_arg (ap, double); | 851 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
860 | break; | 852 | count++; |
861 | case GNUNET_ATS_PREFERENCE_LATENCY: | 853 | (void)va_arg(ap, double); |
862 | count++; | 854 | break; |
863 | (void) va_arg (ap, double); | 855 | |
864 | break; | 856 | case GNUNET_ATS_PREFERENCE_LATENCY: |
865 | default: | 857 | count++; |
866 | GNUNET_assert(0); | 858 | (void)va_arg(ap, double); |
859 | break; | ||
860 | |||
861 | default: | ||
862 | GNUNET_assert(0); | ||
863 | } | ||
867 | } | 864 | } |
868 | } | ||
869 | va_end(ap); | 865 | va_end(ap); |
870 | env = GNUNET_MQ_msg_extra (m, | 866 | env = GNUNET_MQ_msg_extra(m, |
871 | count * sizeof(struct PreferenceInformation), | 867 | count * sizeof(struct PreferenceInformation), |
872 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); | 868 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); |
873 | m->num_preferences = htonl (count); | 869 | m->num_preferences = htonl(count); |
874 | m->peer = *peer; | 870 | m->peer = *peer; |
875 | pi = (struct PreferenceInformation *) &m[1]; | 871 | pi = (struct PreferenceInformation *)&m[1]; |
876 | count = 0; | 872 | count = 0; |
877 | va_start(ap, peer); | 873 | va_start(ap, peer); |
878 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 874 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
879 | GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 875 | GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
880 | { | ||
881 | pi[count].preference_kind = htonl (kind); | ||
882 | switch (kind) | ||
883 | { | 876 | { |
884 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 877 | pi[count].preference_kind = htonl(kind); |
885 | pi[count].preference_value = (float) va_arg (ap, double); | 878 | switch (kind) |
886 | 879 | { | |
887 | count++; | 880 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
888 | break; | 881 | pi[count].preference_value = (float)va_arg(ap, double); |
889 | case GNUNET_ATS_PREFERENCE_LATENCY: | 882 | |
890 | pi[count].preference_value = (float) va_arg (ap, double); | 883 | count++; |
891 | 884 | break; | |
892 | count++; | 885 | |
893 | break; | 886 | case GNUNET_ATS_PREFERENCE_LATENCY: |
894 | default: | 887 | pi[count].preference_value = (float)va_arg(ap, double); |
895 | GNUNET_assert(0); | 888 | |
889 | count++; | ||
890 | break; | ||
891 | |||
892 | default: | ||
893 | GNUNET_assert(0); | ||
894 | } | ||
896 | } | 895 | } |
897 | } | ||
898 | va_end(ap); | 896 | va_end(ap); |
899 | GNUNET_MQ_send (ph->mq, | 897 | GNUNET_MQ_send(ph->mq, |
900 | env); | 898 | env); |
901 | } | 899 | } |
902 | 900 | ||
903 | 901 | ||
@@ -911,10 +909,10 @@ GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *p | |||
911 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes | 909 | * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes |
912 | */ | 910 | */ |
913 | void | 911 | void |
914 | GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | 912 | GNUNET_ATS_performance_give_feedback(struct GNUNET_ATS_PerformanceHandle *ph, |
915 | const struct GNUNET_PeerIdentity *peer, | 913 | const struct GNUNET_PeerIdentity *peer, |
916 | const struct GNUNET_TIME_Relative scope, | 914 | const struct GNUNET_TIME_Relative scope, |
917 | ...) | 915 | ...) |
918 | { | 916 | { |
919 | struct GNUNET_MQ_Envelope *env; | 917 | struct GNUNET_MQ_Envelope *env; |
920 | struct FeedbackPreferenceMessage *m; | 918 | struct FeedbackPreferenceMessage *m; |
@@ -928,55 +926,59 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph, | |||
928 | count = 0; | 926 | count = 0; |
929 | va_start(ap, scope); | 927 | va_start(ap, scope); |
930 | while (GNUNET_ATS_PREFERENCE_END != | 928 | while (GNUNET_ATS_PREFERENCE_END != |
931 | (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 929 | (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
932 | { | ||
933 | switch (kind) | ||
934 | { | 930 | { |
935 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 931 | switch (kind) |
936 | count++; | 932 | { |
937 | (void) va_arg (ap, double); | 933 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
938 | break; | 934 | count++; |
939 | case GNUNET_ATS_PREFERENCE_LATENCY: | 935 | (void)va_arg(ap, double); |
940 | count++; | 936 | break; |
941 | (void) va_arg (ap, double); | 937 | |
942 | break; | 938 | case GNUNET_ATS_PREFERENCE_LATENCY: |
943 | default: | 939 | count++; |
944 | GNUNET_assert(0); | 940 | (void)va_arg(ap, double); |
941 | break; | ||
942 | |||
943 | default: | ||
944 | GNUNET_assert(0); | ||
945 | } | ||
945 | } | 946 | } |
946 | } | ||
947 | va_end(ap); | 947 | va_end(ap); |
948 | env = GNUNET_MQ_msg_extra (m, | 948 | env = GNUNET_MQ_msg_extra(m, |
949 | count * sizeof(struct PreferenceInformation), | 949 | count * sizeof(struct PreferenceInformation), |
950 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK); | 950 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK); |
951 | m->scope = GNUNET_TIME_relative_hton (scope); | 951 | m->scope = GNUNET_TIME_relative_hton(scope); |
952 | m->num_feedback = htonl (count); | 952 | m->num_feedback = htonl(count); |
953 | m->peer = *peer; | 953 | m->peer = *peer; |
954 | pi = (struct PreferenceInformation *) &m[1]; | 954 | pi = (struct PreferenceInformation *)&m[1]; |
955 | count = 0; | 955 | count = 0; |
956 | va_start(ap, scope); | 956 | va_start(ap, scope); |
957 | while (GNUNET_ATS_PREFERENCE_END != (kind = | 957 | while (GNUNET_ATS_PREFERENCE_END != (kind = |
958 | GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind) )) | 958 | GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) |
959 | { | ||
960 | pi[count].preference_kind = htonl (kind); | ||
961 | switch (kind) | ||
962 | { | 959 | { |
963 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 960 | pi[count].preference_kind = htonl(kind); |
964 | pi[count].preference_value = (float) va_arg (ap, double); | 961 | switch (kind) |
965 | 962 | { | |
966 | count++; | 963 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
967 | break; | 964 | pi[count].preference_value = (float)va_arg(ap, double); |
968 | case GNUNET_ATS_PREFERENCE_LATENCY: | 965 | |
969 | pi[count].preference_value = (float) va_arg (ap, double); | 966 | count++; |
970 | 967 | break; | |
971 | count++; | 968 | |
972 | break; | 969 | case GNUNET_ATS_PREFERENCE_LATENCY: |
973 | default: | 970 | pi[count].preference_value = (float)va_arg(ap, double); |
974 | GNUNET_assert(0); | 971 | |
972 | count++; | ||
973 | break; | ||
974 | |||
975 | default: | ||
976 | GNUNET_assert(0); | ||
977 | } | ||
975 | } | 978 | } |
976 | } | ||
977 | va_end(ap); | 979 | va_end(ap); |
978 | GNUNET_MQ_send (ph->mq, | 980 | GNUNET_MQ_send(ph->mq, |
979 | env); | 981 | env); |
980 | } | 982 | } |
981 | 983 | ||
982 | /* end of ats_api_performance.c */ | 984 | /* end of ats_api_performance.c */ |
diff --git a/src/ats/ats_api_scanner.c b/src/ats/ats_api_scanner.c index e23b4de8a..5c8ffe196 100644 --- a/src/ats/ats_api_scanner.c +++ b/src/ats/ats_api_scanner.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api_scanner.c | 21 | * @file ats/ats_api_scanner.c |
22 | * @brief LAN interface scanning to determine IPs in LAN | 22 | * @brief LAN interface scanning to determine IPs in LAN |
@@ -33,14 +33,14 @@ | |||
33 | * @param hbo value read | 33 | * @param hbo value read |
34 | */ | 34 | */ |
35 | void | 35 | void |
36 | GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo, | 36 | GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, |
37 | const struct GNUNET_ATS_Properties *hbo) | 37 | const struct GNUNET_ATS_Properties *hbo) |
38 | { | 38 | { |
39 | nbo->utilization_out = htonl (hbo->utilization_out); | 39 | nbo->utilization_out = htonl(hbo->utilization_out); |
40 | nbo->utilization_in = htonl (hbo->utilization_in); | 40 | nbo->utilization_in = htonl(hbo->utilization_in); |
41 | nbo->scope = htonl ((uint32_t) hbo->scope); | 41 | nbo->scope = htonl((uint32_t)hbo->scope); |
42 | nbo->distance = htonl (hbo->distance); | 42 | nbo->distance = htonl(hbo->distance); |
43 | nbo->delay = GNUNET_TIME_relative_hton (hbo->delay); | 43 | nbo->delay = GNUNET_TIME_relative_hton(hbo->delay); |
44 | } | 44 | } |
45 | 45 | ||
46 | 46 | ||
@@ -51,14 +51,14 @@ GNUNET_ATS_properties_hton (struct GNUNET_ATS_PropertiesNBO *nbo, | |||
51 | * @param nbo value read | 51 | * @param nbo value read |
52 | */ | 52 | */ |
53 | void | 53 | void |
54 | GNUNET_ATS_properties_ntoh (struct GNUNET_ATS_Properties *hbo, | 54 | GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo, |
55 | const struct GNUNET_ATS_PropertiesNBO *nbo) | 55 | const struct GNUNET_ATS_PropertiesNBO *nbo) |
56 | { | 56 | { |
57 | hbo->utilization_out = ntohl (nbo->utilization_out); | 57 | hbo->utilization_out = ntohl(nbo->utilization_out); |
58 | hbo->utilization_in = ntohl (nbo->utilization_in); | 58 | hbo->utilization_in = ntohl(nbo->utilization_in); |
59 | hbo->scope = ntohl ((uint32_t) nbo->scope); | 59 | hbo->scope = ntohl((uint32_t)nbo->scope); |
60 | hbo->distance = ntohl (nbo->distance); | 60 | hbo->distance = ntohl(nbo->distance); |
61 | hbo->delay = GNUNET_TIME_relative_ntoh (nbo->delay); | 61 | hbo->delay = GNUNET_TIME_relative_ntoh(nbo->delay); |
62 | } | 62 | } |
63 | 63 | ||
64 | 64 | ||
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index 532426e91..f375be6a5 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/ats_api_scheduling.c | 21 | * @file ats/ats_api_scheduling.c |
22 | * @brief automatic transport selection and outbound bandwidth determination | 22 | * @brief automatic transport selection and outbound bandwidth determination |
@@ -38,9 +38,9 @@ | |||
38 | /** | 38 | /** |
39 | * How frequently do we scan the interfaces for changes to the addresses? | 39 | * How frequently do we scan the interfaces for changes to the addresses? |
40 | */ | 40 | */ |
41 | #define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) | 41 | #define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2) |
42 | 42 | ||
43 | #define LOG(kind,...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__) | 43 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * Session ID we use if there is no session / slot. | 46 | * Session ID we use if there is no session / slot. |
@@ -53,9 +53,7 @@ | |||
53 | * doesn't matter if we have a session, any address that ATS is | 53 | * doesn't matter if we have a session, any address that ATS is |
54 | * allowed to suggest right now should be tracked. | 54 | * allowed to suggest right now should be tracked. |
55 | */ | 55 | */ |
56 | struct GNUNET_ATS_AddressRecord | 56 | struct GNUNET_ATS_AddressRecord { |
57 | { | ||
58 | |||
59 | /** | 57 | /** |
60 | * Scheduling handle this address record belongs to. | 58 | * Scheduling handle this address record belongs to. |
61 | */ | 59 | */ |
@@ -99,9 +97,7 @@ struct GNUNET_ATS_AddressRecord | |||
99 | /** | 97 | /** |
100 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. | 98 | * Handle to the ATS subsystem for bandwidth/transport scheduling information. |
101 | */ | 99 | */ |
102 | struct GNUNET_ATS_SchedulingHandle | 100 | struct GNUNET_ATS_SchedulingHandle { |
103 | { | ||
104 | |||
105 | /** | 101 | /** |
106 | * Our configuration. | 102 | * Our configuration. |
107 | */ | 103 | */ |
@@ -144,7 +140,6 @@ struct GNUNET_ATS_SchedulingHandle | |||
144 | * Size of the @e session_array. | 140 | * Size of the @e session_array. |
145 | */ | 141 | */ |
146 | unsigned int session_array_size; | 142 | unsigned int session_array_size; |
147 | |||
148 | }; | 143 | }; |
149 | 144 | ||
150 | 145 | ||
@@ -154,7 +149,7 @@ struct GNUNET_ATS_SchedulingHandle | |||
154 | * @param sh handle to use to re-connect. | 149 | * @param sh handle to use to re-connect. |
155 | */ | 150 | */ |
156 | static void | 151 | static void |
157 | reconnect (struct GNUNET_ATS_SchedulingHandle *sh); | 152 | reconnect(struct GNUNET_ATS_SchedulingHandle *sh); |
158 | 153 | ||
159 | 154 | ||
160 | /** | 155 | /** |
@@ -163,12 +158,12 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh); | |||
163 | * @param cls handle to use to re-connect. | 158 | * @param cls handle to use to re-connect. |
164 | */ | 159 | */ |
165 | static void | 160 | static void |
166 | reconnect_task (void *cls) | 161 | reconnect_task(void *cls) |
167 | { | 162 | { |
168 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 163 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
169 | 164 | ||
170 | sh->task = NULL; | 165 | sh->task = NULL; |
171 | reconnect (sh); | 166 | reconnect(sh); |
172 | } | 167 | } |
173 | 168 | ||
174 | 169 | ||
@@ -178,21 +173,21 @@ reconnect_task (void *cls) | |||
178 | * @param sh our handle | 173 | * @param sh our handle |
179 | */ | 174 | */ |
180 | static void | 175 | static void |
181 | force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | 176 | force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh) |
182 | { | 177 | { |
183 | if (NULL != sh->mq) | 178 | if (NULL != sh->mq) |
184 | { | 179 | { |
185 | GNUNET_MQ_destroy (sh->mq); | 180 | GNUNET_MQ_destroy(sh->mq); |
186 | sh->mq = NULL; | 181 | sh->mq = NULL; |
187 | } | 182 | } |
188 | sh->suggest_cb (sh->suggest_cb_cls, | 183 | sh->suggest_cb(sh->suggest_cb_cls, |
189 | NULL, NULL, NULL, | 184 | NULL, NULL, NULL, |
190 | GNUNET_BANDWIDTH_ZERO, | 185 | GNUNET_BANDWIDTH_ZERO, |
191 | GNUNET_BANDWIDTH_ZERO); | 186 | GNUNET_BANDWIDTH_ZERO); |
192 | sh->backoff = GNUNET_TIME_STD_BACKOFF (sh->backoff); | 187 | sh->backoff = GNUNET_TIME_STD_BACKOFF(sh->backoff); |
193 | sh->task = GNUNET_SCHEDULER_add_delayed (sh->backoff, | 188 | sh->task = GNUNET_SCHEDULER_add_delayed(sh->backoff, |
194 | &reconnect_task, | 189 | &reconnect_task, |
195 | sh); | 190 | sh); |
196 | } | 191 | } |
197 | 192 | ||
198 | 193 | ||
@@ -205,37 +200,37 @@ force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
205 | * @return the session object (or NULL) | 200 | * @return the session object (or NULL) |
206 | */ | 201 | */ |
207 | static struct GNUNET_ATS_AddressRecord * | 202 | static struct GNUNET_ATS_AddressRecord * |
208 | find_session (struct GNUNET_ATS_SchedulingHandle *sh, | 203 | find_session(struct GNUNET_ATS_SchedulingHandle *sh, |
209 | uint32_t session_id, | 204 | uint32_t session_id, |
210 | const struct GNUNET_PeerIdentity *peer) | 205 | const struct GNUNET_PeerIdentity *peer) |
211 | { | 206 | { |
212 | struct GNUNET_ATS_AddressRecord *ar; | 207 | struct GNUNET_ATS_AddressRecord *ar; |
213 | 208 | ||
214 | if (session_id >= sh->session_array_size) | 209 | if (session_id >= sh->session_array_size) |
215 | { | 210 | { |
216 | GNUNET_break (0); | 211 | GNUNET_break(0); |
217 | return NULL; | 212 | return NULL; |
218 | } | 213 | } |
219 | if (0 == session_id) | 214 | if (0 == session_id) |
220 | return NULL; | 215 | return NULL; |
221 | ar = sh->session_array[session_id]; | 216 | ar = sh->session_array[session_id]; |
222 | if (NULL == ar) | 217 | if (NULL == ar) |
223 | { | 218 | { |
224 | GNUNET_break (0); | 219 | GNUNET_break(0); |
225 | return NULL; | 220 | return NULL; |
226 | } | 221 | } |
227 | if (NULL == ar->address) | 222 | if (NULL == ar->address) |
228 | { | 223 | { |
229 | /* address was destroyed in the meantime, this can happen | 224 | /* address was destroyed in the meantime, this can happen |
230 | as we communicate asynchronously with the ATS service. */ | 225 | as we communicate asynchronously with the ATS service. */ |
231 | return NULL; | 226 | return NULL; |
232 | } | 227 | } |
233 | if (0 != GNUNET_memcmp (peer, | 228 | if (0 != GNUNET_memcmp(peer, |
234 | &ar->address->peer)) | 229 | &ar->address->peer)) |
235 | { | 230 | { |
236 | GNUNET_break (0); | 231 | GNUNET_break(0); |
237 | return NULL; | 232 | return NULL; |
238 | } | 233 | } |
239 | return ar; | 234 | return ar; |
240 | } | 235 | } |
241 | 236 | ||
@@ -247,27 +242,27 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, | |||
247 | * @return an unused slot, but never NOT_FOUND (0) | 242 | * @return an unused slot, but never NOT_FOUND (0) |
248 | */ | 243 | */ |
249 | static uint32_t | 244 | static uint32_t |
250 | find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh) | 245 | find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh) |
251 | { | 246 | { |
252 | static uint32_t off; | 247 | static uint32_t off; |
253 | uint32_t i; | 248 | uint32_t i; |
254 | 249 | ||
255 | GNUNET_assert (0 != sh->session_array_size); | 250 | GNUNET_assert(0 != sh->session_array_size); |
256 | i = 0; | 251 | i = 0; |
257 | while ( ( (NOT_FOUND == off) || | 252 | while (((NOT_FOUND == off) || |
258 | (NULL != sh->session_array[off % sh->session_array_size]) ) && | 253 | (NULL != sh->session_array[off % sh->session_array_size])) && |
259 | (i < sh->session_array_size) ) | 254 | (i < sh->session_array_size)) |
260 | { | 255 | { |
261 | off++; | 256 | off++; |
262 | i++; | 257 | i++; |
263 | } | 258 | } |
264 | if ( (NOT_FOUND != off % sh->session_array_size) && | 259 | if ((NOT_FOUND != off % sh->session_array_size) && |
265 | (NULL == sh->session_array[off % sh->session_array_size]) ) | 260 | (NULL == sh->session_array[off % sh->session_array_size])) |
266 | return off; | 261 | return off; |
267 | i = sh->session_array_size; | 262 | i = sh->session_array_size; |
268 | GNUNET_array_grow (sh->session_array, | 263 | GNUNET_array_grow(sh->session_array, |
269 | sh->session_array_size, | 264 | sh->session_array_size, |
270 | sh->session_array_size * 2); | 265 | sh->session_array_size * 2); |
271 | return i; | 266 | return i; |
272 | } | 267 | } |
273 | 268 | ||
@@ -281,26 +276,26 @@ find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh) | |||
281 | * @return the session id or NOT_FOUND for error | 276 | * @return the session id or NOT_FOUND for error |
282 | */ | 277 | */ |
283 | static uint32_t | 278 | static uint32_t |
284 | find_session_id (struct GNUNET_ATS_SchedulingHandle *sh, | 279 | find_session_id(struct GNUNET_ATS_SchedulingHandle *sh, |
285 | struct GNUNET_ATS_Session *session, | 280 | struct GNUNET_ATS_Session *session, |
286 | const struct GNUNET_HELLO_Address *address) | 281 | const struct GNUNET_HELLO_Address *address) |
287 | { | 282 | { |
288 | uint32_t i; | 283 | uint32_t i; |
289 | 284 | ||
290 | if (NULL == address) | 285 | if (NULL == address) |
291 | { | 286 | { |
292 | GNUNET_break (0); | 287 | GNUNET_break(0); |
293 | return NOT_FOUND; | 288 | return NOT_FOUND; |
294 | } | 289 | } |
295 | for (i = 1; i < sh->session_array_size; i++) | 290 | for (i = 1; i < sh->session_array_size; i++) |
296 | if ( (NULL != sh->session_array[i]) && | 291 | if ((NULL != sh->session_array[i]) && |
297 | (GNUNET_NO == sh->session_array[i]->in_destroy) && | 292 | (GNUNET_NO == sh->session_array[i]->in_destroy) && |
298 | ( (session == sh->session_array[i]->session) || | 293 | ((session == sh->session_array[i]->session) || |
299 | (NULL == sh->session_array[i]->session) ) && | 294 | (NULL == sh->session_array[i]->session)) && |
300 | (0 == GNUNET_memcmp (&address->peer, | 295 | (0 == GNUNET_memcmp(&address->peer, |
301 | &sh->session_array[i]->address->peer)) && | 296 | &sh->session_array[i]->address->peer)) && |
302 | (0 == GNUNET_HELLO_address_cmp (address, | 297 | (0 == GNUNET_HELLO_address_cmp(address, |
303 | sh->session_array[i]->address)) ) | 298 | sh->session_array[i]->address))) |
304 | return i; | 299 | return i; |
305 | return NOT_FOUND; | 300 | return NOT_FOUND; |
306 | } | 301 | } |
@@ -314,29 +309,29 @@ find_session_id (struct GNUNET_ATS_SchedulingHandle *sh, | |||
314 | * @param session_id identifies session that is no longer valid | 309 | * @param session_id identifies session that is no longer valid |
315 | */ | 310 | */ |
316 | static void | 311 | static void |
317 | release_session (struct GNUNET_ATS_SchedulingHandle *sh, | 312 | release_session(struct GNUNET_ATS_SchedulingHandle *sh, |
318 | uint32_t session_id) | 313 | uint32_t session_id) |
319 | { | 314 | { |
320 | struct GNUNET_ATS_AddressRecord *ar; | 315 | struct GNUNET_ATS_AddressRecord *ar; |
321 | 316 | ||
322 | if (NOT_FOUND == session_id) | 317 | if (NOT_FOUND == session_id) |
323 | return; | 318 | return; |
324 | if (session_id >= sh->session_array_size) | 319 | if (session_id >= sh->session_array_size) |
325 | { | 320 | { |
326 | GNUNET_break (0); | 321 | GNUNET_break(0); |
327 | force_reconnect (sh); | 322 | force_reconnect(sh); |
328 | return; | 323 | return; |
329 | } | 324 | } |
330 | /* this slot should have been removed from remove_session before */ | 325 | /* this slot should have been removed from remove_session before */ |
331 | ar = sh->session_array[session_id]; | 326 | ar = sh->session_array[session_id]; |
332 | if (NULL != ar->session) | 327 | if (NULL != ar->session) |
333 | { | 328 | { |
334 | GNUNET_break (0); | 329 | GNUNET_break(0); |
335 | force_reconnect (sh); | 330 | force_reconnect(sh); |
336 | return; | 331 | return; |
337 | } | 332 | } |
338 | GNUNET_HELLO_address_free (ar->address); | 333 | GNUNET_HELLO_address_free(ar->address); |
339 | GNUNET_free (ar); | 334 | GNUNET_free(ar); |
340 | sh->session_array[session_id] = NULL; | 335 | sh->session_array[session_id] = NULL; |
341 | } | 336 | } |
342 | 337 | ||
@@ -349,15 +344,15 @@ release_session (struct GNUNET_ATS_SchedulingHandle *sh, | |||
349 | * @param srm message received | 344 | * @param srm message received |
350 | */ | 345 | */ |
351 | static void | 346 | static void |
352 | handle_ats_session_release (void *cls, | 347 | handle_ats_session_release(void *cls, |
353 | const struct GNUNET_ATS_SessionReleaseMessage *srm) | 348 | const struct GNUNET_ATS_SessionReleaseMessage *srm) |
354 | { | 349 | { |
355 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 350 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
356 | 351 | ||
357 | /* Note: peer field in srm not necessary right now, | 352 | /* Note: peer field in srm not necessary right now, |
358 | but might be good to have in the future */ | 353 | but might be good to have in the future */ |
359 | release_session (sh, | 354 | release_session(sh, |
360 | ntohl (srm->session_id)); | 355 | ntohl(srm->session_id)); |
361 | } | 356 | } |
362 | 357 | ||
363 | 358 | ||
@@ -369,71 +364,71 @@ handle_ats_session_release (void *cls, | |||
369 | * @param m message received | 364 | * @param m message received |
370 | */ | 365 | */ |
371 | static void | 366 | static void |
372 | handle_ats_address_suggestion (void *cls, | 367 | handle_ats_address_suggestion(void *cls, |
373 | const struct AddressSuggestionMessage *m) | 368 | const struct AddressSuggestionMessage *m) |
374 | { | 369 | { |
375 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 370 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
376 | struct GNUNET_ATS_AddressRecord *ar; | 371 | struct GNUNET_ATS_AddressRecord *ar; |
377 | uint32_t session_id; | 372 | uint32_t session_id; |
378 | 373 | ||
379 | session_id = ntohl (m->session_id); | 374 | session_id = ntohl(m->session_id); |
380 | if (0 == session_id) | 375 | if (0 == session_id) |
381 | { | 376 | { |
382 | GNUNET_break (0); | 377 | GNUNET_break(0); |
383 | force_reconnect (sh); | 378 | force_reconnect(sh); |
384 | return; | 379 | return; |
385 | } | 380 | } |
386 | ar = find_session (sh, | 381 | ar = find_session(sh, |
387 | session_id, | 382 | session_id, |
388 | &m->peer); | 383 | &m->peer); |
389 | if (NULL == ar) | 384 | if (NULL == ar) |
390 | { | 385 | { |
391 | GNUNET_break (0); | 386 | GNUNET_break(0); |
392 | force_reconnect (sh); | 387 | force_reconnect(sh); |
393 | return; | 388 | return; |
394 | } | 389 | } |
395 | if (NULL == sh->suggest_cb) | 390 | if (NULL == sh->suggest_cb) |
396 | return; | 391 | return; |
397 | if (GNUNET_YES == ar->in_destroy) | 392 | if (GNUNET_YES == ar->in_destroy) |
398 | { | ||
399 | /* ignore suggestion, as this address is dying, unless BW is 0, | ||
400 | in that case signal 'disconnect' via BW 0 */ | ||
401 | if ( (0 == ntohl (m->bandwidth_out.value__)) && | ||
402 | (0 == ntohl (m->bandwidth_in.value__)) ) | ||
403 | { | 393 | { |
404 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 394 | /* ignore suggestion, as this address is dying, unless BW is 0, |
405 | "ATS suggests disconnect from peer `%s' with BW %u/%u\n", | 395 | in that case signal 'disconnect' via BW 0 */ |
406 | GNUNET_i2s (&ar->address->peer), | 396 | if ((0 == ntohl(m->bandwidth_out.value__)) && |
407 | (unsigned int) ntohl (m->bandwidth_out.value__), | 397 | (0 == ntohl(m->bandwidth_in.value__))) |
408 | (unsigned int) ntohl (m->bandwidth_in.value__)); | 398 | { |
409 | sh->suggest_cb (sh->suggest_cb_cls, | 399 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
410 | &m->peer, | 400 | "ATS suggests disconnect from peer `%s' with BW %u/%u\n", |
411 | NULL, | 401 | GNUNET_i2s(&ar->address->peer), |
412 | NULL, | 402 | (unsigned int)ntohl(m->bandwidth_out.value__), |
413 | m->bandwidth_out, | 403 | (unsigned int)ntohl(m->bandwidth_in.value__)); |
414 | m->bandwidth_in); | 404 | sh->suggest_cb(sh->suggest_cb_cls, |
405 | &m->peer, | ||
406 | NULL, | ||
407 | NULL, | ||
408 | m->bandwidth_out, | ||
409 | m->bandwidth_in); | ||
410 | } | ||
411 | return; | ||
412 | } | ||
413 | if ((NULL == ar->session) && | ||
414 | (GNUNET_HELLO_address_check_option(ar->address, | ||
415 | GNUNET_HELLO_ADDRESS_INFO_INBOUND))) | ||
416 | { | ||
417 | GNUNET_break(0); | ||
418 | return; | ||
415 | } | 419 | } |
416 | return; | ||
417 | } | ||
418 | if ( (NULL == ar->session) && | ||
419 | (GNUNET_HELLO_address_check_option (ar->address, | ||
420 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) ) | ||
421 | { | ||
422 | GNUNET_break (0); | ||
423 | return; | ||
424 | } | ||
425 | sh->backoff = GNUNET_TIME_UNIT_ZERO; | 420 | sh->backoff = GNUNET_TIME_UNIT_ZERO; |
426 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 421 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
427 | "ATS suggests address slot %u for peer `%s' using plugin %s\n", | 422 | "ATS suggests address slot %u for peer `%s' using plugin %s\n", |
428 | ar->slot, | 423 | ar->slot, |
429 | GNUNET_i2s (&ar->address->peer), | 424 | GNUNET_i2s(&ar->address->peer), |
430 | ar->address->transport_name); | 425 | ar->address->transport_name); |
431 | sh->suggest_cb (sh->suggest_cb_cls, | 426 | sh->suggest_cb(sh->suggest_cb_cls, |
432 | &m->peer, | 427 | &m->peer, |
433 | ar->address, | 428 | ar->address, |
434 | ar->session, | 429 | ar->session, |
435 | m->bandwidth_out, | 430 | m->bandwidth_out, |
436 | m->bandwidth_in); | 431 | m->bandwidth_in); |
437 | } | 432 | } |
438 | 433 | ||
439 | 434 | ||
@@ -445,15 +440,15 @@ handle_ats_address_suggestion (void *cls, | |||
445 | * @param error details about the error | 440 | * @param error details about the error |
446 | */ | 441 | */ |
447 | static void | 442 | static void |
448 | error_handler (void *cls, | 443 | error_handler(void *cls, |
449 | enum GNUNET_MQ_Error error) | 444 | enum GNUNET_MQ_Error error) |
450 | { | 445 | { |
451 | struct GNUNET_ATS_SchedulingHandle *sh = cls; | 446 | struct GNUNET_ATS_SchedulingHandle *sh = cls; |
452 | 447 | ||
453 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 448 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
454 | "ATS connection died (code %d), reconnecting\n", | 449 | "ATS connection died (code %d), reconnecting\n", |
455 | (int) error); | 450 | (int)error); |
456 | force_reconnect (sh); | 451 | force_reconnect(sh); |
457 | } | 452 | } |
458 | 453 | ||
459 | 454 | ||
@@ -465,8 +460,8 @@ error_handler (void *cls, | |||
465 | * @param ar the address to inform the ATS service about | 460 | * @param ar the address to inform the ATS service about |
466 | */ | 461 | */ |
467 | static void | 462 | static void |
468 | send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | 463 | send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh, |
469 | const struct GNUNET_ATS_AddressRecord *ar) | 464 | const struct GNUNET_ATS_AddressRecord *ar) |
470 | { | 465 | { |
471 | struct GNUNET_MQ_Envelope *ev; | 466 | struct GNUNET_MQ_Envelope *ev; |
472 | struct AddressAddMessage *m; | 467 | struct AddressAddMessage *m; |
@@ -476,32 +471,32 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
476 | 471 | ||
477 | if (NULL == sh->mq) | 472 | if (NULL == sh->mq) |
478 | return; /* disconnected, skip for now */ | 473 | return; /* disconnected, skip for now */ |
479 | GNUNET_break (GNUNET_NT_UNSPECIFIED != ar->properties.scope); | 474 | GNUNET_break(GNUNET_NT_UNSPECIFIED != ar->properties.scope); |
480 | namelen = strlen (ar->address->transport_name) + 1; | 475 | namelen = strlen(ar->address->transport_name) + 1; |
481 | msize = ar->address->address_length + namelen; | 476 | msize = ar->address->address_length + namelen; |
482 | ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); | 477 | ev = GNUNET_MQ_msg_extra(m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); |
483 | m->peer = ar->address->peer; | 478 | m->peer = ar->address->peer; |
484 | m->address_length = htons (ar->address->address_length); | 479 | m->address_length = htons(ar->address->address_length); |
485 | m->address_local_info = htonl ((uint32_t) ar->address->local_info); | 480 | m->address_local_info = htonl((uint32_t)ar->address->local_info); |
486 | m->plugin_name_length = htons (namelen); | 481 | m->plugin_name_length = htons(namelen); |
487 | m->session_id = htonl (ar->slot); | 482 | m->session_id = htonl(ar->slot); |
488 | m->properties = ar->properties; | 483 | m->properties = ar->properties; |
489 | 484 | ||
490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 485 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
491 | "Adding address for peer `%s', plugin `%s', session %p slot %u\n", | 486 | "Adding address for peer `%s', plugin `%s', session %p slot %u\n", |
492 | GNUNET_i2s (&ar->address->peer), | 487 | GNUNET_i2s(&ar->address->peer), |
493 | ar->address->transport_name, | 488 | ar->address->transport_name, |
494 | ar->session, | 489 | ar->session, |
495 | ar->slot); | 490 | ar->slot); |
496 | pm = (char *) &m[1]; | 491 | pm = (char *)&m[1]; |
497 | GNUNET_memcpy (pm, | 492 | GNUNET_memcpy(pm, |
498 | ar->address->address, | 493 | ar->address->address, |
499 | ar->address->address_length); | 494 | ar->address->address_length); |
500 | if (NULL != ar->address->transport_name) | 495 | if (NULL != ar->address->transport_name) |
501 | GNUNET_memcpy (&pm[ar->address->address_length], | 496 | GNUNET_memcpy(&pm[ar->address->address_length], |
502 | ar->address->transport_name, | 497 | ar->address->transport_name, |
503 | namelen); | 498 | namelen); |
504 | GNUNET_MQ_send (sh->mq, ev); | 499 | GNUNET_MQ_send(sh->mq, ev); |
505 | } | 500 | } |
506 | 501 | ||
507 | 502 | ||
@@ -511,51 +506,51 @@ send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh, | |||
511 | * @param sh handle to use to re-connect. | 506 | * @param sh handle to use to re-connect. |
512 | */ | 507 | */ |
513 | static void | 508 | static void |
514 | reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | 509 | reconnect(struct GNUNET_ATS_SchedulingHandle *sh) |
515 | { | 510 | { |
516 | struct GNUNET_MQ_MessageHandler handlers[] = { | 511 | struct GNUNET_MQ_MessageHandler handlers[] = { |
517 | GNUNET_MQ_hd_fixed_size (ats_session_release, | 512 | GNUNET_MQ_hd_fixed_size(ats_session_release, |
518 | GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE, | 513 | GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE, |
519 | struct GNUNET_ATS_SessionReleaseMessage, | 514 | struct GNUNET_ATS_SessionReleaseMessage, |
520 | sh), | 515 | sh), |
521 | GNUNET_MQ_hd_fixed_size (ats_address_suggestion, | 516 | GNUNET_MQ_hd_fixed_size(ats_address_suggestion, |
522 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, | 517 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, |
523 | struct AddressSuggestionMessage, | 518 | struct AddressSuggestionMessage, |
524 | sh), | 519 | sh), |
525 | GNUNET_MQ_handler_end () | 520 | GNUNET_MQ_handler_end() |
526 | }; | 521 | }; |
527 | struct GNUNET_MQ_Envelope *ev; | 522 | struct GNUNET_MQ_Envelope *ev; |
528 | struct ClientStartMessage *init; | 523 | struct ClientStartMessage *init; |
529 | unsigned int i; | 524 | unsigned int i; |
530 | struct GNUNET_ATS_AddressRecord *ar; | 525 | struct GNUNET_ATS_AddressRecord *ar; |
531 | 526 | ||
532 | GNUNET_assert (NULL == sh->mq); | 527 | GNUNET_assert(NULL == sh->mq); |
533 | sh->mq = GNUNET_CLIENT_connect (sh->cfg, | 528 | sh->mq = GNUNET_CLIENT_connect(sh->cfg, |
534 | "ats", | 529 | "ats", |
535 | handlers, | 530 | handlers, |
536 | &error_handler, | 531 | &error_handler, |
537 | sh); | 532 | sh); |
538 | if (NULL == sh->mq) | 533 | if (NULL == sh->mq) |
539 | { | 534 | { |
540 | GNUNET_break (0); | 535 | GNUNET_break(0); |
541 | force_reconnect (sh); | 536 | force_reconnect(sh); |
542 | return; | 537 | return; |
543 | } | 538 | } |
544 | ev = GNUNET_MQ_msg (init, | 539 | ev = GNUNET_MQ_msg(init, |
545 | GNUNET_MESSAGE_TYPE_ATS_START); | 540 | GNUNET_MESSAGE_TYPE_ATS_START); |
546 | init->start_flag = htonl (START_FLAG_SCHEDULING); | 541 | init->start_flag = htonl(START_FLAG_SCHEDULING); |
547 | GNUNET_MQ_send (sh->mq, ev); | 542 | GNUNET_MQ_send(sh->mq, ev); |
548 | if (NULL == sh->mq) | 543 | if (NULL == sh->mq) |
549 | return; | 544 | return; |
550 | for (i=0;i<sh->session_array_size;i++) | 545 | for (i = 0; i < sh->session_array_size; i++) |
551 | { | 546 | { |
552 | ar = sh->session_array[i]; | 547 | ar = sh->session_array[i]; |
553 | if (NULL == ar) | 548 | if (NULL == ar) |
554 | continue; | 549 | continue; |
555 | send_add_address_message (sh, ar); | 550 | send_add_address_message(sh, ar); |
556 | if (NULL == sh->mq) | 551 | if (NULL == sh->mq) |
557 | return; | 552 | return; |
558 | } | 553 | } |
559 | } | 554 | } |
560 | 555 | ||
561 | 556 | ||
@@ -568,20 +563,20 @@ reconnect (struct GNUNET_ATS_SchedulingHandle *sh) | |||
568 | * @return ats context | 563 | * @return ats context |
569 | */ | 564 | */ |
570 | struct GNUNET_ATS_SchedulingHandle * | 565 | struct GNUNET_ATS_SchedulingHandle * |
571 | GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | 566 | GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg, |
572 | GNUNET_ATS_AddressSuggestionCallback suggest_cb, | 567 | GNUNET_ATS_AddressSuggestionCallback suggest_cb, |
573 | void *suggest_cb_cls) | 568 | void *suggest_cb_cls) |
574 | { | 569 | { |
575 | struct GNUNET_ATS_SchedulingHandle *sh; | 570 | struct GNUNET_ATS_SchedulingHandle *sh; |
576 | 571 | ||
577 | sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle); | 572 | sh = GNUNET_new(struct GNUNET_ATS_SchedulingHandle); |
578 | sh->cfg = cfg; | 573 | sh->cfg = cfg; |
579 | sh->suggest_cb = suggest_cb; | 574 | sh->suggest_cb = suggest_cb; |
580 | sh->suggest_cb_cls = suggest_cb_cls; | 575 | sh->suggest_cb_cls = suggest_cb_cls; |
581 | GNUNET_array_grow (sh->session_array, | 576 | GNUNET_array_grow(sh->session_array, |
582 | sh->session_array_size, | 577 | sh->session_array_size, |
583 | 4); | 578 | 4); |
584 | reconnect (sh); | 579 | reconnect(sh); |
585 | return sh; | 580 | return sh; |
586 | } | 581 | } |
587 | 582 | ||
@@ -592,34 +587,34 @@ GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
592 | * @param sh handle to release | 587 | * @param sh handle to release |
593 | */ | 588 | */ |
594 | void | 589 | void |
595 | GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | 590 | GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh) |
596 | { | 591 | { |
597 | struct GNUNET_ATS_AddressRecord *ar; | 592 | struct GNUNET_ATS_AddressRecord *ar; |
598 | unsigned int i; | 593 | unsigned int i; |
599 | 594 | ||
600 | if (NULL != sh->mq) | 595 | if (NULL != sh->mq) |
601 | { | 596 | { |
602 | GNUNET_MQ_destroy (sh->mq); | 597 | GNUNET_MQ_destroy(sh->mq); |
603 | sh->mq = NULL; | 598 | sh->mq = NULL; |
604 | } | 599 | } |
605 | if (NULL != sh->task) | 600 | if (NULL != sh->task) |
606 | { | ||
607 | GNUNET_SCHEDULER_cancel (sh->task); | ||
608 | sh->task = NULL; | ||
609 | } | ||
610 | for (i=0;i<sh->session_array_size;i++) | ||
611 | { | ||
612 | if (NULL != (ar = sh->session_array[i])) | ||
613 | { | 601 | { |
614 | GNUNET_HELLO_address_free (ar->address); | 602 | GNUNET_SCHEDULER_cancel(sh->task); |
615 | GNUNET_free (ar); | 603 | sh->task = NULL; |
616 | sh->session_array[i] = NULL; | ||
617 | } | 604 | } |
618 | } | 605 | for (i = 0; i < sh->session_array_size; i++) |
619 | GNUNET_array_grow (sh->session_array, | 606 | { |
620 | sh->session_array_size, | 607 | if (NULL != (ar = sh->session_array[i])) |
621 | 0); | 608 | { |
622 | GNUNET_free (sh); | 609 | GNUNET_HELLO_address_free(ar->address); |
610 | GNUNET_free(ar); | ||
611 | sh->session_array[i] = NULL; | ||
612 | } | ||
613 | } | ||
614 | GNUNET_array_grow(sh->session_array, | ||
615 | sh->session_array_size, | ||
616 | 0); | ||
617 | GNUNET_free(sh); | ||
623 | } | 618 | } |
624 | 619 | ||
625 | 620 | ||
@@ -636,10 +631,10 @@ GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh) | |||
636 | * on error (i.e. ATS knows this exact address already) | 631 | * on error (i.e. ATS knows this exact address already) |
637 | */ | 632 | */ |
638 | struct GNUNET_ATS_AddressRecord * | 633 | struct GNUNET_ATS_AddressRecord * |
639 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | 634 | GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh, |
640 | const struct GNUNET_HELLO_Address *address, | 635 | const struct GNUNET_HELLO_Address *address, |
641 | struct GNUNET_ATS_Session *session, | 636 | struct GNUNET_ATS_Session *session, |
642 | const struct GNUNET_ATS_Properties *prop) | 637 | const struct GNUNET_ATS_Properties *prop) |
643 | { | 638 | { |
644 | struct GNUNET_ATS_AddressRecord *ar; | 639 | struct GNUNET_ATS_AddressRecord *ar; |
645 | size_t namelen; | 640 | size_t namelen; |
@@ -647,42 +642,42 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
647 | uint32_t s; | 642 | uint32_t s; |
648 | 643 | ||
649 | if (NULL == address) | 644 | if (NULL == address) |
650 | { | 645 | { |
651 | /* we need a valid address */ | 646 | /* we need a valid address */ |
652 | GNUNET_break (0); | 647 | GNUNET_break(0); |
653 | return NULL; | 648 | return NULL; |
654 | } | 649 | } |
655 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 650 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
656 | namelen = strlen (address->transport_name) + 1; | 651 | namelen = strlen(address->transport_name) + 1; |
657 | msize = address->address_length + namelen; | 652 | msize = address->address_length + namelen; |
658 | if ((msize + sizeof (struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) || | 653 | if ((msize + sizeof(struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) || |
659 | (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) || | 654 | (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) || |
660 | (namelen >= GNUNET_MAX_MESSAGE_SIZE) ) | 655 | (namelen >= GNUNET_MAX_MESSAGE_SIZE)) |
661 | { | 656 | { |
662 | /* address too large for us, this should not happen */ | 657 | /* address too large for us, this should not happen */ |
663 | GNUNET_break (0); | 658 | GNUNET_break(0); |
664 | return NULL; | 659 | return NULL; |
665 | } | 660 | } |
666 | 661 | ||
667 | if (NOT_FOUND != | 662 | if (NOT_FOUND != |
668 | find_session_id (sh, | 663 | find_session_id(sh, |
669 | session, | 664 | session, |
670 | address)) | 665 | address)) |
671 | { | 666 | { |
672 | /* Already existing, nothing todo, but this should not happen */ | 667 | /* Already existing, nothing todo, but this should not happen */ |
673 | GNUNET_break (0); | 668 | GNUNET_break(0); |
674 | return NULL; | 669 | return NULL; |
675 | } | 670 | } |
676 | s = find_empty_session_slot (sh); | 671 | s = find_empty_session_slot(sh); |
677 | ar = GNUNET_new (struct GNUNET_ATS_AddressRecord); | 672 | ar = GNUNET_new(struct GNUNET_ATS_AddressRecord); |
678 | ar->sh = sh; | 673 | ar->sh = sh; |
679 | ar->slot = s; | 674 | ar->slot = s; |
680 | ar->session = session; | 675 | ar->session = session; |
681 | ar->address = GNUNET_HELLO_address_copy (address); | 676 | ar->address = GNUNET_HELLO_address_copy(address); |
682 | GNUNET_ATS_properties_hton (&ar->properties, | 677 | GNUNET_ATS_properties_hton(&ar->properties, |
683 | prop); | 678 | prop); |
684 | sh->session_array[s] = ar; | 679 | sh->session_array[s] = ar; |
685 | send_add_address_message (sh, ar); | 680 | send_add_address_message(sh, ar); |
686 | return ar; | 681 | return ar; |
687 | } | 682 | } |
688 | 683 | ||
@@ -694,10 +689,10 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
694 | * @param session session handle | 689 | * @param session session handle |
695 | */ | 690 | */ |
696 | void | 691 | void |
697 | GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar, | 692 | GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar, |
698 | struct GNUNET_ATS_Session *session) | 693 | struct GNUNET_ATS_Session *session) |
699 | { | 694 | { |
700 | GNUNET_break (NULL == ar->session); | 695 | GNUNET_break(NULL == ar->session); |
701 | ar->session = session; | 696 | ar->session = session; |
702 | } | 697 | } |
703 | 698 | ||
@@ -715,17 +710,17 @@ GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar, | |||
715 | * use it still to establish a new session | 710 | * use it still to establish a new session |
716 | */ | 711 | */ |
717 | int | 712 | int |
718 | GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar, | 713 | GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar, |
719 | struct GNUNET_ATS_Session *session) | 714 | struct GNUNET_ATS_Session *session) |
720 | { | 715 | { |
721 | GNUNET_assert (session == ar->session); | 716 | GNUNET_assert(session == ar->session); |
722 | ar->session = NULL; | 717 | ar->session = NULL; |
723 | if (GNUNET_HELLO_address_check_option (ar->address, | 718 | if (GNUNET_HELLO_address_check_option(ar->address, |
724 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 719 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
725 | { | 720 | { |
726 | GNUNET_ATS_address_destroy (ar); | 721 | GNUNET_ATS_address_destroy(ar); |
727 | return GNUNET_YES; | 722 | return GNUNET_YES; |
728 | } | 723 | } |
729 | return GNUNET_NO; | 724 | return GNUNET_NO; |
730 | } | 725 | } |
731 | 726 | ||
@@ -742,30 +737,30 @@ GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar, | |||
742 | * @param prop performance data for the address | 737 | * @param prop performance data for the address |
743 | */ | 738 | */ |
744 | void | 739 | void |
745 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | 740 | GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar, |
746 | const struct GNUNET_ATS_Properties *prop) | 741 | const struct GNUNET_ATS_Properties *prop) |
747 | { | 742 | { |
748 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | 743 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; |
749 | struct GNUNET_MQ_Envelope *ev; | 744 | struct GNUNET_MQ_Envelope *ev; |
750 | struct AddressUpdateMessage *m; | 745 | struct AddressUpdateMessage *m; |
751 | 746 | ||
752 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 747 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
753 | "Updating address for peer `%s', plugin `%s', session %p slot %u\n", | 748 | "Updating address for peer `%s', plugin `%s', session %p slot %u\n", |
754 | GNUNET_i2s (&ar->address->peer), | 749 | GNUNET_i2s(&ar->address->peer), |
755 | ar->address->transport_name, | 750 | ar->address->transport_name, |
756 | ar->session, | 751 | ar->session, |
757 | ar->slot); | 752 | ar->slot); |
758 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 753 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
759 | GNUNET_ATS_properties_hton (&ar->properties, | 754 | GNUNET_ATS_properties_hton(&ar->properties, |
760 | prop); | 755 | prop); |
761 | if (NULL == sh->mq) | 756 | if (NULL == sh->mq) |
762 | return; /* disconnected, skip for now */ | 757 | return; /* disconnected, skip for now */ |
763 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); | 758 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); |
764 | m->session_id = htonl (ar->slot); | 759 | m->session_id = htonl(ar->slot); |
765 | m->peer = ar->address->peer; | 760 | m->peer = ar->address->peer; |
766 | m->properties = ar->properties; | 761 | m->properties = ar->properties; |
767 | GNUNET_MQ_send (sh->mq, | 762 | GNUNET_MQ_send(sh->mq, |
768 | ev); | 763 | ev); |
769 | } | 764 | } |
770 | 765 | ||
771 | 766 | ||
@@ -775,27 +770,27 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, | |||
775 | * @param ar address to destroy | 770 | * @param ar address to destroy |
776 | */ | 771 | */ |
777 | void | 772 | void |
778 | GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar) | 773 | GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar) |
779 | { | 774 | { |
780 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; | 775 | struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; |
781 | struct GNUNET_MQ_Envelope *ev; | 776 | struct GNUNET_MQ_Envelope *ev; |
782 | struct AddressDestroyedMessage *m; | 777 | struct AddressDestroyedMessage *m; |
783 | 778 | ||
784 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 779 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
785 | "Deleting address for peer `%s', plugin `%s', slot %u session %p\n", | 780 | "Deleting address for peer `%s', plugin `%s', slot %u session %p\n", |
786 | GNUNET_i2s (&ar->address->peer), | 781 | GNUNET_i2s(&ar->address->peer), |
787 | ar->address->transport_name, | 782 | ar->address->transport_name, |
788 | ar->slot, | 783 | ar->slot, |
789 | ar->session); | 784 | ar->session); |
790 | GNUNET_break (NULL == ar->session); | 785 | GNUNET_break(NULL == ar->session); |
791 | ar->session = NULL; | 786 | ar->session = NULL; |
792 | ar->in_destroy = GNUNET_YES; | 787 | ar->in_destroy = GNUNET_YES; |
793 | if (NULL == sh->mq) | 788 | if (NULL == sh->mq) |
794 | return; | 789 | return; |
795 | ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); | 790 | ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); |
796 | m->session_id = htonl (ar->slot); | 791 | m->session_id = htonl(ar->slot); |
797 | m->peer = ar->address->peer; | 792 | m->peer = ar->address->peer; |
798 | GNUNET_MQ_send (sh->mq, ev); | 793 | GNUNET_MQ_send(sh->mq, ev); |
799 | } | 794 | } |
800 | 795 | ||
801 | 796 | ||
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index 833cb9ded..4068cffce 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013 GNUnet e.V. | 3 | Copyright (C) 2010-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -85,32 +85,38 @@ static int opt_disable_normalization; | |||
85 | static int res; | 85 | static int res; |
86 | 86 | ||
87 | static void | 87 | static void |
88 | end_now (); | 88 | end_now(); |
89 | 89 | ||
90 | 90 | ||
91 | static char * | 91 | static char * |
92 | print_generator_type (enum GeneratorType g) | 92 | print_generator_type(enum GeneratorType g) |
93 | { | 93 | { |
94 | switch (g) { | 94 | switch (g) |
95 | { | ||
95 | case GNUNET_ATS_TEST_TG_CONSTANT: | 96 | case GNUNET_ATS_TEST_TG_CONSTANT: |
96 | return "CONSTANT"; | 97 | return "CONSTANT"; |
98 | |||
97 | case GNUNET_ATS_TEST_TG_LINEAR: | 99 | case GNUNET_ATS_TEST_TG_LINEAR: |
98 | return "LINEAR"; | 100 | return "LINEAR"; |
101 | |||
99 | case GNUNET_ATS_TEST_TG_RANDOM: | 102 | case GNUNET_ATS_TEST_TG_RANDOM: |
100 | return "RANDOM"; | 103 | return "RANDOM"; |
104 | |||
101 | case GNUNET_ATS_TEST_TG_SINUS: | 105 | case GNUNET_ATS_TEST_TG_SINUS: |
102 | return "SINUS"; | 106 | return "SINUS"; |
107 | |||
103 | default: | 108 | default: |
104 | return "INVALID"; | 109 | return "INVALID"; |
105 | break; | 110 | break; |
106 | } | 111 | } |
107 | } | 112 | } |
108 | 113 | ||
109 | 114 | ||
110 | static struct TestPeer * | 115 | static struct TestPeer * |
111 | find_peer_by_id (int id) | 116 | find_peer_by_id(int id) |
112 | { | 117 | { |
113 | struct TestPeer *cur; | 118 | struct TestPeer *cur; |
119 | |||
114 | for (cur = peer_head; NULL != cur; cur = cur->next) | 120 | for (cur = peer_head; NULL != cur; cur = cur->next) |
115 | if (cur->id == id) | 121 | if (cur->id == id) |
116 | return cur; | 122 | return cur; |
@@ -118,19 +124,21 @@ find_peer_by_id (int id) | |||
118 | } | 124 | } |
119 | 125 | ||
120 | static struct TestPeer * | 126 | static struct TestPeer * |
121 | find_peer_by_pid (const struct GNUNET_PeerIdentity *pid) | 127 | find_peer_by_pid(const struct GNUNET_PeerIdentity *pid) |
122 | { | 128 | { |
123 | struct TestPeer *cur; | 129 | struct TestPeer *cur; |
130 | |||
124 | for (cur = peer_head; NULL != cur; cur = cur->next) | 131 | for (cur = peer_head; NULL != cur; cur = cur->next) |
125 | if (0 == GNUNET_memcmp (&cur->peer_id, pid)) | 132 | if (0 == GNUNET_memcmp(&cur->peer_id, pid)) |
126 | return cur; | 133 | return cur; |
127 | return NULL; | 134 | return NULL; |
128 | } | 135 | } |
129 | 136 | ||
130 | static struct TestAddress * | 137 | static struct TestAddress * |
131 | find_address_by_id (struct TestPeer *peer, int aid) | 138 | find_address_by_id(struct TestPeer *peer, int aid) |
132 | { | 139 | { |
133 | struct TestAddress *cur; | 140 | struct TestAddress *cur; |
141 | |||
134 | for (cur = peer->addr_head; NULL != cur; cur = cur->next) | 142 | for (cur = peer->addr_head; NULL != cur; cur = cur->next) |
135 | if (cur->aid == aid) | 143 | if (cur->aid == aid) |
136 | return cur; | 144 | return cur; |
@@ -142,7 +150,7 @@ find_address_by_id (struct TestPeer *peer, int aid) | |||
142 | * Logging | 150 | * Logging |
143 | */ | 151 | */ |
144 | void | 152 | void |
145 | GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | 153 | GNUNET_ATS_solver_logging_now(struct LoggingHandle *l) |
146 | { | 154 | { |
147 | struct LoggingTimeStep *lts; | 155 | struct LoggingTimeStep *lts; |
148 | struct TestPeer *cur; | 156 | struct TestPeer *cur; |
@@ -151,7 +159,7 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
151 | struct LoggingAddress *log_a; | 159 | struct LoggingAddress *log_a; |
152 | int c; | 160 | int c; |
153 | 161 | ||
154 | lts = GNUNET_new (struct LoggingTimeStep); | 162 | lts = GNUNET_new(struct LoggingTimeStep); |
155 | GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts); | 163 | GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts); |
156 | lts->timestamp = GNUNET_TIME_absolute_get(); | 164 | lts->timestamp = GNUNET_TIME_absolute_get(); |
157 | if (NULL == lts->prev) | 165 | if (NULL == lts->prev) |
@@ -159,102 +167,103 @@ GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | |||
159 | else | 167 | else |
160 | lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp); | 168 | lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp); |
161 | 169 | ||
162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n", | 170 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n", |
163 | lts->timestamp.abs_value_us, lts->delta.rel_value_us); | 171 | lts->timestamp.abs_value_us, lts->delta.rel_value_us); |
164 | 172 | ||
165 | 173 | ||
166 | /* Store logging data here */ | 174 | /* Store logging data here */ |
167 | for (cur = peer_head; NULL != cur; cur = cur->next) | 175 | for (cur = peer_head; NULL != cur; cur = cur->next) |
168 | { | 176 | { |
169 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 177 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
170 | "Logging peer id %llu\n", cur->id); | 178 | "Logging peer id %llu\n", cur->id); |
171 | 179 | ||
172 | log_p = GNUNET_new (struct LoggingPeer); | 180 | log_p = GNUNET_new(struct LoggingPeer); |
173 | log_p->id = cur->id; | 181 | log_p->id = cur->id; |
174 | log_p->peer_id = cur->peer_id; | 182 | log_p->peer_id = cur->peer_id; |
175 | log_p->is_requested = cur->is_requested; | 183 | log_p->is_requested = cur->is_requested; |
176 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | 184 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) |
177 | { | 185 | { |
178 | log_p->pref_abs[c] = cur->pref_abs[c]; | 186 | log_p->pref_abs[c] = cur->pref_abs[c]; |
179 | log_p->pref_norm[c] = cur->pref_norm[c]; | 187 | log_p->pref_norm[c] = cur->pref_norm[c]; |
180 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
181 | "\t %s = %.2f %.2f [abs/rel]\n", | 189 | "\t %s = %.2f %.2f [abs/rel]\n", |
182 | GNUNET_ATS_print_preference_type(c), | 190 | GNUNET_ATS_print_preference_type(c), |
183 | log_p->pref_abs[c], log_p->pref_norm[c]); | 191 | log_p->pref_abs[c], log_p->pref_norm[c]); |
184 | } | 192 | } |
185 | GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p); | 193 | GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p); |
186 | |||
187 | for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next) | ||
188 | { | ||
189 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
190 | "Logging peer id %llu address %llu\n", | ||
191 | cur->id, cur_addr->aid); | ||
192 | log_a = GNUNET_new (struct LoggingAddress); | ||
193 | log_a->aid = cur_addr->aid; | ||
194 | log_a->active = cur_addr->ats_addr->active; | ||
195 | log_a->network = cur_addr->network; | ||
196 | log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in; | ||
197 | log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out; | ||
198 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | ||
199 | { | ||
200 | log_a->prop_abs[c] = cur_addr->prop_abs[c]; | ||
201 | log_a->prop_norm[c] = cur_addr->prop_norm[c]; | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
203 | "\t %s = %.2f %.2f [abs/rel]\n", | ||
204 | GNUNET_ATS_print_property_type(c), | ||
205 | log_a->prop_abs[c], | ||
206 | log_a->prop_norm[c]); | ||
207 | } | ||
208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active); | ||
209 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in); | ||
210 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out); | ||
211 | 194 | ||
212 | GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail, log_a); | 195 | for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next) |
196 | { | ||
197 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
198 | "Logging peer id %llu address %llu\n", | ||
199 | cur->id, cur_addr->aid); | ||
200 | log_a = GNUNET_new(struct LoggingAddress); | ||
201 | log_a->aid = cur_addr->aid; | ||
202 | log_a->active = cur_addr->ats_addr->active; | ||
203 | log_a->network = cur_addr->network; | ||
204 | log_a->assigned_bw_in = cur_addr->ats_addr->assigned_bw_in; | ||
205 | log_a->assigned_bw_out = cur_addr->ats_addr->assigned_bw_out; | ||
206 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | ||
207 | { | ||
208 | log_a->prop_abs[c] = cur_addr->prop_abs[c]; | ||
209 | log_a->prop_norm[c] = cur_addr->prop_norm[c]; | ||
210 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
211 | "\t %s = %.2f %.2f [abs/rel]\n", | ||
212 | GNUNET_ATS_print_property_type(c), | ||
213 | log_a->prop_abs[c], | ||
214 | log_a->prop_norm[c]); | ||
215 | } | ||
216 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\t Active = %i\n", log_a->active); | ||
217 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "\t BW in = %llu\n", log_a->assigned_bw_in); | ||
218 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n", log_a->assigned_bw_out); | ||
219 | |||
220 | GNUNET_CONTAINER_DLL_insert_tail(log_p->addr_head, log_p->addr_tail, log_a); | ||
221 | } | ||
213 | } | 222 | } |
214 | } | ||
215 | } | 223 | } |
216 | 224 | ||
217 | 225 | ||
218 | static void | 226 | static void |
219 | logging_task (void *cls) | 227 | logging_task(void *cls) |
220 | { | 228 | { |
221 | struct LoggingHandle *l = cls; | 229 | struct LoggingHandle *l = cls; |
222 | 230 | ||
223 | l->logging_task = NULL; | 231 | l->logging_task = NULL; |
224 | GNUNET_ATS_solver_logging_now (l); | 232 | GNUNET_ATS_solver_logging_now(l); |
225 | l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq, | 233 | l->logging_task = GNUNET_SCHEDULER_add_delayed(l->log_freq, |
226 | &logging_task, | 234 | &logging_task, |
227 | l); | 235 | l); |
228 | } | 236 | } |
229 | 237 | ||
230 | struct LoggingHandle * | 238 | struct LoggingHandle * |
231 | GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq) | 239 | GNUNET_ATS_solver_logging_start(struct GNUNET_TIME_Relative freq) |
232 | { | 240 | { |
233 | struct LoggingHandle *l; | 241 | struct LoggingHandle *l; |
234 | l = GNUNET_new (struct LoggingHandle); | ||
235 | 242 | ||
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n", | 243 | l = GNUNET_new(struct LoggingHandle); |
237 | GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO)); | 244 | |
245 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n", | ||
246 | GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO)); | ||
238 | l->log_freq = freq; | 247 | l->log_freq = freq; |
239 | l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l); | 248 | l->logging_task = GNUNET_SCHEDULER_add_now(&logging_task, l); |
240 | return l; | 249 | return l; |
241 | } | 250 | } |
242 | 251 | ||
243 | void | 252 | void |
244 | GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l) | 253 | GNUNET_ATS_solver_logging_stop(struct LoggingHandle *l) |
245 | { | 254 | { |
246 | if (NULL != l->logging_task) | 255 | if (NULL != l->logging_task) |
247 | GNUNET_SCHEDULER_cancel (l->logging_task); | 256 | GNUNET_SCHEDULER_cancel(l->logging_task); |
248 | 257 | ||
249 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n"); | 258 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Stop logging\n"); |
250 | 259 | ||
251 | l->logging_task = NULL; | 260 | l->logging_task = NULL; |
252 | } | 261 | } |
253 | 262 | ||
254 | static struct LoggingFileHandle * | 263 | static struct LoggingFileHandle * |
255 | find_logging_file_handle (struct LoggingFileHandle *lf_head, | 264 | find_logging_file_handle(struct LoggingFileHandle *lf_head, |
256 | struct LoggingFileHandle *lf_tail, | 265 | struct LoggingFileHandle *lf_tail, |
257 | int peer_id, int address_id) | 266 | int peer_id, int address_id) |
258 | { | 267 | { |
259 | struct LoggingFileHandle *res; | 268 | struct LoggingFileHandle *res; |
260 | 269 | ||
@@ -262,12 +271,11 @@ find_logging_file_handle (struct LoggingFileHandle *lf_head, | |||
262 | if ((res->pid == peer_id) && (res->aid == address_id)) | 271 | if ((res->pid == peer_id) && (res->aid == address_id)) |
263 | return res; | 272 | return res; |
264 | return NULL; | 273 | return NULL; |
265 | |||
266 | } | 274 | } |
267 | 275 | ||
268 | void | 276 | void |
269 | GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_stamp, | 277 | GNUNET_ATS_solver_logging_write_to_disk(struct LoggingHandle *l, int add_time_stamp, |
270 | char *output_dir) | 278 | char *output_dir) |
271 | { | 279 | { |
272 | struct LoggingTimeStep *lts; | 280 | struct LoggingTimeStep *lts; |
273 | struct LoggingPeer *log_p; | 281 | struct LoggingPeer *log_p; |
@@ -287,157 +295,153 @@ GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int add_time_s | |||
287 | 295 | ||
288 | use_dir = GNUNET_NO; | 296 | use_dir = GNUNET_NO; |
289 | if (NULL != output_dir) | 297 | if (NULL != output_dir) |
290 | { | ||
291 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir)) | ||
292 | { | ||
293 | fprintf (stderr, "Failed to create directory `%s'\n", output_dir); | ||
294 | return; | ||
295 | } | ||
296 | else | ||
297 | { | 298 | { |
298 | fprintf (stderr, "Created directory `%s'\n", output_dir); | 299 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(output_dir)) |
299 | use_dir = GNUNET_YES; | 300 | { |
301 | fprintf(stderr, "Failed to create directory `%s'\n", output_dir); | ||
302 | return; | ||
303 | } | ||
304 | else | ||
305 | { | ||
306 | fprintf(stderr, "Created directory `%s'\n", output_dir); | ||
307 | use_dir = GNUNET_YES; | ||
308 | } | ||
300 | } | 309 | } |
301 | } | ||
302 | 310 | ||
303 | lf_head = NULL; | 311 | lf_head = NULL; |
304 | lf_tail = NULL; | 312 | lf_tail = NULL; |
305 | 313 | ||
306 | for (lts = l->head; NULL != lts; lts = lts->next) | 314 | for (lts = l->head; NULL != lts; lts = lts->next) |
307 | { | ||
308 | |||
309 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n", | ||
310 | (long long unsigned int) lts->timestamp.abs_value_us); | ||
311 | |||
312 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) | ||
313 | { | 315 | { |
314 | for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next) | 316 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n", |
315 | { | 317 | (long long unsigned int)lts->timestamp.abs_value_us); |
316 | |||
317 | cur = find_logging_file_handle (lf_head, lf_tail, log_p->id, | ||
318 | log_a->aid); | ||
319 | if (NULL == cur) | ||
320 | { | ||
321 | cur = GNUNET_new (struct LoggingFileHandle); | ||
322 | cur->aid = log_a->aid; | ||
323 | cur->pid = log_p->id; | ||
324 | |||
325 | if (GNUNET_YES == add_time_stamp) | ||
326 | GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log", | ||
327 | (GNUNET_YES == use_dir) ? output_dir : "", | ||
328 | (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "", | ||
329 | e->log_prefix, | ||
330 | opt_solver, | ||
331 | cur->pid, | ||
332 | cur->aid, | ||
333 | l->head->timestamp.abs_value_us); | ||
334 | else | ||
335 | GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log", | ||
336 | (GNUNET_YES == use_dir) ? output_dir : "", | ||
337 | (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "", | ||
338 | e->log_prefix, | ||
339 | opt_solver, | ||
340 | cur->pid, | ||
341 | cur->aid); | ||
342 | |||
343 | fprintf (stderr, "Add writing log data for peer %llu address %llu to file `%s'\n", | ||
344 | cur->pid, cur->aid, filename); | ||
345 | |||
346 | |||
347 | cur->f_hd = GNUNET_DISK_file_open (filename, | ||
348 | GNUNET_DISK_OPEN_READWRITE | | ||
349 | GNUNET_DISK_OPEN_CREATE | | ||
350 | GNUNET_DISK_OPEN_TRUNCATE, | ||
351 | GNUNET_DISK_PERM_USER_READ | | ||
352 | GNUNET_DISK_PERM_USER_WRITE | | ||
353 | GNUNET_DISK_PERM_GROUP_READ | | ||
354 | GNUNET_DISK_PERM_OTHER_READ); | ||
355 | if (NULL == cur->f_hd) | ||
356 | { | ||
357 | fprintf (stderr, "Cannot open `%s' to write log data!\n", filename); | ||
358 | GNUNET_free (filename); | ||
359 | GNUNET_free (cur); | ||
360 | goto cleanup; | ||
361 | } | ||
362 | GNUNET_free (filename); | ||
363 | GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur); | ||
364 | |||
365 | GNUNET_asprintf(&datastring,"#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \ | ||
366 | "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \ | ||
367 | "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;"\ | ||
368 | "DELAY; DELAY; " \ | ||
369 | "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \ | ||
370 | "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n"); | ||
371 | GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring)); | ||
372 | GNUNET_free (datastring); | ||
373 | |||
374 | } | ||
375 | 318 | ||
376 | prefstring = GNUNET_strdup(""); | 319 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) |
377 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) | ||
378 | { | 320 | { |
379 | /* | 321 | for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next) |
380 | fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n", | 322 | { |
381 | GNUNET_ATS_print_preference_type(c), | 323 | cur = find_logging_file_handle(lf_head, lf_tail, log_p->id, |
382 | log_p->pref_abs[c], log_p->pref_norm[c]); | 324 | log_a->aid); |
383 | */ | 325 | if (NULL == cur) |
384 | GNUNET_asprintf(&prefstring_tmp,"%s;%.3f;%.3f", | 326 | { |
385 | prefstring, log_p->pref_abs[c], log_p->pref_norm[c]); | 327 | cur = GNUNET_new(struct LoggingFileHandle); |
386 | 328 | cur->aid = log_a->aid; | |
387 | 329 | cur->pid = log_p->id; | |
388 | GNUNET_free (prefstring); | 330 | |
389 | prefstring = GNUNET_strdup(prefstring_tmp); | 331 | if (GNUNET_YES == add_time_stamp) |
390 | GNUNET_free (prefstring_tmp); | 332 | GNUNET_asprintf(&filename, "%s%s%s_%s_p%u_a%u_%llu.log", |
333 | (GNUNET_YES == use_dir) ? output_dir : "", | ||
334 | (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "", | ||
335 | e->log_prefix, | ||
336 | opt_solver, | ||
337 | cur->pid, | ||
338 | cur->aid, | ||
339 | l->head->timestamp.abs_value_us); | ||
340 | else | ||
341 | GNUNET_asprintf(&filename, "%s%s%s_%s_p%u_a%u.log", | ||
342 | (GNUNET_YES == use_dir) ? output_dir : "", | ||
343 | (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "", | ||
344 | e->log_prefix, | ||
345 | opt_solver, | ||
346 | cur->pid, | ||
347 | cur->aid); | ||
348 | |||
349 | fprintf(stderr, "Add writing log data for peer %llu address %llu to file `%s'\n", | ||
350 | cur->pid, cur->aid, filename); | ||
351 | |||
352 | |||
353 | cur->f_hd = GNUNET_DISK_file_open(filename, | ||
354 | GNUNET_DISK_OPEN_READWRITE | | ||
355 | GNUNET_DISK_OPEN_CREATE | | ||
356 | GNUNET_DISK_OPEN_TRUNCATE, | ||
357 | GNUNET_DISK_PERM_USER_READ | | ||
358 | GNUNET_DISK_PERM_USER_WRITE | | ||
359 | GNUNET_DISK_PERM_GROUP_READ | | ||
360 | GNUNET_DISK_PERM_OTHER_READ); | ||
361 | if (NULL == cur->f_hd) | ||
362 | { | ||
363 | fprintf(stderr, "Cannot open `%s' to write log data!\n", filename); | ||
364 | GNUNET_free(filename); | ||
365 | GNUNET_free(cur); | ||
366 | goto cleanup; | ||
367 | } | ||
368 | GNUNET_free(filename); | ||
369 | GNUNET_CONTAINER_DLL_insert(lf_head, lf_tail, cur); | ||
370 | |||
371 | GNUNET_asprintf(&datastring, "#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \ | ||
372 | "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \ | ||
373 | "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;" \ | ||
374 | "DELAY; DELAY; " \ | ||
375 | "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \ | ||
376 | "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n"); | ||
377 | GNUNET_DISK_file_write(cur->f_hd, datastring, strlen(datastring)); | ||
378 | GNUNET_free(datastring); | ||
379 | } | ||
380 | |||
381 | prefstring = GNUNET_strdup(""); | ||
382 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) | ||
383 | { | ||
384 | /* | ||
385 | fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n", | ||
386 | GNUNET_ATS_print_preference_type(c), | ||
387 | log_p->pref_abs[c], log_p->pref_norm[c]); | ||
388 | */ | ||
389 | GNUNET_asprintf(&prefstring_tmp, "%s;%.3f;%.3f", | ||
390 | prefstring, log_p->pref_abs[c], log_p->pref_norm[c]); | ||
391 | |||
392 | |||
393 | GNUNET_free(prefstring); | ||
394 | prefstring = GNUNET_strdup(prefstring_tmp); | ||
395 | GNUNET_free(prefstring_tmp); | ||
396 | } | ||
397 | |||
398 | |||
399 | propstring = GNUNET_strdup(""); | ||
400 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) | ||
401 | { | ||
402 | if (GNUNET_ATS_NETWORK_TYPE == c) | ||
403 | continue; | ||
404 | /* | ||
405 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", | ||
406 | GNUNET_ATS_print_property_type(c), | ||
407 | log_a->prop_abs[c], log_a->prop_norm[c]);*/ | ||
408 | GNUNET_asprintf(&propstring_tmp, "%s%.3f;%.3f;", | ||
409 | propstring, | ||
410 | log_a->prop_abs[c], | ||
411 | log_a->prop_norm[c]); | ||
412 | GNUNET_free(propstring); | ||
413 | propstring = GNUNET_strdup(propstring_tmp); | ||
414 | GNUNET_free(propstring_tmp); | ||
415 | } | ||
416 | GNUNET_asprintf(&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n", | ||
417 | GNUNET_TIME_absolute_get_difference(l->head->timestamp, | ||
418 | lts->timestamp).rel_value_us / 1000, lts->delta, | ||
419 | log_p->is_requested, log_a->network, log_a->active, | ||
420 | log_a->assigned_bw_in, log_a->assigned_bw_out, propstring, | ||
421 | prefstring); | ||
422 | |||
423 | GNUNET_DISK_file_write(cur->f_hd, datastring, strlen(datastring)); | ||
424 | GNUNET_free(datastring); | ||
425 | GNUNET_free(prefstring); | ||
426 | GNUNET_free(propstring); | ||
427 | } | ||
391 | } | 428 | } |
392 | |||
393 | |||
394 | propstring = GNUNET_strdup(""); | ||
395 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) | ||
396 | { | ||
397 | if (GNUNET_ATS_NETWORK_TYPE == c) | ||
398 | continue; | ||
399 | /* | ||
400 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", | ||
401 | GNUNET_ATS_print_property_type(c), | ||
402 | log_a->prop_abs[c], log_a->prop_norm[c]);*/ | ||
403 | GNUNET_asprintf(&propstring_tmp,"%s%.3f;%.3f;", | ||
404 | propstring, | ||
405 | log_a->prop_abs[c], | ||
406 | log_a->prop_norm[c]); | ||
407 | GNUNET_free (propstring); | ||
408 | propstring = GNUNET_strdup(propstring_tmp); | ||
409 | GNUNET_free (propstring_tmp); | ||
410 | } | ||
411 | GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n", | ||
412 | GNUNET_TIME_absolute_get_difference (l->head->timestamp, | ||
413 | lts->timestamp).rel_value_us / 1000, lts->delta, | ||
414 | log_p->is_requested, log_a->network, log_a->active, | ||
415 | log_a->assigned_bw_in, log_a->assigned_bw_out, propstring, | ||
416 | prefstring); | ||
417 | |||
418 | GNUNET_DISK_file_write (cur->f_hd, datastring, strlen(datastring)); | ||
419 | GNUNET_free (datastring); | ||
420 | GNUNET_free (prefstring); | ||
421 | GNUNET_free (propstring); | ||
422 | } | ||
423 | } | 429 | } |
424 | } | ||
425 | 430 | ||
426 | cleanup: | 431 | cleanup: |
427 | next = lf_head; | 432 | next = lf_head; |
428 | for (cur = next; NULL != cur; cur = next) | 433 | for (cur = next; NULL != cur; cur = next) |
429 | { | 434 | { |
430 | next = cur->next; | 435 | next = cur->next; |
431 | GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur); | 436 | GNUNET_CONTAINER_DLL_remove(lf_head, lf_tail, cur); |
432 | if (NULL != cur->f_hd) | 437 | if (NULL != cur->f_hd) |
433 | GNUNET_DISK_file_close (cur->f_hd); | 438 | GNUNET_DISK_file_close(cur->f_hd); |
434 | GNUNET_free (cur); | 439 | GNUNET_free(cur); |
435 | } | 440 | } |
436 | |||
437 | } | 441 | } |
438 | 442 | ||
439 | void | 443 | void |
440 | GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l) | 444 | GNUNET_ATS_solver_logging_eval(struct LoggingHandle *l) |
441 | { | 445 | { |
442 | struct LoggingTimeStep *lts; | 446 | struct LoggingTimeStep *lts; |
443 | struct LoggingPeer *log_p; | 447 | struct LoggingPeer *log_p; |
@@ -445,43 +449,43 @@ GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l) | |||
445 | int c; | 449 | int c; |
446 | 450 | ||
447 | for (lts = l->head; NULL != lts; lts = lts->next) | 451 | for (lts = l->head; NULL != lts; lts = lts->next) |
448 | { | ||
449 | fprintf (stderr, "Log step %llu %llu: \n", | ||
450 | (long long unsigned int) lts->timestamp.abs_value_us, | ||
451 | (long long unsigned int) lts->delta.rel_value_us); | ||
452 | |||
453 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) | ||
454 | { | 452 | { |
455 | fprintf (stderr,"\tLogging peer pid %llu\n", log_p->id); | 453 | fprintf(stderr, "Log step %llu %llu: \n", |
456 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) | 454 | (long long unsigned int)lts->timestamp.abs_value_us, |
457 | { | 455 | (long long unsigned int)lts->delta.rel_value_us); |
458 | fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n", | ||
459 | GNUNET_ATS_print_preference_type(c), | ||
460 | log_p->pref_abs[c], log_p->pref_norm[c]); | ||
461 | } | ||
462 | |||
463 | for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next) | ||
464 | { | ||
465 | fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n", | ||
466 | log_p->id, log_a->aid, log_a->active, | ||
467 | log_a->assigned_bw_in, | ||
468 | log_a->assigned_bw_out); | ||
469 | 456 | ||
470 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) | 457 | for (log_p = lts->head; NULL != log_p; log_p = log_p->next) |
471 | { | 458 | { |
472 | if (GNUNET_ATS_NETWORK_TYPE == c) | 459 | fprintf(stderr, "\tLogging peer pid %llu\n", log_p->id); |
473 | continue; | 460 | for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) |
474 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", | 461 | { |
475 | GNUNET_ATS_print_property_type(c), | 462 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", |
476 | log_a->prop_abs[c], log_a->prop_norm[c]); | 463 | GNUNET_ATS_print_preference_type(c), |
464 | log_p->pref_abs[c], log_p->pref_norm[c]); | ||
465 | } | ||
466 | |||
467 | for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next) | ||
468 | { | ||
469 | fprintf(stderr, "\tPeer pid %llu address %llu: %u %u %u\n", | ||
470 | log_p->id, log_a->aid, log_a->active, | ||
471 | log_a->assigned_bw_in, | ||
472 | log_a->assigned_bw_out); | ||
473 | |||
474 | for (c = 1; c < GNUNET_ATS_PropertyCount; c++) | ||
475 | { | ||
476 | if (GNUNET_ATS_NETWORK_TYPE == c) | ||
477 | continue; | ||
478 | fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", | ||
479 | GNUNET_ATS_print_property_type(c), | ||
480 | log_a->prop_abs[c], log_a->prop_norm[c]); | ||
481 | } | ||
482 | } | ||
477 | } | 483 | } |
478 | } | ||
479 | } | 484 | } |
480 | } | ||
481 | } | 485 | } |
482 | 486 | ||
483 | void | 487 | void |
484 | GNUNET_ATS_solver_logging_free (struct LoggingHandle *l) | 488 | GNUNET_ATS_solver_logging_free(struct LoggingHandle *l) |
485 | { | 489 | { |
486 | struct LoggingTimeStep *lts_cur; | 490 | struct LoggingTimeStep *lts_cur; |
487 | struct LoggingTimeStep *lts_next; | 491 | struct LoggingTimeStep *lts_next; |
@@ -491,37 +495,37 @@ GNUNET_ATS_solver_logging_free (struct LoggingHandle *l) | |||
491 | struct LoggingAddress *log_a_next; | 495 | struct LoggingAddress *log_a_next; |
492 | 496 | ||
493 | if (NULL != l->logging_task) | 497 | if (NULL != l->logging_task) |
494 | GNUNET_SCHEDULER_cancel (l->logging_task); | 498 | GNUNET_SCHEDULER_cancel(l->logging_task); |
495 | l->logging_task = NULL; | 499 | l->logging_task = NULL; |
496 | 500 | ||
497 | lts_next = l->head; | 501 | lts_next = l->head; |
498 | while (NULL != (lts_cur = lts_next)) | 502 | while (NULL != (lts_cur = lts_next)) |
499 | { | ||
500 | lts_next = lts_cur->next; | ||
501 | |||
502 | log_p_next = lts_cur->head; | ||
503 | while (NULL != (log_p_cur = log_p_next)) | ||
504 | { | 503 | { |
505 | log_p_next = log_p_cur->next; | 504 | lts_next = lts_cur->next; |
506 | 505 | ||
507 | log_a_next = log_p_cur->addr_head; | 506 | log_p_next = lts_cur->head; |
508 | while (NULL != (log_a_cur = log_a_next)) | 507 | while (NULL != (log_p_cur = log_p_next)) |
509 | { | 508 | { |
510 | log_a_next = log_a_cur->next; | 509 | log_p_next = log_p_cur->next; |
511 | 510 | ||
512 | GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur); | 511 | log_a_next = log_p_cur->addr_head; |
513 | GNUNET_free (log_a_cur); | 512 | while (NULL != (log_a_cur = log_a_next)) |
514 | } | 513 | { |
514 | log_a_next = log_a_cur->next; | ||
515 | 515 | ||
516 | GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur); | 516 | GNUNET_CONTAINER_DLL_remove(log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur); |
517 | GNUNET_free (log_p_cur); | 517 | GNUNET_free(log_a_cur); |
518 | } | 518 | } |
519 | 519 | ||
520 | GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur); | 520 | GNUNET_CONTAINER_DLL_remove(lts_cur->head, lts_cur->tail, log_p_cur); |
521 | GNUNET_free (lts_cur); | 521 | GNUNET_free(log_p_cur); |
522 | } | 522 | } |
523 | 523 | ||
524 | GNUNET_free (l); | 524 | GNUNET_CONTAINER_DLL_remove(l->head, l->tail, lts_cur); |
525 | GNUNET_free(lts_cur); | ||
526 | } | ||
527 | |||
528 | GNUNET_free(l); | ||
525 | } | 529 | } |
526 | 530 | ||
527 | /** | 531 | /** |
@@ -532,65 +536,70 @@ static struct PropertyGenerator *prop_gen_tail; | |||
532 | 536 | ||
533 | 537 | ||
534 | static double | 538 | static double |
535 | get_property (struct PropertyGenerator *pg) | 539 | get_property(struct PropertyGenerator *pg) |
536 | { | 540 | { |
537 | struct GNUNET_TIME_Relative time_delta; | 541 | struct GNUNET_TIME_Relative time_delta; |
538 | double delta_value; | 542 | double delta_value; |
539 | double pref_value; | 543 | double pref_value; |
540 | 544 | ||
541 | /* Calculate the current preference value */ | 545 | /* Calculate the current preference value */ |
542 | switch (pg->type) { | 546 | switch (pg->type) |
547 | { | ||
543 | case GNUNET_ATS_TEST_TG_CONSTANT: | 548 | case GNUNET_ATS_TEST_TG_CONSTANT: |
544 | pref_value = pg->base_value; | 549 | pref_value = pg->base_value; |
545 | break; | 550 | break; |
551 | |||
546 | case GNUNET_ATS_TEST_TG_LINEAR: | 552 | case GNUNET_ATS_TEST_TG_LINEAR: |
547 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); | 553 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); |
548 | /* Calculate point of time in the current period */ | 554 | /* Calculate point of time in the current period */ |
549 | time_delta.rel_value_us = time_delta.rel_value_us % | 555 | time_delta.rel_value_us = time_delta.rel_value_us % |
550 | pg->duration_period.rel_value_us; | 556 | pg->duration_period.rel_value_us; |
551 | delta_value = ((double) time_delta.rel_value_us / | 557 | delta_value = ((double)time_delta.rel_value_us / |
552 | pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); | 558 | pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); |
553 | if ((pg->max_value < pg->base_value) && | 559 | if ((pg->max_value < pg->base_value) && |
554 | ((pg->max_value - pg->base_value) > pg->base_value)) | 560 | ((pg->max_value - pg->base_value) > pg->base_value)) |
555 | { | 561 | { |
556 | /* This will cause an underflow */ | 562 | /* This will cause an underflow */ |
557 | GNUNET_break (0); | 563 | GNUNET_break(0); |
558 | } | 564 | } |
559 | pref_value = pg->base_value + delta_value; | 565 | pref_value = pg->base_value + delta_value; |
560 | break; | 566 | break; |
567 | |||
561 | case GNUNET_ATS_TEST_TG_RANDOM: | 568 | case GNUNET_ATS_TEST_TG_RANDOM: |
562 | delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 569 | delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
563 | 10000 * (pg->max_value - pg->base_value)) / 10000; | 570 | 10000 * (pg->max_value - pg->base_value)) / 10000; |
564 | pref_value = pg->base_value + delta_value; | 571 | pref_value = pg->base_value + delta_value; |
565 | break; | 572 | break; |
573 | |||
566 | case GNUNET_ATS_TEST_TG_SINUS: | 574 | case GNUNET_ATS_TEST_TG_SINUS: |
567 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); | 575 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); |
568 | /* Calculate point of time in the current period */ | 576 | /* Calculate point of time in the current period */ |
569 | time_delta.rel_value_us = time_delta.rel_value_us % | 577 | time_delta.rel_value_us = time_delta.rel_value_us % |
570 | pg->duration_period.rel_value_us; | 578 | pg->duration_period.rel_value_us; |
571 | if ((pg->max_value - pg->base_value) > pg->base_value) | 579 | if ((pg->max_value - pg->base_value) > pg->base_value) |
572 | { | 580 | { |
573 | /* This will cause an underflow for second half of sinus period, | 581 | /* This will cause an underflow for second half of sinus period, |
574 | * will be detected in general when experiments are loaded */ | 582 | * will be detected in general when experiments are loaded */ |
575 | GNUNET_break (0); | 583 | GNUNET_break(0); |
576 | } | 584 | } |
577 | delta_value = (pg->max_value - pg->base_value) * | 585 | delta_value = (pg->max_value - pg->base_value) * |
578 | sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) * | 586 | sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) * |
579 | time_delta.rel_value_us); | 587 | time_delta.rel_value_us); |
580 | pref_value = pg->base_value + delta_value; | 588 | pref_value = pg->base_value + delta_value; |
581 | break; | 589 | break; |
590 | |||
582 | default: | 591 | default: |
583 | pref_value = 0.0; | 592 | pref_value = 0.0; |
584 | break; | 593 | break; |
585 | } | 594 | } |
586 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n", | 595 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n", |
587 | pref_value); | 596 | pref_value); |
588 | return pref_value; | 597 | return pref_value; |
589 | } | 598 | } |
590 | 599 | ||
591 | 600 | ||
592 | static void | 601 | static void |
593 | set_prop_task (void *cls) | 602 | set_prop_task(void *cls) |
594 | { | 603 | { |
595 | struct PropertyGenerator *pg = cls; | 604 | struct PropertyGenerator *pg = cls; |
596 | struct TestPeer *p; | 605 | struct TestPeer *p; |
@@ -600,58 +609,58 @@ set_prop_task (void *cls) | |||
600 | 609 | ||
601 | pg->set_task = NULL; | 610 | pg->set_task = NULL; |
602 | 611 | ||
603 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses, | 612 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value(sh->addresses, |
604 | &pg->test_peer->peer_id, pg->test_address->ats_addr)) | 613 | &pg->test_peer->peer_id, pg->test_address->ats_addr)) |
605 | { | 614 | { |
606 | GNUNET_break (0); | 615 | GNUNET_break(0); |
607 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 616 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
608 | "Setting property generation for unknown address [%u:%u]\n", | 617 | "Setting property generation for unknown address [%u:%u]\n", |
609 | pg->peer, pg->address_id); | 618 | pg->peer, pg->address_id); |
610 | return; | 619 | return; |
611 | } | 620 | } |
612 | if (NULL == (p = find_peer_by_id (pg->peer))) | 621 | if (NULL == (p = find_peer_by_id(pg->peer))) |
613 | { | 622 | { |
614 | GNUNET_break (0); | 623 | GNUNET_break(0); |
615 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 624 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
616 | "Setting property generation for unknown peer %u\n", | 625 | "Setting property generation for unknown peer %u\n", |
617 | pg->peer); | 626 | pg->peer); |
618 | return; | 627 | return; |
619 | } | 628 | } |
620 | if (NULL == (a = find_address_by_id (p, pg->address_id))) | 629 | if (NULL == (a = find_address_by_id(p, pg->address_id))) |
621 | { | 630 | { |
622 | GNUNET_break (0); | 631 | GNUNET_break(0); |
623 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 632 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
624 | "Setting property generation for unknown peer %u\n", | 633 | "Setting property generation for unknown peer %u\n", |
625 | pg->peer); | 634 | pg->peer); |
626 | return; | 635 | return; |
627 | } | 636 | } |
628 | 637 | ||
629 | prop_value = get_property (pg); | 638 | prop_value = get_property(pg); |
630 | a->prop_abs[pg->ats_property] = prop_value; | 639 | a->prop_abs[pg->ats_property] = prop_value; |
631 | 640 | ||
632 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 641 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
633 | "Setting property for peer [%u] address [%u] for %s to %f\n", | 642 | "Setting property for peer [%u] address [%u] for %s to %f\n", |
634 | pg->peer, pg->address_id, | 643 | pg->peer, pg->address_id, |
635 | GNUNET_ATS_print_property_type (pg->ats_property), prop_value); | 644 | GNUNET_ATS_print_property_type(pg->ats_property), prop_value); |
636 | 645 | ||
637 | atsi.type = htonl (pg->ats_property); | 646 | atsi.type = htonl(pg->ats_property); |
638 | atsi.value = htonl ((uint32_t) prop_value); | 647 | atsi.value = htonl((uint32_t)prop_value); |
639 | 648 | ||
640 | /* set performance here! */ | 649 | /* set performance here! */ |
641 | sh->sf->s_bulk_start (sh->sf->cls); | 650 | sh->sf->s_bulk_start(sh->sf->cls); |
642 | if (GNUNET_YES == opt_disable_normalization) | 651 | if (GNUNET_YES == opt_disable_normalization) |
643 | { | 652 | { |
644 | a->prop_abs[pg->ats_property] = prop_value; | 653 | a->prop_abs[pg->ats_property] = prop_value; |
645 | a->prop_norm[pg->ats_property] = prop_value; | 654 | a->prop_norm[pg->ats_property] = prop_value; |
646 | sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr, | 655 | sh->sf->s_address_update_property(sh->sf->cls, a->ats_addr, |
647 | pg->ats_property, prop_value, prop_value); | 656 | pg->ats_property, prop_value, prop_value); |
648 | } | 657 | } |
649 | else | 658 | else |
650 | GAS_normalization_update_property (pg->test_address->ats_addr, &atsi, 1); | 659 | GAS_normalization_update_property(pg->test_address->ats_addr, &atsi, 1); |
651 | sh->sf->s_bulk_stop (sh->sf->cls); | 660 | sh->sf->s_bulk_stop(sh->sf->cls); |
652 | 661 | ||
653 | pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, | 662 | pg->set_task = GNUNET_SCHEDULER_add_delayed(pg->frequency, |
654 | &set_prop_task, pg); | 663 | &set_prop_task, pg); |
655 | } | 664 | } |
656 | 665 | ||
657 | 666 | ||
@@ -659,35 +668,36 @@ set_prop_task (void *cls) | |||
659 | * Set ats_property to 0 to find all pgs | 668 | * Set ats_property to 0 to find all pgs |
660 | */ | 669 | */ |
661 | static struct PropertyGenerator * | 670 | static struct PropertyGenerator * |
662 | find_prop_gen (unsigned int peer, unsigned int address, | 671 | find_prop_gen(unsigned int peer, unsigned int address, |
663 | uint32_t ats_property) | 672 | uint32_t ats_property) |
664 | { | 673 | { |
665 | struct PropertyGenerator *cur; | 674 | struct PropertyGenerator *cur; |
675 | |||
666 | for (cur = prop_gen_head; NULL != cur; cur = cur->next) | 676 | for (cur = prop_gen_head; NULL != cur; cur = cur->next) |
667 | if ((cur->peer == peer) && (cur->address_id == address)) | 677 | if ((cur->peer == peer) && (cur->address_id == address)) |
668 | { | 678 | { |
669 | if ((cur->ats_property == ats_property) || (0 == ats_property)) | 679 | if ((cur->ats_property == ats_property) || (0 == ats_property)) |
670 | return cur; | 680 | return cur; |
671 | } | 681 | } |
672 | return NULL; | 682 | return NULL; |
673 | } | 683 | } |
674 | 684 | ||
675 | void | 685 | void |
676 | GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg) | 686 | GNUNET_ATS_solver_generate_property_stop(struct PropertyGenerator *pg) |
677 | { | 687 | { |
678 | GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg); | 688 | GNUNET_CONTAINER_DLL_remove(prop_gen_head, prop_gen_tail, pg); |
679 | 689 | ||
680 | if (NULL != pg->set_task) | 690 | if (NULL != pg->set_task) |
681 | { | 691 | { |
682 | GNUNET_SCHEDULER_cancel (pg->set_task); | 692 | GNUNET_SCHEDULER_cancel(pg->set_task); |
683 | pg->set_task = NULL; | 693 | pg->set_task = NULL; |
684 | } | 694 | } |
685 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 695 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
686 | "Removing old up preference generator peer [%u] address [%u] `%s'\n", | 696 | "Removing old up preference generator peer [%u] address [%u] `%s'\n", |
687 | pg->peer, pg->address_id, | 697 | pg->peer, pg->address_id, |
688 | GNUNET_ATS_print_property_type(pg->ats_property)); | 698 | GNUNET_ATS_print_property_type(pg->ats_property)); |
689 | 699 | ||
690 | GNUNET_free (pg); | 700 | GNUNET_free(pg); |
691 | } | 701 | } |
692 | 702 | ||
693 | 703 | ||
@@ -708,21 +718,21 @@ GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg) | |||
708 | * @return the property generator | 718 | * @return the property generator |
709 | */ | 719 | */ |
710 | struct PropertyGenerator * | 720 | struct PropertyGenerator * |
711 | GNUNET_ATS_solver_generate_property_start (unsigned int peer, | 721 | GNUNET_ATS_solver_generate_property_start(unsigned int peer, |
712 | unsigned int address_id, | 722 | unsigned int address_id, |
713 | struct TestPeer *test_peer, | 723 | struct TestPeer *test_peer, |
714 | struct TestAddress *test_address, | 724 | struct TestAddress *test_address, |
715 | enum GeneratorType type, | 725 | enum GeneratorType type, |
716 | long int base_value, | 726 | long int base_value, |
717 | long int value_rate, | 727 | long int value_rate, |
718 | struct GNUNET_TIME_Relative period, | 728 | struct GNUNET_TIME_Relative period, |
719 | struct GNUNET_TIME_Relative frequency, | 729 | struct GNUNET_TIME_Relative frequency, |
720 | uint32_t ats_property) | 730 | uint32_t ats_property) |
721 | { | 731 | { |
722 | struct PropertyGenerator *pg; | 732 | struct PropertyGenerator *pg; |
723 | 733 | ||
724 | pg = GNUNET_new (struct PropertyGenerator); | 734 | pg = GNUNET_new(struct PropertyGenerator); |
725 | GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg); | 735 | GNUNET_CONTAINER_DLL_insert(prop_gen_head, prop_gen_tail, pg); |
726 | pg->type = type; | 736 | pg->type = type; |
727 | pg->peer = peer; | 737 | pg->peer = peer; |
728 | pg->test_address = test_address; | 738 | pg->test_address = test_address; |
@@ -735,44 +745,49 @@ GNUNET_ATS_solver_generate_property_start (unsigned int peer, | |||
735 | pg->frequency = frequency; | 745 | pg->frequency = frequency; |
736 | pg->time_start = GNUNET_TIME_absolute_get(); | 746 | pg->time_start = GNUNET_TIME_absolute_get(); |
737 | 747 | ||
738 | switch (type) { | 748 | switch (type) |
749 | { | ||
739 | case GNUNET_ATS_TEST_TG_CONSTANT: | 750 | case GNUNET_ATS_TEST_TG_CONSTANT: |
740 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 751 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
741 | "Setting up %s property generator peer [%u] address [%u] `%s'"\ | 752 | "Setting up %s property generator peer [%u] address [%u] `%s'" \ |
742 | "max %u Bips\n", | 753 | "max %u Bips\n", |
743 | print_generator_type(type), pg->peer, pg->address_id, | 754 | print_generator_type(type), pg->peer, pg->address_id, |
744 | GNUNET_ATS_print_property_type (ats_property), | 755 | GNUNET_ATS_print_property_type(ats_property), |
745 | base_value); | 756 | base_value); |
746 | break; | 757 | break; |
758 | |||
747 | case GNUNET_ATS_TEST_TG_LINEAR: | 759 | case GNUNET_ATS_TEST_TG_LINEAR: |
748 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 760 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
749 | "Setting up %s property generator peer [%u] address [%u] `%s' " \ | 761 | "Setting up %s property generator peer [%u] address [%u] `%s' " \ |
750 | "min %u Bips max %u Bips\n", | 762 | "min %u Bips max %u Bips\n", |
751 | print_generator_type(type), pg->peer, pg->address_id, | 763 | print_generator_type(type), pg->peer, pg->address_id, |
752 | GNUNET_ATS_print_property_type(ats_property), | 764 | GNUNET_ATS_print_property_type(ats_property), |
753 | base_value, value_rate); | 765 | base_value, value_rate); |
754 | break; | 766 | break; |
767 | |||
755 | case GNUNET_ATS_TEST_TG_SINUS: | 768 | case GNUNET_ATS_TEST_TG_SINUS: |
756 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 769 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
757 | "Setting up %s property generator peer [%u] address [%u] `%s' "\ | 770 | "Setting up %s property generator peer [%u] address [%u] `%s' " \ |
758 | "baserate %u Bips, amplitude %u Bps\n", | 771 | "baserate %u Bips, amplitude %u Bps\n", |
759 | print_generator_type(type), pg->peer, pg->address_id, | 772 | print_generator_type(type), pg->peer, pg->address_id, |
760 | GNUNET_ATS_print_property_type(ats_property), | 773 | GNUNET_ATS_print_property_type(ats_property), |
761 | base_value, value_rate); | 774 | base_value, value_rate); |
762 | break; | 775 | break; |
776 | |||
763 | case GNUNET_ATS_TEST_TG_RANDOM: | 777 | case GNUNET_ATS_TEST_TG_RANDOM: |
764 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 778 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
765 | "Setting up %s property generator peer [%u] address [%u] `%s' "\ | 779 | "Setting up %s property generator peer [%u] address [%u] `%s' " \ |
766 | "min %u Bips max %u Bps\n", | 780 | "min %u Bips max %u Bps\n", |
767 | print_generator_type(type), pg->peer, pg->address_id, | 781 | print_generator_type(type), pg->peer, pg->address_id, |
768 | GNUNET_ATS_print_property_type(ats_property), | 782 | GNUNET_ATS_print_property_type(ats_property), |
769 | base_value, value_rate); | 783 | base_value, value_rate); |
770 | break; | 784 | break; |
785 | |||
771 | default: | 786 | default: |
772 | break; | 787 | break; |
773 | } | 788 | } |
774 | 789 | ||
775 | pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg); | 790 | pg->set_task = GNUNET_SCHEDULER_add_now(&set_prop_task, pg); |
776 | return pg; | 791 | return pg; |
777 | } | 792 | } |
778 | 793 | ||
@@ -781,16 +796,17 @@ GNUNET_ATS_solver_generate_property_start (unsigned int peer, | |||
781 | * Stop all preferences generators | 796 | * Stop all preferences generators |
782 | */ | 797 | */ |
783 | void | 798 | void |
784 | GNUNET_ATS_solver_generate_property_stop_all () | 799 | GNUNET_ATS_solver_generate_property_stop_all() |
785 | { | 800 | { |
786 | struct PropertyGenerator *cur; | 801 | struct PropertyGenerator *cur; |
787 | struct PropertyGenerator *next; | 802 | struct PropertyGenerator *next; |
803 | |||
788 | next = prop_gen_head; | 804 | next = prop_gen_head; |
789 | for (cur = next; NULL != cur; cur = next) | 805 | for (cur = next; NULL != cur; cur = next) |
790 | { | 806 | { |
791 | next = cur->next; | 807 | next = cur->next; |
792 | GNUNET_ATS_solver_generate_property_stop (cur); | 808 | GNUNET_ATS_solver_generate_property_stop(cur); |
793 | } | 809 | } |
794 | } | 810 | } |
795 | 811 | ||
796 | 812 | ||
@@ -802,65 +818,70 @@ static struct PreferenceGenerator *pref_gen_tail; | |||
802 | 818 | ||
803 | 819 | ||
804 | static double | 820 | static double |
805 | get_preference (struct PreferenceGenerator *pg) | 821 | get_preference(struct PreferenceGenerator *pg) |
806 | { | 822 | { |
807 | struct GNUNET_TIME_Relative time_delta; | 823 | struct GNUNET_TIME_Relative time_delta; |
808 | double delta_value; | 824 | double delta_value; |
809 | double pref_value; | 825 | double pref_value; |
810 | 826 | ||
811 | /* Calculate the current preference value */ | 827 | /* Calculate the current preference value */ |
812 | switch (pg->type) { | 828 | switch (pg->type) |
829 | { | ||
813 | case GNUNET_ATS_TEST_TG_CONSTANT: | 830 | case GNUNET_ATS_TEST_TG_CONSTANT: |
814 | pref_value = pg->base_value; | 831 | pref_value = pg->base_value; |
815 | break; | 832 | break; |
833 | |||
816 | case GNUNET_ATS_TEST_TG_LINEAR: | 834 | case GNUNET_ATS_TEST_TG_LINEAR: |
817 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); | 835 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); |
818 | /* Calculate point of time in the current period */ | 836 | /* Calculate point of time in the current period */ |
819 | time_delta.rel_value_us = time_delta.rel_value_us % | 837 | time_delta.rel_value_us = time_delta.rel_value_us % |
820 | pg->duration_period.rel_value_us; | 838 | pg->duration_period.rel_value_us; |
821 | delta_value = ((double) time_delta.rel_value_us / | 839 | delta_value = ((double)time_delta.rel_value_us / |
822 | pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); | 840 | pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); |
823 | if ((pg->max_value < pg->base_value) && | 841 | if ((pg->max_value < pg->base_value) && |
824 | ((pg->max_value - pg->base_value) > pg->base_value)) | 842 | ((pg->max_value - pg->base_value) > pg->base_value)) |
825 | { | 843 | { |
826 | /* This will cause an underflow */ | 844 | /* This will cause an underflow */ |
827 | GNUNET_break (0); | 845 | GNUNET_break(0); |
828 | } | 846 | } |
829 | pref_value = pg->base_value + delta_value; | 847 | pref_value = pg->base_value + delta_value; |
830 | break; | 848 | break; |
849 | |||
831 | case GNUNET_ATS_TEST_TG_RANDOM: | 850 | case GNUNET_ATS_TEST_TG_RANDOM: |
832 | delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 851 | delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
833 | 10000 * (pg->max_value - pg->base_value)) / 10000; | 852 | 10000 * (pg->max_value - pg->base_value)) / 10000; |
834 | pref_value = pg->base_value + delta_value; | 853 | pref_value = pg->base_value + delta_value; |
835 | break; | 854 | break; |
855 | |||
836 | case GNUNET_ATS_TEST_TG_SINUS: | 856 | case GNUNET_ATS_TEST_TG_SINUS: |
837 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); | 857 | time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); |
838 | /* Calculate point of time in the current period */ | 858 | /* Calculate point of time in the current period */ |
839 | time_delta.rel_value_us = time_delta.rel_value_us % | 859 | time_delta.rel_value_us = time_delta.rel_value_us % |
840 | pg->duration_period.rel_value_us; | 860 | pg->duration_period.rel_value_us; |
841 | if ((pg->max_value - pg->base_value) > pg->base_value) | 861 | if ((pg->max_value - pg->base_value) > pg->base_value) |
842 | { | 862 | { |
843 | /* This will cause an underflow for second half of sinus period, | 863 | /* This will cause an underflow for second half of sinus period, |
844 | * will be detected in general when experiments are loaded */ | 864 | * will be detected in general when experiments are loaded */ |
845 | GNUNET_break (0); | 865 | GNUNET_break(0); |
846 | } | 866 | } |
847 | delta_value = (pg->max_value - pg->base_value) * | 867 | delta_value = (pg->max_value - pg->base_value) * |
848 | sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) * | 868 | sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) * |
849 | time_delta.rel_value_us); | 869 | time_delta.rel_value_us); |
850 | pref_value = pg->base_value + delta_value; | 870 | pref_value = pg->base_value + delta_value; |
851 | break; | 871 | break; |
872 | |||
852 | default: | 873 | default: |
853 | pref_value = 0.0; | 874 | pref_value = 0.0; |
854 | break; | 875 | break; |
855 | } | 876 | } |
856 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", | 877 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", |
857 | pref_value); | 878 | pref_value); |
858 | return pref_value; | 879 | return pref_value; |
859 | } | 880 | } |
860 | 881 | ||
861 | 882 | ||
862 | static void | 883 | static void |
863 | set_feedback_task (void *cls) | 884 | set_feedback_task(void *cls) |
864 | { | 885 | { |
865 | struct PreferenceGenerator *pg = cls; | 886 | struct PreferenceGenerator *pg = cls; |
866 | struct TestPeer *p; | 887 | struct TestPeer *p; |
@@ -873,50 +894,52 @@ set_feedback_task (void *cls) | |||
873 | 894 | ||
874 | pg->feedback_task = NULL; | 895 | pg->feedback_task = NULL; |
875 | 896 | ||
876 | if (NULL == (p = find_peer_by_id (pg->peer))) | 897 | if (NULL == (p = find_peer_by_id(pg->peer))) |
877 | { | 898 | { |
878 | GNUNET_break (0); | 899 | GNUNET_break(0); |
879 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 900 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
880 | "Setting feedback for unknown peer %u\n", pg->peer); | 901 | "Setting feedback for unknown peer %u\n", pg->peer); |
881 | return; | 902 | return; |
882 | } | 903 | } |
883 | 904 | ||
884 | switch (pg->kind) | 905 | switch (pg->kind) |
885 | { | 906 | { |
886 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 907 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
887 | dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); | 908 | dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); |
888 | bw_acc_in = dur.rel_value_us *pg->last_assigned_bw_in + pg->feedback_bw_in_acc; | 909 | bw_acc_in = dur.rel_value_us * pg->last_assigned_bw_in + pg->feedback_bw_in_acc; |
889 | pg->feedback_bw_in_acc = 0; | 910 | pg->feedback_bw_in_acc = 0; |
890 | 911 | ||
891 | bw_acc_out = dur.rel_value_us *pg->last_assigned_bw_out + pg->feedback_bw_out_acc; | 912 | bw_acc_out = dur.rel_value_us * pg->last_assigned_bw_out + pg->feedback_bw_out_acc; |
892 | p_new = get_preference (pg); | 913 | p_new = get_preference(pg); |
893 | feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) / | 914 | feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) / |
894 | (2 *GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); | 915 | (2 * GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); |
895 | 916 | ||
896 | break; | 917 | break; |
918 | |||
897 | case GNUNET_ATS_PREFERENCE_LATENCY: | 919 | case GNUNET_ATS_PREFERENCE_LATENCY: |
898 | dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update); | 920 | dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update); |
899 | delay_acc_in =dur.rel_value_us *pg->last_delay_value + pg->feedback_delay_acc; | 921 | delay_acc_in = dur.rel_value_us * pg->last_delay_value + pg->feedback_delay_acc; |
900 | pg->feedback_delay_acc = 0; | 922 | pg->feedback_delay_acc = 0; |
901 | 923 | ||
902 | p_new = get_preference (pg); | 924 | p_new = get_preference(pg); |
903 | feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) / | 925 | feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) / |
904 | (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); | 926 | (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); |
905 | 927 | ||
906 | break; | 928 | break; |
929 | |||
907 | default: | 930 | default: |
908 | GNUNET_break (0); | 931 | GNUNET_break(0); |
909 | feedback = 0.0; | 932 | feedback = 0.0; |
910 | break; | 933 | break; |
911 | } | 934 | } |
912 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 935 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
913 | "Giving feedback for peer [%u] for client %p pref %s of %.3f\n", | 936 | "Giving feedback for peer [%u] for client %p pref %s of %.3f\n", |
914 | pg->peer, NULL + (pg->client_id), | 937 | pg->peer, NULL + (pg->client_id), |
915 | GNUNET_ATS_print_preference_type (pg->kind), | 938 | GNUNET_ATS_print_preference_type(pg->kind), |
916 | feedback); | 939 | feedback); |
917 | 940 | ||
918 | sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id, | 941 | sh->sf->s_feedback(sh->sf->cls, NULL + (pg->client_id), &p->peer_id, |
919 | pg->feedback_frequency, pg->kind, feedback); | 942 | pg->feedback_frequency, pg->kind, feedback); |
920 | pg->feedback_last = GNUNET_TIME_absolute_get(); | 943 | pg->feedback_last = GNUNET_TIME_absolute_get(); |
921 | 944 | ||
922 | 945 | ||
@@ -928,105 +951,111 @@ set_feedback_task (void *cls) | |||
928 | pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); | 951 | pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); |
929 | 952 | ||
930 | 953 | ||
931 | pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency, | 954 | pg->feedback_task = GNUNET_SCHEDULER_add_delayed(pg->feedback_frequency, |
932 | &set_feedback_task, pg); | 955 | &set_feedback_task, pg); |
933 | } | 956 | } |
934 | 957 | ||
935 | 958 | ||
936 | static void | 959 | static void |
937 | set_pref_task (void *cls) | 960 | set_pref_task(void *cls) |
938 | { | 961 | { |
939 | struct PreferenceGenerator *pg = cls; | 962 | struct PreferenceGenerator *pg = cls; |
940 | struct TestPeer *p; | 963 | struct TestPeer *p; |
941 | double pref_value; | 964 | double pref_value; |
965 | |||
942 | pg->set_task = NULL; | 966 | pg->set_task = NULL; |
943 | 967 | ||
944 | if (NULL == (p = find_peer_by_id (pg->peer))) | 968 | if (NULL == (p = find_peer_by_id(pg->peer))) |
945 | { | 969 | { |
946 | GNUNET_break (0); | 970 | GNUNET_break(0); |
947 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 971 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
948 | "Setting preference for unknown peer %u\n", pg->peer); | 972 | "Setting preference for unknown peer %u\n", pg->peer); |
949 | return; | 973 | return; |
950 | } | 974 | } |
951 | 975 | ||
952 | pref_value = get_preference (pg); | 976 | pref_value = get_preference(pg); |
953 | switch (pg->kind) { | 977 | switch (pg->kind) |
978 | { | ||
954 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 979 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
955 | pg->pref_bw_old = pref_value; | 980 | pg->pref_bw_old = pref_value; |
956 | break; | 981 | break; |
982 | |||
957 | case GNUNET_ATS_PREFERENCE_LATENCY: | 983 | case GNUNET_ATS_PREFERENCE_LATENCY: |
958 | pg->pref_latency_old = pref_value; | 984 | pg->pref_latency_old = pref_value; |
959 | break; | 985 | break; |
986 | |||
960 | default: | 987 | default: |
961 | break; | 988 | break; |
962 | } | 989 | } |
963 | 990 | ||
964 | p->pref_abs[pg->kind] = pref_value; | 991 | p->pref_abs[pg->kind] = pref_value; |
965 | 992 | ||
966 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 993 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
967 | "Setting preference for peer [%u] for client %p pref %s to %f\n", | 994 | "Setting preference for peer [%u] for client %p pref %s to %f\n", |
968 | pg->peer, NULL + (pg->client_id), | 995 | pg->peer, NULL + (pg->client_id), |
969 | GNUNET_ATS_print_preference_type (pg->kind), pref_value); | 996 | GNUNET_ATS_print_preference_type(pg->kind), pref_value); |
970 | 997 | ||
971 | if (GNUNET_YES == opt_disable_normalization) | 998 | if (GNUNET_YES == opt_disable_normalization) |
972 | { | 999 | { |
973 | p->pref_abs[pg->kind] = pref_value; | 1000 | p->pref_abs[pg->kind] = pref_value; |
974 | p->pref_norm[pg->kind] = pref_value; | 1001 | p->pref_norm[pg->kind] = pref_value; |
975 | sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value); | 1002 | sh->sf->s_pref(sh->sf->cls, &p->peer_id, pg->kind, pref_value); |
976 | } | 1003 | } |
977 | else | 1004 | else |
978 | update_preference (NULL + (pg->client_id), | 1005 | update_preference(NULL + (pg->client_id), |
979 | &p->peer_id, | 1006 | &p->peer_id, |
980 | pg->kind, | 1007 | pg->kind, |
981 | pref_value); | 1008 | pref_value); |
982 | 1009 | ||
983 | pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, | 1010 | pg->set_task = GNUNET_SCHEDULER_add_delayed(pg->frequency, |
984 | &set_pref_task, | 1011 | &set_pref_task, |
985 | pg); | 1012 | pg); |
986 | } | 1013 | } |
987 | 1014 | ||
988 | 1015 | ||
989 | static struct PreferenceGenerator * | 1016 | static struct PreferenceGenerator * |
990 | find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind) | 1017 | find_pref_gen(unsigned int peer, enum GNUNET_ATS_PreferenceKind kind) |
991 | { | 1018 | { |
992 | struct PreferenceGenerator *cur; | 1019 | struct PreferenceGenerator *cur; |
1020 | |||
993 | for (cur = pref_gen_head; NULL != cur; cur = cur->next) | 1021 | for (cur = pref_gen_head; NULL != cur; cur = cur->next) |
994 | if (cur->peer == peer) | 1022 | if (cur->peer == peer) |
995 | { | 1023 | { |
996 | if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind)) | 1024 | if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind)) |
997 | return cur; | 1025 | return cur; |
998 | } | 1026 | } |
999 | return NULL; | 1027 | return NULL; |
1000 | } | 1028 | } |
1001 | 1029 | ||
1002 | void | 1030 | void |
1003 | GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg) | 1031 | GNUNET_ATS_solver_generate_preferences_stop(struct PreferenceGenerator *pg) |
1004 | { | 1032 | { |
1005 | GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg); | 1033 | GNUNET_CONTAINER_DLL_remove(pref_gen_head, pref_gen_tail, pg); |
1006 | 1034 | ||
1007 | if (NULL != pg->feedback_task) | 1035 | if (NULL != pg->feedback_task) |
1008 | { | 1036 | { |
1009 | GNUNET_SCHEDULER_cancel (pg->feedback_task); | 1037 | GNUNET_SCHEDULER_cancel(pg->feedback_task); |
1010 | pg->feedback_task = NULL; | 1038 | pg->feedback_task = NULL; |
1011 | } | 1039 | } |
1012 | 1040 | ||
1013 | if (NULL != pg->set_task) | 1041 | if (NULL != pg->set_task) |
1014 | { | 1042 | { |
1015 | GNUNET_SCHEDULER_cancel (pg->set_task); | 1043 | GNUNET_SCHEDULER_cancel(pg->set_task); |
1016 | pg->set_task = NULL; | 1044 | pg->set_task = NULL; |
1017 | } | 1045 | } |
1018 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1046 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1019 | "Removing old up preference generator peer [%u] `%s'\n", | 1047 | "Removing old up preference generator peer [%u] `%s'\n", |
1020 | pg->peer, GNUNET_ATS_print_preference_type(pg->kind)); | 1048 | pg->peer, GNUNET_ATS_print_preference_type(pg->kind)); |
1021 | 1049 | ||
1022 | GNUNET_free (pg); | 1050 | GNUNET_free(pg); |
1023 | } | 1051 | } |
1024 | 1052 | ||
1025 | 1053 | ||
1026 | static struct TestAddress* | 1054 | static struct TestAddress* |
1027 | find_active_address (struct TestPeer *p) | 1055 | find_active_address(struct TestPeer *p) |
1028 | { | 1056 | { |
1029 | struct TestAddress *cur; | 1057 | struct TestAddress *cur; |
1058 | |||
1030 | for (cur = p->addr_head; NULL != cur; cur = cur->next) | 1059 | for (cur = p->addr_head; NULL != cur; cur = cur->next) |
1031 | if (GNUNET_YES == cur->ats_addr->active) | 1060 | if (GNUNET_YES == cur->ats_addr->active) |
1032 | return cur; | 1061 | return cur; |
@@ -1051,30 +1080,30 @@ find_active_address (struct TestPeer *p) | |||
1051 | * @return the preference generator | 1080 | * @return the preference generator |
1052 | */ | 1081 | */ |
1053 | struct PreferenceGenerator * | 1082 | struct PreferenceGenerator * |
1054 | GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | 1083 | GNUNET_ATS_solver_generate_preferences_start(unsigned int peer, |
1055 | unsigned int address_id, | 1084 | unsigned int address_id, |
1056 | unsigned int client_id, | 1085 | unsigned int client_id, |
1057 | enum GeneratorType type, | 1086 | enum GeneratorType type, |
1058 | long int base_value, | 1087 | long int base_value, |
1059 | long int value_rate, | 1088 | long int value_rate, |
1060 | struct GNUNET_TIME_Relative period, | 1089 | struct GNUNET_TIME_Relative period, |
1061 | struct GNUNET_TIME_Relative frequency, | 1090 | struct GNUNET_TIME_Relative frequency, |
1062 | enum GNUNET_ATS_PreferenceKind kind, | 1091 | enum GNUNET_ATS_PreferenceKind kind, |
1063 | struct GNUNET_TIME_Relative feedback_frequency) | 1092 | struct GNUNET_TIME_Relative feedback_frequency) |
1064 | { | 1093 | { |
1065 | struct PreferenceGenerator *pg; | 1094 | struct PreferenceGenerator *pg; |
1066 | struct TestPeer *p; | 1095 | struct TestPeer *p; |
1067 | 1096 | ||
1068 | if (NULL == (p = find_peer_by_id (peer))) | 1097 | if (NULL == (p = find_peer_by_id(peer))) |
1069 | { | 1098 | { |
1070 | GNUNET_break (0); | 1099 | GNUNET_break(0); |
1071 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1100 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1072 | "Starting preference for unknown peer %u\n", peer); | 1101 | "Starting preference for unknown peer %u\n", peer); |
1073 | return NULL; | 1102 | return NULL; |
1074 | } | 1103 | } |
1075 | 1104 | ||
1076 | pg = GNUNET_new (struct PreferenceGenerator); | 1105 | pg = GNUNET_new(struct PreferenceGenerator); |
1077 | GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg); | 1106 | GNUNET_CONTAINER_DLL_insert(pref_gen_head, pref_gen_tail, pg); |
1078 | pg->type = type; | 1107 | pg->type = type; |
1079 | pg->peer = peer; | 1108 | pg->peer = peer; |
1080 | pg->client_id = client_id; | 1109 | pg->client_id = client_id; |
@@ -1086,54 +1115,59 @@ GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | |||
1086 | pg->time_start = GNUNET_TIME_absolute_get(); | 1115 | pg->time_start = GNUNET_TIME_absolute_get(); |
1087 | pg->feedback_frequency = feedback_frequency; | 1116 | pg->feedback_frequency = feedback_frequency; |
1088 | 1117 | ||
1089 | switch (type) { | 1118 | switch (type) |
1119 | { | ||
1090 | case GNUNET_ATS_TEST_TG_CONSTANT: | 1120 | case GNUNET_ATS_TEST_TG_CONSTANT: |
1091 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1121 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1092 | "Setting up %s preference generator peer [%u] `%s' max %u Bips\n", | 1122 | "Setting up %s preference generator peer [%u] `%s' max %u Bips\n", |
1093 | print_generator_type (type), pg->peer, | 1123 | print_generator_type(type), pg->peer, |
1094 | GNUNET_ATS_print_preference_type(kind), | 1124 | GNUNET_ATS_print_preference_type(kind), |
1095 | base_value); | 1125 | base_value); |
1096 | break; | 1126 | break; |
1127 | |||
1097 | case GNUNET_ATS_TEST_TG_LINEAR: | 1128 | case GNUNET_ATS_TEST_TG_LINEAR: |
1098 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1129 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1099 | "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n", | 1130 | "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n", |
1100 | print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind), | 1131 | print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), |
1101 | base_value, value_rate); | 1132 | base_value, value_rate); |
1102 | break; | 1133 | break; |
1134 | |||
1103 | case GNUNET_ATS_TEST_TG_SINUS: | 1135 | case GNUNET_ATS_TEST_TG_SINUS: |
1104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1136 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1105 | "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n", | 1137 | "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n", |
1106 | print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind), | 1138 | print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), |
1107 | base_value, value_rate); | 1139 | base_value, value_rate); |
1108 | break; | 1140 | break; |
1141 | |||
1109 | case GNUNET_ATS_TEST_TG_RANDOM: | 1142 | case GNUNET_ATS_TEST_TG_RANDOM: |
1110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1143 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1111 | "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n", | 1144 | "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n", |
1112 | print_generator_type (type), pg->peer, GNUNET_ATS_print_preference_type(kind), | 1145 | print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), |
1113 | base_value, value_rate); | 1146 | base_value, value_rate); |
1114 | break; | 1147 | break; |
1148 | |||
1115 | default: | 1149 | default: |
1116 | break; | 1150 | break; |
1117 | } | 1151 | } |
1118 | 1152 | ||
1119 | pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg); | 1153 | pg->set_task = GNUNET_SCHEDULER_add_now(&set_pref_task, pg); |
1120 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) | 1154 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) |
1121 | { | 1155 | { |
1122 | struct TestAddress * addr = find_active_address(p); | 1156 | struct TestAddress * addr = find_active_address(p); |
1123 | 1157 | ||
1124 | pg->last_assigned_bw_in = p->assigned_bw_in; | 1158 | pg->last_assigned_bw_in = p->assigned_bw_in; |
1125 | pg->last_assigned_bw_out = p->assigned_bw_out; | 1159 | pg->last_assigned_bw_out = p->assigned_bw_out; |
1126 | pg->feedback_bw_in_acc = 0; | 1160 | pg->feedback_bw_in_acc = 0; |
1127 | pg->feedback_bw_out_acc = 0; | 1161 | pg->feedback_bw_out_acc = 0; |
1128 | pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY]; | 1162 | pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY]; |
1129 | pg->feedback_delay_acc = 0; | 1163 | pg->feedback_delay_acc = 0; |
1130 | 1164 | ||
1131 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); | 1165 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); |
1132 | pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); | 1166 | pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); |
1133 | pg->feedback_last = GNUNET_TIME_absolute_get(); | 1167 | pg->feedback_last = GNUNET_TIME_absolute_get(); |
1134 | pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency, | 1168 | pg->feedback_task = GNUNET_SCHEDULER_add_delayed(feedback_frequency, |
1135 | &set_feedback_task, pg); | 1169 | &set_feedback_task, pg); |
1136 | } | 1170 | } |
1137 | 1171 | ||
1138 | return pg; | 1172 | return pg; |
1139 | } | 1173 | } |
@@ -1144,16 +1178,17 @@ GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | |||
1144 | * Stop all preferences generators | 1178 | * Stop all preferences generators |
1145 | */ | 1179 | */ |
1146 | void | 1180 | void |
1147 | GNUNET_ATS_solver_generate_preferences_stop_all () | 1181 | GNUNET_ATS_solver_generate_preferences_stop_all() |
1148 | { | 1182 | { |
1149 | struct PreferenceGenerator *cur; | 1183 | struct PreferenceGenerator *cur; |
1150 | struct PreferenceGenerator *next; | 1184 | struct PreferenceGenerator *next; |
1185 | |||
1151 | next = pref_gen_head; | 1186 | next = pref_gen_head; |
1152 | for (cur = next; NULL != cur; cur = next) | 1187 | for (cur = next; NULL != cur; cur = next) |
1153 | { | 1188 | { |
1154 | next = cur->next; | 1189 | next = cur->next; |
1155 | GNUNET_ATS_solver_generate_preferences_stop(cur); | 1190 | GNUNET_ATS_solver_generate_preferences_stop(cur); |
1156 | } | 1191 | } |
1157 | } | 1192 | } |
1158 | 1193 | ||
1159 | 1194 | ||
@@ -1162,37 +1197,47 @@ GNUNET_ATS_solver_generate_preferences_stop_all () | |||
1162 | * Experiments | 1197 | * Experiments |
1163 | */ | 1198 | */ |
1164 | static const char * | 1199 | static const char * |
1165 | print_op (enum OperationType op) | 1200 | print_op(enum OperationType op) |
1166 | { | 1201 | { |
1167 | switch (op) { | 1202 | switch (op) |
1203 | { | ||
1168 | case SOLVER_OP_ADD_ADDRESS: | 1204 | case SOLVER_OP_ADD_ADDRESS: |
1169 | return "ADD_ADDRESS"; | 1205 | return "ADD_ADDRESS"; |
1206 | |||
1170 | case SOLVER_OP_DEL_ADDRESS: | 1207 | case SOLVER_OP_DEL_ADDRESS: |
1171 | return "DEL_ADDRESS"; | 1208 | return "DEL_ADDRESS"; |
1209 | |||
1172 | case SOLVER_OP_START_SET_PREFERENCE: | 1210 | case SOLVER_OP_START_SET_PREFERENCE: |
1173 | return "START_SET_PREFERENCE"; | 1211 | return "START_SET_PREFERENCE"; |
1212 | |||
1174 | case SOLVER_OP_STOP_SET_PREFERENCE: | 1213 | case SOLVER_OP_STOP_SET_PREFERENCE: |
1175 | return "STOP_STOP_PREFERENCE"; | 1214 | return "STOP_STOP_PREFERENCE"; |
1215 | |||
1176 | case SOLVER_OP_START_SET_PROPERTY: | 1216 | case SOLVER_OP_START_SET_PROPERTY: |
1177 | return "START_SET_PROPERTY"; | 1217 | return "START_SET_PROPERTY"; |
1218 | |||
1178 | case SOLVER_OP_STOP_SET_PROPERTY: | 1219 | case SOLVER_OP_STOP_SET_PROPERTY: |
1179 | return "STOP_SET_PROPERTY"; | 1220 | return "STOP_SET_PROPERTY"; |
1221 | |||
1180 | case SOLVER_OP_START_REQUEST: | 1222 | case SOLVER_OP_START_REQUEST: |
1181 | return "START_REQUEST"; | 1223 | return "START_REQUEST"; |
1224 | |||
1182 | case SOLVER_OP_STOP_REQUEST: | 1225 | case SOLVER_OP_STOP_REQUEST: |
1183 | return "STOP_REQUEST"; | 1226 | return "STOP_REQUEST"; |
1227 | |||
1184 | default: | 1228 | default: |
1185 | break; | 1229 | break; |
1186 | } | 1230 | } |
1187 | return ""; | 1231 | return ""; |
1188 | } | 1232 | } |
1189 | 1233 | ||
1190 | 1234 | ||
1191 | static struct Experiment * | 1235 | static struct Experiment * |
1192 | create_experiment () | 1236 | create_experiment() |
1193 | { | 1237 | { |
1194 | struct Experiment *e; | 1238 | struct Experiment *e; |
1195 | e = GNUNET_new (struct Experiment); | 1239 | |
1240 | e = GNUNET_new(struct Experiment); | ||
1196 | e->name = NULL; | 1241 | e->name = NULL; |
1197 | e->start = NULL; | 1242 | e->start = NULL; |
1198 | e->total_duration = GNUNET_TIME_UNIT_ZERO; | 1243 | e->total_duration = GNUNET_TIME_UNIT_ZERO; |
@@ -1201,7 +1246,7 @@ create_experiment () | |||
1201 | 1246 | ||
1202 | 1247 | ||
1203 | static void | 1248 | static void |
1204 | free_experiment (struct Experiment *e) | 1249 | free_experiment(struct Experiment *e) |
1205 | { | 1250 | { |
1206 | struct Episode *cur; | 1251 | struct Episode *cur; |
1207 | struct Episode *next; | 1252 | struct Episode *next; |
@@ -1210,237 +1255,238 @@ free_experiment (struct Experiment *e) | |||
1210 | 1255 | ||
1211 | next = e->start; | 1256 | next = e->start; |
1212 | for (cur = next; NULL != cur; cur = next) | 1257 | for (cur = next; NULL != cur; cur = next) |
1213 | { | ||
1214 | next = cur->next; | ||
1215 | |||
1216 | next_o = cur->head; | ||
1217 | for (cur_o = next_o; NULL != cur_o; cur_o = next_o) | ||
1218 | { | 1258 | { |
1219 | next_o = cur_o->next; | 1259 | next = cur->next; |
1220 | GNUNET_free_non_null (cur_o->address); | 1260 | |
1221 | GNUNET_free_non_null (cur_o->plugin); | 1261 | next_o = cur->head; |
1222 | GNUNET_free (cur_o); | 1262 | for (cur_o = next_o; NULL != cur_o; cur_o = next_o) |
1263 | { | ||
1264 | next_o = cur_o->next; | ||
1265 | GNUNET_free_non_null(cur_o->address); | ||
1266 | GNUNET_free_non_null(cur_o->plugin); | ||
1267 | GNUNET_free(cur_o); | ||
1268 | } | ||
1269 | GNUNET_free(cur); | ||
1223 | } | 1270 | } |
1224 | GNUNET_free (cur); | ||
1225 | } | ||
1226 | 1271 | ||
1227 | GNUNET_free_non_null (e->name); | 1272 | GNUNET_free_non_null(e->name); |
1228 | GNUNET_free_non_null (e->log_prefix); | 1273 | GNUNET_free_non_null(e->log_prefix); |
1229 | GNUNET_free_non_null (e->log_output_dir); | 1274 | GNUNET_free_non_null(e->log_output_dir); |
1230 | GNUNET_free_non_null (e->cfg_file); | 1275 | GNUNET_free_non_null(e->cfg_file); |
1231 | GNUNET_free (e); | 1276 | GNUNET_free(e); |
1232 | } | 1277 | } |
1233 | 1278 | ||
1234 | 1279 | ||
1235 | static int | 1280 | static int |
1236 | load_op_add_address (struct GNUNET_ATS_TEST_Operation *o, | 1281 | load_op_add_address(struct GNUNET_ATS_TEST_Operation *o, |
1237 | struct Episode *e, | 1282 | struct Episode *e, |
1238 | int op_counter, | 1283 | int op_counter, |
1239 | char *sec_name, | 1284 | char *sec_name, |
1240 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1285 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1241 | { | 1286 | { |
1242 | char *op_name; | 1287 | char *op_name; |
1243 | char *op_network; | 1288 | char *op_network; |
1244 | 1289 | ||
1245 | /* peer pid */ | 1290 | /* peer pid */ |
1246 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1291 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1247 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1292 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1248 | sec_name, op_name, &o->peer_id)) | 1293 | sec_name, op_name, &o->peer_id)) |
1249 | { | 1294 | { |
1250 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1295 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1251 | op_counter, "ADD_ADDRESS", op_name); | 1296 | op_counter, "ADD_ADDRESS", op_name); |
1252 | GNUNET_free (op_name); | 1297 | GNUNET_free(op_name); |
1253 | return GNUNET_SYSERR; | 1298 | return GNUNET_SYSERR; |
1254 | } | 1299 | } |
1255 | GNUNET_free (op_name); | 1300 | GNUNET_free(op_name); |
1256 | 1301 | ||
1257 | /* address pid */ | 1302 | /* address pid */ |
1258 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); | 1303 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); |
1259 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1304 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1260 | sec_name, op_name, &o->address_id)) | 1305 | sec_name, op_name, &o->address_id)) |
1261 | { | 1306 | { |
1262 | fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", | 1307 | fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", |
1263 | op_counter, "ADD_ADDRESS", op_name); | 1308 | op_counter, "ADD_ADDRESS", op_name); |
1264 | GNUNET_free (op_name); | 1309 | GNUNET_free(op_name); |
1265 | return GNUNET_SYSERR; | 1310 | return GNUNET_SYSERR; |
1266 | } | 1311 | } |
1267 | GNUNET_free (op_name); | 1312 | GNUNET_free(op_name); |
1268 | 1313 | ||
1269 | /* plugin */ | 1314 | /* plugin */ |
1270 | GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); | 1315 | GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); |
1271 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1316 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1272 | sec_name, op_name, &o->plugin)) | 1317 | sec_name, op_name, &o->plugin)) |
1273 | { | 1318 | { |
1274 | fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", | 1319 | fprintf(stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", |
1275 | op_counter, "ADD_ADDRESS", op_name); | 1320 | op_counter, "ADD_ADDRESS", op_name); |
1276 | GNUNET_free (op_name); | 1321 | GNUNET_free(op_name); |
1277 | return GNUNET_SYSERR; | 1322 | return GNUNET_SYSERR; |
1278 | } | 1323 | } |
1279 | GNUNET_free (op_name); | 1324 | GNUNET_free(op_name); |
1280 | 1325 | ||
1281 | /* address */ | 1326 | /* address */ |
1282 | GNUNET_asprintf(&op_name, "op-%u-address", op_counter); | 1327 | GNUNET_asprintf(&op_name, "op-%u-address", op_counter); |
1283 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1328 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1284 | sec_name, op_name, &o->address)) | 1329 | sec_name, op_name, &o->address)) |
1285 | { | 1330 | { |
1286 | fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n", | 1331 | fprintf(stderr, "Missing address in operation %u `%s' in episode `%s'\n", |
1287 | op_counter, "ADD_ADDRESS", op_name); | 1332 | op_counter, "ADD_ADDRESS", op_name); |
1288 | GNUNET_free (op_name); | 1333 | GNUNET_free(op_name); |
1289 | return GNUNET_SYSERR; | 1334 | return GNUNET_SYSERR; |
1290 | } | 1335 | } |
1291 | GNUNET_free (op_name); | 1336 | GNUNET_free(op_name); |
1292 | 1337 | ||
1293 | /* session */ | 1338 | /* session */ |
1294 | GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); | 1339 | GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); |
1295 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1340 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1296 | sec_name, op_name, &o->address_session)) | 1341 | sec_name, op_name, &o->address_session)) |
1297 | { | 1342 | { |
1298 | fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", | 1343 | fprintf(stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", |
1299 | op_counter, "ADD_ADDRESS", op_name); | 1344 | op_counter, "ADD_ADDRESS", op_name); |
1300 | GNUNET_free (op_name); | 1345 | GNUNET_free(op_name); |
1301 | return GNUNET_SYSERR; | 1346 | return GNUNET_SYSERR; |
1302 | } | 1347 | } |
1303 | GNUNET_free (op_name); | 1348 | GNUNET_free(op_name); |
1304 | 1349 | ||
1305 | /* network */ | 1350 | /* network */ |
1306 | GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter); | 1351 | GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter); |
1307 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1352 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1308 | sec_name, op_name, &op_network)) | 1353 | sec_name, op_name, &op_network)) |
1309 | { | ||
1310 | fprintf (stderr, "Missing address-network in operation %u `%s' in episode `%s'\n", | ||
1311 | op_counter, "ADD_ADDRESS", op_name); | ||
1312 | GNUNET_free (op_name); | ||
1313 | return GNUNET_SYSERR; | ||
1314 | } | ||
1315 | else | ||
1316 | { | ||
1317 | GNUNET_STRINGS_utf8_toupper (op_network,op_network); | ||
1318 | if (0 == strcmp(op_network, "UNSPECIFIED")) | ||
1319 | { | ||
1320 | o->address_network = GNUNET_NT_UNSPECIFIED; | ||
1321 | } | ||
1322 | else if (0 == strcmp(op_network, "LOOPBACK")) | ||
1323 | { | 1354 | { |
1324 | o->address_network = GNUNET_NT_LOOPBACK; | 1355 | fprintf(stderr, "Missing address-network in operation %u `%s' in episode `%s'\n", |
1325 | } | 1356 | op_counter, "ADD_ADDRESS", op_name); |
1326 | else if (0 == strcmp(op_network, "LAN")) | 1357 | GNUNET_free(op_name); |
1327 | { | 1358 | return GNUNET_SYSERR; |
1328 | o->address_network = GNUNET_NT_LAN; | ||
1329 | } | ||
1330 | else if (0 == strcmp(op_network, "WAN")) | ||
1331 | { | ||
1332 | o->address_network = GNUNET_NT_WAN; | ||
1333 | } | ||
1334 | else if (0 == strcmp(op_network, "WLAN")) | ||
1335 | { | ||
1336 | o->address_network = GNUNET_NT_WLAN; | ||
1337 | } | ||
1338 | else if (0 == strcmp(op_network, "BT")) | ||
1339 | { | ||
1340 | o->address_network = GNUNET_NT_BT; | ||
1341 | } | 1359 | } |
1342 | else | 1360 | else |
1343 | { | 1361 | { |
1344 | fprintf (stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n", | 1362 | GNUNET_STRINGS_utf8_toupper(op_network, op_network); |
1345 | op_counter, "ADD_ADDRESS", op_name, op_network); | 1363 | if (0 == strcmp(op_network, "UNSPECIFIED")) |
1346 | GNUNET_free (op_network); | 1364 | { |
1347 | GNUNET_free (op_name); | 1365 | o->address_network = GNUNET_NT_UNSPECIFIED; |
1348 | return GNUNET_SYSERR; | 1366 | } |
1367 | else if (0 == strcmp(op_network, "LOOPBACK")) | ||
1368 | { | ||
1369 | o->address_network = GNUNET_NT_LOOPBACK; | ||
1370 | } | ||
1371 | else if (0 == strcmp(op_network, "LAN")) | ||
1372 | { | ||
1373 | o->address_network = GNUNET_NT_LAN; | ||
1374 | } | ||
1375 | else if (0 == strcmp(op_network, "WAN")) | ||
1376 | { | ||
1377 | o->address_network = GNUNET_NT_WAN; | ||
1378 | } | ||
1379 | else if (0 == strcmp(op_network, "WLAN")) | ||
1380 | { | ||
1381 | o->address_network = GNUNET_NT_WLAN; | ||
1382 | } | ||
1383 | else if (0 == strcmp(op_network, "BT")) | ||
1384 | { | ||
1385 | o->address_network = GNUNET_NT_BT; | ||
1386 | } | ||
1387 | else | ||
1388 | { | ||
1389 | fprintf(stderr, "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n", | ||
1390 | op_counter, "ADD_ADDRESS", op_name, op_network); | ||
1391 | GNUNET_free(op_network); | ||
1392 | GNUNET_free(op_name); | ||
1393 | return GNUNET_SYSERR; | ||
1394 | } | ||
1349 | } | 1395 | } |
1350 | } | 1396 | GNUNET_free(op_network); |
1351 | GNUNET_free (op_network); | 1397 | GNUNET_free(op_name); |
1352 | GNUNET_free (op_name); | ||
1353 | 1398 | ||
1354 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1399 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1355 | "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", | 1400 | "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", |
1356 | "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); | 1401 | "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); |
1357 | 1402 | ||
1358 | return GNUNET_OK; | 1403 | return GNUNET_OK; |
1359 | } | 1404 | } |
1360 | 1405 | ||
1361 | 1406 | ||
1362 | static int | 1407 | static int |
1363 | load_op_del_address (struct GNUNET_ATS_TEST_Operation *o, | 1408 | load_op_del_address(struct GNUNET_ATS_TEST_Operation *o, |
1364 | struct Episode *e, | 1409 | struct Episode *e, |
1365 | int op_counter, | 1410 | int op_counter, |
1366 | char *sec_name, | 1411 | char *sec_name, |
1367 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1412 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1368 | { | 1413 | { |
1369 | char *op_name; | 1414 | char *op_name; |
1415 | |||
1370 | //char *op_network; | 1416 | //char *op_network; |
1371 | 1417 | ||
1372 | /* peer pid */ | 1418 | /* peer pid */ |
1373 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1419 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1374 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1420 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1375 | sec_name, op_name, &o->peer_id)) | 1421 | sec_name, op_name, &o->peer_id)) |
1376 | { | 1422 | { |
1377 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1423 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1378 | op_counter, "DEL_ADDRESS", op_name); | 1424 | op_counter, "DEL_ADDRESS", op_name); |
1379 | GNUNET_free (op_name); | 1425 | GNUNET_free(op_name); |
1380 | return GNUNET_SYSERR; | 1426 | return GNUNET_SYSERR; |
1381 | } | 1427 | } |
1382 | GNUNET_free (op_name); | 1428 | GNUNET_free(op_name); |
1383 | 1429 | ||
1384 | /* address pid */ | 1430 | /* address pid */ |
1385 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); | 1431 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); |
1386 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1432 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1387 | sec_name, op_name, &o->address_id)) | 1433 | sec_name, op_name, &o->address_id)) |
1388 | { | 1434 | { |
1389 | fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", | 1435 | fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", |
1390 | op_counter, "DEL_ADDRESS", op_name); | 1436 | op_counter, "DEL_ADDRESS", op_name); |
1391 | GNUNET_free (op_name); | 1437 | GNUNET_free(op_name); |
1392 | return GNUNET_SYSERR; | 1438 | return GNUNET_SYSERR; |
1393 | } | 1439 | } |
1394 | GNUNET_free (op_name); | 1440 | GNUNET_free(op_name); |
1395 | 1441 | ||
1396 | #if 0 | 1442 | #if 0 |
1397 | /* plugin */ | 1443 | /* plugin */ |
1398 | GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); | 1444 | GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); |
1399 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1445 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1400 | sec_name, op_name, &o->plugin)) | 1446 | sec_name, op_name, &o->plugin)) |
1401 | { | 1447 | { |
1402 | fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", | 1448 | fprintf(stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", |
1403 | op_counter, "DEL_ADDRESS", op_name); | 1449 | op_counter, "DEL_ADDRESS", op_name); |
1404 | GNUNET_free (op_name); | 1450 | GNUNET_free(op_name); |
1405 | return GNUNET_SYSERR; | 1451 | return GNUNET_SYSERR; |
1406 | } | 1452 | } |
1407 | GNUNET_free (op_name); | 1453 | GNUNET_free(op_name); |
1408 | 1454 | ||
1409 | /* address */ | 1455 | /* address */ |
1410 | GNUNET_asprintf(&op_name, "op-%u-address", op_counter); | 1456 | GNUNET_asprintf(&op_name, "op-%u-address", op_counter); |
1411 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1457 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1412 | sec_name, op_name, &o->address)) | 1458 | sec_name, op_name, &o->address)) |
1413 | { | 1459 | { |
1414 | fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n", | 1460 | fprintf(stderr, "Missing address in operation %u `%s' in episode `%s'\n", |
1415 | op_counter, "DEL_ADDRESS", op_name); | 1461 | op_counter, "DEL_ADDRESS", op_name); |
1416 | GNUNET_free (op_name); | 1462 | GNUNET_free(op_name); |
1417 | return GNUNET_SYSERR; | 1463 | return GNUNET_SYSERR; |
1418 | } | 1464 | } |
1419 | GNUNET_free (op_name); | 1465 | GNUNET_free(op_name); |
1420 | 1466 | ||
1421 | /* session */ | 1467 | /* session */ |
1422 | GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); | 1468 | GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); |
1423 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1469 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1424 | sec_name, op_name, &o->address_session)) | 1470 | sec_name, op_name, &o->address_session)) |
1425 | { | 1471 | { |
1426 | fprintf (stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", | 1472 | fprintf(stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", |
1427 | op_counter, "DEL_ADDRESS", op_name); | 1473 | op_counter, "DEL_ADDRESS", op_name); |
1428 | GNUNET_free (op_name); | 1474 | GNUNET_free(op_name); |
1429 | return GNUNET_SYSERR; | 1475 | return GNUNET_SYSERR; |
1430 | } | 1476 | } |
1431 | GNUNET_free (op_name); | 1477 | GNUNET_free(op_name); |
1432 | #endif | 1478 | #endif |
1433 | 1479 | ||
1434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1480 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1435 | "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", | 1481 | "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", |
1436 | "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); | 1482 | "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); |
1437 | 1483 | ||
1438 | return GNUNET_OK; | 1484 | return GNUNET_OK; |
1439 | } | 1485 | } |
1440 | 1486 | ||
1441 | 1487 | ||
1442 | static enum GNUNET_ATS_Property | 1488 | static enum GNUNET_ATS_Property |
1443 | parse_preference_string (const char * str) | 1489 | parse_preference_string(const char * str) |
1444 | { | 1490 | { |
1445 | int c = 0; | 1491 | int c = 0; |
1446 | char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; | 1492 | char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; |
@@ -1453,11 +1499,11 @@ parse_preference_string (const char * str) | |||
1453 | 1499 | ||
1454 | 1500 | ||
1455 | static int | 1501 | static int |
1456 | load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, | 1502 | load_op_start_set_preference(struct GNUNET_ATS_TEST_Operation *o, |
1457 | struct Episode *e, | 1503 | struct Episode *e, |
1458 | int op_counter, | 1504 | int op_counter, |
1459 | char *sec_name, | 1505 | char *sec_name, |
1460 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1506 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1461 | { | 1507 | { |
1462 | char *op_name; | 1508 | char *op_name; |
1463 | char *type; | 1509 | char *type; |
@@ -1465,235 +1511,235 @@ load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, | |||
1465 | 1511 | ||
1466 | /* peer pid */ | 1512 | /* peer pid */ |
1467 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1513 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1468 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1514 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1469 | sec_name, op_name, &o->peer_id)) | 1515 | sec_name, op_name, &o->peer_id)) |
1470 | { | 1516 | { |
1471 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1517 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1472 | op_counter, "START_SET_PREFERENCE", op_name); | 1518 | op_counter, "START_SET_PREFERENCE", op_name); |
1473 | GNUNET_free (op_name); | 1519 | GNUNET_free(op_name); |
1474 | return GNUNET_SYSERR; | 1520 | return GNUNET_SYSERR; |
1475 | } | 1521 | } |
1476 | GNUNET_free (op_name); | 1522 | GNUNET_free(op_name); |
1477 | 1523 | ||
1478 | /* address pid */ | 1524 | /* address pid */ |
1479 | GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter); | 1525 | GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter); |
1480 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1526 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1481 | sec_name, op_name, &o->client_id)) | 1527 | sec_name, op_name, &o->client_id)) |
1482 | { | 1528 | { |
1483 | fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n", | 1529 | fprintf(stderr, "Missing client-id in operation %u `%s' in episode `%s'\n", |
1484 | op_counter, "START_SET_PREFERENCE", op_name); | 1530 | op_counter, "START_SET_PREFERENCE", op_name); |
1485 | GNUNET_free (op_name); | 1531 | GNUNET_free(op_name); |
1486 | return GNUNET_SYSERR; | 1532 | return GNUNET_SYSERR; |
1487 | } | 1533 | } |
1488 | GNUNET_free (op_name); | 1534 | GNUNET_free(op_name); |
1489 | 1535 | ||
1490 | /* generator */ | 1536 | /* generator */ |
1491 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); | 1537 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); |
1492 | if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 1538 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1493 | sec_name, op_name, &type)) ) | 1539 | sec_name, op_name, &type))) |
1494 | { | 1540 | { |
1495 | fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n", | 1541 | fprintf(stderr, "Missing type in operation %u `%s' in episode `%s'\n", |
1496 | op_counter, "START_SET_PREFERENCE", op_name); | 1542 | op_counter, "START_SET_PREFERENCE", op_name); |
1497 | GNUNET_free (op_name); | 1543 | GNUNET_free(op_name); |
1498 | return GNUNET_SYSERR; | 1544 | return GNUNET_SYSERR; |
1499 | } | 1545 | } |
1500 | 1546 | ||
1501 | /* Load arguments for set_rate, start_send, set_preference */ | 1547 | /* Load arguments for set_rate, start_send, set_preference */ |
1502 | if (0 == strcmp (type, "constant")) | 1548 | if (0 == strcmp(type, "constant")) |
1503 | { | 1549 | { |
1504 | o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; | 1550 | o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; |
1505 | } | 1551 | } |
1506 | else if (0 == strcmp (type, "linear")) | 1552 | else if (0 == strcmp(type, "linear")) |
1507 | { | 1553 | { |
1508 | o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; | 1554 | o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; |
1509 | } | 1555 | } |
1510 | else if (0 == strcmp (type, "sinus")) | 1556 | else if (0 == strcmp(type, "sinus")) |
1511 | { | 1557 | { |
1512 | o->gen_type = GNUNET_ATS_TEST_TG_SINUS; | 1558 | o->gen_type = GNUNET_ATS_TEST_TG_SINUS; |
1513 | } | 1559 | } |
1514 | else if (0 == strcmp (type, "random")) | 1560 | else if (0 == strcmp(type, "random")) |
1515 | { | 1561 | { |
1516 | o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; | 1562 | o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; |
1517 | } | 1563 | } |
1518 | else | 1564 | else |
1519 | { | 1565 | { |
1520 | fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n", | 1566 | fprintf(stderr, "Invalid generator type %u `%s' in episode %u\n", |
1521 | op_counter, op_name, e->id); | 1567 | op_counter, op_name, e->id); |
1522 | GNUNET_free (type); | 1568 | GNUNET_free(type); |
1523 | GNUNET_free (op_name); | 1569 | GNUNET_free(op_name); |
1524 | return GNUNET_SYSERR; | 1570 | return GNUNET_SYSERR; |
1525 | } | 1571 | } |
1526 | GNUNET_free (type); | 1572 | GNUNET_free(type); |
1527 | GNUNET_free (op_name); | 1573 | GNUNET_free(op_name); |
1528 | 1574 | ||
1529 | 1575 | ||
1530 | /* Get base rate */ | 1576 | /* Get base rate */ |
1531 | GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); | 1577 | GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); |
1532 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1578 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1533 | sec_name, op_name, &o->base_rate)) | 1579 | sec_name, op_name, &o->base_rate)) |
1534 | { | 1580 | { |
1535 | fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n", | 1581 | fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", |
1536 | op_counter, op_name, e->id); | 1582 | op_counter, op_name, e->id); |
1537 | GNUNET_free (op_name); | 1583 | GNUNET_free(op_name); |
1538 | return GNUNET_SYSERR; | 1584 | return GNUNET_SYSERR; |
1539 | } | 1585 | } |
1540 | GNUNET_free (op_name); | 1586 | GNUNET_free(op_name); |
1541 | 1587 | ||
1542 | 1588 | ||
1543 | /* Get max rate */ | 1589 | /* Get max rate */ |
1544 | GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); | 1590 | GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); |
1545 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1591 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1546 | sec_name, op_name, &o->max_rate)) | 1592 | sec_name, op_name, &o->max_rate)) |
1547 | { | ||
1548 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || | ||
1549 | (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || | ||
1550 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) | ||
1551 | { | 1593 | { |
1552 | fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n", | 1594 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || |
1553 | op_counter, op_name, e->id); | 1595 | (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || |
1554 | GNUNET_free (op_name); | 1596 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) |
1555 | return GNUNET_SYSERR; | 1597 | { |
1598 | fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n", | ||
1599 | op_counter, op_name, e->id); | ||
1600 | GNUNET_free(op_name); | ||
1601 | return GNUNET_SYSERR; | ||
1602 | } | ||
1556 | } | 1603 | } |
1557 | } | 1604 | GNUNET_free(op_name); |
1558 | GNUNET_free (op_name); | ||
1559 | 1605 | ||
1560 | /* Get period */ | 1606 | /* Get period */ |
1561 | GNUNET_asprintf(&op_name, "op-%u-period", op_counter); | 1607 | GNUNET_asprintf(&op_name, "op-%u-period", op_counter); |
1562 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | 1608 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
1563 | sec_name, op_name, &o->period)) | 1609 | sec_name, op_name, &o->period)) |
1564 | { | 1610 | { |
1565 | o->period = e->duration; | 1611 | o->period = e->duration; |
1566 | } | 1612 | } |
1567 | GNUNET_free (op_name); | 1613 | GNUNET_free(op_name); |
1568 | 1614 | ||
1569 | /* Get frequency */ | 1615 | /* Get frequency */ |
1570 | GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); | 1616 | GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); |
1571 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | 1617 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
1572 | sec_name, op_name, &o->frequency)) | 1618 | sec_name, op_name, &o->frequency)) |
1573 | { | 1619 | { |
1574 | fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n", | 1620 | fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", |
1575 | op_counter, op_name, e->id); | 1621 | op_counter, op_name, e->id); |
1576 | GNUNET_free (op_name); | 1622 | GNUNET_free(op_name); |
1577 | return GNUNET_SYSERR; | 1623 | return GNUNET_SYSERR; |
1578 | } | 1624 | } |
1579 | GNUNET_free (op_name); | 1625 | GNUNET_free(op_name); |
1580 | 1626 | ||
1581 | /* Get preference */ | 1627 | /* Get preference */ |
1582 | GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); | 1628 | GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); |
1583 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1629 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1584 | sec_name, op_name, &pref)) | 1630 | sec_name, op_name, &pref)) |
1585 | { | 1631 | { |
1586 | fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n", | 1632 | fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n", |
1587 | op_counter, op_name, e->id); | 1633 | op_counter, op_name, e->id); |
1588 | GNUNET_free (op_name); | 1634 | GNUNET_free(op_name); |
1589 | return GNUNET_SYSERR; | 1635 | return GNUNET_SYSERR; |
1590 | } | 1636 | } |
1591 | 1637 | ||
1592 | if (0 == (o->pref_type = parse_preference_string(pref))) | 1638 | if (0 == (o->pref_type = parse_preference_string(pref))) |
1593 | { | 1639 | { |
1594 | fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n", | 1640 | fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n", |
1595 | op_counter, op_name, e->id); | 1641 | op_counter, op_name, e->id); |
1596 | GNUNET_free (op_name); | 1642 | GNUNET_free(op_name); |
1597 | GNUNET_free (pref); | 1643 | GNUNET_free(pref); |
1598 | return GNUNET_SYSERR; | 1644 | return GNUNET_SYSERR; |
1599 | } | 1645 | } |
1600 | GNUNET_free (pref); | 1646 | GNUNET_free(pref); |
1601 | GNUNET_free (op_name); | 1647 | GNUNET_free(op_name); |
1602 | 1648 | ||
1603 | /* Get feedback delay */ | 1649 | /* Get feedback delay */ |
1604 | GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter); | 1650 | GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter); |
1605 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg, | 1651 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time(cfg, |
1606 | sec_name, op_name, &o->feedback_delay)) | 1652 | sec_name, op_name, &o->feedback_delay)) |
1607 | { | 1653 | { |
1608 | fprintf (stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n", | 1654 | fprintf(stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n", |
1609 | (long long unsigned int) o->feedback_delay.rel_value_us, | 1655 | (long long unsigned int)o->feedback_delay.rel_value_us, |
1610 | op_counter, op_name, e->id); | 1656 | op_counter, op_name, e->id); |
1611 | } | 1657 | } |
1612 | else | 1658 | else |
1613 | o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 1659 | o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
1614 | GNUNET_free (op_name); | 1660 | GNUNET_free(op_name); |
1615 | 1661 | ||
1616 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1662 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1617 | "Found operation %s: [%llu:%llu]: %s = %llu\n", | 1663 | "Found operation %s: [%llu:%llu]: %s = %llu\n", |
1618 | "START_SET_PREFERENCE", o->peer_id, o->address_id, | 1664 | "START_SET_PREFERENCE", o->peer_id, o->address_id, |
1619 | GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate); | 1665 | GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate); |
1620 | 1666 | ||
1621 | return GNUNET_OK; | 1667 | return GNUNET_OK; |
1622 | } | 1668 | } |
1623 | 1669 | ||
1624 | 1670 | ||
1625 | static int | 1671 | static int |
1626 | load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o, | 1672 | load_op_stop_set_preference(struct GNUNET_ATS_TEST_Operation *o, |
1627 | struct Episode *e, | 1673 | struct Episode *e, |
1628 | int op_counter, | 1674 | int op_counter, |
1629 | char *sec_name, | 1675 | char *sec_name, |
1630 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1676 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1631 | { | 1677 | { |
1632 | char *op_name; | 1678 | char *op_name; |
1633 | char *pref; | 1679 | char *pref; |
1634 | 1680 | ||
1635 | /* peer pid */ | 1681 | /* peer pid */ |
1636 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1682 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1637 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1683 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1638 | sec_name, op_name, &o->peer_id)) | 1684 | sec_name, op_name, &o->peer_id)) |
1639 | { | 1685 | { |
1640 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1686 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1641 | op_counter, "STOP_SET_PREFERENCE", op_name); | 1687 | op_counter, "STOP_SET_PREFERENCE", op_name); |
1642 | GNUNET_free (op_name); | 1688 | GNUNET_free(op_name); |
1643 | return GNUNET_SYSERR; | 1689 | return GNUNET_SYSERR; |
1644 | } | 1690 | } |
1645 | GNUNET_free (op_name); | 1691 | GNUNET_free(op_name); |
1646 | 1692 | ||
1647 | /* address pid */ | 1693 | /* address pid */ |
1648 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); | 1694 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); |
1649 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1695 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1650 | sec_name, op_name, &o->address_id)) | 1696 | sec_name, op_name, &o->address_id)) |
1651 | { | 1697 | { |
1652 | fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", | 1698 | fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", |
1653 | op_counter, "STOP_SET_PREFERENCE", op_name); | 1699 | op_counter, "STOP_SET_PREFERENCE", op_name); |
1654 | GNUNET_free (op_name); | 1700 | GNUNET_free(op_name); |
1655 | return GNUNET_SYSERR; | 1701 | return GNUNET_SYSERR; |
1656 | } | 1702 | } |
1657 | GNUNET_free (op_name); | 1703 | GNUNET_free(op_name); |
1658 | 1704 | ||
1659 | /* Get preference */ | 1705 | /* Get preference */ |
1660 | GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); | 1706 | GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); |
1661 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1707 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1662 | sec_name, op_name, &pref)) | 1708 | sec_name, op_name, &pref)) |
1663 | { | 1709 | { |
1664 | fprintf (stderr, "Missing preference in operation %u `%s' in episode `%s'\n", | 1710 | fprintf(stderr, "Missing preference in operation %u `%s' in episode `%s'\n", |
1665 | op_counter, "STOP_SET_PREFERENCE", op_name); | 1711 | op_counter, "STOP_SET_PREFERENCE", op_name); |
1666 | GNUNET_free (op_name); | 1712 | GNUNET_free(op_name); |
1667 | return GNUNET_SYSERR; | 1713 | return GNUNET_SYSERR; |
1668 | } | 1714 | } |
1669 | 1715 | ||
1670 | if (0 == (o->pref_type = parse_preference_string(pref))) | 1716 | if (0 == (o->pref_type = parse_preference_string(pref))) |
1671 | { | 1717 | { |
1672 | fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n", | 1718 | fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n", |
1673 | op_counter, op_name, e->id); | 1719 | op_counter, op_name, e->id); |
1674 | GNUNET_free (op_name); | 1720 | GNUNET_free(op_name); |
1675 | GNUNET_free (pref); | 1721 | GNUNET_free(pref); |
1676 | return GNUNET_SYSERR; | 1722 | return GNUNET_SYSERR; |
1677 | } | 1723 | } |
1678 | GNUNET_free (pref); | 1724 | GNUNET_free(pref); |
1679 | GNUNET_free (op_name); | 1725 | GNUNET_free(op_name); |
1680 | 1726 | ||
1681 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1727 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1682 | "Found operation %s: [%llu:%llu]: %s\n", | 1728 | "Found operation %s: [%llu:%llu]: %s\n", |
1683 | "STOP_SET_PREFERENCE", o->peer_id, o->address_id, | 1729 | "STOP_SET_PREFERENCE", o->peer_id, o->address_id, |
1684 | GNUNET_ATS_print_preference_type(o->pref_type)); | 1730 | GNUNET_ATS_print_preference_type(o->pref_type)); |
1685 | return GNUNET_OK; | 1731 | return GNUNET_OK; |
1686 | } | 1732 | } |
1687 | 1733 | ||
1688 | 1734 | ||
1689 | static enum GNUNET_ATS_Property | 1735 | static enum GNUNET_ATS_Property |
1690 | parse_property_string (const char *str) | 1736 | parse_property_string(const char *str) |
1691 | { | 1737 | { |
1692 | enum GNUNET_ATS_Property c; | 1738 | enum GNUNET_ATS_Property c; |
1693 | 1739 | ||
1694 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | 1740 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) |
1695 | if (0 == strcmp(str, | 1741 | if (0 == strcmp(str, |
1696 | GNUNET_ATS_print_property_type (c))) | 1742 | GNUNET_ATS_print_property_type(c))) |
1697 | return c; | 1743 | return c; |
1698 | return 0; | 1744 | return 0; |
1699 | } | 1745 | } |
@@ -1701,10 +1747,10 @@ parse_property_string (const char *str) | |||
1701 | 1747 | ||
1702 | static int | 1748 | static int |
1703 | load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o, | 1749 | load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o, |
1704 | struct Episode *e, | 1750 | struct Episode *e, |
1705 | int op_counter, | 1751 | int op_counter, |
1706 | char *sec_name, | 1752 | char *sec_name, |
1707 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1753 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1708 | { | 1754 | { |
1709 | char *op_name; | 1755 | char *op_name; |
1710 | char *type; | 1756 | char *type; |
@@ -1712,268 +1758,268 @@ load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o, | |||
1712 | 1758 | ||
1713 | /* peer pid */ | 1759 | /* peer pid */ |
1714 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1760 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1715 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1761 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1716 | sec_name, op_name, &o->peer_id)) | 1762 | sec_name, op_name, &o->peer_id)) |
1717 | { | 1763 | { |
1718 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1764 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1719 | op_counter, "START_SET_PROPERTY", op_name); | 1765 | op_counter, "START_SET_PROPERTY", op_name); |
1720 | GNUNET_free (op_name); | 1766 | GNUNET_free(op_name); |
1721 | return GNUNET_SYSERR; | 1767 | return GNUNET_SYSERR; |
1722 | } | 1768 | } |
1723 | GNUNET_free (op_name); | 1769 | GNUNET_free(op_name); |
1724 | 1770 | ||
1725 | /* address pid */ | 1771 | /* address pid */ |
1726 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); | 1772 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); |
1727 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1773 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1728 | sec_name, op_name, &o->address_id)) | 1774 | sec_name, op_name, &o->address_id)) |
1729 | { | 1775 | { |
1730 | fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", | 1776 | fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", |
1731 | op_counter, "START_SET_PROPERTY", op_name); | 1777 | op_counter, "START_SET_PROPERTY", op_name); |
1732 | GNUNET_free (op_name); | 1778 | GNUNET_free(op_name); |
1733 | return GNUNET_SYSERR; | 1779 | return GNUNET_SYSERR; |
1734 | } | 1780 | } |
1735 | GNUNET_free (op_name); | 1781 | GNUNET_free(op_name); |
1736 | 1782 | ||
1737 | /* generator */ | 1783 | /* generator */ |
1738 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); | 1784 | GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); |
1739 | if ( (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | 1785 | if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1740 | sec_name, op_name, &type)) ) | 1786 | sec_name, op_name, &type))) |
1741 | { | 1787 | { |
1742 | fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n", | 1788 | fprintf(stderr, "Missing type in operation %u `%s' in episode `%s'\n", |
1743 | op_counter, "START_SET_PROPERTY", op_name); | 1789 | op_counter, "START_SET_PROPERTY", op_name); |
1744 | GNUNET_free (op_name); | 1790 | GNUNET_free(op_name); |
1745 | return GNUNET_SYSERR; | 1791 | return GNUNET_SYSERR; |
1746 | } | 1792 | } |
1747 | 1793 | ||
1748 | /* Load arguments for set_rate, start_send, set_preference */ | 1794 | /* Load arguments for set_rate, start_send, set_preference */ |
1749 | if (0 == strcmp (type, "constant")) | 1795 | if (0 == strcmp(type, "constant")) |
1750 | { | 1796 | { |
1751 | o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; | 1797 | o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; |
1752 | } | 1798 | } |
1753 | else if (0 == strcmp (type, "linear")) | 1799 | else if (0 == strcmp(type, "linear")) |
1754 | { | 1800 | { |
1755 | o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; | 1801 | o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; |
1756 | } | 1802 | } |
1757 | else if (0 == strcmp (type, "sinus")) | 1803 | else if (0 == strcmp(type, "sinus")) |
1758 | { | 1804 | { |
1759 | o->gen_type = GNUNET_ATS_TEST_TG_SINUS; | 1805 | o->gen_type = GNUNET_ATS_TEST_TG_SINUS; |
1760 | } | 1806 | } |
1761 | else if (0 == strcmp (type, "random")) | 1807 | else if (0 == strcmp(type, "random")) |
1762 | { | 1808 | { |
1763 | o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; | 1809 | o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; |
1764 | } | 1810 | } |
1765 | else | 1811 | else |
1766 | { | 1812 | { |
1767 | fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n", | 1813 | fprintf(stderr, "Invalid generator type %u `%s' in episode %u\n", |
1768 | op_counter, op_name, e->id); | 1814 | op_counter, op_name, e->id); |
1769 | GNUNET_free (type); | 1815 | GNUNET_free(type); |
1770 | GNUNET_free (op_name); | 1816 | GNUNET_free(op_name); |
1771 | return GNUNET_SYSERR; | 1817 | return GNUNET_SYSERR; |
1772 | } | 1818 | } |
1773 | GNUNET_free (type); | 1819 | GNUNET_free(type); |
1774 | GNUNET_free (op_name); | 1820 | GNUNET_free(op_name); |
1775 | 1821 | ||
1776 | 1822 | ||
1777 | /* Get base rate */ | 1823 | /* Get base rate */ |
1778 | GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); | 1824 | GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); |
1779 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1825 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1780 | sec_name, op_name, &o->base_rate)) | 1826 | sec_name, op_name, &o->base_rate)) |
1781 | { | 1827 | { |
1782 | fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n", | 1828 | fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", |
1783 | op_counter, op_name, e->id); | 1829 | op_counter, op_name, e->id); |
1784 | GNUNET_free (op_name); | 1830 | GNUNET_free(op_name); |
1785 | return GNUNET_SYSERR; | 1831 | return GNUNET_SYSERR; |
1786 | } | 1832 | } |
1787 | GNUNET_free (op_name); | 1833 | GNUNET_free(op_name); |
1788 | 1834 | ||
1789 | 1835 | ||
1790 | /* Get max rate */ | 1836 | /* Get max rate */ |
1791 | GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); | 1837 | GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); |
1792 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1838 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1793 | sec_name, op_name, &o->max_rate)) | 1839 | sec_name, op_name, &o->max_rate)) |
1794 | { | ||
1795 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || | ||
1796 | (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || | ||
1797 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) | ||
1798 | { | 1840 | { |
1799 | fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n", | 1841 | if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || |
1800 | op_counter, op_name, e->id); | 1842 | (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || |
1801 | GNUNET_free (op_name); | 1843 | (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) |
1802 | return GNUNET_SYSERR; | 1844 | { |
1845 | fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n", | ||
1846 | op_counter, op_name, e->id); | ||
1847 | GNUNET_free(op_name); | ||
1848 | return GNUNET_SYSERR; | ||
1849 | } | ||
1803 | } | 1850 | } |
1804 | } | 1851 | GNUNET_free(op_name); |
1805 | GNUNET_free (op_name); | ||
1806 | 1852 | ||
1807 | /* Get period */ | 1853 | /* Get period */ |
1808 | GNUNET_asprintf(&op_name, "op-%u-period", op_counter); | 1854 | GNUNET_asprintf(&op_name, "op-%u-period", op_counter); |
1809 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | 1855 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
1810 | sec_name, op_name, &o->period)) | 1856 | sec_name, op_name, &o->period)) |
1811 | { | 1857 | { |
1812 | o->period = e->duration; | 1858 | o->period = e->duration; |
1813 | } | 1859 | } |
1814 | GNUNET_free (op_name); | 1860 | GNUNET_free(op_name); |
1815 | 1861 | ||
1816 | /* Get frequency */ | 1862 | /* Get frequency */ |
1817 | GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); | 1863 | GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); |
1818 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, | 1864 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
1819 | sec_name, op_name, &o->frequency)) | 1865 | sec_name, op_name, &o->frequency)) |
1820 | { | 1866 | { |
1821 | fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n", | 1867 | fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", |
1822 | op_counter, op_name, e->id); | 1868 | op_counter, op_name, e->id); |
1823 | GNUNET_free (op_name); | 1869 | GNUNET_free(op_name); |
1824 | return GNUNET_SYSERR; | 1870 | return GNUNET_SYSERR; |
1825 | } | 1871 | } |
1826 | GNUNET_free (op_name); | 1872 | GNUNET_free(op_name); |
1827 | 1873 | ||
1828 | /* Get preference */ | 1874 | /* Get preference */ |
1829 | GNUNET_asprintf(&op_name, "op-%u-property", op_counter); | 1875 | GNUNET_asprintf(&op_name, "op-%u-property", op_counter); |
1830 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1876 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1831 | sec_name, op_name, &prop)) | 1877 | sec_name, op_name, &prop)) |
1832 | { | 1878 | { |
1833 | fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n", | 1879 | fprintf(stderr, "Missing property in operation %u `%s' in episode %u\n", |
1834 | op_counter, op_name, e->id); | 1880 | op_counter, op_name, e->id); |
1835 | GNUNET_free (op_name); | 1881 | GNUNET_free(op_name); |
1836 | GNUNET_free_non_null (prop); | 1882 | GNUNET_free_non_null(prop); |
1837 | return GNUNET_SYSERR; | 1883 | return GNUNET_SYSERR; |
1838 | } | 1884 | } |
1839 | 1885 | ||
1840 | if (0 == (o->prop_type = parse_property_string(prop))) | 1886 | if (0 == (o->prop_type = parse_property_string(prop))) |
1841 | { | 1887 | { |
1842 | fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n", | 1888 | fprintf(stderr, "Invalid property in operation %u `%s' in episode %u\n", |
1843 | op_counter, op_name, e->id); | 1889 | op_counter, op_name, e->id); |
1844 | GNUNET_free (op_name); | 1890 | GNUNET_free(op_name); |
1845 | GNUNET_free (prop); | 1891 | GNUNET_free(prop); |
1846 | return GNUNET_SYSERR; | 1892 | return GNUNET_SYSERR; |
1847 | } | 1893 | } |
1848 | 1894 | ||
1849 | GNUNET_free (prop); | 1895 | GNUNET_free(prop); |
1850 | GNUNET_free (op_name); | 1896 | GNUNET_free(op_name); |
1851 | 1897 | ||
1852 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1898 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1853 | "Found operation %s: [%llu:%llu] %s = %llu\n", | 1899 | "Found operation %s: [%llu:%llu] %s = %llu\n", |
1854 | "START_SET_PROPERTY", o->peer_id, o->address_id, | 1900 | "START_SET_PROPERTY", o->peer_id, o->address_id, |
1855 | GNUNET_ATS_print_property_type (o->prop_type), o->base_rate); | 1901 | GNUNET_ATS_print_property_type(o->prop_type), o->base_rate); |
1856 | 1902 | ||
1857 | return GNUNET_OK; | 1903 | return GNUNET_OK; |
1858 | } | 1904 | } |
1859 | 1905 | ||
1860 | static int | 1906 | static int |
1861 | load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o, | 1907 | load_op_stop_set_property(struct GNUNET_ATS_TEST_Operation *o, |
1862 | struct Episode *e, | 1908 | struct Episode *e, |
1863 | int op_counter, | 1909 | int op_counter, |
1864 | char *sec_name, | 1910 | char *sec_name, |
1865 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1911 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1866 | { | 1912 | { |
1867 | char *op_name; | 1913 | char *op_name; |
1868 | char *pref; | 1914 | char *pref; |
1869 | 1915 | ||
1870 | /* peer pid */ | 1916 | /* peer pid */ |
1871 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1917 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1872 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1918 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1873 | sec_name, op_name, &o->peer_id)) | 1919 | sec_name, op_name, &o->peer_id)) |
1874 | { | 1920 | { |
1875 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1921 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1876 | op_counter, "STOP_SET_PROPERTY", op_name); | 1922 | op_counter, "STOP_SET_PROPERTY", op_name); |
1877 | GNUNET_free (op_name); | 1923 | GNUNET_free(op_name); |
1878 | return GNUNET_SYSERR; | 1924 | return GNUNET_SYSERR; |
1879 | } | 1925 | } |
1880 | GNUNET_free (op_name); | 1926 | GNUNET_free(op_name); |
1881 | 1927 | ||
1882 | /* address pid */ | 1928 | /* address pid */ |
1883 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); | 1929 | GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); |
1884 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1930 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1885 | sec_name, op_name, &o->address_id)) | 1931 | sec_name, op_name, &o->address_id)) |
1886 | { | 1932 | { |
1887 | fprintf (stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", | 1933 | fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", |
1888 | op_counter, "STOP_SET_PROPERTY", op_name); | 1934 | op_counter, "STOP_SET_PROPERTY", op_name); |
1889 | GNUNET_free (op_name); | 1935 | GNUNET_free(op_name); |
1890 | return GNUNET_SYSERR; | 1936 | return GNUNET_SYSERR; |
1891 | } | 1937 | } |
1892 | GNUNET_free (op_name); | 1938 | GNUNET_free(op_name); |
1893 | 1939 | ||
1894 | /* Get property */ | 1940 | /* Get property */ |
1895 | GNUNET_asprintf(&op_name, "op-%u-property", op_counter); | 1941 | GNUNET_asprintf(&op_name, "op-%u-property", op_counter); |
1896 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, | 1942 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1897 | sec_name, op_name, &pref)) | 1943 | sec_name, op_name, &pref)) |
1898 | { | 1944 | { |
1899 | fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n", | 1945 | fprintf(stderr, "Missing property in operation %u `%s' in episode `%s'\n", |
1900 | op_counter, "STOP_SET_PROPERTY", op_name); | 1946 | op_counter, "STOP_SET_PROPERTY", op_name); |
1901 | GNUNET_free (op_name); | 1947 | GNUNET_free(op_name); |
1902 | GNUNET_free_non_null (pref); | 1948 | GNUNET_free_non_null(pref); |
1903 | return GNUNET_SYSERR; | 1949 | return GNUNET_SYSERR; |
1904 | } | 1950 | } |
1905 | 1951 | ||
1906 | if (0 == (o->prop_type = parse_property_string(pref))) | 1952 | if (0 == (o->prop_type = parse_property_string(pref))) |
1907 | { | 1953 | { |
1908 | fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n", | 1954 | fprintf(stderr, "Invalid property in operation %u `%s' in episode %u\n", |
1909 | op_counter, op_name, e->id); | 1955 | op_counter, op_name, e->id); |
1910 | GNUNET_free (op_name); | 1956 | GNUNET_free(op_name); |
1911 | GNUNET_free_non_null (pref); | 1957 | GNUNET_free_non_null(pref); |
1912 | return GNUNET_SYSERR; | 1958 | return GNUNET_SYSERR; |
1913 | } | 1959 | } |
1914 | 1960 | ||
1915 | GNUNET_free (pref); | 1961 | GNUNET_free(pref); |
1916 | GNUNET_free (op_name); | 1962 | GNUNET_free(op_name); |
1917 | 1963 | ||
1918 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1964 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1919 | "Found operation %s: [%llu:%llu] %s\n", | 1965 | "Found operation %s: [%llu:%llu] %s\n", |
1920 | "STOP_SET_PROPERTY", o->peer_id, o->address_id, | 1966 | "STOP_SET_PROPERTY", o->peer_id, o->address_id, |
1921 | GNUNET_ATS_print_property_type (o->prop_type)); | 1967 | GNUNET_ATS_print_property_type(o->prop_type)); |
1922 | 1968 | ||
1923 | return GNUNET_OK; | 1969 | return GNUNET_OK; |
1924 | } | 1970 | } |
1925 | 1971 | ||
1926 | 1972 | ||
1927 | static int | 1973 | static int |
1928 | load_op_start_request (struct GNUNET_ATS_TEST_Operation *o, | 1974 | load_op_start_request(struct GNUNET_ATS_TEST_Operation *o, |
1929 | struct Episode *e, | 1975 | struct Episode *e, |
1930 | int op_counter, | 1976 | int op_counter, |
1931 | char *sec_name, | 1977 | char *sec_name, |
1932 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1978 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1933 | { | 1979 | { |
1934 | char *op_name; | 1980 | char *op_name; |
1935 | 1981 | ||
1936 | /* peer pid */ | 1982 | /* peer pid */ |
1937 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 1983 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1938 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 1984 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1939 | sec_name, op_name, &o->peer_id)) | 1985 | sec_name, op_name, &o->peer_id)) |
1940 | { | 1986 | { |
1941 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 1987 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1942 | op_counter, "START_REQUEST", op_name); | 1988 | op_counter, "START_REQUEST", op_name); |
1943 | GNUNET_free (op_name); | 1989 | GNUNET_free(op_name); |
1944 | return GNUNET_SYSERR; | 1990 | return GNUNET_SYSERR; |
1945 | } | 1991 | } |
1946 | GNUNET_free (op_name); | 1992 | GNUNET_free(op_name); |
1947 | return GNUNET_OK; | 1993 | return GNUNET_OK; |
1948 | } | 1994 | } |
1949 | 1995 | ||
1950 | static int | 1996 | static int |
1951 | load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o, | 1997 | load_op_stop_request(struct GNUNET_ATS_TEST_Operation *o, |
1952 | struct Episode *e, | 1998 | struct Episode *e, |
1953 | int op_counter, | 1999 | int op_counter, |
1954 | char *sec_name, | 2000 | char *sec_name, |
1955 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 2001 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1956 | { | 2002 | { |
1957 | char *op_name; | 2003 | char *op_name; |
1958 | 2004 | ||
1959 | /* peer pid */ | 2005 | /* peer pid */ |
1960 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); | 2006 | GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); |
1961 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, | 2007 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, |
1962 | sec_name, op_name, &o->peer_id)) | 2008 | sec_name, op_name, &o->peer_id)) |
1963 | { | 2009 | { |
1964 | fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", | 2010 | fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", |
1965 | op_counter, "STOP_REQUEST", op_name); | 2011 | op_counter, "STOP_REQUEST", op_name); |
1966 | GNUNET_free (op_name); | 2012 | GNUNET_free(op_name); |
1967 | return GNUNET_SYSERR; | 2013 | return GNUNET_SYSERR; |
1968 | } | 2014 | } |
1969 | GNUNET_free (op_name); | 2015 | GNUNET_free(op_name); |
1970 | return GNUNET_OK; | 2016 | return GNUNET_OK; |
1971 | } | 2017 | } |
1972 | 2018 | ||
1973 | 2019 | ||
1974 | static int | 2020 | static int |
1975 | load_episode (struct Experiment *e, struct Episode *cur, | 2021 | load_episode(struct Experiment *e, struct Episode *cur, |
1976 | struct GNUNET_CONFIGURATION_Handle *cfg) | 2022 | struct GNUNET_CONFIGURATION_Handle *cfg) |
1977 | { | 2023 | { |
1978 | struct GNUNET_ATS_TEST_Operation *o; | 2024 | struct GNUNET_ATS_TEST_Operation *o; |
1979 | char *sec_name; | 2025 | char *sec_name; |
@@ -1981,98 +2027,99 @@ load_episode (struct Experiment *e, struct Episode *cur, | |||
1981 | char *op; | 2027 | char *op; |
1982 | int op_counter = 0; | 2028 | int op_counter = 0; |
1983 | int res; | 2029 | int res; |
1984 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n",cur->id); | 2030 | |
2031 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n", cur->id); | ||
1985 | GNUNET_asprintf(&sec_name, "episode-%u", cur->id); | 2032 | GNUNET_asprintf(&sec_name, "episode-%u", cur->id); |
1986 | 2033 | ||
1987 | while (1) | 2034 | while (1) |
1988 | { | ||
1989 | /* Load operation */ | ||
1990 | GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); | ||
1991 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, | ||
1992 | sec_name, op_name, &op)) | ||
1993 | { | 2035 | { |
1994 | GNUNET_free (op_name); | 2036 | /* Load operation */ |
1995 | break; | 2037 | GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); |
1996 | } | 2038 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, |
1997 | o = GNUNET_new (struct GNUNET_ATS_TEST_Operation); | 2039 | sec_name, op_name, &op)) |
1998 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n", | 2040 | { |
1999 | cur->id, op_name); | 2041 | GNUNET_free(op_name); |
2042 | break; | ||
2043 | } | ||
2044 | o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); | ||
2045 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n", | ||
2046 | cur->id, op_name); | ||
2000 | 2047 | ||
2001 | /* operations = set_rate, start_send, stop_send, set_preference */ | 2048 | /* operations = set_rate, start_send, stop_send, set_preference */ |
2002 | if (0 == strcmp (op, "address_add")) | 2049 | if (0 == strcmp(op, "address_add")) |
2003 | { | 2050 | { |
2004 | o->type = SOLVER_OP_ADD_ADDRESS; | 2051 | o->type = SOLVER_OP_ADD_ADDRESS; |
2005 | res = load_op_add_address (o, cur, | 2052 | res = load_op_add_address(o, cur, |
2006 | op_counter, sec_name, cfg); | 2053 | op_counter, sec_name, cfg); |
2007 | } | 2054 | } |
2008 | else if (0 == strcmp (op, "address_del")) | 2055 | else if (0 == strcmp(op, "address_del")) |
2009 | { | 2056 | { |
2010 | o->type = SOLVER_OP_DEL_ADDRESS; | 2057 | o->type = SOLVER_OP_DEL_ADDRESS; |
2011 | res = load_op_del_address (o, cur, | 2058 | res = load_op_del_address(o, cur, |
2012 | op_counter, sec_name, cfg); | 2059 | op_counter, sec_name, cfg); |
2013 | } | 2060 | } |
2014 | else if (0 == strcmp (op, "start_set_property")) | 2061 | else if (0 == strcmp(op, "start_set_property")) |
2015 | { | 2062 | { |
2016 | o->type = SOLVER_OP_START_SET_PROPERTY; | 2063 | o->type = SOLVER_OP_START_SET_PROPERTY; |
2017 | res = load_op_start_set_property (o, cur, | 2064 | res = load_op_start_set_property(o, cur, |
2018 | op_counter, sec_name, cfg); | 2065 | op_counter, sec_name, cfg); |
2019 | } | 2066 | } |
2020 | else if (0 == strcmp (op, "stop_set_property")) | 2067 | else if (0 == strcmp(op, "stop_set_property")) |
2021 | { | 2068 | { |
2022 | o->type = SOLVER_OP_STOP_SET_PROPERTY; | 2069 | o->type = SOLVER_OP_STOP_SET_PROPERTY; |
2023 | res = load_op_stop_set_property (o, cur, | 2070 | res = load_op_stop_set_property(o, cur, |
2024 | op_counter, sec_name, cfg); | 2071 | op_counter, sec_name, cfg); |
2025 | } | 2072 | } |
2026 | else if (0 == strcmp (op, "start_set_preference")) | 2073 | else if (0 == strcmp(op, "start_set_preference")) |
2027 | { | 2074 | { |
2028 | o->type = SOLVER_OP_START_SET_PREFERENCE; | 2075 | o->type = SOLVER_OP_START_SET_PREFERENCE; |
2029 | res = load_op_start_set_preference (o, cur, | 2076 | res = load_op_start_set_preference(o, cur, |
2030 | op_counter, sec_name, cfg); | 2077 | op_counter, sec_name, cfg); |
2031 | } | 2078 | } |
2032 | else if (0 == strcmp (op, "stop_set_preference")) | 2079 | else if (0 == strcmp(op, "stop_set_preference")) |
2033 | { | 2080 | { |
2034 | o->type = SOLVER_OP_STOP_SET_PREFERENCE; | 2081 | o->type = SOLVER_OP_STOP_SET_PREFERENCE; |
2035 | res = load_op_stop_set_preference (o, cur, | 2082 | res = load_op_stop_set_preference(o, cur, |
2036 | op_counter, sec_name, cfg); | 2083 | op_counter, sec_name, cfg); |
2037 | } | 2084 | } |
2038 | else if (0 == strcmp (op, "start_request")) | 2085 | else if (0 == strcmp(op, "start_request")) |
2039 | { | 2086 | { |
2040 | o->type = SOLVER_OP_START_REQUEST; | 2087 | o->type = SOLVER_OP_START_REQUEST; |
2041 | res = load_op_start_request (o, cur, | 2088 | res = load_op_start_request(o, cur, |
2042 | op_counter, sec_name, cfg); | 2089 | op_counter, sec_name, cfg); |
2043 | } | 2090 | } |
2044 | else if (0 == strcmp (op, "stop_request")) | 2091 | else if (0 == strcmp(op, "stop_request")) |
2045 | { | 2092 | { |
2046 | o->type = SOLVER_OP_STOP_REQUEST; | 2093 | o->type = SOLVER_OP_STOP_REQUEST; |
2047 | res = load_op_stop_request(o, cur, | 2094 | res = load_op_stop_request(o, cur, |
2048 | op_counter, sec_name, cfg); | 2095 | op_counter, sec_name, cfg); |
2049 | } | 2096 | } |
2050 | else | 2097 | else |
2051 | { | 2098 | { |
2052 | fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", | 2099 | fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", |
2053 | op_counter, op, cur->id); | 2100 | op_counter, op, cur->id); |
2054 | res = GNUNET_SYSERR; | 2101 | res = GNUNET_SYSERR; |
2055 | } | 2102 | } |
2056 | 2103 | ||
2057 | GNUNET_free (op); | 2104 | GNUNET_free(op); |
2058 | GNUNET_free (op_name); | 2105 | GNUNET_free(op_name); |
2059 | 2106 | ||
2060 | if (GNUNET_SYSERR == res) | 2107 | if (GNUNET_SYSERR == res) |
2061 | { | 2108 | { |
2062 | GNUNET_free (o); | 2109 | GNUNET_free(o); |
2063 | GNUNET_free (sec_name); | 2110 | GNUNET_free(sec_name); |
2064 | return GNUNET_SYSERR; | 2111 | return GNUNET_SYSERR; |
2065 | } | 2112 | } |
2066 | 2113 | ||
2067 | GNUNET_CONTAINER_DLL_insert_tail (cur->head,cur->tail, o); | 2114 | GNUNET_CONTAINER_DLL_insert_tail(cur->head, cur->tail, o); |
2068 | op_counter++; | 2115 | op_counter++; |
2069 | } | 2116 | } |
2070 | GNUNET_free (sec_name); | 2117 | GNUNET_free(sec_name); |
2071 | return GNUNET_OK; | 2118 | return GNUNET_OK; |
2072 | } | 2119 | } |
2073 | 2120 | ||
2074 | static int | 2121 | static int |
2075 | load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) | 2122 | load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) |
2076 | { | 2123 | { |
2077 | int e_counter = 0; | 2124 | int e_counter = 0; |
2078 | char *sec_name; | 2125 | char *sec_name; |
@@ -2083,87 +2130,87 @@ load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) | |||
2083 | e_counter = 0; | 2130 | e_counter = 0; |
2084 | last = NULL; | 2131 | last = NULL; |
2085 | while (1) | 2132 | while (1) |
2086 | { | ||
2087 | GNUNET_asprintf(&sec_name, "episode-%u", e_counter); | ||
2088 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, | ||
2089 | sec_name, "duration", &e_duration)) | ||
2090 | { | 2133 | { |
2091 | GNUNET_free (sec_name); | 2134 | GNUNET_asprintf(&sec_name, "episode-%u", e_counter); |
2092 | break; | 2135 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, |
2093 | } | 2136 | sec_name, "duration", &e_duration)) |
2137 | { | ||
2138 | GNUNET_free(sec_name); | ||
2139 | break; | ||
2140 | } | ||
2094 | 2141 | ||
2095 | cur = GNUNET_new (struct Episode); | 2142 | cur = GNUNET_new(struct Episode); |
2096 | cur->duration = e_duration; | 2143 | cur->duration = e_duration; |
2097 | cur->id = e_counter; | 2144 | cur->id = e_counter; |
2098 | 2145 | ||
2099 | if (GNUNET_OK != load_episode (e, cur, cfg)) | 2146 | if (GNUNET_OK != load_episode(e, cur, cfg)) |
2100 | { | 2147 | { |
2101 | GNUNET_free (sec_name); | 2148 | GNUNET_free(sec_name); |
2102 | GNUNET_free (cur); | 2149 | GNUNET_free(cur); |
2103 | return GNUNET_SYSERR; | 2150 | return GNUNET_SYSERR; |
2104 | } | 2151 | } |
2105 | 2152 | ||
2106 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n", | 2153 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n", |
2107 | e_counter, | 2154 | e_counter, |
2108 | GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); | 2155 | GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); |
2109 | 2156 | ||
2110 | /* Update experiment */ | 2157 | /* Update experiment */ |
2111 | e->num_episodes ++; | 2158 | e->num_episodes++; |
2112 | e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); | 2159 | e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); |
2113 | /* Put in linked list */ | 2160 | /* Put in linked list */ |
2114 | if (NULL == last) | 2161 | if (NULL == last) |
2115 | e->start = cur; | 2162 | e->start = cur; |
2116 | else | 2163 | else |
2117 | last->next = cur; | 2164 | last->next = cur; |
2118 | 2165 | ||
2119 | GNUNET_free (sec_name); | 2166 | GNUNET_free(sec_name); |
2120 | e_counter ++; | 2167 | e_counter++; |
2121 | last = cur; | 2168 | last = cur; |
2122 | } | 2169 | } |
2123 | return e_counter; | 2170 | return e_counter; |
2124 | } | 2171 | } |
2125 | 2172 | ||
2126 | 2173 | ||
2127 | static void | 2174 | static void |
2128 | timeout_experiment (void *cls) | 2175 | timeout_experiment(void *cls) |
2129 | { | 2176 | { |
2130 | struct Experiment *e = cls; | 2177 | struct Experiment *e = cls; |
2131 | 2178 | ||
2132 | e->experiment_timeout_task = NULL; | 2179 | e->experiment_timeout_task = NULL; |
2133 | fprintf (stderr, "Experiment timeout!\n"); | 2180 | fprintf(stderr, "Experiment timeout!\n"); |
2134 | 2181 | ||
2135 | if (NULL != e->episode_timeout_task) | 2182 | if (NULL != e->episode_timeout_task) |
2136 | { | 2183 | { |
2137 | GNUNET_SCHEDULER_cancel (e->episode_timeout_task); | 2184 | GNUNET_SCHEDULER_cancel(e->episode_timeout_task); |
2138 | e->episode_timeout_task = NULL; | 2185 | e->episode_timeout_task = NULL; |
2139 | } | 2186 | } |
2140 | 2187 | ||
2141 | e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), | 2188 | e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), |
2142 | GNUNET_SYSERR); | 2189 | GNUNET_SYSERR); |
2143 | } | 2190 | } |
2144 | 2191 | ||
2145 | struct ATS_Address * | 2192 | struct ATS_Address * |
2146 | create_ats_address (const struct GNUNET_PeerIdentity *peer, | 2193 | create_ats_address(const struct GNUNET_PeerIdentity *peer, |
2147 | const char *plugin_name, | 2194 | const char *plugin_name, |
2148 | const void *plugin_addr, | 2195 | const void *plugin_addr, |
2149 | size_t plugin_addr_len, | 2196 | size_t plugin_addr_len, |
2150 | uint32_t session_id, | 2197 | uint32_t session_id, |
2151 | uint32_t network) | 2198 | uint32_t network) |
2152 | { | 2199 | { |
2153 | struct ATS_Address *aa = NULL; | 2200 | struct ATS_Address *aa = NULL; |
2154 | 2201 | ||
2155 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1); | 2202 | aa = GNUNET_malloc(sizeof(struct ATS_Address) + plugin_addr_len + strlen(plugin_name) + 1); |
2156 | aa->atsi = GNUNET_new (struct GNUNET_ATS_Information); | 2203 | aa->atsi = GNUNET_new(struct GNUNET_ATS_Information); |
2157 | aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 2204 | aa->atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); |
2158 | aa->atsi[0].value = htonl (network); | 2205 | aa->atsi[0].value = htonl(network); |
2159 | aa->atsi_count = 1; | 2206 | aa->atsi_count = 1; |
2160 | 2207 | ||
2161 | aa->peer = *peer; | 2208 | aa->peer = *peer; |
2162 | aa->addr_len = plugin_addr_len; | 2209 | aa->addr_len = plugin_addr_len; |
2163 | aa->addr = &aa[1]; | 2210 | aa->addr = &aa[1]; |
2164 | aa->plugin = (char *) &aa[1] + plugin_addr_len; | 2211 | aa->plugin = (char *)&aa[1] + plugin_addr_len; |
2165 | GNUNET_memcpy (&aa[1], plugin_addr, plugin_addr_len); | 2212 | GNUNET_memcpy(&aa[1], plugin_addr, plugin_addr_len); |
2166 | GNUNET_memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1); | 2213 | GNUNET_memcpy(aa->plugin, plugin_name, strlen(plugin_name) + 1); |
2167 | aa->session_id = session_id; | 2214 | aa->session_id = session_id; |
2168 | 2215 | ||
2169 | return aa; | 2216 | return aa; |
@@ -2172,522 +2219,529 @@ create_ats_address (const struct GNUNET_PeerIdentity *peer, | |||
2172 | 2219 | ||
2173 | 2220 | ||
2174 | static void | 2221 | static void |
2175 | enforce_add_address (struct GNUNET_ATS_TEST_Operation *op) | 2222 | enforce_add_address(struct GNUNET_ATS_TEST_Operation *op) |
2176 | { | 2223 | { |
2177 | struct TestPeer *p; | 2224 | struct TestPeer *p; |
2178 | struct TestAddress *a; | 2225 | struct TestAddress *a; |
2179 | int c; | 2226 | int c; |
2180 | 2227 | ||
2181 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2228 | if (NULL == (p = find_peer_by_id(op->peer_id))) |
2182 | { | ||
2183 | p = GNUNET_new (struct TestPeer); | ||
2184 | p->id = op->peer_id; | ||
2185 | p->assigned_bw_in = 0; | ||
2186 | p->assigned_bw_out = 0; | ||
2187 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); | ||
2188 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | ||
2189 | { | 2229 | { |
2190 | p->pref_abs[c] = DEFAULT_ABS_PREFERENCE; | 2230 | p = GNUNET_new(struct TestPeer); |
2191 | p->pref_norm[c] = DEFAULT_REL_PREFERENCE; | 2231 | p->id = op->peer_id; |
2192 | } | 2232 | p->assigned_bw_in = 0; |
2233 | p->assigned_bw_out = 0; | ||
2234 | memset(&p->peer_id, op->peer_id, sizeof(p->peer_id)); | ||
2235 | for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) | ||
2236 | { | ||
2237 | p->pref_abs[c] = DEFAULT_ABS_PREFERENCE; | ||
2238 | p->pref_norm[c] = DEFAULT_REL_PREFERENCE; | ||
2239 | } | ||
2193 | 2240 | ||
2194 | GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p); | 2241 | GNUNET_CONTAINER_DLL_insert(peer_head, peer_tail, p); |
2195 | } | 2242 | } |
2196 | 2243 | ||
2197 | if (NULL != (find_address_by_id (p, op->address_id))) | 2244 | if (NULL != (find_address_by_id(p, op->address_id))) |
2198 | { | 2245 | { |
2199 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n", | 2246 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n", |
2200 | op->address_id, op->peer_id); | 2247 | op->address_id, op->peer_id); |
2201 | return; | 2248 | return; |
2202 | } | 2249 | } |
2203 | 2250 | ||
2204 | a = GNUNET_new (struct TestAddress); | 2251 | a = GNUNET_new(struct TestAddress); |
2205 | a->aid = op->address_id; | 2252 | a->aid = op->address_id; |
2206 | a->network = op->address_network; | 2253 | a->network = op->address_network; |
2207 | a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address, | 2254 | a->ats_addr = create_ats_address(&p->peer_id, op->plugin, op->address, |
2208 | strlen (op->address) + 1, op->address_session, op->address_network); | 2255 | strlen(op->address) + 1, op->address_session, op->address_network); |
2209 | memset (&p->peer_id, op->peer_id, sizeof (p->peer_id)); | 2256 | memset(&p->peer_id, op->peer_id, sizeof(p->peer_id)); |
2210 | GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a); | 2257 | GNUNET_CONTAINER_DLL_insert_tail(p->addr_head, p->addr_tail, a); |
2211 | 2258 | ||
2212 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | 2259 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) |
2213 | a->prop_norm[c] = DEFAULT_REL_QUALITY; | 2260 | a->prop_norm[c] = DEFAULT_REL_QUALITY; |
2214 | 2261 | ||
2215 | GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr, | 2262 | GNUNET_CONTAINER_multipeermap_put(sh->addresses, &p->peer_id, a->ats_addr, |
2216 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2263 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2217 | |||
2218 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n", | ||
2219 | op->address_id, op->peer_id, GNUNET_NT_to_string(a->network)); | ||
2220 | 2264 | ||
2221 | sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network); | 2265 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n", |
2266 | op->address_id, op->peer_id, GNUNET_NT_to_string(a->network)); | ||
2222 | 2267 | ||
2268 | sh->sf->s_add(sh->sf->cls, a->ats_addr, op->address_network); | ||
2223 | } | 2269 | } |
2224 | 2270 | ||
2225 | 2271 | ||
2226 | static void | 2272 | static void |
2227 | enforce_del_address (struct GNUNET_ATS_TEST_Operation *op) | 2273 | enforce_del_address(struct GNUNET_ATS_TEST_Operation *op) |
2228 | { | 2274 | { |
2229 | struct TestPeer *p; | 2275 | struct TestPeer *p; |
2230 | struct TestAddress *a; | 2276 | struct TestAddress *a; |
2231 | struct PropertyGenerator *pg; | 2277 | struct PropertyGenerator *pg; |
2232 | 2278 | ||
2233 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2279 | if (NULL == (p = find_peer_by_id(op->peer_id))) |
2234 | { | 2280 | { |
2235 | GNUNET_break (0); | 2281 | GNUNET_break(0); |
2236 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2282 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2237 | "Deleting address for unknown peer %u\n", op->peer_id); | 2283 | "Deleting address for unknown peer %u\n", op->peer_id); |
2238 | return; | 2284 | return; |
2239 | } | 2285 | } |
2240 | 2286 | ||
2241 | if (NULL == (a =find_address_by_id (p, op->address_id))) | 2287 | if (NULL == (a = find_address_by_id(p, op->address_id))) |
2242 | { | 2288 | { |
2243 | GNUNET_break (0); | 2289 | GNUNET_break(0); |
2244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2290 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2245 | "Deleting address for unknown peer %u\n", op->peer_id); | 2291 | "Deleting address for unknown peer %u\n", op->peer_id); |
2246 | return; | 2292 | return; |
2247 | } | 2293 | } |
2248 | 2294 | ||
2249 | while (NULL != (pg = find_prop_gen (p->id, a->aid, 0))) | 2295 | while (NULL != (pg = find_prop_gen(p->id, a->aid, 0))) |
2250 | { | 2296 | { |
2251 | GNUNET_ATS_solver_generate_property_stop (pg); | 2297 | GNUNET_ATS_solver_generate_property_stop(pg); |
2252 | } | 2298 | } |
2253 | 2299 | ||
2254 | GNUNET_assert (GNUNET_YES == | 2300 | GNUNET_assert(GNUNET_YES == |
2255 | GNUNET_CONTAINER_multipeermap_remove (sh->addresses, | 2301 | GNUNET_CONTAINER_multipeermap_remove(sh->addresses, |
2256 | &p->peer_id, | 2302 | &p->peer_id, |
2257 | a->ats_addr)); | 2303 | a->ats_addr)); |
2258 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2304 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2259 | "Removing address %u for peer %u\n", | 2305 | "Removing address %u for peer %u\n", |
2260 | op->address_id, | 2306 | op->address_id, |
2261 | op->peer_id); | 2307 | op->peer_id); |
2262 | 2308 | ||
2263 | sh->sf->s_del (sh->sf->cls, a->ats_addr); | 2309 | sh->sf->s_del(sh->sf->cls, a->ats_addr); |
2264 | 2310 | ||
2265 | if (NULL != l) | 2311 | if (NULL != l) |
2266 | { | 2312 | { |
2267 | GNUNET_ATS_solver_logging_now (l); | 2313 | GNUNET_ATS_solver_logging_now(l); |
2268 | } | 2314 | } |
2269 | GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a); | 2315 | GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a); |
2270 | 2316 | ||
2271 | GNUNET_free_non_null(a->ats_addr->atsi); | 2317 | GNUNET_free_non_null(a->ats_addr->atsi); |
2272 | GNUNET_free (a->ats_addr); | 2318 | GNUNET_free(a->ats_addr); |
2273 | GNUNET_free (a); | 2319 | GNUNET_free(a); |
2274 | |||
2275 | } | 2320 | } |
2276 | 2321 | ||
2277 | static void | 2322 | static void |
2278 | enforce_start_property (struct GNUNET_ATS_TEST_Operation *op) | 2323 | enforce_start_property(struct GNUNET_ATS_TEST_Operation *op) |
2279 | { | 2324 | { |
2280 | struct PropertyGenerator *pg; | 2325 | struct PropertyGenerator *pg; |
2281 | struct TestPeer *p; | 2326 | struct TestPeer *p; |
2282 | struct TestAddress *a; | 2327 | struct TestAddress *a; |
2283 | 2328 | ||
2284 | if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type))) | 2329 | if (NULL != (pg = find_prop_gen(op->peer_id, op->address_id, op->prop_type))) |
2285 | { | 2330 | { |
2286 | GNUNET_ATS_solver_generate_property_stop (pg); | 2331 | GNUNET_ATS_solver_generate_property_stop(pg); |
2287 | GNUNET_free (pg); | 2332 | GNUNET_free(pg); |
2288 | } | 2333 | } |
2289 | 2334 | ||
2290 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2335 | if (NULL == (p = find_peer_by_id(op->peer_id))) |
2291 | { | 2336 | { |
2292 | GNUNET_break (0); | 2337 | GNUNET_break(0); |
2293 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2338 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2294 | "Starting property generation for unknown peer %u\n", op->peer_id); | 2339 | "Starting property generation for unknown peer %u\n", op->peer_id); |
2295 | return; | 2340 | return; |
2296 | } | 2341 | } |
2297 | 2342 | ||
2298 | if (NULL == (a = find_address_by_id (p, op->address_id))) | 2343 | if (NULL == (a = find_address_by_id(p, op->address_id))) |
2299 | { | 2344 | { |
2300 | GNUNET_break (0); | 2345 | GNUNET_break(0); |
2301 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2346 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2302 | "Setting property for unknown address %u\n", op->peer_id); | 2347 | "Setting property for unknown address %u\n", op->peer_id); |
2303 | return; | 2348 | return; |
2304 | } | 2349 | } |
2305 | 2350 | ||
2306 | GNUNET_ATS_solver_generate_property_start (op->peer_id, | 2351 | GNUNET_ATS_solver_generate_property_start(op->peer_id, |
2307 | op->address_id, | 2352 | op->address_id, |
2308 | p, a, | 2353 | p, a, |
2309 | op->gen_type, | 2354 | op->gen_type, |
2310 | op->base_rate, | 2355 | op->base_rate, |
2311 | op->max_rate, | 2356 | op->max_rate, |
2312 | op->period, | 2357 | op->period, |
2313 | op->frequency, | 2358 | op->frequency, |
2314 | op->prop_type); | 2359 | op->prop_type); |
2315 | } | 2360 | } |
2316 | 2361 | ||
2317 | static void | 2362 | static void |
2318 | enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op) | 2363 | enforce_stop_property(struct GNUNET_ATS_TEST_Operation *op) |
2319 | { | 2364 | { |
2320 | struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id, | 2365 | struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id, |
2321 | op->prop_type); | 2366 | op->prop_type); |
2367 | |||
2322 | if (NULL != pg) | 2368 | if (NULL != pg) |
2323 | { | 2369 | { |
2324 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2370 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2325 | "Stopping preference generation for peer %u address %u\n", op->peer_id, | 2371 | "Stopping preference generation for peer %u address %u\n", op->peer_id, |
2326 | op->address_id); | 2372 | op->address_id); |
2327 | GNUNET_ATS_solver_generate_property_stop (pg); | 2373 | GNUNET_ATS_solver_generate_property_stop(pg); |
2328 | } | 2374 | } |
2329 | else | 2375 | else |
2330 | { | 2376 | { |
2331 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2377 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2332 | "Cannot find preference generator for peer %u address %u\n", | 2378 | "Cannot find preference generator for peer %u address %u\n", |
2333 | op->peer_id, op->address_id); | 2379 | op->peer_id, op->address_id); |
2334 | GNUNET_break (0); | 2380 | GNUNET_break(0); |
2335 | } | 2381 | } |
2336 | } | 2382 | } |
2337 | 2383 | ||
2338 | static void | 2384 | static void |
2339 | enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) | 2385 | enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) |
2340 | { | 2386 | { |
2341 | struct PreferenceGenerator *pg; | 2387 | struct PreferenceGenerator *pg; |
2342 | if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type))) | ||
2343 | { | ||
2344 | GNUNET_ATS_solver_generate_preferences_stop (pg); | ||
2345 | GNUNET_free (pg); | ||
2346 | } | ||
2347 | 2388 | ||
2348 | if (NULL == (find_peer_by_id (op->peer_id))) | 2389 | if (NULL != (pg = find_pref_gen(op->peer_id, op->pref_type))) |
2349 | { | 2390 | { |
2350 | GNUNET_break (0); | 2391 | GNUNET_ATS_solver_generate_preferences_stop(pg); |
2351 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2392 | GNUNET_free(pg); |
2352 | "Starting preference generation for unknown peer %u\n", op->peer_id); | 2393 | } |
2353 | return; | 2394 | |
2354 | } | 2395 | if (NULL == (find_peer_by_id(op->peer_id))) |
2396 | { | ||
2397 | GNUNET_break(0); | ||
2398 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2399 | "Starting preference generation for unknown peer %u\n", op->peer_id); | ||
2400 | return; | ||
2401 | } | ||
2355 | 2402 | ||
2356 | GNUNET_ATS_solver_generate_preferences_start (op->peer_id, | 2403 | GNUNET_ATS_solver_generate_preferences_start(op->peer_id, |
2357 | op->address_id, | 2404 | op->address_id, |
2358 | op->client_id, | 2405 | op->client_id, |
2359 | op->gen_type, | 2406 | op->gen_type, |
2360 | op->base_rate, | 2407 | op->base_rate, |
2361 | op->max_rate, | 2408 | op->max_rate, |
2362 | op->period, | 2409 | op->period, |
2363 | op->frequency, | 2410 | op->frequency, |
2364 | op->pref_type, | 2411 | op->pref_type, |
2365 | op->frequency); | 2412 | op->frequency); |
2366 | } | 2413 | } |
2367 | 2414 | ||
2368 | static void | 2415 | static void |
2369 | enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op) | 2416 | enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) |
2370 | { | 2417 | { |
2371 | struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, | 2418 | struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, |
2372 | op->pref_type); | 2419 | op->pref_type); |
2420 | |||
2373 | if (NULL != pg) | 2421 | if (NULL != pg) |
2374 | { | 2422 | { |
2375 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 2423 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2376 | "Stopping property generation for peer %u address %u\n", op->peer_id, | 2424 | "Stopping property generation for peer %u address %u\n", op->peer_id, |
2377 | op->address_id); | 2425 | op->address_id); |
2378 | GNUNET_ATS_solver_generate_preferences_stop (pg); | 2426 | GNUNET_ATS_solver_generate_preferences_stop(pg); |
2379 | } | 2427 | } |
2380 | else | 2428 | else |
2381 | { | 2429 | { |
2382 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2430 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2383 | "Cannot find preference generator for peer %u address %u\n", | 2431 | "Cannot find preference generator for peer %u address %u\n", |
2384 | op->peer_id, op->address_id); | 2432 | op->peer_id, op->address_id); |
2385 | GNUNET_break (0); | 2433 | GNUNET_break(0); |
2386 | } | 2434 | } |
2387 | } | 2435 | } |
2388 | 2436 | ||
2389 | 2437 | ||
2390 | static void | 2438 | static void |
2391 | enforce_start_request (struct GNUNET_ATS_TEST_Operation *op) | 2439 | enforce_start_request(struct GNUNET_ATS_TEST_Operation *op) |
2392 | { | 2440 | { |
2393 | struct TestPeer *p; | 2441 | struct TestPeer *p; |
2394 | 2442 | ||
2395 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2443 | if (NULL == (p = find_peer_by_id(op->peer_id))) |
2396 | { | 2444 | { |
2397 | GNUNET_break (0); | 2445 | GNUNET_break(0); |
2398 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2446 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2399 | "Requesting address for unknown peer %u\n", op->peer_id); | 2447 | "Requesting address for unknown peer %u\n", op->peer_id); |
2400 | return; | 2448 | return; |
2401 | } | 2449 | } |
2402 | 2450 | ||
2403 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n", | 2451 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n", |
2404 | op->peer_id); | 2452 | op->peer_id); |
2405 | p->is_requested = GNUNET_YES; | 2453 | p->is_requested = GNUNET_YES; |
2406 | 2454 | ||
2407 | sh->sf->s_get (sh->sf->cls, &p->peer_id); | 2455 | sh->sf->s_get(sh->sf->cls, &p->peer_id); |
2408 | } | 2456 | } |
2409 | 2457 | ||
2410 | 2458 | ||
2411 | static void | 2459 | static void |
2412 | enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op) | 2460 | enforce_stop_request(struct GNUNET_ATS_TEST_Operation *op) |
2413 | { | 2461 | { |
2414 | struct TestPeer *p; | 2462 | struct TestPeer *p; |
2415 | 2463 | ||
2416 | if (NULL == (p = find_peer_by_id (op->peer_id))) | 2464 | if (NULL == (p = find_peer_by_id(op->peer_id))) |
2417 | { | 2465 | { |
2418 | GNUNET_break (0); | 2466 | GNUNET_break(0); |
2419 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2467 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
2420 | "Requesting address for unknown peer %u\n", op->peer_id); | 2468 | "Requesting address for unknown peer %u\n", op->peer_id); |
2421 | return; | 2469 | return; |
2422 | } | 2470 | } |
2423 | 2471 | ||
2424 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 2472 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2425 | "Stop requesting address for peer %u\n", | 2473 | "Stop requesting address for peer %u\n", |
2426 | op->peer_id); | 2474 | op->peer_id); |
2427 | p->is_requested = GNUNET_NO; | 2475 | p->is_requested = GNUNET_NO; |
2428 | p->assigned_bw_in = 0; | 2476 | p->assigned_bw_in = 0; |
2429 | p->assigned_bw_out = 0; | 2477 | p->assigned_bw_out = 0; |
2430 | sh->sf->s_get_stop (sh->sf->cls, &p->peer_id); | 2478 | sh->sf->s_get_stop(sh->sf->cls, &p->peer_id); |
2431 | 2479 | ||
2432 | if (NULL != l) | 2480 | if (NULL != l) |
2433 | { | 2481 | { |
2434 | GNUNET_ATS_solver_logging_now (l); | 2482 | GNUNET_ATS_solver_logging_now(l); |
2435 | } | 2483 | } |
2436 | |||
2437 | } | 2484 | } |
2438 | 2485 | ||
2439 | static void enforce_episode (struct Episode *ep) | 2486 | static void enforce_episode(struct Episode *ep) |
2440 | { | 2487 | { |
2441 | struct GNUNET_ATS_TEST_Operation *cur; | 2488 | struct GNUNET_ATS_TEST_Operation *cur; |
2489 | |||
2442 | for (cur = ep->head; NULL != cur; cur = cur->next) | 2490 | for (cur = ep->head; NULL != cur; cur = cur->next) |
2443 | { | 2491 | { |
2444 | switch (cur->type) { | 2492 | switch (cur->type) |
2445 | case SOLVER_OP_ADD_ADDRESS: | 2493 | { |
2446 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n", | 2494 | case SOLVER_OP_ADD_ADDRESS: |
2447 | print_op (cur->type), cur->peer_id, cur->address_id); | 2495 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu]\n", |
2448 | enforce_add_address (cur); | 2496 | print_op(cur->type), cur->peer_id, cur->address_id); |
2449 | break; | 2497 | enforce_add_address(cur); |
2450 | case SOLVER_OP_DEL_ADDRESS: | 2498 | break; |
2451 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n", | 2499 | |
2452 | print_op (cur->type), cur->peer_id, cur->address_id); | 2500 | case SOLVER_OP_DEL_ADDRESS: |
2453 | enforce_del_address (cur); | 2501 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu]\n", |
2454 | break; | 2502 | print_op(cur->type), cur->peer_id, cur->address_id); |
2455 | case SOLVER_OP_START_SET_PROPERTY: | 2503 | enforce_del_address(cur); |
2456 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", | 2504 | break; |
2457 | print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate); | 2505 | |
2458 | enforce_start_property (cur); | 2506 | case SOLVER_OP_START_SET_PROPERTY: |
2459 | break; | 2507 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", |
2460 | case SOLVER_OP_STOP_SET_PROPERTY: | 2508 | print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); |
2461 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", | 2509 | enforce_start_property(cur); |
2462 | print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate); | 2510 | break; |
2463 | enforce_stop_property (cur); | 2511 | |
2464 | break; | 2512 | case SOLVER_OP_STOP_SET_PROPERTY: |
2465 | case SOLVER_OP_START_SET_PREFERENCE: | 2513 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", |
2466 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", | 2514 | print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); |
2467 | print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate); | 2515 | enforce_stop_property(cur); |
2468 | enforce_start_preference (cur); | 2516 | break; |
2469 | break; | 2517 | |
2470 | case SOLVER_OP_STOP_SET_PREFERENCE: | 2518 | case SOLVER_OP_START_SET_PREFERENCE: |
2471 | fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", | 2519 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", |
2472 | print_op (cur->type), cur->peer_id, cur->address_id, cur->base_rate); | 2520 | print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); |
2473 | enforce_stop_preference (cur); | 2521 | enforce_start_preference(cur); |
2474 | break; | 2522 | break; |
2475 | case SOLVER_OP_START_REQUEST: | 2523 | |
2476 | fprintf (stderr, "Enforcing operation: %s [%llu]\n", | 2524 | case SOLVER_OP_STOP_SET_PREFERENCE: |
2477 | print_op (cur->type), cur->peer_id); | 2525 | fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", |
2478 | enforce_start_request (cur); | 2526 | print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); |
2479 | break; | 2527 | enforce_stop_preference(cur); |
2480 | case SOLVER_OP_STOP_REQUEST: | 2528 | break; |
2481 | fprintf (stderr, "Enforcing operation: %s [%llu]\n", | 2529 | |
2482 | print_op (cur->type), cur->peer_id); | 2530 | case SOLVER_OP_START_REQUEST: |
2483 | enforce_stop_request (cur); | 2531 | fprintf(stderr, "Enforcing operation: %s [%llu]\n", |
2484 | break; | 2532 | print_op(cur->type), cur->peer_id); |
2485 | default: | 2533 | enforce_start_request(cur); |
2486 | break; | 2534 | break; |
2487 | } | 2535 | |
2488 | } | 2536 | case SOLVER_OP_STOP_REQUEST: |
2537 | fprintf(stderr, "Enforcing operation: %s [%llu]\n", | ||
2538 | print_op(cur->type), cur->peer_id); | ||
2539 | enforce_stop_request(cur); | ||
2540 | break; | ||
2541 | |||
2542 | default: | ||
2543 | break; | ||
2544 | } | ||
2545 | } | ||
2489 | } | 2546 | } |
2490 | 2547 | ||
2491 | 2548 | ||
2492 | static void | 2549 | static void |
2493 | timeout_episode (void *cls) | 2550 | timeout_episode(void *cls) |
2494 | { | 2551 | { |
2495 | struct Experiment *e = cls; | 2552 | struct Experiment *e = cls; |
2496 | 2553 | ||
2497 | e->episode_timeout_task = NULL; | 2554 | e->episode_timeout_task = NULL; |
2498 | if (NULL != e->ep_done_cb) | 2555 | if (NULL != e->ep_done_cb) |
2499 | e->ep_done_cb (e->cur); | 2556 | e->ep_done_cb(e->cur); |
2500 | 2557 | ||
2501 | /* Scheduling next */ | 2558 | /* Scheduling next */ |
2502 | e->cur = e->cur->next; | 2559 | e->cur = e->cur->next; |
2503 | if (NULL == e->cur) | 2560 | if (NULL == e->cur) |
2504 | { | ||
2505 | /* done */ | ||
2506 | fprintf (stderr, "Last episode done!\n"); | ||
2507 | if (NULL != e->experiment_timeout_task) | ||
2508 | { | 2561 | { |
2509 | GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); | 2562 | /* done */ |
2510 | e->experiment_timeout_task = NULL; | 2563 | fprintf(stderr, "Last episode done!\n"); |
2564 | if (NULL != e->experiment_timeout_task) | ||
2565 | { | ||
2566 | GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); | ||
2567 | e->experiment_timeout_task = NULL; | ||
2568 | } | ||
2569 | e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK); | ||
2570 | return; | ||
2511 | } | 2571 | } |
2512 | e->e_done_cb (e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK); | ||
2513 | return; | ||
2514 | } | ||
2515 | 2572 | ||
2516 | fprintf (stderr, "Running episode %u with timeout %s\n", | 2573 | fprintf(stderr, "Running episode %u with timeout %s\n", |
2517 | e->cur->id, | 2574 | e->cur->id, |
2518 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); | 2575 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); |
2519 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, | 2576 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, |
2520 | &timeout_episode, e); | 2577 | &timeout_episode, e); |
2521 | enforce_episode(e->cur); | 2578 | enforce_episode(e->cur); |
2522 | |||
2523 | |||
2524 | } | 2579 | } |
2525 | 2580 | ||
2526 | 2581 | ||
2527 | void | 2582 | void |
2528 | GNUNET_ATS_solvers_experimentation_run (struct Experiment *e, | 2583 | GNUNET_ATS_solvers_experimentation_run(struct Experiment *e, |
2529 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, | 2584 | GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, |
2530 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) | 2585 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) |
2531 | { | 2586 | { |
2532 | fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name, | 2587 | fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, |
2533 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); | 2588 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); |
2534 | e->e_done_cb = e_done_cb; | 2589 | e->e_done_cb = e_done_cb; |
2535 | e->ep_done_cb = ep_done_cb; | 2590 | e->ep_done_cb = ep_done_cb; |
2536 | e->start_time = GNUNET_TIME_absolute_get(); | 2591 | e->start_time = GNUNET_TIME_absolute_get(); |
2537 | 2592 | ||
2538 | /* Start total time out */ | 2593 | /* Start total time out */ |
2539 | e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration, | 2594 | e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, |
2540 | &timeout_experiment, e); | 2595 | &timeout_experiment, e); |
2541 | 2596 | ||
2542 | /* Start */ | 2597 | /* Start */ |
2543 | if (NULL == e->start) | 2598 | if (NULL == e->start) |
2544 | { | 2599 | { |
2545 | GNUNET_break (0); | 2600 | GNUNET_break(0); |
2546 | return; | 2601 | return; |
2547 | } | 2602 | } |
2548 | 2603 | ||
2549 | e->cur = e->start; | 2604 | e->cur = e->start; |
2550 | fprintf (stderr, "Running episode %u with timeout %s\n", | 2605 | fprintf(stderr, "Running episode %u with timeout %s\n", |
2551 | e->cur->id, | 2606 | e->cur->id, |
2552 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); | 2607 | GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); |
2553 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, | 2608 | e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, |
2554 | &timeout_episode, e); | 2609 | &timeout_episode, e); |
2555 | enforce_episode(e->cur); | 2610 | enforce_episode(e->cur); |
2556 | |||
2557 | } | 2611 | } |
2558 | 2612 | ||
2559 | void | 2613 | void |
2560 | GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e) | 2614 | GNUNET_ATS_solvers_experimentation_stop(struct Experiment *e) |
2561 | { | 2615 | { |
2562 | if (NULL != e->experiment_timeout_task) | 2616 | if (NULL != e->experiment_timeout_task) |
2563 | { | 2617 | { |
2564 | GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); | 2618 | GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); |
2565 | e->experiment_timeout_task = NULL; | 2619 | e->experiment_timeout_task = NULL; |
2566 | } | 2620 | } |
2567 | if (NULL != e->episode_timeout_task) | 2621 | if (NULL != e->episode_timeout_task) |
2568 | { | 2622 | { |
2569 | GNUNET_SCHEDULER_cancel (e->episode_timeout_task); | 2623 | GNUNET_SCHEDULER_cancel(e->episode_timeout_task); |
2570 | e->episode_timeout_task = NULL; | 2624 | e->episode_timeout_task = NULL; |
2571 | } | 2625 | } |
2572 | if (NULL != e->cfg) | 2626 | if (NULL != e->cfg) |
2573 | { | 2627 | { |
2574 | GNUNET_CONFIGURATION_destroy(e->cfg); | 2628 | GNUNET_CONFIGURATION_destroy(e->cfg); |
2575 | e->cfg = NULL; | 2629 | e->cfg = NULL; |
2576 | } | 2630 | } |
2577 | free_experiment (e); | 2631 | free_experiment(e); |
2578 | } | 2632 | } |
2579 | 2633 | ||
2580 | 2634 | ||
2581 | struct Experiment * | 2635 | struct Experiment * |
2582 | GNUNET_ATS_solvers_experimentation_load (char *filename) | 2636 | GNUNET_ATS_solvers_experimentation_load(char *filename) |
2583 | { | 2637 | { |
2584 | struct Experiment *e; | 2638 | struct Experiment *e; |
2585 | struct GNUNET_CONFIGURATION_Handle *cfg; | 2639 | struct GNUNET_CONFIGURATION_Handle *cfg; |
2640 | |||
2586 | e = NULL; | 2641 | e = NULL; |
2587 | 2642 | ||
2588 | cfg = GNUNET_CONFIGURATION_create(); | 2643 | cfg = GNUNET_CONFIGURATION_create(); |
2589 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename)) | 2644 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) |
2590 | { | 2645 | { |
2591 | fprintf (stderr, "Failed to load `%s'\n", filename); | 2646 | fprintf(stderr, "Failed to load `%s'\n", filename); |
2592 | GNUNET_CONFIGURATION_destroy (cfg); | 2647 | GNUNET_CONFIGURATION_destroy(cfg); |
2593 | return NULL; | 2648 | return NULL; |
2594 | } | 2649 | } |
2595 | 2650 | ||
2596 | e = create_experiment (); | 2651 | e = create_experiment(); |
2597 | 2652 | ||
2598 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", | 2653 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", |
2599 | "name", &e->name)) | 2654 | "name", &e->name)) |
2600 | { | 2655 | { |
2601 | fprintf (stderr, "Invalid %s \n", "name"); | 2656 | fprintf(stderr, "Invalid %s \n", "name"); |
2602 | free_experiment (e); | 2657 | free_experiment(e); |
2603 | return NULL; | 2658 | return NULL; |
2604 | } | 2659 | } |
2605 | else | 2660 | else |
2606 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name); | 2661 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name); |
2607 | 2662 | ||
2608 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", | 2663 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", |
2609 | "log_prefix", &e->log_prefix)) | 2664 | "log_prefix", &e->log_prefix)) |
2610 | { | 2665 | { |
2611 | fprintf (stderr, "Invalid %s \n", "log_prefix"); | 2666 | fprintf(stderr, "Invalid %s \n", "log_prefix"); |
2612 | free_experiment (e); | 2667 | free_experiment(e); |
2613 | return NULL; | 2668 | return NULL; |
2614 | } | 2669 | } |
2615 | else | 2670 | else |
2616 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n", | 2671 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n", |
2617 | e->log_prefix); | 2672 | e->log_prefix); |
2618 | 2673 | ||
2619 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment", | 2674 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", |
2620 | "log_output_dir", &e->log_output_dir)) | 2675 | "log_output_dir", &e->log_output_dir)) |
2621 | { | 2676 | { |
2622 | e->log_output_dir = NULL; | 2677 | e->log_output_dir = NULL; |
2623 | } | 2678 | } |
2624 | else | 2679 | else |
2625 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n", | 2680 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n", |
2626 | e->log_output_dir); | 2681 | e->log_output_dir); |
2627 | 2682 | ||
2628 | 2683 | ||
2629 | if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 2684 | if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
2630 | "experiment", "log_append_time_stamp"))) | 2685 | "experiment", "log_append_time_stamp"))) |
2631 | e->log_append_time_stamp = GNUNET_YES; | 2686 | e->log_append_time_stamp = GNUNET_YES; |
2632 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n", | 2687 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n", |
2633 | (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no"); | 2688 | (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no"); |
2634 | 2689 | ||
2635 | 2690 | ||
2636 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, "experiment", | 2691 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", |
2637 | "cfg_file", &e->cfg_file)) | 2692 | "cfg_file", &e->cfg_file)) |
2638 | { | ||
2639 | fprintf (stderr, "Invalid %s \n", "cfg_file"); | ||
2640 | free_experiment (e); | ||
2641 | return NULL; | ||
2642 | } | ||
2643 | else | ||
2644 | { | ||
2645 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file); | ||
2646 | e->cfg = GNUNET_CONFIGURATION_create(); | ||
2647 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file)) | ||
2648 | { | 2693 | { |
2649 | fprintf (stderr, "Invalid configuration %s \n", "cfg_file"); | 2694 | fprintf(stderr, "Invalid %s \n", "cfg_file"); |
2650 | free_experiment (e); | 2695 | free_experiment(e); |
2651 | return NULL; | 2696 | return NULL; |
2652 | } | 2697 | } |
2653 | 2698 | else | |
2654 | } | 2699 | { |
2700 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file); | ||
2701 | e->cfg = GNUNET_CONFIGURATION_create(); | ||
2702 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(e->cfg, e->cfg_file)) | ||
2703 | { | ||
2704 | fprintf(stderr, "Invalid configuration %s \n", "cfg_file"); | ||
2705 | free_experiment(e); | ||
2706 | return NULL; | ||
2707 | } | ||
2708 | } | ||
2655 | 2709 | ||
2656 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", | 2710 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", |
2657 | "log_freq", &e->log_freq)) | 2711 | "log_freq", &e->log_freq)) |
2658 | { | 2712 | { |
2659 | fprintf (stderr, "Invalid %s \n", "log_freq"); | 2713 | fprintf(stderr, "Invalid %s \n", "log_freq"); |
2660 | free_experiment (e); | 2714 | free_experiment(e); |
2661 | return NULL; | 2715 | return NULL; |
2662 | } | 2716 | } |
2663 | else | 2717 | else |
2664 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n", | 2718 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n", |
2665 | GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES)); | 2719 | GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); |
2666 | 2720 | ||
2667 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", | 2721 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", |
2668 | "max_duration", &e->max_duration)) | 2722 | "max_duration", &e->max_duration)) |
2669 | { | 2723 | { |
2670 | fprintf (stderr, "Invalid %s", "max_duration"); | 2724 | fprintf(stderr, "Invalid %s", "max_duration"); |
2671 | free_experiment (e); | 2725 | free_experiment(e); |
2672 | return NULL; | 2726 | return NULL; |
2673 | } | 2727 | } |
2674 | else | 2728 | else |
2675 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n", | 2729 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n", |
2676 | GNUNET_STRINGS_relative_time_to_string (e->max_duration, GNUNET_YES)); | 2730 | GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); |
2677 | 2731 | ||
2678 | if (GNUNET_SYSERR == load_episodes (e, cfg)) | 2732 | if (GNUNET_SYSERR == load_episodes(e, cfg)) |
2679 | { | 2733 | { |
2680 | GNUNET_ATS_solvers_experimentation_stop (e); | 2734 | GNUNET_ATS_solvers_experimentation_stop(e); |
2681 | GNUNET_CONFIGURATION_destroy (cfg); | 2735 | GNUNET_CONFIGURATION_destroy(cfg); |
2682 | e = NULL; | 2736 | e = NULL; |
2683 | fprintf (stderr, "Failed to load experiment\n"); | 2737 | fprintf(stderr, "Failed to load experiment\n"); |
2684 | return NULL; | 2738 | return NULL; |
2685 | } | 2739 | } |
2686 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n", | 2740 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n", |
2687 | e->num_episodes, | 2741 | e->num_episodes, |
2688 | GNUNET_STRINGS_relative_time_to_string (e->total_duration, GNUNET_YES)); | 2742 | GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); |
2689 | 2743 | ||
2690 | GNUNET_CONFIGURATION_destroy (cfg); | 2744 | GNUNET_CONFIGURATION_destroy(cfg); |
2691 | return e; | 2745 | return e; |
2692 | } | 2746 | } |
2693 | 2747 | ||
@@ -2698,33 +2752,34 @@ GNUNET_ATS_solvers_experimentation_load (char *filename) | |||
2698 | */ | 2752 | */ |
2699 | 2753 | ||
2700 | static int | 2754 | static int |
2701 | free_all_it (void *cls, | 2755 | free_all_it(void *cls, |
2702 | const struct GNUNET_PeerIdentity *key, | 2756 | const struct GNUNET_PeerIdentity *key, |
2703 | void *value) | 2757 | void *value) |
2704 | { | 2758 | { |
2705 | struct ATS_Address *address = value; | 2759 | struct ATS_Address *address = value; |
2706 | GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (sh->env.addresses, | 2760 | |
2707 | key, value)); | 2761 | GNUNET_break(GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove(sh->env.addresses, |
2708 | GNUNET_free (address); | 2762 | key, value)); |
2763 | GNUNET_free(address); | ||
2709 | 2764 | ||
2710 | return GNUNET_OK; | 2765 | return GNUNET_OK; |
2711 | } | 2766 | } |
2712 | 2767 | ||
2713 | void | 2768 | void |
2714 | GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh) | 2769 | GNUNET_ATS_solvers_solver_stop(struct SolverHandle *sh) |
2715 | { | 2770 | { |
2716 | GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats, | 2771 | GNUNET_STATISTICS_destroy((struct GNUNET_STATISTICS_Handle *)sh->env.stats, |
2717 | GNUNET_NO); | 2772 | GNUNET_NO); |
2718 | GNUNET_PLUGIN_unload (sh->plugin, sh->sf); | 2773 | GNUNET_PLUGIN_unload(sh->plugin, sh->sf); |
2719 | sh->sf = NULL; | 2774 | sh->sf = NULL; |
2720 | GAS_normalization_stop(); | 2775 | GAS_normalization_stop(); |
2721 | 2776 | ||
2722 | GNUNET_CONTAINER_multipeermap_iterate (sh->addresses, | 2777 | GNUNET_CONTAINER_multipeermap_iterate(sh->addresses, |
2723 | &free_all_it, | 2778 | &free_all_it, |
2724 | NULL); | 2779 | NULL); |
2725 | GNUNET_CONTAINER_multipeermap_destroy(sh->addresses); | 2780 | GNUNET_CONTAINER_multipeermap_destroy(sh->addresses); |
2726 | GNUNET_free (sh->plugin); | 2781 | GNUNET_free(sh->plugin); |
2727 | GNUNET_free (sh); | 2782 | GNUNET_free(sh); |
2728 | } | 2783 | } |
2729 | 2784 | ||
2730 | 2785 | ||
@@ -2738,10 +2793,10 @@ GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh) | |||
2738 | * @return number of networks loaded | 2793 | * @return number of networks loaded |
2739 | */ | 2794 | */ |
2740 | unsigned int | 2795 | unsigned int |
2741 | GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | 2796 | GNUNET_ATS_solvers_load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg, |
2742 | unsigned long long *out_dest, | 2797 | unsigned long long *out_dest, |
2743 | unsigned long long *in_dest, | 2798 | unsigned long long *in_dest, |
2744 | int dest_length) | 2799 | int dest_length) |
2745 | { | 2800 | { |
2746 | char * entry_in = NULL; | 2801 | char * entry_in = NULL; |
2747 | char * entry_out = NULL; | 2802 | char * entry_out = NULL; |
@@ -2751,105 +2806,105 @@ GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2751 | int res; | 2806 | int res; |
2752 | 2807 | ||
2753 | for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) | 2808 | for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) |
2754 | { | ||
2755 | in_dest[c] = 0; | ||
2756 | out_dest[c] = 0; | ||
2757 | GNUNET_asprintf (&entry_out, | ||
2758 | "%s_QUOTA_OUT", | ||
2759 | GNUNET_NT_to_string (c)); | ||
2760 | GNUNET_asprintf (&entry_in, | ||
2761 | "%s_QUOTA_IN", | ||
2762 | GNUNET_NT_to_string (c)); | ||
2763 | |||
2764 | /* quota out */ | ||
2765 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | ||
2766 | { | ||
2767 | res = GNUNET_NO; | ||
2768 | if (0 == strcmp(quota_out_str, BIG_M_STRING)) | ||
2769 | { | ||
2770 | out_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
2771 | res = GNUNET_YES; | ||
2772 | } | ||
2773 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c]))) | ||
2774 | res = GNUNET_YES; | ||
2775 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_out, &out_dest[c]))) | ||
2776 | res = GNUNET_YES; | ||
2777 | |||
2778 | if (GNUNET_NO == res) | ||
2779 | { | ||
2780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2781 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
2782 | GNUNET_NT_to_string (c), | ||
2783 | quota_out_str, | ||
2784 | GNUNET_ATS_DefaultBandwidth); | ||
2785 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
2786 | } | ||
2787 | else | ||
2788 | { | ||
2789 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2790 | "Outbound quota configure for network `%s' is %llu\n", | ||
2791 | GNUNET_NT_to_string (c), | ||
2792 | out_dest[c]); | ||
2793 | } | ||
2794 | GNUNET_free (quota_out_str); | ||
2795 | } | ||
2796 | else | ||
2797 | { | ||
2798 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2799 | _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), | ||
2800 | GNUNET_NT_to_string (c), | ||
2801 | GNUNET_ATS_DefaultBandwidth); | ||
2802 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
2803 | } | ||
2804 | |||
2805 | /* quota in */ | ||
2806 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) | ||
2807 | { | 2809 | { |
2808 | res = GNUNET_NO; | 2810 | in_dest[c] = 0; |
2809 | if (0 == strcmp(quota_in_str, BIG_M_STRING)) | 2811 | out_dest[c] = 0; |
2810 | { | 2812 | GNUNET_asprintf(&entry_out, |
2811 | in_dest[c] = GNUNET_ATS_MaxBandwidth; | 2813 | "%s_QUOTA_OUT", |
2812 | res = GNUNET_YES; | 2814 | GNUNET_NT_to_string(c)); |
2813 | } | 2815 | GNUNET_asprintf(&entry_in, |
2814 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c]))) | 2816 | "%s_QUOTA_IN", |
2815 | res = GNUNET_YES; | 2817 | GNUNET_NT_to_string(c)); |
2816 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg, "ats", entry_in, &in_dest[c]))) | 2818 | |
2817 | res = GNUNET_YES; | 2819 | /* quota out */ |
2820 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, "a_out_str)) | ||
2821 | { | ||
2822 | res = GNUNET_NO; | ||
2823 | if (0 == strcmp(quota_out_str, BIG_M_STRING)) | ||
2824 | { | ||
2825 | out_dest[c] = GNUNET_ATS_MaxBandwidth; | ||
2826 | res = GNUNET_YES; | ||
2827 | } | ||
2828 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes(quota_out_str, &out_dest[c]))) | ||
2829 | res = GNUNET_YES; | ||
2830 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "ats", entry_out, &out_dest[c]))) | ||
2831 | res = GNUNET_YES; | ||
2832 | |||
2833 | if (GNUNET_NO == res) | ||
2834 | { | ||
2835 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2836 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
2837 | GNUNET_NT_to_string(c), | ||
2838 | quota_out_str, | ||
2839 | GNUNET_ATS_DefaultBandwidth); | ||
2840 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
2841 | } | ||
2842 | else | ||
2843 | { | ||
2844 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2845 | "Outbound quota configure for network `%s' is %llu\n", | ||
2846 | GNUNET_NT_to_string(c), | ||
2847 | out_dest[c]); | ||
2848 | } | ||
2849 | GNUNET_free(quota_out_str); | ||
2850 | } | ||
2851 | else | ||
2852 | { | ||
2853 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
2854 | _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), | ||
2855 | GNUNET_NT_to_string(c), | ||
2856 | GNUNET_ATS_DefaultBandwidth); | ||
2857 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
2858 | } | ||
2818 | 2859 | ||
2819 | if (GNUNET_NO == res) | 2860 | /* quota in */ |
2820 | { | 2861 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, "a_in_str)) |
2821 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 2862 | { |
2822 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | 2863 | res = GNUNET_NO; |
2823 | GNUNET_NT_to_string (c), | 2864 | if (0 == strcmp(quota_in_str, BIG_M_STRING)) |
2824 | quota_in_str, | 2865 | { |
2825 | GNUNET_ATS_DefaultBandwidth); | 2866 | in_dest[c] = GNUNET_ATS_MaxBandwidth; |
2826 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | 2867 | res = GNUNET_YES; |
2827 | } | 2868 | } |
2869 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes(quota_in_str, &in_dest[c]))) | ||
2870 | res = GNUNET_YES; | ||
2871 | if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "ats", entry_in, &in_dest[c]))) | ||
2872 | res = GNUNET_YES; | ||
2873 | |||
2874 | if (GNUNET_NO == res) | ||
2875 | { | ||
2876 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
2877 | _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), | ||
2878 | GNUNET_NT_to_string(c), | ||
2879 | quota_in_str, | ||
2880 | GNUNET_ATS_DefaultBandwidth); | ||
2881 | in_dest[c] = GNUNET_ATS_DefaultBandwidth; | ||
2882 | } | ||
2883 | else | ||
2884 | { | ||
2885 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2886 | "Inbound quota configured for network `%s' is %llu\n", | ||
2887 | GNUNET_NT_to_string(c), | ||
2888 | in_dest[c]); | ||
2889 | } | ||
2890 | GNUNET_free(quota_in_str); | ||
2891 | } | ||
2828 | else | 2892 | else |
2829 | { | 2893 | { |
2830 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2894 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
2831 | "Inbound quota configured for network `%s' is %llu\n", | 2895 | _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), |
2832 | GNUNET_NT_to_string (c), | 2896 | GNUNET_NT_to_string(c), |
2833 | in_dest[c]); | 2897 | GNUNET_ATS_DefaultBandwidth); |
2834 | } | 2898 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; |
2835 | GNUNET_free (quota_in_str); | 2899 | } |
2836 | } | 2900 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2837 | else | 2901 | "Loaded quota for network `%s' (in/out): %llu %llu\n", |
2838 | { | 2902 | GNUNET_NT_to_string(c), |
2839 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 2903 | in_dest[c], |
2840 | _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), | 2904 | out_dest[c]); |
2841 | GNUNET_NT_to_string (c), | 2905 | GNUNET_free(entry_out); |
2842 | GNUNET_ATS_DefaultBandwidth); | 2906 | GNUNET_free(entry_in); |
2843 | out_dest[c] = GNUNET_ATS_DefaultBandwidth; | 2907 | } |
2844 | } | ||
2845 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
2846 | "Loaded quota for network `%s' (in/out): %llu %llu\n", | ||
2847 | GNUNET_NT_to_string (c), | ||
2848 | in_dest[c], | ||
2849 | out_dest[c]); | ||
2850 | GNUNET_free (entry_out); | ||
2851 | GNUNET_free (entry_in); | ||
2852 | } | ||
2853 | return GNUNET_NT_COUNT; | 2908 | return GNUNET_NT_COUNT; |
2854 | } | 2909 | } |
2855 | 2910 | ||
@@ -2863,107 +2918,121 @@ GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
2863 | * @param add additional solver information | 2918 | * @param add additional solver information |
2864 | */ | 2919 | */ |
2865 | static void | 2920 | static void |
2866 | solver_info_cb (void *cls, | 2921 | solver_info_cb(void *cls, |
2867 | enum GAS_Solver_Operation op, | 2922 | enum GAS_Solver_Operation op, |
2868 | enum GAS_Solver_Status stat, | 2923 | enum GAS_Solver_Status stat, |
2869 | enum GAS_Solver_Additional_Information add) | 2924 | enum GAS_Solver_Additional_Information add) |
2870 | { | 2925 | { |
2871 | char *add_info; | 2926 | char *add_info; |
2872 | switch (add) { | 2927 | |
2928 | switch (add) | ||
2929 | { | ||
2873 | case GAS_INFO_NONE: | 2930 | case GAS_INFO_NONE: |
2874 | add_info = "GAS_INFO_NONE"; | 2931 | add_info = "GAS_INFO_NONE"; |
2875 | break; | 2932 | break; |
2933 | |||
2876 | case GAS_INFO_FULL: | 2934 | case GAS_INFO_FULL: |
2877 | add_info = "GAS_INFO_MLP_FULL"; | 2935 | add_info = "GAS_INFO_MLP_FULL"; |
2878 | break; | 2936 | break; |
2937 | |||
2879 | case GAS_INFO_UPDATED: | 2938 | case GAS_INFO_UPDATED: |
2880 | add_info = "GAS_INFO_MLP_UPDATED"; | 2939 | add_info = "GAS_INFO_MLP_UPDATED"; |
2881 | break; | 2940 | break; |
2941 | |||
2882 | case GAS_INFO_PROP_ALL: | 2942 | case GAS_INFO_PROP_ALL: |
2883 | add_info = "GAS_INFO_PROP_ALL"; | 2943 | add_info = "GAS_INFO_PROP_ALL"; |
2884 | break; | 2944 | break; |
2945 | |||
2885 | case GAS_INFO_PROP_SINGLE: | 2946 | case GAS_INFO_PROP_SINGLE: |
2886 | add_info = "GAS_INFO_PROP_SINGLE"; | 2947 | add_info = "GAS_INFO_PROP_SINGLE"; |
2887 | break; | 2948 | break; |
2949 | |||
2888 | default: | 2950 | default: |
2889 | add_info = "INVALID"; | 2951 | add_info = "INVALID"; |
2890 | break; | 2952 | break; |
2891 | } | 2953 | } |
2892 | 2954 | ||
2893 | switch (op) | 2955 | switch (op) |
2894 | { | 2956 | { |
2895 | case GAS_OP_SOLVE_START: | 2957 | case GAS_OP_SOLVE_START: |
2896 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2958 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2897 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", | 2959 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", |
2898 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 2960 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); |
2899 | return; | 2961 | return; |
2962 | |||
2900 | case GAS_OP_SOLVE_STOP: | 2963 | case GAS_OP_SOLVE_STOP: |
2901 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2964 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2902 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP", | 2965 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP", |
2903 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 2966 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); |
2904 | return; | 2967 | return; |
2905 | 2968 | ||
2906 | case GAS_OP_SOLVE_SETUP_START: | 2969 | case GAS_OP_SOLVE_SETUP_START: |
2907 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2970 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2908 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", | 2971 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", |
2909 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 2972 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2910 | return; | 2973 | return; |
2911 | 2974 | ||
2912 | case GAS_OP_SOLVE_SETUP_STOP: | 2975 | case GAS_OP_SOLVE_SETUP_STOP: |
2913 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2976 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2914 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", | 2977 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", |
2915 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 2978 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2916 | return; | 2979 | return; |
2917 | 2980 | ||
2918 | case GAS_OP_SOLVE_MLP_LP_START: | 2981 | case GAS_OP_SOLVE_MLP_LP_START: |
2919 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2982 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2920 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", | 2983 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", |
2921 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 2984 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2922 | return; | 2985 | return; |
2986 | |||
2923 | case GAS_OP_SOLVE_MLP_LP_STOP: | 2987 | case GAS_OP_SOLVE_MLP_LP_STOP: |
2924 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2988 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2925 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", | 2989 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", |
2926 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 2990 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2927 | return; | 2991 | return; |
2928 | 2992 | ||
2929 | case GAS_OP_SOLVE_MLP_MLP_START: | 2993 | case GAS_OP_SOLVE_MLP_MLP_START: |
2930 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2994 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2931 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", | 2995 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", |
2932 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 2996 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2933 | return; | 2997 | return; |
2998 | |||
2934 | case GAS_OP_SOLVE_MLP_MLP_STOP: | 2999 | case GAS_OP_SOLVE_MLP_MLP_STOP: |
2935 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3000 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2936 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", | 3001 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", |
2937 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 3002 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2938 | return; | 3003 | return; |
3004 | |||
2939 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: | 3005 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: |
2940 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3006 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2941 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", | 3007 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", |
2942 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 3008 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2943 | return; | 3009 | return; |
3010 | |||
2944 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: | 3011 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: |
2945 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 3012 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2946 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", | 3013 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", |
2947 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 3014 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
2948 | return; | 3015 | return; |
3016 | |||
2949 | default: | 3017 | default: |
2950 | break; | 3018 | break; |
2951 | } | 3019 | } |
2952 | } | 3020 | } |
2953 | 3021 | ||
2954 | static void | 3022 | static void |
2955 | solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address) | 3023 | solver_bandwidth_changed_cb(void *cls, struct ATS_Address *address) |
2956 | { | 3024 | { |
2957 | struct GNUNET_TIME_Relative duration; | 3025 | struct GNUNET_TIME_Relative duration; |
2958 | struct TestPeer *p; | 3026 | struct TestPeer *p; |
2959 | static struct PreferenceGenerator *pg; | 3027 | static struct PreferenceGenerator *pg; |
2960 | uint32_t delta; | 3028 | uint32_t delta; |
2961 | if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) ) | 3029 | |
2962 | { | 3030 | if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in)) |
2963 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3031 | { |
2964 | "Solver notified to disconnect peer `%s'\n", | 3032 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2965 | GNUNET_i2s (&address->peer)); | 3033 | "Solver notified to disconnect peer `%s'\n", |
2966 | } | 3034 | GNUNET_i2s(&address->peer)); |
3035 | } | ||
2967 | p = find_peer_by_pid(&address->peer); | 3036 | p = find_peer_by_pid(&address->peer); |
2968 | if (NULL == p) | 3037 | if (NULL == p) |
2969 | return; | 3038 | return; |
@@ -2971,82 +3040,87 @@ solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
2971 | p->assigned_bw_in = address->assigned_bw_in; | 3040 | p->assigned_bw_in = address->assigned_bw_in; |
2972 | 3041 | ||
2973 | for (pg = pref_gen_head; NULL != pg; pg = pg->next) | 3042 | for (pg = pref_gen_head; NULL != pg; pg = pg->next) |
2974 | { | ||
2975 | if (pg->peer == p->id) | ||
2976 | { | 3043 | { |
2977 | duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); | 3044 | if (pg->peer == p->id) |
2978 | delta = duration.rel_value_us * pg->last_assigned_bw_out; | 3045 | { |
2979 | pg->feedback_bw_out_acc += delta; | 3046 | duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); |
3047 | delta = duration.rel_value_us * pg->last_assigned_bw_out; | ||
3048 | pg->feedback_bw_out_acc += delta; | ||
2980 | 3049 | ||
2981 | delta = duration.rel_value_us * pg->last_assigned_bw_in; | 3050 | delta = duration.rel_value_us * pg->last_assigned_bw_in; |
2982 | pg->feedback_bw_in_acc += delta; | 3051 | pg->feedback_bw_in_acc += delta; |
2983 | 3052 | ||
2984 | pg->last_assigned_bw_in = address->assigned_bw_in; | 3053 | pg->last_assigned_bw_in = address->assigned_bw_in; |
2985 | pg->last_assigned_bw_out = address->assigned_bw_out; | 3054 | pg->last_assigned_bw_out = address->assigned_bw_out; |
2986 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); | 3055 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); |
3056 | } | ||
2987 | } | 3057 | } |
2988 | } | ||
2989 | 3058 | ||
2990 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 3059 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
2991 | "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", | 3060 | "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", |
2992 | GNUNET_i2s (&address->peer), | 3061 | GNUNET_i2s(&address->peer), |
2993 | address, | 3062 | address, |
2994 | address->assigned_bw_out, | 3063 | address->assigned_bw_out, |
2995 | address->assigned_bw_in); | 3064 | address->assigned_bw_in); |
2996 | 3065 | ||
2997 | if (NULL != l) | 3066 | if (NULL != l) |
2998 | GNUNET_ATS_solver_logging_now (l); | 3067 | GNUNET_ATS_solver_logging_now(l); |
2999 | 3068 | ||
3000 | return; | 3069 | return; |
3001 | } | 3070 | } |
3002 | 3071 | ||
3003 | const double * | 3072 | const double * |
3004 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 3073 | get_preferences_cb(void *cls, const struct GNUNET_PeerIdentity *id) |
3005 | { | 3074 | { |
3006 | struct TestPeer *p; | 3075 | struct TestPeer *p; |
3076 | |||
3007 | if (GNUNET_YES == opt_disable_normalization) | 3077 | if (GNUNET_YES == opt_disable_normalization) |
3008 | { | 3078 | { |
3009 | if (NULL == (p = find_peer_by_pid (id))) | 3079 | if (NULL == (p = find_peer_by_pid(id))) |
3010 | return NULL; | 3080 | return NULL; |
3011 | return p->pref_abs; | 3081 | return p->pref_abs; |
3012 | } | 3082 | } |
3013 | else | 3083 | else |
3014 | return GAS_preference_get_by_peer (NULL, | 3084 | return GAS_preference_get_by_peer(NULL, |
3015 | id); | 3085 | id); |
3016 | } | 3086 | } |
3017 | 3087 | ||
3018 | 3088 | ||
3019 | struct SolverHandle * | 3089 | struct SolverHandle * |
3020 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | 3090 | GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type) |
3021 | { | 3091 | { |
3022 | struct SolverHandle *sh; | 3092 | struct SolverHandle *sh; |
3023 | char * solver_str; | 3093 | char * solver_str; |
3024 | 3094 | ||
3025 | switch (type) { | 3095 | switch (type) |
3096 | { | ||
3026 | case GNUNET_ATS_SOLVER_PROPORTIONAL: | 3097 | case GNUNET_ATS_SOLVER_PROPORTIONAL: |
3027 | solver_str = "proportional"; | 3098 | solver_str = "proportional"; |
3028 | break; | 3099 | break; |
3100 | |||
3029 | case GNUNET_ATS_SOLVER_MLP: | 3101 | case GNUNET_ATS_SOLVER_MLP: |
3030 | solver_str = "mlp"; | 3102 | solver_str = "mlp"; |
3031 | break; | 3103 | break; |
3104 | |||
3032 | case GNUNET_ATS_SOLVER_RIL: | 3105 | case GNUNET_ATS_SOLVER_RIL: |
3033 | solver_str = "ril"; | 3106 | solver_str = "ril"; |
3034 | break; | 3107 | break; |
3108 | |||
3035 | default: | 3109 | default: |
3036 | GNUNET_break (0); | 3110 | GNUNET_break(0); |
3037 | return NULL; | 3111 | return NULL; |
3038 | break; | 3112 | break; |
3039 | } | 3113 | } |
3040 | 3114 | ||
3041 | sh = GNUNET_new (struct SolverHandle); | 3115 | sh = GNUNET_new(struct SolverHandle); |
3042 | GNUNET_asprintf (&sh->plugin, | 3116 | GNUNET_asprintf(&sh->plugin, |
3043 | "libgnunet_plugin_ats_%s", | 3117 | "libgnunet_plugin_ats_%s", |
3044 | solver_str); | 3118 | solver_str); |
3045 | sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 3119 | sh->addresses = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO); |
3046 | 3120 | ||
3047 | /* setup environment */ | 3121 | /* setup environment */ |
3048 | sh->env.cfg = e->cfg; | 3122 | sh->env.cfg = e->cfg; |
3049 | sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg); | 3123 | sh->env.stats = GNUNET_STATISTICS_create("ats", e->cfg); |
3050 | sh->env.addresses = sh->addresses; | 3124 | sh->env.addresses = sh->addresses; |
3051 | sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; | 3125 | sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; |
3052 | sh->env.get_preferences = &get_preferences_cb; | 3126 | sh->env.get_preferences = &get_preferences_cb; |
@@ -3055,35 +3129,35 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | |||
3055 | sh->env.network_count = GNUNET_NT_COUNT; | 3129 | sh->env.network_count = GNUNET_NT_COUNT; |
3056 | 3130 | ||
3057 | /* start normalization */ | 3131 | /* start normalization */ |
3058 | GAS_normalization_start (); | 3132 | GAS_normalization_start(); |
3059 | 3133 | ||
3060 | /* load quotas */ | 3134 | /* load quotas */ |
3061 | if (GNUNET_NT_COUNT != GNUNET_ATS_solvers_load_quotas (e->cfg, | 3135 | if (GNUNET_NT_COUNT != GNUNET_ATS_solvers_load_quotas(e->cfg, |
3062 | sh->env.out_quota, sh->env.in_quota, GNUNET_NT_COUNT)) | 3136 | sh->env.out_quota, sh->env.in_quota, GNUNET_NT_COUNT)) |
3063 | { | 3137 | { |
3064 | GNUNET_break(0); | 3138 | GNUNET_break(0); |
3065 | GNUNET_free (sh->plugin); | 3139 | GNUNET_free(sh->plugin); |
3066 | GNUNET_free (sh); | 3140 | GNUNET_free(sh); |
3067 | end_now (); | 3141 | end_now(); |
3068 | return NULL; | 3142 | return NULL; |
3069 | } | 3143 | } |
3070 | 3144 | ||
3071 | sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env); | 3145 | sh->sf = GNUNET_PLUGIN_load(sh->plugin, &sh->env); |
3072 | if (NULL == sh->sf) | 3146 | if (NULL == sh->sf) |
3073 | { | 3147 | { |
3074 | fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin); | 3148 | fprintf(stderr, "Failed to load solver `%s'\n", sh->plugin); |
3075 | GNUNET_break(0); | 3149 | GNUNET_break(0); |
3076 | GNUNET_free (sh->plugin); | 3150 | GNUNET_free(sh->plugin); |
3077 | GNUNET_free (sh); | 3151 | GNUNET_free(sh); |
3078 | end_now (); | 3152 | end_now(); |
3079 | return NULL; | 3153 | return NULL; |
3080 | } | 3154 | } |
3081 | return sh; | 3155 | return sh; |
3082 | } | 3156 | } |
3083 | 3157 | ||
3084 | 3158 | ||
3085 | static void | 3159 | static void |
3086 | done () | 3160 | done() |
3087 | { | 3161 | { |
3088 | struct TestPeer *cur; | 3162 | struct TestPeer *cur; |
3089 | struct TestPeer *next; | 3163 | struct TestPeer *next; |
@@ -3092,79 +3166,79 @@ done () | |||
3092 | struct TestAddress *next_a; | 3166 | struct TestAddress *next_a; |
3093 | 3167 | ||
3094 | /* Stop logging */ | 3168 | /* Stop logging */ |
3095 | GNUNET_ATS_solver_logging_stop (l); | 3169 | GNUNET_ATS_solver_logging_stop(l); |
3096 | 3170 | ||
3097 | /* Stop all preference generation */ | 3171 | /* Stop all preference generation */ |
3098 | GNUNET_ATS_solver_generate_preferences_stop_all (); | 3172 | GNUNET_ATS_solver_generate_preferences_stop_all(); |
3099 | 3173 | ||
3100 | /* Stop all property generation */ | 3174 | /* Stop all property generation */ |
3101 | GNUNET_ATS_solver_generate_property_stop_all (); | 3175 | GNUNET_ATS_solver_generate_property_stop_all(); |
3102 | 3176 | ||
3103 | if (opt_print) | 3177 | if (opt_print) |
3104 | { | 3178 | { |
3105 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n"); | 3179 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "== Printing log information \n"); |
3106 | GNUNET_ATS_solver_logging_eval (l); | 3180 | GNUNET_ATS_solver_logging_eval(l); |
3107 | } | 3181 | } |
3108 | if (opt_save) | 3182 | if (opt_save) |
3109 | { | 3183 | { |
3110 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n"); | 3184 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "== Saving log information \n"); |
3111 | GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp, | 3185 | GNUNET_ATS_solver_logging_write_to_disk(l, e->log_append_time_stamp, |
3112 | e->log_output_dir); | 3186 | e->log_output_dir); |
3113 | } | 3187 | } |
3114 | 3188 | ||
3115 | if (NULL != l) | 3189 | if (NULL != l) |
3116 | { | 3190 | { |
3117 | GNUNET_ATS_solver_logging_free (l); | 3191 | GNUNET_ATS_solver_logging_free(l); |
3118 | l = NULL; | 3192 | l = NULL; |
3119 | } | 3193 | } |
3120 | 3194 | ||
3121 | /* Clean up experiment */ | 3195 | /* Clean up experiment */ |
3122 | if (NULL != e) | 3196 | if (NULL != e) |
3123 | { | 3197 | { |
3124 | GNUNET_ATS_solvers_experimentation_stop (e); | 3198 | GNUNET_ATS_solvers_experimentation_stop(e); |
3125 | e = NULL; | 3199 | e = NULL; |
3126 | } | 3200 | } |
3127 | 3201 | ||
3128 | next = peer_head; | 3202 | next = peer_head; |
3129 | while (NULL != (cur = next)) | 3203 | while (NULL != (cur = next)) |
3130 | { | ||
3131 | next = cur->next; | ||
3132 | GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur); | ||
3133 | next_a = cur->addr_head; | ||
3134 | while (NULL != (cur_a = next_a)) | ||
3135 | { | 3204 | { |
3136 | next_a = cur_a->next; | 3205 | next = cur->next; |
3137 | GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a); | 3206 | GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, cur); |
3138 | GNUNET_free (cur_a); | 3207 | next_a = cur->addr_head; |
3208 | while (NULL != (cur_a = next_a)) | ||
3209 | { | ||
3210 | next_a = cur_a->next; | ||
3211 | GNUNET_CONTAINER_DLL_remove(cur->addr_head, cur->addr_tail, cur_a); | ||
3212 | GNUNET_free(cur_a); | ||
3213 | } | ||
3214 | GNUNET_free(cur); | ||
3139 | } | 3215 | } |
3140 | GNUNET_free (cur); | ||
3141 | } | ||
3142 | if (NULL != sh) | 3216 | if (NULL != sh) |
3143 | { | 3217 | { |
3144 | GNUNET_ATS_solvers_solver_stop (sh); | 3218 | GNUNET_ATS_solvers_solver_stop(sh); |
3145 | sh = NULL; | 3219 | sh = NULL; |
3146 | } | 3220 | } |
3147 | 3221 | ||
3148 | /* Shutdown */ | 3222 | /* Shutdown */ |
3149 | end_now(); | 3223 | end_now(); |
3150 | } | 3224 | } |
3151 | 3225 | ||
3152 | static void | 3226 | static void |
3153 | experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,int success) | 3227 | experiment_done_cb(struct Experiment *e, struct GNUNET_TIME_Relative duration, int success) |
3154 | { | 3228 | { |
3155 | if (GNUNET_OK == success) | 3229 | if (GNUNET_OK == success) |
3156 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n", | 3230 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n", |
3157 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | 3231 | GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); |
3158 | else | 3232 | else |
3159 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); | 3233 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); |
3160 | 3234 | ||
3161 | GNUNET_SCHEDULER_add_now (&done, NULL); | 3235 | GNUNET_SCHEDULER_add_now(&done, NULL); |
3162 | } | 3236 | } |
3163 | 3237 | ||
3164 | static void | 3238 | static void |
3165 | episode_done_cb (struct Episode *ep) | 3239 | episode_done_cb(struct Episode *ep) |
3166 | { | 3240 | { |
3167 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id); | 3241 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id); |
3168 | } | 3242 | } |
3169 | 3243 | ||
3170 | 3244 | ||
@@ -3173,62 +3247,62 @@ episode_done_cb (struct Episode *ep) | |||
3173 | * Do shutdown | 3247 | * Do shutdown |
3174 | */ | 3248 | */ |
3175 | static void | 3249 | static void |
3176 | end_now () | 3250 | end_now() |
3177 | { | 3251 | { |
3178 | if (NULL != e) | 3252 | if (NULL != e) |
3179 | { | 3253 | { |
3180 | GNUNET_ATS_solvers_experimentation_stop (e); | 3254 | GNUNET_ATS_solvers_experimentation_stop(e); |
3181 | e = NULL; | 3255 | e = NULL; |
3182 | } | 3256 | } |
3183 | if (NULL != sh) | 3257 | if (NULL != sh) |
3184 | { | 3258 | { |
3185 | GNUNET_ATS_solvers_solver_stop (sh); | 3259 | GNUNET_ATS_solvers_solver_stop(sh); |
3186 | sh = NULL; | 3260 | sh = NULL; |
3187 | } | 3261 | } |
3188 | } | 3262 | } |
3189 | 3263 | ||
3190 | static void | 3264 | static void |
3191 | run (void *cls, char * const *args, const char *cfgfile, | 3265 | run(void *cls, char * const *args, const char *cfgfile, |
3192 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 3266 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
3193 | { | 3267 | { |
3194 | enum GNUNET_ATS_Solvers solver; | 3268 | enum GNUNET_ATS_Solvers solver; |
3195 | int c; | 3269 | int c; |
3196 | 3270 | ||
3197 | if (NULL == opt_exp_file) | 3271 | if (NULL == opt_exp_file) |
3198 | { | 3272 | { |
3199 | fprintf (stderr, "No experiment given ...\n"); | 3273 | fprintf(stderr, "No experiment given ...\n"); |
3200 | res = 1; | 3274 | res = 1; |
3201 | end_now (); | 3275 | end_now(); |
3202 | return; | 3276 | return; |
3203 | } | 3277 | } |
3204 | 3278 | ||
3205 | if (NULL == opt_solver) | 3279 | if (NULL == opt_solver) |
3206 | { | 3280 | { |
3207 | fprintf (stderr, "No solver given ...\n"); | 3281 | fprintf(stderr, "No solver given ...\n"); |
3208 | res = 1; | 3282 | res = 1; |
3209 | end_now (); | 3283 | end_now(); |
3210 | return; | 3284 | return; |
3211 | } | 3285 | } |
3212 | 3286 | ||
3213 | if (0 == strcmp(opt_solver, "mlp")) | 3287 | if (0 == strcmp(opt_solver, "mlp")) |
3214 | { | 3288 | { |
3215 | solver = GNUNET_ATS_SOLVER_MLP; | 3289 | solver = GNUNET_ATS_SOLVER_MLP; |
3216 | } | 3290 | } |
3217 | else if (0 == strcmp(opt_solver, "proportional")) | 3291 | else if (0 == strcmp(opt_solver, "proportional")) |
3218 | { | 3292 | { |
3219 | solver = GNUNET_ATS_SOLVER_PROPORTIONAL; | 3293 | solver = GNUNET_ATS_SOLVER_PROPORTIONAL; |
3220 | } | 3294 | } |
3221 | else if (0 == strcmp(opt_solver, "ril")) | 3295 | else if (0 == strcmp(opt_solver, "ril")) |
3222 | { | 3296 | { |
3223 | solver = GNUNET_ATS_SOLVER_RIL; | 3297 | solver = GNUNET_ATS_SOLVER_RIL; |
3224 | } | 3298 | } |
3225 | else | 3299 | else |
3226 | { | 3300 | { |
3227 | fprintf (stderr, "No solver given ..."); | 3301 | fprintf(stderr, "No solver given ..."); |
3228 | res = 1; | 3302 | res = 1; |
3229 | end_now (); | 3303 | end_now(); |
3230 | return; | 3304 | return; |
3231 | } | 3305 | } |
3232 | 3306 | ||
3233 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) | 3307 | for (c = 0; c < GNUNET_ATS_PropertyCount; c++) |
3234 | default_properties[c] = DEFAULT_REL_QUALITY; | 3308 | default_properties[c] = DEFAULT_REL_QUALITY; |
@@ -3237,35 +3311,35 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
3237 | default_preferences[c] = DEFAULT_REL_PREFERENCE; | 3311 | default_preferences[c] = DEFAULT_REL_PREFERENCE; |
3238 | 3312 | ||
3239 | /* load experiment */ | 3313 | /* load experiment */ |
3240 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n"); | 3314 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n"); |
3241 | e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file); | 3315 | e = GNUNET_ATS_solvers_experimentation_load(opt_exp_file); |
3242 | if (NULL == e) | 3316 | if (NULL == e) |
3243 | { | 3317 | { |
3244 | fprintf (stderr, "Failed to load experiment ...\n"); | 3318 | fprintf(stderr, "Failed to load experiment ...\n"); |
3245 | res = 1; | 3319 | res = 1; |
3246 | end_now (); | 3320 | end_now(); |
3247 | return; | 3321 | return; |
3248 | } | 3322 | } |
3249 | 3323 | ||
3250 | /* load solver */ | 3324 | /* load solver */ |
3251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n"); | 3325 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n"); |
3252 | sh = GNUNET_ATS_solvers_solver_start (solver); | 3326 | sh = GNUNET_ATS_solvers_solver_start(solver); |
3253 | if (NULL == sh) | 3327 | if (NULL == sh) |
3254 | { | 3328 | { |
3255 | fprintf (stderr, "Failed to start solver ...\n"); | 3329 | fprintf(stderr, "Failed to start solver ...\n"); |
3256 | end_now (); | 3330 | end_now(); |
3257 | res = 1; | 3331 | res = 1; |
3258 | return; | 3332 | return; |
3259 | } | 3333 | } |
3260 | 3334 | ||
3261 | /* start logging */ | 3335 | /* start logging */ |
3262 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n"); | 3336 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Start logging \n"); |
3263 | l = GNUNET_ATS_solver_logging_start (e->log_freq); | 3337 | l = GNUNET_ATS_solver_logging_start(e->log_freq); |
3264 | 3338 | ||
3265 | /* run experiment */ | 3339 | /* run experiment */ |
3266 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n"); | 3340 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n"); |
3267 | GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb, | 3341 | GNUNET_ATS_solvers_experimentation_run(e, episode_done_cb, |
3268 | experiment_done_cb); | 3342 | experiment_done_cb); |
3269 | 3343 | ||
3270 | /* WAIT */ | 3344 | /* WAIT */ |
3271 | } | 3345 | } |
@@ -3278,7 +3352,7 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
3278 | * @param argv argument values | 3352 | * @param argv argument values |
3279 | */ | 3353 | */ |
3280 | int | 3354 | int |
3281 | main (int argc, char *argv[]) | 3355 | main(int argc, char *argv[]) |
3282 | { | 3356 | { |
3283 | opt_exp_file = NULL; | 3357 | opt_exp_file = NULL; |
3284 | opt_solver = NULL; | 3358 | opt_solver = NULL; |
@@ -3289,38 +3363,38 @@ main (int argc, char *argv[]) | |||
3289 | 3363 | ||
3290 | static struct GNUNET_GETOPT_CommandLineOption options[] = | 3364 | static struct GNUNET_GETOPT_CommandLineOption options[] = |
3291 | { | 3365 | { |
3292 | GNUNET_GETOPT_option_string ('s', | 3366 | GNUNET_GETOPT_option_string('s', |
3293 | "solver", | 3367 | "solver", |
3294 | gettext_noop ("solver to use"), | 3368 | gettext_noop("solver to use"), |
3295 | &opt_solver), | 3369 | &opt_solver), |
3296 | 3370 | ||
3297 | GNUNET_GETOPT_option_string ('e', | 3371 | GNUNET_GETOPT_option_string('e', |
3298 | "experiment" | 3372 | "experiment" |
3299 | gettext_noop ("experiment to use"), | 3373 | gettext_noop("experiment to use"), |
3300 | &opt_exp_file), | 3374 | &opt_exp_file), |
3301 | 3375 | ||
3302 | GNUNET_GETOPT_option_verbose (&opt_verbose), | 3376 | GNUNET_GETOPT_option_verbose(&opt_verbose), |
3303 | 3377 | ||
3304 | GNUNET_GETOPT_option_flag ('p', | 3378 | GNUNET_GETOPT_option_flag('p', |
3305 | "print", | 3379 | "print", |
3306 | gettext_noop ("print logging"), | 3380 | gettext_noop("print logging"), |
3307 | &opt_print), | 3381 | &opt_print), |
3308 | 3382 | ||
3309 | GNUNET_GETOPT_option_flag ('f', | 3383 | GNUNET_GETOPT_option_flag('f', |
3310 | "file", | 3384 | "file", |
3311 | gettext_noop ("save logging to disk"), | 3385 | gettext_noop("save logging to disk"), |
3312 | &opt_save), | 3386 | &opt_save), |
3313 | 3387 | ||
3314 | GNUNET_GETOPT_option_flag ('d', | 3388 | GNUNET_GETOPT_option_flag('d', |
3315 | "dn", | 3389 | "dn", |
3316 | gettext_noop ("disable normalization"), | 3390 | gettext_noop("disable normalization"), |
3317 | &opt_disable_normalization), | 3391 | &opt_disable_normalization), |
3318 | 3392 | ||
3319 | GNUNET_GETOPT_OPTION_END | 3393 | GNUNET_GETOPT_OPTION_END |
3320 | }; | 3394 | }; |
3321 | 3395 | ||
3322 | GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval", | 3396 | GNUNET_PROGRAM_run(argc, argv, "gnunet-ats-solver-eval", |
3323 | NULL, options, &run, argv[0]); | 3397 | NULL, options, &run, argv[0]); |
3324 | 3398 | ||
3325 | return res; | 3399 | return res; |
3326 | } | 3400 | } |
diff --git a/src/ats/gnunet-ats-solver-eval.h b/src/ats/gnunet-ats-solver-eval.h index d5a68c5b0..e3afa02b1 100644 --- a/src/ats/gnunet-ats-solver-eval.h +++ b/src/ats/gnunet-ats-solver-eval.h | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010-2013 GNUnet e.V. | 3 | Copyright (C) 2010-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -34,8 +34,7 @@ | |||
34 | #include "gnunet-service-ats_normalization.h" | 34 | #include "gnunet-service-ats_normalization.h" |
35 | #include "test_ats_api_common.h" | 35 | #include "test_ats_api_common.h" |
36 | 36 | ||
37 | enum GeneratorType | 37 | enum GeneratorType { |
38 | { | ||
39 | GNUNET_ATS_TEST_TG_LINEAR, | 38 | GNUNET_ATS_TEST_TG_LINEAR, |
40 | GNUNET_ATS_TEST_TG_CONSTANT, | 39 | GNUNET_ATS_TEST_TG_CONSTANT, |
41 | GNUNET_ATS_TEST_TG_RANDOM, | 40 | GNUNET_ATS_TEST_TG_RANDOM, |
@@ -43,8 +42,7 @@ enum GeneratorType | |||
43 | }; | 42 | }; |
44 | 43 | ||
45 | 44 | ||
46 | enum OperationType | 45 | enum OperationType { |
47 | { | ||
48 | SOLVER_OP_ADD_ADDRESS, | 46 | SOLVER_OP_ADD_ADDRESS, |
49 | SOLVER_OP_DEL_ADDRESS, | 47 | SOLVER_OP_DEL_ADDRESS, |
50 | SOLVER_OP_START_SET_PROPERTY, | 48 | SOLVER_OP_START_SET_PROPERTY, |
@@ -55,8 +53,7 @@ enum OperationType | |||
55 | SOLVER_OP_STOP_REQUEST, | 53 | SOLVER_OP_STOP_REQUEST, |
56 | }; | 54 | }; |
57 | 55 | ||
58 | struct SolverHandle | 56 | struct SolverHandle { |
59 | { | ||
60 | /** | 57 | /** |
61 | * Solver plugin name | 58 | * Solver plugin name |
62 | */ | 59 | */ |
@@ -78,15 +75,13 @@ struct SolverHandle | |||
78 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; | 75 | struct GNUNET_CONTAINER_MultiPeerMap *addresses; |
79 | }; | 76 | }; |
80 | 77 | ||
81 | enum GNUNET_ATS_Solvers | 78 | enum GNUNET_ATS_Solvers { |
82 | { | ||
83 | GNUNET_ATS_SOLVER_PROPORTIONAL, | 79 | GNUNET_ATS_SOLVER_PROPORTIONAL, |
84 | GNUNET_ATS_SOLVER_MLP, | 80 | GNUNET_ATS_SOLVER_MLP, |
85 | GNUNET_ATS_SOLVER_RIL, | 81 | GNUNET_ATS_SOLVER_RIL, |
86 | }; | 82 | }; |
87 | 83 | ||
88 | struct LoggingFileHandle | 84 | struct LoggingFileHandle { |
89 | { | ||
90 | /* DLL list for logging time steps */ | 85 | /* DLL list for logging time steps */ |
91 | struct LoggingFileHandle *next; | 86 | struct LoggingFileHandle *next; |
92 | struct LoggingFileHandle *prev; | 87 | struct LoggingFileHandle *prev; |
@@ -98,11 +93,9 @@ struct LoggingFileHandle | |||
98 | long long unsigned int aid; | 93 | long long unsigned int aid; |
99 | 94 | ||
100 | struct GNUNET_DISK_FileHandle *f_hd; | 95 | struct GNUNET_DISK_FileHandle *f_hd; |
101 | |||
102 | }; | 96 | }; |
103 | 97 | ||
104 | struct LoggingTimeStep | 98 | struct LoggingTimeStep { |
105 | { | ||
106 | struct LoggingTimeStep *prev; | 99 | struct LoggingTimeStep *prev; |
107 | struct LoggingTimeStep *next; | 100 | struct LoggingTimeStep *next; |
108 | 101 | ||
@@ -113,8 +106,7 @@ struct LoggingTimeStep | |||
113 | struct GNUNET_TIME_Relative delta; | 106 | struct GNUNET_TIME_Relative delta; |
114 | }; | 107 | }; |
115 | 108 | ||
116 | struct LoggingPeer | 109 | struct LoggingPeer { |
117 | { | ||
118 | struct LoggingPeer *prev; | 110 | struct LoggingPeer *prev; |
119 | struct LoggingPeer *next; | 111 | struct LoggingPeer *next; |
120 | 112 | ||
@@ -128,8 +120,7 @@ struct LoggingPeer | |||
128 | struct LoggingAddress *addr_tail; | 120 | struct LoggingAddress *addr_tail; |
129 | }; | 121 | }; |
130 | 122 | ||
131 | struct LoggingAddress | 123 | struct LoggingAddress { |
132 | { | ||
133 | struct LoggingAddress *next; | 124 | struct LoggingAddress *next; |
134 | struct LoggingAddress *prev; | 125 | struct LoggingAddress *prev; |
135 | 126 | ||
@@ -144,8 +135,7 @@ struct LoggingAddress | |||
144 | }; | 135 | }; |
145 | 136 | ||
146 | 137 | ||
147 | struct TestPeer | 138 | struct TestPeer { |
148 | { | ||
149 | struct TestPeer *prev; | 139 | struct TestPeer *prev; |
150 | struct TestPeer *next; | 140 | struct TestPeer *next; |
151 | 141 | ||
@@ -165,8 +155,7 @@ struct TestPeer | |||
165 | }; | 155 | }; |
166 | 156 | ||
167 | 157 | ||
168 | struct TestAddress | 158 | struct TestAddress { |
169 | { | ||
170 | struct TestAddress *next; | 159 | struct TestAddress *next; |
171 | struct TestAddress *prev; | 160 | struct TestAddress *prev; |
172 | 161 | ||
@@ -183,16 +172,15 @@ struct Episode; | |||
183 | struct Experiment; | 172 | struct Experiment; |
184 | 173 | ||
185 | typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) ( | 174 | typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) ( |
186 | struct Episode *e); | 175 | struct Episode *e); |
187 | 176 | ||
188 | typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, | 177 | typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, |
189 | struct GNUNET_TIME_Relative duration,int success); | 178 | struct GNUNET_TIME_Relative duration, int success); |
190 | 179 | ||
191 | /** | 180 | /** |
192 | * An operation in an experiment | 181 | * An operation in an experiment |
193 | */ | 182 | */ |
194 | struct GNUNET_ATS_TEST_Operation | 183 | struct GNUNET_ATS_TEST_Operation { |
195 | { | ||
196 | struct GNUNET_ATS_TEST_Operation *next; | 184 | struct GNUNET_ATS_TEST_Operation *next; |
197 | struct GNUNET_ATS_TEST_Operation *prev; | 185 | struct GNUNET_ATS_TEST_Operation *prev; |
198 | 186 | ||
@@ -218,8 +206,7 @@ struct GNUNET_ATS_TEST_Operation | |||
218 | // enum GNUNET_ATS_Property prop_type; | 206 | // enum GNUNET_ATS_Property prop_type; |
219 | }; | 207 | }; |
220 | 208 | ||
221 | struct Episode | 209 | struct Episode { |
222 | { | ||
223 | int id; | 210 | int id; |
224 | struct Episode *next; | 211 | struct Episode *next; |
225 | struct GNUNET_TIME_Relative duration; | 212 | struct GNUNET_TIME_Relative duration; |
@@ -228,8 +215,7 @@ struct Episode | |||
228 | struct GNUNET_ATS_TEST_Operation *tail; | 215 | struct GNUNET_ATS_TEST_Operation *tail; |
229 | }; | 216 | }; |
230 | 217 | ||
231 | struct LoggingHandle | 218 | struct LoggingHandle { |
232 | { | ||
233 | struct GNUNET_SCHEDULER_Task * logging_task; | 219 | struct GNUNET_SCHEDULER_Task * logging_task; |
234 | struct GNUNET_TIME_Relative log_freq; | 220 | struct GNUNET_TIME_Relative log_freq; |
235 | 221 | ||
@@ -238,8 +224,7 @@ struct LoggingHandle | |||
238 | struct LoggingTimeStep *tail; | 224 | struct LoggingTimeStep *tail; |
239 | }; | 225 | }; |
240 | 226 | ||
241 | struct Experiment | 227 | struct Experiment { |
242 | { | ||
243 | char *name; | 228 | char *name; |
244 | char *log_prefix; | 229 | char *log_prefix; |
245 | char *cfg_file; | 230 | char *cfg_file; |
@@ -263,8 +248,7 @@ struct Experiment | |||
263 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb; | 248 | GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb; |
264 | }; | 249 | }; |
265 | 250 | ||
266 | struct PreferenceGenerator | 251 | struct PreferenceGenerator { |
267 | { | ||
268 | struct PreferenceGenerator *prev; | 252 | struct PreferenceGenerator *prev; |
269 | struct PreferenceGenerator *next; | 253 | struct PreferenceGenerator *next; |
270 | 254 | ||
@@ -302,12 +286,10 @@ struct PreferenceGenerator | |||
302 | uint32_t last_assigned_bw_in; | 286 | uint32_t last_assigned_bw_in; |
303 | uint32_t last_assigned_bw_out; | 287 | uint32_t last_assigned_bw_out; |
304 | double last_delay_value; | 288 | double last_delay_value; |
305 | |||
306 | }; | 289 | }; |
307 | 290 | ||
308 | 291 | ||
309 | struct PropertyGenerator | 292 | struct PropertyGenerator { |
310 | { | ||
311 | struct PropertyGenerator *prev; | 293 | struct PropertyGenerator *prev; |
312 | struct PropertyGenerator *next; | 294 | struct PropertyGenerator *next; |
313 | 295 | ||
diff --git a/src/ats/gnunet-service-ats-new.c b/src/ats/gnunet-service-ats-new.c index b451c8c67..1061c28c2 100644 --- a/src/ats/gnunet-service-ats-new.c +++ b/src/ats/gnunet-service-ats-new.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats-new.c | 21 | * @file ats/gnunet-service-ats-new.c |
22 | * @brief ats service | 22 | * @brief ats service |
@@ -59,8 +59,7 @@ struct Client; | |||
59 | /** | 59 | /** |
60 | * Preferences expressed by a client are kept in a DLL per client. | 60 | * Preferences expressed by a client are kept in a DLL per client. |
61 | */ | 61 | */ |
62 | struct ClientPreference | 62 | struct ClientPreference { |
63 | { | ||
64 | /** | 63 | /** |
65 | * DLL pointer. | 64 | * DLL pointer. |
66 | */ | 65 | */ |
@@ -91,9 +90,7 @@ struct ClientPreference | |||
91 | /** | 90 | /** |
92 | * Information about ongoing sessions of the transport client. | 91 | * Information about ongoing sessions of the transport client. |
93 | */ | 92 | */ |
94 | struct GNUNET_ATS_Session | 93 | struct GNUNET_ATS_Session { |
95 | { | ||
96 | |||
97 | /** | 94 | /** |
98 | * Session data exposed to the plugin. | 95 | * Session data exposed to the plugin. |
99 | */ | 96 | */ |
@@ -113,15 +110,13 @@ struct GNUNET_ATS_Session | |||
113 | * Unique ID for the session when talking with the client. | 110 | * Unique ID for the session when talking with the client. |
114 | */ | 111 | */ |
115 | uint32_t session_id; | 112 | uint32_t session_id; |
116 | |||
117 | }; | 113 | }; |
118 | 114 | ||
119 | 115 | ||
120 | /** | 116 | /** |
121 | * Information we track per client. | 117 | * Information we track per client. |
122 | */ | 118 | */ |
123 | struct Client | 119 | struct Client { |
124 | { | ||
125 | /** | 120 | /** |
126 | * Type of the client, initially #CT_NONE. | 121 | * Type of the client, initially #CT_NONE. |
127 | */ | 122 | */ |
@@ -141,9 +136,7 @@ struct Client | |||
141 | * Details depending on @e type. | 136 | * Details depending on @e type. |
142 | */ | 137 | */ |
143 | union { | 138 | union { |
144 | |||
145 | struct { | 139 | struct { |
146 | |||
147 | /** | 140 | /** |
148 | * Head of DLL of preferences expressed by this client. | 141 | * Head of DLL of preferences expressed by this client. |
149 | */ | 142 | */ |
@@ -153,20 +146,15 @@ struct Client | |||
153 | * Tail of DLL of preferences expressed by this client. | 146 | * Tail of DLL of preferences expressed by this client. |
154 | */ | 147 | */ |
155 | struct ClientPreference *cp_tail; | 148 | struct ClientPreference *cp_tail; |
156 | |||
157 | } application; | 149 | } application; |
158 | 150 | ||
159 | struct { | 151 | struct { |
160 | |||
161 | /** | 152 | /** |
162 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. | 153 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. |
163 | */ | 154 | */ |
164 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; | 155 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; |
165 | |||
166 | } transport; | 156 | } transport; |
167 | |||
168 | } details; | 157 | } details; |
169 | |||
170 | }; | 158 | }; |
171 | 159 | ||
172 | 160 | ||
@@ -200,32 +188,32 @@ static struct Client *transport_client; | |||
200 | * @param address address the transport should try | 188 | * @param address address the transport should try |
201 | */ | 189 | */ |
202 | static void | 190 | static void |
203 | suggest_cb (void *cls, | 191 | suggest_cb(void *cls, |
204 | const struct GNUNET_PeerIdentity *pid, | 192 | const struct GNUNET_PeerIdentity *pid, |
205 | const char *address) | 193 | const char *address) |
206 | { | 194 | { |
207 | struct GNUNET_MQ_Envelope *env; | 195 | struct GNUNET_MQ_Envelope *env; |
208 | size_t slen = strlen (address) + 1; | 196 | size_t slen = strlen(address) + 1; |
209 | struct AddressSuggestionMessage *as; | 197 | struct AddressSuggestionMessage *as; |
210 | 198 | ||
211 | if (NULL == transport_client) | 199 | if (NULL == transport_client) |
212 | { | 200 | { |
213 | // FIXME: stats! | 201 | // FIXME: stats! |
214 | return; | 202 | return; |
215 | } | 203 | } |
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
217 | "Suggesting address `%s' of peer `%s'\n", | 205 | "Suggesting address `%s' of peer `%s'\n", |
218 | address, | 206 | address, |
219 | GNUNET_i2s (pid)); | 207 | GNUNET_i2s(pid)); |
220 | env = GNUNET_MQ_msg_extra (as, | 208 | env = GNUNET_MQ_msg_extra(as, |
221 | slen, | 209 | slen, |
222 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | 210 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); |
223 | as->peer = *pid; | 211 | as->peer = *pid; |
224 | memcpy (&as[1], | 212 | memcpy(&as[1], |
225 | address, | 213 | address, |
226 | slen); | 214 | slen); |
227 | GNUNET_MQ_send (transport_client->mq, | 215 | GNUNET_MQ_send(transport_client->mq, |
228 | env); | 216 | env); |
229 | } | 217 | } |
230 | 218 | ||
231 | 219 | ||
@@ -240,37 +228,37 @@ suggest_cb (void *cls, | |||
240 | * @param bw_out suggested bandwidth for transmission | 228 | * @param bw_out suggested bandwidth for transmission |
241 | */ | 229 | */ |
242 | static void | 230 | static void |
243 | allocate_cb (void *cls, | 231 | allocate_cb(void *cls, |
244 | struct GNUNET_ATS_Session *session, | 232 | struct GNUNET_ATS_Session *session, |
245 | const struct GNUNET_PeerIdentity *peer, | 233 | const struct GNUNET_PeerIdentity *peer, |
246 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, | 234 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, |
247 | struct GNUNET_BANDWIDTH_Value32NBO bw_out) | 235 | struct GNUNET_BANDWIDTH_Value32NBO bw_out) |
248 | { | 236 | { |
249 | struct GNUNET_MQ_Envelope *env; | 237 | struct GNUNET_MQ_Envelope *env; |
250 | struct SessionAllocationMessage *sam; | 238 | struct SessionAllocationMessage *sam; |
251 | 239 | ||
252 | (void) cls; | 240 | (void)cls; |
253 | if ( (NULL == transport_client) || | 241 | if ((NULL == transport_client) || |
254 | (session->client != transport_client) ) | 242 | (session->client != transport_client)) |
255 | { | 243 | { |
256 | /* transport must have just died and solver is addressing the | 244 | /* transport must have just died and solver is addressing the |
257 | losses of sessions (possibly of previous transport), ignore! */ | 245 | losses of sessions (possibly of previous transport), ignore! */ |
258 | return; | 246 | return; |
259 | } | 247 | } |
260 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 248 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
261 | "Allocating %u/%u bytes for %p of peer `%s'\n", | 249 | "Allocating %u/%u bytes for %p of peer `%s'\n", |
262 | ntohl (bw_in.value__), | 250 | ntohl(bw_in.value__), |
263 | ntohl (bw_out.value__), | 251 | ntohl(bw_out.value__), |
264 | session, | 252 | session, |
265 | GNUNET_i2s (peer)); | 253 | GNUNET_i2s(peer)); |
266 | env = GNUNET_MQ_msg (sam, | 254 | env = GNUNET_MQ_msg(sam, |
267 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); | 255 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); |
268 | sam->session_id = session->session_id; | 256 | sam->session_id = session->session_id; |
269 | sam->peer = *peer; | 257 | sam->peer = *peer; |
270 | sam->bandwidth_in = bw_in; | 258 | sam->bandwidth_in = bw_in; |
271 | sam->bandwidth_out = bw_out; | 259 | sam->bandwidth_out = bw_out; |
272 | GNUNET_MQ_send (transport_client->mq, | 260 | GNUNET_MQ_send(transport_client->mq, |
273 | env); | 261 | env); |
274 | } | 262 | } |
275 | 263 | ||
276 | 264 | ||
@@ -281,18 +269,18 @@ allocate_cb (void *cls, | |||
281 | * @param prop[out] in HBO | 269 | * @param prop[out] in HBO |
282 | */ | 270 | */ |
283 | static void | 271 | static void |
284 | prop_ntoh (const struct PropertiesNBO *properties, | 272 | prop_ntoh(const struct PropertiesNBO *properties, |
285 | struct GNUNET_ATS_Properties *prop) | 273 | struct GNUNET_ATS_Properties *prop) |
286 | { | 274 | { |
287 | prop->delay = GNUNET_TIME_relative_ntoh (properties->delay); | 275 | prop->delay = GNUNET_TIME_relative_ntoh(properties->delay); |
288 | prop->goodput_out = ntohl (properties->goodput_out); | 276 | prop->goodput_out = ntohl(properties->goodput_out); |
289 | prop->goodput_in = ntohl (properties->goodput_in); | 277 | prop->goodput_in = ntohl(properties->goodput_in); |
290 | prop->utilization_out = ntohl (properties->utilization_out); | 278 | prop->utilization_out = ntohl(properties->utilization_out); |
291 | prop->utilization_in = ntohl (properties->utilization_in); | 279 | prop->utilization_in = ntohl(properties->utilization_in); |
292 | prop->distance = ntohl (properties->distance); | 280 | prop->distance = ntohl(properties->distance); |
293 | prop->mtu = ntohl (properties->mtu); | 281 | prop->mtu = ntohl(properties->mtu); |
294 | prop->nt = (enum GNUNET_NetworkType) ntohl (properties->nt); | 282 | prop->nt = (enum GNUNET_NetworkType)ntohl(properties->nt); |
295 | prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (properties->cc); | 283 | prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(properties->cc); |
296 | } | 284 | } |
297 | 285 | ||
298 | 286 | ||
@@ -303,8 +291,8 @@ prop_ntoh (const struct PropertiesNBO *properties, | |||
303 | * @param msg the start message | 291 | * @param msg the start message |
304 | */ | 292 | */ |
305 | static void | 293 | static void |
306 | handle_suggest (void *cls, | 294 | handle_suggest(void *cls, |
307 | const struct ExpressPreferenceMessage *msg) | 295 | const struct ExpressPreferenceMessage *msg) |
308 | { | 296 | { |
309 | struct Client *c = cls; | 297 | struct Client *c = cls; |
310 | struct ClientPreference *cp; | 298 | struct ClientPreference *cp; |
@@ -312,27 +300,27 @@ handle_suggest (void *cls, | |||
312 | if (CT_NONE == c->type) | 300 | if (CT_NONE == c->type) |
313 | c->type = CT_APPLICATION; | 301 | c->type = CT_APPLICATION; |
314 | if (CT_APPLICATION != c->type) | 302 | if (CT_APPLICATION != c->type) |
315 | { | 303 | { |
316 | GNUNET_break (0); | 304 | GNUNET_break(0); |
317 | GNUNET_SERVICE_client_drop (c->client); | 305 | GNUNET_SERVICE_client_drop(c->client); |
318 | return; | 306 | return; |
319 | } | 307 | } |
320 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 308 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
321 | "Client suggested we talk to %s with preference %d at rate %u\n", | 309 | "Client suggested we talk to %s with preference %d at rate %u\n", |
322 | GNUNET_i2s (&msg->peer), | 310 | GNUNET_i2s(&msg->peer), |
323 | (int) ntohl (msg->pk), | 311 | (int)ntohl(msg->pk), |
324 | (int) ntohl (msg->bw.value__)); | 312 | (int)ntohl(msg->bw.value__)); |
325 | cp = GNUNET_new (struct ClientPreference); | 313 | cp = GNUNET_new(struct ClientPreference); |
326 | cp->client = c; | 314 | cp->client = c; |
327 | cp->pref.peer = msg->peer; | 315 | cp->pref.peer = msg->peer; |
328 | cp->pref.bw = msg->bw; | 316 | cp->pref.bw = msg->bw; |
329 | cp->pref.pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk); | 317 | cp->pref.pk = (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk); |
330 | cp->ph = plugin->preference_add (plugin->cls, | 318 | cp->ph = plugin->preference_add(plugin->cls, |
331 | &cp->pref); | 319 | &cp->pref); |
332 | GNUNET_CONTAINER_DLL_insert (c->details.application.cp_head, | 320 | GNUNET_CONTAINER_DLL_insert(c->details.application.cp_head, |
333 | c->details.application.cp_tail, | 321 | c->details.application.cp_tail, |
334 | cp); | 322 | cp); |
335 | GNUNET_SERVICE_client_continue (c->client); | 323 | GNUNET_SERVICE_client_continue(c->client); |
336 | } | 324 | } |
337 | 325 | ||
338 | 326 | ||
@@ -343,8 +331,8 @@ handle_suggest (void *cls, | |||
343 | * @param msg the start message | 331 | * @param msg the start message |
344 | */ | 332 | */ |
345 | static void | 333 | static void |
346 | handle_suggest_cancel (void *cls, | 334 | handle_suggest_cancel(void *cls, |
347 | const struct ExpressPreferenceMessage *msg) | 335 | const struct ExpressPreferenceMessage *msg) |
348 | { | 336 | { |
349 | struct Client *c = cls; | 337 | struct Client *c = cls; |
350 | struct ClientPreference *cp; | 338 | struct ClientPreference *cp; |
@@ -352,33 +340,33 @@ handle_suggest_cancel (void *cls, | |||
352 | if (CT_NONE == c->type) | 340 | if (CT_NONE == c->type) |
353 | c->type = CT_APPLICATION; | 341 | c->type = CT_APPLICATION; |
354 | if (CT_APPLICATION != c->type) | 342 | if (CT_APPLICATION != c->type) |
355 | { | 343 | { |
356 | GNUNET_break (0); | 344 | GNUNET_break(0); |
357 | GNUNET_SERVICE_client_drop (c->client); | 345 | GNUNET_SERVICE_client_drop(c->client); |
358 | return; | 346 | return; |
359 | } | 347 | } |
360 | for (cp = c->details.application.cp_head; | 348 | for (cp = c->details.application.cp_head; |
361 | NULL != cp; | 349 | NULL != cp; |
362 | cp = cp->next) | 350 | cp = cp->next) |
363 | if ( (cp->pref.pk == (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk)) && | 351 | if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk)) && |
364 | (cp->pref.bw.value__ == msg->bw.value__) && | 352 | (cp->pref.bw.value__ == msg->bw.value__) && |
365 | (0 == GNUNET_memcmp (&cp->pref.peer, | 353 | (0 == GNUNET_memcmp(&cp->pref.peer, |
366 | &msg->peer)) ) | 354 | &msg->peer))) |
367 | break; | 355 | break; |
368 | if (NULL == cp) | 356 | if (NULL == cp) |
369 | { | 357 | { |
370 | GNUNET_break (0); | 358 | GNUNET_break(0); |
371 | GNUNET_SERVICE_client_drop (c->client); | 359 | GNUNET_SERVICE_client_drop(c->client); |
372 | return; | 360 | return; |
373 | } | 361 | } |
374 | plugin->preference_del (plugin->cls, | 362 | plugin->preference_del(plugin->cls, |
375 | cp->ph, | 363 | cp->ph, |
376 | &cp->pref); | 364 | &cp->pref); |
377 | GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head, | 365 | GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head, |
378 | c->details.application.cp_tail, | 366 | c->details.application.cp_tail, |
379 | cp); | 367 | cp); |
380 | GNUNET_free (cp); | 368 | GNUNET_free(cp); |
381 | GNUNET_SERVICE_client_continue (c->client); | 369 | GNUNET_SERVICE_client_continue(c->client); |
382 | } | 370 | } |
383 | 371 | ||
384 | 372 | ||
@@ -389,27 +377,27 @@ handle_suggest_cancel (void *cls, | |||
389 | * @param message the request message | 377 | * @param message the request message |
390 | */ | 378 | */ |
391 | static void | 379 | static void |
392 | handle_start (void *cls, | 380 | handle_start(void *cls, |
393 | const struct GNUNET_MessageHeader *hdr) | 381 | const struct GNUNET_MessageHeader *hdr) |
394 | { | 382 | { |
395 | struct Client *c = cls; | 383 | struct Client *c = cls; |
396 | 384 | ||
397 | if (CT_NONE != c->type) | 385 | if (CT_NONE != c->type) |
398 | { | 386 | { |
399 | GNUNET_break (0); | 387 | GNUNET_break(0); |
400 | GNUNET_SERVICE_client_drop (c->client); | 388 | GNUNET_SERVICE_client_drop(c->client); |
401 | return; | 389 | return; |
402 | } | 390 | } |
403 | c->type = CT_TRANSPORT; | 391 | c->type = CT_TRANSPORT; |
404 | c->details.transport.sessions | 392 | c->details.transport.sessions |
405 | = GNUNET_CONTAINER_multihashmap32_create (128); | 393 | = GNUNET_CONTAINER_multihashmap32_create(128); |
406 | if (NULL != transport_client) | 394 | if (NULL != transport_client) |
407 | { | 395 | { |
408 | GNUNET_SERVICE_client_drop (transport_client->client); | 396 | GNUNET_SERVICE_client_drop(transport_client->client); |
409 | transport_client = NULL; | 397 | transport_client = NULL; |
410 | } | 398 | } |
411 | transport_client = c; | 399 | transport_client = c; |
412 | GNUNET_SERVICE_client_continue (c->client); | 400 | GNUNET_SERVICE_client_continue(c->client); |
413 | } | 401 | } |
414 | 402 | ||
415 | 403 | ||
@@ -422,17 +410,17 @@ handle_start (void *cls, | |||
422 | * @return #GNUNET_OK if @a message is well-formed | 410 | * @return #GNUNET_OK if @a message is well-formed |
423 | */ | 411 | */ |
424 | static int | 412 | static int |
425 | check_session_add (void *cls, | 413 | check_session_add(void *cls, |
426 | const struct SessionAddMessage *message) | 414 | const struct SessionAddMessage *message) |
427 | { | 415 | { |
428 | struct Client *c = cls; | 416 | struct Client *c = cls; |
429 | 417 | ||
430 | GNUNET_MQ_check_zero_termination (message); | 418 | GNUNET_MQ_check_zero_termination(message); |
431 | if (CT_TRANSPORT != c->type) | 419 | if (CT_TRANSPORT != c->type) |
432 | { | 420 | { |
433 | GNUNET_break (0); | 421 | GNUNET_break(0); |
434 | return GNUNET_SYSERR; | 422 | return GNUNET_SYSERR; |
435 | } | 423 | } |
436 | return GNUNET_OK; | 424 | return GNUNET_OK; |
437 | } | 425 | } |
438 | 426 | ||
@@ -444,45 +432,45 @@ check_session_add (void *cls, | |||
444 | * @param message the request message | 432 | * @param message the request message |
445 | */ | 433 | */ |
446 | static void | 434 | static void |
447 | handle_session_add (void *cls, | 435 | handle_session_add(void *cls, |
448 | const struct SessionAddMessage *message) | 436 | const struct SessionAddMessage *message) |
449 | { | 437 | { |
450 | struct Client *c = cls; | 438 | struct Client *c = cls; |
451 | const char *address = (const char *) &message[1]; | 439 | const char *address = (const char *)&message[1]; |
452 | struct GNUNET_ATS_Session *session; | 440 | struct GNUNET_ATS_Session *session; |
453 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == | 441 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == |
454 | ntohs (message->header.type)); | 442 | ntohs(message->header.type)); |
455 | 443 | ||
456 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 444 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
457 | message->session_id); | 445 | message->session_id); |
458 | if (NULL != session) | 446 | if (NULL != session) |
459 | { | 447 | { |
460 | GNUNET_break (0); | 448 | GNUNET_break(0); |
461 | GNUNET_SERVICE_client_drop (c->client); | 449 | GNUNET_SERVICE_client_drop(c->client); |
462 | return; | 450 | return; |
463 | } | 451 | } |
464 | session = GNUNET_new (struct GNUNET_ATS_Session); | 452 | session = GNUNET_new(struct GNUNET_ATS_Session); |
465 | session->data.session = session; | 453 | session->data.session = session; |
466 | session->client = c; | 454 | session->client = c; |
467 | session->session_id = message->session_id; | 455 | session->session_id = message->session_id; |
468 | session->data.peer = message->peer; | 456 | session->data.peer = message->peer; |
469 | prop_ntoh (&message->properties, | 457 | prop_ntoh(&message->properties, |
470 | &session->data.prop); | 458 | &session->data.prop); |
471 | session->data.inbound_only = inbound_only; | 459 | session->data.inbound_only = inbound_only; |
472 | GNUNET_assert (GNUNET_YES == | 460 | GNUNET_assert(GNUNET_YES == |
473 | GNUNET_CONTAINER_multihashmap32_put (c->details.transport.sessions, | 461 | GNUNET_CONTAINER_multihashmap32_put(c->details.transport.sessions, |
474 | message->session_id, | 462 | message->session_id, |
475 | session, | 463 | session, |
476 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 464 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
477 | session->sh = plugin->session_add (plugin->cls, | 465 | session->sh = plugin->session_add(plugin->cls, |
478 | &session->data, | 466 | &session->data, |
479 | address); | 467 | address); |
480 | GNUNET_assert (NULL != session->sh); | 468 | GNUNET_assert(NULL != session->sh); |
481 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 469 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
482 | "Transport has new session %p to %s\n", | 470 | "Transport has new session %p to %s\n", |
483 | session, | 471 | session, |
484 | GNUNET_i2s (&message->peer)); | 472 | GNUNET_i2s(&message->peer)); |
485 | GNUNET_SERVICE_client_continue (c->client); | 473 | GNUNET_SERVICE_client_continue(c->client); |
486 | } | 474 | } |
487 | 475 | ||
488 | 476 | ||
@@ -493,32 +481,32 @@ handle_session_add (void *cls, | |||
493 | * @param msg the request message | 481 | * @param msg the request message |
494 | */ | 482 | */ |
495 | static void | 483 | static void |
496 | handle_session_update (void *cls, | 484 | handle_session_update(void *cls, |
497 | const struct SessionUpdateMessage *msg) | 485 | const struct SessionUpdateMessage *msg) |
498 | { | 486 | { |
499 | struct Client *c = cls; | 487 | struct Client *c = cls; |
500 | struct GNUNET_ATS_Session *session; | 488 | struct GNUNET_ATS_Session *session; |
501 | 489 | ||
502 | if (CT_TRANSPORT != c->type) | 490 | if (CT_TRANSPORT != c->type) |
503 | { | 491 | { |
504 | GNUNET_break (0); | 492 | GNUNET_break(0); |
505 | GNUNET_SERVICE_client_drop (c->client); | 493 | GNUNET_SERVICE_client_drop(c->client); |
506 | return; | 494 | return; |
507 | } | 495 | } |
508 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 496 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
509 | msg->session_id); | 497 | msg->session_id); |
510 | if (NULL == session) | 498 | if (NULL == session) |
511 | { | 499 | { |
512 | GNUNET_break (0); | 500 | GNUNET_break(0); |
513 | GNUNET_SERVICE_client_drop (c->client); | 501 | GNUNET_SERVICE_client_drop(c->client); |
514 | return; | 502 | return; |
515 | } | 503 | } |
516 | prop_ntoh (&msg->properties, | 504 | prop_ntoh(&msg->properties, |
517 | &session->data.prop); | 505 | &session->data.prop); |
518 | plugin->session_update (plugin->cls, | 506 | plugin->session_update(plugin->cls, |
519 | session->sh, | 507 | session->sh, |
520 | &session->data); | 508 | &session->data); |
521 | GNUNET_SERVICE_client_continue (c->client); | 509 | GNUNET_SERVICE_client_continue(c->client); |
522 | } | 510 | } |
523 | 511 | ||
524 | 512 | ||
@@ -529,41 +517,41 @@ handle_session_update (void *cls, | |||
529 | * @param message the request message | 517 | * @param message the request message |
530 | */ | 518 | */ |
531 | static void | 519 | static void |
532 | handle_session_del (void *cls, | 520 | handle_session_del(void *cls, |
533 | const struct SessionDelMessage *message) | 521 | const struct SessionDelMessage *message) |
534 | { | 522 | { |
535 | struct Client *c = cls; | 523 | struct Client *c = cls; |
536 | struct GNUNET_ATS_Session *session; | 524 | struct GNUNET_ATS_Session *session; |
537 | 525 | ||
538 | if (CT_TRANSPORT != c->type) | 526 | if (CT_TRANSPORT != c->type) |
539 | { | 527 | { |
540 | GNUNET_break (0); | 528 | GNUNET_break(0); |
541 | GNUNET_SERVICE_client_drop (c->client); | 529 | GNUNET_SERVICE_client_drop(c->client); |
542 | return; | 530 | return; |
543 | } | 531 | } |
544 | session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions, | 532 | session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, |
545 | message->session_id); | 533 | message->session_id); |
546 | if (NULL == session) | 534 | if (NULL == session) |
547 | { | 535 | { |
548 | GNUNET_break (0); | 536 | GNUNET_break(0); |
549 | GNUNET_SERVICE_client_drop (c->client); | 537 | GNUNET_SERVICE_client_drop(c->client); |
550 | return; | 538 | return; |
551 | } | 539 | } |
552 | GNUNET_assert (NULL != session->sh); | 540 | GNUNET_assert(NULL != session->sh); |
553 | plugin->session_del (plugin->cls, | 541 | plugin->session_del(plugin->cls, |
554 | session->sh, | 542 | session->sh, |
555 | &session->data); | 543 | &session->data); |
556 | session->sh = NULL; | 544 | session->sh = NULL; |
557 | GNUNET_assert (GNUNET_YES == | 545 | GNUNET_assert(GNUNET_YES == |
558 | GNUNET_CONTAINER_multihashmap32_remove (c->details.transport.sessions, | 546 | GNUNET_CONTAINER_multihashmap32_remove(c->details.transport.sessions, |
559 | session->session_id, | 547 | session->session_id, |
560 | session)); | 548 | session)); |
561 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 549 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
562 | "Transport lost session %p to %s\n", | 550 | "Transport lost session %p to %s\n", |
563 | session, | 551 | session, |
564 | GNUNET_i2s (&session->data.peer)); | 552 | GNUNET_i2s(&session->data.peer)); |
565 | GNUNET_free (session); | 553 | GNUNET_free(session); |
566 | GNUNET_SERVICE_client_continue (c->client); | 554 | GNUNET_SERVICE_client_continue(c->client); |
567 | } | 555 | } |
568 | 556 | ||
569 | 557 | ||
@@ -577,11 +565,11 @@ handle_session_del (void *cls, | |||
577 | * @return @a client | 565 | * @return @a client |
578 | */ | 566 | */ |
579 | static void * | 567 | static void * |
580 | client_connect_cb (void *cls, | 568 | client_connect_cb(void *cls, |
581 | struct GNUNET_SERVICE_Client *client, | 569 | struct GNUNET_SERVICE_Client *client, |
582 | struct GNUNET_MQ_Handle *mq) | 570 | struct GNUNET_MQ_Handle *mq) |
583 | { | 571 | { |
584 | struct Client *c = GNUNET_new (struct Client); | 572 | struct Client *c = GNUNET_new(struct Client); |
585 | 573 | ||
586 | c->client = client; | 574 | c->client = client; |
587 | c->mq = mq; | 575 | c->mq = mq; |
@@ -598,21 +586,21 @@ client_connect_cb (void *cls, | |||
598 | * @param value a `struct GNUNET_ATS_Session` | 586 | * @param value a `struct GNUNET_ATS_Session` |
599 | */ | 587 | */ |
600 | static int | 588 | static int |
601 | free_session (void *cls, | 589 | free_session(void *cls, |
602 | uint32_t key, | 590 | uint32_t key, |
603 | void *value) | 591 | void *value) |
604 | { | 592 | { |
605 | struct Client *c = cls; | 593 | struct Client *c = cls; |
606 | struct GNUNET_ATS_Session *session = value; | 594 | struct GNUNET_ATS_Session *session = value; |
607 | 595 | ||
608 | (void) key; | 596 | (void)key; |
609 | GNUNET_assert (c == session->client); | 597 | GNUNET_assert(c == session->client); |
610 | GNUNET_assert (NULL != session->sh); | 598 | GNUNET_assert(NULL != session->sh); |
611 | plugin->session_del (plugin->cls, | 599 | plugin->session_del(plugin->cls, |
612 | session->sh, | 600 | session->sh, |
613 | &session->data); | 601 | &session->data); |
614 | session->sh = NULL; | 602 | session->sh = NULL; |
615 | GNUNET_free (session); | 603 | GNUNET_free(session); |
616 | return GNUNET_OK; | 604 | return GNUNET_OK; |
617 | } | 605 | } |
618 | 606 | ||
@@ -626,42 +614,44 @@ free_session (void *cls, | |||
626 | * @param app_ctx our `struct Client` | 614 | * @param app_ctx our `struct Client` |
627 | */ | 615 | */ |
628 | static void | 616 | static void |
629 | client_disconnect_cb (void *cls, | 617 | client_disconnect_cb(void *cls, |
630 | struct GNUNET_SERVICE_Client *client, | 618 | struct GNUNET_SERVICE_Client *client, |
631 | void *app_ctx) | 619 | void *app_ctx) |
632 | { | 620 | { |
633 | struct Client *c = app_ctx; | 621 | struct Client *c = app_ctx; |
634 | 622 | ||
635 | (void) cls; | 623 | (void)cls; |
636 | GNUNET_assert (c->client == client); | 624 | GNUNET_assert(c->client == client); |
637 | switch (c->type) | 625 | switch (c->type) |
638 | { | ||
639 | case CT_NONE: | ||
640 | break; | ||
641 | case CT_APPLICATION: | ||
642 | for (struct ClientPreference *cp = c->details.application.cp_head; | ||
643 | NULL != cp; | ||
644 | cp = c->details.application.cp_head) | ||
645 | { | 626 | { |
646 | plugin->preference_del (plugin->cls, | 627 | case CT_NONE: |
647 | cp->ph, | 628 | break; |
648 | &cp->pref); | 629 | |
649 | GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head, | 630 | case CT_APPLICATION: |
650 | c->details.application.cp_tail, | 631 | for (struct ClientPreference *cp = c->details.application.cp_head; |
651 | cp); | 632 | NULL != cp; |
652 | GNUNET_free (cp); | 633 | cp = c->details.application.cp_head) |
634 | { | ||
635 | plugin->preference_del(plugin->cls, | ||
636 | cp->ph, | ||
637 | &cp->pref); | ||
638 | GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head, | ||
639 | c->details.application.cp_tail, | ||
640 | cp); | ||
641 | GNUNET_free(cp); | ||
642 | } | ||
643 | break; | ||
644 | |||
645 | case CT_TRANSPORT: | ||
646 | if (transport_client == c) | ||
647 | transport_client = NULL; | ||
648 | GNUNET_CONTAINER_multihashmap32_iterate(c->details.transport.sessions, | ||
649 | &free_session, | ||
650 | c); | ||
651 | GNUNET_CONTAINER_multihashmap32_destroy(c->details.transport.sessions); | ||
652 | break; | ||
653 | } | 653 | } |
654 | break; | 654 | GNUNET_free(c); |
655 | case CT_TRANSPORT: | ||
656 | if (transport_client == c) | ||
657 | transport_client = NULL; | ||
658 | GNUNET_CONTAINER_multihashmap32_iterate (c->details.transport.sessions, | ||
659 | &free_session, | ||
660 | c); | ||
661 | GNUNET_CONTAINER_multihashmap32_destroy (c->details.transport.sessions); | ||
662 | break; | ||
663 | } | ||
664 | GNUNET_free (c); | ||
665 | } | 655 | } |
666 | 656 | ||
667 | 657 | ||
@@ -671,26 +661,26 @@ client_disconnect_cb (void *cls, | |||
671 | * @param cls unused | 661 | * @param cls unused |
672 | */ | 662 | */ |
673 | static void | 663 | static void |
674 | final_cleanup (void *cls) | 664 | final_cleanup(void *cls) |
675 | { | 665 | { |
676 | (void) cls; | 666 | (void)cls; |
677 | if (NULL != stats) | 667 | if (NULL != stats) |
678 | { | 668 | { |
679 | GNUNET_STATISTICS_destroy (stats, | 669 | GNUNET_STATISTICS_destroy(stats, |
680 | GNUNET_NO); | 670 | GNUNET_NO); |
681 | stats = NULL; | 671 | stats = NULL; |
682 | } | 672 | } |
683 | if (NULL != plugin) | 673 | if (NULL != plugin) |
684 | { | 674 | { |
685 | GNUNET_PLUGIN_unload (plugin_name, | 675 | GNUNET_PLUGIN_unload(plugin_name, |
686 | plugin); | 676 | plugin); |
687 | plugin = NULL; | 677 | plugin = NULL; |
688 | } | 678 | } |
689 | if (NULL != plugin_name) | 679 | if (NULL != plugin_name) |
690 | { | 680 | { |
691 | GNUNET_free (plugin_name); | 681 | GNUNET_free(plugin_name); |
692 | plugin_name = NULL; | 682 | plugin_name = NULL; |
693 | } | 683 | } |
694 | } | 684 | } |
695 | 685 | ||
696 | 686 | ||
@@ -700,13 +690,13 @@ final_cleanup (void *cls) | |||
700 | * @param cls unused | 690 | * @param cls unused |
701 | */ | 691 | */ |
702 | static void | 692 | static void |
703 | cleanup_task (void *cls) | 693 | cleanup_task(void *cls) |
704 | { | 694 | { |
705 | (void) cls; | 695 | (void)cls; |
706 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 696 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
707 | "ATS shutdown initiated\n"); | 697 | "ATS shutdown initiated\n"); |
708 | GNUNET_SCHEDULER_add_now (&final_cleanup, | 698 | GNUNET_SCHEDULER_add_now(&final_cleanup, |
709 | NULL); | 699 | NULL); |
710 | } | 700 | } |
711 | 701 | ||
712 | 702 | ||
@@ -718,45 +708,45 @@ cleanup_task (void *cls) | |||
718 | * @param service the initialized service | 708 | * @param service the initialized service |
719 | */ | 709 | */ |
720 | static void | 710 | static void |
721 | run (void *cls, | 711 | run(void *cls, |
722 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 712 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
723 | struct GNUNET_SERVICE_Handle *service) | 713 | struct GNUNET_SERVICE_Handle *service) |
724 | { | 714 | { |
725 | static struct GNUNET_ATS_PluginEnvironment env; | 715 | static struct GNUNET_ATS_PluginEnvironment env; |
726 | char *solver; | 716 | char *solver; |
727 | 717 | ||
728 | stats = GNUNET_STATISTICS_create ("ats", | 718 | stats = GNUNET_STATISTICS_create("ats", |
729 | cfg); | 719 | cfg); |
730 | if (GNUNET_SYSERR == | 720 | if (GNUNET_SYSERR == |
731 | GNUNET_CONFIGURATION_get_value_string (cfg, | 721 | GNUNET_CONFIGURATION_get_value_string(cfg, |
732 | "ats", | 722 | "ats", |
733 | "SOLVER", | 723 | "SOLVER", |
734 | &solver)) | 724 | &solver)) |
735 | { | 725 | { |
736 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 726 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
737 | "No ATS solver configured, using 'simple' approach\n"); | 727 | "No ATS solver configured, using 'simple' approach\n"); |
738 | solver = GNUNET_strdup ("simple"); | 728 | solver = GNUNET_strdup("simple"); |
739 | } | 729 | } |
740 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 730 | GNUNET_SCHEDULER_add_shutdown(&cleanup_task, |
741 | NULL); | 731 | NULL); |
742 | env.cls = NULL; | 732 | env.cls = NULL; |
743 | env.cfg = cfg; | 733 | env.cfg = cfg; |
744 | env.stats = stats; | 734 | env.stats = stats; |
745 | env.suggest_cb = &suggest_cb; | 735 | env.suggest_cb = &suggest_cb; |
746 | env.allocate_cb = &allocate_cb; | 736 | env.allocate_cb = &allocate_cb; |
747 | GNUNET_asprintf (&plugin_name, | 737 | GNUNET_asprintf(&plugin_name, |
748 | "libgnunet_plugin_ats2_%s", | 738 | "libgnunet_plugin_ats2_%s", |
749 | solver); | 739 | solver); |
750 | GNUNET_free (solver); | 740 | GNUNET_free(solver); |
751 | if (NULL == (plugin = GNUNET_PLUGIN_load (plugin_name, | 741 | if (NULL == (plugin = GNUNET_PLUGIN_load(plugin_name, |
752 | &env))) | 742 | &env))) |
753 | { | 743 | { |
754 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 744 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
755 | _("Failed to initialize solver `%s'!\n"), | 745 | _("Failed to initialize solver `%s'!\n"), |
756 | plugin_name); | 746 | plugin_name); |
757 | GNUNET_SCHEDULER_shutdown (); | 747 | GNUNET_SCHEDULER_shutdown(); |
758 | return; | 748 | return; |
759 | } | 749 | } |
760 | } | 750 | } |
761 | 751 | ||
762 | 752 | ||
@@ -764,41 +754,41 @@ run (void *cls, | |||
764 | * Define "main" method using service macro. | 754 | * Define "main" method using service macro. |
765 | */ | 755 | */ |
766 | GNUNET_SERVICE_MAIN | 756 | GNUNET_SERVICE_MAIN |
767 | ("ats", | 757 | ("ats", |
768 | GNUNET_SERVICE_OPTION_NONE, | 758 | GNUNET_SERVICE_OPTION_NONE, |
769 | &run, | 759 | &run, |
770 | &client_connect_cb, | 760 | &client_connect_cb, |
771 | &client_disconnect_cb, | 761 | &client_disconnect_cb, |
772 | NULL, | 762 | NULL, |
773 | GNUNET_MQ_hd_fixed_size (suggest, | 763 | GNUNET_MQ_hd_fixed_size(suggest, |
774 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST, | 764 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST, |
775 | struct ExpressPreferenceMessage, | 765 | struct ExpressPreferenceMessage, |
776 | NULL), | 766 | NULL), |
777 | GNUNET_MQ_hd_fixed_size (suggest_cancel, | 767 | GNUNET_MQ_hd_fixed_size(suggest_cancel, |
778 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, | 768 | GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, |
779 | struct ExpressPreferenceMessage, | 769 | struct ExpressPreferenceMessage, |
780 | NULL), | 770 | NULL), |
781 | GNUNET_MQ_hd_fixed_size (start, | 771 | GNUNET_MQ_hd_fixed_size(start, |
782 | GNUNET_MESSAGE_TYPE_ATS_START, | 772 | GNUNET_MESSAGE_TYPE_ATS_START, |
783 | struct GNUNET_MessageHeader, | 773 | struct GNUNET_MessageHeader, |
784 | NULL), | 774 | NULL), |
785 | GNUNET_MQ_hd_var_size (session_add, | 775 | GNUNET_MQ_hd_var_size(session_add, |
786 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, | 776 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, |
787 | struct SessionAddMessage, | 777 | struct SessionAddMessage, |
788 | NULL), | 778 | NULL), |
789 | GNUNET_MQ_hd_var_size (session_add, | 779 | GNUNET_MQ_hd_var_size(session_add, |
790 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, | 780 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, |
791 | struct SessionAddMessage, | 781 | struct SessionAddMessage, |
792 | NULL), | 782 | NULL), |
793 | GNUNET_MQ_hd_fixed_size (session_update, | 783 | GNUNET_MQ_hd_fixed_size(session_update, |
794 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, | 784 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, |
795 | struct SessionUpdateMessage, | 785 | struct SessionUpdateMessage, |
796 | NULL), | 786 | NULL), |
797 | GNUNET_MQ_hd_fixed_size (session_del, | 787 | GNUNET_MQ_hd_fixed_size(session_del, |
798 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, | 788 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, |
799 | struct SessionDelMessage, | 789 | struct SessionDelMessage, |
800 | NULL), | 790 | NULL), |
801 | GNUNET_MQ_handler_end ()); | 791 | GNUNET_MQ_handler_end()); |
802 | 792 | ||
803 | 793 | ||
804 | /* end of gnunet-service-ats.c */ | 794 | /* end of gnunet-service-ats.c */ |
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 2dc3edea6..d9bb71c2b 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats.c | 21 | * @file ats/gnunet-service-ats.c |
22 | * @brief ats service | 22 | * @brief ats service |
@@ -50,43 +50,47 @@ struct GNUNET_STATISTICS_Handle *GSA_stats; | |||
50 | * @param msg the start message | 50 | * @param msg the start message |
51 | */ | 51 | */ |
52 | static void | 52 | static void |
53 | handle_ats_start (void *cls, | 53 | handle_ats_start(void *cls, |
54 | const struct ClientStartMessage *msg) | 54 | const struct ClientStartMessage *msg) |
55 | { | 55 | { |
56 | struct GNUNET_SERVICE_Client *client = cls; | 56 | struct GNUNET_SERVICE_Client *client = cls; |
57 | enum StartFlag flag; | 57 | enum StartFlag flag; |
58 | 58 | ||
59 | flag = ntohl (msg->start_flag); | 59 | flag = ntohl(msg->start_flag); |
60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 60 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
61 | "Received ATS_START (%d) message\n", | 61 | "Received ATS_START (%d) message\n", |
62 | (int) flag); | 62 | (int)flag); |
63 | switch (flag) | 63 | switch (flag) |
64 | { | ||
65 | case START_FLAG_SCHEDULING: | ||
66 | if (GNUNET_OK != | ||
67 | GAS_scheduling_add_client (client)) | ||
68 | { | 64 | { |
69 | GNUNET_SERVICE_client_drop (client); | 65 | case START_FLAG_SCHEDULING: |
66 | if (GNUNET_OK != | ||
67 | GAS_scheduling_add_client(client)) | ||
68 | { | ||
69 | GNUNET_SERVICE_client_drop(client); | ||
70 | return; | ||
71 | } | ||
72 | break; | ||
73 | |||
74 | case START_FLAG_PERFORMANCE_WITH_PIC: | ||
75 | GAS_performance_add_client(client, | ||
76 | flag); | ||
77 | break; | ||
78 | |||
79 | case START_FLAG_PERFORMANCE_NO_PIC: | ||
80 | GAS_performance_add_client(client, | ||
81 | flag); | ||
82 | break; | ||
83 | |||
84 | case START_FLAG_CONNECTION_SUGGESTION: | ||
85 | /* This client won't receive messages from us, no need to 'add' */ | ||
86 | break; | ||
87 | |||
88 | default: | ||
89 | GNUNET_break(0); | ||
90 | GNUNET_SERVICE_client_drop(client); | ||
70 | return; | 91 | return; |
71 | } | 92 | } |
72 | break; | 93 | GNUNET_SERVICE_client_continue(client); |
73 | case START_FLAG_PERFORMANCE_WITH_PIC: | ||
74 | GAS_performance_add_client (client, | ||
75 | flag); | ||
76 | break; | ||
77 | case START_FLAG_PERFORMANCE_NO_PIC: | ||
78 | GAS_performance_add_client (client, | ||
79 | flag); | ||
80 | break; | ||
81 | case START_FLAG_CONNECTION_SUGGESTION: | ||
82 | /* This client won't receive messages from us, no need to 'add' */ | ||
83 | break; | ||
84 | default: | ||
85 | GNUNET_break (0); | ||
86 | GNUNET_SERVICE_client_drop (client); | ||
87 | return; | ||
88 | } | ||
89 | GNUNET_SERVICE_client_continue (client); | ||
90 | } | 94 | } |
91 | 95 | ||
92 | 96 | ||
@@ -98,14 +102,14 @@ handle_ats_start (void *cls, | |||
98 | * @param message the request message | 102 | * @param message the request message |
99 | */ | 103 | */ |
100 | static void | 104 | static void |
101 | handle_reservation_request (void *cls, | 105 | handle_reservation_request(void *cls, |
102 | const struct ReservationRequestMessage *message) | 106 | const struct ReservationRequestMessage *message) |
103 | { | 107 | { |
104 | struct GNUNET_SERVICE_Client *client = cls; | 108 | struct GNUNET_SERVICE_Client *client = cls; |
105 | 109 | ||
106 | GAS_handle_reservation_request (client, | 110 | GAS_handle_reservation_request(client, |
107 | message); | 111 | message); |
108 | GNUNET_SERVICE_client_continue (client); | 112 | GNUNET_SERVICE_client_continue(client); |
109 | } | 113 | } |
110 | 114 | ||
111 | 115 | ||
@@ -117,23 +121,23 @@ handle_reservation_request (void *cls, | |||
117 | * @return #GNUNET_OK if @a message is well-formed | 121 | * @return #GNUNET_OK if @a message is well-formed |
118 | */ | 122 | */ |
119 | static int | 123 | static int |
120 | check_feedback (void *cls, | 124 | check_feedback(void *cls, |
121 | const struct FeedbackPreferenceMessage *message) | 125 | const struct FeedbackPreferenceMessage *message) |
122 | { | 126 | { |
123 | uint16_t msize; | 127 | uint16_t msize; |
124 | uint32_t nump; | 128 | uint32_t nump; |
125 | 129 | ||
126 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 130 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
127 | "Received PREFERENCE_FEEDBACK message\n"); | 131 | "Received PREFERENCE_FEEDBACK message\n"); |
128 | msize = ntohs (message->header.size); | 132 | msize = ntohs(message->header.size); |
129 | nump = ntohl (message->num_feedback); | 133 | nump = ntohl(message->num_feedback); |
130 | if (msize != | 134 | if (msize != |
131 | sizeof (struct FeedbackPreferenceMessage) + | 135 | sizeof(struct FeedbackPreferenceMessage) + |
132 | nump * sizeof (struct PreferenceInformation)) | 136 | nump * sizeof(struct PreferenceInformation)) |
133 | { | 137 | { |
134 | GNUNET_break (0); | 138 | GNUNET_break(0); |
135 | return GNUNET_SYSERR; | 139 | return GNUNET_SYSERR; |
136 | } | 140 | } |
137 | return GNUNET_OK; | 141 | return GNUNET_OK; |
138 | } | 142 | } |
139 | 143 | ||
@@ -145,42 +149,42 @@ check_feedback (void *cls, | |||
145 | * @param msg the request message | 149 | * @param msg the request message |
146 | */ | 150 | */ |
147 | static void | 151 | static void |
148 | handle_feedback (void *cls, | 152 | handle_feedback(void *cls, |
149 | const struct FeedbackPreferenceMessage *msg) | 153 | const struct FeedbackPreferenceMessage *msg) |
150 | { | 154 | { |
151 | struct GNUNET_SERVICE_Client *client = cls; | 155 | struct GNUNET_SERVICE_Client *client = cls; |
152 | const struct PreferenceInformation *pi; | 156 | const struct PreferenceInformation *pi; |
153 | uint32_t nump; | 157 | uint32_t nump; |
154 | 158 | ||
155 | nump = ntohl (msg->num_feedback); | 159 | nump = ntohl(msg->num_feedback); |
156 | if (GNUNET_NO == | 160 | if (GNUNET_NO == |
157 | GNUNET_CONTAINER_multipeermap_contains (GSA_addresses, | 161 | GNUNET_CONTAINER_multipeermap_contains(GSA_addresses, |
158 | &msg->peer)) | 162 | &msg->peer)) |
159 | { | 163 | { |
160 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 164 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
161 | "Received PREFERENCE FEEDBACK for unknown peer `%s'\n", | 165 | "Received PREFERENCE FEEDBACK for unknown peer `%s'\n", |
162 | GNUNET_i2s (&msg->peer)); | 166 | GNUNET_i2s(&msg->peer)); |
163 | GNUNET_SERVICE_client_continue (client); | 167 | GNUNET_SERVICE_client_continue(client); |
164 | return; | 168 | return; |
165 | } | 169 | } |
166 | 170 | ||
167 | GNUNET_STATISTICS_update (GSA_stats, | 171 | GNUNET_STATISTICS_update(GSA_stats, |
168 | "# preference feedbacks requests processed", | 172 | "# preference feedbacks requests processed", |
169 | 1, | 173 | 1, |
170 | GNUNET_NO); | 174 | GNUNET_NO); |
171 | pi = (const struct PreferenceInformation *) &msg[1]; | 175 | pi = (const struct PreferenceInformation *)&msg[1]; |
172 | for (uint32_t i = 0; i < nump; i++) | 176 | for (uint32_t i = 0; i < nump; i++) |
173 | { | 177 | { |
174 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 178 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
175 | "Received PREFERENCE FEEDBACK for peer `%s'\n", | 179 | "Received PREFERENCE FEEDBACK for peer `%s'\n", |
176 | GNUNET_i2s (&msg->peer)); | 180 | GNUNET_i2s(&msg->peer)); |
177 | GAS_plugin_notify_feedback (client, | 181 | GAS_plugin_notify_feedback(client, |
178 | &msg->peer, | 182 | &msg->peer, |
179 | GNUNET_TIME_relative_ntoh (msg->scope), | 183 | GNUNET_TIME_relative_ntoh(msg->scope), |
180 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), | 184 | (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind), |
181 | pi[i].preference_value); | 185 | pi[i].preference_value); |
182 | } | 186 | } |
183 | GNUNET_SERVICE_client_continue (client); | 187 | GNUNET_SERVICE_client_continue(client); |
184 | } | 188 | } |
185 | 189 | ||
186 | 190 | ||
@@ -191,14 +195,14 @@ handle_feedback (void *cls, | |||
191 | * @param message the request message | 195 | * @param message the request message |
192 | */ | 196 | */ |
193 | static void | 197 | static void |
194 | handle_request_address_list (void *cls, | 198 | handle_request_address_list(void *cls, |
195 | const struct AddressListRequestMessage *message) | 199 | const struct AddressListRequestMessage *message) |
196 | { | 200 | { |
197 | struct GNUNET_SERVICE_Client *client = cls; | 201 | struct GNUNET_SERVICE_Client *client = cls; |
198 | 202 | ||
199 | GAS_handle_request_address_list (client, | 203 | GAS_handle_request_address_list(client, |
200 | message); | 204 | message); |
201 | GNUNET_SERVICE_client_continue (client); | 205 | GNUNET_SERVICE_client_continue(client); |
202 | } | 206 | } |
203 | 207 | ||
204 | 208 | ||
@@ -209,14 +213,14 @@ handle_request_address_list (void *cls, | |||
209 | * @param message the request message | 213 | * @param message the request message |
210 | */ | 214 | */ |
211 | static void | 215 | static void |
212 | handle_request_address (void *cls, | 216 | handle_request_address(void *cls, |
213 | const struct RequestAddressMessage * message) | 217 | const struct RequestAddressMessage * message) |
214 | { | 218 | { |
215 | struct GNUNET_SERVICE_Client *client = cls; | 219 | struct GNUNET_SERVICE_Client *client = cls; |
216 | 220 | ||
217 | GAS_handle_request_address (client, | 221 | GAS_handle_request_address(client, |
218 | message); | 222 | message); |
219 | GNUNET_SERVICE_client_continue (client); | 223 | GNUNET_SERVICE_client_continue(client); |
220 | } | 224 | } |
221 | 225 | ||
222 | 226 | ||
@@ -227,14 +231,14 @@ handle_request_address (void *cls, | |||
227 | * @param message the request message | 231 | * @param message the request message |
228 | */ | 232 | */ |
229 | static void | 233 | static void |
230 | handle_request_address_cancel (void *cls, | 234 | handle_request_address_cancel(void *cls, |
231 | const struct RequestAddressMessage *message) | 235 | const struct RequestAddressMessage *message) |
232 | { | 236 | { |
233 | struct GNUNET_SERVICE_Client *client = cls; | 237 | struct GNUNET_SERVICE_Client *client = cls; |
234 | 238 | ||
235 | GAS_handle_request_address_cancel (client, | 239 | GAS_handle_request_address_cancel(client, |
236 | message); | 240 | message); |
237 | GNUNET_SERVICE_client_continue (client); | 241 | GNUNET_SERVICE_client_continue(client); |
238 | } | 242 | } |
239 | 243 | ||
240 | 244 | ||
@@ -245,8 +249,8 @@ handle_request_address_cancel (void *cls, | |||
245 | * @param m the request message | 249 | * @param m the request message |
246 | */ | 250 | */ |
247 | static int | 251 | static int |
248 | check_address_add (void *cls, | 252 | check_address_add(void *cls, |
249 | const struct AddressAddMessage *m) | 253 | const struct AddressAddMessage *m) |
250 | { | 254 | { |
251 | const char *address; | 255 | const char *address; |
252 | const char *plugin_name; | 256 | const char *plugin_name; |
@@ -254,23 +258,23 @@ check_address_add (void *cls, | |||
254 | uint16_t plugin_name_length; | 258 | uint16_t plugin_name_length; |
255 | uint16_t size; | 259 | uint16_t size; |
256 | 260 | ||
257 | size = ntohs (m->header.size); | 261 | size = ntohs(m->header.size); |
258 | address_length = ntohs (m->address_length); | 262 | address_length = ntohs(m->address_length); |
259 | plugin_name_length = ntohs (m->plugin_name_length); | 263 | plugin_name_length = ntohs(m->plugin_name_length); |
260 | address = (const char *) &m[1]; | 264 | address = (const char *)&m[1]; |
261 | if (plugin_name_length != 0) | 265 | if (plugin_name_length != 0) |
262 | plugin_name = &address[address_length]; | 266 | plugin_name = &address[address_length]; |
263 | else | 267 | else |
264 | plugin_name = ""; | 268 | plugin_name = ""; |
265 | 269 | ||
266 | if ( (address_length + plugin_name_length + | 270 | if ((address_length + plugin_name_length + |
267 | sizeof (struct AddressAddMessage) != size) || | 271 | sizeof(struct AddressAddMessage) != size) || |
268 | ( (plugin_name_length > 0) && | 272 | ((plugin_name_length > 0) && |
269 | (plugin_name[plugin_name_length - 1] != '\0') ) ) | 273 | (plugin_name[plugin_name_length - 1] != '\0'))) |
270 | { | 274 | { |
271 | GNUNET_break (0); | 275 | GNUNET_break(0); |
272 | return GNUNET_SYSERR; | 276 | return GNUNET_SYSERR; |
273 | } | 277 | } |
274 | return GNUNET_OK; | 278 | return GNUNET_OK; |
275 | } | 279 | } |
276 | 280 | ||
@@ -282,13 +286,13 @@ check_address_add (void *cls, | |||
282 | * @param message the request message | 286 | * @param message the request message |
283 | */ | 287 | */ |
284 | static void | 288 | static void |
285 | handle_address_add (void *cls, | 289 | handle_address_add(void *cls, |
286 | const struct AddressAddMessage *message) | 290 | const struct AddressAddMessage *message) |
287 | { | 291 | { |
288 | struct GNUNET_SERVICE_Client *client = cls; | 292 | struct GNUNET_SERVICE_Client *client = cls; |
289 | 293 | ||
290 | GAS_handle_address_add (message); | 294 | GAS_handle_address_add(message); |
291 | GNUNET_SERVICE_client_continue (client); | 295 | GNUNET_SERVICE_client_continue(client); |
292 | } | 296 | } |
293 | 297 | ||
294 | 298 | ||
@@ -299,13 +303,13 @@ handle_address_add (void *cls, | |||
299 | * @param message the request message | 303 | * @param message the request message |
300 | */ | 304 | */ |
301 | static void | 305 | static void |
302 | handle_address_update (void *cls, | 306 | handle_address_update(void *cls, |
303 | const struct AddressUpdateMessage *message) | 307 | const struct AddressUpdateMessage *message) |
304 | { | 308 | { |
305 | struct GNUNET_SERVICE_Client *client = cls; | 309 | struct GNUNET_SERVICE_Client *client = cls; |
306 | 310 | ||
307 | GAS_handle_address_update (message); | 311 | GAS_handle_address_update(message); |
308 | GNUNET_SERVICE_client_continue (client); | 312 | GNUNET_SERVICE_client_continue(client); |
309 | } | 313 | } |
310 | 314 | ||
311 | 315 | ||
@@ -316,13 +320,13 @@ handle_address_update (void *cls, | |||
316 | * @param message the request message | 320 | * @param message the request message |
317 | */ | 321 | */ |
318 | static void | 322 | static void |
319 | handle_address_destroyed (void *cls, | 323 | handle_address_destroyed(void *cls, |
320 | const struct AddressDestroyedMessage *message) | 324 | const struct AddressDestroyedMessage *message) |
321 | { | 325 | { |
322 | struct GNUNET_SERVICE_Client *client = cls; | 326 | struct GNUNET_SERVICE_Client *client = cls; |
323 | 327 | ||
324 | GAS_handle_address_destroyed (message); | 328 | GAS_handle_address_destroyed(message); |
325 | GNUNET_SERVICE_client_continue (client); | 329 | GNUNET_SERVICE_client_continue(client); |
326 | } | 330 | } |
327 | 331 | ||
328 | 332 | ||
@@ -334,22 +338,22 @@ handle_address_destroyed (void *cls, | |||
334 | * @return #GNUNET_OK if @a message is well-formed | 338 | * @return #GNUNET_OK if @a message is well-formed |
335 | */ | 339 | */ |
336 | static int | 340 | static int |
337 | check_preference_change (void *cls, | 341 | check_preference_change(void *cls, |
338 | const struct ChangePreferenceMessage *message) | 342 | const struct ChangePreferenceMessage *message) |
339 | { | 343 | { |
340 | uint16_t msize; | 344 | uint16_t msize; |
341 | uint32_t nump; | 345 | uint32_t nump; |
342 | 346 | ||
343 | msize = ntohs (message->header.size); | 347 | msize = ntohs(message->header.size); |
344 | nump = ntohl (message->num_preferences); | 348 | nump = ntohl(message->num_preferences); |
345 | if ( (msize != | 349 | if ((msize != |
346 | sizeof (struct ChangePreferenceMessage) + | 350 | sizeof(struct ChangePreferenceMessage) + |
347 | nump * sizeof (struct PreferenceInformation)) || | 351 | nump * sizeof(struct PreferenceInformation)) || |
348 | (UINT16_MAX / sizeof (struct PreferenceInformation) < nump) ) | 352 | (UINT16_MAX / sizeof(struct PreferenceInformation) < nump)) |
349 | { | 353 | { |
350 | GNUNET_break (0); | 354 | GNUNET_break(0); |
351 | return GNUNET_SYSERR; | 355 | return GNUNET_SYSERR; |
352 | } | 356 | } |
353 | return GNUNET_OK; | 357 | return GNUNET_OK; |
354 | } | 358 | } |
355 | 359 | ||
@@ -361,14 +365,14 @@ check_preference_change (void *cls, | |||
361 | * @param message the request message | 365 | * @param message the request message |
362 | */ | 366 | */ |
363 | static void | 367 | static void |
364 | handle_preference_change (void *cls, | 368 | handle_preference_change(void *cls, |
365 | const struct ChangePreferenceMessage *message) | 369 | const struct ChangePreferenceMessage *message) |
366 | { | 370 | { |
367 | struct GNUNET_SERVICE_Client *client = cls; | 371 | struct GNUNET_SERVICE_Client *client = cls; |
368 | 372 | ||
369 | GAS_handle_preference_change (client, | 373 | GAS_handle_preference_change(client, |
370 | message); | 374 | message); |
371 | GNUNET_SERVICE_client_continue (client); | 375 | GNUNET_SERVICE_client_continue(client); |
372 | } | 376 | } |
373 | 377 | ||
374 | 378 | ||
@@ -382,9 +386,9 @@ handle_preference_change (void *cls, | |||
382 | * @return @a client | 386 | * @return @a client |
383 | */ | 387 | */ |
384 | static void * | 388 | static void * |
385 | client_connect_cb (void *cls, | 389 | client_connect_cb(void *cls, |
386 | struct GNUNET_SERVICE_Client *client, | 390 | struct GNUNET_SERVICE_Client *client, |
387 | struct GNUNET_MQ_Handle *mq) | 391 | struct GNUNET_MQ_Handle *mq) |
388 | { | 392 | { |
389 | return client; | 393 | return client; |
390 | } | 394 | } |
@@ -399,15 +403,15 @@ client_connect_cb (void *cls, | |||
399 | * @param app_ctx | 403 | * @param app_ctx |
400 | */ | 404 | */ |
401 | static void | 405 | static void |
402 | client_disconnect_cb (void *cls, | 406 | client_disconnect_cb(void *cls, |
403 | struct GNUNET_SERVICE_Client *client, | 407 | struct GNUNET_SERVICE_Client *client, |
404 | void *app_ctx) | 408 | void *app_ctx) |
405 | { | 409 | { |
406 | if (NULL == client) | 410 | if (NULL == client) |
407 | return; | 411 | return; |
408 | GAS_scheduling_remove_client (client); | 412 | GAS_scheduling_remove_client(client); |
409 | GAS_connectivity_remove_client (client); | 413 | GAS_connectivity_remove_client(client); |
410 | GAS_preference_client_disconnect (client); | 414 | GAS_preference_client_disconnect(client); |
411 | } | 415 | } |
412 | 416 | ||
413 | 417 | ||
@@ -417,22 +421,22 @@ client_disconnect_cb (void *cls, | |||
417 | * @param cls unused | 421 | * @param cls unused |
418 | */ | 422 | */ |
419 | static void | 423 | static void |
420 | cleanup_task (void *cls) | 424 | cleanup_task(void *cls) |
421 | { | 425 | { |
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 426 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
423 | "ATS shutdown initiated\n"); | 427 | "ATS shutdown initiated\n"); |
424 | GAS_connectivity_done (); | 428 | GAS_connectivity_done(); |
425 | GAS_addresses_done (); | 429 | GAS_addresses_done(); |
426 | GAS_plugin_done (); | 430 | GAS_plugin_done(); |
427 | GAS_normalization_stop (); | 431 | GAS_normalization_stop(); |
428 | GAS_performance_done (); | 432 | GAS_performance_done(); |
429 | GAS_preference_done (); | 433 | GAS_preference_done(); |
430 | GAS_reservations_done (); | 434 | GAS_reservations_done(); |
431 | if (NULL != GSA_stats) | 435 | if (NULL != GSA_stats) |
432 | { | 436 | { |
433 | GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO); | 437 | GNUNET_STATISTICS_destroy(GSA_stats, GNUNET_NO); |
434 | GSA_stats = NULL; | 438 | GSA_stats = NULL; |
435 | } | 439 | } |
436 | } | 440 | } |
437 | 441 | ||
438 | 442 | ||
@@ -444,37 +448,37 @@ cleanup_task (void *cls) | |||
444 | * @param service the initialized service | 448 | * @param service the initialized service |
445 | */ | 449 | */ |
446 | static void | 450 | static void |
447 | run (void *cls, | 451 | run(void *cls, |
448 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 452 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
449 | struct GNUNET_SERVICE_Handle *service) | 453 | struct GNUNET_SERVICE_Handle *service) |
450 | { | 454 | { |
451 | GSA_stats = GNUNET_STATISTICS_create ("ats", | 455 | GSA_stats = GNUNET_STATISTICS_create("ats", |
452 | cfg); | 456 | cfg); |
453 | GAS_reservations_init (); | 457 | GAS_reservations_init(); |
454 | GAS_connectivity_init (); | 458 | GAS_connectivity_init(); |
455 | GAS_preference_init (); | 459 | GAS_preference_init(); |
456 | GAS_normalization_start (); | 460 | GAS_normalization_start(); |
457 | GAS_addresses_init (); | 461 | GAS_addresses_init(); |
458 | if (GNUNET_OK != | 462 | if (GNUNET_OK != |
459 | GAS_plugin_init (cfg)) | 463 | GAS_plugin_init(cfg)) |
460 | { | ||
461 | GNUNET_break (0); | ||
462 | GAS_addresses_done (); | ||
463 | GAS_normalization_stop (); | ||
464 | GAS_reservations_done (); | ||
465 | GAS_connectivity_done (); | ||
466 | GAS_preference_done (); | ||
467 | if (NULL != GSA_stats) | ||
468 | { | 464 | { |
469 | GNUNET_STATISTICS_destroy (GSA_stats, | 465 | GNUNET_break(0); |
470 | GNUNET_NO); | 466 | GAS_addresses_done(); |
471 | GSA_stats = NULL; | 467 | GAS_normalization_stop(); |
468 | GAS_reservations_done(); | ||
469 | GAS_connectivity_done(); | ||
470 | GAS_preference_done(); | ||
471 | if (NULL != GSA_stats) | ||
472 | { | ||
473 | GNUNET_STATISTICS_destroy(GSA_stats, | ||
474 | GNUNET_NO); | ||
475 | GSA_stats = NULL; | ||
476 | } | ||
477 | return; | ||
472 | } | 478 | } |
473 | return; | 479 | GAS_performance_init(); |
474 | } | 480 | GNUNET_SCHEDULER_add_shutdown(&cleanup_task, |
475 | GAS_performance_init (); | 481 | NULL); |
476 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | ||
477 | NULL); | ||
478 | } | 482 | } |
479 | 483 | ||
480 | 484 | ||
@@ -482,53 +486,53 @@ run (void *cls, | |||
482 | * Define "main" method using service macro. | 486 | * Define "main" method using service macro. |
483 | */ | 487 | */ |
484 | GNUNET_SERVICE_MAIN | 488 | GNUNET_SERVICE_MAIN |
485 | ("ats", | 489 | ("ats", |
486 | GNUNET_SERVICE_OPTION_NONE, | 490 | GNUNET_SERVICE_OPTION_NONE, |
487 | &run, | 491 | &run, |
488 | &client_connect_cb, | 492 | &client_connect_cb, |
489 | &client_disconnect_cb, | 493 | &client_disconnect_cb, |
490 | NULL, | 494 | NULL, |
491 | GNUNET_MQ_hd_fixed_size (ats_start, | 495 | GNUNET_MQ_hd_fixed_size(ats_start, |
492 | GNUNET_MESSAGE_TYPE_ATS_START, | 496 | GNUNET_MESSAGE_TYPE_ATS_START, |
493 | struct ClientStartMessage, | 497 | struct ClientStartMessage, |
494 | NULL), | 498 | NULL), |
495 | GNUNET_MQ_hd_fixed_size (request_address, | 499 | GNUNET_MQ_hd_fixed_size(request_address, |
496 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, | 500 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, |
497 | struct RequestAddressMessage, | 501 | struct RequestAddressMessage, |
498 | NULL), | 502 | NULL), |
499 | GNUNET_MQ_hd_fixed_size (request_address_cancel, | 503 | GNUNET_MQ_hd_fixed_size(request_address_cancel, |
500 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL, | 504 | GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL, |
501 | struct RequestAddressMessage, | 505 | struct RequestAddressMessage, |
502 | NULL), | 506 | NULL), |
503 | GNUNET_MQ_hd_fixed_size (request_address_list, | 507 | GNUNET_MQ_hd_fixed_size(request_address_list, |
504 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST, | 508 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST, |
505 | struct AddressListRequestMessage, | 509 | struct AddressListRequestMessage, |
506 | NULL), | 510 | NULL), |
507 | GNUNET_MQ_hd_var_size (address_add, | 511 | GNUNET_MQ_hd_var_size(address_add, |
508 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, | 512 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, |
509 | struct AddressAddMessage, | 513 | struct AddressAddMessage, |
510 | NULL), | 514 | NULL), |
511 | GNUNET_MQ_hd_fixed_size (address_update, | 515 | GNUNET_MQ_hd_fixed_size(address_update, |
512 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, | 516 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, |
513 | struct AddressUpdateMessage, | 517 | struct AddressUpdateMessage, |
514 | NULL), | 518 | NULL), |
515 | GNUNET_MQ_hd_fixed_size (address_destroyed, | 519 | GNUNET_MQ_hd_fixed_size(address_destroyed, |
516 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, | 520 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, |
517 | struct AddressDestroyedMessage, | 521 | struct AddressDestroyedMessage, |
518 | NULL), | 522 | NULL), |
519 | GNUNET_MQ_hd_fixed_size (reservation_request, | 523 | GNUNET_MQ_hd_fixed_size(reservation_request, |
520 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, | 524 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, |
521 | struct ReservationRequestMessage, | 525 | struct ReservationRequestMessage, |
522 | NULL), | 526 | NULL), |
523 | GNUNET_MQ_hd_var_size (preference_change, | 527 | GNUNET_MQ_hd_var_size(preference_change, |
524 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, | 528 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, |
525 | struct ChangePreferenceMessage, | 529 | struct ChangePreferenceMessage, |
526 | NULL), | 530 | NULL), |
527 | GNUNET_MQ_hd_var_size (feedback, | 531 | GNUNET_MQ_hd_var_size(feedback, |
528 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, | 532 | GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, |
529 | struct FeedbackPreferenceMessage, | 533 | struct FeedbackPreferenceMessage, |
530 | NULL), | 534 | NULL), |
531 | GNUNET_MQ_handler_end ()); | 535 | GNUNET_MQ_handler_end()); |
532 | 536 | ||
533 | 537 | ||
534 | /* end of gnunet-service-ats.c */ | 538 | /* end of gnunet-service-ats.c */ |
diff --git a/src/ats/gnunet-service-ats.h b/src/ats/gnunet-service-ats.h index 521a460ff..6abe57fdb 100644 --- a/src/ats/gnunet-service-ats.h +++ b/src/ats/gnunet-service-ats.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats.h | 22 | * @file ats/gnunet-service-ats.h |
@@ -31,7 +31,7 @@ | |||
31 | 31 | ||
32 | #define GAS_normalization_queue_length 3 | 32 | #define GAS_normalization_queue_length 3 |
33 | 33 | ||
34 | #define BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init (0) | 34 | #define BANDWIDTH_ZERO GNUNET_BANDWIDTH_value_init(0) |
35 | 35 | ||
36 | /** | 36 | /** |
37 | * Handle for statistics. | 37 | * Handle for statistics. |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index efe968024..8ca245b1e 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015 GNUnet e.V. | 3 | Copyright (C) 2011-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -41,12 +41,12 @@ struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses; | |||
41 | * Update statistic on number of addresses. | 41 | * Update statistic on number of addresses. |
42 | */ | 42 | */ |
43 | static void | 43 | static void |
44 | update_addresses_stat () | 44 | update_addresses_stat() |
45 | { | 45 | { |
46 | GNUNET_STATISTICS_set (GSA_stats, | 46 | GNUNET_STATISTICS_set(GSA_stats, |
47 | "# addresses", | 47 | "# addresses", |
48 | GNUNET_CONTAINER_multipeermap_size (GSA_addresses), | 48 | GNUNET_CONTAINER_multipeermap_size(GSA_addresses), |
49 | GNUNET_NO); | 49 | GNUNET_NO); |
50 | } | 50 | } |
51 | 51 | ||
52 | 52 | ||
@@ -56,25 +56,25 @@ update_addresses_stat () | |||
56 | * @param addr address to destroy | 56 | * @param addr address to destroy |
57 | */ | 57 | */ |
58 | static void | 58 | static void |
59 | free_address (struct ATS_Address *addr) | 59 | free_address(struct ATS_Address *addr) |
60 | { | 60 | { |
61 | GNUNET_assert (GNUNET_YES == | 61 | GNUNET_assert(GNUNET_YES == |
62 | GNUNET_CONTAINER_multipeermap_remove (GSA_addresses, | 62 | GNUNET_CONTAINER_multipeermap_remove(GSA_addresses, |
63 | &addr->peer, | 63 | &addr->peer, |
64 | addr)); | 64 | addr)); |
65 | update_addresses_stat (); | 65 | update_addresses_stat(); |
66 | GAS_plugin_delete_address (addr); | 66 | GAS_plugin_delete_address(addr); |
67 | GAS_performance_notify_all_clients (&addr->peer, | 67 | GAS_performance_notify_all_clients(&addr->peer, |
68 | addr->plugin, | 68 | addr->plugin, |
69 | addr->addr, | 69 | addr->addr, |
70 | addr->addr_len, | 70 | addr->addr_len, |
71 | GNUNET_NO, | 71 | GNUNET_NO, |
72 | NULL, | 72 | NULL, |
73 | addr->local_address_info, | 73 | addr->local_address_info, |
74 | GNUNET_BANDWIDTH_ZERO, | 74 | GNUNET_BANDWIDTH_ZERO, |
75 | GNUNET_BANDWIDTH_ZERO); | 75 | GNUNET_BANDWIDTH_ZERO); |
76 | GNUNET_free (addr->plugin); | 76 | GNUNET_free(addr->plugin); |
77 | GNUNET_free (addr); | 77 | GNUNET_free(addr); |
78 | } | 78 | } |
79 | 79 | ||
80 | 80 | ||
@@ -84,7 +84,7 @@ free_address (struct ATS_Address *addr) | |||
84 | * @param norm normalization data to initialize | 84 | * @param norm normalization data to initialize |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | init_norm (struct GAS_NormalizationInfo *norm) | 87 | init_norm(struct GAS_NormalizationInfo *norm) |
88 | { | 88 | { |
89 | unsigned int c; | 89 | unsigned int c; |
90 | 90 | ||
@@ -105,29 +105,29 @@ init_norm (struct GAS_NormalizationInfo *norm) | |||
105 | * @return the ATS_Address | 105 | * @return the ATS_Address |
106 | */ | 106 | */ |
107 | static struct ATS_Address * | 107 | static struct ATS_Address * |
108 | create_address (const struct GNUNET_PeerIdentity *peer, | 108 | create_address(const struct GNUNET_PeerIdentity *peer, |
109 | const char *plugin_name, | 109 | const char *plugin_name, |
110 | const void *plugin_addr, | 110 | const void *plugin_addr, |
111 | size_t plugin_addr_len, | 111 | size_t plugin_addr_len, |
112 | uint32_t local_address_info, | 112 | uint32_t local_address_info, |
113 | uint32_t session_id) | 113 | uint32_t session_id) |
114 | { | 114 | { |
115 | struct ATS_Address *aa; | 115 | struct ATS_Address *aa; |
116 | 116 | ||
117 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); | 117 | aa = GNUNET_malloc(sizeof(struct ATS_Address) + plugin_addr_len); |
118 | aa->peer = *peer; | 118 | aa->peer = *peer; |
119 | aa->addr_len = plugin_addr_len; | 119 | aa->addr_len = plugin_addr_len; |
120 | aa->addr = &aa[1]; | 120 | aa->addr = &aa[1]; |
121 | GNUNET_memcpy (&aa[1], | 121 | GNUNET_memcpy(&aa[1], |
122 | plugin_addr, | 122 | plugin_addr, |
123 | plugin_addr_len); | 123 | plugin_addr_len); |
124 | aa->plugin = GNUNET_strdup (plugin_name); | 124 | aa->plugin = GNUNET_strdup(plugin_name); |
125 | aa->session_id = session_id; | 125 | aa->session_id = session_id; |
126 | aa->local_address_info = local_address_info; | 126 | aa->local_address_info = local_address_info; |
127 | init_norm (&aa->norm_delay); | 127 | init_norm(&aa->norm_delay); |
128 | init_norm (&aa->norm_distance); | 128 | init_norm(&aa->norm_distance); |
129 | init_norm (&aa->norm_utilization_in); | 129 | init_norm(&aa->norm_utilization_in); |
130 | init_norm (&aa->norm_utilization_out); | 130 | init_norm(&aa->norm_utilization_out); |
131 | return aa; | 131 | return aa; |
132 | } | 132 | } |
133 | 133 | ||
@@ -135,8 +135,7 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
135 | /** | 135 | /** |
136 | * Closure for #find_address_cb() | 136 | * Closure for #find_address_cb() |
137 | */ | 137 | */ |
138 | struct FindAddressContext | 138 | struct FindAddressContext { |
139 | { | ||
140 | /** | 139 | /** |
141 | * Session Id to look for. | 140 | * Session Id to look for. |
142 | */ | 141 | */ |
@@ -146,7 +145,6 @@ struct FindAddressContext | |||
146 | * Where to store matching address result. | 145 | * Where to store matching address result. |
147 | */ | 146 | */ |
148 | struct ATS_Address *exact_address; | 147 | struct ATS_Address *exact_address; |
149 | |||
150 | }; | 148 | }; |
151 | 149 | ||
152 | 150 | ||
@@ -159,18 +157,18 @@ struct FindAddressContext | |||
159 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is found | 157 | * @return #GNUNET_YES to continue, #GNUNET_NO if address is found |
160 | */ | 158 | */ |
161 | static int | 159 | static int |
162 | find_address_cb (void *cls, | 160 | find_address_cb(void *cls, |
163 | const struct GNUNET_PeerIdentity *key, | 161 | const struct GNUNET_PeerIdentity *key, |
164 | void *value) | 162 | void *value) |
165 | { | 163 | { |
166 | struct FindAddressContext *fac = cls; | 164 | struct FindAddressContext *fac = cls; |
167 | struct ATS_Address *aa = value; | 165 | struct ATS_Address *aa = value; |
168 | 166 | ||
169 | if (aa->session_id == fac->session_id) | 167 | if (aa->session_id == fac->session_id) |
170 | { | 168 | { |
171 | fac->exact_address = aa; | 169 | fac->exact_address = aa; |
172 | return GNUNET_NO; | 170 | return GNUNET_NO; |
173 | } | 171 | } |
174 | return GNUNET_YES; | 172 | return GNUNET_YES; |
175 | } | 173 | } |
176 | 174 | ||
@@ -183,16 +181,16 @@ find_address_cb (void *cls, | |||
183 | * @return an ATS_address or NULL | 181 | * @return an ATS_address or NULL |
184 | */ | 182 | */ |
185 | static struct ATS_Address * | 183 | static struct ATS_Address * |
186 | find_exact_address (const struct GNUNET_PeerIdentity *peer, | 184 | find_exact_address(const struct GNUNET_PeerIdentity *peer, |
187 | uint32_t session_id) | 185 | uint32_t session_id) |
188 | { | 186 | { |
189 | struct FindAddressContext fac; | 187 | struct FindAddressContext fac; |
190 | 188 | ||
191 | fac.exact_address = NULL; | 189 | fac.exact_address = NULL; |
192 | fac.session_id = session_id; | 190 | fac.session_id = session_id; |
193 | GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, | 191 | GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, |
194 | peer, | 192 | peer, |
195 | &find_address_cb, &fac); | 193 | &find_address_cb, &fac); |
196 | return fac.exact_address; | 194 | return fac.exact_address; |
197 | } | 195 | } |
198 | 196 | ||
@@ -209,58 +207,58 @@ find_exact_address (const struct GNUNET_PeerIdentity *peer, | |||
209 | * @param prop performance information for this address | 207 | * @param prop performance information for this address |
210 | */ | 208 | */ |
211 | void | 209 | void |
212 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | 210 | GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, |
213 | const char *plugin_name, | 211 | const char *plugin_name, |
214 | const void *plugin_addr, | 212 | const void *plugin_addr, |
215 | size_t plugin_addr_len, | 213 | size_t plugin_addr_len, |
216 | uint32_t local_address_info, | 214 | uint32_t local_address_info, |
217 | uint32_t session_id, | 215 | uint32_t session_id, |
218 | const struct GNUNET_ATS_Properties *prop) | 216 | const struct GNUNET_ATS_Properties *prop) |
219 | { | 217 | { |
220 | struct ATS_Address *new_address; | 218 | struct ATS_Address *new_address; |
221 | 219 | ||
222 | if (NULL != find_exact_address (peer, | 220 | if (NULL != find_exact_address(peer, |
223 | session_id)) | 221 | session_id)) |
224 | { | 222 | { |
225 | GNUNET_break (0); | 223 | GNUNET_break(0); |
226 | return; | 224 | return; |
227 | } | 225 | } |
228 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 226 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
229 | new_address = create_address (peer, | 227 | new_address = create_address(peer, |
230 | plugin_name, | 228 | plugin_name, |
231 | plugin_addr, | 229 | plugin_addr, |
232 | plugin_addr_len, | 230 | plugin_addr_len, |
233 | local_address_info, | 231 | local_address_info, |
234 | session_id); | 232 | session_id); |
235 | /* Add a new address */ | 233 | /* Add a new address */ |
236 | new_address->properties = *prop; | 234 | new_address->properties = *prop; |
237 | new_address->t_added = GNUNET_TIME_absolute_get(); | 235 | new_address->t_added = GNUNET_TIME_absolute_get(); |
238 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); | 236 | new_address->t_last_activity = GNUNET_TIME_absolute_get(); |
239 | GNUNET_assert(GNUNET_OK == | 237 | GNUNET_assert(GNUNET_OK == |
240 | GNUNET_CONTAINER_multipeermap_put (GSA_addresses, | 238 | GNUNET_CONTAINER_multipeermap_put(GSA_addresses, |
241 | peer, | 239 | peer, |
242 | new_address, | 240 | new_address, |
243 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 241 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
244 | update_addresses_stat (); | 242 | update_addresses_stat(); |
245 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 243 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
246 | "Adding new address for peer `%s' slot %u\n", | 244 | "Adding new address for peer `%s' slot %u\n", |
247 | GNUNET_i2s (peer), | 245 | GNUNET_i2s(peer), |
248 | session_id); | 246 | session_id); |
249 | /* Tell solver about new address */ | 247 | /* Tell solver about new address */ |
250 | GAS_plugin_solver_lock (); | 248 | GAS_plugin_solver_lock(); |
251 | GAS_plugin_new_address (new_address); | 249 | GAS_plugin_new_address(new_address); |
252 | GAS_normalization_update_property (new_address); // FIXME: needed? | 250 | GAS_normalization_update_property(new_address); // FIXME: needed? |
253 | GAS_plugin_solver_unlock (); | 251 | GAS_plugin_solver_unlock(); |
254 | /* Notify performance clients about new address */ | 252 | /* Notify performance clients about new address */ |
255 | GAS_performance_notify_all_clients (&new_address->peer, | 253 | GAS_performance_notify_all_clients(&new_address->peer, |
256 | new_address->plugin, | 254 | new_address->plugin, |
257 | new_address->addr, | 255 | new_address->addr, |
258 | new_address->addr_len, | 256 | new_address->addr_len, |
259 | new_address->active, | 257 | new_address->active, |
260 | &new_address->properties, | 258 | &new_address->properties, |
261 | new_address->local_address_info, | 259 | new_address->local_address_info, |
262 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_out), | 260 | GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_out), |
263 | GNUNET_BANDWIDTH_value_init (new_address->assigned_bw_in)); | 261 | GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_in)); |
264 | } | 262 | } |
265 | 263 | ||
266 | 264 | ||
@@ -272,45 +270,45 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
272 | * @param prop performance information for this address | 270 | * @param prop performance information for this address |
273 | */ | 271 | */ |
274 | void | 272 | void |
275 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | 273 | GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, |
276 | uint32_t session_id, | 274 | uint32_t session_id, |
277 | const struct GNUNET_ATS_Properties *prop) | 275 | const struct GNUNET_ATS_Properties *prop) |
278 | { | 276 | { |
279 | struct ATS_Address *aa; | 277 | struct ATS_Address *aa; |
280 | 278 | ||
281 | /* Get existing address */ | 279 | /* Get existing address */ |
282 | aa = find_exact_address (peer, | 280 | aa = find_exact_address(peer, |
283 | session_id); | 281 | session_id); |
284 | if (NULL == aa) | 282 | if (NULL == aa) |
285 | { | 283 | { |
286 | GNUNET_break (0); | 284 | GNUNET_break(0); |
287 | return; | 285 | return; |
288 | } | 286 | } |
289 | if (NULL == aa->solver_information) | 287 | if (NULL == aa->solver_information) |
290 | { | 288 | { |
291 | GNUNET_break (0); | 289 | GNUNET_break(0); |
292 | return; | 290 | return; |
293 | } | 291 | } |
294 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
295 | "Received ADDRESS_UPDATE for peer `%s' slot %u\n", | 293 | "Received ADDRESS_UPDATE for peer `%s' slot %u\n", |
296 | GNUNET_i2s (peer), | 294 | GNUNET_i2s(peer), |
297 | (unsigned int) session_id); | 295 | (unsigned int)session_id); |
298 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 296 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
299 | /* Update address */ | 297 | /* Update address */ |
300 | aa->t_last_activity = GNUNET_TIME_absolute_get(); | 298 | aa->t_last_activity = GNUNET_TIME_absolute_get(); |
301 | aa->properties = *prop; | 299 | aa->properties = *prop; |
302 | /* Notify performance clients about updated address */ | 300 | /* Notify performance clients about updated address */ |
303 | GAS_performance_notify_all_clients (&aa->peer, | 301 | GAS_performance_notify_all_clients(&aa->peer, |
304 | aa->plugin, | 302 | aa->plugin, |
305 | aa->addr, | 303 | aa->addr, |
306 | aa->addr_len, | 304 | aa->addr_len, |
307 | aa->active, | 305 | aa->active, |
308 | prop, | 306 | prop, |
309 | aa->local_address_info, | 307 | aa->local_address_info, |
310 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_out), | 308 | GNUNET_BANDWIDTH_value_init(aa->assigned_bw_out), |
311 | GNUNET_BANDWIDTH_value_init (aa->assigned_bw_in)); | 309 | GNUNET_BANDWIDTH_value_init(aa->assigned_bw_in)); |
312 | 310 | ||
313 | GAS_normalization_update_property (aa); | 311 | GAS_normalization_update_property(aa); |
314 | } | 312 | } |
315 | 313 | ||
316 | 314 | ||
@@ -321,24 +319,24 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
321 | * @param session_id session id, can never be 0 | 319 | * @param session_id session id, can never be 0 |
322 | */ | 320 | */ |
323 | void | 321 | void |
324 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | 322 | GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, |
325 | uint32_t session_id) | 323 | uint32_t session_id) |
326 | { | 324 | { |
327 | struct ATS_Address *ea; | 325 | struct ATS_Address *ea; |
328 | 326 | ||
329 | /* Get existing address */ | 327 | /* Get existing address */ |
330 | ea = find_exact_address (peer, | 328 | ea = find_exact_address(peer, |
331 | session_id); | 329 | session_id); |
332 | if (NULL == ea) | 330 | if (NULL == ea) |
333 | { | 331 | { |
334 | GNUNET_break (0); | 332 | GNUNET_break(0); |
335 | return; | 333 | return; |
336 | } | 334 | } |
337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 335 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
338 | "Received ADDRESS_DESTROYED for peer `%s' session %u\n", | 336 | "Received ADDRESS_DESTROYED for peer `%s' session %u\n", |
339 | GNUNET_i2s (peer), | 337 | GNUNET_i2s(peer), |
340 | session_id); | 338 | session_id); |
341 | free_address (ea); | 339 | free_address(ea); |
342 | } | 340 | } |
343 | 341 | ||
344 | 342 | ||
@@ -349,12 +347,12 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | |||
349 | * and receives updates when the solver changes the resource allocation. | 347 | * and receives updates when the solver changes the resource allocation. |
350 | */ | 348 | */ |
351 | void | 349 | void |
352 | GAS_addresses_init () | 350 | GAS_addresses_init() |
353 | { | 351 | { |
354 | GSA_addresses | 352 | GSA_addresses |
355 | = GNUNET_CONTAINER_multipeermap_create (128, | 353 | = GNUNET_CONTAINER_multipeermap_create(128, |
356 | GNUNET_NO); | 354 | GNUNET_NO); |
357 | update_addresses_stat (); | 355 | update_addresses_stat(); |
358 | } | 356 | } |
359 | 357 | ||
360 | 358 | ||
@@ -367,13 +365,13 @@ GAS_addresses_init () | |||
367 | * @return #GNUNET_OK (continue to iterate) | 365 | * @return #GNUNET_OK (continue to iterate) |
368 | */ | 366 | */ |
369 | static int | 367 | static int |
370 | destroy_all_address_it (void *cls, | 368 | destroy_all_address_it(void *cls, |
371 | const struct GNUNET_PeerIdentity *key, | 369 | const struct GNUNET_PeerIdentity *key, |
372 | void *value) | 370 | void *value) |
373 | { | 371 | { |
374 | struct ATS_Address *aa = value; | 372 | struct ATS_Address *aa = value; |
375 | 373 | ||
376 | free_address (aa); | 374 | free_address(aa); |
377 | return GNUNET_OK; | 375 | return GNUNET_OK; |
378 | } | 376 | } |
379 | 377 | ||
@@ -382,18 +380,18 @@ destroy_all_address_it (void *cls, | |||
382 | * Remove all addresses | 380 | * Remove all addresses |
383 | */ | 381 | */ |
384 | void | 382 | void |
385 | GAS_addresses_destroy_all () | 383 | GAS_addresses_destroy_all() |
386 | { | 384 | { |
387 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 385 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
388 | "Destroying all addresses\n"); | 386 | "Destroying all addresses\n"); |
389 | if (0 == | 387 | if (0 == |
390 | GNUNET_CONTAINER_multipeermap_size (GSA_addresses)) | 388 | GNUNET_CONTAINER_multipeermap_size(GSA_addresses)) |
391 | return; | 389 | return; |
392 | GAS_plugin_solver_lock (); | 390 | GAS_plugin_solver_lock(); |
393 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 391 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, |
394 | &destroy_all_address_it, | 392 | &destroy_all_address_it, |
395 | NULL); | 393 | NULL); |
396 | GAS_plugin_solver_unlock (); | 394 | GAS_plugin_solver_unlock(); |
397 | } | 395 | } |
398 | 396 | ||
399 | 397 | ||
@@ -401,14 +399,14 @@ GAS_addresses_destroy_all () | |||
401 | * Shutdown address subsystem. | 399 | * Shutdown address subsystem. |
402 | */ | 400 | */ |
403 | void | 401 | void |
404 | GAS_addresses_done () | 402 | GAS_addresses_done() |
405 | { | 403 | { |
406 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 404 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
407 | "Shutting down addresses\n"); | 405 | "Shutting down addresses\n"); |
408 | GAS_plugin_solver_lock (); | 406 | GAS_plugin_solver_lock(); |
409 | GAS_addresses_destroy_all (); | 407 | GAS_addresses_destroy_all(); |
410 | GAS_plugin_solver_unlock (); | 408 | GAS_plugin_solver_unlock(); |
411 | GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses); | 409 | GNUNET_CONTAINER_multipeermap_destroy(GSA_addresses); |
412 | GSA_addresses = NULL; | 410 | GSA_addresses = NULL; |
413 | } | 411 | } |
414 | 412 | ||
@@ -416,8 +414,7 @@ GAS_addresses_done () | |||
416 | /** | 414 | /** |
417 | * Closure for #peerinfo_it(). | 415 | * Closure for #peerinfo_it(). |
418 | */ | 416 | */ |
419 | struct PeerInfoIteratorContext | 417 | struct PeerInfoIteratorContext { |
420 | { | ||
421 | /** | 418 | /** |
422 | * Function to call for each address. | 419 | * Function to call for each address. |
423 | */ | 420 | */ |
@@ -439,23 +436,23 @@ struct PeerInfoIteratorContext | |||
439 | * @return #GNUNET_OK to continue | 436 | * @return #GNUNET_OK to continue |
440 | */ | 437 | */ |
441 | static int | 438 | static int |
442 | peerinfo_it (void *cls, | 439 | peerinfo_it(void *cls, |
443 | const struct GNUNET_PeerIdentity *key, | 440 | const struct GNUNET_PeerIdentity *key, |
444 | void *value) | 441 | void *value) |
445 | { | 442 | { |
446 | struct PeerInfoIteratorContext *pi_ctx = cls; | 443 | struct PeerInfoIteratorContext *pi_ctx = cls; |
447 | struct ATS_Address *addr = value; | 444 | struct ATS_Address *addr = value; |
448 | 445 | ||
449 | pi_ctx->it (pi_ctx->it_cls, | 446 | pi_ctx->it(pi_ctx->it_cls, |
450 | &addr->peer, | 447 | &addr->peer, |
451 | addr->plugin, | 448 | addr->plugin, |
452 | addr->addr, | 449 | addr->addr, |
453 | addr->addr_len, | 450 | addr->addr_len, |
454 | addr->active, | 451 | addr->active, |
455 | &addr->properties, | 452 | &addr->properties, |
456 | addr->local_address_info, | 453 | addr->local_address_info, |
457 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out), | 454 | GNUNET_BANDWIDTH_value_init(addr->assigned_bw_out), |
458 | GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in)); | 455 | GNUNET_BANDWIDTH_value_init(addr->assigned_bw_in)); |
459 | return GNUNET_OK; | 456 | return GNUNET_OK; |
460 | } | 457 | } |
461 | 458 | ||
@@ -468,41 +465,41 @@ peerinfo_it (void *cls, | |||
468 | * @param pi_it_cls the closure for @a pi_it | 465 | * @param pi_it_cls the closure for @a pi_it |
469 | */ | 466 | */ |
470 | void | 467 | void |
471 | GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | 468 | GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, |
472 | GNUNET_ATS_PeerInfo_Iterator pi_it, | 469 | GNUNET_ATS_PeerInfo_Iterator pi_it, |
473 | void *pi_it_cls) | 470 | void *pi_it_cls) |
474 | { | 471 | { |
475 | struct PeerInfoIteratorContext pi_ctx; | 472 | struct PeerInfoIteratorContext pi_ctx; |
476 | 473 | ||
477 | if (NULL == pi_it) | 474 | if (NULL == pi_it) |
478 | { | 475 | { |
479 | /* does not make sense without callback */ | 476 | /* does not make sense without callback */ |
480 | GNUNET_break (0); | 477 | GNUNET_break(0); |
481 | return; | 478 | return; |
482 | } | 479 | } |
483 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 480 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
484 | "Returning information for %s from a total of %u known addresses\n", | 481 | "Returning information for %s from a total of %u known addresses\n", |
485 | (NULL == peer) | 482 | (NULL == peer) |
486 | ? "all peers" | 483 | ? "all peers" |
487 | : GNUNET_i2s (peer), | 484 | : GNUNET_i2s(peer), |
488 | (unsigned int) GNUNET_CONTAINER_multipeermap_size (GSA_addresses)); | 485 | (unsigned int)GNUNET_CONTAINER_multipeermap_size(GSA_addresses)); |
489 | pi_ctx.it = pi_it; | 486 | pi_ctx.it = pi_it; |
490 | pi_ctx.it_cls = pi_it_cls; | 487 | pi_ctx.it_cls = pi_it_cls; |
491 | if (NULL == peer) | 488 | if (NULL == peer) |
492 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 489 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, |
493 | &peerinfo_it, | 490 | &peerinfo_it, |
494 | &pi_ctx); | 491 | &pi_ctx); |
495 | else | 492 | else |
496 | GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses, | 493 | GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, |
497 | peer, | 494 | peer, |
498 | &peerinfo_it, &pi_ctx); | 495 | &peerinfo_it, &pi_ctx); |
499 | pi_it (pi_it_cls, | 496 | pi_it(pi_it_cls, |
500 | NULL, NULL, NULL, 0, | 497 | NULL, NULL, NULL, 0, |
501 | GNUNET_NO, | 498 | GNUNET_NO, |
502 | NULL, | 499 | NULL, |
503 | GNUNET_HELLO_ADDRESS_INFO_NONE, | 500 | GNUNET_HELLO_ADDRESS_INFO_NONE, |
504 | GNUNET_BANDWIDTH_ZERO, | 501 | GNUNET_BANDWIDTH_ZERO, |
505 | GNUNET_BANDWIDTH_ZERO); | 502 | GNUNET_BANDWIDTH_ZERO); |
506 | } | 503 | } |
507 | 504 | ||
508 | 505 | ||
@@ -510,8 +507,7 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | |||
510 | * Information we need for the callbacks to return a list of addresses | 507 | * Information we need for the callbacks to return a list of addresses |
511 | * back to the client. | 508 | * back to the client. |
512 | */ | 509 | */ |
513 | struct AddressIteration | 510 | struct AddressIteration { |
514 | { | ||
515 | /** | 511 | /** |
516 | * Actual handle to the client. | 512 | * Actual handle to the client. |
517 | */ | 513 | */ |
@@ -526,7 +522,6 @@ struct AddressIteration | |||
526 | * Which ID should be included in the response? | 522 | * Which ID should be included in the response? |
527 | */ | 523 | */ |
528 | uint32_t id; | 524 | uint32_t id; |
529 | |||
530 | }; | 525 | }; |
531 | 526 | ||
532 | 527 | ||
@@ -546,16 +541,16 @@ struct AddressIteration | |||
546 | * @param bandwidth_in current inbound bandwidth assigned to address | 541 | * @param bandwidth_in current inbound bandwidth assigned to address |
547 | */ | 542 | */ |
548 | static void | 543 | static void |
549 | transmit_req_addr (struct AddressIteration *ai, | 544 | transmit_req_addr(struct AddressIteration *ai, |
550 | const struct GNUNET_PeerIdentity *id, | 545 | const struct GNUNET_PeerIdentity *id, |
551 | const char *plugin_name, | 546 | const char *plugin_name, |
552 | const void *plugin_addr, | 547 | const void *plugin_addr, |
553 | size_t plugin_addr_len, | 548 | size_t plugin_addr_len, |
554 | int active, | 549 | int active, |
555 | const struct GNUNET_ATS_Properties *prop, | 550 | const struct GNUNET_ATS_Properties *prop, |
556 | enum GNUNET_HELLO_AddressInfo local_address_info, | 551 | enum GNUNET_HELLO_AddressInfo local_address_info, |
557 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 552 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
558 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 553 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
559 | 554 | ||
560 | { | 555 | { |
561 | struct GNUNET_MQ_Envelope *env; | 556 | struct GNUNET_MQ_Envelope *env; |
@@ -565,37 +560,37 @@ transmit_req_addr (struct AddressIteration *ai, | |||
565 | size_t msize; | 560 | size_t msize; |
566 | 561 | ||
567 | if (NULL != plugin_name) | 562 | if (NULL != plugin_name) |
568 | plugin_name_length = strlen (plugin_name) + 1; | 563 | plugin_name_length = strlen(plugin_name) + 1; |
569 | else | 564 | else |
570 | plugin_name_length = 0; | 565 | plugin_name_length = 0; |
571 | msize = plugin_addr_len + plugin_name_length; | 566 | msize = plugin_addr_len + plugin_name_length; |
572 | 567 | ||
573 | GNUNET_assert (sizeof (struct PeerInformationMessage) + msize | 568 | GNUNET_assert(sizeof(struct PeerInformationMessage) + msize |
574 | < GNUNET_MAX_MESSAGE_SIZE); | 569 | < GNUNET_MAX_MESSAGE_SIZE); |
575 | env = GNUNET_MQ_msg_extra (msg, | 570 | env = GNUNET_MQ_msg_extra(msg, |
576 | msize, | 571 | msize, |
577 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); | 572 | GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); |
578 | msg->id = htonl (ai->id); | 573 | msg->id = htonl(ai->id); |
579 | if (NULL != id) | 574 | if (NULL != id) |
580 | msg->peer = *id; | 575 | msg->peer = *id; |
581 | msg->address_length = htons (plugin_addr_len); | 576 | msg->address_length = htons(plugin_addr_len); |
582 | msg->address_active = ntohl (active); | 577 | msg->address_active = ntohl(active); |
583 | msg->plugin_name_length = htons (plugin_name_length); | 578 | msg->plugin_name_length = htons(plugin_name_length); |
584 | msg->bandwidth_out = bandwidth_out; | 579 | msg->bandwidth_out = bandwidth_out; |
585 | msg->bandwidth_in = bandwidth_in; | 580 | msg->bandwidth_in = bandwidth_in; |
586 | if (NULL != prop) | 581 | if (NULL != prop) |
587 | GNUNET_ATS_properties_hton (&msg->properties, | 582 | GNUNET_ATS_properties_hton(&msg->properties, |
588 | prop); | 583 | prop); |
589 | msg->address_local_info = htonl ((uint32_t) local_address_info); | 584 | msg->address_local_info = htonl((uint32_t)local_address_info); |
590 | addrp = (char *) &msg[1]; | 585 | addrp = (char *)&msg[1]; |
591 | GNUNET_memcpy (addrp, | 586 | GNUNET_memcpy(addrp, |
592 | plugin_addr, | 587 | plugin_addr, |
593 | plugin_addr_len); | 588 | plugin_addr_len); |
594 | if (NULL != plugin_name) | 589 | if (NULL != plugin_name) |
595 | strcpy (&addrp[plugin_addr_len], | 590 | strcpy(&addrp[plugin_addr_len], |
596 | plugin_name); | 591 | plugin_name); |
597 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client), | 592 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(ai->client), |
598 | env); | 593 | env); |
599 | } | 594 | } |
600 | 595 | ||
601 | 596 | ||
@@ -615,48 +610,48 @@ transmit_req_addr (struct AddressIteration *ai, | |||
615 | * @param bandwidth_in current inbound bandwidth assigned to address | 610 | * @param bandwidth_in current inbound bandwidth assigned to address |
616 | */ | 611 | */ |
617 | static void | 612 | static void |
618 | req_addr_peerinfo_it (void *cls, | 613 | req_addr_peerinfo_it(void *cls, |
619 | const struct GNUNET_PeerIdentity *id, | 614 | const struct GNUNET_PeerIdentity *id, |
620 | const char *plugin_name, | 615 | const char *plugin_name, |
621 | const void *plugin_addr, | 616 | const void *plugin_addr, |
622 | size_t plugin_addr_len, | 617 | size_t plugin_addr_len, |
623 | int active, | 618 | int active, |
624 | const struct GNUNET_ATS_Properties *prop, | 619 | const struct GNUNET_ATS_Properties *prop, |
625 | enum GNUNET_HELLO_AddressInfo local_address_info, | 620 | enum GNUNET_HELLO_AddressInfo local_address_info, |
626 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 621 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
627 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 622 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
628 | { | 623 | { |
629 | struct AddressIteration *ai = cls; | 624 | struct AddressIteration *ai = cls; |
630 | 625 | ||
631 | if ( (NULL == id) && | 626 | if ((NULL == id) && |
632 | (NULL == plugin_name) && | 627 | (NULL == plugin_name) && |
633 | (NULL == plugin_addr) ) | 628 | (NULL == plugin_addr)) |
634 | { | 629 | { |
635 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 630 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
636 | "Address iteration done for one peer\n"); | 631 | "Address iteration done for one peer\n"); |
637 | return; | 632 | return; |
638 | } | 633 | } |
639 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 634 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
640 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", | 635 | "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", |
641 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", | 636 | (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", |
642 | GNUNET_i2s (id), | 637 | GNUNET_i2s(id), |
643 | plugin_name, | 638 | plugin_name, |
644 | (unsigned int) ntohl (bandwidth_out.value__), | 639 | (unsigned int)ntohl(bandwidth_out.value__), |
645 | (unsigned int) ntohl (bandwidth_in.value__)); | 640 | (unsigned int)ntohl(bandwidth_in.value__)); |
646 | /* Transmit result (either if address is active, or if | 641 | /* Transmit result (either if address is active, or if |
647 | client wanted all addresses) */ | 642 | client wanted all addresses) */ |
648 | if ( (GNUNET_YES != ai->all) && | 643 | if ((GNUNET_YES != ai->all) && |
649 | (GNUNET_YES != active)) | 644 | (GNUNET_YES != active)) |
650 | return; | 645 | return; |
651 | transmit_req_addr (ai, | 646 | transmit_req_addr(ai, |
652 | id, | 647 | id, |
653 | plugin_name, | 648 | plugin_name, |
654 | plugin_addr, plugin_addr_len, | 649 | plugin_addr, plugin_addr_len, |
655 | active, | 650 | active, |
656 | prop, | 651 | prop, |
657 | local_address_info, | 652 | local_address_info, |
658 | bandwidth_out, | 653 | bandwidth_out, |
659 | bandwidth_in); | 654 | bandwidth_in); |
660 | } | 655 | } |
661 | 656 | ||
662 | 657 | ||
@@ -667,45 +662,45 @@ req_addr_peerinfo_it (void *cls, | |||
667 | * @param alrm the request message | 662 | * @param alrm the request message |
668 | */ | 663 | */ |
669 | void | 664 | void |
670 | GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, | 665 | GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client, |
671 | const struct AddressListRequestMessage *alrm) | 666 | const struct AddressListRequestMessage *alrm) |
672 | { | 667 | { |
673 | struct AddressIteration ai; | 668 | struct AddressIteration ai; |
674 | struct GNUNET_PeerIdentity allzeros; | 669 | struct GNUNET_PeerIdentity allzeros; |
675 | 670 | ||
676 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 671 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
677 | "Received ADDRESSLIST_REQUEST message\n"); | 672 | "Received ADDRESSLIST_REQUEST message\n"); |
678 | ai.all = ntohl (alrm->all); | 673 | ai.all = ntohl(alrm->all); |
679 | ai.id = ntohl (alrm->id); | 674 | ai.id = ntohl(alrm->id); |
680 | ai.client = client; | 675 | ai.client = client; |
681 | 676 | ||
682 | memset (&allzeros, | 677 | memset(&allzeros, |
683 | '\0', | 678 | '\0', |
684 | sizeof (struct GNUNET_PeerIdentity)); | 679 | sizeof(struct GNUNET_PeerIdentity)); |
685 | if (0 == GNUNET_is_zero (&alrm->peer)) | 680 | if (0 == GNUNET_is_zero(&alrm->peer)) |
686 | { | 681 | { |
687 | /* Return addresses for all peers */ | 682 | /* Return addresses for all peers */ |
688 | GAS_addresses_get_peer_info (NULL, | 683 | GAS_addresses_get_peer_info(NULL, |
689 | &req_addr_peerinfo_it, | 684 | &req_addr_peerinfo_it, |
690 | &ai); | 685 | &ai); |
691 | } | 686 | } |
692 | else | 687 | else |
693 | { | 688 | { |
694 | /* Return addresses for a specific peer */ | 689 | /* Return addresses for a specific peer */ |
695 | GAS_addresses_get_peer_info (&alrm->peer, | 690 | GAS_addresses_get_peer_info(&alrm->peer, |
696 | &req_addr_peerinfo_it, | 691 | &req_addr_peerinfo_it, |
697 | &ai); | 692 | &ai); |
698 | } | 693 | } |
699 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 694 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
700 | "Finished handling `%s' message\n", | 695 | "Finished handling `%s' message\n", |
701 | "ADDRESSLIST_REQUEST"); | 696 | "ADDRESSLIST_REQUEST"); |
702 | transmit_req_addr (&ai, | 697 | transmit_req_addr(&ai, |
703 | NULL, NULL, NULL, | 698 | NULL, NULL, NULL, |
704 | 0, GNUNET_NO, | 699 | 0, GNUNET_NO, |
705 | NULL, | 700 | NULL, |
706 | GNUNET_HELLO_ADDRESS_INFO_NONE, | 701 | GNUNET_HELLO_ADDRESS_INFO_NONE, |
707 | GNUNET_BANDWIDTH_ZERO, | 702 | GNUNET_BANDWIDTH_ZERO, |
708 | GNUNET_BANDWIDTH_ZERO); | 703 | GNUNET_BANDWIDTH_ZERO); |
709 | } | 704 | } |
710 | 705 | ||
711 | 706 | ||
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index c9ad9a45d..f7dd98b1e 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -226,8 +226,7 @@ | |||
226 | /** | 226 | /** |
227 | * Information provided by ATS normalization | 227 | * Information provided by ATS normalization |
228 | */ | 228 | */ |
229 | struct GAS_NormalizationInfo | 229 | struct GAS_NormalizationInfo { |
230 | { | ||
231 | /** | 230 | /** |
232 | * Next index to use in averaging queue | 231 | * Next index to use in averaging queue |
233 | */ | 232 | */ |
@@ -253,8 +252,7 @@ struct GAS_NormalizationInfo | |||
253 | /** | 252 | /** |
254 | * Address with additional information | 253 | * Address with additional information |
255 | */ | 254 | */ |
256 | struct ATS_Address | 255 | struct ATS_Address { |
257 | { | ||
258 | /** | 256 | /** |
259 | * Peer ID this address is for. | 257 | * Peer ID this address is for. |
260 | */ | 258 | */ |
@@ -350,11 +348,10 @@ struct ATS_Address | |||
350 | */ | 348 | */ |
351 | struct GAS_NormalizationInfo norm_utilization_in; | 349 | struct GAS_NormalizationInfo norm_utilization_in; |
352 | 350 | ||
353 | /** | 351 | /** |
354 | * Normalized utilization outbound for this address. | 352 | * Normalized utilization outbound for this address. |
355 | */ | 353 | */ |
356 | struct GAS_NormalizationInfo norm_utilization_out; | 354 | struct GAS_NormalizationInfo norm_utilization_out; |
357 | |||
358 | }; | 355 | }; |
359 | 356 | ||
360 | 357 | ||
@@ -369,14 +366,14 @@ extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses; | |||
369 | * known and current performance information. | 366 | * known and current performance information. |
370 | */ | 367 | */ |
371 | void | 368 | void |
372 | GAS_addresses_init (void); | 369 | GAS_addresses_init(void); |
373 | 370 | ||
374 | 371 | ||
375 | /** | 372 | /** |
376 | * Shutdown address subsystem. | 373 | * Shutdown address subsystem. |
377 | */ | 374 | */ |
378 | void | 375 | void |
379 | GAS_addresses_done (void); | 376 | GAS_addresses_done(void); |
380 | 377 | ||
381 | 378 | ||
382 | /** | 379 | /** |
@@ -391,13 +388,13 @@ GAS_addresses_done (void); | |||
391 | * @param prop performance information for this address | 388 | * @param prop performance information for this address |
392 | */ | 389 | */ |
393 | void | 390 | void |
394 | GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | 391 | GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, |
395 | const char *plugin_name, | 392 | const char *plugin_name, |
396 | const void *plugin_addr, | 393 | const void *plugin_addr, |
397 | size_t plugin_addr_len, | 394 | size_t plugin_addr_len, |
398 | uint32_t local_address_info, | 395 | uint32_t local_address_info, |
399 | uint32_t session_id, | 396 | uint32_t session_id, |
400 | const struct GNUNET_ATS_Properties *prop); | 397 | const struct GNUNET_ATS_Properties *prop); |
401 | 398 | ||
402 | 399 | ||
403 | /** | 400 | /** |
@@ -408,9 +405,9 @@ GAS_addresses_add (const struct GNUNET_PeerIdentity *peer, | |||
408 | * @param prop performance information for this address | 405 | * @param prop performance information for this address |
409 | */ | 406 | */ |
410 | void | 407 | void |
411 | GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | 408 | GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, |
412 | uint32_t session_id, | 409 | uint32_t session_id, |
413 | const struct GNUNET_ATS_Properties *prop); | 410 | const struct GNUNET_ATS_Properties *prop); |
414 | 411 | ||
415 | 412 | ||
416 | /** | 413 | /** |
@@ -420,15 +417,15 @@ GAS_addresses_update (const struct GNUNET_PeerIdentity *peer, | |||
420 | * @param session_id session id, can never be 0 | 417 | * @param session_id session id, can never be 0 |
421 | */ | 418 | */ |
422 | void | 419 | void |
423 | GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer, | 420 | GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, |
424 | uint32_t session_id); | 421 | uint32_t session_id); |
425 | 422 | ||
426 | 423 | ||
427 | /** | 424 | /** |
428 | * Remove all addresses. | 425 | * Remove all addresses. |
429 | */ | 426 | */ |
430 | void | 427 | void |
431 | GAS_addresses_destroy_all (void); | 428 | GAS_addresses_destroy_all(void); |
432 | 429 | ||
433 | 430 | ||
434 | /** | 431 | /** |
@@ -466,9 +463,9 @@ typedef void | |||
466 | * @param pi_it_cls the closure for @a pi_it | 463 | * @param pi_it_cls the closure for @a pi_it |
467 | */ | 464 | */ |
468 | void | 465 | void |
469 | GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | 466 | GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, |
470 | GNUNET_ATS_PeerInfo_Iterator pi_it, | 467 | GNUNET_ATS_PeerInfo_Iterator pi_it, |
471 | void *pi_it_cls); | 468 | void *pi_it_cls); |
472 | 469 | ||
473 | 470 | ||
474 | /** | 471 | /** |
@@ -478,8 +475,8 @@ GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, | |||
478 | * @param alrm the request message | 475 | * @param alrm the request message |
479 | */ | 476 | */ |
480 | void | 477 | void |
481 | GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client, | 478 | GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client, |
482 | const struct AddressListRequestMessage *alrm); | 479 | const struct AddressListRequestMessage *alrm); |
483 | 480 | ||
484 | 481 | ||
485 | #endif | 482 | #endif |
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c index 3853aeb0e..f71d18e82 100644 --- a/src/ats/gnunet-service-ats_connectivity.c +++ b/src/ats/gnunet-service-ats_connectivity.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_connectivity.c | 22 | * @file ats/gnunet-service-ats_connectivity.c |
@@ -35,8 +35,7 @@ | |||
35 | /** | 35 | /** |
36 | * Active connection requests. | 36 | * Active connection requests. |
37 | */ | 37 | */ |
38 | struct ConnectionRequest | 38 | struct ConnectionRequest { |
39 | { | ||
40 | /** | 39 | /** |
41 | * Client that made the request. | 40 | * Client that made the request. |
42 | */ | 41 | */ |
@@ -61,14 +60,14 @@ static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests; | |||
61 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 60 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
62 | */ | 61 | */ |
63 | unsigned int | 62 | unsigned int |
64 | GAS_connectivity_has_peer (void *cls, | 63 | GAS_connectivity_has_peer(void *cls, |
65 | const struct GNUNET_PeerIdentity *peer) | 64 | const struct GNUNET_PeerIdentity *peer) |
66 | { | 65 | { |
67 | if (NULL == connection_requests) | 66 | if (NULL == connection_requests) |
68 | return 0; | 67 | return 0; |
69 | /* TODO: return sum of 'strength's of connectivity requests */ | 68 | /* TODO: return sum of 'strength's of connectivity requests */ |
70 | return GNUNET_CONTAINER_multipeermap_contains (connection_requests, | 69 | return GNUNET_CONTAINER_multipeermap_contains(connection_requests, |
71 | peer); | 70 | peer); |
72 | } | 71 | } |
73 | 72 | ||
74 | 73 | ||
@@ -79,22 +78,22 @@ GAS_connectivity_has_peer (void *cls, | |||
79 | * @param message the request message | 78 | * @param message the request message |
80 | */ | 79 | */ |
81 | void | 80 | void |
82 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | 81 | GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, |
83 | const struct RequestAddressMessage *msg) | 82 | const struct RequestAddressMessage *msg) |
84 | { | 83 | { |
85 | struct ConnectionRequest *cr; | 84 | struct ConnectionRequest *cr; |
86 | 85 | ||
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
88 | "Received `%s' message\n", | 87 | "Received `%s' message\n", |
89 | "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); | 88 | "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); |
90 | /* FIXME: should not ignore "msg->strength" */ | 89 | /* FIXME: should not ignore "msg->strength" */ |
91 | cr = GNUNET_new (struct ConnectionRequest); | 90 | cr = GNUNET_new(struct ConnectionRequest); |
92 | cr->client = client; | 91 | cr->client = client; |
93 | (void) GNUNET_CONTAINER_multipeermap_put (connection_requests, | 92 | (void)GNUNET_CONTAINER_multipeermap_put(connection_requests, |
94 | &msg->peer, | 93 | &msg->peer, |
95 | cr, | 94 | cr, |
96 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 95 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
97 | GAS_plugin_request_connect_start (&msg->peer); | 96 | GAS_plugin_request_connect_start(&msg->peer); |
98 | } | 97 | } |
99 | 98 | ||
100 | 99 | ||
@@ -108,25 +107,25 @@ GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | |||
108 | * @return #GNUNET_OK (continue to iterate) | 107 | * @return #GNUNET_OK (continue to iterate) |
109 | */ | 108 | */ |
110 | static int | 109 | static int |
111 | free_matching_requests (void *cls, | 110 | free_matching_requests(void *cls, |
112 | const struct GNUNET_PeerIdentity *pid, | 111 | const struct GNUNET_PeerIdentity *pid, |
113 | void *value) | 112 | void *value) |
114 | { | 113 | { |
115 | struct GNUNET_SERVICE_Client *client = cls; | 114 | struct GNUNET_SERVICE_Client *client = cls; |
116 | struct ConnectionRequest *cr = value; | 115 | struct ConnectionRequest *cr = value; |
117 | 116 | ||
118 | if (cr->client == client) | 117 | if (cr->client == client) |
119 | { | 118 | { |
120 | GAS_plugin_request_connect_stop (pid); | 119 | GAS_plugin_request_connect_stop(pid); |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
122 | "Removed request pending for peer `%s\n", | 121 | "Removed request pending for peer `%s\n", |
123 | GNUNET_i2s (pid)); | 122 | GNUNET_i2s(pid)); |
124 | GNUNET_assert (GNUNET_YES == | 123 | GNUNET_assert(GNUNET_YES == |
125 | GNUNET_CONTAINER_multipeermap_remove (connection_requests, | 124 | GNUNET_CONTAINER_multipeermap_remove(connection_requests, |
126 | pid, | 125 | pid, |
127 | cr)); | 126 | cr)); |
128 | GNUNET_free (cr); | 127 | GNUNET_free(cr); |
129 | } | 128 | } |
130 | return GNUNET_OK; | 129 | return GNUNET_OK; |
131 | } | 130 | } |
132 | 131 | ||
@@ -139,17 +138,17 @@ free_matching_requests (void *cls, | |||
139 | * @param msg the request message | 138 | * @param msg the request message |
140 | */ | 139 | */ |
141 | void | 140 | void |
142 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | 141 | GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, |
143 | const struct RequestAddressMessage *msg) | 142 | const struct RequestAddressMessage *msg) |
144 | { | 143 | { |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
146 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", | 145 | "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", |
147 | GNUNET_i2s (&msg->peer)); | 146 | GNUNET_i2s(&msg->peer)); |
148 | GNUNET_break (0 == ntohl (msg->strength)); | 147 | GNUNET_break(0 == ntohl(msg->strength)); |
149 | GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests, | 148 | GNUNET_CONTAINER_multipeermap_get_multiple(connection_requests, |
150 | &msg->peer, | 149 | &msg->peer, |
151 | &free_matching_requests, | 150 | &free_matching_requests, |
152 | client); | 151 | client); |
153 | } | 152 | } |
154 | 153 | ||
155 | 154 | ||
@@ -160,11 +159,11 @@ GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | |||
160 | * @param client handle of the (now dead) client | 159 | * @param client handle of the (now dead) client |
161 | */ | 160 | */ |
162 | void | 161 | void |
163 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) | 162 | GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client) |
164 | { | 163 | { |
165 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | 164 | GNUNET_CONTAINER_multipeermap_iterate(connection_requests, |
166 | &free_matching_requests, | 165 | &free_matching_requests, |
167 | client); | 166 | client); |
168 | } | 167 | } |
169 | 168 | ||
170 | 169 | ||
@@ -172,11 +171,11 @@ GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client) | |||
172 | * Shutdown connectivity subsystem. | 171 | * Shutdown connectivity subsystem. |
173 | */ | 172 | */ |
174 | void | 173 | void |
175 | GAS_connectivity_init () | 174 | GAS_connectivity_init() |
176 | { | 175 | { |
177 | connection_requests | 176 | connection_requests |
178 | = GNUNET_CONTAINER_multipeermap_create (32, | 177 | = GNUNET_CONTAINER_multipeermap_create(32, |
179 | GNUNET_NO); | 178 | GNUNET_NO); |
180 | } | 179 | } |
181 | 180 | ||
182 | 181 | ||
@@ -189,15 +188,15 @@ GAS_connectivity_init () | |||
189 | * @return #GNUNET_OK (continue to iterate) | 188 | * @return #GNUNET_OK (continue to iterate) |
190 | */ | 189 | */ |
191 | static int | 190 | static int |
192 | free_request (void *cls, | 191 | free_request(void *cls, |
193 | const struct GNUNET_PeerIdentity *pid, | 192 | const struct GNUNET_PeerIdentity *pid, |
194 | void *value) | 193 | void *value) |
195 | { | 194 | { |
196 | struct ConnectionRequest *cr = value; | 195 | struct ConnectionRequest *cr = value; |
197 | 196 | ||
198 | free_matching_requests (cr->client, | 197 | free_matching_requests(cr->client, |
199 | pid, | 198 | pid, |
200 | cr); | 199 | cr); |
201 | return GNUNET_OK; | 200 | return GNUNET_OK; |
202 | } | 201 | } |
203 | 202 | ||
@@ -206,14 +205,14 @@ free_request (void *cls, | |||
206 | * Shutdown connectivity subsystem. | 205 | * Shutdown connectivity subsystem. |
207 | */ | 206 | */ |
208 | void | 207 | void |
209 | GAS_connectivity_done () | 208 | GAS_connectivity_done() |
210 | { | 209 | { |
211 | GAS_plugin_solver_lock (); | 210 | GAS_plugin_solver_lock(); |
212 | GNUNET_CONTAINER_multipeermap_iterate (connection_requests, | 211 | GNUNET_CONTAINER_multipeermap_iterate(connection_requests, |
213 | &free_request, | 212 | &free_request, |
214 | NULL); | 213 | NULL); |
215 | GAS_plugin_solver_unlock (); | 214 | GAS_plugin_solver_unlock(); |
216 | GNUNET_CONTAINER_multipeermap_destroy (connection_requests); | 215 | GNUNET_CONTAINER_multipeermap_destroy(connection_requests); |
217 | connection_requests = NULL; | 216 | connection_requests = NULL; |
218 | } | 217 | } |
219 | 218 | ||
diff --git a/src/ats/gnunet-service-ats_connectivity.h b/src/ats/gnunet-service-ats_connectivity.h index 891a923db..98d84b44a 100644 --- a/src/ats/gnunet-service-ats_connectivity.h +++ b/src/ats/gnunet-service-ats_connectivity.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats_connectivity.h | 21 | * @file ats/gnunet-service-ats_connectivity.h |
22 | * @brief ats service, interaction with 'connecivity' API | 22 | * @brief ats service, interaction with 'connecivity' API |
@@ -38,8 +38,8 @@ | |||
38 | * @return #GNUNET_YES if so, #GNUNET_NO if not | 38 | * @return #GNUNET_YES if so, #GNUNET_NO if not |
39 | */ | 39 | */ |
40 | unsigned int | 40 | unsigned int |
41 | GAS_connectivity_has_peer (void *cls, | 41 | GAS_connectivity_has_peer(void *cls, |
42 | const struct GNUNET_PeerIdentity *peer); | 42 | const struct GNUNET_PeerIdentity *peer); |
43 | 43 | ||
44 | 44 | ||
45 | /** | 45 | /** |
@@ -49,8 +49,8 @@ GAS_connectivity_has_peer (void *cls, | |||
49 | * @param msg the request message | 49 | * @param msg the request message |
50 | */ | 50 | */ |
51 | void | 51 | void |
52 | GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | 52 | GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, |
53 | const struct RequestAddressMessage *msg); | 53 | const struct RequestAddressMessage *msg); |
54 | 54 | ||
55 | 55 | ||
56 | /** | 56 | /** |
@@ -60,8 +60,8 @@ GAS_handle_request_address (struct GNUNET_SERVICE_Client *client, | |||
60 | * @param msg the request message | 60 | * @param msg the request message |
61 | */ | 61 | */ |
62 | void | 62 | void |
63 | GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | 63 | GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, |
64 | const struct RequestAddressMessage *msg); | 64 | const struct RequestAddressMessage *msg); |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
@@ -71,21 +71,21 @@ GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client, | |||
71 | * @param client handle of the (now dead) client | 71 | * @param client handle of the (now dead) client |
72 | */ | 72 | */ |
73 | void | 73 | void |
74 | GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client); | 74 | GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client); |
75 | 75 | ||
76 | 76 | ||
77 | /** | 77 | /** |
78 | * Initialize connectivity subsystem. | 78 | * Initialize connectivity subsystem. |
79 | */ | 79 | */ |
80 | void | 80 | void |
81 | GAS_connectivity_init (void); | 81 | GAS_connectivity_init(void); |
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
85 | * Shutdown connectivity subsystem. | 85 | * Shutdown connectivity subsystem. |
86 | */ | 86 | */ |
87 | void | 87 | void |
88 | GAS_connectivity_done (void); | 88 | GAS_connectivity_done(void); |
89 | 89 | ||
90 | 90 | ||
91 | #endif | 91 | #endif |
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 4b58bf9b7..fa2b37425 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015 GNUnet e.V. | 3 | Copyright (C) 2011-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -31,14 +31,13 @@ | |||
31 | #include "gnunet-service-ats_normalization.h" | 31 | #include "gnunet-service-ats_normalization.h" |
32 | #include "gnunet-service-ats_plugins.h" | 32 | #include "gnunet-service-ats_plugins.h" |
33 | 33 | ||
34 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-normalization", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | * Range information for normalization of quality properties. | 38 | * Range information for normalization of quality properties. |
39 | */ | 39 | */ |
40 | struct PropertyRange | 40 | struct PropertyRange { |
41 | { | ||
42 | /** | 41 | /** |
43 | * Minimum value we see for this property across all addresses. | 42 | * Minimum value we see for this property across all addresses. |
44 | */ | 43 | */ |
@@ -65,8 +64,8 @@ static struct PropertyRange property_range; | |||
65 | * @param ni normalization information to update | 64 | * @param ni normalization information to update |
66 | */ | 65 | */ |
67 | static void | 66 | static void |
68 | update_avg (uint64_t current_val, | 67 | update_avg(uint64_t current_val, |
69 | struct GAS_NormalizationInfo *ni) | 68 | struct GAS_NormalizationInfo *ni) |
70 | { | 69 | { |
71 | double sum; | 70 | double sum; |
72 | uint32_t count; | 71 | uint32_t count; |
@@ -78,13 +77,13 @@ update_avg (uint64_t current_val, | |||
78 | count = 0; | 77 | count = 0; |
79 | sum = 0.0; | 78 | sum = 0.0; |
80 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) | 79 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) |
81 | { | ||
82 | if (UINT64_MAX != ni->atsi_abs[c1]) | ||
83 | { | 80 | { |
84 | count++; | 81 | if (UINT64_MAX != ni->atsi_abs[c1]) |
85 | sum += (double) ni->atsi_abs[c1]; | 82 | { |
83 | count++; | ||
84 | sum += (double)ni->atsi_abs[c1]; | ||
85 | } | ||
86 | } | 86 | } |
87 | } | ||
88 | if (0 == count) | 87 | if (0 == count) |
89 | ni->avg = current_val; /* must be UINT64_MAX */ | 88 | ni->avg = current_val; /* must be UINT64_MAX */ |
90 | else | 89 | else |
@@ -103,29 +102,29 @@ update_avg (uint64_t current_val, | |||
103 | * @return #GNUNET_OK (continue to iterate) | 102 | * @return #GNUNET_OK (continue to iterate) |
104 | */ | 103 | */ |
105 | static int | 104 | static int |
106 | find_min_max_it (void *cls, | 105 | find_min_max_it(void *cls, |
107 | const struct GNUNET_PeerIdentity *h, | 106 | const struct GNUNET_PeerIdentity *h, |
108 | void *k) | 107 | void *k) |
109 | { | 108 | { |
110 | struct PropertyRange *pr = cls; | 109 | struct PropertyRange *pr = cls; |
111 | const struct ATS_Address *a = k; | 110 | const struct ATS_Address *a = k; |
112 | 111 | ||
113 | pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out, | 112 | pr->max.utilization_out = GNUNET_MAX(pr->max.utilization_out, |
114 | a->properties.utilization_out); | 113 | a->properties.utilization_out); |
115 | pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in, | 114 | pr->max.utilization_in = GNUNET_MAX(pr->max.utilization_in, |
116 | a->properties.utilization_in); | 115 | a->properties.utilization_in); |
117 | pr->max.distance = GNUNET_MAX (pr->max.distance, | 116 | pr->max.distance = GNUNET_MAX(pr->max.distance, |
118 | a->properties.distance); | 117 | a->properties.distance); |
119 | pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay, | 118 | pr->max.delay = GNUNET_TIME_relative_max(pr->max.delay, |
120 | a->properties.delay); | 119 | a->properties.delay); |
121 | pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out, | 120 | pr->min.utilization_out = GNUNET_MIN(pr->min.utilization_out, |
122 | a->properties.utilization_out); | 121 | a->properties.utilization_out); |
123 | pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in, | 122 | pr->min.utilization_in = GNUNET_MIN(pr->min.utilization_in, |
124 | a->properties.utilization_in); | 123 | a->properties.utilization_in); |
125 | pr->min.distance = GNUNET_MIN (pr->min.distance, | 124 | pr->min.distance = GNUNET_MIN(pr->min.distance, |
126 | a->properties.distance); | 125 | a->properties.distance); |
127 | pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay, | 126 | pr->min.delay = GNUNET_TIME_relative_min(pr->min.delay, |
128 | a->properties.delay); | 127 | a->properties.delay); |
129 | return GNUNET_OK; | 128 | return GNUNET_OK; |
130 | } | 129 | } |
131 | 130 | ||
@@ -139,13 +138,13 @@ find_min_max_it (void *cls, | |||
139 | * @param ni normalization information to update | 138 | * @param ni normalization information to update |
140 | */ | 139 | */ |
141 | static void | 140 | static void |
142 | update_norm (uint64_t min, | 141 | update_norm(uint64_t min, |
143 | uint64_t max, | 142 | uint64_t max, |
144 | struct GAS_NormalizationInfo *ni) | 143 | struct GAS_NormalizationInfo *ni) |
145 | { | 144 | { |
146 | /* max - 2 * min + avg_value / (max - min) */ | 145 | /* max - 2 * min + avg_value / (max - min) */ |
147 | if (min < max) | 146 | if (min < max) |
148 | ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min); | 147 | ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min); |
149 | else | 148 | else |
150 | ni->norm = DEFAULT_REL_QUALITY; | 149 | ni->norm = DEFAULT_REL_QUALITY; |
151 | } | 150 | } |
@@ -163,24 +162,24 @@ update_norm (uint64_t min, | |||
163 | * @return #GNUNET_OK (continue to iterate) | 162 | * @return #GNUNET_OK (continue to iterate) |
164 | */ | 163 | */ |
165 | static int | 164 | static int |
166 | normalize_address (void *cls, | 165 | normalize_address(void *cls, |
167 | const struct GNUNET_PeerIdentity *key, | 166 | const struct GNUNET_PeerIdentity *key, |
168 | void *value) | 167 | void *value) |
169 | { | 168 | { |
170 | struct ATS_Address *address = value; | 169 | struct ATS_Address *address = value; |
171 | 170 | ||
172 | update_norm (property_range.min.delay.rel_value_us, | 171 | update_norm(property_range.min.delay.rel_value_us, |
173 | property_range.max.delay.rel_value_us, | 172 | property_range.max.delay.rel_value_us, |
174 | &address->norm_delay); | 173 | &address->norm_delay); |
175 | update_norm (property_range.min.distance, | 174 | update_norm(property_range.min.distance, |
176 | property_range.max.distance, | 175 | property_range.max.distance, |
177 | &address->norm_distance); | 176 | &address->norm_distance); |
178 | update_norm (property_range.min.utilization_in, | 177 | update_norm(property_range.min.utilization_in, |
179 | property_range.max.utilization_in, | 178 | property_range.max.utilization_in, |
180 | &address->norm_utilization_in); | 179 | &address->norm_utilization_in); |
181 | update_norm (property_range.min.utilization_out, | 180 | update_norm(property_range.min.utilization_out, |
182 | property_range.max.utilization_out, | 181 | property_range.max.utilization_out, |
183 | &address->norm_utilization_out); | 182 | &address->norm_utilization_out); |
184 | return GNUNET_OK; | 183 | return GNUNET_OK; |
185 | } | 184 | } |
186 | 185 | ||
@@ -194,13 +193,13 @@ normalize_address (void *cls, | |||
194 | * @return #GNUNET_OK (continue to iterate) | 193 | * @return #GNUNET_OK (continue to iterate) |
195 | */ | 194 | */ |
196 | static int | 195 | static int |
197 | notify_change (void *cls, | 196 | notify_change(void *cls, |
198 | const struct GNUNET_PeerIdentity *key, | 197 | const struct GNUNET_PeerIdentity *key, |
199 | void *value) | 198 | void *value) |
200 | { | 199 | { |
201 | struct ATS_Address *address = value; | 200 | struct ATS_Address *address = value; |
202 | 201 | ||
203 | GAS_plugin_notify_property_changed (address); | 202 | GAS_plugin_notify_property_changed(address); |
204 | return GNUNET_OK; | 203 | return GNUNET_OK; |
205 | } | 204 | } |
206 | 205 | ||
@@ -212,9 +211,9 @@ notify_change (void *cls, | |||
212 | * @param pr range to initialize | 211 | * @param pr range to initialize |
213 | */ | 212 | */ |
214 | static void | 213 | static void |
215 | init_range (struct PropertyRange *pr) | 214 | init_range(struct PropertyRange *pr) |
216 | { | 215 | { |
217 | memset (pr, 0, sizeof (struct PropertyRange)); | 216 | memset(pr, 0, sizeof(struct PropertyRange)); |
218 | pr->min.utilization_out = UINT32_MAX; | 217 | pr->min.utilization_out = UINT32_MAX; |
219 | pr->min.utilization_in = UINT32_MAX; | 218 | pr->min.utilization_in = UINT32_MAX; |
220 | pr->min.distance = UINT32_MAX; | 219 | pr->min.distance = UINT32_MAX; |
@@ -228,51 +227,51 @@ init_range (struct PropertyRange *pr) | |||
228 | * @param address the address to update | 227 | * @param address the address to update |
229 | */ | 228 | */ |
230 | void | 229 | void |
231 | GAS_normalization_update_property (struct ATS_Address *address) | 230 | GAS_normalization_update_property(struct ATS_Address *address) |
232 | { | 231 | { |
233 | const struct GNUNET_ATS_Properties *prop = &address->properties; | 232 | const struct GNUNET_ATS_Properties *prop = &address->properties; |
234 | struct PropertyRange range; | 233 | struct PropertyRange range; |
235 | 234 | ||
236 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 235 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
237 | "Updating properties for peer `%s'\n", | 236 | "Updating properties for peer `%s'\n", |
238 | GNUNET_i2s (&address->peer)); | 237 | GNUNET_i2s(&address->peer)); |
239 | GAS_plugin_solver_lock (); | 238 | GAS_plugin_solver_lock(); |
240 | update_avg (prop->delay.rel_value_us, | 239 | update_avg(prop->delay.rel_value_us, |
241 | &address->norm_delay); | 240 | &address->norm_delay); |
242 | update_avg (prop->distance, | 241 | update_avg(prop->distance, |
243 | &address->norm_distance); | 242 | &address->norm_distance); |
244 | update_avg (prop->utilization_in, | 243 | update_avg(prop->utilization_in, |
245 | &address->norm_utilization_in); | 244 | &address->norm_utilization_in); |
246 | update_avg (prop->utilization_in, | 245 | update_avg(prop->utilization_in, |
247 | &address->norm_utilization_out); | 246 | &address->norm_utilization_out); |
248 | 247 | ||
249 | init_range (&range); | 248 | init_range(&range); |
250 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 249 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, |
251 | &find_min_max_it, | 250 | &find_min_max_it, |
252 | &range); | 251 | &range); |
253 | if (0 != GNUNET_memcmp (&range, | 252 | if (0 != GNUNET_memcmp(&range, |
254 | &property_range)) | 253 | &property_range)) |
255 | { | 254 | { |
256 | /* limits changed, (re)normalize all addresses */ | 255 | /* limits changed, (re)normalize all addresses */ |
257 | property_range = range; | 256 | property_range = range; |
258 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 257 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, |
259 | &normalize_address, | 258 | &normalize_address, |
260 | NULL); | 259 | NULL); |
261 | GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses, | 260 | GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, |
262 | ¬ify_change, | 261 | ¬ify_change, |
263 | NULL); | 262 | NULL); |
264 | } | 263 | } |
265 | else | 264 | else |
266 | { | 265 | { |
267 | /* renormalize just this one address */ | 266 | /* renormalize just this one address */ |
268 | normalize_address (NULL, | 267 | normalize_address(NULL, |
269 | &address->peer, | 268 | &address->peer, |
270 | address); | 269 | address); |
271 | notify_change (NULL, | 270 | notify_change(NULL, |
272 | &address->peer, | 271 | &address->peer, |
273 | address); | 272 | address); |
274 | } | 273 | } |
275 | GAS_plugin_solver_unlock (); | 274 | GAS_plugin_solver_unlock(); |
276 | } | 275 | } |
277 | 276 | ||
278 | 277 | ||
@@ -280,9 +279,9 @@ GAS_normalization_update_property (struct ATS_Address *address) | |||
280 | * Start the normalization component | 279 | * Start the normalization component |
281 | */ | 280 | */ |
282 | void | 281 | void |
283 | GAS_normalization_start () | 282 | GAS_normalization_start() |
284 | { | 283 | { |
285 | init_range (&property_range); | 284 | init_range(&property_range); |
286 | } | 285 | } |
287 | 286 | ||
288 | 287 | ||
@@ -290,7 +289,7 @@ GAS_normalization_start () | |||
290 | * Stop the normalization component and free all items | 289 | * Stop the normalization component and free all items |
291 | */ | 290 | */ |
292 | void | 291 | void |
293 | GAS_normalization_stop () | 292 | GAS_normalization_stop() |
294 | { | 293 | { |
295 | /* nothing to do */ | 294 | /* nothing to do */ |
296 | } | 295 | } |
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 4435c4ae6..57bcf49f4 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_normalization.h | 22 | * @file ats/gnunet-service-ats_normalization.h |
@@ -40,21 +40,21 @@ | |||
40 | * @param address the address to update | 40 | * @param address the address to update |
41 | */ | 41 | */ |
42 | void | 42 | void |
43 | GAS_normalization_update_property (struct ATS_Address *address); | 43 | GAS_normalization_update_property(struct ATS_Address *address); |
44 | 44 | ||
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Start the normalization component | 47 | * Start the normalization component |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | GAS_normalization_start (void); | 50 | GAS_normalization_start(void); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
54 | * Stop the normalization component and free all items | 54 | * Stop the normalization component and free all items |
55 | */ | 55 | */ |
56 | void | 56 | void |
57 | GAS_normalization_stop (void); | 57 | GAS_normalization_stop(void); |
58 | 58 | ||
59 | #endif | 59 | #endif |
60 | /* end of gnunet-service-ats_normalization.h */ | 60 | /* end of gnunet-service-ats_normalization.h */ |
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 94a22d378..16d0777de 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats_performance.c | 21 | * @file ats/gnunet-service-ats_performance.c |
22 | * @brief ats service, interaction with 'performance' API | 22 | * @brief ats service, interaction with 'performance' API |
@@ -63,64 +63,64 @@ static struct GNUNET_NotificationContext *nc_pic; | |||
63 | * @param bandwidth_in assigned inbound bandwidth | 63 | * @param bandwidth_in assigned inbound bandwidth |
64 | */ | 64 | */ |
65 | static void | 65 | static void |
66 | notify_client (struct GNUNET_SERVICE_Client *client, | 66 | notify_client(struct GNUNET_SERVICE_Client *client, |
67 | const struct GNUNET_PeerIdentity *peer, | 67 | const struct GNUNET_PeerIdentity *peer, |
68 | const char *plugin_name, | 68 | const char *plugin_name, |
69 | const void *plugin_addr, | 69 | const void *plugin_addr, |
70 | size_t plugin_addr_len, | 70 | size_t plugin_addr_len, |
71 | int active, | 71 | int active, |
72 | const struct GNUNET_ATS_Properties *prop, | 72 | const struct GNUNET_ATS_Properties *prop, |
73 | enum GNUNET_HELLO_AddressInfo local_address_info, | 73 | enum GNUNET_HELLO_AddressInfo local_address_info, |
74 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 74 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
75 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 75 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
76 | { | 76 | { |
77 | struct PeerInformationMessage *msg; | 77 | struct PeerInformationMessage *msg; |
78 | size_t plugin_name_length = strlen (plugin_name) + 1; | 78 | size_t plugin_name_length = strlen(plugin_name) + 1; |
79 | size_t msize = | 79 | size_t msize = |
80 | sizeof (struct PeerInformationMessage) + | 80 | sizeof(struct PeerInformationMessage) + |
81 | plugin_addr_len + | 81 | plugin_addr_len + |
82 | plugin_name_length; | 82 | plugin_name_length; |
83 | char buf[msize] GNUNET_ALIGN; | 83 | char buf[msize] GNUNET_ALIGN; |
84 | char *addrp; | 84 | char *addrp; |
85 | 85 | ||
86 | if (NULL != prop) | 86 | if (NULL != prop) |
87 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 87 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
88 | GNUNET_assert (msize < GNUNET_MAX_MESSAGE_SIZE); | 88 | GNUNET_assert(msize < GNUNET_MAX_MESSAGE_SIZE); |
89 | msg = (struct PeerInformationMessage *) buf; | 89 | msg = (struct PeerInformationMessage *)buf; |
90 | msg->header.size = htons (msize); | 90 | msg->header.size = htons(msize); |
91 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); | 91 | msg->header.type = htons(GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); |
92 | msg->id = htonl (0); | 92 | msg->id = htonl(0); |
93 | msg->peer = *peer; | 93 | msg->peer = *peer; |
94 | msg->address_length = htons (plugin_addr_len); | 94 | msg->address_length = htons(plugin_addr_len); |
95 | msg->address_active = ntohl ((uint32_t) active); | 95 | msg->address_active = ntohl((uint32_t)active); |
96 | msg->plugin_name_length = htons (plugin_name_length); | 96 | msg->plugin_name_length = htons(plugin_name_length); |
97 | msg->bandwidth_out = bandwidth_out; | 97 | msg->bandwidth_out = bandwidth_out; |
98 | msg->bandwidth_in = bandwidth_in; | 98 | msg->bandwidth_in = bandwidth_in; |
99 | if (NULL != prop) | 99 | if (NULL != prop) |
100 | GNUNET_ATS_properties_hton (&msg->properties, | 100 | GNUNET_ATS_properties_hton(&msg->properties, |
101 | prop); | 101 | prop); |
102 | else | 102 | else |
103 | memset (&msg->properties, | 103 | memset(&msg->properties, |
104 | 0, | 104 | 0, |
105 | sizeof (struct GNUNET_ATS_Properties)); | 105 | sizeof(struct GNUNET_ATS_Properties)); |
106 | msg->address_local_info = htonl (local_address_info); | 106 | msg->address_local_info = htonl(local_address_info); |
107 | addrp = (char *) &msg[1]; | 107 | addrp = (char *)&msg[1]; |
108 | GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len); | 108 | GNUNET_memcpy(addrp, plugin_addr, plugin_addr_len); |
109 | strcpy (&addrp[plugin_addr_len], plugin_name); | 109 | strcpy(&addrp[plugin_addr_len], plugin_name); |
110 | if (NULL == client) | 110 | if (NULL == client) |
111 | { | 111 | { |
112 | GNUNET_notification_context_broadcast (nc_pic, | 112 | GNUNET_notification_context_broadcast(nc_pic, |
113 | &msg->header, | 113 | &msg->header, |
114 | GNUNET_YES); | 114 | GNUNET_YES); |
115 | } | 115 | } |
116 | else | 116 | else |
117 | { | 117 | { |
118 | struct GNUNET_MQ_Envelope *env; | 118 | struct GNUNET_MQ_Envelope *env; |
119 | 119 | ||
120 | env = GNUNET_MQ_msg_copy (&msg->header); | 120 | env = GNUNET_MQ_msg_copy(&msg->header); |
121 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 121 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
122 | env); | 122 | env); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
@@ -142,32 +142,32 @@ notify_client (struct GNUNET_SERVICE_Client *client, | |||
142 | * @param bandwidth_in assigned inbound bandwidth | 142 | * @param bandwidth_in assigned inbound bandwidth |
143 | */ | 143 | */ |
144 | void | 144 | void |
145 | GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | 145 | GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, |
146 | const char *plugin_name, | 146 | const char *plugin_name, |
147 | const void *plugin_addr, | 147 | const void *plugin_addr, |
148 | size_t plugin_addr_len, | 148 | size_t plugin_addr_len, |
149 | int active, | 149 | int active, |
150 | const struct GNUNET_ATS_Properties *prop, | 150 | const struct GNUNET_ATS_Properties *prop, |
151 | enum GNUNET_HELLO_AddressInfo local_address_info, | 151 | enum GNUNET_HELLO_AddressInfo local_address_info, |
152 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 152 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
153 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 153 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
154 | { | 154 | { |
155 | GNUNET_break ( (NULL == prop) || | 155 | GNUNET_break((NULL == prop) || |
156 | (GNUNET_NT_UNSPECIFIED != prop->scope) ); | 156 | (GNUNET_NT_UNSPECIFIED != prop->scope)); |
157 | notify_client (NULL, | 157 | notify_client(NULL, |
158 | peer, | 158 | peer, |
159 | plugin_name, | 159 | plugin_name, |
160 | plugin_addr, | 160 | plugin_addr, |
161 | plugin_addr_len, | 161 | plugin_addr_len, |
162 | active, | 162 | active, |
163 | prop, | 163 | prop, |
164 | local_address_info, | 164 | local_address_info, |
165 | bandwidth_out, | 165 | bandwidth_out, |
166 | bandwidth_in); | 166 | bandwidth_in); |
167 | GNUNET_STATISTICS_update (GSA_stats, | 167 | GNUNET_STATISTICS_update(GSA_stats, |
168 | "# performance updates given to clients", | 168 | "# performance updates given to clients", |
169 | 1, | 169 | 1, |
170 | GNUNET_NO); | 170 | GNUNET_NO); |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
@@ -186,38 +186,38 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
186 | * @param bandwidth_in current inbound bandwidth assigned to address | 186 | * @param bandwidth_in current inbound bandwidth assigned to address |
187 | */ | 187 | */ |
188 | static void | 188 | static void |
189 | peerinfo_it (void *cls, | 189 | peerinfo_it(void *cls, |
190 | const struct GNUNET_PeerIdentity *id, | 190 | const struct GNUNET_PeerIdentity *id, |
191 | const char *plugin_name, | 191 | const char *plugin_name, |
192 | const void *plugin_addr, | 192 | const void *plugin_addr, |
193 | size_t plugin_addr_len, | 193 | size_t plugin_addr_len, |
194 | int active, | 194 | int active, |
195 | const struct GNUNET_ATS_Properties *prop, | 195 | const struct GNUNET_ATS_Properties *prop, |
196 | enum GNUNET_HELLO_AddressInfo local_address_info, | 196 | enum GNUNET_HELLO_AddressInfo local_address_info, |
197 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 197 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
198 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 198 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
199 | { | 199 | { |
200 | struct GNUNET_SERVICE_Client *client = cls; | 200 | struct GNUNET_SERVICE_Client *client = cls; |
201 | 201 | ||
202 | if (NULL == id) | 202 | if (NULL == id) |
203 | return; | 203 | return; |
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 204 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
205 | "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n", | 205 | "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n", |
206 | GNUNET_i2s (id), | 206 | GNUNET_i2s(id), |
207 | plugin_name, | 207 | plugin_name, |
208 | (unsigned int) ntohl (bandwidth_out.value__), | 208 | (unsigned int)ntohl(bandwidth_out.value__), |
209 | (unsigned int) ntohl (bandwidth_in.value__)); | 209 | (unsigned int)ntohl(bandwidth_in.value__)); |
210 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); | 210 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); |
211 | notify_client (client, | 211 | notify_client(client, |
212 | id, | 212 | id, |
213 | plugin_name, | 213 | plugin_name, |
214 | plugin_addr, | 214 | plugin_addr, |
215 | plugin_addr_len, | 215 | plugin_addr_len, |
216 | active, | 216 | active, |
217 | prop, | 217 | prop, |
218 | local_address_info, | 218 | local_address_info, |
219 | bandwidth_out, | 219 | bandwidth_out, |
220 | bandwidth_in); | 220 | bandwidth_in); |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
@@ -228,25 +228,25 @@ peerinfo_it (void *cls, | |||
228 | * @param flag flag specifying the type of the client | 228 | * @param flag flag specifying the type of the client |
229 | */ | 229 | */ |
230 | void | 230 | void |
231 | GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, | 231 | GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, |
232 | enum StartFlag flag) | 232 | enum StartFlag flag) |
233 | { | 233 | { |
234 | struct GNUNET_MQ_Handle *mq; | 234 | struct GNUNET_MQ_Handle *mq; |
235 | 235 | ||
236 | mq = GNUNET_SERVICE_client_get_mq (client); | 236 | mq = GNUNET_SERVICE_client_get_mq(client); |
237 | if (START_FLAG_PERFORMANCE_WITH_PIC == flag) | 237 | if (START_FLAG_PERFORMANCE_WITH_PIC == flag) |
238 | { | 238 | { |
239 | GNUNET_notification_context_add (nc_pic, | 239 | GNUNET_notification_context_add(nc_pic, |
240 | mq); | 240 | mq); |
241 | GAS_addresses_get_peer_info (NULL, | 241 | GAS_addresses_get_peer_info(NULL, |
242 | &peerinfo_it, | 242 | &peerinfo_it, |
243 | client); | 243 | client); |
244 | } | 244 | } |
245 | else | 245 | else |
246 | { | 246 | { |
247 | GNUNET_notification_context_add (nc_no_pic, | 247 | GNUNET_notification_context_add(nc_no_pic, |
248 | mq); | 248 | mq); |
249 | } | 249 | } |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
@@ -256,10 +256,10 @@ GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, | |||
256 | * @param server handle to our server | 256 | * @param server handle to our server |
257 | */ | 257 | */ |
258 | void | 258 | void |
259 | GAS_performance_init () | 259 | GAS_performance_init() |
260 | { | 260 | { |
261 | nc_no_pic = GNUNET_notification_context_create (32); | 261 | nc_no_pic = GNUNET_notification_context_create(32); |
262 | nc_pic = GNUNET_notification_context_create (32); | 262 | nc_pic = GNUNET_notification_context_create(32); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
@@ -267,11 +267,11 @@ GAS_performance_init () | |||
267 | * Shutdown performance subsystem. | 267 | * Shutdown performance subsystem. |
268 | */ | 268 | */ |
269 | void | 269 | void |
270 | GAS_performance_done () | 270 | GAS_performance_done() |
271 | { | 271 | { |
272 | GNUNET_notification_context_destroy (nc_no_pic); | 272 | GNUNET_notification_context_destroy(nc_no_pic); |
273 | nc_no_pic = NULL; | 273 | nc_no_pic = NULL; |
274 | GNUNET_notification_context_destroy (nc_pic); | 274 | GNUNET_notification_context_destroy(nc_pic); |
275 | nc_pic = NULL; | 275 | nc_pic = NULL; |
276 | } | 276 | } |
277 | 277 | ||
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index e7ba3b554..3d5de0d85 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_performance.h | 22 | * @file ats/gnunet-service-ats_performance.h |
@@ -50,15 +50,15 @@ | |||
50 | * @param bandwidth_in assigned inbound bandwidth | 50 | * @param bandwidth_in assigned inbound bandwidth |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | 53 | GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, |
54 | const char *plugin_name, | 54 | const char *plugin_name, |
55 | const void *plugin_addr, | 55 | const void *plugin_addr, |
56 | size_t plugin_addr_len, | 56 | size_t plugin_addr_len, |
57 | int active, | 57 | int active, |
58 | const struct GNUNET_ATS_Properties *prop, | 58 | const struct GNUNET_ATS_Properties *prop, |
59 | enum GNUNET_HELLO_AddressInfo local_address_info, | 59 | enum GNUNET_HELLO_AddressInfo local_address_info, |
60 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 60 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
61 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); | 61 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
@@ -68,8 +68,8 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer, | |||
68 | * @param flag flag specifying the type of the client | 68 | * @param flag flag specifying the type of the client |
69 | */ | 69 | */ |
70 | void | 70 | void |
71 | GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, | 71 | GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, |
72 | enum StartFlag flag); | 72 | enum StartFlag flag); |
73 | 73 | ||
74 | 74 | ||
75 | /** | 75 | /** |
@@ -79,14 +79,14 @@ GAS_performance_add_client (struct GNUNET_SERVICE_Client *client, | |||
79 | * @param addresses the address handle to use | 79 | * @param addresses the address handle to use |
80 | */ | 80 | */ |
81 | void | 81 | void |
82 | GAS_performance_init (void); | 82 | GAS_performance_init(void); |
83 | 83 | ||
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Shutdown performance subsystem. | 86 | * Shutdown performance subsystem. |
87 | */ | 87 | */ |
88 | void | 88 | void |
89 | GAS_performance_done (void); | 89 | GAS_performance_done(void); |
90 | 90 | ||
91 | 91 | ||
92 | #endif | 92 | #endif |
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index 0b0e5ec4b..274f89e7a 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -59,14 +59,14 @@ static char *plugin; | |||
59 | * @param pref_rel the new relative preference value | 59 | * @param pref_rel the new relative preference value |
60 | */ | 60 | */ |
61 | void | 61 | void |
62 | GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | 62 | GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, |
63 | enum GNUNET_ATS_PreferenceKind kind, | 63 | enum GNUNET_ATS_PreferenceKind kind, |
64 | double pref_rel) | 64 | double pref_rel) |
65 | { | 65 | { |
66 | sf->s_pref (sf->cls, | 66 | sf->s_pref(sf->cls, |
67 | peer, | 67 | peer, |
68 | kind, | 68 | kind, |
69 | pref_rel); | 69 | pref_rel); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
@@ -76,10 +76,10 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | |||
76 | * @param address the peer for which a property changed | 76 | * @param address the peer for which a property changed |
77 | */ | 77 | */ |
78 | void | 78 | void |
79 | GAS_plugin_notify_property_changed (struct ATS_Address *address) | 79 | GAS_plugin_notify_property_changed(struct ATS_Address *address) |
80 | { | 80 | { |
81 | sf->s_address_update_property (sf->cls, | 81 | sf->s_address_update_property(sf->cls, |
82 | address); | 82 | address); |
83 | } | 83 | } |
84 | 84 | ||
85 | 85 | ||
@@ -92,100 +92,116 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address) | |||
92 | * @param add additional information | 92 | * @param add additional information |
93 | */ | 93 | */ |
94 | static void | 94 | static void |
95 | solver_info_cb (void *cls, | 95 | solver_info_cb(void *cls, |
96 | enum GAS_Solver_Operation op, | 96 | enum GAS_Solver_Operation op, |
97 | enum GAS_Solver_Status status, | 97 | enum GAS_Solver_Status status, |
98 | enum GAS_Solver_Additional_Information add) | 98 | enum GAS_Solver_Additional_Information add) |
99 | { | 99 | { |
100 | const char *add_info; | 100 | const char *add_info; |
101 | 101 | ||
102 | switch (add) { | 102 | switch (add) |
103 | { | ||
103 | case GAS_INFO_NONE: | 104 | case GAS_INFO_NONE: |
104 | add_info = "GAS_INFO_NONE"; | 105 | add_info = "GAS_INFO_NONE"; |
105 | break; | 106 | break; |
107 | |||
106 | case GAS_INFO_FULL: | 108 | case GAS_INFO_FULL: |
107 | add_info = "GAS_INFO_MLP_FULL"; | 109 | add_info = "GAS_INFO_MLP_FULL"; |
108 | break; | 110 | break; |
111 | |||
109 | case GAS_INFO_UPDATED: | 112 | case GAS_INFO_UPDATED: |
110 | add_info = "GAS_INFO_MLP_UPDATED"; | 113 | add_info = "GAS_INFO_MLP_UPDATED"; |
111 | break; | 114 | break; |
115 | |||
112 | case GAS_INFO_PROP_ALL: | 116 | case GAS_INFO_PROP_ALL: |
113 | add_info = "GAS_INFO_PROP_ALL"; | 117 | add_info = "GAS_INFO_PROP_ALL"; |
114 | break; | 118 | break; |
119 | |||
115 | case GAS_INFO_PROP_SINGLE: | 120 | case GAS_INFO_PROP_SINGLE: |
116 | add_info = "GAS_INFO_PROP_SINGLE"; | 121 | add_info = "GAS_INFO_PROP_SINGLE"; |
117 | break; | 122 | break; |
123 | |||
118 | default: | 124 | default: |
119 | add_info = "INVALID"; | 125 | add_info = "INVALID"; |
120 | break; | 126 | break; |
121 | } | 127 | } |
122 | switch (op) | 128 | switch (op) |
123 | { | 129 | { |
124 | case GAS_OP_SOLVE_START: | 130 | case GAS_OP_SOLVE_START: |
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 131 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
126 | "Solver notifies `%s' with result `%s' `%s'\n", | 132 | "Solver notifies `%s' with result `%s' `%s'\n", |
127 | "GAS_OP_SOLVE_START", | 133 | "GAS_OP_SOLVE_START", |
128 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", | 134 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", |
129 | add_info); | 135 | add_info); |
130 | return; | 136 | return; |
131 | case GAS_OP_SOLVE_STOP: | 137 | |
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 138 | case GAS_OP_SOLVE_STOP: |
133 | "Solver notifies `%s' with result `%s'\n", | 139 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
134 | "GAS_OP_SOLVE_STOP", | 140 | "Solver notifies `%s' with result `%s'\n", |
135 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 141 | "GAS_OP_SOLVE_STOP", |
136 | return; | 142 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
137 | case GAS_OP_SOLVE_SETUP_START: | 143 | return; |
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | |
139 | "Solver notifies `%s' with result `%s'\n", | 145 | case GAS_OP_SOLVE_SETUP_START: |
140 | "GAS_OP_SOLVE_SETUP_START", | 146 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
141 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 147 | "Solver notifies `%s' with result `%s'\n", |
142 | return; | 148 | "GAS_OP_SOLVE_SETUP_START", |
143 | case GAS_OP_SOLVE_SETUP_STOP: | 149 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 150 | return; |
145 | "Solver notifies `%s' with result `%s'\n", | 151 | |
146 | "GAS_OP_SOLVE_SETUP_STOP", | 152 | case GAS_OP_SOLVE_SETUP_STOP: |
147 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
148 | return; | 154 | "Solver notifies `%s' with result `%s'\n", |
149 | case GAS_OP_SOLVE_MLP_LP_START: | 155 | "GAS_OP_SOLVE_SETUP_STOP", |
150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 156 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
151 | "Solver notifies `%s' with result `%s'\n", | 157 | return; |
152 | "GAS_OP_SOLVE_LP_START", | 158 | |
153 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 159 | case GAS_OP_SOLVE_MLP_LP_START: |
154 | return; | 160 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
155 | case GAS_OP_SOLVE_MLP_LP_STOP: | 161 | "Solver notifies `%s' with result `%s'\n", |
156 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 162 | "GAS_OP_SOLVE_LP_START", |
157 | "Solver notifies `%s' with result `%s'\n", | 163 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
158 | "GAS_OP_SOLVE_LP_STOP", | 164 | return; |
159 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 165 | |
160 | return; | 166 | case GAS_OP_SOLVE_MLP_LP_STOP: |
161 | case GAS_OP_SOLVE_MLP_MLP_START: | 167 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
162 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 168 | "Solver notifies `%s' with result `%s'\n", |
163 | "Solver notifies `%s' with result `%s'\n", | 169 | "GAS_OP_SOLVE_LP_STOP", |
164 | "GAS_OP_SOLVE_MLP_START", | 170 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
165 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 171 | return; |
166 | return; | 172 | |
167 | case GAS_OP_SOLVE_MLP_MLP_STOP: | 173 | case GAS_OP_SOLVE_MLP_MLP_START: |
168 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
169 | "Solver notifies `%s' with result `%s'\n", | 175 | "Solver notifies `%s' with result `%s'\n", |
170 | "GAS_OP_SOLVE_MLP_STOP", | 176 | "GAS_OP_SOLVE_MLP_START", |
171 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 177 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
172 | return; | 178 | return; |
173 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: | 179 | |
174 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 180 | case GAS_OP_SOLVE_MLP_MLP_STOP: |
175 | "Solver notifies `%s' with result `%s'\n", | 181 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
176 | "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", | 182 | "Solver notifies `%s' with result `%s'\n", |
177 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 183 | "GAS_OP_SOLVE_MLP_STOP", |
178 | return; | 184 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
179 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: | 185 | return; |
180 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 186 | |
181 | "Solver notifies `%s' with result `%s'\n", | 187 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: |
182 | "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", | 188 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
183 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | 189 | "Solver notifies `%s' with result `%s'\n", |
184 | return; | 190 | "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", |
185 | default: | 191 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); |
186 | GNUNET_break (0); | 192 | return; |
187 | break; | 193 | |
188 | } | 194 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: |
195 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
196 | "Solver notifies `%s' with result `%s'\n", | ||
197 | "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", | ||
198 | (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); | ||
199 | return; | ||
200 | |||
201 | default: | ||
202 | GNUNET_break(0); | ||
203 | break; | ||
204 | } | ||
189 | } | 205 | } |
190 | 206 | ||
191 | 207 | ||
@@ -196,69 +212,69 @@ solver_info_cb (void *cls, | |||
196 | * @param address the address with changes | 212 | * @param address the address with changes |
197 | */ | 213 | */ |
198 | static void | 214 | static void |
199 | bandwidth_changed_cb (void *cls, | 215 | bandwidth_changed_cb(void *cls, |
200 | struct ATS_Address *address) | 216 | struct ATS_Address *address) |
201 | { | 217 | { |
202 | long long diff_out; | 218 | long long diff_out; |
203 | long long diff_in; | 219 | long long diff_in; |
204 | 220 | ||
205 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 221 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
206 | "Bandwidth assignment changed for peer %s to %u/%u\n", | 222 | "Bandwidth assignment changed for peer %s to %u/%u\n", |
207 | GNUNET_i2s (&address->peer), | 223 | GNUNET_i2s(&address->peer), |
208 | (unsigned int) address->assigned_bw_in, | 224 | (unsigned int)address->assigned_bw_in, |
209 | (unsigned int) address->assigned_bw_out); | 225 | (unsigned int)address->assigned_bw_out); |
210 | GAS_reservations_set_bandwidth (&address->peer, | 226 | GAS_reservations_set_bandwidth(&address->peer, |
211 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 227 | GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); |
212 | /* Notify performance clients about changes to address */ | 228 | /* Notify performance clients about changes to address */ |
213 | GAS_performance_notify_all_clients (&address->peer, | 229 | GAS_performance_notify_all_clients(&address->peer, |
214 | address->plugin, | 230 | address->plugin, |
215 | address->addr, | 231 | address->addr, |
216 | address->addr_len, | 232 | address->addr_len, |
217 | address->active, | 233 | address->active, |
218 | &address->properties, | 234 | &address->properties, |
219 | address->local_address_info, | 235 | address->local_address_info, |
220 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), | 236 | GNUNET_BANDWIDTH_value_init(address->assigned_bw_out), |
221 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 237 | GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); |
222 | 238 | ||
223 | if ( (0 == address->assigned_bw_in) && | 239 | if ((0 == address->assigned_bw_in) && |
224 | (0 == address->assigned_bw_out) ) | 240 | (0 == address->assigned_bw_out)) |
225 | { | 241 | { |
226 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 242 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
227 | "Telling transport to disconnect peer `%s'\n", | 243 | "Telling transport to disconnect peer `%s'\n", |
228 | GNUNET_i2s (&address->peer)); | 244 | GNUNET_i2s(&address->peer)); |
229 | 245 | ||
230 | /* Notify scheduling clients about suggestion */ | 246 | /* Notify scheduling clients about suggestion */ |
231 | GAS_scheduling_transmit_address_suggestion (&address->peer, | 247 | GAS_scheduling_transmit_address_suggestion(&address->peer, |
232 | address->session_id, | 248 | address->session_id, |
233 | GNUNET_BANDWIDTH_ZERO, | 249 | GNUNET_BANDWIDTH_ZERO, |
234 | GNUNET_BANDWIDTH_ZERO); | 250 | GNUNET_BANDWIDTH_ZERO); |
235 | return; | 251 | return; |
236 | } | 252 | } |
237 | 253 | ||
238 | /* Do bandwidth stability check */ | 254 | /* Do bandwidth stability check */ |
239 | diff_out = llabs ((long long) address->assigned_bw_out - | 255 | diff_out = llabs((long long)address->assigned_bw_out - |
240 | (long long) address->last_notified_bw_out); | 256 | (long long)address->last_notified_bw_out); |
241 | diff_in = llabs ((long long) address->assigned_bw_in - | 257 | diff_in = llabs((long long)address->assigned_bw_in - |
242 | (long long) address->last_notified_bw_in); | 258 | (long long)address->last_notified_bw_in); |
243 | if ( (diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) && | 259 | if ((diff_out < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) && |
244 | (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) ) | 260 | (diff_in < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__))) |
245 | { | 261 | { |
246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 262 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
247 | "Bandwidth change too small, not notifying client\n"); | 263 | "Bandwidth change too small, not notifying client\n"); |
248 | return; | 264 | return; |
249 | } | 265 | } |
250 | 266 | ||
251 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 267 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
252 | "Sending bandwidth update for peer `%s': %u/%u\n", | 268 | "Sending bandwidth update for peer `%s': %u/%u\n", |
253 | GNUNET_i2s (&address->peer), | 269 | GNUNET_i2s(&address->peer), |
254 | address->assigned_bw_out, | 270 | address->assigned_bw_out, |
255 | address->assigned_bw_out); | 271 | address->assigned_bw_out); |
256 | 272 | ||
257 | /* *Notify scheduling clients about suggestion */ | 273 | /* *Notify scheduling clients about suggestion */ |
258 | GAS_scheduling_transmit_address_suggestion (&address->peer, | 274 | GAS_scheduling_transmit_address_suggestion(&address->peer, |
259 | address->session_id, | 275 | address->session_id, |
260 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_out), | 276 | GNUNET_BANDWIDTH_value_init(address->assigned_bw_out), |
261 | GNUNET_BANDWIDTH_value_init (address->assigned_bw_in)); | 277 | GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); |
262 | 278 | ||
263 | address->last_notified_bw_out = address->assigned_bw_out; | 279 | address->last_notified_bw_out = address->assigned_bw_out; |
264 | address->last_notified_bw_in = address->assigned_bw_in; | 280 | address->last_notified_bw_in = address->assigned_bw_in; |
@@ -274,48 +290,48 @@ bandwidth_changed_cb (void *cls, | |||
274 | * @return numeric quota value to use | 290 | * @return numeric quota value to use |
275 | */ | 291 | */ |
276 | static unsigned long long | 292 | static unsigned long long |
277 | parse_quota (const char *quota_str, | 293 | parse_quota(const char *quota_str, |
278 | const char *direction, | 294 | const char *direction, |
279 | enum GNUNET_NetworkType network) | 295 | enum GNUNET_NetworkType network) |
280 | { | 296 | { |
281 | int res; | 297 | int res; |
282 | unsigned long long ret; | 298 | unsigned long long ret; |
283 | 299 | ||
284 | res = GNUNET_NO; | 300 | res = GNUNET_NO; |
285 | if (0 == strcmp (quota_str, GNUNET_ATS_MaxBandwidthString)) | 301 | if (0 == strcmp(quota_str, GNUNET_ATS_MaxBandwidthString)) |
286 | { | 302 | { |
287 | ret = GNUNET_ATS_MaxBandwidth; | 303 | ret = GNUNET_ATS_MaxBandwidth; |
288 | res = GNUNET_YES; | 304 | res = GNUNET_YES; |
289 | } | 305 | } |
290 | if ((GNUNET_NO == res) && | 306 | if ((GNUNET_NO == res) && |
291 | (GNUNET_OK == | 307 | (GNUNET_OK == |
292 | GNUNET_STRINGS_fancy_size_to_bytes (quota_str, | 308 | GNUNET_STRINGS_fancy_size_to_bytes(quota_str, |
293 | &ret))) | 309 | &ret))) |
294 | res = GNUNET_YES; | 310 | res = GNUNET_YES; |
295 | if ((GNUNET_NO == res) && | 311 | if ((GNUNET_NO == res) && |
296 | (1 == | 312 | (1 == |
297 | sscanf (quota_str, | 313 | sscanf(quota_str, |
298 | "%llu", | 314 | "%llu", |
299 | &ret))) | 315 | &ret))) |
300 | res = GNUNET_YES; | 316 | res = GNUNET_YES; |
301 | if (GNUNET_NO == res) | 317 | if (GNUNET_NO == res) |
302 | { | 318 | { |
303 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 319 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
304 | _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), | 320 | _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), |
305 | direction, | 321 | direction, |
306 | GNUNET_NT_to_string (network), | 322 | GNUNET_NT_to_string(network), |
307 | quota_str, | 323 | quota_str, |
308 | (unsigned long long) GNUNET_ATS_DefaultBandwidth); | 324 | (unsigned long long)GNUNET_ATS_DefaultBandwidth); |
309 | ret = GNUNET_ATS_DefaultBandwidth; | 325 | ret = GNUNET_ATS_DefaultBandwidth; |
310 | } | 326 | } |
311 | else | 327 | else |
312 | { | 328 | { |
313 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 329 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
314 | _("%s quota configured for network `%s' is %llu\n"), | 330 | _("%s quota configured for network `%s' is %llu\n"), |
315 | direction, | 331 | direction, |
316 | GNUNET_NT_to_string (network), | 332 | GNUNET_NT_to_string(network), |
317 | ret); | 333 | ret); |
318 | } | 334 | } |
319 | return ret; | 335 | return ret; |
320 | } | 336 | } |
321 | 337 | ||
@@ -330,39 +346,39 @@ parse_quota (const char *quota_str, | |||
330 | * @return quota to apply | 346 | * @return quota to apply |
331 | */ | 347 | */ |
332 | static unsigned long long | 348 | static unsigned long long |
333 | load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg, | 349 | load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, |
334 | enum GNUNET_NetworkType type, | 350 | enum GNUNET_NetworkType type, |
335 | const char *direction) | 351 | const char *direction) |
336 | { | 352 | { |
337 | char *entry; | 353 | char *entry; |
338 | char *quota_str; | 354 | char *quota_str; |
339 | unsigned long long ret; | 355 | unsigned long long ret; |
340 | 356 | ||
341 | GNUNET_asprintf (&entry, | 357 | GNUNET_asprintf(&entry, |
342 | "%s_QUOTA_%s", | 358 | "%s_QUOTA_%s", |
343 | GNUNET_NT_to_string (type), | 359 | GNUNET_NT_to_string(type), |
344 | direction); | 360 | direction); |
345 | if (GNUNET_OK == | 361 | if (GNUNET_OK == |
346 | GNUNET_CONFIGURATION_get_value_string (cfg, | 362 | GNUNET_CONFIGURATION_get_value_string(cfg, |
347 | "ats", | 363 | "ats", |
348 | entry, | 364 | entry, |
349 | "a_str)) | 365 | "a_str)) |
350 | { | 366 | { |
351 | ret = parse_quota (quota_str, | 367 | ret = parse_quota(quota_str, |
352 | direction, | 368 | direction, |
353 | type); | 369 | type); |
354 | GNUNET_free (quota_str); | 370 | GNUNET_free(quota_str); |
355 | } | 371 | } |
356 | else | 372 | else |
357 | { | 373 | { |
358 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 374 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
359 | _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"), | 375 | _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"), |
360 | direction, | 376 | direction, |
361 | GNUNET_NT_to_string (type), | 377 | GNUNET_NT_to_string(type), |
362 | (unsigned long long) GNUNET_ATS_DefaultBandwidth); | 378 | (unsigned long long)GNUNET_ATS_DefaultBandwidth); |
363 | ret = GNUNET_ATS_DefaultBandwidth; | 379 | ret = GNUNET_ATS_DefaultBandwidth; |
364 | } | 380 | } |
365 | GNUNET_free (entry); | 381 | GNUNET_free(entry); |
366 | return ret; | 382 | return ret; |
367 | } | 383 | } |
368 | 384 | ||
@@ -377,27 +393,27 @@ load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
377 | * @return number of networks loaded | 393 | * @return number of networks loaded |
378 | */ | 394 | */ |
379 | static unsigned int | 395 | static unsigned int |
380 | load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | 396 | load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg, |
381 | unsigned long long *out_dest, | 397 | unsigned long long *out_dest, |
382 | unsigned long long *in_dest, | 398 | unsigned long long *in_dest, |
383 | int dest_length) | 399 | int dest_length) |
384 | { | 400 | { |
385 | unsigned int c; | 401 | unsigned int c; |
386 | 402 | ||
387 | for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) | 403 | for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) |
388 | { | 404 | { |
389 | in_dest[c] = load_quota (cfg, | 405 | in_dest[c] = load_quota(cfg, |
390 | c, | ||
391 | "out"); | ||
392 | out_dest[c] = load_quota (cfg, | ||
393 | c, | 406 | c, |
394 | "in"); | 407 | "out"); |
395 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 408 | out_dest[c] = load_quota(cfg, |
396 | "Loaded quota for network `%s' (in/out): %llu %llu\n", | 409 | c, |
397 | GNUNET_NT_to_string (c), | 410 | "in"); |
398 | in_dest[c], | 411 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
399 | out_dest[c]); | 412 | "Loaded quota for network `%s' (in/out): %llu %llu\n", |
400 | } | 413 | GNUNET_NT_to_string(c), |
414 | in_dest[c], | ||
415 | out_dest[c]); | ||
416 | } | ||
401 | return c; | 417 | return c; |
402 | } | 418 | } |
403 | 419 | ||
@@ -410,21 +426,21 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
410 | * solver plugin) | 426 | * solver plugin) |
411 | */ | 427 | */ |
412 | int | 428 | int |
413 | GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | 429 | GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg) |
414 | { | 430 | { |
415 | char *mode_str; | 431 | char *mode_str; |
416 | 432 | ||
417 | /* Figure out configured solution method */ | 433 | /* Figure out configured solution method */ |
418 | if (GNUNET_SYSERR == | 434 | if (GNUNET_SYSERR == |
419 | GNUNET_CONFIGURATION_get_value_string (cfg, | 435 | GNUNET_CONFIGURATION_get_value_string(cfg, |
420 | "ats", | 436 | "ats", |
421 | "MODE", | 437 | "MODE", |
422 | &mode_str)) | 438 | &mode_str)) |
423 | { | 439 | { |
424 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 440 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
425 | "No resource assignment method configured, using proportional approach\n"); | 441 | "No resource assignment method configured, using proportional approach\n"); |
426 | mode_str = GNUNET_strdup ("proportional"); | 442 | mode_str = GNUNET_strdup("proportional"); |
427 | } | 443 | } |
428 | env.cls = NULL; | 444 | env.cls = NULL; |
429 | env.info_cb = &solver_info_cb; | 445 | env.info_cb = &solver_info_cb; |
430 | env.bandwidth_changed_cb = &bandwidth_changed_cb; | 446 | env.bandwidth_changed_cb = &bandwidth_changed_cb; |
@@ -434,24 +450,24 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
434 | env.stats = GSA_stats; | 450 | env.stats = GSA_stats; |
435 | env.addresses = GSA_addresses; | 451 | env.addresses = GSA_addresses; |
436 | env.network_count = GNUNET_NT_COUNT; | 452 | env.network_count = GNUNET_NT_COUNT; |
437 | load_quotas (cfg, | 453 | load_quotas(cfg, |
438 | env.out_quota, | 454 | env.out_quota, |
439 | env.in_quota, | 455 | env.in_quota, |
440 | GNUNET_NT_COUNT); | 456 | GNUNET_NT_COUNT); |
441 | GNUNET_asprintf (&plugin, | 457 | GNUNET_asprintf(&plugin, |
442 | "libgnunet_plugin_ats_%s", | 458 | "libgnunet_plugin_ats_%s", |
443 | mode_str); | 459 | mode_str); |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 460 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
445 | "Initializing solver `%s'\n", | 461 | "Initializing solver `%s'\n", |
446 | mode_str); | 462 | mode_str); |
447 | GNUNET_free (mode_str); | 463 | GNUNET_free(mode_str); |
448 | if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env))) | 464 | if (NULL == (sf = GNUNET_PLUGIN_load(plugin, &env))) |
449 | { | 465 | { |
450 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 466 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
451 | _("Failed to initialize solver `%s'!\n"), | 467 | _("Failed to initialize solver `%s'!\n"), |
452 | plugin); | 468 | plugin); |
453 | return GNUNET_SYSERR; | 469 | return GNUNET_SYSERR; |
454 | } | 470 | } |
455 | return GNUNET_OK; | 471 | return GNUNET_OK; |
456 | } | 472 | } |
457 | 473 | ||
@@ -460,12 +476,12 @@ GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
460 | * Shutdown address subsystem. | 476 | * Shutdown address subsystem. |
461 | */ | 477 | */ |
462 | void | 478 | void |
463 | GAS_plugin_done () | 479 | GAS_plugin_done() |
464 | { | 480 | { |
465 | GNUNET_PLUGIN_unload (plugin, | 481 | GNUNET_PLUGIN_unload(plugin, |
466 | sf); | 482 | sf); |
467 | sf = NULL; | 483 | sf = NULL; |
468 | GNUNET_free (plugin); | 484 | GNUNET_free(plugin); |
469 | plugin = NULL; | 485 | plugin = NULL; |
470 | } | 486 | } |
471 | 487 | ||
@@ -477,11 +493,11 @@ GAS_plugin_done () | |||
477 | * @param new_address the new address | 493 | * @param new_address the new address |
478 | */ | 494 | */ |
479 | void | 495 | void |
480 | GAS_plugin_new_address (struct ATS_Address *new_address) | 496 | GAS_plugin_new_address(struct ATS_Address *new_address) |
481 | { | 497 | { |
482 | sf->s_add (sf->cls, | 498 | sf->s_add(sf->cls, |
483 | new_address, | 499 | new_address, |
484 | new_address->properties.scope); /* FIXME: remove 3rd arg here! */ | 500 | new_address->properties.scope); /* FIXME: remove 3rd arg here! */ |
485 | } | 501 | } |
486 | 502 | ||
487 | 503 | ||
@@ -492,10 +508,10 @@ GAS_plugin_new_address (struct ATS_Address *new_address) | |||
492 | * @param address address that was deleted | 508 | * @param address address that was deleted |
493 | */ | 509 | */ |
494 | void | 510 | void |
495 | GAS_plugin_delete_address (struct ATS_Address *address) | 511 | GAS_plugin_delete_address(struct ATS_Address *address) |
496 | { | 512 | { |
497 | sf->s_del (sf->cls, | 513 | sf->s_del(sf->cls, |
498 | address); | 514 | address); |
499 | } | 515 | } |
500 | 516 | ||
501 | 517 | ||
@@ -510,18 +526,18 @@ GAS_plugin_delete_address (struct ATS_Address *address) | |||
510 | * @param score_abs degree of the appreciation | 526 | * @param score_abs degree of the appreciation |
511 | */ | 527 | */ |
512 | void | 528 | void |
513 | GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, | 529 | GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application, |
514 | const struct GNUNET_PeerIdentity *peer, | 530 | const struct GNUNET_PeerIdentity *peer, |
515 | const struct GNUNET_TIME_Relative scope, | 531 | const struct GNUNET_TIME_Relative scope, |
516 | enum GNUNET_ATS_PreferenceKind kind, | 532 | enum GNUNET_ATS_PreferenceKind kind, |
517 | float score_abs) | 533 | float score_abs) |
518 | { | 534 | { |
519 | sf->s_feedback (sf->cls, | 535 | sf->s_feedback(sf->cls, |
520 | application, | 536 | application, |
521 | peer, | 537 | peer, |
522 | scope, | 538 | scope, |
523 | kind, | 539 | kind, |
524 | score_abs); | 540 | score_abs); |
525 | } | 541 | } |
526 | 542 | ||
527 | 543 | ||
@@ -530,9 +546,9 @@ GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, | |||
530 | * happening in bulk right now. | 546 | * happening in bulk right now. |
531 | */ | 547 | */ |
532 | void | 548 | void |
533 | GAS_plugin_solver_lock () | 549 | GAS_plugin_solver_lock() |
534 | { | 550 | { |
535 | sf->s_bulk_start (sf->cls); | 551 | sf->s_bulk_start(sf->cls); |
536 | } | 552 | } |
537 | 553 | ||
538 | 554 | ||
@@ -540,9 +556,9 @@ GAS_plugin_solver_lock () | |||
540 | * Resume instant solving, we are done with the bulk state updates. | 556 | * Resume instant solving, we are done with the bulk state updates. |
541 | */ | 557 | */ |
542 | void | 558 | void |
543 | GAS_plugin_solver_unlock () | 559 | GAS_plugin_solver_unlock() |
544 | { | 560 | { |
545 | sf->s_bulk_stop (sf->cls); | 561 | sf->s_bulk_stop(sf->cls); |
546 | } | 562 | } |
547 | 563 | ||
548 | 564 | ||
@@ -553,10 +569,10 @@ GAS_plugin_solver_unlock () | |||
553 | * @param pid identity of peer we now care about | 569 | * @param pid identity of peer we now care about |
554 | */ | 570 | */ |
555 | void | 571 | void |
556 | GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid) | 572 | GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid) |
557 | { | 573 | { |
558 | sf->s_get (sf->cls, | 574 | sf->s_get(sf->cls, |
559 | pid); | 575 | pid); |
560 | } | 576 | } |
561 | 577 | ||
562 | 578 | ||
@@ -567,10 +583,10 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid) | |||
567 | * @param pid identity of peer we care now less about | 583 | * @param pid identity of peer we care now less about |
568 | */ | 584 | */ |
569 | void | 585 | void |
570 | GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid) | 586 | GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid) |
571 | { | 587 | { |
572 | sf->s_get_stop (sf->cls, | 588 | sf->s_get_stop(sf->cls, |
573 | pid); | 589 | pid); |
574 | } | 590 | } |
575 | 591 | ||
576 | 592 | ||
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h index 70ae1d597..e2256f691 100644 --- a/src/ats/gnunet-service-ats_plugins.h +++ b/src/ats/gnunet-service-ats_plugins.h | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -41,14 +41,14 @@ | |||
41 | * solver plugin) | 41 | * solver plugin) |
42 | */ | 42 | */ |
43 | int | 43 | int |
44 | GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg); | 44 | GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Shutdown address subsystem. | 48 | * Shutdown address subsystem. |
49 | */ | 49 | */ |
50 | void | 50 | void |
51 | GAS_plugin_done (void); | 51 | GAS_plugin_done(void); |
52 | 52 | ||
53 | 53 | ||
54 | /** | 54 | /** |
@@ -59,9 +59,9 @@ GAS_plugin_done (void); | |||
59 | * @param pref_rel the new relative preference value | 59 | * @param pref_rel the new relative preference value |
60 | */ | 60 | */ |
61 | void | 61 | void |
62 | GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | 62 | GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, |
63 | enum GNUNET_ATS_PreferenceKind kind, | 63 | enum GNUNET_ATS_PreferenceKind kind, |
64 | double pref_rel); | 64 | double pref_rel); |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
@@ -70,7 +70,7 @@ GAS_plugin_notify_preference_changed (const struct GNUNET_PeerIdentity *peer, | |||
70 | * @param address the peer | 70 | * @param address the peer |
71 | */ | 71 | */ |
72 | void | 72 | void |
73 | GAS_plugin_notify_property_changed (struct ATS_Address *address); | 73 | GAS_plugin_notify_property_changed(struct ATS_Address *address); |
74 | 74 | ||
75 | 75 | ||
76 | /** | 76 | /** |
@@ -81,7 +81,7 @@ GAS_plugin_notify_property_changed (struct ATS_Address *address); | |||
81 | * @param addr_net network scope the address is in | 81 | * @param addr_net network scope the address is in |
82 | */ | 82 | */ |
83 | void | 83 | void |
84 | GAS_plugin_new_address (struct ATS_Address *new_address); | 84 | GAS_plugin_new_address(struct ATS_Address *new_address); |
85 | 85 | ||
86 | 86 | ||
87 | /** | 87 | /** |
@@ -91,7 +91,7 @@ GAS_plugin_new_address (struct ATS_Address *new_address); | |||
91 | * @param address address that was deleted | 91 | * @param address address that was deleted |
92 | */ | 92 | */ |
93 | void | 93 | void |
94 | GAS_plugin_delete_address (struct ATS_Address *address); | 94 | GAS_plugin_delete_address(struct ATS_Address *address); |
95 | 95 | ||
96 | 96 | ||
97 | /** | 97 | /** |
@@ -105,11 +105,11 @@ GAS_plugin_delete_address (struct ATS_Address *address); | |||
105 | * @param score_abs degree of the appreciation | 105 | * @param score_abs degree of the appreciation |
106 | */ | 106 | */ |
107 | void | 107 | void |
108 | GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, | 108 | GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application, |
109 | const struct GNUNET_PeerIdentity *peer, | 109 | const struct GNUNET_PeerIdentity *peer, |
110 | const struct GNUNET_TIME_Relative scope, | 110 | const struct GNUNET_TIME_Relative scope, |
111 | enum GNUNET_ATS_PreferenceKind kind, | 111 | enum GNUNET_ATS_PreferenceKind kind, |
112 | float score_abs); | 112 | float score_abs); |
113 | 113 | ||
114 | 114 | ||
115 | /** | 115 | /** |
@@ -117,14 +117,14 @@ GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application, | |||
117 | * happening in bulk right now. | 117 | * happening in bulk right now. |
118 | */ | 118 | */ |
119 | void | 119 | void |
120 | GAS_plugin_solver_lock (void); | 120 | GAS_plugin_solver_lock(void); |
121 | 121 | ||
122 | 122 | ||
123 | /** | 123 | /** |
124 | * Resume instant solving, we are done with the bulk state updates. | 124 | * Resume instant solving, we are done with the bulk state updates. |
125 | */ | 125 | */ |
126 | void | 126 | void |
127 | GAS_plugin_solver_unlock (void); | 127 | GAS_plugin_solver_unlock(void); |
128 | 128 | ||
129 | 129 | ||
130 | /** | 130 | /** |
@@ -134,7 +134,7 @@ GAS_plugin_solver_unlock (void); | |||
134 | * @param pid identity of peer we now care about | 134 | * @param pid identity of peer we now care about |
135 | */ | 135 | */ |
136 | void | 136 | void |
137 | GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid); | 137 | GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid); |
138 | 138 | ||
139 | 139 | ||
140 | /** | 140 | /** |
@@ -144,7 +144,7 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid); | |||
144 | * @param pid identity of peer we care now less about | 144 | * @param pid identity of peer we care now less about |
145 | */ | 145 | */ |
146 | void | 146 | void |
147 | GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid); | 147 | GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid); |
148 | 148 | ||
149 | 149 | ||
150 | #endif | 150 | #endif |
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c index 26929ea7c..0a12faaae 100644 --- a/src/ats/gnunet-service-ats_preferences.c +++ b/src/ats/gnunet-service-ats_preferences.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats_preferences.c | 21 | * @file ats/gnunet-service-ats_preferences.c |
22 | * @brief manage preferences expressed by clients | 22 | * @brief manage preferences expressed by clients |
@@ -32,12 +32,12 @@ | |||
32 | #include "gnunet-service-ats_reservations.h" | 32 | #include "gnunet-service-ats_reservations.h" |
33 | #include "ats.h" | 33 | #include "ats.h" |
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-preferences",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-preferences", __VA_ARGS__) |
36 | 36 | ||
37 | /** | 37 | /** |
38 | * How frequently do we age preference values? | 38 | * How frequently do we age preference values? |
39 | */ | 39 | */ |
40 | #define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 40 | #define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * By which factor do we age preferences expressed during | 43 | * By which factor do we age preferences expressed during |
@@ -56,8 +56,7 @@ | |||
56 | /** | 56 | /** |
57 | * Relative preferences for a peer. | 57 | * Relative preferences for a peer. |
58 | */ | 58 | */ |
59 | struct PeerRelative | 59 | struct PeerRelative { |
60 | { | ||
61 | /** | 60 | /** |
62 | * Array of relative preference values, to be indexed by | 61 | * Array of relative preference values, to be indexed by |
63 | * an `enum GNUNET_ATS_PreferenceKind`. | 62 | * an `enum GNUNET_ATS_PreferenceKind`. |
@@ -83,8 +82,7 @@ static struct PeerRelative defvalues; | |||
83 | /** | 82 | /** |
84 | * Preference information per peer and client. | 83 | * Preference information per peer and client. |
85 | */ | 84 | */ |
86 | struct PreferencePeer | 85 | struct PreferencePeer { |
87 | { | ||
88 | /** | 86 | /** |
89 | * Next in DLL of preference entries for the same client. | 87 | * Next in DLL of preference entries for the same client. |
90 | */ | 88 | */ |
@@ -107,7 +105,6 @@ struct PreferencePeer | |||
107 | * client scored other peers. | 105 | * client scored other peers. |
108 | */ | 106 | */ |
109 | double f_rel[GNUNET_ATS_PREFERENCE_END]; | 107 | double f_rel[GNUNET_ATS_PREFERENCE_END]; |
110 | |||
111 | }; | 108 | }; |
112 | 109 | ||
113 | 110 | ||
@@ -116,9 +113,7 @@ struct PreferencePeer | |||
116 | * for peers. This is the information we keep track of for each | 113 | * for peers. This is the information we keep track of for each |
117 | * such client. | 114 | * such client. |
118 | */ | 115 | */ |
119 | struct PreferenceClient | 116 | struct PreferenceClient { |
120 | { | ||
121 | |||
122 | /** | 117 | /** |
123 | * Next in client list | 118 | * Next in client list |
124 | */ | 119 | */ |
@@ -145,7 +140,6 @@ struct PreferenceClient | |||
145 | * peers as expressed by this client. | 140 | * peers as expressed by this client. |
146 | */ | 141 | */ |
147 | double f_abs_sum[GNUNET_ATS_PREFERENCE_END]; | 142 | double f_abs_sum[GNUNET_ATS_PREFERENCE_END]; |
148 | |||
149 | }; | 143 | }; |
150 | 144 | ||
151 | 145 | ||
@@ -175,8 +169,7 @@ static struct GNUNET_SCHEDULER_Task *aging_task; | |||
175 | /** | 169 | /** |
176 | * Closure for #sum_relative_preferences(). | 170 | * Closure for #sum_relative_preferences(). |
177 | */ | 171 | */ |
178 | struct SumContext | 172 | struct SumContext { |
179 | { | ||
180 | /** | 173 | /** |
181 | * Where to accumulate the result. | 174 | * Where to accumulate the result. |
182 | */ | 175 | */ |
@@ -200,9 +193,9 @@ struct SumContext | |||
200 | * @return #GNUNET_OK | 193 | * @return #GNUNET_OK |
201 | */ | 194 | */ |
202 | static int | 195 | static int |
203 | sum_relative_preferences (void *cls, | 196 | sum_relative_preferences(void *cls, |
204 | const struct GNUNET_PeerIdentity *peer, | 197 | const struct GNUNET_PeerIdentity *peer, |
205 | void *value) | 198 | void *value) |
206 | { | 199 | { |
207 | struct SumContext *sum_ctx = cls; | 200 | struct SumContext *sum_ctx = cls; |
208 | struct PreferencePeer *p_cur = value; | 201 | struct PreferencePeer *p_cur = value; |
@@ -221,8 +214,8 @@ sum_relative_preferences (void *cls, | |||
221 | * @return the new relative preference | 214 | * @return the new relative preference |
222 | */ | 215 | */ |
223 | static void | 216 | static void |
224 | update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | 217 | update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id, |
225 | enum GNUNET_ATS_PreferenceKind kind) | 218 | enum GNUNET_ATS_PreferenceKind kind) |
226 | { | 219 | { |
227 | struct PreferenceClient *c_cur; | 220 | struct PreferenceClient *c_cur; |
228 | struct SumContext sum_ctx; | 221 | struct SumContext sum_ctx; |
@@ -231,25 +224,25 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | |||
231 | sum_ctx.f_rel_total = 0.0; | 224 | sum_ctx.f_rel_total = 0.0; |
232 | sum_ctx.kind = kind; | 225 | sum_ctx.kind = kind; |
233 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) | 226 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) |
234 | GNUNET_CONTAINER_multipeermap_get_multiple (c_cur->peer2pref, | 227 | GNUNET_CONTAINER_multipeermap_get_multiple(c_cur->peer2pref, |
235 | id, | 228 | id, |
236 | &sum_relative_preferences, | 229 | &sum_relative_preferences, |
237 | &sum_ctx); | 230 | &sum_ctx); |
238 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 231 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
239 | "Total relative preference for peer `%s' for `%s' is %.3f\n", | 232 | "Total relative preference for peer `%s' for `%s' is %.3f\n", |
240 | GNUNET_i2s (id), | 233 | GNUNET_i2s(id), |
241 | GNUNET_ATS_print_preference_type (kind), | 234 | GNUNET_ATS_print_preference_type(kind), |
242 | sum_ctx.f_rel_total); | 235 | sum_ctx.f_rel_total); |
243 | rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, | 236 | rp = GNUNET_CONTAINER_multipeermap_get(preference_peers, |
244 | id); | 237 | id); |
245 | GNUNET_assert (NULL != rp); | 238 | GNUNET_assert(NULL != rp); |
246 | if (rp->f_rel[kind] != sum_ctx.f_rel_total) | 239 | if (rp->f_rel[kind] != sum_ctx.f_rel_total) |
247 | { | 240 | { |
248 | rp->f_rel[kind] = sum_ctx.f_rel_total; | 241 | rp->f_rel[kind] = sum_ctx.f_rel_total; |
249 | GAS_plugin_notify_preference_changed (id, | 242 | GAS_plugin_notify_preference_changed(id, |
250 | kind, | 243 | kind, |
251 | rp->f_rel[kind]); | 244 | rp->f_rel[kind]); |
252 | } | 245 | } |
253 | } | 246 | } |
254 | 247 | ||
255 | 248 | ||
@@ -262,17 +255,17 @@ update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id, | |||
262 | * @return #GNUNET_OK to continue | 255 | * @return #GNUNET_OK to continue |
263 | */ | 256 | */ |
264 | static int | 257 | static int |
265 | free_peer (void *cls, | 258 | free_peer(void *cls, |
266 | const struct GNUNET_PeerIdentity *key, | 259 | const struct GNUNET_PeerIdentity *key, |
267 | void *value) | 260 | void *value) |
268 | { | 261 | { |
269 | struct PeerRelative *rp = value; | 262 | struct PeerRelative *rp = value; |
270 | 263 | ||
271 | GNUNET_assert (GNUNET_YES == | 264 | GNUNET_assert(GNUNET_YES == |
272 | GNUNET_CONTAINER_multipeermap_remove (preference_peers, | 265 | GNUNET_CONTAINER_multipeermap_remove(preference_peers, |
273 | key, | 266 | key, |
274 | value)); | 267 | value)); |
275 | GNUNET_free (rp); | 268 | GNUNET_free(rp); |
276 | return GNUNET_OK; | 269 | return GNUNET_OK; |
277 | } | 270 | } |
278 | 271 | ||
@@ -286,30 +279,30 @@ free_peer (void *cls, | |||
286 | * @return #GNUNET_OK (continue to iterate) | 279 | * @return #GNUNET_OK (continue to iterate) |
287 | */ | 280 | */ |
288 | static int | 281 | static int |
289 | free_preference (void *cls, | 282 | free_preference(void *cls, |
290 | const struct GNUNET_PeerIdentity *key, | 283 | const struct GNUNET_PeerIdentity *key, |
291 | void *value) | 284 | void *value) |
292 | { | 285 | { |
293 | struct PreferenceClient *pc = cls; | 286 | struct PreferenceClient *pc = cls; |
294 | struct PreferencePeer *p = value; | 287 | struct PreferencePeer *p = value; |
295 | struct PeerRelative *pr; | 288 | struct PeerRelative *pr; |
296 | 289 | ||
297 | GNUNET_assert (GNUNET_OK == | 290 | GNUNET_assert(GNUNET_OK == |
298 | GNUNET_CONTAINER_multipeermap_remove (pc->peer2pref, | 291 | GNUNET_CONTAINER_multipeermap_remove(pc->peer2pref, |
299 | key, | 292 | key, |
300 | p)); | 293 | p)); |
301 | GNUNET_free (p); | 294 | GNUNET_free(p); |
302 | pr = GNUNET_CONTAINER_multipeermap_get (preference_peers, | 295 | pr = GNUNET_CONTAINER_multipeermap_get(preference_peers, |
303 | key); | 296 | key); |
304 | GNUNET_assert (NULL != pr); | 297 | GNUNET_assert(NULL != pr); |
305 | GNUNET_assert (pr->num_clients > 0); | 298 | GNUNET_assert(pr->num_clients > 0); |
306 | pr->num_clients--; | 299 | pr->num_clients--; |
307 | if (0 == pr->num_clients) | 300 | if (0 == pr->num_clients) |
308 | { | 301 | { |
309 | free_peer (NULL, | 302 | free_peer(NULL, |
310 | key, | 303 | key, |
311 | pr); | 304 | pr); |
312 | } | 305 | } |
313 | return GNUNET_OK; | 306 | return GNUNET_OK; |
314 | } | 307 | } |
315 | 308 | ||
@@ -317,8 +310,7 @@ free_preference (void *cls, | |||
317 | /** | 310 | /** |
318 | * Closure for #age_values(). | 311 | * Closure for #age_values(). |
319 | */ | 312 | */ |
320 | struct AgeContext | 313 | struct AgeContext { |
321 | { | ||
322 | /** | 314 | /** |
323 | * Counter of values remaining to update, incremented for each value | 315 | * Counter of values remaining to update, incremented for each value |
324 | * changed (to a new non-zero value). | 316 | * changed (to a new non-zero value). |
@@ -329,7 +321,6 @@ struct AgeContext | |||
329 | * Client we are currently aging values for. | 321 | * Client we are currently aging values for. |
330 | */ | 322 | */ |
331 | struct PreferenceClient *cur_client; | 323 | struct PreferenceClient *cur_client; |
332 | |||
333 | }; | 324 | }; |
334 | 325 | ||
335 | 326 | ||
@@ -342,9 +333,9 @@ struct AgeContext | |||
342 | * @return #GNUNET_OK (continue to iterate) | 333 | * @return #GNUNET_OK (continue to iterate) |
343 | */ | 334 | */ |
344 | static int | 335 | static int |
345 | age_values (void *cls, | 336 | age_values(void *cls, |
346 | const struct GNUNET_PeerIdentity *peer, | 337 | const struct GNUNET_PeerIdentity *peer, |
347 | void *value) | 338 | void *value) |
348 | { | 339 | { |
349 | struct AgeContext *ac = cls; | 340 | struct AgeContext *ac = cls; |
350 | struct PreferencePeer *p = value; | 341 | struct PreferencePeer *p = value; |
@@ -353,32 +344,32 @@ age_values (void *cls, | |||
353 | 344 | ||
354 | dead = GNUNET_YES; | 345 | dead = GNUNET_YES; |
355 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) | 346 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
356 | { | ||
357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
358 | "Aging preference for peer `%s'\n", | ||
359 | GNUNET_i2s (peer)); | ||
360 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) | ||
361 | p->f_abs[i] *= PREF_AGING_FACTOR; | ||
362 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) | ||
363 | { | 347 | { |
364 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; | 348 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
365 | p->f_rel[i] = DEFAULT_REL_PREFERENCE; | 349 | "Aging preference for peer `%s'\n", |
366 | update_relative_values_for_peer (peer, | 350 | GNUNET_i2s(peer)); |
367 | i); | 351 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) |
352 | p->f_abs[i] *= PREF_AGING_FACTOR; | ||
353 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) | ||
354 | { | ||
355 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; | ||
356 | p->f_rel[i] = DEFAULT_REL_PREFERENCE; | ||
357 | update_relative_values_for_peer(peer, | ||
358 | i); | ||
359 | } | ||
360 | else | ||
361 | { | ||
362 | ac->values_to_update++; | ||
363 | dead = GNUNET_NO; | ||
364 | } | ||
368 | } | 365 | } |
369 | else | 366 | if (GNUNET_YES == dead) |
370 | { | 367 | { |
371 | ac->values_to_update++; | 368 | /* all preferences are zero, remove this entry */ |
372 | dead = GNUNET_NO; | 369 | free_preference(ac->cur_client, |
370 | peer, | ||
371 | p); | ||
373 | } | 372 | } |
374 | } | ||
375 | if (GNUNET_YES == dead) | ||
376 | { | ||
377 | /* all preferences are zero, remove this entry */ | ||
378 | free_preference (ac->cur_client, | ||
379 | peer, | ||
380 | p); | ||
381 | } | ||
382 | return GNUNET_OK; | 373 | return GNUNET_OK; |
383 | } | 374 | } |
384 | 375 | ||
@@ -389,41 +380,40 @@ age_values (void *cls, | |||
389 | * @param cls unused | 380 | * @param cls unused |
390 | */ | 381 | */ |
391 | static void | 382 | static void |
392 | preference_aging (void *cls) | 383 | preference_aging(void *cls) |
393 | { | 384 | { |
394 | struct AgeContext ac; | 385 | struct AgeContext ac; |
395 | 386 | ||
396 | aging_task = NULL; | 387 | aging_task = NULL; |
397 | GAS_plugin_solver_lock (); | 388 | GAS_plugin_solver_lock(); |
398 | ac.values_to_update = 0; | 389 | ac.values_to_update = 0; |
399 | for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client = ac.cur_client->next) | 390 | for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client = ac.cur_client->next) |
400 | GNUNET_CONTAINER_multipeermap_iterate (ac.cur_client->peer2pref, | 391 | GNUNET_CONTAINER_multipeermap_iterate(ac.cur_client->peer2pref, |
401 | &age_values, | 392 | &age_values, |
402 | &ac); | 393 | &ac); |
403 | GAS_plugin_solver_unlock (); | 394 | GAS_plugin_solver_unlock(); |
404 | if (ac.values_to_update > 0) | 395 | if (ac.values_to_update > 0) |
405 | { | 396 | { |
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 397 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
407 | "Rescheduling aging task due to %u elements remaining to age\n", | 398 | "Rescheduling aging task due to %u elements remaining to age\n", |
408 | ac.values_to_update); | 399 | ac.values_to_update); |
409 | if (NULL == aging_task) | 400 | if (NULL == aging_task) |
410 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 401 | aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL, |
411 | &preference_aging, | 402 | &preference_aging, |
412 | NULL); | 403 | NULL); |
413 | } | 404 | } |
414 | else | 405 | else |
415 | { | 406 | { |
416 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 407 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
417 | "No values to age left, not rescheduling aging task\n"); | 408 | "No values to age left, not rescheduling aging task\n"); |
418 | } | 409 | } |
419 | } | 410 | } |
420 | 411 | ||
421 | 412 | ||
422 | /** | 413 | /** |
423 | * Closure for #update_rel_sum() and #update_abs_sum(). | 414 | * Closure for #update_rel_sum() and #update_abs_sum(). |
424 | */ | 415 | */ |
425 | struct UpdateContext | 416 | struct UpdateContext { |
426 | { | ||
427 | /** | 417 | /** |
428 | * Preference client with the sum of all absolute scores. | 418 | * Preference client with the sum of all absolute scores. |
429 | */ | 419 | */ |
@@ -433,7 +423,6 @@ struct UpdateContext | |||
433 | * Which kind are we updating? | 423 | * Which kind are we updating? |
434 | */ | 424 | */ |
435 | enum GNUNET_ATS_PreferenceKind kind; | 425 | enum GNUNET_ATS_PreferenceKind kind; |
436 | |||
437 | }; | 426 | }; |
438 | 427 | ||
439 | 428 | ||
@@ -447,9 +436,9 @@ struct UpdateContext | |||
447 | * @return #GNUNET_OK (continue to iterate) | 436 | * @return #GNUNET_OK (continue to iterate) |
448 | */ | 437 | */ |
449 | static int | 438 | static int |
450 | update_abs_sum (void *cls, | 439 | update_abs_sum(void *cls, |
451 | const struct GNUNET_PeerIdentity *peer, | 440 | const struct GNUNET_PeerIdentity *peer, |
452 | void *value) | 441 | void *value) |
453 | { | 442 | { |
454 | struct UpdateContext *uc = cls; | 443 | struct UpdateContext *uc = cls; |
455 | struct PreferencePeer *p_cur = value; | 444 | struct PreferencePeer *p_cur = value; |
@@ -469,19 +458,19 @@ update_abs_sum (void *cls, | |||
469 | * @return #GNUNET_OK (continue to iterate) | 458 | * @return #GNUNET_OK (continue to iterate) |
470 | */ | 459 | */ |
471 | static int | 460 | static int |
472 | update_rel_sum (void *cls, | 461 | update_rel_sum(void *cls, |
473 | const struct GNUNET_PeerIdentity *peer, | 462 | const struct GNUNET_PeerIdentity *peer, |
474 | void *value) | 463 | void *value) |
475 | { | 464 | { |
476 | struct UpdateContext *uc = cls; | 465 | struct UpdateContext *uc = cls; |
477 | struct PreferencePeer *p_cur = value; | 466 | struct PreferencePeer *p_cur = value; |
478 | 467 | ||
479 | p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind]; | 468 | p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind]; |
480 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 469 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
481 | "Client has relative preference for %s for peer `%s' of %.3f\n", | 470 | "Client has relative preference for %s for peer `%s' of %.3f\n", |
482 | GNUNET_ATS_print_preference_type (uc->kind), | 471 | GNUNET_ATS_print_preference_type(uc->kind), |
483 | GNUNET_i2s (peer), | 472 | GNUNET_i2s(peer), |
484 | p_cur->f_rel[uc->kind]); | 473 | p_cur->f_rel[uc->kind]); |
485 | return GNUNET_OK; | 474 | return GNUNET_OK; |
486 | } | 475 | } |
487 | 476 | ||
@@ -494,8 +483,8 @@ update_rel_sum (void *cls, | |||
494 | * @return the result | 483 | * @return the result |
495 | */ | 484 | */ |
496 | static void | 485 | static void |
497 | recalculate_relative_preferences (struct PreferenceClient *c, | 486 | recalculate_relative_preferences(struct PreferenceClient *c, |
498 | enum GNUNET_ATS_PreferenceKind kind) | 487 | enum GNUNET_ATS_PreferenceKind kind) |
499 | { | 488 | { |
500 | struct UpdateContext uc; | 489 | struct UpdateContext uc; |
501 | 490 | ||
@@ -505,18 +494,18 @@ recalculate_relative_preferences (struct PreferenceClient *c, | |||
505 | c->f_abs_sum[kind] = 0.0; | 494 | c->f_abs_sum[kind] = 0.0; |
506 | 495 | ||
507 | /* For all peers: calculate sum of absolute preferences */ | 496 | /* For all peers: calculate sum of absolute preferences */ |
508 | GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref, | 497 | GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref, |
509 | &update_abs_sum, | 498 | &update_abs_sum, |
510 | &uc); | 499 | &uc); |
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 500 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
512 | "Client has sum of total preferences for %s of %.3f\n", | 501 | "Client has sum of total preferences for %s of %.3f\n", |
513 | GNUNET_ATS_print_preference_type (kind), | 502 | GNUNET_ATS_print_preference_type(kind), |
514 | c->f_abs_sum[kind]); | 503 | c->f_abs_sum[kind]); |
515 | 504 | ||
516 | /* For all peers: calculate relative preference */ | 505 | /* For all peers: calculate relative preference */ |
517 | GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref, | 506 | GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref, |
518 | &update_rel_sum, | 507 | &update_rel_sum, |
519 | &uc); | 508 | &uc); |
520 | } | 509 | } |
521 | 510 | ||
522 | 511 | ||
@@ -531,14 +520,14 @@ recalculate_relative_preferences (struct PreferenceClient *c, | |||
531 | * @param value a `struct PeerRelative`, unused | 520 | * @param value a `struct PeerRelative`, unused |
532 | */ | 521 | */ |
533 | static int | 522 | static int |
534 | update_iterator (void *cls, | 523 | update_iterator(void *cls, |
535 | const struct GNUNET_PeerIdentity *key, | 524 | const struct GNUNET_PeerIdentity *key, |
536 | void *value) | 525 | void *value) |
537 | { | 526 | { |
538 | enum GNUNET_ATS_PreferenceKind *kind = cls; | 527 | enum GNUNET_ATS_PreferenceKind *kind = cls; |
539 | 528 | ||
540 | update_relative_values_for_peer (key, | 529 | update_relative_values_for_peer(key, |
541 | *kind); | 530 | *kind); |
542 | return GNUNET_OK; | 531 | return GNUNET_OK; |
543 | } | 532 | } |
544 | 533 | ||
@@ -553,10 +542,10 @@ update_iterator (void *cls, | |||
553 | * @param score_abs the normalized score | 542 | * @param score_abs the normalized score |
554 | */ | 543 | */ |
555 | static void | 544 | static void |
556 | update_preference (struct GNUNET_SERVICE_Client *client, | 545 | update_preference(struct GNUNET_SERVICE_Client *client, |
557 | const struct GNUNET_PeerIdentity *peer, | 546 | const struct GNUNET_PeerIdentity *peer, |
558 | enum GNUNET_ATS_PreferenceKind kind, | 547 | enum GNUNET_ATS_PreferenceKind kind, |
559 | float score_abs) | 548 | float score_abs) |
560 | { | 549 | { |
561 | struct PreferenceClient *c_cur; | 550 | struct PreferenceClient *c_cur; |
562 | struct PreferencePeer *p_cur; | 551 | struct PreferencePeer *p_cur; |
@@ -564,15 +553,15 @@ update_preference (struct GNUNET_SERVICE_Client *client, | |||
564 | unsigned int i; | 553 | unsigned int i; |
565 | 554 | ||
566 | if (kind >= GNUNET_ATS_PREFERENCE_END) | 555 | if (kind >= GNUNET_ATS_PREFERENCE_END) |
567 | { | 556 | { |
568 | GNUNET_break(0); | 557 | GNUNET_break(0); |
569 | return; | 558 | return; |
570 | } | 559 | } |
571 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 560 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
572 | "Client changes preference for peer `%s' for `%s' to %.2f\n", | 561 | "Client changes preference for peer `%s' for `%s' to %.2f\n", |
573 | GNUNET_i2s (peer), | 562 | GNUNET_i2s(peer), |
574 | GNUNET_ATS_print_preference_type (kind), | 563 | GNUNET_ATS_print_preference_type(kind), |
575 | score_abs); | 564 | score_abs); |
576 | 565 | ||
577 | /* Find preference client */ | 566 | /* Find preference client */ |
578 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) | 567 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) |
@@ -580,66 +569,66 @@ update_preference (struct GNUNET_SERVICE_Client *client, | |||
580 | break; | 569 | break; |
581 | /* Not found: create new preference client */ | 570 | /* Not found: create new preference client */ |
582 | if (NULL == c_cur) | 571 | if (NULL == c_cur) |
583 | { | 572 | { |
584 | c_cur = GNUNET_new (struct PreferenceClient); | 573 | c_cur = GNUNET_new(struct PreferenceClient); |
585 | c_cur->client = client; | 574 | c_cur->client = client; |
586 | c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create (16, | 575 | c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create(16, |
587 | GNUNET_NO); | 576 | GNUNET_NO); |
588 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) | 577 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
589 | c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; | 578 | c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; |
590 | GNUNET_CONTAINER_DLL_insert (pc_head, | 579 | GNUNET_CONTAINER_DLL_insert(pc_head, |
591 | pc_tail, | 580 | pc_tail, |
592 | c_cur); | 581 | c_cur); |
593 | } | 582 | } |
594 | 583 | ||
595 | /* check global peer entry exists */ | 584 | /* check global peer entry exists */ |
596 | if (NULL == | 585 | if (NULL == |
597 | (r_cur = GNUNET_CONTAINER_multipeermap_get (preference_peers, | 586 | (r_cur = GNUNET_CONTAINER_multipeermap_get(preference_peers, |
598 | peer))) | 587 | peer))) |
599 | { | 588 | { |
600 | /* Create struct for peer */ | 589 | /* Create struct for peer */ |
601 | r_cur = GNUNET_new (struct PeerRelative); | 590 | r_cur = GNUNET_new(struct PeerRelative); |
602 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) | 591 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
603 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 592 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
604 | GNUNET_assert (GNUNET_OK == | 593 | GNUNET_assert(GNUNET_OK == |
605 | GNUNET_CONTAINER_multipeermap_put (preference_peers, | 594 | GNUNET_CONTAINER_multipeermap_put(preference_peers, |
606 | peer, | 595 | peer, |
607 | r_cur, | 596 | r_cur, |
608 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 597 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
609 | } | 598 | } |
610 | 599 | ||
611 | /* Find entry for peer */ | 600 | /* Find entry for peer */ |
612 | p_cur = GNUNET_CONTAINER_multipeermap_get (c_cur->peer2pref, | 601 | p_cur = GNUNET_CONTAINER_multipeermap_get(c_cur->peer2pref, |
613 | peer); | 602 | peer); |
614 | if (NULL == p_cur) | 603 | if (NULL == p_cur) |
615 | { | ||
616 | /* Not found: create new peer entry */ | ||
617 | p_cur = GNUNET_new (struct PreferencePeer); | ||
618 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) | ||
619 | { | 604 | { |
620 | /* Default value per peer absolute preference for a preference*/ | 605 | /* Not found: create new peer entry */ |
621 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; | 606 | p_cur = GNUNET_new(struct PreferencePeer); |
622 | /* Default value per peer relative preference for a quality */ | 607 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
623 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 608 | { |
624 | } | 609 | /* Default value per peer absolute preference for a preference*/ |
625 | GNUNET_assert (GNUNET_YES == | 610 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; |
626 | GNUNET_CONTAINER_multipeermap_put (c_cur->peer2pref, | 611 | /* Default value per peer relative preference for a quality */ |
612 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | ||
613 | } | ||
614 | GNUNET_assert(GNUNET_YES == | ||
615 | GNUNET_CONTAINER_multipeermap_put(c_cur->peer2pref, | ||
627 | peer, | 616 | peer, |
628 | p_cur, | 617 | p_cur, |
629 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 618 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
630 | r_cur->num_clients++; | 619 | r_cur->num_clients++; |
631 | } | 620 | } |
632 | 621 | ||
633 | p_cur->f_abs[kind] += score_abs; | 622 | p_cur->f_abs[kind] += score_abs; |
634 | recalculate_relative_preferences (c_cur, kind); | 623 | recalculate_relative_preferences(c_cur, kind); |
635 | GNUNET_CONTAINER_multipeermap_iterate (preference_peers, | 624 | GNUNET_CONTAINER_multipeermap_iterate(preference_peers, |
636 | &update_iterator, | 625 | &update_iterator, |
637 | &kind); | 626 | &kind); |
638 | 627 | ||
639 | if (NULL == aging_task) | 628 | if (NULL == aging_task) |
640 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 629 | aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL, |
641 | &preference_aging, | 630 | &preference_aging, |
642 | NULL); | 631 | NULL); |
643 | } | 632 | } |
644 | 633 | ||
645 | 634 | ||
@@ -650,28 +639,28 @@ update_preference (struct GNUNET_SERVICE_Client *client, | |||
650 | * @param msg the request message | 639 | * @param msg the request message |
651 | */ | 640 | */ |
652 | void | 641 | void |
653 | GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, | 642 | GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client, |
654 | const struct ChangePreferenceMessage *msg) | 643 | const struct ChangePreferenceMessage *msg) |
655 | { | 644 | { |
656 | const struct PreferenceInformation *pi; | 645 | const struct PreferenceInformation *pi; |
657 | uint32_t nump; | 646 | uint32_t nump; |
658 | 647 | ||
659 | nump = ntohl (msg->num_preferences); | 648 | nump = ntohl(msg->num_preferences); |
660 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 649 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
661 | "Received PREFERENCE_CHANGE message for peer `%s'\n", | 650 | "Received PREFERENCE_CHANGE message for peer `%s'\n", |
662 | GNUNET_i2s (&msg->peer)); | 651 | GNUNET_i2s(&msg->peer)); |
663 | GNUNET_STATISTICS_update (GSA_stats, | 652 | GNUNET_STATISTICS_update(GSA_stats, |
664 | "# preference change requests processed", | 653 | "# preference change requests processed", |
665 | 1, | 654 | 1, |
666 | GNUNET_NO); | 655 | GNUNET_NO); |
667 | pi = (const struct PreferenceInformation *) &msg[1]; | 656 | pi = (const struct PreferenceInformation *)&msg[1]; |
668 | GAS_plugin_solver_lock (); | 657 | GAS_plugin_solver_lock(); |
669 | for (uint32_t i = 0; i < nump; i++) | 658 | for (uint32_t i = 0; i < nump; i++) |
670 | update_preference (client, | 659 | update_preference(client, |
671 | &msg->peer, | 660 | &msg->peer, |
672 | (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), | 661 | (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind), |
673 | pi[i].preference_value); | 662 | pi[i].preference_value); |
674 | GAS_plugin_solver_unlock (); | 663 | GAS_plugin_solver_unlock(); |
675 | } | 664 | } |
676 | 665 | ||
677 | 666 | ||
@@ -679,12 +668,12 @@ GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, | |||
679 | * Initialize preferences subsystem. | 668 | * Initialize preferences subsystem. |
680 | */ | 669 | */ |
681 | void | 670 | void |
682 | GAS_preference_init () | 671 | GAS_preference_init() |
683 | { | 672 | { |
684 | unsigned int i; | 673 | unsigned int i; |
685 | 674 | ||
686 | preference_peers = GNUNET_CONTAINER_multipeermap_create (16, | 675 | preference_peers = GNUNET_CONTAINER_multipeermap_create(16, |
687 | GNUNET_NO); | 676 | GNUNET_NO); |
688 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) | 677 | for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) |
689 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 678 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
690 | } | 679 | } |
@@ -694,34 +683,33 @@ GAS_preference_init () | |||
694 | * Shutdown preferences subsystem. | 683 | * Shutdown preferences subsystem. |
695 | */ | 684 | */ |
696 | void | 685 | void |
697 | GAS_preference_done () | 686 | GAS_preference_done() |
698 | { | 687 | { |
699 | struct PreferenceClient *pc; | 688 | struct PreferenceClient *pc; |
700 | struct PreferenceClient *next_pc; | 689 | struct PreferenceClient *next_pc; |
701 | 690 | ||
702 | if (NULL != aging_task) | 691 | if (NULL != aging_task) |
703 | { | 692 | { |
704 | GNUNET_SCHEDULER_cancel (aging_task); | 693 | GNUNET_SCHEDULER_cancel(aging_task); |
705 | aging_task = NULL; | 694 | aging_task = NULL; |
706 | } | 695 | } |
707 | next_pc = pc_head; | 696 | next_pc = pc_head; |
708 | while (NULL != (pc = next_pc)) | 697 | while (NULL != (pc = next_pc)) |
709 | { | 698 | { |
710 | next_pc = pc->next; | 699 | next_pc = pc->next; |
711 | GNUNET_CONTAINER_DLL_remove (pc_head, | 700 | GNUNET_CONTAINER_DLL_remove(pc_head, |
712 | pc_tail, | 701 | pc_tail, |
713 | pc); | 702 | pc); |
714 | GNUNET_CONTAINER_multipeermap_iterate (pc->peer2pref, | 703 | GNUNET_CONTAINER_multipeermap_iterate(pc->peer2pref, |
715 | &free_preference, | 704 | &free_preference, |
716 | pc); | 705 | pc); |
717 | GNUNET_CONTAINER_multipeermap_destroy (pc->peer2pref); | 706 | GNUNET_CONTAINER_multipeermap_destroy(pc->peer2pref); |
718 | GNUNET_free (pc); | 707 | GNUNET_free(pc); |
719 | } | 708 | } |
720 | GNUNET_CONTAINER_multipeermap_iterate (preference_peers, | 709 | GNUNET_CONTAINER_multipeermap_iterate(preference_peers, |
721 | &free_peer, | 710 | &free_peer, |
722 | NULL); | 711 | NULL); |
723 | GNUNET_CONTAINER_multipeermap_destroy (preference_peers); | 712 | GNUNET_CONTAINER_multipeermap_destroy(preference_peers); |
724 | |||
725 | } | 713 | } |
726 | 714 | ||
727 | 715 | ||
@@ -735,17 +723,17 @@ GAS_preference_done () | |||
735 | * default preferences if peer does not exist | 723 | * default preferences if peer does not exist |
736 | */ | 724 | */ |
737 | const double * | 725 | const double * |
738 | GAS_preference_get_by_peer (void *cls, | 726 | GAS_preference_get_by_peer(void *cls, |
739 | const struct GNUNET_PeerIdentity *id) | 727 | const struct GNUNET_PeerIdentity *id) |
740 | { | 728 | { |
741 | struct PeerRelative *rp; | 729 | struct PeerRelative *rp; |
742 | 730 | ||
743 | if (NULL == | 731 | if (NULL == |
744 | (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, | 732 | (rp = GNUNET_CONTAINER_multipeermap_get(preference_peers, |
745 | id))) | 733 | id))) |
746 | { | 734 | { |
747 | return defvalues.f_rel; | 735 | return defvalues.f_rel; |
748 | } | 736 | } |
749 | return rp->f_rel; | 737 | return rp->f_rel; |
750 | } | 738 | } |
751 | 739 | ||
@@ -756,7 +744,7 @@ GAS_preference_get_by_peer (void *cls, | |||
756 | * @param client the client | 744 | * @param client the client |
757 | */ | 745 | */ |
758 | void | 746 | void |
759 | GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client) | 747 | GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client) |
760 | { | 748 | { |
761 | struct PreferenceClient *c_cur; | 749 | struct PreferenceClient *c_cur; |
762 | 750 | ||
@@ -765,14 +753,14 @@ GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client) | |||
765 | break; | 753 | break; |
766 | if (NULL == c_cur) | 754 | if (NULL == c_cur) |
767 | return; | 755 | return; |
768 | GNUNET_CONTAINER_DLL_remove (pc_head, | 756 | GNUNET_CONTAINER_DLL_remove(pc_head, |
769 | pc_tail, | 757 | pc_tail, |
770 | c_cur); | 758 | c_cur); |
771 | GNUNET_CONTAINER_multipeermap_iterate (c_cur->peer2pref, | 759 | GNUNET_CONTAINER_multipeermap_iterate(c_cur->peer2pref, |
772 | &free_preference, | 760 | &free_preference, |
773 | c_cur); | 761 | c_cur); |
774 | GNUNET_CONTAINER_multipeermap_destroy (c_cur->peer2pref); | 762 | GNUNET_CONTAINER_multipeermap_destroy(c_cur->peer2pref); |
775 | GNUNET_free (c_cur); | 763 | GNUNET_free(c_cur); |
776 | } | 764 | } |
777 | 765 | ||
778 | 766 | ||
diff --git a/src/ats/gnunet-service-ats_preferences.h b/src/ats/gnunet-service-ats_preferences.h index e0c7aa2e3..48aa33ea6 100644 --- a/src/ats/gnunet-service-ats_preferences.h +++ b/src/ats/gnunet-service-ats_preferences.h | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -50,22 +50,22 @@ | |||
50 | * @param msg the request message | 50 | * @param msg the request message |
51 | */ | 51 | */ |
52 | void | 52 | void |
53 | GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client, | 53 | GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client, |
54 | const struct ChangePreferenceMessage *msg); | 54 | const struct ChangePreferenceMessage *msg); |
55 | 55 | ||
56 | 56 | ||
57 | /** | 57 | /** |
58 | * Initialize preferences subsystem. | 58 | * Initialize preferences subsystem. |
59 | */ | 59 | */ |
60 | void | 60 | void |
61 | GAS_preference_init (void); | 61 | GAS_preference_init(void); |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Shutdown preferences subsystem. | 65 | * Shutdown preferences subsystem. |
66 | */ | 66 | */ |
67 | void | 67 | void |
68 | GAS_preference_done (void); | 68 | GAS_preference_done(void); |
69 | 69 | ||
70 | 70 | ||
71 | /** | 71 | /** |
@@ -77,8 +77,8 @@ GAS_preference_done (void); | |||
77 | * with `enum GNUNET_ATS_PreferenceKind`, never NULL | 77 | * with `enum GNUNET_ATS_PreferenceKind`, never NULL |
78 | */ | 78 | */ |
79 | const double * | 79 | const double * |
80 | GAS_preference_get_by_peer (void *cls, | 80 | GAS_preference_get_by_peer(void *cls, |
81 | const struct GNUNET_PeerIdentity *id); | 81 | const struct GNUNET_PeerIdentity *id); |
82 | 82 | ||
83 | 83 | ||
84 | /** | 84 | /** |
@@ -87,7 +87,7 @@ GAS_preference_get_by_peer (void *cls, | |||
87 | * @param client the disconnecting client | 87 | * @param client the disconnecting client |
88 | */ | 88 | */ |
89 | void | 89 | void |
90 | GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client); | 90 | GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client); |
91 | 91 | ||
92 | 92 | ||
93 | #endif | 93 | #endif |
diff --git a/src/ats/gnunet-service-ats_reservations.c b/src/ats/gnunet-service-ats_reservations.c index 41de442c7..ec1f4b0d5 100644 --- a/src/ats/gnunet-service-ats_reservations.c +++ b/src/ats/gnunet-service-ats_reservations.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/gnunet-service-ats_reservations.c | 21 | * @file ats/gnunet-service-ats_reservations.c |
22 | * @brief ats service, inbound bandwidth reservation management | 22 | * @brief ats service, inbound bandwidth reservation management |
@@ -53,38 +53,38 @@ static struct GNUNET_CONTAINER_MultiPeerMap *trackers; | |||
53 | * until the reservation might succeed | 53 | * until the reservation might succeed |
54 | */ | 54 | */ |
55 | static struct GNUNET_TIME_Relative | 55 | static struct GNUNET_TIME_Relative |
56 | reservations_reserve (const struct GNUNET_PeerIdentity *peer, | 56 | reservations_reserve(const struct GNUNET_PeerIdentity *peer, |
57 | int32_t amount) | 57 | int32_t amount) |
58 | { | 58 | { |
59 | struct GNUNET_BANDWIDTH_Tracker *tracker; | 59 | struct GNUNET_BANDWIDTH_Tracker *tracker; |
60 | struct GNUNET_TIME_Relative ret; | 60 | struct GNUNET_TIME_Relative ret; |
61 | 61 | ||
62 | tracker = GNUNET_CONTAINER_multipeermap_get (trackers, | 62 | tracker = GNUNET_CONTAINER_multipeermap_get(trackers, |
63 | peer); | 63 | peer); |
64 | if (NULL == tracker) | 64 | if (NULL == tracker) |
65 | { | 65 | { |
66 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 66 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
67 | "Not connected, allowing reservation of %d bytes\n", | 67 | "Not connected, allowing reservation of %d bytes\n", |
68 | (int) amount); | 68 | (int)amount); |
69 | return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ | 69 | return GNUNET_TIME_UNIT_ZERO; /* not connected, satisfy now */ |
70 | } | 70 | } |
71 | if (amount >= 0) | 71 | if (amount >= 0) |
72 | { | ||
73 | ret = GNUNET_BANDWIDTH_tracker_get_delay (tracker, amount); | ||
74 | if (ret.rel_value_us > 0) | ||
75 | { | 72 | { |
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 73 | ret = GNUNET_BANDWIDTH_tracker_get_delay(tracker, amount); |
77 | "Delay to satisfy reservation for %d bytes is %s\n", | 74 | if (ret.rel_value_us > 0) |
78 | (int) amount, | 75 | { |
79 | GNUNET_STRINGS_relative_time_to_string (ret, | 76 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
80 | GNUNET_YES)); | 77 | "Delay to satisfy reservation for %d bytes is %s\n", |
81 | return ret; | 78 | (int)amount, |
79 | GNUNET_STRINGS_relative_time_to_string(ret, | ||
80 | GNUNET_YES)); | ||
81 | return ret; | ||
82 | } | ||
82 | } | 83 | } |
83 | } | 84 | (void)GNUNET_BANDWIDTH_tracker_consume(tracker, amount); |
84 | (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount); | 85 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 86 | "Reserved %d bytes\n", |
86 | "Reserved %d bytes\n", | 87 | (int)amount); |
87 | (int) amount); | ||
88 | return GNUNET_TIME_UNIT_ZERO; | 88 | return GNUNET_TIME_UNIT_ZERO; |
89 | } | 89 | } |
90 | 90 | ||
@@ -98,40 +98,40 @@ reservations_reserve (const struct GNUNET_PeerIdentity *peer, | |||
98 | * this peer (estimate) | 98 | * this peer (estimate) |
99 | */ | 99 | */ |
100 | void | 100 | void |
101 | GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | 101 | GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, |
102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
103 | { | 103 | { |
104 | struct GNUNET_BANDWIDTH_Tracker *tracker; | 104 | struct GNUNET_BANDWIDTH_Tracker *tracker; |
105 | 105 | ||
106 | tracker = GNUNET_CONTAINER_multipeermap_get (trackers, peer); | 106 | tracker = GNUNET_CONTAINER_multipeermap_get(trackers, peer); |
107 | if (0 == ntohl (bandwidth_in.value__)) | 107 | if (0 == ntohl(bandwidth_in.value__)) |
108 | { | 108 | { |
109 | if (NULL == tracker) | 109 | if (NULL == tracker) |
110 | return; | 110 | return; |
111 | GNUNET_assert (GNUNET_YES == | 111 | GNUNET_assert(GNUNET_YES == |
112 | GNUNET_CONTAINER_multipeermap_remove (trackers, | 112 | GNUNET_CONTAINER_multipeermap_remove(trackers, |
113 | peer, | 113 | peer, |
114 | tracker)); | 114 | tracker)); |
115 | GNUNET_free (tracker); | 115 | GNUNET_free(tracker); |
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | if (NULL == tracker) | 118 | if (NULL == tracker) |
119 | { | 119 | { |
120 | tracker = GNUNET_new (struct GNUNET_BANDWIDTH_Tracker); | 120 | tracker = GNUNET_new(struct GNUNET_BANDWIDTH_Tracker); |
121 | GNUNET_BANDWIDTH_tracker_init (tracker, | 121 | GNUNET_BANDWIDTH_tracker_init(tracker, |
122 | NULL, | 122 | NULL, |
123 | NULL, | 123 | NULL, |
124 | bandwidth_in, | 124 | bandwidth_in, |
125 | MAX_BANDWIDTH_CARRY_S); | 125 | MAX_BANDWIDTH_CARRY_S); |
126 | GNUNET_assert (GNUNET_OK == | 126 | GNUNET_assert(GNUNET_OK == |
127 | GNUNET_CONTAINER_multipeermap_put (trackers, | 127 | GNUNET_CONTAINER_multipeermap_put(trackers, |
128 | peer, | 128 | peer, |
129 | tracker, | 129 | tracker, |
130 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 130 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
131 | return; | 131 | return; |
132 | } | 132 | } |
133 | GNUNET_BANDWIDTH_tracker_update_quota (tracker, | 133 | GNUNET_BANDWIDTH_tracker_update_quota(tracker, |
134 | bandwidth_in); | 134 | bandwidth_in); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
@@ -142,31 +142,31 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
142 | * @param msg the request message | 142 | * @param msg the request message |
143 | */ | 143 | */ |
144 | void | 144 | void |
145 | GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | 145 | GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, |
146 | const struct ReservationRequestMessage *msg) | 146 | const struct ReservationRequestMessage *msg) |
147 | { | 147 | { |
148 | struct GNUNET_MQ_Envelope *env; | 148 | struct GNUNET_MQ_Envelope *env; |
149 | struct ReservationResultMessage *result; | 149 | struct ReservationResultMessage *result; |
150 | int32_t amount; | 150 | int32_t amount; |
151 | struct GNUNET_TIME_Relative res_delay; | 151 | struct GNUNET_TIME_Relative res_delay; |
152 | 152 | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 153 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
154 | "Received RESERVATION_REQUEST message\n"); | 154 | "Received RESERVATION_REQUEST message\n"); |
155 | amount = (int32_t) ntohl (msg->amount); | 155 | amount = (int32_t)ntohl(msg->amount); |
156 | res_delay = reservations_reserve (&msg->peer, amount); | 156 | res_delay = reservations_reserve(&msg->peer, amount); |
157 | if (res_delay.rel_value_us > 0) | 157 | if (res_delay.rel_value_us > 0) |
158 | amount = 0; | 158 | amount = 0; |
159 | env = GNUNET_MQ_msg (result, | 159 | env = GNUNET_MQ_msg(result, |
160 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); | 160 | GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT); |
161 | result->amount = htonl (amount); | 161 | result->amount = htonl(amount); |
162 | result->peer = msg->peer; | 162 | result->peer = msg->peer; |
163 | result->res_delay = GNUNET_TIME_relative_hton (res_delay); | 163 | result->res_delay = GNUNET_TIME_relative_hton(res_delay); |
164 | GNUNET_STATISTICS_update (GSA_stats, | 164 | GNUNET_STATISTICS_update(GSA_stats, |
165 | "# reservation requests processed", | 165 | "# reservation requests processed", |
166 | 1, | 166 | 1, |
167 | GNUNET_NO); | 167 | GNUNET_NO); |
168 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), | 168 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), |
169 | env); | 169 | env); |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
@@ -174,10 +174,10 @@ GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | |||
174 | * Initialize reservations subsystem. | 174 | * Initialize reservations subsystem. |
175 | */ | 175 | */ |
176 | void | 176 | void |
177 | GAS_reservations_init () | 177 | GAS_reservations_init() |
178 | { | 178 | { |
179 | trackers = GNUNET_CONTAINER_multipeermap_create (128, | 179 | trackers = GNUNET_CONTAINER_multipeermap_create(128, |
180 | GNUNET_NO); | 180 | GNUNET_NO); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
@@ -190,13 +190,13 @@ GAS_reservations_init () | |||
190 | * @return #GNUNET_OK (continue to iterate) | 190 | * @return #GNUNET_OK (continue to iterate) |
191 | */ | 191 | */ |
192 | static int | 192 | static int |
193 | free_tracker (void *cls, | 193 | free_tracker(void *cls, |
194 | const struct GNUNET_PeerIdentity *key, | 194 | const struct GNUNET_PeerIdentity *key, |
195 | void *value) | 195 | void *value) |
196 | { | 196 | { |
197 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; | 197 | struct GNUNET_BANDWIDTH_Tracker *tracker = value; |
198 | 198 | ||
199 | GNUNET_free (tracker); | 199 | GNUNET_free(tracker); |
200 | return GNUNET_OK; | 200 | return GNUNET_OK; |
201 | } | 201 | } |
202 | 202 | ||
@@ -205,12 +205,12 @@ free_tracker (void *cls, | |||
205 | * Shutdown reservations subsystem. | 205 | * Shutdown reservations subsystem. |
206 | */ | 206 | */ |
207 | void | 207 | void |
208 | GAS_reservations_done () | 208 | GAS_reservations_done() |
209 | { | 209 | { |
210 | GNUNET_CONTAINER_multipeermap_iterate (trackers, | 210 | GNUNET_CONTAINER_multipeermap_iterate(trackers, |
211 | &free_tracker, | 211 | &free_tracker, |
212 | NULL); | 212 | NULL); |
213 | GNUNET_CONTAINER_multipeermap_destroy (trackers); | 213 | GNUNET_CONTAINER_multipeermap_destroy(trackers); |
214 | } | 214 | } |
215 | 215 | ||
216 | /* end of gnunet-service-ats_reservations.c */ | 216 | /* end of gnunet-service-ats_reservations.c */ |
diff --git a/src/ats/gnunet-service-ats_reservations.h b/src/ats/gnunet-service-ats_reservations.h index 525236e8c..100cd9a90 100644 --- a/src/ats/gnunet-service-ats_reservations.h +++ b/src/ats/gnunet-service-ats_reservations.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_reservations.h | 22 | * @file ats/gnunet-service-ats_reservations.h |
@@ -39,9 +39,9 @@ | |||
39 | * this peer (estimate) | 39 | * this peer (estimate) |
40 | */ | 40 | */ |
41 | void | 41 | void |
42 | GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | 42 | GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, |
43 | struct GNUNET_BANDWIDTH_Value32NBO | 43 | struct GNUNET_BANDWIDTH_Value32NBO |
44 | bandwidth_in); | 44 | bandwidth_in); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -51,8 +51,8 @@ GAS_reservations_set_bandwidth (const struct GNUNET_PeerIdentity *peer, | |||
51 | * @param message the request message | 51 | * @param message the request message |
52 | */ | 52 | */ |
53 | void | 53 | void |
54 | GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | 54 | GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, |
55 | const struct ReservationRequestMessage *message); | 55 | const struct ReservationRequestMessage *message); |
56 | 56 | ||
57 | 57 | ||
58 | /** | 58 | /** |
@@ -61,13 +61,13 @@ GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client, | |||
61 | * @param server handle to our server | 61 | * @param server handle to our server |
62 | */ | 62 | */ |
63 | void | 63 | void |
64 | GAS_reservations_init (void); | 64 | GAS_reservations_init(void); |
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | * Shutdown reservations subsystem. | 68 | * Shutdown reservations subsystem. |
69 | */ | 69 | */ |
70 | void | 70 | void |
71 | GAS_reservations_done (void); | 71 | GAS_reservations_done(void); |
72 | 72 | ||
73 | #endif | 73 | #endif |
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c index 870912dc7..d50df9b2e 100644 --- a/src/ats/gnunet-service-ats_scheduling.c +++ b/src/ats/gnunet-service-ats_scheduling.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_scheduling.c | 22 | * @file ats/gnunet-service-ats_scheduling.c |
@@ -42,14 +42,14 @@ static struct GNUNET_SERVICE_Client *my_client; | |||
42 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 42 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
43 | */ | 43 | */ |
44 | int | 44 | int |
45 | GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client) | 45 | GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client) |
46 | { | 46 | { |
47 | if (NULL != my_client) | 47 | if (NULL != my_client) |
48 | { | 48 | { |
49 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 49 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
50 | "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); | 50 | "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); |
51 | return GNUNET_SYSERR; | 51 | return GNUNET_SYSERR; |
52 | } | 52 | } |
53 | my_client = client; | 53 | my_client = client; |
54 | return GNUNET_OK; | 54 | return GNUNET_OK; |
55 | } | 55 | } |
@@ -62,11 +62,11 @@ GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client) | |||
62 | * @param client handle of the (now dead) client | 62 | * @param client handle of the (now dead) client |
63 | */ | 63 | */ |
64 | void | 64 | void |
65 | GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client) | 65 | GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client) |
66 | { | 66 | { |
67 | if (my_client != client) | 67 | if (my_client != client) |
68 | return; | 68 | return; |
69 | GAS_addresses_destroy_all (); | 69 | GAS_addresses_destroy_all(); |
70 | my_client = NULL; | 70 | my_client = NULL; |
71 | } | 71 | } |
72 | 72 | ||
@@ -81,33 +81,33 @@ GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client) | |||
81 | * @param bandwidth_in assigned inbound bandwidth | 81 | * @param bandwidth_in assigned inbound bandwidth |
82 | */ | 82 | */ |
83 | void | 83 | void |
84 | GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, | 84 | GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, |
85 | uint32_t session_id, | 85 | uint32_t session_id, |
86 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 86 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
87 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 87 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
88 | { | 88 | { |
89 | struct GNUNET_MQ_Envelope *env; | 89 | struct GNUNET_MQ_Envelope *env; |
90 | struct AddressSuggestionMessage *msg; | 90 | struct AddressSuggestionMessage *msg; |
91 | 91 | ||
92 | if (NULL == my_client) | 92 | if (NULL == my_client) |
93 | return; | 93 | return; |
94 | GNUNET_STATISTICS_update (GSA_stats, | 94 | GNUNET_STATISTICS_update(GSA_stats, |
95 | "# address suggestions made", | 95 | "# address suggestions made", |
96 | 1, | 96 | 1, |
97 | GNUNET_NO); | 97 | GNUNET_NO); |
98 | env = GNUNET_MQ_msg (msg, | 98 | env = GNUNET_MQ_msg(msg, |
99 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | 99 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); |
100 | msg->peer = *peer; | 100 | msg->peer = *peer; |
101 | msg->session_id = htonl (session_id); | 101 | msg->session_id = htonl(session_id); |
102 | msg->bandwidth_out = bandwidth_out; | 102 | msg->bandwidth_out = bandwidth_out; |
103 | msg->bandwidth_in = bandwidth_in; | 103 | msg->bandwidth_in = bandwidth_in; |
104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 104 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
105 | "ATS sends quota for peer `%s': (in/out) %u/%u\n", | 105 | "ATS sends quota for peer `%s': (in/out) %u/%u\n", |
106 | GNUNET_i2s (peer), | 106 | GNUNET_i2s(peer), |
107 | (unsigned int) ntohl (bandwidth_in.value__), | 107 | (unsigned int)ntohl(bandwidth_in.value__), |
108 | (unsigned int) ntohl (bandwidth_out.value__)); | 108 | (unsigned int)ntohl(bandwidth_out.value__)); |
109 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client), | 109 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client), |
110 | env); | 110 | env); |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
@@ -117,7 +117,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
117 | * @param m the request message | 117 | * @param m the request message |
118 | */ | 118 | */ |
119 | void | 119 | void |
120 | GAS_handle_address_add (const struct AddressAddMessage *m) | 120 | GAS_handle_address_add(const struct AddressAddMessage *m) |
121 | { | 121 | { |
122 | const char *address; | 122 | const char *address; |
123 | const char *plugin_name; | 123 | const char *plugin_name; |
@@ -125,30 +125,30 @@ GAS_handle_address_add (const struct AddressAddMessage *m) | |||
125 | uint16_t plugin_name_length; | 125 | uint16_t plugin_name_length; |
126 | struct GNUNET_ATS_Properties prop; | 126 | struct GNUNET_ATS_Properties prop; |
127 | 127 | ||
128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 128 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
129 | "Received `%s' message\n", | 129 | "Received `%s' message\n", |
130 | "ADDRESS_ADD"); | 130 | "ADDRESS_ADD"); |
131 | address_length = ntohs (m->address_length); | 131 | address_length = ntohs(m->address_length); |
132 | plugin_name_length = ntohs (m->plugin_name_length); | 132 | plugin_name_length = ntohs(m->plugin_name_length); |
133 | address = (const char *) &m[1]; | 133 | address = (const char *)&m[1]; |
134 | if (plugin_name_length != 0) | 134 | if (plugin_name_length != 0) |
135 | plugin_name = &address[address_length]; | 135 | plugin_name = &address[address_length]; |
136 | else | 136 | else |
137 | plugin_name = ""; | 137 | plugin_name = ""; |
138 | GNUNET_STATISTICS_update (GSA_stats, | 138 | GNUNET_STATISTICS_update(GSA_stats, |
139 | "# addresses created", | 139 | "# addresses created", |
140 | 1, | 140 | 1, |
141 | GNUNET_NO); | 141 | GNUNET_NO); |
142 | GNUNET_ATS_properties_ntoh (&prop, | 142 | GNUNET_ATS_properties_ntoh(&prop, |
143 | &m->properties); | 143 | &m->properties); |
144 | GNUNET_break (GNUNET_NT_UNSPECIFIED != prop.scope); | 144 | GNUNET_break(GNUNET_NT_UNSPECIFIED != prop.scope); |
145 | GAS_addresses_add (&m->peer, | 145 | GAS_addresses_add(&m->peer, |
146 | plugin_name, | 146 | plugin_name, |
147 | address, | 147 | address, |
148 | address_length, | 148 | address_length, |
149 | ntohl (m->address_local_info), | 149 | ntohl(m->address_local_info), |
150 | ntohl (m->session_id), | 150 | ntohl(m->session_id), |
151 | &prop); | 151 | &prop); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
@@ -158,19 +158,19 @@ GAS_handle_address_add (const struct AddressAddMessage *m) | |||
158 | * @param m the request message | 158 | * @param m the request message |
159 | */ | 159 | */ |
160 | void | 160 | void |
161 | GAS_handle_address_update (const struct AddressUpdateMessage *m) | 161 | GAS_handle_address_update(const struct AddressUpdateMessage *m) |
162 | { | 162 | { |
163 | struct GNUNET_ATS_Properties prop; | 163 | struct GNUNET_ATS_Properties prop; |
164 | 164 | ||
165 | GNUNET_STATISTICS_update (GSA_stats, | 165 | GNUNET_STATISTICS_update(GSA_stats, |
166 | "# address updates received", | 166 | "# address updates received", |
167 | 1, | 167 | 1, |
168 | GNUNET_NO); | 168 | GNUNET_NO); |
169 | GNUNET_ATS_properties_ntoh (&prop, | 169 | GNUNET_ATS_properties_ntoh(&prop, |
170 | &m->properties); | 170 | &m->properties); |
171 | GAS_addresses_update (&m->peer, | 171 | GAS_addresses_update(&m->peer, |
172 | ntohl (m->session_id), | 172 | ntohl(m->session_id), |
173 | &prop); | 173 | &prop); |
174 | } | 174 | } |
175 | 175 | ||
176 | 176 | ||
@@ -180,26 +180,26 @@ GAS_handle_address_update (const struct AddressUpdateMessage *m) | |||
180 | * @param m the request message | 180 | * @param m the request message |
181 | */ | 181 | */ |
182 | void | 182 | void |
183 | GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m) | 183 | GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m) |
184 | { | 184 | { |
185 | struct GNUNET_MQ_Envelope *env; | 185 | struct GNUNET_MQ_Envelope *env; |
186 | struct GNUNET_ATS_SessionReleaseMessage *srm; | 186 | struct GNUNET_ATS_SessionReleaseMessage *srm; |
187 | 187 | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 188 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
189 | "Received `%s' message\n", | 189 | "Received `%s' message\n", |
190 | "ADDRESS_DESTROYED"); | 190 | "ADDRESS_DESTROYED"); |
191 | GNUNET_STATISTICS_update (GSA_stats, | 191 | GNUNET_STATISTICS_update(GSA_stats, |
192 | "# addresses destroyed", | 192 | "# addresses destroyed", |
193 | 1, | 193 | 1, |
194 | GNUNET_NO); | 194 | GNUNET_NO); |
195 | GAS_addresses_destroy (&m->peer, | 195 | GAS_addresses_destroy(&m->peer, |
196 | ntohl (m->session_id)); | 196 | ntohl(m->session_id)); |
197 | env = GNUNET_MQ_msg (srm, | 197 | env = GNUNET_MQ_msg(srm, |
198 | GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); | 198 | GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); |
199 | srm->session_id = m->session_id; | 199 | srm->session_id = m->session_id; |
200 | srm->peer = m->peer; | 200 | srm->peer = m->peer; |
201 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client), | 201 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client), |
202 | env); | 202 | env); |
203 | } | 203 | } |
204 | 204 | ||
205 | 205 | ||
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h index 30cceb97b..b2575ca60 100644 --- a/src/ats/gnunet-service-ats_scheduling.h +++ b/src/ats/gnunet-service-ats_scheduling.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/gnunet-service-ats_scheduling.h | 22 | * @file ats/gnunet-service-ats_scheduling.h |
@@ -37,7 +37,7 @@ | |||
37 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 37 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
38 | */ | 38 | */ |
39 | int | 39 | int |
40 | GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client); | 40 | GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client); |
41 | 41 | ||
42 | 42 | ||
43 | /** | 43 | /** |
@@ -47,7 +47,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client); | |||
47 | * @param client handle of the (now dead) client | 47 | * @param client handle of the (now dead) client |
48 | */ | 48 | */ |
49 | void | 49 | void |
50 | GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client); | 50 | GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client); |
51 | 51 | ||
52 | 52 | ||
53 | /** | 53 | /** |
@@ -60,10 +60,10 @@ GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client); | |||
60 | * @param bandwidth_in assigned inbound bandwidth | 60 | * @param bandwidth_in assigned inbound bandwidth |
61 | */ | 61 | */ |
62 | void | 62 | void |
63 | GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, | 63 | GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, |
64 | uint32_t session_id, | 64 | uint32_t session_id, |
65 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 65 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
66 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); | 66 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); |
67 | 67 | ||
68 | 68 | ||
69 | /** | 69 | /** |
@@ -73,7 +73,7 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe | |||
73 | * @param m the request message | 73 | * @param m the request message |
74 | */ | 74 | */ |
75 | void | 75 | void |
76 | GAS_handle_address_add (const struct AddressAddMessage *m); | 76 | GAS_handle_address_add(const struct AddressAddMessage *m); |
77 | 77 | ||
78 | 78 | ||
79 | /** | 79 | /** |
@@ -82,7 +82,7 @@ GAS_handle_address_add (const struct AddressAddMessage *m); | |||
82 | * @param m the request message | 82 | * @param m the request message |
83 | */ | 83 | */ |
84 | void | 84 | void |
85 | GAS_handle_address_update (const struct AddressUpdateMessage *m); | 85 | GAS_handle_address_update(const struct AddressUpdateMessage *m); |
86 | 86 | ||
87 | 87 | ||
88 | /** | 88 | /** |
@@ -91,7 +91,7 @@ GAS_handle_address_update (const struct AddressUpdateMessage *m); | |||
91 | * @param m the request message | 91 | * @param m the request message |
92 | */ | 92 | */ |
93 | void | 93 | void |
94 | GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m); | 94 | GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m); |
95 | 95 | ||
96 | 96 | ||
97 | #endif | 97 | #endif |
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c index 33180a953..6a4eadad7 100644 --- a/src/ats/perf_ats_solver.c +++ b/src/ats/perf_ats_solver.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2010,2011 GNUnet e.V. | 3 | Copyright (C) 2010,2011 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -49,8 +49,7 @@ struct GNUNET_STATISTICS_Handle *GSA_stats; | |||
49 | /** | 49 | /** |
50 | * Handle for ATS address component | 50 | * Handle for ATS address component |
51 | */ | 51 | */ |
52 | struct PerfHandle | 52 | struct PerfHandle { |
53 | { | ||
54 | /** | 53 | /** |
55 | * Performance peers | 54 | * Performance peers |
56 | */ | 55 | */ |
@@ -165,8 +164,7 @@ struct PerfHandle | |||
165 | /** | 164 | /** |
166 | * Data structure to store results for a single iteration | 165 | * Data structure to store results for a single iteration |
167 | */ | 166 | */ |
168 | struct Iteration | 167 | struct Iteration { |
169 | { | ||
170 | struct Result **results_array; | 168 | struct Result **results_array; |
171 | 169 | ||
172 | struct Result **update_results_array; | 170 | struct Result **update_results_array; |
@@ -176,8 +174,7 @@ struct Iteration | |||
176 | /** | 174 | /** |
177 | * Result for a solver calculcation | 175 | * Result for a solver calculcation |
178 | */ | 176 | */ |
179 | struct Result | 177 | struct Result { |
180 | { | ||
181 | /** | 178 | /** |
182 | * Previous element in the linked list | 179 | * Previous element in the linked list |
183 | */ | 180 | */ |
@@ -283,8 +280,7 @@ struct Result | |||
283 | /** | 280 | /** |
284 | * Peer used for the benchmarking | 281 | * Peer used for the benchmarking |
285 | */ | 282 | */ |
286 | struct PerfPeer | 283 | struct PerfPeer { |
287 | { | ||
288 | /** | 284 | /** |
289 | * Peer identitity | 285 | * Peer identitity |
290 | */ | 286 | */ |
@@ -317,19 +313,19 @@ static int ret; | |||
317 | * Do shutdown | 313 | * Do shutdown |
318 | */ | 314 | */ |
319 | static void | 315 | static void |
320 | end_now (int res) | 316 | end_now(int res) |
321 | { | 317 | { |
322 | if (NULL != ph.stat) | 318 | if (NULL != ph.stat) |
323 | { | 319 | { |
324 | GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO); | 320 | GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); |
325 | ph.stat = NULL; | 321 | ph.stat = NULL; |
326 | } | 322 | } |
327 | 323 | ||
328 | GNUNET_free_non_null (ph.peers); | 324 | GNUNET_free_non_null(ph.peers); |
329 | GNUNET_free_non_null (ph.iterations_results); | 325 | GNUNET_free_non_null(ph.iterations_results); |
330 | 326 | ||
331 | GAS_normalization_stop (); | 327 | GAS_normalization_stop(); |
332 | GAS_preference_done (); | 328 | GAS_preference_done(); |
333 | ret = res; | 329 | ret = res; |
334 | } | 330 | } |
335 | 331 | ||
@@ -340,13 +336,12 @@ end_now (int res) | |||
340 | * @param cp the number of the peer | 336 | * @param cp the number of the peer |
341 | */ | 337 | */ |
342 | static void | 338 | static void |
343 | perf_create_peer (int cp) | 339 | perf_create_peer(int cp) |
344 | { | 340 | { |
345 | 341 | GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, | |
346 | GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, | 342 | &ph.peers[cp].id, sizeof(struct GNUNET_PeerIdentity)); |
347 | &ph.peers[cp].id, sizeof (struct GNUNET_PeerIdentity)); | ||
348 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, | 343 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, |
349 | GNUNET_i2s (&ph.peers[cp].id)); | 344 | GNUNET_i2s(&ph.peers[cp].id)); |
350 | } | 345 | } |
351 | 346 | ||
352 | 347 | ||
@@ -356,91 +351,94 @@ perf_create_peer (int cp) | |||
356 | * @param cur the address to update | 351 | * @param cur the address to update |
357 | */ | 352 | */ |
358 | static void | 353 | static void |
359 | perf_update_address (struct ATS_Address *cur) | 354 | perf_update_address(struct ATS_Address *cur) |
360 | { | 355 | { |
361 | int r_type; | 356 | int r_type; |
362 | int abs_val; | 357 | int abs_val; |
363 | double rel_val; | 358 | double rel_val; |
364 | 359 | ||
365 | r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2); | 360 | r_type = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); |
366 | switch (r_type) | 361 | switch (r_type) |
367 | { | 362 | { |
368 | case 0: | 363 | case 0: |
369 | abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 364 | abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
370 | rel_val = (100 + (double) abs_val) / 100; | 365 | rel_val = (100 + (double)abs_val) / 100; |
371 | 366 | ||
372 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 367 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
373 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", | 368 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", |
374 | GNUNET_i2s (&cur->peer), cur, | 369 | GNUNET_i2s(&cur->peer), cur, |
375 | "GNUNET_ATS_QUALITY_NET_DELAY", | 370 | "GNUNET_ATS_QUALITY_NET_DELAY", |
376 | abs_val, rel_val); | 371 | abs_val, rel_val); |
377 | ph.sf->s_address_update_property (ph.sf->cls, cur, | 372 | ph.sf->s_address_update_property(ph.sf->cls, cur, |
378 | GNUNET_ATS_QUALITY_NET_DELAY, | 373 | GNUNET_ATS_QUALITY_NET_DELAY, |
379 | abs_val, rel_val); | 374 | abs_val, rel_val); |
380 | break; | 375 | break; |
381 | case 1: | 376 | |
382 | abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10); | 377 | case 1: |
383 | rel_val = (100 + (double) abs_val) / 100; | 378 | abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); |
384 | 379 | rel_val = (100 + (double)abs_val) / 100; | |
385 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 380 | |
386 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", | 381 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
387 | GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", | 382 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", |
388 | abs_val, rel_val); | 383 | GNUNET_i2s(&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", |
389 | ph.sf->s_address_update_property (ph.sf->cls, cur, | 384 | abs_val, rel_val); |
390 | GNUNET_ATS_QUALITY_NET_DISTANCE, | 385 | ph.sf->s_address_update_property(ph.sf->cls, cur, |
391 | abs_val, rel_val); | 386 | GNUNET_ATS_QUALITY_NET_DISTANCE, |
392 | break; | 387 | abs_val, rel_val); |
393 | default: | 388 | break; |
394 | break; | 389 | |
395 | } | 390 | default: |
391 | break; | ||
392 | } | ||
396 | } | 393 | } |
397 | 394 | ||
398 | 395 | ||
399 | static void | 396 | static void |
400 | bandwidth_changed_cb (void *cls, | 397 | bandwidth_changed_cb(void *cls, |
401 | struct ATS_Address *address) | 398 | struct ATS_Address *address) |
402 | { | 399 | { |
403 | if ( (0 == address->assigned_bw_out) && (0 == address->assigned_bw_in) ) | 400 | if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in)) |
404 | return; | 401 | return; |
405 | 402 | ||
406 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
407 | "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", | 404 | "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", |
408 | GNUNET_i2s (&address->peer), | 405 | GNUNET_i2s(&address->peer), |
409 | address, | 406 | address, |
410 | address->assigned_bw_out, | 407 | address->assigned_bw_out, |
411 | address->assigned_bw_in); | 408 | address->assigned_bw_in); |
412 | if (GNUNET_YES == ph.bulk_running) | 409 | if (GNUNET_YES == ph.bulk_running) |
413 | GNUNET_break (0); | 410 | GNUNET_break(0); |
414 | return; | 411 | return; |
415 | } | 412 | } |
416 | 413 | ||
417 | 414 | ||
418 | static const double * | 415 | static const double * |
419 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 416 | get_preferences_cb(void *cls, const struct GNUNET_PeerIdentity *id) |
420 | { | 417 | { |
421 | return GAS_preference_get_by_peer (NULL, id); | 418 | return GAS_preference_get_by_peer(NULL, id); |
422 | } | 419 | } |
423 | 420 | ||
424 | 421 | ||
425 | static void | 422 | static void |
426 | perf_address_initial_update (void *dead, | 423 | perf_address_initial_update(void *dead, |
427 | struct GNUNET_CONTAINER_MultiPeerMap * addresses, | 424 | struct GNUNET_CONTAINER_MultiPeerMap * addresses, |
428 | struct ATS_Address *address) | 425 | struct ATS_Address *address) |
429 | { | 426 | { |
430 | double delay; | 427 | double delay; |
431 | double distance; | 428 | double distance; |
432 | uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 429 | uint32_t random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
433 | delay = (100 + (double) random) / 100; | ||
434 | ph.sf->s_address_update_property (ph.sf->cls, | ||
435 | address, GNUNET_ATS_QUALITY_NET_DELAY, | ||
436 | 100, delay); | ||
437 | 430 | ||
438 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 431 | delay = (100 + (double)random) / 100; |
439 | distance = (100 + (double) random) / 100; | 432 | ph.sf->s_address_update_property(ph.sf->cls, |
433 | address, GNUNET_ATS_QUALITY_NET_DELAY, | ||
434 | 100, delay); | ||
440 | 435 | ||
441 | ph.sf->s_address_update_property (ph.sf->cls, address, | 436 | random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); |
442 | GNUNET_ATS_QUALITY_NET_DISTANCE, | 437 | distance = (100 + (double)random) / 100; |
443 | 10, distance); | 438 | |
439 | ph.sf->s_address_update_property(ph.sf->cls, address, | ||
440 | GNUNET_ATS_QUALITY_NET_DISTANCE, | ||
441 | 10, distance); | ||
444 | 442 | ||
445 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 443 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
446 | "Initial update address %p : %.2f %.2f\n", | 444 | "Initial update address %p : %.2f %.2f\n", |
@@ -448,23 +446,22 @@ perf_address_initial_update (void *dead, | |||
448 | } | 446 | } |
449 | 447 | ||
450 | 448 | ||
451 | struct DUA_Ctx | 449 | struct DUA_Ctx { |
452 | { | ||
453 | int r; | 450 | int r; |
454 | int c_cur_a; | 451 | int c_cur_a; |
455 | }; | 452 | }; |
456 | 453 | ||
457 | 454 | ||
458 | static int | 455 | static int |
459 | do_update_address (void *cls, | 456 | do_update_address(void *cls, |
460 | const struct GNUNET_PeerIdentity *pid, | 457 | const struct GNUNET_PeerIdentity *pid, |
461 | void *value) | 458 | void *value) |
462 | { | 459 | { |
463 | struct DUA_Ctx *ctx = cls; | 460 | struct DUA_Ctx *ctx = cls; |
464 | struct ATS_Address *addr = value; | 461 | struct ATS_Address *addr = value; |
465 | 462 | ||
466 | if (ctx->c_cur_a == ctx->r) | 463 | if (ctx->c_cur_a == ctx->r) |
467 | perf_update_address (addr); | 464 | perf_update_address(addr); |
468 | ctx->c_cur_a++; | 465 | ctx->c_cur_a++; |
469 | return GNUNET_OK; | 466 | return GNUNET_OK; |
470 | } | 467 | } |
@@ -478,7 +475,7 @@ do_update_address (void *cls, | |||
478 | * @param percentage_peers the percentage of peers to update | 475 | * @param percentage_peers the percentage of peers to update |
479 | */ | 476 | */ |
480 | static void | 477 | static void |
481 | perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers) | 478 | perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percentage_peers) |
482 | { | 479 | { |
483 | int c_peer; | 480 | int c_peer; |
484 | int c_select; | 481 | int c_select; |
@@ -488,9 +485,9 @@ perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percen | |||
488 | unsigned int m[cp]; | 485 | unsigned int m[cp]; |
489 | struct DUA_Ctx dua_ctx; | 486 | struct DUA_Ctx dua_ctx; |
490 | 487 | ||
491 | count = cp * ((double) percentage_peers / 100); | 488 | count = cp * ((double)percentage_peers / 100); |
492 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 489 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
493 | "Updating %u of %u peers \n", count, cp); | 490 | "Updating %u of %u peers \n", count, cp); |
494 | 491 | ||
495 | for (c_peer = 0; c_peer < cp; c_peer++) | 492 | for (c_peer = 0; c_peer < cp; c_peer++) |
496 | m[c_peer] = 0; | 493 | m[c_peer] = 0; |
@@ -498,32 +495,32 @@ perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percen | |||
498 | c_select = 0; | 495 | c_select = 0; |
499 | 496 | ||
500 | while (c_select < count) | 497 | while (c_select < count) |
501 | { | ||
502 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp); | ||
503 | if (0 == m[r]) | ||
504 | { | 498 | { |
505 | m[r] = 1; | 499 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, cp); |
506 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 500 | if (0 == m[r]) |
507 | "Updating peer [%u] \n", r); | 501 | { |
508 | c_select++; | 502 | m[r] = 1; |
503 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
504 | "Updating peer [%u] \n", r); | ||
505 | c_select++; | ||
506 | } | ||
509 | } | 507 | } |
510 | } | ||
511 | for (c_cur_p = 0; c_cur_p < cp; c_cur_p++) | 508 | for (c_cur_p = 0; c_cur_p < cp; c_cur_p++) |
512 | { | ||
513 | if (1 == m[c_cur_p]) | ||
514 | { | 509 | { |
515 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca); | 510 | if (1 == m[c_cur_p]) |
516 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 511 | { |
517 | "Updating peer [%u] address [%u]\n", c_cur_p, r); | 512 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, ca); |
518 | 513 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | |
519 | dua_ctx.c_cur_a = 0; | 514 | "Updating peer [%u] address [%u]\n", c_cur_p, r); |
520 | dua_ctx.r = r; | 515 | |
521 | GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses, | 516 | dua_ctx.c_cur_a = 0; |
522 | &ph.peers[c_cur_p].id, | 517 | dua_ctx.r = r; |
523 | &do_update_address, | 518 | GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, |
524 | &dua_ctx); | 519 | &ph.peers[c_cur_p].id, |
520 | &do_update_address, | ||
521 | &dua_ctx); | ||
522 | } | ||
525 | } | 523 | } |
526 | } | ||
527 | } | 524 | } |
528 | 525 | ||
529 | /** | 526 | /** |
@@ -534,14 +531,14 @@ perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percen | |||
534 | * @return the address | 531 | * @return the address |
535 | */ | 532 | */ |
536 | static struct ATS_Address * | 533 | static struct ATS_Address * |
537 | perf_create_address (int cp, int ca) | 534 | perf_create_address(int cp, int ca) |
538 | { | 535 | { |
539 | struct ATS_Address *a; | 536 | struct ATS_Address *a; |
540 | 537 | ||
541 | a = create_address (&ph.peers[cp].id, | 538 | a = create_address(&ph.peers[cp].id, |
542 | "Test 1", "test 1", strlen ("test 1") + 1, 0); | 539 | "Test 1", "test 1", strlen("test 1") + 1, 0); |
543 | GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a, | 540 | GNUNET_CONTAINER_multipeermap_put(ph.addresses, &ph.peers[cp].id, a, |
544 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 541 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
545 | return a; | 542 | return a; |
546 | } | 543 | } |
547 | 544 | ||
@@ -554,93 +551,100 @@ perf_create_address (int cp, int ca) | |||
554 | * @param add additional solver information | 551 | * @param add additional solver information |
555 | */ | 552 | */ |
556 | static void | 553 | static void |
557 | solver_info_cb (void *cls, | 554 | solver_info_cb(void *cls, |
558 | enum GAS_Solver_Operation op, | 555 | enum GAS_Solver_Operation op, |
559 | enum GAS_Solver_Status stat, | 556 | enum GAS_Solver_Status stat, |
560 | enum GAS_Solver_Additional_Information add) | 557 | enum GAS_Solver_Additional_Information add) |
561 | { | 558 | { |
562 | char *add_info; | 559 | char *add_info; |
563 | switch (add) { | 560 | |
561 | switch (add) | ||
562 | { | ||
564 | case GAS_INFO_NONE: | 563 | case GAS_INFO_NONE: |
565 | add_info = "GAS_INFO_NONE"; | 564 | add_info = "GAS_INFO_NONE"; |
566 | break; | 565 | break; |
566 | |||
567 | case GAS_INFO_FULL: | 567 | case GAS_INFO_FULL: |
568 | add_info = "GAS_INFO_MLP_FULL"; | 568 | add_info = "GAS_INFO_MLP_FULL"; |
569 | break; | 569 | break; |
570 | |||
570 | case GAS_INFO_UPDATED: | 571 | case GAS_INFO_UPDATED: |
571 | add_info = "GAS_INFO_MLP_UPDATED"; | 572 | add_info = "GAS_INFO_MLP_UPDATED"; |
572 | break; | 573 | break; |
574 | |||
573 | case GAS_INFO_PROP_ALL: | 575 | case GAS_INFO_PROP_ALL: |
574 | add_info = "GAS_INFO_PROP_ALL"; | 576 | add_info = "GAS_INFO_PROP_ALL"; |
575 | break; | 577 | break; |
578 | |||
576 | case GAS_INFO_PROP_SINGLE: | 579 | case GAS_INFO_PROP_SINGLE: |
577 | add_info = "GAS_INFO_PROP_SINGLE"; | 580 | add_info = "GAS_INFO_PROP_SINGLE"; |
578 | break; | 581 | break; |
582 | |||
579 | default: | 583 | default: |
580 | add_info = "INVALID"; | 584 | add_info = "INVALID"; |
581 | break; | 585 | break; |
582 | } | 586 | } |
583 | 587 | ||
584 | struct Result *tmp; | 588 | struct Result *tmp; |
585 | switch (op) | 589 | switch (op) |
586 | { | 590 | { |
587 | case GAS_OP_SOLVE_START: | 591 | case GAS_OP_SOLVE_START: |
588 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 592 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
589 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", | 593 | "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", |
590 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 594 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); |
591 | if (GNUNET_NO == ph.expecting_solution) | 595 | if (GNUNET_NO == ph.expecting_solution) |
592 | { | ||
593 | /* We do not expect a solution at the moment */ | ||
594 | GNUNET_break (0); | ||
595 | return; | ||
596 | } | ||
597 | |||
598 | if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result)) | ||
599 | { | ||
600 | tmp = GNUNET_new (struct Result); | ||
601 | /* Create new result */ | ||
602 | if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update)) | ||
603 | { | ||
604 | ph.current_result = tmp; | ||
605 | //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p); | ||
606 | ph.iterations_results[ph.current_iteration-1].update_results_array[ph.current_p] = tmp; | ||
607 | } | ||
608 | else | ||
609 | { | 596 | { |
610 | ph.current_result = tmp; | 597 | /* We do not expect a solution at the moment */ |
611 | //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p); | 598 | GNUNET_break(0); |
612 | ph.iterations_results[ph.current_iteration-1].results_array[ph.current_p] = tmp; | 599 | return; |
613 | } | 600 | } |
614 | 601 | ||
615 | ph.current_result->addresses = ph.current_a; | 602 | if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result)) |
616 | ph.current_result->peers = ph.current_p; | ||
617 | ph.current_result->s_total = GNUNET_TIME_absolute_get(); | ||
618 | ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
619 | ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
620 | ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
621 | ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
622 | ph.current_result->info = add; | ||
623 | if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update)) | ||
624 | { | ||
625 | ph.current_result->update = GNUNET_YES; | ||
626 | } | ||
627 | else | ||
628 | { | 603 | { |
629 | ph.current_result->update = GNUNET_NO; | 604 | tmp = GNUNET_new(struct Result); |
605 | /* Create new result */ | ||
606 | if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update)) | ||
607 | { | ||
608 | ph.current_result = tmp; | ||
609 | //fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p); | ||
610 | ph.iterations_results[ph.current_iteration - 1].update_results_array[ph.current_p] = tmp; | ||
611 | } | ||
612 | else | ||
613 | { | ||
614 | ph.current_result = tmp; | ||
615 | //fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p); | ||
616 | ph.iterations_results[ph.current_iteration - 1].results_array[ph.current_p] = tmp; | ||
617 | } | ||
618 | |||
619 | ph.current_result->addresses = ph.current_a; | ||
620 | ph.current_result->peers = ph.current_p; | ||
621 | ph.current_result->s_total = GNUNET_TIME_absolute_get(); | ||
622 | ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
623 | ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
624 | ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
625 | ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL; | ||
626 | ph.current_result->info = add; | ||
627 | if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update)) | ||
628 | { | ||
629 | ph.current_result->update = GNUNET_YES; | ||
630 | } | ||
631 | else | ||
632 | { | ||
633 | ph.current_result->update = GNUNET_NO; | ||
634 | } | ||
630 | } | 635 | } |
631 | |||
632 | } | ||
633 | return; | 636 | return; |
637 | |||
634 | case GAS_OP_SOLVE_STOP: | 638 | case GAS_OP_SOLVE_STOP: |
635 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 639 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
636 | "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP", | 640 | "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP", |
637 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); | 641 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); |
638 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 642 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
639 | { | 643 | { |
640 | /* We do not expect a solution at the moment */ | 644 | /* We do not expect a solution at the moment */ |
641 | GNUNET_break (0); | 645 | GNUNET_break(0); |
642 | return; | 646 | return; |
643 | } | 647 | } |
644 | 648 | ||
645 | if (GAS_STAT_SUCCESS == stat) | 649 | if (GAS_STAT_SUCCESS == stat) |
646 | ph.current_result->valid = GNUNET_YES; | 650 | ph.current_result->valid = GNUNET_YES; |
@@ -648,143 +652,148 @@ solver_info_cb (void *cls, | |||
648 | ph.current_result->valid = GNUNET_NO; | 652 | ph.current_result->valid = GNUNET_NO; |
649 | 653 | ||
650 | if (NULL != ph.current_result) | 654 | if (NULL != ph.current_result) |
651 | { | 655 | { |
652 | /* Finalize result */ | 656 | /* Finalize result */ |
653 | ph.current_result->e_total = GNUNET_TIME_absolute_get (); | 657 | ph.current_result->e_total = GNUNET_TIME_absolute_get(); |
654 | ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference ( | 658 | ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference( |
655 | ph.current_result->s_total, ph.current_result->e_total); | 659 | ph.current_result->s_total, ph.current_result->e_total); |
656 | } | 660 | } |
657 | ph.current_result = NULL; | 661 | ph.current_result = NULL; |
658 | return; | 662 | return; |
659 | 663 | ||
660 | case GAS_OP_SOLVE_SETUP_START: | 664 | case GAS_OP_SOLVE_SETUP_START: |
661 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 665 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
662 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", | 666 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", |
663 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 667 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
664 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 668 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
665 | { | 669 | { |
666 | GNUNET_break(0); | 670 | GNUNET_break(0); |
667 | return; | 671 | return; |
668 | } | 672 | } |
669 | 673 | ||
670 | if (GAS_STAT_SUCCESS == stat) | 674 | if (GAS_STAT_SUCCESS == stat) |
671 | ph.current_result->valid = GNUNET_YES; | 675 | ph.current_result->valid = GNUNET_YES; |
672 | else | 676 | else |
673 | ph.current_result->valid = GNUNET_NO; | 677 | ph.current_result->valid = GNUNET_NO; |
674 | 678 | ||
675 | ph.current_result->s_setup = GNUNET_TIME_absolute_get (); | 679 | ph.current_result->s_setup = GNUNET_TIME_absolute_get(); |
676 | return; | 680 | return; |
677 | 681 | ||
678 | case GAS_OP_SOLVE_SETUP_STOP: | 682 | case GAS_OP_SOLVE_SETUP_STOP: |
679 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 683 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
680 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", | 684 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", |
681 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 685 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
682 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 686 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
683 | { | 687 | { |
684 | GNUNET_break(0); | 688 | GNUNET_break(0); |
685 | return; | 689 | return; |
686 | } | 690 | } |
687 | 691 | ||
688 | if (GAS_STAT_SUCCESS == stat) | 692 | if (GAS_STAT_SUCCESS == stat) |
689 | ph.current_result->valid = GNUNET_YES; | 693 | ph.current_result->valid = GNUNET_YES; |
690 | else | 694 | else |
691 | ph.current_result->valid = GNUNET_NO; | 695 | ph.current_result->valid = GNUNET_NO; |
692 | 696 | ||
693 | ph.current_result->e_setup = GNUNET_TIME_absolute_get (); | 697 | ph.current_result->e_setup = GNUNET_TIME_absolute_get(); |
694 | ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference ( | 698 | ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference( |
695 | ph.current_result->s_setup, ph.current_result->e_setup); | 699 | ph.current_result->s_setup, ph.current_result->e_setup); |
696 | return; | 700 | return; |
697 | 701 | ||
698 | case GAS_OP_SOLVE_MLP_LP_START: | 702 | case GAS_OP_SOLVE_MLP_LP_START: |
699 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 703 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
700 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", | 704 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", |
701 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 705 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
702 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 706 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
703 | { | 707 | { |
704 | GNUNET_break(0); | 708 | GNUNET_break(0); |
705 | return; | 709 | return; |
706 | } | 710 | } |
707 | 711 | ||
708 | if (GAS_STAT_SUCCESS == stat) | 712 | if (GAS_STAT_SUCCESS == stat) |
709 | ph.current_result->valid = GNUNET_YES; | 713 | ph.current_result->valid = GNUNET_YES; |
710 | else | 714 | else |
711 | ph.current_result->valid = GNUNET_NO; | 715 | ph.current_result->valid = GNUNET_NO; |
712 | 716 | ||
713 | ph.current_result->s_lp = GNUNET_TIME_absolute_get (); | 717 | ph.current_result->s_lp = GNUNET_TIME_absolute_get(); |
714 | return; | 718 | return; |
719 | |||
715 | case GAS_OP_SOLVE_MLP_LP_STOP: | 720 | case GAS_OP_SOLVE_MLP_LP_STOP: |
716 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 721 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
717 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", | 722 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", |
718 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 723 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
719 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 724 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
720 | { | 725 | { |
721 | GNUNET_break(0); | 726 | GNUNET_break(0); |
722 | return; | 727 | return; |
723 | } | 728 | } |
724 | 729 | ||
725 | if (GAS_STAT_SUCCESS == stat) | 730 | if (GAS_STAT_SUCCESS == stat) |
726 | ph.current_result->valid = GNUNET_YES; | 731 | ph.current_result->valid = GNUNET_YES; |
727 | else | 732 | else |
728 | ph.current_result->valid = GNUNET_NO; | 733 | ph.current_result->valid = GNUNET_NO; |
729 | 734 | ||
730 | ph.current_result->e_lp = GNUNET_TIME_absolute_get (); | 735 | ph.current_result->e_lp = GNUNET_TIME_absolute_get(); |
731 | ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference ( | 736 | ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference( |
732 | ph.current_result->s_lp, ph.current_result->e_lp); | 737 | ph.current_result->s_lp, ph.current_result->e_lp); |
733 | return; | 738 | return; |
734 | 739 | ||
735 | case GAS_OP_SOLVE_MLP_MLP_START: | 740 | case GAS_OP_SOLVE_MLP_MLP_START: |
736 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 741 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
737 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", | 742 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", |
738 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 743 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
739 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 744 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
740 | { | 745 | { |
741 | GNUNET_break(0); | 746 | GNUNET_break(0); |
742 | return; | 747 | return; |
743 | } | 748 | } |
744 | 749 | ||
745 | if (GAS_STAT_SUCCESS == stat) | 750 | if (GAS_STAT_SUCCESS == stat) |
746 | ph.current_result->valid = GNUNET_YES; | 751 | ph.current_result->valid = GNUNET_YES; |
747 | else | 752 | else |
748 | ph.current_result->valid = GNUNET_NO; | 753 | ph.current_result->valid = GNUNET_NO; |
749 | 754 | ||
750 | ph.current_result->s_mlp = GNUNET_TIME_absolute_get (); | 755 | ph.current_result->s_mlp = GNUNET_TIME_absolute_get(); |
751 | return; | 756 | return; |
757 | |||
752 | case GAS_OP_SOLVE_MLP_MLP_STOP: | 758 | case GAS_OP_SOLVE_MLP_MLP_STOP: |
753 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 759 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
754 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", | 760 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", |
755 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 761 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
756 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) | 762 | if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) |
757 | { | 763 | { |
758 | GNUNET_break(0); | 764 | GNUNET_break(0); |
759 | return; | 765 | return; |
760 | } | 766 | } |
761 | 767 | ||
762 | if (GAS_STAT_SUCCESS == stat) | 768 | if (GAS_STAT_SUCCESS == stat) |
763 | ph.current_result->valid = GNUNET_YES; | 769 | ph.current_result->valid = GNUNET_YES; |
764 | else | 770 | else |
765 | ph.current_result->valid = GNUNET_NO; | 771 | ph.current_result->valid = GNUNET_NO; |
766 | 772 | ||
767 | ph.current_result->e_mlp = GNUNET_TIME_absolute_get (); | 773 | ph.current_result->e_mlp = GNUNET_TIME_absolute_get(); |
768 | ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference ( | 774 | ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference( |
769 | ph.current_result->s_mlp, ph.current_result->e_mlp); | 775 | ph.current_result->s_mlp, ph.current_result->e_mlp); |
770 | return; | 776 | return; |
777 | |||
771 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: | 778 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: |
772 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 779 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
773 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", | 780 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", |
774 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 781 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
775 | return; | 782 | return; |
783 | |||
776 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: | 784 | case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: |
777 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 785 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
778 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", | 786 | "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", |
779 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); | 787 | (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); |
780 | if (GAS_STAT_SUCCESS != stat) | 788 | if (GAS_STAT_SUCCESS != stat) |
781 | { | 789 | { |
782 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 790 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
783 | "Solver `%s' failed to update problem with %u peers and %u address!\n", | 791 | "Solver `%s' failed to update problem with %u peers and %u address!\n", |
784 | ph.ats_string, ph.current_p, ph.current_a); | 792 | ph.ats_string, ph.current_p, ph.current_a); |
785 | } | 793 | } |
786 | 794 | ||
787 | return; | 795 | return; |
796 | |||
788 | default: | 797 | default: |
789 | break; | 798 | break; |
790 | } | 799 | } |
@@ -796,82 +805,82 @@ solver_info_cb (void *cls, | |||
796 | * @param iteration the iteration to evaluate | 805 | * @param iteration the iteration to evaluate |
797 | */ | 806 | */ |
798 | static void | 807 | static void |
799 | evaluate (int iteration) | 808 | evaluate(int iteration) |
800 | { | 809 | { |
801 | struct Result *cur; | 810 | struct Result *cur; |
802 | int cp; | 811 | int cp; |
803 | 812 | ||
804 | for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp ++) | 813 | for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp++) |
805 | { | ||
806 | cur = ph.iterations_results[ph.current_iteration-1].results_array[cp]; | ||
807 | if (0 == cp) | ||
808 | continue; | ||
809 | if (NULL == cur) | ||
810 | { | 814 | { |
811 | GNUNET_break (0); | 815 | cur = ph.iterations_results[ph.current_iteration - 1].results_array[cp]; |
812 | fprintf (stderr, | 816 | if (0 == cp) |
813 | "Missing result for %u peers\n", cp); | 817 | continue; |
814 | continue; | 818 | if (NULL == cur) |
815 | } | 819 | { |
820 | GNUNET_break(0); | ||
821 | fprintf(stderr, | ||
822 | "Missing result for %u peers\n", cp); | ||
823 | continue; | ||
824 | } | ||
816 | 825 | ||
817 | 826 | ||
818 | if (GNUNET_NO == cur->valid) | 827 | if (GNUNET_NO == cur->valid) |
819 | { | 828 | { |
820 | fprintf (stderr, | 829 | fprintf(stderr, |
821 | "Total time to solve %s for %u peers %u addresses: %s\n", | 830 | "Total time to solve %s for %u peers %u addresses: %s\n", |
822 | (GNUNET_YES == cur->update) ? "updated" : "full", | 831 | (GNUNET_YES == cur->update) ? "updated" : "full", |
823 | cur->peers, cur->addresses, "Failed to solve!"); | 832 | cur->peers, cur->addresses, "Failed to solve!"); |
824 | continue; | 833 | continue; |
825 | } | 834 | } |
826 | 835 | ||
827 | 836 | ||
828 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us) | 837 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us) |
829 | { | 838 | { |
830 | fprintf (stderr, | 839 | fprintf(stderr, |
831 | "Total time to solve %s for %u peers %u addresses: %llu us\n", | 840 | "Total time to solve %s for %u peers %u addresses: %llu us\n", |
832 | (GNUNET_YES == cur->update) ? "updated" : "full", | 841 | (GNUNET_YES == cur->update) ? "updated" : "full", |
833 | cur->peers, cur->addresses, | 842 | cur->peers, cur->addresses, |
834 | (unsigned long long) cur->d_total_full.rel_value_us); | 843 | (unsigned long long)cur->d_total_full.rel_value_us); |
835 | } | 844 | } |
836 | 845 | ||
837 | 846 | ||
838 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us) | 847 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us) |
839 | { | 848 | { |
840 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 849 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
841 | "Total time to setup %s %u peers %u addresses: %llu us\n", | 850 | "Total time to setup %s %u peers %u addresses: %llu us\n", |
842 | (GNUNET_YES == cur->update) ? "updated" : "full", | 851 | (GNUNET_YES == cur->update) ? "updated" : "full", |
843 | cur->peers, cur->addresses, | 852 | cur->peers, cur->addresses, |
844 | (unsigned long long) cur->d_setup_full.rel_value_us); | 853 | (unsigned long long)cur->d_setup_full.rel_value_us); |
845 | } | 854 | } |
846 | 855 | ||
847 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us) | 856 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us) |
848 | { | 857 | { |
849 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 858 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
850 | "Total time to solve %s LP for %u peers %u addresses: %llu us\n", | 859 | "Total time to solve %s LP for %u peers %u addresses: %llu us\n", |
851 | (GNUNET_YES == cur->update) ? "updated" : "full", | 860 | (GNUNET_YES == cur->update) ? "updated" : "full", |
852 | cur->peers, | 861 | cur->peers, |
853 | cur->addresses, | 862 | cur->addresses, |
854 | (unsigned long long )cur->d_lp_full.rel_value_us); | 863 | (unsigned long long )cur->d_lp_full.rel_value_us); |
855 | } | 864 | } |
856 | 865 | ||
857 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us) | 866 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us) |
858 | { | 867 | { |
859 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 868 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
860 | "Total time to solve %s MLP for %u peers %u addresses: %llu us\n", | 869 | "Total time to solve %s MLP for %u peers %u addresses: %llu us\n", |
861 | (GNUNET_YES == cur->update) ? "updated" : "full", | 870 | (GNUNET_YES == cur->update) ? "updated" : "full", |
862 | cur->peers, cur->addresses, | 871 | cur->peers, cur->addresses, |
863 | (unsigned long long )cur->d_mlp_full.rel_value_us); | 872 | (unsigned long long )cur->d_mlp_full.rel_value_us); |
873 | } | ||
864 | } | 874 | } |
865 | } | ||
866 | } | 875 | } |
867 | 876 | ||
868 | 877 | ||
869 | static unsigned int | 878 | static unsigned int |
870 | get_connectivity_cb (void *cls, | 879 | get_connectivity_cb(void *cls, |
871 | const struct GNUNET_PeerIdentity *peer) | 880 | const struct GNUNET_PeerIdentity *peer) |
872 | { | 881 | { |
873 | return GNUNET_CONTAINER_multipeermap_contains (ph.addresses, | 882 | return GNUNET_CONTAINER_multipeermap_contains(ph.addresses, |
874 | peer); | 883 | peer); |
875 | } | 884 | } |
876 | 885 | ||
877 | 886 | ||
@@ -879,7 +888,7 @@ get_connectivity_cb (void *cls, | |||
879 | * Evaluate average results for all iterations | 888 | * Evaluate average results for all iterations |
880 | */ | 889 | */ |
881 | static void | 890 | static void |
882 | write_all_iterations (void) | 891 | write_all_iterations(void) |
883 | { | 892 | { |
884 | int c_iteration; | 893 | int c_iteration; |
885 | int c_peer; | 894 | int c_peer; |
@@ -898,180 +907,179 @@ write_all_iterations (void) | |||
898 | if (GNUNET_NO == ph.create_datafile) | 907 | if (GNUNET_NO == ph.create_datafile) |
899 | return; | 908 | return; |
900 | 909 | ||
901 | GNUNET_asprintf (&data_fn_full, | 910 | GNUNET_asprintf(&data_fn_full, |
902 | "perf_%s_full_%u-%u_%u_%u.data", | 911 | "perf_%s_full_%u-%u_%u_%u.data", |
903 | ph.ats_string, | 912 | ph.ats_string, |
904 | ph.total_iterations, | 913 | ph.total_iterations, |
905 | ph.N_peers_start, | 914 | ph.N_peers_start, |
906 | ph.N_peers_end, | 915 | ph.N_peers_end, |
907 | ph.N_address); | 916 | ph.N_address); |
908 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 917 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
909 | "Using data file `%s'\n", | 918 | "Using data file `%s'\n", |
910 | data_fn_full); | 919 | data_fn_full); |
911 | 920 | ||
912 | f_full = GNUNET_DISK_file_open (data_fn_full, | 921 | f_full = GNUNET_DISK_file_open(data_fn_full, |
913 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, | 922 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, |
914 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 923 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); |
915 | if (NULL == f_full) | 924 | if (NULL == f_full) |
916 | { | 925 | { |
917 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 926 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
918 | "Cannot open data file `%s'\n", | 927 | "Cannot open data file `%s'\n", |
919 | data_fn_full); | 928 | data_fn_full); |
920 | GNUNET_free (data_fn_full); | 929 | GNUNET_free(data_fn_full); |
921 | return; | 930 | return; |
922 | } | 931 | } |
923 | 932 | ||
924 | data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; | 933 | data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; |
925 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data))) | 934 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data))) |
926 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 935 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
927 | "Cannot write data to log file `%s'\n", | 936 | "Cannot write data to log file `%s'\n", |
928 | data_fn_full); | 937 | data_fn_full); |
929 | 938 | ||
930 | data_fn_update = NULL; | 939 | data_fn_update = NULL; |
931 | if (GNUNET_YES == ph.measure_updates) | 940 | if (GNUNET_YES == ph.measure_updates) |
932 | { | ||
933 | GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data", | ||
934 | ph.ats_string, | ||
935 | ph.total_iterations, | ||
936 | ph.N_peers_start, | ||
937 | ph.N_peers_end, | ||
938 | ph.N_address); | ||
939 | f_update = GNUNET_DISK_file_open (data_fn_update, | ||
940 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, | ||
941 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
942 | if (NULL == f_update) | ||
943 | { | 941 | { |
944 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 942 | GNUNET_asprintf(&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data", |
945 | "Cannot open gnuplot file `%s'\n", data_fn_update); | 943 | ph.ats_string, |
946 | GNUNET_free (data_fn_update); | 944 | ph.total_iterations, |
947 | if (NULL != f_full) | 945 | ph.N_peers_start, |
948 | GNUNET_DISK_file_close (f_full); | 946 | ph.N_peers_end, |
949 | GNUNET_free (data_fn_full); | 947 | ph.N_address); |
950 | return; | 948 | f_update = GNUNET_DISK_file_open(data_fn_update, |
951 | } | 949 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, |
952 | 950 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | |
953 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 951 | if (NULL == f_update) |
954 | "Using update data file `%s'\n", | 952 | { |
955 | data_fn_update); | 953 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
956 | 954 | "Cannot open gnuplot file `%s'\n", data_fn_update); | |
957 | data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; | 955 | GNUNET_free(data_fn_update); |
958 | if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen(data))) | 956 | if (NULL != f_full) |
959 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 957 | GNUNET_DISK_file_close(f_full); |
960 | "Cannot write data to log file `%s'\n", | 958 | GNUNET_free(data_fn_full); |
961 | data_fn_update); | 959 | return; |
962 | } | 960 | } |
963 | |||
964 | for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer ++) | ||
965 | { | ||
966 | char * data_str; | ||
967 | char * data_tmp; | ||
968 | char * data_upd_str; | ||
969 | char * data_upd_tmp; | ||
970 | GNUNET_asprintf(&data_str, "%u;%u",c_peer, ph.N_address); | ||
971 | if (ph.measure_updates) | ||
972 | GNUNET_asprintf(&data_upd_str, "%u;%u",c_peer, ph.N_address); | ||
973 | for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration ++) | ||
974 | { | ||
975 | struct Result *cur_full_res; | ||
976 | struct Result *cur_upd_res; | ||
977 | |||
978 | 961 | ||
962 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
963 | "Using update data file `%s'\n", | ||
964 | data_fn_update); | ||
979 | 965 | ||
980 | //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res); | 966 | data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; |
981 | cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer]; | 967 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data, strlen(data))) |
982 | if (c_peer == 0) | 968 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
983 | continue; | 969 | "Cannot write data to log file `%s'\n", |
984 | if (NULL == cur_full_res) | 970 | data_fn_update); |
985 | continue; | 971 | } |
986 | 972 | ||
973 | for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer++) | ||
974 | { | ||
975 | char * data_str; | ||
976 | char * data_tmp; | ||
977 | char * data_upd_str; | ||
978 | char * data_upd_tmp; | ||
979 | GNUNET_asprintf(&data_str, "%u;%u", c_peer, ph.N_address); | ||
987 | if (ph.measure_updates) | 980 | if (ph.measure_updates) |
988 | { | 981 | GNUNET_asprintf(&data_upd_str, "%u;%u", c_peer, ph.N_address); |
989 | cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer]; | 982 | for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration++) |
990 | data_upd_tmp = GNUNET_strdup (data_upd_str); | ||
991 | GNUNET_free (data_upd_str); | ||
992 | if (GNUNET_YES == cur_full_res->valid) | ||
993 | { | 983 | { |
994 | GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp, | 984 | struct Result *cur_full_res; |
995 | (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us); | 985 | struct Result *cur_upd_res; |
986 | |||
987 | |||
988 | |||
989 | //fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res); | ||
990 | cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer]; | ||
991 | if (c_peer == 0) | ||
992 | continue; | ||
993 | if (NULL == cur_full_res) | ||
994 | continue; | ||
995 | |||
996 | if (ph.measure_updates) | ||
997 | { | ||
998 | cur_upd_res = ph.iterations_results[c_iteration].update_results_array[c_peer]; | ||
999 | data_upd_tmp = GNUNET_strdup(data_upd_str); | ||
1000 | GNUNET_free(data_upd_str); | ||
1001 | if (GNUNET_YES == cur_full_res->valid) | ||
1002 | { | ||
1003 | GNUNET_asprintf(&data_upd_str, "%s;%llu", data_upd_tmp, | ||
1004 | (NULL == cur_upd_res) ? 0 : cur_upd_res->d_total_full.rel_value_us); | ||
1005 | } | ||
1006 | else | ||
1007 | { | ||
1008 | GNUNET_asprintf(&data_upd_str, "%s;", data_upd_tmp); | ||
1009 | } | ||
1010 | GNUNET_free(data_upd_tmp); | ||
1011 | } | ||
1012 | |||
1013 | //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses); | ||
1014 | //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us); | ||
1015 | |||
1016 | data_tmp = GNUNET_strdup(data_str); | ||
1017 | GNUNET_free(data_str); | ||
1018 | if (GNUNET_YES == cur_full_res->valid) | ||
1019 | { | ||
1020 | GNUNET_asprintf(&data_str, "%s;%llu", data_tmp, | ||
1021 | cur_full_res->d_total_full.rel_value_us); | ||
1022 | } | ||
1023 | else | ||
1024 | { | ||
1025 | GNUNET_asprintf(&data_str, "%s;", data_tmp); | ||
1026 | } | ||
1027 | |||
1028 | GNUNET_free(data_tmp); | ||
996 | } | 1029 | } |
997 | else | 1030 | data_tmp = GNUNET_strdup(data_str); |
998 | { | 1031 | GNUNET_free(data_str); |
999 | GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp); | 1032 | GNUNET_asprintf(&data_str, "%s\n", data_tmp); |
1000 | } | 1033 | GNUNET_free(data_tmp); |
1001 | GNUNET_free (data_upd_tmp); | ||
1002 | |||
1003 | } | ||
1004 | |||
1005 | //fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses); | ||
1006 | //fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us); | ||
1007 | |||
1008 | data_tmp = GNUNET_strdup (data_str); | ||
1009 | GNUNET_free (data_str); | ||
1010 | if (GNUNET_YES == cur_full_res->valid) | ||
1011 | { | ||
1012 | GNUNET_asprintf (&data_str, "%s;%llu", data_tmp, | ||
1013 | cur_full_res->d_total_full.rel_value_us); | ||
1014 | } | ||
1015 | else | ||
1016 | { | ||
1017 | GNUNET_asprintf (&data_str, "%s;", data_tmp); | ||
1018 | } | ||
1019 | 1034 | ||
1020 | GNUNET_free (data_tmp); | 1035 | fprintf(stderr, "Result full solution: %s\n", data_str); |
1021 | } | 1036 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data_str, strlen(data_str))) |
1022 | data_tmp = GNUNET_strdup (data_str); | 1037 | GNUNET_break(0); |
1023 | GNUNET_free (data_str); | 1038 | GNUNET_free(data_str); |
1024 | GNUNET_asprintf (&data_str, "%s\n", data_tmp); | ||
1025 | GNUNET_free (data_tmp); | ||
1026 | |||
1027 | fprintf (stderr, "Result full solution: %s\n", data_str); | ||
1028 | if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen(data_str))) | ||
1029 | GNUNET_break (0); | ||
1030 | GNUNET_free (data_str); | ||
1031 | 1039 | ||
1032 | if (ph.measure_updates) | 1040 | if (ph.measure_updates) |
1033 | { | 1041 | { |
1034 | data_upd_tmp = GNUNET_strdup (data_upd_str); | 1042 | data_upd_tmp = GNUNET_strdup(data_upd_str); |
1035 | GNUNET_free (data_upd_str); | 1043 | GNUNET_free(data_upd_str); |
1036 | GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp); | 1044 | GNUNET_asprintf(&data_upd_str, "%s\n", data_upd_tmp); |
1037 | GNUNET_free (data_upd_tmp); | 1045 | GNUNET_free(data_upd_tmp); |
1038 | 1046 | ||
1039 | fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str); | 1047 | fprintf(stderr, "Result updated solution: `%s'\n", data_upd_str); |
1040 | if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str, strlen(data_upd_str))) | 1048 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data_upd_str, strlen(data_upd_str))) |
1041 | GNUNET_break (0); | 1049 | GNUNET_break(0); |
1042 | GNUNET_free (data_upd_str); | 1050 | GNUNET_free(data_upd_str); |
1051 | } | ||
1043 | } | 1052 | } |
1044 | } | ||
1045 | 1053 | ||
1046 | if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full))) | 1054 | if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_full))) |
1047 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", | 1055 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", |
1048 | data_fn_full); | 1056 | data_fn_full); |
1049 | GNUNET_free_non_null (data_fn_full); | 1057 | GNUNET_free_non_null(data_fn_full); |
1050 | 1058 | ||
1051 | if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_update))) | 1059 | if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_update))) |
1052 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", | 1060 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", |
1053 | data_fn_update); | 1061 | data_fn_update); |
1054 | GNUNET_free_non_null (data_fn_update); | 1062 | GNUNET_free_non_null(data_fn_update); |
1055 | } | 1063 | } |
1056 | 1064 | ||
1057 | 1065 | ||
1058 | static int | 1066 | static int |
1059 | do_delete_address (void *cls, | 1067 | do_delete_address(void *cls, |
1060 | const struct GNUNET_PeerIdentity *pid, | 1068 | const struct GNUNET_PeerIdentity *pid, |
1061 | void *value) | 1069 | void *value) |
1062 | { | 1070 | { |
1063 | struct ATS_Address *cur = value; | 1071 | struct ATS_Address *cur = value; |
1064 | 1072 | ||
1065 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1073 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
1066 | "Deleting addresses for peer %u\n", | 1074 | "Deleting addresses for peer %u\n", |
1067 | pid); | 1075 | pid); |
1068 | GNUNET_assert (GNUNET_OK == | 1076 | GNUNET_assert(GNUNET_OK == |
1069 | GNUNET_CONTAINER_multipeermap_remove (ph.addresses, | 1077 | GNUNET_CONTAINER_multipeermap_remove(ph.addresses, |
1070 | pid, | 1078 | pid, |
1071 | cur)); | 1079 | cur)); |
1072 | ph.sf->s_del (ph.sf->cls, cur); | 1080 | ph.sf->s_del(ph.sf->cls, cur); |
1073 | GNUNET_free_non_null (cur->atsi); | 1081 | GNUNET_free_non_null(cur->atsi); |
1074 | GNUNET_free (cur); | 1082 | GNUNET_free(cur); |
1075 | return GNUNET_OK; | 1083 | return GNUNET_OK; |
1076 | } | 1084 | } |
1077 | 1085 | ||
@@ -1080,7 +1088,7 @@ do_delete_address (void *cls, | |||
1080 | * Run a performance iteration | 1088 | * Run a performance iteration |
1081 | */ | 1089 | */ |
1082 | static void | 1090 | static void |
1083 | perf_run_iteration (void) | 1091 | perf_run_iteration(void) |
1084 | { | 1092 | { |
1085 | int cp; | 1093 | int cp; |
1086 | int ca; | 1094 | int ca; |
@@ -1089,125 +1097,125 @@ perf_run_iteration (void) | |||
1089 | struct ATS_Address * cur_addr; | 1097 | struct ATS_Address * cur_addr; |
1090 | uint32_t net; | 1098 | uint32_t net; |
1091 | 1099 | ||
1092 | ph.iterations_results[ph.current_iteration-1].results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *)); | 1100 | ph.iterations_results[ph.current_iteration - 1].results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); |
1093 | if (ph.measure_updates) | 1101 | if (ph.measure_updates) |
1094 | ph.iterations_results[ph.current_iteration-1].update_results_array = GNUNET_malloc ((count_p + 1) * sizeof (struct Result *)); | 1102 | ph.iterations_results[ph.current_iteration - 1].update_results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); |
1095 | ph.peers = GNUNET_malloc ((count_p) * sizeof (struct PerfPeer)); | 1103 | ph.peers = GNUNET_malloc((count_p) * sizeof(struct PerfPeer)); |
1096 | for (cp = 0; cp < count_p; cp++) | 1104 | for (cp = 0; cp < count_p; cp++) |
1097 | perf_create_peer (cp); | 1105 | perf_create_peer(cp); |
1098 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1106 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1099 | "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp); | 1107 | "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp); |
1100 | 1108 | ||
1101 | for (cp = 0; cp < count_p; cp++) | 1109 | for (cp = 0; cp < count_p; cp++) |
1102 | { | ||
1103 | fprintf (stderr,"%u..", cp); | ||
1104 | if (GNUNET_NO == ph.bulk_running) | ||
1105 | { | ||
1106 | ph.bulk_running = GNUNET_YES; | ||
1107 | ph.sf->s_bulk_start (ph.sf->cls); | ||
1108 | } | ||
1109 | ph.current_p = cp + 1; | ||
1110 | for (ca = 0; ca < count_a; ca++) | ||
1111 | { | ||
1112 | cur_addr = perf_create_address (cp, ca); | ||
1113 | /* Add address */ | ||
1114 | |||
1115 | /* Random network selection */ | ||
1116 | //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1); | ||
1117 | /* Random equally distributed network selection */ | ||
1118 | net = 1 + (ca % (GNUNET_NT_COUNT - 1)); | ||
1119 | /* fprintf (stderr, "Network: %u `%s'\n", | ||
1120 | * mod_net , GNUNET_NT_to_string(mod_net)); */ | ||
1121 | |||
1122 | cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information); | ||
1123 | cur_addr->atsi_count = 1; | ||
1124 | cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
1125 | cur_addr->atsi[0].value = htonl (net); | ||
1126 | ph.sf->s_add (ph.sf->cls, cur_addr, net); | ||
1127 | |||
1128 | ph.current_a = ca + 1; | ||
1129 | perf_address_initial_update (NULL, ph.addresses, cur_addr); | ||
1130 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1131 | "Adding address for peer %u address %u in network %s\n", cp, ca, | ||
1132 | GNUNET_NT_to_string(net)); | ||
1133 | } | ||
1134 | /* Notify solver about request */ | ||
1135 | ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id); | ||
1136 | |||
1137 | if (cp + 1 >= ph.N_peers_start) | ||
1138 | { | 1110 | { |
1139 | /* Disable bulk to solve the problem */ | 1111 | fprintf(stderr, "%u..", cp); |
1140 | if (GNUNET_YES == ph.bulk_running) | 1112 | if (GNUNET_NO == ph.bulk_running) |
1141 | { | ||
1142 | ph.expecting_solution = GNUNET_YES; | ||
1143 | ph.bulk_running = GNUNET_NO; | ||
1144 | ph.sf->s_bulk_stop (ph.sf->cls); | ||
1145 | } | ||
1146 | else | ||
1147 | GNUNET_break (0); | ||
1148 | |||
1149 | /* Problem is solved by the solver here due to unlocking */ | ||
1150 | ph.expecting_solution = GNUNET_NO; | ||
1151 | |||
1152 | /* Update the problem */ | ||
1153 | if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates)) | ||
1154 | { | ||
1155 | /* Update */ | ||
1156 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1157 | "Updating problem with %u peers and %u addresses\n", cp + 1, ca); | ||
1158 | |||
1159 | ph.expecting_solution = GNUNET_YES; | ||
1160 | ph.performed_update = GNUNET_YES; | ||
1161 | if (GNUNET_NO == ph.bulk_running) | ||
1162 | { | 1113 | { |
1163 | ph.bulk_running = GNUNET_YES; | 1114 | ph.bulk_running = GNUNET_YES; |
1164 | ph.sf->s_bulk_start (ph.sf->cls); | 1115 | ph.sf->s_bulk_start(ph.sf->cls); |
1116 | } | ||
1117 | ph.current_p = cp + 1; | ||
1118 | for (ca = 0; ca < count_a; ca++) | ||
1119 | { | ||
1120 | cur_addr = perf_create_address(cp, ca); | ||
1121 | /* Add address */ | ||
1122 | |||
1123 | /* Random network selection */ | ||
1124 | //net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1); | ||
1125 | /* Random equally distributed network selection */ | ||
1126 | net = 1 + (ca % (GNUNET_NT_COUNT - 1)); | ||
1127 | /* fprintf (stderr, "Network: %u `%s'\n", | ||
1128 | * mod_net , GNUNET_NT_to_string(mod_net)); */ | ||
1129 | |||
1130 | cur_addr->atsi = GNUNET_new(struct GNUNET_ATS_Information); | ||
1131 | cur_addr->atsi_count = 1; | ||
1132 | cur_addr->atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); | ||
1133 | cur_addr->atsi[0].value = htonl(net); | ||
1134 | ph.sf->s_add(ph.sf->cls, cur_addr, net); | ||
1135 | |||
1136 | ph.current_a = ca + 1; | ||
1137 | perf_address_initial_update(NULL, ph.addresses, cur_addr); | ||
1138 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1139 | "Adding address for peer %u address %u in network %s\n", cp, ca, | ||
1140 | GNUNET_NT_to_string(net)); | ||
1141 | } | ||
1142 | /* Notify solver about request */ | ||
1143 | ph.sf->s_get(ph.sf->cls, &ph.peers[cp].id); | ||
1144 | |||
1145 | if (cp + 1 >= ph.N_peers_start) | ||
1146 | { | ||
1147 | /* Disable bulk to solve the problem */ | ||
1148 | if (GNUNET_YES == ph.bulk_running) | ||
1149 | { | ||
1150 | ph.expecting_solution = GNUNET_YES; | ||
1151 | ph.bulk_running = GNUNET_NO; | ||
1152 | ph.sf->s_bulk_stop(ph.sf->cls); | ||
1153 | } | ||
1154 | else | ||
1155 | GNUNET_break(0); | ||
1156 | |||
1157 | /* Problem is solved by the solver here due to unlocking */ | ||
1158 | ph.expecting_solution = GNUNET_NO; | ||
1159 | |||
1160 | /* Update the problem */ | ||
1161 | if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates)) | ||
1162 | { | ||
1163 | /* Update */ | ||
1164 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1165 | "Updating problem with %u peers and %u addresses\n", cp + 1, ca); | ||
1166 | |||
1167 | ph.expecting_solution = GNUNET_YES; | ||
1168 | ph.performed_update = GNUNET_YES; | ||
1169 | if (GNUNET_NO == ph.bulk_running) | ||
1170 | { | ||
1171 | ph.bulk_running = GNUNET_YES; | ||
1172 | ph.sf->s_bulk_start(ph.sf->cls); | ||
1173 | } | ||
1174 | perf_update_all_addresses(cp + 1, ca, ph.opt_update_percent); | ||
1175 | ph.bulk_running = GNUNET_NO; | ||
1176 | ph.sf->s_bulk_stop(ph.sf->cls); | ||
1177 | /* Problem is solved by the solver here due to unlocking */ | ||
1178 | ph.performed_update = GNUNET_NO; | ||
1179 | ph.expecting_solution = GNUNET_NO; | ||
1180 | } | ||
1181 | GNUNET_assert(GNUNET_NO == ph.bulk_running); | ||
1165 | } | 1182 | } |
1166 | perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent); | ||
1167 | ph.bulk_running = GNUNET_NO; | ||
1168 | ph.sf->s_bulk_stop (ph.sf->cls); | ||
1169 | /* Problem is solved by the solver here due to unlocking */ | ||
1170 | ph.performed_update = GNUNET_NO; | ||
1171 | ph.expecting_solution = GNUNET_NO; | ||
1172 | } | ||
1173 | GNUNET_assert (GNUNET_NO == ph.bulk_running); | ||
1174 | } | 1183 | } |
1175 | } | 1184 | fprintf(stderr, "\n"); |
1176 | fprintf (stderr,"\n"); | ||
1177 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1185 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1178 | "Done, cleaning up addresses\n"); | 1186 | "Done, cleaning up addresses\n"); |
1179 | if (GNUNET_NO == ph.bulk_running) | 1187 | if (GNUNET_NO == ph.bulk_running) |
1180 | { | 1188 | { |
1181 | ph.sf->s_bulk_start (ph.sf->cls); | 1189 | ph.sf->s_bulk_start(ph.sf->cls); |
1182 | ph.bulk_running = GNUNET_YES; | 1190 | ph.bulk_running = GNUNET_YES; |
1183 | } | 1191 | } |
1184 | 1192 | ||
1185 | for (cp = 0; cp < count_p; cp++) | 1193 | for (cp = 0; cp < count_p; cp++) |
1186 | { | 1194 | { |
1187 | GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses, | 1195 | GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, |
1188 | &ph.peers[cp].id, | 1196 | &ph.peers[cp].id, |
1189 | &do_delete_address, | 1197 | &do_delete_address, |
1190 | NULL); | 1198 | NULL); |
1191 | } | 1199 | } |
1192 | if (GNUNET_NO == ph.bulk_running) | 1200 | if (GNUNET_NO == ph.bulk_running) |
1193 | { | 1201 | { |
1194 | ph.sf->s_bulk_stop (ph.sf->cls); | 1202 | ph.sf->s_bulk_stop(ph.sf->cls); |
1195 | ph.bulk_running = GNUNET_NO; | 1203 | ph.bulk_running = GNUNET_NO; |
1196 | } | 1204 | } |
1197 | 1205 | ||
1198 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1206 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1199 | "Iteration done\n"); | 1207 | "Iteration done\n"); |
1200 | GNUNET_free(ph.peers); | 1208 | GNUNET_free(ph.peers); |
1201 | } | 1209 | } |
1202 | 1210 | ||
1203 | 1211 | ||
1204 | static void | 1212 | static void |
1205 | run (void *cls, char * const *args, const char *cfgfile, | 1213 | run(void *cls, char * const *args, const char *cfgfile, |
1206 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 1214 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
1207 | { | 1215 | { |
1208 | GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL); | 1216 | GNUNET_log_setup("perf-ats-solver", "WARNING", NULL); |
1209 | char *sep; | 1217 | char *sep; |
1210 | char *src_filename = GNUNET_strdup (__FILE__); | 1218 | char *src_filename = GNUNET_strdup(__FILE__); |
1211 | char *test_filename = cls; | 1219 | char *test_filename = cls; |
1212 | char *solver; | 1220 | char *solver; |
1213 | char *plugin; | 1221 | char *plugin; |
@@ -1218,92 +1226,92 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1218 | int c2; | 1226 | int c2; |
1219 | 1227 | ||
1220 | /* Extract test name */ | 1228 | /* Extract test name */ |
1221 | if (NULL == (sep = (strstr (src_filename,".c")))) | 1229 | if (NULL == (sep = (strstr(src_filename, ".c")))) |
1222 | { | 1230 | { |
1223 | GNUNET_free (src_filename); | 1231 | GNUNET_free(src_filename); |
1224 | GNUNET_break (0); | 1232 | GNUNET_break(0); |
1225 | ret = 1; | 1233 | ret = 1; |
1226 | return ; | 1234 | return; |
1227 | } | 1235 | } |
1228 | sep[0] = '\0'; | 1236 | sep[0] = '\0'; |
1229 | 1237 | ||
1230 | if (NULL != (sep = strstr (test_filename, ".exe"))) | 1238 | if (NULL != (sep = strstr(test_filename, ".exe"))) |
1231 | sep[0] = '\0'; | 1239 | sep[0] = '\0'; |
1232 | 1240 | ||
1233 | if (NULL == (solver = strstr (test_filename, src_filename))) | 1241 | if (NULL == (solver = strstr(test_filename, src_filename))) |
1234 | { | 1242 | { |
1235 | GNUNET_free (src_filename); | 1243 | GNUNET_free(src_filename); |
1236 | GNUNET_break (0); | 1244 | GNUNET_break(0); |
1237 | ret = 1; | 1245 | ret = 1; |
1238 | return ; | 1246 | return; |
1239 | } | 1247 | } |
1240 | solver += strlen (src_filename) +1; | 1248 | solver += strlen(src_filename) + 1; |
1241 | 1249 | ||
1242 | if (0 == strcmp(solver, "proportional")) | 1250 | if (0 == strcmp(solver, "proportional")) |
1243 | { | 1251 | { |
1244 | ph.ats_string = "proportional"; | 1252 | ph.ats_string = "proportional"; |
1245 | } | 1253 | } |
1246 | else if (0 == strcmp(solver, "mlp")) | 1254 | else if (0 == strcmp(solver, "mlp")) |
1247 | { | 1255 | { |
1248 | ph.ats_string = "mlp"; | 1256 | ph.ats_string = "mlp"; |
1249 | } | 1257 | } |
1250 | else if ((0 == strcmp(solver, "ril"))) | 1258 | else if ((0 == strcmp(solver, "ril"))) |
1251 | { | 1259 | { |
1252 | ph.ats_string = "ril"; | 1260 | ph.ats_string = "ril"; |
1253 | } | 1261 | } |
1254 | else | 1262 | else |
1255 | { | 1263 | { |
1256 | GNUNET_free (src_filename); | 1264 | GNUNET_free(src_filename); |
1257 | GNUNET_break (0); | 1265 | GNUNET_break(0); |
1258 | ret = 1; | 1266 | ret = 1; |
1259 | return ; | 1267 | return; |
1260 | } | 1268 | } |
1261 | GNUNET_free (src_filename); | 1269 | GNUNET_free(src_filename); |
1262 | 1270 | ||
1263 | /* Calculcate peers */ | 1271 | /* Calculcate peers */ |
1264 | if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end)) | 1272 | if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end)) |
1265 | { | 1273 | { |
1266 | ph.N_peers_start = DEFAULT_PEERS_START; | 1274 | ph.N_peers_start = DEFAULT_PEERS_START; |
1267 | ph.N_peers_end = DEFAULT_PEERS_END; | 1275 | ph.N_peers_end = DEFAULT_PEERS_END; |
1268 | } | 1276 | } |
1269 | if (0 == ph.N_address) | 1277 | if (0 == ph.N_address) |
1270 | ph.N_address = DEFAULT_ADDRESSES; | 1278 | ph.N_address = DEFAULT_ADDRESSES; |
1271 | 1279 | ||
1272 | 1280 | ||
1273 | if (ph.N_peers_start != ph.N_peers_end) | 1281 | if (ph.N_peers_start != ph.N_peers_end) |
1274 | fprintf (stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n", | 1282 | fprintf(stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n", |
1275 | ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations); | 1283 | ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations); |
1276 | else | 1284 | else |
1277 | fprintf (stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n", | 1285 | fprintf(stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n", |
1278 | ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations); | 1286 | ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations); |
1279 | 1287 | ||
1280 | if (0 == ph.opt_update_percent) | 1288 | if (0 == ph.opt_update_percent) |
1281 | ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE; | 1289 | ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE; |
1282 | 1290 | ||
1283 | /* Load quotas */ | 1291 | /* Load quotas */ |
1284 | solver_cfg = GNUNET_CONFIGURATION_create(); | 1292 | solver_cfg = GNUNET_CONFIGURATION_create(); |
1285 | if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load ( solver_cfg, "perf_ats_solver.conf")))) | 1293 | if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load(solver_cfg, "perf_ats_solver.conf")))) |
1286 | { | 1294 | { |
1287 | GNUNET_break(0); | 1295 | GNUNET_break(0); |
1288 | end_now (1); | 1296 | end_now(1); |
1289 | return; | 1297 | return; |
1290 | } | 1298 | } |
1291 | if (GNUNET_NT_COUNT != load_quotas (solver_cfg, | 1299 | if (GNUNET_NT_COUNT != load_quotas(solver_cfg, |
1292 | quotas_out, quotas_in, GNUNET_NT_COUNT)) | 1300 | quotas_out, quotas_in, GNUNET_NT_COUNT)) |
1293 | { | 1301 | { |
1294 | GNUNET_break(0); | 1302 | GNUNET_break(0); |
1295 | end_now (1); | 1303 | end_now(1); |
1296 | return; | 1304 | return; |
1297 | } | 1305 | } |
1298 | 1306 | ||
1299 | /* Create array of DLL to store results for iterations */ | 1307 | /* Create array of DLL to store results for iterations */ |
1300 | ph.iterations_results = GNUNET_malloc (sizeof (struct Iteration) * ph.total_iterations); | 1308 | ph.iterations_results = GNUNET_malloc(sizeof(struct Iteration) * ph.total_iterations); |
1301 | 1309 | ||
1302 | /* Load solver */ | 1310 | /* Load solver */ |
1303 | ph.env.cfg = solver_cfg; | 1311 | ph.env.cfg = solver_cfg; |
1304 | ph.stat = GNUNET_STATISTICS_create ("ats", cfg); | 1312 | ph.stat = GNUNET_STATISTICS_create("ats", cfg); |
1305 | ph.env.stats = ph.stat; | 1313 | ph.env.stats = ph.stat; |
1306 | ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); | 1314 | ph.addresses = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO); |
1307 | ph.env.addresses = ph.addresses; | 1315 | ph.env.addresses = ph.addresses; |
1308 | ph.env.bandwidth_changed_cb = bandwidth_changed_cb; | 1316 | ph.env.bandwidth_changed_cb = bandwidth_changed_cb; |
1309 | ph.env.get_connectivity = &get_connectivity_cb; | 1317 | ph.env.get_connectivity = &get_connectivity_cb; |
@@ -1312,75 +1320,75 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1312 | ph.env.info_cb = &solver_info_cb; | 1320 | ph.env.info_cb = &solver_info_cb; |
1313 | 1321 | ||
1314 | for (c = 0; c < GNUNET_NT_COUNT; c++) | 1322 | for (c = 0; c < GNUNET_NT_COUNT; c++) |
1315 | { | 1323 | { |
1316 | ph.env.out_quota[c] = quotas_out[c]; | 1324 | ph.env.out_quota[c] = quotas_out[c]; |
1317 | ph.env.in_quota[c] = quotas_in[c]; | 1325 | ph.env.in_quota[c] = quotas_in[c]; |
1318 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1326 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1319 | "Loading network quotas: `%s' %llu %llu \n", | 1327 | "Loading network quotas: `%s' %llu %llu \n", |
1320 | GNUNET_NT_to_string (c), | 1328 | GNUNET_NT_to_string(c), |
1321 | ph.env.out_quota[c], | 1329 | ph.env.out_quota[c], |
1322 | ph.env.in_quota[c]); | 1330 | ph.env.in_quota[c]); |
1323 | } | 1331 | } |
1324 | GAS_normalization_start (); | 1332 | GAS_normalization_start(); |
1325 | GAS_preference_init (); | 1333 | GAS_preference_init(); |
1326 | 1334 | ||
1327 | GNUNET_asprintf (&plugin, | 1335 | GNUNET_asprintf(&plugin, |
1328 | "libgnunet_plugin_ats_%s", | 1336 | "libgnunet_plugin_ats_%s", |
1329 | ph.ats_string); | 1337 | ph.ats_string); |
1330 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1338 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1331 | _("Initializing solver `%s'\n"), | 1339 | _("Initializing solver `%s'\n"), |
1332 | ph.ats_string); | 1340 | ph.ats_string); |
1333 | if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env))) | 1341 | if (NULL == (ph.sf = GNUNET_PLUGIN_load(plugin, &ph.env))) |
1334 | { | 1342 | { |
1335 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1343 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1336 | _("Failed to initialize solver `%s'!\n"), | 1344 | _("Failed to initialize solver `%s'!\n"), |
1337 | plugin); | 1345 | plugin); |
1338 | ret = 1; | 1346 | ret = 1; |
1339 | return; | 1347 | return; |
1340 | } | 1348 | } |
1341 | 1349 | ||
1342 | /* Do the benchmark */ | 1350 | /* Do the benchmark */ |
1343 | for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++) | 1351 | for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++) |
1344 | { | 1352 | { |
1345 | fprintf (stderr, | 1353 | fprintf(stderr, |
1346 | "Iteration %u of %u starting\n", | 1354 | "Iteration %u of %u starting\n", |
1347 | ph.current_iteration, | 1355 | ph.current_iteration, |
1348 | ph.total_iterations); | 1356 | ph.total_iterations); |
1349 | perf_run_iteration (); | 1357 | perf_run_iteration(); |
1350 | evaluate (ph.current_iteration); | 1358 | evaluate(ph.current_iteration); |
1351 | fprintf (stderr, | 1359 | fprintf(stderr, |
1352 | "Iteration %u of %u done\n", | 1360 | "Iteration %u of %u done\n", |
1353 | ph.current_iteration, | 1361 | ph.current_iteration, |
1354 | ph.total_iterations); | 1362 | ph.total_iterations); |
1355 | } | 1363 | } |
1356 | if (ph.create_datafile) | 1364 | if (ph.create_datafile) |
1357 | write_all_iterations (); | 1365 | write_all_iterations(); |
1358 | 1366 | ||
1359 | /* Unload solver*/ | 1367 | /* Unload solver*/ |
1360 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1368 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1361 | _("Unloading solver `%s'\n"), | 1369 | _("Unloading solver `%s'\n"), |
1362 | ph.ats_string); | 1370 | ph.ats_string); |
1363 | GNUNET_PLUGIN_unload (plugin, ph.sf); | 1371 | GNUNET_PLUGIN_unload(plugin, ph.sf); |
1364 | ph.sf = NULL; | 1372 | ph.sf = NULL; |
1365 | GNUNET_free (plugin); | 1373 | GNUNET_free(plugin); |
1366 | for (c = 0; c < ph.total_iterations; c++ ) | 1374 | for (c = 0; c < ph.total_iterations; c++) |
1367 | { | ||
1368 | for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++ ) | ||
1369 | { | 1375 | { |
1370 | if (0 == c2) | 1376 | for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++) |
1371 | continue; | 1377 | { |
1378 | if (0 == c2) | ||
1379 | continue; | ||
1380 | if (ph.measure_updates) | ||
1381 | GNUNET_free_non_null(ph.iterations_results[c].update_results_array[c2]); | ||
1382 | GNUNET_free(ph.iterations_results[c].results_array[c2]); | ||
1383 | } | ||
1372 | if (ph.measure_updates) | 1384 | if (ph.measure_updates) |
1373 | GNUNET_free_non_null (ph.iterations_results[c].update_results_array[c2]); | 1385 | GNUNET_free(ph.iterations_results[c].update_results_array); |
1374 | GNUNET_free (ph.iterations_results[c].results_array[c2]); | 1386 | GNUNET_free(ph.iterations_results[c].results_array); |
1375 | } | 1387 | } |
1376 | if (ph.measure_updates) | 1388 | GNUNET_free(ph.iterations_results); |
1377 | GNUNET_free (ph.iterations_results[c].update_results_array); | 1389 | |
1378 | GNUNET_free(ph.iterations_results[c].results_array); | 1390 | GNUNET_CONFIGURATION_destroy(solver_cfg); |
1379 | } | 1391 | GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); |
1380 | GNUNET_free (ph.iterations_results); | ||
1381 | |||
1382 | GNUNET_CONFIGURATION_destroy (solver_cfg); | ||
1383 | GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO); | ||
1384 | } | 1392 | } |
1385 | 1393 | ||
1386 | 1394 | ||
@@ -1391,7 +1399,7 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1391 | * @param argv argument values | 1399 | * @param argv argument values |
1392 | */ | 1400 | */ |
1393 | int | 1401 | int |
1394 | main (int argc, char *argv[]) | 1402 | main(int argc, char *argv[]) |
1395 | { | 1403 | { |
1396 | /* extract command line arguments */ | 1404 | /* extract command line arguments */ |
1397 | ph.opt_update_percent = 0; | 1405 | ph.opt_update_percent = 0; |
@@ -1404,46 +1412,45 @@ main (int argc, char *argv[]) | |||
1404 | ph.total_iterations = 1; | 1412 | ph.total_iterations = 1; |
1405 | 1413 | ||
1406 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 1414 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
1407 | 1415 | GNUNET_GETOPT_option_uint('a', | |
1408 | GNUNET_GETOPT_option_uint ('a', | 1416 | "addresses", |
1409 | "addresses", | 1417 | gettext_noop("addresses to use"), |
1410 | gettext_noop ("addresses to use"), | 1418 | &ph.N_address), |
1411 | &ph.N_address), | 1419 | |
1412 | 1420 | GNUNET_GETOPT_option_uint('s', | |
1413 | GNUNET_GETOPT_option_uint ('s', | 1421 | "start", |
1414 | "start", | 1422 | gettext_noop("start with peer"), |
1415 | gettext_noop ("start with peer"), | 1423 | &ph.N_peers_start), |
1416 | &ph.N_peers_start), | 1424 | |
1417 | 1425 | GNUNET_GETOPT_option_uint('e', | |
1418 | GNUNET_GETOPT_option_uint ('e', | 1426 | "end", |
1419 | "end", | 1427 | gettext_noop("end with peer"), |
1420 | gettext_noop ("end with peer"), | 1428 | &ph.N_peers_end), |
1421 | &ph.N_peers_end), | 1429 | |
1422 | 1430 | GNUNET_GETOPT_option_uint('i', | |
1423 | GNUNET_GETOPT_option_uint ('i', | 1431 | "iterations", |
1424 | "iterations", | 1432 | gettext_noop("number of iterations used for averaging (default: 1)"), |
1425 | gettext_noop ("number of iterations used for averaging (default: 1)"), | 1433 | &ph.total_iterations), |
1426 | &ph.total_iterations), | 1434 | |
1427 | 1435 | GNUNET_GETOPT_option_uint('p', | |
1428 | GNUNET_GETOPT_option_uint ('p', | 1436 | "percentage", |
1429 | "percentage", | 1437 | gettext_noop("update a fix percentage of addresses"), |
1430 | gettext_noop ("update a fix percentage of addresses"), | 1438 | &ph.opt_update_percent), |
1431 | &ph.opt_update_percent), | 1439 | |
1432 | 1440 | GNUNET_GETOPT_option_flag('d', | |
1433 | GNUNET_GETOPT_option_flag ('d', | 1441 | "data", |
1434 | "data", | 1442 | gettext_noop("create data file"), |
1435 | gettext_noop ("create data file"), | 1443 | &ph.create_datafile), |
1436 | &ph.create_datafile), | 1444 | |
1437 | 1445 | GNUNET_GETOPT_option_flag('u', | |
1438 | GNUNET_GETOPT_option_flag ('u', | 1446 | "update", |
1439 | "update", | 1447 | gettext_noop("measure updates"), |
1440 | gettext_noop ("measure updates"), | 1448 | &ph.measure_updates), |
1441 | &ph.measure_updates), | 1449 | |
1442 | 1450 | GNUNET_GETOPT_OPTION_END | |
1443 | GNUNET_GETOPT_OPTION_END | ||
1444 | }; | 1451 | }; |
1445 | 1452 | ||
1446 | GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]); | 1453 | GNUNET_PROGRAM_run(argc, argv, argv[0], NULL, options, &run, argv[0]); |
1447 | return ret; | 1454 | return ret; |
1448 | } | 1455 | } |
1449 | 1456 | ||
diff --git a/src/ats/plugin_ats2_common.c b/src/ats/plugin_ats2_common.c index faa2f0edf..c12d2a06f 100644 --- a/src/ats/plugin_ats2_common.c +++ b/src/ats/plugin_ats2_common.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. | 3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -40,59 +40,59 @@ | |||
40 | * @param quota[out] set to quota, #DEFAULT_BANDWIDTH if @a cfg does not say anything useful | 40 | * @param quota[out] set to quota, #DEFAULT_BANDWIDTH if @a cfg does not say anything useful |
41 | */ | 41 | */ |
42 | static void | 42 | static void |
43 | get_quota (const struct GNUNET_CONFIGURATION_Handle *cfg, | 43 | get_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, |
44 | const char *nts, | 44 | const char *nts, |
45 | const char *direction, | 45 | const char *direction, |
46 | unsigned long long *quota) | 46 | unsigned long long *quota) |
47 | { | 47 | { |
48 | char *quota_str; | 48 | char *quota_str; |
49 | char *quota_s; | 49 | char *quota_s; |
50 | int res; | 50 | int res; |
51 | 51 | ||
52 | GNUNET_asprintf ("a_s, | 52 | GNUNET_asprintf("a_s, |
53 | "%s_QUOTA_%s", | 53 | "%s_QUOTA_%s", |
54 | nts, | 54 | nts, |
55 | direction); | 55 | direction); |
56 | if (GNUNET_OK != | 56 | if (GNUNET_OK != |
57 | GNUNET_CONFIGURATION_get_value_string (cfg, | 57 | GNUNET_CONFIGURATION_get_value_string(cfg, |
58 | "ATS", | 58 | "ATS", |
59 | quota_s, | 59 | quota_s, |
60 | "a_str)) | 60 | "a_str)) |
61 | { | 61 | { |
62 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, | 62 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_WARNING, |
63 | "ATS", | 63 | "ATS", |
64 | quota_s); | 64 | quota_s); |
65 | GNUNET_free (quota_s); | 65 | GNUNET_free(quota_s); |
66 | return; | 66 | return; |
67 | } | 67 | } |
68 | GNUNET_free (quota_s); | 68 | GNUNET_free(quota_s); |
69 | res = GNUNET_NO; | 69 | res = GNUNET_NO; |
70 | if (0 == strcmp (quota_str, | 70 | if (0 == strcmp(quota_str, |
71 | "unlimited")) | 71 | "unlimited")) |
72 | { | 72 | { |
73 | *quota = ULONG_MAX; | 73 | *quota = ULONG_MAX; |
74 | res = GNUNET_YES; | ||
75 | } | ||
76 | if ((GNUNET_NO == res) && | ||
77 | (GNUNET_OK == | ||
78 | GNUNET_STRINGS_fancy_size_to_bytes(quota_str, | ||
79 | quota))) | ||
74 | res = GNUNET_YES; | 80 | res = GNUNET_YES; |
75 | } | 81 | if ((GNUNET_NO == res) && |
76 | if ( (GNUNET_NO == res) && | 82 | (1 == |
77 | (GNUNET_OK == | 83 | sscanf(quota_str, |
78 | GNUNET_STRINGS_fancy_size_to_bytes (quota_str, | 84 | "%llu", |
79 | quota)) ) | 85 | quota))) |
80 | res = GNUNET_YES; | ||
81 | if ( (GNUNET_NO == res) && | ||
82 | (1 == | ||
83 | sscanf (quota_str, | ||
84 | "%llu", | ||
85 | quota)) ) | ||
86 | res = GNUNET_YES; | 86 | res = GNUNET_YES; |
87 | if (GNUNET_NO == res) | 87 | if (GNUNET_NO == res) |
88 | { | 88 | { |
89 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 89 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
90 | _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), | 90 | _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), |
91 | direction, | 91 | direction, |
92 | nts, | 92 | nts, |
93 | quota_str, | 93 | quota_str, |
94 | (unsigned long long) DEFAULT_BANDWIDTH); | 94 | (unsigned long long)DEFAULT_BANDWIDTH); |
95 | *quota = DEFAULT_BANDWIDTH; | 95 | *quota = DEFAULT_BANDWIDTH; |
96 | } | 96 | } |
97 | GNUNET_free (quota_str); | 97 | GNUNET_free(quota_str); |
98 | } | 98 | } |
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c index 14bd2b99d..90566c561 100644 --- a/src/ats/plugin_ats2_simple.c +++ b/src/ats/plugin_ats2_simple.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. | 3 | Copyright (C) 2011-2015, 2018 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -31,7 +31,7 @@ | |||
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_peerstore_service.h" | 32 | #include "gnunet_peerstore_service.h" |
33 | 33 | ||
34 | #define LOG(kind, ...) GNUNET_log_from (kind, "ats-simple", __VA_ARGS__) | 34 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-simple", __VA_ARGS__) |
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
@@ -68,9 +68,7 @@ struct Peer; | |||
68 | /** | 68 | /** |
69 | * Entry in list of addresses we could try per peer. | 69 | * Entry in list of addresses we could try per peer. |
70 | */ | 70 | */ |
71 | struct Hello | 71 | struct Hello { |
72 | { | ||
73 | |||
74 | /** | 72 | /** |
75 | * Kept in a DLL. | 73 | * Kept in a DLL. |
76 | */ | 74 | */ |
@@ -123,9 +121,7 @@ struct Hello | |||
123 | * Internal representation of a session by the plugin. | 121 | * Internal representation of a session by the plugin. |
124 | * (If desired, plugin may just use NULL.) | 122 | * (If desired, plugin may just use NULL.) |
125 | */ | 123 | */ |
126 | struct GNUNET_ATS_SessionHandle | 124 | struct GNUNET_ATS_SessionHandle { |
127 | { | ||
128 | |||
129 | /** | 125 | /** |
130 | * Kept in DLL per peer. | 126 | * Kept in DLL per peer. |
131 | */ | 127 | */ |
@@ -193,9 +189,7 @@ struct GNUNET_ATS_SessionHandle | |||
193 | * Information about preferences and sessions we track | 189 | * Information about preferences and sessions we track |
194 | * per peer. | 190 | * per peer. |
195 | */ | 191 | */ |
196 | struct Peer | 192 | struct Peer { |
197 | { | ||
198 | |||
199 | /** | 193 | /** |
200 | * Kept in DLL per peer. | 194 | * Kept in DLL per peer. |
201 | */ | 195 | */ |
@@ -253,9 +247,7 @@ struct Peer | |||
253 | /** | 247 | /** |
254 | * Representation of a network (to be expanded...) | 248 | * Representation of a network (to be expanded...) |
255 | */ | 249 | */ |
256 | struct Network | 250 | struct Network { |
257 | { | ||
258 | |||
259 | /** | 251 | /** |
260 | * Total inbound quota | 252 | * Total inbound quota |
261 | */ | 253 | */ |
@@ -276,9 +268,7 @@ struct Network | |||
276 | /** | 268 | /** |
277 | * A handle for the proportional solver | 269 | * A handle for the proportional solver |
278 | */ | 270 | */ |
279 | struct SimpleHandle | 271 | struct SimpleHandle { |
280 | { | ||
281 | |||
282 | /** | 272 | /** |
283 | * Our execution environment. | 273 | * Our execution environment. |
284 | */ | 274 | */ |
@@ -316,9 +306,9 @@ struct SimpleHandle | |||
316 | * @return NULL for not found | 306 | * @return NULL for not found |
317 | */ | 307 | */ |
318 | struct Peer * | 308 | struct Peer * |
319 | lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | 309 | lookup_peer(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
320 | { | 310 | { |
321 | return GNUNET_CONTAINER_multipeermap_get (h->peers, pid); | 311 | return GNUNET_CONTAINER_multipeermap_get(h->peers, pid); |
322 | } | 312 | } |
323 | 313 | ||
324 | 314 | ||
@@ -330,7 +320,7 @@ lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | |||
330 | * @return #GNUNET_YES if no information is left in @a p | 320 | * @return #GNUNET_YES if no information is left in @a p |
331 | */ | 321 | */ |
332 | static int | 322 | static int |
333 | peer_test_dead (struct Peer *p) | 323 | peer_test_dead(struct Peer *p) |
334 | { | 324 | { |
335 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; | 325 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
336 | pk++) | 326 | pk++) |
@@ -350,17 +340,17 @@ peer_test_dead (struct Peer *p) | |||
350 | * @param hello[in,out] address suggestion to make | 340 | * @param hello[in,out] address suggestion to make |
351 | */ | 341 | */ |
352 | static void | 342 | static void |
353 | suggest_hello (struct Hello *hello) | 343 | suggest_hello(struct Hello *hello) |
354 | { | 344 | { |
355 | struct Peer *p = hello->peer; | 345 | struct Peer *p = hello->peer; |
356 | struct SimpleHandle *h = p->h; | 346 | struct SimpleHandle *h = p->h; |
357 | 347 | ||
358 | p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get (); | 348 | p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get(); |
359 | hello->backoff = | 349 | hello->backoff = |
360 | GNUNET_TIME_randomized_backoff (hello->backoff, | 350 | GNUNET_TIME_randomized_backoff(hello->backoff, |
361 | GNUNET_TIME_absolute_get_remaining ( | 351 | GNUNET_TIME_absolute_get_remaining( |
362 | hello->expiration)); | 352 | hello->expiration)); |
363 | h->env->suggest_cb (h->env->cls, &p->pid, hello->address); | 353 | h->env->suggest_cb(h->env->cls, &p->pid, hello->address); |
364 | } | 354 | } |
365 | 355 | ||
366 | 356 | ||
@@ -379,7 +369,7 @@ suggest_hello (struct Hello *hello) | |||
379 | * @param cls a `struct Peer` | 369 | * @param cls a `struct Peer` |
380 | */ | 370 | */ |
381 | static void | 371 | static void |
382 | suggest_start_cb (void *cls) | 372 | suggest_start_cb(void *cls) |
383 | { | 373 | { |
384 | struct Peer *p = cls; | 374 | struct Peer *p = cls; |
385 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO; | 375 | struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO; |
@@ -397,63 +387,63 @@ suggest_start_cb (void *cls) | |||
397 | /* calculate square of number of sessions */ | 387 | /* calculate square of number of sessions */ |
398 | num_sessions++; /* start with 1, even if we have zero sessions */ | 388 | num_sessions++; /* start with 1, even if we have zero sessions */ |
399 | if (num_sessions < UINT16_MAX) | 389 | if (num_sessions < UINT16_MAX) |
400 | sq = num_sessions * (uint32_t) num_sessions; | 390 | sq = num_sessions * (uint32_t)num_sessions; |
401 | else | 391 | else |
402 | sq = UINT32_MAX; | 392 | sq = UINT32_MAX; |
403 | xdelay = | 393 | xdelay = |
404 | GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ, | 394 | GNUNET_TIME_randomized_backoff(GNUNET_TIME_relative_multiply(SUGGEST_FREQ, |
405 | sq), | 395 | sq), |
406 | GNUNET_TIME_UNIT_FOREVER_REL); | 396 | GNUNET_TIME_UNIT_FOREVER_REL); |
407 | xnext = GNUNET_TIME_relative_to_absolute (xdelay); | 397 | xnext = GNUNET_TIME_relative_to_absolute(xdelay); |
408 | 398 | ||
409 | p->task = NULL; | 399 | p->task = NULL; |
410 | while (0 == delay.rel_value_us) | 400 | while (0 == delay.rel_value_us) |
411 | { | ||
412 | struct Hello *next; | ||
413 | struct GNUNET_TIME_Absolute xmax; | ||
414 | |||
415 | if (NULL != hello) | ||
416 | { | ||
417 | /* We went through the loop already once and found | ||
418 | a HELLO that is due *now*, so make a suggestion! */ | ||
419 | GNUNET_break (NULL == hello->sh); | ||
420 | suggest_hello (hello); | ||
421 | hello = NULL; | ||
422 | hpt = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
423 | } | ||
424 | for (struct Hello *pos = p->h_head; NULL != pos; pos = next) | ||
425 | { | 401 | { |
426 | struct GNUNET_TIME_Absolute pt; | 402 | struct Hello *next; |
427 | 403 | struct GNUNET_TIME_Absolute xmax; | |
428 | next = pos->next; | 404 | |
429 | if (NULL != pos->sh) | 405 | if (NULL != hello) |
430 | continue; | 406 | { |
431 | if (0 == | 407 | /* We went through the loop already once and found |
432 | GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us) | 408 | a HELLO that is due *now*, so make a suggestion! */ |
433 | { | 409 | GNUNET_break(NULL == hello->sh); |
434 | /* expired, remove! */ | 410 | suggest_hello(hello); |
435 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, pos); | 411 | hello = NULL; |
436 | GNUNET_free (pos); | 412 | hpt = GNUNET_TIME_UNIT_FOREVER_ABS; |
437 | continue; | 413 | } |
438 | } | 414 | for (struct Hello *pos = p->h_head; NULL != pos; pos = next) |
439 | pt = GNUNET_TIME_absolute_add (pos->last_attempt, pos->backoff); | 415 | { |
440 | if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us)) | 416 | struct GNUNET_TIME_Absolute pt; |
441 | { | 417 | |
442 | hello = pos; | 418 | next = pos->next; |
443 | hpt = pt; | 419 | if (NULL != pos->sh) |
444 | } | 420 | continue; |
421 | if (0 == | ||
422 | GNUNET_TIME_absolute_get_remaining(pos->expiration).rel_value_us) | ||
423 | { | ||
424 | /* expired, remove! */ | ||
425 | GNUNET_CONTAINER_DLL_remove(p->h_head, p->h_tail, pos); | ||
426 | GNUNET_free(pos); | ||
427 | continue; | ||
428 | } | ||
429 | pt = GNUNET_TIME_absolute_add(pos->last_attempt, pos->backoff); | ||
430 | if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us)) | ||
431 | { | ||
432 | hello = pos; | ||
433 | hpt = pt; | ||
434 | } | ||
435 | } | ||
436 | if (NULL == hello) | ||
437 | return; /* no HELLOs that could still be tried */ | ||
438 | |||
439 | /* hpt is now the *earliest* possible time for any HELLO | ||
440 | but we might not want to go for as early as possible for | ||
441 | this peer. So the actual time is the max of the earliest | ||
442 | HELLO and the 'xnext' */ | ||
443 | xmax = GNUNET_TIME_absolute_max(hpt, xnext); | ||
444 | delay = GNUNET_TIME_absolute_get_remaining(xmax); | ||
445 | } | 445 | } |
446 | if (NULL == hello) | 446 | p->task = GNUNET_SCHEDULER_add_delayed(delay, &suggest_start_cb, p); |
447 | return; /* no HELLOs that could still be tried */ | ||
448 | |||
449 | /* hpt is now the *earliest* possible time for any HELLO | ||
450 | but we might not want to go for as early as possible for | ||
451 | this peer. So the actual time is the max of the earliest | ||
452 | HELLO and the 'xnext' */ | ||
453 | xmax = GNUNET_TIME_absolute_max (hpt, xnext); | ||
454 | delay = GNUNET_TIME_absolute_get_remaining (xmax); | ||
455 | } | ||
456 | p->task = GNUNET_SCHEDULER_add_delayed (delay, &suggest_start_cb, p); | ||
457 | } | 447 | } |
458 | 448 | ||
459 | 449 | ||
@@ -465,9 +455,9 @@ suggest_start_cb (void *cls) | |||
465 | * @param emsg error message, or NULL if no errors | 455 | * @param emsg error message, or NULL if no errors |
466 | */ | 456 | */ |
467 | static void | 457 | static void |
468 | watch_cb (void *cls, | 458 | watch_cb(void *cls, |
469 | const struct GNUNET_PEERSTORE_Record *record, | 459 | const struct GNUNET_PEERSTORE_Record *record, |
470 | const char *emsg) | 460 | const char *emsg) |
471 | { | 461 | { |
472 | struct Peer *p = cls; | 462 | struct Peer *p = cls; |
473 | char *addr; | 463 | char *addr; |
@@ -476,65 +466,65 @@ watch_cb (void *cls, | |||
476 | struct GNUNET_TIME_Absolute expiration; | 466 | struct GNUNET_TIME_Absolute expiration; |
477 | struct Hello *hello; | 467 | struct Hello *hello; |
478 | 468 | ||
479 | if (0 != GNUNET_memcmp (&p->pid, &record->peer)) | 469 | if (0 != GNUNET_memcmp(&p->pid, &record->peer)) |
480 | { | 470 | { |
481 | GNUNET_break (0); | 471 | GNUNET_break(0); |
482 | return; | 472 | return; |
483 | } | 473 | } |
484 | if (0 != strcmp (record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) | 474 | if (0 != strcmp(record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) |
485 | { | 475 | { |
486 | GNUNET_break (0); | 476 | GNUNET_break(0); |
487 | return; | 477 | return; |
488 | } | 478 | } |
489 | addr = GNUNET_HELLO_extract_address (record->value, | 479 | addr = GNUNET_HELLO_extract_address(record->value, |
490 | record->value_size, | 480 | record->value_size, |
491 | &p->pid, | 481 | &p->pid, |
492 | &nt, | 482 | &nt, |
493 | &expiration); | 483 | &expiration); |
494 | if (NULL == addr) | 484 | if (NULL == addr) |
495 | return; /* invalid hello, bad signature, other problem */ | 485 | return; /* invalid hello, bad signature, other problem */ |
496 | if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) | 486 | if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) |
497 | { | 487 | { |
498 | /* expired, ignore */ | 488 | /* expired, ignore */ |
499 | GNUNET_free (addr); | 489 | GNUNET_free(addr); |
500 | return; | 490 | return; |
501 | } | 491 | } |
502 | /* check if addr is already known */ | 492 | /* check if addr is already known */ |
503 | for (struct Hello *he = p->h_head; NULL != he; he = he->next) | 493 | for (struct Hello *he = p->h_head; NULL != he; he = he->next) |
504 | { | ||
505 | if (0 != strcmp (he->address, addr)) | ||
506 | continue; | ||
507 | if (he->expiration.abs_value_us < expiration.abs_value_us) | ||
508 | { | 494 | { |
509 | he->expiration = expiration; | 495 | if (0 != strcmp(he->address, addr)) |
510 | he->nt = nt; | 496 | continue; |
497 | if (he->expiration.abs_value_us < expiration.abs_value_us) | ||
498 | { | ||
499 | he->expiration = expiration; | ||
500 | he->nt = nt; | ||
501 | } | ||
502 | GNUNET_free(addr); | ||
503 | return; | ||
511 | } | 504 | } |
512 | GNUNET_free (addr); | ||
513 | return; | ||
514 | } | ||
515 | /* create new HELLO */ | 505 | /* create new HELLO */ |
516 | alen = strlen (addr) + 1; | 506 | alen = strlen(addr) + 1; |
517 | hello = GNUNET_malloc (sizeof (struct Hello) + alen); | 507 | hello = GNUNET_malloc(sizeof(struct Hello) + alen); |
518 | hello->address = (const char *) &hello[1]; | 508 | hello->address = (const char *)&hello[1]; |
519 | hello->expiration = expiration; | 509 | hello->expiration = expiration; |
520 | hello->nt = nt; | 510 | hello->nt = nt; |
521 | hello->peer = p; | 511 | hello->peer = p; |
522 | memcpy (&hello[1], addr, alen); | 512 | memcpy(&hello[1], addr, alen); |
523 | GNUNET_CONTAINER_DLL_insert (p->h_head, p->h_tail, hello); | 513 | GNUNET_CONTAINER_DLL_insert(p->h_head, p->h_tail, hello); |
524 | /* check if sh for this HELLO already exists */ | 514 | /* check if sh for this HELLO already exists */ |
525 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; | 515 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; |
526 | sh = sh->next) | 516 | sh = sh->next) |
527 | { | 517 | { |
528 | if ((NULL == sh->address) || (0 != strcmp (sh->address, addr))) | 518 | if ((NULL == sh->address) || (0 != strcmp(sh->address, addr))) |
529 | continue; | 519 | continue; |
530 | GNUNET_assert (NULL == sh->hello); | 520 | GNUNET_assert(NULL == sh->hello); |
531 | sh->hello = hello; | 521 | sh->hello = hello; |
532 | hello->sh = sh; | 522 | hello->sh = sh; |
533 | break; | 523 | break; |
534 | } | 524 | } |
535 | GNUNET_free (addr); | 525 | GNUNET_free(addr); |
536 | if (NULL == p->task) | 526 | if (NULL == p->task) |
537 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); | 527 | p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); |
538 | } | 528 | } |
539 | 529 | ||
540 | 530 | ||
@@ -546,27 +536,27 @@ watch_cb (void *cls, | |||
546 | * @return a peer handle | 536 | * @return a peer handle |
547 | */ | 537 | */ |
548 | static struct Peer * | 538 | static struct Peer * |
549 | peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | 539 | peer_add(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
550 | { | 540 | { |
551 | struct Peer *p = lookup_peer (h, pid); | 541 | struct Peer *p = lookup_peer(h, pid); |
552 | 542 | ||
553 | if (NULL != p) | 543 | if (NULL != p) |
554 | return p; | 544 | return p; |
555 | p = GNUNET_new (struct Peer); | 545 | p = GNUNET_new(struct Peer); |
556 | p->h = h; | 546 | p->h = h; |
557 | p->pid = *pid; | 547 | p->pid = *pid; |
558 | p->wc = GNUNET_PEERSTORE_watch (h->ps, | 548 | p->wc = GNUNET_PEERSTORE_watch(h->ps, |
559 | "transport", | 549 | "transport", |
560 | &p->pid, | 550 | &p->pid, |
561 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, | 551 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, |
562 | &watch_cb, | 552 | &watch_cb, |
563 | p); | 553 | p); |
564 | GNUNET_assert (GNUNET_YES == | 554 | GNUNET_assert(GNUNET_YES == |
565 | GNUNET_CONTAINER_multipeermap_put ( | 555 | GNUNET_CONTAINER_multipeermap_put( |
566 | h->peers, | 556 | h->peers, |
567 | &p->pid, | 557 | &p->pid, |
568 | p, | 558 | p, |
569 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 559 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
570 | 560 | ||
571 | return p; | 561 | return p; |
572 | } | 562 | } |
@@ -579,31 +569,31 @@ peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) | |||
579 | * @param p the peer to free | 569 | * @param p the peer to free |
580 | */ | 570 | */ |
581 | static void | 571 | static void |
582 | peer_free (struct Peer *p) | 572 | peer_free(struct Peer *p) |
583 | { | 573 | { |
584 | struct SimpleHandle *h = p->h; | 574 | struct SimpleHandle *h = p->h; |
585 | struct Hello *hello; | 575 | struct Hello *hello; |
586 | 576 | ||
587 | GNUNET_assert (NULL == p->sh_head); | 577 | GNUNET_assert(NULL == p->sh_head); |
588 | while (NULL != (hello = p->h_head)) | 578 | while (NULL != (hello = p->h_head)) |
589 | { | 579 | { |
590 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, hello); | 580 | GNUNET_CONTAINER_DLL_remove(p->h_head, p->h_tail, hello); |
591 | GNUNET_assert (NULL == hello->sh); | 581 | GNUNET_assert(NULL == hello->sh); |
592 | GNUNET_free (hello); | 582 | GNUNET_free(hello); |
593 | } | 583 | } |
594 | if (NULL != p->task) | 584 | if (NULL != p->task) |
595 | { | 585 | { |
596 | GNUNET_SCHEDULER_cancel (p->task); | 586 | GNUNET_SCHEDULER_cancel(p->task); |
597 | p->task = NULL; | 587 | p->task = NULL; |
598 | } | 588 | } |
599 | if (NULL != p->wc) | 589 | if (NULL != p->wc) |
600 | { | 590 | { |
601 | GNUNET_PEERSTORE_watch_cancel (p->wc); | 591 | GNUNET_PEERSTORE_watch_cancel(p->wc); |
602 | p->wc = NULL; | 592 | p->wc = NULL; |
603 | } | 593 | } |
604 | GNUNET_assert (GNUNET_YES == | 594 | GNUNET_assert(GNUNET_YES == |
605 | GNUNET_CONTAINER_multipeermap_remove (h->peers, &p->pid, p)); | 595 | GNUNET_CONTAINER_multipeermap_remove(h->peers, &p->pid, p)); |
606 | GNUNET_free (p); | 596 | GNUNET_free(p); |
607 | } | 597 | } |
608 | 598 | ||
609 | 599 | ||
@@ -614,7 +604,7 @@ peer_free (struct Peer *p) | |||
614 | * @param sh session handle to consider updating transport for | 604 | * @param sh session handle to consider updating transport for |
615 | */ | 605 | */ |
616 | static void | 606 | static void |
617 | consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | 607 | consider_notify_transport(struct GNUNET_ATS_SessionHandle *sh) |
618 | { | 608 | { |
619 | struct Peer *peer = sh->peer; | 609 | struct Peer *peer = sh->peer; |
620 | struct SimpleHandle *h = peer->h; | 610 | struct SimpleHandle *h = peer->h; |
@@ -625,15 +615,15 @@ consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | |||
625 | int64_t delta_in; | 615 | int64_t delta_in; |
626 | int64_t delta_out; | 616 | int64_t delta_out; |
627 | 617 | ||
628 | delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation); | 618 | delay = GNUNET_TIME_absolute_get_duration(sh->last_allocation); |
629 | /* A significant change is more than 10% of the quota, | 619 | /* A significant change is more than 10% of the quota, |
630 | which is given in bytes/second */ | 620 | which is given in bytes/second */ |
631 | sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / | 621 | sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / |
632 | 1000LL / 10; | 622 | 1000LL / 10; |
633 | sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / | 623 | sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / |
634 | 1000LL / 10; | 624 | 1000LL / 10; |
635 | delta_in = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 625 | delta_in = ((int64_t)ntohl(sh->bw_in.value__)) - ((int64_t)sh->target_in); |
636 | delta_out = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 626 | delta_out = ((int64_t)ntohl(sh->bw_in.value__)) - ((int64_t)sh->target_in); |
637 | /* we want the absolute values */ | 627 | /* we want the absolute values */ |
638 | if (delta_in < 0) | 628 | if (delta_in < 0) |
639 | delta_in = -delta_in; | 629 | delta_in = -delta_in; |
@@ -648,24 +638,23 @@ consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | |||
648 | /* change is significant, tell transport! */ | 638 | /* change is significant, tell transport! */ |
649 | if (sh->target_in > UINT32_MAX) | 639 | if (sh->target_in > UINT32_MAX) |
650 | sh->target_in = UINT32_MAX; | 640 | sh->target_in = UINT32_MAX; |
651 | sh->bw_in.value__ = htonl ((uint32_t) sh->target_in); | 641 | sh->bw_in.value__ = htonl((uint32_t)sh->target_in); |
652 | if (sh->target_out > UINT32_MAX) | 642 | if (sh->target_out > UINT32_MAX) |
653 | sh->target_out = UINT32_MAX; | 643 | sh->target_out = UINT32_MAX; |
654 | sh->bw_out.value__ = htonl ((uint32_t) sh->target_out); | 644 | sh->bw_out.value__ = htonl((uint32_t)sh->target_out); |
655 | sh->last_allocation = GNUNET_TIME_absolute_get (); | 645 | sh->last_allocation = GNUNET_TIME_absolute_get(); |
656 | h->env->allocate_cb (h->env->cls, | 646 | h->env->allocate_cb(h->env->cls, |
657 | sh->session, | 647 | sh->session, |
658 | &peer->pid, | 648 | &peer->pid, |
659 | sh->bw_in, | 649 | sh->bw_in, |
660 | sh->bw_out); | 650 | sh->bw_out); |
661 | } | 651 | } |
662 | 652 | ||
663 | 653 | ||
664 | /** | 654 | /** |
665 | * Closure for #update_counters and #update_allocation. | 655 | * Closure for #update_counters and #update_allocation. |
666 | */ | 656 | */ |
667 | struct Counters | 657 | struct Counters { |
668 | { | ||
669 | /** | 658 | /** |
670 | * Plugin's state. | 659 | * Plugin's state. |
671 | */ | 660 | */ |
@@ -709,100 +698,103 @@ struct Counters | |||
709 | * @return #GNUNET_YES (continue to iterate) | 698 | * @return #GNUNET_YES (continue to iterate) |
710 | */ | 699 | */ |
711 | static int | 700 | static int |
712 | update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | 701 | update_counters(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
713 | { | 702 | { |
714 | struct Counters *c = cls; | 703 | struct Counters *c = cls; |
715 | struct Peer *peer = value; | 704 | struct Peer *peer = value; |
716 | struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT]; | 705 | struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT]; |
717 | 706 | ||
718 | (void) pid; | 707 | (void)pid; |
719 | if (NULL == peer->sh_head) | 708 | if (NULL == peer->sh_head) |
720 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ | 709 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ |
721 | memset (best, 0, sizeof (best)); | 710 | memset(best, 0, sizeof(best)); |
722 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; | 711 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
723 | sh = sh->next) | 712 | sh = sh->next) |
724 | { | ||
725 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | ||
726 | |||
727 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; | ||
728 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; | ||
729 | c->bw_in_by_nt[nt] += | ||
730 | GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); | ||
731 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; | ||
732 | pk++) | ||
733 | { | 713 | { |
734 | /* General rule: always prefer smaller distance if possible, | 714 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
735 | otherwise decide by pk: */ | 715 | |
736 | switch (pk) | 716 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; |
737 | { | 717 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; |
738 | case GNUNET_MQ_PREFERENCE_NONE: | 718 | c->bw_in_by_nt[nt] += |
739 | break; | 719 | GNUNET_MAX(MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); |
740 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: | 720 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
741 | /* For bandwidth, we compare the sum of transmitted bytes and | 721 | pk++) |
742 | confirmed transmitted bytes, so confirmed data counts twice */ | 722 | { |
743 | if ((NULL == best[pk]) || | 723 | /* General rule: always prefer smaller distance if possible, |
744 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 724 | otherwise decide by pk: */ |
745 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > | 725 | switch (pk) |
746 | best[pk]->data->prop.utilization_out + | 726 | { |
747 | best[pk]->data->prop.goodput_out)) | 727 | case GNUNET_MQ_PREFERENCE_NONE: |
748 | best[pk] = sh; | 728 | break; |
749 | /* If both are equal (i.e. usually this happens if there is a zero), use | 729 | |
750 | latency as a yardstick */ | 730 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: |
751 | if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == | 731 | /* For bandwidth, we compare the sum of transmitted bytes and |
752 | best[pk]->data->prop.utilization_out + | 732 | confirmed transmitted bytes, so confirmed data counts twice */ |
753 | best[pk]->data->prop.goodput_out) && | 733 | if ((NULL == best[pk]) || |
754 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 734 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
755 | (sh->data->prop.delay.rel_value_us < | 735 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > |
756 | best[pk]->data->prop.delay.rel_value_us)) | 736 | best[pk]->data->prop.utilization_out + |
757 | best[pk] = sh; | 737 | best[pk]->data->prop.goodput_out)) |
758 | break; | 738 | best[pk] = sh; |
759 | case GNUNET_MQ_PREFERENCE_LATENCY: | 739 | /* If both are equal (i.e. usually this happens if there is a zero), use |
760 | if ((NULL == best[pk]) || | 740 | latency as a yardstick */ |
761 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 741 | if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == |
762 | ((sh->data->prop.distance == best[pk]->data->prop.distance) && | 742 | best[pk]->data->prop.utilization_out + |
763 | (sh->data->prop.delay.rel_value_us < | 743 | best[pk]->data->prop.goodput_out) && |
764 | best[pk]->data->prop.delay.rel_value_us))) | 744 | (sh->data->prop.distance == best[pk]->data->prop.distance) && |
765 | best[pk] = sh; | 745 | (sh->data->prop.delay.rel_value_us < |
766 | break; | 746 | best[pk]->data->prop.delay.rel_value_us)) |
767 | case GNUNET_MQ_PREFERENCE_RELIABILITY: | 747 | best[pk] = sh; |
768 | /* For reliability, we consider the ratio of goodput to utilization | 748 | break; |
769 | (but use multiplicative formultations to avoid division by zero) */ | 749 | |
770 | if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * | 750 | case GNUNET_MQ_PREFERENCE_LATENCY: |
771 | best[pk]->data->prop.utilization_out > | 751 | if ((NULL == best[pk]) || |
772 | 1ULL * sh->data->prop.utilization_out * | 752 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
773 | best[pk]->data->prop.goodput_out)) | 753 | ((sh->data->prop.distance == best[pk]->data->prop.distance) && |
774 | best[pk] = sh; | 754 | (sh->data->prop.delay.rel_value_us < |
775 | /* If both are equal (i.e. usually this happens if there is a zero), use | 755 | best[pk]->data->prop.delay.rel_value_us))) |
776 | latency as a yardstick */ | 756 | best[pk] = sh; |
777 | if ((1ULL * sh->data->prop.goodput_out * | 757 | break; |
778 | best[pk]->data->prop.utilization_out == | 758 | |
779 | 1ULL * sh->data->prop.utilization_out * | 759 | case GNUNET_MQ_PREFERENCE_RELIABILITY: |
780 | best[pk]->data->prop.goodput_out) && | 760 | /* For reliability, we consider the ratio of goodput to utilization |
781 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 761 | (but use multiplicative formultations to avoid division by zero) */ |
782 | (sh->data->prop.delay.rel_value_us < | 762 | if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * |
783 | best[pk]->data->prop.delay.rel_value_us)) | 763 | best[pk]->data->prop.utilization_out > |
784 | best[pk] = sh; | 764 | 1ULL * sh->data->prop.utilization_out * |
785 | break; | 765 | best[pk]->data->prop.goodput_out)) |
786 | } | 766 | best[pk] = sh; |
767 | /* If both are equal (i.e. usually this happens if there is a zero), use | ||
768 | latency as a yardstick */ | ||
769 | if ((1ULL * sh->data->prop.goodput_out * | ||
770 | best[pk]->data->prop.utilization_out == | ||
771 | 1ULL * sh->data->prop.utilization_out * | ||
772 | best[pk]->data->prop.goodput_out) && | ||
773 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | ||
774 | (sh->data->prop.delay.rel_value_us < | ||
775 | best[pk]->data->prop.delay.rel_value_us)) | ||
776 | best[pk] = sh; | ||
777 | break; | ||
778 | } | ||
779 | } | ||
787 | } | 780 | } |
788 | } | ||
789 | /* for first round, assign target bandwidth simply to sum of | 781 | /* for first round, assign target bandwidth simply to sum of |
790 | requested bandwidth */ | 782 | requested bandwidth */ |
791 | for (enum GNUNET_MQ_PreferenceKind pk = | 783 | for (enum GNUNET_MQ_PreferenceKind pk = |
792 | 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; | 784 | 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; |
793 | pk < GNUNET_MQ_PREFERENCE_COUNT; | 785 | pk < GNUNET_MQ_PREFERENCE_COUNT; |
794 | pk++) | 786 | pk++) |
795 | { | 787 | { |
796 | const struct GNUNET_ATS_SessionData *data = best[pk]->data; | 788 | const struct GNUNET_ATS_SessionData *data = best[pk]->data; |
797 | enum GNUNET_NetworkType nt; | 789 | enum GNUNET_NetworkType nt; |
798 | 790 | ||
799 | GNUNET_assert (NULL != data); | 791 | GNUNET_assert(NULL != data); |
800 | nt = data->prop.nt; | 792 | nt = data->prop.nt; |
801 | best[pk]->target_out = | 793 | best[pk]->target_out = |
802 | GNUNET_MIN (peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); | 794 | GNUNET_MIN(peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); |
803 | c->bw_out_by_nt[nt] += | 795 | c->bw_out_by_nt[nt] += |
804 | (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); | 796 | (uint64_t)(best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); |
805 | } | 797 | } |
806 | return GNUNET_YES; | 798 | return GNUNET_YES; |
807 | } | 799 | } |
808 | 800 | ||
@@ -817,23 +809,23 @@ update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
817 | * @return #GNUNET_YES (continue to iterate) | 809 | * @return #GNUNET_YES (continue to iterate) |
818 | */ | 810 | */ |
819 | static int | 811 | static int |
820 | update_allocation (void *cls, | 812 | update_allocation(void *cls, |
821 | const struct GNUNET_PeerIdentity *pid, | 813 | const struct GNUNET_PeerIdentity *pid, |
822 | void *value) | 814 | void *value) |
823 | { | 815 | { |
824 | struct Counters *c = cls; | 816 | struct Counters *c = cls; |
825 | struct Peer *peer = value; | 817 | struct Peer *peer = value; |
826 | 818 | ||
827 | (void) pid; | 819 | (void)pid; |
828 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; | 820 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
829 | sh = sh->next) | 821 | sh = sh->next) |
830 | { | 822 | { |
831 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | 823 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
832 | 824 | ||
833 | sh->target_out = (uint64_t) (c->scale_out[nt] * sh->target_out); | 825 | sh->target_out = (uint64_t)(c->scale_out[nt] * sh->target_out); |
834 | sh->target_in = (uint64_t) (c->scale_in[nt] * sh->target_in); | 826 | sh->target_in = (uint64_t)(c->scale_in[nt] * sh->target_in); |
835 | consider_notify_transport (sh); | 827 | consider_notify_transport(sh); |
836 | } | 828 | } |
837 | return GNUNET_YES; | 829 | return GNUNET_YES; |
838 | } | 830 | } |
839 | 831 | ||
@@ -842,23 +834,23 @@ update_allocation (void *cls, | |||
842 | * The world changed, recalculate our allocations. | 834 | * The world changed, recalculate our allocations. |
843 | */ | 835 | */ |
844 | static void | 836 | static void |
845 | update (struct SimpleHandle *h) | 837 | update(struct SimpleHandle *h) |
846 | { | 838 | { |
847 | struct Counters cnt = {.h = h}; | 839 | struct Counters cnt = { .h = h }; |
848 | 840 | ||
849 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_counters, &cnt); | 841 | GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_counters, &cnt); |
850 | /* calculate how badly the missmatch between requested | 842 | /* calculate how badly the missmatch between requested |
851 | allocations and available bandwidth is per network type */ | 843 | allocations and available bandwidth is per network type */ |
852 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) | 844 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
853 | { | 845 | { |
854 | cnt.scale_out[nt] = | 846 | cnt.scale_out[nt] = |
855 | 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; | 847 | 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; |
856 | cnt.scale_in[nt] = | 848 | cnt.scale_in[nt] = |
857 | 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; | 849 | 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; |
858 | } | 850 | } |
859 | /* recalculate allocations, considering scaling factor, and | 851 | /* recalculate allocations, considering scaling factor, and |
860 | update transport if the change is significant */ | 852 | update transport if the change is significant */ |
861 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_allocation, &cnt); | 853 | GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_allocation, &cnt); |
862 | } | 854 | } |
863 | 855 | ||
864 | 856 | ||
@@ -870,15 +862,15 @@ update (struct SimpleHandle *h) | |||
870 | * @return plugin's internal representation, or NULL | 862 | * @return plugin's internal representation, or NULL |
871 | */ | 863 | */ |
872 | static struct GNUNET_ATS_PreferenceHandle * | 864 | static struct GNUNET_ATS_PreferenceHandle * |
873 | simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref) | 865 | simple_preference_add(void *cls, const struct GNUNET_ATS_Preference *pref) |
874 | { | 866 | { |
875 | struct SimpleHandle *h = cls; | 867 | struct SimpleHandle *h = cls; |
876 | struct Peer *p = peer_add (h, &pref->peer); | 868 | struct Peer *p = peer_add(h, &pref->peer); |
877 | 869 | ||
878 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 870 | GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
879 | p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); | 871 | p->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); |
880 | h->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); | 872 | h->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); |
881 | update (h); | 873 | update(h); |
882 | return NULL; | 874 | return NULL; |
883 | } | 875 | } |
884 | 876 | ||
@@ -892,20 +884,20 @@ simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref) | |||
892 | * @return plugin's internal representation, or NULL | 884 | * @return plugin's internal representation, or NULL |
893 | */ | 885 | */ |
894 | static void | 886 | static void |
895 | simple_preference_del (void *cls, | 887 | simple_preference_del(void *cls, |
896 | struct GNUNET_ATS_PreferenceHandle *ph, | 888 | struct GNUNET_ATS_PreferenceHandle *ph, |
897 | const struct GNUNET_ATS_Preference *pref) | 889 | const struct GNUNET_ATS_Preference *pref) |
898 | { | 890 | { |
899 | struct SimpleHandle *h = cls; | 891 | struct SimpleHandle *h = cls; |
900 | struct Peer *p = lookup_peer (h, &pref->peer); | 892 | struct Peer *p = lookup_peer(h, &pref->peer); |
901 | 893 | ||
902 | GNUNET_assert (NULL != p); | 894 | GNUNET_assert(NULL != p); |
903 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 895 | GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
904 | p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 896 | p->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); |
905 | h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 897 | h->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); |
906 | if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead (p))) | 898 | if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead(p))) |
907 | peer_free (p); | 899 | peer_free(p); |
908 | update (h); | 900 | update(h); |
909 | } | 901 | } |
910 | 902 | ||
911 | 903 | ||
@@ -919,50 +911,50 @@ simple_preference_del (void *cls, | |||
919 | * @return handle by which the plugin will identify this session | 911 | * @return handle by which the plugin will identify this session |
920 | */ | 912 | */ |
921 | static struct GNUNET_ATS_SessionHandle * | 913 | static struct GNUNET_ATS_SessionHandle * |
922 | simple_session_add (void *cls, | 914 | simple_session_add(void *cls, |
923 | const struct GNUNET_ATS_SessionData *data, | 915 | const struct GNUNET_ATS_SessionData *data, |
924 | const char *address) | 916 | const char *address) |
925 | { | 917 | { |
926 | struct SimpleHandle *h = cls; | 918 | struct SimpleHandle *h = cls; |
927 | struct Peer *p = peer_add (h, &data->peer); | 919 | struct Peer *p = peer_add(h, &data->peer); |
928 | struct Hello *hello; | 920 | struct Hello *hello; |
929 | size_t alen; | 921 | size_t alen; |
930 | struct GNUNET_ATS_SessionHandle *sh; | 922 | struct GNUNET_ATS_SessionHandle *sh; |
931 | 923 | ||
932 | /* setup session handle */ | 924 | /* setup session handle */ |
933 | GNUNET_assert (NULL != data); | 925 | GNUNET_assert(NULL != data); |
934 | if (NULL == address) | 926 | if (NULL == address) |
935 | alen = 0; | 927 | alen = 0; |
936 | else | 928 | else |
937 | alen = strlen (address) + 1; | 929 | alen = strlen(address) + 1; |
938 | sh = GNUNET_malloc (sizeof (struct GNUNET_ATS_SessionHandle) + alen); | 930 | sh = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionHandle) + alen); |
939 | sh->peer = p; | 931 | sh->peer = p; |
940 | sh->session = data->session; | 932 | sh->session = data->session; |
941 | sh->data = data; | 933 | sh->data = data; |
942 | if (NULL == address) | 934 | if (NULL == address) |
943 | { | 935 | { |
944 | sh->address = NULL; | 936 | sh->address = NULL; |
945 | } | 937 | } |
946 | else | 938 | else |
947 | { | 939 | { |
948 | memcpy (&sh[1], address, alen); | 940 | memcpy(&sh[1], address, alen); |
949 | sh->address = (const char *) &sh[1]; | 941 | sh->address = (const char *)&sh[1]; |
950 | } | 942 | } |
951 | GNUNET_CONTAINER_DLL_insert (p->sh_head, p->sh_tail, sh); | 943 | GNUNET_CONTAINER_DLL_insert(p->sh_head, p->sh_tail, sh); |
952 | if (NULL != address) | 944 | if (NULL != address) |
953 | { | ||
954 | /* match HELLO */ | ||
955 | hello = p->h_head; | ||
956 | while ((NULL != hello) && (0 != strcmp (address, hello->address))) | ||
957 | hello = hello->next; | ||
958 | if (NULL != hello) | ||
959 | { | 945 | { |
960 | hello->sh = sh; | 946 | /* match HELLO */ |
961 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | 947 | hello = p->h_head; |
962 | sh->hello = hello; | 948 | while ((NULL != hello) && (0 != strcmp(address, hello->address))) |
949 | hello = hello->next; | ||
950 | if (NULL != hello) | ||
951 | { | ||
952 | hello->sh = sh; | ||
953 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | ||
954 | sh->hello = hello; | ||
955 | } | ||
963 | } | 956 | } |
964 | } | 957 | update(h); |
965 | update (h); | ||
966 | return sh; | 958 | return sh; |
967 | } | 959 | } |
968 | 960 | ||
@@ -976,15 +968,15 @@ simple_session_add (void *cls, | |||
976 | * @param data performance characteristics of @a sh | 968 | * @param data performance characteristics of @a sh |
977 | */ | 969 | */ |
978 | static void | 970 | static void |
979 | simple_session_update (void *cls, | 971 | simple_session_update(void *cls, |
980 | struct GNUNET_ATS_SessionHandle *sh, | 972 | struct GNUNET_ATS_SessionHandle *sh, |
981 | const struct GNUNET_ATS_SessionData *data) | 973 | const struct GNUNET_ATS_SessionData *data) |
982 | { | 974 | { |
983 | struct SimpleHandle *h = cls; | 975 | struct SimpleHandle *h = cls; |
984 | 976 | ||
985 | GNUNET_assert (NULL != data); | 977 | GNUNET_assert(NULL != data); |
986 | sh->data = data; /* this statement should not really do anything... */ | 978 | sh->data = data; /* this statement should not really do anything... */ |
987 | update (h); | 979 | update(h); |
988 | } | 980 | } |
989 | 981 | ||
990 | 982 | ||
@@ -996,30 +988,30 @@ simple_session_update (void *cls, | |||
996 | * @param data (last) performance characteristics of @a sh | 988 | * @param data (last) performance characteristics of @a sh |
997 | */ | 989 | */ |
998 | static void | 990 | static void |
999 | simple_session_del (void *cls, | 991 | simple_session_del(void *cls, |
1000 | struct GNUNET_ATS_SessionHandle *sh, | 992 | struct GNUNET_ATS_SessionHandle *sh, |
1001 | const struct GNUNET_ATS_SessionData *data) | 993 | const struct GNUNET_ATS_SessionData *data) |
1002 | { | 994 | { |
1003 | struct SimpleHandle *h = cls; | 995 | struct SimpleHandle *h = cls; |
1004 | struct Peer *p = sh->peer; | 996 | struct Peer *p = sh->peer; |
1005 | struct Hello *hello = sh->hello; | 997 | struct Hello *hello = sh->hello; |
1006 | 998 | ||
1007 | /* clean up sh */ | 999 | /* clean up sh */ |
1008 | GNUNET_CONTAINER_DLL_remove (p->sh_head, p->sh_tail, sh); | 1000 | GNUNET_CONTAINER_DLL_remove(p->sh_head, p->sh_tail, sh); |
1009 | if (NULL != hello) | 1001 | if (NULL != hello) |
1010 | { | 1002 | { |
1011 | GNUNET_assert (sh == hello->sh); | 1003 | GNUNET_assert(sh == hello->sh); |
1012 | hello->sh = NULL; | 1004 | hello->sh = NULL; |
1013 | /* session went down, if necessary restart suggesting | 1005 | /* session went down, if necessary restart suggesting |
1014 | addresses */ | 1006 | addresses */ |
1015 | if (NULL == p->task) | 1007 | if (NULL == p->task) |
1016 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); | 1008 | p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); |
1017 | } | 1009 | } |
1018 | GNUNET_free (sh); | 1010 | GNUNET_free(sh); |
1019 | /* del peer if otherwise dead */ | 1011 | /* del peer if otherwise dead */ |
1020 | if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead (p))) | 1012 | if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead(p))) |
1021 | peer_free (p); | 1013 | peer_free(p); |
1022 | update (h); | 1014 | update(h); |
1023 | } | 1015 | } |
1024 | 1016 | ||
1025 | 1017 | ||
@@ -1034,16 +1026,16 @@ simple_session_del (void *cls, | |||
1034 | * @return the `struct SimpleHandle` to pass as a closure | 1026 | * @return the `struct SimpleHandle` to pass as a closure |
1035 | */ | 1027 | */ |
1036 | void * | 1028 | void * |
1037 | libgnunet_plugin_ats2_simple_init (void *cls) | 1029 | libgnunet_plugin_ats2_simple_init(void *cls) |
1038 | { | 1030 | { |
1039 | static struct GNUNET_ATS_SolverFunctions sf; | 1031 | static struct GNUNET_ATS_SolverFunctions sf; |
1040 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 1032 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
1041 | struct SimpleHandle *s; | 1033 | struct SimpleHandle *s; |
1042 | 1034 | ||
1043 | s = GNUNET_new (struct SimpleHandle); | 1035 | s = GNUNET_new(struct SimpleHandle); |
1044 | s->env = env; | 1036 | s->env = env; |
1045 | s->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); | 1037 | s->peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); |
1046 | s->ps = GNUNET_PEERSTORE_connect (env->cfg); | 1038 | s->ps = GNUNET_PEERSTORE_connect(env->cfg); |
1047 | sf.cls = s; | 1039 | sf.cls = s; |
1048 | sf.preference_add = &simple_preference_add; | 1040 | sf.preference_add = &simple_preference_add; |
1049 | sf.preference_del = &simple_preference_del; | 1041 | sf.preference_del = &simple_preference_del; |
@@ -1051,18 +1043,18 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1051 | sf.session_update = &simple_session_update; | 1043 | sf.session_update = &simple_session_update; |
1052 | sf.session_del = &simple_session_del; | 1044 | sf.session_del = &simple_session_del; |
1053 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) | 1045 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
1054 | { | ||
1055 | const char *name = GNUNET_NT_to_string (nt); | ||
1056 | |||
1057 | if (NULL == name) | ||
1058 | { | 1046 | { |
1059 | GNUNET_break (0); | 1047 | const char *name = GNUNET_NT_to_string(nt); |
1060 | break; | 1048 | |
1049 | if (NULL == name) | ||
1050 | { | ||
1051 | GNUNET_break(0); | ||
1052 | break; | ||
1053 | } | ||
1054 | get_quota(env->cfg, name, "IN", &s->networks[nt].total_quota_in); | ||
1055 | get_quota(env->cfg, name, "OUT", &s->networks[nt].total_quota_out); | ||
1056 | s->networks[nt].type = nt; | ||
1061 | } | 1057 | } |
1062 | get_quota (env->cfg, name, "IN", &s->networks[nt].total_quota_in); | ||
1063 | get_quota (env->cfg, name, "OUT", &s->networks[nt].total_quota_out); | ||
1064 | s->networks[nt].type = nt; | ||
1065 | } | ||
1066 | return &sf; | 1058 | return &sf; |
1067 | } | 1059 | } |
1068 | 1060 | ||
@@ -1073,15 +1065,15 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1073 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() | 1065 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() |
1074 | */ | 1066 | */ |
1075 | void * | 1067 | void * |
1076 | libgnunet_plugin_ats2_simple_done (void *cls) | 1068 | libgnunet_plugin_ats2_simple_done(void *cls) |
1077 | { | 1069 | { |
1078 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 1070 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
1079 | struct SimpleHandle *s = sf->cls; | 1071 | struct SimpleHandle *s = sf->cls; |
1080 | 1072 | ||
1081 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (s->peers)); | 1073 | GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(s->peers)); |
1082 | GNUNET_CONTAINER_multipeermap_destroy (s->peers); | 1074 | GNUNET_CONTAINER_multipeermap_destroy(s->peers); |
1083 | GNUNET_PEERSTORE_disconnect (s->ps, GNUNET_NO); | 1075 | GNUNET_PEERSTORE_disconnect(s->ps, GNUNET_NO); |
1084 | GNUNET_free (s); | 1076 | GNUNET_free(s); |
1085 | return NULL; | 1077 | return NULL; |
1086 | } | 1078 | } |
1087 | 1079 | ||
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index 0f3a727a7..8d3c9e23a 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file ats/plugin_ats_mlp.c | 22 | * @file ats/plugin_ats_mlp.c |
@@ -34,7 +34,7 @@ | |||
34 | #include <glpk.h> | 34 | #include <glpk.h> |
35 | 35 | ||
36 | 36 | ||
37 | #define BIG_M_VALUE (UINT32_MAX) /10 | 37 | #define BIG_M_VALUE (UINT32_MAX) / 10 |
38 | #define BIG_M_STRING "unlimited" | 38 | #define BIG_M_STRING "unlimited" |
39 | 39 | ||
40 | #define MLP_AVERAGING_QUEUE_LENGTH 3 | 40 | #define MLP_AVERAGING_QUEUE_LENGTH 3 |
@@ -54,16 +54,14 @@ | |||
54 | #define GLP_YES 1.0 | 54 | #define GLP_YES 1.0 |
55 | #define GLP_NO 0.0 | 55 | #define GLP_NO 0.0 |
56 | 56 | ||
57 | enum MLP_Output_Format | 57 | enum MLP_Output_Format { |
58 | { | ||
59 | MLP_MPS, | 58 | MLP_MPS, |
60 | MLP_CPLEX, | 59 | MLP_CPLEX, |
61 | MLP_GLPK | 60 | MLP_GLPK |
62 | }; | 61 | }; |
63 | 62 | ||
64 | 63 | ||
65 | enum QualityMetrics | 64 | enum QualityMetrics { |
66 | { | ||
67 | RQ_QUALITY_METRIC_DELAY = 0, | 65 | RQ_QUALITY_METRIC_DELAY = 0, |
68 | RQ_QUALITY_METRIC_DISTANCE = 1, | 66 | RQ_QUALITY_METRIC_DISTANCE = 1, |
69 | RQ_QUALITY_METRIC_COUNT = 2 | 67 | RQ_QUALITY_METRIC_COUNT = 2 |
@@ -71,22 +69,24 @@ enum QualityMetrics | |||
71 | 69 | ||
72 | 70 | ||
73 | static const char * | 71 | static const char * |
74 | print_quality_type (enum QualityMetrics qm) | 72 | print_quality_type(enum QualityMetrics qm) |
75 | { | 73 | { |
76 | switch (qm){ | 74 | switch (qm) |
77 | case RQ_QUALITY_METRIC_DELAY: | 75 | { |
78 | return "delay"; | 76 | case RQ_QUALITY_METRIC_DELAY: |
79 | case RQ_QUALITY_METRIC_DISTANCE: | 77 | return "delay"; |
80 | return "distance"; | 78 | |
81 | default: | 79 | case RQ_QUALITY_METRIC_DISTANCE: |
82 | GNUNET_break (0); | 80 | return "distance"; |
83 | return NULL; | 81 | |
84 | } | 82 | default: |
83 | GNUNET_break(0); | ||
84 | return NULL; | ||
85 | } | ||
85 | } | 86 | } |
86 | 87 | ||
87 | 88 | ||
88 | struct MLP_Solution | 89 | struct MLP_Solution { |
89 | { | ||
90 | int lp_res; | 90 | int lp_res; |
91 | int lp_presolv; | 91 | int lp_presolv; |
92 | int mip_res; | 92 | int mip_res; |
@@ -103,11 +103,9 @@ struct MLP_Solution | |||
103 | 103 | ||
104 | int n_peers; | 104 | int n_peers; |
105 | int n_addresses; | 105 | int n_addresses; |
106 | |||
107 | }; | 106 | }; |
108 | 107 | ||
109 | struct ATS_Peer | 108 | struct ATS_Peer { |
110 | { | ||
111 | struct GNUNET_PeerIdentity id; | 109 | struct GNUNET_PeerIdentity id; |
112 | 110 | ||
113 | /* Was this peer already added to the current problem? */ | 111 | /* Was this peer already added to the current problem? */ |
@@ -123,8 +121,7 @@ struct ATS_Peer | |||
123 | double f; | 121 | double f; |
124 | }; | 122 | }; |
125 | 123 | ||
126 | struct MLP_Problem | 124 | struct MLP_Problem { |
127 | { | ||
128 | /** | 125 | /** |
129 | * GLPK (MLP) problem object | 126 | * GLPK (MLP) problem object |
130 | */ | 127 | */ |
@@ -170,11 +167,9 @@ struct MLP_Problem | |||
170 | int *ja; | 167 | int *ja; |
171 | /* Column index value */ | 168 | /* Column index value */ |
172 | double *ar; | 169 | double *ar; |
173 | |||
174 | }; | 170 | }; |
175 | 171 | ||
176 | struct MLP_Variables | 172 | struct MLP_Variables { |
177 | { | ||
178 | /* Big M value for bandwidth capping */ | 173 | /* Big M value for bandwidth capping */ |
179 | double BIG_M; | 174 | double BIG_M; |
180 | 175 | ||
@@ -225,14 +220,12 @@ struct MLP_Variables | |||
225 | * contains mapping to GNUNET_ATS_Property | 220 | * contains mapping to GNUNET_ATS_Property |
226 | * */ | 221 | * */ |
227 | int rc[RQ_QUALITY_METRIC_COUNT]; | 222 | int rc[RQ_QUALITY_METRIC_COUNT]; |
228 | |||
229 | }; | 223 | }; |
230 | 224 | ||
231 | /** | 225 | /** |
232 | * MLP Handle | 226 | * MLP Handle |
233 | */ | 227 | */ |
234 | struct GAS_MLP_Handle | 228 | struct GAS_MLP_Handle { |
235 | { | ||
236 | struct GNUNET_ATS_PluginEnvironment *env; | 229 | struct GNUNET_ATS_PluginEnvironment *env; |
237 | 230 | ||
238 | /** | 231 | /** |
@@ -367,9 +360,7 @@ struct GAS_MLP_Handle | |||
367 | /** | 360 | /** |
368 | * Address specific MLP information | 361 | * Address specific MLP information |
369 | */ | 362 | */ |
370 | struct MLP_information | 363 | struct MLP_information { |
371 | { | ||
372 | |||
373 | /** | 364 | /** |
374 | * Bandwidth assigned outbound | 365 | * Bandwidth assigned outbound |
375 | */ | 366 | */ |
@@ -512,7 +503,7 @@ struct MLP_information | |||
512 | 503 | ||
513 | */ | 504 | */ |
514 | 505 | ||
515 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-mlp",__VA_ARGS__) | 506 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-mlp", __VA_ARGS__) |
516 | 507 | ||
517 | /** | 508 | /** |
518 | * Print debug output for mlp problem creation | 509 | * Print debug output for mlp problem creation |
@@ -527,12 +518,12 @@ struct MLP_information | |||
527 | * @return 0: glpk prints output on terminal, 0 != surpress output | 518 | * @return 0: glpk prints output on terminal, 0 != surpress output |
528 | */ | 519 | */ |
529 | static int | 520 | static int |
530 | mlp_term_hook (void *info, const char *s) | 521 | mlp_term_hook(void *info, const char *s) |
531 | { | 522 | { |
532 | struct GAS_MLP_Handle *mlp = info; | 523 | struct GAS_MLP_Handle *mlp = info; |
533 | 524 | ||
534 | if (mlp->opt_dbg_glpk_verbose) | 525 | if (mlp->opt_dbg_glpk_verbose) |
535 | LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s); | 526 | LOG(GNUNET_ERROR_TYPE_ERROR, "%s", s); |
536 | return 1; | 527 | return 1; |
537 | } | 528 | } |
538 | 529 | ||
@@ -546,14 +537,15 @@ mlp_term_hook (void *info, const char *s) | |||
546 | * @return #GNUNET_OK | 537 | * @return #GNUNET_OK |
547 | */ | 538 | */ |
548 | static int | 539 | static int |
549 | reset_peers (void *cls, | 540 | reset_peers(void *cls, |
550 | const struct GNUNET_PeerIdentity *key, | 541 | const struct GNUNET_PeerIdentity *key, |
551 | void *value) | 542 | void *value) |
552 | { | 543 | { |
553 | struct ATS_Peer *peer = value; | 544 | struct ATS_Peer *peer = value; |
554 | peer->processed = GNUNET_NO; | 545 | |
555 | return GNUNET_OK; | 546 | peer->processed = GNUNET_NO; |
556 | } | 547 | return GNUNET_OK; |
548 | } | ||
557 | 549 | ||
558 | /** | 550 | /** |
559 | * Delete the MLP problem and free the constrain matrix | 551 | * Delete the MLP problem and free the constrain matrix |
@@ -561,37 +553,38 @@ reset_peers (void *cls, | |||
561 | * @param mlp the MLP handle | 553 | * @param mlp the MLP handle |
562 | */ | 554 | */ |
563 | static void | 555 | static void |
564 | mlp_delete_problem (struct GAS_MLP_Handle *mlp) | 556 | mlp_delete_problem(struct GAS_MLP_Handle *mlp) |
565 | { | 557 | { |
566 | int c; | 558 | int c; |
559 | |||
567 | if (mlp == NULL) | 560 | if (mlp == NULL) |
568 | return; | 561 | return; |
569 | if (mlp->p.prob != NULL) | 562 | if (mlp->p.prob != NULL) |
570 | { | 563 | { |
571 | glp_delete_prob(mlp->p.prob); | 564 | glp_delete_prob(mlp->p.prob); |
572 | mlp->p.prob = NULL; | 565 | mlp->p.prob = NULL; |
573 | } | 566 | } |
574 | 567 | ||
575 | /* delete row index */ | 568 | /* delete row index */ |
576 | if (mlp->p.ia != NULL) | 569 | if (mlp->p.ia != NULL) |
577 | { | 570 | { |
578 | GNUNET_free (mlp->p.ia); | 571 | GNUNET_free(mlp->p.ia); |
579 | mlp->p.ia = NULL; | 572 | mlp->p.ia = NULL; |
580 | } | 573 | } |
581 | 574 | ||
582 | /* delete column index */ | 575 | /* delete column index */ |
583 | if (mlp->p.ja != NULL) | 576 | if (mlp->p.ja != NULL) |
584 | { | 577 | { |
585 | GNUNET_free (mlp->p.ja); | 578 | GNUNET_free(mlp->p.ja); |
586 | mlp->p.ja = NULL; | 579 | mlp->p.ja = NULL; |
587 | } | 580 | } |
588 | 581 | ||
589 | /* delete coefficients */ | 582 | /* delete coefficients */ |
590 | if (mlp->p.ar != NULL) | 583 | if (mlp->p.ar != NULL) |
591 | { | 584 | { |
592 | GNUNET_free (mlp->p.ar); | 585 | GNUNET_free(mlp->p.ar); |
593 | mlp->p.ar = NULL; | 586 | mlp->p.ar = NULL; |
594 | } | 587 | } |
595 | mlp->p.ci = 0; | 588 | mlp->p.ci = 0; |
596 | mlp->p.prob = NULL; | 589 | mlp->p.prob = NULL; |
597 | 590 | ||
@@ -601,15 +594,15 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
601 | mlp->p.r_c4 = MLP_UNDEFINED; | 594 | mlp->p.r_c4 = MLP_UNDEFINED; |
602 | mlp->p.r_c6 = MLP_UNDEFINED; | 595 | mlp->p.r_c6 = MLP_UNDEFINED; |
603 | mlp->p.r_c9 = MLP_UNDEFINED; | 596 | mlp->p.r_c9 = MLP_UNDEFINED; |
604 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT ; c ++) | 597 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) |
605 | mlp->p.r_q[c] = MLP_UNDEFINED; | 598 | mlp->p.r_q[c] = MLP_UNDEFINED; |
606 | for (c = 0; c < GNUNET_NT_COUNT; c ++) | 599 | for (c = 0; c < GNUNET_NT_COUNT; c++) |
607 | mlp->p.r_quota[c] = MLP_UNDEFINED; | 600 | mlp->p.r_quota[c] = MLP_UNDEFINED; |
608 | mlp->p.ci = MLP_UNDEFINED; | 601 | mlp->p.ci = MLP_UNDEFINED; |
609 | 602 | ||
610 | 603 | ||
611 | GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, | 604 | GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers, |
612 | &reset_peers, NULL); | 605 | &reset_peers, NULL); |
613 | } | 606 | } |
614 | 607 | ||
615 | 608 | ||
@@ -619,25 +612,32 @@ mlp_delete_problem (struct GAS_MLP_Handle *mlp) | |||
619 | * @return string with result | 612 | * @return string with result |
620 | */ | 613 | */ |
621 | static const char * | 614 | static const char * |
622 | mlp_status_to_string (int retcode) | 615 | mlp_status_to_string(int retcode) |
623 | { | 616 | { |
624 | switch (retcode) { | 617 | switch (retcode) |
618 | { | ||
625 | case GLP_UNDEF: | 619 | case GLP_UNDEF: |
626 | return "solution is undefined"; | 620 | return "solution is undefined"; |
621 | |||
627 | case GLP_FEAS: | 622 | case GLP_FEAS: |
628 | return "solution is feasible"; | 623 | return "solution is feasible"; |
624 | |||
629 | case GLP_INFEAS: | 625 | case GLP_INFEAS: |
630 | return "solution is infeasible"; | 626 | return "solution is infeasible"; |
627 | |||
631 | case GLP_NOFEAS: | 628 | case GLP_NOFEAS: |
632 | return "no feasible solution exists"; | 629 | return "no feasible solution exists"; |
630 | |||
633 | case GLP_OPT: | 631 | case GLP_OPT: |
634 | return "solution is optimal"; | 632 | return "solution is optimal"; |
633 | |||
635 | case GLP_UNBND: | 634 | case GLP_UNBND: |
636 | return "solution is unbounded"; | 635 | return "solution is unbounded"; |
636 | |||
637 | default: | 637 | default: |
638 | GNUNET_break (0); | 638 | GNUNET_break(0); |
639 | return "unknown error"; | 639 | return "unknown error"; |
640 | } | 640 | } |
641 | } | 641 | } |
642 | 642 | ||
643 | 643 | ||
@@ -647,114 +647,134 @@ mlp_status_to_string (int retcode) | |||
647 | * @return string with result | 647 | * @return string with result |
648 | */ | 648 | */ |
649 | static const char * | 649 | static const char * |
650 | mlp_solve_to_string (int retcode) | 650 | mlp_solve_to_string(int retcode) |
651 | { | 651 | { |
652 | switch (retcode) { | 652 | switch (retcode) |
653 | { | ||
653 | case 0: | 654 | case 0: |
654 | return "ok"; | 655 | return "ok"; |
656 | |||
655 | case GLP_EBADB: | 657 | case GLP_EBADB: |
656 | return "invalid basis"; | 658 | return "invalid basis"; |
659 | |||
657 | case GLP_ESING: | 660 | case GLP_ESING: |
658 | return "singular matrix"; | 661 | return "singular matrix"; |
662 | |||
659 | case GLP_ECOND: | 663 | case GLP_ECOND: |
660 | return "ill-conditioned matrix"; | 664 | return "ill-conditioned matrix"; |
665 | |||
661 | case GLP_EBOUND: | 666 | case GLP_EBOUND: |
662 | return "invalid bounds"; | 667 | return "invalid bounds"; |
668 | |||
663 | case GLP_EFAIL: | 669 | case GLP_EFAIL: |
664 | return "solver failed"; | 670 | return "solver failed"; |
671 | |||
665 | case GLP_EOBJLL: | 672 | case GLP_EOBJLL: |
666 | return "objective lower limit reached"; | 673 | return "objective lower limit reached"; |
674 | |||
667 | case GLP_EOBJUL: | 675 | case GLP_EOBJUL: |
668 | return "objective upper limit reached"; | 676 | return "objective upper limit reached"; |
677 | |||
669 | case GLP_EITLIM: | 678 | case GLP_EITLIM: |
670 | return "iteration limit exceeded"; | 679 | return "iteration limit exceeded"; |
680 | |||
671 | case GLP_ETMLIM: | 681 | case GLP_ETMLIM: |
672 | return "time limit exceeded"; | 682 | return "time limit exceeded"; |
683 | |||
673 | case GLP_ENOPFS: | 684 | case GLP_ENOPFS: |
674 | return "no primal feasible solution"; | 685 | return "no primal feasible solution"; |
686 | |||
675 | case GLP_ENODFS: | 687 | case GLP_ENODFS: |
676 | return "no dual feasible solution"; | 688 | return "no dual feasible solution"; |
689 | |||
677 | case GLP_EROOT: | 690 | case GLP_EROOT: |
678 | return "root LP optimum not provided"; | 691 | return "root LP optimum not provided"; |
692 | |||
679 | case GLP_ESTOP: | 693 | case GLP_ESTOP: |
680 | return "search terminated by application"; | 694 | return "search terminated by application"; |
695 | |||
681 | case GLP_EMIPGAP: | 696 | case GLP_EMIPGAP: |
682 | return "relative mip gap tolerance reached"; | 697 | return "relative mip gap tolerance reached"; |
698 | |||
683 | case GLP_ENOFEAS: | 699 | case GLP_ENOFEAS: |
684 | return "no dual feasible solution"; | 700 | return "no dual feasible solution"; |
701 | |||
685 | case GLP_ENOCVG: | 702 | case GLP_ENOCVG: |
686 | return "no convergence"; | 703 | return "no convergence"; |
704 | |||
687 | case GLP_EINSTAB: | 705 | case GLP_EINSTAB: |
688 | return "numerical instability"; | 706 | return "numerical instability"; |
707 | |||
689 | case GLP_EDATA: | 708 | case GLP_EDATA: |
690 | return "invalid data"; | 709 | return "invalid data"; |
710 | |||
691 | case GLP_ERANGE: | 711 | case GLP_ERANGE: |
692 | return "result out of range"; | 712 | return "result out of range"; |
713 | |||
693 | default: | 714 | default: |
694 | GNUNET_break (0); | 715 | GNUNET_break(0); |
695 | return "unknown error"; | 716 | return "unknown error"; |
696 | } | 717 | } |
697 | } | 718 | } |
698 | 719 | ||
699 | 720 | ||
700 | struct CountContext | 721 | struct CountContext { |
701 | { | ||
702 | const struct GNUNET_CONTAINER_MultiPeerMap *map; | 722 | const struct GNUNET_CONTAINER_MultiPeerMap *map; |
703 | int result; | 723 | int result; |
704 | }; | 724 | }; |
705 | 725 | ||
706 | static int | 726 | static int |
707 | mlp_create_problem_count_addresses_it (void *cls, | 727 | mlp_create_problem_count_addresses_it(void *cls, |
708 | const struct GNUNET_PeerIdentity *key, | 728 | const struct GNUNET_PeerIdentity *key, |
709 | void *value) | 729 | void *value) |
710 | { | 730 | { |
711 | struct CountContext *cctx = cls; | 731 | struct CountContext *cctx = cls; |
712 | 732 | ||
713 | /* Check if we have to add this peer due to a pending request */ | 733 | /* Check if we have to add this peer due to a pending request */ |
714 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key)) | 734 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key)) |
715 | cctx->result++; | 735 | cctx->result++; |
716 | return GNUNET_OK; | 736 | return GNUNET_OK; |
717 | } | 737 | } |
718 | 738 | ||
719 | 739 | ||
720 | static int | 740 | static int |
721 | mlp_create_problem_count_addresses (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, | 741 | mlp_create_problem_count_addresses(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, |
722 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses) | 742 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses) |
723 | { | 743 | { |
724 | struct CountContext cctx; | 744 | struct CountContext cctx; |
725 | 745 | ||
726 | cctx.map = requested_peers; | 746 | cctx.map = requested_peers; |
727 | cctx.result = 0; | 747 | cctx.result = 0; |
728 | GNUNET_CONTAINER_multipeermap_iterate (addresses, | 748 | GNUNET_CONTAINER_multipeermap_iterate(addresses, |
729 | &mlp_create_problem_count_addresses_it, &cctx); | 749 | &mlp_create_problem_count_addresses_it, &cctx); |
730 | return cctx.result; | 750 | return cctx.result; |
731 | } | 751 | } |
732 | 752 | ||
733 | 753 | ||
734 | static int | 754 | static int |
735 | mlp_create_problem_count_peers_it (void *cls, | 755 | mlp_create_problem_count_peers_it(void *cls, |
736 | const struct GNUNET_PeerIdentity *key, | 756 | const struct GNUNET_PeerIdentity *key, |
737 | void *value) | 757 | void *value) |
738 | { | 758 | { |
739 | struct CountContext *cctx = cls; | 759 | struct CountContext *cctx = cls; |
740 | 760 | ||
741 | /* Check if we have to addresses for the requested peer */ | 761 | /* Check if we have to addresses for the requested peer */ |
742 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key)) | 762 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key)) |
743 | cctx->result++; | 763 | cctx->result++; |
744 | return GNUNET_OK; | 764 | return GNUNET_OK; |
745 | } | 765 | } |
746 | 766 | ||
747 | 767 | ||
748 | static int | 768 | static int |
749 | mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, | 769 | mlp_create_problem_count_peers(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, |
750 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses) | 770 | const struct GNUNET_CONTAINER_MultiPeerMap *addresses) |
751 | { | 771 | { |
752 | struct CountContext cctx; | 772 | struct CountContext cctx; |
753 | 773 | ||
754 | cctx.map = addresses; | 774 | cctx.map = addresses; |
755 | cctx.result = 0; | 775 | cctx.result = 0; |
756 | GNUNET_CONTAINER_multipeermap_iterate (requested_peers, | 776 | GNUNET_CONTAINER_multipeermap_iterate(requested_peers, |
757 | &mlp_create_problem_count_peers_it, &cctx); | 777 | &mlp_create_problem_count_peers_it, &cctx); |
758 | return cctx.result; | 778 | return cctx.result; |
759 | } | 779 | } |
760 | 780 | ||
@@ -773,9 +793,9 @@ mlp_create_problem_count_peers (const struct GNUNET_CONTAINER_MultiPeerMap *requ | |||
773 | * on error | 793 | * on error |
774 | */ | 794 | */ |
775 | static int | 795 | static int |
776 | mlp_create_problem_update_value (struct MLP_Problem *p, | 796 | mlp_create_problem_update_value(struct MLP_Problem *p, |
777 | int row, int col, double val, | 797 | int row, int col, double val, |
778 | int line) | 798 | int line) |
779 | { | 799 | { |
780 | int c_cols; | 800 | int c_cols; |
781 | int c_elems; | 801 | int c_elems; |
@@ -785,59 +805,59 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
785 | double *val_array; | 805 | double *val_array; |
786 | int *ind_array; | 806 | int *ind_array; |
787 | 807 | ||
788 | GNUNET_assert (NULL != p->prob); | 808 | GNUNET_assert(NULL != p->prob); |
789 | 809 | ||
790 | /* Get number of columns and prepare data structure */ | 810 | /* Get number of columns and prepare data structure */ |
791 | c_cols = glp_get_num_cols(p->prob); | 811 | c_cols = glp_get_num_cols(p->prob); |
792 | if (0 >= c_cols) | 812 | if (0 >= c_cols) |
793 | return GNUNET_SYSERR; | 813 | return GNUNET_SYSERR; |
794 | 814 | ||
795 | val_array = GNUNET_malloc ((c_cols +1)* sizeof (double)); | 815 | val_array = GNUNET_malloc((c_cols + 1) * sizeof(double)); |
796 | GNUNET_assert (NULL != val_array); | 816 | GNUNET_assert(NULL != val_array); |
797 | ind_array = GNUNET_malloc ((c_cols+1) * sizeof (int)); | 817 | ind_array = GNUNET_malloc((c_cols + 1) * sizeof(int)); |
798 | GNUNET_assert (NULL != ind_array); | 818 | GNUNET_assert(NULL != ind_array); |
799 | /* Extract the row */ | 819 | /* Extract the row */ |
800 | 820 | ||
801 | /* Update the value */ | 821 | /* Update the value */ |
802 | c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array); | 822 | c_elems = glp_get_mat_row(p->prob, row, ind_array, val_array); |
803 | found = GNUNET_NO; | 823 | found = GNUNET_NO; |
804 | for (c1 = 1; c1 < (c_elems+1); c1++) | 824 | for (c1 = 1; c1 < (c_elems + 1); c1++) |
805 | { | ||
806 | if (ind_array[c1] == col) | ||
807 | { | 825 | { |
808 | found = GNUNET_YES; | 826 | if (ind_array[c1] == col) |
809 | break; | 827 | { |
828 | found = GNUNET_YES; | ||
829 | break; | ||
830 | } | ||
810 | } | 831 | } |
811 | } | ||
812 | if (GNUNET_NO == found) | 832 | if (GNUNET_NO == found) |
813 | { | 833 | { |
814 | ind_array[c_elems+1] = col; | 834 | ind_array[c_elems + 1] = col; |
815 | val_array[c_elems+1] = val; | 835 | val_array[c_elems + 1] = val; |
816 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n", | 836 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n", |
817 | glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col), | 837 | glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col), |
818 | val); | 838 | val); |
819 | glp_set_mat_row (p->prob, row, c_elems+1, ind_array, val_array); | 839 | glp_set_mat_row(p->prob, row, c_elems + 1, ind_array, val_array); |
820 | GNUNET_free (ind_array); | 840 | GNUNET_free(ind_array); |
821 | GNUNET_free (val_array); | 841 | GNUNET_free(val_array); |
822 | return GNUNET_YES; | 842 | return GNUNET_YES; |
823 | } | 843 | } |
824 | else | 844 | else |
825 | { | 845 | { |
826 | /* Update value */ | 846 | /* Update value */ |
827 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n", | 847 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n", |
828 | glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col), | 848 | glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col), |
829 | val_array[c1], val); | 849 | val_array[c1], val); |
830 | if (val != val_array[c1]) | 850 | if (val != val_array[c1]) |
831 | res = GNUNET_YES; | 851 | res = GNUNET_YES; |
832 | else | 852 | else |
833 | res = GNUNET_NO; | 853 | res = GNUNET_NO; |
834 | val_array[c1] = val; | 854 | val_array[c1] = val; |
835 | /* Update the row in the matrix */ | 855 | /* Update the row in the matrix */ |
836 | glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array); | 856 | glp_set_mat_row(p->prob, row, c_elems, ind_array, val_array); |
837 | } | 857 | } |
838 | 858 | ||
839 | GNUNET_free (ind_array); | 859 | GNUNET_free(ind_array); |
840 | GNUNET_free (val_array); | 860 | GNUNET_free(val_array); |
841 | return res; | 861 | return res; |
842 | } | 862 | } |
843 | 863 | ||
@@ -854,83 +874,89 @@ mlp_create_problem_update_value (struct MLP_Problem *p, | |||
854 | * @param line calling line for debbuging | 874 | * @param line calling line for debbuging |
855 | */ | 875 | */ |
856 | static void | 876 | static void |
857 | mlp_create_problem_set_value (struct MLP_Problem *p, | 877 | mlp_create_problem_set_value(struct MLP_Problem *p, |
858 | int row, int col, double val, | 878 | int row, int col, double val, |
859 | int line) | 879 | int line) |
860 | { | 880 | { |
861 | if ((p->ci) >= p->num_elements) | 881 | if ((p->ci) >= p->num_elements) |
862 | { | 882 | { |
863 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n", | 883 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n", |
864 | line, p->ci + 1, p->num_elements); | 884 | line, p->ci + 1, p->num_elements); |
865 | GNUNET_break (0); | 885 | GNUNET_break(0); |
866 | return; | 886 | return; |
867 | } | 887 | } |
868 | if ((0 == row) || (0 == col)) | 888 | if ((0 == row) || (0 == col)) |
869 | { | 889 | { |
870 | GNUNET_break (0); | 890 | GNUNET_break(0); |
871 | LOG (GNUNET_ERROR_TYPE_ERROR, "[P]: Invalid call from line %u: row = %u, col = %u\n", | 891 | LOG(GNUNET_ERROR_TYPE_ERROR, "[P]: Invalid call from line %u: row = %u, col = %u\n", |
872 | line, row, col); | 892 | line, row, col); |
873 | } | 893 | } |
874 | p->ia[p->ci] = row ; | 894 | p->ia[p->ci] = row; |
875 | p->ja[p->ci] = col; | 895 | p->ja[p->ci] = col; |
876 | p->ar[p->ci] = val; | 896 | p->ar[p->ci] = val; |
877 | #if DEBUG_MLP_PROBLEM_CREATION | 897 | #if DEBUG_MLP_PROBLEM_CREATION |
878 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n", | 898 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n", |
879 | line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]); | 899 | line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]); |
880 | #endif | 900 | #endif |
881 | p->ci++; | 901 | p->ci++; |
882 | } | 902 | } |
883 | 903 | ||
884 | static int | 904 | static int |
885 | mlp_create_problem_create_column (struct MLP_Problem *p, char *name, | 905 | mlp_create_problem_create_column(struct MLP_Problem *p, char *name, |
886 | unsigned int type, unsigned int bound, double lb, double ub, | 906 | unsigned int type, unsigned int bound, double lb, double ub, |
887 | double coef) | 907 | double coef) |
888 | { | 908 | { |
889 | int col = glp_add_cols (p->prob, 1); | 909 | int col = glp_add_cols(p->prob, 1); |
890 | glp_set_col_name (p->prob, col, name); | 910 | |
891 | glp_set_col_bnds (p->prob, col, bound, lb, ub); | 911 | glp_set_col_name(p->prob, col, name); |
892 | glp_set_col_kind (p->prob, col, type); | 912 | glp_set_col_bnds(p->prob, col, bound, lb, ub); |
893 | glp_set_obj_coef (p->prob, col, coef); | 913 | glp_set_col_kind(p->prob, col, type); |
914 | glp_set_obj_coef(p->prob, col, coef); | ||
894 | #if DEBUG_MLP_PROBLEM_CREATION | 915 | #if DEBUG_MLP_PROBLEM_CREATION |
895 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n", | 916 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n", |
896 | col, name, coef); | 917 | col, name, coef); |
897 | #endif | 918 | #endif |
898 | return col; | 919 | return col; |
899 | } | 920 | } |
900 | 921 | ||
901 | static int | 922 | static int |
902 | mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name, | 923 | mlp_create_problem_create_constraint(struct MLP_Problem *p, char *name, |
903 | unsigned int bound, double lb, double ub) | 924 | unsigned int bound, double lb, double ub) |
904 | { | 925 | { |
905 | char * op; | 926 | char * op; |
906 | int row = glp_add_rows (p->prob, 1); | 927 | int row = glp_add_rows(p->prob, 1); |
928 | |||
907 | /* set row name */ | 929 | /* set row name */ |
908 | glp_set_row_name (p->prob, row, name); | 930 | glp_set_row_name(p->prob, row, name); |
909 | /* set row bounds: <= 0 */ | 931 | /* set row bounds: <= 0 */ |
910 | glp_set_row_bnds (p->prob, row, bound, lb, ub); | 932 | glp_set_row_bnds(p->prob, row, bound, lb, ub); |
911 | switch (bound) | 933 | switch (bound) |
912 | { | 934 | { |
913 | case GLP_UP: | 935 | case GLP_UP: |
914 | GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub); | 936 | GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub); |
915 | break; | 937 | break; |
938 | |||
916 | case GLP_DB: | 939 | case GLP_DB: |
917 | GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub); | 940 | GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub); |
918 | break; | 941 | break; |
942 | |||
919 | case GLP_FX: | 943 | case GLP_FX: |
920 | GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub); | 944 | GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub); |
921 | break; | 945 | break; |
946 | |||
922 | case GLP_LO: | 947 | case GLP_LO: |
923 | GNUNET_asprintf(&op, "%.2f <= x <= inf", lb); | 948 | GNUNET_asprintf(&op, "%.2f <= x <= inf", lb); |
924 | break; | 949 | break; |
950 | |||
925 | default: | 951 | default: |
926 | GNUNET_asprintf(&op, "ERROR"); | 952 | GNUNET_asprintf(&op, "ERROR"); |
927 | break; | 953 | break; |
928 | } | 954 | } |
929 | #if DEBUG_MLP_PROBLEM_CREATION | 955 | #if DEBUG_MLP_PROBLEM_CREATION |
930 | LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n", | 956 | LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n", |
931 | row, name, op); | 957 | row, name, op); |
932 | #endif | 958 | #endif |
933 | GNUNET_free (op); | 959 | GNUNET_free(op); |
934 | return row; | 960 | return row; |
935 | } | 961 | } |
936 | 962 | ||
@@ -942,9 +968,9 @@ mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name, | |||
942 | * - Set address dependent entries in problem matrix as well | 968 | * - Set address dependent entries in problem matrix as well |
943 | */ | 969 | */ |
944 | static int | 970 | static int |
945 | mlp_create_problem_add_address_information (void *cls, | 971 | mlp_create_problem_add_address_information(void *cls, |
946 | const struct GNUNET_PeerIdentity *key, | 972 | const struct GNUNET_PeerIdentity *key, |
947 | void *value) | 973 | void *value) |
948 | { | 974 | { |
949 | struct GAS_MLP_Handle *mlp = cls; | 975 | struct GAS_MLP_Handle *mlp = cls; |
950 | struct MLP_Problem *p = &mlp->p; | 976 | struct MLP_Problem *p = &mlp->p; |
@@ -964,63 +990,63 @@ mlp_create_problem_add_address_information (void *cls, | |||
964 | 990 | ||
965 | mlpi = address->solver_information; | 991 | mlpi = address->solver_information; |
966 | if (NULL == mlpi) | 992 | if (NULL == mlpi) |
967 | { | 993 | { |
968 | fprintf (stderr, "%s %p\n",GNUNET_i2s (&address->peer), address); | 994 | fprintf(stderr, "%s %p\n", GNUNET_i2s(&address->peer), address); |
969 | GNUNET_break (0); | 995 | GNUNET_break(0); |
970 | return GNUNET_OK; | 996 | return GNUNET_OK; |
971 | } | 997 | } |
972 | 998 | ||
973 | addr_net = address->properties.scope; | 999 | addr_net = address->properties.scope; |
974 | for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++) | 1000 | for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++) |
975 | { | 1001 | { |
976 | if (mlp->pv.quota_index[addr_net_index] == addr_net) | 1002 | if (mlp->pv.quota_index[addr_net_index] == addr_net) |
977 | break; | 1003 | break; |
978 | } | 1004 | } |
979 | 1005 | ||
980 | if (addr_net_index >= GNUNET_NT_COUNT) | 1006 | if (addr_net_index >= GNUNET_NT_COUNT) |
981 | { | 1007 | { |
982 | GNUNET_break (0); | 1008 | GNUNET_break(0); |
983 | return GNUNET_OK; | 1009 | return GNUNET_OK; |
984 | } | 1010 | } |
985 | 1011 | ||
986 | max_quota = 0; | 1012 | max_quota = 0; |
987 | for (c = 0; c < GNUNET_NT_COUNT; c++) | 1013 | for (c = 0; c < GNUNET_NT_COUNT; c++) |
988 | { | 1014 | { |
989 | if (mlp->pv.quota_out[c] > max_quota) | 1015 | if (mlp->pv.quota_out[c] > max_quota) |
990 | max_quota = mlp->pv.quota_out[c]; | 1016 | max_quota = mlp->pv.quota_out[c]; |
991 | if (mlp->pv.quota_in[c] > max_quota) | 1017 | if (mlp->pv.quota_in[c] > max_quota) |
992 | max_quota = mlp->pv.quota_in[c]; | 1018 | max_quota = mlp->pv.quota_in[c]; |
993 | } | 1019 | } |
994 | if (max_quota > mlp->pv.BIG_M) | 1020 | if (max_quota > mlp->pv.BIG_M) |
995 | cur_bigm = (double) mlp->pv.BIG_M; | 1021 | cur_bigm = (double)mlp->pv.BIG_M; |
996 | else | 1022 | else |
997 | cur_bigm = max_quota; | 1023 | cur_bigm = max_quota; |
998 | 1024 | ||
999 | 1025 | ||
1000 | /* Get peer */ | 1026 | /* Get peer */ |
1001 | peer = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, key); | 1027 | peer = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, key); |
1002 | GNUNET_assert (NULL != peer); | 1028 | GNUNET_assert(NULL != peer); |
1003 | if (peer->processed == GNUNET_NO) | 1029 | if (peer->processed == GNUNET_NO) |
1004 | { | 1030 | { |
1005 | /* Add peer dependent constraints */ | 1031 | /* Add peer dependent constraints */ |
1006 | /* Add c2) One address active per peer */ | 1032 | /* Add c2) One address active per peer */ |
1007 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer)); | 1033 | GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer)); |
1008 | peer->r_c2 = mlp_create_problem_create_constraint (p, name, GLP_FX, 1.0, 1.0); | 1034 | peer->r_c2 = mlp_create_problem_create_constraint(p, name, GLP_FX, 1.0, 1.0); |
1009 | GNUNET_free (name); | 1035 | GNUNET_free(name); |
1010 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 1036 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
1011 | { | ||
1012 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) | ||
1013 | { | 1037 | { |
1014 | /* Add c9) Relativity */ | 1038 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) |
1015 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer)); | 1039 | { |
1016 | peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); | 1040 | /* Add c9) Relativity */ |
1017 | GNUNET_free (name); | 1041 | GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer)); |
1018 | /* c9) set coefficient */ | 1042 | peer->r_c9 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0); |
1019 | mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f , __LINE__); | 1043 | GNUNET_free(name); |
1044 | /* c9) set coefficient */ | ||
1045 | mlp_create_problem_set_value(p, peer->r_c9, p->c_r, -peer->f, __LINE__); | ||
1046 | } | ||
1020 | } | 1047 | } |
1021 | } | ||
1022 | peer->processed = GNUNET_YES; | 1048 | peer->processed = GNUNET_YES; |
1023 | } | 1049 | } |
1024 | 1050 | ||
1025 | /* Reset addresses' solver information */ | 1051 | /* Reset addresses' solver information */ |
1026 | mlpi->c_b = 0; | 1052 | mlpi->c_b = 0; |
@@ -1030,47 +1056,47 @@ mlp_create_problem_add_address_information (void *cls, | |||
1030 | mlpi->r_c3 = 0; | 1056 | mlpi->r_c3 = 0; |
1031 | 1057 | ||
1032 | /* Add bandwidth column */ | 1058 | /* Add bandwidth column */ |
1033 | GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); | 1059 | GNUNET_asprintf(&name, "b_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); |
1034 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 1060 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
1035 | { | 1061 | { |
1036 | mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0); | 1062 | mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0); |
1037 | } | 1063 | } |
1038 | else | 1064 | else |
1039 | { | 1065 | { |
1040 | /* Maximize for bandwidth assignment in feasibility testing */ | 1066 | /* Maximize for bandwidth assignment in feasibility testing */ |
1041 | mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0); | 1067 | mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0); |
1042 | } | 1068 | } |
1043 | GNUNET_free (name); | 1069 | GNUNET_free(name); |
1044 | 1070 | ||
1045 | /* Add address active column */ | 1071 | /* Add address active column */ |
1046 | GNUNET_asprintf (&name, "n_%s_%s_%p", GNUNET_i2s (&address->peer), address->plugin, address); | 1072 | GNUNET_asprintf(&name, "n_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); |
1047 | mlpi->c_n = mlp_create_problem_create_column (p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0); | 1073 | mlpi->c_n = mlp_create_problem_create_column(p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0); |
1048 | GNUNET_free (name); | 1074 | GNUNET_free(name); |
1049 | 1075 | ||
1050 | /* Add address dependent constraints */ | 1076 | /* Add address dependent constraints */ |
1051 | /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */ | 1077 | /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */ |
1052 | GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); | 1078 | GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); |
1053 | mlpi->r_c1 = mlp_create_problem_create_constraint (p, name, GLP_UP, 0.0, 0.0); | 1079 | mlpi->r_c1 = mlp_create_problem_create_constraint(p, name, GLP_UP, 0.0, 0.0); |
1054 | GNUNET_free (name); | 1080 | GNUNET_free(name); |
1055 | /* c1) set b = 1 coefficient */ | 1081 | /* c1) set b = 1 coefficient */ |
1056 | mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1, __LINE__); | 1082 | mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_b, 1, __LINE__); |
1057 | /* c1) set n = - min (M, quota) coefficient */ | 1083 | /* c1) set n = - min (M, quota) coefficient */ |
1058 | cur_bigm = (double) mlp->pv.quota_out[addr_net_index]; | 1084 | cur_bigm = (double)mlp->pv.quota_out[addr_net_index]; |
1059 | if (cur_bigm > mlp->pv.BIG_M) | 1085 | if (cur_bigm > mlp->pv.BIG_M) |
1060 | cur_bigm = (double) mlp->pv.BIG_M; | 1086 | cur_bigm = (double)mlp->pv.BIG_M; |
1061 | mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__); | 1087 | mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__); |
1062 | 1088 | ||
1063 | /* Add constraint c 3) minimum bandwidth | 1089 | /* Add constraint c 3) minimum bandwidth |
1064 | * b_t + (-n_t * b_min) >= 0 | 1090 | * b_t + (-n_t * b_min) >= 0 |
1065 | * */ | 1091 | * */ |
1066 | GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); | 1092 | GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); |
1067 | mlpi->r_c3 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0); | 1093 | mlpi->r_c3 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0); |
1068 | GNUNET_free (name); | 1094 | GNUNET_free(name); |
1069 | 1095 | ||
1070 | /* c3) set b = 1 coefficient */ | 1096 | /* c3) set b = 1 coefficient */ |
1071 | mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1, __LINE__); | 1097 | mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_b, 1, __LINE__); |
1072 | /* c3) set n = -b_min coefficient */ | 1098 | /* c3) set n = -b_min coefficient */ |
1073 | mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n, - ((double )mlp->pv.b_min), __LINE__); | 1099 | mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_n, -((double )mlp->pv.b_min), __LINE__); |
1074 | 1100 | ||
1075 | 1101 | ||
1076 | /* Set coefficient entries in invariant rows */ | 1102 | /* Set coefficient entries in invariant rows */ |
@@ -1078,41 +1104,41 @@ mlp_create_problem_add_address_information (void *cls, | |||
1078 | /* Feasbility */ | 1104 | /* Feasbility */ |
1079 | 1105 | ||
1080 | /* c 4) minimum connections */ | 1106 | /* c 4) minimum connections */ |
1081 | mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1, __LINE__); | 1107 | mlp_create_problem_set_value(p, p->r_c4, mlpi->c_n, 1, __LINE__); |
1082 | /* c 2) 1 address peer peer */ | 1108 | /* c 2) 1 address peer peer */ |
1083 | mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1, __LINE__); | 1109 | mlp_create_problem_set_value(p, peer->r_c2, mlpi->c_n, 1, __LINE__); |
1084 | /* c 10) obey network specific quotas | 1110 | /* c 10) obey network specific quotas |
1085 | * (1)*b_1 + ... + (1)*b_m <= quota_n | 1111 | * (1)*b_1 + ... + (1)*b_m <= quota_n |
1086 | */ | 1112 | */ |
1087 | mlp_create_problem_set_value (p, p->r_quota[addr_net_index], mlpi->c_b, 1, __LINE__); | 1113 | mlp_create_problem_set_value(p, p->r_quota[addr_net_index], mlpi->c_b, 1, __LINE__); |
1088 | 1114 | ||
1089 | /* Optimality */ | 1115 | /* Optimality */ |
1090 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 1116 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
1091 | { | 1117 | { |
1092 | /* c 6) maximize diversity */ | 1118 | /* c 6) maximize diversity */ |
1093 | mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1, __LINE__); | 1119 | mlp_create_problem_set_value(p, p->r_c6, mlpi->c_n, 1, __LINE__); |
1094 | /* c 9) relativity */ | 1120 | /* c 9) relativity */ |
1095 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) | 1121 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) |
1096 | mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1, __LINE__); | 1122 | mlp_create_problem_set_value(p, peer->r_c9, mlpi->c_b, 1, __LINE__); |
1097 | /* c 8) utility */ | 1123 | /* c 8) utility */ |
1098 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) | 1124 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) |
1099 | mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1, __LINE__); | 1125 | mlp_create_problem_set_value(p, p->r_c8, mlpi->c_b, 1, __LINE__); |
1100 | /* c 7) Optimize quality */ | 1126 | /* c 7) Optimize quality */ |
1101 | /* For all quality metrics, set quality of this address */ | 1127 | /* For all quality metrics, set quality of this address */ |
1102 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) | 1128 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) |
1103 | { | 1129 | { |
1104 | mlp_create_problem_set_value (p, | 1130 | mlp_create_problem_set_value(p, |
1105 | p->r_q[RQ_QUALITY_METRIC_DELAY], | 1131 | p->r_q[RQ_QUALITY_METRIC_DELAY], |
1106 | mlpi->c_b, | 1132 | mlpi->c_b, |
1107 | address->norm_delay.norm, | 1133 | address->norm_delay.norm, |
1108 | __LINE__); | 1134 | __LINE__); |
1109 | mlp_create_problem_set_value (p, | 1135 | mlp_create_problem_set_value(p, |
1110 | p->r_q[RQ_QUALITY_METRIC_DISTANCE], | 1136 | p->r_q[RQ_QUALITY_METRIC_DISTANCE], |
1111 | mlpi->c_b, | 1137 | mlpi->c_b, |
1112 | address->norm_distance.norm, | 1138 | address->norm_distance.norm, |
1113 | __LINE__); | 1139 | __LINE__); |
1114 | } | 1140 | } |
1115 | } | 1141 | } |
1116 | 1142 | ||
1117 | return GNUNET_OK; | 1143 | return GNUNET_OK; |
1118 | } | 1144 | } |
@@ -1122,7 +1148,7 @@ mlp_create_problem_add_address_information (void *cls, | |||
1122 | * Create the invariant columns c4, c6, c10, c8, c7 | 1148 | * Create the invariant columns c4, c6, c10, c8, c7 |
1123 | */ | 1149 | */ |
1124 | static void | 1150 | static void |
1125 | mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) | 1151 | mlp_create_problem_add_invariant_rows(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) |
1126 | { | 1152 | { |
1127 | int c; | 1153 | int c; |
1128 | 1154 | ||
@@ -1130,55 +1156,55 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1130 | 1156 | ||
1131 | /* Row for c4) minimum connection */ | 1157 | /* Row for c4) minimum connection */ |
1132 | /* Number of minimum connections is min(|Peers|, n_min) */ | 1158 | /* Number of minimum connections is min(|Peers|, n_min) */ |
1133 | p->r_c4 = mlp_create_problem_create_constraint (p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0); | 1159 | p->r_c4 = mlp_create_problem_create_constraint(p, "c4", GLP_LO, (mlp->pv.n_min > p->num_peers) ? p->num_peers : mlp->pv.n_min, 0.0); |
1134 | 1160 | ||
1135 | /* Rows for c 10) Enforce network quotas */ | 1161 | /* Rows for c 10) Enforce network quotas */ |
1136 | for (c = 0; c < GNUNET_NT_COUNT; c++) | 1162 | for (c = 0; c < GNUNET_NT_COUNT; c++) |
1137 | { | 1163 | { |
1138 | char * text; | 1164 | char * text; |
1139 | GNUNET_asprintf(&text, "c10_quota_ats_%s", | 1165 | GNUNET_asprintf(&text, "c10_quota_ats_%s", |
1140 | GNUNET_NT_to_string(mlp->pv.quota_index[c])); | 1166 | GNUNET_NT_to_string(mlp->pv.quota_index[c])); |
1141 | p->r_quota[c] = mlp_create_problem_create_constraint (p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]); | 1167 | p->r_quota[c] = mlp_create_problem_create_constraint(p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]); |
1142 | GNUNET_free (text); | 1168 | GNUNET_free(text); |
1143 | } | 1169 | } |
1144 | 1170 | ||
1145 | /* Optimality */ | 1171 | /* Optimality */ |
1146 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 1172 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
1147 | { | ||
1148 | char *name; | ||
1149 | /* Add row for c6) Maximize for diversity */ | ||
1150 | if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) | ||
1151 | { | 1173 | { |
1152 | p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0, 0.0); | 1174 | char *name; |
1153 | /* Set c6 ) Setting -D */ | 1175 | /* Add row for c6) Maximize for diversity */ |
1154 | mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1, __LINE__); | 1176 | if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) |
1155 | } | 1177 | { |
1178 | p->r_c6 = mlp_create_problem_create_constraint(p, "c6", GLP_FX, 0.0, 0.0); | ||
1179 | /* Set c6 ) Setting -D */ | ||
1180 | mlp_create_problem_set_value(p, p->r_c6, p->c_d, -1, __LINE__); | ||
1181 | } | ||
1156 | 1182 | ||
1157 | /* Adding rows for c 8) Maximize utility */ | 1183 | /* Adding rows for c 8) Maximize utility */ |
1158 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) | 1184 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) |
1159 | { | 1185 | { |
1160 | p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0, 0.0); | 1186 | p->r_c8 = mlp_create_problem_create_constraint(p, "c8", GLP_FX, 0.0, 0.0); |
1161 | /* -u */ | 1187 | /* -u */ |
1162 | mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1, __LINE__); | 1188 | mlp_create_problem_set_value(p, p->r_c8, p->c_u, -1, __LINE__); |
1163 | } | 1189 | } |
1164 | 1190 | ||
1165 | /* For all quality metrics: | 1191 | /* For all quality metrics: |
1166 | * c 7) Maximize quality, austerity */ | 1192 | * c 7) Maximize quality, austerity */ |
1167 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) | 1193 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) |
1168 | { | 1194 | { |
1169 | for (c = 0; c < mlp->pv.m_q; c++) | 1195 | for (c = 0; c < mlp->pv.m_q; c++) |
1170 | { | 1196 | { |
1171 | GNUNET_asprintf (&name, | 1197 | GNUNET_asprintf(&name, |
1172 | "c7_q%i_%s", c, | 1198 | "c7_q%i_%s", c, |
1173 | print_quality_type (c)); | 1199 | print_quality_type(c)); |
1174 | p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0, 0.0); | 1200 | p->r_q[c] = mlp_create_problem_create_constraint(p, name, GLP_FX, 0.0, 0.0); |
1175 | GNUNET_free (name); | 1201 | GNUNET_free(name); |
1176 | mlp_create_problem_set_value (p, | 1202 | mlp_create_problem_set_value(p, |
1177 | p->r_q[c], | 1203 | p->r_q[c], |
1178 | p->c_q[c], -1, __LINE__); | 1204 | p->c_q[c], -1, __LINE__); |
1179 | } | 1205 | } |
1206 | } | ||
1180 | } | 1207 | } |
1181 | } | ||
1182 | } | 1208 | } |
1183 | 1209 | ||
1184 | 1210 | ||
@@ -1186,36 +1212,36 @@ mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct MLP_Pr | |||
1186 | * Create the invariant columns d, u, r, q0 ... qm | 1212 | * Create the invariant columns d, u, r, q0 ... qm |
1187 | */ | 1213 | */ |
1188 | static void | 1214 | static void |
1189 | mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) | 1215 | mlp_create_problem_add_invariant_columns(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) |
1190 | { | 1216 | { |
1191 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 1217 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
1192 | { | 1218 | { |
1193 | char *name; | 1219 | char *name; |
1194 | int c; | 1220 | int c; |
1195 | 1221 | ||
1196 | /* Diversity d column */ | 1222 | /* Diversity d column */ |
1197 | if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) | 1223 | if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) |
1198 | p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D); | 1224 | p->c_d = mlp_create_problem_create_column(p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D); |
1199 | 1225 | ||
1200 | /* Utilization u column */ | 1226 | /* Utilization u column */ |
1201 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) | 1227 | if (GNUNET_YES == mlp->opt_dbg_optimize_utility) |
1202 | p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U); | 1228 | p->c_u = mlp_create_problem_create_column(p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U); |
1203 | 1229 | ||
1204 | /* Relativity r column */ | 1230 | /* Relativity r column */ |
1205 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) | 1231 | if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) |
1206 | p->c_r = mlp_create_problem_create_column (p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R); | 1232 | p->c_r = mlp_create_problem_create_column(p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R); |
1207 | 1233 | ||
1208 | /* Quality metric columns */ | 1234 | /* Quality metric columns */ |
1209 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) | 1235 | if (GNUNET_YES == mlp->opt_dbg_optimize_quality) |
1210 | { | 1236 | { |
1211 | for (c = 0; c < mlp->pv.m_q; c++) | 1237 | for (c = 0; c < mlp->pv.m_q; c++) |
1212 | { | 1238 | { |
1213 | GNUNET_asprintf (&name, "q_%u", c); | 1239 | GNUNET_asprintf(&name, "q_%u", c); |
1214 | p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); | 1240 | p->c_q[c] = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_Q[c]); |
1215 | GNUNET_free (name); | 1241 | GNUNET_free(name); |
1216 | } | 1242 | } |
1243 | } | ||
1217 | } | 1244 | } |
1218 | } | ||
1219 | } | 1245 | } |
1220 | 1246 | ||
1221 | 1247 | ||
@@ -1226,73 +1252,73 @@ mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct MLP | |||
1226 | * @return #GNUNET_OK or #GNUNET_SYSERR | 1252 | * @return #GNUNET_OK or #GNUNET_SYSERR |
1227 | */ | 1253 | */ |
1228 | static int | 1254 | static int |
1229 | mlp_create_problem (struct GAS_MLP_Handle *mlp) | 1255 | mlp_create_problem(struct GAS_MLP_Handle *mlp) |
1230 | { | 1256 | { |
1231 | struct MLP_Problem *p = &mlp->p; | 1257 | struct MLP_Problem *p = &mlp->p; |
1232 | int res = GNUNET_OK; | 1258 | int res = GNUNET_OK; |
1233 | 1259 | ||
1234 | GNUNET_assert (p->prob == NULL); | 1260 | GNUNET_assert(p->prob == NULL); |
1235 | GNUNET_assert (p->ia == NULL); | 1261 | GNUNET_assert(p->ia == NULL); |
1236 | GNUNET_assert (p->ja == NULL); | 1262 | GNUNET_assert(p->ja == NULL); |
1237 | GNUNET_assert (p->ar == NULL); | 1263 | GNUNET_assert(p->ar == NULL); |
1238 | /* Reset MLP problem struct */ | 1264 | /* Reset MLP problem struct */ |
1239 | 1265 | ||
1240 | /* create the glpk problem */ | 1266 | /* create the glpk problem */ |
1241 | p->prob = glp_create_prob (); | 1267 | p->prob = glp_create_prob(); |
1242 | GNUNET_assert (NULL != p->prob); | 1268 | GNUNET_assert(NULL != p->prob); |
1243 | p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers, mlp->env->addresses); | 1269 | p->num_peers = mlp_create_problem_count_peers(mlp->requested_peers, mlp->env->addresses); |
1244 | p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers, | 1270 | p->num_addresses = mlp_create_problem_count_addresses(mlp->requested_peers, |
1245 | mlp->env->addresses); | 1271 | mlp->env->addresses); |
1246 | 1272 | ||
1247 | /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ | 1273 | /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ |
1248 | p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + | 1274 | p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + |
1249 | mlp->pv.m_q + p->num_peers + 2 + 1); | 1275 | mlp->pv.m_q + p->num_peers + 2 + 1); |
1250 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1276 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1251 | "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", | 1277 | "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", |
1252 | p->num_peers, | 1278 | p->num_peers, |
1253 | p->num_addresses, | 1279 | p->num_addresses, |
1254 | mlp->pv.m_q, | 1280 | mlp->pv.m_q, |
1255 | p->num_elements); | 1281 | p->num_elements); |
1256 | 1282 | ||
1257 | /* Set a problem name */ | 1283 | /* Set a problem name */ |
1258 | glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution"); | 1284 | glp_set_prob_name(p->prob, "GNUnet ATS bandwidth distribution"); |
1259 | /* Set optimization direction to maximize */ | 1285 | /* Set optimization direction to maximize */ |
1260 | glp_set_obj_dir (p->prob, GLP_MAX); | 1286 | glp_set_obj_dir(p->prob, GLP_MAX); |
1261 | 1287 | ||
1262 | /* Create problem matrix */ | 1288 | /* Create problem matrix */ |
1263 | /* last +1 caused by glpk index starting with one: [1..elements]*/ | 1289 | /* last +1 caused by glpk index starting with one: [1..elements]*/ |
1264 | p->ci = 1; | 1290 | p->ci = 1; |
1265 | /* row index */ | 1291 | /* row index */ |
1266 | p->ia = GNUNET_malloc (p->num_elements * sizeof (int)); | 1292 | p->ia = GNUNET_malloc(p->num_elements * sizeof(int)); |
1267 | /* column index */ | 1293 | /* column index */ |
1268 | p->ja = GNUNET_malloc (p->num_elements * sizeof (int)); | 1294 | p->ja = GNUNET_malloc(p->num_elements * sizeof(int)); |
1269 | /* coefficient */ | 1295 | /* coefficient */ |
1270 | p->ar = GNUNET_malloc (p->num_elements * sizeof (double)); | 1296 | p->ar = GNUNET_malloc(p->num_elements * sizeof(double)); |
1271 | 1297 | ||
1272 | if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar)) | 1298 | if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar)) |
1273 | { | 1299 | { |
1274 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n")); | 1300 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n")); |
1275 | return GNUNET_SYSERR; | 1301 | return GNUNET_SYSERR; |
1276 | } | 1302 | } |
1277 | 1303 | ||
1278 | /* Adding invariant columns */ | 1304 | /* Adding invariant columns */ |
1279 | mlp_create_problem_add_invariant_columns (mlp, p); | 1305 | mlp_create_problem_add_invariant_columns(mlp, p); |
1280 | 1306 | ||
1281 | /* Adding address independent constraint rows */ | 1307 | /* Adding address independent constraint rows */ |
1282 | mlp_create_problem_add_invariant_rows (mlp, p); | 1308 | mlp_create_problem_add_invariant_rows(mlp, p); |
1283 | 1309 | ||
1284 | /* Adding address dependent columns constraint rows */ | 1310 | /* Adding address dependent columns constraint rows */ |
1285 | GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses, | 1311 | GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, |
1286 | &mlp_create_problem_add_address_information, | 1312 | &mlp_create_problem_add_address_information, |
1287 | mlp); | 1313 | mlp); |
1288 | 1314 | ||
1289 | /* Load the matrix */ | 1315 | /* Load the matrix */ |
1290 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); | 1316 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); |
1291 | glp_load_matrix(p->prob, (p->ci)-1, p->ia, p->ja, p->ar); | 1317 | glp_load_matrix(p->prob, (p->ci) - 1, p->ia, p->ja, p->ar); |
1292 | if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) | 1318 | if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) |
1293 | { | 1319 | { |
1294 | glp_scale_prob (p->prob, GLP_SF_AUTO); | 1320 | glp_scale_prob(p->prob, GLP_SF_AUTO); |
1295 | } | 1321 | } |
1296 | 1322 | ||
1297 | return res; | 1323 | return res; |
1298 | } | 1324 | } |
@@ -1305,34 +1331,37 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp) | |||
1305 | * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure | 1331 | * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure |
1306 | */ | 1332 | */ |
1307 | static int | 1333 | static int |
1308 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) | 1334 | mlp_solve_lp_problem(struct GAS_MLP_Handle *mlp) |
1309 | { | 1335 | { |
1310 | int res = 0; | 1336 | int res = 0; |
1311 | int res_status = 0; | 1337 | int res_status = 0; |
1338 | |||
1312 | res = glp_simplex(mlp->p.prob, &mlp->control_param_lp); | 1339 | res = glp_simplex(mlp->p.prob, &mlp->control_param_lp); |
1313 | if (0 == res) | 1340 | if (0 == res) |
1314 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", | 1341 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", |
1315 | mlp_solve_to_string (res)); | 1342 | mlp_solve_to_string(res)); |
1316 | else | 1343 | else |
1317 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n", | 1344 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n", |
1318 | mlp_solve_to_string (res)); | 1345 | mlp_solve_to_string(res)); |
1319 | 1346 | ||
1320 | /* Analyze problem status */ | 1347 | /* Analyze problem status */ |
1321 | res_status = glp_get_status (mlp->p.prob); | 1348 | res_status = glp_get_status(mlp->p.prob); |
1322 | switch (res_status) { | 1349 | switch (res_status) |
1350 | { | ||
1323 | case GLP_OPT: /* solution is optimal */ | 1351 | case GLP_OPT: /* solution is optimal */ |
1324 | LOG (GNUNET_ERROR_TYPE_INFO, | 1352 | LOG(GNUNET_ERROR_TYPE_INFO, |
1325 | "Solving LP problem: %s, %s\n", | 1353 | "Solving LP problem: %s, %s\n", |
1326 | mlp_solve_to_string(res), | 1354 | mlp_solve_to_string(res), |
1327 | mlp_status_to_string(res_status)); | 1355 | mlp_status_to_string(res_status)); |
1328 | return GNUNET_OK; | 1356 | return GNUNET_OK; |
1357 | |||
1329 | default: | 1358 | default: |
1330 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1359 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1331 | "Solving LP problem failed: %s %s\n", | 1360 | "Solving LP problem failed: %s %s\n", |
1332 | mlp_solve_to_string(res), | 1361 | mlp_solve_to_string(res), |
1333 | mlp_status_to_string(res_status)); | 1362 | mlp_status_to_string(res_status)); |
1334 | return GNUNET_SYSERR; | 1363 | return GNUNET_SYSERR; |
1335 | } | 1364 | } |
1336 | } | 1365 | } |
1337 | 1366 | ||
1338 | 1367 | ||
@@ -1345,9 +1374,9 @@ mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp) | |||
1345 | * @return #GNUNET_OK to continue | 1374 | * @return #GNUNET_OK to continue |
1346 | */ | 1375 | */ |
1347 | static int | 1376 | static int |
1348 | mlp_propagate_results (void *cls, | 1377 | mlp_propagate_results(void *cls, |
1349 | const struct GNUNET_PeerIdentity *key, | 1378 | const struct GNUNET_PeerIdentity *key, |
1350 | void *value) | 1379 | void *value) |
1351 | { | 1380 | { |
1352 | struct GAS_MLP_Handle *mlp = cls; | 1381 | struct GAS_MLP_Handle *mlp = cls; |
1353 | struct ATS_Address *address; | 1382 | struct ATS_Address *address; |
@@ -1357,27 +1386,27 @@ mlp_propagate_results (void *cls, | |||
1357 | double mlp_use = MLP_NaN; | 1386 | double mlp_use = MLP_NaN; |
1358 | 1387 | ||
1359 | /* Check if we have to add this peer due to a pending request */ | 1388 | /* Check if we have to add this peer due to a pending request */ |
1360 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers, | 1389 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers, |
1361 | key)) | 1390 | key)) |
1362 | { | 1391 | { |
1363 | return GNUNET_OK; | 1392 | return GNUNET_OK; |
1364 | } | 1393 | } |
1365 | address = value; | 1394 | address = value; |
1366 | GNUNET_assert (address->solver_information != NULL); | 1395 | GNUNET_assert(address->solver_information != NULL); |
1367 | mlpi = address->solver_information; | 1396 | mlpi = address->solver_information; |
1368 | 1397 | ||
1369 | mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */ | 1398 | mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */ |
1370 | if (mlp_bw_in > (double) UINT32_MAX) | 1399 | if (mlp_bw_in > (double)UINT32_MAX) |
1371 | { | 1400 | { |
1372 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); | 1401 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n"); |
1373 | mlp_bw_in = (double) UINT32_MAX; | 1402 | mlp_bw_in = (double)UINT32_MAX; |
1374 | } | 1403 | } |
1375 | mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b); | 1404 | mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b); |
1376 | if (mlp_bw_out > (double) UINT32_MAX) | 1405 | if (mlp_bw_out > (double)UINT32_MAX) |
1377 | { | 1406 | { |
1378 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n" ); | 1407 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n"); |
1379 | mlp_bw_out = (double) UINT32_MAX; | 1408 | mlp_bw_out = (double)UINT32_MAX; |
1380 | } | 1409 | } |
1381 | mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); | 1410 | mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); |
1382 | 1411 | ||
1383 | /* | 1412 | /* |
@@ -1388,147 +1417,154 @@ mlp_propagate_results (void *cls, | |||
1388 | */ | 1417 | */ |
1389 | 1418 | ||
1390 | if (GLP_YES == mlp_use) | 1419 | if (GLP_YES == mlp_use) |
1391 | { | ||
1392 | /* This address was selected by the solver to be used */ | ||
1393 | mlpi->n = GNUNET_YES; | ||
1394 | if (GNUNET_NO == address->active) | ||
1395 | { | ||
1396 | /* Address was not used before, enabling address */ | ||
1397 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", | ||
1398 | (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); | ||
1399 | address->active = GNUNET_YES; | ||
1400 | address->assigned_bw_in = mlp_bw_in; | ||
1401 | mlpi->b_in = mlp_bw_in; | ||
1402 | address->assigned_bw_out = mlp_bw_out; | ||
1403 | mlpi->b_out = mlp_bw_out; | ||
1404 | if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer))) | ||
1405 | mlp->env->bandwidth_changed_cb (mlp->env->cls, address); | ||
1406 | return GNUNET_OK; | ||
1407 | } | ||
1408 | else if (GNUNET_YES == address->active) | ||
1409 | { | 1420 | { |
1410 | /* Address was used before, check for bandwidth change */ | 1421 | /* This address was selected by the solver to be used */ |
1411 | if ((mlp_bw_out != address->assigned_bw_out) || | 1422 | mlpi->n = GNUNET_YES; |
1412 | (mlp_bw_in != address->assigned_bw_in)) | 1423 | if (GNUNET_NO == address->active) |
1413 | { | 1424 | { |
1414 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", | 1425 | /* Address was not used before, enabling address */ |
1415 | (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); | 1426 | LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", |
1427 | (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); | ||
1428 | address->active = GNUNET_YES; | ||
1416 | address->assigned_bw_in = mlp_bw_in; | 1429 | address->assigned_bw_in = mlp_bw_in; |
1417 | mlpi->b_in = mlp_bw_in; | 1430 | mlpi->b_in = mlp_bw_in; |
1418 | address->assigned_bw_out = mlp_bw_out; | 1431 | address->assigned_bw_out = mlp_bw_out; |
1419 | mlpi->b_out = mlp_bw_out; | 1432 | mlpi->b_out = mlp_bw_out; |
1420 | if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer, mlp->exclude_peer))) | 1433 | if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp(&address->peer, mlp->exclude_peer))) |
1421 | mlp->env->bandwidth_changed_cb (mlp->env->cls, address); | 1434 | mlp->env->bandwidth_changed_cb(mlp->env->cls, address); |
1422 | return GNUNET_OK; | 1435 | return GNUNET_OK; |
1423 | } | 1436 | } |
1437 | else if (GNUNET_YES == address->active) | ||
1438 | { | ||
1439 | /* Address was used before, check for bandwidth change */ | ||
1440 | if ((mlp_bw_out != address->assigned_bw_out) || | ||
1441 | (mlp_bw_in != address->assigned_bw_in)) | ||
1442 | { | ||
1443 | LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", | ||
1444 | (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); | ||
1445 | address->assigned_bw_in = mlp_bw_in; | ||
1446 | mlpi->b_in = mlp_bw_in; | ||
1447 | address->assigned_bw_out = mlp_bw_out; | ||
1448 | mlpi->b_out = mlp_bw_out; | ||
1449 | if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp(&address->peer, mlp->exclude_peer))) | ||
1450 | mlp->env->bandwidth_changed_cb(mlp->env->cls, address); | ||
1451 | return GNUNET_OK; | ||
1452 | } | ||
1453 | } | ||
1454 | else | ||
1455 | GNUNET_break(0); | ||
1424 | } | 1456 | } |
1425 | else | ||
1426 | GNUNET_break (0); | ||
1427 | } | ||
1428 | else if (GLP_NO == mlp_use) | 1457 | else if (GLP_NO == mlp_use) |
1429 | { | 1458 | { |
1430 | /* This address was selected by the solver to be not used */ | 1459 | /* This address was selected by the solver to be not used */ |
1431 | mlpi->n = GNUNET_NO; | 1460 | mlpi->n = GNUNET_NO; |
1432 | if (GNUNET_NO == address->active) | 1461 | if (GNUNET_NO == address->active) |
1433 | { | 1462 | { |
1434 | /* Address was not used before, nothing to do */ | 1463 | /* Address was not used before, nothing to do */ |
1435 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", | 1464 | LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", |
1436 | (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); | 1465 | (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); |
1437 | return GNUNET_OK; | 1466 | return GNUNET_OK; |
1438 | } | 1467 | } |
1439 | else if (GNUNET_YES == address->active) | 1468 | else if (GNUNET_YES == address->active) |
1440 | { | 1469 | { |
1441 | /* Address was used before, disabling address */ | 1470 | /* Address was used before, disabling address */ |
1442 | LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", | 1471 | LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", |
1443 | (1 == mlp_use) ? "[x]": "[ ]", mlp_bw_out); | 1472 | (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); |
1444 | address->active = GNUNET_NO; | 1473 | address->active = GNUNET_NO; |
1445 | /* Set bandwidth to 0 */ | 1474 | /* Set bandwidth to 0 */ |
1446 | address->assigned_bw_in = 0; | 1475 | address->assigned_bw_in = 0; |
1447 | mlpi->b_in = 0; | 1476 | mlpi->b_in = 0; |
1448 | address->assigned_bw_out = 0; | 1477 | address->assigned_bw_out = 0; |
1449 | mlpi->b_out = 0; | 1478 | mlpi->b_out = 0; |
1450 | return GNUNET_OK; | 1479 | return GNUNET_OK; |
1480 | } | ||
1481 | else | ||
1482 | GNUNET_break(0); | ||
1451 | } | 1483 | } |
1452 | else | ||
1453 | GNUNET_break (0); | ||
1454 | } | ||
1455 | else | 1484 | else |
1456 | GNUNET_break (0); | 1485 | GNUNET_break(0); |
1457 | 1486 | ||
1458 | return GNUNET_OK; | 1487 | return GNUNET_OK; |
1459 | } | 1488 | } |
1460 | 1489 | ||
1461 | 1490 | ||
1462 | static void | 1491 | static void |
1463 | notify (struct GAS_MLP_Handle *mlp, | 1492 | notify(struct GAS_MLP_Handle *mlp, |
1464 | enum GAS_Solver_Operation op, | 1493 | enum GAS_Solver_Operation op, |
1465 | enum GAS_Solver_Status stat, | 1494 | enum GAS_Solver_Status stat, |
1466 | enum GAS_Solver_Additional_Information add) | 1495 | enum GAS_Solver_Additional_Information add) |
1467 | { | 1496 | { |
1468 | mlp->env->info_cb (mlp->env->cls, | 1497 | mlp->env->info_cb(mlp->env->cls, |
1469 | op, | 1498 | op, |
1470 | stat, | 1499 | stat, |
1471 | add); | 1500 | add); |
1472 | } | 1501 | } |
1473 | 1502 | ||
1474 | 1503 | ||
1475 | static void | 1504 | static void |
1476 | mlp_branch_and_cut_cb (glp_tree *tree, void *info) | 1505 | mlp_branch_and_cut_cb(glp_tree *tree, void *info) |
1477 | { | 1506 | { |
1478 | struct GAS_MLP_Handle *mlp = info; | 1507 | struct GAS_MLP_Handle *mlp = info; |
1479 | double mlp_obj = 0; | 1508 | double mlp_obj = 0; |
1480 | 1509 | ||
1481 | switch (glp_ios_reason (tree)) | 1510 | switch (glp_ios_reason(tree)) |
1482 | { | 1511 | { |
1483 | case GLP_ISELECT: | 1512 | case GLP_ISELECT: |
1484 | /* Do nothing here */ | 1513 | /* Do nothing here */ |
1485 | break; | 1514 | break; |
1515 | |||
1486 | case GLP_IPREPRO: | 1516 | case GLP_IPREPRO: |
1487 | /* Do nothing here */ | 1517 | /* Do nothing here */ |
1488 | break; | 1518 | break; |
1519 | |||
1489 | case GLP_IROWGEN: | 1520 | case GLP_IROWGEN: |
1490 | /* Do nothing here */ | 1521 | /* Do nothing here */ |
1491 | break; | 1522 | break; |
1523 | |||
1492 | case GLP_IHEUR: | 1524 | case GLP_IHEUR: |
1493 | /* Do nothing here */ | 1525 | /* Do nothing here */ |
1494 | break; | 1526 | break; |
1527 | |||
1495 | case GLP_ICUTGEN: | 1528 | case GLP_ICUTGEN: |
1496 | /* Do nothing here */ | 1529 | /* Do nothing here */ |
1497 | break; | 1530 | break; |
1531 | |||
1498 | case GLP_IBRANCH: | 1532 | case GLP_IBRANCH: |
1499 | /* Do nothing here */ | 1533 | /* Do nothing here */ |
1500 | break; | 1534 | break; |
1535 | |||
1501 | case GLP_IBINGO: | 1536 | case GLP_IBINGO: |
1502 | /* A better solution was found */ | 1537 | /* A better solution was found */ |
1503 | mlp->ps.mlp_gap = glp_ios_mip_gap (tree); | 1538 | mlp->ps.mlp_gap = glp_ios_mip_gap(tree); |
1504 | mlp_obj = glp_mip_obj_val (mlp->p.prob); | 1539 | mlp_obj = glp_mip_obj_val(mlp->p.prob); |
1505 | mlp->ps.lp_mlp_gap = (abs(mlp_obj - mlp->ps.lp_objective_value)) / (abs(mlp_obj) + DBL_EPSILON); | 1540 | mlp->ps.lp_mlp_gap = (abs(mlp_obj - mlp->ps.lp_objective_value)) / (abs(mlp_obj) + DBL_EPSILON); |
1506 | 1541 | ||
1507 | LOG (GNUNET_ERROR_TYPE_INFO, | 1542 | LOG(GNUNET_ERROR_TYPE_INFO, |
1508 | "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n", | 1543 | "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n", |
1509 | mlp->ps.mlp_gap, mlp->pv.mip_gap, | 1544 | mlp->ps.mlp_gap, mlp->pv.mip_gap, |
1510 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); | 1545 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); |
1511 | 1546 | ||
1512 | if (mlp->ps.mlp_gap <= mlp->pv.mip_gap) | 1547 | if (mlp->ps.mlp_gap <= mlp->pv.mip_gap) |
1513 | { | 1548 | { |
1514 | LOG (GNUNET_ERROR_TYPE_INFO, | 1549 | LOG(GNUNET_ERROR_TYPE_INFO, |
1515 | "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", | 1550 | "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", |
1516 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); | 1551 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); |
1517 | glp_ios_terminate (tree); | 1552 | glp_ios_terminate(tree); |
1518 | } | 1553 | } |
1519 | 1554 | ||
1520 | if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap) | 1555 | if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap) |
1521 | { | 1556 | { |
1522 | LOG (GNUNET_ERROR_TYPE_INFO, | 1557 | LOG(GNUNET_ERROR_TYPE_INFO, |
1523 | "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", | 1558 | "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n", |
1524 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); | 1559 | mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap); |
1525 | glp_ios_terminate (tree); | 1560 | glp_ios_terminate(tree); |
1526 | } | 1561 | } |
1527 | 1562 | ||
1528 | break; | 1563 | break; |
1564 | |||
1529 | default: | 1565 | default: |
1530 | break; | 1566 | break; |
1531 | } | 1567 | } |
1532 | //GNUNET_break (0); | 1568 | //GNUNET_break (0); |
1533 | } | 1569 | } |
1534 | 1570 | ||
@@ -1540,7 +1576,7 @@ mlp_branch_and_cut_cb (glp_tree *tree, void *info) | |||
1540 | * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure | 1576 | * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure |
1541 | */ | 1577 | */ |
1542 | static int | 1578 | static int |
1543 | GAS_mlp_solve_problem (void *solver) | 1579 | GAS_mlp_solve_problem(void *solver) |
1544 | { | 1580 | { |
1545 | struct GAS_MLP_Handle *mlp = solver; | 1581 | struct GAS_MLP_Handle *mlp = solver; |
1546 | char *filename; | 1582 | char *filename; |
@@ -1556,7 +1592,7 @@ GAS_mlp_solve_problem (void *solver) | |||
1556 | struct GNUNET_TIME_Relative dur_mlp; | 1592 | struct GNUNET_TIME_Relative dur_mlp; |
1557 | 1593 | ||
1558 | GNUNET_assert(NULL != solver); | 1594 | GNUNET_assert(NULL != solver); |
1559 | dur_lp = GNUNET_TIME_UNIT_ZERO; | 1595 | dur_lp = GNUNET_TIME_UNIT_ZERO; |
1560 | 1596 | ||
1561 | if (GNUNET_YES == mlp->stat_bulk_lock) | 1597 | if (GNUNET_YES == mlp->stat_bulk_lock) |
1562 | { | 1598 | { |
@@ -1564,7 +1600,7 @@ GAS_mlp_solve_problem (void *solver) | |||
1564 | return GNUNET_NO; | 1600 | return GNUNET_NO; |
1565 | } | 1601 | } |
1566 | notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS, | 1602 | notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS, |
1567 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1603 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1568 | start_total = GNUNET_TIME_absolute_get(); | 1604 | start_total = GNUNET_TIME_absolute_get(); |
1569 | 1605 | ||
1570 | if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers)) | 1606 | if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers)) |
@@ -1586,32 +1622,32 @@ GAS_mlp_solve_problem (void *solver) | |||
1586 | return GNUNET_OK; | 1622 | return GNUNET_OK; |
1587 | } | 1623 | } |
1588 | if (GNUNET_YES == mlp->stat_mlp_prob_changed) | 1624 | if (GNUNET_YES == mlp->stat_mlp_prob_changed) |
1589 | { | 1625 | { |
1590 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n"); | 1626 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n"); |
1591 | notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL); | 1627 | notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL); |
1592 | mlp_delete_problem (mlp); | 1628 | mlp_delete_problem(mlp); |
1593 | if (GNUNET_SYSERR == mlp_create_problem (mlp)) | 1629 | if (GNUNET_SYSERR == mlp_create_problem(mlp)) |
1594 | { | 1630 | { |
1595 | notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL); | 1631 | notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL); |
1596 | return GNUNET_SYSERR; | 1632 | return GNUNET_SYSERR; |
1597 | } | 1633 | } |
1598 | notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL); | 1634 | notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL); |
1599 | if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) | 1635 | if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) |
1600 | { | 1636 | { |
1601 | mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */ | 1637 | mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */ |
1602 | mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */ | 1638 | mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */ |
1603 | } | 1639 | } |
1604 | else | 1640 | else |
1605 | { | 1641 | { |
1606 | mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */ | 1642 | mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */ |
1607 | mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */ | 1643 | mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */ |
1608 | dur_lp = GNUNET_TIME_UNIT_ZERO; | 1644 | dur_lp = GNUNET_TIME_UNIT_ZERO; |
1609 | } | 1645 | } |
1610 | } | 1646 | } |
1611 | else | 1647 | else |
1612 | { | 1648 | { |
1613 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n"); | 1649 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n"); |
1614 | } | 1650 | } |
1615 | 1651 | ||
1616 | /* Reset solution info */ | 1652 | /* Reset solution info */ |
1617 | mlp->ps.lp_objective_value = 0.0; | 1653 | mlp->ps.lp_objective_value = 0.0; |
@@ -1619,156 +1655,160 @@ GAS_mlp_solve_problem (void *solver) | |||
1619 | mlp->ps.mlp_objective_value = 0.0; | 1655 | mlp->ps.mlp_objective_value = 0.0; |
1620 | mlp->ps.lp_mlp_gap = 0.0; | 1656 | mlp->ps.lp_mlp_gap = 0.0; |
1621 | 1657 | ||
1622 | dur_setup = GNUNET_TIME_absolute_get_duration (start_total); | 1658 | dur_setup = GNUNET_TIME_absolute_get_duration(start_total); |
1623 | 1659 | ||
1624 | /* Run LP solver */ | 1660 | /* Run LP solver */ |
1625 | if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) | 1661 | if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) |
1626 | { | 1662 | { |
1627 | notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS, | 1663 | notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS, |
1628 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1664 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1629 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1665 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1630 | "Running LP solver %s\n", | 1666 | "Running LP solver %s\n", |
1631 | (GLP_YES == mlp->control_param_lp.presolve)? "with presolver": "without presolver"); | 1667 | (GLP_YES == mlp->control_param_lp.presolve) ? "with presolver" : "without presolver"); |
1632 | start_cur_op = GNUNET_TIME_absolute_get(); | 1668 | start_cur_op = GNUNET_TIME_absolute_get(); |
1633 | 1669 | ||
1634 | /* Solve LP */ | 1670 | /* Solve LP */ |
1635 | /* Only for debugging: | 1671 | /* Only for debugging: |
1636 | * Always use LP presolver: | 1672 | * Always use LP presolver: |
1637 | * mlp->control_param_lp.presolve = GLP_YES; */ | 1673 | * mlp->control_param_lp.presolve = GLP_YES; */ |
1638 | res_lp = mlp_solve_lp_problem(mlp); | 1674 | res_lp = mlp_solve_lp_problem(mlp); |
1639 | if (GNUNET_OK == res_lp) | 1675 | if (GNUNET_OK == res_lp) |
1640 | { | 1676 | { |
1641 | mlp->ps.lp_objective_value = glp_get_obj_val (mlp->p.prob); | 1677 | mlp->ps.lp_objective_value = glp_get_obj_val(mlp->p.prob); |
1642 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1678 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1643 | "LP solution was: %.3f\n", | 1679 | "LP solution was: %.3f\n", |
1644 | mlp->ps.lp_objective_value); | 1680 | mlp->ps.lp_objective_value); |
1645 | } | 1681 | } |
1646 | 1682 | ||
1647 | dur_lp = GNUNET_TIME_absolute_get_duration (start_cur_op); | 1683 | dur_lp = GNUNET_TIME_absolute_get_duration(start_cur_op); |
1648 | notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP, | 1684 | notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP, |
1649 | (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, | 1685 | (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, |
1650 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1686 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1651 | } | 1687 | } |
1652 | 1688 | ||
1653 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) | 1689 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) |
1654 | res_lp = GNUNET_OK; | 1690 | res_lp = GNUNET_OK; |
1655 | 1691 | ||
1656 | /* Run MLP solver */ | 1692 | /* Run MLP solver */ |
1657 | if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver)) | 1693 | if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver)) |
1658 | { | 1694 | { |
1659 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n"); | 1695 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n"); |
1660 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS, | 1696 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS, |
1661 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1697 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1662 | start_cur_op = GNUNET_TIME_absolute_get(); | 1698 | start_cur_op = GNUNET_TIME_absolute_get(); |
1663 | 1699 | ||
1664 | /* Solve MIP */ | 1700 | /* Solve MIP */ |
1665 | 1701 | ||
1666 | /* Only for debugging, always use LP presolver */ | 1702 | /* Only for debugging, always use LP presolver */ |
1667 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) | 1703 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) |
1668 | mlp->control_param_mlp.presolve = GNUNET_YES; | 1704 | mlp->control_param_mlp.presolve = GNUNET_YES; |
1669 | 1705 | ||
1670 | mip_res = glp_intopt (mlp->p.prob, &mlp->control_param_mlp); | 1706 | mip_res = glp_intopt(mlp->p.prob, &mlp->control_param_mlp); |
1671 | switch (mip_res) | 1707 | switch (mip_res) |
1672 | { | 1708 | { |
1673 | case 0: | 1709 | case 0: |
1674 | /* Successful */ | 1710 | /* Successful */ |
1675 | LOG (GNUNET_ERROR_TYPE_INFO, | 1711 | LOG(GNUNET_ERROR_TYPE_INFO, |
1676 | "Solving MLP problem: %s\n", | 1712 | "Solving MLP problem: %s\n", |
1677 | mlp_solve_to_string (mip_res)); | 1713 | mlp_solve_to_string(mip_res)); |
1678 | break; | 1714 | break; |
1715 | |||
1679 | case GLP_ETMLIM: /* Time limit reached */ | 1716 | case GLP_ETMLIM: /* Time limit reached */ |
1680 | case GLP_EMIPGAP: /* MIP gap tolerance limit reached */ | 1717 | case GLP_EMIPGAP: /* MIP gap tolerance limit reached */ |
1681 | case GLP_ESTOP: /* Solver was instructed to stop*/ | 1718 | case GLP_ESTOP: /* Solver was instructed to stop*/ |
1682 | /* Semi-successful */ | 1719 | /* Semi-successful */ |
1683 | LOG (GNUNET_ERROR_TYPE_INFO, | 1720 | LOG(GNUNET_ERROR_TYPE_INFO, |
1684 | "Solving MLP problem solution was interupted: %s\n", | 1721 | "Solving MLP problem solution was interupted: %s\n", |
1685 | mlp_solve_to_string (mip_res)); | 1722 | mlp_solve_to_string(mip_res)); |
1686 | break; | 1723 | break; |
1724 | |||
1687 | case GLP_EBOUND: | 1725 | case GLP_EBOUND: |
1688 | case GLP_EROOT: | 1726 | case GLP_EROOT: |
1689 | case GLP_ENOPFS: | 1727 | case GLP_ENOPFS: |
1690 | case GLP_ENODFS: | 1728 | case GLP_ENODFS: |
1691 | case GLP_EFAIL: | 1729 | case GLP_EFAIL: |
1692 | default: | 1730 | default: |
1693 | /* Fail */ | 1731 | /* Fail */ |
1694 | LOG (GNUNET_ERROR_TYPE_INFO, | 1732 | LOG(GNUNET_ERROR_TYPE_INFO, |
1695 | "Solving MLP problem failed: %s\n", | 1733 | "Solving MLP problem failed: %s\n", |
1696 | mlp_solve_to_string (mip_res)); | 1734 | mlp_solve_to_string(mip_res)); |
1697 | break; | 1735 | break; |
1698 | } | 1736 | } |
1699 | |||
1700 | /* Analyze problem status */ | ||
1701 | mip_status = glp_mip_status(mlp->p.prob); | ||
1702 | switch (mip_status) | ||
1703 | { | ||
1704 | case GLP_OPT: /* solution is optimal */ | ||
1705 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1706 | "Solution of MLP problem is optimal: %s, %s\n", | ||
1707 | mlp_solve_to_string (mip_res), | ||
1708 | mlp_status_to_string (mip_status)); | ||
1709 | mip_res = GNUNET_OK; | ||
1710 | break; | ||
1711 | case GLP_FEAS: /* solution is feasible but not proven optimal */ | ||
1712 | 1737 | ||
1713 | if ( (mlp->ps.mlp_gap <= mlp->pv.mip_gap) || | 1738 | /* Analyze problem status */ |
1714 | (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap) ) | 1739 | mip_status = glp_mip_status(mlp->p.prob); |
1740 | switch (mip_status) | ||
1715 | { | 1741 | { |
1716 | LOG (GNUNET_ERROR_TYPE_INFO, | 1742 | case GLP_OPT: /* solution is optimal */ |
1717 | "Solution of MLP problem is feasible and solution within gap constraints: %s, %s\n", | 1743 | LOG(GNUNET_ERROR_TYPE_WARNING, |
1718 | mlp_solve_to_string (mip_res), | 1744 | "Solution of MLP problem is optimal: %s, %s\n", |
1719 | mlp_status_to_string (mip_status)); | 1745 | mlp_solve_to_string(mip_res), |
1746 | mlp_status_to_string(mip_status)); | ||
1720 | mip_res = GNUNET_OK; | 1747 | mip_res = GNUNET_OK; |
1721 | } | 1748 | break; |
1722 | else | 1749 | |
1723 | { | 1750 | case GLP_FEAS: /* solution is feasible but not proven optimal */ |
1724 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1751 | |
1725 | "Solution of MLP problem is feasible but solution not within gap constraints: %s, %s\n", | 1752 | if ((mlp->ps.mlp_gap <= mlp->pv.mip_gap) || |
1726 | mlp_solve_to_string (mip_res), | 1753 | (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap)) |
1727 | mlp_status_to_string (mip_status)); | 1754 | { |
1755 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1756 | "Solution of MLP problem is feasible and solution within gap constraints: %s, %s\n", | ||
1757 | mlp_solve_to_string(mip_res), | ||
1758 | mlp_status_to_string(mip_status)); | ||
1759 | mip_res = GNUNET_OK; | ||
1760 | } | ||
1761 | else | ||
1762 | { | ||
1763 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
1764 | "Solution of MLP problem is feasible but solution not within gap constraints: %s, %s\n", | ||
1765 | mlp_solve_to_string(mip_res), | ||
1766 | mlp_status_to_string(mip_status)); | ||
1767 | mip_res = GNUNET_SYSERR; | ||
1768 | } | ||
1769 | break; | ||
1770 | |||
1771 | case GLP_UNDEF: /* Solution undefined */ | ||
1772 | case GLP_NOFEAS: /* No feasible solution */ | ||
1773 | default: | ||
1774 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1775 | "Solving MLP problem failed: %s %s\n", | ||
1776 | mlp_solve_to_string(mip_res), | ||
1777 | mlp_status_to_string(mip_status)); | ||
1728 | mip_res = GNUNET_SYSERR; | 1778 | mip_res = GNUNET_SYSERR; |
1779 | break; | ||
1729 | } | 1780 | } |
1730 | break; | ||
1731 | case GLP_UNDEF: /* Solution undefined */ | ||
1732 | case GLP_NOFEAS: /* No feasible solution */ | ||
1733 | default: | ||
1734 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1735 | "Solving MLP problem failed: %s %s\n", | ||
1736 | mlp_solve_to_string (mip_res), | ||
1737 | mlp_status_to_string (mip_status)); | ||
1738 | mip_res = GNUNET_SYSERR; | ||
1739 | break; | ||
1740 | } | ||
1741 | 1781 | ||
1742 | dur_mlp = GNUNET_TIME_absolute_get_duration (start_cur_op); | 1782 | dur_mlp = GNUNET_TIME_absolute_get_duration(start_cur_op); |
1743 | dur_total = GNUNET_TIME_absolute_get_duration (start_total); | 1783 | dur_total = GNUNET_TIME_absolute_get_duration(start_total); |
1744 | 1784 | ||
1745 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, | 1785 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, |
1746 | (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, | 1786 | (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, |
1747 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1787 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1748 | } | 1788 | } |
1749 | else | 1789 | else |
1750 | { | 1790 | { |
1751 | /* Do not execute mip solver since lp solution is invalid */ | 1791 | /* Do not execute mip solver since lp solution is invalid */ |
1752 | dur_mlp = GNUNET_TIME_UNIT_ZERO; | 1792 | dur_mlp = GNUNET_TIME_UNIT_ZERO; |
1753 | dur_total = GNUNET_TIME_absolute_get_duration (start_total); | 1793 | dur_total = GNUNET_TIME_absolute_get_duration(start_total); |
1754 | 1794 | ||
1755 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL, | 1795 | notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL, |
1756 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1796 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1757 | mip_res = GNUNET_SYSERR; | 1797 | mip_res = GNUNET_SYSERR; |
1758 | } | 1798 | } |
1759 | 1799 | ||
1760 | /* Notify about end */ | 1800 | /* Notify about end */ |
1761 | notify(mlp, GAS_OP_SOLVE_STOP, | 1801 | notify(mlp, GAS_OP_SOLVE_STOP, |
1762 | ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, | 1802 | ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, |
1763 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); | 1803 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); |
1764 | 1804 | ||
1765 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1805 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1766 | "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n", | 1806 | "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n", |
1767 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated", | 1807 | (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated", |
1768 | (unsigned long long) dur_total.rel_value_us, | 1808 | (unsigned long long)dur_total.rel_value_us, |
1769 | (unsigned long long) dur_setup.rel_value_us, | 1809 | (unsigned long long)dur_setup.rel_value_us, |
1770 | (unsigned long long) dur_lp.rel_value_us, | 1810 | (unsigned long long)dur_lp.rel_value_us, |
1771 | (unsigned long long) dur_mlp.rel_value_us); | 1811 | (unsigned long long)dur_mlp.rel_value_us); |
1772 | 1812 | ||
1773 | /* Save stats */ | 1813 | /* Save stats */ |
1774 | mlp->ps.lp_res = res_lp; | 1814 | mlp->ps.lp_res = res_lp; |
@@ -1780,55 +1820,59 @@ GAS_mlp_solve_problem (void *solver) | |||
1780 | mlp->ps.p_elements = mlp->p.num_elements; | 1820 | mlp->ps.p_elements = mlp->p.num_elements; |
1781 | 1821 | ||
1782 | /* Propagate result*/ | 1822 | /* Propagate result*/ |
1783 | notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | 1823 | notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, |
1784 | (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, | 1824 | (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, |
1785 | GAS_INFO_NONE); | 1825 | GAS_INFO_NONE); |
1786 | if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) | 1826 | if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) |
1787 | { | 1827 | { |
1788 | GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, | 1828 | GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, |
1789 | &mlp_propagate_results, mlp); | 1829 | &mlp_propagate_results, mlp); |
1790 | } | 1830 | } |
1791 | notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | 1831 | notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, |
1792 | (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, | 1832 | (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, |
1793 | GAS_INFO_NONE); | 1833 | GAS_INFO_NONE); |
1794 | 1834 | ||
1795 | struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get(); | 1835 | struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get(); |
1796 | if ( (GNUNET_YES == mlp->opt_dump_problem_all) || | 1836 | if ((GNUNET_YES == mlp->opt_dump_problem_all) || |
1797 | (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))) ) | 1837 | (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res)))) |
1798 | { | 1838 | { |
1799 | /* Write problem to disk */ | 1839 | /* Write problem to disk */ |
1800 | switch (mlp->opt_log_format) { | 1840 | switch (mlp->opt_log_format) |
1841 | { | ||
1801 | case MLP_CPLEX: | 1842 | case MLP_CPLEX: |
1802 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.cplex", mlp->p.num_peers, | 1843 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.cplex", mlp->p.num_peers, |
1803 | mlp->p.num_addresses, time.abs_value_us); | 1844 | mlp->p.num_addresses, time.abs_value_us); |
1804 | glp_write_lp (mlp->p.prob, NULL, filename); | 1845 | glp_write_lp(mlp->p.prob, NULL, filename); |
1805 | break; | 1846 | break; |
1847 | |||
1806 | case MLP_GLPK: | 1848 | case MLP_GLPK: |
1807 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.glpk", mlp->p.num_peers, | 1849 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.glpk", mlp->p.num_peers, |
1808 | mlp->p.num_addresses, time.abs_value_us); | 1850 | mlp->p.num_addresses, time.abs_value_us); |
1809 | glp_write_prob (mlp->p.prob, 0, filename); | 1851 | glp_write_prob(mlp->p.prob, 0, filename); |
1810 | break; | 1852 | break; |
1853 | |||
1811 | case MLP_MPS: | 1854 | case MLP_MPS: |
1812 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers, | 1855 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers, |
1813 | mlp->p.num_addresses, time.abs_value_us); | 1856 | mlp->p.num_addresses, time.abs_value_us); |
1814 | glp_write_mps (mlp->p.prob, GLP_MPS_FILE, NULL, filename); | 1857 | glp_write_mps(mlp->p.prob, GLP_MPS_FILE, NULL, filename); |
1815 | break; | 1858 | break; |
1859 | |||
1816 | default: | 1860 | default: |
1817 | break; | 1861 | break; |
1818 | } | 1862 | } |
1819 | LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename); | 1863 | LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename); |
1820 | GNUNET_free(filename); | 1864 | GNUNET_free(filename); |
1821 | } | 1865 | } |
1822 | if ( (mlp->opt_dump_solution_all) || | 1866 | if ((mlp->opt_dump_solution_all) || |
1823 | (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res))) ) | 1867 | (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res)))) |
1824 | { | 1868 | { |
1825 | /* Write solution to disk */ | 1869 | /* Write solution to disk */ |
1826 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers, | 1870 | GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers, |
1827 | mlp->p.num_addresses, time.abs_value_us); | 1871 | mlp->p.num_addresses, time.abs_value_us); |
1828 | glp_print_mip(mlp->p.prob, filename); | 1872 | glp_print_mip(mlp->p.prob, filename); |
1829 | LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename); | 1873 | LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename); |
1830 | GNUNET_free(filename); | 1874 | GNUNET_free(filename); |
1831 | } | 1875 | } |
1832 | 1876 | ||
1833 | /* Reset change and update marker */ | 1877 | /* Reset change and update marker */ |
1834 | mlp->control_param_lp.presolve = GLP_NO; | 1878 | mlp->control_param_lp.presolve = GLP_NO; |
@@ -1849,46 +1893,46 @@ GAS_mlp_solve_problem (void *solver) | |||
1849 | * @param network network type of this address | 1893 | * @param network network type of this address |
1850 | */ | 1894 | */ |
1851 | static void | 1895 | static void |
1852 | GAS_mlp_address_add (void *solver, | 1896 | GAS_mlp_address_add(void *solver, |
1853 | struct ATS_Address *address, | 1897 | struct ATS_Address *address, |
1854 | uint32_t network) | 1898 | uint32_t network) |
1855 | { | 1899 | { |
1856 | struct GAS_MLP_Handle *mlp = solver; | 1900 | struct GAS_MLP_Handle *mlp = solver; |
1857 | 1901 | ||
1858 | if (GNUNET_NT_COUNT <= network) | 1902 | if (GNUNET_NT_COUNT <= network) |
1859 | { | 1903 | { |
1860 | GNUNET_break (0); | 1904 | GNUNET_break(0); |
1861 | return; | 1905 | return; |
1862 | } | 1906 | } |
1863 | 1907 | ||
1864 | if (NULL == address->solver_information) | 1908 | if (NULL == address->solver_information) |
1865 | { | 1909 | { |
1866 | address->solver_information = GNUNET_new (struct MLP_information); | 1910 | address->solver_information = GNUNET_new(struct MLP_information); |
1867 | } | 1911 | } |
1868 | else | 1912 | else |
1869 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1913 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1870 | _("Adding address for peer `%s' multiple times\n"), | 1914 | _("Adding address for peer `%s' multiple times\n"), |
1871 | GNUNET_i2s(&address->peer)); | 1915 | GNUNET_i2s(&address->peer)); |
1872 | 1916 | ||
1873 | /* Is this peer included in the problem? */ | 1917 | /* Is this peer included in the problem? */ |
1874 | if (NULL == | 1918 | if (NULL == |
1875 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, | 1919 | GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, |
1876 | &address->peer)) | 1920 | &address->peer)) |
1877 | { | 1921 | { |
1878 | /* FIXME: should this be an error? */ | 1922 | /* FIXME: should this be an error? */ |
1879 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1923 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1880 | "Adding address for peer `%s' without address request\n", | 1924 | "Adding address for peer `%s' without address request\n", |
1881 | GNUNET_i2s(&address->peer)); | 1925 | GNUNET_i2s(&address->peer)); |
1882 | return; | 1926 | return; |
1883 | } | 1927 | } |
1884 | 1928 | ||
1885 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1929 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1886 | "Adding address for peer `%s' with address request \n", | 1930 | "Adding address for peer `%s' with address request \n", |
1887 | GNUNET_i2s(&address->peer)); | 1931 | GNUNET_i2s(&address->peer)); |
1888 | /* Problem size changed: new address for peer with pending request */ | 1932 | /* Problem size changed: new address for peer with pending request */ |
1889 | mlp->stat_mlp_prob_changed = GNUNET_YES; | 1933 | mlp->stat_mlp_prob_changed = GNUNET_YES; |
1890 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | 1934 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) |
1891 | GAS_mlp_solve_problem (solver); | 1935 | GAS_mlp_solve_problem(solver); |
1892 | } | 1936 | } |
1893 | 1937 | ||
1894 | 1938 | ||
@@ -1899,8 +1943,8 @@ GAS_mlp_address_add (void *solver, | |||
1899 | * @param address the address | 1943 | * @param address the address |
1900 | */ | 1944 | */ |
1901 | static void | 1945 | static void |
1902 | GAS_mlp_address_property_changed (void *solver, | 1946 | GAS_mlp_address_property_changed(void *solver, |
1903 | struct ATS_Address *address) | 1947 | struct ATS_Address *address) |
1904 | { | 1948 | { |
1905 | struct MLP_information *mlpi = address->solver_information; | 1949 | struct MLP_information *mlpi = address->solver_information; |
1906 | struct GAS_MLP_Handle *mlp = solver; | 1950 | struct GAS_MLP_Handle *mlp = solver; |
@@ -1909,47 +1953,46 @@ GAS_mlp_address_property_changed (void *solver, | |||
1909 | return; /* There is no MLP problem to update yet */ | 1953 | return; /* There is no MLP problem to update yet */ |
1910 | 1954 | ||
1911 | if (NULL == mlpi) | 1955 | if (NULL == mlpi) |
1912 | { | 1956 | { |
1913 | LOG (GNUNET_ERROR_TYPE_INFO, | 1957 | LOG(GNUNET_ERROR_TYPE_INFO, |
1914 | _("Updating address property for peer `%s' %p not added before\n"), | 1958 | _("Updating address property for peer `%s' %p not added before\n"), |
1915 | GNUNET_i2s (&address->peer), | 1959 | GNUNET_i2s(&address->peer), |
1916 | address); | 1960 | address); |
1917 | GNUNET_break (0); | 1961 | GNUNET_break(0); |
1918 | return; | 1962 | return; |
1919 | } | 1963 | } |
1920 | if (NULL == | 1964 | if (NULL == |
1921 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, | 1965 | GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, |
1922 | &address->peer)) | 1966 | &address->peer)) |
1923 | { | 1967 | { |
1924 | /* Peer is not requested, so no need to update problem */ | 1968 | /* Peer is not requested, so no need to update problem */ |
1925 | return; | 1969 | return; |
1926 | } | 1970 | } |
1927 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1971 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1928 | "Updating properties for peer `%s'\n", | 1972 | "Updating properties for peer `%s'\n", |
1929 | GNUNET_i2s(&address->peer)); | 1973 | GNUNET_i2s(&address->peer)); |
1930 | 1974 | ||
1931 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) | 1975 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) |
1932 | return; | 1976 | return; |
1933 | 1977 | ||
1934 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ | 1978 | /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ |
1935 | if ( (GNUNET_YES == | 1979 | if ((GNUNET_YES == |
1936 | mlp_create_problem_update_value (&mlp->p, | 1980 | mlp_create_problem_update_value(&mlp->p, |
1937 | mlp->p.r_q[RQ_QUALITY_METRIC_DELAY], | 1981 | mlp->p.r_q[RQ_QUALITY_METRIC_DELAY], |
1938 | mlpi->c_b, | 1982 | mlpi->c_b, |
1939 | address->norm_delay.norm, | 1983 | address->norm_delay.norm, |
1940 | __LINE__)) || | 1984 | __LINE__)) || |
1941 | (GNUNET_YES == | 1985 | (GNUNET_YES == |
1942 | mlp_create_problem_update_value (&mlp->p, | 1986 | mlp_create_problem_update_value(&mlp->p, |
1943 | mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE], | 1987 | mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE], |
1944 | mlpi->c_b, | 1988 | mlpi->c_b, |
1945 | address->norm_distance.norm, | 1989 | address->norm_distance.norm, |
1946 | __LINE__)) ) | 1990 | __LINE__))) |
1947 | { | 1991 | { |
1948 | mlp->stat_mlp_prob_updated = GNUNET_YES; | 1992 | mlp->stat_mlp_prob_updated = GNUNET_YES; |
1949 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | 1993 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) |
1950 | GAS_mlp_solve_problem (solver); | 1994 | GAS_mlp_solve_problem(solver); |
1951 | } | 1995 | } |
1952 | |||
1953 | } | 1996 | } |
1954 | 1997 | ||
1955 | 1998 | ||
@@ -1961,9 +2004,9 @@ GAS_mlp_address_property_changed (void *solver, | |||
1961 | * @return #GNUNET_OK | 2004 | * @return #GNUNET_OK |
1962 | */ | 2005 | */ |
1963 | static int | 2006 | static int |
1964 | mlp_get_preferred_address_it (void *cls, | 2007 | mlp_get_preferred_address_it(void *cls, |
1965 | const struct GNUNET_PeerIdentity *key, | 2008 | const struct GNUNET_PeerIdentity *key, |
1966 | void *value) | 2009 | void *value) |
1967 | { | 2010 | { |
1968 | static int counter = 0; | 2011 | static int counter = 0; |
1969 | struct ATS_Address **aa = cls; | 2012 | struct ATS_Address **aa = cls; |
@@ -1983,41 +2026,40 @@ mlp_get_preferred_address_it (void *cls, | |||
1983 | */ | 2026 | */ |
1984 | 2027 | ||
1985 | if (GNUNET_YES == mlpi->n) | 2028 | if (GNUNET_YES == mlpi->n) |
1986 | { | 2029 | { |
1987 | 2030 | (*aa) = addr; | |
1988 | (*aa) = addr; | 2031 | (*aa)->assigned_bw_in = mlpi->b_in; |
1989 | (*aa)->assigned_bw_in = mlpi->b_in; | 2032 | (*aa)->assigned_bw_out = mlpi->b_out; |
1990 | (*aa)->assigned_bw_out = mlpi->b_out; | 2033 | return GNUNET_NO; |
1991 | return GNUNET_NO; | 2034 | } |
1992 | } | ||
1993 | counter++; | 2035 | counter++; |
1994 | return GNUNET_YES; | 2036 | return GNUNET_YES; |
1995 | } | 2037 | } |
1996 | 2038 | ||
1997 | 2039 | ||
1998 | static double | 2040 | static double |
1999 | get_peer_pref_value (struct GAS_MLP_Handle *mlp, | 2041 | get_peer_pref_value(struct GAS_MLP_Handle *mlp, |
2000 | const struct GNUNET_PeerIdentity *peer) | 2042 | const struct GNUNET_PeerIdentity *peer) |
2001 | { | 2043 | { |
2002 | double res; | 2044 | double res; |
2003 | const double *preferences; | 2045 | const double *preferences; |
2004 | int c; | 2046 | int c; |
2005 | 2047 | ||
2006 | preferences = mlp->env->get_preferences (mlp->env->cls, peer); | 2048 | preferences = mlp->env->get_preferences(mlp->env->cls, peer); |
2007 | res = 0.0; | 2049 | res = 0.0; |
2008 | for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) | 2050 | for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) |
2009 | { | 2051 | { |
2010 | /* fprintf (stderr, "VALUE[%u] %s %.3f \n", | 2052 | /* fprintf (stderr, "VALUE[%u] %s %.3f \n", |
2011 | * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ | 2053 | * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ |
2012 | res += preferences[c]; | 2054 | res += preferences[c]; |
2013 | } | 2055 | } |
2014 | 2056 | ||
2015 | res /= GNUNET_ATS_PREFERENCE_END; | 2057 | res /= GNUNET_ATS_PREFERENCE_END; |
2016 | res += 1.0; | 2058 | res += 1.0; |
2017 | 2059 | ||
2018 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2060 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2019 | "Peer preference for peer `%s' == %.2f\n", | 2061 | "Peer preference for peer `%s' == %.2f\n", |
2020 | GNUNET_i2s(peer), res); | 2062 | GNUNET_i2s(peer), res); |
2021 | 2063 | ||
2022 | return res; | 2064 | return res; |
2023 | } | 2065 | } |
@@ -2030,51 +2072,51 @@ get_peer_pref_value (struct GAS_MLP_Handle *mlp, | |||
2030 | * @param peer the peer | 2072 | * @param peer the peer |
2031 | */ | 2073 | */ |
2032 | static void | 2074 | static void |
2033 | GAS_mlp_get_preferred_address (void *solver, | 2075 | GAS_mlp_get_preferred_address(void *solver, |
2034 | const struct GNUNET_PeerIdentity *peer) | 2076 | const struct GNUNET_PeerIdentity *peer) |
2035 | { | 2077 | { |
2036 | struct GAS_MLP_Handle *mlp = solver; | 2078 | struct GAS_MLP_Handle *mlp = solver; |
2037 | struct ATS_Peer *p; | 2079 | struct ATS_Peer *p; |
2038 | struct ATS_Address *res; | 2080 | struct ATS_Address *res; |
2039 | 2081 | ||
2040 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2082 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2041 | "Getting preferred address for `%s'\n", | 2083 | "Getting preferred address for `%s'\n", |
2042 | GNUNET_i2s (peer)); | 2084 | GNUNET_i2s(peer)); |
2043 | 2085 | ||
2044 | /* Is this peer included in the problem? */ | 2086 | /* Is this peer included in the problem? */ |
2045 | if (NULL == | 2087 | if (NULL == |
2046 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, | 2088 | GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, |
2047 | peer)) | 2089 | peer)) |
2048 | { | 2090 | { |
2049 | LOG (GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n", | 2091 | LOG(GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n", |
2050 | GNUNET_i2s (peer)); | 2092 | GNUNET_i2s(peer)); |
2051 | 2093 | ||
2052 | p = GNUNET_new (struct ATS_Peer); | 2094 | p = GNUNET_new(struct ATS_Peer); |
2053 | p->id = (*peer); | 2095 | p->id = (*peer); |
2054 | p->f = get_peer_pref_value (mlp, peer); | 2096 | p->f = get_peer_pref_value(mlp, peer); |
2055 | GNUNET_CONTAINER_multipeermap_put (mlp->requested_peers, | 2097 | GNUNET_CONTAINER_multipeermap_put(mlp->requested_peers, |
2056 | peer, p, | 2098 | peer, p, |
2057 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 2099 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
2058 | 2100 | ||
2059 | /* Added new peer, we have to rebuild problem before solving */ | 2101 | /* Added new peer, we have to rebuild problem before solving */ |
2060 | mlp->stat_mlp_prob_changed = GNUNET_YES; | 2102 | mlp->stat_mlp_prob_changed = GNUNET_YES; |
2061 | 2103 | ||
2062 | if ((GNUNET_YES == mlp->opt_mlp_auto_solve)&& | 2104 | if ((GNUNET_YES == mlp->opt_mlp_auto_solve) && |
2063 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses, | 2105 | (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses, |
2064 | peer))) | 2106 | peer))) |
2065 | { | 2107 | { |
2066 | mlp->exclude_peer = peer; | 2108 | mlp->exclude_peer = peer; |
2067 | GAS_mlp_solve_problem (mlp); | 2109 | GAS_mlp_solve_problem(mlp); |
2068 | mlp->exclude_peer = NULL; | 2110 | mlp->exclude_peer = NULL; |
2069 | } | 2111 | } |
2070 | } | 2112 | } |
2071 | /* Get prefered address */ | 2113 | /* Get prefered address */ |
2072 | res = NULL; | 2114 | res = NULL; |
2073 | GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer, | 2115 | GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses, peer, |
2074 | &mlp_get_preferred_address_it, &res); | 2116 | &mlp_get_preferred_address_it, &res); |
2075 | if (NULL != res) | 2117 | if (NULL != res) |
2076 | mlp->env->bandwidth_changed_cb (mlp->env->cls, | 2118 | mlp->env->bandwidth_changed_cb(mlp->env->cls, |
2077 | res); | 2119 | res); |
2078 | } | 2120 | } |
2079 | 2121 | ||
2080 | 2122 | ||
@@ -2087,8 +2129,8 @@ GAS_mlp_get_preferred_address (void *solver, | |||
2087 | * @param address the address to delete | 2129 | * @param address the address to delete |
2088 | */ | 2130 | */ |
2089 | static void | 2131 | static void |
2090 | GAS_mlp_address_delete (void *solver, | 2132 | GAS_mlp_address_delete(void *solver, |
2091 | struct ATS_Address *address) | 2133 | struct ATS_Address *address) |
2092 | { | 2134 | { |
2093 | struct GAS_MLP_Handle *mlp = solver; | 2135 | struct GAS_MLP_Handle *mlp = solver; |
2094 | struct MLP_information *mlpi; | 2136 | struct MLP_information *mlpi; |
@@ -2097,11 +2139,11 @@ GAS_mlp_address_delete (void *solver, | |||
2097 | 2139 | ||
2098 | mlpi = address->solver_information; | 2140 | mlpi = address->solver_information; |
2099 | if (NULL != mlpi) | 2141 | if (NULL != mlpi) |
2100 | { | 2142 | { |
2101 | /* Remove full address */ | 2143 | /* Remove full address */ |
2102 | GNUNET_free (mlpi); | 2144 | GNUNET_free(mlpi); |
2103 | address->solver_information = NULL; | 2145 | address->solver_information = NULL; |
2104 | } | 2146 | } |
2105 | was_active = address->active; | 2147 | was_active = address->active; |
2106 | address->active = GNUNET_NO; | 2148 | address->active = GNUNET_NO; |
2107 | address->assigned_bw_in = 0; | 2149 | address->assigned_bw_in = 0; |
@@ -2109,38 +2151,38 @@ GAS_mlp_address_delete (void *solver, | |||
2109 | 2151 | ||
2110 | /* Is this peer included in the problem? */ | 2152 | /* Is this peer included in the problem? */ |
2111 | if (NULL == | 2153 | if (NULL == |
2112 | GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, | 2154 | GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, |
2113 | &address->peer)) | 2155 | &address->peer)) |
2114 | { | 2156 | { |
2115 | LOG (GNUNET_ERROR_TYPE_INFO, | 2157 | LOG(GNUNET_ERROR_TYPE_INFO, |
2116 | "Deleting address for peer `%s' without address request \n", | 2158 | "Deleting address for peer `%s' without address request \n", |
2117 | GNUNET_i2s(&address->peer)); | 2159 | GNUNET_i2s(&address->peer)); |
2118 | return; | 2160 | return; |
2119 | } | 2161 | } |
2120 | LOG (GNUNET_ERROR_TYPE_INFO, | 2162 | LOG(GNUNET_ERROR_TYPE_INFO, |
2121 | "Deleting address for peer `%s' with address request \n", | 2163 | "Deleting address for peer `%s' with address request \n", |
2122 | GNUNET_i2s (&address->peer)); | 2164 | GNUNET_i2s(&address->peer)); |
2123 | 2165 | ||
2124 | /* Problem size changed: new address for peer with pending request */ | 2166 | /* Problem size changed: new address for peer with pending request */ |
2125 | mlp->stat_mlp_prob_changed = GNUNET_YES; | 2167 | mlp->stat_mlp_prob_changed = GNUNET_YES; |
2126 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | 2168 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) |
2127 | { | 2169 | { |
2128 | GAS_mlp_solve_problem (solver); | 2170 | GAS_mlp_solve_problem(solver); |
2129 | } | 2171 | } |
2130 | if (GNUNET_YES == was_active) | 2172 | if (GNUNET_YES == was_active) |
2131 | { | 2173 | { |
2132 | GAS_mlp_get_preferred_address (solver, &address->peer); | 2174 | GAS_mlp_get_preferred_address(solver, &address->peer); |
2133 | res = NULL; | 2175 | res = NULL; |
2134 | GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, | 2176 | GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses, |
2135 | &address->peer, | 2177 | &address->peer, |
2136 | &mlp_get_preferred_address_it, | 2178 | &mlp_get_preferred_address_it, |
2137 | &res); | 2179 | &res); |
2138 | if (NULL == res) | 2180 | if (NULL == res) |
2139 | { | 2181 | { |
2140 | /* No alternative address, disconnecting peer */ | 2182 | /* No alternative address, disconnecting peer */ |
2141 | mlp->env->bandwidth_changed_cb (mlp->env->cls, address); | 2183 | mlp->env->bandwidth_changed_cb(mlp->env->cls, address); |
2142 | } | 2184 | } |
2143 | } | 2185 | } |
2144 | } | 2186 | } |
2145 | 2187 | ||
2146 | 2188 | ||
@@ -2150,38 +2192,38 @@ GAS_mlp_address_delete (void *solver, | |||
2150 | * @param solver the solver | 2192 | * @param solver the solver |
2151 | */ | 2193 | */ |
2152 | static void | 2194 | static void |
2153 | GAS_mlp_bulk_start (void *solver) | 2195 | GAS_mlp_bulk_start(void *solver) |
2154 | { | 2196 | { |
2155 | struct GAS_MLP_Handle *s = solver; | 2197 | struct GAS_MLP_Handle *s = solver; |
2156 | 2198 | ||
2157 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2199 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2158 | "Locking solver for bulk operation ...\n"); | 2200 | "Locking solver for bulk operation ...\n"); |
2159 | GNUNET_assert (NULL != solver); | 2201 | GNUNET_assert(NULL != solver); |
2160 | s->stat_bulk_lock ++; | 2202 | s->stat_bulk_lock++; |
2161 | } | 2203 | } |
2162 | 2204 | ||
2163 | 2205 | ||
2164 | static void | 2206 | static void |
2165 | GAS_mlp_bulk_stop (void *solver) | 2207 | GAS_mlp_bulk_stop(void *solver) |
2166 | { | 2208 | { |
2167 | struct GAS_MLP_Handle *s = solver; | 2209 | struct GAS_MLP_Handle *s = solver; |
2168 | 2210 | ||
2169 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2211 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2170 | "Unlocking solver from bulk operation ...\n"); | 2212 | "Unlocking solver from bulk operation ...\n"); |
2171 | GNUNET_assert (NULL != solver); | 2213 | GNUNET_assert(NULL != solver); |
2172 | 2214 | ||
2173 | if (s->stat_bulk_lock < 1) | 2215 | if (s->stat_bulk_lock < 1) |
2174 | { | 2216 | { |
2175 | GNUNET_break (0); | 2217 | GNUNET_break(0); |
2176 | return; | 2218 | return; |
2177 | } | 2219 | } |
2178 | s->stat_bulk_lock --; | 2220 | s->stat_bulk_lock--; |
2179 | 2221 | ||
2180 | if (0 < s->stat_bulk_requests) | 2222 | if (0 < s->stat_bulk_requests) |
2181 | { | 2223 | { |
2182 | GAS_mlp_solve_problem (solver); | 2224 | GAS_mlp_solve_problem(solver); |
2183 | s->stat_bulk_requests= 0; | 2225 | s->stat_bulk_requests = 0; |
2184 | } | 2226 | } |
2185 | } | 2227 | } |
2186 | 2228 | ||
2187 | 2229 | ||
@@ -2193,26 +2235,26 @@ GAS_mlp_bulk_stop (void *solver) | |||
2193 | * @param peer the peer | 2235 | * @param peer the peer |
2194 | */ | 2236 | */ |
2195 | static void | 2237 | static void |
2196 | GAS_mlp_stop_get_preferred_address (void *solver, | 2238 | GAS_mlp_stop_get_preferred_address(void *solver, |
2197 | const struct GNUNET_PeerIdentity *peer) | 2239 | const struct GNUNET_PeerIdentity *peer) |
2198 | { | 2240 | { |
2199 | struct GAS_MLP_Handle *mlp = solver; | 2241 | struct GAS_MLP_Handle *mlp = solver; |
2200 | struct ATS_Peer *p = NULL; | 2242 | struct ATS_Peer *p = NULL; |
2201 | 2243 | ||
2202 | GNUNET_assert (NULL != solver); | 2244 | GNUNET_assert(NULL != solver); |
2203 | GNUNET_assert (NULL != peer); | 2245 | GNUNET_assert(NULL != peer); |
2204 | if (NULL != (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) | 2246 | if (NULL != (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer))) |
2205 | { | ||
2206 | GNUNET_assert (GNUNET_YES == | ||
2207 | GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers, peer, p)); | ||
2208 | GNUNET_free (p); | ||
2209 | |||
2210 | mlp->stat_mlp_prob_changed = GNUNET_YES; | ||
2211 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | ||
2212 | { | 2247 | { |
2213 | GAS_mlp_solve_problem (solver); | 2248 | GNUNET_assert(GNUNET_YES == |
2249 | GNUNET_CONTAINER_multipeermap_remove(mlp->requested_peers, peer, p)); | ||
2250 | GNUNET_free(p); | ||
2251 | |||
2252 | mlp->stat_mlp_prob_changed = GNUNET_YES; | ||
2253 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | ||
2254 | { | ||
2255 | GAS_mlp_solve_problem(solver); | ||
2256 | } | ||
2214 | } | 2257 | } |
2215 | } | ||
2216 | } | 2258 | } |
2217 | 2259 | ||
2218 | 2260 | ||
@@ -2225,48 +2267,48 @@ GAS_mlp_stop_get_preferred_address (void *solver, | |||
2225 | * @param pref_rel the relative score | 2267 | * @param pref_rel the relative score |
2226 | */ | 2268 | */ |
2227 | static void | 2269 | static void |
2228 | GAS_mlp_address_change_preference (void *solver, | 2270 | GAS_mlp_address_change_preference(void *solver, |
2229 | const struct GNUNET_PeerIdentity *peer, | 2271 | const struct GNUNET_PeerIdentity *peer, |
2230 | enum GNUNET_ATS_PreferenceKind kind, | 2272 | enum GNUNET_ATS_PreferenceKind kind, |
2231 | double pref_rel) | 2273 | double pref_rel) |
2232 | { | 2274 | { |
2233 | struct GAS_MLP_Handle *mlp = solver; | 2275 | struct GAS_MLP_Handle *mlp = solver; |
2234 | struct ATS_Peer *p; | 2276 | struct ATS_Peer *p; |
2235 | 2277 | ||
2236 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2278 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2237 | "Changing preference for address for peer `%s' to %.2f\n", | 2279 | "Changing preference for address for peer `%s' to %.2f\n", |
2238 | GNUNET_i2s(peer), | 2280 | GNUNET_i2s(peer), |
2239 | pref_rel); | 2281 | pref_rel); |
2240 | 2282 | ||
2241 | GNUNET_STATISTICS_update (mlp->env->stats, | 2283 | GNUNET_STATISTICS_update(mlp->env->stats, |
2242 | "# LP address preference changes", 1, GNUNET_NO); | 2284 | "# LP address preference changes", 1, GNUNET_NO); |
2243 | /* Update the constraints with changed preferences */ | 2285 | /* Update the constraints with changed preferences */ |
2244 | 2286 | ||
2245 | 2287 | ||
2246 | 2288 | ||
2247 | /* Update relativity constraint c9 */ | 2289 | /* Update relativity constraint c9 */ |
2248 | if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, peer))) | 2290 | if (NULL == (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer))) |
2249 | { | 2291 | { |
2250 | LOG (GNUNET_ERROR_TYPE_INFO, | 2292 | LOG(GNUNET_ERROR_TYPE_INFO, |
2251 | "Updating preference for unknown peer `%s'\n", | 2293 | "Updating preference for unknown peer `%s'\n", |
2252 | GNUNET_i2s(peer)); | 2294 | GNUNET_i2s(peer)); |
2253 | return; | 2295 | return; |
2254 | } | 2296 | } |
2255 | 2297 | ||
2256 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) | 2298 | if (GNUNET_NO == mlp->opt_dbg_feasibility_only) |
2257 | { | 2299 | { |
2258 | p->f = get_peer_pref_value (mlp, peer); | 2300 | p->f = get_peer_pref_value(mlp, peer); |
2259 | mlp_create_problem_update_value (&mlp->p, | 2301 | mlp_create_problem_update_value(&mlp->p, |
2260 | p->r_c9, | 2302 | p->r_c9, |
2261 | mlp->p.c_r, | 2303 | mlp->p.c_r, |
2262 | - p->f, | 2304 | -p->f, |
2263 | __LINE__); | 2305 | __LINE__); |
2264 | 2306 | ||
2265 | /* Problem size changed: new address for peer with pending request */ | 2307 | /* Problem size changed: new address for peer with pending request */ |
2266 | mlp->stat_mlp_prob_updated = GNUNET_YES; | 2308 | mlp->stat_mlp_prob_updated = GNUNET_YES; |
2267 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) | 2309 | if (GNUNET_YES == mlp->opt_mlp_auto_solve) |
2268 | GAS_mlp_solve_problem (solver); | 2310 | GAS_mlp_solve_problem(solver); |
2269 | } | 2311 | } |
2270 | } | 2312 | } |
2271 | 2313 | ||
2272 | 2314 | ||
@@ -2281,31 +2323,31 @@ GAS_mlp_address_change_preference (void *solver, | |||
2281 | * @param score the score | 2323 | * @param score the score |
2282 | */ | 2324 | */ |
2283 | static void | 2325 | static void |
2284 | GAS_mlp_address_preference_feedback (void *solver, | 2326 | GAS_mlp_address_preference_feedback(void *solver, |
2285 | struct GNUNET_SERVICE_Client *application, | 2327 | struct GNUNET_SERVICE_Client *application, |
2286 | const struct GNUNET_PeerIdentity *peer, | 2328 | const struct GNUNET_PeerIdentity *peer, |
2287 | const struct GNUNET_TIME_Relative scope, | 2329 | const struct GNUNET_TIME_Relative scope, |
2288 | enum GNUNET_ATS_PreferenceKind kind, | 2330 | enum GNUNET_ATS_PreferenceKind kind, |
2289 | double score) | 2331 | double score) |
2290 | { | 2332 | { |
2291 | struct GAS_PROPORTIONAL_Handle *s = solver; | 2333 | struct GAS_PROPORTIONAL_Handle *s = solver; |
2292 | 2334 | ||
2293 | GNUNET_assert (NULL != solver); | 2335 | GNUNET_assert(NULL != solver); |
2294 | GNUNET_assert (NULL != peer); | 2336 | GNUNET_assert(NULL != peer); |
2295 | GNUNET_assert (NULL != s); | 2337 | GNUNET_assert(NULL != s); |
2296 | } | 2338 | } |
2297 | 2339 | ||
2298 | 2340 | ||
2299 | static int | 2341 | static int |
2300 | mlp_free_peers (void *cls, | 2342 | mlp_free_peers(void *cls, |
2301 | const struct GNUNET_PeerIdentity *key, void *value) | 2343 | const struct GNUNET_PeerIdentity *key, void *value) |
2302 | { | 2344 | { |
2303 | struct GNUNET_CONTAINER_MultiPeerMap *map = cls; | 2345 | struct GNUNET_CONTAINER_MultiPeerMap *map = cls; |
2304 | struct ATS_Peer *p = value; | 2346 | struct ATS_Peer *p = value; |
2305 | 2347 | ||
2306 | GNUNET_assert (GNUNET_YES == | 2348 | GNUNET_assert(GNUNET_YES == |
2307 | GNUNET_CONTAINER_multipeermap_remove (map, key, value)); | 2349 | GNUNET_CONTAINER_multipeermap_remove(map, key, value)); |
2308 | GNUNET_free (p); | 2350 | GNUNET_free(p); |
2309 | 2351 | ||
2310 | return GNUNET_OK; | 2352 | return GNUNET_OK; |
2311 | } | 2353 | } |
@@ -2318,36 +2360,36 @@ mlp_free_peers (void *cls, | |||
2318 | * @return NULL | 2360 | * @return NULL |
2319 | */ | 2361 | */ |
2320 | void * | 2362 | void * |
2321 | libgnunet_plugin_ats_mlp_done (void *cls) | 2363 | libgnunet_plugin_ats_mlp_done(void *cls) |
2322 | { | 2364 | { |
2323 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 2365 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
2324 | struct GAS_MLP_Handle *mlp = sf->cls; | 2366 | struct GAS_MLP_Handle *mlp = sf->cls; |
2325 | 2367 | ||
2326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2368 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2327 | "Shutting down mlp solver\n"); | 2369 | "Shutting down mlp solver\n"); |
2328 | mlp_delete_problem (mlp); | 2370 | mlp_delete_problem(mlp); |
2329 | GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers, | 2371 | GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers, |
2330 | &mlp_free_peers, | 2372 | &mlp_free_peers, |
2331 | mlp->requested_peers); | 2373 | mlp->requested_peers); |
2332 | GNUNET_CONTAINER_multipeermap_destroy (mlp->requested_peers); | 2374 | GNUNET_CONTAINER_multipeermap_destroy(mlp->requested_peers); |
2333 | mlp->requested_peers = NULL; | 2375 | mlp->requested_peers = NULL; |
2334 | 2376 | ||
2335 | /* Clean up GLPK environment */ | 2377 | /* Clean up GLPK environment */ |
2336 | glp_free_env(); | 2378 | glp_free_env(); |
2337 | GNUNET_free (mlp); | 2379 | GNUNET_free(mlp); |
2338 | 2380 | ||
2339 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2381 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2340 | "Shutdown down of mlp solver complete\n"); | 2382 | "Shutdown down of mlp solver complete\n"); |
2341 | return NULL; | 2383 | return NULL; |
2342 | } | 2384 | } |
2343 | 2385 | ||
2344 | 2386 | ||
2345 | void * | 2387 | void * |
2346 | libgnunet_plugin_ats_mlp_init (void *cls) | 2388 | libgnunet_plugin_ats_mlp_init(void *cls) |
2347 | { | 2389 | { |
2348 | static struct GNUNET_ATS_SolverFunctions sf; | 2390 | static struct GNUNET_ATS_SolverFunctions sf; |
2349 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 2391 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
2350 | struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle); | 2392 | struct GAS_MLP_Handle * mlp = GNUNET_new(struct GAS_MLP_Handle); |
2351 | float f_tmp; | 2393 | float f_tmp; |
2352 | unsigned long long tmp; | 2394 | unsigned long long tmp; |
2353 | unsigned int b_min; | 2395 | unsigned int b_min; |
@@ -2360,349 +2402,355 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2360 | 2402 | ||
2361 | /* Init GLPK environment */ | 2403 | /* Init GLPK environment */ |
2362 | int res = glp_init_env(); | 2404 | int res = glp_init_env(); |
2363 | switch (res) { | 2405 | |
2406 | switch (res) | ||
2407 | { | ||
2364 | case 0: | 2408 | case 0: |
2365 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", | 2409 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", |
2366 | "initialization successful"); | 2410 | "initialization successful"); |
2367 | break; | 2411 | break; |
2412 | |||
2368 | case 1: | 2413 | case 1: |
2369 | LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", | 2414 | LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", |
2370 | "environment is already initialized"); | 2415 | "environment is already initialized"); |
2371 | break; | 2416 | break; |
2417 | |||
2372 | case 2: | 2418 | case 2: |
2373 | LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", | 2419 | LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", |
2374 | "initialization failed (insufficient memory)"); | 2420 | "initialization failed (insufficient memory)"); |
2375 | GNUNET_free(mlp); | 2421 | GNUNET_free(mlp); |
2376 | return NULL; | 2422 | return NULL; |
2377 | break; | 2423 | break; |
2424 | |||
2378 | case 3: | 2425 | case 3: |
2379 | LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", | 2426 | LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", |
2380 | "initialization failed (unsupported programming model)"); | 2427 | "initialization failed (unsupported programming model)"); |
2381 | GNUNET_free(mlp); | 2428 | GNUNET_free(mlp); |
2382 | return NULL; | 2429 | return NULL; |
2383 | break; | 2430 | break; |
2431 | |||
2384 | default: | 2432 | default: |
2385 | break; | 2433 | break; |
2386 | } | 2434 | } |
2387 | 2435 | ||
2388 | mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2436 | mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2389 | "ats", "MLP_DUMP_PROBLEM_ALL"); | 2437 | "ats", "MLP_DUMP_PROBLEM_ALL"); |
2390 | if (GNUNET_SYSERR == mlp->opt_dump_problem_all) | 2438 | if (GNUNET_SYSERR == mlp->opt_dump_problem_all) |
2391 | mlp->opt_dump_problem_all = GNUNET_NO; | 2439 | mlp->opt_dump_problem_all = GNUNET_NO; |
2392 | 2440 | ||
2393 | mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2441 | mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2394 | "ats", "MLP_DUMP_SOLUTION_ALL"); | 2442 | "ats", "MLP_DUMP_SOLUTION_ALL"); |
2395 | if (GNUNET_SYSERR == mlp->opt_dump_solution_all) | 2443 | if (GNUNET_SYSERR == mlp->opt_dump_solution_all) |
2396 | mlp->opt_dump_solution_all = GNUNET_NO; | 2444 | mlp->opt_dump_solution_all = GNUNET_NO; |
2397 | 2445 | ||
2398 | mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2446 | mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2399 | "ats", "MLP_DUMP_PROBLEM_ON_FAIL"); | 2447 | "ats", "MLP_DUMP_PROBLEM_ON_FAIL"); |
2400 | if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail) | 2448 | if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail) |
2401 | mlp->opt_dump_problem_on_fail = GNUNET_NO; | 2449 | mlp->opt_dump_problem_on_fail = GNUNET_NO; |
2402 | 2450 | ||
2403 | mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2451 | mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2404 | "ats", "MLP_DUMP_SOLUTION_ON_FAIL"); | 2452 | "ats", "MLP_DUMP_SOLUTION_ON_FAIL"); |
2405 | if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail) | 2453 | if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail) |
2406 | mlp->opt_dump_solution_on_fail = GNUNET_NO; | 2454 | mlp->opt_dump_solution_on_fail = GNUNET_NO; |
2407 | 2455 | ||
2408 | mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2456 | mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2409 | "ats", "MLP_DBG_GLPK_VERBOSE"); | 2457 | "ats", "MLP_DBG_GLPK_VERBOSE"); |
2410 | if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose) | 2458 | if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose) |
2411 | mlp->opt_dbg_glpk_verbose = GNUNET_NO; | 2459 | mlp->opt_dbg_glpk_verbose = GNUNET_NO; |
2412 | 2460 | ||
2413 | mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2461 | mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2414 | "ats", "MLP_DBG_FEASIBILITY_ONLY"); | 2462 | "ats", "MLP_DBG_FEASIBILITY_ONLY"); |
2415 | if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only) | 2463 | if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only) |
2416 | mlp->opt_dbg_feasibility_only = GNUNET_NO; | 2464 | mlp->opt_dbg_feasibility_only = GNUNET_NO; |
2417 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) | 2465 | if (GNUNET_YES == mlp->opt_dbg_feasibility_only) |
2418 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2466 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2419 | "MLP solver is configured to check feasibility only!\n"); | 2467 | "MLP solver is configured to check feasibility only!\n"); |
2420 | 2468 | ||
2421 | mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2469 | mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2422 | "ats", "MLP_DBG_AUTOSCALE_PROBLEM"); | 2470 | "ats", "MLP_DBG_AUTOSCALE_PROBLEM"); |
2423 | if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem) | 2471 | if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem) |
2424 | mlp->opt_dbg_autoscale_problem = GNUNET_NO; | 2472 | mlp->opt_dbg_autoscale_problem = GNUNET_NO; |
2425 | if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) | 2473 | if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) |
2426 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2474 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2427 | "MLP solver is configured automatically scale the problem!\n"); | 2475 | "MLP solver is configured automatically scale the problem!\n"); |
2428 | 2476 | ||
2429 | mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2477 | mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2430 | "ats", "MLP_DBG_INTOPT_PRESOLVE"); | 2478 | "ats", "MLP_DBG_INTOPT_PRESOLVE"); |
2431 | if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver) | 2479 | if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver) |
2432 | mlp->opt_dbg_intopt_presolver = GNUNET_NO; | 2480 | mlp->opt_dbg_intopt_presolver = GNUNET_NO; |
2433 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) | 2481 | if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) |
2434 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2482 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2435 | "MLP solver is configured use the mlp presolver\n"); | 2483 | "MLP solver is configured use the mlp presolver\n"); |
2436 | 2484 | ||
2437 | mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2485 | mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2438 | "ats", "MLP_DBG_OPTIMIZE_DIVERSITY"); | 2486 | "ats", "MLP_DBG_OPTIMIZE_DIVERSITY"); |
2439 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity) | 2487 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity) |
2440 | mlp->opt_dbg_optimize_diversity = GNUNET_YES; | 2488 | mlp->opt_dbg_optimize_diversity = GNUNET_YES; |
2441 | if (GNUNET_NO == mlp->opt_dbg_optimize_diversity) | 2489 | if (GNUNET_NO == mlp->opt_dbg_optimize_diversity) |
2442 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2490 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2443 | "MLP solver is not optimizing for diversity\n"); | 2491 | "MLP solver is not optimizing for diversity\n"); |
2444 | 2492 | ||
2445 | mlp->opt_dbg_optimize_relativity= GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2493 | mlp->opt_dbg_optimize_relativity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2446 | "ats", "MLP_DBG_OPTIMIZE_RELATIVITY"); | 2494 | "ats", "MLP_DBG_OPTIMIZE_RELATIVITY"); |
2447 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity) | 2495 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity) |
2448 | mlp->opt_dbg_optimize_relativity = GNUNET_YES; | 2496 | mlp->opt_dbg_optimize_relativity = GNUNET_YES; |
2449 | if (GNUNET_NO == mlp->opt_dbg_optimize_relativity) | 2497 | if (GNUNET_NO == mlp->opt_dbg_optimize_relativity) |
2450 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2498 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2451 | "MLP solver is not optimizing for relativity\n"); | 2499 | "MLP solver is not optimizing for relativity\n"); |
2452 | 2500 | ||
2453 | mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2501 | mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2454 | "ats", "MLP_DBG_OPTIMIZE_QUALITY"); | 2502 | "ats", "MLP_DBG_OPTIMIZE_QUALITY"); |
2455 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality) | 2503 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality) |
2456 | mlp->opt_dbg_optimize_quality = GNUNET_YES; | 2504 | mlp->opt_dbg_optimize_quality = GNUNET_YES; |
2457 | if (GNUNET_NO == mlp->opt_dbg_optimize_quality) | 2505 | if (GNUNET_NO == mlp->opt_dbg_optimize_quality) |
2458 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2506 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2459 | "MLP solver is not optimizing for quality\n"); | 2507 | "MLP solver is not optimizing for quality\n"); |
2460 | 2508 | ||
2461 | mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 2509 | mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, |
2462 | "ats", "MLP_DBG_OPTIMIZE_UTILITY"); | 2510 | "ats", "MLP_DBG_OPTIMIZE_UTILITY"); |
2463 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility) | 2511 | if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility) |
2464 | mlp->opt_dbg_optimize_utility = GNUNET_YES; | 2512 | mlp->opt_dbg_optimize_utility = GNUNET_YES; |
2465 | if (GNUNET_NO == mlp->opt_dbg_optimize_utility) | 2513 | if (GNUNET_NO == mlp->opt_dbg_optimize_utility) |
2466 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2514 | LOG(GNUNET_ERROR_TYPE_WARNING, |
2467 | "MLP solver is not optimizing for utility\n"); | 2515 | "MLP solver is not optimizing for utility\n"); |
2468 | 2516 | ||
2469 | if ( (GNUNET_NO == mlp->opt_dbg_optimize_utility) && | 2517 | if ((GNUNET_NO == mlp->opt_dbg_optimize_utility) && |
2470 | (GNUNET_NO == mlp->opt_dbg_optimize_quality) && | 2518 | (GNUNET_NO == mlp->opt_dbg_optimize_quality) && |
2471 | (GNUNET_NO == mlp->opt_dbg_optimize_relativity) && | 2519 | (GNUNET_NO == mlp->opt_dbg_optimize_relativity) && |
2472 | (GNUNET_NO == mlp->opt_dbg_optimize_utility) && | 2520 | (GNUNET_NO == mlp->opt_dbg_optimize_utility) && |
2473 | (GNUNET_NO == mlp->opt_dbg_feasibility_only)) | 2521 | (GNUNET_NO == mlp->opt_dbg_feasibility_only)) |
2474 | { | ||
2475 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2476 | _("MLP solver is not optimizing for anything, changing to feasibility check\n")); | ||
2477 | mlp->opt_dbg_feasibility_only = GNUNET_YES; | ||
2478 | } | ||
2479 | |||
2480 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg, | ||
2481 | "ats", "MLP_LOG_FORMAT", &outputformat)) | ||
2482 | mlp->opt_log_format = MLP_CPLEX; | ||
2483 | else | ||
2484 | { | ||
2485 | GNUNET_STRINGS_utf8_toupper(outputformat, outputformat); | ||
2486 | if (0 == strcmp (outputformat, "MPS")) | ||
2487 | { | ||
2488 | mlp->opt_log_format = MLP_MPS; | ||
2489 | } | ||
2490 | else if (0 == strcmp (outputformat, "CPLEX")) | ||
2491 | { | 2522 | { |
2492 | mlp->opt_log_format = MLP_CPLEX; | 2523 | LOG(GNUNET_ERROR_TYPE_ERROR, |
2524 | _("MLP solver is not optimizing for anything, changing to feasibility check\n")); | ||
2525 | mlp->opt_dbg_feasibility_only = GNUNET_YES; | ||
2493 | } | 2526 | } |
2494 | else if (0 == strcmp (outputformat, "GLPK")) | 2527 | |
2495 | { | 2528 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(env->cfg, |
2496 | mlp->opt_log_format = MLP_GLPK; | 2529 | "ats", "MLP_LOG_FORMAT", &outputformat)) |
2497 | } | 2530 | mlp->opt_log_format = MLP_CPLEX; |
2498 | else | 2531 | else |
2499 | { | 2532 | { |
2500 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2533 | GNUNET_STRINGS_utf8_toupper(outputformat, outputformat); |
2501 | "Invalid log format `%s' in configuration, using CPLEX!\n", | 2534 | if (0 == strcmp(outputformat, "MPS")) |
2502 | outputformat); | 2535 | { |
2503 | mlp->opt_log_format = MLP_CPLEX; | 2536 | mlp->opt_log_format = MLP_MPS; |
2537 | } | ||
2538 | else if (0 == strcmp(outputformat, "CPLEX")) | ||
2539 | { | ||
2540 | mlp->opt_log_format = MLP_CPLEX; | ||
2541 | } | ||
2542 | else if (0 == strcmp(outputformat, "GLPK")) | ||
2543 | { | ||
2544 | mlp->opt_log_format = MLP_GLPK; | ||
2545 | } | ||
2546 | else | ||
2547 | { | ||
2548 | LOG(GNUNET_ERROR_TYPE_WARNING, | ||
2549 | "Invalid log format `%s' in configuration, using CPLEX!\n", | ||
2550 | outputformat); | ||
2551 | mlp->opt_log_format = MLP_CPLEX; | ||
2552 | } | ||
2553 | GNUNET_free(outputformat); | ||
2504 | } | 2554 | } |
2505 | GNUNET_free (outputformat); | ||
2506 | } | ||
2507 | 2555 | ||
2508 | mlp->pv.BIG_M = (double) BIG_M_VALUE; | 2556 | mlp->pv.BIG_M = (double)BIG_M_VALUE; |
2509 | 2557 | ||
2510 | mlp->pv.mip_gap = (double) 0.0; | 2558 | mlp->pv.mip_gap = (double)0.0; |
2511 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2559 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2512 | "MLP_MAX_MIP_GAP", &f_tmp)) | 2560 | "MLP_MAX_MIP_GAP", &f_tmp)) |
2513 | { | ||
2514 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2515 | { | ||
2516 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2517 | "MIP gap", f_tmp); | ||
2518 | } | ||
2519 | else | ||
2520 | { | 2561 | { |
2521 | mlp->pv.mip_gap = f_tmp; | 2562 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2522 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2563 | { |
2523 | "MIP gap", f_tmp); | 2564 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2565 | "MIP gap", f_tmp); | ||
2566 | } | ||
2567 | else | ||
2568 | { | ||
2569 | mlp->pv.mip_gap = f_tmp; | ||
2570 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2571 | "MIP gap", f_tmp); | ||
2572 | } | ||
2524 | } | 2573 | } |
2525 | } | ||
2526 | 2574 | ||
2527 | mlp->pv.lp_mip_gap = (double) 0.0; | 2575 | mlp->pv.lp_mip_gap = (double)0.0; |
2528 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2576 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2529 | "MLP_MAX_LP_MIP_GAP", &f_tmp)) | 2577 | "MLP_MAX_LP_MIP_GAP", &f_tmp)) |
2530 | { | ||
2531 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2532 | { | ||
2533 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2534 | "LP/MIP", f_tmp); | ||
2535 | } | ||
2536 | else | ||
2537 | { | 2578 | { |
2538 | mlp->pv.lp_mip_gap = f_tmp; | 2579 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2539 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | 2580 | { |
2540 | "LP/MIP", f_tmp); | 2581 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2582 | "LP/MIP", f_tmp); | ||
2583 | } | ||
2584 | else | ||
2585 | { | ||
2586 | mlp->pv.lp_mip_gap = f_tmp; | ||
2587 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | ||
2588 | "LP/MIP", f_tmp); | ||
2589 | } | ||
2541 | } | 2590 | } |
2542 | } | ||
2543 | 2591 | ||
2544 | /* Get timeout for iterations */ | 2592 | /* Get timeout for iterations */ |
2545 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", | 2593 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", |
2546 | "MLP_MAX_DURATION", &max_duration)) | 2594 | "MLP_MAX_DURATION", &max_duration)) |
2547 | { | 2595 | { |
2548 | max_duration = MLP_MAX_EXEC_DURATION; | 2596 | max_duration = MLP_MAX_EXEC_DURATION; |
2549 | } | 2597 | } |
2550 | 2598 | ||
2551 | /* Get maximum number of iterations */ | 2599 | /* Get maximum number of iterations */ |
2552 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", | 2600 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", |
2553 | "MLP_MAX_ITERATIONS", &max_iterations)) | 2601 | "MLP_MAX_ITERATIONS", &max_iterations)) |
2554 | { | 2602 | { |
2555 | max_iterations = MLP_MAX_ITERATIONS; | 2603 | max_iterations = MLP_MAX_ITERATIONS; |
2556 | } | 2604 | } |
2557 | 2605 | ||
2558 | /* Get diversity coefficient from configuration */ | 2606 | /* Get diversity coefficient from configuration */ |
2559 | mlp->pv.co_D = MLP_DEFAULT_D; | 2607 | mlp->pv.co_D = MLP_DEFAULT_D; |
2560 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2608 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2561 | "MLP_COEFFICIENT_D", &f_tmp)) | 2609 | "MLP_COEFFICIENT_D", &f_tmp)) |
2562 | { | ||
2563 | if ((f_tmp < 0.0)) | ||
2564 | { | ||
2565 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2566 | "MLP_COEFFICIENT_D", f_tmp); | ||
2567 | } | ||
2568 | else | ||
2569 | { | 2610 | { |
2570 | mlp->pv.co_D = f_tmp; | 2611 | if ((f_tmp < 0.0)) |
2571 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | 2612 | { |
2572 | "MLP_COEFFICIENT_D", f_tmp); | 2613 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2614 | "MLP_COEFFICIENT_D", f_tmp); | ||
2615 | } | ||
2616 | else | ||
2617 | { | ||
2618 | mlp->pv.co_D = f_tmp; | ||
2619 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | ||
2620 | "MLP_COEFFICIENT_D", f_tmp); | ||
2621 | } | ||
2573 | } | 2622 | } |
2574 | } | ||
2575 | 2623 | ||
2576 | /* Get relativity coefficient from configuration */ | 2624 | /* Get relativity coefficient from configuration */ |
2577 | mlp->pv.co_R = MLP_DEFAULT_R; | 2625 | mlp->pv.co_R = MLP_DEFAULT_R; |
2578 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2626 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2579 | "MLP_COEFFICIENT_R", &f_tmp)) | 2627 | "MLP_COEFFICIENT_R", &f_tmp)) |
2580 | { | ||
2581 | if ((f_tmp < 0.0)) | ||
2582 | { | ||
2583 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2584 | "MLP_COEFFICIENT_R", f_tmp); | ||
2585 | } | ||
2586 | else | ||
2587 | { | 2628 | { |
2588 | mlp->pv.co_R = f_tmp; | 2629 | if ((f_tmp < 0.0)) |
2589 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | 2630 | { |
2590 | "MLP_COEFFICIENT_R", f_tmp); | 2631 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2632 | "MLP_COEFFICIENT_R", f_tmp); | ||
2633 | } | ||
2634 | else | ||
2635 | { | ||
2636 | mlp->pv.co_R = f_tmp; | ||
2637 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | ||
2638 | "MLP_COEFFICIENT_R", f_tmp); | ||
2639 | } | ||
2591 | } | 2640 | } |
2592 | } | ||
2593 | 2641 | ||
2594 | 2642 | ||
2595 | /* Get utilization coefficient from configuration */ | 2643 | /* Get utilization coefficient from configuration */ |
2596 | mlp->pv.co_U = MLP_DEFAULT_U; | 2644 | mlp->pv.co_U = MLP_DEFAULT_U; |
2597 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2645 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2598 | "MLP_COEFFICIENT_U", &f_tmp)) | 2646 | "MLP_COEFFICIENT_U", &f_tmp)) |
2599 | { | ||
2600 | if ((f_tmp < 0.0)) | ||
2601 | { | ||
2602 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2603 | "MLP_COEFFICIENT_U", f_tmp); | ||
2604 | } | ||
2605 | else | ||
2606 | { | 2647 | { |
2607 | mlp->pv.co_U = f_tmp; | 2648 | if ((f_tmp < 0.0)) |
2608 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | 2649 | { |
2609 | "MLP_COEFFICIENT_U", f_tmp); | 2650 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2651 | "MLP_COEFFICIENT_U", f_tmp); | ||
2652 | } | ||
2653 | else | ||
2654 | { | ||
2655 | mlp->pv.co_U = f_tmp; | ||
2656 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n", | ||
2657 | "MLP_COEFFICIENT_U", f_tmp); | ||
2658 | } | ||
2610 | } | 2659 | } |
2611 | } | ||
2612 | 2660 | ||
2613 | /* Get quality metric coefficients from configuration */ | 2661 | /* Get quality metric coefficients from configuration */ |
2614 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) | 2662 | for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) |
2615 | { | 2663 | { |
2616 | /* initialize quality coefficients with default value 1.0 */ | 2664 | /* initialize quality coefficients with default value 1.0 */ |
2617 | mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; | 2665 | mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; |
2618 | } | 2666 | } |
2619 | 2667 | ||
2620 | 2668 | ||
2621 | if (GNUNET_OK == | 2669 | if (GNUNET_OK == |
2622 | GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2670 | GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", |
2623 | "MLP_COEFFICIENT_QUALITY_DELAY", | 2671 | "MLP_COEFFICIENT_QUALITY_DELAY", |
2624 | &tmp)) | 2672 | &tmp)) |
2625 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100; | 2673 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double)tmp / 100; |
2626 | else | 2674 | else |
2627 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY; | 2675 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY; |
2628 | 2676 | ||
2629 | if (GNUNET_OK == | 2677 | if (GNUNET_OK == |
2630 | GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2678 | GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", |
2631 | "MLP_COEFFICIENT_QUALITY_DISTANCE", | 2679 | "MLP_COEFFICIENT_QUALITY_DISTANCE", |
2632 | &tmp)) | 2680 | &tmp)) |
2633 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100; | 2681 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double)tmp / 100; |
2634 | else | 2682 | else |
2635 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY; | 2683 | mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY; |
2636 | 2684 | ||
2637 | /* Get minimum bandwidth per used address from configuration */ | 2685 | /* Get minimum bandwidth per used address from configuration */ |
2638 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2686 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", |
2639 | "MLP_MIN_BANDWIDTH", | 2687 | "MLP_MIN_BANDWIDTH", |
2640 | &tmp)) | 2688 | &tmp)) |
2641 | b_min = tmp; | 2689 | b_min = tmp; |
2642 | else | 2690 | else |
2643 | { | 2691 | { |
2644 | b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 2692 | b_min = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
2645 | } | 2693 | } |
2646 | 2694 | ||
2647 | /* Get minimum number of connections from configuration */ | 2695 | /* Get minimum number of connections from configuration */ |
2648 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats", | 2696 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", |
2649 | "MLP_MIN_CONNECTIONS", | 2697 | "MLP_MIN_CONNECTIONS", |
2650 | &tmp)) | 2698 | &tmp)) |
2651 | n_min = tmp; | 2699 | n_min = tmp; |
2652 | else | 2700 | else |
2653 | n_min = MLP_DEFAULT_MIN_CONNECTIONS; | 2701 | n_min = MLP_DEFAULT_MIN_CONNECTIONS; |
2654 | 2702 | ||
2655 | /* Init network quotas */ | 2703 | /* Init network quotas */ |
2656 | for (c = 0; c < GNUNET_NT_COUNT; c++) | 2704 | for (c = 0; c < GNUNET_NT_COUNT; c++) |
2657 | { | 2705 | { |
2658 | mlp->pv.quota_index[c] = c; | 2706 | mlp->pv.quota_index[c] = c; |
2659 | mlp->pv.quota_out[c] = env->out_quota[c]; | 2707 | mlp->pv.quota_out[c] = env->out_quota[c]; |
2660 | mlp->pv.quota_in[c] = env->in_quota[c]; | 2708 | mlp->pv.quota_in[c] = env->in_quota[c]; |
2661 | 2709 | ||
2662 | LOG (GNUNET_ERROR_TYPE_INFO, | 2710 | LOG(GNUNET_ERROR_TYPE_INFO, |
2663 | "Quota for network `%s' (in/out) %llu/%llu\n", | 2711 | "Quota for network `%s' (in/out) %llu/%llu\n", |
2664 | GNUNET_NT_to_string (c), | 2712 | GNUNET_NT_to_string(c), |
2665 | mlp->pv.quota_out[c], | 2713 | mlp->pv.quota_out[c], |
2666 | mlp->pv.quota_in[c]); | 2714 | mlp->pv.quota_in[c]); |
2667 | /* Check if defined quota could make problem unsolvable */ | 2715 | /* Check if defined quota could make problem unsolvable */ |
2668 | if ((n_min * b_min) > mlp->pv.quota_out[c]) | 2716 | if ((n_min * b_min) > mlp->pv.quota_out[c]) |
2669 | { | 2717 | { |
2670 | LOG (GNUNET_ERROR_TYPE_INFO, | 2718 | LOG(GNUNET_ERROR_TYPE_INFO, |
2671 | _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), | 2719 | _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), |
2672 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), | 2720 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), |
2673 | mlp->pv.quota_out[c], | 2721 | mlp->pv.quota_out[c], |
2674 | (n_min * b_min)); | 2722 | (n_min * b_min)); |
2675 | mlp->pv.quota_out[c] = (n_min * b_min); | 2723 | mlp->pv.quota_out[c] = (n_min * b_min); |
2676 | } | 2724 | } |
2677 | if ((n_min * b_min) > mlp->pv.quota_in[c]) | 2725 | if ((n_min * b_min) > mlp->pv.quota_in[c]) |
2678 | { | 2726 | { |
2679 | LOG (GNUNET_ERROR_TYPE_INFO, | 2727 | LOG(GNUNET_ERROR_TYPE_INFO, |
2680 | _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), | 2728 | _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), |
2681 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), | 2729 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), |
2682 | mlp->pv.quota_in[c], | 2730 | mlp->pv.quota_in[c], |
2683 | (n_min * b_min)); | 2731 | (n_min * b_min)); |
2684 | mlp->pv.quota_in[c] = (n_min * b_min); | 2732 | mlp->pv.quota_in[c] = (n_min * b_min); |
2685 | } | 2733 | } |
2686 | /* Check if bandwidth is too big to make problem solvable */ | 2734 | /* Check if bandwidth is too big to make problem solvable */ |
2687 | if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) | 2735 | if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) |
2688 | { | 2736 | { |
2689 | LOG (GNUNET_ERROR_TYPE_INFO, | 2737 | LOG(GNUNET_ERROR_TYPE_INFO, |
2690 | _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), | 2738 | _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), |
2691 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), | 2739 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), |
2692 | mlp->pv.quota_out[c], | 2740 | mlp->pv.quota_out[c], |
2693 | mlp->pv.BIG_M); | 2741 | mlp->pv.BIG_M); |
2694 | mlp->pv.quota_out[c] = mlp->pv.BIG_M ; | 2742 | mlp->pv.quota_out[c] = mlp->pv.BIG_M; |
2695 | } | 2743 | } |
2696 | if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) | 2744 | if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) |
2697 | { | 2745 | { |
2698 | LOG (GNUNET_ERROR_TYPE_INFO, | 2746 | LOG(GNUNET_ERROR_TYPE_INFO, |
2699 | _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), | 2747 | _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), |
2700 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), | 2748 | GNUNET_NT_to_string(mlp->pv.quota_index[c]), |
2701 | mlp->pv.quota_in[c], | 2749 | mlp->pv.quota_in[c], |
2702 | mlp->pv.BIG_M); | 2750 | mlp->pv.BIG_M); |
2703 | mlp->pv.quota_in[c] = mlp->pv.BIG_M ; | 2751 | mlp->pv.quota_in[c] = mlp->pv.BIG_M; |
2704 | } | 2752 | } |
2705 | } | 2753 | } |
2706 | mlp->env = env; | 2754 | mlp->env = env; |
2707 | sf.cls = mlp; | 2755 | sf.cls = mlp; |
2708 | sf.s_add = &GAS_mlp_address_add; | 2756 | sf.s_add = &GAS_mlp_address_add; |
@@ -2722,13 +2770,13 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2722 | mlp->stat_mlp_prob_changed = GNUNET_NO; | 2770 | mlp->stat_mlp_prob_changed = GNUNET_NO; |
2723 | mlp->stat_mlp_prob_updated = GNUNET_NO; | 2771 | mlp->stat_mlp_prob_updated = GNUNET_NO; |
2724 | mlp->opt_mlp_auto_solve = GNUNET_YES; | 2772 | mlp->opt_mlp_auto_solve = GNUNET_YES; |
2725 | mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 2773 | mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); |
2726 | mlp->stat_bulk_requests = 0; | 2774 | mlp->stat_bulk_requests = 0; |
2727 | mlp->stat_bulk_lock = 0; | 2775 | mlp->stat_bulk_lock = 0; |
2728 | 2776 | ||
2729 | /* Setup GLPK */ | 2777 | /* Setup GLPK */ |
2730 | /* Redirect GLPK output to GNUnet logging */ | 2778 | /* Redirect GLPK output to GNUnet logging */ |
2731 | glp_term_hook (&mlp_term_hook, (void *) mlp); | 2779 | glp_term_hook(&mlp_term_hook, (void *)mlp); |
2732 | 2780 | ||
2733 | /* Init LP solving parameters */ | 2781 | /* Init LP solving parameters */ |
2734 | glp_init_smcp(&mlp->control_param_lp); | 2782 | glp_init_smcp(&mlp->control_param_lp); |
@@ -2750,7 +2798,7 @@ libgnunet_plugin_ats_mlp_init (void *cls) | |||
2750 | mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; | 2798 | mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; |
2751 | mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL; | 2799 | mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL; |
2752 | 2800 | ||
2753 | LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n"); | 2801 | LOG(GNUNET_ERROR_TYPE_DEBUG, "solver ready\n"); |
2754 | 2802 | ||
2755 | return &sf; | 2803 | return &sf; |
2756 | } | 2804 | } |
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index 3fab09fb3..bdb5d6cf0 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2015 GNUnet e.V. | 3 | Copyright (C) 2011-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -29,7 +29,7 @@ | |||
29 | #include "gnunet_ats_plugin.h" | 29 | #include "gnunet_ats_plugin.h" |
30 | #include "gnunet-service-ats_addresses.h" | 30 | #include "gnunet-service-ats_addresses.h" |
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-proportional",__VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-proportional", __VA_ARGS__) |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * How much do we value stability over adaptation by default. A low | 35 | * How much do we value stability over adaptation by default. A low |
@@ -58,8 +58,7 @@ | |||
58 | * They are also stored in the respective `struct Network`'s linked | 58 | * They are also stored in the respective `struct Network`'s linked |
59 | * list. | 59 | * list. |
60 | */ | 60 | */ |
61 | struct AddressWrapper | 61 | struct AddressWrapper { |
62 | { | ||
63 | /** | 62 | /** |
64 | * Next in DLL | 63 | * Next in DLL |
65 | */ | 64 | */ |
@@ -75,7 +74,7 @@ struct AddressWrapper | |||
75 | */ | 74 | */ |
76 | struct ATS_Address *addr; | 75 | struct ATS_Address *addr; |
77 | 76 | ||
78 | /** | 77 | /** |
79 | * Network scope this address is in | 78 | * Network scope this address is in |
80 | */ | 79 | */ |
81 | struct Network *network; | 80 | struct Network *network; |
@@ -94,15 +93,13 @@ struct AddressWrapper | |||
94 | * When was this address activated | 93 | * When was this address activated |
95 | */ | 94 | */ |
96 | struct GNUNET_TIME_Absolute activated; | 95 | struct GNUNET_TIME_Absolute activated; |
97 | |||
98 | }; | 96 | }; |
99 | 97 | ||
100 | 98 | ||
101 | /** | 99 | /** |
102 | * Representation of a network | 100 | * Representation of a network |
103 | */ | 101 | */ |
104 | struct Network | 102 | struct Network { |
105 | { | ||
106 | /** | 103 | /** |
107 | * Network description | 104 | * Network description |
108 | */ | 105 | */ |
@@ -152,16 +149,13 @@ struct Network | |||
152 | * Number of total addresses for this network | 149 | * Number of total addresses for this network |
153 | */ | 150 | */ |
154 | unsigned int total_addresses; | 151 | unsigned int total_addresses; |
155 | |||
156 | }; | 152 | }; |
157 | 153 | ||
158 | 154 | ||
159 | /** | 155 | /** |
160 | * A handle for the proportional solver | 156 | * A handle for the proportional solver |
161 | */ | 157 | */ |
162 | struct GAS_PROPORTIONAL_Handle | 158 | struct GAS_PROPORTIONAL_Handle { |
163 | { | ||
164 | |||
165 | /** | 159 | /** |
166 | * Our execution environment. | 160 | * Our execution environment. |
167 | */ | 161 | */ |
@@ -197,7 +191,6 @@ struct GAS_PROPORTIONAL_Handle | |||
197 | * Number of active addresses for solver | 191 | * Number of active addresses for solver |
198 | */ | 192 | */ |
199 | unsigned int active_addresses; | 193 | unsigned int active_addresses; |
200 | |||
201 | }; | 194 | }; |
202 | 195 | ||
203 | 196 | ||
@@ -209,18 +202,18 @@ struct GAS_PROPORTIONAL_Handle | |||
209 | * @return #GNUNET_YES or #GNUNET_NO | 202 | * @return #GNUNET_YES or #GNUNET_NO |
210 | */ | 203 | */ |
211 | static int | 204 | static int |
212 | is_bandwidth_available_in_network (struct Network *net, | 205 | is_bandwidth_available_in_network(struct Network *net, |
213 | int extra) | 206 | int extra) |
214 | { | 207 | { |
215 | unsigned int na; | 208 | unsigned int na; |
216 | uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 209 | uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
217 | 210 | ||
218 | GNUNET_assert (((int)net->active_addresses) + extra >= 0); | 211 | GNUNET_assert(((int)net->active_addresses) + extra >= 0); |
219 | na = net->active_addresses + extra; | 212 | na = net->active_addresses + extra; |
220 | if (0 == na) | 213 | if (0 == na) |
221 | return GNUNET_YES; | 214 | return GNUNET_YES; |
222 | if ( ((net->total_quota_in / na) > min_bw) && | 215 | if (((net->total_quota_in / na) > min_bw) && |
223 | ((net->total_quota_out / na) > min_bw) ) | 216 | ((net->total_quota_out / na) > min_bw)) |
224 | return GNUNET_YES; | 217 | return GNUNET_YES; |
225 | return GNUNET_NO; | 218 | return GNUNET_NO; |
226 | } | 219 | } |
@@ -236,16 +229,16 @@ is_bandwidth_available_in_network (struct Network *net, | |||
236 | * @return #GNUNET_YES or #GNUNET_NO | 229 | * @return #GNUNET_YES or #GNUNET_NO |
237 | */ | 230 | */ |
238 | static int | 231 | static int |
239 | all_require_connectivity (struct GAS_PROPORTIONAL_Handle *s, | 232 | all_require_connectivity(struct GAS_PROPORTIONAL_Handle *s, |
240 | struct Network *net, | 233 | struct Network *net, |
241 | unsigned int con) | 234 | unsigned int con) |
242 | { | 235 | { |
243 | struct AddressWrapper *aw; | 236 | struct AddressWrapper *aw; |
244 | 237 | ||
245 | for (aw = net->head; NULL != aw; aw = aw->next) | 238 | for (aw = net->head; NULL != aw; aw = aw->next) |
246 | if (con > | 239 | if (con > |
247 | s->env->get_connectivity (s->env->cls, | 240 | s->env->get_connectivity(s->env->cls, |
248 | &aw->addr->peer)) | 241 | &aw->addr->peer)) |
249 | return GNUNET_NO; | 242 | return GNUNET_NO; |
250 | return GNUNET_YES; | 243 | return GNUNET_YES; |
251 | } | 244 | } |
@@ -261,10 +254,10 @@ all_require_connectivity (struct GAS_PROPORTIONAL_Handle *s, | |||
261 | * @param net the network type to update | 254 | * @param net the network type to update |
262 | */ | 255 | */ |
263 | static void | 256 | static void |
264 | distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | 257 | distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s, |
265 | struct Network *net) | 258 | struct Network *net) |
266 | { | 259 | { |
267 | const uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); | 260 | const uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); |
268 | struct AddressWrapper *aw; | 261 | struct AddressWrapper *aw; |
269 | unsigned long long remaining_quota_in; | 262 | unsigned long long remaining_quota_in; |
270 | unsigned long long quota_out_used; | 263 | unsigned long long quota_out_used; |
@@ -276,110 +269,110 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
276 | double total_weight; | 269 | double total_weight; |
277 | const double *peer_relative_prefs; | 270 | const double *peer_relative_prefs; |
278 | 271 | ||
279 | LOG (GNUNET_ERROR_TYPE_INFO, | 272 | LOG(GNUNET_ERROR_TYPE_INFO, |
280 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", | 273 | "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", |
281 | net->desc, | 274 | net->desc, |
282 | net->active_addresses, | 275 | net->active_addresses, |
283 | net->total_quota_in, | 276 | net->total_quota_in, |
284 | net->total_quota_in); | 277 | net->total_quota_in); |
285 | 278 | ||
286 | if (0 == net->active_addresses) | 279 | if (0 == net->active_addresses) |
287 | return; /* no addresses to update */ | 280 | return; /* no addresses to update */ |
288 | 281 | ||
289 | /* sanity checks */ | 282 | /* sanity checks */ |
290 | if ((net->active_addresses * min_bw) > net->total_quota_in) | 283 | if ((net->active_addresses * min_bw) > net->total_quota_in) |
291 | { | 284 | { |
292 | GNUNET_break(0); | 285 | GNUNET_break(0); |
293 | return; | 286 | return; |
294 | } | 287 | } |
295 | if ((net->active_addresses * min_bw) > net->total_quota_out) | 288 | if ((net->active_addresses * min_bw) > net->total_quota_out) |
296 | { | 289 | { |
297 | GNUNET_break(0); | 290 | GNUNET_break(0); |
298 | return; | 291 | return; |
299 | } | 292 | } |
300 | 293 | ||
301 | /* Calculate sum of relative preference for active addresses in this | 294 | /* Calculate sum of relative preference for active addresses in this |
302 | network */ | 295 | network */ |
303 | sum_relative_peer_prefences = 0.0; | 296 | sum_relative_peer_prefences = 0.0; |
304 | count_addresses = 0; | 297 | count_addresses = 0; |
305 | for (aw = net->head; NULL != aw; aw = aw->next) | 298 | for (aw = net->head; NULL != aw; aw = aw->next) |
306 | { | 299 | { |
307 | if (GNUNET_YES != aw->addr->active) | 300 | if (GNUNET_YES != aw->addr->active) |
308 | continue; | 301 | continue; |
309 | peer_relative_prefs = s->env->get_preferences (s->env->cls, | 302 | peer_relative_prefs = s->env->get_preferences(s->env->cls, |
310 | &aw->addr->peer); | 303 | &aw->addr->peer); |
311 | sum_relative_peer_prefences | 304 | sum_relative_peer_prefences |
312 | += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; | 305 | += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; |
313 | count_addresses++; | 306 | count_addresses++; |
314 | } | 307 | } |
315 | if (count_addresses != net->active_addresses) | 308 | if (count_addresses != net->active_addresses) |
316 | { | 309 | { |
317 | GNUNET_break (0); | 310 | GNUNET_break(0); |
318 | LOG (GNUNET_ERROR_TYPE_WARNING, | 311 | LOG(GNUNET_ERROR_TYPE_WARNING, |
319 | "%s: Counted %u active addresses, expected %u active addresses\n", | 312 | "%s: Counted %u active addresses, expected %u active addresses\n", |
320 | net->desc, | 313 | net->desc, |
321 | count_addresses, | 314 | count_addresses, |
322 | net->active_addresses); | 315 | net->active_addresses); |
323 | /* try to fix... */ | 316 | /* try to fix... */ |
324 | net->active_addresses = count_addresses; | 317 | net->active_addresses = count_addresses; |
325 | } | 318 | } |
326 | LOG (GNUNET_ERROR_TYPE_INFO, | 319 | LOG(GNUNET_ERROR_TYPE_INFO, |
327 | "Total relative preference %.3f for %u addresses in network %s\n", | 320 | "Total relative preference %.3f for %u addresses in network %s\n", |
328 | sum_relative_peer_prefences, | 321 | sum_relative_peer_prefences, |
329 | net->active_addresses, | 322 | net->active_addresses, |
330 | net->desc); | 323 | net->desc); |
331 | 324 | ||
332 | /* check how much we have to distribute */ | 325 | /* check how much we have to distribute */ |
333 | remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw); | 326 | remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw); |
334 | remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); | 327 | remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); |
335 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 328 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
336 | "Proportionally distributable bandwidth (in/out): %llu/%llu\n", | 329 | "Proportionally distributable bandwidth (in/out): %llu/%llu\n", |
337 | remaining_quota_in, | 330 | remaining_quota_in, |
338 | remaining_quota_out); | 331 | remaining_quota_out); |
339 | 332 | ||
340 | /* distribute remaining quota; we do not do it exactly proportional, | 333 | /* distribute remaining quota; we do not do it exactly proportional, |
341 | but balance "even" distribution ("net->active_addresses") with | 334 | but balance "even" distribution ("net->active_addresses") with |
342 | the preference sum using the "prop_factor". */ | 335 | the preference sum using the "prop_factor". */ |
343 | total_weight = net->active_addresses + | 336 | total_weight = net->active_addresses + |
344 | s->prop_factor * sum_relative_peer_prefences; | 337 | s->prop_factor * sum_relative_peer_prefences; |
345 | quota_out_used = 0; | 338 | quota_out_used = 0; |
346 | quota_in_used = 0; | 339 | quota_in_used = 0; |
347 | for (aw = net->head; NULL != aw; aw = aw->next) | 340 | for (aw = net->head; NULL != aw; aw = aw->next) |
348 | { | ||
349 | if (GNUNET_YES != aw->addr->active) | ||
350 | { | 341 | { |
351 | /* set to 0, just to be sure */ | 342 | if (GNUNET_YES != aw->addr->active) |
352 | aw->calculated_quota_in = 0; | 343 | { |
353 | aw->calculated_quota_out = 0; | 344 | /* set to 0, just to be sure */ |
354 | continue; | 345 | aw->calculated_quota_in = 0; |
346 | aw->calculated_quota_out = 0; | ||
347 | continue; | ||
348 | } | ||
349 | peer_relative_prefs = s->env->get_preferences(s->env->cls, | ||
350 | &aw->addr->peer); | ||
351 | peer_weight = 1.0 | ||
352 | + s->prop_factor * peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; | ||
353 | |||
354 | aw->calculated_quota_in = min_bw | ||
355 | + (peer_weight / total_weight) * remaining_quota_in; | ||
356 | aw->calculated_quota_out = min_bw | ||
357 | + (peer_weight / total_weight) * remaining_quota_out; | ||
358 | |||
359 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
360 | "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n", | ||
361 | GNUNET_i2s(&aw->addr->peer), | ||
362 | peer_weight, | ||
363 | total_weight, | ||
364 | (unsigned int)aw->calculated_quota_in, | ||
365 | (unsigned int)aw->calculated_quota_out); | ||
366 | quota_in_used += aw->calculated_quota_in; | ||
367 | quota_out_used += aw->calculated_quota_out; | ||
355 | } | 368 | } |
356 | peer_relative_prefs = s->env->get_preferences (s->env->cls, | 369 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
357 | &aw->addr->peer); | 370 | "Total bandwidth assigned is (in/out): %llu /%llu\n", |
358 | peer_weight = 1.0 | 371 | quota_in_used, |
359 | + s->prop_factor * peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; | 372 | quota_out_used); |
360 | |||
361 | aw->calculated_quota_in = min_bw | ||
362 | + (peer_weight / total_weight) * remaining_quota_in; | ||
363 | aw->calculated_quota_out = min_bw | ||
364 | + (peer_weight / total_weight) * remaining_quota_out; | ||
365 | |||
366 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
367 | "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n", | ||
368 | GNUNET_i2s (&aw->addr->peer), | ||
369 | peer_weight, | ||
370 | total_weight, | ||
371 | (unsigned int) aw->calculated_quota_in, | ||
372 | (unsigned int) aw->calculated_quota_out); | ||
373 | quota_in_used += aw->calculated_quota_in; | ||
374 | quota_out_used += aw->calculated_quota_out; | ||
375 | } | ||
376 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
377 | "Total bandwidth assigned is (in/out): %llu /%llu\n", | ||
378 | quota_in_used, | ||
379 | quota_out_used); | ||
380 | /* +1 due to possible rounding errors */ | 373 | /* +1 due to possible rounding errors */ |
381 | GNUNET_break (quota_out_used <= net->total_quota_out + 1); | 374 | GNUNET_break(quota_out_used <= net->total_quota_out + 1); |
382 | GNUNET_break (quota_in_used <= net->total_quota_in + 1); | 375 | GNUNET_break(quota_in_used <= net->total_quota_in + 1); |
383 | } | 376 | } |
384 | 377 | ||
385 | 378 | ||
@@ -390,22 +383,22 @@ distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
390 | * @param net the network to propagate changes in | 383 | * @param net the network to propagate changes in |
391 | */ | 384 | */ |
392 | static void | 385 | static void |
393 | propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | 386 | propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s, |
394 | struct Network *net) | 387 | struct Network *net) |
395 | { | 388 | { |
396 | struct AddressWrapper *cur; | 389 | struct AddressWrapper *cur; |
397 | 390 | ||
398 | for (cur = net->head; NULL != cur; cur = cur->next) | 391 | for (cur = net->head; NULL != cur; cur = cur->next) |
399 | { | 392 | { |
400 | if ( (cur->addr->assigned_bw_in == cur->calculated_quota_in) && | 393 | if ((cur->addr->assigned_bw_in == cur->calculated_quota_in) && |
401 | (cur->addr->assigned_bw_out == cur->calculated_quota_out) ) | 394 | (cur->addr->assigned_bw_out == cur->calculated_quota_out)) |
402 | continue; | 395 | continue; |
403 | cur->addr->assigned_bw_in = cur->calculated_quota_in; | 396 | cur->addr->assigned_bw_in = cur->calculated_quota_in; |
404 | cur->addr->assigned_bw_out = cur->calculated_quota_out; | 397 | cur->addr->assigned_bw_out = cur->calculated_quota_out; |
405 | if (GNUNET_YES == cur->addr->active) | 398 | if (GNUNET_YES == cur->addr->active) |
406 | s->env->bandwidth_changed_cb (s->env->cls, | 399 | s->env->bandwidth_changed_cb(s->env->cls, |
407 | cur->addr); | 400 | cur->addr); |
408 | } | 401 | } |
409 | } | 402 | } |
410 | 403 | ||
411 | 404 | ||
@@ -417,81 +410,80 @@ propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s, | |||
417 | * @param n the network, can be NULL for all networks | 410 | * @param n the network, can be NULL for all networks |
418 | */ | 411 | */ |
419 | static void | 412 | static void |
420 | distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s, | 413 | distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, |
421 | struct Network *n) | 414 | struct Network *n) |
422 | { | 415 | { |
423 | unsigned int i; | 416 | unsigned int i; |
424 | 417 | ||
425 | if (0 != s->bulk_lock) | 418 | if (0 != s->bulk_lock) |
426 | { | 419 | { |
427 | s->bulk_requests++; | 420 | s->bulk_requests++; |
428 | return; | 421 | return; |
429 | } | 422 | } |
430 | if (NULL != n) | 423 | if (NULL != n) |
431 | { | 424 | { |
432 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 425 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
433 | "Redistributing bandwidth in network %s with %u active and %u total addresses\n", | 426 | "Redistributing bandwidth in network %s with %u active and %u total addresses\n", |
434 | GNUNET_NT_to_string(n->type), | 427 | GNUNET_NT_to_string(n->type), |
435 | n->active_addresses, | 428 | n->active_addresses, |
436 | n->total_addresses); | 429 | n->total_addresses); |
437 | s->env->info_cb (s->env->cls, | 430 | s->env->info_cb(s->env->cls, |
438 | GAS_OP_SOLVE_START, | 431 | GAS_OP_SOLVE_START, |
439 | GAS_STAT_SUCCESS, | 432 | GAS_STAT_SUCCESS, |
440 | GAS_INFO_PROP_SINGLE); | 433 | GAS_INFO_PROP_SINGLE); |
441 | distribute_bandwidth(s, | 434 | distribute_bandwidth(s, |
442 | n); | 435 | n); |
443 | s->env->info_cb (s->env->cls, | 436 | s->env->info_cb(s->env->cls, |
444 | GAS_OP_SOLVE_STOP, | 437 | GAS_OP_SOLVE_STOP, |
445 | GAS_STAT_SUCCESS, | 438 | GAS_STAT_SUCCESS, |
446 | GAS_INFO_PROP_SINGLE); | 439 | GAS_INFO_PROP_SINGLE); |
447 | s->env->info_cb (s->env->cls, | 440 | s->env->info_cb(s->env->cls, |
448 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | 441 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, |
449 | GAS_STAT_SUCCESS, | 442 | GAS_STAT_SUCCESS, |
450 | GAS_INFO_PROP_SINGLE); | 443 | GAS_INFO_PROP_SINGLE); |
451 | propagate_bandwidth (s, | 444 | propagate_bandwidth(s, |
452 | n); | 445 | n); |
453 | 446 | ||
454 | s->env->info_cb (s->env->cls, | 447 | s->env->info_cb(s->env->cls, |
455 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | 448 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, |
456 | GAS_STAT_SUCCESS, | 449 | GAS_STAT_SUCCESS, |
457 | GAS_INFO_PROP_SINGLE); | 450 | GAS_INFO_PROP_SINGLE); |
458 | } | 451 | } |
459 | else | 452 | else |
460 | { | 453 | { |
461 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 454 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
462 | "Redistributing bandwidth in all %u networks\n", | 455 | "Redistributing bandwidth in all %u networks\n", |
463 | s->env->network_count); | 456 | s->env->network_count); |
464 | s->env->info_cb (s->env->cls, | 457 | s->env->info_cb(s->env->cls, |
465 | GAS_OP_SOLVE_START, | 458 | GAS_OP_SOLVE_START, |
466 | GAS_STAT_SUCCESS, | 459 | GAS_STAT_SUCCESS, |
467 | GAS_INFO_PROP_ALL); | 460 | GAS_INFO_PROP_ALL); |
468 | for (i = 0; i < s->env->network_count; i++) | 461 | for (i = 0; i < s->env->network_count; i++) |
469 | distribute_bandwidth (s, | 462 | distribute_bandwidth(s, |
463 | &s->network_entries[i]); | ||
464 | s->env->info_cb(s->env->cls, | ||
465 | GAS_OP_SOLVE_STOP, | ||
466 | GAS_STAT_SUCCESS, | ||
467 | GAS_INFO_PROP_ALL); | ||
468 | s->env->info_cb(s->env->cls, | ||
469 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
470 | GAS_STAT_SUCCESS, | ||
471 | GAS_INFO_PROP_ALL); | ||
472 | for (i = 0; i < s->env->network_count; i++) | ||
473 | propagate_bandwidth(s, | ||
470 | &s->network_entries[i]); | 474 | &s->network_entries[i]); |
471 | s->env->info_cb (s->env->cls, | 475 | s->env->info_cb(s->env->cls, |
472 | GAS_OP_SOLVE_STOP, | 476 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, |
473 | GAS_STAT_SUCCESS, | 477 | GAS_STAT_SUCCESS, |
474 | GAS_INFO_PROP_ALL); | 478 | GAS_INFO_PROP_ALL); |
475 | s->env->info_cb (s->env->cls, | 479 | } |
476 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, | ||
477 | GAS_STAT_SUCCESS, | ||
478 | GAS_INFO_PROP_ALL); | ||
479 | for (i = 0; i < s->env->network_count; i++) | ||
480 | propagate_bandwidth (s, | ||
481 | &s->network_entries[i]); | ||
482 | s->env->info_cb (s->env->cls, | ||
483 | GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, | ||
484 | GAS_STAT_SUCCESS, | ||
485 | GAS_INFO_PROP_ALL); | ||
486 | } | ||
487 | } | 480 | } |
488 | 481 | ||
489 | 482 | ||
490 | /** | 483 | /** |
491 | * Context for finding the best address* Linked list of addresses in this network: head | 484 | * Context for finding the best address* Linked list of addresses in this network: head |
492 | */ | 485 | */ |
493 | struct FindBestAddressCtx | 486 | struct FindBestAddressCtx { |
494 | { | ||
495 | /** | 487 | /** |
496 | * The solver handle | 488 | * The solver handle |
497 | */ | 489 | */ |
@@ -516,9 +508,9 @@ struct FindBestAddressCtx | |||
516 | * @return #GNUNET_OK (continue to iterate) | 508 | * @return #GNUNET_OK (continue to iterate) |
517 | */ | 509 | */ |
518 | static int | 510 | static int |
519 | find_best_address_it (void *cls, | 511 | find_best_address_it(void *cls, |
520 | const struct GNUNET_PeerIdentity *key, | 512 | const struct GNUNET_PeerIdentity *key, |
521 | void *value) | 513 | void *value) |
522 | { | 514 | { |
523 | struct FindBestAddressCtx *ctx = cls; | 515 | struct FindBestAddressCtx *ctx = cls; |
524 | struct ATS_Address *current = value; | 516 | struct ATS_Address *current = value; |
@@ -536,48 +528,48 @@ find_best_address_it (void *cls, | |||
536 | need = (GNUNET_YES == current->active) ? 0 : 1; | 528 | need = (GNUNET_YES == current->active) ? 0 : 1; |
537 | /* we save -1 slot if 'best' is active and belongs | 529 | /* we save -1 slot if 'best' is active and belongs |
538 | to the same network (as we would replace it) */ | 530 | to the same network (as we would replace it) */ |
539 | if ( (NULL != ctx->best) && | 531 | if ((NULL != ctx->best) && |
540 | (GNUNET_YES == ctx->best->active) && | 532 | (GNUNET_YES == ctx->best->active) && |
541 | (((struct AddressWrapper *) ctx->best->solver_information)->network == | 533 | (((struct AddressWrapper *)ctx->best->solver_information)->network == |
542 | asi->network) ) | 534 | asi->network)) |
543 | need--; | 535 | need--; |
544 | /* we can gain -1 slot if this peers connectivity | 536 | /* we can gain -1 slot if this peers connectivity |
545 | requirement is higher than that of another peer | 537 | requirement is higher than that of another peer |
546 | in that network scope */ | 538 | in that network scope */ |
547 | con = ctx->s->env->get_connectivity (ctx->s->env->cls, | 539 | con = ctx->s->env->get_connectivity(ctx->s->env->cls, |
548 | key); | 540 | key); |
549 | if (GNUNET_YES != | 541 | if (GNUNET_YES != |
550 | all_require_connectivity (ctx->s, | 542 | all_require_connectivity(ctx->s, |
551 | asi->network, | 543 | asi->network, |
552 | con)) | 544 | con)) |
553 | need--; | 545 | need--; |
554 | /* test if minimum bandwidth for 'current' would be available */ | 546 | /* test if minimum bandwidth for 'current' would be available */ |
555 | bw_available | 547 | bw_available |
556 | = is_bandwidth_available_in_network (asi->network, | 548 | = is_bandwidth_available_in_network(asi->network, |
557 | need); | 549 | need); |
558 | if (! bw_available) | 550 | if (!bw_available) |
559 | { | 551 | { |
560 | /* Bandwidth for this address is unavailable, so we cannot use | 552 | /* Bandwidth for this address is unavailable, so we cannot use |
561 | it. */ | 553 | it. */ |
562 | return GNUNET_OK; | 554 | return GNUNET_OK; |
563 | } | 555 | } |
564 | if (GNUNET_YES == current->active) | 556 | if (GNUNET_YES == current->active) |
565 | { | ||
566 | active_time = GNUNET_TIME_absolute_get_duration (asi->activated); | ||
567 | if (active_time.rel_value_us <= | ||
568 | ((double) GNUNET_TIME_UNIT_SECONDS.rel_value_us) * ctx->s->stability_factor) | ||
569 | { | 557 | { |
570 | /* Keep active address for stability reasons */ | 558 | active_time = GNUNET_TIME_absolute_get_duration(asi->activated); |
571 | ctx->best = current; | 559 | if (active_time.rel_value_us <= |
572 | return GNUNET_NO; | 560 | ((double)GNUNET_TIME_UNIT_SECONDS.rel_value_us) * ctx->s->stability_factor) |
561 | { | ||
562 | /* Keep active address for stability reasons */ | ||
563 | ctx->best = current; | ||
564 | return GNUNET_NO; | ||
565 | } | ||
573 | } | 566 | } |
574 | } | ||
575 | if (NULL == ctx->best) | 567 | if (NULL == ctx->best) |
576 | { | 568 | { |
577 | /* We so far have nothing else, so go with it! */ | 569 | /* We so far have nothing else, so go with it! */ |
578 | ctx->best = current; | 570 | ctx->best = current; |
579 | return GNUNET_OK; | 571 | return GNUNET_OK; |
580 | } | 572 | } |
581 | 573 | ||
582 | /* Now compare ATS information */ | 574 | /* Now compare ATS information */ |
583 | cur_distance = current->norm_distance.norm; | 575 | cur_distance = current->norm_distance.norm; |
@@ -587,33 +579,33 @@ find_best_address_it (void *cls, | |||
587 | 579 | ||
588 | /* user shorter distance */ | 580 | /* user shorter distance */ |
589 | if (cur_distance < best_distance) | 581 | if (cur_distance < best_distance) |
590 | { | ||
591 | if (GNUNET_NO == ctx->best->active) | ||
592 | { | ||
593 | /* Activity doesn't influence the equation, use current */ | ||
594 | ctx->best = current; | ||
595 | } | ||
596 | else if ((best_distance / cur_distance) > ctx->s->stability_factor) | ||
597 | { | 582 | { |
598 | /* Distance change is significant, switch active address! */ | 583 | if (GNUNET_NO == ctx->best->active) |
599 | ctx->best = current; | 584 | { |
585 | /* Activity doesn't influence the equation, use current */ | ||
586 | ctx->best = current; | ||
587 | } | ||
588 | else if ((best_distance / cur_distance) > ctx->s->stability_factor) | ||
589 | { | ||
590 | /* Distance change is significant, switch active address! */ | ||
591 | ctx->best = current; | ||
592 | } | ||
600 | } | 593 | } |
601 | } | ||
602 | 594 | ||
603 | /* User connection with less delay */ | 595 | /* User connection with less delay */ |
604 | if (cur_delay < best_delay) | 596 | if (cur_delay < best_delay) |
605 | { | ||
606 | if (GNUNET_NO == ctx->best->active) | ||
607 | { | 597 | { |
608 | /* Activity doesn't influence the equation, use current */ | 598 | if (GNUNET_NO == ctx->best->active) |
609 | ctx->best = current; | 599 | { |
610 | } | 600 | /* Activity doesn't influence the equation, use current */ |
611 | else if ((best_delay / cur_delay) > ctx->s->stability_factor) | 601 | ctx->best = current; |
612 | { | 602 | } |
613 | /* Latency change is significant, switch active address! */ | 603 | else if ((best_delay / cur_delay) > ctx->s->stability_factor) |
614 | ctx->best = current; | 604 | { |
605 | /* Latency change is significant, switch active address! */ | ||
606 | ctx->best = current; | ||
607 | } | ||
615 | } | 608 | } |
616 | } | ||
617 | return GNUNET_OK; | 609 | return GNUNET_OK; |
618 | } | 610 | } |
619 | 611 | ||
@@ -628,18 +620,18 @@ find_best_address_it (void *cls, | |||
628 | * @return the address or NULL | 620 | * @return the address or NULL |
629 | */ | 621 | */ |
630 | struct ATS_Address * | 622 | struct ATS_Address * |
631 | get_best_address (struct GAS_PROPORTIONAL_Handle *s, | 623 | get_best_address(struct GAS_PROPORTIONAL_Handle *s, |
632 | struct GNUNET_CONTAINER_MultiPeerMap *addresses, | 624 | struct GNUNET_CONTAINER_MultiPeerMap *addresses, |
633 | const struct GNUNET_PeerIdentity *id) | 625 | const struct GNUNET_PeerIdentity *id) |
634 | { | 626 | { |
635 | struct FindBestAddressCtx fba_ctx; | 627 | struct FindBestAddressCtx fba_ctx; |
636 | 628 | ||
637 | fba_ctx.best = NULL; | 629 | fba_ctx.best = NULL; |
638 | fba_ctx.s = s; | 630 | fba_ctx.s = s; |
639 | GNUNET_CONTAINER_multipeermap_get_multiple (addresses, | 631 | GNUNET_CONTAINER_multipeermap_get_multiple(addresses, |
640 | id, | 632 | id, |
641 | &find_best_address_it, | 633 | &find_best_address_it, |
642 | &fba_ctx); | 634 | &fba_ctx); |
643 | return fba_ctx.best; | 635 | return fba_ctx.best; |
644 | } | 636 | } |
645 | 637 | ||
@@ -651,21 +643,21 @@ get_best_address (struct GAS_PROPORTIONAL_Handle *s, | |||
651 | * @param net the network type | 643 | * @param net the network type |
652 | */ | 644 | */ |
653 | static void | 645 | static void |
654 | address_decrement_active (struct GAS_PROPORTIONAL_Handle *s, | 646 | address_decrement_active(struct GAS_PROPORTIONAL_Handle *s, |
655 | struct Network *net) | 647 | struct Network *net) |
656 | { | 648 | { |
657 | GNUNET_assert (net->active_addresses > 0); | 649 | GNUNET_assert(net->active_addresses > 0); |
658 | net->active_addresses--; | 650 | net->active_addresses--; |
659 | GNUNET_STATISTICS_update (s->env->stats, | 651 | GNUNET_STATISTICS_update(s->env->stats, |
660 | net->stat_active, | 652 | net->stat_active, |
661 | -1, | 653 | -1, |
662 | GNUNET_NO); | 654 | GNUNET_NO); |
663 | GNUNET_assert (s->active_addresses > 0); | 655 | GNUNET_assert(s->active_addresses > 0); |
664 | s->active_addresses--; | 656 | s->active_addresses--; |
665 | GNUNET_STATISTICS_update (s->env->stats, | 657 | GNUNET_STATISTICS_update(s->env->stats, |
666 | "# ATS addresses total", | 658 | "# ATS addresses total", |
667 | -1, | 659 | -1, |
668 | GNUNET_NO); | 660 | GNUNET_NO); |
669 | } | 661 | } |
670 | 662 | ||
671 | 663 | ||
@@ -679,16 +671,16 @@ address_decrement_active (struct GAS_PROPORTIONAL_Handle *s, | |||
679 | * @return #GNUNET_NO on double active address else #GNUNET_YES; | 671 | * @return #GNUNET_NO on double active address else #GNUNET_YES; |
680 | */ | 672 | */ |
681 | static int | 673 | static int |
682 | get_active_address_it (void *cls, | 674 | get_active_address_it(void *cls, |
683 | const struct GNUNET_PeerIdentity *key, | 675 | const struct GNUNET_PeerIdentity *key, |
684 | void *value) | 676 | void *value) |
685 | { | 677 | { |
686 | struct ATS_Address **dest = cls; | 678 | struct ATS_Address **dest = cls; |
687 | struct ATS_Address *aa = value; | 679 | struct ATS_Address *aa = value; |
688 | 680 | ||
689 | if (GNUNET_YES != aa->active) | 681 | if (GNUNET_YES != aa->active) |
690 | return GNUNET_OK; | 682 | return GNUNET_OK; |
691 | GNUNET_assert (NULL == (*dest)); | 683 | GNUNET_assert(NULL == (*dest)); |
692 | (*dest) = aa; | 684 | (*dest) = aa; |
693 | return GNUNET_OK; | 685 | return GNUNET_OK; |
694 | } | 686 | } |
@@ -702,16 +694,16 @@ get_active_address_it (void *cls, | |||
702 | * @return active address or NULL | 694 | * @return active address or NULL |
703 | */ | 695 | */ |
704 | static struct ATS_Address * | 696 | static struct ATS_Address * |
705 | get_active_address (struct GAS_PROPORTIONAL_Handle *s, | 697 | get_active_address(struct GAS_PROPORTIONAL_Handle *s, |
706 | const struct GNUNET_PeerIdentity *peer) | 698 | const struct GNUNET_PeerIdentity *peer) |
707 | { | 699 | { |
708 | struct ATS_Address *dest; | 700 | struct ATS_Address *dest; |
709 | 701 | ||
710 | dest = NULL; | 702 | dest = NULL; |
711 | GNUNET_CONTAINER_multipeermap_get_multiple (s->env->addresses, | 703 | GNUNET_CONTAINER_multipeermap_get_multiple(s->env->addresses, |
712 | peer, | 704 | peer, |
713 | &get_active_address_it, | 705 | &get_active_address_it, |
714 | &dest); | 706 | &dest); |
715 | return dest; | 707 | return dest; |
716 | } | 708 | } |
717 | 709 | ||
@@ -727,9 +719,9 @@ get_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
727 | * @param peer the peer to check | 719 | * @param peer the peer to check |
728 | */ | 720 | */ |
729 | static void | 721 | static void |
730 | update_active_address (struct GAS_PROPORTIONAL_Handle *s, | 722 | update_active_address(struct GAS_PROPORTIONAL_Handle *s, |
731 | struct ATS_Address *current_address, | 723 | struct ATS_Address *current_address, |
732 | const struct GNUNET_PeerIdentity *peer) | 724 | const struct GNUNET_PeerIdentity *peer) |
733 | { | 725 | { |
734 | struct ATS_Address *best_address; | 726 | struct ATS_Address *best_address; |
735 | struct AddressWrapper *asi_cur; | 727 | struct AddressWrapper *asi_cur; |
@@ -739,9 +731,9 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
739 | unsigned int a_con; | 731 | unsigned int a_con; |
740 | unsigned int con_min; | 732 | unsigned int con_min; |
741 | 733 | ||
742 | best_address = get_best_address (s, | 734 | best_address = get_best_address(s, |
743 | s->env->addresses, | 735 | s->env->addresses, |
744 | peer); | 736 | peer); |
745 | if (NULL != best_address) | 737 | if (NULL != best_address) |
746 | asi_best = best_address->solver_information; | 738 | asi_best = best_address->solver_information; |
747 | else | 739 | else |
@@ -749,98 +741,98 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
749 | if (current_address == best_address) | 741 | if (current_address == best_address) |
750 | return; /* no changes */ | 742 | return; /* no changes */ |
751 | if (NULL != current_address) | 743 | if (NULL != current_address) |
752 | { | ||
753 | /* We switch to a new address (or to none); | ||
754 | mark old address as inactive. */ | ||
755 | asi_cur = current_address->solver_information; | ||
756 | GNUNET_assert (GNUNET_YES == current_address->active); | ||
757 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
758 | "Disabling previous active address for peer `%s'\n", | ||
759 | GNUNET_i2s (peer)); | ||
760 | asi_cur->activated = GNUNET_TIME_UNIT_ZERO_ABS; | ||
761 | current_address->active = GNUNET_NO; | ||
762 | current_address->assigned_bw_in = 0; | ||
763 | current_address->assigned_bw_out = 0; | ||
764 | address_decrement_active (s, | ||
765 | asi_cur->network); | ||
766 | if ( (NULL == best_address) || | ||
767 | (asi_best->network != asi_cur->network) ) | ||
768 | distribute_bandwidth_in_network (s, | ||
769 | asi_cur->network); | ||
770 | if (NULL == best_address) | ||
771 | { | 744 | { |
772 | /* We previously had an active address, but now we cannot | 745 | /* We switch to a new address (or to none); |
773 | * suggest one. Therefore we have to disconnect the peer. | 746 | mark old address as inactive. */ |
774 | * The above call to "distribute_bandwidth_in_network() | 747 | asi_cur = current_address->solver_information; |
775 | * does not see 'current_address' so we need to trigger | 748 | GNUNET_assert(GNUNET_YES == current_address->active); |
776 | * the update here. */ | 749 | LOG(GNUNET_ERROR_TYPE_INFO, |
777 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 750 | "Disabling previous active address for peer `%s'\n", |
778 | "Disconnecting peer `%s'.\n", | 751 | GNUNET_i2s(peer)); |
779 | GNUNET_i2s (peer)); | 752 | asi_cur->activated = GNUNET_TIME_UNIT_ZERO_ABS; |
780 | s->env->bandwidth_changed_cb (s->env->cls, | 753 | current_address->active = GNUNET_NO; |
781 | current_address); | 754 | current_address->assigned_bw_in = 0; |
782 | return; | 755 | current_address->assigned_bw_out = 0; |
756 | address_decrement_active(s, | ||
757 | asi_cur->network); | ||
758 | if ((NULL == best_address) || | ||
759 | (asi_best->network != asi_cur->network)) | ||
760 | distribute_bandwidth_in_network(s, | ||
761 | asi_cur->network); | ||
762 | if (NULL == best_address) | ||
763 | { | ||
764 | /* We previously had an active address, but now we cannot | ||
765 | * suggest one. Therefore we have to disconnect the peer. | ||
766 | * The above call to "distribute_bandwidth_in_network() | ||
767 | * does not see 'current_address' so we need to trigger | ||
768 | * the update here. */ | ||
769 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
770 | "Disconnecting peer `%s'.\n", | ||
771 | GNUNET_i2s(peer)); | ||
772 | s->env->bandwidth_changed_cb(s->env->cls, | ||
773 | current_address); | ||
774 | return; | ||
775 | } | ||
783 | } | 776 | } |
784 | } | ||
785 | if (NULL == best_address) | 777 | if (NULL == best_address) |
786 | { | 778 | { |
787 | /* We do not have a new address, so we are done. */ | 779 | /* We do not have a new address, so we are done. */ |
788 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 780 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
789 | "Cannot suggest address for peer `%s'\n", | 781 | "Cannot suggest address for peer `%s'\n", |
790 | GNUNET_i2s (peer)); | 782 | GNUNET_i2s(peer)); |
791 | return; | 783 | return; |
792 | } | 784 | } |
793 | /* We do have a new address, activate it */ | 785 | /* We do have a new address, activate it */ |
794 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 786 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
795 | "Selecting new address %p for peer `%s'\n", | 787 | "Selecting new address %p for peer `%s'\n", |
796 | best_address, | 788 | best_address, |
797 | GNUNET_i2s (peer)); | 789 | GNUNET_i2s(peer)); |
798 | /* Mark address as active */ | 790 | /* Mark address as active */ |
799 | best_address->active = GNUNET_YES; | 791 | best_address->active = GNUNET_YES; |
800 | asi_best->activated = GNUNET_TIME_absolute_get (); | 792 | asi_best->activated = GNUNET_TIME_absolute_get(); |
801 | asi_best->network->active_addresses++; | 793 | asi_best->network->active_addresses++; |
802 | s->active_addresses++; | 794 | s->active_addresses++; |
803 | GNUNET_STATISTICS_update (s->env->stats, | 795 | GNUNET_STATISTICS_update(s->env->stats, |
804 | "# ATS active addresses total", | 796 | "# ATS active addresses total", |
805 | 1, | 797 | 1, |
806 | GNUNET_NO); | 798 | GNUNET_NO); |
807 | GNUNET_STATISTICS_update (s->env->stats, | 799 | GNUNET_STATISTICS_update(s->env->stats, |
808 | asi_best->network->stat_active, | 800 | asi_best->network->stat_active, |
809 | 1, | 801 | 1, |
810 | GNUNET_NO); | 802 | GNUNET_NO); |
811 | LOG (GNUNET_ERROR_TYPE_INFO, | 803 | LOG(GNUNET_ERROR_TYPE_INFO, |
812 | "Address %p for peer `%s' is now active\n", | 804 | "Address %p for peer `%s' is now active\n", |
813 | best_address, | 805 | best_address, |
814 | GNUNET_i2s (peer)); | 806 | GNUNET_i2s(peer)); |
815 | 807 | ||
816 | if (GNUNET_NO == | 808 | if (GNUNET_NO == |
817 | is_bandwidth_available_in_network (asi_best->network, | 809 | is_bandwidth_available_in_network(asi_best->network, |
818 | 0)) | 810 | 0)) |
819 | { | ||
820 | /* we went over the maximum number of addresses for | ||
821 | this scope; remove the address with the smallest | ||
822 | connectivity requirement */ | ||
823 | con_min = UINT32_MAX; | ||
824 | aw_min = NULL; | ||
825 | for (aw = asi_best->network->head; NULL != aw; aw = aw->next) | ||
826 | { | 811 | { |
827 | if ( (con_min > | 812 | /* we went over the maximum number of addresses for |
828 | (a_con = s->env->get_connectivity (s->env->cls, | 813 | this scope; remove the address with the smallest |
829 | &aw->addr->peer))) && | 814 | connectivity requirement */ |
830 | (GNUNET_YES == aw->addr->active) ) | 815 | con_min = UINT32_MAX; |
831 | { | 816 | aw_min = NULL; |
832 | aw_min = aw; | 817 | for (aw = asi_best->network->head; NULL != aw; aw = aw->next) |
833 | con_min = a_con; | 818 | { |
834 | if (0 == con_min) | 819 | if ((con_min > |
835 | break; | 820 | (a_con = s->env->get_connectivity(s->env->cls, |
836 | } | 821 | &aw->addr->peer))) && |
822 | (GNUNET_YES == aw->addr->active)) | ||
823 | { | ||
824 | aw_min = aw; | ||
825 | con_min = a_con; | ||
826 | if (0 == con_min) | ||
827 | break; | ||
828 | } | ||
829 | } | ||
830 | update_active_address(s, | ||
831 | aw_min->addr, | ||
832 | &aw_min->addr->peer); | ||
837 | } | 833 | } |
838 | update_active_address (s, | 834 | distribute_bandwidth_in_network(s, |
839 | aw_min->addr, | 835 | asi_best->network); |
840 | &aw_min->addr->peer); | ||
841 | } | ||
842 | distribute_bandwidth_in_network (s, | ||
843 | asi_best->network); | ||
844 | } | 836 | } |
845 | 837 | ||
846 | 838 | ||
@@ -853,17 +845,17 @@ update_active_address (struct GAS_PROPORTIONAL_Handle *s, | |||
853 | * @param pref_rel the normalized preference value for this kind over all clients | 845 | * @param pref_rel the normalized preference value for this kind over all clients |
854 | */ | 846 | */ |
855 | static void | 847 | static void |
856 | GAS_proportional_change_preference (void *solver, | 848 | GAS_proportional_change_preference(void *solver, |
857 | const struct GNUNET_PeerIdentity *peer, | 849 | const struct GNUNET_PeerIdentity *peer, |
858 | enum GNUNET_ATS_PreferenceKind kind, | 850 | enum GNUNET_ATS_PreferenceKind kind, |
859 | double pref_rel) | 851 | double pref_rel) |
860 | { | 852 | { |
861 | struct GAS_PROPORTIONAL_Handle *s = solver; | 853 | struct GAS_PROPORTIONAL_Handle *s = solver; |
862 | 854 | ||
863 | if (GNUNET_ATS_PREFERENCE_BANDWIDTH != kind) | 855 | if (GNUNET_ATS_PREFERENCE_BANDWIDTH != kind) |
864 | return; /* we do not care */ | 856 | return; /* we do not care */ |
865 | distribute_bandwidth_in_network (s, | 857 | distribute_bandwidth_in_network(s, |
866 | NULL); | 858 | NULL); |
867 | } | 859 | } |
868 | 860 | ||
869 | 861 | ||
@@ -878,12 +870,12 @@ GAS_proportional_change_preference (void *solver, | |||
878 | * @param score the score | 870 | * @param score the score |
879 | */ | 871 | */ |
880 | static void | 872 | static void |
881 | GAS_proportional_feedback (void *solver, | 873 | GAS_proportional_feedback(void *solver, |
882 | struct GNUNET_SERVICE_Client *application, | 874 | struct GNUNET_SERVICE_Client *application, |
883 | const struct GNUNET_PeerIdentity *peer, | 875 | const struct GNUNET_PeerIdentity *peer, |
884 | const struct GNUNET_TIME_Relative scope, | 876 | const struct GNUNET_TIME_Relative scope, |
885 | enum GNUNET_ATS_PreferenceKind kind, | 877 | enum GNUNET_ATS_PreferenceKind kind, |
886 | double score) | 878 | double score) |
887 | { | 879 | { |
888 | /* Proportional does not care about feedback */ | 880 | /* Proportional does not care about feedback */ |
889 | } | 881 | } |
@@ -896,15 +888,15 @@ GAS_proportional_feedback (void *solver, | |||
896 | * @param peer the identity of the peer | 888 | * @param peer the identity of the peer |
897 | */ | 889 | */ |
898 | static void | 890 | static void |
899 | GAS_proportional_start_get_address (void *solver, | 891 | GAS_proportional_start_get_address(void *solver, |
900 | const struct GNUNET_PeerIdentity *peer) | 892 | const struct GNUNET_PeerIdentity *peer) |
901 | { | 893 | { |
902 | struct GAS_PROPORTIONAL_Handle *s = solver; | 894 | struct GAS_PROPORTIONAL_Handle *s = solver; |
903 | 895 | ||
904 | update_active_address (s, | 896 | update_active_address(s, |
905 | get_active_address (s, | 897 | get_active_address(s, |
906 | peer), | 898 | peer), |
907 | peer); | 899 | peer); |
908 | } | 900 | } |
909 | 901 | ||
910 | 902 | ||
@@ -915,20 +907,20 @@ GAS_proportional_start_get_address (void *solver, | |||
915 | * @param peer the peer | 907 | * @param peer the peer |
916 | */ | 908 | */ |
917 | static void | 909 | static void |
918 | GAS_proportional_stop_get_address (void *solver, | 910 | GAS_proportional_stop_get_address(void *solver, |
919 | const struct GNUNET_PeerIdentity *peer) | 911 | const struct GNUNET_PeerIdentity *peer) |
920 | { | 912 | { |
921 | struct GAS_PROPORTIONAL_Handle *s = solver; | 913 | struct GAS_PROPORTIONAL_Handle *s = solver; |
922 | struct ATS_Address *cur; | 914 | struct ATS_Address *cur; |
923 | struct AddressWrapper *asi; | 915 | struct AddressWrapper *asi; |
924 | 916 | ||
925 | cur = get_active_address (s, | 917 | cur = get_active_address(s, |
926 | peer); | 918 | peer); |
927 | if (NULL == cur) | 919 | if (NULL == cur) |
928 | return; | 920 | return; |
929 | asi = cur->solver_information; | 921 | asi = cur->solver_information; |
930 | distribute_bandwidth_in_network (s, | 922 | distribute_bandwidth_in_network(s, |
931 | asi->network); | 923 | asi->network); |
932 | } | 924 | } |
933 | 925 | ||
934 | 926 | ||
@@ -938,13 +930,13 @@ GAS_proportional_stop_get_address (void *solver, | |||
938 | * @param solver the solver | 930 | * @param solver the solver |
939 | */ | 931 | */ |
940 | static void | 932 | static void |
941 | GAS_proportional_bulk_start (void *solver) | 933 | GAS_proportional_bulk_start(void *solver) |
942 | { | 934 | { |
943 | struct GAS_PROPORTIONAL_Handle *s = solver; | 935 | struct GAS_PROPORTIONAL_Handle *s = solver; |
944 | 936 | ||
945 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 937 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
946 | "Locking solver for bulk operation ...\n"); | 938 | "Locking solver for bulk operation ...\n"); |
947 | GNUNET_assert (NULL != solver); | 939 | GNUNET_assert(NULL != solver); |
948 | s->bulk_lock++; | 940 | s->bulk_lock++; |
949 | } | 941 | } |
950 | 942 | ||
@@ -955,27 +947,27 @@ GAS_proportional_bulk_start (void *solver) | |||
955 | * @param solver our `struct GAS_PROPORTIONAL_Handle *` | 947 | * @param solver our `struct GAS_PROPORTIONAL_Handle *` |
956 | */ | 948 | */ |
957 | static void | 949 | static void |
958 | GAS_proportional_bulk_stop (void *solver) | 950 | GAS_proportional_bulk_stop(void *solver) |
959 | { | 951 | { |
960 | struct GAS_PROPORTIONAL_Handle *s = solver; | 952 | struct GAS_PROPORTIONAL_Handle *s = solver; |
961 | 953 | ||
962 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 954 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
963 | "Unlocking solver from bulk operation ...\n"); | 955 | "Unlocking solver from bulk operation ...\n"); |
964 | if (s->bulk_lock < 1) | 956 | if (s->bulk_lock < 1) |
965 | { | 957 | { |
966 | GNUNET_break(0); | 958 | GNUNET_break(0); |
967 | return; | 959 | return; |
968 | } | 960 | } |
969 | s->bulk_lock--; | 961 | s->bulk_lock--; |
970 | if ( (0 == s->bulk_lock) && | 962 | if ((0 == s->bulk_lock) && |
971 | (0 < s->bulk_requests) ) | 963 | (0 < s->bulk_requests)) |
972 | { | 964 | { |
973 | LOG (GNUNET_ERROR_TYPE_INFO, | 965 | LOG(GNUNET_ERROR_TYPE_INFO, |
974 | "No lock pending, recalculating\n"); | 966 | "No lock pending, recalculating\n"); |
975 | distribute_bandwidth_in_network (s, | 967 | distribute_bandwidth_in_network(s, |
976 | NULL); | 968 | NULL); |
977 | s->bulk_requests = 0; | 969 | s->bulk_requests = 0; |
978 | } | 970 | } |
979 | } | 971 | } |
980 | 972 | ||
981 | 973 | ||
@@ -986,14 +978,14 @@ GAS_proportional_bulk_stop (void *solver) | |||
986 | * @param address the address | 978 | * @param address the address |
987 | */ | 979 | */ |
988 | static void | 980 | static void |
989 | GAS_proportional_address_property_changed (void *solver, | 981 | GAS_proportional_address_property_changed(void *solver, |
990 | struct ATS_Address *address) | 982 | struct ATS_Address *address) |
991 | { | 983 | { |
992 | struct GAS_PROPORTIONAL_Handle *s = solver; | 984 | struct GAS_PROPORTIONAL_Handle *s = solver; |
993 | struct AddressWrapper *asi = address->solver_information; | 985 | struct AddressWrapper *asi = address->solver_information; |
994 | 986 | ||
995 | distribute_bandwidth_in_network (s, | 987 | distribute_bandwidth_in_network(s, |
996 | asi->network); | 988 | asi->network); |
997 | } | 989 | } |
998 | 990 | ||
999 | 991 | ||
@@ -1005,43 +997,43 @@ GAS_proportional_address_property_changed (void *solver, | |||
1005 | * @param network network type of this address | 997 | * @param network network type of this address |
1006 | */ | 998 | */ |
1007 | static void | 999 | static void |
1008 | GAS_proportional_address_add (void *solver, | 1000 | GAS_proportional_address_add(void *solver, |
1009 | struct ATS_Address *address, | 1001 | struct ATS_Address *address, |
1010 | uint32_t network) | 1002 | uint32_t network) |
1011 | { | 1003 | { |
1012 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1004 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1013 | struct Network *net; | 1005 | struct Network *net; |
1014 | struct AddressWrapper *aw; | 1006 | struct AddressWrapper *aw; |
1015 | 1007 | ||
1016 | GNUNET_assert (network < s->env->network_count); | 1008 | GNUNET_assert(network < s->env->network_count); |
1017 | net = &s->network_entries[network]; | 1009 | net = &s->network_entries[network]; |
1018 | net->total_addresses++; | 1010 | net->total_addresses++; |
1019 | 1011 | ||
1020 | aw = GNUNET_new (struct AddressWrapper); | 1012 | aw = GNUNET_new(struct AddressWrapper); |
1021 | aw->addr = address; | 1013 | aw->addr = address; |
1022 | aw->network = net; | 1014 | aw->network = net; |
1023 | address->solver_information = aw; | 1015 | address->solver_information = aw; |
1024 | GNUNET_CONTAINER_DLL_insert (net->head, | 1016 | GNUNET_CONTAINER_DLL_insert(net->head, |
1025 | net->tail, | 1017 | net->tail, |
1026 | aw); | 1018 | aw); |
1027 | GNUNET_STATISTICS_update (s->env->stats, | 1019 | GNUNET_STATISTICS_update(s->env->stats, |
1028 | "# ATS addresses total", | 1020 | "# ATS addresses total", |
1029 | 1, | 1021 | 1, |
1030 | GNUNET_NO); | 1022 | GNUNET_NO); |
1031 | GNUNET_STATISTICS_update (s->env->stats, | 1023 | GNUNET_STATISTICS_update(s->env->stats, |
1032 | net->stat_total, | 1024 | net->stat_total, |
1033 | 1, | 1025 | 1, |
1034 | GNUNET_NO); | 1026 | GNUNET_NO); |
1035 | update_active_address (s, | 1027 | update_active_address(s, |
1036 | get_active_address (s, | 1028 | get_active_address(s, |
1037 | &address->peer), | 1029 | &address->peer), |
1038 | &address->peer); | 1030 | &address->peer); |
1039 | LOG (GNUNET_ERROR_TYPE_INFO, | 1031 | LOG(GNUNET_ERROR_TYPE_INFO, |
1040 | "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", | 1032 | "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", |
1041 | GNUNET_i2s (&address->peer), | 1033 | GNUNET_i2s(&address->peer), |
1042 | net->total_addresses, | 1034 | net->total_addresses, |
1043 | net->active_addresses, | 1035 | net->active_addresses, |
1044 | net->desc); | 1036 | net->desc); |
1045 | } | 1037 | } |
1046 | 1038 | ||
1047 | 1039 | ||
@@ -1057,45 +1049,45 @@ GAS_proportional_address_add (void *solver, | |||
1057 | * @param address the address to remove | 1049 | * @param address the address to remove |
1058 | */ | 1050 | */ |
1059 | static void | 1051 | static void |
1060 | GAS_proportional_address_delete (void *solver, | 1052 | GAS_proportional_address_delete(void *solver, |
1061 | struct ATS_Address *address) | 1053 | struct ATS_Address *address) |
1062 | { | 1054 | { |
1063 | struct GAS_PROPORTIONAL_Handle *s = solver; | 1055 | struct GAS_PROPORTIONAL_Handle *s = solver; |
1064 | struct AddressWrapper *aw = address->solver_information; | 1056 | struct AddressWrapper *aw = address->solver_information; |
1065 | struct Network *net = aw->network; | 1057 | struct Network *net = aw->network; |
1066 | 1058 | ||
1067 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1059 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1068 | "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n", | 1060 | "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n", |
1069 | (GNUNET_NO == address->active) ? "inactive" : "active", | 1061 | (GNUNET_NO == address->active) ? "inactive" : "active", |
1070 | GNUNET_i2s (&address->peer), | 1062 | GNUNET_i2s(&address->peer), |
1071 | net->desc, | 1063 | net->desc, |
1072 | net->total_addresses, | 1064 | net->total_addresses, |
1073 | net->active_addresses); | 1065 | net->active_addresses); |
1074 | 1066 | ||
1075 | GNUNET_CONTAINER_DLL_remove (net->head, | 1067 | GNUNET_CONTAINER_DLL_remove(net->head, |
1076 | net->tail, | 1068 | net->tail, |
1077 | aw); | 1069 | aw); |
1078 | GNUNET_assert (net->total_addresses > 0); | 1070 | GNUNET_assert(net->total_addresses > 0); |
1079 | net->total_addresses--; | 1071 | net->total_addresses--; |
1080 | GNUNET_STATISTICS_update (s->env->stats, | 1072 | GNUNET_STATISTICS_update(s->env->stats, |
1081 | net->stat_total, | 1073 | net->stat_total, |
1082 | -1, | 1074 | -1, |
1083 | GNUNET_NO); | 1075 | GNUNET_NO); |
1084 | if (GNUNET_YES == address->active) | 1076 | if (GNUNET_YES == address->active) |
1085 | { | 1077 | { |
1086 | /* Address was active, remove from network and update quotas */ | 1078 | /* Address was active, remove from network and update quotas */ |
1087 | update_active_address (s, | 1079 | update_active_address(s, |
1088 | address, | 1080 | address, |
1089 | &address->peer); | 1081 | &address->peer); |
1090 | distribute_bandwidth_in_network (s, net); | 1082 | distribute_bandwidth_in_network(s, net); |
1091 | } | 1083 | } |
1092 | GNUNET_free (aw); | 1084 | GNUNET_free(aw); |
1093 | address->solver_information = NULL; | 1085 | address->solver_information = NULL; |
1094 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1086 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
1095 | "After deleting address now total %u and active %u addresses in network `%s'\n", | 1087 | "After deleting address now total %u and active %u addresses in network `%s'\n", |
1096 | net->total_addresses, | 1088 | net->total_addresses, |
1097 | net->active_addresses, | 1089 | net->active_addresses, |
1098 | net->desc); | 1090 | net->desc); |
1099 | } | 1091 | } |
1100 | 1092 | ||
1101 | 1093 | ||
@@ -1107,7 +1099,7 @@ GAS_proportional_address_delete (void *solver, | |||
1107 | * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure | 1099 | * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure |
1108 | */ | 1100 | */ |
1109 | void * | 1101 | void * |
1110 | libgnunet_plugin_ats_proportional_init (void *cls) | 1102 | libgnunet_plugin_ats_proportional_init(void *cls) |
1111 | { | 1103 | { |
1112 | static struct GNUNET_ATS_SolverFunctions sf; | 1104 | static struct GNUNET_ATS_SolverFunctions sf; |
1113 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 1105 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
@@ -1116,7 +1108,7 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1116 | float f_tmp; | 1108 | float f_tmp; |
1117 | unsigned int c; | 1109 | unsigned int c; |
1118 | 1110 | ||
1119 | s = GNUNET_new (struct GAS_PROPORTIONAL_Handle); | 1111 | s = GNUNET_new(struct GAS_PROPORTIONAL_Handle); |
1120 | s->env = env; | 1112 | s->env = env; |
1121 | sf.cls = s; | 1113 | sf.cls = s; |
1122 | sf.s_add = &GAS_proportional_address_add; | 1114 | sf.s_add = &GAS_proportional_address_add; |
@@ -1130,73 +1122,73 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1130 | sf.s_bulk_stop = &GAS_proportional_bulk_stop; | 1122 | sf.s_bulk_stop = &GAS_proportional_bulk_stop; |
1131 | s->stability_factor = PROP_STABILITY_FACTOR; | 1123 | s->stability_factor = PROP_STABILITY_FACTOR; |
1132 | if (GNUNET_SYSERR != | 1124 | if (GNUNET_SYSERR != |
1133 | GNUNET_CONFIGURATION_get_value_float (env->cfg, | 1125 | GNUNET_CONFIGURATION_get_value_float(env->cfg, |
1134 | "ats", | 1126 | "ats", |
1135 | "PROP_STABILITY_FACTOR", | 1127 | "PROP_STABILITY_FACTOR", |
1136 | &f_tmp)) | 1128 | &f_tmp)) |
1137 | { | ||
1138 | if ((f_tmp < 1.0) || (f_tmp > 2.0)) | ||
1139 | { | ||
1140 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1141 | _("Invalid %s configuration %f \n"), | ||
1142 | "PROP_STABILITY_FACTOR", | ||
1143 | f_tmp); | ||
1144 | } | ||
1145 | else | ||
1146 | { | 1129 | { |
1147 | s->stability_factor = f_tmp; | 1130 | if ((f_tmp < 1.0) || (f_tmp > 2.0)) |
1148 | LOG (GNUNET_ERROR_TYPE_INFO, | 1131 | { |
1149 | "Using %s of %.3f\n", | 1132 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1150 | "PROP_STABILITY_FACTOR", | 1133 | _("Invalid %s configuration %f \n"), |
1151 | f_tmp); | 1134 | "PROP_STABILITY_FACTOR", |
1135 | f_tmp); | ||
1136 | } | ||
1137 | else | ||
1138 | { | ||
1139 | s->stability_factor = f_tmp; | ||
1140 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1141 | "Using %s of %.3f\n", | ||
1142 | "PROP_STABILITY_FACTOR", | ||
1143 | f_tmp); | ||
1144 | } | ||
1152 | } | 1145 | } |
1153 | } | ||
1154 | s->prop_factor = PROPORTIONALITY_FACTOR; | 1146 | s->prop_factor = PROPORTIONALITY_FACTOR; |
1155 | if (GNUNET_SYSERR != | 1147 | if (GNUNET_SYSERR != |
1156 | GNUNET_CONFIGURATION_get_value_float (env->cfg, | 1148 | GNUNET_CONFIGURATION_get_value_float(env->cfg, |
1157 | "ats", | 1149 | "ats", |
1158 | "PROP_PROPORTIONALITY_FACTOR", | 1150 | "PROP_PROPORTIONALITY_FACTOR", |
1159 | &f_tmp)) | 1151 | &f_tmp)) |
1160 | { | ||
1161 | if (f_tmp < 1.0) | ||
1162 | { | 1152 | { |
1163 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1153 | if (f_tmp < 1.0) |
1164 | _("Invalid %s configuration %f\n"), | 1154 | { |
1165 | "PROP_PROPORTIONALITY_FACTOR", | 1155 | LOG(GNUNET_ERROR_TYPE_ERROR, |
1166 | f_tmp); | 1156 | _("Invalid %s configuration %f\n"), |
1157 | "PROP_PROPORTIONALITY_FACTOR", | ||
1158 | f_tmp); | ||
1159 | } | ||
1160 | else | ||
1161 | { | ||
1162 | s->prop_factor = f_tmp; | ||
1163 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1164 | "Using %s of %.3f\n", | ||
1165 | "PROP_PROPORTIONALITY_FACTOR", | ||
1166 | f_tmp); | ||
1167 | } | ||
1167 | } | 1168 | } |
1168 | else | ||
1169 | { | ||
1170 | s->prop_factor = f_tmp; | ||
1171 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1172 | "Using %s of %.3f\n", | ||
1173 | "PROP_PROPORTIONALITY_FACTOR", | ||
1174 | f_tmp); | ||
1175 | } | ||
1176 | } | ||
1177 | 1169 | ||
1178 | s->network_entries = GNUNET_malloc (env->network_count * | 1170 | s->network_entries = GNUNET_malloc(env->network_count * |
1179 | sizeof (struct Network)); | 1171 | sizeof(struct Network)); |
1180 | for (c = 0; c < env->network_count; c++) | 1172 | for (c = 0; c < env->network_count; c++) |
1181 | { | 1173 | { |
1182 | cur = &s->network_entries[c]; | 1174 | cur = &s->network_entries[c]; |
1183 | cur->type = c; | 1175 | cur->type = c; |
1184 | cur->total_quota_in = env->in_quota[c]; | 1176 | cur->total_quota_in = env->in_quota[c]; |
1185 | cur->total_quota_out = env->out_quota[c]; | 1177 | cur->total_quota_out = env->out_quota[c]; |
1186 | cur->desc = GNUNET_NT_to_string (c); | 1178 | cur->desc = GNUNET_NT_to_string(c); |
1187 | GNUNET_asprintf (&cur->stat_total, | 1179 | GNUNET_asprintf(&cur->stat_total, |
1188 | "# ATS addresses %s total", | 1180 | "# ATS addresses %s total", |
1189 | cur->desc); | 1181 | cur->desc); |
1190 | GNUNET_asprintf (&cur->stat_active, | 1182 | GNUNET_asprintf(&cur->stat_active, |
1191 | "# ATS active addresses %s total", | 1183 | "# ATS active addresses %s total", |
1192 | cur->desc); | 1184 | cur->desc); |
1193 | LOG (GNUNET_ERROR_TYPE_INFO, | 1185 | LOG(GNUNET_ERROR_TYPE_INFO, |
1194 | "Added network %u `%s' (%llu/%llu)\n", | 1186 | "Added network %u `%s' (%llu/%llu)\n", |
1195 | c, | 1187 | c, |
1196 | cur->desc, | 1188 | cur->desc, |
1197 | cur->total_quota_in, | 1189 | cur->total_quota_in, |
1198 | cur->total_quota_out); | 1190 | cur->total_quota_out); |
1199 | } | 1191 | } |
1200 | return &sf; | 1192 | return &sf; |
1201 | } | 1193 | } |
1202 | 1194 | ||
@@ -1207,7 +1199,7 @@ libgnunet_plugin_ats_proportional_init (void *cls) | |||
1207 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() | 1199 | * @param cls return value from #libgnunet_plugin_ats_proportional_init() |
1208 | */ | 1200 | */ |
1209 | void * | 1201 | void * |
1210 | libgnunet_plugin_ats_proportional_done (void *cls) | 1202 | libgnunet_plugin_ats_proportional_done(void *cls) |
1211 | { | 1203 | { |
1212 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 1204 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
1213 | struct GAS_PROPORTIONAL_Handle *s = sf->cls; | 1205 | struct GAS_PROPORTIONAL_Handle *s = sf->cls; |
@@ -1216,25 +1208,25 @@ libgnunet_plugin_ats_proportional_done (void *cls) | |||
1216 | unsigned int c; | 1208 | unsigned int c; |
1217 | 1209 | ||
1218 | for (c = 0; c < s->env->network_count; c++) | 1210 | for (c = 0; c < s->env->network_count; c++) |
1219 | { | ||
1220 | GNUNET_break (0 == s->network_entries[c].total_addresses); | ||
1221 | GNUNET_break (0 == s->network_entries[c].active_addresses); | ||
1222 | next = s->network_entries[c].head; | ||
1223 | while (NULL != (cur = next)) | ||
1224 | { | 1211 | { |
1225 | next = cur->next; | 1212 | GNUNET_break(0 == s->network_entries[c].total_addresses); |
1226 | GNUNET_CONTAINER_DLL_remove (s->network_entries[c].head, | 1213 | GNUNET_break(0 == s->network_entries[c].active_addresses); |
1227 | s->network_entries[c].tail, | 1214 | next = s->network_entries[c].head; |
1228 | cur); | 1215 | while (NULL != (cur = next)) |
1229 | GNUNET_free_non_null (cur->addr->solver_information); | 1216 | { |
1230 | GNUNET_free(cur); | 1217 | next = cur->next; |
1218 | GNUNET_CONTAINER_DLL_remove(s->network_entries[c].head, | ||
1219 | s->network_entries[c].tail, | ||
1220 | cur); | ||
1221 | GNUNET_free_non_null(cur->addr->solver_information); | ||
1222 | GNUNET_free(cur); | ||
1223 | } | ||
1224 | GNUNET_free(s->network_entries[c].stat_total); | ||
1225 | GNUNET_free(s->network_entries[c].stat_active); | ||
1231 | } | 1226 | } |
1232 | GNUNET_free (s->network_entries[c].stat_total); | 1227 | GNUNET_break(0 == s->active_addresses); |
1233 | GNUNET_free (s->network_entries[c].stat_active); | 1228 | GNUNET_free(s->network_entries); |
1234 | } | 1229 | GNUNET_free(s); |
1235 | GNUNET_break (0 == s->active_addresses); | ||
1236 | GNUNET_free (s->network_entries); | ||
1237 | GNUNET_free (s); | ||
1238 | return NULL; | 1230 | return NULL; |
1239 | } | 1231 | } |
1240 | 1232 | ||
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 9f78450c2..abf265f19 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c | |||
@@ -1,19 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011-2014 GNUnet e.V. | 3 | Copyright (C) 2011-2014 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation, either version 3 of the License, | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | or (at your option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
@@ -32,17 +32,17 @@ | |||
32 | 32 | ||
33 | 33 | ||
34 | 34 | ||
35 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-ril",__VA_ARGS__) | 35 | #define LOG(kind, ...) GNUNET_log_from(kind, "ats-ril", __VA_ARGS__) |
36 | 36 | ||
37 | #define RIL_MIN_BW (5 * ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) | 37 | #define RIL_MIN_BW (5 * ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) |
38 | #define RIL_MAX_BW GNUNET_ATS_MaxBandwidth | 38 | #define RIL_MAX_BW GNUNET_ATS_MaxBandwidth |
39 | 39 | ||
40 | #define RIL_ACTION_INVALID -1 | 40 | #define RIL_ACTION_INVALID -1 |
41 | #define RIL_INTERVAL_EXPONENT 10 | 41 | #define RIL_INTERVAL_EXPONENT 10 |
42 | #define RIL_UTILITY_DELAY_MAX 1000 | 42 | #define RIL_UTILITY_DELAY_MAX 1000 |
43 | 43 | ||
44 | #define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 200) | 44 | #define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) |
45 | #define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 2000) | 45 | #define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2000) |
46 | #define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA | 46 | #define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA |
47 | #define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX | 47 | #define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX |
48 | #define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH | 48 | #define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH |
@@ -71,8 +71,7 @@ | |||
71 | * to a particular address. The action of switching to address with index i is depicted by the | 71 | * to a particular address. The action of switching to address with index i is depicted by the |
72 | * number (RIL_ACTION_TYPE_NUM + i). | 72 | * number (RIL_ACTION_TYPE_NUM + i). |
73 | */ | 73 | */ |
74 | enum RIL_Action_Type | 74 | enum RIL_Action_Type { |
75 | { | ||
76 | RIL_ACTION_NOTHING = 0, | 75 | RIL_ACTION_NOTHING = 0, |
77 | RIL_ACTION_BW_IN_DBL = -2, //TODO? Potentially add more actions | 76 | RIL_ACTION_BW_IN_DBL = -2, //TODO? Potentially add more actions |
78 | RIL_ACTION_BW_IN_HLV = -3, | 77 | RIL_ACTION_BW_IN_HLV = -3, |
@@ -85,26 +84,22 @@ enum RIL_Action_Type | |||
85 | RIL_ACTION_TYPE_NUM = 5 | 84 | RIL_ACTION_TYPE_NUM = 5 |
86 | }; | 85 | }; |
87 | 86 | ||
88 | enum RIL_Algorithm | 87 | enum RIL_Algorithm { |
89 | { | ||
90 | RIL_ALGO_SARSA = 0, | 88 | RIL_ALGO_SARSA = 0, |
91 | RIL_ALGO_Q = 1 | 89 | RIL_ALGO_Q = 1 |
92 | }; | 90 | }; |
93 | 91 | ||
94 | enum RIL_Select | 92 | enum RIL_Select { |
95 | { | ||
96 | RIL_SELECT_SOFTMAX = 0, | 93 | RIL_SELECT_SOFTMAX = 0, |
97 | RIL_SELECT_EGREEDY = 1 | 94 | RIL_SELECT_EGREEDY = 1 |
98 | }; | 95 | }; |
99 | 96 | ||
100 | enum RIL_Welfare | 97 | enum RIL_Welfare { |
101 | { | ||
102 | RIL_WELFARE_NASH, | 98 | RIL_WELFARE_NASH, |
103 | RIL_WELFARE_EGALITARIAN | 99 | RIL_WELFARE_EGALITARIAN |
104 | }; | 100 | }; |
105 | 101 | ||
106 | enum RIL_E_Modification | 102 | enum RIL_E_Modification { |
107 | { | ||
108 | RIL_E_DECAY, | 103 | RIL_E_DECAY, |
109 | RIL_E_ZERO, | 104 | RIL_E_ZERO, |
110 | RIL_E_ACCUMULATE, | 105 | RIL_E_ACCUMULATE, |
@@ -114,8 +109,7 @@ enum RIL_E_Modification | |||
114 | /** | 109 | /** |
115 | * Global learning parameters | 110 | * Global learning parameters |
116 | */ | 111 | */ |
117 | struct RIL_Learning_Parameters | 112 | struct RIL_Learning_Parameters { |
118 | { | ||
119 | /** | 113 | /** |
120 | * The TD-algorithm to use | 114 | * The TD-algorithm to use |
121 | */ | 115 | */ |
@@ -205,8 +199,7 @@ struct RIL_Learning_Parameters | |||
205 | /** | 199 | /** |
206 | * Wrapper for addresses to store them in agent's linked list | 200 | * Wrapper for addresses to store them in agent's linked list |
207 | */ | 201 | */ |
208 | struct RIL_Address_Wrapped | 202 | struct RIL_Address_Wrapped { |
209 | { | ||
210 | /** | 203 | /** |
211 | * Next in DLL | 204 | * Next in DLL |
212 | */ | 205 | */ |
@@ -224,8 +217,7 @@ struct RIL_Address_Wrapped | |||
224 | }; | 217 | }; |
225 | 218 | ||
226 | 219 | ||
227 | struct RIL_Peer_Agent | 220 | struct RIL_Peer_Agent { |
228 | { | ||
229 | /** | 221 | /** |
230 | * Next agent in solver's linked list | 222 | * Next agent in solver's linked list |
231 | */ | 223 | */ |
@@ -337,8 +329,7 @@ struct RIL_Peer_Agent | |||
337 | double nop_bonus; | 329 | double nop_bonus; |
338 | }; | 330 | }; |
339 | 331 | ||
340 | struct RIL_Scope | 332 | struct RIL_Scope { |
341 | { | ||
342 | /** | 333 | /** |
343 | * ATS network type | 334 | * ATS network type |
344 | */ | 335 | */ |
@@ -388,8 +379,7 @@ struct RIL_Scope | |||
388 | /** | 379 | /** |
389 | * A handle for the reinforcement learning solver | 380 | * A handle for the reinforcement learning solver |
390 | */ | 381 | */ |
391 | struct GAS_RIL_Handle | 382 | struct GAS_RIL_Handle { |
392 | { | ||
393 | /** | 383 | /** |
394 | * The solver-plugin environment of the solver-plugin API | 384 | * The solver-plugin environment of the solver-plugin API |
395 | */ | 385 | */ |
@@ -476,9 +466,9 @@ struct GAS_RIL_Handle | |||
476 | * @return estimation value | 466 | * @return estimation value |
477 | */ | 467 | */ |
478 | static double | 468 | static double |
479 | agent_q (struct RIL_Peer_Agent *agent, | 469 | agent_q(struct RIL_Peer_Agent *agent, |
480 | const double *state, | 470 | const double *state, |
481 | int action) | 471 | int action) |
482 | { | 472 | { |
483 | unsigned int i; | 473 | unsigned int i; |
484 | double result = 0.0; | 474 | double result = 0.0; |
@@ -488,7 +478,7 @@ agent_q (struct RIL_Peer_Agent *agent, | |||
488 | 478 | ||
489 | /* prevent crashes if learning diverges */ | 479 | /* prevent crashes if learning diverges */ |
490 | if (isnan(result)) | 480 | if (isnan(result)) |
491 | return isnan(result) * UINT32_MAX; | 481 | return isnan(result) * UINT32_MAX; |
492 | if (isinf(result)) | 482 | if (isinf(result)) |
493 | return isinf(result) * UINT32_MAX; | 483 | return isinf(result) * UINT32_MAX; |
494 | return result; | 484 | return result; |
@@ -503,18 +493,18 @@ agent_q (struct RIL_Peer_Agent *agent, | |||
503 | * @return the index, starting with zero | 493 | * @return the index, starting with zero |
504 | */ | 494 | */ |
505 | static int | 495 | static int |
506 | agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 496 | agent_address_get_index(struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
507 | { | 497 | { |
508 | int i; | 498 | int i; |
509 | struct RIL_Address_Wrapped *cur; | 499 | struct RIL_Address_Wrapped *cur; |
510 | 500 | ||
511 | i = -1; | 501 | i = -1; |
512 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) | 502 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) |
513 | { | 503 | { |
514 | i++; | 504 | i++; |
515 | if (cur->address_naked == address) | 505 | if (cur->address_naked == address) |
516 | return i; | 506 | return i; |
517 | } | 507 | } |
518 | return i; | 508 | return i; |
519 | } | 509 | } |
520 | 510 | ||
@@ -527,7 +517,7 @@ agent_address_get_index (struct RIL_Peer_Agent *agent, struct ATS_Address *addre | |||
527 | * @return wrapped address | 517 | * @return wrapped address |
528 | */ | 518 | */ |
529 | static struct RIL_Address_Wrapped * | 519 | static struct RIL_Address_Wrapped * |
530 | agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct ATS_Address *address) | 520 | agent_address_get_wrapped(struct RIL_Peer_Agent *agent, struct ATS_Address *address) |
531 | { | 521 | { |
532 | struct RIL_Address_Wrapped *cur; | 522 | struct RIL_Address_Wrapped *cur; |
533 | 523 | ||
@@ -539,62 +529,67 @@ agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct ATS_Address *add | |||
539 | 529 | ||
540 | 530 | ||
541 | static int | 531 | static int |
542 | agent_action_is_possible (struct RIL_Peer_Agent *agent, int action) | 532 | agent_action_is_possible(struct RIL_Peer_Agent *agent, int action) |
543 | { | 533 | { |
544 | int address_index; | 534 | int address_index; |
545 | 535 | ||
546 | switch (action) | 536 | switch (action) |
547 | { | ||
548 | case RIL_ACTION_NOTHING: | ||
549 | return GNUNET_YES; | ||
550 | break; | ||
551 | case RIL_ACTION_BW_IN_INC: | ||
552 | case RIL_ACTION_BW_IN_DBL: | ||
553 | if (agent->bw_in >= RIL_MAX_BW) | ||
554 | return GNUNET_NO; | ||
555 | else | ||
556 | return GNUNET_YES; | ||
557 | break; | ||
558 | case RIL_ACTION_BW_IN_DEC: | ||
559 | case RIL_ACTION_BW_IN_HLV: | ||
560 | if (agent->bw_in <= 0) | ||
561 | return GNUNET_NO; | ||
562 | else | ||
563 | return GNUNET_YES; | ||
564 | break; | ||
565 | case RIL_ACTION_BW_OUT_INC: | ||
566 | case RIL_ACTION_BW_OUT_DBL: | ||
567 | if (agent->bw_out >= RIL_MAX_BW) | ||
568 | return GNUNET_NO; | ||
569 | else | ||
570 | return GNUNET_YES; | ||
571 | break; | ||
572 | case RIL_ACTION_BW_OUT_DEC: | ||
573 | case RIL_ACTION_BW_OUT_HLV: | ||
574 | if (agent->bw_out <= 0) | ||
575 | return GNUNET_NO; | ||
576 | else | ||
577 | return GNUNET_YES; | ||
578 | break; | ||
579 | default: | ||
580 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
581 | { | 537 | { |
582 | address_index = action - RIL_ACTION_TYPE_NUM; | 538 | case RIL_ACTION_NOTHING: |
539 | return GNUNET_YES; | ||
540 | break; | ||
541 | |||
542 | case RIL_ACTION_BW_IN_INC: | ||
543 | case RIL_ACTION_BW_IN_DBL: | ||
544 | if (agent->bw_in >= RIL_MAX_BW) | ||
545 | return GNUNET_NO; | ||
546 | else | ||
547 | return GNUNET_YES; | ||
548 | break; | ||
583 | 549 | ||
584 | GNUNET_assert(address_index >= 0); | 550 | case RIL_ACTION_BW_IN_DEC: |
585 | GNUNET_assert( | 551 | case RIL_ACTION_BW_IN_HLV: |
586 | address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked)); | 552 | if (agent->bw_in <= 0) |
553 | return GNUNET_NO; | ||
554 | else | ||
555 | return GNUNET_YES; | ||
556 | break; | ||
557 | |||
558 | case RIL_ACTION_BW_OUT_INC: | ||
559 | case RIL_ACTION_BW_OUT_DBL: | ||
560 | if (agent->bw_out >= RIL_MAX_BW) | ||
561 | return GNUNET_NO; | ||
562 | else | ||
563 | return GNUNET_YES; | ||
564 | break; | ||
587 | 565 | ||
588 | if ((agent_address_get_index(agent, agent->address_inuse) == address_index) || | 566 | case RIL_ACTION_BW_OUT_DEC: |
589 | agent->address_inuse->active) | 567 | case RIL_ACTION_BW_OUT_HLV: |
568 | if (agent->bw_out <= 0) | ||
590 | return GNUNET_NO; | 569 | return GNUNET_NO; |
591 | else | 570 | else |
592 | return GNUNET_YES; | 571 | return GNUNET_YES; |
593 | break; | 572 | break; |
573 | |||
574 | default: | ||
575 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
576 | { | ||
577 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
578 | |||
579 | GNUNET_assert(address_index >= 0); | ||
580 | GNUNET_assert( | ||
581 | address_index <= agent_address_get_index(agent, agent->addresses_tail->address_naked)); | ||
582 | |||
583 | if ((agent_address_get_index(agent, agent->address_inuse) == address_index) || | ||
584 | agent->address_inuse->active) | ||
585 | return GNUNET_NO; | ||
586 | else | ||
587 | return GNUNET_YES; | ||
588 | break; | ||
589 | } | ||
590 | // error - action does not exist | ||
591 | GNUNET_assert(GNUNET_NO); | ||
594 | } | 592 | } |
595 | // error - action does not exist | ||
596 | GNUNET_assert(GNUNET_NO); | ||
597 | } | ||
598 | } | 593 | } |
599 | 594 | ||
600 | 595 | ||
@@ -607,7 +602,7 @@ agent_action_is_possible (struct RIL_Peer_Agent *agent, int action) | |||
607 | * @return the action promising most future reward | 602 | * @return the action promising most future reward |
608 | */ | 603 | */ |
609 | static int | 604 | static int |
610 | agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | 605 | agent_get_action_max(struct RIL_Peer_Agent *agent, double *state) |
611 | { | 606 | { |
612 | int i; | 607 | int i; |
613 | int max_i = RIL_ACTION_INVALID; | 608 | int max_i = RIL_ACTION_INVALID; |
@@ -615,17 +610,17 @@ agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | |||
615 | double max_q = -DBL_MAX; | 610 | double max_q = -DBL_MAX; |
616 | 611 | ||
617 | for (i = 0; i < agent->n; i++) | 612 | for (i = 0; i < agent->n; i++) |
618 | { | ||
619 | if (agent_action_is_possible(agent, i)) | ||
620 | { | 613 | { |
621 | cur_q = agent_q (agent, state, i); | 614 | if (agent_action_is_possible(agent, i)) |
622 | if (cur_q > max_q) | 615 | { |
623 | { | 616 | cur_q = agent_q(agent, state, i); |
624 | max_q = cur_q; | 617 | if (cur_q > max_q) |
625 | max_i = i; | 618 | { |
626 | } | 619 | max_q = cur_q; |
620 | max_i = i; | ||
621 | } | ||
622 | } | ||
627 | } | 623 | } |
628 | } | ||
629 | 624 | ||
630 | GNUNET_assert(RIL_ACTION_INVALID != max_i); | 625 | GNUNET_assert(RIL_ACTION_INVALID != max_i); |
631 | 626 | ||
@@ -639,38 +634,38 @@ agent_get_action_max (struct RIL_Peer_Agent *agent, double *state) | |||
639 | * @return the action index | 634 | * @return the action index |
640 | */ | 635 | */ |
641 | static int | 636 | static int |
642 | agent_get_action_random (struct RIL_Peer_Agent *agent) | 637 | agent_get_action_random(struct RIL_Peer_Agent *agent) |
643 | { | 638 | { |
644 | int i; | 639 | int i; |
645 | int is_possible[agent->n]; | 640 | int is_possible[agent->n]; |
646 | int sum = 0; | 641 | int sum = 0; |
647 | int r; | 642 | int r; |
648 | 643 | ||
649 | for (i = 0; i<agent->n; i++) | 644 | for (i = 0; i < agent->n; i++) |
650 | { | ||
651 | if (agent_action_is_possible(agent, i)) | ||
652 | { | ||
653 | is_possible[i] = GNUNET_YES; | ||
654 | sum++; | ||
655 | } | ||
656 | else | ||
657 | { | 645 | { |
658 | is_possible[i] = GNUNET_NO; | 646 | if (agent_action_is_possible(agent, i)) |
647 | { | ||
648 | is_possible[i] = GNUNET_YES; | ||
649 | sum++; | ||
650 | } | ||
651 | else | ||
652 | { | ||
653 | is_possible[i] = GNUNET_NO; | ||
654 | } | ||
659 | } | 655 | } |
660 | } | ||
661 | 656 | ||
662 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, sum); | 657 | r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, sum); |
663 | 658 | ||
664 | sum = -1; | 659 | sum = -1; |
665 | for (i = 0; i<agent->n; i++) | 660 | for (i = 0; i < agent->n; i++) |
666 | { | ||
667 | if (is_possible[i]) | ||
668 | { | 661 | { |
669 | sum++; | 662 | if (is_possible[i]) |
670 | if (sum == r) | 663 | { |
671 | return i; | 664 | sum++; |
665 | if (sum == r) | ||
666 | return i; | ||
667 | } | ||
672 | } | 668 | } |
673 | } | ||
674 | 669 | ||
675 | GNUNET_assert(GNUNET_NO); | 670 | GNUNET_assert(GNUNET_NO); |
676 | return RIL_ACTION_INVALID; | 671 | return RIL_ACTION_INVALID; |
@@ -686,7 +681,7 @@ agent_get_action_random (struct RIL_Peer_Agent *agent) | |||
686 | * @param a_prime the new | 681 | * @param a_prime the new |
687 | */ | 682 | */ |
688 | static void | 683 | static void |
689 | agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime) | 684 | agent_update(struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime) |
690 | { | 685 | { |
691 | int i; | 686 | int i; |
692 | int k; | 687 | int k; |
@@ -694,8 +689,8 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
694 | double **theta = agent->W; | 689 | double **theta = agent->W; |
695 | 690 | ||
696 | delta = agent->envi->global_discount_integrated * reward; //reward | 691 | delta = agent->envi->global_discount_integrated * reward; //reward |
697 | delta += agent->envi->global_discount_variable * agent_q (agent, s_next, a_prime); //discounted future value | 692 | delta += agent->envi->global_discount_variable * agent_q(agent, s_next, a_prime); //discounted future value |
698 | delta -= agent_q (agent, agent->s_old, agent->a_old); //one step | 693 | delta -= agent_q(agent, agent->s_old, agent->a_old); //one step |
699 | 694 | ||
700 | // LOG(GNUNET_ERROR_TYPE_INFO, "update() Step# %llu Q(s,a): %f a: %f r: %f y: %f Q(s+1,a+1) = %f delta: %f\n", | 695 | // LOG(GNUNET_ERROR_TYPE_INFO, "update() Step# %llu Q(s,a): %f a: %f r: %f y: %f Q(s+1,a+1) = %f delta: %f\n", |
701 | // agent->step_count, | 696 | // agent->step_count, |
@@ -707,17 +702,17 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
707 | // delta); | 702 | // delta); |
708 | 703 | ||
709 | for (k = 0; k < agent->n; k++) | 704 | for (k = 0; k < agent->n; k++) |
710 | { | ||
711 | for (i = 0; i < agent->m; i++) | ||
712 | { | 705 | { |
713 | // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n", | 706 | for (i = 0; i < agent->m; i++) |
714 | // agent->envi->parameters.alpha, | 707 | { |
715 | // delta, | 708 | // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n", |
716 | // i, | 709 | // agent->envi->parameters.alpha, |
717 | // agent->e[i]); | 710 | // delta, |
718 | theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i]; | 711 | // i, |
712 | // agent->e[i]); | ||
713 | theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i]; | ||
714 | } | ||
719 | } | 715 | } |
720 | } | ||
721 | } | 716 | } |
722 | 717 | ||
723 | 718 | ||
@@ -734,38 +729,41 @@ agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int a | |||
734 | * @param action the action to take | 729 | * @param action the action to take |
735 | */ | 730 | */ |
736 | static void | 731 | static void |
737 | agent_modify_eligibility (struct RIL_Peer_Agent *agent, | 732 | agent_modify_eligibility(struct RIL_Peer_Agent *agent, |
738 | enum RIL_E_Modification mod, | 733 | enum RIL_E_Modification mod, |
739 | double *feature, | 734 | double *feature, |
740 | int action) | 735 | int action) |
741 | { | 736 | { |
742 | int i; | 737 | int i; |
743 | int k; | 738 | int k; |
744 | 739 | ||
745 | for (i = 0; i < agent->m; i++) | 740 | for (i = 0; i < agent->m; i++) |
746 | { | ||
747 | switch (mod) | ||
748 | { | 741 | { |
749 | case RIL_E_ACCUMULATE: | 742 | switch (mod) |
750 | agent->E[action][i] += feature[i]; | 743 | { |
751 | break; | 744 | case RIL_E_ACCUMULATE: |
752 | case RIL_E_REPLACE: | 745 | agent->E[action][i] += feature[i]; |
753 | agent->E[action][i] = agent->E[action][i] > feature[i] ? agent->E[action][i] : feature[i]; | 746 | break; |
754 | break; | 747 | |
755 | case RIL_E_DECAY: | 748 | case RIL_E_REPLACE: |
756 | for (k = 0; k < agent->n; k++) | 749 | agent->E[action][i] = agent->E[action][i] > feature[i] ? agent->E[action][i] : feature[i]; |
757 | { | 750 | break; |
758 | agent->E[k][i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda; | 751 | |
759 | } | 752 | case RIL_E_DECAY: |
760 | break; | 753 | for (k = 0; k < agent->n; k++) |
761 | case RIL_E_ZERO: | 754 | { |
762 | for (k = 0; k < agent->n; k++) | 755 | agent->E[k][i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda; |
763 | { | 756 | } |
764 | agent->E[k][i] = 0; | 757 | break; |
765 | } | 758 | |
766 | break; | 759 | case RIL_E_ZERO: |
760 | for (k = 0; k < agent->n; k++) | ||
761 | { | ||
762 | agent->E[k][i] = 0; | ||
763 | } | ||
764 | break; | ||
765 | } | ||
767 | } | 766 | } |
768 | } | ||
769 | } | 767 | } |
770 | 768 | ||
771 | /** | 769 | /** |
@@ -776,14 +774,14 @@ agent_modify_eligibility (struct RIL_Peer_Agent *agent, | |||
776 | * @param stat | 774 | * @param stat |
777 | */ | 775 | */ |
778 | static void | 776 | static void |
779 | ril_inform (struct GAS_RIL_Handle *solver, | 777 | ril_inform(struct GAS_RIL_Handle *solver, |
780 | enum GAS_Solver_Operation op, | 778 | enum GAS_Solver_Operation op, |
781 | enum GAS_Solver_Status stat) | 779 | enum GAS_Solver_Status stat) |
782 | { | 780 | { |
783 | solver->env->info_cb (solver->env->cls, | 781 | solver->env->info_cb(solver->env->cls, |
784 | op, | 782 | op, |
785 | stat, | 783 | stat, |
786 | GAS_INFO_NONE); | 784 | GAS_INFO_NONE); |
787 | } | 785 | } |
788 | 786 | ||
789 | /** | 787 | /** |
@@ -792,7 +790,7 @@ ril_inform (struct GAS_RIL_Handle *solver, | |||
792 | * @param net | 790 | * @param net |
793 | */ | 791 | */ |
794 | static unsigned long long | 792 | static unsigned long long |
795 | ril_get_max_bw (struct RIL_Scope *net) | 793 | ril_get_max_bw(struct RIL_Scope *net) |
796 | { | 794 | { |
797 | return GNUNET_MIN(2 * GNUNET_MAX(net->bw_in_available, net->bw_out_available), GNUNET_ATS_MaxBandwidth); | 795 | return GNUNET_MIN(2 * GNUNET_MAX(net->bw_in_available, net->bw_out_available), GNUNET_ATS_MaxBandwidth); |
798 | } | 796 | } |
@@ -809,82 +807,82 @@ ril_get_max_bw (struct RIL_Scope *net) | |||
809 | * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES | 807 | * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES |
810 | */ | 808 | */ |
811 | static void | 809 | static void |
812 | envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | 810 | envi_set_active_suggestion(struct GAS_RIL_Handle *solver, |
813 | struct RIL_Peer_Agent *agent, | 811 | struct RIL_Peer_Agent *agent, |
814 | struct ATS_Address *new_address, | 812 | struct ATS_Address *new_address, |
815 | unsigned long long new_bw_in, | 813 | unsigned long long new_bw_in, |
816 | unsigned long long new_bw_out, | 814 | unsigned long long new_bw_out, |
817 | int silent) | 815 | int silent) |
818 | { | 816 | { |
819 | int notify = GNUNET_NO; | 817 | int notify = GNUNET_NO; |
820 | 818 | ||
821 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 819 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
822 | " set_active_suggestion() for peer '%s'\n", | 820 | " set_active_suggestion() for peer '%s'\n", |
823 | GNUNET_i2s (&agent->peer)); | 821 | GNUNET_i2s(&agent->peer)); |
824 | 822 | ||
825 | //address change | 823 | //address change |
826 | if (agent->address_inuse != new_address) | 824 | if (agent->address_inuse != new_address) |
827 | { | ||
828 | if (NULL != agent->address_inuse) | ||
829 | { | 825 | { |
830 | agent->address_inuse->active = GNUNET_NO; | 826 | if (NULL != agent->address_inuse) |
831 | agent->address_inuse->assigned_bw_in = 0; | 827 | { |
832 | agent->address_inuse->assigned_bw_out = 0; | 828 | agent->address_inuse->active = GNUNET_NO; |
833 | } | 829 | agent->address_inuse->assigned_bw_in = 0; |
834 | if (NULL != new_address) | 830 | agent->address_inuse->assigned_bw_out = 0; |
835 | { | 831 | } |
836 | LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no"); | 832 | if (NULL != new_address) |
837 | new_address->active = agent->is_active; | 833 | { |
838 | new_address->assigned_bw_in = agent->bw_in; | 834 | LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no"); |
839 | new_address->assigned_bw_out = agent->bw_out; | 835 | new_address->active = agent->is_active; |
840 | } | 836 | new_address->assigned_bw_in = agent->bw_in; |
841 | notify |= GNUNET_YES; | 837 | new_address->assigned_bw_out = agent->bw_out; |
842 | } | 838 | } |
843 | |||
844 | if (new_address) | ||
845 | { | ||
846 | //activity change | ||
847 | if (new_address->active != agent->is_active) | ||
848 | { | ||
849 | new_address->active = agent->is_active; | ||
850 | notify |= GNUNET_YES; | 839 | notify |= GNUNET_YES; |
851 | } | 840 | } |
852 | 841 | ||
853 | //bw change | 842 | if (new_address) |
854 | if (agent->bw_in != new_bw_in) | ||
855 | { | ||
856 | agent->bw_in = new_bw_in; | ||
857 | new_address->assigned_bw_in = new_bw_in; | ||
858 | notify |= GNUNET_YES; | ||
859 | } | ||
860 | if (agent->bw_out != new_bw_out) | ||
861 | { | 843 | { |
862 | agent->bw_out = new_bw_out; | 844 | //activity change |
863 | new_address->assigned_bw_out = new_bw_out; | 845 | if (new_address->active != agent->is_active) |
864 | notify |= GNUNET_YES; | 846 | { |
847 | new_address->active = agent->is_active; | ||
848 | notify |= GNUNET_YES; | ||
849 | } | ||
850 | |||
851 | //bw change | ||
852 | if (agent->bw_in != new_bw_in) | ||
853 | { | ||
854 | agent->bw_in = new_bw_in; | ||
855 | new_address->assigned_bw_in = new_bw_in; | ||
856 | notify |= GNUNET_YES; | ||
857 | } | ||
858 | if (agent->bw_out != new_bw_out) | ||
859 | { | ||
860 | agent->bw_out = new_bw_out; | ||
861 | new_address->assigned_bw_out = new_bw_out; | ||
862 | notify |= GNUNET_YES; | ||
863 | } | ||
865 | } | 864 | } |
866 | } | ||
867 | 865 | ||
868 | if (notify && agent->is_active && (GNUNET_NO == silent)) | 866 | if (notify && agent->is_active && (GNUNET_NO == silent)) |
869 | { | ||
870 | if (new_address) | ||
871 | { | ||
872 | LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n"); | ||
873 | agent->suggestion_issue = GNUNET_YES; | ||
874 | agent->suggestion_address = new_address; | ||
875 | } | ||
876 | else if (agent->address_inuse) | ||
877 | { | 867 | { |
878 | /* disconnect case, no new address */ | 868 | if (new_address) |
879 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_in); | 869 | { |
880 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_out); | 870 | LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n"); |
881 | agent->bw_in = 0; | 871 | agent->suggestion_issue = GNUNET_YES; |
882 | agent->bw_out = 0; | 872 | agent->suggestion_address = new_address; |
883 | 873 | } | |
884 | agent->suggestion_issue = GNUNET_YES; | 874 | else if (agent->address_inuse) |
885 | agent->suggestion_address = agent->address_inuse; | 875 | { |
876 | /* disconnect case, no new address */ | ||
877 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_in); | ||
878 | GNUNET_assert(0 == agent->address_inuse->assigned_bw_out); | ||
879 | agent->bw_in = 0; | ||
880 | agent->bw_out = 0; | ||
881 | |||
882 | agent->suggestion_issue = GNUNET_YES; | ||
883 | agent->suggestion_address = agent->address_inuse; | ||
884 | } | ||
886 | } | 885 | } |
887 | } | ||
888 | agent->address_inuse = new_address; | 886 | agent->address_inuse = new_address; |
889 | } | 887 | } |
890 | 888 | ||
@@ -896,7 +894,7 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver, | |||
896 | * @return pointer to the state vector | 894 | * @return pointer to the state vector |
897 | */ | 895 | */ |
898 | static double * | 896 | static double * |
899 | envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 897 | envi_get_state(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
900 | { | 898 | { |
901 | double *state; | 899 | double *state; |
902 | double y[2]; | 900 | double y[2]; |
@@ -909,27 +907,27 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
909 | int k; | 907 | int k; |
910 | unsigned long long max_bw; | 908 | unsigned long long max_bw; |
911 | 909 | ||
912 | state = GNUNET_malloc (sizeof(double) * agent->m); | 910 | state = GNUNET_malloc(sizeof(double) * agent->m); |
913 | 911 | ||
914 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 912 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
915 | 913 | ||
916 | y[0] = (double) agent->bw_out; | 914 | y[0] = (double)agent->bw_out; |
917 | y[1] = (double) agent->bw_in; | 915 | y[1] = (double)agent->bw_in; |
918 | 916 | ||
919 | m = agent_address_get_index (agent, agent->address_inuse) * (solver->parameters.rbf_divisor+1) * (solver->parameters.rbf_divisor+1); | 917 | m = agent_address_get_index(agent, agent->address_inuse) * (solver->parameters.rbf_divisor + 1) * (solver->parameters.rbf_divisor + 1); |
920 | for (i = 0; i <= solver->parameters.rbf_divisor; i++) | 918 | for (i = 0; i <= solver->parameters.rbf_divisor; i++) |
921 | { | ||
922 | for (k = 0; k <= solver->parameters.rbf_divisor; k++) | ||
923 | { | 919 | { |
924 | x[0] = (double) i * (double) max_bw / (double) solver->parameters.rbf_divisor; | 920 | for (k = 0; k <= solver->parameters.rbf_divisor; k++) |
925 | x[1] = (double) k * (double) max_bw / (double) solver->parameters.rbf_divisor; | 921 | { |
926 | d[0] = x[0]-y[0]; | 922 | x[0] = (double)i * (double)max_bw / (double)solver->parameters.rbf_divisor; |
927 | d[1] = x[1]-y[1]; | 923 | x[1] = (double)k * (double)max_bw / (double)solver->parameters.rbf_divisor; |
928 | sigma = (((double) max_bw / ((double) solver->parameters.rbf_divisor + 1)) * 0.5); | 924 | d[0] = x[0] - y[0]; |
929 | f = exp(-((d[0]*d[0] + d[1]*d[1]) / (2 * sigma * sigma))); | 925 | d[1] = x[1] - y[1]; |
930 | state[m++] = f; | 926 | sigma = (((double)max_bw / ((double)solver->parameters.rbf_divisor + 1)) * 0.5); |
927 | f = exp(-((d[0] * d[0] + d[1] * d[1]) / (2 * sigma * sigma))); | ||
928 | state[m++] = f; | ||
929 | } | ||
931 | } | 930 | } |
932 | } | ||
933 | 931 | ||
934 | return state; | 932 | return state; |
935 | } | 933 | } |
@@ -942,22 +940,22 @@ envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
942 | * @return the utility value | 940 | * @return the utility value |
943 | */ | 941 | */ |
944 | static double | 942 | static double |
945 | agent_get_utility (struct RIL_Peer_Agent *agent) | 943 | agent_get_utility(struct RIL_Peer_Agent *agent) |
946 | { | 944 | { |
947 | const double *preferences; | 945 | const double *preferences; |
948 | double delay_atsi; | 946 | double delay_atsi; |
949 | double delay_norm; | 947 | double delay_norm; |
950 | double pref_match; | 948 | double pref_match; |
951 | 949 | ||
952 | preferences = agent->envi->env->get_preferences (agent->envi->env->cls, | 950 | preferences = agent->envi->env->get_preferences(agent->envi->env->cls, |
953 | &agent->peer); | 951 | &agent->peer); |
954 | 952 | ||
955 | delay_atsi = agent->address_inuse->norm_delay.norm; | 953 | delay_atsi = agent->address_inuse->norm_delay.norm; |
956 | delay_norm = RIL_UTILITY_DELAY_MAX*exp(-delay_atsi*0.00001); | 954 | delay_norm = RIL_UTILITY_DELAY_MAX * exp(-delay_atsi * 0.00001); |
957 | 955 | ||
958 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; | 956 | pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; |
959 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * | 957 | pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * |
960 | sqrt((double) (agent->bw_in/RIL_MIN_BW) * (double) (agent->bw_out/RIL_MIN_BW)); | 958 | sqrt((double)(agent->bw_in / RIL_MIN_BW) * (double)(agent->bw_out / RIL_MIN_BW)); |
961 | return pref_match; | 959 | return pref_match; |
962 | } | 960 | } |
963 | 961 | ||
@@ -970,41 +968,41 @@ agent_get_utility (struct RIL_Peer_Agent *agent) | |||
970 | * @return the social welfare value | 968 | * @return the social welfare value |
971 | */ | 969 | */ |
972 | static double | 970 | static double |
973 | ril_network_get_social_welfare (struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) | 971 | ril_network_get_social_welfare(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) |
974 | { | 972 | { |
975 | struct RIL_Peer_Agent *cur; | 973 | struct RIL_Peer_Agent *cur; |
976 | double result; | 974 | double result; |
977 | 975 | ||
978 | switch (solver->parameters.social_welfare) | 976 | switch (solver->parameters.social_welfare) |
979 | { | ||
980 | case RIL_WELFARE_EGALITARIAN: | ||
981 | result = DBL_MAX; | ||
982 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
983 | { | ||
984 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
985 | { | ||
986 | result = GNUNET_MIN(result, agent_get_utility(cur)); | ||
987 | } | ||
988 | } | ||
989 | return result; | ||
990 | |||
991 | case RIL_WELFARE_NASH: | ||
992 | result = 0; | ||
993 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
994 | { | 977 | { |
995 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | 978 | case RIL_WELFARE_EGALITARIAN: |
996 | { | 979 | result = DBL_MAX; |
997 | result *= pow(agent_get_utility(cur), 1.0 / (double) scope->active_agent_count); | 980 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
998 | } | 981 | { |
982 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
983 | { | ||
984 | result = GNUNET_MIN(result, agent_get_utility(cur)); | ||
985 | } | ||
986 | } | ||
987 | return result; | ||
988 | |||
989 | case RIL_WELFARE_NASH: | ||
990 | result = 0; | ||
991 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | ||
992 | { | ||
993 | if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) | ||
994 | { | ||
995 | result *= pow(agent_get_utility(cur), 1.0 / (double)scope->active_agent_count); | ||
996 | } | ||
997 | } | ||
998 | return result; | ||
999 | } | 999 | } |
1000 | return result; | ||
1001 | } | ||
1002 | GNUNET_assert(GNUNET_NO); | 1000 | GNUNET_assert(GNUNET_NO); |
1003 | return 1; | 1001 | return 1; |
1004 | } | 1002 | } |
1005 | 1003 | ||
1006 | static double | 1004 | static double |
1007 | envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1005 | envi_get_penalty(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1008 | { | 1006 | { |
1009 | struct RIL_Scope *net; | 1007 | struct RIL_Scope *net; |
1010 | unsigned long long over_max; | 1008 | unsigned long long over_max; |
@@ -1014,26 +1012,26 @@ envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1014 | net = agent->address_inuse->solver_information; | 1012 | net = agent->address_inuse->solver_information; |
1015 | 1013 | ||
1016 | if (net->bw_in_utilized > net->bw_in_available) | 1014 | if (net->bw_in_utilized > net->bw_in_available) |
1017 | { | ||
1018 | over_in = net->bw_in_utilized - net->bw_in_available; | ||
1019 | if (RIL_ACTION_BW_IN_INC == agent->a_old) | ||
1020 | { | 1015 | { |
1021 | /* increase quadratically */ | 1016 | over_in = net->bw_in_utilized - net->bw_in_available; |
1022 | over_in *= over_in; | 1017 | if (RIL_ACTION_BW_IN_INC == agent->a_old) |
1018 | { | ||
1019 | /* increase quadratically */ | ||
1020 | over_in *= over_in; | ||
1021 | } | ||
1023 | } | 1022 | } |
1024 | } | ||
1025 | if (net->bw_out_utilized > net->bw_out_available) | 1023 | if (net->bw_out_utilized > net->bw_out_available) |
1026 | { | ||
1027 | over_out = net->bw_out_utilized - net->bw_out_available; | ||
1028 | if (RIL_ACTION_BW_OUT_INC == agent->a_old) | ||
1029 | { | 1024 | { |
1030 | /* increase quadratically */ | 1025 | over_out = net->bw_out_utilized - net->bw_out_available; |
1031 | over_out *= over_out; | 1026 | if (RIL_ACTION_BW_OUT_INC == agent->a_old) |
1027 | { | ||
1028 | /* increase quadratically */ | ||
1029 | over_out *= over_out; | ||
1030 | } | ||
1032 | } | 1031 | } |
1033 | } | ||
1034 | over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW); | 1032 | over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW); |
1035 | 1033 | ||
1036 | return -1.0 * (double) over_max; | 1034 | return -1.0 * (double)over_max; |
1037 | } | 1035 | } |
1038 | 1036 | ||
1039 | /** | 1037 | /** |
@@ -1046,7 +1044,7 @@ envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1046 | * @return the reward | 1044 | * @return the reward |
1047 | */ | 1045 | */ |
1048 | static double | 1046 | static double |
1049 | envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1047 | envi_get_reward(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1050 | { | 1048 | { |
1051 | struct RIL_Scope *net; | 1049 | struct RIL_Scope *net; |
1052 | double objective; | 1050 | double objective; |
@@ -1058,18 +1056,18 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1058 | net = agent->address_inuse->solver_information; | 1056 | net = agent->address_inuse->solver_information; |
1059 | 1057 | ||
1060 | penalty = envi_get_penalty(solver, agent); | 1058 | penalty = envi_get_penalty(solver, agent); |
1061 | objective = (agent_get_utility (agent) + net->social_welfare) / 2; | 1059 | objective = (agent_get_utility(agent) + net->social_welfare) / 2; |
1062 | delta = objective - agent->objective_old; | 1060 | delta = objective - agent->objective_old; |
1063 | agent->objective_old = objective; | 1061 | agent->objective_old = objective; |
1064 | 1062 | ||
1065 | if (delta != 0 && penalty == 0) | 1063 | if (delta != 0 && penalty == 0) |
1066 | { | 1064 | { |
1067 | agent->nop_bonus = delta * RIL_NOP_DECAY; | 1065 | agent->nop_bonus = delta * RIL_NOP_DECAY; |
1068 | } | 1066 | } |
1069 | else | 1067 | else |
1070 | { | 1068 | { |
1071 | agent->nop_bonus *= RIL_NOP_DECAY; | 1069 | agent->nop_bonus *= RIL_NOP_DECAY; |
1072 | } | 1070 | } |
1073 | 1071 | ||
1074 | steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; | 1072 | steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; |
1075 | 1073 | ||
@@ -1085,31 +1083,31 @@ envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
1085 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth | 1083 | * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth |
1086 | */ | 1084 | */ |
1087 | static void | 1085 | static void |
1088 | envi_action_bw_double (struct GAS_RIL_Handle *solver, | 1086 | envi_action_bw_double(struct GAS_RIL_Handle *solver, |
1089 | struct RIL_Peer_Agent *agent, | 1087 | struct RIL_Peer_Agent *agent, |
1090 | int direction_in) | 1088 | int direction_in) |
1091 | { | 1089 | { |
1092 | unsigned long long new_bw; | 1090 | unsigned long long new_bw; |
1093 | unsigned long long max_bw; | 1091 | unsigned long long max_bw; |
1094 | 1092 | ||
1095 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 1093 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
1096 | 1094 | ||
1097 | if (direction_in) | 1095 | if (direction_in) |
1098 | { | 1096 | { |
1099 | new_bw = agent->bw_in * 2; | 1097 | new_bw = agent->bw_in * 2; |
1100 | if (new_bw < agent->bw_in || new_bw > max_bw) | 1098 | if (new_bw < agent->bw_in || new_bw > max_bw) |
1101 | new_bw = max_bw; | 1099 | new_bw = max_bw; |
1102 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, | 1100 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, |
1103 | agent->bw_out, GNUNET_NO); | 1101 | agent->bw_out, GNUNET_NO); |
1104 | } | 1102 | } |
1105 | else | 1103 | else |
1106 | { | 1104 | { |
1107 | new_bw = agent->bw_out * 2; | 1105 | new_bw = agent->bw_out * 2; |
1108 | if (new_bw < agent->bw_out || new_bw > max_bw) | 1106 | if (new_bw < agent->bw_out || new_bw > max_bw) |
1109 | new_bw = max_bw; | 1107 | new_bw = max_bw; |
1110 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, | 1108 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, |
1111 | new_bw, GNUNET_NO); | 1109 | new_bw, GNUNET_NO); |
1112 | } | 1110 | } |
1113 | } | 1111 | } |
1114 | 1112 | ||
1115 | /** | 1113 | /** |
@@ -1122,28 +1120,28 @@ envi_action_bw_double (struct GAS_RIL_Handle *solver, | |||
1122 | * bandwidth | 1120 | * bandwidth |
1123 | */ | 1121 | */ |
1124 | static void | 1122 | static void |
1125 | envi_action_bw_halven (struct GAS_RIL_Handle *solver, | 1123 | envi_action_bw_halven(struct GAS_RIL_Handle *solver, |
1126 | struct RIL_Peer_Agent *agent, | 1124 | struct RIL_Peer_Agent *agent, |
1127 | int direction_in) | 1125 | int direction_in) |
1128 | { | 1126 | { |
1129 | unsigned long long new_bw; | 1127 | unsigned long long new_bw; |
1130 | 1128 | ||
1131 | if (direction_in) | 1129 | if (direction_in) |
1132 | { | 1130 | { |
1133 | new_bw = agent->bw_in / 2; | 1131 | new_bw = agent->bw_in / 2; |
1134 | if (new_bw <= 0 || new_bw > agent->bw_in) | 1132 | if (new_bw <= 0 || new_bw > agent->bw_in) |
1135 | new_bw = 0; | 1133 | new_bw = 0; |
1136 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, | 1134 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, |
1137 | GNUNET_NO); | 1135 | GNUNET_NO); |
1138 | } | 1136 | } |
1139 | else | 1137 | else |
1140 | { | 1138 | { |
1141 | new_bw = agent->bw_out / 2; | 1139 | new_bw = agent->bw_out / 2; |
1142 | if (new_bw <= 0 || new_bw > agent->bw_out) | 1140 | if (new_bw <= 0 || new_bw > agent->bw_out) |
1143 | new_bw = 0; | 1141 | new_bw = 0; |
1144 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, | 1142 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, |
1145 | GNUNET_NO); | 1143 | GNUNET_NO); |
1146 | } | 1144 | } |
1147 | } | 1145 | } |
1148 | 1146 | ||
1149 | /** | 1147 | /** |
@@ -1155,29 +1153,29 @@ envi_action_bw_halven (struct GAS_RIL_Handle *solver, | |||
1155 | * bandwidth | 1153 | * bandwidth |
1156 | */ | 1154 | */ |
1157 | static void | 1155 | static void |
1158 | envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 1156 | envi_action_bw_inc(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
1159 | { | 1157 | { |
1160 | unsigned long long new_bw; | 1158 | unsigned long long new_bw; |
1161 | unsigned long long max_bw; | 1159 | unsigned long long max_bw; |
1162 | 1160 | ||
1163 | max_bw = ril_get_max_bw((struct RIL_Scope *) agent->address_inuse->solver_information); | 1161 | max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); |
1164 | 1162 | ||
1165 | if (direction_in) | 1163 | if (direction_in) |
1166 | { | 1164 | { |
1167 | new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1165 | new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1168 | if (new_bw < agent->bw_in || new_bw > max_bw) | 1166 | if (new_bw < agent->bw_in || new_bw > max_bw) |
1169 | new_bw = max_bw; | 1167 | new_bw = max_bw; |
1170 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, | 1168 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, |
1171 | agent->bw_out, GNUNET_NO); | 1169 | agent->bw_out, GNUNET_NO); |
1172 | } | 1170 | } |
1173 | else | 1171 | else |
1174 | { | 1172 | { |
1175 | new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1173 | new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1176 | if (new_bw < agent->bw_out || new_bw > max_bw) | 1174 | if (new_bw < agent->bw_out || new_bw > max_bw) |
1177 | new_bw = max_bw; | 1175 | new_bw = max_bw; |
1178 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, | 1176 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, |
1179 | new_bw, GNUNET_NO); | 1177 | new_bw, GNUNET_NO); |
1180 | } | 1178 | } |
1181 | } | 1179 | } |
1182 | 1180 | ||
1183 | /** | 1181 | /** |
@@ -1190,26 +1188,26 @@ envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
1190 | * bandwidth | 1188 | * bandwidth |
1191 | */ | 1189 | */ |
1192 | static void | 1190 | static void |
1193 | envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) | 1191 | envi_action_bw_dec(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) |
1194 | { | 1192 | { |
1195 | unsigned long long new_bw; | 1193 | unsigned long long new_bw; |
1196 | 1194 | ||
1197 | if (direction_in) | 1195 | if (direction_in) |
1198 | { | 1196 | { |
1199 | new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1197 | new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1200 | if (new_bw <= 0 || new_bw > agent->bw_in) | 1198 | if (new_bw <= 0 || new_bw > agent->bw_in) |
1201 | new_bw = 0; | 1199 | new_bw = 0; |
1202 | envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw, agent->bw_out, | 1200 | envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, |
1203 | GNUNET_NO); | 1201 | GNUNET_NO); |
1204 | } | 1202 | } |
1205 | else | 1203 | else |
1206 | { | 1204 | { |
1207 | new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); | 1205 | new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); |
1208 | if (new_bw <= 0 || new_bw > agent->bw_out) | 1206 | if (new_bw <= 0 || new_bw > agent->bw_out) |
1209 | new_bw = 0; | 1207 | new_bw = 0; |
1210 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, new_bw, | 1208 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, |
1211 | GNUNET_NO); | 1209 | GNUNET_NO); |
1212 | } | 1210 | } |
1213 | } | 1211 | } |
1214 | 1212 | ||
1215 | /** | 1213 | /** |
@@ -1220,9 +1218,9 @@ envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, | |||
1220 | * @param address_index index of the address as it is saved in the agent's list, starting with zero | 1218 | * @param address_index index of the address as it is saved in the agent's list, starting with zero |
1221 | */ | 1219 | */ |
1222 | static void | 1220 | static void |
1223 | envi_action_address_switch (struct GAS_RIL_Handle *solver, | 1221 | envi_action_address_switch(struct GAS_RIL_Handle *solver, |
1224 | struct RIL_Peer_Agent *agent, | 1222 | struct RIL_Peer_Agent *agent, |
1225 | unsigned int address_index) | 1223 | unsigned int address_index) |
1226 | { | 1224 | { |
1227 | struct RIL_Address_Wrapped *cur; | 1225 | struct RIL_Address_Wrapped *cur; |
1228 | int i = 0; | 1226 | int i = 0; |
@@ -1230,17 +1228,17 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver, | |||
1230 | //cur = agent_address_get_wrapped(agent, agent->address_inuse); | 1228 | //cur = agent_address_get_wrapped(agent, agent->address_inuse); |
1231 | 1229 | ||
1232 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) | 1230 | for (cur = agent->addresses_head; NULL != cur; cur = cur->next) |
1233 | { | ||
1234 | if (i == address_index) | ||
1235 | { | 1231 | { |
1236 | envi_set_active_suggestion (solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, | 1232 | if (i == address_index) |
1237 | GNUNET_NO); | 1233 | { |
1238 | return; | 1234 | envi_set_active_suggestion(solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, |
1235 | GNUNET_NO); | ||
1236 | return; | ||
1237 | } | ||
1238 | |||
1239 | i++; | ||
1239 | } | 1240 | } |
1240 | 1241 | ||
1241 | i++; | ||
1242 | } | ||
1243 | |||
1244 | //no address with address_index exists, in this case this action should not be callable | 1242 | //no address with address_index exists, in this case this action should not be callable |
1245 | GNUNET_assert(GNUNET_NO); | 1243 | GNUNET_assert(GNUNET_NO); |
1246 | } | 1244 | } |
@@ -1253,53 +1251,62 @@ envi_action_address_switch (struct GAS_RIL_Handle *solver, | |||
1253 | * @param action the action to perform by the solver | 1251 | * @param action the action to perform by the solver |
1254 | */ | 1252 | */ |
1255 | static void | 1253 | static void |
1256 | envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action) | 1254 | envi_do_action(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action) |
1257 | { | 1255 | { |
1258 | int address_index; | 1256 | int address_index; |
1259 | 1257 | ||
1260 | switch (action) | 1258 | switch (action) |
1261 | { | 1259 | { |
1262 | case RIL_ACTION_NOTHING: | 1260 | case RIL_ACTION_NOTHING: |
1263 | break; | 1261 | break; |
1264 | case RIL_ACTION_BW_IN_DBL: | 1262 | |
1265 | envi_action_bw_double (solver, agent, GNUNET_YES); | 1263 | case RIL_ACTION_BW_IN_DBL: |
1266 | break; | 1264 | envi_action_bw_double(solver, agent, GNUNET_YES); |
1267 | case RIL_ACTION_BW_IN_HLV: | 1265 | break; |
1268 | envi_action_bw_halven (solver, agent, GNUNET_YES); | 1266 | |
1269 | break; | 1267 | case RIL_ACTION_BW_IN_HLV: |
1270 | case RIL_ACTION_BW_IN_INC: | 1268 | envi_action_bw_halven(solver, agent, GNUNET_YES); |
1271 | envi_action_bw_inc (solver, agent, GNUNET_YES); | 1269 | break; |
1272 | break; | 1270 | |
1273 | case RIL_ACTION_BW_IN_DEC: | 1271 | case RIL_ACTION_BW_IN_INC: |
1274 | envi_action_bw_dec (solver, agent, GNUNET_YES); | 1272 | envi_action_bw_inc(solver, agent, GNUNET_YES); |
1275 | break; | 1273 | break; |
1276 | case RIL_ACTION_BW_OUT_DBL: | 1274 | |
1277 | envi_action_bw_double (solver, agent, GNUNET_NO); | 1275 | case RIL_ACTION_BW_IN_DEC: |
1278 | break; | 1276 | envi_action_bw_dec(solver, agent, GNUNET_YES); |
1279 | case RIL_ACTION_BW_OUT_HLV: | 1277 | break; |
1280 | envi_action_bw_halven (solver, agent, GNUNET_NO); | 1278 | |
1281 | break; | 1279 | case RIL_ACTION_BW_OUT_DBL: |
1282 | case RIL_ACTION_BW_OUT_INC: | 1280 | envi_action_bw_double(solver, agent, GNUNET_NO); |
1283 | envi_action_bw_inc (solver, agent, GNUNET_NO); | 1281 | break; |
1284 | break; | 1282 | |
1285 | case RIL_ACTION_BW_OUT_DEC: | 1283 | case RIL_ACTION_BW_OUT_HLV: |
1286 | envi_action_bw_dec (solver, agent, GNUNET_NO); | 1284 | envi_action_bw_halven(solver, agent, GNUNET_NO); |
1287 | break; | ||
1288 | default: | ||
1289 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
1290 | { | ||
1291 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
1292 | |||
1293 | GNUNET_assert(address_index >= 0); | ||
1294 | GNUNET_assert( | ||
1295 | address_index <= agent_address_get_index (agent, agent->addresses_tail->address_naked)); | ||
1296 | |||
1297 | envi_action_address_switch (solver, agent, address_index); | ||
1298 | break; | 1285 | break; |
1286 | |||
1287 | case RIL_ACTION_BW_OUT_INC: | ||
1288 | envi_action_bw_inc(solver, agent, GNUNET_NO); | ||
1289 | break; | ||
1290 | |||
1291 | case RIL_ACTION_BW_OUT_DEC: | ||
1292 | envi_action_bw_dec(solver, agent, GNUNET_NO); | ||
1293 | break; | ||
1294 | |||
1295 | default: | ||
1296 | if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action | ||
1297 | { | ||
1298 | address_index = action - RIL_ACTION_TYPE_NUM; | ||
1299 | |||
1300 | GNUNET_assert(address_index >= 0); | ||
1301 | GNUNET_assert( | ||
1302 | address_index <= agent_address_get_index(agent, agent->addresses_tail->address_naked)); | ||
1303 | |||
1304 | envi_action_address_switch(solver, agent, address_index); | ||
1305 | break; | ||
1306 | } | ||
1307 | // error - action does not exist | ||
1308 | GNUNET_assert(GNUNET_NO); | ||
1299 | } | 1309 | } |
1300 | // error - action does not exist | ||
1301 | GNUNET_assert(GNUNET_NO); | ||
1302 | } | ||
1303 | } | 1310 | } |
1304 | 1311 | ||
1305 | /** | 1312 | /** |
@@ -1314,27 +1321,27 @@ envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int | |||
1314 | * @return the action index | 1321 | * @return the action index |
1315 | */ | 1322 | */ |
1316 | static int | 1323 | static int |
1317 | agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state) | 1324 | agent_select_egreedy(struct RIL_Peer_Agent *agent, double *state) |
1318 | { | 1325 | { |
1319 | int action; | 1326 | int action; |
1320 | double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1327 | double r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1321 | UINT32_MAX) / (double) UINT32_MAX; | 1328 | UINT32_MAX) / (double)UINT32_MAX; |
1322 | 1329 | ||
1323 | if (r < agent->envi->parameters.epsilon) //explore | 1330 | if (r < agent->envi->parameters.epsilon) //explore |
1324 | { | ||
1325 | action = agent_get_action_random(agent); | ||
1326 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | ||
1327 | { | 1331 | { |
1328 | agent->eligibility_reset = GNUNET_YES; | 1332 | action = agent_get_action_random(agent); |
1333 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | ||
1334 | { | ||
1335 | agent->eligibility_reset = GNUNET_YES; | ||
1336 | } | ||
1337 | agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay; | ||
1338 | return action; | ||
1329 | } | 1339 | } |
1330 | agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay; | ||
1331 | return action; | ||
1332 | } | ||
1333 | else //exploit | 1340 | else //exploit |
1334 | { | 1341 | { |
1335 | action = agent_get_action_max(agent, state); | 1342 | action = agent_get_action_max(agent, state); |
1336 | return action; | 1343 | return action; |
1337 | } | 1344 | } |
1338 | } | 1345 | } |
1339 | 1346 | ||
1340 | /** | 1347 | /** |
@@ -1348,7 +1355,7 @@ agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state) | |||
1348 | * @return | 1355 | * @return |
1349 | */ | 1356 | */ |
1350 | static int | 1357 | static int |
1351 | agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | 1358 | agent_select_softmax(struct RIL_Peer_Agent *agent, double *state) |
1352 | { | 1359 | { |
1353 | int i; | 1360 | int i; |
1354 | int a_max; | 1361 | int a_max; |
@@ -1359,44 +1366,44 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | |||
1359 | 1366 | ||
1360 | a_max = agent_get_action_max(agent, state); | 1367 | a_max = agent_get_action_max(agent, state); |
1361 | 1368 | ||
1362 | for (i=0; i<agent->n; i++) | 1369 | for (i = 0; i < agent->n; i++) |
1363 | { | ||
1364 | if (agent_action_is_possible(agent, i)) | ||
1365 | { | ||
1366 | eqt[i] = exp(agent_q(agent,state,i) / agent->envi->parameters.temperature); | ||
1367 | if (isinf (eqt[i])) | ||
1368 | eqt[i] = isinf(eqt[i]) * UINT32_MAX; | ||
1369 | sum += eqt[i]; | ||
1370 | } | ||
1371 | } | ||
1372 | for (i=0; i<agent->n; i++) | ||
1373 | { | ||
1374 | if (agent_action_is_possible(agent, i)) | ||
1375 | { | 1370 | { |
1376 | p[i] = eqt[i]/sum; | 1371 | if (agent_action_is_possible(agent, i)) |
1372 | { | ||
1373 | eqt[i] = exp(agent_q(agent, state, i) / agent->envi->parameters.temperature); | ||
1374 | if (isinf(eqt[i])) | ||
1375 | eqt[i] = isinf(eqt[i]) * UINT32_MAX; | ||
1376 | sum += eqt[i]; | ||
1377 | } | ||
1377 | } | 1378 | } |
1378 | else | 1379 | for (i = 0; i < agent->n; i++) |
1379 | { | 1380 | { |
1380 | p[i] = 0; | 1381 | if (agent_action_is_possible(agent, i)) |
1382 | { | ||
1383 | p[i] = eqt[i] / sum; | ||
1384 | } | ||
1385 | else | ||
1386 | { | ||
1387 | p[i] = 0; | ||
1388 | } | ||
1381 | } | 1389 | } |
1382 | } | 1390 | r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1383 | r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1391 | UINT32_MAX) / (double)UINT32_MAX; |
1384 | UINT32_MAX) / (double) UINT32_MAX; | ||
1385 | sum = 0; | 1392 | sum = 0; |
1386 | for (i=0; i<agent->n; i++) | 1393 | for (i = 0; i < agent->n; i++) |
1387 | { | ||
1388 | if (sum + p[i] > r) | ||
1389 | { | 1394 | { |
1390 | if (i != a_max) | 1395 | if (sum + p[i] > r) |
1391 | { | 1396 | { |
1392 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) | 1397 | if (i != a_max) |
1393 | agent->eligibility_reset = GNUNET_YES; | 1398 | { |
1394 | agent->envi->parameters.temperature *= agent->envi->parameters.temperature_decay; | 1399 | if (RIL_ALGO_Q == agent->envi->parameters.algorithm) |
1395 | } | 1400 | agent->eligibility_reset = GNUNET_YES; |
1396 | return i; | 1401 | agent->envi->parameters.temperature *= agent->envi->parameters.temperature_decay; |
1402 | } | ||
1403 | return i; | ||
1404 | } | ||
1405 | sum += p[i]; | ||
1397 | } | 1406 | } |
1398 | sum += p[i]; | ||
1399 | } | ||
1400 | GNUNET_assert(GNUNET_NO); | 1407 | GNUNET_assert(GNUNET_NO); |
1401 | return RIL_ACTION_INVALID; | 1408 | return RIL_ACTION_INVALID; |
1402 | } | 1409 | } |
@@ -1410,16 +1417,16 @@ agent_select_softmax (struct RIL_Peer_Agent *agent, double *state) | |||
1410 | * @return the action index | 1417 | * @return the action index |
1411 | */ | 1418 | */ |
1412 | static int | 1419 | static int |
1413 | agent_select_action (struct RIL_Peer_Agent *agent, double *state) | 1420 | agent_select_action(struct RIL_Peer_Agent *agent, double *state) |
1414 | { | 1421 | { |
1415 | if (agent->envi->parameters.select == RIL_SELECT_EGREEDY) | 1422 | if (agent->envi->parameters.select == RIL_SELECT_EGREEDY) |
1416 | { | 1423 | { |
1417 | return agent_select_egreedy(agent, state); | 1424 | return agent_select_egreedy(agent, state); |
1418 | } | 1425 | } |
1419 | else | 1426 | else |
1420 | { | 1427 | { |
1421 | return agent_select_softmax(agent, state); | 1428 | return agent_select_softmax(agent, state); |
1422 | } | 1429 | } |
1423 | } | 1430 | } |
1424 | 1431 | ||
1425 | /** | 1432 | /** |
@@ -1431,7 +1438,7 @@ agent_select_action (struct RIL_Peer_Agent *agent, double *state) | |||
1431 | * @param agent the agent performing the step | 1438 | * @param agent the agent performing the step |
1432 | */ | 1439 | */ |
1433 | static void | 1440 | static void |
1434 | agent_step (struct RIL_Peer_Agent *agent) | 1441 | agent_step(struct RIL_Peer_Agent *agent) |
1435 | { | 1442 | { |
1436 | int a_next = RIL_ACTION_INVALID; | 1443 | int a_next = RIL_ACTION_INVALID; |
1437 | int a_max; | 1444 | int a_max; |
@@ -1439,58 +1446,58 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1439 | double reward; | 1446 | double reward; |
1440 | 1447 | ||
1441 | LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n", | 1448 | LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n", |
1442 | GNUNET_i2s (&agent->peer), | 1449 | GNUNET_i2s(&agent->peer), |
1443 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); | 1450 | agent->envi->parameters.algorithm ? "Q" : "SARSA"); |
1444 | 1451 | ||
1445 | s_next = envi_get_state (agent->envi, agent); | 1452 | s_next = envi_get_state(agent->envi, agent); |
1446 | reward = envi_get_reward (agent->envi, agent); | 1453 | reward = envi_get_reward(agent->envi, agent); |
1447 | 1454 | ||
1448 | if (agent->eligibility_reset) | 1455 | if (agent->eligibility_reset) |
1449 | { | 1456 | { |
1450 | agent_modify_eligibility(agent, RIL_E_ZERO, NULL, -1); | 1457 | agent_modify_eligibility(agent, RIL_E_ZERO, NULL, -1); |
1451 | agent->eligibility_reset = GNUNET_NO; | 1458 | agent->eligibility_reset = GNUNET_NO; |
1452 | } | 1459 | } |
1453 | else | 1460 | else |
1454 | { | 1461 | { |
1455 | agent_modify_eligibility (agent, RIL_E_DECAY, NULL, -1); | 1462 | agent_modify_eligibility(agent, RIL_E_DECAY, NULL, -1); |
1456 | } | 1463 | } |
1457 | if (RIL_ACTION_INVALID != agent->a_old) | 1464 | if (RIL_ACTION_INVALID != agent->a_old) |
1458 | { | ||
1459 | agent_modify_eligibility (agent, agent->envi->parameters.eligibility_trace_mode, agent->s_old, agent->a_old); | ||
1460 | } | ||
1461 | |||
1462 | switch (agent->envi->parameters.algorithm) | ||
1463 | { | ||
1464 | case RIL_ALGO_SARSA: | ||
1465 | a_next = agent_select_action (agent, s_next); | ||
1466 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1467 | { | 1465 | { |
1468 | //updates weights with selected action (on-policy), if not first step | 1466 | agent_modify_eligibility(agent, agent->envi->parameters.eligibility_trace_mode, agent->s_old, agent->a_old); |
1469 | agent_update (agent, reward, s_next, a_next); | ||
1470 | } | 1467 | } |
1471 | break; | ||
1472 | 1468 | ||
1473 | case RIL_ALGO_Q: | 1469 | switch (agent->envi->parameters.algorithm) |
1474 | a_max = agent_get_action_max (agent, s_next); | ||
1475 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1476 | { | 1470 | { |
1477 | //updates weights with best action, disregarding actually selected action (off-policy), if not first step | 1471 | case RIL_ALGO_SARSA: |
1478 | agent_update (agent, reward, s_next, a_max); | 1472 | a_next = agent_select_action(agent, s_next); |
1473 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1474 | { | ||
1475 | //updates weights with selected action (on-policy), if not first step | ||
1476 | agent_update(agent, reward, s_next, a_next); | ||
1477 | } | ||
1478 | break; | ||
1479 | |||
1480 | case RIL_ALGO_Q: | ||
1481 | a_max = agent_get_action_max(agent, s_next); | ||
1482 | if (RIL_ACTION_INVALID != agent->a_old) | ||
1483 | { | ||
1484 | //updates weights with best action, disregarding actually selected action (off-policy), if not first step | ||
1485 | agent_update(agent, reward, s_next, a_max); | ||
1486 | } | ||
1487 | a_next = agent_select_action(agent, s_next); | ||
1488 | break; | ||
1479 | } | 1489 | } |
1480 | a_next = agent_select_action (agent, s_next); | ||
1481 | break; | ||
1482 | } | ||
1483 | 1490 | ||
1484 | GNUNET_assert(RIL_ACTION_INVALID != a_next); | 1491 | GNUNET_assert(RIL_ACTION_INVALID != a_next); |
1485 | 1492 | ||
1486 | LOG (GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n", | 1493 | LOG(GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n", |
1487 | agent->step_count, | 1494 | agent->step_count, |
1488 | reward, | 1495 | reward, |
1489 | agent->bw_in/1024, | 1496 | agent->bw_in / 1024, |
1490 | agent->bw_out/1024, | 1497 | agent->bw_out / 1024, |
1491 | a_next); | 1498 | a_next); |
1492 | 1499 | ||
1493 | envi_do_action (agent->envi, agent, a_next); | 1500 | envi_do_action(agent->envi, agent, a_next); |
1494 | 1501 | ||
1495 | GNUNET_free(agent->s_old); | 1502 | GNUNET_free(agent->s_old); |
1496 | agent->s_old = s_next; | 1503 | agent->s_old = s_next; |
@@ -1505,7 +1512,7 @@ agent_step (struct RIL_Peer_Agent *agent) | |||
1505 | * @param solver the solver handle | 1512 | * @param solver the solver handle |
1506 | */ | 1513 | */ |
1507 | static void | 1514 | static void |
1508 | ril_step (struct GAS_RIL_Handle *solver); | 1515 | ril_step(struct GAS_RIL_Handle *solver); |
1509 | 1516 | ||
1510 | 1517 | ||
1511 | /** | 1518 | /** |
@@ -1515,12 +1522,12 @@ ril_step (struct GAS_RIL_Handle *solver); | |||
1515 | * @param cls the solver handle | 1522 | * @param cls the solver handle |
1516 | */ | 1523 | */ |
1517 | static void | 1524 | static void |
1518 | ril_step_scheduler_task (void *cls) | 1525 | ril_step_scheduler_task(void *cls) |
1519 | { | 1526 | { |
1520 | struct GAS_RIL_Handle *solver = cls; | 1527 | struct GAS_RIL_Handle *solver = cls; |
1521 | 1528 | ||
1522 | solver->step_next_task_id = NULL; | 1529 | solver->step_next_task_id = NULL; |
1523 | ril_step (solver); | 1530 | ril_step(solver); |
1524 | } | 1531 | } |
1525 | 1532 | ||
1526 | /** | 1533 | /** |
@@ -1532,7 +1539,7 @@ ril_step_scheduler_task (void *cls) | |||
1532 | * @return the ratio | 1539 | * @return the ratio |
1533 | */ | 1540 | */ |
1534 | static double | 1541 | static double |
1535 | ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | 1542 | ril_get_used_resource_ratio(struct GAS_RIL_Handle *solver) |
1536 | { | 1543 | { |
1537 | int i; | 1544 | int i; |
1538 | struct RIL_Scope net; | 1545 | struct RIL_Scope net; |
@@ -1541,24 +1548,24 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | |||
1541 | double ratio; | 1548 | double ratio; |
1542 | 1549 | ||
1543 | for (i = 0; i < solver->networks_count; i++) | 1550 | for (i = 0; i < solver->networks_count; i++) |
1544 | { | ||
1545 | net = solver->network_entries[i]; | ||
1546 | if (net.bw_in_assigned > 0) //only consider scopes where an address is actually active | ||
1547 | { | 1551 | { |
1548 | sum_assigned += net.bw_in_utilized; | 1552 | net = solver->network_entries[i]; |
1549 | sum_assigned += net.bw_out_utilized; | 1553 | if (net.bw_in_assigned > 0) //only consider scopes where an address is actually active |
1550 | sum_available += net.bw_in_available; | 1554 | { |
1551 | sum_available += net.bw_out_available; | 1555 | sum_assigned += net.bw_in_utilized; |
1556 | sum_assigned += net.bw_out_utilized; | ||
1557 | sum_available += net.bw_in_available; | ||
1558 | sum_available += net.bw_out_available; | ||
1559 | } | ||
1552 | } | 1560 | } |
1553 | } | ||
1554 | if (sum_available > 0) | 1561 | if (sum_available > 0) |
1555 | { | 1562 | { |
1556 | ratio = ((double) sum_assigned) / ((double) sum_available); | 1563 | ratio = ((double)sum_assigned) / ((double)sum_available); |
1557 | } | 1564 | } |
1558 | else | 1565 | else |
1559 | { | 1566 | { |
1560 | ratio = 0; | 1567 | ratio = 0; |
1561 | } | 1568 | } |
1562 | 1569 | ||
1563 | return ratio > 1 ? 1 : ratio; //overutilization is possible, cap at 1 | 1570 | return ratio > 1 ? 1 : ratio; //overutilization is possible, cap at 1 |
1564 | } | 1571 | } |
@@ -1571,18 +1578,18 @@ ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver) | |||
1571 | * @return the network struct | 1578 | * @return the network struct |
1572 | */ | 1579 | */ |
1573 | static struct RIL_Scope * | 1580 | static struct RIL_Scope * |
1574 | ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | 1581 | ril_get_network(struct GAS_RIL_Handle *s, uint32_t type) |
1575 | { | 1582 | { |
1576 | int i; | 1583 | int i; |
1577 | 1584 | ||
1578 | for (i = 0; i < s->networks_count; i++) | 1585 | for (i = 0; i < s->networks_count; i++) |
1579 | { | ||
1580 | if (s->network_entries[i].type == type) | ||
1581 | { | 1586 | { |
1582 | return &s->network_entries[i]; | 1587 | if (s->network_entries[i].type == type) |
1588 | { | ||
1589 | return &s->network_entries[i]; | ||
1590 | } | ||
1583 | } | 1591 | } |
1584 | } | 1592 | return NULL; |
1585 | return NULL ; | ||
1586 | } | 1593 | } |
1587 | 1594 | ||
1588 | /** | 1595 | /** |
@@ -1595,25 +1602,25 @@ ril_get_network (struct GAS_RIL_Handle *s, uint32_t type) | |||
1595 | * @return GNUNET_YES if there are theoretically enough resources left | 1602 | * @return GNUNET_YES if there are theoretically enough resources left |
1596 | */ | 1603 | */ |
1597 | static int | 1604 | static int |
1598 | ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) | 1605 | ril_network_is_not_full(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) |
1599 | { | 1606 | { |
1600 | struct RIL_Scope *net; | 1607 | struct RIL_Scope *net; |
1601 | struct RIL_Peer_Agent *agent; | 1608 | struct RIL_Peer_Agent *agent; |
1602 | unsigned long long address_count = 0; | 1609 | unsigned long long address_count = 0; |
1603 | 1610 | ||
1604 | for (agent = solver->agents_head; NULL != agent; agent = agent->next) | 1611 | for (agent = solver->agents_head; NULL != agent; agent = agent->next) |
1605 | { | ||
1606 | if (agent->address_inuse && agent->is_active) | ||
1607 | { | 1612 | { |
1608 | net = agent->address_inuse->solver_information; | 1613 | if (agent->address_inuse && agent->is_active) |
1609 | if (net->type == network) | 1614 | { |
1610 | { | 1615 | net = agent->address_inuse->solver_information; |
1611 | address_count++; | 1616 | if (net->type == network) |
1612 | } | 1617 | { |
1618 | address_count++; | ||
1619 | } | ||
1620 | } | ||
1613 | } | 1621 | } |
1614 | } | ||
1615 | 1622 | ||
1616 | net = ril_get_network (solver, network); | 1623 | net = ril_get_network(solver, network); |
1617 | return (net->bw_in_available > RIL_MIN_BW * address_count) && (net->bw_out_available > RIL_MIN_BW * address_count); | 1624 | return (net->bw_in_available > RIL_MIN_BW * address_count) && (net->bw_out_available > RIL_MIN_BW * address_count); |
1618 | } | 1625 | } |
1619 | 1626 | ||
@@ -1628,7 +1635,7 @@ ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1628 | * @param silent | 1635 | * @param silent |
1629 | */ | 1636 | */ |
1630 | static void | 1637 | static void |
1631 | ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent) | 1638 | ril_try_unblock_agent(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent) |
1632 | { | 1639 | { |
1633 | struct RIL_Address_Wrapped *addr_wrap; | 1640 | struct RIL_Address_Wrapped *addr_wrap; |
1634 | struct RIL_Scope *net; | 1641 | struct RIL_Scope *net; |
@@ -1636,19 +1643,19 @@ ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *age | |||
1636 | unsigned long long start_out; | 1643 | unsigned long long start_out; |
1637 | 1644 | ||
1638 | for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next) | 1645 | for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next) |
1639 | { | 1646 | { |
1640 | net = addr_wrap->address_naked->solver_information; | 1647 | net = addr_wrap->address_naked->solver_information; |
1641 | if (ril_network_is_not_full(solver, net->type)) | 1648 | if (ril_network_is_not_full(solver, net->type)) |
1642 | { | 1649 | { |
1643 | if (NULL == agent->address_inuse) | 1650 | if (NULL == agent->address_inuse) |
1644 | { | 1651 | { |
1645 | start_in = net->bw_in_available < net->bw_in_utilized ? (net->bw_in_available - net->bw_in_utilized) / 2 : RIL_MIN_BW; | 1652 | start_in = net->bw_in_available < net->bw_in_utilized ? (net->bw_in_available - net->bw_in_utilized) / 2 : RIL_MIN_BW; |
1646 | start_out = net->bw_out_available < net->bw_out_utilized ? (net->bw_out_available - net->bw_out_utilized) / 2 : RIL_MIN_BW; | 1653 | start_out = net->bw_out_available < net->bw_out_utilized ? (net->bw_out_available - net->bw_out_utilized) / 2 : RIL_MIN_BW; |
1647 | envi_set_active_suggestion (solver, agent, addr_wrap->address_naked, start_in, start_out, silent); | 1654 | envi_set_active_suggestion(solver, agent, addr_wrap->address_naked, start_in, start_out, silent); |
1648 | } | 1655 | } |
1649 | return; | 1656 | return; |
1657 | } | ||
1650 | } | 1658 | } |
1651 | } | ||
1652 | agent->address_inuse = NULL; | 1659 | agent->address_inuse = NULL; |
1653 | } | 1660 | } |
1654 | 1661 | ||
@@ -1659,7 +1666,7 @@ ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *age | |||
1659 | * @param solver the solver handle | 1666 | * @param solver the solver handle |
1660 | */ | 1667 | */ |
1661 | static void | 1668 | static void |
1662 | ril_calculate_discount (struct GAS_RIL_Handle *solver) | 1669 | ril_calculate_discount(struct GAS_RIL_Handle *solver) |
1663 | { | 1670 | { |
1664 | struct GNUNET_TIME_Absolute time_now; | 1671 | struct GNUNET_TIME_Absolute time_now; |
1665 | struct GNUNET_TIME_Relative time_delta; | 1672 | struct GNUNET_TIME_Relative time_delta; |
@@ -1667,25 +1674,25 @@ ril_calculate_discount (struct GAS_RIL_Handle *solver) | |||
1667 | 1674 | ||
1668 | // MDP case only for debugging purposes | 1675 | // MDP case only for debugging purposes |
1669 | if (solver->simulate) | 1676 | if (solver->simulate) |
1670 | { | 1677 | { |
1671 | solver->global_discount_variable = solver->parameters.gamma; | 1678 | solver->global_discount_variable = solver->parameters.gamma; |
1672 | solver->global_discount_integrated = 1; | 1679 | solver->global_discount_integrated = 1; |
1673 | return; | 1680 | return; |
1674 | } | 1681 | } |
1675 | 1682 | ||
1676 | // semi-MDP case | 1683 | // semi-MDP case |
1677 | 1684 | ||
1678 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step | 1685 | //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step |
1679 | time_now = GNUNET_TIME_absolute_get (); | 1686 | time_now = GNUNET_TIME_absolute_get(); |
1680 | time_delta = GNUNET_TIME_absolute_get_difference (solver->step_time_last, time_now); | 1687 | time_delta = GNUNET_TIME_absolute_get_difference(solver->step_time_last, time_now); |
1681 | solver->step_time_last = time_now; | 1688 | solver->step_time_last = time_now; |
1682 | tau = (double) time_delta.rel_value_us | 1689 | tau = (double)time_delta.rel_value_us |
1683 | / (double) solver->parameters.step_time_min.rel_value_us; | 1690 | / (double)solver->parameters.step_time_min.rel_value_us; |
1684 | 1691 | ||
1685 | //calculate reward discounts (once per step for all agents) | 1692 | //calculate reward discounts (once per step for all agents) |
1686 | solver->global_discount_variable = pow (M_E, ((-1.0) * ((double) solver->parameters.beta) * tau)); | 1693 | solver->global_discount_variable = pow(M_E, ((-1.0) * ((double)solver->parameters.beta) * tau)); |
1687 | solver->global_discount_integrated = (1.0 - solver->global_discount_variable) | 1694 | solver->global_discount_integrated = (1.0 - solver->global_discount_variable) |
1688 | / (double) solver->parameters.beta; | 1695 | / (double)solver->parameters.beta; |
1689 | } | 1696 | } |
1690 | 1697 | ||
1691 | /** | 1698 | /** |
@@ -1696,18 +1703,18 @@ ril_calculate_discount (struct GAS_RIL_Handle *solver) | |||
1696 | * @return the number of allocated connections | 1703 | * @return the number of allocated connections |
1697 | */ | 1704 | */ |
1698 | static int | 1705 | static int |
1699 | ril_network_count_active_agents (struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) | 1706 | ril_network_count_active_agents(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) |
1700 | { | 1707 | { |
1701 | int c = 0; | 1708 | int c = 0; |
1702 | struct RIL_Peer_Agent *cur_agent; | 1709 | struct RIL_Peer_Agent *cur_agent; |
1703 | 1710 | ||
1704 | for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent = cur_agent->next) | 1711 | for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent = cur_agent->next) |
1705 | { | ||
1706 | if (cur_agent->is_active && cur_agent->address_inuse && (cur_agent->address_inuse->solver_information == scope)) | ||
1707 | { | 1712 | { |
1708 | c++; | 1713 | if (cur_agent->is_active && cur_agent->address_inuse && (cur_agent->address_inuse->solver_information == scope)) |
1714 | { | ||
1715 | c++; | ||
1716 | } | ||
1709 | } | 1717 | } |
1710 | } | ||
1711 | return c; | 1718 | return c; |
1712 | } | 1719 | } |
1713 | 1720 | ||
@@ -1722,26 +1729,26 @@ ril_network_count_active_agents (struct GAS_RIL_Handle *solver, struct RIL_Scope | |||
1722 | * @return the sum of the assigned bandwidths | 1729 | * @return the sum of the assigned bandwidths |
1723 | */ | 1730 | */ |
1724 | static unsigned long long | 1731 | static unsigned long long |
1725 | ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) | 1732 | ril_network_get_assigned(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) |
1726 | { | 1733 | { |
1727 | struct RIL_Peer_Agent *cur; | 1734 | struct RIL_Peer_Agent *cur; |
1728 | struct RIL_Scope *net; | 1735 | struct RIL_Scope *net; |
1729 | unsigned long long sum = 0; | 1736 | unsigned long long sum = 0; |
1730 | 1737 | ||
1731 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1738 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1732 | { | ||
1733 | if (cur->is_active && cur->address_inuse) | ||
1734 | { | 1739 | { |
1735 | net = cur->address_inuse->solver_information; | 1740 | if (cur->is_active && cur->address_inuse) |
1736 | if (net->type == type) | 1741 | { |
1737 | { | 1742 | net = cur->address_inuse->solver_information; |
1738 | if (direction_in) | 1743 | if (net->type == type) |
1739 | sum += cur->bw_in; | 1744 | { |
1740 | else | 1745 | if (direction_in) |
1741 | sum += cur->bw_out; | 1746 | sum += cur->bw_in; |
1742 | } | 1747 | else |
1748 | sum += cur->bw_out; | ||
1749 | } | ||
1750 | } | ||
1743 | } | 1751 | } |
1744 | } | ||
1745 | 1752 | ||
1746 | return sum; | 1753 | return sum; |
1747 | } | 1754 | } |
@@ -1757,26 +1764,26 @@ ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1757 | * @return the sum of the utilized bandwidths (in bytes/second) | 1764 | * @return the sum of the utilized bandwidths (in bytes/second) |
1758 | */ | 1765 | */ |
1759 | static unsigned long long | 1766 | static unsigned long long |
1760 | ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) | 1767 | ril_network_get_utilized(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) |
1761 | { | 1768 | { |
1762 | struct RIL_Peer_Agent *cur; | 1769 | struct RIL_Peer_Agent *cur; |
1763 | struct RIL_Scope *net; | 1770 | struct RIL_Scope *net; |
1764 | unsigned long long sum = 0; | 1771 | unsigned long long sum = 0; |
1765 | 1772 | ||
1766 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1773 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1767 | { | ||
1768 | if (cur->is_active && cur->address_inuse) | ||
1769 | { | 1774 | { |
1770 | net = cur->address_inuse->solver_information; | 1775 | if (cur->is_active && cur->address_inuse) |
1771 | if (net->type == type) | 1776 | { |
1772 | { | 1777 | net = cur->address_inuse->solver_information; |
1773 | if (direction_in) | 1778 | if (net->type == type) |
1774 | sum += cur->address_inuse->norm_utilization_in.norm; | 1779 | { |
1775 | else | 1780 | if (direction_in) |
1776 | sum += cur->address_inuse->norm_utilization_out.norm; | 1781 | sum += cur->address_inuse->norm_utilization_in.norm; |
1777 | } | 1782 | else |
1783 | sum += cur->address_inuse->norm_utilization_out.norm; | ||
1784 | } | ||
1785 | } | ||
1778 | } | 1786 | } |
1779 | } | ||
1780 | 1787 | ||
1781 | return sum; | 1788 | return sum; |
1782 | } | 1789 | } |
@@ -1788,21 +1795,21 @@ ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType | |||
1788 | * @param solver the solver handle | 1795 | * @param solver the solver handle |
1789 | */ | 1796 | */ |
1790 | static void | 1797 | static void |
1791 | ril_networks_update_state (struct GAS_RIL_Handle *solver) | 1798 | ril_networks_update_state(struct GAS_RIL_Handle *solver) |
1792 | { | 1799 | { |
1793 | int c; | 1800 | int c; |
1794 | struct RIL_Scope *net; | 1801 | struct RIL_Scope *net; |
1795 | 1802 | ||
1796 | for (c = 0; c < solver->networks_count; c++) | 1803 | for (c = 0; c < solver->networks_count; c++) |
1797 | { | 1804 | { |
1798 | net = &solver->network_entries[c]; | 1805 | net = &solver->network_entries[c]; |
1799 | net->bw_in_assigned = ril_network_get_assigned(solver, net->type, GNUNET_YES); | 1806 | net->bw_in_assigned = ril_network_get_assigned(solver, net->type, GNUNET_YES); |
1800 | net->bw_in_utilized = ril_network_get_utilized(solver, net->type, GNUNET_YES); | 1807 | net->bw_in_utilized = ril_network_get_utilized(solver, net->type, GNUNET_YES); |
1801 | net->bw_out_assigned = ril_network_get_assigned(solver, net->type, GNUNET_NO); | 1808 | net->bw_out_assigned = ril_network_get_assigned(solver, net->type, GNUNET_NO); |
1802 | net->bw_out_utilized = ril_network_get_utilized(solver, net->type, GNUNET_NO); | 1809 | net->bw_out_utilized = ril_network_get_utilized(solver, net->type, GNUNET_NO); |
1803 | net->active_agent_count = ril_network_count_active_agents(solver, net); | 1810 | net->active_agent_count = ril_network_count_active_agents(solver, net); |
1804 | net->social_welfare = ril_network_get_social_welfare(solver, net); | 1811 | net->social_welfare = ril_network_get_social_welfare(solver, net); |
1805 | } | 1812 | } |
1806 | } | 1813 | } |
1807 | 1814 | ||
1808 | /** | 1815 | /** |
@@ -1813,7 +1820,7 @@ ril_networks_update_state (struct GAS_RIL_Handle *solver) | |||
1813 | * @param solver the solver handle | 1820 | * @param solver the solver handle |
1814 | */ | 1821 | */ |
1815 | static void | 1822 | static void |
1816 | ril_step_schedule_next (struct GAS_RIL_Handle *solver) | 1823 | ril_step_schedule_next(struct GAS_RIL_Handle *solver) |
1817 | { | 1824 | { |
1818 | double used_ratio; | 1825 | double used_ratio; |
1819 | double factor; | 1826 | double factor; |
@@ -1821,21 +1828,21 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1821 | double offset; | 1828 | double offset; |
1822 | struct GNUNET_TIME_Relative time_next; | 1829 | struct GNUNET_TIME_Relative time_next; |
1823 | 1830 | ||
1824 | used_ratio = ril_get_used_resource_ratio (solver); | 1831 | used_ratio = ril_get_used_resource_ratio(solver); |
1825 | 1832 | ||
1826 | GNUNET_assert( | 1833 | GNUNET_assert( |
1827 | solver->parameters.step_time_min.rel_value_us | 1834 | solver->parameters.step_time_min.rel_value_us |
1828 | <= solver->parameters.step_time_max.rel_value_us); | 1835 | <= solver->parameters.step_time_max.rel_value_us); |
1829 | 1836 | ||
1830 | factor = (double) GNUNET_TIME_relative_subtract (solver->parameters.step_time_max, | 1837 | factor = (double)GNUNET_TIME_relative_subtract(solver->parameters.step_time_max, |
1831 | solver->parameters.step_time_min).rel_value_us; | 1838 | solver->parameters.step_time_min).rel_value_us; |
1832 | offset = (double) solver->parameters.step_time_min.rel_value_us; | 1839 | offset = (double)solver->parameters.step_time_min.rel_value_us; |
1833 | y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset; | 1840 | y = factor * pow(used_ratio, RIL_INTERVAL_EXPONENT) + offset; |
1834 | 1841 | ||
1835 | GNUNET_assert(y <= (double) solver->parameters.step_time_max.rel_value_us); | 1842 | GNUNET_assert(y <= (double)solver->parameters.step_time_max.rel_value_us); |
1836 | GNUNET_assert(y >= (double) solver->parameters.step_time_min.rel_value_us); | 1843 | GNUNET_assert(y >= (double)solver->parameters.step_time_min.rel_value_us); |
1837 | 1844 | ||
1838 | time_next = GNUNET_TIME_relative_saturating_multiply (GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y); | 1845 | time_next = GNUNET_TIME_relative_saturating_multiply(GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long)y); |
1839 | 1846 | ||
1840 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", | 1847 | // LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", |
1841 | // used_ratio, | 1848 | // used_ratio, |
@@ -1844,15 +1851,15 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1844 | // y); | 1851 | // y); |
1845 | 1852 | ||
1846 | if (solver->simulate) | 1853 | if (solver->simulate) |
1847 | { | 1854 | { |
1848 | time_next = GNUNET_TIME_UNIT_ZERO; | 1855 | time_next = GNUNET_TIME_UNIT_ZERO; |
1849 | } | 1856 | } |
1850 | 1857 | ||
1851 | if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done)) | 1858 | if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done)) |
1852 | { | 1859 | { |
1853 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next, &ril_step_scheduler_task, | 1860 | solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed(time_next, &ril_step_scheduler_task, |
1854 | solver); | 1861 | solver); |
1855 | } | 1862 | } |
1856 | } | 1863 | } |
1857 | 1864 | ||
1858 | /** | 1865 | /** |
@@ -1861,61 +1868,62 @@ ril_step_schedule_next (struct GAS_RIL_Handle *solver) | |||
1861 | * @param solver | 1868 | * @param solver |
1862 | */ | 1869 | */ |
1863 | static void | 1870 | static void |
1864 | ril_step (struct GAS_RIL_Handle *solver) | 1871 | ril_step(struct GAS_RIL_Handle *solver) |
1865 | { | 1872 | { |
1866 | struct RIL_Peer_Agent *cur; | 1873 | struct RIL_Peer_Agent *cur; |
1867 | 1874 | ||
1868 | if (GNUNET_YES == solver->bulk_lock) | 1875 | if (GNUNET_YES == solver->bulk_lock) |
1869 | { | 1876 | { |
1870 | solver->bulk_changes++; | 1877 | solver->bulk_changes++; |
1871 | return; | 1878 | return; |
1872 | } | 1879 | } |
1873 | 1880 | ||
1874 | ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); | 1881 | ril_inform(solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); |
1875 | 1882 | ||
1876 | LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count); | 1883 | LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count); |
1877 | 1884 | ||
1878 | if (0 == solver->step_count) | 1885 | if (0 == solver->step_count) |
1879 | { | 1886 | { |
1880 | solver->step_time_last = GNUNET_TIME_absolute_get (); | 1887 | solver->step_time_last = GNUNET_TIME_absolute_get(); |
1881 | } | 1888 | } |
1882 | 1889 | ||
1883 | ril_calculate_discount (solver); | 1890 | ril_calculate_discount(solver); |
1884 | ril_networks_update_state (solver); | 1891 | ril_networks_update_state(solver); |
1885 | 1892 | ||
1886 | //trigger one step per active, unblocked agent | 1893 | //trigger one step per active, unblocked agent |
1887 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1894 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1888 | { | ||
1889 | if (cur->is_active) | ||
1890 | { | 1895 | { |
1891 | if (NULL == cur->address_inuse) | 1896 | if (cur->is_active) |
1892 | { | 1897 | { |
1893 | ril_try_unblock_agent(solver, cur, GNUNET_NO); | 1898 | if (NULL == cur->address_inuse) |
1894 | } | 1899 | { |
1895 | if (cur->address_inuse) | 1900 | ril_try_unblock_agent(solver, cur, GNUNET_NO); |
1896 | { | 1901 | } |
1897 | agent_step (cur); | 1902 | if (cur->address_inuse) |
1898 | } | 1903 | { |
1904 | agent_step(cur); | ||
1905 | } | ||
1906 | } | ||
1899 | } | 1907 | } |
1900 | } | ||
1901 | 1908 | ||
1902 | ril_networks_update_state (solver); | 1909 | ril_networks_update_state(solver); |
1903 | 1910 | ||
1904 | solver->step_count++; | 1911 | solver->step_count++; |
1905 | ril_step_schedule_next (solver); | 1912 | ril_step_schedule_next(solver); |
1906 | 1913 | ||
1907 | ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); | 1914 | ril_inform(solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); |
1908 | 1915 | ||
1909 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS); | 1916 | ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS); |
1910 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 1917 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
1911 | { | 1918 | { |
1912 | if (cur->suggestion_issue) { | 1919 | if (cur->suggestion_issue) |
1913 | solver->env->bandwidth_changed_cb (solver->env->cls, | 1920 | { |
1914 | cur->suggestion_address); | 1921 | solver->env->bandwidth_changed_cb(solver->env->cls, |
1915 | cur->suggestion_issue = GNUNET_NO; | 1922 | cur->suggestion_address); |
1916 | } | 1923 | cur->suggestion_issue = GNUNET_NO; |
1917 | } | 1924 | } |
1918 | ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); | 1925 | } |
1926 | ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); | ||
1919 | } | 1927 | } |
1920 | 1928 | ||
1921 | /** | 1929 | /** |
@@ -1924,18 +1932,18 @@ ril_step (struct GAS_RIL_Handle *solver) | |||
1924 | * @param agent The respective agent | 1932 | * @param agent The respective agent |
1925 | */ | 1933 | */ |
1926 | static void | 1934 | static void |
1927 | agent_w_init (struct RIL_Peer_Agent *agent) | 1935 | agent_w_init(struct RIL_Peer_Agent *agent) |
1928 | { | 1936 | { |
1929 | int i; | 1937 | int i; |
1930 | int k; | 1938 | int k; |
1931 | 1939 | ||
1932 | for (i = 0; i < agent->n; i++) | 1940 | for (i = 0; i < agent->n; i++) |
1933 | { | ||
1934 | for (k = 0; k < agent->m; k++) | ||
1935 | { | 1941 | { |
1936 | agent->W[i][k] = agent->envi->parameters.alpha * (1.0 - 2.0 * ((double) GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)/(double) UINT32_MAX)); | 1942 | for (k = 0; k < agent->m; k++) |
1943 | { | ||
1944 | agent->W[i][k] = agent->envi->parameters.alpha * (1.0 - 2.0 * ((double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) / (double)UINT32_MAX)); | ||
1945 | } | ||
1937 | } | 1946 | } |
1938 | } | ||
1939 | } | 1947 | } |
1940 | 1948 | ||
1941 | /** | 1949 | /** |
@@ -1946,11 +1954,11 @@ agent_w_init (struct RIL_Peer_Agent *agent) | |||
1946 | * @return handle to the new agent | 1954 | * @return handle to the new agent |
1947 | */ | 1955 | */ |
1948 | static struct RIL_Peer_Agent * | 1956 | static struct RIL_Peer_Agent * |
1949 | agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | 1957 | agent_init(void *s, const struct GNUNET_PeerIdentity *peer) |
1950 | { | 1958 | { |
1951 | int i; | 1959 | int i; |
1952 | struct GAS_RIL_Handle * solver = s; | 1960 | struct GAS_RIL_Handle * solver = s; |
1953 | struct RIL_Peer_Agent * agent = GNUNET_new (struct RIL_Peer_Agent); | 1961 | struct RIL_Peer_Agent * agent = GNUNET_new(struct RIL_Peer_Agent); |
1954 | 1962 | ||
1955 | agent->envi = solver; | 1963 | agent->envi = solver; |
1956 | agent->peer = *peer; | 1964 | agent->peer = *peer; |
@@ -1961,17 +1969,17 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1961 | agent->suggestion_issue = GNUNET_NO; | 1969 | agent->suggestion_issue = GNUNET_NO; |
1962 | agent->n = RIL_ACTION_TYPE_NUM; | 1970 | agent->n = RIL_ACTION_TYPE_NUM; |
1963 | agent->m = 0; | 1971 | agent->m = 0; |
1964 | agent->W = (double **) GNUNET_malloc (sizeof (double *) * agent->n); | 1972 | agent->W = (double **)GNUNET_malloc(sizeof(double *) * agent->n); |
1965 | agent->E = (double **) GNUNET_malloc (sizeof (double *) * agent->n); | 1973 | agent->E = (double **)GNUNET_malloc(sizeof(double *) * agent->n); |
1966 | for (i = 0; i < agent->n; i++) | 1974 | for (i = 0; i < agent->n; i++) |
1967 | { | 1975 | { |
1968 | agent->W[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m); | 1976 | agent->W[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); |
1969 | agent->E[i] = (double *) GNUNET_malloc (sizeof (double) * agent->m); | 1977 | agent->E[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); |
1970 | } | 1978 | } |
1971 | agent_w_init(agent); | 1979 | agent_w_init(agent); |
1972 | agent->eligibility_reset = GNUNET_NO; | 1980 | agent->eligibility_reset = GNUNET_NO; |
1973 | agent->a_old = RIL_ACTION_INVALID; | 1981 | agent->a_old = RIL_ACTION_INVALID; |
1974 | agent->s_old = GNUNET_malloc (sizeof (double) * agent->m); | 1982 | agent->s_old = GNUNET_malloc(sizeof(double) * agent->m); |
1975 | agent->address_inuse = NULL; | 1983 | agent->address_inuse = NULL; |
1976 | agent->objective_old = 0; | 1984 | agent->objective_old = 0; |
1977 | agent->nop_bonus = 0; | 1985 | agent->nop_bonus = 0; |
@@ -1986,15 +1994,15 @@ agent_init (void *s, const struct GNUNET_PeerIdentity *peer) | |||
1986 | * @param agent the agent to retire | 1994 | * @param agent the agent to retire |
1987 | */ | 1995 | */ |
1988 | static void | 1996 | static void |
1989 | agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | 1997 | agent_die(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) |
1990 | { | 1998 | { |
1991 | int i; | 1999 | int i; |
1992 | 2000 | ||
1993 | for (i = 0; i < agent->n; i++) | 2001 | for (i = 0; i < agent->n; i++) |
1994 | { | 2002 | { |
1995 | GNUNET_free_non_null(agent->W[i]); | 2003 | GNUNET_free_non_null(agent->W[i]); |
1996 | GNUNET_free_non_null(agent->E[i]); | 2004 | GNUNET_free_non_null(agent->E[i]); |
1997 | } | 2005 | } |
1998 | GNUNET_free_non_null(agent->W); | 2006 | GNUNET_free_non_null(agent->W); |
1999 | GNUNET_free_non_null(agent->E); | 2007 | GNUNET_free_non_null(agent->E); |
2000 | GNUNET_free_non_null(agent->s_old); | 2008 | GNUNET_free_non_null(agent->s_old); |
@@ -2010,25 +2018,25 @@ agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) | |||
2010 | * @return the agent | 2018 | * @return the agent |
2011 | */ | 2019 | */ |
2012 | static struct RIL_Peer_Agent * | 2020 | static struct RIL_Peer_Agent * |
2013 | ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create) | 2021 | ril_get_agent(struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create) |
2014 | { | 2022 | { |
2015 | struct RIL_Peer_Agent *cur; | 2023 | struct RIL_Peer_Agent *cur; |
2016 | 2024 | ||
2017 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) | 2025 | for (cur = solver->agents_head; NULL != cur; cur = cur->next) |
2018 | { | ||
2019 | if (0 == GNUNET_memcmp (peer, &cur->peer)) | ||
2020 | { | 2026 | { |
2021 | return cur; | 2027 | if (0 == GNUNET_memcmp(peer, &cur->peer)) |
2028 | { | ||
2029 | return cur; | ||
2030 | } | ||
2022 | } | 2031 | } |
2023 | } | ||
2024 | 2032 | ||
2025 | if (create) | 2033 | if (create) |
2026 | { | 2034 | { |
2027 | cur = agent_init (solver, peer); | 2035 | cur = agent_init(solver, peer); |
2028 | GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur); | 2036 | GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur); |
2029 | return cur; | 2037 | return cur; |
2030 | } | 2038 | } |
2031 | return NULL ; | 2039 | return NULL; |
2032 | } | 2040 | } |
2033 | 2041 | ||
2034 | /** | 2042 | /** |
@@ -2040,11 +2048,11 @@ ril_get_agent (struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity * | |||
2040 | * @return whether or not the network is considered active | 2048 | * @return whether or not the network is considered active |
2041 | */ | 2049 | */ |
2042 | static int | 2050 | static int |
2043 | ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) | 2051 | ril_network_is_active(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) |
2044 | { | 2052 | { |
2045 | struct RIL_Scope *net; | 2053 | struct RIL_Scope *net; |
2046 | 2054 | ||
2047 | net = ril_get_network (solver, network); | 2055 | net = ril_get_network(solver, network); |
2048 | return net->bw_out_available >= RIL_MIN_BW; | 2056 | return net->bw_out_available >= RIL_MIN_BW; |
2049 | } | 2057 | } |
2050 | 2058 | ||
@@ -2060,14 +2068,14 @@ ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType ne | |||
2060 | * @param old_length the length of the old vector | 2068 | * @param old_length the length of the old vector |
2061 | */ | 2069 | */ |
2062 | static void | 2070 | static void |
2063 | ril_cut_from_vector (void **old, | 2071 | ril_cut_from_vector(void **old, |
2064 | size_t element_size, | 2072 | size_t element_size, |
2065 | unsigned int hole_start, | 2073 | unsigned int hole_start, |
2066 | unsigned int hole_length, | 2074 | unsigned int hole_length, |
2067 | unsigned int old_length) | 2075 | unsigned int old_length) |
2068 | { | 2076 | { |
2069 | char *tmpptr; | 2077 | char *tmpptr; |
2070 | char *oldptr = (char *) *old; | 2078 | char *oldptr = (char *)*old; |
2071 | size_t size; | 2079 | size_t size; |
2072 | unsigned int bytes_before; | 2080 | unsigned int bytes_before; |
2073 | unsigned int bytes_hole; | 2081 | unsigned int bytes_hole; |
@@ -2083,20 +2091,20 @@ ril_cut_from_vector (void **old, | |||
2083 | bytes_after = element_size * (old_length - hole_start - hole_length); | 2091 | bytes_after = element_size * (old_length - hole_start - hole_length); |
2084 | 2092 | ||
2085 | if (0 == size) | 2093 | if (0 == size) |
2086 | { | 2094 | { |
2087 | tmpptr = NULL; | 2095 | tmpptr = NULL; |
2088 | } | 2096 | } |
2089 | else | 2097 | else |
2090 | { | 2098 | { |
2091 | tmpptr = GNUNET_malloc (size); | 2099 | tmpptr = GNUNET_malloc(size); |
2092 | GNUNET_memcpy (tmpptr, oldptr, bytes_before); | 2100 | GNUNET_memcpy(tmpptr, oldptr, bytes_before); |
2093 | GNUNET_memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); | 2101 | GNUNET_memcpy(tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); |
2094 | } | 2102 | } |
2095 | if (NULL != *old) | 2103 | if (NULL != *old) |
2096 | { | 2104 | { |
2097 | GNUNET_free(*old); | 2105 | GNUNET_free(*old); |
2098 | } | 2106 | } |
2099 | *old = (void *) tmpptr; | 2107 | *old = (void *)tmpptr; |
2100 | } | 2108 | } |
2101 | 2109 | ||
2102 | /* | 2110 | /* |
@@ -2113,20 +2121,20 @@ ril_cut_from_vector (void **old, | |||
2113 | * @param pref_rel the normalized preference value for this kind over all clients | 2121 | * @param pref_rel the normalized preference value for this kind over all clients |
2114 | */ | 2122 | */ |
2115 | static void | 2123 | static void |
2116 | GAS_ril_address_change_preference (void *solver, | 2124 | GAS_ril_address_change_preference(void *solver, |
2117 | const struct GNUNET_PeerIdentity *peer, | 2125 | const struct GNUNET_PeerIdentity *peer, |
2118 | enum GNUNET_ATS_PreferenceKind kind, | 2126 | enum GNUNET_ATS_PreferenceKind kind, |
2119 | double pref_rel) | 2127 | double pref_rel) |
2120 | { | 2128 | { |
2121 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2129 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2122 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", | 2130 | "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", |
2123 | GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel); | 2131 | GNUNET_ATS_print_preference_type(kind), GNUNET_i2s(peer), pref_rel); |
2124 | 2132 | ||
2125 | struct GAS_RIL_Handle *s = solver; | 2133 | struct GAS_RIL_Handle *s = solver; |
2126 | 2134 | ||
2127 | s->parameters.temperature = s->parameters.temperature_init; | 2135 | s->parameters.temperature = s->parameters.temperature_init; |
2128 | s->parameters.epsilon = s->parameters.epsilon_init; | 2136 | s->parameters.epsilon = s->parameters.epsilon_init; |
2129 | ril_step (s); | 2137 | ril_step(s); |
2130 | } | 2138 | } |
2131 | 2139 | ||
2132 | 2140 | ||
@@ -2140,9 +2148,9 @@ GAS_ril_address_change_preference (void *solver, | |||
2140 | * @param network network type of this address | 2148 | * @param network network type of this address |
2141 | */ | 2149 | */ |
2142 | static void | 2150 | static void |
2143 | GAS_ril_address_add (void *solver, | 2151 | GAS_ril_address_add(void *solver, |
2144 | struct ATS_Address *address, | 2152 | struct ATS_Address *address, |
2145 | uint32_t network) | 2153 | uint32_t network) |
2146 | { | 2154 | { |
2147 | struct GAS_RIL_Handle *s = solver; | 2155 | struct GAS_RIL_Handle *s = solver; |
2148 | struct RIL_Peer_Agent *agent; | 2156 | struct RIL_Peer_Agent *agent; |
@@ -2155,32 +2163,32 @@ GAS_ril_address_add (void *solver, | |||
2155 | int i; | 2163 | int i; |
2156 | unsigned int zero; | 2164 | unsigned int zero; |
2157 | 2165 | ||
2158 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2166 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2159 | "API_address_add()\n"); | 2167 | "API_address_add()\n"); |
2160 | 2168 | ||
2161 | net = ril_get_network (s, network); | 2169 | net = ril_get_network(s, network); |
2162 | address->solver_information = net; | 2170 | address->solver_information = net; |
2163 | 2171 | ||
2164 | if (!ril_network_is_active (s, network)) | 2172 | if (!ril_network_is_active(s, network)) |
2165 | { | 2173 | { |
2166 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2174 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2167 | "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n", | 2175 | "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n", |
2168 | address->plugin, address->addr, GNUNET_i2s (&address->peer)); | 2176 | address->plugin, address->addr, GNUNET_i2s(&address->peer)); |
2169 | return; | 2177 | return; |
2170 | } | 2178 | } |
2171 | 2179 | ||
2172 | s->parameters.temperature = s->parameters.temperature_init; | 2180 | s->parameters.temperature = s->parameters.temperature_init; |
2173 | s->parameters.epsilon = s->parameters.epsilon_init; | 2181 | s->parameters.epsilon = s->parameters.epsilon_init; |
2174 | 2182 | ||
2175 | agent = ril_get_agent (s, &address->peer, GNUNET_YES); | 2183 | agent = ril_get_agent(s, &address->peer, GNUNET_YES); |
2176 | 2184 | ||
2177 | //add address | 2185 | //add address |
2178 | address_wrapped = GNUNET_new (struct RIL_Address_Wrapped); | 2186 | address_wrapped = GNUNET_new(struct RIL_Address_Wrapped); |
2179 | address_wrapped->address_naked = address; | 2187 | address_wrapped->address_naked = address; |
2180 | GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); | 2188 | GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); |
2181 | 2189 | ||
2182 | //increase size of W | 2190 | //increase size of W |
2183 | m_new = agent->m + ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); | 2191 | m_new = agent->m + ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); |
2184 | m_old = agent->m; | 2192 | m_old = agent->m; |
2185 | n_new = agent->n + 1; | 2193 | n_new = agent->n + 1; |
2186 | n_old = agent->n; | 2194 | n_old = agent->n; |
@@ -2189,22 +2197,22 @@ GAS_ril_address_add (void *solver, | |||
2189 | agent->n = n_old; | 2197 | agent->n = n_old; |
2190 | GNUNET_array_grow(agent->E, agent->n, n_new); | 2198 | GNUNET_array_grow(agent->E, agent->n, n_new); |
2191 | for (i = 0; i < n_new; i++) | 2199 | for (i = 0; i < n_new; i++) |
2192 | { | ||
2193 | if (i < n_old) | ||
2194 | { | ||
2195 | agent->m = m_old; | ||
2196 | GNUNET_array_grow(agent->W[i], agent->m, m_new); | ||
2197 | agent->m = m_old; | ||
2198 | GNUNET_array_grow(agent->E[i], agent->m, m_new); | ||
2199 | } | ||
2200 | else | ||
2201 | { | 2200 | { |
2202 | zero = 0; | 2201 | if (i < n_old) |
2203 | GNUNET_array_grow(agent->W[i], zero, m_new); | 2202 | { |
2204 | zero = 0; | 2203 | agent->m = m_old; |
2205 | GNUNET_array_grow(agent->E[i], zero, m_new); | 2204 | GNUNET_array_grow(agent->W[i], agent->m, m_new); |
2205 | agent->m = m_old; | ||
2206 | GNUNET_array_grow(agent->E[i], agent->m, m_new); | ||
2207 | } | ||
2208 | else | ||
2209 | { | ||
2210 | zero = 0; | ||
2211 | GNUNET_array_grow(agent->W[i], zero, m_new); | ||
2212 | zero = 0; | ||
2213 | GNUNET_array_grow(agent->E[i], zero, m_new); | ||
2214 | } | ||
2206 | } | 2215 | } |
2207 | } | ||
2208 | 2216 | ||
2209 | //increase size of old state vector | 2217 | //increase size of old state vector |
2210 | agent->m = m_old; | 2218 | agent->m = m_old; |
@@ -2212,11 +2220,11 @@ GAS_ril_address_add (void *solver, | |||
2212 | 2220 | ||
2213 | ril_try_unblock_agent(s, agent, GNUNET_NO); | 2221 | ril_try_unblock_agent(s, agent, GNUNET_NO); |
2214 | 2222 | ||
2215 | ril_step (s); | 2223 | ril_step(s); |
2216 | 2224 | ||
2217 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n", | 2225 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n", |
2218 | address->active ? "active" : "inactive", address->plugin, address->addr, | 2226 | address->active ? "active" : "inactive", address->plugin, address->addr, |
2219 | GNUNET_i2s (&address->peer)); | 2227 | GNUNET_i2s(&address->peer)); |
2220 | } | 2228 | } |
2221 | 2229 | ||
2222 | /** | 2230 | /** |
@@ -2228,8 +2236,8 @@ GAS_ril_address_add (void *solver, | |||
2228 | * @param address the address to remove | 2236 | * @param address the address to remove |
2229 | */ | 2237 | */ |
2230 | static void | 2238 | static void |
2231 | GAS_ril_address_delete (void *solver, | 2239 | GAS_ril_address_delete(void *solver, |
2232 | struct ATS_Address *address) | 2240 | struct ATS_Address *address) |
2233 | { | 2241 | { |
2234 | struct GAS_RIL_Handle *s = solver; | 2242 | struct GAS_RIL_Handle *s = solver; |
2235 | struct RIL_Peer_Agent *agent; | 2243 | struct RIL_Peer_Agent *agent; |
@@ -2240,103 +2248,103 @@ GAS_ril_address_delete (void *solver, | |||
2240 | int i; | 2248 | int i; |
2241 | struct RIL_Scope *net; | 2249 | struct RIL_Scope *net; |
2242 | 2250 | ||
2243 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2251 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2244 | "API_address_delete() Delete %s %s address %s for peer '%s'\n", | 2252 | "API_address_delete() Delete %s %s address %s for peer '%s'\n", |
2245 | address->active ? "active" : "inactive", | 2253 | address->active ? "active" : "inactive", |
2246 | address->plugin, | 2254 | address->plugin, |
2247 | address->addr, | 2255 | address->addr, |
2248 | GNUNET_i2s (&address->peer)); | 2256 | GNUNET_i2s(&address->peer)); |
2249 | 2257 | ||
2250 | agent = ril_get_agent (s, &address->peer, GNUNET_NO); | 2258 | agent = ril_get_agent(s, &address->peer, GNUNET_NO); |
2251 | if (NULL == agent) | 2259 | if (NULL == agent) |
2252 | { | 2260 | { |
2253 | net = address->solver_information; | 2261 | net = address->solver_information; |
2254 | GNUNET_assert(! ril_network_is_active (s, net->type)); | 2262 | GNUNET_assert(!ril_network_is_active(s, net->type)); |
2255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2263 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2256 | "No agent allocated for peer yet, since address was in inactive network\n"); | 2264 | "No agent allocated for peer yet, since address was in inactive network\n"); |
2257 | return; | 2265 | return; |
2258 | } | 2266 | } |
2259 | 2267 | ||
2260 | s->parameters.temperature = s->parameters.temperature_init; | 2268 | s->parameters.temperature = s->parameters.temperature_init; |
2261 | s->parameters.epsilon = s->parameters.epsilon_init; | 2269 | s->parameters.epsilon = s->parameters.epsilon_init; |
2262 | 2270 | ||
2263 | address_index = agent_address_get_index (agent, address); | 2271 | address_index = agent_address_get_index(agent, address); |
2264 | address_wrapped = agent_address_get_wrapped (agent, address); | 2272 | address_wrapped = agent_address_get_wrapped(agent, address); |
2265 | 2273 | ||
2266 | if (NULL == address_wrapped) | 2274 | if (NULL == address_wrapped) |
2267 | { | 2275 | { |
2268 | net = address->solver_information; | 2276 | net = address->solver_information; |
2269 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2277 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2270 | "Address not considered by agent, address was in inactive network\n"); | 2278 | "Address not considered by agent, address was in inactive network\n"); |
2271 | return; | 2279 | return; |
2272 | } | 2280 | } |
2273 | GNUNET_CONTAINER_DLL_remove (agent->addresses_head, | 2281 | GNUNET_CONTAINER_DLL_remove(agent->addresses_head, |
2274 | agent->addresses_tail, | 2282 | agent->addresses_tail, |
2275 | address_wrapped); | 2283 | address_wrapped); |
2276 | GNUNET_free (address_wrapped); | 2284 | GNUNET_free(address_wrapped); |
2277 | 2285 | ||
2278 | //decrease W | 2286 | //decrease W |
2279 | m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); | 2287 | m_new = agent->m - ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); |
2280 | n_new = agent->n - 1; | 2288 | n_new = agent->n - 1; |
2281 | 2289 | ||
2282 | for (i = 0; i < agent->n; i++) | 2290 | for (i = 0; i < agent->n; i++) |
2283 | { | 2291 | { |
2284 | ril_cut_from_vector ((void **) &agent->W[i], sizeof(double), | 2292 | ril_cut_from_vector((void **)&agent->W[i], sizeof(double), |
2285 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2293 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2286 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2294 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2287 | ril_cut_from_vector ((void **) &agent->E[i], sizeof(double), | 2295 | ril_cut_from_vector((void **)&agent->E[i], sizeof(double), |
2288 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2296 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2289 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2297 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2290 | } | 2298 | } |
2291 | GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]); | 2299 | GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]); |
2292 | GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]); | 2300 | GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]); |
2293 | ril_cut_from_vector ((void **) &agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, | 2301 | ril_cut_from_vector((void **)&agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, |
2294 | 1, agent->n); | 2302 | 1, agent->n); |
2295 | ril_cut_from_vector ((void **) &agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, | 2303 | ril_cut_from_vector((void **)&agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, |
2296 | 1, agent->n); | 2304 | 1, agent->n); |
2297 | //correct last action | 2305 | //correct last action |
2298 | if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index)) | 2306 | if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index)) |
2299 | { | 2307 | { |
2300 | agent->a_old -= 1; | 2308 | agent->a_old -= 1; |
2301 | } | 2309 | } |
2302 | else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index)) | 2310 | else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index)) |
2303 | { | 2311 | { |
2304 | agent->a_old = RIL_ACTION_INVALID; | 2312 | agent->a_old = RIL_ACTION_INVALID; |
2305 | } | 2313 | } |
2306 | //decrease old state vector | 2314 | //decrease old state vector |
2307 | ril_cut_from_vector ((void **) &agent->s_old, sizeof(double), | 2315 | ril_cut_from_vector((void **)&agent->s_old, sizeof(double), |
2308 | address_index * ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), | 2316 | address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), |
2309 | ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)), agent->m); | 2317 | ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); |
2310 | agent->m = m_new; | 2318 | agent->m = m_new; |
2311 | agent->n = n_new; | 2319 | agent->n = n_new; |
2312 | 2320 | ||
2313 | if (agent->address_inuse == address) | 2321 | if (agent->address_inuse == address) |
2314 | { | 2322 | { |
2315 | if (NULL != agent->addresses_head) //if peer has an address left, use it | 2323 | if (NULL != agent->addresses_head) //if peer has an address left, use it |
2316 | { | 2324 | { |
2317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2325 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2318 | "Active address died, suggesting alternative!\n"); | 2326 | "Active address died, suggesting alternative!\n"); |
2319 | envi_set_active_suggestion (s, | 2327 | envi_set_active_suggestion(s, |
2320 | agent, | 2328 | agent, |
2321 | agent->addresses_head->address_naked, | 2329 | agent->addresses_head->address_naked, |
2322 | agent->bw_in, | 2330 | agent->bw_in, |
2323 | agent->bw_out, | 2331 | agent->bw_out, |
2324 | GNUNET_YES); | 2332 | GNUNET_YES); |
2325 | } | 2333 | } |
2326 | else | 2334 | else |
2327 | { | 2335 | { |
2328 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2336 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
2329 | "Active address died, suggesting disconnect!\n"); | 2337 | "Active address died, suggesting disconnect!\n"); |
2330 | envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO); | 2338 | envi_set_active_suggestion(s, agent, NULL, 0, 0, GNUNET_NO); |
2331 | } | 2339 | } |
2332 | } | 2340 | } |
2333 | ril_step (solver); | 2341 | ril_step(solver); |
2334 | if (agent->suggestion_address == address) | 2342 | if (agent->suggestion_address == address) |
2335 | { | 2343 | { |
2336 | agent->suggestion_issue = GNUNET_NO; | 2344 | agent->suggestion_issue = GNUNET_NO; |
2337 | agent->suggestion_address = NULL; | 2345 | agent->suggestion_address = NULL; |
2338 | } | 2346 | } |
2339 | GNUNET_assert (agent->address_inuse != address); | 2347 | GNUNET_assert(agent->address_inuse != address); |
2340 | } | 2348 | } |
2341 | 2349 | ||
2342 | 2350 | ||
@@ -2347,17 +2355,17 @@ GAS_ril_address_delete (void *solver, | |||
2347 | * @param address the address | 2355 | * @param address the address |
2348 | */ | 2356 | */ |
2349 | static void | 2357 | static void |
2350 | GAS_ril_address_property_changed (void *solver, | 2358 | GAS_ril_address_property_changed(void *solver, |
2351 | struct ATS_Address *address) | 2359 | struct ATS_Address *address) |
2352 | { | 2360 | { |
2353 | struct GAS_RIL_Handle *s = solver; | 2361 | struct GAS_RIL_Handle *s = solver; |
2354 | 2362 | ||
2355 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2363 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2356 | "Properties for peer '%s' address changed\n", | 2364 | "Properties for peer '%s' address changed\n", |
2357 | GNUNET_i2s (&address->peer)); | 2365 | GNUNET_i2s(&address->peer)); |
2358 | s->parameters.temperature = s->parameters.temperature_init; | 2366 | s->parameters.temperature = s->parameters.temperature_init; |
2359 | s->parameters.epsilon = s->parameters.epsilon_init; | 2367 | s->parameters.epsilon = s->parameters.epsilon_init; |
2360 | ril_step (s); | 2368 | ril_step(s); |
2361 | } | 2369 | } |
2362 | 2370 | ||
2363 | 2371 | ||
@@ -2372,20 +2380,20 @@ GAS_ril_address_property_changed (void *solver, | |||
2372 | * @param score the score | 2380 | * @param score the score |
2373 | */ | 2381 | */ |
2374 | static void | 2382 | static void |
2375 | GAS_ril_address_preference_feedback (void *solver, | 2383 | GAS_ril_address_preference_feedback(void *solver, |
2376 | struct GNUNET_SERVICE_Client *application, | 2384 | struct GNUNET_SERVICE_Client *application, |
2377 | const struct GNUNET_PeerIdentity *peer, | 2385 | const struct GNUNET_PeerIdentity *peer, |
2378 | const struct GNUNET_TIME_Relative scope, | 2386 | const struct GNUNET_TIME_Relative scope, |
2379 | enum GNUNET_ATS_PreferenceKind kind, | 2387 | enum GNUNET_ATS_PreferenceKind kind, |
2380 | double score) | 2388 | double score) |
2381 | { | 2389 | { |
2382 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2390 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2383 | "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " | 2391 | "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " |
2384 | "preference %s for %d seconds\n", | 2392 | "preference %s for %d seconds\n", |
2385 | GNUNET_i2s (peer), | 2393 | GNUNET_i2s(peer), |
2386 | "UNKNOWN", | 2394 | "UNKNOWN", |
2387 | GNUNET_ATS_print_preference_type (kind), | 2395 | GNUNET_ATS_print_preference_type(kind), |
2388 | scope.rel_value_us / 1000000); | 2396 | scope.rel_value_us / 1000000); |
2389 | } | 2397 | } |
2390 | 2398 | ||
2391 | 2399 | ||
@@ -2395,12 +2403,12 @@ GAS_ril_address_preference_feedback (void *solver, | |||
2395 | * @param solver the solver | 2403 | * @param solver the solver |
2396 | */ | 2404 | */ |
2397 | static void | 2405 | static void |
2398 | GAS_ril_bulk_start (void *solver) | 2406 | GAS_ril_bulk_start(void *solver) |
2399 | { | 2407 | { |
2400 | struct GAS_RIL_Handle *s = solver; | 2408 | struct GAS_RIL_Handle *s = solver; |
2401 | 2409 | ||
2402 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2410 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2403 | "API_bulk_start() lock: %d\n", s->bulk_lock+1); | 2411 | "API_bulk_start() lock: %d\n", s->bulk_lock + 1); |
2404 | 2412 | ||
2405 | s->bulk_lock++; | 2413 | s->bulk_lock++; |
2406 | } | 2414 | } |
@@ -2412,7 +2420,7 @@ GAS_ril_bulk_start (void *solver) | |||
2412 | * @param solver the solver handle | 2420 | * @param solver the solver handle |
2413 | */ | 2421 | */ |
2414 | static void | 2422 | static void |
2415 | GAS_ril_bulk_stop (void *solver) | 2423 | GAS_ril_bulk_stop(void *solver) |
2416 | { | 2424 | { |
2417 | struct GAS_RIL_Handle *s = solver; | 2425 | struct GAS_RIL_Handle *s = solver; |
2418 | 2426 | ||
@@ -2421,17 +2429,17 @@ GAS_ril_bulk_stop (void *solver) | |||
2421 | s->bulk_lock - 1); | 2429 | s->bulk_lock - 1); |
2422 | 2430 | ||
2423 | if (s->bulk_lock < 1) | 2431 | if (s->bulk_lock < 1) |
2424 | { | 2432 | { |
2425 | GNUNET_break(0); | 2433 | GNUNET_break(0); |
2426 | return; | 2434 | return; |
2427 | } | 2435 | } |
2428 | s->bulk_lock--; | 2436 | s->bulk_lock--; |
2429 | 2437 | ||
2430 | if (0 < s->bulk_changes) | 2438 | if (0 < s->bulk_changes) |
2431 | { | 2439 | { |
2432 | ril_step (solver); | 2440 | ril_step(solver); |
2433 | s->bulk_changes = 0; | 2441 | s->bulk_changes = 0; |
2434 | } | 2442 | } |
2435 | } | 2443 | } |
2436 | 2444 | ||
2437 | 2445 | ||
@@ -2446,38 +2454,38 @@ GAS_ril_bulk_stop (void *solver) | |||
2446 | * @param peer the identity of the peer | 2454 | * @param peer the identity of the peer |
2447 | */ | 2455 | */ |
2448 | static void | 2456 | static void |
2449 | GAS_ril_get_preferred_address (void *solver, | 2457 | GAS_ril_get_preferred_address(void *solver, |
2450 | const struct GNUNET_PeerIdentity *peer) | 2458 | const struct GNUNET_PeerIdentity *peer) |
2451 | { | 2459 | { |
2452 | struct GAS_RIL_Handle *s = solver; | 2460 | struct GAS_RIL_Handle *s = solver; |
2453 | struct RIL_Peer_Agent *agent; | 2461 | struct RIL_Peer_Agent *agent; |
2454 | 2462 | ||
2455 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n"); | 2463 | LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n"); |
2456 | 2464 | ||
2457 | agent = ril_get_agent (s, peer, GNUNET_YES); | 2465 | agent = ril_get_agent(s, peer, GNUNET_YES); |
2458 | 2466 | ||
2459 | agent->is_active = GNUNET_YES; | 2467 | agent->is_active = GNUNET_YES; |
2460 | envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES); | 2468 | envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES); |
2461 | 2469 | ||
2462 | ril_try_unblock_agent(solver, agent, GNUNET_YES); | 2470 | ril_try_unblock_agent(solver, agent, GNUNET_YES); |
2463 | 2471 | ||
2464 | if (agent->address_inuse) | 2472 | if (agent->address_inuse) |
2465 | { | 2473 | { |
2466 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2474 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2467 | "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n", | 2475 | "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n", |
2468 | GNUNET_i2s (peer), agent->address_inuse->plugin, agent->address_inuse->addr); | 2476 | GNUNET_i2s(peer), agent->address_inuse->plugin, agent->address_inuse->addr); |
2469 | } | 2477 | } |
2470 | else | 2478 | else |
2471 | { | 2479 | { |
2472 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2480 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2473 | "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", | 2481 | "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", |
2474 | GNUNET_i2s (peer)); | 2482 | GNUNET_i2s(peer)); |
2475 | s->parameters.temperature = s->parameters.temperature_init; | 2483 | s->parameters.temperature = s->parameters.temperature_init; |
2476 | s->parameters.epsilon = s->parameters.epsilon_init; | 2484 | s->parameters.epsilon = s->parameters.epsilon_init; |
2477 | } | 2485 | } |
2478 | if (NULL != agent->address_inuse) | 2486 | if (NULL != agent->address_inuse) |
2479 | s->env->bandwidth_changed_cb (s->env->cls, | 2487 | s->env->bandwidth_changed_cb(s->env->cls, |
2480 | agent->address_inuse); | 2488 | agent->address_inuse); |
2481 | } | 2489 | } |
2482 | 2490 | ||
2483 | 2491 | ||
@@ -2491,41 +2499,41 @@ GAS_ril_get_preferred_address (void *solver, | |||
2491 | * @param peer the peer | 2499 | * @param peer the peer |
2492 | */ | 2500 | */ |
2493 | static void | 2501 | static void |
2494 | GAS_ril_stop_get_preferred_address (void *solver, | 2502 | GAS_ril_stop_get_preferred_address(void *solver, |
2495 | const struct GNUNET_PeerIdentity *peer) | 2503 | const struct GNUNET_PeerIdentity *peer) |
2496 | { | 2504 | { |
2497 | struct GAS_RIL_Handle *s = solver; | 2505 | struct GAS_RIL_Handle *s = solver; |
2498 | struct RIL_Peer_Agent *agent; | 2506 | struct RIL_Peer_Agent *agent; |
2499 | 2507 | ||
2500 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2508 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2501 | "API_stop_get_preferred_address()"); | 2509 | "API_stop_get_preferred_address()"); |
2502 | 2510 | ||
2503 | agent = ril_get_agent (s, peer, GNUNET_NO); | 2511 | agent = ril_get_agent(s, peer, GNUNET_NO); |
2504 | 2512 | ||
2505 | if (NULL == agent) | 2513 | if (NULL == agent) |
2506 | { | 2514 | { |
2507 | GNUNET_break(0); | 2515 | GNUNET_break(0); |
2508 | return; | 2516 | return; |
2509 | } | 2517 | } |
2510 | if (GNUNET_NO == agent->is_active) | 2518 | if (GNUNET_NO == agent->is_active) |
2511 | { | 2519 | { |
2512 | GNUNET_break(0); | 2520 | GNUNET_break(0); |
2513 | return; | 2521 | return; |
2514 | } | 2522 | } |
2515 | 2523 | ||
2516 | s->parameters.temperature = s->parameters.temperature_init; | 2524 | s->parameters.temperature = s->parameters.temperature_init; |
2517 | s->parameters.epsilon = s->parameters.epsilon_init; | 2525 | s->parameters.epsilon = s->parameters.epsilon_init; |
2518 | 2526 | ||
2519 | agent->is_active = GNUNET_NO; | 2527 | agent->is_active = GNUNET_NO; |
2520 | 2528 | ||
2521 | envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, | 2529 | envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, |
2522 | GNUNET_YES); | 2530 | GNUNET_YES); |
2523 | 2531 | ||
2524 | ril_step (s); | 2532 | ril_step(s); |
2525 | 2533 | ||
2526 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2534 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2527 | "API_stop_get_preferred_address() Paused agent for peer '%s'\n", | 2535 | "API_stop_get_preferred_address() Paused agent for peer '%s'\n", |
2528 | GNUNET_i2s (peer)); | 2536 | GNUNET_i2s(peer)); |
2529 | } | 2537 | } |
2530 | 2538 | ||
2531 | 2539 | ||
@@ -2535,233 +2543,233 @@ GAS_ril_stop_get_preferred_address (void *solver, | |||
2535 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' | 2543 | * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' |
2536 | */ | 2544 | */ |
2537 | void * | 2545 | void * |
2538 | libgnunet_plugin_ats_ril_init (void *cls) | 2546 | libgnunet_plugin_ats_ril_init(void *cls) |
2539 | { | 2547 | { |
2540 | static struct GNUNET_ATS_SolverFunctions sf; | 2548 | static struct GNUNET_ATS_SolverFunctions sf; |
2541 | struct GNUNET_ATS_PluginEnvironment *env = cls; | 2549 | struct GNUNET_ATS_PluginEnvironment *env = cls; |
2542 | struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle); | 2550 | struct GAS_RIL_Handle *solver = GNUNET_new(struct GAS_RIL_Handle); |
2543 | struct RIL_Scope * cur; | 2551 | struct RIL_Scope * cur; |
2544 | int c; | 2552 | int c; |
2545 | char *string; | 2553 | char *string; |
2546 | float f_tmp; | 2554 | float f_tmp; |
2547 | 2555 | ||
2548 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2556 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2549 | "API_init() Initializing RIL solver\n"); | 2557 | "API_init() Initializing RIL solver\n"); |
2550 | 2558 | ||
2551 | GNUNET_assert (NULL != env); | 2559 | GNUNET_assert(NULL != env); |
2552 | GNUNET_assert (NULL != env->cfg); | 2560 | GNUNET_assert(NULL != env->cfg); |
2553 | GNUNET_assert (NULL != env->stats); | 2561 | GNUNET_assert(NULL != env->stats); |
2554 | GNUNET_assert (NULL != env->bandwidth_changed_cb); | 2562 | GNUNET_assert(NULL != env->bandwidth_changed_cb); |
2555 | GNUNET_assert (NULL != env->get_preferences); | 2563 | GNUNET_assert(NULL != env->get_preferences); |
2556 | 2564 | ||
2557 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) | 2565 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) |
2558 | { | 2566 | { |
2559 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; | 2567 | solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; |
2560 | } | 2568 | } |
2561 | 2569 | ||
2562 | if (GNUNET_OK | 2570 | if (GNUNET_OK |
2563 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MIN", | 2571 | != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MIN", |
2564 | &solver->parameters.step_time_min)) | 2572 | &solver->parameters.step_time_min)) |
2565 | { | 2573 | { |
2566 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; | 2574 | solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; |
2567 | } | 2575 | } |
2568 | 2576 | ||
2569 | if (GNUNET_OK | 2577 | if (GNUNET_OK |
2570 | != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats", "RIL_STEP_TIME_MAX", | 2578 | != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MAX", |
2571 | &solver->parameters.step_time_max)) | 2579 | &solver->parameters.step_time_max)) |
2572 | { | 2580 | { |
2573 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; | 2581 | solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; |
2574 | } | 2582 | } |
2575 | 2583 | ||
2576 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_ALGORITHM", &string)) | 2584 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_ALGORITHM", &string)) |
2577 | { | ||
2578 | GNUNET_STRINGS_utf8_toupper (string, string); | ||
2579 | if (0 == strcmp (string, "SARSA")) | ||
2580 | { | 2585 | { |
2581 | solver->parameters.algorithm = RIL_ALGO_SARSA; | 2586 | GNUNET_STRINGS_utf8_toupper(string, string); |
2587 | if (0 == strcmp(string, "SARSA")) | ||
2588 | { | ||
2589 | solver->parameters.algorithm = RIL_ALGO_SARSA; | ||
2590 | } | ||
2591 | if (0 == strcmp(string, "Q-LEARNING")) | ||
2592 | { | ||
2593 | solver->parameters.algorithm = RIL_ALGO_Q; | ||
2594 | } | ||
2595 | |||
2596 | GNUNET_free(string); | ||
2582 | } | 2597 | } |
2583 | if (0 == strcmp (string, "Q-LEARNING")) | 2598 | else |
2584 | { | 2599 | { |
2585 | solver->parameters.algorithm = RIL_ALGO_Q; | 2600 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; |
2586 | } | 2601 | } |
2587 | 2602 | ||
2588 | GNUNET_free (string); | 2603 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SELECT", &string)) |
2589 | } | 2604 | { |
2590 | else | 2605 | solver->parameters.select = !strcmp(string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; |
2591 | { | 2606 | GNUNET_free(string); |
2592 | solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; | 2607 | } |
2593 | } | ||
2594 | |||
2595 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SELECT", &string)) | ||
2596 | { | ||
2597 | solver->parameters.select = !strcmp (string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX; | ||
2598 | GNUNET_free (string); | ||
2599 | } | ||
2600 | else | 2608 | else |
2601 | { | 2609 | { |
2602 | solver->parameters.select = RIL_DEFAULT_SELECT; | 2610 | solver->parameters.select = RIL_DEFAULT_SELECT; |
2603 | } | 2611 | } |
2604 | 2612 | ||
2605 | 2613 | ||
2606 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; | 2614 | solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; |
2607 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2615 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2608 | "RIL_DISCOUNT_BETA", &f_tmp)) | 2616 | "RIL_DISCOUNT_BETA", &f_tmp)) |
2609 | { | ||
2610 | if (f_tmp < 0.0) | ||
2611 | { | ||
2612 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2613 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2614 | } | ||
2615 | else | ||
2616 | { | 2617 | { |
2617 | solver->parameters.beta = f_tmp; | 2618 | if (f_tmp < 0.0) |
2618 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2619 | { |
2619 | "RIL_DISCOUNT_BETA", f_tmp); | 2620 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2621 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2622 | } | ||
2623 | else | ||
2624 | { | ||
2625 | solver->parameters.beta = f_tmp; | ||
2626 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2627 | "RIL_DISCOUNT_BETA", f_tmp); | ||
2628 | } | ||
2620 | } | 2629 | } |
2621 | } | ||
2622 | 2630 | ||
2623 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; | 2631 | solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; |
2624 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2632 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2625 | "RIL_DISCOUNT_GAMMA", &f_tmp)) | 2633 | "RIL_DISCOUNT_GAMMA", &f_tmp)) |
2626 | { | ||
2627 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2628 | { | 2634 | { |
2629 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2635 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2630 | "RIL_DISCOUNT_GAMMA", f_tmp); | 2636 | { |
2631 | } | 2637 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2632 | else | 2638 | "RIL_DISCOUNT_GAMMA", f_tmp); |
2633 | { | 2639 | } |
2634 | solver->parameters.gamma = f_tmp; | 2640 | else |
2635 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2641 | { |
2636 | "RIL_DISCOUNT_GAMMA", f_tmp); | 2642 | solver->parameters.gamma = f_tmp; |
2643 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2644 | "RIL_DISCOUNT_GAMMA", f_tmp); | ||
2645 | } | ||
2637 | } | 2646 | } |
2638 | } | ||
2639 | 2647 | ||
2640 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; | 2648 | solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE; |
2641 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2649 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2642 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) | 2650 | "RIL_GRADIENT_STEP_SIZE", &f_tmp)) |
2643 | { | ||
2644 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2645 | { | 2651 | { |
2646 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2652 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2647 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | 2653 | { |
2648 | } | 2654 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2649 | else | 2655 | "RIL_GRADIENT_STEP_SIZE", f_tmp); |
2650 | { | 2656 | } |
2651 | solver->parameters.alpha = f_tmp; | 2657 | else |
2652 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2658 | { |
2653 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | 2659 | solver->parameters.alpha = f_tmp; |
2660 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2661 | "RIL_GRADIENT_STEP_SIZE", f_tmp); | ||
2662 | } | ||
2654 | } | 2663 | } |
2655 | } | ||
2656 | 2664 | ||
2657 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; | 2665 | solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; |
2658 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2666 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2659 | "RIL_TRACE_DECAY", &f_tmp)) | 2667 | "RIL_TRACE_DECAY", &f_tmp)) |
2660 | { | ||
2661 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2662 | { | ||
2663 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2664 | "RIL_TRACE_DECAY", f_tmp); | ||
2665 | } | ||
2666 | else | ||
2667 | { | 2668 | { |
2668 | solver->parameters.lambda = f_tmp; | 2669 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2669 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2670 | { |
2670 | "RIL_TRACE_DECAY", f_tmp); | 2671 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2672 | "RIL_TRACE_DECAY", f_tmp); | ||
2673 | } | ||
2674 | else | ||
2675 | { | ||
2676 | solver->parameters.lambda = f_tmp; | ||
2677 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2678 | "RIL_TRACE_DECAY", f_tmp); | ||
2679 | } | ||
2671 | } | 2680 | } |
2672 | } | ||
2673 | 2681 | ||
2674 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; | 2682 | solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO; |
2675 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2683 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2676 | "RIL_EXPLORE_RATIO", &f_tmp)) | 2684 | "RIL_EXPLORE_RATIO", &f_tmp)) |
2677 | { | ||
2678 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2679 | { | ||
2680 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2681 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2682 | } | ||
2683 | else | ||
2684 | { | 2685 | { |
2685 | solver->parameters.epsilon_init = f_tmp; | 2686 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2686 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2687 | { |
2687 | "RIL_EXPLORE_RATIO", f_tmp); | 2688 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2689 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2690 | } | ||
2691 | else | ||
2692 | { | ||
2693 | solver->parameters.epsilon_init = f_tmp; | ||
2694 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2695 | "RIL_EXPLORE_RATIO", f_tmp); | ||
2696 | } | ||
2688 | } | 2697 | } |
2689 | } | ||
2690 | 2698 | ||
2691 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; | 2699 | solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; |
2692 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2700 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2693 | "RIL_EXPLORE_DECAY", &f_tmp)) | 2701 | "RIL_EXPLORE_DECAY", &f_tmp)) |
2694 | { | ||
2695 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) | ||
2696 | { | 2702 | { |
2697 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2703 | if ((f_tmp < 0.0) || (f_tmp > 1.0)) |
2698 | "RIL_EXPLORE_DECAY", f_tmp); | 2704 | { |
2699 | } | 2705 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2700 | else | 2706 | "RIL_EXPLORE_DECAY", f_tmp); |
2701 | { | 2707 | } |
2702 | solver->parameters.epsilon_decay = f_tmp; | 2708 | else |
2703 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2709 | { |
2704 | "RIL_EXPLORE_DECAY", f_tmp); | 2710 | solver->parameters.epsilon_decay = f_tmp; |
2711 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2712 | "RIL_EXPLORE_DECAY", f_tmp); | ||
2713 | } | ||
2705 | } | 2714 | } |
2706 | } | ||
2707 | 2715 | ||
2708 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; | 2716 | solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE; |
2709 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2717 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2710 | "RIL_TEMPERATURE", &f_tmp)) | 2718 | "RIL_TEMPERATURE", &f_tmp)) |
2711 | { | ||
2712 | if (f_tmp <= 0.0) | ||
2713 | { | ||
2714 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2715 | "RIL_TEMPERATURE", f_tmp); | ||
2716 | } | ||
2717 | else | ||
2718 | { | 2719 | { |
2719 | solver->parameters.temperature_init = f_tmp; | 2720 | if (f_tmp <= 0.0) |
2720 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | 2721 | { |
2721 | "RIL_TEMPERATURE", f_tmp); | 2722 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), |
2723 | "RIL_TEMPERATURE", f_tmp); | ||
2724 | } | ||
2725 | else | ||
2726 | { | ||
2727 | solver->parameters.temperature_init = f_tmp; | ||
2728 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2729 | "RIL_TEMPERATURE", f_tmp); | ||
2730 | } | ||
2722 | } | 2731 | } |
2723 | } | ||
2724 | 2732 | ||
2725 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; | 2733 | solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; |
2726 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats", | 2734 | if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", |
2727 | "RIL_TEMPERATURE_DECAY", &f_tmp)) | 2735 | "RIL_TEMPERATURE_DECAY", &f_tmp)) |
2728 | { | ||
2729 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) | ||
2730 | { | 2736 | { |
2731 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | 2737 | if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) |
2732 | "RIL_TEMPERATURE_DECAY", f_tmp); | 2738 | { |
2739 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), | ||
2740 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2741 | } | ||
2742 | else | ||
2743 | { | ||
2744 | solver->parameters.temperature_decay = f_tmp; | ||
2745 | LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2746 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2747 | } | ||
2733 | } | 2748 | } |
2734 | else | 2749 | |
2750 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2735 | { | 2751 | { |
2736 | solver->parameters.temperature_decay = f_tmp; | 2752 | solver->simulate = GNUNET_NO; |
2737 | LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n", | ||
2738 | "RIL_TEMPERATURE_DECAY", f_tmp); | ||
2739 | } | 2753 | } |
2740 | } | ||
2741 | |||
2742 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats", "RIL_SIMULATE", &solver->simulate)) | ||
2743 | { | ||
2744 | solver->simulate = GNUNET_NO; | ||
2745 | } | ||
2746 | 2754 | ||
2747 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) | 2755 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) |
2748 | { | 2756 | { |
2749 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; | 2757 | solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; |
2750 | } | 2758 | } |
2751 | else | 2759 | else |
2752 | { | 2760 | { |
2753 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; | 2761 | solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; |
2754 | } | 2762 | } |
2755 | 2763 | ||
2756 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) | 2764 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) |
2757 | { | 2765 | { |
2758 | solver->parameters.social_welfare = !strcmp (string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; | 2766 | solver->parameters.social_welfare = !strcmp(string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; |
2759 | GNUNET_free (string); | 2767 | GNUNET_free(string); |
2760 | } | 2768 | } |
2761 | else | 2769 | else |
2762 | { | 2770 | { |
2763 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; | 2771 | solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; |
2764 | } | 2772 | } |
2765 | 2773 | ||
2766 | solver->env = env; | 2774 | solver->env = env; |
2767 | sf.cls = solver; | 2775 | sf.cls = solver; |
@@ -2776,22 +2784,22 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
2776 | sf.s_bulk_stop = &GAS_ril_bulk_stop; | 2784 | sf.s_bulk_stop = &GAS_ril_bulk_stop; |
2777 | 2785 | ||
2778 | solver->networks_count = env->network_count; | 2786 | solver->networks_count = env->network_count; |
2779 | solver->network_entries = GNUNET_malloc (env->network_count * sizeof (struct RIL_Scope)); | 2787 | solver->network_entries = GNUNET_malloc(env->network_count * sizeof(struct RIL_Scope)); |
2780 | solver->step_count = 0; | 2788 | solver->step_count = 0; |
2781 | solver->done = GNUNET_NO; | 2789 | solver->done = GNUNET_NO; |
2782 | 2790 | ||
2783 | for (c = 0; c < env->network_count; c++) | 2791 | for (c = 0; c < env->network_count; c++) |
2784 | { | 2792 | { |
2785 | cur = &solver->network_entries[c]; | 2793 | cur = &solver->network_entries[c]; |
2786 | cur->type = c; | 2794 | cur->type = c; |
2787 | cur->bw_in_available = env->in_quota[c]; | 2795 | cur->bw_in_available = env->in_quota[c]; |
2788 | cur->bw_out_available = env->out_quota[c]; | 2796 | cur->bw_out_available = env->out_quota[c]; |
2789 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2797 | LOG(GNUNET_ERROR_TYPE_DEBUG, |
2790 | "init() Quotas for %s network: IN %llu - OUT %llu\n", | 2798 | "init() Quotas for %s network: IN %llu - OUT %llu\n", |
2791 | GNUNET_NT_to_string(cur->type), | 2799 | GNUNET_NT_to_string(cur->type), |
2792 | cur->bw_in_available/1024, | 2800 | cur->bw_in_available / 1024, |
2793 | cur->bw_out_available/1024); | 2801 | cur->bw_out_available / 1024); |
2794 | } | 2802 | } |
2795 | 2803 | ||
2796 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); | 2804 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); |
2797 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", | 2805 | LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", |
@@ -2816,7 +2824,7 @@ libgnunet_plugin_ats_ril_init (void *cls) | |||
2816 | * @param cls the solver handle | 2824 | * @param cls the solver handle |
2817 | */ | 2825 | */ |
2818 | void * | 2826 | void * |
2819 | libgnunet_plugin_ats_ril_done (void *cls) | 2827 | libgnunet_plugin_ats_ril_done(void *cls) |
2820 | { | 2828 | { |
2821 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 2829 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
2822 | struct GAS_RIL_Handle *s = sf->cls; | 2830 | struct GAS_RIL_Handle *s = sf->cls; |
@@ -2829,17 +2837,17 @@ libgnunet_plugin_ats_ril_done (void *cls) | |||
2829 | 2837 | ||
2830 | cur_agent = s->agents_head; | 2838 | cur_agent = s->agents_head; |
2831 | while (NULL != cur_agent) | 2839 | while (NULL != cur_agent) |
2832 | { | 2840 | { |
2833 | next_agent = cur_agent->next; | 2841 | next_agent = cur_agent->next; |
2834 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); | 2842 | GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); |
2835 | agent_die (s, cur_agent); | 2843 | agent_die(s, cur_agent); |
2836 | cur_agent = next_agent; | 2844 | cur_agent = next_agent; |
2837 | } | 2845 | } |
2838 | 2846 | ||
2839 | if (NULL != s->step_next_task_id) | 2847 | if (NULL != s->step_next_task_id) |
2840 | { | 2848 | { |
2841 | GNUNET_SCHEDULER_cancel (s->step_next_task_id); | 2849 | GNUNET_SCHEDULER_cancel(s->step_next_task_id); |
2842 | } | 2850 | } |
2843 | GNUNET_free(s->network_entries); | 2851 | GNUNET_free(s->network_entries); |
2844 | GNUNET_free(s); | 2852 | GNUNET_free(s); |
2845 | 2853 | ||
diff --git a/src/ats/test_ats2_lib.c b/src/ats/test_ats2_lib.c index 2c6dafa1a..1b9f0e234 100644 --- a/src/ats/test_ats2_lib.c +++ b/src/ats/test_ats2_lib.c | |||
@@ -14,7 +14,7 @@ | |||
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | /** | 18 | /** |
19 | * @file ats/test_ats2_lib.c | 19 | * @file ats/test_ats2_lib.c |
20 | * @brief test ATS library with a generic interpreter for running ATS tests | 20 | * @brief test ATS library with a generic interpreter for running ATS tests |
@@ -76,13 +76,13 @@ static struct GNUNET_ATS_SessionRecord *sr; | |||
76 | * @return | 76 | * @return |
77 | */ | 77 | */ |
78 | static void | 78 | static void |
79 | allocation_cb (void *cls, | 79 | allocation_cb(void *cls, |
80 | struct GNUNET_ATS_Session *session, | 80 | struct GNUNET_ATS_Session *session, |
81 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 81 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
82 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 82 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
83 | { | 83 | { |
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 84 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
85 | "allocation_cb() called\n"); | 85 | "allocation_cb() called\n"); |
86 | } | 86 | } |
87 | 87 | ||
88 | 88 | ||
@@ -96,12 +96,12 @@ allocation_cb (void *cls, | |||
96 | * @param address | 96 | * @param address |
97 | */ | 97 | */ |
98 | static void | 98 | static void |
99 | suggestion_cb (void *cls, | 99 | suggestion_cb(void *cls, |
100 | const struct GNUNET_PeerIdentity *pid, | 100 | const struct GNUNET_PeerIdentity *pid, |
101 | const char *address) | 101 | const char *address) |
102 | { | 102 | { |
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
104 | "suggestion_cb() called\n"); | 104 | "suggestion_cb() called\n"); |
105 | ret = 0; | 105 | ret = 0; |
106 | } | 106 | } |
107 | 107 | ||
@@ -112,16 +112,16 @@ suggestion_cb (void *cls, | |||
112 | * Initialises the application and transportation side of ATS. | 112 | * Initialises the application and transportation side of ATS. |
113 | */ | 113 | */ |
114 | static void | 114 | static void |
115 | init_both (const struct GNUNET_CONFIGURATION_Handle *cfg) | 115 | init_both(const struct GNUNET_CONFIGURATION_Handle *cfg) |
116 | { | 116 | { |
117 | ah = GNUNET_ATS_application_init (cfg); | 117 | ah = GNUNET_ATS_application_init(cfg); |
118 | GNUNET_assert (NULL != ah); | 118 | GNUNET_assert(NULL != ah); |
119 | th = GNUNET_ATS_transport_init (cfg, | 119 | th = GNUNET_ATS_transport_init(cfg, |
120 | &allocation_cb, | 120 | &allocation_cb, |
121 | NULL, | 121 | NULL, |
122 | &suggestion_cb, | 122 | &suggestion_cb, |
123 | NULL); | 123 | NULL); |
124 | GNUNET_assert (NULL != ah); | 124 | GNUNET_assert(NULL != ah); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
@@ -129,11 +129,11 @@ init_both (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
129 | * @brief Disconnect both 'sides' of ATS | 129 | * @brief Disconnect both 'sides' of ATS |
130 | */ | 130 | */ |
131 | static void | 131 | static void |
132 | finish_both (void) | 132 | finish_both(void) |
133 | { | 133 | { |
134 | GNUNET_ATS_application_done (ah); | 134 | GNUNET_ATS_application_done(ah); |
135 | ah = NULL; | 135 | ah = NULL; |
136 | GNUNET_ATS_transport_done (th); | 136 | GNUNET_ATS_transport_done(th); |
137 | th = NULL; | 137 | th = NULL; |
138 | } | 138 | } |
139 | 139 | ||
@@ -142,7 +142,7 @@ finish_both (void) | |||
142 | * @brief Provide information about the start of an imaginary connection | 142 | * @brief Provide information about the start of an imaginary connection |
143 | */ | 143 | */ |
144 | static void | 144 | static void |
145 | provide_info_start (void) | 145 | provide_info_start(void) |
146 | { | 146 | { |
147 | struct GNUNET_ATS_Properties prop = | 147 | struct GNUNET_ATS_Properties prop = |
148 | { | 148 | { |
@@ -157,12 +157,12 @@ provide_info_start (void) | |||
157 | .cc = GNUNET_TRANSPORT_CC_UNKNOWN, | 157 | .cc = GNUNET_TRANSPORT_CC_UNKNOWN, |
158 | }; | 158 | }; |
159 | 159 | ||
160 | sr = GNUNET_ATS_session_add (th, | 160 | sr = GNUNET_ATS_session_add(th, |
161 | &other_peer, | 161 | &other_peer, |
162 | "test-address", | 162 | "test-address", |
163 | NULL, | 163 | NULL, |
164 | &prop); | 164 | &prop); |
165 | GNUNET_assert (NULL != sr); | 165 | GNUNET_assert(NULL != sr); |
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
@@ -170,9 +170,9 @@ provide_info_start (void) | |||
170 | * @brief Provide information about the end of an imaginary connection | 170 | * @brief Provide information about the end of an imaginary connection |
171 | */ | 171 | */ |
172 | static void | 172 | static void |
173 | provide_info_end (void) | 173 | provide_info_end(void) |
174 | { | 174 | { |
175 | GNUNET_ATS_session_del (sr); | 175 | GNUNET_ATS_session_del(sr); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
@@ -180,24 +180,24 @@ provide_info_end (void) | |||
180 | * @brief Inform ATS about the need of a connection towards a peer | 180 | * @brief Inform ATS about the need of a connection towards a peer |
181 | */ | 181 | */ |
182 | static void | 182 | static void |
183 | get_suggestion (void) | 183 | get_suggestion(void) |
184 | { | 184 | { |
185 | struct GNUNET_ATS_ApplicationSuggestHandle *ash; | 185 | struct GNUNET_ATS_ApplicationSuggestHandle *ash; |
186 | 186 | ||
187 | ash = GNUNET_ATS_application_suggest (ah, | 187 | ash = GNUNET_ATS_application_suggest(ah, |
188 | &other_peer, | 188 | &other_peer, |
189 | GNUNET_MQ_PREFERENCE_NONE, | 189 | GNUNET_MQ_PREFERENCE_NONE, |
190 | GNUNET_BANDWIDTH_VALUE_MAX); | 190 | GNUNET_BANDWIDTH_VALUE_MAX); |
191 | GNUNET_assert (NULL != ash); | 191 | GNUNET_assert(NULL != ash); |
192 | } | 192 | } |
193 | 193 | ||
194 | 194 | ||
195 | static void | 195 | static void |
196 | on_shutdown (void *cls) | 196 | on_shutdown(void *cls) |
197 | { | 197 | { |
198 | provide_info_end (); | 198 | provide_info_end(); |
199 | finish_both (); | 199 | finish_both(); |
200 | GNUNET_SCHEDULER_shutdown (); | 200 | GNUNET_SCHEDULER_shutdown(); |
201 | } | 201 | } |
202 | 202 | ||
203 | 203 | ||
@@ -209,16 +209,16 @@ on_shutdown (void *cls) | |||
209 | * @param peer handle to the peer | 209 | * @param peer handle to the peer |
210 | */ | 210 | */ |
211 | static void | 211 | static void |
212 | run (void *cls, | 212 | run(void *cls, |
213 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 213 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
214 | struct GNUNET_TESTING_Peer *peer) | 214 | struct GNUNET_TESTING_Peer *peer) |
215 | { | 215 | { |
216 | init_both (cfg); | 216 | init_both(cfg); |
217 | provide_info_start (); | 217 | provide_info_start(); |
218 | get_suggestion (); | 218 | get_suggestion(); |
219 | (void) GNUNET_SCHEDULER_add_delayed (timeout, | 219 | (void)GNUNET_SCHEDULER_add_delayed(timeout, |
220 | &on_shutdown, | 220 | &on_shutdown, |
221 | NULL); | 221 | NULL); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
@@ -231,27 +231,27 @@ run (void *cls, | |||
231 | * @return | 231 | * @return |
232 | */ | 232 | */ |
233 | int | 233 | int |
234 | main (int argc, | 234 | main(int argc, |
235 | char *argv[]) | 235 | char *argv[]) |
236 | { | 236 | { |
237 | ret = 1; | 237 | ret = 1; |
238 | memset (&other_peer, 0, sizeof (struct GNUNET_PeerIdentity)); | 238 | memset(&other_peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
239 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 239 | timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, |
240 | 2); | 240 | 2); |
241 | if (0 != GNUNET_TESTING_peer_run ("test-ats2-lib", | 241 | if (0 != GNUNET_TESTING_peer_run("test-ats2-lib", |
242 | "test_ats2_lib.conf", | 242 | "test_ats2_lib.conf", |
243 | &run, NULL)) | 243 | &run, NULL)) |
244 | { | 244 | { |
245 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 245 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
246 | "Running the testing peer failed.\n"); | 246 | "Running the testing peer failed.\n"); |
247 | return 1; | 247 | return 1; |
248 | } | 248 | } |
249 | if (0 != ret) | 249 | if (0 != ret) |
250 | { | 250 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 251 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
252 | "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n"); | 252 | "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n"); |
253 | ret = 77; // SKIP test, test not yet right! | 253 | ret = 77; // SKIP test, test not yet right! |
254 | } | 254 | } |
255 | return ret; | 255 | return ret; |
256 | } | 256 | } |
257 | 257 | ||
diff --git a/src/ats/test_ats2_lib.h b/src/ats/test_ats2_lib.h index 5c1518792..f6d4d45b0 100644 --- a/src/ats/test_ats2_lib.h +++ b/src/ats/test_ats2_lib.h | |||
@@ -11,10 +11,10 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
18 | /** | 18 | /** |
19 | * @file ats/test_ats_lib.h | 19 | * @file ats/test_ats_lib.h |
20 | * @brief test ATS library with a generic interpreter for running ATS tests | 20 | * @brief test ATS library with a generic interpreter for running ATS tests |
@@ -515,9 +515,9 @@ | |||
515 | * @return 0 on success | 515 | * @return 0 on success |
516 | */ | 516 | */ |
517 | int | 517 | int |
518 | TEST_ATS_run (int argc, | 518 | TEST_ATS_run(int argc, |
519 | char *argv[], | 519 | char *argv[], |
520 | struct Command *cmds, | 520 | struct Command *cmds, |
521 | struct GNUNET_TIME_Relative timeout); | 521 | struct GNUNET_TIME_Relative timeout); |
522 | 522 | ||
523 | #endif | 523 | #endif |
diff --git a/src/ats/test_ats_api.c b/src/ats/test_ats_api.c index f04b4b08b..bc703a111 100644 --- a/src/ats/test_ats_api.c +++ b/src/ats/test_ats_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_api.c | 21 | * @file ats/test_ats_api.c |
22 | * @brief test ATS | 22 | * @brief test ATS |
@@ -28,7 +28,7 @@ | |||
28 | /** | 28 | /** |
29 | * Global timeout for the testcase. | 29 | * Global timeout for the testcase. |
30 | */ | 30 | */ |
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Definition of the test as a sequence of commands. | 34 | * Definition of the test as a sequence of commands. |
@@ -89,7 +89,7 @@ static struct Command test_commands[] = { | |||
89 | .code = CMD_ADD_SESSION, | 89 | .code = CMD_ADD_SESSION, |
90 | .label = "add-session-0-0-1", | 90 | .label = "add-session-0-0-1", |
91 | .details.add_session = { | 91 | .details.add_session = { |
92 | .add_label ="add-address-0-0", | 92 | .add_label = "add-address-0-0", |
93 | .session = 1 | 93 | .session = 1 |
94 | } | 94 | } |
95 | }, | 95 | }, |
@@ -104,7 +104,7 @@ static struct Command test_commands[] = { | |||
104 | .code = CMD_CHANGE_PREFERENCE, | 104 | .code = CMD_CHANGE_PREFERENCE, |
105 | .details.change_preference = { | 105 | .details.change_preference = { |
106 | .pid = 0 | 106 | .pid = 0 |
107 | /* FIXME: preference details */ | 107 | /* FIXME: preference details */ |
108 | } | 108 | } |
109 | }, | 109 | }, |
110 | { | 110 | { |
@@ -233,13 +233,13 @@ static struct Command test_commands[] = { | |||
233 | 233 | ||
234 | 234 | ||
235 | int | 235 | int |
236 | main (int argc, | 236 | main(int argc, |
237 | char *argv[]) | 237 | char *argv[]) |
238 | { | 238 | { |
239 | return TEST_ATS_run (argc, | 239 | return TEST_ATS_run(argc, |
240 | argv, | 240 | argv, |
241 | test_commands, | 241 | test_commands, |
242 | TIMEOUT); | 242 | TIMEOUT); |
243 | } | 243 | } |
244 | 244 | ||
245 | 245 | ||
diff --git a/src/ats/test_ats_lib.c b/src/ats/test_ats_lib.c index 33597e678..979dbde3e 100644 --- a/src/ats/test_ats_lib.c +++ b/src/ats/test_ats_lib.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_lib.c | 21 | * @file ats/test_ats_lib.c |
22 | * @brief test ATS library with a generic interpreter for running ATS tests | 22 | * @brief test ATS library with a generic interpreter for running ATS tests |
@@ -31,8 +31,7 @@ | |||
31 | /** | 31 | /** |
32 | * Information about the last address suggestion we got for a peer. | 32 | * Information about the last address suggestion we got for a peer. |
33 | */ | 33 | */ |
34 | struct AddressSuggestData | 34 | struct AddressSuggestData { |
35 | { | ||
36 | /** | 35 | /** |
37 | * Which session were we given? | 36 | * Which session were we given? |
38 | */ | 37 | */ |
@@ -63,8 +62,7 @@ struct AddressSuggestData | |||
63 | /** | 62 | /** |
64 | * Information about the last address information we got for an address. | 63 | * Information about the last address information we got for an address. |
65 | */ | 64 | */ |
66 | struct AddressInformationData | 65 | struct AddressInformationData { |
67 | { | ||
68 | /** | 66 | /** |
69 | * What address is this data about? | 67 | * What address is this data about? |
70 | */ | 68 | */ |
@@ -156,18 +154,18 @@ static struct Command *test_commands; | |||
156 | * @return #GNUNET_OK (continue to iterate) | 154 | * @return #GNUNET_OK (continue to iterate) |
157 | */ | 155 | */ |
158 | static int | 156 | static int |
159 | free_asd (void *cls, | 157 | free_asd(void *cls, |
160 | const struct GNUNET_PeerIdentity *key, | 158 | const struct GNUNET_PeerIdentity *key, |
161 | void *value) | 159 | void *value) |
162 | { | 160 | { |
163 | struct AddressSuggestData *asd = value; | 161 | struct AddressSuggestData *asd = value; |
164 | 162 | ||
165 | GNUNET_assert (GNUNET_YES == | 163 | GNUNET_assert(GNUNET_YES == |
166 | GNUNET_CONTAINER_multipeermap_remove (p2asd, | 164 | GNUNET_CONTAINER_multipeermap_remove(p2asd, |
167 | key, | 165 | key, |
168 | asd)); | 166 | asd)); |
169 | GNUNET_free_non_null (asd->address); | 167 | GNUNET_free_non_null(asd->address); |
170 | GNUNET_free (asd); | 168 | GNUNET_free(asd); |
171 | return GNUNET_OK; | 169 | return GNUNET_OK; |
172 | } | 170 | } |
173 | 171 | ||
@@ -181,18 +179,18 @@ free_asd (void *cls, | |||
181 | * @return #GNUNET_OK (continue to iterate) | 179 | * @return #GNUNET_OK (continue to iterate) |
182 | */ | 180 | */ |
183 | static int | 181 | static int |
184 | free_aid (void *cls, | 182 | free_aid(void *cls, |
185 | const struct GNUNET_PeerIdentity *key, | 183 | const struct GNUNET_PeerIdentity *key, |
186 | void *value) | 184 | void *value) |
187 | { | 185 | { |
188 | struct AddressInformationData *aid = value; | 186 | struct AddressInformationData *aid = value; |
189 | 187 | ||
190 | GNUNET_assert (GNUNET_YES == | 188 | GNUNET_assert(GNUNET_YES == |
191 | GNUNET_CONTAINER_multipeermap_remove (p2aid, | 189 | GNUNET_CONTAINER_multipeermap_remove(p2aid, |
192 | key, | 190 | key, |
193 | aid)); | 191 | aid)); |
194 | GNUNET_free (aid->address); | 192 | GNUNET_free(aid->address); |
195 | GNUNET_free (aid); | 193 | GNUNET_free(aid); |
196 | return GNUNET_OK; | 194 | return GNUNET_OK; |
197 | } | 195 | } |
198 | 196 | ||
@@ -204,18 +202,17 @@ free_aid (void *cls, | |||
204 | * @return NULL if peer was never involved | 202 | * @return NULL if peer was never involved |
205 | */ | 203 | */ |
206 | static struct AddressSuggestData * | 204 | static struct AddressSuggestData * |
207 | find_address_suggestion (const struct GNUNET_PeerIdentity *pid) | 205 | find_address_suggestion(const struct GNUNET_PeerIdentity *pid) |
208 | { | 206 | { |
209 | return GNUNET_CONTAINER_multipeermap_get (p2asd, | 207 | return GNUNET_CONTAINER_multipeermap_get(p2asd, |
210 | pid); | 208 | pid); |
211 | } | 209 | } |
212 | 210 | ||
213 | 211 | ||
214 | /** | 212 | /** |
215 | * Closure for #match_address() | 213 | * Closure for #match_address() |
216 | */ | 214 | */ |
217 | struct MatchAddressContext | 215 | struct MatchAddressContext { |
218 | { | ||
219 | /** | 216 | /** |
220 | * Address to find. | 217 | * Address to find. |
221 | */ | 218 | */ |
@@ -237,19 +234,19 @@ struct MatchAddressContext | |||
237 | * @return #GNUNET_OK if not found | 234 | * @return #GNUNET_OK if not found |
238 | */ | 235 | */ |
239 | static int | 236 | static int |
240 | match_address (void *cls, | 237 | match_address(void *cls, |
241 | const struct GNUNET_PeerIdentity *key, | 238 | const struct GNUNET_PeerIdentity *key, |
242 | void *value) | 239 | void *value) |
243 | { | 240 | { |
244 | struct MatchAddressContext *mac = cls; | 241 | struct MatchAddressContext *mac = cls; |
245 | struct AddressInformationData *aid = value; | 242 | struct AddressInformationData *aid = value; |
246 | 243 | ||
247 | if (0 == GNUNET_HELLO_address_cmp (mac->addr, | 244 | if (0 == GNUNET_HELLO_address_cmp(mac->addr, |
248 | aid->address)) | 245 | aid->address)) |
249 | { | 246 | { |
250 | mac->ret = aid; | 247 | mac->ret = aid; |
251 | return GNUNET_NO; | 248 | return GNUNET_NO; |
252 | } | 249 | } |
253 | return GNUNET_OK; | 250 | return GNUNET_OK; |
254 | } | 251 | } |
255 | 252 | ||
@@ -261,16 +258,16 @@ match_address (void *cls, | |||
261 | * @return NULL if peer was never involved | 258 | * @return NULL if peer was never involved |
262 | */ | 259 | */ |
263 | static struct AddressInformationData * | 260 | static struct AddressInformationData * |
264 | find_address_information (const struct GNUNET_HELLO_Address *addr) | 261 | find_address_information(const struct GNUNET_HELLO_Address *addr) |
265 | { | 262 | { |
266 | struct MatchAddressContext mac; | 263 | struct MatchAddressContext mac; |
267 | 264 | ||
268 | mac.ret = NULL; | 265 | mac.ret = NULL; |
269 | mac.addr = addr; | 266 | mac.addr = addr; |
270 | GNUNET_CONTAINER_multipeermap_get_multiple (p2aid, | 267 | GNUNET_CONTAINER_multipeermap_get_multiple(p2aid, |
271 | &addr->peer, | 268 | &addr->peer, |
272 | &match_address, | 269 | &match_address, |
273 | &mac); | 270 | &mac); |
274 | return mac.ret; | 271 | return mac.ret; |
275 | } | 272 | } |
276 | 273 | ||
@@ -281,51 +278,51 @@ find_address_information (const struct GNUNET_HELLO_Address *addr) | |||
281 | * @param cls NULL | 278 | * @param cls NULL |
282 | */ | 279 | */ |
283 | static void | 280 | static void |
284 | end (void *cls) | 281 | end(void *cls) |
285 | { | 282 | { |
286 | if (0 != ret) | 283 | if (0 != ret) |
287 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 284 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
288 | "Test failed at stage %u %s\n", | 285 | "Test failed at stage %u %s\n", |
289 | off, | 286 | off, |
290 | (NULL != test_commands[off].label) | 287 | (NULL != test_commands[off].label) |
291 | ? test_commands[off].label | 288 | ? test_commands[off].label |
292 | : ""); | 289 | : ""); |
293 | if (NULL != interpreter_task) | 290 | if (NULL != interpreter_task) |
294 | { | 291 | { |
295 | GNUNET_SCHEDULER_cancel (interpreter_task); | 292 | GNUNET_SCHEDULER_cancel(interpreter_task); |
296 | interpreter_task = NULL; | 293 | interpreter_task = NULL; |
297 | } | 294 | } |
298 | if (NULL != sched_ats) | 295 | if (NULL != sched_ats) |
299 | { | 296 | { |
300 | GNUNET_ATS_scheduling_done (sched_ats); | 297 | GNUNET_ATS_scheduling_done(sched_ats); |
301 | sched_ats = NULL; | 298 | sched_ats = NULL; |
302 | } | 299 | } |
303 | if (NULL != con_ats) | 300 | if (NULL != con_ats) |
304 | { | 301 | { |
305 | GNUNET_ATS_connectivity_done (con_ats); | 302 | GNUNET_ATS_connectivity_done(con_ats); |
306 | con_ats = NULL; | 303 | con_ats = NULL; |
307 | } | 304 | } |
308 | if (NULL != perf_ats) | 305 | if (NULL != perf_ats) |
309 | { | 306 | { |
310 | GNUNET_ATS_performance_done (perf_ats); | 307 | GNUNET_ATS_performance_done(perf_ats); |
311 | perf_ats = NULL; | 308 | perf_ats = NULL; |
312 | } | 309 | } |
313 | if (NULL != p2asd) | 310 | if (NULL != p2asd) |
314 | { | 311 | { |
315 | GNUNET_CONTAINER_multipeermap_iterate (p2asd, | 312 | GNUNET_CONTAINER_multipeermap_iterate(p2asd, |
316 | &free_asd, | 313 | &free_asd, |
317 | NULL); | 314 | NULL); |
318 | GNUNET_CONTAINER_multipeermap_destroy (p2asd); | 315 | GNUNET_CONTAINER_multipeermap_destroy(p2asd); |
319 | p2asd = NULL; | 316 | p2asd = NULL; |
320 | } | 317 | } |
321 | if (NULL != p2aid) | 318 | if (NULL != p2aid) |
322 | { | 319 | { |
323 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | 320 | GNUNET_CONTAINER_multipeermap_iterate(p2aid, |
324 | &free_aid, | 321 | &free_aid, |
325 | NULL); | 322 | NULL); |
326 | GNUNET_CONTAINER_multipeermap_destroy (p2aid); | 323 | GNUNET_CONTAINER_multipeermap_destroy(p2aid); |
327 | p2aid = NULL; | 324 | p2aid = NULL; |
328 | } | 325 | } |
329 | } | 326 | } |
330 | 327 | ||
331 | 328 | ||
@@ -335,19 +332,19 @@ end (void *cls) | |||
335 | * @param cls NULL | 332 | * @param cls NULL |
336 | */ | 333 | */ |
337 | static void | 334 | static void |
338 | interpreter (void *cls); | 335 | interpreter(void *cls); |
339 | 336 | ||
340 | 337 | ||
341 | /** | 338 | /** |
342 | * Run the interpreter next. | 339 | * Run the interpreter next. |
343 | */ | 340 | */ |
344 | static void | 341 | static void |
345 | run_interpreter () | 342 | run_interpreter() |
346 | { | 343 | { |
347 | if (NULL != interpreter_task) | 344 | if (NULL != interpreter_task) |
348 | GNUNET_SCHEDULER_cancel (interpreter_task); | 345 | GNUNET_SCHEDULER_cancel(interpreter_task); |
349 | interpreter_task = GNUNET_SCHEDULER_add_now (&interpreter, | 346 | interpreter_task = GNUNET_SCHEDULER_add_now(&interpreter, |
350 | NULL); | 347 | NULL); |
351 | } | 348 | } |
352 | 349 | ||
353 | 350 | ||
@@ -358,15 +355,15 @@ run_interpreter () | |||
358 | * @param pk resulting fake public key | 355 | * @param pk resulting fake public key |
359 | */ | 356 | */ |
360 | static void | 357 | static void |
361 | make_peer (uint32_t pid, | 358 | make_peer(uint32_t pid, |
362 | struct GNUNET_PeerIdentity *pk) | 359 | struct GNUNET_PeerIdentity *pk) |
363 | { | 360 | { |
364 | memset (pk, | 361 | memset(pk, |
365 | (int) pid, | 362 | (int)pid, |
366 | sizeof (struct GNUNET_PeerIdentity)); | 363 | sizeof(struct GNUNET_PeerIdentity)); |
367 | GNUNET_memcpy (pk, | 364 | GNUNET_memcpy(pk, |
368 | &pid, | 365 | &pid, |
369 | sizeof (uint32_t)); | 366 | sizeof(uint32_t)); |
370 | } | 367 | } |
371 | 368 | ||
372 | 369 | ||
@@ -379,29 +376,28 @@ make_peer (uint32_t pid, | |||
379 | * @return the address | 376 | * @return the address |
380 | */ | 377 | */ |
381 | static struct GNUNET_HELLO_Address * | 378 | static struct GNUNET_HELLO_Address * |
382 | make_address (uint32_t pid, | 379 | make_address(uint32_t pid, |
383 | uint32_t num, | 380 | uint32_t num, |
384 | enum GNUNET_HELLO_AddressInfo addr_flags) | 381 | enum GNUNET_HELLO_AddressInfo addr_flags) |
385 | { | 382 | { |
386 | struct GNUNET_PeerIdentity pk; | 383 | struct GNUNET_PeerIdentity pk; |
387 | uint32_t nbo; | 384 | uint32_t nbo; |
388 | 385 | ||
389 | nbo = htonl (num); | 386 | nbo = htonl(num); |
390 | make_peer (pid, | 387 | make_peer(pid, |
391 | &pk); | 388 | &pk); |
392 | return GNUNET_HELLO_address_allocate (&pk, | 389 | return GNUNET_HELLO_address_allocate(&pk, |
393 | "test", | 390 | "test", |
394 | &nbo, | 391 | &nbo, |
395 | sizeof (nbo), | 392 | sizeof(nbo), |
396 | addr_flags); | 393 | addr_flags); |
397 | } | 394 | } |
398 | 395 | ||
399 | 396 | ||
400 | /** | 397 | /** |
401 | * Our dummy sessions. | 398 | * Our dummy sessions. |
402 | */ | 399 | */ |
403 | struct GNUNET_ATS_Session | 400 | struct GNUNET_ATS_Session { |
404 | { | ||
405 | /** | 401 | /** |
406 | * Field to avoid `0 == sizeof(struct GNUNET_ATS_Session)`. | 402 | * Field to avoid `0 == sizeof(struct GNUNET_ATS_Session)`. |
407 | */ | 403 | */ |
@@ -416,7 +412,7 @@ struct GNUNET_ATS_Session | |||
416 | * @return NULL if @a i is 0, otherwise a pointer unique to @a i | 412 | * @return NULL if @a i is 0, otherwise a pointer unique to @a i |
417 | */ | 413 | */ |
418 | static struct GNUNET_ATS_Session * | 414 | static struct GNUNET_ATS_Session * |
419 | make_session (unsigned int i) | 415 | make_session(unsigned int i) |
420 | { | 416 | { |
421 | struct GNUNET_ATS_Session *baseptr = NULL; | 417 | struct GNUNET_ATS_Session *baseptr = NULL; |
422 | 418 | ||
@@ -438,19 +434,19 @@ make_session (unsigned int i) | |||
438 | * @return previous command with the matching label | 434 | * @return previous command with the matching label |
439 | */ | 435 | */ |
440 | static struct Command * | 436 | static struct Command * |
441 | find_command (enum CommandCode code, | 437 | find_command(enum CommandCode code, |
442 | const char *label) | 438 | const char *label) |
443 | { | 439 | { |
444 | int i; | 440 | int i; |
445 | 441 | ||
446 | if (NULL == label) | 442 | if (NULL == label) |
447 | return NULL; | 443 | return NULL; |
448 | for (i=off-1;i>=0;i--) | 444 | for (i = off - 1; i >= 0; i--) |
449 | if ( (code == test_commands[i].code) && | 445 | if ((code == test_commands[i].code) && |
450 | (0 == strcmp (test_commands[i].label, | 446 | (0 == strcmp(test_commands[i].label, |
451 | label)) ) | 447 | label))) |
452 | return &test_commands[i]; | 448 | return &test_commands[i]; |
453 | GNUNET_break (0); | 449 | GNUNET_break(0); |
454 | return NULL; | 450 | return NULL; |
455 | } | 451 | } |
456 | 452 | ||
@@ -470,51 +466,53 @@ find_command (enum CommandCode code, | |||
470 | * @param prop performance data for the address | 466 | * @param prop performance data for the address |
471 | */ | 467 | */ |
472 | static void | 468 | static void |
473 | info_cb (void *cls, | 469 | info_cb(void *cls, |
474 | const struct GNUNET_HELLO_Address *address, | 470 | const struct GNUNET_HELLO_Address *address, |
475 | int address_active, | 471 | int address_active, |
476 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 472 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
477 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 473 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
478 | const struct GNUNET_ATS_Properties *prop) | 474 | const struct GNUNET_ATS_Properties *prop) |
479 | { | 475 | { |
480 | struct Command *c = cls; | 476 | struct Command *c = cls; |
481 | struct CommandListAddresses *cmd = &c->details.list_addresses; | 477 | struct CommandListAddresses *cmd = &c->details.list_addresses; |
482 | 478 | ||
483 | if (NULL == address) | 479 | if (NULL == address) |
484 | { | ||
485 | cmd->alh = NULL; | ||
486 | /* we are done with the iteration, continue to execute */ | ||
487 | if ( (cmd->calls < cmd->min_calls) && | ||
488 | (cmd->active_calls < cmd->min_active_calls) ) | ||
489 | { | 480 | { |
490 | GNUNET_SCHEDULER_shutdown (); | 481 | cmd->alh = NULL; |
482 | /* we are done with the iteration, continue to execute */ | ||
483 | if ((cmd->calls < cmd->min_calls) && | ||
484 | (cmd->active_calls < cmd->min_active_calls)) | ||
485 | { | ||
486 | GNUNET_SCHEDULER_shutdown(); | ||
487 | return; | ||
488 | } | ||
489 | off++; | ||
490 | run_interpreter(); | ||
491 | return; | 491 | return; |
492 | } | 492 | } |
493 | off++; | ||
494 | run_interpreter (); | ||
495 | return; | ||
496 | } | ||
497 | switch (address_active) | 493 | switch (address_active) |
498 | { | 494 | { |
499 | case GNUNET_YES: | 495 | case GNUNET_YES: |
500 | cmd->active_calls++; | 496 | cmd->active_calls++; |
501 | cmd->calls++; | 497 | cmd->calls++; |
502 | break; | 498 | break; |
503 | case GNUNET_NO: | 499 | |
504 | cmd->calls++; | 500 | case GNUNET_NO: |
505 | break; | 501 | cmd->calls++; |
506 | case GNUNET_SYSERR: | 502 | break; |
507 | return; | 503 | |
508 | } | 504 | case GNUNET_SYSERR: |
509 | if ( (cmd->calls > cmd->max_calls) && | 505 | return; |
510 | (cmd->active_calls < cmd->max_active_calls) ) | 506 | } |
511 | { | 507 | if ((cmd->calls > cmd->max_calls) && |
512 | GNUNET_break (0); | 508 | (cmd->active_calls < cmd->max_active_calls)) |
513 | GNUNET_ATS_performance_list_addresses_cancel (cmd->alh); | 509 | { |
514 | cmd->alh = NULL; | 510 | GNUNET_break(0); |
515 | GNUNET_SCHEDULER_shutdown (); | 511 | GNUNET_ATS_performance_list_addresses_cancel(cmd->alh); |
516 | return; | 512 | cmd->alh = NULL; |
517 | } | 513 | GNUNET_SCHEDULER_shutdown(); |
514 | return; | ||
515 | } | ||
518 | } | 516 | } |
519 | 517 | ||
520 | 518 | ||
@@ -529,56 +527,58 @@ info_cb (void *cls, | |||
529 | * long should the client wait until re-trying? | 527 | * long should the client wait until re-trying? |
530 | */ | 528 | */ |
531 | static void | 529 | static void |
532 | reservation_cb (void *cls, | 530 | reservation_cb(void *cls, |
533 | const struct GNUNET_PeerIdentity *peer, | 531 | const struct GNUNET_PeerIdentity *peer, |
534 | int32_t amount, | 532 | int32_t amount, |
535 | struct GNUNET_TIME_Relative res_delay) | 533 | struct GNUNET_TIME_Relative res_delay) |
536 | { | 534 | { |
537 | struct Command *cmd = cls; | 535 | struct Command *cmd = cls; |
538 | struct GNUNET_PeerIdentity pid; | 536 | struct GNUNET_PeerIdentity pid; |
539 | 537 | ||
540 | cmd->details.reserve_bandwidth.rc = NULL; | 538 | cmd->details.reserve_bandwidth.rc = NULL; |
541 | make_peer (cmd->details.reserve_bandwidth.pid, | 539 | make_peer(cmd->details.reserve_bandwidth.pid, |
542 | &pid); | 540 | &pid); |
543 | GNUNET_assert (0 == GNUNET_memcmp (peer, | 541 | GNUNET_assert(0 == GNUNET_memcmp(peer, |
544 | &pid)); | 542 | &pid)); |
545 | switch (cmd->details.reserve_bandwidth.expected_result) | 543 | switch (cmd->details.reserve_bandwidth.expected_result) |
546 | { | ||
547 | case GNUNET_OK: | ||
548 | if (amount != cmd->details.reserve_bandwidth.amount) | ||
549 | { | ||
550 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
551 | "Unexpectedly failed to reserve %d/%d bytes with delay %s!\n", | ||
552 | (int) amount, | ||
553 | (int) cmd->details.reserve_bandwidth.amount, | ||
554 | GNUNET_STRINGS_relative_time_to_string (res_delay, | ||
555 | GNUNET_YES)); | ||
556 | GNUNET_break (0); | ||
557 | GNUNET_SCHEDULER_shutdown (); | ||
558 | return; | ||
559 | } | ||
560 | break; | ||
561 | case GNUNET_NO: | ||
562 | GNUNET_break ( (0 != amount) || | ||
563 | (0 != res_delay.rel_value_us) ); | ||
564 | break; | ||
565 | case GNUNET_SYSERR: | ||
566 | if ( (amount != 0) || | ||
567 | (0 == res_delay.rel_value_us) ) | ||
568 | { | 544 | { |
569 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 545 | case GNUNET_OK: |
570 | "Unexpectedly reserved %d bytes with delay %s!\n", | 546 | if (amount != cmd->details.reserve_bandwidth.amount) |
571 | (int) amount, | 547 | { |
572 | GNUNET_STRINGS_relative_time_to_string (res_delay, | 548 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
573 | GNUNET_YES)); | 549 | "Unexpectedly failed to reserve %d/%d bytes with delay %s!\n", |
574 | GNUNET_break (0); | 550 | (int)amount, |
575 | GNUNET_SCHEDULER_shutdown (); | 551 | (int)cmd->details.reserve_bandwidth.amount, |
576 | return; | 552 | GNUNET_STRINGS_relative_time_to_string(res_delay, |
553 | GNUNET_YES)); | ||
554 | GNUNET_break(0); | ||
555 | GNUNET_SCHEDULER_shutdown(); | ||
556 | return; | ||
557 | } | ||
558 | break; | ||
559 | |||
560 | case GNUNET_NO: | ||
561 | GNUNET_break((0 != amount) || | ||
562 | (0 != res_delay.rel_value_us)); | ||
563 | break; | ||
564 | |||
565 | case GNUNET_SYSERR: | ||
566 | if ((amount != 0) || | ||
567 | (0 == res_delay.rel_value_us)) | ||
568 | { | ||
569 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
570 | "Unexpectedly reserved %d bytes with delay %s!\n", | ||
571 | (int)amount, | ||
572 | GNUNET_STRINGS_relative_time_to_string(res_delay, | ||
573 | GNUNET_YES)); | ||
574 | GNUNET_break(0); | ||
575 | GNUNET_SCHEDULER_shutdown(); | ||
576 | return; | ||
577 | } | ||
578 | break; | ||
577 | } | 579 | } |
578 | break; | ||
579 | } | ||
580 | off++; | 580 | off++; |
581 | run_interpreter (); | 581 | run_interpreter(); |
582 | } | 582 | } |
583 | 583 | ||
584 | 584 | ||
@@ -588,282 +588,297 @@ reservation_cb (void *cls, | |||
588 | * @param cls NULL | 588 | * @param cls NULL |
589 | */ | 589 | */ |
590 | static void | 590 | static void |
591 | interpreter (void *cls) | 591 | interpreter(void *cls) |
592 | 592 | ||
593 | { | 593 | { |
594 | struct Command *cmd; | 594 | struct Command *cmd; |
595 | 595 | ||
596 | interpreter_task = NULL; | 596 | interpreter_task = NULL; |
597 | while (1) | 597 | while (1) |
598 | { | ||
599 | cmd = &test_commands[off]; | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
601 | "#%u: %d %s\n", | ||
602 | off, | ||
603 | (int) cmd->code, | ||
604 | (NULL != cmd->label) ? cmd->label : ""); | ||
605 | switch (cmd->code) | ||
606 | { | 598 | { |
607 | case CMD_END_PASS: | 599 | cmd = &test_commands[off]; |
608 | ret = 0; | 600 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
609 | GNUNET_SCHEDULER_shutdown (); | 601 | "#%u: %d %s\n", |
610 | return; | 602 | off, |
611 | case CMD_ADD_ADDRESS: | 603 | (int)cmd->code, |
612 | { | 604 | (NULL != cmd->label) ? cmd->label : ""); |
613 | struct GNUNET_HELLO_Address *addr; | 605 | switch (cmd->code) |
614 | struct GNUNET_ATS_Session *session; | 606 | { |
615 | 607 | case CMD_END_PASS: | |
616 | addr = make_address (cmd->details.add_address.pid, | 608 | ret = 0; |
617 | cmd->details.add_address.addr_num, | 609 | GNUNET_SCHEDULER_shutdown(); |
618 | cmd->details.add_address.addr_flags); | 610 | return; |
619 | session = make_session (cmd->details.add_address.session); | 611 | |
620 | if (cmd->details.add_address.expect_fail) | 612 | case CMD_ADD_ADDRESS: |
621 | GNUNET_log_skip (1, GNUNET_NO); | ||
622 | cmd->details.add_address.ar | ||
623 | = GNUNET_ATS_address_add (sched_ats, | ||
624 | addr, | ||
625 | session, | ||
626 | &cmd->details.add_address.properties); | ||
627 | GNUNET_free (addr); | ||
628 | if (cmd->details.add_address.expect_fail) | ||
629 | { | 613 | { |
630 | GNUNET_log_skip (0, GNUNET_YES); | 614 | struct GNUNET_HELLO_Address *addr; |
615 | struct GNUNET_ATS_Session *session; | ||
616 | |||
617 | addr = make_address(cmd->details.add_address.pid, | ||
618 | cmd->details.add_address.addr_num, | ||
619 | cmd->details.add_address.addr_flags); | ||
620 | session = make_session(cmd->details.add_address.session); | ||
621 | if (cmd->details.add_address.expect_fail) | ||
622 | GNUNET_log_skip(1, GNUNET_NO); | ||
623 | cmd->details.add_address.ar | ||
624 | = GNUNET_ATS_address_add(sched_ats, | ||
625 | addr, | ||
626 | session, | ||
627 | &cmd->details.add_address.properties); | ||
628 | GNUNET_free(addr); | ||
629 | if (cmd->details.add_address.expect_fail) | ||
630 | { | ||
631 | GNUNET_log_skip(0, GNUNET_YES); | ||
632 | } | ||
633 | else if (NULL == cmd->details.add_address.ar) | ||
634 | { | ||
635 | GNUNET_break(0); | ||
636 | GNUNET_SCHEDULER_shutdown(); | ||
637 | return; | ||
638 | } | ||
639 | off++; | ||
640 | break; | ||
631 | } | 641 | } |
632 | else if (NULL == cmd->details.add_address.ar) | 642 | |
643 | case CMD_DEL_ADDRESS: | ||
633 | { | 644 | { |
634 | GNUNET_break (0); | 645 | struct Command *add; |
635 | GNUNET_SCHEDULER_shutdown (); | 646 | |
636 | return; | 647 | add = find_command(CMD_ADD_ADDRESS, |
648 | cmd->details.del_address.add_label); | ||
649 | GNUNET_assert(NULL != add->details.add_address.ar); | ||
650 | GNUNET_ATS_address_destroy(add->details.add_address.ar); | ||
651 | add->details.add_address.ar = NULL; | ||
652 | off++; | ||
653 | break; | ||
637 | } | 654 | } |
638 | off++; | 655 | |
639 | break; | 656 | case CMD_AWAIT_ADDRESS_SUGGESTION: |
640 | } | ||
641 | case CMD_DEL_ADDRESS: | ||
642 | { | ||
643 | struct Command *add; | ||
644 | |||
645 | add = find_command (CMD_ADD_ADDRESS, | ||
646 | cmd->details.del_address.add_label); | ||
647 | GNUNET_assert (NULL != add->details.add_address.ar); | ||
648 | GNUNET_ATS_address_destroy (add->details.add_address.ar); | ||
649 | add->details.add_address.ar = NULL; | ||
650 | off++; | ||
651 | break; | ||
652 | } | ||
653 | case CMD_AWAIT_ADDRESS_SUGGESTION: | ||
654 | { | ||
655 | struct GNUNET_PeerIdentity pid; | ||
656 | struct GNUNET_HELLO_Address *addr; | ||
657 | struct Command *add; | ||
658 | struct AddressSuggestData *asd; | ||
659 | int done; | ||
660 | |||
661 | make_peer (cmd->details.await_address_suggestion.pid, | ||
662 | &pid); | ||
663 | asd = find_address_suggestion (&pid); | ||
664 | if (NULL == asd) | ||
665 | return; | ||
666 | if (GNUNET_NO == asd->active) | ||
667 | return; /* last suggestion was to disconnect, wait longer */ | ||
668 | done = GNUNET_YES; | ||
669 | if (NULL != cmd->details.await_address_suggestion.add_label) | ||
670 | { | 657 | { |
671 | done = GNUNET_NO; | 658 | struct GNUNET_PeerIdentity pid; |
672 | add = find_command (CMD_ADD_ADDRESS, | 659 | struct GNUNET_HELLO_Address *addr; |
673 | cmd->details.await_address_suggestion.add_label); | 660 | struct Command *add; |
674 | addr = make_address (add->details.add_address.pid, | 661 | struct AddressSuggestData *asd; |
675 | add->details.add_address.addr_num, | 662 | int done; |
676 | add->details.add_address.addr_flags); | 663 | |
677 | if ( (asd->session == | 664 | make_peer(cmd->details.await_address_suggestion.pid, |
678 | make_session (add->details.add_address.session)) && | 665 | &pid); |
679 | (0 == | 666 | asd = find_address_suggestion(&pid); |
680 | GNUNET_HELLO_address_cmp (addr, | 667 | if (NULL == asd) |
681 | asd->address)) ) | 668 | return; |
682 | done = GNUNET_YES; | 669 | if (GNUNET_NO == asd->active) |
683 | GNUNET_free (addr); | 670 | return; /* last suggestion was to disconnect, wait longer */ |
671 | done = GNUNET_YES; | ||
672 | if (NULL != cmd->details.await_address_suggestion.add_label) | ||
673 | { | ||
674 | done = GNUNET_NO; | ||
675 | add = find_command(CMD_ADD_ADDRESS, | ||
676 | cmd->details.await_address_suggestion.add_label); | ||
677 | addr = make_address(add->details.add_address.pid, | ||
678 | add->details.add_address.addr_num, | ||
679 | add->details.add_address.addr_flags); | ||
680 | if ((asd->session == | ||
681 | make_session(add->details.add_address.session)) && | ||
682 | (0 == | ||
683 | GNUNET_HELLO_address_cmp(addr, | ||
684 | asd->address))) | ||
685 | done = GNUNET_YES; | ||
686 | GNUNET_free(addr); | ||
687 | } | ||
688 | if (GNUNET_NO == done) | ||
689 | return; | ||
690 | off++; | ||
691 | break; | ||
684 | } | 692 | } |
685 | if (GNUNET_NO == done) | 693 | |
686 | return; | 694 | case CMD_AWAIT_DISCONNECT_SUGGESTION: |
687 | off++; | ||
688 | break; | ||
689 | } | ||
690 | case CMD_AWAIT_DISCONNECT_SUGGESTION: | ||
691 | { | ||
692 | struct GNUNET_PeerIdentity pid; | ||
693 | struct AddressSuggestData *asd; | ||
694 | |||
695 | make_peer (cmd->details.await_disconnect_suggestion.pid, | ||
696 | &pid); | ||
697 | asd = find_address_suggestion (&pid); | ||
698 | if (NULL == asd) | ||
699 | return; /* odd, no suggestion at all yet!? */ | ||
700 | if (GNUNET_YES == asd->active) | ||
701 | return; /* last suggestion was to activate, wait longer */ | ||
702 | /* last suggestion was to deactivate, condition satisfied! */ | ||
703 | off++; | ||
704 | break; | ||
705 | } | ||
706 | case CMD_REQUEST_CONNECTION_START: | ||
707 | { | ||
708 | struct GNUNET_PeerIdentity pid; | ||
709 | |||
710 | make_peer (cmd->details.request_connection_start.pid, | ||
711 | &pid); | ||
712 | cmd->details.request_connection_start.csh | ||
713 | = GNUNET_ATS_connectivity_suggest (con_ats, | ||
714 | &pid, | ||
715 | 1); | ||
716 | off++; | ||
717 | break; | ||
718 | } | ||
719 | case CMD_REQUEST_CONNECTION_STOP: | ||
720 | { | ||
721 | struct Command *start; | ||
722 | |||
723 | start = find_command (CMD_REQUEST_CONNECTION_START, | ||
724 | cmd->details.request_connection_stop.connect_label); | ||
725 | GNUNET_ATS_connectivity_suggest_cancel (start->details.request_connection_start.csh); | ||
726 | start->details.request_connection_start.csh = NULL; | ||
727 | off++; | ||
728 | break; | ||
729 | } | ||
730 | case CMD_AWAIT_ADDRESS_INFORMATION: | ||
731 | { | ||
732 | struct AddressInformationData *aid; | ||
733 | struct Command *add; | ||
734 | struct Command *update; | ||
735 | struct GNUNET_HELLO_Address *addr; | ||
736 | const struct GNUNET_ATS_Properties *cmp; | ||
737 | |||
738 | add = find_command (CMD_ADD_ADDRESS, | ||
739 | cmd->details.await_address_information.add_label); | ||
740 | update = find_command (CMD_UPDATE_ADDRESS, | ||
741 | cmd->details.await_address_information.update_label); | ||
742 | addr = make_address (add->details.add_address.pid, | ||
743 | add->details.add_address.addr_num, | ||
744 | add->details.add_address.addr_flags); | ||
745 | aid = find_address_information (addr); | ||
746 | GNUNET_free (addr); | ||
747 | if (NULL == update) | ||
748 | cmp = &add->details.add_address.properties; | ||
749 | else | ||
750 | cmp = &update->details.update_address.properties; | ||
751 | if ( (NULL != aid) && | ||
752 | (cmp->delay.rel_value_us == aid->properties.delay.rel_value_us) && | ||
753 | (cmp->utilization_out == aid->properties.utilization_out) && | ||
754 | (cmp->utilization_in == aid->properties.utilization_in) && | ||
755 | (cmp->distance == aid->properties.distance) && | ||
756 | (cmp->scope == aid->properties.scope) ) | ||
757 | { | 695 | { |
696 | struct GNUNET_PeerIdentity pid; | ||
697 | struct AddressSuggestData *asd; | ||
698 | |||
699 | make_peer(cmd->details.await_disconnect_suggestion.pid, | ||
700 | &pid); | ||
701 | asd = find_address_suggestion(&pid); | ||
702 | if (NULL == asd) | ||
703 | return; /* odd, no suggestion at all yet!? */ | ||
704 | if (GNUNET_YES == asd->active) | ||
705 | return; /* last suggestion was to activate, wait longer */ | ||
706 | /* last suggestion was to deactivate, condition satisfied! */ | ||
758 | off++; | 707 | off++; |
759 | break; | 708 | break; |
760 | } | 709 | } |
761 | return; | 710 | |
762 | } | 711 | case CMD_REQUEST_CONNECTION_START: |
763 | case CMD_UPDATE_ADDRESS: | 712 | { |
764 | { | 713 | struct GNUNET_PeerIdentity pid; |
765 | struct Command *add; | 714 | |
766 | 715 | make_peer(cmd->details.request_connection_start.pid, | |
767 | add = find_command (CMD_ADD_ADDRESS, | 716 | &pid); |
768 | cmd->details.update_address.add_label); | 717 | cmd->details.request_connection_start.csh |
769 | GNUNET_assert (NULL != add->details.add_address.ar); | 718 | = GNUNET_ATS_connectivity_suggest(con_ats, |
770 | GNUNET_ATS_address_update (add->details.add_address.ar, | ||
771 | &cmd->details.update_address.properties); | ||
772 | off++; | ||
773 | break; | ||
774 | } | ||
775 | case CMD_ADD_SESSION: | ||
776 | { | ||
777 | struct Command *add; | ||
778 | struct GNUNET_ATS_Session *session; | ||
779 | |||
780 | add = find_command (CMD_ADD_ADDRESS, | ||
781 | cmd->details.add_session.add_label); | ||
782 | session = make_session (cmd->details.add_session.session); | ||
783 | GNUNET_assert (NULL != add->details.add_address.ar); | ||
784 | GNUNET_ATS_address_add_session (add->details.add_address.ar, | ||
785 | session); | ||
786 | off++; | ||
787 | break; | ||
788 | } | ||
789 | case CMD_DEL_SESSION: | ||
790 | { | ||
791 | struct Command *add_address; | ||
792 | struct Command *add_session; | ||
793 | struct GNUNET_ATS_Session *session; | ||
794 | |||
795 | add_session = find_command (CMD_ADD_SESSION, | ||
796 | cmd->details.del_session.add_session_label); | ||
797 | add_address = find_command (CMD_ADD_ADDRESS, | ||
798 | add_session->details.add_session.add_label); | ||
799 | GNUNET_assert (NULL != add_address->details.add_address.ar); | ||
800 | session = make_session (add_session->details.add_session.session); | ||
801 | GNUNET_ATS_address_del_session (add_address->details.add_address.ar, | ||
802 | session); | ||
803 | off++; | ||
804 | break; | ||
805 | } | ||
806 | case CMD_CHANGE_PREFERENCE: | ||
807 | { | ||
808 | struct GNUNET_PeerIdentity pid; | ||
809 | |||
810 | make_peer (cmd->details.change_preference.pid, | ||
811 | &pid); | ||
812 | GNUNET_ATS_performance_change_preference (perf_ats, | ||
813 | &pid, | ||
814 | GNUNET_ATS_PREFERENCE_END); | ||
815 | off++; | ||
816 | break; | ||
817 | } | ||
818 | case CMD_PROVIDE_FEEDBACK: | ||
819 | { | ||
820 | struct GNUNET_PeerIdentity pid; | ||
821 | |||
822 | make_peer (cmd->details.provide_feedback.pid, | ||
823 | &pid); | ||
824 | GNUNET_ATS_performance_give_feedback (perf_ats, | ||
825 | &pid, | 719 | &pid, |
826 | cmd->details.provide_feedback.scope, | 720 | 1); |
827 | GNUNET_ATS_PREFERENCE_END); | 721 | off++; |
828 | off++; | 722 | break; |
829 | break; | 723 | } |
830 | } | 724 | |
831 | case CMD_LIST_ADDRESSES: | 725 | case CMD_REQUEST_CONNECTION_STOP: |
832 | { | 726 | { |
833 | struct GNUNET_PeerIdentity pid; | 727 | struct Command *start; |
834 | 728 | ||
835 | make_peer (cmd->details.list_addresses.pid, | 729 | start = find_command(CMD_REQUEST_CONNECTION_START, |
836 | &pid); | 730 | cmd->details.request_connection_stop.connect_label); |
837 | cmd->details.list_addresses.alh | 731 | GNUNET_ATS_connectivity_suggest_cancel(start->details.request_connection_start.csh); |
838 | = GNUNET_ATS_performance_list_addresses (perf_ats, | 732 | start->details.request_connection_start.csh = NULL; |
733 | off++; | ||
734 | break; | ||
735 | } | ||
736 | |||
737 | case CMD_AWAIT_ADDRESS_INFORMATION: | ||
738 | { | ||
739 | struct AddressInformationData *aid; | ||
740 | struct Command *add; | ||
741 | struct Command *update; | ||
742 | struct GNUNET_HELLO_Address *addr; | ||
743 | const struct GNUNET_ATS_Properties *cmp; | ||
744 | |||
745 | add = find_command(CMD_ADD_ADDRESS, | ||
746 | cmd->details.await_address_information.add_label); | ||
747 | update = find_command(CMD_UPDATE_ADDRESS, | ||
748 | cmd->details.await_address_information.update_label); | ||
749 | addr = make_address(add->details.add_address.pid, | ||
750 | add->details.add_address.addr_num, | ||
751 | add->details.add_address.addr_flags); | ||
752 | aid = find_address_information(addr); | ||
753 | GNUNET_free(addr); | ||
754 | if (NULL == update) | ||
755 | cmp = &add->details.add_address.properties; | ||
756 | else | ||
757 | cmp = &update->details.update_address.properties; | ||
758 | if ((NULL != aid) && | ||
759 | (cmp->delay.rel_value_us == aid->properties.delay.rel_value_us) && | ||
760 | (cmp->utilization_out == aid->properties.utilization_out) && | ||
761 | (cmp->utilization_in == aid->properties.utilization_in) && | ||
762 | (cmp->distance == aid->properties.distance) && | ||
763 | (cmp->scope == aid->properties.scope)) | ||
764 | { | ||
765 | off++; | ||
766 | break; | ||
767 | } | ||
768 | return; | ||
769 | } | ||
770 | |||
771 | case CMD_UPDATE_ADDRESS: | ||
772 | { | ||
773 | struct Command *add; | ||
774 | |||
775 | add = find_command(CMD_ADD_ADDRESS, | ||
776 | cmd->details.update_address.add_label); | ||
777 | GNUNET_assert(NULL != add->details.add_address.ar); | ||
778 | GNUNET_ATS_address_update(add->details.add_address.ar, | ||
779 | &cmd->details.update_address.properties); | ||
780 | off++; | ||
781 | break; | ||
782 | } | ||
783 | |||
784 | case CMD_ADD_SESSION: | ||
785 | { | ||
786 | struct Command *add; | ||
787 | struct GNUNET_ATS_Session *session; | ||
788 | |||
789 | add = find_command(CMD_ADD_ADDRESS, | ||
790 | cmd->details.add_session.add_label); | ||
791 | session = make_session(cmd->details.add_session.session); | ||
792 | GNUNET_assert(NULL != add->details.add_address.ar); | ||
793 | GNUNET_ATS_address_add_session(add->details.add_address.ar, | ||
794 | session); | ||
795 | off++; | ||
796 | break; | ||
797 | } | ||
798 | |||
799 | case CMD_DEL_SESSION: | ||
800 | { | ||
801 | struct Command *add_address; | ||
802 | struct Command *add_session; | ||
803 | struct GNUNET_ATS_Session *session; | ||
804 | |||
805 | add_session = find_command(CMD_ADD_SESSION, | ||
806 | cmd->details.del_session.add_session_label); | ||
807 | add_address = find_command(CMD_ADD_ADDRESS, | ||
808 | add_session->details.add_session.add_label); | ||
809 | GNUNET_assert(NULL != add_address->details.add_address.ar); | ||
810 | session = make_session(add_session->details.add_session.session); | ||
811 | GNUNET_ATS_address_del_session(add_address->details.add_address.ar, | ||
812 | session); | ||
813 | off++; | ||
814 | break; | ||
815 | } | ||
816 | |||
817 | case CMD_CHANGE_PREFERENCE: | ||
818 | { | ||
819 | struct GNUNET_PeerIdentity pid; | ||
820 | |||
821 | make_peer(cmd->details.change_preference.pid, | ||
822 | &pid); | ||
823 | GNUNET_ATS_performance_change_preference(perf_ats, | ||
839 | &pid, | 824 | &pid, |
840 | cmd->details.list_addresses.all, | 825 | GNUNET_ATS_PREFERENCE_END); |
841 | &info_cb, | 826 | off++; |
842 | cmd); | 827 | break; |
843 | return; | 828 | } |
844 | } | 829 | |
845 | case CMD_RESERVE_BANDWIDTH: | 830 | case CMD_PROVIDE_FEEDBACK: |
846 | { | 831 | { |
847 | struct GNUNET_PeerIdentity pid; | 832 | struct GNUNET_PeerIdentity pid; |
848 | 833 | ||
849 | make_peer (cmd->details.reserve_bandwidth.pid, | 834 | make_peer(cmd->details.provide_feedback.pid, |
850 | &pid); | 835 | &pid); |
851 | cmd->details.reserve_bandwidth.rc | 836 | GNUNET_ATS_performance_give_feedback(perf_ats, |
852 | = GNUNET_ATS_reserve_bandwidth (perf_ats, | 837 | &pid, |
853 | &pid, | 838 | cmd->details.provide_feedback.scope, |
854 | cmd->details.reserve_bandwidth.amount, | 839 | GNUNET_ATS_PREFERENCE_END); |
855 | &reservation_cb, | 840 | off++; |
856 | cmd); | 841 | break; |
857 | return; | 842 | } |
858 | } | 843 | |
859 | case CMD_SLEEP: | 844 | case CMD_LIST_ADDRESSES: |
860 | off++; | 845 | { |
861 | interpreter_task = GNUNET_SCHEDULER_add_delayed (cmd->details.sleep.delay, | 846 | struct GNUNET_PeerIdentity pid; |
862 | &interpreter, | 847 | |
863 | NULL); | 848 | make_peer(cmd->details.list_addresses.pid, |
864 | return; | 849 | &pid); |
865 | } /* end switch */ | 850 | cmd->details.list_addresses.alh |
866 | } /* end while(1) */ | 851 | = GNUNET_ATS_performance_list_addresses(perf_ats, |
852 | &pid, | ||
853 | cmd->details.list_addresses.all, | ||
854 | &info_cb, | ||
855 | cmd); | ||
856 | return; | ||
857 | } | ||
858 | |||
859 | case CMD_RESERVE_BANDWIDTH: | ||
860 | { | ||
861 | struct GNUNET_PeerIdentity pid; | ||
862 | |||
863 | make_peer(cmd->details.reserve_bandwidth.pid, | ||
864 | &pid); | ||
865 | cmd->details.reserve_bandwidth.rc | ||
866 | = GNUNET_ATS_reserve_bandwidth(perf_ats, | ||
867 | &pid, | ||
868 | cmd->details.reserve_bandwidth.amount, | ||
869 | &reservation_cb, | ||
870 | cmd); | ||
871 | return; | ||
872 | } | ||
873 | |||
874 | case CMD_SLEEP: | ||
875 | off++; | ||
876 | interpreter_task = GNUNET_SCHEDULER_add_delayed(cmd->details.sleep.delay, | ||
877 | &interpreter, | ||
878 | NULL); | ||
879 | return; | ||
880 | } /* end switch */ | ||
881 | } /* end while(1) */ | ||
867 | } | 882 | } |
868 | 883 | ||
869 | 884 | ||
@@ -882,59 +897,59 @@ interpreter (void *cls) | |||
882 | * 0 to signal disconnect | 897 | * 0 to signal disconnect |
883 | */ | 898 | */ |
884 | static void | 899 | static void |
885 | address_suggest_cb (void *cls, | 900 | address_suggest_cb(void *cls, |
886 | const struct GNUNET_PeerIdentity *peer, | 901 | const struct GNUNET_PeerIdentity *peer, |
887 | const struct GNUNET_HELLO_Address *address, | 902 | const struct GNUNET_HELLO_Address *address, |
888 | struct GNUNET_ATS_Session *session, | 903 | struct GNUNET_ATS_Session *session, |
889 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 904 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
890 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) | 905 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) |
891 | { | 906 | { |
892 | const char *asc_cls = cls; | 907 | const char *asc_cls = cls; |
893 | struct AddressSuggestData *asd; | 908 | struct AddressSuggestData *asd; |
894 | 909 | ||
895 | GNUNET_break (0 == strcmp (asc_cls, "asc-closure")); | 910 | GNUNET_break(0 == strcmp(asc_cls, "asc-closure")); |
896 | if (NULL == peer) | 911 | if (NULL == peer) |
897 | { | 912 | { |
898 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 913 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
899 | "Connection to ATS died, likely a crash!\n"); | 914 | "Connection to ATS died, likely a crash!\n"); |
900 | GNUNET_SCHEDULER_shutdown (); | 915 | GNUNET_SCHEDULER_shutdown(); |
901 | #if 0 | 916 | #if 0 |
902 | /* This is what we should do if we wanted to continue past | 917 | /* This is what we should do if we wanted to continue past |
903 | the ATS crash. */ | 918 | the ATS crash. */ |
904 | GNUNET_CONTAINER_multipeermap_iterate (p2asd, | 919 | GNUNET_CONTAINER_multipeermap_iterate(p2asd, |
905 | &free_asd, | 920 | &free_asd, |
906 | NULL); | 921 | NULL); |
907 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | 922 | GNUNET_CONTAINER_multipeermap_iterate(p2aid, |
908 | &free_aid, | 923 | &free_aid, |
909 | NULL); | 924 | NULL); |
910 | #endif | 925 | #endif |
911 | return; | 926 | return; |
912 | } | 927 | } |
913 | 928 | ||
914 | asd = find_address_suggestion (peer); | 929 | asd = find_address_suggestion(peer); |
915 | if (NULL == asd) | 930 | if (NULL == asd) |
916 | { | 931 | { |
917 | asd = GNUNET_new (struct AddressSuggestData); | 932 | asd = GNUNET_new(struct AddressSuggestData); |
918 | GNUNET_assert (GNUNET_YES == | 933 | GNUNET_assert(GNUNET_YES == |
919 | GNUNET_CONTAINER_multipeermap_put (p2asd, | 934 | GNUNET_CONTAINER_multipeermap_put(p2asd, |
920 | peer, | 935 | peer, |
921 | asd, | 936 | asd, |
922 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 937 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
923 | } | 938 | } |
924 | if ( (0 == ntohl (bandwidth_out.value__)) && | 939 | if ((0 == ntohl(bandwidth_out.value__)) && |
925 | (0 == ntohl (bandwidth_in.value__)) ) | 940 | (0 == ntohl(bandwidth_in.value__))) |
926 | asd->active = GNUNET_NO; | 941 | asd->active = GNUNET_NO; |
927 | else | 942 | else |
928 | asd->active = GNUNET_YES; | 943 | asd->active = GNUNET_YES; |
929 | asd->bandwidth_out = bandwidth_out; | 944 | asd->bandwidth_out = bandwidth_out; |
930 | asd->bandwidth_in = bandwidth_in; | 945 | asd->bandwidth_in = bandwidth_in; |
931 | asd->session = session; | 946 | asd->session = session; |
932 | GNUNET_free_non_null (asd->address); | 947 | GNUNET_free_non_null(asd->address); |
933 | asd->address = NULL; | 948 | asd->address = NULL; |
934 | if (NULL != address) | 949 | if (NULL != address) |
935 | asd->address = GNUNET_HELLO_address_copy (address); | 950 | asd->address = GNUNET_HELLO_address_copy(address); |
936 | if (NULL == interpreter_task) | 951 | if (NULL == interpreter_task) |
937 | run_interpreter (); | 952 | run_interpreter(); |
938 | } | 953 | } |
939 | 954 | ||
940 | 955 | ||
@@ -952,44 +967,44 @@ address_suggest_cb (void *cls, | |||
952 | * @param prop performance data for the address | 967 | * @param prop performance data for the address |
953 | */ | 968 | */ |
954 | static void | 969 | static void |
955 | address_information_cb (void *cls, | 970 | address_information_cb(void *cls, |
956 | const struct GNUNET_HELLO_Address *address, | 971 | const struct GNUNET_HELLO_Address *address, |
957 | int address_active, | 972 | int address_active, |
958 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 973 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
959 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 974 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
960 | const struct GNUNET_ATS_Properties *prop) | 975 | const struct GNUNET_ATS_Properties *prop) |
961 | { | 976 | { |
962 | const char *aic_cls = cls; | 977 | const char *aic_cls = cls; |
963 | struct AddressInformationData *aid; | 978 | struct AddressInformationData *aid; |
964 | 979 | ||
965 | GNUNET_break (0 == strcmp (aic_cls, "aic-closure")); | 980 | GNUNET_break(0 == strcmp(aic_cls, "aic-closure")); |
966 | if (NULL == address) | 981 | if (NULL == address) |
967 | { | 982 | { |
968 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 983 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
969 | "Connection to ATS died, likely a crash!\n"); | 984 | "Connection to ATS died, likely a crash!\n"); |
970 | GNUNET_CONTAINER_multipeermap_iterate (p2aid, | 985 | GNUNET_CONTAINER_multipeermap_iterate(p2aid, |
971 | &free_aid, | 986 | &free_aid, |
972 | NULL); | 987 | NULL); |
973 | return; | 988 | return; |
974 | } | 989 | } |
975 | 990 | ||
976 | aid = find_address_information (address); | 991 | aid = find_address_information(address); |
977 | if (NULL == aid) | 992 | if (NULL == aid) |
978 | { | 993 | { |
979 | aid = GNUNET_new (struct AddressInformationData); | 994 | aid = GNUNET_new(struct AddressInformationData); |
980 | aid->address = GNUNET_HELLO_address_copy (address); | 995 | aid->address = GNUNET_HELLO_address_copy(address); |
981 | GNUNET_assert (GNUNET_YES == | 996 | GNUNET_assert(GNUNET_YES == |
982 | GNUNET_CONTAINER_multipeermap_put (p2aid, | 997 | GNUNET_CONTAINER_multipeermap_put(p2aid, |
983 | &address->peer, | 998 | &address->peer, |
984 | aid, | 999 | aid, |
985 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 1000 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
986 | } | 1001 | } |
987 | aid->active = address_active; | 1002 | aid->active = address_active; |
988 | aid->bandwidth_out = bandwidth_out; | 1003 | aid->bandwidth_out = bandwidth_out; |
989 | aid->bandwidth_in = bandwidth_in; | 1004 | aid->bandwidth_in = bandwidth_in; |
990 | aid->properties = *prop; | 1005 | aid->properties = *prop; |
991 | if (NULL == interpreter_task) | 1006 | if (NULL == interpreter_task) |
992 | run_interpreter (); | 1007 | run_interpreter(); |
993 | } | 1008 | } |
994 | 1009 | ||
995 | 1010 | ||
@@ -1001,44 +1016,44 @@ address_information_cb (void *cls, | |||
1001 | * @param peer handle to the peer | 1016 | * @param peer handle to the peer |
1002 | */ | 1017 | */ |
1003 | static void | 1018 | static void |
1004 | run (void *cls, | 1019 | run(void *cls, |
1005 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1020 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1006 | struct GNUNET_TESTING_Peer *peer) | 1021 | struct GNUNET_TESTING_Peer *peer) |
1007 | { | 1022 | { |
1008 | p2asd = GNUNET_CONTAINER_multipeermap_create (128, | 1023 | p2asd = GNUNET_CONTAINER_multipeermap_create(128, |
1009 | GNUNET_NO); | 1024 | GNUNET_NO); |
1010 | p2aid = GNUNET_CONTAINER_multipeermap_create (128, | 1025 | p2aid = GNUNET_CONTAINER_multipeermap_create(128, |
1011 | GNUNET_NO); | 1026 | GNUNET_NO); |
1012 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 1027 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
1013 | &end, | 1028 | &end, |
1014 | NULL); | 1029 | NULL); |
1015 | 1030 | ||
1016 | sched_ats = GNUNET_ATS_scheduling_init (cfg, | 1031 | sched_ats = GNUNET_ATS_scheduling_init(cfg, |
1017 | &address_suggest_cb, | 1032 | &address_suggest_cb, |
1018 | "asc-closure"); | 1033 | "asc-closure"); |
1019 | if (NULL == sched_ats) | 1034 | if (NULL == sched_ats) |
1020 | { | 1035 | { |
1021 | GNUNET_break (0); | 1036 | GNUNET_break(0); |
1022 | GNUNET_SCHEDULER_shutdown (); | 1037 | GNUNET_SCHEDULER_shutdown(); |
1023 | return; | 1038 | return; |
1024 | } | 1039 | } |
1025 | con_ats = GNUNET_ATS_connectivity_init (cfg); | 1040 | con_ats = GNUNET_ATS_connectivity_init(cfg); |
1026 | if (NULL == con_ats) | 1041 | if (NULL == con_ats) |
1027 | { | 1042 | { |
1028 | GNUNET_break (0); | 1043 | GNUNET_break(0); |
1029 | GNUNET_SCHEDULER_shutdown (); | 1044 | GNUNET_SCHEDULER_shutdown(); |
1030 | return; | 1045 | return; |
1031 | } | 1046 | } |
1032 | perf_ats = GNUNET_ATS_performance_init (cfg, | 1047 | perf_ats = GNUNET_ATS_performance_init(cfg, |
1033 | &address_information_cb, | 1048 | &address_information_cb, |
1034 | "aic-closure"); | 1049 | "aic-closure"); |
1035 | if (NULL == perf_ats) | 1050 | if (NULL == perf_ats) |
1036 | { | 1051 | { |
1037 | GNUNET_break (0); | 1052 | GNUNET_break(0); |
1038 | GNUNET_SCHEDULER_shutdown (); | 1053 | GNUNET_SCHEDULER_shutdown(); |
1039 | return; | 1054 | return; |
1040 | } | 1055 | } |
1041 | run_interpreter (); | 1056 | run_interpreter(); |
1042 | } | 1057 | } |
1043 | 1058 | ||
1044 | 1059 | ||
@@ -1052,32 +1067,32 @@ run (void *cls, | |||
1052 | * @return 0 on success | 1067 | * @return 0 on success |
1053 | */ | 1068 | */ |
1054 | int | 1069 | int |
1055 | TEST_ATS_run (int argc, | 1070 | TEST_ATS_run(int argc, |
1056 | char *argv[], | 1071 | char *argv[], |
1057 | struct Command *cmds, | 1072 | struct Command *cmds, |
1058 | struct GNUNET_TIME_Relative timeout) | 1073 | struct GNUNET_TIME_Relative timeout) |
1059 | { | 1074 | { |
1060 | char *test_filename = GNUNET_strdup (argv[0]); | 1075 | char *test_filename = GNUNET_strdup(argv[0]); |
1061 | char *sep; | 1076 | char *sep; |
1062 | char *config_file; | 1077 | char *config_file; |
1063 | char *underscore; | 1078 | char *underscore; |
1064 | 1079 | ||
1065 | test_commands = cmds; | 1080 | test_commands = cmds; |
1066 | TIMEOUT = timeout; | 1081 | TIMEOUT = timeout; |
1067 | if (NULL != (sep = strstr (test_filename, ".exe"))) | 1082 | if (NULL != (sep = strstr(test_filename, ".exe"))) |
1068 | sep[0] = '\0'; | 1083 | sep[0] = '\0'; |
1069 | underscore = strrchr (test_filename, (int) '_'); | 1084 | underscore = strrchr(test_filename, (int)'_'); |
1070 | GNUNET_assert (NULL != underscore); | 1085 | GNUNET_assert(NULL != underscore); |
1071 | GNUNET_asprintf (&config_file, | 1086 | GNUNET_asprintf(&config_file, |
1072 | "test_ats_api_%s.conf", | 1087 | "test_ats_api_%s.conf", |
1073 | underscore + 1); | 1088 | underscore + 1); |
1074 | ret = 2; | 1089 | ret = 2; |
1075 | if (0 != GNUNET_TESTING_peer_run ("test-ats-api", | 1090 | if (0 != GNUNET_TESTING_peer_run("test-ats-api", |
1076 | config_file, | 1091 | config_file, |
1077 | &run, NULL)) | 1092 | &run, NULL)) |
1078 | ret = 1; | 1093 | ret = 1; |
1079 | GNUNET_free (test_filename); | 1094 | GNUNET_free(test_filename); |
1080 | GNUNET_free (config_file); | 1095 | GNUNET_free(config_file); |
1081 | return ret; | 1096 | return ret; |
1082 | } | 1097 | } |
1083 | 1098 | ||
diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h index cc9f8ec73..db083d2d7 100644 --- a/src/ats/test_ats_lib.h +++ b/src/ats/test_ats_lib.h | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_lib.h | 21 | * @file ats/test_ats_lib.h |
22 | * @brief test ATS library with a generic interpreter for running ATS tests | 22 | * @brief test ATS library with a generic interpreter for running ATS tests |
@@ -33,8 +33,7 @@ | |||
33 | /** | 33 | /** |
34 | * Commands for the interpreter. | 34 | * Commands for the interpreter. |
35 | */ | 35 | */ |
36 | enum CommandCode | 36 | enum CommandCode { |
37 | { | ||
38 | /** | 37 | /** |
39 | * End the test (passing). | 38 | * End the test (passing). |
40 | */ | 39 | */ |
@@ -123,15 +122,13 @@ enum CommandCode | |||
123 | * Wait for a bit. | 122 | * Wait for a bit. |
124 | */ | 123 | */ |
125 | CMD_SLEEP | 124 | CMD_SLEEP |
126 | |||
127 | }; | 125 | }; |
128 | 126 | ||
129 | 127 | ||
130 | /** | 128 | /** |
131 | * Details for the #CMD_ADD_ADDRESS command. | 129 | * Details for the #CMD_ADD_ADDRESS command. |
132 | */ | 130 | */ |
133 | struct CommandAddAddress | 131 | struct CommandAddAddress { |
134 | { | ||
135 | /** | 132 | /** |
136 | * Number of the peer (used to generate PID). | 133 | * Number of the peer (used to generate PID). |
137 | */ | 134 | */ |
@@ -172,8 +169,7 @@ struct CommandAddAddress | |||
172 | /** | 169 | /** |
173 | * Details for the #CMD_DEL_ADDRESS command. | 170 | * Details for the #CMD_DEL_ADDRESS command. |
174 | */ | 171 | */ |
175 | struct CommandDelAddress | 172 | struct CommandDelAddress { |
176 | { | ||
177 | /** | 173 | /** |
178 | * Label of the corresponding #CMD_ADD_ADDRESS that | 174 | * Label of the corresponding #CMD_ADD_ADDRESS that |
179 | * we are now to remove. | 175 | * we are now to remove. |
@@ -185,8 +181,7 @@ struct CommandDelAddress | |||
185 | /** | 181 | /** |
186 | * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. | 182 | * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. |
187 | */ | 183 | */ |
188 | struct CommandAwaitAddressSuggestion | 184 | struct CommandAwaitAddressSuggestion { |
189 | { | ||
190 | /** | 185 | /** |
191 | * For which peer do we expect a suggestion? | 186 | * For which peer do we expect a suggestion? |
192 | */ | 187 | */ |
@@ -198,28 +193,24 @@ struct CommandAwaitAddressSuggestion | |||
198 | * use NULL for "any" available address. | 193 | * use NULL for "any" available address. |
199 | */ | 194 | */ |
200 | const char *add_label; | 195 | const char *add_label; |
201 | |||
202 | }; | 196 | }; |
203 | 197 | ||
204 | 198 | ||
205 | /** | 199 | /** |
206 | * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. | 200 | * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. |
207 | */ | 201 | */ |
208 | struct CommandAwaitDisconnectSuggestion | 202 | struct CommandAwaitDisconnectSuggestion { |
209 | { | ||
210 | /** | 203 | /** |
211 | * For which peer do we expect the disconnect? | 204 | * For which peer do we expect the disconnect? |
212 | */ | 205 | */ |
213 | unsigned int pid; | 206 | unsigned int pid; |
214 | |||
215 | }; | 207 | }; |
216 | 208 | ||
217 | 209 | ||
218 | /** | 210 | /** |
219 | * Details for the #CMD_REQUEST_CONNECTION_START command. | 211 | * Details for the #CMD_REQUEST_CONNECTION_START command. |
220 | */ | 212 | */ |
221 | struct CommandRequestConnectionStart | 213 | struct CommandRequestConnectionStart { |
222 | { | ||
223 | /** | 214 | /** |
224 | * Identity of the peer we would like to connect to. | 215 | * Identity of the peer we would like to connect to. |
225 | */ | 216 | */ |
@@ -236,8 +227,7 @@ struct CommandRequestConnectionStart | |||
236 | /** | 227 | /** |
237 | * Details for the #CMD_REQUEST_CONNECTION_STOP command. | 228 | * Details for the #CMD_REQUEST_CONNECTION_STOP command. |
238 | */ | 229 | */ |
239 | struct CommandRequestConnectionStop | 230 | struct CommandRequestConnectionStop { |
240 | { | ||
241 | /** | 231 | /** |
242 | * Label of the corresponding #CMD_REQUEST_CONNECTION_START that | 232 | * Label of the corresponding #CMD_REQUEST_CONNECTION_START that |
243 | * we are now stopping. | 233 | * we are now stopping. |
@@ -249,8 +239,7 @@ struct CommandRequestConnectionStop | |||
249 | /** | 239 | /** |
250 | * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. | 240 | * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. |
251 | */ | 241 | */ |
252 | struct CommandAwaitAddressInformation | 242 | struct CommandAwaitAddressInformation { |
253 | { | ||
254 | /** | 243 | /** |
255 | * For which address do we expect information? | 244 | * For which address do we expect information? |
256 | * The address is identified by the respective | 245 | * The address is identified by the respective |
@@ -264,15 +253,13 @@ struct CommandAwaitAddressInformation | |||
264 | * the properties from the @e add_label. | 253 | * the properties from the @e add_label. |
265 | */ | 254 | */ |
266 | const char *update_label; | 255 | const char *update_label; |
267 | |||
268 | }; | 256 | }; |
269 | 257 | ||
270 | 258 | ||
271 | /** | 259 | /** |
272 | * Details for the #CMD_UPDATE_ADDRESS command. | 260 | * Details for the #CMD_UPDATE_ADDRESS command. |
273 | */ | 261 | */ |
274 | struct CommandUpdateAddress | 262 | struct CommandUpdateAddress { |
275 | { | ||
276 | /** | 263 | /** |
277 | * Label of the addresses's add operation. | 264 | * Label of the addresses's add operation. |
278 | */ | 265 | */ |
@@ -282,16 +269,14 @@ struct CommandUpdateAddress | |||
282 | * Performance properties to supply. | 269 | * Performance properties to supply. |
283 | */ | 270 | */ |
284 | struct GNUNET_ATS_Properties properties; | 271 | struct GNUNET_ATS_Properties properties; |
285 | |||
286 | }; | 272 | }; |
287 | 273 | ||
288 | 274 | ||
289 | /** | 275 | /** |
290 | * Details for the #CMD_ADD_SESSION command. | 276 | * Details for the #CMD_ADD_SESSION command. |
291 | */ | 277 | */ |
292 | struct CommandAddSession | 278 | struct CommandAddSession { |
293 | { | 279 | /** |
294 | /** | ||
295 | * Label of the addresses's add operation. | 280 | * Label of the addresses's add operation. |
296 | */ | 281 | */ |
297 | const char *add_label; | 282 | const char *add_label; |
@@ -300,43 +285,37 @@ struct CommandAddSession | |||
300 | * Session to supply. | 285 | * Session to supply. |
301 | */ | 286 | */ |
302 | unsigned int session; | 287 | unsigned int session; |
303 | |||
304 | }; | 288 | }; |
305 | 289 | ||
306 | 290 | ||
307 | /** | 291 | /** |
308 | * Details for the #CMD_DEL_SESSION command. | 292 | * Details for the #CMD_DEL_SESSION command. |
309 | */ | 293 | */ |
310 | struct CommandDelSession | 294 | struct CommandDelSession { |
311 | { | 295 | /** |
312 | /** | ||
313 | * Label of the addresses's add operation. | 296 | * Label of the addresses's add operation. |
314 | */ | 297 | */ |
315 | const char *add_session_label; | 298 | const char *add_session_label; |
316 | |||
317 | }; | 299 | }; |
318 | 300 | ||
319 | 301 | ||
320 | /** | 302 | /** |
321 | * Details for the #CMD_CHANGE_PREFERENCE command. | 303 | * Details for the #CMD_CHANGE_PREFERENCE command. |
322 | */ | 304 | */ |
323 | struct CommandChangePreference | 305 | struct CommandChangePreference { |
324 | { | ||
325 | /** | 306 | /** |
326 | * Identity of the peer we have a preference change towards. | 307 | * Identity of the peer we have a preference change towards. |
327 | */ | 308 | */ |
328 | unsigned int pid; | 309 | unsigned int pid; |
329 | 310 | ||
330 | /* FIXME: preference details! */ | 311 | /* FIXME: preference details! */ |
331 | |||
332 | }; | 312 | }; |
333 | 313 | ||
334 | 314 | ||
335 | /** | 315 | /** |
336 | * Details for the #CMD_PROVIDE_FEEDBACK command. | 316 | * Details for the #CMD_PROVIDE_FEEDBACK command. |
337 | */ | 317 | */ |
338 | struct CommandProvideFeedback | 318 | struct CommandProvideFeedback { |
339 | { | ||
340 | /** | 319 | /** |
341 | * Identity of the peer we have a feedback for. | 320 | * Identity of the peer we have a feedback for. |
342 | */ | 321 | */ |
@@ -354,8 +333,7 @@ struct CommandProvideFeedback | |||
354 | /** | 333 | /** |
355 | * Details for the #CMD_LIST_ADDRESSES command. | 334 | * Details for the #CMD_LIST_ADDRESSES command. |
356 | */ | 335 | */ |
357 | struct CommandListAddresses | 336 | struct CommandListAddresses { |
358 | { | ||
359 | /** | 337 | /** |
360 | * Identity of the peer we want a list for. | 338 | * Identity of the peer we want a list for. |
361 | */ | 339 | */ |
@@ -403,15 +381,13 @@ struct CommandListAddresses | |||
403 | * #GNUNET_ATS_performance_list_addresses(). | 381 | * #GNUNET_ATS_performance_list_addresses(). |
404 | */ | 382 | */ |
405 | struct GNUNET_ATS_AddressListHandle *alh; | 383 | struct GNUNET_ATS_AddressListHandle *alh; |
406 | |||
407 | }; | 384 | }; |
408 | 385 | ||
409 | 386 | ||
410 | /** | 387 | /** |
411 | * Details for the #CMD_RESERVE_BANDWIDTH command. | 388 | * Details for the #CMD_RESERVE_BANDWIDTH command. |
412 | */ | 389 | */ |
413 | struct CommandReserveBandwidth | 390 | struct CommandReserveBandwidth { |
414 | { | ||
415 | /** | 391 | /** |
416 | * For which peer do we reserve bandwidth? | 392 | * For which peer do we reserve bandwidth? |
417 | */ | 393 | */ |
@@ -435,15 +411,13 @@ struct CommandReserveBandwidth | |||
435 | * #GNUNET_ATS_reserve_bandwidth(). | 411 | * #GNUNET_ATS_reserve_bandwidth(). |
436 | */ | 412 | */ |
437 | struct GNUNET_ATS_ReservationContext *rc; | 413 | struct GNUNET_ATS_ReservationContext *rc; |
438 | |||
439 | }; | 414 | }; |
440 | 415 | ||
441 | 416 | ||
442 | /** | 417 | /** |
443 | * Details for the #CMD_SLEEP command. | 418 | * Details for the #CMD_SLEEP command. |
444 | */ | 419 | */ |
445 | struct CommandSleep | 420 | struct CommandSleep { |
446 | { | ||
447 | /** | 421 | /** |
448 | * How long should we wait before running the next command? | 422 | * How long should we wait before running the next command? |
449 | */ | 423 | */ |
@@ -454,8 +428,7 @@ struct CommandSleep | |||
454 | /** | 428 | /** |
455 | * A command for the test case interpreter. | 429 | * A command for the test case interpreter. |
456 | */ | 430 | */ |
457 | struct Command | 431 | struct Command { |
458 | { | ||
459 | /** | 432 | /** |
460 | * Command code to run. | 433 | * Command code to run. |
461 | */ | 434 | */ |
@@ -470,7 +443,6 @@ struct Command | |||
470 | * Additional arguments to commands, if any. | 443 | * Additional arguments to commands, if any. |
471 | */ | 444 | */ |
472 | union { | 445 | union { |
473 | |||
474 | struct CommandAddAddress add_address; | 446 | struct CommandAddAddress add_address; |
475 | 447 | ||
476 | struct CommandDelAddress del_address; | 448 | struct CommandDelAddress del_address; |
@@ -500,9 +472,7 @@ struct Command | |||
500 | struct CommandReserveBandwidth reserve_bandwidth; | 472 | struct CommandReserveBandwidth reserve_bandwidth; |
501 | 473 | ||
502 | struct CommandSleep sleep; | 474 | struct CommandSleep sleep; |
503 | |||
504 | } details; | 475 | } details; |
505 | |||
506 | }; | 476 | }; |
507 | 477 | ||
508 | 478 | ||
@@ -516,9 +486,9 @@ struct Command | |||
516 | * @return 0 on success | 486 | * @return 0 on success |
517 | */ | 487 | */ |
518 | int | 488 | int |
519 | TEST_ATS_run (int argc, | 489 | TEST_ATS_run(int argc, |
520 | char *argv[], | 490 | char *argv[], |
521 | struct Command *cmds, | 491 | struct Command *cmds, |
522 | struct GNUNET_TIME_Relative timeout); | 492 | struct GNUNET_TIME_Relative timeout); |
523 | 493 | ||
524 | #endif | 494 | #endif |
diff --git a/src/ats/test_ats_reservation_api.c b/src/ats/test_ats_reservation_api.c index e7791343e..f6b0573e1 100644 --- a/src/ats/test_ats_reservation_api.c +++ b/src/ats/test_ats_reservation_api.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_reservation_api.c | 21 | * @file ats/test_ats_reservation_api.c |
22 | * @brief test ATS bandwidth reservation API | 22 | * @brief test ATS bandwidth reservation API |
@@ -28,7 +28,7 @@ | |||
28 | /** | 28 | /** |
29 | * Global timeout for the testcase. | 29 | * Global timeout for the testcase. |
30 | */ | 30 | */ |
31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) |
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Definition of the test as a sequence of commands. | 34 | * Definition of the test as a sequence of commands. |
@@ -146,13 +146,13 @@ static struct Command test_commands[] = { | |||
146 | 146 | ||
147 | 147 | ||
148 | int | 148 | int |
149 | main (int argc, | 149 | main(int argc, |
150 | char *argv[]) | 150 | char *argv[]) |
151 | { | 151 | { |
152 | return TEST_ATS_run (argc, | 152 | return TEST_ATS_run(argc, |
153 | argv, | 153 | argv, |
154 | test_commands, | 154 | test_commands, |
155 | TIMEOUT); | 155 | TIMEOUT); |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||