2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file transport/gnunet-service-transport_neighbours.h
23 * @brief neighbour management API
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
27 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
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"
37 // - ATS and similar info is a bit lacking in the API right now...
42 * Initialize the neighbours subsystem.
44 * @param cls closure for callbacks
45 * @param connect_cb function to call if we connect to a peer
46 * @param disconnect_cb function to call if we disconnect from a peer
47 * @param peer_address_cb function to call if a neighbour's active address changes
48 * @param max_fds maximum number of fds to use
51 GST_neighbours_start (void *cls,
52 NotifyConnect connect_cb,
53 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
54 GNUNET_TRANSPORT_NeighbourChangeCallback peer_address_cb,
55 unsigned int max_fds);
59 * Cleanup the neighbours subsystem.
62 GST_neighbours_stop (void);
66 * Try to create a connection to the given target (eventually).
68 * @param target peer to try to connect to
71 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
75 * Test if we're connected to the given peer.
77 * @param target peer to test
78 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
81 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
85 * Function called after the transmission is done.
88 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
90 typedef void (*GST_NeighbourSendContinuation) (void *cls, int success,
92 size_t bytes_on_wire);
96 * Transmit a message to the given target using the active connection.
98 * @param target destination
99 * @param msg message to send
100 * @param msg_size number of bytes in @a msg
101 * @param timeout when to fail with timeout
102 * @param cont function to call when done
103 * @param cont_cls closure for @a cont
106 GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
107 size_t msg_size, struct GNUNET_TIME_Relative timeout,
108 GST_NeighbourSendContinuation cont, void *cont_cls);
111 GST_neighbours_register_quota_notification (void *cls,
112 const struct GNUNET_PeerIdentity *peer,
114 struct Session *session);
117 GST_neighbours_unregister_quota_notification(void *cls,
118 const struct GNUNET_PeerIdentity *peer, const char *plugin, struct Session *session);
121 * We have received a message from the given sender.
122 * How long should we delay before receiving more?
123 * (Also used to keep the peer marked as live).
125 * @param sender sender of the message
126 * @param size size of the message
127 * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
128 * #GNUNET_NO if the neighbour is not connected or violates the quota
129 * @return how long to wait before reading more from this sender
131 struct GNUNET_TIME_Relative
132 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
133 *sender, ssize_t size, int *do_forward);
137 * Keep the connection to the given neighbour alive longer,
138 * we received a KEEPALIVE (or equivalent); send a response.
140 * @param neighbour neighbour to keep alive (by sending keep alive response)
141 * @param m the keep alive message containing the nonce to respond to
144 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
145 const struct GNUNET_MessageHeader *m);
149 * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
150 * latency to this peer. Pass the updated information (existing ats
151 * plus calculated latency) to ATS.
153 * @param neighbour neighbour to keep alive
154 * @param m the message containing the keep alive response
157 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
158 const struct GNUNET_MessageHeader *m);
162 * Change the incoming quota for the given peer.
164 * @param neighbour identity of peer to change qutoa for
165 * @param quota new quota
168 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
169 struct GNUNET_BANDWIDTH_Value32NBO quota);
173 * If we have an active connection to the given target, it must be shutdown.
175 * @param target peer to disconnect from
178 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
182 * Function called for each neighbour.
185 * @param neighbour identity of the neighbour
186 * @param address the address (or NULL)
187 * @param state current state the peer is in
188 * @param state_timeout timeout for this state
189 * @param bandwidth_in inbound quota in NBO
190 * @param bandwidth_out outbound quota in NBO
192 typedef void (*GST_NeighbourIterator) (void *cls,
193 const struct GNUNET_PeerIdentity *neighbour,
194 const struct GNUNET_HELLO_Address *address,
195 enum GNUNET_TRANSPORT_PeerState state,
196 struct GNUNET_TIME_Absolute state_timeout,
197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
202 * Iterate over all connected neighbours.
204 * @param cb function to call
205 * @param cb_cls closure for @a cb
208 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
212 * A session was terminated. Take note.
214 * @param peer identity of the peer where the session died
215 * @param session session that is gone
216 * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
217 * this session was not in use
220 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
221 struct Session *session);
225 GST_neighbours_notify_data_recv (const struct GNUNET_PeerIdentity *peer,
226 const struct GNUNET_HELLO_Address *address,
227 struct Session *session,
228 const struct GNUNET_MessageHeader *message);
232 GST_neighbours_notify_payload_recv (const struct GNUNET_PeerIdentity *peer,
233 const struct GNUNET_HELLO_Address *address,
234 struct Session *session,
235 const struct GNUNET_MessageHeader *message);
239 GST_neighbours_notify_payload_sent (const struct GNUNET_PeerIdentity *peer,
244 GST_neighbours_notify_data_sent (const struct GNUNET_PeerIdentity *peer,
245 const struct GNUNET_HELLO_Address *address,
246 struct Session *session,
251 * For an existing neighbour record, set the active connection to
252 * use the given address.
254 * @param peer identity of the peer to switch the address for
255 * @param address address of the other peer, NULL if other peer
257 * @param session session to use (or NULL)
258 * @param ats performance data
259 * @param ats_count number of entries in ats
260 * @param bandwidth_in inbound quota to be used when connection is up
261 * @param bandwidth_out outbound quota to be used when connection is up
264 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
265 const struct GNUNET_HELLO_Address *address,
266 struct Session *session,
267 const struct GNUNET_ATS_Information *ats,
269 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
270 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
274 * We received a 'SESSION_CONNECT' message from the other peer.
275 * Consider switching to it.
277 * @param message possibly a 'struct SessionConnectMessage' (check format)
278 * @param peer identity of the peer to switch the address for
279 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
282 GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
283 const struct GNUNET_PeerIdentity *peer);
287 * We received a 'SESSION_CONNECT_ACK' message from the other peer.
288 * Consider switching to it.
290 * @param message possibly a 'struct SessionConnectMessage' (check format)
291 * @param peer identity of the peer to switch the address for
292 * @param address address of the other peer, NULL if other peer
294 * @param session session to use (or NULL)
295 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
298 GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
299 const struct GNUNET_PeerIdentity *peer,
300 const struct GNUNET_HELLO_Address *address,
301 struct Session *session);
305 * We received a 'SESSION_ACK' message from the other peer.
306 * If we sent a 'CONNECT_ACK' last, this means we are now
307 * connected. Otherwise, do nothing.
309 * @param message possibly a 'struct SessionConnectMessage' (check format)
310 * @param peer identity of the peer to switch the address for
311 * @param address address of the other peer, NULL if other peer
313 * @param session session to use (or NULL)
314 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
317 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
318 const struct GNUNET_PeerIdentity *peer,
319 const struct GNUNET_HELLO_Address *address,
320 struct Session *session);
324 * Obtain current latency information for the given neighbour.
327 * @return observed latency of the address, FOREVER if the address was
328 * never successfully validated
330 struct GNUNET_TIME_Relative
331 GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
335 * Obtain current address information for the given neighbour.
338 * @return address currently used
340 struct GNUNET_HELLO_Address *
341 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
345 * We received a disconnect message from the given peer,
346 * validate and process.
348 * @param peer sender of the message
349 * @param msg the disconnect message
352 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
354 const struct GNUNET_MessageHeader
359 /* end of file gnunet-service-transport_neighbours.h */