aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-09-13 03:18:26 +0000
committerChristian Grothoff <christian@grothoff.org>2010-09-13 03:18:26 +0000
commit2e9791b5b713120238ea95113537fa55ff49b95d (patch)
tree98c0c6e0171109e7e4403fc50b6cae03a5c26c15
parenta42b4e0ed22b65631caea4bb456f3d8fc21f11b1 (diff)
downloadgnunet-2e9791b5b713120238ea95113537fa55ff49b95d.tar.gz
gnunet-2e9791b5b713120238ea95113537fa55ff49b95d.zip
new block lib
-rw-r--r--TODO9
-rw-r--r--contrib/defaults.conf3
-rw-r--r--src/block/block.c236
-rw-r--r--src/block/plugin_block_fs.c7
-rw-r--r--src/block/test_block.c61
-rw-r--r--src/fs/fs.h1
-rw-r--r--src/fs/gnunet-service-fs.c56
-rw-r--r--src/include/Makefile.am3
-rw-r--r--src/include/block_fs.h165
-rw-r--r--src/include/gnunet_block_lib.h156
-rw-r--r--src/util/test_time.c12
11 files changed, 327 insertions, 382 deletions
diff --git a/TODO b/TODO
index 9349189b3..e95522d87 100644
--- a/TODO
+++ b/TODO
@@ -1,14 +1,11 @@
10.9.0pre2: 10.9.0pre2:
2* BLOCK: 2 FS:
3 - implement FS plugin
4 - design new block-lib API
5 - move FS serivce to new block API 3 - move FS serivce to new block API
6* FS:
7 - integrate with DHT 4 - integrate with DHT
8 - measure latencies (core, datastore) => trust economy 5 - measure latencies (core, datastore) => trust economy
9 - refuse content migration message (or solicit?) 6 - refuse content migration message (or solicit?)
10 - FS performance benchmarking 7 - FS performance benchmarking
11* DHT: 8* DHT: [Nate]
12 - use new block lib 9 - use new block lib
13* CORE: 10* CORE:
14 - derived key generation [Nils] 11 - derived key generation [Nils]
@@ -101,6 +98,8 @@
101 - good to have for DHT evaluation! 98 - good to have for DHT evaluation!
102* DHT: [Nate] 99* DHT: [Nate]
103 - performance tests 100 - performance tests
101* BLOCK:
102 - more testing (KBlock, SBlock, NBlock)
104 103
1050.9.1: 1040.9.1:
106* TRANSPORT: [MW] 105* TRANSPORT: [MW]
diff --git a/contrib/defaults.conf b/contrib/defaults.conf
index 73f303b3f..f936386f8 100644
--- a/contrib/defaults.conf
+++ b/contrib/defaults.conf
@@ -261,3 +261,6 @@ UNIXPATH = /tmp/gnunet-service-dht.sock
261# REJECT_FROM = 261# REJECT_FROM =
262# REJECT_FROM6 = 262# REJECT_FROM6 =
263# PREFIX = 263# PREFIX =
264
265[block]
266PLUGINS = fs
diff --git a/src/block/block.c b/src/block/block.c
index cb6837499..8d8018b50 100644
--- a/src/block/block.c
+++ b/src/block/block.c
@@ -29,205 +29,6 @@
29#include "gnunet_block_lib.h" 29#include "gnunet_block_lib.h"
30#include "plugin_block.h" 30#include "plugin_block.h"
31 31
32/**
33 * Check if the given KBlock is well-formed.
34 *
35 * @param kb the kblock data (or at least "dsize" bytes claiming to be one)
36 * @param dsize size of "kb" in bytes; check for < sizeof(struct KBlock)!
37 * @param query where to store the query that this block answers
38 * @return GNUNET_OK if this is actually a well-formed KBlock
39 */
40static int
41check_kblock (const struct KBlock *kb,
42 size_t dsize,
43 GNUNET_HashCode *query)
44{
45 if (dsize < sizeof (struct KBlock))
46 {
47 GNUNET_break_op (0);
48 return GNUNET_SYSERR;
49 }
50 if (dsize - sizeof (struct KBlock) !=
51 ntohl (kb->purpose.size)
52 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
53 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
54 {
55 GNUNET_break_op (0);
56 return GNUNET_SYSERR;
57 }
58 if (GNUNET_OK !=
59 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_KBLOCK,
60 &kb->purpose,
61 &kb->signature,
62 &kb->keyspace))
63 {
64 GNUNET_break_op (0);
65 return GNUNET_SYSERR;
66 }
67 if (query != NULL)
68 GNUNET_CRYPTO_hash (&kb->keyspace,
69 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
70 query);
71 return GNUNET_OK;
72}
73
74
75/**
76 * Check if the given NBlock is well-formed.
77 *
78 * @param nb the nblock data (or at least "dsize" bytes claiming to be one)
79 * @param dsize size of "nb" in bytes; check for < sizeof(struct NBlock)!
80 * @param query where to store the query that this block answers
81 * @return GNUNET_OK if this is actually a well-formed NBlock
82 */
83static int
84check_nblock (const struct NBlock *nb,
85 size_t dsize,
86 GNUNET_HashCode *query)
87{
88 if (dsize < sizeof (struct NBlock))
89 {
90 GNUNET_break_op (0);
91 return GNUNET_SYSERR;
92 }
93 if (dsize - sizeof (struct NBlock) !=
94 ntohl (nb->ns_purpose.size)
95 - sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose)
96 - sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) )
97 {
98 GNUNET_break_op (0);
99 return GNUNET_SYSERR;
100 }
101 if (dsize !=
102 ntohl (nb->ksk_purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
103 {
104 GNUNET_break_op (0);
105 return GNUNET_SYSERR;
106 }
107 if (GNUNET_OK !=
108 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK_KSIG,
109 &nb->ksk_purpose,
110 &nb->ksk_signature,
111 &nb->keyspace))
112 {
113 GNUNET_break_op (0);
114 return GNUNET_SYSERR;
115 }
116 if (GNUNET_OK !=
117 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_NBLOCK,
118 &nb->ns_purpose,
119 &nb->ns_signature,
120 &nb->subspace))
121 {
122 GNUNET_break_op (0);
123 return GNUNET_SYSERR;
124 }
125 if (query != NULL)
126 GNUNET_CRYPTO_hash (&nb->keyspace,
127 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
128 query);
129 return GNUNET_OK;
130}
131
132
133/**
134 * Check if the given SBlock is well-formed.
135 *
136 * @param sb the sblock data (or at least "dsize" bytes claiming to be one)
137 * @param dsize size of "kb" in bytes; check for < sizeof(struct SBlock)!
138 * @param query where to store the query that this block answers
139 * @return GNUNET_OK if this is actually a well-formed SBlock
140 */
141static int
142check_sblock (const struct SBlock *sb,
143 size_t dsize,
144 GNUNET_HashCode *query)
145{
146 if (dsize < sizeof (struct SBlock))
147 {
148 GNUNET_break_op (0);
149 return GNUNET_SYSERR;
150 }
151 if (dsize !=
152 ntohl (sb->purpose.size) + sizeof (struct GNUNET_CRYPTO_RsaSignature))
153 {
154 GNUNET_break_op (0);
155 return GNUNET_SYSERR;
156 }
157 if (GNUNET_OK !=
158 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_FS_SBLOCK,
159 &sb->purpose,
160 &sb->signature,
161 &sb->subspace))
162 {
163 GNUNET_break_op (0);
164 return GNUNET_SYSERR;
165 }
166 if (query != NULL)
167 *query = sb->identifier;
168 return GNUNET_OK;
169}
170
171
172/**
173 * Check if the given block is well-formed (and of the given type).
174 *
175 * @param type type of the block
176 * @param block the block data (or at least "size" bytes claiming to be one)
177 * @param size size of "kb" in bytes; check that it is large enough
178 * @param query where to store the query that this block answers
179 * @return GNUNET_OK if this is actually a well-formed block,
180 * GNUNET_NO if we could not determine the query,
181 * GNUNET_SYSERR if the block is malformed
182 */
183int
184GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
185 const void *block,
186 size_t size,
187 GNUNET_HashCode *query)
188{
189 /* first, validate! */
190 switch (type)
191 {
192 case GNUNET_BLOCK_TYPE_DBLOCK:
193 case GNUNET_BLOCK_TYPE_IBLOCK:
194 GNUNET_CRYPTO_hash (block, size, query);
195 break;
196 case GNUNET_BLOCK_TYPE_KBLOCK:
197 if (GNUNET_OK !=
198 check_kblock (block,
199 size,
200 query))
201 return GNUNET_SYSERR;
202 break;
203 case GNUNET_BLOCK_TYPE_SBLOCK:
204 if (GNUNET_OK !=
205 check_sblock (block,
206 size,
207 query))
208 return GNUNET_SYSERR;
209 break;
210 case GNUNET_BLOCK_TYPE_NBLOCK:
211 if (GNUNET_OK !=
212 check_nblock (block,
213 size,
214 query))
215 return GNUNET_SYSERR;
216 return GNUNET_OK;
217 case GNUNET_BLOCK_TYPE_ONDEMAND:
218 if (size != sizeof (struct OnDemandBlock))
219 return GNUNET_SYSERR;
220 memset (query, 0, sizeof (GNUNET_HashCode));
221 return GNUNET_NO;
222 default:
223 /* unknown block type */
224 GNUNET_break_op (0);
225 return GNUNET_SYSERR;
226 }
227 return GNUNET_OK;
228}
229
230/* ***************** NEW API ******************* */
231 32
232/** 33/**
233 * Handle for a plugin. 34 * Handle for a plugin.
@@ -272,12 +73,47 @@ struct GNUNET_BLOCK_Context *
272GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg) 73GNUNET_BLOCK_context_create (const struct GNUNET_CONFIGURATION_Handle *cfg)
273{ 74{
274 struct GNUNET_BLOCK_Context *ctx; 75 struct GNUNET_BLOCK_Context *ctx;
76 struct GNUNET_BLOCK_PluginFunctions *api;
77 struct Plugin *plugin;
275 unsigned int num_plugins; 78 unsigned int num_plugins;
79 char *plugs;
80 char *pos;
81 char *libname;
276 82
277 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context)); 83 ctx = GNUNET_malloc (sizeof (struct GNUNET_BLOCK_Context));
278 ctx->cfg = cfg; 84 ctx->cfg = cfg;
279 num_plugins = 0; 85 num_plugins = 0;
280 /* FIXME: actually load plugins... */ 86 if (GNUNET_OK ==
87 GNUNET_CONFIGURATION_get_value_string (cfg,
88 "block", "PLUGINS", &plugs))
89 {
90 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
91 _("Loading block plugins `%s'\n"), plugs);
92 pos = strtok (plugs, " ");
93 while (pos != NULL)
94 {
95 GNUNET_asprintf (&libname, "libgnunet_plugin_block_%s", pos);
96 api = GNUNET_PLUGIN_load (libname, NULL);
97 if (api == NULL)
98 {
99 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
100 _("Failed to load block plugin `%s'\n"),
101 pos);
102 GNUNET_free (libname);
103 }
104 else
105 {
106 plugin = GNUNET_malloc (sizeof (struct Plugin));
107 plugin->api = api;
108 plugin->library_name = libname;
109 GNUNET_array_append (ctx->plugins,
110 num_plugins,
111 plugin);
112 }
113 pos = strtok (NULL, " ");
114 }
115 GNUNET_free (plugs);
116 }
281 GNUNET_array_append (ctx->plugins, 117 GNUNET_array_append (ctx->plugins,
282 num_plugins, 118 num_plugins,
283 NULL); 119 NULL);
diff --git a/src/block/plugin_block_fs.c b/src/block/plugin_block_fs.c
index 362932991..0626e458c 100644
--- a/src/block/plugin_block_fs.c
+++ b/src/block/plugin_block_fs.c
@@ -26,6 +26,7 @@
26 26
27#include "platform.h" 27#include "platform.h"
28#include "plugin_block.h" 28#include "plugin_block.h"
29#include "block_fs.h"
29#include "gnunet_signatures.h" 30#include "gnunet_signatures.h"
30 31
31#define DEBUG_FS_BLOCK GNUNET_NO 32#define DEBUG_FS_BLOCK GNUNET_NO
@@ -97,6 +98,8 @@ block_plugin_fs_evaluate (void *cls,
97 GNUNET_break_op (0); 98 GNUNET_break_op (0);
98 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; 99 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
99 } 100 }
101 if (reply_block == NULL)
102 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
100 return GNUNET_BLOCK_EVALUATION_OK_LAST; 103 return GNUNET_BLOCK_EVALUATION_OK_LAST;
101 case GNUNET_BLOCK_TYPE_KBLOCK: 104 case GNUNET_BLOCK_TYPE_KBLOCK:
102 case GNUNET_BLOCK_TYPE_NBLOCK: 105 case GNUNET_BLOCK_TYPE_NBLOCK:
@@ -310,7 +313,7 @@ block_plugin_fs_get_key (void *cls,
310 * Entry point for the plugin. 313 * Entry point for the plugin.
311 */ 314 */
312void * 315void *
313gnunet_plugin_block_fs_init (void *cls) 316libgnunet_plugin_block_fs_init (void *cls)
314{ 317{
315 static enum GNUNET_BLOCK_Type types[] = 318 static enum GNUNET_BLOCK_Type types[] =
316 { 319 {
@@ -335,7 +338,7 @@ gnunet_plugin_block_fs_init (void *cls)
335 * Exit point from the plugin. 338 * Exit point from the plugin.
336 */ 339 */
337void * 340void *
338gnunet_plugin_block_fs_done (void *cls) 341libgnunet_plugin_block_fs_done (void *cls)
339{ 342{
340 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 343 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
341 344
diff --git a/src/block/test_block.c b/src/block/test_block.c
index bdb806e5b..02719e5aa 100644
--- a/src/block/test_block.c
+++ b/src/block/test_block.c
@@ -29,8 +29,67 @@
29 29
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
32static int
33test_fs (struct GNUNET_BLOCK_Context *ctx)
34{
35 GNUNET_HashCode key;
36 char block[4];
37
38 memset (block, 1, sizeof (block));
39 if (GNUNET_OK !=
40 GNUNET_BLOCK_get_key (ctx,
41 GNUNET_BLOCK_TYPE_DBLOCK,
42 block,
43 sizeof (block),
44 &key))
45 return 1;
46 if (GNUNET_BLOCK_EVALUATION_OK_LAST !=
47 GNUNET_BLOCK_evaluate (ctx,
48 GNUNET_BLOCK_TYPE_DBLOCK,
49 &key,
50 NULL, 0,
51 NULL, 0,
52 block, sizeof (block)))
53 return 2;
54 if (GNUNET_BLOCK_EVALUATION_REQUEST_VALID !=
55 GNUNET_BLOCK_evaluate (ctx,
56 GNUNET_BLOCK_TYPE_DBLOCK,
57 &key,
58 NULL, 0,
59 NULL, 0,
60 NULL, 0))
61 return 4;
62 GNUNET_log_skip (1, GNUNET_NO);
63 if (GNUNET_BLOCK_EVALUATION_REQUEST_INVALID !=
64 GNUNET_BLOCK_evaluate (ctx,
65 GNUNET_BLOCK_TYPE_DBLOCK,
66 &key,
67 NULL, 0,
68 "bogus", 5,
69 NULL, 0))
70 return 8;
71 GNUNET_log_skip (0, GNUNET_YES);
72 return 0;
73}
74
32int 75int
33main (int argc, char *argv[]) 76main (int argc, char *argv[])
34{ 77{
35 return 0; /* testcase passed */ 78 int ret;
79 struct GNUNET_BLOCK_Context *ctx;
80 struct GNUNET_CONFIGURATION_Handle *cfg;
81
82 GNUNET_log_setup ("test-block", "WARNING", NULL);
83 cfg = GNUNET_CONFIGURATION_create ();
84 GNUNET_CONFIGURATION_set_value_string (cfg,
85 "block",
86 "PLUGINS",
87 "fs");
88 ctx = GNUNET_BLOCK_context_create (cfg);
89 ret = test_fs (ctx);
90 GNUNET_BLOCK_context_destroy (ctx);
91 GNUNET_CONFIGURATION_destroy (cfg);
92 if (ret != 0)
93 fprintf (stderr, "Tests failed: %d\n", ret);
94 return ret;
36} 95}
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 699f73a79..605e6c84b 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -31,6 +31,7 @@
31#include "gnunet_datastore_service.h" 31#include "gnunet_datastore_service.h"
32#include "gnunet_fs_service.h" 32#include "gnunet_fs_service.h"
33#include "gnunet_block_lib.h" 33#include "gnunet_block_lib.h"
34#include "block_fs.h"
34 35
35/** 36/**
36 * Maximum size of the datastore queue for P2P operations. 37 * Maximum size of the datastore queue for P2P operations.
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c
index 6b56784db..a0e275f2d 100644
--- a/src/fs/gnunet-service-fs.c
+++ b/src/fs/gnunet-service-fs.c
@@ -616,6 +616,15 @@ struct MigrationReadyBlock
616 */ 616 */
617static struct GNUNET_DATASTORE_Handle *dsh; 617static struct GNUNET_DATASTORE_Handle *dsh;
618 618
619/**
620 * Our block context.
621 */
622static struct GNUNET_BLOCK_Context *block_ctx;
623
624/**
625 * Our block configuration.
626 */
627static struct GNUNET_CONFIGURATION_Handle *block_cfg;
619 628
620/** 629/**
621 * Our scheduler. 630 * Our scheduler.
@@ -1569,12 +1578,19 @@ shutdown_task (void *cls,
1569 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1578 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
1570 stats = NULL; 1579 stats = NULL;
1571 } 1580 }
1572 GNUNET_DATASTORE_disconnect (dsh, 1581 if (dsh != NULL)
1573 GNUNET_NO); 1582 {
1583 GNUNET_DATASTORE_disconnect (dsh,
1584 GNUNET_NO);
1585 dsh = NULL;
1586 }
1574 while (mig_head != NULL) 1587 while (mig_head != NULL)
1575 delete_migration_block (mig_head); 1588 delete_migration_block (mig_head);
1576 GNUNET_assert (0 == mig_size); 1589 GNUNET_assert (0 == mig_size);
1577 dsh = NULL; 1590 GNUNET_BLOCK_context_destroy (block_ctx);
1591 block_ctx = NULL;
1592 GNUNET_CONFIGURATION_destroy (block_cfg);
1593 block_cfg = NULL;
1578 sched = NULL; 1594 sched = NULL;
1579 cfg = NULL; 1595 cfg = NULL;
1580 GNUNET_free_non_null (trustDirectory); 1596 GNUNET_free_non_null (trustDirectory);
@@ -2783,17 +2799,18 @@ handle_p2p_put (void *cls,
2783 type = ntohl (put->type); 2799 type = ntohl (put->type);
2784 expiration = GNUNET_TIME_absolute_ntoh (put->expiration); 2800 expiration = GNUNET_TIME_absolute_ntoh (put->expiration);
2785 2801
2802 if (type == GNUNET_BLOCK_TYPE_ONDEMAND)
2803 return GNUNET_SYSERR;
2786 if (GNUNET_OK != 2804 if (GNUNET_OK !=
2787 GNUNET_BLOCK_check_block (type, 2805 GNUNET_BLOCK_get_key (block_ctx,
2788 &put[1], 2806 type,
2789 dsize, 2807 &put[1],
2790 &query)) 2808 dsize,
2809 &query))
2791 { 2810 {
2792 GNUNET_break_op (0); 2811 GNUNET_break_op (0);
2793 return GNUNET_SYSERR; 2812 return GNUNET_SYSERR;
2794 } 2813 }
2795 if (type == GNUNET_BLOCK_TYPE_ONDEMAND)
2796 return GNUNET_SYSERR;
2797 if (GNUNET_BLOCK_TYPE_SBLOCK == type) 2814 if (GNUNET_BLOCK_TYPE_SBLOCK == type)
2798 { 2815 {
2799 sb = (const struct SBlock*) &put[1]; 2816 sb = (const struct SBlock*) &put[1];
@@ -3051,10 +3068,12 @@ process_local_reply (void *cls,
3051 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 3068 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
3052 &prq.namespace); 3069 &prq.namespace);
3053 } 3070 }
3054 if (GNUNET_OK != GNUNET_BLOCK_check_block (type, 3071 if (GNUNET_OK !=
3055 data, 3072 GNUNET_BLOCK_get_key (block_ctx,
3056 size, 3073 type,
3057 &query)) 3074 data,
3075 size,
3076 &query))
3058 { 3077 {
3059 GNUNET_break (0); 3078 GNUNET_break (0);
3060 GNUNET_DATASTORE_remove (dsh, 3079 GNUNET_DATASTORE_remove (dsh,
@@ -3786,12 +3805,23 @@ run (void *cls,
3786 GNUNET_SCHEDULER_shutdown (sched); 3805 GNUNET_SCHEDULER_shutdown (sched);
3787 return; 3806 return;
3788 } 3807 }
3808 block_cfg = GNUNET_CONFIGURATION_create ();
3809 GNUNET_CONFIGURATION_set_value_string (block_cfg,
3810 "block",
3811 "PLUGINS",
3812 "fs");
3813 block_ctx = GNUNET_BLOCK_context_create (block_cfg);
3814 GNUNET_assert (NULL != block_ctx);
3789 if ( (GNUNET_OK != GNUNET_FS_indexing_init (sched, cfg, dsh)) || 3815 if ( (GNUNET_OK != GNUNET_FS_indexing_init (sched, cfg, dsh)) ||
3790 (GNUNET_OK != main_init (sched, server, cfg)) ) 3816 (GNUNET_OK != main_init (sched, server, cfg)) )
3791 { 3817 {
3792 GNUNET_SCHEDULER_shutdown (sched); 3818 GNUNET_SCHEDULER_shutdown (sched);
3793 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO); 3819 GNUNET_DATASTORE_disconnect (dsh, GNUNET_NO);
3794 dsh = NULL; 3820 dsh = NULL;
3821 GNUNET_BLOCK_context_destroy (block_ctx);
3822 block_ctx = NULL;
3823 GNUNET_CONFIGURATION_destroy (block_cfg);
3824 block_cfg = NULL;
3795 return; 3825 return;
3796 } 3826 }
3797} 3827}
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 01e42fe3a..4e7fb8b7b 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -3,7 +3,8 @@ SUBDIRS = .
3gnunetincludedir = $(includedir)/gnunet 3gnunetincludedir = $(includedir)/gnunet
4 4
5nodist_gnunetinclude_HEADERS = \ 5nodist_gnunetinclude_HEADERS = \
6 gnunet_directories.h 6 gnunet_directories.h \
7 block_fs.h
7 8
8if MINGW 9if MINGW
9 WINPROC = winproc.h 10 WINPROC = winproc.h
diff --git a/src/include/block_fs.h b/src/include/block_fs.h
new file mode 100644
index 000000000..c3dcdeced
--- /dev/null
+++ b/src/include/block_fs.h
@@ -0,0 +1,165 @@
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 include/block_fs.h
23 * @brief fs block formats (shared between fs and block)
24 * @author Christian Grothoff
25 */
26#ifndef BLOCK_FS_H
27#define BLOCK_FS_H
28
29#include "gnunet_util_lib.h"
30
31/**
32 * @brief keyword block (advertising data under a keyword)
33 */
34struct KBlock
35{
36
37 /**
38 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
39 */
40 struct GNUNET_CRYPTO_RsaSignature signature;
41
42 /**
43 * What is being signed and why?
44 */
45 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
46
47 /**
48 * Key generated (!) from the H(keyword) as the seed!
49 */
50 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
51
52 /* 0-terminated URI here */
53
54 /* variable-size Meta-Data follows here */
55
56};
57
58
59/**
60 * @brief namespace content block (advertising data under an identifier in a namespace)
61 */
62struct SBlock
63{
64
65 /**
66 * GNUNET_RSA_Signature using RSA-key of the namespace
67 */
68 struct GNUNET_CRYPTO_RsaSignature signature;
69
70 /**
71 * What is being signed and why?
72 */
73 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
74
75 /**
76 * Hash of the hash of the human-readable identifier used for
77 * this entry (the hash of the human-readable identifier is
78 * used as the key for decryption; the xor of this identifier
79 * and the hash of the "keyspace" is the datastore-query hash).
80 */
81 GNUNET_HashCode identifier;
82
83 /**
84 * Public key of the namespace.
85 */
86 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
87
88 /* 0-terminated update-identifier here */
89
90 /* 0-terminated URI here (except for NBlocks) */
91
92 /* variable-size Meta-Data follows here */
93
94};
95
96
97/**
98 * @brief namespace advertisement block (advertising root of a namespace)
99 */
100struct NBlock
101{
102
103 /**
104 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
105 */
106 struct GNUNET_CRYPTO_RsaSignature ksk_signature;
107
108 /**
109 * What is being signed and why?
110 */
111 struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose;
112
113 /**
114 * Key generated (!) from the H(keyword) as the seed!
115 */
116 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
117
118 /**
119 * GNUNET_RSA_Signature using RSA-key of the namespace
120 */
121 struct GNUNET_CRYPTO_RsaSignature ns_signature;
122
123 /**
124 * What is being signed and why?
125 */
126 struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose;
127
128 /**
129 * Public key of the namespace.
130 */
131 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
132
133 /* from here on, data is encrypted with H(keyword) */
134
135 /* 0-terminated root identifier here */
136
137 /* variable-size Meta-Data follows here */
138
139};
140
141
142/**
143 * @brief index block (indexing a DBlock that
144 * can be obtained directly from reading
145 * the plaintext file)
146 */
147struct OnDemandBlock
148{
149 /**
150 * Hash code of the entire content of the
151 * file that was indexed (used to uniquely
152 * identify the plaintext file).
153 */
154 GNUNET_HashCode file_id;
155
156 /**
157 * At which offset should we be able to find
158 * this on-demand encoded block? (in NBO)
159 */
160 uint64_t offset GNUNET_PACKED;
161
162};
163
164
165#endif
diff --git a/src/include/gnunet_block_lib.h b/src/include/gnunet_block_lib.h
index ace4f23bb..7d06d592f 100644
--- a/src/include/gnunet_block_lib.h
+++ b/src/include/gnunet_block_lib.h
@@ -83,163 +83,7 @@ enum GNUNET_BLOCK_Type
83 }; 83 };
84 84
85 85
86/* **************** FIXME: move these to block_fs.h or so ***************** */
87 86
88/**
89 * @brief keyword block (advertising data under a keyword)
90 */
91struct KBlock
92{
93
94 /**
95 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
96 */
97 struct GNUNET_CRYPTO_RsaSignature signature;
98
99 /**
100 * What is being signed and why?
101 */
102 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
103
104 /**
105 * Key generated (!) from the H(keyword) as the seed!
106 */
107 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
108
109 /* 0-terminated URI here */
110
111 /* variable-size Meta-Data follows here */
112
113};
114
115
116/**
117 * @brief namespace content block (advertising data under an identifier in a namespace)
118 */
119struct SBlock
120{
121
122 /**
123 * GNUNET_RSA_Signature using RSA-key of the namespace
124 */
125 struct GNUNET_CRYPTO_RsaSignature signature;
126
127 /**
128 * What is being signed and why?
129 */
130 struct GNUNET_CRYPTO_RsaSignaturePurpose purpose;
131
132 /**
133 * Hash of the hash of the human-readable identifier used for
134 * this entry (the hash of the human-readable identifier is
135 * used as the key for decryption; the xor of this identifier
136 * and the hash of the "keyspace" is the datastore-query hash).
137 */
138 GNUNET_HashCode identifier;
139
140 /**
141 * Public key of the namespace.
142 */
143 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
144
145 /* 0-terminated update-identifier here */
146
147 /* 0-terminated URI here (except for NBlocks) */
148
149 /* variable-size Meta-Data follows here */
150
151};
152
153
154/**
155 * @brief namespace advertisement block (advertising root of a namespace)
156 */
157struct NBlock
158{
159
160 /**
161 * GNUNET_RSA_Signature using RSA-key generated from search keyword.
162 */
163 struct GNUNET_CRYPTO_RsaSignature ksk_signature;
164
165 /**
166 * What is being signed and why?
167 */
168 struct GNUNET_CRYPTO_RsaSignaturePurpose ksk_purpose;
169
170 /**
171 * Key generated (!) from the H(keyword) as the seed!
172 */
173 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded keyspace;
174
175 /**
176 * GNUNET_RSA_Signature using RSA-key of the namespace
177 */
178 struct GNUNET_CRYPTO_RsaSignature ns_signature;
179
180 /**
181 * What is being signed and why?
182 */
183 struct GNUNET_CRYPTO_RsaSignaturePurpose ns_purpose;
184
185 /**
186 * Public key of the namespace.
187 */
188 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded subspace;
189
190 /* from here on, data is encrypted with H(keyword) */
191
192 /* 0-terminated root identifier here */
193
194 /* variable-size Meta-Data follows here */
195
196};
197
198
199/**
200 * @brief index block (indexing a DBlock that
201 * can be obtained directly from reading
202 * the plaintext file)
203 */
204struct OnDemandBlock
205{
206 /**
207 * Hash code of the entire content of the
208 * file that was indexed (used to uniquely
209 * identify the plaintext file).
210 */
211 GNUNET_HashCode file_id;
212
213 /**
214 * At which offset should we be able to find
215 * this on-demand encoded block? (in NBO)
216 */
217 uint64_t offset GNUNET_PACKED;
218
219};
220
221
222/* **************** OLD API ***************** */
223
224/**
225 * Check if the given block is well-formed (and of the given type).
226 *
227 * @param type type of the block
228 * @param block the block data (or at least "size" bytes claiming to be one)
229 * @param size size of "kb" in bytes; check that it is large enough
230 * @param query where to store the query that this block answers
231 * @return GNUNET_OK if this is actually a well-formed KBlock
232 * GNUNET_NO if we could not determine the query,
233 * GNUNET_SYSERR if the block is malformed
234 */
235int
236GNUNET_BLOCK_check_block (enum GNUNET_BLOCK_Type type,
237 const void *block,
238 size_t size,
239 GNUNET_HashCode *query);
240
241
242/* **************** NEW API ***************** */
243 87
244/** 88/**
245 * Possible ways for how a block may relate to a query. 89 * Possible ways for how a block may relate to a query.
diff --git a/src/util/test_time.c b/src/util/test_time.c
index bf4655b48..eecbbafae 100644
--- a/src/util/test_time.c
+++ b/src/util/test_time.c
@@ -64,8 +64,10 @@ check ()
64 GNUNET_assert (GNUNET_TIME_relative_get_zero ().value == GNUNET_TIME_relative_multiply (rel,0).value); 64 GNUNET_assert (GNUNET_TIME_relative_get_zero ().value == GNUNET_TIME_relative_multiply (rel,0).value);
65 65
66 /* test infinity-check for relative to absolute */ 66 /* test infinity-check for relative to absolute */
67 GNUNET_log_skip (1, GNUNET_NO);
67 last = GNUNET_TIME_relative_to_absolute (rel); 68 last = GNUNET_TIME_relative_to_absolute (rel);
68 GNUNET_assert (last.value == GNUNET_TIME_UNIT_FOREVER_ABS.value); 69 GNUNET_assert (last.value == GNUNET_TIME_UNIT_FOREVER_ABS.value);
70 GNUNET_log_skip (0, GNUNET_YES);
69 71
70 /*check relative to absolute*/ 72 /*check relative to absolute*/
71 rel.value = 0; 73 rel.value = 0;
@@ -179,13 +181,15 @@ check ()
179 forever = GNUNET_TIME_absolute_get_forever (); 181 forever = GNUNET_TIME_absolute_get_forever ();
180 forever.value = forever.value - 1024; 182 forever.value = forever.value - 1024;
181 GNUNET_assert(GNUNET_TIME_absolute_get_zero ().value == 183 GNUNET_assert(GNUNET_TIME_absolute_get_zero ().value ==
182 GNUNET_TIME_calculate_eta (forever,50000,100000).value); 184 GNUNET_TIME_calculate_eta (forever, 50000, 100000).value);
183 /*check zero*/ 185 /* check zero */
186 GNUNET_log_skip (1, GNUNET_NO);
184 GNUNET_assert(GNUNET_TIME_UNIT_ZERO.value == 187 GNUNET_assert(GNUNET_TIME_UNIT_ZERO.value ==
185 (GNUNET_TIME_calculate_eta (last,60000,50000)).value); 188 (GNUNET_TIME_calculate_eta (last, 60000, 50000)).value);
189 GNUNET_log_skip (0, GNUNET_YES);
186 /*check forever*/ 190 /*check forever*/
187 GNUNET_assert(GNUNET_TIME_UNIT_FOREVER_REL.value == 191 GNUNET_assert(GNUNET_TIME_UNIT_FOREVER_REL.value ==
188 (GNUNET_TIME_calculate_eta (last,0,50000)).value); 192 (GNUNET_TIME_calculate_eta (last, 0, 50000)).value);
189 193
190 /*check relative subtract*/ 194 /*check relative subtract*/
191 now = GNUNET_TIME_absolute_get (); 195 now = GNUNET_TIME_absolute_get ();