gnunet_block_lib.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2010 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 include/gnunet_block_lib.h
  19. * @brief library for data block manipulation
  20. * @author Christian Grothoff
  21. */
  22. #ifndef GNUNET_BLOCK_LIB_H
  23. #define GNUNET_BLOCK_LIB_H
  24. #include "gnunet_util_lib.h"
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #if 0 /* keep Emacsens' auto-indent happy */
  29. }
  30. #endif
  31. #endif
  32. /**
  33. * Blocks in the datastore and the datacache must have a unique type.
  34. */
  35. enum GNUNET_BLOCK_Type
  36. {
  37. /**
  38. * Any type of block, used as a wildcard when searching. Should
  39. * never be attached to a specific block.
  40. */
  41. GNUNET_BLOCK_TYPE_ANY = 0,
  42. /**
  43. * Data block (leaf) in the CHK tree.
  44. */
  45. GNUNET_BLOCK_TYPE_FS_DBLOCK = 1,
  46. /**
  47. * Inner block in the CHK tree.
  48. */
  49. GNUNET_BLOCK_TYPE_FS_IBLOCK = 2,
  50. /**
  51. * Type of a block representing a keyword search result. Note that
  52. * the values for KBLOCK, SBLOCK and NBLOCK must be consecutive.
  53. */
  54. GNUNET_BLOCK_TYPE_FS_KBLOCK = 3,
  55. /**
  56. * Type of a block that is used to advertise content in a namespace.
  57. */
  58. GNUNET_BLOCK_TYPE_FS_SBLOCK = 4,
  59. /**
  60. * Type of a block that is used to advertise a namespace.
  61. */
  62. GNUNET_BLOCK_TYPE_FS_NBLOCK = 5,
  63. /**
  64. * Type of a block representing a block to be encoded on demand from disk.
  65. * Should never appear on the network directly.
  66. */
  67. GNUNET_BLOCK_TYPE_FS_ONDEMAND = 6,
  68. /**
  69. * Type of a block that contains a HELLO for a peer (for
  70. * DHT find-peer operations).
  71. */
  72. GNUNET_BLOCK_TYPE_DHT_HELLO = 7,
  73. /**
  74. * Block for testing.
  75. */
  76. GNUNET_BLOCK_TYPE_TEST = 8,
  77. #if HAVE_MALICIOUS
  78. /**
  79. * Block for simulating malicious peers.
  80. */
  81. GNUNET_BLOCK_DHT_MALICIOUS_MESSAGE_TYPE = 9,
  82. #endif
  83. /**
  84. * Block for storing .gnunet-domains
  85. */
  86. GNUNET_BLOCK_TYPE_DNS = 10
  87. };
  88. /**
  89. * Possible ways for how a block may relate to a query.
  90. */
  91. enum GNUNET_BLOCK_EvaluationResult
  92. {
  93. /**
  94. * Valid result, and there may be more.
  95. */
  96. GNUNET_BLOCK_EVALUATION_OK_MORE = 0,
  97. /**
  98. * Last possible valid result.
  99. */
  100. GNUNET_BLOCK_EVALUATION_OK_LAST = 1,
  101. /**
  102. * Valid result, but suppressed because it is a duplicate.
  103. */
  104. GNUNET_BLOCK_EVALUATION_OK_DUPLICATE = 2,
  105. /**
  106. * Block does not match query (invalid result)
  107. */
  108. GNUNET_BLOCK_EVALUATION_RESULT_INVALID = 3,
  109. /**
  110. * Query is valid, no reply given.
  111. */
  112. GNUNET_BLOCK_EVALUATION_REQUEST_VALID = 4,
  113. /**
  114. * Query format does not match block type (invalid query). For
  115. * example, xquery not given or xquery_size not appropriate for
  116. * type.
  117. */
  118. GNUNET_BLOCK_EVALUATION_REQUEST_INVALID = 5,
  119. /**
  120. * Specified block type not supported by this plugin.
  121. */
  122. GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED = 6
  123. };
  124. /**
  125. * Handle to an initialized block library.
  126. */
  127. struct GNUNET_BLOCK_Context;
  128. /**
  129. * Mingle hash with the mingle_number to produce different bits.
  130. *
  131. * @param in original hash code
  132. * @param mingle_number number for hash permutation
  133. * @param hc where to store the result.
  134. */
  135. void
  136. GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, uint32_t mingle_number,
  137. GNUNET_HashCode * hc);
  138. /**
  139. * Create a block context. Loads the block plugins.
  140. *
  141. * @param cfg configuration to use
  142. * @return NULL on error
  143. */
  144. struct GNUNET_BLOCK_Context *
  145. GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg);
  146. /**
  147. * Destroy the block context.
  148. *
  149. * @param ctx context to destroy
  150. */
  151. void
  152. GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx);
  153. /**
  154. * Function called to validate a reply or a request. For
  155. * request evaluation, simply pass "NULL" for the reply_block.
  156. * Note that it is assumed that the reply has already been
  157. * matched to the key (and signatures checked) as it would
  158. * be done with the "get_key" function.
  159. *
  160. * @param ctx block contxt
  161. * @param type block type
  162. * @param query original query (hash)
  163. * @param bf pointer to bloom filter associated with query; possibly updated (!)
  164. * @param bf_mutator mutation value for bf
  165. * @param xquery extrended query data (can be NULL, depending on type)
  166. * @param xquery_size number of bytes in xquery
  167. * @param reply_block response to validate
  168. * @param reply_block_size number of bytes in reply block
  169. * @return characterization of result
  170. */
  171. enum GNUNET_BLOCK_EvaluationResult
  172. GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
  173. enum GNUNET_BLOCK_Type type,
  174. const GNUNET_HashCode * query,
  175. struct GNUNET_CONTAINER_BloomFilter **bf,
  176. int32_t bf_mutator, const void *xquery,
  177. size_t xquery_size, const void *reply_block,
  178. size_t reply_block_size);
  179. /**
  180. * Function called to obtain the key for a block.
  181. *
  182. * @param ctx block context
  183. * @param type block type
  184. * @param block block to get the key for
  185. * @param block_size number of bytes in block
  186. * @param key set to the key (query) for the given block
  187. * @return GNUNET_YES on success,
  188. * GNUNET_NO if the block is malformed
  189. * GNUNET_SYSERR if type not supported
  190. * (or if extracting a key from a block of this type does not work)
  191. */
  192. int
  193. GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
  194. enum GNUNET_BLOCK_Type type, const void *block,
  195. size_t block_size, GNUNET_HashCode * key);
  196. #if 0 /* keep Emacsens' auto-indent happy */
  197. {
  198. #endif
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. /* ifndef GNUNET_BLOCK_LIB_H */
  203. #endif
  204. /* end of gnunet_block_lib.h */