2 This file is part of GNUnet.
3 (C) 2001 - 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 cadet/cadet_path.h
23 * @brief Path handling functions
24 * @author Bartlomiej Polot
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet-service-cadet_connection.h"
41 /******************************************************************************/
42 /************************ DATA STRUCTURES ****************************/
43 /******************************************************************************/
46 * Information regarding a possible path to reach a single peer
54 struct CadetPeerPath *next;
55 struct CadetPeerPath *prev;
58 * List of all the peers that form the path from origin to target.
60 GNUNET_PEER_Id *peers;
63 * Number of peers (hops) in the path
68 * User defined data store.
70 struct CadetConnection *c;
73 * Path's score, how reliable is the path.
78 * Task to delete the path.
79 * We tried it, it didn't work, don't try again in a while.
81 struct GNUNET_SCHEDULER_Task * path_delete;
85 /******************************************************************************/
86 /************************* FUNCTIONS *****************************/
87 /******************************************************************************/
92 * @param length How many hops will the path have.
94 * @return A newly allocated path with a peer array of the specified length.
96 struct CadetPeerPath *
97 path_new (unsigned int length);
103 * @param path The path to invert.
106 path_invert (struct CadetPeerPath *path);
110 * Duplicate a path, incrementing short peer's rc.
112 * @param path The path to duplicate.
114 struct CadetPeerPath *
115 path_duplicate (const struct CadetPeerPath *path);
119 * Get the length of a path.
121 * @param path The path to measure, with the local peer at any point of it.
123 * @return Number of hops to reach destination.
124 * UINT_MAX in case the peer is not in the path.
127 path_get_length (struct CadetPeerPath *path);
130 * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop.
132 * DHT_get sometimes returns bad cached results, for instance, on a locally
133 * cached result where the PUT followed a path that is no longer current.
135 * @param p Path to invalidate.
138 path_invalidate (struct CadetPeerPath *p);
141 * Test if two paths are equivalent (equal or revese of each other).
143 * @param p1 First path
144 * @param p2 Second path
146 * @return GNUNET_YES if both paths are equivalent
147 * GNUNET_NO otherwise
150 path_equivalent (const struct CadetPeerPath *p1,
151 const struct CadetPeerPath *p2);
154 * Test if a path is valid (or at least not known to be invalid).
156 * @param path Path to test.
158 * @return #GNUNET_YES If the path is valid or unknown,
159 * #GNUNET_NO If the path is known to be invalid.
162 path_is_valid (const struct CadetPeerPath *path);
165 * Destroy the path and free any allocated resources linked to it
167 * @param p the path to destroy
169 * @return GNUNET_OK on success
172 path_destroy (struct CadetPeerPath *p);
175 * Builds a path from a PeerIdentity array.
177 * @param peers PeerIdentity array.
178 * @param size Size of the @c peers array.
179 * @param myid ID of local peer, to find @c own_pos.
180 * @param own_pos Output parameter: own position in the path.
182 * @return Fixed and shortened path.
184 struct CadetPeerPath *
185 path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
188 unsigned int *own_pos);
191 * Path -> allocated one line string. Caller must free.
196 path_2s (struct CadetPeerPath *p);
199 * Print info about the path for debug.
201 * @param p Path to debug.
204 path_debug (struct CadetPeerPath *p);
206 #if 0 /* keep Emacsens' auto-indent happy */
214 /* ifndef CADET_PATH_H */