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 "transport.h"
33 #include "gnunet_util_lib.h"
36 // - ATS and similar info is a bit lacking in the API right now...
41 * Initialize the neighbours subsystem.
43 * @param cls closure for callbacks
44 * @param connect_cb function to call if we connect to a peer
45 * @param disconnect_cb function to call if we disconnect from a peer
46 * @param peer_address_cb function to call if a neighbour's active address changes
49 GST_neighbours_start (void *cls,
50 NotifyConnect connect_cb,
51 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb,
52 GNUNET_TRANSPORT_PeerIterateCallback peer_address_cb);
56 * Cleanup the neighbours subsystem.
59 GST_neighbours_stop (void);
63 * Try to create a connection to the given target (eventually).
65 * @param target peer to try to connect to
68 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
72 * Test if we're connected to the given peer.
74 * @param target peer to test
75 * @return GNUNET_YES if we are connected, GNUNET_NO if not
78 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
82 * Function called after the transmission is done.
85 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
87 typedef void (*GST_NeighbourSendContinuation) (void *cls, int success,
89 size_t bytes_on_wire);
93 * Transmit a message to the given target using the active connection.
95 * @param target destination
96 * @param msg message to send
97 * @param msg_size number of bytes in msg
98 * @param timeout when to fail with timeout
99 * @param cont function to call when done
100 * @param cont_cls closure for 'cont'
103 GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
104 size_t msg_size, struct GNUNET_TIME_Relative timeout,
105 GST_NeighbourSendContinuation cont, void *cont_cls);
109 * We have received a message from the given sender.
110 * How long should we delay before receiving more?
111 * (Also used to keep the peer marked as live).
113 * @param sender sender of the message
114 * @param size size of the message
115 * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
116 * GNUNET_NO if the neighbour is not connected or violates the quota
117 * @return how long to wait before reading more from this sender
119 struct GNUNET_TIME_Relative
120 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
121 *sender, ssize_t size, int *do_forward);
125 * Keep the connection to the given neighbour alive longer,
126 * we received a KEEPALIVE (or equivalent).
128 * @param neighbour neighbour to keep alive
131 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
135 * We received a KEEP_ALIVE_RESPONSE message and use this to calculate latency
138 * @param neighbour neighbour to keep alive
139 * @param ats performance data
140 * @param ats_count number of entries in ats
143 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
144 const struct GNUNET_ATS_Information *ats,
149 * Change the incoming quota for the given peer.
151 * @param neighbour identity of peer to change qutoa for
152 * @param quota new quota
155 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
156 struct GNUNET_BANDWIDTH_Value32NBO quota);
160 * If we have an active connection to the given target, it must be shutdown.
162 * @param target peer to disconnect from
165 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
169 * Function called for each connected neighbour.
172 * @param neighbour identity of the neighbour
173 * @param ats performance data
174 * @param ats_count number of entries in ats (including 0-termination)
175 * @param address the address (or NULL)
176 * @param bandwidth_in inbound quota in NBO
177 * @param bandwidth_out outbound quota in NBO
179 typedef void (*GST_NeighbourIterator) (void *cls,
180 const struct GNUNET_PeerIdentity *
182 const struct GNUNET_ATS_Information *
183 ats, uint32_t ats_count,
184 const struct GNUNET_HELLO_Address *
186 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
187 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
191 * Iterate over all connected neighbours.
193 * @param cb function to call
194 * @param cb_cls closure for cb
197 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
201 * A session was terminated. Take note.
203 * @param peer identity of the peer where the session died
204 * @param session session that is gone
205 * @return GNUNET_YES if this was a session used, GNUNET_NO if
206 * this session was not in use
209 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
210 struct Session *session);
214 * For an existing neighbour record, set the active connection to
215 * use the given address.
217 * @param peer identity of the peer to switch the address for
218 * @param address address of the other peer, NULL if other peer
220 * @param session session to use (or NULL)
221 * @param ats performance data
222 * @param ats_count number of entries in ats
223 * @param bandwidth_in inbound quota to be used when connection is up
224 * @param bandwidth_out outbound quota to be used when connection is up
227 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
228 const struct GNUNET_HELLO_Address
229 *address, struct Session *session,
230 const struct GNUNET_ATS_Information *ats,
232 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
233 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
237 * We received a 'SESSION_CONNECT' message from the other peer.
238 * Consider switching to it.
240 * @param message possibly a 'struct SessionConnectMessage' (check format)
241 * @param peer identity of the peer to switch the address for
242 * @param address address of the other peer, NULL if other peer
244 * @param session session to use (or NULL)
245 * @param ats performance data
246 * @param ats_count number of entries in ats (excluding 0-termination)
249 GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message,
250 const struct GNUNET_PeerIdentity *peer,
251 const struct GNUNET_HELLO_Address *address,
252 struct Session *session,
253 const struct GNUNET_ATS_Information *ats,
258 * We received a 'SESSION_CONNECT_ACK' message from the other peer.
259 * Consider switching to it.
261 * @param message possibly a 'struct SessionConnectMessage' (check format)
262 * @param peer identity of the peer to switch the address for
263 * @param address address of the other peer, NULL if other peer
265 * @param session session to use (or NULL)
266 * @param ats performance data
267 * @param ats_count number of entries in ats
270 GST_neighbours_handle_connect_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,
279 * We received a 'SESSION_ACK' message from the other peer.
280 * FIXME: describe what this means!
282 * @param message possibly a 'struct SessionConnectMessage' (check format)
283 * @param peer identity of the peer to switch the address for
284 * @param address address of the other peer, NULL if other peer
286 * @param session session to use (or NULL)
287 * @param ats performance data
288 * @param ats_count number of entries in ats
291 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
292 const struct GNUNET_PeerIdentity *peer,
293 const struct GNUNET_HELLO_Address *address,
294 struct Session *session,
295 const struct GNUNET_ATS_Information *ats,
300 * Obtain current latency information for the given neighbour.
303 * @return observed latency of the address, FOREVER if the address was
304 * never successfully validated
306 struct GNUNET_TIME_Relative
307 GST_neighbour_get_latency (const struct GNUNET_PeerIdentity *peer);
311 * Obtain current address information for the given neighbour.
314 * @return address currently used
316 struct GNUNET_HELLO_Address *
317 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
321 * We received a disconnect message from the given peer,
322 * validate and process.
324 * @param peer sender of the message
325 * @param msg the disconnect message
328 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity
330 const struct GNUNET_MessageHeader
335 /* end of file gnunet-service-transport_neighbours.h */