- changes to round system, stats collection
[oweals/gnunet.git] / src / mesh / mesh_path.h
1 /*
2      This file is part of GNUnet.
3      (C) 2001 - 2013 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      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      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file mesh/mesh_path.h
23  * @brief Path handling functions
24  * @author Bartlomiej Polot
25  */
26
27 #ifndef MESH_PATH_H_
28 #define MESH_PATH_H_
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33   #if 0                           /* keep Emacsens' auto-indent happy */
34 }
35 #endif
36 #endif
37
38 /******************************************************************************/
39 /************************      DATA STRUCTURES     ****************************/
40 /******************************************************************************/
41
42 /**
43  * Information regarding a possible path to reach a single peer
44  */
45 struct MeshPeerPath
46 {
47
48     /**
49      * Linked list
50      */
51   struct MeshPeerPath *next;
52   struct MeshPeerPath *prev;
53
54     /**
55      * List of all the peers that form the path from origin to target.
56      */
57   GNUNET_PEER_Id *peers;
58
59     /**
60      * Number of peers (hops) in the path
61      */
62   unsigned int length;
63
64     /**
65      * Path's score, how reliable is the path.
66      */
67 //   int score;
68
69   /**
70    * Task to delete the path.
71    * We tried it, it didn't work, don't try again in a while.
72    */
73   GNUNET_SCHEDULER_TaskIdentifier path_delete;
74
75 };
76
77 /******************************************************************************/
78 /*************************        FUNCTIONS       *****************************/
79 /******************************************************************************/
80
81 /**
82  * Create a new path.
83  *
84  * @param length How many hops will the path have.
85  *
86  * @return A newly allocated path with a peer array of the specified length.
87  */
88 struct MeshPeerPath *
89 path_new (unsigned int length);
90
91
92 /**
93  * Invert the path.
94  *
95  * @param path The path to invert.
96  */
97 void
98 path_invert (struct MeshPeerPath *path);
99
100
101 /**
102  * Duplicate a path, incrementing short peer's rc.
103  *
104  * @param path The path to duplicate.
105  */
106 struct MeshPeerPath *
107 path_duplicate (const struct MeshPeerPath *path);
108
109
110 /**
111  * Get the length of a path.
112  *
113  * @param path The path to measure, with the local peer at any point of it.
114  *
115  * @return Number of hops to reach destination.
116  *         UINT_MAX in case the peer is not in the path.
117  */
118 unsigned int
119 path_get_length (struct MeshPeerPath *path);
120
121 /**
122  * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop.
123  *
124  * DHT_get sometimes returns bad cached results, for instance, on a locally
125  * cached result where the PUT followed a path that is no longer current.
126  *
127  * @param p Path to invalidate.
128  */
129 void
130 path_invalidate (struct MeshPeerPath *p);
131
132 /**
133  * Test if a path is valid (or at least not known to be invalid).
134  *
135  * @param path Path to test.
136  *
137  * @return #GNUNET_YES If the path is valid or unknown,
138  *         #GNUNET_NO If the path is known to be invalid.
139  */
140 int
141 path_is_valid (const struct MeshPeerPath *path);
142
143 /**
144  * Destroy the path and free any allocated resources linked to it
145  *
146  * @param p the path to destroy
147  *
148  * @return GNUNET_OK on success
149  */
150 int
151 path_destroy (struct MeshPeerPath *p);
152
153 /**
154  * Path -> allocated one line string. Caller must free.
155  *
156  * @param p Path.
157  */
158 char *
159 path_2s (struct MeshPeerPath *p);
160
161 /**
162  * Print info about the path for debug.
163  *
164  * @param p Path to debug.
165  */
166 void
167 path_debug (struct MeshPeerPath *p);
168
169 #if 0                           /* keep Emacsens' auto-indent happy */
170 {
171   #endif
172   #ifdef __cplusplus
173 }
174 #endif
175
176
177 /* ifndef MESH_PATH_H */
178 #endif