2 This file is part of GNUnet.
3 Copyright (C) 2010-2014, 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/transport_api_blacklist.c
23 * @brief library to access the blacklisting functions of the transport service
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_arm_service.h"
29 #include "gnunet_hello_lib.h"
30 #include "gnunet_protocols.h"
31 #include "gnunet_transport_service.h"
32 #include "transport.h"
35 * Handle for blacklisting requests.
37 struct GNUNET_TRANSPORT_Blacklist
41 * Connection to transport service.
43 struct GNUNET_MQ_Handle *mq;
46 * Configuration to use.
48 const struct GNUNET_CONFIGURATION_Handle *cfg;
51 * Function to call for determining if a peer is allowed
52 * to communicate with us.
54 GNUNET_TRANSPORT_BlacklistCallback cb;
65 * Establish blacklist connection to transport service.
67 * @param br overall handle
70 reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
74 * Handle blacklist queries.
76 * @param cls our overall handle
80 handle_query (void *cls,
81 const struct BlacklistMessage *bm)
83 struct GNUNET_TRANSPORT_Blacklist *br = cls;
84 struct GNUNET_MQ_Envelope *env;
85 struct BlacklistMessage *res;
87 GNUNET_break (0 == ntohl (bm->is_allowed));
88 env = GNUNET_MQ_msg (res,
89 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
90 res->is_allowed = htonl (br->cb (br->cb_cls,
93 GNUNET_MQ_send (br->mq,
98 * Generic error handler, called with the appropriate error code and
99 * the same closure specified at the creation of the message queue.
100 * Not every message queue implementation supports an error handler.
102 * @param cls closure with the `struct GNUNET_TRANSPORT_Blacklist *`
103 * @param error error code
106 mq_error_handler (void *cls,
107 enum GNUNET_MQ_Error error)
109 struct GNUNET_TRANSPORT_Blacklist *br = cls;
116 * Establish blacklist connection to transport service.
118 * @param br overall handle
121 reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
123 struct GNUNET_MQ_MessageHandler handlers[] = {
124 GNUNET_MQ_hd_fixed_size (query,
125 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY,
126 struct BlacklistMessage,
128 GNUNET_MQ_handler_end ()
130 struct GNUNET_MQ_Envelope *env;
131 struct GNUNET_MessageHeader *req;
134 GNUNET_MQ_destroy (br->mq);
135 br->mq = GNUNET_CLIENT_connect (br->cfg,
142 env = GNUNET_MQ_msg (req,
143 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
144 GNUNET_MQ_send (br->mq,
150 * Install a blacklist callback. The service will be queried for all
151 * existing connections as well as any fresh connections to check if
152 * they are permitted. If the blacklisting callback is unregistered,
153 * all hosts that were denied in the past will automatically be
154 * whitelisted again. Cancelling the blacklist handle is also the
155 * only way to re-enable connections from peers that were previously
158 * @param cfg configuration to use
159 * @param cb callback to invoke to check if connections are allowed
160 * @param cb_cls closure for @a cb
161 * @return NULL on error, otherwise handle for cancellation
163 struct GNUNET_TRANSPORT_Blacklist *
164 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
165 GNUNET_TRANSPORT_BlacklistCallback cb,
168 struct GNUNET_TRANSPORT_Blacklist *br;
170 br = GNUNET_new (struct GNUNET_TRANSPORT_Blacklist);
185 * Abort the blacklist. Note that this function is the only way for
186 * removing a peer from the blacklist.
188 * @param br handle of the request that is to be cancelled
191 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
193 GNUNET_MQ_destroy (br->mq);
198 /* end of transport_api_blacklist.c */