aboutsummaryrefslogtreecommitdiff
path: root/src/set/plugin_block_set_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/set/plugin_block_set_test.c')
-rw-r--r--src/set/plugin_block_set_test.c88
1 files changed, 86 insertions, 2 deletions
diff --git a/src/set/plugin_block_set_test.c b/src/set/plugin_block_set_test.c
index 1de086092..3d66831bb 100644
--- a/src/set/plugin_block_set_test.c
+++ b/src/set/plugin_block_set_test.c
@@ -66,6 +66,87 @@ block_plugin_set_test_evaluate (void *cls,
66 66
67 67
68/** 68/**
69 * Function called to validate a query.
70 *
71 * @param cls closure
72 * @param ctx block context
73 * @param type block type
74 * @param query original query (hash)
75 * @param xquery extrended query data (can be NULL, depending on type)
76 * @param xquery_size number of bytes in @a xquery
77 * @return #GNUNET_OK if the query is fine, #GNUNET_NO if not
78 */
79static enum GNUNET_GenericReturnValue
80block_plugin_set_test_check_query (void *cls,
81 enum GNUNET_BLOCK_Type type,
82 const struct GNUNET_HashCode *query,
83 const void *xquery,
84 size_t xquery_size)
85{
86 return GNUNET_OK;
87}
88
89
90/**
91 * Function called to validate a block for storage.
92 *
93 * @param cls closure
94 * @param type block type
95 * @param query key for the block (hash), must match exactly
96 * @param block block data to validate
97 * @param block_size number of bytes in @a block
98 * @return #GNUNET_OK if the block is fine, #GNUNET_NO if not
99 */
100static enum GNUNET_GenericReturnValue
101block_plugin_set_test_check_block (void *cls,
102 enum GNUNET_BLOCK_Type type,
103 const struct GNUNET_HashCode *query,
104 const void *block,
105 size_t block_size)
106{
107 if ((NULL == block) ||
108 (0 == block_size) ||
109 (0 != ((char *) block)[0]))
110 return GNUNET_SYSERR;
111 return GNUNET_OK;
112}
113
114
115/**
116 * Function called to validate a reply to a request. Note that it is assumed
117 * that the reply has already been matched to the key (and signatures checked)
118 * as it would be done with the GetKeyFunction and the
119 * BlockEvaluationFunction.
120 *
121 * @param cls closure
122 * @param type block type
123 * @param group which block group to use for evaluation
124 * @param query original query (hash)
125 * @param xquery extrended query data (can be NULL, depending on type)
126 * @param xquery_size number of bytes in @a xquery
127 * @param reply_block response to validate
128 * @param reply_block_size number of bytes in @a reply_block
129 * @return characterization of result
130 */
131static enum GNUNET_BLOCK_ReplyEvaluationResult
132block_plugin_set_test_check_reply (void *cls,
133 enum GNUNET_BLOCK_Type type,
134 struct GNUNET_BLOCK_Group *group,
135 const struct GNUNET_HashCode *query,
136 const void *xquery,
137 size_t xquery_size,
138 const void *reply_block,
139 size_t reply_block_size)
140{
141 if ((NULL == reply_block) ||
142 (0 == reply_block_size) ||
143 (0 != ((char *) reply_block)[0]))
144 return GNUNET_BLOCK_REPLY_INVALID;
145 return GNUNET_BLOCK_REPLY_OK_MORE;
146}
147
148
149/**
69 * Function called to obtain the key for a block. 150 * Function called to obtain the key for a block.
70 * 151 *
71 * @param cls closure 152 * @param cls closure
@@ -76,7 +157,7 @@ block_plugin_set_test_evaluate (void *cls,
76 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported 157 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
77 * (or if extracting a key from a block of this type does not work) 158 * (or if extracting a key from a block of this type does not work)
78 */ 159 */
79static int 160static enum GNUNET_GenericReturnValue
80block_plugin_set_test_get_key (void *cls, 161block_plugin_set_test_get_key (void *cls,
81 enum GNUNET_BLOCK_Type type, 162 enum GNUNET_BLOCK_Type type,
82 const void *block, 163 const void *block,
@@ -93,7 +174,7 @@ block_plugin_set_test_get_key (void *cls,
93void * 174void *
94libgnunet_plugin_block_set_test_init (void *cls) 175libgnunet_plugin_block_set_test_init (void *cls)
95{ 176{
96 static enum GNUNET_BLOCK_Type types[] = { 177 static const enum GNUNET_BLOCK_Type types[] = {
97 GNUNET_BLOCK_TYPE_SET_TEST, 178 GNUNET_BLOCK_TYPE_SET_TEST,
98 GNUNET_BLOCK_TYPE_ANY /* end of list */ 179 GNUNET_BLOCK_TYPE_ANY /* end of list */
99 }; 180 };
@@ -102,6 +183,9 @@ libgnunet_plugin_block_set_test_init (void *cls)
102 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 183 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
103 api->evaluate = &block_plugin_set_test_evaluate; 184 api->evaluate = &block_plugin_set_test_evaluate;
104 api->get_key = &block_plugin_set_test_get_key; 185 api->get_key = &block_plugin_set_test_get_key;
186 api->check_query = &block_plugin_set_test_check_query;
187 api->check_block = &block_plugin_set_test_check_block;
188 api->check_reply = &block_plugin_set_test_check_reply;
105 api->types = types; 189 api->types = types;
106 return api; 190 return api;
107} 191}