- wip
[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 #include "mesh.h"
39
40 /******************************************************************************/
41 /************************      DATA STRUCTURES     ****************************/
42 /******************************************************************************/
43
44 /**
45  * Information regarding a possible path to reach a single peer
46  */
47 struct MeshPeerPath
48 {
49
50     /**
51      * Linked list
52      */
53   struct MeshPeerPath *next;
54   struct MeshPeerPath *prev;
55
56     /**
57      * List of all the peers that form the path from origin to target.
58      */
59   GNUNET_PEER_Id *peers;
60
61     /**
62      * Number of peers (hops) in the path
63      */
64   unsigned int length;
65
66     /**
67      * Path's score, how reliable is the path.
68      */
69   int score;
70
71 };
72
73 /******************************************************************************/
74 /*************************        FUNCTIONS       *****************************/
75 /******************************************************************************/
76
77 /**
78  * Create a new path.
79  *
80  * @param length How many hops will the path have.
81  *
82  * @return A newly allocated path with a peer array of the specified length.
83  */
84 struct MeshPeerPath *
85 path_new (unsigned int length);
86
87
88 /**
89  * Invert the path.
90  *
91  * @param path The path to invert.
92  */
93 void
94 path_invert (struct MeshPeerPath *path);
95
96
97 /**
98  * Duplicate a path, incrementing short peer's rc.
99  *
100  * @param path The path to duplicate.
101  */
102 struct MeshPeerPath *
103 path_duplicate (struct MeshPeerPath *path);
104
105
106 /**
107  * Get the length of a path.
108  *
109  * @param path The path to measure, with the local peer at any point of it.
110  *
111  * @return Number of hops to reach destination.
112  *         UINT_MAX in case the peer is not in the path.
113  */
114 unsigned int
115 path_get_length (struct MeshPeerPath *path);
116
117
118 /**
119  * Destroy the path and free any allocated resources linked to it
120  *
121  * @param p the path to destroy
122  *
123  * @return GNUNET_OK on success
124  */
125 int
126 path_destroy (struct MeshPeerPath *p);
127
128
129 #if 0                           /* keep Emacsens' auto-indent happy */
130 {
131   #endif
132   #ifdef __cplusplus
133 }
134 #endif
135
136
137 /* ifndef MESH_PATH_H */
138 #endif