diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-11 14:50:07 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-11 14:50:07 +0000 |
commit | cd67a970afe36e8a2aa99e48cbe103cc4cc26424 (patch) | |
tree | 67e5023676f2278485e35a2b71ce246b9933f406 /src/fs/fs_publish.c | |
parent | 3dd666cbad61490c0de1cb891fd1b36c8536c348 (diff) | |
download | gnunet-cd67a970afe36e8a2aa99e48cbe103cc4cc26424.tar.gz gnunet-cd67a970afe36e8a2aa99e48cbe103cc4cc26424.zip |
generate progress events when publishing directories (towards fixing #2230)
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 05645f0ab..2075c5f2b 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -362,7 +362,7 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
362 | if (UINT64_MAX == offset) | 362 | if (UINT64_MAX == offset) |
363 | { | 363 | { |
364 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) | 364 | if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) |
365 | { | 365 | { |
366 | /* force closing the file to avoid keeping too many files open */ | 366 | /* force closing the file to avoid keeping too many files open */ |
367 | p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); | 367 | p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL); |
368 | } | 368 | } |
@@ -390,7 +390,8 @@ block_reader (void *cls, uint64_t offset, size_t max, void *buf, char **emsg) | |||
390 | * @param tc scheduler's task context (not used) | 390 | * @param tc scheduler's task context (not used) |
391 | */ | 391 | */ |
392 | static void | 392 | static void |
393 | encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 393 | encode_cont (void *cls, |
394 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
394 | { | 395 | { |
395 | struct GNUNET_FS_PublishContext *pc = cls; | 396 | struct GNUNET_FS_PublishContext *pc = cls; |
396 | struct GNUNET_FS_FileInformation *p; | 397 | struct GNUNET_FS_FileInformation *p; |
@@ -421,7 +422,7 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
421 | } | 422 | } |
422 | else | 423 | else |
423 | { | 424 | { |
424 | /* final progress event */ | 425 | /* final progress event */ |
425 | GNUNET_assert (NULL != p->chk_uri); | 426 | GNUNET_assert (NULL != p->chk_uri); |
426 | flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); | 427 | flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri); |
427 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; | 428 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; |
@@ -454,8 +455,12 @@ encode_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
454 | * @param block_size size of @a block (in bytes) | 455 | * @param block_size size of @a block (in bytes) |
455 | */ | 456 | */ |
456 | static void | 457 | static void |
457 | block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, | 458 | block_proc (void *cls, |
458 | unsigned int depth, enum GNUNET_BLOCK_Type type, const void *block, | 459 | const struct ContentHashKey *chk, |
460 | uint64_t offset, | ||
461 | unsigned int depth, | ||
462 | enum GNUNET_BLOCK_Type type, | ||
463 | const void *block, | ||
459 | uint16_t block_size) | 464 | uint16_t block_size) |
460 | { | 465 | { |
461 | struct GNUNET_FS_PublishContext *pc = cls; | 466 | struct GNUNET_FS_PublishContext *pc = cls; |
@@ -520,11 +525,14 @@ block_proc (void *cls, const struct ContentHashKey *chk, uint64_t offset, | |||
520 | * @param depth depth of the block in the tree, 0 for DBLOCK | 525 | * @param depth depth of the block in the tree, 0 for DBLOCK |
521 | */ | 526 | */ |
522 | static void | 527 | static void |
523 | progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size, | 528 | progress_proc (void *cls, uint64_t offset, |
529 | const void *pt_block, | ||
530 | size_t pt_size, | ||
524 | unsigned int depth) | 531 | unsigned int depth) |
525 | { | 532 | { |
526 | struct GNUNET_FS_PublishContext *pc = cls; | 533 | struct GNUNET_FS_PublishContext *pc = cls; |
527 | struct GNUNET_FS_FileInformation *p; | 534 | struct GNUNET_FS_FileInformation *p; |
535 | struct GNUNET_FS_FileInformation *par; | ||
528 | struct GNUNET_FS_ProgressInfo pi; | 536 | struct GNUNET_FS_ProgressInfo pi; |
529 | 537 | ||
530 | p = pc->fi_pos; | 538 | p = pc->fi_pos; |
@@ -534,6 +542,23 @@ progress_proc (void *cls, uint64_t offset, const void *pt_block, size_t pt_size, | |||
534 | pi.value.publish.specifics.progress.data_len = pt_size; | 542 | pi.value.publish.specifics.progress.data_len = pt_size; |
535 | pi.value.publish.specifics.progress.depth = depth; | 543 | pi.value.publish.specifics.progress.depth = depth; |
536 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset); | 544 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset); |
545 | if ( (0 != depth) || | ||
546 | (GNUNET_YES == p->is_directory) ) | ||
547 | return; | ||
548 | while (NULL != (par = p->dir)) | ||
549 | { | ||
550 | p = par; | ||
551 | GNUNET_assert (GNUNET_YES == par->is_directory); | ||
552 | p->data.dir.contents_completed += pt_size; | ||
553 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; | ||
554 | pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; | ||
555 | pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; | ||
556 | pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta (p->start_time, | ||
557 | p->data.dir.contents_completed, | ||
558 | p->data.dir.contents_size); | ||
559 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0); | ||
560 | |||
561 | } | ||
537 | } | 562 | } |
538 | 563 | ||
539 | 564 | ||
@@ -1137,6 +1162,25 @@ finish_reserve (void *cls, int success, | |||
1137 | 1162 | ||
1138 | 1163 | ||
1139 | /** | 1164 | /** |
1165 | * Calculate the total size of all of the files in the directory structure. | ||
1166 | * | ||
1167 | * @param fi file structure to traverse | ||
1168 | */ | ||
1169 | static uint64_t | ||
1170 | compute_contents_size (struct GNUNET_FS_FileInformation *fi) | ||
1171 | { | ||
1172 | struct GNUNET_FS_FileInformation *ent; | ||
1173 | |||
1174 | if (GNUNET_YES != fi->is_directory) | ||
1175 | return fi->data.file.file_size; | ||
1176 | fi->data.dir.contents_size = 0; | ||
1177 | for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) | ||
1178 | fi->data.dir.contents_size += compute_contents_size (ent); | ||
1179 | return fi->data.dir.contents_size; | ||
1180 | } | ||
1181 | |||
1182 | |||
1183 | /** | ||
1140 | * Publish a file or directory. | 1184 | * Publish a file or directory. |
1141 | * | 1185 | * |
1142 | * @param h handle to the file sharing subsystem | 1186 | * @param h handle to the file sharing subsystem |
@@ -1161,6 +1205,7 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | |||
1161 | struct GNUNET_DATASTORE_Handle *dsh; | 1205 | struct GNUNET_DATASTORE_Handle *dsh; |
1162 | 1206 | ||
1163 | GNUNET_assert (NULL != h); | 1207 | GNUNET_assert (NULL != h); |
1208 | compute_contents_size (fi); | ||
1164 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) | 1209 | if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) |
1165 | { | 1210 | { |
1166 | dsh = GNUNET_DATASTORE_connect (h->cfg); | 1211 | dsh = GNUNET_DATASTORE_connect (h->cfg); |