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_peer.h
23 * @brief mesh service; dealing with remote peers
24 * @author Bartlomiej Polot
26 * All functions in this file should use the prefix GMP (Gnunet Mesh Peer)
29 #ifndef GNUNET_SERVICE_MESH_PEER_H
30 #define GNUNET_SERVICE_MESH_PEER_H
35 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
44 * Struct containing all information regarding a given peer
49 * Struct containing info about a queued transmission to this peer
53 #include "gnunet-service-mesh_connection.h"
56 * Callback called when a queued message is sent.
59 * @param c Connection this message was on.
60 * @param sent Was it really sent? (Could have been canceled)
61 * @param type Type of message sent.
62 * @param fwd Was this a FWD going message?
63 * @param size Size of the message.
64 * @param wait Time spent waiting for core (only the time for THIS message)
66 typedef void (*GMP_sent) (void *cls,
67 struct MeshConnection *c, int sent,
68 uint16_t type, int fwd, size_t size,
69 struct GNUNET_TIME_Relative wait);
71 /******************************************************************************/
72 /******************************** API ***********************************/
73 /******************************************************************************/
76 * Initialize peer subsystem.
78 * @param c Configuration.
81 GMP_init (const struct GNUNET_CONFIGURATION_Handle *c);
84 * Shut down the peer subsystem.
91 * Retrieve the MeshPeer stucture associated with the peer, create one
92 * and insert it in the appropriate structures if the peer is not known yet.
94 * @param peer_id Full identity of the peer.
96 * @return Existing or newly created peer structure.
99 GMP_get (const struct GNUNET_PeerIdentity *peer_id);
103 * Retrieve the MeshPeer stucture associated with the peer, create one
104 * and insert it in the appropriate structures if the peer is not known yet.
106 * @param peer Short identity of the peer.
108 * @return Existing or newly created peer structure.
111 GMP_get_short (const GNUNET_PEER_Id peer);
114 * Try to establish a new connection to this peer (in its tunnel).
115 * If the peer doesn't have any path to it yet, try to get one.
116 * If the peer already has some path, send a CREATE CONNECTION towards it.
118 * @param peer Peer to connect to.
121 GMP_connect (struct MeshPeer *peer);
124 * Free a transmission that was already queued with all resources
125 * associated to the request.
127 * @param queue Queue handler to cancel.
128 * @param clear_cls Is it necessary to free associated cls?
129 * @param sent Was it really sent? (Could have been canceled)
132 GMP_queue_destroy (struct MeshPeerQueue *queue, int clear_cls, int sent);
135 * @brief Queue and pass message to core when possible.
137 * @param peer Peer towards which to queue the message.
138 * @param cls Closure (@c type dependant). It will be used by queue_send to
139 * build the message to be sent if not already prebuilt.
140 * @param type Type of the message, 0 for a raw message.
141 * @param size Size of the message.
142 * @param c Connection this message belongs to (cannot be NULL).
143 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
144 * @param cont Continuation to be called once CORE has taken the message.
145 * @param cont_cls Closure for @c cont.
147 * @return Handle to cancel the message before it is sent. Once cont is called
148 * message has been sent and therefore the handle is no longer valid.
150 struct MeshPeerQueue *
151 GMP_queue_add (struct MeshPeer *peer, void *cls, uint16_t type, size_t size,
152 struct MeshConnection *c, int fwd,
153 GMP_sent cont, void *cont_cls);
156 * Cancel all queued messages to a peer that belong to a certain connection.
158 * @param peer Peer towards whom to cancel.
159 * @param c Connection whose queued messages to cancel. Might be destroyed by
160 * the sent continuation call.
163 GMP_queue_cancel (struct MeshPeer *peer, struct MeshConnection *c);
166 * Get the first message for a connection and unqueue it.
168 * @param peer Neighboring peer.
169 * @param c Connection.
171 * @return First message for this connection.
173 struct GNUNET_MessageHeader *
174 GMP_connection_pop (struct MeshPeer *peer, struct MeshConnection *c);
177 GMP_queue_unlock (struct MeshPeer *peer, struct MeshConnection *c);
186 GMP_set_tunnel (struct MeshPeer *peer, struct MeshTunnel3 *t);
189 * Check whether there is a direct (core level) connection to peer.
191 * @param peer Peer to check.
193 * @return #GNUNET_YES if there is a direct connection.
196 GMP_is_neighbor (const struct MeshPeer *peer);
199 * Create and initialize a new tunnel towards a peer, in case it has none.
201 * Does not generate any traffic, just creates the local data structures.
203 * @param peer Peer towards which to create the tunnel.
206 GMP_add_tunnel (struct MeshPeer *peer);
209 * Add a connection to a neighboring peer.
211 * Store that the peer is the first hop of the connection in one
212 * direction and that on peer disconnect the connection must be
213 * notified and destroyed, for it will no longer be valid.
215 * @param peer Peer to add connection to.
216 * @param c Connection to add.
218 * @return GNUNET_OK on success.
221 GMP_add_connection (struct MeshPeer *peer, struct MeshConnection *c);
224 * Add the path to the peer and update the path used to reach it in case this
227 * @param peer Destination peer to add the path to.
228 * @param path New path to add. Last peer must be the peer in arg 1.
229 * Path will be either used of freed if already known.
230 * @param trusted Do we trust that this path is real?
232 * @return path if path was taken, pointer to existing duplicate if exists
235 struct MeshPeerPath *
236 GMP_add_path (struct MeshPeer *peer, struct MeshPeerPath *p, int trusted);
239 * Add the path to the origin peer and update the path used to reach it in case
240 * this is the shortest.
241 * The path is given in peer_info -> destination, therefore we turn the path
244 * @param peer Peer to add the path to, being the origin of the path.
245 * @param path New path to add after being inversed.
246 * Path will be either used or freed.
247 * @param trusted Do we trust that this path is real?
249 * @return path if path was taken, pointer to existing duplicate if exists
252 struct MeshPeerPath *
253 GMP_add_path_to_origin (struct MeshPeer *peer,
254 struct MeshPeerPath *path,
258 * Adds a path to the info of all the peers in the path
260 * @param p Path to process.
261 * @param confirmed Whether we know if the path works or not.
264 GMP_add_path_to_all (const struct MeshPeerPath *p, int confirmed);
267 * Remove any path to the peer that has the extact same peers as the one given.
269 * @param peer Peer to remove the path from.
270 * @param path Path to remove. Is always destroyed .
273 GMP_remove_path (struct MeshPeer *peer, struct MeshPeerPath *path);
276 * Remove a connection from a neighboring peer.
278 * @param peer Peer to remove connection from.
279 * @param c Connection to remove.
281 * @return GNUNET_OK on success.
284 GMP_remove_connection (struct MeshPeer *peer, const struct MeshConnection *c);
287 * Start the DHT search for new paths towards the peer: we don't have
288 * enough good connections.
290 * @param peer Destination peer.
293 GMP_start_search (struct MeshPeer *peer);
296 * Stop the DHT search for new paths towards the peer: we already have
297 * enough good connections.
299 * @param peer Destination peer.
302 GMP_stop_search (struct MeshPeer *peer);
305 * Get the Full ID of a peer.
307 * @param peer Peer to get from.
309 * @return Full ID of peer.
311 const struct GNUNET_PeerIdentity *
312 GMP_get_id (const struct MeshPeer *peer);
315 * Get the Short ID of a peer.
317 * @param peer Peer to get from.
319 * @return Short ID of peer.
322 GMP_get_short_id (const struct MeshPeer *peer);
325 * Get the tunnel towards a peer.
327 * @param peer Peer to get from.
329 * @return Tunnel towards peer.
332 GMP_get_tunnel (const struct MeshPeer *peer);
335 * Set the hello message.
337 * @param peer Peer whose message to set.
338 * @param hello Hello message.
341 GMP_set_hello (struct MeshPeer *peer, const struct GNUNET_HELLO_Message *hello);
344 * Get the hello message.
346 * @param peer Peer whose message to get.
348 * @return Hello message.
350 struct GNUNET_HELLO_Message *
351 GMP_get_hello (struct MeshPeer *peer);
355 * Try to connect to a peer on TRANSPORT level.
357 * @param peer Peer to whom to connect.
360 GMP_try_connect (struct MeshPeer *peer);
363 * Notify a peer that a link between two other peers is broken. If any path
364 * used that link, eliminate it.
366 * @param peer Peer affected by the change.
367 * @param peer1 Peer whose link is broken.
368 * @param peer2 Peer whose link is broken.
371 GMP_notify_broken_link (struct MeshPeer *peer,
372 struct GNUNET_PeerIdentity *peer1,
373 struct GNUNET_PeerIdentity *peer2);
376 * Count the number of known paths toward the peer.
378 * @param peer Peer to get path info.
380 * @return Number of known paths.
383 GMP_count_paths (const struct MeshPeer *peer);
386 * Iterate all known peers.
388 * @param iter Iterator.
389 * @param cls Closure for @c iter.
392 GMP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
395 * Get the static string for a peer ID.
399 * @return Static string for it's ID.
402 GMP_2s (const struct MeshPeer *peer);
405 #if 0 /* keep Emacsens' auto-indent happy */
412 /* ifndef GNUNET_MESH_SERVICE_PEER_H */
414 /* end of gnunet-mesh-service_peer.h */