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);
127 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
128 * one and insert it in the appropriate structures if the peer is not known yet.
130 * @param peer Short identity of the peer.
131 * @param create #GNUNET_YES if a new peer should be created if unknown.
132 * #GNUNET_NO otherwise.
134 * @return Existing or newly created peer structure.
135 * NULL if unknown and not requested @a create
138 GCP_get_short (const GNUNET_PEER_Id peer, int create);
142 * Try to establish a new connection to this peer (in its tunnel).
143 * If the peer doesn't have any path to it yet, try to get one.
144 * If the peer already has some path, send a CREATE CONNECTION towards it.
146 * @param peer Peer to connect to.
149 GCP_connect (struct CadetPeer *peer);
152 * @brief Send a message to another peer (using CORE).
154 * @param peer Peer towards which to queue the message.
155 * @param message Message to send.
156 * @param payload_type Type of the message's payload, for debug messages.
157 * 0 if the message is a retransmission (unknown payload).
158 * UINT16_MAX if the message does not have payload.
159 * @param payload_id ID of the payload (MID, ACK #, etc)
160 * @param c Connection this message belongs to (can be NULL).
161 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
162 * @param cont Continuation to be called once CORE has sent the message.
163 * @param cont_cls Closure for @c cont.
165 struct CadetPeerQueue *
166 GCP_send (struct CadetPeer *peer,
167 const struct GNUNET_MessageHeader *message,
168 uint16_t payload_type,
170 struct CadetConnection *c,
176 * Cancel sending a message. Message must have been sent with
177 * #GCP_send before. May not be called after the notify sent
178 * callback has been called.
180 * It does NOT call the continuation given to #GCP_send.
182 * @param q Queue handle to cancel
185 GCP_send_cancel (struct CadetPeerQueue *q);
194 GCP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel *t);
198 * Check whether there is a direct (core level) connection to peer.
200 * @param peer Peer to check.
202 * @return #GNUNET_YES if there is a direct connection.
205 GCP_is_neighbor (const struct CadetPeer *peer);
209 * Create and initialize a new tunnel towards a peer, in case it has none.
211 * Does not generate any traffic, just creates the local data structures.
213 * @param peer Peer towards which to create the tunnel.
216 GCP_add_tunnel (struct CadetPeer *peer);
220 * Add a connection to a neighboring peer.
222 * Store that the peer is the first hop of the connection in one
223 * direction and that on peer disconnect the connection must be
224 * notified and destroyed, for it will no longer be valid.
226 * @param peer Peer to add connection to.
227 * @param c Connection to add.
228 * @param pred #GNUNET_YES if we are predecessor, #GNUNET_NO if we are successor
231 GCP_add_connection (struct CadetPeer *peer,
232 struct CadetConnection *c,
237 * Add the path to the peer and update the path used to reach it in case this
240 * @param peer Destination peer to add the path to.
241 * @param path New path to add. Last peer must be the peer in arg 1.
242 * Path will be either used of freed if already known.
243 * @param trusted Do we trust that this path is real?
245 * @return path if path was taken, pointer to existing duplicate if exists
248 struct CadetPeerPath *
249 GCP_add_path (struct CadetPeer *peer,
250 struct CadetPeerPath *p,
255 * Add the path to the origin peer and update the path used to reach it in case
256 * this is the shortest.
257 * The path is given in peer_info -> destination, therefore we turn the path
260 * @param peer Peer to add the path to, being the origin of the path.
261 * @param path New path to add after being inversed.
262 * Path will be either used or freed.
263 * @param trusted Do we trust that this path is real?
265 * @return path if path was taken, pointer to existing duplicate if exists
268 struct CadetPeerPath *
269 GCP_add_path_to_origin (struct CadetPeer *peer,
270 struct CadetPeerPath *path,
274 * Adds a path to the info of all the peers in the path
276 * @param p Path to process.
277 * @param confirmed Whether we know if the path works or not.
280 GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed);
284 * Remove any path to the peer that has the extact same peers as the one given.
286 * @param peer Peer to remove the path from.
287 * @param path Path to remove. Is always destroyed .
290 GCP_remove_path (struct CadetPeer *peer,
291 struct CadetPeerPath *path);
295 * Check that we are aware of a connection from a neighboring peer.
297 * @param peer Peer to the connection is with
298 * @param c Connection that should be in the map with this peer.
301 GCP_check_connection (const struct CadetPeer *peer,
302 const struct CadetConnection *c);
306 * Remove a connection from a neighboring peer.
308 * @param peer Peer to remove connection from.
309 * @param c Connection to remove.
312 GCP_remove_connection (struct CadetPeer *peer,
313 const struct CadetConnection *c);
317 * Start the DHT search for new paths towards the peer: we don't have
318 * enough good connections.
320 * @param peer Destination peer.
323 GCP_start_search (struct CadetPeer *peer);
327 * Stop the DHT search for new paths towards the peer: we already have
328 * enough good connections.
330 * @param peer Destination peer.
333 GCP_stop_search (struct CadetPeer *peer);
337 * Get the Full ID of a peer.
339 * @param peer Peer to get from.
341 * @return Full ID of peer.
343 const struct GNUNET_PeerIdentity *
344 GCP_get_id (const struct CadetPeer *peer);
348 * Get the Short ID of a peer.
350 * @param peer Peer to get from.
352 * @return Short ID of peer.
355 GCP_get_short_id (const struct CadetPeer *peer);
359 * Get the tunnel towards a peer.
361 * @param peer Peer to get from.
363 * @return Tunnel towards peer.
366 GCP_get_tunnel (const struct CadetPeer *peer);
370 * Set the hello message.
372 * @param peer Peer whose message to set.
373 * @param hello Hello message.
376 GCP_set_hello (struct CadetPeer *peer,
377 const struct GNUNET_HELLO_Message *hello);
381 * Get the hello message.
383 * @param peer Peer whose message to get.
385 * @return Hello message.
387 struct GNUNET_HELLO_Message *
388 GCP_get_hello (struct CadetPeer *peer);
392 * Try to connect to a peer on TRANSPORT level.
394 * @param peer Peer to whom to connect.
397 GCP_try_connect (struct CadetPeer *peer);
400 * Notify a peer that a link between two other peers is broken. If any path
401 * used that link, eliminate it.
403 * @param peer Peer affected by the change.
404 * @param peer1 Peer whose link is broken.
405 * @param peer2 Peer whose link is broken.
408 GCP_notify_broken_link (struct CadetPeer *peer,
409 const struct GNUNET_PeerIdentity *peer1,
410 const struct GNUNET_PeerIdentity *peer2);
414 * Count the number of known paths toward the peer.
416 * @param peer Peer to get path info.
418 * @return Number of known paths.
421 GCP_count_paths (const struct CadetPeer *peer);
424 * Iterate over the paths to a peer.
426 * @param peer Peer to get path info.
427 * @param callback Function to call for every path.
428 * @param cls Closure for @a callback.
430 * @return Number of iterated paths.
433 GCP_iterate_paths (struct CadetPeer *peer,
434 GCP_path_iterator callback,
439 * Iterate all known peers.
441 * @param iter Iterator.
442 * @param cls Closure for @c iter.
445 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
450 * Get the static string for a peer ID.
454 * @return Static string for it's ID.
457 GCP_2s (const struct CadetPeer *peer);
461 * Log all kinds of info about a peer.
466 GCP_debug (const struct CadetPeer *p,
467 enum GNUNET_ErrorType level);
470 #if 0 /* keep Emacsens' auto-indent happy */
477 /* ifndef GNUNET_CADET_SERVICE_PEER_H */
479 /* end of gnunet-cadet-service_peer.h */