diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-04 23:08:19 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-04 23:08:19 +0200 |
commit | 0a01368474f54f563aa8168bb4d0a6356a66c104 (patch) | |
tree | 4618513fb3943380a0838ded7d90f2ca169a15cc /src/ats | |
parent | c2ccd9da323ca84aceb1a3356d6d59b9c7d8e4ad (diff) | |
download | gnunet-0a01368474f54f563aa8168bb4d0a6356a66c104.tar.gz gnunet-0a01368474f54f563aa8168bb4d0a6356a66c104.zip |
fix missing API migration
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/plugin_ats2_simple.c | 334 |
1 files changed, 135 insertions, 199 deletions
diff --git a/src/ats/plugin_ats2_simple.c b/src/ats/plugin_ats2_simple.c index 35a256f32..7d5aebdfa 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 | /** |
@@ -116,7 +116,6 @@ struct Hello | |||
116 | * Type of the network for this HELLO. | 116 | * Type of the network for this HELLO. |
117 | */ | 117 | */ |
118 | enum GNUNET_NetworkType nt; | 118 | enum GNUNET_NetworkType nt; |
119 | |||
120 | }; | 119 | }; |
121 | 120 | ||
122 | 121 | ||
@@ -187,7 +186,6 @@ struct GNUNET_ATS_SessionHandle | |||
187 | * New BW-out allocation given to the transport service. | 186 | * New BW-out allocation given to the transport service. |
188 | */ | 187 | */ |
189 | uint64_t target_out; | 188 | uint64_t target_out; |
190 | |||
191 | }; | 189 | }; |
192 | 190 | ||
193 | 191 | ||
@@ -249,7 +247,6 @@ struct Peer | |||
249 | * by preference kind (see `enum GNUNET_MQ_PreferenceKind`) | 247 | * by preference kind (see `enum GNUNET_MQ_PreferenceKind`) |
250 | */ | 248 | */ |
251 | uint64_t bw_by_pk[GNUNET_MQ_PREFERENCE_COUNT]; | 249 | uint64_t bw_by_pk[GNUNET_MQ_PREFERENCE_COUNT]; |
252 | |||
253 | }; | 250 | }; |
254 | 251 | ||
255 | 252 | ||
@@ -273,7 +270,6 @@ struct Network | |||
273 | * ATS network type | 270 | * ATS network type |
274 | */ | 271 | */ |
275 | enum GNUNET_NetworkType type; | 272 | enum GNUNET_NetworkType type; |
276 | |||
277 | }; | 273 | }; |
278 | 274 | ||
279 | 275 | ||
@@ -309,7 +305,6 @@ struct SimpleHandle | |||
309 | * Information we track per network type (quotas). | 305 | * Information we track per network type (quotas). |
310 | */ | 306 | */ |
311 | struct Network networks[GNUNET_NT_COUNT]; | 307 | struct Network networks[GNUNET_NT_COUNT]; |
312 | |||
313 | }; | 308 | }; |
314 | 309 | ||
315 | 310 | ||
@@ -321,11 +316,9 @@ struct SimpleHandle | |||
321 | * @return NULL for not found | 316 | * @return NULL for not found |
322 | */ | 317 | */ |
323 | struct Peer * | 318 | struct Peer * |
324 | lookup_peer (struct SimpleHandle *h, | 319 | lookup_peer (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
325 | const struct GNUNET_PeerIdentity *pid) | ||
326 | { | 320 | { |
327 | return GNUNET_CONTAINER_multipeermap_get (h->peers, | 321 | return GNUNET_CONTAINER_multipeermap_get (h->peers, pid); |
328 | pid); | ||
329 | } | 322 | } |
330 | 323 | ||
331 | 324 | ||
@@ -339,8 +332,7 @@ lookup_peer (struct SimpleHandle *h, | |||
339 | static int | 332 | static int |
340 | peer_test_dead (struct Peer *p) | 333 | peer_test_dead (struct Peer *p) |
341 | { | 334 | { |
342 | for (enum GNUNET_MQ_PreferenceKind pk = 0; | 335 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
343 | pk < GNUNET_MQ_PREFERENCE_COUNT; | ||
344 | pk++) | 336 | pk++) |
345 | if (0 != p->bw_by_pk[pk]) | 337 | if (0 != p->bw_by_pk[pk]) |
346 | return GNUNET_NO; | 338 | return GNUNET_NO; |
@@ -363,14 +355,12 @@ suggest_hello (struct Hello *hello) | |||
363 | struct Peer *p = hello->peer; | 355 | struct Peer *p = hello->peer; |
364 | struct SimpleHandle *h = p->h; | 356 | struct SimpleHandle *h = p->h; |
365 | 357 | ||
366 | p->last_suggestion | 358 | p->last_suggestion = hello->last_attempt = GNUNET_TIME_absolute_get (); |
367 | = hello->last_attempt | 359 | hello->backoff = |
368 | = GNUNET_TIME_absolute_get (); | 360 | GNUNET_TIME_randomized_backoff (hello->backoff, |
369 | hello->backoff = GNUNET_TIME_randomized_backoff (hello->backoff, | 361 | GNUNET_TIME_absolute_get_remaining ( |
370 | GNUNET_TIME_absolute_get_remaining (hello->expiration)); | 362 | hello->expiration)); |
371 | h->env->suggest_cb (h->env->cls, | 363 | h->env->suggest_cb (h->env->cls, &p->pid, hello->address); |
372 | &p->pid, | ||
373 | hello->address); | ||
374 | } | 364 | } |
375 | 365 | ||
376 | 366 | ||
@@ -401,8 +391,7 @@ suggest_start_cb (void *cls) | |||
401 | uint32_t sq; | 391 | uint32_t sq; |
402 | 392 | ||
403 | /* count number of active sessions */ | 393 | /* count number of active sessions */ |
404 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; | 394 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; |
405 | NULL != sh; | ||
406 | sh = sh->next) | 395 | sh = sh->next) |
407 | num_sessions++; | 396 | num_sessions++; |
408 | /* calculate square of number of sessions */ | 397 | /* calculate square of number of sessions */ |
@@ -411,9 +400,10 @@ suggest_start_cb (void *cls) | |||
411 | sq = num_sessions * (uint32_t) num_sessions; | 400 | sq = num_sessions * (uint32_t) num_sessions; |
412 | else | 401 | else |
413 | sq = UINT32_MAX; | 402 | sq = UINT32_MAX; |
414 | xdelay = GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ, | 403 | xdelay = |
415 | sq), | 404 | GNUNET_TIME_randomized_backoff (GNUNET_TIME_relative_multiply (SUGGEST_FREQ, |
416 | GNUNET_TIME_UNIT_FOREVER_REL); | 405 | sq), |
406 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
417 | xnext = GNUNET_TIME_relative_to_absolute (xdelay); | 407 | xnext = GNUNET_TIME_relative_to_absolute (xdelay); |
418 | 408 | ||
419 | p->task = NULL; | 409 | p->task = NULL; |
@@ -438,19 +428,16 @@ suggest_start_cb (void *cls) | |||
438 | next = pos->next; | 428 | next = pos->next; |
439 | if (NULL != pos->sh) | 429 | if (NULL != pos->sh) |
440 | continue; | 430 | continue; |
441 | if (0 == GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us) | 431 | if (0 == |
432 | GNUNET_TIME_absolute_get_remaining (pos->expiration).rel_value_us) | ||
442 | { | 433 | { |
443 | /* expired, remove! */ | 434 | /* expired, remove! */ |
444 | GNUNET_CONTAINER_DLL_remove (p->h_head, | 435 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, pos); |
445 | p->h_tail, | ||
446 | pos); | ||
447 | GNUNET_free (pos); | 436 | GNUNET_free (pos); |
448 | continue; | 437 | continue; |
449 | } | 438 | } |
450 | pt = GNUNET_TIME_absolute_add (pos->last_attempt, | 439 | pt = GNUNET_TIME_absolute_add (pos->last_attempt, pos->backoff); |
451 | pos->backoff); | 440 | if ((NULL == hello) || (pt.abs_value_us < hpt.abs_value_us)) |
452 | if ( (NULL == hello) || | ||
453 | (pt.abs_value_us < hpt.abs_value_us) ) | ||
454 | { | 441 | { |
455 | hello = pos; | 442 | hello = pos; |
456 | hpt = pt; | 443 | hpt = pt; |
@@ -463,13 +450,10 @@ suggest_start_cb (void *cls) | |||
463 | but we might not want to go for as early as possible for | 450 | but we might not want to go for as early as possible for |
464 | this peer. So the actual time is the max of the earliest | 451 | this peer. So the actual time is the max of the earliest |
465 | HELLO and the 'xnext' */ | 452 | HELLO and the 'xnext' */ |
466 | xmax = GNUNET_TIME_absolute_max (hpt, | 453 | xmax = GNUNET_TIME_absolute_max (hpt, xnext); |
467 | xnext); | ||
468 | delay = GNUNET_TIME_absolute_get_remaining (xmax); | 454 | delay = GNUNET_TIME_absolute_get_remaining (xmax); |
469 | } | 455 | } |
470 | p->task = GNUNET_SCHEDULER_add_delayed (delay, | 456 | p->task = GNUNET_SCHEDULER_add_delayed (delay, &suggest_start_cb, p); |
471 | &suggest_start_cb, | ||
472 | p); | ||
473 | } | 457 | } |
474 | 458 | ||
475 | 459 | ||
@@ -492,14 +476,12 @@ watch_cb (void *cls, | |||
492 | struct GNUNET_TIME_Absolute expiration; | 476 | struct GNUNET_TIME_Absolute expiration; |
493 | struct Hello *hello; | 477 | struct Hello *hello; |
494 | 478 | ||
495 | if (0 != GNUNET_memcmp (&p->pid, | 479 | if (0 != GNUNET_memcmp (&p->pid, &record->peer)) |
496 | &record->peer)) | ||
497 | { | 480 | { |
498 | GNUNET_break (0); | 481 | GNUNET_break (0); |
499 | return; | 482 | return; |
500 | } | 483 | } |
501 | if (0 != strcmp (record->key, | 484 | if (0 != strcmp (record->key, GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) |
502 | GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY)) | ||
503 | { | 485 | { |
504 | GNUNET_break (0); | 486 | GNUNET_break (0); |
505 | return; | 487 | return; |
@@ -518,12 +500,9 @@ watch_cb (void *cls, | |||
518 | return; | 500 | return; |
519 | } | 501 | } |
520 | /* check if addr is already known */ | 502 | /* check if addr is already known */ |
521 | for (struct Hello *he = p->h_head; | 503 | for (struct Hello *he = p->h_head; NULL != he; he = he->next) |
522 | NULL != he; | ||
523 | he = he->next) | ||
524 | { | 504 | { |
525 | if (0 != strcmp (he->address, | 505 | if (0 != strcmp (he->address, addr)) |
526 | addr)) | ||
527 | continue; | 506 | continue; |
528 | if (he->expiration.abs_value_us < expiration.abs_value_us) | 507 | if (he->expiration.abs_value_us < expiration.abs_value_us) |
529 | { | 508 | { |
@@ -540,21 +519,14 @@ watch_cb (void *cls, | |||
540 | hello->expiration = expiration; | 519 | hello->expiration = expiration; |
541 | hello->nt = nt; | 520 | hello->nt = nt; |
542 | hello->peer = p; | 521 | hello->peer = p; |
543 | memcpy (&hello[1], | 522 | memcpy (&hello[1], addr, alen); |
544 | addr, | ||
545 | alen); | ||
546 | GNUNET_free (addr); | 523 | GNUNET_free (addr); |
547 | GNUNET_CONTAINER_DLL_insert (p->h_head, | 524 | GNUNET_CONTAINER_DLL_insert (p->h_head, p->h_tail, hello); |
548 | p->h_tail, | ||
549 | hello); | ||
550 | /* check if sh for this HELLO already exists */ | 525 | /* check if sh for this HELLO already exists */ |
551 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; | 526 | for (struct GNUNET_ATS_SessionHandle *sh = p->sh_head; NULL != sh; |
552 | NULL != sh; | ||
553 | sh = sh->next) | 527 | sh = sh->next) |
554 | { | 528 | { |
555 | if ( (NULL == sh->address) || | 529 | if ((NULL == sh->address) || (0 != strcmp (sh->address, addr))) |
556 | (0 != strcmp (sh->address, | ||
557 | addr)) ) | ||
558 | continue; | 530 | continue; |
559 | GNUNET_assert (NULL == sh->hello); | 531 | GNUNET_assert (NULL == sh->hello); |
560 | sh->hello = hello; | 532 | sh->hello = hello; |
@@ -562,8 +534,7 @@ watch_cb (void *cls, | |||
562 | break; | 534 | break; |
563 | } | 535 | } |
564 | if (NULL == p->task) | 536 | if (NULL == p->task) |
565 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, | 537 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); |
566 | p); | ||
567 | } | 538 | } |
568 | 539 | ||
569 | 540 | ||
@@ -575,11 +546,9 @@ watch_cb (void *cls, | |||
575 | * @return a peer handle | 546 | * @return a peer handle |
576 | */ | 547 | */ |
577 | static struct Peer * | 548 | static struct Peer * |
578 | peer_add (struct SimpleHandle *h, | 549 | peer_add (struct SimpleHandle *h, const struct GNUNET_PeerIdentity *pid) |
579 | const struct GNUNET_PeerIdentity *pid) | ||
580 | { | 550 | { |
581 | struct Peer *p = lookup_peer (h, | 551 | struct Peer *p = lookup_peer (h, pid); |
582 | pid); | ||
583 | 552 | ||
584 | if (NULL != p) | 553 | if (NULL != p) |
585 | return p; | 554 | return p; |
@@ -593,10 +562,11 @@ peer_add (struct SimpleHandle *h, | |||
593 | &watch_cb, | 562 | &watch_cb, |
594 | p); | 563 | p); |
595 | GNUNET_assert (GNUNET_YES == | 564 | GNUNET_assert (GNUNET_YES == |
596 | GNUNET_CONTAINER_multipeermap_put (h->peers, | 565 | GNUNET_CONTAINER_multipeermap_put ( |
597 | &p->pid, | 566 | h->peers, |
598 | p, | 567 | &p->pid, |
599 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 568 | p, |
569 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
600 | 570 | ||
601 | return p; | 571 | return p; |
602 | } | 572 | } |
@@ -617,9 +587,7 @@ peer_free (struct Peer *p) | |||
617 | GNUNET_assert (NULL == p->sh_head); | 587 | GNUNET_assert (NULL == p->sh_head); |
618 | while (NULL != (hello = p->h_head)) | 588 | while (NULL != (hello = p->h_head)) |
619 | { | 589 | { |
620 | GNUNET_CONTAINER_DLL_remove (p->h_head, | 590 | GNUNET_CONTAINER_DLL_remove (p->h_head, p->h_tail, hello); |
621 | p->h_tail, | ||
622 | hello); | ||
623 | GNUNET_assert (NULL == hello->sh); | 591 | GNUNET_assert (NULL == hello->sh); |
624 | GNUNET_free (hello); | 592 | GNUNET_free (hello); |
625 | } | 593 | } |
@@ -634,9 +602,7 @@ peer_free (struct Peer *p) | |||
634 | p->wc = NULL; | 602 | p->wc = NULL; |
635 | } | 603 | } |
636 | GNUNET_assert (GNUNET_YES == | 604 | GNUNET_assert (GNUNET_YES == |
637 | GNUNET_CONTAINER_multipeermap_remove (h->peers, | 605 | GNUNET_CONTAINER_multipeermap_remove (h->peers, &p->pid, p)); |
638 | &p->pid, | ||
639 | p)); | ||
640 | GNUNET_free (p); | 606 | GNUNET_free (p); |
641 | } | 607 | } |
642 | 608 | ||
@@ -662,23 +628,22 @@ consider_notify_transport (struct GNUNET_ATS_SessionHandle *sh) | |||
662 | delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation); | 628 | delay = GNUNET_TIME_absolute_get_duration (sh->last_allocation); |
663 | /* A significant change is more than 10% of the quota, | 629 | /* A significant change is more than 10% of the quota, |
664 | which is given in bytes/second */ | 630 | which is given in bytes/second */ |
665 | sig_in | 631 | sig_in = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / |
666 | = h->networks[nt].total_quota_in * (delay.rel_value_us / 1000LL) / 1000LL / 10; | 632 | 1000LL / 10; |
667 | sig_out | 633 | sig_out = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / |
668 | = h->networks[nt].total_quota_out * (delay.rel_value_us / 1000LL) / 1000LL / 10; | 634 | 1000LL / 10; |
669 | delta_in = ( (int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 635 | delta_in = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); |
670 | delta_out = ( (int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); | 636 | delta_out = ((int64_t) ntohl (sh->bw_in.value__)) - ((int64_t) sh->target_in); |
671 | /* we want the absolute values */ | 637 | /* we want the absolute values */ |
672 | if (delta_in < 0) | 638 | if (delta_in < 0) |
673 | delta_in = - delta_in; | 639 | delta_in = -delta_in; |
674 | if (INT64_MIN == delta_in) | 640 | if (INT64_MIN == delta_in) |
675 | delta_in = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */ | 641 | delta_in = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */ |
676 | if (delta_out < 0) | 642 | if (delta_out < 0) |
677 | delta_out = - delta_out; | 643 | delta_out = -delta_out; |
678 | if (INT64_MIN == delta_out) | 644 | if (INT64_MIN == delta_out) |
679 | delta_out = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */ | 645 | delta_out = INT64_MAX; /* Handle corner case: INT_MIN == - INT_MIN */ |
680 | if ( (sig_in > delta_in) && | 646 | if ((sig_in > delta_in) && (sig_out > delta_out)) |
681 | (sig_out > delta_out) ) | ||
682 | return; /* insignificant change */ | 647 | return; /* insignificant change */ |
683 | /* change is significant, tell transport! */ | 648 | /* change is significant, tell transport! */ |
684 | if (sh->target_in > UINT32_MAX) | 649 | if (sh->target_in > UINT32_MAX) |
@@ -731,7 +696,6 @@ struct Counters | |||
731 | * for inbound bandwidth? | 696 | * for inbound bandwidth? |
732 | */ | 697 | */ |
733 | double scale_in[GNUNET_NT_COUNT]; | 698 | double scale_in[GNUNET_NT_COUNT]; |
734 | |||
735 | }; | 699 | }; |
736 | 700 | ||
737 | 701 | ||
@@ -745,9 +709,7 @@ struct Counters | |||
745 | * @return #GNUNET_YES (continue to iterate) | 709 | * @return #GNUNET_YES (continue to iterate) |
746 | */ | 710 | */ |
747 | static int | 711 | static int |
748 | update_counters (void *cls, | 712 | update_counters (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
749 | const struct GNUNET_PeerIdentity *pid, | ||
750 | void *value) | ||
751 | { | 713 | { |
752 | struct Counters *c = cls; | 714 | struct Counters *c = cls; |
753 | struct Peer *peer = value; | 715 | struct Peer *peer = value; |
@@ -756,67 +718,69 @@ update_counters (void *cls, | |||
756 | (void) pid; | 718 | (void) pid; |
757 | if (NULL == peer->sh_head) | 719 | if (NULL == peer->sh_head) |
758 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ | 720 | return GNUNET_YES; /* no available session, cannot allocate bandwidth */ |
759 | memset (best, | 721 | memset (best, 0, sizeof (best)); |
760 | 0, | 722 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
761 | sizeof (best)); | ||
762 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; | ||
763 | NULL != sh; | ||
764 | sh = sh->next) | 723 | sh = sh->next) |
765 | { | 724 | { |
766 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | 725 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
767 | 726 | ||
768 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; | 727 | sh->target_out = MIN_BANDWIDTH_PER_SESSION; |
769 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; | 728 | c->bw_out_by_nt[nt] += MIN_BANDWIDTH_PER_SESSION; |
770 | c->bw_in_by_nt[nt] += GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION, | 729 | c->bw_in_by_nt[nt] += |
771 | sh->data->prop.goodput_in); | 730 | GNUNET_MAX (MIN_BANDWIDTH_PER_SESSION, sh->data->prop.goodput_in); |
772 | for (enum GNUNET_MQ_PreferenceKind pk = 0; | 731 | for (enum GNUNET_MQ_PreferenceKind pk = 0; pk < GNUNET_MQ_PREFERENCE_COUNT; |
773 | pk < GNUNET_MQ_PREFERENCE_COUNT; | ||
774 | pk++) | 732 | pk++) |
775 | { | 733 | { |
776 | /* General rule: always prefer smaller distance if possible, | 734 | /* General rule: always prefer smaller distance if possible, |
777 | otherwise decide by pk: */ | 735 | otherwise decide by pk: */ |
778 | switch (pk) { | 736 | switch (pk) |
737 | { | ||
779 | case GNUNET_MQ_PREFERENCE_NONE: | 738 | case GNUNET_MQ_PREFERENCE_NONE: |
780 | break; | 739 | break; |
781 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: | 740 | case GNUNET_MQ_PREFERENCE_BANDWIDTH: |
782 | /* For bandwidth, we compare the sum of transmitted bytes and | 741 | /* For bandwidth, we compare the sum of transmitted bytes and |
783 | confirmed transmitted bytes, so confirmed data counts twice */ | 742 | confirmed transmitted bytes, so confirmed data counts twice */ |
784 | if ( (NULL == best[pk]) || | 743 | if ((NULL == best[pk]) || |
785 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 744 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
786 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > | 745 | (sh->data->prop.utilization_out + sh->data->prop.goodput_out > |
787 | best[pk]->data->prop.utilization_out + best[pk]->data->prop.goodput_out) ) | 746 | best[pk]->data->prop.utilization_out + |
747 | best[pk]->data->prop.goodput_out)) | ||
788 | best[pk] = sh; | 748 | best[pk] = sh; |
789 | /* If both are equal (i.e. usually this happens if there is a zero), use | 749 | /* If both are equal (i.e. usually this happens if there is a zero), use |
790 | latency as a yardstick */ | 750 | latency as a yardstick */ |
791 | if ( (sh->data->prop.utilization_out + sh->data->prop.goodput_out == | 751 | if ((sh->data->prop.utilization_out + sh->data->prop.goodput_out == |
792 | best[pk]->data->prop.utilization_out + best[pk]->data->prop.goodput_out) && | 752 | best[pk]->data->prop.utilization_out + |
793 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 753 | best[pk]->data->prop.goodput_out) && |
794 | (sh->data->prop.delay.rel_value_us < | 754 | (sh->data->prop.distance == best[pk]->data->prop.distance) && |
795 | best[pk]->data->prop.delay.rel_value_us) ) | 755 | (sh->data->prop.delay.rel_value_us < |
756 | best[pk]->data->prop.delay.rel_value_us)) | ||
796 | best[pk] = sh; | 757 | best[pk] = sh; |
797 | break; | 758 | break; |
798 | case GNUNET_MQ_PREFERENCE_LATENCY: | 759 | case GNUNET_MQ_PREFERENCE_LATENCY: |
799 | if ( (NULL == best[pk]) || | 760 | if ((NULL == best[pk]) || |
800 | (sh->data->prop.distance < best[pk]->data->prop.distance) || | 761 | (sh->data->prop.distance < best[pk]->data->prop.distance) || |
801 | ( (sh->data->prop.distance == best[pk]->data->prop.distance) && | 762 | ((sh->data->prop.distance == best[pk]->data->prop.distance) && |
802 | (sh->data->prop.delay.rel_value_us < | 763 | (sh->data->prop.delay.rel_value_us < |
803 | best[pk]->data->prop.delay.rel_value_us) ) ) | 764 | best[pk]->data->prop.delay.rel_value_us))) |
804 | best[pk] = sh; | 765 | best[pk] = sh; |
805 | break; | 766 | break; |
806 | case GNUNET_MQ_PREFERENCE_RELIABILITY: | 767 | case GNUNET_MQ_PREFERENCE_RELIABILITY: |
807 | /* For reliability, we consider the ratio of goodput to utilization | 768 | /* For reliability, we consider the ratio of goodput to utilization |
808 | (but use multiplicative formultations to avoid division by zero) */ | 769 | (but use multiplicative formultations to avoid division by zero) */ |
809 | if ( (NULL == best[pk]) || | 770 | if ((NULL == best[pk]) || (1ULL * sh->data->prop.goodput_out * |
810 | (1ULL * sh->data->prop.goodput_out * best[pk]->data->prop.utilization_out > | 771 | best[pk]->data->prop.utilization_out > |
811 | 1ULL * sh->data->prop.utilization_out * best[pk]->data->prop.goodput_out) ) | 772 | 1ULL * sh->data->prop.utilization_out * |
773 | best[pk]->data->prop.goodput_out)) | ||
812 | best[pk] = sh; | 774 | best[pk] = sh; |
813 | /* If both are equal (i.e. usually this happens if there is a zero), use | 775 | /* If both are equal (i.e. usually this happens if there is a zero), use |
814 | latency as a yardstick */ | 776 | latency as a yardstick */ |
815 | if ( (1ULL * sh->data->prop.goodput_out * best[pk]->data->prop.utilization_out == | 777 | if ((1ULL * sh->data->prop.goodput_out * |
816 | 1ULL * sh->data->prop.utilization_out * best[pk]->data->prop.goodput_out) && | 778 | best[pk]->data->prop.utilization_out == |
817 | (sh->data->prop.distance == best[pk]->data->prop.distance) && | 779 | 1ULL * sh->data->prop.utilization_out * |
818 | (sh->data->prop.delay.rel_value_us < | 780 | best[pk]->data->prop.goodput_out) && |
819 | best[pk]->data->prop.delay.rel_value_us) ) | 781 | (sh->data->prop.distance == best[pk]->data->prop.distance) && |
782 | (sh->data->prop.delay.rel_value_us < | ||
783 | best[pk]->data->prop.delay.rel_value_us)) | ||
820 | best[pk] = sh; | 784 | best[pk] = sh; |
821 | break; | 785 | break; |
822 | } | 786 | } |
@@ -824,7 +788,8 @@ update_counters (void *cls, | |||
824 | } | 788 | } |
825 | /* for first round, assign target bandwidth simply to sum of | 789 | /* for first round, assign target bandwidth simply to sum of |
826 | requested bandwidth */ | 790 | requested bandwidth */ |
827 | for (enum GNUNET_MQ_PreferenceKind pk = 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; | 791 | for (enum GNUNET_MQ_PreferenceKind pk = |
792 | 1 /* skip GNUNET_MQ_PREFERENCE_NONE */; | ||
828 | pk < GNUNET_MQ_PREFERENCE_COUNT; | 793 | pk < GNUNET_MQ_PREFERENCE_COUNT; |
829 | pk++) | 794 | pk++) |
830 | { | 795 | { |
@@ -833,9 +798,10 @@ update_counters (void *cls, | |||
833 | 798 | ||
834 | GNUNET_assert (NULL != data); | 799 | GNUNET_assert (NULL != data); |
835 | nt = data->prop.nt; | 800 | nt = data->prop.nt; |
836 | best[pk]->target_out = GNUNET_MIN (peer->bw_by_pk[pk], | 801 | best[pk]->target_out = |
837 | MIN_BANDWIDTH_PER_SESSION); | 802 | GNUNET_MIN (peer->bw_by_pk[pk], MIN_BANDWIDTH_PER_SESSION); |
838 | c->bw_out_by_nt[nt] += (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); | 803 | c->bw_out_by_nt[nt] += |
804 | (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION); | ||
839 | } | 805 | } |
840 | return GNUNET_YES; | 806 | return GNUNET_YES; |
841 | } | 807 | } |
@@ -859,8 +825,7 @@ update_allocation (void *cls, | |||
859 | struct Peer *peer = value; | 825 | struct Peer *peer = value; |
860 | 826 | ||
861 | (void) pid; | 827 | (void) pid; |
862 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; | 828 | for (struct GNUNET_ATS_SessionHandle *sh = peer->sh_head; NULL != sh; |
863 | NULL != sh; | ||
864 | sh = sh->next) | 829 | sh = sh->next) |
865 | { | 830 | { |
866 | enum GNUNET_NetworkType nt = sh->data->prop.nt; | 831 | enum GNUNET_NetworkType nt = sh->data->prop.nt; |
@@ -879,27 +844,21 @@ update_allocation (void *cls, | |||
879 | static void | 844 | static void |
880 | update (struct SimpleHandle *h) | 845 | update (struct SimpleHandle *h) |
881 | { | 846 | { |
882 | struct Counters cnt = { | 847 | struct Counters cnt = {.h = h}; |
883 | .h = h | ||
884 | }; | ||
885 | 848 | ||
886 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, | 849 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_counters, &cnt); |
887 | &update_counters, | ||
888 | &cnt); | ||
889 | /* calculate how badly the missmatch between requested | 850 | /* calculate how badly the missmatch between requested |
890 | allocations and available bandwidth is per network type */ | 851 | allocations and available bandwidth is per network type */ |
891 | for (enum GNUNET_NetworkType nt = 0; | 852 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
892 | nt < GNUNET_NT_COUNT; | ||
893 | nt++) | ||
894 | { | 853 | { |
895 | cnt.scale_out[nt] = 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; | 854 | cnt.scale_out[nt] = |
896 | cnt.scale_in[nt] = 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; | 855 | 1.0 * cnt.bw_out_by_nt[nt] / h->networks[nt].total_quota_out; |
856 | cnt.scale_in[nt] = | ||
857 | 1.0 * cnt.bw_in_by_nt[nt] / h->networks[nt].total_quota_in; | ||
897 | } | 858 | } |
898 | /* recalculate allocations, considering scaling factor, and | 859 | /* recalculate allocations, considering scaling factor, and |
899 | update transport if the change is significant */ | 860 | update transport if the change is significant */ |
900 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, | 861 | GNUNET_CONTAINER_multipeermap_iterate (h->peers, &update_allocation, &cnt); |
901 | &update_allocation, | ||
902 | &cnt); | ||
903 | } | 862 | } |
904 | 863 | ||
905 | 864 | ||
@@ -911,12 +870,10 @@ update (struct SimpleHandle *h) | |||
911 | * @return plugin's internal representation, or NULL | 870 | * @return plugin's internal representation, or NULL |
912 | */ | 871 | */ |
913 | static struct GNUNET_ATS_PreferenceHandle * | 872 | static struct GNUNET_ATS_PreferenceHandle * |
914 | simple_preference_add (void *cls, | 873 | simple_preference_add (void *cls, const struct GNUNET_ATS_Preference *pref) |
915 | const struct GNUNET_ATS_Preference *pref) | ||
916 | { | 874 | { |
917 | struct SimpleHandle *h = cls; | 875 | struct SimpleHandle *h = cls; |
918 | struct Peer *p = peer_add (h, | 876 | struct Peer *p = peer_add (h, &pref->peer); |
919 | &pref->peer); | ||
920 | 877 | ||
921 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 878 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
922 | p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); | 879 | p->bw_by_pk[pref->pk] += ntohl (pref->bw.value__); |
@@ -936,19 +893,17 @@ simple_preference_add (void *cls, | |||
936 | */ | 893 | */ |
937 | static void | 894 | static void |
938 | simple_preference_del (void *cls, | 895 | simple_preference_del (void *cls, |
939 | struct GNUNET_ATS_PreferenceHandle *ph, | 896 | struct GNUNET_ATS_PreferenceHandle *ph, |
940 | const struct GNUNET_ATS_Preference *pref) | 897 | const struct GNUNET_ATS_Preference *pref) |
941 | { | 898 | { |
942 | struct SimpleHandle *h = cls; | 899 | struct SimpleHandle *h = cls; |
943 | struct Peer *p = lookup_peer (h, | 900 | struct Peer *p = lookup_peer (h, &pref->peer); |
944 | &pref->peer); | ||
945 | 901 | ||
946 | GNUNET_assert (NULL != p); | 902 | GNUNET_assert (NULL != p); |
947 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); | 903 | GNUNET_assert (pref->pk < GNUNET_MQ_PREFERENCE_COUNT); |
948 | p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 904 | p->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); |
949 | h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); | 905 | h->bw_by_pk[pref->pk] -= ntohl (pref->bw.value__); |
950 | if ( (0 == p->bw_by_pk[pref->pk]) && | 906 | if ((0 == p->bw_by_pk[pref->pk]) && (GNUNET_YES == peer_test_dead (p))) |
951 | (GNUNET_YES == peer_test_dead (p)) ) | ||
952 | peer_free (p); | 907 | peer_free (p); |
953 | update (h); | 908 | update (h); |
954 | } | 909 | } |
@@ -965,12 +920,11 @@ simple_preference_del (void *cls, | |||
965 | */ | 920 | */ |
966 | static struct GNUNET_ATS_SessionHandle * | 921 | static struct GNUNET_ATS_SessionHandle * |
967 | simple_session_add (void *cls, | 922 | simple_session_add (void *cls, |
968 | const struct GNUNET_ATS_SessionData *data, | 923 | const struct GNUNET_ATS_SessionData *data, |
969 | const char *address) | 924 | const char *address) |
970 | { | 925 | { |
971 | struct SimpleHandle *h = cls; | 926 | struct SimpleHandle *h = cls; |
972 | struct Peer *p = peer_add (h, | 927 | struct Peer *p = peer_add (h, &data->peer); |
973 | &data->peer); | ||
974 | struct Hello *hello; | 928 | struct Hello *hello; |
975 | size_t alen; | 929 | size_t alen; |
976 | struct GNUNET_ATS_SessionHandle *sh; | 930 | struct GNUNET_ATS_SessionHandle *sh; |
@@ -991,25 +945,22 @@ simple_session_add (void *cls, | |||
991 | } | 945 | } |
992 | else | 946 | else |
993 | { | 947 | { |
994 | memcpy (&sh[1], | 948 | memcpy (&sh[1], address, alen); |
995 | address, | ||
996 | alen); | ||
997 | sh->address = (const char *) &sh[1]; | 949 | sh->address = (const char *) &sh[1]; |
998 | } | 950 | } |
999 | GNUNET_CONTAINER_DLL_insert (p->sh_head, | 951 | GNUNET_CONTAINER_DLL_insert (p->sh_head, p->sh_tail, sh); |
1000 | p->sh_tail, | 952 | if (NULL != address) |
1001 | sh); | ||
1002 | /* match HELLO */ | ||
1003 | hello = p->h_head; | ||
1004 | while ( (NULL != hello) && | ||
1005 | (0 != strcmp (address, | ||
1006 | hello->address)) ) | ||
1007 | hello = hello->next; | ||
1008 | if (NULL != hello) | ||
1009 | { | 953 | { |
1010 | hello->sh = sh; | 954 | /* match HELLO */ |
1011 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | 955 | hello = p->h_head; |
1012 | sh->hello = hello; | 956 | while ((NULL != hello) && (0 != strcmp (address, hello->address))) |
957 | hello = hello->next; | ||
958 | if (NULL != hello) | ||
959 | { | ||
960 | hello->sh = sh; | ||
961 | hello->backoff = GNUNET_TIME_UNIT_ZERO; | ||
962 | sh->hello = hello; | ||
963 | } | ||
1013 | } | 964 | } |
1014 | update (h); | 965 | update (h); |
1015 | return sh; | 966 | return sh; |
@@ -1026,8 +977,8 @@ simple_session_add (void *cls, | |||
1026 | */ | 977 | */ |
1027 | static void | 978 | static void |
1028 | simple_session_update (void *cls, | 979 | simple_session_update (void *cls, |
1029 | struct GNUNET_ATS_SessionHandle *sh, | 980 | struct GNUNET_ATS_SessionHandle *sh, |
1030 | const struct GNUNET_ATS_SessionData *data) | 981 | const struct GNUNET_ATS_SessionData *data) |
1031 | { | 982 | { |
1032 | struct SimpleHandle *h = cls; | 983 | struct SimpleHandle *h = cls; |
1033 | 984 | ||
@@ -1046,17 +997,15 @@ simple_session_update (void *cls, | |||
1046 | */ | 997 | */ |
1047 | static void | 998 | static void |
1048 | simple_session_del (void *cls, | 999 | simple_session_del (void *cls, |
1049 | struct GNUNET_ATS_SessionHandle *sh, | 1000 | struct GNUNET_ATS_SessionHandle *sh, |
1050 | const struct GNUNET_ATS_SessionData *data) | 1001 | const struct GNUNET_ATS_SessionData *data) |
1051 | { | 1002 | { |
1052 | struct SimpleHandle *h = cls; | 1003 | struct SimpleHandle *h = cls; |
1053 | struct Peer *p = sh->peer; | 1004 | struct Peer *p = sh->peer; |
1054 | struct Hello *hello = sh->hello; | 1005 | struct Hello *hello = sh->hello; |
1055 | 1006 | ||
1056 | /* clean up sh */ | 1007 | /* clean up sh */ |
1057 | GNUNET_CONTAINER_DLL_remove (p->sh_head, | 1008 | GNUNET_CONTAINER_DLL_remove (p->sh_head, p->sh_tail, sh); |
1058 | p->sh_tail, | ||
1059 | sh); | ||
1060 | if (NULL != hello) | 1009 | if (NULL != hello) |
1061 | { | 1010 | { |
1062 | GNUNET_assert (sh == hello->sh); | 1011 | GNUNET_assert (sh == hello->sh); |
@@ -1064,13 +1013,11 @@ simple_session_del (void *cls, | |||
1064 | /* session went down, if necessary restart suggesting | 1013 | /* session went down, if necessary restart suggesting |
1065 | addresses */ | 1014 | addresses */ |
1066 | if (NULL == p->task) | 1015 | if (NULL == p->task) |
1067 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, | 1016 | p->task = GNUNET_SCHEDULER_add_now (&suggest_start_cb, p); |
1068 | p); | ||
1069 | } | 1017 | } |
1070 | GNUNET_free (sh); | 1018 | GNUNET_free (sh); |
1071 | /* del peer if otherwise dead */ | 1019 | /* del peer if otherwise dead */ |
1072 | if ( (NULL == p->sh_head) && | 1020 | if ((NULL == p->sh_head) && (GNUNET_YES == peer_test_dead (p))) |
1073 | (GNUNET_YES == peer_test_dead (p)) ) | ||
1074 | peer_free (p); | 1021 | peer_free (p); |
1075 | update (h); | 1022 | update (h); |
1076 | } | 1023 | } |
@@ -1095,8 +1042,7 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1095 | 1042 | ||
1096 | s = GNUNET_new (struct SimpleHandle); | 1043 | s = GNUNET_new (struct SimpleHandle); |
1097 | s->env = env; | 1044 | s->env = env; |
1098 | s->peers = GNUNET_CONTAINER_multipeermap_create (128, | 1045 | s->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); |
1099 | GNUNET_YES); | ||
1100 | s->ps = GNUNET_PEERSTORE_connect (env->cfg); | 1046 | s->ps = GNUNET_PEERSTORE_connect (env->cfg); |
1101 | sf.cls = s; | 1047 | sf.cls = s; |
1102 | sf.preference_add = &simple_preference_add; | 1048 | sf.preference_add = &simple_preference_add; |
@@ -1104,9 +1050,7 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1104 | sf.session_add = &simple_session_add; | 1050 | sf.session_add = &simple_session_add; |
1105 | sf.session_update = &simple_session_update; | 1051 | sf.session_update = &simple_session_update; |
1106 | sf.session_del = &simple_session_del; | 1052 | sf.session_del = &simple_session_del; |
1107 | for (enum GNUNET_NetworkType nt = 0; | 1053 | for (enum GNUNET_NetworkType nt = 0; nt < GNUNET_NT_COUNT; nt++) |
1108 | nt < GNUNET_NT_COUNT; | ||
1109 | nt++) | ||
1110 | { | 1054 | { |
1111 | const char *name = GNUNET_NT_to_string (nt); | 1055 | const char *name = GNUNET_NT_to_string (nt); |
1112 | 1056 | ||
@@ -1115,14 +1059,8 @@ libgnunet_plugin_ats2_simple_init (void *cls) | |||
1115 | GNUNET_break (0); | 1059 | GNUNET_break (0); |
1116 | break; | 1060 | break; |
1117 | } | 1061 | } |
1118 | get_quota (env->cfg, | 1062 | get_quota (env->cfg, name, "IN", &s->networks[nt].total_quota_in); |
1119 | name, | 1063 | get_quota (env->cfg, name, "OUT", &s->networks[nt].total_quota_out); |
1120 | "IN", | ||
1121 | &s->networks[nt].total_quota_in); | ||
1122 | get_quota (env->cfg, | ||
1123 | name, | ||
1124 | "OUT", | ||
1125 | &s->networks[nt].total_quota_out); | ||
1126 | s->networks[nt].type = nt; | 1064 | s->networks[nt].type = nt; |
1127 | } | 1065 | } |
1128 | return &sf; | 1066 | return &sf; |
@@ -1140,11 +1078,9 @@ libgnunet_plugin_ats2_simple_done (void *cls) | |||
1140 | struct GNUNET_ATS_SolverFunctions *sf = cls; | 1078 | struct GNUNET_ATS_SolverFunctions *sf = cls; |
1141 | struct SimpleHandle *s = sf->cls; | 1079 | struct SimpleHandle *s = sf->cls; |
1142 | 1080 | ||
1143 | GNUNET_break (0 == | 1081 | GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (s->peers)); |
1144 | GNUNET_CONTAINER_multipeermap_size (s->peers)); | ||
1145 | GNUNET_CONTAINER_multipeermap_destroy (s->peers); | 1082 | GNUNET_CONTAINER_multipeermap_destroy (s->peers); |
1146 | GNUNET_PEERSTORE_disconnect (s->ps, | 1083 | GNUNET_PEERSTORE_disconnect (s->ps, GNUNET_NO); |
1147 | GNUNET_NO); | ||
1148 | GNUNET_free (s); | 1084 | GNUNET_free (s); |
1149 | return NULL; | 1085 | return NULL; |
1150 | } | 1086 | } |