diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-17 16:44:03 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-01-17 16:44:03 +0000 |
commit | 53c1a5bf753575d9ca1c2134e0e99fa38b29a552 (patch) | |
tree | 869fbd8c66fba2ba3a0fb62ded9e5cdf87937efc /src/ats | |
parent | e2969268a9ff5fc99c65052c9fb92c545c9f3924 (diff) | |
download | gnunet-53c1a5bf753575d9ca1c2134e0e99fa38b29a552.tar.gz gnunet-53c1a5bf753575d9ca1c2134e0e99fa38b29a552.zip |
- changes
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 49 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 12 |
2 files changed, 60 insertions, 1 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 90ceea01d..452d782f8 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -33,6 +33,8 @@ | |||
33 | #include "glpk.h" | 33 | #include "glpk.h" |
34 | #endif | 34 | #endif |
35 | 35 | ||
36 | #define DEBUG_ATS GNUNET_YES | ||
37 | |||
36 | /** | 38 | /** |
37 | * Translate glpk solver error codes to text | 39 | * Translate glpk solver error codes to text |
38 | * @param retcode return code | 40 | * @param retcode return code |
@@ -165,7 +167,6 @@ mlp_term_hook (void *info, const char *s) | |||
165 | * @param mlp the MLP handle | 167 | * @param mlp the MLP handle |
166 | * @return GNUNET_OK or GNUNET_SYSERR | 168 | * @return GNUNET_OK or GNUNET_SYSERR |
167 | */ | 169 | */ |
168 | |||
169 | static int | 170 | static int |
170 | mlp_create_problem (struct GAS_MLP_Handle *mlp) | 171 | mlp_create_problem (struct GAS_MLP_Handle *mlp) |
171 | { | 172 | { |
@@ -395,6 +396,26 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) | |||
395 | return GNUNET_OK; | 396 | return GNUNET_OK; |
396 | } | 397 | } |
397 | 398 | ||
399 | int mlp_solve_problem (struct GAS_MLP_Handle *mlp); | ||
400 | |||
401 | static void | ||
402 | mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
403 | { | ||
404 | struct GAS_MLP_Handle *mlp = cls; | ||
405 | |||
406 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; | ||
407 | |||
408 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
409 | return; | ||
410 | |||
411 | #if DEBUG_ATS | ||
412 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); | ||
413 | #endif | ||
414 | if (mlp->addr_in_problem != 0) | ||
415 | mlp_solve_problem(mlp); | ||
416 | } | ||
417 | |||
418 | |||
398 | /** | 419 | /** |
399 | * Solves the MLP problem | 420 | * Solves the MLP problem |
400 | * | 421 | * |
@@ -409,6 +430,12 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
409 | res = mlp_solve_lp_problem (mlp); | 430 | res = mlp_solve_lp_problem (mlp); |
410 | if (res == GNUNET_OK) | 431 | if (res == GNUNET_OK) |
411 | res = mlp_solve_mlp_problem (mlp); | 432 | res = mlp_solve_mlp_problem (mlp); |
433 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) | ||
434 | { | ||
435 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); | ||
436 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; | ||
437 | } | ||
438 | mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); | ||
412 | return res; | 439 | return res; |
413 | } | 440 | } |
414 | 441 | ||
@@ -434,6 +461,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
434 | long long unsigned int tmp; | 461 | long long unsigned int tmp; |
435 | unsigned int b_min; | 462 | unsigned int b_min; |
436 | unsigned int n_min; | 463 | unsigned int n_min; |
464 | struct GNUNET_TIME_Relative i_exec; | ||
437 | 465 | ||
438 | /* Init GLPK environment */ | 466 | /* Init GLPK environment */ |
439 | GNUNET_assert (glp_init_env() == 0); | 467 | GNUNET_assert (glp_init_env() == 0); |
@@ -514,6 +542,14 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
514 | else | 542 | else |
515 | n_min = 4; | 543 | n_min = 4; |
516 | 544 | ||
545 | /* Get minimum number of connections from configuration */ | ||
546 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg, "ats", | ||
547 | "ATS_EXEC_INTERVAL", | ||
548 | &i_exec)) | ||
549 | mlp->exec_interval = i_exec; | ||
550 | else | ||
551 | mlp->exec_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30); | ||
552 | |||
517 | mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; | 553 | mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; |
518 | mlp->max_iterations = max_iterations; | 554 | mlp->max_iterations = max_iterations; |
519 | mlp->max_exec_duration = max_duration; | 555 | mlp->max_exec_duration = max_duration; |
@@ -610,6 +646,9 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
610 | glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); | 646 | glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); |
611 | 647 | ||
612 | /* Add */ | 648 | /* Add */ |
649 | |||
650 | |||
651 | mlp->addr_in_problem ++; | ||
613 | } | 652 | } |
614 | else | 653 | else |
615 | new = GNUNET_NO; | 654 | new = GNUNET_NO; |
@@ -641,6 +680,8 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
641 | { | 680 | { |
642 | GNUNET_free (address->mlp_information); | 681 | GNUNET_free (address->mlp_information); |
643 | address->mlp_information = NULL; | 682 | address->mlp_information = NULL; |
683 | |||
684 | mlp->addr_in_problem --; | ||
644 | } | 685 | } |
645 | 686 | ||
646 | /* Update problem */ | 687 | /* Update problem */ |
@@ -670,6 +711,12 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CON | |||
670 | void | 711 | void |
671 | GAS_mlp_done (struct GAS_MLP_Handle *mlp) | 712 | GAS_mlp_done (struct GAS_MLP_Handle *mlp) |
672 | { | 713 | { |
714 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) | ||
715 | { | ||
716 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); | ||
717 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; | ||
718 | } | ||
719 | |||
673 | if (mlp != NULL) | 720 | if (mlp != NULL) |
674 | glp_delete_prob(mlp->prob); | 721 | glp_delete_prob(mlp->prob); |
675 | 722 | ||
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 4b4b93319..f72cb7c23 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -70,6 +70,16 @@ struct GAS_MLP_Handle | |||
70 | glp_iocp control_param_mlp; | 70 | glp_iocp control_param_mlp; |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Solves the task in an regular interval | ||
74 | */ | ||
75 | GNUNET_SCHEDULER_TaskIdentifier mlp_task; | ||
76 | |||
77 | /** | ||
78 | * Interval between scheduled problem solving | ||
79 | */ | ||
80 | struct GNUNET_TIME_Relative exec_interval; | ||
81 | |||
82 | /** | ||
73 | * Maximum execution time per problem solving | 83 | * Maximum execution time per problem solving |
74 | */ | 84 | */ |
75 | struct GNUNET_TIME_Relative max_exec_duration; | 85 | struct GNUNET_TIME_Relative max_exec_duration; |
@@ -121,6 +131,8 @@ struct GAS_MLP_Handle | |||
121 | */ | 131 | */ |
122 | uint64_t mlp_total_duration; | 132 | uint64_t mlp_total_duration; |
123 | 133 | ||
134 | unsigned int addr_in_problem; | ||
135 | |||
124 | /* Information about the problem */ | 136 | /* Information about the problem */ |
125 | 137 | ||
126 | 138 | ||