2 This file is part of GNUnet.
3 (C) 2009, 2010 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 include/gnunet_mesh_service.h
23 * @brief mesh service; establish tunnels to distant peers
24 * @author Christian Grothoff
27 #ifndef GNUNET_MESH_SERVICE_H
28 #define GNUNET_MESH_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_util_lib.h"
39 #include "gnunet_transport_service.h"
42 * Version number of GNUnet-mesh API.
44 #define GNUNET_MESH_VERSION 0x00000000
48 * Opaque handle to the service.
50 struct GNUNET_MESH_Handle;
53 * Opaque handle to a tunnel.
55 struct GNUNET_MESH_Tunnel;
58 * Functions with this signature are called whenever a message is
59 * received or transmitted.
61 * @param cls closure (set from GNUNET_MESH_connect)
62 * @param tunnel connection to the other end
63 * @param tunnel_ctx place to store local state associated with the tunnel
64 * @param sender who sent the message
65 * @param message the actual message
66 * @param atsi performance data for the connection
67 * @return GNUNET_OK to keep the connection open,
68 * GNUNET_SYSERR to close it (signal serious error)
71 (*GNUNET_MESH_MessageCallback) (void *cls,
72 struct GNUNET_MESH_Tunnel *tunnel,
74 const struct GNUNET_PeerIdentity *sender,
75 const struct GNUNET_MessageHeader *message,
76 const struct GNUNET_TRANSPORT_ATS_Information
81 * Message handler. Each struct specifies how to handle on particular
82 * type of message received.
84 struct GNUNET_MESH_MessageHandler
87 * Function to call for messages of "type".
89 GNUNET_MESH_MessageCallback callback;
92 * Type of the message this handler covers.
97 * Expected size of messages of this type. Use 0 for variable-size.
98 * If non-zero, messages of the given type will be discarded if they
99 * do not have the right size.
101 uint16_t expected_size;
107 * Function called whenever an inbound tunnel is destroyed. Should clean up
108 * any associated state.
110 * @param cls closure (set from GNUNET_MESH_connect)
111 * @param tunnel connection to the other end (henceforth invalid)
112 * @param tunnel_ctx place where local state associated
113 * with the tunnel is stored
115 typedef void (GNUNET_MESH_TunnelEndHandler)(void *cls,
116 const struct GNUNET_MESH_Tunnel
122 * Type for an application. Values defined in gnunet_applications.h
124 typedef uint32_t GNUNET_MESH_ApplicationType;
128 * Connect to the mesh service.
130 * @param cfg configuration to use
131 * @param cls closure for the various callbacks that follow
132 * (including handlers in the handlers array)
133 * @param cleaner function called when an *inbound* tunnel is destroyed
134 * @param handlers callbacks for messages we care about, NULL-terminated
135 * note that the mesh is allowed to drop notifications about
136 * inbound messages if the client does not process them fast
137 * enough (for this notification type, a bounded queue is used)
138 * @return handle to the mesh service NULL on error
139 * (in this case, init is never called)
141 struct GNUNET_MESH_Handle *
142 GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
144 GNUNET_MESH_TunnelEndHandler cleaner,
145 const struct GNUNET_MESH_MessageHandler *handlers,
146 const GNUNET_MESH_ApplicationType *stypes);
150 * Disconnect from the mesh service.
152 * @param handle connection to mesh to disconnect
154 void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle);
158 * Method called whenever a tunnel falls apart.
161 * @param peer peer identity the tunnel stopped working with
163 typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls,
164 const struct GNUNET_PeerIdentity *peer);
168 * Method called whenever a tunnel is established.
171 * @param peer peer identity the tunnel was created to, NULL on timeout
172 * @param atsi performance data for the connection
174 typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls,
175 const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
181 * Create a new tunnel (we're initiator and will be allowed to add/remove peers
184 * @param h mesh handle
185 * @param connect_handler function to call when peers are actually connected
186 * @param disconnect_handler function to call when peers are disconnected
187 * @param handler_cls closure for connect/disconnect handlers
189 struct GNUNET_MESH_Tunnel *
190 GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
191 GNUNET_MESH_TunnelConnectHandler
193 GNUNET_MESH_TunnelDisconnectHandler
198 * Destroy an existing tunnel.
200 * @param tun tunnel handle
203 GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun);
207 * Request that a peer should be added to the tunnel. The existing
208 * connect handler will be called ONCE with either success or failure.
210 * @param tunnel handle to existing tunnel
211 * @param timeout how long to try to establish a connection
212 * @param peer peer to add
215 GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
216 struct GNUNET_TIME_Relative timeout,
217 const struct GNUNET_PeerIdentity *peer);
221 * Request that a peer should be removed from the tunnel. The existing
222 * disconnect handler will be called ONCE if we were connected.
224 * @param tunnel handle to existing tunnel
225 * @param peer peer to remove
228 GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
229 const struct GNUNET_PeerIdentity *peer);
233 * Request that the mesh should try to connect to a peer supporting the given
236 * @param tunnel handle to existing tunnel
237 * @param timeout how long to try to establish a connection
238 * @param app_type application type that must be supported by the peer
239 * (MESH should discover peer in proximity handling this type)
242 GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
243 struct GNUNET_TIME_Relative timeout,
244 GNUNET_MESH_ApplicationType app_type);
248 * Handle for a transmission request.
250 struct GNUNET_MESH_TransmitHandle;
254 * Ask the mesh to call "notify" once it is ready to transmit the
255 * given number of bytes to the specified "target". If we are not yet
256 * connected to the specified peer, a call to this function will cause
257 * us to try to establish a connection.
259 * @param tunnel tunnel to use for transmission
260 * @param cork is corking allowed for this transmission?
261 * @param priority how important is the message?
262 * @param maxdelay how long can the message wait?
263 * @param target destination for the message
264 * NULL for multicast to all tunnel targets
265 * @param notify_size how many bytes of buffer space does notify want?
266 * @param notify function to call when buffer space is available;
267 * will be called with NULL on timeout or if the overall queue
268 * for this peer is larger than queue_size and this is currently
269 * the message with the lowest priority
270 * @param notify_cls closure for notify
271 * @return non-NULL if the notify callback was queued,
272 * NULL if we can not even queue the request (insufficient
273 * memory); if NULL is returned, "notify" will NOT be called.
275 struct GNUNET_MESH_TransmitHandle *
276 GNUNET_MESH_notify_transmit_ready (struct
284 const struct GNUNET_PeerIdentity *target,
287 GNUNET_CONNECTION_TransmitReadyNotify
294 * Cancel the specified transmission-ready notification.
296 * @param th handle that was returned by "notify_transmit_ready".
299 GNUNET_MESH_notify_transmit_ready_cancel (struct GNUNET_MESH_TransmitHandle
303 #if 0 /* keep Emacsens' auto-indent happy */
310 /* ifndef GNUNET_MESH_SERVICE_H */
312 /* end of gnunet_mesh_service.h */