rename configs to match
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2010-2015 GNUnet e.V.
4
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.
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      Affero General Public License for more details.
14
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/>.
17
18      SPDX-License-Identifier: AGPL3.0-or-later
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-service-transport.h"
33 #include "transport.h"
34 #include "gnunet_util_lib.h"
35
36
37 /**
38  * Initialize the neighbours subsystem.
39  *
40  * @param max_fds maximum number of fds to use
41  */
42 void
43 GST_neighbours_start (unsigned int max_fds);
44
45
46 /**
47  * Cleanup the neighbours subsystem.
48  */
49 void
50 GST_neighbours_stop (void);
51
52
53 /**
54  * Test if we're connected to the given peer.
55  *
56  * @param target peer to test
57  * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
58  */
59 int
60 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
61
62
63 /**
64  * Function called after the transmission is done.
65  *
66  * @param cls closure
67  * @param success #GNUNET_OK on success, #GNUNET_NO on failure, #GNUNET_SYSERR if we're not connected
68  * @param bytes_payload how much payload was transmitted
69  * @param bytes_on_wire how many bytes were used on the wire
70  */
71 typedef void
72 (*GST_NeighbourSendContinuation) (void *cls,
73                                   int success,
74                                   size_t bytes_payload,
75                                   size_t bytes_on_wire);
76
77
78 /**
79  * Transmit a message to the given target using the active connection.
80  *
81  * @param target destination
82  * @param msg message to send
83  * @param msg_size number of bytes in @a msg
84  * @param timeout when to fail with timeout
85  * @param cont function to call when done
86  * @param cont_cls closure for @a cont
87  */
88 void
89 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
90                      const void *msg,
91                      size_t msg_size,
92                      struct GNUNET_TIME_Relative timeout,
93                      GST_NeighbourSendContinuation cont, void *cont_cls);
94
95
96 /**
97  * We have received a message from the given sender.
98  * How long should we delay before receiving more?
99  * (Also used to keep the peer marked as live).
100  *
101  * @param sender sender of the message
102  * @param size size of the message
103  * @param do_forward set to #GNUNET_YES if the message should be forwarded to clients
104  *                   #GNUNET_NO if the neighbour is not connected or violates the quota
105  * @return how long to wait before reading more from this sender
106  */
107 struct GNUNET_TIME_Relative
108 GST_neighbours_calculate_receive_delay (const struct
109                                         GNUNET_PeerIdentity *sender,
110                                         ssize_t size,
111                                         int *do_forward);
112
113
114 /**
115  * Keep the connection to the given neighbour alive longer,
116  * we received a KEEPALIVE (or equivalent); send a response.
117  *
118  * @param neighbour neighbour to keep alive (by sending keep alive response)
119  * @param m the keep alive message containing the nonce to respond to
120  */
121 void
122 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
123                           const struct GNUNET_MessageHeader *m);
124
125
126 /**
127  * We received a KEEP_ALIVE_RESPONSE message and use this to calculate
128  * latency to this peer.  Pass the updated information (existing ats
129  * plus calculated latency) to ATS.
130  *
131  * @param neighbour neighbour to keep alive
132  * @param m the message containing the keep alive response
133  */
134 void
135 GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
136                                    const struct GNUNET_MessageHeader *m);
137
138
139 /**
140  * If we have an active connection to the given target, it must be shutdown.
141  *
142  * @param target peer to disconnect from
143  */
144 void
145 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
146
147
148 /**
149  * Function called for each neighbour.
150  *
151  * @param cls closure
152  * @param peer identity of the neighbour
153  * @param address the address of the neighbour
154  * @param state current state the peer is in
155  * @param state_timeout timeout for this state
156  * @param bandwidth_in inbound quota in NBO
157  * @param bandwidth_out outbound quota in NBO
158  */
159 typedef void
160 (*GST_NeighbourIterator) (void *cls,
161                           const struct GNUNET_PeerIdentity *peer,
162                           const struct GNUNET_HELLO_Address *address,
163                           enum GNUNET_TRANSPORT_PeerState state,
164                           struct GNUNET_TIME_Absolute state_timeout,
165                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
166                           struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
167
168
169 /**
170  * Iterate over all connected neighbours.
171  *
172  * @param cb function to call
173  * @param cb_cls closure for @a cb
174  */
175 void
176 GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
177
178
179 /**
180  * A session was terminated. Take note.
181  *
182  * @param peer identity of the peer where the session died
183  * @param session session that is gone
184  * @return #GNUNET_YES if this was a session used, #GNUNET_NO if
185  *        this session was not in use
186  */
187 int
188 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
189                                    struct GNUNET_ATS_Session *session);
190
191
192 /**
193  * Track information about data we received from the
194  * given address (used to notify ATS about our utilization
195  * of allocated resources).
196  *
197  * @param address the address we got data from
198  * @param message the message we received (really only the size is used)
199  */
200 void
201 GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
202                                  const struct GNUNET_MessageHeader *message);
203
204
205 /**
206  * Track information about data we transmitted using the given @a
207  * address and @a session (used to notify ATS about our utilization of
208  * allocated resources).
209  *
210  * @param address the address we transmitted data to
211  * @param session session we used to transmit data
212  * @param message the message we sent (really only the size is used)
213  */
214 void
215 GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
216                                  struct GNUNET_ATS_Session *session,
217                                  size_t size);
218
219
220 /**
221  * For an existing neighbour record, set the active connection to
222  * use the given address.
223  *
224  * @param address address of the other peer to start using
225  * @param session session to use (or NULL)
226  * @param bandwidth_in inbound quota to be used when connection is up
227  * @param bandwidth_out outbound quota to be used when connection is up
228  */
229 void
230 GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
231                                   struct GNUNET_ATS_Session *session,
232                                   struct GNUNET_BANDWIDTH_Value32NBO
233                                   bandwidth_in,
234                                   struct GNUNET_BANDWIDTH_Value32NBO
235                                   bandwidth_out);
236
237
238 /**
239  * We received a 'SESSION_CONNECT' message from the other peer.
240  * Consider switching to it.
241  *
242  * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
243  * @param peer identity of the peer to switch the address for
244  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
245  */
246 int
247 GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
248                                    const struct GNUNET_PeerIdentity *peer);
249
250
251 /**
252  * We received a 'SESSION_CONNECT_ACK' message from the other peer.
253  * Consider switching to it.
254  *
255  * @param message possibly a `struct GNUNET_ATS_SessionConnectMessage` (check format)
256  * @param address address of the other peer
257  * @param session session to use (or NULL)
258  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
259  */
260 int
261 GST_neighbours_handle_session_syn_ack (const struct
262                                        GNUNET_MessageHeader *message,
263                                        const struct
264                                        GNUNET_HELLO_Address *address,
265                                        struct GNUNET_ATS_Session *session);
266
267
268 /**
269  * We received a 'SESSION_ACK' message from the other peer.
270  * If we sent a 'CONNECT_ACK' last, this means we are now
271  * connected.  Otherwise, do nothing.
272  *
273  * @param message possibly a 'struct GNUNET_ATS_SessionConnectMessage' (check format)
274  * @param address address of the other peer
275  * @param session session to use (or NULL)
276  * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
277  */
278 int
279 GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
280                                    const struct GNUNET_HELLO_Address *address,
281                                    struct GNUNET_ATS_Session *session);
282
283
284 /**
285  * Obtain current address information for the given neighbour.
286  *
287  * @param peer
288  * @return address currently used
289  */
290 const struct GNUNET_HELLO_Address *
291 GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
292
293
294 /**
295  * We received a quoat message from the given peer,
296  * validate and process.
297  *
298  * @param peer sender of the message
299  * @param msg the quota message
300  */
301 void
302 GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
303                                      const struct GNUNET_MessageHeader *msg);
304
305
306 /**
307  * We received a disconnect message from the given peer,
308  * validate and process.
309  *
310  * @param peer sender of the message
311  * @param msg the disconnect message
312  */
313 void
314 GST_neighbours_handle_disconnect_message (const struct
315                                           GNUNET_PeerIdentity *peer,
316                                           const struct
317                                           GNUNET_MessageHeader *msg);
318
319
320 #endif
321 /* end of file gnunet-service-transport_neighbours.h */