From 53c1a5bf753575d9ca1c2134e0e99fa38b29a552 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Tue, 17 Jan 2012 16:44:03 +0000 Subject: [PATCH] - changes --- src/ats/gnunet-service-ats_addresses_mlp.c | 49 +++++++++++++++++++++- src/ats/gnunet-service-ats_addresses_mlp.h | 12 ++++++ 2 files changed, 60 insertions(+), 1 deletion(-) 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 @@ #include "glpk.h" #endif +#define DEBUG_ATS GNUNET_YES + /** * Translate glpk solver error codes to text * @param retcode return code @@ -165,7 +167,6 @@ mlp_term_hook (void *info, const char *s) * @param mlp the MLP handle * @return GNUNET_OK or GNUNET_SYSERR */ - static int mlp_create_problem (struct GAS_MLP_Handle *mlp) { @@ -395,6 +396,26 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp) return GNUNET_OK; } +int mlp_solve_problem (struct GAS_MLP_Handle *mlp); + +static void +mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct GAS_MLP_Handle *mlp = cls; + + mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; + + if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) + return; + +#if DEBUG_ATS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); +#endif + if (mlp->addr_in_problem != 0) + mlp_solve_problem(mlp); +} + + /** * Solves the MLP problem * @@ -409,6 +430,12 @@ mlp_solve_problem (struct GAS_MLP_Handle *mlp) res = mlp_solve_lp_problem (mlp); if (res == GNUNET_OK) res = mlp_solve_mlp_problem (mlp); + if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel(mlp->mlp_task); + mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; + } + mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); return res; } @@ -434,6 +461,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, long long unsigned int tmp; unsigned int b_min; unsigned int n_min; + struct GNUNET_TIME_Relative i_exec; /* Init GLPK environment */ GNUNET_assert (glp_init_env() == 0); @@ -514,6 +542,14 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, else n_min = 4; + /* Get minimum number of connections from configuration */ + if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (cfg, "ats", + "ATS_EXEC_INTERVAL", + &i_exec)) + mlp->exec_interval = i_exec; + else + mlp->exec_interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30); + mlp->stats = (struct GNUNET_STATISTICS_Handle *) stats; mlp->max_iterations = max_iterations; mlp->max_exec_duration = max_duration; @@ -610,6 +646,9 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult glp_set_obj_coef (mlp->prob, mlpi->c_n, 0); /* Add */ + + + mlp->addr_in_problem ++; } else new = GNUNET_NO; @@ -641,6 +680,8 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult { GNUNET_free (address->mlp_information); address->mlp_information = NULL; + + mlp->addr_in_problem --; } /* Update problem */ @@ -670,6 +711,12 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, struct GNUNET_CON void GAS_mlp_done (struct GAS_MLP_Handle *mlp) { + if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) + { + GNUNET_SCHEDULER_cancel(mlp->mlp_task); + mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; + } + if (mlp != NULL) glp_delete_prob(mlp->prob); 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 @@ -69,6 +69,16 @@ struct GAS_MLP_Handle */ glp_iocp control_param_mlp; + /** + * Solves the task in an regular interval + */ + GNUNET_SCHEDULER_TaskIdentifier mlp_task; + + /** + * Interval between scheduled problem solving + */ + struct GNUNET_TIME_Relative exec_interval; + /** * Maximum execution time per problem solving */ @@ -121,6 +131,8 @@ struct GAS_MLP_Handle */ uint64_t mlp_total_duration; + unsigned int addr_in_problem; + /* Information about the problem */ -- 2.25.1