aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/Makefile.am22
-rw-r--r--src/transport/test_transport_api.c40
-rw-r--r--src/transport/test_transport_api_bidirectional_connect.c448
-rw-r--r--src/transport/test_transport_api_bidirectional_connect_peer1.conf43
-rw-r--r--src/transport/test_transport_api_bidirectional_connect_peer2.conf43
-rw-r--r--src/transport/test_transport_api_blacklisting.c450
-rw-r--r--src/transport/test_transport_api_blacklisting_tcp_peer1.conf9
-rw-r--r--src/transport/test_transport_api_blacklisting_tcp_peer2.conf9
-rw-r--r--src/transport/test_transport_api_slow_ats_peer2.conf2
-rw-r--r--src/transport/transport-testing-main.c69
-rw-r--r--src/transport/transport-testing.c45
-rw-r--r--src/transport/transport-testing.h23
12 files changed, 265 insertions, 938 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 34fbe9caf..2c6c7dfd8 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -445,9 +445,8 @@ check_PROGRAMS = \
445 $(HTTPS_CLIENT_PLUGIN_TEST) \ 445 $(HTTPS_CLIENT_PLUGIN_TEST) \
446 $(HTTP_SERVER_PLUGIN_TEST) \ 446 $(HTTP_SERVER_PLUGIN_TEST) \
447 $(HTTPS_SERVER_PLUGIN_TEST) \ 447 $(HTTPS_SERVER_PLUGIN_TEST) \
448 test_transport_api_blacklisting \ 448 test_transport_api_blacklisting_tcp \
449 test_transport_api_disconnect_tcp \ 449 test_transport_api_disconnect_tcp \
450 test_transport_api_bidirectional_connect \
451 test_transport_api_tcp \ 450 test_transport_api_tcp \
452 test_transport_api_restart_1peer \ 451 test_transport_api_restart_1peer \
453 test_transport_api_timeout_tcp \ 452 test_transport_api_timeout_tcp \
@@ -516,9 +515,8 @@ TESTS = \
516 $(UNIX_TEST) \ 515 $(UNIX_TEST) \
517 $(WLAN_PLUGIN_TEST) \ 516 $(WLAN_PLUGIN_TEST) \
518 $(BT_PLUGIN_TEST) \ 517 $(BT_PLUGIN_TEST) \
519 test_transport_api_blacklisting \ 518 test_transport_api_blacklisting_tcp \
520 test_transport_api_disconnect_tcp \ 519 test_transport_api_disconnect_tcp \
521 test_transport_api_bidirectional_connect \
522 test_transport_api_tcp \ 520 test_transport_api_tcp \
523 test_transport_api_restart_1peer \ 521 test_transport_api_restart_1peer \
524 test_transport_api_restart_2peers \ 522 test_transport_api_restart_2peers \
@@ -592,9 +590,9 @@ test_transport_testing_restart_LDADD = \
592 $(top_builddir)/src/hello/libgnunethello.la \ 590 $(top_builddir)/src/hello/libgnunethello.la \
593 libgnunettransporttesting.la 591 libgnunettransporttesting.la
594 592
595test_transport_api_blacklisting_SOURCES = \ 593test_transport_api_blacklisting_tcp_SOURCES = \
596 test_transport_api_blacklisting.c 594 test_transport_api_blacklisting.c
597test_transport_api_blacklisting_LDADD = \ 595test_transport_api_blacklisting_tcp_LDADD = \
598 libgnunettransport.la \ 596 libgnunettransport.la \
599 $(top_builddir)/src/hello/libgnunethello.la \ 597 $(top_builddir)/src/hello/libgnunethello.la \
600 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 598 $(top_builddir)/src/statistics/libgnunetstatistics.la \
@@ -763,14 +761,6 @@ test_transport_api_tcp_LDADD = \
763 $(top_builddir)/src/util/libgnunetutil.la \ 761 $(top_builddir)/src/util/libgnunetutil.la \
764 libgnunettransporttesting.la 762 libgnunettransporttesting.la
765 763
766test_transport_api_bidirectional_connect_SOURCES = \
767 test_transport_api_bidirectional_connect.c
768test_transport_api_bidirectional_connect_LDADD = \
769 libgnunettransport.la \
770 $(top_builddir)/src/hello/libgnunethello.la \
771 $(top_builddir)/src/util/libgnunetutil.la \
772 libgnunettransporttesting.la
773
774test_transport_api_restart_1peer_SOURCES = \ 764test_transport_api_restart_1peer_SOURCES = \
775 test_transport_api_restart_1peer.c 765 test_transport_api_restart_1peer.c
776test_transport_api_restart_1peer_LDADD = \ 766test_transport_api_restart_1peer_LDADD = \
@@ -1264,6 +1254,8 @@ test_quota_compliance_wlan_asymmetric_peer2.conf\
1264test_quota_compliance_bluetooth_asymmetric_peer1.conf\ 1254test_quota_compliance_bluetooth_asymmetric_peer1.conf\
1265test_quota_compliance_bluetooth_asymmetric_peer2.conf\ 1255test_quota_compliance_bluetooth_asymmetric_peer2.conf\
1266test_transport_api_data.conf\ 1256test_transport_api_data.conf\
1257test_transport_api_blacklisting_tcp_peer1.conf \
1258test_transport_api_blacklisting_tcp_peer2.conf \
1267test_transport_api_http_peer1.conf\ 1259test_transport_api_http_peer1.conf\
1268test_transport_api_http_peer2.conf\ 1260test_transport_api_http_peer2.conf\
1269test_transport_api_https_peer1.conf\ 1261test_transport_api_https_peer1.conf\
@@ -1286,8 +1278,6 @@ test_transport_api_reliability_wlan_peer1.conf\
1286test_transport_api_reliability_wlan_peer2.conf\ 1278test_transport_api_reliability_wlan_peer2.conf\
1287test_transport_api_reliability_bluetooth_peer1.conf\ 1279test_transport_api_reliability_bluetooth_peer1.conf\
1288test_transport_api_reliability_bluetooth_peer2.conf\ 1280test_transport_api_reliability_bluetooth_peer2.conf\
1289test_transport_api_bidirectional_connect_peer1.conf\
1290test_transport_api_bidirectional_connect_peer2.conf\
1291test_transport_api_manipulation_send_tcp_peer1.conf\ 1281test_transport_api_manipulation_send_tcp_peer1.conf\
1292test_transport_api_manipulation_send_tcp_peer2.conf\ 1282test_transport_api_manipulation_send_tcp_peer2.conf\
1293test_transport_api_manipulation_recv_tcp_peer1.conf\ 1283test_transport_api_manipulation_recv_tcp_peer1.conf\
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index bb10116e2..ad078f582 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -20,6 +20,7 @@
20/** 20/**
21 * @file transport/test_transport_api.c 21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
23 * @author Christian Grothoff
23 * 24 *
24 * This test case serves as a base for tcp, udp, and udp-nat 25 * This test case serves as a base for tcp, udp, and udp-nat
25 * transport test cases. Based on the executable being run 26 * transport test cases. Based on the executable being run
@@ -33,12 +34,12 @@
33/** 34/**
34 * How long until we give up on transmitting the message? 35 * How long until we give up on transmitting the message?
35 */ 36 */
36#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
37 38
38/** 39/**
39 * How long until we give up on transmitting the message? 40 * How long until we give up on transmitting the message?
40 */ 41 */
41#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 42#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
42 43
43#define TEST_MESSAGE_SIZE 2600 44#define TEST_MESSAGE_SIZE 2600
44 45
@@ -58,9 +59,6 @@ custom_shutdown (void *cls)
58 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 59 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
59 th = NULL; 60 th = NULL;
60 } 61 }
61 else
62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
63 "Peers were not ready to send data\n");
64} 62}
65 63
66 64
@@ -148,7 +146,7 @@ sendtask (void *cls)
148 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); 146 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id));
149 147
150 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
151 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n", 149 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n",
152 ccc->p[1]->no, 150 ccc->p[1]->no,
153 GNUNET_i2s (&ccc->p[1]->id), 151 GNUNET_i2s (&ccc->p[1]->id),
154 ccc->p[0]->no, 152 ccc->p[0]->no,
@@ -162,6 +160,7 @@ sendtask (void *cls)
162 TIMEOUT_TRANSMIT, 160 TIMEOUT_TRANSMIT,
163 &notify_ready, 161 &notify_ready,
164 ccc->p[0]); 162 ccc->p[0]);
163 GNUNET_assert (NULL != th);
165} 164}
166 165
167 166
@@ -181,9 +180,16 @@ notify_disconnect (void *cls,
181} 180}
182 181
183 182
184int 183/**
185main (int argc, 184 * Runs the test.
186 char *argv[]) 185 *
186 * @param argv the argv argument from main()
187 * @param bi_directional should we try to establish connections
188 * in both directions simultaneously?
189 */
190static int
191test (char *argv[],
192 int bi_directional)
187{ 193{
188 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 194 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
189 .connect_continuation = &sendtask, 195 .connect_continuation = &sendtask,
@@ -192,7 +198,8 @@ main (int argc,
192 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 198 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
193 .nd = &notify_disconnect, 199 .nd = &notify_disconnect,
194 .shutdown_task = &custom_shutdown, 200 .shutdown_task = &custom_shutdown,
195 .timeout = TIMEOUT 201 .timeout = TIMEOUT,
202 .bi_directional = bi_directional
196 }; 203 };
197 204
198 ccc = &my_ccc; 205 ccc = &my_ccc;
@@ -204,4 +211,17 @@ main (int argc,
204 return 0; 211 return 0;
205} 212}
206 213
214
215int
216main (int argc,
217 char *argv[])
218{
219 if ( (0 != test (argv,
220 GNUNET_NO)) ||
221 (0 != test (argv,
222 GNUNET_YES) ) )
223 return 1;
224 return 0;
225}
226
207/* end of test_transport_api.c */ 227/* end of test_transport_api.c */
diff --git a/src/transport/test_transport_api_bidirectional_connect.c b/src/transport/test_transport_api_bidirectional_connect.c
deleted file mode 100644
index 10b20e21e..000000000
--- a/src/transport/test_transport_api_bidirectional_connect.c
+++ /dev/null
@@ -1,448 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010 GNUnet e.V.
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20/**
21 * @file transport/test_transport_api_bidirectional_connect.c
22 * @brief base test case for transport implementations
23 *
24 * Perform a 3-way handshake connection set up in both directions at
25 * (almost) the same time
26 */
27#include "platform.h"
28#include "gnunet_transport_service.h"
29#include "transport-testing.h"
30
31
32/**
33 * How long until we give up on transmitting the message?
34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
36
37/**
38 * How long until we give up on transmitting the message?
39 */
40#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
41
42#define MTYPE 12345
43
44static char *test_source;
45
46static char *test_plugin;
47
48static char *test_name;
49
50static int ok;
51
52static struct GNUNET_SCHEDULER_Task * die_task;
53
54static struct GNUNET_SCHEDULER_Task * send_task;
55
56static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
57
58static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
59
60static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc1;
61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc2;
62
63static struct GNUNET_TRANSPORT_TransmitHandle *th;
64
65static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
66
67static char *cfg_file_p1;
68
69static char *cfg_file_p2;
70
71
72static void
73end ()
74{
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
76
77 if (send_task != NULL)
78 {
79 GNUNET_SCHEDULER_cancel (send_task);
80 send_task = NULL;
81 }
82
83 if (die_task != NULL)
84 GNUNET_SCHEDULER_cancel (die_task);
85
86 if (NULL != th)
87 {
88 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
89 th = NULL;
90 }
91
92 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
93 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
94}
95
96
97static void
98end_badly (void *cls)
99{
100 die_task = NULL;
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
102 if (send_task != NULL)
103 {
104 GNUNET_SCHEDULER_cancel (send_task);
105 send_task = NULL;
106 }
107
108 if (NULL != cc2)
109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
111 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc2);
112 cc2 = NULL;
113 }
114 if (NULL != cc1)
115 {
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
117 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc1);
118 cc1 = NULL;
119 }
120 if (NULL != th)
121 {
122 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
123 th = NULL;
124 }
125 if (p1 != NULL)
126 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
127 if (p2 != NULL)
128 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
129
130 ok = GNUNET_SYSERR;
131}
132
133
134static void
135notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
136 const struct GNUNET_MessageHeader *message)
137{
138 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
139 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
140
141 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
142 t = p1;
143 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
144 t = p2;
145 GNUNET_assert (t != NULL);
146
147 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
149 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
150 p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
151 GNUNET_i2s (&t->id));
152 GNUNET_free (ps);
153 if ((MTYPE == ntohs (message->type)) &&
154 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
155 {
156 ok = 0;
157 end ();
158 }
159 else
160 {
161 GNUNET_break (0);
162 ok = 1;
163 end ();
164 }
165}
166
167
168static size_t
169notify_ready (void *cls, size_t size, void *buf)
170{
171 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
172 struct GNUNET_MessageHeader *hdr;
173
174 th = NULL;
175
176 if (buf == NULL)
177 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
179 "Timeout occurred while waiting for transmit_ready\n");
180 if (NULL != die_task)
181 GNUNET_SCHEDULER_cancel (die_task);
182 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
183 ok = 42;
184 return 0;
185 }
186
187 GNUNET_assert (size >= 256);
188 hdr = buf;
189 hdr->size = htons (sizeof (struct GNUNET_MessageHeader));
190 hdr->type = htons (MTYPE);
191
192 {
193 char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
194
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
196 "Peer %u (`%4s') sending message with type %u and size %u bytes to peer %u (`%4s')\n",
197 p2->no,
198 ps,
199 ntohs (hdr->type),
200 ntohs (hdr->size),
201 p->no,
202 GNUNET_i2s (&p->id));
203 GNUNET_free (ps);
204 }
205
206 return sizeof (struct GNUNET_MessageHeader);
207}
208
209
210static void
211sendtask (void *cls)
212{
213 char *receiver_s;
214
215 send_task = NULL;
216 receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id));
217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
218 "Sending message from peer %u (`%4s') -> peer %u (`%s') !\n",
219 p2->no, GNUNET_i2s (&p2->id), p1->no, receiver_s);
220 GNUNET_free (receiver_s);
221
222 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id, 256,
223 TIMEOUT_TRANSMIT, &notify_ready,
224 p1);
225}
226
227
228static void
229notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer)
230{
231 static int c;
232
233 c++;
234 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
235 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL;
236
237 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
238 t = p1;
239 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
240 t = p2;
241 GNUNET_assert (t != NULL);
242
243 {
244 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
245
246 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
247 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
248 p->no,
249 ps,
250 t->no,
251 GNUNET_i2s (peer));
252 GNUNET_free (ps);
253 }
254}
255
256
257static void
258notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
259{
260 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
261
262 {
263 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
264
265 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
266 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n",
267 p->no,
268 ps,
269 GNUNET_i2s (peer));
270 GNUNET_free (ps);
271 }
272 if (NULL != send_task)
273 {
274 GNUNET_SCHEDULER_cancel(send_task);
275 GNUNET_break (0);
276 send_task = NULL;
277 }
278 if (NULL != th)
279 {
280 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
281 th = NULL;
282 }
283}
284
285
286static void
287testing_connect_cb (void *cls)
288{
289 static int connected = GNUNET_NO;
290
291 if ((cls == cc1) && (NULL != cc2))
292 {
293 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc2);
294 }
295 if ((cls == cc2) && (NULL != cc1))
296 {
297 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc1);
298 }
299 cc1 = NULL;
300 cc2 = NULL;
301
302 if (connected > 0)
303 return;
304 connected++;
305
306 {
307 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
308
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "Peers connected: %u (%s) <-> %u (%s)\n",
311 p1->no,
312 p1_c,
313 p2->no,
314 GNUNET_i2s (&p2->id));
315 GNUNET_free (p1_c);
316 }
317 send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
318 &sendtask,
319 NULL);
320}
321
322
323static void
324start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls)
325{
326 static int started;
327
328 started++;
329
330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
331 "Peer %u (`%s') started\n",
332 p->no,
333 GNUNET_i2s (&p->id));
334
335 if (started != 2)
336 return;
337
338 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
339
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
341 "Test tries to connect peer %u (`%s') <-> peer %u (`%s')\n",
342 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
343 GNUNET_free (sender_c);
344 cc1 =
345 GNUNET_TRANSPORT_TESTING_connect_peers (p2,
346 p1,
347 &testing_connect_cb,
348 cc1);
349 cc2 =
350 GNUNET_TRANSPORT_TESTING_connect_peers (p1,
351 p2,
352 &testing_connect_cb,
353 cc2);
354}
355
356
357static void
358run (void *cls, char *const *args, const char *cfgfile,
359 const struct GNUNET_CONFIGURATION_Handle *cfg)
360{
361 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
362
363 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
364 cfg_file_p1, 1,
365 &notify_receive,
366 &notify_connect,
367 &notify_disconnect,
368 &start_cb,
369 NULL);
370
371 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
372 cfg_file_p2,
373 2,
374 &notify_receive,
375 &notify_connect,
376 &notify_disconnect,
377 &start_cb,
378 NULL);
379
380 if ((p1 == NULL) || (p2 == NULL))
381 {
382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Fail! Could not start peers!\n");
383 if (die_task != NULL)
384 GNUNET_SCHEDULER_cancel (die_task);
385 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
386 return;
387 }
388}
389
390
391static int
392check ()
393{
394 static char *const argv[] = { "test-transport-api",
395 "-c",
396 "test_transport_api_data.conf",
397 NULL
398 };
399 static struct GNUNET_GETOPT_CommandLineOption options[] = {
400 GNUNET_GETOPT_OPTION_END
401 };
402
403#if WRITECONFIG
404 setTransportOptions ("test_transport_api_data.conf");
405#endif
406 send_task = NULL;
407
408 ok = 1;
409 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, test_name,
410 "nohelp", options, &run, &ok);
411
412 return ok;
413}
414
415int
416main (int argc, char *argv[])
417{
418 int ret;
419
420 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv[0]);
421 GNUNET_log_setup (test_name,
422 "WARNING",
423 NULL);
424
425 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (__FILE__);
426 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv[0],
427 test_source);
428
429 tth = GNUNET_TRANSPORT_TESTING_init ();
430
431 cfg_file_p1 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 1);
432 cfg_file_p2 = GNUNET_TRANSPORT_TESTING_get_config_name (argv[0], 2);
433
434 ret = check ();
435
436 GNUNET_free (cfg_file_p1);
437 GNUNET_free (cfg_file_p2);
438
439 GNUNET_free (test_source);
440 GNUNET_free (test_plugin);
441 GNUNET_free (test_name);
442
443 GNUNET_TRANSPORT_TESTING_done (tth);
444
445 return ret;
446}
447
448/* end of test_transport_api_bidirectional_connect.c */
diff --git a/src/transport/test_transport_api_bidirectional_connect_peer1.conf b/src/transport/test_transport_api_bidirectional_connect_peer1.conf
deleted file mode 100644
index dff464e45..000000000
--- a/src/transport/test_transport_api_bidirectional_connect_peer1.conf
+++ /dev/null
@@ -1,43 +0,0 @@
1@INLINE@ template_cfg_peer1.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
4
5[arm]
6PORT = 12000
7UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-arm.sock
8
9[statistics]
10PORT = 12001
11UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-statistics.sock
12
13[resolver]
14PORT = 12002
15UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-resolver.sock
16
17[peerinfo]
18PORT = 12003
19UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-peerinfo.sock
20
21[transport]
22PORT = 12004
23UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p1-service-transport.sock
24
25[transport-tcp]
26PORT = 12005
27TIMEOUT = 5 s
28
29[transport-udp]
30PORT = 12006
31TIMEOUT = 5 s
32
33[transport-unix]
34PORT = 12007
35TIMEOUT = 5 s
36
37[transport-http]
38PORT = 12008
39TIMEOUT = 5 s
40
41[transport-https]
42PORT = 12009
43TIMEOUT = 5 s
diff --git a/src/transport/test_transport_api_bidirectional_connect_peer2.conf b/src/transport/test_transport_api_bidirectional_connect_peer2.conf
deleted file mode 100644
index 245175788..000000000
--- a/src/transport/test_transport_api_bidirectional_connect_peer2.conf
+++ /dev/null
@@ -1,43 +0,0 @@
1@INLINE@ template_cfg_peer2.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
4
5[arm]
6PORT = 12010
7UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-arm.sock
8
9[statistics]
10PORT = 12011
11UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-statistics.sock
12
13[resolver]
14PORT = 12012
15UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-resolver.sock
16
17[peerinfo]
18PORT = 12013
19UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-peerinfo.sock
20
21[transport]
22PORT = 12014
23UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-p2-service-transport.sock
24
25[transport-tcp]
26PORT = 12015
27TIMEOUT = 5 s
28
29[transport-udp]
30PORT = 12016
31TIMEOUT = 5 s
32
33[transport-unix]
34PORT = 12017
35TIMEOUT = 5 s
36
37[transport-http]
38PORT = 12018
39TIMEOUT = 5 s
40
41[transport-https]
42PORT = 12019
43TIMEOUT = 5 s
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c
index 8dce4d48d..72f8a71a3 100644
--- a/src/transport/test_transport_api_blacklisting.c
+++ b/src/transport/test_transport_api_blacklisting.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, 2011 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2011, 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
@@ -19,242 +19,127 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file transport/transport_api_blacklisting.c 22 * @file transport/test_transport_api_blacklisting.c
23 * @brief test for the blacklisting API 23 * @brief test for the blacklisting API
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 * 25 * @author Christian Grothoff
26 */ 26 */
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_transport_service.h" 28#include "gnunet_transport_service.h"
29#include "transport-testing.h" 29#include "transport-testing.h"
30 30
31static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
32
33static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
34
35static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc;
36
37static struct GNUNET_TRANSPORT_TransmitHandle *th;
38
39static struct GNUNET_TRANSPORT_TESTING_Handle *tth;
40
41/**
42 * How long until we give up on transmitting the message?
43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
45
46/**
47 * How long until we give up on transmitting the message?
48 */
49#define TIMEOUT_TRANSMIT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
50 32
51#define TEST_MESSAGE_SIZE 2600 33#define TEST_MESSAGE_SIZE 2600
52 34
53#define TEST_MESSAGE_TYPE 12345 35#define TEST_MESSAGE_TYPE 12345
54 36
55 37
56static int ok; 38static struct GNUNET_TRANSPORT_TransmitHandle *th;
39
40static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
41
57static int connected; 42static int connected;
58static int blacklist_request_p1;
59static int blacklist_request_p2;
60 43
61static struct GNUNET_TRANSPORT_Blacklist * blacklist_p1; 44static int blacklist_request_p1;
62 45
63static struct GNUNET_TRANSPORT_Blacklist * blacklist_p2; 46static int blacklist_request_p2;
64 47
65static struct GNUNET_SCHEDULER_Task * die_task; 48static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1;
66 49
67static struct GNUNET_SCHEDULER_Task * send_task; 50static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2;
68 51
69static struct GNUNET_SCHEDULER_Task * shutdown_task; 52static struct GNUNET_SCHEDULER_Task *send_task;
70 53
71#if VERBOSE 54static struct GNUNET_SCHEDULER_Task *shutdown_task;
72#define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
73#else
74#define OKPP do { ok++; } while (0)
75#endif
76 55
77 56
78static void 57static void
79end (void *cls) 58end (void *cls)
80{ 59{
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); 60 shutdown_task = NULL;
82 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 if (send_task != NULL) 62 "Stopping\n");
84 GNUNET_SCHEDULER_cancel (send_task); 63 if ((GNUNET_YES == blacklist_request_p1) &&
85 64 (GNUNET_YES == blacklist_request_p2) &&
86 if (die_task != NULL) 65 (GNUNET_NO == connected) )
87 {
88 GNUNET_SCHEDULER_cancel (die_task);
89 die_task = NULL;
90 }
91
92 if (cc != NULL)
93 {
94 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
95 cc = NULL;
96 }
97
98 if (th != NULL)
99 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
100 th = NULL;
101
102 if (blacklist_p1 != NULL)
103 {
104 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
105 blacklist_p1 = NULL;
106 }
107
108 if (blacklist_p2 != NULL)
109 {
110 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
111 blacklist_p2 = NULL;
112 }
113
114 if (p1 != NULL)
115 {
116 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
117 p1 = NULL;
118 }
119 if (p2 != NULL)
120 {
121 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
122 p2 = NULL;
123 }
124
125 if ((blacklist_request_p1 == GNUNET_YES) &&
126 (blacklist_request_p2 == GNUNET_YES) &&
127 (connected == GNUNET_NO))
128 { 66 {
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Peers were not connected, success\n")); 67 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 ok = 0; 68 "Peers were never connected, success\n");
69 ccc->global_ret = GNUNET_OK;
131 } 70 }
132 else 71 else
133 { 72 {
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Peers were not connected, fail\n")); 73 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 ok = 1; 74 "Peers were not connected, fail\n");
75 ccc->global_ret = GNUNET_SYSERR;
136 } 76 }
77 GNUNET_SCHEDULER_shutdown ();
137} 78}
138 79
139 80
140static void 81static void
141end_badly (void *cls) 82custom_shutdown (void *cls)
142{ 83{
143 if (send_task != NULL) 84 if (NULL != send_task)
144 { 85 {
145 GNUNET_SCHEDULER_cancel (send_task); 86 GNUNET_SCHEDULER_cancel (send_task);
146 send_task = NULL; 87 send_task = NULL;
147 } 88 }
148 89 if (NULL != shutdown_task)
149 if (shutdown_task != NULL)
150 { 90 {
151 GNUNET_SCHEDULER_cancel (shutdown_task); 91 GNUNET_SCHEDULER_cancel (shutdown_task);
152 shutdown_task = NULL; 92 shutdown_task = NULL;
153 } 93 }
154 94 if (NULL != th)
155 if (cc != NULL)
156 { 95 {
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n"));
158 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
159 cc = NULL;
160 }
161
162 if (th != NULL)
163 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 96 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
164 th = NULL; 97 th = NULL;
165 98 }
166 if (blacklist_p1 != NULL) 99 if (NULL != blacklist_p1)
100 {
167 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1); 101 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
168 102 blacklist_p1 = NULL;
169 if (blacklist_p2 != NULL) 103 }
104 if (NULL != blacklist_p2)
105 {
170 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2); 106 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
171 107 blacklist_p2 = NULL;
172 if (p1 != NULL) 108 }
173 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
174 if (p2 != NULL)
175 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
176
177 ok = GNUNET_SYSERR;
178} 109}
179 110
180 111
181static void 112static void
182notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 113notify_receive (void *cls,
114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
115 const struct GNUNET_PeerIdentity *sender,
183 const struct GNUNET_MessageHeader *message) 116 const struct GNUNET_MessageHeader *message)
184{ 117{
185 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
186 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; 119 "Unexpectedly even received the message despite blacklist\n");
187 120 GNUNET_SCHEDULER_shutdown ();
188 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity)))
189 t = p1;
190 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
191 t = p2;
192 GNUNET_assert (t != NULL);
193
194 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
195
196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Peer %u (`%4s') received message of type %d and size %u size from peer %u (`%4s')!\n",
198 p->no, ps, ntohs (message->type), ntohs (message->size), t->no,
199 GNUNET_i2s (&t->id));
200 GNUNET_free (ps);
201
202 if ((TEST_MESSAGE_TYPE == ntohs (message->type)) &&
203 (TEST_MESSAGE_SIZE == ntohs (message->size)))
204 {
205 ok = 0;
206 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
207 }
208 else
209 {
210 GNUNET_break (0);
211 ok = 1;
212 shutdown_task = GNUNET_SCHEDULER_add_now(&end, NULL);
213 }
214} 121}
215 122
216 123
217static size_t 124static size_t
218notify_ready (void *cls, size_t size, void *buf) 125notify_ready (void *cls,
126 size_t size,
127 void *buf)
219{ 128{
220 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
221 struct GNUNET_MessageHeader *hdr; 129 struct GNUNET_MessageHeader *hdr;
222 130
223 th = NULL; 131 th = NULL;
224 132 if (NULL == buf)
225 if (buf == NULL)
226 { 133 {
227 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
228 "Timeout occurred while waiting for transmit_ready\n"); 135 "Timeout occurred while waiting for transmit_ready\n");
229 if (NULL != die_task) 136 GNUNET_SCHEDULER_shutdown ();
230 {
231 GNUNET_SCHEDULER_cancel (die_task);
232 die_task = NULL;
233 }
234 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
235 ok = 42;
236 return 0; 137 return 0;
237 } 138 }
238
239 GNUNET_assert (size >= TEST_MESSAGE_SIZE); 139 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
240 hdr = buf; 140 hdr = buf;
241 hdr->size = htons (TEST_MESSAGE_SIZE); 141 hdr->size = htons (TEST_MESSAGE_SIZE);
242 hdr->type = htons (TEST_MESSAGE_TYPE); 142 hdr->type = htons (TEST_MESSAGE_TYPE);
243
244 {
245 char *ps = GNUNET_strdup (GNUNET_i2s (&p2->id));
246
247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
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; 143 return TEST_MESSAGE_SIZE;
259} 144}
260 145
@@ -262,222 +147,123 @@ notify_ready (void *cls, size_t size, void *buf)
262static void 147static void
263sendtask (void *cls) 148sendtask (void *cls)
264{ 149{
265 send_task = NULL; 150 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
266 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&p1->id)); 151 &ccc->p[0]->id,
267
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
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
273 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, &p1->id,
274 TEST_MESSAGE_SIZE, 152 TEST_MESSAGE_SIZE,
275 TIMEOUT_TRANSMIT, &notify_ready, 153 TIMEOUT,
276 p1); 154 &notify_ready,
155 ccc->p[0]);
277} 156}
278 157
279 158
280static void 159static void
281notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 160notify_connect (void *cls,
161 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
162 const struct GNUNET_PeerIdentity *other)
282{ 163{
283 static int c; 164 GNUNET_TRANSPORT_TESTING_log_connect (cls,
284 165 me,
285 c++; 166 other);
286 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
287 struct GNUNET_TRANSPORT_TESTING_PeerContext *t = NULL; 168 "Peers connected despite blacklist!\n");
288 169 connected = GNUNET_YES; /* this test now failed */
289 connected = GNUNET_YES; 170 GNUNET_SCHEDULER_cancel (shutdown_task);
290 if (0 == memcmp (peer, &p1->id, sizeof (struct GNUNET_PeerIdentity))) 171 end (NULL);
291 t = p1;
292 if (0 == memcmp (peer, &p2->id, sizeof (struct GNUNET_PeerIdentity)))
293 t = p2;
294 GNUNET_assert (t != NULL);
295
296 {
297 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id));
298
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
300 "Peer %u (`%4s'): peer %u (`%s') connected to me!\n",
301 p->no,
302 ps,
303 t->no,
304 GNUNET_i2s (peer));
305 GNUNET_free (ps);
306 }
307} 172}
308 173
309 174
310static void 175static void
311notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 176notify_disconnect (void *cls,
177 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
178 const struct GNUNET_PeerIdentity *other)
312{ 179{
313 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 180 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
314 char *ps = GNUNET_strdup (GNUNET_i2s (&p->id)); 181 me,
315 182 other);
316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 183 if (NULL != th)
317 "Peer %u (`%4s'): peer (`%s') disconnected from me!\n", p->no, ps, 184 {
318 GNUNET_i2s (peer));
319
320 GNUNET_free (ps);
321
322 if (th != NULL)
323 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th); 185 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
324 th = NULL; 186 th = NULL;
325} 187 }
326
327
328static void
329testing_connect_cb (void *cls)
330{
331 cc = NULL;
332 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
333
334 connected = GNUNET_YES;
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n",
336 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
337 GNUNET_free (p1_c);
338
339
340
341 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
342} 188}
343 189
344 190
345static int 191static int
346blacklist_cb (void *cls, 192blacklist_cb (void *cls,
347 const struct 193 const struct GNUNET_PeerIdentity *pid)
348 GNUNET_PeerIdentity * pid)
349{ 194{
350 struct GNUNET_TRANSPORT_TESTING_PeerContext * p = cls; 195 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
351 int res = GNUNET_SYSERR; 196 int res = GNUNET_SYSERR;
352 197
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "Peer %u : Blacklist request for peer `%s'\n", 199 "Peer %u: Blacklist request for peer `%s'\n",
355 p->no, 200 p->no,
356 GNUNET_i2s (pid)); 201 GNUNET_i2s (pid));
357 202
358 if (p == p1) 203 if (p == ccc->p[0])
359 { 204 {
360 blacklist_request_p1 = GNUNET_YES; 205 blacklist_request_p1 = GNUNET_YES;
361 res = GNUNET_OK; 206 res = GNUNET_OK;
362 } 207 }
363 else if (p == p2) 208 if (p == ccc->p[1])
364 { 209 {
365 blacklist_request_p2 = GNUNET_YES; 210 blacklist_request_p2 = GNUNET_YES;
366 res = GNUNET_SYSERR; 211 res = GNUNET_SYSERR;
367 } 212 }
368 213
369 if (((blacklist_request_p2 == GNUNET_YES) && (blacklist_request_p1 == GNUNET_YES)) && (shutdown_task == NULL)) 214 if ( (GNUNET_YES == blacklist_request_p2) &&
215 (GNUNET_YES == blacklist_request_p1) &&
216 (NULL == shutdown_task) )
370 { 217 {
371 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3), &end, NULL); 218 shutdown_task
219 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
220 &end,
221 NULL);
372 } 222 }
373
374 return res; 223 return res;
375} 224}
376 225
377 226
378static void 227static void
379start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) 228start_blacklist (void *cls)
380{ 229{
381 static int started;
382
383 started++;
384
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
386 GNUNET_i2s (&p->id));
387
388 if (started != 2)
389 return;
390
391 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
392
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
394 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 231 "Starting blacklists\n");
395 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); 232 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
396 GNUNET_free (sender_c);
397
398 cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
399 p2,
400 &testing_connect_cb,
401 NULL);
402
403}
404
405
406static void
407run (void *cls, char *const *args, const char *cfgfile,
408 const struct GNUNET_CONFIGURATION_Handle *cfg)
409{
410 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
411 &end_badly,
412 NULL);
413 connected = GNUNET_NO;
414 blacklist_request_p1 = GNUNET_NO;
415 blacklist_request_p2 = GNUNET_NO;
416
417 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
418 "test_transport_api_tcp_peer1.conf", 1,
419 &notify_receive,
420 &notify_connect,
421 &notify_disconnect,
422 &start_cb,
423 NULL);
424
425 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
426 "test_transport_api_tcp_peer2.conf", 2,
427 &notify_receive,
428 &notify_connect,
429 &notify_disconnect,
430 &start_cb,
431 NULL);
432
433 blacklist_p1 = GNUNET_TRANSPORT_blacklist (p1->cfg,
434 &blacklist_cb, 233 &blacklist_cb,
435 p1); 234 ccc->p[0]);
436 235 GNUNET_assert (NULL != blacklist_p1);
437 blacklist_p2 = GNUNET_TRANSPORT_blacklist (p2->cfg, 236 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
438 &blacklist_cb, 237 &blacklist_cb,
439 p2); 238 ccc->p[1]);
440 239 GNUNET_assert (NULL != blacklist_p2);
441 GNUNET_assert (blacklist_p1 != NULL);
442 GNUNET_assert (blacklist_p2 != NULL);
443} 240}
444 241
445 242
446static int 243int
447check () 244main (int argc,
245 char *argv[])
448{ 246{
449 static char *const argv[] = { "test-transport-api-blacklisting", 247 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
450 "-c", 248 .pre_connect_task = &start_blacklist,
451 "test_transport_api_data.conf", 249 .connect_continuation = &sendtask,
452 NULL 250 .config_file = "test_transport_api_data.conf",
251 .rec = &notify_receive,
252 .nc = &notify_connect,
253 .nd = &notify_disconnect,
254 .shutdown_task = &custom_shutdown,
255 .timeout = TIMEOUT,
256 .bi_directional = GNUNET_YES
453 }; 257 };
454 static struct GNUNET_GETOPT_CommandLineOption options[] = {
455 GNUNET_GETOPT_OPTION_END
456 };
457
458 ok = 1;
459 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-transport-api-blacklisting",
460 "nohelp", options, &run, &ok);
461 258
462 return ok; 259 ccc = &my_ccc;
260 if (GNUNET_OK !=
261 GNUNET_TRANSPORT_TESTING_main (2,
262 &GNUNET_TRANSPORT_TESTING_connect_check,
263 ccc))
264 return 1;
265 return 0;
463} 266}
464 267
465int
466main (int argc, char *argv[])
467{
468 int ret;
469
470 GNUNET_log_setup ("test-transport-api-blacklisting",
471 "WARNING",
472 NULL);
473
474 tth = GNUNET_TRANSPORT_TESTING_init ();
475
476 ret = check ();
477
478 GNUNET_TRANSPORT_TESTING_done (tth);
479
480 return ret;
481}
482 268
483/* end of transport_api_blacklisting.c */ 269/* end of transport_api_blacklisting.c */
diff --git a/src/transport/test_transport_api_blacklisting_tcp_peer1.conf b/src/transport/test_transport_api_blacklisting_tcp_peer1.conf
new file mode 100644
index 000000000..4bfe9b6ca
--- /dev/null
+++ b/src/transport/test_transport_api_blacklisting_tcp_peer1.conf
@@ -0,0 +1,9 @@
1@INLINE@ template_cfg_peer1.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p1/
4
5[transport]
6PLUGINS = tcp
7
8#[transport]
9#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_blacklisting_tcp_peer2.conf b/src/transport/test_transport_api_blacklisting_tcp_peer2.conf
new file mode 100644
index 000000000..e68cdbee4
--- /dev/null
+++ b/src/transport/test_transport_api_blacklisting_tcp_peer2.conf
@@ -0,0 +1,9 @@
1@INLINE@ template_cfg_peer2.conf
2[PATHS]
3GNUNET_TEST_HOME = /tmp/test-transport/api-tcp-p2/
4
5[transport]
6PLUGINS = tcp
7
8#[transport]
9#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_slow_ats_peer2.conf b/src/transport/test_transport_api_slow_ats_peer2.conf
index 4895e4c4f..6b67c89d8 100644
--- a/src/transport/test_transport_api_slow_ats_peer2.conf
+++ b/src/transport/test_transport_api_slow_ats_peer2.conf
@@ -6,4 +6,4 @@ GNUNET_TEST_HOME = /tmp/test-transport/api-slow-ats-p2/
6PLUGINS = tcp 6PLUGINS = tcp
7 7
8[ats] 8[ats]
9PREFIX = ./test_delay -t 30 -- 9PREFIX = ./test_delay -t 10 --
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c
index b8dbb9c03..de2ec3d0c 100644
--- a/src/transport/transport-testing-main.c
+++ b/src/transport/transport-testing-main.c
@@ -83,6 +83,11 @@ do_shutdown (void *cls)
83 GNUNET_SCHEDULER_cancel (ccc->timeout_task); 83 GNUNET_SCHEDULER_cancel (ccc->timeout_task);
84 ccc->timeout_task = NULL; 84 ccc->timeout_task = NULL;
85 } 85 }
86 if (NULL != ccc->connect_task)
87 {
88 GNUNET_SCHEDULER_cancel (ccc->connect_task);
89 ccc->connect_task = NULL;
90 }
86 while (NULL != (crl = ccc->crl_head)) 91 while (NULL != (crl = ccc->crl_head))
87 { 92 {
88 GNUNET_CONTAINER_DLL_remove (ccc->crl_head, 93 GNUNET_CONTAINER_DLL_remove (ccc->crl_head,
@@ -263,33 +268,23 @@ my_rec (void *cls,
263 268
264 269
265/** 270/**
266 * Function called once we have successfully launched a peer. 271 * Connect the peers as a clique.
267 * Once all peers have been launched, we connect all of them
268 * in a clique.
269 * 272 *
270 * @param p peer that was launched (redundant, kill ASAP) 273 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
271 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
272 */ 274 */
273static void 275static void
274start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 276do_connect (void *cls)
275 void *cls)
276{ 277{
277 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 278 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
278 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
279
280 ccc->started++;
281 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
282 "Peer %u (`%s') started\n",
283 p->no,
284 GNUNET_i2s (&p->id));
285 if (ccc->started != ccc->num_peers)
286 return;
287 279
280 ccc->connect_task = NULL;
288 for (unsigned int i=0;i<ccc->num_peers;i++) 281 for (unsigned int i=0;i<ccc->num_peers;i++)
289 for (unsigned int j=i+1;j<ccc->num_peers;j++) 282 for (unsigned int j=(ccc->bi_directional ? 0 : i+1);j<ccc->num_peers;j++)
290 { 283 {
291 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; 284 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
292 285
286 if (i == j)
287 continue;
293 crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList); 288 crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList);
294 GNUNET_CONTAINER_DLL_insert (ccc->crl_head, 289 GNUNET_CONTAINER_DLL_insert (ccc->crl_head,
295 ccc->crl_tail, 290 ccc->crl_tail,
@@ -317,6 +312,44 @@ start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
317 312
318 313
319/** 314/**
315 * Function called once we have successfully launched a peer.
316 * Once all peers have been launched, we connect all of them
317 * in a clique.
318 *
319 * @param p peer that was launched (redundant, kill ASAP)
320 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
321 */
322static void
323start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
324 void *cls)
325{
326 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
327 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
328
329 ccc->started++;
330 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
331 "Peer %u (`%s') started\n",
332 p->no,
333 GNUNET_i2s (&p->id));
334 if (ccc->started != ccc->num_peers)
335 return;
336 if (NULL != ccc->pre_connect_task)
337 {
338 /* Run the custom per-connect job, then give it a second to
339 go into effect before we continue connecting peers. */
340 ccc->pre_connect_task (ccc->pre_connect_task_cls);
341 ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
342 &do_connect,
343 ccc);
344 }
345 else
346 {
347 do_connect (ccc);
348 }
349}
350
351
352/**
320 * Function run from #GNUNET_TRANSPORT_TESTING_connect_check 353 * Function run from #GNUNET_TRANSPORT_TESTING_connect_check
321 * once the scheduler is up. Should launch the peers and 354 * once the scheduler is up. Should launch the peers and
322 * then in the continuations try to connect them. 355 * then in the continuations try to connect them.
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 95f4eb671..ae878a79e 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -44,23 +44,30 @@ find_peer_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
44} 44}
45 45
46 46
47static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 47static void
48find_connecting_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth, 48notify_connecting_context (struct GNUNET_TRANSPORT_TESTING_Handle *tth,
49 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 49 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
50 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2) 50 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2)
51{ 51{
52 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 52 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
53 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
53 54
54 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 55 for (cc = tth->cc_head; NULL != cc; cc = ccn)
55 { 56 {
57 ccn = cc->next;
56 if ( (cc->p1 == p1) && 58 if ( (cc->p1 == p1) &&
57 (cc->p2 == p2) ) 59 (cc->p2 == p2) )
58 return cc; 60 cc->p1_c = GNUNET_YES;
59 if ( (cc->p1 == p2) && 61 if ( (cc->p1 == p2) &&
60 (cc->p2 == p1) ) 62 (cc->p2 == p1) )
61 return cc; 63 cc->p2_c = GNUNET_YES;
64 if ( (cc->p1_c == GNUNET_YES) &&
65 (cc->p2_c == GNUNET_YES) )
66 {
67 cc->cb (cc->cb_cls);
68 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
69 }
62 } 70 }
63 return NULL;
64} 71}
65 72
66 73
@@ -71,7 +78,6 @@ notify_connect (void *cls,
71 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 78 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
72 char *p2_s; 79 char *p2_s;
73 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; 80 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
74 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
75 81
76 p2 = find_peer_context (p->tth, 82 p2 = find_peer_context (p->tth,
77 peer); 83 peer);
@@ -94,24 +100,9 @@ notify_connect (void *cls,
94 p->no, 100 p->no,
95 GNUNET_i2s (&p->id)); 101 GNUNET_i2s (&p->id));
96 GNUNET_free (p2_s); 102 GNUNET_free (p2_s);
97 103 notify_connecting_context (p->tth,
98 /* Find ConnectingContext */ 104 p,
99 cc = find_connecting_context (p->tth, 105 p2);
100 p,
101 p2);
102 if (NULL == cc)
103 return;
104 if (p == cc->p1)
105 cc->p1_c = GNUNET_YES;
106 if (p == cc->p2)
107 cc->p2_c = GNUNET_YES;
108
109 if ( (cc->p1_c == GNUNET_YES) &&
110 (cc->p2_c == GNUNET_YES) )
111 {
112 cc->cb (cc->cb_cls);
113 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
114 }
115} 106}
116 107
117 108
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 842c88374..b78d11dbe 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -459,10 +459,28 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
459 void *shutdown_task_cls; 459 void *shutdown_task_cls;
460 460
461 /** 461 /**
462 * Custom task to run after peers were started but before we try to
463 * connect them. If this function is set, we wait ONE second after
464 * running this function until we continue with connecting the
465 * peers.
466 */
467 GNUNET_SCHEDULER_TaskCallback pre_connect_task;
468
469 /**
470 * Closure for @e shutdown_task.
471 */
472 void *pre_connect_task_cls;
473
474 /**
462 * When should the testcase time out? 475 * When should the testcase time out?
463 */ 476 */
464 struct GNUNET_TIME_Relative timeout; 477 struct GNUNET_TIME_Relative timeout;
465 478
479 /**
480 * Should we try to create connections in both directions?
481 */
482 int bi_directional;
483
466 /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */ 484 /* ******* fields set by #GNUNET_TRANSPORT_TESTING_connect_check **** */
467 485
468 /** 486 /**
@@ -514,6 +532,11 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
514 struct GNUNET_SCHEDULER_Task *timeout_task; 532 struct GNUNET_SCHEDULER_Task *timeout_task;
515 533
516 /** 534 /**
535 * Task run to connect peers.
536 */
537 struct GNUNET_SCHEDULER_Task *connect_task;
538
539 /**
517 * Number of peers that have been started. 540 * Number of peers that have been started.
518 */ 541 */
519 unsigned int started; 542 unsigned int started;