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.
17 * @file transport/test_transport_api_blacklisting.c
18 * @brief test for the blacklisting API
19 * @author Matthias Wachs
20 * @author Christian Grothoff
23 #include "gnunet_transport_service.h"
24 #include "transport-testing.h"
26 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
28 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
32 static int blacklist_request_p1;
34 static int blacklist_request_p2;
36 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1;
38 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2;
40 static struct GNUNET_SCHEDULER_Task *shutdown_task;
47 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
49 if ((GNUNET_YES == blacklist_request_p1) &&
50 (GNUNET_YES == blacklist_request_p2) &&
51 (GNUNET_NO == connected) )
53 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
54 "Peers were never connected, success\n");
55 ccc->global_ret = GNUNET_OK;
59 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
60 "Peers were not connected, fail\n");
61 ccc->global_ret = GNUNET_SYSERR;
63 GNUNET_SCHEDULER_shutdown ();
68 custom_shutdown (void *cls)
70 if (NULL != shutdown_task)
72 GNUNET_SCHEDULER_cancel (shutdown_task);
75 if (NULL != blacklist_p1)
77 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
80 if (NULL != blacklist_p2)
82 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
89 notify_receive (void *cls,
90 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
91 const struct GNUNET_PeerIdentity *sender,
92 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
94 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
95 "Unexpectedly even received the message despite blacklist\n");
96 connected = GNUNET_YES;
97 GNUNET_SCHEDULER_cancel (shutdown_task);
103 notify_connect (void *cls,
104 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
105 const struct GNUNET_PeerIdentity *other)
107 GNUNET_TRANSPORT_TESTING_log_connect (cls,
110 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
111 "Peers connected despite blacklist!\n");
112 connected = GNUNET_YES; /* this test now failed */
113 GNUNET_SCHEDULER_cancel (shutdown_task);
119 blacklist_cb (void *cls,
120 const struct GNUNET_PeerIdentity *pid)
122 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
123 int res = GNUNET_SYSERR;
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
126 "Peer %u: Blacklist request for peer `%s'\n",
132 blacklist_request_p1 = GNUNET_YES;
137 blacklist_request_p2 = GNUNET_YES;
141 if ( (GNUNET_YES == blacklist_request_p2) &&
142 (GNUNET_YES == blacklist_request_p1) &&
143 (NULL == shutdown_task) )
146 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
155 start_blacklist (void *cls)
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Starting blacklists\n");
159 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
162 GNUNET_assert (NULL != blacklist_p1);
163 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
166 GNUNET_assert (NULL != blacklist_p2);
174 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
177 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
178 .pre_connect_task = &start_blacklist,
179 .connect_continuation = &GNUNET_TRANSPORT_TESTING_simple_send,
180 .connect_continuation_cls = &sc,
181 .config_file = "test_transport_api_data.conf",
182 .rec = ¬ify_receive,
183 .nc = ¬ify_connect,
184 .nd = &GNUNET_TRANSPORT_TESTING_log_disconnect,
185 .shutdown_task = &custom_shutdown,
187 .bi_directional = GNUNET_YES
192 GNUNET_TRANSPORT_TESTING_main (2,
193 &GNUNET_TRANSPORT_TESTING_connect_check,
200 /* end of transport_api_blacklisting.c */