4b47784a05328002879fb05a4caaca975888596a
[oweals/gnunet.git] / src / cadet / gnunet-service-cadet-new_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
7      it under the terms of the GNU General Public License as published
8      by the Free Software Foundation; either version 3, or (at your
9      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      General Public License for more details.
15
16      You should have received a copy of the GNU General Public License
17      along with GNUnet; see the file COPYING.  If not, write to the
18      Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19      Boston, MA 02110-1301, USA.
20 */
21
22 /**
23  * @file cadet/gnunet-service-cadet-new_paths.h
24  * @brief Information we track per path.
25  * @author Bartlomiej Polot
26  * @author Christian Grothoff
27  */
28 #ifndef GNUNET_SERVICE_CADET_PATHS_H
29 #define GNUNET_SERVICE_CADET_PATHS_H
30
31 #include "gnunet_util_lib.h"
32 #include "gnunet-service-cadet-new.h"
33
34 /**
35  * Create a peer path based on the result of a DHT lookup.
36  * If we already know this path, or one that is longer,
37  * simply return NULL.
38  *
39  * @param get_path path of the get request
40  * @param get_path_length lenght of @a get_path
41  * @param put_path path of the put request
42  * @param put_path_length length of the @a put_path
43  * @return a path through the network
44  */
45 struct CadetPeerPath *
46 GCPP_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
47                     unsigned int get_path_length,
48                     const struct GNUNET_PeerIdentity *put_path,
49                     unsigned int put_path_length);
50
51
52 /**
53  * Destroy a path, we no longer need it.
54  *
55  * @param path path to destroy.
56  */
57 void
58 GCPP_path_destroy (struct CadetPeerPath *path);
59
60
61 /**
62  * Return the length of the path.  Excludes one end of the
63  * path, so the loopback path has length 0.
64  *
65  * @param path path to return the length for
66  * @return number of peers on the path
67  */
68 unsigned int
69 GCPP_get_length (struct CadetPeerPath *path);
70
71
72 /**
73  * Return connection to @a destination using @a path, or return
74  * NULL if no such connection exists.
75  *
76  * @param path path to traverse
77  * @param destination destination node to get to, must be on path
78  * @param off offset of @a destination on @a path
79  * @return NULL if @a create is NO and we have no existing connection
80  *         otherwise connection from us to @a destination via @a path
81  */
82 struct CadetConnection *
83 GCPP_get_connection (struct CadetPeerPath *path,
84                      struct CadetPeer *destination,
85                      unsigned int off);
86
87
88 /**
89  * Notify @a path that it is used for connection @a cc
90  * which ends at the path's offset @a off.
91  *
92  * @param path the path to remember the @a cc
93  * @param off the offset where the @a cc ends
94  * @param cc the connection to remember
95  */
96 void
97 GCPP_add_connection (struct CadetPeerPath *path,
98                      unsigned int off,
99                      struct CadetConnection *cc);
100
101
102 /**
103  * Notify @a path that it is no longer used for connection @a cc which
104  * ended at the path's offset @a off.
105  *
106  * @param path the path to forget the @a cc
107  * @param off the offset where the @a cc ended
108  * @param cc the connection to forget
109  */
110 void
111 GCPP_del_connection (struct CadetPeerPath *path,
112                      unsigned int off,
113                      struct CadetConnection *cc);
114
115
116 /**
117  * Find peer's offset on path.
118  *
119  * @param path path to search
120  * @param cp peer to look for
121  * @return offset of @a cp on @a path, or UINT_MAX if not found
122  */
123 unsigned int
124 GCPP_find_peer (struct CadetPeerPath *path,
125                 struct CadetPeer *cp);
126
127
128 /**
129  * Return how much we like keeping the path.  This is an aggregate
130  * score based on various factors, including the age of the path
131  * (older == better), and the value of this path to all of its ajacent
132  * peers.  For example, long paths that end at a peer that we have no
133  * shorter way to reach are very desirable, while long paths that end
134  * at a peer for which we have a shorter way as well are much less
135  * desirable.  Higher values indicate more valuable paths.  The
136  * returned value should be used to decide which paths to remember.
137  *
138  * @param path path to return the length for
139  * @return desirability of the path, larger is more desirable
140  */
141 GNUNET_CONTAINER_HeapCostType
142 GCPP_get_desirability (const struct CadetPeerPath *path);
143
144
145 /**
146  * The given peer @a cp used to own this @a path.  However, it is no
147  * longer interested in maintaining it, so the path should be
148  * discarded or shortened (in case a previous peer on the path finds
149  * the path desirable).
150  *
151  * @param path the path that is being released
152  * @param node entry in the heap of @a cp where this path is anchored
153  *             should be used for updates to the desirability of this path
154  */
155 void
156 GCPP_acquire (struct CadetPeerPath *path,
157               struct GNUNET_CONTAINER_HeapNode *node);
158
159
160 /**
161  * The given peer @a cp used to own this @a path.  However, it is no
162  * longer interested in maintaining it, so the path should be
163  * discarded or shortened (in case a previous peer on the path finds
164  * the path desirable).
165  *
166  * @param path the path that is being released
167  */
168 void
169 GCPP_release (struct CadetPeerPath *path);
170
171
172 /**
173  * Obtain the peer at offset @a off in @a path.
174  *
175  * @param path peer path to inspect
176  * @param off offset to return, must be smaller than path length
177  * @return peer at offset @a off
178  */
179 struct CadetPeer *
180 GCPP_get_peer_at_offset (struct CadetPeerPath *path,
181                          unsigned int off);
182
183
184 #endif