plugin_block_setu_test.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. This file is part of GNUnet
  3. Copyright (C) 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 setu/plugin_block_setu_test.c
  18. * @brief set test block, recognizes elements with non-zero first byte as invalid
  19. * @author Christian Grothoff
  20. */
  21. #include "platform.h"
  22. #include "gnunet_block_plugin.h"
  23. #include "gnunet_block_group_lib.h"
  24. /**
  25. * Function called to validate a reply or a request. For
  26. * request evaluation, simply pass "NULL" for the reply_block.
  27. *
  28. * @param cls closure
  29. * @param ctx block context
  30. * @param type block type
  31. * @param group block group to use
  32. * @param eo control flags
  33. * @param query original query (hash)
  34. * @param xquery extrended query data (can be NULL, depending on type)
  35. * @param xquery_size number of bytes in xquery
  36. * @param reply_block response to validate
  37. * @param reply_block_size number of bytes in reply block
  38. * @return characterization of result
  39. */
  40. static enum GNUNET_BLOCK_EvaluationResult
  41. block_plugin_setu_test_evaluate (void *cls,
  42. struct GNUNET_BLOCK_Context *ctx,
  43. enum GNUNET_BLOCK_Type type,
  44. struct GNUNET_BLOCK_Group *group,
  45. enum GNUNET_BLOCK_EvaluationOptions eo,
  46. const struct GNUNET_HashCode *query,
  47. const void *xquery,
  48. size_t xquery_size,
  49. const void *reply_block,
  50. size_t reply_block_size)
  51. {
  52. if ((NULL == reply_block) ||
  53. (reply_block_size == 0) ||
  54. (0 != ((char *) reply_block)[0]))
  55. return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
  56. return GNUNET_BLOCK_EVALUATION_OK_MORE;
  57. }
  58. /**
  59. * Function called to obtain the key for a block.
  60. *
  61. * @param cls closure
  62. * @param type block type
  63. * @param block block to get the key for
  64. * @param block_size number of bytes in block
  65. * @param key set to the key (query) for the given block
  66. * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
  67. * (or if extracting a key from a block of this type does not work)
  68. */
  69. static int
  70. block_plugin_setu_test_get_key (void *cls,
  71. enum GNUNET_BLOCK_Type type,
  72. const void *block,
  73. size_t block_size,
  74. struct GNUNET_HashCode *key)
  75. {
  76. return GNUNET_SYSERR;
  77. }
  78. /**
  79. * Entry point for the plugin.
  80. */
  81. void *
  82. libgnunet_plugin_block_setu_test_init (void *cls)
  83. {
  84. static enum GNUNET_BLOCK_Type types[] = {
  85. GNUNET_BLOCK_TYPE_SETU_TEST,
  86. GNUNET_BLOCK_TYPE_ANY /* end of list */
  87. };
  88. struct GNUNET_BLOCK_PluginFunctions *api;
  89. api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
  90. api->evaluate = &block_plugin_setu_test_evaluate;
  91. api->get_key = &block_plugin_setu_test_get_key;
  92. api->types = types;
  93. return api;
  94. }
  95. /**
  96. * Exit point from the plugin.
  97. */
  98. void *
  99. libgnunet_plugin_block_setu_test_done (void *cls)
  100. {
  101. struct GNUNET_BLOCK_PluginFunctions *api = cls;
  102. GNUNET_free (api);
  103. return NULL;
  104. }
  105. /* end of plugin_block_setu_test.c */