more refactoring of tests for new send API
[oweals/gnunet.git] / src / transport / gnunet-service-transport_blacklist.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010,2011 GNUnet e.V.
4
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.
9
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.
14
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.
19 */
20
21 /**
22  * @file transport/gnunet-service-transport_blacklist.h
23  * @brief blacklisting API
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_TRANSPORT_BLACKLIST_H
27 #define GNUNET_SERVICE_TRANSPORT_BLACKLIST_H
28
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_ats_service.h"
31 #include "gnunet_util_lib.h"
32
33 /**
34  * Start blacklist subsystem.
35  *
36  * @param server server used to accept clients from
37  * @param cfg configuration handle
38  * @param my_id my peer id
39  */
40 void
41 GST_blacklist_start (struct GNUNET_SERVER_Handle *server,
42                      const struct GNUNET_CONFIGURATION_Handle *cfg,
43                      const struct GNUNET_PeerIdentity *my_id);
44
45
46 /**
47  * Stop blacklist subsystem.
48  */
49 void
50 GST_blacklist_stop (void);
51
52
53 /**
54  * Initialize a blacklisting client.  We got a blacklist-init
55  * message from this client, add him to the list of clients
56  * to query for blacklisting.
57  *
58  * @param cls unused
59  * @param client the client
60  * @param message the blacklist-init message that was sent
61  */
62 void
63 GST_blacklist_handle_init (void *cls,
64                            struct GNUNET_SERVER_Client *client,
65                            const struct GNUNET_MessageHeader *message);
66
67
68 /**
69  * A blacklisting client has sent us reply. Process it.
70  *
71  * @param cls unused
72  * @param client the client
73  * @param message the blacklist-init message that was sent
74  */
75 void
76 GST_blacklist_handle_reply (void *cls,
77                             struct GNUNET_SERVER_Client *client,
78                             const struct GNUNET_MessageHeader *message);
79
80
81 /**
82  * Add the given peer to the blacklist (for the given transport).
83  *
84  * @param peer peer to blacklist
85  * @param transport_name transport to blacklist for this peer, NULL for all
86  */
87 void
88 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
89                         const char *transport_name);
90
91
92 /**
93  * Handle to an active blacklist check.
94  */
95 struct GST_BlacklistCheck;
96
97
98 /**
99  * Continuation called from a blacklist test.
100  *
101  * @param cls closure
102  * @param peer identity of peer that was tested
103  * @param address address associated with the request
104  * @param session session associated with the request
105  * @param result #GNUNET_OK if the connection is allowed,
106  *               #GNUNET_NO if not,
107  *               #GNUNET_SYSERR if operation was aborted
108  */
109 typedef void
110 (*GST_BlacklistTestContinuation) (void *cls,
111                                   const struct GNUNET_PeerIdentity *peer,
112                                   const struct GNUNET_HELLO_Address *address,
113                                   struct GNUNET_ATS_Session *session,
114                                   int result);
115
116
117 /**
118  * Test if a peer/transport combination is blacklisted.
119  *
120  * @param peer the identity of the peer to test
121  * @param transport_name name of the transport to test, never NULL
122  * @param cont function to call with result
123  * @param cont_cls closure for @a cont
124  * @param address address to pass back to @a cont, can be NULL
125  * @param session session to pass back to @a cont, can be NULL
126  * @return handle to the blacklist check, NULL if the decision
127  *        was made instantly and @a cont was already called
128  */
129 struct GST_BlacklistCheck *
130 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
131                             const char *transport_name,
132                             GST_BlacklistTestContinuation cont, 
133                             void *cont_cls,
134                             const struct GNUNET_HELLO_Address *address,
135                             struct GNUNET_ATS_Session *session);
136
137
138 /**
139  * Abort blacklist if @a address and @a session match.
140  *
141  * @param address address used to abort matching checks
142  * @param session session used to abort matching checks
143  */
144 void
145 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
146                               struct GNUNET_ATS_Session *session);
147
148
149
150 /**
151  * Cancel a blacklist check.
152  *
153  * @param bc check to cancel
154  */
155 void
156 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
157
158 #endif
159 /* end of file gnunet-service-transport_blacklist.h */