aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
committerChristian Grothoff <christian@grothoff.org>2019-10-05 15:09:28 +0200
commitc4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch)
treecac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/ats
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats.h45
-rw-r--r--src/ats/ats2.h21
-rw-r--r--src/ats/ats_api2_application.c202
-rw-r--r--src/ats/ats_api2_transport.c437
-rw-r--r--src/ats/ats_api_connectivity.c216
-rw-r--r--src/ats/ats_api_performance.c737
-rw-r--r--src/ats/ats_api_scanner.c28
-rw-r--r--src/ats/ats_api_scheduling.c582
-rw-r--r--src/ats/gnunet-ats-solver-eval.c4516
-rw-r--r--src/ats/gnunet-ats-solver-eval.h65
-rw-r--r--src/ats/gnunet-service-ats-new.c658
-rw-r--r--src/ats/gnunet-service-ats.c447
-rw-r--r--src/ats/gnunet-service-ats.h2
-rw-r--r--src/ats/gnunet-service-ats_addresses.c608
-rw-r--r--src/ats/gnunet-service-ats_addresses.h58
-rw-r--r--src/ats/gnunet-service-ats_connectivity.c117
-rw-r--r--src/ats/gnunet-service-ats_connectivity.h18
-rw-r--r--src/ats/gnunet-service-ats_normalization.c193
-rw-r--r--src/ats/gnunet-service-ats_normalization.h6
-rw-r--r--src/ats/gnunet-service-ats_performance.c233
-rw-r--r--src/ats/gnunet-service-ats_performance.h29
-rw-r--r--src/ats/gnunet-service-ats_plugins.c601
-rw-r--r--src/ats/gnunet-service-ats_plugins.h34
-rw-r--r--src/ats/gnunet-service-ats_preferences.c491
-rw-r--r--src/ats/gnunet-service-ats_preferences.h14
-rw-r--r--src/ats/gnunet-service-ats_reservations.c154
-rw-r--r--src/ats/gnunet-service-ats_reservations.h15
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c145
-rw-r--r--src/ats/gnunet-service-ats_scheduling.h21
-rw-r--r--src/ats/perf_ats_solver.c1609
-rw-r--r--src/ats/plugin_ats2_common.c83
-rw-r--r--src/ats/plugin_ats2_simple.c698
-rw-r--r--src/ats/plugin_ats_mlp.c2742
-rw-r--r--src/ats/plugin_ats_proportional.c1032
-rw-r--r--src/ats/plugin_ats_ril.c2423
-rw-r--r--src/ats/test_ats2_lib.c141
-rw-r--r--src/ats/test_ats2_lib.h110
-rw-r--r--src/ats/test_ats_api.c14
-rw-r--r--src/ats/test_ats_lib.c1128
-rw-r--r--src/ats/test_ats_lib.h62
-rw-r--r--src/ats/test_ats_reservation_api.c14
41 files changed, 10691 insertions, 10058 deletions
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 3501860f3..3a3d12cfa 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -34,7 +34,8 @@
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 */
37enum StartFlag { 37enum StartFlag
38{
38 /** 39 /**
39 * This is a scheduling client (aka transport service) 40 * This is a scheduling client (aka transport service)
40 */ 41 */
@@ -65,7 +66,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
65 * First message any client sends to ATS, used to self-identify 66 * First message any client sends to ATS, used to self-identify
66 * (what type of client this is). 67 * (what type of client this is).
67 */ 68 */
68struct ClientStartMessage { 69struct ClientStartMessage
70{
69 /** 71 /**
70 * Type is #GNUNET_MESSAGE_TYPE_ATS_START. 72 * Type is #GNUNET_MESSAGE_TYPE_ATS_START.
71 */ 73 */
@@ -82,7 +84,8 @@ struct ClientStartMessage {
82 * Connectivity client to ATS service: we would like to have 84 * Connectivity client to ATS service: we would like to have
83 * address suggestions for this peer. 85 * address suggestions for this peer.
84 */ 86 */
85struct RequestAddressMessage { 87struct RequestAddressMessage
88{
86 /** 89 /**
87 * Type is #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS or 90 * Type is #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS or
88 * #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL to stop 91 * #GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL to stop
@@ -105,7 +108,8 @@ struct RequestAddressMessage {
105/** 108/**
106 * Scheduling client to ATS service: here is another address you can use. 109 * Scheduling client to ATS service: here is another address you can use.
107 */ 110 */
108struct AddressAddMessage { 111struct AddressAddMessage
112{
109 /** 113 /**
110 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD. 114 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD.
111 */ 115 */
@@ -154,7 +158,8 @@ struct AddressAddMessage {
154 * Message used to notify ATS that the performance 158 * Message used to notify ATS that the performance
155 * characteristics for an address have changed. 159 * characteristics for an address have changed.
156 */ 160 */
157struct AddressUpdateMessage { 161struct AddressUpdateMessage
162{
158 /** 163 /**
159 * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE. 164 * Message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE.
160 */ 165 */
@@ -184,7 +189,8 @@ struct AddressUpdateMessage {
184 * was destroyed and must thus henceforth no longer be considered 189 * was destroyed and must thus henceforth no longer be considered
185 * for scheduling. 190 * for scheduling.
186 */ 191 */
187struct AddressDestroyedMessage { 192struct AddressDestroyedMessage
193{
188 /** 194 /**
189 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED. 195 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED.
190 */ 196 */
@@ -208,7 +214,8 @@ struct AddressDestroyedMessage {
208 * Message sent by ATS service to client to confirm that it is done 214 * Message sent by ATS service to client to confirm that it is done
209 * using the given session ID. 215 * using the given session ID.
210 */ 216 */
211struct GNUNET_ATS_SessionReleaseMessage { 217struct GNUNET_ATS_SessionReleaseMessage
218{
212 /** 219 /**
213 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE. 220 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE.
214 */ 221 */
@@ -234,7 +241,8 @@ struct GNUNET_ATS_SessionReleaseMessage {
234 * identified by the given @e session_id for the given @e peer with 241 * 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. 242 * the given @e bandwidth_in and @e bandwidth_out limits from now on.
236 */ 243 */
237struct AddressSuggestionMessage { 244struct AddressSuggestionMessage
245{
238 /** 246 /**
239 * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. 247 * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION.
240 */ 248 */
@@ -268,7 +276,8 @@ struct AddressSuggestionMessage {
268/** 276/**
269 * 277 *
270 */ 278 */
271struct PeerInformationMessage { 279struct PeerInformationMessage
280{
272 /** 281 /**
273 * Type is #GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION 282 * Type is #GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
274 */ 283 */
@@ -330,7 +339,8 @@ struct PeerInformationMessage {
330/** 339/**
331 * Client to service: please give us an overview of the addresses. 340 * Client to service: please give us an overview of the addresses.
332 */ 341 */
333struct AddressListRequestMessage { 342struct AddressListRequestMessage
343{
334 /** 344 /**
335 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST 345 * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST
336 */ 346 */
@@ -357,7 +367,8 @@ struct AddressListRequestMessage {
357/** 367/**
358 * 368 *
359 */ 369 */
360struct ReservationRequestMessage { 370struct ReservationRequestMessage
371{
361 /** 372 /**
362 * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST 373 * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST
363 */ 374 */
@@ -378,7 +389,8 @@ struct ReservationRequestMessage {
378/** 389/**
379 * 390 *
380 */ 391 */
381struct ReservationResultMessage { 392struct ReservationResultMessage
393{
382 /** 394 /**
383 * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT 395 * Type is #GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT
384 */ 396 */
@@ -405,7 +417,8 @@ struct ReservationResultMessage {
405 * Variable-size entry in a `struct ChangePreferenceMessage` or 417 * Variable-size entry in a `struct ChangePreferenceMessage` or
406 * `struct FeedbackPreferenceMessage`. 418 * `struct FeedbackPreferenceMessage`.
407 */ 419 */
408struct PreferenceInformation { 420struct PreferenceInformation
421{
409 /** 422 /**
410 * An `enum GNUNET_ATS_PreferenceKind` in NBO. 423 * An `enum GNUNET_ATS_PreferenceKind` in NBO.
411 */ 424 */
@@ -422,7 +435,8 @@ struct PreferenceInformation {
422/** 435/**
423 * Client to ATS: I have a performance preference for a peer. 436 * Client to ATS: I have a performance preference for a peer.
424 */ 437 */
425struct ChangePreferenceMessage { 438struct ChangePreferenceMessage
439{
426 /** 440 /**
427 * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE. 441 * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE.
428 */ 442 */
@@ -447,7 +461,8 @@ struct ChangePreferenceMessage {
447/** 461/**
448 * Message containing application feedback for a peer 462 * Message containing application feedback for a peer
449 */ 463 */
450struct FeedbackPreferenceMessage { 464struct FeedbackPreferenceMessage
465{
451 /** 466 /**
452 * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK. 467 * Type is #GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK.
453 */ 468 */
diff --git a/src/ats/ats2.h b/src/ats/ats2.h
index 723a8440d..df402dba2 100644
--- a/src/ats/ats2.h
+++ b/src/ats/ats2.h
@@ -36,7 +36,8 @@ GNUNET_NETWORK_STRUCT_BEGIN
36/** 36/**
37 * ATS performance characteristics for an address. 37 * ATS performance characteristics for an address.
38 */ 38 */
39struct PropertiesNBO { 39struct PropertiesNBO
40{
40 /** 41 /**
41 * Delay. Time between when the time packet is sent and the packet 42 * Delay. Time between when the time packet is sent and the packet
42 * arrives. FOREVER if we did not (successfully) measure yet. 43 * arrives. FOREVER if we did not (successfully) measure yet.
@@ -106,7 +107,8 @@ struct PropertiesNBO {
106 * Application client to ATS service: we would like to have 107 * Application client to ATS service: we would like to have
107 * address suggestions for this peer. 108 * address suggestions for this peer.
108 */ 109 */
109struct ExpressPreferenceMessage { 110struct ExpressPreferenceMessage
111{
110 /** 112 /**
111 * Type is #GNUNET_MESSAGE_TYPE_ATS_SUGGEST or 113 * Type is #GNUNET_MESSAGE_TYPE_ATS_SUGGEST or
112 * #GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL to stop 114 * #GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL to stop
@@ -135,7 +137,8 @@ struct ExpressPreferenceMessage {
135/** 137/**
136 * Transport client to ATS service: here is another session you can use. 138 * Transport client to ATS service: here is another session you can use.
137 */ 139 */
138struct SessionAddMessage { 140struct SessionAddMessage
141{
139 /** 142 /**
140 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or 143 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or
141 * #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY 144 * #GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
@@ -168,7 +171,8 @@ struct SessionAddMessage {
168 * Message used to notify ATS that the performance 171 * Message used to notify ATS that the performance
169 * characteristics for an session have changed. 172 * characteristics for an session have changed.
170 */ 173 */
171struct SessionUpdateMessage { 174struct SessionUpdateMessage
175{
172 /** 176 /**
173 * Message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE. 177 * Message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE.
174 */ 178 */
@@ -198,7 +202,8 @@ struct SessionUpdateMessage {
198 * was destroyed and must thus henceforth no longer be considered 202 * was destroyed and must thus henceforth no longer be considered
199 * for scheduling. 203 * for scheduling.
200 */ 204 */
201struct SessionDelMessage { 205struct SessionDelMessage
206{
202 /** 207 /**
203 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL. 208 * Type is #GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL.
204 */ 209 */
@@ -223,7 +228,8 @@ struct SessionDelMessage {
223 * identified by the given @e session_id for the given @e peer with 228 * identified by the given @e session_id for the given @e peer with
224 * the given @e bandwidth_in and @e bandwidth_out limits from now on. 229 * the given @e bandwidth_in and @e bandwidth_out limits from now on.
225 */ 230 */
226struct SessionAllocationMessage { 231struct SessionAllocationMessage
232{
227 /** 233 /**
228 * A message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION. 234 * A message of type #GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION.
229 */ 235 */
@@ -258,7 +264,8 @@ struct SessionAllocationMessage {
258 * ATS Service suggests to the transport service to try the address 264 * ATS Service suggests to the transport service to try the address
259 * for the given @e peer. 265 * for the given @e peer.
260 */ 266 */
261struct AddressSuggestionMessage { 267struct AddressSuggestionMessage
268{
262 /** 269 /**
263 * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION. 270 * A message of type #GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION.
264 */ 271 */
diff --git a/src/ats/ats_api2_application.c b/src/ats/ats_api2_application.c
index 2a21a116a..46e57c5bb 100644
--- a/src/ats/ats_api2_application.c
+++ b/src/ats/ats_api2_application.c
@@ -28,13 +28,15 @@
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", \
32 __VA_ARGS__)
32 33
33 34
34/** 35/**
35 * Handle for ATS address suggestion requests. 36 * Handle for ATS address suggestion requests.
36 */ 37 */
37struct GNUNET_ATS_ApplicationSuggestHandle { 38struct GNUNET_ATS_ApplicationSuggestHandle
39{
38 /** 40 /**
39 * ID of the peer for which address suggestion was requested. 41 * ID of the peer for which address suggestion was requested.
40 */ 42 */
@@ -60,7 +62,8 @@ struct GNUNET_ATS_ApplicationSuggestHandle {
60/** 62/**
61 * Handle to the ATS subsystem for application management. 63 * Handle to the ATS subsystem for application management.
62 */ 64 */
63struct GNUNET_ATS_ApplicationHandle { 65struct GNUNET_ATS_ApplicationHandle
66{
64 /** 67 /**
65 * Our configuration. 68 * Our configuration.
66 */ 69 */
@@ -96,7 +99,7 @@ struct GNUNET_ATS_ApplicationHandle {
96 * @param ch handle to use to re-connect. 99 * @param ch handle to use to re-connect.
97 */ 100 */
98static void 101static void
99reconnect(struct GNUNET_ATS_ApplicationHandle *ch); 102reconnect (struct GNUNET_ATS_ApplicationHandle *ch);
100 103
101 104
102/** 105/**
@@ -105,12 +108,12 @@ reconnect(struct GNUNET_ATS_ApplicationHandle *ch);
105 * @param cls handle to use to re-connect. 108 * @param cls handle to use to re-connect.
106 */ 109 */
107static void 110static void
108reconnect_task(void *cls) 111reconnect_task (void *cls)
109{ 112{
110 struct GNUNET_ATS_ApplicationHandle *ch = cls; 113 struct GNUNET_ATS_ApplicationHandle *ch = cls;
111 114
112 ch->task = NULL; 115 ch->task = NULL;
113 reconnect(ch); 116 reconnect (ch);
114} 117}
115 118
116 119
@@ -120,17 +123,17 @@ reconnect_task(void *cls)
120 * @param ch our handle 123 * @param ch our handle
121 */ 124 */
122static void 125static void
123force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch) 126force_reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
124{ 127{
125 if (NULL != ch->mq) 128 if (NULL != ch->mq)
126 { 129 {
127 GNUNET_MQ_destroy(ch->mq); 130 GNUNET_MQ_destroy (ch->mq);
128 ch->mq = NULL; 131 ch->mq = NULL;
129 } 132 }
130 ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); 133 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
131 ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, 134 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
132 &reconnect_task, 135 &reconnect_task,
133 ch); 136 ch);
134} 137}
135 138
136 139
@@ -142,15 +145,15 @@ force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
142 * @param error details about the error 145 * @param error details about the error
143 */ 146 */
144static void 147static void
145error_handler(void *cls, 148error_handler (void *cls,
146 enum GNUNET_MQ_Error error) 149 enum GNUNET_MQ_Error error)
147{ 150{
148 struct GNUNET_ATS_ApplicationHandle *ch = cls; 151 struct GNUNET_ATS_ApplicationHandle *ch = cls;
149 152
150 LOG(GNUNET_ERROR_TYPE_DEBUG, 153 LOG (GNUNET_ERROR_TYPE_DEBUG,
151 "ATS connection died (code %d), reconnecting\n", 154 "ATS connection died (code %d), reconnecting\n",
152 (int)error); 155 (int) error);
153 force_reconnect(ch); 156 force_reconnect (ch);
154} 157}
155 158
156 159
@@ -164,9 +167,9 @@ error_handler(void *cls,
164 * failure (message queue no longer exists) 167 * failure (message queue no longer exists)
165 */ 168 */
166static int 169static int
167transmit_suggestion(void *cls, 170transmit_suggestion (void *cls,
168 const struct GNUNET_PeerIdentity *peer, 171 const struct GNUNET_PeerIdentity *peer,
169 void *value) 172 void *value)
170{ 173{
171 struct GNUNET_ATS_ApplicationHandle *ch = cls; 174 struct GNUNET_ATS_ApplicationHandle *ch = cls;
172 struct GNUNET_ATS_ApplicationSuggestHandle *sh = value; 175 struct GNUNET_ATS_ApplicationSuggestHandle *sh = value;
@@ -175,12 +178,12 @@ transmit_suggestion(void *cls,
175 178
176 if (NULL == ch->mq) 179 if (NULL == ch->mq)
177 return GNUNET_SYSERR; 180 return GNUNET_SYSERR;
178 ev = GNUNET_MQ_msg(m, 181 ev = GNUNET_MQ_msg (m,
179 GNUNET_MESSAGE_TYPE_ATS_SUGGEST); 182 GNUNET_MESSAGE_TYPE_ATS_SUGGEST);
180 m->pk = htonl((uint32_t)sh->pk); 183 m->pk = htonl ((uint32_t) sh->pk);
181 m->bw = sh->bw; 184 m->bw = sh->bw;
182 m->peer = *peer; 185 m->peer = *peer;
183 GNUNET_MQ_send(ch->mq, ev); 186 GNUNET_MQ_send (ch->mq, ev);
184 return GNUNET_OK; 187 return GNUNET_OK;
185} 188}
186 189
@@ -191,26 +194,26 @@ transmit_suggestion(void *cls,
191 * @param ch handle to use to re-connect. 194 * @param ch handle to use to re-connect.
192 */ 195 */
193static void 196static void
194reconnect(struct GNUNET_ATS_ApplicationHandle *ch) 197reconnect (struct GNUNET_ATS_ApplicationHandle *ch)
195{ 198{
196 static const struct GNUNET_MQ_MessageHandler handlers[] = { 199 static const struct GNUNET_MQ_MessageHandler handlers[] = {
197 { NULL, 0, 0 } 200 { NULL, 0, 0 }
198 }; 201 };
199 202
200 GNUNET_assert(NULL == ch->mq); 203 GNUNET_assert (NULL == ch->mq);
201 ch->mq = GNUNET_CLIENT_connect(ch->cfg, 204 ch->mq = GNUNET_CLIENT_connect (ch->cfg,
202 "ats", 205 "ats",
203 handlers, 206 handlers,
204 &error_handler, 207 &error_handler,
205 ch); 208 ch);
206 if (NULL == ch->mq) 209 if (NULL == ch->mq)
207 { 210 {
208 force_reconnect(ch); 211 force_reconnect (ch);
209 return; 212 return;
210 } 213 }
211 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 214 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
212 &transmit_suggestion, 215 &transmit_suggestion,
213 ch); 216 ch);
214} 217}
215 218
216 219
@@ -221,15 +224,15 @@ reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
221 * @return ats application handle, NULL on error 224 * @return ats application handle, NULL on error
222 */ 225 */
223struct GNUNET_ATS_ApplicationHandle * 226struct GNUNET_ATS_ApplicationHandle *
224GNUNET_ATS_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg) 227GNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
225{ 228{
226 struct GNUNET_ATS_ApplicationHandle *ch; 229 struct GNUNET_ATS_ApplicationHandle *ch;
227 230
228 ch = GNUNET_new(struct GNUNET_ATS_ApplicationHandle); 231 ch = GNUNET_new (struct GNUNET_ATS_ApplicationHandle);
229 ch->cfg = cfg; 232 ch->cfg = cfg;
230 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, 233 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32,
231 GNUNET_YES); 234 GNUNET_YES);
232 reconnect(ch); 235 reconnect (ch);
233 return ch; 236 return ch;
234} 237}
235 238
@@ -244,13 +247,13 @@ GNUNET_ATS_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
244 * @return #GNUNET_OK (continue to iterate) 247 * @return #GNUNET_OK (continue to iterate)
245 */ 248 */
246static int 249static int
247free_sug_handle(void *cls, 250free_sug_handle (void *cls,
248 const struct GNUNET_PeerIdentity *key, 251 const struct GNUNET_PeerIdentity *key,
249 void *value) 252 void *value)
250{ 253{
251 struct GNUNET_ATS_ApplicationSuggestHandle *cur = value; 254 struct GNUNET_ATS_ApplicationSuggestHandle *cur = value;
252 255
253 GNUNET_free(cur); 256 GNUNET_free (cur);
254 return GNUNET_OK; 257 return GNUNET_OK;
255} 258}
256 259
@@ -261,23 +264,23 @@ free_sug_handle(void *cls,
261 * @param ch handle to release 264 * @param ch handle to release
262 */ 265 */
263void 266void
264GNUNET_ATS_application_done(struct GNUNET_ATS_ApplicationHandle *ch) 267GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch)
265{ 268{
266 if (NULL != ch->mq) 269 if (NULL != ch->mq)
267 { 270 {
268 GNUNET_MQ_destroy(ch->mq); 271 GNUNET_MQ_destroy (ch->mq);
269 ch->mq = NULL; 272 ch->mq = NULL;
270 } 273 }
271 if (NULL != ch->task) 274 if (NULL != ch->task)
272 { 275 {
273 GNUNET_SCHEDULER_cancel(ch->task); 276 GNUNET_SCHEDULER_cancel (ch->task);
274 ch->task = NULL; 277 ch->task = NULL;
275 } 278 }
276 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 279 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
277 &free_sug_handle, 280 &free_sug_handle,
278 NULL); 281 NULL);
279 GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); 282 GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests);
280 GNUNET_free(ch); 283 GNUNET_free (ch);
281} 284}
282 285
283 286
@@ -295,31 +298,31 @@ GNUNET_ATS_application_done(struct GNUNET_ATS_ApplicationHandle *ch)
295 * @return suggest handle, NULL if a request is already pending 298 * @return suggest handle, NULL if a request is already pending
296 */ 299 */
297struct GNUNET_ATS_ApplicationSuggestHandle * 300struct GNUNET_ATS_ApplicationSuggestHandle *
298GNUNET_ATS_application_suggest(struct GNUNET_ATS_ApplicationHandle *ch, 301GNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch,
299 const struct GNUNET_PeerIdentity *peer, 302 const struct GNUNET_PeerIdentity *peer,
300 enum GNUNET_MQ_PreferenceKind pk, 303 enum GNUNET_MQ_PreferenceKind pk,
301 struct GNUNET_BANDWIDTH_Value32NBO bw) 304 struct GNUNET_BANDWIDTH_Value32NBO bw)
302{ 305{
303 struct GNUNET_ATS_ApplicationSuggestHandle *s; 306 struct GNUNET_ATS_ApplicationSuggestHandle *s;
304 307
305 s = GNUNET_new(struct GNUNET_ATS_ApplicationSuggestHandle); 308 s = GNUNET_new (struct GNUNET_ATS_ApplicationSuggestHandle);
306 s->ch = ch; 309 s->ch = ch;
307 s->id = *peer; 310 s->id = *peer;
308 s->pk = pk; 311 s->pk = pk;
309 s->bw = bw; 312 s->bw = bw;
310 (void)GNUNET_CONTAINER_multipeermap_put(ch->sug_requests, 313 (void) GNUNET_CONTAINER_multipeermap_put (ch->sug_requests,
311 &s->id, 314 &s->id,
312 s, 315 s,
313 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 316 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
314 LOG(GNUNET_ERROR_TYPE_DEBUG, 317 LOG (GNUNET_ERROR_TYPE_DEBUG,
315 "Requesting ATS to suggest address for `%s'\n", 318 "Requesting ATS to suggest address for `%s'\n",
316 GNUNET_i2s(peer)); 319 GNUNET_i2s (peer));
317 if (NULL == ch->mq) 320 if (NULL == ch->mq)
318 return s; 321 return s;
319 GNUNET_assert(GNUNET_OK == 322 GNUNET_assert (GNUNET_OK ==
320 transmit_suggestion(ch, 323 transmit_suggestion (ch,
321 &s->id, 324 &s->id,
322 s)); 325 s));
323 return s; 326 return s;
324} 327}
325 328
@@ -330,32 +333,33 @@ GNUNET_ATS_application_suggest(struct GNUNET_ATS_ApplicationHandle *ch,
330 * @param sh handle to stop 333 * @param sh handle to stop
331 */ 334 */
332void 335void
333GNUNET_ATS_application_suggest_cancel(struct GNUNET_ATS_ApplicationSuggestHandle *sh) 336GNUNET_ATS_application_suggest_cancel (struct
337 GNUNET_ATS_ApplicationSuggestHandle *sh)
334{ 338{
335 struct GNUNET_ATS_ApplicationHandle *ch = sh->ch; 339 struct GNUNET_ATS_ApplicationHandle *ch = sh->ch;
336 struct GNUNET_MQ_Envelope *ev; 340 struct GNUNET_MQ_Envelope *ev;
337 struct ExpressPreferenceMessage *m; 341 struct ExpressPreferenceMessage *m;
338 342
339 LOG(GNUNET_ERROR_TYPE_DEBUG, 343 LOG (GNUNET_ERROR_TYPE_DEBUG,
340 "Telling ATS we no longer care for an address for `%s'\n", 344 "Telling ATS we no longer care for an address for `%s'\n",
341 GNUNET_i2s(&sh->id)); 345 GNUNET_i2s (&sh->id));
342 GNUNET_assert(GNUNET_OK == 346 GNUNET_assert (GNUNET_OK ==
343 GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, 347 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests,
344 &sh->id, 348 &sh->id,
345 sh)); 349 sh));
346 if (NULL == ch->mq) 350 if (NULL == ch->mq)
347 { 351 {
348 GNUNET_free(sh); 352 GNUNET_free (sh);
349 return; 353 return;
350 } 354 }
351 ev = GNUNET_MQ_msg(m, 355 ev = GNUNET_MQ_msg (m,
352 GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL); 356 GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL);
353 m->pk = htonl((uint32_t)sh->pk); 357 m->pk = htonl ((uint32_t) sh->pk);
354 m->bw = sh->bw; 358 m->bw = sh->bw;
355 m->peer = sh->id; 359 m->peer = sh->id;
356 GNUNET_MQ_send(ch->mq, 360 GNUNET_MQ_send (ch->mq,
357 ev); 361 ev);
358 GNUNET_free(sh); 362 GNUNET_free (sh);
359} 363}
360 364
361 365
diff --git a/src/ats/ats_api2_transport.c b/src/ats/ats_api2_transport.c
index 441e7c8c2..da02ca592 100644
--- a/src/ats/ats_api2_transport.c
+++ b/src/ats/ats_api2_transport.c
@@ -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,7 +35,8 @@
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 */
38struct GNUNET_ATS_SessionRecord { 38struct GNUNET_ATS_SessionRecord
39{
39 /** 40 /**
40 * Transport handle this session record belongs to. 41 * Transport handle this session record belongs to.
41 */ 42 */
@@ -79,7 +80,8 @@ struct GNUNET_ATS_SessionRecord {
79/** 80/**
80 * Handle to the ATS subsystem for bandwidth/transport transport information. 81 * Handle to the ATS subsystem for bandwidth/transport transport information.
81 */ 82 */
82struct GNUNET_ATS_TransportHandle { 83struct GNUNET_ATS_TransportHandle
84{
83 /** 85 /**
84 * Our configuration. 86 * Our configuration.
85 */ 87 */
@@ -135,18 +137,18 @@ struct GNUNET_ATS_TransportHandle {
135 * @param hbo value read 137 * @param hbo value read
136 */ 138 */
137static void 139static void
138properties_hton(struct PropertiesNBO *nbo, 140properties_hton (struct PropertiesNBO *nbo,
139 const struct GNUNET_ATS_Properties *hbo) 141 const struct GNUNET_ATS_Properties *hbo)
140{ 142{
141 nbo->delay = GNUNET_TIME_relative_hton(hbo->delay); 143 nbo->delay = GNUNET_TIME_relative_hton (hbo->delay);
142 nbo->goodput_out = htonl(hbo->goodput_out); 144 nbo->goodput_out = htonl (hbo->goodput_out);
143 nbo->goodput_in = htonl(hbo->goodput_in); 145 nbo->goodput_in = htonl (hbo->goodput_in);
144 nbo->utilization_out = htonl(hbo->utilization_out); 146 nbo->utilization_out = htonl (hbo->utilization_out);
145 nbo->utilization_in = htonl(hbo->utilization_in); 147 nbo->utilization_in = htonl (hbo->utilization_in);
146 nbo->distance = htonl(hbo->distance); 148 nbo->distance = htonl (hbo->distance);
147 nbo->mtu = htonl(hbo->mtu); 149 nbo->mtu = htonl (hbo->mtu);
148 nbo->nt = htonl((uint32_t)hbo->nt); 150 nbo->nt = htonl ((uint32_t) hbo->nt);
149 nbo->cc = htonl((uint32_t)hbo->cc); 151 nbo->cc = htonl ((uint32_t) hbo->cc);
150} 152}
151 153
152 154
@@ -156,7 +158,7 @@ properties_hton(struct PropertiesNBO *nbo,
156 * @param sh handle to use to re-connect. 158 * @param sh handle to use to re-connect.
157 */ 159 */
158static void 160static void
159reconnect(struct GNUNET_ATS_TransportHandle *ath); 161reconnect (struct GNUNET_ATS_TransportHandle *ath);
160 162
161 163
162/** 164/**
@@ -165,12 +167,12 @@ reconnect(struct GNUNET_ATS_TransportHandle *ath);
165 * @param cls handle to use to re-connect. 167 * @param cls handle to use to re-connect.
166 */ 168 */
167static void 169static void
168reconnect_task(void *cls) 170reconnect_task (void *cls)
169{ 171{
170 struct GNUNET_ATS_TransportHandle *ath = cls; 172 struct GNUNET_ATS_TransportHandle *ath = cls;
171 173
172 ath->task = NULL; 174 ath->task = NULL;
173 reconnect(ath); 175 reconnect (ath);
174} 176}
175 177
176 178
@@ -180,22 +182,22 @@ reconnect_task(void *cls)
180 * @param ath our handle 182 * @param ath our handle
181 */ 183 */
182static void 184static void
183force_reconnect(struct GNUNET_ATS_TransportHandle *ath) 185force_reconnect (struct GNUNET_ATS_TransportHandle *ath)
184{ 186{
185 if (NULL != ath->mq) 187 if (NULL != ath->mq)
186 { 188 {
187 GNUNET_MQ_destroy(ath->mq); 189 GNUNET_MQ_destroy (ath->mq);
188 ath->mq = NULL; 190 ath->mq = NULL;
189 } 191 }
190 /* FIXME: do we tell transport service about disconnect events? CON: 192 /* FIXME: do we tell transport service about disconnect events? CON:
191 initially ATS will have a really screwed picture of the world and 193 initially ATS will have a really screwed picture of the world and
192 the rapid change would be bad. PRO: if we don't, ATS and 194 the rapid change would be bad. PRO: if we don't, ATS and
193 transport may disagree about the allocation for a while... 195 transport may disagree about the allocation for a while...
194 For now: lazy: do nothing. */ 196 For now: lazy: do nothing. */
195 ath->backoff = GNUNET_TIME_STD_BACKOFF(ath->backoff); 197 ath->backoff = GNUNET_TIME_STD_BACKOFF (ath->backoff);
196 ath->task = GNUNET_SCHEDULER_add_delayed(ath->backoff, 198 ath->task = GNUNET_SCHEDULER_add_delayed (ath->backoff,
197 &reconnect_task, 199 &reconnect_task,
198 ath); 200 ath);
199} 201}
200 202
201 203
@@ -206,11 +208,11 @@ force_reconnect(struct GNUNET_ATS_TransportHandle *ath)
206 * @param m message received 208 * @param m message received
207 */ 209 */
208static int 210static int
209check_ats_address_suggestion(void *cls, 211check_ats_address_suggestion (void *cls,
210 const struct AddressSuggestionMessage *m) 212 const struct AddressSuggestionMessage *m)
211{ 213{
212 (void)cls; 214 (void) cls;
213 GNUNET_MQ_check_zero_termination(m); 215 GNUNET_MQ_check_zero_termination (m);
214 return GNUNET_SYSERR; 216 return GNUNET_SYSERR;
215} 217}
216 218
@@ -222,22 +224,23 @@ check_ats_address_suggestion(void *cls,
222 * @param m message received 224 * @param m message received
223 */ 225 */
224static void 226static void
225handle_ats_address_suggestion(void *cls, 227handle_ats_address_suggestion (void *cls,
226 const struct AddressSuggestionMessage *m) 228 const struct AddressSuggestionMessage *m)
227{ 229{
228 struct GNUNET_ATS_TransportHandle *ath = cls; 230 struct GNUNET_ATS_TransportHandle *ath = cls;
229 const char *address = (const char *)&m[1]; 231 const char *address = (const char *) &m[1];
230 232
231 ath->suggest_cb(ath->suggest_cb_cls, 233 ath->suggest_cb (ath->suggest_cb_cls,
232 &m->peer, 234 &m->peer,
233 address); 235 address);
234} 236}
235 237
236 238
237/** 239/**
238 * Closure for #match_session_cb. 240 * Closure for #match_session_cb.
239 */ 241 */
240struct FindContext { 242struct FindContext
243{
241 /** 244 /**
242 * Key to look for. 245 * Key to look for.
243 */ 246 */
@@ -259,19 +262,19 @@ struct FindContext {
259 * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching 262 * @return #GNUNET_NO if match found, #GNUNET_YES to continue searching
260 */ 263 */
261static int 264static int
262match_session_cb(void *cls, 265match_session_cb (void *cls,
263 const struct GNUNET_PeerIdentity *pid, 266 const struct GNUNET_PeerIdentity *pid,
264 void *value) 267 void *value)
265{ 268{
266 struct FindContext *fc = cls; 269 struct FindContext *fc = cls;
267 struct GNUNET_ATS_SessionRecord *sr = value; 270 struct GNUNET_ATS_SessionRecord *sr = value;
268 271
269 (void)pid; 272 (void) pid;
270 if (fc->session_id == sr->slot) 273 if (fc->session_id == sr->slot)
271 { 274 {
272 fc->sr = sr; 275 fc->sr = sr;
273 return GNUNET_NO; 276 return GNUNET_NO;
274 } 277 }
275 return GNUNET_YES; 278 return GNUNET_YES;
276} 279}
277 280
@@ -286,19 +289,19 @@ match_session_cb(void *cls,
286 * @return NULL if no such record exists 289 * @return NULL if no such record exists
287 */ 290 */
288static struct GNUNET_ATS_SessionRecord * 291static struct GNUNET_ATS_SessionRecord *
289find_session(struct GNUNET_ATS_TransportHandle *ath, 292find_session (struct GNUNET_ATS_TransportHandle *ath,
290 uint32_t session_id, 293 uint32_t session_id,
291 const struct GNUNET_PeerIdentity *pid) 294 const struct GNUNET_PeerIdentity *pid)
292{ 295{
293 struct FindContext fc = { 296 struct FindContext fc = {
294 .session_id = session_id, 297 .session_id = session_id,
295 .sr = NULL 298 .sr = NULL
296 }; 299 };
297 300
298 GNUNET_CONTAINER_multipeermap_get_multiple(ath->records, 301 GNUNET_CONTAINER_multipeermap_get_multiple (ath->records,
299 pid, 302 pid,
300 &match_session_cb, 303 &match_session_cb,
301 &fc); 304 &fc);
302 return fc.sr; 305 return fc.sr;
303} 306}
304 307
@@ -310,34 +313,34 @@ find_session(struct GNUNET_ATS_TransportHandle *ath,
310 * @param m message received 313 * @param m message received
311 */ 314 */
312static void 315static void
313handle_ats_session_allocation(void *cls, 316handle_ats_session_allocation (void *cls,
314 const struct SessionAllocationMessage *m) 317 const struct SessionAllocationMessage *m)
315{ 318{
316 struct GNUNET_ATS_TransportHandle *ath = cls; 319 struct GNUNET_ATS_TransportHandle *ath = cls;
317 struct GNUNET_ATS_SessionRecord *ar; 320 struct GNUNET_ATS_SessionRecord *ar;
318 uint32_t session_id; 321 uint32_t session_id;
319 322
320 session_id = ntohl(m->session_id); 323 session_id = ntohl (m->session_id);
321 ar = find_session(ath, 324 ar = find_session (ath,
322 session_id, 325 session_id,
323 &m->peer); 326 &m->peer);
324 if (NULL == ar) 327 if (NULL == ar)
325 { 328 {
326 /* this can (rarely) happen if ATS changes an sessiones allocation 329 /* this can (rarely) happen if ATS changes an sessiones allocation
327 just when the transport service deleted it */ 330 just when the transport service deleted it */
328 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 331 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
329 "Allocation ignored, session unknown\n"); 332 "Allocation ignored, session unknown\n");
330 return; 333 return;
331 } 334 }
332 ath->backoff = GNUNET_TIME_UNIT_ZERO; 335 ath->backoff = GNUNET_TIME_UNIT_ZERO;
333 LOG(GNUNET_ERROR_TYPE_DEBUG, 336 LOG (GNUNET_ERROR_TYPE_DEBUG,
334 "ATS allocates bandwidth for peer `%s' using address %s\n", 337 "ATS allocates bandwidth for peer `%s' using address %s\n",
335 GNUNET_i2s(&ar->pid), 338 GNUNET_i2s (&ar->pid),
336 ar->address); 339 ar->address);
337 ath->alloc_cb(ath->alloc_cb_cls, 340 ath->alloc_cb (ath->alloc_cb_cls,
338 ar->session, 341 ar->session,
339 m->bandwidth_out, 342 m->bandwidth_out,
340 m->bandwidth_in); 343 m->bandwidth_in);
341} 344}
342 345
343 346
@@ -349,15 +352,15 @@ handle_ats_session_allocation(void *cls,
349 * @param error details about the error 352 * @param error details about the error
350 */ 353 */
351static void 354static void
352error_handler(void *cls, 355error_handler (void *cls,
353 enum GNUNET_MQ_Error error) 356 enum GNUNET_MQ_Error error)
354{ 357{
355 struct GNUNET_ATS_TransportHandle *ath = cls; 358 struct GNUNET_ATS_TransportHandle *ath = cls;
356 359
357 LOG(GNUNET_ERROR_TYPE_DEBUG, 360 LOG (GNUNET_ERROR_TYPE_DEBUG,
358 "ATS connection died (code %d), reconnecting\n", 361 "ATS connection died (code %d), reconnecting\n",
359 (int)error); 362 (int) error);
360 force_reconnect(ath); 363 force_reconnect (ath);
361} 364}
362 365
363 366
@@ -368,7 +371,7 @@ error_handler(void *cls,
368 * @param ar the session to inform the ATS service about 371 * @param ar the session to inform the ATS service about
369 */ 372 */
370static void 373static void
371send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar) 374send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
372{ 375{
373 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 376 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
374 struct GNUNET_MQ_Envelope *ev; 377 struct GNUNET_MQ_Envelope *ev;
@@ -377,26 +380,26 @@ send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar)
377 380
378 if (NULL == ath->mq) 381 if (NULL == ath->mq)
379 return; /* disconnected, skip for now */ 382 return; /* disconnected, skip for now */
380 alen = strlen(ar->address) + 1; 383 alen = strlen (ar->address) + 1;
381 ev = GNUNET_MQ_msg_extra(m, 384 ev = GNUNET_MQ_msg_extra (m,
382 alen, 385 alen,
383 (NULL == ar->session) 386 (NULL == ar->session)
384 ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY 387 ? GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
385 : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD); 388 : GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD);
386 m->peer = ar->pid; 389 m->peer = ar->pid;
387 m->session_id = htonl(ar->slot); 390 m->session_id = htonl (ar->slot);
388 properties_hton(&m->properties, 391 properties_hton (&m->properties,
389 &ar->properties); 392 &ar->properties);
390 GNUNET_memcpy(&m[1], 393 GNUNET_memcpy (&m[1],
391 ar->address, 394 ar->address,
392 alen); 395 alen);
393 396
394 LOG(GNUNET_ERROR_TYPE_DEBUG, 397 LOG (GNUNET_ERROR_TYPE_DEBUG,
395 "Adding address `%s' for peer `%s'\n", 398 "Adding address `%s' for peer `%s'\n",
396 ar->address, 399 ar->address,
397 GNUNET_i2s(&ar->pid)); 400 GNUNET_i2s (&ar->pid));
398 GNUNET_MQ_send(ath->mq, 401 GNUNET_MQ_send (ath->mq,
399 ev); 402 ev);
400} 403}
401 404
402 405
@@ -409,15 +412,15 @@ send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar)
409 * @return #GNUNET_OK 412 * @return #GNUNET_OK
410 */ 413 */
411static int 414static int
412send_add_session_cb(void *cls, 415send_add_session_cb (void *cls,
413 const struct GNUNET_PeerIdentity *pid, 416 const struct GNUNET_PeerIdentity *pid,
414 void *value) 417 void *value)
415{ 418{
416 struct GNUNET_ATS_SessionRecord *ar = value; 419 struct GNUNET_ATS_SessionRecord *ar = value;
417 420
418 (void)cls; 421 (void) cls;
419 (void)pid; 422 (void) pid;
420 send_add_session_message(ar); 423 send_add_session_message (ar);
421 return GNUNET_OK; 424 return GNUNET_OK;
422} 425}
423 426
@@ -428,43 +431,43 @@ send_add_session_cb(void *cls,
428 * @param ath handle to use to re-connect. 431 * @param ath handle to use to re-connect.
429 */ 432 */
430static void 433static void
431reconnect(struct GNUNET_ATS_TransportHandle *ath) 434reconnect (struct GNUNET_ATS_TransportHandle *ath)
432{ 435{
433 struct GNUNET_MQ_MessageHandler handlers[] = { 436 struct GNUNET_MQ_MessageHandler handlers[] = {
434 GNUNET_MQ_hd_var_size(ats_address_suggestion, 437 GNUNET_MQ_hd_var_size (ats_address_suggestion,
435 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, 438 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
436 struct AddressSuggestionMessage, 439 struct AddressSuggestionMessage,
437 ath), 440 ath),
438 GNUNET_MQ_hd_fixed_size(ats_session_allocation, 441 GNUNET_MQ_hd_fixed_size (ats_session_allocation,
439 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION, 442 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION,
440 struct SessionAllocationMessage, 443 struct SessionAllocationMessage,
441 ath), 444 ath),
442 GNUNET_MQ_handler_end() 445 GNUNET_MQ_handler_end ()
443 }; 446 };
444 struct GNUNET_MQ_Envelope *ev; 447 struct GNUNET_MQ_Envelope *ev;
445 struct GNUNET_MessageHeader *init; 448 struct GNUNET_MessageHeader *init;
446 449
447 GNUNET_assert(NULL == ath->mq); 450 GNUNET_assert (NULL == ath->mq);
448 ath->mq = GNUNET_CLIENT_connect(ath->cfg, 451 ath->mq = GNUNET_CLIENT_connect (ath->cfg,
449 "ats", 452 "ats",
450 handlers, 453 handlers,
451 &error_handler, 454 &error_handler,
452 ath); 455 ath);
453 if (NULL == ath->mq) 456 if (NULL == ath->mq)
454 { 457 {
455 GNUNET_break(0); 458 GNUNET_break (0);
456 force_reconnect(ath); 459 force_reconnect (ath);
457 return; 460 return;
458 } 461 }
459 ev = GNUNET_MQ_msg(init, 462 ev = GNUNET_MQ_msg (init,
460 GNUNET_MESSAGE_TYPE_ATS_START); 463 GNUNET_MESSAGE_TYPE_ATS_START);
461 GNUNET_MQ_send(ath->mq, 464 GNUNET_MQ_send (ath->mq,
462 ev); 465 ev);
463 if (NULL == ath->mq) 466 if (NULL == ath->mq)
464 return; 467 return;
465 GNUNET_CONTAINER_multipeermap_iterate(ath->records, 468 GNUNET_CONTAINER_multipeermap_iterate (ath->records,
466 &send_add_session_cb, 469 &send_add_session_cb,
467 ath); 470 ath);
468} 471}
469 472
470 473
@@ -479,23 +482,23 @@ reconnect(struct GNUNET_ATS_TransportHandle *ath)
479 * @return ats context 482 * @return ats context
480 */ 483 */
481struct GNUNET_ATS_TransportHandle * 484struct GNUNET_ATS_TransportHandle *
482GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg, 485GNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
483 GNUNET_ATS_AllocationCallback alloc_cb, 486 GNUNET_ATS_AllocationCallback alloc_cb,
484 void *alloc_cb_cls, 487 void *alloc_cb_cls,
485 GNUNET_ATS_SuggestionCallback suggest_cb, 488 GNUNET_ATS_SuggestionCallback suggest_cb,
486 void *suggest_cb_cls) 489 void *suggest_cb_cls)
487{ 490{
488 struct GNUNET_ATS_TransportHandle *ath; 491 struct GNUNET_ATS_TransportHandle *ath;
489 492
490 ath = GNUNET_new(struct GNUNET_ATS_TransportHandle); 493 ath = GNUNET_new (struct GNUNET_ATS_TransportHandle);
491 ath->cfg = cfg; 494 ath->cfg = cfg;
492 ath->suggest_cb = suggest_cb; 495 ath->suggest_cb = suggest_cb;
493 ath->suggest_cb_cls = suggest_cb_cls; 496 ath->suggest_cb_cls = suggest_cb_cls;
494 ath->alloc_cb = alloc_cb; 497 ath->alloc_cb = alloc_cb;
495 ath->alloc_cb_cls = alloc_cb_cls; 498 ath->alloc_cb_cls = alloc_cb_cls;
496 ath->records = GNUNET_CONTAINER_multipeermap_create(128, 499 ath->records = GNUNET_CONTAINER_multipeermap_create (128,
497 GNUNET_YES); 500 GNUNET_YES);
498 reconnect(ath); 501 reconnect (ath);
499 return ath; 502 return ath;
500} 503}
501 504
@@ -509,15 +512,15 @@ GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
509 * @return #GNUNET_OK 512 * @return #GNUNET_OK
510 */ 513 */
511static int 514static int
512free_record(void *cls, 515free_record (void *cls,
513 const struct GNUNET_PeerIdentity *pid, 516 const struct GNUNET_PeerIdentity *pid,
514 void *value) 517 void *value)
515{ 518{
516 struct GNUNET_ATS_SessionRecord *ar = value; 519 struct GNUNET_ATS_SessionRecord *ar = value;
517 520
518 (void)cls; 521 (void) cls;
519 (void)pid; 522 (void) pid;
520 GNUNET_free(ar); 523 GNUNET_free (ar);
521 return GNUNET_OK; 524 return GNUNET_OK;
522} 525}
523 526
@@ -528,23 +531,23 @@ free_record(void *cls,
528 * @param ath handle to release 531 * @param ath handle to release
529 */ 532 */
530void 533void
531GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath) 534GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath)
532{ 535{
533 if (NULL != ath->mq) 536 if (NULL != ath->mq)
534 { 537 {
535 GNUNET_MQ_destroy(ath->mq); 538 GNUNET_MQ_destroy (ath->mq);
536 ath->mq = NULL; 539 ath->mq = NULL;
537 } 540 }
538 if (NULL != ath->task) 541 if (NULL != ath->task)
539 { 542 {
540 GNUNET_SCHEDULER_cancel(ath->task); 543 GNUNET_SCHEDULER_cancel (ath->task);
541 ath->task = NULL; 544 ath->task = NULL;
542 } 545 }
543 GNUNET_CONTAINER_multipeermap_iterate(ath->records, 546 GNUNET_CONTAINER_multipeermap_iterate (ath->records,
544 &free_record, 547 &free_record,
545 NULL); 548 NULL);
546 GNUNET_CONTAINER_multipeermap_destroy(ath->records); 549 GNUNET_CONTAINER_multipeermap_destroy (ath->records);
547 GNUNET_free(ath); 550 GNUNET_free (ath);
548} 551}
549 552
550 553
@@ -563,56 +566,56 @@ GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath)
563 * on error (i.e. ATS knows this exact session already) 566 * on error (i.e. ATS knows this exact session already)
564 */ 567 */
565struct GNUNET_ATS_SessionRecord * 568struct GNUNET_ATS_SessionRecord *
566GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath, 569GNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath,
567 const struct GNUNET_PeerIdentity *pid, 570 const struct GNUNET_PeerIdentity *pid,
568 const char *address, 571 const char *address,
569 struct GNUNET_ATS_Session *session, 572 struct GNUNET_ATS_Session *session,
570 const struct GNUNET_ATS_Properties *prop) 573 const struct GNUNET_ATS_Properties *prop)
571{ 574{
572 struct GNUNET_ATS_SessionRecord *ar; 575 struct GNUNET_ATS_SessionRecord *ar;
573 uint32_t s; 576 uint32_t s;
574 size_t alen; 577 size_t alen;
575 578
576 if (NULL == address) 579 if (NULL == address)
577 { 580 {
578 /* we need a valid address */ 581 /* we need a valid address */
579 GNUNET_break(0); 582 GNUNET_break (0);
580 return NULL; 583 return NULL;
581 } 584 }
582 alen = strlen(address) + 1; 585 alen = strlen (address) + 1;
583 if ((alen + sizeof(struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 586 if ((alen + sizeof(struct SessionAddMessage) >= GNUNET_MAX_MESSAGE_SIZE) ||
584 (alen >= GNUNET_MAX_MESSAGE_SIZE)) 587 (alen >= GNUNET_MAX_MESSAGE_SIZE))
585 { 588 {
586 /* address too large for us, this should not happen */ 589 /* address too large for us, this should not happen */
587 GNUNET_break(0); 590 GNUNET_break (0);
588 return NULL; 591 return NULL;
589 } 592 }
590 593
591 /* Spin 's' until we find an unused session ID for this pid */ 594 /* Spin 's' until we find an unused session ID for this pid */
592 for (s = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 595 for (s = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
593 UINT32_MAX); 596 UINT32_MAX);
594 NULL != find_session(ath, 597 NULL != find_session (ath,
595 s, 598 s,
596 pid); 599 pid);
597 s++) 600 s++)
598 ; 601 ;
599 602
600 alen = strlen(address) + 1; 603 alen = strlen (address) + 1;
601 ar = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionRecord) + alen); 604 ar = GNUNET_malloc (sizeof(struct GNUNET_ATS_SessionRecord) + alen);
602 ar->ath = ath; 605 ar->ath = ath;
603 ar->slot = s; 606 ar->slot = s;
604 ar->session = session; 607 ar->session = session;
605 ar->address = (const char *)&ar[1]; 608 ar->address = (const char *) &ar[1];
606 ar->pid = *pid; 609 ar->pid = *pid;
607 ar->properties = *prop; 610 ar->properties = *prop;
608 memcpy(&ar[1], 611 memcpy (&ar[1],
609 address, 612 address,
610 alen); 613 alen);
611 (void)GNUNET_CONTAINER_multipeermap_put(ath->records, 614 (void) GNUNET_CONTAINER_multipeermap_put (ath->records,
612 &ar->pid, 615 &ar->pid,
613 ar, 616 ar,
614 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 617 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
615 send_add_session_message(ar); 618 send_add_session_message (ar);
616 return ar; 619 return ar;
617} 620}
618 621
@@ -629,28 +632,28 @@ GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath,
629 * @param prop performance data for the session 632 * @param prop performance data for the session
630 */ 633 */
631void 634void
632GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar, 635GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar,
633 const struct GNUNET_ATS_Properties *prop) 636 const struct GNUNET_ATS_Properties *prop)
634{ 637{
635 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 638 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
636 struct GNUNET_MQ_Envelope *ev; 639 struct GNUNET_MQ_Envelope *ev;
637 struct SessionUpdateMessage *m; 640 struct SessionUpdateMessage *m;
638 641
639 LOG(GNUNET_ERROR_TYPE_DEBUG, 642 LOG (GNUNET_ERROR_TYPE_DEBUG,
640 "Updating address `%s' for peer `%s'\n", 643 "Updating address `%s' for peer `%s'\n",
641 ar->address, 644 ar->address,
642 GNUNET_i2s(&ar->pid)); 645 GNUNET_i2s (&ar->pid));
643 ar->properties = *prop; 646 ar->properties = *prop;
644 if (NULL == ath->mq) 647 if (NULL == ath->mq)
645 return; /* disconnected, skip for now */ 648 return; /* disconnected, skip for now */
646 ev = GNUNET_MQ_msg(m, 649 ev = GNUNET_MQ_msg (m,
647 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE); 650 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE);
648 m->session_id = htonl(ar->slot); 651 m->session_id = htonl (ar->slot);
649 m->peer = ar->pid; 652 m->peer = ar->pid;
650 properties_hton(&m->properties, 653 properties_hton (&m->properties,
651 &ar->properties); 654 &ar->properties);
652 GNUNET_MQ_send(ath->mq, 655 GNUNET_MQ_send (ath->mq,
653 ev); 656 ev);
654} 657}
655 658
656 659
@@ -662,24 +665,24 @@ GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar,
662 * @param ar session record to drop 665 * @param ar session record to drop
663 */ 666 */
664void 667void
665GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar) 668GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar)
666{ 669{
667 struct GNUNET_ATS_TransportHandle *ath = ar->ath; 670 struct GNUNET_ATS_TransportHandle *ath = ar->ath;
668 struct GNUNET_MQ_Envelope *ev; 671 struct GNUNET_MQ_Envelope *ev;
669 struct SessionDelMessage *m; 672 struct SessionDelMessage *m;
670 673
671 LOG(GNUNET_ERROR_TYPE_DEBUG, 674 LOG (GNUNET_ERROR_TYPE_DEBUG,
672 "Deleting address `%s' for peer `%s'\n", 675 "Deleting address `%s' for peer `%s'\n",
673 ar->address, 676 ar->address,
674 GNUNET_i2s(&ar->pid)); 677 GNUNET_i2s (&ar->pid));
675 if (NULL == ath->mq) 678 if (NULL == ath->mq)
676 return; 679 return;
677 ev = GNUNET_MQ_msg(m, 680 ev = GNUNET_MQ_msg (m,
678 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL); 681 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL);
679 m->session_id = htonl(ar->slot); 682 m->session_id = htonl (ar->slot);
680 m->peer = ar->pid; 683 m->peer = ar->pid;
681 GNUNET_MQ_send(ath->mq, 684 GNUNET_MQ_send (ath->mq,
682 ev); 685 ev);
683} 686}
684 687
685 688
diff --git a/src/ats/ats_api_connectivity.c b/src/ats/ats_api_connectivity.c
index 2ff734c25..1b8e82777 100644
--- a/src/ats/ats_api_connectivity.c
+++ b/src/ats/ats_api_connectivity.c
@@ -28,13 +28,15 @@
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", \
32 __VA_ARGS__)
32 33
33 34
34/** 35/**
35 * Handle for ATS address suggestion requests. 36 * Handle for ATS address suggestion requests.
36 */ 37 */
37struct GNUNET_ATS_ConnectivitySuggestHandle { 38struct GNUNET_ATS_ConnectivitySuggestHandle
39{
38 /** 40 /**
39 * ID of the peer for which address suggestion was requested. 41 * ID of the peer for which address suggestion was requested.
40 */ 42 */
@@ -55,7 +57,8 @@ struct GNUNET_ATS_ConnectivitySuggestHandle {
55/** 57/**
56 * Handle to the ATS subsystem for connectivity management. 58 * Handle to the ATS subsystem for connectivity management.
57 */ 59 */
58struct GNUNET_ATS_ConnectivityHandle { 60struct GNUNET_ATS_ConnectivityHandle
61{
59 /** 62 /**
60 * Our configuration. 63 * Our configuration.
61 */ 64 */
@@ -91,7 +94,7 @@ struct GNUNET_ATS_ConnectivityHandle {
91 * @param ch handle to use to re-connect. 94 * @param ch handle to use to re-connect.
92 */ 95 */
93static void 96static void
94reconnect(struct GNUNET_ATS_ConnectivityHandle *ch); 97reconnect (struct GNUNET_ATS_ConnectivityHandle *ch);
95 98
96 99
97/** 100/**
@@ -100,12 +103,12 @@ reconnect(struct GNUNET_ATS_ConnectivityHandle *ch);
100 * @param cls handle to use to re-connect. 103 * @param cls handle to use to re-connect.
101 */ 104 */
102static void 105static void
103reconnect_task(void *cls) 106reconnect_task (void *cls)
104{ 107{
105 struct GNUNET_ATS_ConnectivityHandle *ch = cls; 108 struct GNUNET_ATS_ConnectivityHandle *ch = cls;
106 109
107 ch->task = NULL; 110 ch->task = NULL;
108 reconnect(ch); 111 reconnect (ch);
109} 112}
110 113
111 114
@@ -115,17 +118,17 @@ reconnect_task(void *cls)
115 * @param ch our handle 118 * @param ch our handle
116 */ 119 */
117static void 120static void
118force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) 121force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
119{ 122{
120 if (NULL != ch->mq) 123 if (NULL != ch->mq)
121 { 124 {
122 GNUNET_MQ_destroy(ch->mq); 125 GNUNET_MQ_destroy (ch->mq);
123 ch->mq = NULL; 126 ch->mq = NULL;
124 } 127 }
125 ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff); 128 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
126 ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, 129 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
127 &reconnect_task, 130 &reconnect_task,
128 ch); 131 ch);
129} 132}
130 133
131 134
@@ -137,15 +140,15 @@ force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
137 * @param error details about the error 140 * @param error details about the error
138 */ 141 */
139static void 142static void
140error_handler(void *cls, 143error_handler (void *cls,
141 enum GNUNET_MQ_Error error) 144 enum GNUNET_MQ_Error error)
142{ 145{
143 struct GNUNET_ATS_ConnectivityHandle *ch = cls; 146 struct GNUNET_ATS_ConnectivityHandle *ch = cls;
144 147
145 LOG(GNUNET_ERROR_TYPE_DEBUG, 148 LOG (GNUNET_ERROR_TYPE_DEBUG,
146 "ATS connection died (code %d), reconnecting\n", 149 "ATS connection died (code %d), reconnecting\n",
147 (int)error); 150 (int) error);
148 force_reconnect(ch); 151 force_reconnect (ch);
149} 152}
150 153
151 154
@@ -159,9 +162,9 @@ error_handler(void *cls,
159 * failure (message queue no longer exists) 162 * failure (message queue no longer exists)
160 */ 163 */
161static int 164static int
162transmit_suggestion(void *cls, 165transmit_suggestion (void *cls,
163 const struct GNUNET_PeerIdentity *peer, 166 const struct GNUNET_PeerIdentity *peer,
164 void *value) 167 void *value)
165{ 168{
166 struct GNUNET_ATS_ConnectivityHandle *ch = cls; 169 struct GNUNET_ATS_ConnectivityHandle *ch = cls;
167 struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value; 170 struct GNUNET_ATS_ConnectivitySuggestHandle *sh = value;
@@ -170,10 +173,10 @@ transmit_suggestion(void *cls,
170 173
171 if (NULL == ch->mq) 174 if (NULL == ch->mq)
172 return GNUNET_SYSERR; 175 return GNUNET_SYSERR;
173 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS); 176 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS);
174 m->strength = htonl(sh->strength); 177 m->strength = htonl (sh->strength);
175 m->peer = *peer; 178 m->peer = *peer;
176 GNUNET_MQ_send(ch->mq, ev); 179 GNUNET_MQ_send (ch->mq, ev);
177 return GNUNET_OK; 180 return GNUNET_OK;
178} 181}
179 182
@@ -184,33 +187,33 @@ transmit_suggestion(void *cls,
184 * @param ch handle to use to re-connect. 187 * @param ch handle to use to re-connect.
185 */ 188 */
186static void 189static void
187reconnect(struct GNUNET_ATS_ConnectivityHandle *ch) 190reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
188{ 191{
189 static const struct GNUNET_MQ_MessageHandler handlers[] = 192 static const struct GNUNET_MQ_MessageHandler handlers[] =
190 { { NULL, 0, 0 } }; 193 { { NULL, 0, 0 } };
191 struct GNUNET_MQ_Envelope *ev; 194 struct GNUNET_MQ_Envelope *ev;
192 struct ClientStartMessage *init; 195 struct ClientStartMessage *init;
193 196
194 GNUNET_assert(NULL == ch->mq); 197 GNUNET_assert (NULL == ch->mq);
195 ch->mq = GNUNET_CLIENT_connect(ch->cfg, 198 ch->mq = GNUNET_CLIENT_connect (ch->cfg,
196 "ats", 199 "ats",
197 handlers, 200 handlers,
198 &error_handler, 201 &error_handler,
199 ch); 202 ch);
200 if (NULL == ch->mq) 203 if (NULL == ch->mq)
201 { 204 {
202 force_reconnect(ch); 205 force_reconnect (ch);
203 return; 206 return;
204 } 207 }
205 ev = GNUNET_MQ_msg(init, 208 ev = GNUNET_MQ_msg (init,
206 GNUNET_MESSAGE_TYPE_ATS_START); 209 GNUNET_MESSAGE_TYPE_ATS_START);
207 init->start_flag = htonl(START_FLAG_CONNECTION_SUGGESTION); 210 init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION);
208 GNUNET_MQ_send(ch->mq, ev); 211 GNUNET_MQ_send (ch->mq, ev);
209 if (NULL == ch->mq) 212 if (NULL == ch->mq)
210 return; 213 return;
211 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 214 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
212 &transmit_suggestion, 215 &transmit_suggestion,
213 ch); 216 ch);
214} 217}
215 218
216 219
@@ -221,15 +224,15 @@ reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
221 * @return ats connectivity handle, NULL on error 224 * @return ats connectivity handle, NULL on error
222 */ 225 */
223struct GNUNET_ATS_ConnectivityHandle * 226struct GNUNET_ATS_ConnectivityHandle *
224GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg) 227GNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
225{ 228{
226 struct GNUNET_ATS_ConnectivityHandle *ch; 229 struct GNUNET_ATS_ConnectivityHandle *ch;
227 230
228 ch = GNUNET_new(struct GNUNET_ATS_ConnectivityHandle); 231 ch = GNUNET_new (struct GNUNET_ATS_ConnectivityHandle);
229 ch->cfg = cfg; 232 ch->cfg = cfg;
230 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, 233 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32,
231 GNUNET_YES); 234 GNUNET_YES);
232 reconnect(ch); 235 reconnect (ch);
233 return ch; 236 return ch;
234} 237}
235 238
@@ -244,13 +247,13 @@ GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
244 * @return #GNUNET_OK (continue to iterate) 247 * @return #GNUNET_OK (continue to iterate)
245 */ 248 */
246static int 249static int
247free_sug_handle(void *cls, 250free_sug_handle (void *cls,
248 const struct GNUNET_PeerIdentity *key, 251 const struct GNUNET_PeerIdentity *key,
249 void *value) 252 void *value)
250{ 253{
251 struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value; 254 struct GNUNET_ATS_ConnectivitySuggestHandle *cur = value;
252 255
253 GNUNET_free(cur); 256 GNUNET_free (cur);
254 return GNUNET_OK; 257 return GNUNET_OK;
255} 258}
256 259
@@ -261,23 +264,23 @@ free_sug_handle(void *cls,
261 * @param ch handle to release 264 * @param ch handle to release
262 */ 265 */
263void 266void
264GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch) 267GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch)
265{ 268{
266 if (NULL != ch->mq) 269 if (NULL != ch->mq)
267 { 270 {
268 GNUNET_MQ_destroy(ch->mq); 271 GNUNET_MQ_destroy (ch->mq);
269 ch->mq = NULL; 272 ch->mq = NULL;
270 } 273 }
271 if (NULL != ch->task) 274 if (NULL != ch->task)
272 { 275 {
273 GNUNET_SCHEDULER_cancel(ch->task); 276 GNUNET_SCHEDULER_cancel (ch->task);
274 ch->task = NULL; 277 ch->task = NULL;
275 } 278 }
276 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests, 279 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests,
277 &free_sug_handle, 280 &free_sug_handle,
278 NULL); 281 NULL);
279 GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests); 282 GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests);
280 GNUNET_free(ch); 283 GNUNET_free (ch);
281} 284}
282 285
283 286
@@ -293,36 +296,36 @@ GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
293 * @return suggest handle, NULL if a request is already pending 296 * @return suggest handle, NULL if a request is already pending
294 */ 297 */
295struct GNUNET_ATS_ConnectivitySuggestHandle * 298struct GNUNET_ATS_ConnectivitySuggestHandle *
296GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, 299GNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch,
297 const struct GNUNET_PeerIdentity *peer, 300 const struct GNUNET_PeerIdentity *peer,
298 uint32_t strength) 301 uint32_t strength)
299{ 302{
300 struct GNUNET_ATS_ConnectivitySuggestHandle *s; 303 struct GNUNET_ATS_ConnectivitySuggestHandle *s;
301 304
302 s = GNUNET_new(struct GNUNET_ATS_ConnectivitySuggestHandle); 305 s = GNUNET_new (struct GNUNET_ATS_ConnectivitySuggestHandle);
303 s->ch = ch; 306 s->ch = ch;
304 s->id = *peer; 307 s->id = *peer;
305 s->strength = strength; 308 s->strength = strength;
306 if (GNUNET_OK != 309 if (GNUNET_OK !=
307 GNUNET_CONTAINER_multipeermap_put(ch->sug_requests, 310 GNUNET_CONTAINER_multipeermap_put (ch->sug_requests,
308 &s->id, 311 &s->id,
309 s, 312 s,
310 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 313 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
311 { 314 {
312 LOG(GNUNET_ERROR_TYPE_DEBUG, 315 LOG (GNUNET_ERROR_TYPE_DEBUG,
313 "Not requesting ATS to suggest address for `%s', request already pending\n", 316 "Not requesting ATS to suggest address for `%s', request already pending\n",
314 GNUNET_i2s(peer)); 317 GNUNET_i2s (peer));
315 GNUNET_free(s); 318 GNUNET_free (s);
316 return NULL; 319 return NULL;
317 } 320 }
318 LOG(GNUNET_ERROR_TYPE_DEBUG, 321 LOG (GNUNET_ERROR_TYPE_DEBUG,
319 "Requesting ATS to suggest address for `%s'\n", 322 "Requesting ATS to suggest address for `%s'\n",
320 GNUNET_i2s(peer)); 323 GNUNET_i2s (peer));
321 if (NULL == ch->mq) 324 if (NULL == ch->mq)
322 return s; 325 return s;
323 (void)transmit_suggestion(ch, 326 (void) transmit_suggestion (ch,
324 &s->id, 327 &s->id,
325 s); 328 s);
326 return s; 329 return s;
327} 330}
328 331
@@ -333,30 +336,31 @@ GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch,
333 * @param sh handle to stop 336 * @param sh handle to stop
334 */ 337 */
335void 338void
336GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh) 339GNUNET_ATS_connectivity_suggest_cancel (struct
340 GNUNET_ATS_ConnectivitySuggestHandle *sh)
337{ 341{
338 struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch; 342 struct GNUNET_ATS_ConnectivityHandle *ch = sh->ch;
339 struct GNUNET_MQ_Envelope *ev; 343 struct GNUNET_MQ_Envelope *ev;
340 struct RequestAddressMessage *m; 344 struct RequestAddressMessage *m;
341 345
342 LOG(GNUNET_ERROR_TYPE_DEBUG, 346 LOG (GNUNET_ERROR_TYPE_DEBUG,
343 "Telling ATS we no longer care for an address for `%s'\n", 347 "Telling ATS we no longer care for an address for `%s'\n",
344 GNUNET_i2s(&sh->id)); 348 GNUNET_i2s (&sh->id));
345 GNUNET_assert(GNUNET_OK == 349 GNUNET_assert (GNUNET_OK ==
346 GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, 350 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests,
347 &sh->id, 351 &sh->id,
348 sh)); 352 sh));
349 if (NULL == ch->mq) 353 if (NULL == ch->mq)
350 { 354 {
351 GNUNET_free(sh); 355 GNUNET_free (sh);
352 return; 356 return;
353 } 357 }
354 ev = GNUNET_MQ_msg(m, 358 ev = GNUNET_MQ_msg (m,
355 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL); 359 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL);
356 m->strength = htonl(0); 360 m->strength = htonl (0);
357 m->peer = sh->id; 361 m->peer = sh->id;
358 GNUNET_MQ_send(ch->mq, ev); 362 GNUNET_MQ_send (ch->mq, ev);
359 GNUNET_free(sh); 363 GNUNET_free (sh);
360} 364}
361 365
362 366
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index b30093f4c..8defd6022 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -28,13 +28,15 @@
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", \
32 __VA_ARGS__)
32 33
33 34
34/** 35/**
35 * Linked list of pending reservations. 36 * Linked list of pending reservations.
36 */ 37 */
37struct GNUNET_ATS_ReservationContext { 38struct GNUNET_ATS_ReservationContext
39{
38 /** 40 /**
39 * Kept in a DLL. 41 * Kept in a DLL.
40 */ 42 */
@@ -80,7 +82,8 @@ struct GNUNET_ATS_ReservationContext {
80/** 82/**
81 * Linked list of pending reservations. 83 * Linked list of pending reservations.
82 */ 84 */
83struct GNUNET_ATS_AddressListHandle { 85struct GNUNET_ATS_AddressListHandle
86{
84 /** 87 /**
85 * Kept in a DLL. 88 * Kept in a DLL.
86 */ 89 */
@@ -131,7 +134,8 @@ struct GNUNET_ATS_AddressListHandle {
131/** 134/**
132 * ATS Handle to obtain and/or modify performance information. 135 * ATS Handle to obtain and/or modify performance information.
133 */ 136 */
134struct GNUNET_ATS_PerformanceHandle { 137struct GNUNET_ATS_PerformanceHandle
138{
135 /** 139 /**
136 * Our configuration. 140 * Our configuration.
137 */ 141 */
@@ -209,7 +213,7 @@ struct GNUNET_ATS_PerformanceHandle {
209 * @param ph handle to use to re-connect. 213 * @param ph handle to use to re-connect.
210 */ 214 */
211static void 215static void
212reconnect(struct GNUNET_ATS_PerformanceHandle *ph); 216reconnect (struct GNUNET_ATS_PerformanceHandle *ph);
213 217
214 218
215/** 219/**
@@ -218,12 +222,12 @@ reconnect(struct GNUNET_ATS_PerformanceHandle *ph);
218 * @param cls handle to use to re-connect. 222 * @param cls handle to use to re-connect.
219 */ 223 */
220static void 224static void
221reconnect_task(void *cls) 225reconnect_task (void *cls)
222{ 226{
223 struct GNUNET_ATS_PerformanceHandle *ph = cls; 227 struct GNUNET_ATS_PerformanceHandle *ph = cls;
224 228
225 ph->task = NULL; 229 ph->task = NULL;
226 reconnect(ph); 230 reconnect (ph);
227} 231}
228 232
229 233
@@ -233,58 +237,58 @@ reconnect_task(void *cls)
233 * @param ph handle to reconnect 237 * @param ph handle to reconnect
234 */ 238 */
235static void 239static void
236do_reconnect(struct GNUNET_ATS_PerformanceHandle *ph) 240do_reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
237{ 241{
238 struct GNUNET_ATS_ReservationContext *rc; 242 struct GNUNET_ATS_ReservationContext *rc;
239 struct GNUNET_ATS_AddressListHandle *alh; 243 struct GNUNET_ATS_AddressListHandle *alh;
240 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero; 244 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
241 245
242 if (NULL != ph->mq) 246 if (NULL != ph->mq)
243 { 247 {
244 GNUNET_MQ_destroy(ph->mq); 248 GNUNET_MQ_destroy (ph->mq);
245 ph->mq = NULL; 249 ph->mq = NULL;
246 } 250 }
247 while (NULL != (rc = ph->reservation_head)) 251 while (NULL != (rc = ph->reservation_head))
248 { 252 {
249 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, 253 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
250 ph->reservation_tail, 254 ph->reservation_tail,
251 rc); 255 rc);
252 if (NULL != rc->rcb) 256 if (NULL != rc->rcb)
253 rc->rcb(rc->rcb_cls, 257 rc->rcb (rc->rcb_cls,
254 NULL, 258 NULL,
255 0, 259 0,
256 GNUNET_TIME_UNIT_FOREVER_REL); 260 GNUNET_TIME_UNIT_FOREVER_REL);
257 GNUNET_free(rc); 261 GNUNET_free (rc);
258 } 262 }
259 bandwidth_zero.value__ = htonl(0); 263 bandwidth_zero.value__ = htonl (0);
260 while (NULL != (alh = ph->addresslist_head)) 264 while (NULL != (alh = ph->addresslist_head))
261 { 265 {
262 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, 266 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
263 ph->addresslist_tail, 267 ph->addresslist_tail,
264 alh); 268 alh);
265 if (NULL != alh->cb) 269 if (NULL != alh->cb)
266 alh->cb(alh->cb_cls, 270 alh->cb (alh->cb_cls,
267 NULL, 271 NULL,
268 GNUNET_NO, 272 GNUNET_NO,
269 bandwidth_zero, 273 bandwidth_zero,
270 bandwidth_zero, 274 bandwidth_zero,
271 NULL); 275 NULL);
272 GNUNET_free(alh); 276 GNUNET_free (alh);
273 } 277 }
274 if (NULL != ph->addr_info_cb) 278 if (NULL != ph->addr_info_cb)
275 { 279 {
276 /* Indicate reconnect */ 280 /* Indicate reconnect */
277 ph->addr_info_cb(ph->addr_info_cb_cls, 281 ph->addr_info_cb (ph->addr_info_cb_cls,
278 NULL, 282 NULL,
279 GNUNET_NO, 283 GNUNET_NO,
280 bandwidth_zero, 284 bandwidth_zero,
281 bandwidth_zero, 285 bandwidth_zero,
282 NULL); 286 NULL);
283 } 287 }
284 ph->backoff = GNUNET_TIME_STD_BACKOFF(ph->backoff); 288 ph->backoff = GNUNET_TIME_STD_BACKOFF (ph->backoff);
285 ph->task = GNUNET_SCHEDULER_add_delayed(ph->backoff, 289 ph->task = GNUNET_SCHEDULER_add_delayed (ph->backoff,
286 &reconnect_task, 290 &reconnect_task,
287 ph); 291 ph);
288} 292}
289 293
290 294
@@ -296,25 +300,25 @@ do_reconnect(struct GNUNET_ATS_PerformanceHandle *ph)
296 * @return #GNUNET_OK if the message was well-formed 300 * @return #GNUNET_OK if the message was well-formed
297 */ 301 */
298static int 302static int
299check_peer_information(void *cls, 303check_peer_information (void *cls,
300 const struct PeerInformationMessage *pi) 304 const struct PeerInformationMessage *pi)
301{ 305{
302 const char *plugin_address; 306 const char *plugin_address;
303 const char *plugin_name; 307 const char *plugin_name;
304 uint16_t plugin_address_length; 308 uint16_t plugin_address_length;
305 uint16_t plugin_name_length; 309 uint16_t plugin_name_length;
306 310
307 plugin_address_length = ntohs(pi->address_length); 311 plugin_address_length = ntohs (pi->address_length);
308 plugin_name_length = ntohs(pi->plugin_name_length); 312 plugin_name_length = ntohs (pi->plugin_name_length);
309 plugin_address = (const char *)&pi[1]; 313 plugin_address = (const char *) &pi[1];
310 plugin_name = &plugin_address[plugin_address_length]; 314 plugin_name = &plugin_address[plugin_address_length];
311 if ((plugin_address_length + plugin_name_length 315 if ((plugin_address_length + plugin_name_length
312 + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || 316 + sizeof(struct PeerInformationMessage) != ntohs (pi->header.size)) ||
313 (plugin_name[plugin_name_length - 1] != '\0')) 317 (plugin_name[plugin_name_length - 1] != '\0'))
314 { 318 {
315 GNUNET_break(0); 319 GNUNET_break (0);
316 return GNUNET_SYSERR; 320 return GNUNET_SYSERR;
317 } 321 }
318 return GNUNET_OK; 322 return GNUNET_OK;
319} 323}
320 324
@@ -327,8 +331,8 @@ check_peer_information(void *cls,
327 * @return #GNUNET_OK if the message was well-formed 331 * @return #GNUNET_OK if the message was well-formed
328 */ 332 */
329static void 333static void
330handle_peer_information(void *cls, 334handle_peer_information (void *cls,
331 const struct PeerInformationMessage *pi) 335 const struct PeerInformationMessage *pi)
332{ 336{
333 struct GNUNET_ATS_PerformanceHandle *ph = cls; 337 struct GNUNET_ATS_PerformanceHandle *ph = cls;
334 const char *plugin_address; 338 const char *plugin_address;
@@ -340,24 +344,25 @@ handle_peer_information(void *cls,
340 344
341 if (NULL == ph->addr_info_cb) 345 if (NULL == ph->addr_info_cb)
342 return; 346 return;
343 plugin_address_length = ntohs(pi->address_length); 347 plugin_address_length = ntohs (pi->address_length);
344 addr_active = (int)ntohl(pi->address_active); 348 addr_active = (int) ntohl (pi->address_active);
345 plugin_address = (const char *)&pi[1]; 349 plugin_address = (const char *) &pi[1];
346 plugin_name = &plugin_address[plugin_address_length]; 350 plugin_name = &plugin_address[plugin_address_length];
347 351
348 GNUNET_ATS_properties_ntoh(&prop, 352 GNUNET_ATS_properties_ntoh (&prop,
349 &pi->properties); 353 &pi->properties);
350 address.peer = pi->peer; 354 address.peer = pi->peer;
351 address.local_info = (enum GNUNET_HELLO_AddressInfo)ntohl(pi->address_local_info); 355 address.local_info = (enum GNUNET_HELLO_AddressInfo) ntohl (
356 pi->address_local_info);
352 address.address = plugin_address; 357 address.address = plugin_address;
353 address.address_length = plugin_address_length; 358 address.address_length = plugin_address_length;
354 address.transport_name = plugin_name; 359 address.transport_name = plugin_name;
355 ph->addr_info_cb(ph->addr_info_cb_cls, 360 ph->addr_info_cb (ph->addr_info_cb_cls,
356 &address, 361 &address,
357 addr_active, 362 addr_active,
358 pi->bandwidth_out, 363 pi->bandwidth_out,
359 pi->bandwidth_in, 364 pi->bandwidth_in,
360 &prop); 365 &prop);
361} 366}
362 367
363 368
@@ -368,48 +373,48 @@ handle_peer_information(void *cls,
368 * @param rr the message 373 * @param rr the message
369 */ 374 */
370static void 375static void
371handle_reservation_result(void *cls, 376handle_reservation_result (void *cls,
372 const struct ReservationResultMessage *rr) 377 const struct ReservationResultMessage *rr)
373{ 378{
374 struct GNUNET_ATS_PerformanceHandle *ph = cls; 379 struct GNUNET_ATS_PerformanceHandle *ph = cls;
375 struct GNUNET_ATS_ReservationContext *rc; 380 struct GNUNET_ATS_ReservationContext *rc;
376 int32_t amount; 381 int32_t amount;
377 382
378 amount = ntohl(rr->amount); 383 amount = ntohl (rr->amount);
379 rc = ph->reservation_head; 384 rc = ph->reservation_head;
380 if (0 != GNUNET_memcmp(&rr->peer, 385 if (0 != GNUNET_memcmp (&rr->peer,
381 &rc->peer)) 386 &rc->peer))
382 { 387 {
383 GNUNET_break(0); 388 GNUNET_break (0);
384 reconnect(ph); 389 reconnect (ph);
385 return; 390 return;
386 } 391 }
387 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, 392 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
388 ph->reservation_tail, 393 ph->reservation_tail,
389 rc); 394 rc);
390 if ((0 == amount) || 395 if ((0 == amount) ||
391 (NULL != rc->rcb)) 396 (NULL != rc->rcb))
392 { 397 {
393 /* tell client if not cancelled */ 398 /* tell client if not cancelled */
394 if (NULL != rc->rcb) 399 if (NULL != rc->rcb)
395 rc->rcb(rc->rcb_cls, 400 rc->rcb (rc->rcb_cls,
396 &rr->peer, 401 &rr->peer,
397 amount, 402 amount,
398 GNUNET_TIME_relative_ntoh(rr->res_delay)); 403 GNUNET_TIME_relative_ntoh (rr->res_delay));
399 GNUNET_free(rc); 404 GNUNET_free (rc);
400 return; 405 return;
401 } 406 }
402 /* amount non-zero, but client cancelled, consider undo! */ 407 /* amount non-zero, but client cancelled, consider undo! */
403 if (GNUNET_YES != rc->undo) 408 if (GNUNET_YES != rc->undo)
404 { 409 {
405 GNUNET_free(rc); 410 GNUNET_free (rc);
406 return; /* do not try to undo failed undos or negative amounts */ 411 return; /* do not try to undo failed undos or negative amounts */
407 } 412 }
408 GNUNET_free(rc); 413 GNUNET_free (rc);
409 (void)GNUNET_ATS_reserve_bandwidth(ph, 414 (void) GNUNET_ATS_reserve_bandwidth (ph,
410 &rr->peer, 415 &rr->peer,
411 -amount, 416 -amount,
412 NULL, NULL); 417 NULL, NULL);
413} 418}
414 419
415 420
@@ -421,25 +426,25 @@ handle_reservation_result(void *cls,
421 * @return #GNUNET_OK if the message was well-formed 426 * @return #GNUNET_OK if the message was well-formed
422 */ 427 */
423static int 428static int
424check_address_list(void *cls, 429check_address_list (void *cls,
425 const struct PeerInformationMessage *pi) 430 const struct PeerInformationMessage *pi)
426{ 431{
427 const char *plugin_address; 432 const char *plugin_address;
428 const char *plugin_name; 433 const char *plugin_name;
429 uint16_t plugin_address_length; 434 uint16_t plugin_address_length;
430 uint16_t plugin_name_length; 435 uint16_t plugin_name_length;
431 436
432 plugin_address_length = ntohs(pi->address_length); 437 plugin_address_length = ntohs (pi->address_length);
433 plugin_name_length = ntohs(pi->plugin_name_length); 438 plugin_name_length = ntohs (pi->plugin_name_length);
434 plugin_address = (const char *)&pi[1]; 439 plugin_address = (const char *) &pi[1];
435 plugin_name = &plugin_address[plugin_address_length]; 440 plugin_name = &plugin_address[plugin_address_length];
436 if ((plugin_address_length + plugin_name_length 441 if ((plugin_address_length + plugin_name_length
437 + sizeof(struct PeerInformationMessage) != ntohs(pi->header.size)) || 442 + sizeof(struct PeerInformationMessage) != ntohs (pi->header.size)) ||
438 (plugin_name[plugin_name_length - 1] != '\0')) 443 (plugin_name[plugin_name_length - 1] != '\0'))
439 { 444 {
440 GNUNET_break(0); 445 GNUNET_break (0);
441 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
442 } 447 }
443 return GNUNET_OK; 448 return GNUNET_OK;
444} 449}
445 450
@@ -452,8 +457,8 @@ check_address_list(void *cls,
452 * @param pi the message 457 * @param pi the message
453 */ 458 */
454static void 459static void
455handle_address_list(void *cls, 460handle_address_list (void *cls,
456 const struct PeerInformationMessage *pi) 461 const struct PeerInformationMessage *pi)
457{ 462{
458 struct GNUNET_ATS_PerformanceHandle *ph = cls; 463 struct GNUNET_ATS_PerformanceHandle *ph = cls;
459 struct GNUNET_ATS_AddressListHandle *alh; 464 struct GNUNET_ATS_AddressListHandle *alh;
@@ -469,49 +474,49 @@ handle_address_list(void *cls,
469 uint32_t active; 474 uint32_t active;
470 uint32_t id; 475 uint32_t id;
471 476
472 id = ntohl(pi->id); 477 id = ntohl (pi->id);
473 active = ntohl(pi->address_active); 478 active = ntohl (pi->address_active);
474 plugin_address_length = ntohs(pi->address_length); 479 plugin_address_length = ntohs (pi->address_length);
475 plugin_name_length = ntohs(pi->plugin_name_length); 480 plugin_name_length = ntohs (pi->plugin_name_length);
476 plugin_address = (const char *)&pi[1]; 481 plugin_address = (const char *) &pi[1];
477 plugin_name = &plugin_address[plugin_address_length]; 482 plugin_name = &plugin_address[plugin_address_length];
478 LOG(GNUNET_ERROR_TYPE_DEBUG, 483 LOG (GNUNET_ERROR_TYPE_DEBUG,
479 "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n", 484 "Received ATS_ADDRESSLIST_RESPONSE message for peer %s and plugin %s\n",
480 GNUNET_i2s(&pi->peer), 485 GNUNET_i2s (&pi->peer),
481 plugin_name); 486 plugin_name);
482 487
483 next = ph->addresslist_head; 488 next = ph->addresslist_head;
484 while (NULL != (alh = next)) 489 while (NULL != (alh = next))
485 { 490 {
486 next = alh->next; 491 next = alh->next;
487 if (alh->id == id) 492 if (alh->id == id)
488 break; 493 break;
489 } 494 }
490 if (NULL == alh) 495 if (NULL == alh)
491 return; /* was canceled */ 496 return; /* was canceled */
492 497
493 memset(&allzeros, '\0', sizeof(allzeros)); 498 memset (&allzeros, '\0', sizeof(allzeros));
494 if ((0 == GNUNET_is_zero(&pi->peer)) && 499 if ((0 == GNUNET_is_zero (&pi->peer)) &&
495 (0 == plugin_name_length) && 500 (0 == plugin_name_length) &&
496 (0 == plugin_address_length)) 501 (0 == plugin_address_length))
497 { 502 {
498 /* Done */ 503 /* Done */
499 LOG(GNUNET_ERROR_TYPE_DEBUG, 504 LOG (GNUNET_ERROR_TYPE_DEBUG,
500 "Received last message for ATS_ADDRESSLIST_RESPONSE\n"); 505 "Received last message for ATS_ADDRESSLIST_RESPONSE\n");
501 bandwidth_zero.value__ = htonl(0); 506 bandwidth_zero.value__ = htonl (0);
502 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, 507 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
503 ph->addresslist_tail, 508 ph->addresslist_tail,
504 alh); 509 alh);
505 if (NULL != alh->cb) 510 if (NULL != alh->cb)
506 alh->cb(alh->cb_cls, 511 alh->cb (alh->cb_cls,
507 NULL, 512 NULL,
508 GNUNET_NO, 513 GNUNET_NO,
509 bandwidth_zero, 514 bandwidth_zero,
510 bandwidth_zero, 515 bandwidth_zero,
511 NULL); 516 NULL);
512 GNUNET_free(alh); 517 GNUNET_free (alh);
513 return; 518 return;
514 } 519 }
515 520
516 address.peer = pi->peer; 521 address.peer = pi->peer;
517 address.address = plugin_address; 522 address.address = plugin_address;
@@ -520,16 +525,16 @@ handle_address_list(void *cls,
520 if (((GNUNET_YES == alh->all_addresses) || 525 if (((GNUNET_YES == alh->all_addresses) ||
521 (GNUNET_YES == active)) && 526 (GNUNET_YES == active)) &&
522 (NULL != alh->cb)) 527 (NULL != alh->cb))
523 { 528 {
524 GNUNET_ATS_properties_ntoh(&prop, 529 GNUNET_ATS_properties_ntoh (&prop,
525 &pi->properties); 530 &pi->properties);
526 alh->cb(alh->cb_cls, 531 alh->cb (alh->cb_cls,
527 &address, 532 &address,
528 active, 533 active,
529 pi->bandwidth_out, 534 pi->bandwidth_out,
530 pi->bandwidth_in, 535 pi->bandwidth_in,
531 &prop); 536 &prop);
532 } 537 }
533} 538}
534 539
535 540
@@ -542,12 +547,12 @@ handle_address_list(void *cls,
542 * @param error error code 547 * @param error error code
543 */ 548 */
544static void 549static void
545mq_error_handler(void *cls, 550mq_error_handler (void *cls,
546 enum GNUNET_MQ_Error error) 551 enum GNUNET_MQ_Error error)
547{ 552{
548 struct GNUNET_ATS_PerformanceHandle *ph = cls; 553 struct GNUNET_ATS_PerformanceHandle *ph = cls;
549 554
550 do_reconnect(ph); 555 do_reconnect (ph);
551} 556}
552 557
553 558
@@ -557,41 +562,41 @@ mq_error_handler(void *cls,
557 * @param ph handle to use to re-connect. 562 * @param ph handle to use to re-connect.
558 */ 563 */
559static void 564static void
560reconnect(struct GNUNET_ATS_PerformanceHandle *ph) 565reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
561{ 566{
562 struct GNUNET_MQ_MessageHandler handlers[] = { 567 struct GNUNET_MQ_MessageHandler handlers[] = {
563 GNUNET_MQ_hd_var_size(peer_information, 568 GNUNET_MQ_hd_var_size (peer_information,
564 GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION, 569 GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION,
565 struct PeerInformationMessage, 570 struct PeerInformationMessage,
566 ph), 571 ph),
567 GNUNET_MQ_hd_fixed_size(reservation_result, 572 GNUNET_MQ_hd_fixed_size (reservation_result,
568 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT, 573 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_RESULT,
569 struct ReservationResultMessage, 574 struct ReservationResultMessage,
570 ph), 575 ph),
571 GNUNET_MQ_hd_var_size(address_list, 576 GNUNET_MQ_hd_var_size (address_list,
572 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE, 577 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE,
573 struct PeerInformationMessage, 578 struct PeerInformationMessage,
574 ph), 579 ph),
575 GNUNET_MQ_handler_end() 580 GNUNET_MQ_handler_end ()
576 }; 581 };
577 struct GNUNET_MQ_Envelope *env; 582 struct GNUNET_MQ_Envelope *env;
578 struct ClientStartMessage *init; 583 struct ClientStartMessage *init;
579 584
580 GNUNET_assert(NULL == ph->mq); 585 GNUNET_assert (NULL == ph->mq);
581 ph->mq = GNUNET_CLIENT_connect(ph->cfg, 586 ph->mq = GNUNET_CLIENT_connect (ph->cfg,
582 "ats", 587 "ats",
583 handlers, 588 handlers,
584 &mq_error_handler, 589 &mq_error_handler,
585 ph); 590 ph);
586 if (NULL == ph->mq) 591 if (NULL == ph->mq)
587 return; 592 return;
588 env = GNUNET_MQ_msg(init, 593 env = GNUNET_MQ_msg (init,
589 GNUNET_MESSAGE_TYPE_ATS_START); 594 GNUNET_MESSAGE_TYPE_ATS_START);
590 init->start_flag = htonl((NULL == ph->addr_info_cb) 595 init->start_flag = htonl ((NULL == ph->addr_info_cb)
591 ? START_FLAG_PERFORMANCE_NO_PIC 596 ? START_FLAG_PERFORMANCE_NO_PIC
592 : START_FLAG_PERFORMANCE_WITH_PIC); 597 : START_FLAG_PERFORMANCE_WITH_PIC);
593 GNUNET_MQ_send(ph->mq, 598 GNUNET_MQ_send (ph->mq,
594 env); 599 env);
595} 600}
596 601
597 602
@@ -605,22 +610,22 @@ reconnect(struct GNUNET_ATS_PerformanceHandle *ph)
605 * @return ats performance context 610 * @return ats performance context
606 */ 611 */
607struct GNUNET_ATS_PerformanceHandle * 612struct GNUNET_ATS_PerformanceHandle *
608GNUNET_ATS_performance_init(const struct GNUNET_CONFIGURATION_Handle *cfg, 613GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
609 GNUNET_ATS_AddressInformationCallback addr_info_cb, 614 GNUNET_ATS_AddressInformationCallback addr_info_cb,
610 void *addr_info_cb_cls) 615 void *addr_info_cb_cls)
611{ 616{
612 struct GNUNET_ATS_PerformanceHandle *ph; 617 struct GNUNET_ATS_PerformanceHandle *ph;
613 618
614 ph = GNUNET_new(struct GNUNET_ATS_PerformanceHandle); 619 ph = GNUNET_new (struct GNUNET_ATS_PerformanceHandle);
615 ph->cfg = cfg; 620 ph->cfg = cfg;
616 ph->addr_info_cb = addr_info_cb; 621 ph->addr_info_cb = addr_info_cb;
617 ph->addr_info_cb_cls = addr_info_cb_cls; 622 ph->addr_info_cb_cls = addr_info_cb_cls;
618 reconnect(ph); 623 reconnect (ph);
619 if (NULL == ph->mq) 624 if (NULL == ph->mq)
620 { 625 {
621 GNUNET_free(ph); 626 GNUNET_free (ph);
622 return NULL; 627 return NULL;
623 } 628 }
624 return ph; 629 return ph;
625} 630}
626 631
@@ -631,37 +636,37 @@ GNUNET_ATS_performance_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
631 * @param ph handle 636 * @param ph handle
632 */ 637 */
633void 638void
634GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph) 639GNUNET_ATS_performance_done (struct GNUNET_ATS_PerformanceHandle *ph)
635{ 640{
636 struct GNUNET_ATS_ReservationContext *rc; 641 struct GNUNET_ATS_ReservationContext *rc;
637 struct GNUNET_ATS_AddressListHandle *alh; 642 struct GNUNET_ATS_AddressListHandle *alh;
638 643
639 while (NULL != (alh = ph->addresslist_head)) 644 while (NULL != (alh = ph->addresslist_head))
640 { 645 {
641 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, 646 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
642 ph->addresslist_tail, 647 ph->addresslist_tail,
643 alh); 648 alh);
644 GNUNET_free(alh); 649 GNUNET_free (alh);
645 } 650 }
646 while (NULL != (rc = ph->reservation_head)) 651 while (NULL != (rc = ph->reservation_head))
647 { 652 {
648 GNUNET_CONTAINER_DLL_remove(ph->reservation_head, 653 GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
649 ph->reservation_tail, 654 ph->reservation_tail,
650 rc); 655 rc);
651 GNUNET_break(NULL == rc->rcb); 656 GNUNET_break (NULL == rc->rcb);
652 GNUNET_free(rc); 657 GNUNET_free (rc);
653 } 658 }
654 if (NULL != ph->task) 659 if (NULL != ph->task)
655 { 660 {
656 GNUNET_SCHEDULER_cancel(ph->task); 661 GNUNET_SCHEDULER_cancel (ph->task);
657 ph->task = NULL; 662 ph->task = NULL;
658 } 663 }
659 if (NULL != ph->mq) 664 if (NULL != ph->mq)
660 { 665 {
661 GNUNET_MQ_destroy(ph->mq); 666 GNUNET_MQ_destroy (ph->mq);
662 ph->mq = NULL; 667 ph->mq = NULL;
663 } 668 }
664 GNUNET_free(ph); 669 GNUNET_free (ph);
665} 670}
666 671
667 672
@@ -680,11 +685,11 @@ GNUNET_ATS_performance_done(struct GNUNET_ATS_PerformanceHandle *ph)
680 * @deprecated will be replaced soon 685 * @deprecated will be replaced soon
681 */ 686 */
682struct GNUNET_ATS_ReservationContext * 687struct GNUNET_ATS_ReservationContext *
683GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, 688GNUNET_ATS_reserve_bandwidth (struct GNUNET_ATS_PerformanceHandle *ph,
684 const struct GNUNET_PeerIdentity *peer, 689 const struct GNUNET_PeerIdentity *peer,
685 int32_t amount, 690 int32_t amount,
686 GNUNET_ATS_ReservationCallback rcb, 691 GNUNET_ATS_ReservationCallback rcb,
687 void *rcb_cls) 692 void *rcb_cls)
688{ 693{
689 struct GNUNET_ATS_ReservationContext *rc; 694 struct GNUNET_ATS_ReservationContext *rc;
690 struct GNUNET_MQ_Envelope *env; 695 struct GNUNET_MQ_Envelope *env;
@@ -692,7 +697,7 @@ GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph,
692 697
693 if (NULL == ph->mq) 698 if (NULL == ph->mq)
694 return NULL; 699 return NULL;
695 rc = GNUNET_new(struct GNUNET_ATS_ReservationContext); 700 rc = GNUNET_new (struct GNUNET_ATS_ReservationContext);
696 rc->size = amount; 701 rc->size = amount;
697 rc->peer = *peer; 702 rc->peer = *peer;
698 rc->rcb = rcb; 703 rc->rcb = rcb;
@@ -700,15 +705,15 @@ GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph,
700 if ((NULL != rcb) && 705 if ((NULL != rcb) &&
701 (amount > 0)) 706 (amount > 0))
702 rc->undo = GNUNET_YES; 707 rc->undo = GNUNET_YES;
703 GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, 708 GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head,
704 ph->reservation_tail, 709 ph->reservation_tail,
705 rc); 710 rc);
706 env = GNUNET_MQ_msg(m, 711 env = GNUNET_MQ_msg (m,
707 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST); 712 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST);
708 m->amount = htonl(amount); 713 m->amount = htonl (amount);
709 m->peer = *peer; 714 m->peer = *peer;
710 GNUNET_MQ_send(ph->mq, 715 GNUNET_MQ_send (ph->mq,
711 env); 716 env);
712 return rc; 717 return rc;
713} 718}
714 719
@@ -719,7 +724,7 @@ GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph,
719 * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call 724 * @param rc context returned by the original #GNUNET_ATS_reserve_bandwidth() call
720 */ 725 */
721void 726void
722GNUNET_ATS_reserve_bandwidth_cancel(struct GNUNET_ATS_ReservationContext *rc) 727GNUNET_ATS_reserve_bandwidth_cancel (struct GNUNET_ATS_ReservationContext *rc)
723{ 728{
724 rc->rcb = NULL; 729 rc->rcb = NULL;
725} 730}
@@ -738,11 +743,12 @@ GNUNET_ATS_reserve_bandwidth_cancel(struct GNUNET_ATS_ReservationContext *rc)
738 * @return ats performance context 743 * @return ats performance context
739 */ 744 */
740struct GNUNET_ATS_AddressListHandle* 745struct GNUNET_ATS_AddressListHandle*
741GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph, 746GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *ph,
742 const struct GNUNET_PeerIdentity *peer, 747 const struct GNUNET_PeerIdentity *peer,
743 int all, 748 int all,
744 GNUNET_ATS_AddressInformationCallback infocb, 749 GNUNET_ATS_AddressInformationCallback
745 void *infocb_cls) 750 infocb,
751 void *infocb_cls)
746{ 752{
747 struct GNUNET_ATS_AddressListHandle *alh; 753 struct GNUNET_ATS_AddressListHandle *alh;
748 struct GNUNET_MQ_Envelope *env; 754 struct GNUNET_MQ_Envelope *env;
@@ -751,36 +757,36 @@ GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph,
751 if (NULL == ph->mq) 757 if (NULL == ph->mq)
752 return NULL; 758 return NULL;
753 if (NULL == infocb) 759 if (NULL == infocb)
754 { 760 {
755 GNUNET_break(0); 761 GNUNET_break (0);
756 return NULL; 762 return NULL;
757 } 763 }
758 alh = GNUNET_new(struct GNUNET_ATS_AddressListHandle); 764 alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle);
759 alh->id = ph->id++; 765 alh->id = ph->id++;
760 alh->cb = infocb; 766 alh->cb = infocb;
761 alh->cb_cls = infocb_cls; 767 alh->cb_cls = infocb_cls;
762 alh->ph = ph; 768 alh->ph = ph;
763 alh->all_addresses = all; 769 alh->all_addresses = all;
764 if (NULL == peer) 770 if (NULL == peer)
765 { 771 {
766 alh->all_peers = GNUNET_YES; 772 alh->all_peers = GNUNET_YES;
767 } 773 }
768 else 774 else
769 { 775 {
770 alh->all_peers = GNUNET_NO; 776 alh->all_peers = GNUNET_NO;
771 alh->peer = *peer; 777 alh->peer = *peer;
772 } 778 }
773 GNUNET_CONTAINER_DLL_insert(ph->addresslist_head, 779 GNUNET_CONTAINER_DLL_insert (ph->addresslist_head,
774 ph->addresslist_tail, 780 ph->addresslist_tail,
775 alh); 781 alh);
776 env = GNUNET_MQ_msg(m, 782 env = GNUNET_MQ_msg (m,
777 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); 783 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST);
778 m->all = htonl(all); 784 m->all = htonl (all);
779 m->id = htonl(alh->id); 785 m->id = htonl (alh->id);
780 if (NULL != peer) 786 if (NULL != peer)
781 m->peer = *peer; 787 m->peer = *peer;
782 GNUNET_MQ_send(ph->mq, 788 GNUNET_MQ_send (ph->mq,
783 env); 789 env);
784 return alh; 790 return alh;
785} 791}
786 792
@@ -791,14 +797,15 @@ GNUNET_ATS_performance_list_addresses(struct GNUNET_ATS_PerformanceHandle *ph,
791 * @param alh the handle of the request to cancel 797 * @param alh the handle of the request to cancel
792 */ 798 */
793void 799void
794GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle *alh) 800GNUNET_ATS_performance_list_addresses_cancel (struct
801 GNUNET_ATS_AddressListHandle *alh)
795{ 802{
796 struct GNUNET_ATS_PerformanceHandle *ph = alh->ph; 803 struct GNUNET_ATS_PerformanceHandle *ph = alh->ph;
797 804
798 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, 805 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
799 ph->addresslist_tail, 806 ph->addresslist_tail,
800 alh); 807 alh);
801 GNUNET_free(alh); 808 GNUNET_free (alh);
802} 809}
803 810
804 811
@@ -809,7 +816,7 @@ GNUNET_ATS_performance_list_addresses_cancel(struct GNUNET_ATS_AddressListHandle
809 * @return a string or NULL if invalid 816 * @return a string or NULL if invalid
810 */ 817 */
811const char * 818const char *
812GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type) 819GNUNET_ATS_print_preference_type (enum GNUNET_ATS_PreferenceKind type)
813{ 820{
814 const char *prefs[] = GNUNET_ATS_PreferenceTypeString; 821 const char *prefs[] = GNUNET_ATS_PreferenceTypeString;
815 822
@@ -828,9 +835,11 @@ GNUNET_ATS_print_preference_type(enum GNUNET_ATS_PreferenceKind type)
828 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes 835 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
829 */ 836 */
830void 837void
831GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, 838GNUNET_ATS_performance_change_preference (struct
832 const struct GNUNET_PeerIdentity *peer, 839 GNUNET_ATS_PerformanceHandle *ph,
833 ...) 840 const struct
841 GNUNET_PeerIdentity *peer,
842 ...)
834{ 843{
835 struct GNUNET_MQ_Envelope *env; 844 struct GNUNET_MQ_Envelope *env;
836 struct ChangePreferenceMessage *m; 845 struct ChangePreferenceMessage *m;
@@ -842,60 +851,61 @@ GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph
842 if (NULL == ph->mq) 851 if (NULL == ph->mq)
843 return; 852 return;
844 count = 0; 853 count = 0;
845 va_start(ap, peer); 854 va_start (ap, peer);
846 while (GNUNET_ATS_PREFERENCE_END != 855 while (GNUNET_ATS_PREFERENCE_END !=
847 (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) 856 (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind)))
857 {
858 switch (kind)
848 { 859 {
849 switch (kind) 860 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
850 { 861 count++;
851 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 862 (void) va_arg (ap, double);
852 count++; 863 break;
853 (void)va_arg(ap, double); 864
854 break; 865 case GNUNET_ATS_PREFERENCE_LATENCY:
855 866 count++;
856 case GNUNET_ATS_PREFERENCE_LATENCY: 867 (void) va_arg (ap, double);
857 count++; 868 break;
858 (void)va_arg(ap, double); 869
859 break; 870 default:
860 871 GNUNET_assert (0);
861 default:
862 GNUNET_assert(0);
863 }
864 } 872 }
865 va_end(ap); 873 }
866 env = GNUNET_MQ_msg_extra(m, 874 va_end (ap);
867 count * sizeof(struct PreferenceInformation), 875 env = GNUNET_MQ_msg_extra (m,
868 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE); 876 count * sizeof(struct PreferenceInformation),
869 m->num_preferences = htonl(count); 877 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE);
878 m->num_preferences = htonl (count);
870 m->peer = *peer; 879 m->peer = *peer;
871 pi = (struct PreferenceInformation *)&m[1]; 880 pi = (struct PreferenceInformation *) &m[1];
872 count = 0; 881 count = 0;
873 va_start(ap, peer); 882 va_start (ap, peer);
874 while (GNUNET_ATS_PREFERENCE_END != (kind = 883 while (GNUNET_ATS_PREFERENCE_END != (kind =
875 GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) 884 GNUNET_VA_ARG_ENUM (ap,
885 GNUNET_ATS_PreferenceKind)))
886 {
887 pi[count].preference_kind = htonl (kind);
888 switch (kind)
876 { 889 {
877 pi[count].preference_kind = htonl(kind); 890 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
878 switch (kind) 891 pi[count].preference_value = (float) va_arg (ap, double);
879 {
880 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
881 pi[count].preference_value = (float)va_arg(ap, double);
882 892
883 count++; 893 count++;
884 break; 894 break;
885 895
886 case GNUNET_ATS_PREFERENCE_LATENCY: 896 case GNUNET_ATS_PREFERENCE_LATENCY:
887 pi[count].preference_value = (float)va_arg(ap, double); 897 pi[count].preference_value = (float) va_arg (ap, double);
888 898
889 count++; 899 count++;
890 break; 900 break;
891 901
892 default: 902 default:
893 GNUNET_assert(0); 903 GNUNET_assert (0);
894 }
895 } 904 }
896 va_end(ap); 905 }
897 GNUNET_MQ_send(ph->mq, 906 va_end (ap);
898 env); 907 GNUNET_MQ_send (ph->mq,
908 env);
899} 909}
900 910
901 911
@@ -909,10 +919,10 @@ GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph
909 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes 919 * @param ... #GNUNET_ATS_PREFERENCE_END-terminated specification of the desired changes
910 */ 920 */
911void 921void
912GNUNET_ATS_performance_give_feedback(struct GNUNET_ATS_PerformanceHandle *ph, 922GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
913 const struct GNUNET_PeerIdentity *peer, 923 const struct GNUNET_PeerIdentity *peer,
914 const struct GNUNET_TIME_Relative scope, 924 const struct GNUNET_TIME_Relative scope,
915 ...) 925 ...)
916{ 926{
917 struct GNUNET_MQ_Envelope *env; 927 struct GNUNET_MQ_Envelope *env;
918 struct FeedbackPreferenceMessage *m; 928 struct FeedbackPreferenceMessage *m;
@@ -924,61 +934,62 @@ GNUNET_ATS_performance_give_feedback(struct GNUNET_ATS_PerformanceHandle *ph,
924 if (NULL == ph->mq) 934 if (NULL == ph->mq)
925 return; 935 return;
926 count = 0; 936 count = 0;
927 va_start(ap, scope); 937 va_start (ap, scope);
928 while (GNUNET_ATS_PREFERENCE_END != 938 while (GNUNET_ATS_PREFERENCE_END !=
929 (kind = GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) 939 (kind = GNUNET_VA_ARG_ENUM (ap, GNUNET_ATS_PreferenceKind)))
940 {
941 switch (kind)
930 { 942 {
931 switch (kind) 943 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
932 { 944 count++;
933 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 945 (void) va_arg (ap, double);
934 count++; 946 break;
935 (void)va_arg(ap, double); 947
936 break; 948 case GNUNET_ATS_PREFERENCE_LATENCY:
937 949 count++;
938 case GNUNET_ATS_PREFERENCE_LATENCY: 950 (void) va_arg (ap, double);
939 count++; 951 break;
940 (void)va_arg(ap, double); 952
941 break; 953 default:
942 954 GNUNET_assert (0);
943 default:
944 GNUNET_assert(0);
945 }
946 } 955 }
947 va_end(ap); 956 }
948 env = GNUNET_MQ_msg_extra(m, 957 va_end (ap);
949 count * sizeof(struct PreferenceInformation), 958 env = GNUNET_MQ_msg_extra (m,
950 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK); 959 count * sizeof(struct PreferenceInformation),
951 m->scope = GNUNET_TIME_relative_hton(scope); 960 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK);
952 m->num_feedback = htonl(count); 961 m->scope = GNUNET_TIME_relative_hton (scope);
962 m->num_feedback = htonl (count);
953 m->peer = *peer; 963 m->peer = *peer;
954 pi = (struct PreferenceInformation *)&m[1]; 964 pi = (struct PreferenceInformation *) &m[1];
955 count = 0; 965 count = 0;
956 va_start(ap, scope); 966 va_start (ap, scope);
957 while (GNUNET_ATS_PREFERENCE_END != (kind = 967 while (GNUNET_ATS_PREFERENCE_END != (kind =
958 GNUNET_VA_ARG_ENUM(ap, GNUNET_ATS_PreferenceKind))) 968 GNUNET_VA_ARG_ENUM (ap,
969 GNUNET_ATS_PreferenceKind)))
970 {
971 pi[count].preference_kind = htonl (kind);
972 switch (kind)
959 { 973 {
960 pi[count].preference_kind = htonl(kind); 974 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
961 switch (kind) 975 pi[count].preference_value = (float) va_arg (ap, double);
962 {
963 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
964 pi[count].preference_value = (float)va_arg(ap, double);
965 976
966 count++; 977 count++;
967 break; 978 break;
968 979
969 case GNUNET_ATS_PREFERENCE_LATENCY: 980 case GNUNET_ATS_PREFERENCE_LATENCY:
970 pi[count].preference_value = (float)va_arg(ap, double); 981 pi[count].preference_value = (float) va_arg (ap, double);
971 982
972 count++; 983 count++;
973 break; 984 break;
974 985
975 default: 986 default:
976 GNUNET_assert(0); 987 GNUNET_assert (0);
977 }
978 } 988 }
979 va_end(ap); 989 }
980 GNUNET_MQ_send(ph->mq, 990 va_end (ap);
981 env); 991 GNUNET_MQ_send (ph->mq,
992 env);
982} 993}
983 994
984/* end of ats_api_performance.c */ 995/* end of ats_api_performance.c */
diff --git a/src/ats/ats_api_scanner.c b/src/ats/ats_api_scanner.c
index 5c8ffe196..82114f888 100644
--- a/src/ats/ats_api_scanner.c
+++ b/src/ats/ats_api_scanner.c
@@ -33,14 +33,14 @@
33 * @param hbo value read 33 * @param hbo value read
34 */ 34 */
35void 35void
36GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, 36GNUNET_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 */
53void 53void
54GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo, 54GNUNET_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 f375be6a5..36162d12f 100644
--- a/src/ats/ats_api_scheduling.c
+++ b/src/ats/ats_api_scheduling.c
@@ -38,9 +38,10 @@
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 ( \
42 GNUNET_TIME_UNIT_MINUTES, 2)
42 43
43#define LOG(kind, ...) GNUNET_log_from(kind, "ats-scheduling-api", __VA_ARGS__) 44#define LOG(kind, ...) GNUNET_log_from (kind, "ats-scheduling-api", __VA_ARGS__)
44 45
45/** 46/**
46 * Session ID we use if there is no session / slot. 47 * Session ID we use if there is no session / slot.
@@ -53,7 +54,8 @@
53 * doesn't matter if we have a session, any address that ATS is 54 * doesn't matter if we have a session, any address that ATS is
54 * allowed to suggest right now should be tracked. 55 * allowed to suggest right now should be tracked.
55 */ 56 */
56struct GNUNET_ATS_AddressRecord { 57struct GNUNET_ATS_AddressRecord
58{
57 /** 59 /**
58 * Scheduling handle this address record belongs to. 60 * Scheduling handle this address record belongs to.
59 */ 61 */
@@ -97,7 +99,8 @@ struct GNUNET_ATS_AddressRecord {
97/** 99/**
98 * Handle to the ATS subsystem for bandwidth/transport scheduling information. 100 * Handle to the ATS subsystem for bandwidth/transport scheduling information.
99 */ 101 */
100struct GNUNET_ATS_SchedulingHandle { 102struct GNUNET_ATS_SchedulingHandle
103{
101 /** 104 /**
102 * Our configuration. 105 * Our configuration.
103 */ 106 */
@@ -149,7 +152,7 @@ struct GNUNET_ATS_SchedulingHandle {
149 * @param sh handle to use to re-connect. 152 * @param sh handle to use to re-connect.
150 */ 153 */
151static void 154static void
152reconnect(struct GNUNET_ATS_SchedulingHandle *sh); 155reconnect (struct GNUNET_ATS_SchedulingHandle *sh);
153 156
154 157
155/** 158/**
@@ -158,12 +161,12 @@ reconnect(struct GNUNET_ATS_SchedulingHandle *sh);
158 * @param cls handle to use to re-connect. 161 * @param cls handle to use to re-connect.
159 */ 162 */
160static void 163static void
161reconnect_task(void *cls) 164reconnect_task (void *cls)
162{ 165{
163 struct GNUNET_ATS_SchedulingHandle *sh = cls; 166 struct GNUNET_ATS_SchedulingHandle *sh = cls;
164 167
165 sh->task = NULL; 168 sh->task = NULL;
166 reconnect(sh); 169 reconnect (sh);
167} 170}
168 171
169 172
@@ -173,21 +176,21 @@ reconnect_task(void *cls)
173 * @param sh our handle 176 * @param sh our handle
174 */ 177 */
175static void 178static void
176force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh) 179force_reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
177{ 180{
178 if (NULL != sh->mq) 181 if (NULL != sh->mq)
179 { 182 {
180 GNUNET_MQ_destroy(sh->mq); 183 GNUNET_MQ_destroy (sh->mq);
181 sh->mq = NULL; 184 sh->mq = NULL;
182 } 185 }
183 sh->suggest_cb(sh->suggest_cb_cls, 186 sh->suggest_cb (sh->suggest_cb_cls,
184 NULL, NULL, NULL, 187 NULL, NULL, NULL,
185 GNUNET_BANDWIDTH_ZERO, 188 GNUNET_BANDWIDTH_ZERO,
186 GNUNET_BANDWIDTH_ZERO); 189 GNUNET_BANDWIDTH_ZERO);
187 sh->backoff = GNUNET_TIME_STD_BACKOFF(sh->backoff); 190 sh->backoff = GNUNET_TIME_STD_BACKOFF (sh->backoff);
188 sh->task = GNUNET_SCHEDULER_add_delayed(sh->backoff, 191 sh->task = GNUNET_SCHEDULER_add_delayed (sh->backoff,
189 &reconnect_task, 192 &reconnect_task,
190 sh); 193 sh);
191} 194}
192 195
193 196
@@ -200,37 +203,37 @@ force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
200 * @return the session object (or NULL) 203 * @return the session object (or NULL)
201 */ 204 */
202static struct GNUNET_ATS_AddressRecord * 205static struct GNUNET_ATS_AddressRecord *
203find_session(struct GNUNET_ATS_SchedulingHandle *sh, 206find_session (struct GNUNET_ATS_SchedulingHandle *sh,
204 uint32_t session_id, 207 uint32_t session_id,
205 const struct GNUNET_PeerIdentity *peer) 208 const struct GNUNET_PeerIdentity *peer)
206{ 209{
207 struct GNUNET_ATS_AddressRecord *ar; 210 struct GNUNET_ATS_AddressRecord *ar;
208 211
209 if (session_id >= sh->session_array_size) 212 if (session_id >= sh->session_array_size)
210 { 213 {
211 GNUNET_break(0); 214 GNUNET_break (0);
212 return NULL; 215 return NULL;
213 } 216 }
214 if (0 == session_id) 217 if (0 == session_id)
215 return NULL; 218 return NULL;
216 ar = sh->session_array[session_id]; 219 ar = sh->session_array[session_id];
217 if (NULL == ar) 220 if (NULL == ar)
218 { 221 {
219 GNUNET_break(0); 222 GNUNET_break (0);
220 return NULL; 223 return NULL;
221 } 224 }
222 if (NULL == ar->address) 225 if (NULL == ar->address)
223 { 226 {
224 /* address was destroyed in the meantime, this can happen 227 /* address was destroyed in the meantime, this can happen
225 as we communicate asynchronously with the ATS service. */ 228 as we communicate asynchronously with the ATS service. */
226 return NULL; 229 return NULL;
227 } 230 }
228 if (0 != GNUNET_memcmp(peer, 231 if (0 != GNUNET_memcmp (peer,
229 &ar->address->peer)) 232 &ar->address->peer))
230 { 233 {
231 GNUNET_break(0); 234 GNUNET_break (0);
232 return NULL; 235 return NULL;
233 } 236 }
234 return ar; 237 return ar;
235} 238}
236 239
@@ -242,27 +245,27 @@ find_session(struct GNUNET_ATS_SchedulingHandle *sh,
242 * @return an unused slot, but never NOT_FOUND (0) 245 * @return an unused slot, but never NOT_FOUND (0)
243 */ 246 */
244static uint32_t 247static uint32_t
245find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh) 248find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh)
246{ 249{
247 static uint32_t off; 250 static uint32_t off;
248 uint32_t i; 251 uint32_t i;
249 252
250 GNUNET_assert(0 != sh->session_array_size); 253 GNUNET_assert (0 != sh->session_array_size);
251 i = 0; 254 i = 0;
252 while (((NOT_FOUND == off) || 255 while (((NOT_FOUND == off) ||
253 (NULL != sh->session_array[off % sh->session_array_size])) && 256 (NULL != sh->session_array[off % sh->session_array_size])) &&
254 (i < sh->session_array_size)) 257 (i < sh->session_array_size))
255 { 258 {
256 off++; 259 off++;
257 i++; 260 i++;
258 } 261 }
259 if ((NOT_FOUND != off % sh->session_array_size) && 262 if ((NOT_FOUND != off % sh->session_array_size) &&
260 (NULL == sh->session_array[off % sh->session_array_size])) 263 (NULL == sh->session_array[off % sh->session_array_size]))
261 return off; 264 return off;
262 i = sh->session_array_size; 265 i = sh->session_array_size;
263 GNUNET_array_grow(sh->session_array, 266 GNUNET_array_grow (sh->session_array,
264 sh->session_array_size, 267 sh->session_array_size,
265 sh->session_array_size * 2); 268 sh->session_array_size * 2);
266 return i; 269 return i;
267} 270}
268 271
@@ -276,26 +279,26 @@ find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh)
276 * @return the session id or NOT_FOUND for error 279 * @return the session id or NOT_FOUND for error
277 */ 280 */
278static uint32_t 281static uint32_t
279find_session_id(struct GNUNET_ATS_SchedulingHandle *sh, 282find_session_id (struct GNUNET_ATS_SchedulingHandle *sh,
280 struct GNUNET_ATS_Session *session, 283 struct GNUNET_ATS_Session *session,
281 const struct GNUNET_HELLO_Address *address) 284 const struct GNUNET_HELLO_Address *address)
282{ 285{
283 uint32_t i; 286 uint32_t i;
284 287
285 if (NULL == address) 288 if (NULL == address)
286 { 289 {
287 GNUNET_break(0); 290 GNUNET_break (0);
288 return NOT_FOUND; 291 return NOT_FOUND;
289 } 292 }
290 for (i = 1; i < sh->session_array_size; i++) 293 for (i = 1; i < sh->session_array_size; i++)
291 if ((NULL != sh->session_array[i]) && 294 if ((NULL != sh->session_array[i]) &&
292 (GNUNET_NO == sh->session_array[i]->in_destroy) && 295 (GNUNET_NO == sh->session_array[i]->in_destroy) &&
293 ((session == sh->session_array[i]->session) || 296 ((session == sh->session_array[i]->session) ||
294 (NULL == sh->session_array[i]->session)) && 297 (NULL == sh->session_array[i]->session)) &&
295 (0 == GNUNET_memcmp(&address->peer, 298 (0 == GNUNET_memcmp (&address->peer,
296 &sh->session_array[i]->address->peer)) && 299 &sh->session_array[i]->address->peer)) &&
297 (0 == GNUNET_HELLO_address_cmp(address, 300 (0 == GNUNET_HELLO_address_cmp (address,
298 sh->session_array[i]->address))) 301 sh->session_array[i]->address)))
299 return i; 302 return i;
300 return NOT_FOUND; 303 return NOT_FOUND;
301} 304}
@@ -309,29 +312,29 @@ find_session_id(struct GNUNET_ATS_SchedulingHandle *sh,
309 * @param session_id identifies session that is no longer valid 312 * @param session_id identifies session that is no longer valid
310 */ 313 */
311static void 314static void
312release_session(struct GNUNET_ATS_SchedulingHandle *sh, 315release_session (struct GNUNET_ATS_SchedulingHandle *sh,
313 uint32_t session_id) 316 uint32_t session_id)
314{ 317{
315 struct GNUNET_ATS_AddressRecord *ar; 318 struct GNUNET_ATS_AddressRecord *ar;
316 319
317 if (NOT_FOUND == session_id) 320 if (NOT_FOUND == session_id)
318 return; 321 return;
319 if (session_id >= sh->session_array_size) 322 if (session_id >= sh->session_array_size)
320 { 323 {
321 GNUNET_break(0); 324 GNUNET_break (0);
322 force_reconnect(sh); 325 force_reconnect (sh);
323 return; 326 return;
324 } 327 }
325 /* this slot should have been removed from remove_session before */ 328 /* this slot should have been removed from remove_session before */
326 ar = sh->session_array[session_id]; 329 ar = sh->session_array[session_id];
327 if (NULL != ar->session) 330 if (NULL != ar->session)
328 { 331 {
329 GNUNET_break(0); 332 GNUNET_break (0);
330 force_reconnect(sh); 333 force_reconnect (sh);
331 return; 334 return;
332 } 335 }
333 GNUNET_HELLO_address_free(ar->address); 336 GNUNET_HELLO_address_free (ar->address);
334 GNUNET_free(ar); 337 GNUNET_free (ar);
335 sh->session_array[session_id] = NULL; 338 sh->session_array[session_id] = NULL;
336} 339}
337 340
@@ -344,15 +347,15 @@ release_session(struct GNUNET_ATS_SchedulingHandle *sh,
344 * @param srm message received 347 * @param srm message received
345 */ 348 */
346static void 349static void
347handle_ats_session_release(void *cls, 350handle_ats_session_release (void *cls,
348 const struct GNUNET_ATS_SessionReleaseMessage *srm) 351 const struct GNUNET_ATS_SessionReleaseMessage *srm)
349{ 352{
350 struct GNUNET_ATS_SchedulingHandle *sh = cls; 353 struct GNUNET_ATS_SchedulingHandle *sh = cls;
351 354
352 /* Note: peer field in srm not necessary right now, 355 /* Note: peer field in srm not necessary right now,
353 but might be good to have in the future */ 356 but might be good to have in the future */
354 release_session(sh, 357 release_session (sh,
355 ntohl(srm->session_id)); 358 ntohl (srm->session_id));
356} 359}
357 360
358 361
@@ -364,71 +367,71 @@ handle_ats_session_release(void *cls,
364 * @param m message received 367 * @param m message received
365 */ 368 */
366static void 369static void
367handle_ats_address_suggestion(void *cls, 370handle_ats_address_suggestion (void *cls,
368 const struct AddressSuggestionMessage *m) 371 const struct AddressSuggestionMessage *m)
369{ 372{
370 struct GNUNET_ATS_SchedulingHandle *sh = cls; 373 struct GNUNET_ATS_SchedulingHandle *sh = cls;
371 struct GNUNET_ATS_AddressRecord *ar; 374 struct GNUNET_ATS_AddressRecord *ar;
372 uint32_t session_id; 375 uint32_t session_id;
373 376
374 session_id = ntohl(m->session_id); 377 session_id = ntohl (m->session_id);
375 if (0 == session_id) 378 if (0 == session_id)
376 { 379 {
377 GNUNET_break(0); 380 GNUNET_break (0);
378 force_reconnect(sh); 381 force_reconnect (sh);
379 return; 382 return;
380 } 383 }
381 ar = find_session(sh, 384 ar = find_session (sh,
382 session_id, 385 session_id,
383 &m->peer); 386 &m->peer);
384 if (NULL == ar) 387 if (NULL == ar)
385 { 388 {
386 GNUNET_break(0); 389 GNUNET_break (0);
387 force_reconnect(sh); 390 force_reconnect (sh);
388 return; 391 return;
389 } 392 }
390 if (NULL == sh->suggest_cb) 393 if (NULL == sh->suggest_cb)
391 return; 394 return;
392 if (GNUNET_YES == ar->in_destroy) 395 if (GNUNET_YES == ar->in_destroy)
396 {
397 /* ignore suggestion, as this address is dying, unless BW is 0,
398 in that case signal 'disconnect' via BW 0 */
399 if ((0 == ntohl (m->bandwidth_out.value__)) &&
400 (0 == ntohl (m->bandwidth_in.value__)))
393 { 401 {
394 /* ignore suggestion, as this address is dying, unless BW is 0, 402 LOG (GNUNET_ERROR_TYPE_DEBUG,
395 in that case signal 'disconnect' via BW 0 */ 403 "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
396 if ((0 == ntohl(m->bandwidth_out.value__)) && 404 GNUNET_i2s (&ar->address->peer),
397 (0 == ntohl(m->bandwidth_in.value__))) 405 (unsigned int) ntohl (m->bandwidth_out.value__),
398 { 406 (unsigned int) ntohl (m->bandwidth_in.value__));
399 LOG(GNUNET_ERROR_TYPE_DEBUG, 407 sh->suggest_cb (sh->suggest_cb_cls,
400 "ATS suggests disconnect from peer `%s' with BW %u/%u\n", 408 &m->peer,
401 GNUNET_i2s(&ar->address->peer), 409 NULL,
402 (unsigned int)ntohl(m->bandwidth_out.value__), 410 NULL,
403 (unsigned int)ntohl(m->bandwidth_in.value__)); 411 m->bandwidth_out,
404 sh->suggest_cb(sh->suggest_cb_cls, 412 m->bandwidth_in);
405 &m->peer,
406 NULL,
407 NULL,
408 m->bandwidth_out,
409 m->bandwidth_in);
410 }
411 return;
412 } 413 }
414 return;
415 }
413 if ((NULL == ar->session) && 416 if ((NULL == ar->session) &&
414 (GNUNET_HELLO_address_check_option(ar->address, 417 (GNUNET_HELLO_address_check_option (ar->address,
415 GNUNET_HELLO_ADDRESS_INFO_INBOUND))) 418 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
416 { 419 {
417 GNUNET_break(0); 420 GNUNET_break (0);
418 return; 421 return;
419 } 422 }
420 sh->backoff = GNUNET_TIME_UNIT_ZERO; 423 sh->backoff = GNUNET_TIME_UNIT_ZERO;
421 LOG(GNUNET_ERROR_TYPE_DEBUG, 424 LOG (GNUNET_ERROR_TYPE_DEBUG,
422 "ATS suggests address slot %u for peer `%s' using plugin %s\n", 425 "ATS suggests address slot %u for peer `%s' using plugin %s\n",
423 ar->slot, 426 ar->slot,
424 GNUNET_i2s(&ar->address->peer), 427 GNUNET_i2s (&ar->address->peer),
425 ar->address->transport_name); 428 ar->address->transport_name);
426 sh->suggest_cb(sh->suggest_cb_cls, 429 sh->suggest_cb (sh->suggest_cb_cls,
427 &m->peer, 430 &m->peer,
428 ar->address, 431 ar->address,
429 ar->session, 432 ar->session,
430 m->bandwidth_out, 433 m->bandwidth_out,
431 m->bandwidth_in); 434 m->bandwidth_in);
432} 435}
433 436
434 437
@@ -440,15 +443,15 @@ handle_ats_address_suggestion(void *cls,
440 * @param error details about the error 443 * @param error details about the error
441 */ 444 */
442static void 445static void
443error_handler(void *cls, 446error_handler (void *cls,
444 enum GNUNET_MQ_Error error) 447 enum GNUNET_MQ_Error error)
445{ 448{
446 struct GNUNET_ATS_SchedulingHandle *sh = cls; 449 struct GNUNET_ATS_SchedulingHandle *sh = cls;
447 450
448 LOG(GNUNET_ERROR_TYPE_DEBUG, 451 LOG (GNUNET_ERROR_TYPE_DEBUG,
449 "ATS connection died (code %d), reconnecting\n", 452 "ATS connection died (code %d), reconnecting\n",
450 (int)error); 453 (int) error);
451 force_reconnect(sh); 454 force_reconnect (sh);
452} 455}
453 456
454 457
@@ -460,8 +463,8 @@ error_handler(void *cls,
460 * @param ar the address to inform the ATS service about 463 * @param ar the address to inform the ATS service about
461 */ 464 */
462static void 465static void
463send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh, 466send_add_address_message (struct GNUNET_ATS_SchedulingHandle *sh,
464 const struct GNUNET_ATS_AddressRecord *ar) 467 const struct GNUNET_ATS_AddressRecord *ar)
465{ 468{
466 struct GNUNET_MQ_Envelope *ev; 469 struct GNUNET_MQ_Envelope *ev;
467 struct AddressAddMessage *m; 470 struct AddressAddMessage *m;
@@ -471,32 +474,32 @@ send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh,
471 474
472 if (NULL == sh->mq) 475 if (NULL == sh->mq)
473 return; /* disconnected, skip for now */ 476 return; /* disconnected, skip for now */
474 GNUNET_break(GNUNET_NT_UNSPECIFIED != ar->properties.scope); 477 GNUNET_break (GNUNET_NT_UNSPECIFIED != ar->properties.scope);
475 namelen = strlen(ar->address->transport_name) + 1; 478 namelen = strlen (ar->address->transport_name) + 1;
476 msize = ar->address->address_length + namelen; 479 msize = ar->address->address_length + namelen;
477 ev = GNUNET_MQ_msg_extra(m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); 480 ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD);
478 m->peer = ar->address->peer; 481 m->peer = ar->address->peer;
479 m->address_length = htons(ar->address->address_length); 482 m->address_length = htons (ar->address->address_length);
480 m->address_local_info = htonl((uint32_t)ar->address->local_info); 483 m->address_local_info = htonl ((uint32_t) ar->address->local_info);
481 m->plugin_name_length = htons(namelen); 484 m->plugin_name_length = htons (namelen);
482 m->session_id = htonl(ar->slot); 485 m->session_id = htonl (ar->slot);
483 m->properties = ar->properties; 486 m->properties = ar->properties;
484 487
485 LOG(GNUNET_ERROR_TYPE_DEBUG, 488 LOG (GNUNET_ERROR_TYPE_DEBUG,
486 "Adding address for peer `%s', plugin `%s', session %p slot %u\n", 489 "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
487 GNUNET_i2s(&ar->address->peer), 490 GNUNET_i2s (&ar->address->peer),
488 ar->address->transport_name, 491 ar->address->transport_name,
489 ar->session, 492 ar->session,
490 ar->slot); 493 ar->slot);
491 pm = (char *)&m[1]; 494 pm = (char *) &m[1];
492 GNUNET_memcpy(pm, 495 GNUNET_memcpy (pm,
493 ar->address->address, 496 ar->address->address,
494 ar->address->address_length); 497 ar->address->address_length);
495 if (NULL != ar->address->transport_name) 498 if (NULL != ar->address->transport_name)
496 GNUNET_memcpy(&pm[ar->address->address_length], 499 GNUNET_memcpy (&pm[ar->address->address_length],
497 ar->address->transport_name, 500 ar->address->transport_name,
498 namelen); 501 namelen);
499 GNUNET_MQ_send(sh->mq, ev); 502 GNUNET_MQ_send (sh->mq, ev);
500} 503}
501 504
502 505
@@ -506,51 +509,51 @@ send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh,
506 * @param sh handle to use to re-connect. 509 * @param sh handle to use to re-connect.
507 */ 510 */
508static void 511static void
509reconnect(struct GNUNET_ATS_SchedulingHandle *sh) 512reconnect (struct GNUNET_ATS_SchedulingHandle *sh)
510{ 513{
511 struct GNUNET_MQ_MessageHandler handlers[] = { 514 struct GNUNET_MQ_MessageHandler handlers[] = {
512 GNUNET_MQ_hd_fixed_size(ats_session_release, 515 GNUNET_MQ_hd_fixed_size (ats_session_release,
513 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE, 516 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE,
514 struct GNUNET_ATS_SessionReleaseMessage, 517 struct GNUNET_ATS_SessionReleaseMessage,
515 sh), 518 sh),
516 GNUNET_MQ_hd_fixed_size(ats_address_suggestion, 519 GNUNET_MQ_hd_fixed_size (ats_address_suggestion,
517 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, 520 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION,
518 struct AddressSuggestionMessage, 521 struct AddressSuggestionMessage,
519 sh), 522 sh),
520 GNUNET_MQ_handler_end() 523 GNUNET_MQ_handler_end ()
521 }; 524 };
522 struct GNUNET_MQ_Envelope *ev; 525 struct GNUNET_MQ_Envelope *ev;
523 struct ClientStartMessage *init; 526 struct ClientStartMessage *init;
524 unsigned int i; 527 unsigned int i;
525 struct GNUNET_ATS_AddressRecord *ar; 528 struct GNUNET_ATS_AddressRecord *ar;
526 529
527 GNUNET_assert(NULL == sh->mq); 530 GNUNET_assert (NULL == sh->mq);
528 sh->mq = GNUNET_CLIENT_connect(sh->cfg, 531 sh->mq = GNUNET_CLIENT_connect (sh->cfg,
529 "ats", 532 "ats",
530 handlers, 533 handlers,
531 &error_handler, 534 &error_handler,
532 sh); 535 sh);
533 if (NULL == sh->mq) 536 if (NULL == sh->mq)
534 { 537 {
535 GNUNET_break(0); 538 GNUNET_break (0);
536 force_reconnect(sh); 539 force_reconnect (sh);
537 return; 540 return;
538 } 541 }
539 ev = GNUNET_MQ_msg(init, 542 ev = GNUNET_MQ_msg (init,
540 GNUNET_MESSAGE_TYPE_ATS_START); 543 GNUNET_MESSAGE_TYPE_ATS_START);
541 init->start_flag = htonl(START_FLAG_SCHEDULING); 544 init->start_flag = htonl (START_FLAG_SCHEDULING);
542 GNUNET_MQ_send(sh->mq, ev); 545 GNUNET_MQ_send (sh->mq, ev);
543 if (NULL == sh->mq) 546 if (NULL == sh->mq)
544 return; 547 return;
545 for (i = 0; i < sh->session_array_size; i++) 548 for (i = 0; i < sh->session_array_size; i++)
546 { 549 {
547 ar = sh->session_array[i]; 550 ar = sh->session_array[i];
548 if (NULL == ar) 551 if (NULL == ar)
549 continue; 552 continue;
550 send_add_address_message(sh, ar); 553 send_add_address_message (sh, ar);
551 if (NULL == sh->mq) 554 if (NULL == sh->mq)
552 return; 555 return;
553 } 556 }
554} 557}
555 558
556 559
@@ -563,20 +566,20 @@ reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
563 * @return ats context 566 * @return ats context
564 */ 567 */
565struct GNUNET_ATS_SchedulingHandle * 568struct GNUNET_ATS_SchedulingHandle *
566GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg, 569GNUNET_ATS_scheduling_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
567 GNUNET_ATS_AddressSuggestionCallback suggest_cb, 570 GNUNET_ATS_AddressSuggestionCallback suggest_cb,
568 void *suggest_cb_cls) 571 void *suggest_cb_cls)
569{ 572{
570 struct GNUNET_ATS_SchedulingHandle *sh; 573 struct GNUNET_ATS_SchedulingHandle *sh;
571 574
572 sh = GNUNET_new(struct GNUNET_ATS_SchedulingHandle); 575 sh = GNUNET_new (struct GNUNET_ATS_SchedulingHandle);
573 sh->cfg = cfg; 576 sh->cfg = cfg;
574 sh->suggest_cb = suggest_cb; 577 sh->suggest_cb = suggest_cb;
575 sh->suggest_cb_cls = suggest_cb_cls; 578 sh->suggest_cb_cls = suggest_cb_cls;
576 GNUNET_array_grow(sh->session_array, 579 GNUNET_array_grow (sh->session_array,
577 sh->session_array_size, 580 sh->session_array_size,
578 4); 581 4);
579 reconnect(sh); 582 reconnect (sh);
580 return sh; 583 return sh;
581} 584}
582 585
@@ -587,34 +590,34 @@ GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg,
587 * @param sh handle to release 590 * @param sh handle to release
588 */ 591 */
589void 592void
590GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh) 593GNUNET_ATS_scheduling_done (struct GNUNET_ATS_SchedulingHandle *sh)
591{ 594{
592 struct GNUNET_ATS_AddressRecord *ar; 595 struct GNUNET_ATS_AddressRecord *ar;
593 unsigned int i; 596 unsigned int i;
594 597
595 if (NULL != sh->mq) 598 if (NULL != sh->mq)
596 { 599 {
597 GNUNET_MQ_destroy(sh->mq); 600 GNUNET_MQ_destroy (sh->mq);
598 sh->mq = NULL; 601 sh->mq = NULL;
599 } 602 }
600 if (NULL != sh->task) 603 if (NULL != sh->task)
601 { 604 {
602 GNUNET_SCHEDULER_cancel(sh->task); 605 GNUNET_SCHEDULER_cancel (sh->task);
603 sh->task = NULL; 606 sh->task = NULL;
604 } 607 }
605 for (i = 0; i < sh->session_array_size; i++) 608 for (i = 0; i < sh->session_array_size; i++)
609 {
610 if (NULL != (ar = sh->session_array[i]))
606 { 611 {
607 if (NULL != (ar = sh->session_array[i])) 612 GNUNET_HELLO_address_free (ar->address);
608 { 613 GNUNET_free (ar);
609 GNUNET_HELLO_address_free(ar->address); 614 sh->session_array[i] = NULL;
610 GNUNET_free(ar);
611 sh->session_array[i] = NULL;
612 }
613 } 615 }
614 GNUNET_array_grow(sh->session_array, 616 }
615 sh->session_array_size, 617 GNUNET_array_grow (sh->session_array,
616 0); 618 sh->session_array_size,
617 GNUNET_free(sh); 619 0);
620 GNUNET_free (sh);
618} 621}
619 622
620 623
@@ -631,10 +634,10 @@ GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh)
631 * on error (i.e. ATS knows this exact address already) 634 * on error (i.e. ATS knows this exact address already)
632 */ 635 */
633struct GNUNET_ATS_AddressRecord * 636struct GNUNET_ATS_AddressRecord *
634GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh, 637GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
635 const struct GNUNET_HELLO_Address *address, 638 const struct GNUNET_HELLO_Address *address,
636 struct GNUNET_ATS_Session *session, 639 struct GNUNET_ATS_Session *session,
637 const struct GNUNET_ATS_Properties *prop) 640 const struct GNUNET_ATS_Properties *prop)
638{ 641{
639 struct GNUNET_ATS_AddressRecord *ar; 642 struct GNUNET_ATS_AddressRecord *ar;
640 size_t namelen; 643 size_t namelen;
@@ -642,42 +645,43 @@ GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh,
642 uint32_t s; 645 uint32_t s;
643 646
644 if (NULL == address) 647 if (NULL == address)
645 { 648 {
646 /* we need a valid address */ 649 /* we need a valid address */
647 GNUNET_break(0); 650 GNUNET_break (0);
648 return NULL; 651 return NULL;
649 } 652 }
650 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 653 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
651 namelen = strlen(address->transport_name) + 1; 654 namelen = strlen (address->transport_name) + 1;
652 msize = address->address_length + namelen; 655 msize = address->address_length + namelen;
653 if ((msize + sizeof(struct AddressUpdateMessage) >= GNUNET_MAX_MESSAGE_SIZE) || 656 if ((msize + sizeof(struct AddressUpdateMessage) >=
657 GNUNET_MAX_MESSAGE_SIZE) ||
654 (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) || 658 (address->address_length >= GNUNET_MAX_MESSAGE_SIZE) ||
655 (namelen >= GNUNET_MAX_MESSAGE_SIZE)) 659 (namelen >= GNUNET_MAX_MESSAGE_SIZE))
656 { 660 {
657 /* address too large for us, this should not happen */ 661 /* address too large for us, this should not happen */
658 GNUNET_break(0); 662 GNUNET_break (0);
659 return NULL; 663 return NULL;
660 } 664 }
661 665
662 if (NOT_FOUND != 666 if (NOT_FOUND !=
663 find_session_id(sh, 667 find_session_id (sh,
664 session, 668 session,
665 address)) 669 address))
666 { 670 {
667 /* Already existing, nothing todo, but this should not happen */ 671 /* Already existing, nothing todo, but this should not happen */
668 GNUNET_break(0); 672 GNUNET_break (0);
669 return NULL; 673 return NULL;
670 } 674 }
671 s = find_empty_session_slot(sh); 675 s = find_empty_session_slot (sh);
672 ar = GNUNET_new(struct GNUNET_ATS_AddressRecord); 676 ar = GNUNET_new (struct GNUNET_ATS_AddressRecord);
673 ar->sh = sh; 677 ar->sh = sh;
674 ar->slot = s; 678 ar->slot = s;
675 ar->session = session; 679 ar->session = session;
676 ar->address = GNUNET_HELLO_address_copy(address); 680 ar->address = GNUNET_HELLO_address_copy (address);
677 GNUNET_ATS_properties_hton(&ar->properties, 681 GNUNET_ATS_properties_hton (&ar->properties,
678 prop); 682 prop);
679 sh->session_array[s] = ar; 683 sh->session_array[s] = ar;
680 send_add_address_message(sh, ar); 684 send_add_address_message (sh, ar);
681 return ar; 685 return ar;
682} 686}
683 687
@@ -689,10 +693,10 @@ GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh,
689 * @param session session handle 693 * @param session session handle
690 */ 694 */
691void 695void
692GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar, 696GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
693 struct GNUNET_ATS_Session *session) 697 struct GNUNET_ATS_Session *session)
694{ 698{
695 GNUNET_break(NULL == ar->session); 699 GNUNET_break (NULL == ar->session);
696 ar->session = session; 700 ar->session = session;
697} 701}
698 702
@@ -710,17 +714,17 @@ GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar,
710 * use it still to establish a new session 714 * use it still to establish a new session
711 */ 715 */
712int 716int
713GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar, 717GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
714 struct GNUNET_ATS_Session *session) 718 struct GNUNET_ATS_Session *session)
715{ 719{
716 GNUNET_assert(session == ar->session); 720 GNUNET_assert (session == ar->session);
717 ar->session = NULL; 721 ar->session = NULL;
718 if (GNUNET_HELLO_address_check_option(ar->address, 722 if (GNUNET_HELLO_address_check_option (ar->address,
719 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 723 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
720 { 724 {
721 GNUNET_ATS_address_destroy(ar); 725 GNUNET_ATS_address_destroy (ar);
722 return GNUNET_YES; 726 return GNUNET_YES;
723 } 727 }
724 return GNUNET_NO; 728 return GNUNET_NO;
725} 729}
726 730
@@ -737,30 +741,30 @@ GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar,
737 * @param prop performance data for the address 741 * @param prop performance data for the address
738 */ 742 */
739void 743void
740GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar, 744GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
741 const struct GNUNET_ATS_Properties *prop) 745 const struct GNUNET_ATS_Properties *prop)
742{ 746{
743 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; 747 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
744 struct GNUNET_MQ_Envelope *ev; 748 struct GNUNET_MQ_Envelope *ev;
745 struct AddressUpdateMessage *m; 749 struct AddressUpdateMessage *m;
746 750
747 LOG(GNUNET_ERROR_TYPE_DEBUG, 751 LOG (GNUNET_ERROR_TYPE_DEBUG,
748 "Updating address for peer `%s', plugin `%s', session %p slot %u\n", 752 "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
749 GNUNET_i2s(&ar->address->peer), 753 GNUNET_i2s (&ar->address->peer),
750 ar->address->transport_name, 754 ar->address->transport_name,
751 ar->session, 755 ar->session,
752 ar->slot); 756 ar->slot);
753 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 757 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
754 GNUNET_ATS_properties_hton(&ar->properties, 758 GNUNET_ATS_properties_hton (&ar->properties,
755 prop); 759 prop);
756 if (NULL == sh->mq) 760 if (NULL == sh->mq)
757 return; /* disconnected, skip for now */ 761 return; /* disconnected, skip for now */
758 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); 762 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
759 m->session_id = htonl(ar->slot); 763 m->session_id = htonl (ar->slot);
760 m->peer = ar->address->peer; 764 m->peer = ar->address->peer;
761 m->properties = ar->properties; 765 m->properties = ar->properties;
762 GNUNET_MQ_send(sh->mq, 766 GNUNET_MQ_send (sh->mq,
763 ev); 767 ev);
764} 768}
765 769
766 770
@@ -770,27 +774,27 @@ GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar,
770 * @param ar address to destroy 774 * @param ar address to destroy
771 */ 775 */
772void 776void
773GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar) 777GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
774{ 778{
775 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh; 779 struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
776 struct GNUNET_MQ_Envelope *ev; 780 struct GNUNET_MQ_Envelope *ev;
777 struct AddressDestroyedMessage *m; 781 struct AddressDestroyedMessage *m;
778 782
779 LOG(GNUNET_ERROR_TYPE_DEBUG, 783 LOG (GNUNET_ERROR_TYPE_DEBUG,
780 "Deleting address for peer `%s', plugin `%s', slot %u session %p\n", 784 "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
781 GNUNET_i2s(&ar->address->peer), 785 GNUNET_i2s (&ar->address->peer),
782 ar->address->transport_name, 786 ar->address->transport_name,
783 ar->slot, 787 ar->slot,
784 ar->session); 788 ar->session);
785 GNUNET_break(NULL == ar->session); 789 GNUNET_break (NULL == ar->session);
786 ar->session = NULL; 790 ar->session = NULL;
787 ar->in_destroy = GNUNET_YES; 791 ar->in_destroy = GNUNET_YES;
788 if (NULL == sh->mq) 792 if (NULL == sh->mq)
789 return; 793 return;
790 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED); 794 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
791 m->session_id = htonl(ar->slot); 795 m->session_id = htonl (ar->slot);
792 m->peer = ar->address->peer; 796 m->peer = ar->address->peer;
793 GNUNET_MQ_send(sh->mq, ev); 797 GNUNET_MQ_send (sh->mq, ev);
794} 798}
795 799
796 800
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c
index 4068cffce..9866ca929 100644
--- a/src/ats/gnunet-ats-solver-eval.c
+++ b/src/ats/gnunet-ats-solver-eval.c
@@ -85,35 +85,35 @@ static int opt_disable_normalization;
85static int res; 85static int res;
86 86
87static void 87static void
88end_now(); 88end_now ();
89 89
90 90
91static char * 91static char *
92print_generator_type(enum GeneratorType g) 92print_generator_type (enum GeneratorType g)
93{ 93{
94 switch (g) 94 switch (g)
95 { 95 {
96 case GNUNET_ATS_TEST_TG_CONSTANT: 96 case GNUNET_ATS_TEST_TG_CONSTANT:
97 return "CONSTANT"; 97 return "CONSTANT";
98 98
99 case GNUNET_ATS_TEST_TG_LINEAR: 99 case GNUNET_ATS_TEST_TG_LINEAR:
100 return "LINEAR"; 100 return "LINEAR";
101 101
102 case GNUNET_ATS_TEST_TG_RANDOM: 102 case GNUNET_ATS_TEST_TG_RANDOM:
103 return "RANDOM"; 103 return "RANDOM";
104 104
105 case GNUNET_ATS_TEST_TG_SINUS: 105 case GNUNET_ATS_TEST_TG_SINUS:
106 return "SINUS"; 106 return "SINUS";
107 107
108 default: 108 default:
109 return "INVALID"; 109 return "INVALID";
110 break; 110 break;
111 } 111 }
112} 112}
113 113
114 114
115static struct TestPeer * 115static struct TestPeer *
116find_peer_by_id(int id) 116find_peer_by_id (int id)
117{ 117{
118 struct TestPeer *cur; 118 struct TestPeer *cur;
119 119
@@ -124,18 +124,18 @@ find_peer_by_id(int id)
124} 124}
125 125
126static struct TestPeer * 126static struct TestPeer *
127find_peer_by_pid(const struct GNUNET_PeerIdentity *pid) 127find_peer_by_pid (const struct GNUNET_PeerIdentity *pid)
128{ 128{
129 struct TestPeer *cur; 129 struct TestPeer *cur;
130 130
131 for (cur = peer_head; NULL != cur; cur = cur->next) 131 for (cur = peer_head; NULL != cur; cur = cur->next)
132 if (0 == GNUNET_memcmp(&cur->peer_id, pid)) 132 if (0 == GNUNET_memcmp (&cur->peer_id, pid))
133 return cur; 133 return cur;
134 return NULL; 134 return NULL;
135} 135}
136 136
137static struct TestAddress * 137static struct TestAddress *
138find_address_by_id(struct TestPeer *peer, int aid) 138find_address_by_id (struct TestPeer *peer, int aid)
139{ 139{
140 struct TestAddress *cur; 140 struct TestAddress *cur;
141 141
@@ -150,7 +150,7 @@ find_address_by_id(struct TestPeer *peer, int aid)
150 * Logging 150 * Logging
151 */ 151 */
152void 152void
153GNUNET_ATS_solver_logging_now(struct LoggingHandle *l) 153GNUNET_ATS_solver_logging_now (struct LoggingHandle *l)
154{ 154{
155 struct LoggingTimeStep *lts; 155 struct LoggingTimeStep *lts;
156 struct TestPeer *cur; 156 struct TestPeer *cur;
@@ -159,111 +159,114 @@ GNUNET_ATS_solver_logging_now(struct LoggingHandle *l)
159 struct LoggingAddress *log_a; 159 struct LoggingAddress *log_a;
160 int c; 160 int c;
161 161
162 lts = GNUNET_new(struct LoggingTimeStep); 162 lts = GNUNET_new (struct LoggingTimeStep);
163 GNUNET_CONTAINER_DLL_insert_tail(l->head, l->tail, lts); 163 GNUNET_CONTAINER_DLL_insert_tail (l->head, l->tail, lts);
164 lts->timestamp = GNUNET_TIME_absolute_get(); 164 lts->timestamp = GNUNET_TIME_absolute_get ();
165 if (NULL == lts->prev) 165 if (NULL == lts->prev)
166 lts->delta = GNUNET_TIME_UNIT_ZERO; 166 lts->delta = GNUNET_TIME_UNIT_ZERO;
167 else 167 else
168 lts->delta = GNUNET_TIME_absolute_get_duration(lts->prev->timestamp); 168 lts->delta = GNUNET_TIME_absolute_get_duration (lts->prev->timestamp);
169 169
170 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n", 170 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Logging %llu, delta %llu\n",
171 lts->timestamp.abs_value_us, lts->delta.rel_value_us); 171 lts->timestamp.abs_value_us, lts->delta.rel_value_us);
172 172
173 173
174 /* Store logging data here */ 174 /* Store logging data here */
175 for (cur = peer_head; NULL != cur; cur = cur->next) 175 for (cur = peer_head; NULL != cur; cur = cur->next)
176 { 176 {
177 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
178 "Logging peer id %llu\n", cur->id); 178 "Logging peer id %llu\n", cur->id);
179 179
180 log_p = GNUNET_new(struct LoggingPeer); 180 log_p = GNUNET_new (struct LoggingPeer);
181 log_p->id = cur->id; 181 log_p->id = cur->id;
182 log_p->peer_id = cur->peer_id; 182 log_p->peer_id = cur->peer_id;
183 log_p->is_requested = cur->is_requested; 183 log_p->is_requested = cur->is_requested;
184 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 184 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
185 { 185 {
186 log_p->pref_abs[c] = cur->pref_abs[c]; 186 log_p->pref_abs[c] = cur->pref_abs[c];
187 log_p->pref_norm[c] = cur->pref_norm[c]; 187 log_p->pref_norm[c] = cur->pref_norm[c];
188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "\t %s = %.2f %.2f [abs/rel]\n", 189 "\t %s = %.2f %.2f [abs/rel]\n",
190 GNUNET_ATS_print_preference_type(c), 190 GNUNET_ATS_print_preference_type (c),
191 log_p->pref_abs[c], log_p->pref_norm[c]); 191 log_p->pref_abs[c], log_p->pref_norm[c]);
192 } 192 }
193 GNUNET_CONTAINER_DLL_insert_tail(lts->head, lts->tail, log_p); 193 GNUNET_CONTAINER_DLL_insert_tail (lts->head, lts->tail, log_p);
194
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",
218 log_a->assigned_bw_in);
219 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t BW out = %llu\n",
220 log_a->assigned_bw_out);
194 221
195 for (cur_addr = cur->addr_head; NULL != cur_addr; cur_addr = cur_addr->next) 222 GNUNET_CONTAINER_DLL_insert_tail (log_p->addr_head, log_p->addr_tail,
196 { 223 log_a);
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 }
222 } 224 }
225 }
223} 226}
224 227
225 228
226static void 229static void
227logging_task(void *cls) 230logging_task (void *cls)
228{ 231{
229 struct LoggingHandle *l = cls; 232 struct LoggingHandle *l = cls;
230 233
231 l->logging_task = NULL; 234 l->logging_task = NULL;
232 GNUNET_ATS_solver_logging_now(l); 235 GNUNET_ATS_solver_logging_now (l);
233 l->logging_task = GNUNET_SCHEDULER_add_delayed(l->log_freq, 236 l->logging_task = GNUNET_SCHEDULER_add_delayed (l->log_freq,
234 &logging_task, 237 &logging_task,
235 l); 238 l);
236} 239}
237 240
238struct LoggingHandle * 241struct LoggingHandle *
239GNUNET_ATS_solver_logging_start(struct GNUNET_TIME_Relative freq) 242GNUNET_ATS_solver_logging_start (struct GNUNET_TIME_Relative freq)
240{ 243{
241 struct LoggingHandle *l; 244 struct LoggingHandle *l;
242 245
243 l = GNUNET_new(struct LoggingHandle); 246 l = GNUNET_new (struct LoggingHandle);
244 247
245 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n", 248 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start logging every %s\n",
246 GNUNET_STRINGS_relative_time_to_string(freq, GNUNET_NO)); 249 GNUNET_STRINGS_relative_time_to_string (freq, GNUNET_NO));
247 l->log_freq = freq; 250 l->log_freq = freq;
248 l->logging_task = GNUNET_SCHEDULER_add_now(&logging_task, l); 251 l->logging_task = GNUNET_SCHEDULER_add_now (&logging_task, l);
249 return l; 252 return l;
250} 253}
251 254
252void 255void
253GNUNET_ATS_solver_logging_stop(struct LoggingHandle *l) 256GNUNET_ATS_solver_logging_stop (struct LoggingHandle *l)
254{ 257{
255 if (NULL != l->logging_task) 258 if (NULL != l->logging_task)
256 GNUNET_SCHEDULER_cancel(l->logging_task); 259 GNUNET_SCHEDULER_cancel (l->logging_task);
257 260
258 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Stop logging\n"); 261 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stop logging\n");
259 262
260 l->logging_task = NULL; 263 l->logging_task = NULL;
261} 264}
262 265
263static struct LoggingFileHandle * 266static struct LoggingFileHandle *
264find_logging_file_handle(struct LoggingFileHandle *lf_head, 267find_logging_file_handle (struct LoggingFileHandle *lf_head,
265 struct LoggingFileHandle *lf_tail, 268 struct LoggingFileHandle *lf_tail,
266 int peer_id, int address_id) 269 int peer_id, int address_id)
267{ 270{
268 struct LoggingFileHandle *res; 271 struct LoggingFileHandle *res;
269 272
@@ -274,8 +277,9 @@ find_logging_file_handle(struct LoggingFileHandle *lf_head,
274} 277}
275 278
276void 279void
277GNUNET_ATS_solver_logging_write_to_disk(struct LoggingHandle *l, int add_time_stamp, 280GNUNET_ATS_solver_logging_write_to_disk (struct LoggingHandle *l, int
278 char *output_dir) 281 add_time_stamp,
282 char *output_dir)
279{ 283{
280 struct LoggingTimeStep *lts; 284 struct LoggingTimeStep *lts;
281 struct LoggingPeer *log_p; 285 struct LoggingPeer *log_p;
@@ -284,164 +288,169 @@ GNUNET_ATS_solver_logging_write_to_disk(struct LoggingHandle *l, int add_time_st
284 struct LoggingFileHandle *lf_tail; 288 struct LoggingFileHandle *lf_tail;
285 struct LoggingFileHandle *cur; 289 struct LoggingFileHandle *cur;
286 struct LoggingFileHandle *next; 290 struct LoggingFileHandle *next;
287 char * filename; 291 char *filename;
288 char * datastring; 292 char *datastring;
289 char * propstring; 293 char *propstring;
290 char * propstring_tmp; 294 char *propstring_tmp;
291 char * prefstring; 295 char *prefstring;
292 char * prefstring_tmp; 296 char *prefstring_tmp;
293 int c; 297 int c;
294 int use_dir; 298 int use_dir;
295 299
296 use_dir = GNUNET_NO; 300 use_dir = GNUNET_NO;
297 if (NULL != output_dir) 301 if (NULL != output_dir)
302 {
303 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (output_dir))
298 { 304 {
299 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(output_dir)) 305 fprintf (stderr, "Failed to create directory `%s'\n", output_dir);
300 { 306 return;
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 }
309 } 307 }
308 else
309 {
310 fprintf (stderr, "Created directory `%s'\n", output_dir);
311 use_dir = GNUNET_YES;
312 }
313 }
310 314
311 lf_head = NULL; 315 lf_head = NULL;
312 lf_tail = NULL; 316 lf_tail = NULL;
313 317
314 for (lts = l->head; NULL != lts; lts = lts->next) 318 for (lts = l->head; NULL != lts; lts = lts->next)
319 {
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n",
321 (long long unsigned int) lts->timestamp.abs_value_us);
322
323 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
315 { 324 {
316 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Writing log step %llu\n", 325 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
317 (long long unsigned int)lts->timestamp.abs_value_us); 326 {
327 cur = find_logging_file_handle (lf_head, lf_tail, log_p->id,
328 log_a->aid);
329 if (NULL == cur)
330 {
331 cur = GNUNET_new (struct LoggingFileHandle);
332 cur->aid = log_a->aid;
333 cur->pid = log_p->id;
334
335 if (GNUNET_YES == add_time_stamp)
336 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u_%llu.log",
337 (GNUNET_YES == use_dir) ? output_dir : "",
338 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
339 e->log_prefix,
340 opt_solver,
341 cur->pid,
342 cur->aid,
343 l->head->timestamp.abs_value_us);
344 else
345 GNUNET_asprintf (&filename, "%s%s%s_%s_p%u_a%u.log",
346 (GNUNET_YES == use_dir) ? output_dir : "",
347 (GNUNET_YES == use_dir) ? DIR_SEPARATOR_STR : "",
348 e->log_prefix,
349 opt_solver,
350 cur->pid,
351 cur->aid);
352
353 fprintf (stderr,
354 "Add writing log data for peer %llu address %llu to file `%s'\n",
355 cur->pid, cur->aid, filename);
356
357
358 cur->f_hd = GNUNET_DISK_file_open (filename,
359 GNUNET_DISK_OPEN_READWRITE
360 | GNUNET_DISK_OPEN_CREATE
361 | GNUNET_DISK_OPEN_TRUNCATE,
362 GNUNET_DISK_PERM_USER_READ
363 | GNUNET_DISK_PERM_USER_WRITE
364 | GNUNET_DISK_PERM_GROUP_READ
365 | GNUNET_DISK_PERM_OTHER_READ);
366 if (NULL == cur->f_hd)
367 {
368 fprintf (stderr, "Cannot open `%s' to write log data!\n", filename);
369 GNUNET_free (filename);
370 GNUNET_free (cur);
371 goto cleanup;
372 }
373 GNUNET_free (filename);
374 GNUNET_CONTAINER_DLL_insert (lf_head, lf_tail, cur);
375
376 GNUNET_asprintf (&datastring,
377 "#time delta;log duration;peer_requested;addr net; addr_active; bw in; bw out; " \
378 "UTILIZATION_UP [abs/rel]; UTILIZATION_UP; UTILIZATION_DOWN; UTILIZATION_DOWN; " \
379 "UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_UP; UTILIZATION_PAYLOAD_DOWN; UTILIZATION_PAYLOAD_DOWN;" \
380 "DELAY; DELAY; " \
381 "DISTANCE ;DISTANCE ; COST_WAN; COST_WAN; COST_LAN; COST_LAN; " \
382 "COST_WLAN; COST_WLAN;COST_BT; COST_BT; PREF BW abs; PREF BW rel; PREF LATENCY abs; PREF LATENCY rel;\n");
383 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen (datastring));
384 GNUNET_free (datastring);
385 }
318 386
319 for (log_p = lts->head; NULL != log_p; log_p = log_p->next) 387 prefstring = GNUNET_strdup ("");
388 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
320 { 389 {
321 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next) 390 /*
322 { 391 fprintf(stderr,"\t %s = %.2f %.2f [abs/rel]\n",
323 cur = find_logging_file_handle(lf_head, lf_tail, log_p->id, 392 GNUNET_ATS_print_preference_type(c),
324 log_a->aid); 393 log_p->pref_abs[c], log_p->pref_norm[c]);
325 if (NULL == cur) 394 */
326 { 395 GNUNET_asprintf (&prefstring_tmp, "%s;%.3f;%.3f",
327 cur = GNUNET_new(struct LoggingFileHandle); 396 prefstring, log_p->pref_abs[c], log_p->pref_norm[c]);
328 cur->aid = log_a->aid; 397
329 cur->pid = log_p->id; 398
330 399 GNUNET_free (prefstring);
331 if (GNUNET_YES == add_time_stamp) 400 prefstring = GNUNET_strdup (prefstring_tmp);
332 GNUNET_asprintf(&filename, "%s%s%s_%s_p%u_a%u_%llu.log", 401 GNUNET_free (prefstring_tmp);
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 }
428 } 402 }
403
404
405 propstring = GNUNET_strdup ("");
406 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
407 {
408 if (GNUNET_ATS_NETWORK_TYPE == c)
409 continue;
410 /*
411 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n",
412 GNUNET_ATS_print_property_type(c),
413 log_a->prop_abs[c], log_a->prop_norm[c]);*/
414 GNUNET_asprintf (&propstring_tmp, "%s%.3f;%.3f;",
415 propstring,
416 log_a->prop_abs[c],
417 log_a->prop_norm[c]);
418 GNUNET_free (propstring);
419 propstring = GNUNET_strdup (propstring_tmp);
420 GNUNET_free (propstring_tmp);
421 }
422 GNUNET_asprintf (&datastring, "%llu;%llu;%u;%u;%i;%u;%u;%s;%s\n",
423 GNUNET_TIME_absolute_get_difference (
424 l->head->timestamp,
425 lts->timestamp).
426 rel_value_us / 1000, lts->delta,
427 log_p->is_requested, log_a->network, log_a->active,
428 log_a->assigned_bw_in, log_a->assigned_bw_out,
429 propstring,
430 prefstring);
431
432 GNUNET_DISK_file_write (cur->f_hd, datastring, strlen (datastring));
433 GNUNET_free (datastring);
434 GNUNET_free (prefstring);
435 GNUNET_free (propstring);
436 }
429 } 437 }
438 }
430 439
431cleanup: 440cleanup:
432 next = lf_head; 441 next = lf_head;
433 for (cur = next; NULL != cur; cur = next) 442 for (cur = next; NULL != cur; cur = next)
434 { 443 {
435 next = cur->next; 444 next = cur->next;
436 GNUNET_CONTAINER_DLL_remove(lf_head, lf_tail, cur); 445 GNUNET_CONTAINER_DLL_remove (lf_head, lf_tail, cur);
437 if (NULL != cur->f_hd) 446 if (NULL != cur->f_hd)
438 GNUNET_DISK_file_close(cur->f_hd); 447 GNUNET_DISK_file_close (cur->f_hd);
439 GNUNET_free(cur); 448 GNUNET_free (cur);
440 } 449 }
441} 450}
442 451
443void 452void
444GNUNET_ATS_solver_logging_eval(struct LoggingHandle *l) 453GNUNET_ATS_solver_logging_eval (struct LoggingHandle *l)
445{ 454{
446 struct LoggingTimeStep *lts; 455 struct LoggingTimeStep *lts;
447 struct LoggingPeer *log_p; 456 struct LoggingPeer *log_p;
@@ -449,43 +458,43 @@ GNUNET_ATS_solver_logging_eval(struct LoggingHandle *l)
449 int c; 458 int c;
450 459
451 for (lts = l->head; NULL != lts; lts = lts->next) 460 for (lts = l->head; NULL != lts; lts = lts->next)
461 {
462 fprintf (stderr, "Log step %llu %llu: \n",
463 (long long unsigned int) lts->timestamp.abs_value_us,
464 (long long unsigned int) lts->delta.rel_value_us);
465
466 for (log_p = lts->head; NULL != log_p; log_p = log_p->next)
452 { 467 {
453 fprintf(stderr, "Log step %llu %llu: \n", 468 fprintf (stderr, "\tLogging peer pid %llu\n", log_p->id);
454 (long long unsigned int)lts->timestamp.abs_value_us, 469 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
455 (long long unsigned int)lts->delta.rel_value_us); 470 {
471 fprintf (stderr, "\t %s = %.2f %.2f [abs/rel]\n",
472 GNUNET_ATS_print_preference_type (c),
473 log_p->pref_abs[c], log_p->pref_norm[c]);
474 }
456 475
457 for (log_p = lts->head; NULL != log_p; log_p = log_p->next) 476 for (log_a = log_p->addr_head; NULL != log_a; log_a = log_a->next)
477 {
478 fprintf (stderr, "\tPeer pid %llu address %llu: %u %u %u\n",
479 log_p->id, log_a->aid, log_a->active,
480 log_a->assigned_bw_in,
481 log_a->assigned_bw_out);
482
483 for (c = 1; c < GNUNET_ATS_PropertyCount; c++)
458 { 484 {
459 fprintf(stderr, "\tLogging peer pid %llu\n", log_p->id); 485 if (GNUNET_ATS_NETWORK_TYPE == c)
460 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) 486 continue;
461 { 487 fprintf (stderr, "\t %s = %.2f %.2f [abs/rel]\n",
462 fprintf(stderr, "\t %s = %.2f %.2f [abs/rel]\n", 488 GNUNET_ATS_print_property_type (c),
463 GNUNET_ATS_print_preference_type(c), 489 log_a->prop_abs[c], log_a->prop_norm[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 }
483 } 490 }
491 }
484 } 492 }
493 }
485} 494}
486 495
487void 496void
488GNUNET_ATS_solver_logging_free(struct LoggingHandle *l) 497GNUNET_ATS_solver_logging_free (struct LoggingHandle *l)
489{ 498{
490 struct LoggingTimeStep *lts_cur; 499 struct LoggingTimeStep *lts_cur;
491 struct LoggingTimeStep *lts_next; 500 struct LoggingTimeStep *lts_next;
@@ -495,37 +504,38 @@ GNUNET_ATS_solver_logging_free(struct LoggingHandle *l)
495 struct LoggingAddress *log_a_next; 504 struct LoggingAddress *log_a_next;
496 505
497 if (NULL != l->logging_task) 506 if (NULL != l->logging_task)
498 GNUNET_SCHEDULER_cancel(l->logging_task); 507 GNUNET_SCHEDULER_cancel (l->logging_task);
499 l->logging_task = NULL; 508 l->logging_task = NULL;
500 509
501 lts_next = l->head; 510 lts_next = l->head;
502 while (NULL != (lts_cur = lts_next)) 511 while (NULL != (lts_cur = lts_next))
503 { 512 {
504 lts_next = lts_cur->next; 513 lts_next = lts_cur->next;
505
506 log_p_next = lts_cur->head;
507 while (NULL != (log_p_cur = log_p_next))
508 {
509 log_p_next = log_p_cur->next;
510 514
511 log_a_next = log_p_cur->addr_head; 515 log_p_next = lts_cur->head;
512 while (NULL != (log_a_cur = log_a_next)) 516 while (NULL != (log_p_cur = log_p_next))
513 { 517 {
514 log_a_next = log_a_cur->next; 518 log_p_next = log_p_cur->next;
515 519
516 GNUNET_CONTAINER_DLL_remove(log_p_cur->addr_head, log_p_cur->addr_tail, log_a_cur); 520 log_a_next = log_p_cur->addr_head;
517 GNUNET_free(log_a_cur); 521 while (NULL != (log_a_cur = log_a_next))
518 } 522 {
523 log_a_next = log_a_cur->next;
519 524
520 GNUNET_CONTAINER_DLL_remove(lts_cur->head, lts_cur->tail, log_p_cur); 525 GNUNET_CONTAINER_DLL_remove (log_p_cur->addr_head, log_p_cur->addr_tail,
521 GNUNET_free(log_p_cur); 526 log_a_cur);
522 } 527 GNUNET_free (log_a_cur);
528 }
523 529
524 GNUNET_CONTAINER_DLL_remove(l->head, l->tail, lts_cur); 530 GNUNET_CONTAINER_DLL_remove (lts_cur->head, lts_cur->tail, log_p_cur);
525 GNUNET_free(lts_cur); 531 GNUNET_free (log_p_cur);
526 } 532 }
527 533
528 GNUNET_free(l); 534 GNUNET_CONTAINER_DLL_remove (l->head, l->tail, lts_cur);
535 GNUNET_free (lts_cur);
536 }
537
538 GNUNET_free (l);
529} 539}
530 540
531/** 541/**
@@ -536,7 +546,7 @@ static struct PropertyGenerator *prop_gen_tail;
536 546
537 547
538static double 548static double
539get_property(struct PropertyGenerator *pg) 549get_property (struct PropertyGenerator *pg)
540{ 550{
541 struct GNUNET_TIME_Relative time_delta; 551 struct GNUNET_TIME_Relative time_delta;
542 double delta_value; 552 double delta_value;
@@ -544,62 +554,66 @@ get_property(struct PropertyGenerator *pg)
544 554
545 /* Calculate the current preference value */ 555 /* Calculate the current preference value */
546 switch (pg->type) 556 switch (pg->type)
547 { 557 {
548 case GNUNET_ATS_TEST_TG_CONSTANT: 558 case GNUNET_ATS_TEST_TG_CONSTANT:
549 pref_value = pg->base_value; 559 pref_value = pg->base_value;
550 break; 560 break;
551 561
552 case GNUNET_ATS_TEST_TG_LINEAR: 562 case GNUNET_ATS_TEST_TG_LINEAR:
553 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); 563 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
554 /* Calculate point of time in the current period */ 564 /* Calculate point of time in the current period */
555 time_delta.rel_value_us = time_delta.rel_value_us % 565 time_delta.rel_value_us = time_delta.rel_value_us
556 pg->duration_period.rel_value_us; 566 % pg->duration_period.rel_value_us;
557 delta_value = ((double)time_delta.rel_value_us / 567 delta_value = ((double) time_delta.rel_value_us
558 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); 568 / pg->duration_period.rel_value_us) * (pg->max_value
559 if ((pg->max_value < pg->base_value) && 569 - pg->base_value);
560 ((pg->max_value - pg->base_value) > pg->base_value)) 570 if ((pg->max_value < pg->base_value) &&
561 { 571 ((pg->max_value - pg->base_value) > pg->base_value))
562 /* This will cause an underflow */ 572 {
563 GNUNET_break(0); 573 /* This will cause an underflow */
564 } 574 GNUNET_break (0);
565 pref_value = pg->base_value + delta_value; 575 }
566 break; 576 pref_value = pg->base_value + delta_value;
567 577 break;
568 case GNUNET_ATS_TEST_TG_RANDOM: 578
569 delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 579 case GNUNET_ATS_TEST_TG_RANDOM:
570 10000 * (pg->max_value - pg->base_value)) / 10000; 580 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
571 pref_value = pg->base_value + delta_value; 581 10000 * (pg->max_value
572 break; 582 - pg->base_value))
573 583 / 10000;
574 case GNUNET_ATS_TEST_TG_SINUS: 584 pref_value = pg->base_value + delta_value;
575 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); 585 break;
576 /* Calculate point of time in the current period */ 586
577 time_delta.rel_value_us = time_delta.rel_value_us % 587 case GNUNET_ATS_TEST_TG_SINUS:
578 pg->duration_period.rel_value_us; 588 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
579 if ((pg->max_value - pg->base_value) > pg->base_value) 589 /* Calculate point of time in the current period */
580 { 590 time_delta.rel_value_us = time_delta.rel_value_us
581 /* This will cause an underflow for second half of sinus period, 591 % pg->duration_period.rel_value_us;
582 * will be detected in general when experiments are loaded */ 592 if ((pg->max_value - pg->base_value) > pg->base_value)
583 GNUNET_break(0); 593 {
584 } 594 /* This will cause an underflow for second half of sinus period,
585 delta_value = (pg->max_value - pg->base_value) * 595 * will be detected in general when experiments are loaded */
586 sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) * 596 GNUNET_break (0);
587 time_delta.rel_value_us); 597 }
588 pref_value = pg->base_value + delta_value; 598 delta_value = (pg->max_value - pg->base_value)
589 break; 599 * sin ((2 * M_PI)
590 600 / ((double) pg->duration_period.rel_value_us)
591 default: 601 * time_delta.rel_value_us);
592 pref_value = 0.0; 602 pref_value = pg->base_value + delta_value;
593 break; 603 break;
594 } 604
595 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n", 605 default:
596 pref_value); 606 pref_value = 0.0;
607 break;
608 }
609 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current property value is %f\n",
610 pref_value);
597 return pref_value; 611 return pref_value;
598} 612}
599 613
600 614
601static void 615static void
602set_prop_task(void *cls) 616set_prop_task (void *cls)
603{ 617{
604 struct PropertyGenerator *pg = cls; 618 struct PropertyGenerator *pg = cls;
605 struct TestPeer *p; 619 struct TestPeer *p;
@@ -609,58 +623,63 @@ set_prop_task(void *cls)
609 623
610 pg->set_task = NULL; 624 pg->set_task = NULL;
611 625
612 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value(sh->addresses, 626 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains_value (sh->addresses,
613 &pg->test_peer->peer_id, pg->test_address->ats_addr)) 627 &pg->test_peer
614 { 628 ->peer_id,
615 GNUNET_break(0); 629 pg->
616 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 630 test_address->
617 "Setting property generation for unknown address [%u:%u]\n", 631 ats_addr))
618 pg->peer, pg->address_id); 632 {
619 return; 633 GNUNET_break (0);
620 } 634 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
621 if (NULL == (p = find_peer_by_id(pg->peer))) 635 "Setting property generation for unknown address [%u:%u]\n",
622 { 636 pg->peer, pg->address_id);
623 GNUNET_break(0); 637 return;
624 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 638 }
625 "Setting property generation for unknown peer %u\n", 639 if (NULL == (p = find_peer_by_id (pg->peer)))
626 pg->peer); 640 {
627 return; 641 GNUNET_break (0);
628 } 642 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
629 if (NULL == (a = find_address_by_id(p, pg->address_id))) 643 "Setting property generation for unknown peer %u\n",
630 { 644 pg->peer);
631 GNUNET_break(0); 645 return;
632 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 646 }
633 "Setting property generation for unknown peer %u\n", 647 if (NULL == (a = find_address_by_id (p, pg->address_id)))
634 pg->peer); 648 {
635 return; 649 GNUNET_break (0);
636 } 650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
651 "Setting property generation for unknown peer %u\n",
652 pg->peer);
653 return;
654 }
637 655
638 prop_value = get_property(pg); 656 prop_value = get_property (pg);
639 a->prop_abs[pg->ats_property] = prop_value; 657 a->prop_abs[pg->ats_property] = prop_value;
640 658
641 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 659 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
642 "Setting property for peer [%u] address [%u] for %s to %f\n", 660 "Setting property for peer [%u] address [%u] for %s to %f\n",
643 pg->peer, pg->address_id, 661 pg->peer, pg->address_id,
644 GNUNET_ATS_print_property_type(pg->ats_property), prop_value); 662 GNUNET_ATS_print_property_type (pg->ats_property), prop_value);
645 663
646 atsi.type = htonl(pg->ats_property); 664 atsi.type = htonl (pg->ats_property);
647 atsi.value = htonl((uint32_t)prop_value); 665 atsi.value = htonl ((uint32_t) prop_value);
648 666
649 /* set performance here! */ 667 /* set performance here! */
650 sh->sf->s_bulk_start(sh->sf->cls); 668 sh->sf->s_bulk_start (sh->sf->cls);
651 if (GNUNET_YES == opt_disable_normalization) 669 if (GNUNET_YES == opt_disable_normalization)
652 { 670 {
653 a->prop_abs[pg->ats_property] = prop_value; 671 a->prop_abs[pg->ats_property] = prop_value;
654 a->prop_norm[pg->ats_property] = prop_value; 672 a->prop_norm[pg->ats_property] = prop_value;
655 sh->sf->s_address_update_property(sh->sf->cls, a->ats_addr, 673 sh->sf->s_address_update_property (sh->sf->cls, a->ats_addr,
656 pg->ats_property, prop_value, prop_value); 674 pg->ats_property, prop_value,
657 } 675 prop_value);
676 }
658 else 677 else
659 GAS_normalization_update_property(pg->test_address->ats_addr, &atsi, 1); 678 GAS_normalization_update_property (pg->test_address->ats_addr, &atsi, 1);
660 sh->sf->s_bulk_stop(sh->sf->cls); 679 sh->sf->s_bulk_stop (sh->sf->cls);
661 680
662 pg->set_task = GNUNET_SCHEDULER_add_delayed(pg->frequency, 681 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
663 &set_prop_task, pg); 682 &set_prop_task, pg);
664} 683}
665 684
666 685
@@ -668,36 +687,36 @@ set_prop_task(void *cls)
668 * Set ats_property to 0 to find all pgs 687 * Set ats_property to 0 to find all pgs
669 */ 688 */
670static struct PropertyGenerator * 689static struct PropertyGenerator *
671find_prop_gen(unsigned int peer, unsigned int address, 690find_prop_gen (unsigned int peer, unsigned int address,
672 uint32_t ats_property) 691 uint32_t ats_property)
673{ 692{
674 struct PropertyGenerator *cur; 693 struct PropertyGenerator *cur;
675 694
676 for (cur = prop_gen_head; NULL != cur; cur = cur->next) 695 for (cur = prop_gen_head; NULL != cur; cur = cur->next)
677 if ((cur->peer == peer) && (cur->address_id == address)) 696 if ((cur->peer == peer) && (cur->address_id == address))
678 { 697 {
679 if ((cur->ats_property == ats_property) || (0 == ats_property)) 698 if ((cur->ats_property == ats_property) || (0 == ats_property))
680 return cur; 699 return cur;
681 } 700 }
682 return NULL; 701 return NULL;
683} 702}
684 703
685void 704void
686GNUNET_ATS_solver_generate_property_stop(struct PropertyGenerator *pg) 705GNUNET_ATS_solver_generate_property_stop (struct PropertyGenerator *pg)
687{ 706{
688 GNUNET_CONTAINER_DLL_remove(prop_gen_head, prop_gen_tail, pg); 707 GNUNET_CONTAINER_DLL_remove (prop_gen_head, prop_gen_tail, pg);
689 708
690 if (NULL != pg->set_task) 709 if (NULL != pg->set_task)
691 { 710 {
692 GNUNET_SCHEDULER_cancel(pg->set_task); 711 GNUNET_SCHEDULER_cancel (pg->set_task);
693 pg->set_task = NULL; 712 pg->set_task = NULL;
694 } 713 }
695 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 714 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
696 "Removing old up preference generator peer [%u] address [%u] `%s'\n", 715 "Removing old up preference generator peer [%u] address [%u] `%s'\n",
697 pg->peer, pg->address_id, 716 pg->peer, pg->address_id,
698 GNUNET_ATS_print_property_type(pg->ats_property)); 717 GNUNET_ATS_print_property_type (pg->ats_property));
699 718
700 GNUNET_free(pg); 719 GNUNET_free (pg);
701} 720}
702 721
703 722
@@ -718,21 +737,22 @@ GNUNET_ATS_solver_generate_property_stop(struct PropertyGenerator *pg)
718 * @return the property generator 737 * @return the property generator
719 */ 738 */
720struct PropertyGenerator * 739struct PropertyGenerator *
721GNUNET_ATS_solver_generate_property_start(unsigned int peer, 740GNUNET_ATS_solver_generate_property_start (unsigned int peer,
722 unsigned int address_id, 741 unsigned int address_id,
723 struct TestPeer *test_peer, 742 struct TestPeer *test_peer,
724 struct TestAddress *test_address, 743 struct TestAddress *test_address,
725 enum GeneratorType type, 744 enum GeneratorType type,
726 long int base_value, 745 long int base_value,
727 long int value_rate, 746 long int value_rate,
728 struct GNUNET_TIME_Relative period, 747 struct GNUNET_TIME_Relative period,
729 struct GNUNET_TIME_Relative frequency, 748 struct GNUNET_TIME_Relative
730 uint32_t ats_property) 749 frequency,
750 uint32_t ats_property)
731{ 751{
732 struct PropertyGenerator *pg; 752 struct PropertyGenerator *pg;
733 753
734 pg = GNUNET_new(struct PropertyGenerator); 754 pg = GNUNET_new (struct PropertyGenerator);
735 GNUNET_CONTAINER_DLL_insert(prop_gen_head, prop_gen_tail, pg); 755 GNUNET_CONTAINER_DLL_insert (prop_gen_head, prop_gen_tail, pg);
736 pg->type = type; 756 pg->type = type;
737 pg->peer = peer; 757 pg->peer = peer;
738 pg->test_address = test_address; 758 pg->test_address = test_address;
@@ -743,51 +763,51 @@ GNUNET_ATS_solver_generate_property_start(unsigned int peer,
743 pg->max_value = value_rate; 763 pg->max_value = value_rate;
744 pg->duration_period = period; 764 pg->duration_period = period;
745 pg->frequency = frequency; 765 pg->frequency = frequency;
746 pg->time_start = GNUNET_TIME_absolute_get(); 766 pg->time_start = GNUNET_TIME_absolute_get ();
747 767
748 switch (type) 768 switch (type)
749 { 769 {
750 case GNUNET_ATS_TEST_TG_CONSTANT: 770 case GNUNET_ATS_TEST_TG_CONSTANT:
751 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
752 "Setting up %s property generator peer [%u] address [%u] `%s'" \ 772 "Setting up %s property generator peer [%u] address [%u] `%s'" \
753 "max %u Bips\n", 773 "max %u Bips\n",
754 print_generator_type(type), pg->peer, pg->address_id, 774 print_generator_type (type), pg->peer, pg->address_id,
755 GNUNET_ATS_print_property_type(ats_property), 775 GNUNET_ATS_print_property_type (ats_property),
756 base_value); 776 base_value);
757 break; 777 break;
758 778
759 case GNUNET_ATS_TEST_TG_LINEAR: 779 case GNUNET_ATS_TEST_TG_LINEAR:
760 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 780 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
761 "Setting up %s property generator peer [%u] address [%u] `%s' " \ 781 "Setting up %s property generator peer [%u] address [%u] `%s' " \
762 "min %u Bips max %u Bips\n", 782 "min %u Bips max %u Bips\n",
763 print_generator_type(type), pg->peer, pg->address_id, 783 print_generator_type (type), pg->peer, pg->address_id,
764 GNUNET_ATS_print_property_type(ats_property), 784 GNUNET_ATS_print_property_type (ats_property),
765 base_value, value_rate); 785 base_value, value_rate);
766 break; 786 break;
767 787
768 case GNUNET_ATS_TEST_TG_SINUS: 788 case GNUNET_ATS_TEST_TG_SINUS:
769 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 789 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
770 "Setting up %s property generator peer [%u] address [%u] `%s' " \ 790 "Setting up %s property generator peer [%u] address [%u] `%s' " \
771 "baserate %u Bips, amplitude %u Bps\n", 791 "baserate %u Bips, amplitude %u Bps\n",
772 print_generator_type(type), pg->peer, pg->address_id, 792 print_generator_type (type), pg->peer, pg->address_id,
773 GNUNET_ATS_print_property_type(ats_property), 793 GNUNET_ATS_print_property_type (ats_property),
774 base_value, value_rate); 794 base_value, value_rate);
775 break; 795 break;
776 796
777 case GNUNET_ATS_TEST_TG_RANDOM: 797 case GNUNET_ATS_TEST_TG_RANDOM:
778 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 798 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
779 "Setting up %s property generator peer [%u] address [%u] `%s' " \ 799 "Setting up %s property generator peer [%u] address [%u] `%s' " \
780 "min %u Bips max %u Bps\n", 800 "min %u Bips max %u Bps\n",
781 print_generator_type(type), pg->peer, pg->address_id, 801 print_generator_type (type), pg->peer, pg->address_id,
782 GNUNET_ATS_print_property_type(ats_property), 802 GNUNET_ATS_print_property_type (ats_property),
783 base_value, value_rate); 803 base_value, value_rate);
784 break; 804 break;
785 805
786 default: 806 default:
787 break; 807 break;
788 } 808 }
789 809
790 pg->set_task = GNUNET_SCHEDULER_add_now(&set_prop_task, pg); 810 pg->set_task = GNUNET_SCHEDULER_add_now (&set_prop_task, pg);
791 return pg; 811 return pg;
792} 812}
793 813
@@ -796,17 +816,17 @@ GNUNET_ATS_solver_generate_property_start(unsigned int peer,
796 * Stop all preferences generators 816 * Stop all preferences generators
797 */ 817 */
798void 818void
799GNUNET_ATS_solver_generate_property_stop_all() 819GNUNET_ATS_solver_generate_property_stop_all ()
800{ 820{
801 struct PropertyGenerator *cur; 821 struct PropertyGenerator *cur;
802 struct PropertyGenerator *next; 822 struct PropertyGenerator *next;
803 823
804 next = prop_gen_head; 824 next = prop_gen_head;
805 for (cur = next; NULL != cur; cur = next) 825 for (cur = next; NULL != cur; cur = next)
806 { 826 {
807 next = cur->next; 827 next = cur->next;
808 GNUNET_ATS_solver_generate_property_stop(cur); 828 GNUNET_ATS_solver_generate_property_stop (cur);
809 } 829 }
810} 830}
811 831
812 832
@@ -818,7 +838,7 @@ static struct PreferenceGenerator *pref_gen_tail;
818 838
819 839
820static double 840static double
821get_preference(struct PreferenceGenerator *pg) 841get_preference (struct PreferenceGenerator *pg)
822{ 842{
823 struct GNUNET_TIME_Relative time_delta; 843 struct GNUNET_TIME_Relative time_delta;
824 double delta_value; 844 double delta_value;
@@ -826,62 +846,66 @@ get_preference(struct PreferenceGenerator *pg)
826 846
827 /* Calculate the current preference value */ 847 /* Calculate the current preference value */
828 switch (pg->type) 848 switch (pg->type)
829 { 849 {
830 case GNUNET_ATS_TEST_TG_CONSTANT: 850 case GNUNET_ATS_TEST_TG_CONSTANT:
831 pref_value = pg->base_value; 851 pref_value = pg->base_value;
832 break; 852 break;
833 853
834 case GNUNET_ATS_TEST_TG_LINEAR: 854 case GNUNET_ATS_TEST_TG_LINEAR:
835 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); 855 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
836 /* Calculate point of time in the current period */ 856 /* Calculate point of time in the current period */
837 time_delta.rel_value_us = time_delta.rel_value_us % 857 time_delta.rel_value_us = time_delta.rel_value_us
838 pg->duration_period.rel_value_us; 858 % pg->duration_period.rel_value_us;
839 delta_value = ((double)time_delta.rel_value_us / 859 delta_value = ((double) time_delta.rel_value_us
840 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); 860 / pg->duration_period.rel_value_us) * (pg->max_value
841 if ((pg->max_value < pg->base_value) && 861 - pg->base_value);
842 ((pg->max_value - pg->base_value) > pg->base_value)) 862 if ((pg->max_value < pg->base_value) &&
843 { 863 ((pg->max_value - pg->base_value) > pg->base_value))
844 /* This will cause an underflow */ 864 {
845 GNUNET_break(0); 865 /* This will cause an underflow */
846 } 866 GNUNET_break (0);
847 pref_value = pg->base_value + delta_value; 867 }
848 break; 868 pref_value = pg->base_value + delta_value;
849 869 break;
850 case GNUNET_ATS_TEST_TG_RANDOM: 870
851 delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 871 case GNUNET_ATS_TEST_TG_RANDOM:
852 10000 * (pg->max_value - pg->base_value)) / 10000; 872 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
853 pref_value = pg->base_value + delta_value; 873 10000 * (pg->max_value
854 break; 874 - pg->base_value))
855 875 / 10000;
856 case GNUNET_ATS_TEST_TG_SINUS: 876 pref_value = pg->base_value + delta_value;
857 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); 877 break;
858 /* Calculate point of time in the current period */ 878
859 time_delta.rel_value_us = time_delta.rel_value_us % 879 case GNUNET_ATS_TEST_TG_SINUS:
860 pg->duration_period.rel_value_us; 880 time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start);
861 if ((pg->max_value - pg->base_value) > pg->base_value) 881 /* Calculate point of time in the current period */
862 { 882 time_delta.rel_value_us = time_delta.rel_value_us
863 /* This will cause an underflow for second half of sinus period, 883 % pg->duration_period.rel_value_us;
864 * will be detected in general when experiments are loaded */ 884 if ((pg->max_value - pg->base_value) > pg->base_value)
865 GNUNET_break(0); 885 {
866 } 886 /* This will cause an underflow for second half of sinus period,
867 delta_value = (pg->max_value - pg->base_value) * 887 * will be detected in general when experiments are loaded */
868 sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) * 888 GNUNET_break (0);
869 time_delta.rel_value_us); 889 }
870 pref_value = pg->base_value + delta_value; 890 delta_value = (pg->max_value - pg->base_value)
871 break; 891 * sin ((2 * M_PI)
872 892 / ((double) pg->duration_period.rel_value_us)
873 default: 893 * time_delta.rel_value_us);
874 pref_value = 0.0; 894 pref_value = pg->base_value + delta_value;
875 break; 895 break;
876 } 896
877 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", 897 default:
878 pref_value); 898 pref_value = 0.0;
899 break;
900 }
901 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
902 pref_value);
879 return pref_value; 903 return pref_value;
880} 904}
881 905
882 906
883static void 907static void
884set_feedback_task(void *cls) 908set_feedback_task (void *cls)
885{ 909{
886 struct PreferenceGenerator *pg = cls; 910 struct PreferenceGenerator *pg = cls;
887 struct TestPeer *p; 911 struct TestPeer *p;
@@ -894,70 +918,75 @@ set_feedback_task(void *cls)
894 918
895 pg->feedback_task = NULL; 919 pg->feedback_task = NULL;
896 920
897 if (NULL == (p = find_peer_by_id(pg->peer))) 921 if (NULL == (p = find_peer_by_id (pg->peer)))
898 { 922 {
899 GNUNET_break(0); 923 GNUNET_break (0);
900 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 924 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
901 "Setting feedback for unknown peer %u\n", pg->peer); 925 "Setting feedback for unknown peer %u\n", pg->peer);
902 return; 926 return;
903 } 927 }
904 928
905 switch (pg->kind) 929 switch (pg->kind)
906 { 930 {
907 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 931 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
908 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); 932 dur = GNUNET_TIME_absolute_get_duration (pg->feedback_last_bw_update);
909 bw_acc_in = dur.rel_value_us * pg->last_assigned_bw_in + pg->feedback_bw_in_acc; 933 bw_acc_in = dur.rel_value_us * pg->last_assigned_bw_in
910 pg->feedback_bw_in_acc = 0; 934 + pg->feedback_bw_in_acc;
911 935 pg->feedback_bw_in_acc = 0;
912 bw_acc_out = dur.rel_value_us * pg->last_assigned_bw_out + pg->feedback_bw_out_acc; 936
913 p_new = get_preference(pg); 937 bw_acc_out = dur.rel_value_us * pg->last_assigned_bw_out
914 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out) / 938 + pg->feedback_bw_out_acc;
915 (2 * GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); 939 p_new = get_preference (pg);
916 940 feedback = (p_new / pg->pref_bw_old) * (bw_acc_in + bw_acc_out)
917 break; 941 / (2 * GNUNET_TIME_absolute_get_duration (
918 942 pg->feedback_last).rel_value_us);
919 case GNUNET_ATS_PREFERENCE_LATENCY: 943
920 dur = GNUNET_TIME_absolute_get_duration(pg->feedback_last_delay_update); 944 break;
921 delay_acc_in = dur.rel_value_us * pg->last_delay_value + pg->feedback_delay_acc; 945
922 pg->feedback_delay_acc = 0; 946 case GNUNET_ATS_PREFERENCE_LATENCY:
923 947 dur = GNUNET_TIME_absolute_get_duration (pg->feedback_last_delay_update);
924 p_new = get_preference(pg); 948 delay_acc_in = dur.rel_value_us * pg->last_delay_value
925 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in) / 949 + pg->feedback_delay_acc;
926 (GNUNET_TIME_absolute_get_duration(pg->feedback_last).rel_value_us); 950 pg->feedback_delay_acc = 0;
927 951
928 break; 952 p_new = get_preference (pg);
929 953 feedback = (p_new / pg->pref_latency_old) * (delay_acc_in)
930 default: 954 / (GNUNET_TIME_absolute_get_duration (
931 GNUNET_break(0); 955 pg->feedback_last).rel_value_us);
932 feedback = 0.0; 956
933 break; 957 break;
934 } 958
935 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 959 default:
936 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n", 960 GNUNET_break (0);
937 pg->peer, NULL + (pg->client_id), 961 feedback = 0.0;
938 GNUNET_ATS_print_preference_type(pg->kind), 962 break;
939 feedback); 963 }
940 964 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
941 sh->sf->s_feedback(sh->sf->cls, NULL + (pg->client_id), &p->peer_id, 965 "Giving feedback for peer [%u] for client %p pref %s of %.3f\n",
942 pg->feedback_frequency, pg->kind, feedback); 966 pg->peer, NULL + (pg->client_id),
943 pg->feedback_last = GNUNET_TIME_absolute_get(); 967 GNUNET_ATS_print_preference_type (pg->kind),
968 feedback);
969
970 sh->sf->s_feedback (sh->sf->cls, NULL + (pg->client_id), &p->peer_id,
971 pg->feedback_frequency, pg->kind, feedback);
972 pg->feedback_last = GNUNET_TIME_absolute_get ();
944 973
945 974
946 pg->feedback_bw_out_acc = 0; 975 pg->feedback_bw_out_acc = 0;
947 pg->feedback_bw_in_acc = 0; 976 pg->feedback_bw_in_acc = 0;
948 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); 977 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get ();
949 978
950 pg->feedback_delay_acc = 0; 979 pg->feedback_delay_acc = 0;
951 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); 980 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get ();
952 981
953 982
954 pg->feedback_task = GNUNET_SCHEDULER_add_delayed(pg->feedback_frequency, 983 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (pg->feedback_frequency,
955 &set_feedback_task, pg); 984 &set_feedback_task, pg);
956} 985}
957 986
958 987
959static void 988static void
960set_pref_task(void *cls) 989set_pref_task (void *cls)
961{ 990{
962 struct PreferenceGenerator *pg = cls; 991 struct PreferenceGenerator *pg = cls;
963 struct TestPeer *p; 992 struct TestPeer *p;
@@ -965,94 +994,94 @@ set_pref_task(void *cls)
965 994
966 pg->set_task = NULL; 995 pg->set_task = NULL;
967 996
968 if (NULL == (p = find_peer_by_id(pg->peer))) 997 if (NULL == (p = find_peer_by_id (pg->peer)))
969 { 998 {
970 GNUNET_break(0); 999 GNUNET_break (0);
971 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1000 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
972 "Setting preference for unknown peer %u\n", pg->peer); 1001 "Setting preference for unknown peer %u\n", pg->peer);
973 return; 1002 return;
974 } 1003 }
975 1004
976 pref_value = get_preference(pg); 1005 pref_value = get_preference (pg);
977 switch (pg->kind) 1006 switch (pg->kind)
978 { 1007 {
979 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 1008 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
980 pg->pref_bw_old = pref_value; 1009 pg->pref_bw_old = pref_value;
981 break; 1010 break;
982 1011
983 case GNUNET_ATS_PREFERENCE_LATENCY: 1012 case GNUNET_ATS_PREFERENCE_LATENCY:
984 pg->pref_latency_old = pref_value; 1013 pg->pref_latency_old = pref_value;
985 break; 1014 break;
986 1015
987 default: 1016 default:
988 break; 1017 break;
989 } 1018 }
990 1019
991 p->pref_abs[pg->kind] = pref_value; 1020 p->pref_abs[pg->kind] = pref_value;
992 1021
993 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1022 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
994 "Setting preference for peer [%u] for client %p pref %s to %f\n", 1023 "Setting preference for peer [%u] for client %p pref %s to %f\n",
995 pg->peer, NULL + (pg->client_id), 1024 pg->peer, NULL + (pg->client_id),
996 GNUNET_ATS_print_preference_type(pg->kind), pref_value); 1025 GNUNET_ATS_print_preference_type (pg->kind), pref_value);
997 1026
998 if (GNUNET_YES == opt_disable_normalization) 1027 if (GNUNET_YES == opt_disable_normalization)
999 { 1028 {
1000 p->pref_abs[pg->kind] = pref_value; 1029 p->pref_abs[pg->kind] = pref_value;
1001 p->pref_norm[pg->kind] = pref_value; 1030 p->pref_norm[pg->kind] = pref_value;
1002 sh->sf->s_pref(sh->sf->cls, &p->peer_id, pg->kind, pref_value); 1031 sh->sf->s_pref (sh->sf->cls, &p->peer_id, pg->kind, pref_value);
1003 } 1032 }
1004 else 1033 else
1005 update_preference(NULL + (pg->client_id), 1034 update_preference (NULL + (pg->client_id),
1006 &p->peer_id, 1035 &p->peer_id,
1007 pg->kind, 1036 pg->kind,
1008 pref_value); 1037 pref_value);
1009 1038
1010 pg->set_task = GNUNET_SCHEDULER_add_delayed(pg->frequency, 1039 pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency,
1011 &set_pref_task, 1040 &set_pref_task,
1012 pg); 1041 pg);
1013} 1042}
1014 1043
1015 1044
1016static struct PreferenceGenerator * 1045static struct PreferenceGenerator *
1017find_pref_gen(unsigned int peer, enum GNUNET_ATS_PreferenceKind kind) 1046find_pref_gen (unsigned int peer, enum GNUNET_ATS_PreferenceKind kind)
1018{ 1047{
1019 struct PreferenceGenerator *cur; 1048 struct PreferenceGenerator *cur;
1020 1049
1021 for (cur = pref_gen_head; NULL != cur; cur = cur->next) 1050 for (cur = pref_gen_head; NULL != cur; cur = cur->next)
1022 if (cur->peer == peer) 1051 if (cur->peer == peer)
1023 { 1052 {
1024 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind)) 1053 if ((cur->kind == kind) || (GNUNET_ATS_PREFERENCE_END == kind))
1025 return cur; 1054 return cur;
1026 } 1055 }
1027 return NULL; 1056 return NULL;
1028} 1057}
1029 1058
1030void 1059void
1031GNUNET_ATS_solver_generate_preferences_stop(struct PreferenceGenerator *pg) 1060GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg)
1032{ 1061{
1033 GNUNET_CONTAINER_DLL_remove(pref_gen_head, pref_gen_tail, pg); 1062 GNUNET_CONTAINER_DLL_remove (pref_gen_head, pref_gen_tail, pg);
1034 1063
1035 if (NULL != pg->feedback_task) 1064 if (NULL != pg->feedback_task)
1036 { 1065 {
1037 GNUNET_SCHEDULER_cancel(pg->feedback_task); 1066 GNUNET_SCHEDULER_cancel (pg->feedback_task);
1038 pg->feedback_task = NULL; 1067 pg->feedback_task = NULL;
1039 } 1068 }
1040 1069
1041 if (NULL != pg->set_task) 1070 if (NULL != pg->set_task)
1042 { 1071 {
1043 GNUNET_SCHEDULER_cancel(pg->set_task); 1072 GNUNET_SCHEDULER_cancel (pg->set_task);
1044 pg->set_task = NULL; 1073 pg->set_task = NULL;
1045 } 1074 }
1046 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1047 "Removing old up preference generator peer [%u] `%s'\n", 1076 "Removing old up preference generator peer [%u] `%s'\n",
1048 pg->peer, GNUNET_ATS_print_preference_type(pg->kind)); 1077 pg->peer, GNUNET_ATS_print_preference_type (pg->kind));
1049 1078
1050 GNUNET_free(pg); 1079 GNUNET_free (pg);
1051} 1080}
1052 1081
1053 1082
1054static struct TestAddress* 1083static struct TestAddress*
1055find_active_address(struct TestPeer *p) 1084find_active_address (struct TestPeer *p)
1056{ 1085{
1057 struct TestAddress *cur; 1086 struct TestAddress *cur;
1058 1087
@@ -1080,30 +1109,34 @@ find_active_address(struct TestPeer *p)
1080 * @return the preference generator 1109 * @return the preference generator
1081 */ 1110 */
1082struct PreferenceGenerator * 1111struct PreferenceGenerator *
1083GNUNET_ATS_solver_generate_preferences_start(unsigned int peer, 1112GNUNET_ATS_solver_generate_preferences_start (unsigned int peer,
1084 unsigned int address_id, 1113 unsigned int address_id,
1085 unsigned int client_id, 1114 unsigned int client_id,
1086 enum GeneratorType type, 1115 enum GeneratorType type,
1087 long int base_value, 1116 long int base_value,
1088 long int value_rate, 1117 long int value_rate,
1089 struct GNUNET_TIME_Relative period, 1118 struct GNUNET_TIME_Relative
1090 struct GNUNET_TIME_Relative frequency, 1119 period,
1091 enum GNUNET_ATS_PreferenceKind kind, 1120 struct GNUNET_TIME_Relative
1092 struct GNUNET_TIME_Relative feedback_frequency) 1121 frequency,
1122 enum GNUNET_ATS_PreferenceKind
1123 kind,
1124 struct GNUNET_TIME_Relative
1125 feedback_frequency)
1093{ 1126{
1094 struct PreferenceGenerator *pg; 1127 struct PreferenceGenerator *pg;
1095 struct TestPeer *p; 1128 struct TestPeer *p;
1096 1129
1097 if (NULL == (p = find_peer_by_id(peer))) 1130 if (NULL == (p = find_peer_by_id (peer)))
1098 { 1131 {
1099 GNUNET_break(0); 1132 GNUNET_break (0);
1100 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1101 "Starting preference for unknown peer %u\n", peer); 1134 "Starting preference for unknown peer %u\n", peer);
1102 return NULL; 1135 return NULL;
1103 } 1136 }
1104 1137
1105 pg = GNUNET_new(struct PreferenceGenerator); 1138 pg = GNUNET_new (struct PreferenceGenerator);
1106 GNUNET_CONTAINER_DLL_insert(pref_gen_head, pref_gen_tail, pg); 1139 GNUNET_CONTAINER_DLL_insert (pref_gen_head, pref_gen_tail, pg);
1107 pg->type = type; 1140 pg->type = type;
1108 pg->peer = peer; 1141 pg->peer = peer;
1109 pg->client_id = client_id; 1142 pg->client_id = client_id;
@@ -1112,62 +1145,66 @@ GNUNET_ATS_solver_generate_preferences_start(unsigned int peer,
1112 pg->max_value = value_rate; 1145 pg->max_value = value_rate;
1113 pg->duration_period = period; 1146 pg->duration_period = period;
1114 pg->frequency = frequency; 1147 pg->frequency = frequency;
1115 pg->time_start = GNUNET_TIME_absolute_get(); 1148 pg->time_start = GNUNET_TIME_absolute_get ();
1116 pg->feedback_frequency = feedback_frequency; 1149 pg->feedback_frequency = feedback_frequency;
1117 1150
1118 switch (type) 1151 switch (type)
1119 { 1152 {
1120 case GNUNET_ATS_TEST_TG_CONSTANT: 1153 case GNUNET_ATS_TEST_TG_CONSTANT:
1121 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1122 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n", 1155 "Setting up %s preference generator peer [%u] `%s' max %u Bips\n",
1123 print_generator_type(type), pg->peer, 1156 print_generator_type (type), pg->peer,
1124 GNUNET_ATS_print_preference_type(kind), 1157 GNUNET_ATS_print_preference_type (kind),
1125 base_value); 1158 base_value);
1126 break; 1159 break;
1127 1160
1128 case GNUNET_ATS_TEST_TG_LINEAR: 1161 case GNUNET_ATS_TEST_TG_LINEAR:
1129 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1130 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n", 1163 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bips\n",
1131 print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), 1164 print_generator_type (type), pg->peer,
1132 base_value, value_rate); 1165 GNUNET_ATS_print_preference_type (kind),
1133 break; 1166 base_value, value_rate);
1134 1167 break;
1135 case GNUNET_ATS_TEST_TG_SINUS: 1168
1136 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1169 case GNUNET_ATS_TEST_TG_SINUS:
1137 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n", 1170 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1138 print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), 1171 "Setting up %s preference generator peer [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
1139 base_value, value_rate); 1172 print_generator_type (type), pg->peer,
1140 break; 1173 GNUNET_ATS_print_preference_type (kind),
1141 1174 base_value, value_rate);
1142 case GNUNET_ATS_TEST_TG_RANDOM: 1175 break;
1143 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1176
1144 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n", 1177 case GNUNET_ATS_TEST_TG_RANDOM:
1145 print_generator_type(type), pg->peer, GNUNET_ATS_print_preference_type(kind), 1178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1146 base_value, value_rate); 1179 "Setting up %s preference generator peer [%u] `%s' min %u Bips max %u Bps\n",
1147 break; 1180 print_generator_type (type), pg->peer,
1148 1181 GNUNET_ATS_print_preference_type (kind),
1149 default: 1182 base_value, value_rate);
1150 break; 1183 break;
1151 } 1184
1152 1185 default:
1153 pg->set_task = GNUNET_SCHEDULER_add_now(&set_pref_task, pg); 1186 break;
1154 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) 1187 }
1155 { 1188
1156 struct TestAddress * addr = find_active_address(p); 1189 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, pg);
1157 1190 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
1158 pg->last_assigned_bw_in = p->assigned_bw_in; 1191 feedback_frequency.rel_value_us)
1159 pg->last_assigned_bw_out = p->assigned_bw_out; 1192 {
1160 pg->feedback_bw_in_acc = 0; 1193 struct TestAddress *addr = find_active_address (p);
1161 pg->feedback_bw_out_acc = 0; 1194
1162 pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY]; 1195 pg->last_assigned_bw_in = p->assigned_bw_in;
1163 pg->feedback_delay_acc = 0; 1196 pg->last_assigned_bw_out = p->assigned_bw_out;
1164 1197 pg->feedback_bw_in_acc = 0;
1165 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); 1198 pg->feedback_bw_out_acc = 0;
1166 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get(); 1199 pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY];
1167 pg->feedback_last = GNUNET_TIME_absolute_get(); 1200 pg->feedback_delay_acc = 0;
1168 pg->feedback_task = GNUNET_SCHEDULER_add_delayed(feedback_frequency, 1201
1169 &set_feedback_task, pg); 1202 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get ();
1170 } 1203 pg->feedback_last_delay_update = GNUNET_TIME_absolute_get ();
1204 pg->feedback_last = GNUNET_TIME_absolute_get ();
1205 pg->feedback_task = GNUNET_SCHEDULER_add_delayed (feedback_frequency,
1206 &set_feedback_task, pg);
1207 }
1171 1208
1172 return pg; 1209 return pg;
1173} 1210}
@@ -1178,17 +1215,17 @@ GNUNET_ATS_solver_generate_preferences_start(unsigned int peer,
1178 * Stop all preferences generators 1215 * Stop all preferences generators
1179 */ 1216 */
1180void 1217void
1181GNUNET_ATS_solver_generate_preferences_stop_all() 1218GNUNET_ATS_solver_generate_preferences_stop_all ()
1182{ 1219{
1183 struct PreferenceGenerator *cur; 1220 struct PreferenceGenerator *cur;
1184 struct PreferenceGenerator *next; 1221 struct PreferenceGenerator *next;
1185 1222
1186 next = pref_gen_head; 1223 next = pref_gen_head;
1187 for (cur = next; NULL != cur; cur = next) 1224 for (cur = next; NULL != cur; cur = next)
1188 { 1225 {
1189 next = cur->next; 1226 next = cur->next;
1190 GNUNET_ATS_solver_generate_preferences_stop(cur); 1227 GNUNET_ATS_solver_generate_preferences_stop (cur);
1191 } 1228 }
1192} 1229}
1193 1230
1194 1231
@@ -1197,47 +1234,47 @@ GNUNET_ATS_solver_generate_preferences_stop_all()
1197 * Experiments 1234 * Experiments
1198 */ 1235 */
1199static const char * 1236static const char *
1200print_op(enum OperationType op) 1237print_op (enum OperationType op)
1201{ 1238{
1202 switch (op) 1239 switch (op)
1203 { 1240 {
1204 case SOLVER_OP_ADD_ADDRESS: 1241 case SOLVER_OP_ADD_ADDRESS:
1205 return "ADD_ADDRESS"; 1242 return "ADD_ADDRESS";
1206 1243
1207 case SOLVER_OP_DEL_ADDRESS: 1244 case SOLVER_OP_DEL_ADDRESS:
1208 return "DEL_ADDRESS"; 1245 return "DEL_ADDRESS";
1209 1246
1210 case SOLVER_OP_START_SET_PREFERENCE: 1247 case SOLVER_OP_START_SET_PREFERENCE:
1211 return "START_SET_PREFERENCE"; 1248 return "START_SET_PREFERENCE";
1212 1249
1213 case SOLVER_OP_STOP_SET_PREFERENCE: 1250 case SOLVER_OP_STOP_SET_PREFERENCE:
1214 return "STOP_STOP_PREFERENCE"; 1251 return "STOP_STOP_PREFERENCE";
1215 1252
1216 case SOLVER_OP_START_SET_PROPERTY: 1253 case SOLVER_OP_START_SET_PROPERTY:
1217 return "START_SET_PROPERTY"; 1254 return "START_SET_PROPERTY";
1218 1255
1219 case SOLVER_OP_STOP_SET_PROPERTY: 1256 case SOLVER_OP_STOP_SET_PROPERTY:
1220 return "STOP_SET_PROPERTY"; 1257 return "STOP_SET_PROPERTY";
1221 1258
1222 case SOLVER_OP_START_REQUEST: 1259 case SOLVER_OP_START_REQUEST:
1223 return "START_REQUEST"; 1260 return "START_REQUEST";
1224 1261
1225 case SOLVER_OP_STOP_REQUEST: 1262 case SOLVER_OP_STOP_REQUEST:
1226 return "STOP_REQUEST"; 1263 return "STOP_REQUEST";
1227 1264
1228 default: 1265 default:
1229 break; 1266 break;
1230 } 1267 }
1231 return ""; 1268 return "";
1232} 1269}
1233 1270
1234 1271
1235static struct Experiment * 1272static struct Experiment *
1236create_experiment() 1273create_experiment ()
1237{ 1274{
1238 struct Experiment *e; 1275 struct Experiment *e;
1239 1276
1240 e = GNUNET_new(struct Experiment); 1277 e = GNUNET_new (struct Experiment);
1241 e->name = NULL; 1278 e->name = NULL;
1242 e->start = NULL; 1279 e->start = NULL;
1243 e->total_duration = GNUNET_TIME_UNIT_ZERO; 1280 e->total_duration = GNUNET_TIME_UNIT_ZERO;
@@ -1246,7 +1283,7 @@ create_experiment()
1246 1283
1247 1284
1248static void 1285static void
1249free_experiment(struct Experiment *e) 1286free_experiment (struct Experiment *e)
1250{ 1287{
1251 struct Episode *cur; 1288 struct Episode *cur;
1252 struct Episode *next; 1289 struct Episode *next;
@@ -1255,771 +1292,820 @@ free_experiment(struct Experiment *e)
1255 1292
1256 next = e->start; 1293 next = e->start;
1257 for (cur = next; NULL != cur; cur = next) 1294 for (cur = next; NULL != cur; cur = next)
1258 { 1295 {
1259 next = cur->next; 1296 next = cur->next;
1260 1297
1261 next_o = cur->head; 1298 next_o = cur->head;
1262 for (cur_o = next_o; NULL != cur_o; cur_o = next_o) 1299 for (cur_o = next_o; NULL != cur_o; cur_o = next_o)
1263 { 1300 {
1264 next_o = cur_o->next; 1301 next_o = cur_o->next;
1265 GNUNET_free_non_null(cur_o->address); 1302 GNUNET_free_non_null (cur_o->address);
1266 GNUNET_free_non_null(cur_o->plugin); 1303 GNUNET_free_non_null (cur_o->plugin);
1267 GNUNET_free(cur_o); 1304 GNUNET_free (cur_o);
1268 }
1269 GNUNET_free(cur);
1270 } 1305 }
1306 GNUNET_free (cur);
1307 }
1271 1308
1272 GNUNET_free_non_null(e->name); 1309 GNUNET_free_non_null (e->name);
1273 GNUNET_free_non_null(e->log_prefix); 1310 GNUNET_free_non_null (e->log_prefix);
1274 GNUNET_free_non_null(e->log_output_dir); 1311 GNUNET_free_non_null (e->log_output_dir);
1275 GNUNET_free_non_null(e->cfg_file); 1312 GNUNET_free_non_null (e->cfg_file);
1276 GNUNET_free(e); 1313 GNUNET_free (e);
1277} 1314}
1278 1315
1279 1316
1280static int 1317static int
1281load_op_add_address(struct GNUNET_ATS_TEST_Operation *o, 1318load_op_add_address (struct GNUNET_ATS_TEST_Operation *o,
1282 struct Episode *e, 1319 struct Episode *e,
1283 int op_counter, 1320 int op_counter,
1284 char *sec_name, 1321 char *sec_name,
1285 const struct GNUNET_CONFIGURATION_Handle *cfg) 1322 const struct GNUNET_CONFIGURATION_Handle *cfg)
1286{ 1323{
1287 char *op_name; 1324 char *op_name;
1288 char *op_network; 1325 char *op_network;
1289 1326
1290 /* peer pid */ 1327 /* peer pid */
1291 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1328 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1292 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1329 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1293 sec_name, op_name, &o->peer_id)) 1330 sec_name, op_name,
1294 { 1331 &o->peer_id))
1295 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 1332 {
1296 op_counter, "ADD_ADDRESS", op_name); 1333 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1297 GNUNET_free(op_name); 1334 op_counter, "ADD_ADDRESS", op_name);
1298 return GNUNET_SYSERR; 1335 GNUNET_free (op_name);
1299 } 1336 return GNUNET_SYSERR;
1300 GNUNET_free(op_name); 1337 }
1338 GNUNET_free (op_name);
1301 1339
1302 /* address pid */ 1340 /* address pid */
1303 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); 1341 GNUNET_asprintf (&op_name, "op-%u-address-id", op_counter);
1304 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1342 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1305 sec_name, op_name, &o->address_id)) 1343 sec_name, op_name,
1306 { 1344 &o->address_id))
1307 fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", 1345 {
1308 op_counter, "ADD_ADDRESS", op_name); 1346 fprintf (stderr,
1309 GNUNET_free(op_name); 1347 "Missing address-id in operation %u `%s' in episode `%s'\n",
1310 return GNUNET_SYSERR; 1348 op_counter, "ADD_ADDRESS", op_name);
1311 } 1349 GNUNET_free (op_name);
1312 GNUNET_free(op_name); 1350 return GNUNET_SYSERR;
1351 }
1352 GNUNET_free (op_name);
1313 1353
1314 /* plugin */ 1354 /* plugin */
1315 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); 1355 GNUNET_asprintf (&op_name, "op-%u-plugin", op_counter);
1316 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1356 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1317 sec_name, op_name, &o->plugin)) 1357 sec_name, op_name,
1318 { 1358 &o->plugin))
1319 fprintf(stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", 1359 {
1320 op_counter, "ADD_ADDRESS", op_name); 1360 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1321 GNUNET_free(op_name); 1361 op_counter, "ADD_ADDRESS", op_name);
1322 return GNUNET_SYSERR; 1362 GNUNET_free (op_name);
1323 } 1363 return GNUNET_SYSERR;
1324 GNUNET_free(op_name); 1364 }
1365 GNUNET_free (op_name);
1325 1366
1326 /* address */ 1367 /* address */
1327 GNUNET_asprintf(&op_name, "op-%u-address", op_counter); 1368 GNUNET_asprintf (&op_name, "op-%u-address", op_counter);
1328 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1369 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1329 sec_name, op_name, &o->address)) 1370 sec_name, op_name,
1330 { 1371 &o->address))
1331 fprintf(stderr, "Missing address in operation %u `%s' in episode `%s'\n", 1372 {
1332 op_counter, "ADD_ADDRESS", op_name); 1373 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1333 GNUNET_free(op_name); 1374 op_counter, "ADD_ADDRESS", op_name);
1334 return GNUNET_SYSERR; 1375 GNUNET_free (op_name);
1335 } 1376 return GNUNET_SYSERR;
1336 GNUNET_free(op_name); 1377 }
1378 GNUNET_free (op_name);
1337 1379
1338 /* session */ 1380 /* session */
1339 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); 1381 GNUNET_asprintf (&op_name, "op-%u-address-session", op_counter);
1340 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1382 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1341 sec_name, op_name, &o->address_session)) 1383 sec_name, op_name,
1342 { 1384 &o->
1343 fprintf(stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", 1385 address_session))
1344 op_counter, "ADD_ADDRESS", op_name); 1386 {
1345 GNUNET_free(op_name); 1387 fprintf (stderr,
1346 return GNUNET_SYSERR; 1388 "Missing address-session in operation %u `%s' in episode `%s'\n",
1347 } 1389 op_counter, "ADD_ADDRESS", op_name);
1348 GNUNET_free(op_name); 1390 GNUNET_free (op_name);
1391 return GNUNET_SYSERR;
1392 }
1393 GNUNET_free (op_name);
1349 1394
1350 /* network */ 1395 /* network */
1351 GNUNET_asprintf(&op_name, "op-%u-address-network", op_counter); 1396 GNUNET_asprintf (&op_name, "op-%u-address-network", op_counter);
1352 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1397 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1353 sec_name, op_name, &op_network)) 1398 sec_name, op_name,
1399 &op_network))
1400 {
1401 fprintf (stderr,
1402 "Missing address-network in operation %u `%s' in episode `%s'\n",
1403 op_counter, "ADD_ADDRESS", op_name);
1404 GNUNET_free (op_name);
1405 return GNUNET_SYSERR;
1406 }
1407 else
1408 {
1409 GNUNET_STRINGS_utf8_toupper (op_network, op_network);
1410 if (0 == strcmp (op_network, "UNSPECIFIED"))
1354 { 1411 {
1355 fprintf(stderr, "Missing address-network in operation %u `%s' in episode `%s'\n", 1412 o->address_network = GNUNET_NT_UNSPECIFIED;
1356 op_counter, "ADD_ADDRESS", op_name);
1357 GNUNET_free(op_name);
1358 return GNUNET_SYSERR;
1359 } 1413 }
1360 else 1414 else if (0 == strcmp (op_network, "LOOPBACK"))
1361 { 1415 {
1362 GNUNET_STRINGS_utf8_toupper(op_network, op_network); 1416 o->address_network = GNUNET_NT_LOOPBACK;
1363 if (0 == strcmp(op_network, "UNSPECIFIED")) 1417 }
1364 { 1418 else if (0 == strcmp (op_network, "LAN"))
1365 o->address_network = GNUNET_NT_UNSPECIFIED; 1419 {
1366 } 1420 o->address_network = GNUNET_NT_LAN;
1367 else if (0 == strcmp(op_network, "LOOPBACK")) 1421 }
1368 { 1422 else if (0 == strcmp (op_network, "WAN"))
1369 o->address_network = GNUNET_NT_LOOPBACK; 1423 {
1370 } 1424 o->address_network = GNUNET_NT_WAN;
1371 else if (0 == strcmp(op_network, "LAN")) 1425 }
1372 { 1426 else if (0 == strcmp (op_network, "WLAN"))
1373 o->address_network = GNUNET_NT_LAN; 1427 {
1374 } 1428 o->address_network = GNUNET_NT_WLAN;
1375 else if (0 == strcmp(op_network, "WAN")) 1429 }
1376 { 1430 else if (0 == strcmp (op_network, "BT"))
1377 o->address_network = GNUNET_NT_WAN; 1431 {
1378 } 1432 o->address_network = GNUNET_NT_BT;
1379 else if (0 == strcmp(op_network, "WLAN")) 1433 }
1380 { 1434 else
1381 o->address_network = GNUNET_NT_WLAN; 1435 {
1382 } 1436 fprintf (stderr,
1383 else if (0 == strcmp(op_network, "BT")) 1437 "Invalid address-network in operation %u `%s' in episode `%s': `%s'\n",
1384 { 1438 op_counter, "ADD_ADDRESS", op_name, op_network);
1385 o->address_network = GNUNET_NT_BT; 1439 GNUNET_free (op_network);
1386 } 1440 GNUNET_free (op_name);
1387 else 1441 return GNUNET_SYSERR;
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 }
1395 } 1442 }
1396 GNUNET_free(op_network); 1443 }
1397 GNUNET_free(op_name); 1444 GNUNET_free (op_network);
1445 GNUNET_free (op_name);
1398 1446
1399 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1447 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1400 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", 1448 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1401 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); 1449 "ADD_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1402 1450
1403 return GNUNET_OK; 1451 return GNUNET_OK;
1404} 1452}
1405 1453
1406 1454
1407static int 1455static int
1408load_op_del_address(struct GNUNET_ATS_TEST_Operation *o, 1456load_op_del_address (struct GNUNET_ATS_TEST_Operation *o,
1409 struct Episode *e, 1457 struct Episode *e,
1410 int op_counter, 1458 int op_counter,
1411 char *sec_name, 1459 char *sec_name,
1412 const struct GNUNET_CONFIGURATION_Handle *cfg) 1460 const struct GNUNET_CONFIGURATION_Handle *cfg)
1413{ 1461{
1414 char *op_name; 1462 char *op_name;
1415 1463
1416 //char *op_network; 1464 // char *op_network;
1417 1465
1418 /* peer pid */ 1466 /* peer pid */
1419 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1467 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1420 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1468 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1421 sec_name, op_name, &o->peer_id)) 1469 sec_name, op_name,
1422 { 1470 &o->peer_id))
1423 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 1471 {
1424 op_counter, "DEL_ADDRESS", op_name); 1472 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1425 GNUNET_free(op_name); 1473 op_counter, "DEL_ADDRESS", op_name);
1426 return GNUNET_SYSERR; 1474 GNUNET_free (op_name);
1427 } 1475 return GNUNET_SYSERR;
1428 GNUNET_free(op_name); 1476 }
1477 GNUNET_free (op_name);
1429 1478
1430 /* address pid */ 1479 /* address pid */
1431 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); 1480 GNUNET_asprintf (&op_name, "op-%u-address-id", op_counter);
1432 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1481 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1433 sec_name, op_name, &o->address_id)) 1482 sec_name, op_name,
1434 { 1483 &o->address_id))
1435 fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", 1484 {
1436 op_counter, "DEL_ADDRESS", op_name); 1485 fprintf (stderr,
1437 GNUNET_free(op_name); 1486 "Missing address-id in operation %u `%s' in episode `%s'\n",
1438 return GNUNET_SYSERR; 1487 op_counter, "DEL_ADDRESS", op_name);
1439 } 1488 GNUNET_free (op_name);
1440 GNUNET_free(op_name); 1489 return GNUNET_SYSERR;
1490 }
1491 GNUNET_free (op_name);
1441 1492
1442#if 0 1493#if 0
1443 /* plugin */ 1494 /* plugin */
1444 GNUNET_asprintf(&op_name, "op-%u-plugin", op_counter); 1495 GNUNET_asprintf (&op_name, "op-%u-plugin", op_counter);
1445 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1496 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1446 sec_name, op_name, &o->plugin)) 1497 sec_name, op_name,
1447 { 1498 &o->plugin))
1448 fprintf(stderr, "Missing plugin in operation %u `%s' in episode `%s'\n", 1499 {
1449 op_counter, "DEL_ADDRESS", op_name); 1500 fprintf (stderr, "Missing plugin in operation %u `%s' in episode `%s'\n",
1450 GNUNET_free(op_name); 1501 op_counter, "DEL_ADDRESS", op_name);
1451 return GNUNET_SYSERR; 1502 GNUNET_free (op_name);
1452 } 1503 return GNUNET_SYSERR;
1453 GNUNET_free(op_name); 1504 }
1505 GNUNET_free (op_name);
1454 1506
1455 /* address */ 1507 /* address */
1456 GNUNET_asprintf(&op_name, "op-%u-address", op_counter); 1508 GNUNET_asprintf (&op_name, "op-%u-address", op_counter);
1457 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1509 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1458 sec_name, op_name, &o->address)) 1510 sec_name, op_name,
1459 { 1511 &o->address))
1460 fprintf(stderr, "Missing address in operation %u `%s' in episode `%s'\n", 1512 {
1461 op_counter, "DEL_ADDRESS", op_name); 1513 fprintf (stderr, "Missing address in operation %u `%s' in episode `%s'\n",
1462 GNUNET_free(op_name); 1514 op_counter, "DEL_ADDRESS", op_name);
1463 return GNUNET_SYSERR; 1515 GNUNET_free (op_name);
1464 } 1516 return GNUNET_SYSERR;
1465 GNUNET_free(op_name); 1517 }
1518 GNUNET_free (op_name);
1466 1519
1467 /* session */ 1520 /* session */
1468 GNUNET_asprintf(&op_name, "op-%u-address-session", op_counter); 1521 GNUNET_asprintf (&op_name, "op-%u-address-session", op_counter);
1469 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1522 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1470 sec_name, op_name, &o->address_session)) 1523 sec_name, op_name,
1471 { 1524 &o->
1472 fprintf(stderr, "Missing address-session in operation %u `%s' in episode `%s'\n", 1525 address_session))
1473 op_counter, "DEL_ADDRESS", op_name); 1526 {
1474 GNUNET_free(op_name); 1527 fprintf (stderr,
1475 return GNUNET_SYSERR; 1528 "Missing address-session in operation %u `%s' in episode `%s'\n",
1476 } 1529 op_counter, "DEL_ADDRESS", op_name);
1477 GNUNET_free(op_name); 1530 GNUNET_free (op_name);
1531 return GNUNET_SYSERR;
1532 }
1533 GNUNET_free (op_name);
1478#endif 1534#endif
1479 1535
1480 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1536 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1481 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n", 1537 "Found operation %s: [%llu:%llu] address `%s' plugin `%s' \n",
1482 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin); 1538 "DEL_ADDRESS", o->peer_id, o->address_id, o->address, o->plugin);
1483 1539
1484 return GNUNET_OK; 1540 return GNUNET_OK;
1485} 1541}
1486 1542
1487 1543
1488static enum GNUNET_ATS_Property 1544static enum GNUNET_ATS_Property
1489parse_preference_string(const char * str) 1545parse_preference_string (const char *str)
1490{ 1546{
1491 int c = 0; 1547 int c = 0;
1492 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; 1548 char *props[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
1493 1549
1494 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++) 1550 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
1495 if (0 == strcmp(str, props[c])) 1551 if (0 == strcmp (str, props[c]))
1496 return c; 1552 return c;
1497 return 0; 1553 return 0;
1498} 1554}
1499 1555
1500 1556
1501static int 1557static int
1502load_op_start_set_preference(struct GNUNET_ATS_TEST_Operation *o, 1558load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1503 struct Episode *e, 1559 struct Episode *e,
1504 int op_counter, 1560 int op_counter,
1505 char *sec_name, 1561 char *sec_name,
1506 const struct GNUNET_CONFIGURATION_Handle *cfg) 1562 const struct GNUNET_CONFIGURATION_Handle *cfg)
1507{ 1563{
1508 char *op_name; 1564 char *op_name;
1509 char *type; 1565 char *type;
1510 char *pref; 1566 char *pref;
1511 1567
1512 /* peer pid */ 1568 /* peer pid */
1513 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1569 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1514 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1570 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1515 sec_name, op_name, &o->peer_id)) 1571 sec_name, op_name,
1516 { 1572 &o->peer_id))
1517 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 1573 {
1518 op_counter, "START_SET_PREFERENCE", op_name); 1574 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1519 GNUNET_free(op_name); 1575 op_counter, "START_SET_PREFERENCE", op_name);
1520 return GNUNET_SYSERR; 1576 GNUNET_free (op_name);
1521 } 1577 return GNUNET_SYSERR;
1522 GNUNET_free(op_name); 1578 }
1579 GNUNET_free (op_name);
1523 1580
1524 /* address pid */ 1581 /* address pid */
1525 GNUNET_asprintf(&op_name, "op-%u-client-id", op_counter); 1582 GNUNET_asprintf (&op_name, "op-%u-client-id", op_counter);
1526 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1583 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1527 sec_name, op_name, &o->client_id)) 1584 sec_name, op_name,
1528 { 1585 &o->client_id))
1529 fprintf(stderr, "Missing client-id in operation %u `%s' in episode `%s'\n", 1586 {
1530 op_counter, "START_SET_PREFERENCE", op_name); 1587 fprintf (stderr, "Missing client-id in operation %u `%s' in episode `%s'\n",
1531 GNUNET_free(op_name); 1588 op_counter, "START_SET_PREFERENCE", op_name);
1532 return GNUNET_SYSERR; 1589 GNUNET_free (op_name);
1533 } 1590 return GNUNET_SYSERR;
1534 GNUNET_free(op_name); 1591 }
1592 GNUNET_free (op_name);
1535 1593
1536 /* generator */ 1594 /* generator */
1537 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); 1595 GNUNET_asprintf (&op_name, "op-%u-gen-type", op_counter);
1538 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1596 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1539 sec_name, op_name, &type))) 1597 sec_name,
1540 { 1598 op_name, &type)))
1541 fprintf(stderr, "Missing type in operation %u `%s' in episode `%s'\n", 1599 {
1542 op_counter, "START_SET_PREFERENCE", op_name); 1600 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1543 GNUNET_free(op_name); 1601 op_counter, "START_SET_PREFERENCE", op_name);
1544 return GNUNET_SYSERR; 1602 GNUNET_free (op_name);
1545 } 1603 return GNUNET_SYSERR;
1604 }
1546 1605
1547 /* Load arguments for set_rate, start_send, set_preference */ 1606 /* Load arguments for set_rate, start_send, set_preference */
1548 if (0 == strcmp(type, "constant")) 1607 if (0 == strcmp (type, "constant"))
1549 { 1608 {
1550 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; 1609 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1551 } 1610 }
1552 else if (0 == strcmp(type, "linear")) 1611 else if (0 == strcmp (type, "linear"))
1553 { 1612 {
1554 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; 1613 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1555 } 1614 }
1556 else if (0 == strcmp(type, "sinus")) 1615 else if (0 == strcmp (type, "sinus"))
1557 { 1616 {
1558 o->gen_type = GNUNET_ATS_TEST_TG_SINUS; 1617 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1559 } 1618 }
1560 else if (0 == strcmp(type, "random")) 1619 else if (0 == strcmp (type, "random"))
1561 { 1620 {
1562 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; 1621 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1563 } 1622 }
1564 else 1623 else
1565 { 1624 {
1566 fprintf(stderr, "Invalid generator type %u `%s' in episode %u\n", 1625 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1567 op_counter, op_name, e->id); 1626 op_counter, op_name, e->id);
1568 GNUNET_free(type); 1627 GNUNET_free (type);
1569 GNUNET_free(op_name); 1628 GNUNET_free (op_name);
1570 return GNUNET_SYSERR; 1629 return GNUNET_SYSERR;
1571 } 1630 }
1572 GNUNET_free(type); 1631 GNUNET_free (type);
1573 GNUNET_free(op_name); 1632 GNUNET_free (op_name);
1574 1633
1575 1634
1576 /* Get base rate */ 1635 /* Get base rate */
1577 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); 1636 GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
1578 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1637 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1579 sec_name, op_name, &o->base_rate)) 1638 sec_name, op_name,
1580 { 1639 &o->base_rate))
1581 fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", 1640 {
1582 op_counter, op_name, e->id); 1641 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1583 GNUNET_free(op_name); 1642 op_counter, op_name, e->id);
1584 return GNUNET_SYSERR; 1643 GNUNET_free (op_name);
1585 } 1644 return GNUNET_SYSERR;
1586 GNUNET_free(op_name); 1645 }
1646 GNUNET_free (op_name);
1587 1647
1588 1648
1589 /* Get max rate */ 1649 /* Get max rate */
1590 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); 1650 GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
1591 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1651 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1592 sec_name, op_name, &o->max_rate)) 1652 sec_name, op_name,
1653 &o->max_rate))
1654 {
1655 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1656 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1657 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1593 { 1658 {
1594 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || 1659 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1595 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || 1660 op_counter, op_name, e->id);
1596 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) 1661 GNUNET_free (op_name);
1597 { 1662 return GNUNET_SYSERR;
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 }
1603 } 1663 }
1604 GNUNET_free(op_name); 1664 }
1665 GNUNET_free (op_name);
1605 1666
1606 /* Get period */ 1667 /* Get period */
1607 GNUNET_asprintf(&op_name, "op-%u-period", op_counter); 1668 GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
1608 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 1669 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1609 sec_name, op_name, &o->period)) 1670 sec_name, op_name,
1610 { 1671 &o->period))
1611 o->period = e->duration; 1672 {
1612 } 1673 o->period = e->duration;
1613 GNUNET_free(op_name); 1674 }
1675 GNUNET_free (op_name);
1614 1676
1615 /* Get frequency */ 1677 /* Get frequency */
1616 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); 1678 GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
1617 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 1679 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1618 sec_name, op_name, &o->frequency)) 1680 sec_name, op_name,
1619 { 1681 &o->frequency))
1620 fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", 1682 {
1621 op_counter, op_name, e->id); 1683 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1622 GNUNET_free(op_name); 1684 op_counter, op_name, e->id);
1623 return GNUNET_SYSERR; 1685 GNUNET_free (op_name);
1624 } 1686 return GNUNET_SYSERR;
1625 GNUNET_free(op_name); 1687 }
1688 GNUNET_free (op_name);
1626 1689
1627 /* Get preference */ 1690 /* Get preference */
1628 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); 1691 GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
1629 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1692 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1630 sec_name, op_name, &pref)) 1693 sec_name, op_name,
1631 { 1694 &pref))
1632 fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n", 1695 {
1633 op_counter, op_name, e->id); 1696 fprintf (stderr, "Missing preference in operation %u `%s' in episode %u\n",
1634 GNUNET_free(op_name); 1697 op_counter, op_name, e->id);
1635 return GNUNET_SYSERR; 1698 GNUNET_free (op_name);
1636 } 1699 return GNUNET_SYSERR;
1700 }
1637 1701
1638 if (0 == (o->pref_type = parse_preference_string(pref))) 1702 if (0 == (o->pref_type = parse_preference_string (pref)))
1639 { 1703 {
1640 fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n", 1704 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1641 op_counter, op_name, e->id); 1705 op_counter, op_name, e->id);
1642 GNUNET_free(op_name); 1706 GNUNET_free (op_name);
1643 GNUNET_free(pref); 1707 GNUNET_free (pref);
1644 return GNUNET_SYSERR; 1708 return GNUNET_SYSERR;
1645 } 1709 }
1646 GNUNET_free(pref); 1710 GNUNET_free (pref);
1647 GNUNET_free(op_name); 1711 GNUNET_free (op_name);
1648 1712
1649 /* Get feedback delay */ 1713 /* Get feedback delay */
1650 GNUNET_asprintf(&op_name, "op-%u-feedback_delay", op_counter); 1714 GNUNET_asprintf (&op_name, "op-%u-feedback_delay", op_counter);
1651 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time(cfg, 1715 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg,
1652 sec_name, op_name, &o->feedback_delay)) 1716 sec_name, op_name,
1653 { 1717 &o->feedback_delay))
1654 fprintf(stderr, "Using feedback delay %llu in operation %u `%s' in episode %u\n", 1718 {
1655 (long long unsigned int)o->feedback_delay.rel_value_us, 1719 fprintf (stderr,
1656 op_counter, op_name, e->id); 1720 "Using feedback delay %llu in operation %u `%s' in episode %u\n",
1657 } 1721 (long long unsigned int) o->feedback_delay.rel_value_us,
1722 op_counter, op_name, e->id);
1723 }
1658 else 1724 else
1659 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL; 1725 o->feedback_delay = GNUNET_TIME_UNIT_FOREVER_REL;
1660 GNUNET_free(op_name); 1726 GNUNET_free (op_name);
1661 1727
1662 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1728 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1663 "Found operation %s: [%llu:%llu]: %s = %llu\n", 1729 "Found operation %s: [%llu:%llu]: %s = %llu\n",
1664 "START_SET_PREFERENCE", o->peer_id, o->address_id, 1730 "START_SET_PREFERENCE", o->peer_id, o->address_id,
1665 GNUNET_ATS_print_preference_type(o->pref_type), o->base_rate); 1731 GNUNET_ATS_print_preference_type (o->pref_type), o->base_rate);
1666 1732
1667 return GNUNET_OK; 1733 return GNUNET_OK;
1668} 1734}
1669 1735
1670 1736
1671static int 1737static int
1672load_op_stop_set_preference(struct GNUNET_ATS_TEST_Operation *o, 1738load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o,
1673 struct Episode *e, 1739 struct Episode *e,
1674 int op_counter, 1740 int op_counter,
1675 char *sec_name, 1741 char *sec_name,
1676 const struct GNUNET_CONFIGURATION_Handle *cfg) 1742 const struct GNUNET_CONFIGURATION_Handle *cfg)
1677{ 1743{
1678 char *op_name; 1744 char *op_name;
1679 char *pref; 1745 char *pref;
1680 1746
1681 /* peer pid */ 1747 /* peer pid */
1682 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1748 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1683 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1749 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1684 sec_name, op_name, &o->peer_id)) 1750 sec_name, op_name,
1685 { 1751 &o->peer_id))
1686 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 1752 {
1687 op_counter, "STOP_SET_PREFERENCE", op_name); 1753 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1688 GNUNET_free(op_name); 1754 op_counter, "STOP_SET_PREFERENCE", op_name);
1689 return GNUNET_SYSERR; 1755 GNUNET_free (op_name);
1690 } 1756 return GNUNET_SYSERR;
1691 GNUNET_free(op_name); 1757 }
1758 GNUNET_free (op_name);
1692 1759
1693 /* address pid */ 1760 /* address pid */
1694 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); 1761 GNUNET_asprintf (&op_name, "op-%u-address-id", op_counter);
1695 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1762 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1696 sec_name, op_name, &o->address_id)) 1763 sec_name, op_name,
1697 { 1764 &o->address_id))
1698 fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", 1765 {
1699 op_counter, "STOP_SET_PREFERENCE", op_name); 1766 fprintf (stderr,
1700 GNUNET_free(op_name); 1767 "Missing address-id in operation %u `%s' in episode `%s'\n",
1701 return GNUNET_SYSERR; 1768 op_counter, "STOP_SET_PREFERENCE", op_name);
1702 } 1769 GNUNET_free (op_name);
1703 GNUNET_free(op_name); 1770 return GNUNET_SYSERR;
1771 }
1772 GNUNET_free (op_name);
1704 1773
1705 /* Get preference */ 1774 /* Get preference */
1706 GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); 1775 GNUNET_asprintf (&op_name, "op-%u-pref", op_counter);
1707 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1776 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1708 sec_name, op_name, &pref)) 1777 sec_name, op_name,
1709 { 1778 &pref))
1710 fprintf(stderr, "Missing preference in operation %u `%s' in episode `%s'\n", 1779 {
1711 op_counter, "STOP_SET_PREFERENCE", op_name); 1780 fprintf (stderr,
1712 GNUNET_free(op_name); 1781 "Missing preference in operation %u `%s' in episode `%s'\n",
1713 return GNUNET_SYSERR; 1782 op_counter, "STOP_SET_PREFERENCE", op_name);
1714 } 1783 GNUNET_free (op_name);
1715 1784 return GNUNET_SYSERR;
1716 if (0 == (o->pref_type = parse_preference_string(pref))) 1785 }
1717 { 1786
1718 fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n", 1787 if (0 == (o->pref_type = parse_preference_string (pref)))
1719 op_counter, op_name, e->id); 1788 {
1720 GNUNET_free(op_name); 1789 fprintf (stderr, "Invalid preference in operation %u `%s' in episode %u\n",
1721 GNUNET_free(pref); 1790 op_counter, op_name, e->id);
1722 return GNUNET_SYSERR; 1791 GNUNET_free (op_name);
1723 } 1792 GNUNET_free (pref);
1724 GNUNET_free(pref); 1793 return GNUNET_SYSERR;
1725 GNUNET_free(op_name); 1794 }
1726 1795 GNUNET_free (pref);
1727 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1796 GNUNET_free (op_name);
1728 "Found operation %s: [%llu:%llu]: %s\n", 1797
1729 "STOP_SET_PREFERENCE", o->peer_id, o->address_id, 1798 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1730 GNUNET_ATS_print_preference_type(o->pref_type)); 1799 "Found operation %s: [%llu:%llu]: %s\n",
1800 "STOP_SET_PREFERENCE", o->peer_id, o->address_id,
1801 GNUNET_ATS_print_preference_type (o->pref_type));
1731 return GNUNET_OK; 1802 return GNUNET_OK;
1732} 1803}
1733 1804
1734 1805
1735static enum GNUNET_ATS_Property 1806static enum GNUNET_ATS_Property
1736parse_property_string(const char *str) 1807parse_property_string (const char *str)
1737{ 1808{
1738 enum GNUNET_ATS_Property c; 1809 enum GNUNET_ATS_Property c;
1739 1810
1740 for (c = 0; c < GNUNET_ATS_PropertyCount; c++) 1811 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
1741 if (0 == strcmp(str, 1812 if (0 == strcmp (str,
1742 GNUNET_ATS_print_property_type(c))) 1813 GNUNET_ATS_print_property_type (c)))
1743 return c; 1814 return c;
1744 return 0; 1815 return 0;
1745} 1816}
1746 1817
1747 1818
1748static int 1819static int
1749load_op_start_set_property(struct GNUNET_ATS_TEST_Operation *o, 1820load_op_start_set_property (struct GNUNET_ATS_TEST_Operation *o,
1750 struct Episode *e, 1821 struct Episode *e,
1751 int op_counter, 1822 int op_counter,
1752 char *sec_name, 1823 char *sec_name,
1753 const struct GNUNET_CONFIGURATION_Handle *cfg) 1824 const struct GNUNET_CONFIGURATION_Handle *cfg)
1754{ 1825{
1755 char *op_name; 1826 char *op_name;
1756 char *type; 1827 char *type;
1757 char *prop; 1828 char *prop;
1758 1829
1759 /* peer pid */ 1830 /* peer pid */
1760 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1831 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1761 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1832 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1762 sec_name, op_name, &o->peer_id)) 1833 sec_name, op_name,
1763 { 1834 &o->peer_id))
1764 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 1835 {
1765 op_counter, "START_SET_PROPERTY", op_name); 1836 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1766 GNUNET_free(op_name); 1837 op_counter, "START_SET_PROPERTY", op_name);
1767 return GNUNET_SYSERR; 1838 GNUNET_free (op_name);
1768 } 1839 return GNUNET_SYSERR;
1769 GNUNET_free(op_name); 1840 }
1841 GNUNET_free (op_name);
1770 1842
1771 /* address pid */ 1843 /* address pid */
1772 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); 1844 GNUNET_asprintf (&op_name, "op-%u-address-id", op_counter);
1773 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1845 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1774 sec_name, op_name, &o->address_id)) 1846 sec_name, op_name,
1775 { 1847 &o->address_id))
1776 fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", 1848 {
1777 op_counter, "START_SET_PROPERTY", op_name); 1849 fprintf (stderr,
1778 GNUNET_free(op_name); 1850 "Missing address-id in operation %u `%s' in episode `%s'\n",
1779 return GNUNET_SYSERR; 1851 op_counter, "START_SET_PROPERTY", op_name);
1780 } 1852 GNUNET_free (op_name);
1781 GNUNET_free(op_name); 1853 return GNUNET_SYSERR;
1854 }
1855 GNUNET_free (op_name);
1782 1856
1783 /* generator */ 1857 /* generator */
1784 GNUNET_asprintf(&op_name, "op-%u-gen-type", op_counter); 1858 GNUNET_asprintf (&op_name, "op-%u-gen-type", op_counter);
1785 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1859 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1786 sec_name, op_name, &type))) 1860 sec_name,
1787 { 1861 op_name, &type)))
1788 fprintf(stderr, "Missing type in operation %u `%s' in episode `%s'\n", 1862 {
1789 op_counter, "START_SET_PROPERTY", op_name); 1863 fprintf (stderr, "Missing type in operation %u `%s' in episode `%s'\n",
1790 GNUNET_free(op_name); 1864 op_counter, "START_SET_PROPERTY", op_name);
1791 return GNUNET_SYSERR; 1865 GNUNET_free (op_name);
1792 } 1866 return GNUNET_SYSERR;
1867 }
1793 1868
1794 /* Load arguments for set_rate, start_send, set_preference */ 1869 /* Load arguments for set_rate, start_send, set_preference */
1795 if (0 == strcmp(type, "constant")) 1870 if (0 == strcmp (type, "constant"))
1796 { 1871 {
1797 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; 1872 o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT;
1798 } 1873 }
1799 else if (0 == strcmp(type, "linear")) 1874 else if (0 == strcmp (type, "linear"))
1800 { 1875 {
1801 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; 1876 o->gen_type = GNUNET_ATS_TEST_TG_LINEAR;
1802 } 1877 }
1803 else if (0 == strcmp(type, "sinus")) 1878 else if (0 == strcmp (type, "sinus"))
1804 { 1879 {
1805 o->gen_type = GNUNET_ATS_TEST_TG_SINUS; 1880 o->gen_type = GNUNET_ATS_TEST_TG_SINUS;
1806 } 1881 }
1807 else if (0 == strcmp(type, "random")) 1882 else if (0 == strcmp (type, "random"))
1808 { 1883 {
1809 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; 1884 o->gen_type = GNUNET_ATS_TEST_TG_RANDOM;
1810 } 1885 }
1811 else 1886 else
1812 { 1887 {
1813 fprintf(stderr, "Invalid generator type %u `%s' in episode %u\n", 1888 fprintf (stderr, "Invalid generator type %u `%s' in episode %u\n",
1814 op_counter, op_name, e->id); 1889 op_counter, op_name, e->id);
1815 GNUNET_free(type); 1890 GNUNET_free (type);
1816 GNUNET_free(op_name); 1891 GNUNET_free (op_name);
1817 return GNUNET_SYSERR; 1892 return GNUNET_SYSERR;
1818 } 1893 }
1819 GNUNET_free(type); 1894 GNUNET_free (type);
1820 GNUNET_free(op_name); 1895 GNUNET_free (op_name);
1821 1896
1822 1897
1823 /* Get base rate */ 1898 /* Get base rate */
1824 GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); 1899 GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter);
1825 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1900 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1826 sec_name, op_name, &o->base_rate)) 1901 sec_name, op_name,
1827 { 1902 &o->base_rate))
1828 fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", 1903 {
1829 op_counter, op_name, e->id); 1904 fprintf (stderr, "Missing base rate in operation %u `%s' in episode %u\n",
1830 GNUNET_free(op_name); 1905 op_counter, op_name, e->id);
1831 return GNUNET_SYSERR; 1906 GNUNET_free (op_name);
1832 } 1907 return GNUNET_SYSERR;
1833 GNUNET_free(op_name); 1908 }
1909 GNUNET_free (op_name);
1834 1910
1835 1911
1836 /* Get max rate */ 1912 /* Get max rate */
1837 GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); 1913 GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter);
1838 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1914 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1839 sec_name, op_name, &o->max_rate)) 1915 sec_name, op_name,
1916 &o->max_rate))
1917 {
1918 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) ||
1919 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) ||
1920 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type))
1840 { 1921 {
1841 if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || 1922 fprintf (stderr, "Missing max rate in operation %u `%s' in episode %u\n",
1842 (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || 1923 op_counter, op_name, e->id);
1843 (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) 1924 GNUNET_free (op_name);
1844 { 1925 return GNUNET_SYSERR;
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 }
1850 } 1926 }
1851 GNUNET_free(op_name); 1927 }
1928 GNUNET_free (op_name);
1852 1929
1853 /* Get period */ 1930 /* Get period */
1854 GNUNET_asprintf(&op_name, "op-%u-period", op_counter); 1931 GNUNET_asprintf (&op_name, "op-%u-period", op_counter);
1855 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 1932 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1856 sec_name, op_name, &o->period)) 1933 sec_name, op_name,
1857 { 1934 &o->period))
1858 o->period = e->duration; 1935 {
1859 } 1936 o->period = e->duration;
1860 GNUNET_free(op_name); 1937 }
1938 GNUNET_free (op_name);
1861 1939
1862 /* Get frequency */ 1940 /* Get frequency */
1863 GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); 1941 GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter);
1864 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 1942 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
1865 sec_name, op_name, &o->frequency)) 1943 sec_name, op_name,
1866 { 1944 &o->frequency))
1867 fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", 1945 {
1868 op_counter, op_name, e->id); 1946 fprintf (stderr, "Missing frequency in operation %u `%s' in episode %u\n",
1869 GNUNET_free(op_name); 1947 op_counter, op_name, e->id);
1870 return GNUNET_SYSERR; 1948 GNUNET_free (op_name);
1871 } 1949 return GNUNET_SYSERR;
1872 GNUNET_free(op_name); 1950 }
1951 GNUNET_free (op_name);
1873 1952
1874 /* Get preference */ 1953 /* Get preference */
1875 GNUNET_asprintf(&op_name, "op-%u-property", op_counter); 1954 GNUNET_asprintf (&op_name, "op-%u-property", op_counter);
1876 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 1955 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1877 sec_name, op_name, &prop)) 1956 sec_name, op_name,
1878 { 1957 &prop))
1879 fprintf(stderr, "Missing property in operation %u `%s' in episode %u\n", 1958 {
1880 op_counter, op_name, e->id); 1959 fprintf (stderr, "Missing property in operation %u `%s' in episode %u\n",
1881 GNUNET_free(op_name); 1960 op_counter, op_name, e->id);
1882 GNUNET_free_non_null(prop); 1961 GNUNET_free (op_name);
1883 return GNUNET_SYSERR; 1962 GNUNET_free_non_null (prop);
1884 } 1963 return GNUNET_SYSERR;
1885 1964 }
1886 if (0 == (o->prop_type = parse_property_string(prop))) 1965
1887 { 1966 if (0 == (o->prop_type = parse_property_string (prop)))
1888 fprintf(stderr, "Invalid property in operation %u `%s' in episode %u\n", 1967 {
1889 op_counter, op_name, e->id); 1968 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1890 GNUNET_free(op_name); 1969 op_counter, op_name, e->id);
1891 GNUNET_free(prop); 1970 GNUNET_free (op_name);
1892 return GNUNET_SYSERR; 1971 GNUNET_free (prop);
1893 } 1972 return GNUNET_SYSERR;
1973 }
1894 1974
1895 GNUNET_free(prop); 1975 GNUNET_free (prop);
1896 GNUNET_free(op_name); 1976 GNUNET_free (op_name);
1897 1977
1898 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1978 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1899 "Found operation %s: [%llu:%llu] %s = %llu\n", 1979 "Found operation %s: [%llu:%llu] %s = %llu\n",
1900 "START_SET_PROPERTY", o->peer_id, o->address_id, 1980 "START_SET_PROPERTY", o->peer_id, o->address_id,
1901 GNUNET_ATS_print_property_type(o->prop_type), o->base_rate); 1981 GNUNET_ATS_print_property_type (o->prop_type), o->base_rate);
1902 1982
1903 return GNUNET_OK; 1983 return GNUNET_OK;
1904} 1984}
1905 1985
1906static int 1986static int
1907load_op_stop_set_property(struct GNUNET_ATS_TEST_Operation *o, 1987load_op_stop_set_property (struct GNUNET_ATS_TEST_Operation *o,
1908 struct Episode *e, 1988 struct Episode *e,
1909 int op_counter, 1989 int op_counter,
1910 char *sec_name, 1990 char *sec_name,
1911 const struct GNUNET_CONFIGURATION_Handle *cfg) 1991 const struct GNUNET_CONFIGURATION_Handle *cfg)
1912{ 1992{
1913 char *op_name; 1993 char *op_name;
1914 char *pref; 1994 char *pref;
1915 1995
1916 /* peer pid */ 1996 /* peer pid */
1917 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 1997 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1918 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 1998 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1919 sec_name, op_name, &o->peer_id)) 1999 sec_name, op_name,
1920 { 2000 &o->peer_id))
1921 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 2001 {
1922 op_counter, "STOP_SET_PROPERTY", op_name); 2002 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1923 GNUNET_free(op_name); 2003 op_counter, "STOP_SET_PROPERTY", op_name);
1924 return GNUNET_SYSERR; 2004 GNUNET_free (op_name);
1925 } 2005 return GNUNET_SYSERR;
1926 GNUNET_free(op_name); 2006 }
2007 GNUNET_free (op_name);
1927 2008
1928 /* address pid */ 2009 /* address pid */
1929 GNUNET_asprintf(&op_name, "op-%u-address-id", op_counter); 2010 GNUNET_asprintf (&op_name, "op-%u-address-id", op_counter);
1930 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 2011 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1931 sec_name, op_name, &o->address_id)) 2012 sec_name, op_name,
1932 { 2013 &o->address_id))
1933 fprintf(stderr, "Missing address-id in operation %u `%s' in episode `%s'\n", 2014 {
1934 op_counter, "STOP_SET_PROPERTY", op_name); 2015 fprintf (stderr,
1935 GNUNET_free(op_name); 2016 "Missing address-id in operation %u `%s' in episode `%s'\n",
1936 return GNUNET_SYSERR; 2017 op_counter, "STOP_SET_PROPERTY", op_name);
1937 } 2018 GNUNET_free (op_name);
1938 GNUNET_free(op_name); 2019 return GNUNET_SYSERR;
2020 }
2021 GNUNET_free (op_name);
1939 2022
1940 /* Get property */ 2023 /* Get property */
1941 GNUNET_asprintf(&op_name, "op-%u-property", op_counter); 2024 GNUNET_asprintf (&op_name, "op-%u-property", op_counter);
1942 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 2025 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
1943 sec_name, op_name, &pref)) 2026 sec_name, op_name,
1944 { 2027 &pref))
1945 fprintf(stderr, "Missing property in operation %u `%s' in episode `%s'\n", 2028 {
1946 op_counter, "STOP_SET_PROPERTY", op_name); 2029 fprintf (stderr, "Missing property in operation %u `%s' in episode `%s'\n",
1947 GNUNET_free(op_name); 2030 op_counter, "STOP_SET_PROPERTY", op_name);
1948 GNUNET_free_non_null(pref); 2031 GNUNET_free (op_name);
1949 return GNUNET_SYSERR; 2032 GNUNET_free_non_null (pref);
1950 } 2033 return GNUNET_SYSERR;
1951 2034 }
1952 if (0 == (o->prop_type = parse_property_string(pref))) 2035
1953 { 2036 if (0 == (o->prop_type = parse_property_string (pref)))
1954 fprintf(stderr, "Invalid property in operation %u `%s' in episode %u\n", 2037 {
1955 op_counter, op_name, e->id); 2038 fprintf (stderr, "Invalid property in operation %u `%s' in episode %u\n",
1956 GNUNET_free(op_name); 2039 op_counter, op_name, e->id);
1957 GNUNET_free_non_null(pref); 2040 GNUNET_free (op_name);
1958 return GNUNET_SYSERR; 2041 GNUNET_free_non_null (pref);
1959 } 2042 return GNUNET_SYSERR;
2043 }
1960 2044
1961 GNUNET_free(pref); 2045 GNUNET_free (pref);
1962 GNUNET_free(op_name); 2046 GNUNET_free (op_name);
1963 2047
1964 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2048 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1965 "Found operation %s: [%llu:%llu] %s\n", 2049 "Found operation %s: [%llu:%llu] %s\n",
1966 "STOP_SET_PROPERTY", o->peer_id, o->address_id, 2050 "STOP_SET_PROPERTY", o->peer_id, o->address_id,
1967 GNUNET_ATS_print_property_type(o->prop_type)); 2051 GNUNET_ATS_print_property_type (o->prop_type));
1968 2052
1969 return GNUNET_OK; 2053 return GNUNET_OK;
1970} 2054}
1971 2055
1972 2056
1973static int 2057static int
1974load_op_start_request(struct GNUNET_ATS_TEST_Operation *o, 2058load_op_start_request (struct GNUNET_ATS_TEST_Operation *o,
1975 struct Episode *e, 2059 struct Episode *e,
1976 int op_counter, 2060 int op_counter,
1977 char *sec_name, 2061 char *sec_name,
1978 const struct GNUNET_CONFIGURATION_Handle *cfg) 2062 const struct GNUNET_CONFIGURATION_Handle *cfg)
1979{ 2063{
1980 char *op_name; 2064 char *op_name;
1981 2065
1982 /* peer pid */ 2066 /* peer pid */
1983 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 2067 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
1984 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 2068 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
1985 sec_name, op_name, &o->peer_id)) 2069 sec_name, op_name,
1986 { 2070 &o->peer_id))
1987 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 2071 {
1988 op_counter, "START_REQUEST", op_name); 2072 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
1989 GNUNET_free(op_name); 2073 op_counter, "START_REQUEST", op_name);
1990 return GNUNET_SYSERR; 2074 GNUNET_free (op_name);
1991 } 2075 return GNUNET_SYSERR;
1992 GNUNET_free(op_name); 2076 }
2077 GNUNET_free (op_name);
1993 return GNUNET_OK; 2078 return GNUNET_OK;
1994} 2079}
1995 2080
1996static int 2081static int
1997load_op_stop_request(struct GNUNET_ATS_TEST_Operation *o, 2082load_op_stop_request (struct GNUNET_ATS_TEST_Operation *o,
1998 struct Episode *e, 2083 struct Episode *e,
1999 int op_counter, 2084 int op_counter,
2000 char *sec_name, 2085 char *sec_name,
2001 const struct GNUNET_CONFIGURATION_Handle *cfg) 2086 const struct GNUNET_CONFIGURATION_Handle *cfg)
2002{ 2087{
2003 char *op_name; 2088 char *op_name;
2004 2089
2005 /* peer pid */ 2090 /* peer pid */
2006 GNUNET_asprintf(&op_name, "op-%u-peer-id", op_counter); 2091 GNUNET_asprintf (&op_name, "op-%u-peer-id", op_counter);
2007 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, 2092 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg,
2008 sec_name, op_name, &o->peer_id)) 2093 sec_name, op_name,
2009 { 2094 &o->peer_id))
2010 fprintf(stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n", 2095 {
2011 op_counter, "STOP_REQUEST", op_name); 2096 fprintf (stderr, "Missing peer-id in operation %u `%s' in episode `%s'\n",
2012 GNUNET_free(op_name); 2097 op_counter, "STOP_REQUEST", op_name);
2013 return GNUNET_SYSERR; 2098 GNUNET_free (op_name);
2014 } 2099 return GNUNET_SYSERR;
2015 GNUNET_free(op_name); 2100 }
2101 GNUNET_free (op_name);
2016 return GNUNET_OK; 2102 return GNUNET_OK;
2017} 2103}
2018 2104
2019 2105
2020static int 2106static int
2021load_episode(struct Experiment *e, struct Episode *cur, 2107load_episode (struct Experiment *e, struct Episode *cur,
2022 struct GNUNET_CONFIGURATION_Handle *cfg) 2108 struct GNUNET_CONFIGURATION_Handle *cfg)
2023{ 2109{
2024 struct GNUNET_ATS_TEST_Operation *o; 2110 struct GNUNET_ATS_TEST_Operation *o;
2025 char *sec_name; 2111 char *sec_name;
@@ -2028,98 +2114,99 @@ load_episode(struct Experiment *e, struct Episode *cur,
2028 int op_counter = 0; 2114 int op_counter = 0;
2029 int res; 2115 int res;
2030 2116
2031 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n", cur->id); 2117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Parsing episode %u\n", cur->id);
2032 GNUNET_asprintf(&sec_name, "episode-%u", cur->id); 2118 GNUNET_asprintf (&sec_name, "episode-%u", cur->id);
2033 2119
2034 while (1) 2120 while (1)
2121 {
2122 /* Load operation */
2123 GNUNET_asprintf (&op_name, "op-%u-operation", op_counter);
2124 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg,
2125 sec_name,
2126 op_name, &op))
2035 { 2127 {
2036 /* Load operation */ 2128 GNUNET_free (op_name);
2037 GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); 2129 break;
2038 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, 2130 }
2039 sec_name, op_name, &op)) 2131 o = GNUNET_new (struct GNUNET_ATS_TEST_Operation);
2040 { 2132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "==== Parsing operation %u: `%s'\n",
2041 GNUNET_free(op_name); 2133 cur->id, 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);
2047 2134
2048 /* operations = set_rate, start_send, stop_send, set_preference */ 2135 /* operations = set_rate, start_send, stop_send, set_preference */
2049 if (0 == strcmp(op, "address_add")) 2136 if (0 == strcmp (op, "address_add"))
2050 { 2137 {
2051 o->type = SOLVER_OP_ADD_ADDRESS; 2138 o->type = SOLVER_OP_ADD_ADDRESS;
2052 res = load_op_add_address(o, cur, 2139 res = load_op_add_address (o, cur,
2053 op_counter, sec_name, cfg); 2140 op_counter, sec_name, cfg);
2054 } 2141 }
2055 else if (0 == strcmp(op, "address_del")) 2142 else if (0 == strcmp (op, "address_del"))
2056 { 2143 {
2057 o->type = SOLVER_OP_DEL_ADDRESS; 2144 o->type = SOLVER_OP_DEL_ADDRESS;
2058 res = load_op_del_address(o, cur, 2145 res = load_op_del_address (o, cur,
2059 op_counter, sec_name, cfg); 2146 op_counter, sec_name, cfg);
2060 } 2147 }
2061 else if (0 == strcmp(op, "start_set_property")) 2148 else if (0 == strcmp (op, "start_set_property"))
2062 { 2149 {
2063 o->type = SOLVER_OP_START_SET_PROPERTY; 2150 o->type = SOLVER_OP_START_SET_PROPERTY;
2064 res = load_op_start_set_property(o, cur, 2151 res = load_op_start_set_property (o, cur,
2065 op_counter, sec_name, cfg); 2152 op_counter, sec_name, cfg);
2066 } 2153 }
2067 else if (0 == strcmp(op, "stop_set_property")) 2154 else if (0 == strcmp (op, "stop_set_property"))
2068 { 2155 {
2069 o->type = SOLVER_OP_STOP_SET_PROPERTY; 2156 o->type = SOLVER_OP_STOP_SET_PROPERTY;
2070 res = load_op_stop_set_property(o, cur, 2157 res = load_op_stop_set_property (o, cur,
2158 op_counter, sec_name, cfg);
2159 }
2160 else if (0 == strcmp (op, "start_set_preference"))
2161 {
2162 o->type = SOLVER_OP_START_SET_PREFERENCE;
2163 res = load_op_start_set_preference (o, cur,
2071 op_counter, sec_name, cfg); 2164 op_counter, sec_name, cfg);
2072 } 2165 }
2073 else if (0 == strcmp(op, "start_set_preference")) 2166 else if (0 == strcmp (op, "stop_set_preference"))
2074 { 2167 {
2075 o->type = SOLVER_OP_START_SET_PREFERENCE; 2168 o->type = SOLVER_OP_STOP_SET_PREFERENCE;
2076 res = load_op_start_set_preference(o, cur, 2169 res = load_op_stop_set_preference (o, cur,
2077 op_counter, sec_name, cfg); 2170 op_counter, sec_name, cfg);
2078 } 2171 }
2079 else if (0 == strcmp(op, "stop_set_preference")) 2172 else if (0 == strcmp (op, "start_request"))
2080 { 2173 {
2081 o->type = SOLVER_OP_STOP_SET_PREFERENCE; 2174 o->type = SOLVER_OP_START_REQUEST;
2082 res = load_op_stop_set_preference(o, cur, 2175 res = load_op_start_request (o, cur,
2083 op_counter, sec_name, cfg); 2176 op_counter, sec_name, cfg);
2084 } 2177 }
2085 else if (0 == strcmp(op, "start_request")) 2178 else if (0 == strcmp (op, "stop_request"))
2086 { 2179 {
2087 o->type = SOLVER_OP_START_REQUEST; 2180 o->type = SOLVER_OP_STOP_REQUEST;
2088 res = load_op_start_request(o, cur, 2181 res = load_op_stop_request (o, cur,
2089 op_counter, sec_name, cfg); 2182 op_counter, sec_name, cfg);
2090 } 2183 }
2091 else if (0 == strcmp(op, "stop_request")) 2184 else
2092 { 2185 {
2093 o->type = SOLVER_OP_STOP_REQUEST; 2186 fprintf (stderr, "Invalid operation %u `%s' in episode %u\n",
2094 res = load_op_stop_request(o, cur, 2187 op_counter, op, cur->id);
2095 op_counter, sec_name, cfg); 2188 res = GNUNET_SYSERR;
2096 } 2189 }
2097 else
2098 {
2099 fprintf(stderr, "Invalid operation %u `%s' in episode %u\n",
2100 op_counter, op, cur->id);
2101 res = GNUNET_SYSERR;
2102 }
2103
2104 GNUNET_free(op);
2105 GNUNET_free(op_name);
2106 2190
2107 if (GNUNET_SYSERR == res) 2191 GNUNET_free (op);
2108 { 2192 GNUNET_free (op_name);
2109 GNUNET_free(o);
2110 GNUNET_free(sec_name);
2111 return GNUNET_SYSERR;
2112 }
2113 2193
2114 GNUNET_CONTAINER_DLL_insert_tail(cur->head, cur->tail, o); 2194 if (GNUNET_SYSERR == res)
2115 op_counter++; 2195 {
2196 GNUNET_free (o);
2197 GNUNET_free (sec_name);
2198 return GNUNET_SYSERR;
2116 } 2199 }
2117 GNUNET_free(sec_name); 2200
2201 GNUNET_CONTAINER_DLL_insert_tail (cur->head, cur->tail, o);
2202 op_counter++;
2203 }
2204 GNUNET_free (sec_name);
2118 return GNUNET_OK; 2205 return GNUNET_OK;
2119} 2206}
2120 2207
2121static int 2208static int
2122load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) 2209load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2123{ 2210{
2124 int e_counter = 0; 2211 int e_counter = 0;
2125 char *sec_name; 2212 char *sec_name;
@@ -2130,87 +2217,92 @@ load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg)
2130 e_counter = 0; 2217 e_counter = 0;
2131 last = NULL; 2218 last = NULL;
2132 while (1) 2219 while (1)
2220 {
2221 GNUNET_asprintf (&sec_name, "episode-%u", e_counter);
2222 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg,
2223 sec_name,
2224 "duration",
2225 &e_duration))
2133 { 2226 {
2134 GNUNET_asprintf(&sec_name, "episode-%u", e_counter); 2227 GNUNET_free (sec_name);
2135 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, 2228 break;
2136 sec_name, "duration", &e_duration)) 2229 }
2137 {
2138 GNUNET_free(sec_name);
2139 break;
2140 }
2141
2142 cur = GNUNET_new(struct Episode);
2143 cur->duration = e_duration;
2144 cur->id = e_counter;
2145
2146 if (GNUNET_OK != load_episode(e, cur, cfg))
2147 {
2148 GNUNET_free(sec_name);
2149 GNUNET_free(cur);
2150 return GNUNET_SYSERR;
2151 }
2152
2153 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2154 e_counter,
2155 GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES));
2156 2230
2157 /* Update experiment */ 2231 cur = GNUNET_new (struct Episode);
2158 e->num_episodes++; 2232 cur->duration = e_duration;
2159 e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); 2233 cur->id = e_counter;
2160 /* Put in linked list */
2161 if (NULL == last)
2162 e->start = cur;
2163 else
2164 last->next = cur;
2165 2234
2166 GNUNET_free(sec_name); 2235 if (GNUNET_OK != load_episode (e, cur, cfg))
2167 e_counter++; 2236 {
2168 last = cur; 2237 GNUNET_free (sec_name);
2238 GNUNET_free (cur);
2239 return GNUNET_SYSERR;
2169 } 2240 }
2241
2242 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Found episode %u with duration %s \n",
2243 e_counter,
2244 GNUNET_STRINGS_relative_time_to_string (cur->duration,
2245 GNUNET_YES));
2246
2247 /* Update experiment */
2248 e->num_episodes++;
2249 e->total_duration = GNUNET_TIME_relative_add (e->total_duration,
2250 cur->duration);
2251 /* Put in linked list */
2252 if (NULL == last)
2253 e->start = cur;
2254 else
2255 last->next = cur;
2256
2257 GNUNET_free (sec_name);
2258 e_counter++;
2259 last = cur;
2260 }
2170 return e_counter; 2261 return e_counter;
2171} 2262}
2172 2263
2173 2264
2174static void 2265static void
2175timeout_experiment(void *cls) 2266timeout_experiment (void *cls)
2176{ 2267{
2177 struct Experiment *e = cls; 2268 struct Experiment *e = cls;
2178 2269
2179 e->experiment_timeout_task = NULL; 2270 e->experiment_timeout_task = NULL;
2180 fprintf(stderr, "Experiment timeout!\n"); 2271 fprintf (stderr, "Experiment timeout!\n");
2181 2272
2182 if (NULL != e->episode_timeout_task) 2273 if (NULL != e->episode_timeout_task)
2183 { 2274 {
2184 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 2275 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2185 e->episode_timeout_task = NULL; 2276 e->episode_timeout_task = NULL;
2186 } 2277 }
2187 2278
2188 e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), 2279 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
2189 GNUNET_SYSERR); 2280 GNUNET_SYSERR);
2190} 2281}
2191 2282
2192struct ATS_Address * 2283struct ATS_Address *
2193create_ats_address(const struct GNUNET_PeerIdentity *peer, 2284create_ats_address (const struct GNUNET_PeerIdentity *peer,
2194 const char *plugin_name, 2285 const char *plugin_name,
2195 const void *plugin_addr, 2286 const void *plugin_addr,
2196 size_t plugin_addr_len, 2287 size_t plugin_addr_len,
2197 uint32_t session_id, 2288 uint32_t session_id,
2198 uint32_t network) 2289 uint32_t network)
2199{ 2290{
2200 struct ATS_Address *aa = NULL; 2291 struct ATS_Address *aa = NULL;
2201 2292
2202 aa = GNUNET_malloc(sizeof(struct ATS_Address) + plugin_addr_len + strlen(plugin_name) + 1); 2293 aa = GNUNET_malloc (sizeof(struct ATS_Address) + plugin_addr_len + strlen (
2203 aa->atsi = GNUNET_new(struct GNUNET_ATS_Information); 2294 plugin_name) + 1);
2204 aa->atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE); 2295 aa->atsi = GNUNET_new (struct GNUNET_ATS_Information);
2205 aa->atsi[0].value = htonl(network); 2296 aa->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
2297 aa->atsi[0].value = htonl (network);
2206 aa->atsi_count = 1; 2298 aa->atsi_count = 1;
2207 2299
2208 aa->peer = *peer; 2300 aa->peer = *peer;
2209 aa->addr_len = plugin_addr_len; 2301 aa->addr_len = plugin_addr_len;
2210 aa->addr = &aa[1]; 2302 aa->addr = &aa[1];
2211 aa->plugin = (char *)&aa[1] + plugin_addr_len; 2303 aa->plugin = (char *) &aa[1] + plugin_addr_len;
2212 GNUNET_memcpy(&aa[1], plugin_addr, plugin_addr_len); 2304 GNUNET_memcpy (&aa[1], plugin_addr, plugin_addr_len);
2213 GNUNET_memcpy(aa->plugin, plugin_name, strlen(plugin_name) + 1); 2305 GNUNET_memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
2214 aa->session_id = session_id; 2306 aa->session_id = session_id;
2215 2307
2216 return aa; 2308 return aa;
@@ -2219,529 +2311,563 @@ create_ats_address(const struct GNUNET_PeerIdentity *peer,
2219 2311
2220 2312
2221static void 2313static void
2222enforce_add_address(struct GNUNET_ATS_TEST_Operation *op) 2314enforce_add_address (struct GNUNET_ATS_TEST_Operation *op)
2223{ 2315{
2224 struct TestPeer *p; 2316 struct TestPeer *p;
2225 struct TestAddress *a; 2317 struct TestAddress *a;
2226 int c; 2318 int c;
2227 2319
2228 if (NULL == (p = find_peer_by_id(op->peer_id))) 2320 if (NULL == (p = find_peer_by_id (op->peer_id)))
2321 {
2322 p = GNUNET_new (struct TestPeer);
2323 p->id = op->peer_id;
2324 p->assigned_bw_in = 0;
2325 p->assigned_bw_out = 0;
2326 memset (&p->peer_id, op->peer_id, sizeof(p->peer_id));
2327 for (c = 0; c < GNUNET_ATS_PreferenceCount; c++)
2229 { 2328 {
2230 p = GNUNET_new(struct TestPeer); 2329 p->pref_abs[c] = DEFAULT_ABS_PREFERENCE;
2231 p->id = op->peer_id; 2330 p->pref_norm[c] = DEFAULT_REL_PREFERENCE;
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 }
2240
2241 GNUNET_CONTAINER_DLL_insert(peer_head, peer_tail, p);
2242 } 2331 }
2243 2332
2244 if (NULL != (find_address_by_id(p, op->address_id))) 2333 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, p);
2245 { 2334 }
2246 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2247 op->address_id, op->peer_id);
2248 return;
2249 }
2250 2335
2251 a = GNUNET_new(struct TestAddress); 2336 if (NULL != (find_address_by_id (p, op->address_id)))
2337 {
2338 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Duplicate address %u for peer %u\n",
2339 op->address_id, op->peer_id);
2340 return;
2341 }
2342
2343 a = GNUNET_new (struct TestAddress);
2252 a->aid = op->address_id; 2344 a->aid = op->address_id;
2253 a->network = op->address_network; 2345 a->network = op->address_network;
2254 a->ats_addr = create_ats_address(&p->peer_id, op->plugin, op->address, 2346 a->ats_addr = create_ats_address (&p->peer_id, op->plugin, op->address,
2255 strlen(op->address) + 1, op->address_session, op->address_network); 2347 strlen (op->address) + 1,
2256 memset(&p->peer_id, op->peer_id, sizeof(p->peer_id)); 2348 op->address_session, op->address_network);
2257 GNUNET_CONTAINER_DLL_insert_tail(p->addr_head, p->addr_tail, a); 2349 memset (&p->peer_id, op->peer_id, sizeof(p->peer_id));
2350 GNUNET_CONTAINER_DLL_insert_tail (p->addr_head, p->addr_tail, a);
2258 2351
2259 for (c = 0; c < GNUNET_ATS_PropertyCount; c++) 2352 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
2260 a->prop_norm[c] = DEFAULT_REL_QUALITY; 2353 a->prop_norm[c] = DEFAULT_REL_QUALITY;
2261 2354
2262 GNUNET_CONTAINER_multipeermap_put(sh->addresses, &p->peer_id, a->ats_addr, 2355 GNUNET_CONTAINER_multipeermap_put (sh->addresses, &p->peer_id, a->ats_addr,
2263 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2356 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2264 2357
2265 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Adding address %u for peer %u in network `%s'\n", 2358 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2266 op->address_id, op->peer_id, GNUNET_NT_to_string(a->network)); 2359 "Adding address %u for peer %u in network `%s'\n",
2360 op->address_id, op->peer_id, GNUNET_NT_to_string (a->network));
2267 2361
2268 sh->sf->s_add(sh->sf->cls, a->ats_addr, op->address_network); 2362 sh->sf->s_add (sh->sf->cls, a->ats_addr, op->address_network);
2269} 2363}
2270 2364
2271 2365
2272static void 2366static void
2273enforce_del_address(struct GNUNET_ATS_TEST_Operation *op) 2367enforce_del_address (struct GNUNET_ATS_TEST_Operation *op)
2274{ 2368{
2275 struct TestPeer *p; 2369 struct TestPeer *p;
2276 struct TestAddress *a; 2370 struct TestAddress *a;
2277 struct PropertyGenerator *pg; 2371 struct PropertyGenerator *pg;
2278 2372
2279 if (NULL == (p = find_peer_by_id(op->peer_id))) 2373 if (NULL == (p = find_peer_by_id (op->peer_id)))
2280 { 2374 {
2281 GNUNET_break(0); 2375 GNUNET_break (0);
2282 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2283 "Deleting address for unknown peer %u\n", op->peer_id); 2377 "Deleting address for unknown peer %u\n", op->peer_id);
2284 return; 2378 return;
2285 } 2379 }
2286 2380
2287 if (NULL == (a = find_address_by_id(p, op->address_id))) 2381 if (NULL == (a = find_address_by_id (p, op->address_id)))
2288 { 2382 {
2289 GNUNET_break(0); 2383 GNUNET_break (0);
2290 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2384 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2291 "Deleting address for unknown peer %u\n", op->peer_id); 2385 "Deleting address for unknown peer %u\n", op->peer_id);
2292 return; 2386 return;
2293 } 2387 }
2294 2388
2295 while (NULL != (pg = find_prop_gen(p->id, a->aid, 0))) 2389 while (NULL != (pg = find_prop_gen (p->id, a->aid, 0)))
2296 { 2390 {
2297 GNUNET_ATS_solver_generate_property_stop(pg); 2391 GNUNET_ATS_solver_generate_property_stop (pg);
2298 } 2392 }
2299 2393
2300 GNUNET_assert(GNUNET_YES == 2394 GNUNET_assert (GNUNET_YES ==
2301 GNUNET_CONTAINER_multipeermap_remove(sh->addresses, 2395 GNUNET_CONTAINER_multipeermap_remove (sh->addresses,
2302 &p->peer_id, 2396 &p->peer_id,
2303 a->ats_addr)); 2397 a->ats_addr));
2304 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2398 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2305 "Removing address %u for peer %u\n", 2399 "Removing address %u for peer %u\n",
2306 op->address_id, 2400 op->address_id,
2307 op->peer_id); 2401 op->peer_id);
2308 2402
2309 sh->sf->s_del(sh->sf->cls, a->ats_addr); 2403 sh->sf->s_del (sh->sf->cls, a->ats_addr);
2310 2404
2311 if (NULL != l) 2405 if (NULL != l)
2312 { 2406 {
2313 GNUNET_ATS_solver_logging_now(l); 2407 GNUNET_ATS_solver_logging_now (l);
2314 } 2408 }
2315 GNUNET_CONTAINER_DLL_remove(p->addr_head, p->addr_tail, a); 2409 GNUNET_CONTAINER_DLL_remove (p->addr_head, p->addr_tail, a);
2316 2410
2317 GNUNET_free_non_null(a->ats_addr->atsi); 2411 GNUNET_free_non_null (a->ats_addr->atsi);
2318 GNUNET_free(a->ats_addr); 2412 GNUNET_free (a->ats_addr);
2319 GNUNET_free(a); 2413 GNUNET_free (a);
2320} 2414}
2321 2415
2322static void 2416static void
2323enforce_start_property(struct GNUNET_ATS_TEST_Operation *op) 2417enforce_start_property (struct GNUNET_ATS_TEST_Operation *op)
2324{ 2418{
2325 struct PropertyGenerator *pg; 2419 struct PropertyGenerator *pg;
2326 struct TestPeer *p; 2420 struct TestPeer *p;
2327 struct TestAddress *a; 2421 struct TestAddress *a;
2328 2422
2329 if (NULL != (pg = find_prop_gen(op->peer_id, op->address_id, op->prop_type))) 2423 if (NULL != (pg = find_prop_gen (op->peer_id, op->address_id, op->prop_type)))
2330 { 2424 {
2331 GNUNET_ATS_solver_generate_property_stop(pg); 2425 GNUNET_ATS_solver_generate_property_stop (pg);
2332 GNUNET_free(pg); 2426 GNUNET_free (pg);
2333 } 2427 }
2334 2428
2335 if (NULL == (p = find_peer_by_id(op->peer_id))) 2429 if (NULL == (p = find_peer_by_id (op->peer_id)))
2336 { 2430 {
2337 GNUNET_break(0); 2431 GNUNET_break (0);
2338 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2339 "Starting property generation for unknown peer %u\n", op->peer_id); 2433 "Starting property generation for unknown peer %u\n",
2340 return; 2434 op->peer_id);
2341 } 2435 return;
2436 }
2342 2437
2343 if (NULL == (a = find_address_by_id(p, op->address_id))) 2438 if (NULL == (a = find_address_by_id (p, op->address_id)))
2344 { 2439 {
2345 GNUNET_break(0); 2440 GNUNET_break (0);
2346 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2347 "Setting property for unknown address %u\n", op->peer_id); 2442 "Setting property for unknown address %u\n", op->peer_id);
2348 return; 2443 return;
2349 } 2444 }
2350 2445
2351 GNUNET_ATS_solver_generate_property_start(op->peer_id, 2446 GNUNET_ATS_solver_generate_property_start (op->peer_id,
2352 op->address_id, 2447 op->address_id,
2353 p, a, 2448 p, a,
2354 op->gen_type, 2449 op->gen_type,
2355 op->base_rate, 2450 op->base_rate,
2356 op->max_rate, 2451 op->max_rate,
2357 op->period, 2452 op->period,
2358 op->frequency, 2453 op->frequency,
2359 op->prop_type); 2454 op->prop_type);
2360} 2455}
2361 2456
2362static void 2457static void
2363enforce_stop_property(struct GNUNET_ATS_TEST_Operation *op) 2458enforce_stop_property (struct GNUNET_ATS_TEST_Operation *op)
2364{ 2459{
2365 struct PropertyGenerator *pg = find_prop_gen(op->peer_id, op->address_id, 2460 struct PropertyGenerator *pg = find_prop_gen (op->peer_id, op->address_id,
2366 op->prop_type); 2461 op->prop_type);
2367 2462
2368 if (NULL != pg) 2463 if (NULL != pg)
2369 { 2464 {
2370 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2465 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2371 "Stopping preference generation for peer %u address %u\n", op->peer_id, 2466 "Stopping preference generation for peer %u address %u\n",
2372 op->address_id); 2467 op->peer_id,
2373 GNUNET_ATS_solver_generate_property_stop(pg); 2468 op->address_id);
2374 } 2469 GNUNET_ATS_solver_generate_property_stop (pg);
2470 }
2375 else 2471 else
2376 { 2472 {
2377 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2473 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2378 "Cannot find preference generator for peer %u address %u\n", 2474 "Cannot find preference generator for peer %u address %u\n",
2379 op->peer_id, op->address_id); 2475 op->peer_id, op->address_id);
2380 GNUNET_break(0); 2476 GNUNET_break (0);
2381 } 2477 }
2382} 2478}
2383 2479
2384static void 2480static void
2385enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) 2481enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op)
2386{ 2482{
2387 struct PreferenceGenerator *pg; 2483 struct PreferenceGenerator *pg;
2388 2484
2389 if (NULL != (pg = find_pref_gen(op->peer_id, op->pref_type))) 2485 if (NULL != (pg = find_pref_gen (op->peer_id, op->pref_type)))
2390 { 2486 {
2391 GNUNET_ATS_solver_generate_preferences_stop(pg); 2487 GNUNET_ATS_solver_generate_preferences_stop (pg);
2392 GNUNET_free(pg); 2488 GNUNET_free (pg);
2393 } 2489 }
2394 2490
2395 if (NULL == (find_peer_by_id(op->peer_id))) 2491 if (NULL == (find_peer_by_id (op->peer_id)))
2396 { 2492 {
2397 GNUNET_break(0); 2493 GNUNET_break (0);
2398 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2494 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2399 "Starting preference generation for unknown peer %u\n", op->peer_id); 2495 "Starting preference generation for unknown peer %u\n",
2400 return; 2496 op->peer_id);
2401 } 2497 return;
2498 }
2402 2499
2403 GNUNET_ATS_solver_generate_preferences_start(op->peer_id, 2500 GNUNET_ATS_solver_generate_preferences_start (op->peer_id,
2404 op->address_id, 2501 op->address_id,
2405 op->client_id, 2502 op->client_id,
2406 op->gen_type, 2503 op->gen_type,
2407 op->base_rate, 2504 op->base_rate,
2408 op->max_rate, 2505 op->max_rate,
2409 op->period, 2506 op->period,
2410 op->frequency, 2507 op->frequency,
2411 op->pref_type, 2508 op->pref_type,
2412 op->frequency); 2509 op->frequency);
2413} 2510}
2414 2511
2415static void 2512static void
2416enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) 2513enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op)
2417{ 2514{
2418 struct PreferenceGenerator *pg = find_pref_gen(op->peer_id, 2515 struct PreferenceGenerator *pg = find_pref_gen (op->peer_id,
2419 op->pref_type); 2516 op->pref_type);
2420 2517
2421 if (NULL != pg) 2518 if (NULL != pg)
2422 { 2519 {
2423 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2520 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2424 "Stopping property generation for peer %u address %u\n", op->peer_id, 2521 "Stopping property generation for peer %u address %u\n",
2425 op->address_id); 2522 op->peer_id,
2426 GNUNET_ATS_solver_generate_preferences_stop(pg); 2523 op->address_id);
2427 } 2524 GNUNET_ATS_solver_generate_preferences_stop (pg);
2525 }
2428 else 2526 else
2429 { 2527 {
2430 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2528 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2431 "Cannot find preference generator for peer %u address %u\n", 2529 "Cannot find preference generator for peer %u address %u\n",
2432 op->peer_id, op->address_id); 2530 op->peer_id, op->address_id);
2433 GNUNET_break(0); 2531 GNUNET_break (0);
2434 } 2532 }
2435} 2533}
2436 2534
2437 2535
2438static void 2536static void
2439enforce_start_request(struct GNUNET_ATS_TEST_Operation *op) 2537enforce_start_request (struct GNUNET_ATS_TEST_Operation *op)
2440{ 2538{
2441 struct TestPeer *p; 2539 struct TestPeer *p;
2442 2540
2443 if (NULL == (p = find_peer_by_id(op->peer_id))) 2541 if (NULL == (p = find_peer_by_id (op->peer_id)))
2444 { 2542 {
2445 GNUNET_break(0); 2543 GNUNET_break (0);
2446 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2544 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2447 "Requesting address for unknown peer %u\n", op->peer_id); 2545 "Requesting address for unknown peer %u\n", op->peer_id);
2448 return; 2546 return;
2449 } 2547 }
2450 2548
2451 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n", 2549 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting address for peer %u\n",
2452 op->peer_id); 2550 op->peer_id);
2453 p->is_requested = GNUNET_YES; 2551 p->is_requested = GNUNET_YES;
2454 2552
2455 sh->sf->s_get(sh->sf->cls, &p->peer_id); 2553 sh->sf->s_get (sh->sf->cls, &p->peer_id);
2456} 2554}
2457 2555
2458 2556
2459static void 2557static void
2460enforce_stop_request(struct GNUNET_ATS_TEST_Operation *op) 2558enforce_stop_request (struct GNUNET_ATS_TEST_Operation *op)
2461{ 2559{
2462 struct TestPeer *p; 2560 struct TestPeer *p;
2463 2561
2464 if (NULL == (p = find_peer_by_id(op->peer_id))) 2562 if (NULL == (p = find_peer_by_id (op->peer_id)))
2465 { 2563 {
2466 GNUNET_break(0); 2564 GNUNET_break (0);
2467 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2565 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2468 "Requesting address for unknown peer %u\n", op->peer_id); 2566 "Requesting address for unknown peer %u\n", op->peer_id);
2469 return; 2567 return;
2470 } 2568 }
2471 2569
2472 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 2570 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2473 "Stop requesting address for peer %u\n", 2571 "Stop requesting address for peer %u\n",
2474 op->peer_id); 2572 op->peer_id);
2475 p->is_requested = GNUNET_NO; 2573 p->is_requested = GNUNET_NO;
2476 p->assigned_bw_in = 0; 2574 p->assigned_bw_in = 0;
2477 p->assigned_bw_out = 0; 2575 p->assigned_bw_out = 0;
2478 sh->sf->s_get_stop(sh->sf->cls, &p->peer_id); 2576 sh->sf->s_get_stop (sh->sf->cls, &p->peer_id);
2479 2577
2480 if (NULL != l) 2578 if (NULL != l)
2481 { 2579 {
2482 GNUNET_ATS_solver_logging_now(l); 2580 GNUNET_ATS_solver_logging_now (l);
2483 } 2581 }
2484} 2582}
2485 2583
2486static void enforce_episode(struct Episode *ep) 2584static void enforce_episode (struct Episode *ep)
2487{ 2585{
2488 struct GNUNET_ATS_TEST_Operation *cur; 2586 struct GNUNET_ATS_TEST_Operation *cur;
2489 2587
2490 for (cur = ep->head; NULL != cur; cur = cur->next) 2588 for (cur = ep->head; NULL != cur; cur = cur->next)
2589 {
2590 switch (cur->type)
2491 { 2591 {
2492 switch (cur->type) 2592 case SOLVER_OP_ADD_ADDRESS:
2493 { 2593 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2494 case SOLVER_OP_ADD_ADDRESS: 2594 print_op (cur->type), cur->peer_id, cur->address_id);
2495 fprintf(stderr, "Enforcing operation: %s [%llu:%llu]\n", 2595 enforce_add_address (cur);
2496 print_op(cur->type), cur->peer_id, cur->address_id); 2596 break;
2497 enforce_add_address(cur); 2597
2498 break; 2598 case SOLVER_OP_DEL_ADDRESS:
2499 2599 fprintf (stderr, "Enforcing operation: %s [%llu:%llu]\n",
2500 case SOLVER_OP_DEL_ADDRESS: 2600 print_op (cur->type), cur->peer_id, cur->address_id);
2501 fprintf(stderr, "Enforcing operation: %s [%llu:%llu]\n", 2601 enforce_del_address (cur);
2502 print_op(cur->type), cur->peer_id, cur->address_id); 2602 break;
2503 enforce_del_address(cur); 2603
2504 break; 2604 case SOLVER_OP_START_SET_PROPERTY:
2505 2605 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2506 case SOLVER_OP_START_SET_PROPERTY: 2606 print_op (cur->type), cur->peer_id, cur->address_id,
2507 fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", 2607 cur->base_rate);
2508 print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); 2608 enforce_start_property (cur);
2509 enforce_start_property(cur); 2609 break;
2510 break; 2610
2511 2611 case SOLVER_OP_STOP_SET_PROPERTY:
2512 case SOLVER_OP_STOP_SET_PROPERTY: 2612 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2513 fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", 2613 print_op (cur->type), cur->peer_id, cur->address_id,
2514 print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); 2614 cur->base_rate);
2515 enforce_stop_property(cur); 2615 enforce_stop_property (cur);
2516 break; 2616 break;
2517 2617
2518 case SOLVER_OP_START_SET_PREFERENCE: 2618 case SOLVER_OP_START_SET_PREFERENCE:
2519 fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", 2619 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2520 print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); 2620 print_op (cur->type), cur->peer_id, cur->address_id,
2521 enforce_start_preference(cur); 2621 cur->base_rate);
2522 break; 2622 enforce_start_preference (cur);
2523 2623 break;
2524 case SOLVER_OP_STOP_SET_PREFERENCE: 2624
2525 fprintf(stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n", 2625 case SOLVER_OP_STOP_SET_PREFERENCE:
2526 print_op(cur->type), cur->peer_id, cur->address_id, cur->base_rate); 2626 fprintf (stderr, "Enforcing operation: %s [%llu:%llu] == %llu\n",
2527 enforce_stop_preference(cur); 2627 print_op (cur->type), cur->peer_id, cur->address_id,
2528 break; 2628 cur->base_rate);
2529 2629 enforce_stop_preference (cur);
2530 case SOLVER_OP_START_REQUEST: 2630 break;
2531 fprintf(stderr, "Enforcing operation: %s [%llu]\n", 2631
2532 print_op(cur->type), cur->peer_id); 2632 case SOLVER_OP_START_REQUEST:
2533 enforce_start_request(cur); 2633 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2534 break; 2634 print_op (cur->type), cur->peer_id);
2535 2635 enforce_start_request (cur);
2536 case SOLVER_OP_STOP_REQUEST: 2636 break;
2537 fprintf(stderr, "Enforcing operation: %s [%llu]\n", 2637
2538 print_op(cur->type), cur->peer_id); 2638 case SOLVER_OP_STOP_REQUEST:
2539 enforce_stop_request(cur); 2639 fprintf (stderr, "Enforcing operation: %s [%llu]\n",
2540 break; 2640 print_op (cur->type), cur->peer_id);
2541 2641 enforce_stop_request (cur);
2542 default: 2642 break;
2543 break; 2643
2544 } 2644 default:
2645 break;
2545 } 2646 }
2647 }
2546} 2648}
2547 2649
2548 2650
2549static void 2651static void
2550timeout_episode(void *cls) 2652timeout_episode (void *cls)
2551{ 2653{
2552 struct Experiment *e = cls; 2654 struct Experiment *e = cls;
2553 2655
2554 e->episode_timeout_task = NULL; 2656 e->episode_timeout_task = NULL;
2555 if (NULL != e->ep_done_cb) 2657 if (NULL != e->ep_done_cb)
2556 e->ep_done_cb(e->cur); 2658 e->ep_done_cb (e->cur);
2557 2659
2558 /* Scheduling next */ 2660 /* Scheduling next */
2559 e->cur = e->cur->next; 2661 e->cur = e->cur->next;
2560 if (NULL == e->cur) 2662 if (NULL == e->cur)
2663 {
2664 /* done */
2665 fprintf (stderr, "Last episode done!\n");
2666 if (NULL != e->experiment_timeout_task)
2561 { 2667 {
2562 /* done */ 2668 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2563 fprintf(stderr, "Last episode done!\n"); 2669 e->experiment_timeout_task = NULL;
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;
2571 } 2670 }
2671 e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time),
2672 GNUNET_OK);
2673 return;
2674 }
2572 2675
2573 fprintf(stderr, "Running episode %u with timeout %s\n", 2676 fprintf (stderr, "Running episode %u with timeout %s\n",
2574 e->cur->id, 2677 e->cur->id,
2575 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 2678 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
2576 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 2679 GNUNET_YES));
2577 &timeout_episode, e); 2680 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2578 enforce_episode(e->cur); 2681 &timeout_episode, e);
2682 enforce_episode (e->cur);
2579} 2683}
2580 2684
2581 2685
2582void 2686void
2583GNUNET_ATS_solvers_experimentation_run(struct Experiment *e, 2687GNUNET_ATS_solvers_experimentation_run (struct Experiment *e,
2584 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, 2688 GNUNET_ATS_TESTING_EpisodeDoneCallback
2585 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) 2689 ep_done_cb,
2586{ 2690 GNUNET_ATS_TESTING_ExperimentDoneCallback
2587 fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, 2691 e_done_cb)
2588 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 2692{
2693 fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name,
2694 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
2695 GNUNET_YES));
2589 e->e_done_cb = e_done_cb; 2696 e->e_done_cb = e_done_cb;
2590 e->ep_done_cb = ep_done_cb; 2697 e->ep_done_cb = ep_done_cb;
2591 e->start_time = GNUNET_TIME_absolute_get(); 2698 e->start_time = GNUNET_TIME_absolute_get ();
2592 2699
2593 /* Start total time out */ 2700 /* Start total time out */
2594 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, 2701 e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration,
2595 &timeout_experiment, e); 2702 &timeout_experiment,
2703 e);
2596 2704
2597 /* Start */ 2705 /* Start */
2598 if (NULL == e->start) 2706 if (NULL == e->start)
2599 { 2707 {
2600 GNUNET_break(0); 2708 GNUNET_break (0);
2601 return; 2709 return;
2602 } 2710 }
2603 2711
2604 e->cur = e->start; 2712 e->cur = e->start;
2605 fprintf(stderr, "Running episode %u with timeout %s\n", 2713 fprintf (stderr, "Running episode %u with timeout %s\n",
2606 e->cur->id, 2714 e->cur->id,
2607 GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); 2715 GNUNET_STRINGS_relative_time_to_string (e->cur->duration,
2608 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, 2716 GNUNET_YES));
2609 &timeout_episode, e); 2717 e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration,
2610 enforce_episode(e->cur); 2718 &timeout_episode, e);
2719 enforce_episode (e->cur);
2611} 2720}
2612 2721
2613void 2722void
2614GNUNET_ATS_solvers_experimentation_stop(struct Experiment *e) 2723GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e)
2615{ 2724{
2616 if (NULL != e->experiment_timeout_task) 2725 if (NULL != e->experiment_timeout_task)
2617 { 2726 {
2618 GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); 2727 GNUNET_SCHEDULER_cancel (e->experiment_timeout_task);
2619 e->experiment_timeout_task = NULL; 2728 e->experiment_timeout_task = NULL;
2620 } 2729 }
2621 if (NULL != e->episode_timeout_task) 2730 if (NULL != e->episode_timeout_task)
2622 { 2731 {
2623 GNUNET_SCHEDULER_cancel(e->episode_timeout_task); 2732 GNUNET_SCHEDULER_cancel (e->episode_timeout_task);
2624 e->episode_timeout_task = NULL; 2733 e->episode_timeout_task = NULL;
2625 } 2734 }
2626 if (NULL != e->cfg) 2735 if (NULL != e->cfg)
2627 { 2736 {
2628 GNUNET_CONFIGURATION_destroy(e->cfg); 2737 GNUNET_CONFIGURATION_destroy (e->cfg);
2629 e->cfg = NULL; 2738 e->cfg = NULL;
2630 } 2739 }
2631 free_experiment(e); 2740 free_experiment (e);
2632} 2741}
2633 2742
2634 2743
2635struct Experiment * 2744struct Experiment *
2636GNUNET_ATS_solvers_experimentation_load(char *filename) 2745GNUNET_ATS_solvers_experimentation_load (char *filename)
2637{ 2746{
2638 struct Experiment *e; 2747 struct Experiment *e;
2639 struct GNUNET_CONFIGURATION_Handle *cfg; 2748 struct GNUNET_CONFIGURATION_Handle *cfg;
2640 2749
2641 e = NULL; 2750 e = NULL;
2642 2751
2643 cfg = GNUNET_CONFIGURATION_create(); 2752 cfg = GNUNET_CONFIGURATION_create ();
2644 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) 2753 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename))
2645 { 2754 {
2646 fprintf(stderr, "Failed to load `%s'\n", filename); 2755 fprintf (stderr, "Failed to load `%s'\n", filename);
2647 GNUNET_CONFIGURATION_destroy(cfg); 2756 GNUNET_CONFIGURATION_destroy (cfg);
2648 return NULL; 2757 return NULL;
2649 } 2758 }
2650 2759
2651 e = create_experiment(); 2760 e = create_experiment ();
2652 2761
2653 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", 2762 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
2654 "name", &e->name)) 2763 "name", &e->name))
2655 { 2764 {
2656 fprintf(stderr, "Invalid %s \n", "name"); 2765 fprintf (stderr, "Invalid %s \n", "name");
2657 free_experiment(e); 2766 free_experiment (e);
2658 return NULL; 2767 return NULL;
2659 } 2768 }
2660 else 2769 else
2661 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name); 2770 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment name: `%s'\n", e->name);
2662 2771
2663 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", 2772 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment",
2664 "log_prefix", &e->log_prefix)) 2773 "log_prefix",
2665 { 2774 &e->log_prefix))
2666 fprintf(stderr, "Invalid %s \n", "log_prefix"); 2775 {
2667 free_experiment(e); 2776 fprintf (stderr, "Invalid %s \n", "log_prefix");
2668 return NULL; 2777 free_experiment (e);
2669 } 2778 return NULL;
2779 }
2670 else 2780 else
2671 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n", 2781 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging prefix: `%s'\n",
2672 e->log_prefix); 2782 e->log_prefix);
2673 2783
2674 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", 2784 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
2675 "log_output_dir", &e->log_output_dir)) 2785 "experiment",
2676 { 2786 "log_output_dir",
2677 e->log_output_dir = NULL; 2787 &e->
2678 } 2788 log_output_dir))
2789 {
2790 e->log_output_dir = NULL;
2791 }
2679 else 2792 else
2680 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging output directory: `%s'\n", 2793 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2681 e->log_output_dir); 2794 "Experiment logging output directory: `%s'\n",
2795 e->log_output_dir);
2682 2796
2683 2797
2684 if (GNUNET_SYSERR == (e->log_append_time_stamp = GNUNET_CONFIGURATION_get_value_yesno(cfg, 2798 if (GNUNET_SYSERR == (e->log_append_time_stamp =
2685 "experiment", "log_append_time_stamp"))) 2799 GNUNET_CONFIGURATION_get_value_yesno (cfg,
2800 "experiment",
2801 "log_append_time_stamp")))
2686 e->log_append_time_stamp = GNUNET_YES; 2802 e->log_append_time_stamp = GNUNET_YES;
2687 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging append timestamp: `%s'\n", 2803 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2688 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no"); 2804 "Experiment logging append timestamp: `%s'\n",
2805 (GNUNET_YES == e->log_append_time_stamp) ? "yes" : "no");
2689 2806
2690 2807
2691 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", 2808 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg,
2692 "cfg_file", &e->cfg_file)) 2809 "experiment",
2693 { 2810 "cfg_file",
2694 fprintf(stderr, "Invalid %s \n", "cfg_file"); 2811 &e->cfg_file))
2695 free_experiment(e); 2812 {
2696 return NULL; 2813 fprintf (stderr, "Invalid %s \n", "cfg_file");
2697 } 2814 free_experiment (e);
2815 return NULL;
2816 }
2698 else 2817 else
2818 {
2819 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n",
2820 e->cfg_file);
2821 e->cfg = GNUNET_CONFIGURATION_create ();
2822 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (e->cfg, e->cfg_file))
2699 { 2823 {
2700 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment configuration: `%s'\n", e->cfg_file); 2824 fprintf (stderr, "Invalid configuration %s \n", "cfg_file");
2701 e->cfg = GNUNET_CONFIGURATION_create(); 2825 free_experiment (e);
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 }
2709
2710 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment",
2711 "log_freq", &e->log_freq))
2712 {
2713 fprintf(stderr, "Invalid %s \n", "log_freq");
2714 free_experiment(e);
2715 return NULL; 2826 return NULL;
2716 } 2827 }
2717 else 2828 }
2718 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2719 GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES));
2720 2829
2721 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", 2830 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
2722 "max_duration", &e->max_duration)) 2831 "log_freq",
2723 { 2832 &e->log_freq))
2724 fprintf(stderr, "Invalid %s", "max_duration"); 2833 {
2725 free_experiment(e); 2834 fprintf (stderr, "Invalid %s \n", "log_freq");
2726 return NULL; 2835 free_experiment (e);
2727 } 2836 return NULL;
2837 }
2728 else 2838 else
2729 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n", 2839 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment logging frequency: `%s'\n",
2730 GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); 2840 GNUNET_STRINGS_relative_time_to_string (e->log_freq,
2841 GNUNET_YES));
2731 2842
2732 if (GNUNET_SYSERR == load_episodes(e, cfg)) 2843 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment",
2733 { 2844 "max_duration",
2734 GNUNET_ATS_solvers_experimentation_stop(e); 2845 &e->max_duration))
2735 GNUNET_CONFIGURATION_destroy(cfg); 2846 {
2736 e = NULL; 2847 fprintf (stderr, "Invalid %s", "max_duration");
2737 fprintf(stderr, "Failed to load experiment\n"); 2848 free_experiment (e);
2738 return NULL; 2849 return NULL;
2739 } 2850 }
2740 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loaded %u episodes with total duration %s\n", 2851 else
2741 e->num_episodes, 2852 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment duration: `%s'\n",
2742 GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); 2853 GNUNET_STRINGS_relative_time_to_string (e->max_duration,
2854 GNUNET_YES));
2743 2855
2744 GNUNET_CONFIGURATION_destroy(cfg); 2856 if (GNUNET_SYSERR == load_episodes (e, cfg))
2857 {
2858 GNUNET_ATS_solvers_experimentation_stop (e);
2859 GNUNET_CONFIGURATION_destroy (cfg);
2860 e = NULL;
2861 fprintf (stderr, "Failed to load experiment\n");
2862 return NULL;
2863 }
2864 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2865 "Loaded %u episodes with total duration %s\n",
2866 e->num_episodes,
2867 GNUNET_STRINGS_relative_time_to_string (e->total_duration,
2868 GNUNET_YES));
2869
2870 GNUNET_CONFIGURATION_destroy (cfg);
2745 return e; 2871 return e;
2746} 2872}
2747 2873
@@ -2752,34 +2878,35 @@ GNUNET_ATS_solvers_experimentation_load(char *filename)
2752 */ 2878 */
2753 2879
2754static int 2880static int
2755free_all_it(void *cls, 2881free_all_it (void *cls,
2756 const struct GNUNET_PeerIdentity *key, 2882 const struct GNUNET_PeerIdentity *key,
2757 void *value) 2883 void *value)
2758{ 2884{
2759 struct ATS_Address *address = value; 2885 struct ATS_Address *address = value;
2760 2886
2761 GNUNET_break(GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove(sh->env.addresses, 2887 GNUNET_break (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (
2762 key, value)); 2888 sh->env.addresses,
2763 GNUNET_free(address); 2889 key, value));
2890 GNUNET_free (address);
2764 2891
2765 return GNUNET_OK; 2892 return GNUNET_OK;
2766} 2893}
2767 2894
2768void 2895void
2769GNUNET_ATS_solvers_solver_stop(struct SolverHandle *sh) 2896GNUNET_ATS_solvers_solver_stop (struct SolverHandle *sh)
2770{ 2897{
2771 GNUNET_STATISTICS_destroy((struct GNUNET_STATISTICS_Handle *)sh->env.stats, 2898 GNUNET_STATISTICS_destroy ((struct GNUNET_STATISTICS_Handle *) sh->env.stats,
2772 GNUNET_NO); 2899 GNUNET_NO);
2773 GNUNET_PLUGIN_unload(sh->plugin, sh->sf); 2900 GNUNET_PLUGIN_unload (sh->plugin, sh->sf);
2774 sh->sf = NULL; 2901 sh->sf = NULL;
2775 GAS_normalization_stop(); 2902 GAS_normalization_stop ();
2776 2903
2777 GNUNET_CONTAINER_multipeermap_iterate(sh->addresses, 2904 GNUNET_CONTAINER_multipeermap_iterate (sh->addresses,
2778 &free_all_it, 2905 &free_all_it,
2779 NULL); 2906 NULL);
2780 GNUNET_CONTAINER_multipeermap_destroy(sh->addresses); 2907 GNUNET_CONTAINER_multipeermap_destroy (sh->addresses);
2781 GNUNET_free(sh->plugin); 2908 GNUNET_free (sh->plugin);
2782 GNUNET_free(sh); 2909 GNUNET_free (sh);
2783} 2910}
2784 2911
2785 2912
@@ -2793,118 +2920,141 @@ GNUNET_ATS_solvers_solver_stop(struct SolverHandle *sh)
2793 * @return number of networks loaded 2920 * @return number of networks loaded
2794 */ 2921 */
2795unsigned int 2922unsigned int
2796GNUNET_ATS_solvers_load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg, 2923GNUNET_ATS_solvers_load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
2797 unsigned long long *out_dest, 2924 unsigned long long *out_dest,
2798 unsigned long long *in_dest, 2925 unsigned long long *in_dest,
2799 int dest_length) 2926 int dest_length)
2800{ 2927{
2801 char * entry_in = NULL; 2928 char *entry_in = NULL;
2802 char * entry_out = NULL; 2929 char *entry_out = NULL;
2803 char * quota_out_str; 2930 char *quota_out_str;
2804 char * quota_in_str; 2931 char *quota_in_str;
2805 int c; 2932 int c;
2806 int res; 2933 int res;
2807 2934
2808 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) 2935 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++)
2809 { 2936 {
2810 in_dest[c] = 0; 2937 in_dest[c] = 0;
2811 out_dest[c] = 0; 2938 out_dest[c] = 0;
2812 GNUNET_asprintf(&entry_out, 2939 GNUNET_asprintf (&entry_out,
2813 "%s_QUOTA_OUT", 2940 "%s_QUOTA_OUT",
2814 GNUNET_NT_to_string(c)); 2941 GNUNET_NT_to_string (c));
2815 GNUNET_asprintf(&entry_in, 2942 GNUNET_asprintf (&entry_in,
2816 "%s_QUOTA_IN", 2943 "%s_QUOTA_IN",
2817 GNUNET_NT_to_string(c)); 2944 GNUNET_NT_to_string (c));
2818 2945
2819 /* quota out */ 2946 /* quota out */
2820 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, &quota_out_str)) 2947 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ats",
2821 { 2948 entry_out,
2822 res = GNUNET_NO; 2949 &quota_out_str))
2823 if (0 == strcmp(quota_out_str, BIG_M_STRING)) 2950 {
2824 { 2951 res = GNUNET_NO;
2825 out_dest[c] = GNUNET_ATS_MaxBandwidth; 2952 if (0 == strcmp (quota_out_str, BIG_M_STRING))
2826 res = GNUNET_YES; 2953 {
2827 } 2954 out_dest[c] = GNUNET_ATS_MaxBandwidth;
2828 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes(quota_out_str, &out_dest[c]))) 2955 res = GNUNET_YES;
2829 res = GNUNET_YES; 2956 }
2830 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "ats", entry_out, &out_dest[c]))) 2957 if ((GNUNET_NO == res) && (GNUNET_OK ==
2831 res = GNUNET_YES; 2958 GNUNET_STRINGS_fancy_size_to_bytes (
2832 2959 quota_out_str, &out_dest[c])))
2833 if (GNUNET_NO == res) 2960 res = GNUNET_YES;
2834 { 2961 if ((GNUNET_NO == res) && (GNUNET_OK ==
2835 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 2962 GNUNET_CONFIGURATION_get_value_number (cfg,
2836 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), 2963 "ats",
2837 GNUNET_NT_to_string(c), 2964 entry_out,
2838 quota_out_str, 2965 &
2839 GNUNET_ATS_DefaultBandwidth); 2966 out_dest
2840 out_dest[c] = GNUNET_ATS_DefaultBandwidth; 2967 [c])))
2841 } 2968 res = GNUNET_YES;
2842 else 2969
2843 { 2970 if (GNUNET_NO == res)
2844 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2971 {
2845 "Outbound quota configure for network `%s' is %llu\n", 2972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2846 GNUNET_NT_to_string(c), 2973 _ (
2847 out_dest[c]); 2974 "Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2848 } 2975 GNUNET_NT_to_string (c),
2849 GNUNET_free(quota_out_str); 2976 quota_out_str,
2850 } 2977 GNUNET_ATS_DefaultBandwidth);
2978 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2979 }
2851 else 2980 else
2852 { 2981 {
2853 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 2982 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2854 _("No outbound quota configured for network `%s', assigning default bandwidth %llu\n"), 2983 "Outbound quota configure for network `%s' is %llu\n",
2855 GNUNET_NT_to_string(c), 2984 GNUNET_NT_to_string (c),
2856 GNUNET_ATS_DefaultBandwidth); 2985 out_dest[c]);
2857 out_dest[c] = GNUNET_ATS_DefaultBandwidth; 2986 }
2858 } 2987 GNUNET_free (quota_out_str);
2988 }
2989 else
2990 {
2991 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2992 _ (
2993 "No outbound quota configured for network `%s', assigning default bandwidth %llu\n"),
2994 GNUNET_NT_to_string (c),
2995 GNUNET_ATS_DefaultBandwidth);
2996 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
2997 }
2859 2998
2860 /* quota in */ 2999 /* quota in */
2861 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, &quota_in_str)) 3000 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, "ats",
2862 { 3001 entry_in,
2863 res = GNUNET_NO; 3002 &quota_in_str))
2864 if (0 == strcmp(quota_in_str, BIG_M_STRING)) 3003 {
2865 { 3004 res = GNUNET_NO;
2866 in_dest[c] = GNUNET_ATS_MaxBandwidth; 3005 if (0 == strcmp (quota_in_str, BIG_M_STRING))
2867 res = GNUNET_YES; 3006 {
2868 } 3007 in_dest[c] = GNUNET_ATS_MaxBandwidth;
2869 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_STRINGS_fancy_size_to_bytes(quota_in_str, &in_dest[c]))) 3008 res = GNUNET_YES;
2870 res = GNUNET_YES; 3009 }
2871 if ((GNUNET_NO == res) && (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "ats", entry_in, &in_dest[c]))) 3010 if ((GNUNET_NO == res) && (GNUNET_OK ==
2872 res = GNUNET_YES; 3011 GNUNET_STRINGS_fancy_size_to_bytes (
2873 3012 quota_in_str, &in_dest[c])))
2874 if (GNUNET_NO == res) 3013 res = GNUNET_YES;
2875 { 3014 if ((GNUNET_NO == res) && (GNUNET_OK ==
2876 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 3015 GNUNET_CONFIGURATION_get_value_number (cfg,
2877 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), 3016 "ats",
2878 GNUNET_NT_to_string(c), 3017 entry_in,
2879 quota_in_str, 3018 &in_dest
2880 GNUNET_ATS_DefaultBandwidth); 3019 [c])))
2881 in_dest[c] = GNUNET_ATS_DefaultBandwidth; 3020 res = GNUNET_YES;
2882 } 3021
2883 else 3022 if (GNUNET_NO == res)
2884 { 3023 {
2885 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3024 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2886 "Inbound quota configured for network `%s' is %llu\n", 3025 _ (
2887 GNUNET_NT_to_string(c), 3026 "Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
2888 in_dest[c]); 3027 GNUNET_NT_to_string (c),
2889 } 3028 quota_in_str,
2890 GNUNET_free(quota_in_str); 3029 GNUNET_ATS_DefaultBandwidth);
2891 } 3030 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
3031 }
2892 else 3032 else
2893 { 3033 {
2894 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 3034 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2895 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), 3035 "Inbound quota configured for network `%s' is %llu\n",
2896 GNUNET_NT_to_string(c), 3036 GNUNET_NT_to_string (c),
2897 GNUNET_ATS_DefaultBandwidth); 3037 in_dest[c]);
2898 out_dest[c] = GNUNET_ATS_DefaultBandwidth; 3038 }
2899 } 3039 GNUNET_free (quota_in_str);
2900 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3040 }
2901 "Loaded quota for network `%s' (in/out): %llu %llu\n", 3041 else
2902 GNUNET_NT_to_string(c), 3042 {
2903 in_dest[c], 3043 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2904 out_dest[c]); 3044 _ (
2905 GNUNET_free(entry_out); 3045 "No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
2906 GNUNET_free(entry_in); 3046 GNUNET_NT_to_string (c),
2907 } 3047 GNUNET_ATS_DefaultBandwidth);
3048 out_dest[c] = GNUNET_ATS_DefaultBandwidth;
3049 }
3050 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3051 "Loaded quota for network `%s' (in/out): %llu %llu\n",
3052 GNUNET_NT_to_string (c),
3053 in_dest[c],
3054 out_dest[c]);
3055 GNUNET_free (entry_out);
3056 GNUNET_free (entry_in);
3057 }
2908 return GNUNET_NT_COUNT; 3058 return GNUNET_NT_COUNT;
2909} 3059}
2910 3060
@@ -2918,109 +3068,118 @@ GNUNET_ATS_solvers_load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg,
2918 * @param add additional solver information 3068 * @param add additional solver information
2919 */ 3069 */
2920static void 3070static void
2921solver_info_cb(void *cls, 3071solver_info_cb (void *cls,
2922 enum GAS_Solver_Operation op, 3072 enum GAS_Solver_Operation op,
2923 enum GAS_Solver_Status stat, 3073 enum GAS_Solver_Status stat,
2924 enum GAS_Solver_Additional_Information add) 3074 enum GAS_Solver_Additional_Information add)
2925{ 3075{
2926 char *add_info; 3076 char *add_info;
2927 3077
2928 switch (add) 3078 switch (add)
2929 { 3079 {
2930 case GAS_INFO_NONE: 3080 case GAS_INFO_NONE:
2931 add_info = "GAS_INFO_NONE"; 3081 add_info = "GAS_INFO_NONE";
2932 break; 3082 break;
2933 3083
2934 case GAS_INFO_FULL: 3084 case GAS_INFO_FULL:
2935 add_info = "GAS_INFO_MLP_FULL"; 3085 add_info = "GAS_INFO_MLP_FULL";
2936 break; 3086 break;
2937 3087
2938 case GAS_INFO_UPDATED: 3088 case GAS_INFO_UPDATED:
2939 add_info = "GAS_INFO_MLP_UPDATED"; 3089 add_info = "GAS_INFO_MLP_UPDATED";
2940 break; 3090 break;
2941 3091
2942 case GAS_INFO_PROP_ALL: 3092 case GAS_INFO_PROP_ALL:
2943 add_info = "GAS_INFO_PROP_ALL"; 3093 add_info = "GAS_INFO_PROP_ALL";
2944 break; 3094 break;
2945 3095
2946 case GAS_INFO_PROP_SINGLE: 3096 case GAS_INFO_PROP_SINGLE:
2947 add_info = "GAS_INFO_PROP_SINGLE"; 3097 add_info = "GAS_INFO_PROP_SINGLE";
2948 break; 3098 break;
2949 3099
2950 default: 3100 default:
2951 add_info = "INVALID"; 3101 add_info = "INVALID";
2952 break; 3102 break;
2953 } 3103 }
2954 3104
2955 switch (op) 3105 switch (op)
2956 { 3106 {
2957 case GAS_OP_SOLVE_START: 3107 case GAS_OP_SOLVE_START:
2958 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2959 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START", 3109 "Solver notifies `%s' with result `%s' `%s'\n",
2960 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); 3110 "GAS_OP_SOLVE_START",
2961 return; 3111 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
3112 return;
2962 3113
2963 case GAS_OP_SOLVE_STOP: 3114 case GAS_OP_SOLVE_STOP:
2964 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2965 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP", 3116 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_STOP",
2966 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); 3117 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
2967 return; 3118 return;
2968 3119
2969 case GAS_OP_SOLVE_SETUP_START: 3120 case GAS_OP_SOLVE_SETUP_START:
2970 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2971 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", 3122 "Solver notifies `%s' with result `%s'\n",
2972 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3123 "GAS_OP_SOLVE_SETUP_START",
2973 return; 3124 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3125 return;
2974 3126
2975 case GAS_OP_SOLVE_SETUP_STOP: 3127 case GAS_OP_SOLVE_SETUP_STOP:
2976 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2977 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", 3129 "Solver notifies `%s' with result `%s'\n",
2978 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3130 "GAS_OP_SOLVE_SETUP_STOP",
2979 return; 3131 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3132 return;
2980 3133
2981 case GAS_OP_SOLVE_MLP_LP_START: 3134 case GAS_OP_SOLVE_MLP_LP_START:
2982 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2983 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", 3136 "Solver notifies `%s' with result `%s'\n",
2984 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3137 "GAS_OP_SOLVE_LP_START",
2985 return; 3138 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3139 return;
2986 3140
2987 case GAS_OP_SOLVE_MLP_LP_STOP: 3141 case GAS_OP_SOLVE_MLP_LP_STOP:
2988 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2989 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", 3143 "Solver notifies `%s' with result `%s'\n",
2990 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3144 "GAS_OP_SOLVE_LP_STOP",
2991 return; 3145 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3146 return;
2992 3147
2993 case GAS_OP_SOLVE_MLP_MLP_START: 3148 case GAS_OP_SOLVE_MLP_MLP_START:
2994 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2995 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", 3150 "Solver notifies `%s' with result `%s'\n",
2996 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3151 "GAS_OP_SOLVE_MLP_START",
2997 return; 3152 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3153 return;
2998 3154
2999 case GAS_OP_SOLVE_MLP_MLP_STOP: 3155 case GAS_OP_SOLVE_MLP_MLP_STOP:
3000 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3001 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", 3157 "Solver notifies `%s' with result `%s'\n",
3002 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3158 "GAS_OP_SOLVE_MLP_STOP",
3003 return; 3159 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3160 return;
3004 3161
3005 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: 3162 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
3006 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3007 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", 3164 "Solver notifies `%s' with result `%s'\n",
3008 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3165 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
3009 return; 3166 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3167 return;
3010 3168
3011 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: 3169 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
3012 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3013 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", 3171 "Solver notifies `%s' with result `%s'\n",
3014 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 3172 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
3015 return; 3173 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
3174 return;
3016 3175
3017 default: 3176 default:
3018 break; 3177 break;
3019 } 3178 }
3020} 3179}
3021 3180
3022static void 3181static void
3023solver_bandwidth_changed_cb(void *cls, struct ATS_Address *address) 3182solver_bandwidth_changed_cb (void *cls, struct ATS_Address *address)
3024{ 3183{
3025 struct GNUNET_TIME_Relative duration; 3184 struct GNUNET_TIME_Relative duration;
3026 struct TestPeer *p; 3185 struct TestPeer *p;
@@ -3028,99 +3187,100 @@ solver_bandwidth_changed_cb(void *cls, struct ATS_Address *address)
3028 uint32_t delta; 3187 uint32_t delta;
3029 3188
3030 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in)) 3189 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in))
3031 { 3190 {
3032 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3191 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3033 "Solver notified to disconnect peer `%s'\n", 3192 "Solver notified to disconnect peer `%s'\n",
3034 GNUNET_i2s(&address->peer)); 3193 GNUNET_i2s (&address->peer));
3035 } 3194 }
3036 p = find_peer_by_pid(&address->peer); 3195 p = find_peer_by_pid (&address->peer);
3037 if (NULL == p) 3196 if (NULL == p)
3038 return; 3197 return;
3039 p->assigned_bw_out = address->assigned_bw_out; 3198 p->assigned_bw_out = address->assigned_bw_out;
3040 p->assigned_bw_in = address->assigned_bw_in; 3199 p->assigned_bw_in = address->assigned_bw_in;
3041 3200
3042 for (pg = pref_gen_head; NULL != pg; pg = pg->next) 3201 for (pg = pref_gen_head; NULL != pg; pg = pg->next)
3202 {
3203 if (pg->peer == p->id)
3043 { 3204 {
3044 if (pg->peer == p->id) 3205 duration = GNUNET_TIME_absolute_get_duration (
3045 { 3206 pg->feedback_last_bw_update);
3046 duration = GNUNET_TIME_absolute_get_duration(pg->feedback_last_bw_update); 3207 delta = duration.rel_value_us * pg->last_assigned_bw_out;
3047 delta = duration.rel_value_us * pg->last_assigned_bw_out; 3208 pg->feedback_bw_out_acc += delta;
3048 pg->feedback_bw_out_acc += delta;
3049 3209
3050 delta = duration.rel_value_us * pg->last_assigned_bw_in; 3210 delta = duration.rel_value_us * pg->last_assigned_bw_in;
3051 pg->feedback_bw_in_acc += delta; 3211 pg->feedback_bw_in_acc += delta;
3052 3212
3053 pg->last_assigned_bw_in = address->assigned_bw_in; 3213 pg->last_assigned_bw_in = address->assigned_bw_in;
3054 pg->last_assigned_bw_out = address->assigned_bw_out; 3214 pg->last_assigned_bw_out = address->assigned_bw_out;
3055 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); 3215 pg->feedback_last_bw_update = GNUNET_TIME_absolute_get ();
3056 }
3057 } 3216 }
3217 }
3058 3218
3059 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 3219 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3060 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", 3220 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
3061 GNUNET_i2s(&address->peer), 3221 GNUNET_i2s (&address->peer),
3062 address, 3222 address,
3063 address->assigned_bw_out, 3223 address->assigned_bw_out,
3064 address->assigned_bw_in); 3224 address->assigned_bw_in);
3065 3225
3066 if (NULL != l) 3226 if (NULL != l)
3067 GNUNET_ATS_solver_logging_now(l); 3227 GNUNET_ATS_solver_logging_now (l);
3068 3228
3069 return; 3229 return;
3070} 3230}
3071 3231
3072const double * 3232const double *
3073get_preferences_cb(void *cls, const struct GNUNET_PeerIdentity *id) 3233get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
3074{ 3234{
3075 struct TestPeer *p; 3235 struct TestPeer *p;
3076 3236
3077 if (GNUNET_YES == opt_disable_normalization) 3237 if (GNUNET_YES == opt_disable_normalization)
3078 { 3238 {
3079 if (NULL == (p = find_peer_by_pid(id))) 3239 if (NULL == (p = find_peer_by_pid (id)))
3080 return NULL; 3240 return NULL;
3081 return p->pref_abs; 3241 return p->pref_abs;
3082 } 3242 }
3083 else 3243 else
3084 return GAS_preference_get_by_peer(NULL, 3244 return GAS_preference_get_by_peer (NULL,
3085 id); 3245 id);
3086} 3246}
3087 3247
3088 3248
3089struct SolverHandle * 3249struct SolverHandle *
3090GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type) 3250GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type)
3091{ 3251{
3092 struct SolverHandle *sh; 3252 struct SolverHandle *sh;
3093 char * solver_str; 3253 char *solver_str;
3094 3254
3095 switch (type) 3255 switch (type)
3096 { 3256 {
3097 case GNUNET_ATS_SOLVER_PROPORTIONAL: 3257 case GNUNET_ATS_SOLVER_PROPORTIONAL:
3098 solver_str = "proportional"; 3258 solver_str = "proportional";
3099 break; 3259 break;
3100 3260
3101 case GNUNET_ATS_SOLVER_MLP: 3261 case GNUNET_ATS_SOLVER_MLP:
3102 solver_str = "mlp"; 3262 solver_str = "mlp";
3103 break; 3263 break;
3104 3264
3105 case GNUNET_ATS_SOLVER_RIL: 3265 case GNUNET_ATS_SOLVER_RIL:
3106 solver_str = "ril"; 3266 solver_str = "ril";
3107 break; 3267 break;
3108 3268
3109 default: 3269 default:
3110 GNUNET_break(0); 3270 GNUNET_break (0);
3111 return NULL; 3271 return NULL;
3112 break; 3272 break;
3113 } 3273 }
3114 3274
3115 sh = GNUNET_new(struct SolverHandle); 3275 sh = GNUNET_new (struct SolverHandle);
3116 GNUNET_asprintf(&sh->plugin, 3276 GNUNET_asprintf (&sh->plugin,
3117 "libgnunet_plugin_ats_%s", 3277 "libgnunet_plugin_ats_%s",
3118 solver_str); 3278 solver_str);
3119 sh->addresses = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO); 3279 sh->addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
3120 3280
3121 /* setup environment */ 3281 /* setup environment */
3122 sh->env.cfg = e->cfg; 3282 sh->env.cfg = e->cfg;
3123 sh->env.stats = GNUNET_STATISTICS_create("ats", e->cfg); 3283 sh->env.stats = GNUNET_STATISTICS_create ("ats", e->cfg);
3124 sh->env.addresses = sh->addresses; 3284 sh->env.addresses = sh->addresses;
3125 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; 3285 sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb;
3126 sh->env.get_preferences = &get_preferences_cb; 3286 sh->env.get_preferences = &get_preferences_cb;
@@ -3129,35 +3289,37 @@ GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type)
3129 sh->env.network_count = GNUNET_NT_COUNT; 3289 sh->env.network_count = GNUNET_NT_COUNT;
3130 3290
3131 /* start normalization */ 3291 /* start normalization */
3132 GAS_normalization_start(); 3292 GAS_normalization_start ();
3133 3293
3134 /* load quotas */ 3294 /* load quotas */
3135 if (GNUNET_NT_COUNT != GNUNET_ATS_solvers_load_quotas(e->cfg, 3295 if (GNUNET_NT_COUNT != GNUNET_ATS_solvers_load_quotas (e->cfg,
3136 sh->env.out_quota, sh->env.in_quota, GNUNET_NT_COUNT)) 3296 sh->env.out_quota,
3137 { 3297 sh->env.in_quota,
3138 GNUNET_break(0); 3298 GNUNET_NT_COUNT))
3139 GNUNET_free(sh->plugin); 3299 {
3140 GNUNET_free(sh); 3300 GNUNET_break (0);
3141 end_now(); 3301 GNUNET_free (sh->plugin);
3142 return NULL; 3302 GNUNET_free (sh);
3143 } 3303 end_now ();
3144 3304 return NULL;
3145 sh->sf = GNUNET_PLUGIN_load(sh->plugin, &sh->env); 3305 }
3306
3307 sh->sf = GNUNET_PLUGIN_load (sh->plugin, &sh->env);
3146 if (NULL == sh->sf) 3308 if (NULL == sh->sf)
3147 { 3309 {
3148 fprintf(stderr, "Failed to load solver `%s'\n", sh->plugin); 3310 fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin);
3149 GNUNET_break(0); 3311 GNUNET_break (0);
3150 GNUNET_free(sh->plugin); 3312 GNUNET_free (sh->plugin);
3151 GNUNET_free(sh); 3313 GNUNET_free (sh);
3152 end_now(); 3314 end_now ();
3153 return NULL; 3315 return NULL;
3154 } 3316 }
3155 return sh; 3317 return sh;
3156} 3318}
3157 3319
3158 3320
3159static void 3321static void
3160done() 3322done ()
3161{ 3323{
3162 struct TestPeer *cur; 3324 struct TestPeer *cur;
3163 struct TestPeer *next; 3325 struct TestPeer *next;
@@ -3166,79 +3328,80 @@ done()
3166 struct TestAddress *next_a; 3328 struct TestAddress *next_a;
3167 3329
3168 /* Stop logging */ 3330 /* Stop logging */
3169 GNUNET_ATS_solver_logging_stop(l); 3331 GNUNET_ATS_solver_logging_stop (l);
3170 3332
3171 /* Stop all preference generation */ 3333 /* Stop all preference generation */
3172 GNUNET_ATS_solver_generate_preferences_stop_all(); 3334 GNUNET_ATS_solver_generate_preferences_stop_all ();
3173 3335
3174 /* Stop all property generation */ 3336 /* Stop all property generation */
3175 GNUNET_ATS_solver_generate_property_stop_all(); 3337 GNUNET_ATS_solver_generate_property_stop_all ();
3176 3338
3177 if (opt_print) 3339 if (opt_print)
3178 { 3340 {
3179 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "== Printing log information \n"); 3341 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Printing log information \n");
3180 GNUNET_ATS_solver_logging_eval(l); 3342 GNUNET_ATS_solver_logging_eval (l);
3181 } 3343 }
3182 if (opt_save) 3344 if (opt_save)
3183 { 3345 {
3184 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "== Saving log information \n"); 3346 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "== Saving log information \n");
3185 GNUNET_ATS_solver_logging_write_to_disk(l, e->log_append_time_stamp, 3347 GNUNET_ATS_solver_logging_write_to_disk (l, e->log_append_time_stamp,
3186 e->log_output_dir); 3348 e->log_output_dir);
3187 } 3349 }
3188 3350
3189 if (NULL != l) 3351 if (NULL != l)
3190 { 3352 {
3191 GNUNET_ATS_solver_logging_free(l); 3353 GNUNET_ATS_solver_logging_free (l);
3192 l = NULL; 3354 l = NULL;
3193 } 3355 }
3194 3356
3195 /* Clean up experiment */ 3357 /* Clean up experiment */
3196 if (NULL != e) 3358 if (NULL != e)
3197 { 3359 {
3198 GNUNET_ATS_solvers_experimentation_stop(e); 3360 GNUNET_ATS_solvers_experimentation_stop (e);
3199 e = NULL; 3361 e = NULL;
3200 } 3362 }
3201 3363
3202 next = peer_head; 3364 next = peer_head;
3203 while (NULL != (cur = next)) 3365 while (NULL != (cur = next))
3366 {
3367 next = cur->next;
3368 GNUNET_CONTAINER_DLL_remove (peer_head, peer_tail, cur);
3369 next_a = cur->addr_head;
3370 while (NULL != (cur_a = next_a))
3204 { 3371 {
3205 next = cur->next; 3372 next_a = cur_a->next;
3206 GNUNET_CONTAINER_DLL_remove(peer_head, peer_tail, cur); 3373 GNUNET_CONTAINER_DLL_remove (cur->addr_head, cur->addr_tail, cur_a);
3207 next_a = cur->addr_head; 3374 GNUNET_free (cur_a);
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);
3215 } 3375 }
3376 GNUNET_free (cur);
3377 }
3216 if (NULL != sh) 3378 if (NULL != sh)
3217 { 3379 {
3218 GNUNET_ATS_solvers_solver_stop(sh); 3380 GNUNET_ATS_solvers_solver_stop (sh);
3219 sh = NULL; 3381 sh = NULL;
3220 } 3382 }
3221 3383
3222 /* Shutdown */ 3384 /* Shutdown */
3223 end_now(); 3385 end_now ();
3224} 3386}
3225 3387
3226static void 3388static void
3227experiment_done_cb(struct Experiment *e, struct GNUNET_TIME_Relative duration, int success) 3389experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,
3390 int success)
3228{ 3391{
3229 if (GNUNET_OK == success) 3392 if (GNUNET_OK == success)
3230 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n", 3393 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment done successful in %s\n",
3231 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES)); 3394 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES));
3232 else 3395 else
3233 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); 3396 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n");
3234 3397
3235 GNUNET_SCHEDULER_add_now(&done, NULL); 3398 GNUNET_SCHEDULER_add_now (&done, NULL);
3236} 3399}
3237 3400
3238static void 3401static void
3239episode_done_cb(struct Episode *ep) 3402episode_done_cb (struct Episode *ep)
3240{ 3403{
3241 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id); 3404 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Episode %u done\n", ep->id);
3242} 3405}
3243 3406
3244 3407
@@ -3247,62 +3410,62 @@ episode_done_cb(struct Episode *ep)
3247 * Do shutdown 3410 * Do shutdown
3248 */ 3411 */
3249static void 3412static void
3250end_now() 3413end_now ()
3251{ 3414{
3252 if (NULL != e) 3415 if (NULL != e)
3253 { 3416 {
3254 GNUNET_ATS_solvers_experimentation_stop(e); 3417 GNUNET_ATS_solvers_experimentation_stop (e);
3255 e = NULL; 3418 e = NULL;
3256 } 3419 }
3257 if (NULL != sh) 3420 if (NULL != sh)
3258 { 3421 {
3259 GNUNET_ATS_solvers_solver_stop(sh); 3422 GNUNET_ATS_solvers_solver_stop (sh);
3260 sh = NULL; 3423 sh = NULL;
3261 } 3424 }
3262} 3425}
3263 3426
3264static void 3427static void
3265run(void *cls, char * const *args, const char *cfgfile, 3428run (void *cls, char *const *args, const char *cfgfile,
3266 const struct GNUNET_CONFIGURATION_Handle *cfg) 3429 const struct GNUNET_CONFIGURATION_Handle *cfg)
3267{ 3430{
3268 enum GNUNET_ATS_Solvers solver; 3431 enum GNUNET_ATS_Solvers solver;
3269 int c; 3432 int c;
3270 3433
3271 if (NULL == opt_exp_file) 3434 if (NULL == opt_exp_file)
3272 { 3435 {
3273 fprintf(stderr, "No experiment given ...\n"); 3436 fprintf (stderr, "No experiment given ...\n");
3274 res = 1; 3437 res = 1;
3275 end_now(); 3438 end_now ();
3276 return; 3439 return;
3277 } 3440 }
3278 3441
3279 if (NULL == opt_solver) 3442 if (NULL == opt_solver)
3280 { 3443 {
3281 fprintf(stderr, "No solver given ...\n"); 3444 fprintf (stderr, "No solver given ...\n");
3282 res = 1; 3445 res = 1;
3283 end_now(); 3446 end_now ();
3284 return; 3447 return;
3285 } 3448 }
3286 3449
3287 if (0 == strcmp(opt_solver, "mlp")) 3450 if (0 == strcmp (opt_solver, "mlp"))
3288 { 3451 {
3289 solver = GNUNET_ATS_SOLVER_MLP; 3452 solver = GNUNET_ATS_SOLVER_MLP;
3290 } 3453 }
3291 else if (0 == strcmp(opt_solver, "proportional")) 3454 else if (0 == strcmp (opt_solver, "proportional"))
3292 { 3455 {
3293 solver = GNUNET_ATS_SOLVER_PROPORTIONAL; 3456 solver = GNUNET_ATS_SOLVER_PROPORTIONAL;
3294 } 3457 }
3295 else if (0 == strcmp(opt_solver, "ril")) 3458 else if (0 == strcmp (opt_solver, "ril"))
3296 { 3459 {
3297 solver = GNUNET_ATS_SOLVER_RIL; 3460 solver = GNUNET_ATS_SOLVER_RIL;
3298 } 3461 }
3299 else 3462 else
3300 { 3463 {
3301 fprintf(stderr, "No solver given ..."); 3464 fprintf (stderr, "No solver given ...");
3302 res = 1; 3465 res = 1;
3303 end_now(); 3466 end_now ();
3304 return; 3467 return;
3305 } 3468 }
3306 3469
3307 for (c = 0; c < GNUNET_ATS_PropertyCount; c++) 3470 for (c = 0; c < GNUNET_ATS_PropertyCount; c++)
3308 default_properties[c] = DEFAULT_REL_QUALITY; 3471 default_properties[c] = DEFAULT_REL_QUALITY;
@@ -3311,35 +3474,35 @@ run(void *cls, char * const *args, const char *cfgfile,
3311 default_preferences[c] = DEFAULT_REL_PREFERENCE; 3474 default_preferences[c] = DEFAULT_REL_PREFERENCE;
3312 3475
3313 /* load experiment */ 3476 /* load experiment */
3314 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n"); 3477 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading experiment\n");
3315 e = GNUNET_ATS_solvers_experimentation_load(opt_exp_file); 3478 e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file);
3316 if (NULL == e) 3479 if (NULL == e)
3317 { 3480 {
3318 fprintf(stderr, "Failed to load experiment ...\n"); 3481 fprintf (stderr, "Failed to load experiment ...\n");
3319 res = 1; 3482 res = 1;
3320 end_now(); 3483 end_now ();
3321 return; 3484 return;
3322 } 3485 }
3323 3486
3324 /* load solver */ 3487 /* load solver */
3325 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n"); 3488 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Loading solver\n");
3326 sh = GNUNET_ATS_solvers_solver_start(solver); 3489 sh = GNUNET_ATS_solvers_solver_start (solver);
3327 if (NULL == sh) 3490 if (NULL == sh)
3328 { 3491 {
3329 fprintf(stderr, "Failed to start solver ...\n"); 3492 fprintf (stderr, "Failed to start solver ...\n");
3330 end_now(); 3493 end_now ();
3331 res = 1; 3494 res = 1;
3332 return; 3495 return;
3333 } 3496 }
3334 3497
3335 /* start logging */ 3498 /* start logging */
3336 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Start logging \n"); 3499 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Start logging \n");
3337 l = GNUNET_ATS_solver_logging_start(e->log_freq); 3500 l = GNUNET_ATS_solver_logging_start (e->log_freq);
3338 3501
3339 /* run experiment */ 3502 /* run experiment */
3340 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n"); 3503 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "=== Running experiment \n");
3341 GNUNET_ATS_solvers_experimentation_run(e, episode_done_cb, 3504 GNUNET_ATS_solvers_experimentation_run (e, episode_done_cb,
3342 experiment_done_cb); 3505 experiment_done_cb);
3343 3506
3344 /* WAIT */ 3507 /* WAIT */
3345} 3508}
@@ -3352,7 +3515,7 @@ run(void *cls, char * const *args, const char *cfgfile,
3352 * @param argv argument values 3515 * @param argv argument values
3353 */ 3516 */
3354int 3517int
3355main(int argc, char *argv[]) 3518main (int argc, char *argv[])
3356{ 3519{
3357 opt_exp_file = NULL; 3520 opt_exp_file = NULL;
3358 opt_solver = NULL; 3521 opt_solver = NULL;
@@ -3361,40 +3524,39 @@ main(int argc, char *argv[])
3361 3524
3362 res = 0; 3525 res = 0;
3363 3526
3364 static struct GNUNET_GETOPT_CommandLineOption options[] = 3527 static struct GNUNET_GETOPT_CommandLineOption options[] = {
3365 { 3528 GNUNET_GETOPT_option_string ('s',
3366 GNUNET_GETOPT_option_string('s', 3529 "solver",
3367 "solver", 3530 gettext_noop ("solver to use"),
3368 gettext_noop("solver to use"), 3531 &opt_solver),
3369 &opt_solver),
3370 3532
3371 GNUNET_GETOPT_option_string('e', 3533 GNUNET_GETOPT_option_string ('e',
3372 "experiment" 3534 "experiment"
3373 gettext_noop("experiment to use"), 3535 gettext_noop ("experiment to use"),
3374 &opt_exp_file), 3536 &opt_exp_file),
3375 3537
3376 GNUNET_GETOPT_option_verbose(&opt_verbose), 3538 GNUNET_GETOPT_option_verbose (&opt_verbose),
3377 3539
3378 GNUNET_GETOPT_option_flag('p', 3540 GNUNET_GETOPT_option_flag ('p',
3379 "print", 3541 "print",
3380 gettext_noop("print logging"), 3542 gettext_noop ("print logging"),
3381 &opt_print), 3543 &opt_print),
3382 3544
3383 GNUNET_GETOPT_option_flag('f', 3545 GNUNET_GETOPT_option_flag ('f',
3384 "file", 3546 "file",
3385 gettext_noop("save logging to disk"), 3547 gettext_noop ("save logging to disk"),
3386 &opt_save), 3548 &opt_save),
3387 3549
3388 GNUNET_GETOPT_option_flag('d', 3550 GNUNET_GETOPT_option_flag ('d',
3389 "dn", 3551 "dn",
3390 gettext_noop("disable normalization"), 3552 gettext_noop ("disable normalization"),
3391 &opt_disable_normalization), 3553 &opt_disable_normalization),
3392 3554
3393 GNUNET_GETOPT_OPTION_END 3555 GNUNET_GETOPT_OPTION_END
3394 }; 3556 };
3395 3557
3396 GNUNET_PROGRAM_run(argc, argv, "gnunet-ats-solver-eval", 3558 GNUNET_PROGRAM_run (argc, argv, "gnunet-ats-solver-eval",
3397 NULL, options, &run, argv[0]); 3559 NULL, options, &run, argv[0]);
3398 3560
3399 return res; 3561 return res;
3400} 3562}
diff --git a/src/ats/gnunet-ats-solver-eval.h b/src/ats/gnunet-ats-solver-eval.h
index e3afa02b1..7d14bf761 100644
--- a/src/ats/gnunet-ats-solver-eval.h
+++ b/src/ats/gnunet-ats-solver-eval.h
@@ -34,7 +34,8 @@
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
37enum GeneratorType { 37enum GeneratorType
38{
38 GNUNET_ATS_TEST_TG_LINEAR, 39 GNUNET_ATS_TEST_TG_LINEAR,
39 GNUNET_ATS_TEST_TG_CONSTANT, 40 GNUNET_ATS_TEST_TG_CONSTANT,
40 GNUNET_ATS_TEST_TG_RANDOM, 41 GNUNET_ATS_TEST_TG_RANDOM,
@@ -42,7 +43,8 @@ enum GeneratorType {
42}; 43};
43 44
44 45
45enum OperationType { 46enum OperationType
47{
46 SOLVER_OP_ADD_ADDRESS, 48 SOLVER_OP_ADD_ADDRESS,
47 SOLVER_OP_DEL_ADDRESS, 49 SOLVER_OP_DEL_ADDRESS,
48 SOLVER_OP_START_SET_PROPERTY, 50 SOLVER_OP_START_SET_PROPERTY,
@@ -53,7 +55,8 @@ enum OperationType {
53 SOLVER_OP_STOP_REQUEST, 55 SOLVER_OP_STOP_REQUEST,
54}; 56};
55 57
56struct SolverHandle { 58struct SolverHandle
59{
57 /** 60 /**
58 * Solver plugin name 61 * Solver plugin name
59 */ 62 */
@@ -75,13 +78,15 @@ struct SolverHandle {
75 struct GNUNET_CONTAINER_MultiPeerMap *addresses; 78 struct GNUNET_CONTAINER_MultiPeerMap *addresses;
76}; 79};
77 80
78enum GNUNET_ATS_Solvers { 81enum GNUNET_ATS_Solvers
82{
79 GNUNET_ATS_SOLVER_PROPORTIONAL, 83 GNUNET_ATS_SOLVER_PROPORTIONAL,
80 GNUNET_ATS_SOLVER_MLP, 84 GNUNET_ATS_SOLVER_MLP,
81 GNUNET_ATS_SOLVER_RIL, 85 GNUNET_ATS_SOLVER_RIL,
82}; 86};
83 87
84struct LoggingFileHandle { 88struct LoggingFileHandle
89{
85 /* DLL list for logging time steps */ 90 /* DLL list for logging time steps */
86 struct LoggingFileHandle *next; 91 struct LoggingFileHandle *next;
87 struct LoggingFileHandle *prev; 92 struct LoggingFileHandle *prev;
@@ -95,7 +100,8 @@ struct LoggingFileHandle {
95 struct GNUNET_DISK_FileHandle *f_hd; 100 struct GNUNET_DISK_FileHandle *f_hd;
96}; 101};
97 102
98struct LoggingTimeStep { 103struct LoggingTimeStep
104{
99 struct LoggingTimeStep *prev; 105 struct LoggingTimeStep *prev;
100 struct LoggingTimeStep *next; 106 struct LoggingTimeStep *next;
101 107
@@ -106,7 +112,8 @@ struct LoggingTimeStep {
106 struct GNUNET_TIME_Relative delta; 112 struct GNUNET_TIME_Relative delta;
107}; 113};
108 114
109struct LoggingPeer { 115struct LoggingPeer
116{
110 struct LoggingPeer *prev; 117 struct LoggingPeer *prev;
111 struct LoggingPeer *next; 118 struct LoggingPeer *next;
112 119
@@ -120,7 +127,8 @@ struct LoggingPeer {
120 struct LoggingAddress *addr_tail; 127 struct LoggingAddress *addr_tail;
121}; 128};
122 129
123struct LoggingAddress { 130struct LoggingAddress
131{
124 struct LoggingAddress *next; 132 struct LoggingAddress *next;
125 struct LoggingAddress *prev; 133 struct LoggingAddress *prev;
126 134
@@ -135,7 +143,8 @@ struct LoggingAddress {
135}; 143};
136 144
137 145
138struct TestPeer { 146struct TestPeer
147{
139 struct TestPeer *prev; 148 struct TestPeer *prev;
140 struct TestPeer *next; 149 struct TestPeer *next;
141 150
@@ -155,7 +164,8 @@ struct TestPeer {
155}; 164};
156 165
157 166
158struct TestAddress { 167struct TestAddress
168{
159 struct TestAddress *next; 169 struct TestAddress *next;
160 struct TestAddress *prev; 170 struct TestAddress *prev;
161 171
@@ -175,12 +185,16 @@ typedef void (*GNUNET_ATS_TESTING_EpisodeDoneCallback) (
175 struct Episode *e); 185 struct Episode *e);
176 186
177typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e, 187typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) (struct Experiment *e,
178 struct GNUNET_TIME_Relative duration, int success); 188 struct
189 GNUNET_TIME_Relative
190 duration, int
191 success);
179 192
180/** 193/**
181 * An operation in an experiment 194 * An operation in an experiment
182 */ 195 */
183struct GNUNET_ATS_TEST_Operation { 196struct GNUNET_ATS_TEST_Operation
197{
184 struct GNUNET_ATS_TEST_Operation *next; 198 struct GNUNET_ATS_TEST_Operation *next;
185 struct GNUNET_ATS_TEST_Operation *prev; 199 struct GNUNET_ATS_TEST_Operation *prev;
186 200
@@ -206,7 +220,8 @@ struct GNUNET_ATS_TEST_Operation {
206 // enum GNUNET_ATS_Property prop_type; 220 // enum GNUNET_ATS_Property prop_type;
207}; 221};
208 222
209struct Episode { 223struct Episode
224{
210 int id; 225 int id;
211 struct Episode *next; 226 struct Episode *next;
212 struct GNUNET_TIME_Relative duration; 227 struct GNUNET_TIME_Relative duration;
@@ -215,8 +230,9 @@ struct Episode {
215 struct GNUNET_ATS_TEST_Operation *tail; 230 struct GNUNET_ATS_TEST_Operation *tail;
216}; 231};
217 232
218struct LoggingHandle { 233struct LoggingHandle
219 struct GNUNET_SCHEDULER_Task * logging_task; 234{
235 struct GNUNET_SCHEDULER_Task *logging_task;
220 struct GNUNET_TIME_Relative log_freq; 236 struct GNUNET_TIME_Relative log_freq;
221 237
222 /* DLL list for logging time steps */ 238 /* DLL list for logging time steps */
@@ -224,7 +240,8 @@ struct LoggingHandle {
224 struct LoggingTimeStep *tail; 240 struct LoggingTimeStep *tail;
225}; 241};
226 242
227struct Experiment { 243struct Experiment
244{
228 char *name; 245 char *name;
229 char *log_prefix; 246 char *log_prefix;
230 char *cfg_file; 247 char *cfg_file;
@@ -240,15 +257,16 @@ struct Experiment {
240 257
241 struct GNUNET_CONFIGURATION_Handle *cfg; 258 struct GNUNET_CONFIGURATION_Handle *cfg;
242 259
243 struct GNUNET_SCHEDULER_Task * experiment_timeout_task; 260 struct GNUNET_SCHEDULER_Task *experiment_timeout_task;
244 struct GNUNET_SCHEDULER_Task * episode_timeout_task; 261 struct GNUNET_SCHEDULER_Task *episode_timeout_task;
245 struct Episode *cur; 262 struct Episode *cur;
246 263
247 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb; 264 GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb;
248 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb; 265 GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb;
249}; 266};
250 267
251struct PreferenceGenerator { 268struct PreferenceGenerator
269{
252 struct PreferenceGenerator *prev; 270 struct PreferenceGenerator *prev;
253 struct PreferenceGenerator *next; 271 struct PreferenceGenerator *next;
254 272
@@ -265,8 +283,8 @@ struct PreferenceGenerator {
265 struct GNUNET_TIME_Relative frequency; 283 struct GNUNET_TIME_Relative frequency;
266 struct GNUNET_TIME_Relative feedback_frequency; 284 struct GNUNET_TIME_Relative feedback_frequency;
267 285
268 struct GNUNET_SCHEDULER_Task * set_task; 286 struct GNUNET_SCHEDULER_Task *set_task;
269 struct GNUNET_SCHEDULER_Task * feedback_task; 287 struct GNUNET_SCHEDULER_Task *feedback_task;
270 struct GNUNET_TIME_Absolute next_ping_transmission; 288 struct GNUNET_TIME_Absolute next_ping_transmission;
271 struct GNUNET_TIME_Absolute time_start; 289 struct GNUNET_TIME_Absolute time_start;
272 290
@@ -289,7 +307,8 @@ struct PreferenceGenerator {
289}; 307};
290 308
291 309
292struct PropertyGenerator { 310struct PropertyGenerator
311{
293 struct PropertyGenerator *prev; 312 struct PropertyGenerator *prev;
294 struct PropertyGenerator *next; 313 struct PropertyGenerator *next;
295 314
@@ -307,7 +326,7 @@ struct PropertyGenerator {
307 struct GNUNET_TIME_Relative duration_period; 326 struct GNUNET_TIME_Relative duration_period;
308 struct GNUNET_TIME_Relative frequency; 327 struct GNUNET_TIME_Relative frequency;
309 328
310 struct GNUNET_SCHEDULER_Task * set_task; 329 struct GNUNET_SCHEDULER_Task *set_task;
311 struct GNUNET_TIME_Absolute next_ping_transmission; 330 struct GNUNET_TIME_Absolute next_ping_transmission;
312 struct GNUNET_TIME_Absolute time_start; 331 struct GNUNET_TIME_Absolute time_start;
313}; 332};
diff --git a/src/ats/gnunet-service-ats-new.c b/src/ats/gnunet-service-ats-new.c
index 1061c28c2..f2ef92436 100644
--- a/src/ats/gnunet-service-ats-new.c
+++ b/src/ats/gnunet-service-ats-new.c
@@ -33,7 +33,8 @@
33/** 33/**
34 * What type of client is this client? 34 * What type of client is this client?
35 */ 35 */
36enum ClientType { 36enum ClientType
37{
37 /** 38 /**
38 * We don't know yet. 39 * We don't know yet.
39 */ 40 */
@@ -59,7 +60,8 @@ struct Client;
59/** 60/**
60 * Preferences expressed by a client are kept in a DLL per client. 61 * Preferences expressed by a client are kept in a DLL per client.
61 */ 62 */
62struct ClientPreference { 63struct ClientPreference
64{
63 /** 65 /**
64 * DLL pointer. 66 * DLL pointer.
65 */ 67 */
@@ -90,7 +92,8 @@ struct ClientPreference {
90/** 92/**
91 * Information about ongoing sessions of the transport client. 93 * Information about ongoing sessions of the transport client.
92 */ 94 */
93struct GNUNET_ATS_Session { 95struct GNUNET_ATS_Session
96{
94 /** 97 /**
95 * Session data exposed to the plugin. 98 * Session data exposed to the plugin.
96 */ 99 */
@@ -116,7 +119,8 @@ struct GNUNET_ATS_Session {
116/** 119/**
117 * Information we track per client. 120 * Information we track per client.
118 */ 121 */
119struct Client { 122struct Client
123{
120 /** 124 /**
121 * Type of the client, initially #CT_NONE. 125 * Type of the client, initially #CT_NONE.
122 */ 126 */
@@ -135,8 +139,10 @@ struct Client {
135 /** 139 /**
136 * Details depending on @e type. 140 * Details depending on @e type.
137 */ 141 */
138 union { 142 union
139 struct { 143 {
144 struct
145 {
140 /** 146 /**
141 * Head of DLL of preferences expressed by this client. 147 * Head of DLL of preferences expressed by this client.
142 */ 148 */
@@ -148,7 +154,8 @@ struct Client {
148 struct ClientPreference *cp_tail; 154 struct ClientPreference *cp_tail;
149 } application; 155 } application;
150 156
151 struct { 157 struct
158 {
152 /** 159 /**
153 * Map from session IDs to `struct GNUNET_ATS_Session` objects. 160 * Map from session IDs to `struct GNUNET_ATS_Session` objects.
154 */ 161 */
@@ -188,32 +195,32 @@ static struct Client *transport_client;
188 * @param address address the transport should try 195 * @param address address the transport should try
189 */ 196 */
190static void 197static void
191suggest_cb(void *cls, 198suggest_cb (void *cls,
192 const struct GNUNET_PeerIdentity *pid, 199 const struct GNUNET_PeerIdentity *pid,
193 const char *address) 200 const char *address)
194{ 201{
195 struct GNUNET_MQ_Envelope *env; 202 struct GNUNET_MQ_Envelope *env;
196 size_t slen = strlen(address) + 1; 203 size_t slen = strlen (address) + 1;
197 struct AddressSuggestionMessage *as; 204 struct AddressSuggestionMessage *as;
198 205
199 if (NULL == transport_client) 206 if (NULL == transport_client)
200 { 207 {
201 // FIXME: stats! 208 // FIXME: stats!
202 return; 209 return;
203 } 210 }
204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Suggesting address `%s' of peer `%s'\n", 212 "Suggesting address `%s' of peer `%s'\n",
206 address, 213 address,
207 GNUNET_i2s(pid)); 214 GNUNET_i2s (pid));
208 env = GNUNET_MQ_msg_extra(as, 215 env = GNUNET_MQ_msg_extra (as,
209 slen, 216 slen,
210 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 217 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
211 as->peer = *pid; 218 as->peer = *pid;
212 memcpy(&as[1], 219 memcpy (&as[1],
213 address, 220 address,
214 slen); 221 slen);
215 GNUNET_MQ_send(transport_client->mq, 222 GNUNET_MQ_send (transport_client->mq,
216 env); 223 env);
217} 224}
218 225
219 226
@@ -228,37 +235,37 @@ suggest_cb(void *cls,
228 * @param bw_out suggested bandwidth for transmission 235 * @param bw_out suggested bandwidth for transmission
229 */ 236 */
230static void 237static void
231allocate_cb(void *cls, 238allocate_cb (void *cls,
232 struct GNUNET_ATS_Session *session, 239 struct GNUNET_ATS_Session *session,
233 const struct GNUNET_PeerIdentity *peer, 240 const struct GNUNET_PeerIdentity *peer,
234 struct GNUNET_BANDWIDTH_Value32NBO bw_in, 241 struct GNUNET_BANDWIDTH_Value32NBO bw_in,
235 struct GNUNET_BANDWIDTH_Value32NBO bw_out) 242 struct GNUNET_BANDWIDTH_Value32NBO bw_out)
236{ 243{
237 struct GNUNET_MQ_Envelope *env; 244 struct GNUNET_MQ_Envelope *env;
238 struct SessionAllocationMessage *sam; 245 struct SessionAllocationMessage *sam;
239 246
240 (void)cls; 247 (void) cls;
241 if ((NULL == transport_client) || 248 if ((NULL == transport_client) ||
242 (session->client != transport_client)) 249 (session->client != transport_client))
243 { 250 {
244 /* transport must have just died and solver is addressing the 251 /* transport must have just died and solver is addressing the
245 losses of sessions (possibly of previous transport), ignore! */ 252 losses of sessions (possibly of previous transport), ignore! */
246 return; 253 return;
247 } 254 }
248 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
249 "Allocating %u/%u bytes for %p of peer `%s'\n", 256 "Allocating %u/%u bytes for %p of peer `%s'\n",
250 ntohl(bw_in.value__), 257 ntohl (bw_in.value__),
251 ntohl(bw_out.value__), 258 ntohl (bw_out.value__),
252 session, 259 session,
253 GNUNET_i2s(peer)); 260 GNUNET_i2s (peer));
254 env = GNUNET_MQ_msg(sam, 261 env = GNUNET_MQ_msg (sam,
255 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); 262 GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION);
256 sam->session_id = session->session_id; 263 sam->session_id = session->session_id;
257 sam->peer = *peer; 264 sam->peer = *peer;
258 sam->bandwidth_in = bw_in; 265 sam->bandwidth_in = bw_in;
259 sam->bandwidth_out = bw_out; 266 sam->bandwidth_out = bw_out;
260 GNUNET_MQ_send(transport_client->mq, 267 GNUNET_MQ_send (transport_client->mq,
261 env); 268 env);
262} 269}
263 270
264 271
@@ -269,18 +276,19 @@ allocate_cb(void *cls,
269 * @param prop[out] in HBO 276 * @param prop[out] in HBO
270 */ 277 */
271static void 278static void
272prop_ntoh(const struct PropertiesNBO *properties, 279prop_ntoh (const struct PropertiesNBO *properties,
273 struct GNUNET_ATS_Properties *prop) 280 struct GNUNET_ATS_Properties *prop)
274{ 281{
275 prop->delay = GNUNET_TIME_relative_ntoh(properties->delay); 282 prop->delay = GNUNET_TIME_relative_ntoh (properties->delay);
276 prop->goodput_out = ntohl(properties->goodput_out); 283 prop->goodput_out = ntohl (properties->goodput_out);
277 prop->goodput_in = ntohl(properties->goodput_in); 284 prop->goodput_in = ntohl (properties->goodput_in);
278 prop->utilization_out = ntohl(properties->utilization_out); 285 prop->utilization_out = ntohl (properties->utilization_out);
279 prop->utilization_in = ntohl(properties->utilization_in); 286 prop->utilization_in = ntohl (properties->utilization_in);
280 prop->distance = ntohl(properties->distance); 287 prop->distance = ntohl (properties->distance);
281 prop->mtu = ntohl(properties->mtu); 288 prop->mtu = ntohl (properties->mtu);
282 prop->nt = (enum GNUNET_NetworkType)ntohl(properties->nt); 289 prop->nt = (enum GNUNET_NetworkType) ntohl (properties->nt);
283 prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(properties->cc); 290 prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (
291 properties->cc);
284} 292}
285 293
286 294
@@ -291,8 +299,8 @@ prop_ntoh(const struct PropertiesNBO *properties,
291 * @param msg the start message 299 * @param msg the start message
292 */ 300 */
293static void 301static void
294handle_suggest(void *cls, 302handle_suggest (void *cls,
295 const struct ExpressPreferenceMessage *msg) 303 const struct ExpressPreferenceMessage *msg)
296{ 304{
297 struct Client *c = cls; 305 struct Client *c = cls;
298 struct ClientPreference *cp; 306 struct ClientPreference *cp;
@@ -300,27 +308,27 @@ handle_suggest(void *cls,
300 if (CT_NONE == c->type) 308 if (CT_NONE == c->type)
301 c->type = CT_APPLICATION; 309 c->type = CT_APPLICATION;
302 if (CT_APPLICATION != c->type) 310 if (CT_APPLICATION != c->type)
303 { 311 {
304 GNUNET_break(0); 312 GNUNET_break (0);
305 GNUNET_SERVICE_client_drop(c->client); 313 GNUNET_SERVICE_client_drop (c->client);
306 return; 314 return;
307 } 315 }
308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
309 "Client suggested we talk to %s with preference %d at rate %u\n", 317 "Client suggested we talk to %s with preference %d at rate %u\n",
310 GNUNET_i2s(&msg->peer), 318 GNUNET_i2s (&msg->peer),
311 (int)ntohl(msg->pk), 319 (int) ntohl (msg->pk),
312 (int)ntohl(msg->bw.value__)); 320 (int) ntohl (msg->bw.value__));
313 cp = GNUNET_new(struct ClientPreference); 321 cp = GNUNET_new (struct ClientPreference);
314 cp->client = c; 322 cp->client = c;
315 cp->pref.peer = msg->peer; 323 cp->pref.peer = msg->peer;
316 cp->pref.bw = msg->bw; 324 cp->pref.bw = msg->bw;
317 cp->pref.pk = (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk); 325 cp->pref.pk = (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk);
318 cp->ph = plugin->preference_add(plugin->cls, 326 cp->ph = plugin->preference_add (plugin->cls,
319 &cp->pref); 327 &cp->pref);
320 GNUNET_CONTAINER_DLL_insert(c->details.application.cp_head, 328 GNUNET_CONTAINER_DLL_insert (c->details.application.cp_head,
321 c->details.application.cp_tail, 329 c->details.application.cp_tail,
322 cp); 330 cp);
323 GNUNET_SERVICE_client_continue(c->client); 331 GNUNET_SERVICE_client_continue (c->client);
324} 332}
325 333
326 334
@@ -331,8 +339,8 @@ handle_suggest(void *cls,
331 * @param msg the start message 339 * @param msg the start message
332 */ 340 */
333static void 341static void
334handle_suggest_cancel(void *cls, 342handle_suggest_cancel (void *cls,
335 const struct ExpressPreferenceMessage *msg) 343 const struct ExpressPreferenceMessage *msg)
336{ 344{
337 struct Client *c = cls; 345 struct Client *c = cls;
338 struct ClientPreference *cp; 346 struct ClientPreference *cp;
@@ -340,33 +348,33 @@ handle_suggest_cancel(void *cls,
340 if (CT_NONE == c->type) 348 if (CT_NONE == c->type)
341 c->type = CT_APPLICATION; 349 c->type = CT_APPLICATION;
342 if (CT_APPLICATION != c->type) 350 if (CT_APPLICATION != c->type)
343 { 351 {
344 GNUNET_break(0); 352 GNUNET_break (0);
345 GNUNET_SERVICE_client_drop(c->client); 353 GNUNET_SERVICE_client_drop (c->client);
346 return; 354 return;
347 } 355 }
348 for (cp = c->details.application.cp_head; 356 for (cp = c->details.application.cp_head;
349 NULL != cp; 357 NULL != cp;
350 cp = cp->next) 358 cp = cp->next)
351 if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk)) && 359 if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind) ntohl (msg->pk)) &&
352 (cp->pref.bw.value__ == msg->bw.value__) && 360 (cp->pref.bw.value__ == msg->bw.value__) &&
353 (0 == GNUNET_memcmp(&cp->pref.peer, 361 (0 == GNUNET_memcmp (&cp->pref.peer,
354 &msg->peer))) 362 &msg->peer)))
355 break; 363 break;
356 if (NULL == cp) 364 if (NULL == cp)
357 { 365 {
358 GNUNET_break(0); 366 GNUNET_break (0);
359 GNUNET_SERVICE_client_drop(c->client); 367 GNUNET_SERVICE_client_drop (c->client);
360 return; 368 return;
361 } 369 }
362 plugin->preference_del(plugin->cls, 370 plugin->preference_del (plugin->cls,
363 cp->ph, 371 cp->ph,
364 &cp->pref); 372 &cp->pref);
365 GNUNET_CONTAINER_DLL_remove(c->details.application.cp_head, 373 GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head,
366 c->details.application.cp_tail, 374 c->details.application.cp_tail,
367 cp); 375 cp);
368 GNUNET_free(cp); 376 GNUNET_free (cp);
369 GNUNET_SERVICE_client_continue(c->client); 377 GNUNET_SERVICE_client_continue (c->client);
370} 378}
371 379
372 380
@@ -377,27 +385,27 @@ handle_suggest_cancel(void *cls,
377 * @param message the request message 385 * @param message the request message
378 */ 386 */
379static void 387static void
380handle_start(void *cls, 388handle_start (void *cls,
381 const struct GNUNET_MessageHeader *hdr) 389 const struct GNUNET_MessageHeader *hdr)
382{ 390{
383 struct Client *c = cls; 391 struct Client *c = cls;
384 392
385 if (CT_NONE != c->type) 393 if (CT_NONE != c->type)
386 { 394 {
387 GNUNET_break(0); 395 GNUNET_break (0);
388 GNUNET_SERVICE_client_drop(c->client); 396 GNUNET_SERVICE_client_drop (c->client);
389 return; 397 return;
390 } 398 }
391 c->type = CT_TRANSPORT; 399 c->type = CT_TRANSPORT;
392 c->details.transport.sessions 400 c->details.transport.sessions
393 = GNUNET_CONTAINER_multihashmap32_create(128); 401 = GNUNET_CONTAINER_multihashmap32_create (128);
394 if (NULL != transport_client) 402 if (NULL != transport_client)
395 { 403 {
396 GNUNET_SERVICE_client_drop(transport_client->client); 404 GNUNET_SERVICE_client_drop (transport_client->client);
397 transport_client = NULL; 405 transport_client = NULL;
398 } 406 }
399 transport_client = c; 407 transport_client = c;
400 GNUNET_SERVICE_client_continue(c->client); 408 GNUNET_SERVICE_client_continue (c->client);
401} 409}
402 410
403 411
@@ -410,17 +418,17 @@ handle_start(void *cls,
410 * @return #GNUNET_OK if @a message is well-formed 418 * @return #GNUNET_OK if @a message is well-formed
411 */ 419 */
412static int 420static int
413check_session_add(void *cls, 421check_session_add (void *cls,
414 const struct SessionAddMessage *message) 422 const struct SessionAddMessage *message)
415{ 423{
416 struct Client *c = cls; 424 struct Client *c = cls;
417 425
418 GNUNET_MQ_check_zero_termination(message); 426 GNUNET_MQ_check_zero_termination (message);
419 if (CT_TRANSPORT != c->type) 427 if (CT_TRANSPORT != c->type)
420 { 428 {
421 GNUNET_break(0); 429 GNUNET_break (0);
422 return GNUNET_SYSERR; 430 return GNUNET_SYSERR;
423 } 431 }
424 return GNUNET_OK; 432 return GNUNET_OK;
425} 433}
426 434
@@ -432,45 +440,46 @@ check_session_add(void *cls,
432 * @param message the request message 440 * @param message the request message
433 */ 441 */
434static void 442static void
435handle_session_add(void *cls, 443handle_session_add (void *cls,
436 const struct SessionAddMessage *message) 444 const struct SessionAddMessage *message)
437{ 445{
438 struct Client *c = cls; 446 struct Client *c = cls;
439 const char *address = (const char *)&message[1]; 447 const char *address = (const char *) &message[1];
440 struct GNUNET_ATS_Session *session; 448 struct GNUNET_ATS_Session *session;
441 int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == 449 int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY ==
442 ntohs(message->header.type)); 450 ntohs (message->header.type));
443 451
444 session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, 452 session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
445 message->session_id); 453 message->session_id);
446 if (NULL != session) 454 if (NULL != session)
447 { 455 {
448 GNUNET_break(0); 456 GNUNET_break (0);
449 GNUNET_SERVICE_client_drop(c->client); 457 GNUNET_SERVICE_client_drop (c->client);
450 return; 458 return;
451 } 459 }
452 session = GNUNET_new(struct GNUNET_ATS_Session); 460 session = GNUNET_new (struct GNUNET_ATS_Session);
453 session->data.session = session; 461 session->data.session = session;
454 session->client = c; 462 session->client = c;
455 session->session_id = message->session_id; 463 session->session_id = message->session_id;
456 session->data.peer = message->peer; 464 session->data.peer = message->peer;
457 prop_ntoh(&message->properties, 465 prop_ntoh (&message->properties,
458 &session->data.prop); 466 &session->data.prop);
459 session->data.inbound_only = inbound_only; 467 session->data.inbound_only = inbound_only;
460 GNUNET_assert(GNUNET_YES == 468 GNUNET_assert (GNUNET_YES ==
461 GNUNET_CONTAINER_multihashmap32_put(c->details.transport.sessions, 469 GNUNET_CONTAINER_multihashmap32_put (
462 message->session_id, 470 c->details.transport.sessions,
463 session, 471 message->session_id,
464 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 472 session,
465 session->sh = plugin->session_add(plugin->cls, 473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
466 &session->data, 474 session->sh = plugin->session_add (plugin->cls,
467 address); 475 &session->data,
468 GNUNET_assert(NULL != session->sh); 476 address);
469 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 477 GNUNET_assert (NULL != session->sh);
470 "Transport has new session %p to %s\n", 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 session, 479 "Transport has new session %p to %s\n",
472 GNUNET_i2s(&message->peer)); 480 session,
473 GNUNET_SERVICE_client_continue(c->client); 481 GNUNET_i2s (&message->peer));
482 GNUNET_SERVICE_client_continue (c->client);
474} 483}
475 484
476 485
@@ -481,32 +490,32 @@ handle_session_add(void *cls,
481 * @param msg the request message 490 * @param msg the request message
482 */ 491 */
483static void 492static void
484handle_session_update(void *cls, 493handle_session_update (void *cls,
485 const struct SessionUpdateMessage *msg) 494 const struct SessionUpdateMessage *msg)
486{ 495{
487 struct Client *c = cls; 496 struct Client *c = cls;
488 struct GNUNET_ATS_Session *session; 497 struct GNUNET_ATS_Session *session;
489 498
490 if (CT_TRANSPORT != c->type) 499 if (CT_TRANSPORT != c->type)
491 { 500 {
492 GNUNET_break(0); 501 GNUNET_break (0);
493 GNUNET_SERVICE_client_drop(c->client); 502 GNUNET_SERVICE_client_drop (c->client);
494 return; 503 return;
495 } 504 }
496 session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, 505 session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
497 msg->session_id); 506 msg->session_id);
498 if (NULL == session) 507 if (NULL == session)
499 { 508 {
500 GNUNET_break(0); 509 GNUNET_break (0);
501 GNUNET_SERVICE_client_drop(c->client); 510 GNUNET_SERVICE_client_drop (c->client);
502 return; 511 return;
503 } 512 }
504 prop_ntoh(&msg->properties, 513 prop_ntoh (&msg->properties,
505 &session->data.prop); 514 &session->data.prop);
506 plugin->session_update(plugin->cls, 515 plugin->session_update (plugin->cls,
507 session->sh, 516 session->sh,
508 &session->data); 517 &session->data);
509 GNUNET_SERVICE_client_continue(c->client); 518 GNUNET_SERVICE_client_continue (c->client);
510} 519}
511 520
512 521
@@ -517,41 +526,42 @@ handle_session_update(void *cls,
517 * @param message the request message 526 * @param message the request message
518 */ 527 */
519static void 528static void
520handle_session_del(void *cls, 529handle_session_del (void *cls,
521 const struct SessionDelMessage *message) 530 const struct SessionDelMessage *message)
522{ 531{
523 struct Client *c = cls; 532 struct Client *c = cls;
524 struct GNUNET_ATS_Session *session; 533 struct GNUNET_ATS_Session *session;
525 534
526 if (CT_TRANSPORT != c->type) 535 if (CT_TRANSPORT != c->type)
527 { 536 {
528 GNUNET_break(0); 537 GNUNET_break (0);
529 GNUNET_SERVICE_client_drop(c->client); 538 GNUNET_SERVICE_client_drop (c->client);
530 return; 539 return;
531 } 540 }
532 session = GNUNET_CONTAINER_multihashmap32_get(c->details.transport.sessions, 541 session = GNUNET_CONTAINER_multihashmap32_get (c->details.transport.sessions,
533 message->session_id); 542 message->session_id);
534 if (NULL == session) 543 if (NULL == session)
535 { 544 {
536 GNUNET_break(0); 545 GNUNET_break (0);
537 GNUNET_SERVICE_client_drop(c->client); 546 GNUNET_SERVICE_client_drop (c->client);
538 return; 547 return;
539 } 548 }
540 GNUNET_assert(NULL != session->sh); 549 GNUNET_assert (NULL != session->sh);
541 plugin->session_del(plugin->cls, 550 plugin->session_del (plugin->cls,
542 session->sh, 551 session->sh,
543 &session->data); 552 &session->data);
544 session->sh = NULL; 553 session->sh = NULL;
545 GNUNET_assert(GNUNET_YES == 554 GNUNET_assert (GNUNET_YES ==
546 GNUNET_CONTAINER_multihashmap32_remove(c->details.transport.sessions, 555 GNUNET_CONTAINER_multihashmap32_remove (
547 session->session_id, 556 c->details.transport.sessions,
548 session)); 557 session->session_id,
549 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 558 session));
550 "Transport lost session %p to %s\n", 559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
551 session, 560 "Transport lost session %p to %s\n",
552 GNUNET_i2s(&session->data.peer)); 561 session,
553 GNUNET_free(session); 562 GNUNET_i2s (&session->data.peer));
554 GNUNET_SERVICE_client_continue(c->client); 563 GNUNET_free (session);
564 GNUNET_SERVICE_client_continue (c->client);
555} 565}
556 566
557 567
@@ -565,11 +575,11 @@ handle_session_del(void *cls,
565 * @return @a client 575 * @return @a client
566 */ 576 */
567static void * 577static void *
568client_connect_cb(void *cls, 578client_connect_cb (void *cls,
569 struct GNUNET_SERVICE_Client *client, 579 struct GNUNET_SERVICE_Client *client,
570 struct GNUNET_MQ_Handle *mq) 580 struct GNUNET_MQ_Handle *mq)
571{ 581{
572 struct Client *c = GNUNET_new(struct Client); 582 struct Client *c = GNUNET_new (struct Client);
573 583
574 c->client = client; 584 c->client = client;
575 c->mq = mq; 585 c->mq = mq;
@@ -586,21 +596,21 @@ client_connect_cb(void *cls,
586 * @param value a `struct GNUNET_ATS_Session` 596 * @param value a `struct GNUNET_ATS_Session`
587 */ 597 */
588static int 598static int
589free_session(void *cls, 599free_session (void *cls,
590 uint32_t key, 600 uint32_t key,
591 void *value) 601 void *value)
592{ 602{
593 struct Client *c = cls; 603 struct Client *c = cls;
594 struct GNUNET_ATS_Session *session = value; 604 struct GNUNET_ATS_Session *session = value;
595 605
596 (void)key; 606 (void) key;
597 GNUNET_assert(c == session->client); 607 GNUNET_assert (c == session->client);
598 GNUNET_assert(NULL != session->sh); 608 GNUNET_assert (NULL != session->sh);
599 plugin->session_del(plugin->cls, 609 plugin->session_del (plugin->cls,
600 session->sh, 610 session->sh,
601 &session->data); 611 &session->data);
602 session->sh = NULL; 612 session->sh = NULL;
603 GNUNET_free(session); 613 GNUNET_free (session);
604 return GNUNET_OK; 614 return GNUNET_OK;
605} 615}
606 616
@@ -614,44 +624,44 @@ free_session(void *cls,
614 * @param app_ctx our `struct Client` 624 * @param app_ctx our `struct Client`
615 */ 625 */
616static void 626static void
617client_disconnect_cb(void *cls, 627client_disconnect_cb (void *cls,
618 struct GNUNET_SERVICE_Client *client, 628 struct GNUNET_SERVICE_Client *client,
619 void *app_ctx) 629 void *app_ctx)
620{ 630{
621 struct Client *c = app_ctx; 631 struct Client *c = app_ctx;
622 632
623 (void)cls; 633 (void) cls;
624 GNUNET_assert(c->client == client); 634 GNUNET_assert (c->client == client);
625 switch (c->type) 635 switch (c->type)
636 {
637 case CT_NONE:
638 break;
639
640 case CT_APPLICATION:
641 for (struct ClientPreference *cp = c->details.application.cp_head;
642 NULL != cp;
643 cp = c->details.application.cp_head)
626 { 644 {
627 case CT_NONE: 645 plugin->preference_del (plugin->cls,
628 break; 646 cp->ph,
629 647 &cp->pref);
630 case CT_APPLICATION: 648 GNUNET_CONTAINER_DLL_remove (c->details.application.cp_head,
631 for (struct ClientPreference *cp = c->details.application.cp_head; 649 c->details.application.cp_tail,
632 NULL != cp; 650 cp);
633 cp = c->details.application.cp_head) 651 GNUNET_free (cp);
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 } 652 }
654 GNUNET_free(c); 653 break;
654
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);
655} 665}
656 666
657 667
@@ -661,26 +671,26 @@ client_disconnect_cb(void *cls,
661 * @param cls unused 671 * @param cls unused
662 */ 672 */
663static void 673static void
664final_cleanup(void *cls) 674final_cleanup (void *cls)
665{ 675{
666 (void)cls; 676 (void) cls;
667 if (NULL != stats) 677 if (NULL != stats)
668 { 678 {
669 GNUNET_STATISTICS_destroy(stats, 679 GNUNET_STATISTICS_destroy (stats,
670 GNUNET_NO); 680 GNUNET_NO);
671 stats = NULL; 681 stats = NULL;
672 } 682 }
673 if (NULL != plugin) 683 if (NULL != plugin)
674 { 684 {
675 GNUNET_PLUGIN_unload(plugin_name, 685 GNUNET_PLUGIN_unload (plugin_name,
676 plugin); 686 plugin);
677 plugin = NULL; 687 plugin = NULL;
678 } 688 }
679 if (NULL != plugin_name) 689 if (NULL != plugin_name)
680 { 690 {
681 GNUNET_free(plugin_name); 691 GNUNET_free (plugin_name);
682 plugin_name = NULL; 692 plugin_name = NULL;
683 } 693 }
684} 694}
685 695
686 696
@@ -690,13 +700,13 @@ final_cleanup(void *cls)
690 * @param cls unused 700 * @param cls unused
691 */ 701 */
692static void 702static void
693cleanup_task(void *cls) 703cleanup_task (void *cls)
694{ 704{
695 (void)cls; 705 (void) cls;
696 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
697 "ATS shutdown initiated\n"); 707 "ATS shutdown initiated\n");
698 GNUNET_SCHEDULER_add_now(&final_cleanup, 708 GNUNET_SCHEDULER_add_now (&final_cleanup,
699 NULL); 709 NULL);
700} 710}
701 711
702 712
@@ -708,45 +718,45 @@ cleanup_task(void *cls)
708 * @param service the initialized service 718 * @param service the initialized service
709 */ 719 */
710static void 720static void
711run(void *cls, 721run (void *cls,
712 const struct GNUNET_CONFIGURATION_Handle *cfg, 722 const struct GNUNET_CONFIGURATION_Handle *cfg,
713 struct GNUNET_SERVICE_Handle *service) 723 struct GNUNET_SERVICE_Handle *service)
714{ 724{
715 static struct GNUNET_ATS_PluginEnvironment env; 725 static struct GNUNET_ATS_PluginEnvironment env;
716 char *solver; 726 char *solver;
717 727
718 stats = GNUNET_STATISTICS_create("ats", 728 stats = GNUNET_STATISTICS_create ("ats",
719 cfg); 729 cfg);
720 if (GNUNET_SYSERR == 730 if (GNUNET_SYSERR ==
721 GNUNET_CONFIGURATION_get_value_string(cfg, 731 GNUNET_CONFIGURATION_get_value_string (cfg,
722 "ats", 732 "ats",
723 "SOLVER", 733 "SOLVER",
724 &solver)) 734 &solver))
725 { 735 {
726 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 736 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
727 "No ATS solver configured, using 'simple' approach\n"); 737 "No ATS solver configured, using 'simple' approach\n");
728 solver = GNUNET_strdup("simple"); 738 solver = GNUNET_strdup ("simple");
729 } 739 }
730 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, 740 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
731 NULL); 741 NULL);
732 env.cls = NULL; 742 env.cls = NULL;
733 env.cfg = cfg; 743 env.cfg = cfg;
734 env.stats = stats; 744 env.stats = stats;
735 env.suggest_cb = &suggest_cb; 745 env.suggest_cb = &suggest_cb;
736 env.allocate_cb = &allocate_cb; 746 env.allocate_cb = &allocate_cb;
737 GNUNET_asprintf(&plugin_name, 747 GNUNET_asprintf (&plugin_name,
738 "libgnunet_plugin_ats2_%s", 748 "libgnunet_plugin_ats2_%s",
739 solver); 749 solver);
740 GNUNET_free(solver); 750 GNUNET_free (solver);
741 if (NULL == (plugin = GNUNET_PLUGIN_load(plugin_name, 751 if (NULL == (plugin = GNUNET_PLUGIN_load (plugin_name,
742 &env))) 752 &env)))
743 { 753 {
744 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 754 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
745 _("Failed to initialize solver `%s'!\n"), 755 _ ("Failed to initialize solver `%s'!\n"),
746 plugin_name); 756 plugin_name);
747 GNUNET_SCHEDULER_shutdown(); 757 GNUNET_SCHEDULER_shutdown ();
748 return; 758 return;
749 } 759 }
750} 760}
751 761
752 762
@@ -760,35 +770,35 @@ GNUNET_SERVICE_MAIN
760 &client_connect_cb, 770 &client_connect_cb,
761 &client_disconnect_cb, 771 &client_disconnect_cb,
762 NULL, 772 NULL,
763 GNUNET_MQ_hd_fixed_size(suggest, 773 GNUNET_MQ_hd_fixed_size (suggest,
764 GNUNET_MESSAGE_TYPE_ATS_SUGGEST, 774 GNUNET_MESSAGE_TYPE_ATS_SUGGEST,
765 struct ExpressPreferenceMessage, 775 struct ExpressPreferenceMessage,
766 NULL), 776 NULL),
767 GNUNET_MQ_hd_fixed_size(suggest_cancel, 777 GNUNET_MQ_hd_fixed_size (suggest_cancel,
768 GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, 778 GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL,
769 struct ExpressPreferenceMessage, 779 struct ExpressPreferenceMessage,
770 NULL), 780 NULL),
771 GNUNET_MQ_hd_fixed_size(start, 781 GNUNET_MQ_hd_fixed_size (start,
772 GNUNET_MESSAGE_TYPE_ATS_START, 782 GNUNET_MESSAGE_TYPE_ATS_START,
773 struct GNUNET_MessageHeader, 783 struct GNUNET_MessageHeader,
774 NULL), 784 NULL),
775 GNUNET_MQ_hd_var_size(session_add, 785 GNUNET_MQ_hd_var_size (session_add,
776 GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, 786 GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD,
777 struct SessionAddMessage, 787 struct SessionAddMessage,
778 NULL), 788 NULL),
779 GNUNET_MQ_hd_var_size(session_add, 789 GNUNET_MQ_hd_var_size (session_add,
780 GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, 790 GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY,
781 struct SessionAddMessage, 791 struct SessionAddMessage,
782 NULL), 792 NULL),
783 GNUNET_MQ_hd_fixed_size(session_update, 793 GNUNET_MQ_hd_fixed_size (session_update,
784 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, 794 GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE,
785 struct SessionUpdateMessage, 795 struct SessionUpdateMessage,
786 NULL), 796 NULL),
787 GNUNET_MQ_hd_fixed_size(session_del, 797 GNUNET_MQ_hd_fixed_size (session_del,
788 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, 798 GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL,
789 struct SessionDelMessage, 799 struct SessionDelMessage,
790 NULL), 800 NULL),
791 GNUNET_MQ_handler_end()); 801 GNUNET_MQ_handler_end ());
792 802
793 803
794/* end of gnunet-service-ats.c */ 804/* end of gnunet-service-ats.c */
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index d9bb71c2b..fbef6f166 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -50,47 +50,47 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
50 * @param msg the start message 50 * @param msg the start message
51 */ 51 */
52static void 52static void
53handle_ats_start(void *cls, 53handle_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))
64 { 68 {
65 case START_FLAG_SCHEDULING: 69 GNUNET_SERVICE_client_drop (client);
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);
91 return; 70 return;
92 } 71 }
93 GNUNET_SERVICE_client_continue(client); 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);
91 return;
92 }
93 GNUNET_SERVICE_client_continue (client);
94} 94}
95 95
96 96
@@ -102,14 +102,14 @@ handle_ats_start(void *cls,
102 * @param message the request message 102 * @param message the request message
103 */ 103 */
104static void 104static void
105handle_reservation_request(void *cls, 105handle_reservation_request (void *cls,
106 const struct ReservationRequestMessage *message) 106 const struct ReservationRequestMessage *message)
107{ 107{
108 struct GNUNET_SERVICE_Client *client = cls; 108 struct GNUNET_SERVICE_Client *client = cls;
109 109
110 GAS_handle_reservation_request(client, 110 GAS_handle_reservation_request (client,
111 message); 111 message);
112 GNUNET_SERVICE_client_continue(client); 112 GNUNET_SERVICE_client_continue (client);
113} 113}
114 114
115 115
@@ -121,23 +121,23 @@ handle_reservation_request(void *cls,
121 * @return #GNUNET_OK if @a message is well-formed 121 * @return #GNUNET_OK if @a message is well-formed
122 */ 122 */
123static int 123static int
124check_feedback(void *cls, 124check_feedback (void *cls,
125 const struct FeedbackPreferenceMessage *message) 125 const struct FeedbackPreferenceMessage *message)
126{ 126{
127 uint16_t msize; 127 uint16_t msize;
128 uint32_t nump; 128 uint32_t nump;
129 129
130 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Received PREFERENCE_FEEDBACK message\n"); 131 "Received PREFERENCE_FEEDBACK message\n");
132 msize = ntohs(message->header.size); 132 msize = ntohs (message->header.size);
133 nump = ntohl(message->num_feedback); 133 nump = ntohl (message->num_feedback);
134 if (msize != 134 if (msize !=
135 sizeof(struct FeedbackPreferenceMessage) + 135 sizeof(struct FeedbackPreferenceMessage)
136 nump * sizeof(struct PreferenceInformation)) 136 + nump * sizeof(struct PreferenceInformation))
137 { 137 {
138 GNUNET_break(0); 138 GNUNET_break (0);
139 return GNUNET_SYSERR; 139 return GNUNET_SYSERR;
140 } 140 }
141 return GNUNET_OK; 141 return GNUNET_OK;
142} 142}
143 143
@@ -149,42 +149,43 @@ check_feedback(void *cls,
149 * @param msg the request message 149 * @param msg the request message
150 */ 150 */
151static void 151static void
152handle_feedback(void *cls, 152handle_feedback (void *cls,
153 const struct FeedbackPreferenceMessage *msg) 153 const struct FeedbackPreferenceMessage *msg)
154{ 154{
155 struct GNUNET_SERVICE_Client *client = cls; 155 struct GNUNET_SERVICE_Client *client = cls;
156 const struct PreferenceInformation *pi; 156 const struct PreferenceInformation *pi;
157 uint32_t nump; 157 uint32_t nump;
158 158
159 nump = ntohl(msg->num_feedback); 159 nump = ntohl (msg->num_feedback);
160 if (GNUNET_NO == 160 if (GNUNET_NO ==
161 GNUNET_CONTAINER_multipeermap_contains(GSA_addresses, 161 GNUNET_CONTAINER_multipeermap_contains (GSA_addresses,
162 &msg->peer)) 162 &msg->peer))
163 { 163 {
164 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 164 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
165 "Received PREFERENCE FEEDBACK for unknown peer `%s'\n", 165 "Received PREFERENCE FEEDBACK for unknown peer `%s'\n",
166 GNUNET_i2s(&msg->peer)); 166 GNUNET_i2s (&msg->peer));
167 GNUNET_SERVICE_client_continue(client); 167 GNUNET_SERVICE_client_continue (client);
168 return; 168 return;
169 } 169 }
170 170
171 GNUNET_STATISTICS_update(GSA_stats, 171 GNUNET_STATISTICS_update (GSA_stats,
172 "# preference feedbacks requests processed", 172 "# preference feedbacks requests processed",
173 1, 173 1,
174 GNUNET_NO); 174 GNUNET_NO);
175 pi = (const struct PreferenceInformation *)&msg[1]; 175 pi = (const struct PreferenceInformation *) &msg[1];
176 for (uint32_t i = 0; i < nump; i++) 176 for (uint32_t i = 0; i < nump; i++)
177 { 177 {
178 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
179 "Received PREFERENCE FEEDBACK for peer `%s'\n", 179 "Received PREFERENCE FEEDBACK for peer `%s'\n",
180 GNUNET_i2s(&msg->peer)); 180 GNUNET_i2s (&msg->peer));
181 GAS_plugin_notify_feedback(client, 181 GAS_plugin_notify_feedback (client,
182 &msg->peer, 182 &msg->peer,
183 GNUNET_TIME_relative_ntoh(msg->scope), 183 GNUNET_TIME_relative_ntoh (msg->scope),
184 (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind), 184 (enum GNUNET_ATS_PreferenceKind) ntohl (
185 pi[i].preference_value); 185 pi[i].preference_kind),
186 } 186 pi[i].preference_value);
187 GNUNET_SERVICE_client_continue(client); 187 }
188 GNUNET_SERVICE_client_continue (client);
188} 189}
189 190
190 191
@@ -195,14 +196,14 @@ handle_feedback(void *cls,
195 * @param message the request message 196 * @param message the request message
196 */ 197 */
197static void 198static void
198handle_request_address_list(void *cls, 199handle_request_address_list (void *cls,
199 const struct AddressListRequestMessage *message) 200 const struct AddressListRequestMessage *message)
200{ 201{
201 struct GNUNET_SERVICE_Client *client = cls; 202 struct GNUNET_SERVICE_Client *client = cls;
202 203
203 GAS_handle_request_address_list(client, 204 GAS_handle_request_address_list (client,
204 message); 205 message);
205 GNUNET_SERVICE_client_continue(client); 206 GNUNET_SERVICE_client_continue (client);
206} 207}
207 208
208 209
@@ -213,14 +214,14 @@ handle_request_address_list(void *cls,
213 * @param message the request message 214 * @param message the request message
214 */ 215 */
215static void 216static void
216handle_request_address(void *cls, 217handle_request_address (void *cls,
217 const struct RequestAddressMessage * message) 218 const struct RequestAddressMessage *message)
218{ 219{
219 struct GNUNET_SERVICE_Client *client = cls; 220 struct GNUNET_SERVICE_Client *client = cls;
220 221
221 GAS_handle_request_address(client, 222 GAS_handle_request_address (client,
222 message); 223 message);
223 GNUNET_SERVICE_client_continue(client); 224 GNUNET_SERVICE_client_continue (client);
224} 225}
225 226
226 227
@@ -231,14 +232,14 @@ handle_request_address(void *cls,
231 * @param message the request message 232 * @param message the request message
232 */ 233 */
233static void 234static void
234handle_request_address_cancel(void *cls, 235handle_request_address_cancel (void *cls,
235 const struct RequestAddressMessage *message) 236 const struct RequestAddressMessage *message)
236{ 237{
237 struct GNUNET_SERVICE_Client *client = cls; 238 struct GNUNET_SERVICE_Client *client = cls;
238 239
239 GAS_handle_request_address_cancel(client, 240 GAS_handle_request_address_cancel (client,
240 message); 241 message);
241 GNUNET_SERVICE_client_continue(client); 242 GNUNET_SERVICE_client_continue (client);
242} 243}
243 244
244 245
@@ -249,8 +250,8 @@ handle_request_address_cancel(void *cls,
249 * @param m the request message 250 * @param m the request message
250 */ 251 */
251static int 252static int
252check_address_add(void *cls, 253check_address_add (void *cls,
253 const struct AddressAddMessage *m) 254 const struct AddressAddMessage *m)
254{ 255{
255 const char *address; 256 const char *address;
256 const char *plugin_name; 257 const char *plugin_name;
@@ -258,23 +259,23 @@ check_address_add(void *cls,
258 uint16_t plugin_name_length; 259 uint16_t plugin_name_length;
259 uint16_t size; 260 uint16_t size;
260 261
261 size = ntohs(m->header.size); 262 size = ntohs (m->header.size);
262 address_length = ntohs(m->address_length); 263 address_length = ntohs (m->address_length);
263 plugin_name_length = ntohs(m->plugin_name_length); 264 plugin_name_length = ntohs (m->plugin_name_length);
264 address = (const char *)&m[1]; 265 address = (const char *) &m[1];
265 if (plugin_name_length != 0) 266 if (plugin_name_length != 0)
266 plugin_name = &address[address_length]; 267 plugin_name = &address[address_length];
267 else 268 else
268 plugin_name = ""; 269 plugin_name = "";
269 270
270 if ((address_length + plugin_name_length + 271 if ((address_length + plugin_name_length
271 sizeof(struct AddressAddMessage) != size) || 272 + sizeof(struct AddressAddMessage) != size) ||
272 ((plugin_name_length > 0) && 273 ((plugin_name_length > 0) &&
273 (plugin_name[plugin_name_length - 1] != '\0'))) 274 (plugin_name[plugin_name_length - 1] != '\0')))
274 { 275 {
275 GNUNET_break(0); 276 GNUNET_break (0);
276 return GNUNET_SYSERR; 277 return GNUNET_SYSERR;
277 } 278 }
278 return GNUNET_OK; 279 return GNUNET_OK;
279} 280}
280 281
@@ -286,13 +287,13 @@ check_address_add(void *cls,
286 * @param message the request message 287 * @param message the request message
287 */ 288 */
288static void 289static void
289handle_address_add(void *cls, 290handle_address_add (void *cls,
290 const struct AddressAddMessage *message) 291 const struct AddressAddMessage *message)
291{ 292{
292 struct GNUNET_SERVICE_Client *client = cls; 293 struct GNUNET_SERVICE_Client *client = cls;
293 294
294 GAS_handle_address_add(message); 295 GAS_handle_address_add (message);
295 GNUNET_SERVICE_client_continue(client); 296 GNUNET_SERVICE_client_continue (client);
296} 297}
297 298
298 299
@@ -303,13 +304,13 @@ handle_address_add(void *cls,
303 * @param message the request message 304 * @param message the request message
304 */ 305 */
305static void 306static void
306handle_address_update(void *cls, 307handle_address_update (void *cls,
307 const struct AddressUpdateMessage *message) 308 const struct AddressUpdateMessage *message)
308{ 309{
309 struct GNUNET_SERVICE_Client *client = cls; 310 struct GNUNET_SERVICE_Client *client = cls;
310 311
311 GAS_handle_address_update(message); 312 GAS_handle_address_update (message);
312 GNUNET_SERVICE_client_continue(client); 313 GNUNET_SERVICE_client_continue (client);
313} 314}
314 315
315 316
@@ -320,13 +321,13 @@ handle_address_update(void *cls,
320 * @param message the request message 321 * @param message the request message
321 */ 322 */
322static void 323static void
323handle_address_destroyed(void *cls, 324handle_address_destroyed (void *cls,
324 const struct AddressDestroyedMessage *message) 325 const struct AddressDestroyedMessage *message)
325{ 326{
326 struct GNUNET_SERVICE_Client *client = cls; 327 struct GNUNET_SERVICE_Client *client = cls;
327 328
328 GAS_handle_address_destroyed(message); 329 GAS_handle_address_destroyed (message);
329 GNUNET_SERVICE_client_continue(client); 330 GNUNET_SERVICE_client_continue (client);
330} 331}
331 332
332 333
@@ -338,22 +339,22 @@ handle_address_destroyed(void *cls,
338 * @return #GNUNET_OK if @a message is well-formed 339 * @return #GNUNET_OK if @a message is well-formed
339 */ 340 */
340static int 341static int
341check_preference_change(void *cls, 342check_preference_change (void *cls,
342 const struct ChangePreferenceMessage *message) 343 const struct ChangePreferenceMessage *message)
343{ 344{
344 uint16_t msize; 345 uint16_t msize;
345 uint32_t nump; 346 uint32_t nump;
346 347
347 msize = ntohs(message->header.size); 348 msize = ntohs (message->header.size);
348 nump = ntohl(message->num_preferences); 349 nump = ntohl (message->num_preferences);
349 if ((msize != 350 if ((msize !=
350 sizeof(struct ChangePreferenceMessage) + 351 sizeof(struct ChangePreferenceMessage)
351 nump * sizeof(struct PreferenceInformation)) || 352 + nump * sizeof(struct PreferenceInformation)) ||
352 (UINT16_MAX / sizeof(struct PreferenceInformation) < nump)) 353 (UINT16_MAX / sizeof(struct PreferenceInformation) < nump))
353 { 354 {
354 GNUNET_break(0); 355 GNUNET_break (0);
355 return GNUNET_SYSERR; 356 return GNUNET_SYSERR;
356 } 357 }
357 return GNUNET_OK; 358 return GNUNET_OK;
358} 359}
359 360
@@ -365,14 +366,14 @@ check_preference_change(void *cls,
365 * @param message the request message 366 * @param message the request message
366 */ 367 */
367static void 368static void
368handle_preference_change(void *cls, 369handle_preference_change (void *cls,
369 const struct ChangePreferenceMessage *message) 370 const struct ChangePreferenceMessage *message)
370{ 371{
371 struct GNUNET_SERVICE_Client *client = cls; 372 struct GNUNET_SERVICE_Client *client = cls;
372 373
373 GAS_handle_preference_change(client, 374 GAS_handle_preference_change (client,
374 message); 375 message);
375 GNUNET_SERVICE_client_continue(client); 376 GNUNET_SERVICE_client_continue (client);
376} 377}
377 378
378 379
@@ -386,9 +387,9 @@ handle_preference_change(void *cls,
386 * @return @a client 387 * @return @a client
387 */ 388 */
388static void * 389static void *
389client_connect_cb(void *cls, 390client_connect_cb (void *cls,
390 struct GNUNET_SERVICE_Client *client, 391 struct GNUNET_SERVICE_Client *client,
391 struct GNUNET_MQ_Handle *mq) 392 struct GNUNET_MQ_Handle *mq)
392{ 393{
393 return client; 394 return client;
394} 395}
@@ -403,15 +404,15 @@ client_connect_cb(void *cls,
403 * @param app_ctx 404 * @param app_ctx
404 */ 405 */
405static void 406static void
406client_disconnect_cb(void *cls, 407client_disconnect_cb (void *cls,
407 struct GNUNET_SERVICE_Client *client, 408 struct GNUNET_SERVICE_Client *client,
408 void *app_ctx) 409 void *app_ctx)
409{ 410{
410 if (NULL == client) 411 if (NULL == client)
411 return; 412 return;
412 GAS_scheduling_remove_client(client); 413 GAS_scheduling_remove_client (client);
413 GAS_connectivity_remove_client(client); 414 GAS_connectivity_remove_client (client);
414 GAS_preference_client_disconnect(client); 415 GAS_preference_client_disconnect (client);
415} 416}
416 417
417 418
@@ -421,22 +422,22 @@ client_disconnect_cb(void *cls,
421 * @param cls unused 422 * @param cls unused
422 */ 423 */
423static void 424static void
424cleanup_task(void *cls) 425cleanup_task (void *cls)
425{ 426{
426 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
427 "ATS shutdown initiated\n"); 428 "ATS shutdown initiated\n");
428 GAS_connectivity_done(); 429 GAS_connectivity_done ();
429 GAS_addresses_done(); 430 GAS_addresses_done ();
430 GAS_plugin_done(); 431 GAS_plugin_done ();
431 GAS_normalization_stop(); 432 GAS_normalization_stop ();
432 GAS_performance_done(); 433 GAS_performance_done ();
433 GAS_preference_done(); 434 GAS_preference_done ();
434 GAS_reservations_done(); 435 GAS_reservations_done ();
435 if (NULL != GSA_stats) 436 if (NULL != GSA_stats)
436 { 437 {
437 GNUNET_STATISTICS_destroy(GSA_stats, GNUNET_NO); 438 GNUNET_STATISTICS_destroy (GSA_stats, GNUNET_NO);
438 GSA_stats = NULL; 439 GSA_stats = NULL;
439 } 440 }
440} 441}
441 442
442 443
@@ -448,37 +449,37 @@ cleanup_task(void *cls)
448 * @param service the initialized service 449 * @param service the initialized service
449 */ 450 */
450static void 451static void
451run(void *cls, 452run (void *cls,
452 const struct GNUNET_CONFIGURATION_Handle *cfg, 453 const struct GNUNET_CONFIGURATION_Handle *cfg,
453 struct GNUNET_SERVICE_Handle *service) 454 struct GNUNET_SERVICE_Handle *service)
454{ 455{
455 GSA_stats = GNUNET_STATISTICS_create("ats", 456 GSA_stats = GNUNET_STATISTICS_create ("ats",
456 cfg); 457 cfg);
457 GAS_reservations_init(); 458 GAS_reservations_init ();
458 GAS_connectivity_init(); 459 GAS_connectivity_init ();
459 GAS_preference_init(); 460 GAS_preference_init ();
460 GAS_normalization_start(); 461 GAS_normalization_start ();
461 GAS_addresses_init(); 462 GAS_addresses_init ();
462 if (GNUNET_OK != 463 if (GNUNET_OK !=
463 GAS_plugin_init(cfg)) 464 GAS_plugin_init (cfg))
465 {
466 GNUNET_break (0);
467 GAS_addresses_done ();
468 GAS_normalization_stop ();
469 GAS_reservations_done ();
470 GAS_connectivity_done ();
471 GAS_preference_done ();
472 if (NULL != GSA_stats)
464 { 473 {
465 GNUNET_break(0); 474 GNUNET_STATISTICS_destroy (GSA_stats,
466 GAS_addresses_done(); 475 GNUNET_NO);
467 GAS_normalization_stop(); 476 GSA_stats = NULL;
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;
478 } 477 }
479 GAS_performance_init(); 478 return;
480 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, 479 }
481 NULL); 480 GAS_performance_init ();
481 GNUNET_SCHEDULER_add_shutdown (&cleanup_task,
482 NULL);
482} 483}
483 484
484 485
@@ -492,47 +493,47 @@ GNUNET_SERVICE_MAIN
492 &client_connect_cb, 493 &client_connect_cb,
493 &client_disconnect_cb, 494 &client_disconnect_cb,
494 NULL, 495 NULL,
495 GNUNET_MQ_hd_fixed_size(ats_start, 496 GNUNET_MQ_hd_fixed_size (ats_start,
496 GNUNET_MESSAGE_TYPE_ATS_START, 497 GNUNET_MESSAGE_TYPE_ATS_START,
497 struct ClientStartMessage, 498 struct ClientStartMessage,
498 NULL), 499 NULL),
499 GNUNET_MQ_hd_fixed_size(request_address, 500 GNUNET_MQ_hd_fixed_size (request_address,
500 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, 501 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS,
501 struct RequestAddressMessage, 502 struct RequestAddressMessage,
502 NULL), 503 NULL),
503 GNUNET_MQ_hd_fixed_size(request_address_cancel, 504 GNUNET_MQ_hd_fixed_size (request_address_cancel,
504 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL, 505 GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL,
505 struct RequestAddressMessage, 506 struct RequestAddressMessage,
506 NULL), 507 NULL),
507 GNUNET_MQ_hd_fixed_size(request_address_list, 508 GNUNET_MQ_hd_fixed_size (request_address_list,
508 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST, 509 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST,
509 struct AddressListRequestMessage, 510 struct AddressListRequestMessage,
510 NULL), 511 NULL),
511 GNUNET_MQ_hd_var_size(address_add, 512 GNUNET_MQ_hd_var_size (address_add,
512 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD, 513 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD,
513 struct AddressAddMessage, 514 struct AddressAddMessage,
514 NULL), 515 NULL),
515 GNUNET_MQ_hd_fixed_size(address_update, 516 GNUNET_MQ_hd_fixed_size (address_update,
516 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE, 517 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE,
517 struct AddressUpdateMessage, 518 struct AddressUpdateMessage,
518 NULL), 519 NULL),
519 GNUNET_MQ_hd_fixed_size(address_destroyed, 520 GNUNET_MQ_hd_fixed_size (address_destroyed,
520 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED, 521 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED,
521 struct AddressDestroyedMessage, 522 struct AddressDestroyedMessage,
522 NULL), 523 NULL),
523 GNUNET_MQ_hd_fixed_size(reservation_request, 524 GNUNET_MQ_hd_fixed_size (reservation_request,
524 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST, 525 GNUNET_MESSAGE_TYPE_ATS_RESERVATION_REQUEST,
525 struct ReservationRequestMessage, 526 struct ReservationRequestMessage,
526 NULL), 527 NULL),
527 GNUNET_MQ_hd_var_size(preference_change, 528 GNUNET_MQ_hd_var_size (preference_change,
528 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 529 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE,
529 struct ChangePreferenceMessage, 530 struct ChangePreferenceMessage,
530 NULL), 531 NULL),
531 GNUNET_MQ_hd_var_size(feedback, 532 GNUNET_MQ_hd_var_size (feedback,
532 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, 533 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK,
533 struct FeedbackPreferenceMessage, 534 struct FeedbackPreferenceMessage,
534 NULL), 535 NULL),
535 GNUNET_MQ_handler_end()); 536 GNUNET_MQ_handler_end ());
536 537
537 538
538/* end of gnunet-service-ats.c */ 539/* end of gnunet-service-ats.c */
diff --git a/src/ats/gnunet-service-ats.h b/src/ats/gnunet-service-ats.h
index 6abe57fdb..85d522b9f 100644
--- a/src/ats/gnunet-service-ats.h
+++ b/src/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 8ca245b1e..7c73cbf5b 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -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 */
43static void 43static void
44update_addresses_stat() 44update_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 */
58static void 58static void
59free_address(struct ATS_Address *addr) 59free_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 */
86static void 86static void
87init_norm(struct GAS_NormalizationInfo *norm) 87init_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 */
107static struct ATS_Address * 107static struct ATS_Address *
108create_address(const struct GNUNET_PeerIdentity *peer, 108create_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,7 +135,8 @@ create_address(const struct GNUNET_PeerIdentity *peer,
135/** 135/**
136 * Closure for #find_address_cb() 136 * Closure for #find_address_cb()
137 */ 137 */
138struct FindAddressContext { 138struct FindAddressContext
139{
139 /** 140 /**
140 * Session Id to look for. 141 * Session Id to look for.
141 */ 142 */
@@ -157,18 +158,18 @@ struct FindAddressContext {
157 * @return #GNUNET_YES to continue, #GNUNET_NO if address is found 158 * @return #GNUNET_YES to continue, #GNUNET_NO if address is found
158 */ 159 */
159static int 160static int
160find_address_cb(void *cls, 161find_address_cb (void *cls,
161 const struct GNUNET_PeerIdentity *key, 162 const struct GNUNET_PeerIdentity *key,
162 void *value) 163 void *value)
163{ 164{
164 struct FindAddressContext *fac = cls; 165 struct FindAddressContext *fac = cls;
165 struct ATS_Address *aa = value; 166 struct ATS_Address *aa = value;
166 167
167 if (aa->session_id == fac->session_id) 168 if (aa->session_id == fac->session_id)
168 { 169 {
169 fac->exact_address = aa; 170 fac->exact_address = aa;
170 return GNUNET_NO; 171 return GNUNET_NO;
171 } 172 }
172 return GNUNET_YES; 173 return GNUNET_YES;
173} 174}
174 175
@@ -181,16 +182,16 @@ find_address_cb(void *cls,
181 * @return an ATS_address or NULL 182 * @return an ATS_address or NULL
182 */ 183 */
183static struct ATS_Address * 184static struct ATS_Address *
184find_exact_address(const struct GNUNET_PeerIdentity *peer, 185find_exact_address (const struct GNUNET_PeerIdentity *peer,
185 uint32_t session_id) 186 uint32_t session_id)
186{ 187{
187 struct FindAddressContext fac; 188 struct FindAddressContext fac;
188 189
189 fac.exact_address = NULL; 190 fac.exact_address = NULL;
190 fac.session_id = session_id; 191 fac.session_id = session_id;
191 GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, 192 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
192 peer, 193 peer,
193 &find_address_cb, &fac); 194 &find_address_cb, &fac);
194 return fac.exact_address; 195 return fac.exact_address;
195} 196}
196 197
@@ -207,58 +208,60 @@ find_exact_address(const struct GNUNET_PeerIdentity *peer,
207 * @param prop performance information for this address 208 * @param prop performance information for this address
208 */ 209 */
209void 210void
210GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, 211GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
211 const char *plugin_name, 212 const char *plugin_name,
212 const void *plugin_addr, 213 const void *plugin_addr,
213 size_t plugin_addr_len, 214 size_t plugin_addr_len,
214 uint32_t local_address_info, 215 uint32_t local_address_info,
215 uint32_t session_id, 216 uint32_t session_id,
216 const struct GNUNET_ATS_Properties *prop) 217 const struct GNUNET_ATS_Properties *prop)
217{ 218{
218 struct ATS_Address *new_address; 219 struct ATS_Address *new_address;
219 220
220 if (NULL != find_exact_address(peer, 221 if (NULL != find_exact_address (peer,
221 session_id)) 222 session_id))
222 { 223 {
223 GNUNET_break(0); 224 GNUNET_break (0);
224 return; 225 return;
225 } 226 }
226 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 227 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
227 new_address = create_address(peer, 228 new_address = create_address (peer,
228 plugin_name, 229 plugin_name,
229 plugin_addr, 230 plugin_addr,
230 plugin_addr_len, 231 plugin_addr_len,
231 local_address_info, 232 local_address_info,
232 session_id); 233 session_id);
233 /* Add a new address */ 234 /* Add a new address */
234 new_address->properties = *prop; 235 new_address->properties = *prop;
235 new_address->t_added = GNUNET_TIME_absolute_get(); 236 new_address->t_added = GNUNET_TIME_absolute_get ();
236 new_address->t_last_activity = GNUNET_TIME_absolute_get(); 237 new_address->t_last_activity = GNUNET_TIME_absolute_get ();
237 GNUNET_assert(GNUNET_OK == 238 GNUNET_assert (GNUNET_OK ==
238 GNUNET_CONTAINER_multipeermap_put(GSA_addresses, 239 GNUNET_CONTAINER_multipeermap_put (GSA_addresses,
239 peer, 240 peer,
240 new_address, 241 new_address,
241 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 242 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
242 update_addresses_stat(); 243 update_addresses_stat ();
243 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 244 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
244 "Adding new address for peer `%s' slot %u\n", 245 "Adding new address for peer `%s' slot %u\n",
245 GNUNET_i2s(peer), 246 GNUNET_i2s (peer),
246 session_id); 247 session_id);
247 /* Tell solver about new address */ 248 /* Tell solver about new address */
248 GAS_plugin_solver_lock(); 249 GAS_plugin_solver_lock ();
249 GAS_plugin_new_address(new_address); 250 GAS_plugin_new_address (new_address);
250 GAS_normalization_update_property(new_address); // FIXME: needed? 251 GAS_normalization_update_property (new_address); // FIXME: needed?
251 GAS_plugin_solver_unlock(); 252 GAS_plugin_solver_unlock ();
252 /* Notify performance clients about new address */ 253 /* Notify performance clients about new address */
253 GAS_performance_notify_all_clients(&new_address->peer, 254 GAS_performance_notify_all_clients (&new_address->peer,
254 new_address->plugin, 255 new_address->plugin,
255 new_address->addr, 256 new_address->addr,
256 new_address->addr_len, 257 new_address->addr_len,
257 new_address->active, 258 new_address->active,
258 &new_address->properties, 259 &new_address->properties,
259 new_address->local_address_info, 260 new_address->local_address_info,
260 GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_out), 261 GNUNET_BANDWIDTH_value_init (
261 GNUNET_BANDWIDTH_value_init(new_address->assigned_bw_in)); 262 new_address->assigned_bw_out),
263 GNUNET_BANDWIDTH_value_init (
264 new_address->assigned_bw_in));
262} 265}
263 266
264 267
@@ -270,45 +273,47 @@ GAS_addresses_add(const struct GNUNET_PeerIdentity *peer,
270 * @param prop performance information for this address 273 * @param prop performance information for this address
271 */ 274 */
272void 275void
273GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, 276GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
274 uint32_t session_id, 277 uint32_t session_id,
275 const struct GNUNET_ATS_Properties *prop) 278 const struct GNUNET_ATS_Properties *prop)
276{ 279{
277 struct ATS_Address *aa; 280 struct ATS_Address *aa;
278 281
279 /* Get existing address */ 282 /* Get existing address */
280 aa = find_exact_address(peer, 283 aa = find_exact_address (peer,
281 session_id); 284 session_id);
282 if (NULL == aa) 285 if (NULL == aa)
283 { 286 {
284 GNUNET_break(0); 287 GNUNET_break (0);
285 return; 288 return;
286 } 289 }
287 if (NULL == aa->solver_information) 290 if (NULL == aa->solver_information)
288 { 291 {
289 GNUNET_break(0); 292 GNUNET_break (0);
290 return; 293 return;
291 } 294 }
292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 "Received ADDRESS_UPDATE for peer `%s' slot %u\n", 296 "Received ADDRESS_UPDATE for peer `%s' slot %u\n",
294 GNUNET_i2s(peer), 297 GNUNET_i2s (peer),
295 (unsigned int)session_id); 298 (unsigned int) session_id);
296 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 299 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
297 /* Update address */ 300 /* Update address */
298 aa->t_last_activity = GNUNET_TIME_absolute_get(); 301 aa->t_last_activity = GNUNET_TIME_absolute_get ();
299 aa->properties = *prop; 302 aa->properties = *prop;
300 /* Notify performance clients about updated address */ 303 /* Notify performance clients about updated address */
301 GAS_performance_notify_all_clients(&aa->peer, 304 GAS_performance_notify_all_clients (&aa->peer,
302 aa->plugin, 305 aa->plugin,
303 aa->addr, 306 aa->addr,
304 aa->addr_len, 307 aa->addr_len,
305 aa->active, 308 aa->active,
306 prop, 309 prop,
307 aa->local_address_info, 310 aa->local_address_info,
308 GNUNET_BANDWIDTH_value_init(aa->assigned_bw_out), 311 GNUNET_BANDWIDTH_value_init (
309 GNUNET_BANDWIDTH_value_init(aa->assigned_bw_in)); 312 aa->assigned_bw_out),
310 313 GNUNET_BANDWIDTH_value_init (
311 GAS_normalization_update_property(aa); 314 aa->assigned_bw_in));
315
316 GAS_normalization_update_property (aa);
312} 317}
313 318
314 319
@@ -319,24 +324,24 @@ GAS_addresses_update(const struct GNUNET_PeerIdentity *peer,
319 * @param session_id session id, can never be 0 324 * @param session_id session id, can never be 0
320 */ 325 */
321void 326void
322GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, 327GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
323 uint32_t session_id) 328 uint32_t session_id)
324{ 329{
325 struct ATS_Address *ea; 330 struct ATS_Address *ea;
326 331
327 /* Get existing address */ 332 /* Get existing address */
328 ea = find_exact_address(peer, 333 ea = find_exact_address (peer,
329 session_id); 334 session_id);
330 if (NULL == ea) 335 if (NULL == ea)
331 { 336 {
332 GNUNET_break(0); 337 GNUNET_break (0);
333 return; 338 return;
334 } 339 }
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "Received ADDRESS_DESTROYED for peer `%s' session %u\n", 341 "Received ADDRESS_DESTROYED for peer `%s' session %u\n",
337 GNUNET_i2s(peer), 342 GNUNET_i2s (peer),
338 session_id); 343 session_id);
339 free_address(ea); 344 free_address (ea);
340} 345}
341 346
342 347
@@ -347,12 +352,12 @@ GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer,
347 * and receives updates when the solver changes the resource allocation. 352 * and receives updates when the solver changes the resource allocation.
348 */ 353 */
349void 354void
350GAS_addresses_init() 355GAS_addresses_init ()
351{ 356{
352 GSA_addresses 357 GSA_addresses
353 = GNUNET_CONTAINER_multipeermap_create(128, 358 = GNUNET_CONTAINER_multipeermap_create (128,
354 GNUNET_NO); 359 GNUNET_NO);
355 update_addresses_stat(); 360 update_addresses_stat ();
356} 361}
357 362
358 363
@@ -365,13 +370,13 @@ GAS_addresses_init()
365 * @return #GNUNET_OK (continue to iterate) 370 * @return #GNUNET_OK (continue to iterate)
366 */ 371 */
367static int 372static int
368destroy_all_address_it(void *cls, 373destroy_all_address_it (void *cls,
369 const struct GNUNET_PeerIdentity *key, 374 const struct GNUNET_PeerIdentity *key,
370 void *value) 375 void *value)
371{ 376{
372 struct ATS_Address *aa = value; 377 struct ATS_Address *aa = value;
373 378
374 free_address(aa); 379 free_address (aa);
375 return GNUNET_OK; 380 return GNUNET_OK;
376} 381}
377 382
@@ -380,18 +385,18 @@ destroy_all_address_it(void *cls,
380 * Remove all addresses 385 * Remove all addresses
381 */ 386 */
382void 387void
383GAS_addresses_destroy_all() 388GAS_addresses_destroy_all ()
384{ 389{
385 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 390 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
386 "Destroying all addresses\n"); 391 "Destroying all addresses\n");
387 if (0 == 392 if (0 ==
388 GNUNET_CONTAINER_multipeermap_size(GSA_addresses)) 393 GNUNET_CONTAINER_multipeermap_size (GSA_addresses))
389 return; 394 return;
390 GAS_plugin_solver_lock(); 395 GAS_plugin_solver_lock ();
391 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, 396 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
392 &destroy_all_address_it, 397 &destroy_all_address_it,
393 NULL); 398 NULL);
394 GAS_plugin_solver_unlock(); 399 GAS_plugin_solver_unlock ();
395} 400}
396 401
397 402
@@ -399,14 +404,14 @@ GAS_addresses_destroy_all()
399 * Shutdown address subsystem. 404 * Shutdown address subsystem.
400 */ 405 */
401void 406void
402GAS_addresses_done() 407GAS_addresses_done ()
403{ 408{
404 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 409 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
405 "Shutting down addresses\n"); 410 "Shutting down addresses\n");
406 GAS_plugin_solver_lock(); 411 GAS_plugin_solver_lock ();
407 GAS_addresses_destroy_all(); 412 GAS_addresses_destroy_all ();
408 GAS_plugin_solver_unlock(); 413 GAS_plugin_solver_unlock ();
409 GNUNET_CONTAINER_multipeermap_destroy(GSA_addresses); 414 GNUNET_CONTAINER_multipeermap_destroy (GSA_addresses);
410 GSA_addresses = NULL; 415 GSA_addresses = NULL;
411} 416}
412 417
@@ -414,7 +419,8 @@ GAS_addresses_done()
414/** 419/**
415 * Closure for #peerinfo_it(). 420 * Closure for #peerinfo_it().
416 */ 421 */
417struct PeerInfoIteratorContext { 422struct PeerInfoIteratorContext
423{
418 /** 424 /**
419 * Function to call for each address. 425 * Function to call for each address.
420 */ 426 */
@@ -436,23 +442,23 @@ struct PeerInfoIteratorContext {
436 * @return #GNUNET_OK to continue 442 * @return #GNUNET_OK to continue
437 */ 443 */
438static int 444static int
439peerinfo_it(void *cls, 445peerinfo_it (void *cls,
440 const struct GNUNET_PeerIdentity *key, 446 const struct GNUNET_PeerIdentity *key,
441 void *value) 447 void *value)
442{ 448{
443 struct PeerInfoIteratorContext *pi_ctx = cls; 449 struct PeerInfoIteratorContext *pi_ctx = cls;
444 struct ATS_Address *addr = value; 450 struct ATS_Address *addr = value;
445 451
446 pi_ctx->it(pi_ctx->it_cls, 452 pi_ctx->it (pi_ctx->it_cls,
447 &addr->peer, 453 &addr->peer,
448 addr->plugin, 454 addr->plugin,
449 addr->addr, 455 addr->addr,
450 addr->addr_len, 456 addr->addr_len,
451 addr->active, 457 addr->active,
452 &addr->properties, 458 &addr->properties,
453 addr->local_address_info, 459 addr->local_address_info,
454 GNUNET_BANDWIDTH_value_init(addr->assigned_bw_out), 460 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
455 GNUNET_BANDWIDTH_value_init(addr->assigned_bw_in)); 461 GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
456 return GNUNET_OK; 462 return GNUNET_OK;
457} 463}
458 464
@@ -465,41 +471,42 @@ peerinfo_it(void *cls,
465 * @param pi_it_cls the closure for @a pi_it 471 * @param pi_it_cls the closure for @a pi_it
466 */ 472 */
467void 473void
468GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, 474GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
469 GNUNET_ATS_PeerInfo_Iterator pi_it, 475 GNUNET_ATS_PeerInfo_Iterator pi_it,
470 void *pi_it_cls) 476 void *pi_it_cls)
471{ 477{
472 struct PeerInfoIteratorContext pi_ctx; 478 struct PeerInfoIteratorContext pi_ctx;
473 479
474 if (NULL == pi_it) 480 if (NULL == pi_it)
475 { 481 {
476 /* does not make sense without callback */ 482 /* does not make sense without callback */
477 GNUNET_break(0); 483 GNUNET_break (0);
478 return; 484 return;
479 } 485 }
480 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
481 "Returning information for %s from a total of %u known addresses\n", 487 "Returning information for %s from a total of %u known addresses\n",
482 (NULL == peer) 488 (NULL == peer)
483 ? "all peers" 489 ? "all peers"
484 : GNUNET_i2s(peer), 490 : GNUNET_i2s (peer),
485 (unsigned int)GNUNET_CONTAINER_multipeermap_size(GSA_addresses)); 491 (unsigned int) GNUNET_CONTAINER_multipeermap_size (
492 GSA_addresses));
486 pi_ctx.it = pi_it; 493 pi_ctx.it = pi_it;
487 pi_ctx.it_cls = pi_it_cls; 494 pi_ctx.it_cls = pi_it_cls;
488 if (NULL == peer) 495 if (NULL == peer)
489 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, 496 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
490 &peerinfo_it, 497 &peerinfo_it,
491 &pi_ctx); 498 &pi_ctx);
492 else 499 else
493 GNUNET_CONTAINER_multipeermap_get_multiple(GSA_addresses, 500 GNUNET_CONTAINER_multipeermap_get_multiple (GSA_addresses,
494 peer, 501 peer,
495 &peerinfo_it, &pi_ctx); 502 &peerinfo_it, &pi_ctx);
496 pi_it(pi_it_cls, 503 pi_it (pi_it_cls,
497 NULL, NULL, NULL, 0, 504 NULL, NULL, NULL, 0,
498 GNUNET_NO, 505 GNUNET_NO,
499 NULL, 506 NULL,
500 GNUNET_HELLO_ADDRESS_INFO_NONE, 507 GNUNET_HELLO_ADDRESS_INFO_NONE,
501 GNUNET_BANDWIDTH_ZERO, 508 GNUNET_BANDWIDTH_ZERO,
502 GNUNET_BANDWIDTH_ZERO); 509 GNUNET_BANDWIDTH_ZERO);
503} 510}
504 511
505 512
@@ -507,7 +514,8 @@ GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer,
507 * Information we need for the callbacks to return a list of addresses 514 * Information we need for the callbacks to return a list of addresses
508 * back to the client. 515 * back to the client.
509 */ 516 */
510struct AddressIteration { 517struct AddressIteration
518{
511 /** 519 /**
512 * Actual handle to the client. 520 * Actual handle to the client.
513 */ 521 */
@@ -541,16 +549,16 @@ struct AddressIteration {
541 * @param bandwidth_in current inbound bandwidth assigned to address 549 * @param bandwidth_in current inbound bandwidth assigned to address
542 */ 550 */
543static void 551static void
544transmit_req_addr(struct AddressIteration *ai, 552transmit_req_addr (struct AddressIteration *ai,
545 const struct GNUNET_PeerIdentity *id, 553 const struct GNUNET_PeerIdentity *id,
546 const char *plugin_name, 554 const char *plugin_name,
547 const void *plugin_addr, 555 const void *plugin_addr,
548 size_t plugin_addr_len, 556 size_t plugin_addr_len,
549 int active, 557 int active,
550 const struct GNUNET_ATS_Properties *prop, 558 const struct GNUNET_ATS_Properties *prop,
551 enum GNUNET_HELLO_AddressInfo local_address_info, 559 enum GNUNET_HELLO_AddressInfo local_address_info,
552 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 560 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
553 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 561 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
554 562
555{ 563{
556 struct GNUNET_MQ_Envelope *env; 564 struct GNUNET_MQ_Envelope *env;
@@ -560,37 +568,37 @@ transmit_req_addr(struct AddressIteration *ai,
560 size_t msize; 568 size_t msize;
561 569
562 if (NULL != plugin_name) 570 if (NULL != plugin_name)
563 plugin_name_length = strlen(plugin_name) + 1; 571 plugin_name_length = strlen (plugin_name) + 1;
564 else 572 else
565 plugin_name_length = 0; 573 plugin_name_length = 0;
566 msize = plugin_addr_len + plugin_name_length; 574 msize = plugin_addr_len + plugin_name_length;
567 575
568 GNUNET_assert(sizeof(struct PeerInformationMessage) + msize 576 GNUNET_assert (sizeof(struct PeerInformationMessage) + msize
569 < GNUNET_MAX_MESSAGE_SIZE); 577 < GNUNET_MAX_MESSAGE_SIZE);
570 env = GNUNET_MQ_msg_extra(msg, 578 env = GNUNET_MQ_msg_extra (msg,
571 msize, 579 msize,
572 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE); 580 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
573 msg->id = htonl(ai->id); 581 msg->id = htonl (ai->id);
574 if (NULL != id) 582 if (NULL != id)
575 msg->peer = *id; 583 msg->peer = *id;
576 msg->address_length = htons(plugin_addr_len); 584 msg->address_length = htons (plugin_addr_len);
577 msg->address_active = ntohl(active); 585 msg->address_active = ntohl (active);
578 msg->plugin_name_length = htons(plugin_name_length); 586 msg->plugin_name_length = htons (plugin_name_length);
579 msg->bandwidth_out = bandwidth_out; 587 msg->bandwidth_out = bandwidth_out;
580 msg->bandwidth_in = bandwidth_in; 588 msg->bandwidth_in = bandwidth_in;
581 if (NULL != prop) 589 if (NULL != prop)
582 GNUNET_ATS_properties_hton(&msg->properties, 590 GNUNET_ATS_properties_hton (&msg->properties,
583 prop); 591 prop);
584 msg->address_local_info = htonl((uint32_t)local_address_info); 592 msg->address_local_info = htonl ((uint32_t) local_address_info);
585 addrp = (char *)&msg[1]; 593 addrp = (char *) &msg[1];
586 GNUNET_memcpy(addrp, 594 GNUNET_memcpy (addrp,
587 plugin_addr, 595 plugin_addr,
588 plugin_addr_len); 596 plugin_addr_len);
589 if (NULL != plugin_name) 597 if (NULL != plugin_name)
590 strcpy(&addrp[plugin_addr_len], 598 strcpy (&addrp[plugin_addr_len],
591 plugin_name); 599 plugin_name);
592 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(ai->client), 600 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client),
593 env); 601 env);
594} 602}
595 603
596 604
@@ -610,48 +618,48 @@ transmit_req_addr(struct AddressIteration *ai,
610 * @param bandwidth_in current inbound bandwidth assigned to address 618 * @param bandwidth_in current inbound bandwidth assigned to address
611 */ 619 */
612static void 620static void
613req_addr_peerinfo_it(void *cls, 621req_addr_peerinfo_it (void *cls,
614 const struct GNUNET_PeerIdentity *id, 622 const struct GNUNET_PeerIdentity *id,
615 const char *plugin_name, 623 const char *plugin_name,
616 const void *plugin_addr, 624 const void *plugin_addr,
617 size_t plugin_addr_len, 625 size_t plugin_addr_len,
618 int active, 626 int active,
619 const struct GNUNET_ATS_Properties *prop, 627 const struct GNUNET_ATS_Properties *prop,
620 enum GNUNET_HELLO_AddressInfo local_address_info, 628 enum GNUNET_HELLO_AddressInfo local_address_info,
621 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 629 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
622 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 630 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
623{ 631{
624 struct AddressIteration *ai = cls; 632 struct AddressIteration *ai = cls;
625 633
626 if ((NULL == id) && 634 if ((NULL == id) &&
627 (NULL == plugin_name) && 635 (NULL == plugin_name) &&
628 (NULL == plugin_addr)) 636 (NULL == plugin_addr))
629 { 637 {
630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
631 "Address iteration done for one peer\n"); 639 "Address iteration done for one peer\n");
632 return; 640 return;
633 } 641 }
634 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
635 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", 643 "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
636 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", 644 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
637 GNUNET_i2s(id), 645 GNUNET_i2s (id),
638 plugin_name, 646 plugin_name,
639 (unsigned int)ntohl(bandwidth_out.value__), 647 (unsigned int) ntohl (bandwidth_out.value__),
640 (unsigned int)ntohl(bandwidth_in.value__)); 648 (unsigned int) ntohl (bandwidth_in.value__));
641 /* Transmit result (either if address is active, or if 649 /* Transmit result (either if address is active, or if
642 client wanted all addresses) */ 650 client wanted all addresses) */
643 if ((GNUNET_YES != ai->all) && 651 if ((GNUNET_YES != ai->all) &&
644 (GNUNET_YES != active)) 652 (GNUNET_YES != active))
645 return; 653 return;
646 transmit_req_addr(ai, 654 transmit_req_addr (ai,
647 id, 655 id,
648 plugin_name, 656 plugin_name,
649 plugin_addr, plugin_addr_len, 657 plugin_addr, plugin_addr_len,
650 active, 658 active,
651 prop, 659 prop,
652 local_address_info, 660 local_address_info,
653 bandwidth_out, 661 bandwidth_out,
654 bandwidth_in); 662 bandwidth_in);
655} 663}
656 664
657 665
@@ -662,45 +670,45 @@ req_addr_peerinfo_it(void *cls,
662 * @param alrm the request message 670 * @param alrm the request message
663 */ 671 */
664void 672void
665GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client, 673GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
666 const struct AddressListRequestMessage *alrm) 674 const struct AddressListRequestMessage *alrm)
667{ 675{
668 struct AddressIteration ai; 676 struct AddressIteration ai;
669 struct GNUNET_PeerIdentity allzeros; 677 struct GNUNET_PeerIdentity allzeros;
670 678
671 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
672 "Received ADDRESSLIST_REQUEST message\n"); 680 "Received ADDRESSLIST_REQUEST message\n");
673 ai.all = ntohl(alrm->all); 681 ai.all = ntohl (alrm->all);
674 ai.id = ntohl(alrm->id); 682 ai.id = ntohl (alrm->id);
675 ai.client = client; 683 ai.client = client;
676 684
677 memset(&allzeros, 685 memset (&allzeros,
678 '\0', 686 '\0',
679 sizeof(struct GNUNET_PeerIdentity)); 687 sizeof(struct GNUNET_PeerIdentity));
680 if (0 == GNUNET_is_zero(&alrm->peer)) 688 if (0 == GNUNET_is_zero (&alrm->peer))
681 { 689 {
682 /* Return addresses for all peers */ 690 /* Return addresses for all peers */
683 GAS_addresses_get_peer_info(NULL, 691 GAS_addresses_get_peer_info (NULL,
684 &req_addr_peerinfo_it, 692 &req_addr_peerinfo_it,
685 &ai); 693 &ai);
686 } 694 }
687 else 695 else
688 { 696 {
689 /* Return addresses for a specific peer */ 697 /* Return addresses for a specific peer */
690 GAS_addresses_get_peer_info(&alrm->peer, 698 GAS_addresses_get_peer_info (&alrm->peer,
691 &req_addr_peerinfo_it, 699 &req_addr_peerinfo_it,
692 &ai); 700 &ai);
693 } 701 }
694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "Finished handling `%s' message\n", 703 "Finished handling `%s' message\n",
696 "ADDRESSLIST_REQUEST"); 704 "ADDRESSLIST_REQUEST");
697 transmit_req_addr(&ai, 705 transmit_req_addr (&ai,
698 NULL, NULL, NULL, 706 NULL, NULL, NULL,
699 0, GNUNET_NO, 707 0, GNUNET_NO,
700 NULL, 708 NULL,
701 GNUNET_HELLO_ADDRESS_INFO_NONE, 709 GNUNET_HELLO_ADDRESS_INFO_NONE,
702 GNUNET_BANDWIDTH_ZERO, 710 GNUNET_BANDWIDTH_ZERO,
703 GNUNET_BANDWIDTH_ZERO); 711 GNUNET_BANDWIDTH_ZERO);
704} 712}
705 713
706 714
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index f7dd98b1e..a18cce2c7 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -221,12 +221,14 @@
221/* 221/*
222 * How long will address suggestions blocked after a suggestion 222 * How long will address suggestions blocked after a suggestion
223 */ 223 */
224#define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100) 224#define ATS_BLOCKING_DELTA GNUNET_TIME_relative_multiply ( \
225 GNUNET_TIME_UNIT_MILLISECONDS, 100)
225 226
226/** 227/**
227 * Information provided by ATS normalization 228 * Information provided by ATS normalization
228 */ 229 */
229struct GAS_NormalizationInfo { 230struct GAS_NormalizationInfo
231{
230 /** 232 /**
231 * Next index to use in averaging queue 233 * Next index to use in averaging queue
232 */ 234 */
@@ -252,7 +254,8 @@ struct GAS_NormalizationInfo {
252/** 254/**
253 * Address with additional information 255 * Address with additional information
254 */ 256 */
255struct ATS_Address { 257struct ATS_Address
258{
256 /** 259 /**
257 * Peer ID this address is for. 260 * Peer ID this address is for.
258 */ 261 */
@@ -366,14 +369,14 @@ extern struct GNUNET_CONTAINER_MultiPeerMap *GSA_addresses;
366 * known and current performance information. 369 * known and current performance information.
367 */ 370 */
368void 371void
369GAS_addresses_init(void); 372GAS_addresses_init (void);
370 373
371 374
372/** 375/**
373 * Shutdown address subsystem. 376 * Shutdown address subsystem.
374 */ 377 */
375void 378void
376GAS_addresses_done(void); 379GAS_addresses_done (void);
377 380
378 381
379/** 382/**
@@ -388,13 +391,13 @@ GAS_addresses_done(void);
388 * @param prop performance information for this address 391 * @param prop performance information for this address
389 */ 392 */
390void 393void
391GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, 394GAS_addresses_add (const struct GNUNET_PeerIdentity *peer,
392 const char *plugin_name, 395 const char *plugin_name,
393 const void *plugin_addr, 396 const void *plugin_addr,
394 size_t plugin_addr_len, 397 size_t plugin_addr_len,
395 uint32_t local_address_info, 398 uint32_t local_address_info,
396 uint32_t session_id, 399 uint32_t session_id,
397 const struct GNUNET_ATS_Properties *prop); 400 const struct GNUNET_ATS_Properties *prop);
398 401
399 402
400/** 403/**
@@ -405,9 +408,9 @@ GAS_addresses_add(const struct GNUNET_PeerIdentity *peer,
405 * @param prop performance information for this address 408 * @param prop performance information for this address
406 */ 409 */
407void 410void
408GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, 411GAS_addresses_update (const struct GNUNET_PeerIdentity *peer,
409 uint32_t session_id, 412 uint32_t session_id,
410 const struct GNUNET_ATS_Properties *prop); 413 const struct GNUNET_ATS_Properties *prop);
411 414
412 415
413/** 416/**
@@ -417,15 +420,15 @@ GAS_addresses_update(const struct GNUNET_PeerIdentity *peer,
417 * @param session_id session id, can never be 0 420 * @param session_id session id, can never be 0
418 */ 421 */
419void 422void
420GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, 423GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
421 uint32_t session_id); 424 uint32_t session_id);
422 425
423 426
424/** 427/**
425 * Remove all addresses. 428 * Remove all addresses.
426 */ 429 */
427void 430void
428GAS_addresses_destroy_all(void); 431GAS_addresses_destroy_all (void);
429 432
430 433
431/** 434/**
@@ -450,9 +453,12 @@ typedef void
450 size_t plugin_addr_len, 453 size_t plugin_addr_len,
451 const int address_active, 454 const int address_active,
452 const struct GNUNET_ATS_Properties *prop, 455 const struct GNUNET_ATS_Properties *prop,
453 enum GNUNET_HELLO_AddressInfo local_address_info, 456 enum GNUNET_HELLO_AddressInfo
454 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 457 local_address_info,
455 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 458 struct GNUNET_BANDWIDTH_Value32NBO
459 bandwidth_out,
460 struct GNUNET_BANDWIDTH_Value32NBO
461 bandwidth_in);
456 462
457 463
458/** 464/**
@@ -463,9 +469,9 @@ typedef void
463 * @param pi_it_cls the closure for @a pi_it 469 * @param pi_it_cls the closure for @a pi_it
464 */ 470 */
465void 471void
466GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, 472GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer,
467 GNUNET_ATS_PeerInfo_Iterator pi_it, 473 GNUNET_ATS_PeerInfo_Iterator pi_it,
468 void *pi_it_cls); 474 void *pi_it_cls);
469 475
470 476
471/** 477/**
@@ -475,8 +481,8 @@ GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer,
475 * @param alrm the request message 481 * @param alrm the request message
476 */ 482 */
477void 483void
478GAS_handle_request_address_list(struct GNUNET_SERVICE_Client *client, 484GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
479 const struct AddressListRequestMessage *alrm); 485 const struct AddressListRequestMessage *alrm);
480 486
481 487
482#endif 488#endif
diff --git a/src/ats/gnunet-service-ats_connectivity.c b/src/ats/gnunet-service-ats_connectivity.c
index f71d18e82..05046f007 100644
--- a/src/ats/gnunet-service-ats_connectivity.c
+++ b/src/ats/gnunet-service-ats_connectivity.c
@@ -35,7 +35,8 @@
35/** 35/**
36 * Active connection requests. 36 * Active connection requests.
37 */ 37 */
38struct ConnectionRequest { 38struct ConnectionRequest
39{
39 /** 40 /**
40 * Client that made the request. 41 * Client that made the request.
41 */ 42 */
@@ -60,14 +61,14 @@ static struct GNUNET_CONTAINER_MultiPeerMap *connection_requests;
60 * @return #GNUNET_YES if so, #GNUNET_NO if not 61 * @return #GNUNET_YES if so, #GNUNET_NO if not
61 */ 62 */
62unsigned int 63unsigned int
63GAS_connectivity_has_peer(void *cls, 64GAS_connectivity_has_peer (void *cls,
64 const struct GNUNET_PeerIdentity *peer) 65 const struct GNUNET_PeerIdentity *peer)
65{ 66{
66 if (NULL == connection_requests) 67 if (NULL == connection_requests)
67 return 0; 68 return 0;
68 /* TODO: return sum of 'strength's of connectivity requests */ 69 /* TODO: return sum of 'strength's of connectivity requests */
69 return GNUNET_CONTAINER_multipeermap_contains(connection_requests, 70 return GNUNET_CONTAINER_multipeermap_contains (connection_requests,
70 peer); 71 peer);
71} 72}
72 73
73 74
@@ -78,22 +79,22 @@ GAS_connectivity_has_peer(void *cls,
78 * @param message the request message 79 * @param message the request message
79 */ 80 */
80void 81void
81GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, 82GAS_handle_request_address (struct GNUNET_SERVICE_Client *client,
82 const struct RequestAddressMessage *msg) 83 const struct RequestAddressMessage *msg)
83{ 84{
84 struct ConnectionRequest *cr; 85 struct ConnectionRequest *cr;
85 86
86 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 "Received `%s' message\n", 88 "Received `%s' message\n",
88 "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS"); 89 "GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS");
89 /* FIXME: should not ignore "msg->strength" */ 90 /* FIXME: should not ignore "msg->strength" */
90 cr = GNUNET_new(struct ConnectionRequest); 91 cr = GNUNET_new (struct ConnectionRequest);
91 cr->client = client; 92 cr->client = client;
92 (void)GNUNET_CONTAINER_multipeermap_put(connection_requests, 93 (void) GNUNET_CONTAINER_multipeermap_put (connection_requests,
93 &msg->peer, 94 &msg->peer,
94 cr, 95 cr,
95 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 96 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
96 GAS_plugin_request_connect_start(&msg->peer); 97 GAS_plugin_request_connect_start (&msg->peer);
97} 98}
98 99
99 100
@@ -107,25 +108,25 @@ GAS_handle_request_address(struct GNUNET_SERVICE_Client *client,
107 * @return #GNUNET_OK (continue to iterate) 108 * @return #GNUNET_OK (continue to iterate)
108 */ 109 */
109static int 110static int
110free_matching_requests(void *cls, 111free_matching_requests (void *cls,
111 const struct GNUNET_PeerIdentity *pid, 112 const struct GNUNET_PeerIdentity *pid,
112 void *value) 113 void *value)
113{ 114{
114 struct GNUNET_SERVICE_Client *client = cls; 115 struct GNUNET_SERVICE_Client *client = cls;
115 struct ConnectionRequest *cr = value; 116 struct ConnectionRequest *cr = value;
116 117
117 if (cr->client == client) 118 if (cr->client == client)
118 { 119 {
119 GAS_plugin_request_connect_stop(pid); 120 GAS_plugin_request_connect_stop (pid);
120 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
121 "Removed request pending for peer `%s\n", 122 "Removed request pending for peer `%s\n",
122 GNUNET_i2s(pid)); 123 GNUNET_i2s (pid));
123 GNUNET_assert(GNUNET_YES == 124 GNUNET_assert (GNUNET_YES ==
124 GNUNET_CONTAINER_multipeermap_remove(connection_requests, 125 GNUNET_CONTAINER_multipeermap_remove (connection_requests,
125 pid, 126 pid,
126 cr)); 127 cr));
127 GNUNET_free(cr); 128 GNUNET_free (cr);
128 } 129 }
129 return GNUNET_OK; 130 return GNUNET_OK;
130} 131}
131 132
@@ -138,17 +139,17 @@ free_matching_requests(void *cls,
138 * @param msg the request message 139 * @param msg the request message
139 */ 140 */
140void 141void
141GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, 142GAS_handle_request_address_cancel (struct GNUNET_SERVICE_Client *client,
142 const struct RequestAddressMessage *msg) 143 const struct RequestAddressMessage *msg)
143{ 144{
144 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
145 "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n", 146 "Received GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS_CANCEL message for peer %s\n",
146 GNUNET_i2s(&msg->peer)); 147 GNUNET_i2s (&msg->peer));
147 GNUNET_break(0 == ntohl(msg->strength)); 148 GNUNET_break (0 == ntohl (msg->strength));
148 GNUNET_CONTAINER_multipeermap_get_multiple(connection_requests, 149 GNUNET_CONTAINER_multipeermap_get_multiple (connection_requests,
149 &msg->peer, 150 &msg->peer,
150 &free_matching_requests, 151 &free_matching_requests,
151 client); 152 client);
152} 153}
153 154
154 155
@@ -159,11 +160,11 @@ GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client,
159 * @param client handle of the (now dead) client 160 * @param client handle of the (now dead) client
160 */ 161 */
161void 162void
162GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client) 163GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client)
163{ 164{
164 GNUNET_CONTAINER_multipeermap_iterate(connection_requests, 165 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
165 &free_matching_requests, 166 &free_matching_requests,
166 client); 167 client);
167} 168}
168 169
169 170
@@ -171,11 +172,11 @@ GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client)
171 * Shutdown connectivity subsystem. 172 * Shutdown connectivity subsystem.
172 */ 173 */
173void 174void
174GAS_connectivity_init() 175GAS_connectivity_init ()
175{ 176{
176 connection_requests 177 connection_requests
177 = GNUNET_CONTAINER_multipeermap_create(32, 178 = GNUNET_CONTAINER_multipeermap_create (32,
178 GNUNET_NO); 179 GNUNET_NO);
179} 180}
180 181
181 182
@@ -188,15 +189,15 @@ GAS_connectivity_init()
188 * @return #GNUNET_OK (continue to iterate) 189 * @return #GNUNET_OK (continue to iterate)
189 */ 190 */
190static int 191static int
191free_request(void *cls, 192free_request (void *cls,
192 const struct GNUNET_PeerIdentity *pid, 193 const struct GNUNET_PeerIdentity *pid,
193 void *value) 194 void *value)
194{ 195{
195 struct ConnectionRequest *cr = value; 196 struct ConnectionRequest *cr = value;
196 197
197 free_matching_requests(cr->client, 198 free_matching_requests (cr->client,
198 pid, 199 pid,
199 cr); 200 cr);
200 return GNUNET_OK; 201 return GNUNET_OK;
201} 202}
202 203
@@ -205,14 +206,14 @@ free_request(void *cls,
205 * Shutdown connectivity subsystem. 206 * Shutdown connectivity subsystem.
206 */ 207 */
207void 208void
208GAS_connectivity_done() 209GAS_connectivity_done ()
209{ 210{
210 GAS_plugin_solver_lock(); 211 GAS_plugin_solver_lock ();
211 GNUNET_CONTAINER_multipeermap_iterate(connection_requests, 212 GNUNET_CONTAINER_multipeermap_iterate (connection_requests,
212 &free_request, 213 &free_request,
213 NULL); 214 NULL);
214 GAS_plugin_solver_unlock(); 215 GAS_plugin_solver_unlock ();
215 GNUNET_CONTAINER_multipeermap_destroy(connection_requests); 216 GNUNET_CONTAINER_multipeermap_destroy (connection_requests);
216 connection_requests = NULL; 217 connection_requests = NULL;
217} 218}
218 219
diff --git a/src/ats/gnunet-service-ats_connectivity.h b/src/ats/gnunet-service-ats_connectivity.h
index 98d84b44a..39453dfc8 100644
--- a/src/ats/gnunet-service-ats_connectivity.h
+++ b/src/ats/gnunet-service-ats_connectivity.h
@@ -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 */
40unsigned int 40unsigned int
41GAS_connectivity_has_peer(void *cls, 41GAS_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 */
51void 51void
52GAS_handle_request_address(struct GNUNET_SERVICE_Client *client, 52GAS_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 */
62void 62void
63GAS_handle_request_address_cancel(struct GNUNET_SERVICE_Client *client, 63GAS_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 */
73void 73void
74GAS_connectivity_remove_client(struct GNUNET_SERVICE_Client *client); 74GAS_connectivity_remove_client (struct GNUNET_SERVICE_Client *client);
75 75
76 76
77/** 77/**
78 * Initialize connectivity subsystem. 78 * Initialize connectivity subsystem.
79 */ 79 */
80void 80void
81GAS_connectivity_init(void); 81GAS_connectivity_init (void);
82 82
83 83
84/** 84/**
85 * Shutdown connectivity subsystem. 85 * Shutdown connectivity subsystem.
86 */ 86 */
87void 87void
88GAS_connectivity_done(void); 88GAS_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 fa2b37425..36584e944 100644
--- a/src/ats/gnunet-service-ats_normalization.c
+++ b/src/ats/gnunet-service-ats_normalization.c
@@ -31,13 +31,14 @@
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 */
40struct PropertyRange { 40struct PropertyRange
41{
41 /** 42 /**
42 * Minimum value we see for this property across all addresses. 43 * Minimum value we see for this property across all addresses.
43 */ 44 */
@@ -64,8 +65,8 @@ static struct PropertyRange property_range;
64 * @param ni normalization information to update 65 * @param ni normalization information to update
65 */ 66 */
66static void 67static void
67update_avg(uint64_t current_val, 68update_avg (uint64_t current_val,
68 struct GAS_NormalizationInfo *ni) 69 struct GAS_NormalizationInfo *ni)
69{ 70{
70 double sum; 71 double sum;
71 uint32_t count; 72 uint32_t count;
@@ -77,13 +78,13 @@ update_avg(uint64_t current_val,
77 count = 0; 78 count = 0;
78 sum = 0.0; 79 sum = 0.0;
79 for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) 80 for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
81 {
82 if (UINT64_MAX != ni->atsi_abs[c1])
80 { 83 {
81 if (UINT64_MAX != ni->atsi_abs[c1]) 84 count++;
82 { 85 sum += (double) ni->atsi_abs[c1];
83 count++;
84 sum += (double)ni->atsi_abs[c1];
85 }
86 } 86 }
87 }
87 if (0 == count) 88 if (0 == count)
88 ni->avg = current_val; /* must be UINT64_MAX */ 89 ni->avg = current_val; /* must be UINT64_MAX */
89 else 90 else
@@ -102,29 +103,29 @@ update_avg(uint64_t current_val,
102 * @return #GNUNET_OK (continue to iterate) 103 * @return #GNUNET_OK (continue to iterate)
103 */ 104 */
104static int 105static int
105find_min_max_it(void *cls, 106find_min_max_it (void *cls,
106 const struct GNUNET_PeerIdentity *h, 107 const struct GNUNET_PeerIdentity *h,
107 void *k) 108 void *k)
108{ 109{
109 struct PropertyRange *pr = cls; 110 struct PropertyRange *pr = cls;
110 const struct ATS_Address *a = k; 111 const struct ATS_Address *a = k;
111 112
112 pr->max.utilization_out = GNUNET_MAX(pr->max.utilization_out, 113 pr->max.utilization_out = GNUNET_MAX (pr->max.utilization_out,
113 a->properties.utilization_out); 114 a->properties.utilization_out);
114 pr->max.utilization_in = GNUNET_MAX(pr->max.utilization_in, 115 pr->max.utilization_in = GNUNET_MAX (pr->max.utilization_in,
115 a->properties.utilization_in); 116 a->properties.utilization_in);
116 pr->max.distance = GNUNET_MAX(pr->max.distance, 117 pr->max.distance = GNUNET_MAX (pr->max.distance,
117 a->properties.distance); 118 a->properties.distance);
118 pr->max.delay = GNUNET_TIME_relative_max(pr->max.delay, 119 pr->max.delay = GNUNET_TIME_relative_max (pr->max.delay,
119 a->properties.delay); 120 a->properties.delay);
120 pr->min.utilization_out = GNUNET_MIN(pr->min.utilization_out, 121 pr->min.utilization_out = GNUNET_MIN (pr->min.utilization_out,
121 a->properties.utilization_out); 122 a->properties.utilization_out);
122 pr->min.utilization_in = GNUNET_MIN(pr->min.utilization_in, 123 pr->min.utilization_in = GNUNET_MIN (pr->min.utilization_in,
123 a->properties.utilization_in); 124 a->properties.utilization_in);
124 pr->min.distance = GNUNET_MIN(pr->min.distance, 125 pr->min.distance = GNUNET_MIN (pr->min.distance,
125 a->properties.distance); 126 a->properties.distance);
126 pr->min.delay = GNUNET_TIME_relative_min(pr->min.delay, 127 pr->min.delay = GNUNET_TIME_relative_min (pr->min.delay,
127 a->properties.delay); 128 a->properties.delay);
128 return GNUNET_OK; 129 return GNUNET_OK;
129} 130}
130 131
@@ -138,13 +139,13 @@ find_min_max_it(void *cls,
138 * @param ni normalization information to update 139 * @param ni normalization information to update
139 */ 140 */
140static void 141static void
141update_norm(uint64_t min, 142update_norm (uint64_t min,
142 uint64_t max, 143 uint64_t max,
143 struct GAS_NormalizationInfo *ni) 144 struct GAS_NormalizationInfo *ni)
144{ 145{
145 /* max - 2 * min + avg_value / (max - min) */ 146 /* max - 2 * min + avg_value / (max - min) */
146 if (min < max) 147 if (min < max)
147 ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double)(max - min); 148 ni->norm = DEFAULT_REL_QUALITY + (ni->avg - min) / (double) (max - min);
148 else 149 else
149 ni->norm = DEFAULT_REL_QUALITY; 150 ni->norm = DEFAULT_REL_QUALITY;
150} 151}
@@ -162,24 +163,24 @@ update_norm(uint64_t min,
162 * @return #GNUNET_OK (continue to iterate) 163 * @return #GNUNET_OK (continue to iterate)
163 */ 164 */
164static int 165static int
165normalize_address(void *cls, 166normalize_address (void *cls,
166 const struct GNUNET_PeerIdentity *key, 167 const struct GNUNET_PeerIdentity *key,
167 void *value) 168 void *value)
168{ 169{
169 struct ATS_Address *address = value; 170 struct ATS_Address *address = value;
170 171
171 update_norm(property_range.min.delay.rel_value_us, 172 update_norm (property_range.min.delay.rel_value_us,
172 property_range.max.delay.rel_value_us, 173 property_range.max.delay.rel_value_us,
173 &address->norm_delay); 174 &address->norm_delay);
174 update_norm(property_range.min.distance, 175 update_norm (property_range.min.distance,
175 property_range.max.distance, 176 property_range.max.distance,
176 &address->norm_distance); 177 &address->norm_distance);
177 update_norm(property_range.min.utilization_in, 178 update_norm (property_range.min.utilization_in,
178 property_range.max.utilization_in, 179 property_range.max.utilization_in,
179 &address->norm_utilization_in); 180 &address->norm_utilization_in);
180 update_norm(property_range.min.utilization_out, 181 update_norm (property_range.min.utilization_out,
181 property_range.max.utilization_out, 182 property_range.max.utilization_out,
182 &address->norm_utilization_out); 183 &address->norm_utilization_out);
183 return GNUNET_OK; 184 return GNUNET_OK;
184} 185}
185 186
@@ -193,13 +194,13 @@ normalize_address(void *cls,
193 * @return #GNUNET_OK (continue to iterate) 194 * @return #GNUNET_OK (continue to iterate)
194 */ 195 */
195static int 196static int
196notify_change(void *cls, 197notify_change (void *cls,
197 const struct GNUNET_PeerIdentity *key, 198 const struct GNUNET_PeerIdentity *key,
198 void *value) 199 void *value)
199{ 200{
200 struct ATS_Address *address = value; 201 struct ATS_Address *address = value;
201 202
202 GAS_plugin_notify_property_changed(address); 203 GAS_plugin_notify_property_changed (address);
203 return GNUNET_OK; 204 return GNUNET_OK;
204} 205}
205 206
@@ -211,9 +212,9 @@ notify_change(void *cls,
211 * @param pr range to initialize 212 * @param pr range to initialize
212 */ 213 */
213static void 214static void
214init_range(struct PropertyRange *pr) 215init_range (struct PropertyRange *pr)
215{ 216{
216 memset(pr, 0, sizeof(struct PropertyRange)); 217 memset (pr, 0, sizeof(struct PropertyRange));
217 pr->min.utilization_out = UINT32_MAX; 218 pr->min.utilization_out = UINT32_MAX;
218 pr->min.utilization_in = UINT32_MAX; 219 pr->min.utilization_in = UINT32_MAX;
219 pr->min.distance = UINT32_MAX; 220 pr->min.distance = UINT32_MAX;
@@ -227,51 +228,51 @@ init_range(struct PropertyRange *pr)
227 * @param address the address to update 228 * @param address the address to update
228 */ 229 */
229void 230void
230GAS_normalization_update_property(struct ATS_Address *address) 231GAS_normalization_update_property (struct ATS_Address *address)
231{ 232{
232 const struct GNUNET_ATS_Properties *prop = &address->properties; 233 const struct GNUNET_ATS_Properties *prop = &address->properties;
233 struct PropertyRange range; 234 struct PropertyRange range;
234 235
235 LOG(GNUNET_ERROR_TYPE_DEBUG, 236 LOG (GNUNET_ERROR_TYPE_DEBUG,
236 "Updating properties for peer `%s'\n", 237 "Updating properties for peer `%s'\n",
237 GNUNET_i2s(&address->peer)); 238 GNUNET_i2s (&address->peer));
238 GAS_plugin_solver_lock(); 239 GAS_plugin_solver_lock ();
239 update_avg(prop->delay.rel_value_us, 240 update_avg (prop->delay.rel_value_us,
240 &address->norm_delay); 241 &address->norm_delay);
241 update_avg(prop->distance, 242 update_avg (prop->distance,
242 &address->norm_distance); 243 &address->norm_distance);
243 update_avg(prop->utilization_in, 244 update_avg (prop->utilization_in,
244 &address->norm_utilization_in); 245 &address->norm_utilization_in);
245 update_avg(prop->utilization_in, 246 update_avg (prop->utilization_in,
246 &address->norm_utilization_out); 247 &address->norm_utilization_out);
247 248
248 init_range(&range); 249 init_range (&range);
249 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, 250 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
250 &find_min_max_it, 251 &find_min_max_it,
251 &range); 252 &range);
252 if (0 != GNUNET_memcmp(&range, 253 if (0 != GNUNET_memcmp (&range,
253 &property_range)) 254 &property_range))
254 { 255 {
255 /* limits changed, (re)normalize all addresses */ 256 /* limits changed, (re)normalize all addresses */
256 property_range = range; 257 property_range = range;
257 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, 258 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
258 &normalize_address, 259 &normalize_address,
259 NULL); 260 NULL);
260 GNUNET_CONTAINER_multipeermap_iterate(GSA_addresses, 261 GNUNET_CONTAINER_multipeermap_iterate (GSA_addresses,
261 &notify_change, 262 &notify_change,
262 NULL); 263 NULL);
263 } 264 }
264 else 265 else
265 { 266 {
266 /* renormalize just this one address */ 267 /* renormalize just this one address */
267 normalize_address(NULL, 268 normalize_address (NULL,
268 &address->peer, 269 &address->peer,
269 address); 270 address);
270 notify_change(NULL, 271 notify_change (NULL,
271 &address->peer, 272 &address->peer,
272 address); 273 address);
273 } 274 }
274 GAS_plugin_solver_unlock(); 275 GAS_plugin_solver_unlock ();
275} 276}
276 277
277 278
@@ -279,9 +280,9 @@ GAS_normalization_update_property(struct ATS_Address *address)
279 * Start the normalization component 280 * Start the normalization component
280 */ 281 */
281void 282void
282GAS_normalization_start() 283GAS_normalization_start ()
283{ 284{
284 init_range(&property_range); 285 init_range (&property_range);
285} 286}
286 287
287 288
@@ -289,7 +290,7 @@ GAS_normalization_start()
289 * Stop the normalization component and free all items 290 * Stop the normalization component and free all items
290 */ 291 */
291void 292void
292GAS_normalization_stop() 293GAS_normalization_stop ()
293{ 294{
294 /* nothing to do */ 295 /* nothing to do */
295} 296}
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h
index 57bcf49f4..9c02586c2 100644
--- a/src/ats/gnunet-service-ats_normalization.h
+++ b/src/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 */
42void 42void
43GAS_normalization_update_property(struct ATS_Address *address); 43GAS_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 */
49void 49void
50GAS_normalization_start(void); 50GAS_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 */
56void 56void
57GAS_normalization_stop(void); 57GAS_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 16d0777de..441c6610e 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -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 */
65static void 65static void
66notify_client(struct GNUNET_SERVICE_Client *client, 66notify_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,35 @@ notify_client(struct GNUNET_SERVICE_Client *client,
142 * @param bandwidth_in assigned inbound bandwidth 142 * @param bandwidth_in assigned inbound bandwidth
143 */ 143 */
144void 144void
145GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, 145GAS_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
152 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 152 local_address_info,
153 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 153 struct GNUNET_BANDWIDTH_Value32NBO
154 bandwidth_out,
155 struct GNUNET_BANDWIDTH_Value32NBO
156 bandwidth_in)
154{ 157{
155 GNUNET_break((NULL == prop) || 158 GNUNET_break ((NULL == prop) ||
156 (GNUNET_NT_UNSPECIFIED != prop->scope)); 159 (GNUNET_NT_UNSPECIFIED != prop->scope));
157 notify_client(NULL, 160 notify_client (NULL,
158 peer, 161 peer,
159 plugin_name, 162 plugin_name,
160 plugin_addr, 163 plugin_addr,
161 plugin_addr_len, 164 plugin_addr_len,
162 active, 165 active,
163 prop, 166 prop,
164 local_address_info, 167 local_address_info,
165 bandwidth_out, 168 bandwidth_out,
166 bandwidth_in); 169 bandwidth_in);
167 GNUNET_STATISTICS_update(GSA_stats, 170 GNUNET_STATISTICS_update (GSA_stats,
168 "# performance updates given to clients", 171 "# performance updates given to clients",
169 1, 172 1,
170 GNUNET_NO); 173 GNUNET_NO);
171} 174}
172 175
173 176
@@ -186,38 +189,38 @@ GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer,
186 * @param bandwidth_in current inbound bandwidth assigned to address 189 * @param bandwidth_in current inbound bandwidth assigned to address
187 */ 190 */
188static void 191static void
189peerinfo_it(void *cls, 192peerinfo_it (void *cls,
190 const struct GNUNET_PeerIdentity *id, 193 const struct GNUNET_PeerIdentity *id,
191 const char *plugin_name, 194 const char *plugin_name,
192 const void *plugin_addr, 195 const void *plugin_addr,
193 size_t plugin_addr_len, 196 size_t plugin_addr_len,
194 int active, 197 int active,
195 const struct GNUNET_ATS_Properties *prop, 198 const struct GNUNET_ATS_Properties *prop,
196 enum GNUNET_HELLO_AddressInfo local_address_info, 199 enum GNUNET_HELLO_AddressInfo local_address_info,
197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 200 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 201 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
199{ 202{
200 struct GNUNET_SERVICE_Client *client = cls; 203 struct GNUNET_SERVICE_Client *client = cls;
201 204
202 if (NULL == id) 205 if (NULL == id)
203 return; 206 return;
204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n", 208 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
206 GNUNET_i2s(id), 209 GNUNET_i2s (id),
207 plugin_name, 210 plugin_name,
208 (unsigned int)ntohl(bandwidth_out.value__), 211 (unsigned int) ntohl (bandwidth_out.value__),
209 (unsigned int)ntohl(bandwidth_in.value__)); 212 (unsigned int) ntohl (bandwidth_in.value__));
210 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope); 213 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope);
211 notify_client(client, 214 notify_client (client,
212 id, 215 id,
213 plugin_name, 216 plugin_name,
214 plugin_addr, 217 plugin_addr,
215 plugin_addr_len, 218 plugin_addr_len,
216 active, 219 active,
217 prop, 220 prop,
218 local_address_info, 221 local_address_info,
219 bandwidth_out, 222 bandwidth_out,
220 bandwidth_in); 223 bandwidth_in);
221} 224}
222 225
223 226
@@ -228,25 +231,25 @@ peerinfo_it(void *cls,
228 * @param flag flag specifying the type of the client 231 * @param flag flag specifying the type of the client
229 */ 232 */
230void 233void
231GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, 234GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
232 enum StartFlag flag) 235 enum StartFlag flag)
233{ 236{
234 struct GNUNET_MQ_Handle *mq; 237 struct GNUNET_MQ_Handle *mq;
235 238
236 mq = GNUNET_SERVICE_client_get_mq(client); 239 mq = GNUNET_SERVICE_client_get_mq (client);
237 if (START_FLAG_PERFORMANCE_WITH_PIC == flag) 240 if (START_FLAG_PERFORMANCE_WITH_PIC == flag)
238 { 241 {
239 GNUNET_notification_context_add(nc_pic, 242 GNUNET_notification_context_add (nc_pic,
240 mq); 243 mq);
241 GAS_addresses_get_peer_info(NULL, 244 GAS_addresses_get_peer_info (NULL,
242 &peerinfo_it, 245 &peerinfo_it,
243 client); 246 client);
244 } 247 }
245 else 248 else
246 { 249 {
247 GNUNET_notification_context_add(nc_no_pic, 250 GNUNET_notification_context_add (nc_no_pic,
248 mq); 251 mq);
249 } 252 }
250} 253}
251 254
252 255
@@ -256,10 +259,10 @@ GAS_performance_add_client(struct GNUNET_SERVICE_Client *client,
256 * @param server handle to our server 259 * @param server handle to our server
257 */ 260 */
258void 261void
259GAS_performance_init() 262GAS_performance_init ()
260{ 263{
261 nc_no_pic = GNUNET_notification_context_create(32); 264 nc_no_pic = GNUNET_notification_context_create (32);
262 nc_pic = GNUNET_notification_context_create(32); 265 nc_pic = GNUNET_notification_context_create (32);
263} 266}
264 267
265 268
@@ -267,11 +270,11 @@ GAS_performance_init()
267 * Shutdown performance subsystem. 270 * Shutdown performance subsystem.
268 */ 271 */
269void 272void
270GAS_performance_done() 273GAS_performance_done ()
271{ 274{
272 GNUNET_notification_context_destroy(nc_no_pic); 275 GNUNET_notification_context_destroy (nc_no_pic);
273 nc_no_pic = NULL; 276 nc_no_pic = NULL;
274 GNUNET_notification_context_destroy(nc_pic); 277 GNUNET_notification_context_destroy (nc_pic);
275 nc_pic = NULL; 278 nc_pic = NULL;
276} 279}
277 280
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h
index 3d5de0d85..292c27c95 100644
--- a/src/ats/gnunet-service-ats_performance.h
+++ b/src/ats/gnunet-service-ats_performance.h
@@ -50,15 +50,18 @@
50 * @param bandwidth_in assigned inbound bandwidth 50 * @param bandwidth_in assigned inbound bandwidth
51 */ 51 */
52void 52void
53GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, 53GAS_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
60 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 60 local_address_info,
61 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 61 struct GNUNET_BANDWIDTH_Value32NBO
62 bandwidth_out,
63 struct GNUNET_BANDWIDTH_Value32NBO
64 bandwidth_in);
62 65
63 66
64/** 67/**
@@ -68,8 +71,8 @@ GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer,
68 * @param flag flag specifying the type of the client 71 * @param flag flag specifying the type of the client
69 */ 72 */
70void 73void
71GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, 74GAS_performance_add_client (struct GNUNET_SERVICE_Client *client,
72 enum StartFlag flag); 75 enum StartFlag flag);
73 76
74 77
75/** 78/**
@@ -79,14 +82,14 @@ GAS_performance_add_client(struct GNUNET_SERVICE_Client *client,
79 * @param addresses the address handle to use 82 * @param addresses the address handle to use
80 */ 83 */
81void 84void
82GAS_performance_init(void); 85GAS_performance_init (void);
83 86
84 87
85/** 88/**
86 * Shutdown performance subsystem. 89 * Shutdown performance subsystem.
87 */ 90 */
88void 91void
89GAS_performance_done(void); 92GAS_performance_done (void);
90 93
91 94
92#endif 95#endif
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index 274f89e7a..d8d6be11d 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -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 */
61void 61void
62GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, 62GAS_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 */
78void 78void
79GAS_plugin_notify_property_changed(struct ATS_Address *address) 79GAS_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,116 +92,116 @@ GAS_plugin_notify_property_changed(struct ATS_Address *address)
92 * @param add additional information 92 * @param add additional information
93 */ 93 */
94static void 94static void
95solver_info_cb(void *cls, 95solver_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 {
104 case GAS_INFO_NONE: 104 case GAS_INFO_NONE:
105 add_info = "GAS_INFO_NONE"; 105 add_info = "GAS_INFO_NONE";
106 break; 106 break;
107 107
108 case GAS_INFO_FULL: 108 case GAS_INFO_FULL:
109 add_info = "GAS_INFO_MLP_FULL"; 109 add_info = "GAS_INFO_MLP_FULL";
110 break; 110 break;
111 111
112 case GAS_INFO_UPDATED: 112 case GAS_INFO_UPDATED:
113 add_info = "GAS_INFO_MLP_UPDATED"; 113 add_info = "GAS_INFO_MLP_UPDATED";
114 break; 114 break;
115 115
116 case GAS_INFO_PROP_ALL: 116 case GAS_INFO_PROP_ALL:
117 add_info = "GAS_INFO_PROP_ALL"; 117 add_info = "GAS_INFO_PROP_ALL";
118 break; 118 break;
119 119
120 case GAS_INFO_PROP_SINGLE: 120 case GAS_INFO_PROP_SINGLE:
121 add_info = "GAS_INFO_PROP_SINGLE"; 121 add_info = "GAS_INFO_PROP_SINGLE";
122 break; 122 break;
123 123
124 default: 124 default:
125 add_info = "INVALID"; 125 add_info = "INVALID";
126 break; 126 break;
127 } 127 }
128 switch (op) 128 switch (op)
129 { 129 {
130 case GAS_OP_SOLVE_START: 130 case GAS_OP_SOLVE_START:
131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Solver notifies `%s' with result `%s' `%s'\n", 132 "Solver notifies `%s' with result `%s' `%s'\n",
133 "GAS_OP_SOLVE_START", 133 "GAS_OP_SOLVE_START",
134 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL", 134 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL",
135 add_info); 135 add_info);
136 return; 136 return;
137 137
138 case GAS_OP_SOLVE_STOP: 138 case GAS_OP_SOLVE_STOP:
139 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "Solver notifies `%s' with result `%s'\n", 140 "Solver notifies `%s' with result `%s'\n",
141 "GAS_OP_SOLVE_STOP", 141 "GAS_OP_SOLVE_STOP",
142 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 142 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
143 return; 143 return;
144 144
145 case GAS_OP_SOLVE_SETUP_START: 145 case GAS_OP_SOLVE_SETUP_START:
146 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Solver notifies `%s' with result `%s'\n", 147 "Solver notifies `%s' with result `%s'\n",
148 "GAS_OP_SOLVE_SETUP_START", 148 "GAS_OP_SOLVE_SETUP_START",
149 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 149 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
150 return; 150 return;
151 151
152 case GAS_OP_SOLVE_SETUP_STOP: 152 case GAS_OP_SOLVE_SETUP_STOP:
153 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
154 "Solver notifies `%s' with result `%s'\n", 154 "Solver notifies `%s' with result `%s'\n",
155 "GAS_OP_SOLVE_SETUP_STOP", 155 "GAS_OP_SOLVE_SETUP_STOP",
156 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 156 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
157 return; 157 return;
158 158
159 case GAS_OP_SOLVE_MLP_LP_START: 159 case GAS_OP_SOLVE_MLP_LP_START:
160 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
161 "Solver notifies `%s' with result `%s'\n", 161 "Solver notifies `%s' with result `%s'\n",
162 "GAS_OP_SOLVE_LP_START", 162 "GAS_OP_SOLVE_LP_START",
163 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 163 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
164 return; 164 return;
165 165
166 case GAS_OP_SOLVE_MLP_LP_STOP: 166 case GAS_OP_SOLVE_MLP_LP_STOP:
167 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
168 "Solver notifies `%s' with result `%s'\n", 168 "Solver notifies `%s' with result `%s'\n",
169 "GAS_OP_SOLVE_LP_STOP", 169 "GAS_OP_SOLVE_LP_STOP",
170 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 170 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
171 return; 171 return;
172 172
173 case GAS_OP_SOLVE_MLP_MLP_START: 173 case GAS_OP_SOLVE_MLP_MLP_START:
174 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Solver notifies `%s' with result `%s'\n", 175 "Solver notifies `%s' with result `%s'\n",
176 "GAS_OP_SOLVE_MLP_START", 176 "GAS_OP_SOLVE_MLP_START",
177 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 177 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
178 return; 178 return;
179 179
180 case GAS_OP_SOLVE_MLP_MLP_STOP: 180 case GAS_OP_SOLVE_MLP_MLP_STOP:
181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
182 "Solver notifies `%s' with result `%s'\n", 182 "Solver notifies `%s' with result `%s'\n",
183 "GAS_OP_SOLVE_MLP_STOP", 183 "GAS_OP_SOLVE_MLP_STOP",
184 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 184 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
185 return; 185 return;
186 186
187 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: 187 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Solver notifies `%s' with result `%s'\n", 189 "Solver notifies `%s' with result `%s'\n",
190 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", 190 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
191 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 191 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
192 return; 192 return;
193 193
194 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: 194 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
195 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
196 "Solver notifies `%s' with result `%s'\n", 196 "Solver notifies `%s' with result `%s'\n",
197 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", 197 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
198 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL"); 198 (GAS_STAT_SUCCESS == status) ? "SUCCESS" : "FAIL");
199 return; 199 return;
200 200
201 default: 201 default:
202 GNUNET_break(0); 202 GNUNET_break (0);
203 break; 203 break;
204 } 204 }
205} 205}
206 206
207 207
@@ -212,69 +212,74 @@ solver_info_cb(void *cls,
212 * @param address the address with changes 212 * @param address the address with changes
213 */ 213 */
214static void 214static void
215bandwidth_changed_cb(void *cls, 215bandwidth_changed_cb (void *cls,
216 struct ATS_Address *address) 216 struct ATS_Address *address)
217{ 217{
218 long long diff_out; 218 long long diff_out;
219 long long diff_in; 219 long long diff_in;
220 220
221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
222 "Bandwidth assignment changed for peer %s to %u/%u\n", 222 "Bandwidth assignment changed for peer %s to %u/%u\n",
223 GNUNET_i2s(&address->peer), 223 GNUNET_i2s (&address->peer),
224 (unsigned int)address->assigned_bw_in, 224 (unsigned int) address->assigned_bw_in,
225 (unsigned int)address->assigned_bw_out); 225 (unsigned int) address->assigned_bw_out);
226 GAS_reservations_set_bandwidth(&address->peer, 226 GAS_reservations_set_bandwidth (&address->peer,
227 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); 227 GNUNET_BANDWIDTH_value_init (
228 address->assigned_bw_in));
228 /* Notify performance clients about changes to address */ 229 /* Notify performance clients about changes to address */
229 GAS_performance_notify_all_clients(&address->peer, 230 GAS_performance_notify_all_clients (&address->peer,
230 address->plugin, 231 address->plugin,
231 address->addr, 232 address->addr,
232 address->addr_len, 233 address->addr_len,
233 address->active, 234 address->active,
234 &address->properties, 235 &address->properties,
235 address->local_address_info, 236 address->local_address_info,
236 GNUNET_BANDWIDTH_value_init(address->assigned_bw_out), 237 GNUNET_BANDWIDTH_value_init (
237 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); 238 address->assigned_bw_out),
239 GNUNET_BANDWIDTH_value_init (
240 address->assigned_bw_in));
238 241
239 if ((0 == address->assigned_bw_in) && 242 if ((0 == address->assigned_bw_in) &&
240 (0 == address->assigned_bw_out)) 243 (0 == address->assigned_bw_out))
241 { 244 {
242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
243 "Telling transport to disconnect peer `%s'\n", 246 "Telling transport to disconnect peer `%s'\n",
244 GNUNET_i2s(&address->peer)); 247 GNUNET_i2s (&address->peer));
245 248
246 /* Notify scheduling clients about suggestion */ 249 /* Notify scheduling clients about suggestion */
247 GAS_scheduling_transmit_address_suggestion(&address->peer, 250 GAS_scheduling_transmit_address_suggestion (&address->peer,
248 address->session_id, 251 address->session_id,
249 GNUNET_BANDWIDTH_ZERO, 252 GNUNET_BANDWIDTH_ZERO,
250 GNUNET_BANDWIDTH_ZERO); 253 GNUNET_BANDWIDTH_ZERO);
251 return; 254 return;
252 } 255 }
253 256
254 /* Do bandwidth stability check */ 257 /* Do bandwidth stability check */
255 diff_out = llabs((long long)address->assigned_bw_out - 258 diff_out = llabs ((long long) address->assigned_bw_out
256 (long long)address->last_notified_bw_out); 259 - (long long) address->last_notified_bw_out);
257 diff_in = llabs((long long)address->assigned_bw_in - 260 diff_in = llabs ((long long) address->assigned_bw_in
258 (long long)address->last_notified_bw_in); 261 - (long long) address->last_notified_bw_in);
259 if ((diff_out < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) && 262 if ((diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
260 (diff_in < htonl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__))) 263 (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)))
261 { 264 {
262 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 "Bandwidth change too small, not notifying client\n"); 266 "Bandwidth change too small, not notifying client\n");
264 return; 267 return;
265 } 268 }
266 269
267 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
268 "Sending bandwidth update for peer `%s': %u/%u\n", 271 "Sending bandwidth update for peer `%s': %u/%u\n",
269 GNUNET_i2s(&address->peer), 272 GNUNET_i2s (&address->peer),
270 address->assigned_bw_out, 273 address->assigned_bw_out,
271 address->assigned_bw_out); 274 address->assigned_bw_out);
272 275
273 /* *Notify scheduling clients about suggestion */ 276 /* *Notify scheduling clients about suggestion */
274 GAS_scheduling_transmit_address_suggestion(&address->peer, 277 GAS_scheduling_transmit_address_suggestion (&address->peer,
275 address->session_id, 278 address->session_id,
276 GNUNET_BANDWIDTH_value_init(address->assigned_bw_out), 279 GNUNET_BANDWIDTH_value_init (
277 GNUNET_BANDWIDTH_value_init(address->assigned_bw_in)); 280 address->assigned_bw_out),
281 GNUNET_BANDWIDTH_value_init (
282 address->assigned_bw_in));
278 283
279 address->last_notified_bw_out = address->assigned_bw_out; 284 address->last_notified_bw_out = address->assigned_bw_out;
280 address->last_notified_bw_in = address->assigned_bw_in; 285 address->last_notified_bw_in = address->assigned_bw_in;
@@ -290,48 +295,49 @@ bandwidth_changed_cb(void *cls,
290 * @return numeric quota value to use 295 * @return numeric quota value to use
291 */ 296 */
292static unsigned long long 297static unsigned long long
293parse_quota(const char *quota_str, 298parse_quota (const char *quota_str,
294 const char *direction, 299 const char *direction,
295 enum GNUNET_NetworkType network) 300 enum GNUNET_NetworkType network)
296{ 301{
297 int res; 302 int res;
298 unsigned long long ret; 303 unsigned long long ret;
299 304
300 res = GNUNET_NO; 305 res = GNUNET_NO;
301 if (0 == strcmp(quota_str, GNUNET_ATS_MaxBandwidthString)) 306 if (0 == strcmp (quota_str, GNUNET_ATS_MaxBandwidthString))
302 { 307 {
303 ret = GNUNET_ATS_MaxBandwidth; 308 ret = GNUNET_ATS_MaxBandwidth;
304 res = GNUNET_YES; 309 res = GNUNET_YES;
305 } 310 }
306 if ((GNUNET_NO == res) && 311 if ((GNUNET_NO == res) &&
307 (GNUNET_OK == 312 (GNUNET_OK ==
308 GNUNET_STRINGS_fancy_size_to_bytes(quota_str, 313 GNUNET_STRINGS_fancy_size_to_bytes (quota_str,
309 &ret))) 314 &ret)))
310 res = GNUNET_YES; 315 res = GNUNET_YES;
311 if ((GNUNET_NO == res) && 316 if ((GNUNET_NO == res) &&
312 (1 == 317 (1 ==
313 sscanf(quota_str, 318 sscanf (quota_str,
314 "%llu", 319 "%llu",
315 &ret))) 320 &ret)))
316 res = GNUNET_YES; 321 res = GNUNET_YES;
317 if (GNUNET_NO == res) 322 if (GNUNET_NO == res)
318 { 323 {
319 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
320 _("Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"), 325 _ (
321 direction, 326 "Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
322 GNUNET_NT_to_string(network), 327 direction,
323 quota_str, 328 GNUNET_NT_to_string (network),
324 (unsigned long long)GNUNET_ATS_DefaultBandwidth); 329 quota_str,
325 ret = GNUNET_ATS_DefaultBandwidth; 330 (unsigned long long) GNUNET_ATS_DefaultBandwidth);
326 } 331 ret = GNUNET_ATS_DefaultBandwidth;
332 }
327 else 333 else
328 { 334 {
329 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 335 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
330 _("%s quota configured for network `%s' is %llu\n"), 336 _ ("%s quota configured for network `%s' is %llu\n"),
331 direction, 337 direction,
332 GNUNET_NT_to_string(network), 338 GNUNET_NT_to_string (network),
333 ret); 339 ret);
334 } 340 }
335 return ret; 341 return ret;
336} 342}
337 343
@@ -346,39 +352,40 @@ parse_quota(const char *quota_str,
346 * @return quota to apply 352 * @return quota to apply
347 */ 353 */
348static unsigned long long 354static unsigned long long
349load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, 355load_quota (const struct GNUNET_CONFIGURATION_Handle *cfg,
350 enum GNUNET_NetworkType type, 356 enum GNUNET_NetworkType type,
351 const char *direction) 357 const char *direction)
352{ 358{
353 char *entry; 359 char *entry;
354 char *quota_str; 360 char *quota_str;
355 unsigned long long ret; 361 unsigned long long ret;
356 362
357 GNUNET_asprintf(&entry, 363 GNUNET_asprintf (&entry,
358 "%s_QUOTA_%s", 364 "%s_QUOTA_%s",
359 GNUNET_NT_to_string(type), 365 GNUNET_NT_to_string (type),
360 direction); 366 direction);
361 if (GNUNET_OK == 367 if (GNUNET_OK ==
362 GNUNET_CONFIGURATION_get_value_string(cfg, 368 GNUNET_CONFIGURATION_get_value_string (cfg,
363 "ats", 369 "ats",
364 entry, 370 entry,
365 &quota_str)) 371 &quota_str))
366 { 372 {
367 ret = parse_quota(quota_str, 373 ret = parse_quota (quota_str,
368 direction, 374 direction,
369 type); 375 type);
370 GNUNET_free(quota_str); 376 GNUNET_free (quota_str);
371 } 377 }
372 else 378 else
373 { 379 {
374 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
375 _("No %s-quota configured for network `%s', assigning default bandwidth %llu\n"), 381 _ (
376 direction, 382 "No %s-quota configured for network `%s', assigning default bandwidth %llu\n"),
377 GNUNET_NT_to_string(type), 383 direction,
378 (unsigned long long)GNUNET_ATS_DefaultBandwidth); 384 GNUNET_NT_to_string (type),
379 ret = GNUNET_ATS_DefaultBandwidth; 385 (unsigned long long) GNUNET_ATS_DefaultBandwidth);
380 } 386 ret = GNUNET_ATS_DefaultBandwidth;
381 GNUNET_free(entry); 387 }
388 GNUNET_free (entry);
382 return ret; 389 return ret;
383} 390}
384 391
@@ -393,27 +400,27 @@ load_quota(const struct GNUNET_CONFIGURATION_Handle *cfg,
393 * @return number of networks loaded 400 * @return number of networks loaded
394 */ 401 */
395static unsigned int 402static unsigned int
396load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg, 403load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
397 unsigned long long *out_dest, 404 unsigned long long *out_dest,
398 unsigned long long *in_dest, 405 unsigned long long *in_dest,
399 int dest_length) 406 int dest_length)
400{ 407{
401 unsigned int c; 408 unsigned int c;
402 409
403 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++) 410 for (c = 0; (c < GNUNET_NT_COUNT) && (c < dest_length); c++)
404 { 411 {
405 in_dest[c] = load_quota(cfg, 412 in_dest[c] = load_quota (cfg,
413 c,
414 "out");
415 out_dest[c] = load_quota (cfg,
406 c, 416 c,
407 "out"); 417 "in");
408 out_dest[c] = load_quota(cfg, 418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
409 c, 419 "Loaded quota for network `%s' (in/out): %llu %llu\n",
410 "in"); 420 GNUNET_NT_to_string (c),
411 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 421 in_dest[c],
412 "Loaded quota for network `%s' (in/out): %llu %llu\n", 422 out_dest[c]);
413 GNUNET_NT_to_string(c), 423 }
414 in_dest[c],
415 out_dest[c]);
416 }
417 return c; 424 return c;
418} 425}
419 426
@@ -426,21 +433,21 @@ load_quotas(const struct GNUNET_CONFIGURATION_Handle *cfg,
426 * solver plugin) 433 * solver plugin)
427 */ 434 */
428int 435int
429GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg) 436GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
430{ 437{
431 char *mode_str; 438 char *mode_str;
432 439
433 /* Figure out configured solution method */ 440 /* Figure out configured solution method */
434 if (GNUNET_SYSERR == 441 if (GNUNET_SYSERR ==
435 GNUNET_CONFIGURATION_get_value_string(cfg, 442 GNUNET_CONFIGURATION_get_value_string (cfg,
436 "ats", 443 "ats",
437 "MODE", 444 "MODE",
438 &mode_str)) 445 &mode_str))
439 { 446 {
440 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 447 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
441 "No resource assignment method configured, using proportional approach\n"); 448 "No resource assignment method configured, using proportional approach\n");
442 mode_str = GNUNET_strdup("proportional"); 449 mode_str = GNUNET_strdup ("proportional");
443 } 450 }
444 env.cls = NULL; 451 env.cls = NULL;
445 env.info_cb = &solver_info_cb; 452 env.info_cb = &solver_info_cb;
446 env.bandwidth_changed_cb = &bandwidth_changed_cb; 453 env.bandwidth_changed_cb = &bandwidth_changed_cb;
@@ -450,24 +457,24 @@ GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
450 env.stats = GSA_stats; 457 env.stats = GSA_stats;
451 env.addresses = GSA_addresses; 458 env.addresses = GSA_addresses;
452 env.network_count = GNUNET_NT_COUNT; 459 env.network_count = GNUNET_NT_COUNT;
453 load_quotas(cfg, 460 load_quotas (cfg,
454 env.out_quota, 461 env.out_quota,
455 env.in_quota, 462 env.in_quota,
456 GNUNET_NT_COUNT); 463 GNUNET_NT_COUNT);
457 GNUNET_asprintf(&plugin, 464 GNUNET_asprintf (&plugin,
458 "libgnunet_plugin_ats_%s", 465 "libgnunet_plugin_ats_%s",
459 mode_str); 466 mode_str);
460 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
461 "Initializing solver `%s'\n", 468 "Initializing solver `%s'\n",
462 mode_str); 469 mode_str);
463 GNUNET_free(mode_str); 470 GNUNET_free (mode_str);
464 if (NULL == (sf = GNUNET_PLUGIN_load(plugin, &env))) 471 if (NULL == (sf = GNUNET_PLUGIN_load (plugin, &env)))
465 { 472 {
466 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 473 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
467 _("Failed to initialize solver `%s'!\n"), 474 _ ("Failed to initialize solver `%s'!\n"),
468 plugin); 475 plugin);
469 return GNUNET_SYSERR; 476 return GNUNET_SYSERR;
470 } 477 }
471 return GNUNET_OK; 478 return GNUNET_OK;
472} 479}
473 480
@@ -476,12 +483,12 @@ GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
476 * Shutdown address subsystem. 483 * Shutdown address subsystem.
477 */ 484 */
478void 485void
479GAS_plugin_done() 486GAS_plugin_done ()
480{ 487{
481 GNUNET_PLUGIN_unload(plugin, 488 GNUNET_PLUGIN_unload (plugin,
482 sf); 489 sf);
483 sf = NULL; 490 sf = NULL;
484 GNUNET_free(plugin); 491 GNUNET_free (plugin);
485 plugin = NULL; 492 plugin = NULL;
486} 493}
487 494
@@ -493,11 +500,11 @@ GAS_plugin_done()
493 * @param new_address the new address 500 * @param new_address the new address
494 */ 501 */
495void 502void
496GAS_plugin_new_address(struct ATS_Address *new_address) 503GAS_plugin_new_address (struct ATS_Address *new_address)
497{ 504{
498 sf->s_add(sf->cls, 505 sf->s_add (sf->cls,
499 new_address, 506 new_address,
500 new_address->properties.scope); /* FIXME: remove 3rd arg here! */ 507 new_address->properties.scope); /* FIXME: remove 3rd arg here! */
501} 508}
502 509
503 510
@@ -508,10 +515,10 @@ GAS_plugin_new_address(struct ATS_Address *new_address)
508 * @param address address that was deleted 515 * @param address address that was deleted
509 */ 516 */
510void 517void
511GAS_plugin_delete_address(struct ATS_Address *address) 518GAS_plugin_delete_address (struct ATS_Address *address)
512{ 519{
513 sf->s_del(sf->cls, 520 sf->s_del (sf->cls,
514 address); 521 address);
515} 522}
516 523
517 524
@@ -526,18 +533,18 @@ GAS_plugin_delete_address(struct ATS_Address *address)
526 * @param score_abs degree of the appreciation 533 * @param score_abs degree of the appreciation
527 */ 534 */
528void 535void
529GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application, 536GAS_plugin_notify_feedback (struct GNUNET_SERVICE_Client *application,
530 const struct GNUNET_PeerIdentity *peer, 537 const struct GNUNET_PeerIdentity *peer,
531 const struct GNUNET_TIME_Relative scope, 538 const struct GNUNET_TIME_Relative scope,
532 enum GNUNET_ATS_PreferenceKind kind, 539 enum GNUNET_ATS_PreferenceKind kind,
533 float score_abs) 540 float score_abs)
534{ 541{
535 sf->s_feedback(sf->cls, 542 sf->s_feedback (sf->cls,
536 application, 543 application,
537 peer, 544 peer,
538 scope, 545 scope,
539 kind, 546 kind,
540 score_abs); 547 score_abs);
541} 548}
542 549
543 550
@@ -546,9 +553,9 @@ GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application,
546 * happening in bulk right now. 553 * happening in bulk right now.
547 */ 554 */
548void 555void
549GAS_plugin_solver_lock() 556GAS_plugin_solver_lock ()
550{ 557{
551 sf->s_bulk_start(sf->cls); 558 sf->s_bulk_start (sf->cls);
552} 559}
553 560
554 561
@@ -556,9 +563,9 @@ GAS_plugin_solver_lock()
556 * Resume instant solving, we are done with the bulk state updates. 563 * Resume instant solving, we are done with the bulk state updates.
557 */ 564 */
558void 565void
559GAS_plugin_solver_unlock() 566GAS_plugin_solver_unlock ()
560{ 567{
561 sf->s_bulk_stop(sf->cls); 568 sf->s_bulk_stop (sf->cls);
562} 569}
563 570
564 571
@@ -569,10 +576,10 @@ GAS_plugin_solver_unlock()
569 * @param pid identity of peer we now care about 576 * @param pid identity of peer we now care about
570 */ 577 */
571void 578void
572GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid) 579GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
573{ 580{
574 sf->s_get(sf->cls, 581 sf->s_get (sf->cls,
575 pid); 582 pid);
576} 583}
577 584
578 585
@@ -583,10 +590,10 @@ GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid)
583 * @param pid identity of peer we care now less about 590 * @param pid identity of peer we care now less about
584 */ 591 */
585void 592void
586GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid) 593GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
587{ 594{
588 sf->s_get_stop(sf->cls, 595 sf->s_get_stop (sf->cls,
589 pid); 596 pid);
590} 597}
591 598
592 599
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h
index e2256f691..4165fe9e2 100644
--- a/src/ats/gnunet-service-ats_plugins.h
+++ b/src/ats/gnunet-service-ats_plugins.h
@@ -41,14 +41,14 @@
41 * solver plugin) 41 * solver plugin)
42 */ 42 */
43int 43int
44GAS_plugin_init(const struct GNUNET_CONFIGURATION_Handle *cfg); 44GAS_plugin_init (const struct GNUNET_CONFIGURATION_Handle *cfg);
45 45
46 46
47/** 47/**
48 * Shutdown address subsystem. 48 * Shutdown address subsystem.
49 */ 49 */
50void 50void
51GAS_plugin_done(void); 51GAS_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 */
61void 61void
62GAS_plugin_notify_preference_changed(const struct GNUNET_PeerIdentity *peer, 62GAS_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 */
72void 72void
73GAS_plugin_notify_property_changed(struct ATS_Address *address); 73GAS_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 */
83void 83void
84GAS_plugin_new_address(struct ATS_Address *new_address); 84GAS_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 */
93void 93void
94GAS_plugin_delete_address(struct ATS_Address *address); 94GAS_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 */
107void 107void
108GAS_plugin_notify_feedback(struct GNUNET_SERVICE_Client *application, 108GAS_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 */
119void 119void
120GAS_plugin_solver_lock(void); 120GAS_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 */
126void 126void
127GAS_plugin_solver_unlock(void); 127GAS_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 */
136void 136void
137GAS_plugin_request_connect_start(const struct GNUNET_PeerIdentity *pid); 137GAS_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 */
146void 146void
147GAS_plugin_request_connect_stop(const struct GNUNET_PeerIdentity *pid); 147GAS_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 0a12faaae..636e2db47 100644
--- a/src/ats/gnunet-service-ats_preferences.c
+++ b/src/ats/gnunet-service-ats_preferences.c
@@ -32,12 +32,13 @@
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 ( \
41 GNUNET_TIME_UNIT_SECONDS, 10)
41 42
42/** 43/**
43 * By which factor do we age preferences expressed during 44 * By which factor do we age preferences expressed during
@@ -56,7 +57,8 @@
56/** 57/**
57 * Relative preferences for a peer. 58 * Relative preferences for a peer.
58 */ 59 */
59struct PeerRelative { 60struct PeerRelative
61{
60 /** 62 /**
61 * Array of relative preference values, to be indexed by 63 * Array of relative preference values, to be indexed by
62 * an `enum GNUNET_ATS_PreferenceKind`. 64 * an `enum GNUNET_ATS_PreferenceKind`.
@@ -82,7 +84,8 @@ static struct PeerRelative defvalues;
82/** 84/**
83 * Preference information per peer and client. 85 * Preference information per peer and client.
84 */ 86 */
85struct PreferencePeer { 87struct PreferencePeer
88{
86 /** 89 /**
87 * Next in DLL of preference entries for the same client. 90 * Next in DLL of preference entries for the same client.
88 */ 91 */
@@ -113,7 +116,8 @@ struct PreferencePeer {
113 * for peers. This is the information we keep track of for each 116 * for peers. This is the information we keep track of for each
114 * such client. 117 * such client.
115 */ 118 */
116struct PreferenceClient { 119struct PreferenceClient
120{
117 /** 121 /**
118 * Next in client list 122 * Next in client list
119 */ 123 */
@@ -169,7 +173,8 @@ static struct GNUNET_SCHEDULER_Task *aging_task;
169/** 173/**
170 * Closure for #sum_relative_preferences(). 174 * Closure for #sum_relative_preferences().
171 */ 175 */
172struct SumContext { 176struct SumContext
177{
173 /** 178 /**
174 * Where to accumulate the result. 179 * Where to accumulate the result.
175 */ 180 */
@@ -193,9 +198,9 @@ struct SumContext {
193 * @return #GNUNET_OK 198 * @return #GNUNET_OK
194 */ 199 */
195static int 200static int
196sum_relative_preferences(void *cls, 201sum_relative_preferences (void *cls,
197 const struct GNUNET_PeerIdentity *peer, 202 const struct GNUNET_PeerIdentity *peer,
198 void *value) 203 void *value)
199{ 204{
200 struct SumContext *sum_ctx = cls; 205 struct SumContext *sum_ctx = cls;
201 struct PreferencePeer *p_cur = value; 206 struct PreferencePeer *p_cur = value;
@@ -214,8 +219,8 @@ sum_relative_preferences(void *cls,
214 * @return the new relative preference 219 * @return the new relative preference
215 */ 220 */
216static void 221static void
217update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id, 222update_relative_values_for_peer (const struct GNUNET_PeerIdentity *id,
218 enum GNUNET_ATS_PreferenceKind kind) 223 enum GNUNET_ATS_PreferenceKind kind)
219{ 224{
220 struct PreferenceClient *c_cur; 225 struct PreferenceClient *c_cur;
221 struct SumContext sum_ctx; 226 struct SumContext sum_ctx;
@@ -224,25 +229,25 @@ update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id,
224 sum_ctx.f_rel_total = 0.0; 229 sum_ctx.f_rel_total = 0.0;
225 sum_ctx.kind = kind; 230 sum_ctx.kind = kind;
226 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) 231 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
227 GNUNET_CONTAINER_multipeermap_get_multiple(c_cur->peer2pref, 232 GNUNET_CONTAINER_multipeermap_get_multiple (c_cur->peer2pref,
228 id, 233 id,
229 &sum_relative_preferences, 234 &sum_relative_preferences,
230 &sum_ctx); 235 &sum_ctx);
231 LOG(GNUNET_ERROR_TYPE_DEBUG, 236 LOG (GNUNET_ERROR_TYPE_DEBUG,
232 "Total relative preference for peer `%s' for `%s' is %.3f\n", 237 "Total relative preference for peer `%s' for `%s' is %.3f\n",
233 GNUNET_i2s(id), 238 GNUNET_i2s (id),
234 GNUNET_ATS_print_preference_type(kind), 239 GNUNET_ATS_print_preference_type (kind),
235 sum_ctx.f_rel_total); 240 sum_ctx.f_rel_total);
236 rp = GNUNET_CONTAINER_multipeermap_get(preference_peers, 241 rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
237 id); 242 id);
238 GNUNET_assert(NULL != rp); 243 GNUNET_assert (NULL != rp);
239 if (rp->f_rel[kind] != sum_ctx.f_rel_total) 244 if (rp->f_rel[kind] != sum_ctx.f_rel_total)
240 { 245 {
241 rp->f_rel[kind] = sum_ctx.f_rel_total; 246 rp->f_rel[kind] = sum_ctx.f_rel_total;
242 GAS_plugin_notify_preference_changed(id, 247 GAS_plugin_notify_preference_changed (id,
243 kind, 248 kind,
244 rp->f_rel[kind]); 249 rp->f_rel[kind]);
245 } 250 }
246} 251}
247 252
248 253
@@ -255,17 +260,17 @@ update_relative_values_for_peer(const struct GNUNET_PeerIdentity *id,
255 * @return #GNUNET_OK to continue 260 * @return #GNUNET_OK to continue
256 */ 261 */
257static int 262static int
258free_peer(void *cls, 263free_peer (void *cls,
259 const struct GNUNET_PeerIdentity *key, 264 const struct GNUNET_PeerIdentity *key,
260 void *value) 265 void *value)
261{ 266{
262 struct PeerRelative *rp = value; 267 struct PeerRelative *rp = value;
263 268
264 GNUNET_assert(GNUNET_YES == 269 GNUNET_assert (GNUNET_YES ==
265 GNUNET_CONTAINER_multipeermap_remove(preference_peers, 270 GNUNET_CONTAINER_multipeermap_remove (preference_peers,
266 key, 271 key,
267 value)); 272 value));
268 GNUNET_free(rp); 273 GNUNET_free (rp);
269 return GNUNET_OK; 274 return GNUNET_OK;
270} 275}
271 276
@@ -279,30 +284,30 @@ free_peer(void *cls,
279 * @return #GNUNET_OK (continue to iterate) 284 * @return #GNUNET_OK (continue to iterate)
280 */ 285 */
281static int 286static int
282free_preference(void *cls, 287free_preference (void *cls,
283 const struct GNUNET_PeerIdentity *key, 288 const struct GNUNET_PeerIdentity *key,
284 void *value) 289 void *value)
285{ 290{
286 struct PreferenceClient *pc = cls; 291 struct PreferenceClient *pc = cls;
287 struct PreferencePeer *p = value; 292 struct PreferencePeer *p = value;
288 struct PeerRelative *pr; 293 struct PeerRelative *pr;
289 294
290 GNUNET_assert(GNUNET_OK == 295 GNUNET_assert (GNUNET_OK ==
291 GNUNET_CONTAINER_multipeermap_remove(pc->peer2pref, 296 GNUNET_CONTAINER_multipeermap_remove (pc->peer2pref,
292 key, 297 key,
293 p)); 298 p));
294 GNUNET_free(p); 299 GNUNET_free (p);
295 pr = GNUNET_CONTAINER_multipeermap_get(preference_peers, 300 pr = GNUNET_CONTAINER_multipeermap_get (preference_peers,
296 key); 301 key);
297 GNUNET_assert(NULL != pr); 302 GNUNET_assert (NULL != pr);
298 GNUNET_assert(pr->num_clients > 0); 303 GNUNET_assert (pr->num_clients > 0);
299 pr->num_clients--; 304 pr->num_clients--;
300 if (0 == pr->num_clients) 305 if (0 == pr->num_clients)
301 { 306 {
302 free_peer(NULL, 307 free_peer (NULL,
303 key, 308 key,
304 pr); 309 pr);
305 } 310 }
306 return GNUNET_OK; 311 return GNUNET_OK;
307} 312}
308 313
@@ -310,7 +315,8 @@ free_preference(void *cls,
310/** 315/**
311 * Closure for #age_values(). 316 * Closure for #age_values().
312 */ 317 */
313struct AgeContext { 318struct AgeContext
319{
314 /** 320 /**
315 * Counter of values remaining to update, incremented for each value 321 * Counter of values remaining to update, incremented for each value
316 * changed (to a new non-zero value). 322 * changed (to a new non-zero value).
@@ -333,9 +339,9 @@ struct AgeContext {
333 * @return #GNUNET_OK (continue to iterate) 339 * @return #GNUNET_OK (continue to iterate)
334 */ 340 */
335static int 341static int
336age_values(void *cls, 342age_values (void *cls,
337 const struct GNUNET_PeerIdentity *peer, 343 const struct GNUNET_PeerIdentity *peer,
338 void *value) 344 void *value)
339{ 345{
340 struct AgeContext *ac = cls; 346 struct AgeContext *ac = cls;
341 struct PreferencePeer *p = value; 347 struct PreferencePeer *p = value;
@@ -344,32 +350,32 @@ age_values(void *cls,
344 350
345 dead = GNUNET_YES; 351 dead = GNUNET_YES;
346 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) 352 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
353 {
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
355 "Aging preference for peer `%s'\n",
356 GNUNET_i2s (peer));
357 if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE)
358 p->f_abs[i] *= PREF_AGING_FACTOR;
359 if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON)
347 { 360 {
348 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 361 p->f_abs[i] = DEFAULT_ABS_PREFERENCE;
349 "Aging preference for peer `%s'\n", 362 p->f_rel[i] = DEFAULT_REL_PREFERENCE;
350 GNUNET_i2s(peer)); 363 update_relative_values_for_peer (peer,
351 if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) 364 i);
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 }
365 } 365 }
366 if (GNUNET_YES == dead) 366 else
367 { 367 {
368 /* all preferences are zero, remove this entry */ 368 ac->values_to_update++;
369 free_preference(ac->cur_client, 369 dead = GNUNET_NO;
370 peer,
371 p);
372 } 370 }
371 }
372 if (GNUNET_YES == dead)
373 {
374 /* all preferences are zero, remove this entry */
375 free_preference (ac->cur_client,
376 peer,
377 p);
378 }
373 return GNUNET_OK; 379 return GNUNET_OK;
374} 380}
375 381
@@ -380,40 +386,42 @@ age_values(void *cls,
380 * @param cls unused 386 * @param cls unused
381 */ 387 */
382static void 388static void
383preference_aging(void *cls) 389preference_aging (void *cls)
384{ 390{
385 struct AgeContext ac; 391 struct AgeContext ac;
386 392
387 aging_task = NULL; 393 aging_task = NULL;
388 GAS_plugin_solver_lock(); 394 GAS_plugin_solver_lock ();
389 ac.values_to_update = 0; 395 ac.values_to_update = 0;
390 for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client = ac.cur_client->next) 396 for (ac.cur_client = pc_head; NULL != ac.cur_client; ac.cur_client =
391 GNUNET_CONTAINER_multipeermap_iterate(ac.cur_client->peer2pref, 397 ac.cur_client->next)
392 &age_values, 398 GNUNET_CONTAINER_multipeermap_iterate (ac.cur_client->peer2pref,
393 &ac); 399 &age_values,
394 GAS_plugin_solver_unlock(); 400 &ac);
401 GAS_plugin_solver_unlock ();
395 if (ac.values_to_update > 0) 402 if (ac.values_to_update > 0)
396 { 403 {
397 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
398 "Rescheduling aging task due to %u elements remaining to age\n", 405 "Rescheduling aging task due to %u elements remaining to age\n",
399 ac.values_to_update); 406 ac.values_to_update);
400 if (NULL == aging_task) 407 if (NULL == aging_task)
401 aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL, 408 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
402 &preference_aging, 409 &preference_aging,
403 NULL); 410 NULL);
404 } 411 }
405 else 412 else
406 { 413 {
407 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
408 "No values to age left, not rescheduling aging task\n"); 415 "No values to age left, not rescheduling aging task\n");
409 } 416 }
410} 417}
411 418
412 419
413/** 420/**
414 * Closure for #update_rel_sum() and #update_abs_sum(). 421 * Closure for #update_rel_sum() and #update_abs_sum().
415 */ 422 */
416struct UpdateContext { 423struct UpdateContext
424{
417 /** 425 /**
418 * Preference client with the sum of all absolute scores. 426 * Preference client with the sum of all absolute scores.
419 */ 427 */
@@ -436,9 +444,9 @@ struct UpdateContext {
436 * @return #GNUNET_OK (continue to iterate) 444 * @return #GNUNET_OK (continue to iterate)
437 */ 445 */
438static int 446static int
439update_abs_sum(void *cls, 447update_abs_sum (void *cls,
440 const struct GNUNET_PeerIdentity *peer, 448 const struct GNUNET_PeerIdentity *peer,
441 void *value) 449 void *value)
442{ 450{
443 struct UpdateContext *uc = cls; 451 struct UpdateContext *uc = cls;
444 struct PreferencePeer *p_cur = value; 452 struct PreferencePeer *p_cur = value;
@@ -458,19 +466,19 @@ update_abs_sum(void *cls,
458 * @return #GNUNET_OK (continue to iterate) 466 * @return #GNUNET_OK (continue to iterate)
459 */ 467 */
460static int 468static int
461update_rel_sum(void *cls, 469update_rel_sum (void *cls,
462 const struct GNUNET_PeerIdentity *peer, 470 const struct GNUNET_PeerIdentity *peer,
463 void *value) 471 void *value)
464{ 472{
465 struct UpdateContext *uc = cls; 473 struct UpdateContext *uc = cls;
466 struct PreferencePeer *p_cur = value; 474 struct PreferencePeer *p_cur = value;
467 475
468 p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind]; 476 p_cur->f_rel[uc->kind] = p_cur->f_abs[uc->kind] / uc->pc->f_abs_sum[uc->kind];
469 LOG(GNUNET_ERROR_TYPE_DEBUG, 477 LOG (GNUNET_ERROR_TYPE_DEBUG,
470 "Client has relative preference for %s for peer `%s' of %.3f\n", 478 "Client has relative preference for %s for peer `%s' of %.3f\n",
471 GNUNET_ATS_print_preference_type(uc->kind), 479 GNUNET_ATS_print_preference_type (uc->kind),
472 GNUNET_i2s(peer), 480 GNUNET_i2s (peer),
473 p_cur->f_rel[uc->kind]); 481 p_cur->f_rel[uc->kind]);
474 return GNUNET_OK; 482 return GNUNET_OK;
475} 483}
476 484
@@ -483,8 +491,8 @@ update_rel_sum(void *cls,
483 * @return the result 491 * @return the result
484 */ 492 */
485static void 493static void
486recalculate_relative_preferences(struct PreferenceClient *c, 494recalculate_relative_preferences (struct PreferenceClient *c,
487 enum GNUNET_ATS_PreferenceKind kind) 495 enum GNUNET_ATS_PreferenceKind kind)
488{ 496{
489 struct UpdateContext uc; 497 struct UpdateContext uc;
490 498
@@ -494,18 +502,18 @@ recalculate_relative_preferences(struct PreferenceClient *c,
494 c->f_abs_sum[kind] = 0.0; 502 c->f_abs_sum[kind] = 0.0;
495 503
496 /* For all peers: calculate sum of absolute preferences */ 504 /* For all peers: calculate sum of absolute preferences */
497 GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref, 505 GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref,
498 &update_abs_sum, 506 &update_abs_sum,
499 &uc); 507 &uc);
500 LOG(GNUNET_ERROR_TYPE_DEBUG, 508 LOG (GNUNET_ERROR_TYPE_DEBUG,
501 "Client has sum of total preferences for %s of %.3f\n", 509 "Client has sum of total preferences for %s of %.3f\n",
502 GNUNET_ATS_print_preference_type(kind), 510 GNUNET_ATS_print_preference_type (kind),
503 c->f_abs_sum[kind]); 511 c->f_abs_sum[kind]);
504 512
505 /* For all peers: calculate relative preference */ 513 /* For all peers: calculate relative preference */
506 GNUNET_CONTAINER_multipeermap_iterate(c->peer2pref, 514 GNUNET_CONTAINER_multipeermap_iterate (c->peer2pref,
507 &update_rel_sum, 515 &update_rel_sum,
508 &uc); 516 &uc);
509} 517}
510 518
511 519
@@ -520,14 +528,14 @@ recalculate_relative_preferences(struct PreferenceClient *c,
520 * @param value a `struct PeerRelative`, unused 528 * @param value a `struct PeerRelative`, unused
521 */ 529 */
522static int 530static int
523update_iterator(void *cls, 531update_iterator (void *cls,
524 const struct GNUNET_PeerIdentity *key, 532 const struct GNUNET_PeerIdentity *key,
525 void *value) 533 void *value)
526{ 534{
527 enum GNUNET_ATS_PreferenceKind *kind = cls; 535 enum GNUNET_ATS_PreferenceKind *kind = cls;
528 536
529 update_relative_values_for_peer(key, 537 update_relative_values_for_peer (key,
530 *kind); 538 *kind);
531 return GNUNET_OK; 539 return GNUNET_OK;
532} 540}
533 541
@@ -542,10 +550,10 @@ update_iterator(void *cls,
542 * @param score_abs the normalized score 550 * @param score_abs the normalized score
543 */ 551 */
544static void 552static void
545update_preference(struct GNUNET_SERVICE_Client *client, 553update_preference (struct GNUNET_SERVICE_Client *client,
546 const struct GNUNET_PeerIdentity *peer, 554 const struct GNUNET_PeerIdentity *peer,
547 enum GNUNET_ATS_PreferenceKind kind, 555 enum GNUNET_ATS_PreferenceKind kind,
548 float score_abs) 556 float score_abs)
549{ 557{
550 struct PreferenceClient *c_cur; 558 struct PreferenceClient *c_cur;
551 struct PreferencePeer *p_cur; 559 struct PreferencePeer *p_cur;
@@ -553,15 +561,15 @@ update_preference(struct GNUNET_SERVICE_Client *client,
553 unsigned int i; 561 unsigned int i;
554 562
555 if (kind >= GNUNET_ATS_PREFERENCE_END) 563 if (kind >= GNUNET_ATS_PREFERENCE_END)
556 { 564 {
557 GNUNET_break(0); 565 GNUNET_break (0);
558 return; 566 return;
559 } 567 }
560 LOG(GNUNET_ERROR_TYPE_DEBUG, 568 LOG (GNUNET_ERROR_TYPE_DEBUG,
561 "Client changes preference for peer `%s' for `%s' to %.2f\n", 569 "Client changes preference for peer `%s' for `%s' to %.2f\n",
562 GNUNET_i2s(peer), 570 GNUNET_i2s (peer),
563 GNUNET_ATS_print_preference_type(kind), 571 GNUNET_ATS_print_preference_type (kind),
564 score_abs); 572 score_abs);
565 573
566 /* Find preference client */ 574 /* Find preference client */
567 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) 575 for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next)
@@ -569,66 +577,66 @@ update_preference(struct GNUNET_SERVICE_Client *client,
569 break; 577 break;
570 /* Not found: create new preference client */ 578 /* Not found: create new preference client */
571 if (NULL == c_cur) 579 if (NULL == c_cur)
572 { 580 {
573 c_cur = GNUNET_new(struct PreferenceClient); 581 c_cur = GNUNET_new (struct PreferenceClient);
574 c_cur->client = client; 582 c_cur->client = client;
575 c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create(16, 583 c_cur->peer2pref = GNUNET_CONTAINER_multipeermap_create (16,
576 GNUNET_NO); 584 GNUNET_NO);
577 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) 585 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
578 c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; 586 c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
579 GNUNET_CONTAINER_DLL_insert(pc_head, 587 GNUNET_CONTAINER_DLL_insert (pc_head,
580 pc_tail, 588 pc_tail,
581 c_cur); 589 c_cur);
582 } 590 }
583 591
584 /* check global peer entry exists */ 592 /* check global peer entry exists */
585 if (NULL == 593 if (NULL ==
586 (r_cur = GNUNET_CONTAINER_multipeermap_get(preference_peers, 594 (r_cur = GNUNET_CONTAINER_multipeermap_get (preference_peers,
587 peer))) 595 peer)))
588 { 596 {
589 /* Create struct for peer */ 597 /* Create struct for peer */
590 r_cur = GNUNET_new(struct PeerRelative); 598 r_cur = GNUNET_new (struct PeerRelative);
591 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) 599 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
592 r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; 600 r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
593 GNUNET_assert(GNUNET_OK == 601 GNUNET_assert (GNUNET_OK ==
594 GNUNET_CONTAINER_multipeermap_put(preference_peers, 602 GNUNET_CONTAINER_multipeermap_put (preference_peers,
595 peer, 603 peer,
596 r_cur, 604 r_cur,
597 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 605 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
598 } 606 }
599 607
600 /* Find entry for peer */ 608 /* Find entry for peer */
601 p_cur = GNUNET_CONTAINER_multipeermap_get(c_cur->peer2pref, 609 p_cur = GNUNET_CONTAINER_multipeermap_get (c_cur->peer2pref,
602 peer); 610 peer);
603 if (NULL == p_cur) 611 if (NULL == p_cur)
612 {
613 /* Not found: create new peer entry */
614 p_cur = GNUNET_new (struct PreferencePeer);
615 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
604 { 616 {
605 /* Not found: create new peer entry */ 617 /* Default value per peer absolute preference for a preference*/
606 p_cur = GNUNET_new(struct PreferencePeer); 618 p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE;
607 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) 619 /* Default value per peer relative preference for a quality */
608 { 620 p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
609 /* Default value per peer absolute preference for a preference*/ 621 }
610 p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; 622 GNUNET_assert (GNUNET_YES ==
611 /* Default value per peer relative preference for a quality */ 623 GNUNET_CONTAINER_multipeermap_put (c_cur->peer2pref,
612 p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE;
613 }
614 GNUNET_assert(GNUNET_YES ==
615 GNUNET_CONTAINER_multipeermap_put(c_cur->peer2pref,
616 peer, 624 peer,
617 p_cur, 625 p_cur,
618 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 626 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
619 r_cur->num_clients++; 627 r_cur->num_clients++;
620 } 628 }
621 629
622 p_cur->f_abs[kind] += score_abs; 630 p_cur->f_abs[kind] += score_abs;
623 recalculate_relative_preferences(c_cur, kind); 631 recalculate_relative_preferences (c_cur, kind);
624 GNUNET_CONTAINER_multipeermap_iterate(preference_peers, 632 GNUNET_CONTAINER_multipeermap_iterate (preference_peers,
625 &update_iterator, 633 &update_iterator,
626 &kind); 634 &kind);
627 635
628 if (NULL == aging_task) 636 if (NULL == aging_task)
629 aging_task = GNUNET_SCHEDULER_add_delayed(PREF_AGING_INTERVAL, 637 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,
630 &preference_aging, 638 &preference_aging,
631 NULL); 639 NULL);
632} 640}
633 641
634 642
@@ -639,28 +647,29 @@ update_preference(struct GNUNET_SERVICE_Client *client,
639 * @param msg the request message 647 * @param msg the request message
640 */ 648 */
641void 649void
642GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client, 650GAS_handle_preference_change (struct GNUNET_SERVICE_Client *client,
643 const struct ChangePreferenceMessage *msg) 651 const struct ChangePreferenceMessage *msg)
644{ 652{
645 const struct PreferenceInformation *pi; 653 const struct PreferenceInformation *pi;
646 uint32_t nump; 654 uint32_t nump;
647 655
648 nump = ntohl(msg->num_preferences); 656 nump = ntohl (msg->num_preferences);
649 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 657 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
650 "Received PREFERENCE_CHANGE message for peer `%s'\n", 658 "Received PREFERENCE_CHANGE message for peer `%s'\n",
651 GNUNET_i2s(&msg->peer)); 659 GNUNET_i2s (&msg->peer));
652 GNUNET_STATISTICS_update(GSA_stats, 660 GNUNET_STATISTICS_update (GSA_stats,
653 "# preference change requests processed", 661 "# preference change requests processed",
654 1, 662 1,
655 GNUNET_NO); 663 GNUNET_NO);
656 pi = (const struct PreferenceInformation *)&msg[1]; 664 pi = (const struct PreferenceInformation *) &msg[1];
657 GAS_plugin_solver_lock(); 665 GAS_plugin_solver_lock ();
658 for (uint32_t i = 0; i < nump; i++) 666 for (uint32_t i = 0; i < nump; i++)
659 update_preference(client, 667 update_preference (client,
660 &msg->peer, 668 &msg->peer,
661 (enum GNUNET_ATS_PreferenceKind)ntohl(pi[i].preference_kind), 669 (enum GNUNET_ATS_PreferenceKind) ntohl (
662 pi[i].preference_value); 670 pi[i].preference_kind),
663 GAS_plugin_solver_unlock(); 671 pi[i].preference_value);
672 GAS_plugin_solver_unlock ();
664} 673}
665 674
666 675
@@ -668,12 +677,12 @@ GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client,
668 * Initialize preferences subsystem. 677 * Initialize preferences subsystem.
669 */ 678 */
670void 679void
671GAS_preference_init() 680GAS_preference_init ()
672{ 681{
673 unsigned int i; 682 unsigned int i;
674 683
675 preference_peers = GNUNET_CONTAINER_multipeermap_create(16, 684 preference_peers = GNUNET_CONTAINER_multipeermap_create (16,
676 GNUNET_NO); 685 GNUNET_NO);
677 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++) 686 for (i = 0; i < GNUNET_ATS_PREFERENCE_END; i++)
678 defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; 687 defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE;
679} 688}
@@ -683,33 +692,33 @@ GAS_preference_init()
683 * Shutdown preferences subsystem. 692 * Shutdown preferences subsystem.
684 */ 693 */
685void 694void
686GAS_preference_done() 695GAS_preference_done ()
687{ 696{
688 struct PreferenceClient *pc; 697 struct PreferenceClient *pc;
689 struct PreferenceClient *next_pc; 698 struct PreferenceClient *next_pc;
690 699
691 if (NULL != aging_task) 700 if (NULL != aging_task)
692 { 701 {
693 GNUNET_SCHEDULER_cancel(aging_task); 702 GNUNET_SCHEDULER_cancel (aging_task);
694 aging_task = NULL; 703 aging_task = NULL;
695 } 704 }
696 next_pc = pc_head; 705 next_pc = pc_head;
697 while (NULL != (pc = next_pc)) 706 while (NULL != (pc = next_pc))
698 { 707 {
699 next_pc = pc->next; 708 next_pc = pc->next;
700 GNUNET_CONTAINER_DLL_remove(pc_head, 709 GNUNET_CONTAINER_DLL_remove (pc_head,
701 pc_tail, 710 pc_tail,
702 pc); 711 pc);
703 GNUNET_CONTAINER_multipeermap_iterate(pc->peer2pref, 712 GNUNET_CONTAINER_multipeermap_iterate (pc->peer2pref,
704 &free_preference, 713 &free_preference,
705 pc); 714 pc);
706 GNUNET_CONTAINER_multipeermap_destroy(pc->peer2pref); 715 GNUNET_CONTAINER_multipeermap_destroy (pc->peer2pref);
707 GNUNET_free(pc); 716 GNUNET_free (pc);
708 } 717 }
709 GNUNET_CONTAINER_multipeermap_iterate(preference_peers, 718 GNUNET_CONTAINER_multipeermap_iterate (preference_peers,
710 &free_peer, 719 &free_peer,
711 NULL); 720 NULL);
712 GNUNET_CONTAINER_multipeermap_destroy(preference_peers); 721 GNUNET_CONTAINER_multipeermap_destroy (preference_peers);
713} 722}
714 723
715 724
@@ -723,17 +732,17 @@ GAS_preference_done()
723 * default preferences if peer does not exist 732 * default preferences if peer does not exist
724 */ 733 */
725const double * 734const double *
726GAS_preference_get_by_peer(void *cls, 735GAS_preference_get_by_peer (void *cls,
727 const struct GNUNET_PeerIdentity *id) 736 const struct GNUNET_PeerIdentity *id)
728{ 737{
729 struct PeerRelative *rp; 738 struct PeerRelative *rp;
730 739
731 if (NULL == 740 if (NULL ==
732 (rp = GNUNET_CONTAINER_multipeermap_get(preference_peers, 741 (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers,
733 id))) 742 id)))
734 { 743 {
735 return defvalues.f_rel; 744 return defvalues.f_rel;
736 } 745 }
737 return rp->f_rel; 746 return rp->f_rel;
738} 747}
739 748
@@ -744,7 +753,7 @@ GAS_preference_get_by_peer(void *cls,
744 * @param client the client 753 * @param client the client
745 */ 754 */
746void 755void
747GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client) 756GAS_preference_client_disconnect (struct GNUNET_SERVICE_Client *client)
748{ 757{
749 struct PreferenceClient *c_cur; 758 struct PreferenceClient *c_cur;
750 759
@@ -753,14 +762,14 @@ GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client)
753 break; 762 break;
754 if (NULL == c_cur) 763 if (NULL == c_cur)
755 return; 764 return;
756 GNUNET_CONTAINER_DLL_remove(pc_head, 765 GNUNET_CONTAINER_DLL_remove (pc_head,
757 pc_tail, 766 pc_tail,
758 c_cur); 767 c_cur);
759 GNUNET_CONTAINER_multipeermap_iterate(c_cur->peer2pref, 768 GNUNET_CONTAINER_multipeermap_iterate (c_cur->peer2pref,
760 &free_preference, 769 &free_preference,
761 c_cur); 770 c_cur);
762 GNUNET_CONTAINER_multipeermap_destroy(c_cur->peer2pref); 771 GNUNET_CONTAINER_multipeermap_destroy (c_cur->peer2pref);
763 GNUNET_free(c_cur); 772 GNUNET_free (c_cur);
764} 773}
765 774
766 775
diff --git a/src/ats/gnunet-service-ats_preferences.h b/src/ats/gnunet-service-ats_preferences.h
index 48aa33ea6..49bf2ddbd 100644
--- a/src/ats/gnunet-service-ats_preferences.h
+++ b/src/ats/gnunet-service-ats_preferences.h
@@ -50,22 +50,22 @@
50 * @param msg the request message 50 * @param msg the request message
51 */ 51 */
52void 52void
53GAS_handle_preference_change(struct GNUNET_SERVICE_Client *client, 53GAS_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 */
60void 60void
61GAS_preference_init(void); 61GAS_preference_init (void);
62 62
63 63
64/** 64/**
65 * Shutdown preferences subsystem. 65 * Shutdown preferences subsystem.
66 */ 66 */
67void 67void
68GAS_preference_done(void); 68GAS_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 */
79const double * 79const double *
80GAS_preference_get_by_peer(void *cls, 80GAS_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 */
89void 89void
90GAS_preference_client_disconnect(struct GNUNET_SERVICE_Client *client); 90GAS_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 ec1f4b0d5..c4367fb85 100644
--- a/src/ats/gnunet-service-ats_reservations.c
+++ b/src/ats/gnunet-service-ats_reservations.c
@@ -53,38 +53,38 @@ static struct GNUNET_CONTAINER_MultiPeerMap *trackers;
53 * until the reservation might succeed 53 * until the reservation might succeed
54 */ 54 */
55static struct GNUNET_TIME_Relative 55static struct GNUNET_TIME_Relative
56reservations_reserve(const struct GNUNET_PeerIdentity *peer, 56reservations_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)
72 { 75 {
73 ret = GNUNET_BANDWIDTH_tracker_get_delay(tracker, amount); 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
74 if (ret.rel_value_us > 0) 77 "Delay to satisfy reservation for %d bytes is %s\n",
75 { 78 (int) amount,
76 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 79 GNUNET_STRINGS_relative_time_to_string (ret,
77 "Delay to satisfy reservation for %d bytes is %s\n", 80 GNUNET_YES));
78 (int)amount, 81 return ret;
79 GNUNET_STRINGS_relative_time_to_string(ret,
80 GNUNET_YES));
81 return ret;
82 }
83 } 82 }
84 (void)GNUNET_BANDWIDTH_tracker_consume(tracker, amount); 83 }
85 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 84 (void) GNUNET_BANDWIDTH_tracker_consume (tracker, amount);
86 "Reserved %d bytes\n", 85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
87 (int)amount); 86 "Reserved %d bytes\n",
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 */
100void 100void
101GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, 101GAS_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 */
144void 144void
145GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, 145GAS_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 */
176void 176void
177GAS_reservations_init() 177GAS_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 */
192static int 192static int
193free_tracker(void *cls, 193free_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 */
207void 207void
208GAS_reservations_done() 208GAS_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 100cd9a90..d95945697 100644
--- a/src/ats/gnunet-service-ats_reservations.h
+++ b/src/ats/gnunet-service-ats_reservations.h
@@ -39,9 +39,9 @@
39 * this peer (estimate) 39 * this peer (estimate)
40 */ 40 */
41void 41void
42GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer, 42GAS_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,9 @@ GAS_reservations_set_bandwidth(const struct GNUNET_PeerIdentity *peer,
51 * @param message the request message 51 * @param message the request message
52 */ 52 */
53void 53void
54GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client, 54GAS_handle_reservation_request (struct GNUNET_SERVICE_Client *client,
55 const struct ReservationRequestMessage *message); 55 const struct
56 ReservationRequestMessage *message);
56 57
57 58
58/** 59/**
@@ -61,13 +62,13 @@ GAS_handle_reservation_request(struct GNUNET_SERVICE_Client *client,
61 * @param server handle to our server 62 * @param server handle to our server
62 */ 63 */
63void 64void
64GAS_reservations_init(void); 65GAS_reservations_init (void);
65 66
66 67
67/** 68/**
68 * Shutdown reservations subsystem. 69 * Shutdown reservations subsystem.
69 */ 70 */
70void 71void
71GAS_reservations_done(void); 72GAS_reservations_done (void);
72 73
73#endif 74#endif
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index d50df9b2e..456c222a9 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/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 */
44int 44int
45GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client) 45GAS_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 */
64void 64void
65GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client) 65GAS_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,36 @@ 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 */
83void 83void
84GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, 84GAS_scheduling_transmit_address_suggestion (const struct
85 uint32_t session_id, 85 GNUNET_PeerIdentity *peer,
86 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 86 uint32_t session_id,
87 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 87 struct GNUNET_BANDWIDTH_Value32NBO
88 bandwidth_out,
89 struct GNUNET_BANDWIDTH_Value32NBO
90 bandwidth_in)
88{ 91{
89 struct GNUNET_MQ_Envelope *env; 92 struct GNUNET_MQ_Envelope *env;
90 struct AddressSuggestionMessage *msg; 93 struct AddressSuggestionMessage *msg;
91 94
92 if (NULL == my_client) 95 if (NULL == my_client)
93 return; 96 return;
94 GNUNET_STATISTICS_update(GSA_stats, 97 GNUNET_STATISTICS_update (GSA_stats,
95 "# address suggestions made", 98 "# address suggestions made",
96 1, 99 1,
97 GNUNET_NO); 100 GNUNET_NO);
98 env = GNUNET_MQ_msg(msg, 101 env = GNUNET_MQ_msg (msg,
99 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 102 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
100 msg->peer = *peer; 103 msg->peer = *peer;
101 msg->session_id = htonl(session_id); 104 msg->session_id = htonl (session_id);
102 msg->bandwidth_out = bandwidth_out; 105 msg->bandwidth_out = bandwidth_out;
103 msg->bandwidth_in = bandwidth_in; 106 msg->bandwidth_in = bandwidth_in;
104 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "ATS sends quota for peer `%s': (in/out) %u/%u\n", 108 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
106 GNUNET_i2s(peer), 109 GNUNET_i2s (peer),
107 (unsigned int)ntohl(bandwidth_in.value__), 110 (unsigned int) ntohl (bandwidth_in.value__),
108 (unsigned int)ntohl(bandwidth_out.value__)); 111 (unsigned int) ntohl (bandwidth_out.value__));
109 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client), 112 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
110 env); 113 env);
111} 114}
112 115
113 116
@@ -117,7 +120,7 @@ GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *pee
117 * @param m the request message 120 * @param m the request message
118 */ 121 */
119void 122void
120GAS_handle_address_add(const struct AddressAddMessage *m) 123GAS_handle_address_add (const struct AddressAddMessage *m)
121{ 124{
122 const char *address; 125 const char *address;
123 const char *plugin_name; 126 const char *plugin_name;
@@ -125,30 +128,30 @@ GAS_handle_address_add(const struct AddressAddMessage *m)
125 uint16_t plugin_name_length; 128 uint16_t plugin_name_length;
126 struct GNUNET_ATS_Properties prop; 129 struct GNUNET_ATS_Properties prop;
127 130
128 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Received `%s' message\n", 132 "Received `%s' message\n",
130 "ADDRESS_ADD"); 133 "ADDRESS_ADD");
131 address_length = ntohs(m->address_length); 134 address_length = ntohs (m->address_length);
132 plugin_name_length = ntohs(m->plugin_name_length); 135 plugin_name_length = ntohs (m->plugin_name_length);
133 address = (const char *)&m[1]; 136 address = (const char *) &m[1];
134 if (plugin_name_length != 0) 137 if (plugin_name_length != 0)
135 plugin_name = &address[address_length]; 138 plugin_name = &address[address_length];
136 else 139 else
137 plugin_name = ""; 140 plugin_name = "";
138 GNUNET_STATISTICS_update(GSA_stats, 141 GNUNET_STATISTICS_update (GSA_stats,
139 "# addresses created", 142 "# addresses created",
140 1, 143 1,
141 GNUNET_NO); 144 GNUNET_NO);
142 GNUNET_ATS_properties_ntoh(&prop, 145 GNUNET_ATS_properties_ntoh (&prop,
143 &m->properties); 146 &m->properties);
144 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop.scope); 147 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop.scope);
145 GAS_addresses_add(&m->peer, 148 GAS_addresses_add (&m->peer,
146 plugin_name, 149 plugin_name,
147 address, 150 address,
148 address_length, 151 address_length,
149 ntohl(m->address_local_info), 152 ntohl (m->address_local_info),
150 ntohl(m->session_id), 153 ntohl (m->session_id),
151 &prop); 154 &prop);
152} 155}
153 156
154 157
@@ -158,19 +161,19 @@ GAS_handle_address_add(const struct AddressAddMessage *m)
158 * @param m the request message 161 * @param m the request message
159 */ 162 */
160void 163void
161GAS_handle_address_update(const struct AddressUpdateMessage *m) 164GAS_handle_address_update (const struct AddressUpdateMessage *m)
162{ 165{
163 struct GNUNET_ATS_Properties prop; 166 struct GNUNET_ATS_Properties prop;
164 167
165 GNUNET_STATISTICS_update(GSA_stats, 168 GNUNET_STATISTICS_update (GSA_stats,
166 "# address updates received", 169 "# address updates received",
167 1, 170 1,
168 GNUNET_NO); 171 GNUNET_NO);
169 GNUNET_ATS_properties_ntoh(&prop, 172 GNUNET_ATS_properties_ntoh (&prop,
170 &m->properties); 173 &m->properties);
171 GAS_addresses_update(&m->peer, 174 GAS_addresses_update (&m->peer,
172 ntohl(m->session_id), 175 ntohl (m->session_id),
173 &prop); 176 &prop);
174} 177}
175 178
176 179
@@ -180,26 +183,26 @@ GAS_handle_address_update(const struct AddressUpdateMessage *m)
180 * @param m the request message 183 * @param m the request message
181 */ 184 */
182void 185void
183GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m) 186GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
184{ 187{
185 struct GNUNET_MQ_Envelope *env; 188 struct GNUNET_MQ_Envelope *env;
186 struct GNUNET_ATS_SessionReleaseMessage *srm; 189 struct GNUNET_ATS_SessionReleaseMessage *srm;
187 190
188 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Received `%s' message\n", 192 "Received `%s' message\n",
190 "ADDRESS_DESTROYED"); 193 "ADDRESS_DESTROYED");
191 GNUNET_STATISTICS_update(GSA_stats, 194 GNUNET_STATISTICS_update (GSA_stats,
192 "# addresses destroyed", 195 "# addresses destroyed",
193 1, 196 1,
194 GNUNET_NO); 197 GNUNET_NO);
195 GAS_addresses_destroy(&m->peer, 198 GAS_addresses_destroy (&m->peer,
196 ntohl(m->session_id)); 199 ntohl (m->session_id));
197 env = GNUNET_MQ_msg(srm, 200 env = GNUNET_MQ_msg (srm,
198 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 201 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
199 srm->session_id = m->session_id; 202 srm->session_id = m->session_id;
200 srm->peer = m->peer; 203 srm->peer = m->peer;
201 GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(my_client), 204 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
202 env); 205 env);
203} 206}
204 207
205 208
diff --git a/src/ats/gnunet-service-ats_scheduling.h b/src/ats/gnunet-service-ats_scheduling.h
index b2575ca60..d68306988 100644
--- a/src/ats/gnunet-service-ats_scheduling.h
+++ b/src/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 */
39int 39int
40GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client); 40GAS_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 */
49void 49void
50GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client); 50GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client);
51 51
52 52
53/** 53/**
@@ -60,10 +60,13 @@ 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 */
62void 62void
63GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, 63GAS_scheduling_transmit_address_suggestion (const struct
64 uint32_t session_id, 64 GNUNET_PeerIdentity *peer,
65 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 65 uint32_t session_id,
66 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); 66 struct GNUNET_BANDWIDTH_Value32NBO
67 bandwidth_out,
68 struct GNUNET_BANDWIDTH_Value32NBO
69 bandwidth_in);
67 70
68 71
69/** 72/**
@@ -73,7 +76,7 @@ GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *pee
73 * @param m the request message 76 * @param m the request message
74 */ 77 */
75void 78void
76GAS_handle_address_add(const struct AddressAddMessage *m); 79GAS_handle_address_add (const struct AddressAddMessage *m);
77 80
78 81
79/** 82/**
@@ -82,7 +85,7 @@ GAS_handle_address_add(const struct AddressAddMessage *m);
82 * @param m the request message 85 * @param m the request message
83 */ 86 */
84void 87void
85GAS_handle_address_update(const struct AddressUpdateMessage *m); 88GAS_handle_address_update (const struct AddressUpdateMessage *m);
86 89
87 90
88/** 91/**
@@ -91,7 +94,7 @@ GAS_handle_address_update(const struct AddressUpdateMessage *m);
91 * @param m the request message 94 * @param m the request message
92 */ 95 */
93void 96void
94GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m); 97GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m);
95 98
96 99
97#endif 100#endif
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c
index 6a4eadad7..5f10addaf 100644
--- a/src/ats/perf_ats_solver.c
+++ b/src/ats/perf_ats_solver.c
@@ -49,7 +49,8 @@ struct GNUNET_STATISTICS_Handle *GSA_stats;
49/** 49/**
50 * Handle for ATS address component 50 * Handle for ATS address component
51 */ 51 */
52struct PerfHandle { 52struct PerfHandle
53{
53 /** 54 /**
54 * Performance peers 55 * Performance peers
55 */ 56 */
@@ -164,7 +165,8 @@ struct PerfHandle {
164/** 165/**
165 * Data structure to store results for a single iteration 166 * Data structure to store results for a single iteration
166 */ 167 */
167struct Iteration { 168struct Iteration
169{
168 struct Result **results_array; 170 struct Result **results_array;
169 171
170 struct Result **update_results_array; 172 struct Result **update_results_array;
@@ -174,7 +176,8 @@ struct Iteration {
174/** 176/**
175 * Result for a solver calculcation 177 * Result for a solver calculcation
176 */ 178 */
177struct Result { 179struct Result
180{
178 /** 181 /**
179 * Previous element in the linked list 182 * Previous element in the linked list
180 */ 183 */
@@ -280,7 +283,8 @@ struct Result {
280/** 283/**
281 * Peer used for the benchmarking 284 * Peer used for the benchmarking
282 */ 285 */
283struct PerfPeer { 286struct PerfPeer
287{
284 /** 288 /**
285 * Peer identitity 289 * Peer identitity
286 */ 290 */
@@ -313,19 +317,19 @@ static int ret;
313 * Do shutdown 317 * Do shutdown
314 */ 318 */
315static void 319static void
316end_now(int res) 320end_now (int res)
317{ 321{
318 if (NULL != ph.stat) 322 if (NULL != ph.stat)
319 { 323 {
320 GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); 324 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
321 ph.stat = NULL; 325 ph.stat = NULL;
322 } 326 }
323 327
324 GNUNET_free_non_null(ph.peers); 328 GNUNET_free_non_null (ph.peers);
325 GNUNET_free_non_null(ph.iterations_results); 329 GNUNET_free_non_null (ph.iterations_results);
326 330
327 GAS_normalization_stop(); 331 GAS_normalization_stop ();
328 GAS_preference_done(); 332 GAS_preference_done ();
329 ret = res; 333 ret = res;
330} 334}
331 335
@@ -336,12 +340,13 @@ end_now(int res)
336 * @param cp the number of the peer 340 * @param cp the number of the peer
337 */ 341 */
338static void 342static void
339perf_create_peer(int cp) 343perf_create_peer (int cp)
340{ 344{
341 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, 345 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
342 &ph.peers[cp].id, sizeof(struct GNUNET_PeerIdentity)); 346 &ph.peers[cp].id, sizeof(struct
343 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp, 347 GNUNET_PeerIdentity));
344 GNUNET_i2s(&ph.peers[cp].id)); 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer #%u: %s \n", cp,
349 GNUNET_i2s (&ph.peers[cp].id));
345} 350}
346 351
347 352
@@ -351,117 +356,118 @@ perf_create_peer(int cp)
351 * @param cur the address to update 356 * @param cur the address to update
352 */ 357 */
353static void 358static void
354perf_update_address(struct ATS_Address *cur) 359perf_update_address (struct ATS_Address *cur)
355{ 360{
356 int r_type; 361 int r_type;
357 int abs_val; 362 int abs_val;
358 double rel_val; 363 double rel_val;
359 364
360 r_type = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); 365 r_type = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2);
361 switch (r_type) 366 switch (r_type)
362 { 367 {
363 case 0: 368 case 0:
364 abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 369 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
365 rel_val = (100 + (double)abs_val) / 100; 370 rel_val = (100 + (double) abs_val) / 100;
366 371
367 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 372 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
368 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", 373 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
369 GNUNET_i2s(&cur->peer), cur, 374 GNUNET_i2s (&cur->peer), cur,
370 "GNUNET_ATS_QUALITY_NET_DELAY", 375 "GNUNET_ATS_QUALITY_NET_DELAY",
371 abs_val, rel_val); 376 abs_val, rel_val);
372 ph.sf->s_address_update_property(ph.sf->cls, cur, 377 ph.sf->s_address_update_property (ph.sf->cls, cur,
373 GNUNET_ATS_QUALITY_NET_DELAY, 378 GNUNET_ATS_QUALITY_NET_DELAY,
374 abs_val, rel_val); 379 abs_val, rel_val);
375 break; 380 break;
376 381
377 case 1: 382 case 1:
378 abs_val = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); 383 abs_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
379 rel_val = (100 + (double)abs_val) / 100; 384 rel_val = (100 + (double) abs_val) / 100;
380 385
381 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 386 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
382 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", 387 "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n",
383 GNUNET_i2s(&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", 388 GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE",
384 abs_val, rel_val); 389 abs_val, rel_val);
385 ph.sf->s_address_update_property(ph.sf->cls, cur, 390 ph.sf->s_address_update_property (ph.sf->cls, cur,
386 GNUNET_ATS_QUALITY_NET_DISTANCE, 391 GNUNET_ATS_QUALITY_NET_DISTANCE,
387 abs_val, rel_val); 392 abs_val, rel_val);
388 break; 393 break;
389 394
390 default: 395 default:
391 break; 396 break;
392 } 397 }
393} 398}
394 399
395 400
396static void 401static void
397bandwidth_changed_cb(void *cls, 402bandwidth_changed_cb (void *cls,
398 struct ATS_Address *address) 403 struct ATS_Address *address)
399{ 404{
400 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in)) 405 if ((0 == address->assigned_bw_out) && (0 == address->assigned_bw_in))
401 return; 406 return;
402 407
403 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
404 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n", 409 "Bandwidth changed addresses %s %p to %u Bps out / %u Bps in\n",
405 GNUNET_i2s(&address->peer), 410 GNUNET_i2s (&address->peer),
406 address, 411 address,
407 address->assigned_bw_out, 412 address->assigned_bw_out,
408 address->assigned_bw_in); 413 address->assigned_bw_in);
409 if (GNUNET_YES == ph.bulk_running) 414 if (GNUNET_YES == ph.bulk_running)
410 GNUNET_break(0); 415 GNUNET_break (0);
411 return; 416 return;
412} 417}
413 418
414 419
415static const double * 420static const double *
416get_preferences_cb(void *cls, const struct GNUNET_PeerIdentity *id) 421get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id)
417{ 422{
418 return GAS_preference_get_by_peer(NULL, id); 423 return GAS_preference_get_by_peer (NULL, id);
419} 424}
420 425
421 426
422static void 427static void
423perf_address_initial_update(void *dead, 428perf_address_initial_update (void *dead,
424 struct GNUNET_CONTAINER_MultiPeerMap * addresses, 429 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
425 struct ATS_Address *address) 430 struct ATS_Address *address)
426{ 431{
427 double delay; 432 double delay;
428 double distance; 433 double distance;
429 uint32_t random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 434 uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
430 435
431 delay = (100 + (double)random) / 100; 436 delay = (100 + (double) random) / 100;
432 ph.sf->s_address_update_property(ph.sf->cls, 437 ph.sf->s_address_update_property (ph.sf->cls,
433 address, GNUNET_ATS_QUALITY_NET_DELAY, 438 address, GNUNET_ATS_QUALITY_NET_DELAY,
434 100, delay); 439 100, delay);
435 440
436 random = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 100); 441 random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100);
437 distance = (100 + (double)random) / 100; 442 distance = (100 + (double) random) / 100;
438 443
439 ph.sf->s_address_update_property(ph.sf->cls, address, 444 ph.sf->s_address_update_property (ph.sf->cls, address,
440 GNUNET_ATS_QUALITY_NET_DISTANCE, 445 GNUNET_ATS_QUALITY_NET_DISTANCE,
441 10, distance); 446 10, distance);
442 447
443 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 448 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
444 "Initial update address %p : %.2f %.2f\n", 449 "Initial update address %p : %.2f %.2f\n",
445 address, delay, distance); 450 address, delay, distance);
446} 451}
447 452
448 453
449struct DUA_Ctx { 454struct DUA_Ctx
455{
450 int r; 456 int r;
451 int c_cur_a; 457 int c_cur_a;
452}; 458};
453 459
454 460
455static int 461static int
456do_update_address(void *cls, 462do_update_address (void *cls,
457 const struct GNUNET_PeerIdentity *pid, 463 const struct GNUNET_PeerIdentity *pid,
458 void *value) 464 void *value)
459{ 465{
460 struct DUA_Ctx *ctx = cls; 466 struct DUA_Ctx *ctx = cls;
461 struct ATS_Address *addr = value; 467 struct ATS_Address *addr = value;
462 468
463 if (ctx->c_cur_a == ctx->r) 469 if (ctx->c_cur_a == ctx->r)
464 perf_update_address(addr); 470 perf_update_address (addr);
465 ctx->c_cur_a++; 471 ctx->c_cur_a++;
466 return GNUNET_OK; 472 return GNUNET_OK;
467} 473}
@@ -475,7 +481,8 @@ do_update_address(void *cls,
475 * @param percentage_peers the percentage of peers to update 481 * @param percentage_peers the percentage of peers to update
476 */ 482 */
477static void 483static void
478perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percentage_peers) 484perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int
485 percentage_peers)
479{ 486{
480 int c_peer; 487 int c_peer;
481 int c_select; 488 int c_select;
@@ -485,9 +492,9 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
485 unsigned int m[cp]; 492 unsigned int m[cp];
486 struct DUA_Ctx dua_ctx; 493 struct DUA_Ctx dua_ctx;
487 494
488 count = cp * ((double)percentage_peers / 100); 495 count = cp * ((double) percentage_peers / 100);
489 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 496 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
490 "Updating %u of %u peers \n", count, cp); 497 "Updating %u of %u peers \n", count, cp);
491 498
492 for (c_peer = 0; c_peer < cp; c_peer++) 499 for (c_peer = 0; c_peer < cp; c_peer++)
493 m[c_peer] = 0; 500 m[c_peer] = 0;
@@ -495,32 +502,32 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
495 c_select = 0; 502 c_select = 0;
496 503
497 while (c_select < count) 504 while (c_select < count)
505 {
506 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, cp);
507 if (0 == m[r])
498 { 508 {
499 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, cp); 509 m[r] = 1;
500 if (0 == m[r]) 510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
501 { 511 "Updating peer [%u] \n", r);
502 m[r] = 1; 512 c_select++;
503 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
504 "Updating peer [%u] \n", r);
505 c_select++;
506 }
507 } 513 }
514 }
508 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++) 515 for (c_cur_p = 0; c_cur_p < cp; c_cur_p++)
516 {
517 if (1 == m[c_cur_p])
509 { 518 {
510 if (1 == m[c_cur_p]) 519 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca);
511 { 520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
512 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, ca); 521 "Updating peer [%u] address [%u]\n", c_cur_p, r);
513 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 522
514 "Updating peer [%u] address [%u]\n", c_cur_p, r); 523 dua_ctx.c_cur_a = 0;
515 524 dua_ctx.r = r;
516 dua_ctx.c_cur_a = 0; 525 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
517 dua_ctx.r = r; 526 &ph.peers[c_cur_p].id,
518 GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, 527 &do_update_address,
519 &ph.peers[c_cur_p].id, 528 &dua_ctx);
520 &do_update_address,
521 &dua_ctx);
522 }
523 } 529 }
530 }
524} 531}
525 532
526/** 533/**
@@ -531,14 +538,14 @@ perf_update_all_addresses(unsigned int cp, unsigned int ca, unsigned int percent
531 * @return the address 538 * @return the address
532 */ 539 */
533static struct ATS_Address * 540static struct ATS_Address *
534perf_create_address(int cp, int ca) 541perf_create_address (int cp, int ca)
535{ 542{
536 struct ATS_Address *a; 543 struct ATS_Address *a;
537 544
538 a = create_address(&ph.peers[cp].id, 545 a = create_address (&ph.peers[cp].id,
539 "Test 1", "test 1", strlen("test 1") + 1, 0); 546 "Test 1", "test 1", strlen ("test 1") + 1, 0);
540 GNUNET_CONTAINER_multipeermap_put(ph.addresses, &ph.peers[cp].id, a, 547 GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a,
541 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 548 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
542 return a; 549 return a;
543} 550}
544 551
@@ -551,252 +558,264 @@ perf_create_address(int cp, int ca)
551 * @param add additional solver information 558 * @param add additional solver information
552 */ 559 */
553static void 560static void
554solver_info_cb(void *cls, 561solver_info_cb (void *cls,
555 enum GAS_Solver_Operation op, 562 enum GAS_Solver_Operation op,
556 enum GAS_Solver_Status stat, 563 enum GAS_Solver_Status stat,
557 enum GAS_Solver_Additional_Information add) 564 enum GAS_Solver_Additional_Information add)
558{ 565{
559 char *add_info; 566 char *add_info;
560 567
561 switch (add) 568 switch (add)
562 { 569 {
563 case GAS_INFO_NONE: 570 case GAS_INFO_NONE:
564 add_info = "GAS_INFO_NONE"; 571 add_info = "GAS_INFO_NONE";
565 break; 572 break;
566 573
567 case GAS_INFO_FULL: 574 case GAS_INFO_FULL:
568 add_info = "GAS_INFO_MLP_FULL"; 575 add_info = "GAS_INFO_MLP_FULL";
569 break; 576 break;
570 577
571 case GAS_INFO_UPDATED: 578 case GAS_INFO_UPDATED:
572 add_info = "GAS_INFO_MLP_UPDATED"; 579 add_info = "GAS_INFO_MLP_UPDATED";
573 break; 580 break;
574 581
575 case GAS_INFO_PROP_ALL: 582 case GAS_INFO_PROP_ALL:
576 add_info = "GAS_INFO_PROP_ALL"; 583 add_info = "GAS_INFO_PROP_ALL";
577 break; 584 break;
578 585
579 case GAS_INFO_PROP_SINGLE: 586 case GAS_INFO_PROP_SINGLE:
580 add_info = "GAS_INFO_PROP_SINGLE"; 587 add_info = "GAS_INFO_PROP_SINGLE";
581 break; 588 break;
582 589
583 default: 590 default:
584 add_info = "INVALID"; 591 add_info = "INVALID";
585 break; 592 break;
586 } 593 }
587 594
588 struct Result *tmp; 595 struct Result *tmp;
589 switch (op) 596 switch (op)
597 {
598 case GAS_OP_SOLVE_START:
599 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
600 "Solver notifies `%s' with result `%s' `%s'\n",
601 "GAS_OP_SOLVE_START",
602 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
603 if (GNUNET_NO == ph.expecting_solution)
590 { 604 {
591 case GAS_OP_SOLVE_START: 605 /* We do not expect a solution at the moment */
592 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 606 GNUNET_break (0);
593 "Solver notifies `%s' with result `%s' `%s'\n", "GAS_OP_SOLVE_START",
594 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
595 if (GNUNET_NO == ph.expecting_solution)
596 {
597 /* We do not expect a solution at the moment */
598 GNUNET_break(0);
599 return;
600 }
601
602 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
603 {
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 }
635 }
636 return; 607 return;
608 }
637 609
638 case GAS_OP_SOLVE_STOP: 610 if ((GAS_STAT_SUCCESS == stat) && (NULL == ph.current_result))
639 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 611 {
640 "Solver notifies `%s' with result `%s', `%s'\n", "GAS_OP_SOLVE_STOP", 612 tmp = GNUNET_new (struct Result);
641 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info); 613 /* Create new result */
642 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result)) 614 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
643 { 615 {
644 /* We do not expect a solution at the moment */ 616 ph.current_result = tmp;
645 GNUNET_break(0); 617 // fprintf (stderr,"UPDATE %u %u\n",ph.current_iteration-1, ph.current_p);
646 return; 618 ph.iterations_results[ph.current_iteration
647 } 619 - 1].update_results_array[ph.current_p] = tmp;
648 620 }
649 if (GAS_STAT_SUCCESS == stat)
650 ph.current_result->valid = GNUNET_YES;
651 else 621 else
652 ph.current_result->valid = GNUNET_NO; 622 {
623 ph.current_result = tmp;
624 // fprintf (stderr,"FULL %u %u\n",ph.current_iteration-1, ph.current_p);
625 ph.iterations_results[ph.current_iteration
626 - 1].results_array[ph.current_p] = tmp;
627 }
628
629 ph.current_result->addresses = ph.current_a;
630 ph.current_result->peers = ph.current_p;
631 ph.current_result->s_total = GNUNET_TIME_absolute_get ();
632 ph.current_result->d_total_full = GNUNET_TIME_UNIT_FOREVER_REL;
633 ph.current_result->d_setup_full = GNUNET_TIME_UNIT_FOREVER_REL;
634 ph.current_result->d_lp_full = GNUNET_TIME_UNIT_FOREVER_REL;
635 ph.current_result->d_mlp_full = GNUNET_TIME_UNIT_FOREVER_REL;
636 ph.current_result->info = add;
637 if ((add == GAS_INFO_UPDATED) || (GNUNET_YES == ph.performed_update))
638 {
639 ph.current_result->update = GNUNET_YES;
640 }
641 else
642 {
643 ph.current_result->update = GNUNET_NO;
644 }
645 }
646 return;
653 647
654 if (NULL != ph.current_result) 648 case GAS_OP_SOLVE_STOP:
655 { 649 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
656 /* Finalize result */ 650 "Solver notifies `%s' with result `%s', `%s'\n",
657 ph.current_result->e_total = GNUNET_TIME_absolute_get(); 651 "GAS_OP_SOLVE_STOP",
658 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference( 652 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL", add_info);
659 ph.current_result->s_total, ph.current_result->e_total); 653 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
660 } 654 {
661 ph.current_result = NULL; 655 /* We do not expect a solution at the moment */
656 GNUNET_break (0);
662 return; 657 return;
658 }
663 659
664 case GAS_OP_SOLVE_SETUP_START: 660 if (GAS_STAT_SUCCESS == stat)
665 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 661 ph.current_result->valid = GNUNET_YES;
666 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_START", 662 else
667 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 663 ph.current_result->valid = GNUNET_NO;
668 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
669 {
670 GNUNET_break(0);
671 return;
672 }
673 664
674 if (GAS_STAT_SUCCESS == stat) 665 if (NULL != ph.current_result)
675 ph.current_result->valid = GNUNET_YES; 666 {
676 else 667 /* Finalize result */
677 ph.current_result->valid = GNUNET_NO; 668 ph.current_result->e_total = GNUNET_TIME_absolute_get ();
669 ph.current_result->d_total_full = GNUNET_TIME_absolute_get_difference (
670 ph.current_result->s_total, ph.current_result->e_total);
671 }
672 ph.current_result = NULL;
673 return;
678 674
679 ph.current_result->s_setup = GNUNET_TIME_absolute_get(); 675 case GAS_OP_SOLVE_SETUP_START:
676 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
677 "Solver notifies `%s' with result `%s'\n",
678 "GAS_OP_SOLVE_SETUP_START",
679 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
680 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
681 {
682 GNUNET_break (0);
680 return; 683 return;
684 }
681 685
682 case GAS_OP_SOLVE_SETUP_STOP: 686 if (GAS_STAT_SUCCESS == stat)
683 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 687 ph.current_result->valid = GNUNET_YES;
684 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_SETUP_STOP", 688 else
685 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 689 ph.current_result->valid = GNUNET_NO;
686 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
687 {
688 GNUNET_break(0);
689 return;
690 }
691 690
692 if (GAS_STAT_SUCCESS == stat) 691 ph.current_result->s_setup = GNUNET_TIME_absolute_get ();
693 ph.current_result->valid = GNUNET_YES; 692 return;
694 else
695 ph.current_result->valid = GNUNET_NO;
696 693
697 ph.current_result->e_setup = GNUNET_TIME_absolute_get(); 694 case GAS_OP_SOLVE_SETUP_STOP:
698 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference( 695 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
699 ph.current_result->s_setup, ph.current_result->e_setup); 696 "Solver notifies `%s' with result `%s'\n",
697 "GAS_OP_SOLVE_SETUP_STOP",
698 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
699 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
700 {
701 GNUNET_break (0);
700 return; 702 return;
703 }
701 704
702 case GAS_OP_SOLVE_MLP_LP_START: 705 if (GAS_STAT_SUCCESS == stat)
703 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 706 ph.current_result->valid = GNUNET_YES;
704 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_START", 707 else
705 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 708 ph.current_result->valid = GNUNET_NO;
706 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
707 {
708 GNUNET_break(0);
709 return;
710 }
711 709
712 if (GAS_STAT_SUCCESS == stat) 710 ph.current_result->e_setup = GNUNET_TIME_absolute_get ();
713 ph.current_result->valid = GNUNET_YES; 711 ph.current_result->d_setup_full = GNUNET_TIME_absolute_get_difference (
714 else 712 ph.current_result->s_setup, ph.current_result->e_setup);
715 ph.current_result->valid = GNUNET_NO; 713 return;
716 714
717 ph.current_result->s_lp = GNUNET_TIME_absolute_get(); 715 case GAS_OP_SOLVE_MLP_LP_START:
716 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
717 "Solver notifies `%s' with result `%s'\n",
718 "GAS_OP_SOLVE_LP_START",
719 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
720 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
721 {
722 GNUNET_break (0);
718 return; 723 return;
724 }
719 725
720 case GAS_OP_SOLVE_MLP_LP_STOP: 726 if (GAS_STAT_SUCCESS == stat)
721 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 727 ph.current_result->valid = GNUNET_YES;
722 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_LP_STOP", 728 else
723 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 729 ph.current_result->valid = GNUNET_NO;
724 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
725 {
726 GNUNET_break(0);
727 return;
728 }
729 730
730 if (GAS_STAT_SUCCESS == stat) 731 ph.current_result->s_lp = GNUNET_TIME_absolute_get ();
731 ph.current_result->valid = GNUNET_YES; 732 return;
732 else
733 ph.current_result->valid = GNUNET_NO;
734 733
735 ph.current_result->e_lp = GNUNET_TIME_absolute_get(); 734 case GAS_OP_SOLVE_MLP_LP_STOP:
736 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference( 735 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
737 ph.current_result->s_lp, ph.current_result->e_lp); 736 "Solver notifies `%s' with result `%s'\n",
737 "GAS_OP_SOLVE_LP_STOP",
738 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
739 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
740 {
741 GNUNET_break (0);
738 return; 742 return;
743 }
739 744
740 case GAS_OP_SOLVE_MLP_MLP_START: 745 if (GAS_STAT_SUCCESS == stat)
741 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 746 ph.current_result->valid = GNUNET_YES;
742 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_START", 747 else
743 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 748 ph.current_result->valid = GNUNET_NO;
744 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
745 {
746 GNUNET_break(0);
747 return;
748 }
749 749
750 if (GAS_STAT_SUCCESS == stat) 750 ph.current_result->e_lp = GNUNET_TIME_absolute_get ();
751 ph.current_result->valid = GNUNET_YES; 751 ph.current_result->d_lp_full = GNUNET_TIME_absolute_get_difference (
752 else 752 ph.current_result->s_lp, ph.current_result->e_lp);
753 ph.current_result->valid = GNUNET_NO; 753 return;
754 754
755 ph.current_result->s_mlp = GNUNET_TIME_absolute_get(); 755 case GAS_OP_SOLVE_MLP_MLP_START:
756 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
757 "Solver notifies `%s' with result `%s'\n",
758 "GAS_OP_SOLVE_MLP_START",
759 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
760 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
761 {
762 GNUNET_break (0);
756 return; 763 return;
764 }
757 765
758 case GAS_OP_SOLVE_MLP_MLP_STOP: 766 if (GAS_STAT_SUCCESS == stat)
759 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 767 ph.current_result->valid = GNUNET_YES;
760 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_MLP_STOP", 768 else
761 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 769 ph.current_result->valid = GNUNET_NO;
762 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
763 {
764 GNUNET_break(0);
765 return;
766 }
767 770
768 if (GAS_STAT_SUCCESS == stat) 771 ph.current_result->s_mlp = GNUNET_TIME_absolute_get ();
769 ph.current_result->valid = GNUNET_YES; 772 return;
770 else
771 ph.current_result->valid = GNUNET_NO;
772 773
773 ph.current_result->e_mlp = GNUNET_TIME_absolute_get(); 774 case GAS_OP_SOLVE_MLP_MLP_STOP:
774 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference( 775 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
775 ph.current_result->s_mlp, ph.current_result->e_mlp); 776 "Solver notifies `%s' with result `%s'\n",
777 "GAS_OP_SOLVE_MLP_STOP",
778 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
779 if ((GNUNET_NO == ph.expecting_solution) || (NULL == ph.current_result))
780 {
781 GNUNET_break (0);
776 return; 782 return;
783 }
777 784
778 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START: 785 if (GAS_STAT_SUCCESS == stat)
779 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 786 ph.current_result->valid = GNUNET_YES;
780 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START", 787 else
781 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 788 ph.current_result->valid = GNUNET_NO;
782 return;
783 789
784 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP: 790 ph.current_result->e_mlp = GNUNET_TIME_absolute_get ();
785 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 791 ph.current_result->d_mlp_full = GNUNET_TIME_absolute_get_difference (
786 "Solver notifies `%s' with result `%s'\n", "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP", 792 ph.current_result->s_mlp, ph.current_result->e_mlp);
787 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL"); 793 return;
788 if (GAS_STAT_SUCCESS != stat)
789 {
790 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
791 "Solver `%s' failed to update problem with %u peers and %u address!\n",
792 ph.ats_string, ph.current_p, ph.current_a);
793 }
794 794
795 return; 795 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_START:
796 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
797 "Solver notifies `%s' with result `%s'\n",
798 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_START",
799 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
800 return;
796 801
797 default: 802 case GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP:
798 break; 803 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
804 "Solver notifies `%s' with result `%s'\n",
805 "GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP",
806 (GAS_STAT_SUCCESS == stat) ? "SUCCESS" : "FAIL");
807 if (GAS_STAT_SUCCESS != stat)
808 {
809 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
810 "Solver `%s' failed to update problem with %u peers and %u address!\n",
811 ph.ats_string, ph.current_p, ph.current_a);
799 } 812 }
813
814 return;
815
816 default:
817 break;
818 }
800} 819}
801 820
802/** 821/**
@@ -805,82 +824,86 @@ solver_info_cb(void *cls,
805 * @param iteration the iteration to evaluate 824 * @param iteration the iteration to evaluate
806 */ 825 */
807static void 826static void
808evaluate(int iteration) 827evaluate (int iteration)
809{ 828{
810 struct Result *cur; 829 struct Result *cur;
811 int cp; 830 int cp;
812 831
813 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp++) 832 for (cp = ph.N_peers_start; cp <= ph.N_peers_end; cp++)
833 {
834 cur = ph.iterations_results[ph.current_iteration - 1].results_array[cp];
835 if (0 == cp)
836 continue;
837 if (NULL == cur)
814 { 838 {
815 cur = ph.iterations_results[ph.current_iteration - 1].results_array[cp]; 839 GNUNET_break (0);
816 if (0 == cp) 840 fprintf (stderr,
817 continue; 841 "Missing result for %u peers\n", cp);
818 if (NULL == cur) 842 continue;
819 { 843 }
820 GNUNET_break(0);
821 fprintf(stderr,
822 "Missing result for %u peers\n", cp);
823 continue;
824 }
825 844
826 845
827 if (GNUNET_NO == cur->valid) 846 if (GNUNET_NO == cur->valid)
828 { 847 {
829 fprintf(stderr, 848 fprintf (stderr,
830 "Total time to solve %s for %u peers %u addresses: %s\n", 849 "Total time to solve %s for %u peers %u addresses: %s\n",
831 (GNUNET_YES == cur->update) ? "updated" : "full", 850 (GNUNET_YES == cur->update) ? "updated" : "full",
832 cur->peers, cur->addresses, "Failed to solve!"); 851 cur->peers, cur->addresses, "Failed to solve!");
833 continue; 852 continue;
834 } 853 }
835 854
836 855
837 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_total_full.rel_value_us) 856 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
838 { 857 cur->d_total_full.rel_value_us)
839 fprintf(stderr, 858 {
840 "Total time to solve %s for %u peers %u addresses: %llu us\n", 859 fprintf (stderr,
841 (GNUNET_YES == cur->update) ? "updated" : "full", 860 "Total time to solve %s for %u peers %u addresses: %llu us\n",
842 cur->peers, cur->addresses, 861 (GNUNET_YES == cur->update) ? "updated" : "full",
843 (unsigned long long)cur->d_total_full.rel_value_us); 862 cur->peers, cur->addresses,
844 } 863 (unsigned long long) cur->d_total_full.rel_value_us);
864 }
845 865
846 866
847 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_setup_full.rel_value_us) 867 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
848 { 868 cur->d_setup_full.rel_value_us)
849 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 869 {
850 "Total time to setup %s %u peers %u addresses: %llu us\n", 870 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
851 (GNUNET_YES == cur->update) ? "updated" : "full", 871 "Total time to setup %s %u peers %u addresses: %llu us\n",
852 cur->peers, cur->addresses, 872 (GNUNET_YES == cur->update) ? "updated" : "full",
853 (unsigned long long)cur->d_setup_full.rel_value_us); 873 cur->peers, cur->addresses,
854 } 874 (unsigned long long) cur->d_setup_full.rel_value_us);
875 }
855 876
856 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_lp_full.rel_value_us) 877 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
857 { 878 cur->d_lp_full.rel_value_us)
858 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 879 {
859 "Total time to solve %s LP for %u peers %u addresses: %llu us\n", 880 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
860 (GNUNET_YES == cur->update) ? "updated" : "full", 881 "Total time to solve %s LP for %u peers %u addresses: %llu us\n",
861 cur->peers, 882 (GNUNET_YES == cur->update) ? "updated" : "full",
862 cur->addresses, 883 cur->peers,
863 (unsigned long long )cur->d_lp_full.rel_value_us); 884 cur->addresses,
864 } 885 (unsigned long long ) cur->d_lp_full.rel_value_us);
886 }
865 887
866 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != cur->d_mlp_full.rel_value_us) 888 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us !=
867 { 889 cur->d_mlp_full.rel_value_us)
868 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 890 {
869 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n", 891 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
870 (GNUNET_YES == cur->update) ? "updated" : "full", 892 "Total time to solve %s MLP for %u peers %u addresses: %llu us\n",
871 cur->peers, cur->addresses, 893 (GNUNET_YES == cur->update) ? "updated" : "full",
872 (unsigned long long )cur->d_mlp_full.rel_value_us); 894 cur->peers, cur->addresses,
873 } 895 (unsigned long long ) cur->d_mlp_full.rel_value_us);
874 } 896 }
897 }
875} 898}
876 899
877 900
878static unsigned int 901static unsigned int
879get_connectivity_cb(void *cls, 902get_connectivity_cb (void *cls,
880 const struct GNUNET_PeerIdentity *peer) 903 const struct GNUNET_PeerIdentity *peer)
881{ 904{
882 return GNUNET_CONTAINER_multipeermap_contains(ph.addresses, 905 return GNUNET_CONTAINER_multipeermap_contains (ph.addresses,
883 peer); 906 peer);
884} 907}
885 908
886 909
@@ -888,16 +911,16 @@ get_connectivity_cb(void *cls,
888 * Evaluate average results for all iterations 911 * Evaluate average results for all iterations
889 */ 912 */
890static void 913static void
891write_all_iterations(void) 914write_all_iterations (void)
892{ 915{
893 int c_iteration; 916 int c_iteration;
894 int c_peer; 917 int c_peer;
895 918
896 struct GNUNET_DISK_FileHandle *f_full; 919 struct GNUNET_DISK_FileHandle *f_full;
897 struct GNUNET_DISK_FileHandle *f_update; 920 struct GNUNET_DISK_FileHandle *f_update;
898 char * data_fn_full; 921 char *data_fn_full;
899 char * data_fn_update; 922 char *data_fn_update;
900 char * data; 923 char *data;
901 924
902 f_full = NULL; 925 f_full = NULL;
903 f_update = NULL; 926 f_update = NULL;
@@ -907,179 +930,192 @@ write_all_iterations(void)
907 if (GNUNET_NO == ph.create_datafile) 930 if (GNUNET_NO == ph.create_datafile)
908 return; 931 return;
909 932
910 GNUNET_asprintf(&data_fn_full, 933 GNUNET_asprintf (&data_fn_full,
911 "perf_%s_full_%u-%u_%u_%u.data", 934 "perf_%s_full_%u-%u_%u_%u.data",
912 ph.ats_string, 935 ph.ats_string,
913 ph.total_iterations, 936 ph.total_iterations,
914 ph.N_peers_start, 937 ph.N_peers_start,
915 ph.N_peers_end, 938 ph.N_peers_end,
916 ph.N_address); 939 ph.N_address);
917 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 940 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
918 "Using data file `%s'\n", 941 "Using data file `%s'\n",
919 data_fn_full); 942 data_fn_full);
920 943
921 f_full = GNUNET_DISK_file_open(data_fn_full, 944 f_full = GNUNET_DISK_file_open (data_fn_full,
922 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 945 GNUNET_DISK_OPEN_WRITE
923 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 946 | GNUNET_DISK_OPEN_CREATE,
947 GNUNET_DISK_PERM_USER_EXEC
948 | GNUNET_DISK_PERM_USER_READ
949 | GNUNET_DISK_PERM_USER_WRITE);
924 if (NULL == f_full) 950 if (NULL == f_full)
925 { 951 {
926 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 952 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
927 "Cannot open data file `%s'\n", 953 "Cannot open data file `%s'\n",
928 data_fn_full); 954 data_fn_full);
929 GNUNET_free(data_fn_full); 955 GNUNET_free (data_fn_full);
930 return; 956 return;
931 } 957 }
932 958
933 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; 959 data =
934 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data, strlen(data))) 960 "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
935 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 961 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data, strlen (data)))
936 "Cannot write data to log file `%s'\n", 962 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
937 data_fn_full); 963 "Cannot write data to log file `%s'\n",
964 data_fn_full);
938 965
939 data_fn_update = NULL; 966 data_fn_update = NULL;
940 if (GNUNET_YES == ph.measure_updates) 967 if (GNUNET_YES == ph.measure_updates)
968 {
969 GNUNET_asprintf (&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data",
970 ph.ats_string,
971 ph.total_iterations,
972 ph.N_peers_start,
973 ph.N_peers_end,
974 ph.N_address);
975 f_update = GNUNET_DISK_file_open (data_fn_update,
976 GNUNET_DISK_OPEN_WRITE
977 | GNUNET_DISK_OPEN_CREATE,
978 GNUNET_DISK_PERM_USER_EXEC
979 | GNUNET_DISK_PERM_USER_READ
980 | GNUNET_DISK_PERM_USER_WRITE);
981 if (NULL == f_update)
941 { 982 {
942 GNUNET_asprintf(&data_fn_update, "perf_%s_update_%u-%u_%u_%u.data", 983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
943 ph.ats_string, 984 "Cannot open gnuplot file `%s'\n", data_fn_update);
944 ph.total_iterations, 985 GNUNET_free (data_fn_update);
945 ph.N_peers_start, 986 if (NULL != f_full)
946 ph.N_peers_end, 987 GNUNET_DISK_file_close (f_full);
947 ph.N_address); 988 GNUNET_free (data_fn_full);
948 f_update = GNUNET_DISK_file_open(data_fn_update, 989 return;
949 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, 990 }
950 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
951 if (NULL == f_update)
952 {
953 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
954 "Cannot open gnuplot file `%s'\n", data_fn_update);
955 GNUNET_free(data_fn_update);
956 if (NULL != f_full)
957 GNUNET_DISK_file_close(f_full);
958 GNUNET_free(data_fn_full);
959 return;
960 }
961 991
962 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 992 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
963 "Using update data file `%s'\n", 993 "Using update data file `%s'\n",
964 data_fn_update); 994 data_fn_update);
965 995
966 data = "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n"; 996 data =
967 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data, strlen(data))) 997 "#peers;addresses;time total in us;#time setup in us;#time lp in us;#time mlp in us;\n";
968 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 998 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data, strlen (data)))
969 "Cannot write data to log file `%s'\n", 999 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
970 data_fn_update); 1000 "Cannot write data to log file `%s'\n",
971 } 1001 data_fn_update);
1002 }
972 1003
973 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer++) 1004 for (c_peer = ph.N_peers_start; c_peer <= ph.N_peers_end; c_peer++)
1005 {
1006 char *data_str;
1007 char *data_tmp;
1008 char *data_upd_str;
1009 char *data_upd_tmp;
1010 GNUNET_asprintf (&data_str, "%u;%u", c_peer, ph.N_address);
1011 if (ph.measure_updates)
1012 GNUNET_asprintf (&data_upd_str, "%u;%u", c_peer, ph.N_address);
1013 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration++)
974 { 1014 {
975 char * data_str; 1015 struct Result *cur_full_res;
976 char * data_tmp; 1016 struct Result *cur_upd_res;
977 char * data_upd_str;
978 char * data_upd_tmp;
979 GNUNET_asprintf(&data_str, "%u;%u", c_peer, ph.N_address);
980 if (ph.measure_updates)
981 GNUNET_asprintf(&data_upd_str, "%u;%u", c_peer, ph.N_address);
982 for (c_iteration = 0; c_iteration < ph.total_iterations; c_iteration++)
983 {
984 struct Result *cur_full_res;
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);
1029 }
1030 data_tmp = GNUNET_strdup(data_str);
1031 GNUNET_free(data_str);
1032 GNUNET_asprintf(&data_str, "%s\n", data_tmp);
1033 GNUNET_free(data_tmp);
1034 1017
1035 fprintf(stderr, "Result full solution: %s\n", data_str); 1018
1036 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_full, data_str, strlen(data_str))) 1019
1037 GNUNET_break(0); 1020 // fprintf (stderr, "P: %u I: %u == %p \n", c_peer, c_iteration, cur_res);
1038 GNUNET_free(data_str); 1021 cur_full_res = ph.iterations_results[c_iteration].results_array[c_peer];
1022 if (c_peer == 0)
1023 continue;
1024 if (NULL == cur_full_res)
1025 continue;
1039 1026
1040 if (ph.measure_updates) 1027 if (ph.measure_updates)
1028 {
1029 cur_upd_res =
1030 ph.iterations_results[c_iteration].update_results_array[c_peer];
1031 data_upd_tmp = GNUNET_strdup (data_upd_str);
1032 GNUNET_free (data_upd_str);
1033 if (GNUNET_YES == cur_full_res->valid)
1041 { 1034 {
1042 data_upd_tmp = GNUNET_strdup(data_upd_str); 1035 GNUNET_asprintf (&data_upd_str, "%s;%llu", data_upd_tmp,
1043 GNUNET_free(data_upd_str); 1036 (NULL == cur_upd_res) ? 0 :
1044 GNUNET_asprintf(&data_upd_str, "%s\n", data_upd_tmp); 1037 cur_upd_res->d_total_full.rel_value_us);
1045 GNUNET_free(data_upd_tmp);
1046
1047 fprintf(stderr, "Result updated solution: `%s'\n", data_upd_str);
1048 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_update, data_upd_str, strlen(data_upd_str)))
1049 GNUNET_break(0);
1050 GNUNET_free(data_upd_str);
1051 } 1038 }
1052 } 1039 else
1053 1040 {
1054 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_full))) 1041 GNUNET_asprintf (&data_upd_str, "%s;", data_upd_tmp);
1055 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1042 }
1056 data_fn_full); 1043 GNUNET_free (data_upd_tmp);
1057 GNUNET_free_non_null(data_fn_full); 1044 }
1045
1046 // fprintf (stderr, "P: %u I: %u: P %i A %i\n", c_peer, c_iteration, cur_res->peers, cur_res->addresses);
1047 // fprintf (stderr, "D total: %llu\n", (long long unsigned int) cur_res->d_total.rel_value_us);
1048
1049 data_tmp = GNUNET_strdup (data_str);
1050 GNUNET_free (data_str);
1051 if (GNUNET_YES == cur_full_res->valid)
1052 {
1053 GNUNET_asprintf (&data_str, "%s;%llu", data_tmp,
1054 cur_full_res->d_total_full.rel_value_us);
1055 }
1056 else
1057 {
1058 GNUNET_asprintf (&data_str, "%s;", data_tmp);
1059 }
1058 1060
1059 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close(f_update))) 1061 GNUNET_free (data_tmp);
1060 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", 1062 }
1061 data_fn_update); 1063 data_tmp = GNUNET_strdup (data_str);
1062 GNUNET_free_non_null(data_fn_update); 1064 GNUNET_free (data_str);
1065 GNUNET_asprintf (&data_str, "%s\n", data_tmp);
1066 GNUNET_free (data_tmp);
1067
1068 fprintf (stderr, "Result full solution: %s\n", data_str);
1069 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_full, data_str, strlen (
1070 data_str)))
1071 GNUNET_break (0);
1072 GNUNET_free (data_str);
1073
1074 if (ph.measure_updates)
1075 {
1076 data_upd_tmp = GNUNET_strdup (data_upd_str);
1077 GNUNET_free (data_upd_str);
1078 GNUNET_asprintf (&data_upd_str, "%s\n", data_upd_tmp);
1079 GNUNET_free (data_upd_tmp);
1080
1081 fprintf (stderr, "Result updated solution: `%s'\n", data_upd_str);
1082 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_update, data_upd_str,
1083 strlen (data_upd_str)))
1084 GNUNET_break (0);
1085 GNUNET_free (data_upd_str);
1086 }
1087 }
1088
1089 if ((NULL != f_full) && (GNUNET_SYSERR == GNUNET_DISK_file_close (f_full)))
1090 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1091 data_fn_full);
1092 GNUNET_free_non_null (data_fn_full);
1093
1094 if ((NULL != f_update) && (GNUNET_SYSERR == GNUNET_DISK_file_close (
1095 f_update)))
1096 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n",
1097 data_fn_update);
1098 GNUNET_free_non_null (data_fn_update);
1063} 1099}
1064 1100
1065 1101
1066static int 1102static int
1067do_delete_address(void *cls, 1103do_delete_address (void *cls,
1068 const struct GNUNET_PeerIdentity *pid, 1104 const struct GNUNET_PeerIdentity *pid,
1069 void *value) 1105 void *value)
1070{ 1106{
1071 struct ATS_Address *cur = value; 1107 struct ATS_Address *cur = value;
1072 1108
1073 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1074 "Deleting addresses for peer %u\n", 1110 "Deleting addresses for peer %u\n",
1075 pid); 1111 pid);
1076 GNUNET_assert(GNUNET_OK == 1112 GNUNET_assert (GNUNET_OK ==
1077 GNUNET_CONTAINER_multipeermap_remove(ph.addresses, 1113 GNUNET_CONTAINER_multipeermap_remove (ph.addresses,
1078 pid, 1114 pid,
1079 cur)); 1115 cur));
1080 ph.sf->s_del(ph.sf->cls, cur); 1116 ph.sf->s_del (ph.sf->cls, cur);
1081 GNUNET_free_non_null(cur->atsi); 1117 GNUNET_free_non_null (cur->atsi);
1082 GNUNET_free(cur); 1118 GNUNET_free (cur);
1083 return GNUNET_OK; 1119 return GNUNET_OK;
1084} 1120}
1085 1121
@@ -1088,134 +1124,139 @@ do_delete_address(void *cls,
1088 * Run a performance iteration 1124 * Run a performance iteration
1089 */ 1125 */
1090static void 1126static void
1091perf_run_iteration(void) 1127perf_run_iteration (void)
1092{ 1128{
1093 int cp; 1129 int cp;
1094 int ca; 1130 int ca;
1095 int count_p = ph.N_peers_end; 1131 int count_p = ph.N_peers_end;
1096 int count_a = ph.N_address; 1132 int count_a = ph.N_address;
1097 struct ATS_Address * cur_addr; 1133 struct ATS_Address *cur_addr;
1098 uint32_t net; 1134 uint32_t net;
1099 1135
1100 ph.iterations_results[ph.current_iteration - 1].results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); 1136 ph.iterations_results[ph.current_iteration - 1].results_array =
1137 GNUNET_malloc ((count_p + 1) * sizeof(struct Result *));
1101 if (ph.measure_updates) 1138 if (ph.measure_updates)
1102 ph.iterations_results[ph.current_iteration - 1].update_results_array = GNUNET_malloc((count_p + 1) * sizeof(struct Result *)); 1139 ph.iterations_results[ph.current_iteration - 1].update_results_array =
1103 ph.peers = GNUNET_malloc((count_p) * sizeof(struct PerfPeer)); 1140 GNUNET_malloc ((count_p + 1) * sizeof(struct Result *));
1141 ph.peers = GNUNET_malloc ((count_p) * sizeof(struct PerfPeer));
1104 for (cp = 0; cp < count_p; cp++) 1142 for (cp = 0; cp < count_p; cp++)
1105 perf_create_peer(cp); 1143 perf_create_peer (cp);
1106 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1144 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1107 "Iteration %u of %u, added %u peers\n", ph.current_iteration, ph.total_iterations, cp); 1145 "Iteration %u of %u, added %u peers\n", ph.current_iteration,
1146 ph.total_iterations, cp);
1108 1147
1109 for (cp = 0; cp < count_p; cp++) 1148 for (cp = 0; cp < count_p; cp++)
1149 {
1150 fprintf (stderr, "%u..", cp);
1151 if (GNUNET_NO == ph.bulk_running)
1110 { 1152 {
1111 fprintf(stderr, "%u..", cp); 1153 ph.bulk_running = GNUNET_YES;
1112 if (GNUNET_NO == ph.bulk_running) 1154 ph.sf->s_bulk_start (ph.sf->cls);
1113 {
1114 ph.bulk_running = GNUNET_YES;
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);
1182 }
1183 } 1155 }
1184 fprintf(stderr, "\n"); 1156 ph.current_p = cp + 1;
1185 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1157 for (ca = 0; ca < count_a; ca++)
1186 "Done, cleaning up addresses\n");
1187 if (GNUNET_NO == ph.bulk_running)
1188 { 1158 {
1189 ph.sf->s_bulk_start(ph.sf->cls); 1159 cur_addr = perf_create_address (cp, ca);
1190 ph.bulk_running = GNUNET_YES; 1160 /* Add address */
1161
1162 /* Random network selection */
1163 // net = 1 + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_NT_COUNT - 1);
1164 /* Random equally distributed network selection */
1165 net = 1 + (ca % (GNUNET_NT_COUNT - 1));
1166 /* fprintf (stderr, "Network: %u `%s'\n",
1167 * mod_net , GNUNET_NT_to_string(mod_net)); */
1168
1169 cur_addr->atsi = GNUNET_new (struct GNUNET_ATS_Information);
1170 cur_addr->atsi_count = 1;
1171 cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
1172 cur_addr->atsi[0].value = htonl (net);
1173 ph.sf->s_add (ph.sf->cls, cur_addr, net);
1174
1175 ph.current_a = ca + 1;
1176 perf_address_initial_update (NULL, ph.addresses, cur_addr);
1177 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1178 "Adding address for peer %u address %u in network %s\n", cp,
1179 ca,
1180 GNUNET_NT_to_string (net));
1191 } 1181 }
1182 /* Notify solver about request */
1183 ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id);
1192 1184
1193 for (cp = 0; cp < count_p; cp++) 1185 if (cp + 1 >= ph.N_peers_start)
1194 { 1186 {
1195 GNUNET_CONTAINER_multipeermap_get_multiple(ph.addresses, 1187 /* Disable bulk to solve the problem */
1196 &ph.peers[cp].id, 1188 if (GNUNET_YES == ph.bulk_running)
1197 &do_delete_address, 1189 {
1198 NULL); 1190 ph.expecting_solution = GNUNET_YES;
1191 ph.bulk_running = GNUNET_NO;
1192 ph.sf->s_bulk_stop (ph.sf->cls);
1193 }
1194 else
1195 GNUNET_break (0);
1196
1197 /* Problem is solved by the solver here due to unlocking */
1198 ph.expecting_solution = GNUNET_NO;
1199
1200 /* Update the problem */
1201 if ((0 < ph.opt_update_percent) && (GNUNET_YES == ph.measure_updates))
1202 {
1203 /* Update */
1204 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1205 "Updating problem with %u peers and %u addresses\n", cp + 1,
1206 ca);
1207
1208 ph.expecting_solution = GNUNET_YES;
1209 ph.performed_update = GNUNET_YES;
1210 if (GNUNET_NO == ph.bulk_running)
1211 {
1212 ph.bulk_running = GNUNET_YES;
1213 ph.sf->s_bulk_start (ph.sf->cls);
1214 }
1215 perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent);
1216 ph.bulk_running = GNUNET_NO;
1217 ph.sf->s_bulk_stop (ph.sf->cls);
1218 /* Problem is solved by the solver here due to unlocking */
1219 ph.performed_update = GNUNET_NO;
1220 ph.expecting_solution = GNUNET_NO;
1221 }
1222 GNUNET_assert (GNUNET_NO == ph.bulk_running);
1199 } 1223 }
1224 }
1225 fprintf (stderr, "\n");
1226 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1227 "Done, cleaning up addresses\n");
1200 if (GNUNET_NO == ph.bulk_running) 1228 if (GNUNET_NO == ph.bulk_running)
1201 { 1229 {
1202 ph.sf->s_bulk_stop(ph.sf->cls); 1230 ph.sf->s_bulk_start (ph.sf->cls);
1203 ph.bulk_running = GNUNET_NO; 1231 ph.bulk_running = GNUNET_YES;
1204 } 1232 }
1205 1233
1206 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1234 for (cp = 0; cp < count_p; cp++)
1207 "Iteration done\n"); 1235 {
1208 GNUNET_free(ph.peers); 1236 GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses,
1237 &ph.peers[cp].id,
1238 &do_delete_address,
1239 NULL);
1240 }
1241 if (GNUNET_NO == ph.bulk_running)
1242 {
1243 ph.sf->s_bulk_stop (ph.sf->cls);
1244 ph.bulk_running = GNUNET_NO;
1245 }
1246
1247 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1248 "Iteration done\n");
1249 GNUNET_free (ph.peers);
1209} 1250}
1210 1251
1211 1252
1212static void 1253static void
1213run(void *cls, char * const *args, const char *cfgfile, 1254run (void *cls, char *const *args, const char *cfgfile,
1214 const struct GNUNET_CONFIGURATION_Handle *cfg) 1255 const struct GNUNET_CONFIGURATION_Handle *cfg)
1215{ 1256{
1216 GNUNET_log_setup("perf-ats-solver", "WARNING", NULL); 1257 GNUNET_log_setup ("perf-ats-solver", "WARNING", NULL);
1217 char *sep; 1258 char *sep;
1218 char *src_filename = GNUNET_strdup(__FILE__); 1259 char *src_filename = GNUNET_strdup (__FILE__);
1219 char *test_filename = cls; 1260 char *test_filename = cls;
1220 char *solver; 1261 char *solver;
1221 char *plugin; 1262 char *plugin;
@@ -1226,92 +1267,98 @@ run(void *cls, char * const *args, const char *cfgfile,
1226 int c2; 1267 int c2;
1227 1268
1228 /* Extract test name */ 1269 /* Extract test name */
1229 if (NULL == (sep = (strstr(src_filename, ".c")))) 1270 if (NULL == (sep = (strstr (src_filename, ".c"))))
1230 { 1271 {
1231 GNUNET_free(src_filename); 1272 GNUNET_free (src_filename);
1232 GNUNET_break(0); 1273 GNUNET_break (0);
1233 ret = 1; 1274 ret = 1;
1234 return; 1275 return;
1235 } 1276 }
1236 sep[0] = '\0'; 1277 sep[0] = '\0';
1237 1278
1238 if (NULL != (sep = strstr(test_filename, ".exe"))) 1279 if (NULL != (sep = strstr (test_filename, ".exe")))
1239 sep[0] = '\0'; 1280 sep[0] = '\0';
1240 1281
1241 if (NULL == (solver = strstr(test_filename, src_filename))) 1282 if (NULL == (solver = strstr (test_filename, src_filename)))
1242 { 1283 {
1243 GNUNET_free(src_filename); 1284 GNUNET_free (src_filename);
1244 GNUNET_break(0); 1285 GNUNET_break (0);
1245 ret = 1; 1286 ret = 1;
1246 return; 1287 return;
1247 } 1288 }
1248 solver += strlen(src_filename) + 1; 1289 solver += strlen (src_filename) + 1;
1249 1290
1250 if (0 == strcmp(solver, "proportional")) 1291 if (0 == strcmp (solver, "proportional"))
1251 { 1292 {
1252 ph.ats_string = "proportional"; 1293 ph.ats_string = "proportional";
1253 } 1294 }
1254 else if (0 == strcmp(solver, "mlp")) 1295 else if (0 == strcmp (solver, "mlp"))
1255 { 1296 {
1256 ph.ats_string = "mlp"; 1297 ph.ats_string = "mlp";
1257 } 1298 }
1258 else if ((0 == strcmp(solver, "ril"))) 1299 else if ((0 == strcmp (solver, "ril")))
1259 { 1300 {
1260 ph.ats_string = "ril"; 1301 ph.ats_string = "ril";
1261 } 1302 }
1262 else 1303 else
1263 { 1304 {
1264 GNUNET_free(src_filename); 1305 GNUNET_free (src_filename);
1265 GNUNET_break(0); 1306 GNUNET_break (0);
1266 ret = 1; 1307 ret = 1;
1267 return; 1308 return;
1268 } 1309 }
1269 GNUNET_free(src_filename); 1310 GNUNET_free (src_filename);
1270 1311
1271 /* Calculcate peers */ 1312 /* Calculcate peers */
1272 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end)) 1313 if ((0 == ph.N_peers_start) && (0 == ph.N_peers_end))
1273 { 1314 {
1274 ph.N_peers_start = DEFAULT_PEERS_START; 1315 ph.N_peers_start = DEFAULT_PEERS_START;
1275 ph.N_peers_end = DEFAULT_PEERS_END; 1316 ph.N_peers_end = DEFAULT_PEERS_END;
1276 } 1317 }
1277 if (0 == ph.N_address) 1318 if (0 == ph.N_address)
1278 ph.N_address = DEFAULT_ADDRESSES; 1319 ph.N_address = DEFAULT_ADDRESSES;
1279 1320
1280 1321
1281 if (ph.N_peers_start != ph.N_peers_end) 1322 if (ph.N_peers_start != ph.N_peers_end)
1282 fprintf(stderr, "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n", 1323 fprintf (stderr,
1283 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address, ph.total_iterations); 1324 "Benchmarking solver `%s' with %u to %u peers and %u addresses in %u iterations\n",
1325 ph.ats_string, ph.N_peers_start, ph.N_peers_end, ph.N_address,
1326 ph.total_iterations);
1284 else 1327 else
1285 fprintf(stderr, "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n", 1328 fprintf (stderr,
1286 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations); 1329 "Benchmarking solver `%s' with %u peers and %u addresses in %u iterations\n",
1330 ph.ats_string, ph.N_peers_end, ph.N_address, ph.total_iterations);
1287 1331
1288 if (0 == ph.opt_update_percent) 1332 if (0 == ph.opt_update_percent)
1289 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE; 1333 ph.opt_update_percent = DEFAULT_UPDATE_PERCENTAGE;
1290 1334
1291 /* Load quotas */ 1335 /* Load quotas */
1292 solver_cfg = GNUNET_CONFIGURATION_create(); 1336 solver_cfg = GNUNET_CONFIGURATION_create ();
1293 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load(solver_cfg, "perf_ats_solver.conf")))) 1337 if ((NULL == solver_cfg) || (GNUNET_SYSERR == (GNUNET_CONFIGURATION_load (
1294 { 1338 solver_cfg,
1295 GNUNET_break(0); 1339 "perf_ats_solver.conf"))))
1296 end_now(1); 1340 {
1297 return; 1341 GNUNET_break (0);
1298 } 1342 end_now (1);
1299 if (GNUNET_NT_COUNT != load_quotas(solver_cfg, 1343 return;
1300 quotas_out, quotas_in, GNUNET_NT_COUNT)) 1344 }
1301 { 1345 if (GNUNET_NT_COUNT != load_quotas (solver_cfg,
1302 GNUNET_break(0); 1346 quotas_out, quotas_in, GNUNET_NT_COUNT))
1303 end_now(1); 1347 {
1304 return; 1348 GNUNET_break (0);
1305 } 1349 end_now (1);
1350 return;
1351 }
1306 1352
1307 /* Create array of DLL to store results for iterations */ 1353 /* Create array of DLL to store results for iterations */
1308 ph.iterations_results = GNUNET_malloc(sizeof(struct Iteration) * ph.total_iterations); 1354 ph.iterations_results = GNUNET_malloc (sizeof(struct Iteration)
1355 * ph.total_iterations);
1309 1356
1310 /* Load solver */ 1357 /* Load solver */
1311 ph.env.cfg = solver_cfg; 1358 ph.env.cfg = solver_cfg;
1312 ph.stat = GNUNET_STATISTICS_create("ats", cfg); 1359 ph.stat = GNUNET_STATISTICS_create ("ats", cfg);
1313 ph.env.stats = ph.stat; 1360 ph.env.stats = ph.stat;
1314 ph.addresses = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO); 1361 ph.addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
1315 ph.env.addresses = ph.addresses; 1362 ph.env.addresses = ph.addresses;
1316 ph.env.bandwidth_changed_cb = bandwidth_changed_cb; 1363 ph.env.bandwidth_changed_cb = bandwidth_changed_cb;
1317 ph.env.get_connectivity = &get_connectivity_cb; 1364 ph.env.get_connectivity = &get_connectivity_cb;
@@ -1320,75 +1367,77 @@ run(void *cls, char * const *args, const char *cfgfile,
1320 ph.env.info_cb = &solver_info_cb; 1367 ph.env.info_cb = &solver_info_cb;
1321 1368
1322 for (c = 0; c < GNUNET_NT_COUNT; c++) 1369 for (c = 0; c < GNUNET_NT_COUNT; c++)
1323 { 1370 {
1324 ph.env.out_quota[c] = quotas_out[c]; 1371 ph.env.out_quota[c] = quotas_out[c];
1325 ph.env.in_quota[c] = quotas_in[c]; 1372 ph.env.in_quota[c] = quotas_in[c];
1326 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1373 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1327 "Loading network quotas: `%s' %llu %llu \n", 1374 "Loading network quotas: `%s' %llu %llu \n",
1328 GNUNET_NT_to_string(c), 1375 GNUNET_NT_to_string (c),
1329 ph.env.out_quota[c], 1376 ph.env.out_quota[c],
1330 ph.env.in_quota[c]); 1377 ph.env.in_quota[c]);
1331 } 1378 }
1332 GAS_normalization_start(); 1379 GAS_normalization_start ();
1333 GAS_preference_init(); 1380 GAS_preference_init ();
1334 1381
1335 GNUNET_asprintf(&plugin, 1382 GNUNET_asprintf (&plugin,
1336 "libgnunet_plugin_ats_%s", 1383 "libgnunet_plugin_ats_%s",
1337 ph.ats_string); 1384 ph.ats_string);
1338 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1385 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1339 _("Initializing solver `%s'\n"), 1386 _ ("Initializing solver `%s'\n"),
1340 ph.ats_string); 1387 ph.ats_string);
1341 if (NULL == (ph.sf = GNUNET_PLUGIN_load(plugin, &ph.env))) 1388 if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env)))
1342 { 1389 {
1343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 1390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1344 _("Failed to initialize solver `%s'!\n"), 1391 _ ("Failed to initialize solver `%s'!\n"),
1345 plugin); 1392 plugin);
1346 ret = 1; 1393 ret = 1;
1347 return; 1394 return;
1348 } 1395 }
1349 1396
1350 /* Do the benchmark */ 1397 /* Do the benchmark */
1351 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations; ph.current_iteration++) 1398 for (ph.current_iteration = 1; ph.current_iteration <= ph.total_iterations;
1352 { 1399 ph.current_iteration++)
1353 fprintf(stderr, 1400 {
1354 "Iteration %u of %u starting\n", 1401 fprintf (stderr,
1355 ph.current_iteration, 1402 "Iteration %u of %u starting\n",
1356 ph.total_iterations); 1403 ph.current_iteration,
1357 perf_run_iteration(); 1404 ph.total_iterations);
1358 evaluate(ph.current_iteration); 1405 perf_run_iteration ();
1359 fprintf(stderr, 1406 evaluate (ph.current_iteration);
1360 "Iteration %u of %u done\n", 1407 fprintf (stderr,
1361 ph.current_iteration, 1408 "Iteration %u of %u done\n",
1362 ph.total_iterations); 1409 ph.current_iteration,
1363 } 1410 ph.total_iterations);
1411 }
1364 if (ph.create_datafile) 1412 if (ph.create_datafile)
1365 write_all_iterations(); 1413 write_all_iterations ();
1366 1414
1367 /* Unload solver*/ 1415 /* Unload solver*/
1368 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1416 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1369 _("Unloading solver `%s'\n"), 1417 _ ("Unloading solver `%s'\n"),
1370 ph.ats_string); 1418 ph.ats_string);
1371 GNUNET_PLUGIN_unload(plugin, ph.sf); 1419 GNUNET_PLUGIN_unload (plugin, ph.sf);
1372 ph.sf = NULL; 1420 ph.sf = NULL;
1373 GNUNET_free(plugin); 1421 GNUNET_free (plugin);
1374 for (c = 0; c < ph.total_iterations; c++) 1422 for (c = 0; c < ph.total_iterations; c++)
1423 {
1424 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++)
1375 { 1425 {
1376 for (c2 = ph.N_peers_start; c2 < ph.N_peers_end; c2++) 1426 if (0 == c2)
1377 { 1427 continue;
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 }
1384 if (ph.measure_updates) 1428 if (ph.measure_updates)
1385 GNUNET_free(ph.iterations_results[c].update_results_array); 1429 GNUNET_free_non_null (
1386 GNUNET_free(ph.iterations_results[c].results_array); 1430 ph.iterations_results[c].update_results_array[c2]);
1431 GNUNET_free (ph.iterations_results[c].results_array[c2]);
1387 } 1432 }
1388 GNUNET_free(ph.iterations_results); 1433 if (ph.measure_updates)
1389 1434 GNUNET_free (ph.iterations_results[c].update_results_array);
1390 GNUNET_CONFIGURATION_destroy(solver_cfg); 1435 GNUNET_free (ph.iterations_results[c].results_array);
1391 GNUNET_STATISTICS_destroy(ph.stat, GNUNET_NO); 1436 }
1437 GNUNET_free (ph.iterations_results);
1438
1439 GNUNET_CONFIGURATION_destroy (solver_cfg);
1440 GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO);
1392} 1441}
1393 1442
1394 1443
@@ -1399,7 +1448,7 @@ run(void *cls, char * const *args, const char *cfgfile,
1399 * @param argv argument values 1448 * @param argv argument values
1400 */ 1449 */
1401int 1450int
1402main(int argc, char *argv[]) 1451main (int argc, char *argv[])
1403{ 1452{
1404 /* extract command line arguments */ 1453 /* extract command line arguments */
1405 ph.opt_update_percent = 0; 1454 ph.opt_update_percent = 0;
@@ -1412,45 +1461,47 @@ main(int argc, char *argv[])
1412 ph.total_iterations = 1; 1461 ph.total_iterations = 1;
1413 1462
1414 static struct GNUNET_GETOPT_CommandLineOption options[] = { 1463 static struct GNUNET_GETOPT_CommandLineOption options[] = {
1415 GNUNET_GETOPT_option_uint('a', 1464 GNUNET_GETOPT_option_uint ('a',
1416 "addresses", 1465 "addresses",
1417 gettext_noop("addresses to use"), 1466 gettext_noop ("addresses to use"),
1418 &ph.N_address), 1467 &ph.N_address),
1419 1468
1420 GNUNET_GETOPT_option_uint('s', 1469 GNUNET_GETOPT_option_uint ('s',
1421 "start", 1470 "start",
1422 gettext_noop("start with peer"), 1471 gettext_noop ("start with peer"),
1423 &ph.N_peers_start), 1472 &ph.N_peers_start),
1424 1473
1425 GNUNET_GETOPT_option_uint('e', 1474 GNUNET_GETOPT_option_uint ('e',
1426 "end", 1475 "end",
1427 gettext_noop("end with peer"), 1476 gettext_noop ("end with peer"),
1428 &ph.N_peers_end), 1477 &ph.N_peers_end),
1429 1478
1430 GNUNET_GETOPT_option_uint('i', 1479 GNUNET_GETOPT_option_uint ('i',
1431 "iterations", 1480 "iterations",
1432 gettext_noop("number of iterations used for averaging (default: 1)"), 1481 gettext_noop (
1433 &ph.total_iterations), 1482 "number of iterations used for averaging (default: 1)"),
1434 1483 &ph.total_iterations),
1435 GNUNET_GETOPT_option_uint('p', 1484
1436 "percentage", 1485 GNUNET_GETOPT_option_uint ('p',
1437 gettext_noop("update a fix percentage of addresses"), 1486 "percentage",
1438 &ph.opt_update_percent), 1487 gettext_noop (
1439 1488 "update a fix percentage of addresses"),
1440 GNUNET_GETOPT_option_flag('d', 1489 &ph.opt_update_percent),
1441 "data", 1490
1442 gettext_noop("create data file"), 1491 GNUNET_GETOPT_option_flag ('d',
1443 &ph.create_datafile), 1492 "data",
1444 1493 gettext_noop ("create data file"),
1445 GNUNET_GETOPT_option_flag('u', 1494 &ph.create_datafile),
1446 "update", 1495
1447 gettext_noop("measure updates"), 1496 GNUNET_GETOPT_option_flag ('u',
1448 &ph.measure_updates), 1497 "update",
1498 gettext_noop ("measure updates"),
1499 &ph.measure_updates),
1449 1500
1450 GNUNET_GETOPT_OPTION_END 1501 GNUNET_GETOPT_OPTION_END
1451 }; 1502 };
1452 1503
1453 GNUNET_PROGRAM_run(argc, argv, argv[0], NULL, options, &run, argv[0]); 1504 GNUNET_PROGRAM_run (argc, argv, argv[0], NULL, options, &run, argv[0]);
1454 return ret; 1505 return ret;
1455} 1506}
1456 1507
diff --git a/src/ats/plugin_ats2_common.c b/src/ats/plugin_ats2_common.c
index c12d2a06f..da20a342c 100644
--- a/src/ats/plugin_ats2_common.c
+++ b/src/ats/plugin_ats2_common.c
@@ -40,59 +40,60 @@
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 */
42static void 42static void
43get_quota(const struct GNUNET_CONFIGURATION_Handle *cfg, 43get_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(&quota_s, 52 GNUNET_asprintf (&quota_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 &quota_str)) 60 &quota_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; 74 res = GNUNET_YES;
75 } 75 }
76 if ((GNUNET_NO == res) && 76 if ((GNUNET_NO == res) &&
77 (GNUNET_OK == 77 (GNUNET_OK ==
78 GNUNET_STRINGS_fancy_size_to_bytes(quota_str, 78 GNUNET_STRINGS_fancy_size_to_bytes (quota_str,
79 quota))) 79 quota)))
80 res = GNUNET_YES; 80 res = GNUNET_YES;
81 if ((GNUNET_NO == res) && 81 if ((GNUNET_NO == res) &&
82 (1 == 82 (1 ==
83 sscanf(quota_str, 83 sscanf (quota_str,
84 "%llu", 84 "%llu",
85 quota))) 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 _ (
91 direction, 91 "Could not load %s quota for network `%s': `%s', assigning default bandwidth %llu\n"),
92 nts, 92 direction,
93 quota_str, 93 nts,
94 (unsigned long long)DEFAULT_BANDWIDTH); 94 quota_str,
95 *quota = DEFAULT_BANDWIDTH; 95 (unsigned long long) DEFAULT_BANDWIDTH);
96 } 96 *quota = DEFAULT_BANDWIDTH;
97 GNUNET_free(quota_str); 97 }
98 GNUNET_free (quota_str);
98} 99}
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c
index 90566c561..3062b6019 100644
--- a/src/ats/plugin_ats2_simple.c
+++ b/src/ats/plugin_ats2_simple.c
@@ -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,7 +68,8 @@ 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 */
71struct Hello { 71struct Hello
72{
72 /** 73 /**
73 * Kept in a DLL. 74 * Kept in a DLL.
74 */ 75 */
@@ -121,7 +122,8 @@ struct Hello {
121 * Internal representation of a session by the plugin. 122 * Internal representation of a session by the plugin.
122 * (If desired, plugin may just use NULL.) 123 * (If desired, plugin may just use NULL.)
123 */ 124 */
124struct GNUNET_ATS_SessionHandle { 125struct GNUNET_ATS_SessionHandle
126{
125 /** 127 /**
126 * Kept in DLL per peer. 128 * Kept in DLL per peer.
127 */ 129 */
@@ -189,7 +191,8 @@ struct GNUNET_ATS_SessionHandle {
189 * Information about preferences and sessions we track 191 * Information about preferences and sessions we track
190 * per peer. 192 * per peer.
191 */ 193 */
192struct Peer { 194struct Peer
195{
193 /** 196 /**
194 * Kept in DLL per peer. 197 * Kept in DLL per peer.
195 */ 198 */
@@ -247,7 +250,8 @@ struct Peer {
247/** 250/**
248 * Representation of a network (to be expanded...) 251 * Representation of a network (to be expanded...)
249 */ 252 */
250struct Network { 253struct Network
254{
251 /** 255 /**
252 * Total inbound quota 256 * Total inbound quota
253 */ 257 */
@@ -268,7 +272,8 @@ struct Network {
268/** 272/**
269 * A handle for the proportional solver 273 * A handle for the proportional solver
270 */ 274 */
271struct SimpleHandle { 275struct SimpleHandle
276{
272 /** 277 /**
273 * Our execution environment. 278 * Our execution environment.
274 */ 279 */
@@ -306,9 +311,9 @@ struct SimpleHandle {
306 * @return NULL for not found 311 * @return NULL for not found
307 */ 312 */
308struct Peer * 313struct Peer *
309lookup_peer(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) 314lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid)
310{ 315{
311 return GNUNET_CONTAINER_multipeermap_get(h->peers, pid); 316 return GNUNET_CONTAINER_multipeermap_get (h->peers, pid);
312} 317}
313 318
314 319
@@ -320,7 +325,7 @@ lookup_peer(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid)
320 * @return #GNUNET_YES if no information is left in @a p 325 * @return #GNUNET_YES if no information is left in @a p
321 */ 326 */
322static int 327static int
323peer_test_dead(struct Peer *p) 328peer_test_dead (struct Peer *p)
324{ 329{
325 for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; 330 for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT;
326 pk++) 331 pk++)
@@ -340,17 +345,17 @@ peer_test_dead(struct Peer *p)
340 * @param hello[in,out] address suggestion to make 345 * @param hello[in,out] address suggestion to make
341 */ 346 */
342static void 347static void
343suggest_hello(struct Hello *hello) 348suggest_hello (struct Hello *hello)
344{ 349{
345 struct Peer *p = hello->peer; 350 struct Peer *p = hello->peer;
346 struct SimpleHandle *h = p->h; 351 struct SimpleHandle *h = p->h;
347 352
348 p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get(); 353 p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get ();
349 hello->backoff = 354 hello->backoff =
350 GNUNET_TIME_randomized_backoff(hello->backoff, 355 GNUNET_TIME_randomized_backoff (hello->backoff,
351 GNUNET_TIME_absolute_get_remaining( 356 GNUNET_TIME_absolute_get_remaining (
352 hello->expiration)); 357 hello->expiration));
353 h->env->suggest_cb(h->env->cls, &p->pid, hello->address); 358 h->env->suggest_cb (h->env->cls, &p->pid, hello->address);
354} 359}
355 360
356 361
@@ -369,7 +374,7 @@ suggest_hello(struct Hello *hello)
369 * @param cls a `struct Peer` 374 * @param cls a `struct Peer`
370 */ 375 */
371static void 376static void
372suggest_start_cb(void *cls) 377suggest_start_cb (void *cls)
373{ 378{
374 struct Peer *p = cls; 379 struct Peer *p = cls;
375 struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO; 380 struct GNUNET_TIME_Relative delay = GNUNET_TIME_UNIT_ZERO;
@@ -387,63 +392,63 @@ suggest_start_cb(void *cls)
387 /* calculate square of number of sessions */ 392 /* calculate square of number of sessions */
388 num_sessions++; /* start with 1, even if we have zero sessions */ 393 num_sessions++; /* start with 1, even if we have zero sessions */
389 if (num_sessions < UINT16_MAX) 394 if (num_sessions < UINT16_MAX)
390 sq = num_sessions * (uint32_t)num_sessions; 395 sq = num_sessions * (uint32_t) num_sessions;
391 else 396 else
392 sq = UINT32_MAX; 397 sq = UINT32_MAX;
393 xdelay = 398 xdelay =
394 GNUNET_TIME_randomized_backoff(GNUNET_TIME_relative_multiply(SUGGEST_FREQ, 399 GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ,
395 sq), 400 sq),
396 GNUNET_TIME_UNIT_FOREVER_REL); 401 GNUNET_TIME_UNIT_FOREVER_REL);
397 xnext = GNUNET_TIME_relative_to_absolute(xdelay); 402 xnext = GNUNET_TIME_relative_to_absolute (xdelay);
398 403
399 p->task = NULL; 404 p->task = NULL;
400 while (0 == delay.rel_value_us) 405 while (0 == delay.rel_value_us)
406 {
407 struct Hello *next;
408 struct GNUNET_TIME_Absolute xmax;
409
410 if (NULL != hello)
401 { 411 {
402 struct Hello *next; 412 /* We went through the loop already once and found
403 struct GNUNET_TIME_Absolute xmax; 413 a HELLO that is due *now*, so make a suggestion! */
404 414 GNUNET_break (NULL == hello->sh);
405 if (NULL != hello) 415 suggest_hello (hello);
406 { 416 hello = NULL;
407 /* We went through the loop already once and found 417 hpt = GNUNET_TIME_UNIT_FOREVER_ABS;
408 a HELLO that is due *now*, so make a suggestion! */
409 GNUNET_break(NULL == hello->sh);
410 suggest_hello(hello);
411 hello = NULL;
412 hpt = GNUNET_TIME_UNIT_FOREVER_ABS;
413 }
414 for (struct Hello *pos = p->h_head; NULL != pos; pos = next)
415 {
416 struct GNUNET_TIME_Absolute pt;
417
418 next = pos->next;
419 if (NULL != pos->sh)
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 } 418 }
446 p->task = GNUNET_SCHEDULER_add_delayed(delay, &suggest_start_cb, p); 419 for (struct Hello *pos = p->h_head; NULL != pos; pos = next)
420 {
421 struct GNUNET_TIME_Absolute pt;
422
423 next = pos->next;
424 if (NULL != pos->sh)
425 continue;
426 if (0 ==
427 GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us)
428 {
429 /* expired, remove! */
430 GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, pos);
431 GNUNET_free (pos);
432 continue;
433 }
434 pt = GNUNET_TIME_absolute_add (pos->last_attempt, pos->backoff);
435 if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us))
436 {
437 hello = pos;
438 hpt = pt;
439 }
440 }
441 if (NULL == hello)
442 return; /* no HELLOs that could still be tried */
443
444 /* hpt is now the *earliest* possible time for any HELLO
445 but we might not want to go for as early as possible for
446 this peer. So the actual time is the max of the earliest
447 HELLO and the 'xnext' */
448 xmax = GNUNET_TIME_absolute_max (hpt, xnext);
449 delay = GNUNET_TIME_absolute_get_remaining (xmax);
450 }
451 p->task = GNUNET_SCHEDULER_add_delayed (delay, &suggest_start_cb, p);
447} 452}
448 453
449 454
@@ -455,9 +460,9 @@ suggest_start_cb(void *cls)
455 * @param emsg error message, or NULL if no errors 460 * @param emsg error message, or NULL if no errors
456 */ 461 */
457static void 462static void
458watch_cb(void *cls, 463watch_cb (void *cls,
459 const struct GNUNET_PEERSTORE_Record *record, 464 const struct GNUNET_PEERSTORE_Record *record,
460 const char *emsg) 465 const char *emsg)
461{ 466{
462 struct Peer *p = cls; 467 struct Peer *p = cls;
463 char *addr; 468 char *addr;
@@ -466,65 +471,65 @@ watch_cb(void *cls,
466 struct GNUNET_TIME_Absolute expiration; 471 struct GNUNET_TIME_Absolute expiration;
467 struct Hello *hello; 472 struct Hello *hello;
468 473
469 if (0 != GNUNET_memcmp(&p->pid, &record->peer)) 474 if (0 != GNUNET_memcmp (&p->pid, &record->peer))
470 { 475 {
471 GNUNET_break(0); 476 GNUNET_break (0);
472 return; 477 return;
473 } 478 }
474 if (0 != strcmp(record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) 479 if (0 != strcmp (record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY))
475 { 480 {
476 GNUNET_break(0); 481 GNUNET_break (0);
477 return; 482 return;
478 } 483 }
479 addr = GNUNET_HELLO_extract_address(record->value, 484 addr = GNUNET_HELLO_extract_address (record->value,
480 record->value_size, 485 record->value_size,
481 &p->pid, 486 &p->pid,
482 &nt, 487 &nt,
483 &expiration); 488 &expiration);
484 if (NULL == addr) 489 if (NULL == addr)
485 return; /* invalid hello, bad signature, other problem */ 490 return; /* invalid hello, bad signature, other problem */
486 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us) 491 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
487 { 492 {
488 /* expired, ignore */ 493 /* expired, ignore */
489 GNUNET_free(addr); 494 GNUNET_free (addr);
490 return; 495 return;
491 } 496 }
492 /* check if addr is already known */ 497 /* check if addr is already known */
493 for (struct Hello *he = p->h_head; NULL != he; he = he->next) 498 for (struct Hello *he = p->h_head; NULL != he; he = he->next)
499 {
500 if (0 != strcmp (he->address, addr))
501 continue;
502 if (he->expiration.abs_value_us < expiration.abs_value_us)
494 { 503 {
495 if (0 != strcmp(he->address, addr)) 504 he->expiration = expiration;
496 continue; 505 he->nt = nt;
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;
504 } 506 }
507 GNUNET_free (addr);
508 return;
509 }
505 /* create new HELLO */ 510 /* create new HELLO */
506 alen = strlen(addr) + 1; 511 alen = strlen (addr) + 1;
507 hello = GNUNET_malloc(sizeof(struct Hello) + alen); 512 hello = GNUNET_malloc (sizeof(struct Hello) + alen);
508 hello->address = (const char *)&hello[1]; 513 hello->address = (const char *) &hello[1];
509 hello->expiration = expiration; 514 hello->expiration = expiration;
510 hello->nt = nt; 515 hello->nt = nt;
511 hello->peer = p; 516 hello->peer = p;
512 memcpy(&hello[1], addr, alen); 517 memcpy (&hello[1], addr, alen);
513 GNUNET_CONTAINER_DLL_insert(p->h_head, p->h_tail, hello); 518 GNUNET_CONTAINER_DLL_insert (p->h_head, p->h_tail, hello);
514 /* check if sh for this HELLO already exists */ 519 /* check if sh for this HELLO already exists */
515 for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; 520 for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh;
516 sh = sh->next) 521 sh = sh->next)
517 { 522 {
518 if ((NULL == sh->address) || (0 != strcmp(sh->address, addr))) 523 if ((NULL == sh->address) || (0 != strcmp (sh->address, addr)))
519 continue; 524 continue;
520 GNUNET_assert(NULL == sh->hello); 525 GNUNET_assert (NULL == sh->hello);
521 sh->hello = hello; 526 sh->hello = hello;
522 hello->sh = sh; 527 hello->sh = sh;
523 break; 528 break;
524 } 529 }
525 GNUNET_free(addr); 530 GNUNET_free (addr);
526 if (NULL == p->task) 531 if (NULL == p->task)
527 p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); 532 p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p);
528} 533}
529 534
530 535
@@ -536,27 +541,27 @@ watch_cb(void *cls,
536 * @return a peer handle 541 * @return a peer handle
537 */ 542 */
538static struct Peer * 543static struct Peer *
539peer_add(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) 544peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid)
540{ 545{
541 struct Peer *p = lookup_peer(h, pid); 546 struct Peer *p = lookup_peer (h, pid);
542 547
543 if (NULL != p) 548 if (NULL != p)
544 return p; 549 return p;
545 p = GNUNET_new(struct Peer); 550 p = GNUNET_new (struct Peer);
546 p->h = h; 551 p->h = h;
547 p->pid = *pid; 552 p->pid = *pid;
548 p->wc = GNUNET_PEERSTORE_watch(h->ps, 553 p->wc = GNUNET_PEERSTORE_watch (h->ps,
549 "transport", 554 "transport",
550 &p->pid, 555 &p->pid,
551 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 556 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
552 &watch_cb, 557 &watch_cb,
553 p); 558 p);
554 GNUNET_assert(GNUNET_YES == 559 GNUNET_assert (GNUNET_YES ==
555 GNUNET_CONTAINER_multipeermap_put( 560 GNUNET_CONTAINER_multipeermap_put (
556 h->peers, 561 h->peers,
557 &p->pid, 562 &p->pid,
558 p, 563 p,
559 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 564 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
560 565
561 return p; 566 return p;
562} 567}
@@ -569,31 +574,31 @@ peer_add(struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid)
569 * @param p the peer to free 574 * @param p the peer to free
570 */ 575 */
571static void 576static void
572peer_free(struct Peer *p) 577peer_free (struct Peer *p)
573{ 578{
574 struct SimpleHandle *h = p->h; 579 struct SimpleHandle *h = p->h;
575 struct Hello *hello; 580 struct Hello *hello;
576 581
577 GNUNET_assert(NULL == p->sh_head); 582 GNUNET_assert (NULL == p->sh_head);
578 while (NULL != (hello = p->h_head)) 583 while (NULL != (hello = p->h_head))
579 { 584 {
580 GNUNET_CONTAINER_DLL_remove(p->h_head, p->h_tail, hello); 585 GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, hello);
581 GNUNET_assert(NULL == hello->sh); 586 GNUNET_assert (NULL == hello->sh);
582 GNUNET_free(hello); 587 GNUNET_free (hello);
583 } 588 }
584 if (NULL != p->task) 589 if (NULL != p->task)
585 { 590 {
586 GNUNET_SCHEDULER_cancel(p->task); 591 GNUNET_SCHEDULER_cancel (p->task);
587 p->task = NULL; 592 p->task = NULL;
588 } 593 }
589 if (NULL != p->wc) 594 if (NULL != p->wc)
590 { 595 {
591 GNUNET_PEERSTORE_watch_cancel(p->wc); 596 GNUNET_PEERSTORE_watch_cancel (p->wc);
592 p->wc = NULL; 597 p->wc = NULL;
593 } 598 }
594 GNUNET_assert(GNUNET_YES == 599 GNUNET_assert (GNUNET_YES ==
595 GNUNET_CONTAINER_multipeermap_remove(h->peers, &p->pid, p)); 600 GNUNET_CONTAINER_multipeermap_remove (h->peers, &p->pid, p));
596 GNUNET_free(p); 601 GNUNET_free (p);
597} 602}
598 603
599 604
@@ -604,7 +609,7 @@ peer_free(struct Peer *p)
604 * @param sh session handle to consider updating transport for 609 * @param sh session handle to consider updating transport for
605 */ 610 */
606static void 611static void
607consider_notify_transport(struct GNUNET_ATS_SessionHandle *sh) 612consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh)
608{ 613{
609 struct Peer *peer = sh->peer; 614 struct Peer *peer = sh->peer;
610 struct SimpleHandle *h = peer->h; 615 struct SimpleHandle *h = peer->h;
@@ -615,15 +620,15 @@ consider_notify_transport(struct GNUNET_ATS_SessionHandle *sh)
615 int64_t delta_in; 620 int64_t delta_in;
616 int64_t delta_out; 621 int64_t delta_out;
617 622
618 delay = GNUNET_TIME_absolute_get_duration(sh->last_allocation); 623 delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation);
619 /* A significant change is more than 10% of the quota, 624 /* A significant change is more than 10% of the quota,
620 which is given in bytes/second */ 625 which is given in bytes/second */
621 sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / 626 sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL)
622 1000LL / 10; 627 / 1000LL / 10;
623 sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / 628 sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL)
624 1000LL / 10; 629 / 1000LL / 10;
625 delta_in = ((int64_t)ntohl(sh->bw_in.value__)) - ((int64_t)sh->target_in); 630 delta_in = ((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); 631 delta_out = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in);
627 /* we want the absolute values */ 632 /* we want the absolute values */
628 if (delta_in < 0) 633 if (delta_in < 0)
629 delta_in = -delta_in; 634 delta_in = -delta_in;
@@ -638,23 +643,24 @@ consider_notify_transport(struct GNUNET_ATS_SessionHandle *sh)
638 /* change is significant, tell transport! */ 643 /* change is significant, tell transport! */
639 if (sh->target_in > UINT32_MAX) 644 if (sh->target_in > UINT32_MAX)
640 sh->target_in = UINT32_MAX; 645 sh->target_in = UINT32_MAX;
641 sh->bw_in.value__ = htonl((uint32_t)sh->target_in); 646 sh->bw_in.value__ = htonl ((uint32_t) sh->target_in);
642 if (sh->target_out > UINT32_MAX) 647 if (sh->target_out > UINT32_MAX)
643 sh->target_out = UINT32_MAX; 648 sh->target_out = UINT32_MAX;
644 sh->bw_out.value__ = htonl((uint32_t)sh->target_out); 649 sh->bw_out.value__ = htonl ((uint32_t) sh->target_out);
645 sh->last_allocation = GNUNET_TIME_absolute_get(); 650 sh->last_allocation = GNUNET_TIME_absolute_get ();
646 h->env->allocate_cb(h->env->cls, 651 h->env->allocate_cb (h->env->cls,
647 sh->session, 652 sh->session,
648 &peer->pid, 653 &peer->pid,
649 sh->bw_in, 654 sh->bw_in,
650 sh->bw_out); 655 sh->bw_out);
651} 656}
652 657
653 658
654/** 659/**
655 * Closure for #update_counters and #update_allocation. 660 * Closure for #update_counters and #update_allocation.
656 */ 661 */
657struct Counters { 662struct Counters
663{
658 /** 664 /**
659 * Plugin's state. 665 * Plugin's state.
660 */ 666 */
@@ -698,103 +704,103 @@ struct Counters {
698 * @return #GNUNET_YES (continue to iterate) 704 * @return #GNUNET_YES (continue to iterate)
699 */ 705 */
700static int 706static int
701update_counters(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) 707update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
702{ 708{
703 struct Counters *c = cls; 709 struct Counters *c = cls;
704 struct Peer *peer = value; 710 struct Peer *peer = value;
705 struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT]; 711 struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT];
706 712
707 (void)pid; 713 (void) pid;
708 if (NULL == peer->sh_head) 714 if (NULL == peer->sh_head)
709 return GNUNET_YES; /* no available session, cannot allocate bandwidth */ 715 return GNUNET_YES; /* no available session, cannot allocate bandwidth */
710 memset(best, 0, sizeof(best)); 716 memset (best, 0, sizeof(best));
711 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; 717 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh;
712 sh = sh->next) 718 sh = sh->next)
719 {
720 enum GNUNET_NetworkType nt = sh->data->prop.nt;
721
722 sh->target_out = MIN_BANDWIDTH_PER_SESSION;
723 c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION;
724 c->bw_in_by_nt[nt] +=
725 GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in);
726 for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT;
727 pk++)
713 { 728 {
714 enum GNUNET_NetworkType nt = sh->data->prop.nt; 729 /* General rule: always prefer smaller distance if possible,
715 730 otherwise decide by pk: */
716 sh->target_out = MIN_BANDWIDTH_PER_SESSION; 731 switch (pk)
717 c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; 732 {
718 c->bw_in_by_nt[nt] += 733 case GNUNET_MQ_PREFERENCE_NONE:
719 GNUNET_MAX(MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); 734 break;
720 for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; 735
721 pk++) 736 case GNUNET_MQ_PREFERENCE_BANDWIDTH:
722 { 737 /* For bandwidth, we compare the sum of transmitted bytes and
723 /* General rule: always prefer smaller distance if possible, 738 confirmed transmitted bytes, so confirmed data counts twice */
724 otherwise decide by pk: */ 739 if ((NULL == best[pk]) ||
725 switch (pk) 740 (sh->data->prop.distance < best[pk]->data->prop.distance) ||
726 { 741 (sh->data->prop.utilization_out + sh->data->prop.goodput_out >
727 case GNUNET_MQ_PREFERENCE_NONE: 742 best[pk]->data->prop.utilization_out
728 break; 743 + best[pk]->data->prop.goodput_out))
729 744 best[pk] = sh;
730 case GNUNET_MQ_PREFERENCE_BANDWIDTH: 745 /* If both are equal (i.e. usually this happens if there is a zero), use
731 /* For bandwidth, we compare the sum of transmitted bytes and 746 latency as a yardstick */
732 confirmed transmitted bytes, so confirmed data counts twice */ 747 if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out ==
733 if ((NULL == best[pk]) || 748 best[pk]->data->prop.utilization_out
734 (sh->data->prop.distance < best[pk]->data->prop.distance) || 749 + best[pk]->data->prop.goodput_out) &&
735 (sh->data->prop.utilization_out + sh->data->prop.goodput_out > 750 (sh->data->prop.distance == best[pk]->data->prop.distance) &&
736 best[pk]->data->prop.utilization_out + 751 (sh->data->prop.delay.rel_value_us <
737 best[pk]->data->prop.goodput_out)) 752 best[pk]->data->prop.delay.rel_value_us))
738 best[pk] = sh; 753 best[pk] = sh;
739 /* If both are equal (i.e. usually this happens if there is a zero), use 754 break;
740 latency as a yardstick */ 755
741 if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == 756 case GNUNET_MQ_PREFERENCE_LATENCY:
742 best[pk]->data->prop.utilization_out + 757 if ((NULL == best[pk]) ||
743 best[pk]->data->prop.goodput_out) && 758 (sh->data->prop.distance < best[pk]->data->prop.distance) ||
744 (sh->data->prop.distance == best[pk]->data->prop.distance) && 759 ((sh->data->prop.distance == best[pk]->data->prop.distance) &&
745 (sh->data->prop.delay.rel_value_us < 760 (sh->data->prop.delay.rel_value_us <
746 best[pk]->data->prop.delay.rel_value_us)) 761 best[pk]->data->prop.delay.rel_value_us)))
747 best[pk] = sh; 762 best[pk] = sh;
748 break; 763 break;
749 764
750 case GNUNET_MQ_PREFERENCE_LATENCY: 765 case GNUNET_MQ_PREFERENCE_RELIABILITY:
751 if ((NULL == best[pk]) || 766 /* For reliability, we consider the ratio of goodput to utilization
752 (sh->data->prop.distance < best[pk]->data->prop.distance) || 767 (but use multiplicative formultations to avoid division by zero) */
753 ((sh->data->prop.distance == best[pk]->data->prop.distance) && 768 if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out
754 (sh->data->prop.delay.rel_value_us < 769 * best[pk]->data->prop.utilization_out >
755 best[pk]->data->prop.delay.rel_value_us))) 770 1ULL * sh->data->prop.utilization_out
756 best[pk] = sh; 771 * best[pk]->data->prop.goodput_out))
757 break; 772 best[pk] = sh;
758 773 /* If both are equal (i.e. usually this happens if there is a zero), use
759 case GNUNET_MQ_PREFERENCE_RELIABILITY: 774 latency as a yardstick */
760 /* For reliability, we consider the ratio of goodput to utilization 775 if ((1ULL * sh->data->prop.goodput_out
761 (but use multiplicative formultations to avoid division by zero) */ 776 * best[pk]->data->prop.utilization_out ==
762 if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * 777 1ULL * sh->data->prop.utilization_out
763 best[pk]->data->prop.utilization_out > 778 * best[pk]->data->prop.goodput_out) &&
764 1ULL * sh->data->prop.utilization_out * 779 (sh->data->prop.distance == best[pk]->data->prop.distance) &&
765 best[pk]->data->prop.goodput_out)) 780 (sh->data->prop.delay.rel_value_us <
766 best[pk] = sh; 781 best[pk]->data->prop.delay.rel_value_us))
767 /* If both are equal (i.e. usually this happens if there is a zero), use 782 best[pk] = sh;
768 latency as a yardstick */ 783 break;
769 if ((1ULL * sh->data->prop.goodput_out * 784 }
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 }
780 } 785 }
786 }
781 /* for first round, assign target bandwidth simply to sum of 787 /* for first round, assign target bandwidth simply to sum of
782 requested bandwidth */ 788 requested bandwidth */
783 for (enum GNUNET_MQ_PreferenceKind pk = 789 for (enum GNUNET_MQ_PreferenceKind pk =
784 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; 790 1 /* skip GNUNET_MQ_PREFERENCE_NONE */;
785 pk < GNUNET_MQ_PREFERENCE_COUNT; 791 pk < GNUNET_MQ_PREFERENCE_COUNT;
786 pk++) 792 pk++)
787 { 793 {
788 const struct GNUNET_ATS_SessionData *data = best[pk]->data; 794 const struct GNUNET_ATS_SessionData *data = best[pk]->data;
789 enum GNUNET_NetworkType nt; 795 enum GNUNET_NetworkType nt;
790 796
791 GNUNET_assert(NULL != data); 797 GNUNET_assert (NULL != data);
792 nt = data->prop.nt; 798 nt = data->prop.nt;
793 best[pk]->target_out = 799 best[pk]->target_out =
794 GNUNET_MIN(peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); 800 GNUNET_MIN (peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION);
795 c->bw_out_by_nt[nt] += 801 c->bw_out_by_nt[nt] +=
796 (uint64_t)(best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); 802 (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION);
797 } 803 }
798 return GNUNET_YES; 804 return GNUNET_YES;
799} 805}
800 806
@@ -809,23 +815,23 @@ update_counters(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
809 * @return #GNUNET_YES (continue to iterate) 815 * @return #GNUNET_YES (continue to iterate)
810 */ 816 */
811static int 817static int
812update_allocation(void *cls, 818update_allocation (void *cls,
813 const struct GNUNET_PeerIdentity *pid, 819 const struct GNUNET_PeerIdentity *pid,
814 void *value) 820 void *value)
815{ 821{
816 struct Counters *c = cls; 822 struct Counters *c = cls;
817 struct Peer *peer = value; 823 struct Peer *peer = value;
818 824
819 (void)pid; 825 (void) pid;
820 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; 826 for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh;
821 sh = sh->next) 827 sh = sh->next)
822 { 828 {
823 enum GNUNET_NetworkType nt = sh->data->prop.nt; 829 enum GNUNET_NetworkType nt = sh->data->prop.nt;
824 830
825 sh->target_out = (uint64_t)(c->scale_out[nt] * sh->target_out); 831 sh->target_out = (uint64_t) (c->scale_out[nt] * sh->target_out);
826 sh->target_in = (uint64_t)(c->scale_in[nt] * sh->target_in); 832 sh->target_in = (uint64_t) (c->scale_in[nt] * sh->target_in);
827 consider_notify_transport(sh); 833 consider_notify_transport (sh);
828 } 834 }
829 return GNUNET_YES; 835 return GNUNET_YES;
830} 836}
831 837
@@ -834,23 +840,23 @@ update_allocation(void *cls,
834 * The world changed, recalculate our allocations. 840 * The world changed, recalculate our allocations.
835 */ 841 */
836static void 842static void
837update(struct SimpleHandle *h) 843update (struct SimpleHandle *h)
838{ 844{
839 struct Counters cnt = { .h = h }; 845 struct Counters cnt = { .h = h };
840 846
841 GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_counters, &cnt); 847 GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_counters, &cnt);
842 /* calculate how badly the missmatch between requested 848 /* calculate how badly the missmatch between requested
843 allocations and available bandwidth is per network type */ 849 allocations and available bandwidth is per network type */
844 for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) 850 for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++)
845 { 851 {
846 cnt.scale_out[nt] = 852 cnt.scale_out[nt] =
847 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; 853 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out;
848 cnt.scale_in[nt] = 854 cnt.scale_in[nt] =
849 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; 855 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in;
850 } 856 }
851 /* recalculate allocations, considering scaling factor, and 857 /* recalculate allocations, considering scaling factor, and
852 update transport if the change is significant */ 858 update transport if the change is significant */
853 GNUNET_CONTAINER_multipeermap_iterate(h->peers, &update_allocation, &cnt); 859 GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_allocation, &cnt);
854} 860}
855 861
856 862
@@ -862,15 +868,15 @@ update(struct SimpleHandle *h)
862 * @return plugin's internal representation, or NULL 868 * @return plugin's internal representation, or NULL
863 */ 869 */
864static struct GNUNET_ATS_PreferenceHandle * 870static struct GNUNET_ATS_PreferenceHandle *
865simple_preference_add(void *cls, const struct GNUNET_ATS_Preference *pref) 871simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref)
866{ 872{
867 struct SimpleHandle *h = cls; 873 struct SimpleHandle *h = cls;
868 struct Peer *p = peer_add(h, &pref->peer); 874 struct Peer *p = peer_add (h, &pref->peer);
869 875
870 GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); 876 GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT);
871 p->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); 877 p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__);
872 h->bw_by_pk[pref->pk] += ntohl(pref->bw.value__); 878 h->bw_by_pk[pref->pk] += ntohl (pref->bw.value__);
873 update(h); 879 update (h);
874 return NULL; 880 return NULL;
875} 881}
876 882
@@ -884,20 +890,20 @@ simple_preference_add(void *cls, const struct GNUNET_ATS_Preference *pref)
884 * @return plugin's internal representation, or NULL 890 * @return plugin's internal representation, or NULL
885 */ 891 */
886static void 892static void
887simple_preference_del(void *cls, 893simple_preference_del (void *cls,
888 struct GNUNET_ATS_PreferenceHandle *ph, 894 struct GNUNET_ATS_PreferenceHandle *ph,
889 const struct GNUNET_ATS_Preference *pref) 895 const struct GNUNET_ATS_Preference *pref)
890{ 896{
891 struct SimpleHandle *h = cls; 897 struct SimpleHandle *h = cls;
892 struct Peer *p = lookup_peer(h, &pref->peer); 898 struct Peer *p = lookup_peer (h, &pref->peer);
893 899
894 GNUNET_assert(NULL != p); 900 GNUNET_assert (NULL != p);
895 GNUNET_assert(pref->pk < GNUNET_MQ_PREFERENCE_COUNT); 901 GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT);
896 p->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); 902 p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__);
897 h->bw_by_pk[pref->pk] -= ntohl(pref->bw.value__); 903 h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__);
898 if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead(p))) 904 if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead (p)))
899 peer_free(p); 905 peer_free (p);
900 update(h); 906 update (h);
901} 907}
902 908
903 909
@@ -911,50 +917,50 @@ simple_preference_del(void *cls,
911 * @return handle by which the plugin will identify this session 917 * @return handle by which the plugin will identify this session
912 */ 918 */
913static struct GNUNET_ATS_SessionHandle * 919static struct GNUNET_ATS_SessionHandle *
914simple_session_add(void *cls, 920simple_session_add (void *cls,
915 const struct GNUNET_ATS_SessionData *data, 921 const struct GNUNET_ATS_SessionData *data,
916 const char *address) 922 const char *address)
917{ 923{
918 struct SimpleHandle *h = cls; 924 struct SimpleHandle *h = cls;
919 struct Peer *p = peer_add(h, &data->peer); 925 struct Peer *p = peer_add (h, &data->peer);
920 struct Hello *hello; 926 struct Hello *hello;
921 size_t alen; 927 size_t alen;
922 struct GNUNET_ATS_SessionHandle *sh; 928 struct GNUNET_ATS_SessionHandle *sh;
923 929
924 /* setup session handle */ 930 /* setup session handle */
925 GNUNET_assert(NULL != data); 931 GNUNET_assert (NULL != data);
926 if (NULL == address) 932 if (NULL == address)
927 alen = 0; 933 alen = 0;
928 else 934 else
929 alen = strlen(address) + 1; 935 alen = strlen (address) + 1;
930 sh = GNUNET_malloc(sizeof(struct GNUNET_ATS_SessionHandle) + alen); 936 sh = GNUNET_malloc (sizeof(struct GNUNET_ATS_SessionHandle) + alen);
931 sh->peer = p; 937 sh->peer = p;
932 sh->session = data->session; 938 sh->session = data->session;
933 sh->data = data; 939 sh->data = data;
934 if (NULL == address) 940 if (NULL == address)
935 { 941 {
936 sh->address = NULL; 942 sh->address = NULL;
937 } 943 }
938 else 944 else
939 { 945 {
940 memcpy(&sh[1], address, alen); 946 memcpy (&sh[1], address, alen);
941 sh->address = (const char *)&sh[1]; 947 sh->address = (const char *) &sh[1];
942 } 948 }
943 GNUNET_CONTAINER_DLL_insert(p->sh_head, p->sh_tail, sh); 949 GNUNET_CONTAINER_DLL_insert (p->sh_head, p->sh_tail, sh);
944 if (NULL != address) 950 if (NULL != address)
951 {
952 /* match HELLO */
953 hello = p->h_head;
954 while ((NULL != hello) && (0 != strcmp (address, hello->address)))
955 hello = hello->next;
956 if (NULL != hello)
945 { 957 {
946 /* match HELLO */ 958 hello->sh = sh;
947 hello = p->h_head; 959 hello->backoff = GNUNET_TIME_UNIT_ZERO;
948 while ((NULL != hello) && (0 != strcmp(address, hello->address))) 960 sh->hello = hello;
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 }
956 } 961 }
957 update(h); 962 }
963 update (h);
958 return sh; 964 return sh;
959} 965}
960 966
@@ -968,15 +974,15 @@ simple_session_add(void *cls,
968 * @param data performance characteristics of @a sh 974 * @param data performance characteristics of @a sh
969 */ 975 */
970static void 976static void
971simple_session_update(void *cls, 977simple_session_update (void *cls,
972 struct GNUNET_ATS_SessionHandle *sh, 978 struct GNUNET_ATS_SessionHandle *sh,
973 const struct GNUNET_ATS_SessionData *data) 979 const struct GNUNET_ATS_SessionData *data)
974{ 980{
975 struct SimpleHandle *h = cls; 981 struct SimpleHandle *h = cls;
976 982
977 GNUNET_assert(NULL != data); 983 GNUNET_assert (NULL != data);
978 sh->data = data; /* this statement should not really do anything... */ 984 sh->data = data; /* this statement should not really do anything... */
979 update(h); 985 update (h);
980} 986}
981 987
982 988
@@ -988,30 +994,30 @@ simple_session_update(void *cls,
988 * @param data (last) performance characteristics of @a sh 994 * @param data (last) performance characteristics of @a sh
989 */ 995 */
990static void 996static void
991simple_session_del(void *cls, 997simple_session_del (void *cls,
992 struct GNUNET_ATS_SessionHandle *sh, 998 struct GNUNET_ATS_SessionHandle *sh,
993 const struct GNUNET_ATS_SessionData *data) 999 const struct GNUNET_ATS_SessionData *data)
994{ 1000{
995 struct SimpleHandle *h = cls; 1001 struct SimpleHandle *h = cls;
996 struct Peer *p = sh->peer; 1002 struct Peer *p = sh->peer;
997 struct Hello *hello = sh->hello; 1003 struct Hello *hello = sh->hello;
998 1004
999 /* clean up sh */ 1005 /* clean up sh */
1000 GNUNET_CONTAINER_DLL_remove(p->sh_head, p->sh_tail, sh); 1006 GNUNET_CONTAINER_DLL_remove (p->sh_head, p->sh_tail, sh);
1001 if (NULL != hello) 1007 if (NULL != hello)
1002 { 1008 {
1003 GNUNET_assert(sh == hello->sh); 1009 GNUNET_assert (sh == hello->sh);
1004 hello->sh = NULL; 1010 hello->sh = NULL;
1005 /* session went down, if necessary restart suggesting 1011 /* session went down, if necessary restart suggesting
1006 addresses */ 1012 addresses */
1007 if (NULL == p->task) 1013 if (NULL == p->task)
1008 p->task = GNUNET_SCHEDULER_add_now(&suggest_start_cb, p); 1014 p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p);
1009 } 1015 }
1010 GNUNET_free(sh); 1016 GNUNET_free (sh);
1011 /* del peer if otherwise dead */ 1017 /* del peer if otherwise dead */
1012 if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead(p))) 1018 if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead (p)))
1013 peer_free(p); 1019 peer_free (p);
1014 update(h); 1020 update (h);
1015} 1021}
1016 1022
1017 1023
@@ -1026,16 +1032,16 @@ simple_session_del(void *cls,
1026 * @return the `struct SimpleHandle` to pass as a closure 1032 * @return the `struct SimpleHandle` to pass as a closure
1027 */ 1033 */
1028void * 1034void *
1029libgnunet_plugin_ats2_simple_init(void *cls) 1035libgnunet_plugin_ats2_simple_init (void *cls)
1030{ 1036{
1031 static struct GNUNET_ATS_SolverFunctions sf; 1037 static struct GNUNET_ATS_SolverFunctions sf;
1032 struct GNUNET_ATS_PluginEnvironment *env = cls; 1038 struct GNUNET_ATS_PluginEnvironment *env = cls;
1033 struct SimpleHandle *s; 1039 struct SimpleHandle *s;
1034 1040
1035 s = GNUNET_new(struct SimpleHandle); 1041 s = GNUNET_new (struct SimpleHandle);
1036 s->env = env; 1042 s->env = env;
1037 s->peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES); 1043 s->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
1038 s->ps = GNUNET_PEERSTORE_connect(env->cfg); 1044 s->ps = GNUNET_PEERSTORE_connect (env->cfg);
1039 sf.cls = s; 1045 sf.cls = s;
1040 sf.preference_add = &simple_preference_add; 1046 sf.preference_add = &simple_preference_add;
1041 sf.preference_del = &simple_preference_del; 1047 sf.preference_del = &simple_preference_del;
@@ -1043,18 +1049,18 @@ libgnunet_plugin_ats2_simple_init(void *cls)
1043 sf.session_update = &simple_session_update; 1049 sf.session_update = &simple_session_update;
1044 sf.session_del = &simple_session_del; 1050 sf.session_del = &simple_session_del;
1045 for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) 1051 for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++)
1052 {
1053 const char *name = GNUNET_NT_to_string (nt);
1054
1055 if (NULL == name)
1046 { 1056 {
1047 const char *name = GNUNET_NT_to_string(nt); 1057 GNUNET_break (0);
1048 1058 break;
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;
1057 } 1059 }
1060 get_quota (env->cfg, name, "IN", &s->networks[nt].total_quota_in);
1061 get_quota (env->cfg, name, "OUT", &s->networks[nt].total_quota_out);
1062 s->networks[nt].type = nt;
1063 }
1058 return &sf; 1064 return &sf;
1059} 1065}
1060 1066
@@ -1065,15 +1071,15 @@ libgnunet_plugin_ats2_simple_init(void *cls)
1065 * @param cls return value from #libgnunet_plugin_ats_proportional_init() 1071 * @param cls return value from #libgnunet_plugin_ats_proportional_init()
1066 */ 1072 */
1067void * 1073void *
1068libgnunet_plugin_ats2_simple_done(void *cls) 1074libgnunet_plugin_ats2_simple_done (void *cls)
1069{ 1075{
1070 struct GNUNET_ATS_SolverFunctions *sf = cls; 1076 struct GNUNET_ATS_SolverFunctions *sf = cls;
1071 struct SimpleHandle *s = sf->cls; 1077 struct SimpleHandle *s = sf->cls;
1072 1078
1073 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(s->peers)); 1079 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (s->peers));
1074 GNUNET_CONTAINER_multipeermap_destroy(s->peers); 1080 GNUNET_CONTAINER_multipeermap_destroy (s->peers);
1075 GNUNET_PEERSTORE_disconnect(s->ps, GNUNET_NO); 1081 GNUNET_PEERSTORE_disconnect (s->ps, GNUNET_NO);
1076 GNUNET_free(s); 1082 GNUNET_free (s);
1077 return NULL; 1083 return NULL;
1078} 1084}
1079 1085
diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c
index 8d3c9e23a..6ab823b1e 100644
--- a/src/ats/plugin_ats_mlp.c
+++ b/src/ats/plugin_ats_mlp.c
@@ -39,7 +39,8 @@
39 39
40#define MLP_AVERAGING_QUEUE_LENGTH 3 40#define MLP_AVERAGING_QUEUE_LENGTH 3
41 41
42#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 42#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply ( \
43 GNUNET_TIME_UNIT_SECONDS, 10)
43#define MLP_MAX_ITERATIONS 4096 44#define MLP_MAX_ITERATIONS 4096
44 45
45#define MLP_DEFAULT_D 1.0 46#define MLP_DEFAULT_D 1.0
@@ -54,14 +55,16 @@
54#define GLP_YES 1.0 55#define GLP_YES 1.0
55#define GLP_NO 0.0 56#define GLP_NO 0.0
56 57
57enum MLP_Output_Format { 58enum MLP_Output_Format
59{
58 MLP_MPS, 60 MLP_MPS,
59 MLP_CPLEX, 61 MLP_CPLEX,
60 MLP_GLPK 62 MLP_GLPK
61}; 63};
62 64
63 65
64enum QualityMetrics { 66enum QualityMetrics
67{
65 RQ_QUALITY_METRIC_DELAY = 0, 68 RQ_QUALITY_METRIC_DELAY = 0,
66 RQ_QUALITY_METRIC_DISTANCE = 1, 69 RQ_QUALITY_METRIC_DISTANCE = 1,
67 RQ_QUALITY_METRIC_COUNT = 2 70 RQ_QUALITY_METRIC_COUNT = 2
@@ -69,24 +72,25 @@ enum QualityMetrics {
69 72
70 73
71static const char * 74static const char *
72print_quality_type(enum QualityMetrics qm) 75print_quality_type (enum QualityMetrics qm)
73{ 76{
74 switch (qm) 77 switch (qm)
75 { 78 {
76 case RQ_QUALITY_METRIC_DELAY: 79 case RQ_QUALITY_METRIC_DELAY:
77 return "delay"; 80 return "delay";
78 81
79 case RQ_QUALITY_METRIC_DISTANCE: 82 case RQ_QUALITY_METRIC_DISTANCE:
80 return "distance"; 83 return "distance";
81 84
82 default: 85 default:
83 GNUNET_break(0); 86 GNUNET_break (0);
84 return NULL; 87 return NULL;
85 } 88 }
86} 89}
87 90
88 91
89struct MLP_Solution { 92struct MLP_Solution
93{
90 int lp_res; 94 int lp_res;
91 int lp_presolv; 95 int lp_presolv;
92 int mip_res; 96 int mip_res;
@@ -105,7 +109,8 @@ struct MLP_Solution {
105 int n_addresses; 109 int n_addresses;
106}; 110};
107 111
108struct ATS_Peer { 112struct ATS_Peer
113{
109 struct GNUNET_PeerIdentity id; 114 struct GNUNET_PeerIdentity id;
110 115
111 /* Was this peer already added to the current problem? */ 116 /* Was this peer already added to the current problem? */
@@ -121,7 +126,8 @@ struct ATS_Peer {
121 double f; 126 double f;
122}; 127};
123 128
124struct MLP_Problem { 129struct MLP_Problem
130{
125 /** 131 /**
126 * GLPK (MLP) problem object 132 * GLPK (MLP) problem object
127 */ 133 */
@@ -169,7 +175,8 @@ struct MLP_Problem {
169 double *ar; 175 double *ar;
170}; 176};
171 177
172struct MLP_Variables { 178struct MLP_Variables
179{
173 /* Big M value for bandwidth capping */ 180 /* Big M value for bandwidth capping */
174 double BIG_M; 181 double BIG_M;
175 182
@@ -225,7 +232,8 @@ struct MLP_Variables {
225/** 232/**
226 * MLP Handle 233 * MLP Handle
227 */ 234 */
228struct GAS_MLP_Handle { 235struct GAS_MLP_Handle
236{
229 struct GNUNET_ATS_PluginEnvironment *env; 237 struct GNUNET_ATS_PluginEnvironment *env;
230 238
231 /** 239 /**
@@ -360,7 +368,8 @@ struct GAS_MLP_Handle {
360/** 368/**
361 * Address specific MLP information 369 * Address specific MLP information
362 */ 370 */
363struct MLP_information { 371struct MLP_information
372{
364 /** 373 /**
365 * Bandwidth assigned outbound 374 * Bandwidth assigned outbound
366 */ 375 */
@@ -503,7 +512,7 @@ struct MLP_information {
503 512
504 */ 513 */
505 514
506#define LOG(kind, ...) GNUNET_log_from(kind, "ats-mlp", __VA_ARGS__) 515#define LOG(kind, ...) GNUNET_log_from (kind, "ats-mlp", __VA_ARGS__)
507 516
508/** 517/**
509 * Print debug output for mlp problem creation 518 * Print debug output for mlp problem creation
@@ -518,12 +527,12 @@ struct MLP_information {
518 * @return 0: glpk prints output on terminal, 0 != surpress output 527 * @return 0: glpk prints output on terminal, 0 != surpress output
519 */ 528 */
520static int 529static int
521mlp_term_hook(void *info, const char *s) 530mlp_term_hook (void *info, const char *s)
522{ 531{
523 struct GAS_MLP_Handle *mlp = info; 532 struct GAS_MLP_Handle *mlp = info;
524 533
525 if (mlp->opt_dbg_glpk_verbose) 534 if (mlp->opt_dbg_glpk_verbose)
526 LOG(GNUNET_ERROR_TYPE_ERROR, "%s", s); 535 LOG (GNUNET_ERROR_TYPE_ERROR, "%s", s);
527 return 1; 536 return 1;
528} 537}
529 538
@@ -537,9 +546,9 @@ mlp_term_hook(void *info, const char *s)
537 * @return #GNUNET_OK 546 * @return #GNUNET_OK
538 */ 547 */
539static int 548static int
540reset_peers(void *cls, 549reset_peers (void *cls,
541 const struct GNUNET_PeerIdentity *key, 550 const struct GNUNET_PeerIdentity *key,
542 void *value) 551 void *value)
543{ 552{
544 struct ATS_Peer *peer = value; 553 struct ATS_Peer *peer = value;
545 554
@@ -553,38 +562,38 @@ reset_peers(void *cls,
553 * @param mlp the MLP handle 562 * @param mlp the MLP handle
554 */ 563 */
555static void 564static void
556mlp_delete_problem(struct GAS_MLP_Handle *mlp) 565mlp_delete_problem (struct GAS_MLP_Handle *mlp)
557{ 566{
558 int c; 567 int c;
559 568
560 if (mlp == NULL) 569 if (mlp == NULL)
561 return; 570 return;
562 if (mlp->p.prob != NULL) 571 if (mlp->p.prob != NULL)
563 { 572 {
564 glp_delete_prob(mlp->p.prob); 573 glp_delete_prob (mlp->p.prob);
565 mlp->p.prob = NULL; 574 mlp->p.prob = NULL;
566 } 575 }
567 576
568 /* delete row index */ 577 /* delete row index */
569 if (mlp->p.ia != NULL) 578 if (mlp->p.ia != NULL)
570 { 579 {
571 GNUNET_free(mlp->p.ia); 580 GNUNET_free (mlp->p.ia);
572 mlp->p.ia = NULL; 581 mlp->p.ia = NULL;
573 } 582 }
574 583
575 /* delete column index */ 584 /* delete column index */
576 if (mlp->p.ja != NULL) 585 if (mlp->p.ja != NULL)
577 { 586 {
578 GNUNET_free(mlp->p.ja); 587 GNUNET_free (mlp->p.ja);
579 mlp->p.ja = NULL; 588 mlp->p.ja = NULL;
580 } 589 }
581 590
582 /* delete coefficients */ 591 /* delete coefficients */
583 if (mlp->p.ar != NULL) 592 if (mlp->p.ar != NULL)
584 { 593 {
585 GNUNET_free(mlp->p.ar); 594 GNUNET_free (mlp->p.ar);
586 mlp->p.ar = NULL; 595 mlp->p.ar = NULL;
587 } 596 }
588 mlp->p.ci = 0; 597 mlp->p.ci = 0;
589 mlp->p.prob = NULL; 598 mlp->p.prob = NULL;
590 599
@@ -601,8 +610,8 @@ mlp_delete_problem(struct GAS_MLP_Handle *mlp)
601 mlp->p.ci = MLP_UNDEFINED; 610 mlp->p.ci = MLP_UNDEFINED;
602 611
603 612
604 GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers, 613 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
605 &reset_peers, NULL); 614 &reset_peers, NULL);
606} 615}
607 616
608 617
@@ -612,32 +621,32 @@ mlp_delete_problem(struct GAS_MLP_Handle *mlp)
612 * @return string with result 621 * @return string with result
613 */ 622 */
614static const char * 623static const char *
615mlp_status_to_string(int retcode) 624mlp_status_to_string (int retcode)
616{ 625{
617 switch (retcode) 626 switch (retcode)
618 { 627 {
619 case GLP_UNDEF: 628 case GLP_UNDEF:
620 return "solution is undefined"; 629 return "solution is undefined";
621 630
622 case GLP_FEAS: 631 case GLP_FEAS:
623 return "solution is feasible"; 632 return "solution is feasible";
624 633
625 case GLP_INFEAS: 634 case GLP_INFEAS:
626 return "solution is infeasible"; 635 return "solution is infeasible";
627 636
628 case GLP_NOFEAS: 637 case GLP_NOFEAS:
629 return "no feasible solution exists"; 638 return "no feasible solution exists";
630 639
631 case GLP_OPT: 640 case GLP_OPT:
632 return "solution is optimal"; 641 return "solution is optimal";
633 642
634 case GLP_UNBND: 643 case GLP_UNBND:
635 return "solution is unbounded"; 644 return "solution is unbounded";
636 645
637 default: 646 default:
638 GNUNET_break(0); 647 GNUNET_break (0);
639 return "unknown error"; 648 return "unknown error";
640 } 649 }
641} 650}
642 651
643 652
@@ -647,134 +656,142 @@ mlp_status_to_string(int retcode)
647 * @return string with result 656 * @return string with result
648 */ 657 */
649static const char * 658static const char *
650mlp_solve_to_string(int retcode) 659mlp_solve_to_string (int retcode)
651{ 660{
652 switch (retcode) 661 switch (retcode)
653 { 662 {
654 case 0: 663 case 0:
655 return "ok"; 664 return "ok";
656 665
657 case GLP_EBADB: 666 case GLP_EBADB:
658 return "invalid basis"; 667 return "invalid basis";
659 668
660 case GLP_ESING: 669 case GLP_ESING:
661 return "singular matrix"; 670 return "singular matrix";
662 671
663 case GLP_ECOND: 672 case GLP_ECOND:
664 return "ill-conditioned matrix"; 673 return "ill-conditioned matrix";
665 674
666 case GLP_EBOUND: 675 case GLP_EBOUND:
667 return "invalid bounds"; 676 return "invalid bounds";
668 677
669 case GLP_EFAIL: 678 case GLP_EFAIL:
670 return "solver failed"; 679 return "solver failed";
671 680
672 case GLP_EOBJLL: 681 case GLP_EOBJLL:
673 return "objective lower limit reached"; 682 return "objective lower limit reached";
674 683
675 case GLP_EOBJUL: 684 case GLP_EOBJUL:
676 return "objective upper limit reached"; 685 return "objective upper limit reached";
677 686
678 case GLP_EITLIM: 687 case GLP_EITLIM:
679 return "iteration limit exceeded"; 688 return "iteration limit exceeded";
680 689
681 case GLP_ETMLIM: 690 case GLP_ETMLIM:
682 return "time limit exceeded"; 691 return "time limit exceeded";
683 692
684 case GLP_ENOPFS: 693 case GLP_ENOPFS:
685 return "no primal feasible solution"; 694 return "no primal feasible solution";
686 695
687 case GLP_ENODFS: 696 case GLP_ENODFS:
688 return "no dual feasible solution"; 697 return "no dual feasible solution";
689 698
690 case GLP_EROOT: 699 case GLP_EROOT:
691 return "root LP optimum not provided"; 700 return "root LP optimum not provided";
692 701
693 case GLP_ESTOP: 702 case GLP_ESTOP:
694 return "search terminated by application"; 703 return "search terminated by application";
695 704
696 case GLP_EMIPGAP: 705 case GLP_EMIPGAP:
697 return "relative mip gap tolerance reached"; 706 return "relative mip gap tolerance reached";
698 707
699 case GLP_ENOFEAS: 708 case GLP_ENOFEAS:
700 return "no dual feasible solution"; 709 return "no dual feasible solution";
701 710
702 case GLP_ENOCVG: 711 case GLP_ENOCVG:
703 return "no convergence"; 712 return "no convergence";
704 713
705 case GLP_EINSTAB: 714 case GLP_EINSTAB:
706 return "numerical instability"; 715 return "numerical instability";
707 716
708 case GLP_EDATA: 717 case GLP_EDATA:
709 return "invalid data"; 718 return "invalid data";
710 719
711 case GLP_ERANGE: 720 case GLP_ERANGE:
712 return "result out of range"; 721 return "result out of range";
713 722
714 default: 723 default:
715 GNUNET_break(0); 724 GNUNET_break (0);
716 return "unknown error"; 725 return "unknown error";
717 } 726 }
718} 727}
719 728
720 729
721struct CountContext { 730struct CountContext
731{
722 const struct GNUNET_CONTAINER_MultiPeerMap *map; 732 const struct GNUNET_CONTAINER_MultiPeerMap *map;
723 int result; 733 int result;
724}; 734};
725 735
726static int 736static int
727mlp_create_problem_count_addresses_it(void *cls, 737mlp_create_problem_count_addresses_it (void *cls,
728 const struct GNUNET_PeerIdentity *key, 738 const struct GNUNET_PeerIdentity *key,
729 void *value) 739 void *value)
730{ 740{
731 struct CountContext *cctx = cls; 741 struct CountContext *cctx = cls;
732 742
733 /* Check if we have to add this peer due to a pending request */ 743 /* Check if we have to add this peer due to a pending request */
734 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key)) 744 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
735 cctx->result++; 745 cctx->result++;
736 return GNUNET_OK; 746 return GNUNET_OK;
737} 747}
738 748
739 749
740static int 750static int
741mlp_create_problem_count_addresses(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, 751mlp_create_problem_count_addresses (const struct
742 const struct GNUNET_CONTAINER_MultiPeerMap *addresses) 752 GNUNET_CONTAINER_MultiPeerMap *
753 requested_peers,
754 const struct
755 GNUNET_CONTAINER_MultiPeerMap *addresses)
743{ 756{
744 struct CountContext cctx; 757 struct CountContext cctx;
745 758
746 cctx.map = requested_peers; 759 cctx.map = requested_peers;
747 cctx.result = 0; 760 cctx.result = 0;
748 GNUNET_CONTAINER_multipeermap_iterate(addresses, 761 GNUNET_CONTAINER_multipeermap_iterate (addresses,
749 &mlp_create_problem_count_addresses_it, &cctx); 762 &mlp_create_problem_count_addresses_it,
763 &cctx);
750 return cctx.result; 764 return cctx.result;
751} 765}
752 766
753 767
754static int 768static int
755mlp_create_problem_count_peers_it(void *cls, 769mlp_create_problem_count_peers_it (void *cls,
756 const struct GNUNET_PeerIdentity *key, 770 const struct GNUNET_PeerIdentity *key,
757 void *value) 771 void *value)
758{ 772{
759 struct CountContext *cctx = cls; 773 struct CountContext *cctx = cls;
760 774
761 /* Check if we have to addresses for the requested peer */ 775 /* Check if we have to addresses for the requested peer */
762 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(cctx->map, key)) 776 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (cctx->map, key))
763 cctx->result++; 777 cctx->result++;
764 return GNUNET_OK; 778 return GNUNET_OK;
765} 779}
766 780
767 781
768static int 782static int
769mlp_create_problem_count_peers(const struct GNUNET_CONTAINER_MultiPeerMap *requested_peers, 783mlp_create_problem_count_peers (const struct
770 const struct GNUNET_CONTAINER_MultiPeerMap *addresses) 784 GNUNET_CONTAINER_MultiPeerMap *requested_peers,
785 const struct
786 GNUNET_CONTAINER_MultiPeerMap *addresses)
771{ 787{
772 struct CountContext cctx; 788 struct CountContext cctx;
773 789
774 cctx.map = addresses; 790 cctx.map = addresses;
775 cctx.result = 0; 791 cctx.result = 0;
776 GNUNET_CONTAINER_multipeermap_iterate(requested_peers, 792 GNUNET_CONTAINER_multipeermap_iterate (requested_peers,
777 &mlp_create_problem_count_peers_it, &cctx); 793 &mlp_create_problem_count_peers_it,
794 &cctx);
778 return cctx.result; 795 return cctx.result;
779} 796}
780 797
@@ -793,9 +810,9 @@ mlp_create_problem_count_peers(const struct GNUNET_CONTAINER_MultiPeerMap *reque
793 * on error 810 * on error
794 */ 811 */
795static int 812static int
796mlp_create_problem_update_value(struct MLP_Problem *p, 813mlp_create_problem_update_value (struct MLP_Problem *p,
797 int row, int col, double val, 814 int row, int col, double val,
798 int line) 815 int line)
799{ 816{
800 int c_cols; 817 int c_cols;
801 int c_elems; 818 int c_elems;
@@ -805,59 +822,60 @@ mlp_create_problem_update_value(struct MLP_Problem *p,
805 double *val_array; 822 double *val_array;
806 int *ind_array; 823 int *ind_array;
807 824
808 GNUNET_assert(NULL != p->prob); 825 GNUNET_assert (NULL != p->prob);
809 826
810 /* Get number of columns and prepare data structure */ 827 /* Get number of columns and prepare data structure */
811 c_cols = glp_get_num_cols(p->prob); 828 c_cols = glp_get_num_cols (p->prob);
812 if (0 >= c_cols) 829 if (0 >= c_cols)
813 return GNUNET_SYSERR; 830 return GNUNET_SYSERR;
814 831
815 val_array = GNUNET_malloc((c_cols + 1) * sizeof(double)); 832 val_array = GNUNET_malloc ((c_cols + 1) * sizeof(double));
816 GNUNET_assert(NULL != val_array); 833 GNUNET_assert (NULL != val_array);
817 ind_array = GNUNET_malloc((c_cols + 1) * sizeof(int)); 834 ind_array = GNUNET_malloc ((c_cols + 1) * sizeof(int));
818 GNUNET_assert(NULL != ind_array); 835 GNUNET_assert (NULL != ind_array);
819 /* Extract the row */ 836 /* Extract the row */
820 837
821 /* Update the value */ 838 /* Update the value */
822 c_elems = glp_get_mat_row(p->prob, row, ind_array, val_array); 839 c_elems = glp_get_mat_row (p->prob, row, ind_array, val_array);
823 found = GNUNET_NO; 840 found = GNUNET_NO;
824 for (c1 = 1; c1 < (c_elems + 1); c1++) 841 for (c1 = 1; c1 < (c_elems + 1); c1++)
842 {
843 if (ind_array[c1] == col)
825 { 844 {
826 if (ind_array[c1] == col) 845 found = GNUNET_YES;
827 { 846 break;
828 found = GNUNET_YES;
829 break;
830 }
831 } 847 }
848 }
832 if (GNUNET_NO == found) 849 if (GNUNET_NO == found)
833 { 850 {
834 ind_array[c_elems + 1] = col; 851 ind_array[c_elems + 1] = col;
835 val_array[c_elems + 1] = val; 852 val_array[c_elems + 1] = val;
836 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n", 853 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P] Setting value in [%s : %s] to `%.2f'\n",
837 glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col), 854 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
838 val); 855 val);
839 glp_set_mat_row(p->prob, row, c_elems + 1, ind_array, val_array); 856 glp_set_mat_row (p->prob, row, c_elems + 1, ind_array, val_array);
840 GNUNET_free(ind_array); 857 GNUNET_free (ind_array);
841 GNUNET_free(val_array); 858 GNUNET_free (val_array);
842 return GNUNET_YES; 859 return GNUNET_YES;
843 } 860 }
844 else 861 else
845 { 862 {
846 /* Update value */ 863 /* Update value */
847 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n", 864 LOG (GNUNET_ERROR_TYPE_DEBUG,
848 glp_get_row_name(p->prob, row), glp_get_col_name(p->prob, col), 865 "[P] Updating value in [%s : %s] from `%.2f' to `%.2f'\n",
849 val_array[c1], val); 866 glp_get_row_name (p->prob, row), glp_get_col_name (p->prob, col),
850 if (val != val_array[c1]) 867 val_array[c1], val);
851 res = GNUNET_YES; 868 if (val != val_array[c1])
852 else 869 res = GNUNET_YES;
853 res = GNUNET_NO; 870 else
854 val_array[c1] = val; 871 res = GNUNET_NO;
855 /* Update the row in the matrix */ 872 val_array[c1] = val;
856 glp_set_mat_row(p->prob, row, c_elems, ind_array, val_array); 873 /* Update the row in the matrix */
857 } 874 glp_set_mat_row (p->prob, row, c_elems, ind_array, val_array);
858 875 }
859 GNUNET_free(ind_array); 876
860 GNUNET_free(val_array); 877 GNUNET_free (ind_array);
878 GNUNET_free (val_array);
861 return res; 879 return res;
862} 880}
863 881
@@ -874,89 +892,93 @@ mlp_create_problem_update_value(struct MLP_Problem *p,
874 * @param line calling line for debbuging 892 * @param line calling line for debbuging
875 */ 893 */
876static void 894static void
877mlp_create_problem_set_value(struct MLP_Problem *p, 895mlp_create_problem_set_value (struct MLP_Problem *p,
878 int row, int col, double val, 896 int row, int col, double val,
879 int line) 897 int line)
880{ 898{
881 if ((p->ci) >= p->num_elements) 899 if ((p->ci) >= p->num_elements)
882 { 900 {
883 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Request for index %u bigger than array size of %u\n", 901 LOG (GNUNET_ERROR_TYPE_DEBUG,
884 line, p->ci + 1, p->num_elements); 902 "[P]: line %u: Request for index %u bigger than array size of %u\n",
885 GNUNET_break(0); 903 line, p->ci + 1, p->num_elements);
886 return; 904 GNUNET_break (0);
887 } 905 return;
906 }
888 if ((0 == row) || (0 == col)) 907 if ((0 == row) || (0 == col))
889 { 908 {
890 GNUNET_break(0); 909 GNUNET_break (0);
891 LOG(GNUNET_ERROR_TYPE_ERROR, "[P]: Invalid call from line %u: row = %u, col = %u\n", 910 LOG (GNUNET_ERROR_TYPE_ERROR,
892 line, row, col); 911 "[P]: Invalid call from line %u: row = %u, col = %u\n",
893 } 912 line, row, col);
913 }
894 p->ia[p->ci] = row; 914 p->ia[p->ci] = row;
895 p->ja[p->ci] = col; 915 p->ja[p->ci] = col;
896 p->ar[p->ci] = val; 916 p->ar[p->ci] = val;
897#if DEBUG_MLP_PROBLEM_CREATION 917#if DEBUG_MLP_PROBLEM_CREATION
898 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n", 918 LOG (GNUNET_ERROR_TYPE_DEBUG,
899 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]); 919 "[P]: line %u: Set value [%u,%u] in index %u == %.2f\n",
920 line, p->ia[p->ci], p->ja[p->ci], p->ci, p->ar[p->ci]);
900#endif 921#endif
901 p->ci++; 922 p->ci++;
902} 923}
903 924
904static int 925static int
905mlp_create_problem_create_column(struct MLP_Problem *p, char *name, 926mlp_create_problem_create_column (struct MLP_Problem *p, char *name,
906 unsigned int type, unsigned int bound, double lb, double ub, 927 unsigned int type, unsigned int bound, double
907 double coef) 928 lb, double ub,
929 double coef)
908{ 930{
909 int col = glp_add_cols(p->prob, 1); 931 int col = glp_add_cols (p->prob, 1);
910 932
911 glp_set_col_name(p->prob, col, name); 933 glp_set_col_name (p->prob, col, name);
912 glp_set_col_bnds(p->prob, col, bound, lb, ub); 934 glp_set_col_bnds (p->prob, col, bound, lb, ub);
913 glp_set_col_kind(p->prob, col, type); 935 glp_set_col_kind (p->prob, col, type);
914 glp_set_obj_coef(p->prob, col, coef); 936 glp_set_obj_coef (p->prob, col, coef);
915#if DEBUG_MLP_PROBLEM_CREATION 937#if DEBUG_MLP_PROBLEM_CREATION
916 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n", 938 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added column [%u] `%s': %.2f\n",
917 col, name, coef); 939 col, name, coef);
918#endif 940#endif
919 return col; 941 return col;
920} 942}
921 943
922static int 944static int
923mlp_create_problem_create_constraint(struct MLP_Problem *p, char *name, 945mlp_create_problem_create_constraint (struct MLP_Problem *p, char *name,
924 unsigned int bound, double lb, double ub) 946 unsigned int bound, double lb, double ub)
925{ 947{
926 char * op; 948 char *op;
927 int row = glp_add_rows(p->prob, 1); 949 int row = glp_add_rows (p->prob, 1);
928 950
929 /* set row name */ 951 /* set row name */
930 glp_set_row_name(p->prob, row, name); 952 glp_set_row_name (p->prob, row, name);
931 /* set row bounds: <= 0 */ 953 /* set row bounds: <= 0 */
932 glp_set_row_bnds(p->prob, row, bound, lb, ub); 954 glp_set_row_bnds (p->prob, row, bound, lb, ub);
933 switch (bound) 955 switch (bound)
934 { 956 {
935 case GLP_UP: 957 case GLP_UP:
936 GNUNET_asprintf(&op, "-inf <= x <= %.2f", ub); 958 GNUNET_asprintf (&op, "-inf <= x <= %.2f", ub);
937 break; 959 break;
938 960
939 case GLP_DB: 961 case GLP_DB:
940 GNUNET_asprintf(&op, "%.2f <= x <= %.2f", lb, ub); 962 GNUNET_asprintf (&op, "%.2f <= x <= %.2f", lb, ub);
941 break; 963 break;
942 964
943 case GLP_FX: 965 case GLP_FX:
944 GNUNET_asprintf(&op, "%.2f == x == %.2f", lb, ub); 966 GNUNET_asprintf (&op, "%.2f == x == %.2f", lb, ub);
945 break; 967 break;
946 968
947 case GLP_LO: 969 case GLP_LO:
948 GNUNET_asprintf(&op, "%.2f <= x <= inf", lb); 970 GNUNET_asprintf (&op, "%.2f <= x <= inf", lb);
949 break; 971 break;
950 972
951 default: 973 default:
952 GNUNET_asprintf(&op, "ERROR"); 974 GNUNET_asprintf (&op, "ERROR");
953 break; 975 break;
954 } 976 }
955#if DEBUG_MLP_PROBLEM_CREATION 977#if DEBUG_MLP_PROBLEM_CREATION
956 LOG(GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n", 978 LOG (GNUNET_ERROR_TYPE_DEBUG, "[P]: Added row [%u] `%s': %s\n",
957 row, name, op); 979 row, name, op);
958#endif 980#endif
959 GNUNET_free(op); 981 GNUNET_free (op);
960 return row; 982 return row;
961} 983}
962 984
@@ -968,9 +990,10 @@ mlp_create_problem_create_constraint(struct MLP_Problem *p, char *name,
968 * - Set address dependent entries in problem matrix as well 990 * - Set address dependent entries in problem matrix as well
969 */ 991 */
970static int 992static int
971mlp_create_problem_add_address_information(void *cls, 993mlp_create_problem_add_address_information (void *cls,
972 const struct GNUNET_PeerIdentity *key, 994 const struct
973 void *value) 995 GNUNET_PeerIdentity *key,
996 void *value)
974{ 997{
975 struct GAS_MLP_Handle *mlp = cls; 998 struct GAS_MLP_Handle *mlp = cls;
976 struct MLP_Problem *p = &mlp->p; 999 struct MLP_Problem *p = &mlp->p;
@@ -985,68 +1008,72 @@ mlp_create_problem_add_address_information(void *cls,
985 int c; 1008 int c;
986 1009
987 /* Check if we have to add this peer due to a pending request */ 1010 /* Check if we have to add this peer due to a pending request */
988 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers, key)) 1011 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers,
1012 key))
989 return GNUNET_OK; 1013 return GNUNET_OK;
990 1014
991 mlpi = address->solver_information; 1015 mlpi = address->solver_information;
992 if (NULL == mlpi) 1016 if (NULL == mlpi)
993 { 1017 {
994 fprintf(stderr, "%s %p\n", GNUNET_i2s(&address->peer), address); 1018 fprintf (stderr, "%s %p\n", GNUNET_i2s (&address->peer), address);
995 GNUNET_break(0); 1019 GNUNET_break (0);
996 return GNUNET_OK; 1020 return GNUNET_OK;
997 } 1021 }
998 1022
999 addr_net = address->properties.scope; 1023 addr_net = address->properties.scope;
1000 for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++) 1024 for (addr_net_index = 0; addr_net_index < GNUNET_NT_COUNT; addr_net_index++)
1001 { 1025 {
1002 if (mlp->pv.quota_index[addr_net_index] == addr_net) 1026 if (mlp->pv.quota_index[addr_net_index] == addr_net)
1003 break; 1027 break;
1004 } 1028 }
1005 1029
1006 if (addr_net_index >= GNUNET_NT_COUNT) 1030 if (addr_net_index >= GNUNET_NT_COUNT)
1007 { 1031 {
1008 GNUNET_break(0); 1032 GNUNET_break (0);
1009 return GNUNET_OK; 1033 return GNUNET_OK;
1010 } 1034 }
1011 1035
1012 max_quota = 0; 1036 max_quota = 0;
1013 for (c = 0; c < GNUNET_NT_COUNT; c++) 1037 for (c = 0; c < GNUNET_NT_COUNT; c++)
1014 { 1038 {
1015 if (mlp->pv.quota_out[c] > max_quota) 1039 if (mlp->pv.quota_out[c] > max_quota)
1016 max_quota = mlp->pv.quota_out[c]; 1040 max_quota = mlp->pv.quota_out[c];
1017 if (mlp->pv.quota_in[c] > max_quota) 1041 if (mlp->pv.quota_in[c] > max_quota)
1018 max_quota = mlp->pv.quota_in[c]; 1042 max_quota = mlp->pv.quota_in[c];
1019 } 1043 }
1020 if (max_quota > mlp->pv.BIG_M) 1044 if (max_quota > mlp->pv.BIG_M)
1021 cur_bigm = (double)mlp->pv.BIG_M; 1045 cur_bigm = (double) mlp->pv.BIG_M;
1022 else 1046 else
1023 cur_bigm = max_quota; 1047 cur_bigm = max_quota;
1024 1048
1025 1049
1026 /* Get peer */ 1050 /* Get peer */
1027 peer = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, key); 1051 peer = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers, key);
1028 GNUNET_assert(NULL != peer); 1052 GNUNET_assert (NULL != peer);
1029 if (peer->processed == GNUNET_NO) 1053 if (peer->processed == GNUNET_NO)
1054 {
1055 /* Add peer dependent constraints */
1056 /* Add c2) One address active per peer */
1057 GNUNET_asprintf (&name, "c2_%s", GNUNET_i2s (&address->peer));
1058 peer->r_c2 = mlp_create_problem_create_constraint (p, name, GLP_FX, 1.0,
1059 1.0);
1060 GNUNET_free (name);
1061 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1030 { 1062 {
1031 /* Add peer dependent constraints */ 1063 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1032 /* Add c2) One address active per peer */ 1064 {
1033 GNUNET_asprintf(&name, "c2_%s", GNUNET_i2s(&address->peer)); 1065 /* Add c9) Relativity */
1034 peer->r_c2 = mlp_create_problem_create_constraint(p, name, GLP_FX, 1.0, 1.0); 1066 GNUNET_asprintf (&name, "c9_%s", GNUNET_i2s (&address->peer));
1035 GNUNET_free(name); 1067 peer->r_c9 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0,
1036 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1068 0.0);
1037 { 1069 GNUNET_free (name);
1038 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) 1070 /* c9) set coefficient */
1039 { 1071 mlp_create_problem_set_value (p, peer->r_c9, p->c_r, -peer->f,
1040 /* Add c9) Relativity */ 1072 __LINE__);
1041 GNUNET_asprintf(&name, "c9_%s", GNUNET_i2s(&address->peer)); 1073 }
1042 peer->r_c9 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0);
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 }
1047 }
1048 peer->processed = GNUNET_YES;
1049 } 1074 }
1075 peer->processed = GNUNET_YES;
1076 }
1050 1077
1051 /* Reset addresses' solver information */ 1078 /* Reset addresses' solver information */
1052 mlpi->c_b = 0; 1079 mlpi->c_b = 0;
@@ -1056,47 +1083,55 @@ mlp_create_problem_add_address_information(void *cls,
1056 mlpi->r_c3 = 0; 1083 mlpi->r_c3 = 0;
1057 1084
1058 /* Add bandwidth column */ 1085 /* Add bandwidth column */
1059 GNUNET_asprintf(&name, "b_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1086 GNUNET_asprintf (&name, "b_%s_%s_%p", GNUNET_i2s (&address->peer),
1087 address->plugin, address);
1060 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1088 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1061 { 1089 {
1062 mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 0.0); 1090 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0,
1063 } 1091 0.0, 0.0);
1092 }
1064 else 1093 else
1065 { 1094 {
1066 /* Maximize for bandwidth assignment in feasibility testing */ 1095 /* Maximize for bandwidth assignment in feasibility testing */
1067 mlpi->c_b = mlp_create_problem_create_column(p, name, GLP_CV, GLP_LO, 0.0, 0.0, 1.0); 1096 mlpi->c_b = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO, 0.0,
1068 } 1097 0.0, 1.0);
1069 GNUNET_free(name); 1098 }
1099 GNUNET_free (name);
1070 1100
1071 /* Add address active column */ 1101 /* Add address active column */
1072 GNUNET_asprintf(&name, "n_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1102 GNUNET_asprintf (&name, "n_%s_%s_%p", GNUNET_i2s (&address->peer),
1073 mlpi->c_n = mlp_create_problem_create_column(p, name, GLP_IV, GLP_DB, 0.0, 1.0, 0.0); 1103 address->plugin, address);
1074 GNUNET_free(name); 1104 mlpi->c_n = mlp_create_problem_create_column (p, name, GLP_IV, GLP_DB, 0.0,
1105 1.0, 0.0);
1106 GNUNET_free (name);
1075 1107
1076 /* Add address dependent constraints */ 1108 /* Add address dependent constraints */
1077 /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */ 1109 /* Add c1) bandwidth capping: b_t + (-M) * n_t <= 0 */
1078 GNUNET_asprintf(&name, "c1_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1110 GNUNET_asprintf (&name, "c1_%s_%s_%p", GNUNET_i2s (&address->peer),
1079 mlpi->r_c1 = mlp_create_problem_create_constraint(p, name, GLP_UP, 0.0, 0.0); 1111 address->plugin, address);
1080 GNUNET_free(name); 1112 mlpi->r_c1 = mlp_create_problem_create_constraint (p, name, GLP_UP, 0.0, 0.0);
1113 GNUNET_free (name);
1081 /* c1) set b = 1 coefficient */ 1114 /* c1) set b = 1 coefficient */
1082 mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_b, 1, __LINE__); 1115 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_b, 1, __LINE__);
1083 /* c1) set n = - min (M, quota) coefficient */ 1116 /* c1) set n = - min (M, quota) coefficient */
1084 cur_bigm = (double)mlp->pv.quota_out[addr_net_index]; 1117 cur_bigm = (double) mlp->pv.quota_out[addr_net_index];
1085 if (cur_bigm > mlp->pv.BIG_M) 1118 if (cur_bigm > mlp->pv.BIG_M)
1086 cur_bigm = (double)mlp->pv.BIG_M; 1119 cur_bigm = (double) mlp->pv.BIG_M;
1087 mlp_create_problem_set_value(p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__); 1120 mlp_create_problem_set_value (p, mlpi->r_c1, mlpi->c_n, -cur_bigm, __LINE__);
1088 1121
1089 /* Add constraint c 3) minimum bandwidth 1122 /* Add constraint c 3) minimum bandwidth
1090 * b_t + (-n_t * b_min) >= 0 1123 * b_t + (-n_t * b_min) >= 0
1091 * */ 1124 * */
1092 GNUNET_asprintf(&name, "c3_%s_%s_%p", GNUNET_i2s(&address->peer), address->plugin, address); 1125 GNUNET_asprintf (&name, "c3_%s_%s_%p", GNUNET_i2s (&address->peer),
1093 mlpi->r_c3 = mlp_create_problem_create_constraint(p, name, GLP_LO, 0.0, 0.0); 1126 address->plugin, address);
1094 GNUNET_free(name); 1127 mlpi->r_c3 = mlp_create_problem_create_constraint (p, name, GLP_LO, 0.0, 0.0);
1128 GNUNET_free (name);
1095 1129
1096 /* c3) set b = 1 coefficient */ 1130 /* c3) set b = 1 coefficient */
1097 mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_b, 1, __LINE__); 1131 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_b, 1, __LINE__);
1098 /* c3) set n = -b_min coefficient */ 1132 /* c3) set n = -b_min coefficient */
1099 mlp_create_problem_set_value(p, mlpi->r_c3, mlpi->c_n, -((double )mlp->pv.b_min), __LINE__); 1133 mlp_create_problem_set_value (p, mlpi->r_c3, mlpi->c_n,
1134 -((double ) mlp->pv.b_min), __LINE__);
1100 1135
1101 1136
1102 /* Set coefficient entries in invariant rows */ 1137 /* Set coefficient entries in invariant rows */
@@ -1104,41 +1139,42 @@ mlp_create_problem_add_address_information(void *cls,
1104 /* Feasbility */ 1139 /* Feasbility */
1105 1140
1106 /* c 4) minimum connections */ 1141 /* c 4) minimum connections */
1107 mlp_create_problem_set_value(p, p->r_c4, mlpi->c_n, 1, __LINE__); 1142 mlp_create_problem_set_value (p, p->r_c4, mlpi->c_n, 1, __LINE__);
1108 /* c 2) 1 address peer peer */ 1143 /* c 2) 1 address peer peer */
1109 mlp_create_problem_set_value(p, peer->r_c2, mlpi->c_n, 1, __LINE__); 1144 mlp_create_problem_set_value (p, peer->r_c2, mlpi->c_n, 1, __LINE__);
1110 /* c 10) obey network specific quotas 1145 /* c 10) obey network specific quotas
1111 * (1)*b_1 + ... + (1)*b_m <= quota_n 1146 * (1)*b_1 + ... + (1)*b_m <= quota_n
1112 */ 1147 */
1113 mlp_create_problem_set_value(p, p->r_quota[addr_net_index], mlpi->c_b, 1, __LINE__); 1148 mlp_create_problem_set_value (p, p->r_quota[addr_net_index], mlpi->c_b, 1,
1149 __LINE__);
1114 1150
1115 /* Optimality */ 1151 /* Optimality */
1116 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1152 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1117 { 1153 {
1118 /* c 6) maximize diversity */ 1154 /* c 6) maximize diversity */
1119 mlp_create_problem_set_value(p, p->r_c6, mlpi->c_n, 1, __LINE__); 1155 mlp_create_problem_set_value (p, p->r_c6, mlpi->c_n, 1, __LINE__);
1120 /* c 9) relativity */ 1156 /* c 9) relativity */
1121 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) 1157 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1122 mlp_create_problem_set_value(p, peer->r_c9, mlpi->c_b, 1, __LINE__); 1158 mlp_create_problem_set_value (p, peer->r_c9, mlpi->c_b, 1, __LINE__);
1123 /* c 8) utility */ 1159 /* c 8) utility */
1124 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1160 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1125 mlp_create_problem_set_value(p, p->r_c8, mlpi->c_b, 1, __LINE__); 1161 mlp_create_problem_set_value (p, p->r_c8, mlpi->c_b, 1, __LINE__);
1126 /* c 7) Optimize quality */ 1162 /* c 7) Optimize quality */
1127 /* For all quality metrics, set quality of this address */ 1163 /* For all quality metrics, set quality of this address */
1128 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1164 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1129 { 1165 {
1130 mlp_create_problem_set_value(p, 1166 mlp_create_problem_set_value (p,
1131 p->r_q[RQ_QUALITY_METRIC_DELAY], 1167 p->r_q[RQ_QUALITY_METRIC_DELAY],
1132 mlpi->c_b, 1168 mlpi->c_b,
1133 address->norm_delay.norm, 1169 address->norm_delay.norm,
1134 __LINE__); 1170 __LINE__);
1135 mlp_create_problem_set_value(p, 1171 mlp_create_problem_set_value (p,
1136 p->r_q[RQ_QUALITY_METRIC_DISTANCE], 1172 p->r_q[RQ_QUALITY_METRIC_DISTANCE],
1137 mlpi->c_b, 1173 mlpi->c_b,
1138 address->norm_distance.norm, 1174 address->norm_distance.norm,
1139 __LINE__); 1175 __LINE__);
1140 } 1176 }
1141 } 1177 }
1142 1178
1143 return GNUNET_OK; 1179 return GNUNET_OK;
1144} 1180}
@@ -1148,7 +1184,8 @@ mlp_create_problem_add_address_information(void *cls,
1148 * Create the invariant columns c4, c6, c10, c8, c7 1184 * Create the invariant columns c4, c6, c10, c8, c7
1149 */ 1185 */
1150static void 1186static void
1151mlp_create_problem_add_invariant_rows(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) 1187mlp_create_problem_add_invariant_rows (struct GAS_MLP_Handle *mlp, struct
1188 MLP_Problem *p)
1152{ 1189{
1153 int c; 1190 int c;
1154 1191
@@ -1156,55 +1193,63 @@ mlp_create_problem_add_invariant_rows(struct GAS_MLP_Handle *mlp, struct MLP_Pro
1156 1193
1157 /* Row for c4) minimum connection */ 1194 /* Row for c4) minimum connection */
1158 /* Number of minimum connections is min(|Peers|, n_min) */ 1195 /* Number of minimum connections is min(|Peers|, n_min) */
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); 1196 p->r_c4 = mlp_create_problem_create_constraint (p, "c4", GLP_LO,
1197 (mlp->pv.n_min >
1198 p->num_peers) ?
1199 p->num_peers : mlp->pv.n_min,
1200 0.0);
1160 1201
1161 /* Rows for c 10) Enforce network quotas */ 1202 /* Rows for c 10) Enforce network quotas */
1162 for (c = 0; c < GNUNET_NT_COUNT; c++) 1203 for (c = 0; c < GNUNET_NT_COUNT; c++)
1163 { 1204 {
1164 char * text; 1205 char *text;
1165 GNUNET_asprintf(&text, "c10_quota_ats_%s", 1206 GNUNET_asprintf (&text, "c10_quota_ats_%s",
1166 GNUNET_NT_to_string(mlp->pv.quota_index[c])); 1207 GNUNET_NT_to_string (mlp->pv.quota_index[c]));
1167 p->r_quota[c] = mlp_create_problem_create_constraint(p, text, GLP_DB, 0.0, mlp->pv.quota_out[c]); 1208 p->r_quota[c] = mlp_create_problem_create_constraint (p, text, GLP_DB, 0.0,
1168 GNUNET_free(text); 1209 mlp->pv.quota_out[c]);
1169 } 1210 GNUNET_free (text);
1211 }
1170 1212
1171 /* Optimality */ 1213 /* Optimality */
1172 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1214 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1173 { 1215 {
1174 char *name; 1216 char *name;
1175 /* Add row for c6) Maximize for diversity */ 1217 /* Add row for c6) Maximize for diversity */
1176 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) 1218 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity)
1177 { 1219 {
1178 p->r_c6 = mlp_create_problem_create_constraint(p, "c6", GLP_FX, 0.0, 0.0); 1220 p->r_c6 = mlp_create_problem_create_constraint (p, "c6", GLP_FX, 0.0,
1179 /* Set c6 ) Setting -D */ 1221 0.0);
1180 mlp_create_problem_set_value(p, p->r_c6, p->c_d, -1, __LINE__); 1222 /* Set c6 ) Setting -D */
1181 } 1223 mlp_create_problem_set_value (p, p->r_c6, p->c_d, -1, __LINE__);
1182 1224 }
1183 /* Adding rows for c 8) Maximize utility */ 1225
1184 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1226 /* Adding rows for c 8) Maximize utility */
1185 { 1227 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1186 p->r_c8 = mlp_create_problem_create_constraint(p, "c8", GLP_FX, 0.0, 0.0); 1228 {
1187 /* -u */ 1229 p->r_c8 = mlp_create_problem_create_constraint (p, "c8", GLP_FX, 0.0,
1188 mlp_create_problem_set_value(p, p->r_c8, p->c_u, -1, __LINE__); 1230 0.0);
1189 } 1231 /* -u */
1190 1232 mlp_create_problem_set_value (p, p->r_c8, p->c_u, -1, __LINE__);
1191 /* For all quality metrics: 1233 }
1192 * c 7) Maximize quality, austerity */ 1234
1193 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1235 /* For all quality metrics:
1194 { 1236 * c 7) Maximize quality, austerity */
1195 for (c = 0; c < mlp->pv.m_q; c++) 1237 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1196 { 1238 {
1197 GNUNET_asprintf(&name, 1239 for (c = 0; c < mlp->pv.m_q; c++)
1198 "c7_q%i_%s", c, 1240 {
1199 print_quality_type(c)); 1241 GNUNET_asprintf (&name,
1200 p->r_q[c] = mlp_create_problem_create_constraint(p, name, GLP_FX, 0.0, 0.0); 1242 "c7_q%i_%s", c,
1201 GNUNET_free(name); 1243 print_quality_type (c));
1202 mlp_create_problem_set_value(p, 1244 p->r_q[c] = mlp_create_problem_create_constraint (p, name, GLP_FX, 0.0,
1203 p->r_q[c], 1245 0.0);
1204 p->c_q[c], -1, __LINE__); 1246 GNUNET_free (name);
1205 } 1247 mlp_create_problem_set_value (p,
1206 } 1248 p->r_q[c],
1207 } 1249 p->c_q[c], -1, __LINE__);
1250 }
1251 }
1252 }
1208} 1253}
1209 1254
1210 1255
@@ -1212,36 +1257,42 @@ mlp_create_problem_add_invariant_rows(struct GAS_MLP_Handle *mlp, struct MLP_Pro
1212 * Create the invariant columns d, u, r, q0 ... qm 1257 * Create the invariant columns d, u, r, q0 ... qm
1213 */ 1258 */
1214static void 1259static void
1215mlp_create_problem_add_invariant_columns(struct GAS_MLP_Handle *mlp, struct MLP_Problem *p) 1260mlp_create_problem_add_invariant_columns (struct GAS_MLP_Handle *mlp, struct
1261 MLP_Problem *p)
1216{ 1262{
1217 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 1263 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
1218 { 1264 {
1219 char *name; 1265 char *name;
1220 int c; 1266 int c;
1221 1267
1222 /* Diversity d column */ 1268 /* Diversity d column */
1223 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity) 1269 if (GNUNET_YES == mlp->opt_dbg_optimize_diversity)
1224 p->c_d = mlp_create_problem_create_column(p, "d", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_D); 1270 p->c_d = mlp_create_problem_create_column (p, "d", GLP_CV, GLP_LO, 0.0,
1225 1271 0.0, mlp->pv.co_D);
1226 /* Utilization u column */ 1272
1227 if (GNUNET_YES == mlp->opt_dbg_optimize_utility) 1273 /* Utilization u column */
1228 p->c_u = mlp_create_problem_create_column(p, "u", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_U); 1274 if (GNUNET_YES == mlp->opt_dbg_optimize_utility)
1229 1275 p->c_u = mlp_create_problem_create_column (p, "u", GLP_CV, GLP_LO, 0.0,
1230 /* Relativity r column */ 1276 0.0, mlp->pv.co_U);
1231 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity) 1277
1232 p->c_r = mlp_create_problem_create_column(p, "r", GLP_CV, GLP_LO, 0.0, 0.0, mlp->pv.co_R); 1278 /* Relativity r column */
1233 1279 if (GNUNET_YES == mlp->opt_dbg_optimize_relativity)
1234 /* Quality metric columns */ 1280 p->c_r = mlp_create_problem_create_column (p, "r", GLP_CV, GLP_LO, 0.0,
1235 if (GNUNET_YES == mlp->opt_dbg_optimize_quality) 1281 0.0, mlp->pv.co_R);
1236 { 1282
1237 for (c = 0; c < mlp->pv.m_q; c++) 1283 /* Quality metric columns */
1238 { 1284 if (GNUNET_YES == mlp->opt_dbg_optimize_quality)
1239 GNUNET_asprintf(&name, "q_%u", c); 1285 {
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]); 1286 for (c = 0; c < mlp->pv.m_q; c++)
1241 GNUNET_free(name); 1287 {
1242 } 1288 GNUNET_asprintf (&name, "q_%u", c);
1243 } 1289 p->c_q[c] = mlp_create_problem_create_column (p, name, GLP_CV, GLP_LO,
1244 } 1290 0.0, 0.0,
1291 mlp->pv.co_Q[c]);
1292 GNUNET_free (name);
1293 }
1294 }
1295 }
1245} 1296}
1246 1297
1247 1298
@@ -1252,73 +1303,76 @@ mlp_create_problem_add_invariant_columns(struct GAS_MLP_Handle *mlp, struct MLP_
1252 * @return #GNUNET_OK or #GNUNET_SYSERR 1303 * @return #GNUNET_OK or #GNUNET_SYSERR
1253 */ 1304 */
1254static int 1305static int
1255mlp_create_problem(struct GAS_MLP_Handle *mlp) 1306mlp_create_problem (struct GAS_MLP_Handle *mlp)
1256{ 1307{
1257 struct MLP_Problem *p = &mlp->p; 1308 struct MLP_Problem *p = &mlp->p;
1258 int res = GNUNET_OK; 1309 int res = GNUNET_OK;
1259 1310
1260 GNUNET_assert(p->prob == NULL); 1311 GNUNET_assert (p->prob == NULL);
1261 GNUNET_assert(p->ia == NULL); 1312 GNUNET_assert (p->ia == NULL);
1262 GNUNET_assert(p->ja == NULL); 1313 GNUNET_assert (p->ja == NULL);
1263 GNUNET_assert(p->ar == NULL); 1314 GNUNET_assert (p->ar == NULL);
1264 /* Reset MLP problem struct */ 1315 /* Reset MLP problem struct */
1265 1316
1266 /* create the glpk problem */ 1317 /* create the glpk problem */
1267 p->prob = glp_create_prob(); 1318 p->prob = glp_create_prob ();
1268 GNUNET_assert(NULL != p->prob); 1319 GNUNET_assert (NULL != p->prob);
1269 p->num_peers = mlp_create_problem_count_peers(mlp->requested_peers, mlp->env->addresses); 1320 p->num_peers = mlp_create_problem_count_peers (mlp->requested_peers,
1270 p->num_addresses = mlp_create_problem_count_addresses(mlp->requested_peers, 1321 mlp->env->addresses);
1271 mlp->env->addresses); 1322 p->num_addresses = mlp_create_problem_count_addresses (mlp->requested_peers,
1323 mlp->env->addresses);
1272 1324
1273 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */ 1325 /* Create problem matrix: 10 * #addresses + #q * #addresses + #q, + #peer + 2 + 1 */
1274 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses + 1326 p->num_elements = (10 * p->num_addresses + mlp->pv.m_q * p->num_addresses
1275 mlp->pv.m_q + p->num_peers + 2 + 1); 1327 + mlp->pv.m_q + p->num_peers + 2 + 1);
1276 LOG(GNUNET_ERROR_TYPE_DEBUG, 1328 LOG (GNUNET_ERROR_TYPE_DEBUG,
1277 "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n", 1329 "Rebuilding problem for %u peer(s) and %u addresse(s) and %u quality metrics == %u elements\n",
1278 p->num_peers, 1330 p->num_peers,
1279 p->num_addresses, 1331 p->num_addresses,
1280 mlp->pv.m_q, 1332 mlp->pv.m_q,
1281 p->num_elements); 1333 p->num_elements);
1282 1334
1283 /* Set a problem name */ 1335 /* Set a problem name */
1284 glp_set_prob_name(p->prob, "GNUnet ATS bandwidth distribution"); 1336 glp_set_prob_name (p->prob, "GNUnet ATS bandwidth distribution");
1285 /* Set optimization direction to maximize */ 1337 /* Set optimization direction to maximize */
1286 glp_set_obj_dir(p->prob, GLP_MAX); 1338 glp_set_obj_dir (p->prob, GLP_MAX);
1287 1339
1288 /* Create problem matrix */ 1340 /* Create problem matrix */
1289 /* last +1 caused by glpk index starting with one: [1..elements]*/ 1341 /* last +1 caused by glpk index starting with one: [1..elements]*/
1290 p->ci = 1; 1342 p->ci = 1;
1291 /* row index */ 1343 /* row index */
1292 p->ia = GNUNET_malloc(p->num_elements * sizeof(int)); 1344 p->ia = GNUNET_malloc (p->num_elements * sizeof(int));
1293 /* column index */ 1345 /* column index */
1294 p->ja = GNUNET_malloc(p->num_elements * sizeof(int)); 1346 p->ja = GNUNET_malloc (p->num_elements * sizeof(int));
1295 /* coefficient */ 1347 /* coefficient */
1296 p->ar = GNUNET_malloc(p->num_elements * sizeof(double)); 1348 p->ar = GNUNET_malloc (p->num_elements * sizeof(double));
1297 1349
1298 if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar)) 1350 if ((NULL == p->ia) || (NULL == p->ja) || (NULL == p->ar))
1299 { 1351 {
1300 LOG(GNUNET_ERROR_TYPE_ERROR, _("Problem size too large, cannot allocate memory!\n")); 1352 LOG (GNUNET_ERROR_TYPE_ERROR, _ (
1301 return GNUNET_SYSERR; 1353 "Problem size too large, cannot allocate memory!\n"));
1302 } 1354 return GNUNET_SYSERR;
1355 }
1303 1356
1304 /* Adding invariant columns */ 1357 /* Adding invariant columns */
1305 mlp_create_problem_add_invariant_columns(mlp, p); 1358 mlp_create_problem_add_invariant_columns (mlp, p);
1306 1359
1307 /* Adding address independent constraint rows */ 1360 /* Adding address independent constraint rows */
1308 mlp_create_problem_add_invariant_rows(mlp, p); 1361 mlp_create_problem_add_invariant_rows (mlp, p);
1309 1362
1310 /* Adding address dependent columns constraint rows */ 1363 /* Adding address dependent columns constraint rows */
1311 GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, 1364 GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses,
1312 &mlp_create_problem_add_address_information, 1365 &
1313 mlp); 1366 mlp_create_problem_add_address_information,
1367 mlp);
1314 1368
1315 /* Load the matrix */ 1369 /* Load the matrix */
1316 LOG(GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n"); 1370 LOG (GNUNET_ERROR_TYPE_DEBUG, "Loading matrix\n");
1317 glp_load_matrix(p->prob, (p->ci) - 1, p->ia, p->ja, p->ar); 1371 glp_load_matrix (p->prob, (p->ci) - 1, p->ia, p->ja, p->ar);
1318 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) 1372 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem)
1319 { 1373 {
1320 glp_scale_prob(p->prob, GLP_SF_AUTO); 1374 glp_scale_prob (p->prob, GLP_SF_AUTO);
1321 } 1375 }
1322 1376
1323 return res; 1377 return res;
1324} 1378}
@@ -1331,37 +1385,37 @@ mlp_create_problem(struct GAS_MLP_Handle *mlp)
1331 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure 1385 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
1332 */ 1386 */
1333static int 1387static int
1334mlp_solve_lp_problem(struct GAS_MLP_Handle *mlp) 1388mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp)
1335{ 1389{
1336 int res = 0; 1390 int res = 0;
1337 int res_status = 0; 1391 int res_status = 0;
1338 1392
1339 res = glp_simplex(mlp->p.prob, &mlp->control_param_lp); 1393 res = glp_simplex (mlp->p.prob, &mlp->control_param_lp);
1340 if (0 == res) 1394 if (0 == res)
1341 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n", 1395 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem: %s\n",
1342 mlp_solve_to_string(res)); 1396 mlp_solve_to_string (res));
1343 else 1397 else
1344 LOG(GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n", 1398 LOG (GNUNET_ERROR_TYPE_DEBUG, "Solving LP problem failed: %s\n",
1345 mlp_solve_to_string(res)); 1399 mlp_solve_to_string (res));
1346 1400
1347 /* Analyze problem status */ 1401 /* Analyze problem status */
1348 res_status = glp_get_status(mlp->p.prob); 1402 res_status = glp_get_status (mlp->p.prob);
1349 switch (res_status) 1403 switch (res_status)
1350 { 1404 {
1351 case GLP_OPT: /* solution is optimal */ 1405 case GLP_OPT: /* solution is optimal */
1352 LOG(GNUNET_ERROR_TYPE_INFO, 1406 LOG (GNUNET_ERROR_TYPE_INFO,
1353 "Solving LP problem: %s, %s\n", 1407 "Solving LP problem: %s, %s\n",
1354 mlp_solve_to_string(res), 1408 mlp_solve_to_string (res),
1355 mlp_status_to_string(res_status)); 1409 mlp_status_to_string (res_status));
1356 return GNUNET_OK; 1410 return GNUNET_OK;
1357 1411
1358 default: 1412 default:
1359 LOG(GNUNET_ERROR_TYPE_ERROR, 1413 LOG (GNUNET_ERROR_TYPE_ERROR,
1360 "Solving LP problem failed: %s %s\n", 1414 "Solving LP problem failed: %s %s\n",
1361 mlp_solve_to_string(res), 1415 mlp_solve_to_string (res),
1362 mlp_status_to_string(res_status)); 1416 mlp_status_to_string (res_status));
1363 return GNUNET_SYSERR; 1417 return GNUNET_SYSERR;
1364 } 1418 }
1365} 1419}
1366 1420
1367 1421
@@ -1374,9 +1428,9 @@ mlp_solve_lp_problem(struct GAS_MLP_Handle *mlp)
1374 * @return #GNUNET_OK to continue 1428 * @return #GNUNET_OK to continue
1375 */ 1429 */
1376static int 1430static int
1377mlp_propagate_results(void *cls, 1431mlp_propagate_results (void *cls,
1378 const struct GNUNET_PeerIdentity *key, 1432 const struct GNUNET_PeerIdentity *key,
1379 void *value) 1433 void *value)
1380{ 1434{
1381 struct GAS_MLP_Handle *mlp = cls; 1435 struct GAS_MLP_Handle *mlp = cls;
1382 struct ATS_Address *address; 1436 struct ATS_Address *address;
@@ -1386,28 +1440,30 @@ mlp_propagate_results(void *cls,
1386 double mlp_use = MLP_NaN; 1440 double mlp_use = MLP_NaN;
1387 1441
1388 /* Check if we have to add this peer due to a pending request */ 1442 /* Check if we have to add this peer due to a pending request */
1389 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains(mlp->requested_peers, 1443 if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mlp->requested_peers,
1390 key)) 1444 key))
1391 { 1445 {
1392 return GNUNET_OK; 1446 return GNUNET_OK;
1393 } 1447 }
1394 address = value; 1448 address = value;
1395 GNUNET_assert(address->solver_information != NULL); 1449 GNUNET_assert (address->solver_information != NULL);
1396 mlpi = address->solver_information; 1450 mlpi = address->solver_information;
1397 1451
1398 mlp_bw_in = glp_mip_col_val(mlp->p.prob, mlpi->c_b);/* FIXME */ 1452 mlp_bw_in = glp_mip_col_val (mlp->p.prob, mlpi->c_b);/* FIXME */
1399 if (mlp_bw_in > (double)UINT32_MAX) 1453 if (mlp_bw_in > (double) UINT32_MAX)
1400 { 1454 {
1401 LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n"); 1455 LOG (GNUNET_ERROR_TYPE_DEBUG,
1402 mlp_bw_in = (double)UINT32_MAX; 1456 "Overflow in assigned bandwidth, reducing ...\n");
1403 } 1457 mlp_bw_in = (double) UINT32_MAX;
1404 mlp_bw_out = glp_mip_col_val(mlp->p.prob, mlpi->c_b); 1458 }
1405 if (mlp_bw_out > (double)UINT32_MAX) 1459 mlp_bw_out = glp_mip_col_val (mlp->p.prob, mlpi->c_b);
1406 { 1460 if (mlp_bw_out > (double) UINT32_MAX)
1407 LOG(GNUNET_ERROR_TYPE_DEBUG, "Overflow in assigned bandwidth, reducing ...\n"); 1461 {
1408 mlp_bw_out = (double)UINT32_MAX; 1462 LOG (GNUNET_ERROR_TYPE_DEBUG,
1409 } 1463 "Overflow in assigned bandwidth, reducing ...\n");
1410 mlp_use = glp_mip_col_val(mlp->p.prob, mlpi->c_n); 1464 mlp_bw_out = (double) UINT32_MAX;
1465 }
1466 mlp_use = glp_mip_col_val (mlp->p.prob, mlpi->c_n);
1411 1467
1412 /* 1468 /*
1413 * Debug: solution 1469 * Debug: solution
@@ -1417,155 +1473,161 @@ mlp_propagate_results(void *cls,
1417 */ 1473 */
1418 1474
1419 if (GLP_YES == mlp_use) 1475 if (GLP_YES == mlp_use)
1420 { 1476 {
1421 /* This address was selected by the solver to be used */ 1477 /* This address was selected by the solver to be used */
1422 mlpi->n = GNUNET_YES; 1478 mlpi->n = GNUNET_YES;
1423 if (GNUNET_NO == address->active) 1479 if (GNUNET_NO == address->active)
1424 { 1480 {
1425 /* Address was not used before, enabling address */ 1481 /* Address was not used before, enabling address */
1426 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", 1482 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n",
1427 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); 1483 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1428 address->active = GNUNET_YES; 1484 address->active = GNUNET_YES;
1429 address->assigned_bw_in = mlp_bw_in; 1485 address->assigned_bw_in = mlp_bw_in;
1430 mlpi->b_in = mlp_bw_in; 1486 mlpi->b_in = mlp_bw_in;
1431 address->assigned_bw_out = mlp_bw_out; 1487 address->assigned_bw_out = mlp_bw_out;
1432 mlpi->b_out = mlp_bw_out; 1488 mlpi->b_out = mlp_bw_out;
1433 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp(&address->peer, mlp->exclude_peer))) 1489 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer,
1434 mlp->env->bandwidth_changed_cb(mlp->env->cls, address); 1490 mlp->exclude_peer)))
1435 return GNUNET_OK; 1491 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
1436 } 1492 return GNUNET_OK;
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);
1456 } 1493 }
1494 else if (GNUNET_YES == address->active)
1495 {
1496 /* Address was used before, check for bandwidth change */
1497 if ((mlp_bw_out != address->assigned_bw_out) ||
1498 (mlp_bw_in != address->assigned_bw_in))
1499 {
1500 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n",
1501 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1502 address->assigned_bw_in = mlp_bw_in;
1503 mlpi->b_in = mlp_bw_in;
1504 address->assigned_bw_out = mlp_bw_out;
1505 mlpi->b_out = mlp_bw_out;
1506 if ((NULL == mlp->exclude_peer) || (0 != GNUNET_memcmp (&address->peer,
1507 mlp->
1508 exclude_peer)))
1509 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
1510 return GNUNET_OK;
1511 }
1512 }
1513 else
1514 GNUNET_break (0);
1515 }
1457 else if (GLP_NO == mlp_use) 1516 else if (GLP_NO == mlp_use)
1458 { 1517 {
1459 /* This address was selected by the solver to be not used */ 1518 /* This address was selected by the solver to be not used */
1460 mlpi->n = GNUNET_NO; 1519 mlpi->n = GNUNET_NO;
1461 if (GNUNET_NO == address->active) 1520 if (GNUNET_NO == address->active)
1462 { 1521 {
1463 /* Address was not used before, nothing to do */ 1522 /* Address was not used before, nothing to do */
1464 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", 1523 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n",
1465 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); 1524 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1466 return GNUNET_OK; 1525 return GNUNET_OK;
1467 } 1526 }
1468 else if (GNUNET_YES == address->active) 1527 else if (GNUNET_YES == address->active)
1469 { 1528 {
1470 /* Address was used before, disabling address */ 1529 /* Address was used before, disabling address */
1471 LOG(GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", 1530 LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n",
1472 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out); 1531 (1 == mlp_use) ? "[x]" : "[ ]", mlp_bw_out);
1473 address->active = GNUNET_NO; 1532 address->active = GNUNET_NO;
1474 /* Set bandwidth to 0 */ 1533 /* Set bandwidth to 0 */
1475 address->assigned_bw_in = 0; 1534 address->assigned_bw_in = 0;
1476 mlpi->b_in = 0; 1535 mlpi->b_in = 0;
1477 address->assigned_bw_out = 0; 1536 address->assigned_bw_out = 0;
1478 mlpi->b_out = 0; 1537 mlpi->b_out = 0;
1479 return GNUNET_OK; 1538 return GNUNET_OK;
1480 }
1481 else
1482 GNUNET_break(0);
1483 } 1539 }
1540 else
1541 GNUNET_break (0);
1542 }
1484 else 1543 else
1485 GNUNET_break(0); 1544 GNUNET_break (0);
1486 1545
1487 return GNUNET_OK; 1546 return GNUNET_OK;
1488} 1547}
1489 1548
1490 1549
1491static void 1550static void
1492notify(struct GAS_MLP_Handle *mlp, 1551notify (struct GAS_MLP_Handle *mlp,
1493 enum GAS_Solver_Operation op, 1552 enum GAS_Solver_Operation op,
1494 enum GAS_Solver_Status stat, 1553 enum GAS_Solver_Status stat,
1495 enum GAS_Solver_Additional_Information add) 1554 enum GAS_Solver_Additional_Information add)
1496{ 1555{
1497 mlp->env->info_cb(mlp->env->cls, 1556 mlp->env->info_cb (mlp->env->cls,
1498 op, 1557 op,
1499 stat, 1558 stat,
1500 add); 1559 add);
1501} 1560}
1502 1561
1503 1562
1504static void 1563static void
1505mlp_branch_and_cut_cb(glp_tree *tree, void *info) 1564mlp_branch_and_cut_cb (glp_tree *tree, void *info)
1506{ 1565{
1507 struct GAS_MLP_Handle *mlp = info; 1566 struct GAS_MLP_Handle *mlp = info;
1508 double mlp_obj = 0; 1567 double mlp_obj = 0;
1509 1568
1510 switch (glp_ios_reason(tree)) 1569 switch (glp_ios_reason (tree))
1511 { 1570 {
1512 case GLP_ISELECT: 1571 case GLP_ISELECT:
1513 /* Do nothing here */ 1572 /* Do nothing here */
1514 break; 1573 break;
1515 1574
1516 case GLP_IPREPRO: 1575 case GLP_IPREPRO:
1517 /* Do nothing here */ 1576 /* Do nothing here */
1518 break; 1577 break;
1519 1578
1520 case GLP_IROWGEN: 1579 case GLP_IROWGEN:
1521 /* Do nothing here */ 1580 /* Do nothing here */
1522 break; 1581 break;
1523 1582
1524 case GLP_IHEUR: 1583 case GLP_IHEUR:
1525 /* Do nothing here */ 1584 /* Do nothing here */
1526 break; 1585 break;
1527 1586
1528 case GLP_ICUTGEN: 1587 case GLP_ICUTGEN:
1529 /* Do nothing here */ 1588 /* Do nothing here */
1530 break; 1589 break;
1531 1590
1532 case GLP_IBRANCH: 1591 case GLP_IBRANCH:
1533 /* Do nothing here */ 1592 /* Do nothing here */
1534 break; 1593 break;
1535 1594
1536 case GLP_IBINGO: 1595 case GLP_IBINGO:
1537 /* A better solution was found */ 1596 /* A better solution was found */
1538 mlp->ps.mlp_gap = glp_ios_mip_gap(tree); 1597 mlp->ps.mlp_gap = glp_ios_mip_gap (tree);
1539 mlp_obj = glp_mip_obj_val(mlp->p.prob); 1598 mlp_obj = glp_mip_obj_val (mlp->p.prob);
1540 mlp->ps.lp_mlp_gap = (abs(mlp_obj - mlp->ps.lp_objective_value)) / (abs(mlp_obj) + DBL_EPSILON); 1599 mlp->ps.lp_mlp_gap = (abs (mlp_obj - mlp->ps.lp_objective_value)) / (abs (
1541 1600 mlp_obj)
1542 LOG(GNUNET_ERROR_TYPE_INFO, 1601 +
1543 "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n", 1602 DBL_EPSILON);
1544 mlp->ps.mlp_gap, mlp->pv.mip_gap,
1545 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1546
1547 if (mlp->ps.mlp_gap <= mlp->pv.mip_gap)
1548 {
1549 LOG(GNUNET_ERROR_TYPE_INFO,
1550 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1551 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1552 glp_ios_terminate(tree);
1553 }
1554
1555 if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap)
1556 {
1557 LOG(GNUNET_ERROR_TYPE_INFO,
1558 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1559 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1560 glp_ios_terminate(tree);
1561 }
1562 1603
1563 break; 1604 LOG (GNUNET_ERROR_TYPE_INFO,
1605 "Found better integer solution, current gaps: %.3f <= %.3f, %.3f <= %.3f\n",
1606 mlp->ps.mlp_gap, mlp->pv.mip_gap,
1607 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1564 1608
1565 default: 1609 if (mlp->ps.mlp_gap <= mlp->pv.mip_gap)
1566 break; 1610 {
1611 LOG (GNUNET_ERROR_TYPE_INFO,
1612 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1613 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1614 glp_ios_terminate (tree);
1567 } 1615 }
1568 //GNUNET_break (0); 1616
1617 if (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap)
1618 {
1619 LOG (GNUNET_ERROR_TYPE_INFO,
1620 "Current LP/MLP gap of %.3f smaller than tolerated gap of %.3f, terminating search\n",
1621 mlp->ps.lp_mlp_gap, mlp->pv.lp_mip_gap);
1622 glp_ios_terminate (tree);
1623 }
1624
1625 break;
1626
1627 default:
1628 break;
1629 }
1630 // GNUNET_break (0);
1569} 1631}
1570 1632
1571 1633
@@ -1576,7 +1638,7 @@ mlp_branch_and_cut_cb(glp_tree *tree, void *info)
1576 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure 1638 * @return #GNUNET_OK if could be solved, #GNUNET_SYSERR on failure
1577 */ 1639 */
1578static int 1640static int
1579GAS_mlp_solve_problem(void *solver) 1641GAS_mlp_solve_problem (void *solver)
1580{ 1642{
1581 struct GAS_MLP_Handle *mlp = solver; 1643 struct GAS_MLP_Handle *mlp = solver;
1582 char *filename; 1644 char *filename;
@@ -1591,63 +1653,64 @@ GAS_mlp_solve_problem(void *solver)
1591 struct GNUNET_TIME_Relative dur_lp; 1653 struct GNUNET_TIME_Relative dur_lp;
1592 struct GNUNET_TIME_Relative dur_mlp; 1654 struct GNUNET_TIME_Relative dur_mlp;
1593 1655
1594 GNUNET_assert(NULL != solver); 1656 GNUNET_assert (NULL != solver);
1595 dur_lp = GNUNET_TIME_UNIT_ZERO; 1657 dur_lp = GNUNET_TIME_UNIT_ZERO;
1596 1658
1597 if (GNUNET_YES == mlp->stat_bulk_lock) 1659 if (GNUNET_YES == mlp->stat_bulk_lock)
1598 { 1660 {
1599 mlp->stat_bulk_requests++; 1661 mlp->stat_bulk_requests++;
1600 return GNUNET_NO; 1662 return GNUNET_NO;
1601 } 1663 }
1602 notify(mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS, 1664 notify (mlp, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS,
1603 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1665 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1604 start_total = GNUNET_TIME_absolute_get(); 1666 GAS_INFO_UPDATED);
1605 1667 start_total = GNUNET_TIME_absolute_get ();
1606 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->requested_peers)) 1668
1607 { 1669 if (0 == GNUNET_CONTAINER_multipeermap_size (mlp->requested_peers))
1608 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); 1670 {
1609 return GNUNET_OK; /* No pending requests */ 1671 notify (mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1610 } 1672 return GNUNET_OK; /* No pending requests */
1611 if (0 == GNUNET_CONTAINER_multipeermap_size(mlp->env->addresses)) 1673 }
1612 { 1674 if (0 == GNUNET_CONTAINER_multipeermap_size (mlp->env->addresses))
1613 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); 1675 {
1614 return GNUNET_OK; /* No addresses available */ 1676 notify (mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1615 } 1677 return GNUNET_OK; /* No addresses available */
1678 }
1616 1679
1617 if ((GNUNET_NO == mlp->stat_mlp_prob_changed) 1680 if ((GNUNET_NO == mlp->stat_mlp_prob_changed)
1618 && (GNUNET_NO == mlp->stat_mlp_prob_updated)) 1681 && (GNUNET_NO == mlp->stat_mlp_prob_updated))
1682 {
1683 LOG (GNUNET_ERROR_TYPE_DEBUG, "No changes to problem\n");
1684 notify (mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE);
1685 return GNUNET_OK;
1686 }
1687 if (GNUNET_YES == mlp->stat_mlp_prob_changed)
1688 {
1689 LOG (GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n");
1690 notify (mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1691 mlp_delete_problem (mlp);
1692 if (GNUNET_SYSERR == mlp_create_problem (mlp))
1619 { 1693 {
1620 LOG(GNUNET_ERROR_TYPE_DEBUG, "No changes to problem\n"); 1694 notify (mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
1621 notify(mlp, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS, GAS_INFO_NONE); 1695 return GNUNET_SYSERR;
1622 return GNUNET_OK;
1623 } 1696 }
1624 if (GNUNET_YES == mlp->stat_mlp_prob_changed) 1697 notify (mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1698 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver)
1625 { 1699 {
1626 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem size changed, rebuilding\n"); 1700 mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */
1627 notify(mlp, GAS_OP_SOLVE_SETUP_START, GAS_STAT_SUCCESS, GAS_INFO_FULL); 1701 mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */
1628 mlp_delete_problem(mlp);
1629 if (GNUNET_SYSERR == mlp_create_problem(mlp))
1630 {
1631 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_FAIL, GAS_INFO_FULL);
1632 return GNUNET_SYSERR;
1633 }
1634 notify(mlp, GAS_OP_SOLVE_SETUP_STOP, GAS_STAT_SUCCESS, GAS_INFO_FULL);
1635 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver)
1636 {
1637 mlp->control_param_lp.presolve = GLP_YES; /* LP presolver, we need lp solution */
1638 mlp->control_param_mlp.presolve = GNUNET_NO; /* No presolver, we have LP solution */
1639 }
1640 else
1641 {
1642 mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */
1643 mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */
1644 dur_lp = GNUNET_TIME_UNIT_ZERO;
1645 }
1646 } 1702 }
1647 else 1703 else
1648 { 1704 {
1649 LOG(GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n"); 1705 mlp->control_param_lp.presolve = GNUNET_NO; /* LP presolver, we need lp solution */
1706 mlp->control_param_mlp.presolve = GLP_YES; /* No presolver, we have LP solution */
1707 dur_lp = GNUNET_TIME_UNIT_ZERO;
1650 } 1708 }
1709 }
1710 else
1711 {
1712 LOG (GNUNET_ERROR_TYPE_DEBUG, "Problem was updated, resolving\n");
1713 }
1651 1714
1652 /* Reset solution info */ 1715 /* Reset solution info */
1653 mlp->ps.lp_objective_value = 0.0; 1716 mlp->ps.lp_objective_value = 0.0;
@@ -1655,224 +1718,238 @@ GAS_mlp_solve_problem(void *solver)
1655 mlp->ps.mlp_objective_value = 0.0; 1718 mlp->ps.mlp_objective_value = 0.0;
1656 mlp->ps.lp_mlp_gap = 0.0; 1719 mlp->ps.lp_mlp_gap = 0.0;
1657 1720
1658 dur_setup = GNUNET_TIME_absolute_get_duration(start_total); 1721 dur_setup = GNUNET_TIME_absolute_get_duration (start_total);
1659 1722
1660 /* Run LP solver */ 1723 /* Run LP solver */
1661 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver) 1724 if (GNUNET_NO == mlp->opt_dbg_intopt_presolver)
1662 { 1725 {
1663 notify(mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS, 1726 notify (mlp, GAS_OP_SOLVE_MLP_LP_START, GAS_STAT_SUCCESS,
1664 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1727 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1665 LOG(GNUNET_ERROR_TYPE_DEBUG, 1728 GAS_INFO_UPDATED);
1666 "Running LP solver %s\n", 1729 LOG (GNUNET_ERROR_TYPE_DEBUG,
1667 (GLP_YES == mlp->control_param_lp.presolve) ? "with presolver" : "without presolver"); 1730 "Running LP solver %s\n",
1668 start_cur_op = GNUNET_TIME_absolute_get(); 1731 (GLP_YES == mlp->control_param_lp.presolve) ? "with presolver" :
1669 1732 "without presolver");
1670 /* Solve LP */ 1733 start_cur_op = GNUNET_TIME_absolute_get ();
1671 /* Only for debugging: 1734
1672 * Always use LP presolver: 1735 /* Solve LP */
1673 * mlp->control_param_lp.presolve = GLP_YES; */ 1736 /* Only for debugging:
1674 res_lp = mlp_solve_lp_problem(mlp); 1737 * Always use LP presolver:
1675 if (GNUNET_OK == res_lp) 1738 * mlp->control_param_lp.presolve = GLP_YES; */
1676 { 1739 res_lp = mlp_solve_lp_problem (mlp);
1677 mlp->ps.lp_objective_value = glp_get_obj_val(mlp->p.prob); 1740 if (GNUNET_OK == res_lp)
1678 LOG(GNUNET_ERROR_TYPE_DEBUG, 1741 {
1679 "LP solution was: %.3f\n", 1742 mlp->ps.lp_objective_value = glp_get_obj_val (mlp->p.prob);
1680 mlp->ps.lp_objective_value); 1743 LOG (GNUNET_ERROR_TYPE_DEBUG,
1681 } 1744 "LP solution was: %.3f\n",
1682 1745 mlp->ps.lp_objective_value);
1683 dur_lp = GNUNET_TIME_absolute_get_duration(start_cur_op); 1746 }
1684 notify(mlp, GAS_OP_SOLVE_MLP_LP_STOP, 1747
1685 (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1748 dur_lp = GNUNET_TIME_absolute_get_duration (start_cur_op);
1686 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1749 notify (mlp, GAS_OP_SOLVE_MLP_LP_STOP,
1687 } 1750 (GNUNET_OK == res_lp) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1751 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1752 GAS_INFO_UPDATED);
1753 }
1688 1754
1689 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 1755 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
1690 res_lp = GNUNET_OK; 1756 res_lp = GNUNET_OK;
1691 1757
1692 /* Run MLP solver */ 1758 /* Run MLP solver */
1693 if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver)) 1759 if ((GNUNET_OK == res_lp) || (GNUNET_YES == mlp->opt_dbg_intopt_presolver))
1760 {
1761 LOG (GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n");
1762 notify (mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS,
1763 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1764 GAS_INFO_UPDATED);
1765 start_cur_op = GNUNET_TIME_absolute_get ();
1766
1767 /* Solve MIP */
1768
1769 /* Only for debugging, always use LP presolver */
1770 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
1771 mlp->control_param_mlp.presolve = GNUNET_YES;
1772
1773 mip_res = glp_intopt (mlp->p.prob, &mlp->control_param_mlp);
1774 switch (mip_res)
1694 { 1775 {
1695 LOG(GNUNET_ERROR_TYPE_DEBUG, "Running MLP solver \n"); 1776 case 0:
1696 notify(mlp, GAS_OP_SOLVE_MLP_MLP_START, GAS_STAT_SUCCESS, 1777 /* Successful */
1697 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1778 LOG (GNUNET_ERROR_TYPE_INFO,
1698 start_cur_op = GNUNET_TIME_absolute_get(); 1779 "Solving MLP problem: %s\n",
1699 1780 mlp_solve_to_string (mip_res));
1700 /* Solve MIP */ 1781 break;
1701 1782
1702 /* Only for debugging, always use LP presolver */ 1783 case GLP_ETMLIM: /* Time limit reached */
1703 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 1784 case GLP_EMIPGAP: /* MIP gap tolerance limit reached */
1704 mlp->control_param_mlp.presolve = GNUNET_YES; 1785 case GLP_ESTOP: /* Solver was instructed to stop*/
1705 1786 /* Semi-successful */
1706 mip_res = glp_intopt(mlp->p.prob, &mlp->control_param_mlp); 1787 LOG (GNUNET_ERROR_TYPE_INFO,
1707 switch (mip_res) 1788 "Solving MLP problem solution was interupted: %s\n",
1708 { 1789 mlp_solve_to_string (mip_res));
1709 case 0: 1790 break;
1710 /* Successful */ 1791
1711 LOG(GNUNET_ERROR_TYPE_INFO, 1792 case GLP_EBOUND:
1712 "Solving MLP problem: %s\n", 1793 case GLP_EROOT:
1713 mlp_solve_to_string(mip_res)); 1794 case GLP_ENOPFS:
1714 break; 1795 case GLP_ENODFS:
1715 1796 case GLP_EFAIL:
1716 case GLP_ETMLIM: /* Time limit reached */ 1797 default:
1717 case GLP_EMIPGAP: /* MIP gap tolerance limit reached */ 1798 /* Fail */
1718 case GLP_ESTOP: /* Solver was instructed to stop*/ 1799 LOG (GNUNET_ERROR_TYPE_INFO,
1719 /* Semi-successful */ 1800 "Solving MLP problem failed: %s\n",
1720 LOG(GNUNET_ERROR_TYPE_INFO, 1801 mlp_solve_to_string (mip_res));
1721 "Solving MLP problem solution was interupted: %s\n", 1802 break;
1722 mlp_solve_to_string(mip_res));
1723 break;
1724
1725 case GLP_EBOUND:
1726 case GLP_EROOT:
1727 case GLP_ENOPFS:
1728 case GLP_ENODFS:
1729 case GLP_EFAIL:
1730 default:
1731 /* Fail */
1732 LOG(GNUNET_ERROR_TYPE_INFO,
1733 "Solving MLP problem failed: %s\n",
1734 mlp_solve_to_string(mip_res));
1735 break;
1736 }
1737
1738 /* Analyze problem status */
1739 mip_status = glp_mip_status(mlp->p.prob);
1740 switch (mip_status)
1741 {
1742 case GLP_OPT: /* solution is optimal */
1743 LOG(GNUNET_ERROR_TYPE_WARNING,
1744 "Solution of MLP problem is optimal: %s, %s\n",
1745 mlp_solve_to_string(mip_res),
1746 mlp_status_to_string(mip_status));
1747 mip_res = GNUNET_OK;
1748 break;
1749
1750 case GLP_FEAS: /* solution is feasible but not proven optimal */
1751
1752 if ((mlp->ps.mlp_gap <= mlp->pv.mip_gap) ||
1753 (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap))
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));
1778 mip_res = GNUNET_SYSERR;
1779 break;
1780 }
1781
1782 dur_mlp = GNUNET_TIME_absolute_get_duration(start_cur_op);
1783 dur_total = GNUNET_TIME_absolute_get_duration(start_total);
1784
1785 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP,
1786 (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1787 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED);
1788 } 1803 }
1789 else 1804
1805 /* Analyze problem status */
1806 mip_status = glp_mip_status (mlp->p.prob);
1807 switch (mip_status)
1790 { 1808 {
1791 /* Do not execute mip solver since lp solution is invalid */ 1809 case GLP_OPT: /* solution is optimal */
1792 dur_mlp = GNUNET_TIME_UNIT_ZERO; 1810 LOG (GNUNET_ERROR_TYPE_WARNING,
1793 dur_total = GNUNET_TIME_absolute_get_duration(start_total); 1811 "Solution of MLP problem is optimal: %s, %s\n",
1812 mlp_solve_to_string (mip_res),
1813 mlp_status_to_string (mip_status));
1814 mip_res = GNUNET_OK;
1815 break;
1816
1817 case GLP_FEAS: /* solution is feasible but not proven optimal */
1818
1819 if ((mlp->ps.mlp_gap <= mlp->pv.mip_gap) ||
1820 (mlp->ps.lp_mlp_gap <= mlp->pv.lp_mip_gap))
1821 {
1822 LOG (GNUNET_ERROR_TYPE_INFO,
1823 "Solution of MLP problem is feasible and solution within gap constraints: %s, %s\n",
1824 mlp_solve_to_string (mip_res),
1825 mlp_status_to_string (mip_status));
1826 mip_res = GNUNET_OK;
1827 }
1828 else
1829 {
1830 LOG (GNUNET_ERROR_TYPE_WARNING,
1831 "Solution of MLP problem is feasible but solution not within gap constraints: %s, %s\n",
1832 mlp_solve_to_string (mip_res),
1833 mlp_status_to_string (mip_status));
1834 mip_res = GNUNET_SYSERR;
1835 }
1836 break;
1794 1837
1795 notify(mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL, 1838 case GLP_UNDEF: /* Solution undefined */
1796 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1839 case GLP_NOFEAS: /* No feasible solution */
1840 default:
1841 LOG (GNUNET_ERROR_TYPE_ERROR,
1842 "Solving MLP problem failed: %s %s\n",
1843 mlp_solve_to_string (mip_res),
1844 mlp_status_to_string (mip_status));
1797 mip_res = GNUNET_SYSERR; 1845 mip_res = GNUNET_SYSERR;
1846 break;
1798 } 1847 }
1799 1848
1849 dur_mlp = GNUNET_TIME_absolute_get_duration (start_cur_op);
1850 dur_total = GNUNET_TIME_absolute_get_duration (start_total);
1851
1852 notify (mlp, GAS_OP_SOLVE_MLP_MLP_STOP,
1853 (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1854 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1855 GAS_INFO_UPDATED);
1856 }
1857 else
1858 {
1859 /* Do not execute mip solver since lp solution is invalid */
1860 dur_mlp = GNUNET_TIME_UNIT_ZERO;
1861 dur_total = GNUNET_TIME_absolute_get_duration (start_total);
1862
1863 notify (mlp, GAS_OP_SOLVE_MLP_MLP_STOP, GAS_STAT_FAIL,
1864 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1865 GAS_INFO_UPDATED);
1866 mip_res = GNUNET_SYSERR;
1867 }
1868
1800 /* Notify about end */ 1869 /* Notify about end */
1801 notify(mlp, GAS_OP_SOLVE_STOP, 1870 notify (mlp, GAS_OP_SOLVE_STOP,
1802 ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1871 ((GNUNET_OK == mip_res) && (GNUNET_OK == mip_res)) ?
1803 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL : GAS_INFO_UPDATED); 1872 GAS_STAT_SUCCESS : GAS_STAT_FAIL,
1804 1873 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? GAS_INFO_FULL :
1805 LOG(GNUNET_ERROR_TYPE_DEBUG, 1874 GAS_INFO_UPDATED);
1806 "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n", 1875
1807 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated", 1876 LOG (GNUNET_ERROR_TYPE_DEBUG,
1808 (unsigned long long)dur_total.rel_value_us, 1877 "Execution time for %s solve: (total/setup/lp/mlp) : %llu %llu %llu %llu\n",
1809 (unsigned long long)dur_setup.rel_value_us, 1878 (GNUNET_YES == mlp->stat_mlp_prob_changed) ? "full" : "updated",
1810 (unsigned long long)dur_lp.rel_value_us, 1879 (unsigned long long) dur_total.rel_value_us,
1811 (unsigned long long)dur_mlp.rel_value_us); 1880 (unsigned long long) dur_setup.rel_value_us,
1881 (unsigned long long) dur_lp.rel_value_us,
1882 (unsigned long long) dur_mlp.rel_value_us);
1812 1883
1813 /* Save stats */ 1884 /* Save stats */
1814 mlp->ps.lp_res = res_lp; 1885 mlp->ps.lp_res = res_lp;
1815 mlp->ps.mip_res = mip_res; 1886 mlp->ps.mip_res = mip_res;
1816 mlp->ps.lp_presolv = mlp->control_param_lp.presolve; 1887 mlp->ps.lp_presolv = mlp->control_param_lp.presolve;
1817 mlp->ps.mip_presolv = mlp->control_param_mlp.presolve; 1888 mlp->ps.mip_presolv = mlp->control_param_mlp.presolve;
1818 mlp->ps.p_cols = glp_get_num_cols(mlp->p.prob); 1889 mlp->ps.p_cols = glp_get_num_cols (mlp->p.prob);
1819 mlp->ps.p_rows = glp_get_num_rows(mlp->p.prob); 1890 mlp->ps.p_rows = glp_get_num_rows (mlp->p.prob);
1820 mlp->ps.p_elements = mlp->p.num_elements; 1891 mlp->ps.p_elements = mlp->p.num_elements;
1821 1892
1822 /* Propagate result*/ 1893 /* Propagate result*/
1823 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, 1894 notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
1824 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1895 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS :
1825 GAS_INFO_NONE); 1896 GAS_STAT_FAIL,
1897 GAS_INFO_NONE);
1826 if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res)) 1898 if ((GNUNET_OK == res_lp) && (GNUNET_OK == mip_res))
1827 { 1899 {
1828 GNUNET_CONTAINER_multipeermap_iterate(mlp->env->addresses, 1900 GNUNET_CONTAINER_multipeermap_iterate (mlp->env->addresses,
1829 &mlp_propagate_results, mlp); 1901 &mlp_propagate_results, mlp);
1830 } 1902 }
1831 notify(mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 1903 notify (mlp, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
1832 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS : GAS_STAT_FAIL, 1904 (GNUNET_OK == res_lp) && (GNUNET_OK == mip_res) ? GAS_STAT_SUCCESS :
1833 GAS_INFO_NONE); 1905 GAS_STAT_FAIL,
1834 1906 GAS_INFO_NONE);
1835 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get(); 1907
1908 struct GNUNET_TIME_Absolute time = GNUNET_TIME_absolute_get ();
1836 if ((GNUNET_YES == mlp->opt_dump_problem_all) || 1909 if ((GNUNET_YES == mlp->opt_dump_problem_all) ||
1837 (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res)))) 1910 (mlp->opt_dump_problem_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK !=
1838 { 1911 mip_res))))
1839 /* Write problem to disk */ 1912 {
1840 switch (mlp->opt_log_format) 1913 /* Write problem to disk */
1841 { 1914 switch (mlp->opt_log_format)
1842 case MLP_CPLEX: 1915 {
1843 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.cplex", mlp->p.num_peers, 1916 case MLP_CPLEX:
1844 mlp->p.num_addresses, time.abs_value_us); 1917 GNUNET_asprintf (&filename, "problem_p_%u_a%u_%llu.cplex",
1845 glp_write_lp(mlp->p.prob, NULL, filename); 1918 mlp->p.num_peers,
1846 break; 1919 mlp->p.num_addresses, time.abs_value_us);
1847 1920 glp_write_lp (mlp->p.prob, NULL, filename);
1848 case MLP_GLPK: 1921 break;
1849 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.glpk", mlp->p.num_peers, 1922
1850 mlp->p.num_addresses, time.abs_value_us); 1923 case MLP_GLPK:
1851 glp_write_prob(mlp->p.prob, 0, filename); 1924 GNUNET_asprintf (&filename, "problem_p_%u_a%u_%llu.glpk",
1852 break; 1925 mlp->p.num_peers,
1853 1926 mlp->p.num_addresses, time.abs_value_us);
1854 case MLP_MPS: 1927 glp_write_prob (mlp->p.prob, 0, filename);
1855 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers, 1928 break;
1856 mlp->p.num_addresses, time.abs_value_us); 1929
1857 glp_write_mps(mlp->p.prob, GLP_MPS_FILE, NULL, filename); 1930 case MLP_MPS:
1858 break; 1931 GNUNET_asprintf (&filename, "problem_p_%u_a%u_%llu.mps", mlp->p.num_peers,
1859 1932 mlp->p.num_addresses, time.abs_value_us);
1860 default: 1933 glp_write_mps (mlp->p.prob, GLP_MPS_FILE, NULL, filename);
1861 break; 1934 break;
1862 } 1935
1863 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename); 1936 default:
1864 GNUNET_free(filename); 1937 break;
1865 } 1938 }
1939 LOG (GNUNET_ERROR_TYPE_ERROR, "Dumped problem to file: `%s' \n", filename);
1940 GNUNET_free (filename);
1941 }
1866 if ((mlp->opt_dump_solution_all) || 1942 if ((mlp->opt_dump_solution_all) ||
1867 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK != mip_res)))) 1943 (mlp->opt_dump_solution_on_fail && ((GNUNET_OK != res_lp) || (GNUNET_OK !=
1868 { 1944 mip_res))))
1869 /* Write solution to disk */ 1945 {
1870 GNUNET_asprintf(&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers, 1946 /* Write solution to disk */
1871 mlp->p.num_addresses, time.abs_value_us); 1947 GNUNET_asprintf (&filename, "problem_p_%u_a%u_%llu.sol", mlp->p.num_peers,
1872 glp_print_mip(mlp->p.prob, filename); 1948 mlp->p.num_addresses, time.abs_value_us);
1873 LOG(GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename); 1949 glp_print_mip (mlp->p.prob, filename);
1874 GNUNET_free(filename); 1950 LOG (GNUNET_ERROR_TYPE_ERROR, "Dumped solution to file: `%s' \n", filename);
1875 } 1951 GNUNET_free (filename);
1952 }
1876 1953
1877 /* Reset change and update marker */ 1954 /* Reset change and update marker */
1878 mlp->control_param_lp.presolve = GLP_NO; 1955 mlp->control_param_lp.presolve = GLP_NO;
@@ -1893,46 +1970,46 @@ GAS_mlp_solve_problem(void *solver)
1893 * @param network network type of this address 1970 * @param network network type of this address
1894 */ 1971 */
1895static void 1972static void
1896GAS_mlp_address_add(void *solver, 1973GAS_mlp_address_add (void *solver,
1897 struct ATS_Address *address, 1974 struct ATS_Address *address,
1898 uint32_t network) 1975 uint32_t network)
1899{ 1976{
1900 struct GAS_MLP_Handle *mlp = solver; 1977 struct GAS_MLP_Handle *mlp = solver;
1901 1978
1902 if (GNUNET_NT_COUNT <= network) 1979 if (GNUNET_NT_COUNT <= network)
1903 { 1980 {
1904 GNUNET_break(0); 1981 GNUNET_break (0);
1905 return; 1982 return;
1906 } 1983 }
1907 1984
1908 if (NULL == address->solver_information) 1985 if (NULL == address->solver_information)
1909 { 1986 {
1910 address->solver_information = GNUNET_new(struct MLP_information); 1987 address->solver_information = GNUNET_new (struct MLP_information);
1911 } 1988 }
1912 else 1989 else
1913 LOG(GNUNET_ERROR_TYPE_ERROR, 1990 LOG (GNUNET_ERROR_TYPE_ERROR,
1914 _("Adding address for peer `%s' multiple times\n"), 1991 _ ("Adding address for peer `%s' multiple times\n"),
1915 GNUNET_i2s(&address->peer)); 1992 GNUNET_i2s (&address->peer));
1916 1993
1917 /* Is this peer included in the problem? */ 1994 /* Is this peer included in the problem? */
1918 if (NULL == 1995 if (NULL ==
1919 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, 1996 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1920 &address->peer)) 1997 &address->peer))
1921 { 1998 {
1922 /* FIXME: should this be an error? */ 1999 /* FIXME: should this be an error? */
1923 LOG(GNUNET_ERROR_TYPE_DEBUG, 2000 LOG (GNUNET_ERROR_TYPE_DEBUG,
1924 "Adding address for peer `%s' without address request\n", 2001 "Adding address for peer `%s' without address request\n",
1925 GNUNET_i2s(&address->peer)); 2002 GNUNET_i2s (&address->peer));
1926 return; 2003 return;
1927 } 2004 }
1928 2005
1929 LOG(GNUNET_ERROR_TYPE_DEBUG, 2006 LOG (GNUNET_ERROR_TYPE_DEBUG,
1930 "Adding address for peer `%s' with address request \n", 2007 "Adding address for peer `%s' with address request \n",
1931 GNUNET_i2s(&address->peer)); 2008 GNUNET_i2s (&address->peer));
1932 /* Problem size changed: new address for peer with pending request */ 2009 /* Problem size changed: new address for peer with pending request */
1933 mlp->stat_mlp_prob_changed = GNUNET_YES; 2010 mlp->stat_mlp_prob_changed = GNUNET_YES;
1934 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2011 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1935 GAS_mlp_solve_problem(solver); 2012 GAS_mlp_solve_problem (solver);
1936} 2013}
1937 2014
1938 2015
@@ -1943,8 +2020,8 @@ GAS_mlp_address_add(void *solver,
1943 * @param address the address 2020 * @param address the address
1944 */ 2021 */
1945static void 2022static void
1946GAS_mlp_address_property_changed(void *solver, 2023GAS_mlp_address_property_changed (void *solver,
1947 struct ATS_Address *address) 2024 struct ATS_Address *address)
1948{ 2025{
1949 struct MLP_information *mlpi = address->solver_information; 2026 struct MLP_information *mlpi = address->solver_information;
1950 struct GAS_MLP_Handle *mlp = solver; 2027 struct GAS_MLP_Handle *mlp = solver;
@@ -1953,46 +2030,46 @@ GAS_mlp_address_property_changed(void *solver,
1953 return; /* There is no MLP problem to update yet */ 2030 return; /* There is no MLP problem to update yet */
1954 2031
1955 if (NULL == mlpi) 2032 if (NULL == mlpi)
1956 { 2033 {
1957 LOG(GNUNET_ERROR_TYPE_INFO, 2034 LOG (GNUNET_ERROR_TYPE_INFO,
1958 _("Updating address property for peer `%s' %p not added before\n"), 2035 _ ("Updating address property for peer `%s' %p not added before\n"),
1959 GNUNET_i2s(&address->peer), 2036 GNUNET_i2s (&address->peer),
1960 address); 2037 address);
1961 GNUNET_break(0); 2038 GNUNET_break (0);
1962 return; 2039 return;
1963 } 2040 }
1964 if (NULL == 2041 if (NULL ==
1965 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, 2042 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
1966 &address->peer)) 2043 &address->peer))
1967 { 2044 {
1968 /* Peer is not requested, so no need to update problem */ 2045 /* Peer is not requested, so no need to update problem */
1969 return; 2046 return;
1970 } 2047 }
1971 LOG(GNUNET_ERROR_TYPE_DEBUG, 2048 LOG (GNUNET_ERROR_TYPE_DEBUG,
1972 "Updating properties for peer `%s'\n", 2049 "Updating properties for peer `%s'\n",
1973 GNUNET_i2s(&address->peer)); 2050 GNUNET_i2s (&address->peer));
1974 2051
1975 if (GNUNET_YES == mlp->opt_dbg_feasibility_only) 2052 if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
1976 return; 2053 return;
1977 2054
1978 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */ 2055 /* Update c7) [r_q[index]][c_b] = f_q * q_averaged[type_index] */
1979 if ((GNUNET_YES == 2056 if ((GNUNET_YES ==
1980 mlp_create_problem_update_value(&mlp->p, 2057 mlp_create_problem_update_value (&mlp->p,
1981 mlp->p.r_q[RQ_QUALITY_METRIC_DELAY], 2058 mlp->p.r_q[RQ_QUALITY_METRIC_DELAY],
1982 mlpi->c_b, 2059 mlpi->c_b,
1983 address->norm_delay.norm, 2060 address->norm_delay.norm,
1984 __LINE__)) || 2061 __LINE__)) ||
1985 (GNUNET_YES == 2062 (GNUNET_YES ==
1986 mlp_create_problem_update_value(&mlp->p, 2063 mlp_create_problem_update_value (&mlp->p,
1987 mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE], 2064 mlp->p.r_q[RQ_QUALITY_METRIC_DISTANCE],
1988 mlpi->c_b, 2065 mlpi->c_b,
1989 address->norm_distance.norm, 2066 address->norm_distance.norm,
1990 __LINE__))) 2067 __LINE__)))
1991 { 2068 {
1992 mlp->stat_mlp_prob_updated = GNUNET_YES; 2069 mlp->stat_mlp_prob_updated = GNUNET_YES;
1993 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2070 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
1994 GAS_mlp_solve_problem(solver); 2071 GAS_mlp_solve_problem (solver);
1995 } 2072 }
1996} 2073}
1997 2074
1998 2075
@@ -2004,9 +2081,9 @@ GAS_mlp_address_property_changed(void *solver,
2004 * @return #GNUNET_OK 2081 * @return #GNUNET_OK
2005 */ 2082 */
2006static int 2083static int
2007mlp_get_preferred_address_it(void *cls, 2084mlp_get_preferred_address_it (void *cls,
2008 const struct GNUNET_PeerIdentity *key, 2085 const struct GNUNET_PeerIdentity *key,
2009 void *value) 2086 void *value)
2010{ 2087{
2011 static int counter = 0; 2088 static int counter = 0;
2012 struct ATS_Address **aa = cls; 2089 struct ATS_Address **aa = cls;
@@ -2026,40 +2103,40 @@ mlp_get_preferred_address_it(void *cls,
2026 */ 2103 */
2027 2104
2028 if (GNUNET_YES == mlpi->n) 2105 if (GNUNET_YES == mlpi->n)
2029 { 2106 {
2030 (*aa) = addr; 2107 (*aa) = addr;
2031 (*aa)->assigned_bw_in = mlpi->b_in; 2108 (*aa)->assigned_bw_in = mlpi->b_in;
2032 (*aa)->assigned_bw_out = mlpi->b_out; 2109 (*aa)->assigned_bw_out = mlpi->b_out;
2033 return GNUNET_NO; 2110 return GNUNET_NO;
2034 } 2111 }
2035 counter++; 2112 counter++;
2036 return GNUNET_YES; 2113 return GNUNET_YES;
2037} 2114}
2038 2115
2039 2116
2040static double 2117static double
2041get_peer_pref_value(struct GAS_MLP_Handle *mlp, 2118get_peer_pref_value (struct GAS_MLP_Handle *mlp,
2042 const struct GNUNET_PeerIdentity *peer) 2119 const struct GNUNET_PeerIdentity *peer)
2043{ 2120{
2044 double res; 2121 double res;
2045 const double *preferences; 2122 const double *preferences;
2046 int c; 2123 int c;
2047 2124
2048 preferences = mlp->env->get_preferences(mlp->env->cls, peer); 2125 preferences = mlp->env->get_preferences (mlp->env->cls, peer);
2049 res = 0.0; 2126 res = 0.0;
2050 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) 2127 for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++)
2051 { 2128 {
2052 /* fprintf (stderr, "VALUE[%u] %s %.3f \n", 2129 /* fprintf (stderr, "VALUE[%u] %s %.3f \n",
2053 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */ 2130 * c, GNUNET_i2s (&cur->addr->peer), t[c]); */
2054 res += preferences[c]; 2131 res += preferences[c];
2055 } 2132 }
2056 2133
2057 res /= GNUNET_ATS_PREFERENCE_END; 2134 res /= GNUNET_ATS_PREFERENCE_END;
2058 res += 1.0; 2135 res += 1.0;
2059 2136
2060 LOG(GNUNET_ERROR_TYPE_DEBUG, 2137 LOG (GNUNET_ERROR_TYPE_DEBUG,
2061 "Peer preference for peer `%s' == %.2f\n", 2138 "Peer preference for peer `%s' == %.2f\n",
2062 GNUNET_i2s(peer), res); 2139 GNUNET_i2s (peer), res);
2063 2140
2064 return res; 2141 return res;
2065} 2142}
@@ -2072,51 +2149,54 @@ get_peer_pref_value(struct GAS_MLP_Handle *mlp,
2072 * @param peer the peer 2149 * @param peer the peer
2073 */ 2150 */
2074static void 2151static void
2075GAS_mlp_get_preferred_address(void *solver, 2152GAS_mlp_get_preferred_address (void *solver,
2076 const struct GNUNET_PeerIdentity *peer) 2153 const struct GNUNET_PeerIdentity *peer)
2077{ 2154{
2078 struct GAS_MLP_Handle *mlp = solver; 2155 struct GAS_MLP_Handle *mlp = solver;
2079 struct ATS_Peer *p; 2156 struct ATS_Peer *p;
2080 struct ATS_Address *res; 2157 struct ATS_Address *res;
2081 2158
2082 LOG(GNUNET_ERROR_TYPE_DEBUG, 2159 LOG (GNUNET_ERROR_TYPE_DEBUG,
2083 "Getting preferred address for `%s'\n", 2160 "Getting preferred address for `%s'\n",
2084 GNUNET_i2s(peer)); 2161 GNUNET_i2s (peer));
2085 2162
2086 /* Is this peer included in the problem? */ 2163 /* Is this peer included in the problem? */
2087 if (NULL == 2164 if (NULL ==
2088 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, 2165 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
2089 peer)) 2166 peer))
2090 { 2167 {
2091 LOG(GNUNET_ERROR_TYPE_INFO, "Adding peer `%s' to list of requested_peers with requests\n", 2168 LOG (GNUNET_ERROR_TYPE_INFO,
2092 GNUNET_i2s(peer)); 2169 "Adding peer `%s' to list of requested_peers with requests\n",
2093 2170 GNUNET_i2s (peer));
2094 p = GNUNET_new(struct ATS_Peer); 2171
2095 p->id = (*peer); 2172 p = GNUNET_new (struct ATS_Peer);
2096 p->f = get_peer_pref_value(mlp, peer); 2173 p->id = (*peer);
2097 GNUNET_CONTAINER_multipeermap_put(mlp->requested_peers, 2174 p->f = get_peer_pref_value (mlp, peer);
2098 peer, p, 2175 GNUNET_CONTAINER_multipeermap_put (mlp->requested_peers,
2099 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 2176 peer, p,
2100 2177 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
2101 /* Added new peer, we have to rebuild problem before solving */ 2178
2102 mlp->stat_mlp_prob_changed = GNUNET_YES; 2179 /* Added new peer, we have to rebuild problem before solving */
2103 2180 mlp->stat_mlp_prob_changed = GNUNET_YES;
2104 if ((GNUNET_YES == mlp->opt_mlp_auto_solve) && 2181
2105 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(mlp->env->addresses, 2182 if ((GNUNET_YES == mlp->opt_mlp_auto_solve) &&
2106 peer))) 2183 (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (
2107 { 2184 mlp->env->addresses,
2108 mlp->exclude_peer = peer; 2185 peer)))
2109 GAS_mlp_solve_problem(mlp); 2186 {
2110 mlp->exclude_peer = NULL; 2187 mlp->exclude_peer = peer;
2111 } 2188 GAS_mlp_solve_problem (mlp);
2112 } 2189 mlp->exclude_peer = NULL;
2190 }
2191 }
2113 /* Get prefered address */ 2192 /* Get prefered address */
2114 res = NULL; 2193 res = NULL;
2115 GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses, peer, 2194 GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses, peer,
2116 &mlp_get_preferred_address_it, &res); 2195 &mlp_get_preferred_address_it,
2196 &res);
2117 if (NULL != res) 2197 if (NULL != res)
2118 mlp->env->bandwidth_changed_cb(mlp->env->cls, 2198 mlp->env->bandwidth_changed_cb (mlp->env->cls,
2119 res); 2199 res);
2120} 2200}
2121 2201
2122 2202
@@ -2129,8 +2209,8 @@ GAS_mlp_get_preferred_address(void *solver,
2129 * @param address the address to delete 2209 * @param address the address to delete
2130 */ 2210 */
2131static void 2211static void
2132GAS_mlp_address_delete(void *solver, 2212GAS_mlp_address_delete (void *solver,
2133 struct ATS_Address *address) 2213 struct ATS_Address *address)
2134{ 2214{
2135 struct GAS_MLP_Handle *mlp = solver; 2215 struct GAS_MLP_Handle *mlp = solver;
2136 struct MLP_information *mlpi; 2216 struct MLP_information *mlpi;
@@ -2139,11 +2219,11 @@ GAS_mlp_address_delete(void *solver,
2139 2219
2140 mlpi = address->solver_information; 2220 mlpi = address->solver_information;
2141 if (NULL != mlpi) 2221 if (NULL != mlpi)
2142 { 2222 {
2143 /* Remove full address */ 2223 /* Remove full address */
2144 GNUNET_free(mlpi); 2224 GNUNET_free (mlpi);
2145 address->solver_information = NULL; 2225 address->solver_information = NULL;
2146 } 2226 }
2147 was_active = address->active; 2227 was_active = address->active;
2148 address->active = GNUNET_NO; 2228 address->active = GNUNET_NO;
2149 address->assigned_bw_in = 0; 2229 address->assigned_bw_in = 0;
@@ -2151,38 +2231,38 @@ GAS_mlp_address_delete(void *solver,
2151 2231
2152 /* Is this peer included in the problem? */ 2232 /* Is this peer included in the problem? */
2153 if (NULL == 2233 if (NULL ==
2154 GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, 2234 GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
2155 &address->peer)) 2235 &address->peer))
2156 { 2236 {
2157 LOG(GNUNET_ERROR_TYPE_INFO, 2237 LOG (GNUNET_ERROR_TYPE_INFO,
2158 "Deleting address for peer `%s' without address request \n", 2238 "Deleting address for peer `%s' without address request \n",
2159 GNUNET_i2s(&address->peer)); 2239 GNUNET_i2s (&address->peer));
2160 return; 2240 return;
2161 } 2241 }
2162 LOG(GNUNET_ERROR_TYPE_INFO, 2242 LOG (GNUNET_ERROR_TYPE_INFO,
2163 "Deleting address for peer `%s' with address request \n", 2243 "Deleting address for peer `%s' with address request \n",
2164 GNUNET_i2s(&address->peer)); 2244 GNUNET_i2s (&address->peer));
2165 2245
2166 /* Problem size changed: new address for peer with pending request */ 2246 /* Problem size changed: new address for peer with pending request */
2167 mlp->stat_mlp_prob_changed = GNUNET_YES; 2247 mlp->stat_mlp_prob_changed = GNUNET_YES;
2168 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2248 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2169 { 2249 {
2170 GAS_mlp_solve_problem(solver); 2250 GAS_mlp_solve_problem (solver);
2171 } 2251 }
2172 if (GNUNET_YES == was_active) 2252 if (GNUNET_YES == was_active)
2173 { 2253 {
2174 GAS_mlp_get_preferred_address(solver, &address->peer); 2254 GAS_mlp_get_preferred_address (solver, &address->peer);
2175 res = NULL; 2255 res = NULL;
2176 GNUNET_CONTAINER_multipeermap_get_multiple(mlp->env->addresses, 2256 GNUNET_CONTAINER_multipeermap_get_multiple (mlp->env->addresses,
2177 &address->peer, 2257 &address->peer,
2178 &mlp_get_preferred_address_it, 2258 &mlp_get_preferred_address_it,
2179 &res); 2259 &res);
2180 if (NULL == res) 2260 if (NULL == res)
2181 { 2261 {
2182 /* No alternative address, disconnecting peer */ 2262 /* No alternative address, disconnecting peer */
2183 mlp->env->bandwidth_changed_cb(mlp->env->cls, address); 2263 mlp->env->bandwidth_changed_cb (mlp->env->cls, address);
2184 } 2264 }
2185 } 2265 }
2186} 2266}
2187 2267
2188 2268
@@ -2192,38 +2272,38 @@ GAS_mlp_address_delete(void *solver,
2192 * @param solver the solver 2272 * @param solver the solver
2193 */ 2273 */
2194static void 2274static void
2195GAS_mlp_bulk_start(void *solver) 2275GAS_mlp_bulk_start (void *solver)
2196{ 2276{
2197 struct GAS_MLP_Handle *s = solver; 2277 struct GAS_MLP_Handle *s = solver;
2198 2278
2199 LOG(GNUNET_ERROR_TYPE_DEBUG, 2279 LOG (GNUNET_ERROR_TYPE_DEBUG,
2200 "Locking solver for bulk operation ...\n"); 2280 "Locking solver for bulk operation ...\n");
2201 GNUNET_assert(NULL != solver); 2281 GNUNET_assert (NULL != solver);
2202 s->stat_bulk_lock++; 2282 s->stat_bulk_lock++;
2203} 2283}
2204 2284
2205 2285
2206static void 2286static void
2207GAS_mlp_bulk_stop(void *solver) 2287GAS_mlp_bulk_stop (void *solver)
2208{ 2288{
2209 struct GAS_MLP_Handle *s = solver; 2289 struct GAS_MLP_Handle *s = solver;
2210 2290
2211 LOG(GNUNET_ERROR_TYPE_DEBUG, 2291 LOG (GNUNET_ERROR_TYPE_DEBUG,
2212 "Unlocking solver from bulk operation ...\n"); 2292 "Unlocking solver from bulk operation ...\n");
2213 GNUNET_assert(NULL != solver); 2293 GNUNET_assert (NULL != solver);
2214 2294
2215 if (s->stat_bulk_lock < 1) 2295 if (s->stat_bulk_lock < 1)
2216 { 2296 {
2217 GNUNET_break(0); 2297 GNUNET_break (0);
2218 return; 2298 return;
2219 } 2299 }
2220 s->stat_bulk_lock--; 2300 s->stat_bulk_lock--;
2221 2301
2222 if (0 < s->stat_bulk_requests) 2302 if (0 < s->stat_bulk_requests)
2223 { 2303 {
2224 GAS_mlp_solve_problem(solver); 2304 GAS_mlp_solve_problem (solver);
2225 s->stat_bulk_requests = 0; 2305 s->stat_bulk_requests = 0;
2226 } 2306 }
2227} 2307}
2228 2308
2229 2309
@@ -2235,26 +2315,28 @@ GAS_mlp_bulk_stop(void *solver)
2235 * @param peer the peer 2315 * @param peer the peer
2236 */ 2316 */
2237static void 2317static void
2238GAS_mlp_stop_get_preferred_address(void *solver, 2318GAS_mlp_stop_get_preferred_address (void *solver,
2239 const struct GNUNET_PeerIdentity *peer) 2319 const struct GNUNET_PeerIdentity *peer)
2240{ 2320{
2241 struct GAS_MLP_Handle *mlp = solver; 2321 struct GAS_MLP_Handle *mlp = solver;
2242 struct ATS_Peer *p = NULL; 2322 struct ATS_Peer *p = NULL;
2243 2323
2244 GNUNET_assert(NULL != solver); 2324 GNUNET_assert (NULL != solver);
2245 GNUNET_assert(NULL != peer); 2325 GNUNET_assert (NULL != peer);
2246 if (NULL != (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer))) 2326 if (NULL != (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
2327 peer)))
2328 {
2329 GNUNET_assert (GNUNET_YES ==
2330 GNUNET_CONTAINER_multipeermap_remove (mlp->requested_peers,
2331 peer, p));
2332 GNUNET_free (p);
2333
2334 mlp->stat_mlp_prob_changed = GNUNET_YES;
2335 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2247 { 2336 {
2248 GNUNET_assert(GNUNET_YES == 2337 GAS_mlp_solve_problem (solver);
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 }
2257 } 2338 }
2339 }
2258} 2340}
2259 2341
2260 2342
@@ -2267,48 +2349,49 @@ GAS_mlp_stop_get_preferred_address(void *solver,
2267 * @param pref_rel the relative score 2349 * @param pref_rel the relative score
2268 */ 2350 */
2269static void 2351static void
2270GAS_mlp_address_change_preference(void *solver, 2352GAS_mlp_address_change_preference (void *solver,
2271 const struct GNUNET_PeerIdentity *peer, 2353 const struct GNUNET_PeerIdentity *peer,
2272 enum GNUNET_ATS_PreferenceKind kind, 2354 enum GNUNET_ATS_PreferenceKind kind,
2273 double pref_rel) 2355 double pref_rel)
2274{ 2356{
2275 struct GAS_MLP_Handle *mlp = solver; 2357 struct GAS_MLP_Handle *mlp = solver;
2276 struct ATS_Peer *p; 2358 struct ATS_Peer *p;
2277 2359
2278 LOG(GNUNET_ERROR_TYPE_DEBUG, 2360 LOG (GNUNET_ERROR_TYPE_DEBUG,
2279 "Changing preference for address for peer `%s' to %.2f\n", 2361 "Changing preference for address for peer `%s' to %.2f\n",
2280 GNUNET_i2s(peer), 2362 GNUNET_i2s (peer),
2281 pref_rel); 2363 pref_rel);
2282 2364
2283 GNUNET_STATISTICS_update(mlp->env->stats, 2365 GNUNET_STATISTICS_update (mlp->env->stats,
2284 "# LP address preference changes", 1, GNUNET_NO); 2366 "# LP address preference changes", 1, GNUNET_NO);
2285 /* Update the constraints with changed preferences */ 2367 /* Update the constraints with changed preferences */
2286 2368
2287 2369
2288 2370
2289 /* Update relativity constraint c9 */ 2371 /* Update relativity constraint c9 */
2290 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get(mlp->requested_peers, peer))) 2372 if (NULL == (p = GNUNET_CONTAINER_multipeermap_get (mlp->requested_peers,
2291 { 2373 peer)))
2292 LOG(GNUNET_ERROR_TYPE_INFO, 2374 {
2293 "Updating preference for unknown peer `%s'\n", 2375 LOG (GNUNET_ERROR_TYPE_INFO,
2294 GNUNET_i2s(peer)); 2376 "Updating preference for unknown peer `%s'\n",
2295 return; 2377 GNUNET_i2s (peer));
2296 } 2378 return;
2379 }
2297 2380
2298 if (GNUNET_NO == mlp->opt_dbg_feasibility_only) 2381 if (GNUNET_NO == mlp->opt_dbg_feasibility_only)
2299 { 2382 {
2300 p->f = get_peer_pref_value(mlp, peer); 2383 p->f = get_peer_pref_value (mlp, peer);
2301 mlp_create_problem_update_value(&mlp->p, 2384 mlp_create_problem_update_value (&mlp->p,
2302 p->r_c9, 2385 p->r_c9,
2303 mlp->p.c_r, 2386 mlp->p.c_r,
2304 -p->f, 2387 -p->f,
2305 __LINE__); 2388 __LINE__);
2306 2389
2307 /* Problem size changed: new address for peer with pending request */ 2390 /* Problem size changed: new address for peer with pending request */
2308 mlp->stat_mlp_prob_updated = GNUNET_YES; 2391 mlp->stat_mlp_prob_updated = GNUNET_YES;
2309 if (GNUNET_YES == mlp->opt_mlp_auto_solve) 2392 if (GNUNET_YES == mlp->opt_mlp_auto_solve)
2310 GAS_mlp_solve_problem(solver); 2393 GAS_mlp_solve_problem (solver);
2311 } 2394 }
2312} 2395}
2313 2396
2314 2397
@@ -2323,31 +2406,31 @@ GAS_mlp_address_change_preference(void *solver,
2323 * @param score the score 2406 * @param score the score
2324 */ 2407 */
2325static void 2408static void
2326GAS_mlp_address_preference_feedback(void *solver, 2409GAS_mlp_address_preference_feedback (void *solver,
2327 struct GNUNET_SERVICE_Client *application, 2410 struct GNUNET_SERVICE_Client *application,
2328 const struct GNUNET_PeerIdentity *peer, 2411 const struct GNUNET_PeerIdentity *peer,
2329 const struct GNUNET_TIME_Relative scope, 2412 const struct GNUNET_TIME_Relative scope,
2330 enum GNUNET_ATS_PreferenceKind kind, 2413 enum GNUNET_ATS_PreferenceKind kind,
2331 double score) 2414 double score)
2332{ 2415{
2333 struct GAS_PROPORTIONAL_Handle *s = solver; 2416 struct GAS_PROPORTIONAL_Handle *s = solver;
2334 2417
2335 GNUNET_assert(NULL != solver); 2418 GNUNET_assert (NULL != solver);
2336 GNUNET_assert(NULL != peer); 2419 GNUNET_assert (NULL != peer);
2337 GNUNET_assert(NULL != s); 2420 GNUNET_assert (NULL != s);
2338} 2421}
2339 2422
2340 2423
2341static int 2424static int
2342mlp_free_peers(void *cls, 2425mlp_free_peers (void *cls,
2343 const struct GNUNET_PeerIdentity *key, void *value) 2426 const struct GNUNET_PeerIdentity *key, void *value)
2344{ 2427{
2345 struct GNUNET_CONTAINER_MultiPeerMap *map = cls; 2428 struct GNUNET_CONTAINER_MultiPeerMap *map = cls;
2346 struct ATS_Peer *p = value; 2429 struct ATS_Peer *p = value;
2347 2430
2348 GNUNET_assert(GNUNET_YES == 2431 GNUNET_assert (GNUNET_YES ==
2349 GNUNET_CONTAINER_multipeermap_remove(map, key, value)); 2432 GNUNET_CONTAINER_multipeermap_remove (map, key, value));
2350 GNUNET_free(p); 2433 GNUNET_free (p);
2351 2434
2352 return GNUNET_OK; 2435 return GNUNET_OK;
2353} 2436}
@@ -2360,36 +2443,36 @@ mlp_free_peers(void *cls,
2360 * @return NULL 2443 * @return NULL
2361 */ 2444 */
2362void * 2445void *
2363libgnunet_plugin_ats_mlp_done(void *cls) 2446libgnunet_plugin_ats_mlp_done (void *cls)
2364{ 2447{
2365 struct GNUNET_ATS_SolverFunctions *sf = cls; 2448 struct GNUNET_ATS_SolverFunctions *sf = cls;
2366 struct GAS_MLP_Handle *mlp = sf->cls; 2449 struct GAS_MLP_Handle *mlp = sf->cls;
2367 2450
2368 LOG(GNUNET_ERROR_TYPE_DEBUG, 2451 LOG (GNUNET_ERROR_TYPE_DEBUG,
2369 "Shutting down mlp solver\n"); 2452 "Shutting down mlp solver\n");
2370 mlp_delete_problem(mlp); 2453 mlp_delete_problem (mlp);
2371 GNUNET_CONTAINER_multipeermap_iterate(mlp->requested_peers, 2454 GNUNET_CONTAINER_multipeermap_iterate (mlp->requested_peers,
2372 &mlp_free_peers, 2455 &mlp_free_peers,
2373 mlp->requested_peers); 2456 mlp->requested_peers);
2374 GNUNET_CONTAINER_multipeermap_destroy(mlp->requested_peers); 2457 GNUNET_CONTAINER_multipeermap_destroy (mlp->requested_peers);
2375 mlp->requested_peers = NULL; 2458 mlp->requested_peers = NULL;
2376 2459
2377 /* Clean up GLPK environment */ 2460 /* Clean up GLPK environment */
2378 glp_free_env(); 2461 glp_free_env ();
2379 GNUNET_free(mlp); 2462 GNUNET_free (mlp);
2380 2463
2381 LOG(GNUNET_ERROR_TYPE_DEBUG, 2464 LOG (GNUNET_ERROR_TYPE_DEBUG,
2382 "Shutdown down of mlp solver complete\n"); 2465 "Shutdown down of mlp solver complete\n");
2383 return NULL; 2466 return NULL;
2384} 2467}
2385 2468
2386 2469
2387void * 2470void *
2388libgnunet_plugin_ats_mlp_init(void *cls) 2471libgnunet_plugin_ats_mlp_init (void *cls)
2389{ 2472{
2390 static struct GNUNET_ATS_SolverFunctions sf; 2473 static struct GNUNET_ATS_SolverFunctions sf;
2391 struct GNUNET_ATS_PluginEnvironment *env = cls; 2474 struct GNUNET_ATS_PluginEnvironment *env = cls;
2392 struct GAS_MLP_Handle * mlp = GNUNET_new(struct GAS_MLP_Handle); 2475 struct GAS_MLP_Handle *mlp = GNUNET_new (struct GAS_MLP_Handle);
2393 float f_tmp; 2476 float f_tmp;
2394 unsigned long long tmp; 2477 unsigned long long tmp;
2395 unsigned int b_min; 2478 unsigned int b_min;
@@ -2401,356 +2484,391 @@ libgnunet_plugin_ats_mlp_init(void *cls)
2401 long long unsigned int max_iterations; 2484 long long unsigned int max_iterations;
2402 2485
2403 /* Init GLPK environment */ 2486 /* Init GLPK environment */
2404 int res = glp_init_env(); 2487 int res = glp_init_env ();
2405 2488
2406 switch (res) 2489 switch (res)
2407 { 2490 {
2408 case 0: 2491 case 0:
2409 LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", 2492 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
2410 "initialization successful"); 2493 "initialization successful");
2411 break; 2494 break;
2412 2495
2413 case 1: 2496 case 1:
2414 LOG(GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n", 2497 LOG (GNUNET_ERROR_TYPE_DEBUG, "GLPK: `%s'\n",
2415 "environment is already initialized"); 2498 "environment is already initialized");
2416 break; 2499 break;
2417 2500
2418 case 2: 2501 case 2:
2419 LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", 2502 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
2420 "initialization failed (insufficient memory)"); 2503 "initialization failed (insufficient memory)");
2421 GNUNET_free(mlp); 2504 GNUNET_free (mlp);
2422 return NULL; 2505 return NULL;
2423 break; 2506 break;
2424 2507
2425 case 3: 2508 case 3:
2426 LOG(GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n", 2509 LOG (GNUNET_ERROR_TYPE_ERROR, "Could not init GLPK: `%s'\n",
2427 "initialization failed (unsupported programming model)"); 2510 "initialization failed (unsupported programming model)");
2428 GNUNET_free(mlp); 2511 GNUNET_free (mlp);
2429 return NULL; 2512 return NULL;
2430 break; 2513 break;
2431 2514
2432 default: 2515 default:
2433 break; 2516 break;
2434 } 2517 }
2435 2518
2436 mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2519 mlp->opt_dump_problem_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2437 "ats", "MLP_DUMP_PROBLEM_ALL"); 2520 "ats",
2521 "MLP_DUMP_PROBLEM_ALL");
2438 if (GNUNET_SYSERR == mlp->opt_dump_problem_all) 2522 if (GNUNET_SYSERR == mlp->opt_dump_problem_all)
2439 mlp->opt_dump_problem_all = GNUNET_NO; 2523 mlp->opt_dump_problem_all = GNUNET_NO;
2440 2524
2441 mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2525 mlp->opt_dump_solution_all = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2442 "ats", "MLP_DUMP_SOLUTION_ALL"); 2526 "ats",
2527 "MLP_DUMP_SOLUTION_ALL");
2443 if (GNUNET_SYSERR == mlp->opt_dump_solution_all) 2528 if (GNUNET_SYSERR == mlp->opt_dump_solution_all)
2444 mlp->opt_dump_solution_all = GNUNET_NO; 2529 mlp->opt_dump_solution_all = GNUNET_NO;
2445 2530
2446 mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2531 mlp->opt_dump_problem_on_fail = GNUNET_CONFIGURATION_get_value_yesno (
2447 "ats", "MLP_DUMP_PROBLEM_ON_FAIL"); 2532 env->cfg,
2533 "ats",
2534 "MLP_DUMP_PROBLEM_ON_FAIL");
2448 if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail) 2535 if (GNUNET_SYSERR == mlp->opt_dump_problem_on_fail)
2449 mlp->opt_dump_problem_on_fail = GNUNET_NO; 2536 mlp->opt_dump_problem_on_fail = GNUNET_NO;
2450 2537
2451 mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2538 mlp->opt_dump_solution_on_fail = GNUNET_CONFIGURATION_get_value_yesno (
2452 "ats", "MLP_DUMP_SOLUTION_ON_FAIL"); 2539 env->cfg,
2540 "ats",
2541 "MLP_DUMP_SOLUTION_ON_FAIL");
2453 if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail) 2542 if (GNUNET_SYSERR == mlp->opt_dump_solution_on_fail)
2454 mlp->opt_dump_solution_on_fail = GNUNET_NO; 2543 mlp->opt_dump_solution_on_fail = GNUNET_NO;
2455 2544
2456 mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2545 mlp->opt_dbg_glpk_verbose = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
2457 "ats", "MLP_DBG_GLPK_VERBOSE"); 2546 "ats",
2547 "MLP_DBG_GLPK_VERBOSE");
2458 if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose) 2548 if (GNUNET_SYSERR == mlp->opt_dbg_glpk_verbose)
2459 mlp->opt_dbg_glpk_verbose = GNUNET_NO; 2549 mlp->opt_dbg_glpk_verbose = GNUNET_NO;
2460 2550
2461 mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2551 mlp->opt_dbg_feasibility_only = GNUNET_CONFIGURATION_get_value_yesno (
2462 "ats", "MLP_DBG_FEASIBILITY_ONLY"); 2552 env->cfg,
2553 "ats",
2554 "MLP_DBG_FEASIBILITY_ONLY");
2463 if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only) 2555 if (GNUNET_SYSERR == mlp->opt_dbg_feasibility_only)
2464 mlp->opt_dbg_feasibility_only = GNUNET_NO; 2556 mlp->opt_dbg_feasibility_only = GNUNET_NO;
2465 if (GNUNET_YES == mlp->opt_dbg_feasibility_only) 2557 if (GNUNET_YES == mlp->opt_dbg_feasibility_only)
2466 LOG(GNUNET_ERROR_TYPE_WARNING, 2558 LOG (GNUNET_ERROR_TYPE_WARNING,
2467 "MLP solver is configured to check feasibility only!\n"); 2559 "MLP solver is configured to check feasibility only!\n");
2468 2560
2469 mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2561 mlp->opt_dbg_autoscale_problem = GNUNET_CONFIGURATION_get_value_yesno (
2470 "ats", "MLP_DBG_AUTOSCALE_PROBLEM"); 2562 env->cfg,
2563 "ats",
2564 "MLP_DBG_AUTOSCALE_PROBLEM");
2471 if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem) 2565 if (GNUNET_SYSERR == mlp->opt_dbg_autoscale_problem)
2472 mlp->opt_dbg_autoscale_problem = GNUNET_NO; 2566 mlp->opt_dbg_autoscale_problem = GNUNET_NO;
2473 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem) 2567 if (GNUNET_YES == mlp->opt_dbg_autoscale_problem)
2474 LOG(GNUNET_ERROR_TYPE_WARNING, 2568 LOG (GNUNET_ERROR_TYPE_WARNING,
2475 "MLP solver is configured automatically scale the problem!\n"); 2569 "MLP solver is configured automatically scale the problem!\n");
2476 2570
2477 mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2571 mlp->opt_dbg_intopt_presolver = GNUNET_CONFIGURATION_get_value_yesno (
2478 "ats", "MLP_DBG_INTOPT_PRESOLVE"); 2572 env->cfg,
2573 "ats",
2574 "MLP_DBG_INTOPT_PRESOLVE");
2479 if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver) 2575 if (GNUNET_SYSERR == mlp->opt_dbg_intopt_presolver)
2480 mlp->opt_dbg_intopt_presolver = GNUNET_NO; 2576 mlp->opt_dbg_intopt_presolver = GNUNET_NO;
2481 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver) 2577 if (GNUNET_YES == mlp->opt_dbg_intopt_presolver)
2482 LOG(GNUNET_ERROR_TYPE_WARNING, 2578 LOG (GNUNET_ERROR_TYPE_WARNING,
2483 "MLP solver is configured use the mlp presolver\n"); 2579 "MLP solver is configured use the mlp presolver\n");
2484 2580
2485 mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2581 mlp->opt_dbg_optimize_diversity = GNUNET_CONFIGURATION_get_value_yesno (
2486 "ats", "MLP_DBG_OPTIMIZE_DIVERSITY"); 2582 env->cfg,
2583 "ats",
2584 "MLP_DBG_OPTIMIZE_DIVERSITY");
2487 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity) 2585 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_diversity)
2488 mlp->opt_dbg_optimize_diversity = GNUNET_YES; 2586 mlp->opt_dbg_optimize_diversity = GNUNET_YES;
2489 if (GNUNET_NO == mlp->opt_dbg_optimize_diversity) 2587 if (GNUNET_NO == mlp->opt_dbg_optimize_diversity)
2490 LOG(GNUNET_ERROR_TYPE_WARNING, 2588 LOG (GNUNET_ERROR_TYPE_WARNING,
2491 "MLP solver is not optimizing for diversity\n"); 2589 "MLP solver is not optimizing for diversity\n");
2492 2590
2493 mlp->opt_dbg_optimize_relativity = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2591 mlp->opt_dbg_optimize_relativity = GNUNET_CONFIGURATION_get_value_yesno (
2494 "ats", "MLP_DBG_OPTIMIZE_RELATIVITY"); 2592 env->cfg,
2593 "ats",
2594 "MLP_DBG_OPTIMIZE_RELATIVITY");
2495 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity) 2595 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_relativity)
2496 mlp->opt_dbg_optimize_relativity = GNUNET_YES; 2596 mlp->opt_dbg_optimize_relativity = GNUNET_YES;
2497 if (GNUNET_NO == mlp->opt_dbg_optimize_relativity) 2597 if (GNUNET_NO == mlp->opt_dbg_optimize_relativity)
2498 LOG(GNUNET_ERROR_TYPE_WARNING, 2598 LOG (GNUNET_ERROR_TYPE_WARNING,
2499 "MLP solver is not optimizing for relativity\n"); 2599 "MLP solver is not optimizing for relativity\n");
2500 2600
2501 mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2601 mlp->opt_dbg_optimize_quality = GNUNET_CONFIGURATION_get_value_yesno (
2502 "ats", "MLP_DBG_OPTIMIZE_QUALITY"); 2602 env->cfg,
2603 "ats",
2604 "MLP_DBG_OPTIMIZE_QUALITY");
2503 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality) 2605 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_quality)
2504 mlp->opt_dbg_optimize_quality = GNUNET_YES; 2606 mlp->opt_dbg_optimize_quality = GNUNET_YES;
2505 if (GNUNET_NO == mlp->opt_dbg_optimize_quality) 2607 if (GNUNET_NO == mlp->opt_dbg_optimize_quality)
2506 LOG(GNUNET_ERROR_TYPE_WARNING, 2608 LOG (GNUNET_ERROR_TYPE_WARNING,
2507 "MLP solver is not optimizing for quality\n"); 2609 "MLP solver is not optimizing for quality\n");
2508 2610
2509 mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno(env->cfg, 2611 mlp->opt_dbg_optimize_utility = GNUNET_CONFIGURATION_get_value_yesno (
2510 "ats", "MLP_DBG_OPTIMIZE_UTILITY"); 2612 env->cfg,
2613 "ats",
2614 "MLP_DBG_OPTIMIZE_UTILITY");
2511 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility) 2615 if (GNUNET_SYSERR == mlp->opt_dbg_optimize_utility)
2512 mlp->opt_dbg_optimize_utility = GNUNET_YES; 2616 mlp->opt_dbg_optimize_utility = GNUNET_YES;
2513 if (GNUNET_NO == mlp->opt_dbg_optimize_utility) 2617 if (GNUNET_NO == mlp->opt_dbg_optimize_utility)
2514 LOG(GNUNET_ERROR_TYPE_WARNING, 2618 LOG (GNUNET_ERROR_TYPE_WARNING,
2515 "MLP solver is not optimizing for utility\n"); 2619 "MLP solver is not optimizing for utility\n");
2516 2620
2517 if ((GNUNET_NO == mlp->opt_dbg_optimize_utility) && 2621 if ((GNUNET_NO == mlp->opt_dbg_optimize_utility) &&
2518 (GNUNET_NO == mlp->opt_dbg_optimize_quality) && 2622 (GNUNET_NO == mlp->opt_dbg_optimize_quality) &&
2519 (GNUNET_NO == mlp->opt_dbg_optimize_relativity) && 2623 (GNUNET_NO == mlp->opt_dbg_optimize_relativity) &&
2520 (GNUNET_NO == mlp->opt_dbg_optimize_utility) && 2624 (GNUNET_NO == mlp->opt_dbg_optimize_utility) &&
2521 (GNUNET_NO == mlp->opt_dbg_feasibility_only)) 2625 (GNUNET_NO == mlp->opt_dbg_feasibility_only))
2522 { 2626 {
2523 LOG(GNUNET_ERROR_TYPE_ERROR, 2627 LOG (GNUNET_ERROR_TYPE_ERROR,
2524 _("MLP solver is not optimizing for anything, changing to feasibility check\n")); 2628 _ (
2525 mlp->opt_dbg_feasibility_only = GNUNET_YES; 2629 "MLP solver is not optimizing for anything, changing to feasibility check\n"));
2526 } 2630 mlp->opt_dbg_feasibility_only = GNUNET_YES;
2527 2631 }
2528 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(env->cfg, 2632
2529 "ats", "MLP_LOG_FORMAT", &outputformat)) 2633 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (env->cfg,
2634 "ats",
2635 "MLP_LOG_FORMAT",
2636 &outputformat))
2530 mlp->opt_log_format = MLP_CPLEX; 2637 mlp->opt_log_format = MLP_CPLEX;
2531 else 2638 else
2639 {
2640 GNUNET_STRINGS_utf8_toupper (outputformat, outputformat);
2641 if (0 == strcmp (outputformat, "MPS"))
2532 { 2642 {
2533 GNUNET_STRINGS_utf8_toupper(outputformat, outputformat); 2643 mlp->opt_log_format = MLP_MPS;
2534 if (0 == strcmp(outputformat, "MPS")) 2644 }
2535 { 2645 else if (0 == strcmp (outputformat, "CPLEX"))
2536 mlp->opt_log_format = MLP_MPS; 2646 {
2537 } 2647 mlp->opt_log_format = MLP_CPLEX;
2538 else if (0 == strcmp(outputformat, "CPLEX")) 2648 }
2539 { 2649 else if (0 == strcmp (outputformat, "GLPK"))
2540 mlp->opt_log_format = MLP_CPLEX; 2650 {
2541 } 2651 mlp->opt_log_format = MLP_GLPK;
2542 else if (0 == strcmp(outputformat, "GLPK")) 2652 }
2543 { 2653 else
2544 mlp->opt_log_format = MLP_GLPK; 2654 {
2545 } 2655 LOG (GNUNET_ERROR_TYPE_WARNING,
2546 else 2656 "Invalid log format `%s' in configuration, using CPLEX!\n",
2547 { 2657 outputformat);
2548 LOG(GNUNET_ERROR_TYPE_WARNING, 2658 mlp->opt_log_format = MLP_CPLEX;
2549 "Invalid log format `%s' in configuration, using CPLEX!\n",
2550 outputformat);
2551 mlp->opt_log_format = MLP_CPLEX;
2552 }
2553 GNUNET_free(outputformat);
2554 } 2659 }
2660 GNUNET_free (outputformat);
2661 }
2555 2662
2556 mlp->pv.BIG_M = (double)BIG_M_VALUE; 2663 mlp->pv.BIG_M = (double) BIG_M_VALUE;
2557 2664
2558 mlp->pv.mip_gap = (double)0.0; 2665 mlp->pv.mip_gap = (double) 0.0;
2559 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2666 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2560 "MLP_MAX_MIP_GAP", &f_tmp)) 2667 "MLP_MAX_MIP_GAP",
2668 &f_tmp))
2669 {
2670 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2561 { 2671 {
2562 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2672 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2563 { 2673 "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 }
2573 } 2674 }
2574 2675 else
2575 mlp->pv.lp_mip_gap = (double)0.0;
2576 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2577 "MLP_MAX_LP_MIP_GAP", &f_tmp))
2578 { 2676 {
2579 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2677 mlp->pv.mip_gap = f_tmp;
2580 { 2678 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2581 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2679 "MIP gap", f_tmp);
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 }
2590 } 2680 }
2681 }
2591 2682
2592 /* Get timeout for iterations */ 2683 mlp->pv.lp_mip_gap = (double) 0.0;
2593 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", 2684 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2594 "MLP_MAX_DURATION", &max_duration)) 2685 "MLP_MAX_LP_MIP_GAP",
2686 &f_tmp))
2687 {
2688 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2595 { 2689 {
2596 max_duration = MLP_MAX_EXEC_DURATION; 2690 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2691 "LP/MIP", f_tmp);
2597 } 2692 }
2598 2693 else
2599 /* Get maximum number of iterations */
2600 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats",
2601 "MLP_MAX_ITERATIONS", &max_iterations))
2602 { 2694 {
2603 max_iterations = MLP_MAX_ITERATIONS; 2695 mlp->pv.lp_mip_gap = f_tmp;
2696 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2697 "LP/MIP", f_tmp);
2604 } 2698 }
2699 }
2700
2701 /* Get timeout for iterations */
2702 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats",
2703 "MLP_MAX_DURATION",
2704 &max_duration))
2705 {
2706 max_duration = MLP_MAX_EXEC_DURATION;
2707 }
2708
2709 /* Get maximum number of iterations */
2710 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2711 "MLP_MAX_ITERATIONS",
2712 &max_iterations))
2713 {
2714 max_iterations = MLP_MAX_ITERATIONS;
2715 }
2605 2716
2606 /* Get diversity coefficient from configuration */ 2717 /* Get diversity coefficient from configuration */
2607 mlp->pv.co_D = MLP_DEFAULT_D; 2718 mlp->pv.co_D = MLP_DEFAULT_D;
2608 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2719 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2609 "MLP_COEFFICIENT_D", &f_tmp)) 2720 "MLP_COEFFICIENT_D",
2721 &f_tmp))
2722 {
2723 if ((f_tmp < 0.0))
2610 { 2724 {
2611 if ((f_tmp < 0.0)) 2725 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2612 { 2726 "MLP_COEFFICIENT_D", f_tmp);
2613 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2727 }
2614 "MLP_COEFFICIENT_D", f_tmp); 2728 else
2615 } 2729 {
2616 else 2730 mlp->pv.co_D = f_tmp;
2617 { 2731 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2618 mlp->pv.co_D = f_tmp; 2732 "MLP_COEFFICIENT_D", f_tmp);
2619 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2620 "MLP_COEFFICIENT_D", f_tmp);
2621 }
2622 } 2733 }
2734 }
2623 2735
2624 /* Get relativity coefficient from configuration */ 2736 /* Get relativity coefficient from configuration */
2625 mlp->pv.co_R = MLP_DEFAULT_R; 2737 mlp->pv.co_R = MLP_DEFAULT_R;
2626 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2738 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2627 "MLP_COEFFICIENT_R", &f_tmp)) 2739 "MLP_COEFFICIENT_R",
2740 &f_tmp))
2741 {
2742 if ((f_tmp < 0.0))
2628 { 2743 {
2629 if ((f_tmp < 0.0)) 2744 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2630 { 2745 "MLP_COEFFICIENT_R", f_tmp);
2631 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2746 }
2632 "MLP_COEFFICIENT_R", f_tmp); 2747 else
2633 } 2748 {
2634 else 2749 mlp->pv.co_R = f_tmp;
2635 { 2750 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2636 mlp->pv.co_R = f_tmp; 2751 "MLP_COEFFICIENT_R", f_tmp);
2637 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2638 "MLP_COEFFICIENT_R", f_tmp);
2639 }
2640 } 2752 }
2753 }
2641 2754
2642 2755
2643 /* Get utilization coefficient from configuration */ 2756 /* Get utilization coefficient from configuration */
2644 mlp->pv.co_U = MLP_DEFAULT_U; 2757 mlp->pv.co_U = MLP_DEFAULT_U;
2645 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2758 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2646 "MLP_COEFFICIENT_U", &f_tmp)) 2759 "MLP_COEFFICIENT_U",
2760 &f_tmp))
2761 {
2762 if ((f_tmp < 0.0))
2647 { 2763 {
2648 if ((f_tmp < 0.0)) 2764 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2649 { 2765 "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 }
2659 } 2766 }
2767 else
2768 {
2769 mlp->pv.co_U = f_tmp;
2770 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s gap of %.3f\n",
2771 "MLP_COEFFICIENT_U", f_tmp);
2772 }
2773 }
2660 2774
2661 /* Get quality metric coefficients from configuration */ 2775 /* Get quality metric coefficients from configuration */
2662 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++) 2776 for (c = 0; c < RQ_QUALITY_METRIC_COUNT; c++)
2663 { 2777 {
2664 /* initialize quality coefficients with default value 1.0 */ 2778 /* initialize quality coefficients with default value 1.0 */
2665 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY; 2779 mlp->pv.co_Q[c] = MLP_DEFAULT_QUALITY;
2666 } 2780 }
2667 2781
2668 2782
2669 if (GNUNET_OK == 2783 if (GNUNET_OK ==
2670 GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", 2784 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2671 "MLP_COEFFICIENT_QUALITY_DELAY", 2785 "MLP_COEFFICIENT_QUALITY_DELAY",
2672 &tmp)) 2786 &tmp))
2673 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double)tmp / 100; 2787 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = (double) tmp / 100;
2674 else 2788 else
2675 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY; 2789 mlp->pv.co_Q[RQ_QUALITY_METRIC_DELAY] = MLP_DEFAULT_QUALITY;
2676 2790
2677 if (GNUNET_OK == 2791 if (GNUNET_OK ==
2678 GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", 2792 GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2679 "MLP_COEFFICIENT_QUALITY_DISTANCE", 2793 "MLP_COEFFICIENT_QUALITY_DISTANCE",
2680 &tmp)) 2794 &tmp))
2681 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double)tmp / 100; 2795 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = (double) tmp / 100;
2682 else 2796 else
2683 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY; 2797 mlp->pv.co_Q[RQ_QUALITY_METRIC_DISTANCE] = MLP_DEFAULT_QUALITY;
2684 2798
2685 /* Get minimum bandwidth per used address from configuration */ 2799 /* Get minimum bandwidth per used address from configuration */
2686 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", 2800 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2687 "MLP_MIN_BANDWIDTH", 2801 "MLP_MIN_BANDWIDTH",
2688 &tmp)) 2802 &tmp))
2689 b_min = tmp; 2803 b_min = tmp;
2690 else 2804 else
2691 { 2805 {
2692 b_min = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 2806 b_min = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
2693 } 2807 }
2694 2808
2695 /* Get minimum number of connections from configuration */ 2809 /* Get minimum number of connections from configuration */
2696 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size(env->cfg, "ats", 2810 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_size (env->cfg, "ats",
2697 "MLP_MIN_CONNECTIONS", 2811 "MLP_MIN_CONNECTIONS",
2698 &tmp)) 2812 &tmp))
2699 n_min = tmp; 2813 n_min = tmp;
2700 else 2814 else
2701 n_min = MLP_DEFAULT_MIN_CONNECTIONS; 2815 n_min = MLP_DEFAULT_MIN_CONNECTIONS;
2702 2816
2703 /* Init network quotas */ 2817 /* Init network quotas */
2704 for (c = 0; c < GNUNET_NT_COUNT; c++) 2818 for (c = 0; c < GNUNET_NT_COUNT; c++)
2705 { 2819 {
2706 mlp->pv.quota_index[c] = c; 2820 mlp->pv.quota_index[c] = c;
2707 mlp->pv.quota_out[c] = env->out_quota[c]; 2821 mlp->pv.quota_out[c] = env->out_quota[c];
2708 mlp->pv.quota_in[c] = env->in_quota[c]; 2822 mlp->pv.quota_in[c] = env->in_quota[c];
2709 2823
2710 LOG(GNUNET_ERROR_TYPE_INFO, 2824 LOG (GNUNET_ERROR_TYPE_INFO,
2711 "Quota for network `%s' (in/out) %llu/%llu\n", 2825 "Quota for network `%s' (in/out) %llu/%llu\n",
2712 GNUNET_NT_to_string(c), 2826 GNUNET_NT_to_string (c),
2713 mlp->pv.quota_out[c], 2827 mlp->pv.quota_out[c],
2714 mlp->pv.quota_in[c]); 2828 mlp->pv.quota_in[c]);
2715 /* Check if defined quota could make problem unsolvable */ 2829 /* Check if defined quota could make problem unsolvable */
2716 if ((n_min * b_min) > mlp->pv.quota_out[c]) 2830 if ((n_min * b_min) > mlp->pv.quota_out[c])
2717 { 2831 {
2718 LOG(GNUNET_ERROR_TYPE_INFO, 2832 LOG (GNUNET_ERROR_TYPE_INFO,
2719 _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), 2833 _ (
2720 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2834 "Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2721 mlp->pv.quota_out[c], 2835 GNUNET_NT_to_string (mlp->pv.quota_index[c]),
2722 (n_min * b_min)); 2836 mlp->pv.quota_out[c],
2723 mlp->pv.quota_out[c] = (n_min * b_min); 2837 (n_min * b_min));
2724 } 2838 mlp->pv.quota_out[c] = (n_min * b_min);
2725 if ((n_min * b_min) > mlp->pv.quota_in[c]) 2839 }
2726 { 2840 if ((n_min * b_min) > mlp->pv.quota_in[c])
2727 LOG(GNUNET_ERROR_TYPE_INFO, 2841 {
2728 _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), 2842 LOG (GNUNET_ERROR_TYPE_INFO,
2729 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2843 _ (
2730 mlp->pv.quota_in[c], 2844 "Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"),
2731 (n_min * b_min)); 2845 GNUNET_NT_to_string (mlp->pv.quota_index[c]),
2732 mlp->pv.quota_in[c] = (n_min * b_min); 2846 mlp->pv.quota_in[c],
2733 } 2847 (n_min * b_min));
2734 /* Check if bandwidth is too big to make problem solvable */ 2848 mlp->pv.quota_in[c] = (n_min * b_min);
2735 if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) 2849 }
2736 { 2850 /* Check if bandwidth is too big to make problem solvable */
2737 LOG(GNUNET_ERROR_TYPE_INFO, 2851 if (mlp->pv.BIG_M < mlp->pv.quota_out[c])
2738 _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), 2852 {
2739 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2853 LOG (GNUNET_ERROR_TYPE_INFO,
2740 mlp->pv.quota_out[c], 2854 _ (
2741 mlp->pv.BIG_M); 2855 "Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"),
2742 mlp->pv.quota_out[c] = mlp->pv.BIG_M; 2856 GNUNET_NT_to_string (mlp->pv.quota_index[c]),
2743 } 2857 mlp->pv.quota_out[c],
2744 if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) 2858 mlp->pv.BIG_M);
2745 { 2859 mlp->pv.quota_out[c] = mlp->pv.BIG_M;
2746 LOG(GNUNET_ERROR_TYPE_INFO, 2860 }
2747 _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), 2861 if (mlp->pv.BIG_M < mlp->pv.quota_in[c])
2748 GNUNET_NT_to_string(mlp->pv.quota_index[c]), 2862 {
2749 mlp->pv.quota_in[c], 2863 LOG (GNUNET_ERROR_TYPE_INFO,
2750 mlp->pv.BIG_M); 2864 _ (
2751 mlp->pv.quota_in[c] = mlp->pv.BIG_M; 2865 "Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"),
2752 } 2866 GNUNET_NT_to_string (mlp->pv.quota_index[c]),
2753 } 2867 mlp->pv.quota_in[c],
2868 mlp->pv.BIG_M);
2869 mlp->pv.quota_in[c] = mlp->pv.BIG_M;
2870 }
2871 }
2754 mlp->env = env; 2872 mlp->env = env;
2755 sf.cls = mlp; 2873 sf.cls = mlp;
2756 sf.s_add = &GAS_mlp_address_add; 2874 sf.s_add = &GAS_mlp_address_add;
@@ -2770,16 +2888,16 @@ libgnunet_plugin_ats_mlp_init(void *cls)
2770 mlp->stat_mlp_prob_changed = GNUNET_NO; 2888 mlp->stat_mlp_prob_changed = GNUNET_NO;
2771 mlp->stat_mlp_prob_updated = GNUNET_NO; 2889 mlp->stat_mlp_prob_updated = GNUNET_NO;
2772 mlp->opt_mlp_auto_solve = GNUNET_YES; 2890 mlp->opt_mlp_auto_solve = GNUNET_YES;
2773 mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 2891 mlp->requested_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
2774 mlp->stat_bulk_requests = 0; 2892 mlp->stat_bulk_requests = 0;
2775 mlp->stat_bulk_lock = 0; 2893 mlp->stat_bulk_lock = 0;
2776 2894
2777 /* Setup GLPK */ 2895 /* Setup GLPK */
2778 /* Redirect GLPK output to GNUnet logging */ 2896 /* Redirect GLPK output to GNUnet logging */
2779 glp_term_hook(&mlp_term_hook, (void *)mlp); 2897 glp_term_hook (&mlp_term_hook, (void *) mlp);
2780 2898
2781 /* Init LP solving parameters */ 2899 /* Init LP solving parameters */
2782 glp_init_smcp(&mlp->control_param_lp); 2900 glp_init_smcp (&mlp->control_param_lp);
2783 mlp->control_param_lp.msg_lev = GLP_MSG_OFF; 2901 mlp->control_param_lp.msg_lev = GLP_MSG_OFF;
2784 if (GNUNET_YES == mlp->opt_dbg_glpk_verbose) 2902 if (GNUNET_YES == mlp->opt_dbg_glpk_verbose)
2785 mlp->control_param_lp.msg_lev = GLP_MSG_ALL; 2903 mlp->control_param_lp.msg_lev = GLP_MSG_ALL;
@@ -2788,7 +2906,7 @@ libgnunet_plugin_ats_mlp_init(void *cls)
2788 mlp->control_param_lp.tm_lim = max_duration.rel_value_us / 1000LL; 2906 mlp->control_param_lp.tm_lim = max_duration.rel_value_us / 1000LL;
2789 2907
2790 /* Init MLP solving parameters */ 2908 /* Init MLP solving parameters */
2791 glp_init_iocp(&mlp->control_param_mlp); 2909 glp_init_iocp (&mlp->control_param_mlp);
2792 /* Setting callback function */ 2910 /* Setting callback function */
2793 mlp->control_param_mlp.cb_func = &mlp_branch_and_cut_cb; 2911 mlp->control_param_mlp.cb_func = &mlp_branch_and_cut_cb;
2794 mlp->control_param_mlp.cb_info = mlp; 2912 mlp->control_param_mlp.cb_info = mlp;
@@ -2798,7 +2916,7 @@ libgnunet_plugin_ats_mlp_init(void *cls)
2798 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL; 2916 mlp->control_param_mlp.msg_lev = GLP_MSG_ALL;
2799 mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL; 2917 mlp->control_param_mlp.tm_lim = max_duration.rel_value_us / 1000LL;
2800 2918
2801 LOG(GNUNET_ERROR_TYPE_DEBUG, "solver ready\n"); 2919 LOG (GNUNET_ERROR_TYPE_DEBUG, "solver ready\n");
2802 2920
2803 return &sf; 2921 return &sf;
2804} 2922}
diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c
index bdb5d6cf0..a1e995013 100644
--- a/src/ats/plugin_ats_proportional.c
+++ b/src/ats/plugin_ats_proportional.c
@@ -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,7 +58,8 @@
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 */
61struct AddressWrapper { 61struct AddressWrapper
62{
62 /** 63 /**
63 * Next in DLL 64 * Next in DLL
64 */ 65 */
@@ -99,7 +100,8 @@ struct AddressWrapper {
99/** 100/**
100 * Representation of a network 101 * Representation of a network
101 */ 102 */
102struct Network { 103struct Network
104{
103 /** 105 /**
104 * Network description 106 * Network description
105 */ 107 */
@@ -155,7 +157,8 @@ struct Network {
155/** 157/**
156 * A handle for the proportional solver 158 * A handle for the proportional solver
157 */ 159 */
158struct GAS_PROPORTIONAL_Handle { 160struct GAS_PROPORTIONAL_Handle
161{
159 /** 162 /**
160 * Our execution environment. 163 * Our execution environment.
161 */ 164 */
@@ -202,13 +205,13 @@ struct GAS_PROPORTIONAL_Handle {
202 * @return #GNUNET_YES or #GNUNET_NO 205 * @return #GNUNET_YES or #GNUNET_NO
203 */ 206 */
204static int 207static int
205is_bandwidth_available_in_network(struct Network *net, 208is_bandwidth_available_in_network (struct Network *net,
206 int extra) 209 int extra)
207{ 210{
208 unsigned int na; 211 unsigned int na;
209 uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 212 uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
210 213
211 GNUNET_assert(((int)net->active_addresses) + extra >= 0); 214 GNUNET_assert (((int) net->active_addresses) + extra >= 0);
212 na = net->active_addresses + extra; 215 na = net->active_addresses + extra;
213 if (0 == na) 216 if (0 == na)
214 return GNUNET_YES; 217 return GNUNET_YES;
@@ -229,16 +232,16 @@ is_bandwidth_available_in_network(struct Network *net,
229 * @return #GNUNET_YES or #GNUNET_NO 232 * @return #GNUNET_YES or #GNUNET_NO
230 */ 233 */
231static int 234static int
232all_require_connectivity(struct GAS_PROPORTIONAL_Handle *s, 235all_require_connectivity (struct GAS_PROPORTIONAL_Handle *s,
233 struct Network *net, 236 struct Network *net,
234 unsigned int con) 237 unsigned int con)
235{ 238{
236 struct AddressWrapper *aw; 239 struct AddressWrapper *aw;
237 240
238 for (aw = net->head; NULL != aw; aw = aw->next) 241 for (aw = net->head; NULL != aw; aw = aw->next)
239 if (con > 242 if (con >
240 s->env->get_connectivity(s->env->cls, 243 s->env->get_connectivity (s->env->cls,
241 &aw->addr->peer)) 244 &aw->addr->peer))
242 return GNUNET_NO; 245 return GNUNET_NO;
243 return GNUNET_YES; 246 return GNUNET_YES;
244} 247}
@@ -254,10 +257,10 @@ all_require_connectivity(struct GAS_PROPORTIONAL_Handle *s,
254 * @param net the network type to update 257 * @param net the network type to update
255 */ 258 */
256static void 259static void
257distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s, 260distribute_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
258 struct Network *net) 261 struct Network *net)
259{ 262{
260 const uint32_t min_bw = ntohl(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); 263 const uint32_t min_bw = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__);
261 struct AddressWrapper *aw; 264 struct AddressWrapper *aw;
262 unsigned long long remaining_quota_in; 265 unsigned long long remaining_quota_in;
263 unsigned long long quota_out_used; 266 unsigned long long quota_out_used;
@@ -269,110 +272,113 @@ distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s,
269 double total_weight; 272 double total_weight;
270 const double *peer_relative_prefs; 273 const double *peer_relative_prefs;
271 274
272 LOG(GNUNET_ERROR_TYPE_INFO, 275 LOG (GNUNET_ERROR_TYPE_INFO,
273 "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n", 276 "Recalculate quota for network type `%s' for %u addresses (in/out): %llu/%llu \n",
274 net->desc, 277 net->desc,
275 net->active_addresses, 278 net->active_addresses,
276 net->total_quota_in, 279 net->total_quota_in,
277 net->total_quota_in); 280 net->total_quota_in);
278 281
279 if (0 == net->active_addresses) 282 if (0 == net->active_addresses)
280 return; /* no addresses to update */ 283 return; /* no addresses to update */
281 284
282 /* sanity checks */ 285 /* sanity checks */
283 if ((net->active_addresses * min_bw) > net->total_quota_in) 286 if ((net->active_addresses * min_bw) > net->total_quota_in)
284 { 287 {
285 GNUNET_break(0); 288 GNUNET_break (0);
286 return; 289 return;
287 } 290 }
288 if ((net->active_addresses * min_bw) > net->total_quota_out) 291 if ((net->active_addresses * min_bw) > net->total_quota_out)
289 { 292 {
290 GNUNET_break(0); 293 GNUNET_break (0);
291 return; 294 return;
292 } 295 }
293 296
294 /* Calculate sum of relative preference for active addresses in this 297 /* Calculate sum of relative preference for active addresses in this
295 network */ 298 network */
296 sum_relative_peer_prefences = 0.0; 299 sum_relative_peer_prefences = 0.0;
297 count_addresses = 0; 300 count_addresses = 0;
298 for (aw = net->head; NULL != aw; aw = aw->next) 301 for (aw = net->head; NULL != aw; aw = aw->next)
299 { 302 {
300 if (GNUNET_YES != aw->addr->active) 303 if (GNUNET_YES != aw->addr->active)
301 continue; 304 continue;
302 peer_relative_prefs = s->env->get_preferences(s->env->cls, 305 peer_relative_prefs = s->env->get_preferences (s->env->cls,
303 &aw->addr->peer); 306 &aw->addr->peer);
304 sum_relative_peer_prefences 307 sum_relative_peer_prefences
305 += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH]; 308 += peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
306 count_addresses++; 309 count_addresses++;
307 } 310 }
308 if (count_addresses != net->active_addresses) 311 if (count_addresses != net->active_addresses)
309 { 312 {
310 GNUNET_break(0); 313 GNUNET_break (0);
311 LOG(GNUNET_ERROR_TYPE_WARNING, 314 LOG (GNUNET_ERROR_TYPE_WARNING,
312 "%s: Counted %u active addresses, expected %u active addresses\n", 315 "%s: Counted %u active addresses, expected %u active addresses\n",
313 net->desc, 316 net->desc,
314 count_addresses, 317 count_addresses,
315 net->active_addresses); 318 net->active_addresses);
316 /* try to fix... */ 319 /* try to fix... */
317 net->active_addresses = count_addresses; 320 net->active_addresses = count_addresses;
318 } 321 }
319 LOG(GNUNET_ERROR_TYPE_INFO, 322 LOG (GNUNET_ERROR_TYPE_INFO,
320 "Total relative preference %.3f for %u addresses in network %s\n", 323 "Total relative preference %.3f for %u addresses in network %s\n",
321 sum_relative_peer_prefences, 324 sum_relative_peer_prefences,
322 net->active_addresses, 325 net->active_addresses,
323 net->desc); 326 net->desc);
324 327
325 /* check how much we have to distribute */ 328 /* check how much we have to distribute */
326 remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw); 329 remaining_quota_in = net->total_quota_in - (net->active_addresses * min_bw);
327 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw); 330 remaining_quota_out = net->total_quota_out - (net->active_addresses * min_bw);
328 LOG(GNUNET_ERROR_TYPE_DEBUG, 331 LOG (GNUNET_ERROR_TYPE_DEBUG,
329 "Proportionally distributable bandwidth (in/out): %llu/%llu\n", 332 "Proportionally distributable bandwidth (in/out): %llu/%llu\n",
330 remaining_quota_in, 333 remaining_quota_in,
331 remaining_quota_out); 334 remaining_quota_out);
332 335
333 /* distribute remaining quota; we do not do it exactly proportional, 336 /* distribute remaining quota; we do not do it exactly proportional,
334 but balance "even" distribution ("net->active_addresses") with 337 but balance "even" distribution ("net->active_addresses") with
335 the preference sum using the "prop_factor". */ 338 the preference sum using the "prop_factor". */
336 total_weight = net->active_addresses + 339 total_weight = net->active_addresses
337 s->prop_factor * sum_relative_peer_prefences; 340 + s->prop_factor * sum_relative_peer_prefences;
338 quota_out_used = 0; 341 quota_out_used = 0;
339 quota_in_used = 0; 342 quota_in_used = 0;
340 for (aw = net->head; NULL != aw; aw = aw->next) 343 for (aw = net->head; NULL != aw; aw = aw->next)
344 {
345 if (GNUNET_YES != aw->addr->active)
341 { 346 {
342 if (GNUNET_YES != aw->addr->active) 347 /* set to 0, just to be sure */
343 { 348 aw->calculated_quota_in = 0;
344 /* set to 0, just to be sure */ 349 aw->calculated_quota_out = 0;
345 aw->calculated_quota_in = 0; 350 continue;
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;
368 } 351 }
369 LOG(GNUNET_ERROR_TYPE_DEBUG, 352 peer_relative_prefs = s->env->get_preferences (s->env->cls,
370 "Total bandwidth assigned is (in/out): %llu /%llu\n", 353 &aw->addr->peer);
371 quota_in_used, 354 peer_weight = 1.0
372 quota_out_used); 355 + s->prop_factor
356 * peer_relative_prefs[GNUNET_ATS_PREFERENCE_BANDWIDTH];
357
358 aw->calculated_quota_in = min_bw
359 + (peer_weight / total_weight)
360 * remaining_quota_in;
361 aw->calculated_quota_out = min_bw
362 + (peer_weight / total_weight)
363 * remaining_quota_out;
364
365 LOG (GNUNET_ERROR_TYPE_INFO,
366 "New quotas for peer `%s' with weight (cur/total) %.3f/%.3f (in/out) are: %u/%u\n",
367 GNUNET_i2s (&aw->addr->peer),
368 peer_weight,
369 total_weight,
370 (unsigned int) aw->calculated_quota_in,
371 (unsigned int) aw->calculated_quota_out);
372 quota_in_used += aw->calculated_quota_in;
373 quota_out_used += aw->calculated_quota_out;
374 }
375 LOG (GNUNET_ERROR_TYPE_DEBUG,
376 "Total bandwidth assigned is (in/out): %llu /%llu\n",
377 quota_in_used,
378 quota_out_used);
373 /* +1 due to possible rounding errors */ 379 /* +1 due to possible rounding errors */
374 GNUNET_break(quota_out_used <= net->total_quota_out + 1); 380 GNUNET_break (quota_out_used <= net->total_quota_out + 1);
375 GNUNET_break(quota_in_used <= net->total_quota_in + 1); 381 GNUNET_break (quota_in_used <= net->total_quota_in + 1);
376} 382}
377 383
378 384
@@ -383,22 +389,22 @@ distribute_bandwidth(struct GAS_PROPORTIONAL_Handle *s,
383 * @param net the network to propagate changes in 389 * @param net the network to propagate changes in
384 */ 390 */
385static void 391static void
386propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s, 392propagate_bandwidth (struct GAS_PROPORTIONAL_Handle *s,
387 struct Network *net) 393 struct Network *net)
388{ 394{
389 struct AddressWrapper *cur; 395 struct AddressWrapper *cur;
390 396
391 for (cur = net->head; NULL != cur; cur = cur->next) 397 for (cur = net->head; NULL != cur; cur = cur->next)
392 { 398 {
393 if ((cur->addr->assigned_bw_in == cur->calculated_quota_in) && 399 if ((cur->addr->assigned_bw_in == cur->calculated_quota_in) &&
394 (cur->addr->assigned_bw_out == cur->calculated_quota_out)) 400 (cur->addr->assigned_bw_out == cur->calculated_quota_out))
395 continue; 401 continue;
396 cur->addr->assigned_bw_in = cur->calculated_quota_in; 402 cur->addr->assigned_bw_in = cur->calculated_quota_in;
397 cur->addr->assigned_bw_out = cur->calculated_quota_out; 403 cur->addr->assigned_bw_out = cur->calculated_quota_out;
398 if (GNUNET_YES == cur->addr->active) 404 if (GNUNET_YES == cur->addr->active)
399 s->env->bandwidth_changed_cb(s->env->cls, 405 s->env->bandwidth_changed_cb (s->env->cls,
400 cur->addr); 406 cur->addr);
401 } 407 }
402} 408}
403 409
404 410
@@ -410,80 +416,81 @@ propagate_bandwidth(struct GAS_PROPORTIONAL_Handle *s,
410 * @param n the network, can be NULL for all networks 416 * @param n the network, can be NULL for all networks
411 */ 417 */
412static void 418static void
413distribute_bandwidth_in_network(struct GAS_PROPORTIONAL_Handle *s, 419distribute_bandwidth_in_network (struct GAS_PROPORTIONAL_Handle *s,
414 struct Network *n) 420 struct Network *n)
415{ 421{
416 unsigned int i; 422 unsigned int i;
417 423
418 if (0 != s->bulk_lock) 424 if (0 != s->bulk_lock)
419 { 425 {
420 s->bulk_requests++; 426 s->bulk_requests++;
421 return; 427 return;
422 } 428 }
423 if (NULL != n) 429 if (NULL != n)
424 { 430 {
425 LOG(GNUNET_ERROR_TYPE_DEBUG, 431 LOG (GNUNET_ERROR_TYPE_DEBUG,
426 "Redistributing bandwidth in network %s with %u active and %u total addresses\n", 432 "Redistributing bandwidth in network %s with %u active and %u total addresses\n",
427 GNUNET_NT_to_string(n->type), 433 GNUNET_NT_to_string (n->type),
428 n->active_addresses, 434 n->active_addresses,
429 n->total_addresses); 435 n->total_addresses);
430 s->env->info_cb(s->env->cls, 436 s->env->info_cb (s->env->cls,
431 GAS_OP_SOLVE_START, 437 GAS_OP_SOLVE_START,
432 GAS_STAT_SUCCESS, 438 GAS_STAT_SUCCESS,
433 GAS_INFO_PROP_SINGLE); 439 GAS_INFO_PROP_SINGLE);
434 distribute_bandwidth(s, 440 distribute_bandwidth (s,
435 n);
436 s->env->info_cb(s->env->cls,
437 GAS_OP_SOLVE_STOP,
438 GAS_STAT_SUCCESS,
439 GAS_INFO_PROP_SINGLE);
440 s->env->info_cb(s->env->cls,
441 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
442 GAS_STAT_SUCCESS,
443 GAS_INFO_PROP_SINGLE);
444 propagate_bandwidth(s,
445 n); 441 n);
446 442 s->env->info_cb (s->env->cls,
447 s->env->info_cb(s->env->cls, 443 GAS_OP_SOLVE_STOP,
448 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 444 GAS_STAT_SUCCESS,
449 GAS_STAT_SUCCESS, 445 GAS_INFO_PROP_SINGLE);
450 GAS_INFO_PROP_SINGLE); 446 s->env->info_cb (s->env->cls,
451 } 447 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
448 GAS_STAT_SUCCESS,
449 GAS_INFO_PROP_SINGLE);
450 propagate_bandwidth (s,
451 n);
452
453 s->env->info_cb (s->env->cls,
454 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
455 GAS_STAT_SUCCESS,
456 GAS_INFO_PROP_SINGLE);
457 }
452 else 458 else
453 { 459 {
454 LOG(GNUNET_ERROR_TYPE_DEBUG, 460 LOG (GNUNET_ERROR_TYPE_DEBUG,
455 "Redistributing bandwidth in all %u networks\n", 461 "Redistributing bandwidth in all %u networks\n",
456 s->env->network_count); 462 s->env->network_count);
457 s->env->info_cb(s->env->cls, 463 s->env->info_cb (s->env->cls,
458 GAS_OP_SOLVE_START, 464 GAS_OP_SOLVE_START,
459 GAS_STAT_SUCCESS, 465 GAS_STAT_SUCCESS,
460 GAS_INFO_PROP_ALL); 466 GAS_INFO_PROP_ALL);
461 for (i = 0; i < s->env->network_count; i++) 467 for (i = 0; i < s->env->network_count; i++)
462 distribute_bandwidth(s, 468 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,
474 &s->network_entries[i]); 469 &s->network_entries[i]);
475 s->env->info_cb(s->env->cls, 470 s->env->info_cb (s->env->cls,
476 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, 471 GAS_OP_SOLVE_STOP,
477 GAS_STAT_SUCCESS, 472 GAS_STAT_SUCCESS,
478 GAS_INFO_PROP_ALL); 473 GAS_INFO_PROP_ALL);
479 } 474 s->env->info_cb (s->env->cls,
475 GAS_OP_SOLVE_UPDATE_NOTIFICATION_START,
476 GAS_STAT_SUCCESS,
477 GAS_INFO_PROP_ALL);
478 for (i = 0; i < s->env->network_count; i++)
479 propagate_bandwidth (s,
480 &s->network_entries[i]);
481 s->env->info_cb (s->env->cls,
482 GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP,
483 GAS_STAT_SUCCESS,
484 GAS_INFO_PROP_ALL);
485 }
480} 486}
481 487
482 488
483/** 489/**
484 * Context for finding the best address* Linked list of addresses in this network: head 490 * Context for finding the best address* Linked list of addresses in this network: head
485 */ 491 */
486struct FindBestAddressCtx { 492struct FindBestAddressCtx
493{
487 /** 494 /**
488 * The solver handle 495 * The solver handle
489 */ 496 */
@@ -508,9 +515,9 @@ struct FindBestAddressCtx {
508 * @return #GNUNET_OK (continue to iterate) 515 * @return #GNUNET_OK (continue to iterate)
509 */ 516 */
510static int 517static int
511find_best_address_it(void *cls, 518find_best_address_it (void *cls,
512 const struct GNUNET_PeerIdentity *key, 519 const struct GNUNET_PeerIdentity *key,
513 void *value) 520 void *value)
514{ 521{
515 struct FindBestAddressCtx *ctx = cls; 522 struct FindBestAddressCtx *ctx = cls;
516 struct ATS_Address *current = value; 523 struct ATS_Address *current = value;
@@ -530,46 +537,47 @@ find_best_address_it(void *cls,
530 to the same network (as we would replace it) */ 537 to the same network (as we would replace it) */
531 if ((NULL != ctx->best) && 538 if ((NULL != ctx->best) &&
532 (GNUNET_YES == ctx->best->active) && 539 (GNUNET_YES == ctx->best->active) &&
533 (((struct AddressWrapper *)ctx->best->solver_information)->network == 540 (((struct AddressWrapper *) ctx->best->solver_information)->network ==
534 asi->network)) 541 asi->network))
535 need--; 542 need--;
536 /* we can gain -1 slot if this peers connectivity 543 /* we can gain -1 slot if this peers connectivity
537 requirement is higher than that of another peer 544 requirement is higher than that of another peer
538 in that network scope */ 545 in that network scope */
539 con = ctx->s->env->get_connectivity(ctx->s->env->cls, 546 con = ctx->s->env->get_connectivity (ctx->s->env->cls,
540 key); 547 key);
541 if (GNUNET_YES != 548 if (GNUNET_YES !=
542 all_require_connectivity(ctx->s, 549 all_require_connectivity (ctx->s,
543 asi->network, 550 asi->network,
544 con)) 551 con))
545 need--; 552 need--;
546 /* test if minimum bandwidth for 'current' would be available */ 553 /* test if minimum bandwidth for 'current' would be available */
547 bw_available 554 bw_available
548 = is_bandwidth_available_in_network(asi->network, 555 = is_bandwidth_available_in_network (asi->network,
549 need); 556 need);
550 if (!bw_available) 557 if (! bw_available)
551 { 558 {
552 /* Bandwidth for this address is unavailable, so we cannot use 559 /* Bandwidth for this address is unavailable, so we cannot use
553 it. */ 560 it. */
554 return GNUNET_OK; 561 return GNUNET_OK;
555 } 562 }
556 if (GNUNET_YES == current->active) 563 if (GNUNET_YES == current->active)
564 {
565 active_time = GNUNET_TIME_absolute_get_duration (asi->activated);
566 if (active_time.rel_value_us <=
567 ((double) GNUNET_TIME_UNIT_SECONDS.rel_value_us)
568 * ctx->s->stability_factor)
557 { 569 {
558 active_time = GNUNET_TIME_absolute_get_duration(asi->activated); 570 /* Keep active address for stability reasons */
559 if (active_time.rel_value_us <=
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 }
566 }
567 if (NULL == ctx->best)
568 {
569 /* We so far have nothing else, so go with it! */
570 ctx->best = current; 571 ctx->best = current;
571 return GNUNET_OK; 572 return GNUNET_NO;
572 } 573 }
574 }
575 if (NULL == ctx->best)
576 {
577 /* We so far have nothing else, so go with it! */
578 ctx->best = current;
579 return GNUNET_OK;
580 }
573 581
574 /* Now compare ATS information */ 582 /* Now compare ATS information */
575 cur_distance = current->norm_distance.norm; 583 cur_distance = current->norm_distance.norm;
@@ -579,33 +587,33 @@ find_best_address_it(void *cls,
579 587
580 /* user shorter distance */ 588 /* user shorter distance */
581 if (cur_distance < best_distance) 589 if (cur_distance < best_distance)
590 {
591 if (GNUNET_NO == ctx->best->active)
582 { 592 {
583 if (GNUNET_NO == ctx->best->active) 593 /* Activity doesn't influence the equation, use current */
584 { 594 ctx->best = current;
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 }
593 } 595 }
596 else if ((best_distance / cur_distance) > ctx->s->stability_factor)
597 {
598 /* Distance change is significant, switch active address! */
599 ctx->best = current;
600 }
601 }
594 602
595 /* User connection with less delay */ 603 /* User connection with less delay */
596 if (cur_delay < best_delay) 604 if (cur_delay < best_delay)
605 {
606 if (GNUNET_NO == ctx->best->active)
607 {
608 /* Activity doesn't influence the equation, use current */
609 ctx->best = current;
610 }
611 else if ((best_delay / cur_delay) > ctx->s->stability_factor)
597 { 612 {
598 if (GNUNET_NO == ctx->best->active) 613 /* Latency change is significant, switch active address! */
599 { 614 ctx->best = current;
600 /* Activity doesn't influence the equation, use current */
601 ctx->best = current;
602 }
603 else if ((best_delay / cur_delay) > ctx->s->stability_factor)
604 {
605 /* Latency change is significant, switch active address! */
606 ctx->best = current;
607 }
608 } 615 }
616 }
609 return GNUNET_OK; 617 return GNUNET_OK;
610} 618}
611 619
@@ -620,18 +628,18 @@ find_best_address_it(void *cls,
620 * @return the address or NULL 628 * @return the address or NULL
621 */ 629 */
622struct ATS_Address * 630struct ATS_Address *
623get_best_address(struct GAS_PROPORTIONAL_Handle *s, 631get_best_address (struct GAS_PROPORTIONAL_Handle *s,
624 struct GNUNET_CONTAINER_MultiPeerMap *addresses, 632 struct GNUNET_CONTAINER_MultiPeerMap *addresses,
625 const struct GNUNET_PeerIdentity *id) 633 const struct GNUNET_PeerIdentity *id)
626{ 634{
627 struct FindBestAddressCtx fba_ctx; 635 struct FindBestAddressCtx fba_ctx;
628 636
629 fba_ctx.best = NULL; 637 fba_ctx.best = NULL;
630 fba_ctx.s = s; 638 fba_ctx.s = s;
631 GNUNET_CONTAINER_multipeermap_get_multiple(addresses, 639 GNUNET_CONTAINER_multipeermap_get_multiple (addresses,
632 id, 640 id,
633 &find_best_address_it, 641 &find_best_address_it,
634 &fba_ctx); 642 &fba_ctx);
635 return fba_ctx.best; 643 return fba_ctx.best;
636} 644}
637 645
@@ -643,21 +651,21 @@ get_best_address(struct GAS_PROPORTIONAL_Handle *s,
643 * @param net the network type 651 * @param net the network type
644 */ 652 */
645static void 653static void
646address_decrement_active(struct GAS_PROPORTIONAL_Handle *s, 654address_decrement_active (struct GAS_PROPORTIONAL_Handle *s,
647 struct Network *net) 655 struct Network *net)
648{ 656{
649 GNUNET_assert(net->active_addresses > 0); 657 GNUNET_assert (net->active_addresses > 0);
650 net->active_addresses--; 658 net->active_addresses--;
651 GNUNET_STATISTICS_update(s->env->stats, 659 GNUNET_STATISTICS_update (s->env->stats,
652 net->stat_active, 660 net->stat_active,
653 -1, 661 -1,
654 GNUNET_NO); 662 GNUNET_NO);
655 GNUNET_assert(s->active_addresses > 0); 663 GNUNET_assert (s->active_addresses > 0);
656 s->active_addresses--; 664 s->active_addresses--;
657 GNUNET_STATISTICS_update(s->env->stats, 665 GNUNET_STATISTICS_update (s->env->stats,
658 "# ATS addresses total", 666 "# ATS addresses total",
659 -1, 667 -1,
660 GNUNET_NO); 668 GNUNET_NO);
661} 669}
662 670
663 671
@@ -671,16 +679,16 @@ address_decrement_active(struct GAS_PROPORTIONAL_Handle *s,
671 * @return #GNUNET_NO on double active address else #GNUNET_YES; 679 * @return #GNUNET_NO on double active address else #GNUNET_YES;
672 */ 680 */
673static int 681static int
674get_active_address_it(void *cls, 682get_active_address_it (void *cls,
675 const struct GNUNET_PeerIdentity *key, 683 const struct GNUNET_PeerIdentity *key,
676 void *value) 684 void *value)
677{ 685{
678 struct ATS_Address **dest = cls; 686 struct ATS_Address **dest = cls;
679 struct ATS_Address *aa = value; 687 struct ATS_Address *aa = value;
680 688
681 if (GNUNET_YES != aa->active) 689 if (GNUNET_YES != aa->active)
682 return GNUNET_OK; 690 return GNUNET_OK;
683 GNUNET_assert(NULL == (*dest)); 691 GNUNET_assert (NULL == (*dest));
684 (*dest) = aa; 692 (*dest) = aa;
685 return GNUNET_OK; 693 return GNUNET_OK;
686} 694}
@@ -694,16 +702,16 @@ get_active_address_it(void *cls,
694 * @return active address or NULL 702 * @return active address or NULL
695 */ 703 */
696static struct ATS_Address * 704static struct ATS_Address *
697get_active_address(struct GAS_PROPORTIONAL_Handle *s, 705get_active_address (struct GAS_PROPORTIONAL_Handle *s,
698 const struct GNUNET_PeerIdentity *peer) 706 const struct GNUNET_PeerIdentity *peer)
699{ 707{
700 struct ATS_Address *dest; 708 struct ATS_Address *dest;
701 709
702 dest = NULL; 710 dest = NULL;
703 GNUNET_CONTAINER_multipeermap_get_multiple(s->env->addresses, 711 GNUNET_CONTAINER_multipeermap_get_multiple (s->env->addresses,
704 peer, 712 peer,
705 &get_active_address_it, 713 &get_active_address_it,
706 &dest); 714 &dest);
707 return dest; 715 return dest;
708} 716}
709 717
@@ -719,9 +727,9 @@ get_active_address(struct GAS_PROPORTIONAL_Handle *s,
719 * @param peer the peer to check 727 * @param peer the peer to check
720 */ 728 */
721static void 729static void
722update_active_address(struct GAS_PROPORTIONAL_Handle *s, 730update_active_address (struct GAS_PROPORTIONAL_Handle *s,
723 struct ATS_Address *current_address, 731 struct ATS_Address *current_address,
724 const struct GNUNET_PeerIdentity *peer) 732 const struct GNUNET_PeerIdentity *peer)
725{ 733{
726 struct ATS_Address *best_address; 734 struct ATS_Address *best_address;
727 struct AddressWrapper *asi_cur; 735 struct AddressWrapper *asi_cur;
@@ -731,9 +739,9 @@ update_active_address(struct GAS_PROPORTIONAL_Handle *s,
731 unsigned int a_con; 739 unsigned int a_con;
732 unsigned int con_min; 740 unsigned int con_min;
733 741
734 best_address = get_best_address(s, 742 best_address = get_best_address (s,
735 s->env->addresses, 743 s->env->addresses,
736 peer); 744 peer);
737 if (NULL != best_address) 745 if (NULL != best_address)
738 asi_best = best_address->solver_information; 746 asi_best = best_address->solver_information;
739 else 747 else
@@ -741,98 +749,98 @@ update_active_address(struct GAS_PROPORTIONAL_Handle *s,
741 if (current_address == best_address) 749 if (current_address == best_address)
742 return; /* no changes */ 750 return; /* no changes */
743 if (NULL != current_address) 751 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)
744 { 771 {
745 /* We switch to a new address (or to none); 772 /* We previously had an active address, but now we cannot
746 mark old address as inactive. */ 773 * suggest one. Therefore we have to disconnect the peer.
747 asi_cur = current_address->solver_information; 774 * The above call to "distribute_bandwidth_in_network()
748 GNUNET_assert(GNUNET_YES == current_address->active); 775 * does not see 'current_address' so we need to trigger
749 LOG(GNUNET_ERROR_TYPE_INFO, 776 * the update here. */
750 "Disabling previous active address for peer `%s'\n", 777 LOG (GNUNET_ERROR_TYPE_DEBUG,
751 GNUNET_i2s(peer)); 778 "Disconnecting peer `%s'.\n",
752 asi_cur->activated = GNUNET_TIME_UNIT_ZERO_ABS; 779 GNUNET_i2s (peer));
753 current_address->active = GNUNET_NO; 780 s->env->bandwidth_changed_cb (s->env->cls,
754 current_address->assigned_bw_in = 0; 781 current_address);
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 }
776 }
777 if (NULL == best_address)
778 {
779 /* We do not have a new address, so we are done. */
780 LOG(GNUNET_ERROR_TYPE_DEBUG,
781 "Cannot suggest address for peer `%s'\n",
782 GNUNET_i2s(peer));
783 return; 782 return;
784 } 783 }
784 }
785 if (NULL == best_address)
786 {
787 /* We do not have a new address, so we are done. */
788 LOG (GNUNET_ERROR_TYPE_DEBUG,
789 "Cannot suggest address for peer `%s'\n",
790 GNUNET_i2s (peer));
791 return;
792 }
785 /* We do have a new address, activate it */ 793 /* We do have a new address, activate it */
786 LOG(GNUNET_ERROR_TYPE_DEBUG, 794 LOG (GNUNET_ERROR_TYPE_DEBUG,
787 "Selecting new address %p for peer `%s'\n", 795 "Selecting new address %p for peer `%s'\n",
788 best_address, 796 best_address,
789 GNUNET_i2s(peer)); 797 GNUNET_i2s (peer));
790 /* Mark address as active */ 798 /* Mark address as active */
791 best_address->active = GNUNET_YES; 799 best_address->active = GNUNET_YES;
792 asi_best->activated = GNUNET_TIME_absolute_get(); 800 asi_best->activated = GNUNET_TIME_absolute_get ();
793 asi_best->network->active_addresses++; 801 asi_best->network->active_addresses++;
794 s->active_addresses++; 802 s->active_addresses++;
795 GNUNET_STATISTICS_update(s->env->stats, 803 GNUNET_STATISTICS_update (s->env->stats,
796 "# ATS active addresses total", 804 "# ATS active addresses total",
797 1, 805 1,
798 GNUNET_NO); 806 GNUNET_NO);
799 GNUNET_STATISTICS_update(s->env->stats, 807 GNUNET_STATISTICS_update (s->env->stats,
800 asi_best->network->stat_active, 808 asi_best->network->stat_active,
801 1, 809 1,
802 GNUNET_NO); 810 GNUNET_NO);
803 LOG(GNUNET_ERROR_TYPE_INFO, 811 LOG (GNUNET_ERROR_TYPE_INFO,
804 "Address %p for peer `%s' is now active\n", 812 "Address %p for peer `%s' is now active\n",
805 best_address, 813 best_address,
806 GNUNET_i2s(peer)); 814 GNUNET_i2s (peer));
807 815
808 if (GNUNET_NO == 816 if (GNUNET_NO ==
809 is_bandwidth_available_in_network(asi_best->network, 817 is_bandwidth_available_in_network (asi_best->network,
810 0)) 818 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)
811 { 826 {
812 /* we went over the maximum number of addresses for 827 if ((con_min >
813 this scope; remove the address with the smallest 828 (a_con = s->env->get_connectivity (s->env->cls,
814 connectivity requirement */ 829 &aw->addr->peer))) &&
815 con_min = UINT32_MAX; 830 (GNUNET_YES == aw->addr->active))
816 aw_min = NULL; 831 {
817 for (aw = asi_best->network->head; NULL != aw; aw = aw->next) 832 aw_min = aw;
818 { 833 con_min = a_con;
819 if ((con_min > 834 if (0 == con_min)
820 (a_con = s->env->get_connectivity(s->env->cls, 835 break;
821 &aw->addr->peer))) && 836 }
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);
833 } 837 }
834 distribute_bandwidth_in_network(s, 838 update_active_address (s,
835 asi_best->network); 839 aw_min->addr,
840 &aw_min->addr->peer);
841 }
842 distribute_bandwidth_in_network (s,
843 asi_best->network);
836} 844}
837 845
838 846
@@ -845,17 +853,17 @@ update_active_address(struct GAS_PROPORTIONAL_Handle *s,
845 * @param pref_rel the normalized preference value for this kind over all clients 853 * @param pref_rel the normalized preference value for this kind over all clients
846 */ 854 */
847static void 855static void
848GAS_proportional_change_preference(void *solver, 856GAS_proportional_change_preference (void *solver,
849 const struct GNUNET_PeerIdentity *peer, 857 const struct GNUNET_PeerIdentity *peer,
850 enum GNUNET_ATS_PreferenceKind kind, 858 enum GNUNET_ATS_PreferenceKind kind,
851 double pref_rel) 859 double pref_rel)
852{ 860{
853 struct GAS_PROPORTIONAL_Handle *s = solver; 861 struct GAS_PROPORTIONAL_Handle *s = solver;
854 862
855 if (GNUNET_ATS_PREFERENCE_BANDWIDTH != kind) 863 if (GNUNET_ATS_PREFERENCE_BANDWIDTH != kind)
856 return; /* we do not care */ 864 return; /* we do not care */
857 distribute_bandwidth_in_network(s, 865 distribute_bandwidth_in_network (s,
858 NULL); 866 NULL);
859} 867}
860 868
861 869
@@ -870,12 +878,12 @@ GAS_proportional_change_preference(void *solver,
870 * @param score the score 878 * @param score the score
871 */ 879 */
872static void 880static void
873GAS_proportional_feedback(void *solver, 881GAS_proportional_feedback (void *solver,
874 struct GNUNET_SERVICE_Client *application, 882 struct GNUNET_SERVICE_Client *application,
875 const struct GNUNET_PeerIdentity *peer, 883 const struct GNUNET_PeerIdentity *peer,
876 const struct GNUNET_TIME_Relative scope, 884 const struct GNUNET_TIME_Relative scope,
877 enum GNUNET_ATS_PreferenceKind kind, 885 enum GNUNET_ATS_PreferenceKind kind,
878 double score) 886 double score)
879{ 887{
880 /* Proportional does not care about feedback */ 888 /* Proportional does not care about feedback */
881} 889}
@@ -888,15 +896,15 @@ GAS_proportional_feedback(void *solver,
888 * @param peer the identity of the peer 896 * @param peer the identity of the peer
889 */ 897 */
890static void 898static void
891GAS_proportional_start_get_address(void *solver, 899GAS_proportional_start_get_address (void *solver,
892 const struct GNUNET_PeerIdentity *peer) 900 const struct GNUNET_PeerIdentity *peer)
893{ 901{
894 struct GAS_PROPORTIONAL_Handle *s = solver; 902 struct GAS_PROPORTIONAL_Handle *s = solver;
895 903
896 update_active_address(s, 904 update_active_address (s,
897 get_active_address(s, 905 get_active_address (s,
898 peer), 906 peer),
899 peer); 907 peer);
900} 908}
901 909
902 910
@@ -907,20 +915,20 @@ GAS_proportional_start_get_address(void *solver,
907 * @param peer the peer 915 * @param peer the peer
908 */ 916 */
909static void 917static void
910GAS_proportional_stop_get_address(void *solver, 918GAS_proportional_stop_get_address (void *solver,
911 const struct GNUNET_PeerIdentity *peer) 919 const struct GNUNET_PeerIdentity *peer)
912{ 920{
913 struct GAS_PROPORTIONAL_Handle *s = solver; 921 struct GAS_PROPORTIONAL_Handle *s = solver;
914 struct ATS_Address *cur; 922 struct ATS_Address *cur;
915 struct AddressWrapper *asi; 923 struct AddressWrapper *asi;
916 924
917 cur = get_active_address(s, 925 cur = get_active_address (s,
918 peer); 926 peer);
919 if (NULL == cur) 927 if (NULL == cur)
920 return; 928 return;
921 asi = cur->solver_information; 929 asi = cur->solver_information;
922 distribute_bandwidth_in_network(s, 930 distribute_bandwidth_in_network (s,
923 asi->network); 931 asi->network);
924} 932}
925 933
926 934
@@ -930,13 +938,13 @@ GAS_proportional_stop_get_address(void *solver,
930 * @param solver the solver 938 * @param solver the solver
931 */ 939 */
932static void 940static void
933GAS_proportional_bulk_start(void *solver) 941GAS_proportional_bulk_start (void *solver)
934{ 942{
935 struct GAS_PROPORTIONAL_Handle *s = solver; 943 struct GAS_PROPORTIONAL_Handle *s = solver;
936 944
937 LOG(GNUNET_ERROR_TYPE_DEBUG, 945 LOG (GNUNET_ERROR_TYPE_DEBUG,
938 "Locking solver for bulk operation ...\n"); 946 "Locking solver for bulk operation ...\n");
939 GNUNET_assert(NULL != solver); 947 GNUNET_assert (NULL != solver);
940 s->bulk_lock++; 948 s->bulk_lock++;
941} 949}
942 950
@@ -947,27 +955,27 @@ GAS_proportional_bulk_start(void *solver)
947 * @param solver our `struct GAS_PROPORTIONAL_Handle *` 955 * @param solver our `struct GAS_PROPORTIONAL_Handle *`
948 */ 956 */
949static void 957static void
950GAS_proportional_bulk_stop(void *solver) 958GAS_proportional_bulk_stop (void *solver)
951{ 959{
952 struct GAS_PROPORTIONAL_Handle *s = solver; 960 struct GAS_PROPORTIONAL_Handle *s = solver;
953 961
954 LOG(GNUNET_ERROR_TYPE_DEBUG, 962 LOG (GNUNET_ERROR_TYPE_DEBUG,
955 "Unlocking solver from bulk operation ...\n"); 963 "Unlocking solver from bulk operation ...\n");
956 if (s->bulk_lock < 1) 964 if (s->bulk_lock < 1)
957 { 965 {
958 GNUNET_break(0); 966 GNUNET_break (0);
959 return; 967 return;
960 } 968 }
961 s->bulk_lock--; 969 s->bulk_lock--;
962 if ((0 == s->bulk_lock) && 970 if ((0 == s->bulk_lock) &&
963 (0 < s->bulk_requests)) 971 (0 < s->bulk_requests))
964 { 972 {
965 LOG(GNUNET_ERROR_TYPE_INFO, 973 LOG (GNUNET_ERROR_TYPE_INFO,
966 "No lock pending, recalculating\n"); 974 "No lock pending, recalculating\n");
967 distribute_bandwidth_in_network(s, 975 distribute_bandwidth_in_network (s,
968 NULL); 976 NULL);
969 s->bulk_requests = 0; 977 s->bulk_requests = 0;
970 } 978 }
971} 979}
972 980
973 981
@@ -978,14 +986,14 @@ GAS_proportional_bulk_stop(void *solver)
978 * @param address the address 986 * @param address the address
979 */ 987 */
980static void 988static void
981GAS_proportional_address_property_changed(void *solver, 989GAS_proportional_address_property_changed (void *solver,
982 struct ATS_Address *address) 990 struct ATS_Address *address)
983{ 991{
984 struct GAS_PROPORTIONAL_Handle *s = solver; 992 struct GAS_PROPORTIONAL_Handle *s = solver;
985 struct AddressWrapper *asi = address->solver_information; 993 struct AddressWrapper *asi = address->solver_information;
986 994
987 distribute_bandwidth_in_network(s, 995 distribute_bandwidth_in_network (s,
988 asi->network); 996 asi->network);
989} 997}
990 998
991 999
@@ -997,43 +1005,43 @@ GAS_proportional_address_property_changed(void *solver,
997 * @param network network type of this address 1005 * @param network network type of this address
998 */ 1006 */
999static void 1007static void
1000GAS_proportional_address_add(void *solver, 1008GAS_proportional_address_add (void *solver,
1001 struct ATS_Address *address, 1009 struct ATS_Address *address,
1002 uint32_t network) 1010 uint32_t network)
1003{ 1011{
1004 struct GAS_PROPORTIONAL_Handle *s = solver; 1012 struct GAS_PROPORTIONAL_Handle *s = solver;
1005 struct Network *net; 1013 struct Network *net;
1006 struct AddressWrapper *aw; 1014 struct AddressWrapper *aw;
1007 1015
1008 GNUNET_assert(network < s->env->network_count); 1016 GNUNET_assert (network < s->env->network_count);
1009 net = &s->network_entries[network]; 1017 net = &s->network_entries[network];
1010 net->total_addresses++; 1018 net->total_addresses++;
1011 1019
1012 aw = GNUNET_new(struct AddressWrapper); 1020 aw = GNUNET_new (struct AddressWrapper);
1013 aw->addr = address; 1021 aw->addr = address;
1014 aw->network = net; 1022 aw->network = net;
1015 address->solver_information = aw; 1023 address->solver_information = aw;
1016 GNUNET_CONTAINER_DLL_insert(net->head, 1024 GNUNET_CONTAINER_DLL_insert (net->head,
1017 net->tail, 1025 net->tail,
1018 aw); 1026 aw);
1019 GNUNET_STATISTICS_update(s->env->stats, 1027 GNUNET_STATISTICS_update (s->env->stats,
1020 "# ATS addresses total", 1028 "# ATS addresses total",
1021 1, 1029 1,
1022 GNUNET_NO); 1030 GNUNET_NO);
1023 GNUNET_STATISTICS_update(s->env->stats, 1031 GNUNET_STATISTICS_update (s->env->stats,
1024 net->stat_total, 1032 net->stat_total,
1025 1, 1033 1,
1026 GNUNET_NO); 1034 GNUNET_NO);
1027 update_active_address(s, 1035 update_active_address (s,
1028 get_active_address(s, 1036 get_active_address (s,
1029 &address->peer), 1037 &address->peer),
1030 &address->peer); 1038 &address->peer);
1031 LOG(GNUNET_ERROR_TYPE_INFO, 1039 LOG (GNUNET_ERROR_TYPE_INFO,
1032 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n", 1040 "Added new address for `%s', now total %u and active %u addresses in network `%s'\n",
1033 GNUNET_i2s(&address->peer), 1041 GNUNET_i2s (&address->peer),
1034 net->total_addresses, 1042 net->total_addresses,
1035 net->active_addresses, 1043 net->active_addresses,
1036 net->desc); 1044 net->desc);
1037} 1045}
1038 1046
1039 1047
@@ -1049,45 +1057,45 @@ GAS_proportional_address_add(void *solver,
1049 * @param address the address to remove 1057 * @param address the address to remove
1050 */ 1058 */
1051static void 1059static void
1052GAS_proportional_address_delete(void *solver, 1060GAS_proportional_address_delete (void *solver,
1053 struct ATS_Address *address) 1061 struct ATS_Address *address)
1054{ 1062{
1055 struct GAS_PROPORTIONAL_Handle *s = solver; 1063 struct GAS_PROPORTIONAL_Handle *s = solver;
1056 struct AddressWrapper *aw = address->solver_information; 1064 struct AddressWrapper *aw = address->solver_information;
1057 struct Network *net = aw->network; 1065 struct Network *net = aw->network;
1058 1066
1059 LOG(GNUNET_ERROR_TYPE_DEBUG, 1067 LOG (GNUNET_ERROR_TYPE_DEBUG,
1060 "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n", 1068 "Deleting %s address for peer `%s' from network `%s' (total: %u/active: %u)\n",
1061 (GNUNET_NO == address->active) ? "inactive" : "active", 1069 (GNUNET_NO == address->active) ? "inactive" : "active",
1062 GNUNET_i2s(&address->peer), 1070 GNUNET_i2s (&address->peer),
1063 net->desc, 1071 net->desc,
1064 net->total_addresses, 1072 net->total_addresses,
1065 net->active_addresses); 1073 net->active_addresses);
1066 1074
1067 GNUNET_CONTAINER_DLL_remove(net->head, 1075 GNUNET_CONTAINER_DLL_remove (net->head,
1068 net->tail, 1076 net->tail,
1069 aw); 1077 aw);
1070 GNUNET_assert(net->total_addresses > 0); 1078 GNUNET_assert (net->total_addresses > 0);
1071 net->total_addresses--; 1079 net->total_addresses--;
1072 GNUNET_STATISTICS_update(s->env->stats, 1080 GNUNET_STATISTICS_update (s->env->stats,
1073 net->stat_total, 1081 net->stat_total,
1074 -1, 1082 -1,
1075 GNUNET_NO); 1083 GNUNET_NO);
1076 if (GNUNET_YES == address->active) 1084 if (GNUNET_YES == address->active)
1077 { 1085 {
1078 /* Address was active, remove from network and update quotas */ 1086 /* Address was active, remove from network and update quotas */
1079 update_active_address(s, 1087 update_active_address (s,
1080 address, 1088 address,
1081 &address->peer); 1089 &address->peer);
1082 distribute_bandwidth_in_network(s, net); 1090 distribute_bandwidth_in_network (s, net);
1083 } 1091 }
1084 GNUNET_free(aw); 1092 GNUNET_free (aw);
1085 address->solver_information = NULL; 1093 address->solver_information = NULL;
1086 LOG(GNUNET_ERROR_TYPE_DEBUG, 1094 LOG (GNUNET_ERROR_TYPE_DEBUG,
1087 "After deleting address now total %u and active %u addresses in network `%s'\n", 1095 "After deleting address now total %u and active %u addresses in network `%s'\n",
1088 net->total_addresses, 1096 net->total_addresses,
1089 net->active_addresses, 1097 net->active_addresses,
1090 net->desc); 1098 net->desc);
1091} 1099}
1092 1100
1093 1101
@@ -1099,16 +1107,16 @@ GAS_proportional_address_delete(void *solver,
1099 * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure 1107 * @return the `struct GAS_PROPORTIONAL_Handle` to pass as a closure
1100 */ 1108 */
1101void * 1109void *
1102libgnunet_plugin_ats_proportional_init(void *cls) 1110libgnunet_plugin_ats_proportional_init (void *cls)
1103{ 1111{
1104 static struct GNUNET_ATS_SolverFunctions sf; 1112 static struct GNUNET_ATS_SolverFunctions sf;
1105 struct GNUNET_ATS_PluginEnvironment *env = cls; 1113 struct GNUNET_ATS_PluginEnvironment *env = cls;
1106 struct GAS_PROPORTIONAL_Handle *s; 1114 struct GAS_PROPORTIONAL_Handle *s;
1107 struct Network * cur; 1115 struct Network *cur;
1108 float f_tmp; 1116 float f_tmp;
1109 unsigned int c; 1117 unsigned int c;
1110 1118
1111 s = GNUNET_new(struct GAS_PROPORTIONAL_Handle); 1119 s = GNUNET_new (struct GAS_PROPORTIONAL_Handle);
1112 s->env = env; 1120 s->env = env;
1113 sf.cls = s; 1121 sf.cls = s;
1114 sf.s_add = &GAS_proportional_address_add; 1122 sf.s_add = &GAS_proportional_address_add;
@@ -1122,73 +1130,73 @@ libgnunet_plugin_ats_proportional_init(void *cls)
1122 sf.s_bulk_stop = &GAS_proportional_bulk_stop; 1130 sf.s_bulk_stop = &GAS_proportional_bulk_stop;
1123 s->stability_factor = PROP_STABILITY_FACTOR; 1131 s->stability_factor = PROP_STABILITY_FACTOR;
1124 if (GNUNET_SYSERR != 1132 if (GNUNET_SYSERR !=
1125 GNUNET_CONFIGURATION_get_value_float(env->cfg, 1133 GNUNET_CONFIGURATION_get_value_float (env->cfg,
1126 "ats", 1134 "ats",
1127 "PROP_STABILITY_FACTOR", 1135 "PROP_STABILITY_FACTOR",
1128 &f_tmp)) 1136 &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
1129 { 1146 {
1130 if ((f_tmp < 1.0) || (f_tmp > 2.0)) 1147 s->stability_factor = f_tmp;
1131 { 1148 LOG (GNUNET_ERROR_TYPE_INFO,
1132 LOG(GNUNET_ERROR_TYPE_ERROR, 1149 "Using %s of %.3f\n",
1133 _("Invalid %s configuration %f \n"), 1150 "PROP_STABILITY_FACTOR",
1134 "PROP_STABILITY_FACTOR", 1151 f_tmp);
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 }
1145 } 1152 }
1153 }
1146 s->prop_factor = PROPORTIONALITY_FACTOR; 1154 s->prop_factor = PROPORTIONALITY_FACTOR;
1147 if (GNUNET_SYSERR != 1155 if (GNUNET_SYSERR !=
1148 GNUNET_CONFIGURATION_get_value_float(env->cfg, 1156 GNUNET_CONFIGURATION_get_value_float (env->cfg,
1149 "ats", 1157 "ats",
1150 "PROP_PROPORTIONALITY_FACTOR", 1158 "PROP_PROPORTIONALITY_FACTOR",
1151 &f_tmp)) 1159 &f_tmp))
1160 {
1161 if (f_tmp < 1.0)
1152 { 1162 {
1153 if (f_tmp < 1.0) 1163 LOG (GNUNET_ERROR_TYPE_ERROR,
1154 { 1164 _ ("Invalid %s configuration %f\n"),
1155 LOG(GNUNET_ERROR_TYPE_ERROR, 1165 "PROP_PROPORTIONALITY_FACTOR",
1156 _("Invalid %s configuration %f\n"), 1166 f_tmp);
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 }
1168 } 1167 }
1169 1168 else
1170 s->network_entries = GNUNET_malloc(env->network_count *
1171 sizeof(struct Network));
1172 for (c = 0; c < env->network_count; c++)
1173 { 1169 {
1174 cur = &s->network_entries[c]; 1170 s->prop_factor = f_tmp;
1175 cur->type = c; 1171 LOG (GNUNET_ERROR_TYPE_INFO,
1176 cur->total_quota_in = env->in_quota[c]; 1172 "Using %s of %.3f\n",
1177 cur->total_quota_out = env->out_quota[c]; 1173 "PROP_PROPORTIONALITY_FACTOR",
1178 cur->desc = GNUNET_NT_to_string(c); 1174 f_tmp);
1179 GNUNET_asprintf(&cur->stat_total,
1180 "# ATS addresses %s total",
1181 cur->desc);
1182 GNUNET_asprintf(&cur->stat_active,
1183 "# ATS active addresses %s total",
1184 cur->desc);
1185 LOG(GNUNET_ERROR_TYPE_INFO,
1186 "Added network %u `%s' (%llu/%llu)\n",
1187 c,
1188 cur->desc,
1189 cur->total_quota_in,
1190 cur->total_quota_out);
1191 } 1175 }
1176 }
1177
1178 s->network_entries = GNUNET_malloc (env->network_count
1179 * sizeof(struct Network));
1180 for (c = 0; c < env->network_count; c++)
1181 {
1182 cur = &s->network_entries[c];
1183 cur->type = c;
1184 cur->total_quota_in = env->in_quota[c];
1185 cur->total_quota_out = env->out_quota[c];
1186 cur->desc = GNUNET_NT_to_string (c);
1187 GNUNET_asprintf (&cur->stat_total,
1188 "# ATS addresses %s total",
1189 cur->desc);
1190 GNUNET_asprintf (&cur->stat_active,
1191 "# ATS active addresses %s total",
1192 cur->desc);
1193 LOG (GNUNET_ERROR_TYPE_INFO,
1194 "Added network %u `%s' (%llu/%llu)\n",
1195 c,
1196 cur->desc,
1197 cur->total_quota_in,
1198 cur->total_quota_out);
1199 }
1192 return &sf; 1200 return &sf;
1193} 1201}
1194 1202
@@ -1199,7 +1207,7 @@ libgnunet_plugin_ats_proportional_init(void *cls)
1199 * @param cls return value from #libgnunet_plugin_ats_proportional_init() 1207 * @param cls return value from #libgnunet_plugin_ats_proportional_init()
1200 */ 1208 */
1201void * 1209void *
1202libgnunet_plugin_ats_proportional_done(void *cls) 1210libgnunet_plugin_ats_proportional_done (void *cls)
1203{ 1211{
1204 struct GNUNET_ATS_SolverFunctions *sf = cls; 1212 struct GNUNET_ATS_SolverFunctions *sf = cls;
1205 struct GAS_PROPORTIONAL_Handle *s = sf->cls; 1213 struct GAS_PROPORTIONAL_Handle *s = sf->cls;
@@ -1208,25 +1216,25 @@ libgnunet_plugin_ats_proportional_done(void *cls)
1208 unsigned int c; 1216 unsigned int c;
1209 1217
1210 for (c = 0; c < s->env->network_count; c++) 1218 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))
1211 { 1224 {
1212 GNUNET_break(0 == s->network_entries[c].total_addresses); 1225 next = cur->next;
1213 GNUNET_break(0 == s->network_entries[c].active_addresses); 1226 GNUNET_CONTAINER_DLL_remove (s->network_entries[c].head,
1214 next = s->network_entries[c].head; 1227 s->network_entries[c].tail,
1215 while (NULL != (cur = next)) 1228 cur);
1216 { 1229 GNUNET_free_non_null (cur->addr->solver_information);
1217 next = cur->next; 1230 GNUNET_free (cur);
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);
1226 } 1231 }
1227 GNUNET_break(0 == s->active_addresses); 1232 GNUNET_free (s->network_entries[c].stat_total);
1228 GNUNET_free(s->network_entries); 1233 GNUNET_free (s->network_entries[c].stat_active);
1229 GNUNET_free(s); 1234 }
1235 GNUNET_break (0 == s->active_addresses);
1236 GNUNET_free (s->network_entries);
1237 GNUNET_free (s);
1230 return NULL; 1238 return NULL;
1231} 1239}
1232 1240
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index abf265f19..7be3cb0a1 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -32,17 +32,21 @@
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 ( \
38 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT. \
39 value__))
38#define RIL_MAX_BW GNUNET_ATS_MaxBandwidth 40#define RIL_MAX_BW GNUNET_ATS_MaxBandwidth
39 41
40#define RIL_ACTION_INVALID -1 42#define RIL_ACTION_INVALID -1
41#define RIL_INTERVAL_EXPONENT 10 43#define RIL_INTERVAL_EXPONENT 10
42#define RIL_UTILITY_DELAY_MAX 1000 44#define RIL_UTILITY_DELAY_MAX 1000
43 45
44#define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 200) 46#define RIL_DEFAULT_STEP_TIME_MIN GNUNET_TIME_relative_multiply ( \
45#define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2000) 47 GNUNET_TIME_UNIT_MILLISECONDS, 200)
48#define RIL_DEFAULT_STEP_TIME_MAX GNUNET_TIME_relative_multiply ( \
49 GNUNET_TIME_UNIT_MILLISECONDS, 2000)
46#define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA 50#define RIL_DEFAULT_ALGORITHM RIL_ALGO_SARSA
47#define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX 51#define RIL_DEFAULT_SELECT RIL_SELECT_SOFTMAX
48#define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH 52#define RIL_DEFAULT_WELFARE RIL_WELFARE_NASH
@@ -71,9 +75,10 @@
71 * to a particular address. The action of switching to address with index i is depicted by the 75 * to a particular address. The action of switching to address with index i is depicted by the
72 * number (RIL_ACTION_TYPE_NUM + i). 76 * number (RIL_ACTION_TYPE_NUM + i).
73 */ 77 */
74enum RIL_Action_Type { 78enum RIL_Action_Type
79{
75 RIL_ACTION_NOTHING = 0, 80 RIL_ACTION_NOTHING = 0,
76 RIL_ACTION_BW_IN_DBL = -2, //TODO? Potentially add more actions 81 RIL_ACTION_BW_IN_DBL = -2, // TODO? Potentially add more actions
77 RIL_ACTION_BW_IN_HLV = -3, 82 RIL_ACTION_BW_IN_HLV = -3,
78 RIL_ACTION_BW_IN_INC = 1, 83 RIL_ACTION_BW_IN_INC = 1,
79 RIL_ACTION_BW_IN_DEC = 2, 84 RIL_ACTION_BW_IN_DEC = 2,
@@ -84,22 +89,26 @@ enum RIL_Action_Type {
84 RIL_ACTION_TYPE_NUM = 5 89 RIL_ACTION_TYPE_NUM = 5
85}; 90};
86 91
87enum RIL_Algorithm { 92enum RIL_Algorithm
93{
88 RIL_ALGO_SARSA = 0, 94 RIL_ALGO_SARSA = 0,
89 RIL_ALGO_Q = 1 95 RIL_ALGO_Q = 1
90}; 96};
91 97
92enum RIL_Select { 98enum RIL_Select
99{
93 RIL_SELECT_SOFTMAX = 0, 100 RIL_SELECT_SOFTMAX = 0,
94 RIL_SELECT_EGREEDY = 1 101 RIL_SELECT_EGREEDY = 1
95}; 102};
96 103
97enum RIL_Welfare { 104enum RIL_Welfare
105{
98 RIL_WELFARE_NASH, 106 RIL_WELFARE_NASH,
99 RIL_WELFARE_EGALITARIAN 107 RIL_WELFARE_EGALITARIAN
100}; 108};
101 109
102enum RIL_E_Modification { 110enum RIL_E_Modification
111{
103 RIL_E_DECAY, 112 RIL_E_DECAY,
104 RIL_E_ZERO, 113 RIL_E_ZERO,
105 RIL_E_ACCUMULATE, 114 RIL_E_ACCUMULATE,
@@ -109,7 +118,8 @@ enum RIL_E_Modification {
109/** 118/**
110 * Global learning parameters 119 * Global learning parameters
111 */ 120 */
112struct RIL_Learning_Parameters { 121struct RIL_Learning_Parameters
122{
113 /** 123 /**
114 * The TD-algorithm to use 124 * The TD-algorithm to use
115 */ 125 */
@@ -199,7 +209,8 @@ struct RIL_Learning_Parameters {
199/** 209/**
200 * Wrapper for addresses to store them in agent's linked list 210 * Wrapper for addresses to store them in agent's linked list
201 */ 211 */
202struct RIL_Address_Wrapped { 212struct RIL_Address_Wrapped
213{
203 /** 214 /**
204 * Next in DLL 215 * Next in DLL
205 */ 216 */
@@ -217,7 +228,8 @@ struct RIL_Address_Wrapped {
217}; 228};
218 229
219 230
220struct RIL_Peer_Agent { 231struct RIL_Peer_Agent
232{
221 /** 233 /**
222 * Next agent in solver's linked list 234 * Next agent in solver's linked list
223 */ 235 */
@@ -251,7 +263,7 @@ struct RIL_Peer_Agent {
251 /** 263 /**
252 * Experience matrix W 264 * Experience matrix W
253 */ 265 */
254 double ** W; 266 double **W;
255 267
256 /** 268 /**
257 * Number of rows of W / Number of state-vector features 269 * Number of rows of W / Number of state-vector features
@@ -276,7 +288,7 @@ struct RIL_Peer_Agent {
276 /** 288 /**
277 * Eligibility traces 289 * Eligibility traces
278 */ 290 */
279 double ** E; 291 double **E;
280 292
281 /** 293 /**
282 * Whether to reset the eligibility traces to 0 after a Q-exploration step 294 * Whether to reset the eligibility traces to 0 after a Q-exploration step
@@ -329,7 +341,8 @@ struct RIL_Peer_Agent {
329 double nop_bonus; 341 double nop_bonus;
330}; 342};
331 343
332struct RIL_Scope { 344struct RIL_Scope
345{
333 /** 346 /**
334 * ATS network type 347 * ATS network type
335 */ 348 */
@@ -379,7 +392,8 @@ struct RIL_Scope {
379/** 392/**
380 * A handle for the reinforcement learning solver 393 * A handle for the reinforcement learning solver
381 */ 394 */
382struct GAS_RIL_Handle { 395struct GAS_RIL_Handle
396{
383 /** 397 /**
384 * The solver-plugin environment of the solver-plugin API 398 * The solver-plugin environment of the solver-plugin API
385 */ 399 */
@@ -398,7 +412,7 @@ struct GAS_RIL_Handle {
398 /** 412 /**
399 * Task identifier of the next time-step to be executed 413 * Task identifier of the next time-step to be executed
400 */ 414 */
401 struct GNUNET_SCHEDULER_Task * step_next_task_id; 415 struct GNUNET_SCHEDULER_Task *step_next_task_id;
402 416
403 /** 417 /**
404 * Variable discount factor, dependent on time between steps 418 * Variable discount factor, dependent on time between steps
@@ -428,7 +442,7 @@ struct GAS_RIL_Handle {
428 /** 442 /**
429 * Array of networks with global assignment state 443 * Array of networks with global assignment state
430 */ 444 */
431 struct RIL_Scope * network_entries; 445 struct RIL_Scope *network_entries;
432 446
433 /** 447 /**
434 * Networks count 448 * Networks count
@@ -438,8 +452,8 @@ struct GAS_RIL_Handle {
438 /** 452 /**
439 * List of active peer-agents 453 * List of active peer-agents
440 */ 454 */
441 struct RIL_Peer_Agent * agents_head; 455 struct RIL_Peer_Agent *agents_head;
442 struct RIL_Peer_Agent * agents_tail; 456 struct RIL_Peer_Agent *agents_tail;
443 457
444 /** 458 /**
445 * Shutdown 459 * Shutdown
@@ -466,9 +480,9 @@ struct GAS_RIL_Handle {
466 * @return estimation value 480 * @return estimation value
467 */ 481 */
468static double 482static double
469agent_q(struct RIL_Peer_Agent *agent, 483agent_q (struct RIL_Peer_Agent *agent,
470 const double *state, 484 const double *state,
471 int action) 485 int action)
472{ 486{
473 unsigned int i; 487 unsigned int i;
474 double result = 0.0; 488 double result = 0.0;
@@ -477,10 +491,10 @@ agent_q(struct RIL_Peer_Agent *agent,
477 result += state[i] * agent->W[action][i]; 491 result += state[i] * agent->W[action][i];
478 492
479 /* prevent crashes if learning diverges */ 493 /* prevent crashes if learning diverges */
480 if (isnan(result)) 494 if (isnan (result))
481 return isnan(result) * UINT32_MAX; 495 return isnan (result) * UINT32_MAX;
482 if (isinf(result)) 496 if (isinf (result))
483 return isinf(result) * UINT32_MAX; 497 return isinf (result) * UINT32_MAX;
484 return result; 498 return result;
485} 499}
486 500
@@ -493,18 +507,19 @@ agent_q(struct RIL_Peer_Agent *agent,
493 * @return the index, starting with zero 507 * @return the index, starting with zero
494 */ 508 */
495static int 509static int
496agent_address_get_index(struct RIL_Peer_Agent *agent, struct ATS_Address *address) 510agent_address_get_index (struct RIL_Peer_Agent *agent, struct
511 ATS_Address *address)
497{ 512{
498 int i; 513 int i;
499 struct RIL_Address_Wrapped *cur; 514 struct RIL_Address_Wrapped *cur;
500 515
501 i = -1; 516 i = -1;
502 for (cur = agent->addresses_head; NULL != cur; cur = cur->next) 517 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
503 { 518 {
504 i++; 519 i++;
505 if (cur->address_naked == address) 520 if (cur->address_naked == address)
506 return i; 521 return i;
507 } 522 }
508 return i; 523 return i;
509} 524}
510 525
@@ -517,7 +532,8 @@ agent_address_get_index(struct RIL_Peer_Agent *agent, struct ATS_Address *addres
517 * @return wrapped address 532 * @return wrapped address
518 */ 533 */
519static struct RIL_Address_Wrapped * 534static struct RIL_Address_Wrapped *
520agent_address_get_wrapped(struct RIL_Peer_Agent *agent, struct ATS_Address *address) 535agent_address_get_wrapped (struct RIL_Peer_Agent *agent, struct
536 ATS_Address *address)
521{ 537{
522 struct RIL_Address_Wrapped *cur; 538 struct RIL_Address_Wrapped *cur;
523 539
@@ -529,67 +545,70 @@ agent_address_get_wrapped(struct RIL_Peer_Agent *agent, struct ATS_Address *addr
529 545
530 546
531static int 547static int
532agent_action_is_possible(struct RIL_Peer_Agent *agent, int action) 548agent_action_is_possible (struct RIL_Peer_Agent *agent, int action)
533{ 549{
534 int address_index; 550 int address_index;
535 551
536 switch (action) 552 switch (action)
537 { 553 {
538 case RIL_ACTION_NOTHING: 554 case RIL_ACTION_NOTHING:
555 return GNUNET_YES;
556 break;
557
558 case RIL_ACTION_BW_IN_INC:
559 case RIL_ACTION_BW_IN_DBL:
560 if (agent->bw_in >= RIL_MAX_BW)
561 return GNUNET_NO;
562 else
539 return GNUNET_YES; 563 return GNUNET_YES;
540 break; 564 break;
541 565
542 case RIL_ACTION_BW_IN_INC: 566 case RIL_ACTION_BW_IN_DEC:
543 case RIL_ACTION_BW_IN_DBL: 567 case RIL_ACTION_BW_IN_HLV:
544 if (agent->bw_in >= RIL_MAX_BW) 568 if (agent->bw_in <= 0)
545 return GNUNET_NO; 569 return GNUNET_NO;
546 else 570 else
547 return GNUNET_YES; 571 return GNUNET_YES;
548 break; 572 break;
549 573
550 case RIL_ACTION_BW_IN_DEC: 574 case RIL_ACTION_BW_OUT_INC:
551 case RIL_ACTION_BW_IN_HLV: 575 case RIL_ACTION_BW_OUT_DBL:
552 if (agent->bw_in <= 0) 576 if (agent->bw_out >= RIL_MAX_BW)
553 return GNUNET_NO; 577 return GNUNET_NO;
554 else 578 else
555 return GNUNET_YES; 579 return GNUNET_YES;
556 break; 580 break;
557 581
558 case RIL_ACTION_BW_OUT_INC: 582 case RIL_ACTION_BW_OUT_DEC:
559 case RIL_ACTION_BW_OUT_DBL: 583 case RIL_ACTION_BW_OUT_HLV:
560 if (agent->bw_out >= RIL_MAX_BW) 584 if (agent->bw_out <= 0)
561 return GNUNET_NO; 585 return GNUNET_NO;
562 else 586 else
563 return GNUNET_YES; 587 return GNUNET_YES;
564 break; 588 break;
565 589
566 case RIL_ACTION_BW_OUT_DEC: 590 default:
567 case RIL_ACTION_BW_OUT_HLV: 591 if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) // switch address action
568 if (agent->bw_out <= 0) 592 {
593 address_index = action - RIL_ACTION_TYPE_NUM;
594
595 GNUNET_assert (address_index >= 0);
596 GNUNET_assert (
597 address_index <= agent_address_get_index (agent,
598 agent->addresses_tail->
599 address_naked));
600
601 if ((agent_address_get_index (agent, agent->address_inuse) ==
602 address_index) ||
603 agent->address_inuse->active)
569 return GNUNET_NO; 604 return GNUNET_NO;
570 else 605 else
571 return GNUNET_YES; 606 return GNUNET_YES;
572 break; 607 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);
592 } 608 }
609 // error - action does not exist
610 GNUNET_assert (GNUNET_NO);
611 }
593} 612}
594 613
595 614
@@ -602,7 +621,7 @@ agent_action_is_possible(struct RIL_Peer_Agent *agent, int action)
602 * @return the action promising most future reward 621 * @return the action promising most future reward
603 */ 622 */
604static int 623static int
605agent_get_action_max(struct RIL_Peer_Agent *agent, double *state) 624agent_get_action_max (struct RIL_Peer_Agent *agent, double *state)
606{ 625{
607 int i; 626 int i;
608 int max_i = RIL_ACTION_INVALID; 627 int max_i = RIL_ACTION_INVALID;
@@ -610,19 +629,19 @@ agent_get_action_max(struct RIL_Peer_Agent *agent, double *state)
610 double max_q = -DBL_MAX; 629 double max_q = -DBL_MAX;
611 630
612 for (i = 0; i < agent->n; i++) 631 for (i = 0; i < agent->n; i++)
632 {
633 if (agent_action_is_possible (agent, i))
613 { 634 {
614 if (agent_action_is_possible(agent, i)) 635 cur_q = agent_q (agent, state, i);
615 { 636 if (cur_q > max_q)
616 cur_q = agent_q(agent, state, i); 637 {
617 if (cur_q > max_q) 638 max_q = cur_q;
618 { 639 max_i = i;
619 max_q = cur_q; 640 }
620 max_i = i;
621 }
622 }
623 } 641 }
642 }
624 643
625 GNUNET_assert(RIL_ACTION_INVALID != max_i); 644 GNUNET_assert (RIL_ACTION_INVALID != max_i);
626 645
627 return max_i; 646 return max_i;
628} 647}
@@ -634,7 +653,7 @@ agent_get_action_max(struct RIL_Peer_Agent *agent, double *state)
634 * @return the action index 653 * @return the action index
635 */ 654 */
636static int 655static int
637agent_get_action_random(struct RIL_Peer_Agent *agent) 656agent_get_action_random (struct RIL_Peer_Agent *agent)
638{ 657{
639 int i; 658 int i;
640 int is_possible[agent->n]; 659 int is_possible[agent->n];
@@ -642,32 +661,32 @@ agent_get_action_random(struct RIL_Peer_Agent *agent)
642 int r; 661 int r;
643 662
644 for (i = 0; i < agent->n; i++) 663 for (i = 0; i < agent->n; i++)
664 {
665 if (agent_action_is_possible (agent, i))
645 { 666 {
646 if (agent_action_is_possible(agent, i)) 667 is_possible[i] = GNUNET_YES;
647 { 668 sum++;
648 is_possible[i] = GNUNET_YES; 669 }
649 sum++; 670 else
650 } 671 {
651 else 672 is_possible[i] = GNUNET_NO;
652 {
653 is_possible[i] = GNUNET_NO;
654 }
655 } 673 }
674 }
656 675
657 r = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, sum); 676 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, sum);
658 677
659 sum = -1; 678 sum = -1;
660 for (i = 0; i < agent->n; i++) 679 for (i = 0; i < agent->n; i++)
680 {
681 if (is_possible[i])
661 { 682 {
662 if (is_possible[i]) 683 sum++;
663 { 684 if (sum == r)
664 sum++; 685 return i;
665 if (sum == r)
666 return i;
667 }
668 } 686 }
687 }
669 688
670 GNUNET_assert(GNUNET_NO); 689 GNUNET_assert (GNUNET_NO);
671 return RIL_ACTION_INVALID; 690 return RIL_ACTION_INVALID;
672} 691}
673 692
@@ -681,16 +700,18 @@ agent_get_action_random(struct RIL_Peer_Agent *agent)
681 * @param a_prime the new 700 * @param a_prime the new
682 */ 701 */
683static void 702static void
684agent_update(struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_prime) 703agent_update (struct RIL_Peer_Agent *agent, double reward, double *s_next, int
704 a_prime)
685{ 705{
686 int i; 706 int i;
687 int k; 707 int k;
688 double delta; 708 double delta;
689 double **theta = agent->W; 709 double **theta = agent->W;
690 710
691 delta = agent->envi->global_discount_integrated * reward; //reward 711 delta = agent->envi->global_discount_integrated * reward; // reward
692 delta += agent->envi->global_discount_variable * agent_q(agent, s_next, a_prime); //discounted future value 712 delta += agent->envi->global_discount_variable * agent_q (agent, s_next,
693 delta -= agent_q(agent, agent->s_old, agent->a_old); //one step 713 a_prime); // discounted future value
714 delta -= agent_q (agent, agent->s_old, agent->a_old); // one step
694 715
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", 716// 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",
696// agent->step_count, 717// agent->step_count,
@@ -702,17 +723,17 @@ agent_update(struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_
702// delta); 723// delta);
703 724
704 for (k = 0; k < agent->n; k++) 725 for (k = 0; k < agent->n; k++)
726 {
727 for (i = 0; i < agent->m; i++)
705 { 728 {
706 for (i = 0; i < agent->m; i++) 729 // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n",
707 { 730 // agent->envi->parameters.alpha,
708 // LOG(GNUNET_ERROR_TYPE_INFO, "alpha = %f delta = %f e[%d] = %f\n", 731 // delta,
709 // agent->envi->parameters.alpha, 732 // i,
710 // delta, 733 // agent->e[i]);
711 // i, 734 theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i];
712 // agent->e[i]);
713 theta[k][i] += agent->envi->parameters.alpha * delta * agent->E[k][i];
714 }
715 } 735 }
736 }
716} 737}
717 738
718 739
@@ -729,41 +750,43 @@ agent_update(struct RIL_Peer_Agent *agent, double reward, double *s_next, int a_
729 * @param action the action to take 750 * @param action the action to take
730 */ 751 */
731static void 752static void
732agent_modify_eligibility(struct RIL_Peer_Agent *agent, 753agent_modify_eligibility (struct RIL_Peer_Agent *agent,
733 enum RIL_E_Modification mod, 754 enum RIL_E_Modification mod,
734 double *feature, 755 double *feature,
735 int action) 756 int action)
736{ 757{
737 int i; 758 int i;
738 int k; 759 int k;
739 760
740 for (i = 0; i < agent->m; i++) 761 for (i = 0; i < agent->m; i++)
762 {
763 switch (mod)
741 { 764 {
742 switch (mod) 765 case RIL_E_ACCUMULATE:
743 { 766 agent->E[action][i] += feature[i];
744 case RIL_E_ACCUMULATE: 767 break;
745 agent->E[action][i] += feature[i]; 768
746 break; 769 case RIL_E_REPLACE:
747 770 agent->E[action][i] = agent->E[action][i] > feature[i] ?
748 case RIL_E_REPLACE: 771 agent->E[action][i] : feature[i];
749 agent->E[action][i] = agent->E[action][i] > feature[i] ? agent->E[action][i] : feature[i]; 772 break;
750 break; 773
751 774 case RIL_E_DECAY:
752 case RIL_E_DECAY: 775 for (k = 0; k < agent->n; k++)
753 for (k = 0; k < agent->n; k++) 776 {
754 { 777 agent->E[k][i] *= agent->envi->global_discount_variable
755 agent->E[k][i] *= agent->envi->global_discount_variable * agent->envi->parameters.lambda; 778 * agent->envi->parameters.lambda;
756 } 779 }
757 break; 780 break;
758 781
759 case RIL_E_ZERO: 782 case RIL_E_ZERO:
760 for (k = 0; k < agent->n; k++) 783 for (k = 0; k < agent->n; k++)
761 { 784 {
762 agent->E[k][i] = 0; 785 agent->E[k][i] = 0;
763 } 786 }
764 break; 787 break;
765 }
766 } 788 }
789 }
767} 790}
768 791
769/** 792/**
@@ -774,14 +797,14 @@ agent_modify_eligibility(struct RIL_Peer_Agent *agent,
774 * @param stat 797 * @param stat
775 */ 798 */
776static void 799static void
777ril_inform(struct GAS_RIL_Handle *solver, 800ril_inform (struct GAS_RIL_Handle *solver,
778 enum GAS_Solver_Operation op, 801 enum GAS_Solver_Operation op,
779 enum GAS_Solver_Status stat) 802 enum GAS_Solver_Status stat)
780{ 803{
781 solver->env->info_cb(solver->env->cls, 804 solver->env->info_cb (solver->env->cls,
782 op, 805 op,
783 stat, 806 stat,
784 GAS_INFO_NONE); 807 GAS_INFO_NONE);
785} 808}
786 809
787/** 810/**
@@ -790,9 +813,11 @@ ril_inform(struct GAS_RIL_Handle *solver,
790 * @param net 813 * @param net
791 */ 814 */
792static unsigned long long 815static unsigned long long
793ril_get_max_bw(struct RIL_Scope *net) 816ril_get_max_bw (struct RIL_Scope *net)
794{ 817{
795 return GNUNET_MIN(2 * GNUNET_MAX(net->bw_in_available, net->bw_out_available), GNUNET_ATS_MaxBandwidth); 818 return GNUNET_MIN (2 * GNUNET_MAX (net->bw_in_available,
819 net->bw_out_available),
820 GNUNET_ATS_MaxBandwidth);
796} 821}
797 822
798/** 823/**
@@ -807,82 +832,84 @@ ril_get_max_bw(struct RIL_Scope *net)
807 * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES 832 * @param silent disables invocation of the bw_changed callback, if #GNUNET_YES
808 */ 833 */
809static void 834static void
810envi_set_active_suggestion(struct GAS_RIL_Handle *solver, 835envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
811 struct RIL_Peer_Agent *agent, 836 struct RIL_Peer_Agent *agent,
812 struct ATS_Address *new_address, 837 struct ATS_Address *new_address,
813 unsigned long long new_bw_in, 838 unsigned long long new_bw_in,
814 unsigned long long new_bw_out, 839 unsigned long long new_bw_out,
815 int silent) 840 int silent)
816{ 841{
817 int notify = GNUNET_NO; 842 int notify = GNUNET_NO;
818 843
819 LOG(GNUNET_ERROR_TYPE_DEBUG, 844 LOG (GNUNET_ERROR_TYPE_DEBUG,
820 " set_active_suggestion() for peer '%s'\n", 845 " set_active_suggestion() for peer '%s'\n",
821 GNUNET_i2s(&agent->peer)); 846 GNUNET_i2s (&agent->peer));
822 847
823 //address change 848 // address change
824 if (agent->address_inuse != new_address) 849 if (agent->address_inuse != new_address)
850 {
851 if (NULL != agent->address_inuse)
825 { 852 {
826 if (NULL != agent->address_inuse) 853 agent->address_inuse->active = GNUNET_NO;
827 { 854 agent->address_inuse->assigned_bw_in = 0;
828 agent->address_inuse->active = GNUNET_NO; 855 agent->address_inuse->assigned_bw_out = 0;
829 agent->address_inuse->assigned_bw_in = 0; 856 }
830 agent->address_inuse->assigned_bw_out = 0; 857 if (NULL != new_address)
831 } 858 {
832 if (NULL != new_address) 859 LOG (GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n",
833 { 860 agent->is_active ? "yes" : "no");
834 LOG(GNUNET_ERROR_TYPE_DEBUG, " set address active: %s\n", agent->is_active ? "yes" : "no"); 861 new_address->active = agent->is_active;
835 new_address->active = agent->is_active; 862 new_address->assigned_bw_in = agent->bw_in;
836 new_address->assigned_bw_in = agent->bw_in; 863 new_address->assigned_bw_out = agent->bw_out;
837 new_address->assigned_bw_out = agent->bw_out;
838 }
839 notify |= GNUNET_YES;
840 } 864 }
865 notify |= GNUNET_YES;
866 }
841 867
842 if (new_address) 868 if (new_address)
869 {
870 // activity change
871 if (new_address->active != agent->is_active)
843 { 872 {
844 //activity change 873 new_address->active = agent->is_active;
845 if (new_address->active != agent->is_active) 874 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 }
864 } 875 }
865 876
877 // bw change
878 if (agent->bw_in != new_bw_in)
879 {
880 agent->bw_in = new_bw_in;
881 new_address->assigned_bw_in = new_bw_in;
882 notify |= GNUNET_YES;
883 }
884 if (agent->bw_out != new_bw_out)
885 {
886 agent->bw_out = new_bw_out;
887 new_address->assigned_bw_out = new_bw_out;
888 notify |= GNUNET_YES;
889 }
890 }
891
866 if (notify && agent->is_active && (GNUNET_NO == silent)) 892 if (notify && agent->is_active && (GNUNET_NO == silent))
893 {
894 if (new_address)
867 { 895 {
868 if (new_address) 896 LOG (GNUNET_ERROR_TYPE_DEBUG,
869 { 897 " envi_set_active_suggestion() notify\n");
870 LOG(GNUNET_ERROR_TYPE_DEBUG, " envi_set_active_suggestion() notify\n"); 898 agent->suggestion_issue = GNUNET_YES;
871 agent->suggestion_issue = GNUNET_YES; 899 agent->suggestion_address = new_address;
872 agent->suggestion_address = new_address;
873 }
874 else if (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 }
885 } 900 }
901 else if (agent->address_inuse)
902 {
903 /* disconnect case, no new address */
904 GNUNET_assert (0 == agent->address_inuse->assigned_bw_in);
905 GNUNET_assert (0 == agent->address_inuse->assigned_bw_out);
906 agent->bw_in = 0;
907 agent->bw_out = 0;
908
909 agent->suggestion_issue = GNUNET_YES;
910 agent->suggestion_address = agent->address_inuse;
911 }
912 }
886 agent->address_inuse = new_address; 913 agent->address_inuse = new_address;
887} 914}
888 915
@@ -894,7 +921,7 @@ envi_set_active_suggestion(struct GAS_RIL_Handle *solver,
894 * @return pointer to the state vector 921 * @return pointer to the state vector
895 */ 922 */
896static double * 923static double *
897envi_get_state(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 924envi_get_state (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
898{ 925{
899 double *state; 926 double *state;
900 double y[2]; 927 double y[2];
@@ -907,27 +934,34 @@ envi_get_state(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
907 int k; 934 int k;
908 unsigned long long max_bw; 935 unsigned long long max_bw;
909 936
910 state = GNUNET_malloc(sizeof(double) * agent->m); 937 state = GNUNET_malloc (sizeof(double) * agent->m);
911 938
912 max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); 939 max_bw = ril_get_max_bw ((struct
940 RIL_Scope *) agent->address_inuse->
941 solver_information);
913 942
914 y[0] = (double)agent->bw_out; 943 y[0] = (double) agent->bw_out;
915 y[1] = (double)agent->bw_in; 944 y[1] = (double) agent->bw_in;
916 945
917 m = agent_address_get_index(agent, agent->address_inuse) * (solver->parameters.rbf_divisor + 1) * (solver->parameters.rbf_divisor + 1); 946 m = agent_address_get_index (agent, agent->address_inuse)
947 * (solver->parameters.rbf_divisor + 1) * (solver->parameters.rbf_divisor
948 + 1);
918 for (i = 0; i <= solver->parameters.rbf_divisor; i++) 949 for (i = 0; i <= solver->parameters.rbf_divisor; i++)
919 { 950 {
920 for (k = 0; k <= solver->parameters.rbf_divisor; k++) 951 for (k = 0; k <= solver->parameters.rbf_divisor; k++)
921 { 952 {
922 x[0] = (double)i * (double)max_bw / (double)solver->parameters.rbf_divisor; 953 x[0] = (double) i * (double) max_bw
923 x[1] = (double)k * (double)max_bw / (double)solver->parameters.rbf_divisor; 954 / (double) solver->parameters.rbf_divisor;
924 d[0] = x[0] - y[0]; 955 x[1] = (double) k * (double) max_bw
925 d[1] = x[1] - y[1]; 956 / (double) solver->parameters.rbf_divisor;
926 sigma = (((double)max_bw / ((double)solver->parameters.rbf_divisor + 1)) * 0.5); 957 d[0] = x[0] - y[0];
927 f = exp(-((d[0] * d[0] + d[1] * d[1]) / (2 * sigma * sigma))); 958 d[1] = x[1] - y[1];
928 state[m++] = f; 959 sigma = (((double) max_bw / ((double) solver->parameters.rbf_divisor
929 } 960 + 1)) * 0.5);
930 } 961 f = exp (-((d[0] * d[0] + d[1] * d[1]) / (2 * sigma * sigma)));
962 state[m++] = f;
963 }
964 }
931 965
932 return state; 966 return state;
933} 967}
@@ -940,22 +974,23 @@ envi_get_state(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
940 * @return the utility value 974 * @return the utility value
941 */ 975 */
942static double 976static double
943agent_get_utility(struct RIL_Peer_Agent *agent) 977agent_get_utility (struct RIL_Peer_Agent *agent)
944{ 978{
945 const double *preferences; 979 const double *preferences;
946 double delay_atsi; 980 double delay_atsi;
947 double delay_norm; 981 double delay_norm;
948 double pref_match; 982 double pref_match;
949 983
950 preferences = agent->envi->env->get_preferences(agent->envi->env->cls, 984 preferences = agent->envi->env->get_preferences (agent->envi->env->cls,
951 &agent->peer); 985 &agent->peer);
952 986
953 delay_atsi = agent->address_inuse->norm_delay.norm; 987 delay_atsi = agent->address_inuse->norm_delay.norm;
954 delay_norm = RIL_UTILITY_DELAY_MAX * exp(-delay_atsi * 0.00001); 988 delay_norm = RIL_UTILITY_DELAY_MAX * exp (-delay_atsi * 0.00001);
955 989
956 pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm; 990 pref_match = preferences[GNUNET_ATS_PREFERENCE_LATENCY] * delay_norm;
957 pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH] * 991 pref_match += preferences[GNUNET_ATS_PREFERENCE_BANDWIDTH]
958 sqrt((double)(agent->bw_in / RIL_MIN_BW) * (double)(agent->bw_out / RIL_MIN_BW)); 992 * sqrt ((double) (agent->bw_in / RIL_MIN_BW)
993 * (double) (agent->bw_out / RIL_MIN_BW));
959 return pref_match; 994 return pref_match;
960} 995}
961 996
@@ -968,41 +1003,45 @@ agent_get_utility(struct RIL_Peer_Agent *agent)
968 * @return the social welfare value 1003 * @return the social welfare value
969 */ 1004 */
970static double 1005static double
971ril_network_get_social_welfare(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) 1006ril_network_get_social_welfare (struct GAS_RIL_Handle *solver, struct
1007 RIL_Scope *scope)
972{ 1008{
973 struct RIL_Peer_Agent *cur; 1009 struct RIL_Peer_Agent *cur;
974 double result; 1010 double result;
975 1011
976 switch (solver->parameters.social_welfare) 1012 switch (solver->parameters.social_welfare)
977 { 1013 {
978 case RIL_WELFARE_EGALITARIAN: 1014 case RIL_WELFARE_EGALITARIAN:
979 result = DBL_MAX; 1015 result = DBL_MAX;
980 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1016 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
981 { 1017 {
982 if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) 1018 if (cur->is_active && cur->address_inuse &&
983 { 1019 (cur->address_inuse->solver_information == scope))
984 result = GNUNET_MIN(result, agent_get_utility(cur)); 1020 {
985 } 1021 result = GNUNET_MIN (result, agent_get_utility (cur));
986 } 1022 }
987 return result; 1023 }
988 1024 return result;
989 case RIL_WELFARE_NASH: 1025
990 result = 0; 1026 case RIL_WELFARE_NASH:
991 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1027 result = 0;
992 { 1028 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
993 if (cur->is_active && cur->address_inuse && (cur->address_inuse->solver_information == scope)) 1029 {
994 { 1030 if (cur->is_active && cur->address_inuse &&
995 result *= pow(agent_get_utility(cur), 1.0 / (double)scope->active_agent_count); 1031 (cur->address_inuse->solver_information == scope))
996 } 1032 {
997 } 1033 result *= pow (agent_get_utility (cur), 1.0
998 return result; 1034 / (double) scope->active_agent_count);
999 } 1035 }
1000 GNUNET_assert(GNUNET_NO); 1036 }
1037 return result;
1038 }
1039 GNUNET_assert (GNUNET_NO);
1001 return 1; 1040 return 1;
1002} 1041}
1003 1042
1004static double 1043static double
1005envi_get_penalty(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 1044envi_get_penalty (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1006{ 1045{
1007 struct RIL_Scope *net; 1046 struct RIL_Scope *net;
1008 unsigned long long over_max; 1047 unsigned long long over_max;
@@ -1012,26 +1051,26 @@ envi_get_penalty(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1012 net = agent->address_inuse->solver_information; 1051 net = agent->address_inuse->solver_information;
1013 1052
1014 if (net->bw_in_utilized > net->bw_in_available) 1053 if (net->bw_in_utilized > net->bw_in_available)
1054 {
1055 over_in = net->bw_in_utilized - net->bw_in_available;
1056 if (RIL_ACTION_BW_IN_INC == agent->a_old)
1015 { 1057 {
1016 over_in = net->bw_in_utilized - net->bw_in_available; 1058 /* increase quadratically */
1017 if (RIL_ACTION_BW_IN_INC == agent->a_old) 1059 over_in *= over_in;
1018 {
1019 /* increase quadratically */
1020 over_in *= over_in;
1021 }
1022 } 1060 }
1061 }
1023 if (net->bw_out_utilized > net->bw_out_available) 1062 if (net->bw_out_utilized > net->bw_out_available)
1063 {
1064 over_out = net->bw_out_utilized - net->bw_out_available;
1065 if (RIL_ACTION_BW_OUT_INC == agent->a_old)
1024 { 1066 {
1025 over_out = net->bw_out_utilized - net->bw_out_available; 1067 /* increase quadratically */
1026 if (RIL_ACTION_BW_OUT_INC == agent->a_old) 1068 over_out *= over_out;
1027 {
1028 /* increase quadratically */
1029 over_out *= over_out;
1030 }
1031 } 1069 }
1070 }
1032 over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW); 1071 over_max = (over_in + over_out) / (RIL_MIN_BW * RIL_MIN_BW);
1033 1072
1034 return -1.0 * (double)over_max; 1073 return -1.0 * (double) over_max;
1035} 1074}
1036 1075
1037/** 1076/**
@@ -1044,7 +1083,7 @@ envi_get_penalty(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1044 * @return the reward 1083 * @return the reward
1045 */ 1084 */
1046static double 1085static double
1047envi_get_reward(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 1086envi_get_reward (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1048{ 1087{
1049 struct RIL_Scope *net; 1088 struct RIL_Scope *net;
1050 double objective; 1089 double objective;
@@ -1055,19 +1094,19 @@ envi_get_reward(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1055 1094
1056 net = agent->address_inuse->solver_information; 1095 net = agent->address_inuse->solver_information;
1057 1096
1058 penalty = envi_get_penalty(solver, agent); 1097 penalty = envi_get_penalty (solver, agent);
1059 objective = (agent_get_utility(agent) + net->social_welfare) / 2; 1098 objective = (agent_get_utility (agent) + net->social_welfare) / 2;
1060 delta = objective - agent->objective_old; 1099 delta = objective - agent->objective_old;
1061 agent->objective_old = objective; 1100 agent->objective_old = objective;
1062 1101
1063 if (delta != 0 && penalty == 0) 1102 if ((delta != 0)&&(penalty == 0))
1064 { 1103 {
1065 agent->nop_bonus = delta * RIL_NOP_DECAY; 1104 agent->nop_bonus = delta * RIL_NOP_DECAY;
1066 } 1105 }
1067 else 1106 else
1068 { 1107 {
1069 agent->nop_bonus *= RIL_NOP_DECAY; 1108 agent->nop_bonus *= RIL_NOP_DECAY;
1070 } 1109 }
1071 1110
1072 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0; 1111 steady = (RIL_ACTION_NOTHING == agent->a_old) ? agent->nop_bonus : 0;
1073 1112
@@ -1083,31 +1122,34 @@ envi_get_reward(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1083 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth 1122 * @param direction_in if GNUNET_YES, change inbound bandwidth, otherwise the outbound bandwidth
1084 */ 1123 */
1085static void 1124static void
1086envi_action_bw_double(struct GAS_RIL_Handle *solver, 1125envi_action_bw_double (struct GAS_RIL_Handle *solver,
1087 struct RIL_Peer_Agent *agent, 1126 struct RIL_Peer_Agent *agent,
1088 int direction_in) 1127 int direction_in)
1089{ 1128{
1090 unsigned long long new_bw; 1129 unsigned long long new_bw;
1091 unsigned long long max_bw; 1130 unsigned long long max_bw;
1092 1131
1093 max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); 1132 max_bw = ril_get_max_bw ((struct
1133 RIL_Scope *) agent->address_inuse->
1134 solver_information);
1094 1135
1095 if (direction_in) 1136 if (direction_in)
1096 { 1137 {
1097 new_bw = agent->bw_in * 2; 1138 new_bw = agent->bw_in * 2;
1098 if (new_bw < agent->bw_in || new_bw > max_bw) 1139 if ((new_bw < agent->bw_in) ||(new_bw > max_bw) )
1099 new_bw = max_bw; 1140 new_bw = max_bw;
1100 envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, 1141 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
1101 agent->bw_out, GNUNET_NO); 1142 agent->bw_out, GNUNET_NO);
1102 } 1143 }
1103 else 1144 else
1104 { 1145 {
1105 new_bw = agent->bw_out * 2; 1146 new_bw = agent->bw_out * 2;
1106 if (new_bw < agent->bw_out || new_bw > max_bw) 1147 if ((new_bw < agent->bw_out) ||(new_bw > max_bw) )
1107 new_bw = max_bw; 1148 new_bw = max_bw;
1108 envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, 1149 envi_set_active_suggestion (solver, agent, agent->address_inuse,
1109 new_bw, GNUNET_NO); 1150 agent->bw_in,
1110 } 1151 new_bw, GNUNET_NO);
1152 }
1111} 1153}
1112 1154
1113/** 1155/**
@@ -1120,28 +1162,30 @@ envi_action_bw_double(struct GAS_RIL_Handle *solver,
1120 * bandwidth 1162 * bandwidth
1121 */ 1163 */
1122static void 1164static void
1123envi_action_bw_halven(struct GAS_RIL_Handle *solver, 1165envi_action_bw_halven (struct GAS_RIL_Handle *solver,
1124 struct RIL_Peer_Agent *agent, 1166 struct RIL_Peer_Agent *agent,
1125 int direction_in) 1167 int direction_in)
1126{ 1168{
1127 unsigned long long new_bw; 1169 unsigned long long new_bw;
1128 1170
1129 if (direction_in) 1171 if (direction_in)
1130 { 1172 {
1131 new_bw = agent->bw_in / 2; 1173 new_bw = agent->bw_in / 2;
1132 if (new_bw <= 0 || new_bw > agent->bw_in) 1174 if ((new_bw <= 0) ||(new_bw > agent->bw_in) )
1133 new_bw = 0; 1175 new_bw = 0;
1134 envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, 1176 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
1135 GNUNET_NO); 1177 agent->bw_out,
1136 } 1178 GNUNET_NO);
1179 }
1137 else 1180 else
1138 { 1181 {
1139 new_bw = agent->bw_out / 2; 1182 new_bw = agent->bw_out / 2;
1140 if (new_bw <= 0 || new_bw > agent->bw_out) 1183 if ((new_bw <= 0) ||(new_bw > agent->bw_out) )
1141 new_bw = 0; 1184 new_bw = 0;
1142 envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, 1185 envi_set_active_suggestion (solver, agent, agent->address_inuse,
1143 GNUNET_NO); 1186 agent->bw_in, new_bw,
1144 } 1187 GNUNET_NO);
1188 }
1145} 1189}
1146 1190
1147/** 1191/**
@@ -1153,29 +1197,33 @@ envi_action_bw_halven(struct GAS_RIL_Handle *solver,
1153 * bandwidth 1197 * bandwidth
1154 */ 1198 */
1155static void 1199static void
1156envi_action_bw_inc(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) 1200envi_action_bw_inc (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
1201 int direction_in)
1157{ 1202{
1158 unsigned long long new_bw; 1203 unsigned long long new_bw;
1159 unsigned long long max_bw; 1204 unsigned long long max_bw;
1160 1205
1161 max_bw = ril_get_max_bw((struct RIL_Scope *)agent->address_inuse->solver_information); 1206 max_bw = ril_get_max_bw ((struct
1207 RIL_Scope *) agent->address_inuse->
1208 solver_information);
1162 1209
1163 if (direction_in) 1210 if (direction_in)
1164 { 1211 {
1165 new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); 1212 new_bw = agent->bw_in + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW);
1166 if (new_bw < agent->bw_in || new_bw > max_bw) 1213 if ((new_bw < agent->bw_in) ||(new_bw > max_bw) )
1167 new_bw = max_bw; 1214 new_bw = max_bw;
1168 envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, 1215 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
1169 agent->bw_out, GNUNET_NO); 1216 agent->bw_out, GNUNET_NO);
1170 } 1217 }
1171 else 1218 else
1172 { 1219 {
1173 new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); 1220 new_bw = agent->bw_out + (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW);
1174 if (new_bw < agent->bw_out || new_bw > max_bw) 1221 if ((new_bw < agent->bw_out) ||(new_bw > max_bw) )
1175 new_bw = max_bw; 1222 new_bw = max_bw;
1176 envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, 1223 envi_set_active_suggestion (solver, agent, agent->address_inuse,
1177 new_bw, GNUNET_NO); 1224 agent->bw_in,
1178 } 1225 new_bw, GNUNET_NO);
1226 }
1179} 1227}
1180 1228
1181/** 1229/**
@@ -1188,26 +1236,29 @@ envi_action_bw_inc(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
1188 * bandwidth 1236 * bandwidth
1189 */ 1237 */
1190static void 1238static void
1191envi_action_bw_dec(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int direction_in) 1239envi_action_bw_dec (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
1240 int direction_in)
1192{ 1241{
1193 unsigned long long new_bw; 1242 unsigned long long new_bw;
1194 1243
1195 if (direction_in) 1244 if (direction_in)
1196 { 1245 {
1197 new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); 1246 new_bw = agent->bw_in - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW);
1198 if (new_bw <= 0 || new_bw > agent->bw_in) 1247 if ((new_bw <= 0) ||(new_bw > agent->bw_in) )
1199 new_bw = 0; 1248 new_bw = 0;
1200 envi_set_active_suggestion(solver, agent, agent->address_inuse, new_bw, agent->bw_out, 1249 envi_set_active_suggestion (solver, agent, agent->address_inuse, new_bw,
1201 GNUNET_NO); 1250 agent->bw_out,
1202 } 1251 GNUNET_NO);
1252 }
1203 else 1253 else
1204 { 1254 {
1205 new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW); 1255 new_bw = agent->bw_out - (RIL_INC_DEC_STEP_SIZE * RIL_MIN_BW);
1206 if (new_bw <= 0 || new_bw > agent->bw_out) 1256 if ((new_bw <= 0) ||(new_bw > agent->bw_out) )
1207 new_bw = 0; 1257 new_bw = 0;
1208 envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, new_bw, 1258 envi_set_active_suggestion (solver, agent, agent->address_inuse,
1209 GNUNET_NO); 1259 agent->bw_in, new_bw,
1210 } 1260 GNUNET_NO);
1261 }
1211} 1262}
1212 1263
1213/** 1264/**
@@ -1218,29 +1269,30 @@ envi_action_bw_dec(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent,
1218 * @param address_index index of the address as it is saved in the agent's list, starting with zero 1269 * @param address_index index of the address as it is saved in the agent's list, starting with zero
1219 */ 1270 */
1220static void 1271static void
1221envi_action_address_switch(struct GAS_RIL_Handle *solver, 1272envi_action_address_switch (struct GAS_RIL_Handle *solver,
1222 struct RIL_Peer_Agent *agent, 1273 struct RIL_Peer_Agent *agent,
1223 unsigned int address_index) 1274 unsigned int address_index)
1224{ 1275{
1225 struct RIL_Address_Wrapped *cur; 1276 struct RIL_Address_Wrapped *cur;
1226 int i = 0; 1277 int i = 0;
1227 1278
1228 //cur = agent_address_get_wrapped(agent, agent->address_inuse); 1279 // cur = agent_address_get_wrapped(agent, agent->address_inuse);
1229 1280
1230 for (cur = agent->addresses_head; NULL != cur; cur = cur->next) 1281 for (cur = agent->addresses_head; NULL != cur; cur = cur->next)
1282 {
1283 if (i == address_index)
1231 { 1284 {
1232 if (i == address_index) 1285 envi_set_active_suggestion (solver, agent, cur->address_naked,
1233 { 1286 agent->bw_in, agent->bw_out,
1234 envi_set_active_suggestion(solver, agent, cur->address_naked, agent->bw_in, agent->bw_out, 1287 GNUNET_NO);
1235 GNUNET_NO); 1288 return;
1236 return;
1237 }
1238
1239 i++;
1240 } 1289 }
1241 1290
1242 //no address with address_index exists, in this case this action should not be callable 1291 i++;
1243 GNUNET_assert(GNUNET_NO); 1292 }
1293
1294 // no address with address_index exists, in this case this action should not be callable
1295 GNUNET_assert (GNUNET_NO);
1244} 1296}
1245 1297
1246/** 1298/**
@@ -1251,62 +1303,65 @@ envi_action_address_switch(struct GAS_RIL_Handle *solver,
1251 * @param action the action to perform by the solver 1303 * @param action the action to perform by the solver
1252 */ 1304 */
1253static void 1305static void
1254envi_do_action(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int action) 1306envi_do_action (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int
1307 action)
1255{ 1308{
1256 int address_index; 1309 int address_index;
1257 1310
1258 switch (action) 1311 switch (action)
1259 { 1312 {
1260 case RIL_ACTION_NOTHING: 1313 case RIL_ACTION_NOTHING:
1261 break; 1314 break;
1262 1315
1263 case RIL_ACTION_BW_IN_DBL: 1316 case RIL_ACTION_BW_IN_DBL:
1264 envi_action_bw_double(solver, agent, GNUNET_YES); 1317 envi_action_bw_double (solver, agent, GNUNET_YES);
1265 break; 1318 break;
1266 1319
1267 case RIL_ACTION_BW_IN_HLV: 1320 case RIL_ACTION_BW_IN_HLV:
1268 envi_action_bw_halven(solver, agent, GNUNET_YES); 1321 envi_action_bw_halven (solver, agent, GNUNET_YES);
1269 break; 1322 break;
1270 1323
1271 case RIL_ACTION_BW_IN_INC: 1324 case RIL_ACTION_BW_IN_INC:
1272 envi_action_bw_inc(solver, agent, GNUNET_YES); 1325 envi_action_bw_inc (solver, agent, GNUNET_YES);
1273 break; 1326 break;
1274 1327
1275 case RIL_ACTION_BW_IN_DEC: 1328 case RIL_ACTION_BW_IN_DEC:
1276 envi_action_bw_dec(solver, agent, GNUNET_YES); 1329 envi_action_bw_dec (solver, agent, GNUNET_YES);
1277 break; 1330 break;
1278 1331
1279 case RIL_ACTION_BW_OUT_DBL: 1332 case RIL_ACTION_BW_OUT_DBL:
1280 envi_action_bw_double(solver, agent, GNUNET_NO); 1333 envi_action_bw_double (solver, agent, GNUNET_NO);
1281 break; 1334 break;
1282 1335
1283 case RIL_ACTION_BW_OUT_HLV: 1336 case RIL_ACTION_BW_OUT_HLV:
1284 envi_action_bw_halven(solver, agent, GNUNET_NO); 1337 envi_action_bw_halven (solver, agent, GNUNET_NO);
1285 break; 1338 break;
1286 1339
1287 case RIL_ACTION_BW_OUT_INC: 1340 case RIL_ACTION_BW_OUT_INC:
1288 envi_action_bw_inc(solver, agent, GNUNET_NO); 1341 envi_action_bw_inc (solver, agent, GNUNET_NO);
1289 break; 1342 break;
1290 1343
1291 case RIL_ACTION_BW_OUT_DEC: 1344 case RIL_ACTION_BW_OUT_DEC:
1292 envi_action_bw_dec(solver, agent, GNUNET_NO); 1345 envi_action_bw_dec (solver, agent, GNUNET_NO);
1293 break; 1346 break;
1294 1347
1295 default: 1348 default:
1296 if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) //switch address action 1349 if ((action >= RIL_ACTION_TYPE_NUM) && (action < agent->n)) // switch address action
1297 { 1350 {
1298 address_index = action - RIL_ACTION_TYPE_NUM; 1351 address_index = action - RIL_ACTION_TYPE_NUM;
1299 1352
1300 GNUNET_assert(address_index >= 0); 1353 GNUNET_assert (address_index >= 0);
1301 GNUNET_assert( 1354 GNUNET_assert (
1302 address_index <= agent_address_get_index(agent, agent->addresses_tail->address_naked)); 1355 address_index <= agent_address_get_index (agent,
1356 agent->addresses_tail->
1357 address_naked));
1303 1358
1304 envi_action_address_switch(solver, agent, address_index); 1359 envi_action_address_switch (solver, agent, address_index);
1305 break; 1360 break;
1306 }
1307 // error - action does not exist
1308 GNUNET_assert(GNUNET_NO);
1309 } 1361 }
1362 // error - action does not exist
1363 GNUNET_assert (GNUNET_NO);
1364 }
1310} 1365}
1311 1366
1312/** 1367/**
@@ -1321,27 +1376,28 @@ envi_do_action(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int
1321 * @return the action index 1376 * @return the action index
1322 */ 1377 */
1323static int 1378static int
1324agent_select_egreedy(struct RIL_Peer_Agent *agent, double *state) 1379agent_select_egreedy (struct RIL_Peer_Agent *agent, double *state)
1325{ 1380{
1326 int action; 1381 int action;
1327 double r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1382 double r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1328 UINT32_MAX) / (double)UINT32_MAX; 1383 UINT32_MAX)
1329 1384 / (double) UINT32_MAX;
1330 if (r < agent->envi->parameters.epsilon) //explore 1385
1331 { 1386 if (r < agent->envi->parameters.epsilon) // explore
1332 action = agent_get_action_random(agent); 1387 {
1333 if (RIL_ALGO_Q == agent->envi->parameters.algorithm) 1388 action = agent_get_action_random (agent);
1334 { 1389 if (RIL_ALGO_Q == agent->envi->parameters.algorithm)
1335 agent->eligibility_reset = GNUNET_YES; 1390 {
1336 } 1391 agent->eligibility_reset = GNUNET_YES;
1337 agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay; 1392 }
1338 return action; 1393 agent->envi->parameters.epsilon *= agent->envi->parameters.epsilon_decay;
1339 } 1394 return action;
1340 else //exploit 1395 }
1341 { 1396 else // exploit
1342 action = agent_get_action_max(agent, state); 1397 {
1343 return action; 1398 action = agent_get_action_max (agent, state);
1344 } 1399 return action;
1400 }
1345} 1401}
1346 1402
1347/** 1403/**
@@ -1355,7 +1411,7 @@ agent_select_egreedy(struct RIL_Peer_Agent *agent, double *state)
1355 * @return 1411 * @return
1356 */ 1412 */
1357static int 1413static int
1358agent_select_softmax(struct RIL_Peer_Agent *agent, double *state) 1414agent_select_softmax (struct RIL_Peer_Agent *agent, double *state)
1359{ 1415{
1360 int i; 1416 int i;
1361 int a_max; 1417 int a_max;
@@ -1364,47 +1420,49 @@ agent_select_softmax(struct RIL_Peer_Agent *agent, double *state)
1364 double sum = 0; 1420 double sum = 0;
1365 double r; 1421 double r;
1366 1422
1367 a_max = agent_get_action_max(agent, state); 1423 a_max = agent_get_action_max (agent, state);
1368 1424
1369 for (i = 0; i < agent->n; i++) 1425 for (i = 0; i < agent->n; i++)
1426 {
1427 if (agent_action_is_possible (agent, i))
1370 { 1428 {
1371 if (agent_action_is_possible(agent, i)) 1429 eqt[i] = exp (agent_q (agent, state, i)
1372 { 1430 / agent->envi->parameters.temperature);
1373 eqt[i] = exp(agent_q(agent, state, i) / agent->envi->parameters.temperature); 1431 if (isinf (eqt[i]))
1374 if (isinf(eqt[i])) 1432 eqt[i] = isinf (eqt[i]) * UINT32_MAX;
1375 eqt[i] = isinf(eqt[i]) * UINT32_MAX; 1433 sum += eqt[i];
1376 sum += eqt[i];
1377 }
1378 } 1434 }
1435 }
1379 for (i = 0; i < agent->n; i++) 1436 for (i = 0; i < agent->n; i++)
1437 {
1438 if (agent_action_is_possible (agent, i))
1380 { 1439 {
1381 if (agent_action_is_possible(agent, i)) 1440 p[i] = eqt[i] / sum;
1382 { 1441 }
1383 p[i] = eqt[i] / sum; 1442 else
1384 } 1443 {
1385 else 1444 p[i] = 0;
1386 {
1387 p[i] = 0;
1388 }
1389 } 1445 }
1390 r = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1446 }
1391 UINT32_MAX) / (double)UINT32_MAX; 1447 r = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
1448 UINT32_MAX) / (double) UINT32_MAX;
1392 sum = 0; 1449 sum = 0;
1393 for (i = 0; i < agent->n; i++) 1450 for (i = 0; i < agent->n; i++)
1451 {
1452 if (sum + p[i] > r)
1394 { 1453 {
1395 if (sum + p[i] > r) 1454 if (i != a_max)
1396 { 1455 {
1397 if (i != a_max) 1456 if (RIL_ALGO_Q == agent->envi->parameters.algorithm)
1398 { 1457 agent->eligibility_reset = GNUNET_YES;
1399 if (RIL_ALGO_Q == agent->envi->parameters.algorithm) 1458 agent->envi->parameters.temperature *=
1400 agent->eligibility_reset = GNUNET_YES; 1459 agent->envi->parameters.temperature_decay;
1401 agent->envi->parameters.temperature *= agent->envi->parameters.temperature_decay; 1460 }
1402 } 1461 return i;
1403 return i; 1462 }
1404 } 1463 sum += p[i];
1405 sum += p[i]; 1464 }
1406 } 1465 GNUNET_assert (GNUNET_NO);
1407 GNUNET_assert(GNUNET_NO);
1408 return RIL_ACTION_INVALID; 1466 return RIL_ACTION_INVALID;
1409} 1467}
1410 1468
@@ -1417,16 +1475,16 @@ agent_select_softmax(struct RIL_Peer_Agent *agent, double *state)
1417 * @return the action index 1475 * @return the action index
1418 */ 1476 */
1419static int 1477static int
1420agent_select_action(struct RIL_Peer_Agent *agent, double *state) 1478agent_select_action (struct RIL_Peer_Agent *agent, double *state)
1421{ 1479{
1422 if (agent->envi->parameters.select == RIL_SELECT_EGREEDY) 1480 if (agent->envi->parameters.select == RIL_SELECT_EGREEDY)
1423 { 1481 {
1424 return agent_select_egreedy(agent, state); 1482 return agent_select_egreedy (agent, state);
1425 } 1483 }
1426 else 1484 else
1427 { 1485 {
1428 return agent_select_softmax(agent, state); 1486 return agent_select_softmax (agent, state);
1429 } 1487 }
1430} 1488}
1431 1489
1432/** 1490/**
@@ -1438,68 +1496,71 @@ agent_select_action(struct RIL_Peer_Agent *agent, double *state)
1438 * @param agent the agent performing the step 1496 * @param agent the agent performing the step
1439 */ 1497 */
1440static void 1498static void
1441agent_step(struct RIL_Peer_Agent *agent) 1499agent_step (struct RIL_Peer_Agent *agent)
1442{ 1500{
1443 int a_next = RIL_ACTION_INVALID; 1501 int a_next = RIL_ACTION_INVALID;
1444 int a_max; 1502 int a_max;
1445 double *s_next; 1503 double *s_next;
1446 double reward; 1504 double reward;
1447 1505
1448 LOG(GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n", 1506 LOG (GNUNET_ERROR_TYPE_DEBUG, " agent_step() Peer '%s', algorithm %s\n",
1449 GNUNET_i2s(&agent->peer), 1507 GNUNET_i2s (&agent->peer),
1450 agent->envi->parameters.algorithm ? "Q" : "SARSA"); 1508 agent->envi->parameters.algorithm ? "Q" : "SARSA");
1451 1509
1452 s_next = envi_get_state(agent->envi, agent); 1510 s_next = envi_get_state (agent->envi, agent);
1453 reward = envi_get_reward(agent->envi, agent); 1511 reward = envi_get_reward (agent->envi, agent);
1454 1512
1455 if (agent->eligibility_reset) 1513 if (agent->eligibility_reset)
1456 { 1514 {
1457 agent_modify_eligibility(agent, RIL_E_ZERO, NULL, -1); 1515 agent_modify_eligibility (agent, RIL_E_ZERO, NULL, -1);
1458 agent->eligibility_reset = GNUNET_NO; 1516 agent->eligibility_reset = GNUNET_NO;
1459 } 1517 }
1460 else 1518 else
1461 { 1519 {
1462 agent_modify_eligibility(agent, RIL_E_DECAY, NULL, -1); 1520 agent_modify_eligibility (agent, RIL_E_DECAY, NULL, -1);
1463 } 1521 }
1464 if (RIL_ACTION_INVALID != agent->a_old) 1522 if (RIL_ACTION_INVALID != agent->a_old)
1465 { 1523 {
1466 agent_modify_eligibility(agent, agent->envi->parameters.eligibility_trace_mode, agent->s_old, agent->a_old); 1524 agent_modify_eligibility (agent,
1467 } 1525 agent->envi->parameters.eligibility_trace_mode,
1526 agent->s_old, agent->a_old);
1527 }
1468 1528
1469 switch (agent->envi->parameters.algorithm) 1529 switch (agent->envi->parameters.algorithm)
1530 {
1531 case RIL_ALGO_SARSA:
1532 a_next = agent_select_action (agent, s_next);
1533 if (RIL_ACTION_INVALID != agent->a_old)
1470 { 1534 {
1471 case RIL_ALGO_SARSA: 1535 // updates weights with selected action (on-policy), if not first step
1472 a_next = agent_select_action(agent, s_next); 1536 agent_update (agent, reward, s_next, a_next);
1473 if (RIL_ACTION_INVALID != agent->a_old) 1537 }
1474 { 1538 break;
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 1539
1480 case RIL_ALGO_Q: 1540 case RIL_ALGO_Q:
1481 a_max = agent_get_action_max(agent, s_next); 1541 a_max = agent_get_action_max (agent, s_next);
1482 if (RIL_ACTION_INVALID != agent->a_old) 1542 if (RIL_ACTION_INVALID != agent->a_old)
1483 { 1543 {
1484 //updates weights with best action, disregarding actually selected action (off-policy), if not first step 1544 // updates weights with best action, disregarding actually selected action (off-policy), if not first step
1485 agent_update(agent, reward, s_next, a_max); 1545 agent_update (agent, reward, s_next, a_max);
1486 }
1487 a_next = agent_select_action(agent, s_next);
1488 break;
1489 } 1546 }
1547 a_next = agent_select_action (agent, s_next);
1548 break;
1549 }
1490 1550
1491 GNUNET_assert(RIL_ACTION_INVALID != a_next); 1551 GNUNET_assert (RIL_ACTION_INVALID != a_next);
1492 1552
1493 LOG(GNUNET_ERROR_TYPE_DEBUG, "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n", 1553 LOG (GNUNET_ERROR_TYPE_DEBUG,
1494 agent->step_count, 1554 "step() Step# %llu R: %f IN %llu OUT %llu A: %d\n",
1495 reward, 1555 agent->step_count,
1496 agent->bw_in / 1024, 1556 reward,
1497 agent->bw_out / 1024, 1557 agent->bw_in / 1024,
1498 a_next); 1558 agent->bw_out / 1024,
1559 a_next);
1499 1560
1500 envi_do_action(agent->envi, agent, a_next); 1561 envi_do_action (agent->envi, agent, a_next);
1501 1562
1502 GNUNET_free(agent->s_old); 1563 GNUNET_free (agent->s_old);
1503 agent->s_old = s_next; 1564 agent->s_old = s_next;
1504 agent->a_old = a_next; 1565 agent->a_old = a_next;
1505 1566
@@ -1512,7 +1573,7 @@ agent_step(struct RIL_Peer_Agent *agent)
1512 * @param solver the solver handle 1573 * @param solver the solver handle
1513 */ 1574 */
1514static void 1575static void
1515ril_step(struct GAS_RIL_Handle *solver); 1576ril_step (struct GAS_RIL_Handle *solver);
1516 1577
1517 1578
1518/** 1579/**
@@ -1522,12 +1583,12 @@ ril_step(struct GAS_RIL_Handle *solver);
1522 * @param cls the solver handle 1583 * @param cls the solver handle
1523 */ 1584 */
1524static void 1585static void
1525ril_step_scheduler_task(void *cls) 1586ril_step_scheduler_task (void *cls)
1526{ 1587{
1527 struct GAS_RIL_Handle *solver = cls; 1588 struct GAS_RIL_Handle *solver = cls;
1528 1589
1529 solver->step_next_task_id = NULL; 1590 solver->step_next_task_id = NULL;
1530 ril_step(solver); 1591 ril_step (solver);
1531} 1592}
1532 1593
1533/** 1594/**
@@ -1539,7 +1600,7 @@ ril_step_scheduler_task(void *cls)
1539 * @return the ratio 1600 * @return the ratio
1540 */ 1601 */
1541static double 1602static double
1542ril_get_used_resource_ratio(struct GAS_RIL_Handle *solver) 1603ril_get_used_resource_ratio (struct GAS_RIL_Handle *solver)
1543{ 1604{
1544 int i; 1605 int i;
1545 struct RIL_Scope net; 1606 struct RIL_Scope net;
@@ -1548,26 +1609,26 @@ ril_get_used_resource_ratio(struct GAS_RIL_Handle *solver)
1548 double ratio; 1609 double ratio;
1549 1610
1550 for (i = 0; i < solver->networks_count; i++) 1611 for (i = 0; i < solver->networks_count; i++)
1612 {
1613 net = solver->network_entries[i];
1614 if (net.bw_in_assigned > 0) // only consider scopes where an address is actually active
1551 { 1615 {
1552 net = solver->network_entries[i]; 1616 sum_assigned += net.bw_in_utilized;
1553 if (net.bw_in_assigned > 0) //only consider scopes where an address is actually active 1617 sum_assigned += net.bw_out_utilized;
1554 { 1618 sum_available += net.bw_in_available;
1555 sum_assigned += net.bw_in_utilized; 1619 sum_available += net.bw_out_available;
1556 sum_assigned += net.bw_out_utilized;
1557 sum_available += net.bw_in_available;
1558 sum_available += net.bw_out_available;
1559 }
1560 } 1620 }
1621 }
1561 if (sum_available > 0) 1622 if (sum_available > 0)
1562 { 1623 {
1563 ratio = ((double)sum_assigned) / ((double)sum_available); 1624 ratio = ((double) sum_assigned) / ((double) sum_available);
1564 } 1625 }
1565 else 1626 else
1566 { 1627 {
1567 ratio = 0; 1628 ratio = 0;
1568 } 1629 }
1569 1630
1570 return ratio > 1 ? 1 : ratio; //overutilization is possible, cap at 1 1631 return ratio > 1 ? 1 : ratio; // overutilization is possible, cap at 1
1571} 1632}
1572 1633
1573/** 1634/**
@@ -1578,17 +1639,17 @@ ril_get_used_resource_ratio(struct GAS_RIL_Handle *solver)
1578 * @return the network struct 1639 * @return the network struct
1579 */ 1640 */
1580static struct RIL_Scope * 1641static struct RIL_Scope *
1581ril_get_network(struct GAS_RIL_Handle *s, uint32_t type) 1642ril_get_network (struct GAS_RIL_Handle *s, uint32_t type)
1582{ 1643{
1583 int i; 1644 int i;
1584 1645
1585 for (i = 0; i < s->networks_count; i++) 1646 for (i = 0; i < s->networks_count; i++)
1647 {
1648 if (s->network_entries[i].type == type)
1586 { 1649 {
1587 if (s->network_entries[i].type == type) 1650 return &s->network_entries[i];
1588 {
1589 return &s->network_entries[i];
1590 }
1591 } 1651 }
1652 }
1592 return NULL; 1653 return NULL;
1593} 1654}
1594 1655
@@ -1602,26 +1663,28 @@ ril_get_network(struct GAS_RIL_Handle *s, uint32_t type)
1602 * @return GNUNET_YES if there are theoretically enough resources left 1663 * @return GNUNET_YES if there are theoretically enough resources left
1603 */ 1664 */
1604static int 1665static int
1605ril_network_is_not_full(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) 1666ril_network_is_not_full (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
1667 network)
1606{ 1668{
1607 struct RIL_Scope *net; 1669 struct RIL_Scope *net;
1608 struct RIL_Peer_Agent *agent; 1670 struct RIL_Peer_Agent *agent;
1609 unsigned long long address_count = 0; 1671 unsigned long long address_count = 0;
1610 1672
1611 for (agent = solver->agents_head; NULL != agent; agent = agent->next) 1673 for (agent = solver->agents_head; NULL != agent; agent = agent->next)
1674 {
1675 if (agent->address_inuse && agent->is_active)
1612 { 1676 {
1613 if (agent->address_inuse && agent->is_active) 1677 net = agent->address_inuse->solver_information;
1614 { 1678 if (net->type == network)
1615 net = agent->address_inuse->solver_information; 1679 {
1616 if (net->type == network) 1680 address_count++;
1617 { 1681 }
1618 address_count++;
1619 }
1620 }
1621 } 1682 }
1683 }
1622 1684
1623 net = ril_get_network(solver, network); 1685 net = ril_get_network (solver, network);
1624 return (net->bw_in_available > RIL_MIN_BW * address_count) && (net->bw_out_available > RIL_MIN_BW * address_count); 1686 return (net->bw_in_available > RIL_MIN_BW * address_count) &&
1687 (net->bw_out_available > RIL_MIN_BW * address_count);
1625} 1688}
1626 1689
1627/** 1690/**
@@ -1635,27 +1698,34 @@ ril_network_is_not_full(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType n
1635 * @param silent 1698 * @param silent
1636 */ 1699 */
1637static void 1700static void
1638ril_try_unblock_agent(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent, int silent) 1701ril_try_unblock_agent (struct GAS_RIL_Handle *solver, struct
1702 RIL_Peer_Agent *agent, int silent)
1639{ 1703{
1640 struct RIL_Address_Wrapped *addr_wrap; 1704 struct RIL_Address_Wrapped *addr_wrap;
1641 struct RIL_Scope *net; 1705 struct RIL_Scope *net;
1642 unsigned long long start_in; 1706 unsigned long long start_in;
1643 unsigned long long start_out; 1707 unsigned long long start_out;
1644 1708
1645 for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap = addr_wrap->next) 1709 for (addr_wrap = agent->addresses_head; NULL != addr_wrap; addr_wrap =
1646 { 1710 addr_wrap->next)
1647 net = addr_wrap->address_naked->solver_information; 1711 {
1648 if (ril_network_is_not_full(solver, net->type)) 1712 net = addr_wrap->address_naked->solver_information;
1649 { 1713 if (ril_network_is_not_full (solver, net->type))
1650 if (NULL == agent->address_inuse) 1714 {
1651 { 1715 if (NULL == agent->address_inuse)
1652 start_in = net->bw_in_available < net->bw_in_utilized ? (net->bw_in_available - net->bw_in_utilized) / 2 : RIL_MIN_BW; 1716 {
1653 start_out = net->bw_out_available < net->bw_out_utilized ? (net->bw_out_available - net->bw_out_utilized) / 2 : RIL_MIN_BW; 1717 start_in = net->bw_in_available < net->bw_in_utilized ?
1654 envi_set_active_suggestion(solver, agent, addr_wrap->address_naked, start_in, start_out, silent); 1718 (net->bw_in_available - net->bw_in_utilized) / 2 :
1655 } 1719 RIL_MIN_BW;
1656 return; 1720 start_out = net->bw_out_available < net->bw_out_utilized ?
1657 } 1721 (net->bw_out_available - net->bw_out_utilized) / 2 :
1722 RIL_MIN_BW;
1723 envi_set_active_suggestion (solver, agent, addr_wrap->address_naked,
1724 start_in, start_out, silent);
1725 }
1726 return;
1658 } 1727 }
1728 }
1659 agent->address_inuse = NULL; 1729 agent->address_inuse = NULL;
1660} 1730}
1661 1731
@@ -1666,7 +1736,7 @@ ril_try_unblock_agent(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agen
1666 * @param solver the solver handle 1736 * @param solver the solver handle
1667 */ 1737 */
1668static void 1738static void
1669ril_calculate_discount(struct GAS_RIL_Handle *solver) 1739ril_calculate_discount (struct GAS_RIL_Handle *solver)
1670{ 1740{
1671 struct GNUNET_TIME_Absolute time_now; 1741 struct GNUNET_TIME_Absolute time_now;
1672 struct GNUNET_TIME_Relative time_delta; 1742 struct GNUNET_TIME_Relative time_delta;
@@ -1674,25 +1744,28 @@ ril_calculate_discount(struct GAS_RIL_Handle *solver)
1674 1744
1675 // MDP case only for debugging purposes 1745 // MDP case only for debugging purposes
1676 if (solver->simulate) 1746 if (solver->simulate)
1677 { 1747 {
1678 solver->global_discount_variable = solver->parameters.gamma; 1748 solver->global_discount_variable = solver->parameters.gamma;
1679 solver->global_discount_integrated = 1; 1749 solver->global_discount_integrated = 1;
1680 return; 1750 return;
1681 } 1751 }
1682 1752
1683 // semi-MDP case 1753 // semi-MDP case
1684 1754
1685 //calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step 1755 // calculate tau, i.e. how many real valued time units have passed, one time unit is one minimum time step
1686 time_now = GNUNET_TIME_absolute_get(); 1756 time_now = GNUNET_TIME_absolute_get ();
1687 time_delta = GNUNET_TIME_absolute_get_difference(solver->step_time_last, time_now); 1757 time_delta = GNUNET_TIME_absolute_get_difference (solver->step_time_last,
1758 time_now);
1688 solver->step_time_last = time_now; 1759 solver->step_time_last = time_now;
1689 tau = (double)time_delta.rel_value_us 1760 tau = (double) time_delta.rel_value_us
1690 / (double)solver->parameters.step_time_min.rel_value_us; 1761 / (double) solver->parameters.step_time_min.rel_value_us;
1691 1762
1692 //calculate reward discounts (once per step for all agents) 1763 // calculate reward discounts (once per step for all agents)
1693 solver->global_discount_variable = pow(M_E, ((-1.0) * ((double)solver->parameters.beta) * tau)); 1764 solver->global_discount_variable = pow (M_E, ((-1.0)
1765 * ((double) solver->parameters.
1766 beta) * tau));
1694 solver->global_discount_integrated = (1.0 - solver->global_discount_variable) 1767 solver->global_discount_integrated = (1.0 - solver->global_discount_variable)
1695 / (double)solver->parameters.beta; 1768 / (double) solver->parameters.beta;
1696} 1769}
1697 1770
1698/** 1771/**
@@ -1703,18 +1776,21 @@ ril_calculate_discount(struct GAS_RIL_Handle *solver)
1703 * @return the number of allocated connections 1776 * @return the number of allocated connections
1704 */ 1777 */
1705static int 1778static int
1706ril_network_count_active_agents(struct GAS_RIL_Handle *solver, struct RIL_Scope *scope) 1779ril_network_count_active_agents (struct GAS_RIL_Handle *solver, struct
1780 RIL_Scope *scope)
1707{ 1781{
1708 int c = 0; 1782 int c = 0;
1709 struct RIL_Peer_Agent *cur_agent; 1783 struct RIL_Peer_Agent *cur_agent;
1710 1784
1711 for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent = cur_agent->next) 1785 for (cur_agent = solver->agents_head; NULL != cur_agent; cur_agent =
1786 cur_agent->next)
1787 {
1788 if (cur_agent->is_active && cur_agent->address_inuse &&
1789 (cur_agent->address_inuse->solver_information == scope))
1712 { 1790 {
1713 if (cur_agent->is_active && cur_agent->address_inuse && (cur_agent->address_inuse->solver_information == scope)) 1791 c++;
1714 {
1715 c++;
1716 }
1717 } 1792 }
1793 }
1718 return c; 1794 return c;
1719} 1795}
1720 1796
@@ -1729,26 +1805,27 @@ ril_network_count_active_agents(struct GAS_RIL_Handle *solver, struct RIL_Scope
1729 * @return the sum of the assigned bandwidths 1805 * @return the sum of the assigned bandwidths
1730 */ 1806 */
1731static unsigned long long 1807static unsigned long long
1732ril_network_get_assigned(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) 1808ril_network_get_assigned (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
1809 type, int direction_in)
1733{ 1810{
1734 struct RIL_Peer_Agent *cur; 1811 struct RIL_Peer_Agent *cur;
1735 struct RIL_Scope *net; 1812 struct RIL_Scope *net;
1736 unsigned long long sum = 0; 1813 unsigned long long sum = 0;
1737 1814
1738 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1815 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1816 {
1817 if (cur->is_active && cur->address_inuse)
1739 { 1818 {
1740 if (cur->is_active && cur->address_inuse) 1819 net = cur->address_inuse->solver_information;
1741 { 1820 if (net->type == type)
1742 net = cur->address_inuse->solver_information; 1821 {
1743 if (net->type == type) 1822 if (direction_in)
1744 { 1823 sum += cur->bw_in;
1745 if (direction_in) 1824 else
1746 sum += cur->bw_in; 1825 sum += cur->bw_out;
1747 else 1826 }
1748 sum += cur->bw_out;
1749 }
1750 }
1751 } 1827 }
1828 }
1752 1829
1753 return sum; 1830 return sum;
1754} 1831}
@@ -1764,26 +1841,27 @@ ril_network_get_assigned(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
1764 * @return the sum of the utilized bandwidths (in bytes/second) 1841 * @return the sum of the utilized bandwidths (in bytes/second)
1765 */ 1842 */
1766static unsigned long long 1843static unsigned long long
1767ril_network_get_utilized(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType type, int direction_in) 1844ril_network_get_utilized (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
1845 type, int direction_in)
1768{ 1846{
1769 struct RIL_Peer_Agent *cur; 1847 struct RIL_Peer_Agent *cur;
1770 struct RIL_Scope *net; 1848 struct RIL_Scope *net;
1771 unsigned long long sum = 0; 1849 unsigned long long sum = 0;
1772 1850
1773 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1851 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1852 {
1853 if (cur->is_active && cur->address_inuse)
1774 { 1854 {
1775 if (cur->is_active && cur->address_inuse) 1855 net = cur->address_inuse->solver_information;
1776 { 1856 if (net->type == type)
1777 net = cur->address_inuse->solver_information; 1857 {
1778 if (net->type == type) 1858 if (direction_in)
1779 { 1859 sum += cur->address_inuse->norm_utilization_in.norm;
1780 if (direction_in) 1860 else
1781 sum += cur->address_inuse->norm_utilization_in.norm; 1861 sum += cur->address_inuse->norm_utilization_out.norm;
1782 else 1862 }
1783 sum += cur->address_inuse->norm_utilization_out.norm;
1784 }
1785 }
1786 } 1863 }
1864 }
1787 1865
1788 return sum; 1866 return sum;
1789} 1867}
@@ -1795,21 +1873,25 @@ ril_network_get_utilized(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
1795 * @param solver the solver handle 1873 * @param solver the solver handle
1796 */ 1874 */
1797static void 1875static void
1798ril_networks_update_state(struct GAS_RIL_Handle *solver) 1876ril_networks_update_state (struct GAS_RIL_Handle *solver)
1799{ 1877{
1800 int c; 1878 int c;
1801 struct RIL_Scope *net; 1879 struct RIL_Scope *net;
1802 1880
1803 for (c = 0; c < solver->networks_count; c++) 1881 for (c = 0; c < solver->networks_count; c++)
1804 { 1882 {
1805 net = &solver->network_entries[c]; 1883 net = &solver->network_entries[c];
1806 net->bw_in_assigned = ril_network_get_assigned(solver, net->type, GNUNET_YES); 1884 net->bw_in_assigned = ril_network_get_assigned (solver, net->type,
1807 net->bw_in_utilized = ril_network_get_utilized(solver, net->type, GNUNET_YES); 1885 GNUNET_YES);
1808 net->bw_out_assigned = ril_network_get_assigned(solver, net->type, GNUNET_NO); 1886 net->bw_in_utilized = ril_network_get_utilized (solver, net->type,
1809 net->bw_out_utilized = ril_network_get_utilized(solver, net->type, GNUNET_NO); 1887 GNUNET_YES);
1810 net->active_agent_count = ril_network_count_active_agents(solver, net); 1888 net->bw_out_assigned = ril_network_get_assigned (solver, net->type,
1811 net->social_welfare = ril_network_get_social_welfare(solver, net); 1889 GNUNET_NO);
1812 } 1890 net->bw_out_utilized = ril_network_get_utilized (solver, net->type,
1891 GNUNET_NO);
1892 net->active_agent_count = ril_network_count_active_agents (solver, net);
1893 net->social_welfare = ril_network_get_social_welfare (solver, net);
1894 }
1813} 1895}
1814 1896
1815/** 1897/**
@@ -1820,7 +1902,7 @@ ril_networks_update_state(struct GAS_RIL_Handle *solver)
1820 * @param solver the solver handle 1902 * @param solver the solver handle
1821 */ 1903 */
1822static void 1904static void
1823ril_step_schedule_next(struct GAS_RIL_Handle *solver) 1905ril_step_schedule_next (struct GAS_RIL_Handle *solver)
1824{ 1906{
1825 double used_ratio; 1907 double used_ratio;
1826 double factor; 1908 double factor;
@@ -1828,21 +1910,24 @@ ril_step_schedule_next(struct GAS_RIL_Handle *solver)
1828 double offset; 1910 double offset;
1829 struct GNUNET_TIME_Relative time_next; 1911 struct GNUNET_TIME_Relative time_next;
1830 1912
1831 used_ratio = ril_get_used_resource_ratio(solver); 1913 used_ratio = ril_get_used_resource_ratio (solver);
1832 1914
1833 GNUNET_assert( 1915 GNUNET_assert (
1834 solver->parameters.step_time_min.rel_value_us 1916 solver->parameters.step_time_min.rel_value_us
1835 <= solver->parameters.step_time_max.rel_value_us); 1917 <= solver->parameters.step_time_max.rel_value_us);
1836 1918
1837 factor = (double)GNUNET_TIME_relative_subtract(solver->parameters.step_time_max, 1919 factor = (double) GNUNET_TIME_relative_subtract (
1838 solver->parameters.step_time_min).rel_value_us; 1920 solver->parameters.step_time_max,
1839 offset = (double)solver->parameters.step_time_min.rel_value_us; 1921 solver->parameters.
1840 y = factor * pow(used_ratio, RIL_INTERVAL_EXPONENT) + offset; 1922 step_time_min).rel_value_us;
1923 offset = (double) solver->parameters.step_time_min.rel_value_us;
1924 y = factor * pow (used_ratio, RIL_INTERVAL_EXPONENT) + offset;
1841 1925
1842 GNUNET_assert(y <= (double)solver->parameters.step_time_max.rel_value_us); 1926 GNUNET_assert (y <= (double) solver->parameters.step_time_max.rel_value_us);
1843 GNUNET_assert(y >= (double)solver->parameters.step_time_min.rel_value_us); 1927 GNUNET_assert (y >= (double) solver->parameters.step_time_min.rel_value_us);
1844 1928
1845 time_next = GNUNET_TIME_relative_saturating_multiply(GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long)y); 1929 time_next = GNUNET_TIME_relative_saturating_multiply (
1930 GNUNET_TIME_UNIT_MICROSECONDS, (unsigned long long) y);
1846 1931
1847// LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n", 1932// LOG (GNUNET_ERROR_TYPE_INFO, "ratio: %f, factor: %f, offset: %f, y: %f\n",
1848// used_ratio, 1933// used_ratio,
@@ -1851,15 +1936,17 @@ ril_step_schedule_next(struct GAS_RIL_Handle *solver)
1851// y); 1936// y);
1852 1937
1853 if (solver->simulate) 1938 if (solver->simulate)
1854 { 1939 {
1855 time_next = GNUNET_TIME_UNIT_ZERO; 1940 time_next = GNUNET_TIME_UNIT_ZERO;
1856 } 1941 }
1857 1942
1858 if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done)) 1943 if ((NULL == solver->step_next_task_id) && (GNUNET_NO == solver->done))
1859 { 1944 {
1860 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed(time_next, &ril_step_scheduler_task, 1945 solver->step_next_task_id = GNUNET_SCHEDULER_add_delayed (time_next,
1861 solver); 1946 &
1862 } 1947 ril_step_scheduler_task,
1948 solver);
1949 }
1863} 1950}
1864 1951
1865/** 1952/**
@@ -1868,62 +1955,62 @@ ril_step_schedule_next(struct GAS_RIL_Handle *solver)
1868 * @param solver 1955 * @param solver
1869 */ 1956 */
1870static void 1957static void
1871ril_step(struct GAS_RIL_Handle *solver) 1958ril_step (struct GAS_RIL_Handle *solver)
1872{ 1959{
1873 struct RIL_Peer_Agent *cur; 1960 struct RIL_Peer_Agent *cur;
1874 1961
1875 if (GNUNET_YES == solver->bulk_lock) 1962 if (GNUNET_YES == solver->bulk_lock)
1876 { 1963 {
1877 solver->bulk_changes++; 1964 solver->bulk_changes++;
1878 return; 1965 return;
1879 } 1966 }
1880 1967
1881 ril_inform(solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS); 1968 ril_inform (solver, GAS_OP_SOLVE_START, GAS_STAT_SUCCESS);
1882 1969
1883 LOG(GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count); 1970 LOG (GNUNET_ERROR_TYPE_DEBUG, " RIL step number %d\n", solver->step_count);
1884 1971
1885 if (0 == solver->step_count) 1972 if (0 == solver->step_count)
1886 { 1973 {
1887 solver->step_time_last = GNUNET_TIME_absolute_get(); 1974 solver->step_time_last = GNUNET_TIME_absolute_get ();
1888 } 1975 }
1889 1976
1890 ril_calculate_discount(solver); 1977 ril_calculate_discount (solver);
1891 ril_networks_update_state(solver); 1978 ril_networks_update_state (solver);
1892 1979
1893 //trigger one step per active, unblocked agent 1980 // trigger one step per active, unblocked agent
1894 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 1981 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
1982 {
1983 if (cur->is_active)
1895 { 1984 {
1896 if (cur->is_active) 1985 if (NULL == cur->address_inuse)
1897 { 1986 {
1898 if (NULL == cur->address_inuse) 1987 ril_try_unblock_agent (solver, cur, GNUNET_NO);
1899 { 1988 }
1900 ril_try_unblock_agent(solver, cur, GNUNET_NO); 1989 if (cur->address_inuse)
1901 } 1990 {
1902 if (cur->address_inuse) 1991 agent_step (cur);
1903 { 1992 }
1904 agent_step(cur);
1905 }
1906 }
1907 } 1993 }
1994 }
1908 1995
1909 ril_networks_update_state(solver); 1996 ril_networks_update_state (solver);
1910 1997
1911 solver->step_count++; 1998 solver->step_count++;
1912 ril_step_schedule_next(solver); 1999 ril_step_schedule_next (solver);
1913 2000
1914 ril_inform(solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS); 2001 ril_inform (solver, GAS_OP_SOLVE_STOP, GAS_STAT_SUCCESS);
1915 2002
1916 ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS); 2003 ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_START, GAS_STAT_SUCCESS);
1917 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 2004 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
2005 {
2006 if (cur->suggestion_issue)
1918 { 2007 {
1919 if (cur->suggestion_issue) 2008 solver->env->bandwidth_changed_cb (solver->env->cls,
1920 { 2009 cur->suggestion_address);
1921 solver->env->bandwidth_changed_cb(solver->env->cls, 2010 cur->suggestion_issue = GNUNET_NO;
1922 cur->suggestion_address);
1923 cur->suggestion_issue = GNUNET_NO;
1924 }
1925 } 2011 }
1926 ril_inform(solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS); 2012 }
2013 ril_inform (solver, GAS_OP_SOLVE_UPDATE_NOTIFICATION_STOP, GAS_STAT_SUCCESS);
1927} 2014}
1928 2015
1929/** 2016/**
@@ -1932,18 +2019,23 @@ ril_step(struct GAS_RIL_Handle *solver)
1932 * @param agent The respective agent 2019 * @param agent The respective agent
1933 */ 2020 */
1934static void 2021static void
1935agent_w_init(struct RIL_Peer_Agent *agent) 2022agent_w_init (struct RIL_Peer_Agent *agent)
1936{ 2023{
1937 int i; 2024 int i;
1938 int k; 2025 int k;
1939 2026
1940 for (i = 0; i < agent->n; i++) 2027 for (i = 0; i < agent->n; i++)
2028 {
2029 for (k = 0; k < agent->m; k++)
1941 { 2030 {
1942 for (k = 0; k < agent->m; k++) 2031 agent->W[i][k] = agent->envi->parameters.alpha * (1.0 - 2.0
1943 { 2032 * ((double)
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)); 2033 GNUNET_CRYPTO_random_u32 (
1945 } 2034 GNUNET_CRYPTO_QUALITY_WEAK,
2035 UINT32_MAX)
2036 / (double) UINT32_MAX));
1946 } 2037 }
2038 }
1947} 2039}
1948 2040
1949/** 2041/**
@@ -1954,11 +2046,11 @@ agent_w_init(struct RIL_Peer_Agent *agent)
1954 * @return handle to the new agent 2046 * @return handle to the new agent
1955 */ 2047 */
1956static struct RIL_Peer_Agent * 2048static struct RIL_Peer_Agent *
1957agent_init(void *s, const struct GNUNET_PeerIdentity *peer) 2049agent_init (void *s, const struct GNUNET_PeerIdentity *peer)
1958{ 2050{
1959 int i; 2051 int i;
1960 struct GAS_RIL_Handle * solver = s; 2052 struct GAS_RIL_Handle *solver = s;
1961 struct RIL_Peer_Agent * agent = GNUNET_new(struct RIL_Peer_Agent); 2053 struct RIL_Peer_Agent *agent = GNUNET_new (struct RIL_Peer_Agent);
1962 2054
1963 agent->envi = solver; 2055 agent->envi = solver;
1964 agent->peer = *peer; 2056 agent->peer = *peer;
@@ -1969,17 +2061,17 @@ agent_init(void *s, const struct GNUNET_PeerIdentity *peer)
1969 agent->suggestion_issue = GNUNET_NO; 2061 agent->suggestion_issue = GNUNET_NO;
1970 agent->n = RIL_ACTION_TYPE_NUM; 2062 agent->n = RIL_ACTION_TYPE_NUM;
1971 agent->m = 0; 2063 agent->m = 0;
1972 agent->W = (double **)GNUNET_malloc(sizeof(double *) * agent->n); 2064 agent->W = (double **) GNUNET_malloc (sizeof(double *) * agent->n);
1973 agent->E = (double **)GNUNET_malloc(sizeof(double *) * agent->n); 2065 agent->E = (double **) GNUNET_malloc (sizeof(double *) * agent->n);
1974 for (i = 0; i < agent->n; i++) 2066 for (i = 0; i < agent->n; i++)
1975 { 2067 {
1976 agent->W[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); 2068 agent->W[i] = (double *) GNUNET_malloc (sizeof(double) * agent->m);
1977 agent->E[i] = (double *)GNUNET_malloc(sizeof(double) * agent->m); 2069 agent->E[i] = (double *) GNUNET_malloc (sizeof(double) * agent->m);
1978 } 2070 }
1979 agent_w_init(agent); 2071 agent_w_init (agent);
1980 agent->eligibility_reset = GNUNET_NO; 2072 agent->eligibility_reset = GNUNET_NO;
1981 agent->a_old = RIL_ACTION_INVALID; 2073 agent->a_old = RIL_ACTION_INVALID;
1982 agent->s_old = GNUNET_malloc(sizeof(double) * agent->m); 2074 agent->s_old = GNUNET_malloc (sizeof(double) * agent->m);
1983 agent->address_inuse = NULL; 2075 agent->address_inuse = NULL;
1984 agent->objective_old = 0; 2076 agent->objective_old = 0;
1985 agent->nop_bonus = 0; 2077 agent->nop_bonus = 0;
@@ -1994,19 +2086,19 @@ agent_init(void *s, const struct GNUNET_PeerIdentity *peer)
1994 * @param agent the agent to retire 2086 * @param agent the agent to retire
1995 */ 2087 */
1996static void 2088static void
1997agent_die(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent) 2089agent_die (struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
1998{ 2090{
1999 int i; 2091 int i;
2000 2092
2001 for (i = 0; i < agent->n; i++) 2093 for (i = 0; i < agent->n; i++)
2002 { 2094 {
2003 GNUNET_free_non_null(agent->W[i]); 2095 GNUNET_free_non_null (agent->W[i]);
2004 GNUNET_free_non_null(agent->E[i]); 2096 GNUNET_free_non_null (agent->E[i]);
2005 } 2097 }
2006 GNUNET_free_non_null(agent->W); 2098 GNUNET_free_non_null (agent->W);
2007 GNUNET_free_non_null(agent->E); 2099 GNUNET_free_non_null (agent->E);
2008 GNUNET_free_non_null(agent->s_old); 2100 GNUNET_free_non_null (agent->s_old);
2009 GNUNET_free(agent); 2101 GNUNET_free (agent);
2010} 2102}
2011 2103
2012/** 2104/**
@@ -2018,24 +2110,26 @@ agent_die(struct GAS_RIL_Handle *solver, struct RIL_Peer_Agent *agent)
2018 * @return the agent 2110 * @return the agent
2019 */ 2111 */
2020static struct RIL_Peer_Agent * 2112static struct RIL_Peer_Agent *
2021ril_get_agent(struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *peer, int create) 2113ril_get_agent (struct GAS_RIL_Handle *solver, const struct
2114 GNUNET_PeerIdentity *peer, int create)
2022{ 2115{
2023 struct RIL_Peer_Agent *cur; 2116 struct RIL_Peer_Agent *cur;
2024 2117
2025 for (cur = solver->agents_head; NULL != cur; cur = cur->next) 2118 for (cur = solver->agents_head; NULL != cur; cur = cur->next)
2119 {
2120 if (0 == GNUNET_memcmp (peer, &cur->peer))
2026 { 2121 {
2027 if (0 == GNUNET_memcmp(peer, &cur->peer)) 2122 return cur;
2028 {
2029 return cur;
2030 }
2031 } 2123 }
2124 }
2032 2125
2033 if (create) 2126 if (create)
2034 { 2127 {
2035 cur = agent_init(solver, peer); 2128 cur = agent_init (solver, peer);
2036 GNUNET_CONTAINER_DLL_insert_tail(solver->agents_head, solver->agents_tail, cur); 2129 GNUNET_CONTAINER_DLL_insert_tail (solver->agents_head, solver->agents_tail,
2037 return cur; 2130 cur);
2038 } 2131 return cur;
2132 }
2039 return NULL; 2133 return NULL;
2040} 2134}
2041 2135
@@ -2048,11 +2142,12 @@ ril_get_agent(struct GAS_RIL_Handle *solver, const struct GNUNET_PeerIdentity *p
2048 * @return whether or not the network is considered active 2142 * @return whether or not the network is considered active
2049 */ 2143 */
2050static int 2144static int
2051ril_network_is_active(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType network) 2145ril_network_is_active (struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType
2146 network)
2052{ 2147{
2053 struct RIL_Scope *net; 2148 struct RIL_Scope *net;
2054 2149
2055 net = ril_get_network(solver, network); 2150 net = ril_get_network (solver, network);
2056 return net->bw_out_available >= RIL_MIN_BW; 2151 return net->bw_out_available >= RIL_MIN_BW;
2057} 2152}
2058 2153
@@ -2068,21 +2163,21 @@ ril_network_is_active(struct GAS_RIL_Handle *solver, enum GNUNET_NetworkType net
2068 * @param old_length the length of the old vector 2163 * @param old_length the length of the old vector
2069 */ 2164 */
2070static void 2165static void
2071ril_cut_from_vector(void **old, 2166ril_cut_from_vector (void **old,
2072 size_t element_size, 2167 size_t element_size,
2073 unsigned int hole_start, 2168 unsigned int hole_start,
2074 unsigned int hole_length, 2169 unsigned int hole_length,
2075 unsigned int old_length) 2170 unsigned int old_length)
2076{ 2171{
2077 char *tmpptr; 2172 char *tmpptr;
2078 char *oldptr = (char *)*old; 2173 char *oldptr = (char *) *old;
2079 size_t size; 2174 size_t size;
2080 unsigned int bytes_before; 2175 unsigned int bytes_before;
2081 unsigned int bytes_hole; 2176 unsigned int bytes_hole;
2082 unsigned int bytes_after; 2177 unsigned int bytes_after;
2083 2178
2084 GNUNET_assert(old_length >= hole_length); 2179 GNUNET_assert (old_length >= hole_length);
2085 GNUNET_assert(old_length >= (hole_start + hole_length)); 2180 GNUNET_assert (old_length >= (hole_start + hole_length));
2086 2181
2087 size = element_size * (old_length - hole_length); 2182 size = element_size * (old_length - hole_length);
2088 2183
@@ -2091,20 +2186,21 @@ ril_cut_from_vector(void **old,
2091 bytes_after = element_size * (old_length - hole_start - hole_length); 2186 bytes_after = element_size * (old_length - hole_start - hole_length);
2092 2187
2093 if (0 == size) 2188 if (0 == size)
2094 { 2189 {
2095 tmpptr = NULL; 2190 tmpptr = NULL;
2096 } 2191 }
2097 else 2192 else
2098 { 2193 {
2099 tmpptr = GNUNET_malloc(size); 2194 tmpptr = GNUNET_malloc (size);
2100 GNUNET_memcpy(tmpptr, oldptr, bytes_before); 2195 GNUNET_memcpy (tmpptr, oldptr, bytes_before);
2101 GNUNET_memcpy(tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole), bytes_after); 2196 GNUNET_memcpy (tmpptr + bytes_before, oldptr + (bytes_before + bytes_hole),
2102 } 2197 bytes_after);
2198 }
2103 if (NULL != *old) 2199 if (NULL != *old)
2104 { 2200 {
2105 GNUNET_free(*old); 2201 GNUNET_free (*old);
2106 } 2202 }
2107 *old = (void *)tmpptr; 2203 *old = (void *) tmpptr;
2108} 2204}
2109 2205
2110/* 2206/*
@@ -2121,20 +2217,20 @@ ril_cut_from_vector(void **old,
2121 * @param pref_rel the normalized preference value for this kind over all clients 2217 * @param pref_rel the normalized preference value for this kind over all clients
2122 */ 2218 */
2123static void 2219static void
2124GAS_ril_address_change_preference(void *solver, 2220GAS_ril_address_change_preference (void *solver,
2125 const struct GNUNET_PeerIdentity *peer, 2221 const struct GNUNET_PeerIdentity *peer,
2126 enum GNUNET_ATS_PreferenceKind kind, 2222 enum GNUNET_ATS_PreferenceKind kind,
2127 double pref_rel) 2223 double pref_rel)
2128{ 2224{
2129 LOG(GNUNET_ERROR_TYPE_DEBUG, 2225 LOG (GNUNET_ERROR_TYPE_DEBUG,
2130 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n", 2226 "API_address_change_preference() Preference '%s' for peer '%s' changed to %.2f \n",
2131 GNUNET_ATS_print_preference_type(kind), GNUNET_i2s(peer), pref_rel); 2227 GNUNET_ATS_print_preference_type (kind), GNUNET_i2s (peer), pref_rel);
2132 2228
2133 struct GAS_RIL_Handle *s = solver; 2229 struct GAS_RIL_Handle *s = solver;
2134 2230
2135 s->parameters.temperature = s->parameters.temperature_init; 2231 s->parameters.temperature = s->parameters.temperature_init;
2136 s->parameters.epsilon = s->parameters.epsilon_init; 2232 s->parameters.epsilon = s->parameters.epsilon_init;
2137 ril_step(s); 2233 ril_step (s);
2138} 2234}
2139 2235
2140 2236
@@ -2148,9 +2244,9 @@ GAS_ril_address_change_preference(void *solver,
2148 * @param network network type of this address 2244 * @param network network type of this address
2149 */ 2245 */
2150static void 2246static void
2151GAS_ril_address_add(void *solver, 2247GAS_ril_address_add (void *solver,
2152 struct ATS_Address *address, 2248 struct ATS_Address *address,
2153 uint32_t network) 2249 uint32_t network)
2154{ 2250{
2155 struct GAS_RIL_Handle *s = solver; 2251 struct GAS_RIL_Handle *s = solver;
2156 struct RIL_Peer_Agent *agent; 2252 struct RIL_Peer_Agent *agent;
@@ -2163,68 +2259,71 @@ GAS_ril_address_add(void *solver,
2163 int i; 2259 int i;
2164 unsigned int zero; 2260 unsigned int zero;
2165 2261
2166 LOG(GNUNET_ERROR_TYPE_DEBUG, 2262 LOG (GNUNET_ERROR_TYPE_DEBUG,
2167 "API_address_add()\n"); 2263 "API_address_add()\n");
2168 2264
2169 net = ril_get_network(s, network); 2265 net = ril_get_network (s, network);
2170 address->solver_information = net; 2266 address->solver_information = net;
2171 2267
2172 if (!ril_network_is_active(s, network)) 2268 if (! ril_network_is_active (s, network))
2173 { 2269 {
2174 LOG(GNUNET_ERROR_TYPE_DEBUG, 2270 LOG (GNUNET_ERROR_TYPE_DEBUG,
2175 "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n", 2271 "API_address_add() Did not add %s address %s for peer '%s', network does not have enough bandwidth\n",
2176 address->plugin, address->addr, GNUNET_i2s(&address->peer)); 2272 address->plugin, address->addr, GNUNET_i2s (&address->peer));
2177 return; 2273 return;
2178 } 2274 }
2179 2275
2180 s->parameters.temperature = s->parameters.temperature_init; 2276 s->parameters.temperature = s->parameters.temperature_init;
2181 s->parameters.epsilon = s->parameters.epsilon_init; 2277 s->parameters.epsilon = s->parameters.epsilon_init;
2182 2278
2183 agent = ril_get_agent(s, &address->peer, GNUNET_YES); 2279 agent = ril_get_agent (s, &address->peer, GNUNET_YES);
2184 2280
2185 //add address 2281 // add address
2186 address_wrapped = GNUNET_new(struct RIL_Address_Wrapped); 2282 address_wrapped = GNUNET_new (struct RIL_Address_Wrapped);
2187 address_wrapped->address_naked = address; 2283 address_wrapped->address_naked = address;
2188 GNUNET_CONTAINER_DLL_insert_tail(agent->addresses_head, agent->addresses_tail, address_wrapped); 2284 GNUNET_CONTAINER_DLL_insert_tail (agent->addresses_head,
2285 agent->addresses_tail, address_wrapped);
2189 2286
2190 //increase size of W 2287 // increase size of W
2191 m_new = agent->m + ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); 2288 m_new = agent->m + ((s->parameters.rbf_divisor + 1)
2289 * (s->parameters.rbf_divisor + 1));
2192 m_old = agent->m; 2290 m_old = agent->m;
2193 n_new = agent->n + 1; 2291 n_new = agent->n + 1;
2194 n_old = agent->n; 2292 n_old = agent->n;
2195 2293
2196 GNUNET_array_grow(agent->W, agent->n, n_new); 2294 GNUNET_array_grow (agent->W, agent->n, n_new);
2197 agent->n = n_old; 2295 agent->n = n_old;
2198 GNUNET_array_grow(agent->E, agent->n, n_new); 2296 GNUNET_array_grow (agent->E, agent->n, n_new);
2199 for (i = 0; i < n_new; i++) 2297 for (i = 0; i < n_new; i++)
2298 {
2299 if (i < n_old)
2200 { 2300 {
2201 if (i < n_old) 2301 agent->m = m_old;
2202 { 2302 GNUNET_array_grow (agent->W[i], agent->m, m_new);
2203 agent->m = m_old; 2303 agent->m = m_old;
2204 GNUNET_array_grow(agent->W[i], agent->m, m_new); 2304 GNUNET_array_grow (agent->E[i], agent->m, m_new);
2205 agent->m = m_old; 2305 }
2206 GNUNET_array_grow(agent->E[i], agent->m, m_new); 2306 else
2207 } 2307 {
2208 else 2308 zero = 0;
2209 { 2309 GNUNET_array_grow (agent->W[i], zero, m_new);
2210 zero = 0; 2310 zero = 0;
2211 GNUNET_array_grow(agent->W[i], zero, m_new); 2311 GNUNET_array_grow (agent->E[i], zero, m_new);
2212 zero = 0;
2213 GNUNET_array_grow(agent->E[i], zero, m_new);
2214 }
2215 } 2312 }
2313 }
2216 2314
2217 //increase size of old state vector 2315 // increase size of old state vector
2218 agent->m = m_old; 2316 agent->m = m_old;
2219 GNUNET_array_grow(agent->s_old, agent->m, m_new); 2317 GNUNET_array_grow (agent->s_old, agent->m, m_new);
2220 2318
2221 ril_try_unblock_agent(s, agent, GNUNET_NO); 2319 ril_try_unblock_agent (s, agent, GNUNET_NO);
2222 2320
2223 ril_step(s); 2321 ril_step (s);
2224 2322
2225 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_address_add() Added %s %s address %s for peer '%s'\n", 2323 LOG (GNUNET_ERROR_TYPE_DEBUG,
2226 address->active ? "active" : "inactive", address->plugin, address->addr, 2324 "API_address_add() Added %s %s address %s for peer '%s'\n",
2227 GNUNET_i2s(&address->peer)); 2325 address->active ? "active" : "inactive", address->plugin, address->addr,
2326 GNUNET_i2s (&address->peer));
2228} 2327}
2229 2328
2230/** 2329/**
@@ -2236,8 +2335,8 @@ GAS_ril_address_add(void *solver,
2236 * @param address the address to remove 2335 * @param address the address to remove
2237 */ 2336 */
2238static void 2337static void
2239GAS_ril_address_delete(void *solver, 2338GAS_ril_address_delete (void *solver,
2240 struct ATS_Address *address) 2339 struct ATS_Address *address)
2241{ 2340{
2242 struct GAS_RIL_Handle *s = solver; 2341 struct GAS_RIL_Handle *s = solver;
2243 struct RIL_Peer_Agent *agent; 2342 struct RIL_Peer_Agent *agent;
@@ -2248,103 +2347,112 @@ GAS_ril_address_delete(void *solver,
2248 int i; 2347 int i;
2249 struct RIL_Scope *net; 2348 struct RIL_Scope *net;
2250 2349
2251 LOG(GNUNET_ERROR_TYPE_DEBUG, 2350 LOG (GNUNET_ERROR_TYPE_DEBUG,
2252 "API_address_delete() Delete %s %s address %s for peer '%s'\n", 2351 "API_address_delete() Delete %s %s address %s for peer '%s'\n",
2253 address->active ? "active" : "inactive", 2352 address->active ? "active" : "inactive",
2254 address->plugin, 2353 address->plugin,
2255 address->addr, 2354 address->addr,
2256 GNUNET_i2s(&address->peer)); 2355 GNUNET_i2s (&address->peer));
2257 2356
2258 agent = ril_get_agent(s, &address->peer, GNUNET_NO); 2357 agent = ril_get_agent (s, &address->peer, GNUNET_NO);
2259 if (NULL == agent) 2358 if (NULL == agent)
2260 { 2359 {
2261 net = address->solver_information; 2360 net = address->solver_information;
2262 GNUNET_assert(!ril_network_is_active(s, net->type)); 2361 GNUNET_assert (! ril_network_is_active (s, net->type));
2263 LOG(GNUNET_ERROR_TYPE_DEBUG, 2362 LOG (GNUNET_ERROR_TYPE_DEBUG,
2264 "No agent allocated for peer yet, since address was in inactive network\n"); 2363 "No agent allocated for peer yet, since address was in inactive network\n");
2265 return; 2364 return;
2266 } 2365 }
2267 2366
2268 s->parameters.temperature = s->parameters.temperature_init; 2367 s->parameters.temperature = s->parameters.temperature_init;
2269 s->parameters.epsilon = s->parameters.epsilon_init; 2368 s->parameters.epsilon = s->parameters.epsilon_init;
2270 2369
2271 address_index = agent_address_get_index(agent, address); 2370 address_index = agent_address_get_index (agent, address);
2272 address_wrapped = agent_address_get_wrapped(agent, address); 2371 address_wrapped = agent_address_get_wrapped (agent, address);
2273 2372
2274 if (NULL == address_wrapped) 2373 if (NULL == address_wrapped)
2275 { 2374 {
2276 net = address->solver_information; 2375 net = address->solver_information;
2277 LOG(GNUNET_ERROR_TYPE_DEBUG, 2376 LOG (GNUNET_ERROR_TYPE_DEBUG,
2278 "Address not considered by agent, address was in inactive network\n"); 2377 "Address not considered by agent, address was in inactive network\n");
2279 return; 2378 return;
2280 } 2379 }
2281 GNUNET_CONTAINER_DLL_remove(agent->addresses_head, 2380 GNUNET_CONTAINER_DLL_remove (agent->addresses_head,
2282 agent->addresses_tail, 2381 agent->addresses_tail,
2283 address_wrapped); 2382 address_wrapped);
2284 GNUNET_free(address_wrapped); 2383 GNUNET_free (address_wrapped);
2285 2384
2286 //decrease W 2385 // decrease W
2287 m_new = agent->m - ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)); 2386 m_new = agent->m - ((s->parameters.rbf_divisor + 1)
2387 * (s->parameters.rbf_divisor + 1));
2288 n_new = agent->n - 1; 2388 n_new = agent->n - 1;
2289 2389
2290 for (i = 0; i < agent->n; i++) 2390 for (i = 0; i < agent->n; i++)
2291 { 2391 {
2292 ril_cut_from_vector((void **)&agent->W[i], sizeof(double), 2392 ril_cut_from_vector ((void **) &agent->W[i], sizeof(double),
2293 address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), 2393 address_index * ((s->parameters.rbf_divisor + 1)
2294 ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); 2394 * (s->parameters.rbf_divisor + 1)),
2295 ril_cut_from_vector((void **)&agent->E[i], sizeof(double), 2395 ((s->parameters.rbf_divisor + 1)
2296 address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), 2396 * (s->parameters.rbf_divisor + 1)), agent->m);
2297 ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); 2397 ril_cut_from_vector ((void **) &agent->E[i], sizeof(double),
2298 } 2398 address_index * ((s->parameters.rbf_divisor + 1)
2299 GNUNET_free_non_null(agent->W[RIL_ACTION_TYPE_NUM + address_index]); 2399 * (s->parameters.rbf_divisor + 1)),
2300 GNUNET_free_non_null(agent->E[RIL_ACTION_TYPE_NUM + address_index]); 2400 ((s->parameters.rbf_divisor + 1)
2301 ril_cut_from_vector((void **)&agent->W, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, 2401 * (s->parameters.rbf_divisor + 1)), agent->m);
2302 1, agent->n); 2402 }
2303 ril_cut_from_vector((void **)&agent->E, sizeof(double *), RIL_ACTION_TYPE_NUM + address_index, 2403 GNUNET_free_non_null (agent->W[RIL_ACTION_TYPE_NUM + address_index]);
2304 1, agent->n); 2404 GNUNET_free_non_null (agent->E[RIL_ACTION_TYPE_NUM + address_index]);
2305 //correct last action 2405 ril_cut_from_vector ((void **) &agent->W, sizeof(double *),
2406 RIL_ACTION_TYPE_NUM + address_index,
2407 1, agent->n);
2408 ril_cut_from_vector ((void **) &agent->E, sizeof(double *),
2409 RIL_ACTION_TYPE_NUM + address_index,
2410 1, agent->n);
2411 // correct last action
2306 if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index)) 2412 if (agent->a_old > (RIL_ACTION_TYPE_NUM + address_index))
2307 { 2413 {
2308 agent->a_old -= 1; 2414 agent->a_old -= 1;
2309 } 2415 }
2310 else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index)) 2416 else if (agent->a_old == (RIL_ACTION_TYPE_NUM + address_index))
2311 { 2417 {
2312 agent->a_old = RIL_ACTION_INVALID; 2418 agent->a_old = RIL_ACTION_INVALID;
2313 } 2419 }
2314 //decrease old state vector 2420 // decrease old state vector
2315 ril_cut_from_vector((void **)&agent->s_old, sizeof(double), 2421 ril_cut_from_vector ((void **) &agent->s_old, sizeof(double),
2316 address_index * ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), 2422 address_index * ((s->parameters.rbf_divisor + 1)
2317 ((s->parameters.rbf_divisor + 1) * (s->parameters.rbf_divisor + 1)), agent->m); 2423 * (s->parameters.rbf_divisor + 1)),
2424 ((s->parameters.rbf_divisor + 1)
2425 * (s->parameters.rbf_divisor + 1)), agent->m);
2318 agent->m = m_new; 2426 agent->m = m_new;
2319 agent->n = n_new; 2427 agent->n = n_new;
2320 2428
2321 if (agent->address_inuse == address) 2429 if (agent->address_inuse == address)
2322 { 2430 {
2323 if (NULL != agent->addresses_head) //if peer has an address left, use it 2431 if (NULL != agent->addresses_head) // if peer has an address left, use it
2324 { 2432 {
2325 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2326 "Active address died, suggesting alternative!\n"); 2434 "Active address died, suggesting alternative!\n");
2327 envi_set_active_suggestion(s, 2435 envi_set_active_suggestion (s,
2328 agent, 2436 agent,
2329 agent->addresses_head->address_naked, 2437 agent->addresses_head->address_naked,
2330 agent->bw_in, 2438 agent->bw_in,
2331 agent->bw_out, 2439 agent->bw_out,
2332 GNUNET_YES); 2440 GNUNET_YES);
2333 } 2441 }
2334 else 2442 else
2335 { 2443 {
2336 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 2444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2337 "Active address died, suggesting disconnect!\n"); 2445 "Active address died, suggesting disconnect!\n");
2338 envi_set_active_suggestion(s, agent, NULL, 0, 0, GNUNET_NO); 2446 envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
2339 } 2447 }
2340 } 2448 }
2341 ril_step(solver); 2449 ril_step (solver);
2342 if (agent->suggestion_address == address) 2450 if (agent->suggestion_address == address)
2343 { 2451 {
2344 agent->suggestion_issue = GNUNET_NO; 2452 agent->suggestion_issue = GNUNET_NO;
2345 agent->suggestion_address = NULL; 2453 agent->suggestion_address = NULL;
2346 } 2454 }
2347 GNUNET_assert(agent->address_inuse != address); 2455 GNUNET_assert (agent->address_inuse != address);
2348} 2456}
2349 2457
2350 2458
@@ -2355,17 +2463,17 @@ GAS_ril_address_delete(void *solver,
2355 * @param address the address 2463 * @param address the address
2356 */ 2464 */
2357static void 2465static void
2358GAS_ril_address_property_changed(void *solver, 2466GAS_ril_address_property_changed (void *solver,
2359 struct ATS_Address *address) 2467 struct ATS_Address *address)
2360{ 2468{
2361 struct GAS_RIL_Handle *s = solver; 2469 struct GAS_RIL_Handle *s = solver;
2362 2470
2363 LOG(GNUNET_ERROR_TYPE_DEBUG, 2471 LOG (GNUNET_ERROR_TYPE_DEBUG,
2364 "Properties for peer '%s' address changed\n", 2472 "Properties for peer '%s' address changed\n",
2365 GNUNET_i2s(&address->peer)); 2473 GNUNET_i2s (&address->peer));
2366 s->parameters.temperature = s->parameters.temperature_init; 2474 s->parameters.temperature = s->parameters.temperature_init;
2367 s->parameters.epsilon = s->parameters.epsilon_init; 2475 s->parameters.epsilon = s->parameters.epsilon_init;
2368 ril_step(s); 2476 ril_step (s);
2369} 2477}
2370 2478
2371 2479
@@ -2380,20 +2488,20 @@ GAS_ril_address_property_changed(void *solver,
2380 * @param score the score 2488 * @param score the score
2381 */ 2489 */
2382static void 2490static void
2383GAS_ril_address_preference_feedback(void *solver, 2491GAS_ril_address_preference_feedback (void *solver,
2384 struct GNUNET_SERVICE_Client *application, 2492 struct GNUNET_SERVICE_Client *application,
2385 const struct GNUNET_PeerIdentity *peer, 2493 const struct GNUNET_PeerIdentity *peer,
2386 const struct GNUNET_TIME_Relative scope, 2494 const struct GNUNET_TIME_Relative scope,
2387 enum GNUNET_ATS_PreferenceKind kind, 2495 enum GNUNET_ATS_PreferenceKind kind,
2388 double score) 2496 double score)
2389{ 2497{
2390 LOG(GNUNET_ERROR_TYPE_DEBUG, 2498 LOG (GNUNET_ERROR_TYPE_DEBUG,
2391 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for " 2499 "API_address_preference_feedback() Peer '%s' got a feedback of %+.3f from application %s for "
2392 "preference %s for %d seconds\n", 2500 "preference %s for %d seconds\n",
2393 GNUNET_i2s(peer), 2501 GNUNET_i2s (peer),
2394 "UNKNOWN", 2502 "UNKNOWN",
2395 GNUNET_ATS_print_preference_type(kind), 2503 GNUNET_ATS_print_preference_type (kind),
2396 scope.rel_value_us / 1000000); 2504 scope.rel_value_us / 1000000);
2397} 2505}
2398 2506
2399 2507
@@ -2403,12 +2511,12 @@ GAS_ril_address_preference_feedback(void *solver,
2403 * @param solver the solver 2511 * @param solver the solver
2404 */ 2512 */
2405static void 2513static void
2406GAS_ril_bulk_start(void *solver) 2514GAS_ril_bulk_start (void *solver)
2407{ 2515{
2408 struct GAS_RIL_Handle *s = solver; 2516 struct GAS_RIL_Handle *s = solver;
2409 2517
2410 LOG(GNUNET_ERROR_TYPE_DEBUG, 2518 LOG (GNUNET_ERROR_TYPE_DEBUG,
2411 "API_bulk_start() lock: %d\n", s->bulk_lock + 1); 2519 "API_bulk_start() lock: %d\n", s->bulk_lock + 1);
2412 2520
2413 s->bulk_lock++; 2521 s->bulk_lock++;
2414} 2522}
@@ -2420,26 +2528,26 @@ GAS_ril_bulk_start(void *solver)
2420 * @param solver the solver handle 2528 * @param solver the solver handle
2421 */ 2529 */
2422static void 2530static void
2423GAS_ril_bulk_stop(void *solver) 2531GAS_ril_bulk_stop (void *solver)
2424{ 2532{
2425 struct GAS_RIL_Handle *s = solver; 2533 struct GAS_RIL_Handle *s = solver;
2426 2534
2427 LOG(GNUNET_ERROR_TYPE_DEBUG, 2535 LOG (GNUNET_ERROR_TYPE_DEBUG,
2428 "API_bulk_stop() lock: %d\n", 2536 "API_bulk_stop() lock: %d\n",
2429 s->bulk_lock - 1); 2537 s->bulk_lock - 1);
2430 2538
2431 if (s->bulk_lock < 1) 2539 if (s->bulk_lock < 1)
2432 { 2540 {
2433 GNUNET_break(0); 2541 GNUNET_break (0);
2434 return; 2542 return;
2435 } 2543 }
2436 s->bulk_lock--; 2544 s->bulk_lock--;
2437 2545
2438 if (0 < s->bulk_changes) 2546 if (0 < s->bulk_changes)
2439 { 2547 {
2440 ril_step(solver); 2548 ril_step (solver);
2441 s->bulk_changes = 0; 2549 s->bulk_changes = 0;
2442 } 2550 }
2443} 2551}
2444 2552
2445 2553
@@ -2454,38 +2562,40 @@ GAS_ril_bulk_stop(void *solver)
2454 * @param peer the identity of the peer 2562 * @param peer the identity of the peer
2455 */ 2563 */
2456static void 2564static void
2457GAS_ril_get_preferred_address(void *solver, 2565GAS_ril_get_preferred_address (void *solver,
2458 const struct GNUNET_PeerIdentity *peer) 2566 const struct GNUNET_PeerIdentity *peer)
2459{ 2567{
2460 struct GAS_RIL_Handle *s = solver; 2568 struct GAS_RIL_Handle *s = solver;
2461 struct RIL_Peer_Agent *agent; 2569 struct RIL_Peer_Agent *agent;
2462 2570
2463 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n"); 2571 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_get_preferred_address()\n");
2464 2572
2465 agent = ril_get_agent(s, peer, GNUNET_YES); 2573 agent = ril_get_agent (s, peer, GNUNET_YES);
2466 2574
2467 agent->is_active = GNUNET_YES; 2575 agent->is_active = GNUNET_YES;
2468 envi_set_active_suggestion(solver, agent, agent->address_inuse, agent->bw_in, agent->bw_out, GNUNET_YES); 2576 envi_set_active_suggestion (solver, agent, agent->address_inuse, agent->bw_in,
2577 agent->bw_out, GNUNET_YES);
2469 2578
2470 ril_try_unblock_agent(solver, agent, GNUNET_YES); 2579 ril_try_unblock_agent (solver, agent, GNUNET_YES);
2471 2580
2472 if (agent->address_inuse) 2581 if (agent->address_inuse)
2473 { 2582 {
2474 LOG(GNUNET_ERROR_TYPE_DEBUG, 2583 LOG (GNUNET_ERROR_TYPE_DEBUG,
2475 "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n", 2584 "API_get_preferred_address() Activated agent for peer '%s' with %s address %s\n",
2476 GNUNET_i2s(peer), agent->address_inuse->plugin, agent->address_inuse->addr); 2585 GNUNET_i2s (peer), agent->address_inuse->plugin,
2477 } 2586 agent->address_inuse->addr);
2587 }
2478 else 2588 else
2479 { 2589 {
2480 LOG(GNUNET_ERROR_TYPE_DEBUG, 2590 LOG (GNUNET_ERROR_TYPE_DEBUG,
2481 "API_get_preferred_address() Activated agent for peer '%s', but no address available\n", 2591 "API_get_preferred_address() Activated agent for peer '%s', but no address available\n",
2482 GNUNET_i2s(peer)); 2592 GNUNET_i2s (peer));
2483 s->parameters.temperature = s->parameters.temperature_init; 2593 s->parameters.temperature = s->parameters.temperature_init;
2484 s->parameters.epsilon = s->parameters.epsilon_init; 2594 s->parameters.epsilon = s->parameters.epsilon_init;
2485 } 2595 }
2486 if (NULL != agent->address_inuse) 2596 if (NULL != agent->address_inuse)
2487 s->env->bandwidth_changed_cb(s->env->cls, 2597 s->env->bandwidth_changed_cb (s->env->cls,
2488 agent->address_inuse); 2598 agent->address_inuse);
2489} 2599}
2490 2600
2491 2601
@@ -2499,41 +2609,42 @@ GAS_ril_get_preferred_address(void *solver,
2499 * @param peer the peer 2609 * @param peer the peer
2500 */ 2610 */
2501static void 2611static void
2502GAS_ril_stop_get_preferred_address(void *solver, 2612GAS_ril_stop_get_preferred_address (void *solver,
2503 const struct GNUNET_PeerIdentity *peer) 2613 const struct GNUNET_PeerIdentity *peer)
2504{ 2614{
2505 struct GAS_RIL_Handle *s = solver; 2615 struct GAS_RIL_Handle *s = solver;
2506 struct RIL_Peer_Agent *agent; 2616 struct RIL_Peer_Agent *agent;
2507 2617
2508 LOG(GNUNET_ERROR_TYPE_DEBUG, 2618 LOG (GNUNET_ERROR_TYPE_DEBUG,
2509 "API_stop_get_preferred_address()"); 2619 "API_stop_get_preferred_address()");
2510 2620
2511 agent = ril_get_agent(s, peer, GNUNET_NO); 2621 agent = ril_get_agent (s, peer, GNUNET_NO);
2512 2622
2513 if (NULL == agent) 2623 if (NULL == agent)
2514 { 2624 {
2515 GNUNET_break(0); 2625 GNUNET_break (0);
2516 return; 2626 return;
2517 } 2627 }
2518 if (GNUNET_NO == agent->is_active) 2628 if (GNUNET_NO == agent->is_active)
2519 { 2629 {
2520 GNUNET_break(0); 2630 GNUNET_break (0);
2521 return; 2631 return;
2522 } 2632 }
2523 2633
2524 s->parameters.temperature = s->parameters.temperature_init; 2634 s->parameters.temperature = s->parameters.temperature_init;
2525 s->parameters.epsilon = s->parameters.epsilon_init; 2635 s->parameters.epsilon = s->parameters.epsilon_init;
2526 2636
2527 agent->is_active = GNUNET_NO; 2637 agent->is_active = GNUNET_NO;
2528 2638
2529 envi_set_active_suggestion(s, agent, agent->address_inuse, agent->bw_in, agent->bw_out, 2639 envi_set_active_suggestion (s, agent, agent->address_inuse, agent->bw_in,
2530 GNUNET_YES); 2640 agent->bw_out,
2641 GNUNET_YES);
2531 2642
2532 ril_step(s); 2643 ril_step (s);
2533 2644
2534 LOG(GNUNET_ERROR_TYPE_DEBUG, 2645 LOG (GNUNET_ERROR_TYPE_DEBUG,
2535 "API_stop_get_preferred_address() Paused agent for peer '%s'\n", 2646 "API_stop_get_preferred_address() Paused agent for peer '%s'\n",
2536 GNUNET_i2s(peer)); 2647 GNUNET_i2s (peer));
2537} 2648}
2538 2649
2539 2650
@@ -2543,233 +2654,258 @@ GAS_ril_stop_get_preferred_address(void *solver,
2543 * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment' 2654 * @param cls pointer to the 'struct GNUNET_ATS_PluginEnvironment'
2544 */ 2655 */
2545void * 2656void *
2546libgnunet_plugin_ats_ril_init(void *cls) 2657libgnunet_plugin_ats_ril_init (void *cls)
2547{ 2658{
2548 static struct GNUNET_ATS_SolverFunctions sf; 2659 static struct GNUNET_ATS_SolverFunctions sf;
2549 struct GNUNET_ATS_PluginEnvironment *env = cls; 2660 struct GNUNET_ATS_PluginEnvironment *env = cls;
2550 struct GAS_RIL_Handle *solver = GNUNET_new(struct GAS_RIL_Handle); 2661 struct GAS_RIL_Handle *solver = GNUNET_new (struct GAS_RIL_Handle);
2551 struct RIL_Scope * cur; 2662 struct RIL_Scope *cur;
2552 int c; 2663 int c;
2553 char *string; 2664 char *string;
2554 float f_tmp; 2665 float f_tmp;
2555 2666
2556 LOG(GNUNET_ERROR_TYPE_DEBUG, 2667 LOG (GNUNET_ERROR_TYPE_DEBUG,
2557 "API_init() Initializing RIL solver\n"); 2668 "API_init() Initializing RIL solver\n");
2558 2669
2559 GNUNET_assert(NULL != env); 2670 GNUNET_assert (NULL != env);
2560 GNUNET_assert(NULL != env->cfg); 2671 GNUNET_assert (NULL != env->cfg);
2561 GNUNET_assert(NULL != env->stats); 2672 GNUNET_assert (NULL != env->stats);
2562 GNUNET_assert(NULL != env->bandwidth_changed_cb); 2673 GNUNET_assert (NULL != env->bandwidth_changed_cb);
2563 GNUNET_assert(NULL != env->get_preferences); 2674 GNUNET_assert (NULL != env->get_preferences);
2564 2675
2565 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_RBF_DIVISOR", &solver->parameters.rbf_divisor)) 2676 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats",
2566 { 2677 "RIL_RBF_DIVISOR",
2567 solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR; 2678 &solver->parameters.
2568 } 2679 rbf_divisor))
2680 {
2681 solver->parameters.rbf_divisor = RIL_DEFAULT_RBF_DIVISOR;
2682 }
2569 2683
2570 if (GNUNET_OK 2684 if (GNUNET_OK
2571 != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MIN", 2685 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats",
2572 &solver->parameters.step_time_min)) 2686 "RIL_STEP_TIME_MIN",
2573 { 2687 &solver->parameters.step_time_min))
2574 solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN; 2688 {
2575 } 2689 solver->parameters.step_time_min = RIL_DEFAULT_STEP_TIME_MIN;
2690 }
2576 2691
2577 if (GNUNET_OK 2692 if (GNUNET_OK
2578 != GNUNET_CONFIGURATION_get_value_time(env->cfg, "ats", "RIL_STEP_TIME_MAX", 2693 != GNUNET_CONFIGURATION_get_value_time (env->cfg, "ats",
2579 &solver->parameters.step_time_max)) 2694 "RIL_STEP_TIME_MAX",
2580 { 2695 &solver->parameters.step_time_max))
2581 solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX; 2696 {
2582 } 2697 solver->parameters.step_time_max = RIL_DEFAULT_STEP_TIME_MAX;
2698 }
2583 2699
2584 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_ALGORITHM", &string)) 2700 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats",
2701 "RIL_ALGORITHM",
2702 &string))
2703 {
2704 GNUNET_STRINGS_utf8_toupper (string, string);
2705 if (0 == strcmp (string, "SARSA"))
2585 { 2706 {
2586 GNUNET_STRINGS_utf8_toupper(string, string); 2707 solver->parameters.algorithm = RIL_ALGO_SARSA;
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);
2597 } 2708 }
2598 else 2709 if (0 == strcmp (string, "Q-LEARNING"))
2599 { 2710 {
2600 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM; 2711 solver->parameters.algorithm = RIL_ALGO_Q;
2601 } 2712 }
2602 2713
2603 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SELECT", &string)) 2714 GNUNET_free (string);
2604 { 2715 }
2605 solver->parameters.select = !strcmp(string, "EGREEDY") ? RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
2606 GNUNET_free(string);
2607 }
2608 else 2716 else
2609 { 2717 {
2610 solver->parameters.select = RIL_DEFAULT_SELECT; 2718 solver->parameters.algorithm = RIL_DEFAULT_ALGORITHM;
2611 } 2719 }
2720
2721 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats",
2722 "RIL_SELECT",
2723 &string))
2724 {
2725 solver->parameters.select = ! strcmp (string, "EGREEDY") ?
2726 RIL_SELECT_EGREEDY : RIL_SELECT_SOFTMAX;
2727 GNUNET_free (string);
2728 }
2729 else
2730 {
2731 solver->parameters.select = RIL_DEFAULT_SELECT;
2732 }
2612 2733
2613 2734
2614 solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA; 2735 solver->parameters.beta = RIL_DEFAULT_DISCOUNT_BETA;
2615 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2736 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2616 "RIL_DISCOUNT_BETA", &f_tmp)) 2737 "RIL_DISCOUNT_BETA",
2738 &f_tmp))
2739 {
2740 if (f_tmp < 0.0)
2617 { 2741 {
2618 if (f_tmp < 0.0) 2742 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2619 { 2743 "RIL_DISCOUNT_BETA", f_tmp);
2620 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2744 }
2621 "RIL_DISCOUNT_BETA", f_tmp); 2745 else
2622 } 2746 {
2623 else 2747 solver->parameters.beta = f_tmp;
2624 { 2748 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2625 solver->parameters.beta = f_tmp; 2749 "RIL_DISCOUNT_BETA", f_tmp);
2626 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2627 "RIL_DISCOUNT_BETA", f_tmp);
2628 }
2629 } 2750 }
2751 }
2630 2752
2631 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA; 2753 solver->parameters.gamma = RIL_DEFAULT_DISCOUNT_GAMMA;
2632 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2754 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2633 "RIL_DISCOUNT_GAMMA", &f_tmp)) 2755 "RIL_DISCOUNT_GAMMA",
2756 &f_tmp))
2757 {
2758 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2634 { 2759 {
2635 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2760 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2636 { 2761 "RIL_DISCOUNT_GAMMA", f_tmp);
2637 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2638 "RIL_DISCOUNT_GAMMA", f_tmp);
2639 }
2640 else
2641 {
2642 solver->parameters.gamma = f_tmp;
2643 LOG(GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2644 "RIL_DISCOUNT_GAMMA", f_tmp);
2645 }
2646 } 2762 }
2647 2763 else
2648 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
2649 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2650 "RIL_GRADIENT_STEP_SIZE", &f_tmp))
2651 { 2764 {
2652 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2765 solver->parameters.gamma = f_tmp;
2653 { 2766 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2654 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2767 "RIL_DISCOUNT_GAMMA", f_tmp);
2655 "RIL_GRADIENT_STEP_SIZE", f_tmp);
2656 }
2657 else
2658 {
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 }
2663 } 2768 }
2769 }
2664 2770
2665 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY; 2771 solver->parameters.alpha = RIL_DEFAULT_GRADIENT_STEP_SIZE;
2666 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2772 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2667 "RIL_TRACE_DECAY", &f_tmp)) 2773 "RIL_GRADIENT_STEP_SIZE",
2774 &f_tmp))
2775 {
2776 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2668 { 2777 {
2669 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2778 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2670 { 2779 "RIL_GRADIENT_STEP_SIZE", 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 }
2680 } 2780 }
2681 2781 else
2682 solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
2683 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2684 "RIL_EXPLORE_RATIO", &f_tmp))
2685 { 2782 {
2686 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2783 solver->parameters.alpha = f_tmp;
2687 { 2784 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2688 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2785 "RIL_GRADIENT_STEP_SIZE", f_tmp);
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 }
2697 } 2786 }
2787 }
2698 2788
2699 solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY; 2789 solver->parameters.lambda = RIL_DEFAULT_TRACE_DECAY;
2700 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2790 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2701 "RIL_EXPLORE_DECAY", &f_tmp)) 2791 "RIL_TRACE_DECAY",
2792 &f_tmp))
2793 {
2794 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2702 { 2795 {
2703 if ((f_tmp < 0.0) || (f_tmp > 1.0)) 2796 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2704 { 2797 "RIL_TRACE_DECAY", f_tmp);
2705 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"),
2706 "RIL_EXPLORE_DECAY", f_tmp);
2707 }
2708 else
2709 {
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 }
2714 } 2798 }
2715 2799 else
2716 solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
2717 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats",
2718 "RIL_TEMPERATURE", &f_tmp))
2719 { 2800 {
2720 if (f_tmp <= 0.0) 2801 solver->parameters.lambda = f_tmp;
2721 { 2802 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2722 LOG(GNUNET_ERROR_TYPE_ERROR, _("Invalid %s configuration %f \n"), 2803 "RIL_TRACE_DECAY", f_tmp);
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 }
2731 } 2804 }
2805 }
2732 2806
2733 solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY; 2807 solver->parameters.epsilon_init = RIL_DEFAULT_EXPLORE_RATIO;
2734 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float(env->cfg, "ats", 2808 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2735 "RIL_TEMPERATURE_DECAY", &f_tmp)) 2809 "RIL_EXPLORE_RATIO",
2810 &f_tmp))
2811 {
2812 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2736 { 2813 {
2737 if ((f_tmp <= 0.0) || solver->parameters.temperature_decay > 1) 2814 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2738 { 2815 "RIL_EXPLORE_RATIO", f_tmp);
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 }
2748 } 2816 }
2749 2817 else
2750 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, "ats", "RIL_SIMULATE", &solver->simulate))
2751 { 2818 {
2752 solver->simulate = GNUNET_NO; 2819 solver->parameters.epsilon_init = f_tmp;
2820 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2821 "RIL_EXPLORE_RATIO", f_tmp);
2753 } 2822 }
2823 }
2754 2824
2755 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "ats", "RIL_REPLACE_TRACES")) 2825 solver->parameters.epsilon_decay = RIL_DEFAULT_EXPLORE_DECAY;
2826 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2827 "RIL_EXPLORE_DECAY",
2828 &f_tmp))
2829 {
2830 if ((f_tmp < 0.0) || (f_tmp > 1.0))
2756 { 2831 {
2757 solver->parameters.eligibility_trace_mode = RIL_E_REPLACE; 2832 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2833 "RIL_EXPLORE_DECAY", f_tmp);
2758 } 2834 }
2759 else 2835 else
2760 { 2836 {
2761 solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE; 2837 solver->parameters.epsilon_decay = f_tmp;
2838 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2839 "RIL_EXPLORE_DECAY", f_tmp);
2762 } 2840 }
2841 }
2763 2842
2764 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(env->cfg, "ats", "RIL_SOCIAL_WELFARE", &string)) 2843 solver->parameters.temperature_init = RIL_DEFAULT_TEMPERATURE;
2844 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2845 "RIL_TEMPERATURE",
2846 &f_tmp))
2847 {
2848 if (f_tmp <= 0.0)
2765 { 2849 {
2766 solver->parameters.social_welfare = !strcmp(string, "NASH") ? RIL_WELFARE_NASH : RIL_WELFARE_EGALITARIAN; 2850 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2767 GNUNET_free(string); 2851 "RIL_TEMPERATURE", f_tmp);
2768 } 2852 }
2769 else 2853 else
2770 { 2854 {
2771 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE; 2855 solver->parameters.temperature_init = f_tmp;
2856 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2857 "RIL_TEMPERATURE", f_tmp);
2772 } 2858 }
2859 }
2860
2861 solver->parameters.temperature_decay = RIL_DEFAULT_TEMPERATURE_DECAY;
2862 if (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_float (env->cfg, "ats",
2863 "RIL_TEMPERATURE_DECAY",
2864 &f_tmp))
2865 {
2866 if ((f_tmp <= 0.0) ||(solver->parameters.temperature_decay > 1) )
2867 {
2868 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Invalid %s configuration %f \n"),
2869 "RIL_TEMPERATURE_DECAY", f_tmp);
2870 }
2871 else
2872 {
2873 solver->parameters.temperature_decay = f_tmp;
2874 LOG (GNUNET_ERROR_TYPE_INFO, "Using %s of %.3f\n",
2875 "RIL_TEMPERATURE_DECAY", f_tmp);
2876 }
2877 }
2878
2879 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, "ats",
2880 "RIL_SIMULATE",
2881 &solver->simulate))
2882 {
2883 solver->simulate = GNUNET_NO;
2884 }
2885
2886 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "ats",
2887 "RIL_REPLACE_TRACES"))
2888 {
2889 solver->parameters.eligibility_trace_mode = RIL_E_REPLACE;
2890 }
2891 else
2892 {
2893 solver->parameters.eligibility_trace_mode = RIL_E_ACCUMULATE;
2894 }
2895
2896 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, "ats",
2897 "RIL_SOCIAL_WELFARE",
2898 &string))
2899 {
2900 solver->parameters.social_welfare = ! strcmp (string, "NASH") ?
2901 RIL_WELFARE_NASH :
2902 RIL_WELFARE_EGALITARIAN;
2903 GNUNET_free (string);
2904 }
2905 else
2906 {
2907 solver->parameters.social_welfare = RIL_DEFAULT_WELFARE;
2908 }
2773 2909
2774 solver->env = env; 2910 solver->env = env;
2775 sf.cls = solver; 2911 sf.cls = solver;
@@ -2784,35 +2920,38 @@ libgnunet_plugin_ats_ril_init(void *cls)
2784 sf.s_bulk_stop = &GAS_ril_bulk_stop; 2920 sf.s_bulk_stop = &GAS_ril_bulk_stop;
2785 2921
2786 solver->networks_count = env->network_count; 2922 solver->networks_count = env->network_count;
2787 solver->network_entries = GNUNET_malloc(env->network_count * sizeof(struct RIL_Scope)); 2923 solver->network_entries = GNUNET_malloc (env->network_count * sizeof(struct
2924 RIL_Scope));
2788 solver->step_count = 0; 2925 solver->step_count = 0;
2789 solver->done = GNUNET_NO; 2926 solver->done = GNUNET_NO;
2790 2927
2791 for (c = 0; c < env->network_count; c++) 2928 for (c = 0; c < env->network_count; c++)
2792 { 2929 {
2793 cur = &solver->network_entries[c]; 2930 cur = &solver->network_entries[c];
2794 cur->type = c; 2931 cur->type = c;
2795 cur->bw_in_available = env->in_quota[c]; 2932 cur->bw_in_available = env->in_quota[c];
2796 cur->bw_out_available = env->out_quota[c]; 2933 cur->bw_out_available = env->out_quota[c];
2797 LOG(GNUNET_ERROR_TYPE_DEBUG, 2934 LOG (GNUNET_ERROR_TYPE_DEBUG,
2798 "init() Quotas for %s network: IN %llu - OUT %llu\n", 2935 "init() Quotas for %s network: IN %llu - OUT %llu\n",
2799 GNUNET_NT_to_string(cur->type), 2936 GNUNET_NT_to_string (cur->type),
2800 cur->bw_in_available / 1024, 2937 cur->bw_in_available / 1024,
2801 cur->bw_out_available / 1024); 2938 cur->bw_out_available / 1024);
2802 } 2939 }
2803 2940
2804 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n"); 2941 LOG (GNUNET_ERROR_TYPE_DEBUG, "init() Parameters:\n");
2805 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n", 2942 LOG (GNUNET_ERROR_TYPE_DEBUG,
2806 solver->parameters.algorithm ? "Q" : "SARSA", 2943 "init() Algorithm = %s, alpha = %f, beta = %f, lambda = %f\n",
2807 solver->parameters.alpha, 2944 solver->parameters.algorithm ? "Q" : "SARSA",
2808 solver->parameters.beta, 2945 solver->parameters.alpha,
2809 solver->parameters.lambda); 2946 solver->parameters.beta,
2810 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n", 2947 solver->parameters.lambda);
2811 solver->parameters.epsilon, 2948 LOG (GNUNET_ERROR_TYPE_DEBUG,
2812 solver->parameters.temperature, 2949 "init() exploration_ratio = %f, temperature = %f, ActionSelection = %s\n",
2813 solver->parameters.select ? "EGREEDY" : "SOFTMAX"); 2950 solver->parameters.epsilon,
2814 LOG(GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n", 2951 solver->parameters.temperature,
2815 solver->parameters.rbf_divisor); 2952 solver->parameters.select ? "EGREEDY" : "SOFTMAX");
2953 LOG (GNUNET_ERROR_TYPE_DEBUG, "init() RBF_DIVISOR = %llu\n",
2954 solver->parameters.rbf_divisor);
2816 2955
2817 return &sf; 2956 return &sf;
2818} 2957}
@@ -2824,32 +2963,32 @@ libgnunet_plugin_ats_ril_init(void *cls)
2824 * @param cls the solver handle 2963 * @param cls the solver handle
2825 */ 2964 */
2826void * 2965void *
2827libgnunet_plugin_ats_ril_done(void *cls) 2966libgnunet_plugin_ats_ril_done (void *cls)
2828{ 2967{
2829 struct GNUNET_ATS_SolverFunctions *sf = cls; 2968 struct GNUNET_ATS_SolverFunctions *sf = cls;
2830 struct GAS_RIL_Handle *s = sf->cls; 2969 struct GAS_RIL_Handle *s = sf->cls;
2831 struct RIL_Peer_Agent *cur_agent; 2970 struct RIL_Peer_Agent *cur_agent;
2832 struct RIL_Peer_Agent *next_agent; 2971 struct RIL_Peer_Agent *next_agent;
2833 2972
2834 LOG(GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n"); 2973 LOG (GNUNET_ERROR_TYPE_DEBUG, "API_done() Shutting down RIL solver\n");
2835 2974
2836 s->done = GNUNET_YES; 2975 s->done = GNUNET_YES;
2837 2976
2838 cur_agent = s->agents_head; 2977 cur_agent = s->agents_head;
2839 while (NULL != cur_agent) 2978 while (NULL != cur_agent)
2840 { 2979 {
2841 next_agent = cur_agent->next; 2980 next_agent = cur_agent->next;
2842 GNUNET_CONTAINER_DLL_remove(s->agents_head, s->agents_tail, cur_agent); 2981 GNUNET_CONTAINER_DLL_remove (s->agents_head, s->agents_tail, cur_agent);
2843 agent_die(s, cur_agent); 2982 agent_die (s, cur_agent);
2844 cur_agent = next_agent; 2983 cur_agent = next_agent;
2845 } 2984 }
2846 2985
2847 if (NULL != s->step_next_task_id) 2986 if (NULL != s->step_next_task_id)
2848 { 2987 {
2849 GNUNET_SCHEDULER_cancel(s->step_next_task_id); 2988 GNUNET_SCHEDULER_cancel (s->step_next_task_id);
2850 } 2989 }
2851 GNUNET_free(s->network_entries); 2990 GNUNET_free (s->network_entries);
2852 GNUNET_free(s); 2991 GNUNET_free (s);
2853 2992
2854 return NULL; 2993 return NULL;
2855} 2994}
diff --git a/src/ats/test_ats2_lib.c b/src/ats/test_ats2_lib.c
index 1b9f0e234..f2a8eb1ea 100644
--- a/src/ats/test_ats2_lib.c
+++ b/src/ats/test_ats2_lib.c
@@ -76,13 +76,13 @@ static struct GNUNET_ATS_SessionRecord *sr;
76 * @return 76 * @return
77 */ 77 */
78static void 78static void
79allocation_cb(void *cls, 79allocation_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 */
98static void 98static void
99suggestion_cb(void *cls, 99suggestion_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 */
114static void 114static void
115init_both(const struct GNUNET_CONFIGURATION_Handle *cfg) 115init_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 */
131static void 131static void
132finish_both(void) 132finish_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,10 +142,9 @@ 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 */
144static void 144static void
145provide_info_start(void) 145provide_info_start (void)
146{ 146{
147 struct GNUNET_ATS_Properties prop = 147 struct GNUNET_ATS_Properties prop = {
148 {
149 .delay = GNUNET_TIME_UNIT_FOREVER_REL, 148 .delay = GNUNET_TIME_UNIT_FOREVER_REL,
150 .goodput_out = 1048576, 149 .goodput_out = 1048576,
151 .goodput_in = 1048576, 150 .goodput_in = 1048576,
@@ -157,12 +156,12 @@ provide_info_start(void)
157 .cc = GNUNET_TRANSPORT_CC_UNKNOWN, 156 .cc = GNUNET_TRANSPORT_CC_UNKNOWN,
158 }; 157 };
159 158
160 sr = GNUNET_ATS_session_add(th, 159 sr = GNUNET_ATS_session_add (th,
161 &other_peer, 160 &other_peer,
162 "test-address", 161 "test-address",
163 NULL, 162 NULL,
164 &prop); 163 &prop);
165 GNUNET_assert(NULL != sr); 164 GNUNET_assert (NULL != sr);
166} 165}
167 166
168 167
@@ -170,9 +169,9 @@ provide_info_start(void)
170 * @brief Provide information about the end of an imaginary connection 169 * @brief Provide information about the end of an imaginary connection
171 */ 170 */
172static void 171static void
173provide_info_end(void) 172provide_info_end (void)
174{ 173{
175 GNUNET_ATS_session_del(sr); 174 GNUNET_ATS_session_del (sr);
176} 175}
177 176
178 177
@@ -180,24 +179,24 @@ provide_info_end(void)
180 * @brief Inform ATS about the need of a connection towards a peer 179 * @brief Inform ATS about the need of a connection towards a peer
181 */ 180 */
182static void 181static void
183get_suggestion(void) 182get_suggestion (void)
184{ 183{
185 struct GNUNET_ATS_ApplicationSuggestHandle *ash; 184 struct GNUNET_ATS_ApplicationSuggestHandle *ash;
186 185
187 ash = GNUNET_ATS_application_suggest(ah, 186 ash = GNUNET_ATS_application_suggest (ah,
188 &other_peer, 187 &other_peer,
189 GNUNET_MQ_PREFERENCE_NONE, 188 GNUNET_MQ_PREFERENCE_NONE,
190 GNUNET_BANDWIDTH_VALUE_MAX); 189 GNUNET_BANDWIDTH_VALUE_MAX);
191 GNUNET_assert(NULL != ash); 190 GNUNET_assert (NULL != ash);
192} 191}
193 192
194 193
195static void 194static void
196on_shutdown(void *cls) 195on_shutdown (void *cls)
197{ 196{
198 provide_info_end(); 197 provide_info_end ();
199 finish_both(); 198 finish_both ();
200 GNUNET_SCHEDULER_shutdown(); 199 GNUNET_SCHEDULER_shutdown ();
201} 200}
202 201
203 202
@@ -209,16 +208,16 @@ on_shutdown(void *cls)
209 * @param peer handle to the peer 208 * @param peer handle to the peer
210 */ 209 */
211static void 210static void
212run(void *cls, 211run (void *cls,
213 const struct GNUNET_CONFIGURATION_Handle *cfg, 212 const struct GNUNET_CONFIGURATION_Handle *cfg,
214 struct GNUNET_TESTING_Peer *peer) 213 struct GNUNET_TESTING_Peer *peer)
215{ 214{
216 init_both(cfg); 215 init_both (cfg);
217 provide_info_start(); 216 provide_info_start ();
218 get_suggestion(); 217 get_suggestion ();
219 (void)GNUNET_SCHEDULER_add_delayed(timeout, 218 (void) GNUNET_SCHEDULER_add_delayed (timeout,
220 &on_shutdown, 219 &on_shutdown,
221 NULL); 220 NULL);
222} 221}
223 222
224 223
@@ -231,27 +230,27 @@ run(void *cls,
231 * @return 230 * @return
232 */ 231 */
233int 232int
234main(int argc, 233main (int argc,
235 char *argv[]) 234 char *argv[])
236{ 235{
237 ret = 1; 236 ret = 1;
238 memset(&other_peer, 0, sizeof(struct GNUNET_PeerIdentity)); 237 memset (&other_peer, 0, sizeof(struct GNUNET_PeerIdentity));
239 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 238 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
240 2); 239 2);
241 if (0 != GNUNET_TESTING_peer_run("test-ats2-lib", 240 if (0 != GNUNET_TESTING_peer_run ("test-ats2-lib",
242 "test_ats2_lib.conf", 241 "test_ats2_lib.conf",
243 &run, NULL)) 242 &run, NULL))
244 { 243 {
245 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 244 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
246 "Running the testing peer failed.\n"); 245 "Running the testing peer failed.\n");
247 return 1; 246 return 1;
248 } 247 }
249 if (0 != ret) 248 if (0 != ret)
250 { 249 {
251 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 250 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
252 "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n"); 251 "Global status indicates unsuccessful testrun - probably allocation_cb was not called.\n");
253 ret = 77; // SKIP test, test not yet right! 252 ret = 77; // SKIP test, test not yet right!
254 } 253 }
255 return ret; 254 return ret;
256} 255}
257 256
diff --git a/src/ats/test_ats2_lib.h b/src/ats/test_ats2_lib.h
index f6d4d45b0..090abc20d 100644
--- a/src/ats/test_ats2_lib.h
+++ b/src/ats/test_ats2_lib.h
@@ -32,8 +32,8 @@
32///** 32///**
33// * Commands for the interpreter. 33// * Commands for the interpreter.
34// */ 34// */
35//enum CommandCode 35// enum CommandCode
36//{ 36// {
37// /** 37// /**
38// * End the test (passing). 38// * End the test (passing).
39// */ 39// */
@@ -123,14 +123,14 @@
123// */ 123// */
124// CMD_SLEEP 124// CMD_SLEEP
125// 125//
126//}; 126// };
127// 127//
128// 128//
129///** 129///**
130// * Details for the #CMD_ADD_ADDRESS command. 130// * Details for the #CMD_ADD_ADDRESS command.
131// */ 131// */
132//struct CommandAddAddress 132// struct CommandAddAddress
133//{ 133// {
134// /** 134// /**
135// * Number of the peer (used to generate PID). 135// * Number of the peer (used to generate PID).
136// */ 136// */
@@ -165,27 +165,27 @@
165// * Here the result of the add address operation will be stored. 165// * Here the result of the add address operation will be stored.
166// */ 166// */
167// struct GNUNET_ATS_AddressRecord *ar; 167// struct GNUNET_ATS_AddressRecord *ar;
168//}; 168// };
169// 169//
170// 170//
171///** 171///**
172// * Details for the #CMD_DEL_ADDRESS command. 172// * Details for the #CMD_DEL_ADDRESS command.
173// */ 173// */
174//struct CommandDelAddress 174// struct CommandDelAddress
175//{ 175// {
176// /** 176// /**
177// * Label of the corresponding #CMD_ADD_ADDRESS that 177// * Label of the corresponding #CMD_ADD_ADDRESS that
178// * we are now to remove. 178// * we are now to remove.
179// */ 179// */
180// const char *add_label; 180// const char *add_label;
181//}; 181// };
182// 182//
183// 183//
184///** 184///**
185// * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. 185// * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
186// */ 186// */
187//struct CommandAwaitAddressSuggestion 187// struct CommandAwaitAddressSuggestion
188//{ 188// {
189// /** 189// /**
190// * For which peer do we expect a suggestion? 190// * For which peer do we expect a suggestion?
191// */ 191// */
@@ -198,27 +198,27 @@
198// */ 198// */
199// const char *add_label; 199// const char *add_label;
200// 200//
201//}; 201// };
202// 202//
203// 203//
204///** 204///**
205// * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. 205// * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
206// */ 206// */
207//struct CommandAwaitDisconnectSuggestion 207// struct CommandAwaitDisconnectSuggestion
208//{ 208// {
209// /** 209// /**
210// * For which peer do we expect the disconnect? 210// * For which peer do we expect the disconnect?
211// */ 211// */
212// unsigned int pid; 212// unsigned int pid;
213// 213//
214//}; 214// };
215// 215//
216// 216//
217///** 217///**
218// * Details for the #CMD_REQUEST_CONNECTION_START command. 218// * Details for the #CMD_REQUEST_CONNECTION_START command.
219// */ 219// */
220//struct CommandRequestConnectionStart 220// struct CommandRequestConnectionStart
221//{ 221// {
222// /** 222// /**
223// * Identity of the peer we would like to connect to. 223// * Identity of the peer we would like to connect to.
224// */ 224// */
@@ -229,27 +229,27 @@
229// * #GNUNET_ATS_connectivity_suggest(). 229// * #GNUNET_ATS_connectivity_suggest().
230// */ 230// */
231// struct GNUNET_ATS_ConnectivitySuggestHandle *csh; 231// struct GNUNET_ATS_ConnectivitySuggestHandle *csh;
232//}; 232// };
233// 233//
234// 234//
235///** 235///**
236// * Details for the #CMD_REQUEST_CONNECTION_STOP command. 236// * Details for the #CMD_REQUEST_CONNECTION_STOP command.
237// */ 237// */
238//struct CommandRequestConnectionStop 238// struct CommandRequestConnectionStop
239//{ 239// {
240// /** 240// /**
241// * Label of the corresponding #CMD_REQUEST_CONNECTION_START that 241// * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
242// * we are now stopping. 242// * we are now stopping.
243// */ 243// */
244// const char *connect_label; 244// const char *connect_label;
245//}; 245// };
246// 246//
247// 247//
248///** 248///**
249// * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. 249// * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
250// */ 250// */
251//struct CommandAwaitAddressInformation 251// struct CommandAwaitAddressInformation
252//{ 252// {
253// /** 253// /**
254// * For which address do we expect information? 254// * For which address do we expect information?
255// * The address is identified by the respective 255// * The address is identified by the respective
@@ -264,14 +264,14 @@
264// */ 264// */
265// const char *update_label; 265// const char *update_label;
266// 266//
267//}; 267// };
268// 268//
269// 269//
270///** 270///**
271// * Details for the #CMD_UPDATE_ADDRESS command. 271// * Details for the #CMD_UPDATE_ADDRESS command.
272// */ 272// */
273//struct CommandUpdateAddress 273// struct CommandUpdateAddress
274//{ 274// {
275// /** 275// /**
276// * Label of the addresses's add operation. 276// * Label of the addresses's add operation.
277// */ 277// */
@@ -282,14 +282,14 @@
282// */ 282// */
283// struct GNUNET_ATS_Properties properties; 283// struct GNUNET_ATS_Properties properties;
284// 284//
285//}; 285// };
286// 286//
287// 287//
288///** 288///**
289// * Details for the #CMD_ADD_SESSION command. 289// * Details for the #CMD_ADD_SESSION command.
290// */ 290// */
291//struct CommandAddSession 291// struct CommandAddSession
292//{ 292// {
293// /** 293// /**
294// * Label of the addresses's add operation. 294// * Label of the addresses's add operation.
295// */ 295// */
@@ -300,27 +300,27 @@
300// */ 300// */
301// unsigned int session; 301// unsigned int session;
302// 302//
303//}; 303// };
304// 304//
305// 305//
306///** 306///**
307// * Details for the #CMD_DEL_SESSION command. 307// * Details for the #CMD_DEL_SESSION command.
308// */ 308// */
309//struct CommandDelSession 309// struct CommandDelSession
310//{ 310// {
311// /** 311// /**
312// * Label of the addresses's add operation. 312// * Label of the addresses's add operation.
313// */ 313// */
314// const char *add_session_label; 314// const char *add_session_label;
315// 315//
316//}; 316// };
317// 317//
318// 318//
319///** 319///**
320// * Details for the #CMD_CHANGE_PREFERENCE command. 320// * Details for the #CMD_CHANGE_PREFERENCE command.
321// */ 321// */
322//struct CommandChangePreference 322// struct CommandChangePreference
323//{ 323// {
324// /** 324// /**
325// * Identity of the peer we have a preference change towards. 325// * Identity of the peer we have a preference change towards.
326// */ 326// */
@@ -328,14 +328,14 @@
328// 328//
329// /* FIXME: preference details! */ 329// /* FIXME: preference details! */
330// 330//
331//}; 331// };
332// 332//
333// 333//
334///** 334///**
335// * Details for the #CMD_PROVIDE_FEEDBACK command. 335// * Details for the #CMD_PROVIDE_FEEDBACK command.
336// */ 336// */
337//struct CommandProvideFeedback 337// struct CommandProvideFeedback
338//{ 338// {
339// /** 339// /**
340// * Identity of the peer we have a feedback for. 340// * Identity of the peer we have a feedback for.
341// */ 341// */
@@ -347,14 +347,14 @@
347// struct GNUNET_TIME_Relative scope; 347// struct GNUNET_TIME_Relative scope;
348// 348//
349// /* FIXME: feedback details! */ 349// /* FIXME: feedback details! */
350//}; 350// };
351// 351//
352// 352//
353///** 353///**
354// * Details for the #CMD_LIST_ADDRESSES command. 354// * Details for the #CMD_LIST_ADDRESSES command.
355// */ 355// */
356//struct CommandListAddresses 356// struct CommandListAddresses
357//{ 357// {
358// /** 358// /**
359// * Identity of the peer we want a list for. 359// * Identity of the peer we want a list for.
360// */ 360// */
@@ -403,14 +403,14 @@
403// */ 403// */
404// struct GNUNET_ATS_AddressListHandle *alh; 404// struct GNUNET_ATS_AddressListHandle *alh;
405// 405//
406//}; 406// };
407// 407//
408// 408//
409///** 409///**
410// * Details for the #CMD_RESERVE_BANDWIDTH command. 410// * Details for the #CMD_RESERVE_BANDWIDTH command.
411// */ 411// */
412//struct CommandReserveBandwidth 412// struct CommandReserveBandwidth
413//{ 413// {
414// /** 414// /**
415// * For which peer do we reserve bandwidth? 415// * For which peer do we reserve bandwidth?
416// */ 416// */
@@ -435,26 +435,26 @@
435// */ 435// */
436// struct GNUNET_ATS_ReservationContext *rc; 436// struct GNUNET_ATS_ReservationContext *rc;
437// 437//
438//}; 438// };
439// 439//
440// 440//
441///** 441///**
442// * Details for the #CMD_SLEEP command. 442// * Details for the #CMD_SLEEP command.
443// */ 443// */
444//struct CommandSleep 444// struct CommandSleep
445//{ 445// {
446// /** 446// /**
447// * How long should we wait before running the next command? 447// * How long should we wait before running the next command?
448// */ 448// */
449// struct GNUNET_TIME_Relative delay; 449// struct GNUNET_TIME_Relative delay;
450//}; 450// };
451// 451//
452// 452//
453///** 453///**
454// * A command for the test case interpreter. 454// * A command for the test case interpreter.
455// */ 455// */
456//struct Command 456// struct Command
457//{ 457// {
458// /** 458// /**
459// * Command code to run. 459// * Command code to run.
460// */ 460// */
@@ -502,7 +502,7 @@
502// 502//
503// } details; 503// } details;
504// 504//
505//}; 505// };
506 506
507 507
508/** 508/**
@@ -515,9 +515,9 @@
515 * @return 0 on success 515 * @return 0 on success
516 */ 516 */
517int 517int
518TEST_ATS_run(int argc, 518TEST_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 bc703a111..0ec1bbdef 100644
--- a/src/ats/test_ats_api.c
+++ b/src/ats/test_ats_api.c
@@ -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.
@@ -233,13 +233,13 @@ static struct Command test_commands[] = {
233 233
234 234
235int 235int
236main(int argc, 236main (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 979dbde3e..cd512634d 100644
--- a/src/ats/test_ats_lib.c
+++ b/src/ats/test_ats_lib.c
@@ -31,7 +31,8 @@
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 */
34struct AddressSuggestData { 34struct AddressSuggestData
35{
35 /** 36 /**
36 * Which session were we given? 37 * Which session were we given?
37 */ 38 */
@@ -62,7 +63,8 @@ struct AddressSuggestData {
62/** 63/**
63 * Information about the last address information we got for an address. 64 * Information about the last address information we got for an address.
64 */ 65 */
65struct AddressInformationData { 66struct AddressInformationData
67{
66 /** 68 /**
67 * What address is this data about? 69 * What address is this data about?
68 */ 70 */
@@ -154,18 +156,18 @@ static struct Command *test_commands;
154 * @return #GNUNET_OK (continue to iterate) 156 * @return #GNUNET_OK (continue to iterate)
155 */ 157 */
156static int 158static int
157free_asd(void *cls, 159free_asd (void *cls,
158 const struct GNUNET_PeerIdentity *key, 160 const struct GNUNET_PeerIdentity *key,
159 void *value) 161 void *value)
160{ 162{
161 struct AddressSuggestData *asd = value; 163 struct AddressSuggestData *asd = value;
162 164
163 GNUNET_assert(GNUNET_YES == 165 GNUNET_assert (GNUNET_YES ==
164 GNUNET_CONTAINER_multipeermap_remove(p2asd, 166 GNUNET_CONTAINER_multipeermap_remove (p2asd,
165 key, 167 key,
166 asd)); 168 asd));
167 GNUNET_free_non_null(asd->address); 169 GNUNET_free_non_null (asd->address);
168 GNUNET_free(asd); 170 GNUNET_free (asd);
169 return GNUNET_OK; 171 return GNUNET_OK;
170} 172}
171 173
@@ -179,18 +181,18 @@ free_asd(void *cls,
179 * @return #GNUNET_OK (continue to iterate) 181 * @return #GNUNET_OK (continue to iterate)
180 */ 182 */
181static int 183static int
182free_aid(void *cls, 184free_aid (void *cls,
183 const struct GNUNET_PeerIdentity *key, 185 const struct GNUNET_PeerIdentity *key,
184 void *value) 186 void *value)
185{ 187{
186 struct AddressInformationData *aid = value; 188 struct AddressInformationData *aid = value;
187 189
188 GNUNET_assert(GNUNET_YES == 190 GNUNET_assert (GNUNET_YES ==
189 GNUNET_CONTAINER_multipeermap_remove(p2aid, 191 GNUNET_CONTAINER_multipeermap_remove (p2aid,
190 key, 192 key,
191 aid)); 193 aid));
192 GNUNET_free(aid->address); 194 GNUNET_free (aid->address);
193 GNUNET_free(aid); 195 GNUNET_free (aid);
194 return GNUNET_OK; 196 return GNUNET_OK;
195} 197}
196 198
@@ -202,17 +204,18 @@ free_aid(void *cls,
202 * @return NULL if peer was never involved 204 * @return NULL if peer was never involved
203 */ 205 */
204static struct AddressSuggestData * 206static struct AddressSuggestData *
205find_address_suggestion(const struct GNUNET_PeerIdentity *pid) 207find_address_suggestion (const struct GNUNET_PeerIdentity *pid)
206{ 208{
207 return GNUNET_CONTAINER_multipeermap_get(p2asd, 209 return GNUNET_CONTAINER_multipeermap_get (p2asd,
208 pid); 210 pid);
209} 211}
210 212
211 213
212/** 214/**
213 * Closure for #match_address() 215 * Closure for #match_address()
214 */ 216 */
215struct MatchAddressContext { 217struct MatchAddressContext
218{
216 /** 219 /**
217 * Address to find. 220 * Address to find.
218 */ 221 */
@@ -234,19 +237,19 @@ struct MatchAddressContext {
234 * @return #GNUNET_OK if not found 237 * @return #GNUNET_OK if not found
235 */ 238 */
236static int 239static int
237match_address(void *cls, 240match_address (void *cls,
238 const struct GNUNET_PeerIdentity *key, 241 const struct GNUNET_PeerIdentity *key,
239 void *value) 242 void *value)
240{ 243{
241 struct MatchAddressContext *mac = cls; 244 struct MatchAddressContext *mac = cls;
242 struct AddressInformationData *aid = value; 245 struct AddressInformationData *aid = value;
243 246
244 if (0 == GNUNET_HELLO_address_cmp(mac->addr, 247 if (0 == GNUNET_HELLO_address_cmp (mac->addr,
245 aid->address)) 248 aid->address))
246 { 249 {
247 mac->ret = aid; 250 mac->ret = aid;
248 return GNUNET_NO; 251 return GNUNET_NO;
249 } 252 }
250 return GNUNET_OK; 253 return GNUNET_OK;
251} 254}
252 255
@@ -258,16 +261,16 @@ match_address(void *cls,
258 * @return NULL if peer was never involved 261 * @return NULL if peer was never involved
259 */ 262 */
260static struct AddressInformationData * 263static struct AddressInformationData *
261find_address_information(const struct GNUNET_HELLO_Address *addr) 264find_address_information (const struct GNUNET_HELLO_Address *addr)
262{ 265{
263 struct MatchAddressContext mac; 266 struct MatchAddressContext mac;
264 267
265 mac.ret = NULL; 268 mac.ret = NULL;
266 mac.addr = addr; 269 mac.addr = addr;
267 GNUNET_CONTAINER_multipeermap_get_multiple(p2aid, 270 GNUNET_CONTAINER_multipeermap_get_multiple (p2aid,
268 &addr->peer, 271 &addr->peer,
269 &match_address, 272 &match_address,
270 &mac); 273 &mac);
271 return mac.ret; 274 return mac.ret;
272} 275}
273 276
@@ -278,51 +281,51 @@ find_address_information(const struct GNUNET_HELLO_Address *addr)
278 * @param cls NULL 281 * @param cls NULL
279 */ 282 */
280static void 283static void
281end(void *cls) 284end (void *cls)
282{ 285{
283 if (0 != ret) 286 if (0 != ret)
284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
285 "Test failed at stage %u %s\n", 288 "Test failed at stage %u %s\n",
286 off, 289 off,
287 (NULL != test_commands[off].label) 290 (NULL != test_commands[off].label)
288 ? test_commands[off].label 291 ? test_commands[off].label
289 : ""); 292 : "");
290 if (NULL != interpreter_task) 293 if (NULL != interpreter_task)
291 { 294 {
292 GNUNET_SCHEDULER_cancel(interpreter_task); 295 GNUNET_SCHEDULER_cancel (interpreter_task);
293 interpreter_task = NULL; 296 interpreter_task = NULL;
294 } 297 }
295 if (NULL != sched_ats) 298 if (NULL != sched_ats)
296 { 299 {
297 GNUNET_ATS_scheduling_done(sched_ats); 300 GNUNET_ATS_scheduling_done (sched_ats);
298 sched_ats = NULL; 301 sched_ats = NULL;
299 } 302 }
300 if (NULL != con_ats) 303 if (NULL != con_ats)
301 { 304 {
302 GNUNET_ATS_connectivity_done(con_ats); 305 GNUNET_ATS_connectivity_done (con_ats);
303 con_ats = NULL; 306 con_ats = NULL;
304 } 307 }
305 if (NULL != perf_ats) 308 if (NULL != perf_ats)
306 { 309 {
307 GNUNET_ATS_performance_done(perf_ats); 310 GNUNET_ATS_performance_done (perf_ats);
308 perf_ats = NULL; 311 perf_ats = NULL;
309 } 312 }
310 if (NULL != p2asd) 313 if (NULL != p2asd)
311 { 314 {
312 GNUNET_CONTAINER_multipeermap_iterate(p2asd, 315 GNUNET_CONTAINER_multipeermap_iterate (p2asd,
313 &free_asd, 316 &free_asd,
314 NULL); 317 NULL);
315 GNUNET_CONTAINER_multipeermap_destroy(p2asd); 318 GNUNET_CONTAINER_multipeermap_destroy (p2asd);
316 p2asd = NULL; 319 p2asd = NULL;
317 } 320 }
318 if (NULL != p2aid) 321 if (NULL != p2aid)
319 { 322 {
320 GNUNET_CONTAINER_multipeermap_iterate(p2aid, 323 GNUNET_CONTAINER_multipeermap_iterate (p2aid,
321 &free_aid, 324 &free_aid,
322 NULL); 325 NULL);
323 GNUNET_CONTAINER_multipeermap_destroy(p2aid); 326 GNUNET_CONTAINER_multipeermap_destroy (p2aid);
324 p2aid = NULL; 327 p2aid = NULL;
325 } 328 }
326} 329}
327 330
328 331
@@ -332,19 +335,19 @@ end(void *cls)
332 * @param cls NULL 335 * @param cls NULL
333 */ 336 */
334static void 337static void
335interpreter(void *cls); 338interpreter (void *cls);
336 339
337 340
338/** 341/**
339 * Run the interpreter next. 342 * Run the interpreter next.
340 */ 343 */
341static void 344static void
342run_interpreter() 345run_interpreter ()
343{ 346{
344 if (NULL != interpreter_task) 347 if (NULL != interpreter_task)
345 GNUNET_SCHEDULER_cancel(interpreter_task); 348 GNUNET_SCHEDULER_cancel (interpreter_task);
346 interpreter_task = GNUNET_SCHEDULER_add_now(&interpreter, 349 interpreter_task = GNUNET_SCHEDULER_add_now (&interpreter,
347 NULL); 350 NULL);
348} 351}
349 352
350 353
@@ -355,15 +358,15 @@ run_interpreter()
355 * @param pk resulting fake public key 358 * @param pk resulting fake public key
356 */ 359 */
357static void 360static void
358make_peer(uint32_t pid, 361make_peer (uint32_t pid,
359 struct GNUNET_PeerIdentity *pk) 362 struct GNUNET_PeerIdentity *pk)
360{ 363{
361 memset(pk, 364 memset (pk,
362 (int)pid, 365 (int) pid,
363 sizeof(struct GNUNET_PeerIdentity)); 366 sizeof(struct GNUNET_PeerIdentity));
364 GNUNET_memcpy(pk, 367 GNUNET_memcpy (pk,
365 &pid, 368 &pid,
366 sizeof(uint32_t)); 369 sizeof(uint32_t));
367} 370}
368 371
369 372
@@ -376,28 +379,29 @@ make_peer(uint32_t pid,
376 * @return the address 379 * @return the address
377 */ 380 */
378static struct GNUNET_HELLO_Address * 381static struct GNUNET_HELLO_Address *
379make_address(uint32_t pid, 382make_address (uint32_t pid,
380 uint32_t num, 383 uint32_t num,
381 enum GNUNET_HELLO_AddressInfo addr_flags) 384 enum GNUNET_HELLO_AddressInfo addr_flags)
382{ 385{
383 struct GNUNET_PeerIdentity pk; 386 struct GNUNET_PeerIdentity pk;
384 uint32_t nbo; 387 uint32_t nbo;
385 388
386 nbo = htonl(num); 389 nbo = htonl (num);
387 make_peer(pid, 390 make_peer (pid,
388 &pk); 391 &pk);
389 return GNUNET_HELLO_address_allocate(&pk, 392 return GNUNET_HELLO_address_allocate (&pk,
390 "test", 393 "test",
391 &nbo, 394 &nbo,
392 sizeof(nbo), 395 sizeof(nbo),
393 addr_flags); 396 addr_flags);
394} 397}
395 398
396 399
397/** 400/**
398 * Our dummy sessions. 401 * Our dummy sessions.
399 */ 402 */
400struct GNUNET_ATS_Session { 403struct GNUNET_ATS_Session
404{
401 /** 405 /**
402 * Field to avoid `0 == sizeof(struct GNUNET_ATS_Session)`. 406 * Field to avoid `0 == sizeof(struct GNUNET_ATS_Session)`.
403 */ 407 */
@@ -412,7 +416,7 @@ struct GNUNET_ATS_Session {
412 * @return NULL if @a i is 0, otherwise a pointer unique to @a i 416 * @return NULL if @a i is 0, otherwise a pointer unique to @a i
413 */ 417 */
414static struct GNUNET_ATS_Session * 418static struct GNUNET_ATS_Session *
415make_session(unsigned int i) 419make_session (unsigned int i)
416{ 420{
417 struct GNUNET_ATS_Session *baseptr = NULL; 421 struct GNUNET_ATS_Session *baseptr = NULL;
418 422
@@ -434,8 +438,8 @@ make_session(unsigned int i)
434 * @return previous command with the matching label 438 * @return previous command with the matching label
435 */ 439 */
436static struct Command * 440static struct Command *
437find_command(enum CommandCode code, 441find_command (enum CommandCode code,
438 const char *label) 442 const char *label)
439{ 443{
440 int i; 444 int i;
441 445
@@ -443,10 +447,10 @@ find_command(enum CommandCode code,
443 return NULL; 447 return NULL;
444 for (i = off - 1; i >= 0; i--) 448 for (i = off - 1; i >= 0; i--)
445 if ((code == test_commands[i].code) && 449 if ((code == test_commands[i].code) &&
446 (0 == strcmp(test_commands[i].label, 450 (0 == strcmp (test_commands[i].label,
447 label))) 451 label)))
448 return &test_commands[i]; 452 return &test_commands[i];
449 GNUNET_break(0); 453 GNUNET_break (0);
450 return NULL; 454 return NULL;
451} 455}
452 456
@@ -466,53 +470,53 @@ find_command(enum CommandCode code,
466 * @param prop performance data for the address 470 * @param prop performance data for the address
467 */ 471 */
468static void 472static void
469info_cb(void *cls, 473info_cb (void *cls,
470 const struct GNUNET_HELLO_Address *address, 474 const struct GNUNET_HELLO_Address *address,
471 int address_active, 475 int address_active,
472 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 476 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
473 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 477 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
474 const struct GNUNET_ATS_Properties *prop) 478 const struct GNUNET_ATS_Properties *prop)
475{ 479{
476 struct Command *c = cls; 480 struct Command *c = cls;
477 struct CommandListAddresses *cmd = &c->details.list_addresses; 481 struct CommandListAddresses *cmd = &c->details.list_addresses;
478 482
479 if (NULL == address) 483 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))
480 { 489 {
481 cmd->alh = NULL; 490 GNUNET_SCHEDULER_shutdown ();
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 }
493 switch (address_active) 497 switch (address_active)
494 { 498 {
495 case GNUNET_YES: 499 case GNUNET_YES:
496 cmd->active_calls++; 500 cmd->active_calls++;
497 cmd->calls++; 501 cmd->calls++;
498 break; 502 break;
499 503
500 case GNUNET_NO: 504 case GNUNET_NO:
501 cmd->calls++; 505 cmd->calls++;
502 break; 506 break;
503 507
504 case GNUNET_SYSERR: 508 case GNUNET_SYSERR:
505 return; 509 return;
506 } 510 }
507 if ((cmd->calls > cmd->max_calls) && 511 if ((cmd->calls > cmd->max_calls) &&
508 (cmd->active_calls < cmd->max_active_calls)) 512 (cmd->active_calls < cmd->max_active_calls))
509 { 513 {
510 GNUNET_break(0); 514 GNUNET_break (0);
511 GNUNET_ATS_performance_list_addresses_cancel(cmd->alh); 515 GNUNET_ATS_performance_list_addresses_cancel (cmd->alh);
512 cmd->alh = NULL; 516 cmd->alh = NULL;
513 GNUNET_SCHEDULER_shutdown(); 517 GNUNET_SCHEDULER_shutdown ();
514 return; 518 return;
515 } 519 }
516} 520}
517 521
518 522
@@ -527,58 +531,58 @@ info_cb(void *cls,
527 * long should the client wait until re-trying? 531 * long should the client wait until re-trying?
528 */ 532 */
529static void 533static void
530reservation_cb(void *cls, 534reservation_cb (void *cls,
531 const struct GNUNET_PeerIdentity *peer, 535 const struct GNUNET_PeerIdentity *peer,
532 int32_t amount, 536 int32_t amount,
533 struct GNUNET_TIME_Relative res_delay) 537 struct GNUNET_TIME_Relative res_delay)
534{ 538{
535 struct Command *cmd = cls; 539 struct Command *cmd = cls;
536 struct GNUNET_PeerIdentity pid; 540 struct GNUNET_PeerIdentity pid;
537 541
538 cmd->details.reserve_bandwidth.rc = NULL; 542 cmd->details.reserve_bandwidth.rc = NULL;
539 make_peer(cmd->details.reserve_bandwidth.pid, 543 make_peer (cmd->details.reserve_bandwidth.pid,
540 &pid); 544 &pid);
541 GNUNET_assert(0 == GNUNET_memcmp(peer, 545 GNUNET_assert (0 == GNUNET_memcmp (peer,
542 &pid)); 546 &pid));
543 switch (cmd->details.reserve_bandwidth.expected_result) 547 switch (cmd->details.reserve_bandwidth.expected_result)
548 {
549 case GNUNET_OK:
550 if (amount != cmd->details.reserve_bandwidth.amount)
544 { 551 {
545 case GNUNET_OK: 552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
546 if (amount != cmd->details.reserve_bandwidth.amount) 553 "Unexpectedly failed to reserve %d/%d bytes with delay %s!\n",
547 { 554 (int) amount,
548 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 555 (int) cmd->details.reserve_bandwidth.amount,
549 "Unexpectedly failed to reserve %d/%d bytes with delay %s!\n", 556 GNUNET_STRINGS_relative_time_to_string (res_delay,
550 (int)amount, 557 GNUNET_YES));
551 (int)cmd->details.reserve_bandwidth.amount, 558 GNUNET_break (0);
552 GNUNET_STRINGS_relative_time_to_string(res_delay, 559 GNUNET_SCHEDULER_shutdown ();
553 GNUNET_YES)); 560 return;
554 GNUNET_break(0); 561 }
555 GNUNET_SCHEDULER_shutdown(); 562 break;
556 return;
557 }
558 break;
559 563
560 case GNUNET_NO: 564 case GNUNET_NO:
561 GNUNET_break((0 != amount) || 565 GNUNET_break ((0 != amount) ||
562 (0 != res_delay.rel_value_us)); 566 (0 != res_delay.rel_value_us));
563 break; 567 break;
564 568
565 case GNUNET_SYSERR: 569 case GNUNET_SYSERR:
566 if ((amount != 0) || 570 if ((amount != 0) ||
567 (0 == res_delay.rel_value_us)) 571 (0 == res_delay.rel_value_us))
568 { 572 {
569 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 573 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
570 "Unexpectedly reserved %d bytes with delay %s!\n", 574 "Unexpectedly reserved %d bytes with delay %s!\n",
571 (int)amount, 575 (int) amount,
572 GNUNET_STRINGS_relative_time_to_string(res_delay, 576 GNUNET_STRINGS_relative_time_to_string (res_delay,
573 GNUNET_YES)); 577 GNUNET_YES));
574 GNUNET_break(0); 578 GNUNET_break (0);
575 GNUNET_SCHEDULER_shutdown(); 579 GNUNET_SCHEDULER_shutdown ();
576 return; 580 return;
577 }
578 break;
579 } 581 }
582 break;
583 }
580 off++; 584 off++;
581 run_interpreter(); 585 run_interpreter ();
582} 586}
583 587
584 588
@@ -588,297 +592,301 @@ reservation_cb(void *cls,
588 * @param cls NULL 592 * @param cls NULL
589 */ 593 */
590static void 594static void
591interpreter(void *cls) 595interpreter (void *cls)
592 596
593{ 597{
594 struct Command *cmd; 598 struct Command *cmd;
595 599
596 interpreter_task = NULL; 600 interpreter_task = NULL;
597 while (1) 601 while (1)
602 {
603 cmd = &test_commands[off];
604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
605 "#%u: %d %s\n",
606 off,
607 (int) cmd->code,
608 (NULL != cmd->label) ? cmd->label : "");
609 switch (cmd->code)
598 { 610 {
599 cmd = &test_commands[off]; 611 case CMD_END_PASS:
600 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 612 ret = 0;
601 "#%u: %d %s\n", 613 GNUNET_SCHEDULER_shutdown ();
602 off, 614 return;
603 (int)cmd->code,
604 (NULL != cmd->label) ? cmd->label : "");
605 switch (cmd->code)
606 {
607 case CMD_END_PASS:
608 ret = 0;
609 GNUNET_SCHEDULER_shutdown();
610 return;
611
612 case CMD_ADD_ADDRESS:
613 {
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;
641 }
642
643 case CMD_DEL_ADDRESS:
644 {
645 struct Command *add;
646
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;
654 }
655
656 case CMD_AWAIT_ADDRESS_SUGGESTION:
657 {
658 struct GNUNET_PeerIdentity pid;
659 struct GNUNET_HELLO_Address *addr;
660 struct Command *add;
661 struct AddressSuggestData *asd;
662 int done;
663
664 make_peer(cmd->details.await_address_suggestion.pid,
665 &pid);
666 asd = find_address_suggestion(&pid);
667 if (NULL == asd)
668 return;
669 if (GNUNET_NO == asd->active)
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;
692 }
693
694 case CMD_AWAIT_DISCONNECT_SUGGESTION:
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! */
707 off++;
708 break;
709 }
710
711 case CMD_REQUEST_CONNECTION_START:
712 {
713 struct GNUNET_PeerIdentity pid;
714
715 make_peer(cmd->details.request_connection_start.pid,
716 &pid);
717 cmd->details.request_connection_start.csh
718 = GNUNET_ATS_connectivity_suggest(con_ats,
719 &pid,
720 1);
721 off++;
722 break;
723 }
724 615
725 case CMD_REQUEST_CONNECTION_STOP: 616 case CMD_ADD_ADDRESS:
617 {
618 struct GNUNET_HELLO_Address *addr;
619 struct GNUNET_ATS_Session *session;
620
621 addr = make_address (cmd->details.add_address.pid,
622 cmd->details.add_address.addr_num,
623 cmd->details.add_address.addr_flags);
624 session = make_session (cmd->details.add_address.session);
625 if (cmd->details.add_address.expect_fail)
626 GNUNET_log_skip (1, GNUNET_NO);
627 cmd->details.add_address.ar
628 = GNUNET_ATS_address_add (sched_ats,
629 addr,
630 session,
631 &cmd->details.add_address.properties);
632 GNUNET_free (addr);
633 if (cmd->details.add_address.expect_fail)
726 { 634 {
727 struct Command *start; 635 GNUNET_log_skip (0, GNUNET_YES);
728
729 start = find_command(CMD_REQUEST_CONNECTION_START,
730 cmd->details.request_connection_stop.connect_label);
731 GNUNET_ATS_connectivity_suggest_cancel(start->details.request_connection_start.csh);
732 start->details.request_connection_start.csh = NULL;
733 off++;
734 break;
735 } 636 }
736 637 else if (NULL == cmd->details.add_address.ar)
737 case CMD_AWAIT_ADDRESS_INFORMATION:
738 { 638 {
739 struct AddressInformationData *aid; 639 GNUNET_break (0);
740 struct Command *add; 640 GNUNET_SCHEDULER_shutdown ();
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; 641 return;
769 } 642 }
770 643 off++;
771 case CMD_UPDATE_ADDRESS: 644 break;
645 }
646
647 case CMD_DEL_ADDRESS:
648 {
649 struct Command *add;
650
651 add = find_command (CMD_ADD_ADDRESS,
652 cmd->details.del_address.add_label);
653 GNUNET_assert (NULL != add->details.add_address.ar);
654 GNUNET_ATS_address_destroy (add->details.add_address.ar);
655 add->details.add_address.ar = NULL;
656 off++;
657 break;
658 }
659
660 case CMD_AWAIT_ADDRESS_SUGGESTION:
661 {
662 struct GNUNET_PeerIdentity pid;
663 struct GNUNET_HELLO_Address *addr;
664 struct Command *add;
665 struct AddressSuggestData *asd;
666 int done;
667
668 make_peer (cmd->details.await_address_suggestion.pid,
669 &pid);
670 asd = find_address_suggestion (&pid);
671 if (NULL == asd)
672 return;
673 if (GNUNET_NO == asd->active)
674 return; /* last suggestion was to disconnect, wait longer */
675 done = GNUNET_YES;
676 if (NULL != cmd->details.await_address_suggestion.add_label)
772 { 677 {
773 struct Command *add; 678 done = GNUNET_NO;
774 679 add = find_command (CMD_ADD_ADDRESS,
775 add = find_command(CMD_ADD_ADDRESS, 680 cmd->details.await_address_suggestion.add_label);
776 cmd->details.update_address.add_label); 681 addr = make_address (add->details.add_address.pid,
777 GNUNET_assert(NULL != add->details.add_address.ar); 682 add->details.add_address.addr_num,
778 GNUNET_ATS_address_update(add->details.add_address.ar, 683 add->details.add_address.addr_flags);
779 &cmd->details.update_address.properties); 684 if ((asd->session ==
780 off++; 685 make_session (add->details.add_address.session)) &&
781 break; 686 (0 ==
687 GNUNET_HELLO_address_cmp (addr,
688 asd->address)))
689 done = GNUNET_YES;
690 GNUNET_free (addr);
782 } 691 }
783 692 if (GNUNET_NO == done)
784 case CMD_ADD_SESSION: 693 return;
785 { 694 off++;
786 struct Command *add; 695 break;
787 struct GNUNET_ATS_Session *session; 696 }
788 697
789 add = find_command(CMD_ADD_ADDRESS, 698 case CMD_AWAIT_DISCONNECT_SUGGESTION:
790 cmd->details.add_session.add_label); 699 {
791 session = make_session(cmd->details.add_session.session); 700 struct GNUNET_PeerIdentity pid;
792 GNUNET_assert(NULL != add->details.add_address.ar); 701 struct AddressSuggestData *asd;
793 GNUNET_ATS_address_add_session(add->details.add_address.ar, 702
794 session); 703 make_peer (cmd->details.await_disconnect_suggestion.pid,
795 off++; 704 &pid);
796 break; 705 asd = find_address_suggestion (&pid);
797 } 706 if (NULL == asd)
798 707 return; /* odd, no suggestion at all yet!? */
799 case CMD_DEL_SESSION: 708 if (GNUNET_YES == asd->active)
709 return; /* last suggestion was to activate, wait longer */
710 /* last suggestion was to deactivate, condition satisfied! */
711 off++;
712 break;
713 }
714
715 case CMD_REQUEST_CONNECTION_START:
716 {
717 struct GNUNET_PeerIdentity pid;
718
719 make_peer (cmd->details.request_connection_start.pid,
720 &pid);
721 cmd->details.request_connection_start.csh
722 = GNUNET_ATS_connectivity_suggest (con_ats,
723 &pid,
724 1);
725 off++;
726 break;
727 }
728
729 case CMD_REQUEST_CONNECTION_STOP:
730 {
731 struct Command *start;
732
733 start = find_command (CMD_REQUEST_CONNECTION_START,
734 cmd->details.request_connection_stop.connect_label);
735 GNUNET_ATS_connectivity_suggest_cancel (
736 start->details.request_connection_start.csh);
737 start->details.request_connection_start.csh = NULL;
738 off++;
739 break;
740 }
741
742 case CMD_AWAIT_ADDRESS_INFORMATION:
743 {
744 struct AddressInformationData *aid;
745 struct Command *add;
746 struct Command *update;
747 struct GNUNET_HELLO_Address *addr;
748 const struct GNUNET_ATS_Properties *cmp;
749
750 add = find_command (CMD_ADD_ADDRESS,
751 cmd->details.await_address_information.add_label);
752 update = find_command (CMD_UPDATE_ADDRESS,
753 cmd->details.await_address_information.
754 update_label);
755 addr = make_address (add->details.add_address.pid,
756 add->details.add_address.addr_num,
757 add->details.add_address.addr_flags);
758 aid = find_address_information (addr);
759 GNUNET_free (addr);
760 if (NULL == update)
761 cmp = &add->details.add_address.properties;
762 else
763 cmp = &update->details.update_address.properties;
764 if ((NULL != aid) &&
765 (cmp->delay.rel_value_us == aid->properties.delay.rel_value_us) &&
766 (cmp->utilization_out == aid->properties.utilization_out) &&
767 (cmp->utilization_in == aid->properties.utilization_in) &&
768 (cmp->distance == aid->properties.distance) &&
769 (cmp->scope == aid->properties.scope))
800 { 770 {
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++; 771 off++;
814 break; 772 break;
815 } 773 }
816 774 return;
817 case CMD_CHANGE_PREFERENCE: 775 }
818 { 776
819 struct GNUNET_PeerIdentity pid; 777 case CMD_UPDATE_ADDRESS:
820 778 {
821 make_peer(cmd->details.change_preference.pid, 779 struct Command *add;
822 &pid); 780
823 GNUNET_ATS_performance_change_preference(perf_ats, 781 add = find_command (CMD_ADD_ADDRESS,
782 cmd->details.update_address.add_label);
783 GNUNET_assert (NULL != add->details.add_address.ar);
784 GNUNET_ATS_address_update (add->details.add_address.ar,
785 &cmd->details.update_address.properties);
786 off++;
787 break;
788 }
789
790 case CMD_ADD_SESSION:
791 {
792 struct Command *add;
793 struct GNUNET_ATS_Session *session;
794
795 add = find_command (CMD_ADD_ADDRESS,
796 cmd->details.add_session.add_label);
797 session = make_session (cmd->details.add_session.session);
798 GNUNET_assert (NULL != add->details.add_address.ar);
799 GNUNET_ATS_address_add_session (add->details.add_address.ar,
800 session);
801 off++;
802 break;
803 }
804
805 case CMD_DEL_SESSION:
806 {
807 struct Command *add_address;
808 struct Command *add_session;
809 struct GNUNET_ATS_Session *session;
810
811 add_session = find_command (CMD_ADD_SESSION,
812 cmd->details.del_session.add_session_label);
813 add_address = find_command (CMD_ADD_ADDRESS,
814 add_session->details.add_session.add_label);
815 GNUNET_assert (NULL != add_address->details.add_address.ar);
816 session = make_session (add_session->details.add_session.session);
817 GNUNET_ATS_address_del_session (add_address->details.add_address.ar,
818 session);
819 off++;
820 break;
821 }
822
823 case CMD_CHANGE_PREFERENCE:
824 {
825 struct GNUNET_PeerIdentity pid;
826
827 make_peer (cmd->details.change_preference.pid,
828 &pid);
829 GNUNET_ATS_performance_change_preference (perf_ats,
830 &pid,
831 GNUNET_ATS_PREFERENCE_END);
832 off++;
833 break;
834 }
835
836 case CMD_PROVIDE_FEEDBACK:
837 {
838 struct GNUNET_PeerIdentity pid;
839
840 make_peer (cmd->details.provide_feedback.pid,
841 &pid);
842 GNUNET_ATS_performance_give_feedback (perf_ats,
843 &pid,
844 cmd->details.provide_feedback.
845 scope,
846 GNUNET_ATS_PREFERENCE_END);
847 off++;
848 break;
849 }
850
851 case CMD_LIST_ADDRESSES:
852 {
853 struct GNUNET_PeerIdentity pid;
854
855 make_peer (cmd->details.list_addresses.pid,
856 &pid);
857 cmd->details.list_addresses.alh
858 = GNUNET_ATS_performance_list_addresses (perf_ats,
824 &pid, 859 &pid,
825 GNUNET_ATS_PREFERENCE_END); 860 cmd->details.list_addresses.
826 off++; 861 all,
827 break; 862 &info_cb,
828 } 863 cmd);
829 864 return;
830 case CMD_PROVIDE_FEEDBACK: 865 }
831 { 866
832 struct GNUNET_PeerIdentity pid; 867 case CMD_RESERVE_BANDWIDTH:
833 868 {
834 make_peer(cmd->details.provide_feedback.pid, 869 struct GNUNET_PeerIdentity pid;
835 &pid); 870
836 GNUNET_ATS_performance_give_feedback(perf_ats, 871 make_peer (cmd->details.reserve_bandwidth.pid,
837 &pid, 872 &pid);
838 cmd->details.provide_feedback.scope, 873 cmd->details.reserve_bandwidth.rc
839 GNUNET_ATS_PREFERENCE_END); 874 = GNUNET_ATS_reserve_bandwidth (perf_ats,
840 off++; 875 &pid,
841 break; 876 cmd->details.reserve_bandwidth.amount,
842 } 877 &reservation_cb,
843 878 cmd);
844 case CMD_LIST_ADDRESSES: 879 return;
845 { 880 }
846 struct GNUNET_PeerIdentity pid; 881
847 882 case CMD_SLEEP:
848 make_peer(cmd->details.list_addresses.pid, 883 off++;
849 &pid); 884 interpreter_task = GNUNET_SCHEDULER_add_delayed (cmd->details.sleep.delay,
850 cmd->details.list_addresses.alh 885 &interpreter,
851 = GNUNET_ATS_performance_list_addresses(perf_ats, 886 NULL);
852 &pid, 887 return;
853 cmd->details.list_addresses.all, 888 } /* end switch */
854 &info_cb, 889 } /* end while(1) */
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) */
882} 890}
883 891
884 892
@@ -897,59 +905,59 @@ interpreter(void *cls)
897 * 0 to signal disconnect 905 * 0 to signal disconnect
898 */ 906 */
899static void 907static void
900address_suggest_cb(void *cls, 908address_suggest_cb (void *cls,
901 const struct GNUNET_PeerIdentity *peer, 909 const struct GNUNET_PeerIdentity *peer,
902 const struct GNUNET_HELLO_Address *address, 910 const struct GNUNET_HELLO_Address *address,
903 struct GNUNET_ATS_Session *session, 911 struct GNUNET_ATS_Session *session,
904 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 912 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
905 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 913 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
906{ 914{
907 const char *asc_cls = cls; 915 const char *asc_cls = cls;
908 struct AddressSuggestData *asd; 916 struct AddressSuggestData *asd;
909 917
910 GNUNET_break(0 == strcmp(asc_cls, "asc-closure")); 918 GNUNET_break (0 == strcmp (asc_cls, "asc-closure"));
911 if (NULL == peer) 919 if (NULL == peer)
912 { 920 {
913 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 921 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
914 "Connection to ATS died, likely a crash!\n"); 922 "Connection to ATS died, likely a crash!\n");
915 GNUNET_SCHEDULER_shutdown(); 923 GNUNET_SCHEDULER_shutdown ();
916#if 0 924#if 0
917 /* This is what we should do if we wanted to continue past 925 /* This is what we should do if we wanted to continue past
918 the ATS crash. */ 926 the ATS crash. */
919 GNUNET_CONTAINER_multipeermap_iterate(p2asd, 927 GNUNET_CONTAINER_multipeermap_iterate (p2asd,
920 &free_asd, 928 &free_asd,
921 NULL); 929 NULL);
922 GNUNET_CONTAINER_multipeermap_iterate(p2aid, 930 GNUNET_CONTAINER_multipeermap_iterate (p2aid,
923 &free_aid, 931 &free_aid,
924 NULL); 932 NULL);
925#endif 933#endif
926 return; 934 return;
927 } 935 }
928 936
929 asd = find_address_suggestion(peer); 937 asd = find_address_suggestion (peer);
930 if (NULL == asd) 938 if (NULL == asd)
931 { 939 {
932 asd = GNUNET_new(struct AddressSuggestData); 940 asd = GNUNET_new (struct AddressSuggestData);
933 GNUNET_assert(GNUNET_YES == 941 GNUNET_assert (GNUNET_YES ==
934 GNUNET_CONTAINER_multipeermap_put(p2asd, 942 GNUNET_CONTAINER_multipeermap_put (p2asd,
935 peer, 943 peer,
936 asd, 944 asd,
937 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 945 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
938 } 946 }
939 if ((0 == ntohl(bandwidth_out.value__)) && 947 if ((0 == ntohl (bandwidth_out.value__)) &&
940 (0 == ntohl(bandwidth_in.value__))) 948 (0 == ntohl (bandwidth_in.value__)))
941 asd->active = GNUNET_NO; 949 asd->active = GNUNET_NO;
942 else 950 else
943 asd->active = GNUNET_YES; 951 asd->active = GNUNET_YES;
944 asd->bandwidth_out = bandwidth_out; 952 asd->bandwidth_out = bandwidth_out;
945 asd->bandwidth_in = bandwidth_in; 953 asd->bandwidth_in = bandwidth_in;
946 asd->session = session; 954 asd->session = session;
947 GNUNET_free_non_null(asd->address); 955 GNUNET_free_non_null (asd->address);
948 asd->address = NULL; 956 asd->address = NULL;
949 if (NULL != address) 957 if (NULL != address)
950 asd->address = GNUNET_HELLO_address_copy(address); 958 asd->address = GNUNET_HELLO_address_copy (address);
951 if (NULL == interpreter_task) 959 if (NULL == interpreter_task)
952 run_interpreter(); 960 run_interpreter ();
953} 961}
954 962
955 963
@@ -967,44 +975,44 @@ address_suggest_cb(void *cls,
967 * @param prop performance data for the address 975 * @param prop performance data for the address
968 */ 976 */
969static void 977static void
970address_information_cb(void *cls, 978address_information_cb (void *cls,
971 const struct GNUNET_HELLO_Address *address, 979 const struct GNUNET_HELLO_Address *address,
972 int address_active, 980 int address_active,
973 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 981 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
974 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 982 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
975 const struct GNUNET_ATS_Properties *prop) 983 const struct GNUNET_ATS_Properties *prop)
976{ 984{
977 const char *aic_cls = cls; 985 const char *aic_cls = cls;
978 struct AddressInformationData *aid; 986 struct AddressInformationData *aid;
979 987
980 GNUNET_break(0 == strcmp(aic_cls, "aic-closure")); 988 GNUNET_break (0 == strcmp (aic_cls, "aic-closure"));
981 if (NULL == address) 989 if (NULL == address)
982 { 990 {
983 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 991 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
984 "Connection to ATS died, likely a crash!\n"); 992 "Connection to ATS died, likely a crash!\n");
985 GNUNET_CONTAINER_multipeermap_iterate(p2aid, 993 GNUNET_CONTAINER_multipeermap_iterate (p2aid,
986 &free_aid, 994 &free_aid,
987 NULL); 995 NULL);
988 return; 996 return;
989 } 997 }
990 998
991 aid = find_address_information(address); 999 aid = find_address_information (address);
992 if (NULL == aid) 1000 if (NULL == aid)
993 { 1001 {
994 aid = GNUNET_new(struct AddressInformationData); 1002 aid = GNUNET_new (struct AddressInformationData);
995 aid->address = GNUNET_HELLO_address_copy(address); 1003 aid->address = GNUNET_HELLO_address_copy (address);
996 GNUNET_assert(GNUNET_YES == 1004 GNUNET_assert (GNUNET_YES ==
997 GNUNET_CONTAINER_multipeermap_put(p2aid, 1005 GNUNET_CONTAINER_multipeermap_put (p2aid,
998 &address->peer, 1006 &address->peer,
999 aid, 1007 aid,
1000 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1008 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1001 } 1009 }
1002 aid->active = address_active; 1010 aid->active = address_active;
1003 aid->bandwidth_out = bandwidth_out; 1011 aid->bandwidth_out = bandwidth_out;
1004 aid->bandwidth_in = bandwidth_in; 1012 aid->bandwidth_in = bandwidth_in;
1005 aid->properties = *prop; 1013 aid->properties = *prop;
1006 if (NULL == interpreter_task) 1014 if (NULL == interpreter_task)
1007 run_interpreter(); 1015 run_interpreter ();
1008} 1016}
1009 1017
1010 1018
@@ -1016,44 +1024,44 @@ address_information_cb(void *cls,
1016 * @param peer handle to the peer 1024 * @param peer handle to the peer
1017 */ 1025 */
1018static void 1026static void
1019run(void *cls, 1027run (void *cls,
1020 const struct GNUNET_CONFIGURATION_Handle *cfg, 1028 const struct GNUNET_CONFIGURATION_Handle *cfg,
1021 struct GNUNET_TESTING_Peer *peer) 1029 struct GNUNET_TESTING_Peer *peer)
1022{ 1030{
1023 p2asd = GNUNET_CONTAINER_multipeermap_create(128, 1031 p2asd = GNUNET_CONTAINER_multipeermap_create (128,
1024 GNUNET_NO); 1032 GNUNET_NO);
1025 p2aid = GNUNET_CONTAINER_multipeermap_create(128, 1033 p2aid = GNUNET_CONTAINER_multipeermap_create (128,
1026 GNUNET_NO); 1034 GNUNET_NO);
1027 GNUNET_SCHEDULER_add_delayed(TIMEOUT, 1035 GNUNET_SCHEDULER_add_delayed (TIMEOUT,
1028 &end, 1036 &end,
1029 NULL); 1037 NULL);
1030 1038
1031 sched_ats = GNUNET_ATS_scheduling_init(cfg, 1039 sched_ats = GNUNET_ATS_scheduling_init (cfg,
1032 &address_suggest_cb, 1040 &address_suggest_cb,
1033 "asc-closure"); 1041 "asc-closure");
1034 if (NULL == sched_ats) 1042 if (NULL == sched_ats)
1035 { 1043 {
1036 GNUNET_break(0); 1044 GNUNET_break (0);
1037 GNUNET_SCHEDULER_shutdown(); 1045 GNUNET_SCHEDULER_shutdown ();
1038 return; 1046 return;
1039 } 1047 }
1040 con_ats = GNUNET_ATS_connectivity_init(cfg); 1048 con_ats = GNUNET_ATS_connectivity_init (cfg);
1041 if (NULL == con_ats) 1049 if (NULL == con_ats)
1042 { 1050 {
1043 GNUNET_break(0); 1051 GNUNET_break (0);
1044 GNUNET_SCHEDULER_shutdown(); 1052 GNUNET_SCHEDULER_shutdown ();
1045 return; 1053 return;
1046 } 1054 }
1047 perf_ats = GNUNET_ATS_performance_init(cfg, 1055 perf_ats = GNUNET_ATS_performance_init (cfg,
1048 &address_information_cb, 1056 &address_information_cb,
1049 "aic-closure"); 1057 "aic-closure");
1050 if (NULL == perf_ats) 1058 if (NULL == perf_ats)
1051 { 1059 {
1052 GNUNET_break(0); 1060 GNUNET_break (0);
1053 GNUNET_SCHEDULER_shutdown(); 1061 GNUNET_SCHEDULER_shutdown ();
1054 return; 1062 return;
1055 } 1063 }
1056 run_interpreter(); 1064 run_interpreter ();
1057} 1065}
1058 1066
1059 1067
@@ -1067,32 +1075,32 @@ run(void *cls,
1067 * @return 0 on success 1075 * @return 0 on success
1068 */ 1076 */
1069int 1077int
1070TEST_ATS_run(int argc, 1078TEST_ATS_run (int argc,
1071 char *argv[], 1079 char *argv[],
1072 struct Command *cmds, 1080 struct Command *cmds,
1073 struct GNUNET_TIME_Relative timeout) 1081 struct GNUNET_TIME_Relative timeout)
1074{ 1082{
1075 char *test_filename = GNUNET_strdup(argv[0]); 1083 char *test_filename = GNUNET_strdup (argv[0]);
1076 char *sep; 1084 char *sep;
1077 char *config_file; 1085 char *config_file;
1078 char *underscore; 1086 char *underscore;
1079 1087
1080 test_commands = cmds; 1088 test_commands = cmds;
1081 TIMEOUT = timeout; 1089 TIMEOUT = timeout;
1082 if (NULL != (sep = strstr(test_filename, ".exe"))) 1090 if (NULL != (sep = strstr (test_filename, ".exe")))
1083 sep[0] = '\0'; 1091 sep[0] = '\0';
1084 underscore = strrchr(test_filename, (int)'_'); 1092 underscore = strrchr (test_filename, (int) '_');
1085 GNUNET_assert(NULL != underscore); 1093 GNUNET_assert (NULL != underscore);
1086 GNUNET_asprintf(&config_file, 1094 GNUNET_asprintf (&config_file,
1087 "test_ats_api_%s.conf", 1095 "test_ats_api_%s.conf",
1088 underscore + 1); 1096 underscore + 1);
1089 ret = 2; 1097 ret = 2;
1090 if (0 != GNUNET_TESTING_peer_run("test-ats-api", 1098 if (0 != GNUNET_TESTING_peer_run ("test-ats-api",
1091 config_file, 1099 config_file,
1092 &run, NULL)) 1100 &run, NULL))
1093 ret = 1; 1101 ret = 1;
1094 GNUNET_free(test_filename); 1102 GNUNET_free (test_filename);
1095 GNUNET_free(config_file); 1103 GNUNET_free (config_file);
1096 return ret; 1104 return ret;
1097} 1105}
1098 1106
diff --git a/src/ats/test_ats_lib.h b/src/ats/test_ats_lib.h
index db083d2d7..60b459f79 100644
--- a/src/ats/test_ats_lib.h
+++ b/src/ats/test_ats_lib.h
@@ -33,7 +33,8 @@
33/** 33/**
34 * Commands for the interpreter. 34 * Commands for the interpreter.
35 */ 35 */
36enum CommandCode { 36enum CommandCode
37{
37 /** 38 /**
38 * End the test (passing). 39 * End the test (passing).
39 */ 40 */
@@ -128,7 +129,8 @@ enum CommandCode {
128/** 129/**
129 * Details for the #CMD_ADD_ADDRESS command. 130 * Details for the #CMD_ADD_ADDRESS command.
130 */ 131 */
131struct CommandAddAddress { 132struct CommandAddAddress
133{
132 /** 134 /**
133 * Number of the peer (used to generate PID). 135 * Number of the peer (used to generate PID).
134 */ 136 */
@@ -169,7 +171,8 @@ struct CommandAddAddress {
169/** 171/**
170 * Details for the #CMD_DEL_ADDRESS command. 172 * Details for the #CMD_DEL_ADDRESS command.
171 */ 173 */
172struct CommandDelAddress { 174struct CommandDelAddress
175{
173 /** 176 /**
174 * Label of the corresponding #CMD_ADD_ADDRESS that 177 * Label of the corresponding #CMD_ADD_ADDRESS that
175 * we are now to remove. 178 * we are now to remove.
@@ -181,7 +184,8 @@ struct CommandDelAddress {
181/** 184/**
182 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command. 185 * Details for the #CMD_AWAIT_ADDRESS_SUGGESTION command.
183 */ 186 */
184struct CommandAwaitAddressSuggestion { 187struct CommandAwaitAddressSuggestion
188{
185 /** 189 /**
186 * For which peer do we expect a suggestion? 190 * For which peer do we expect a suggestion?
187 */ 191 */
@@ -199,7 +203,8 @@ struct CommandAwaitAddressSuggestion {
199/** 203/**
200 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command. 204 * Details for the #CMD_AWAIT_DISCONNECT_SUGGESTION command.
201 */ 205 */
202struct CommandAwaitDisconnectSuggestion { 206struct CommandAwaitDisconnectSuggestion
207{
203 /** 208 /**
204 * For which peer do we expect the disconnect? 209 * For which peer do we expect the disconnect?
205 */ 210 */
@@ -210,7 +215,8 @@ struct CommandAwaitDisconnectSuggestion {
210/** 215/**
211 * Details for the #CMD_REQUEST_CONNECTION_START command. 216 * Details for the #CMD_REQUEST_CONNECTION_START command.
212 */ 217 */
213struct CommandRequestConnectionStart { 218struct CommandRequestConnectionStart
219{
214 /** 220 /**
215 * Identity of the peer we would like to connect to. 221 * Identity of the peer we would like to connect to.
216 */ 222 */
@@ -227,7 +233,8 @@ struct CommandRequestConnectionStart {
227/** 233/**
228 * Details for the #CMD_REQUEST_CONNECTION_STOP command. 234 * Details for the #CMD_REQUEST_CONNECTION_STOP command.
229 */ 235 */
230struct CommandRequestConnectionStop { 236struct CommandRequestConnectionStop
237{
231 /** 238 /**
232 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that 239 * Label of the corresponding #CMD_REQUEST_CONNECTION_START that
233 * we are now stopping. 240 * we are now stopping.
@@ -239,7 +246,8 @@ struct CommandRequestConnectionStop {
239/** 246/**
240 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command. 247 * Details for the #CMD_AWAIT_ADDRESS_INFORMATION command.
241 */ 248 */
242struct CommandAwaitAddressInformation { 249struct CommandAwaitAddressInformation
250{
243 /** 251 /**
244 * For which address do we expect information? 252 * For which address do we expect information?
245 * The address is identified by the respective 253 * The address is identified by the respective
@@ -259,7 +267,8 @@ struct CommandAwaitAddressInformation {
259/** 267/**
260 * Details for the #CMD_UPDATE_ADDRESS command. 268 * Details for the #CMD_UPDATE_ADDRESS command.
261 */ 269 */
262struct CommandUpdateAddress { 270struct CommandUpdateAddress
271{
263 /** 272 /**
264 * Label of the addresses's add operation. 273 * Label of the addresses's add operation.
265 */ 274 */
@@ -275,7 +284,8 @@ struct CommandUpdateAddress {
275/** 284/**
276 * Details for the #CMD_ADD_SESSION command. 285 * Details for the #CMD_ADD_SESSION command.
277 */ 286 */
278struct CommandAddSession { 287struct CommandAddSession
288{
279 /** 289 /**
280 * Label of the addresses's add operation. 290 * Label of the addresses's add operation.
281 */ 291 */
@@ -291,7 +301,8 @@ struct CommandAddSession {
291/** 301/**
292 * Details for the #CMD_DEL_SESSION command. 302 * Details for the #CMD_DEL_SESSION command.
293 */ 303 */
294struct CommandDelSession { 304struct CommandDelSession
305{
295 /** 306 /**
296 * Label of the addresses's add operation. 307 * Label of the addresses's add operation.
297 */ 308 */
@@ -302,7 +313,8 @@ struct CommandDelSession {
302/** 313/**
303 * Details for the #CMD_CHANGE_PREFERENCE command. 314 * Details for the #CMD_CHANGE_PREFERENCE command.
304 */ 315 */
305struct CommandChangePreference { 316struct CommandChangePreference
317{
306 /** 318 /**
307 * Identity of the peer we have a preference change towards. 319 * Identity of the peer we have a preference change towards.
308 */ 320 */
@@ -315,7 +327,8 @@ struct CommandChangePreference {
315/** 327/**
316 * Details for the #CMD_PROVIDE_FEEDBACK command. 328 * Details for the #CMD_PROVIDE_FEEDBACK command.
317 */ 329 */
318struct CommandProvideFeedback { 330struct CommandProvideFeedback
331{
319 /** 332 /**
320 * Identity of the peer we have a feedback for. 333 * Identity of the peer we have a feedback for.
321 */ 334 */
@@ -333,7 +346,8 @@ struct CommandProvideFeedback {
333/** 346/**
334 * Details for the #CMD_LIST_ADDRESSES command. 347 * Details for the #CMD_LIST_ADDRESSES command.
335 */ 348 */
336struct CommandListAddresses { 349struct CommandListAddresses
350{
337 /** 351 /**
338 * Identity of the peer we want a list for. 352 * Identity of the peer we want a list for.
339 */ 353 */
@@ -387,7 +401,8 @@ struct CommandListAddresses {
387/** 401/**
388 * Details for the #CMD_RESERVE_BANDWIDTH command. 402 * Details for the #CMD_RESERVE_BANDWIDTH command.
389 */ 403 */
390struct CommandReserveBandwidth { 404struct CommandReserveBandwidth
405{
391 /** 406 /**
392 * For which peer do we reserve bandwidth? 407 * For which peer do we reserve bandwidth?
393 */ 408 */
@@ -417,7 +432,8 @@ struct CommandReserveBandwidth {
417/** 432/**
418 * Details for the #CMD_SLEEP command. 433 * Details for the #CMD_SLEEP command.
419 */ 434 */
420struct CommandSleep { 435struct CommandSleep
436{
421 /** 437 /**
422 * How long should we wait before running the next command? 438 * How long should we wait before running the next command?
423 */ 439 */
@@ -428,7 +444,8 @@ struct CommandSleep {
428/** 444/**
429 * A command for the test case interpreter. 445 * A command for the test case interpreter.
430 */ 446 */
431struct Command { 447struct Command
448{
432 /** 449 /**
433 * Command code to run. 450 * Command code to run.
434 */ 451 */
@@ -442,7 +459,8 @@ struct Command {
442 /** 459 /**
443 * Additional arguments to commands, if any. 460 * Additional arguments to commands, if any.
444 */ 461 */
445 union { 462 union
463 {
446 struct CommandAddAddress add_address; 464 struct CommandAddAddress add_address;
447 465
448 struct CommandDelAddress del_address; 466 struct CommandDelAddress del_address;
@@ -486,9 +504,9 @@ struct Command {
486 * @return 0 on success 504 * @return 0 on success
487 */ 505 */
488int 506int
489TEST_ATS_run(int argc, 507TEST_ATS_run (int argc,
490 char *argv[], 508 char *argv[],
491 struct Command *cmds, 509 struct Command *cmds,
492 struct GNUNET_TIME_Relative timeout); 510 struct GNUNET_TIME_Relative timeout);
493 511
494#endif 512#endif
diff --git a/src/ats/test_ats_reservation_api.c b/src/ats/test_ats_reservation_api.c
index f6b0573e1..ff924b3b4 100644
--- a/src/ats/test_ats_reservation_api.c
+++ b/src/ats/test_ats_reservation_api.c
@@ -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
148int 148int
149main(int argc, 149main (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