diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-02-05 21:41:58 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-02-05 21:41:58 +0000 |
commit | b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5 (patch) | |
tree | f93ff7c7d94c81f5182e1c4bc7fd829f4fc9a609 /src/ats/perf_ats_solver.c | |
parent | d4cb0035c1248e050d906e9018d36a9f5d19eb73 (diff) | |
download | gnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.tar.gz gnunet-b8d5c4c9220576e85b4eec4c7ffa0390ba887fb5.zip |
first pass at cleaning up ATS plugin API
Diffstat (limited to 'src/ats/perf_ats_solver.c')
-rw-r--r-- | src/ats/perf_ats_solver.c | 135 |
1 files changed, 85 insertions, 50 deletions
diff --git a/src/ats/perf_ats_solver.c b/src/ats/perf_ats_solver.c index 769acea99..d81b5779b 100644 --- a/src/ats/perf_ats_solver.c +++ b/src/ats/perf_ats_solver.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet-service-ats_addresses.h" | 29 | #include "gnunet-service-ats_addresses.h" |
30 | #include "gnunet-service-ats_plugins.h" | 30 | #include "gnunet-service-ats_plugins.h" |
31 | #include "gnunet-service-ats_normalization.h" | 31 | #include "gnunet-service-ats_normalization.h" |
32 | #include "gnunet-service-ats_preferences.h" | ||
32 | #include "gnunet_ats_service.h" | 33 | #include "gnunet_ats_service.h" |
33 | #include "gnunet_ats_plugin.h" | 34 | #include "gnunet_ats_plugin.h" |
34 | #include "test_ats_api_common.h" | 35 | #include "test_ats_api_common.h" |
@@ -58,7 +59,7 @@ struct PerfHandle | |||
58 | /** | 59 | /** |
59 | * Solver handle | 60 | * Solver handle |
60 | */ | 61 | */ |
61 | void *solver; | 62 | struct GNUNET_ATS_SolverFunctions *sf; |
62 | 63 | ||
63 | /** | 64 | /** |
64 | * Statistics stat; | 65 | * Statistics stat; |
@@ -372,7 +373,7 @@ perf_update_address (struct ATS_Address *cur) | |||
372 | GNUNET_i2s (&cur->peer), cur, | 373 | GNUNET_i2s (&cur->peer), cur, |
373 | "GNUNET_ATS_QUALITY_NET_DELAY", | 374 | "GNUNET_ATS_QUALITY_NET_DELAY", |
374 | abs_val, rel_val); | 375 | abs_val, rel_val); |
375 | ph.env.sf.s_address_update_property (ph.solver, cur, | 376 | ph.sf->s_address_update_property (ph.sf->cls, cur, |
376 | GNUNET_ATS_QUALITY_NET_DELAY, | 377 | GNUNET_ATS_QUALITY_NET_DELAY, |
377 | abs_val, rel_val); | 378 | abs_val, rel_val); |
378 | break; | 379 | break; |
@@ -384,7 +385,7 @@ perf_update_address (struct ATS_Address *cur) | |||
384 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", | 385 | "Updating peer `%s' address %p type %s abs val %u rel val %.3f\n", |
385 | GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", | 386 | GNUNET_i2s (&cur->peer), cur, "GNUNET_ATS_QUALITY_NET_DISTANCE", |
386 | abs_val, rel_val); | 387 | abs_val, rel_val); |
387 | ph.env.sf.s_address_update_property (ph.solver, cur, | 388 | ph.sf->s_address_update_property (ph.sf->cls, cur, |
388 | GNUNET_ATS_QUALITY_NET_DISTANCE, | 389 | GNUNET_ATS_QUALITY_NET_DISTANCE, |
389 | abs_val, rel_val); | 390 | abs_val, rel_val); |
390 | break; | 391 | break; |
@@ -423,13 +424,13 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
423 | const double * | 424 | const double * |
424 | get_property_cb (void *cls, const struct ATS_Address *address) | 425 | get_property_cb (void *cls, const struct ATS_Address *address) |
425 | { | 426 | { |
426 | return GAS_normalization_get_properties (NULL, | 427 | return GAS_normalization_get_properties (NULL, |
427 | address); | 428 | address); |
428 | } | 429 | } |
429 | 430 | ||
430 | 431 | ||
431 | static void | 432 | static void |
432 | perf_address_initial_update (void *solver, | 433 | perf_address_initial_update (void *dead, |
433 | struct GNUNET_CONTAINER_MultiPeerMap * addresses, | 434 | struct GNUNET_CONTAINER_MultiPeerMap * addresses, |
434 | struct ATS_Address *address) | 435 | struct ATS_Address *address) |
435 | { | 436 | { |
@@ -437,19 +438,45 @@ perf_address_initial_update (void *solver, | |||
437 | double distance; | 438 | double distance; |
438 | uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 439 | uint32_t random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); |
439 | delay = (100 + (double) random) / 100; | 440 | delay = (100 + (double) random) / 100; |
440 | ph.env.sf.s_address_update_property (solver, address, GNUNET_ATS_QUALITY_NET_DELAY, | 441 | ph.sf->s_address_update_property (ph.sf->cls, |
442 | address, GNUNET_ATS_QUALITY_NET_DELAY, | ||
441 | 100, delay); | 443 | 100, delay); |
442 | 444 | ||
443 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); | 445 | random = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100); |
444 | distance = (100 + (double) random) / 100; | 446 | distance = (100 + (double) random) / 100; |
445 | 447 | ||
446 | ph.env.sf.s_address_update_property (solver, address, | 448 | ph.sf->s_address_update_property (ph.sf->cls, address, |
447 | GNUNET_ATS_QUALITY_NET_DISTANCE, 10, distance); | 449 | GNUNET_ATS_QUALITY_NET_DISTANCE, |
450 | 10, distance); | ||
448 | 451 | ||
449 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 452 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
450 | "Initial update address %p : %.2f %.2f\n", address, delay, distance); | 453 | "Initial update address %p : %.2f %.2f\n", |
454 | address, delay, distance); | ||
451 | } | 455 | } |
452 | 456 | ||
457 | |||
458 | struct DUA_Ctx | ||
459 | { | ||
460 | int r; | ||
461 | int c_cur_a; | ||
462 | }; | ||
463 | |||
464 | |||
465 | static int | ||
466 | do_update_address (void *cls, | ||
467 | const struct GNUNET_PeerIdentity *pid, | ||
468 | void *value) | ||
469 | { | ||
470 | struct DUA_Ctx *ctx = cls; | ||
471 | struct ATS_Address *addr = value; | ||
472 | |||
473 | if (ctx->c_cur_a == ctx->r) | ||
474 | perf_update_address (addr); | ||
475 | ctx->c_cur_a++; | ||
476 | return GNUNET_OK; | ||
477 | } | ||
478 | |||
479 | |||
453 | /** | 480 | /** |
454 | * Update a certain percentage of peers | 481 | * Update a certain percentage of peers |
455 | * | 482 | * |
@@ -457,18 +484,16 @@ perf_address_initial_update (void *solver, | |||
457 | * @param ca the current number of addresses | 484 | * @param ca the current number of addresses |
458 | * @param percentage_peers the percentage of peers to update | 485 | * @param percentage_peers the percentage of peers to update |
459 | */ | 486 | */ |
460 | |||
461 | static void | 487 | static void |
462 | perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers) | 488 | perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percentage_peers) |
463 | { | 489 | { |
464 | struct ATS_Address *cur_address; | ||
465 | int c_peer; | 490 | int c_peer; |
466 | int c_select; | 491 | int c_select; |
467 | int c_cur_p; | 492 | int c_cur_p; |
468 | int c_cur_a; | ||
469 | int r; | 493 | int r; |
470 | int count; | 494 | int count; |
471 | unsigned int m[cp]; | 495 | unsigned int m[cp]; |
496 | struct DUA_Ctx dua_ctx; | ||
472 | 497 | ||
473 | count = cp * ((double) percentage_peers / 100); | 498 | count = cp * ((double) percentage_peers / 100); |
474 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 499 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -496,15 +521,14 @@ perf_update_all_addresses (unsigned int cp, unsigned int ca, unsigned int percen | |||
496 | { | 521 | { |
497 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca); | 522 | r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, ca); |
498 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 523 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
499 | "Updating peer [%u] address [%u]\n", c_cur_p, r); | 524 | "Updating peer [%u] address [%u]\n", c_cur_p, r); |
500 | 525 | ||
501 | c_cur_a = 0; | 526 | dua_ctx.c_cur_a = 0; |
502 | for (cur_address = ph.peers[c_cur_p].head; NULL != cur_address; cur_address = cur_address->next) | 527 | dua_ctx.r = r; |
503 | { | 528 | GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses, |
504 | if (c_cur_a == r) | 529 | &ph.peers[c_cur_p].id, |
505 | perf_update_address (cur_address); | 530 | &do_update_address, |
506 | c_cur_a ++; | 531 | &dua_ctx); |
507 | } | ||
508 | } | 532 | } |
509 | } | 533 | } |
510 | } | 534 | } |
@@ -520,9 +544,9 @@ static struct ATS_Address * | |||
520 | perf_create_address (int cp, int ca) | 544 | perf_create_address (int cp, int ca) |
521 | { | 545 | { |
522 | struct ATS_Address *a; | 546 | struct ATS_Address *a; |
547 | |||
523 | a = create_address (&ph.peers[cp].id, | 548 | a = create_address (&ph.peers[cp].id, |
524 | "Test 1", "test 1", strlen ("test 1") + 1, 0); | 549 | "Test 1", "test 1", strlen ("test 1") + 1, 0); |
525 | GNUNET_CONTAINER_DLL_insert (ph.peers[cp].head, ph.peers[cp].tail, a); | ||
526 | GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a, | 550 | GNUNET_CONTAINER_multipeermap_put (ph.addresses, &ph.peers[cp].id, a, |
527 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 551 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
528 | return a; | 552 | return a; |
@@ -1028,15 +1052,34 @@ write_all_iterations (void) | |||
1028 | GNUNET_free_non_null (data_fn_update); | 1052 | GNUNET_free_non_null (data_fn_update); |
1029 | } | 1053 | } |
1030 | 1054 | ||
1055 | |||
1056 | static int | ||
1057 | do_delete_address (void *cls, | ||
1058 | const struct GNUNET_PeerIdentity *pid, | ||
1059 | void *value) | ||
1060 | { | ||
1061 | struct ATS_Address *cur = value; | ||
1062 | |||
1063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
1064 | "Deleting addresses for peer %u\n", | ||
1065 | pid); | ||
1066 | GNUNET_assert (GNUNET_OK == | ||
1067 | GNUNET_CONTAINER_multipeermap_remove (ph.addresses, | ||
1068 | pid, | ||
1069 | cur)); | ||
1070 | ph.sf->s_del (ph.sf->cls, cur, GNUNET_NO); | ||
1071 | GNUNET_free_non_null (cur->atsi); | ||
1072 | GNUNET_free (cur); | ||
1073 | return GNUNET_OK; | ||
1074 | } | ||
1075 | |||
1076 | |||
1031 | /** | 1077 | /** |
1032 | * Run a performance iteration | 1078 | * Run a performance iteration |
1033 | */ | 1079 | */ |
1034 | |||
1035 | static void | 1080 | static void |
1036 | perf_run_iteration (void) | 1081 | perf_run_iteration (void) |
1037 | { | 1082 | { |
1038 | struct ATS_Address *cur; | ||
1039 | struct ATS_Address *next; | ||
1040 | int cp; | 1083 | int cp; |
1041 | int ca; | 1084 | int ca; |
1042 | int count_p = ph.N_peers_end; | 1085 | int count_p = ph.N_peers_end; |
@@ -1059,7 +1102,7 @@ perf_run_iteration (void) | |||
1059 | if (GNUNET_NO == ph.bulk_running) | 1102 | if (GNUNET_NO == ph.bulk_running) |
1060 | { | 1103 | { |
1061 | ph.bulk_running = GNUNET_YES; | 1104 | ph.bulk_running = GNUNET_YES; |
1062 | ph.env.sf.s_bulk_start (ph.solver); | 1105 | ph.sf->s_bulk_start (ph.sf->cls); |
1063 | } | 1106 | } |
1064 | ph.current_p = cp + 1; | 1107 | ph.current_p = cp + 1; |
1065 | for (ca = 0; ca < count_a; ca++) | 1108 | for (ca = 0; ca < count_a; ca++) |
@@ -1078,16 +1121,16 @@ perf_run_iteration (void) | |||
1078 | cur_addr->atsi_count = 1; | 1121 | cur_addr->atsi_count = 1; |
1079 | cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | 1122 | cur_addr->atsi[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); |
1080 | cur_addr->atsi[0].value = htonl (net); | 1123 | cur_addr->atsi[0].value = htonl (net); |
1081 | ph.env.sf.s_add (ph.solver, cur_addr, net); | 1124 | ph.sf->s_add (ph.sf->cls, cur_addr, net); |
1082 | 1125 | ||
1083 | ph.current_a = ca + 1; | 1126 | ph.current_a = ca + 1; |
1084 | perf_address_initial_update (ph.solver, ph.addresses, cur_addr); | 1127 | perf_address_initial_update (NULL, ph.addresses, cur_addr); |
1085 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1128 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
1086 | "Adding address for peer %u address %u in network %s\n", cp, ca, | 1129 | "Adding address for peer %u address %u in network %s\n", cp, ca, |
1087 | GNUNET_ATS_print_network_type(net)); | 1130 | GNUNET_ATS_print_network_type(net)); |
1088 | } | 1131 | } |
1089 | /* Notify solver about request */ | 1132 | /* Notify solver about request */ |
1090 | ph.env.sf.s_get (ph.solver, &ph.peers[cp].id); | 1133 | ph.sf->s_get (ph.sf->cls, &ph.peers[cp].id); |
1091 | 1134 | ||
1092 | if (cp + 1 >= ph.N_peers_start) | 1135 | if (cp + 1 >= ph.N_peers_start) |
1093 | { | 1136 | { |
@@ -1096,7 +1139,7 @@ perf_run_iteration (void) | |||
1096 | { | 1139 | { |
1097 | ph.expecting_solution = GNUNET_YES; | 1140 | ph.expecting_solution = GNUNET_YES; |
1098 | ph.bulk_running = GNUNET_NO; | 1141 | ph.bulk_running = GNUNET_NO; |
1099 | ph.env.sf.s_bulk_stop (ph.solver); | 1142 | ph.sf->s_bulk_stop (ph.sf->cls); |
1100 | } | 1143 | } |
1101 | else | 1144 | else |
1102 | GNUNET_break (0); | 1145 | GNUNET_break (0); |
@@ -1116,11 +1159,11 @@ perf_run_iteration (void) | |||
1116 | if (GNUNET_NO == ph.bulk_running) | 1159 | if (GNUNET_NO == ph.bulk_running) |
1117 | { | 1160 | { |
1118 | ph.bulk_running = GNUNET_YES; | 1161 | ph.bulk_running = GNUNET_YES; |
1119 | ph.env.sf.s_bulk_start (ph.solver); | 1162 | ph.sf->s_bulk_start (ph.sf->cls); |
1120 | } | 1163 | } |
1121 | perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent); | 1164 | perf_update_all_addresses (cp + 1, ca, ph.opt_update_percent); |
1122 | ph.bulk_running = GNUNET_NO; | 1165 | ph.bulk_running = GNUNET_NO; |
1123 | ph.env.sf.s_bulk_stop (ph.solver); | 1166 | ph.sf->s_bulk_stop (ph.sf->cls); |
1124 | /* Problem is solved by the solver here due to unlocking */ | 1167 | /* Problem is solved by the solver here due to unlocking */ |
1125 | ph.performed_update = GNUNET_NO; | 1168 | ph.performed_update = GNUNET_NO; |
1126 | ph.expecting_solution = GNUNET_NO; | 1169 | ph.expecting_solution = GNUNET_NO; |
@@ -1133,24 +1176,16 @@ perf_run_iteration (void) | |||
1133 | "Done, cleaning up addresses\n"); | 1176 | "Done, cleaning up addresses\n"); |
1134 | if (GNUNET_NO == ph.bulk_running) | 1177 | if (GNUNET_NO == ph.bulk_running) |
1135 | { | 1178 | { |
1136 | ph.env.sf.s_bulk_start (ph.solver); | 1179 | ph.sf->s_bulk_start (ph.sf->cls); |
1137 | ph.bulk_running = GNUNET_YES; | 1180 | ph.bulk_running = GNUNET_YES; |
1138 | } | 1181 | } |
1139 | 1182 | ||
1140 | for (cp = 0; cp < count_p; cp++) | 1183 | for (cp = 0; cp < count_p; cp++) |
1141 | { | 1184 | { |
1142 | for (cur = ph.peers[cp].head; cur != NULL ; cur = next) | 1185 | GNUNET_CONTAINER_multipeermap_get_multiple (ph.addresses, |
1143 | { | 1186 | &ph.peers[cp].id, |
1144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1187 | &do_delete_address, |
1145 | "Deleting addresses for peer %u\n", cp); | 1188 | NULL); |
1146 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove (ph.addresses, | ||
1147 | &ph.peers[cp].id, cur)); | ||
1148 | ph.env.sf.s_del (ph.solver, cur, GNUNET_NO); | ||
1149 | next = cur->next; | ||
1150 | GNUNET_CONTAINER_DLL_remove(ph.peers[cp].head, ph.peers[cp].tail, cur); | ||
1151 | GNUNET_free_non_null (cur->atsi); | ||
1152 | GNUNET_free (cur); | ||
1153 | } | ||
1154 | } | 1189 | } |
1155 | 1190 | ||
1156 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1191 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, |
@@ -1271,7 +1306,6 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1271 | ph.env.get_property = &get_property_cb; | 1306 | ph.env.get_property = &get_property_cb; |
1272 | ph.env.network_count = GNUNET_ATS_NetworkTypeCount; | 1307 | ph.env.network_count = GNUNET_ATS_NetworkTypeCount; |
1273 | ph.env.info_cb = &solver_info_cb; | 1308 | ph.env.info_cb = &solver_info_cb; |
1274 | ph.env.info_cb_cls = NULL; | ||
1275 | 1309 | ||
1276 | int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; | 1310 | int networks[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType; |
1277 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) | 1311 | for (c = 0; c < GNUNET_ATS_NetworkTypeCount; c++) |
@@ -1288,9 +1322,10 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1288 | 1322 | ||
1289 | GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string); | 1323 | GNUNET_asprintf (&plugin, "libgnunet_plugin_ats_%s", ph.ats_string); |
1290 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string); | 1324 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s'\n"), ph.ats_string); |
1291 | if (NULL == (ph.solver = GNUNET_PLUGIN_load (plugin, &ph.env))) | 1325 | if (NULL == (ph.sf = GNUNET_PLUGIN_load (plugin, &ph.env))) |
1292 | { | 1326 | { |
1293 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver `%s'!\n"), plugin); | 1327 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1328 | _("Failed to initialize solver `%s'!\n"), plugin); | ||
1294 | ret = 1; | 1329 | ret = 1; |
1295 | return; | 1330 | return; |
1296 | } | 1331 | } |
@@ -1308,7 +1343,8 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1308 | 1343 | ||
1309 | /* Unload solver*/ | 1344 | /* Unload solver*/ |
1310 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string); | 1345 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Unloading solver `%s'\n"), ph.ats_string); |
1311 | GNUNET_PLUGIN_unload (plugin, ph.solver); | 1346 | GNUNET_PLUGIN_unload (plugin, ph.sf); |
1347 | ph.sf = NULL; | ||
1312 | GNUNET_free (plugin); | 1348 | GNUNET_free (plugin); |
1313 | for (c = 0; c < ph.total_iterations; c++ ) | 1349 | for (c = 0; c < ph.total_iterations; c++ ) |
1314 | { | 1350 | { |
@@ -1328,7 +1364,6 @@ run (void *cls, char * const *args, const char *cfgfile, | |||
1328 | 1364 | ||
1329 | GNUNET_CONFIGURATION_destroy (solver_cfg); | 1365 | GNUNET_CONFIGURATION_destroy (solver_cfg); |
1330 | GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO); | 1366 | GNUNET_STATISTICS_destroy (ph.stat, GNUNET_NO); |
1331 | ph.solver = NULL; | ||
1332 | } | 1367 | } |
1333 | 1368 | ||
1334 | /** | 1369 | /** |