aboutsummaryrefslogtreecommitdiff
path: root/src/gns/plugin_block_gns.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-24 17:42:29 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-02-24 17:42:29 +0000
commit1bcb11a931fab488e960ec6980ed4251e5f4231c (patch)
tree2f937536a4f7d168d4017b43ffef970f00a28355 /src/gns/plugin_block_gns.c
parent558c365484160e3c873e3123a8a7453eec45b6aa (diff)
downloadgnunet-1bcb11a931fab488e960ec6980ed4251e5f4231c.tar.gz
gnunet-1bcb11a931fab488e960ec6980ed4251e5f4231c.zip
-first try on blocks
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r--src/gns/plugin_block_gns.c128
1 files changed, 128 insertions, 0 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
new file mode 100644
index 000000000..33699a32c
--- /dev/null
+++ b/src/gns/plugin_block_gns.c
@@ -0,0 +1,128 @@
1/*
2 This file is part of GNUnet
3 (C) 2010 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file gns/plugin_block_gns.c
23 * @brief blocks used for GNS records
24 * @author Martin Schanzenbach
25 */
26
27#include "platform.h"
28#include "gnunet_block_plugin.h"
29#include "block_gns.h"
30#include "gnunet_signatures.h"
31
32/**
33 * Number of bits we set per entry in the bloomfilter.
34 * Do not change! -from fs
35 */
36#define BLOOMFILTER_K 16
37
38/**
39 * Function called to validate a reply or a request. For
40 * request evaluation, simply pass "NULL" for the reply_block.
41 * Note that it is assumed that the reply has already been
42 * matched to the key (and signatures checked) as it would
43 * be done with the "get_key" function.
44 *
45 * @param cls closure
46 * @param type block type
47 * @param query original query (hash)
48 * @param bf pointer to bloom filter associated with query; possibly updated (!)
49 * @param bf_mutator mutation value for bf
50 * @param xquery extrended query data (can be NULL, depending on type)
51 * @param xquery_size number of bytes in xquery
52 * @param reply_block response to validate
53 * @param reply_block_size number of bytes in reply block
54 * @return characterization of result
55 */
56static enum GNUNET_BLOCK_EvaluationResult
57block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
58 const GNUNET_HashCode * query,
59 struct GNUNET_CONTAINER_BloomFilter **bf,
60 int32_t bf_mutator, const void *xquery,
61 size_t xquery_size, const void *reply_block,
62 size_t reply_block_size)
63{
64 if (type != GNUNET_BLOCK_TYPE_GNS_RECORD)
65 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
66
67 //FIXME check signatures here
68 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
69}
70
71
72/**
73 * Function called to obtain the key for a block.
74 *
75 * @param cls closure
76 * @param type block type
77 * @param block block to get the key for
78 * @param block_size number of bytes in block
79 * @param key set to the key (query) for the given block
80 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
81 * (or if extracting a key from a block of this type does not work)
82 */
83static int
84block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type,
85 const void *block, size_t block_size,
86 GNUNET_HashCode * key)
87{
88 if (type != GNUNET_BLOCK_TYPE_GNS_RECORD)
89 return GNUNET_NO;
90 //FIXME calculate key from name and hash(pkey) here
91 return GNUNET_OK;
92}
93
94
95/**
96 * Entry point for the plugin.
97 */
98void *
99libgnunet_plugin_block_gns_init (void *cls)
100{
101 static enum GNUNET_BLOCK_Type types[] =
102 {
103 GNUNET_BLOCK_TYPE_GNS_RECORD,
104 GNUNET_BLOCK_TYPE_ANY /* end of list */
105 };
106 struct GNUNET_BLOCK_PluginFunctions *api;
107
108 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
109 api->evaluate = &block_plugin_gns_evaluate;
110 api->get_key = &block_plugin_gns_get_key;
111 api->types = types;
112 return api;
113}
114
115
116/**
117 * Exit point from the plugin.
118 */
119void *
120libgnunet_plugin_block_gns_done (void *cls)
121{
122 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
123
124 GNUNET_free (api);
125 return NULL;
126}
127
128/* end of plugin_block_gns.c */