aboutsummaryrefslogtreecommitdiff
path: root/src/ats/ats_api_performance.c
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/ats_api_performance.c
parentfbb71d527c7d6babf269a8fefce1db291b9f7068 (diff)
downloadgnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz
gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/ats/ats_api_performance.c')
-rw-r--r--src/ats/ats_api_performance.c737
1 files changed, 374 insertions, 363 deletions
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 */