aboutsummaryrefslogtreecommitdiff
path: root/src/service/cadet/gnunet-service-cadet_paths.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/cadet/gnunet-service-cadet_paths.h')
-rw-r--r--src/service/cadet/gnunet-service-cadet_paths.h183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/service/cadet/gnunet-service-cadet_paths.h b/src/service/cadet/gnunet-service-cadet_paths.h
new file mode 100644
index 000000000..0f3b4dd1a
--- /dev/null
+++ b/src/service/cadet/gnunet-service-cadet_paths.h
@@ -0,0 +1,183 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2001-2017 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file cadet/gnunet-service-cadet-new_paths.h
23 * @brief Information we track per path.
24 * @author Bartlomiej Polot
25 * @author Christian Grothoff
26 */
27#ifndef GNUNET_SERVICE_CADET_PATHS_H
28#define GNUNET_SERVICE_CADET_PATHS_H
29
30#include "gnunet_util_lib.h"
31#include "gnunet_dht_service.h"
32#include "gnunet-service-cadet.h"
33
34/**
35 * Create a peer path based on the result of a DHT lookup. If we
36 * already know this path, or one that is longer, simply return NULL.
37 * Otherwise, we try to extend an existing path, or create a new one
38 * if applicable.
39 *
40 * @param get_path path of the get request
41 * @param get_path_length length of @a get_path
42 * @param put_path path of the put request
43 * @param put_path_length length of the @a put_path
44 */
45void
46GCPP_try_path_from_dht (const struct GNUNET_DHT_PathElement *get_path,
47 unsigned int get_path_length,
48 const struct GNUNET_DHT_PathElement *put_path,
49 unsigned int put_path_length);
50
51
52/**
53 * We got an incoming connection, obtain the corresponding path.
54 *
55 * @param path_length number of segments on the @a path
56 * @param pids path through the network, in reverse order
57 * (we are at the end, at index @a path_length)
58 * @return corresponding path object
59 */
60struct CadetPeerPath *
61GCPP_get_path_from_route (unsigned int path_length,
62 const struct GNUNET_PeerIdentity *pids);
63
64
65/**
66 * Return the length of the path. Excludes one end of the
67 * path, so the loopback path has length 0.
68 *
69 * @param path path to return the length for
70 * @return number of peers on the path
71 */
72unsigned int
73GCPP_get_length (struct CadetPeerPath *path);
74
75
76/**
77 * Return connection to @a destination using @a path, or return
78 * NULL if no such connection exists.
79 *
80 * @param path path to traverse
81 * @param destination destination node to get to, must be on path
82 * @param off offset of @a destination on @a path
83 * @return NULL if we have no existing connection
84 * otherwise connection from us to @a destination via @a path
85 */
86struct CadetConnection *
87GCPP_get_connection (struct CadetPeerPath *path,
88 struct CadetPeer *destination,
89 unsigned int off);
90
91
92/**
93 * Notify @a path that it is used for connection @a cc
94 * which ends at the path's offset @a off.
95 *
96 * @param path the path to remember the @a cc
97 * @param off the offset where the @a cc ends
98 * @param cc the connection to remember
99 */
100void
101GCPP_add_connection (struct CadetPeerPath *path,
102 unsigned int off,
103 struct CadetConnection *cc);
104
105
106/**
107 * Notify @a path that it is no longer used for connection @a cc which
108 * ended at the path's offset @a off.
109 *
110 * @param path the path to forget the @a cc
111 * @param off the offset where the @a cc ended
112 * @param cc the connection to forget
113 */
114void
115GCPP_del_connection (struct CadetPeerPath *path,
116 unsigned int off,
117 struct CadetConnection *cc);
118
119
120/**
121 * Find peer's offset on path.
122 *
123 * @param path path to search
124 * @param cp peer to look for
125 * @return offset of @a cp on @a path, or UINT_MAX if not found
126 */
127unsigned int
128GCPP_find_peer (struct CadetPeerPath *path,
129 struct CadetPeer *cp);
130
131
132/**
133 * Return how much we like keeping the path. This is an aggregate
134 * score based on various factors, including the age of the path
135 * (older == better), and the value of this path to all of its adjacent
136 * peers. For example, long paths that end at a peer that we have no
137 * shorter way to reach are very desirable, while long paths that end
138 * at a peer for which we have a shorter way as well are much less
139 * desirable. Higher values indicate more valuable paths. The
140 * returned value should be used to decide which paths to remember.
141 *
142 * @param path path to return the length for
143 * @return desirability of the path, larger is more desirable
144 */
145GNUNET_CONTAINER_HeapCostType
146GCPP_get_desirability (const struct CadetPeerPath *path);
147
148
149/**
150 * The given peer @a cp used to own this @a path. However, it is no
151 * longer interested in maintaining it, so the path should be
152 * discarded or shortened (in case a previous peer on the path finds
153 * the path desirable).
154 *
155 * @param path the path that is being released
156 */
157void
158GCPP_release (struct CadetPeerPath *path);
159
160
161/**
162 * Obtain the peer at offset @a off in @a path.
163 *
164 * @param path peer path to inspect
165 * @param off offset to return, must be smaller than path length
166 * @return peer at offset @a off
167 */
168struct CadetPeer *
169GCPP_get_peer_at_offset (struct CadetPeerPath *path,
170 unsigned int off);
171
172
173/**
174 * Convert a path to a human-readable string.
175 *
176 * @param path path to convert
177 * @return string, statically allocated
178 */
179const char *
180GCPP_2s (struct CadetPeerPath *p);
181
182
183#endif