summaryrefslogtreecommitdiff
path: root/src/gns/plugin_block_gns.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r--src/gns/plugin_block_gns.c148
1 files changed, 74 insertions, 74 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 86d45b9fe..71cd78a8e 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file gns/plugin_block_gns.c 22 * @file gns/plugin_block_gns.c
@@ -56,37 +56,37 @@
56 * by this @a type of block (this is not an error) 56 * by this @a type of block (this is not an error)
57 */ 57 */
58static struct GNUNET_BLOCK_Group * 58static struct GNUNET_BLOCK_Group *
59block_plugin_gns_create_group (void *cls, 59block_plugin_gns_create_group(void *cls,
60 enum GNUNET_BLOCK_Type type, 60 enum GNUNET_BLOCK_Type type,
61 uint32_t nonce, 61 uint32_t nonce,
62 const void *raw_data, 62 const void *raw_data,
63 size_t raw_data_size, 63 size_t raw_data_size,
64 va_list va) 64 va_list va)
65{ 65{
66 unsigned int bf_size; 66 unsigned int bf_size;
67 const char *guard; 67 const char *guard;
68 68
69 guard = va_arg (va, const char *); 69 guard = va_arg(va, const char *);
70 if (0 == strcmp (guard, 70 if (0 == strcmp(guard,
71 "seen-set-size")) 71 "seen-set-size"))
72 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int), 72 bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int),
73 BLOOMFILTER_K); 73 BLOOMFILTER_K);
74 else if (0 == strcmp (guard, 74 else if (0 == strcmp(guard,
75 "filter-size")) 75 "filter-size"))
76 bf_size = va_arg (va, unsigned int); 76 bf_size = va_arg(va, unsigned int);
77 else 77 else
78 { 78 {
79 GNUNET_break (0); 79 GNUNET_break(0);
80 bf_size = GNS_BF_SIZE; 80 bf_size = GNS_BF_SIZE;
81 } 81 }
82 GNUNET_break (NULL == va_arg (va, const char *)); 82 GNUNET_break(NULL == va_arg(va, const char *));
83 return GNUNET_BLOCK_GROUP_bf_create (cls, 83 return GNUNET_BLOCK_GROUP_bf_create(cls,
84 bf_size, 84 bf_size,
85 BLOOMFILTER_K, 85 BLOOMFILTER_K,
86 type, 86 type,
87 nonce, 87 nonce,
88 raw_data, 88 raw_data,
89 raw_data_size); 89 raw_data_size);
90} 90}
91 91
92 92
@@ -110,16 +110,16 @@ block_plugin_gns_create_group (void *cls,
110 * @return characterization of result 110 * @return characterization of result
111 */ 111 */
112static enum GNUNET_BLOCK_EvaluationResult 112static enum GNUNET_BLOCK_EvaluationResult
113block_plugin_gns_evaluate (void *cls, 113block_plugin_gns_evaluate(void *cls,
114 struct GNUNET_BLOCK_Context *ctx, 114 struct GNUNET_BLOCK_Context *ctx,
115 enum GNUNET_BLOCK_Type type, 115 enum GNUNET_BLOCK_Type type,
116 struct GNUNET_BLOCK_Group *bg, 116 struct GNUNET_BLOCK_Group *bg,
117 enum GNUNET_BLOCK_EvaluationOptions eo, 117 enum GNUNET_BLOCK_EvaluationOptions eo,
118 const struct GNUNET_HashCode *query, 118 const struct GNUNET_HashCode *query,
119 const void *xquery, 119 const void *xquery,
120 size_t xquery_size, 120 size_t xquery_size,
121 const void *reply_block, 121 const void *reply_block,
122 size_t reply_block_size) 122 size_t reply_block_size)
123{ 123{
124 const struct GNUNET_GNSRECORD_Block *block; 124 const struct GNUNET_GNSRECORD_Block *block;
125 struct GNUNET_HashCode h; 125 struct GNUNET_HashCode h;
@@ -128,48 +128,48 @@ block_plugin_gns_evaluate (void *cls,
128 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 128 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
129 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 129 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
130 if (NULL == reply_block) 130 if (NULL == reply_block)
131 {
132 if (0 != xquery_size)
133 { 131 {
134 GNUNET_break_op (0); 132 if (0 != xquery_size)
135 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 133 {
134 GNUNET_break_op(0);
135 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
136 }
137 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
136 } 138 }
137 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
138 }
139 139
140 /* this is a reply */ 140 /* this is a reply */
141 if (reply_block_size < sizeof (struct GNUNET_GNSRECORD_Block)) 141 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
142 { 142 {
143 GNUNET_break_op (0); 143 GNUNET_break_op(0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 } 145 }
146 block = reply_block; 146 block = reply_block;
147 if (ntohl (block->purpose.size) + sizeof (struct GNUNET_CRYPTO_EcdsaSignature) + sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey) != 147 if (ntohl(block->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) !=
148 reply_block_size) 148 reply_block_size)
149 { 149 {
150 GNUNET_break_op (0); 150 GNUNET_break_op(0);
151 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 151 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
152 } 152 }
153 GNUNET_CRYPTO_hash (&block->derived_key, 153 GNUNET_CRYPTO_hash(&block->derived_key,
154 sizeof (block->derived_key), 154 sizeof(block->derived_key),
155 &h); 155 &h);
156 if (0 != GNUNET_memcmp (&h, query)) 156 if (0 != GNUNET_memcmp(&h, query))
157 { 157 {
158 GNUNET_break_op (0); 158 GNUNET_break_op(0);
159 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 159 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
160 } 160 }
161 if (GNUNET_OK != 161 if (GNUNET_OK !=
162 GNUNET_GNSRECORD_block_verify (block)) 162 GNUNET_GNSRECORD_block_verify(block))
163 { 163 {
164 GNUNET_break_op (0); 164 GNUNET_break_op(0);
165 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 165 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
166 } 166 }
167 GNUNET_CRYPTO_hash (reply_block, 167 GNUNET_CRYPTO_hash(reply_block,
168 reply_block_size, 168 reply_block_size,
169 &chash); 169 &chash);
170 if (GNUNET_YES == 170 if (GNUNET_YES ==
171 GNUNET_BLOCK_GROUP_bf_test_and_set (bg, 171 GNUNET_BLOCK_GROUP_bf_test_and_set(bg,
172 &chash)) 172 &chash))
173 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 173 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
174 return GNUNET_BLOCK_EVALUATION_OK_MORE; 174 return GNUNET_BLOCK_EVALUATION_OK_MORE;
175} 175}
@@ -187,25 +187,25 @@ block_plugin_gns_evaluate (void *cls,
187 * (or if extracting a key from a block of this type does not work) 187 * (or if extracting a key from a block of this type does not work)
188 */ 188 */
189static int 189static int
190block_plugin_gns_get_key (void *cls, 190block_plugin_gns_get_key(void *cls,
191 enum GNUNET_BLOCK_Type type, 191 enum GNUNET_BLOCK_Type type,
192 const void *reply_block, 192 const void *reply_block,
193 size_t reply_block_size, 193 size_t reply_block_size,
194 struct GNUNET_HashCode *key) 194 struct GNUNET_HashCode *key)
195{ 195{
196 const struct GNUNET_GNSRECORD_Block *block; 196 const struct GNUNET_GNSRECORD_Block *block;
197 197
198 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 198 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
199 return GNUNET_SYSERR; 199 return GNUNET_SYSERR;
200 if (reply_block_size < sizeof (struct GNUNET_GNSRECORD_Block)) 200 if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block))
201 { 201 {
202 GNUNET_break_op (0); 202 GNUNET_break_op(0);
203 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 203 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
204 } 204 }
205 block = reply_block; 205 block = reply_block;
206 GNUNET_CRYPTO_hash (&block->derived_key, 206 GNUNET_CRYPTO_hash(&block->derived_key,
207 sizeof (block->derived_key), 207 sizeof(block->derived_key),
208 key); 208 key);
209 return GNUNET_OK; 209 return GNUNET_OK;
210} 210}
211 211
@@ -214,7 +214,7 @@ block_plugin_gns_get_key (void *cls,
214 * Entry point for the plugin. 214 * Entry point for the plugin.
215 */ 215 */
216void * 216void *
217libgnunet_plugin_block_gns_init (void *cls) 217libgnunet_plugin_block_gns_init(void *cls)
218{ 218{
219 static enum GNUNET_BLOCK_Type types[] = 219 static enum GNUNET_BLOCK_Type types[] =
220 { 220 {
@@ -223,7 +223,7 @@ libgnunet_plugin_block_gns_init (void *cls)
223 }; 223 };
224 struct GNUNET_BLOCK_PluginFunctions *api; 224 struct GNUNET_BLOCK_PluginFunctions *api;
225 225
226 api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); 226 api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions);
227 api->evaluate = &block_plugin_gns_evaluate; 227 api->evaluate = &block_plugin_gns_evaluate;
228 api->get_key = &block_plugin_gns_get_key; 228 api->get_key = &block_plugin_gns_get_key;
229 api->create_group = &block_plugin_gns_create_group; 229 api->create_group = &block_plugin_gns_create_group;
@@ -236,11 +236,11 @@ libgnunet_plugin_block_gns_init (void *cls)
236 * Exit point from the plugin. 236 * Exit point from the plugin.
237 */ 237 */
238void * 238void *
239libgnunet_plugin_block_gns_done (void *cls) 239libgnunet_plugin_block_gns_done(void *cls)
240{ 240{
241 struct GNUNET_BLOCK_PluginFunctions *api = cls; 241 struct GNUNET_BLOCK_PluginFunctions *api = cls;
242 242
243 GNUNET_free (api); 243 GNUNET_free(api);
244 return NULL; 244 return NULL;
245} 245}
246 246