55e521bbffc6789d38336fd5bed84d4814f83933
[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  *
37  * @param get_path path of the get request
38  * @param get_path_length lenght of @a get_path
39  * @param put_path path of the put request
40  * @param put_path_length length of the @a put_path
41  * @return a path through the network
42  */
43 struct CadetPeerPath *
44 GCPP_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  * Destroy a path, we no longer need it.
52  *
53  * @param p path to destroy.
54  */
55 void
56 GCPP_path_destroy (struct CadetPeerPath *p);
57
58
59 /**
60  * Return the length of the path.  Excludes one end of the
61  * path, so the loopback path has length 0.
62  *
63  * @param path path to return the length for
64  * @return number of peers on the path
65  */
66 unsigned int
67 GCPP_get_length (struct CadetPeerPath *path);
68
69
70 /**
71  * Return how much we like keeping the path.  This is an aggregate
72  * score based on various factors, including the age of the path
73  * (older == better), and the value of this path to all of its ajacent
74  * peers.  For example, long paths that end at a peer that we have no
75  * shorter way to reach are very desirable, while long paths that end
76  * at a peer for which we have a shorter way as well are much less
77  * desirable.  Higher values indicate more valuable paths.  The
78  * returned value should be used to decide which paths to remember.
79  *
80  * @param path path to return the length for
81  * @return desirability of the path, larger is more desirable
82  */
83 GNUNET_CONTAINER_HeapCostType
84 GCPP_get_desirability (struct CadetPeerPath *path);
85
86
87 /**
88  * The given peer @a cp used to own this @a path.  However, it is no
89  * longer interested in maintaining it, so the path should be
90  * discarded or shortened (in case a previous peer on the path finds
91  * the path desirable).
92  *
93  * @param path the path that is being released
94  * @param cp original final destination of @a path
95  * @param node entry in the heap of @a cp where this path is anchored
96  *             should be used for updates to the desirability of this path
97  */
98 void
99 GCPP_acquire (struct CadetPeerPath *path,
100               struct CadetPeer *cp,
101               struct GNUNET_CONTAINER_HeapNode *node);
102
103
104 /**
105  * The given peer @a cp used to own this @a path.  However, it is no
106  * longer interested in maintaining it, so the path should be
107  * discarded or shortened (in case a previous peer on the path finds
108  * the path desirable).
109  *
110  * @param path the path that is being released
111  * @param cp original final destination of @a path
112  */
113 void
114 GCPP_release (struct CadetPeerPath *path,
115               struct CadetPeer *cp);
116
117
118 /**
119  * Obtain the identity of the peer at offset @a off in @a path.
120  *
121  * @param path peer path to inspect
122  * @param off offset to return, must be smaller than path length
123  * @param[out] pid where to write the pid, must not be NULL
124  */
125 void
126 GCPP_get_pid_at_offset (struct CadetPeerPath *path,
127                         unsigned int off,
128                         struct GNUNET_PeerIdentity *pid);
129
130
131 #endif