aboutsummaryrefslogtreecommitdiff
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.c135
1 files changed, 120 insertions, 15 deletions
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c
index f4785fcd5..c3f802b55 100644
--- a/src/transport/test_transport_blacklisting.c
+++ b/src/transport/test_transport_blacklisting.c
@@ -186,8 +186,41 @@ start_cb(struct PeerContext *p, void *cls)
186 186
187} 187}
188 188
189static int check_bl_config (char *src, char *dest) 189static int check_blacklist_config (char *cfg_file,
190 struct GNUNET_PeerIdentity *peer, struct GNUNET_PeerIdentity *bl_peer)
190{ 191{
192 struct GNUNET_CONFIGURATION_Handle *cfg;
193 char *section;
194 char *peer_str;
195 cfg = GNUNET_CONFIGURATION_create ();
196 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file))
197 {
198 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file);
199 GNUNET_CONFIGURATION_destroy (cfg);
200 return GNUNET_SYSERR;
201 }
202
203 peer_str = GNUNET_strdup (GNUNET_i2s_full(peer));
204 GNUNET_asprintf (&section, "transport-blacklist-%s", peer_str);
205
206 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section, GNUNET_i2s_full(bl_peer)))
207 {
208 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
209 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n",
210 cfg_file, peer_str, GNUNET_i2s_full(bl_peer));
211 GNUNET_CONFIGURATION_destroy (cfg);
212 GNUNET_free (section);
213 GNUNET_free (peer_str);
214 return GNUNET_SYSERR;
215 }
216
217 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
218 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n",
219 cfg_file, peer_str, GNUNET_i2s_full(bl_peer));
220
221 GNUNET_CONFIGURATION_destroy (cfg);
222 GNUNET_free (section);
223 GNUNET_free (peer_str);
191 return GNUNET_OK; 224 return GNUNET_OK;
192} 225}
193 226
@@ -218,57 +251,130 @@ run_stage(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
218 else if (0 251 else if (0
219 == strcmp (test_name, "test_transport_blacklisting_outbound_bl_full")) 252 == strcmp (test_name, "test_transport_blacklisting_outbound_bl_full"))
220 { 253 {
254 char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf";
255 char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
221 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 256 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
222 "test_transport_blacklisting_cfg_blp_peer1_full.conf", 1, NULL, NULL, 257 cfg_p1 , 1, NULL, NULL, NULL, &start_cb, NULL );
223 NULL, &start_cb, NULL );
224 258
225 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 259 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
226 "test_transport_blacklisting_cfg_peer2.conf", 2, NULL, NULL, NULL, 260 cfg_p2, 2, NULL, NULL, NULL,
227 &start_cb, NULL ); 261 &start_cb, NULL );
262
263 /* check if configuration contain correct blacklist entries */
264 if ((GNUNET_SYSERR == check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
265 (GNUNET_SYSERR == check_blacklist_config (cfg_p2, &p2->id, &p1->id)) )
266 {
267 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p1);
268 p1 = NULL;
269 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
270 p2 = NULL;
271 ok = 1;
272 GNUNET_SCHEDULER_add_now (&end, NULL );
273 }
274
228 } 275 }
229 else if (0 276 else if (0
230 == strcmp (test_name, "test_transport_blacklisting_outbound_bl_plugin")) 277 == strcmp (test_name, "test_transport_blacklisting_outbound_bl_plugin"))
231 { 278 {
279 char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_plugin.conf";
280 char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
281
232 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 282 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
233 "test_transport_blacklisting_cfg_blp_peer1_plugin.conf", 1, NULL, 283 cfg_p1, 1, NULL,
234 NULL, NULL, &start_cb, NULL ); 284 NULL, NULL, &start_cb, NULL );
235 285
236 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 286 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
237 "test_transport_blacklisting_cfg_peer2.conf", 2, NULL, NULL, NULL, 287 cfg_p2, 2, NULL, NULL, NULL,
238 &start_cb, NULL ); 288 &start_cb, NULL );
289
290 /* check if configuration contain correct blacklist entries */
291 if ((GNUNET_SYSERR == check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
292 (GNUNET_SYSERR == check_blacklist_config (cfg_p2, &p2->id, &p1->id)) )
293 {
294 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p1);
295 p1 = NULL;
296 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
297 p2 = NULL;
298 ok = 1;
299 GNUNET_SCHEDULER_add_now (&end, NULL );
300 }
239 } 301 }
240 else if (0 302 else if (0
241 == strcmp (test_name, "test_transport_blacklisting_inbound_bl_full")) 303 == strcmp (test_name, "test_transport_blacklisting_inbound_bl_full"))
242 { 304 {
305 char * cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
306 char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
307
243 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 308 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
244 "test_transport_blacklisting_cfg_peer1.conf", 1, NULL, NULL, NULL, 309 cfg_p1, 1, NULL, NULL, NULL,
245 &start_cb, NULL ); 310 &start_cb, NULL );
246 311
247 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 312 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
248 "test_transport_blacklisting_cfg_blp_peer2_full.conf", 2, NULL, NULL, 313 cfg_p2, 2, NULL, NULL,
249 NULL, &start_cb, NULL ); 314 NULL, &start_cb, NULL );
315
316 /* check if configuration contain correct blacklist entries */
317 if ((GNUNET_SYSERR == check_blacklist_config (cfg_p2, &p2->id, &p1->id)) )
318 {
319 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p1);
320 p1 = NULL;
321 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
322 p2 = NULL;
323 ok = 1;
324 GNUNET_SCHEDULER_add_now (&end, NULL );
325 }
250 } 326 }
251 else if (0 327 else if (0
252 == strcmp (test_name, "test_transport_blacklisting_inbound_bl_plugin")) 328 == strcmp (test_name, "test_transport_blacklisting_inbound_bl_plugin"))
253 { 329 {
330 char * cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf";
331 char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_plugin.conf";
332
254 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 333 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
255 "test_transport_blacklisting_cfg_peer1.conf", 1, NULL, NULL, NULL, 334 cfg_p1, 1, NULL, NULL, NULL,
256 &start_cb, NULL ); 335 &start_cb, NULL );
257 336
258 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 337 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
259 "test_transport_blacklisting_cfg_blp_peer2_plugin.conf", 2, NULL, 338 cfg_p2, 2, NULL, NULL,
260 NULL, NULL, &start_cb, NULL ); 339 NULL, &start_cb, NULL );
340
341 /* check if configuration contain correct blacklist entries */
342 if ((GNUNET_SYSERR == check_blacklist_config (cfg_p2, &p2->id, &p1->id)) )
343 {
344 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p1);
345 p1 = NULL;
346 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
347 p2 = NULL;
348 ok = 1;
349 GNUNET_SCHEDULER_add_now (&end, NULL );
350 }
351
261 } 352 }
262 else if (0 353 else if (0
263 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins")) 354 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins"))
264 { 355 {
356 char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf";
357 char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf";
358
265 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 359 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
266 "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf", 1, 360 cfg_p1, 1,
267 NULL, NULL, NULL, &start_cb, NULL ); 361 NULL, NULL, NULL, &start_cb, NULL );
268 362
269 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 363 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
270 "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf", 2, 364 cfg_p2, 2,
271 NULL, NULL, NULL, &start_cb, NULL ); 365 NULL, NULL, NULL, &start_cb, NULL );
366
367 /* check if configuration contain correct blacklist entries */
368 if ((GNUNET_SYSERR == check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
369 (GNUNET_SYSERR == check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
370 {
371 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p1);
372 p1 = NULL;
373 GNUNET_TRANSPORT_TESTING_stop_peer(tth, p2);
374 p2 = NULL;
375 ok = 1;
376 GNUNET_SCHEDULER_add_now (&end, NULL );
377 }
272 } 378 }
273 else 379 else
274 { 380 {
@@ -311,8 +417,7 @@ run_stage(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
311 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); 417 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED");
312 418
313 if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) 419 if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
314 || (0 420 || (0 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins")))
315 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins")))
316 { 421 {
317 if ((GNUNET_NO != started) && (GNUNET_YES == connected)) 422 if ((GNUNET_NO != started) && (GNUNET_YES == connected))
318 ok = 0; 423 ok = 0;