aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-02 11:31:34 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-02 11:31:34 +0000
commitc42deb089faffd654e27bf661ce85d5c1bb38b7a (patch)
tree8bf5e1ffe6b12acb7599312bdb536e0d8a8a44e1
parent2806f183b7b07aa0b6060405d68b95c9243fa499 (diff)
downloadgnunet-c42deb089faffd654e27bf661ce85d5c1bb38b7a.tar.gz
gnunet-c42deb089faffd654e27bf661ce85d5c1bb38b7a.zip
-cleanup
-rw-r--r--src/transport/test_transport_testing.c75
1 files changed, 46 insertions, 29 deletions
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index fb5bf6068..1ce751acd 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -18,7 +18,7 @@
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20/** 20/**
21 * @file transport/test_transport_api.c 21 * @file transport/test_transport_testing.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
23 * 23 *
24 * This test case serves as a base for tcp, udp, and udp-nat 24 * This test case serves as a base for tcp, udp, and udp-nat
@@ -34,9 +34,10 @@
34 */ 34 */
35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 35#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
36 36
37struct GNUNET_SCHEDULER_Task * timeout_task; 37static struct GNUNET_SCHEDULER_Task * timeout_task;
38 38
39static struct PeerContext *p1; 39static struct PeerContext *p1;
40
40static struct PeerContext *p2; 41static struct PeerContext *p2;
41 42
42static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; 43static GNUNET_TRANSPORT_TESTING_ConnectRequest cc;
@@ -47,10 +48,12 @@ static int connected = GNUNET_NO;
47 48
48static int ret = 0; 49static int ret = 0;
49 50
51
50static void 52static void
51end () 53end ()
52{ 54{
53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 55 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
56 "Stopping peers\n");
54 57
55 if (timeout_task != NULL) 58 if (timeout_task != NULL)
56 GNUNET_SCHEDULER_cancel (timeout_task); 59 GNUNET_SCHEDULER_cancel (timeout_task);
@@ -61,11 +64,13 @@ end ()
61 GNUNET_TRANSPORT_TESTING_done (tth); 64 GNUNET_TRANSPORT_TESTING_done (tth);
62} 65}
63 66
67
64static void 68static void
65end_badly () 69end_badly ()
66{ 70{
67 timeout_task = NULL; 71 timeout_task = NULL;
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 72 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
73 "Timeout! Stopping peers\n");
69 74
70 if (NULL != cc) 75 if (NULL != cc)
71 { 76 {
@@ -84,8 +89,11 @@ end_badly ()
84 ret = GNUNET_SYSERR; 89 ret = GNUNET_SYSERR;
85} 90}
86 91
92
87static void 93static void
88testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) 94testing_connect_cb (struct PeerContext *p1,
95 struct PeerContext *p2,
96 void *cls)
89{ 97{
90 char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id)); 98 char *ps = GNUNET_strdup (GNUNET_i2s (&p1->id));
91 99
@@ -96,36 +104,47 @@ testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
96 GNUNET_SCHEDULER_add_now (&end, NULL); 104 GNUNET_SCHEDULER_add_now (&end, NULL);
97} 105}
98 106
107
99static void 108static void
100notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) 109notify_connect (void *cls,
110 const struct GNUNET_PeerIdentity *peer)
101{ 111{
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", 112 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
113 "Peer `%s' connected \n",
103 GNUNET_i2s (peer)); 114 GNUNET_i2s (peer));
104 connected++; 115 connected++;
105} 116}
106 117
118
107static void 119static void
108notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 120notify_disconnect (void *cls,
121 const struct GNUNET_PeerIdentity *peer)
109{ 122{
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", 123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
124 "Peer `%s' disconnected \n",
111 GNUNET_i2s (peer)); 125 GNUNET_i2s (peer));
112} 126}
113 127
128
114static void 129static void
115notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 130notify_receive (void *cls,
131 const struct GNUNET_PeerIdentity *peer,
116 const struct GNUNET_MessageHeader *message) 132 const struct GNUNET_MessageHeader *message)
117{ 133{
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving\n"); 134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
135 "Receiving\n");
119} 136}
120 137
121void 138
139static void
122start_cb (struct PeerContext *p, void *cls) 140start_cb (struct PeerContext *p, void *cls)
123{ 141{
124 static int started; 142 static int started;
125 143
126 started++; 144 started++;
127 145
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, 146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Peer %u (`%s') started\n", p->no,
129 GNUNET_i2s (&p->id)); 148 GNUNET_i2s (&p->id));
130 149
131 if (started != 2) 150 if (started != 2)
@@ -138,11 +157,12 @@ start_cb (struct PeerContext *p, void *cls)
138 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); 157 p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id));
139 GNUNET_free (sender_c); 158 GNUNET_free (sender_c);
140 159
141 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, 160 cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2,
161 &testing_connect_cb,
142 NULL); 162 NULL);
143
144} 163}
145 164
165
146static void 166static void
147run (void *cls, char *const *args, const char *cfgfile, 167run (void *cls, char *const *args, const char *cfgfile,
148 const struct GNUNET_CONFIGURATION_Handle *cfg) 168 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -167,41 +187,38 @@ run (void *cls, char *const *args, const char *cfgfile,
167 { 187 {
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
169 "Peer1 was not started successfully\n"); 189 "Peer1 was not started successfully\n");
170 if (timeout_task != NULL) 190 GNUNET_SCHEDULER_shutdown ();
171 GNUNET_SCHEDULER_cancel (timeout_task);
172 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
173 } 191 }
174 if (p2 == NULL) 192 if (p2 == NULL)
175 { 193 {
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 "Peer2 was not started successfully\n"); 195 "Peer2 was not started successfully\n");
178 if (timeout_task != NULL) 196 GNUNET_SCHEDULER_shutdown ();
179 GNUNET_SCHEDULER_cancel (timeout_task);
180 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
181 } 197 }
182} 198}
183 199
200
184int 201int
185main (int argc, char *argv[]) 202main (int argc, char *argv[])
186{ 203{
187 GNUNET_log_setup ("test_transport_testing", 204 char *const argv_1[] = {
188 "WARNING", 205 "test_transport_testing",
189 NULL);
190
191 char *const argv_1[] = { "test_transport_testing",
192 "-c", 206 "-c",
193 "test_transport_api_data.conf", 207 "test_transport_api_data.conf",
194 NULL 208 NULL
195 }; 209 };
196
197 struct GNUNET_GETOPT_CommandLineOption options[] = { 210 struct GNUNET_GETOPT_CommandLineOption options[] = {
198 GNUNET_GETOPT_OPTION_END 211 GNUNET_GETOPT_OPTION_END
199 }; 212 };
200 213
214 GNUNET_log_setup ("test_transport_testing",
215 "WARNING",
216 NULL);
201 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1, 217 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, argv_1,
202 "test_transport_testing", "nohelp", options, &run, &ret); 218 "test_transport_testing", "nohelp", options,
219 &run, &ret);
203 220
204 return ret; 221 return ret;
205} 222}
206 223
207/* end of test_transport_api.c */ 224/* end of test_transport_testing.c */