3 This file is part of GNUnet.
4 Copyright (C) 2001-2017 GNUnet e.V.
6 GNUnet is free software: you can redistribute it and/or modify it
7 under the terms of the GNU Affero General Public License as published
8 by the Free Software Foundation, either version 3 of the License,
9 or (at your option) any later version.
11 GNUnet is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details.
16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 * @file cadet/gnunet-service-cadet-new_paths.h
22 * @brief Information we track per path.
23 * @author Bartlomiej Polot
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_CADET_PATHS_H
27 #define GNUNET_SERVICE_CADET_PATHS_H
29 #include "gnunet_util_lib.h"
30 #include "gnunet-service-cadet.h"
33 * Create a peer path based on the result of a DHT lookup. If we
34 * already know this path, or one that is longer, simply return NULL.
35 * Otherwise, we try to extend an existing path, or create a new one
38 * @param get_path path of the get request
39 * @param get_path_length lenght of @a get_path
40 * @param put_path path of the put request
41 * @param put_path_length length of the @a put_path
44 GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
45 unsigned int get_path_length,
46 const struct GNUNET_PeerIdentity *put_path,
47 unsigned int put_path_length);
51 * We got an incoming connection, obtain the corresponding path.
53 * @param path_length number of segments on the @a path
54 * @param path through the network, in reverse order (we are at the end!)
55 * @return corresponding path object
57 struct CadetPeerPath *
58 GCPP_get_path_from_route (unsigned int path_length,
59 const struct GNUNET_PeerIdentity *pids);
63 * Return the length of the path. Excludes one end of the
64 * path, so the loopback path has length 0.
66 * @param path path to return the length for
67 * @return number of peers on the path
70 GCPP_get_length (struct CadetPeerPath *path);
74 * Return connection to @a destination using @a path, or return
75 * NULL if no such connection exists.
77 * @param path path to traverse
78 * @param destination destination node to get to, must be on path
79 * @param off offset of @a destination on @a path
80 * @return NULL if we have no existing connection
81 * otherwise connection from us to @a destination via @a path
83 struct CadetConnection *
84 GCPP_get_connection (struct CadetPeerPath *path,
85 struct CadetPeer *destination,
90 * Notify @a path that it is used for connection @a cc
91 * which ends at the path's offset @a off.
93 * @param path the path to remember the @a cc
94 * @param off the offset where the @a cc ends
95 * @param cc the connection to remember
98 GCPP_add_connection (struct CadetPeerPath *path,
100 struct CadetConnection *cc);
104 * Notify @a path that it is no longer used for connection @a cc which
105 * ended at the path's offset @a off.
107 * @param path the path to forget the @a cc
108 * @param off the offset where the @a cc ended
109 * @param cc the connection to forget
112 GCPP_del_connection (struct CadetPeerPath *path,
114 struct CadetConnection *cc);
118 * Find peer's offset on path.
120 * @param path path to search
121 * @param cp peer to look for
122 * @return offset of @a cp on @a path, or UINT_MAX if not found
125 GCPP_find_peer (struct CadetPeerPath *path,
126 struct CadetPeer *cp);
130 * Return how much we like keeping the path. This is an aggregate
131 * score based on various factors, including the age of the path
132 * (older == better), and the value of this path to all of its ajacent
133 * peers. For example, long paths that end at a peer that we have no
134 * shorter way to reach are very desirable, while long paths that end
135 * at a peer for which we have a shorter way as well are much less
136 * desirable. Higher values indicate more valuable paths. The
137 * returned value should be used to decide which paths to remember.
139 * @param path path to return the length for
140 * @return desirability of the path, larger is more desirable
142 GNUNET_CONTAINER_HeapCostType
143 GCPP_get_desirability (const struct CadetPeerPath *path);
147 * The given peer @a cp used to own this @a path. However, it is no
148 * longer interested in maintaining it, so the path should be
149 * discarded or shortened (in case a previous peer on the path finds
150 * the path desirable).
152 * @param path the path that is being released
155 GCPP_release (struct CadetPeerPath *path);
159 * Obtain the peer at offset @a off in @a path.
161 * @param path peer path to inspect
162 * @param off offset to return, must be smaller than path length
163 * @return peer at offset @a off
166 GCPP_get_peer_at_offset (struct CadetPeerPath *path,
171 * Convert a path to a human-readable string.
173 * @param path path to convert
174 * @return string, statically allocated
177 GCPP_2s (struct CadetPeerPath *p);