aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am10
-rw-r--r--src/transport/test_transport_testing_startstop.c193
-rw-r--r--src/transport/transport-testing.c7
3 files changed, 209 insertions, 1 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 24984a957..0090d3aca 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -252,6 +252,7 @@ libgnunet_plugin_transport_https_la_CPPFLAGS = \
252 252
253 253
254check_PROGRAMS = \ 254check_PROGRAMS = \
255 test_transport_testing_startstop \
255 test_transport_testing \ 256 test_transport_testing \
256 test_transport_startonly \ 257 test_transport_startonly \
257 test_transport_api_blacklisting \ 258 test_transport_api_blacklisting \
@@ -296,6 +297,7 @@ check_PROGRAMS = \
296 297
297if ENABLE_TEST_RUN 298if ENABLE_TEST_RUN
298TESTS = \ 299TESTS = \
300 test_transport_testing_startstop \
299 test_transport_testing \ 301 test_transport_testing \
300 test_transport_startonly \ 302 test_transport_startonly \
301 test_transport_api_blacklisting \ 303 test_transport_api_blacklisting \
@@ -339,6 +341,14 @@ TESTS = \
339 $(WLAN_UREL_TEST) 341 $(WLAN_UREL_TEST)
340endif 342endif
341 343
344test_transport_testing_startstop_SOURCES = \
345 test_transport_testing_startstop.c
346test_transport_testing_startstop_LDADD = \
347 $(top_builddir)/src/util/libgnunetutil.la \
348 $(top_builddir)/src/transport/libgnunettransport.la \
349 $(top_builddir)/src/hello/libgnunethello.la \
350 $(top_builddir)/src/transport/libgnunettransporttesting.la
351
342test_transport_testing_SOURCES = \ 352test_transport_testing_SOURCES = \
343 test_transport_testing.c 353 test_transport_testing.c
344test_transport_testing_LDADD = \ 354test_transport_testing_LDADD = \
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c
new file mode 100644
index 000000000..2d035ca70
--- /dev/null
+++ b/src/transport/test_transport_testing_startstop.c
@@ -0,0 +1,193 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file transport/test_transport_testing_startstop.c
22 * @brief test case for transport testing library:
23 * start the peer, get the HELLO message and stop the peer
24 *
25 */
26#include "platform.h"
27#include "gnunet_common.h"
28#include "gnunet_hello_lib.h"
29#include "gnunet_getopt_lib.h"
30#include "gnunet_os_lib.h"
31#include "gnunet_program_lib.h"
32#include "gnunet_scheduler_lib.h"
33#include "gnunet_transport_service.h"
34#include "transport.h"
35#include "transport-testing.h"
36
37#define VERBOSE GNUNET_NO
38
39#define VERBOSE_ARM GNUNET_NO
40
41#define START_ARM GNUNET_YES
42
43/**
44 * How long until we give up on transmitting the message?
45 */
46#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
47
48GNUNET_SCHEDULER_TaskIdentifier timeout_task;
49
50static struct PeerContext *p;
51
52//static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
53
54struct GNUNET_TRANSPORT_TESTING_handle *tth;
55
56static int ret = 0;
57
58static void
59end ()
60{
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
62
63 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
64 GNUNET_SCHEDULER_cancel (timeout_task);
65
66 if (NULL != p)
67 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
68 GNUNET_TRANSPORT_TESTING_done (tth);
69}
70
71static void
72end_badly ()
73{
74 timeout_task = GNUNET_SCHEDULER_NO_TASK;
75 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
76
77 if (p != NULL)
78 GNUNET_TRANSPORT_TESTING_stop_peer (tth, p);
79
80 GNUNET_TRANSPORT_TESTING_done (tth);
81
82 ret = GNUNET_SYSERR;
83}
84
85#if 0
86static void
87testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
88{
89 char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
90
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Peer %u (`%4s') connected to peer %u (`%s')!\n", p1->no, ps,
93 p2->no, GNUNET_i2s (&p2->id));
94 GNUNET_free (ps);
95 GNUNET_SCHEDULER_add_now (&end, NULL);
96}
97
98
99static void
100notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
101 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
102{
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
104 GNUNET_i2s (peer));
105 connected++;
106}
107
108static void
109notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
110{
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
112 GNUNET_i2s (peer));
113}
114
115static void
116notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
117 const struct GNUNET_MessageHeader *message,
118 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
119{
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n");
121}
122
123
124
125void
126start_cb (struct PeerContext *p, void *cls)
127{
128 static int started;
129
130 started++;
131
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no,
133 GNUNET_i2s (&p->id));
134
135 if (started != 2)
136 return;
137
138 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p->id));
139
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
142 p->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
143 GNUNET_free (sender_c);
144
145 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p, p2, &testing_connect_cb,
146 NULL);
147}
148#endif
149
150static void
151run (void *cls, char *const *args, const char *cfgfile,
152 const struct GNUNET_CONFIGURATION_Handle *cfg)
153{
154 tth = GNUNET_TRANSPORT_TESTING_init ();
155 GNUNET_assert (NULL != tth);
156
157 timeout_task =
158 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
159
160 GNUNET_SCHEDULER_add_now (&end, NULL);
161}
162
163int
164main (int argc, char *argv[])
165{
166 GNUNET_log_setup ("test_transport_testing_startstop",
167#if VERBOSE
168 "DEBUG",
169#else
170 "WARNING",
171#endif
172 NULL);
173
174 char *const argv_1[] = { "test_transport_testing",
175 "-c",
176 "test_transport_api_data.conf",
177#if VERBOSE
178 "-L", "DEBUG",
179#endif
180 NULL
181 };
182
183 struct GNUNET_GETOPT_CommandLineOption options[] = {
184 GNUNET_GETOPT_OPTION_END
185 };
186
187 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
188 "test_transport_testing_startstop", "nohelp", options, &run, &ret);
189
190 return ret;
191}
192
193/* end of test_transport_testing_startstop.c */
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 8f75c8109..b3c3a9399 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -633,7 +633,12 @@ GNUNET_TRANSPORT_TESTING_init ()
633 /* Init testing the testing lib */ 633 /* Init testing the testing lib */
634 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", 634 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing",
635 "127.0.0.1"); 635 "127.0.0.1");
636 636 if (NULL == tth->tl_system)
637 {
638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize testing library!\n"));
639 GNUNET_free (tth);
640 return NULL;
641 }
637 642
638 tth->hostkey_data = NULL; 643 tth->hostkey_data = NULL;
639 const char *hostkeys_file = "../../contrib/testing_hostkeys.dat"; 644 const char *hostkeys_file = "../../contrib/testing_hostkeys.dat";