fix div by zero
[oweals/gnunet.git] / src / transport / gnunet-service-transport.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 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.
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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file transport/gnunet-service-transport.h
21  * @brief globals
22  * @author Christian Grothoff
23  */
24 #ifndef GNUNET_SERVICE_TRANSPORT_H
25 #define GNUNET_SERVICE_TRANSPORT_H
26
27 #include "gnunet_util_lib.h"
28 #include "gnunet_statistics_service.h"
29 #include "gnunet_ats_service.h"
30 #include "gnunet_transport_service.h"
31
32 #define VERBOSE_VALIDATION GNUNET_YES
33
34 /**
35  * Statistics handle.
36  */
37 extern struct GNUNET_STATISTICS_Handle *GST_stats;
38
39 /**
40  * Configuration handle.
41  */
42 extern const struct GNUNET_CONFIGURATION_Handle *GST_cfg;
43
44 /**
45  * Configuration handle.
46  */
47 extern struct GNUNET_PeerIdentity GST_my_identity;
48
49 /**
50  * Handle to peerinfo service.
51  */
52 extern struct GNUNET_PEERINFO_Handle *GST_peerinfo;
53
54 /**
55  * Our private key.
56  */
57 extern struct GNUNET_CRYPTO_EddsaPrivateKey *GST_my_private_key;
58
59 /**
60  * ATS handle.
61  */
62 extern struct GNUNET_ATS_SchedulingHandle *GST_ats;
63
64 /**
65  * ATS connectivity handle.
66  */
67 extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
68
69 /**
70  * Interface scanner determines our LAN address range(s).
71  */
72 extern struct GNUNET_ATS_InterfaceScanner *GST_is;
73
74
75 /**
76  * Function to call when a peer's address has changed
77  *
78  * @param cls closure
79  * @param peer peer this update is about,
80  * @param address address, NULL for disconnect notification
81  */
82 typedef void
83 (*GNUNET_TRANSPORT_NeighbourChangeCallback) (void *cls,
84     const struct GNUNET_PeerIdentity *peer,
85     const struct GNUNET_HELLO_Address *address,
86     enum GNUNET_TRANSPORT_PeerState state,
87     struct GNUNET_TIME_Absolute state_timeout,
88     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
89     struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
90
91
92 /**
93  * Continuation called from a blacklist test.
94  *
95  * @param cls closure
96  * @param peer identity of peer that was tested
97  * @param address address associated with the request
98  * @param session session associated with the request
99  * @param result #GNUNET_OK if the connection is allowed,
100  *               #GNUNET_NO if not,
101  *               #GNUNET_SYSERR if operation was aborted
102  */
103 typedef void
104 (*GST_BlacklistTestContinuation) (void *cls,
105                                   const struct GNUNET_PeerIdentity *peer,
106                                   const struct GNUNET_HELLO_Address *address,
107                                   struct GNUNET_ATS_Session *session,
108                                   int result);
109
110
111 /**
112  * Add the given peer to the blacklist (for the given transport).
113  *
114  * @param peer peer to blacklist
115  * @param transport_name transport to blacklist for this peer, NULL for all
116  */
117 void
118 GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
119                         const char *transport_name);
120
121
122 /**
123  * Handle to an active blacklist check.
124  */
125 struct GST_BlacklistCheck;
126
127
128
129 /**
130  * Test if a peer/transport combination is blacklisted.
131  *
132  * @param peer the identity of the peer to test
133  * @param transport_name name of the transport to test, never NULL
134  * @param cont function to call with result
135  * @param cont_cls closure for @a cont
136  * @param address address to pass back to @a cont, can be NULL
137  * @param session session to pass back to @a cont, can be NULL
138  * @return handle to the blacklist check, NULL if the decision
139  *        was made instantly and @a cont was already called
140  */
141 struct GST_BlacklistCheck *
142 GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
143                             const char *transport_name,
144                             GST_BlacklistTestContinuation cont, 
145                             void *cont_cls,
146                             const struct GNUNET_HELLO_Address *address,
147                             struct GNUNET_ATS_Session *session);
148
149
150 /**
151  * Abort blacklist if @a address and @a session match.
152  *
153  * @param address address used to abort matching checks
154  * @param session session used to abort matching checks
155  */
156 void
157 GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
158                               struct GNUNET_ATS_Session *session);
159
160 /**
161  * Cancel a blacklist check.
162  *
163  * @param bc check to cancel
164  */
165 void
166 GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
167
168
169 /**
170  * Function called by the transport for each received message.
171  *
172  * @param cls closure, const char* with the name of the plugin we received the message from
173  * @param address address and (claimed) identity of the other peer
174  * @param session identifier used for this session (NULL for plugins
175  *                that do not offer bi-directional communication to the sender
176  *                using the same "connection")
177  * @param message the message, NULL if we only care about
178  *                learning about the delay until we should receive again
179  * @return how long the plugin should wait until receiving more data
180  *         (plugins that do not support this, can ignore the return value)
181  */
182 struct GNUNET_TIME_Relative
183 GST_receive_callback (void *cls,
184                       const struct GNUNET_HELLO_Address *address,
185                       struct GNUNET_ATS_Session *session,
186                       const struct GNUNET_MessageHeader *message);
187
188 /**
189  * Broadcast the given message to all of our clients.
190  *
191  * @param msg message to broadcast
192  * @param may_drop #GNUNET_YES if the message can be dropped / is payload
193  */
194 void
195 GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
196                        int may_drop);
197
198
199 /**
200  * Broadcast the new active address to all clients monitoring the peer.
201  *
202  * @param peer peer this update is about (never NULL)
203  * @param address address, NULL on disconnect
204  * @param state the current state of the peer
205  * @param state_timeout the time out for the state
206  */
207 void
208 GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
209                                          const struct GNUNET_HELLO_Address *address,
210                                          enum GNUNET_TRANSPORT_PeerState state,
211                                          struct GNUNET_TIME_Absolute state_timeout);
212
213
214 /**
215  * Notify all clients about a disconnect, and cancel
216  * pending SEND_OK messages for this peer.
217  *
218  * @param peer peer that disconnected
219  */
220 void
221 GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer);
222
223
224
225
226 #endif
227 /* end of file gnunet-service-transport_plugins.h */