aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaximilian Szengel <gnunet@maxsz.de>2012-11-04 18:35:07 +0000
committerMaximilian Szengel <gnunet@maxsz.de>2012-11-04 18:35:07 +0000
commitb6d09b511fbd61d3b36fde4c28624bed321bf4a1 (patch)
tree9f6159ac87a2b52a896cd1f77dbf54463d6ab47d /src
parent70466ec3c34f9a920e9e798e3169f886e9486a59 (diff)
downloadgnunet-b6d09b511fbd61d3b36fde4c28624bed321bf4a1.tar.gz
gnunet-b6d09b511fbd61d3b36fde4c28624bed321bf4a1.zip
regex profiler fixes
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-regex-profiler.c77
1 files changed, 65 insertions, 12 deletions
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/mesh/gnunet-regex-profiler.c
index 6c519717d..fac7b02e5 100644
--- a/src/mesh/gnunet-regex-profiler.c
+++ b/src/mesh/gnunet-regex-profiler.c
@@ -146,6 +146,14 @@ struct RegexPeer
146 const char *search_str; 146 const char *search_str;
147 147
148 /** 148 /**
149 * Set to GNUNET_YES if the peer successfully matched the above
150 * search string. GNUNET_NO if the string could not be matched
151 * during the profiler run. GNUNET_SYSERR if the string matching
152 * timed out. Undefined if search_str is NULL
153 */
154 int search_str_matched;
155
156 /**
149 * Peer's mesh handle. 157 * Peer's mesh handle.
150 */ 158 */
151 struct GNUNET_MESH_Handle *mesh_handle; 159 struct GNUNET_MESH_Handle *mesh_handle;
@@ -300,7 +308,7 @@ static char * policy_dir;
300/** 308/**
301 * Search strings. 309 * Search strings.
302 */ 310 */
303static char **search_strings; 311static char **search_strings = NULL;
304 312
305/** 313/**
306 * Number of search strings. 314 * Number of search strings.
@@ -441,9 +449,12 @@ static void
441do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 449do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
442{ 450{
443 struct DLLOperation *dll_op; 451 struct DLLOperation *dll_op;
452 struct RegexPeer *peer;
444 unsigned int nhost; 453 unsigned int nhost;
445 unsigned int peer_cnt; 454 unsigned int peer_cnt;
446 unsigned int search_str_cnt; 455 unsigned int search_str_cnt;
456 char output_buffer[512];
457 size_t size;
447 458
448 if (GNUNET_SCHEDULER_NO_TASK != abort_task) 459 if (GNUNET_SCHEDULER_NO_TASK != abort_task)
449 GNUNET_SCHEDULER_cancel (abort_task); 460 GNUNET_SCHEDULER_cancel (abort_task);
@@ -452,6 +463,25 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
452 463
453 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) 464 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
454 { 465 {
466 peer = &peers[peer_cnt];
467
468 if (GNUNET_YES != peer->search_str_matched && NULL != data_file)
469 {
470 prof_time = GNUNET_TIME_absolute_get_duration (peer->prof_start_time);
471 size =
472 GNUNET_snprintf (output_buffer,
473 sizeof (output_buffer),
474 "Search string not found: %s (%d)\nOn peer: %u (%p)\nWith policy file: %s\nAfter: %s\n",
475 peer->search_str,
476 peer->search_str_matched,
477 peer->id,
478 peer,
479 peer->policy_file,
480 GNUNET_STRINGS_relative_time_to_string (prof_time, GNUNET_NO));
481 if (size != GNUNET_DISK_file_write (data_file, output_buffer, size))
482 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
483 }
484
455 if (NULL != peers[peer_cnt].mesh_op_handle) 485 if (NULL != peers[peer_cnt].mesh_op_handle)
456 GNUNET_TESTBED_operation_done (peers[peer_cnt].mesh_op_handle); 486 GNUNET_TESTBED_operation_done (peers[peer_cnt].mesh_op_handle);
457 if (NULL != peers[peer_cnt].stats_op_handle) 487 if (NULL != peers[peer_cnt].stats_op_handle)
@@ -461,9 +491,13 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
461 if (NULL != data_file) 491 if (NULL != data_file)
462 GNUNET_DISK_file_close (data_file); 492 GNUNET_DISK_file_close (data_file);
463 493
464 for (search_str_cnt = 0; search_str_cnt < num_search_strings; search_str_cnt++) 494 for (search_str_cnt = 0;
465 GNUNET_free (search_strings[search_str_cnt]); 495 search_str_cnt < num_search_strings && NULL != search_strings;
466 GNUNET_free (search_strings); 496 search_str_cnt++)
497 {
498 GNUNET_free_non_null (search_strings[search_str_cnt]);
499 }
500 GNUNET_free_non_null (search_strings);
467 501
468 if (NULL != reg_handle) 502 if (NULL != reg_handle)
469 GNUNET_TESTBED_cancel_registration (reg_handle); 503 GNUNET_TESTBED_cancel_registration (reg_handle);
@@ -656,6 +690,7 @@ stats_connect_cb (void *cls,
656 690
657 peer->prof_start_time = GNUNET_TIME_absolute_get (); 691 peer->prof_start_time = GNUNET_TIME_absolute_get ();
658 692
693 peer->search_str_matched = GNUNET_NO;
659 GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle, 694 GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle,
660 peer->search_str); 695 peer->search_str);
661} 696}
@@ -756,6 +791,8 @@ mesh_peer_connect_handler (void *cls,
756 791
757 printf ("String matching timed out for string %s on peer %u (%i/%i)\n", 792 printf ("String matching timed out for string %s on peer %u (%i/%i)\n",
758 peer->search_str, peer->id, peers_found, num_search_strings); 793 peer->search_str, peer->id, peers_found, num_search_strings);
794
795 peer->search_str_matched = GNUNET_SYSERR;
759 } 796 }
760 else 797 else
761 { 798 {
@@ -770,6 +807,8 @@ mesh_peer_connect_handler (void *cls,
770 peers_found, num_search_strings); 807 peers_found, num_search_strings);
771 fflush (stdout); 808 fflush (stdout);
772 809
810 peer->search_str_matched = GNUNET_YES;
811
773 if (NULL != data_file) 812 if (NULL != data_file)
774 { 813 {
775 size = 814 size =
@@ -875,6 +914,7 @@ do_connect_by_string (void *cls,
875 { 914 {
876 peer = &peers[search_cnt % num_peers]; 915 peer = &peers[search_cnt % num_peers];
877 peer->search_str = search_strings[search_cnt]; 916 peer->search_str = search_strings[search_cnt];
917 peer->search_str_matched = GNUNET_NO;
878 918
879 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 919 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
880 "Searching for string \"%s\" on peer %d with file %s\n", 920 "Searching for string \"%s\" on peer %d with file %s\n",
@@ -1281,14 +1321,7 @@ policy_filename_cb (void *cls, const char *filename)
1281 1321
1282 GNUNET_assert (NULL != peer); 1322 GNUNET_assert (NULL != peer);
1283 1323
1284 peer->id = peer_cnt;
1285 peer->policy_file = GNUNET_strdup (filename); 1324 peer->policy_file = GNUNET_strdup (filename);
1286 /* Do not start peers on hosts[0] (master controller) */
1287 peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))];
1288 peer->mesh_handle = NULL;
1289 peer->mesh_tunnel_handle = NULL;
1290 peer->stats_handle = NULL;
1291 peer->stats_op_handle = NULL;
1292 1325
1293 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n", 1326 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Creating peer %i on host %s for policy file %s\n",
1294 peer->id, 1327 peer->id,
@@ -1330,6 +1363,7 @@ controller_event_cb (void *cls,
1330 case GNUNET_TESTBED_ET_OPERATION_FINISHED: 1363 case GNUNET_TESTBED_ET_OPERATION_FINISHED:
1331 { 1364 {
1332 static unsigned int slaves_started; 1365 static unsigned int slaves_started;
1366 unsigned int peer_cnt;
1333 1367
1334 dll_op = event->details.operation_finished.op_cls; 1368 dll_op = event->details.operation_finished.op_cls;
1335 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); 1369 GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
@@ -1360,6 +1394,22 @@ controller_event_cb (void *cls,
1360 NULL); 1394 NULL);
1361 peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers); 1395 peers = GNUNET_malloc (sizeof (struct RegexPeer) * num_peers);
1362 1396
1397 /* Initialize peers */
1398 for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
1399 {
1400 struct RegexPeer *peer = &peers[peer_cnt];
1401 peer->id = peer_cnt;
1402 peer->policy_file = NULL;
1403 /* Do not start peers on hosts[0] (master controller) */
1404 peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))];
1405 peer->mesh_handle = NULL;
1406 peer->mesh_tunnel_handle = NULL;
1407 peer->stats_handle = NULL;
1408 peer->stats_op_handle = NULL;
1409 peer->search_str = NULL;
1410 peer->search_str_matched = GNUNET_NO;
1411 }
1412
1363 GNUNET_DISK_directory_scan (policy_dir, 1413 GNUNET_DISK_directory_scan (policy_dir,
1364 &policy_filename_cb, 1414 &policy_filename_cb,
1365 NULL); 1415 NULL);
@@ -1686,6 +1736,7 @@ run (void *cls, char *const *args, const char *cfgfile,
1686 const struct GNUNET_CONFIGURATION_Handle *config) 1736 const struct GNUNET_CONFIGURATION_Handle *config)
1687{ 1737{
1688 unsigned int nhost; 1738 unsigned int nhost;
1739 unsigned int nsearchstrs;
1689 1740
1690 if (NULL == args[0]) 1741 if (NULL == args[0])
1691 { 1742 {
@@ -1748,8 +1799,10 @@ run (void *cls, char *const *args, const char *cfgfile,
1748 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1799 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1749 return; 1800 return;
1750 } 1801 }
1751 if (num_search_strings != load_search_strings (args[2], &search_strings, num_search_strings)) 1802 nsearchstrs = load_search_strings (args[2], &search_strings, num_search_strings);
1803 if (num_search_strings != nsearchstrs)
1752 { 1804 {
1805 num_search_strings = nsearchstrs;
1753 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n")); 1806 fprintf (stderr, _("Error loading search strings. Given file does not contain enough strings. Exiting.\n"));
1754 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 1807 GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
1755 return; 1808 return;