2 This file is part of GNUnet.
3 (C) 2013 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file mesh/gnunet-service-mesh_connection.h
23 * @brief mesh service; dealing with connections
24 * @author Bartlomiej Polot
26 * All functions in this file should use the prefix GMC (Gnunet Mesh Connection)
29 #ifndef GNUNET_SERVICE_MESH_CONNECTION_H
30 #define GNUNET_SERVICE_MESH_CONNECTION_H
35 #if 0 /* keep Emacsens' auto-indent happy */
40 #include "gnunet_util_lib.h"
42 #include "mesh_path.h"
43 #include "gnunet-service-mesh_channel.h"
47 * Struct containing all information regarding a connection to a peer.
49 struct MeshConnection;
55 * Core handler for connection creation.
57 * @param cls Closure (unused).
58 * @param peer Sender (neighbor).
59 * @param message Message.
61 * @return GNUNET_OK to keep the connection open,
62 * GNUNET_SYSERR to close it (signal serious error)
65 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
66 const struct GNUNET_MessageHeader *message);
69 * Core handler for path confirmations.
72 * @param message message
73 * @param peer peer identity this notification is about
75 * @return GNUNET_OK to keep the connection open,
76 * GNUNET_SYSERR to close it (signal serious error)
79 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
80 const struct GNUNET_MessageHeader *message);
83 * Core handler for notifications of broken paths
85 * @param cls Closure (unused).
86 * @param peer Peer identity of sending neighbor.
87 * @param message Message.
89 * @return GNUNET_OK to keep the connection open,
90 * GNUNET_SYSERR to close it (signal serious error)
93 GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
94 const struct GNUNET_MessageHeader *message);
97 * Core handler for tunnel destruction
99 * @param cls Closure (unused).
100 * @param peer Peer identity of sending neighbor.
101 * @param message Message.
103 * @return GNUNET_OK to keep the connection open,
104 * GNUNET_SYSERR to close it (signal serious error)
107 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
108 const struct GNUNET_MessageHeader *message);
111 * Core handler for mesh network traffic going orig->dest.
113 * @param cls Closure (unused).
114 * @param message Message received.
115 * @param peer Peer who sent the message.
117 * @return GNUNET_OK to keep the connection open,
118 * GNUNET_SYSERR to close it (signal serious error)
121 GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
122 const struct GNUNET_MessageHeader *message);
126 * Core handler for mesh network traffic going dest->orig.
128 * @param cls Closure (unused).
129 * @param message Message received.
130 * @param peer Peer who sent the message.
132 * @return GNUNET_OK to keep the connection open,
133 * GNUNET_SYSERR to close it (signal serious error)
136 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
137 const struct GNUNET_MessageHeader *message);
140 * Core handler for mesh network traffic point-to-point acks.
143 * @param message message
144 * @param peer peer identity this notification is about
146 * @return GNUNET_OK to keep the connection open,
147 * GNUNET_SYSERR to close it (signal serious error)
150 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
151 const struct GNUNET_MessageHeader *message);
154 * Core handler for mesh network traffic point-to-point ack polls.
157 * @param message message
158 * @param peer peer identity this notification is about
160 * @return GNUNET_OK to keep the connection open,
161 * GNUNET_SYSERR to close it (signal serious error)
164 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_MessageHeader *message);
168 * Core handler for mesh keepalives.
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)
176 * TODO: Check who we got this from, to validate route.
179 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
180 const struct GNUNET_MessageHeader *message);
183 * Initialize the connections subsystem
185 * @param c Configuration handle.
188 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
191 * Shut down the connections subsystem.
197 * Create a connection.
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.
204 struct MeshConnection *
205 GMC_new (const struct GNUNET_HashCode *cid,
206 struct MeshTunnel2 *t,
207 struct MeshPeerPath *p,
208 unsigned int own_pos);
211 * Connection is no longer needed: destroy it and remove from tunnel.
213 * @param c Connection to destroy.
216 GMC_destroy (struct MeshConnection *c);
219 * Get the connection ID.
221 * @param c Connection to get the ID from.
223 * @return ID of the connection.
225 const struct GNUNET_HashCode *
226 GMC_get_id (const struct MeshConnection *c);
229 * Count connections in a DLL.
232 GMC_count (const struct MeshConnection *head);
235 * Send FWD keepalive packets for a connection.
237 * @param cls Closure (connection for which to send the keepalive).
238 * @param tc Notification context.
241 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
244 * Send BCK keepalive packets for a connection.
246 * @param cls Closure (connection for which to send the keepalive).
247 * @param tc Notification context.
250 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
254 * Change the tunnel state.
256 * @param c Connection whose state to change.
257 * @param state New state.
260 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
263 * Notify other peers on a connection of a broken link. Mark connections
264 * to destroy after all traffic has been sent.
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).
271 GMC_notify_broken (struct MeshConnection *c,
272 struct MeshPeer *peer,
273 struct GNUNET_PeerIdentity *my_full_id);
276 * @brief Queue and pass message to core when possible.
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!)
287 GMC_queue_add (void* cls,
290 struct MeshConnection* c,
291 struct MeshChannel* ch,
296 * Free a transmission that was already queued with all resources
297 * associated to the request.
299 * @param queue Queue handler to cancel.
300 * @param clear_cls Is it necessary to free associated cls?
303 GMC_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
307 * Core callback to write a queued packet to core buffer
309 * @param cls Closure (peer info).
310 * @param size Number of bytes available in buf.
311 * @param buf Where the to write the message.
313 * @return number of bytes written to buf
316 GMC_queue_send (void *cls, size_t size, void *buf);
321 * Is this peer the first one on the connection?
323 * @param c Connection.
324 * @param fwd Is this about fwd traffic?
326 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
329 GMC_is_origin (struct MeshConnection *c, int fwd);
332 * Is this peer the last one on the connection?
334 * @param c Connection.
335 * @param fwd Is this about fwd traffic?
336 * Note that the ROOT is the terminal for BCK traffic!
338 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
341 GMC_is_terminal (struct MeshConnection *c, int fwd);
344 * Sends an already built message on a connection, properly registering
345 * all used resources.
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?
354 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
355 struct MeshConnection *c,
356 struct MeshChannel *ch,
360 #if 0 /* keep Emacsens' auto-indent happy */
367 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
369 /* end of gnunet-service-mesh_connection.h */