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
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.
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.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file transport/test_transport_api_blacklisting.c
23 * @brief test for the blacklisting API
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet_transport_service.h"
29 #include "transport-testing.h"
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
33 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
37 static int blacklist_request_p1;
39 static int blacklist_request_p2;
41 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1;
43 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2;
45 static struct GNUNET_SCHEDULER_Task *shutdown_task;
52 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
54 if ((GNUNET_YES == blacklist_request_p1) &&
55 (GNUNET_YES == blacklist_request_p2) &&
56 (GNUNET_NO == connected) )
58 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
59 "Peers were never connected, success\n");
60 ccc->global_ret = GNUNET_OK;
64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
65 "Peers were not connected, fail\n");
66 ccc->global_ret = GNUNET_SYSERR;
68 GNUNET_SCHEDULER_shutdown ();
73 custom_shutdown (void *cls)
75 if (NULL != shutdown_task)
77 GNUNET_SCHEDULER_cancel (shutdown_task);
80 if (NULL != blacklist_p1)
82 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
85 if (NULL != blacklist_p2)
87 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
94 notify_receive (void *cls,
95 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
96 const struct GNUNET_PeerIdentity *sender,
97 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
100 "Unexpectedly even received the message despite blacklist\n");
101 connected = GNUNET_YES;
102 GNUNET_SCHEDULER_cancel (shutdown_task);
108 notify_connect (void *cls,
109 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
110 const struct GNUNET_PeerIdentity *other)
112 GNUNET_TRANSPORT_TESTING_log_connect (cls,
115 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
116 "Peers connected despite blacklist!\n");
117 connected = GNUNET_YES; /* this test now failed */
118 GNUNET_SCHEDULER_cancel (shutdown_task);
124 blacklist_cb (void *cls,
125 const struct GNUNET_PeerIdentity *pid)
127 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
128 int res = GNUNET_SYSERR;
130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
131 "Peer %u: Blacklist request for peer `%s'\n",
137 blacklist_request_p1 = GNUNET_YES;
142 blacklist_request_p2 = GNUNET_YES;
146 if ( (GNUNET_YES == blacklist_request_p2) &&
147 (GNUNET_YES == blacklist_request_p1) &&
148 (NULL == shutdown_task) )
151 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
160 start_blacklist (void *cls)
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
163 "Starting blacklists\n");
164 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
167 GNUNET_assert (NULL != blacklist_p1);
168 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
171 GNUNET_assert (NULL != blacklist_p2);
179 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
183 .pre_connect_task = &start_blacklist,
184 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
185 .connect_continuation_cls = &sc,
186 .config_file = "test_transport_api_data.conf",
187 .rec = ¬ify_receive,
188 .nc = ¬ify_connect,
189 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
190 .shutdown_task = &custom_shutdown,
192 .bi_directional = GNUNET_YES
197 GNUNET_TRANSPORT_TESTING_main (2,
198 &GNUNET_TRANSPORT_TESTING_connect_check,
205 /* end of transport_api_blacklisting.c */