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 #define TEST_MESSAGE_SIZE 2600
35 #define TEST_MESSAGE_TYPE 12345
38 static struct GNUNET_TRANSPORT_TransmitHandle *th;
40 static struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc;
44 static int blacklist_request_p1;
46 static int blacklist_request_p2;
48 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p1;
50 static struct GNUNET_TRANSPORT_Blacklist *blacklist_p2;
52 static struct GNUNET_SCHEDULER_Task *send_task;
54 static struct GNUNET_SCHEDULER_Task *shutdown_task;
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
63 if ((GNUNET_YES == blacklist_request_p1) &&
64 (GNUNET_YES == blacklist_request_p2) &&
65 (GNUNET_NO == connected) )
67 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
68 "Peers were never connected, success\n");
69 ccc->global_ret = GNUNET_OK;
73 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
74 "Peers were not connected, fail\n");
75 ccc->global_ret = GNUNET_SYSERR;
77 GNUNET_SCHEDULER_shutdown ();
82 custom_shutdown (void *cls)
84 if (NULL != send_task)
86 GNUNET_SCHEDULER_cancel (send_task);
89 if (NULL != shutdown_task)
91 GNUNET_SCHEDULER_cancel (shutdown_task);
96 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
99 if (NULL != blacklist_p1)
101 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p1);
104 if (NULL != blacklist_p2)
106 GNUNET_TRANSPORT_blacklist_cancel (blacklist_p2);
113 notify_receive (void *cls,
114 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
115 const struct GNUNET_PeerIdentity *sender,
116 const struct GNUNET_MessageHeader *message)
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
119 "Unexpectedly even received the message despite blacklist\n");
120 GNUNET_SCHEDULER_shutdown ();
125 notify_ready (void *cls,
129 struct GNUNET_MessageHeader *hdr;
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
135 "Timeout occurred while waiting for transmit_ready\n");
136 GNUNET_SCHEDULER_shutdown ();
139 GNUNET_assert (size >= TEST_MESSAGE_SIZE);
141 hdr->size = htons (TEST_MESSAGE_SIZE);
142 hdr->type = htons (TEST_MESSAGE_TYPE);
143 return TEST_MESSAGE_SIZE;
150 th = GNUNET_TRANSPORT_notify_transmit_ready (ccc->p[1]->th,
160 notify_connect (void *cls,
161 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
162 const struct GNUNET_PeerIdentity *other)
164 GNUNET_TRANSPORT_TESTING_log_connect (cls,
167 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
168 "Peers connected despite blacklist!\n");
169 connected = GNUNET_YES; /* this test now failed */
170 GNUNET_SCHEDULER_cancel (shutdown_task);
176 notify_disconnect (void *cls,
177 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
178 const struct GNUNET_PeerIdentity *other)
180 GNUNET_TRANSPORT_TESTING_log_disconnect (cls,
185 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
192 blacklist_cb (void *cls,
193 const struct GNUNET_PeerIdentity *pid)
195 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
196 int res = GNUNET_SYSERR;
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "Peer %u: Blacklist request for peer `%s'\n",
205 blacklist_request_p1 = GNUNET_YES;
210 blacklist_request_p2 = GNUNET_YES;
214 if ( (GNUNET_YES == blacklist_request_p2) &&
215 (GNUNET_YES == blacklist_request_p1) &&
216 (NULL == shutdown_task) )
219 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3),
228 start_blacklist (void *cls)
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Starting blacklists\n");
232 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg,
235 GNUNET_assert (NULL != blacklist_p1);
236 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg,
239 GNUNET_assert (NULL != blacklist_p2);
247 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
248 .pre_connect_task = &start_blacklist,
249 .connect_continuation = &sendtask,
250 .config_file = "test_transport_api_data.conf",
251 .rec = ¬ify_receive,
252 .nc = ¬ify_connect,
253 .nd = ¬ify_disconnect,
254 .shutdown_task = &custom_shutdown,
256 .bi_directional = GNUNET_YES
261 GNUNET_TRANSPORT_TESTING_main (2,
262 &GNUNET_TRANSPORT_TESTING_connect_check,
269 /* end of transport_api_blacklisting.c */