diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-21 15:08:55 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-21 15:08:55 +0000 |
commit | a73229d780f855971649aa5afb66813ff759453b (patch) | |
tree | 299fcfe45a27185359c73846fff0f721fe8a5eb9 /src/ats | |
parent | b7ae1ce7504f4b2bc7ce3eda3ca1e8819eb745da (diff) | |
download | gnunet-a73229d780f855971649aa5afb66813ff759453b.tar.gz gnunet-a73229d780f855971649aa5afb66813ff759453b.zip |
basics for quality normalization
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 3 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 138 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 7 |
3 files changed, 133 insertions, 15 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index e0a2449c1..8083ba914 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -919,6 +919,7 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle, | |||
919 | prev_session = aa->session_id; | 919 | prev_session = aa->session_id; |
920 | aa->session_id = session_id; | 920 | aa->session_id = session_id; |
921 | 921 | ||
922 | GAS_normalization_normalize_property (aa, atsi, atsi_count); | ||
922 | 923 | ||
923 | /* Tell solver about update */ | 924 | /* Tell solver about update */ |
924 | handle->s_update (handle->solver, handle->addresses, aa, prev_session, aa->used, atsi_delta, atsi_delta_count); | 925 | handle->s_update (handle->solver, handle->addresses, aa, prev_session, aa->used, atsi_delta, atsi_delta_count); |
@@ -1350,7 +1351,7 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle, | |||
1350 | return; | 1351 | return; |
1351 | } | 1352 | } |
1352 | /* Tell normalization about change, normalization will call callback if preference changed */ | 1353 | /* Tell normalization about change, normalization will call callback if preference changed */ |
1353 | GAS_normalization_change_preference (client, peer, kind, score_abs); | 1354 | GAS_normalization_normalize_preference (client, peer, kind, score_abs); |
1354 | } | 1355 | } |
1355 | 1356 | ||
1356 | 1357 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 129aa1dd5..2b0efa912 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #include "gnunet_ats_service.h" | 28 | #include "gnunet_ats_service.h" |
29 | #include "gnunet-service-ats_addresses.h" | ||
29 | #include "gnunet-service-ats_normalization.h" | 30 | #include "gnunet-service-ats_normalization.h" |
30 | 31 | ||
31 | 32 | ||
@@ -143,9 +144,17 @@ static void *pref_changed_cb_cls; | |||
143 | 144 | ||
144 | 145 | ||
145 | /** | 146 | /** |
146 | * Hashmap to store peer information | 147 | * Hashmap to store peer information for preference normalization |
147 | */ | 148 | */ |
148 | static struct GNUNET_CONTAINER_MultiHashMap *peers; | 149 | static struct GNUNET_CONTAINER_MultiHashMap *preference_peers; |
150 | |||
151 | |||
152 | |||
153 | /** | ||
154 | * Hashmap to store peer information for property normalization | ||
155 | */ | ||
156 | static struct GNUNET_CONTAINER_MultiHashMap *property_peers; | ||
157 | |||
149 | 158 | ||
150 | 159 | ||
151 | /** | 160 | /** |
@@ -165,6 +174,10 @@ static struct PreferenceClient *pc_tail; | |||
165 | */ | 174 | */ |
166 | static struct PeerRelative defvalues; | 175 | static struct PeerRelative defvalues; |
167 | 176 | ||
177 | /** | ||
178 | * Application Preference Normalization | ||
179 | */ | ||
180 | |||
168 | 181 | ||
169 | /** | 182 | /** |
170 | * Update a peer | 183 | * Update a peer |
@@ -210,7 +223,7 @@ update_peers (struct GNUNET_PeerIdentity *id, | |||
210 | GNUNET_i2s (id), | 223 | GNUNET_i2s (id), |
211 | GNUNET_ATS_print_preference_type (kind), | 224 | GNUNET_ATS_print_preference_type (kind), |
212 | f_rel_total); | 225 | f_rel_total); |
213 | if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | 226 | if (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &id->hashPubKey))) |
214 | { | 227 | { |
215 | backup = rp->f_rel[kind]; | 228 | backup = rp->f_rel[kind]; |
216 | if (0 < count) | 229 | if (0 < count) |
@@ -297,7 +310,7 @@ recalculate_rel_preferences (struct PreferenceClient *c, | |||
297 | else | 310 | else |
298 | { | 311 | { |
299 | /* Value did not chang, return old value*/ | 312 | /* Value did not chang, return old value*/ |
300 | GNUNET_assert (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (peers, | 313 | GNUNET_assert (NULL != (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, |
301 | &p->id.hashPubKey))); | 314 | &p->id.hashPubKey))); |
302 | ret = rp->f_rel[kind]; | 315 | ret = rp->f_rel[kind]; |
303 | } | 316 | } |
@@ -383,7 +396,7 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
383 | * @param score_abs the normalized score | 396 | * @param score_abs the normalized score |
384 | */ | 397 | */ |
385 | float | 398 | float |
386 | GAS_normalization_change_preference (void *src, | 399 | GAS_normalization_normalize_preference (void *src, |
387 | const struct GNUNET_PeerIdentity *peer, | 400 | const struct GNUNET_PeerIdentity *peer, |
388 | enum GNUNET_ATS_PreferenceKind kind, | 401 | enum GNUNET_ATS_PreferenceKind kind, |
389 | float score_abs) | 402 | float score_abs) |
@@ -449,14 +462,14 @@ GAS_normalization_change_preference (void *src, | |||
449 | GNUNET_CONTAINER_DLL_insert (c_cur->p_head, c_cur->p_tail, p_cur); | 462 | GNUNET_CONTAINER_DLL_insert (c_cur->p_head, c_cur->p_tail, p_cur); |
450 | } | 463 | } |
451 | 464 | ||
452 | if (NULL == (r_cur = GNUNET_CONTAINER_multihashmap_get (peers, | 465 | if (NULL == (r_cur = GNUNET_CONTAINER_multihashmap_get (preference_peers, |
453 | &peer->hashPubKey))) | 466 | &peer->hashPubKey))) |
454 | { | 467 | { |
455 | r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); | 468 | r_cur = GNUNET_malloc (sizeof (struct PeerRelative)); |
456 | r_cur->id = (*peer); | 469 | r_cur->id = (*peer); |
457 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 470 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
458 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 471 | r_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
459 | GNUNET_CONTAINER_multihashmap_put (peers, &r_cur->id.hashPubKey, | 472 | GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey, |
460 | r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 473 | r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
461 | } | 474 | } |
462 | 475 | ||
@@ -476,17 +489,104 @@ GAS_normalization_change_preference (void *src, | |||
476 | const double * | 489 | const double * |
477 | GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id) | 490 | GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id) |
478 | { | 491 | { |
479 | GNUNET_assert (NULL != peers); | 492 | GNUNET_assert (NULL != preference_peers); |
480 | GNUNET_assert (NULL != id); | 493 | GNUNET_assert (NULL != id); |
481 | 494 | ||
482 | struct PeerRelative *rp; | 495 | struct PeerRelative *rp; |
483 | if (NULL == (rp = GNUNET_CONTAINER_multihashmap_get (peers, &id->hashPubKey))) | 496 | if (NULL == (rp = GNUNET_CONTAINER_multihashmap_get (preference_peers, &id->hashPubKey))) |
484 | { | 497 | { |
485 | return defvalues.f_rel; | 498 | return defvalues.f_rel; |
486 | } | 499 | } |
487 | return rp->f_rel; | 500 | return rp->f_rel; |
488 | } | 501 | } |
489 | 502 | ||
503 | /** | ||
504 | * Quality Normalization | ||
505 | */ | ||
506 | |||
507 | struct Property | ||
508 | { | ||
509 | int have_min; /* Do we have min and max */ | ||
510 | int have_max; | ||
511 | uint32_t min; | ||
512 | uint32_t max; | ||
513 | }; | ||
514 | |||
515 | struct Property properties[GNUNET_ATS_QualityPropertiesCount]; | ||
516 | |||
517 | uint32_t property_average (struct ATS_Address *address, | ||
518 | const struct GNUNET_ATS_Information *atsi) | ||
519 | { | ||
520 | /* Average the values of this property */ | ||
521 | return ntohl(atsi->value); | ||
522 | } | ||
523 | |||
524 | void property_normalize (struct ATS_Address *address, | ||
525 | uint32_t type) | ||
526 | { | ||
527 | /* Normalize the values of this property */ | ||
528 | //GNUNET_break (0); | ||
529 | } | ||
530 | |||
531 | |||
532 | |||
533 | void | ||
534 | GAS_normalization_normalize_property (struct ATS_Address *address, | ||
535 | const struct GNUNET_ATS_Information *atsi, | ||
536 | uint32_t atsi_count) | ||
537 | { | ||
538 | struct Property *cur_prop; | ||
539 | int c1; | ||
540 | int c2; | ||
541 | uint32_t current_type; | ||
542 | uint32_t current_val; | ||
543 | |||
544 | int existing_properties[] = GNUNET_ATS_QualityProperties; | ||
545 | |||
546 | for (c1 = 0; c1 < atsi_count; c1++) | ||
547 | { | ||
548 | current_type = ntohl (atsi[c1].type); | ||
549 | current_val = ntohl (atsi[c1].value); | ||
550 | for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++) | ||
551 | { | ||
552 | if (current_type == existing_properties[c2]) | ||
553 | break; | ||
554 | } | ||
555 | if (GNUNET_ATS_QualityPropertiesCount == c2) | ||
556 | { | ||
557 | /* Invalid property */ | ||
558 | continue; | ||
559 | } | ||
560 | |||
561 | /* Averaging */ | ||
562 | current_val = property_average (address, &atsi[c1]); | ||
563 | |||
564 | /* Normalizing */ | ||
565 | /* Check min, max */ | ||
566 | cur_prop = &properties[c2]; | ||
567 | if (cur_prop->max < current_val) | ||
568 | { | ||
569 | cur_prop->max = current_val; | ||
570 | if (GNUNET_NO == cur_prop->have_max) | ||
571 | cur_prop->have_max = GNUNET_YES; | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New maximum of %u for property %u\n", cur_prop->max, current_type); | ||
573 | } | ||
574 | if (cur_prop->min > current_val) | ||
575 | { | ||
576 | cur_prop->min = current_val; | ||
577 | if (GNUNET_NO == cur_prop->have_min) | ||
578 | cur_prop->have_min = GNUNET_YES; | ||
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New minimum of %u for property %u\n", cur_prop->min, current_type); | ||
580 | } | ||
581 | |||
582 | |||
583 | property_normalize (address, ntohl(atsi[c1].type)); | ||
584 | } | ||
585 | |||
586 | } | ||
587 | |||
588 | |||
589 | |||
490 | 590 | ||
491 | /** | 591 | /** |
492 | * Start the normalization component | 592 | * Start the normalization component |
@@ -498,8 +598,19 @@ void | |||
498 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | 598 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, |
499 | void *pref_ch_cb_cls) | 599 | void *pref_ch_cb_cls) |
500 | { | 600 | { |
601 | int c1; | ||
501 | int i; | 602 | int i; |
502 | peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | 603 | preference_peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); |
604 | property_peers = GNUNET_CONTAINER_multihashmap_create(10, GNUNET_NO); | ||
605 | |||
606 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | ||
607 | { | ||
608 | properties[c1].min = 0; | ||
609 | properties[c1].max = 0; | ||
610 | properties[c1].have_max = GNUNET_NO; | ||
611 | properties[c1].have_min = GNUNET_NO; | ||
612 | } | ||
613 | |||
503 | pref_changed_cb = pref_ch_cb; | 614 | pref_changed_cb = pref_ch_cb; |
504 | pref_changed_cb_cls = pref_ch_cb_cls; | 615 | pref_changed_cb_cls = pref_ch_cb_cls; |
505 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 616 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
@@ -522,7 +633,7 @@ free_peer (void *cls, | |||
522 | void *value) | 633 | void *value) |
523 | { | 634 | { |
524 | struct PeerRelative *rp = value; | 635 | struct PeerRelative *rp = value; |
525 | GNUNET_CONTAINER_multihashmap_remove (peers, key, value); | 636 | GNUNET_CONTAINER_multihashmap_remove (preference_peers, key, value); |
526 | GNUNET_free (rp); | 637 | GNUNET_free (rp); |
527 | return GNUNET_OK; | 638 | return GNUNET_OK; |
528 | } | 639 | } |
@@ -558,8 +669,9 @@ GAS_normalization_stop () | |||
558 | } | 669 | } |
559 | GNUNET_free (pc); | 670 | GNUNET_free (pc); |
560 | } | 671 | } |
561 | GNUNET_CONTAINER_multihashmap_iterate (peers, &free_peer, NULL); | 672 | GNUNET_CONTAINER_multihashmap_iterate (preference_peers, &free_peer, NULL); |
562 | GNUNET_CONTAINER_multihashmap_destroy (peers); | 673 | GNUNET_CONTAINER_multihashmap_destroy (preference_peers); |
674 | GNUNET_CONTAINER_multihashmap_destroy (property_peers); | ||
563 | return; | 675 | return; |
564 | } | 676 | } |
565 | 677 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 37e694dd7..c90d4d8c6 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -59,11 +59,16 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id); | |||
59 | * @param score_abs the normalized score | 59 | * @param score_abs the normalized score |
60 | */ | 60 | */ |
61 | float | 61 | float |
62 | GAS_normalization_change_preference (void *src, | 62 | GAS_normalization_normalize_preference (void *src, |
63 | const struct GNUNET_PeerIdentity *peer, | 63 | const struct GNUNET_PeerIdentity *peer, |
64 | enum GNUNET_ATS_PreferenceKind kind, | 64 | enum GNUNET_ATS_PreferenceKind kind, |
65 | float score_abs); | 65 | float score_abs); |
66 | 66 | ||
67 | void | ||
68 | GAS_normalization_normalize_property (struct ATS_Address *address, | ||
69 | const struct GNUNET_ATS_Information *atsi, | ||
70 | uint32_t atsi_count); | ||
71 | |||
67 | /** | 72 | /** |
68 | * Start the normalization component | 73 | * Start the normalization component |
69 | * | 74 | * |