aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-10-28 22:35:32 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-10-28 22:35:32 +0000
commit5adb26f40e80ead79d64dee3c69904fcf8056214 (patch)
treec3495ec3e0b28d06c4d263e63e35bb0c0b69a173
parent8ec56983556915364a1f35dd8bacadbcbcf54fb0 (diff)
downloadgnunet-5adb26f40e80ead79d64dee3c69904fcf8056214.tar.gz
gnunet-5adb26f40e80ead79d64dee3c69904fcf8056214.zip
batch regex announcing in profiler
-rw-r--r--src/mesh/gnunet-regex-profiler.c188
1 files changed, 123 insertions, 65 deletions
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c
index f36a04ec6..5e54ea3ba 100644
--- a/src/mesh/gnunet-regex-profiler.c
+++ b/src/mesh/gnunet-regex-profiler.c
@@ -343,6 +343,16 @@ static char *data_filename;
343 */ 343 */
344static unsigned int max_path_compression; 344static unsigned int max_path_compression;
345 345
346/**
347 * Announce delay between regex announcing.
348 */
349static struct GNUNET_TIME_Relative announce_delay = { 10000 };
350
351/**
352 * Concurrent announce batch size.
353 */
354static unsigned int announce_batch_size;
355
346 356
347/******************************************************************************/ 357/******************************************************************************/
348/****************************** DECLARATIONS ********************************/ 358/****************************** DECLARATIONS ********************************/
@@ -819,6 +829,99 @@ do_connect_by_string (void *cls,
819 829
820 830
821/** 831/**
832 * Announce regex task that announces the regexes stored in the peers policy file.
833 *
834 * @param cls NULL
835 * @param tc the task context
836 */
837static void
838do_announce_regexes (void *cls,
839 const struct GNUNET_SCHEDULER_TaskContext * tc)
840{
841 static unsigned int num_announced_files;
842 struct RegexPeer *peer;
843 char *regex;
844 char *data;
845 char *buf;
846 uint64_t filesize;
847 unsigned int offset;
848 unsigned int limit;
849
850 limit = num_announced_files + announce_batch_size;
851
852 for (; num_announced_files < limit
853 && num_announced_files < num_peers; num_announced_files++)
854 {
855 peer = &peers[num_announced_files];
856
857 GNUNET_assert (NULL != peer->policy_file);
858
859 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
860 "Announcing regexes for peer %u with file %s\n",
861 peer->id, peer->policy_file);
862
863 if (GNUNET_YES != GNUNET_DISK_file_test (peer->policy_file))
864 {
865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
866 "Could not find policy file %s\n", peer->policy_file);
867 return;
868 }
869 if (GNUNET_OK != GNUNET_DISK_file_size (peer->policy_file, &filesize, GNUNET_YES, GNUNET_YES))
870 filesize = 0;
871 if (0 == filesize)
872 {
873 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", peer->policy_file);
874 return;
875 }
876 data = GNUNET_malloc (filesize);
877 if (filesize != GNUNET_DISK_fn_read (peer->policy_file, data, filesize))
878 {
879 GNUNET_free (data);
880 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
881 peer->policy_file);
882 return;
883 }
884 buf = data;
885 offset = 0;
886 regex = NULL;
887 while (offset < (filesize - 1))
888 {
889 offset++;
890 if (((data[offset] == '\n')) && (buf != &data[offset]))
891 {
892 data[offset] = '\0';
893 regex = buf;
894 GNUNET_assert (NULL != regex);
895 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s on peer %u \n",
896 regex, peer->id);
897 GNUNET_MESH_announce_regex (peer->mesh_handle, regex, max_path_compression);
898 buf = &data[offset + 1];
899 }
900 else if ((data[offset] == '\n') || (data[offset] == '\0'))
901 buf = &data[offset + 1];
902 }
903 GNUNET_free (data);
904 }
905
906 if (num_announced_files < num_peers)
907 GNUNET_SCHEDULER_add_delayed (announce_delay, &do_announce_regexes, NULL);
908 else
909 {
910 printf ("All regexes announced. Waiting %s before starting to search.\n",
911 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
912 fflush (stdout);
913
914 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
915 "All mesh handles connected. Waiting %s before starting to search.\n",
916 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
917
918 search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
919 &do_connect_by_string, NULL);
920 }
921}
922
923
924/**
822 * Mesh connect callback. 925 * Mesh connect callback.
823 * 926 *
824 * @param cls internal peer id. 927 * @param cls internal peer id.
@@ -832,11 +935,6 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
832{ 935{
833 static unsigned int connected_mesh_handles; 936 static unsigned int connected_mesh_handles;
834 struct RegexPeer *peer = (struct RegexPeer *) cls; 937 struct RegexPeer *peer = (struct RegexPeer *) cls;
835 char *regex;
836 char *data;
837 char *buf;
838 uint64_t filesize;
839 unsigned int offset;
840 938
841 if (NULL != emsg) 939 if (NULL != emsg)
842 { 940 {
@@ -846,66 +944,12 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
846 944
847 GNUNET_assert (peer->mesh_op_handle == op); 945 GNUNET_assert (peer->mesh_op_handle == op);
848 GNUNET_assert (peer->mesh_handle == ca_result); 946 GNUNET_assert (peer->mesh_handle == ca_result);
849 GNUNET_assert (NULL != peer->policy_file);
850
851 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
852 "Announcing regexes for peer %u with file %s\n",
853 peer->id, peer->policy_file);
854
855 if (GNUNET_YES != GNUNET_DISK_file_test (peer->policy_file))
856 {
857 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
858 "Could not find policy file %s\n", peer->policy_file);
859 return;
860 }
861 if (GNUNET_OK != GNUNET_DISK_file_size (peer->policy_file, &filesize, GNUNET_YES, GNUNET_YES))
862 filesize = 0;
863 if (0 == filesize)
864 {
865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", peer->policy_file);
866 return;
867 }
868 data = GNUNET_malloc (filesize);
869 if (filesize != GNUNET_DISK_fn_read (peer->policy_file, data, filesize))
870 {
871 GNUNET_free (data);
872 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
873 peer->policy_file);
874 return;
875 }
876 buf = data;
877 offset = 0;
878 regex = NULL;
879 while (offset < (filesize - 1))
880 {
881 offset++;
882 if (((data[offset] == '\n')) && (buf != &data[offset]))
883 {
884 data[offset] = '\0';
885 regex = buf;
886 GNUNET_assert (NULL != regex);
887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s on peer %u \n",
888 regex, peer->id);
889 GNUNET_MESH_announce_regex (peer->mesh_handle, regex, max_path_compression);
890 buf = &data[offset + 1];
891 }
892 else if ((data[offset] == '\n') || (data[offset] == '\0'))
893 buf = &data[offset + 1];
894 }
895 GNUNET_free (data);
896 947
897 if (++connected_mesh_handles == num_peers) 948 if (++connected_mesh_handles == num_peers)
898 { 949 {
899 printf ("\nWaiting %s before starting to search.\n", 950 printf ("\nStarting to announce regexes.\n");
900 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
901 fflush (stdout); 951 fflush (stdout);
902 952 GNUNET_SCHEDULER_add_now (&do_announce_regexes, NULL);
903 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
904 "All mesh handles connected. Waiting %s before starting to search.\n",
905 GNUNET_STRINGS_relative_time_to_string (search_delay, GNUNET_YES));
906
907 search_task = GNUNET_SCHEDULER_add_delayed (search_delay,
908 &do_connect_by_string, NULL);
909 } 953 }
910} 954}
911 955
@@ -1300,8 +1344,16 @@ controller_event_cb (void *cls,
1300 } 1344 }
1301 break; 1345 break;
1302 default: 1346 default:
1303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1347
1304 "Unexpected controller_cb with state %i!\n", state); 1348 switch (state)
1349 {
1350 case STATE_PEERS_CREATING:
1351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to create peer\n");
1352 break;
1353 default:
1354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1355 "Unexpected controller_cb with state %i!\n", state);
1356 }
1305 GNUNET_assert (0); 1357 GNUNET_assert (0);
1306 } 1358 }
1307} 1359}
@@ -1612,14 +1664,20 @@ main (int argc, char *const *argv)
1612 gettext_noop ("tolerate COUNT number of continious timeout failures"), 1664 gettext_noop ("tolerate COUNT number of continious timeout failures"),
1613 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_cont_fails }, 1665 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_cont_fails },
1614 { 't', "matching-timeout", "TIMEOUT", 1666 { 't', "matching-timeout", "TIMEOUT",
1615 gettext_noop ("wait TIMEOUT seconds before considering a string match as failed"), 1667 gettext_noop ("wait TIMEOUT before considering a string match as failed"),
1616 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout }, 1668 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_timeout },
1617 { 's', "search-delay", "DELAY", 1669 { 's', "search-delay", "DELAY",
1618 gettext_noop ("wait DELAY minutes before starting string search"), 1670 gettext_noop ("wait DELAY before starting string search"),
1619 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay }, 1671 GNUNET_YES, &GNUNET_GETOPT_set_relative_time, &search_delay },
1620 {'p', "max-path-compression", "MAX_PATH_COMPRESSION", 1672 {'p', "max-path-compression", "MAX_PATH_COMPRESSION",
1621 gettext_noop ("maximum path compression length"), 1673 gettext_noop ("maximum path compression length"),
1622 1, &GNUNET_GETOPT_set_uint, &max_path_compression}, 1674 1, &GNUNET_GETOPT_set_uint, &max_path_compression},
1675 {'a', "announce-delay", "DELAY",
1676 gettext_noop ("wait DELAY between announcing regexes"),
1677 1, &GNUNET_GETOPT_set_relative_time, &announce_delay},
1678 {'b', "announce-batch", "SIZE",
1679 gettext_noop ("number of peers that should announce regexes concurrently"),
1680 1, &GNUNET_GETOPT_set_uint, &announce_batch_size},
1623 GNUNET_GETOPT_OPTION_END 1681 GNUNET_GETOPT_OPTION_END
1624 }; 1682 };
1625 int ret; 1683 int ret;