aboutsummaryrefslogtreecommitdiff
path: root/src/setu/plugin_block_setu_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/setu/plugin_block_setu_test.c')
-rw-r--r--src/setu/plugin_block_setu_test.c76
1 files changed, 32 insertions, 44 deletions
diff --git a/src/setu/plugin_block_setu_test.c b/src/setu/plugin_block_setu_test.c
index 9872bba39..178ad3314 100644
--- a/src/setu/plugin_block_setu_test.c
+++ b/src/setu/plugin_block_setu_test.c
@@ -23,49 +23,12 @@
23 * @brief set test block, recognizes elements with non-zero first byte as invalid 23 * @brief set test block, recognizes elements with non-zero first byte as invalid
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26
27#include "platform.h" 26#include "platform.h"
28#include "gnunet_block_plugin.h" 27#include "gnunet_block_plugin.h"
29#include "gnunet_block_group_lib.h" 28#include "gnunet_block_group_lib.h"
30 29
31 30
32/** 31/**
33 * Function called to validate a reply or a request. For
34 * request evaluation, simply pass "NULL" for the reply_block.
35 *
36 * @param cls closure
37 * @param ctx block context
38 * @param type block type
39 * @param group block group to use
40 * @param eo control flags
41 * @param query original query (hash)
42 * @param xquery extrended query data (can be NULL, depending on type)
43 * @param xquery_size number of bytes in xquery
44 * @param reply_block response to validate
45 * @param reply_block_size number of bytes in reply block
46 * @return characterization of result
47 */
48static enum GNUNET_BLOCK_EvaluationResult
49block_plugin_setu_test_evaluate (void *cls,
50 struct GNUNET_BLOCK_Context *ctx,
51 enum GNUNET_BLOCK_Type type,
52 struct GNUNET_BLOCK_Group *group,
53 enum GNUNET_BLOCK_EvaluationOptions eo,
54 const struct GNUNET_HashCode *query,
55 const void *xquery,
56 size_t xquery_size,
57 const void *reply_block,
58 size_t reply_block_size)
59{
60 if ((NULL == reply_block) ||
61 (reply_block_size == 0) ||
62 (0 != ((char *) reply_block)[0]))
63 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
64 return GNUNET_BLOCK_EVALUATION_OK_MORE;
65}
66
67
68/**
69 * Function called to validate a query. 32 * Function called to validate a query.
70 * 33 *
71 * @param cls closure 34 * @param cls closure
@@ -83,6 +46,16 @@ block_plugin_setu_test_check_query (void *cls,
83 const void *xquery, 46 const void *xquery,
84 size_t xquery_size) 47 size_t xquery_size)
85{ 48{
49 if (GNUNET_BLOCK_TYPE_SETU_TEST != type)
50 {
51 GNUNET_break (0);
52 return GNUNET_SYSERR;
53 }
54 if (0 != xquery_size)
55 {
56 GNUNET_break_op (0);
57 return GNUNET_NO;
58 }
86 return GNUNET_OK; 59 return GNUNET_OK;
87} 60}
88 61
@@ -92,7 +65,6 @@ block_plugin_setu_test_check_query (void *cls,
92 * 65 *
93 * @param cls closure 66 * @param cls closure
94 * @param type block type 67 * @param type block type
95 * @param query key for the block (hash), must match exactly
96 * @param block block data to validate 68 * @param block block data to validate
97 * @param block_size number of bytes in @a block 69 * @param block_size number of bytes in @a block
98 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not 70 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
@@ -100,14 +72,18 @@ block_plugin_setu_test_check_query (void *cls,
100static enum GNUNET_GenericReturnValue 72static enum GNUNET_GenericReturnValue
101block_plugin_setu_test_check_block (void *cls, 73block_plugin_setu_test_check_block (void *cls,
102 enum GNUNET_BLOCK_Type type, 74 enum GNUNET_BLOCK_Type type,
103 const struct GNUNET_HashCode *query,
104 const void *block, 75 const void *block,
105 size_t block_size) 76 size_t block_size)
106{ 77{
78 if (GNUNET_BLOCK_TYPE_SETU_TEST != type)
79 {
80 GNUNET_break (0);
81 return GNUNET_SYSERR;
82 }
107 if ( (NULL == block) || 83 if ( (NULL == block) ||
108 (0 == block_size) || 84 (0 == block_size) ||
109 (0 != ((char *) block)[0]) ) 85 (0 != ((char *) block)[0]) )
110 return GNUNET_SYSERR; 86 return GNUNET_NO;
111 return GNUNET_OK; 87 return GNUNET_OK;
112} 88}
113 89
@@ -138,10 +114,18 @@ block_plugin_setu_test_check_reply (void *cls,
138 const void *reply_block, 114 const void *reply_block,
139 size_t reply_block_size) 115 size_t reply_block_size)
140{ 116{
117 (void) cls;
118 (void) xquery;
119 (void) xquery_size;
120 if (GNUNET_BLOCK_TYPE_SETU_TEST != type)
121 {
122 GNUNET_break (0);
123 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
124 }
141 if ( (NULL == reply_block) || 125 if ( (NULL == reply_block) ||
142 (0 == reply_block_size) || 126 (0 == reply_block_size) ||
143 (0 != ((char *) reply_block)[0]) ) 127 (0 != ((char *) reply_block)[0]) )
144 return GNUNET_BLOCK_REPLY_INVALID; 128 GNUNET_assert (0);
145 return GNUNET_BLOCK_REPLY_OK_MORE; 129 return GNUNET_BLOCK_REPLY_OK_MORE;
146} 130}
147 131
@@ -164,7 +148,12 @@ block_plugin_setu_test_get_key (void *cls,
164 size_t block_size, 148 size_t block_size,
165 struct GNUNET_HashCode *key) 149 struct GNUNET_HashCode *key)
166{ 150{
167 return GNUNET_SYSERR; 151 if (GNUNET_BLOCK_TYPE_SETU_TEST != type)
152 {
153 GNUNET_break (0);
154 return GNUNET_SYSERR;
155 }
156 return GNUNET_NO;
168} 157}
169 158
170 159
@@ -175,13 +164,12 @@ void *
175libgnunet_plugin_block_setu_test_init (void *cls) 164libgnunet_plugin_block_setu_test_init (void *cls)
176{ 165{
177 static enum GNUNET_BLOCK_Type types[] = { 166 static enum GNUNET_BLOCK_Type types[] = {
178 GNUNET_BLOCK_TYPE_SETU_TEST, 167 GNUNET_BLOCK_TYPE_SETU_TEST,
179 GNUNET_BLOCK_TYPE_ANY /* end of list */ 168 GNUNET_BLOCK_TYPE_ANY /* end of list */
180 }; 169 };
181 struct GNUNET_BLOCK_PluginFunctions *api; 170 struct GNUNET_BLOCK_PluginFunctions *api;
182 171
183 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 172 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
184 api->evaluate = &block_plugin_setu_test_evaluate;
185 api->get_key = &block_plugin_setu_test_get_key; 173 api->get_key = &block_plugin_setu_test_get_key;
186 api->check_query = &block_plugin_setu_test_check_query; 174 api->check_query = &block_plugin_setu_test_check_query;
187 api->check_block = &block_plugin_setu_test_check_block; 175 api->check_block = &block_plugin_setu_test_check_block;