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 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/transport_api_blacklist.c
18 * @brief library to access the blacklisting functions of the transport service
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
23 #include "gnunet_arm_service.h"
24 #include "gnunet_hello_lib.h"
25 #include "gnunet_protocols.h"
26 #include "gnunet_transport_service.h"
27 #include "transport.h"
30 * Handle for blacklisting requests.
32 struct GNUNET_TRANSPORT_Blacklist
36 * Connection to transport service.
38 struct GNUNET_MQ_Handle *mq;
41 * Configuration to use.
43 const struct GNUNET_CONFIGURATION_Handle *cfg;
46 * Function to call for determining if a peer is allowed
47 * to communicate with us.
49 GNUNET_TRANSPORT_BlacklistCallback cb;
60 * Establish blacklist connection to transport service.
62 * @param br overall handle
65 reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
69 * Handle blacklist queries.
71 * @param cls our overall handle
75 handle_query (void *cls,
76 const struct BlacklistMessage *bm)
78 struct GNUNET_TRANSPORT_Blacklist *br = cls;
79 struct GNUNET_MQ_Envelope *env;
80 struct BlacklistMessage *res;
82 GNUNET_break (0 == ntohl (bm->is_allowed));
83 env = GNUNET_MQ_msg (res,
84 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
85 res->is_allowed = htonl (br->cb (br->cb_cls,
88 GNUNET_MQ_send (br->mq,
93 * Generic error handler, called with the appropriate error code and
94 * the same closure specified at the creation of the message queue.
95 * Not every message queue implementation supports an error handler.
97 * @param cls closure with the `struct GNUNET_TRANSPORT_Blacklist *`
98 * @param error error code
101 mq_error_handler (void *cls,
102 enum GNUNET_MQ_Error error)
104 struct GNUNET_TRANSPORT_Blacklist *br = cls;
111 * Establish blacklist connection to transport service.
113 * @param br overall handle
116 reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
118 struct GNUNET_MQ_MessageHandler handlers[] = {
119 GNUNET_MQ_hd_fixed_size (query,
120 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY,
121 struct BlacklistMessage,
123 GNUNET_MQ_handler_end ()
125 struct GNUNET_MQ_Envelope *env;
126 struct GNUNET_MessageHeader *req;
129 GNUNET_MQ_destroy (br->mq);
130 br->mq = GNUNET_CLIENT_connect (br->cfg,
137 env = GNUNET_MQ_msg (req,
138 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
139 GNUNET_MQ_send (br->mq,
145 * Install a blacklist callback. The service will be queried for all
146 * existing connections as well as any fresh connections to check if
147 * they are permitted. If the blacklisting callback is unregistered,
148 * all hosts that were denied in the past will automatically be
149 * whitelisted again. Cancelling the blacklist handle is also the
150 * only way to re-enable connections from peers that were previously
153 * @param cfg configuration to use
154 * @param cb callback to invoke to check if connections are allowed
155 * @param cb_cls closure for @a cb
156 * @return NULL on error, otherwise handle for cancellation
158 struct GNUNET_TRANSPORT_Blacklist *
159 GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
160 GNUNET_TRANSPORT_BlacklistCallback cb,
163 struct GNUNET_TRANSPORT_Blacklist *br;
165 br = GNUNET_new (struct GNUNET_TRANSPORT_Blacklist);
180 * Abort the blacklist. Note that this function is the only way for
181 * removing a peer from the blacklist.
183 * @param br handle of the request that is to be cancelled
186 GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
188 GNUNET_MQ_destroy (br->mq);
193 /* end of transport_api_blacklist.c */