-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 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_util_lib.h"
33
34 // TODO:
35 // - ATS and similar info is a bit lacking in the API right now...
36
37
38
39 /**
40  * Initialize the neighbours subsystem.
41  *
42  * @param cls closure for callbacks
43  * @param connect_cb function to call if we connect to a peer
44  * @param disconnect_cb function to call if we disconnect from a peer
45  * @param peer_address_cb function to call if a neighbour's active address changes
46  */
47 void
48 GST_neighbours_start (void *cls,
49                       GNUNET_TRANSPORT_NotifyConnect connect_cb,
50                       GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
51                       GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb);
52
53
54 /**
55  * Cleanup the neighbours subsystem.
56  */
57 void
58 GST_neighbours_stop (void);
59
60
61 /**
62  * Try to create a connection to the given target (eventually).
63  *
64  * @param target peer to try to connect to
65  */
66 void
67 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
68
69
70 /**
71  * Test if we're connected to the given peer.
72  *
73  * @param target peer to test
74  * @return GNUNET_YES if we are connected, GNUNET_NO if not
75  */
76 int
77 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
78
79
80 /**
81  * Function called after the transmission is done.
82  *
83  * @param cls closure
84  * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
85  */
86 typedef void (*GST_NeighbourSendContinuation) (void *cls, int success);
87
88
89 /**
90  * Transmit a message to the given target using the active connection.
91  *
92  * @param target destination
93  * @param msg message to send
94  * @param msg_size number of bytes in msg
95  * @param timeout when to fail with timeout
96  * @param cont function to call when done
97  * @param cont_cls closure for 'cont'
98  */
99 void
100 GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
101                      size_t msg_size, struct GNUNET_TIME_Relative timeout,
102                      GST_NeighbourSendContinuation cont, void *cont_cls);
103
104
105 /**
106  * We have received a message from the given sender.
107  * How long should we delay before receiving more?
108  * (Also used to keep the peer marked as live).
109  *
110  * @param sender sender of the message
111  * @param size size of the message
112  * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
113  *                   GNUNET_NO if the neighbour is not connected or violates the quota
114  * @return how long to wait before reading more from this sender
115  */
116 struct GNUNET_TIME_Relative
117 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
118                                         *sender, ssize_t size, int *do_forward);
119
120
121 /**
122  * Keep the connection to the given neighbour alive longer,
123  * we received a KEEPALIVE (or equivalent).
124  *
125  * @param neighbour neighbour to keep alive
126  */
127 void
128 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
129
130 /**
131  * We received a KEEP_ALIVE_RESPONSE message and use this to calculate latency
132  * to this peer
133  *
134  * @param neighbour neighbour to keep alive
135  * @param ats performance data
136  * @param ats_count number of entries in ats
137  */
138 void
139 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
140                                    const struct GNUNET_ATS_Information *ats,
141                                    uint32_t ats_count);
142
143
144 /**
145  * Change the incoming quota for the given peer.
146  *
147  * @param neighbour identity of peer to change qutoa for
148  * @param quota new quota
149  */
150 void
151 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
152                                    struct GNUNET_BANDWIDTH_Value32NBO quota);
153
154
155 /**
156  * If we have an active connection to the given target, it must be shutdown.
157  *
158  * @param target peer to disconnect from
159  */
160 void
161 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
162
163
164 /**
165  * Function called for each connected neighbour.
166  *
167  * @param cls closure
168  * @param neighbour identity of the neighbour
169  * @param ats performance data
170  * @param ats_count number of entries in ats (including 0-termination)
171  * @param address the address (or NULL)
172  */
173 typedef void (*GST_NeighbourIterator) (void *cls,
174                                        const struct GNUNET_PeerIdentity *
175                                        neighbour,
176                                        const struct GNUNET_ATS_Information *
177                                        ats, uint32_t ats_count,
178                                        const struct GNUNET_HELLO_Address *
179                                        address);
180
181
182 /**
183  * Iterate over all connected neighbours.
184  *
185  * @param cb function to call
186  * @param cb_cls closure for cb
187  */
188 void
189 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
190
191
192 /**
193  * A session was terminated. Take note.
194  *
195  * @param peer identity of the peer where the session died
196  * @param session session that is gone
197  */
198 void
199 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
200                                    struct Session *session);
201
202
203 /**
204  * For an existing neighbour record, set the active connection to
205  * use the given address.
206  *
207  * @param peer identity of the peer to switch the address for
208  * @param address address of the other peer, NULL if other peer
209  *                       connected to us
210  * @param session session to use (or NULL)
211  * @param ats performance data
212  * @param ats_count number of entries in ats
213  * @param bandwidth_in inbound quota to be used when connection is up
214  * @param bandwidth_out outbound quota to be used when connection is up
215  * @return GNUNET_YES if we are currently connected, GNUNET_NO if the
216  *         connection is not up (yet)
217  */
218 int
219 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
220                                        const struct GNUNET_HELLO_Address
221                                        *address, struct Session *session,
222                                        const struct GNUNET_ATS_Information *ats,
223                                        uint32_t ats_count,
224                                        struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
225                                        struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
226
227
228 /**
229  * We received a 'SESSION_CONNECT' message from the other peer.
230  * Consider switching to it.
231  *
232  * @param message possibly a 'struct SessionConnectMessage' (check format)
233  * @param peer identity of the peer to switch the address for
234  * @param address address of the other peer, NULL if other peer
235  *                       connected to us
236  * @param session session to use (or NULL)
237  * @param ats performance data
238  * @param ats_count number of entries in ats (excluding 0-termination)
239   */
240 void
241 GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
242                                const struct GNUNET_PeerIdentity *peer,
243                                const struct GNUNET_HELLO_Address *address,
244                                struct Session *session,
245                                const struct GNUNET_ATS_Information *ats,
246                                uint32_t ats_count);
247
248
249 /**
250  * We received a 'SESSION_CONNECT_ACK' message from the other peer.
251  * Consider switching to it.
252  *
253  * @param message possibly a 'struct SessionConnectMessage' (check format)
254  * @param peer identity of the peer to switch the address for
255  * @param address address of the other peer, NULL if other peer
256  *                       connected to us
257  * @param session session to use (or NULL)
258  * @param ats performance data
259  * @param ats_count number of entries in ats
260  */
261 void
262 GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
263                                    const struct GNUNET_PeerIdentity *peer,
264                                    const struct GNUNET_HELLO_Address *address,
265                                    struct Session *session,
266                                    const struct GNUNET_ATS_Information *ats,
267                                    uint32_t ats_count);
268
269 void
270 GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message,
271                            const struct GNUNET_PeerIdentity *peer,
272                            const struct GNUNET_HELLO_Address *address,
273                            struct Session *session,
274                            const struct GNUNET_ATS_Information *ats,
275                            uint32_t ats_count);
276
277
278 /**
279  * Obtain current latency information for the given neighbour.
280  *
281  * @param peer
282  * @return observed latency of the address, FOREVER if the address was
283  *         never successfully validated
284  */
285 struct GNUNET_TIME_Relative
286 GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
287
288
289 /**
290  * Obtain current address information for the given neighbour.
291  *
292  * @param peer
293  * @return address currently used
294  */
295 struct GNUNET_HELLO_Address *
296 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
297
298
299 /**
300  * We received a disconnect message from the given peer,
301  * validate and process.
302  *
303  * @param peer sender of the message
304  * @param msg the disconnect message
305  */
306 void
307 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
308                                           *peer,
309                                           const struct GNUNET_MessageHeader
310                                           *msg);
311
312
313 #endif
314 /* end of file gnunet-service-transport_neighbours.h */