create matching connection objects for inbound connections
[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.  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 lenght 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  */
45 void
46 GCPP_try_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  * We got an incoming connection, obtain the corresponding path.
54  *
55  * @param path_length number of segments on the @a path
56  * @param path through the network, in reverse order (we are at the end!)
57  * @return corresponding path object
58  */
59 struct CadetPeerPath *
60 GCPP_get_path_from_route (unsigned int path_length,
61                           const struct GNUNET_PeerIdentity *pids);
62
63
64 /**
65  * Return the length of the path.  Excludes one end of the
66  * path, so the loopback path has length 0.
67  *
68  * @param path path to return the length for
69  * @return number of peers on the path
70  */
71 unsigned int
72 GCPP_get_length (struct CadetPeerPath *path);
73
74
75 /**
76  * Return connection to @a destination using @a path, or return
77  * NULL if no such connection exists.
78  *
79  * @param path path to traverse
80  * @param destination destination node to get to, must be on path
81  * @param off offset of @a destination on @a path
82  * @return NULL if we have no existing connection
83  *         otherwise connection from us to @a destination via @a path
84  */
85 struct CadetConnection *
86 GCPP_get_connection (struct CadetPeerPath *path,
87                      struct CadetPeer *destination,
88                      unsigned int off);
89
90
91 /**
92  * Notify @a path that it is used for connection @a cc
93  * which ends at the path's offset @a off.
94  *
95  * @param path the path to remember the @a cc
96  * @param off the offset where the @a cc ends
97  * @param cc the connection to remember
98  */
99 void
100 GCPP_add_connection (struct CadetPeerPath *path,
101                      unsigned int off,
102                      struct CadetConnection *cc);
103
104
105 /**
106  * Notify @a path that it is no longer used for connection @a cc which
107  * ended at the path's offset @a off.
108  *
109  * @param path the path to forget the @a cc
110  * @param off the offset where the @a cc ended
111  * @param cc the connection to forget
112  */
113 void
114 GCPP_del_connection (struct CadetPeerPath *path,
115                      unsigned int off,
116                      struct CadetConnection *cc);
117
118
119 /**
120  * Find peer's offset on path.
121  *
122  * @param path path to search
123  * @param cp peer to look for
124  * @return offset of @a cp on @a path, or UINT_MAX if not found
125  */
126 unsigned int
127 GCPP_find_peer (struct CadetPeerPath *path,
128                 struct CadetPeer *cp);
129
130
131 /**
132  * Return how much we like keeping the path.  This is an aggregate
133  * score based on various factors, including the age of the path
134  * (older == better), and the value of this path to all of its ajacent
135  * peers.  For example, long paths that end at a peer that we have no
136  * shorter way to reach are very desirable, while long paths that end
137  * at a peer for which we have a shorter way as well are much less
138  * desirable.  Higher values indicate more valuable paths.  The
139  * returned value should be used to decide which paths to remember.
140  *
141  * @param path path to return the length for
142  * @return desirability of the path, larger is more desirable
143  */
144 GNUNET_CONTAINER_HeapCostType
145 GCPP_get_desirability (const struct CadetPeerPath *path);
146
147
148 /**
149  * The given peer @a cp used to own this @a path.  However, it is no
150  * longer interested in maintaining it, so the path should be
151  * discarded or shortened (in case a previous peer on the path finds
152  * the path desirable).
153  *
154  * @param path the path that is being released
155  */
156 void
157 GCPP_release (struct CadetPeerPath *path);
158
159
160 /**
161  * Obtain the peer at offset @a off in @a path.
162  *
163  * @param path peer path to inspect
164  * @param off offset to return, must be smaller than path length
165  * @return peer at offset @a off
166  */
167 struct CadetPeer *
168 GCPP_get_peer_at_offset (struct CadetPeerPath *path,
169                          unsigned int off);
170
171
172 #endif