2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file transport/test_transport_api_blacklisting.c
21 * @brief test for the blacklisting API
22 * @author Matthias Wachs
23 * @author Christian Grothoff
26 #include "gnunet_transport_service.h"
27 #include "transport-testing.h"
29 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
31 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
35 static int blacklist_request_p1;
37 static int blacklist_request_p2;
39 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1;
41 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2;
43 static struct GNUNET_SCHEDULER_Task *shutdown_task;
50 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
52 if ((GNUNET_YES == blacklist_request_p1) &&
53 (GNUNET_YES == blacklist_request_p2) &&
54 (GNUNET_NO == connected) )
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "Peers were never connected, success\n");
58 ccc->global_ret = GNUNET_OK;
62 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
63 "Peers were not connected, fail\n");
64 ccc->global_ret = GNUNET_SYSERR;
66 GNUNET_SCHEDULER_shutdown ();
71 custom_shutdown (void *cls)
73 if (NULL != shutdown_task)
75 GNUNET_SCHEDULER_cancel (shutdown_task);
78 if (NULL != blacklist_p1)
80 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
83 if (NULL != blacklist_p2)
85 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
92 notify_receive (void *cls,
93 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
94 const struct GNUNET_PeerIdentity *sender,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
97 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
98 "Unexpectedly even received the message despite blacklist\n");
99 connected = GNUNET_YES;
100 GNUNET_SCHEDULER_cancel (shutdown_task);
106 notify_connect (void *cls,
107 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
108 const struct GNUNET_PeerIdentity *other)
110 GNUNET_TRANSPORT_TESTING_log_connect (cls,
113 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
114 "Peers connected despite blacklist!\n");
115 connected = GNUNET_YES; /* this test now failed */
116 GNUNET_SCHEDULER_cancel (shutdown_task);
122 blacklist_cb (void *cls,
123 const struct GNUNET_PeerIdentity *pid)
125 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
126 int res = GNUNET_SYSERR;
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Peer %u: Blacklist request for peer `%s'\n",
135 blacklist_request_p1 = GNUNET_YES;
140 blacklist_request_p2 = GNUNET_YES;
144 if ( (GNUNET_YES == blacklist_request_p2) &&
145 (GNUNET_YES == blacklist_request_p1) &&
146 (NULL == shutdown_task) )
149 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
158 start_blacklist (void *cls)
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
161 "Starting blacklists\n");
162 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
165 GNUNET_assert (NULL != blacklist_p1);
166 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
169 GNUNET_assert (NULL != blacklist_p2);
177 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
180 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
181 .pre_connect_task = &start_blacklist,
182 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
183 .connect_continuation_cls = &sc,
184 .config_file = "test_transport_api_data.conf",
185 .rec = ¬ify_receive,
186 .nc = ¬ify_connect,
187 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
188 .shutdown_task = &custom_shutdown,
190 .bi_directional = GNUNET_YES
195 GNUNET_TRANSPORT_TESTING_main (2,
196 &GNUNET_TRANSPORT_TESTING_connect_check,
203 /* end of transport_api_blacklisting.c */