gnunet_block_plugin.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 2010,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., 51 Franklin Street, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. /**
  18. * @author Christian Grothoff
  19. *
  20. * @file
  21. * API for block plugins.
  22. *
  23. * @defgroup block-plugin Block plugin API
  24. * To be implemented by applications storing data in the DHT.
  25. *
  26. * Each block plugin must conform to the API specified by this header.
  27. *
  28. * @{
  29. */
  30. #ifndef PLUGIN_BLOCK_H
  31. #define PLUGIN_BLOCK_H
  32. #include "gnunet_util_lib.h"
  33. #include "gnunet_block_lib.h"
  34. /**
  35. * Function called to validate a reply or a request. For
  36. * request evaluation, simply pass "NULL" for the @a reply_block.
  37. * Note that it is assumed that the reply has already been
  38. * matched to the key (and signatures checked) as it would
  39. * be done with the "get_key" function.
  40. *
  41. * @param cls closure
  42. * @param type block type
  43. * @param eo evaluation options to control evaluation
  44. * @param query original query (hash)
  45. * @param bf pointer to bloom filter associated with query; possibly updated (!)
  46. * @param bf_mutator mutation value for @a bf
  47. * @param xquery extrended query data (can be NULL, depending on type)
  48. * @param xquery_size number of bytes in @a xquery
  49. * @param reply_block response to validate
  50. * @param reply_block_size number of bytes in @a reply_block
  51. * @return characterization of result
  52. */
  53. typedef enum GNUNET_BLOCK_EvaluationResult
  54. (*GNUNET_BLOCK_EvaluationFunction) (void *cls,
  55. enum GNUNET_BLOCK_Type type,
  56. enum GNUNET_BLOCK_EvaluationOptions eo,
  57. const struct GNUNET_HashCode *query,
  58. struct GNUNET_CONTAINER_BloomFilter **bf,
  59. int32_t bf_mutator,
  60. const void *xquery,
  61. size_t xquery_size,
  62. const void *reply_block,
  63. size_t reply_block_size);
  64. /**
  65. * Function called to obtain the key for a block.
  66. *
  67. * @param cls closure
  68. * @param type block type
  69. * @param block block to get the key for
  70. * @param block_size number of bytes in @a block
  71. * @param key set to the key (query) for the given block
  72. * @return #GNUNET_YES on success,
  73. * #GNUNET_NO if the block is malformed
  74. * #GNUNET_SYSERR if type not supported
  75. * (or if extracting a key from a block of this type does not work)
  76. */
  77. typedef int
  78. (*GNUNET_BLOCK_GetKeyFunction) (void *cls,
  79. enum GNUNET_BLOCK_Type type,
  80. const void *block,
  81. size_t block_size,
  82. struct GNUNET_HashCode *key);
  83. /**
  84. * Each plugin is required to return a pointer to a struct of this
  85. * type as the return value from its entry point.
  86. */
  87. struct GNUNET_BLOCK_PluginFunctions
  88. {
  89. /**
  90. * Closure for all of the callbacks.
  91. */
  92. void *cls;
  93. /**
  94. * 0-terminated array of block types supported by this plugin.
  95. */
  96. const enum GNUNET_BLOCK_Type *types;
  97. /**
  98. * Main function of a block plugin. Allows us to check if a
  99. * block matches a query.
  100. */
  101. GNUNET_BLOCK_EvaluationFunction evaluate;
  102. /**
  103. * Obtain the key for a given block (if possible).
  104. */
  105. GNUNET_BLOCK_GetKeyFunction get_key;
  106. };
  107. #endif
  108. /** @} */ /* end of group */