2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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"
38 * Initialize the neighbours subsystem.
40 * @param max_fds maximum number of fds to use
43 GST_neighbours_start (unsigned int max_fds);
47 * Cleanup the neighbours subsystem.
50 GST_neighbours_stop (void);
54 * Try to create a connection to the given target (eventually).
56 * @param target peer to try to connect to
59 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
63 * Test if we're connected to the given peer.
65 * @param target peer to test
66 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
69 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
73 * Function called after the transmission is done.
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
81 (*GST_NeighbourSendContinuation) (void *cls,
84 size_t bytes_on_wire);
88 * Transmit a message to the given target using the active connection.
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
98 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
101 struct GNUNET_TIME_Relative timeout,
102 GST_NeighbourSendContinuation cont, void *cont_cls);
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).
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
116 struct GNUNET_TIME_Relative
117 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
123 * Keep the connection to the given neighbour alive longer,
124 * we received a KEEPALIVE (or equivalent); send a response.
126 * @param neighbour neighbour to keep alive (by sending keep alive response)
127 * @param m the keep alive message containing the nonce to respond to
130 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
131 const struct GNUNET_MessageHeader *m);
135 * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
136 * latency to this peer. Pass the updated information (existing ats
137 * plus calculated latency) to ATS.
139 * @param neighbour neighbour to keep alive
140 * @param m the message containing the keep alive response
143 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
144 const struct GNUNET_MessageHeader *m);
148 * Change the incoming quota for the given peer.
150 * @param neighbour identity of peer to change qutoa for
151 * @param quota new quota
154 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
155 struct GNUNET_BANDWIDTH_Value32NBO quota);
159 * If we have an active connection to the given target, it must be shutdown.
161 * @param target peer to disconnect from
164 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
168 * Function called for each neighbour.
171 * @param peer identity of the neighbour
172 * @param address the address of the neighbour
173 * @param state current state the peer is in
174 * @param state_timeout timeout for this state
175 * @param bandwidth_in inbound quota in NBO
176 * @param bandwidth_out outbound quota in NBO
179 (*GST_NeighbourIterator) (void *cls,
180 const struct GNUNET_PeerIdentity *peer,
181 const struct GNUNET_HELLO_Address *address,
182 enum GNUNET_TRANSPORT_PeerState state,
183 struct GNUNET_TIME_Absolute state_timeout,
184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
185 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
189 * Iterate over all connected neighbours.
191 * @param cb function to call
192 * @param cb_cls closure for @a cb
195 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
199 * A session was terminated. Take note.
201 * @param peer identity of the peer where the session died
202 * @param session session that is gone
203 * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
204 * this session was not in use
207 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
208 struct Session *session);
212 * Track information about data we received from the
213 * given address (used to notify ATS about our utilization
214 * of allocated resources).
216 * @param address the address we got data from
217 * @param message the message we received (really only the size is used)
220 GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
221 const struct GNUNET_MessageHeader *message);
225 * Track information about data we transmitted using the given @a
226 * address and @a session (used to notify ATS about our utilization of
227 * allocated resources).
229 * @param address the address we transmitted data to
230 * @param session session we used to transmit data
231 * @param message the message we sent (really only the size is used)
234 GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
235 struct Session *session,
240 * For an existing neighbour record, set the active connection to
241 * use the given address.
243 * @param address address of the other peer to start using
244 * @param session session to use (or NULL)
245 * @param bandwidth_in inbound quota to be used when connection is up
246 * @param bandwidth_out outbound quota to be used when connection is up
249 GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
250 struct Session *session,
251 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
252 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
256 * We received a 'SESSION_CONNECT' message from the other peer.
257 * Consider switching to it.
259 * @param message possibly a 'struct SessionConnectMessage' (check format)
260 * @param peer identity of the peer to switch the address for
261 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
264 GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
265 const struct GNUNET_PeerIdentity *peer);
269 * We received a 'SESSION_CONNECT_ACK' message from the other peer.
270 * Consider switching to it.
272 * @param message possibly a `struct SessionConnectMessage` (check format)
273 * @param address address of the other peer
274 * @param session session to use (or NULL)
275 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
278 GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message,
279 const struct GNUNET_HELLO_Address *address,
280 struct Session *session);
284 * We received a 'SESSION_ACK' message from the other peer.
285 * If we sent a 'CONNECT_ACK' last, this means we are now
286 * connected. Otherwise, do nothing.
288 * @param message possibly a 'struct SessionConnectMessage' (check format)
289 * @param address address of the other peer
290 * @param session session to use (or NULL)
291 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
294 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
295 const struct GNUNET_HELLO_Address *address,
296 struct Session *session);
300 * Obtain current address information for the given neighbour.
303 * @return address currently used
305 struct GNUNET_HELLO_Address *
306 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
310 * We received a quoat message from the given peer,
311 * validate and process.
313 * @param peer sender of the message
314 * @param msg the quota message
317 GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
318 const struct GNUNET_MessageHeader *msg);
322 * We received a disconnect message from the given peer,
323 * validate and process.
325 * @param peer sender of the message
326 * @param msg the disconnect message
329 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
330 const struct GNUNET_MessageHeader *msg);
334 /* end of file gnunet-service-transport_neighbours.h */