2 This file is part of GNUnet.
3 Copyright (C) 2013 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file cadet/gnunet-service-cadet_peer.h
23 * @brief cadet service; dealing with remote peers
24 * @author Bartlomiej Polot
26 * All functions in this file should use the prefix GMP (Gnunet Cadet Peer)
29 #ifndef GNUNET_SERVICE_CADET_PEER_H
30 #define GNUNET_SERVICE_CADET_PEER_H
35 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
42 #include "cadet_path.h"
45 * Struct containing all information regarding a given peer
50 * Handle to queued messages on a peer level.
52 struct CadetPeerQueue;
54 #include "gnunet-service-cadet_connection.h"
58 * Callback called when a queued message is sent.
61 * @param c Connection this message was on.
62 * @param fwd Was this a FWD going message?
63 * @param sent Was it really sent? (Could have been canceled)
64 * @param type Type of message sent.
65 * @param payload_type Type of payload, if applicable.
66 * @param pid Message ID, or 0 if not applicable (create, destroy, etc).
67 * @param size Size of the message.
68 * @param wait Time spent waiting for core (only the time for THIS message)
71 (*GCP_sent) (void *cls,
72 struct CadetConnection *c, int fwd, int sent,
73 uint16_t type, uint16_t payload_type, uint32_t pid,
75 struct GNUNET_TIME_Relative wait);
81 * @param peer Peer this path is towards.
82 * @param path Path itself
83 * @return #GNUNET_YES if should keep iterating.
84 * #GNUNET_NO otherwise.
87 (*GCP_path_iterator) (void *cls,
88 struct CadetPeer *peer,
89 struct CadetPeerPath *path);
92 /******************************************************************************/
93 /******************************** API ***********************************/
94 /******************************************************************************/
97 * Initialize peer subsystem.
99 * @param c Configuration.
102 GCP_init (const struct GNUNET_CONFIGURATION_Handle *c);
105 * Shut down the peer subsystem.
112 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
113 * one and insert it in the appropriate structures if the peer is not known yet.
115 * @param peer_id Full identity of the peer.
116 * @param create #GNUNET_YES if a new peer should be created if unknown.
117 * #GNUNET_NO otherwise.
119 * @return Existing or newly created peer structure.
120 * NULL if unknown and not requested @a create
123 GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create);
126 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
127 * one and insert it in the appropriate structures if the peer is not known yet.
129 * @param peer Short identity of the peer.
130 * @param create #GNUNET_YES if a new peer should be created if unknown.
131 * #GNUNET_NO otherwise.
133 * @return Existing or newly created peer structure.
134 * NULL if unknown and not requested @a create
137 GCP_get_short (const GNUNET_PEER_Id peer, int create);
140 * Try to establish a new connection to this peer (in its tunnel).
141 * If the peer doesn't have any path to it yet, try to get one.
142 * If the peer already has some path, send a CREATE CONNECTION towards it.
144 * @param peer Peer to connect to.
147 GCP_connect (struct CadetPeer *peer);
150 * @brief Send a message to another peer (using CORE).
152 * @param peer Peer towards which to queue the message.
153 * @param message Message to send.
154 * @param payload_type Type of the message's payload, for debug messages.
155 * 0 if the message is a retransmission (unknown payload).
156 * UINT16_MAX if the message does not have payload.
157 * @param payload_id ID of the payload (MID, ACK #, etc)
158 * @param c Connection this message belongs to (can be NULL).
159 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
160 * @param cont Continuation to be called once CORE has sent the message.
161 * @param cont_cls Closure for @c cont.
163 struct CadetPeerQueue *
164 GCP_send (struct CadetPeer *peer,
165 const struct GNUNET_MessageHeader *message,
166 uint16_t payload_type,
168 struct CadetConnection *c,
174 * Cancel sending a message. Message must have been sent with
175 * #GCP_send before. May not be called after the notify sent
176 * callback has been called.
178 * It does NOT call the continuation given to #GCP_send.
180 * @param q Queue handle to cancel
183 GCP_send_cancel (struct CadetPeerQueue *q);
192 GCP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel *t);
196 * Check whether there is a direct (core level) connection to peer.
198 * @param peer Peer to check.
200 * @return #GNUNET_YES if there is a direct connection.
203 GCP_is_neighbor (const struct CadetPeer *peer);
207 * Create and initialize a new tunnel towards a peer, in case it has none.
209 * Does not generate any traffic, just creates the local data structures.
211 * @param peer Peer towards which to create the tunnel.
214 GCP_add_tunnel (struct CadetPeer *peer);
218 * Add a connection to a neighboring peer.
220 * Store that the peer is the first hop of the connection in one
221 * direction and that on peer disconnect the connection must be
222 * notified and destroyed, for it will no longer be valid.
224 * @param peer Peer to add connection to.
225 * @param c Connection to add.
226 * @param pred #GNUNET_YES if we are predecessor, #GNUNET_NO if we are successor
229 GCP_add_connection (struct CadetPeer *peer,
230 struct CadetConnection *c,
235 * Add the path to the peer and update the path used to reach it in case this
238 * @param peer Destination peer to add the path to.
239 * @param path New path to add. Last peer must be the peer in arg 1.
240 * Path will be either used of freed if already known.
241 * @param trusted Do we trust that this path is real?
243 * @return path if path was taken, pointer to existing duplicate if exists
246 struct CadetPeerPath *
247 GCP_add_path (struct CadetPeer *peer,
248 struct CadetPeerPath *p,
253 * Add the path to the origin peer and update the path used to reach it in case
254 * this is the shortest.
255 * The path is given in peer_info -> destination, therefore we turn the path
258 * @param peer Peer to add the path to, being the origin of the path.
259 * @param path New path to add after being inversed.
260 * Path will be either used or freed.
261 * @param trusted Do we trust that this path is real?
263 * @return path if path was taken, pointer to existing duplicate if exists
266 struct CadetPeerPath *
267 GCP_add_path_to_origin (struct CadetPeer *peer,
268 struct CadetPeerPath *path,
272 * Adds a path to the info of all the peers in the path
274 * @param p Path to process.
275 * @param confirmed Whether we know if the path works or not.
278 GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed);
282 * Remove any path to the peer that has the extact same peers as the one given.
284 * @param peer Peer to remove the path from.
285 * @param path Path to remove. Is always destroyed .
288 GCP_remove_path (struct CadetPeer *peer,
289 struct CadetPeerPath *path);
293 * Check that we are aware of a connection from a neighboring peer.
295 * @param peer Peer to the connection is with
296 * @param c Connection that should be in the map with this peer.
299 GCP_check_connection (const struct CadetPeer *peer,
300 const struct CadetConnection *c);
304 * Remove a connection from a neighboring peer.
306 * @param peer Peer to remove connection from.
307 * @param c Connection to remove.
310 GCP_remove_connection (struct CadetPeer *peer,
311 const struct CadetConnection *c);
315 * Start the DHT search for new paths towards the peer: we don't have
316 * enough good connections.
318 * @param peer Destination peer.
321 GCP_start_search (struct CadetPeer *peer);
325 * Stop the DHT search for new paths towards the peer: we already have
326 * enough good connections.
328 * @param peer Destination peer.
331 GCP_stop_search (struct CadetPeer *peer);
335 * Get the Full ID of a peer.
337 * @param peer Peer to get from.
339 * @return Full ID of peer.
341 const struct GNUNET_PeerIdentity *
342 GCP_get_id (const struct CadetPeer *peer);
346 * Get the Short ID of a peer.
348 * @param peer Peer to get from.
350 * @return Short ID of peer.
353 GCP_get_short_id (const struct CadetPeer *peer);
357 * Get the tunnel towards a peer.
359 * @param peer Peer to get from.
361 * @return Tunnel towards peer.
364 GCP_get_tunnel (const struct CadetPeer *peer);
368 * Set the hello message.
370 * @param peer Peer whose message to set.
371 * @param hello Hello message.
374 GCP_set_hello (struct CadetPeer *peer,
375 const struct GNUNET_HELLO_Message *hello);
379 * Get the hello message.
381 * @param peer Peer whose message to get.
383 * @return Hello message.
385 struct GNUNET_HELLO_Message *
386 GCP_get_hello (struct CadetPeer *peer);
390 * Try to connect to a peer on TRANSPORT level.
392 * @param peer Peer to whom to connect.
395 GCP_try_connect (struct CadetPeer *peer);
398 * Notify a peer that a link between two other peers is broken. If any path
399 * used that link, eliminate it.
401 * @param peer Peer affected by the change.
402 * @param peer1 Peer whose link is broken.
403 * @param peer2 Peer whose link is broken.
406 GCP_notify_broken_link (struct CadetPeer *peer,
407 const struct GNUNET_PeerIdentity *peer1,
408 const struct GNUNET_PeerIdentity *peer2);
412 * Count the number of known paths toward the peer.
414 * @param peer Peer to get path info.
416 * @return Number of known paths.
419 GCP_count_paths (const struct CadetPeer *peer);
422 * Iterate over the paths to a peer.
424 * @param peer Peer to get path info.
425 * @param callback Function to call for every path.
426 * @param cls Closure for @a callback.
428 * @return Number of iterated paths.
431 GCP_iterate_paths (struct CadetPeer *peer,
432 GCP_path_iterator callback,
437 * Iterate all known peers.
439 * @param iter Iterator.
440 * @param cls Closure for @c iter.
443 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter, void *cls);
447 * Get the static string for a peer ID.
451 * @return Static string for it's ID.
454 GCP_2s (const struct CadetPeer *peer);
458 * Log all kinds of info about a peer.
463 GCP_debug (const struct CadetPeer *p,
464 enum GNUNET_ErrorType level);
467 #if 0 /* keep Emacsens' auto-indent happy */
474 /* ifndef GNUNET_CADET_SERVICE_PEER_H */
476 /* end of gnunet-cadet-service_peer.h */