2 This file is part of GNUnet
3 Copyright (C) 2017 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file consensus/plugin_block_consensus.c
18 * @brief consensus block, either nested block or marker
19 * @author Christian Grothoff
23 #include "consensus_protocol.h"
24 #include "gnunet_block_plugin.h"
25 #include "gnunet_block_group_lib.h"
29 * Function called to validate a reply or a request. For
30 * request evaluation, simply pass "NULL" for the reply_block.
34 * @param type block type
35 * @param group block group to use
36 * @param eo control flags
37 * @param query original query (hash)
38 * @param xquery extrended query data (can be NULL, depending on type)
39 * @param xquery_size number of bytes in xquery
40 * @param reply_block response to validate
41 * @param reply_block_size number of bytes in reply block
42 * @return characterization of result
44 static enum GNUNET_BLOCK_EvaluationResult
45 block_plugin_consensus_evaluate (void *cls,
46 struct GNUNET_BLOCK_Context *ctx,
47 enum GNUNET_BLOCK_Type type,
48 struct GNUNET_BLOCK_Group *group,
49 enum GNUNET_BLOCK_EvaluationOptions eo,
50 const struct GNUNET_HashCode *query,
53 const void *reply_block,
54 size_t reply_block_size)
56 if (reply_block_size < sizeof (struct ConsensusElement))
57 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
59 const struct ConsensusElement *ce = reply_block;
61 if ( (0 != ce->marker) ||
62 (0 == ce->payload_type ) )
63 return GNUNET_BLOCK_EVALUATION_OK_MORE;
65 return GNUNET_BLOCK_evaluate (ctx,
73 reply_block_size - sizeof (struct ConsensusElement));
78 * Function called to obtain the key for a block.
81 * @param type block type
82 * @param block block to get the key for
83 * @param block_size number of bytes in block
84 * @param key set to the key (query) for the given block
85 * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported
86 * (or if extracting a key from a block of this type does not work)
89 block_plugin_consensus_get_key (void *cls,
90 enum GNUNET_BLOCK_Type type,
93 struct GNUNET_HashCode *key)
100 * Entry point for the plugin.
103 libgnunet_plugin_block_consensus_init (void *cls)
105 static enum GNUNET_BLOCK_Type types[] =
107 GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT,
108 GNUNET_BLOCK_TYPE_ANY /* end of list */
110 struct GNUNET_BLOCK_PluginFunctions *api;
112 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions);
113 api->evaluate = &block_plugin_consensus_evaluate;
114 api->get_key = &block_plugin_consensus_get_key;
121 * Exit point from the plugin.
124 libgnunet_plugin_block_consensus_done (void *cls)
126 struct GNUNET_BLOCK_PluginFunctions *api = cls;
132 /* end of plugin_block_consensus.c */