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"
44 #include "gnunet-service-mesh_peer.h"
48 * All the states a connection can be in.
50 enum MeshConnectionState
53 * Uninitialized status, should never appear in operation.
58 * Connection create message sent, waiting for ACK.
63 * Connection ACK sent, waiting for ACK.
68 * Connection confirmed, ready to carry traffic.
70 MESH_CONNECTION_READY,
75 * Struct containing all information regarding a connection to a peer.
77 struct MeshConnection;
83 * Core handler for connection creation.
85 * @param cls Closure (unused).
86 * @param peer Sender (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_create (void *cls, const struct GNUNET_PeerIdentity *peer,
94 const struct GNUNET_MessageHeader *message);
97 * Core handler for path confirmations.
100 * @param message message
101 * @param peer peer identity this notification is about
103 * @return GNUNET_OK to keep the connection open,
104 * GNUNET_SYSERR to close it (signal serious error)
107 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
108 const struct GNUNET_MessageHeader *message);
111 * Core handler for notifications of broken paths
113 * @param cls Closure (unused).
114 * @param peer Peer identity of sending neighbor.
115 * @param message Message.
117 * @return GNUNET_OK to keep the connection open,
118 * GNUNET_SYSERR to close it (signal serious error)
121 GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
122 const struct GNUNET_MessageHeader *message);
125 * Core handler for tunnel destruction
127 * @param cls Closure (unused).
128 * @param peer Peer identity of sending neighbor.
129 * @param message Message.
131 * @return GNUNET_OK to keep the connection open,
132 * GNUNET_SYSERR to close it (signal serious error)
135 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
136 const struct GNUNET_MessageHeader *message);
139 * Core handler for mesh network traffic going orig->dest.
141 * @param cls Closure (unused).
142 * @param message Message received.
143 * @param peer Peer who sent the message.
145 * @return GNUNET_OK to keep the connection open,
146 * GNUNET_SYSERR to close it (signal serious error)
149 GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
150 const struct GNUNET_MessageHeader *message);
154 * Core handler for mesh network traffic going dest->orig.
156 * @param cls Closure (unused).
157 * @param message Message received.
158 * @param peer Peer who sent the message.
160 * @return GNUNET_OK to keep the connection open,
161 * GNUNET_SYSERR to close it (signal serious error)
164 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_MessageHeader *message);
168 * Core handler for mesh network traffic point-to-point acks.
171 * @param message message
172 * @param peer peer identity this notification is about
174 * @return GNUNET_OK to keep the connection open,
175 * GNUNET_SYSERR to close it (signal serious error)
178 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
179 const struct GNUNET_MessageHeader *message);
182 * Core handler for mesh network traffic point-to-point ack polls.
185 * @param message message
186 * @param peer peer identity this notification is about
188 * @return GNUNET_OK to keep the connection open,
189 * GNUNET_SYSERR to close it (signal serious error)
192 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
193 const struct GNUNET_MessageHeader *message);
196 * Core handler for mesh keepalives.
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)
204 * TODO: Check who we got this from, to validate route.
207 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
208 const struct GNUNET_MessageHeader *message);
211 * Initialize the connections subsystem
213 * @param c Configuration handle.
216 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
219 * Shut down the connections subsystem.
225 * Create a connection.
227 * @param cid Connection ID (either created locally or imposed remotely).
228 * @param t Tunnel this connection belongs to (or NULL);
229 * @param p Path this connection has to use.
230 * @param own_pos Own position in the @c p path.
232 struct MeshConnection *
233 GMC_new (const struct GNUNET_HashCode *cid,
234 struct MeshTunnel3 *t,
235 struct MeshPeerPath *p,
236 unsigned int own_pos);
239 * Connection is no longer needed: destroy it and remove from tunnel.
241 * @param c Connection to destroy.
244 GMC_destroy (struct MeshConnection *c);
246 struct MeshConnection *
247 GMC_next (struct MeshConnection *c);
250 * Get the connection ID.
252 * @param c Connection to get the ID from.
254 * @return ID of the connection.
256 const struct GNUNET_HashCode *
257 GMC_get_id (const struct MeshConnection *c);
260 * Get the connection state.
262 * @param c Connection to get the state from.
264 * @return state of the connection.
266 enum MeshConnectionState
267 GMC_get_state (const struct MeshConnection *c);
270 * Get free buffer space in a connection.
272 * @param c Connection.
273 * @param fwd Is query about FWD traffic?
275 * @return Free buffer space [0 - max_msgs_queue/max_connections]
278 GMC_get_buffer (struct MeshConnection *c, int fwd);
281 * Get messages queued in a connection.
283 * @param c Connection.
284 * @param fwd Is query about FWD traffic?
286 * @return Number of messages queued.
289 GMC_get_qn (struct MeshConnection *c, int fwd);
292 * Send FWD keepalive packets for a connection.
294 * @param cls Closure (connection for which to send the keepalive).
295 * @param tc Notification context.
298 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
301 * Send BCK keepalive packets for a connection.
303 * @param cls Closure (connection for which to send the keepalive).
304 * @param tc Notification context.
307 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
311 * Change the tunnel state.
313 * @param c Connection whose state to change.
314 * @param state New state.
317 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
320 * Notify other peers on a connection of a broken link. Mark connections
321 * to destroy after all traffic has been sent.
323 * @param c Connection on which there has been a disconnection.
324 * @param peer Peer that disconnected.
325 * @param my_full_id My ID (to send to other peers).
328 GMC_notify_broken (struct MeshConnection *c,
329 struct MeshPeer *peer,
330 struct GNUNET_PeerIdentity *my_full_id);
333 * Is this peer the first one on the connection?
335 * @param c Connection.
336 * @param fwd Is this about fwd traffic?
338 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
341 GMC_is_origin (struct MeshConnection *c, int fwd);
344 * Is this peer the last one on the connection?
346 * @param c Connection.
347 * @param fwd Is this about fwd traffic?
348 * Note that the ROOT is the terminal for BCK traffic!
350 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
353 GMC_is_terminal (struct MeshConnection *c, int fwd);
356 * Sends an already built message on a connection, properly registering
357 * all used resources.
359 * @param message Message to send. Function makes a copy of it.
360 * If message is not hop-by-hop, decrements TTL of copy.
361 * @param c Connection on which this message is transmitted.
362 * @param ch Channel on which this message is transmitted, or NULL.
363 * @param fwd Is this a fwd message?
366 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
367 struct MeshConnection *c,
368 struct MeshChannel *ch,
372 * Send a message to all peers in this connection that the connection
373 * is no longer valid.
375 * If some peer should not receive the message, it should be zero'ed out
376 * before calling this function.
378 * @param c The connection whose peers to notify.
381 GMC_send_destroy (struct MeshConnection *c);
383 #if 0 /* keep Emacsens' auto-indent happy */
390 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
392 /* end of gnunet-service-mesh_connection.h */