aboutsummaryrefslogtreecommitdiff
path: root/src/dv/test_transport_api_dv.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/dv/test_transport_api_dv.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/dv/test_transport_api_dv.c')
-rw-r--r--src/dv/test_transport_api_dv.c183
1 files changed, 73 insertions, 110 deletions
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 5d9d367e1..fee8eea81 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -285,15 +285,13 @@ disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
285 285
286 /* Disconnect from the respective cores */ 286 /* Disconnect from the respective cores */
287#if VERBOSE 287#if VERBOSE
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 1 `%4s'\n",
289 "Disconnecting from peer 1 `%4s'\n",
290 GNUNET_i2s (&pos->peer1->id)); 289 GNUNET_i2s (&pos->peer1->id));
291#endif 290#endif
292 if (pos->peer1handle != NULL) 291 if (pos->peer1handle != NULL)
293 GNUNET_CORE_disconnect (pos->peer1handle); 292 GNUNET_CORE_disconnect (pos->peer1handle);
294#if VERBOSE 293#if VERBOSE
295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from peer 2 `%4s'\n",
296 "Disconnecting from peer 2 `%4s'\n",
297 GNUNET_i2s (&pos->peer2->id)); 295 GNUNET_i2s (&pos->peer2->id));
298#endif 296#endif
299 if (pos->peer2handle != NULL) 297 if (pos->peer2handle != NULL)
@@ -384,8 +382,8 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
384 } 382 }
385} 383}
386 384
387static void 385static void send_other_messages (void *cls,
388send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 386 const struct GNUNET_SCHEDULER_TaskContext *tc);
389 387
390/** 388/**
391 * Get distance information from 'atsi'. 389 * Get distance information from 'atsi'.
@@ -409,8 +407,7 @@ get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
409} 407}
410 408
411static int 409static int
412process_mtype (void *cls, 410process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
413 const struct GNUNET_PeerIdentity *peer,
414 const struct GNUNET_MessageHeader *message, 411 const struct GNUNET_MessageHeader *message,
415 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 412 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
416{ 413{
@@ -460,9 +457,9 @@ process_mtype (void *cls,
460 (total_other_messages == 0)) 457 (total_other_messages == 0))
461 { 458 {
462 GNUNET_SCHEDULER_cancel (die_task); 459 GNUNET_SCHEDULER_cancel (die_task);
463 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 460 die_task =
464 &end_badly, 461 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
465 "waiting for DV peers to connect!"); 462 "waiting for DV peers to connect!");
466 /* 463 /*
467 * if ((num_peers == 3) && (total_other_expected_messages == 2)) 464 * if ((num_peers == 3) && (total_other_expected_messages == 2))
468 * { 465 * {
@@ -527,9 +524,7 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
527 * @param atsi performance data for the connection 524 * @param atsi performance data for the connection
528 */ 525 */
529static void 526static void
530connect_notify_peer2 (void *cls, 527connect_notify_peer2 (void *cls, const struct GNUNET_PeerIdentity *peer,
531 const struct
532 GNUNET_PeerIdentity *peer,
533 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 528 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
534{ 529{
535 struct TestMessageContext *pos = cls; 530 struct TestMessageContext *pos = cls;
@@ -541,14 +536,11 @@ connect_notify_peer2 (void *cls,
541 "Core connection from `%s' to `%4s' verfied, sending message!\n", 536 "Core connection from `%s' to `%4s' verfied, sending message!\n",
542 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey)); 537 GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
543#endif 538#endif
544 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 539 if (NULL ==
545 GNUNET_YES, 540 GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
546 0, 541 TIMEOUT, &pos->peer2->id,
547 TIMEOUT, 542 sizeof (struct GNUNET_TestMessage),
548 &pos->peer2->id, 543 &transmit_ready, pos))
549 sizeof (struct
550 GNUNET_TestMessage),
551 &transmit_ready, pos))
552 { 544 {
553 /* This probably shouldn't happen, but it does (timing issue?) */ 545 /* This probably shouldn't happen, but it does (timing issue?) */
554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 546 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -565,8 +557,7 @@ connect_notify_peer2 (void *cls,
565} 557}
566 558
567static void 559static void
568init_notify_peer2 (void *cls, 560init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
569 struct GNUNET_CORE_Handle *server,
570 const struct GNUNET_PeerIdentity *my_identity, 561 const struct GNUNET_PeerIdentity *my_identity,
571 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 562 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
572 *publicKey) 563 *publicKey)
@@ -588,9 +579,7 @@ init_notify_peer2 (void *cls,
588 * @param atsi performance data for the connection 579 * @param atsi performance data for the connection
589 */ 580 */
590static void 581static void
591connect_notify_peer1 (void *cls, 582connect_notify_peer1 (void *cls, const struct GNUNET_PeerIdentity *peer,
592 const struct
593 GNUNET_PeerIdentity *peer,
594 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 583 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
595{ 584{
596 struct TestMessageContext *pos = cls; 585 struct TestMessageContext *pos = cls;
@@ -605,21 +594,15 @@ connect_notify_peer1 (void *cls,
605 /* 594 /*
606 * Connect to the receiving peer 595 * Connect to the receiving peer
607 */ 596 */
608 pos->peer2handle = GNUNET_CORE_connect (pos->peer2->cfg, 597 pos->peer2handle =
609 1, 598 GNUNET_CORE_connect (pos->peer2->cfg, 1, pos, &init_notify_peer2,
610 pos, 599 &connect_notify_peer2, NULL, NULL, NULL,
611 &init_notify_peer2, 600 GNUNET_YES, NULL, GNUNET_YES, handlers);
612 &connect_notify_peer2,
613 NULL,
614 NULL, NULL,
615 GNUNET_YES, NULL, GNUNET_YES,
616 handlers);
617 } 601 }
618} 602}
619 603
620static void 604static void
621init_notify_peer1 (void *cls, 605init_notify_peer1 (void *cls, struct GNUNET_CORE_Handle *server,
622 struct GNUNET_CORE_Handle *server,
623 const struct GNUNET_PeerIdentity *my_identity, 606 const struct GNUNET_PeerIdentity *my_identity,
624 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded 607 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
625 *publicKey) 608 *publicKey)
@@ -643,9 +626,9 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
643 626
644 if (die_task == GNUNET_SCHEDULER_NO_TASK) 627 if (die_task == GNUNET_SCHEDULER_NO_TASK)
645 { 628 {
646 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 629 die_task =
647 &end_badly, 630 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
648 "from create topology (timeout)"); 631 "from create topology (timeout)");
649 } 632 }
650 633
651 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS) 634 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
@@ -663,16 +646,10 @@ send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
663 /* 646 /*
664 * Connect to the sending peer 647 * Connect to the sending peer
665 */ 648 */
666 pos->peer1handle = GNUNET_CORE_connect (pos->peer1->cfg, 649 pos->peer1handle =
667 1, 650 GNUNET_CORE_connect (pos->peer1->cfg, 1, pos, &init_notify_peer1,
668 pos, 651 &connect_notify_peer1, NULL, NULL, NULL, GNUNET_NO,
669 &init_notify_peer1, 652 NULL, GNUNET_NO, no_handlers);
670 &connect_notify_peer1,
671 NULL,
672 NULL,
673 NULL,
674 GNUNET_NO, NULL, GNUNET_NO,
675 no_handlers);
676 653
677 GNUNET_assert (pos->peer1handle != NULL); 654 GNUNET_assert (pos->peer1handle != NULL);
678 655
@@ -773,10 +750,8 @@ send_other_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
773} 750}
774 751
775static void 752static void
776topology_callback (void *cls, 753topology_callback (void *cls, const struct GNUNET_PeerIdentity *first,
777 const struct GNUNET_PeerIdentity *first, 754 const struct GNUNET_PeerIdentity *second, uint32_t distance,
778 const struct GNUNET_PeerIdentity *second,
779 uint32_t distance,
780 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 755 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
781 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 756 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
782 struct GNUNET_TESTING_Daemon *first_daemon, 757 struct GNUNET_TESTING_Daemon *first_daemon,
@@ -859,15 +834,14 @@ connect_topology ()
859 expected_connections = -1; 834 expected_connections = -1;
860 if ((pg != NULL) && (peers_left == 0)) 835 if ((pg != NULL) && (peers_left == 0))
861 { 836 {
862 expected_connections = GNUNET_TESTING_connect_topology (pg, 837 expected_connections =
863 connection_topology, 838 GNUNET_TESTING_connect_topology (pg, connection_topology,
864 connect_topology_option, 839 connect_topology_option,
865 connect_topology_option_modifier, 840 connect_topology_option_modifier,
866 TIMEOUT, 841 TIMEOUT, 12, NULL, NULL);
867 12, NULL, NULL);
868#if VERBOSE 842#if VERBOSE
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 843 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Have %d expected connections\n",
870 "Have %d expected connections\n", expected_connections); 844 expected_connections);
871#endif 845#endif
872 } 846 }
873 847
@@ -879,9 +853,9 @@ connect_topology ()
879 "from connect topology (bad return)"); 853 "from connect topology (bad return)");
880 } 854 }
881 855
882 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 856 die_task =
883 &end_badly, 857 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
884 "from connect topology (timeout)"); 858 "from connect topology (timeout)");
885} 859}
886 860
887static void 861static void
@@ -905,9 +879,9 @@ create_topology ()
905 "from create topology (bad return)"); 879 "from create topology (bad return)");
906 } 880 }
907 GNUNET_SCHEDULER_cancel (die_task); 881 GNUNET_SCHEDULER_cancel (die_task);
908 die_task = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, 882 die_task =
909 &end_badly, 883 GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &end_badly,
910 "from continue startup (timeout)"); 884 "from continue startup (timeout)");
911} 885}
912 886
913/** 887/**
@@ -919,9 +893,7 @@ create_topology ()
919 * @param distance reported distance (DV) to 'other' 893 * @param distance reported distance (DV) to 'other'
920 */ 894 */
921static void 895static void
922all_connect_handler (void *cls, 896all_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer,
923 const struct
924 GNUNET_PeerIdentity *peer,
925 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 897 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
926{ 898{
927 struct GNUNET_TESTING_Daemon *d = cls; 899 struct GNUNET_TESTING_Daemon *d = cls;
@@ -940,8 +912,8 @@ all_connect_handler (void *cls,
940 912
941#if VERBOSE 913#if VERBOSE
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "connected peer %s to peer %s, distance %u\n", 915 "connected peer %s to peer %s, distance %u\n", d->shortname,
944 d->shortname, second_shortname, distance); 916 second_shortname, distance);
945#endif 917#endif
946 918
947 second_daemon = 919 second_daemon =
@@ -993,8 +965,7 @@ all_connect_handler (void *cls,
993} 965}
994 966
995static void 967static void
996peers_started_callback (void *cls, 968peers_started_callback (void *cls, const struct GNUNET_PeerIdentity *id,
997 const struct GNUNET_PeerIdentity *id,
998 const struct GNUNET_CONFIGURATION_Handle *cfg, 969 const struct GNUNET_CONFIGURATION_Handle *cfg,
999 struct GNUNET_TESTING_Daemon *d, const char *emsg) 970 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1000{ 971{
@@ -1017,13 +988,9 @@ peers_started_callback (void *cls,
1017 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 988 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
1018 989
1019 new_peer = GNUNET_malloc (sizeof (struct PeerContext)); 990 new_peer = GNUNET_malloc (sizeof (struct PeerContext));
1020 new_peer->peer_handle = GNUNET_CORE_connect (cfg, 991 new_peer->peer_handle =
1021 1, 992 GNUNET_CORE_connect (cfg, 1, d, NULL, &all_connect_handler, NULL, NULL,
1022 d, NULL, 993 NULL, GNUNET_NO, NULL, GNUNET_NO, no_handlers);
1023 &all_connect_handler,
1024 NULL, NULL, NULL,
1025 GNUNET_NO, NULL, GNUNET_NO,
1026 no_handlers);
1027 new_peer->daemon = d; 994 new_peer->daemon = d;
1028 new_peer->next = all_peers; 995 new_peer->next = all_peers;
1029 all_peers = new_peer; 996 all_peers = new_peer;
@@ -1038,10 +1005,10 @@ peers_started_callback (void *cls,
1038 GNUNET_SCHEDULER_cancel (die_task); 1005 GNUNET_SCHEDULER_cancel (die_task);
1039 /* Set up task in case topology creation doesn't finish 1006 /* Set up task in case topology creation doesn't finish
1040 * within a reasonable amount of time */ 1007 * within a reasonable amount of time */
1041 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1008 die_task =
1042 (GNUNET_TIME_UNIT_MINUTES, 5), 1009 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1043 &end_badly, 1010 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1044 "from peers_started_callback"); 1011 "from peers_started_callback");
1045 1012
1046 connect_topology (); 1013 connect_topology ();
1047 ok = 0; 1014 ok = 0;
@@ -1057,8 +1024,7 @@ peers_started_callback (void *cls,
1057 * @param emsg non-null on failure 1024 * @param emsg non-null on failure
1058 */ 1025 */
1059static void 1026static void
1060hostkey_callback (void *cls, 1027hostkey_callback (void *cls, const struct GNUNET_PeerIdentity *id,
1061 const struct GNUNET_PeerIdentity *id,
1062 struct GNUNET_TESTING_Daemon *d, const char *emsg) 1028 struct GNUNET_TESTING_Daemon *d, const char *emsg)
1063{ 1029{
1064 if (emsg != NULL) 1030 if (emsg != NULL)
@@ -1068,8 +1034,8 @@ hostkey_callback (void *cls,
1068 } 1034 }
1069 1035
1070#if VERBOSE 1036#if VERBOSE
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Hostkey created for peer `%s'\n",
1072 "Hostkey created for peer `%s'\n", GNUNET_i2s (id)); 1038 GNUNET_i2s (id));
1073#endif 1039#endif
1074 peers_left--; 1040 peers_left--;
1075 if (peers_left == 0) 1041 if (peers_left == 0)
@@ -1081,19 +1047,18 @@ hostkey_callback (void *cls,
1081 GNUNET_SCHEDULER_cancel (die_task); 1047 GNUNET_SCHEDULER_cancel (die_task);
1082 /* Set up task in case topology creation doesn't finish 1048 /* Set up task in case topology creation doesn't finish
1083 * within a reasonable amount of time */ 1049 * within a reasonable amount of time */
1084 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1050 die_task =
1085 (GNUNET_TIME_UNIT_MINUTES, 5), 1051 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1086 &end_badly, 1052 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1087 "from hostkey_callback"); 1053 "from hostkey_callback");
1088 GNUNET_SCHEDULER_add_now (&create_topology, NULL); 1054 GNUNET_SCHEDULER_add_now (&create_topology, NULL);
1089 ok = 0; 1055 ok = 0;
1090 } 1056 }
1091} 1057}
1092 1058
1093static void 1059static void
1094run (void *cls, 1060run (void *cls, char *const *args, const char *cfgfile,
1095 char *const *args, 1061 const struct GNUNET_CONFIGURATION_Handle *cfg)
1096 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
1097{ 1062{
1098 char *topology_str; 1063 char *topology_str;
1099 char *connect_topology_str; 1064 char *connect_topology_str;
@@ -1216,20 +1181,18 @@ run (void *cls,
1216 peers_left = num_peers; 1181 peers_left = num_peers;
1217 1182
1218 /* Set up a task to end testing if peer start fails */ 1183 /* Set up a task to end testing if peer start fails */
1219 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1184 die_task =
1220 (GNUNET_TIME_UNIT_MINUTES, 5), 1185 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1221 &end_badly, 1186 (GNUNET_TIME_UNIT_MINUTES, 5), &end_badly,
1222 "didn't start all daemons in reasonable amount of time!!!"); 1187 "didn't start all daemons in reasonable amount of time!!!");
1223 1188
1224 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left); 1189 peer_daemon_hash = GNUNET_CONTAINER_multihashmap_create (peers_left);
1225 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */ 1190 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
1226 peers_left, /* Number of outstanding connections */ 1191 peers_left, /* Number of outstanding connections */
1227 peers_left, /* Number of parallel ssh connections, or peers being started at once */ 1192 peers_left, /* Number of parallel ssh connections, or peers being started at once */
1228 TIMEOUT, 1193 TIMEOUT, &hostkey_callback, NULL,
1229 &hostkey_callback, 1194 &peers_started_callback, NULL,
1230 NULL, 1195 &topology_callback, NULL, NULL);
1231 &peers_started_callback,
1232 NULL, &topology_callback, NULL, NULL);
1233 1196
1234} 1197}
1235 1198
@@ -1249,9 +1212,9 @@ check ()
1249 struct GNUNET_GETOPT_CommandLineOption options[] = { 1212 struct GNUNET_GETOPT_CommandLineOption options[] = {
1250 GNUNET_GETOPT_OPTION_END 1213 GNUNET_GETOPT_OPTION_END
1251 }; 1214 };
1252 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 1215 ret =
1253 argv, "test-transport-dv", "nohelp", 1216 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
1254 options, &run, &ok); 1217 "test-transport-dv", "nohelp", options, &run, &ok);
1255 if (ret != GNUNET_OK) 1218 if (ret != GNUNET_OK)
1256 { 1219 {
1257 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1220 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,