diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-02-26 23:05:29 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-02-26 23:06:05 +0100 |
commit | e2b2ab728217a64027232c7b8fbbb68ba13edd4a (patch) | |
tree | 69caa7c21703f2eabe9a1ec12ef7d07ac58b0728 /src/consensus/plugin_block_consensus.c | |
parent | 8d7c29c4684f807d5e9a3004bbbab132b158c5aa (diff) | |
download | gnunet-e2b2ab728217a64027232c7b8fbbb68ba13edd4a.tar.gz gnunet-e2b2ab728217a64027232c7b8fbbb68ba13edd4a.zip |
wrap consensus elements in block type
Diffstat (limited to 'src/consensus/plugin_block_consensus.c')
-rw-r--r-- | src/consensus/plugin_block_consensus.c | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/consensus/plugin_block_consensus.c b/src/consensus/plugin_block_consensus.c new file mode 100644 index 000000000..399e85feb --- /dev/null +++ b/src/consensus/plugin_block_consensus.c | |||
@@ -0,0 +1,117 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2017 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
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 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file consensus/plugin_block_consensus.c | ||
23 | * @brief consensus block, either nested block or marker | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_block_plugin.h" | ||
29 | #include "gnunet_block_group_lib.h" | ||
30 | |||
31 | |||
32 | /** | ||
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 type block type | ||
38 | * @param group block group to use | ||
39 | * @param eo control flags | ||
40 | * @param query original query (hash) | ||
41 | * @param xquery extrended query data (can be NULL, depending on type) | ||
42 | * @param xquery_size number of bytes in xquery | ||
43 | * @param reply_block response to validate | ||
44 | * @param reply_block_size number of bytes in reply block | ||
45 | * @return characterization of result | ||
46 | */ | ||
47 | static enum GNUNET_BLOCK_EvaluationResult | ||
48 | block_plugin_consensus_evaluate (void *cls, | ||
49 | enum GNUNET_BLOCK_Type type, | ||
50 | struct GNUNET_BLOCK_Group *group, | ||
51 | enum GNUNET_BLOCK_EvaluationOptions eo, | ||
52 | const struct GNUNET_HashCode *query, | ||
53 | const void *xquery, | ||
54 | size_t xquery_size, | ||
55 | const void *reply_block, | ||
56 | size_t reply_block_size) | ||
57 | { | ||
58 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | ||
59 | } | ||
60 | |||
61 | |||
62 | /** | ||
63 | * Function called to obtain the key for a block. | ||
64 | * | ||
65 | * @param cls closure | ||
66 | * @param type block type | ||
67 | * @param block block to get the key for | ||
68 | * @param block_size number of bytes in block | ||
69 | * @param key set to the key (query) for the given block | ||
70 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if type not supported | ||
71 | * (or if extracting a key from a block of this type does not work) | ||
72 | */ | ||
73 | static int | ||
74 | block_plugin_consensus_get_key (void *cls, | ||
75 | enum GNUNET_BLOCK_Type type, | ||
76 | const void *block, | ||
77 | size_t block_size, | ||
78 | struct GNUNET_HashCode *key) | ||
79 | { | ||
80 | return GNUNET_SYSERR; | ||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Entry point for the plugin. | ||
86 | */ | ||
87 | void * | ||
88 | libgnunet_plugin_block_consensus_init (void *cls) | ||
89 | { | ||
90 | static enum GNUNET_BLOCK_Type types[] = | ||
91 | { | ||
92 | GNUNET_BLOCK_TYPE_CONSENSUS_ELEMENT, | ||
93 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | ||
94 | }; | ||
95 | struct GNUNET_BLOCK_PluginFunctions *api; | ||
96 | |||
97 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); | ||
98 | api->evaluate = &block_plugin_consensus_evaluate; | ||
99 | api->get_key = &block_plugin_consensus_get_key; | ||
100 | api->types = types; | ||
101 | return api; | ||
102 | } | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Exit point from the plugin. | ||
107 | */ | ||
108 | void * | ||
109 | libgnunet_plugin_block_consensus_done (void *cls) | ||
110 | { | ||
111 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | ||
112 | |||
113 | GNUNET_free (api); | ||
114 | return NULL; | ||
115 | } | ||
116 | |||
117 | /* end of plugin_block_consensus.c */ | ||