diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-18 15:49:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-18 15:49:57 +0000 |
commit | 8f3820b6244a0ac7fa28956413e17a6d3feb860c (patch) | |
tree | 592d6cdbf4f1f3239a2b834754ccfe056076eba9 /src/ats/gnunet-service-ats_addresses_mlp.c | |
parent | cc8cf22281f1f9d77fb498664ad8f847dccee17e (diff) | |
download | gnunet-8f3820b6244a0ac7fa28956413e17a6d3feb860c.tar.gz gnunet-8f3820b6244a0ac7fa28956413e17a6d3feb860c.zip |
- remove statistics use return values
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses_mlp.c')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index dfb62e665..85113ea8e 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -807,13 +807,6 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas | |||
807 | } | 807 | } |
808 | 808 | ||
809 | 809 | ||
810 | struct SolveContext | ||
811 | { | ||
812 | struct GNUNET_TIME_Relative lp_duration; | ||
813 | struct GNUNET_TIME_Relative mlp_duration; | ||
814 | }; | ||
815 | |||
816 | |||
817 | /** | 810 | /** |
818 | * Solves the LP problem | 811 | * Solves the LP problem |
819 | * | 812 | * |
@@ -822,7 +815,7 @@ struct SolveContext | |||
822 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | 815 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure |
823 | */ | 816 | */ |
824 | static int | 817 | static int |
825 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) | 818 | mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx) |
826 | { | 819 | { |
827 | int res; | 820 | int res; |
828 | struct GNUNET_TIME_Relative duration; | 821 | struct GNUNET_TIME_Relative duration; |
@@ -916,7 +909,7 @@ lp_solv: | |||
916 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | 909 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure |
917 | */ | 910 | */ |
918 | int | 911 | int |
919 | mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) | 912 | mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx) |
920 | { | 913 | { |
921 | int res; | 914 | int res; |
922 | struct GNUNET_TIME_Relative duration; | 915 | struct GNUNET_TIME_Relative duration; |
@@ -981,23 +974,23 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) | |||
981 | return GNUNET_OK; | 974 | return GNUNET_OK; |
982 | } | 975 | } |
983 | 976 | ||
984 | int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp); | 977 | int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx); |
985 | 978 | ||
986 | static void | 979 | static void |
987 | mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 980 | mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
988 | { | 981 | { |
989 | struct GAS_MLP_Handle *mlp = cls; | 982 | struct GAS_MLP_Handle *mlp = cls; |
983 | struct GAS_MLP_SolutionContext ctx; | ||
990 | 984 | ||
991 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; | 985 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; |
992 | 986 | ||
993 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 987 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
994 | return; | 988 | return; |
995 | 989 | ||
996 | |||
997 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); | 990 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); |
998 | 991 | ||
999 | if (mlp->addr_in_problem != 0) | 992 | if (mlp->addr_in_problem != 0) |
1000 | GAS_mlp_solve_problem(mlp); | 993 | GAS_mlp_solve_problem(mlp, &ctx); |
1001 | } | 994 | } |
1002 | 995 | ||
1003 | /** | 996 | /** |
@@ -1007,12 +1000,16 @@ mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1007 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure | 1000 | * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure |
1008 | */ | 1001 | */ |
1009 | int | 1002 | int |
1010 | GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | 1003 | GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx) |
1011 | { | 1004 | { |
1012 | int res; | 1005 | int res; |
1013 | struct SolveContext s_ctx; | ||
1014 | mlp->last_execution = GNUNET_TIME_absolute_get (); | 1006 | mlp->last_execution = GNUNET_TIME_absolute_get (); |
1015 | 1007 | ||
1008 | ctx->lp_result = GNUNET_SYSERR; | ||
1009 | ctx->mlp_result = GNUNET_SYSERR; | ||
1010 | ctx->lp_duration = GNUNET_TIME_relative_get_forever(); | ||
1011 | ctx->mlp_duration = GNUNET_TIME_relative_get_forever(); | ||
1012 | |||
1016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve LP problem\n"); | 1013 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve LP problem\n"); |
1017 | #if WRITE_MLP | 1014 | #if WRITE_MLP |
1018 | char * name; | 1015 | char * name; |
@@ -1023,12 +1020,14 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
1023 | GNUNET_free (name); | 1020 | GNUNET_free (name); |
1024 | # endif | 1021 | # endif |
1025 | 1022 | ||
1026 | res = mlp_solve_lp_problem (mlp, &s_ctx); | 1023 | res = mlp_solve_lp_problem (mlp, ctx); |
1024 | ctx->lp_result = res; | ||
1027 | if (res != GNUNET_OK) | 1025 | if (res != GNUNET_OK) |
1028 | { | 1026 | { |
1029 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "LP Problem solving failed\n"); | 1027 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "LP Problem solving failed\n"); |
1030 | return GNUNET_SYSERR; | 1028 | return GNUNET_SYSERR; |
1031 | } | 1029 | } |
1030 | |||
1032 | #if WRITE_MLP | 1031 | #if WRITE_MLP |
1033 | GNUNET_asprintf(&name, "problem_%i_lp_solution", i); | 1032 | GNUNET_asprintf(&name, "problem_%i_lp_solution", i); |
1034 | glp_print_sol (mlp->prob, name); | 1033 | glp_print_sol (mlp->prob, name); |
@@ -1037,7 +1036,8 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
1037 | 1036 | ||
1038 | 1037 | ||
1039 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve MLP problem\n"); | 1038 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve MLP problem\n"); |
1040 | res = mlp_solve_mlp_problem (mlp, &s_ctx); | 1039 | res = mlp_solve_mlp_problem (mlp, ctx); |
1040 | ctx->mlp_result = res; | ||
1041 | if (res != GNUNET_OK) | 1041 | if (res != GNUNET_OK) |
1042 | { | 1042 | { |
1043 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP Problem solving failed\n"); | 1043 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP Problem solving failed\n"); |
@@ -1050,7 +1050,7 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
1050 | # endif | 1050 | # endif |
1051 | 1051 | ||
1052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved %s (LP duration %llu / MLP duration %llu)\n", | 1052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved %s (LP duration %llu / MLP duration %llu)\n", |
1053 | (GNUNET_OK == res) ? "successfully" : "failed", s_ctx.lp_duration, s_ctx.mlp_duration); | 1053 | (GNUNET_OK == res) ? "successfully" : "failed", ctx->lp_duration.rel_value, ctx->mlp_duration.rel_value); |
1054 | /* Process result */ | 1054 | /* Process result */ |
1055 | struct ATS_Peer *p = NULL; | 1055 | struct ATS_Peer *p = NULL; |
1056 | struct ATS_Address *a = NULL; | 1056 | struct ATS_Address *a = NULL; |
@@ -1085,7 +1085,7 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
1085 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); | 1085 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); |
1086 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; | 1086 | mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; |
1087 | } | 1087 | } |
1088 | mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); | 1088 | //mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); |
1089 | return res; | 1089 | return res; |
1090 | } | 1090 | } |
1091 | 1091 | ||
@@ -1427,7 +1427,7 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) | |||
1427 | c3 ++; | 1427 | c3 ++; |
1428 | } | 1428 | } |
1429 | } | 1429 | } |
1430 | if (c3 > 0) | 1430 | if ((c3 > 0) && (avg > 0)) |
1431 | /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ | 1431 | /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ |
1432 | mlpi->q_averaged[c] = (double) c3 / avg; | 1432 | mlpi->q_averaged[c] = (double) c3 / avg; |
1433 | else | 1433 | else |
@@ -1452,7 +1452,7 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) | |||
1452 | c3 ++; | 1452 | c3 ++; |
1453 | } | 1453 | } |
1454 | } | 1454 | } |
1455 | if (c3 > 0) | 1455 | if ((c3 > 0) && (avg > 0)) |
1456 | /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ | 1456 | /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ |
1457 | mlpi->q_averaged[c] = (double) c3 / avg; | 1457 | mlpi->q_averaged[c] = (double) c3 / avg; |
1458 | else | 1458 | else |
@@ -1540,6 +1540,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1540 | { | 1540 | { |
1541 | int new; | 1541 | int new; |
1542 | struct MLP_information *mlpi; | 1542 | struct MLP_information *mlpi; |
1543 | struct GAS_MLP_SolutionContext ctx; | ||
1543 | 1544 | ||
1544 | GNUNET_STATISTICS_update (mlp->stats, "# MLP address updates", 1, GNUNET_NO); | 1545 | GNUNET_STATISTICS_update (mlp->stats, "# MLP address updates", 1, GNUNET_NO); |
1545 | 1546 | ||
@@ -1624,7 +1625,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1624 | mlp->presolver_required = GNUNET_YES; | 1625 | mlp->presolver_required = GNUNET_YES; |
1625 | } | 1626 | } |
1626 | if (mlp->auto_solve == GNUNET_YES) | 1627 | if (mlp->auto_solve == GNUNET_YES) |
1627 | GAS_mlp_solve_problem (mlp); | 1628 | GAS_mlp_solve_problem (mlp, &ctx); |
1628 | } | 1629 | } |
1629 | 1630 | ||
1630 | /** | 1631 | /** |
@@ -1641,6 +1642,7 @@ void | |||
1641 | GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) | 1642 | GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) |
1642 | { | 1643 | { |
1643 | GNUNET_STATISTICS_update (mlp->stats,"# LP address deletions", 1, GNUNET_NO); | 1644 | GNUNET_STATISTICS_update (mlp->stats,"# LP address deletions", 1, GNUNET_NO); |
1645 | struct GAS_MLP_SolutionContext ctx; | ||
1644 | 1646 | ||
1645 | /* Free resources */ | 1647 | /* Free resources */ |
1646 | if (address->mlp_information != NULL) | 1648 | if (address->mlp_information != NULL) |
@@ -1682,7 +1684,7 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1682 | /* Recalculate */ | 1684 | /* Recalculate */ |
1683 | mlp->presolver_required = GNUNET_YES; | 1685 | mlp->presolver_required = GNUNET_YES; |
1684 | if (mlp->auto_solve == GNUNET_YES) | 1686 | if (mlp->auto_solve == GNUNET_YES) |
1685 | GAS_mlp_solve_problem (mlp); | 1687 | GAS_mlp_solve_problem (mlp, &ctx); |
1686 | } | 1688 | } |
1687 | } | 1689 | } |
1688 | 1690 | ||