gnunet-service-dht_neighbours.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2009, 2010, 2011 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 dht/gnunet-service-dht_neighbours.h
  18. * @brief GNUnet DHT routing code
  19. * @author Christian Grothoff
  20. * @author Nathan Evans
  21. */
  22. #ifndef GNUNET_SERVICE_DHT_NEIGHBOURS_H
  23. #define GNUNET_SERVICE_DHT_NEIGHBOURS_H
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet_block_lib.h"
  26. #include "gnunet_dht_service.h"
  27. /**
  28. * Hash of the identity of this peer.
  29. */
  30. extern struct GNUNET_HashCode my_identity_hash;
  31. /**
  32. * Perform a PUT operation. Forwards the given request to other
  33. * peers. Does not store the data locally. Does not give the
  34. * data to local clients. May do nothing if this is the only
  35. * peer in the network (or if we are the closest peer in the
  36. * network).
  37. *
  38. * @param type type of the block
  39. * @param options routing options
  40. * @param desired_replication_level desired replication level
  41. * @param expiration_time when does the content expire
  42. * @param hop_count how many hops has this message traversed so far
  43. * @param bf Bloom filter of peers this PUT has already traversed
  44. * @param key key for the content
  45. * @param put_path_length number of entries in put_path
  46. * @param put_path peers this request has traversed so far (if tracked)
  47. * @param data payload to store
  48. * @param data_size number of bytes in data
  49. * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
  50. */
  51. int
  52. GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
  53. enum GNUNET_DHT_RouteOption options,
  54. uint32_t desired_replication_level,
  55. struct GNUNET_TIME_Absolute expiration_time,
  56. uint32_t hop_count,
  57. struct GNUNET_CONTAINER_BloomFilter *bf,
  58. const struct GNUNET_HashCode *key,
  59. unsigned int put_path_length,
  60. struct GNUNET_PeerIdentity *put_path,
  61. const void *data, size_t data_size);
  62. /**
  63. * Perform a GET operation. Forwards the given request to other
  64. * peers. Does not lookup the key locally. May do nothing if this is
  65. * the only peer in the network (or if we are the closest peer in the
  66. * network).
  67. *
  68. * @param type type of the block
  69. * @param options routing options
  70. * @param desired_replication_level desired replication count
  71. * @param hop_count how many hops did this request traverse so far?
  72. * @param key key for the content
  73. * @param xquery extended query
  74. * @param xquery_size number of bytes in @a xquery
  75. * @param bg block group to filter replies
  76. * @param peer_bf filter for peers not to select (again, updated)
  77. * @return #GNUNET_OK if the request was forwarded, #GNUNET_NO if not
  78. */
  79. int
  80. GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
  81. enum GNUNET_DHT_RouteOption options,
  82. uint32_t desired_replication_level,
  83. uint32_t hop_count,
  84. const struct GNUNET_HashCode *key,
  85. const void *xquery,
  86. size_t xquery_size,
  87. struct GNUNET_BLOCK_Group *bg,
  88. struct GNUNET_CONTAINER_BloomFilter *peer_bf);
  89. /**
  90. * Handle a reply (route to origin). Only forwards the reply back to
  91. * other peers waiting for it. Does not do local caching or
  92. * forwarding to local clients.
  93. *
  94. * @param target neighbour that should receive the block (if still connected)
  95. * @param type type of the block
  96. * @param expiration_time when does the content expire
  97. * @param key key for the content
  98. * @param put_path_length number of entries in put_path
  99. * @param put_path peers the original PUT traversed (if tracked)
  100. * @param get_path_length number of entries in put_path
  101. * @param get_path peers this reply has traversed so far (if tracked)
  102. * @param data payload of the reply
  103. * @param data_size number of bytes in data
  104. */
  105. void
  106. GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
  107. enum GNUNET_BLOCK_Type type,
  108. struct GNUNET_TIME_Absolute expiration_time,
  109. const struct GNUNET_HashCode *key,
  110. unsigned int put_path_length,
  111. const struct GNUNET_PeerIdentity *put_path,
  112. unsigned int get_path_length,
  113. const struct GNUNET_PeerIdentity *get_path,
  114. const void *data,
  115. size_t data_size);
  116. /**
  117. * Check whether my identity is closer than any known peers. If a
  118. * non-null bloomfilter is given, check if this is the closest peer
  119. * that hasn't already been routed to.
  120. *
  121. * @param key hash code to check closeness to
  122. * @param bloom bloomfilter, exclude these entries from the decision
  123. * @return #GNUNET_YES if node location is closest,
  124. * #GNUNET_NO otherwise.
  125. */
  126. int
  127. GDS_am_closest_peer (const struct GNUNET_HashCode *key,
  128. const struct GNUNET_CONTAINER_BloomFilter *bloom);
  129. /**
  130. * Initialize neighbours subsystem.
  131. *
  132. * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
  133. */
  134. int
  135. GDS_NEIGHBOURS_init (void);
  136. /**
  137. * Shutdown neighbours subsystem.
  138. */
  139. void
  140. GDS_NEIGHBOURS_done (void);
  141. /**
  142. * Get the ID of the local node.
  143. *
  144. * @return identity of the local node
  145. */
  146. struct GNUNET_PeerIdentity *
  147. GDS_NEIGHBOURS_get_id (void);
  148. #endif