diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-19 16:42:03 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-11-19 16:42:03 +0000 |
commit | 94a6bb6f521b4d57a10035ad294b4c8ef58f01ff (patch) | |
tree | 0357438d1a30092487866a990989e77b5a70e571 /src/ats/gnunet-service-ats_normalization.c | |
parent | 52acb8f4435955e07aa7694e96a1ab732c9c730d (diff) | |
download | gnunet-94a6bb6f521b4d57a10035ad294b4c8ef58f01ff.tar.gz gnunet-94a6bb6f521b4d57a10035ad294b4c8ef58f01ff.zip |
evaluation
Diffstat (limited to 'src/ats/gnunet-service-ats_normalization.c')
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 109 |
1 files changed, 50 insertions, 59 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 9a4e72665..470b82129 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -220,9 +220,7 @@ update_peers (struct GNUNET_PeerIdentity *id, | |||
220 | "%u clients have a total relative preference for peer `%s''s `%s' of %.3f\n", | 220 | "%u clients have a total relative preference for peer `%s''s `%s' of %.3f\n", |
221 | count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind), | 221 | count, GNUNET_i2s (id), GNUNET_ATS_print_preference_type (kind), |
222 | f_rel_total); | 222 | f_rel_total); |
223 | if (NULL | 223 | if (NULL != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id))) |
224 | != (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, | ||
225 | id))) | ||
226 | { | 224 | { |
227 | backup = rp->f_rel[kind]; | 225 | backup = rp->f_rel[kind]; |
228 | if (0 < count) | 226 | if (0 < count) |
@@ -330,7 +328,7 @@ update_preference (struct PreferenceClient *c, struct PreferencePeer *p, | |||
330 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: | 328 | case GNUNET_ATS_PREFERENCE_BANDWIDTH: |
331 | case GNUNET_ATS_PREFERENCE_LATENCY: | 329 | case GNUNET_ATS_PREFERENCE_LATENCY: |
332 | p->f_abs[kind] = (p->f_abs[kind] + score) / 2; | 330 | p->f_abs[kind] = (p->f_abs[kind] + score) / 2; |
333 | p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), | 331 | p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
334 | PREF_AGING_INTERVAL); | 332 | PREF_AGING_INTERVAL); |
335 | break; | 333 | break; |
336 | case GNUNET_ATS_PREFERENCE_END: | 334 | case GNUNET_ATS_PREFERENCE_END: |
@@ -367,24 +365,26 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
367 | /* Aging absolute values: */ | 365 | /* Aging absolute values: */ |
368 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 366 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
369 | { | 367 | { |
370 | if (0 == GNUNET_TIME_absolute_get_remaining(p->next_aging[i]).rel_value_us) | 368 | if (0 |
369 | == GNUNET_TIME_absolute_get_remaining (p->next_aging[i]).rel_value_us) | ||
371 | { | 370 | { |
372 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Aging preference for peer `%s'\n", | 371 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
373 | GNUNET_i2s (&p->id)); | 372 | "Aging preference for peer `%s'\n", GNUNET_i2s (&p->id)); |
374 | backup = p->f_abs[i]; | 373 | backup = p->f_abs[i]; |
375 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) | 374 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) |
376 | p->f_abs[i] *= PREF_AGING_FACTOR; | 375 | p->f_abs[i] *= PREF_AGING_FACTOR; |
377 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) | 376 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) |
378 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; | 377 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; |
379 | if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE) && (backup != p->f_abs[i])) | 378 | if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE) |
379 | && (backup != p->f_abs[i])) | ||
380 | { | 380 | { |
381 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 381 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
382 | "Aged preference for peer `%s' from %.3f to %.3f\n", | 382 | "Aged preference for peer `%s' from %.3f to %.3f\n", |
383 | GNUNET_i2s (&p->id), backup, p->f_abs[i]); | 383 | GNUNET_i2s (&p->id), backup, p->f_abs[i]); |
384 | recalculate_rel_preferences (p->client, p, i); | 384 | recalculate_rel_preferences (p->client, p, i); |
385 | p->next_aging[i] = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | 385 | p->next_aging[i] = GNUNET_TIME_absolute_add ( |
386 | PREF_AGING_INTERVAL); | 386 | GNUNET_TIME_absolute_get (), PREF_AGING_INTERVAL); |
387 | values_to_update ++; | 387 | values_to_update++; |
388 | } | 388 | } |
389 | } | 389 | } |
390 | } | 390 | } |
@@ -393,18 +393,18 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
393 | 393 | ||
394 | if (values_to_update > 0) | 394 | if (values_to_update > 0) |
395 | { | 395 | { |
396 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
397 | "Rescheduling aging task due to %u elements to age\n", values_to_update); | 397 | "Rescheduling aging task due to %u elements to age\n", |
398 | values_to_update); | ||
398 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 399 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, |
399 | &preference_aging, NULL); | 400 | &preference_aging, NULL ); |
400 | } | 401 | } |
401 | else | 402 | else |
402 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 403 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
403 | "No values to age left, not rescheduling aging task\n"); | 404 | "No values to age left, not rescheduling aging task\n"); |
404 | 405 | ||
405 | } | 406 | } |
406 | 407 | ||
407 | |||
408 | /** | 408 | /** |
409 | * Normalize an updated preference value | 409 | * Normalize an updated preference value |
410 | * | 410 | * |
@@ -415,8 +415,7 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
415 | */ | 415 | */ |
416 | void | 416 | void |
417 | GAS_normalization_normalize_preference (void *src, | 417 | GAS_normalization_normalize_preference (void *src, |
418 | const struct GNUNET_PeerIdentity *peer, | 418 | const struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind kind, |
419 | enum GNUNET_ATS_PreferenceKind kind, | ||
420 | float score_abs) | 419 | float score_abs) |
421 | { | 420 | { |
422 | struct PreferenceClient *c_cur; | 421 | struct PreferenceClient *c_cur; |
@@ -448,9 +447,8 @@ GAS_normalization_normalize_preference (void *src, | |||
448 | { | 447 | { |
449 | c_cur = GNUNET_malloc (sizeof (struct PreferenceClient)); | 448 | c_cur = GNUNET_malloc (sizeof (struct PreferenceClient)); |
450 | c_cur->client = src; | 449 | c_cur->client = src; |
451 | GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, c_cur); | 450 | GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur); |
452 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Adding new client %p \n", c_cur); |
453 | "Adding new client %p \n", c_cur); | ||
454 | } | 452 | } |
455 | 453 | ||
456 | /* Find entry for peer */ | 454 | /* Find entry for peer */ |
@@ -476,20 +474,19 @@ GAS_normalization_normalize_preference (void *src, | |||
476 | GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); | 474 | GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); |
477 | } | 475 | } |
478 | 476 | ||
479 | if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, | 477 | if (NULL == GNUNET_CONTAINER_multipeermap_get (preference_peers, peer)) |
480 | peer)) | ||
481 | { | 478 | { |
482 | r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); | 479 | r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); |
483 | r_cur->id = (*peer); | 480 | r_cur->id = (*peer); |
484 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 481 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
485 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 482 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
486 | GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id, | 483 | GNUNET_CONTAINER_multipeermap_put (preference_peers, &r_cur->id, r_cur, |
487 | r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 484 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
488 | } | 485 | } |
489 | 486 | ||
490 | if (GNUNET_SCHEDULER_NO_TASK == aging_task) | 487 | if (GNUNET_SCHEDULER_NO_TASK == aging_task) |
491 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 488 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, |
492 | &preference_aging, NULL); | 489 | &preference_aging, NULL ); |
493 | 490 | ||
494 | update_preference (c_cur, p_cur, kind, score_abs); | 491 | update_preference (c_cur, p_cur, kind, score_abs); |
495 | } | 492 | } |
@@ -509,9 +506,7 @@ GAS_normalization_get_preferences_by_peer (const struct GNUNET_PeerIdentity *id) | |||
509 | GNUNET_assert(NULL != id); | 506 | GNUNET_assert(NULL != id); |
510 | 507 | ||
511 | struct PeerRelative *rp; | 508 | struct PeerRelative *rp; |
512 | if (NULL | 509 | if (NULL == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, id))) |
513 | == (rp = GNUNET_CONTAINER_multipeermap_get (preference_peers, | ||
514 | id))) | ||
515 | { | 510 | { |
516 | return defvalues.f_rel; | 511 | return defvalues.f_rel; |
517 | } | 512 | } |
@@ -519,17 +514,19 @@ GAS_normalization_get_preferences_by_peer (const struct GNUNET_PeerIdentity *id) | |||
519 | } | 514 | } |
520 | 515 | ||
521 | /** | 516 | /** |
522 | * Get the normalized preference values for a specific peer or | 517 | * Get the normalized preference values for a specific client and peer |
523 | * the default values if | ||
524 | * | 518 | * |
525 | * @param id the peer | 519 | * @param id the peer |
526 | * @return pointer to the values, can be indexed with GNUNET_ATS_PreferenceKind, | 520 | * @param the peer |
527 | * default preferences if peer does not exist | 521 | * @return the value |
528 | */ | 522 | */ |
529 | const double | 523 | const double |
530 | GAS_normalization_get_preferences_by_client (const void *client, enum GNUNET_ATS_PreferenceKind pref) | 524 | GAS_normalization_get_preferences_by_client (const void *client, |
525 | struct GNUNET_PeerIdentity *peer, enum GNUNET_ATS_PreferenceKind pref) | ||
531 | { | 526 | { |
532 | struct PreferenceClient *c_cur; | 527 | struct PreferenceClient *c_cur; |
528 | struct PreferencePeer *p_cur; | ||
529 | |||
533 | /* Find preference client */ | 530 | /* Find preference client */ |
534 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) | 531 | for (c_cur = pc_head; NULL != c_cur; c_cur = c_cur->next) |
535 | { | 532 | { |
@@ -537,9 +534,17 @@ GAS_normalization_get_preferences_by_client (const void *client, enum GNUNET_ATS | |||
537 | break; | 534 | break; |
538 | } | 535 | } |
539 | if (NULL == c_cur) | 536 | if (NULL == c_cur) |
540 | return -1; | 537 | return -1.0; |
538 | |||
539 | for (p_cur = c_cur->p_head; NULL != p_cur; p_cur = p_cur->next) | ||
540 | { | ||
541 | if (0 == memcmp (peer, &p_cur->id, sizeof (struct GNUNET_PeerIdentity))) | ||
542 | break; | ||
543 | } | ||
544 | if (NULL == p_cur) | ||
545 | return DEFAULT_REL_PREFERENCE; /* Not found, return default */ | ||
541 | 546 | ||
542 | return 1.0; | 547 | return p_cur->f_rel[pref]; |
543 | } | 548 | } |
544 | 549 | ||
545 | /** | 550 | /** |
@@ -651,7 +656,6 @@ property_average (struct ATS_Address *address, | |||
651 | return res; | 656 | return res; |
652 | } | 657 | } |
653 | 658 | ||
654 | |||
655 | struct FindMinMaxCtx | 659 | struct FindMinMaxCtx |
656 | { | 660 | { |
657 | struct Property *p; | 661 | struct Property *p; |
@@ -659,11 +663,8 @@ struct FindMinMaxCtx | |||
659 | uint32_t max; | 663 | uint32_t max; |
660 | }; | 664 | }; |
661 | 665 | ||
662 | |||
663 | static int | 666 | static int |
664 | find_min_max_it (void *cls, | 667 | find_min_max_it (void *cls, const struct GNUNET_PeerIdentity *h, void *k) |
665 | const struct GNUNET_PeerIdentity *h, | ||
666 | void *k) | ||
667 | { | 668 | { |
668 | struct FindMinMaxCtx *find_res = cls; | 669 | struct FindMinMaxCtx *find_res = cls; |
669 | struct ATS_Address *a = k; | 670 | struct ATS_Address *a = k; |
@@ -677,11 +678,8 @@ find_min_max_it (void *cls, | |||
677 | return GNUNET_OK; | 678 | return GNUNET_OK; |
678 | } | 679 | } |
679 | 680 | ||
680 | |||
681 | static int | 681 | static int |
682 | normalize_address (void *cls, | 682 | normalize_address (void *cls, const struct GNUNET_PeerIdentity *h, void *k) |
683 | const struct GNUNET_PeerIdentity *h, | ||
684 | void *k) | ||
685 | { | 683 | { |
686 | struct Property *p = cls; | 684 | struct Property *p = cls; |
687 | struct ATS_Address *address = k; | 685 | struct ATS_Address *address = k; |
@@ -706,7 +704,6 @@ normalize_address (void *cls, | |||
706 | return GNUNET_OK; | 704 | return GNUNET_OK; |
707 | } | 705 | } |
708 | 706 | ||
709 | |||
710 | /** | 707 | /** |
711 | * Normalize avg_value to a range of values between [1.0, 2.0] | 708 | * Normalize avg_value to a range of values between [1.0, 2.0] |
712 | * based on min max values currently known. | 709 | * based on min max values currently known. |
@@ -718,9 +715,7 @@ normalize_address (void *cls, | |||
718 | */ | 715 | */ |
719 | static void | 716 | static void |
720 | property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses, | 717 | property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses, |
721 | struct Property *p, | 718 | struct Property *p, struct ATS_Address *address, uint32_t avg_value) |
722 | struct ATS_Address *address, | ||
723 | uint32_t avg_value) | ||
724 | { | 719 | { |
725 | struct FindMinMaxCtx find_ctx; | 720 | struct FindMinMaxCtx find_ctx; |
726 | int addr_count; | 721 | int addr_count; |
@@ -730,7 +725,7 @@ property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses, | |||
730 | find_ctx.max = 0; | 725 | find_ctx.max = 0; |
731 | find_ctx.min = UINT32_MAX; | 726 | find_ctx.min = UINT32_MAX; |
732 | addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses, | 727 | addr_count = GNUNET_CONTAINER_multipeermap_iterate (addresses, |
733 | &find_min_max_it, &find_ctx); | 728 | &find_min_max_it, &find_ctx); |
734 | if (0 == addr_count) | 729 | if (0 == addr_count) |
735 | { | 730 | { |
736 | GNUNET_break(0); | 731 | GNUNET_break(0); |
@@ -786,10 +781,10 @@ property_normalize (struct GNUNET_CONTAINER_MultiPeerMap *addresses, | |||
786 | * @param atsi_count the number of atsi information in the array | 781 | * @param atsi_count the number of atsi information in the array |
787 | */ | 782 | */ |
788 | void | 783 | void |
789 | GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addresses, | 784 | GAS_normalization_normalize_property ( |
790 | struct ATS_Address *address, | 785 | struct GNUNET_CONTAINER_MultiPeerMap *addresses, |
791 | const struct GNUNET_ATS_Information *atsi, | 786 | struct ATS_Address *address, const struct GNUNET_ATS_Information *atsi, |
792 | uint32_t atsi_count) | 787 | uint32_t atsi_count) |
793 | { | 788 | { |
794 | struct Property *cur_prop; | 789 | struct Property *cur_prop; |
795 | int c1; | 790 | int c1; |
@@ -834,7 +829,6 @@ GAS_normalization_normalize_property (struct GNUNET_CONTAINER_MultiPeerMap *addr | |||
834 | } | 829 | } |
835 | } | 830 | } |
836 | 831 | ||
837 | |||
838 | static void | 832 | static void |
839 | free_client (struct PreferenceClient *pc) | 833 | free_client (struct PreferenceClient *pc) |
840 | { | 834 | { |
@@ -850,7 +844,6 @@ free_client (struct PreferenceClient *pc) | |||
850 | GNUNET_free(pc); | 844 | GNUNET_free(pc); |
851 | } | 845 | } |
852 | 846 | ||
853 | |||
854 | /** | 847 | /** |
855 | * A performance client disconnected | 848 | * A performance client disconnected |
856 | * | 849 | * |
@@ -871,11 +864,10 @@ GAS_normalization_preference_client_disconnect (void *client) | |||
871 | if (NULL == c_cur) | 864 | if (NULL == c_cur) |
872 | return; | 865 | return; |
873 | 866 | ||
874 | GNUNET_CONTAINER_DLL_remove (pc_head, pc_tail, c_cur); | 867 | GNUNET_CONTAINER_DLL_remove(pc_head, pc_tail, c_cur); |
875 | free_client (c_cur); | 868 | free_client (c_cur); |
876 | } | 869 | } |
877 | 870 | ||
878 | |||
879 | /** | 871 | /** |
880 | * Start the normalization component | 872 | * Start the normalization component |
881 | * | 873 | * |
@@ -917,7 +909,6 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | |||
917 | return; | 909 | return; |
918 | } | 910 | } |
919 | 911 | ||
920 | |||
921 | /** | 912 | /** |
922 | * Free a peer | 913 | * Free a peer |
923 | * | 914 | * |