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