cadet_path.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001 - 2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file cadet/cadet_path.h
  19. * @brief Path handling functions
  20. * @author Bartlomiej Polot
  21. */
  22. #ifndef CADET_PATH_H_
  23. #define CADET_PATH_H_
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #if 0 /* keep Emacsens' auto-indent happy */
  28. }
  29. #endif
  30. #endif
  31. #include "gnunet-service-cadet_connection.h"
  32. /******************************************************************************/
  33. /************************ DATA STRUCTURES ****************************/
  34. /******************************************************************************/
  35. /**
  36. * Information regarding a possible path to reach a single peer
  37. */
  38. struct CadetPeerPath
  39. {
  40. /**
  41. * Linked list
  42. */
  43. struct CadetPeerPath *next;
  44. struct CadetPeerPath *prev;
  45. /**
  46. * List of all the peers that form the path from origin to target.
  47. */
  48. GNUNET_PEER_Id *peers;
  49. /**
  50. * Number of peers (hops) in the path
  51. */
  52. unsigned int length;
  53. /**
  54. * User defined data store.
  55. */
  56. struct CadetConnection *c;
  57. /**
  58. * Path's score, how reliable is the path.
  59. */
  60. // int score;
  61. /**
  62. * Task to delete the path.
  63. * We tried it, it didn't work, don't try again in a while.
  64. */
  65. struct GNUNET_SCHEDULER_Task * path_delete;
  66. };
  67. /******************************************************************************/
  68. /************************* FUNCTIONS *****************************/
  69. /******************************************************************************/
  70. /**
  71. * Create a new path.
  72. *
  73. * @param length How many hops will the path have.
  74. *
  75. * @return A newly allocated path with a peer array of the specified length.
  76. */
  77. struct CadetPeerPath *
  78. path_new (unsigned int length);
  79. /**
  80. * Invert the path.
  81. *
  82. * @param path The path to invert.
  83. */
  84. void
  85. path_invert (struct CadetPeerPath *path);
  86. /**
  87. * Duplicate a path, incrementing short peer's rc.
  88. *
  89. * @param path The path to duplicate.
  90. */
  91. struct CadetPeerPath *
  92. path_duplicate (const struct CadetPeerPath *path);
  93. /**
  94. * Get the length of a path.
  95. *
  96. * @param path The path to measure, with the local peer at any point of it.
  97. *
  98. * @return Number of hops to reach destination.
  99. * UINT_MAX in case the peer is not in the path.
  100. */
  101. unsigned int
  102. path_get_length (struct CadetPeerPath *path);
  103. /**
  104. * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop.
  105. *
  106. * DHT_get sometimes returns bad cached results, for instance, on a locally
  107. * cached result where the PUT followed a path that is no longer current.
  108. *
  109. * @param p Path to invalidate.
  110. */
  111. void
  112. path_invalidate (struct CadetPeerPath *p);
  113. /**
  114. * Test if two paths are equivalent (equal or revese of each other).
  115. *
  116. * @param p1 First path
  117. * @param p2 Second path
  118. *
  119. * @return GNUNET_YES if both paths are equivalent
  120. * GNUNET_NO otherwise
  121. */
  122. int
  123. path_equivalent (const struct CadetPeerPath *p1,
  124. const struct CadetPeerPath *p2);
  125. /**
  126. * Test if a path is valid (or at least not known to be invalid).
  127. *
  128. * @param path Path to test.
  129. *
  130. * @return #GNUNET_YES If the path is valid or unknown,
  131. * #GNUNET_NO If the path is known to be invalid.
  132. */
  133. int
  134. path_is_valid (const struct CadetPeerPath *path);
  135. /**
  136. * Destroy the path and free any allocated resources linked to it
  137. *
  138. * @param p the path to destroy
  139. *
  140. * @return GNUNET_OK on success
  141. */
  142. int
  143. path_destroy (struct CadetPeerPath *p);
  144. /**
  145. * Compare two paths.
  146. *
  147. * @param p1 First path.
  148. * @param p2 Second path.
  149. *
  150. * @return > 0 if p1 is longer, or the first differing PEER_Id is higher on p1.
  151. * < 0 if p2 is longer, or the first differing PEER_Id is higher on p2.
  152. * 0 if they are identical.
  153. */
  154. int
  155. path_cmp (const struct CadetPeerPath *p1, const struct CadetPeerPath *p2);
  156. /**
  157. * Builds a path from a PeerIdentity array.
  158. *
  159. * @param peers PeerIdentity array.
  160. * @param size Size of the @c peers array.
  161. * @param myid ID of local peer, to find @c own_pos.
  162. * @param own_pos Output parameter: own position in the path.
  163. *
  164. * @return Fixed and shortened path.
  165. */
  166. struct CadetPeerPath *
  167. path_build_from_peer_ids (struct GNUNET_PeerIdentity *peers,
  168. unsigned int size,
  169. GNUNET_PEER_Id myid,
  170. unsigned int *own_pos);
  171. /**
  172. * Path -> allocated one line string. Caller must free.
  173. *
  174. * @param p Path.
  175. */
  176. char *
  177. path_2s (struct CadetPeerPath *p);
  178. /**
  179. * Print info about the path for debug.
  180. *
  181. * @param p Path to debug.
  182. */
  183. void
  184. path_debug (struct CadetPeerPath *p);
  185. #if 0 /* keep Emacsens' auto-indent happy */
  186. {
  187. #endif
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. /* ifndef CADET_PATH_H */
  192. #endif