diff options
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 111 |
1 files changed, 80 insertions, 31 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 0078d0d32..f5c2b4cdc 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -26,7 +26,6 @@ | |||
26 | * @author Christian Grothoff | 26 | * @author Christian Grothoff |
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - directory creation | ||
30 | * - KBlocks | 29 | * - KBlocks |
31 | * - SBlocks | 30 | * - SBlocks |
32 | * - indexing support | 31 | * - indexing support |
@@ -119,6 +118,7 @@ ds_put_cont (void *cls, | |||
119 | * | 118 | * |
120 | * @param sc overall upload data | 119 | * @param sc overall upload data |
121 | * @param p file that the block belongs to (needed for options!) | 120 | * @param p file that the block belongs to (needed for options!) |
121 | * @param query what the block should be indexed under | ||
122 | * @param blk encoded block to publish | 122 | * @param blk encoded block to publish |
123 | * @param blk_size size of the block | 123 | * @param blk_size size of the block |
124 | * @param blk_type type of the block | 124 | * @param blk_type type of the block |
@@ -127,15 +127,14 @@ ds_put_cont (void *cls, | |||
127 | static void | 127 | static void |
128 | publish_block (struct GNUNET_FS_PublishContext *sc, | 128 | publish_block (struct GNUNET_FS_PublishContext *sc, |
129 | struct GNUNET_FS_FileInformation *p, | 129 | struct GNUNET_FS_FileInformation *p, |
130 | const GNUNET_HashCode *query, | ||
130 | const void* blk, | 131 | const void* blk, |
131 | uint16_t blk_size, | 132 | uint16_t blk_size, |
132 | uint32_t blk_type, | 133 | uint32_t blk_type, |
133 | GNUNET_SCHEDULER_Task cont) | 134 | GNUNET_SCHEDULER_Task cont) |
134 | { | 135 | { |
135 | struct GNUNET_HashCode key; | 136 | struct PutContCtx * dpc_cls; |
136 | 137 | ||
137 | // FIXME: GNUNET_FS_get_key (blk_type, blk, blk_size, &key); | ||
138 | // (or add "key" as argument to reduce hashing?) | ||
139 | dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx)); | 138 | dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx)); |
140 | dpc_cls->cont = cont; | 139 | dpc_cls->cont = cont; |
141 | dpc_cls->sc = sc; | 140 | dpc_cls->sc = sc; |
@@ -146,8 +145,9 @@ publish_block (struct GNUNET_FS_PublishContext *sc, | |||
146 | // a task ID! | 145 | // a task ID! |
147 | GNUNET_DATASTORE_put (sc->dsh, | 146 | GNUNET_DATASTORE_put (sc->dsh, |
148 | sc->rid, | 147 | sc->rid, |
149 | &key, | 148 | query, |
150 | blk_size, | 149 | blk_size, |
150 | blk, | ||
151 | blk_type, | 151 | blk_type, |
152 | p->priority, | 152 | p->priority, |
153 | p->anonymity, | 153 | p->anonymity, |
@@ -280,7 +280,8 @@ compute_chk_offset (unsigned int height, | |||
280 | uint64_t offset) | 280 | uint64_t offset) |
281 | { | 281 | { |
282 | uint64_t bds; | 282 | uint64_t bds; |
283 | unsigned int ret; | 283 | unsigned int ret; |
284 | unsigned int i; | ||
284 | 285 | ||
285 | bds = GNUNET_FS_DBLOCK_SIZE; /* number of bytes each CHK at level "i" | 286 | bds = GNUNET_FS_DBLOCK_SIZE; /* number of bytes each CHK at level "i" |
286 | corresponds to */ | 287 | corresponds to */ |
@@ -305,7 +306,7 @@ static void | |||
305 | publish_content (struct GNUNET_FS_PublishContext *sc, | 306 | publish_content (struct GNUNET_FS_PublishContext *sc, |
306 | struct GNUNET_FS_FileInformation *p) | 307 | struct GNUNET_FS_FileInformation *p) |
307 | { | 308 | { |
308 | struct ContentHashKey *chk; | 309 | struct ContentHashKey *mychk; |
309 | const void *pt_block; | 310 | const void *pt_block; |
310 | uint16_t pt_size; | 311 | uint16_t pt_size; |
311 | char *emsg; | 312 | char *emsg; |
@@ -315,6 +316,10 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
315 | struct GNUNET_CRYPTO_AesInitializationVector iv; | 316 | struct GNUNET_CRYPTO_AesInitializationVector iv; |
316 | uint64_t size; | 317 | uint64_t size; |
317 | unsigned int off; | 318 | unsigned int off; |
319 | struct GNUNET_FS_DirectoryBuilder *db; | ||
320 | struct GNUNET_FS_FileInformation *dirpos; | ||
321 | void *raw_data; | ||
322 | char *dd; | ||
318 | 323 | ||
319 | // FIXME: figure out how to share this code | 324 | // FIXME: figure out how to share this code |
320 | // with unindex! | 325 | // with unindex! |
@@ -323,14 +328,47 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
323 | { | 328 | { |
324 | if (p->is_directory) | 329 | if (p->is_directory) |
325 | { | 330 | { |
326 | /* FIXME: create function to create directory | 331 | db = GNUNET_FS_directory_builder_create (p->meta); |
327 | and use that API here! */ | 332 | dirpos = p->data.dir.entries; |
328 | GNUNET_FS_directory_create (&p->data.dir.dir_size, | 333 | while (NULL != dirpos) |
329 | &p->data.dir.dir_data, | 334 | { |
330 | p->meta, | 335 | if (dirpos->is_directory) |
331 | &directory_entry_lister, | 336 | { |
332 | p->data.dir.entries); | 337 | raw_data = dirpos->data.dir.dir_data; |
333 | size = p->data.dir.data_size; | 338 | dirpos->data.dir.dir_data = NULL; |
339 | } | ||
340 | else | ||
341 | { | ||
342 | raw_data = NULL; | ||
343 | if ( (dirpos->data.file.file_size < GNUNET_FS_MAX_INLINE_SIZE) && | ||
344 | (dirpos->data.file.file_size > 0) ) | ||
345 | { | ||
346 | raw_data = GNUNET_malloc (dirpos->data.file.file_size); | ||
347 | emsg = NULL; | ||
348 | if (dirpos->data.file.file_size != | ||
349 | dirpos->data.file.reader (dirpos->data.file.reader_cls, | ||
350 | 0, | ||
351 | dirpos->data.file.file_size, | ||
352 | raw_data, | ||
353 | &emsg)) | ||
354 | { | ||
355 | GNUNET_free_non_null (emsg); | ||
356 | GNUNET_free (raw_data); | ||
357 | raw_data = NULL; | ||
358 | } | ||
359 | } | ||
360 | } | ||
361 | GNUNET_FS_directory_builder_add (db, | ||
362 | dirpos->chk_uri, | ||
363 | dirpos->meta, | ||
364 | raw_data); | ||
365 | GNUNET_free_non_null (raw_data); | ||
366 | dirpos = dirpos->next; | ||
367 | } | ||
368 | GNUNET_FS_directory_builder_finish (db, | ||
369 | &p->data.dir.dir_size, | ||
370 | &p->data.dir.dir_data); | ||
371 | size = p->data.dir.dir_size; | ||
334 | } | 372 | } |
335 | p->chk_tree_depth = compute_depth (size); | 373 | p->chk_tree_depth = compute_depth (size); |
336 | p->chk_tree = GNUNET_malloc (p->chk_tree_depth * | 374 | p->chk_tree = GNUNET_malloc (p->chk_tree_depth * |
@@ -344,17 +382,24 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
344 | { | 382 | { |
345 | pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, | 383 | pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, |
346 | p->data.dir.dir_size - p->publish_offset); | 384 | p->data.dir.dir_size - p->publish_offset); |
347 | pt_block = &p->data.dir.dir_data[p->publish_offset]; | 385 | dd = p->data.dir.dir_data; |
386 | pt_block = &dd[p->publish_offset]; | ||
348 | } | 387 | } |
349 | else | 388 | else |
350 | { | 389 | { |
351 | pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, | 390 | pt_size = GNUNET_MIN(GNUNET_FS_DBLOCK_SIZE, |
352 | p->data.file.file_size - p->publish_offset); | 391 | p->data.file.file_size - p->publish_offset); |
353 | p->data.file.reader (p->data.file.reader_cls, | 392 | emsg = NULL; |
354 | p->publish_offset, | 393 | if (pt_size != |
355 | pt_size, | 394 | p->data.file.reader (p->data.file.reader_cls, |
356 | iob, | 395 | p->publish_offset, |
357 | &emsg); | 396 | pt_size, |
397 | iob, | ||
398 | &emsg)) | ||
399 | { | ||
400 | // FIXME: abort with error "emsg" | ||
401 | GNUNET_free (emsg); | ||
402 | } | ||
358 | pt_block = iob; | 403 | pt_block = iob; |
359 | } | 404 | } |
360 | } | 405 | } |
@@ -367,9 +412,9 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
367 | } | 412 | } |
368 | off = compute_chk_offset (p->chk_tree_depth - p->current_depth, | 413 | off = compute_chk_offset (p->chk_tree_depth - p->current_depth, |
369 | p->publish_offset); | 414 | p->publish_offset); |
370 | chk = &p->chk_tree[(p->current_depth-1)*GNUNET_FS_CHK_PER_INODE+off]; | 415 | mychk = &p->chk_tree[(p->current_depth-1)*GNUNET_FS_CHK_PER_INODE+off]; |
371 | GNUNET_CRYPTO_hash (pt_block, pt_size, &chk->key); | 416 | GNUNET_CRYPTO_hash (pt_block, pt_size, &mychk->key); |
372 | GNUNET_CRYPTO_hash_to_aes_key (&chk->key, &sk, &iv); | 417 | GNUNET_CRYPTO_hash_to_aes_key (&mychk->key, &sk, &iv); |
373 | GNUNET_CRYPTO_aes_encrypt (pt_block, | 418 | GNUNET_CRYPTO_aes_encrypt (pt_block, |
374 | pt_size, | 419 | pt_size, |
375 | &sk, | 420 | &sk, |
@@ -379,13 +424,16 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
379 | // between publish/unindex! Parameterize & move this code! | 424 | // between publish/unindex! Parameterize & move this code! |
380 | // FIXME: something around here would need to change | 425 | // FIXME: something around here would need to change |
381 | // for indexing! | 426 | // for indexing! |
382 | publish_block (sc, p, enc, pt_size, | 427 | publish_block (sc, p, |
428 | &mychk->query, | ||
429 | enc, | ||
430 | pt_size, | ||
383 | (p->current_depth == p->chk_tree_depth) | 431 | (p->current_depth == p->chk_tree_depth) |
384 | ? GNUNET_DATASTORE_BLOCKTYPE_DBLOCK | 432 | ? GNUNET_DATASTORE_BLOCKTYPE_DBLOCK |
385 | : GNUNET_DATASTORE_BLOCKTYPE_IBLOCK, | 433 | : GNUNET_DATASTORE_BLOCKTYPE_IBLOCK, |
386 | &do_upload); | 434 | &do_upload); |
387 | // FIXME: should call progress function somewhere here! | 435 | // FIXME: should call progress function somewhere here! |
388 | GNUNET_CRYPTO_hash (enc, pt_size, &chk->query); | 436 | GNUNET_CRYPTO_hash (enc, pt_size, &mychk->query); |
389 | if (p->current_depth == p->chk_tree_depth) | 437 | if (p->current_depth == p->chk_tree_depth) |
390 | { | 438 | { |
391 | p->publish_offset += pt_size; | 439 | p->publish_offset += pt_size; |
@@ -404,9 +452,9 @@ publish_content (struct GNUNET_FS_PublishContext *sc, | |||
404 | if (0 == p->current_depth) | 452 | if (0 == p->current_depth) |
405 | { | 453 | { |
406 | p->chk_uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); | 454 | p->chk_uri = GNUNET_malloc (sizeof(struct GNUNET_FS_Uri)); |
407 | p->chk_uri.type = chk; | 455 | p->chk_uri->type = chk; |
408 | p->chk_uri.data.chk.chk = p->chk_tree[0]; | 456 | p->chk_uri->data.chk.chk = p->chk_tree[0]; |
409 | p->chk_uri.data.chk.file_length = size; | 457 | p->chk_uri->data.chk.file_length = size; |
410 | GNUNET_free (p->chk_tree); | 458 | GNUNET_free (p->chk_tree); |
411 | p->chk_tree = NULL; | 459 | p->chk_tree = NULL; |
412 | } | 460 | } |
@@ -445,7 +493,8 @@ do_upload (void *cls, | |||
445 | publish_kblocks (sc, p); | 493 | publish_kblocks (sc, p); |
446 | return; | 494 | return; |
447 | } | 495 | } |
448 | if (p->do_index) | 496 | if ( (!p->is_directory) && |
497 | (p->data.file.do_index) ) | ||
449 | { | 498 | { |
450 | // FIXME: need to pre-compute hash over | 499 | // FIXME: need to pre-compute hash over |
451 | // the entire file and ask FS to prepare | 500 | // the entire file and ask FS to prepare |
@@ -542,7 +591,7 @@ GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc) | |||
542 | GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); | 591 | GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); |
543 | GNUNET_free_non_null (sc->nid); | 592 | GNUNET_free_non_null (sc->nid); |
544 | GNUNET_free_non_null (sc->nuid); | 593 | GNUNET_free_non_null (sc->nuid); |
545 | GNUNET_DATASTORE_disconnect (sc->dsh); | 594 | GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO); |
546 | GNUNET_free (sc); | 595 | GNUNET_free (sc); |
547 | } | 596 | } |
548 | 597 | ||