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