glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 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
16 /**
17  * @file transport/gnunet-service-transport_neighbours.h
18  * @brief neighbour management API
19  * @author Christian Grothoff
20  */
21 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
22 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
23
24 #include "gnunet_statistics_service.h"
25 #include "gnunet_transport_service.h"
26 #include "gnunet_transport_plugin.h"
27 #include "gnunet-service-transport.h"
28 #include "transport.h"
29 #include "gnunet_util_lib.h"
30
31
32 /**
33  * Initialize the neighbours subsystem.
34  *
35  * @param max_fds maximum number of fds to use
36  */
37 void
38 GST_neighbours_start (unsigned int max_fds);
39
40
41 /**
42  * Cleanup the neighbours subsystem.
43  */
44 void
45 GST_neighbours_stop (void);
46
47
48 /**
49  * Test if we're connected to the given peer.
50  *
51  * @param target peer to test
52  * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
53  */
54 int
55 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
56
57
58 /**
59  * Function called after the transmission is done.
60  *
61  * @param cls closure
62  * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
63  * @param bytes_payload how much payload was transmitted
64  * @param bytes_on_wire how many bytes were used on the wire
65  */
66 typedef void
67 (*GST_NeighbourSendContinuation) (void *cls,
68                                   int success,
69                                   size_t bytes_payload,
70                                   size_t bytes_on_wire);
71
72
73 /**
74  * Transmit a message to the given target using the active connection.
75  *
76  * @param target destination
77  * @param msg message to send
78  * @param msg_size number of bytes in @a msg
79  * @param timeout when to fail with timeout
80  * @param cont function to call when done
81  * @param cont_cls closure for @a cont
82  */
83 void
84 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
85                      const void *msg,
86                      size_t msg_size,
87                      struct GNUNET_TIME_Relative timeout,
88                      GST_NeighbourSendContinuation cont, void *cont_cls);
89
90
91 /**
92  * We have received a message from the given sender.
93  * How long should we delay before receiving more?
94  * (Also used to keep the peer marked as live).
95  *
96  * @param sender sender of the message
97  * @param size size of the message
98  * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
99  *                   #GNUNET_NO if the neighbour is not connected or violates the quota
100  * @return how long to wait before reading more from this sender
101  */
102 struct GNUNET_TIME_Relative
103 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
104                                         ssize_t size,
105                                         int *do_forward);
106
107
108 /**
109  * Keep the connection to the given neighbour alive longer,
110  * we received a KEEPALIVE (or equivalent); send a response.
111  *
112  * @param neighbour neighbour to keep alive (by sending keep alive response)
113  * @param m the keep alive message containing the nonce to respond to
114  */
115 void
116 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
117                           const struct GNUNET_MessageHeader *m);
118
119
120 /**
121  * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
122  * latency to this peer.  Pass the updated information (existing ats
123  * plus calculated latency) to ATS.
124  *
125  * @param neighbour neighbour to keep alive
126  * @param m the message containing the keep alive response
127  */
128 void
129 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
130                                    const struct GNUNET_MessageHeader *m);
131
132
133 /**
134  * If we have an active connection to the given target, it must be shutdown.
135  *
136  * @param target peer to disconnect from
137  */
138 void
139 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
140
141
142 /**
143  * Function called for each neighbour.
144  *
145  * @param cls closure
146  * @param peer identity of the neighbour
147  * @param address the address of the neighbour
148  * @param state current state the peer is in
149  * @param state_timeout timeout for this state
150  * @param bandwidth_in inbound quota in NBO
151  * @param bandwidth_out outbound quota in NBO
152  */
153 typedef void
154 (*GST_NeighbourIterator) (void *cls,
155                           const struct GNUNET_PeerIdentity *peer,
156                           const struct GNUNET_HELLO_Address *address,
157                           enum GNUNET_TRANSPORT_PeerState state,
158                           struct GNUNET_TIME_Absolute state_timeout,
159                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
160                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
161
162
163 /**
164  * Iterate over all connected neighbours.
165  *
166  * @param cb function to call
167  * @param cb_cls closure for @a cb
168  */
169 void
170 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
171
172
173 /**
174  * A session was terminated. Take note.
175  *
176  * @param peer identity of the peer where the session died
177  * @param session session that is gone
178  * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
179  *        this session was not in use
180  */
181 int
182 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
183                                    struct GNUNET_ATS_Session *session);
184
185
186 /**
187  * Track information about data we received from the
188  * given address (used to notify ATS about our utilization
189  * of allocated resources).
190  *
191  * @param address the address we got data from
192  * @param message the message we received (really only the size is used)
193  */
194 void
195 GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
196                                  const struct GNUNET_MessageHeader *message);
197
198
199 /**
200  * Track information about data we transmitted using the given @a
201  * address and @a session (used to notify ATS about our utilization of
202  * allocated resources).
203  *
204  * @param address the address we transmitted data to
205  * @param session session we used to transmit data
206  * @param message the message we sent (really only the size is used)
207  */
208 void
209 GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
210                                  struct GNUNET_ATS_Session *session,
211                                  size_t size);
212
213
214 /**
215  * For an existing neighbour record, set the active connection to
216  * use the given address.
217  *
218  * @param address address of the other peer to start using
219  * @param session session to use (or NULL)
220  * @param bandwidth_in inbound quota to be used when connection is up
221  * @param bandwidth_out outbound quota to be used when connection is up
222  */
223 void
224 GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
225                                   struct GNUNET_ATS_Session *session,
226                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
227                                   struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
228
229
230 /**
231  * We received a 'SESSION_CONNECT' message from the other peer.
232  * Consider switching to it.
233  *
234  * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
235  * @param peer identity of the peer to switch the address for
236  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
237  */
238 int
239 GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
240                                    const struct GNUNET_PeerIdentity *peer);
241
242
243 /**
244  * We received a 'SESSION_CONNECT_ACK' message from the other peer.
245  * Consider switching to it.
246  *
247  * @param message possibly a `struct GNUNET_ATS_SessionConnectMessage` (check format)
248  * @param address address of the other peer
249  * @param session session to use (or NULL)
250  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
251  */
252 int
253 GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message,
254                                        const struct GNUNET_HELLO_Address *address,
255                                        struct GNUNET_ATS_Session *session);
256
257
258 /**
259  * We received a 'SESSION_ACK' message from the other peer.
260  * If we sent a 'CONNECT_ACK' last, this means we are now
261  * connected.  Otherwise, do nothing.
262  *
263  * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
264  * @param address address of the other peer
265  * @param session session to use (or NULL)
266  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
267  */
268 int
269 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
270                                    const struct GNUNET_HELLO_Address *address,
271                                    struct GNUNET_ATS_Session *session);
272
273
274 /**
275  * Obtain current address information for the given neighbour.
276  *
277  * @param peer
278  * @return address currently used
279  */
280 const struct GNUNET_HELLO_Address *
281 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
282
283
284 /**
285  * We received a quoat message from the given peer,
286  * validate and process.
287  *
288  * @param peer sender of the message
289  * @param msg the quota message
290  */
291 void
292 GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
293                                      const struct GNUNET_MessageHeader *msg);
294
295
296 /**
297  * We received a disconnect message from the given peer,
298  * validate and process.
299  *
300  * @param peer sender of the message
301  * @param msg the disconnect message
302  */
303 void
304 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
305                                           const struct GNUNET_MessageHeader *msg);
306
307
308 #endif
309 /* end of file gnunet-service-transport_neighbours.h */