From: Christian Grothoff Date: Fri, 6 Feb 2015 09:28:57 +0000 (+0000) Subject: get rid of stupid network[i]=i array X-Git-Tag: initial-import-from-subversion-38251~2442 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=66d788dbe9224b7d3e51ad60d2a29a167b2e348d;p=oweals%2Fgnunet.git get rid of stupid network[i]=i array --- diff --git a/src/ats/ats_api_scanner.c b/src/ats/ats_api_scanner.c index 43e79b3cf..c213983f2 100644 --- a/src/ats/ats_api_scanner.c +++ b/src/ats/ats_api_scanner.c @@ -331,7 +331,7 @@ GNUNET_ATS_scanner_address_get_type (struct GNUNET_ATS_InterfaceScanner *is, socklen_t addrlen) { struct ATS_Network *cur = is->net_head; - enum GNUNET_ATS_NetworkType type = GNUNET_ATS_NET_UNSPECIFIED; + enum GNUNET_ATS_Network_Type type = GNUNET_ATS_NET_UNSPECIFIED; switch (addr->sa_family) { diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index bfb1c84ab..c39bb30f7 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c @@ -3057,7 +3057,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) { struct SolverHandle *sh; char * solver_str; - int c; switch (type) { case GNUNET_ATS_SOLVER_PROPORTIONAL: @@ -3091,10 +3090,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) sh->env.network_count = GNUNET_ATS_NetworkTypeCount; sh->env.info_cb = &solver_info_cb; sh->env.network_count = GNUNET_ATS_NetworkTypeCount; - int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; - for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) - sh->env.networks[c] = networks[c]; - /* start normalization */ GAS_normalization_start (); diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c index 9c809f913..830deb04b 100644 --- a/src/ats/gnunet-service-ats.c +++ b/src/ats/gnunet-service-ats.c @@ -126,10 +126,10 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { GAS_addresses_done (); + GAS_connectivity_done (); GAS_plugins_done (); GAS_normalization_stop (); GAS_scheduling_done (); - GAS_connectivity_done (); GAS_performance_done (); GAS_preference_done (); GAS_reservations_done (); diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c index 7e03a1a7e..6c15bc27c 100644 --- a/src/ats/gnunet-service-ats_plugins.c +++ b/src/ats/gnunet-service-ats_plugins.c @@ -452,7 +452,10 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg) GNUNET_free(mode_str); } - load_quotas (cfg, quotas_out, quotas_in, GNUNET_ATS_NetworkTypeCount); + load_quotas (cfg, + quotas_out, + quotas_in, + GNUNET_ATS_NetworkTypeCount); env.cls = NULL; env.info_cb = &solver_info_cb; env.bandwidth_changed_cb = &bandwidth_changed_cb; @@ -461,12 +464,9 @@ GAS_plugins_init (const struct GNUNET_CONFIGURATION_Handle *cfg) env.cfg = cfg; env.stats = GSA_stats; env.addresses = GSA_addresses; - env.network_count = GNUNET_ATS_NetworkTypeCount; - int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) { - env.networks[c] = networks[c]; env.out_quota[c] = quotas_out[c]; env.in_quota[c] = quotas_in[c]; } diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c index d81b5779b..0d75561bc 100644 --- a/src/ats/perf_ats_solver.c +++ b/src/ats/perf_ats_solver.c @@ -1307,16 +1307,14 @@ run (void *cls, char * const *args, const char *cfgfile, ph.env.network_count = GNUNET_ATS_NetworkTypeCount; ph.env.info_cb = &solver_info_cb; - int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) { - ph.env.networks[c] = networks[c]; ph.env.out_quota[c] = quotas_out[c]; ph.env.in_quota[c] = quotas_in[c]; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Loading network quotas: `%s' %llu %llu \n", - GNUNET_ATS_print_network_type(ph.env.networks[c]), - ph.env.out_quota[c], - ph.env.in_quota[c]); + GNUNET_ATS_print_network_type (c), + ph.env.out_quota[c], + ph.env.in_quota[c]); } GAS_normalization_start (); diff --git a/src/ats/plugin_ats_mlp.c b/src/ats/plugin_ats_mlp.c index 11f74a37f..23fbf5063 100644 --- a/src/ats/plugin_ats_mlp.c +++ b/src/ats/plugin_ats_mlp.c @@ -2420,14 +2420,11 @@ libgnunet_plugin_ats_mlp_init (void *cls) static struct GNUNET_ATS_SolverFunctions sf; struct GNUNET_ATS_PluginEnvironment *env = cls; struct GAS_MLP_Handle * mlp = GNUNET_new (struct GAS_MLP_Handle); - float f_tmp; unsigned long long tmp; unsigned int b_min; unsigned int n_min; int c; - int c2; - int found; char *outputformat; struct GNUNET_TIME_Relative max_duration; @@ -2740,77 +2737,55 @@ libgnunet_plugin_ats_mlp_init (void *cls) n_min = MLP_DEFAULT_MIN_CONNECTIONS; /* Init network quotas */ - int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) { - found = GNUNET_NO; - for (c2 = 0; c2 < env->network_count; c2++) - { - if (quotas[c] == env->networks[c2]) - { - mlp->pv.quota_index[c] = env->networks[c2]; - mlp->pv.quota_out[c] = env->out_quota[c2]; - mlp->pv.quota_in[c] = env->in_quota[c2]; - - found = GNUNET_YES; - LOG (GNUNET_ERROR_TYPE_INFO, - "Quota for network `%s' (in/out) %llu/%llu\n", - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_out[c], - mlp->pv.quota_in[c]); - break; - - } - } - - /* Check if defined quota could make problem unsolvable */ - if ((n_min * b_min) > mlp->pv.quota_out[c]) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_out[c], - (n_min * b_min)); - mlp->pv.quota_out[c] = (n_min * b_min); - } - if ((n_min * b_min) > mlp->pv.quota_in[c]) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_in[c], - (n_min * b_min)); - mlp->pv.quota_in[c] = (n_min * b_min); - } - - /* Check if bandwidth is too big to make problem solvable */ - if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) - { - LOG (GNUNET_ERROR_TYPE_INFO, - _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_out[c], - mlp->pv.BIG_M); - mlp->pv.quota_out[c] = mlp->pv.BIG_M ; - } - if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) - { - LOG (GNUNET_ERROR_TYPE_INFO, _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_in[c], - mlp->pv.BIG_M); - mlp->pv.quota_in[c] = mlp->pv.BIG_M ; - } + mlp->pv.quota_index[c] = c; + mlp->pv.quota_out[c] = env->out_quota[c]; + mlp->pv.quota_in[c] = env->in_quota[c]; - if (GNUNET_NO == found) - { - mlp->pv.quota_in[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); - mlp->pv.quota_out[c] = ntohl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__); - LOG (GNUNET_ERROR_TYPE_INFO, _("Using default quota configuration for network `%s' (in/out) %llu/%llu\n"), - GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), - mlp->pv.quota_in[c], - mlp->pv.quota_out[c]); - } + LOG (GNUNET_ERROR_TYPE_INFO, + "Quota for network `%s' (in/out) %llu/%llu\n", + GNUNET_ATS_print_network_type (c), + mlp->pv.quota_out[c], + mlp->pv.quota_in[c]); + /* Check if defined quota could make problem unsolvable */ + if ((n_min * b_min) > mlp->pv.quota_out[c]) + { + LOG (GNUNET_ERROR_TYPE_INFO, + _("Adjusting inconsistent outbound quota configuration for network `%s', is %llu must be at least %llu\n"), + GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), + mlp->pv.quota_out[c], + (n_min * b_min)); + mlp->pv.quota_out[c] = (n_min * b_min); + } + if ((n_min * b_min) > mlp->pv.quota_in[c]) + { + LOG (GNUNET_ERROR_TYPE_INFO, + _("Adjusting inconsistent inbound quota configuration for network `%s', is %llu must be at least %llu\n"), + GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), + mlp->pv.quota_in[c], + (n_min * b_min)); + mlp->pv.quota_in[c] = (n_min * b_min); + } + /* Check if bandwidth is too big to make problem solvable */ + if (mlp->pv.BIG_M < mlp->pv.quota_out[c]) + { + LOG (GNUNET_ERROR_TYPE_INFO, + _("Adjusting outbound quota configuration for network `%s'from %llu to %.0f\n"), + GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), + mlp->pv.quota_out[c], + mlp->pv.BIG_M); + mlp->pv.quota_out[c] = mlp->pv.BIG_M ; + } + if (mlp->pv.BIG_M < mlp->pv.quota_in[c]) + { + LOG (GNUNET_ERROR_TYPE_INFO, + _("Adjusting inbound quota configuration for network `%s' from %llu to %.0f\n"), + GNUNET_ATS_print_network_type(mlp->pv.quota_index[c]), + mlp->pv.quota_in[c], + mlp->pv.BIG_M); + mlp->pv.quota_in[c] = mlp->pv.BIG_M ; + } } mlp->env = env; sf.cls = mlp; diff --git a/src/ats/plugin_ats_proportional.c b/src/ats/plugin_ats_proportional.c index a154ceff3..32ee9f4e4 100644 --- a/src/ats/plugin_ats_proportional.c +++ b/src/ats/plugin_ats_proportional.c @@ -282,7 +282,7 @@ struct Network /** * ATS network type */ - unsigned int type; + enum GNUNET_ATS_Network_Type type; /** * Network description @@ -875,11 +875,12 @@ get_active_address (void *solver, const struct GNUNET_CONTAINER_MultiPeerMap * addresses, const struct GNUNET_PeerIdentity *peer) { - static struct ATS_Address * dest = NULL; + static struct ATS_Address *dest; dest = NULL; GNUNET_CONTAINER_multipeermap_get_multiple (addresses, peer, - &get_active_address_it, &dest); + &get_active_address_it, + &dest); return dest; } @@ -892,15 +893,15 @@ get_active_address (void *solver, * @return the network struct */ static struct Network * -get_network (struct GAS_PROPORTIONAL_Handle *s, uint32_t type) +get_network (struct GAS_PROPORTIONAL_Handle *s, + enum GNUNET_ATS_Network_Type type) { - int c; - for (c = 0; c < s->network_count; c++) + if (type >= s->env->network_count) { - if (s->network_entries[c].type == type) - return &s->network_entries[c]; + GNUNET_break (0); + return NULL; } - return NULL ; + return &s->network_entries[type]; } @@ -1672,24 +1673,23 @@ GAS_proportional_address_property_changed (void *solver, static void GAS_proportional_address_add (void *solver, struct ATS_Address *address, - uint32_t network) + enum GNUNET_ATS_Network_Type network) { struct GAS_PROPORTIONAL_Handle *s = solver; - struct Network *net = NULL; - struct AddressWrapper *aw = NULL; + struct Network *net; + struct AddressWrapper *aw; struct AddressSolverInformation *asi; - GNUNET_assert(NULL != s); net = get_network (s, network); if (NULL == net) { - GNUNET_break(0); - - LOG(GNUNET_ERROR_TYPE_ERROR, - "Unknown network %u `%s' for new address %p for peer `%s'\n", - network, GNUNET_ATS_print_network_type(network), - address, GNUNET_i2s(&address->peer)); - + GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_ERROR, + "Unknown network %u `%s' for new address %p for peer `%s'\n", + network, + GNUNET_ATS_print_network_type (network), + address, + GNUNET_i2s (&address->peer)); return; } @@ -1807,7 +1807,7 @@ libgnunet_plugin_ats_proportional_init (void *cls) for (c = 0; c < env->network_count; c++) { cur = &s->network_entries[c]; - cur->type = env->networks[c]; + cur->type = c; cur->total_quota_in = env->in_quota[c]; cur->total_quota_out = env->out_quota[c]; cur->desc = GNUNET_ATS_print_network_type (c); diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c index 662935583..6718cae22 100644 --- a/src/ats/plugin_ats_ril.c +++ b/src/ats/plugin_ats_ril.c @@ -2799,7 +2799,7 @@ libgnunet_plugin_ats_ril_init (void *cls) for (c = 0; c < env->network_count; c++) { cur = &solver->network_entries[c]; - cur->type = env->networks[c]; + cur->type = c; cur->bw_in_available = env->in_quota[c]; cur->bw_out_available = env->out_quota[c]; LOG(GNUNET_ERROR_TYPE_DEBUG, "init() Quotas for %s network: IN %llu - OUT %llu\n", GNUNET_ATS_print_network_type(cur->type), cur->bw_in_available/1024, cur->bw_out_available/1024); diff --git a/src/include/gnunet_ats_plugin.h b/src/include/gnunet_ats_plugin.h index 36a49d252..bec94b31b 100644 --- a/src/include/gnunet_ats_plugin.h +++ b/src/include/gnunet_ats_plugin.h @@ -464,14 +464,10 @@ struct GNUNET_ATS_PluginEnvironment GAS_solver_information_callback info_cb; /** - * Available networks + * Number of networks available, size of the @e out_quota + * and @e in_quota arrays. */ - int networks[GNUNET_ATS_NetworkTypeCount]; - - /** - * Number of networks available - */ - int network_count; + unsigned int network_count; /** * Array of configured outbound quotas diff --git a/src/include/gnunet_ats_service.h b/src/include/gnunet_ats_service.h index 63c560487..e4070c40f 100644 --- a/src/include/gnunet_ats_service.h +++ b/src/include/gnunet_ats_service.h @@ -30,12 +30,6 @@ #include "gnunet_util_lib.h" #include "gnunet_hello_lib.h" -/** - * Number of network types supported by ATS - */ -#define GNUNET_ATS_NetworkTypeCount 6 - - /** * Types of networks (with separate quotas) we support. */ @@ -70,14 +64,13 @@ enum GNUNET_ATS_Network_Type * Bluetooth LAN */ GNUNET_ATS_NET_BT = 5 -}; - /** - * ATS network types as array initializer + * Number of network types supported by ATS */ -#define GNUNET_ATS_NetworkType { GNUNET_ATS_NET_UNSPECIFIED, GNUNET_ATS_NET_LOOPBACK, GNUNET_ATS_NET_LAN, GNUNET_ATS_NET_WAN, GNUNET_ATS_NET_WLAN, GNUNET_ATS_NET_BT } +#define GNUNET_ATS_NetworkTypeCount 6 +}; /**