diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-08-05 15:42:40 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-08-05 15:42:40 +0000 |
commit | f52b27f49550725feebd74567b5e014122d05369 (patch) | |
tree | 9245ef11530a2aecf7ea5070becc5121f9bb648e /src | |
parent | 3e6df453129fd53ff09c342c4d7b4350afb8929a (diff) | |
download | gnunet-f52b27f49550725feebd74567b5e014122d05369.tar.gz gnunet-f52b27f49550725feebd74567b5e014122d05369.zip |
making things work a bit nicer
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-dht-driver.c | 158 | ||||
-rw-r--r-- | src/dht/test_dht_multipeer.c | 5 |
2 files changed, 136 insertions, 27 deletions
diff --git a/src/dht/gnunet-dht-driver.c b/src/dht/gnunet-dht-driver.c index dd2ffe1b3..2fd615914 100644 --- a/src/dht/gnunet-dht-driver.c +++ b/src/dht/gnunet-dht-driver.c | |||
@@ -39,6 +39,8 @@ | |||
39 | /* Timeout for waiting for (individual) replies to get requests */ | 39 | /* Timeout for waiting for (individual) replies to get requests */ |
40 | #define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | 40 | #define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) |
41 | 41 | ||
42 | #define DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90) | ||
43 | |||
42 | /* Timeout for waiting for gets to be sent to the service */ | 44 | /* Timeout for waiting for gets to be sent to the service */ |
43 | #define DEFAULT_GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | 45 | #define DEFAULT_GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) |
44 | 46 | ||
@@ -140,6 +142,18 @@ struct ProgressMeter | |||
140 | char *startup_string; | 142 | char *startup_string; |
141 | }; | 143 | }; |
142 | 144 | ||
145 | /** | ||
146 | * Context for getting a topology, logging it, and continuing | ||
147 | * on with some next operation. | ||
148 | */ | ||
149 | struct TopologyIteratorContext | ||
150 | { | ||
151 | unsigned int total_connections; | ||
152 | GNUNET_SCHEDULER_Task cont; | ||
153 | void *cls; | ||
154 | struct GNUNET_TIME_Relative timeout; | ||
155 | }; | ||
156 | |||
143 | /* Globals */ | 157 | /* Globals */ |
144 | 158 | ||
145 | /** | 159 | /** |
@@ -212,6 +226,11 @@ static struct GNUNET_TESTING_PeerGroup *pg; | |||
212 | static struct GNUNET_SCHEDULER_Handle *sched; | 226 | static struct GNUNET_SCHEDULER_Handle *sched; |
213 | 227 | ||
214 | /** | 228 | /** |
229 | * Global config handle. | ||
230 | */ | ||
231 | const struct GNUNET_CONFIGURATION_Handle *config; | ||
232 | |||
233 | /** | ||
215 | * Total number of peers to run, set based on config file. | 234 | * Total number of peers to run, set based on config file. |
216 | */ | 235 | */ |
217 | static unsigned long long num_peers; | 236 | static unsigned long long num_peers; |
@@ -448,6 +467,45 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
448 | ok = 0; | 467 | ok = 0; |
449 | } | 468 | } |
450 | 469 | ||
470 | /** | ||
471 | * Callback for iterating over all the peer connections of a peer group. | ||
472 | */ | ||
473 | void log_topology_cb (void *cls, | ||
474 | const struct GNUNET_PeerIdentity *first, | ||
475 | const struct GNUNET_PeerIdentity *second, | ||
476 | struct GNUNET_TIME_Relative latency, | ||
477 | uint32_t distance, | ||
478 | const char *emsg) | ||
479 | { | ||
480 | struct TopologyIteratorContext *topo_ctx = cls; | ||
481 | if ((first != NULL) && (second != NULL)) | ||
482 | { | ||
483 | topo_ctx->total_connections++; | ||
484 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(config, "dht_testing", "mysql_logging_extended")) | ||
485 | dhtlog_handle->insert_extended_topology(first, second); | ||
486 | } | ||
487 | else | ||
488 | { | ||
489 | GNUNET_assert(dhtlog_handle != NULL); | ||
490 | fprintf(stderr, "topology iteration finished (%u connections), scheduling continuation\n", topo_ctx->total_connections); | ||
491 | dhtlog_handle->update_topology(topo_ctx->total_connections); | ||
492 | GNUNET_SCHEDULER_add_now (sched, topo_ctx->cont, topo_ctx->cls); | ||
493 | GNUNET_free(topo_ctx); | ||
494 | } | ||
495 | } | ||
496 | |||
497 | /** | ||
498 | * Connect to all peers in the peer group and iterate over their | ||
499 | * connections. | ||
500 | */ | ||
501 | static void | ||
502 | capture_current_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
503 | { | ||
504 | struct TopologyIteratorContext *topo_ctx = cls; | ||
505 | dhtlog_handle->insert_topology(0); | ||
506 | GNUNET_TESTING_get_topology (pg, &log_topology_cb, topo_ctx); | ||
507 | } | ||
508 | |||
451 | 509 | ||
452 | /** | 510 | /** |
453 | * Check if the get_handle is being used, if so stop the request. Either | 511 | * Check if the get_handle is being used, if so stop the request. Either |
@@ -484,7 +542,6 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
484 | 542 | ||
485 | GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL); | 543 | GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL); |
486 | 544 | ||
487 | /* FIXME: optionally get stats for dropped messages, etc. */ | ||
488 | if (dhtlog_handle != NULL) | 545 | if (dhtlog_handle != NULL) |
489 | { | 546 | { |
490 | fprintf(stderr, "Update trial endtime\n"); | 547 | fprintf(stderr, "Update trial endtime\n"); |
@@ -512,6 +569,7 @@ static void | |||
512 | get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 569 | get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
513 | { | 570 | { |
514 | struct TestGetContext *test_get = cls; | 571 | struct TestGetContext *test_get = cls; |
572 | struct TopologyIteratorContext *topo_ctx; | ||
515 | outstanding_gets--; /* GET is really finished */ | 573 | outstanding_gets--; /* GET is really finished */ |
516 | GNUNET_DHT_disconnect(test_get->dht_handle); | 574 | GNUNET_DHT_disconnect(test_get->dht_handle); |
517 | test_get->dht_handle = NULL; | 575 | test_get->dht_handle = NULL; |
@@ -520,15 +578,18 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
520 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); | 578 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); |
521 | #endif | 579 | #endif |
522 | update_meter(get_meter); | 580 | update_meter(get_meter); |
523 | if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */ | 581 | if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) |
524 | { | ||
525 | GNUNET_SCHEDULER_cancel(sched, die_task); | ||
526 | GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); | ||
527 | } | ||
528 | else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */ | ||
529 | { | 582 | { |
530 | GNUNET_SCHEDULER_cancel(sched, die_task); | 583 | GNUNET_SCHEDULER_cancel(sched, die_task); |
531 | GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); | 584 | //GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); |
585 | if (dhtlog_handle != NULL) | ||
586 | { | ||
587 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); | ||
588 | topo_ctx->cont = &finish_testing; | ||
589 | GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx); | ||
590 | } | ||
591 | else | ||
592 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | ||
532 | } | 593 | } |
533 | } | 594 | } |
534 | 595 | ||
@@ -658,6 +719,7 @@ static void | |||
658 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | 719 | put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) |
659 | { | 720 | { |
660 | struct TestPutContext *test_put = cls; | 721 | struct TestPutContext *test_put = cls; |
722 | struct TopologyIteratorContext *topo_ctx; | ||
661 | outstanding_puts--; | 723 | outstanding_puts--; |
662 | puts_completed++; | 724 | puts_completed++; |
663 | 725 | ||
@@ -670,9 +732,23 @@ put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
670 | { | 732 | { |
671 | GNUNET_assert(outstanding_puts == 0); | 733 | GNUNET_assert(outstanding_puts == 0); |
672 | GNUNET_SCHEDULER_cancel (sched, die_task); | 734 | GNUNET_SCHEDULER_cancel (sched, die_task); |
673 | die_task = GNUNET_SCHEDULER_add_delayed (sched, all_get_timeout, | 735 | if (dhtlog_handle != NULL) |
674 | &end_badly, "from do gets"); | 736 | { |
675 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &do_get, all_gets); | 737 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); |
738 | topo_ctx->cont = &do_get; | ||
739 | topo_ctx->cls = all_gets; | ||
740 | topo_ctx->timeout = DEFAULT_GET_TIMEOUT; | ||
741 | die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout), DEFAULT_TOPOLOGY_CAPTURE_TIMEOUT), | ||
742 | &end_badly, "from do gets"); | ||
743 | GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx); | ||
744 | } | ||
745 | else | ||
746 | { | ||
747 | die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_add(DEFAULT_GET_TIMEOUT, all_get_timeout), | ||
748 | &end_badly, "from do gets"); | ||
749 | GNUNET_SCHEDULER_add_delayed(sched, DEFAULT_GET_TIMEOUT, &do_get, all_gets); | ||
750 | GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); | ||
751 | } | ||
676 | return; | 752 | return; |
677 | } | 753 | } |
678 | } | 754 | } |
@@ -764,6 +840,26 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
764 | &end_badly, "from do puts"); | 840 | &end_badly, "from do puts"); |
765 | GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts); | 841 | GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts); |
766 | } | 842 | } |
843 | |||
844 | /** | ||
845 | * Set up some all of the put and get operations we want | ||
846 | * to do. Allocate data structure for each, add to list, | ||
847 | * then call actual insert functions. | ||
848 | */ | ||
849 | static void | ||
850 | continue_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | ||
851 | { | ||
852 | struct TopologyIteratorContext *topo_ctx; | ||
853 | if (dhtlog_handle != NULL) | ||
854 | { | ||
855 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); | ||
856 | topo_ctx->cont = &setup_puts_and_gets; | ||
857 | GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &capture_current_topology, topo_ctx); | ||
858 | } | ||
859 | else | ||
860 | GNUNET_SCHEDULER_add_now (sched, &setup_puts_and_gets, NULL); | ||
861 | } | ||
862 | |||
767 | /** | 863 | /** |
768 | * This function is called whenever a connection attempt is finished between two of | 864 | * This function is called whenever a connection attempt is finished between two of |
769 | * the started peers (started with GNUNET_TESTING_daemons_start). The total | 865 | * the started peers (started with GNUNET_TESTING_daemons_start). The total |
@@ -784,6 +880,7 @@ topology_callback (void *cls, | |||
784 | struct GNUNET_TESTING_Daemon *second_daemon, | 880 | struct GNUNET_TESTING_Daemon *second_daemon, |
785 | const char *emsg) | 881 | const char *emsg) |
786 | { | 882 | { |
883 | struct TopologyIteratorContext *topo_ctx; | ||
787 | if (emsg == NULL) | 884 | if (emsg == NULL) |
788 | { | 885 | { |
789 | total_connections++; | 886 | total_connections++; |
@@ -812,13 +909,22 @@ topology_callback (void *cls, | |||
812 | total_connections); | 909 | total_connections); |
813 | #endif | 910 | #endif |
814 | if (dhtlog_handle != NULL) | 911 | if (dhtlog_handle != NULL) |
815 | dhtlog_handle->update_connections (trialuid, total_connections); | 912 | { |
913 | dhtlog_handle->update_connections (trialuid, total_connections); | ||
914 | dhtlog_handle->insert_topology(expected_connections); | ||
915 | } | ||
816 | 916 | ||
817 | GNUNET_SCHEDULER_cancel (sched, die_task); | 917 | GNUNET_SCHEDULER_cancel (sched, die_task); |
818 | /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT, | 918 | /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT, |
819 | &end_badly, "from setup puts/gets");*/ | 919 | &end_badly, "from setup puts/gets");*/ |
820 | 920 | if ((dhtlog_handle != NULL) && (settle_time > 0)) | |
821 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &setup_puts_and_gets, NULL); | 921 | { |
922 | topo_ctx = GNUNET_malloc(sizeof(struct TopologyIteratorContext)); | ||
923 | topo_ctx->cont = &continue_puts_and_gets; | ||
924 | GNUNET_SCHEDULER_add_now(sched, &capture_current_topology, topo_ctx); | ||
925 | } | ||
926 | else | ||
927 | GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &continue_puts_and_gets, NULL); | ||
822 | } | 928 | } |
823 | else if (total_connections + failed_connections == expected_connections) | 929 | else if (total_connections + failed_connections == expected_connections) |
824 | { | 930 | { |
@@ -862,6 +968,7 @@ peers_started_callback (void *cls, | |||
862 | if ((pg != NULL) && (peers_left == 0)) | 968 | if ((pg != NULL) && (peers_left == 0)) |
863 | { | 969 | { |
864 | expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier); | 970 | expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier); |
971 | |||
865 | peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES); | 972 | peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES); |
866 | #if VERBOSE | 973 | #if VERBOSE |
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -957,28 +1064,27 @@ run (void *cls, | |||
957 | char *const *args, | 1064 | char *const *args, |
958 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) | 1065 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) |
959 | { | 1066 | { |
1067 | struct stat frstat; | ||
960 | struct GNUNET_TESTING_Host *hosts; | 1068 | struct GNUNET_TESTING_Host *hosts; |
961 | struct GNUNET_TESTING_Host *temphost; | 1069 | struct GNUNET_TESTING_Host *temphost; |
962 | char * topology_str; | 1070 | char *topology_str; |
963 | char * connect_topology_str; | 1071 | char *connect_topology_str; |
964 | char * blacklist_topology_str; | 1072 | char *blacklist_topology_str; |
965 | char * connect_topology_option_str; | 1073 | char *connect_topology_option_str; |
966 | char * connect_topology_option_modifier_string; | 1074 | char *connect_topology_option_modifier_string; |
967 | char *trialmessage; | 1075 | char *trialmessage; |
968 | char * topology_percentage_str; | 1076 | char *topology_percentage_str; |
969 | float topology_percentage; | 1077 | float topology_percentage; |
970 | char * topology_probability_str; | 1078 | char *topology_probability_str; |
971 | char * hostfile; | 1079 | char *hostfile; |
972 | float topology_probability; | 1080 | float topology_probability; |
973 | unsigned long long temp_config_number; | 1081 | unsigned long long temp_config_number; |
974 | char *buf; | 1082 | char *buf; |
975 | char *data; | 1083 | char *data; |
976 | |||
977 | struct stat frstat; | ||
978 | int count; | 1084 | int count; |
979 | 1085 | ||
980 | sched = s; | 1086 | sched = s; |
981 | 1087 | config = cfg; | |
982 | /* Get path from configuration file */ | 1088 | /* Get path from configuration file */ |
983 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) | 1089 | if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) |
984 | { | 1090 | { |
@@ -989,7 +1095,7 @@ run (void *cls, | |||
989 | /** | 1095 | /** |
990 | * Get DHT specific testing options. | 1096 | * Get DHT specific testing options. |
991 | */ | 1097 | */ |
992 | if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging"))|| | 1098 | if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging")) || |
993 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended"))) | 1099 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended"))) |
994 | { | 1100 | { |
995 | dhtlog_handle = GNUNET_DHTLOG_connect(cfg); | 1101 | dhtlog_handle = GNUNET_DHTLOG_connect(cfg); |
diff --git a/src/dht/test_dht_multipeer.c b/src/dht/test_dht_multipeer.c index 3762bdaf9..73382494b 100644 --- a/src/dht/test_dht_multipeer.c +++ b/src/dht/test_dht_multipeer.c | |||
@@ -340,7 +340,8 @@ get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); | 340 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed); |
341 | if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */ | 341 | if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */ |
342 | { | 342 | { |
343 | GNUNET_SCHEDULER_cancel(sched, die_task); | 343 | GNUNET_SCHEDULER_cancel (sched, die_task); |
344 | //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5), &get_topology, NULL); | ||
344 | GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); | 345 | GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL); |
345 | } | 346 | } |
346 | else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */ | 347 | else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */ |
@@ -572,6 +573,8 @@ setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) | |||
572 | 573 | ||
573 | GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts); | 574 | GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts); |
574 | } | 575 | } |
576 | |||
577 | |||
575 | /** | 578 | /** |
576 | * This function is called whenever a connection attempt is finished between two of | 579 | * This function is called whenever a connection attempt is finished between two of |
577 | * the started peers (started with GNUNET_TESTING_daemons_start). The total | 580 | * the started peers (started with GNUNET_TESTING_daemons_start). The total |