2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors)
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 2, 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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file transport/gnunet-service-transport_blacklist.c
23 * @brief low-level P2P messaging
24 * @author Christian Grothoff
27 #include "gnunet_protocols.h"
28 #include "gnunet_service_lib.h"
29 #include "transport.h"
30 #include "gnunet-service-transport_blacklist.h"
34 * Information kept for each blacklisted peer.
39 * How long until this entry times out?
41 struct GNUNET_TIME_Absolute until;
44 * Task scheduled to run the moment the time does run out.
46 GNUNET_SCHEDULER_TaskIdentifier timeout_task;
51 * Entry in list of notifications still to transmit to
54 struct PendingNotificationList
58 * This is a linked list.
60 struct PendingNotificationList *next;
63 * Identity of the peer to send notification about.
65 struct GNUNET_PeerIdentity peer;
71 * List of clients to notify whenever the blacklist changes.
73 struct BlacklistNotificationList
77 * This is a linked list.
79 struct BlacklistNotificationList *next;
84 struct GNUNET_SERVER_Client *client;
87 * Pending request for transmission to client, or NULL.
89 struct GNUNET_CONNECTION_TransmitHandle *req;
92 * Blacklist entries that still need to be submitted.
94 struct PendingNotificationList *pending;
100 * Map of blacklisted peers (maps from peer identities
101 * to 'struct BlacklistEntry*' values).
103 static struct GNUNET_CONTAINER_MultiHashMap *blacklist;
106 * Linked list of clients to notify whenever the blacklist changes.
108 static struct BlacklistNotificationList *blacklist_notifiers;
113 static struct GNUNET_SCHEDULER_Handle *sched;
117 * Free the entries in the blacklist hash map.
119 * @param cls closure, unused
120 * @param key current key code
121 * @param value value in the hash map
122 * @return GNUNET_YES if we should continue to
127 free_blacklist_entry (void *cls,
128 const GNUNET_HashCode *key,
131 struct BlacklistEntry *be = value;
133 GNUNET_SCHEDULER_cancel (sched,
141 * Task run when we are shutting down. Cleans up.
143 * @param cls closure (unused)
144 * @param tc scheduler context (unused)
147 shutdown_task (void *cls,
148 const struct GNUNET_SCHEDULER_TaskContext *tc)
150 GNUNET_CONTAINER_multihashmap_iterate (blacklist,
151 &free_blacklist_entry,
153 GNUNET_CONTAINER_multihashmap_destroy (blacklist);
158 * Handle a request to blacklist a peer.
160 * @param cls closure (always NULL)
161 * @param client identification of the client
162 * @param message the actual message
165 GNUNET_TRANSPORT_handle_blacklist (void *cls,
166 struct GNUNET_SERVER_Client *client,
167 const struct GNUNET_MessageHeader *message)
170 GNUNET_SERVER_receive_done (client, GNUNET_OK);
175 * Handle a request for notification of blacklist changes.
177 * @param cls closure (always NULL)
178 * @param client identification of the client
179 * @param message the actual message
182 GNUNET_TRANSPORT_handle_blacklist_notify (void *cls,
183 struct GNUNET_SERVER_Client *client,
184 const struct GNUNET_MessageHeader *message)
187 GNUNET_SERVER_receive_done (client, GNUNET_OK);
192 * Is the given peer currently blacklisted?
194 * @param id identity of the peer
195 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
198 GNUNET_TRANSPORT_blacklist_check (const struct GNUNET_PeerIdentity *id)
200 return GNUNET_CONTAINER_multihashmap_contains (blacklist, &id->hashPubKey);
205 * Initialize the blacklisting subsystem.
207 * @param s scheduler to use
210 GNUNET_TRANSPORT_blacklist_init (struct GNUNET_SCHEDULER_Handle *s)
213 blacklist = GNUNET_CONTAINER_multihashmap_create (4);
214 GNUNET_SCHEDULER_add_delayed (sched,
215 GNUNET_TIME_UNIT_FOREVER_REL,
220 /* end of gnunet-service-transport_blacklist.c */