diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-08 13:04:27 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-08 13:04:27 +0000 |
commit | b644458a5800a53f3b0196fe559d51a21dca70b9 (patch) | |
tree | fa7f8b8a497d5306b68f9f2fe41e565365f8c5c9 /src/ats/gnunet-ats-solver-eval.c | |
parent | 6115a1150c65bd4a33ed61c6e96594c4a73d86ac (diff) | |
download | gnunet-b644458a5800a53f3b0196fe559d51a21dca70b9.tar.gz gnunet-b644458a5800a53f3b0196fe559d51a21dca70b9.zip |
simplify normalization logic, also have clients access norm array of address directly
Diffstat (limited to 'src/ats/gnunet-ats-solver-eval.c')
-rw-r--r-- | src/ats/gnunet-ats-solver-eval.c | 59 |
1 files changed, 13 insertions, 46 deletions
diff --git a/src/ats/gnunet-ats-solver-eval.c b/src/ats/gnunet-ats-solver-eval.c index 5bffb6821..e1340580e 100644 --- a/src/ats/gnunet-ats-solver-eval.c +++ b/src/ats/gnunet-ats-solver-eval.c | |||
@@ -87,8 +87,6 @@ static int res; | |||
87 | static void | 87 | static void |
88 | end_now (); | 88 | end_now (); |
89 | 89 | ||
90 | const double * | ||
91 | get_property_cb (void *cls, const struct ATS_Address *address); | ||
92 | 90 | ||
93 | static char * | 91 | static char * |
94 | print_generator_type (enum GeneratorType g) | 92 | print_generator_type (enum GeneratorType g) |
@@ -140,23 +138,9 @@ find_address_by_id (struct TestPeer *peer, int aid) | |||
140 | } | 138 | } |
141 | 139 | ||
142 | 140 | ||
143 | static struct TestAddress * | ||
144 | find_address_by_ats_address (struct TestPeer *p, const struct ATS_Address *addr) | ||
145 | { | ||
146 | struct TestAddress *cur; | ||
147 | for (cur = p->addr_head; NULL != cur; cur = cur->next) | ||
148 | if ((0 == strcmp(cur->ats_addr->plugin, addr->plugin)) && | ||
149 | (cur->ats_addr->addr_len == addr->addr_len) && | ||
150 | (0 == memcmp (cur->ats_addr->addr, addr->addr, addr->addr_len))) | ||
151 | return cur; | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | 141 | /** |
157 | * Logging | 142 | * Logging |
158 | */ | 143 | */ |
159 | |||
160 | void | 144 | void |
161 | GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) | 145 | GNUNET_ATS_solver_logging_now (struct LoggingHandle *l) |
162 | { | 146 | { |
@@ -660,13 +644,12 @@ set_prop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
660 | 644 | ||
661 | pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, | 645 | pg->set_task = GNUNET_SCHEDULER_add_delayed (pg->frequency, |
662 | &set_prop_task, pg); | 646 | &set_prop_task, pg); |
663 | |||
664 | } | 647 | } |
665 | 648 | ||
649 | |||
666 | /** | 650 | /** |
667 | * Set ats_property to 0 to find all pgs | 651 | * Set ats_property to 0 to find all pgs |
668 | */ | 652 | */ |
669 | |||
670 | static struct PropertyGenerator * | 653 | static struct PropertyGenerator * |
671 | find_prop_gen (unsigned int peer, unsigned int address, | 654 | find_prop_gen (unsigned int peer, unsigned int address, |
672 | uint32_t ats_property) | 655 | uint32_t ats_property) |
@@ -786,7 +769,6 @@ GNUNET_ATS_solver_generate_property_start (unsigned int peer, | |||
786 | } | 769 | } |
787 | 770 | ||
788 | 771 | ||
789 | |||
790 | /** | 772 | /** |
791 | * Stop all preferences generators | 773 | * Stop all preferences generators |
792 | */ | 774 | */ |
@@ -1033,7 +1015,8 @@ GNUNET_ATS_solver_generate_preferences_stop (struct PreferenceGenerator *pg) | |||
1033 | GNUNET_free (pg); | 1015 | GNUNET_free (pg); |
1034 | } | 1016 | } |
1035 | 1017 | ||
1036 | struct TestAddress* | 1018 | |
1019 | static struct TestAddress* | ||
1037 | find_active_address (struct TestPeer *p) | 1020 | find_active_address (struct TestPeer *p) |
1038 | { | 1021 | { |
1039 | struct TestAddress *cur; | 1022 | struct TestAddress *cur; |
@@ -1043,6 +1026,7 @@ find_active_address (struct TestPeer *p) | |||
1043 | return NULL; | 1026 | return NULL; |
1044 | } | 1027 | } |
1045 | 1028 | ||
1029 | |||
1046 | /** | 1030 | /** |
1047 | * Generate between the source master and the partner and set property with a | 1031 | * Generate between the source master and the partner and set property with a |
1048 | * value depending on the generator. | 1032 | * value depending on the generator. |
@@ -1129,14 +1113,12 @@ GNUNET_ATS_solver_generate_preferences_start (unsigned int peer, | |||
1129 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) | 1113 | if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us != feedback_frequency.rel_value_us) |
1130 | { | 1114 | { |
1131 | struct TestAddress * addr = find_active_address(p); | 1115 | struct TestAddress * addr = find_active_address(p); |
1132 | const double *properties = get_property_cb (NULL, addr->ats_addr); | ||
1133 | 1116 | ||
1134 | pg->last_assigned_bw_in = p->assigned_bw_in; | 1117 | pg->last_assigned_bw_in = p->assigned_bw_in; |
1135 | pg->last_assigned_bw_out = p->assigned_bw_out; | 1118 | pg->last_assigned_bw_out = p->assigned_bw_out; |
1136 | pg->feedback_bw_in_acc = 0; | 1119 | pg->feedback_bw_in_acc = 0; |
1137 | pg->feedback_bw_out_acc = 0; | 1120 | pg->feedback_bw_out_acc = 0; |
1138 | 1121 | pg->last_delay_value = addr->prop_norm[GNUNET_ATS_QUALITY_NET_DELAY]; | |
1139 | pg->last_delay_value = properties[GNUNET_ATS_QUALITY_NET_DELAY]; | ||
1140 | pg->feedback_delay_acc = 0; | 1122 | pg->feedback_delay_acc = 0; |
1141 | 1123 | ||
1142 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); | 1124 | pg->feedback_last_bw_update = GNUNET_TIME_absolute_get(); |
@@ -1172,8 +1154,7 @@ GNUNET_ATS_solver_generate_preferences_stop_all () | |||
1172 | /** | 1154 | /** |
1173 | * Experiments | 1155 | * Experiments |
1174 | */ | 1156 | */ |
1175 | 1157 | static const char * | |
1176 | const char * | ||
1177 | print_op (enum OperationType op) | 1158 | print_op (enum OperationType op) |
1178 | { | 1159 | { |
1179 | switch (op) { | 1160 | switch (op) { |
@@ -1199,6 +1180,7 @@ print_op (enum OperationType op) | |||
1199 | return ""; | 1180 | return ""; |
1200 | } | 1181 | } |
1201 | 1182 | ||
1183 | |||
1202 | static struct Experiment * | 1184 | static struct Experiment * |
1203 | create_experiment () | 1185 | create_experiment () |
1204 | { | 1186 | { |
@@ -1210,6 +1192,7 @@ create_experiment () | |||
1210 | return e; | 1192 | return e; |
1211 | } | 1193 | } |
1212 | 1194 | ||
1195 | |||
1213 | static void | 1196 | static void |
1214 | free_experiment (struct Experiment *e) | 1197 | free_experiment (struct Experiment *e) |
1215 | { | 1198 | { |
@@ -1368,6 +1351,7 @@ load_op_add_address (struct GNUNET_ATS_TEST_Operation *o, | |||
1368 | return GNUNET_OK; | 1351 | return GNUNET_OK; |
1369 | } | 1352 | } |
1370 | 1353 | ||
1354 | |||
1371 | static int | 1355 | static int |
1372 | load_op_del_address (struct GNUNET_ATS_TEST_Operation *o, | 1356 | load_op_del_address (struct GNUNET_ATS_TEST_Operation *o, |
1373 | struct Episode *e, | 1357 | struct Episode *e, |
@@ -1447,6 +1431,7 @@ load_op_del_address (struct GNUNET_ATS_TEST_Operation *o, | |||
1447 | return GNUNET_OK; | 1431 | return GNUNET_OK; |
1448 | } | 1432 | } |
1449 | 1433 | ||
1434 | |||
1450 | static enum GNUNET_ATS_Property | 1435 | static enum GNUNET_ATS_Property |
1451 | parse_preference_string (const char * str) | 1436 | parse_preference_string (const char * str) |
1452 | { | 1437 | { |
@@ -1457,7 +1442,8 @@ parse_preference_string (const char * str) | |||
1457 | if (0 == strcmp(str, props[c])) | 1442 | if (0 == strcmp(str, props[c])) |
1458 | return c; | 1443 | return c; |
1459 | return 0; | 1444 | return 0; |
1460 | }; | 1445 | } |
1446 | |||
1461 | 1447 | ||
1462 | static int | 1448 | static int |
1463 | load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, | 1449 | load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, |
@@ -1628,6 +1614,7 @@ load_op_start_set_preference (struct GNUNET_ATS_TEST_Operation *o, | |||
1628 | return GNUNET_OK; | 1614 | return GNUNET_OK; |
1629 | } | 1615 | } |
1630 | 1616 | ||
1617 | |||
1631 | static int | 1618 | static int |
1632 | load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o, | 1619 | load_op_stop_set_preference (struct GNUNET_ATS_TEST_Operation *o, |
1633 | struct Episode *e, | 1620 | struct Episode *e, |
@@ -3028,25 +3015,6 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
3028 | } | 3015 | } |
3029 | 3016 | ||
3030 | 3017 | ||
3031 | const double * | ||
3032 | get_property_cb (void *cls, const struct ATS_Address *address) | ||
3033 | { | ||
3034 | struct TestPeer *p; | ||
3035 | struct TestAddress *a; | ||
3036 | |||
3037 | if (GNUNET_YES == opt_disable_normalization) | ||
3038 | { | ||
3039 | p = find_peer_by_pid (&address->peer); | ||
3040 | if (NULL == p) | ||
3041 | return NULL; | ||
3042 | a = find_address_by_ats_address (p, address); | ||
3043 | return a->prop_abs; | ||
3044 | } | ||
3045 | return GAS_normalization_get_properties (NULL, | ||
3046 | address); | ||
3047 | } | ||
3048 | |||
3049 | |||
3050 | struct SolverHandle * | 3018 | struct SolverHandle * |
3051 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | 3019 | GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) |
3052 | { | 3020 | { |
@@ -3081,7 +3049,6 @@ GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) | |||
3081 | sh->env.addresses = sh->addresses; | 3049 | sh->env.addresses = sh->addresses; |
3082 | sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; | 3050 | sh->env.bandwidth_changed_cb = &solver_bandwidth_changed_cb; |
3083 | sh->env.get_preferences = &get_preferences_cb; | 3051 | sh->env.get_preferences = &get_preferences_cb; |
3084 | sh->env.get_property = &get_property_cb; | ||
3085 | sh->env.network_count = GNUNET_ATS_NetworkTypeCount; | 3052 | sh->env.network_count = GNUNET_ATS_NetworkTypeCount; |
3086 | sh->env.info_cb = &solver_info_cb; | 3053 | sh->env.info_cb = &solver_info_cb; |
3087 | sh->env.network_count = GNUNET_ATS_NetworkTypeCount; | 3054 | sh->env.network_count = GNUNET_ATS_NetworkTypeCount; |