- one catch-all ack handles renedered obsolete
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_connection.h
1 /*
2      This file is part of GNUnet.
3      (C) 2013 Christian Grothoff (and other contributing authors)
4
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.
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      General Public License for more details.
14
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.
19 */
20
21 /**
22  * @file mesh/gnunet-service-mesh_connection.h
23  * @brief mesh service; dealing with connections
24  * @author Bartlomiej Polot
25  *
26  * All functions in this file should use the prefix GMC (Gnunet Mesh Connection)
27  */
28
29 #ifndef GNUNET_SERVICE_MESH_CONNECTION_H
30 #define GNUNET_SERVICE_MESH_CONNECTION_H
31
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #if 0                           /* keep Emacsens' auto-indent happy */
36 }
37 #endif
38 #endif
39
40 #include "gnunet_util_lib.h"
41
42
43 /**
44  * All the states a connection can be in.
45  */
46 enum MeshConnectionState
47 {
48   /**
49    * Uninitialized status, should never appear in operation.
50    */
51   MESH_CONNECTION_NEW,
52
53   /**
54    * Connection create message sent, waiting for ACK.
55    */
56   MESH_CONNECTION_SENT,
57
58   /**
59    * Connection ACK sent, waiting for ACK.
60    */
61   MESH_CONNECTION_ACK,
62
63   /**
64    * Connection confirmed, ready to carry traffic.
65    */
66   MESH_CONNECTION_READY,
67 };
68
69
70 /**
71  * Struct containing all information regarding a connection to a peer.
72  */
73 struct MeshConnection;
74
75 #include "mesh_path.h"
76 #include "gnunet-service-mesh_channel.h"
77 #include "gnunet-service-mesh_peer.h"
78
79
80
81
82 /**
83  * Core handler for connection creation.
84  *
85  * @param cls Closure (unused).
86  * @param peer Sender (neighbor).
87  * @param message Message.
88  *
89  * @return GNUNET_OK to keep the connection open,
90  *         GNUNET_SYSERR to close it (signal serious error)
91  */
92 int
93 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
94                    const struct GNUNET_MessageHeader *message);
95
96 /**
97  * Core handler for path confirmations.
98  *
99  * @param cls closure
100  * @param message message
101  * @param peer peer identity this notification is about
102  *
103  * @return GNUNET_OK to keep the connection open,
104  *         GNUNET_SYSERR to close it (signal serious error)
105  */
106 int
107 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
108                     const struct GNUNET_MessageHeader *message);
109
110 /**
111  * Core handler for notifications of broken paths
112  *
113  * @param cls Closure (unused).
114  * @param peer Peer identity of sending neighbor.
115  * @param message Message.
116  *
117  * @return GNUNET_OK to keep the connection open,
118  *         GNUNET_SYSERR to close it (signal serious error)
119  */
120 int
121 GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
122                    const struct GNUNET_MessageHeader *message);
123
124 /**
125  * Core handler for tunnel destruction
126  *
127  * @param cls Closure (unused).
128  * @param peer Peer identity of sending neighbor.
129  * @param message Message.
130  *
131  * @return GNUNET_OK to keep the connection open,
132  *         GNUNET_SYSERR to close it (signal serious error)
133  */
134 int
135 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
136                     const struct GNUNET_MessageHeader *message);
137
138 /**
139  * Core handler for mesh network traffic going orig->dest.
140  *
141  * @param cls Closure (unused).
142  * @param message Message received.
143  * @param peer Peer who sent the message.
144  *
145  * @return GNUNET_OK to keep the connection open,
146  *         GNUNET_SYSERR to close it (signal serious error)
147  */
148 int
149 GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
150                 const struct GNUNET_MessageHeader *message);
151
152
153 /**
154  * Core handler for mesh network traffic going dest->orig.
155  *
156  * @param cls Closure (unused).
157  * @param message Message received.
158  * @param peer Peer who sent the message.
159  *
160  * @return GNUNET_OK to keep the connection open,
161  *         GNUNET_SYSERR to close it (signal serious error)
162  */
163 int
164 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
165                 const struct GNUNET_MessageHeader *message);
166
167 /**
168  * Core handler for mesh network traffic point-to-point acks.
169  *
170  * @param cls closure
171  * @param message message
172  * @param peer peer identity this notification is about
173  *
174  * @return GNUNET_OK to keep the connection open,
175  *         GNUNET_SYSERR to close it (signal serious error)
176  */
177 int
178 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
179                 const struct GNUNET_MessageHeader *message);
180
181 /**
182  * Core handler for mesh network traffic point-to-point ack polls.
183  *
184  * @param cls closure
185  * @param message message
186  * @param peer peer identity this notification is about
187  *
188  * @return GNUNET_OK to keep the connection open,
189  *         GNUNET_SYSERR to close it (signal serious error)
190  */
191 int
192 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
193                  const struct GNUNET_MessageHeader *message);
194
195 /**
196  * Core handler for mesh keepalives.
197  *
198  * @param cls closure
199  * @param message message
200  * @param peer peer identity this notification is about
201  * @return GNUNET_OK to keep the connection open,
202  *         GNUNET_SYSERR to close it (signal serious error)
203  *
204  * TODO: Check who we got this from, to validate route.
205  */
206 int
207 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
208                       const struct GNUNET_MessageHeader *message);
209
210 /**
211  * Send an ACK on the appropriate connection/channel, depending on
212  * the direction and the position of the peer.
213  *
214  * @param c Which connection to send the hop-by-hop ACK.
215  * @param ch Channel, if any.
216  * @param fwd Is this a fwd ACK? (will go dest->root)
217  */
218 void
219 GMC_send_ack (struct MeshConnection *c, struct MeshChannel *ch, int fwd);
220
221 /**
222  * Initialize the connections subsystem
223  *
224  * @param c Configuration handle.
225  */
226 void
227 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
228
229 /**
230  * Shut down the connections subsystem.
231  */
232 void
233 GMC_shutdown (void);
234
235 /**
236  * Create a connection.
237  *
238  * @param cid Connection ID (either created locally or imposed remotely).
239  * @param t Tunnel this connection belongs to (or NULL);
240  * @param p Path this connection has to use.
241  * @param own_pos Own position in the @c p path.
242  */
243 struct MeshConnection *
244 GMC_new (const struct GNUNET_HashCode *cid,
245          struct MeshTunnel3 *t,
246          struct MeshPeerPath *p,
247          unsigned int own_pos);
248
249 /**
250  * Connection is no longer needed: destroy it and remove from tunnel.
251  *
252  * @param c Connection to destroy.
253  */
254 void
255 GMC_destroy (struct MeshConnection *c);
256
257 /**
258  * Get the connection ID.
259  *
260  * @param c Connection to get the ID from.
261  *
262  * @return ID of the connection.
263  */
264 const struct GNUNET_HashCode *
265 GMC_get_id (const struct MeshConnection *c);
266
267 /**
268  * Get the connection state.
269  *
270  * @param c Connection to get the state from.
271  *
272  * @return state of the connection.
273  */
274 enum MeshConnectionState
275 GMC_get_state (const struct MeshConnection *c);
276
277 /**
278  * Get the connection tunnel.
279  *
280  * @param c Connection to get the tunnel from.
281  *
282  * @return tunnel of the connection.
283  */
284 struct MeshTunnel3 *
285 GMC_get_tunnel (const struct MeshConnection *c);
286
287 /**
288  * Get free buffer space in a connection.
289  *
290  * @param c Connection.
291  * @param fwd Is query about FWD traffic?
292  *
293  * @return Free buffer space [0 - max_msgs_queue/max_connections]
294  */
295 unsigned int
296 GMC_get_buffer (struct MeshConnection *c, int fwd);
297
298 /**
299  * Get messages queued in a connection.
300  *
301  * @param c Connection.
302  * @param fwd Is query about FWD traffic?
303  *
304  * @return Number of messages queued.
305  */
306 unsigned int
307 GMC_get_qn (struct MeshConnection *c, int fwd);
308
309 /**
310  * Send FWD keepalive packets for a connection.
311  *
312  * @param cls Closure (connection for which to send the keepalive).
313  * @param tc Notification context.
314  */
315 void
316 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
317
318 /**
319  * Send BCK keepalive packets for a connection.
320  *
321  * @param cls Closure (connection for which to send the keepalive).
322  * @param tc Notification context.
323  */
324 void
325 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
326
327
328 /**
329  * Change the tunnel state.
330  *
331  * @param c Connection whose state to change.
332  * @param state New state.
333  */
334 void
335 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
336
337 /**
338  * Notify other peers on a connection of a broken link. Mark connections
339  * to destroy after all traffic has been sent.
340  *
341  * @param c Connection on which there has been a disconnection.
342  * @param peer Peer that disconnected.
343  * @param my_full_id My ID (to send to other peers).
344  */
345 void
346 GMC_notify_broken (struct MeshConnection *c,
347                    struct MeshPeer *peer,
348                    struct GNUNET_PeerIdentity *my_full_id);
349
350 /**
351  * Is this peer the first one on the connection?
352  *
353  * @param c Connection.
354  * @param fwd Is this about fwd traffic?
355  *
356  * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
357  */
358 int
359 GMC_is_origin (struct MeshConnection *c, int fwd);
360
361 /**
362  * Is this peer the last one on the connection?
363  *
364  * @param c Connection.
365  * @param fwd Is this about fwd traffic?
366  *            Note that the ROOT is the terminal for BCK traffic!
367  *
368  * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
369  */
370 int
371 GMC_is_terminal (struct MeshConnection *c, int fwd);
372
373 /**
374  * Sends an already built message on a connection, properly registering
375  * all used resources.
376  *
377  * @param message Message to send. Function makes a copy of it.
378  *                If message is not hop-by-hop, decrements TTL of copy.
379  * @param c Connection on which this message is transmitted.
380  * @param ch Channel on which this message is transmitted, or NULL.
381  * @param fwd Is this a fwd message?
382  */
383 void
384 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
385                            struct MeshConnection *c,
386                            struct MeshChannel *ch,
387                            int fwd);
388
389 /**
390  * Send a message to all peers in this connection that the connection
391  * is no longer valid.
392  *
393  * If some peer should not receive the message, it should be zero'ed out
394  * before calling this function.
395  *
396  * @param c The connection whose peers to notify.
397  */
398 void
399 GMC_send_destroy (struct MeshConnection *c);
400
401 #if 0                           /* keep Emacsens' auto-indent happy */
402 {
403 #endif
404 #ifdef __cplusplus
405 }
406 #endif
407
408 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
409 #endif
410 /* end of gnunet-service-mesh_connection.h */