diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-26 08:09:46 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-09-26 08:09:46 +0000 |
commit | 66dcb9389f1624af1012b725c581d44413caa12b (patch) | |
tree | 12ec18662abaae5c5ccfa5d7f44540ed4d52eb2a /src/ats/gnunet-service-ats_normalization.c | |
parent | 78ad97319349e9881653684f276dd620a0a423e9 (diff) | |
download | gnunet-66dcb9389f1624af1012b725c581d44413caa12b.tar.gz gnunet-66dcb9389f1624af1012b725c581d44413caa12b.zip |
fixed segfault + improved aging
Diffstat (limited to 'src/ats/gnunet-service-ats_normalization.c')
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 81 |
1 files changed, 53 insertions, 28 deletions
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index a028b06d3..beb78c925 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -349,51 +349,70 @@ update_preference (struct PreferenceClient *c, struct PreferencePeer *p, | |||
349 | static void | 349 | static void |
350 | preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 350 | preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
351 | { | 351 | { |
352 | struct PreferencePeer *p; | ||
353 | struct PreferenceClient *cur_client; | ||
352 | int i; | 354 | int i; |
353 | int values_to_update; | 355 | int values_to_update; |
354 | double backup; | 356 | double backup; |
355 | struct PreferencePeer *p; | 357 | |
356 | struct PreferenceClient *pc; | ||
357 | aging_task = GNUNET_SCHEDULER_NO_TASK; | 358 | aging_task = GNUNET_SCHEDULER_NO_TASK; |
358 | GNUNET_break (0); | ||
359 | values_to_update = 0; | 359 | values_to_update = 0; |
360 | for (pc = pc_head; NULL != pc; pc =pc->next); | 360 | cur_client = NULL; |
361 | |||
362 | /* | ||
363 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
364 | "Before for: head: %08x cur_client %08x \n", pc_head, cur_client); | ||
365 | */ | ||
366 | |||
367 | //for (cur_client = pc_head; NULL != cur_client; cur_client = cur_client->next); | ||
368 | cur_client = pc_head; | ||
369 | while (NULL != cur_client) | ||
361 | { | 370 | { |
362 | GNUNET_break (0); | 371 | /* |
363 | for (p = pc->p_head; NULL != p; p = p->next) | 372 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
373 | "Aging client head: %p cur_client %p\n", pc_head, cur_client); | ||
374 | */ | ||
375 | for (p = cur_client->p_head; NULL != p; p = p->next) | ||
364 | { | 376 | { |
365 | GNUNET_break (0); | ||
366 | /* Aging absolute values: */ | 377 | /* Aging absolute values: */ |
367 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 378 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
368 | { | 379 | { |
369 | GNUNET_break (0); | ||
370 | if (0 == GNUNET_TIME_absolute_get_remaining(p->next_aging[i]).rel_value_us) | 380 | if (0 == GNUNET_TIME_absolute_get_remaining(p->next_aging[i]).rel_value_us) |
371 | { | 381 | { |
372 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Aging preferences for peer `%s'\n", | 382 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Aging preference for peer `%s'\n", |
373 | GNUNET_i2s (&p->id)); | 383 | GNUNET_i2s (&p->id)); |
384 | backup = p->f_abs[i]; | ||
385 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) | ||
386 | p->f_abs[i] *= PREF_AGING_FACTOR; | ||
387 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) | ||
388 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; | ||
389 | if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE) && (backup != p->f_abs[i])) | ||
390 | { | ||
391 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
392 | "Aged preference for peer `%s' from %.3f to %.3f\n", | ||
393 | GNUNET_i2s (&p->id), backup, p->f_abs[i]); | ||
394 | recalculate_rel_preferences (p->client, p, i); | ||
395 | p->next_aging[i] = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | ||
396 | PREF_AGING_INTERVAL); | ||
397 | values_to_update ++; | ||
398 | } | ||
374 | } | 399 | } |
400 | } | ||
401 | } | ||
402 | |||
403 | cur_client = cur_client->next; | ||
404 | } | ||
375 | 405 | ||
376 | backup = p->f_abs[i]; | ||
377 | if (p->f_abs[i] > DEFAULT_ABS_PREFERENCE) | ||
378 | p->f_abs[i] *= PREF_AGING_FACTOR; | ||
379 | if (p->f_abs[i] <= DEFAULT_ABS_PREFERENCE + PREF_EPSILON) | ||
380 | p->f_abs[i] = DEFAULT_ABS_PREFERENCE; | ||
381 | if ((p->f_abs[i] != DEFAULT_ABS_PREFERENCE) && (backup != p->f_abs[i])) | ||
382 | { | ||
383 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
384 | "Aged preference for peer `%s' from %.3f to %.3f\n", | ||
385 | GNUNET_i2s (&p->id), backup, p->f_abs[i]); | ||
386 | recalculate_rel_preferences (p->client, p, i); | ||
387 | p->next_aging[i] = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | ||
388 | PREF_AGING_INTERVAL); | ||
389 | values_to_update ++; | ||
390 | } | ||
391 | } /* preferences */ | ||
392 | } /* end: p */ | ||
393 | } /* end: pc_head */ | ||
394 | if (values_to_update > 0) | 406 | if (values_to_update > 0) |
407 | { | ||
408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
409 | "Rescheduling aging task due to %u elements to age\n", values_to_update); | ||
395 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, | 410 | aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, |
396 | &preference_aging, NULL); | 411 | &preference_aging, NULL); |
412 | } | ||
413 | else | ||
414 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
415 | "No values to age left, not rescheduling aging task\n"); | ||
397 | 416 | ||
398 | } | 417 | } |
399 | 418 | ||
@@ -440,7 +459,9 @@ GAS_normalization_normalize_preference (void *src, | |||
440 | { | 459 | { |
441 | c_cur = GNUNET_malloc (sizeof (struct PreferenceClient)); | 460 | c_cur = GNUNET_malloc (sizeof (struct PreferenceClient)); |
442 | c_cur->client = src; | 461 | c_cur->client = src; |
443 | GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, c_cur); | 462 | GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, c_cur); |
463 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
464 | "Adding new client %p \n", c_cur); | ||
444 | } | 465 | } |
445 | 466 | ||
446 | /* Find entry for peer */ | 467 | /* Find entry for peer */ |
@@ -461,6 +482,7 @@ GAS_normalization_normalize_preference (void *src, | |||
461 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; | 482 | p_cur->f_abs[i] = DEFAULT_ABS_PREFERENCE; |
462 | /* Default value per peer relative preference for a quality: 1.0 */ | 483 | /* Default value per peer relative preference for a quality: 1.0 */ |
463 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; | 484 | p_cur->f_rel[i] = DEFAULT_REL_PREFERENCE; |
485 | p_cur->next_aging[i] = GNUNET_TIME_UNIT_FOREVER_ABS; | ||
464 | } | 486 | } |
465 | GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); | 487 | GNUNET_CONTAINER_DLL_insert(c_cur->p_head, c_cur->p_tail, p_cur); |
466 | } | 488 | } |
@@ -822,6 +844,9 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | |||
822 | prop_ch_cb = property_ch_cb; | 844 | prop_ch_cb = property_ch_cb; |
823 | prop_ch_cb_cls = pref_ch_cb_cls; | 845 | prop_ch_cb_cls = pref_ch_cb_cls; |
824 | 846 | ||
847 | pc_head = NULL; | ||
848 | pc_tail = NULL; | ||
849 | |||
825 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 850 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
826 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 851 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
827 | aging_task = GNUNET_SCHEDULER_NO_TASK; | 852 | aging_task = GNUNET_SCHEDULER_NO_TASK; |