2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/gnunet-regex-profiler.c
23 * @brief Regex profiler for testing distributed regex use.
31 #include "gnunet_applications.h"
32 #include "gnunet_util_lib.h"
33 #include "gnunet_mesh_service.h"
34 #include "gnunet_stream_lib.h"
35 #include "gnunet_testbed_service.h"
43 * The testbed operation handle
45 struct GNUNET_TESTBED_Operation *op;
53 * The next pointer for DLL
55 struct DLLOperation *next;
58 * The prev pointer for DLL
60 struct DLLOperation *prev;
65 * Available states during profiling
77 STATE_SLAVES_STARTING,
95 * Destroying peers; we can do this as the controller takes care of stopping a
96 * peer if it is running
98 STATE_PEERS_DESTROYING
103 * An array of hosts loaded from the hostkeys file
105 static struct GNUNET_TESTBED_Host **hosts;
113 * The actual testbed peer handle.
115 struct GNUNET_TESTBED_Peer *peer_handle;
118 * Peer's mesh handle.
120 struct GNUNET_MESH_Handle *mesh_handle;
123 * Peer's mesh tunnel handle.
125 struct GNUNET_MESH_Tunnel *mesh_tunnel_handle;
128 * Host on which the peer is running.
130 struct GNUNET_TESTBED_Host *host_handle;
133 * Testbed operation handle.
135 struct GNUNET_TESTBED_Operation *op_handle;
138 * Filename of the peer's policy file.
144 * Array of peer handles used to pass to
145 * GNUNET_TESTBED_overlay_configure_topology
147 struct GNUNET_TESTBED_Peer **peer_handles;
150 * The array of peers; we fill this as the peers are given to us by the testbed
152 static struct Peer *peers;
155 * Host registration handle
157 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
160 * Handle to the master controller process
162 struct GNUNET_TESTBED_ControllerProc *mc_proc;
165 * Handle to the master controller
167 struct GNUNET_TESTBED_Controller *mc;
170 * Handle to global configuration
172 struct GNUNET_CONFIGURATION_Handle *cfg;
175 * Head of the operations list
177 struct DLLOperation *dll_op_head;
180 * Tail of the operations list
182 struct DLLOperation *dll_op_tail;
185 * Peer linking - topology operation
187 struct GNUNET_TESTBED_Operation *topology_op;
190 * Abort task identifier
192 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
195 * Host registration task identifier
197 static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
200 * Global event mask for all testbed events
205 * The starting time of a profiling step
207 struct GNUNET_TIME_Absolute prof_start_time;
210 * Duration profiling step has taken
212 struct GNUNET_TIME_Relative prof_time;
217 unsigned int peer_id;
220 * Number of peers to be started by the profiler
222 static unsigned int num_peers;
225 * Number of hosts in the hosts array
227 static unsigned int num_hosts;
230 * Number of random links to be established between peers
232 static unsigned int num_links;
235 * Global testing status
240 * current state of profiling
246 * Folder where policy files are stored.
248 static char * policy_dir;
253 static char *search_string = "GNUNETVPN0001000IPEX4110010011001111001101000";
256 * Search task identifier
258 static GNUNET_SCHEDULER_TaskIdentifier search_task;
261 * Search timeout task identifier.
263 static GNUNET_SCHEDULER_TaskIdentifier search_timeout_task;
270 * @param tc the task context
273 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
275 struct DLLOperation *dll_op;
279 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
280 GNUNET_SCHEDULER_cancel (abort_task);
281 if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
282 GNUNET_SCHEDULER_cancel (register_hosts_task);
283 if (NULL != reg_handle)
284 GNUNET_TESTBED_cancel_registration (reg_handle);
285 if (NULL != topology_op)
286 GNUNET_TESTBED_operation_cancel (topology_op);
287 for (nhost = 0; nhost < num_hosts; nhost++)
288 if (NULL != hosts[nhost])
289 GNUNET_TESTBED_host_destroy (hosts[nhost]);
290 GNUNET_free_non_null (hosts);
291 while (NULL != (dll_op = dll_op_head))
293 GNUNET_TESTBED_operation_cancel (dll_op->op);
294 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
295 GNUNET_free (dll_op);
297 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
299 if (NULL != peers[peer_cnt].op_handle)
300 GNUNET_TESTBED_operation_cancel (peers[peer_cnt].op_handle);
303 GNUNET_TESTBED_controller_disconnect (mc);
305 GNUNET_TESTBED_controller_stop (mc_proc);
307 GNUNET_CONFIGURATION_destroy (cfg);
309 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
314 * abort task to run on test timed out
317 * @param tc the task context
320 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
322 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
323 abort_task = GNUNET_SCHEDULER_NO_TASK;
324 result = GNUNET_SYSERR;
325 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
330 * Method called whenever another peer has added us to a tunnel
331 * the other peer initiated.
332 * Only called (once) upon reception of data with a message type which was
333 * subscribed to in GNUNET_MESH_connect. A call to GNUNET_MESH_tunnel_destroy
334 * causes te tunnel to be ignored and no further notifications are sent about
338 * @param tunnel new handle to the tunnel
339 * @param initiator peer that started the tunnel
340 * @param atsi performance information for the tunnel
341 * @return initial tunnel context for the tunnel
342 * (can be NULL -- that's not an error)
345 mesh_inbound_tunnel_handler (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
346 const struct GNUNET_PeerIdentity *initiator,
347 const struct GNUNET_ATS_Information *atsi)
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh inbound tunnel handler.\n");
356 * Function called whenever an inbound tunnel is destroyed. Should clean up
357 * any associated state. This function is NOT called if the client has
358 * explicitly asked for the tunnel to be destroyed using
359 * GNUNET_MESH_tunnel_destroy. It must NOT call GNUNET_MESH_tunnel_destroy on
362 * @param cls closure (set from GNUNET_MESH_connect)
363 * @param tunnel connection to the other end (henceforth invalid)
364 * @param tunnel_ctx place where local state associated
365 * with the tunnel is stored
368 mesh_tunnel_end_handler (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh tunnel end handler.\n");
376 * Method called whenever a peer has disconnected from the tunnel.
377 * Implementations of this callback must NOT call
378 * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
379 * to run in some other task later. However, calling
380 * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
383 * @param peer_id peer identity the tunnel stopped working with
386 mesh_peer_disconnect_handler (void *cls,
387 const struct GNUNET_PeerIdentity * peer_id)
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer disconnect handler.\n");
394 * Method called whenever a peer has connected to the tunnel.
397 * @param peer_id peer identity the tunnel was created to, NULL on timeout
398 * @param atsi performance data for the connection
402 mesh_peer_connect_handler (void *cls,
403 const struct GNUNET_PeerIdentity* peer_id,
404 const struct GNUNET_ATS_Information * atsi)
406 // struct Peer *peer = (struct Peer *)cls;
408 GNUNET_SCHEDULER_cancel (search_timeout_task);
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer connect handler.\n");
411 printf ("\nString successfully matched\n");
412 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
417 * Connect by string timeout task
420 * @param tc the task context
423 do_connect_by_string_timeout (void *cls,
424 const struct GNUNET_SCHEDULER_TaskContext * tc)
426 long sec = (long)cls;
428 printf ("Searching for string did not succeed after %ld seconds\n", sec);
430 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
435 * Connect by string task that is run to search for a string in the NFA
438 * @param tc the task context
441 do_connect_by_string (void *cls,
442 const struct GNUNET_SCHEDULER_TaskContext * tc)
444 printf ("Searching for string \"%s\"\n", search_string);
446 peers[0].mesh_tunnel_handle = GNUNET_MESH_tunnel_create (peers[0].mesh_handle,
448 &mesh_peer_connect_handler,
449 &mesh_peer_disconnect_handler,
453 GNUNET_MESH_peer_request_connect_by_string (peers[0].mesh_tunnel_handle,
456 search_timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
457 (GNUNET_TIME_UNIT_SECONDS, 30),
458 &do_connect_by_string_timeout, (void *)(long)30);
463 * Mesh connect callback.
465 * @param cls internal peer id.
466 * @param op operation handle.
467 * @param ca_result connect adapter result.
468 * @param emsg error message.
471 mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
472 void *ca_result, const char *emsg)
474 static unsigned int connected_mesh_handles;
475 struct Peer *peer = (struct Peer *) cls;
484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Mesh connect failed: %s\n", emsg);
488 GNUNET_assert (peer->op_handle == op);
489 GNUNET_assert (peer->mesh_handle == ca_result);
490 GNUNET_assert (NULL != peer->policy_file);
492 printf ("Announcing regexes for peer with file %s\n", peer->policy_file);
495 if (GNUNET_YES != GNUNET_DISK_file_test (peer->policy_file))
497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
498 "Could not find policy file %s\n", peer->policy_file);
501 if (GNUNET_OK != GNUNET_DISK_file_size (peer->policy_file, &filesize, GNUNET_YES, GNUNET_YES))
505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", peer->policy_file);
508 data = GNUNET_malloc (filesize);
509 if (filesize != GNUNET_DISK_fn_read (peer->policy_file, data, filesize))
512 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
519 while (offset < (filesize - 1))
522 if (((data[offset] == '\n')) && (buf != &data[offset]))
526 GNUNET_assert (NULL != regex);
527 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
528 GNUNET_MESH_announce_regex (peer->mesh_handle, regex);
529 buf = &data[offset + 1];
531 else if ((data[offset] == '\n') || (data[offset] == '\0'))
532 buf = &data[offset + 1];
536 if (++connected_mesh_handles == num_peers)
538 printf ("\nAll mesh handles connected.\n");
540 search_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
541 (GNUNET_TIME_UNIT_SECONDS, 10),
542 &do_connect_by_string, NULL);
548 * Mesh connect adapter.
550 * @param cls not used.
551 * @param cfg configuration handle.
556 mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
558 GNUNET_MESH_ApplicationType app;
559 struct Peer *peer = (struct Peer *) cls;
561 static struct GNUNET_MESH_MessageHandler handlers[] = {
565 app = (GNUNET_MESH_ApplicationType)0;
568 GNUNET_MESH_connect (cfg, cls, NULL, NULL, handlers, &app);
570 return peer->mesh_handle;
575 * Adapter function called to destroy a connection to
579 * @param op_result service handle returned from the connect adapter
582 mesh_da (void *cls, void *op_result)
584 struct Peer *peer = (struct Peer *) cls;
586 GNUNET_assert (peer->mesh_handle == op_result);
588 if (NULL != peer->mesh_tunnel_handle)
590 GNUNET_MESH_tunnel_destroy (peer->mesh_tunnel_handle);
591 peer->mesh_tunnel_handle = NULL;
593 if (NULL != peer->mesh_handle)
595 GNUNET_MESH_disconnect (peer->mesh_handle);
596 peer->mesh_handle = NULL;
602 * Functions of this signature are called when a peer has been successfully
603 * started or stopped.
605 * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
606 * @param emsg NULL on success; otherwise an error description
609 peer_churn_cb (void *cls, const char *emsg)
611 struct DLLOperation *dll_op = cls;
612 struct GNUNET_TESTBED_Operation *op;
613 static unsigned int started_peers;
614 unsigned int peer_cnt;
617 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
618 GNUNET_free (dll_op);
621 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
622 _("An operation has failed while starting peers\n"));
623 GNUNET_TESTBED_operation_done (op);
624 GNUNET_SCHEDULER_cancel (abort_task);
625 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
628 GNUNET_TESTBED_operation_done (op);
629 if (++started_peers == num_peers)
631 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
632 printf ("All peers started successfully in %.2f seconds\n",
633 ((double) prof_time.rel_value) / 1000.00);
637 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
641 peer_handles = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) * num_peers);
642 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
643 peer_handles[peer_cnt] = peers[peer_cnt].peer_handle;
645 state = STATE_PEERS_LINKING;
646 /* Do overlay connect */
647 prof_start_time = GNUNET_TIME_absolute_get ();
649 GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peer_handles,
650 GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
652 if (NULL == topology_op)
654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
655 "Cannot create topology, op handle was NULL\n");
663 * Functions of this signature are called when a peer has been successfully
666 * @param cls the closure from GNUNET_TESTBED_peer_create()
667 * @param peer the handle for the created peer; NULL on any error during
669 * @param emsg NULL if peer is not NULL; else MAY contain the error description
672 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
674 struct DLLOperation *dll_op = cls;
675 struct Peer *peer_ptr;
676 static unsigned int created_peers;
677 unsigned int peer_cnt;
681 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
682 _("Creating a peer failed. Error: %s\n"), emsg);
683 GNUNET_TESTBED_operation_done (dll_op->op);
684 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
685 GNUNET_free (dll_op);
686 GNUNET_SCHEDULER_cancel (abort_task);
687 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
691 peer_ptr = dll_op->cls;
692 GNUNET_assert (NULL == peer_ptr->peer_handle);
693 peer_ptr->peer_handle = peer;
694 GNUNET_TESTBED_operation_done (dll_op->op);
695 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
696 GNUNET_free (dll_op);
698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %i created on host %s\n",
700 GNUNET_TESTBED_host_get_hostname (peer_ptr->host_handle));
702 if (++created_peers == num_peers)
704 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
705 printf ("All peers created successfully in %.2f seconds\n",
706 ((double) prof_time.rel_value) / 1000.00);
707 /* Now peers are to be started */
708 state = STATE_PEERS_STARTING;
709 prof_start_time = GNUNET_TIME_absolute_get ();
710 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
712 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
713 dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt].peer_handle,
714 &peer_churn_cb, dll_op);
715 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
721 * Function called with a filename.
724 * @param filename complete filename (absolute path)
725 * @return GNUNET_OK to continue to iterate,
726 * GNUNET_SYSERR to abort iteration with error!
729 policy_filename_cb (void *cls, const char *filename)
731 static unsigned int peer_cnt;
732 struct DLLOperation *dll_op;
734 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer %i on host %s for policy file %s\n",
736 GNUNET_TESTBED_host_get_hostname (hosts[peer_cnt % num_hosts]),
739 peers[peer_cnt].policy_file = GNUNET_strdup (filename);
740 peers[peer_cnt].host_handle = hosts[peer_cnt % num_hosts];
742 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
743 dll_op->cls = &peers[peer_cnt];
744 dll_op->op = GNUNET_TESTBED_peer_create (mc,
745 hosts[peer_cnt % num_hosts],
749 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
757 * Controller event callback
760 * @param event the controller event
763 controller_event_cb (void *cls,
764 const struct GNUNET_TESTBED_EventInformation *event)
766 struct DLLOperation *dll_op;
767 struct GNUNET_TESTBED_Operation *op;
771 case STATE_SLAVES_STARTING:
774 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
776 static unsigned int slaves_started;
778 dll_op = event->details.operation_finished.op_cls;
779 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
780 GNUNET_free (dll_op);
781 op = event->details.operation_finished.operation;
782 if (NULL != event->details.operation_finished.emsg)
784 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
785 _("An operation has failed while starting slaves\n"));
786 GNUNET_TESTBED_operation_done (op);
787 GNUNET_SCHEDULER_cancel (abort_task);
788 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
791 GNUNET_TESTBED_operation_done (op);
792 /* Proceed to start peers */
793 if (++slaves_started == num_hosts - 1)
795 printf ("All slaves started successfully\n");
797 state = STATE_PEERS_CREATING;
798 prof_start_time = GNUNET_TIME_absolute_get ();
800 num_peers = GNUNET_DISK_directory_scan (policy_dir,
803 peers = GNUNET_malloc (sizeof (struct Peer) * num_peers);
805 GNUNET_DISK_directory_scan (policy_dir,
815 case STATE_PEERS_STARTING:
818 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
819 /* Control reaches here when peer start fails */
820 case GNUNET_TESTBED_ET_PEER_START:
821 /* we handle peer starts in peer_churn_cb */
827 case STATE_PEERS_LINKING:
830 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
831 /* Control reaches here when a peer linking operation fails */
832 if (NULL != event->details.operation_finished.emsg)
834 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
835 _("An operation has failed while linking\n"));
836 GNUNET_SCHEDULER_cancel (abort_task);
837 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
840 case GNUNET_TESTBED_ET_CONNECT:
842 static unsigned int established_links;
843 unsigned int peer_cnt;
845 if (0 == established_links)
846 printf ("Establishing links\n .");
852 if (++established_links == num_links)
854 prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
855 printf ("\n%u links established in %.2f seconds\n",
856 num_links, ((double) prof_time.rel_value) / 1000.00);
858 GNUNET_free (peer_handles);
859 printf ("\nConnecting to mesh service...\n");
860 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
862 peers[peer_cnt].op_handle = GNUNET_TESTBED_service_connect (NULL,
863 peers[peer_cnt].peer_handle,
885 * Task to register all hosts available in the global host list
888 * @param tc the scheduler task context
891 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
895 * Callback which will be called to after a host registration succeeded or failed
897 * @param cls the closure
898 * @param emsg the error message; NULL if host registration is successful
901 host_registration_completion (void *cls, const char *emsg)
906 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
907 _("Host registration failed for a host. Error: %s\n"), emsg);
908 GNUNET_SCHEDULER_cancel (abort_task);
909 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
912 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
917 * Task to register all hosts available in the global host list
920 * @param tc the scheduler task context
923 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
925 struct DLLOperation *dll_op;
926 static unsigned int reg_host;
929 register_hosts_task = GNUNET_SCHEDULER_NO_TASK;
930 if (reg_host == num_hosts - 1)
932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
933 "All hosts successfully registered\n");
935 state = STATE_SLAVES_STARTING;
936 for (slave = 1; slave < num_hosts; slave++)
938 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
939 dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
945 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
949 reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
950 host_registration_completion,
956 * Callback to signal successfull startup of the controller process
958 * @param cls the closure from GNUNET_TESTBED_controller_start()
959 * @param config the configuration with which the controller has been started;
960 * NULL if status is not GNUNET_OK
961 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
962 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
965 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
967 GNUNET_SCHEDULER_cancel (abort_task);
968 if (GNUNET_OK != status)
971 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
975 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
976 event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
977 event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
978 event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
979 event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
980 mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
981 &controller_event_cb, NULL);
984 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
985 _("Unable to connect to master controller -- Check config\n"));
986 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
989 register_hosts_task = GNUNET_SCHEDULER_add_now (®ister_hosts, NULL);
990 abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
996 * Main function that will be run by the scheduler.
999 * @param args remaining command-line arguments
1000 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1001 * @param config configuration
1004 run (void *cls, char *const *args, const char *cfgfile,
1005 const struct GNUNET_CONFIGURATION_Handle *config)
1009 if (NULL == args[0])
1011 fprintf (stderr, _("No hosts-file specified on command line. Exiting.\n"));
1014 if (NULL == args[1])
1016 fprintf (stderr, _("No policy directory specified on command line. Exiting.\n"));
1019 num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
1022 fprintf (stderr, _("No hosts loaded. Need at least one host\n"));
1025 for (nhost = 0; nhost < num_hosts; nhost++)
1027 if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost]))
1029 fprintf (stderr, _("Host %s cannot start testbed\n"),
1030 GNUNET_TESTBED_host_get_hostname (hosts[nhost]));
1034 if (num_hosts != nhost)
1036 fprintf (stderr, _("Exiting\n"));
1037 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1042 fprintf (stderr, _("No configuration file given. Exiting\n"));
1043 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1046 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1]))
1048 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
1049 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1052 policy_dir = args[1];
1054 cfg = GNUNET_CONFIGURATION_dup (config);
1056 GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname
1063 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1064 (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
1072 * @param argc argument count
1073 * @param argv argument values
1074 * @return 0 on success
1077 main (int argc, char *const *argv)
1079 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1080 { 'n', "num-links", "COUNT",
1081 gettext_noop ("create COUNT number of random links"),
1082 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links },
1083 GNUNET_GETOPT_OPTION_END
1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1090 result = GNUNET_SYSERR;
1092 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir",
1093 _("Profiler for regex/mesh"),
1094 options, &run, NULL);
1095 if (GNUNET_OK != ret)
1097 if (GNUNET_OK != result)