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