diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 17:05:47 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 17:05:47 +0000 |
commit | cfaef88493535118f0cc16a70be4837ff3c47de0 (patch) | |
tree | 3e95dda4dba8772429c5c2ac945fa5d6f075d46f /src/transport/test_transport_api_monitor_peers.c | |
parent | c6444a089a860da694842942283079a25bc1e957 (diff) | |
download | gnunet-cfaef88493535118f0cc16a70be4837ff3c47de0.tar.gz gnunet-cfaef88493535118f0cc16a70be4837ff3c47de0.zip |
-use new testing API in montior_peers test
Diffstat (limited to 'src/transport/test_transport_api_monitor_peers.c')
-rw-r--r-- | src/transport/test_transport_api_monitor_peers.c | 461 |
1 files changed, 80 insertions, 381 deletions
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c index 4731e41e2..1f0eb184c 100644 --- a/src/transport/test_transport_api_monitor_peers.c +++ b/src/transport/test_transport_api_monitor_peers.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 GNUnet e.V. | 3 | Copyright (C) 2009, 2010, 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 |
@@ -39,136 +39,31 @@ | |||
39 | 39 | ||
40 | #define TEST_MESSAGE_TYPE 12345 | 40 | #define TEST_MESSAGE_TYPE 12345 |
41 | 41 | ||
42 | static char *test_source; | ||
43 | |||
44 | static char *test_plugin; | ||
45 | |||
46 | static char *test_name; | ||
47 | |||
48 | static int ok; | ||
49 | |||
50 | static int s_started; | ||
51 | |||
52 | static int s_connected; | ||
53 | |||
54 | static int s_sending; | ||
55 | |||
56 | static struct GNUNET_SCHEDULER_Task * die_task; | ||
57 | |||
58 | static struct GNUNET_SCHEDULER_Task * send_task; | ||
59 | |||
60 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | ||
61 | |||
62 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
63 | |||
64 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
65 | |||
66 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | 42 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
67 | 43 | ||
68 | static struct GNUNET_TRANSPORT_TESTING_Handle *tth; | 44 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; |
69 | |||
70 | static char *cfg_file_p1; | ||
71 | |||
72 | static char *cfg_file_p2; | ||
73 | 45 | ||
74 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p1; | 46 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p1; |
75 | 47 | ||
76 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p2; | 48 | static struct GNUNET_TRANSPORT_PeerMonitoringContext *pmc_p2; |
77 | 49 | ||
78 | static int p1_c = GNUNET_NO; | 50 | static int p1_c; |
79 | 51 | ||
80 | static int p2_c = GNUNET_NO; | 52 | static int p2_c; |
81 | 53 | ||
82 | static int p1_c_notify = GNUNET_NO; | 54 | static int p1_c_notify; |
83 | 55 | ||
84 | static int p2_c_notify = GNUNET_NO; | 56 | static int p2_c_notify; |
85 | 57 | ||
86 | 58 | ||
87 | static void | 59 | static void |
88 | end () | 60 | custom_shutdown (void *cls) |
89 | { | 61 | { |
90 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
91 | "Stopping peers\n"); | ||
92 | |||
93 | if (send_task != NULL) | ||
94 | { | ||
95 | GNUNET_SCHEDULER_cancel (send_task); | ||
96 | send_task = NULL; | ||
97 | } | ||
98 | |||
99 | if (die_task != NULL) | ||
100 | { | ||
101 | GNUNET_SCHEDULER_cancel (die_task); | ||
102 | die_task = NULL; | ||
103 | } | ||
104 | |||
105 | if (th != NULL) | 62 | if (th != NULL) |
106 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | ||
107 | th = NULL; | ||
108 | |||
109 | if (NULL != p1) | ||
110 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
111 | p1 = NULL; | ||
112 | if (NULL != p2) | ||
113 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
114 | p2 = NULL; | ||
115 | |||
116 | if (NULL != pmc_p1) | ||
117 | { | 63 | { |
118 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); | ||
119 | pmc_p1 = NULL; | ||
120 | } | ||
121 | if (NULL != pmc_p2) | ||
122 | { | ||
123 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); | ||
124 | pmc_p2 = NULL; | ||
125 | } | ||
126 | |||
127 | ok = 0; | ||
128 | } | ||
129 | |||
130 | |||
131 | static void | ||
132 | end_badly (void *cls) | ||
133 | { | ||
134 | die_task = NULL; | ||
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fail! Stopping peers\n"); | ||
136 | |||
137 | if (send_task != NULL) | ||
138 | { | ||
139 | GNUNET_SCHEDULER_cancel (send_task); | ||
140 | send_task = NULL; | ||
141 | } | ||
142 | |||
143 | if (cc != NULL) | ||
144 | { | ||
145 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | ||
146 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); | ||
147 | cc = NULL; | ||
148 | } | ||
149 | |||
150 | if (th != NULL) | ||
151 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 64 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
152 | else | 65 | th = NULL; |
153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | 66 | } |
154 | |||
155 | if (s_started == GNUNET_NO) | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were not started \n")); | ||
157 | else | ||
158 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peers were started \n")); | ||
159 | |||
160 | if (s_connected == GNUNET_NO) | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not connected\n")); | ||
162 | else | ||
163 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were connected\n")); | ||
164 | |||
165 | if (s_sending == GNUNET_NO) | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were not ready to send data\n")); | ||
167 | else | ||
168 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer were ready to send data\n")); | ||
169 | |||
170 | th = NULL; | ||
171 | |||
172 | if (NULL != pmc_p1) | 67 | if (NULL != pmc_p1) |
173 | { | 68 | { |
174 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); | 69 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); |
@@ -179,208 +74,84 @@ end_badly (void *cls) | |||
179 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); | 74 | GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); |
180 | pmc_p2 = NULL; | 75 | pmc_p2 = NULL; |
181 | } | 76 | } |
182 | |||
183 | if (p1 != NULL) | ||
184 | GNUNET_TRANSPORT_TESTING_stop_peer (p1); | ||
185 | else | ||
186 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 1 was not started\n")); | ||
187 | if (p2 != NULL) | ||
188 | GNUNET_TRANSPORT_TESTING_stop_peer (p2); | ||
189 | else | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Peer 2 was not started\n")); | ||
191 | |||
192 | ok = GNUNET_SYSERR; | ||
193 | } | 77 | } |
194 | 78 | ||
195 | 79 | ||
196 | static void | 80 | static void |
197 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 81 | notify_receive (void *cls, |
82 | struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, | ||
83 | const struct GNUNET_PeerIdentity *sender, | ||
198 | const struct GNUNET_MessageHeader *message) | 84 | const struct GNUNET_MessageHeader *message) |
199 | { | 85 | { |
200 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 86 | char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); |
201 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | 87 | |
202 | 88 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | |
203 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | 89 | "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", |
204 | t = p1; | 90 | receiver->no, |
205 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | 91 | ps, |
206 | t = p2; | 92 | ntohs (message->type), |
207 | GNUNET_assert (t != NULL); | 93 | ntohs (message->size), |
208 | 94 | GNUNET_i2s (sender)); | |
209 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
210 | |||
211 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
212 | "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n", | ||
213 | p->no, ps, ntohs (message->type), ntohs (message->size), t->no, | ||
214 | GNUNET_i2s (&t->id)); | ||
215 | GNUNET_free (ps); | 95 | GNUNET_free (ps); |
216 | } | 96 | } |
217 | 97 | ||
218 | 98 | ||
219 | static size_t | ||
220 | notify_ready (void *cls, size_t size, void *buf) | ||
221 | { | ||
222 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | ||
223 | struct GNUNET_MessageHeader *hdr; | ||
224 | |||
225 | th = NULL; | ||
226 | |||
227 | if (buf == NULL) | ||
228 | { | ||
229 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
230 | "Timeout occurred while waiting for transmit_ready\n"); | ||
231 | if (NULL != die_task) | ||
232 | GNUNET_SCHEDULER_cancel (die_task); | ||
233 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
234 | ok = 42; | ||
235 | return 0; | ||
236 | } | ||
237 | |||
238 | GNUNET_assert (size >= TEST_MESSAGE_SIZE); | ||
239 | memset (buf, '\0', TEST_MESSAGE_SIZE); | ||
240 | hdr = buf; | ||
241 | hdr->size = htons (TEST_MESSAGE_SIZE); | ||
242 | hdr->type = htons (TEST_MESSAGE_TYPE); | ||
243 | |||
244 | { | ||
245 | char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id)); | ||
246 | |||
247 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
248 | "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n", | ||
249 | p2->no, | ||
250 | ps, | ||
251 | ntohs (hdr->type), | ||
252 | ntohs (hdr->size), | ||
253 | p->no, | ||
254 | GNUNET_i2s (&p->id)); | ||
255 | GNUNET_free (ps); | ||
256 | } | ||
257 | |||
258 | return TEST_MESSAGE_SIZE; | ||
259 | } | ||
260 | |||
261 | |||
262 | static void | 99 | static void |
263 | sendtask (void *cls) | 100 | sendtask (void *cls) |
264 | { | 101 | { |
265 | send_task = NULL; | 102 | /* intentionally empty */ |
266 | char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
267 | |||
268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
269 | "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", | ||
270 | p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s); | ||
271 | GNUNET_free (receiver_s); | ||
272 | s_sending = GNUNET_YES; | ||
273 | th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, TEST_MESSAGE_SIZE, | ||
274 | TIMEOUT_TRANSMIT, ¬ify_ready, | ||
275 | p1); | ||
276 | } | 103 | } |
277 | 104 | ||
278 | 105 | ||
279 | static void | 106 | static void |
280 | done () | 107 | check_done () |
281 | { | 108 | { |
282 | if ((GNUNET_YES == p1_c) && (GNUNET_YES == p2_c) && p1_c_notify && p2_c_notify) | 109 | if ( (GNUNET_YES == p1_c) && |
110 | (GNUNET_YES == p2_c) && | ||
111 | p1_c_notify && | ||
112 | p2_c_notify) | ||
283 | { | 113 | { |
284 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Both peers state to be connected\n"); | 114 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
285 | ok = 0; | 115 | "Both peers state to be connected\n"); |
286 | end(); | 116 | ccc->global_ret = GNUNET_OK; |
117 | GNUNET_SCHEDULER_shutdown (); | ||
287 | } | 118 | } |
288 | } | 119 | } |
289 | 120 | ||
290 | 121 | ||
291 | static void | 122 | static void |
292 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 123 | notify_connect (void *cls, |
124 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
125 | const struct GNUNET_PeerIdentity *other) | ||
293 | { | 126 | { |
294 | static int c; | 127 | GNUNET_TRANSPORT_TESTING_log_connect (cls, |
295 | 128 | me, | |
296 | c++; | 129 | other); |
297 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 130 | if (0 == memcmp (other, &ccc->p[0]->id, sizeof (struct GNUNET_PeerIdentity))) |
298 | struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; | ||
299 | |||
300 | if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) | ||
301 | { | 131 | { |
302 | p1_c_notify = GNUNET_YES; | 132 | p1_c_notify = GNUNET_YES; |
303 | t = p1; | ||
304 | } | 133 | } |
305 | if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity))) | 134 | if (0 == memcmp (other, &ccc->p[1]->id, sizeof (struct GNUNET_PeerIdentity))) |
306 | { | 135 | { |
307 | p2_c_notify = GNUNET_YES; | 136 | p2_c_notify = GNUNET_YES; |
308 | t = p2; | ||
309 | } | 137 | } |
310 | GNUNET_assert (t != NULL); | 138 | check_done (); |
311 | |||
312 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | ||
313 | |||
314 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
315 | "Peer %u (`%4s'): peer %u (`%s') connected to me!\n", p->no, ps, | ||
316 | t->no, GNUNET_i2s (peer)); | ||
317 | if (p1_c_notify && p2_c_notify) | ||
318 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
319 | GNUNET_free (ps); | ||
320 | } | 139 | } |
321 | 140 | ||
322 | 141 | ||
323 | static void | 142 | static void |
324 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 143 | notify_disconnect (void *cls, |
144 | struct GNUNET_TRANSPORT_TESTING_PeerContext *me, | ||
145 | const struct GNUNET_PeerIdentity *other) | ||
325 | { | 146 | { |
326 | struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; | 147 | GNUNET_TRANSPORT_TESTING_log_disconnect (cls, |
327 | char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); | 148 | me, |
328 | 149 | other); | |
329 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 150 | if (NULL != th) |
330 | "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, | 151 | { |
331 | GNUNET_i2s (peer)); | ||
332 | |||
333 | GNUNET_free (ps); | ||
334 | |||
335 | if (th != NULL) | ||
336 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); | 152 | GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); |
337 | th = NULL; | 153 | th = NULL; |
338 | } | 154 | } |
339 | |||
340 | |||
341 | static void | ||
342 | testing_connect_cb (void *cls) | ||
343 | { | ||
344 | cc = NULL; | ||
345 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
346 | |||
347 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
348 | "Peers connected: %u (%s) <-> %u (%s)\n", | ||
349 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
350 | GNUNET_free (p1_c); | ||
351 | |||
352 | s_connected = GNUNET_YES; | ||
353 | send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); | ||
354 | } | ||
355 | |||
356 | |||
357 | static void | ||
358 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | ||
359 | { | ||
360 | static int started; | ||
361 | |||
362 | started++; | ||
363 | |||
364 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
365 | "Peer %u (`%s') started\n", p->no, | ||
366 | GNUNET_i2s (&p->id)); | ||
367 | |||
368 | if (started != 2) | ||
369 | return; | ||
370 | else | ||
371 | s_started = GNUNET_YES; | ||
372 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
373 | |||
374 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
375 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
376 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
377 | GNUNET_free (sender_c); | ||
378 | |||
379 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, | ||
380 | p2, | ||
381 | &testing_connect_cb, | ||
382 | NULL); | ||
383 | |||
384 | } | 155 | } |
385 | 156 | ||
386 | 157 | ||
@@ -391,7 +162,7 @@ monitor1_cb (void *cls, | |||
391 | enum GNUNET_TRANSPORT_PeerState state, | 162 | enum GNUNET_TRANSPORT_PeerState state, |
392 | struct GNUNET_TIME_Absolute state_timeout) | 163 | struct GNUNET_TIME_Absolute state_timeout) |
393 | { | 164 | { |
394 | if ((NULL == address) || (NULL == p1)) | 165 | if ((NULL == address) || (NULL == ccc->p[0])) |
395 | return; | 166 | return; |
396 | 167 | ||
397 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 168 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -399,14 +170,13 @@ monitor1_cb (void *cls, | |||
399 | GNUNET_i2s (&address->peer), | 170 | GNUNET_i2s (&address->peer), |
400 | GNUNET_TRANSPORT_ps2s (state), | 171 | GNUNET_TRANSPORT_ps2s (state), |
401 | GNUNET_STRINGS_absolute_time_to_string(state_timeout)); | 172 | GNUNET_STRINGS_absolute_time_to_string(state_timeout)); |
402 | if ((0 == memcmp (&address->peer, &p2->id, sizeof (p2->id)) && | 173 | if ( (0 == memcmp (&address->peer, &ccc->p[1]->id, sizeof (ccc->p[1]->id))) && |
403 | (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && | 174 | (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && |
404 | GNUNET_NO == p1_c) ) | 175 | (GNUNET_NO == p1_c) ) |
405 | { | 176 | { |
406 | p1_c = GNUNET_YES; | 177 | p1_c = GNUNET_YES; |
407 | GNUNET_SCHEDULER_add_now (&done, NULL); | 178 | check_done (); |
408 | } | 179 | } |
409 | |||
410 | } | 180 | } |
411 | 181 | ||
412 | 182 | ||
@@ -417,7 +187,7 @@ monitor2_cb (void *cls, | |||
417 | enum GNUNET_TRANSPORT_PeerState state, | 187 | enum GNUNET_TRANSPORT_PeerState state, |
418 | struct GNUNET_TIME_Absolute state_timeout) | 188 | struct GNUNET_TIME_Absolute state_timeout) |
419 | { | 189 | { |
420 | if ((NULL == address) || (NULL == p2)) | 190 | if ((NULL == address) || (NULL == ccc->p[1])) |
421 | return; | 191 | return; |
422 | 192 | ||
423 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 193 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -425,124 +195,53 @@ monitor2_cb (void *cls, | |||
425 | GNUNET_i2s (&address->peer), | 195 | GNUNET_i2s (&address->peer), |
426 | GNUNET_TRANSPORT_ps2s (state), | 196 | GNUNET_TRANSPORT_ps2s (state), |
427 | GNUNET_STRINGS_absolute_time_to_string(state_timeout)); | 197 | GNUNET_STRINGS_absolute_time_to_string(state_timeout)); |
428 | if ((0 == memcmp (&address->peer, &p1->id, sizeof (p1->id)) && | 198 | if ( (0 == memcmp (&address->peer, &ccc->p[0]->id, sizeof (ccc->p[0]->id))) && |
429 | (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && | 199 | (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && |
430 | GNUNET_NO == p2_c) ) | 200 | (GNUNET_NO == p2_c) ) |
431 | { | 201 | { |
432 | p2_c = GNUNET_YES; | 202 | p2_c = GNUNET_YES; |
433 | GNUNET_SCHEDULER_add_now (&done, NULL); | 203 | check_done (); |
434 | } | 204 | } |
435 | } | 205 | } |
436 | 206 | ||
437 | 207 | ||
438 | |||
439 | static void | 208 | static void |
440 | run (void *cls, char *const *args, const char *cfgfile, | 209 | start_monitors (void *cls) |
441 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
442 | { | 210 | { |
443 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | 211 | pmc_p1 = GNUNET_TRANSPORT_monitor_peers (ccc->p[0]->cfg, |
444 | |||
445 | s_started = GNUNET_NO; | ||
446 | s_connected = GNUNET_NO; | ||
447 | s_sending = GNUNET_NO; | ||
448 | |||
449 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
450 | cfg_file_p1, | ||
451 | 1, | ||
452 | ¬ify_receive, | ||
453 | ¬ify_connect, | ||
454 | ¬ify_disconnect, | ||
455 | &start_cb, | ||
456 | NULL); | ||
457 | pmc_p1 = GNUNET_TRANSPORT_monitor_peers (p1->cfg, | ||
458 | NULL, | 212 | NULL, |
459 | GNUNET_NO, | 213 | GNUNET_NO, |
460 | &monitor1_cb, | 214 | &monitor1_cb, |
461 | NULL); | 215 | NULL); |
462 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n"); | 216 | pmc_p2 = GNUNET_TRANSPORT_monitor_peers (ccc->p[1]->cfg, |
463 | |||
464 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
465 | cfg_file_p2, | ||
466 | 2, | ||
467 | ¬ify_receive, | ||
468 | ¬ify_connect, | ||
469 | ¬ify_disconnect, | ||
470 | &start_cb, | ||
471 | NULL); | ||
472 | pmc_p2 = GNUNET_TRANSPORT_monitor_peers (p2->cfg, | ||
473 | NULL, | 217 | NULL, |
474 | GNUNET_NO, | 218 | GNUNET_NO, |
475 | &monitor2_cb, | 219 | &monitor2_cb, |
476 | NULL); | 220 | NULL); |
477 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer 1 started\n"); | ||
478 | if ((p1 == NULL) || (p2 == NULL)) | ||
479 | { | ||
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n"); | ||
481 | if (die_task != NULL) | ||
482 | GNUNET_SCHEDULER_cancel (die_task); | ||
483 | die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
484 | return; | ||
485 | } | ||
486 | } | ||
487 | |||
488 | |||
489 | static int | ||
490 | check () | ||
491 | { | ||
492 | static char *const argv[] = { "test-transport-api", | ||
493 | "-c", | ||
494 | "test_transport_api_data.conf", | ||
495 | NULL | ||
496 | }; | ||
497 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
498 | GNUNET_GETOPT_OPTION_END | ||
499 | }; | ||
500 | |||
501 | send_task = NULL; | ||
502 | |||
503 | ok = 1; | ||
504 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name, | ||
505 | "nohelp", options, &run, &ok); | ||
506 | |||
507 | return ok; | ||
508 | } | 221 | } |
509 | 222 | ||
510 | 223 | ||
511 | int | 224 | int |
512 | main (int argc, char *argv[]) | 225 | main (int argc, char *argv[]) |
513 | { | 226 | { |
514 | int ret; | 227 | struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { |
515 | 228 | .pre_connect_task = &start_monitors, | |
516 | ok = 1; | 229 | .connect_continuation = &sendtask, |
517 | 230 | .config_file = "test_transport_api_data.conf", | |
518 | test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]); | 231 | .rec = ¬ify_receive, |
519 | test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__); | 232 | .nc = ¬ify_connect, |
520 | test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0], | 233 | .nd = ¬ify_disconnect, |
521 | test_source); | 234 | .shutdown_task = &custom_shutdown, |
522 | 235 | .timeout = TIMEOUT | |
523 | GNUNET_log_setup (test_name, | 236 | }; |
524 | "WARNING", | ||
525 | NULL); | ||
526 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
527 | |||
528 | cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1); | ||
529 | cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2); | ||
530 | |||
531 | ret = check (); | ||
532 | |||
533 | GNUNET_free (cfg_file_p1); | ||
534 | GNUNET_free (cfg_file_p2); | ||
535 | |||
536 | GNUNET_free (test_source); | ||
537 | GNUNET_free (test_plugin); | ||
538 | GNUNET_free (test_name); | ||
539 | |||
540 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
541 | 237 | ||
542 | if (0 != ret) | 238 | ccc = &my_ccc; |
543 | return ret; | 239 | if (GNUNET_OK != |
544 | else | 240 | GNUNET_TRANSPORT_TESTING_main (2, |
545 | return ok; | 241 | &GNUNET_TRANSPORT_TESTING_connect_check, |
242 | ccc)) | ||
243 | return 1; | ||
244 | return 0; | ||
546 | } | 245 | } |
547 | 246 | ||
548 | /* end of test_transport_api_monitor_peers.c */ | 247 | /* end of test_transport_api_monitor_peers.c */ |