2 This file is part of GNUnet.
3 (C) 2011 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/mesh_api_new.c
23 * @brief mesh api: client implementation of mesh service
24 * @author Bartlomiej Polot
31 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_mesh_service.h"
41 * Opaque handle to the service.
43 struct GNUNET_MESH_Handle {
44 struct GNUNET_MESH_Tunnel *head;
45 struct GNUNET_MESH_Tunnel *tail;
46 GNUNET_MESH_TunnelEndHandler cleaner;
50 * Opaque handle to a tunnel.
52 struct GNUNET_MESH_Tunnel {
54 GNUNET_PEER_Id destination;
55 GNUNET_MESH_TunnelConnectHandler connect_handler;
56 GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
57 GNUNET_PEER_Id *peers;
63 * Connect to the mesh service.
65 * @param cfg configuration to use
66 * @param cls closure for the various callbacks that follow
67 * (including handlers in the handlers array)
68 * @param cleaner function called when an *inbound* tunnel is destroyed
69 * @param handlers callbacks for messages we care about, NULL-terminated
70 * note that the mesh is allowed to drop notifications about
71 * inbound messages if the client does not process them fast
72 * enough (for this notification type, a bounded queue is used)
73 * @return handle to the mesh service
74 * NULL on error (in this case, init is never called)
76 struct GNUNET_MESH_Handle *
77 GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
79 GNUNET_MESH_TunnelEndHandler cleaner,
80 const struct GNUNET_MESH_MessageHandler *handlers,
81 const GNUNET_MESH_ApplicationType *stypes) {
82 GNUNET_MESH_Handle *h;
83 h = GNUNET_malloc(sizeof(GNUNET_MESH_Handle));
91 * Disconnect from the mesh service.
93 * @param handle connection to mesh to disconnect
95 void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
103 * Create a new tunnel (we're initiator and will be allowed to add/remove peers
106 * @param h mesh handle
107 * @param connect_handler function to call when peers are actually connected
108 * @param disconnect_handler function to call when peers are disconnected
109 * @param handler_cls closure for connect/disconnect handlers
111 struct GNUNET_MESH_Tunnel *
112 GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
113 GNUNET_MESH_TunnelConnectHandler
115 GNUNET_MESH_TunnelDisconnectHandler
118 GNUNET_MESH_Tunnel *tunnel;
119 tunnel = GNUNET_malloc(sizeof(GNUNET_MESH_Tunnel));
121 tunnel->connect_handler = connect_handler;
122 tunnel->disconnect_handler = disconnect_handler;
123 tunnel->peers = NULL;
124 tunnel->cls = handler_cls;
131 * Request that a peer should be added to the tunnel. The existing
132 * connect handler will be called ONCE with either success or failure.
134 * @param tunnel handle to existing tunnel
135 * @param timeout how long to try to establish a connection
136 * @param peer peer to add
139 GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
140 struct GNUNET_TIME_Relative timeout,
141 const struct GNUNET_PeerIdentity *peer) {
142 static GNUNET_PEER_Id peer_id;
144 peer_id = GNUNET_PEER_intern(peer);
146 /* FIXME ACTUALLY DO STUFF */
147 tunnel->peers = &peer;
148 tunnel->connect_handler(tunnel->cls, peer, NULL);
154 * Request that a peer should be removed from the tunnel. The existing
155 * disconnect handler will be called ONCE if we were connected.
157 * @param tunnel handle to existing tunnel
158 * @param peer peer to remove
161 GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
162 const struct GNUNET_PeerIdentity *peer) {
163 /* FIXME ACTUALLY DO STUFF */
164 tunnel->peers = NULL;
165 tunnel->disconnect_handler(tunnel->cls, peer);
171 * Request that the mesh should try to connect to a peer supporting the given
174 * @param tunnel handle to existing tunnel
175 * @param timeout how long to try to establish a connection
176 * @param app_type application type that must be supported by the peer (MESH
177 * should discover peer in proximity handling this type)
180 GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
181 struct GNUNET_TIME_Relative timeout,
182 GNUNET_MESH_ApplicationType
189 * Ask the mesh to call "notify" once it is ready to transmit the
190 * given number of bytes to the specified "target". If we are not yet
191 * connected to the specified peer, a call to this function will cause
192 * us to try to establish a connection.
194 * @param tunnel tunnel to use for transmission
195 * @param cork is corking allowed for this transmission?
196 * @param priority how important is the message?
197 * @param maxdelay how long can the message wait?
198 * @param target destination for the message,
199 * NULL for multicast to all tunnel targets
200 * @param notify_size how many bytes of buffer space does notify want?
201 * @param notify function to call when buffer space is available;
202 * will be called with NULL on timeout or if the overall queue
203 * for this peer is larger than queue_size and this is currently
204 * the message with the lowest priority
205 * @param notify_cls closure for notify
206 * @return non-NULL if the notify callback was queued,
207 * NULL if we can not even queue the request (insufficient
208 * memory); if NULL is returned, "notify" will NOT be called.
210 struct GNUNET_MESH_TransmitHandle *
211 GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
214 struct GNUNET_TIME_Relative maxdelay,
215 const struct GNUNET_PeerIdentity *target,
217 GNUNET_CONNECTION_TransmitReadyNotify
220 struct GNUNET_MESH_Handle *handle;
222 handle = GNUNET_malloc(sizeof(GNUNET_MESH_Handle));
228 #if 0 /* keep Emacsens' auto-indent happy */