diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-02 14:56:30 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-07-02 14:56:30 +0000 |
commit | ad3870165e0c80ac5ec04d5ac78251eeba13e403 (patch) | |
tree | dc96d36a90b7b776f6e32322dee68ccba18a2a3d /src | |
parent | 6d9ebef7d96adad01308c135f27748ec3f6b7774 (diff) | |
download | gnunet-ad3870165e0c80ac5ec04d5ac78251eeba13e403.tar.gz gnunet-ad3870165e0c80ac5ec04d5ac78251eeba13e403.zip |
porting transport testing to new testing lib (mantis 2453)
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/Makefile.am | 10 | ||||
-rw-r--r-- | src/transport/test_transport_testing.c | 28 | ||||
-rw-r--r-- | src/transport/test_transport_testing_restart.c | 152 | ||||
-rw-r--r-- | src/transport/test_transport_testing_startstop.c | 106 | ||||
-rw-r--r-- | src/transport/transport-testing.c | 294 | ||||
-rw-r--r-- | src/transport/transport-testing.h | 34 |
6 files changed, 310 insertions, 314 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 0090d3aca..0cf817db9 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -253,6 +253,7 @@ libgnunet_plugin_transport_https_la_CPPFLAGS = \ | |||
253 | 253 | ||
254 | check_PROGRAMS = \ | 254 | check_PROGRAMS = \ |
255 | test_transport_testing_startstop \ | 255 | test_transport_testing_startstop \ |
256 | test_transport_testing_restart \ | ||
256 | test_transport_testing \ | 257 | test_transport_testing \ |
257 | test_transport_startonly \ | 258 | test_transport_startonly \ |
258 | test_transport_api_blacklisting \ | 259 | test_transport_api_blacklisting \ |
@@ -298,6 +299,7 @@ check_PROGRAMS = \ | |||
298 | if ENABLE_TEST_RUN | 299 | if ENABLE_TEST_RUN |
299 | TESTS = \ | 300 | TESTS = \ |
300 | test_transport_testing_startstop \ | 301 | test_transport_testing_startstop \ |
302 | test_transport_testing_restart \ | ||
301 | test_transport_testing \ | 303 | test_transport_testing \ |
302 | test_transport_startonly \ | 304 | test_transport_startonly \ |
303 | test_transport_api_blacklisting \ | 305 | test_transport_api_blacklisting \ |
@@ -349,6 +351,14 @@ test_transport_testing_startstop_LDADD = \ | |||
349 | $(top_builddir)/src/hello/libgnunethello.la \ | 351 | $(top_builddir)/src/hello/libgnunethello.la \ |
350 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 352 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
351 | 353 | ||
354 | test_transport_testing_restart_SOURCES = \ | ||
355 | test_transport_testing_restart.c | ||
356 | test_transport_testing_restart_LDADD = \ | ||
357 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
358 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
359 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
360 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
361 | |||
352 | test_transport_testing_SOURCES = \ | 362 | test_transport_testing_SOURCES = \ |
353 | test_transport_testing.c | 363 | test_transport_testing.c |
354 | test_transport_testing_LDADD = \ | 364 | test_transport_testing_LDADD = \ |
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c index 842d68651..7b04d9370 100644 --- a/src/transport/test_transport_testing.c +++ b/src/transport/test_transport_testing.c | |||
@@ -29,20 +29,9 @@ | |||
29 | #include "platform.h" | 29 | #include "platform.h" |
30 | #include "gnunet_common.h" | 30 | #include "gnunet_common.h" |
31 | #include "gnunet_hello_lib.h" | 31 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_getopt_lib.h" | ||
33 | #include "gnunet_os_lib.h" | ||
34 | #include "gnunet_program_lib.h" | ||
35 | #include "gnunet_scheduler_lib.h" | 32 | #include "gnunet_scheduler_lib.h" |
36 | #include "gnunet_transport_service.h" | 33 | #include "gnunet_transport_service.h" |
37 | #include "transport.h" | ||
38 | #include "transport-testing.h" | 34 | #include "transport-testing.h" |
39 | |||
40 | #define VERBOSE GNUNET_NO | ||
41 | |||
42 | #define VERBOSE_ARM GNUNET_NO | ||
43 | |||
44 | #define START_ARM GNUNET_YES | ||
45 | |||
46 | /** | 35 | /** |
47 | * How long until we give up on transmitting the message? | 36 | * How long until we give up on transmitting the message? |
48 | */ | 37 | */ |
@@ -81,6 +70,12 @@ end_badly () | |||
81 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 70 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
82 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 71 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
83 | 72 | ||
73 | if (NULL != cc) | ||
74 | { | ||
75 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | ||
76 | cc = NULL; | ||
77 | } | ||
78 | |||
84 | if (p1 != NULL) | 79 | if (p1 != NULL) |
85 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | 80 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
86 | if (p2 != NULL) | 81 | if (p2 != NULL) |
@@ -167,15 +162,11 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
167 | 1, ¬ify_receive, ¬ify_connect, | 162 | 1, ¬ify_receive, ¬ify_connect, |
168 | ¬ify_disconnect, &start_cb, p1); | 163 | ¬ify_disconnect, &start_cb, p1); |
169 | 164 | ||
170 | GNUNET_assert (p1->hostkeyfile != NULL); | ||
171 | |||
172 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | 165 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, |
173 | "test_transport_api_tcp_peer2.conf", | 166 | "test_transport_api_tcp_peer2.conf", |
174 | 2, ¬ify_receive, ¬ify_connect, | 167 | 2, ¬ify_receive, ¬ify_connect, |
175 | ¬ify_disconnect, &start_cb, p2); | 168 | ¬ify_disconnect, &start_cb, p2); |
176 | 169 | ||
177 | GNUNET_assert (p2->hostkeyfile != NULL); | ||
178 | |||
179 | if (p1 == NULL) | 170 | if (p1 == NULL) |
180 | { | 171 | { |
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -198,19 +189,12 @@ int | |||
198 | main (int argc, char *argv[]) | 189 | main (int argc, char *argv[]) |
199 | { | 190 | { |
200 | GNUNET_log_setup ("test_transport_testing", | 191 | GNUNET_log_setup ("test_transport_testing", |
201 | #if VERBOSE | ||
202 | "DEBUG", | ||
203 | #else | ||
204 | "WARNING", | 192 | "WARNING", |
205 | #endif | ||
206 | NULL); | 193 | NULL); |
207 | 194 | ||
208 | char *const argv_1[] = { "test_transport_testing", | 195 | char *const argv_1[] = { "test_transport_testing", |
209 | "-c", | 196 | "-c", |
210 | "test_transport_api_data.conf", | 197 | "test_transport_api_data.conf", |
211 | #if VERBOSE | ||
212 | "-L", "DEBUG", | ||
213 | #endif | ||
214 | NULL | 198 | NULL |
215 | }; | 199 | }; |
216 | 200 | ||
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c new file mode 100644 index 000000000..ed7b2f5c1 --- /dev/null +++ b/src/transport/test_transport_testing_restart.c | |||
@@ -0,0 +1,152 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file transport/test_transport_testing_restart.c | ||
22 | * @brief test case for transport testing library: | ||
23 | * start the peer, get the HELLO message, restart and stop the peer | ||
24 | * | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_common.h" | ||
28 | #include "gnunet_transport_service.h" | ||
29 | #include "transport-testing.h" | ||
30 | |||
31 | /** | ||
32 | * How long until we give up on transmitting the message? | ||
33 | */ | ||
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
35 | |||
36 | GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
37 | |||
38 | static struct PeerContext *p; | ||
39 | |||
40 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | ||
41 | |||
42 | static int ret = 0; | ||
43 | |||
44 | static void | ||
45 | end () | ||
46 | { | ||
47 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
48 | |||
49 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
50 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
51 | |||
52 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
53 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
54 | } | ||
55 | |||
56 | static void | ||
57 | end_badly () | ||
58 | { | ||
59 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | ||
61 | |||
62 | if (NULL != p) | ||
63 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
64 | |||
65 | if (NULL != tth) | ||
66 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
67 | |||
68 | ret = GNUNET_SYSERR; | ||
69 | } | ||
70 | |||
71 | static void | ||
72 | restart_cb (struct PeerContext *p, void *cls) | ||
73 | { | ||
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully restarted\n", | ||
75 | p->no, | ||
76 | GNUNET_i2s (&p->id)); | ||
77 | |||
78 | ret = 0; | ||
79 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
80 | } | ||
81 | |||
82 | |||
83 | static void | ||
84 | restart_task () | ||
85 | { | ||
86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') restarting, \n", | ||
87 | p->no, | ||
88 | GNUNET_i2s (&p->id)); | ||
89 | GNUNET_TRANSPORT_TESTING_restart_peer (tth, p, NULL, restart_cb, p); | ||
90 | } | ||
91 | |||
92 | static void | ||
93 | start_cb (struct PeerContext *p, void *cls) | ||
94 | { | ||
95 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", | ||
96 | p->no, | ||
97 | GNUNET_i2s (&p->id)); | ||
98 | |||
99 | GNUNET_SCHEDULER_add_now (&restart_task, NULL); | ||
100 | } | ||
101 | |||
102 | |||
103 | static void | ||
104 | run (void *cls, char *const *args, const char *cfgfile, | ||
105 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
106 | { | ||
107 | ret = 1; | ||
108 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
109 | GNUNET_assert (NULL != tth); | ||
110 | |||
111 | timeout_task = | ||
112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); | ||
113 | |||
114 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, cfgfile, 1, | ||
115 | NULL, /* receive cb */ | ||
116 | NULL, /* connect cb */ | ||
117 | NULL, /* disconnect cb */ | ||
118 | start_cb, /* startup cb */ | ||
119 | NULL); /* closure */ | ||
120 | if (NULL == p) | ||
121 | { | ||
122 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | ||
123 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
124 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
125 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
126 | } | ||
127 | } | ||
128 | |||
129 | int | ||
130 | main (int argc, char *argv[]) | ||
131 | { | ||
132 | GNUNET_log_setup ("test_transport_testing_restart", | ||
133 | "WARNING", | ||
134 | NULL); | ||
135 | |||
136 | char *const argv_1[] = { "test_transport_testing_restart", | ||
137 | "-c", | ||
138 | "test_transport_api_data.conf", | ||
139 | NULL | ||
140 | }; | ||
141 | |||
142 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
143 | GNUNET_GETOPT_OPTION_END | ||
144 | }; | ||
145 | |||
146 | GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, | ||
147 | "test_transport_testing_restart", "nohelp", options, &run, &ret); | ||
148 | |||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | /* end of test_transport_testing_restart.c */ | ||
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c index 2d035ca70..e1c370627 100644 --- a/src/transport/test_transport_testing_startstop.c +++ b/src/transport/test_transport_testing_startstop.c | |||
@@ -25,21 +25,9 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_common.h" | 27 | #include "gnunet_common.h" |
28 | #include "gnunet_hello_lib.h" | ||
29 | #include "gnunet_getopt_lib.h" | ||
30 | #include "gnunet_os_lib.h" | ||
31 | #include "gnunet_program_lib.h" | ||
32 | #include "gnunet_scheduler_lib.h" | ||
33 | #include "gnunet_transport_service.h" | 28 | #include "gnunet_transport_service.h" |
34 | #include "transport.h" | ||
35 | #include "transport-testing.h" | 29 | #include "transport-testing.h" |
36 | 30 | ||
37 | #define VERBOSE GNUNET_NO | ||
38 | |||
39 | #define VERBOSE_ARM GNUNET_NO | ||
40 | |||
41 | #define START_ARM GNUNET_YES | ||
42 | |||
43 | /** | 31 | /** |
44 | * How long until we give up on transmitting the message? | 32 | * How long until we give up on transmitting the message? |
45 | */ | 33 | */ |
@@ -49,8 +37,6 @@ GNUNET_SCHEDULER_TaskIdentifier timeout_task; | |||
49 | 37 | ||
50 | static struct PeerContext *p; | 38 | static struct PeerContext *p; |
51 | 39 | ||
52 | //static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
53 | |||
54 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | 40 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
55 | 41 | ||
56 | static int ret = 0; | 42 | static int ret = 0; |
@@ -63,8 +49,7 @@ end () | |||
63 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | 49 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) |
64 | GNUNET_SCHEDULER_cancel (timeout_task); | 50 | GNUNET_SCHEDULER_cancel (timeout_task); |
65 | 51 | ||
66 | if (NULL != p) | 52 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); |
67 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
68 | GNUNET_TRANSPORT_TESTING_done (tth); | 53 | GNUNET_TRANSPORT_TESTING_done (tth); |
69 | } | 54 | } |
70 | 55 | ||
@@ -74,109 +59,64 @@ end_badly () | |||
74 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | 59 | timeout_task = GNUNET_SCHEDULER_NO_TASK; |
75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); | 60 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
76 | 61 | ||
77 | if (p != NULL) | 62 | if (NULL != p) |
78 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | 63 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); |
79 | 64 | ||
80 | GNUNET_TRANSPORT_TESTING_done (tth); | 65 | if (NULL != tth) |
66 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
81 | 67 | ||
82 | ret = GNUNET_SYSERR; | 68 | ret = GNUNET_SYSERR; |
83 | } | 69 | } |
84 | 70 | ||
85 | #if 0 | ||
86 | static void | ||
87 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | ||
88 | { | ||
89 | char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
90 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
92 | "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps, | ||
93 | p2->no, GNUNET_i2s (&p2->id)); | ||
94 | GNUNET_free (ps); | ||
95 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
101 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", | ||
104 | GNUNET_i2s (peer)); | ||
105 | connected++; | ||
106 | } | ||
107 | 71 | ||
108 | static void | 72 | static void |
109 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
110 | { | ||
111 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", | ||
112 | GNUNET_i2s (peer)); | ||
113 | } | ||
114 | |||
115 | static void | ||
116 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
117 | const struct GNUNET_MessageHeader *message, | ||
118 | const struct GNUNET_ATS_Information *ats, uint32_t ats_count) | ||
119 | { | ||
120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); | ||
121 | } | ||
122 | |||
123 | |||
124 | |||
125 | void | ||
126 | start_cb (struct PeerContext *p, void *cls) | 73 | start_cb (struct PeerContext *p, void *cls) |
127 | { | 74 | { |
128 | static int started; | 75 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') successfully started\n", |
129 | 76 | p->no, | |
130 | started++; | ||
131 | |||
132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
133 | GNUNET_i2s (&p->id)); | 77 | GNUNET_i2s (&p->id)); |
134 | 78 | ||
135 | if (started != 2) | 79 | ret = 0; |
136 | return; | 80 | GNUNET_SCHEDULER_add_now (&end, NULL); |
137 | |||
138 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
139 | |||
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
141 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
142 | p->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
143 | GNUNET_free (sender_c); | ||
144 | |||
145 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p, p2, &testing_connect_cb, | ||
146 | NULL); | ||
147 | } | 81 | } |
148 | #endif | 82 | |
149 | 83 | ||
150 | static void | 84 | static void |
151 | run (void *cls, char *const *args, const char *cfgfile, | 85 | run (void *cls, char *const *args, const char *cfgfile, |
152 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 86 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
153 | { | 87 | { |
88 | ret = 1; | ||
154 | tth = GNUNET_TRANSPORT_TESTING_init (); | 89 | tth = GNUNET_TRANSPORT_TESTING_init (); |
155 | GNUNET_assert (NULL != tth); | 90 | GNUNET_assert (NULL != tth); |
156 | 91 | ||
157 | timeout_task = | 92 | timeout_task = |
158 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); | 93 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); |
159 | 94 | ||
160 | GNUNET_SCHEDULER_add_now (&end, NULL); | 95 | p = GNUNET_TRANSPORT_TESTING_start_peer(tth, cfgfile, 1, |
96 | NULL, /* receive cb */ | ||
97 | NULL, /* connect cb */ | ||
98 | NULL, /* disconnect cb */ | ||
99 | start_cb, /* startup cb */ | ||
100 | NULL); /* closure */ | ||
101 | if (NULL == p) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start peer\n"); | ||
104 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
105 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
106 | timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
107 | } | ||
161 | } | 108 | } |
162 | 109 | ||
163 | int | 110 | int |
164 | main (int argc, char *argv[]) | 111 | main (int argc, char *argv[]) |
165 | { | 112 | { |
166 | GNUNET_log_setup ("test_transport_testing_startstop", | 113 | GNUNET_log_setup ("test_transport_testing_startstop", |
167 | #if VERBOSE | ||
168 | "DEBUG", | ||
169 | #else | ||
170 | "WARNING", | 114 | "WARNING", |
171 | #endif | ||
172 | NULL); | 115 | NULL); |
173 | 116 | ||
174 | char *const argv_1[] = { "test_transport_testing", | 117 | char *const argv_1[] = { "test_transport_testing", |
175 | "-c", | 118 | "-c", |
176 | "test_transport_api_data.conf", | 119 | "test_transport_api_data.conf", |
177 | #if VERBOSE | ||
178 | "-L", "DEBUG", | ||
179 | #endif | ||
180 | NULL | 120 | NULL |
181 | }; | 121 | }; |
182 | 122 | ||
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c index b3c3a9399..87ce70423 100644 --- a/src/transport/transport-testing.c +++ b/src/transport/transport-testing.c | |||
@@ -27,31 +27,6 @@ | |||
27 | 27 | ||
28 | #include "transport-testing.h" | 28 | #include "transport-testing.h" |
29 | 29 | ||
30 | #define HOSTKEYFILESIZE 914 | ||
31 | |||
32 | static const char * | ||
33 | get_host_key (struct GNUNET_TRANSPORT_TESTING_handle *tth) | ||
34 | { | ||
35 | if (tth->hostkey_data == NULL) | ||
36 | { | ||
37 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
38 | "No precomputed hostkeys available\n"); | ||
39 | return NULL; | ||
40 | } | ||
41 | if (tth->hostkeys_total > tth->hostkeys_last) | ||
42 | { | ||
43 | tth->hostkeys_last++; | ||
44 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
45 | "Used hostkey %u of %u available hostkeys\n", | ||
46 | tth->hostkeys_last, tth->hostkeys_total); | ||
47 | return &tth->hostkey_data[(tth->hostkeys_last - 1) * HOSTKEYFILESIZE]; | ||
48 | } | ||
49 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
50 | "No hostkey available (%u of %u already used)\n", | ||
51 | tth->hostkeys_last, tth->hostkeys_total); | ||
52 | return NULL; | ||
53 | } | ||
54 | |||
55 | 30 | ||
56 | static struct PeerContext * | 31 | static struct PeerContext * |
57 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, | 32 | find_peer_context (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
@@ -190,20 +165,21 @@ static void | |||
190 | get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) | 165 | get_hello (void *cb_cls, const struct GNUNET_MessageHeader *message) |
191 | { | 166 | { |
192 | struct PeerContext *p = cb_cls; | 167 | struct PeerContext *p = cb_cls; |
168 | struct GNUNET_PeerIdentity hello_id; | ||
193 | 169 | ||
194 | GNUNET_assert (message != NULL); | 170 | GNUNET_assert (message != NULL); |
195 | GNUNET_assert (GNUNET_OK == | 171 | GNUNET_assert (GNUNET_OK == |
196 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 172 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
197 | message, &p->id)); | 173 | message, &hello_id)); |
174 | GNUNET_assert (0 == memcmp (&hello_id, &p->id, sizeof (hello_id))); | ||
198 | GNUNET_free_non_null (p->hello); | 175 | GNUNET_free_non_null (p->hello); |
199 | p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message); | 176 | p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message); |
200 | 177 | ||
201 | if (p->start_cb != NULL) | 178 | if (NULL != p->start_cb) |
202 | { | 179 | { |
203 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 180 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
204 | "Peer %u (`%s') successfully started\n", p->no, | 181 | "Peer %u (`%s') successfully started\n", p->no, |
205 | GNUNET_i2s (&p->id)); | 182 | GNUNET_i2s (&p->id)); |
206 | |||
207 | p->start_cb (p, p->cb_cls); | 183 | p->start_cb (p, p->cb_cls); |
208 | p->start_cb = NULL; | 184 | p->start_cb = NULL; |
209 | } | 185 | } |
@@ -247,7 +223,7 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
247 | * Start a peer with the given configuration | 223 | * Start a peer with the given configuration |
248 | * @param tth the testing handle | 224 | * @param tth the testing handle |
249 | * @param cfgname configuration file | 225 | * @param cfgname configuration file |
250 | * @param peer_id the peer_id | 226 | * @param peer_id a unique number to identify the peer |
251 | * @param rec receive callback | 227 | * @param rec receive callback |
252 | * @param nc connect callback | 228 | * @param nc connect callback |
253 | * @param nd disconnect callback | 229 | * @param nd disconnect callback |
@@ -256,18 +232,20 @@ try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
256 | * @return the peer context | 232 | * @return the peer context |
257 | */ | 233 | */ |
258 | struct PeerContext * | 234 | struct PeerContext * |
259 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | 235 | GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, |
260 | *tth, const char *cfgname, int peer_id, | 236 | const char *cfgname, int peer_id, |
261 | GNUNET_TRANSPORT_ReceiveCallback rec, | 237 | GNUNET_TRANSPORT_ReceiveCallback rec, |
262 | GNUNET_TRANSPORT_NotifyConnect nc, | 238 | GNUNET_TRANSPORT_NotifyConnect nc, |
263 | GNUNET_TRANSPORT_NotifyDisconnect nd, | 239 | GNUNET_TRANSPORT_NotifyDisconnect nd, |
264 | GNUNET_TRANSPORT_TESTING_start_cb start_cb, | 240 | GNUNET_TRANSPORT_TESTING_start_cb start_cb, |
265 | void *cb_cls) | 241 | void *cb_cls) |
266 | { | 242 | { |
267 | const char *hostkey = NULL; | 243 | char *emsg = NULL; |
268 | struct GNUNET_DISK_FileHandle *fn; | 244 | struct GNUNET_PeerIdentity *dummy; |
245 | |||
246 | GNUNET_assert (NULL != tth); | ||
247 | GNUNET_assert (NULL != tth->tl_system); | ||
269 | 248 | ||
270 | GNUNET_assert (tth != NULL); | ||
271 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | 249 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) |
272 | { | 250 | { |
273 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | 251 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
@@ -276,47 +254,60 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
276 | } | 254 | } |
277 | 255 | ||
278 | struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext)); | 256 | struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext)); |
257 | GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); | ||
279 | 258 | ||
259 | /* Create configuration and call testing lib to modify it */ | ||
280 | p->cfg = GNUNET_CONFIGURATION_create (); | 260 | p->cfg = GNUNET_CONFIGURATION_create (); |
281 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | 261 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); |
282 | 262 | ||
283 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | 263 | if (GNUNET_SYSERR == GNUNET_TESTING_configuration_create (tth->tl_system, p->cfg)) |
284 | GNUNET_assert (GNUNET_OK == | 264 | { |
285 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", | 265 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
286 | "SERVICEHOME", | 266 | "Testing library failed to create unique configuration based on `%s'\n", |
287 | &p->servicehome)); | 267 | cfgname); |
268 | GNUNET_free (p); | ||
269 | return NULL; | ||
270 | } | ||
288 | 271 | ||
289 | if (NULL != p->servicehome) | 272 | p->no = peer_id; |
290 | GNUNET_DISK_directory_remove (p->servicehome); | 273 | /* Configure peer with configuration */ |
274 | p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, p->cfg, p->no, NULL, &emsg); | ||
275 | if (NULL == p->peer) | ||
276 | { | ||
277 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
278 | "Testing library failed to create unique configuration based on `%s': `%s'\n", | ||
279 | cfgname, emsg); | ||
280 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
281 | return NULL; | ||
282 | } | ||
291 | 283 | ||
292 | hostkey = get_host_key (tth); | 284 | if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) |
293 | if (hostkey != NULL) | ||
294 | { | 285 | { |
286 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
287 | "Testing library failed to create unique configuration based on `%s'\n", | ||
288 | cfgname); | ||
289 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
290 | return NULL; | ||
291 | } | ||
295 | 292 | ||
296 | GNUNET_asprintf (&p->hostkeyfile, "%s/.hostkey", p->servicehome); | 293 | memset(&dummy, '\0', sizeof (dummy)); |
297 | GNUNET_assert (GNUNET_OK == | 294 | GNUNET_TESTING_peer_get_identity (p->peer, &p->id); |
298 | GNUNET_DISK_directory_create_for_file (p->hostkeyfile)); | 295 | if (0 == memcmp (&dummy, &p->id, sizeof (dummy))) |
299 | fn = GNUNET_DISK_file_open (p->hostkeyfile, | 296 | { |
300 | GNUNET_DISK_OPEN_READWRITE | | 297 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
301 | GNUNET_DISK_OPEN_CREATE, | 298 | "Testing library failed to obtain peer identity for peer %u\n", |
302 | GNUNET_DISK_PERM_USER_READ | | 299 | p->no); |
303 | GNUNET_DISK_PERM_USER_WRITE); | 300 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); |
304 | GNUNET_assert (fn != NULL); | 301 | return NULL; |
305 | GNUNET_assert (HOSTKEYFILESIZE == | 302 | } |
306 | GNUNET_DISK_file_write (fn, hostkey, HOSTKEYFILESIZE)); | 303 | else |
307 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fn)); | 304 | { |
308 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 305 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
309 | "Wrote hostkey to file: `%s' \n", p->hostkeyfile); | 306 | "Peer %u configured with identity `%s'\n", |
307 | p->no, | ||
308 | GNUNET_i2s (&p->id)); | ||
310 | } | 309 | } |
311 | 310 | ||
312 | p->arm_proc = | ||
313 | GNUNET_OS_start_process (GNUNET_YES, | ||
314 | NULL, NULL, "gnunet-service-arm", | ||
315 | "gnunet-service-arm", "-c", cfgname, | ||
316 | "-L", "ERROR", | ||
317 | NULL); | ||
318 | |||
319 | p->no = peer_id; | ||
320 | p->tth = tth; | 311 | p->tth = tth; |
321 | p->nc = nc; | 312 | p->nc = nc; |
322 | p->nd = nd; | 313 | p->nd = nd; |
@@ -327,15 +318,21 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
327 | else | 318 | else |
328 | p->cb_cls = p; | 319 | p->cb_cls = p; |
329 | 320 | ||
330 | p->th = | 321 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, |
331 | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, | 322 | ¬ify_receive, |
332 | ¬ify_connect, ¬ify_disconnect); | 323 | ¬ify_connect, ¬ify_disconnect); |
333 | GNUNET_assert (p->th != NULL); | 324 | if (NULL == p->th) |
325 | { | ||
326 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
327 | "Failed to connect to transport service for peer `%s': `%s'\n", | ||
328 | cfgname, emsg); | ||
329 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
330 | return NULL; | ||
331 | } | ||
334 | 332 | ||
335 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); | 333 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); |
336 | GNUNET_assert (p->ghh != NULL); | 334 | GNUNET_assert (p->ghh != NULL); |
337 | 335 | ||
338 | GNUNET_CONTAINER_DLL_insert (tth->p_head, tth->p_tail, p); | ||
339 | return p; | 336 | return p; |
340 | } | 337 | } |
341 | 338 | ||
@@ -355,93 +352,55 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_handle | |||
355 | GNUNET_TRANSPORT_TESTING_start_cb | 352 | GNUNET_TRANSPORT_TESTING_start_cb |
356 | restart_cb, void *cb_cls) | 353 | restart_cb, void *cb_cls) |
357 | { | 354 | { |
358 | struct GNUNET_DISK_FileHandle *fn; | ||
359 | |||
360 | GNUNET_assert (tth != NULL); | 355 | GNUNET_assert (tth != NULL); |
361 | GNUNET_assert (p != NULL); | 356 | GNUNET_assert (p != NULL); |
362 | GNUNET_assert (p->hostkeyfile != NULL); | 357 | GNUNET_assert (NULL != p->peer); |
363 | GNUNET_assert (p->servicehome != NULL); | 358 | |
359 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
360 | "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); | ||
364 | 361 | ||
365 | /* shutdown */ | 362 | /* shutdown */ |
366 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | 363 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", |
367 | "Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); | 364 | "Stopping peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); |
368 | if (p->ghh != NULL) | 365 | if (NULL != p->ghh) |
369 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); | 366 | GNUNET_TRANSPORT_get_hello_cancel (p->ghh); |
370 | p->ghh = NULL; | 367 | p->ghh = NULL; |
371 | 368 | ||
372 | if (p->th != NULL) | 369 | if (NULL != p->th) |
373 | GNUNET_TRANSPORT_disconnect (p->th); | 370 | GNUNET_TRANSPORT_disconnect (p->th); |
374 | 371 | ||
375 | if (NULL != p->arm_proc) | 372 | if (GNUNET_SYSERR == GNUNET_TESTING_peer_stop(p->peer)) |
376 | { | 373 | { |
377 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | 374 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
378 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 375 | "Failed to stop peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); |
379 | GNUNET_OS_process_wait (p->arm_proc); | 376 | return GNUNET_SYSERR; |
380 | GNUNET_OS_process_destroy (p->arm_proc); | ||
381 | p->arm_proc = NULL; | ||
382 | } | 377 | } |
383 | if (p->hello != NULL) | ||
384 | GNUNET_free (p->hello); | ||
385 | p->hello = NULL; | ||
386 | |||
387 | if (p->cfg != NULL) | ||
388 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
389 | p->cfg = NULL; | ||
390 | |||
391 | 378 | ||
392 | /* start */ | 379 | sleep (5); |
393 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
394 | "Restarting peer %u (`%s')\n", p->no, GNUNET_i2s (&p->id)); | ||
395 | sleep (5); // YUCK! | ||
396 | 380 | ||
397 | if (GNUNET_DISK_file_test (cfgname) == GNUNET_NO) | 381 | /* restart */ |
382 | if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer)) | ||
398 | { | 383 | { |
399 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | 384 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", |
400 | "File not found: `%s' \n", cfgname); | 385 | "Failed to restart peer %u (`%s')\n", |
401 | goto fail; | 386 | p->no, GNUNET_i2s (&p->id)); |
387 | return GNUNET_SYSERR; | ||
402 | } | 388 | } |
403 | 389 | ||
404 | p->cfg = GNUNET_CONFIGURATION_create (); | ||
405 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
406 | |||
407 | if (!GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | ||
408 | goto fail; | ||
409 | |||
410 | fn = GNUNET_DISK_file_open (p->hostkeyfile, | ||
411 | GNUNET_DISK_OPEN_READWRITE | | ||
412 | GNUNET_DISK_OPEN_CREATE, | ||
413 | GNUNET_DISK_PERM_USER_READ | | ||
414 | GNUNET_DISK_PERM_USER_WRITE); | ||
415 | if (fn == NULL) | ||
416 | goto fail; | ||
417 | if (GNUNET_OK != GNUNET_DISK_file_close (fn)) | ||
418 | goto fail; | ||
419 | |||
420 | p->arm_proc = | ||
421 | GNUNET_OS_start_process (GNUNET_YES, | ||
422 | NULL, NULL, "gnunet-service-arm", | ||
423 | "gnunet-service-arm", "-c", cfgname, | ||
424 | "-L", "ERROR", | ||
425 | NULL); | ||
426 | |||
427 | p->th = | ||
428 | GNUNET_TRANSPORT_connect (p->cfg, NULL, p, ¬ify_receive, | ||
429 | ¬ify_connect, ¬ify_disconnect); | ||
430 | GNUNET_assert (p->th != NULL); | 390 | GNUNET_assert (p->th != NULL); |
431 | 391 | GNUNET_assert (p->start_cb == NULL); | |
432 | p->start_cb = restart_cb; | 392 | p->start_cb = restart_cb; |
433 | p->cb_cls = cb_cls; | 393 | p->cb_cls = cb_cls; |
434 | 394 | ||
395 | p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, | ||
396 | ¬ify_receive, | ||
397 | ¬ify_connect, | ||
398 | ¬ify_disconnect); | ||
399 | GNUNET_assert (NULL != p->th); | ||
400 | |||
435 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); | 401 | p->ghh = GNUNET_TRANSPORT_get_hello (p->th, &get_hello, p); |
436 | GNUNET_assert (p->ghh != NULL); | 402 | GNUNET_assert (p->ghh != NULL); |
437 | return GNUNET_OK; | 403 | return GNUNET_OK; |
438 | |||
439 | fail: | ||
440 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
441 | "Restarting peer %u (`%s') failed, removing peer\n", p->no, | ||
442 | GNUNET_i2s (&p->id)); | ||
443 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p); | ||
444 | return GNUNET_SYSERR; | ||
445 | } | 404 | } |
446 | 405 | ||
447 | 406 | ||
@@ -461,25 +420,23 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_handle *tth, | |||
461 | p->ghh = NULL; | 420 | p->ghh = NULL; |
462 | } | 421 | } |
463 | if (p->th != NULL) | 422 | if (p->th != NULL) |
464 | GNUNET_TRANSPORT_disconnect (p->th); | ||
465 | if (NULL != p->arm_proc) | ||
466 | { | ||
467 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
468 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
469 | GNUNET_OS_process_wait (p->arm_proc); | ||
470 | GNUNET_OS_process_destroy (p->arm_proc); | ||
471 | p->arm_proc = NULL; | ||
472 | } | ||
473 | if (p->hostkeyfile != NULL) | ||
474 | { | 423 | { |
475 | GNUNET_DISK_directory_remove (p->hostkeyfile); | 424 | GNUNET_TRANSPORT_disconnect (p->th); |
476 | GNUNET_free (p->hostkeyfile); | 425 | p->th = NULL; |
477 | } | 426 | } |
478 | if (p->servicehome != NULL) | 427 | |
428 | if (p->peer != NULL) | ||
479 | { | 429 | { |
480 | GNUNET_DISK_directory_remove (p->servicehome); | 430 | if (GNUNET_OK != GNUNET_TESTING_peer_stop (p->peer)) |
481 | GNUNET_free (p->servicehome); | 431 | { |
432 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
433 | "Testing lib failed to stop peer %u (`%s') \n", p->no, | ||
434 | GNUNET_i2s (&p->id)); | ||
435 | } | ||
436 | GNUNET_TESTING_peer_destroy (p->peer); | ||
437 | p->peer = NULL; | ||
482 | } | 438 | } |
439 | |||
483 | if (p->hello != NULL) | 440 | if (p->hello != NULL) |
484 | { | 441 | { |
485 | GNUNET_free (p->hello); | 442 | GNUNET_free (p->hello); |
@@ -606,8 +563,6 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_handle *tth) | |||
606 | p = t; | 563 | p = t; |
607 | } | 564 | } |
608 | 565 | ||
609 | GNUNET_free_non_null (tth->hostkey_data); | ||
610 | |||
611 | GNUNET_TESTING_system_destroy (tth->tl_system, GNUNET_YES); | 566 | GNUNET_TESTING_system_destroy (tth->tl_system, GNUNET_YES); |
612 | 567 | ||
613 | GNUNET_free (tth); | 568 | GNUNET_free (tth); |
@@ -623,16 +578,12 @@ struct GNUNET_TRANSPORT_TESTING_handle * | |||
623 | GNUNET_TRANSPORT_TESTING_init () | 578 | GNUNET_TRANSPORT_TESTING_init () |
624 | { | 579 | { |
625 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | 580 | struct GNUNET_TRANSPORT_TESTING_handle *tth; |
626 | struct GNUNET_DISK_FileHandle *fd; | ||
627 | uint64_t fs; | ||
628 | uint64_t total_hostkeys; | ||
629 | 581 | ||
630 | /* prepare hostkeys */ | 582 | /* prepare hostkeys */ |
631 | tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); | 583 | tth = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TESTING_handle)); |
632 | 584 | ||
633 | /* Init testing the testing lib */ | 585 | /* Init testing the testing lib */ |
634 | tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", | 586 | tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", NULL); |
635 | "127.0.0.1"); | ||
636 | if (NULL == tth->tl_system) | 587 | if (NULL == tth->tl_system) |
637 | { | 588 | { |
638 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n")); | 589 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n")); |
@@ -640,45 +591,6 @@ GNUNET_TRANSPORT_TESTING_init () | |||
640 | return NULL; | 591 | return NULL; |
641 | } | 592 | } |
642 | 593 | ||
643 | tth->hostkey_data = NULL; | ||
644 | const char *hostkeys_file = "../../contrib/testing_hostkeys.dat"; | ||
645 | |||
646 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | ||
647 | { | ||
648 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Could not read hostkeys file!\n")); | ||
649 | } | ||
650 | else | ||
651 | { | ||
652 | /* Check hostkey file size, read entire thing into memory */ | ||
653 | fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | ||
654 | GNUNET_DISK_PERM_NONE); | ||
655 | if (NULL == fd) | ||
656 | { | ||
657 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_file); | ||
658 | GNUNET_free (tth); | ||
659 | return NULL; | ||
660 | } | ||
661 | |||
662 | if (GNUNET_OK != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES, GNUNET_YES)) | ||
663 | fs = 0; | ||
664 | |||
665 | if (0 != (fs % HOSTKEYFILESIZE)) | ||
666 | { | ||
667 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "transport-testing", | ||
668 | "File size %llu seems incorrect for hostkeys...\n", fs); | ||
669 | } | ||
670 | else | ||
671 | { | ||
672 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
673 | tth->hostkey_data = GNUNET_malloc_large (fs); | ||
674 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, tth->hostkey_data, fs)); | ||
675 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing", | ||
676 | "Read %llu hostkeys from file\n", total_hostkeys); | ||
677 | tth->hostkeys_total = total_hostkeys; | ||
678 | } | ||
679 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); | ||
680 | } | ||
681 | |||
682 | return tth; | 594 | return tth; |
683 | } | 595 | } |
684 | 596 | ||
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h index 3129bc0a0..0b1f24591 100644 --- a/src/transport/transport-testing.h +++ b/src/transport/transport-testing.h | |||
@@ -27,9 +27,7 @@ | |||
27 | 27 | ||
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_common.h" | 29 | #include "gnunet_common.h" |
30 | #include "gnunet_getopt_lib.h" | ||
31 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
32 | #include "gnunet_os_lib.h" | ||
33 | #include "gnunet_program_lib.h" | 31 | #include "gnunet_program_lib.h" |
34 | #include "gnunet_container_lib.h" | 32 | #include "gnunet_container_lib.h" |
35 | #include "gnunet_transport_service.h" | 33 | #include "gnunet_transport_service.h" |
@@ -146,16 +144,6 @@ struct PeerContext | |||
146 | void *cb_cls; | 144 | void *cb_cls; |
147 | 145 | ||
148 | /** | 146 | /** |
149 | * Peer's service home directory | ||
150 | */ | ||
151 | char *servicehome; | ||
152 | |||
153 | /** | ||
154 | * Hostkey file | ||
155 | */ | ||
156 | char *hostkeyfile; | ||
157 | |||
158 | /** | ||
159 | * An unique number to identify the peer | 147 | * An unique number to identify the peer |
160 | */ | 148 | */ |
161 | unsigned int no; | 149 | unsigned int no; |
@@ -179,19 +167,29 @@ struct ConnectingContext | |||
179 | 167 | ||
180 | struct GNUNET_TRANSPORT_TESTING_handle | 168 | struct GNUNET_TRANSPORT_TESTING_handle |
181 | { | 169 | { |
182 | struct ConnectingContext *cc_head; | ||
183 | struct ConnectingContext *cc_tail; | ||
184 | |||
185 | /** | 170 | /** |
186 | * Testing library system handle | 171 | * Testing library system handle |
187 | */ | 172 | */ |
188 | struct GNUNET_TESTING_System *tl_system; | 173 | struct GNUNET_TESTING_System *tl_system; |
189 | 174 | ||
190 | char *hostkey_data; | 175 | /** |
191 | int hostkeys_total; | 176 | * head DLL of connect contexts |
192 | int hostkeys_last; | 177 | */ |
178 | struct ConnectingContext *cc_head; | ||
179 | |||
180 | /** | ||
181 | * head DLL of connect contexts | ||
182 | */ | ||
183 | struct ConnectingContext *cc_tail; | ||
193 | 184 | ||
185 | /** | ||
186 | * head DLL of peers | ||
187 | */ | ||
194 | struct PeerContext *p_head; | 188 | struct PeerContext *p_head; |
189 | |||
190 | /** | ||
191 | * tail DLL of peers | ||
192 | */ | ||
195 | struct PeerContext *p_tail; | 193 | struct PeerContext *p_tail; |
196 | }; | 194 | }; |
197 | 195 | ||