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,
76 uint16_t payload_type,
77 struct CadetEncryptedMessageIdentifier pid,
79 struct GNUNET_TIME_Relative wait);
85 * @param peer Peer this path is towards.
86 * @param path Path itself
87 * @return #GNUNET_YES if should keep iterating.
88 * #GNUNET_NO otherwise.
91 (*GCP_path_iterator) (void *cls,
92 struct CadetPeer *peer,
93 struct CadetPeerPath *path);
96 /******************************************************************************/
97 /******************************** API ***********************************/
98 /******************************************************************************/
101 * Initialize peer subsystem.
103 * @param c Configuration.
106 GCP_init (const struct GNUNET_CONFIGURATION_Handle *c);
109 * Shut down the peer subsystem.
116 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
117 * one and insert it in the appropriate structures if the peer is not known yet.
119 * @param peer_id Full identity of the peer.
120 * @param create #GNUNET_YES if a new peer should be created if unknown.
121 * #GNUNET_NO otherwise.
123 * @return Existing or newly created peer structure.
124 * NULL if unknown and not requested @a create
127 GCP_get (const struct GNUNET_PeerIdentity *peer_id, int create);
131 * Retrieve the CadetPeer stucture associated with the peer. Optionally create
132 * one and insert it in the appropriate structures if the peer is not known yet.
134 * @param peer Short identity of the peer.
135 * @param create #GNUNET_YES if a new peer should be created if unknown.
136 * #GNUNET_NO otherwise.
138 * @return Existing or newly created peer structure.
139 * NULL if unknown and not requested @a create
142 GCP_get_short (const GNUNET_PEER_Id peer, int create);
146 * Try to establish a new connection to this peer (in its tunnel).
147 * If the peer doesn't have any path to it yet, try to get one.
148 * If the peer already has some path, send a CREATE CONNECTION towards it.
150 * @param peer Peer to connect to.
153 GCP_connect (struct CadetPeer *peer);
156 * @brief Send a message to another peer (using CORE).
158 * @param peer Peer towards which to queue the message.
159 * @param message Message to send.
160 * @param payload_type Type of the message's payload, for debug messages.
161 * 0 if the message is a retransmission (unknown payload).
162 * UINT16_MAX if the message does not have payload.
163 * @param payload_id ID of the payload (MID, ACK #, etc)
164 * @param c Connection this message belongs to (can be NULL).
165 * @param fwd Is this a message going root->dest? (FWD ACK are NOT FWD!)
166 * @param cont Continuation to be called once CORE has sent the message.
167 * @param cont_cls Closure for @c cont.
169 struct CadetPeerQueue *
170 GCP_send (struct CadetPeer *peer,
171 const struct GNUNET_MessageHeader *message,
172 uint16_t payload_type,
173 struct CadetEncryptedMessageIdentifier payload_id,
174 struct CadetConnection *c,
180 * Cancel sending a message. Message must have been sent with
181 * #GCP_send before. May not be called after the notify sent
182 * callback has been called.
184 * It does NOT call the continuation given to #GCP_send.
186 * @param q Queue handle to cancel
189 GCP_send_cancel (struct CadetPeerQueue *q);
198 GCP_set_tunnel (struct CadetPeer *peer, struct CadetTunnel *t);
202 * Check whether there is a direct (core level) connection to peer.
204 * @param peer Peer to check.
206 * @return #GNUNET_YES if there is a direct connection.
209 GCP_is_neighbor (const struct CadetPeer *peer);
213 * Create and initialize a new tunnel towards a peer, in case it has none.
215 * Does not generate any traffic, just creates the local data structures.
217 * @param peer Peer towards which to create the tunnel.
220 GCP_add_tunnel (struct CadetPeer *peer);
224 * Add a connection to a neighboring peer.
226 * Store that the peer is the first hop of the connection in one
227 * direction and that on peer disconnect the connection must be
228 * notified and destroyed, for it will no longer be valid.
230 * @param peer Peer to add connection to.
231 * @param c Connection to add.
232 * @param pred #GNUNET_YES if we are predecessor, #GNUNET_NO if we are successor
235 GCP_add_connection (struct CadetPeer *peer,
236 struct CadetConnection *c,
241 * Add the path to the peer and update the path used to reach it in case this
244 * @param peer Destination peer to add the path to.
245 * @param path New path to add. Last peer must be the peer in arg 1.
246 * Path will be either used of freed if already known.
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 CadetPeerPath *
253 GCP_add_path (struct CadetPeer *peer,
254 struct CadetPeerPath *p,
259 * Add the path to the origin peer and update the path used to reach it in case
260 * this is the shortest.
261 * The path is given in peer_info -> destination, therefore we turn the path
264 * @param peer Peer to add the path to, being the origin of the path.
265 * @param path New path to add after being inversed.
266 * Path will be either used or freed.
267 * @param trusted Do we trust that this path is real?
269 * @return path if path was taken, pointer to existing duplicate if exists
272 struct CadetPeerPath *
273 GCP_add_path_to_origin (struct CadetPeer *peer,
274 struct CadetPeerPath *path,
278 * Adds a path to the info of all the peers in the path
280 * @param p Path to process.
281 * @param confirmed Whether we know if the path works or not.
284 GCP_add_path_to_all (const struct CadetPeerPath *p, int confirmed);
288 * Remove any path to the peer that has the extact same peers as the one given.
290 * @param peer Peer to remove the path from.
291 * @param path Path to remove. Is always destroyed .
294 GCP_remove_path (struct CadetPeer *peer,
295 struct CadetPeerPath *path);
299 * Check that we are aware of a connection from a neighboring peer.
301 * @param peer Peer to the connection is with
302 * @param c Connection that should be in the map with this peer.
305 GCP_check_connection (const struct CadetPeer *peer,
306 const struct CadetConnection *c);
310 * Remove a connection from a neighboring peer.
312 * @param peer Peer to remove connection from.
313 * @param c Connection to remove.
316 GCP_remove_connection (struct CadetPeer *peer,
317 const struct CadetConnection *c);
321 * Start the DHT search for new paths towards the peer: we don't have
322 * enough good connections.
324 * @param peer Destination peer.
327 GCP_start_search (struct CadetPeer *peer);
331 * Stop the DHT search for new paths towards the peer: we already have
332 * enough good connections.
334 * @param peer Destination peer.
337 GCP_stop_search (struct CadetPeer *peer);
341 * Get the Full ID of a peer.
343 * @param peer Peer to get from.
345 * @return Full ID of peer.
347 const struct GNUNET_PeerIdentity *
348 GCP_get_id (const struct CadetPeer *peer);
352 * Get the Short ID of a peer.
354 * @param peer Peer to get from.
356 * @return Short ID of peer.
359 GCP_get_short_id (const struct CadetPeer *peer);
363 * Get the tunnel towards a peer.
365 * @param peer Peer to get from.
367 * @return Tunnel towards peer.
370 GCP_get_tunnel (const struct CadetPeer *peer);
374 * Set the hello message.
376 * @param peer Peer whose message to set.
377 * @param hello Hello message.
380 GCP_set_hello (struct CadetPeer *peer,
381 const struct GNUNET_HELLO_Message *hello);
385 * Get the hello message.
387 * @param peer Peer whose message to get.
389 * @return Hello message.
391 struct GNUNET_HELLO_Message *
392 GCP_get_hello (struct CadetPeer *peer);
396 * Try to connect to a peer on TRANSPORT level.
398 * @param peer Peer to whom to connect.
401 GCP_try_connect (struct CadetPeer *peer);
404 * Notify a peer that a link between two other peers is broken. If any path
405 * used that link, eliminate it.
407 * @param peer Peer affected by the change.
408 * @param peer1 Peer whose link is broken.
409 * @param peer2 Peer whose link is broken.
412 GCP_notify_broken_link (struct CadetPeer *peer,
413 const struct GNUNET_PeerIdentity *peer1,
414 const struct GNUNET_PeerIdentity *peer2);
418 * Count the number of known paths toward the peer.
420 * @param peer Peer to get path info.
422 * @return Number of known paths.
425 GCP_count_paths (const struct CadetPeer *peer);
428 * Iterate over the paths to a peer.
430 * @param peer Peer to get path info.
431 * @param callback Function to call for every path.
432 * @param cls Closure for @a callback.
434 * @return Number of iterated paths.
437 GCP_iterate_paths (struct CadetPeer *peer,
438 GCP_path_iterator callback,
443 * Iterate all known peers.
445 * @param iter Iterator.
446 * @param cls Closure for @c iter.
449 GCP_iterate_all (GNUNET_CONTAINER_PeerMapIterator iter,
454 * Get the static string for a peer ID.
458 * @return Static string for it's ID.
461 GCP_2s (const struct CadetPeer *peer);
465 * Log all kinds of info about a peer.
470 GCP_debug (const struct CadetPeer *p,
471 enum GNUNET_ErrorType level);
474 #if 0 /* keep Emacsens' auto-indent happy */
481 /* ifndef GNUNET_CADET_SERVICE_PEER_H */
483 /* end of gnunet-cadet-service_peer.h */