diff options
Diffstat (limited to 'src/transport/transport-testing.c')
-rw-r--r-- | src/transport/transport-testing.c | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index fd5cc4701..4e11f2c78 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -52,6 +52,7 @@ get_host_key (struct GNUNET_TRANSPORT_TESTING_handle *tth) | |||
52 | return NULL; | 52 | return NULL; |
53 | } | 53 | } |
54 | 54 | ||
55 | |||
55 | static struct PeerContext * | 56 | static struct PeerContext * |
56 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 57 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
57 | const struct GNUNET_PeerIdentity *peer) | 58 | const struct GNUNET_PeerIdentity *peer) |
@@ -69,7 +70,8 @@ find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
69 | return t; | 70 | return t; |
70 | } | 71 | } |
71 | 72 | ||
72 | struct ConnectingContext * | 73 | |
74 | static struct ConnectingContext * | ||
73 | find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 75 | find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
74 | struct PeerContext *p1, struct PeerContext *p2) | 76 | struct PeerContext *p1, struct PeerContext *p2) |
75 | { | 77 | { |
@@ -88,6 +90,7 @@ find_connecting_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
88 | return cc; | 90 | return cc; |
89 | } | 91 | } |
90 | 92 | ||
93 | |||
91 | static void | 94 | static void |
92 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 95 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
93 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | 96 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) |
@@ -134,6 +137,7 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
134 | } | 137 | } |
135 | } | 138 | } |
136 | 139 | ||
140 | |||
137 | static void | 141 | static void |
138 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 142 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
139 | { | 143 | { |
@@ -167,6 +171,7 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
167 | p->nd (p->cb_cls, peer); | 171 | p->nd (p->cb_cls, peer); |
168 | } | 172 | } |
169 | 173 | ||
174 | |||
170 | static void | 175 | static void |
171 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 176 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, |
172 | const struct GNUNET_MessageHeader *message, | 177 | const struct GNUNET_MessageHeader *message, |
@@ -180,6 +185,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
180 | p->rec (p->cb_cls, peer, message, ats, ats_count); | 185 | p->rec (p->cb_cls, peer, message, ats, ats_count); |
181 | } | 186 | } |
182 | 187 | ||
188 | |||
183 | static void | 189 | static void |
184 | get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) | 190 | get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) |
185 | { | 191 | { |
@@ -307,11 +313,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
307 | GNUNET_OS_start_process (GNUNET_YES, | 313 | GNUNET_OS_start_process (GNUNET_YES, |
308 | NULL, NULL, "gnunet-service-arm", | 314 | NULL, NULL, "gnunet-service-arm", |
309 | "gnunet-service-arm", "-c", cfgname, | 315 | "gnunet-service-arm", "-c", cfgname, |
310 | #if VERBOSE_PEERS | ||
311 | "-L", "DEBUG", | ||
312 | #else | ||
313 | "-L", "ERROR", | 316 | "-L", "ERROR", |
314 | #endif | ||
315 | NULL); | 317 | NULL); |
316 | 318 | ||
317 | p->no = peer_id; | 319 | p->no = peer_id; |
@@ -361,10 +363,8 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
361 | GNUNET_assert (p->servicehome != NULL); | 363 | GNUNET_assert (p->servicehome != NULL); |
362 | 364 | ||
363 | /* shutdown */ | 365 | /* shutdown */ |
364 | #if VERBOSE | ||
365 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 366 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
366 | "Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); | 367 | "Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); |
367 | #endif | ||
368 | if (p->ghh != NULL) | 368 | if (p->ghh != NULL) |
369 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | 369 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); |
370 | p->ghh = NULL; | 370 | p->ghh = NULL; |
@@ -390,11 +390,8 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
390 | 390 | ||
391 | 391 | ||
392 | /* start */ | 392 | /* start */ |
393 | #if VERBOSE | ||
394 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 393 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
395 | "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); | 394 | "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); |
396 | #endif | ||
397 | |||
398 | sleep (5); // YUCK! | 395 | sleep (5); // YUCK! |
399 | 396 | ||
400 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | 397 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) |
@@ -424,11 +421,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
424 | GNUNET_OS_start_process (GNUNET_YES, | 421 | GNUNET_OS_start_process (GNUNET_YES, |
425 | NULL, NULL, "gnunet-service-arm", | 422 | NULL, NULL, "gnunet-service-arm", |
426 | "gnunet-service-arm", "-c", cfgname, | 423 | "gnunet-service-arm", "-c", cfgname, |
427 | #if VERBOSE_PEERS | ||
428 | "-L", "DEBUG", | ||
429 | #else | ||
430 | "-L", "ERROR", | 424 | "-L", "ERROR", |
431 | #endif | ||
432 | NULL); | 425 | NULL); |
433 | 426 | ||
434 | p->th = | 427 | p->th = |
@@ -451,6 +444,7 @@ fail: | |||
451 | return GNUNET_SYSERR; | 444 | return GNUNET_SYSERR; |
452 | } | 445 | } |
453 | 446 | ||
447 | |||
454 | /** | 448 | /** |
455 | * shutdown the given peer | 449 | * shutdown the given peer |
456 | * @param tth testing handle | 450 | * @param tth testing handle |
@@ -508,6 +502,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
508 | p = NULL; | 502 | p = NULL; |
509 | } | 503 | } |
510 | 504 | ||
505 | |||
511 | /** | 506 | /** |
512 | * Connect the given peers and call the callback when both peers report the | 507 | * Connect the given peers and call the callback when both peers report the |
513 | * inbound connection. Remarks: start_peer's notify_connect callback can be called | 508 | * inbound connection. Remarks: start_peer's notify_connect callback can be called |
@@ -559,6 +554,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_handle * | |||
559 | return cc; | 554 | return cc; |
560 | } | 555 | } |
561 | 556 | ||
557 | |||
562 | /** | 558 | /** |
563 | * Cancel the request to connect two peers | 559 | * Cancel the request to connect two peers |
564 | * Tou MUST cancel the request if you stop the peers before the peers connected succesfully | 560 | * Tou MUST cancel the request if you stop the peers before the peers connected succesfully |
@@ -627,6 +623,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) | |||
627 | tth = NULL; | 623 | tth = NULL; |
628 | } | 624 | } |
629 | 625 | ||
626 | |||
630 | /** | 627 | /** |
631 | * Initialize the transport testing | 628 | * Initialize the transport testing |
632 | * @return transport testing handle | 629 | * @return transport testing handle |
@@ -722,6 +719,7 @@ extract_filename (const char *file) | |||
722 | return res; | 719 | return res; |
723 | } | 720 | } |
724 | 721 | ||
722 | |||
725 | /** | 723 | /** |
726 | * Extracts the test filename from an absolute file name and removes the extension | 724 | * Extracts the test filename from an absolute file name and removes the extension |
727 | * @param file absolute file name | 725 | * @param file absolute file name |
@@ -781,7 +779,8 @@ GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file, char **dest) | |||
781 | 779 | ||
782 | 780 | ||
783 | /** | 781 | /** |
784 | * Extracts the plugin anme from an absolute file name and the test name | 782 | * Extracts the plugin name from an absolute file name and the test name |
783 | * | ||
785 | * @param file absolute file name | 784 | * @param file absolute file name |
786 | * @param test test name | 785 | * @param test test name |
787 | * @param dest where to store result | 786 | * @param dest where to store result |
@@ -790,43 +789,39 @@ void | |||
790 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, | 789 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, |
791 | const char *test, char **dest) | 790 | const char *test, char **dest) |
792 | { | 791 | { |
792 | char *filename; | ||
793 | char *dotexe; | ||
793 | char *e = extract_filename (file); | 794 | char *e = extract_filename (file); |
794 | char *t = extract_filename (test); | 795 | char *t = extract_filename (test); |
795 | 796 | ||
796 | char *filename = NULL; | 797 | if (NULL == e) |
797 | char *dotexe; | ||
798 | |||
799 | if (e == NULL) | ||
800 | goto fail; | 798 | goto fail; |
801 | |||
802 | /* remove "lt-" */ | 799 | /* remove "lt-" */ |
803 | filename = strstr (e, "tes"); | 800 | filename = strstr (e, "tes"); |
804 | if (filename == NULL) | 801 | if (NULL == filename) |
805 | goto fail; | 802 | goto fail; |
806 | |||
807 | /* remove ".exe" */ | 803 | /* remove ".exe" */ |
808 | if (NULL != (dotexe = strstr (filename, ".exe"))) | 804 | if (NULL != (dotexe = strstr (filename, ".exe"))) |
809 | dotexe[0] = '\0'; | 805 | dotexe[0] = '\0'; |
810 | 806 | ||
811 | /* find last _ */ | 807 | /* find last _ */ |
812 | filename = strstr (filename, t); | 808 | filename = strstr (filename, t); |
813 | if (filename == NULL) | 809 | if (NULL == filename) |
814 | goto fail; | 810 | goto fail; |
815 | |||
816 | /* copy plugin */ | 811 | /* copy plugin */ |
817 | filename += strlen (t); | 812 | filename += strlen (t); |
818 | filename++; | 813 | if ('\0' != *filename) |
814 | filename++; | ||
819 | GNUNET_asprintf (dest, "%s", filename); | 815 | GNUNET_asprintf (dest, "%s", filename); |
820 | goto suc; | 816 | goto suc; |
821 | |||
822 | fail: | 817 | fail: |
823 | (*dest) = NULL; | 818 | (*dest) = NULL; |
824 | suc: | 819 | suc: |
825 | GNUNET_free (t); | 820 | GNUNET_free (t); |
826 | GNUNET_free (e); | 821 | GNUNET_free (e); |
827 | |||
828 | } | 822 | } |
829 | 823 | ||
824 | |||
830 | /** | 825 | /** |
831 | * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and | 826 | * This function takes the filename (e.g. argv[0), removes a "lt-"-prefix and |
832 | * if existing ".exe"-prefix and adds the peer-number | 827 | * if existing ".exe"-prefix and adds the peer-number |
@@ -843,30 +838,23 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, char **dest, | |||
843 | char *backup = filename; | 838 | char *backup = filename; |
844 | char *dotexe; | 839 | char *dotexe; |
845 | 840 | ||
846 | if (filename == NULL) | 841 | if (NULL == filename) |
847 | goto fail; | 842 | goto fail; |
848 | |||
849 | /* remove "lt-" */ | 843 | /* remove "lt-" */ |
850 | filename = strstr (filename, "tes"); | 844 | filename = strstr (filename, "tes"); |
851 | if (filename == NULL) | 845 | if (NULL == filename) |
852 | goto fail; | 846 | goto fail; |
853 | |||
854 | /* remove ".exe" */ | 847 | /* remove ".exe" */ |
855 | if (NULL != (dotexe = strstr (filename, ".exe"))) | 848 | if (NULL != (dotexe = strstr (filename, ".exe"))) |
856 | dotexe[0] = '\0'; | 849 | dotexe[0] = '\0'; |
857 | 850 | GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count); | |
858 | goto suc; | 851 | GNUNET_free (backup); |
859 | 852 | return; | |
860 | fail: | 853 | fail: |
861 | (*dest) = NULL; | 854 | (*dest) = NULL; |
862 | return; | ||
863 | |||
864 | suc: | ||
865 | /* create cfg filename */ | ||
866 | GNUNET_asprintf (dest, "%s_peer%u.conf", filename, count); | ||
867 | GNUNET_free (backup); | 855 | GNUNET_free (backup); |
868 | } | 856 | } |
869 | 857 | ||
870 | 858 | ||
871 | 859 | ||
872 | /* end of transport_testing.h */ | 860 | /* end of transport-testing.c */ |