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_util_lib.h"
29 #include "gnunet_service_lib.h"
30 #include "transport.h"
31 #include "gnunet-service-transport_blacklist.h"
34 * Handle a request to start a blacklist.
36 * @param cls closure (always NULL)
37 * @param client identification of the client
38 * @param message the actual message
41 GNUNET_TRANSPORT_handle_blacklist_init (void *cls,
42 struct GNUNET_SERVER_Client *client,
43 const struct GNUNET_MessageHeader *message)
45 struct Blacklisters *bl;
47 bl = GNUNET_malloc (sizeof (struct Blacklisters));
49 GNUNET_SERVER_client_keep (client);
50 GNUNET_CONTAINER_DLL_insert (bl_head, bl_tail, bl);
51 /* FIXME: confirm that all existing connections are OK! */
56 * Handle a request to blacklist a peer.
58 * @param cls closure (always NULL)
59 * @param client identification of the client
60 * @param message the actual message
63 GNUNET_TRANSPORT_handle_blacklist_reply (void *cls,
64 struct GNUNET_SERVER_Client *client,
65 const struct GNUNET_MessageHeader *message)
67 struct Blacklisters *bl;
68 const struct BlacklistMessage *msg = (const struct BlacklistMessage*) message;
71 while ( (bl != NULL) &&
72 (bl->client != client) )
76 GNUNET_SERVER_client_done (client, GNUNET_SYSERR);
79 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
81 be = GNUNET_malloc (sizeof (struct BlacklistEntry));
84 GNUNET_CONTAINER_multihashmap_put (blacklist,
85 &msg->peer.hashPubKey,
87 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
89 /* FIXME: trigger continuation... */
94 * Notify the given client about all entries in the blacklist.
96 * @param cls closure, refers to the 'struct GNUNET_SERVER_Client' to notify
97 * @param key current key code (peer identity, not used)
98 * @param value value in the hash map, the 'struct BlacklistEntry*'
99 * @return GNUNET_YES (continue to iterate)
102 notify_blacklist_entry (void *cls,
103 const GNUNET_HashCode *key,
106 struct GNUNET_SERVER_Client *client = cls;
107 struct BlacklistEntry *be = value;
108 struct BlacklistMessage msg;
110 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST);
111 msg.header.size = htons (sizeof (struct BlacklistMessage));
112 msg.reserved = htonl (0);
114 msg.until = GNUNET_TIME_absolute_hton (be->until);
115 GNUNET_SERVER_notification_context_unicast (blacklist_notifiers,
124 * Handle a request for notification of blacklist changes.
126 * @param cls closure (always NULL)
127 * @param client identification of the client
128 * @param message the actual message
131 GNUNET_TRANSPORT_handle_blacklist_notify (void *cls,
132 struct GNUNET_SERVER_Client *client,
133 const struct GNUNET_MessageHeader *message)
135 GNUNET_SERVER_notification_context_add (blacklist_notifiers, client);
136 GNUNET_CONTAINER_multihashmap_iterate (blacklist,
137 ¬ify_blacklist_entry,
143 * Is the given peer currently blacklisted?
145 * @param id identity of the peer
146 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
149 GNUNET_TRANSPORT_blacklist_check (const struct GNUNET_PeerIdentity *id)
151 if (GNUNET_CONTAINER_multihashmap_contains (blacklist, &id->hashPubKey))
158 * Initialize the blacklisting subsystem.
160 * @param server server of the transport service
161 * @param s scheduler to use
164 GNUNET_TRANSPORT_blacklist_init (struct GNUNET_SERVER_Handle *server,
165 struct GNUNET_SCHEDULER_Handle *s)
168 blacklist = GNUNET_CONTAINER_multihashmap_create (4);
169 GNUNET_SCHEDULER_add_delayed (sched,
170 GNUNET_TIME_UNIT_FOREVER_REL,
176 /* end of gnunet-service-transport_blacklist.c */