gnunet-service-cadet_paths.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2001-2017 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your 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. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file cadet/gnunet-service-cadet-new_paths.h
  18. * @brief Information we track per path.
  19. * @author Bartlomiej Polot
  20. * @author Christian Grothoff
  21. */
  22. #ifndef GNUNET_SERVICE_CADET_PATHS_H
  23. #define GNUNET_SERVICE_CADET_PATHS_H
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet-service-cadet.h"
  26. /**
  27. * Create a peer path based on the result of a DHT lookup. If we
  28. * already know this path, or one that is longer, simply return NULL.
  29. * Otherwise, we try to extend an existing path, or create a new one
  30. * if applicable.
  31. *
  32. * @param get_path path of the get request
  33. * @param get_path_length length of @a get_path
  34. * @param put_path path of the put request
  35. * @param put_path_length length of the @a put_path
  36. */
  37. void
  38. GCPP_try_path_from_dht (const struct GNUNET_PeerIdentity *get_path,
  39. unsigned int get_path_length,
  40. const struct GNUNET_PeerIdentity *put_path,
  41. unsigned int put_path_length);
  42. /**
  43. * We got an incoming connection, obtain the corresponding path.
  44. *
  45. * @param path_length number of segments on the @a path
  46. * @param path through the network, in reverse order (we are at the end!)
  47. * @return corresponding path object
  48. */
  49. struct CadetPeerPath *
  50. GCPP_get_path_from_route (unsigned int path_length,
  51. const struct GNUNET_PeerIdentity *pids);
  52. /**
  53. * Return the length of the path. Excludes one end of the
  54. * path, so the loopback path has length 0.
  55. *
  56. * @param path path to return the length for
  57. * @return number of peers on the path
  58. */
  59. unsigned int
  60. GCPP_get_length (struct CadetPeerPath *path);
  61. /**
  62. * Return connection to @a destination using @a path, or return
  63. * NULL if no such connection exists.
  64. *
  65. * @param path path to traverse
  66. * @param destination destination node to get to, must be on path
  67. * @param off offset of @a destination on @a path
  68. * @return NULL if we have no existing connection
  69. * otherwise connection from us to @a destination via @a path
  70. */
  71. struct CadetConnection *
  72. GCPP_get_connection (struct CadetPeerPath *path,
  73. struct CadetPeer *destination,
  74. unsigned int off);
  75. /**
  76. * Notify @a path that it is used for connection @a cc
  77. * which ends at the path's offset @a off.
  78. *
  79. * @param path the path to remember the @a cc
  80. * @param off the offset where the @a cc ends
  81. * @param cc the connection to remember
  82. */
  83. void
  84. GCPP_add_connection (struct CadetPeerPath *path,
  85. unsigned int off,
  86. struct CadetConnection *cc);
  87. /**
  88. * Notify @a path that it is no longer used for connection @a cc which
  89. * ended at the path's offset @a off.
  90. *
  91. * @param path the path to forget the @a cc
  92. * @param off the offset where the @a cc ended
  93. * @param cc the connection to forget
  94. */
  95. void
  96. GCPP_del_connection (struct CadetPeerPath *path,
  97. unsigned int off,
  98. struct CadetConnection *cc);
  99. /**
  100. * Find peer's offset on path.
  101. *
  102. * @param path path to search
  103. * @param cp peer to look for
  104. * @return offset of @a cp on @a path, or UINT_MAX if not found
  105. */
  106. unsigned int
  107. GCPP_find_peer (struct CadetPeerPath *path,
  108. struct CadetPeer *cp);
  109. /**
  110. * Return how much we like keeping the path. This is an aggregate
  111. * score based on various factors, including the age of the path
  112. * (older == better), and the value of this path to all of its adjacent
  113. * peers. For example, long paths that end at a peer that we have no
  114. * shorter way to reach are very desirable, while long paths that end
  115. * at a peer for which we have a shorter way as well are much less
  116. * desirable. Higher values indicate more valuable paths. The
  117. * returned value should be used to decide which paths to remember.
  118. *
  119. * @param path path to return the length for
  120. * @return desirability of the path, larger is more desirable
  121. */
  122. GNUNET_CONTAINER_HeapCostType
  123. GCPP_get_desirability (const struct CadetPeerPath *path);
  124. /**
  125. * The given peer @a cp used to own this @a path. However, it is no
  126. * longer interested in maintaining it, so the path should be
  127. * discarded or shortened (in case a previous peer on the path finds
  128. * the path desirable).
  129. *
  130. * @param path the path that is being released
  131. */
  132. void
  133. GCPP_release (struct CadetPeerPath *path);
  134. /**
  135. * Obtain the peer at offset @a off in @a path.
  136. *
  137. * @param path peer path to inspect
  138. * @param off offset to return, must be smaller than path length
  139. * @return peer at offset @a off
  140. */
  141. struct CadetPeer *
  142. GCPP_get_peer_at_offset (struct CadetPeerPath *path,
  143. unsigned int off);
  144. /**
  145. * Convert a path to a human-readable string.
  146. *
  147. * @param path path to convert
  148. * @return string, statically allocated
  149. */
  150. const char *
  151. GCPP_2s (struct CadetPeerPath *p);
  152. #endif