gnunet-service-dht_datacache.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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_datacache.h
  18. * @brief GNUnet DHT service's datacache integration
  19. * @author Christian Grothoff
  20. * @author Nathan Evans
  21. */
  22. #ifndef GNUNET_SERVICE_DHT_DATACACHE_H
  23. #define GNUNET_SERVICE_DHT_DATACACHE_H
  24. #include "gnunet_util_lib.h"
  25. #include "gnunet_block_lib.h"
  26. #include "gnunet_dht_service.h"
  27. /**
  28. * Handle a datum we've received from another peer. Cache if
  29. * possible.
  30. *
  31. * @param expiration when will the reply expire
  32. * @param key the query this reply is for
  33. * @param put_path_length number of peers in 'put_path'
  34. * @param put_path path the reply took on put
  35. * @param type type of the reply
  36. * @param data_size number of bytes in 'data'
  37. * @param data application payload data
  38. */
  39. void
  40. GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
  41. const struct GNUNET_HashCode *key,
  42. unsigned int put_path_length,
  43. const struct GNUNET_PeerIdentity *put_path,
  44. enum GNUNET_BLOCK_Type type,
  45. size_t data_size,
  46. const void *data);
  47. /**
  48. * Handle a result for a GET operation.
  49. *
  50. * @param cls closure
  51. * @param type type of the block
  52. * @param expiration_time when does the content expire
  53. * @param key key for the content
  54. * @param put_path_length number of entries in @a put_path
  55. * @param put_path peers the original PUT traversed (if tracked)
  56. * @param get_path_length number of entries in @a get_path
  57. * @param get_path peers this reply has traversed so far (if tracked)
  58. * @param data payload of the reply
  59. * @param data_size number of bytes in @a data
  60. */
  61. typedef void
  62. (*GDS_DATACACHE_GetCallback)(void *cls,
  63. enum GNUNET_BLOCK_Type type,
  64. struct GNUNET_TIME_Absolute expiration_time,
  65. const struct GNUNET_HashCode *key,
  66. unsigned int put_path_length,
  67. const struct GNUNET_PeerIdentity *put_path,
  68. unsigned int get_path_length,
  69. const struct GNUNET_PeerIdentity *get_path,
  70. const void *data,
  71. size_t data_size);
  72. /**
  73. * Handle a GET request we've received from another peer.
  74. *
  75. * @param key the query
  76. * @param type requested data type
  77. * @param xquery extended query
  78. * @param xquery_size number of bytes in xquery
  79. * @param bg block group to use for evaluation of replies
  80. * @param gc function to call on the results
  81. * @param gc_cls closure for @a gc
  82. * @return evaluation result for the local replies
  83. */
  84. enum GNUNET_BLOCK_EvaluationResult
  85. GDS_DATACACHE_handle_get (const struct GNUNET_HashCode *key,
  86. enum GNUNET_BLOCK_Type type,
  87. const void *xquery,
  88. size_t xquery_size,
  89. struct GNUNET_BLOCK_Group *bg,
  90. GDS_DATACACHE_GetCallback gc,
  91. void *gc_cls);
  92. /**
  93. * Obtain a random key from the datacache.
  94. * Used by Whanau for load-balancing.
  95. *
  96. * @param[out] key where to store the key of a random element,
  97. * randomized by PRNG if datacache is empty
  98. * @return #GNUNET_OK on success, #GNUNET_SYSERR if the datacache is empty
  99. */
  100. int
  101. GDS_DATACACHE_get_random_key (struct GNUNET_HashCode *key);
  102. /**
  103. * Send the get result to requesting client.
  104. *
  105. * @param cls closure
  106. * @param options routing options (from GET request)
  107. * @param key key of the requested data.
  108. * @param type block type
  109. * @param put_path_length number of peers in @a put_path
  110. * @param put_path path taken to put the data at its stored location.
  111. * @param expiration when will this result expire?
  112. * @param data payload to store
  113. * @param data_size size of the @a data
  114. */
  115. typedef void
  116. (*GDS_DATACACHE_SuccessorCallback)(void *cls,
  117. enum GNUNET_DHT_RouteOption options,
  118. const struct GNUNET_HashCode *key,
  119. enum GNUNET_BLOCK_Type type,
  120. unsigned int put_path_length,
  121. const struct GNUNET_PeerIdentity *put_path,
  122. struct GNUNET_TIME_Absolute expiration,
  123. const void *data,
  124. size_t data_size);
  125. /**
  126. * Handle a request for data close to a key that we have received from
  127. * another peer.
  128. *
  129. * @param key the location at which the peer is looking for data that is close
  130. * @param cb function to call with the result
  131. * @param cb_cls closure for @a cb
  132. */
  133. void
  134. GDS_DATACACHE_get_successors (const struct GNUNET_HashCode *key,
  135. GDS_DATACACHE_SuccessorCallback cb,
  136. void *cb_cls);
  137. /**
  138. * Initialize datacache subsystem.
  139. */
  140. void
  141. GDS_DATACACHE_init (void);
  142. /**
  143. * Shutdown datacache subsystem.
  144. */
  145. void
  146. GDS_DATACACHE_done (void);
  147. #endif