diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-07-10 16:41:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-07-10 16:41:45 +0000 |
commit | c6444a089a860da694842942283079a25bc1e957 (patch) | |
tree | d35d30bc35acf05681f7f89057ffdc2e774b33ec /src/transport/test_transport_api_blacklisting.c | |
parent | 4f77ea5b2b3d53a21f70237f8b92a9a2273c21bf (diff) | |
download | gnunet-c6444a089a860da694842942283079a25bc1e957.tar.gz gnunet-c6444a089a860da694842942283079a25bc1e957.zip |
fold bidirectional test into main test_ats_api
Diffstat (limited to 'src/transport/test_transport_api_blacklisting.c')
-rw-r--r-- | src/transport/test_transport_api_blacklisting.c | 450 |
1 files changed, 118 insertions, 332 deletions
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 | ||
31 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p1; | 31 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
32 | |||
33 | static struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; | ||
34 | |||
35 | static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; | ||
36 | |||
37 | static struct GNUNET_TRANSPORT_TransmitHandle *th; | ||
38 | |||
39 | static 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 | ||
56 | static int ok; | 38 | static struct GNUNET_TRANSPORT_TransmitHandle *th; |
39 | |||
40 | static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc; | ||
41 | |||
57 | static int connected; | 42 | static int connected; |
58 | static int blacklist_request_p1; | ||
59 | static int blacklist_request_p2; | ||
60 | 43 | ||
61 | static struct GNUNET_TRANSPORT_Blacklist * blacklist_p1; | 44 | static int blacklist_request_p1; |
62 | 45 | ||
63 | static struct GNUNET_TRANSPORT_Blacklist * blacklist_p2; | 46 | static int blacklist_request_p2; |
64 | 47 | ||
65 | static struct GNUNET_SCHEDULER_Task * die_task; | 48 | static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1; |
66 | 49 | ||
67 | static struct GNUNET_SCHEDULER_Task * send_task; | 50 | static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2; |
68 | 51 | ||
69 | static struct GNUNET_SCHEDULER_Task * shutdown_task; | 52 | static struct GNUNET_SCHEDULER_Task *send_task; |
70 | 53 | ||
71 | #if VERBOSE | 54 | static 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 | ||
78 | static void | 57 | static void |
79 | end (void *cls) | 58 | end (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 | ||
140 | static void | 81 | static void |
141 | end_badly (void *cls) | 82 | custom_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 | ||
181 | static void | 112 | static void |
182 | notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer, | 113 | notify_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 | ||
217 | static size_t | 124 | static size_t |
218 | notify_ready (void *cls, size_t size, void *buf) | 125 | notify_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) | |||
262 | static void | 147 | static void |
263 | sendtask (void *cls) | 148 | sendtask (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, ¬ify_ready, | 153 | TIMEOUT, |
276 | p1); | 154 | ¬ify_ready, |
155 | ccc->p[0]); | ||
277 | } | 156 | } |
278 | 157 | ||
279 | 158 | ||
280 | static void | 159 | static void |
281 | notify_connect (void *cls, const struct GNUNET_PeerIdentity *peer) | 160 | notify_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 | ||
310 | static void | 175 | static void |
311 | notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | 176 | notify_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 | |||
328 | static void | ||
329 | testing_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 | ||
345 | static int | 191 | static int |
346 | blacklist_cb (void *cls, | 192 | blacklist_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 | ||
378 | static void | 227 | static void |
379 | start_cb (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, void *cls) | 228 | start_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 | |||
406 | static void | ||
407 | run (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 | ¬ify_receive, | ||
420 | ¬ify_connect, | ||
421 | ¬ify_disconnect, | ||
422 | &start_cb, | ||
423 | NULL); | ||
424 | |||
425 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, | ||
426 | "test_transport_api_tcp_peer2.conf", 2, | ||
427 | ¬ify_receive, | ||
428 | ¬ify_connect, | ||
429 | ¬ify_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 | ||
446 | static int | 243 | int |
447 | check () | 244 | main (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 = ¬ify_receive, | ||
252 | .nc = ¬ify_connect, | ||
253 | .nd = ¬ify_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 | ||
465 | int | ||
466 | main (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 */ |