aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-10-19 16:25:51 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-10-19 16:25:51 +0000
commitd2b7906ca34d860da0dad9c51ae2f6dfa14561ab (patch)
tree145daaa9a63f54a99e815c6d0228324c19a5867a /src
parent4fda586905ec379f8be429720042c0fa2ad7ab36 (diff)
downloadgnunet-d2b7906ca34d860da0dad9c51ae2f6dfa14561ab.tar.gz
gnunet-d2b7906ca34d860da0dad9c51ae2f6dfa14561ab.zip
- Added a new regex to test_mesh_regex
- Mesh connect and regex announce in regex-profiler
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-regex-profiler.c266
-rw-r--r--src/mesh/test_mesh_regex.c15
2 files changed, 232 insertions, 49 deletions
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c
index 6714b8630..e5a460dff 100644
--- a/src/mesh/gnunet-regex-profiler.c
+++ b/src/mesh/gnunet-regex-profiler.c
@@ -120,6 +120,11 @@ struct Peer
120 struct GNUNET_MESH_Handle *mesh_handle; 120 struct GNUNET_MESH_Handle *mesh_handle;
121 121
122 /** 122 /**
123 * Peer's mesh tunnel handle.
124 */
125 struct GNUNET_MESH_Tunnel *mesh_tunnel_handle;
126
127 /**
123 * Host on which the peer is running. 128 * Host on which the peer is running.
124 */ 129 */
125 struct GNUNET_TESTBED_Host *host_handle; 130 struct GNUNET_TESTBED_Host *host_handle;
@@ -128,6 +133,11 @@ struct Peer
128 * Testbed operation handle. 133 * Testbed operation handle.
129 */ 134 */
130 struct GNUNET_TESTBED_Operation *op_handle; 135 struct GNUNET_TESTBED_Operation *op_handle;
136
137 /**
138 * Filename of the peer's policy file.
139 */
140 char *policy_file;
131}; 141};
132 142
133/** 143/**
@@ -233,6 +243,22 @@ enum State state;
233 243
234 244
235/** 245/**
246 * Folder where policy files are stored.
247 */
248static char * policy_dir;
249
250/**
251 * Search string.
252 */
253static char *search_string = "GNUNETVPN0001000IPEX401110011101100100000111";
254
255/**
256 * Search task identifier
257 */
258static GNUNET_SCHEDULER_TaskIdentifier search_task;
259
260
261/**
236 * Shutdown nicely 262 * Shutdown nicely
237 * 263 *
238 * @param cls NULL 264 * @param cls NULL
@@ -243,6 +269,7 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
243{ 269{
244 struct DLLOperation *dll_op; 270 struct DLLOperation *dll_op;
245 unsigned int nhost; 271 unsigned int nhost;
272 int peer_cnt;
246 273
247 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 274 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
248 GNUNET_SCHEDULER_cancel (abort_task); 275 GNUNET_SCHEDULER_cancel (abort_task);
@@ -262,6 +289,11 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
262 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); 289 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
263 GNUNET_free (dll_op); 290 GNUNET_free (dll_op);
264 } 291 }
292 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
293 {
294 if (NULL != peers[peer_cnt].op_handle)
295 GNUNET_TESTBED_operation_cancel (peers[peer_cnt].op_handle);
296 }
265 if (NULL != mc) 297 if (NULL != mc)
266 GNUNET_TESTBED_controller_disconnect (mc); 298 GNUNET_TESTBED_controller_disconnect (mc);
267 if (NULL != mc_proc) 299 if (NULL != mc_proc)
@@ -269,8 +301,6 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
269 if (NULL != cfg) 301 if (NULL != cfg)
270 GNUNET_CONFIGURATION_destroy (cfg); 302 GNUNET_CONFIGURATION_destroy (cfg);
271 303
272 //FIXME GNUNET_MESH_disconnect (peers[i].mesh_handle);
273
274 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */ 304 GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
275} 305}
276 306
@@ -311,6 +341,8 @@ mesh_inbound_tunnel_handler (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
311 const struct GNUNET_PeerIdentity *initiator, 341 const struct GNUNET_PeerIdentity *initiator,
312 const struct GNUNET_ATS_Information *atsi) 342 const struct GNUNET_ATS_Information *atsi)
313{ 343{
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh inbound tunnel handler.\n");
345
314 return NULL; 346 return NULL;
315} 347}
316 348
@@ -331,7 +363,74 @@ void
331mesh_tunnel_end_handler (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, 363mesh_tunnel_end_handler (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
332 void *tunnel_ctx) 364 void *tunnel_ctx)
333{ 365{
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh tunnel end handler.\n");
367}
368
369
370/**
371 * Method called whenever a peer has disconnected from the tunnel.
372 * Implementations of this callback must NOT call
373 * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those
374 * to run in some other task later. However, calling
375 * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed.
376 *
377 * @param cls closure
378 * @param peer_id peer identity the tunnel stopped working with
379 */
380void
381mesh_peer_disconnect_handler (void *cls,
382 const struct GNUNET_PeerIdentity * peer_id)
383{
384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer disconnect handler.\n");
385}
386
387
388/**
389 * Method called whenever a peer has connected to the tunnel.
390 *
391 * @param cls closure
392 * @param peer_id peer identity the tunnel was created to, NULL on timeout
393 * @param atsi performance data for the connection
394 *
395 */
396void
397mesh_peer_connect_handler (void *cls,
398 const struct GNUNET_PeerIdentity* peer_id,
399 const struct GNUNET_ATS_Information * atsi)
400{
401 // struct Peer *peer = (struct Peer *)cls;
402 unsigned int peer_cnt;
403
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer connect handler.\n");
334 405
406 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
407 {
408 GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle);
409 }
410}
411
412
413/**
414 * Connect by string task that is run to search for a string in the NFA
415 *
416 * @param cls NULL
417 * @param tc the task context
418 */
419static void
420do_connect_by_string (void *cls,
421 const struct GNUNET_SCHEDULER_TaskContext * tc)
422{
423 printf ("Searching for string \"%s\"\n", search_string);
424
425 peers[0].mesh_tunnel_handle = GNUNET_MESH_tunnel_create (peers[0].mesh_handle,
426 NULL,
427 &mesh_peer_connect_handler,
428 &mesh_peer_disconnect_handler,
429 &peers[0]);
430
431
432 GNUNET_MESH_peer_request_connect_by_string (peers[0].mesh_tunnel_handle,
433 search_string);
335} 434}
336 435
337 436
@@ -349,7 +448,11 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
349{ 448{
350 static unsigned int connected_mesh_handles; 449 static unsigned int connected_mesh_handles;
351 struct Peer *peer = (struct Peer *) cls; 450 struct Peer *peer = (struct Peer *) cls;
352 unsigned int peer_cnt; 451 char *regex;
452 char *data;
453 char *buf;
454 uint64_t filesize;
455 unsigned int offset;
353 456
354 if (NULL != emsg) 457 if (NULL != emsg)
355 { 458 {
@@ -359,22 +462,64 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
359 462
360 GNUNET_assert (peer->op_handle == op); 463 GNUNET_assert (peer->op_handle == op);
361 GNUNET_assert (peer->mesh_handle == ca_result); 464 GNUNET_assert (peer->mesh_handle == ca_result);
465 GNUNET_assert (NULL != peer->policy_file);
362 466
363 printf ("."); 467 printf ("Announcing regexes for peer with file %s\n", peer->policy_file);
364 fflush (stdout); 468 fflush (stdout);
365 469
366 if (++connected_mesh_handles == num_peers) 470 if (GNUNET_YES != GNUNET_DISK_file_test (peer->policy_file))
367 { 471 {
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All mesh handles connected\n"); 472 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
369 473 "Could not find policy file %s\n", peer->policy_file);
370 // TODO announce regexes... 474 GNUNET_TESTBED_operation_done (peer->op_handle);
371 475 return;
372 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) 476 }
477 if (GNUNET_OK != GNUNET_DISK_file_size (peer->policy_file, &filesize, GNUNET_YES, GNUNET_YES))
478 filesize = 0;
479 if (0 == filesize)
480 {
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Policy file %s is empty.\n", peer->policy_file);
482 GNUNET_TESTBED_operation_done (peer->op_handle);
483 return;
484 }
485 data = GNUNET_malloc (filesize);
486 if (filesize != GNUNET_DISK_fn_read (peer->policy_file, data, filesize))
487 {
488 GNUNET_free (data);
489 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Could not read policy file %s.\n",
490 peer->policy_file);
491 GNUNET_TESTBED_operation_done (peer->op_handle);
492 return;
493 }
494 buf = data;
495 offset = 0;
496 regex = NULL;
497 while (offset < (filesize - 1))
498 {
499 offset++;
500 if (((data[offset] == '\n')) && (buf != &data[offset]))
373 { 501 {
374 GNUNET_TESTBED_operation_done (peers[peer_cnt].op_handle); 502 data[offset] = '\0';
503 regex = buf;
504 GNUNET_assert (NULL != regex);
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex);
506 GNUNET_MESH_announce_regex (peer->mesh_handle, regex);
507 buf = &data[offset + 1];
375 } 508 }
509 else if ((data[offset] == '\n') || (data[offset] == '\0'))
510 buf = &data[offset + 1];
376 } 511 }
377 512 GNUNET_free (data);
513
514 if (++connected_mesh_handles == num_peers)
515 {
516 printf ("\nAll mesh handles connected.\n");
517
518 search_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
519 (GNUNET_TIME_UNIT_SECONDS, 5),
520 &do_connect_by_string, NULL);
521 }
522
378} 523}
379 524
380 525
@@ -391,8 +536,6 @@ mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
391{ 536{
392 struct Peer *peer = (struct Peer *) cls; 537 struct Peer *peer = (struct Peer *) cls;
393 538
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh connect adapter\n");
395
396 static struct GNUNET_MESH_MessageHandler handlers[] = { 539 static struct GNUNET_MESH_MessageHandler handlers[] = {
397 {NULL, 0, 0} 540 {NULL, 0, 0}
398 }; 541 };
@@ -424,7 +567,16 @@ mesh_da (void *cls, void *op_result)
424 567
425 GNUNET_assert (peer->mesh_handle == op_result); 568 GNUNET_assert (peer->mesh_handle == op_result);
426 569
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh disconnect adapter\n"); 570 if (NULL != peer->mesh_tunnel_handle)
571 GNUNET_MESH_tunnel_destroy (peer->mesh_tunnel_handle);
572 GNUNET_MESH_disconnect (peer->mesh_handle);
573 peer->mesh_handle = NULL;
574
575 if (++disconnected_mesh_handles == num_peers)
576 {
577 printf ("All mesh handles disconnected.\n");
578 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
579 }
428 580
429 GNUNET_MESH_disconnect (peer->mesh_handle); 581 GNUNET_MESH_disconnect (peer->mesh_handle);
430 peer->mesh_handle = NULL; 582 peer->mesh_handle = NULL;
@@ -555,6 +707,41 @@ peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
555 } 707 }
556} 708}
557 709
710/**
711 * Function called with a filename.
712 *
713 * @param cls closure
714 * @param filename complete filename (absolute path)
715 * @return GNUNET_OK to continue to iterate,
716 * GNUNET_SYSERR to abort iteration with error!
717 */
718int
719policy_filename_cb (void *cls, const char *filename)
720{
721 static unsigned int peer_cnt;
722 struct DLLOperation *dll_op;
723
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer %i on host %s for policy file %s\n",
725 peer_cnt,
726 GNUNET_TESTBED_host_get_hostname (hosts[peer_cnt % num_hosts]),
727 filename);
728
729 peers[peer_cnt].policy_file = GNUNET_strdup (filename);
730 peers[peer_cnt].host_handle = hosts[peer_cnt % num_hosts];
731
732 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
733 dll_op->cls = &peers[peer_cnt];
734 dll_op->op = GNUNET_TESTBED_peer_create (mc,
735 hosts[peer_cnt % num_hosts],
736 cfg,
737 &peer_create_cb,
738 dll_op);
739 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
740 peer_cnt++;
741
742 return GNUNET_OK;
743}
744
558 745
559/** 746/**
560 * Controller event callback 747 * Controller event callback
@@ -577,7 +764,6 @@ controller_event_cb (void *cls,
577 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 764 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
578 { 765 {
579 static unsigned int slaves_started; 766 static unsigned int slaves_started;
580 unsigned int peer_cnt;
581 767
582 dll_op = event->details.operation_finished.op_cls; 768 dll_op = event->details.operation_finished.op_cls;
583 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); 769 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
@@ -597,26 +783,18 @@ controller_event_cb (void *cls,
597 if (++slaves_started == num_hosts - 1) 783 if (++slaves_started == num_hosts - 1)
598 { 784 {
599 printf ("All slaves started successfully\n"); 785 printf ("All slaves started successfully\n");
786
600 state = STATE_PEERS_CREATING; 787 state = STATE_PEERS_CREATING;
601 prof_start_time = GNUNET_TIME_absolute_get (); 788 prof_start_time = GNUNET_TIME_absolute_get ();
789
790 num_peers = GNUNET_DISK_directory_scan (policy_dir,
791 NULL,
792 NULL);
602 peers = GNUNET_malloc (sizeof (struct Peer) * num_peers); 793 peers = GNUNET_malloc (sizeof (struct Peer) * num_peers);
603 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) 794
604 { 795 GNUNET_DISK_directory_scan (policy_dir,
605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating peer %i on host %s\n", 796 &policy_filename_cb,
606 peer_cnt, 797 NULL);
607 GNUNET_TESTBED_host_get_hostname (hosts[peer_cnt % num_hosts]));
608
609 peers[peer_cnt].host_handle = hosts[peer_cnt % num_hosts];
610
611 dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
612 dll_op->cls = &peers[peer_cnt];
613 dll_op->op = GNUNET_TESTBED_peer_create (mc,
614 hosts[peer_cnt % num_hosts],
615 cfg,
616 &peer_create_cb,
617 dll_op);
618 GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
619 }
620 } 798 }
621 } 799 }
622 break; 800 break;
@@ -768,7 +946,7 @@ register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
768 * Callback to signal successfull startup of the controller process 946 * Callback to signal successfull startup of the controller process
769 * 947 *
770 * @param cls the closure from GNUNET_TESTBED_controller_start() 948 * @param cls the closure from GNUNET_TESTBED_controller_start()
771 * @param cfg the configuration with which the controller has been started; 949 * @param config the configuration with which the controller has been started;
772 * NULL if status is not GNUNET_OK 950 * NULL if status is not GNUNET_OK
773 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not, 951 * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
774 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case 952 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
@@ -820,12 +998,12 @@ run (void *cls, char *const *args, const char *cfgfile,
820 998
821 if (NULL == args[0]) 999 if (NULL == args[0])
822 { 1000 {
823 fprintf (stderr, _("No hosts-file specified on command line\n")); 1001 fprintf (stderr, _("No hosts-file specified on command line. Exiting.\n"));
824 return; 1002 return;
825 } 1003 }
826 if (0 == num_peers) 1004 if (NULL == args[1])
827 { 1005 {
828 result = GNUNET_OK; 1006 fprintf (stderr, _("No policy directory specified on command line. Exiting.\n"));
829 return; 1007 return;
830 } 1008 }
831 num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts); 1009 num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
@@ -855,6 +1033,13 @@ run (void *cls, char *const *args, const char *cfgfile,
855 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1033 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
856 return; 1034 return;
857 } 1035 }
1036 if (GNUNET_YES != GNUNET_DISK_directory_test (args[1]))
1037 {
1038 fprintf (stderr, _("Specified policies directory does not exist. Exiting.\n"));
1039 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1040 return;
1041 }
1042 policy_dir = args[1];
858 1043
859 cfg = GNUNET_CONFIGURATION_dup (config); 1044 cfg = GNUNET_CONFIGURATION_dup (config);
860 mc_proc = 1045 mc_proc =
@@ -874,15 +1059,14 @@ run (void *cls, char *const *args, const char *cfgfile,
874/** 1059/**
875 * Main function. 1060 * Main function.
876 * 1061 *
1062 * @param argc argument count
1063 * @param argv argument values
877 * @return 0 on success 1064 * @return 0 on success
878 */ 1065 */
879int 1066int
880main (int argc, char *const *argv) 1067main (int argc, char *const *argv)
881{ 1068{
882 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1069 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
883 { 'p', "num-peers", "COUNT",
884 gettext_noop ("create COUNT number of peers"),
885 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
886 { 'n', "num-links", "COUNT", 1070 { 'n', "num-links", "COUNT",
887 gettext_noop ("create COUNT number of random links"), 1071 gettext_noop ("create COUNT number of random links"),
888 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links }, 1072 GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links },
@@ -895,7 +1079,7 @@ main (int argc, char *const *argv)
895 1079
896 result = GNUNET_SYSERR; 1080 result = GNUNET_SYSERR;
897 ret = 1081 ret =
898 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file", 1082 GNUNET_PROGRAM_run (argc, argv, "gnunet-regex-profiler [OPTIONS] hosts-file policy-dir",
899 _("Profiler for regex/mesh"), 1083 _("Profiler for regex/mesh"),
900 options, &run, NULL); 1084 options, &run, NULL);
901 if (GNUNET_OK != ret) 1085 if (GNUNET_OK != ret)
diff --git a/src/mesh/test_mesh_regex.c b/src/mesh/test_mesh_regex.c
index 878ca2f68..e31cfed81 100644
--- a/src/mesh/test_mesh_regex.c
+++ b/src/mesh/test_mesh_regex.c
@@ -29,7 +29,7 @@
29 29
30#define VERBOSE GNUNET_YES 30#define VERBOSE GNUNET_YES
31#define REMOVE_DIR GNUNET_YES 31#define REMOVE_DIR GNUNET_YES
32#define MESH_REGEX_PEERS 3 32#define MESH_REGEX_PEERS 4
33 33
34/** 34/**
35 * How long until we give up on connecting the peers? 35 * How long until we give up on connecting the peers?
@@ -42,11 +42,6 @@
42#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 42#define SHORT_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
43 43
44/** 44/**
45 * Initial regex padding.
46 */
47#define REGEX_INITIAL_PADDING "PADPADPADPADPADP"
48
49/**
50 * Which strings have been found & connected. 45 * Which strings have been found & connected.
51 */ 46 */
52static int ok[MESH_REGEX_PEERS]; 47static int ok[MESH_REGEX_PEERS];
@@ -130,7 +125,9 @@ static char *regexes[MESH_REGEX_PEERS] = {"(0|1)"
130 125
131 "0123456789A*BC", 126 "0123456789A*BC",
132 127
133 "0*123456789ABC*"}; 128 "0*123456789ABC*",
129
130 "GNUNETVPN0001000IPEX401110011101100100000111(0|1)*"};
134 131
135 132
136/** 133/**
@@ -140,7 +137,9 @@ static char *strings[MESH_REGEX_PEERS] = {"1123456789ABC",
140 137
141 "0123456789AABC", 138 "0123456789AABC",
142 139
143 "00123456789ABCCCC"}; 140 "00123456789ABCCCC",
141
142 "GNUNETVPN0001000IPEX401110011101100100000111"};
144 143
145/** 144/**
146 * Check whether peers successfully shut down. 145 * Check whether peers successfully shut down.