aboutsummaryrefslogtreecommitdiff
path: root/src/block
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:46:35 +0000
commit502af2167f7c218366666ca4944bd7cc54b5b19a (patch)
treea91fec5cc9769d260640bd91c6633cb9cf395524 /src/block
parent03af5a603b7cc53432249d5854cd412aa90dde0d (diff)
downloadgnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.tar.gz
gnunet-502af2167f7c218366666ca4944bd7cc54b5b19a.zip
indentation
Diffstat (limited to 'src/block')
-rw-r--r--src/block/block.c132
-rw-r--r--src/block/plugin_block_dht.c83
-rw-r--r--src/block/plugin_block_dns.c105
-rw-r--r--src/block/plugin_block_fs.c408
-rw-r--r--src/block/plugin_block_template.c35
-rw-r--r--src/block/plugin_block_test.c61
-rw-r--r--src/block/test_block.c34
7 files changed, 403 insertions, 455 deletions
diff --git a/src/block/block.c b/src/block/block.c
index 24bde02ac..bdef55aa3 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -37,9 +37,9 @@ struct Plugin
37{ 37{
38 /** 38 /**
39 * Name of the shared library. 39 * Name of the shared library.
40 */ 40 */
41 char *library_name; 41 char *library_name;
42 42
43 /** 43 /**
44 * Plugin API. 44 * Plugin API.
45 */ 45 */
@@ -59,7 +59,7 @@ struct GNUNET_BLOCK_Context
59 59
60 /** 60 /**
61 * Our configuration. 61 * Our configuration.
62 */ 62 */
63 const struct GNUNET_CONFIGURATION_Handle *cfg; 63 const struct GNUNET_CONFIGURATION_Handle *cfg;
64}; 64};
65 65
@@ -73,14 +73,11 @@ struct GNUNET_BLOCK_Context
73 */ 73 */
74void 74void
75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in, 75GNUNET_BLOCK_mingle_hash (const GNUNET_HashCode * in,
76 uint32_t mingle_number, 76 uint32_t mingle_number, GNUNET_HashCode * hc)
77 GNUNET_HashCode * hc)
78{ 77{
79 GNUNET_HashCode m; 78 GNUNET_HashCode m;
80 79
81 GNUNET_CRYPTO_hash (&mingle_number, 80 GNUNET_CRYPTO_hash (&mingle_number, sizeof (uint32_t), &m);
82 sizeof (uint32_t),
83 &m);
84 GNUNET_CRYPTO_hash_xor (&m, in, hc); 81 GNUNET_CRYPTO_hash_xor (&m, in, hc);
85} 82}
86 83
@@ -106,39 +103,33 @@ GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
106 ctx->cfg = cfg; 103 ctx->cfg = cfg;
107 num_plugins = 0; 104 num_plugins = 0;
108 if (GNUNET_OK == 105 if (GNUNET_OK ==
109 GNUNET_CONFIGURATION_get_value_string (cfg, 106 GNUNET_CONFIGURATION_get_value_string (cfg, "block", "PLUGINS", &plugs))
110 "block", "PLUGINS", &plugs)) 107 {
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
109 _("Loading block plugins `%s'\n"), plugs);
110 pos = strtok (plugs, " ");
111 while (pos != NULL)
111 { 112 {
112 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 113 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
113 _("Loading block plugins `%s'\n"), plugs); 114 api = GNUNET_PLUGIN_load (libname, NULL);
114 pos = strtok (plugs, " "); 115 if (api == NULL)
115 while (pos != NULL) 116 {
116 { 117 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
117 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos); 118 _("Failed to load block plugin `%s'\n"), pos);
118 api = GNUNET_PLUGIN_load (libname, NULL); 119 GNUNET_free (libname);
119 if (api == NULL) 120 }
120 { 121 else
121 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 122 {
122 _("Failed to load block plugin `%s'\n"), 123 plugin = GNUNET_malloc (sizeof (struct Plugin));
123 pos); 124 plugin->api = api;
124 GNUNET_free (libname); 125 plugin->library_name = libname;
125 } 126 GNUNET_array_append (ctx->plugins, num_plugins, plugin);
126 else 127 }
127 { 128 pos = strtok (NULL, " ");
128 plugin = GNUNET_malloc (sizeof (struct Plugin));
129 plugin->api = api;
130 plugin->library_name = libname;
131 GNUNET_array_append (ctx->plugins,
132 num_plugins,
133 plugin);
134 }
135 pos = strtok (NULL, " ");
136 }
137 GNUNET_free (plugs);
138 } 129 }
139 GNUNET_array_append (ctx->plugins, 130 GNUNET_free (plugs);
140 num_plugins, 131 }
141 NULL); 132 GNUNET_array_append (ctx->plugins, num_plugins, NULL);
142 return ctx; 133 return ctx;
143} 134}
144 135
@@ -156,14 +147,13 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
156 147
157 i = 0; 148 i = 0;
158 while (NULL != (plugin = ctx->plugins[i])) 149 while (NULL != (plugin = ctx->plugins[i]))
159 { 150 {
160 GNUNET_break (NULL == 151 GNUNET_break (NULL ==
161 GNUNET_PLUGIN_unload (plugin->library_name, 152 GNUNET_PLUGIN_unload (plugin->library_name, plugin->api));
162 plugin->api)); 153 GNUNET_free (plugin->library_name);
163 GNUNET_free (plugin->library_name); 154 GNUNET_free (plugin);
164 GNUNET_free (plugin); 155 i++;
165 i++; 156 }
166 }
167 GNUNET_free (ctx->plugins); 157 GNUNET_free (ctx->plugins);
168 GNUNET_free (ctx); 158 GNUNET_free (ctx);
169} 159}
@@ -177,8 +167,7 @@ GNUNET_BLOCK_context_destroy (struct GNUNET_BLOCK_Context *ctx)
177 * @return NULL if no matching plugin exists 167 * @return NULL if no matching plugin exists
178 */ 168 */
179static struct GNUNET_BLOCK_PluginFunctions * 169static struct GNUNET_BLOCK_PluginFunctions *
180find_plugin (struct GNUNET_BLOCK_Context *ctx, 170find_plugin (struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type)
181 enum GNUNET_BLOCK_Type type)
182{ 171{
183 struct Plugin *plugin; 172 struct Plugin *plugin;
184 unsigned int i; 173 unsigned int i;
@@ -186,16 +175,16 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
186 175
187 i = 0; 176 i = 0;
188 while (NULL != (plugin = ctx->plugins[i])) 177 while (NULL != (plugin = ctx->plugins[i]))
178 {
179 j = 0;
180 while (0 != (plugin->api->types[j]))
189 { 181 {
190 j = 0; 182 if (type == plugin->api->types[j])
191 while (0 != (plugin->api->types[j])) 183 return plugin->api;
192 { 184 j++;
193 if (type == plugin->api->types[j])
194 return plugin->api;
195 j++;
196 }
197 i++;
198 } 185 }
186 i++;
187 }
199 return NULL; 188 return NULL;
200} 189}
201 190
@@ -220,22 +209,21 @@ find_plugin (struct GNUNET_BLOCK_Context *ctx,
220 */ 209 */
221enum GNUNET_BLOCK_EvaluationResult 210enum GNUNET_BLOCK_EvaluationResult
222GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx, 211GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
223 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
224 const GNUNET_HashCode *query, 213 const GNUNET_HashCode * query,
225 struct GNUNET_CONTAINER_BloomFilter **bf, 214 struct GNUNET_CONTAINER_BloomFilter **bf,
226 int32_t bf_mutator, 215 int32_t bf_mutator,
227 const void *xquery, 216 const void *xquery,
228 size_t xquery_size, 217 size_t xquery_size,
229 const void *reply_block, 218 const void *reply_block, size_t reply_block_size)
230 size_t reply_block_size)
231{ 219{
232 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 220 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
233 221
234 if (plugin == NULL) 222 if (plugin == NULL)
235 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 223 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
236 return plugin->evaluate (plugin->cls, 224 return plugin->evaluate (plugin->cls,
237 type, query, bf, bf_mutator, 225 type, query, bf, bf_mutator,
238 xquery, xquery_size, reply_block, reply_block_size); 226 xquery, xquery_size, reply_block, reply_block_size);
239} 227}
240 228
241 229
@@ -252,17 +240,15 @@ GNUNET_BLOCK_evaluate (struct GNUNET_BLOCK_Context *ctx,
252 */ 240 */
253int 241int
254GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx, 242GNUNET_BLOCK_get_key (struct GNUNET_BLOCK_Context *ctx,
255 enum GNUNET_BLOCK_Type type, 243 enum GNUNET_BLOCK_Type type,
256 const void *block, 244 const void *block,
257 size_t block_size, 245 size_t block_size, GNUNET_HashCode * key)
258 GNUNET_HashCode *key)
259{ 246{
260 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type); 247 struct GNUNET_BLOCK_PluginFunctions *plugin = find_plugin (ctx, type);
261 248
262 if (plugin == NULL) 249 if (plugin == NULL)
263 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 250 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
264 return plugin->get_key (plugin->cls, 251 return plugin->get_key (plugin->cls, type, block, block_size, key);
265 type, block, block_size, key);
266} 252}
267 253
268 254
diff --git a/src/block/plugin_block_dht.c b/src/block/plugin_block_dht.c
index 0e499b821..1fe51e1a3 100644
--- a/src/block/plugin_block_dht.c
+++ b/src/block/plugin_block_dht.c
@@ -50,14 +50,13 @@
50 */ 50 */
51static enum GNUNET_BLOCK_EvaluationResult 51static enum GNUNET_BLOCK_EvaluationResult
52block_plugin_dht_evaluate (void *cls, 52block_plugin_dht_evaluate (void *cls,
53 enum GNUNET_BLOCK_Type type, 53 enum GNUNET_BLOCK_Type type,
54 const GNUNET_HashCode *query, 54 const GNUNET_HashCode * query,
55 struct GNUNET_CONTAINER_BloomFilter **bf, 55 struct GNUNET_CONTAINER_BloomFilter **bf,
56 int32_t bf_mutator, 56 int32_t bf_mutator,
57 const void *xquery, 57 const void *xquery,
58 size_t xquery_size, 58 size_t xquery_size,
59 const void *reply_block, 59 const void *reply_block, size_t reply_block_size)
60 size_t reply_block_size)
61{ 60{
62 switch (type) 61 switch (type)
63 { 62 {
@@ -67,7 +66,7 @@ block_plugin_dht_evaluate (void *cls,
67 if (reply_block_size == 0) 66 if (reply_block_size == 0)
68 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 67 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
69 GNUNET_break (NULL == *bf); 68 GNUNET_break (NULL == *bf);
70 return GNUNET_BLOCK_EVALUATION_OK_LAST; 69 return GNUNET_BLOCK_EVALUATION_OK_LAST;
71 default: 70 default:
72 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 71 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
73 } 72 }
@@ -87,10 +86,9 @@ block_plugin_dht_evaluate (void *cls,
87 */ 86 */
88static int 87static int
89block_plugin_dht_get_key (void *cls, 88block_plugin_dht_get_key (void *cls,
90 enum GNUNET_BLOCK_Type type, 89 enum GNUNET_BLOCK_Type type,
91 const void *block, 90 const void *block,
92 size_t block_size, 91 size_t block_size, GNUNET_HashCode * key)
93 GNUNET_HashCode *key)
94{ 92{
95 const struct GNUNET_MessageHeader *msg; 93 const struct GNUNET_MessageHeader *msg;
96 const struct GNUNET_HELLO_Message *hello; 94 const struct GNUNET_HELLO_Message *hello;
@@ -99,37 +97,34 @@ block_plugin_dht_get_key (void *cls,
99 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 97 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
100 return GNUNET_SYSERR; 98 return GNUNET_SYSERR;
101 if (block_size < sizeof (struct GNUNET_MessageHeader)) 99 if (block_size < sizeof (struct GNUNET_MessageHeader))
102 { 100 {
103 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 101 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
104 "block-dht", 102 "block-dht",
105 _("Block not of type %u\n"), 103 _("Block not of type %u\n"), GNUNET_BLOCK_TYPE_DHT_HELLO);
106 GNUNET_BLOCK_TYPE_DHT_HELLO); 104 return GNUNET_NO;
107 return GNUNET_NO; 105 }
108 }
109 msg = block; 106 msg = block;
110 if (block_size != ntohs (msg->size)) 107 if (block_size != ntohs (msg->size))
111 { 108 {
112 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 109 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
113 "block-dht", 110 "block-dht",
114 _("Size mismatch for block\n"), 111 _("Size mismatch for block\n"),
115 GNUNET_BLOCK_TYPE_DHT_HELLO); 112 GNUNET_BLOCK_TYPE_DHT_HELLO);
116 return GNUNET_NO; 113 return GNUNET_NO;
117 } 114 }
118 hello = block; 115 hello = block;
119 pid = (struct GNUNET_PeerIdentity*) key; 116 pid = (struct GNUNET_PeerIdentity *) key;
120 if (GNUNET_OK != 117 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
121 GNUNET_HELLO_get_id (hello, 118 {
122 pid)) 119 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
123 { 120 "block-dht",
124 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 121 _("Block of type %u is malformed\n"),
125 "block-dht", 122 GNUNET_BLOCK_TYPE_DHT_HELLO);
126 _("Block of type %u is malformed\n"), 123 return GNUNET_NO;
127 GNUNET_BLOCK_TYPE_DHT_HELLO); 124 }
128 return GNUNET_NO;
129 }
130 return GNUNET_OK; 125 return GNUNET_OK;
131} 126}
132 127
133 128
134/** 129/**
135 * Entry point for the plugin. 130 * Entry point for the plugin.
@@ -137,11 +132,11 @@ block_plugin_dht_get_key (void *cls,
137void * 132void *
138libgnunet_plugin_block_dht_init (void *cls) 133libgnunet_plugin_block_dht_init (void *cls)
139{ 134{
140 static enum GNUNET_BLOCK_Type types[] = 135 static enum GNUNET_BLOCK_Type types[] =
141 { 136 {
142 GNUNET_BLOCK_TYPE_DHT_HELLO, 137 GNUNET_BLOCK_TYPE_DHT_HELLO,
143 GNUNET_BLOCK_TYPE_ANY /* end of list */ 138 GNUNET_BLOCK_TYPE_ANY /* end of list */
144 }; 139 };
145 struct GNUNET_BLOCK_PluginFunctions *api; 140 struct GNUNET_BLOCK_PluginFunctions *api;
146 141
147 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 142 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_dns.c b/src/block/plugin_block_dns.c
index 681a659ae..0cf8c50e9 100644
--- a/src/block/plugin_block_dns.c
+++ b/src/block/plugin_block_dns.c
@@ -48,14 +48,13 @@
48 */ 48 */
49static enum GNUNET_BLOCK_EvaluationResult 49static enum GNUNET_BLOCK_EvaluationResult
50block_plugin_dns_evaluate (void *cls, 50block_plugin_dns_evaluate (void *cls,
51 enum GNUNET_BLOCK_Type type, 51 enum GNUNET_BLOCK_Type type,
52 const GNUNET_HashCode *query, 52 const GNUNET_HashCode * query,
53 struct GNUNET_CONTAINER_BloomFilter **bf, 53 struct GNUNET_CONTAINER_BloomFilter **bf,
54 int32_t bf_mutator, 54 int32_t bf_mutator,
55 const void *xquery, 55 const void *xquery,
56 size_t xquery_size, 56 size_t xquery_size,
57 const void *reply_block, 57 const void *reply_block, size_t reply_block_size)
58 size_t reply_block_size)
59{ 58{
60 switch (type) 59 switch (type)
61 { 60 {
@@ -66,37 +65,43 @@ block_plugin_dns_evaluate (void *cls,
66 if (reply_block_size == 0) 65 if (reply_block_size == 0)
67 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 66 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
68 67
69 if (reply_block_size != sizeof(struct GNUNET_DNS_Record)) 68 if (reply_block_size != sizeof (struct GNUNET_DNS_Record))
70 { 69 {
71 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: reply_block_size=%d != %d\n", reply_block_size, sizeof(struct GNUNET_DNS_Record)); 70 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
72 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 71 "DNS-Block is invalid: reply_block_size=%d != %d\n",
73 } 72 reply_block_size, sizeof (struct GNUNET_DNS_Record));
74 73 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
75 const struct GNUNET_DNS_Record* rec = reply_block; 74 }
76 75
77 if (ntohl(rec->purpose.size) != sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature)) 76 const struct GNUNET_DNS_Record *rec = reply_block;
78 { 77
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 78 if (ntohl (rec->purpose.size) !=
80 "DNS-Block is invalid: rec->purpose.size=%d != %d\n", 79 sizeof (struct GNUNET_DNS_Record) -
81 ntohl(rec->purpose.size), 80 sizeof (struct GNUNET_CRYPTO_RsaSignature))
82 sizeof(struct GNUNET_DNS_Record) - sizeof(struct GNUNET_CRYPTO_RsaSignature)); 81 {
83 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 } 83 "DNS-Block is invalid: rec->purpose.size=%d != %d\n",
85 84 ntohl (rec->purpose.size),
86 if (GNUNET_TIME_relative_get_zero().rel_value == GNUNET_TIME_absolute_get_remaining(rec->expiration_time).rel_value) 85 sizeof (struct GNUNET_DNS_Record) -
87 { 86 sizeof (struct GNUNET_CRYPTO_RsaSignature));
88 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n"); 87 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
89 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 88 }
90 } 89
91 90 if (GNUNET_TIME_relative_get_zero ().rel_value ==
92 if (GNUNET_OK != GNUNET_CRYPTO_rsa_verify (htonl(GNUNET_SIGNATURE_PURPOSE_DNS_RECORD), 91 GNUNET_TIME_absolute_get_remaining (rec->expiration_time).rel_value)
93 &rec->purpose, 92 {
94 &rec->signature, 93 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: Timeout\n");
95 &rec->peer)) 94 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
96 { 95 }
97 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DNS-Block is invalid: invalid signature\n"); 96
98 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 97 if (GNUNET_OK !=
99 } 98 GNUNET_CRYPTO_rsa_verify (htonl (GNUNET_SIGNATURE_PURPOSE_DNS_RECORD),
99 &rec->purpose, &rec->signature, &rec->peer))
100 {
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
102 "DNS-Block is invalid: invalid signature\n");
103 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
104 }
100 105
101 /* How to decide whether there are no more? */ 106 /* How to decide whether there are no more? */
102 return GNUNET_BLOCK_EVALUATION_OK_MORE; 107 return GNUNET_BLOCK_EVALUATION_OK_MORE;
@@ -119,15 +124,15 @@ block_plugin_dns_evaluate (void *cls,
119 */ 124 */
120static int 125static int
121block_plugin_dns_get_key (void *cls, 126block_plugin_dns_get_key (void *cls,
122 enum GNUNET_BLOCK_Type type, 127 enum GNUNET_BLOCK_Type type,
123 const void *block, 128 const void *block,
124 size_t block_size, 129 size_t block_size, GNUNET_HashCode * key)
125 GNUNET_HashCode *key)
126{ 130{
127 if (type != GNUNET_BLOCK_TYPE_DNS) 131 if (type != GNUNET_BLOCK_TYPE_DNS)
128 return GNUNET_SYSERR; 132 return GNUNET_SYSERR;
129 const struct GNUNET_DNS_Record* rec = block; 133 const struct GNUNET_DNS_Record *rec = block;
130 memcpy(key, &rec->service_descriptor, sizeof(GNUNET_HashCode)); 134
135 memcpy (key, &rec->service_descriptor, sizeof (GNUNET_HashCode));
131 return GNUNET_OK; 136 return GNUNET_OK;
132} 137}
133 138
@@ -137,11 +142,11 @@ block_plugin_dns_get_key (void *cls,
137void * 142void *
138libgnunet_plugin_block_dns_init (void *cls) 143libgnunet_plugin_block_dns_init (void *cls)
139{ 144{
140 static enum GNUNET_BLOCK_Type types[] = 145 static enum GNUNET_BLOCK_Type types[] =
141 { 146 {
142 GNUNET_BLOCK_TYPE_DNS, 147 GNUNET_BLOCK_TYPE_DNS,
143 GNUNET_BLOCK_TYPE_ANY /* end of list */ 148 GNUNET_BLOCK_TYPE_ANY /* end of list */
144 }; 149 };
145 struct GNUNET_BLOCK_PluginFunctions *api; 150 struct GNUNET_BLOCK_PluginFunctions *api;
146 151
147 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 152 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
index caf009ddf..db8e59991 100644
--- a/src/block/plugin_block_fs.c
+++ b/src/block/plugin_block_fs.c
@@ -57,14 +57,13 @@
57 */ 57 */
58static enum GNUNET_BLOCK_EvaluationResult 58static enum GNUNET_BLOCK_EvaluationResult
59block_plugin_fs_evaluate (void *cls, 59block_plugin_fs_evaluate (void *cls,
60 enum GNUNET_BLOCK_Type type, 60 enum GNUNET_BLOCK_Type type,
61 const GNUNET_HashCode *query, 61 const GNUNET_HashCode * query,
62 struct GNUNET_CONTAINER_BloomFilter **bf, 62 struct GNUNET_CONTAINER_BloomFilter **bf,
63 int32_t bf_mutator, 63 int32_t bf_mutator,
64 const void *xquery, 64 const void *xquery,
65 size_t xquery_size, 65 size_t xquery_size,
66 const void *reply_block, 66 const void *reply_block, size_t reply_block_size)
67 size_t reply_block_size)
68{ 67{
69 const struct SBlock *sb; 68 const struct SBlock *sb;
70 GNUNET_HashCode chash; 69 GNUNET_HashCode chash;
@@ -73,92 +72,81 @@ block_plugin_fs_evaluate (void *cls,
73 GNUNET_HashCode sh; 72 GNUNET_HashCode sh;
74 73
75 switch (type) 74 switch (type)
75 {
76 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
77 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
78 if (xquery_size != 0)
76 { 79 {
77 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 80 GNUNET_break_op (0);
78 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 81 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
79 if (xquery_size != 0)
80 {
81 GNUNET_break_op (0);
82 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
83 }
84 if (reply_block == NULL)
85 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
86 return GNUNET_BLOCK_EVALUATION_OK_LAST;
87 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
88 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
89 if (xquery_size != 0)
90 {
91 GNUNET_break_op (0);
92 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
93 }
94 if (reply_block == NULL)
95 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
96 GNUNET_CRYPTO_hash (reply_block,
97 reply_block_size,
98 &chash);
99 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
100 if (NULL != *bf)
101 {
102 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
103 &mhash))
104 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
105 }
106 else
107 {
108 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
109 8,
110 BLOOMFILTER_K);
111 }
112 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
113 return GNUNET_BLOCK_EVALUATION_OK_MORE;
114 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
115 if (xquery_size != sizeof (GNUNET_HashCode))
116 {
117 GNUNET_break_op (0);
118 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
119 }
120 if (reply_block == NULL)
121 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
122 nsid = xquery;
123 if (reply_block_size < sizeof (struct SBlock))
124 {
125 GNUNET_break_op (0);
126 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
127 }
128 sb = reply_block;
129 GNUNET_CRYPTO_hash (&sb->subspace,
130 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
131 &sh);
132 if (0 != memcmp (nsid,
133 &sh,
134 sizeof (GNUNET_HashCode)))
135 {
136 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
137 "block-fs",
138 _("Reply mismatched in terms of namespace. Discarded.\n"));
139 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
140 }
141 GNUNET_CRYPTO_hash (reply_block,
142 reply_block_size,
143 &chash);
144 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
145 if (NULL != *bf)
146 {
147 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf,
148 &mhash))
149 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
150 }
151 else
152 {
153 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL,
154 8,
155 BLOOMFILTER_K);
156 }
157 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
158 return GNUNET_BLOCK_EVALUATION_OK_MORE;
159 default:
160 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
161 } 82 }
83 if (reply_block == NULL)
84 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
85 return GNUNET_BLOCK_EVALUATION_OK_LAST;
86 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
87 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
88 if (xquery_size != 0)
89 {
90 GNUNET_break_op (0);
91 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
92 }
93 if (reply_block == NULL)
94 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
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 return GNUNET_BLOCK_EVALUATION_OK_MORE;
108 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
109 if (xquery_size != sizeof (GNUNET_HashCode))
110 {
111 GNUNET_break_op (0);
112 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
113 }
114 if (reply_block == NULL)
115 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
116 nsid = xquery;
117 if (reply_block_size < sizeof (struct SBlock))
118 {
119 GNUNET_break_op (0);
120 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
121 }
122 sb = reply_block;
123 GNUNET_CRYPTO_hash (&sb->subspace,
124 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
125 &sh);
126 if (0 != memcmp (nsid, &sh, sizeof (GNUNET_HashCode)))
127 {
128 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
129 "block-fs",
130 _
131 ("Reply mismatched in terms of namespace. Discarded.\n"));
132 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
133 }
134 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
135 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
136 if (NULL != *bf)
137 {
138 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
139 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
140 }
141 else
142 {
143 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
144 }
145 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
146 return GNUNET_BLOCK_EVALUATION_OK_MORE;
147 default:
148 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
149 }
162} 150}
163 151
164 152
@@ -175,126 +163,122 @@ block_plugin_fs_evaluate (void *cls,
175 */ 163 */
176static int 164static int
177block_plugin_fs_get_key (void *cls, 165block_plugin_fs_get_key (void *cls,
178 enum GNUNET_BLOCK_Type type, 166 enum GNUNET_BLOCK_Type type,
179 const void *block, 167 const void *block,
180 size_t block_size, 168 size_t block_size, GNUNET_HashCode * key)
181 GNUNET_HashCode *key)
182{ 169{
183 const struct KBlock *kb; 170 const struct KBlock *kb;
184 const struct SBlock *sb; 171 const struct SBlock *sb;
185 const struct NBlock *nb; 172 const struct NBlock *nb;
186 173
187 switch (type) 174 switch (type)
175 {
176 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
177 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
178 GNUNET_CRYPTO_hash (block, block_size, key);
179 return GNUNET_OK;
180 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
181 if (block_size < sizeof (struct KBlock))
182 {
183 GNUNET_break_op (0);
184 return GNUNET_NO;
185 }
186 kb = block;
187 if (block_size - sizeof (struct KBlock) !=
188 ntohl (kb->purpose.size)
189 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
190 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
191 {
192 GNUNET_break_op (0);
193 return GNUNET_NO;
194 }
195 if (GNUNET_OK !=
196 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
197 &kb->purpose, &kb->signature, &kb->keyspace))
198 {
199 GNUNET_break_op (0);
200 return GNUNET_NO;
201 }
202 if (key != NULL)
203 GNUNET_CRYPTO_hash (&kb->keyspace,
204 sizeof (struct
205 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
206 key);
207 return GNUNET_OK;
208 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
209 if (block_size < sizeof (struct SBlock))
210 {
211 GNUNET_break_op (0);
212 return GNUNET_NO;
213 }
214 sb = block;
215 if (block_size !=
216 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
188 { 217 {
189 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 218 GNUNET_break_op (0);
190 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 219 return GNUNET_NO;
191 GNUNET_CRYPTO_hash (block, block_size, key);
192 return GNUNET_OK;
193 case GNUNET_BLOCK_TYPE_FS_KBLOCK:
194 if (block_size < sizeof (struct KBlock))
195 {
196 GNUNET_break_op (0);
197 return GNUNET_NO;
198 }
199 kb = block;
200 if (block_size - sizeof (struct KBlock) !=
201 ntohl (kb->purpose.size)
202 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
203 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
204 {
205 GNUNET_break_op (0);
206 return GNUNET_NO;
207 }
208 if (GNUNET_OK !=
209 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
210 &kb->purpose,
211 &kb->signature,
212 &kb->keyspace))
213 {
214 GNUNET_break_op (0);
215 return GNUNET_NO;
216 }
217 if (key != NULL)
218 GNUNET_CRYPTO_hash (&kb->keyspace,
219 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
220 key);
221 return GNUNET_OK;
222 case GNUNET_BLOCK_TYPE_FS_SBLOCK:
223 if (block_size < sizeof (struct SBlock))
224 {
225 GNUNET_break_op (0);
226 return GNUNET_NO;
227 }
228 sb = block;
229 if (block_size !=
230 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
231 {
232 GNUNET_break_op (0);
233 return GNUNET_NO;
234 }
235 if (GNUNET_OK !=
236 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
237 &sb->purpose,
238 &sb->signature,
239 &sb->subspace))
240 {
241 GNUNET_break_op (0);
242 return GNUNET_NO;
243 }
244 if (key != NULL)
245 *key = sb->identifier;
246 return GNUNET_OK;
247 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
248 if (block_size < sizeof (struct NBlock))
249 {
250 GNUNET_break_op (0);
251 return GNUNET_NO;
252 }
253 nb = block;
254 if (block_size - sizeof (struct NBlock) !=
255 ntohl (nb->ns_purpose.size)
256 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
257 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
258 {
259 GNUNET_break_op (0);
260 return GNUNET_NO;
261 }
262 if (block_size !=
263 ntohl (nb->ksk_purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
264 {
265 GNUNET_break_op (0);
266 return GNUNET_NO;
267 }
268 if (GNUNET_OK !=
269 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
270 &nb->ksk_purpose,
271 &nb->ksk_signature,
272 &nb->keyspace))
273 {
274 GNUNET_break_op (0);
275 return GNUNET_NO;
276 }
277 if (GNUNET_OK !=
278 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
279 &nb->ns_purpose,
280 &nb->ns_signature,
281 &nb->subspace))
282 {
283 GNUNET_break_op (0);
284 return GNUNET_NO;
285 }
286 /* FIXME: we used to xor ID with NSID,
287 why not here? */
288 if (key != NULL)
289 GNUNET_CRYPTO_hash (&nb->keyspace,
290 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
291 key);
292 return GNUNET_OK;
293 default:
294 return GNUNET_SYSERR;
295 } 220 }
221 if (GNUNET_OK !=
222 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
223 &sb->purpose, &sb->signature, &sb->subspace))
224 {
225 GNUNET_break_op (0);
226 return GNUNET_NO;
227 }
228 if (key != NULL)
229 *key = sb->identifier;
230 return GNUNET_OK;
231 case GNUNET_BLOCK_TYPE_FS_NBLOCK:
232 if (block_size < sizeof (struct NBlock))
233 {
234 GNUNET_break_op (0);
235 return GNUNET_NO;
236 }
237 nb = block;
238 if (block_size - sizeof (struct NBlock) !=
239 ntohl (nb->ns_purpose.size)
240 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
241 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))
242 {
243 GNUNET_break_op (0);
244 return GNUNET_NO;
245 }
246 if (block_size !=
247 ntohl (nb->ksk_purpose.size) +
248 sizeof (struct GNUNET_CRYPTO_RsaSignature))
249 {
250 GNUNET_break_op (0);
251 return GNUNET_NO;
252 }
253 if (GNUNET_OK !=
254 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
255 &nb->ksk_purpose,
256 &nb->ksk_signature, &nb->keyspace))
257 {
258 GNUNET_break_op (0);
259 return GNUNET_NO;
260 }
261 if (GNUNET_OK !=
262 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
263 &nb->ns_purpose,
264 &nb->ns_signature, &nb->subspace))
265 {
266 GNUNET_break_op (0);
267 return GNUNET_NO;
268 }
269 /* FIXME: we used to xor ID with NSID,
270 * why not here? */
271 if (key != NULL)
272 GNUNET_CRYPTO_hash (&nb->keyspace,
273 sizeof (struct
274 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
275 key);
276 return GNUNET_OK;
277 default:
278 return GNUNET_SYSERR;
279 }
296} 280}
297 281
298 282
299/** 283/**
300 * Entry point for the plugin. 284 * Entry point for the plugin.
@@ -302,15 +286,15 @@ block_plugin_fs_get_key (void *cls,
302void * 286void *
303libgnunet_plugin_block_fs_init (void *cls) 287libgnunet_plugin_block_fs_init (void *cls)
304{ 288{
305 static enum GNUNET_BLOCK_Type types[] = 289 static enum GNUNET_BLOCK_Type types[] =
306 { 290 {
307 GNUNET_BLOCK_TYPE_FS_DBLOCK, 291 GNUNET_BLOCK_TYPE_FS_DBLOCK,
308 GNUNET_BLOCK_TYPE_FS_IBLOCK, 292 GNUNET_BLOCK_TYPE_FS_IBLOCK,
309 GNUNET_BLOCK_TYPE_FS_KBLOCK, 293 GNUNET_BLOCK_TYPE_FS_KBLOCK,
310 GNUNET_BLOCK_TYPE_FS_SBLOCK, 294 GNUNET_BLOCK_TYPE_FS_SBLOCK,
311 GNUNET_BLOCK_TYPE_FS_NBLOCK, 295 GNUNET_BLOCK_TYPE_FS_NBLOCK,
312 GNUNET_BLOCK_TYPE_ANY /* end of list */ 296 GNUNET_BLOCK_TYPE_ANY /* end of list */
313 }; 297 };
314 struct GNUNET_BLOCK_PluginFunctions *api; 298 struct GNUNET_BLOCK_PluginFunctions *api;
315 299
316 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 300 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_template.c b/src/block/plugin_block_template.c
index 77e7c0ab9..9eb84ac4b 100644
--- a/src/block/plugin_block_template.c
+++ b/src/block/plugin_block_template.c
@@ -47,14 +47,14 @@
47 */ 47 */
48static enum GNUNET_BLOCK_EvaluationResult 48static enum GNUNET_BLOCK_EvaluationResult
49block_plugin_template_evaluate (void *cls, 49block_plugin_template_evaluate (void *cls,
50 enum GNUNET_BLOCK_Type type, 50 enum GNUNET_BLOCK_Type type,
51 const GNUNET_HashCode *query, 51 const GNUNET_HashCode * query,
52 struct GNUNET_CONTAINER_BloomFilter **bf, 52 struct GNUNET_CONTAINER_BloomFilter **bf,
53 int32_t bf_mutator, 53 int32_t bf_mutator,
54 const void *xquery, 54 const void *xquery,
55 size_t xquery_size, 55 size_t xquery_size,
56 const void *reply_block, 56 const void *reply_block,
57 size_t reply_block_size) 57 size_t reply_block_size)
58{ 58{
59 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 59 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
60} 60}
@@ -73,14 +73,13 @@ block_plugin_template_evaluate (void *cls,
73 */ 73 */
74static int 74static int
75block_plugin_template_get_key (void *cls, 75block_plugin_template_get_key (void *cls,
76 enum GNUNET_BLOCK_Type type, 76 enum GNUNET_BLOCK_Type type,
77 const void *block, 77 const void *block,
78 size_t block_size, 78 size_t block_size, GNUNET_HashCode * key)
79 GNUNET_HashCode *key)
80{ 79{
81 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
82} 81}
83 82
84 83
85/** 84/**
86 * Entry point for the plugin. 85 * Entry point for the plugin.
@@ -88,11 +87,11 @@ block_plugin_template_get_key (void *cls,
88void * 87void *
89libgnunet_plugin_block_template_init (void *cls) 88libgnunet_plugin_block_template_init (void *cls)
90{ 89{
91 static enum GNUNET_BLOCK_Type types[] = 90 static enum GNUNET_BLOCK_Type types[] =
92 { 91 {
93 /* FIXME: insert supported block types here */ 92 /* FIXME: insert supported block types here */
94 GNUNET_BLOCK_TYPE_ANY /* end of list */ 93 GNUNET_BLOCK_TYPE_ANY /* end of list */
95 }; 94 };
96 struct GNUNET_BLOCK_PluginFunctions *api; 95 struct GNUNET_BLOCK_PluginFunctions *api;
97 96
98 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 97 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/plugin_block_test.c b/src/block/plugin_block_test.c
index 639a5c46e..b5c03eea9 100644
--- a/src/block/plugin_block_test.c
+++ b/src/block/plugin_block_test.c
@@ -54,42 +54,36 @@
54 */ 54 */
55static enum GNUNET_BLOCK_EvaluationResult 55static enum GNUNET_BLOCK_EvaluationResult
56block_plugin_test_evaluate (void *cls, 56block_plugin_test_evaluate (void *cls,
57 enum GNUNET_BLOCK_Type type, 57 enum GNUNET_BLOCK_Type type,
58 const GNUNET_HashCode *query, 58 const GNUNET_HashCode * query,
59 struct GNUNET_CONTAINER_BloomFilter **bf, 59 struct GNUNET_CONTAINER_BloomFilter **bf,
60 int32_t bf_mutator, 60 int32_t bf_mutator,
61 const void *xquery, 61 const void *xquery,
62 size_t xquery_size, 62 size_t xquery_size,
63 const void *reply_block, 63 const void *reply_block, size_t reply_block_size)
64 size_t reply_block_size)
65{ 64{
66 GNUNET_HashCode chash; 65 GNUNET_HashCode chash;
67 GNUNET_HashCode mhash; 66 GNUNET_HashCode mhash;
68 67
69 if (type != GNUNET_BLOCK_TYPE_TEST) 68 if (type != GNUNET_BLOCK_TYPE_TEST)
70 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 69 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
71 if (xquery_size != 0) 70 if (xquery_size != 0)
72 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 71 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
73 if (reply_block_size == 0) 72 if (reply_block_size == 0)
74 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 73 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
75 74
76 GNUNET_CRYPTO_hash (reply_block, 75 GNUNET_CRYPTO_hash (reply_block, reply_block_size, &chash);
77 reply_block_size,
78 &chash);
79 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash); 76 GNUNET_BLOCK_mingle_hash (&chash, bf_mutator, &mhash);
80 if (NULL != *bf) 77 if (NULL != *bf)
81 { 78 {
82 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, 79 if (GNUNET_YES == GNUNET_CONTAINER_bloomfilter_test (*bf, &mhash))
83 &mhash)) 80 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
84 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; 81 }
85 }
86 else 82 else
87 { 83 {
88 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 84 *bf = GNUNET_CONTAINER_bloomfilter_init (NULL, 8, BLOOMFILTER_K);
89 8, 85 }
90 BLOOMFILTER_K); 86 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
91 }
92 GNUNET_CONTAINER_bloomfilter_add (*bf, &mhash);
93 return GNUNET_BLOCK_EVALUATION_OK_MORE; 87 return GNUNET_BLOCK_EVALUATION_OK_MORE;
94} 88}
95 89
@@ -107,16 +101,15 @@ block_plugin_test_evaluate (void *cls,
107 */ 101 */
108static int 102static int
109block_plugin_test_get_key (void *cls, 103block_plugin_test_get_key (void *cls,
110 enum GNUNET_BLOCK_Type type, 104 enum GNUNET_BLOCK_Type type,
111 const void *block, 105 const void *block,
112 size_t block_size, 106 size_t block_size, GNUNET_HashCode * key)
113 GNUNET_HashCode *key)
114{ 107{
115 /* always fails since there is no fixed relationship between 108 /* always fails since there is no fixed relationship between
116 keys and values for test values */ 109 * keys and values for test values */
117 return GNUNET_SYSERR; 110 return GNUNET_SYSERR;
118} 111}
119 112
120 113
121/** 114/**
122 * Entry point for the plugin. 115 * Entry point for the plugin.
@@ -124,11 +117,11 @@ block_plugin_test_get_key (void *cls,
124void * 117void *
125libgnunet_plugin_block_test_init (void *cls) 118libgnunet_plugin_block_test_init (void *cls)
126{ 119{
127 static enum GNUNET_BLOCK_Type types[] = 120 static enum GNUNET_BLOCK_Type types[] =
128 { 121 {
129 GNUNET_BLOCK_TYPE_TEST, 122 GNUNET_BLOCK_TYPE_TEST,
130 GNUNET_BLOCK_TYPE_ANY /* end of list */ 123 GNUNET_BLOCK_TYPE_ANY /* end of list */
131 }; 124 };
132 struct GNUNET_BLOCK_PluginFunctions *api; 125 struct GNUNET_BLOCK_PluginFunctions *api;
133 126
134 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions)); 127 api = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_PluginFunctions));
diff --git a/src/block/test_block.c b/src/block/test_block.c
index bb9a1f01b..4bfd63ceb 100644
--- a/src/block/test_block.c
+++ b/src/block/test_block.c
@@ -38,35 +38,24 @@ test_fs (struct GNUNET_BLOCK_Context *ctx)
38 memset (block, 1, sizeof (block)); 38 memset (block, 1, sizeof (block));
39 if (GNUNET_OK != 39 if (GNUNET_OK !=
40 GNUNET_BLOCK_get_key (ctx, 40 GNUNET_BLOCK_get_key (ctx,
41 GNUNET_BLOCK_TYPE_FS_DBLOCK, 41 GNUNET_BLOCK_TYPE_FS_DBLOCK,
42 block, 42 block, sizeof (block), &key))
43 sizeof (block),
44 &key))
45 return 1; 43 return 1;
46 if (GNUNET_BLOCK_EVALUATION_OK_LAST != 44 if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
47 GNUNET_BLOCK_evaluate (ctx, 45 GNUNET_BLOCK_evaluate (ctx,
48 GNUNET_BLOCK_TYPE_FS_DBLOCK, 46 GNUNET_BLOCK_TYPE_FS_DBLOCK,
49 &key, 47 &key, NULL, 0, NULL, 0, block, sizeof (block)))
50 NULL, 0,
51 NULL, 0,
52 block, sizeof (block)))
53 return 2; 48 return 2;
54 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID != 49 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
55 GNUNET_BLOCK_evaluate (ctx, 50 GNUNET_BLOCK_evaluate (ctx,
56 GNUNET_BLOCK_TYPE_FS_DBLOCK, 51 GNUNET_BLOCK_TYPE_FS_DBLOCK,
57 &key, 52 &key, NULL, 0, NULL, 0, NULL, 0))
58 NULL, 0,
59 NULL, 0,
60 NULL, 0))
61 return 4; 53 return 4;
62 GNUNET_log_skip (1, GNUNET_NO); 54 GNUNET_log_skip (1, GNUNET_NO);
63 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID != 55 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
64 GNUNET_BLOCK_evaluate (ctx, 56 GNUNET_BLOCK_evaluate (ctx,
65 GNUNET_BLOCK_TYPE_FS_DBLOCK, 57 GNUNET_BLOCK_TYPE_FS_DBLOCK,
66 &key, 58 &key, NULL, 0, "bogus", 5, NULL, 0))
67 NULL, 0,
68 "bogus", 5,
69 NULL, 0))
70 return 8; 59 return 8;
71 GNUNET_log_skip (0, GNUNET_YES); 60 GNUNET_log_skip (0, GNUNET_YES);
72 return 0; 61 return 0;
@@ -81,10 +70,7 @@ main (int argc, char *argv[])
81 70
82 GNUNET_log_setup ("test-block", "WARNING", NULL); 71 GNUNET_log_setup ("test-block", "WARNING", NULL);
83 cfg = GNUNET_CONFIGURATION_create (); 72 cfg = GNUNET_CONFIGURATION_create ();
84 GNUNET_CONFIGURATION_set_value_string (cfg, 73 GNUNET_CONFIGURATION_set_value_string (cfg, "block", "PLUGINS", "fs");
85 "block",
86 "PLUGINS",
87 "fs");
88 ctx = GNUNET_BLOCK_context_create (cfg); 74 ctx = GNUNET_BLOCK_context_create (cfg);
89 ret = test_fs (ctx); 75 ret = test_fs (ctx);
90 GNUNET_BLOCK_context_destroy (ctx); 76 GNUNET_BLOCK_context_destroy (ctx);