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"
44 * All the states a connection can be in.
46 enum MeshConnectionState
49 * Uninitialized status, should never appear in operation.
54 * Connection create message sent, waiting for ACK.
59 * Connection ACK sent, waiting for ACK.
64 * Connection confirmed, ready to carry traffic.
66 MESH_CONNECTION_READY,
71 * Struct containing all information regarding a connection to a peer.
73 struct MeshConnection;
75 #include "mesh_path.h"
76 #include "gnunet-service-mesh_channel.h"
77 #include "gnunet-service-mesh_peer.h"
82 * Core handler for connection creation.
84 * @param cls Closure (unused).
85 * @param peer Sender (neighbor).
86 * @param message Message.
88 * @return GNUNET_OK to keep the connection open,
89 * GNUNET_SYSERR to close it (signal serious error)
92 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
93 const struct GNUNET_MessageHeader *message);
96 * Core handler for path confirmations.
99 * @param message message
100 * @param peer peer identity this notification is about
102 * @return GNUNET_OK to keep the connection open,
103 * GNUNET_SYSERR to close it (signal serious error)
106 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
107 const struct GNUNET_MessageHeader *message);
110 * Core handler for notifications of broken paths
112 * @param cls Closure (unused).
113 * @param id Peer identity of sending neighbor.
114 * @param message Message.
116 * @return GNUNET_OK to keep the connection open,
117 * GNUNET_SYSERR to close it (signal serious error)
120 GMC_handle_broken (void* cls,
121 const struct GNUNET_PeerIdentity* id,
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 encrypted mesh network traffic (channel mgmt, data).
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_encrypted (void *cls, const struct GNUNET_PeerIdentity *peer,
150 const struct GNUNET_MessageHeader *message);
153 * Core handler for mesh network traffic point-to-point acks.
156 * @param message message
157 * @param peer peer identity this notification is about
159 * @return GNUNET_OK to keep the connection open,
160 * GNUNET_SYSERR to close it (signal serious error)
163 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
164 const struct GNUNET_MessageHeader *message);
167 * Core handler for mesh network traffic point-to-point ack polls.
170 * @param message message
171 * @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)
177 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
178 const struct GNUNET_MessageHeader *message);
181 * Core handler for mesh keepalives.
184 * @param message message
185 * @param peer peer identity this notification is about
186 * @return GNUNET_OK to keep the connection open,
187 * GNUNET_SYSERR to close it (signal serious error)
189 * TODO: Check who we got this from, to validate route.
192 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
193 const struct GNUNET_MessageHeader *message);
196 * Send an ACK on the appropriate connection/channel, depending on
197 * the direction and the position of the peer.
199 * @param c Which connection to send the hop-by-hop ACK.
200 * @param fwd Is this a fwd ACK? (will go dest->root)
203 GMC_send_ack (struct MeshConnection *c, int fwd);
206 * Initialize the connections subsystem
208 * @param c Configuration handle.
211 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
214 * Shut down the connections subsystem.
220 * Create a connection.
222 * @param cid Connection ID (either created locally or imposed remotely).
223 * @param t Tunnel this connection belongs to (or NULL);
224 * @param p Path this connection has to use.
225 * @param own_pos Own position in the @c p path.
227 * @return Newly created connection, NULL in case of error (own id not in path).
229 struct MeshConnection *
230 GMC_new (const struct GNUNET_HashCode *cid,
231 struct MeshTunnel3 *t,
232 struct MeshPeerPath *p,
233 unsigned int own_pos);
236 * Connection is no longer needed: destroy it.
238 * Cancels all pending traffic (including possible DESTROY messages), all
239 * maintenance tasks and removes the connection from neighbor peers and tunnel.
241 * @param c Connection to destroy.
244 GMC_destroy (struct MeshConnection *c);
247 * Get the connection ID.
249 * @param c Connection to get the ID from.
251 * @return ID of the connection.
253 const struct GNUNET_HashCode *
254 GMC_get_id (const struct MeshConnection *c);
257 * Get the connection path.
259 * @param c Connection to get the path from.
261 * @return path used by the connection.
263 const struct MeshPeerPath *
264 GMC_get_path (const struct MeshConnection *c);
267 * Get the connection state.
269 * @param c Connection to get the state from.
271 * @return state of the connection.
273 enum MeshConnectionState
274 GMC_get_state (const struct MeshConnection *c);
277 * Get the connection tunnel.
279 * @param c Connection to get the tunnel from.
281 * @return tunnel of the connection.
284 GMC_get_tunnel (const struct MeshConnection *c);
287 * Get free buffer space in a connection.
289 * @param c Connection.
290 * @param fwd Is query about FWD traffic?
292 * @return Free buffer space [0 - max_msgs_queue/max_connections]
295 GMC_get_buffer (struct MeshConnection *c, int fwd);
298 * Get how many messages have we allowed to send to us from a direction.
300 * @param c Connection.
301 * @param fwd Are we asking about traffic from FWD (BCK messages)?
303 * @return last_ack_sent - last_pid_recv
306 GMC_get_allowed (struct MeshConnection *c, int fwd);
309 * Get messages queued in a connection.
311 * @param c Connection.
312 * @param fwd Is query about FWD traffic?
314 * @return Number of messages queued.
317 GMC_get_qn (struct MeshConnection *c, int fwd);
320 * Allow the connection to advertise a buffer of the given size.
322 * The connection will send an @c fwd ACK message (so: in direction !fwd)
323 * allowing up to last_pid_recv + buffer.
325 * @param c Connection.
326 * @param buffer How many more messages the connection can accept.
327 * @param fwd Is this about FWD traffic? (The ack will go dest->root).
330 GMC_allow (struct MeshConnection *c, unsigned int buffer, int fwd);
333 * Send FWD keepalive packets for a connection.
335 * @param cls Closure (connection for which to send the keepalive).
336 * @param tc Notification context.
339 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
342 * Send BCK keepalive packets for a connection.
344 * @param cls Closure (connection for which to send the keepalive).
345 * @param tc Notification context.
348 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
352 * Notify other peers on a connection of a broken link. Mark connections
353 * to destroy after all traffic has been sent.
355 * @param c Connection on which there has been a disconnection.
356 * @param peer Peer that disconnected.
359 GMC_notify_broken (struct MeshConnection *c,
360 struct MeshPeer *peer);
363 * Is this peer the first one on the connection?
365 * @param c Connection.
366 * @param fwd Is this about fwd traffic?
368 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
371 GMC_is_origin (struct MeshConnection *c, int fwd);
374 * Is this peer the last one on the connection?
376 * @param c Connection.
377 * @param fwd Is this about fwd traffic?
378 * Note that the ROOT is the terminal for BCK traffic!
380 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
383 GMC_is_terminal (struct MeshConnection *c, int fwd);
386 * See if we are allowed to send by the next hop in the given direction.
388 * @param c Connection.
389 * @param fwd Is this about fwd traffic?
391 * @return GNUNET_YES in case it's OK.
394 GMC_is_sendable (struct MeshConnection *c, int fwd);
397 * Sends an already built message on a connection, properly registering
398 * all used resources.
400 * @param message Message to send. Function makes a copy of it.
401 * If message is not hop-by-hop, decrements TTL of copy.
402 * @param c Connection on which this message is transmitted.
403 * @param fwd Is this a fwd message?
406 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
407 struct MeshConnection *c,
411 * Sends a CREATE CONNECTION message for a path to a peer.
412 * Changes the connection and tunnel states if necessary.
414 * @param connection Connection to create.
417 GMC_send_create (struct MeshConnection *connection);
420 * Send a message to all peers in this connection that the connection
421 * is no longer valid.
423 * If some peer should not receive the message, it should be zero'ed out
424 * before calling this function.
426 * @param c The connection whose peers to notify.
429 GMC_send_destroy (struct MeshConnection *c);
432 * @brief Start a polling timer for the connection.
434 * When a neighbor does not accept more traffic on the connection it could be
435 * caused by a simple congestion or by a lost ACK. Polling enables to check
436 * for the lastest ACK status for a connection.
438 * @param c Connection.
439 * @param fwd Should we poll in the FWD direction?
442 GMC_start_poll (struct MeshConnection *c, int fwd);
446 * @brief Stop polling a connection for ACKs.
448 * Once we have enough ACKs for future traffic, polls are no longer necessary.
450 * @param c Connection.
451 * @param fwd Should we stop the poll in the FWD direction?
454 GMC_stop_poll (struct MeshConnection *c, int fwd);
457 * Get a (static) string for a connection.
459 * @param c Connection.
462 GMC_2s (struct MeshConnection *c);
464 #if 0 /* keep Emacsens' auto-indent happy */
471 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
473 /* end of gnunet-service-mesh_connection.h */