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 shutdown_task (void *cls,
142 const struct GNUNET_SCHEDULER_TaskContext *tc)
144 GNUNET_CONTAINER_multihashmap_iterate (blacklist,
145 &free_blacklist_entry,
147 GNUNET_CONTAINER_multihashmap_destroy (blacklist);
152 * Handle a request to blacklist a peer.
154 * @param cls closure (always NULL)
155 * @param client identification of the client
156 * @param message the actual message
159 GNUNET_TRANSPORT_handle_blacklist (void *cls,
160 struct GNUNET_SERVER_Client *client,
161 const struct GNUNET_MessageHeader *message)
167 * Handle a request for notification of blacklist changes.
169 * @param cls closure (always NULL)
170 * @param client identification of the client
171 * @param message the actual message
174 GNUNET_TRANSPORT_handle_blacklist_notify (void *cls,
175 struct GNUNET_SERVER_Client *client,
176 const struct GNUNET_MessageHeader *message)
182 * Is the given peer currently blacklisted?
184 * @param id identity of the peer
185 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
188 GNUNET_TRANSPORT_blacklist_check (const struct GNUNET_PeerIdentity *id)
190 return GNUNET_CONTAINER_multihashmap_contains (blacklist, &id->hashPubKey);
195 * Initialize the blacklisting subsystem.
197 * @param s scheduler to use
200 GNUNET_TRANSPORT_blacklist_init (struct GNUNET_SCHEDULER_Handle *s)
203 blacklist = GNUNET_CONTAINER_multihashmap_create (4);
204 GNUNET_SCHEDULER_add_delayed (sched,
205 GNUNET_TIME_UNIT_FOREVER_REL,
210 /* end of gnunet-service-transport_blacklist.c */