diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-12 08:08:17 +0000 |
commit | a00afbdaae8de7fd752aab1ed5028833a85eeea7 (patch) | |
tree | 7f332838143653bf2bc7e4f3969ef9e8e43a03b7 /src/transport/test_transport_api_restart_2peers.c | |
parent | 6bfa05291c469d0aba00e85456ceadf8b433601c (diff) | |
download | gnunet-a00afbdaae8de7fd752aab1ed5028833a85eeea7.tar.gz gnunet-a00afbdaae8de7fd752aab1ed5028833a85eeea7.zip |
more transport testing hacking
Diffstat (limited to 'src/transport/test_transport_api_restart_2peers.c')
-rw-r--r-- | src/transport/test_transport_api_restart_2peers.c | 398 |
1 files changed, 103 insertions, 295 deletions
diff --git a/src/transport/test_transport_api_restart_2peers.c b/src/transport/test_transport_api_restart_2peers.c index 876b7209c..40f287623 100644 --- a/src/transport/test_transport_api_restart_2peers.c +++ b/src/transport/test_transport_api_restart_2peers.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2010, 2015 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 2015, 2016 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 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 | 6 | it under the terms of the GNU General Public License as published |
@@ -18,11 +18,12 @@ | |||
18 | Boston, MA 02110-1301, USA. | 18 | Boston, MA 02110-1301, USA. |
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file transport/test_transport_api_restart_2peers.c | 21 | * @file transport/test_transport_api_restart_1peer.c |
22 | * @brief base test case for transport implementations | 22 | * @brief base test case for transport implementations |
23 | * | 23 | * |
24 | * This test case starts 2 peers, connects and exchanges a message | 24 | * This test case starts 2 peers, connects and exchanges a message |
25 | * boths peer are restarted and tested if peers reconnect | 25 | * 1 peer is restarted and tested if peers reconnect |
26 | * C code apparently. | ||
26 | */ | 27 | */ |
27 | #include "platform.h" | 28 | #include "platform.h" |
28 | #include "gnunet_transport_service.h" | 29 | #include "gnunet_transport_service.h" |
@@ -31,100 +32,49 @@ | |||
31 | /** | 32 | /** |
32 | * How long until we give up on transmitting the message? | 33 | * How long until we give up on transmitting the message? |
33 | */ | 34 | */ |
34 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 900) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
35 | 36 | ||
36 | /** | 37 | /** |
37 | * How long until we give up on transmitting the message? | 38 | * How long until we give up on transmitting the message? |
38 | */ | 39 | */ |
39 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) | 40 | #define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
40 | 41 | ||
41 | #define MTYPE 12345 | 42 | #define MTYPE 12345 |
42 | 43 | ||
43 | static char *test_name; | ||
44 | 44 | ||
45 | static int ok; | 45 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
46 | |||
47 | static struct GNUNET_SCHEDULER_Task *die_task; | ||
48 | |||
49 | static struct GNUNET_SCHEDULER_Task *send_task; | ||
50 | 46 | ||
51 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; | 47 | static struct GNUNET_ATS_ConnectivitySuggestHandle *ats_sh; |
52 | 48 | ||
53 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | 49 | static int p1_connected; |
54 | |||
55 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
56 | 50 | ||
57 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; | 51 | static int p2_connected; |
58 | 52 | ||
59 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 53 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
60 | 54 | ||
61 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 55 | static struct GNUNET_SCHEDULER_Task *send_task; |
62 | |||
63 | static char *cfg_file_p1; | ||
64 | |||
65 | static char *cfg_file_p2; | ||
66 | 56 | ||
67 | static int restarted; | 57 | static int restarted; |
68 | 58 | ||
69 | 59 | ||
70 | static void | 60 | static void |
71 | end () | 61 | custom_shutdown (void *cls) |
72 | { | 62 | { |
73 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); | ||
74 | if (NULL != send_task) | ||
75 | { | ||
76 | GNUNET_SCHEDULER_cancel (send_task); | ||
77 | send_task = NULL; | ||
78 | } | ||
79 | if (NULL != ats_sh) | 63 | if (NULL != ats_sh) |
80 | { | 64 | { |
81 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); | 65 | GNUNET_ATS_connectivity_suggest_cancel (ats_sh); |
82 | ats_sh = NULL; | 66 | ats_sh = NULL; |
83 | } | 67 | } |
84 | if (NULL != die_task) | ||
85 | { | ||
86 | GNUNET_SCHEDULER_cancel (die_task); | ||
87 | die_task = NULL; | ||
88 | } | ||
89 | if (NULL != th) | 68 | if (NULL != th) |
90 | { | 69 | { |
91 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 70 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
92 | th = NULL; | 71 | th = NULL; |
93 | } | 72 | } |
94 | if (NULL != p1) | 73 | if (NULL != send_task) |
95 | { | ||
96 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
97 | p1 = NULL; | ||
98 | } | ||
99 | if (NULL != p2) | ||
100 | { | ||
101 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
102 | p2 = NULL; | ||
103 | } | ||
104 | } | ||
105 | |||
106 | |||
107 | static void | ||
108 | end_badly (void *cls) | ||
109 | { | ||
110 | die_task = NULL; | ||
111 | |||
112 | if (restarted == GNUNET_YES) | ||
113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
114 | "Peer was restarted, but communication did not resume\n"); | ||
115 | |||
116 | if (restarted == GNUNET_NO) | ||
117 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
118 | "Peer was NOT (even) restarted\n"); | ||
119 | if (cc != NULL) | ||
120 | { | 74 | { |
121 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 75 | GNUNET_SCHEDULER_cancel (send_task); |
122 | _("Fail! Could not connect peers\n")); | 76 | send_task = NULL; |
123 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
124 | cc = NULL; | ||
125 | } | 77 | } |
126 | end (); | ||
127 | ok = GNUNET_SYSERR; | ||
128 | } | 78 | } |
129 | 79 | ||
130 | 80 | ||
@@ -132,17 +82,17 @@ static void | |||
132 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | 82 | restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, |
133 | void *cls) | 83 | void *cls) |
134 | { | 84 | { |
135 | static int c; | 85 | static unsigned int c; |
136 | 86 | ||
137 | c++; | 87 | c++; |
138 | if (c != 2) | 88 | if (c != 2) |
139 | return; | 89 | return; |
140 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 90 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
141 | "Restarted peer %u (`%4s'), issuing reconnect\n", | 91 | "Restarted peer %u (`%s'), issuing reconnect\n", |
142 | p->no, | 92 | p->no, |
143 | GNUNET_i2s (&p->id)); | 93 | GNUNET_i2s (&p->id)); |
144 | ats_sh = GNUNET_ATS_connectivity_suggest (p->ats, | 94 | ats_sh = GNUNET_ATS_connectivity_suggest (ccc->p[0]->ats, |
145 | &p2->id, | 95 | &ccc->p[1]->id, |
146 | 1); | 96 | 1); |
147 | } | 97 | } |
148 | 98 | ||
@@ -150,78 +100,66 @@ restart_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, | |||
150 | static void | 100 | static void |
151 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) | 101 | restart (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) |
152 | { | 102 | { |
153 | GNUNET_assert (NULL != p); | ||
154 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
155 | "Restarting peer %u (`%4s')\n", | 104 | "Restarting peer %u (`%s')\n", |
156 | p->no, | 105 | p->no, |
157 | GNUNET_i2s (&p->id)); | 106 | GNUNET_i2s (&p->id)); |
158 | GNUNET_TRANSPORT_TESTING_restart_peer (p, | 107 | GNUNET_assert (GNUNET_OK == |
159 | &restart_cb, | 108 | GNUNET_TRANSPORT_TESTING_restart_peer (p, |
160 | p); | 109 | &restart_cb, |
110 | p)); | ||
161 | } | 111 | } |
162 | 112 | ||
163 | 113 | ||
164 | static void | 114 | static void |
165 | notify_receive (void *cls, | 115 | notify_receive (void *cls, |
166 | const struct GNUNET_PeerIdentity *peer, | 116 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, |
117 | const struct GNUNET_PeerIdentity *sender, | ||
167 | const struct GNUNET_MessageHeader *message) | 118 | const struct GNUNET_MessageHeader *message) |
168 | { | 119 | { |
169 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
170 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
171 | |||
172 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
173 | t = p1; | ||
174 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | ||
175 | t = p2; | ||
176 | GNUNET_assert (t != NULL); | ||
177 | |||
178 | { | 120 | { |
179 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 121 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
180 | 122 | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
182 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | 124 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
183 | p->no, | 125 | receiver->no, |
184 | ps, | 126 | ps, |
185 | ntohs (message->type), | 127 | ntohs (message->type), |
186 | ntohs (message->size), | 128 | ntohs (message->size), |
187 | t->no, | 129 | GNUNET_i2s (sender)); |
188 | GNUNET_i2s (&t->id)); | ||
189 | GNUNET_free (ps); | 130 | GNUNET_free (ps); |
190 | } | 131 | } |
191 | |||
192 | if ((MTYPE == ntohs (message->type)) && | 132 | if ((MTYPE == ntohs (message->type)) && |
193 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) | 133 | (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) |
194 | { | 134 | { |
195 | if (restarted == GNUNET_NO) | 135 | if (GNUNET_NO == restarted) |
196 | { | 136 | { |
197 | restarted = GNUNET_YES; | 137 | restarted = GNUNET_YES; |
198 | restart (p1); | 138 | restart (ccc->p[0]); |
199 | restart (p2); | 139 | restart (ccc->p[1]); |
200 | return; | 140 | return; |
201 | } | 141 | } |
202 | else | 142 | else |
203 | { | 143 | { |
204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
205 | "Restarted peers connected, stopping test...\n"); | 145 | "Restarted peers connected and message was sent, stopping test...\n"); |
206 | ok = 0; | 146 | ccc->global_ret = GNUNET_OK; |
207 | end (); | 147 | GNUNET_SCHEDULER_shutdown (); |
208 | } | 148 | } |
209 | } | 149 | } |
210 | else | 150 | else |
211 | { | 151 | { |
212 | GNUNET_break (0); | 152 | GNUNET_break (0); |
213 | ok = 1; | 153 | ccc->global_ret = GNUNET_SYSERR; |
214 | if (die_task != NULL) | 154 | GNUNET_SCHEDULER_shutdown (); |
215 | GNUNET_SCHEDULER_cancel (die_task); | ||
216 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
217 | } | 155 | } |
218 | } | 156 | } |
219 | 157 | ||
220 | 158 | ||
221 | static size_t | 159 | static size_t |
222 | notify_ready (void *cls, | 160 | notify_ready (void *cls, |
223 | size_t size, | 161 | size_t size, |
224 | void *buf) | 162 | void *buf) |
225 | { | 163 | { |
226 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 164 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; |
227 | struct GNUNET_MessageHeader *hdr; | 165 | struct GNUNET_MessageHeader *hdr; |
@@ -231,10 +169,8 @@ notify_ready (void *cls, | |||
231 | { | 169 | { |
232 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
233 | "Timeout occurred while waiting for transmit_ready\n"); | 171 | "Timeout occurred while waiting for transmit_ready\n"); |
234 | if (NULL != die_task) | 172 | GNUNET_SCHEDULER_shutdown (); |
235 | GNUNET_SCHEDULER_cancel (die_task); | 173 | ccc->global_ret = 42; |
236 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
237 | ok = 42; | ||
238 | return 0; | 174 | return 0; |
239 | } | 175 | } |
240 | 176 | ||
@@ -244,11 +180,11 @@ notify_ready (void *cls, | |||
244 | hdr->type = htons (MTYPE); | 180 | hdr->type = htons (MTYPE); |
245 | 181 | ||
246 | { | 182 | { |
247 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | 183 | char *ps = GNUNET_strdup (GNUNET_i2s (&ccc->p[1]->id)); |
248 | 184 | ||
249 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 185 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
250 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | 186 | "Peer %u (`%s') sending message with type %u and size %u bytes to peer %u (`%s')\n", |
251 | p2->no, | 187 | ccc->p[1]->no, |
252 | ps, | 188 | ps, |
253 | ntohs (hdr->type), | 189 | ntohs (hdr->type), |
254 | ntohs (hdr->size), | 190 | ntohs (hdr->size), |
@@ -256,7 +192,6 @@ notify_ready (void *cls, | |||
256 | GNUNET_i2s (&p->id)); | 192 | GNUNET_i2s (&p->id)); |
257 | GNUNET_free (ps); | 193 | GNUNET_free (ps); |
258 | } | 194 | } |
259 | |||
260 | return sizeof (struct GNUNET_MessageHeader); | 195 | return sizeof (struct GNUNET_MessageHeader); |
261 | } | 196 | } |
262 | 197 | ||
@@ -266,82 +201,66 @@ sendtask (void *cls) | |||
266 | { | 201 | { |
267 | send_task = NULL; | 202 | send_task = NULL; |
268 | { | 203 | { |
269 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | 204 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); |
270 | 205 | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
272 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | 207 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", |
273 | p2->no, | 208 | ccc->p[1]->no, |
274 | GNUNET_i2s (&p2->id), | 209 | GNUNET_i2s (&ccc->p[1]->id), |
275 | p1->no, | 210 | ccc->p[0]->no, |
276 | receiver_s); | 211 | receiver_s); |
277 | GNUNET_free (receiver_s); | 212 | GNUNET_free (receiver_s); |
278 | } | 213 | } |
279 | 214 | th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th, | |
280 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, | 215 | &ccc->p[0]->id, |
281 | &p1->id, | ||
282 | 256, | 216 | 256, |
283 | TIMEOUT_TRANSMIT, | 217 | TIMEOUT_TRANSMIT, |
284 | ¬ify_ready, | 218 | ¬ify_ready, |
285 | p1); | 219 | ccc->p[0]); |
286 | } | 220 | } |
287 | 221 | ||
288 | 222 | ||
289 | static void | 223 | static void |
290 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 224 | notify_connect (void *cls, |
225 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
226 | const struct GNUNET_PeerIdentity *other) | ||
291 | { | 227 | { |
292 | static int c; | 228 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
293 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 229 | me, |
294 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 230 | other); |
295 | 231 | if (0 == memcmp (other, | |
296 | c++; | 232 | &ccc->p[0]->id, |
297 | if (0 == memcmp (peer, | 233 | sizeof (struct GNUNET_PeerIdentity))) |
298 | &p1->id, | 234 | p1_connected = GNUNET_YES; |
299 | sizeof (struct GNUNET_PeerIdentity))) | 235 | if (0 == memcmp (other, |
300 | t = p1; | 236 | &ccc->p[1]->id, |
301 | if (0 == memcmp (peer, | 237 | sizeof (struct GNUNET_PeerIdentity))) |
302 | &p2->id, | 238 | p2_connected = GNUNET_YES; |
303 | sizeof (struct GNUNET_PeerIdentity))) | 239 | |
304 | t = p2; | 240 | if ( (GNUNET_YES == restarted) && |
305 | GNUNET_assert (t != NULL); | 241 | (GNUNET_YES == p1_connected) && |
306 | 242 | (GNUNET_YES == p2_connected) ) | |
307 | { | ||
308 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
309 | |||
310 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
311 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", | ||
312 | p->no, | ||
313 | ps, | ||
314 | t->no, | ||
315 | GNUNET_i2s (peer)); | ||
316 | GNUNET_free (ps); | ||
317 | } | ||
318 | |||
319 | if ((restarted == GNUNET_YES) && (c == 4)) | ||
320 | { | 243 | { |
244 | /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ | ||
321 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | 245 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, |
322 | NULL); | 246 | NULL); |
323 | } | 247 | } |
324 | } | 248 | } |
325 | 249 | ||
326 | 250 | ||
327 | static void | 251 | static void |
328 | notify_disconnect (void *cls, | 252 | notify_disconnect (void *cls, |
329 | const struct GNUNET_PeerIdentity *peer) | 253 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, |
254 | const struct GNUNET_PeerIdentity *other) | ||
330 | { | 255 | { |
331 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 256 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
332 | 257 | me, | |
333 | { | 258 | other); |
334 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 259 | if (me == ccc->p[0]) |
335 | 260 | p1_connected = GNUNET_NO; | |
336 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 261 | if (me == ccc->p[1]) |
337 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", | 262 | p2_connected = GNUNET_NO; |
338 | p->no, | 263 | if (NULL != th) |
339 | ps, | ||
340 | GNUNET_i2s (peer)); | ||
341 | GNUNET_free (ps); | ||
342 | } | ||
343 | |||
344 | if (th != NULL) | ||
345 | { | 264 | { |
346 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 265 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
347 | th = NULL; | 266 | th = NULL; |
@@ -354,137 +273,26 @@ notify_disconnect (void *cls, | |||
354 | } | 273 | } |
355 | 274 | ||
356 | 275 | ||
357 | static void | ||
358 | testing_connect_cb (void *cls) | ||
359 | { | ||
360 | cc = NULL; | ||
361 | |||
362 | { | ||
363 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
364 | |||
365 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
366 | "Peers connected: %u (%s) <-> %u (%s)\n", | ||
367 | p1->no, | ||
368 | p1_c, | ||
369 | p2->no, | ||
370 | GNUNET_i2s (&p2->id)); | ||
371 | GNUNET_free (p1_c); | ||
372 | } | ||
373 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, | ||
374 | NULL); | ||
375 | } | ||
376 | |||
377 | |||
378 | static void | ||
379 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
380 | { | ||
381 | static int started; | ||
382 | |||
383 | started++; | ||
384 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
385 | "Peer %u (`%s') started\n", | ||
386 | p->no, | ||
387 | GNUNET_i2s (&p->id)); | ||
388 | if (started != 2) | ||
389 | return; | ||
390 | |||
391 | { | ||
392 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
393 | |||
394 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
395 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
396 | p1->no, | ||
397 | sender_c, | ||
398 | p2->no, | ||
399 | GNUNET_i2s (&p2->id)); | ||
400 | GNUNET_free (sender_c); | ||
401 | } | ||
402 | |||
403 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | ||
404 | p2, | ||
405 | &testing_connect_cb, | ||
406 | NULL); | ||
407 | } | ||
408 | |||
409 | |||
410 | static void | ||
411 | run (void *cls, | ||
412 | char *const *args, | ||
413 | const char *cfgfile, | ||
414 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
415 | { | ||
416 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | ||
417 | &end_badly, | ||
418 | NULL); | ||
419 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
420 | cfg_file_p1, | ||
421 | 1, | ||
422 | ¬ify_receive, | ||
423 | ¬ify_connect, | ||
424 | ¬ify_disconnect, | ||
425 | &start_cb, | ||
426 | NULL); | ||
427 | |||
428 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
429 | cfg_file_p2, | ||
430 | 2, | ||
431 | ¬ify_receive, | ||
432 | ¬ify_connect, | ||
433 | ¬ify_disconnect, | ||
434 | &start_cb, | ||
435 | NULL); | ||
436 | |||
437 | if ((p1 == NULL) || (p2 == NULL)) | ||
438 | { | ||
439 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
440 | if (die_task != NULL) | ||
441 | GNUNET_SCHEDULER_cancel (die_task); | ||
442 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
443 | return; | ||
444 | } | ||
445 | } | ||
446 | |||
447 | |||
448 | static int | ||
449 | check () | ||
450 | { | ||
451 | static char *const argv[] = { "test-transport-api", | ||
452 | "-c", | ||
453 | "test_transport_api_data.conf", | ||
454 | NULL | ||
455 | }; | ||
456 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
457 | GNUNET_GETOPT_OPTION_END | ||
458 | }; | ||
459 | |||
460 | send_task = NULL; | ||
461 | |||
462 | ok = 1; | ||
463 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
464 | "nohelp", options, &run, NULL); | ||
465 | |||
466 | return ok; | ||
467 | } | ||
468 | |||
469 | |||
470 | int | 276 | int |
471 | main (int argc, char *argv[]) | 277 | main (int argc, char *argv[]) |
472 | { | 278 | { |
473 | int ret; | 279 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
474 | 280 | .connect_continuation = &sendtask, | |
475 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 281 | .config_file = "test_transport_api_data.conf", |
476 | GNUNET_log_setup (test_name, | 282 | .rec = ¬ify_receive, |
477 | "WARNING", | 283 | .nc = ¬ify_connect, |
478 | NULL); | 284 | .nd = ¬ify_disconnect, |
479 | tth = GNUNET_TRANSPORT_TESTING_init (); | 285 | .shutdown_task = &custom_shutdown, |
480 | GNUNET_asprintf (&cfg_file_p1, "test_transport_api_tcp_peer1.conf"); | 286 | .timeout = TIMEOUT |
481 | GNUNET_asprintf (&cfg_file_p2, "test_transport_api_tcp_peer2.conf"); | 287 | }; |
482 | ret = check (); | 288 | |
483 | GNUNET_free (cfg_file_p1); | 289 | ccc = &my_ccc; |
484 | GNUNET_free (cfg_file_p2); | 290 | if (GNUNET_OK != |
485 | GNUNET_free (test_name); | 291 | GNUNET_TRANSPORT_TESTING_main (2, |
486 | GNUNET_TRANSPORT_TESTING_done (tth); | 292 | &GNUNET_TRANSPORT_TESTING_connect_check, |
487 | return ret; | 293 | ccc)) |
294 | return 1; | ||
295 | return 0; | ||
488 | } | 296 | } |
489 | 297 | ||
490 | /* end of test_transport_api_restart_2peers.c */ | 298 | /* end of test_transport_api_restart_1peer.c */ |