aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-08-12 07:03:34 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-08-12 07:03:34 +0000
commitb19fa751b866bb6855ed92beb2bee30917f868c8 (patch)
tree76f0433e011d834a672d10d285369b9b7f1fb17e
parent5434646c91cc203f4113018503b06ada292060d4 (diff)
downloadgnunet-b19fa751b866bb6855ed92beb2bee30917f868c8.tar.gz
gnunet-b19fa751b866bb6855ed92beb2bee30917f868c8.zip
test_transport_api ported to use new testing lib
-rw-r--r--src/transport/Makefile.am62
-rw-r--r--src/transport/test_transport_api.c462
-rw-r--r--src/transport/transport-testing.c23
-rw-r--r--src/transport/transport-testing.h1
4 files changed, 130 insertions, 418 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 5fe5aa32f..a1a6ed73c 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -335,6 +335,7 @@ test_transport_testing_SOURCES = \
335 test_transport_testing.c 335 test_transport_testing.c
336test_transport_testing_LDADD = \ 336test_transport_testing_LDADD = \
337 $(top_builddir)/src/transport/libgnunettransport.la \ 337 $(top_builddir)/src/transport/libgnunettransport.la \
338 $(top_builddir)/src/hello/libgnunethello.la \
338 $(top_builddir)/src/transport/libgnunettransporttesting.la 339 $(top_builddir)/src/transport/libgnunettransporttesting.la
339 340
340test_transport_api_disconnect_SOURCES = \ 341test_transport_api_disconnect_SOURCES = \
@@ -376,70 +377,81 @@ test_transport_api_tcp_SOURCES = \
376test_transport_api_tcp_LDADD = \ 377test_transport_api_tcp_LDADD = \
377 $(top_builddir)/src/transport/libgnunettransport.la \ 378 $(top_builddir)/src/transport/libgnunettransport.la \
378 $(top_builddir)/src/hello/libgnunethello.la \ 379 $(top_builddir)/src/hello/libgnunethello.la \
379 $(top_builddir)/src/util/libgnunetutil.la 380 $(top_builddir)/src/util/libgnunetutil.la \
381 $(top_builddir)/src/transport/libgnunettransporttesting.la
380 382
381test_transport_api_tcp_nat_SOURCES = \ 383test_transport_api_tcp_nat_SOURCES = \
382 test_transport_api.c 384 test_transport_api.c
383test_transport_api_tcp_nat_LDADD = \ 385test_transport_api_tcp_nat_LDADD = \
384 $(top_builddir)/src/transport/libgnunettransport.la \ 386 $(top_builddir)/src/transport/libgnunettransport.la \
385 $(top_builddir)/src/hello/libgnunethello.la \ 387 $(top_builddir)/src/hello/libgnunethello.la \
386 $(top_builddir)/src/util/libgnunetutil.la 388 $(top_builddir)/src/util/libgnunetutil.la \
389 $(top_builddir)/src/transport/libgnunettransporttesting.la
387 390
388test_transport_api_reliability_tcp_SOURCES = \ 391test_transport_api_reliability_tcp_SOURCES = \
389 test_transport_api_reliability.c 392 test_transport_api_reliability.c
390test_transport_api_reliability_tcp_LDADD = \ 393test_transport_api_reliability_tcp_LDADD = \
391 $(top_builddir)/src/transport/libgnunettransport.la \ 394 $(top_builddir)/src/transport/libgnunettransport.la \
392 $(top_builddir)/src/hello/libgnunethello.la \ 395 $(top_builddir)/src/hello/libgnunethello.la \
393 $(top_builddir)/src/util/libgnunetutil.la 396 $(top_builddir)/src/util/libgnunetutil.la \
397 $(top_builddir)/src/transport/libgnunettransporttesting.la
398
394 399
395test_transport_api_multiaddress_tcp_SOURCES = \ 400test_transport_api_multiaddress_tcp_SOURCES = \
396 test_transport_api_multiaddress.c 401 test_transport_api_multiaddress.c
397test_transport_api_multiaddress_tcp_LDADD = \ 402test_transport_api_multiaddress_tcp_LDADD = \
398 $(top_builddir)/src/transport/libgnunettransport.la \ 403 $(top_builddir)/src/transport/libgnunettransport.la \
399 $(top_builddir)/src/hello/libgnunethello.la \ 404 $(top_builddir)/src/hello/libgnunethello.la \
400 $(top_builddir)/src/util/libgnunetutil.la 405 $(top_builddir)/src/util/libgnunetutil.la \
406 $(top_builddir)/src/transport/libgnunettransporttesting.la
401 407
402test_transport_api_reliability_tcp_nat_SOURCES = \ 408test_transport_api_reliability_tcp_nat_SOURCES = \
403 test_transport_api_reliability.c 409 test_transport_api_reliability.c
404test_transport_api_reliability_tcp_nat_LDADD = \ 410test_transport_api_reliability_tcp_nat_LDADD = \
405 $(top_builddir)/src/transport/libgnunettransport.la \ 411 $(top_builddir)/src/transport/libgnunettransport.la \
406 $(top_builddir)/src/hello/libgnunethello.la \ 412 $(top_builddir)/src/hello/libgnunethello.la \
407 $(top_builddir)/src/util/libgnunetutil.la 413 $(top_builddir)/src/util/libgnunetutil.la \
414 $(top_builddir)/src/transport/libgnunettransporttesting.la
408 415
409test_transport_api_reliability_wlan_SOURCES = \ 416test_transport_api_reliability_wlan_SOURCES = \
410 test_transport_api_reliability.c 417 test_transport_api_reliability.c
411test_transport_api_reliability_wlan_LDADD = \ 418test_transport_api_reliability_wlan_LDADD = \
412 $(top_builddir)/src/transport/libgnunettransport.la \ 419 $(top_builddir)/src/transport/libgnunettransport.la \
413 $(top_builddir)/src/hello/libgnunethello.la \ 420 $(top_builddir)/src/hello/libgnunethello.la \
414 $(top_builddir)/src/util/libgnunetutil.la 421 $(top_builddir)/src/util/libgnunetutil.la \
422 $(top_builddir)/src/transport/libgnunettransporttesting.la
415 423
416test_transport_api_unreliability_wlan_SOURCES = \ 424test_transport_api_unreliability_wlan_SOURCES = \
417 test_transport_api_unreliability.c 425 test_transport_api_unreliability.c
418test_transport_api_unreliability_wlan_LDADD = \ 426test_transport_api_unreliability_wlan_LDADD = \
419 $(top_builddir)/src/transport/libgnunettransport.la \ 427 $(top_builddir)/src/transport/libgnunettransport.la \
420 $(top_builddir)/src/hello/libgnunethello.la \ 428 $(top_builddir)/src/hello/libgnunethello.la \
421 $(top_builddir)/src/util/libgnunetutil.la 429 $(top_builddir)/src/util/libgnunetutil.la \
422 430 $(top_builddir)/src/transport/libgnunettransporttesting.la
431
423test_transport_api_udp_SOURCES = \ 432test_transport_api_udp_SOURCES = \
424 test_transport_api.c 433 test_transport_api.c
425test_transport_api_udp_LDADD = \ 434test_transport_api_udp_LDADD = \
426 $(top_builddir)/src/transport/libgnunettransport.la \ 435 $(top_builddir)/src/transport/libgnunettransport.la \
427 $(top_builddir)/src/hello/libgnunethello.la \ 436 $(top_builddir)/src/hello/libgnunethello.la \
428 $(top_builddir)/src/util/libgnunetutil.la 437 $(top_builddir)/src/util/libgnunetutil.la \
438 $(top_builddir)/src/transport/libgnunettransporttesting.la
429 439
430test_transport_api_udp_nat_SOURCES = \ 440test_transport_api_udp_nat_SOURCES = \
431 test_transport_api.c 441 test_transport_api.c
432test_transport_api_udp_nat_LDADD = \ 442test_transport_api_udp_nat_LDADD = \
433 $(top_builddir)/src/transport/libgnunettransport.la \ 443 $(top_builddir)/src/transport/libgnunettransport.la \
434 $(top_builddir)/src/hello/libgnunethello.la \ 444 $(top_builddir)/src/hello/libgnunethello.la \
435 $(top_builddir)/src/util/libgnunetutil.la 445 $(top_builddir)/src/util/libgnunetutil.la \
446 $(top_builddir)/src/transport/libgnunettransporttesting.la
436 447
437test_transport_api_unix_SOURCES = \ 448test_transport_api_unix_SOURCES = \
438 test_transport_api.c 449 test_transport_api.c
439test_transport_api_unix_LDADD = \ 450test_transport_api_unix_LDADD = \
440 $(top_builddir)/src/transport/libgnunettransport.la \ 451 $(top_builddir)/src/transport/libgnunettransport.la \
441 $(top_builddir)/src/hello/libgnunethello.la \ 452 $(top_builddir)/src/hello/libgnunethello.la \
442 $(top_builddir)/src/util/libgnunetutil.la 453 $(top_builddir)/src/util/libgnunetutil.la \
454 $(top_builddir)/src/transport/libgnunettransporttesting.la
443 455
444#test_plugin_transport_http_SOURCES = \ 456#test_plugin_transport_http_SOURCES = \
445# test_plugin_transport_http.c 457# test_plugin_transport_http.c
@@ -454,15 +466,17 @@ test_transport_api_http_SOURCES = \
454test_transport_api_http_LDADD = \ 466test_transport_api_http_LDADD = \
455 $(top_builddir)/src/transport/libgnunettransport.la \ 467 $(top_builddir)/src/transport/libgnunettransport.la \
456 $(top_builddir)/src/hello/libgnunethello.la \ 468 $(top_builddir)/src/hello/libgnunethello.la \
457 $(top_builddir)/src/util/libgnunetutil.la 469 $(top_builddir)/src/util/libgnunetutil.la \
458 470 $(top_builddir)/src/transport/libgnunettransporttesting.la
471
459test_transport_api_reliability_http_SOURCES = \ 472test_transport_api_reliability_http_SOURCES = \
460 test_transport_api_reliability.c 473 test_transport_api_reliability.c
461test_transport_api_reliability_http_LDADD = \ 474test_transport_api_reliability_http_LDADD = \
462 $(top_builddir)/src/transport/libgnunettransport.la \ 475 $(top_builddir)/src/transport/libgnunettransport.la \
463 $(top_builddir)/src/hello/libgnunethello.la \ 476 $(top_builddir)/src/hello/libgnunethello.la \
464 $(top_builddir)/src/util/libgnunetutil.la 477 $(top_builddir)/src/util/libgnunetutil.la \
465 478 $(top_builddir)/src/transport/libgnunettransporttesting.la
479
466#test_plugin_transport_https_SOURCES = \ 480#test_plugin_transport_https_SOURCES = \
467# test_plugin_transport_https.c 481# test_plugin_transport_https.c
468#test_plugin_transport_https_LDADD = \ 482#test_plugin_transport_https_LDADD = \
@@ -476,28 +490,33 @@ test_transport_api_https_SOURCES = \
476test_transport_api_https_LDADD = \ 490test_transport_api_https_LDADD = \
477 $(top_builddir)/src/transport/libgnunettransport.la \ 491 $(top_builddir)/src/transport/libgnunettransport.la \
478 $(top_builddir)/src/hello/libgnunethello.la \ 492 $(top_builddir)/src/hello/libgnunethello.la \
479 $(top_builddir)/src/util/libgnunetutil.la 493 $(top_builddir)/src/util/libgnunetutil.la \
494 $(top_builddir)/src/transport/libgnunettransporttesting.la
480 495
481test_transport_api_reliability_https_SOURCES = \ 496test_transport_api_reliability_https_SOURCES = \
482 test_transport_api_reliability.c 497 test_transport_api_reliability.c
483test_transport_api_reliability_https_LDADD = \ 498test_transport_api_reliability_https_LDADD = \
484 $(top_builddir)/src/transport/libgnunettransport.la \ 499 $(top_builddir)/src/transport/libgnunettransport.la \
485 $(top_builddir)/src/hello/libgnunethello.la \ 500 $(top_builddir)/src/hello/libgnunethello.la \
486 $(top_builddir)/src/util/libgnunetutil.la 501 $(top_builddir)/src/util/libgnunetutil.la \
502 $(top_builddir)/src/transport/libgnunettransporttesting.la
487 503
488test_transport_api_unreliability_unix_SOURCES = \ 504test_transport_api_unreliability_unix_SOURCES = \
489 test_transport_api_unreliability.c 505 test_transport_api_unreliability.c
490test_transport_api_unreliability_unix_LDADD = \ 506test_transport_api_unreliability_unix_LDADD = \
491 $(top_builddir)/src/transport/libgnunettransport.la \ 507 $(top_builddir)/src/transport/libgnunettransport.la \
492 $(top_builddir)/src/hello/libgnunethello.la \ 508 $(top_builddir)/src/hello/libgnunethello.la \
493 $(top_builddir)/src/util/libgnunetutil.la 509 $(top_builddir)/src/util/libgnunetutil.la \
510 $(top_builddir)/src/transport/libgnunettransporttesting.la
494 511
495test_transport_api_unreliability_udp_SOURCES = \ 512test_transport_api_unreliability_udp_SOURCES = \
496 test_transport_api_unreliability.c 513 test_transport_api_unreliability.c
497test_transport_api_unreliability_udp_LDADD = \ 514test_transport_api_unreliability_udp_LDADD = \
498 $(top_builddir)/src/transport/libgnunettransport.la \ 515 $(top_builddir)/src/transport/libgnunettransport.la \
499 $(top_builddir)/src/hello/libgnunethello.la \ 516 $(top_builddir)/src/hello/libgnunethello.la \
500 $(top_builddir)/src/util/libgnunetutil.la 517 $(top_builddir)/src/util/libgnunetutil.la \
518 $(top_builddir)/src/transport/libgnunettransporttesting.la
519
501 520
502if LINUX 521if LINUX
503test_transport_api_wlan_SOURCES = \ 522test_transport_api_wlan_SOURCES = \
@@ -608,7 +627,10 @@ test_transport_api_multi_SOURCES = \
608test_transport_api_multi_LDADD = \ 627test_transport_api_multi_LDADD = \
609 $(top_builddir)/src/transport/libgnunettransport.la \ 628 $(top_builddir)/src/transport/libgnunettransport.la \
610 $(top_builddir)/src/hello/libgnunethello.la \ 629 $(top_builddir)/src/hello/libgnunethello.la \
611 $(top_builddir)/src/util/libgnunetutil.la 630 $(top_builddir)/src/util/libgnunetutil.la \
631 $(top_builddir)/src/transport/libgnunettransporttesting.la
632
633
612EXTRA_DIST = \ 634EXTRA_DIST = \
613 gnunet-transport-certificate-creation \ 635 gnunet-transport-certificate-creation \
614 ats_mlp_p100_m400.problem \ 636 ats_mlp_p100_m400.problem \
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 84cb2421d..449cd38d0 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -55,42 +55,20 @@
55 55
56#define MTYPE 12345 56#define MTYPE 12345
57 57
58static struct PeerContext p1;
59
60static struct PeerContext p2;
61
62static int ok; 58static int ok;
63 59
64static int is_tcp;
65
66static int is_tcp_nat;
67
68static int is_udp;
69
70static int is_unix;
71
72static int is_udp_nat;
73
74static int is_http;
75
76static int is_https;
77
78static int is_multi_protocol;
79
80static int is_wlan;
81
82static GNUNET_SCHEDULER_TaskIdentifier die_task; 60static GNUNET_SCHEDULER_TaskIdentifier die_task;
83 61
84static GNUNET_SCHEDULER_TaskIdentifier tct; 62struct PeerContext * p1;
85
86static char * key_file_p1;
87static char * cert_file_p1;
88 63
89static char * key_file_p2; 64struct PeerContext * p2;
90static char * cert_file_p2;
91 65
92struct GNUNET_TRANSPORT_TransmitHandle * th; 66struct GNUNET_TRANSPORT_TransmitHandle * th;
93 67
68char * cfg_file_p1;
69
70char * cfg_file_p2;
71
94#if VERBOSE 72#if VERBOSE
95#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 73#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
96#else 74#else
@@ -101,103 +79,29 @@ struct GNUNET_TRANSPORT_TransmitHandle * th;
101static void 79static void
102end () 80end ()
103{ 81{
104 GNUNET_assert (ok == 6); 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
105 if (GNUNET_SCHEDULER_NO_TASK != die_task)
106 GNUNET_SCHEDULER_cancel (die_task);
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "Disconnecting from transports!\n");
109 if (th != NULL)
110 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th);
111 th = NULL;
112
113 GNUNET_TRANSPORT_disconnect (p1.th);
114 GNUNET_TRANSPORT_disconnect (p2.th);
115 die_task = GNUNET_SCHEDULER_NO_TASK;
116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
117 "Transports disconnected, returning success!\n");
118 ok = 0;
119}
120
121static void
122stop_arm (struct PeerContext *p)
123{
124#if START_ARM
125 if (NULL != p->arm_proc)
126 {
127 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
128 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
129 GNUNET_OS_process_wait (p->arm_proc);
130 GNUNET_OS_process_close (p->arm_proc);
131 p->arm_proc = NULL;
132 }
133#endif
134 GNUNET_CONFIGURATION_destroy (p->cfg);
135}
136
137 83
84 if (die_task != GNUNET_SCHEDULER_NO_TASK)
85 GNUNET_SCHEDULER_cancel(die_task);
138 86
87 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
88 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
139 89
140static void 90 ok = 0;
141exchange_hello_last (void *cls,
142 const struct GNUNET_MessageHeader *message)
143{
144 struct PeerContext *me = cls;
145
146 GNUNET_assert (message != NULL);
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 "Exchanging HELLO of size %d with peer (%s)!\n",
149 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
150 GNUNET_i2s (&me->id));
151 GNUNET_assert (GNUNET_OK ==
152 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
153 message, &me->id));
154 GNUNET_TRANSPORT_offer_hello (p1.th, message, NULL, NULL);
155}
156
157
158static void
159exchange_hello (void *cls,
160 const struct GNUNET_MessageHeader *message)
161{
162 struct PeerContext *me = cls;
163
164 GNUNET_assert (message != NULL);
165 GNUNET_assert (GNUNET_OK ==
166 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
167 message, &me->id));
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169 "Exchanging HELLO of size %d from peer %s!\n",
170 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message),
171 GNUNET_i2s (&me->id));
172 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
173} 91}
174 92
175
176static void 93static void
177end_badly () 94end_badly ()
178{ 95{
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 96 die_task = GNUNET_SCHEDULER_NO_TASK;
180 GNUNET_break (0); 97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
181 98
182 if (th != NULL) 99 if (p1 != NULL)
183 { 100 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
184 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 101 if (p2 != NULL)
185 th = NULL; 102 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
186 }
187 else
188 {
189 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
190 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
191 }
192 103
193 GNUNET_TRANSPORT_disconnect (p1.th); 104 ok = GNUNET_SYSERR;
194 GNUNET_TRANSPORT_disconnect (p2.th);
195 if (GNUNET_SCHEDULER_NO_TASK != tct)
196 {
197 GNUNET_SCHEDULER_cancel (tct);
198 tct = GNUNET_SCHEDULER_NO_TASK;
199 }
200 ok = 1;
201} 105}
202 106
203 107
@@ -212,8 +116,7 @@ notify_receive (void *cls,
212 "Received message of type %d from peer %s!\n", 116 "Received message of type %d from peer %s!\n",
213 ntohs(message->type), 117 ntohs(message->type),
214 GNUNET_i2s (peer)); 118 GNUNET_i2s (peer));
215 GNUNET_assert (ok == 5); 119
216 OKPP;
217 GNUNET_assert (MTYPE == ntohs (message->type)); 120 GNUNET_assert (MTYPE == ntohs (message->type));
218 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 121 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
219 ntohs (message->size)); 122 ntohs (message->size));
@@ -234,8 +137,7 @@ notify_ready (void *cls, size_t size, void *buf)
234 sizeof (struct GNUNET_MessageHeader), 137 sizeof (struct GNUNET_MessageHeader),
235 GNUNET_i2s (&p->id)); 138 GNUNET_i2s (&p->id));
236 GNUNET_assert (size >= 256); 139 GNUNET_assert (size >= 256);
237 GNUNET_assert (ok == 4); 140
238 OKPP;
239 if (buf != NULL) 141 if (buf != NULL)
240 { 142 {
241 hdr = buf; 143 hdr = buf;
@@ -256,25 +158,6 @@ notify_connect (void *cls,
256 "Peer `%4s' connected to us (%p)!\n", 158 "Peer `%4s' connected to us (%p)!\n",
257 GNUNET_i2s (peer), 159 GNUNET_i2s (peer),
258 cls); 160 cls);
259 if (cls == &p1)
260 {
261 GNUNET_assert (ok >= 2);
262 OKPP;
263 OKPP;
264 if (GNUNET_SCHEDULER_NO_TASK != die_task)
265 GNUNET_SCHEDULER_cancel (die_task);
266 if (GNUNET_SCHEDULER_NO_TASK != tct)
267 GNUNET_SCHEDULER_cancel (tct);
268 tct = GNUNET_SCHEDULER_NO_TASK;
269 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
270 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
271 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
272 &end_badly, NULL);
273 th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
274 &p2.id,
275 256, 0, TIMEOUT, &notify_ready,
276 &p1);
277 }
278} 161}
279 162
280 163
@@ -287,185 +170,47 @@ notify_disconnect (void *cls,
287 GNUNET_i2s (peer), cls); 170 GNUNET_i2s (peer), cls);
288} 171}
289 172
290
291static void 173static void
292setup_peer (struct PeerContext *p, 174sendtask ()
293 const char *cfgname)
294{ 175{
295 p->cfg = GNUNET_CONFIGURATION_create (); 176 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th,
296 177 &p2->id,
297 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 178 256, 0, TIMEOUT, &notify_ready,
298 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 179 &p1);
299 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome);
300 if (NULL != p->servicehome)
301 GNUNET_DISK_directory_remove (p->servicehome);
302
303#if START_ARM
304 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
305 "gnunet-service-arm",
306#if VERBOSE_ARM
307 "-L", "DEBUG",
308#endif
309 "-c", cfgname, NULL);
310#endif
311
312
313
314 if (is_https)
315 {
316 struct stat sbuf;
317 if (p==&p1)
318 {
319 if (GNUNET_CONFIGURATION_have_value (p->cfg,
320 "transport-https", "KEY_FILE"))
321 GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p1);
322 if (key_file_p1==NULL)
323 GNUNET_asprintf(&key_file_p1,"https.key");
324 if (0 == stat (key_file_p1, &sbuf ))
325 {
326 if (0 == remove(key_file_p1))
327 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
328 "Successfully removed existing private key file `%s'\n",key_file_p1);
329 else
330 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
331 "Failed to remove private key file `%s'\n",key_file_p1);
332 }
333 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
334 GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p1);
335 if (cert_file_p1==NULL)
336 GNUNET_asprintf(&cert_file_p1,"https.cert");
337 if (0 == stat (cert_file_p1, &sbuf ))
338 {
339 if (0 == remove(cert_file_p1))
340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
341 "Successfully removed existing certificate file `%s'\n",
342 cert_file_p1);
343 else
344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
345 "Failed to remove existing certificate file `%s'\n",
346 cert_file_p1);
347 }
348 }
349 else if (p==&p2)
350 {
351 if (GNUNET_CONFIGURATION_have_value (p->cfg,
352 "transport-https", "KEY_FILE"))
353 GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "KEY_FILE", &key_file_p2);
354 if (key_file_p2==NULL)
355 GNUNET_asprintf(&key_file_p2,"https.key");
356 if (0 == stat (key_file_p2, &sbuf ))
357 {
358 if (0 == remove(key_file_p2))
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
360 "Successfully removed existing private key file `%s'\n",
361 key_file_p2);
362 else
363 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
364 "Failed to remove private key file `%s'\n",
365 key_file_p2);
366 }
367 if (GNUNET_CONFIGURATION_have_value (p->cfg,"transport-https", "CERT_FILE"))
368 GNUNET_CONFIGURATION_get_value_string (p->cfg, "transport-https", "CERT_FILE", &cert_file_p2);
369 if (cert_file_p2==NULL)
370 GNUNET_asprintf(&cert_file_p2,"https.cert");
371 if (0 == stat (cert_file_p2, &sbuf ))
372 {
373 if (0 == remove(cert_file_p2))
374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
375 "Successfully removed existing certificate file `%s'\n",cert_file_p2);
376 else
377 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
378 "Failed to remove existing certificate file `%s'\n",cert_file_p2);
379 }
380 }
381 }
382
383 p->th = GNUNET_TRANSPORT_connect (p->cfg,
384 NULL, p,
385 &notify_receive,
386 &notify_connect, &notify_disconnect);
387 GNUNET_assert (p->th != NULL);
388} 180}
389 181
390
391static void 182static void
392try_connect (void *cls, 183testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls)
393 const struct GNUNET_SCHEDULER_TaskContext *tc)
394{ 184{
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 185 char * p1_c = strdup (GNUNET_i2s(&p1->id));
396 "Asking peers to connect...\n"); 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n",
397 /* FIXME: 'pX.id' may still be all-zeros here... */ 187 p1_c,
398 GNUNET_TRANSPORT_try_connect (p2.th, 188 GNUNET_i2s (&p2->id));
399 &p1.id);
400 GNUNET_TRANSPORT_try_connect (p1.th,
401 &p2.id);
402 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
403 &try_connect,
404 NULL);
405}
406 189
190 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
191 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
192}
407 193
408static void 194static void
409run (void *cls, 195run (void *cls,
410 char *const *args, 196 char *const *args,
411 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 197 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
412{ 198{
413 GNUNET_assert (ok == 1);
414 OKPP;
415 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 199 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
416 &end_badly, NULL); 200 &end_badly, NULL);
417 201
418 if (is_udp) 202 p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1,
419 { 203 &notify_receive,
420 setup_peer (&p1, "test_transport_api_udp_peer1.conf"); 204 &notify_connect,
421 setup_peer (&p2, "test_transport_api_udp_peer2.conf"); 205 &notify_disconnect,
422 } 206 NULL);
423 if (is_unix) 207 p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2,
424 { 208 &notify_receive,
425 setup_peer (&p1, "test_transport_api_unix_peer1.conf"); 209 &notify_connect,
426 setup_peer (&p2, "test_transport_api_unix_peer2.conf"); 210 &notify_disconnect,
427 } 211 NULL);
428 if (is_multi_protocol) 212
429 { 213 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
430 setup_peer (&p1, "test_transport_api_multi_peer1.conf");
431 setup_peer (&p2, "test_transport_api_multi_peer2.conf");
432 }
433 else if (is_tcp)
434 {
435 setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
436 setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
437 }
438 else if (is_tcp_nat)
439 {
440 setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
441 setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
442 }
443 else if (is_udp_nat)
444 {
445 setup_peer (&p1, "test_transport_api_udp_nat_peer1.conf");
446 setup_peer (&p2, "test_transport_api_udp_nat_peer2.conf");
447 }
448 else if (is_http)
449 {
450 setup_peer (&p1, "test_transport_api_http_peer1.conf");
451 setup_peer (&p2, "test_transport_api_http_peer2.conf");
452 }
453 else if (is_https)
454 {
455 setup_peer (&p1, "test_transport_api_https_peer1.conf");
456 setup_peer (&p2, "test_transport_api_https_peer2.conf");
457 }
458 else if (is_wlan)
459 {
460 setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
461 setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
462 }
463 GNUNET_assert(p1.th != NULL);
464 GNUNET_assert(p2.th != NULL);
465
466 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
467 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
468 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
469} 214}
470 215
471static int 216static int
@@ -490,67 +235,7 @@ check ()
490 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 235 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
491 argv, "test-transport-api", "nohelp", 236 argv, "test-transport-api", "nohelp",
492 options, &run, &ok); 237 options, &run, &ok);
493 stop_arm (&p1);
494 stop_arm (&p2);
495 238
496 if (is_https)
497 {
498 struct stat sbuf;
499 if (0 == stat (cert_file_p1, &sbuf ))
500 {
501 if (0 == remove(cert_file_p1))
502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
503 "Successfully removed existing certificate file `%s'\n",cert_file_p1);
504 else
505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
506 "Failed to remove certfile `%s'\n",cert_file_p1);
507 }
508
509 if (0 == stat (key_file_p1, &sbuf ))
510 {
511 if (0 == remove(key_file_p1))
512 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
513 "Successfully removed private key file `%s'\n",key_file_p1);
514 else
515 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
516 "Failed to private key file `%s'\n",key_file_p1);
517 }
518
519 if (0 == stat (cert_file_p2, &sbuf ))
520 {
521 if (0 == remove(cert_file_p2))
522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
523 "Successfully removed existing certificate file `%s'\n",cert_file_p2);
524 else
525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 "Failed to remove certfile `%s'\n",cert_file_p2);
527 }
528
529 if (0 == stat (key_file_p2, &sbuf ))
530 {
531 if (0 == remove(key_file_p2))
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "Successfully removed private key file `%s'\n",key_file_p2);
534 else
535 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
536 "Failed to private key file `%s'\n",key_file_p2);
537 }
538 GNUNET_free(key_file_p1);
539 GNUNET_free(key_file_p2);
540 GNUNET_free(cert_file_p1);
541 GNUNET_free(cert_file_p2);
542 }
543
544 if (p1.servicehome != NULL)
545 {
546 GNUNET_DISK_directory_remove (p1.servicehome);
547 GNUNET_free(p1.servicehome);
548 }
549 if (p2.servicehome != NULL)
550 {
551 GNUNET_DISK_directory_remove (p2.servicehome);
552 GNUNET_free(p2.servicehome);
553 }
554 return ok; 239 return ok;
555} 240}
556 241
@@ -678,9 +363,30 @@ main (int argc, char *argv[])
678#endif 363#endif
679 NULL); 364 NULL);
680 365
366 char * pch = strdup(argv[0]);
367 char * filename = NULL;
368
369 /* get executable filename */
370 pch = strtok (pch,"/");
371 while (pch != NULL)
372 {
373 pch = strtok (NULL, "/");
374 if (pch != NULL)
375 filename = pch;
376 }
377
378 /* remove "lt-" */
379
380 filename = strstr(filename, "tes");
381 //filename = &filename[1];
382 //GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
383 // "`%s'\n",filename);
384 /* create cfg filename */
385 GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename);
386 GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename);
387
681 if (strstr(argv[0], "tcp_nat") != NULL) 388 if (strstr(argv[0], "tcp_nat") != NULL)
682 { 389 {
683 is_tcp_nat = GNUNET_YES;
684 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 390 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
685 { 391 {
686 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 392 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -689,13 +395,8 @@ main (int argc, char *argv[])
689 return 0; 395 return 0;
690 } 396 }
691 } 397 }
692 else if (strstr(argv[0], "tcp") != NULL)
693 {
694 is_tcp = GNUNET_YES;
695 }
696 else if (strstr(argv[0], "udp_nat") != NULL) 398 else if (strstr(argv[0], "udp_nat") != NULL)
697 { 399 {
698 is_udp_nat = GNUNET_YES;
699 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 400 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server"))
700 { 401 {
701 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 402 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -704,33 +405,12 @@ main (int argc, char *argv[])
704 return 0; 405 return 0;
705 } 406 }
706 } 407 }
707 else if (strstr(argv[0], "udp") != NULL)
708 {
709 is_udp = GNUNET_YES;
710 }
711 else if (strstr(argv[0], "unix") != NULL)
712 {
713 is_unix = GNUNET_YES;
714 }
715 else if (strstr(argv[0], "https") != NULL)
716 {
717 is_https = GNUNET_YES;
718 }
719 else if (strstr(argv[0], "http") != NULL)
720 {
721 is_http = GNUNET_YES;
722 }
723 else if (strstr(argv[0], "wlan") != NULL)
724 {
725 is_wlan = GNUNET_YES;
726 }
727 else if (strstr(argv[0], "multi") != NULL)
728 {
729 is_multi_protocol = GNUNET_YES;
730 }
731 408
732 ret = check (); 409 ret = check ();
733 410
411 GNUNET_free (cfg_file_p1);
412 GNUNET_free (cfg_file_p2);
413
734 return ret; 414 return ret;
735} 415}
736 416
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 16e7a1e25..fab0fec5a 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -37,7 +37,8 @@ struct ConnectingContext
37 37
38 struct GNUNET_TRANSPORT_Handle *th_p1; 38 struct GNUNET_TRANSPORT_Handle *th_p1;
39 struct GNUNET_TRANSPORT_Handle *th_p2; 39 struct GNUNET_TRANSPORT_Handle *th_p2;
40 int c; 40 int p1_c;
41 int p2_c;
41}; 42};
42 43
43static void 44static void
@@ -54,12 +55,21 @@ notify_connect_internal (void *cls,
54 uint32_t ats_count) 55 uint32_t ats_count)
55{ 56{
56 struct ConnectingContext * cc = cls; 57 struct ConnectingContext * cc = cls;
57// /void * cb_cls = cc->cb_cls;
58 58
59 GNUNET_assert(cc != NULL); 59 GNUNET_assert(cc != NULL);
60 cc->c++;
61 60
62 if (cc->c == 2) 61 if (0 == memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey, sizeof (GNUNET_HashCode)))
62 {
63 if (cc->p1_c == GNUNET_NO)
64 cc->p1_c = GNUNET_YES;
65 }
66 if (0 == memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey, sizeof (GNUNET_HashCode)))
67 {
68 if (cc->p2_c == GNUNET_NO)
69 cc->p2_c = GNUNET_YES;
70 }
71
72 if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
63 { 73 {
64 /* clean up */ 74 /* clean up */
65 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc); 75 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc);
@@ -70,15 +80,14 @@ notify_connect_internal (void *cls,
70 80
71 cc->tct = GNUNET_SCHEDULER_NO_TASK; 81 cc->tct = GNUNET_SCHEDULER_NO_TASK;
72 82
73 GNUNET_TRANSPORT_disconnect( cc->th_p1); 83 GNUNET_TRANSPORT_disconnect (cc->th_p1);
74 GNUNET_TRANSPORT_disconnect( cc->th_p2); 84 GNUNET_TRANSPORT_disconnect (cc->th_p2);
75 85
76 if (cc->cb != NULL) 86 if (cc->cb != NULL)
77 cc->cb (cc->p1, cc->p2, cc->cb_cls); 87 cc->cb (cc->p1, cc->p2, cc->cb_cls);
78 88
79 GNUNET_free(cc); 89 GNUNET_free(cc);
80 } 90 }
81
82} 91}
83 92
84static void 93static void
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 25a772001..5ea5cf3c3 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -28,6 +28,7 @@
28#include "platform.h" 28#include "platform.h"
29#include "gnunet_common.h" 29#include "gnunet_common.h"
30#include "gnunet_getopt_lib.h" 30#include "gnunet_getopt_lib.h"
31#include "gnunet_hello_lib.h"
31#include "gnunet_os_lib.h" 32#include "gnunet_os_lib.h"
32#include "gnunet_program_lib.h" 33#include "gnunet_program_lib.h"
33#include "gnunet_transport_service.h" 34#include "gnunet_transport_service.h"