2 This file is part of GNUnet.
3 Copyright (C) 2010-2015 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file transport/gnunet-service-transport_neighbours.h
21 * @brief neighbour management API
22 * @author Christian Grothoff
24 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
25 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
27 #include "gnunet_statistics_service.h"
28 #include "gnunet_transport_service.h"
29 #include "gnunet_transport_plugin.h"
30 #include "gnunet-service-transport.h"
31 #include "transport.h"
32 #include "gnunet_util_lib.h"
36 * Initialize the neighbours subsystem.
38 * @param max_fds maximum number of fds to use
41 GST_neighbours_start (unsigned int max_fds);
45 * Cleanup the neighbours subsystem.
48 GST_neighbours_stop (void);
52 * Test if we're connected to the given peer.
54 * @param target peer to test
55 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
58 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
62 * Function called after the transmission is done.
65 * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
66 * @param bytes_payload how much payload was transmitted
67 * @param bytes_on_wire how many bytes were used on the wire
70 (*GST_NeighbourSendContinuation) (void *cls,
73 size_t bytes_on_wire);
77 * Transmit a message to the given target using the active connection.
79 * @param target destination
80 * @param msg message to send
81 * @param msg_size number of bytes in @a msg
82 * @param timeout when to fail with timeout
83 * @param cont function to call when done
84 * @param cont_cls closure for @a cont
87 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
90 struct GNUNET_TIME_Relative timeout,
91 GST_NeighbourSendContinuation cont, void *cont_cls);
95 * We have received a message from the given sender.
96 * How long should we delay before receiving more?
97 * (Also used to keep the peer marked as live).
99 * @param sender sender of the message
100 * @param size size of the message
101 * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
102 * #GNUNET_NO if the neighbour is not connected or violates the quota
103 * @return how long to wait before reading more from this sender
105 struct GNUNET_TIME_Relative
106 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
112 * Keep the connection to the given neighbour alive longer,
113 * we received a KEEPALIVE (or equivalent); send a response.
115 * @param neighbour neighbour to keep alive (by sending keep alive response)
116 * @param m the keep alive message containing the nonce to respond to
119 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
120 const struct GNUNET_MessageHeader *m);
124 * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
125 * latency to this peer. Pass the updated information (existing ats
126 * plus calculated latency) to ATS.
128 * @param neighbour neighbour to keep alive
129 * @param m the message containing the keep alive response
132 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
133 const struct GNUNET_MessageHeader *m);
137 * If we have an active connection to the given target, it must be shutdown.
139 * @param target peer to disconnect from
142 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
146 * Function called for each neighbour.
149 * @param peer identity of the neighbour
150 * @param address the address of the neighbour
151 * @param state current state the peer is in
152 * @param state_timeout timeout for this state
153 * @param bandwidth_in inbound quota in NBO
154 * @param bandwidth_out outbound quota in NBO
157 (*GST_NeighbourIterator) (void *cls,
158 const struct GNUNET_PeerIdentity *peer,
159 const struct GNUNET_HELLO_Address *address,
160 enum GNUNET_TRANSPORT_PeerState state,
161 struct GNUNET_TIME_Absolute state_timeout,
162 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
163 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
167 * Iterate over all connected neighbours.
169 * @param cb function to call
170 * @param cb_cls closure for @a cb
173 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
177 * A session was terminated. Take note.
179 * @param peer identity of the peer where the session died
180 * @param session session that is gone
181 * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
182 * this session was not in use
185 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
186 struct GNUNET_ATS_Session *session);
190 * Track information about data we received from the
191 * given address (used to notify ATS about our utilization
192 * of allocated resources).
194 * @param address the address we got data from
195 * @param message the message we received (really only the size is used)
198 GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
199 const struct GNUNET_MessageHeader *message);
203 * Track information about data we transmitted using the given @a
204 * address and @a session (used to notify ATS about our utilization of
205 * allocated resources).
207 * @param address the address we transmitted data to
208 * @param session session we used to transmit data
209 * @param message the message we sent (really only the size is used)
212 GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
213 struct GNUNET_ATS_Session *session,
218 * For an existing neighbour record, set the active connection to
219 * use the given address.
221 * @param address address of the other peer to start using
222 * @param session session to use (or NULL)
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_HELLO_Address *address,
228 struct GNUNET_ATS_Session *session,
229 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
230 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
234 * We received a 'SESSION_CONNECT' message from the other peer.
235 * Consider switching to it.
237 * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
238 * @param peer identity of the peer to switch the address for
239 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
242 GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
243 const struct GNUNET_PeerIdentity *peer);
247 * We received a 'SESSION_CONNECT_ACK' message from the other peer.
248 * Consider switching to it.
250 * @param message possibly a `struct GNUNET_ATS_SessionConnectMessage` (check format)
251 * @param address address of the other peer
252 * @param session session to use (or NULL)
253 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
256 GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message,
257 const struct GNUNET_HELLO_Address *address,
258 struct GNUNET_ATS_Session *session);
262 * We received a 'SESSION_ACK' message from the other peer.
263 * If we sent a 'CONNECT_ACK' last, this means we are now
264 * connected. Otherwise, do nothing.
266 * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
267 * @param address address of the other peer
268 * @param session session to use (or NULL)
269 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
272 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
273 const struct GNUNET_HELLO_Address *address,
274 struct GNUNET_ATS_Session *session);
278 * Obtain current address information for the given neighbour.
281 * @return address currently used
283 const struct GNUNET_HELLO_Address *
284 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
288 * We received a quoat message from the given peer,
289 * validate and process.
291 * @param peer sender of the message
292 * @param msg the quota message
295 GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
296 const struct GNUNET_MessageHeader *msg);
300 * We received a disconnect message from the given peer,
301 * validate and process.
303 * @param peer sender of the message
304 * @param msg the disconnect message
307 GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer,
308 const struct GNUNET_MessageHeader *msg);
312 /* end of file gnunet-service-transport_neighbours.h */