+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be NULL!)
+ * @param config configuration
+ */
+static void
+run (void *cls, char *const *args, const char *cfgfile,
+ const struct GNUNET_CONFIGURATION_Handle *config)
+{
+ unsigned int nsearchstrs;
+ unsigned int i;
+ struct GNUNET_TIME_Relative abort_time;
+
+ in_shutdown = GNUNET_NO;
+
+ /* Check config */
+ if (NULL == config)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No configuration file given. Exiting\n"));
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ cfg = GNUNET_CONFIGURATION_dup (config);
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER",
+ "REGEX_PREFIX",
+ ®ex_prefix))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Configuration option \"regex_prefix\" missing. Exiting\n"));
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER",
+ "PARALLEL_SEARCHES",
+ &init_parallel_searches))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Configuration option \"PARALLEL_SEARCHES\" missing."
+ " Using default (%d)\n", 10);
+ init_parallel_searches = 10;
+ }
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER",
+ "REANNOUNCE_PERIOD_MAX",
+ &reannounce_period_max))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "reannounce_period_max not given. Using 10 minutes.\n");
+ reannounce_period_max =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 10);
+ }
+
+ /* Check arguments */
+ if (NULL == policy_dir)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No policy directory specified on command line. Exiting.\n"));
+ return;
+ }
+ if (GNUNET_YES != GNUNET_DISK_directory_test (policy_dir, GNUNET_YES))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Specified policies directory does not exist. Exiting.\n"));
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if (-1 == (num_peers = GNUNET_DISK_directory_scan (policy_dir, NULL, NULL)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No files found in `%s'\n"),
+ policy_dir);
+ return;
+ }
+ GNUNET_CONFIGURATION_set_value_string (cfg, "REGEXPROFILER",
+ "POLICY_DIR", policy_dir);
+ if (GNUNET_YES != GNUNET_DISK_file_test (strings_file))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("No search strings file given. Exiting.\n"));
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ nsearchstrs = load_search_strings (strings_file,
+ &search_strings,
+ num_peers);
+ if (num_peers != nsearchstrs)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Error loading search strings.\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "File (%s) does not contain enough strings (%u/%u).\n",
+ strings_file, nsearchstrs, num_peers);
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ if (0 >= num_peers || NULL == search_strings)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Error loading search strings. Exiting.\n"));
+ shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
+ return;
+ }
+ for (i = 0; i < num_peers; i++)
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "search string: %s\n",
+ search_strings[i]);
+
+ /* Check logfile */
+ if ( (NULL != data_filename) &&
+ (NULL == (data_file =
+ GNUNET_DISK_file_open (data_filename,
+ GNUNET_DISK_OPEN_READWRITE |
+ GNUNET_DISK_OPEN_TRUNCATE |
+ GNUNET_DISK_OPEN_CREATE,
+ GNUNET_DISK_PERM_USER_READ |
+ GNUNET_DISK_PERM_USER_WRITE))) )
+ {
+ GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+ "open",
+ data_filename);
+ return;
+ }
+
+ /* Initialize peers */
+ peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
+ for (i = 0; i < num_peers; i++)
+ {
+ peers[i].id = i;
+ }
+
+ GNUNET_CONFIGURATION_set_value_number (cfg,
+ "TESTBED", "OVERLAY_RANDOM_LINKS",
+ num_peers * 20);
+ GNUNET_CONFIGURATION_set_value_number (cfg,
+ "DHT", "FORCE_NSE",
+ (long long unsigned)
+ (log (num_peers) / log (2.0)));
+ event_mask = 0LL;
+/* For feedback about the start process activate these and pass master_cb */
+ event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
+// event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
+ event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
+// event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
+ prof_start_time = GNUNET_TIME_absolute_get ();
+ GNUNET_TESTBED_run (hosts_file,
+ cfg,
+ num_peers,
+ event_mask,
+ &master_controller_cb,
+ NULL, /* master_controller_cb cls */
+ &test_master,
+ NULL); /* test_master cls */
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_time (cfg, "TESTBED",
+ "SETUP_TIMEOUT",
+ &abort_time))
+ {
+ abort_time =
+ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15);
+ }
+ abort_time = GNUNET_TIME_relative_add (abort_time, GNUNET_TIME_UNIT_MINUTES);
+ abort_task =
+ GNUNET_SCHEDULER_add_delayed (abort_time,
+ &do_abort,
+ (void*) __LINE__);
+}