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"
43 * Struct containing all information regarding a connection to a peer.
45 struct MeshConnection;
51 * Core handler for connection creation.
53 * @param cls Closure (unused).
54 * @param peer Sender (neighbor).
55 * @param message Message.
57 * @return GNUNET_OK to keep the connection open,
58 * GNUNET_SYSERR to close it (signal serious error)
61 GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer,
62 const struct GNUNET_MessageHeader *message);
65 * Core handler for path confirmations.
68 * @param message message
69 * @param peer peer identity this notification is about
71 * @return GNUNET_OK to keep the connection open,
72 * GNUNET_SYSERR to close it (signal serious error)
75 GMC_handle_confirm (void *cls, const struct GNUNET_PeerIdentity *peer,
76 const struct GNUNET_MessageHeader *message);
79 * Core handler for notifications of broken paths
81 * @param cls Closure (unused).
82 * @param peer Peer identity of sending neighbor.
83 * @param message Message.
85 * @return GNUNET_OK to keep the connection open,
86 * GNUNET_SYSERR to close it (signal serious error)
89 GMC_handle_broken (void *cls, const struct GNUNET_PeerIdentity *peer,
90 const struct GNUNET_MessageHeader *message);
93 * Core handler for tunnel destruction
95 * @param cls Closure (unused).
96 * @param peer Peer identity of sending neighbor.
97 * @param message Message.
99 * @return GNUNET_OK to keep the connection open,
100 * GNUNET_SYSERR to close it (signal serious error)
103 GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
104 const struct GNUNET_MessageHeader *message);
107 * Core handler for mesh network traffic going orig->dest.
109 * @param cls Closure (unused).
110 * @param message Message received.
111 * @param peer Peer who sent the message.
113 * @return GNUNET_OK to keep the connection open,
114 * GNUNET_SYSERR to close it (signal serious error)
117 GMC_handle_fwd (void *cls, const struct GNUNET_PeerIdentity *peer,
118 const struct GNUNET_MessageHeader *message);
122 * Core handler for mesh network traffic going dest->orig.
124 * @param cls Closure (unused).
125 * @param message Message received.
126 * @param peer Peer who sent the message.
128 * @return GNUNET_OK to keep the connection open,
129 * GNUNET_SYSERR to close it (signal serious error)
132 GMC_handle_bck (void *cls, const struct GNUNET_PeerIdentity *peer,
133 const struct GNUNET_MessageHeader *message);
136 * Core handler for mesh network traffic point-to-point acks.
139 * @param message message
140 * @param peer peer identity this notification is about
142 * @return GNUNET_OK to keep the connection open,
143 * GNUNET_SYSERR to close it (signal serious error)
146 GMC_handle_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
147 const struct GNUNET_MessageHeader *message);
150 * Core handler for mesh network traffic point-to-point ack polls.
153 * @param message message
154 * @param peer peer identity this notification is about
156 * @return GNUNET_OK to keep the connection open,
157 * GNUNET_SYSERR to close it (signal serious error)
160 GMC_handle_poll (void *cls, const struct GNUNET_PeerIdentity *peer,
161 const struct GNUNET_MessageHeader *message);
164 * Core handler for mesh keepalives.
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)
172 * TODO: Check who we got this from, to validate route.
175 GMC_handle_keepalive (void *cls, const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_MessageHeader *message);
179 * Initialize the connections subsystem
181 * @param c Configuration handle.
184 GMC_init (const struct GNUNET_CONFIGURATION_Handle *c);
187 * Shut down the connections subsystem.
193 * Create a connection.
195 * @param cid Connection ID.
197 struct MeshConnection *
198 GMC_new (const struct GNUNET_HashCode *cid);
201 * Connection is no longer needed: destroy it and remove from tunnel.
203 * @param c Connection to destroy.
206 GMC_destroy (struct MeshConnection *c);
209 * Count connections in a DLL.
212 GMC_count (const struct MeshConnection *head);
215 * Send FWD keepalive packets for a connection.
217 * @param cls Closure (connection for which to send the keepalive).
218 * @param tc Notification context.
221 GMC_fwd_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
224 * Send BCK keepalive packets for a connection.
226 * @param cls Closure (connection for which to send the keepalive).
227 * @param tc Notification context.
230 GMC_bck_keepalive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
234 * Change the tunnel state.
236 * @param c Connection whose state to change.
237 * @param state New state.
240 GMC_change_state (struct MeshConnection* c, enum MeshConnectionState state);
243 * Notify other peers on a connection of a broken link. Mark connections
244 * to destroy after all traffic has been sent.
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).
251 GMC_notify_broken (struct MeshConnection *c,
252 struct MeshPeer *peer,
253 struct GNUNET_PeerIdentity *my_full_id);
256 * @brief Queue and pass message to core when possible.
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!)
267 GMC_queue_add (void* cls,
270 struct MeshConnection* c,
271 struct MeshChannel* ch,
276 * Free a transmission that was already queued with all resources
277 * associated to the request.
279 * @param queue Queue handler to cancel.
280 * @param clear_cls Is it necessary to free associated cls?
283 GMC_queue_destroy (struct MeshPeerQueue *queue, int clear_cls);
287 * Core callback to write a queued packet to core buffer
289 * @param cls Closure (peer info).
290 * @param size Number of bytes available in buf.
291 * @param buf Where the to write the message.
293 * @return number of bytes written to buf
296 GMC_queue_send (void *cls, size_t size, void *buf);
301 * Is this peer the first one on the connection?
303 * @param c Connection.
304 * @param fwd Is this about fwd traffic?
306 * @return GNUNET_YES if origin, GNUNET_NO if relay/terminal.
309 GMC_is_origin (struct MeshConnection *c, int fwd);
312 * Is this peer the last one on the connection?
314 * @param c Connection.
315 * @param fwd Is this about fwd traffic?
316 * Note that the ROOT is the terminal for BCK traffic!
318 * @return GNUNET_YES if terminal, GNUNET_NO if relay/origin.
321 GMC_is_terminal (struct MeshConnection *c, int fwd);
324 * Sends an already built message on a connection, properly registering
325 * all used resources.
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?
334 GMC_send_prebuilt_message (const struct GNUNET_MessageHeader *message,
335 struct MeshConnection *c,
336 struct MeshChannel *ch,
340 #if 0 /* keep Emacsens' auto-indent happy */
347 /* ifndef GNUNET_SERVICE_MESH_CONNECTION_H */
349 /* end of gnunet-service-mesh_connection.h */