From 25a6082f9f63a999b5ce35c7fe55908988c2486a Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Fri, 8 Jul 2011 12:06:31 +0000 Subject: [PATCH] more changes to ATS it's running, minor changes have to completed --- src/transport/gnunet-service-transport.c | 300 +++++- src/transport/test_transport_ats.c | 31 +- src/transport/transport_ats.c | 1055 +++++++--------------- src/transport/transport_ats.h | 175 +++- 4 files changed, 754 insertions(+), 807 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 73239c241..fdd86ac3e 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -934,6 +934,19 @@ static int shutdown_in_progress; */ static struct ATS_Handle *ats; +/** + * Time of last ats execution + */ +struct GNUNET_TIME_Absolute last_ats_execution; +/** + * Minimum interval between two ATS executions + */ +struct GNUNET_TIME_Relative ats_minimum_interval; +/** + * Regular interval when ATS execution is triggered + */ +struct GNUNET_TIME_Relative ats_regular_interval; + /** * The peer specified by the given neighbour has timed-out or a plugin * has disconnected. We may either need to do nothing (other plugins @@ -2284,10 +2297,11 @@ try_fast_reconnect (struct TransportPlugin *p, /* No reconnect, signal disconnect instead! */ #if DEBUG_TRANSPORT +#endif GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&nl->id), "try_fast_reconnect"); -#endif + GNUNET_STATISTICS_update (stats, gettext_noop ("# disconnects due to try_fast_reconnect"), 1, @@ -2416,11 +2430,18 @@ plugin_env_session_end (void *cls, gettext_noop ("# disconnects due to missing pong"), 1, GNUNET_NO); + /* FIXME this is never true?! See: line 2416*/ if (GNUNET_YES == pos->connected) disconnect_neighbour (nl, GNUNET_YES); } return; } + + GNUNET_STATISTICS_update (stats, + gettext_noop ("# connected addresses"), + -1, + GNUNET_NO); + /* was inbound connection, free 'pos' */ if (prev == NULL) rl->addresses = pos->next; @@ -2607,7 +2628,7 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer, if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO)) { ats_modify_problem_state(ats, ATS_MODIFIED); - ats_calculate_bandwidth_distribution (ats, stats, neighbours); + ats_calculate_bandwidth_distribution (ats, stats); } @@ -2656,7 +2677,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer) if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO)) { ats_modify_problem_state(ats, ATS_MODIFIED); - ats_calculate_bandwidth_distribution (ats, stats, neighbours); + ats_calculate_bandwidth_distribution (ats, stats); } cpos = clients; @@ -4820,7 +4841,7 @@ disconnect_neighbour (struct NeighbourList *n, int check) if (GNUNET_YES == n->received_pong) notify_clients_disconnect (&n->id); - ats_modify_problem_state(ats, ATS_QUALITY_COST_UPDATED); + ats_modify_problem_state(ats, ATS_MODIFIED); /* clean up all plugins, cancel connections and pending transmissions */ while (NULL != (rpos = n->plugins)) @@ -6006,13 +6027,12 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) GNUNET_CONTAINER_multihashmap_destroy (validation_map); validation_map = NULL; + if (ats_task != GNUNET_SCHEDULER_NO_TASK) { GNUNET_SCHEDULER_cancel(ats_task); ats_task = GNUNET_SCHEDULER_NO_TASK; } - - if (ats != NULL) ats_shutdown (ats); @@ -6058,9 +6078,127 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } +void ats_result_cb () +{ + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS Result callback\n"); +} + + +void create_ats_information ( struct ATS_peer **p, + int * c_p, + struct ATS_mechanism ** m, + int * c_m ) +{ +#if VERBOSE_ATS + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "ATS requires clean address information\n"); +#endif + struct ATS_mechanism * mechanisms; + struct ATS_peer *peers; + + int connected_addresses = 0; + int c_peers = 0; + int c_mechs = 0; + struct NeighbourList *next = neighbours; + + while (next!=NULL) + { + int found_addresses = GNUNET_NO; + struct ReadyList *r_next = next->plugins; + while (r_next != NULL) + { + struct ForeignAddressList * a_next = r_next->addresses; + while (a_next != NULL) + { + c_mechs++; + found_addresses = GNUNET_YES; + a_next = a_next->next; + } + r_next = r_next->next; + } + if (found_addresses) c_peers++; + next = next->next; + } + +#if VERBOSE_ATS + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Found %u peers with % u transport mechanisms\n", c_peers, c_mechs); +#endif + + if ((c_peers == 0) && (c_mechs == 0)) + { + peers = NULL; + (*c_p) = 0; + mechanisms = NULL; + (*c_m) = 0; + return; + } + + mechanisms = GNUNET_malloc((1+c_mechs) * sizeof (struct ATS_mechanism)); + peers = GNUNET_malloc((1+c_peers) * sizeof (struct ATS_peer)); + + c_mechs = 1; + c_peers = 1; + + next = neighbours; + while (next!=NULL) + { + int found_addresses = GNUNET_NO; + struct ReadyList *r_next = next->plugins; + while (r_next != NULL) + { + struct ForeignAddressList * a_next = r_next->addresses; + while (a_next != NULL) + { + if (a_next->connected == GNUNET_YES) + connected_addresses ++; + if (found_addresses == GNUNET_NO) + { + peers[c_peers].peer = next->id; + peers[c_peers].m_head = NULL; + peers[c_peers].m_tail = NULL; + peers[c_peers].f = 1.0 / c_mechs; + } + + mechanisms[c_mechs].addr = a_next; + mechanisms[c_mechs].col_index = c_mechs; + mechanisms[c_mechs].peer = &peers[c_peers]; + mechanisms[c_mechs].next = NULL; + mechanisms[c_mechs].plugin = r_next->plugin; + mechanisms[c_mechs].ressources = a_next->ressources; + mechanisms[c_mechs].quality = a_next->quality; + + GNUNET_CONTAINER_DLL_insert_tail(peers[c_peers].m_head, + peers[c_peers].m_tail, + &mechanisms[c_mechs]); + found_addresses = GNUNET_YES; + c_mechs++; + + a_next = a_next->next; + } + r_next = r_next->next; + } + if (found_addresses == GNUNET_YES) + c_peers++; + next = next->next; + } + c_mechs--; + c_peers--; + (*c_m) = c_mechs; + (*c_p) = c_peers; + (*p) = peers; + (*m) = mechanisms; + + GNUNET_STATISTICS_set(stats, + gettext_noop ("# connected addresses"), + connected_addresses, + GNUNET_NO); +} + static void schedule_ats (void *cls, - const struct GNUNET_SCHEDULER_TaskContext *tc) + const struct GNUNET_SCHEDULER_TaskContext *tc) { struct ATS_Handle *ats = (struct ATS_Handle *) cls; if (ats==NULL) @@ -6069,13 +6207,28 @@ schedule_ats (void *cls, ats_task = GNUNET_SCHEDULER_NO_TASK; if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) return; + if (shutdown_in_progress == GNUNET_YES) return; + + struct GNUNET_TIME_Relative delta = + GNUNET_TIME_absolute_get_difference (last_ats_execution, GNUNET_TIME_absolute_get()); + if (delta.rel_value < ats_minimum_interval.rel_value) + { #if DEBUG_ATS - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running scheduled calculation\n"); + GNUNET_log (GNUNET_ERROR_TYPE_BULK, + "Minimum time between cycles not reached\n"); #endif - ats_calculate_bandwidth_distribution (ats, stats, neighbours); - ats_task = GNUNET_SCHEDULER_add_delayed (ats->exec_interval, + return; + } + +#if DEBUG_ATS + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running scheduled calculation\n"); +#endif + ats_calculate_bandwidth_distribution (ats, stats); + last_ats_execution = GNUNET_TIME_absolute_get(); + + ats_task = GNUNET_SCHEDULER_add_delayed (ats_regular_interval, &schedule_ats, ats); } @@ -6215,11 +6368,136 @@ run (void *cls, if (no_transports) refresh_hello (); - ats = ats_init (cfg); + /* Initializing ATS */ + int co; + char * section; + unsigned long long value; + + double D = 1.0; + double U = 1.0; + double R = 1.0; + int v_b_min = 64000; + int v_n_min = 5; + + ats_minimum_interval = ATS_MIN_INTERVAL; + ats_regular_interval = ATS_EXEC_INTERVAL; + + /* loading cost ressources */ + for (co=0; coprob = NULL; - ats->min_delta = ATS_MIN_INTERVAL; - ats->exec_interval = ATS_EXEC_INTERVAL; - ats->max_exec_duration = ATS_MAX_EXEC_DURATION; - ats->max_iterations = ATS_MAX_ITERATIONS; - - ats->D = 1.0; - ats->U = 1.0; - ats->R = 1.0; - ats->v_b_min = 64000; - ats->v_n_min = 10; - ats->dump_min_peers = 1; - ats->dump_min_addr = 1; + ats->addr_notification = address_not; + ats->result_cb = res_cb; + + ats->max_iterations = max_iterations; + ats->max_exec_duration = max_duration; + + ats->D = D; + ats->U = U; + ats->R = R; + ats->v_b_min = v_b_min; + ats->v_n_min = v_n_min; + ats->dump_min_peers = 0; + ats->dump_min_addr = 0; ats->dump_overwrite = GNUNET_NO; ats->mechanisms = NULL; ats->peers = NULL; ats->successful_executions = 0; ats->invalid_executions = 0; - /* loading cost ressources */ - for (c=0; csave_mlp = GNUNET_CONFIGURATION_get_value_yesno (cfg, - "transport","DUMP_MLP"); - - if (GNUNET_CONFIGURATION_have_value(cfg, "transport", "DUMP_SOLUTION")) - ats->save_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg, - "transport","DUMP_SOLUTION"); - if (GNUNET_CONFIGURATION_have_value(cfg, "transport", "DUMP_OVERWRITE")) - ats->dump_overwrite = GNUNET_CONFIGURATION_get_value_yesno (cfg, - "transport","DUMP_OVERWRITE"); - if (GNUNET_CONFIGURATION_have_value(cfg, "transport", "DUMP_MIN_PEERS")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","DUMP_MIN_PEERS", &value); - ats->dump_min_peers= value; - } - if (GNUNET_CONFIGURATION_have_value(cfg, - "transport", "DUMP_MIN_ADDRS")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","DUMP_MIN_ADDRS", &value); - ats->dump_min_addr= value; - } - if (GNUNET_CONFIGURATION_have_value(cfg, - "transport", "DUMP_OVERWRITE")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","DUMP_OVERWRITE", &value); - ats->min_delta.rel_value = value; - } - - if (GNUNET_CONFIGURATION_have_value(cfg, - "transport", "ATS_MIN_INTERVAL")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","ATS_MIN_INTERVAL", &value); - ats->min_delta.rel_value = value; - } - - if (GNUNET_CONFIGURATION_have_value(cfg, - "transport", "ATS_EXEC_INTERVAL")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","ATS_EXEC_INTERVAL", &value); - ats->exec_interval.rel_value = value; - } - if (GNUNET_CONFIGURATION_have_value(cfg, "transport", "ATS_MIN_INTERVAL")) - { - GNUNET_CONFIGURATION_get_value_number(cfg, - "transport","ATS_MIN_INTERVAL", &value); - ats->min_delta.rel_value = value; - } return ats; } @@ -891,25 +529,23 @@ struct ATS_Handle * ats_init (const struct GNUNET_CONFIGURATION_Handle *cfg) * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used */ int ats_create_problem (struct ATS_Handle *ats, - struct NeighbourList *neighbours, - double D, - double U, - double R, - int v_b_min, - int v_n_min, - struct ATS_stat *stat) + struct ATS_internals *stat, + struct ATS_peer *peers, + int c_p, + struct ATS_mechanism *mechanisms, + int c_m) { #if !HAVE_LIBGLPK GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS not active\n"); return GNUNET_SYSERR; #endif + if ((c_p == 0) || (c_m == 0)) + return GNUNET_SYSERR; + ats->prob = _lp_create_prob(); int c; - int c_peers = 0; - int c_mechs = 0; - int c_c_ressources = available_ressources; int c_q_metrics = available_quality_metrics; @@ -920,104 +556,18 @@ int ats_create_problem (struct ATS_Handle *ats, Q[c] = 1; } - struct NeighbourList *next = neighbours; - while (next!=NULL) - { - int found_addresses = GNUNET_NO; - struct ReadyList *r_next = next->plugins; - while (r_next != NULL) - { - struct ForeignAddressList * a_next = r_next->addresses; - while (a_next != NULL) - { - c_mechs++; - found_addresses = GNUNET_YES; - a_next = a_next->next; - } - r_next = r_next->next; - } - if (found_addresses) c_peers++; - next = next->next; - } - - if (c_mechs==0) - { -#if DEBUG_ATS - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "No addresses for bw distribution available\n", - c_peers); -#endif - stat->valid = GNUNET_NO; - stat->c_peers = 0; - stat->c_mechs = 0; - return GNUNET_SYSERR; - } - - GNUNET_assert (ats->mechanisms == NULL); - ats->mechanisms = GNUNET_malloc((1+c_mechs) * sizeof (struct ATS_mechanism)); - GNUNET_assert (ats->peers == NULL); - ats->peers = GNUNET_malloc((1+c_peers) * sizeof (struct ATS_peer)); - - struct ATS_mechanism * mechanisms = ats->mechanisms; - struct ATS_peer * peers = ats->peers; - - c_mechs = 1; - c_peers = 1; - - next = neighbours; - while (next!=NULL) - { - int found_addresses = GNUNET_NO; - struct ReadyList *r_next = next->plugins; - while (r_next != NULL) - { - struct ForeignAddressList * a_next = r_next->addresses; - while (a_next != NULL) - { - if (found_addresses == GNUNET_NO) - { - peers[c_peers].peer = next->id; - peers[c_peers].m_head = NULL; - peers[c_peers].m_tail = NULL; - peers[c_peers].f = 1.0 / c_mechs; - } - - mechanisms[c_mechs].addr = a_next; - mechanisms[c_mechs].col_index = c_mechs; - mechanisms[c_mechs].peer = &peers[c_peers]; - mechanisms[c_mechs].next = NULL; - mechanisms[c_mechs].plugin = r_next->plugin; - - GNUNET_CONTAINER_DLL_insert_tail(peers[c_peers].m_head, - peers[c_peers].m_tail, - &mechanisms[c_mechs]); - found_addresses = GNUNET_YES; - c_mechs++; - - a_next = a_next->next; - } - r_next = r_next->next; - } - if (found_addresses == GNUNET_YES) - c_peers++; - next = next->next; - } - c_mechs--; - c_peers--; - - if (v_n_min > c_peers) - v_n_min = c_peers; - + if (ats->v_n_min > c_p) + ats->v_n_min = c_p; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n", - c_peers, - c_mechs, + c_p, + c_m, c_c_ressources, c_q_metrics); #endif - int size = 1 + 3 + 10 *c_mechs + c_peers + - (c_q_metrics*c_mechs)+ c_q_metrics + c_c_ressources * c_mechs ; + int size = 1 + 3 + 10 *c_m + c_p + + (c_q_metrics*c_m)+ c_q_metrics + c_c_ressources * c_m ; int row_index; int array_index=1; int * ia = GNUNET_malloc (size * sizeof (int)); @@ -1029,9 +579,9 @@ int ats_create_problem (struct ATS_Handle *ats, /* adding columns */ char * name; - _lp_add_cols(ats->prob, 2 * c_mechs); + _lp_add_cols(ats->prob, 2 * c_m); /* adding b_t cols */ - for (c=1; c <= c_mechs; c++) + for (c=1; c <= c_m; c++) { GNUNET_asprintf(&name, "p_%s_b%i",GNUNET_i2s(&(mechanisms[c].peer->peer)), c); @@ -1039,14 +589,14 @@ int ats_create_problem (struct ATS_Handle *ats, GNUNET_free (name); _lp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0); _lp_set_col_kind(ats->prob, c, GLP_CV); - //_lp_set_obj_coef(ats->prob, c, 0); + _lp_set_obj_coef(ats->prob, c, 0); } /* adding n_t cols */ - for (c=c_mechs+1; c <= 2*c_mechs; c++) + for (c=c_m+1; c <= 2*c_m; c++) { GNUNET_asprintf(&name, - "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_mechs].peer->peer)),(c-c_mechs)); + "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_m].peer->peer)),(c-c_m)); _lp_set_col_name(ats->prob, c, name); GNUNET_free (name); _lp_set_col_bnds(ats->prob, c, GLP_DB, 0.0, 1.0); @@ -1058,9 +608,9 @@ int ats_create_problem (struct ATS_Handle *ats, /* Constraint 1: one address per peer*/ row_index = 1; - _lp_add_rows(ats->prob, c_peers); + _lp_add_rows(ats->prob, c_p); - for (c=1; c<=c_peers; c++) + for (c=1; c<=c_p; c++) { #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", @@ -1072,7 +622,7 @@ int ats_create_problem (struct ATS_Handle *ats, while (m!=NULL) { ia[array_index] = row_index; - ja[array_index] = (c_mechs + m->col_index); + ja[array_index] = (c_m + m->col_index); ar[array_index] = 1; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -1088,8 +638,8 @@ int ats_create_problem (struct ATS_Handle *ats, } /* Constraint 2: only active mechanism gets bandwidth assigned */ - _lp_add_rows(ats->prob, c_mechs); - for (c=1; c<=c_mechs; c++) + _lp_add_rows(ats->prob, c_m); + for (c=1; c<=c_m; c++) { /* b_t - n_t * M <= 0 */ #if VERBOSE_ATS @@ -1109,7 +659,7 @@ int ats_create_problem (struct ATS_Handle *ats, #endif array_index++; ia[array_index] = row_index; - ja[array_index] = c_mechs + mechanisms[c].col_index; + ja[array_index] = c_m + mechanisms[c].col_index; ar[array_index] = -M; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -1123,9 +673,9 @@ int ats_create_problem (struct ATS_Handle *ats, } /* Constraint 3: minimum bandwidth*/ - _lp_add_rows(ats->prob, c_mechs); + _lp_add_rows(ats->prob, c_m); - for (c=1; c<=c_mechs; c++) + for (c=1; c<=c_m; c++) { /* b_t - n_t * b_min <= 0 */ #if VERBOSE_ATS @@ -1147,8 +697,8 @@ int ats_create_problem (struct ATS_Handle *ats, #endif array_index++; ia[array_index] = row_index; - ja[array_index] = c_mechs + mechanisms[c].col_index; - ar[array_index] = -v_b_min; + ja[array_index] = c_m + mechanisms[c].col_index; + ar[array_index] = -ats->v_b_min; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", array_index, @@ -1185,12 +735,12 @@ int ats_create_problem (struct ATS_Handle *ats, #if HAVE_LIBGLPK _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max); #endif - for (c2=1; c2<=c_mechs; c2++) + for (c2=1; c2<=c_m; c2++) { double value = 0; ia[array_index] = row_index; ja[array_index] = c2; - value = mechanisms[c2].addr->ressources[c].c; + value = mechanisms[c2].ressources[c].c; ar[array_index] = value; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -1207,16 +757,16 @@ int ats_create_problem (struct ATS_Handle *ats, /* Constraint 5: min number of connections*/ _lp_add_rows(ats->prob, 1); - for (c=1; c<=c_mechs; c++) + for (c=1; c<=c_m; c++) { // b_t - n_t * b_min >= 0 #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index); #endif - _lp_set_row_bnds(ats->prob, row_index, GLP_LO, v_n_min, 0.0); + _lp_set_row_bnds(ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0); ia[array_index] = row_index; - ja[array_index] = c_mechs + mechanisms[c].col_index; + ja[array_index] = c_m + mechanisms[c].col_index; ar[array_index] = 1; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -1238,7 +788,7 @@ int ats_create_problem (struct ATS_Handle *ats, col_d = _lp_add_cols(ats->prob, 1); _lp_set_col_name(ats->prob, col_d, "d"); - _lp_set_obj_coef(ats->prob, col_d, D); + _lp_set_obj_coef(ats->prob, col_d, ats->D); _lp_set_col_bnds(ats->prob, col_d, GLP_LO, 0.0, 0.0); _lp_add_rows(ats->prob, 1); _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); @@ -1247,10 +797,10 @@ int ats_create_problem (struct ATS_Handle *ats, #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); #endif - for (c=1; c<=c_mechs; c++) + for (c=1; c<=c_m; c++) { ia[array_index] = row_index; - ja[array_index] = c_mechs + mechanisms[c].col_index; + ja[array_index] = c_m + mechanisms[c].col_index; ar[array_index] = 1; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -1300,18 +850,18 @@ int ats_create_problem (struct ATS_Handle *ats, #endif double value = 1; _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); - for (c2=1; c2<=c_mechs; c2++) + for (c2=1; c2<=c_m; c2++) { ia[array_index] = row_index; ja[array_index] = c2; if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) { double v0 = 0, v1 = 0, v2 = 0; - v0 = mechanisms[c2].addr->quality[c-1].values[0]; + v0 = mechanisms[c2].quality[c-1].values[0]; if (v1 < 1) v0 = 0.1; - v1 = mechanisms[c2].addr->quality[c-1].values[1]; + v1 = mechanisms[c2].quality[c-1].values[1]; if (v1 < 1) v0 = 0.1; - v2 = mechanisms[c2].addr->quality[c-1].values[2]; + v2 = mechanisms[c2].quality[c-1].values[2]; if (v1 < 1) v0 = 0.1; value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0); value = 1; @@ -1319,11 +869,11 @@ int ats_create_problem (struct ATS_Handle *ats, if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) { double v0 = 0, v1 = 0, v2 = 0; - v0 = mechanisms[c2].addr->quality[c-1].values[0]; + v0 = mechanisms[c2].quality[c-1].values[0]; if (v0 < 1) v0 = 1; - v1 = mechanisms[c2].addr->quality[c-1].values[1]; + v1 = mechanisms[c2].quality[c-1].values[1]; if (v1 < 1) v1 = 1; - v2 = mechanisms[c2].addr->quality[c-1].values[2]; + v2 = mechanisms[c2].quality[c-1].values[2]; if (v2 < 1) v2 = 1; value = (v0 + 2 * v1 + 3 * v2) / 6.0; if (value >= 1) @@ -1363,7 +913,7 @@ int ats_create_problem (struct ATS_Handle *ats, col_u = _lp_add_cols(ats->prob, 1); _lp_set_col_name(ats->prob, col_u, "u"); - _lp_set_obj_coef(ats->prob, col_u, U); + _lp_set_obj_coef(ats->prob, col_u, ats->U); _lp_set_col_bnds(ats->prob, col_u, GLP_LO, 0.0, 0.0); _lp_add_rows(ats->prob, 1); stat->col_u = col_u; @@ -1371,7 +921,7 @@ int ats_create_problem (struct ATS_Handle *ats, GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); #endif _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); - for (c=1; c<=c_mechs; c++) + for (c=1; c<=c_m; c++) { ia[array_index] = row_index; ja[array_index] = c; @@ -1404,12 +954,12 @@ int ats_create_problem (struct ATS_Handle *ats, col_r = _lp_add_cols(ats->prob, 1); _lp_set_col_name(ats->prob, col_r, "r"); - _lp_set_obj_coef(ats->prob, col_r, R); + _lp_set_obj_coef(ats->prob, col_r, ats->R); _lp_set_col_bnds(ats->prob, col_r, GLP_LO, 0.0, 0.0); - _lp_add_rows(ats->prob, c_peers); + _lp_add_rows(ats->prob, c_p); stat->col_r = col_r; - for (c=1; c<=c_peers; c++) + for (c=1; c<=c_p; c++) { _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0); struct ATS_mechanism *m = peers[c].m_head; @@ -1445,8 +995,8 @@ int ats_create_problem (struct ATS_Handle *ats, /* Loading the matrix */ _lp_load_matrix(ats->prob, array_index-1, ia, ja, ar); - stat->c_mechs = c_mechs; - stat->c_peers = c_peers; + stat->c_mechs = c_m; + stat->c_peers = c_p; stat->solution = 0; stat->valid = GNUNET_YES; @@ -1471,7 +1021,7 @@ void ats_delete_problem (struct ATS_Handle * ats) #endif int c; - for (c=0; c< (ats->stat).c_mechs; c++) + for (c=0; c< (ats->internal).c_mechs; c++) GNUNET_free_non_null (ats->mechanisms[c].rc); if (ats->mechanisms!=NULL) { @@ -1491,14 +1041,14 @@ void ats_delete_problem (struct ATS_Handle * ats) ats->prob = NULL; } - ats->stat.begin_cr = GNUNET_SYSERR; - ats->stat.begin_qm = GNUNET_SYSERR; - ats->stat.c_mechs = 0; - ats->stat.c_peers = 0; - ats->stat.end_cr = GNUNET_SYSERR; - ats->stat.end_qm = GNUNET_SYSERR; - ats->stat.solution = GNUNET_SYSERR; - ats->stat.valid = GNUNET_SYSERR; + ats->internal.begin_cr = GNUNET_SYSERR; + ats->internal.begin_qm = GNUNET_SYSERR; + ats->internal.c_mechs = 0; + ats->internal.c_peers = 0; + ats->internal.end_cr = GNUNET_SYSERR; + ats->internal.end_qm = GNUNET_SYSERR; + ats->internal.solution = GNUNET_SYSERR; + ats->internal.valid = GNUNET_SYSERR; } void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s) @@ -1508,22 +1058,22 @@ void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s switch (s) { case ATS_NEW : - ats->stat.recreate_problem = GNUNET_NO; - ats->stat.modified_quality = GNUNET_NO; - ats->stat.modified_resources = GNUNET_NO; + ats->internal.recreate_problem = GNUNET_NO; + ats->internal.modified_quality = GNUNET_NO; + ats->internal.modified_resources = GNUNET_NO; break; case ATS_MODIFIED: - ats->stat.recreate_problem = GNUNET_YES; + ats->internal.recreate_problem = GNUNET_YES; break; case ATS_QUALITY_UPDATED : - ats->stat.modified_quality = GNUNET_YES; + ats->internal.modified_quality = GNUNET_YES; break; case ATS_COST_UPDATED : - ats->stat.modified_resources = GNUNET_YES; + ats->internal.modified_resources = GNUNET_YES; break; case ATS_QUALITY_COST_UPDATED: - ats->stat.modified_resources = GNUNET_YES; - ats->stat.modified_quality = GNUNET_YES; + ats->internal.modified_resources = GNUNET_YES; + ats->internal.modified_quality = GNUNET_YES; break; default: return; @@ -1538,7 +1088,7 @@ void ats_solve_problem (struct ATS_Handle * ats, unsigned int max_dur, unsigned int c_peers, unsigned int c_mechs, - struct ATS_stat *stat) + struct ATS_internals *stat) { #if !HAVE_LIBGLPK GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS not active\n"); @@ -1564,7 +1114,7 @@ void ats_solve_problem (struct ATS_Handle * ats, // maximum duration opt_lp.tm_lim = max_dur; - if (ats->stat.recreate_problem == GNUNET_YES) + if (ats->internal.recreate_problem == GNUNET_YES) opt_lp.presolve = GLP_ON; result = _lp_simplex(ats->prob, &opt_lp); @@ -1572,7 +1122,7 @@ void ats_solve_problem (struct ATS_Handle * ats, if ((result == GLP_ETMLIM) || (result == GLP_EITLIM)) { - ats->stat.valid = GNUNET_NO; + ats->internal.valid = GNUNET_NO; GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS exceeded time or iteration limit!\n"); return; @@ -1584,7 +1134,7 @@ void ats_solve_problem (struct ATS_Handle * ats, } else { - ats->stat.simplex_rerun_required = GNUNET_YES; + ats->internal.simplex_rerun_required = GNUNET_YES; opt_lp.presolve = GLP_ON; result = _lp_simplex(ats->prob, &opt_lp); lp_solution = _lp_get_status (ats->prob); @@ -1601,13 +1151,13 @@ void ats_solve_problem (struct ATS_Handle * ats, char * filename; GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%llu.mlp", - ats->stat.c_peers, - ats->stat.c_mechs, + ats->internal.c_peers, + ats->internal.c_mechs, GNUNET_TIME_absolute_get().abs_value); _lp_write_lp ((void *)ats->prob, NULL, filename); GNUNET_free (filename); stat->valid = GNUNET_NO; - ats->stat.recreate_problem = GNUNET_YES; + ats->internal.recreate_problem = GNUNET_YES; return; } stat->valid = GNUNET_YES; @@ -1638,8 +1188,8 @@ void ats_solve_problem (struct ATS_Handle * ats, // TODO: Remove if this does not appear until release GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP solution for %i peers, %i mechs is invalid: %i\n", - ats->stat.c_peers, - ats->stat.c_mechs, + ats->internal.c_peers, + ats->internal.c_mechs, mlp_solution); stat->valid = GNUNET_NO; } @@ -1698,14 +1248,14 @@ void ats_update_problem_qm (struct ATS_Handle * ats) int c, c2; int c_q_metrics = available_quality_metrics; - int *ja = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (int)); - double *ar = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (double)); #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); #endif - row_index = ats->stat.begin_qm; + row_index = ats->internal.begin_qm; for (c=1; c <= c_q_metrics; c++) { @@ -1715,7 +1265,7 @@ void ats_update_problem_qm (struct ATS_Handle * ats) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); #endif _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); - for (c2=1; c2<=ats->stat.c_mechs; c2++) + for (c2=1; c2<=ats->internal.c_mechs; c2++) { ja[array_index] = c2; GNUNET_assert (ats->mechanisms[c2].addr != NULL); @@ -1725,11 +1275,11 @@ void ats_update_problem_qm (struct ATS_Handle * ats) { double v0 = 0, v1 = 0, v2 = 0; - v0 = ats->mechanisms[c2].addr->quality[c-1].values[0]; + v0 = ats->mechanisms[c2].quality[c-1].values[0]; if (v1 < 1) v0 = 0.1; - v1 = ats->mechanisms[c2].addr->quality[c-1].values[1]; + v1 = ats->mechanisms[c2].quality[c-1].values[1]; if (v1 < 1) v0 = 0.1; - v2 = ats->mechanisms[c2].addr->quality[c-1].values[2]; + v2 = ats->mechanisms[c2].quality[c-1].values[2]; if (v1 < 1) v0 = 0.1; value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0); //value = 1; @@ -1737,11 +1287,11 @@ void ats_update_problem_qm (struct ATS_Handle * ats) if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) { double v0 = 0, v1 = 0, v2 = 0; - v0 = ats->mechanisms[c2].addr->quality[c-1].values[0]; + v0 = ats->mechanisms[c2].quality[c-1].values[0]; if (v0 < 1) v0 = 1; - v1 = ats->mechanisms[c2].addr->quality[c-1].values[1]; + v1 = ats->mechanisms[c2].quality[c-1].values[1]; if (v1 < 1) v1 = 1; - v2 = ats->mechanisms[c2].addr->quality[c-1].values[2]; + v2 = ats->mechanisms[c2].quality[c-1].values[2]; if (v2 < 1) v2 = 1; value = (v0 + 2 * v1 + 3 * v2) / 6.0; if (value >= 1) @@ -1760,7 +1310,7 @@ void ats_update_problem_qm (struct ATS_Handle * ats) #endif array_index++; } - ja[array_index] = ats->stat.col_qm + c - 1; + ja[array_index] = ats->internal.col_qm + c - 1; ar[array_index] = -1; #if VERBOSE_ATS @@ -1776,13 +1326,13 @@ void ats_update_problem_qm (struct ATS_Handle * ats) } GNUNET_free_non_null (ja); GNUNET_free_non_null (ar); + } void ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, - struct GNUNET_STATISTICS_Handle *stats, - struct NeighbourList *neighbours) + struct GNUNET_STATISTICS_Handle *stats) { #if !HAVE_LIBGLPK GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS not active\n"); @@ -1792,19 +1342,10 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, struct GNUNET_TIME_Absolute start; struct GNUNET_TIME_Relative creation; struct GNUNET_TIME_Relative solving; + int c_m; + int c_p; char *text = "unmodified"; - struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference (ats->last, - GNUNET_TIME_absolute_get()); - if (delta.rel_value < ats->min_delta.rel_value) - { -#if DEBUG_ATS - GNUNET_log (GNUNET_ERROR_TYPE_BULK, - "Minimum time between cycles not reached\n"); -#endif - return; - } - #if FIXME_WACHS int dur; if (INT_MAX < ats->max_exec_duration.rel_value) @@ -1813,103 +1354,109 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, dur = (int) ats->max_exec_duration.rel_value; #endif - ats->stat.simplex_rerun_required = GNUNET_NO; + ats->internal.simplex_rerun_required = GNUNET_NO; start = GNUNET_TIME_absolute_get(); - if ((ats->stat.recreate_problem == GNUNET_YES) || + if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL) || - (ats->stat.valid == GNUNET_NO)) + (ats->internal.valid == GNUNET_NO)) { text = "new"; - ats->stat.recreate_problem = GNUNET_YES; + ats->internal.recreate_problem = GNUNET_YES; ats_delete_problem (ats); - ats_create_problem (ats, - neighbours, - ats->D, - ats->U, - ats->R, - ats->v_b_min, - ats->v_n_min, - &ats->stat); + ats->addr_notification(&ats->peers , &c_p, &ats->mechanisms, &c_m); +#if DEBUG_ATS + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Service returned: %i peer, %i mechs\n", + c_p, + c_m); +#endif + ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms, c_m); + + #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers/Addresses were modified... new problem: %i peer, %i mechs\n", - ats->stat.c_peers, - ats->stat.c_mechs); + ats->internal.c_peers, + ats->internal.c_mechs); #endif } - else if ((ats->stat.recreate_problem == GNUNET_NO) && - (ats->stat.modified_resources == GNUNET_YES) && - (ats->stat.valid == GNUNET_YES)) + else if ((ats->internal.recreate_problem == GNUNET_NO) && + (ats->internal.modified_resources == GNUNET_YES) && + (ats->internal.valid == GNUNET_YES)) { text = "modified resources"; ats_update_problem_cr (ats); } - else if ((ats->stat.recreate_problem == GNUNET_NO) && - (ats->stat.modified_quality == GNUNET_YES) && - (ats->stat.valid == GNUNET_YES)) + else if ((ats->internal.recreate_problem == GNUNET_NO) && + (ats->internal.modified_quality == GNUNET_YES) && + (ats->internal.valid == GNUNET_YES)) { text = "modified quality"; ats_update_problem_qm (ats); - //ats_update_problem_qm_TEST (); + //ats_update_problem_qm_TEST (); } #if DEBUG_ATS - else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is unmodified\n"); + else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text); #endif creation = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); start = GNUNET_TIME_absolute_get(); - ats->stat.solution = GLP_UNDEF; - if (ats->stat.valid == GNUNET_YES) + ats->internal.solution = GLP_UNDEF; + if (ats->internal.valid == GNUNET_YES) { ats_solve_problem(ats, ats->max_iterations, ats->max_exec_duration.rel_value, - ats->stat.c_peers, - ats->stat.c_mechs, - &ats->stat); + ats->internal.c_peers, + ats->internal.c_mechs, + &ats->internal); } solving = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); - if (ats->stat.valid == GNUNET_YES) + if (ats->internal.valid == GNUNET_YES) { + /* Telling about new distribution*/ + ats->result_cb (); + int msg_type = GNUNET_ERROR_TYPE_DEBUG; #if DEBUG_ATS msg_type = GNUNET_ERROR_TYPE_ERROR; #endif GNUNET_log (msg_type, - "MLP %s: creation time: %llu, execution time: %llu, %i mechanisms, simplex rerun: %s, solution %s\n", + "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n", text, creation.rel_value, solving.rel_value, - ats->stat.c_mechs, - (ats->stat.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES", - (ats->stat.solution == 5) ? "OPTIMAL" : "INVALID"); + ats->internal.c_peers, + ats->internal.c_mechs, + (ats->internal.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES", + (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID"); ats->successful_executions ++; GNUNET_STATISTICS_set (stats, "# ATS successful executions", ats->successful_executions, GNUNET_NO); - if ((ats->stat.recreate_problem == GNUNET_YES) || (ats->prob==NULL)) + if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL)) GNUNET_STATISTICS_set (stats, "ATS state",ATS_NEW, GNUNET_NO); - else if ((ats->stat.modified_resources == GNUNET_YES) && - (ats->stat.modified_quality == GNUNET_NO)) + else if ((ats->internal.modified_resources == GNUNET_YES) && + (ats->internal.modified_quality == GNUNET_NO)) GNUNET_STATISTICS_set (stats, "ATS state", ATS_COST_UPDATED, GNUNET_NO); - else if ((ats->stat.modified_resources == GNUNET_NO) && - (ats->stat.modified_quality == GNUNET_YES) && - (ats->stat.simplex_rerun_required == GNUNET_NO)) + else if ((ats->internal.modified_resources == GNUNET_NO) && + (ats->internal.modified_quality == GNUNET_YES) && + (ats->internal.simplex_rerun_required == GNUNET_NO)) GNUNET_STATISTICS_set (stats, "ATS state", ATS_QUALITY_UPDATED, GNUNET_NO); - else if ((ats->stat.modified_resources == GNUNET_YES) && - (ats->stat.modified_quality == GNUNET_YES) && - (ats->stat.simplex_rerun_required == GNUNET_NO)) + else if ((ats->internal.modified_resources == GNUNET_YES) && + (ats->internal.modified_quality == GNUNET_YES) && + (ats->internal.simplex_rerun_required == GNUNET_NO)) GNUNET_STATISTICS_set (stats, "ATS state", ATS_QUALITY_COST_UPDATED, GNUNET_NO); - else if (ats->stat.simplex_rerun_required == GNUNET_NO) + else if (ats->internal.simplex_rerun_required == GNUNET_NO) GNUNET_STATISTICS_set (stats, "ATS state", ATS_UNMODIFIED, GNUNET_NO); } else { - if (ats->stat.c_peers != 0) + if (ats->internal.c_peers != 0) { ats->invalid_executions ++; GNUNET_STATISTICS_set (stats, "# ATS invalid executions", @@ -1925,24 +1472,24 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, GNUNET_STATISTICS_set (stats, "ATS duration", solving.rel_value + creation.rel_value, GNUNET_NO); GNUNET_STATISTICS_set (stats, - "ATS mechanisms", ats->stat.c_mechs, GNUNET_NO); + "ATS mechanisms", ats->internal.c_mechs, GNUNET_NO); GNUNET_STATISTICS_set (stats, - "ATS peers", ats->stat.c_peers, GNUNET_NO); + "ATS peers", ats->internal.c_peers, GNUNET_NO); GNUNET_STATISTICS_set (stats, - "ATS solution", ats->stat.solution, GNUNET_NO); + "ATS solution", ats->internal.solution, GNUNET_NO); GNUNET_STATISTICS_set (stats, "ATS timestamp", start.abs_value, GNUNET_NO); if ((ats->save_mlp == GNUNET_YES) && - (ats->stat.c_mechs >= ats->dump_min_peers) && - (ats->stat.c_mechs >= ats->dump_min_addr)) + (ats->internal.c_mechs >= ats->dump_min_peers) && + (ats->internal.c_mechs >= ats->dump_min_addr)) { char * filename; if (ats->dump_overwrite == GNUNET_NO) { GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp", - ats->stat.c_peers, - ats->stat.c_mechs, + ats->internal.c_peers, + ats->internal.c_mechs, text, GNUNET_TIME_absolute_get().abs_value); _lp_write_lp ((void *) ats->prob, NULL, filename); @@ -1950,21 +1497,21 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, else { GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp", - ats->stat.c_peers, ats->stat.c_mechs ); + ats->internal.c_peers, ats->internal.c_mechs ); _lp_write_lp ((void *) ats->prob, NULL, filename); } GNUNET_free (filename); } if ((ats->save_solution == GNUNET_YES) && - (ats->stat.c_mechs >= ats->dump_min_peers) && - (ats->stat.c_mechs >= ats->dump_min_addr)) + (ats->internal.c_mechs >= ats->dump_min_peers) && + (ats->internal.c_mechs >= ats->dump_min_addr)) { char * filename; if (ats->dump_overwrite == GNUNET_NO) { GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol", - ats->stat.c_peers, - ats->stat.c_mechs, + ats->internal.c_peers, + ats->internal.c_mechs, text, GNUNET_TIME_absolute_get().abs_value); _lp_print_sol (ats->prob, filename); @@ -1972,15 +1519,15 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats, else { GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol", - ats->stat.c_peers, ats->stat.c_mechs); + ats->internal.c_peers, ats->internal.c_mechs); _lp_print_sol (ats->prob, filename); } GNUNET_free (filename); } - ats->last = GNUNET_TIME_absolute_get(); - ats->stat.recreate_problem = GNUNET_NO; - ats->stat.modified_resources = GNUNET_NO; - ats->stat.modified_quality = GNUNET_NO; + + ats->internal.recreate_problem = GNUNET_NO; + ats->internal.modified_resources = GNUNET_NO; + ats->internal.modified_quality = GNUNET_NO; } /** @@ -2115,13 +1662,13 @@ void ats_update_problem_cr (struct ATS_Handle * ats) int c, c2; double ct_max, ct_min; - int *ja = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (int)); - double *ar = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (double)); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); - row_index = ats->stat.begin_cr; + row_index = ats->internal.begin_cr; array_index = 1; for (c=0; cprob, row_index, GLP_DB, ct_min, ct_max); - for (c2=1; c2<=ats->stat.c_mechs; c2++) + for (c2=1; c2<=ats->internal.c_mechs; c2++) { double value = 0; GNUNET_assert (ats->mechanisms[c2].addr != NULL); GNUNET_assert (ats->mechanisms[c2].peer != NULL); ja[array_index] = c2; - value = ats->mechanisms[c2].addr->ressources[c].c; + value = ats->mechanisms[c2].ressources[c].c; ar[array_index] = value; #if VERBOSE_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", @@ -2158,6 +1705,24 @@ void ats_update_problem_cr (struct ATS_Handle * ats) } GNUNET_free_non_null (ja); GNUNET_free_non_null (ar); + +} + +void ats_set_logging_options (struct ATS_Handle * ats, + int minimum_addresses, + int minimum_peers, + int overwrite_dump, + int log_solution, + int log_problem) +{ + if (ats == NULL) + return; + + ats->dump_min_addr = minimum_addresses; + ats->dump_min_peers = minimum_peers; + ats->dump_overwrite = overwrite_dump; + ats->save_mlp = log_problem; + ats->save_solution = log_solution; } #if 0 @@ -2169,19 +1734,19 @@ static void ats_update_problem_qm_TEST () int c_old; int changed = 0; - int old_ja[ats->stat.c_mechs + 2]; - double old_ar[ats->stat.c_mechs + 2]; + int old_ja[ats->internal.c_mechs + 2]; + double old_ar[ats->internal.c_mechs + 2]; - int *ja = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (int)); - double *ar = GNUNET_malloc ((1 + ats->stat.c_mechs*2 + 3 + + double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + available_quality_metrics) * sizeof (double)); #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics TEST\n"); #endif - if (ats->stat.begin_qm >0) - row_index = ats->stat.begin_qm; + if (ats->internal.begin_qm >0) + row_index = ats->internal.begin_qm; else return; for (c=0; c