aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/ats
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats_api.c103
1 files changed, 41 insertions, 62 deletions
diff --git a/src/ats/ats_api.c b/src/ats/ats_api.c
index 6cd8a82ba..ca0954173 100644
--- a/src/ats/ats_api.c
+++ b/src/ats/ats_api.c
@@ -216,18 +216,16 @@ set_bw_connections (void *cls, const GNUNET_HashCode * key, void *value)
216 ar->bandwidth = sbc->bw; 216 ar->bandwidth = sbc->bw;
217 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 217 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
218 (const struct GNUNET_PeerIdentity *) key, 218 (const struct GNUNET_PeerIdentity *) key,
219 ar->plugin_name, 219 ar->plugin_name, ar->session, ar->plugin_addr,
220 ar->session, 220 ar->plugin_addr_len, ar->bandwidth);
221 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
222 } 221 }
223 else if (ntohl (ar->bandwidth.value__) > 0) 222 else if (ntohl (ar->bandwidth.value__) > 0)
224 { 223 {
225 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0); 224 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
226 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls, 225 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
227 (const struct GNUNET_PeerIdentity *) key, 226 (const struct GNUNET_PeerIdentity *) key,
228 ar->plugin_name, 227 ar->plugin_name, ar->session, ar->plugin_addr,
229 ar->session, 228 ar->plugin_addr_len, ar->bandwidth);
230 ar->plugin_addr, ar->plugin_addr_len, ar->bandwidth);
231 } 229 }
232 return GNUNET_YES; 230 return GNUNET_YES;
233} 231}
@@ -286,13 +284,10 @@ suggest_address (void *cls, const GNUNET_HashCode * key, void *value)
286 struct AllocationRecord *ar = value; 284 struct AllocationRecord *ar = value;
287 285
288 /* trivial strategy: pick first available address... */ 286 /* trivial strategy: pick first available address... */
289 asc->cb (asc->cb_cls, 287 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
290 &asc->target,
291 ar->plugin_name,
292 ar->plugin_addr,
293 ar->plugin_addr_len, 288 ar->plugin_addr_len,
294 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 289 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
295 ar->ats, ar->ats_count); 290 ar->ats_count);
296 asc->cb = NULL; 291 asc->cb = NULL;
297 return GNUNET_NO; 292 return GNUNET_NO;
298} 293}
@@ -320,17 +315,14 @@ GNUNET_ATS_suggest_address (struct GNUNET_ATS_Handle *atc,
320 asc->cb_cls = cb_cls; 315 asc->cb_cls = cb_cls;
321 asc->atc = atc; 316 asc->atc = atc;
322 asc->target = *peer; 317 asc->target = *peer;
323 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, 318 GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers, &peer->hashPubKey,
324 &peer->hashPubKey,
325 &suggest_address, asc); 319 &suggest_address, asc);
326 if (NULL == asc->cb) 320 if (NULL == asc->cb)
327 { 321 {
328 GNUNET_free (asc); 322 GNUNET_free (asc);
329 return NULL; 323 return NULL;
330 } 324 }
331 GNUNET_CONTAINER_multihashmap_put (atc->notify_map, 325 GNUNET_CONTAINER_multihashmap_put (atc->notify_map, &peer->hashPubKey, asc,
332 &peer->hashPubKey,
333 asc,
334 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 326 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
335 return asc; 327 return asc;
336} 328}
@@ -372,9 +364,8 @@ GNUNET_ATS_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
372 atc->alloc_cb = alloc_cb; 364 atc->alloc_cb = alloc_cb;
373 atc->alloc_cb_cls = alloc_cb_cls; 365 atc->alloc_cb_cls = alloc_cb_cls;
374 atc->peers = GNUNET_CONTAINER_multihashmap_create (256); 366 atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
375 GNUNET_CONFIGURATION_get_value_number (cfg, 367 GNUNET_CONFIGURATION_get_value_number (cfg, "core", "TOTAL_QUOTA_OUT",
376 "core", 368 &atc->total_bps);
377 "TOTAL_QUOTA_OUT", &atc->total_bps);
378 return atc; 369 return atc;
379} 370}
380 371
@@ -412,8 +403,8 @@ GNUNET_ATS_shutdown (struct GNUNET_ATS_Handle *atc)
412 GNUNET_SCHEDULER_cancel (atc->ba_task); 403 GNUNET_SCHEDULER_cancel (atc->ba_task);
413 atc->ba_task = GNUNET_SCHEDULER_NO_TASK; 404 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
414 } 405 }
415 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 406 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_allocation_record,
416 &destroy_allocation_record, NULL); 407 NULL);
417 GNUNET_CONTAINER_multihashmap_destroy (atc->peers); 408 GNUNET_CONTAINER_multihashmap_destroy (atc->peers);
418 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0); 409 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (atc->notify_map) == 0);
419 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map); 410 GNUNET_CONTAINER_multihashmap_destroy (atc->notify_map);
@@ -461,8 +452,9 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
461 if ((arnew->session == arold->session) || 452 if ((arnew->session == arold->session) ||
462 ((arold->session == NULL) && 453 ((arold->session == NULL) &&
463 (arold->plugin_addr_len == arnew->plugin_addr_len) && 454 (arold->plugin_addr_len == arnew->plugin_addr_len) &&
464 (0 == memcmp (arold->plugin_addr, 455 (0 ==
465 arnew->plugin_addr, arnew->plugin_addr_len)))) 456 memcmp (arold->plugin_addr, arnew->plugin_addr,
457 arnew->plugin_addr_len))))
466 { 458 {
467 change = GNUNET_NO; 459 change = GNUNET_NO;
468 /* records match */ 460 /* records match */
@@ -497,10 +489,8 @@ update_session (void *cls, const GNUNET_HashCode * key, void *value)
497 * @param ats_count number of performance records in 'ats' 489 * @param ats_count number of performance records in 'ats'
498 */ 490 */
499static struct AllocationRecord * 491static struct AllocationRecord *
500create_allocation_record (const char *plugin_name, 492create_allocation_record (const char *plugin_name, struct Session *session,
501 struct Session *session, 493 const void *plugin_addr, size_t plugin_addr_len,
502 const void *plugin_addr,
503 size_t plugin_addr_len,
504 const struct GNUNET_TRANSPORT_ATS_Information *ats, 494 const struct GNUNET_TRANSPORT_ATS_Information *ats,
505 uint32_t ats_count) 495 uint32_t ats_count)
506{ 496{
@@ -513,8 +503,8 @@ create_allocation_record (const char *plugin_name,
513 ar->session = session; 503 ar->session = session;
514 ar->plugin_addr_len = plugin_addr_len; 504 ar->plugin_addr_len = plugin_addr_len;
515 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count); 505 GNUNET_array_grow (ar->ats, ar->ats_count, ats_count);
516 memcpy (ar->ats, 506 memcpy (ar->ats, ats,
517 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 507 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
518 return ar; 508 return ar;
519} 509}
520 510
@@ -559,21 +549,18 @@ disconnect_peer (void *cls, const GNUNET_HashCode * key, void *value)
559void 549void
560GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc, 550GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
561 const struct GNUNET_PeerIdentity *peer, 551 const struct GNUNET_PeerIdentity *peer,
562 const char *plugin_name, 552 const char *plugin_name, struct Session *session,
563 struct Session *session, 553 const void *plugin_addr, size_t plugin_addr_len,
564 const void *plugin_addr,
565 size_t plugin_addr_len,
566 const struct GNUNET_TRANSPORT_ATS_Information *ats, 554 const struct GNUNET_TRANSPORT_ATS_Information *ats,
567 uint32_t ats_count) 555 uint32_t ats_count)
568{ 556{
569 struct AllocationRecord *ar; 557 struct AllocationRecord *ar;
570 struct UpdateSessionContext usc; 558 struct UpdateSessionContext usc;
571 559
572 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 560 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &disconnect_peer,
573 &disconnect_peer, atc); 561 atc);
574 ar = create_allocation_record (plugin_name, 562 ar = create_allocation_record (plugin_name, session, plugin_addr,
575 session, 563 plugin_addr_len, ats, ats_count);
576 plugin_addr, plugin_addr_len, ats, ats_count);
577 ar->connected = GNUNET_YES; 564 ar->connected = GNUNET_YES;
578 usc.atc = atc; 565 usc.atc = atc;
579 usc.arnew = ar; 566 usc.arnew = ar;
@@ -585,8 +572,7 @@ GNUNET_ATS_peer_connect (struct GNUNET_ATS_Handle *atc,
585 } 572 }
586 GNUNET_assert (GNUNET_OK == 573 GNUNET_assert (GNUNET_OK ==
587 GNUNET_CONTAINER_multihashmap_put (atc->peers, 574 GNUNET_CONTAINER_multihashmap_put (atc->peers,
588 &peer->hashPubKey, 575 &peer->hashPubKey, ar,
589 ar,
590 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 576 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
591} 577}
592 578
@@ -646,8 +632,8 @@ destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
646 if (ar->plugin_addr != NULL) 632 if (ar->plugin_addr != NULL)
647 return GNUNET_OK; 633 return GNUNET_OK;
648 GNUNET_assert (GNUNET_OK == 634 GNUNET_assert (GNUNET_OK ==
649 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, 635 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, key,
650 key, ar)); 636 ar));
651 if (GNUNET_YES == ar->connected) ; 637 if (GNUNET_YES == ar->connected) ;
652 { 638 {
653 /* FIXME: is this supposed to be allowed? What to do then? */ 639 /* FIXME: is this supposed to be allowed? What to do then? */
@@ -674,8 +660,8 @@ GNUNET_ATS_session_destroyed (struct GNUNET_ATS_Handle *atc,
674 660
675 sdc.atc = atc; 661 sdc.atc = atc;
676 sdc.session = session; 662 sdc.session = session;
677 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 663 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, &destroy_session,
678 &destroy_session, &sdc); 664 &sdc);
679} 665}
680 666
681 667
@@ -693,13 +679,10 @@ notify_valid (void *cls, const GNUNET_HashCode * key, void *value)
693 struct AllocationRecord *ar = cls; 679 struct AllocationRecord *ar = cls;
694 struct GNUNET_ATS_SuggestionContext *asc = value; 680 struct GNUNET_ATS_SuggestionContext *asc = value;
695 681
696 asc->cb (asc->cb_cls, 682 asc->cb (asc->cb_cls, &asc->target, ar->plugin_name, ar->plugin_addr,
697 &asc->target,
698 ar->plugin_name,
699 ar->plugin_addr,
700 ar->plugin_addr_len, 683 ar->plugin_addr_len,
701 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), 684 GNUNET_BANDWIDTH_value_init (asc->atc->total_bps / 32), ar->ats,
702 ar->ats, ar->ats_count); 685 ar->ats_count);
703 GNUNET_ATS_suggest_address_cancel (asc); 686 GNUNET_ATS_suggest_address_cancel (asc);
704 return GNUNET_OK; 687 return GNUNET_OK;
705} 688}
@@ -727,19 +710,16 @@ void
727GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc, 710GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
728 const struct GNUNET_PeerIdentity *peer, 711 const struct GNUNET_PeerIdentity *peer,
729 struct GNUNET_TIME_Absolute valid_until, 712 struct GNUNET_TIME_Absolute valid_until,
730 const char *plugin_name, 713 const char *plugin_name, struct Session *session,
731 struct Session *session, 714 const void *plugin_addr, size_t plugin_addr_len,
732 const void *plugin_addr,
733 size_t plugin_addr_len,
734 const struct GNUNET_TRANSPORT_ATS_Information *ats, 715 const struct GNUNET_TRANSPORT_ATS_Information *ats,
735 uint32_t ats_count) 716 uint32_t ats_count)
736{ 717{
737 struct AllocationRecord *ar; 718 struct AllocationRecord *ar;
738 struct UpdateSessionContext usc; 719 struct UpdateSessionContext usc;
739 720
740 ar = create_allocation_record (plugin_name, 721 ar = create_allocation_record (plugin_name, session, plugin_addr,
741 session, 722 plugin_addr_len, ats, ats_count);
742 plugin_addr, plugin_addr_len, ats, ats_count);
743 usc.atc = atc; 723 usc.atc = atc;
744 usc.arnew = ar; 724 usc.arnew = ar;
745 if (GNUNET_SYSERR == 725 if (GNUNET_SYSERR ==
@@ -750,12 +730,11 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_Handle *atc,
750 } 730 }
751 GNUNET_assert (GNUNET_OK == 731 GNUNET_assert (GNUNET_OK ==
752 GNUNET_CONTAINER_multihashmap_put (atc->peers, 732 GNUNET_CONTAINER_multihashmap_put (atc->peers,
753 &peer->hashPubKey, 733 &peer->hashPubKey, ar,
754 ar,
755 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 734 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
756 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map, 735 GNUNET_CONTAINER_multihashmap_get_multiple (atc->notify_map,
757 &peer->hashPubKey, 736 &peer->hashPubKey, &notify_valid,
758 &notify_valid, ar); 737 ar);
759} 738}
760 739
761/* end of file gnunet-service-transport_ats.c */ 740/* end of file gnunet-service-transport_ats.c */