}
-struct SolveContext
-{
- struct GNUNET_TIME_Relative lp_duration;
- struct GNUNET_TIME_Relative mlp_duration;
-};
-
-
/**
* Solves the LP problem
*
* @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
*/
static int
-mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx)
+mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx)
{
int res;
struct GNUNET_TIME_Relative duration;
* @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
*/
int
-mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx)
+mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx)
{
int res;
struct GNUNET_TIME_Relative duration;
return GNUNET_OK;
}
-int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp);
+int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx);
static void
mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
struct GAS_MLP_Handle *mlp = cls;
+ struct GAS_MLP_SolutionContext ctx;
mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK;
if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
-
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n");
if (mlp->addr_in_problem != 0)
- GAS_mlp_solve_problem(mlp);
+ GAS_mlp_solve_problem(mlp, &ctx);
}
/**
* @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure
*/
int
-GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp)
+GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx)
{
int res;
- struct SolveContext s_ctx;
mlp->last_execution = GNUNET_TIME_absolute_get ();
+ ctx->lp_result = GNUNET_SYSERR;
+ ctx->mlp_result = GNUNET_SYSERR;
+ ctx->lp_duration = GNUNET_TIME_relative_get_forever();
+ ctx->mlp_duration = GNUNET_TIME_relative_get_forever();
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve LP problem\n");
#if WRITE_MLP
char * name;
GNUNET_free (name);
# endif
- res = mlp_solve_lp_problem (mlp, &s_ctx);
+ res = mlp_solve_lp_problem (mlp, ctx);
+ ctx->lp_result = res;
if (res != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "LP Problem solving failed\n");
return GNUNET_SYSERR;
}
+
#if WRITE_MLP
GNUNET_asprintf(&name, "problem_%i_lp_solution", i);
glp_print_sol (mlp->prob, name);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve MLP problem\n");
- res = mlp_solve_mlp_problem (mlp, &s_ctx);
+ res = mlp_solve_mlp_problem (mlp, ctx);
+ ctx->mlp_result = res;
if (res != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP Problem solving failed\n");
# endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved %s (LP duration %llu / MLP duration %llu)\n",
- (GNUNET_OK == res) ? "successfully" : "failed", s_ctx.lp_duration, s_ctx.mlp_duration);
+ (GNUNET_OK == res) ? "successfully" : "failed", ctx->lp_duration.rel_value, ctx->mlp_duration.rel_value);
/* Process result */
struct ATS_Peer *p = NULL;
struct ATS_Address *a = NULL;
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);
+ //mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp);
return res;
}
c3 ++;
}
}
- if (c3 > 0)
+ if ((c3 > 0) && (avg > 0))
/* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
mlpi->q_averaged[c] = (double) c3 / avg;
else
c3 ++;
}
}
- if (c3 > 0)
+ if ((c3 > 0) && (avg > 0))
/* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/
mlpi->q_averaged[c] = (double) c3 / avg;
else
{
int new;
struct MLP_information *mlpi;
+ struct GAS_MLP_SolutionContext ctx;
GNUNET_STATISTICS_update (mlp->stats, "# MLP address updates", 1, GNUNET_NO);
mlp->presolver_required = GNUNET_YES;
}
if (mlp->auto_solve == GNUNET_YES)
- GAS_mlp_solve_problem (mlp);
+ GAS_mlp_solve_problem (mlp, &ctx);
}
/**
GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address)
{
GNUNET_STATISTICS_update (mlp->stats,"# LP address deletions", 1, GNUNET_NO);
+ struct GAS_MLP_SolutionContext ctx;
/* Free resources */
if (address->mlp_information != NULL)
/* Recalculate */
mlp->presolver_required = GNUNET_YES;
if (mlp->auto_solve == GNUNET_YES)
- GAS_mlp_solve_problem (mlp);
+ GAS_mlp_solve_problem (mlp, &ctx);
}
}
static int ret;
-struct GNUNET_STATISTICS_Handle * stats;
-
struct GNUNET_CONTAINER_MultiHashMap * amap;
struct GAS_MLP_Handle *mlp;
-struct GNUNET_STATISTICS_Handle * stats;
-struct GNUNET_OS_Process *stats_proc;
+
GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
GNUNET_CONTAINER_multihashmap_destroy(amap);
GNUNET_free_non_null (a);
GNUNET_free_non_null (p);
- if (stats != NULL)
- GNUNET_STATISTICS_destroy (stats,GNUNET_NO);
- if (NULL != stats_proc)
- {
- if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM))
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
- if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK)
- GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
- GNUNET_OS_process_close (stats_proc);
- stats_proc = NULL;
- }
}
-int stat_lp_it (void *cls, const char *subsystem,
- const char *name, uint64_t value,
- int is_persistent)
-{
- static long long unsigned lp_time;
- static long long unsigned mlp_time;
- static long long unsigned lp_time_set;
- static long long unsigned mlp_time_set;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received: `%s' : %u \n", name, value);
-
- if (0 == strcmp (name, "# LP execution time (ms)"))
- {
- lp_time = value;
- lp_time_set = GNUNET_YES;
- }
- if (0 == strcmp (name, "# MLP execution time (ms)"))
- {
- mlp_time = value;
- mlp_time_set = GNUNET_YES;
- }
- if ((GNUNET_YES == lp_time_set) && (GNUNET_YES == mlp_time_set))
- {
- if (GNUNET_YES == numeric)
- printf ("%u;%u;%llu;%llu\n",peers, addresses, lp_time, mlp_time);
- if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
- GNUNET_SCHEDULER_cancel(shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
- }
- return GNUNET_OK;
-}
-
-int stat_ready_it (void *cls, const char *subsystem,
- const char *name, uint64_t value,
- int is_persistent)
+static void
+check (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *cfg)
{
unsigned int c = 0;
unsigned int c2 = 0;
unsigned int ca = 0;
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics service ready\n");
-
- GNUNET_STATISTICS_watch (stats, "ats", "# LP execution time (ms)", &stat_lp_it, NULL);
- GNUNET_STATISTICS_watch (stats, "ats", "# MLP execution time (ms)", &stat_lp_it, NULL);
+#if !HAVE_LIBGLPK
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
+ ret = 1;
+ return;
+#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
- mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+ mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
if (NULL == mlp)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n");
if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
GNUNET_SCHEDULER_cancel(shutdown_task);
shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- return GNUNET_NO;
}
if (peers == 0)
for (c=0; c < peers; c++)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c);
- GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey);
+ GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, &p[c].id.hashPubKey);
for (c2=0; c2 < addresses; c2++)
{
a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
- a[ca].ats[0].value = 20;
+ a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10);
a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE;
- a[ca].ats[1].value = 2;
+ a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
a[ca].ats_count = 2;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca);
GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
ca++;
}
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
GNUNET_assert (peers == mlp->c_p);
GNUNET_assert (peers * addresses == mlp->addr_in_problem);
/* Solving the problem */
- if (GNUNET_OK == GAS_mlp_solve_problem(mlp))
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n");
- else
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses);
-
- GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, "Waiting for statistics\n");
-
+ struct GAS_MLP_SolutionContext ctx;
- return GNUNET_OK;
-}
-
-static void
-check (void *cls, char *const *args, const char *cfgfile,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
-#if !HAVE_LIBGLPK
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
- ret = 1;
- return;
-#endif
-
- stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics",
- "gnunet-service-statistics", NULL);
-
- if (NULL == stats_proc)
+ if (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n");
- ret = 1;
- if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
- GNUNET_SCHEDULER_cancel(shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- return;
- }
+ GNUNET_assert (GNUNET_OK == ctx.lp_result);
+ GNUNET_assert (GNUNET_OK == ctx.mlp_result);
+ if (GNUNET_YES == numeric)
+ printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value);
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem solved successfully (LP: %llu ms / MLP: %llu ms)\n", ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value);
- stats = GNUNET_STATISTICS_create("ats", cfg);
+ }
+ else
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses);
+ if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
+ GNUNET_SCHEDULER_cancel(shutdown_task);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
- GNUNET_STATISTICS_watch (stats, "ats", "watch", &stat_ready_it, (void *) cfg);
- GNUNET_STATISTICS_set(stats, "watch", 1, GNUNET_NO);
- return;
}