-bump name to 97
[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 #include "mesh_path.h"
43 #include "gnunet-service-mesh_channel.h"
44
45
46 /**
47  * Struct containing all information regarding a connection to a peer.
48  */
49 struct MeshConnection;
50
51
52
53
54 /**
55  * Core handler for connection creation.
56  *
57  * @param cls Closure (unused).
58  * @param peer Sender (neighbor).
59  * @param message Message.
60  *
61  * @return GNUNET_OK to keep the connection open,
62  *         GNUNET_SYSERR to close it (signal serious error)
63  */
64 int
65 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
66                    const struct GNUNET_MessageHeader *message);
67
68 /**
69  * Core handler for path confirmations.
70  *
71  * @param cls closure
72  * @param message message
73  * @param peer peer identity this notification is about
74  *
75  * @return GNUNET_OK to keep the connection open,
76  *         GNUNET_SYSERR to close it (signal serious error)
77  */
78 int
79 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
80                     const struct GNUNET_MessageHeader *message);
81
82 /**
83  * Core handler for notifications of broken paths
84  *
85  * @param cls Closure (unused).
86  * @param peer Peer identity of sending 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_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
94                    const struct GNUNET_MessageHeader *message);
95
96 /**
97  * Core handler for tunnel destruction
98  *
99  * @param cls Closure (unused).
100  * @param peer Peer identity of sending neighbor.
101  * @param message Message.
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_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
108                     const struct GNUNET_MessageHeader *message);
109
110 /**
111  * Core handler for mesh network traffic going orig->dest.
112  *
113  * @param cls Closure (unused).
114  * @param message Message received.
115  * @param peer Peer who sent the 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_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
122                 const struct GNUNET_MessageHeader *message);
123
124
125 /**
126  * Core handler for mesh network traffic going dest->orig.
127  *
128  * @param cls Closure (unused).
129  * @param message Message received.
130  * @param peer Peer who sent the message.
131  *
132  * @return GNUNET_OK to keep the connection open,
133  *         GNUNET_SYSERR to close it (signal serious error)
134  */
135 int
136 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
137                 const struct GNUNET_MessageHeader *message);
138
139 /**
140  * Core handler for mesh network traffic point-to-point acks.
141  *
142  * @param cls closure
143  * @param message message
144  * @param peer peer identity this notification is about
145  *
146  * @return GNUNET_OK to keep the connection open,
147  *         GNUNET_SYSERR to close it (signal serious error)
148  */
149 int
150 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
151                 const struct GNUNET_MessageHeader *message);
152
153 /**
154  * Core handler for mesh network traffic point-to-point ack polls.
155  *
156  * @param cls closure
157  * @param message message
158  * @param peer peer identity this notification is about
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_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
165                  const struct GNUNET_MessageHeader *message);
166
167 /**
168  * Core handler for mesh keepalives.
169  *
170  * @param cls closure
171  * @param message message
172  * @param peer peer identity this notification is about
173  * @return GNUNET_OK to keep the connection open,
174  *         GNUNET_SYSERR to close it (signal serious error)
175  *
176  * TODO: Check who we got this from, to validate route.
177  */
178 int
179 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
180                       const struct GNUNET_MessageHeader *message);
181
182 /**
183  * Initialize the connections subsystem
184  *
185  * @param c Configuration handle.
186  */
187 void
188 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
189
190 /**
191  * Shut down the connections subsystem.
192  */
193 void
194 GMC_shutdown (void);
195
196 /**
197  * Create a connection.
198  *
199  * @param cid Connection ID (either created locally or imposed remotely).
200  * @param t Tunnel this connection belongs to (or NULL);
201  * @param p Path this connection has to use.
202  * @param own_pos Own position in the @c p path.
203  */
204 struct MeshConnection *
205 GMC_new (const struct GNUNET_HashCode *cid,
206          struct MeshTunnel2 *t,
207          struct MeshPeerPath *p,
208          unsigned int own_pos);
209
210 /**
211  * Connection is no longer needed: destroy it and remove from tunnel.
212  *
213  * @param c Connection to destroy.
214  */
215 void
216 GMC_destroy (struct MeshConnection *c);
217
218 /**
219  * Get the connection ID.
220  *
221  * @param c Connection to get the ID from.
222  *
223  * @return ID of the connection.
224  */
225 const struct GNUNET_HashCode *
226 GMC_get_id (const struct MeshConnection *c);
227
228 /**
229  * Count connections in a DLL.
230  */
231 unsigned int
232 GMC_count (const struct MeshConnection *head);
233
234 /**
235  * Send FWD keepalive packets for a connection.
236  *
237  * @param cls Closure (connection for which to send the keepalive).
238  * @param tc Notification context.
239  */
240 void
241 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
242
243 /**
244  * Send BCK keepalive packets for a connection.
245  *
246  * @param cls Closure (connection for which to send the keepalive).
247  * @param tc Notification context.
248  */
249 void
250 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
251
252
253 /**
254  * Change the tunnel state.
255  *
256  * @param c Connection whose state to change.
257  * @param state New state.
258  */
259 void
260 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
261
262 /**
263  * Notify other peers on a connection of a broken link. Mark connections
264  * to destroy after all traffic has been sent.
265  *
266  * @param c Connection on which there has been a disconnection.
267  * @param peer Peer that disconnected.
268  * @param my_full_id My ID (to send to other peers).
269  */
270 void
271 GMC_notify_broken (struct MeshConnection *c,
272                    struct MeshPeer *peer,
273                    struct GNUNET_PeerIdentity *my_full_id);
274
275 /**
276  * @brief Queue and pass message to core when possible.
277  *
278  * @param cls Closure (@c type dependant). It will be used by queue_send to
279  *            build the message to be sent if not already prebuilt.
280  * @param type Type of the message, 0 for a raw message.
281  * @param size Size of the message.
282  * @param c Connection this message belongs to (cannot be NULL).
283  * @param ch Channel this message belongs to, if applicable (otherwise NULL).
284  * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
285  */
286 void
287 GMC_queue_add (void* cls,
288                uint16_t type,
289                size_t size,
290                struct MeshConnection* c,
291                struct MeshChannel* ch,
292                int fwd);
293
294
295 /**
296  * Free a transmission that was already queued with all resources
297  * associated to the request.
298  *
299  * @param queue Queue handler to cancel.
300  * @param clear_cls Is it necessary to free associated cls?
301  */
302 void
303 GMC_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
304
305
306 /**
307  * Core callback to write a queued packet to core buffer
308  *
309  * @param cls Closure (peer info).
310  * @param size Number of bytes available in buf.
311  * @param buf Where the to write the message.
312  *
313  * @return number of bytes written to buf
314  */
315 size_t
316 GMC_queue_send (void *cls, size_t size, void *buf);
317
318
319
320 /**
321  * Is this peer the first one on the connection?
322  *
323  * @param c Connection.
324  * @param fwd Is this about fwd traffic?
325  *
326  * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
327  */
328 int
329 GMC_is_origin (struct MeshConnection *c, int fwd);
330
331 /**
332  * Is this peer the last one on the connection?
333  *
334  * @param c Connection.
335  * @param fwd Is this about fwd traffic?
336  *            Note that the ROOT is the terminal for BCK traffic!
337  *
338  * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
339  */
340 int
341 GMC_is_terminal (struct MeshConnection *c, int fwd);
342
343 /**
344  * Sends an already built message on a connection, properly registering
345  * all used resources.
346  *
347  * @param message Message to send. Function makes a copy of it.
348  *                If message is not hop-by-hop, decrements TTL of copy.
349  * @param c Connection on which this message is transmitted.
350  * @param ch Channel on which this message is transmitted, or NULL.
351  * @param fwd Is this a fwd message?
352  */
353 void
354 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
355                            struct MeshConnection *c,
356                            struct MeshChannel *ch,
357                            int fwd);
358
359
360 #if 0                           /* keep Emacsens' auto-indent happy */
361 {
362 #endif
363 #ifdef __cplusplus
364 }
365 #endif
366
367 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
368 #endif
369 /* end of gnunet-service-mesh_connection.h */