aboutsummaryrefslogtreecommitdiff
path: root/src/mesh/test_mesh_small.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-29 10:19:43 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-29 10:19:43 +0000
commitcddbdf5b928c68ab71b40c950b9f01ea68a9fbdb (patch)
treeb704e00a3af618b2cd174a7f89514eaebd82a1cf /src/mesh/test_mesh_small.c
parentbb4fc4f4007988874f910d4de5492f9629301641 (diff)
downloadgnunet-cddbdf5b928c68ab71b40c950b9f01ea68a9fbdb.tar.gz
gnunet-cddbdf5b928c68ab71b40c950b9f01ea68a9fbdb.zip
run indent twice, it alternates between two 'canonical' forms, also run whitespace remover
Diffstat (limited to 'src/mesh/test_mesh_small.c')
-rw-r--r--src/mesh/test_mesh_small.c294
1 files changed, 144 insertions, 150 deletions
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 30b2d8aef..6234d0359 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -48,7 +48,7 @@ struct StatsContext
48 48
49 49
50// static struct MeshPeer *peer_head; 50// static struct MeshPeer *peer_head;
51// 51//
52// static struct MeshPeer *peer_tail; 52// static struct MeshPeer *peer_tail;
53 53
54/** 54/**
@@ -180,7 +180,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
180 if (data_file != NULL) 180 if (data_file != NULL)
181 GNUNET_DISK_file_close (data_file); 181 GNUNET_DISK_file_close (data_file);
182 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 182 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
183 GNUNET_CONFIGURATION_destroy(testing_cfg); 183 GNUNET_CONFIGURATION_destroy (testing_cfg);
184} 184}
185 185
186 186
@@ -189,7 +189,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 */ 189 */
190static struct GNUNET_MESH_MessageHandler handlers[] = { 190static struct GNUNET_MESH_MessageHandler handlers[] = {
191// {&callback, 1, 0}, 191// {&callback, 1, 0},
192 {NULL, 0, 0} 192 {NULL, 0, 0}
193}; 193};
194 194
195 195
@@ -203,15 +203,13 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
203 * with the tunnel is stored 203 * with the tunnel is stored
204 */ 204 */
205static void 205static void
206tunnel_cleaner (void *cls, 206tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel,
207 const struct GNUNET_MESH_Tunnel * tunnel,
208 void **tunnel_ctx) 207 void **tunnel_ctx)
209{ 208{
210#if VERBOSE 209#if VERBOSE
211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel disconnected\n");
212 "tunnel disconnected\n");
213#endif 211#endif
214 return; 212 return;
215} 213}
216 214
217/** 215/**
@@ -223,9 +221,8 @@ tunnel_cleaner (void *cls,
223static void 221static void
224dh (void *cls, const struct GNUNET_PeerIdentity *peer) 222dh (void *cls, const struct GNUNET_PeerIdentity *peer)
225{ 223{
226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer disconnected\n");
227 "peer disconnected\n"); 225 return;
228 return;
229} 226}
230 227
231 228
@@ -237,48 +234,43 @@ dh (void *cls, const struct GNUNET_PeerIdentity *peer)
237 * @param atsi performance data for the connection 234 * @param atsi performance data for the connection
238 */ 235 */
239static void 236static void
240ch (void *cls, 237ch (void *cls, const struct GNUNET_PeerIdentity *peer,
241 const struct GNUNET_PeerIdentity * peer, 238 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
242 const struct GNUNET_TRANSPORT_ATS_Information * atsi)
243{ 239{
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer connected\n");
245 "peer connected\n"); 241 return;
246 return;
247} 242}
248 243
249 244
250/** 245/**
251 * connect_mesh_service: connect to the mesh service of one of the peers 246 * connect_mesh_service: connect to the mesh service of one of the peers
252 * 247 *
253 */ 248 */
254static void 249static void
255connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 250connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256{ 251{
257 struct GNUNET_TESTING_Daemon *d; 252 struct GNUNET_TESTING_Daemon *d;
258 struct GNUNET_MESH_Handle *h; 253 struct GNUNET_MESH_Handle *h;
259 struct GNUNET_MESH_Tunnel *t; 254 struct GNUNET_MESH_Tunnel *t;
260 GNUNET_MESH_ApplicationType app; 255 GNUNET_MESH_ApplicationType app;
261 256
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connect_mesh_service\n");
263 "connect_mesh_service\n");
264 258
265 d = GNUNET_TESTING_daemon_get(pg, 1); 259 d = GNUNET_TESTING_daemon_get (pg, 1);
266 app = (GNUNET_MESH_ApplicationType) 0; 260 app = (GNUNET_MESH_ApplicationType) 0;
267 261
268#if VERBOSE 262#if VERBOSE
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
270 "connecting to mesh service of peer %s\n", 264 "connecting to mesh service of peer %s\n", GNUNET_i2s (&d->id));
271 GNUNET_i2s(&d->id));
272#endif 265#endif
273 h = GNUNET_MESH_connect(d->cfg, NULL, &tunnel_cleaner, handlers, &app); 266 h = GNUNET_MESH_connect (d->cfg, NULL, &tunnel_cleaner, handlers, &app);
274#if VERBOSE 267#if VERBOSE
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected to mesh service of peer %s\n",
276 "connected to mesh service of peer %s\n", 269 GNUNET_i2s (&d->id));
277 GNUNET_i2s(&d->id));
278#endif 270#endif
279 t = GNUNET_MESH_tunnel_create(h, &ch, &dh, NULL); 271 t = GNUNET_MESH_tunnel_create (h, &ch, &dh, NULL);
280 GNUNET_MESH_tunnel_destroy(t); 272 GNUNET_MESH_tunnel_destroy (t);
281 GNUNET_MESH_disconnect(h); 273 GNUNET_MESH_disconnect (h);
282} 274}
283 275
284 276
@@ -338,8 +330,8 @@ statistics_iterator (void *cls, const struct GNUNET_PeerIdentity *peer,
338{ 330{
339 struct StatsContext *stats_context = cls; 331 struct StatsContext *stats_context = cls;
340 332
341// 333//
342// if ( (0 == strstr(subsystem, "nse")) && 334// if ( (0 == strstr(subsystem, "nse")) &&
343// (0 == strstr(name, "# flood messages received")) ) 335// (0 == strstr(name, "# flood messages received")) )
344 stats_context->total_mesh_bytes += 1; //value; 336 stats_context->total_mesh_bytes += 1; //value;
345 return GNUNET_OK; 337 return GNUNET_OK;
@@ -489,38 +481,38 @@ churn_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
489static void 481static void
490peergroup_ready (void *cls, const char *emsg) 482peergroup_ready (void *cls, const char *emsg)
491{ 483{
492 char *buf; 484 char *buf;
493 int buf_len; 485 int buf_len;
494 486
495 if (emsg != NULL) 487 if (emsg != NULL)
496 { 488 {
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
498 "Peergroup callback called with error, aborting test!\n"); 490 "Peergroup callback called with error, aborting test!\n");
499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n"); 491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
500 ok = 1; 492 ok = 1;
501 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 493 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
502 return; 494 return;
503 } 495 }
504 496
505#if VERBOSE 497#if VERBOSE
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n"); 498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer Group started successfully!\n");
507#endif 499#endif
508 500
509 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n", 501 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Have %u connections\n",
510 total_connections); 502 total_connections);
511 if (data_file != NULL) 503 if (data_file != NULL)
512 { 504 {
513 buf = NULL; 505 buf = NULL;
514 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); 506 buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections);
515 if (buf_len > 0) 507 if (buf_len > 0)
516 GNUNET_DISK_file_write (data_file, buf, buf_len); 508 GNUNET_DISK_file_write (data_file, buf, buf_len);
517 GNUNET_free (buf); 509 GNUNET_free (buf);
518 } 510 }
519 peers_running = GNUNET_TESTING_daemons_running (pg); 511 peers_running = GNUNET_TESTING_daemons_running (pg);
520 512
521 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL); 513 GNUNET_SCHEDULER_add_now (&connect_mesh_service, NULL);
522 disconnect_task = 514 disconnect_task =
523 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); 515 GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL);
524 516
525} 517}
526 518
@@ -563,110 +555,112 @@ static void
563run (void *cls, char *const *args, const char *cfgfile, 555run (void *cls, char *const *args, const char *cfgfile,
564 const struct GNUNET_CONFIGURATION_Handle *cfg) 556 const struct GNUNET_CONFIGURATION_Handle *cfg)
565{ 557{
566 char *temp_str; 558 char *temp_str;
567 unsigned long long temp_wait; 559 unsigned long long temp_wait;
568 struct GNUNET_TESTING_Host *hosts; 560 struct GNUNET_TESTING_Host *hosts;
569 561
570 ok = 1; 562 ok = 1;
571 testing_cfg = GNUNET_CONFIGURATION_dup(cfg); 563 testing_cfg = GNUNET_CONFIGURATION_dup (cfg);
572 564
573 GNUNET_log_setup ("test_mesh_small", 565 GNUNET_log_setup ("test_mesh_small",
574#if VERBOSE 566#if VERBOSE
575 "DEBUG", 567 "DEBUG",
576#else 568#else
577 "WARNING", 569 "WARNING",
578#endif 570#endif
579 NULL); 571 NULL);
580 572
581#if VERBOSE 573#if VERBOSE
582 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n"); 574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting daemons.\n");
583 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", 575 GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing",
584 "use_progressbars", "YES"); 576 "use_progressbars", "YES");
585#endif 577#endif
586 578
579 if (GNUNET_OK !=
580 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
581 "num_peers", &num_peers))
582 {
583 GNUNET_CONFIGURATION_load (testing_cfg, "test_mesh_small.conf");
587 if (GNUNET_OK != 584 if (GNUNET_OK !=
588 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", 585 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing",
589 "num_peers", &num_peers)) 586 "num_peers", &num_peers))
590 { 587 {
591 GNUNET_CONFIGURATION_load(testing_cfg, "test_mesh_small.conf"); 588 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
592 if (GNUNET_OK != 589 "Option TESTING:NUM_PEERS is required!\n");
593 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", 590 return;
594 "num_peers", &num_peers))
595 {
596 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
597 "Option TESTING:NUM_PEERS is required!\n");
598 return;
599 }
600 } 591 }
592 }
601 593
602 if (GNUNET_OK != 594 if (GNUNET_OK !=
603 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", 595 GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small",
604 "wait_time", &temp_wait)) 596 "wait_time", &temp_wait))
605 { 597 {
606 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 598 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
607 "Option nsetest_mesh_small:wait_time is required!\n"); 599 "Option nsetest_mesh_small:wait_time is required!\n");
608 return; 600 return;
609 } 601 }
610 602
611 if (GNUNET_OK != 603 if (GNUNET_OK !=
612 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", 604 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing",
613 "topology_output_file", 605 "topology_output_file",
614 &topology_file)) 606 &topology_file))
615 { 607 {
616 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
617 "Option test_mesh_small:topology_output_file is required!\n"); 609 "Option test_mesh_small:topology_output_file is required!\n");
618 return; 610 return;
619 } 611 }
620 612
621 if (GNUNET_OK != 613 if (GNUNET_OK !=
622 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", 614 GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small",
623 "data_output_file", 615 "data_output_file",
624 &data_filename)) 616 &data_filename))
625 { 617 {
626 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 618 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
627 "Option test_mesh_small:data_output_file is required!\n"); 619 "Option test_mesh_small:data_output_file is required!\n");
628 return; 620 return;
629 } 621 }
630 622
631 data_file = GNUNET_DISK_file_open (data_filename, 623 data_file =
632 GNUNET_DISK_OPEN_READWRITE | 624 GNUNET_DISK_file_open (data_filename,
633 GNUNET_DISK_OPEN_CREATE, 625 GNUNET_DISK_OPEN_READWRITE |
634 GNUNET_DISK_PERM_USER_READ | 626 GNUNET_DISK_OPEN_CREATE,
635 GNUNET_DISK_PERM_USER_WRITE); 627 GNUNET_DISK_PERM_USER_READ |
636 if (data_file == NULL) { 628 GNUNET_DISK_PERM_USER_WRITE);
637 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 629 if (data_file == NULL)
638 "Failed to open %s for output!\n", 630 {
639 data_filename); 631 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
640 GNUNET_free (data_filename); 632 data_filename);
641 } 633 GNUNET_free (data_filename);
634 }
642 635
643 wait_time = 636 wait_time =
644 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); 637 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait);
645 638
646 if (GNUNET_YES == 639 if (GNUNET_YES ==
647 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", 640 GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small",
648 "output_file", &temp_str)) 641 "output_file", &temp_str))
649 { 642 {
650 output_file = GNUNET_DISK_file_open (temp_str, 643 output_file =
651 GNUNET_DISK_OPEN_READWRITE | 644 GNUNET_DISK_file_open (temp_str,
652 GNUNET_DISK_OPEN_CREATE, 645 GNUNET_DISK_OPEN_READWRITE |
653 GNUNET_DISK_PERM_USER_READ | 646 GNUNET_DISK_OPEN_CREATE,
654 GNUNET_DISK_PERM_USER_WRITE); 647 GNUNET_DISK_PERM_USER_READ |
655 if (output_file == NULL) 648 GNUNET_DISK_PERM_USER_WRITE);
656 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 649 if (output_file == NULL)
657 "Failed to open %s for output!\n", 650 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n",
658 temp_str); 651 temp_str);
659 } 652 }
660 GNUNET_free_non_null (temp_str); 653 GNUNET_free_non_null (temp_str);
661 654
662 hosts = GNUNET_TESTING_hosts_load (testing_cfg); 655 hosts = GNUNET_TESTING_hosts_load (testing_cfg);
663 656
664 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, 657 pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT,
665 &connect_cb, &peergroup_ready, NULL, hosts); 658 &connect_cb, &peergroup_ready, NULL,
666 GNUNET_assert (pg != NULL); 659 hosts);
667 shutdown_handle = GNUNET_SCHEDULER_add_delayed ( 660 GNUNET_assert (pg != NULL);
668 GNUNET_TIME_relative_get_forever (), 661 shutdown_handle =
669 &shutdown_task, NULL); 662 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (),
663 &shutdown_task, NULL);
670} 664}
671 665
672 666
@@ -688,13 +682,13 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = {
688int 682int
689main (int argc, char *argv[]) 683main (int argc, char *argv[])
690{ 684{
691 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small", 685 GNUNET_PROGRAM_run (argc, argv, "test_mesh_small",
692 gettext_noop ("Test mesh in a small network."), options, 686 gettext_noop ("Test mesh in a small network."), options,
693 &run, NULL); 687 &run, NULL);
694#if REMOVE_DIR 688#if REMOVE_DIR
695 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small"); 689 GNUNET_DISK_directory_remove ("/tmp/test_mesh_small");
696#endif 690#endif
697 return ok; 691 return ok;
698} 692}
699 693
700/* end of test_mesh_small.c */ 694/* end of test_mesh_small.c */