summaryrefslogtreecommitdiff
path: root/src/transport/test_transport_blacklisting.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_transport_blacklisting.c')
-rw-r--r--src/transport/test_transport_blacklisting.c737
1 files changed, 376 insertions, 361 deletions
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c
index 1d8ef3fde..ef7f96d99 100644
--- a/src/transport/test_transport_blacklisting.c
+++ b/src/transport/test_transport_blacklisting.c
@@ -58,132 +58,134 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext *p1;
58 58
59struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; 59struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
60 60
61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest * cc; 61static struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
62 62
63struct GNUNET_TRANSPORT_TESTING_Handle *tth; 63struct GNUNET_TRANSPORT_TESTING_Handle *tth;
64 64
65/** 65/**
66 * How long until we give up on transmitting the message? 66 * How long until we give up on transmitting the message?
67 */ 67 */
68#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20) 68#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
69 69
70#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) 70#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \
71 10)
71 72
72static int stage; 73static int stage;
73static int ok; 74static int ok;
74static int connected; 75static int connected;
75 76
76static struct GNUNET_SCHEDULER_Task * die_task; 77static struct GNUNET_SCHEDULER_Task *die_task;
77 78
78static struct GNUNET_SCHEDULER_Task * timeout_task; 79static struct GNUNET_SCHEDULER_Task *timeout_task;
79 80
80static struct GNUNET_SCHEDULER_Task * stage_task; 81static struct GNUNET_SCHEDULER_Task *stage_task;
81 82
82#if VERBOSE 83#if VERBOSE
83#define OKPP do { ok++; fprintf(stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 84#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, \
85 __FILE__, __LINE__); } while (0)
84#else 86#else
85#define OKPP do { ok++; } while (0) 87#define OKPP do { ok++; } while (0)
86#endif 88#endif
87 89
88 90
89static void 91static void
90run_stage(void *cls); 92run_stage (void *cls);
91 93
92 94
93static void 95static void
94end(void *cls) 96end (void *cls)
95{ 97{
96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); 98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n");
97 99
98 if (die_task != NULL) 100 if (die_task != NULL)
99 { 101 {
100 GNUNET_SCHEDULER_cancel(die_task); 102 GNUNET_SCHEDULER_cancel (die_task);
101 die_task = NULL; 103 die_task = NULL;
102 } 104 }
103 105
104 if (timeout_task != NULL) 106 if (timeout_task != NULL)
105 { 107 {
106 GNUNET_SCHEDULER_cancel(timeout_task); 108 GNUNET_SCHEDULER_cancel (timeout_task);
107 timeout_task = NULL; 109 timeout_task = NULL;
108 } 110 }
109 111
110 if (stage_task != NULL) 112 if (stage_task != NULL)
111 { 113 {
112 GNUNET_SCHEDULER_cancel(stage_task); 114 GNUNET_SCHEDULER_cancel (stage_task);
113 stage_task = NULL; 115 stage_task = NULL;
114 } 116 }
115 117
116 if (cc != NULL) 118 if (cc != NULL)
117 { 119 {
118 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 120 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
119 cc = NULL; 121 cc = NULL;
120 } 122 }
121 123
122 if (p1 != NULL) 124 if (p1 != NULL)
123 { 125 {
124 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 126 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
125 p1 = NULL; 127 p1 = NULL;
126 } 128 }
127 if (p2 != NULL) 129 if (p2 != NULL)
128 { 130 {
129 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 131 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
130 p2 = NULL; 132 p2 = NULL;
131 } 133 }
132} 134}
133 135
134 136
135static void 137static void
136end_badly(void *cls) 138end_badly (void *cls)
137{ 139{
138 die_task = NULL; 140 die_task = NULL;
139 141
140 if (timeout_task != NULL) 142 if (timeout_task != NULL)
141 { 143 {
142 GNUNET_SCHEDULER_cancel(timeout_task); 144 GNUNET_SCHEDULER_cancel (timeout_task);
143 timeout_task = NULL; 145 timeout_task = NULL;
144 } 146 }
145 147
146 if (stage_task != NULL) 148 if (stage_task != NULL)
147 { 149 {
148 GNUNET_SCHEDULER_cancel(stage_task); 150 GNUNET_SCHEDULER_cancel (stage_task);
149 stage_task = NULL; 151 stage_task = NULL;
150 } 152 }
151 153
152 if (cc != NULL) 154 if (cc != NULL)
153 { 155 {
154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 156 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
155 cc = NULL; 157 cc = NULL;
156 } 158 }
157 if (p1 != NULL) 159 if (p1 != NULL)
158 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 160 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
159 if (p2 != NULL) 161 if (p2 != NULL)
160 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 162 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
161 163
162 ok = GNUNET_SYSERR; 164 ok = GNUNET_SYSERR;
163} 165}
164 166
165static void 167static void
166testing_connect_cb(void *cls) 168testing_connect_cb (void *cls)
167{ 169{
168 cc = NULL; 170 cc = NULL;
169 char *p1_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); 171 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
170 172
171 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", 173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n",
172 p1->no, p1_c, p2->no, GNUNET_i2s(&p2->id)); 174 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id));
173 GNUNET_free(p1_c); 175 GNUNET_free (p1_c);
174 connected = GNUNET_YES; 176 connected = GNUNET_YES;
175 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); 177 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL);
176} 178}
177 179
178 180
179static void 181static void
180connect_timeout(void *cls) 182connect_timeout (void *cls)
181{ 183{
182 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 184 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
183 "Peers not connected, next stage\n"); 185 "Peers not connected, next stage\n");
184 timeout_task = NULL; 186 timeout_task = NULL;
185 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, 187 stage_task = GNUNET_SCHEDULER_add_now (&run_stage,
186 NULL); 188 NULL);
187} 189}
188 190
189 191
@@ -191,371 +193,384 @@ static int started;
191 193
192 194
193static void 195static void
194start_cb(void *cls) 196start_cb (void *cls)
195{ 197{
196 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 198 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
197 199
198 started++; 200 started++;
199 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
200 "Peer %u (`%s') started\n", 202 "Peer %u (`%s') started\n",
201 p->no, 203 p->no,
202 GNUNET_i2s_full(&p->id)); 204 GNUNET_i2s_full (&p->id));
203 205
204 if (started != 2) 206 if (started != 2)
205 return; 207 return;
206 208
207 char *sender_c = GNUNET_strdup(GNUNET_i2s(&p1->id)); 209 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id));
208 210
209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
210 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 212 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
211 p1->no, 213 p1->no,
212 sender_c, 214 sender_c,
213 p2->no, 215 p2->no,
214 GNUNET_i2s(&p2->id)); 216 GNUNET_i2s (&p2->id));
215 GNUNET_free(sender_c); 217 GNUNET_free (sender_c);
216 218
217 cc = GNUNET_TRANSPORT_TESTING_connect_peers(p1, 219 cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1,
218 p2, 220 p2,
219 &testing_connect_cb, 221 &testing_connect_cb,
220 NULL); 222 NULL);
221} 223}
222 224
223 225
224static int 226static int
225check_blacklist_config(const char *cfg_file, 227check_blacklist_config (const char *cfg_file,
226 struct GNUNET_PeerIdentity *peer, 228 struct GNUNET_PeerIdentity *peer,
227 struct GNUNET_PeerIdentity *bl_peer) 229 struct GNUNET_PeerIdentity *bl_peer)
228{ 230{
229 struct GNUNET_CONFIGURATION_Handle *cfg; 231 struct GNUNET_CONFIGURATION_Handle *cfg;
230 char *section; 232 char *section;
231 char *peer_str; 233 char *peer_str;
232 234
233 cfg = GNUNET_CONFIGURATION_create(); 235 cfg = GNUNET_CONFIGURATION_create ();
234 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_file)) 236 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file))
235 { 237 {
236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); 238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n",
237 GNUNET_CONFIGURATION_destroy(cfg); 239 cfg_file);
238 return GNUNET_SYSERR; 240 GNUNET_CONFIGURATION_destroy (cfg);
239 } 241 return GNUNET_SYSERR;
240 242 }
241 peer_str = GNUNET_strdup(GNUNET_i2s_full(peer)); 243
242 GNUNET_asprintf(&section, "transport-blacklist-%s", peer_str); 244 peer_str = GNUNET_strdup (GNUNET_i2s_full (peer));
243 245 GNUNET_asprintf (&section, "transport-blacklist-%s", peer_str);
244 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, section, GNUNET_i2s_full(bl_peer))) 246
245 { 247 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section,
246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 248 GNUNET_i2s_full (bl_peer)))
247 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", 249 {
248 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
249 GNUNET_CONFIGURATION_destroy(cfg); 251 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n",
250 GNUNET_free(section); 252 cfg_file, peer_str, GNUNET_i2s_full (bl_peer));
251 GNUNET_free(peer_str); 253 GNUNET_CONFIGURATION_destroy (cfg);
252 return GNUNET_SYSERR; 254 GNUNET_free (section);
253 } 255 GNUNET_free (peer_str);
254 256 return GNUNET_SYSERR;
255 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 257 }
256 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", 258
257 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 259 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
258 260 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n",
259 GNUNET_CONFIGURATION_destroy(cfg); 261 cfg_file, peer_str, GNUNET_i2s_full (bl_peer));
260 GNUNET_free(section); 262
261 GNUNET_free(peer_str); 263 GNUNET_CONFIGURATION_destroy (cfg);
264 GNUNET_free (section);
265 GNUNET_free (peer_str);
262 return GNUNET_OK; 266 return GNUNET_OK;
263} 267}
264 268
265 269
266static void 270static void
267run_stage(void *cls) 271run_stage (void *cls)
268{ 272{
269 stage_task = NULL; 273 stage_task = NULL;
270 if (NULL != die_task) 274 if (NULL != die_task)
271 GNUNET_SCHEDULER_cancel(die_task); 275 GNUNET_SCHEDULER_cancel (die_task);
272 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 276 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
273 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); 277 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage);
274 278
275 if (0 == stage) 279 if (0 == stage)
280 {
281 started = GNUNET_NO;
282 connected = GNUNET_NO;
283 if (0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
276 { 284 {
277 started = GNUNET_NO; 285 /* Try to connect peers successfully */
278 connected = GNUNET_NO; 286 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
279 if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) 287 "test_transport_blacklisting_cfg_peer1.conf",
280 { 288 1,
281 /* Try to connect peers successfully */ 289 NULL,
282 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth, 290 NULL,
283 "test_transport_blacklisting_cfg_peer1.conf", 291 NULL,
284 1, 292 NULL,
285 NULL, 293 &start_cb,
286 NULL, 294 NULL);
287 NULL, 295
288 NULL, 296 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
289 &start_cb, 297 "test_transport_blacklisting_cfg_peer2.conf",
290 NULL); 298 2,
291 299 NULL,
292 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth, 300 NULL,
293 "test_transport_blacklisting_cfg_peer2.conf", 301 NULL,
294 2, 302 NULL,
295 NULL, 303 &start_cb,
296 NULL, 304 NULL);
297 NULL,
298 NULL,
299 &start_cb,
300 NULL);
301 }
302 else if (0 == strcmp(test_name,
303 "test_transport_blacklisting_outbound_bl_full"))
304 {
305 const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf";
306 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
307
308 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
309 cfg_p1,
310 1, NULL, NULL, NULL,
311 NULL,
312 &start_cb, NULL);
313 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
314 cfg_p2, 2,
315 NULL, NULL, NULL,
316 NULL,
317 &start_cb, NULL);
318
319 /* check if configuration contain correct blacklist entries */
320 if ((GNUNET_SYSERR ==
321 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
322 (GNUNET_SYSERR ==
323 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
324 {
325 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
326 p1 = NULL;
327 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
328 p2 = NULL;
329 ok = 1;
330 GNUNET_SCHEDULER_add_now(&end, NULL);
331 }
332 }
333 else if (0
334 == strcmp(test_name, "test_transport_blacklisting_outbound_bl_plugin"))
335 {
336 const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf";
337 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
338
339 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
340 cfg_p1,
341 1,
342 NULL,
343 NULL,
344 NULL,
345 NULL,
346 &start_cb,
347 NULL);
348
349 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
350 cfg_p2, 2,
351 NULL,
352 NULL,
353 NULL,
354 NULL,
355 &start_cb,
356 NULL);
357
358 /* check if configuration contain correct blacklist entries */
359 if ((GNUNET_SYSERR ==
360 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
361 (GNUNET_SYSERR ==
362 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
363 {
364 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
365 p1 = NULL;
366 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
367 p2 = NULL;
368 ok = 1;
369 GNUNET_SCHEDULER_add_now(&end, NULL);
370 }
371 }
372 else if (0 == strcmp(test_name,
373 "test_transport_blacklisting_inbound_bl_full"))
374 {
375 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
376 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
377
378 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
379 cfg_p1, 1,
380 NULL,
381 NULL, NULL, NULL,
382 &start_cb, NULL);
383
384 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
385 cfg_p2, 2,
386 NULL,
387 NULL, NULL, NULL,
388 &start_cb, NULL);
389
390 /* check if configuration contain correct blacklist entries */
391 if ((GNUNET_SYSERR ==
392 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
393 {
394 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
395 p1 = NULL;
396 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
397 p2 = NULL;
398 ok = 1;
399 GNUNET_SCHEDULER_add_now(&end, NULL);
400 }
401 }
402 else if (0 == strcmp(test_name,
403 "test_transport_blacklisting_inbound_bl_plugin"))
404 {
405 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
406 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
407
408 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
409 cfg_p1, 1,
410 NULL,
411 NULL, NULL, NULL,
412 &start_cb, NULL);
413
414 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
415 cfg_p2, 2,
416 NULL,
417 NULL, NULL,
418 NULL,
419 &start_cb, NULL);
420
421 /* check if configuration contain correct blacklist entries */
422 if ((GNUNET_SYSERR ==
423 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
424 {
425 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
426 p1 = NULL;
427 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
428 p2 = NULL;
429 ok = 1;
430 GNUNET_SCHEDULER_add_now(&end, NULL);
431 }
432 }
433 else if (0 == strcmp(test_name,
434 "test_transport_blacklisting_multiple_plugins"))
435 {
436 const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf";
437 const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf";
438
439 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
440 cfg_p1, 1,
441 NULL,
442 NULL, NULL, NULL,
443 &start_cb, NULL);
444
445 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
446 cfg_p2, 2,
447 NULL,
448 NULL, NULL, NULL,
449 &start_cb, NULL);
450
451 /* check if configuration contain correct blacklist entries */
452 if ((GNUNET_SYSERR ==
453 check_blacklist_config(cfg_p1, &p1->id, &p2->id)) ||
454 (GNUNET_SYSERR ==
455 check_blacklist_config(cfg_p2, &p2->id, &p1->id)))
456 {
457 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
458 p1 = NULL;
459 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
460 p2 = NULL;
461 ok = 1;
462 GNUNET_SCHEDULER_add_now(&end, NULL);
463 }
464 }
465 else
466 {
467 GNUNET_break(0);
468 GNUNET_SCHEDULER_add_now(&end, NULL);
469 }
470
471 if ((NULL == p1) || (NULL == p2))
472 {
473 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
474 ok = 1;
475 GNUNET_SCHEDULER_add_now(&end, NULL);
476 }
477
478 timeout_task = GNUNET_SCHEDULER_add_delayed(CONNECT_TIMEOUT,
479 &connect_timeout,
480 NULL);
481 stage++;
482 return;
483 } 305 }
484 306 else if (0 == strcmp (test_name,
485 if (cc != NULL) 307 "test_transport_blacklisting_outbound_bl_full"))
486 { 308 {
487 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc); 309 const char *cfg_p1 =
488 cc = NULL; 310 "test_transport_blacklisting_cfg_blp_peer1_full.conf";
311 const char *cfg_p2 =
312 "test_transport_blacklisting_cfg_blp_peer2_full.conf";
313
314 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
315 cfg_p1,
316 1, NULL, NULL, NULL,
317 NULL,
318 &start_cb, NULL);
319 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
320 cfg_p2, 2,
321 NULL, NULL, NULL,
322 NULL,
323 &start_cb, NULL);
324
325 /* check if configuration contain correct blacklist entries */
326 if ((GNUNET_SYSERR ==
327 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
328 (GNUNET_SYSERR ==
329 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
330 {
331 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
332 p1 = NULL;
333 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
334 p2 = NULL;
335 ok = 1;
336 GNUNET_SCHEDULER_add_now (&end, NULL);
337 }
489 } 338 }
490 339 else if (0
491 if (p1 != NULL) 340 == strcmp (test_name,
341 "test_transport_blacklisting_outbound_bl_plugin"))
492 { 342 {
493 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 343 const char *cfg_p1 =
494 p1 = NULL; 344 "test_transport_blacklisting_cfg_blp_peer1_plugin.conf";
345 const char *cfg_p2 =
346 "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
347
348 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
349 cfg_p1,
350 1,
351 NULL,
352 NULL,
353 NULL,
354 NULL,
355 &start_cb,
356 NULL);
357
358 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
359 cfg_p2, 2,
360 NULL,
361 NULL,
362 NULL,
363 NULL,
364 &start_cb,
365 NULL);
366
367 /* check if configuration contain correct blacklist entries */
368 if ((GNUNET_SYSERR ==
369 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
370 (GNUNET_SYSERR ==
371 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
372 {
373 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
374 p1 = NULL;
375 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
376 p2 = NULL;
377 ok = 1;
378 GNUNET_SCHEDULER_add_now (&end, NULL);
379 }
495 } 380 }
496 if (p2 != NULL) 381 else if (0 == strcmp (test_name,
382 "test_transport_blacklisting_inbound_bl_full"))
383 {
384 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
385 const char *cfg_p2 =
386 "test_transport_blacklisting_cfg_blp_peer2_full.conf";
387
388 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
389 cfg_p1, 1,
390 NULL,
391 NULL, NULL, NULL,
392 &start_cb, NULL);
393
394 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
395 cfg_p2, 2,
396 NULL,
397 NULL, NULL, NULL,
398 &start_cb, NULL);
399
400 /* check if configuration contain correct blacklist entries */
401 if ((GNUNET_SYSERR ==
402 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
403 {
404 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
405 p1 = NULL;
406 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
407 p2 = NULL;
408 ok = 1;
409 GNUNET_SCHEDULER_add_now (&end, NULL);
410 }
411 }
412 else if (0 == strcmp (test_name,
413 "test_transport_blacklisting_inbound_bl_plugin"))
414 {
415 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
416 const char *cfg_p2 =
417 "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
418
419 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
420 cfg_p1, 1,
421 NULL,
422 NULL, NULL, NULL,
423 &start_cb, NULL);
424
425 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
426 cfg_p2, 2,
427 NULL,
428 NULL, NULL,
429 NULL,
430 &start_cb, NULL);
431
432 /* check if configuration contain correct blacklist entries */
433 if ((GNUNET_SYSERR ==
434 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
435 {
436 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
437 p1 = NULL;
438 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
439 p2 = NULL;
440 ok = 1;
441 GNUNET_SCHEDULER_add_now (&end, NULL);
442 }
443 }
444 else if (0 == strcmp (test_name,
445 "test_transport_blacklisting_multiple_plugins"))
446 {
447 const char *cfg_p1 =
448 "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf";
449 const char *cfg_p2 =
450 "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf";
451
452 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
453 cfg_p1, 1,
454 NULL,
455 NULL, NULL, NULL,
456 &start_cb, NULL);
457
458 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
459 cfg_p2, 2,
460 NULL,
461 NULL, NULL, NULL,
462 &start_cb, NULL);
463
464 /* check if configuration contain correct blacklist entries */
465 if ((GNUNET_SYSERR ==
466 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
467 (GNUNET_SYSERR ==
468 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
469 {
470 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
471 p1 = NULL;
472 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
473 p2 = NULL;
474 ok = 1;
475 GNUNET_SCHEDULER_add_now (&end, NULL);
476 }
477 }
478 else
497 { 479 {
498 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 480 GNUNET_break (0);
499 p2 = NULL; 481 GNUNET_SCHEDULER_add_now (&end, NULL);
500 } 482 }
501 483
502 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", 484 if ((NULL == p1) || (NULL == p2))
503 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", 485 {
504 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); 486 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
487 ok = 1;
488 GNUNET_SCHEDULER_add_now (&end, NULL);
489 }
505 490
506 if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl")) 491 timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT,
507 || (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins"))) 492 &connect_timeout,
493 NULL);
494 stage++;
495 return;
496 }
497
498 if (cc != NULL)
499 {
500 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
501 cc = NULL;
502 }
503
504 if (p1 != NULL)
505 {
506 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
507 p1 = NULL;
508 }
509 if (p2 != NULL)
510 {
511 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
512 p2 = NULL;
513 }
514
515 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n",
516 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED",
517 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED");
518
519 if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
520 || (0 == strcmp (test_name,
521 "test_transport_blacklisting_multiple_plugins")))
522 {
523 if ((GNUNET_NO != started) && (GNUNET_YES == connected))
524 ok = 0;
525 else
508 { 526 {
509 if ((GNUNET_NO != started) && (GNUNET_YES == connected)) 527 GNUNET_break (0);
510 ok = 0; 528 ok = 1;
511 else
512 {
513 GNUNET_break(0);
514 ok = 1;
515 }
516 } 529 }
530 }
517 else 531 else
532 {
533 if ((GNUNET_NO != started) && (GNUNET_YES != connected))
534 ok = 0;
535 else
518 { 536 {
519 if ((GNUNET_NO != started) && (GNUNET_YES != connected)) 537 ok = 1;
520 ok = 0;
521 else
522 {
523 ok = 1;
524 }
525 } 538 }
526 GNUNET_SCHEDULER_add_now(&end, NULL); 539 }
540 GNUNET_SCHEDULER_add_now (&end, NULL);
527} 541}
528 542
529static void 543static void
530run(void *cls, char * const *args, const char *cfgfile, 544run (void *cls, char *const *args, const char *cfgfile,
531 const struct GNUNET_CONFIGURATION_Handle *cfg) 545 const struct GNUNET_CONFIGURATION_Handle *cfg)
532{ 546{
533 connected = GNUNET_NO; 547 connected = GNUNET_NO;
534 stage = 0; 548 stage = 0;
535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); 549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name);
536 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL); 550 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL);
537} 551}
538 552
539int 553int
540main(int argc, char *argv0[]) 554main (int argc, char *argv0[])
541{ 555{
542 ok = 1; 556 ok = 1;
543 557
544 test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0[0]); 558 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0[0]);
545 559
546 GNUNET_log_setup("test-transport-api-blacklisting", "WARNING", NULL); 560 GNUNET_log_setup ("test-transport-api-blacklisting", "WARNING", NULL);
547 561
548 static char * const argv[] = 562 static char *const argv[] =
549 { "date", "-c", "test_transport_api_data.conf", NULL }; 563 { "date", "-c", "test_transport_api_data.conf", NULL };
550 static struct GNUNET_GETOPT_CommandLineOption options[] = 564 static struct GNUNET_GETOPT_CommandLineOption options[] =
551 { GNUNET_GETOPT_OPTION_END }; 565 { GNUNET_GETOPT_OPTION_END };
552 566
553 tth = GNUNET_TRANSPORT_TESTING_init(); 567 tth = GNUNET_TRANSPORT_TESTING_init ();
554 568
555 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv, 569 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv,
556 "test-transport-api-blacklisting", "nohelp", options, &run, NULL); 570 "test-transport-api-blacklisting", "nohelp", options,
571 &run, NULL);
557 572
558 GNUNET_TRANSPORT_TESTING_done(tth); 573 GNUNET_TRANSPORT_TESTING_done (tth);
559 574
560 return ok; 575 return ok;
561} 576}