diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-27 21:26:37 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-10-27 21:26:37 +0000 |
commit | af6a96ea9ba1c400309d3b1b12d6b49e2a3e8a33 (patch) | |
tree | 8c95a6435b0d5b4ffbfa1f24f2a92a6dcccbb955 /src/transport/test_transport_api_disconnect.c | |
parent | 601fc27e0a8667555f52fa56523b21bd5753078a (diff) | |
download | gnunet-af6a96ea9ba1c400309d3b1b12d6b49e2a3e8a33.tar.gz gnunet-af6a96ea9ba1c400309d3b1b12d6b49e2a3e8a33.zip |
Diffstat (limited to 'src/transport/test_transport_api_disconnect.c')
-rw-r--r-- | src/transport/test_transport_api_disconnect.c | 467 |
1 files changed, 230 insertions, 237 deletions
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c index 850244810..3b294684d 100644 --- a/src/transport/test_transport_api_disconnect.c +++ b/src/transport/test_transport_api_disconnect.c | |||
@@ -21,10 +21,7 @@ | |||
21 | * @file transport/test_transport_api_disconnect.c | 21 | * @file transport/test_transport_api_disconnect.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case serves as a base for tcp, udp, and udp-nat | 24 | * This test case serves tests disconnect notification if peer shutsdown |
25 | * transport test cases. Based on the executable being run | ||
26 | * the correct test case will be performed. Conservation of | ||
27 | * C code apparently. | ||
28 | */ | 25 | */ |
29 | #include "platform.h" | 26 | #include "platform.h" |
30 | #include "gnunet_common.h" | 27 | #include "gnunet_common.h" |
@@ -37,8 +34,7 @@ | |||
37 | #include "transport.h" | 34 | #include "transport.h" |
38 | #include "transport-testing.h" | 35 | #include "transport-testing.h" |
39 | 36 | ||
40 | #define VERBOSE GNUNET_EXTRA_LOGGING | 37 | #define VERBOSE GNUNET_YES |
41 | |||
42 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING | 38 | #define VERBOSE_ARM GNUNET_EXTRA_LOGGING |
43 | 39 | ||
44 | #define START_ARM GNUNET_YES | 40 | #define START_ARM GNUNET_YES |
@@ -46,7 +42,7 @@ | |||
46 | /** | 42 | /** |
47 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
48 | */ | 44 | */ |
49 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) |
50 | 46 | ||
51 | /** | 47 | /** |
52 | * How long until we give up on transmitting the message? | 48 | * How long until we give up on transmitting the message? |
@@ -55,134 +51,92 @@ | |||
55 | 51 | ||
56 | #define MTYPE 12345 | 52 | #define MTYPE 12345 |
57 | 53 | ||
58 | #define ITERATIONS 50 | 54 | static char *test_source; |
59 | 55 | ||
60 | static struct PeerContext p1; | 56 | static char *test_plugin; |
61 | 57 | ||
62 | static struct PeerContext p2; | 58 | static char *test_name; |
63 | 59 | ||
64 | static int ok; | 60 | static int ok; |
65 | 61 | ||
66 | static int peers_connected = 0; | 62 | static GNUNET_SCHEDULER_TaskIdentifier die_task; |
63 | |||
64 | static GNUNET_SCHEDULER_TaskIdentifier send_task; | ||
67 | 65 | ||
68 | static int counter; | 66 | struct PeerContext *p1; |
69 | static int msgs_recv; | ||
70 | 67 | ||
71 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | 68 | struct PeerContext *p2; |
72 | 69 | ||
73 | static GNUNET_SCHEDULER_TaskIdentifier tct; | 70 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; |
74 | 71 | ||
75 | struct GNUNET_TRANSPORT_TransmitHandle *th; | 72 | struct GNUNET_TRANSPORT_TransmitHandle *th; |
76 | 73 | ||
74 | struct GNUNET_TRANSPORT_TESTING_handle * tth; | ||
75 | |||
76 | int shutdown_; | ||
77 | |||
78 | char *cfg_file_p1; | ||
79 | |||
80 | char *cfg_file_p2; | ||
81 | |||
77 | #if VERBOSE | 82 | #if VERBOSE |
78 | #define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 83 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
79 | #else | 84 | #else |
80 | #define OKPP do { ok++; } while (0) | 85 | #define OKPP do { ok++; } while (0) |
81 | #endif | 86 | #endif |
82 | 87 | ||
83 | 88 | ||
84 | static void | 89 | static void |
85 | peers_connect (); | ||
86 | |||
87 | static void | ||
88 | end () | 90 | end () |
89 | { | 91 | { |
90 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 92 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stopping peers\n"); |
93 | |||
94 | if (send_task != GNUNET_SCHEDULER_NO_TASK) | ||
95 | GNUNET_SCHEDULER_cancel (send_task); | ||
96 | |||
97 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
91 | GNUNET_SCHEDULER_cancel (die_task); | 98 | GNUNET_SCHEDULER_cancel (die_task); |
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | 99 | |
93 | if (th != NULL) | 100 | if (th != NULL) |
94 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 101 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
95 | th = NULL; | 102 | th = NULL; |
96 | 103 | ||
97 | if (p1.th != NULL) | 104 | if (p1 != NULL) |
98 | GNUNET_TRANSPORT_disconnect (p1.th); | 105 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
106 | if (p2 != NULL) | ||
107 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
99 | 108 | ||
100 | if (p2.th != NULL) | ||
101 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
102 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
104 | "Transports disconnected, returning success!\n"); | ||
105 | ok = 0; | ||
106 | } | ||
107 | 109 | ||
108 | static void | ||
109 | stop_arm (struct PeerContext *p) | ||
110 | { | ||
111 | #if START_ARM | ||
112 | if (NULL != p->arm_proc) | ||
113 | { | ||
114 | if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) | ||
115 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
116 | GNUNET_OS_process_wait (p->arm_proc); | ||
117 | GNUNET_OS_process_close (p->arm_proc); | ||
118 | p->arm_proc = NULL; | ||
119 | } | ||
120 | #endif | ||
121 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
122 | } | 110 | } |
123 | 111 | ||
124 | |||
125 | |||
126 | |||
127 | static void | 112 | static void |
128 | exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message) | 113 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
129 | { | 114 | { |
130 | struct PeerContext *me = cls; | 115 | die_task = GNUNET_SCHEDULER_NO_TASK; |
131 | 116 | ||
132 | GNUNET_assert (message != NULL); | 117 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); |
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
134 | "Exchanging HELLO of size %d with peer (%s)!\n", | ||
135 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) | ||
136 | message), GNUNET_i2s (&me->id)); | ||
137 | GNUNET_assert (GNUNET_OK == | ||
138 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | ||
139 | message, &me->id)); | ||
140 | GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL); | ||
141 | } | ||
142 | 118 | ||
143 | 119 | ||
144 | static void | 120 | if (send_task != GNUNET_SCHEDULER_NO_TASK) |
145 | exchange_hello (void *cls, const struct GNUNET_MessageHeader *message) | 121 | GNUNET_SCHEDULER_cancel (send_task); |
146 | { | ||
147 | struct PeerContext *me = cls; | ||
148 | 122 | ||
149 | GNUNET_assert (message != NULL); | 123 | if (cc != NULL) |
150 | GNUNET_assert (GNUNET_OK == | 124 | { |
151 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 125 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); |
152 | message, &me->id)); | 126 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); |
153 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 127 | cc = NULL; |
154 | "Exchanging HELLO of size %d from peer %s!\n", | 128 | } |
155 | (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *) | ||
156 | message), GNUNET_i2s (&me->id)); | ||
157 | GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); | ||
158 | } | ||
159 | |||
160 | |||
161 | static void | ||
162 | end_badly () | ||
163 | { | ||
164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); | ||
165 | GNUNET_break (0); | ||
166 | 129 | ||
167 | if (th != NULL) | 130 | if (th != NULL) |
168 | { | ||
169 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 131 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
170 | th = NULL; | 132 | th = NULL; |
171 | } | ||
172 | else | ||
173 | { | ||
174 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | ||
175 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | ||
176 | } | ||
177 | 133 | ||
178 | GNUNET_TRANSPORT_disconnect (p1.th); | 134 | if (p1 != NULL) |
179 | GNUNET_TRANSPORT_disconnect (p2.th); | 135 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); |
180 | if (GNUNET_SCHEDULER_NO_TASK != tct) | 136 | if (p2 != NULL) |
181 | { | 137 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); |
182 | GNUNET_SCHEDULER_cancel (tct); | 138 | |
183 | tct = GNUNET_SCHEDULER_NO_TASK; | 139 | ok = GNUNET_SYSERR; |
184 | } | ||
185 | ok = 1; | ||
186 | } | 140 | } |
187 | 141 | ||
188 | 142 | ||
@@ -192,18 +146,32 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
192 | const struct GNUNET_ATS_Information *ats, | 146 | const struct GNUNET_ATS_Information *ats, |
193 | uint32_t ats_count) | 147 | uint32_t ats_count) |
194 | { | 148 | { |
149 | struct PeerContext * p = cls; | ||
150 | struct PeerContext *t = NULL; | ||
151 | |||
152 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
153 | t = p1; | ||
154 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
155 | t = p2; | ||
156 | GNUNET_assert (t != NULL); | ||
157 | |||
158 | char * ps = strdup (GNUNET_i2s(&p->id)); | ||
159 | |||
195 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
196 | "Received message of type %d from peer %s!\n", | 161 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", |
197 | ntohs (message->type), GNUNET_i2s (peer)); | 162 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, GNUNET_i2s (&t->id)); |
198 | OKPP; | ||
199 | GNUNET_assert (MTYPE == ntohs (message->type)); | ||
200 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); | ||
201 | 163 | ||
202 | msgs_recv++; | 164 | if ((MTYPE == ntohs (message->type)) && |
165 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | ||
166 | { | ||
167 | ok = 1; | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down peer\n"); | ||
169 | shutdown_ = GNUNET_YES; | ||
170 | GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2); | ||
171 | return; | ||
172 | } | ||
203 | } | 173 | } |
204 | 174 | ||
205 | static void | ||
206 | peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
207 | 175 | ||
208 | static size_t | 176 | static size_t |
209 | notify_ready (void *cls, size_t size, void *buf) | 177 | notify_ready (void *cls, size_t size, void *buf) |
@@ -213,21 +181,54 @@ notify_ready (void *cls, size_t size, void *buf) | |||
213 | 181 | ||
214 | th = NULL; | 182 | th = NULL; |
215 | 183 | ||
216 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 184 | if (buf == NULL) |
217 | "Transmitting message with %u bytes to peer %s\n", | 185 | { |
218 | sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id)); | 186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
187 | "Timeout occurred while waiting for transmit_ready\n"); | ||
188 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
189 | GNUNET_SCHEDULER_cancel (die_task); | ||
190 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
191 | ok = 42; | ||
192 | return 0; | ||
193 | } | ||
194 | |||
219 | GNUNET_assert (size >= 256); | 195 | GNUNET_assert (size >= 256); |
220 | OKPP; | 196 | |
221 | if (buf != NULL) | 197 | if (buf != NULL) |
222 | { | 198 | { |
223 | hdr = buf; | 199 | hdr = buf; |
224 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); | 200 | hdr->size = htons (sizeof (struct GNUNET_MessageHeader)); |
225 | hdr->type = htons (MTYPE); | 201 | hdr->type = htons (MTYPE); |
226 | } | 202 | } |
203 | char * ps = strdup (GNUNET_i2s(&p2->id)); | ||
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
205 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
206 | p2->no, | ||
207 | ps, | ||
208 | ntohs (hdr->type), | ||
209 | ntohs (hdr->size), p->no, GNUNET_i2s (&p->id)); | ||
210 | GNUNET_free (ps); | ||
211 | return sizeof (struct GNUNET_MessageHeader); | ||
212 | } | ||
227 | 213 | ||
228 | GNUNET_SCHEDULER_add_now (&peers_disconnect, NULL); | ||
229 | 214 | ||
230 | return sizeof (struct GNUNET_MessageHeader); | 215 | static void |
216 | sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
217 | { | ||
218 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
219 | |||
220 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
221 | return; | ||
222 | char * receiver_s = strdup(GNUNET_i2s (&p1->id)); | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
224 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
225 | p2->no, | ||
226 | GNUNET_i2s (&p2->id), p1->no, receiver_s); | ||
227 | GNUNET_free (receiver_s); | ||
228 | |||
229 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256, 0, | ||
230 | TIMEOUT_TRANSMIT, ¬ify_ready, | ||
231 | p1); | ||
231 | } | 232 | } |
232 | 233 | ||
233 | 234 | ||
@@ -236,150 +237,114 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
236 | const struct GNUNET_ATS_Information *ats, | 237 | const struct GNUNET_ATS_Information *ats, |
237 | uint32_t ats_count) | 238 | uint32_t ats_count) |
238 | { | 239 | { |
239 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' connected to us (%p)!\n", | 240 | static int c; |
240 | GNUNET_i2s (peer), cls); | 241 | c++; |
241 | peers_connected++; | 242 | struct PeerContext *p = cls; |
242 | if (cls == &p1) | 243 | struct PeerContext *t = NULL; |
243 | { | 244 | |
244 | GNUNET_assert (ok >= 2); | 245 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) |
245 | OKPP; | 246 | t = p1; |
246 | OKPP; | 247 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) |
247 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | 248 | t = p2; |
248 | GNUNET_SCHEDULER_cancel (die_task); | 249 | GNUNET_assert (t!=NULL); |
249 | if (GNUNET_SCHEDULER_NO_TASK != tct) | 250 | |
250 | GNUNET_SCHEDULER_cancel (tct); | 251 | char * ps = strdup (GNUNET_i2s(&p->id)); |
251 | tct = GNUNET_SCHEDULER_NO_TASK; | 252 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", |
252 | 253 | p->no, ps, | |
253 | die_task = | 254 | t->no, GNUNET_i2s (peer)); |
254 | GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, &end_badly, NULL); | 255 | GNUNET_free (ps); |
255 | th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th, &p2.id, 256, 0, TIMEOUT, | ||
256 | ¬ify_ready, &p1); | ||
257 | } | ||
258 | } | 256 | } |
259 | 257 | ||
260 | 258 | ||
261 | static void | 259 | static void |
262 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 260 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) |
263 | { | 261 | { |
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%4s' disconnected (%p)!\n", | 262 | struct PeerContext *p = cls; |
265 | GNUNET_i2s (peer), cls); | 263 | char * ps = strdup (GNUNET_i2s(&p->id)); |
264 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", | ||
265 | p->no, ps, GNUNET_i2s (peer)); | ||
266 | |||
266 | if (th != NULL) | 267 | if (th != NULL) |
267 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 268 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
268 | th = NULL; | 269 | th = NULL; |
269 | peers_connected--; | ||
270 | } | ||
271 | 270 | ||
271 | if (shutdown_ == GNUNET_YES) | ||
272 | { | ||
273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Complete, shutting down...\n"); | ||
274 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
275 | } | ||
276 | } | ||
272 | 277 | ||
273 | static void | 278 | static void |
274 | setup_peer (struct PeerContext *p, const char *cfgname) | 279 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) |
275 | { | 280 | { |
276 | p->cfg = GNUNET_CONFIGURATION_create (); | 281 | cc = NULL; |
277 | 282 | char *p1_c = strdup (GNUNET_i2s (&p1->id)); | |
278 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); | ||
279 | if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME")) | ||
280 | GNUNET_assert (GNUNET_OK == | ||
281 | GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", | ||
282 | &p->servicehome)); | ||
283 | if (NULL != p->servicehome) | ||
284 | GNUNET_DISK_directory_remove (p->servicehome); | ||
285 | |||
286 | #if START_ARM | ||
287 | p->arm_proc = | ||
288 | GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", | ||
289 | "gnunet-service-arm", | ||
290 | #if VERBOSE_ARM | ||
291 | "-L", "DEBUG", | ||
292 | #endif | ||
293 | "-c", cfgname, NULL); | ||
294 | #endif | ||
295 | |||
296 | } | ||
297 | 283 | ||
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
285 | p1->no, p1_c, | ||
286 | p2->no, GNUNET_i2s (&p2->id)); | ||
287 | GNUNET_free (p1_c); | ||
298 | 288 | ||
299 | static void | 289 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); |
300 | try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
301 | { | ||
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n"); | ||
303 | /* FIXME: 'pX.id' may still be all-zeros here... */ | ||
304 | GNUNET_TRANSPORT_try_connect (p2.th, &p1.id); | ||
305 | GNUNET_TRANSPORT_try_connect (p1.th, &p2.id); | ||
306 | tct = | ||
307 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, | ||
308 | NULL); | ||
309 | } | 290 | } |
310 | 291 | ||
311 | 292 | ||
312 | static void | ||
313 | peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
314 | { | ||
315 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
316 | return; | ||
317 | |||
318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Transport \n"); | ||
319 | 293 | ||
320 | GNUNET_TRANSPORT_get_hello_cancel (p2.ghh); | 294 | void start_cb (struct PeerContext * p, |
321 | GNUNET_TRANSPORT_get_hello_cancel (p1.ghh); | 295 | void *cls) |
296 | { | ||
297 | static int started; | ||
298 | started++; | ||
322 | 299 | ||
323 | GNUNET_TRANSPORT_disconnect (p1.th); | 300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", |
324 | p1.th = NULL; | 301 | p->no, |
302 | GNUNET_i2s (&p->id)); | ||
325 | 303 | ||
326 | GNUNET_TRANSPORT_disconnect (p2.th); | 304 | if (started != 2) |
327 | p2.th = NULL; | 305 | return; |
328 | 306 | ||
329 | while (peers_connected > 0) ; | 307 | char *sender_c = strdup (GNUNET_i2s (&p1->id)); |
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
309 | p1->no, sender_c, | ||
310 | p2->no, GNUNET_i2s (&p2->id)); | ||
330 | 311 | ||
331 | if (counter < ITERATIONS) | 312 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, |
332 | { | 313 | NULL); |
333 | if ((counter % (ITERATIONS / 10)) == 0) | ||
334 | fprintf (stderr, "%u%%..", (counter / (ITERATIONS / 10)) * 10); | ||
335 | peers_connect (); | ||
336 | } | ||
337 | else | ||
338 | { | ||
339 | fprintf (stderr, "100%%\n"); | ||
340 | end (); | ||
341 | } | ||
342 | } | ||
343 | 314 | ||
344 | static void | ||
345 | peers_connect () | ||
346 | { | ||
347 | counter++; | ||
348 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration %i of %i\n", counter, | ||
349 | ITERATIONS); | ||
350 | |||
351 | GNUNET_assert (p1.th == NULL); | ||
352 | p1.th = | ||
353 | GNUNET_TRANSPORT_connect (p1.cfg, NULL, &p1, ¬ify_receive, | ||
354 | ¬ify_connect, ¬ify_disconnect); | ||
355 | |||
356 | GNUNET_assert (p2.th == NULL); | ||
357 | p2.th = | ||
358 | GNUNET_TRANSPORT_connect (p2.cfg, NULL, &p2, ¬ify_receive, | ||
359 | ¬ify_connect, ¬ify_disconnect); | ||
360 | |||
361 | GNUNET_assert (p1.th != NULL); | ||
362 | GNUNET_assert (p2.th != NULL); | ||
363 | |||
364 | p1.ghh = GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | ||
365 | p2.ghh = GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | ||
366 | tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); | ||
367 | } | 315 | } |
368 | 316 | ||
369 | static void | 317 | static void |
370 | run (void *cls, char *const *args, const char *cfgfile, | 318 | run (void *cls, char *const *args, const char *cfgfile, |
371 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 319 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
372 | { | 320 | { |
373 | GNUNET_assert (ok == 1); | ||
374 | OKPP; | ||
375 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 321 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
376 | 322 | ||
377 | setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); | 323 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p1, 1, |
378 | setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); | 324 | ¬ify_receive, |
379 | 325 | ¬ify_connect, | |
380 | peers_connect (); | 326 | ¬ify_disconnect, |
327 | &start_cb, | ||
328 | NULL); | ||
329 | |||
330 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, cfg_file_p2, 2, | ||
331 | ¬ify_receive, | ||
332 | ¬ify_connect, | ||
333 | ¬ify_disconnect, | ||
334 | &start_cb, | ||
335 | NULL); | ||
336 | |||
337 | if ((p1 == NULL) || (p2 == NULL)) | ||
338 | { | ||
339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
340 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
341 | GNUNET_SCHEDULER_cancel (die_task); | ||
342 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
343 | return; | ||
344 | } | ||
381 | } | 345 | } |
382 | 346 | ||
347 | |||
383 | static int | 348 | static int |
384 | check () | 349 | check () |
385 | { | 350 | { |
@@ -398,22 +363,12 @@ check () | |||
398 | #if WRITECONFIG | 363 | #if WRITECONFIG |
399 | setTransportOptions ("test_transport_api_data.conf"); | 364 | setTransportOptions ("test_transport_api_data.conf"); |
400 | #endif | 365 | #endif |
366 | send_task = GNUNET_SCHEDULER_NO_TASK; | ||
367 | |||
401 | ok = 1; | 368 | ok = 1; |
402 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, | 369 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, |
403 | "test-transport-api", "nohelp", options, &run, &ok); | 370 | "nohelp", options, &run, &ok); |
404 | stop_arm (&p1); | ||
405 | stop_arm (&p2); | ||
406 | 371 | ||
407 | if (p1.servicehome != NULL) | ||
408 | { | ||
409 | GNUNET_DISK_directory_remove (p1.servicehome); | ||
410 | GNUNET_free (p1.servicehome); | ||
411 | } | ||
412 | if (p2.servicehome != NULL) | ||
413 | { | ||
414 | GNUNET_DISK_directory_remove (p2.servicehome); | ||
415 | GNUNET_free (p2.servicehome); | ||
416 | } | ||
417 | return ok; | 372 | return ok; |
418 | } | 373 | } |
419 | 374 | ||
@@ -421,8 +376,16 @@ int | |||
421 | main (int argc, char *argv[]) | 376 | main (int argc, char *argv[]) |
422 | { | 377 | { |
423 | int ret; | 378 | int ret; |
379 | int nat_res; | ||
380 | |||
381 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
424 | 382 | ||
425 | GNUNET_log_setup ("test_transport_api_disconnect", | 383 | GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__, &test_source); |
384 | GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], test_source, | ||
385 | &test_plugin); | ||
386 | GNUNET_TRANSPORT_TESTING_get_test_name (argv[0], &test_name); | ||
387 | |||
388 | GNUNET_log_setup (test_name, | ||
426 | #if VERBOSE | 389 | #if VERBOSE |
427 | "DEBUG", | 390 | "DEBUG", |
428 | #else | 391 | #else |
@@ -430,9 +393,39 @@ main (int argc, char *argv[]) | |||
430 | #endif | 393 | #endif |
431 | NULL); | 394 | NULL); |
432 | 395 | ||
396 | if ((strcmp (test_plugin, "tcp_nat") == 0) || | ||
397 | (strcmp (test_plugin, "udp_nat") == 0)) | ||
398 | { | ||
399 | nat_res = GNUNET_OS_check_helper_binary ("gnunet-nat-server"); | ||
400 | if (GNUNET_NO == nat_res) | ||
401 | { | ||
402 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
403 | "gnunet-nat-server", "SUID not set"); | ||
404 | return 0; | ||
405 | } | ||
406 | if (GNUNET_SYSERR == nat_res) | ||
407 | { | ||
408 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot run NAT test: `%s' %s \n", | ||
409 | "gnunet-nat-server", "file not found"); | ||
410 | return 0; | ||
411 | } | ||
412 | } | ||
413 | |||
414 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p1, 1); | ||
415 | GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], &cfg_file_p2, 2); | ||
416 | |||
433 | ret = check (); | 417 | ret = check (); |
434 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Messages received: %i\n", msgs_recv); | 418 | |
419 | GNUNET_free (cfg_file_p1); | ||
420 | GNUNET_free (cfg_file_p2); | ||
421 | |||
422 | GNUNET_free (test_source); | ||
423 | GNUNET_free (test_plugin); | ||
424 | GNUNET_free (test_name); | ||
425 | |||
426 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
427 | |||
435 | return ret; | 428 | return ret; |
436 | } | 429 | } |
437 | 430 | ||
438 | /* end of test_transport_api_disconnect.c */ | 431 | /* end of test_transport_api.c */ |