diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-28 12:15:08 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-28 12:15:08 +0000 |
commit | 03daaebff579d25715c3db30e5076f5ae87bca9e (patch) | |
tree | e79d34e5f166df9612fa955614868c9fb369ad7a /src | |
parent | 9c841f1b0de6569cef5047e8ee49f47f808b3eae (diff) | |
download | gnunet-03daaebff579d25715c3db30e5076f5ae87bca9e.tar.gz gnunet-03daaebff579d25715c3db30e5076f5ae87bca9e.zip |
fixes to blacklisting
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/Makefile.am | 61 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_blacklist.c | 51 | ||||
-rw-r--r-- | src/transport/test_transport_blacklisting_cfg.c | 323 | ||||
-rw-r--r-- | src/transport/test_transport_blacklisting_cfg_blp_peer1.conf | 37 |
4 files changed, 92 insertions, 380 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index a7032e283..aad49299c 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -323,7 +323,11 @@ check_PROGRAMS = \ | |||
323 | $(HTTP_SERVER_PLUGIN_TEST) \ | 323 | $(HTTP_SERVER_PLUGIN_TEST) \ |
324 | $(HTTPS_SERVER_PLUGIN_TEST) \ | 324 | $(HTTPS_SERVER_PLUGIN_TEST) \ |
325 | test_transport_api_blacklisting \ | 325 | test_transport_api_blacklisting \ |
326 | test_transport_blacklisting_cfg \ | 326 | test_transport_blacklisting_no_bl \ |
327 | test_transport_blacklisting_outbound_bl_full \ | ||
328 | test_transport_blacklisting_outbound_bl_plugin \ | ||
329 | test_transport_blacklisting_inbound_bl_plugin \ | ||
330 | test_transport_blacklisting_inbound_bl_full \ | ||
327 | test_transport_api_disconnect_tcp \ | 331 | test_transport_api_disconnect_tcp \ |
328 | test_transport_api_bidirectional_connect \ | 332 | test_transport_api_bidirectional_connect \ |
329 | test_transport_api_tcp \ | 333 | test_transport_api_tcp \ |
@@ -374,7 +378,11 @@ TESTS = \ | |||
374 | $(UNIX_TEST) \ | 378 | $(UNIX_TEST) \ |
375 | $(WLAN_PLUGIN_TEST) \ | 379 | $(WLAN_PLUGIN_TEST) \ |
376 | test_transport_api_blacklisting \ | 380 | test_transport_api_blacklisting \ |
377 | test_transport_blacklisting_cfg \ | 381 | test_transport_blacklisting_no_bl \ |
382 | test_transport_blacklisting_outbound_bl_full \ | ||
383 | test_transport_blacklisting_outbound_bl_plugin \ | ||
384 | test_transport_blacklisting_inbound_bl_plugin \ | ||
385 | test_transport_blacklisting_inbound_bl_full \ | ||
378 | test_transport_api_disconnect_tcp \ | 386 | test_transport_api_disconnect_tcp \ |
379 | test_transport_api_bidirectional_connect \ | 387 | test_transport_api_bidirectional_connect \ |
380 | test_transport_api_tcp \ | 388 | test_transport_api_tcp \ |
@@ -445,16 +453,51 @@ test_transport_api_blacklisting_LDADD = \ | |||
445 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 453 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
446 | $(top_builddir)/src/util/libgnunetutil.la \ | 454 | $(top_builddir)/src/util/libgnunetutil.la \ |
447 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 455 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
448 | 456 | ||
449 | test_transport_blacklisting_cfg_SOURCES = \ | 457 | test_transport_blacklisting_no_bl_SOURCES = \ |
450 | test_transport_blacklisting_cfg.c | 458 | test_transport_blacklisting.c |
451 | test_transport_blacklisting_cfg_LDADD = \ | 459 | test_transport_blacklisting_no_bl_LDADD = \ |
452 | $(top_builddir)/src/transport/libgnunettransport.la \ | 460 | $(top_builddir)/src/transport/libgnunettransport.la \ |
453 | $(top_builddir)/src/hello/libgnunethello.la \ | 461 | $(top_builddir)/src/hello/libgnunethello.la \ |
454 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 462 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
455 | $(top_builddir)/src/util/libgnunetutil.la \ | 463 | $(top_builddir)/src/util/libgnunetutil.la \ |
456 | $(top_builddir)/src/transport/libgnunettransporttesting.la | 464 | $(top_builddir)/src/transport/libgnunettransporttesting.la |
457 | 465 | ||
466 | test_transport_blacklisting_outbound_bl_full_SOURCES = \ | ||
467 | test_transport_blacklisting.c | ||
468 | test_transport_blacklisting_outbound_bl_full_LDADD = \ | ||
469 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
470 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
471 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
472 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
473 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
474 | |||
475 | test_transport_blacklisting_outbound_bl_plugin_SOURCES = \ | ||
476 | test_transport_blacklisting.c | ||
477 | test_transport_blacklisting_outbound_bl_plugin_LDADD = \ | ||
478 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
479 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
480 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
481 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
482 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
483 | |||
484 | test_transport_blacklisting_inbound_bl_full_SOURCES = \ | ||
485 | test_transport_blacklisting.c | ||
486 | test_transport_blacklisting_inbound_bl_full_LDADD = \ | ||
487 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
488 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
489 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
490 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
491 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
492 | |||
493 | test_transport_blacklisting_inbound_bl_plugin_SOURCES = \ | ||
494 | test_transport_blacklisting.c | ||
495 | test_transport_blacklisting_inbound_bl_plugin_LDADD = \ | ||
496 | $(top_builddir)/src/transport/libgnunettransport.la \ | ||
497 | $(top_builddir)/src/hello/libgnunethello.la \ | ||
498 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
499 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
500 | $(top_builddir)/src/transport/libgnunettransporttesting.la | ||
458 | 501 | ||
459 | test_transport_api_disconnect_tcp_SOURCES = \ | 502 | test_transport_api_disconnect_tcp_SOURCES = \ |
460 | test_transport_api_disconnect.c | 503 | test_transport_api_disconnect.c |
@@ -984,7 +1027,9 @@ test_transport_api_unreliability_constant_udp_peer1.conf\ | |||
984 | test_transport_api_unreliability_constant_udp_peer2.conf\ | 1027 | test_transport_api_unreliability_constant_udp_peer2.conf\ |
985 | test_transport_blacklisting_cfg_peer1.conf \ | 1028 | test_transport_blacklisting_cfg_peer1.conf \ |
986 | test_transport_blacklisting_cfg_peer2.conf \ | 1029 | test_transport_blacklisting_cfg_peer2.conf \ |
987 | test_transport_blacklisting_cfg_blp_peer1.conf \ | 1030 | test_transport_blacklisting_cfg_blp_peer1_full.conf\ |
988 | test_transport_blacklisting_cfg_blp_peer2.conf\ | 1031 | test_transport_blacklisting_cfg_blp_peer1_plugin.conf \ |
1032 | test_transport_blacklisting_cfg_blp_peer2_full.conf\ | ||
1033 | test_transport_blacklisting_cfg_blp_peer2_plugin.conf \ | ||
989 | test_transport_api_http_reverse_peer1.conf \ | 1034 | test_transport_api_http_reverse_peer1.conf \ |
990 | test_transport_api_http_reverse_peer2.conf | 1035 | test_transport_api_http_reverse_peer2.conf |
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c index 3f9616e91..b1a0047f7 100644 --- a/src/transport/gnunet-service-transport_blacklist.c +++ b/src/transport/gnunet-service-transport_blacklist.c | |||
@@ -589,16 +589,21 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, | |||
589 | const char *transport_name) | 589 | const char *transport_name) |
590 | { | 590 | { |
591 | char * transport = NULL; | 591 | char * transport = NULL; |
592 | 592 | if (NULL != transport_name) | |
593 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 593 | { |
594 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
594 | "Adding peer `%s' with plugin `%s' to blacklist\n", | 595 | "Adding peer `%s' with plugin `%s' to blacklist\n", |
595 | GNUNET_i2s (peer), transport_name); | 596 | GNUNET_i2s (peer), transport_name); |
597 | transport = GNUNET_strdup (transport_name); | ||
598 | } | ||
599 | else | ||
600 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
601 | "Adding peer `%s' with all plugins to blacklist\n", | ||
602 | GNUNET_i2s (peer)); | ||
596 | if (blacklist == NULL) | 603 | if (blacklist == NULL) |
597 | blacklist = | 604 | blacklist = |
598 | GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE, | 605 | GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE, |
599 | GNUNET_NO); | 606 | GNUNET_NO); |
600 | if (NULL != transport_name) | ||
601 | transport = GNUNET_strdup (""); | ||
602 | 607 | ||
603 | GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey, | 608 | GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey, |
604 | transport, | 609 | transport, |
@@ -621,16 +626,30 @@ test_blacklisted (void *cls, const struct GNUNET_HashCode * key, void *value) | |||
621 | const char *transport_name = cls; | 626 | const char *transport_name = cls; |
622 | char *be = value; | 627 | char *be = value; |
623 | 628 | ||
624 | /* blacklist check for specific no specific transport*/ | 629 | /* Blacklist entry be: |
625 | if (transport_name == NULL) | 630 | * (NULL == be): peer is blacklisted with all plugins |
626 | return GNUNET_NO; | 631 | * (NULL != be): peer is blacklisted for a specific plugin |
627 | /* all plugins for this peer were blacklisted */ | 632 | * |
633 | * If (NULL != transport_name) we look for a transport specific entry: | ||
634 | * if (transport_name == be) forbidden | ||
635 | * | ||
636 | */ | ||
637 | |||
638 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
639 | "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", | ||
640 | GNUNET_h2s (key), | ||
641 | (NULL == transport_name) ? "unspecified" : transport_name, | ||
642 | (NULL == be) ? "all plugins" : be); | ||
643 | /* all plugins for this peer were blacklisted: disallow */ | ||
628 | if (NULL == value) | 644 | if (NULL == value) |
629 | return GNUNET_NO; | 645 | return GNUNET_NO; |
630 | 646 | ||
631 | /* blacklist check for specific transport */ | 647 | /* blacklist check for specific transport */ |
632 | if (0 == strcmp (transport_name, be)) | 648 | if ((NULL != transport_name) && (NULL != value)) |
633 | return GNUNET_NO; /* abort iteration! */ | 649 | { |
650 | if (0 == strcmp (transport_name, be)) | ||
651 | return GNUNET_NO; /* plugin is blacklisted! */ | ||
652 | } | ||
634 | return GNUNET_OK; | 653 | return GNUNET_OK; |
635 | } | 654 | } |
636 | 655 | ||
@@ -653,17 +672,23 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, | |||
653 | struct GST_BlacklistCheck *bc; | 672 | struct GST_BlacklistCheck *bc; |
654 | 673 | ||
655 | GNUNET_assert (peer != NULL); | 674 | GNUNET_assert (peer != NULL); |
675 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist check for peer `%s':%s\n", | ||
676 | GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified"); | ||
656 | 677 | ||
678 | /* Check local blacklist by iterating over hashmap | ||
679 | * If iteration is aborted, we found a matching blacklist entry */ | ||
657 | if ((blacklist != NULL) && | 680 | if ((blacklist != NULL) && |
658 | (GNUNET_SYSERR == | 681 | (GNUNET_SYSERR == |
659 | GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey, | 682 | GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, &peer->hashPubKey, |
660 | &test_blacklisted, | 683 | &test_blacklisted, |
661 | (void *) transport_name))) | 684 | (void *) transport_name))) |
662 | { | 685 | { |
663 | /* disallowed by config, disapprove instantly */ | 686 | /* Disallowed by config, disapprove instantly */ |
664 | GNUNET_STATISTICS_update (GST_stats, | 687 | GNUNET_STATISTICS_update (GST_stats, |
665 | gettext_noop ("# disconnects due to blacklist"), | 688 | gettext_noop ("# disconnects due to blacklist"), |
666 | 1, GNUNET_NO); | 689 | 1, GNUNET_NO); |
690 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Disallowing connection to peer `%s' on transport %s\n", | ||
691 | GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : "unspecified"); | ||
667 | if (cont != NULL) | 692 | if (cont != NULL) |
668 | cont (cont_cls, peer, GNUNET_NO); | 693 | cont (cont_cls, peer, GNUNET_NO); |
669 | return NULL; | 694 | return NULL; |
@@ -674,6 +699,8 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, | |||
674 | /* no blacklist clients, approve instantly */ | 699 | /* no blacklist clients, approve instantly */ |
675 | if (cont != NULL) | 700 | if (cont != NULL) |
676 | cont (cont_cls, peer, GNUNET_OK); | 701 | cont (cont_cls, peer, GNUNET_OK); |
702 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Allowing connection to peer `%s' %s\n", | ||
703 | GNUNET_i2s (peer), (NULL != transport_name) ? transport_name : ""); | ||
677 | return NULL; | 704 | return NULL; |
678 | } | 705 | } |
679 | 706 | ||
diff --git a/src/transport/test_transport_blacklisting_cfg.c b/src/transport/test_transport_blacklisting_cfg.c deleted file mode 100644 index e2b949a57..000000000 --- a/src/transport/test_transport_blacklisting_cfg.c +++ /dev/null | |||
@@ -1,323 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2009, 2010, 2011 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 | /** | ||
22 | * @file transport/transport_api_blacklisting.c | ||
23 | * @brief test for the blacklisting API | ||
24 | * stage 0: init | ||
25 | * stage 1: connect peers and stop | ||
26 | * stage 2: blacklist whole peer and connect | ||
27 | * stage 3: blacklist tcp and try connect | ||
28 | * | ||
29 | * @author Matthias Wachs | ||
30 | * | ||
31 | */ | ||
32 | #include "platform.h" | ||
33 | #include "gnunet_transport_service.h" | ||
34 | #include "transport-testing.h" | ||
35 | |||
36 | struct PeerContext *p1; | ||
37 | |||
38 | struct PeerContext *p2; | ||
39 | |||
40 | static GNUNET_TRANSPORT_TESTING_ConnectRequest cc; | ||
41 | |||
42 | struct GNUNET_TRANSPORT_TESTING_handle *tth; | ||
43 | |||
44 | /** | ||
45 | * How long until we give up on transmitting the message? | ||
46 | */ | ||
47 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20) | ||
48 | |||
49 | #define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | ||
50 | |||
51 | |||
52 | static int stage; | ||
53 | static int ok; | ||
54 | static int connected; | ||
55 | |||
56 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
57 | |||
58 | static GNUNET_SCHEDULER_TaskIdentifier timeout_task; | ||
59 | |||
60 | static GNUNET_SCHEDULER_TaskIdentifier stage_task; | ||
61 | |||
62 | #if VERBOSE | ||
63 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | ||
64 | #else | ||
65 | #define OKPP do { ok++; } while (0) | ||
66 | #endif | ||
67 | |||
68 | static void | ||
69 | run_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
70 | |||
71 | static void | ||
72 | end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
73 | { | ||
74 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); | ||
75 | |||
76 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
77 | { | ||
78 | GNUNET_SCHEDULER_cancel (die_task); | ||
79 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
80 | } | ||
81 | |||
82 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
83 | { | ||
84 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
85 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
86 | } | ||
87 | |||
88 | if (stage_task != GNUNET_SCHEDULER_NO_TASK) | ||
89 | { | ||
90 | GNUNET_SCHEDULER_cancel (stage_task); | ||
91 | stage_task = GNUNET_SCHEDULER_NO_TASK; | ||
92 | } | ||
93 | |||
94 | if (cc != NULL) | ||
95 | { | ||
96 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel(tth, cc); | ||
97 | cc = NULL; | ||
98 | } | ||
99 | |||
100 | if (p1 != NULL) | ||
101 | { | ||
102 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
103 | p1 = NULL; | ||
104 | } | ||
105 | if (p2 != NULL) | ||
106 | { | ||
107 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
108 | p2 = NULL; | ||
109 | } | ||
110 | } | ||
111 | |||
112 | static void | ||
113 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
114 | { | ||
115 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
116 | |||
117 | if (timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
118 | { | ||
119 | GNUNET_SCHEDULER_cancel (timeout_task); | ||
120 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
121 | } | ||
122 | |||
123 | if (stage_task != GNUNET_SCHEDULER_NO_TASK) | ||
124 | { | ||
125 | GNUNET_SCHEDULER_cancel (stage_task); | ||
126 | stage_task = GNUNET_SCHEDULER_NO_TASK; | ||
127 | } | ||
128 | |||
129 | |||
130 | if (cc != NULL) | ||
131 | { | ||
132 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Fail! Could not connect peers\n")); | ||
133 | GNUNET_TRANSPORT_TESTING_connect_peers_cancel (tth, cc); | ||
134 | cc = NULL; | ||
135 | } | ||
136 | |||
137 | if (p1 != NULL) | ||
138 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
139 | if (p2 != NULL) | ||
140 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
141 | |||
142 | ok = GNUNET_SYSERR; | ||
143 | } | ||
144 | |||
145 | static void | ||
146 | testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls) | ||
147 | { | ||
148 | cc = NULL; | ||
149 | char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
150 | |||
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %u (%s) <-> %u (%s)\n", | ||
152 | p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); | ||
153 | GNUNET_free (p1_c); | ||
154 | |||
155 | if (1 == stage) | ||
156 | { | ||
157 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL); | ||
158 | } | ||
159 | else | ||
160 | { | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected, but they were blacklisted\n"); | ||
162 | stage_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
163 | } | ||
164 | |||
165 | } | ||
166 | |||
167 | static void | ||
168 | connect_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
169 | { | ||
170 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers not connected, next stage\n"); | ||
171 | timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
172 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL); | ||
173 | } | ||
174 | |||
175 | static int started; | ||
176 | |||
177 | void | ||
178 | start_cb (struct PeerContext *p, void *cls) | ||
179 | { | ||
180 | |||
181 | started++; | ||
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer %u (`%s') started\n", p->no, | ||
183 | GNUNET_i2s (&p->id)); | ||
184 | |||
185 | if (started != 2) | ||
186 | return; | ||
187 | |||
188 | char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); | ||
189 | |||
190 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
191 | "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", | ||
192 | p1->no, sender_c, p2->no, GNUNET_i2s (&p2->id)); | ||
193 | GNUNET_free (sender_c); | ||
194 | |||
195 | cc = GNUNET_TRANSPORT_TESTING_connect_peers (tth, p1, p2, &testing_connect_cb, | ||
196 | NULL); | ||
197 | |||
198 | } | ||
199 | |||
200 | static void | ||
201 | run_stage (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
202 | { | ||
203 | stage_task = GNUNET_SCHEDULER_NO_TASK; | ||
204 | if (GNUNET_SCHEDULER_NO_TASK != die_task) | ||
205 | GNUNET_SCHEDULER_cancel (die_task); | ||
206 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
207 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Running stage %u\n", stage); | ||
208 | if (0 == stage) | ||
209 | { | ||
210 | /* Try to connect peers successfully */ | ||
211 | started = 0; | ||
212 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer1.conf", 1, | ||
213 | NULL, NULL, NULL, &start_cb, NULL); | ||
214 | |||
215 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer2.conf", 2, | ||
216 | NULL, NULL, NULL, &start_cb, NULL); | ||
217 | stage ++; | ||
218 | return; | ||
219 | } | ||
220 | |||
221 | if (1 == stage) | ||
222 | { | ||
223 | /* Try to connect peers successfully with 2nd peer fully blacklisted*/ | ||
224 | if (p1 != NULL) | ||
225 | { | ||
226 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
227 | p1 = NULL; | ||
228 | } | ||
229 | if (p2 != NULL) | ||
230 | { | ||
231 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
232 | p2 = NULL; | ||
233 | } | ||
234 | started = 0; | ||
235 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer1.conf", 1, | ||
236 | NULL, NULL, NULL, &start_cb, NULL); | ||
237 | |||
238 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer2.conf", 2, | ||
239 | NULL, NULL, NULL, &start_cb, NULL); | ||
240 | |||
241 | timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT, &connect_timeout, NULL); | ||
242 | stage ++; | ||
243 | return; | ||
244 | } | ||
245 | if (2 == stage) | ||
246 | { | ||
247 | /* Try to connect peers successfully with 1st peer blacklisted on tcp */ | ||
248 | if (p1 != NULL) | ||
249 | { | ||
250 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p1); | ||
251 | p1 = NULL; | ||
252 | } | ||
253 | if (p2 != NULL) | ||
254 | { | ||
255 | GNUNET_TRANSPORT_TESTING_stop_peer (tth, p2); | ||
256 | p2 = NULL; | ||
257 | } | ||
258 | started = 0; | ||
259 | p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_blp_peer1.conf", 1, | ||
260 | NULL, NULL, NULL, &start_cb, NULL); | ||
261 | |||
262 | p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, "test_transport_blacklisting_cfg_peer2.conf", 2, | ||
263 | NULL, NULL, NULL, &start_cb, NULL); | ||
264 | |||
265 | timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT, &connect_timeout, NULL); | ||
266 | stage ++; | ||
267 | return; | ||
268 | } | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Done!\n", stage); | ||
270 | |||
271 | |||
272 | ok = 0; | ||
273 | GNUNET_SCHEDULER_add_now (&end, NULL); | ||
274 | } | ||
275 | |||
276 | static void | ||
277 | run (void *cls, char *const *args, const char *cfgfile, | ||
278 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
279 | { | ||
280 | connected = GNUNET_NO; | ||
281 | stage = 0; | ||
282 | stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL); | ||
283 | } | ||
284 | |||
285 | |||
286 | static int | ||
287 | check () | ||
288 | { | ||
289 | static char *const argv[] = { "test-transport-api-blacklisting", | ||
290 | "-c", | ||
291 | "test_transport_api_data.conf", | ||
292 | NULL | ||
293 | }; | ||
294 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
295 | GNUNET_GETOPT_OPTION_END | ||
296 | }; | ||
297 | |||
298 | ok = 1; | ||
299 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, "test-transport-api-blacklisting", | ||
300 | "nohelp", options, &run, &ok); | ||
301 | |||
302 | return ok; | ||
303 | } | ||
304 | |||
305 | int | ||
306 | main (int argc, char *argv[]) | ||
307 | { | ||
308 | int ret; | ||
309 | |||
310 | GNUNET_log_setup ("test-transport-api-blacklisting", | ||
311 | "WARNING", | ||
312 | NULL); | ||
313 | |||
314 | tth = GNUNET_TRANSPORT_TESTING_init (); | ||
315 | |||
316 | ret = check (); | ||
317 | |||
318 | GNUNET_TRANSPORT_TESTING_done (tth); | ||
319 | |||
320 | return ret; | ||
321 | } | ||
322 | |||
323 | /* end of transport_api_blacklisting.c */ | ||
diff --git a/src/transport/test_transport_blacklisting_cfg_blp_peer1.conf b/src/transport/test_transport_blacklisting_cfg_blp_peer1.conf deleted file mode 100644 index d244265aa..000000000 --- a/src/transport/test_transport_blacklisting_cfg_blp_peer1.conf +++ /dev/null | |||
@@ -1,37 +0,0 @@ | |||
1 | @INLINE@ template_cfg_peer1.conf | ||
2 | [PATHS] | ||
3 | SERVICEHOME = /tmp/test-transport/api-tcp-p1/ | ||
4 | |||
5 | [transport-tcp] | ||
6 | PORT = 12000 | ||
7 | TIMEOUT = 5 s | ||
8 | |||
9 | [arm] | ||
10 | PORT = 12005 | ||
11 | DEFAULTSERVICES = transport | ||
12 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock | ||
13 | |||
14 | [statistics] | ||
15 | PORT = 12004 | ||
16 | UNIXPATH = /tmp/gnunet-p1-service-statistics.sock | ||
17 | |||
18 | [resolver] | ||
19 | PORT = 12003 | ||
20 | UNIXPATH = /tmp/gnunet-p1-service-resolver.sock | ||
21 | |||
22 | [peerinfo] | ||
23 | PORT = 12002 | ||
24 | UNIXPATH = /tmp/gnunet-p1-service-peerinfo.sock | ||
25 | |||
26 | [transport] | ||
27 | #PREFIX = valgrind --leak-check=full | ||
28 | PORT = 12001 | ||
29 | UNIXPATH = /tmp/gnunet-p1-service-transport.sock | ||
30 | PLUGINS = tcp | ||
31 | |||
32 | [transport-blacklist-AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520] | ||
33 | P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G = tcp | ||
34 | |||
35 | [transport-blacklist-P565723JO1C2HSN6J29TAQ22MN6CI8HTMUU55T0FUQG4CMDGGEQ8UCNBKUMB94GC8R9G4FB2SF9LDOBAJ6AMINBP4JHHDD6L7VD801G] | ||
36 | AG2PHES1BARB9IJCPAMJTFPVJ5V3A72S3F2A8SBUB8DAQ2V0O3V8G6G2JU56FHGFOHMQVKBSQFV98TCGTC3RJ1NINP82G0RC00N1520 = tcp | ||
37 | \ No newline at end of file | ||