diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/ats/ats_api2_transport.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/ats/ats_api2_transport.c')
-rw-r--r-- | src/ats/ats_api2_transport.c | 437 |
1 files changed, 220 insertions, 217 deletions
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 | */ |
38 | struct GNUNET_ATS_SessionRecord { | 38 | struct 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 | */ |
82 | struct GNUNET_ATS_TransportHandle { | 83 | struct 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 | */ |
137 | static void | 139 | static void |
138 | properties_hton(struct PropertiesNBO *nbo, | 140 | properties_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 | */ |
158 | static void | 160 | static void |
159 | reconnect(struct GNUNET_ATS_TransportHandle *ath); | 161 | reconnect (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 | */ |
167 | static void | 169 | static void |
168 | reconnect_task(void *cls) | 170 | reconnect_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 | */ |
182 | static void | 184 | static void |
183 | force_reconnect(struct GNUNET_ATS_TransportHandle *ath) | 185 | force_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 | */ |
208 | static int | 210 | static int |
209 | check_ats_address_suggestion(void *cls, | 211 | check_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 | */ |
224 | static void | 226 | static void |
225 | handle_ats_address_suggestion(void *cls, | 227 | handle_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 | */ |
240 | struct FindContext { | 242 | struct 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 | */ |
261 | static int | 264 | static int |
262 | match_session_cb(void *cls, | 265 | match_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 | */ |
288 | static struct GNUNET_ATS_SessionRecord * | 291 | static struct GNUNET_ATS_SessionRecord * |
289 | find_session(struct GNUNET_ATS_TransportHandle *ath, | 292 | find_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 | */ |
312 | static void | 315 | static void |
313 | handle_ats_session_allocation(void *cls, | 316 | handle_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 | */ |
351 | static void | 354 | static void |
352 | error_handler(void *cls, | 355 | error_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 | */ |
370 | static void | 373 | static void |
371 | send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar) | 374 | send_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 | */ |
411 | static int | 414 | static int |
412 | send_add_session_cb(void *cls, | 415 | send_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 | */ |
430 | static void | 433 | static void |
431 | reconnect(struct GNUNET_ATS_TransportHandle *ath) | 434 | reconnect (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 | */ |
481 | struct GNUNET_ATS_TransportHandle * | 484 | struct GNUNET_ATS_TransportHandle * |
482 | GNUNET_ATS_transport_init(const struct GNUNET_CONFIGURATION_Handle *cfg, | 485 | GNUNET_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 | */ |
511 | static int | 514 | static int |
512 | free_record(void *cls, | 515 | free_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 | */ |
530 | void | 533 | void |
531 | GNUNET_ATS_transport_done(struct GNUNET_ATS_TransportHandle *ath) | 534 | GNUNET_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 | */ |
565 | struct GNUNET_ATS_SessionRecord * | 568 | struct GNUNET_ATS_SessionRecord * |
566 | GNUNET_ATS_session_add(struct GNUNET_ATS_TransportHandle *ath, | 569 | GNUNET_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 | */ |
631 | void | 634 | void |
632 | GNUNET_ATS_session_update(struct GNUNET_ATS_SessionRecord *ar, | 635 | GNUNET_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 | */ |
664 | void | 667 | void |
665 | GNUNET_ATS_session_del(struct GNUNET_ATS_SessionRecord *ar) | 668 | GNUNET_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 | ||