aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-11-22 11:53:26 +0000
committerChristian Grothoff <christian@grothoff.org>2011-11-22 11:53:26 +0000
commitd9a610d5d7c6d5c59f7c75385dcc9767c06bd5c3 (patch)
tree0e8e19c935735b4ab2cd2e6b884e70a451331ed3 /src/block
parent171caf7cfe0ef1baf0bab83d9efbbfde8d672562 (diff)
downloadgnunet-d9a610d5d7c6d5c59f7c75385dcc9767c06bd5c3.tar.gz
gnunet-d9a610d5d7c6d5c59f7c75385dcc9767c06bd5c3.zip
moving block plugins to respective subsystem
Diffstat (limited to 'src/block')
-rw-r--r--src/block/Makefile.am32
-rw-r--r--src/block/plugin_block_dht.c181
-rw-r--r--src/block/plugin_block_dns.c170
-rw-r--r--src/block/plugin_block_fs.c322
4 files changed, 0 insertions, 705 deletions
diff --git a/src/block/Makefile.am b/src/block/Makefile.am
index cfbcb797f..39de6edf0 100644
--- a/src/block/Makefile.am
+++ b/src/block/Makefile.am
@@ -13,41 +13,9 @@ endif
13lib_LTLIBRARIES = libgnunetblock.la 13lib_LTLIBRARIES = libgnunetblock.la
14 14
15plugin_LTLIBRARIES = \ 15plugin_LTLIBRARIES = \
16 libgnunet_plugin_block_dht.la \
17 libgnunet_plugin_block_fs.la \
18 libgnunet_plugin_block_template.la \ 16 libgnunet_plugin_block_template.la \
19 libgnunet_plugin_block_dns.la \
20 libgnunet_plugin_block_test.la 17 libgnunet_plugin_block_test.la
21 18
22libgnunet_plugin_block_dht_la_SOURCES = \
23 plugin_block_dht.c
24libgnunet_plugin_block_dht_la_LIBADD = \
25 $(top_builddir)/src/hello/libgnunethello.la \
26 $(top_builddir)/src/block/libgnunetblock.la \
27 $(top_builddir)/src/util/libgnunetutil.la
28libgnunet_plugin_block_dht_la_LDFLAGS = \
29 $(GN_PLUGIN_LDFLAGS)
30libgnunet_plugin_block_dht_la_DEPENDENCIES = \
31 libgnunetblock.la
32
33
34libgnunet_plugin_block_fs_la_SOURCES = \
35 plugin_block_fs.c
36libgnunet_plugin_block_fs_la_LIBADD = \
37 $(top_builddir)/src/block/libgnunetblock.la \
38 $(top_builddir)/src/util/libgnunetutil.la
39libgnunet_plugin_block_fs_la_LDFLAGS = \
40 $(GN_PLUGIN_LDFLAGS)
41libgnunet_plugin_block_fs_la_DEPENDENCIES = \
42 libgnunetblock.la
43
44
45libgnunet_plugin_block_dns_la_SOURCES = \
46 plugin_block_dns.c
47libgnunet_plugin_block_dns_la_LIBADD = \
48 $(top_builddir)/src/util/libgnunetutil.la
49libgnunet_plugin_block_dns_la_LDFLAGS = \
50 $(GN_PLUGIN_LDFLAGS)
51 19
52libgnunet_plugin_block_template_la_SOURCES = \ 20libgnunet_plugin_block_template_la_SOURCES = \
53 plugin_block_template.c 21 plugin_block_template.c
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
deleted file mode 100644
index f574e6d06..000000000
--- a/src/block/plugin_block_dht.c
+++ /dev/null
@@ -1,181 +0,0 @@
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 block/plugin_block_dht.c
23 * @brief block plugin for DHT internals (right now, find-peer requests only);
24 * other plugins should be used to store "useful" data in the
25 * DHT (see fs block plugin)
26 * @author Christian Grothoff
27 */
28
29#include "platform.h"
30#include "gnunet_constants.h"
31#include "gnunet_hello_lib.h"
32#include "gnunet_block_plugin.h"
33
34#define DEBUG_DHT GNUNET_EXTRA_LOGGING
35
36
37/**
38 * Function called to validate a reply or a request. For
39 * request evaluation, simply pass "NULL" for the reply_block.
40 *
41 * @param cls closure
42 * @param type block type
43 * @param query original query (hash)
44 * @param bf pointer to bloom filter associated with query; possibly updated (!)
45 * @param bf_mutator mutation value for bf
46 * @param xquery extended query data (can be NULL, depending on type)
47 * @param xquery_size number of bytes in xquery
48 * @param reply_block response to validate
49 * @param reply_block_size number of bytes in reply block
50 * @return characterization of result
51 */
52static enum GNUNET_BLOCK_EvaluationResult
53block_plugin_dht_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
54 const GNUNET_HashCode * query,
55 struct GNUNET_CONTAINER_BloomFilter **bf,
56 int32_t bf_mutator, const void *xquery,
57 size_t xquery_size, const void *reply_block,
58 size_t reply_block_size)
59{
60 GNUNET_HashCode mhash;
61 const struct GNUNET_HELLO_Message *hello;
62 struct GNUNET_PeerIdentity pid;
63 const struct GNUNET_MessageHeader *msg;
64
65 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
66 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
67 if (xquery_size != 0)
68 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
69 if (reply_block_size == 0)
70 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
71 if (reply_block_size < sizeof (struct GNUNET_MessageHeader))
72 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
73 msg = reply_block;
74 if (reply_block_size != ntohs (msg->size))
75 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
76 hello = reply_block;
77 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
78 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
79 if (NULL != bf)
80 {
81 GNUNET_BLOCK_mingle_hash (&pid.hashPubKey, bf_mutator, &mhash);
82 if (NULL != *bf)
83 {
84 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
85 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
86 }
87 else
88 {
89 *bf =
90 GNUNET_CONTAINER_bloomfilter_init (NULL, 8,
91 GNUNET_CONSTANTS_BLOOMFILTER_K);
92 }
93 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
94 }
95 return GNUNET_BLOCK_EVALUATION_OK_MORE;
96}
97
98
99/**
100 * Function called to obtain the key for a block.
101 *
102 * @param cls closure
103 * @param type block type
104 * @param block block to get the key for
105 * @param block_size number of bytes in block
106 * @param key set to the key (query) for the given block
107 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
108 * (or if extracting a key from a block of this type does not work)
109 */
110static int
111block_plugin_dht_get_key (void *cls, enum GNUNET_BLOCK_Type type,
112 const void *block, size_t block_size,
113 GNUNET_HashCode * key)
114{
115 const struct GNUNET_MessageHeader *msg;
116 const struct GNUNET_HELLO_Message *hello;
117 struct GNUNET_PeerIdentity *pid;
118
119 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
120 return GNUNET_SYSERR;
121 if (block_size < sizeof (struct GNUNET_MessageHeader))
122 {
123 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
124 _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO);
125 return GNUNET_NO;
126 }
127 msg = block;
128 if (block_size != ntohs (msg->size))
129 {
130 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
131 _("Size mismatch for block\n"),
132 GNUNET_BLOCK_TYPE_DHT_HELLO);
133 return GNUNET_NO;
134 }
135 hello = block;
136 pid = (struct GNUNET_PeerIdentity *) key;
137 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
138 {
139 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "block-dht",
140 _("Block of type %u is malformed\n"),
141 GNUNET_BLOCK_TYPE_DHT_HELLO);
142 return GNUNET_NO;
143 }
144 return GNUNET_OK;
145}
146
147
148/**
149 * Entry point for the plugin.
150 */
151void *
152libgnunet_plugin_block_dht_init (void *cls)
153{
154 static enum GNUNET_BLOCK_Type types[] =
155 {
156 GNUNET_BLOCK_TYPE_DHT_HELLO,
157 GNUNET_BLOCK_TYPE_ANY /* end of list */
158 };
159 struct GNUNET_BLOCK_PluginFunctions *api;
160
161 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
162 api->evaluate = &block_plugin_dht_evaluate;
163 api->get_key = &block_plugin_dht_get_key;
164 api->types = types;
165 return api;
166}
167
168
169/**
170 * Exit point from the plugin.
171 */
172void *
173libgnunet_plugin_block_dht_done (void *cls)
174{
175 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
176
177 GNUNET_free (api);
178 return NULL;
179}
180
181/* end of plugin_block_dht.c */
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
deleted file mode 100644
index b33b3798a..000000000
--- a/src/block/plugin_block_dns.c
+++ /dev/null
@@ -1,170 +0,0 @@
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 block/plugin_block_dns.c
23 * @brief block plugin for storing .gnunet-bindings
24 * @author Philipp Tölke
25 */
26
27#include "platform.h"
28#include "gnunet_block_plugin.h"
29#include "block_dns.h"
30#include "gnunet_signatures.h"
31
32#define DEBUG_DHT GNUNET_EXTRA_LOGGING
33
34/**
35 * Function called to validate a reply or a request. For
36 * request evaluation, simply pass "NULL" for the reply_block.
37 *
38 * @param cls closure
39 * @param type block type
40 * @param query original query (hash)
41 * @param bf pointer to bloom filter associated with query; possibly updated (!)
42 * @param bf_mutator mutation value for bf
43 * @param xquery extended query data (can be NULL, depending on type)
44 * @param xquery_size number of bytes in xquery
45 * @param reply_block response to validate
46 * @param reply_block_size number of bytes in reply block
47 * @return characterization of result
48 */
49static enum GNUNET_BLOCK_EvaluationResult
50block_plugin_dns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
51 const GNUNET_HashCode * query,
52 struct GNUNET_CONTAINER_BloomFilter **bf,
53 int32_t bf_mutator, const void *xquery,
54 size_t xquery_size, const void *reply_block,
55 size_t reply_block_size)
56{
57 switch (type)
58 {
59 case GNUNET_BLOCK_TYPE_DNS:
60 if (xquery_size != 0)
61 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
62
63 if (reply_block_size == 0)
64 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
65
66 if (reply_block_size != sizeof (struct GNUNET_DNS_Record))
67 {
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
69 "DNS-Block is invalid: reply_block_size=%d != %d\n",
70 reply_block_size, sizeof (struct GNUNET_DNS_Record));
71 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
72 }
73
74 const struct GNUNET_DNS_Record *rec = reply_block;
75
76 if (ntohl (rec->purpose.size) !=
77 sizeof (struct GNUNET_DNS_Record) -
78 sizeof (struct GNUNET_CRYPTO_RsaSignature))
79 {
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
82 ntohl (rec->purpose.size),
83 sizeof (struct GNUNET_DNS_Record) -
84 sizeof (struct GNUNET_CRYPTO_RsaSignature));
85 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
86 }
87
88 if (GNUNET_TIME_relative_get_zero ().rel_value ==
89 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh
90 (rec->expiration_time)).rel_value)
91 {
92 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
93 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
94 }
95
96 if (GNUNET_OK !=
97 GNUNET_CRYPTO_rsa_verify (htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
98 &rec->purpose, &rec->signature, &rec->peer))
99 {
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
101 "DNS-Block is invalid: invalid signature\n");
102 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
103 }
104
105 /* How to decide whether there are no more? */
106 return GNUNET_BLOCK_EVALUATION_OK_MORE;
107 default:
108 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
109 }
110}
111
112
113/**
114 * Function called to obtain the key for a block.
115 *
116 * @param cls closure
117 * @param type block type
118 * @param block block to get the key for
119 * @param block_size number of bytes in block
120 * @param key set to the key (query) for the given block
121 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
122 * (or if extracting a key from a block of this type does not work)
123 */
124static int
125block_plugin_dns_get_key (void *cls, enum GNUNET_BLOCK_Type type,
126 const void *block, size_t block_size,
127 GNUNET_HashCode * key)
128{
129 if (type != GNUNET_BLOCK_TYPE_DNS)
130 return GNUNET_SYSERR;
131 const struct GNUNET_DNS_Record *rec = block;
132
133 memcpy (key, &rec->service_descriptor, sizeof (GNUNET_HashCode));
134 return GNUNET_OK;
135}
136
137/**
138 * Entry point for the plugin.
139 */
140void *
141libgnunet_plugin_block_dns_init (void *cls)
142{
143 static enum GNUNET_BLOCK_Type types[] =
144 {
145 GNUNET_BLOCK_TYPE_DNS,
146 GNUNET_BLOCK_TYPE_ANY /* end of list */
147 };
148 struct GNUNET_BLOCK_PluginFunctions *api;
149
150 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
151 api->evaluate = &block_plugin_dns_evaluate;
152 api->get_key = &block_plugin_dns_get_key;
153 api->types = types;
154 return api;
155}
156
157
158/**
159 * Exit point from the plugin.
160 */
161void *
162libgnunet_plugin_block_dns_done (void *cls)
163{
164 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
165
166 GNUNET_free (api);
167 return NULL;
168}
169
170/* end of plugin_block_dns.c */
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
deleted file mode 100644
index c1b4ad7c8..000000000
--- a/src/block/plugin_block_fs.c
+++ /dev/null
@@ -1,322 +0,0 @@
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 block/plugin_block_fs.c
23 * @brief blocks used for file-sharing
24 * @author Christian Grothoff
25 */
26
27#include "platform.h"
28#include "gnunet_block_plugin.h"
29#include "block_fs.h"
30#include "gnunet_signatures.h"
31
32#define DEBUG_FS_BLOCK GNUNET_EXTRA_LOGGING
33
34/**
35 * Number of bits we set per entry in the bloomfilter.
36 * Do not change!
37 */
38#define BLOOMFILTER_K 16
39
40/**
41 * Function called to validate a reply or a request. For
42 * request evaluation, simply pass "NULL" for the reply_block.
43 * Note that it is assumed that the reply has already been
44 * matched to the key (and signatures checked) as it would
45 * be done with the "get_key" function.
46 *
47 * @param cls closure
48 * @param type block type
49 * @param query original query (hash)
50 * @param bf pointer to bloom filter associated with query; possibly updated (!)
51 * @param bf_mutator mutation value for bf
52 * @param xquery extrended query data (can be NULL, depending on type)
53 * @param xquery_size number of bytes in xquery
54 * @param reply_block response to validate
55 * @param reply_block_size number of bytes in reply block
56 * @return characterization of result
57 */
58static enum GNUNET_BLOCK_EvaluationResult
59block_plugin_fs_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
60 const GNUNET_HashCode * query,
61 struct GNUNET_CONTAINER_BloomFilter **bf,
62 int32_t bf_mutator, const void *xquery,
63 size_t xquery_size, const void *reply_block,
64 size_t reply_block_size)
65{
66 const struct SBlock *sb;
67 GNUNET_HashCode chash;
68 GNUNET_HashCode mhash;
69 const GNUNET_HashCode *nsid;
70 GNUNET_HashCode sh;
71
72 switch (type)
73 {
74 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
75 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
76 if (xquery_size != 0)
77 {
78 GNUNET_break_op (0);
79 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
80 }
81 if (reply_block == NULL)
82 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
83 return GNUNET_BLOCK_EVALUATION_OK_LAST;
84 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
85 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
86 if (xquery_size != 0)
87 {
88 GNUNET_break_op (0);
89 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
90 }
91 if (reply_block == NULL)
92 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
93 if (NULL != bf)
94 {
95 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
96 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
97 if (NULL != *bf)
98 {
99 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
100 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
101 }
102 else
103 {
104 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
105 }
106 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
107 }
108 return GNUNET_BLOCK_EVALUATION_OK_MORE;
109 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
110 if (xquery_size != sizeof (GNUNET_HashCode))
111 {
112 GNUNET_break_op (0);
113 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
114 }
115 if (reply_block == NULL)
116 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
117 nsid = xquery;
118 if (reply_block_size < sizeof (struct SBlock))
119 {
120 GNUNET_break_op (0);
121 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
122 }
123 sb = reply_block;
124 GNUNET_CRYPTO_hash (&sb->subspace,
125 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
126 &sh);
127 if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode)))
128 {
129 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, "block-fs",
130 _
131 ("Reply mismatched in terms of namespace. Discarded.\n"));
132 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
133 }
134 if (NULL != bf)
135 {
136 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
137 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
138 if (NULL != *bf)
139 {
140 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
141 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
142 }
143 else
144 {
145 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
146 }
147 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
148 }
149 return GNUNET_BLOCK_EVALUATION_OK_MORE;
150 default:
151 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
152 }
153}
154
155
156/**
157 * Function called to obtain the key for a block.
158 *
159 * @param cls closure
160 * @param type block type
161 * @param block block to get the key for
162 * @param block_size number of bytes in block
163 * @param key set to the key (query) for the given block
164 * @return GNUNET_OK on success, GNUNET_SYSERR if type not supported
165 * (or if extracting a key from a block of this type does not work)
166 */
167static int
168block_plugin_fs_get_key (void *cls, enum GNUNET_BLOCK_Type type,
169 const void *block, size_t block_size,
170 GNUNET_HashCode * key)
171{
172 const struct KBlock *kb;
173 const struct SBlock *sb;
174 const struct NBlock *nb;
175
176 switch (type)
177 {
178 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
179 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
180 GNUNET_CRYPTO_hash (block, block_size, key);
181 return GNUNET_OK;
182 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
183 if (block_size < sizeof (struct KBlock))
184 {
185 GNUNET_break_op (0);
186 return GNUNET_NO;
187 }
188 kb = block;
189 if (block_size - sizeof (struct KBlock) !=
190 ntohl (kb->purpose.size) -
191 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
192 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
193 {
194 GNUNET_break_op (0);
195 return GNUNET_NO;
196 }
197 if (GNUNET_OK !=
198 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
199 &kb->purpose, &kb->signature, &kb->keyspace))
200 {
201 GNUNET_break_op (0);
202 return GNUNET_NO;
203 }
204 if (key != NULL)
205 GNUNET_CRYPTO_hash (&kb->keyspace,
206 sizeof (struct
207 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
208 key);
209 return GNUNET_OK;
210 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
211 if (block_size < sizeof (struct SBlock))
212 {
213 GNUNET_break_op (0);
214 return GNUNET_NO;
215 }
216 sb = block;
217 if (block_size !=
218 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
219 {
220 GNUNET_break_op (0);
221 return GNUNET_NO;
222 }
223 if (GNUNET_OK !=
224 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
225 &sb->purpose, &sb->signature, &sb->subspace))
226 {
227 GNUNET_break_op (0);
228 return GNUNET_NO;
229 }
230 if (key != NULL)
231 *key = sb->identifier;
232 return GNUNET_OK;
233 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
234 if (block_size < sizeof (struct NBlock))
235 {
236 GNUNET_break_op (0);
237 return GNUNET_NO;
238 }
239 nb = block;
240 if (block_size - sizeof (struct NBlock) !=
241 ntohl (nb->ns_purpose.size) -
242 sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) -
243 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
244 {
245 GNUNET_break_op (0);
246 return GNUNET_NO;
247 }
248 if (block_size !=
249 ntohl (nb->ksk_purpose.size) +
250 sizeof (struct GNUNET_CRYPTO_RsaSignature))
251 {
252 GNUNET_break_op (0);
253 return GNUNET_NO;
254 }
255 if (GNUNET_OK !=
256 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
257 &nb->ksk_purpose, &nb->ksk_signature,
258 &nb->keyspace))
259 {
260 GNUNET_break_op (0);
261 return GNUNET_NO;
262 }
263 if (GNUNET_OK !=
264 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
265 &nb->ns_purpose, &nb->ns_signature,
266 &nb->subspace))
267 {
268 GNUNET_break_op (0);
269 return GNUNET_NO;
270 }
271 /* FIXME: we used to xor ID with NSID,
272 * why not here? */
273 if (key != NULL)
274 GNUNET_CRYPTO_hash (&nb->keyspace,
275 sizeof (struct
276 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
277 key);
278 return GNUNET_OK;
279 default:
280 return GNUNET_SYSERR;
281 }
282}
283
284
285/**
286 * Entry point for the plugin.
287 */
288void *
289libgnunet_plugin_block_fs_init (void *cls)
290{
291 static enum GNUNET_BLOCK_Type types[] =
292 {
293 GNUNET_BLOCK_TYPE_FS_DBLOCK,
294 GNUNET_BLOCK_TYPE_FS_IBLOCK,
295 GNUNET_BLOCK_TYPE_FS_KBLOCK,
296 GNUNET_BLOCK_TYPE_FS_SBLOCK,
297 GNUNET_BLOCK_TYPE_FS_NBLOCK,
298 GNUNET_BLOCK_TYPE_ANY /* end of list */
299 };
300 struct GNUNET_BLOCK_PluginFunctions *api;
301
302 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
303 api->evaluate = &block_plugin_fs_evaluate;
304 api->get_key = &block_plugin_fs_get_key;
305 api->types = types;
306 return api;
307}
308
309
310/**
311 * Exit point from the plugin.
312 */
313void *
314libgnunet_plugin_block_fs_done (void *cls)
315{
316 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
317
318 GNUNET_free (api);
319 return NULL;
320}
321
322/* end of plugin_block_fs.c */