Merge branch 'master' of gnunet.org:gnunet
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet_paths.h
1
2 /*
3      This file is part of GNUnet.
4      Copyright (C) 2001-2017 GNUnet e.V.
5
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.
10
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.
15     
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/>.
18 */
19
20 /**
21  * @file cadet/gnunet-service-cadet-new_paths.h
22  * @brief Information we track per path.
23  * @author Bartlomiej Polot
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_CADET_PATHS_H
27 #define GNUNET_SERVICE_CADET_PATHS_H
28
29 #include "gnunet_util_lib.h"
30 #include "gnunet-service-cadet.h"
31
32 /**
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
36  * if applicable.
37  *
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
42  */
43 void
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);
48
49
50 /**
51  * We got an incoming connection, obtain the corresponding path.
52  *
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
56  */
57 struct CadetPeerPath *
58 GCPP_get_path_from_route (unsigned int path_length,
59                           const struct GNUNET_PeerIdentity *pids);
60
61
62 /**
63  * Return the length of the path.  Excludes one end of the
64  * path, so the loopback path has length 0.
65  *
66  * @param path path to return the length for
67  * @return number of peers on the path
68  */
69 unsigned int
70 GCPP_get_length (struct CadetPeerPath *path);
71
72
73 /**
74  * Return connection to @a destination using @a path, or return
75  * NULL if no such connection exists.
76  *
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
82  */
83 struct CadetConnection *
84 GCPP_get_connection (struct CadetPeerPath *path,
85                      struct CadetPeer *destination,
86                      unsigned int off);
87
88
89 /**
90  * Notify @a path that it is used for connection @a cc
91  * which ends at the path's offset @a off.
92  *
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
96  */
97 void
98 GCPP_add_connection (struct CadetPeerPath *path,
99                      unsigned int off,
100                      struct CadetConnection *cc);
101
102
103 /**
104  * Notify @a path that it is no longer used for connection @a cc which
105  * ended at the path's offset @a off.
106  *
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
110  */
111 void
112 GCPP_del_connection (struct CadetPeerPath *path,
113                      unsigned int off,
114                      struct CadetConnection *cc);
115
116
117 /**
118  * Find peer's offset on path.
119  *
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
123  */
124 unsigned int
125 GCPP_find_peer (struct CadetPeerPath *path,
126                 struct CadetPeer *cp);
127
128
129 /**
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.
138  *
139  * @param path path to return the length for
140  * @return desirability of the path, larger is more desirable
141  */
142 GNUNET_CONTAINER_HeapCostType
143 GCPP_get_desirability (const struct CadetPeerPath *path);
144
145
146 /**
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).
151  *
152  * @param path the path that is being released
153  */
154 void
155 GCPP_release (struct CadetPeerPath *path);
156
157
158 /**
159  * Obtain the peer at offset @a off in @a path.
160  *
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
164  */
165 struct CadetPeer *
166 GCPP_get_peer_at_offset (struct CadetPeerPath *path,
167                          unsigned int off);
168
169
170 /**
171  * Convert a path to a human-readable string.
172  *
173  * @param path path to convert
174  * @return string, statically allocated
175  */
176 const char *
177 GCPP_2s (struct CadetPeerPath *p);
178
179
180 #endif