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 "gnunet-service-mesh_channel.h"
45 * Struct containing all information regarding a connection to a peer.
47 struct MeshConnection;
53 * Core handler for connection creation.
55 * @param cls Closure (unused).
56 * @param peer Sender (neighbor).
57 * @param message Message.
59 * @return GNUNET_OK to keep the connection open,
60 * GNUNET_SYSERR to close it (signal serious error)
63 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
64 const struct GNUNET_MessageHeader *message);
67 * Core handler for path confirmations.
70 * @param message message
71 * @param peer peer identity this notification is about
73 * @return GNUNET_OK to keep the connection open,
74 * GNUNET_SYSERR to close it (signal serious error)
77 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
78 const struct GNUNET_MessageHeader *message);
81 * Core handler for notifications of broken paths
83 * @param cls Closure (unused).
84 * @param peer Peer identity of sending neighbor.
85 * @param message Message.
87 * @return GNUNET_OK to keep the connection open,
88 * GNUNET_SYSERR to close it (signal serious error)
91 GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
92 const struct GNUNET_MessageHeader *message);
95 * Core handler for tunnel destruction
97 * @param cls Closure (unused).
98 * @param peer Peer identity of sending neighbor.
99 * @param message Message.
101 * @return GNUNET_OK to keep the connection open,
102 * GNUNET_SYSERR to close it (signal serious error)
105 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
106 const struct GNUNET_MessageHeader *message);
109 * Core handler for mesh network traffic going orig->dest.
111 * @param cls Closure (unused).
112 * @param message Message received.
113 * @param peer Peer who sent the message.
115 * @return GNUNET_OK to keep the connection open,
116 * GNUNET_SYSERR to close it (signal serious error)
119 GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
120 const struct GNUNET_MessageHeader *message);
124 * Core handler for mesh network traffic going dest->orig.
126 * @param cls Closure (unused).
127 * @param message Message received.
128 * @param peer Peer who sent the message.
130 * @return GNUNET_OK to keep the connection open,
131 * GNUNET_SYSERR to close it (signal serious error)
134 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
135 const struct GNUNET_MessageHeader *message);
138 * Core handler for mesh network traffic point-to-point acks.
141 * @param message message
142 * @param peer peer identity this notification is about
144 * @return GNUNET_OK to keep the connection open,
145 * GNUNET_SYSERR to close it (signal serious error)
148 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
149 const struct GNUNET_MessageHeader *message);
152 * Core handler for mesh network traffic point-to-point ack polls.
155 * @param message message
156 * @param peer peer identity this notification is about
158 * @return GNUNET_OK to keep the connection open,
159 * GNUNET_SYSERR to close it (signal serious error)
162 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_MessageHeader *message);
166 * Core handler for mesh keepalives.
169 * @param message message
170 * @param peer peer identity this notification is about
171 * @return GNUNET_OK to keep the connection open,
172 * GNUNET_SYSERR to close it (signal serious error)
174 * TODO: Check who we got this from, to validate route.
177 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
178 const struct GNUNET_MessageHeader *message);
181 * Initialize the connections subsystem
183 * @param c Configuration handle.
186 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
189 * Shut down the connections subsystem.
195 * Create a connection.
197 * @param cid Connection ID (either created locally or imposed remotely).
198 * @param t Tunnel this connection belongs to (or NULL);
199 * @param p Path this connection has to use.
200 * @param own_pos Own position in the @c p path.
202 struct MeshConnection *
203 GMC_new (const struct GNUNET_HashCode *cid,
204 struct MeshTunnel2 *t,
205 struct MeshPeerPath *p,
206 unsigned int own_pos);
209 * Connection is no longer needed: destroy it and remove from tunnel.
211 * @param c Connection to destroy.
214 GMC_destroy (struct MeshConnection *c);
217 * Get the connection ID.
219 * @param c Connection to get the ID from.
221 * @return ID of the connection.
223 const struct GNUNET_HashCode *
224 GMC_get_id (const struct MeshConnection *c);
227 * Count connections in a DLL.
230 GMC_count (const struct MeshConnection *head);
233 * Send FWD keepalive packets for a connection.
235 * @param cls Closure (connection for which to send the keepalive).
236 * @param tc Notification context.
239 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
242 * Send BCK keepalive packets for a connection.
244 * @param cls Closure (connection for which to send the keepalive).
245 * @param tc Notification context.
248 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
252 * Change the tunnel state.
254 * @param c Connection whose state to change.
255 * @param state New state.
258 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
261 * Notify other peers on a connection of a broken link. Mark connections
262 * to destroy after all traffic has been sent.
264 * @param c Connection on which there has been a disconnection.
265 * @param peer Peer that disconnected.
266 * @param my_full_id My ID (to send to other peers).
269 GMC_notify_broken (struct MeshConnection *c,
270 struct MeshPeer *peer,
271 struct GNUNET_PeerIdentity *my_full_id);
274 * @brief Queue and pass message to core when possible.
276 * @param cls Closure (@c type dependant). It will be used by queue_send to
277 * build the message to be sent if not already prebuilt.
278 * @param type Type of the message, 0 for a raw message.
279 * @param size Size of the message.
280 * @param c Connection this message belongs to (cannot be NULL).
281 * @param ch Channel this message belongs to, if applicable (otherwise NULL).
282 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
285 GMC_queue_add (void* cls,
288 struct MeshConnection* c,
289 struct MeshChannel* ch,
294 * Free a transmission that was already queued with all resources
295 * associated to the request.
297 * @param queue Queue handler to cancel.
298 * @param clear_cls Is it necessary to free associated cls?
301 GMC_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
305 * Core callback to write a queued packet to core buffer
307 * @param cls Closure (peer info).
308 * @param size Number of bytes available in buf.
309 * @param buf Where the to write the message.
311 * @return number of bytes written to buf
314 GMC_queue_send (void *cls, size_t size, void *buf);
319 * Is this peer the first one on the connection?
321 * @param c Connection.
322 * @param fwd Is this about fwd traffic?
324 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
327 GMC_is_origin (struct MeshConnection *c, int fwd);
330 * Is this peer the last one on the connection?
332 * @param c Connection.
333 * @param fwd Is this about fwd traffic?
334 * Note that the ROOT is the terminal for BCK traffic!
336 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
339 GMC_is_terminal (struct MeshConnection *c, int fwd);
342 * Sends an already built message on a connection, properly registering
343 * all used resources.
345 * @param message Message to send. Function makes a copy of it.
346 * If message is not hop-by-hop, decrements TTL of copy.
347 * @param c Connection on which this message is transmitted.
348 * @param ch Channel on which this message is transmitted, or NULL.
349 * @param fwd Is this a fwd message?
352 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
353 struct MeshConnection *c,
354 struct MeshChannel *ch,
358 #if 0 /* keep Emacsens' auto-indent happy */
365 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
367 /* end of gnunet-service-mesh_connection.h */