diff options
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r-- | src/fs/fs_publish.c | 162 |
1 files changed, 76 insertions, 86 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index 1260d1c7c..f9970e409 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -42,15 +42,6 @@ | |||
42 | 42 | ||
43 | #define DEBUG_PUBLISH GNUNET_NO | 43 | #define DEBUG_PUBLISH GNUNET_NO |
44 | 44 | ||
45 | /** | ||
46 | * Main function that performs the upload. | ||
47 | * @param cls "struct GNUNET_FS_PublishContext" identifies the upload | ||
48 | * @param tc task context | ||
49 | */ | ||
50 | static void | ||
51 | do_upload (void *cls, | ||
52 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
53 | |||
54 | 45 | ||
55 | /** | 46 | /** |
56 | * Context for "ds_put_cont". | 47 | * Context for "ds_put_cont". |
@@ -81,18 +72,19 @@ struct PutContCtx | |||
81 | 72 | ||
82 | /** | 73 | /** |
83 | * Fill in all of the generic fields for | 74 | * Fill in all of the generic fields for |
84 | * a publish event. | 75 | * a publish event and call the callback. |
85 | * | 76 | * |
86 | * @param pi structure to fill in | 77 | * @param pi structure to fill in |
87 | * @param sc overall publishing context | 78 | * @param sc overall publishing context |
88 | * @param p file information for the file being published | 79 | * @param p file information for the file being published |
89 | * @param offset where in the file are we so far | 80 | * @param offset where in the file are we so far |
81 | * @return value returned from callback | ||
90 | */ | 82 | */ |
91 | static void | 83 | void * |
92 | make_publish_status (struct GNUNET_FS_ProgressInfo *pi, | 84 | GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi, |
93 | struct GNUNET_FS_PublishContext *sc, | 85 | struct GNUNET_FS_PublishContext *sc, |
94 | const struct GNUNET_FS_FileInformation *p, | 86 | const struct GNUNET_FS_FileInformation *p, |
95 | uint64_t offset) | 87 | uint64_t offset) |
96 | { | 88 | { |
97 | pi->value.publish.sc = sc; | 89 | pi->value.publish.sc = sc; |
98 | pi->value.publish.fi = p; | 90 | pi->value.publish.fi = p; |
@@ -111,27 +103,29 @@ make_publish_status (struct GNUNET_FS_ProgressInfo *pi, | |||
111 | pi->value.publish.completed = offset; | 103 | pi->value.publish.completed = offset; |
112 | pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (p->start_time); | 104 | pi->value.publish.duration = GNUNET_TIME_absolute_get_duration (p->start_time); |
113 | pi->value.publish.anonymity = p->anonymity; | 105 | pi->value.publish.anonymity = p->anonymity; |
106 | return sc->h->upcb (sc->h->upcb_cls, | ||
107 | pi); | ||
114 | } | 108 | } |
115 | 109 | ||
116 | 110 | ||
117 | /** | 111 | /** |
118 | * Cleanup the publish context, we're done | 112 | * Cleanup the publish context, we're done with it. |
119 | * with it. | ||
120 | * | 113 | * |
121 | * @param sc struct to clean up after | 114 | * @param pc struct to clean up after |
122 | */ | 115 | */ |
123 | static void | 116 | static void |
124 | publish_cleanup (struct GNUNET_FS_PublishContext *sc) | 117 | publish_cleanup (struct GNUNET_FS_PublishContext *pc) |
125 | { | 118 | { |
126 | GNUNET_FS_file_information_destroy (sc->fi, NULL, NULL); | 119 | GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL); |
127 | if (sc->namespace != NULL) | 120 | if (pc->namespace != NULL) |
128 | GNUNET_FS_namespace_delete (sc->namespace, GNUNET_NO); | 121 | GNUNET_FS_namespace_delete (pc->namespace, GNUNET_NO); |
129 | GNUNET_free_non_null (sc->nid); | 122 | GNUNET_free_non_null (pc->nid); |
130 | GNUNET_free_non_null (sc->nuid); | 123 | GNUNET_free_non_null (pc->nuid); |
131 | GNUNET_DATASTORE_disconnect (sc->dsh, GNUNET_NO); | 124 | GNUNET_free_non_null (pc->serialization); |
132 | if (sc->client != NULL) | 125 | GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO); |
133 | GNUNET_CLIENT_disconnect (sc->client, GNUNET_NO); | 126 | if (pc->client != NULL) |
134 | GNUNET_free (sc); | 127 | GNUNET_CLIENT_disconnect (pc->client, GNUNET_NO); |
128 | GNUNET_free (pc); | ||
135 | } | 129 | } |
136 | 130 | ||
137 | 131 | ||
@@ -167,12 +161,9 @@ ds_put_cont (void *cls, | |||
167 | msg); | 161 | msg); |
168 | GNUNET_FS_file_information_sync (pcc->p); | 162 | GNUNET_FS_file_information_sync (pcc->p); |
169 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 163 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
170 | make_publish_status (&pi, pcc->sc, pcc->p, 0); | ||
171 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 164 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
172 | pi.value.publish.specifics.error.message = pcc->p->emsg; | 165 | pi.value.publish.specifics.error.message = pcc->p->emsg; |
173 | pcc->p->client_info | 166 | pcc->p->client_info = GNUNET_FS_publish_make_status_ (&pi, pcc->sc, pcc->p, 0); |
174 | = pcc->sc->h->upcb (pcc->sc->h->upcb_cls, | ||
175 | &pi); | ||
176 | } | 167 | } |
177 | GNUNET_FS_file_information_sync (pcc->p); | 168 | GNUNET_FS_file_information_sync (pcc->p); |
178 | if (NULL != pcc->cont) | 169 | if (NULL != pcc->cont) |
@@ -200,13 +191,10 @@ signal_publish_completion (struct GNUNET_FS_FileInformation *p, | |||
200 | struct GNUNET_FS_ProgressInfo pi; | 191 | struct GNUNET_FS_ProgressInfo pi; |
201 | 192 | ||
202 | pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; | 193 | pi.status = GNUNET_FS_STATUS_PUBLISH_COMPLETED; |
203 | make_publish_status (&pi, sc, p, | ||
204 | GNUNET_ntohll (p->chk_uri->data.chk.file_length)); | ||
205 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; | 194 | pi.value.publish.eta = GNUNET_TIME_UNIT_ZERO; |
206 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; | 195 | pi.value.publish.specifics.completed.chk_uri = p->chk_uri; |
207 | p->client_info | 196 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, |
208 | = sc->h->upcb (sc->h->upcb_cls, | 197 | GNUNET_ntohll (p->chk_uri->data.chk.file_length)); |
209 | &pi); | ||
210 | } | 198 | } |
211 | 199 | ||
212 | 200 | ||
@@ -228,12 +216,9 @@ signal_publish_error (struct GNUNET_FS_FileInformation *p, | |||
228 | 216 | ||
229 | p->emsg = GNUNET_strdup (emsg); | 217 | p->emsg = GNUNET_strdup (emsg); |
230 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 218 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
231 | make_publish_status (&pi, sc, p, 0); | ||
232 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 219 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
233 | pi.value.publish.specifics.error.message =emsg; | 220 | pi.value.publish.specifics.error.message =emsg; |
234 | p->client_info | 221 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0); |
235 | = sc->h->upcb (sc->h->upcb_cls, | ||
236 | &pi); | ||
237 | } | 222 | } |
238 | 223 | ||
239 | 224 | ||
@@ -314,7 +299,7 @@ publish_kblocks_cont (void *cls, | |||
314 | sc->upload_task | 299 | sc->upload_task |
315 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 300 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, |
316 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 301 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
317 | &do_upload, | 302 | &GNUNET_FS_publish_main_, |
318 | sc); | 303 | sc); |
319 | return; | 304 | return; |
320 | } | 305 | } |
@@ -329,7 +314,7 @@ publish_kblocks_cont (void *cls, | |||
329 | sc->upload_task | 314 | sc->upload_task |
330 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 315 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, |
331 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 316 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
332 | &do_upload, | 317 | &GNUNET_FS_publish_main_, |
333 | sc); | 318 | sc); |
334 | } | 319 | } |
335 | 320 | ||
@@ -418,19 +403,16 @@ encode_cont (void *cls, | |||
418 | GNUNET_free (emsg); | 403 | GNUNET_free (emsg); |
419 | GNUNET_FS_file_information_sync (p); | 404 | GNUNET_FS_file_information_sync (p); |
420 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 405 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
421 | make_publish_status (&pi, sc, p, 0); | ||
422 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 406 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
423 | pi.value.publish.specifics.error.message = p->emsg; | 407 | pi.value.publish.specifics.error.message = p->emsg; |
424 | p->client_info | 408 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0); |
425 | = sc->h->upcb (sc->h->upcb_cls, | ||
426 | &pi); | ||
427 | } | 409 | } |
428 | /* continue with main */ | 410 | /* continue with main */ |
429 | sc->upload_task | 411 | sc->upload_task |
430 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 412 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, |
431 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 413 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
432 | &do_upload, | 414 | &GNUNET_FS_publish_main_, |
433 | sc); | 415 | sc); |
434 | } | 416 | } |
435 | 417 | ||
436 | 418 | ||
@@ -465,16 +447,16 @@ block_proc (void *cls, | |||
465 | { | 447 | { |
466 | sc->upload_task | 448 | sc->upload_task |
467 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, | 449 | = GNUNET_SCHEDULER_add_with_priority (sc->h->sched, |
468 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 450 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
469 | &do_upload, | 451 | &GNUNET_FS_publish_main_, |
470 | sc); | 452 | sc); |
471 | return; | 453 | return; |
472 | } | 454 | } |
473 | 455 | ||
474 | GNUNET_assert (GNUNET_NO == sc->in_network_wait); | 456 | GNUNET_assert (GNUNET_NO == sc->in_network_wait); |
475 | sc->in_network_wait = GNUNET_YES; | 457 | sc->in_network_wait = GNUNET_YES; |
476 | dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx)); | 458 | dpc_cls = GNUNET_malloc(sizeof(struct PutContCtx)); |
477 | dpc_cls->cont = &do_upload; | 459 | dpc_cls->cont = &GNUNET_FS_publish_main_; |
478 | dpc_cls->cont_cls = sc; | 460 | dpc_cls->cont_cls = sc; |
479 | dpc_cls->sc = sc; | 461 | dpc_cls->sc = sc; |
480 | dpc_cls->p = p; | 462 | dpc_cls->p = p; |
@@ -550,14 +532,11 @@ progress_proc (void *cls, | |||
550 | 532 | ||
551 | p = sc->fi_pos; | 533 | p = sc->fi_pos; |
552 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; | 534 | pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; |
553 | make_publish_status (&pi, sc, p, offset); | ||
554 | pi.value.publish.specifics.progress.data = pt_block; | 535 | pi.value.publish.specifics.progress.data = pt_block; |
555 | pi.value.publish.specifics.progress.offset = offset; | 536 | pi.value.publish.specifics.progress.offset = offset; |
556 | pi.value.publish.specifics.progress.data_len = pt_size; | 537 | pi.value.publish.specifics.progress.data_len = pt_size; |
557 | pi.value.publish.specifics.progress.depth = depth; | 538 | pi.value.publish.specifics.progress.depth = depth; |
558 | p->client_info | 539 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, offset); |
559 | = sc->h->upcb (sc->h->upcb_cls, | ||
560 | &pi); | ||
561 | } | 540 | } |
562 | 541 | ||
563 | 542 | ||
@@ -800,12 +779,13 @@ hash_for_index_cb (void *cls, | |||
800 | 779 | ||
801 | /** | 780 | /** |
802 | * Main function that performs the upload. | 781 | * Main function that performs the upload. |
782 | * | ||
803 | * @param cls "struct GNUNET_FS_PublishContext" identifies the upload | 783 | * @param cls "struct GNUNET_FS_PublishContext" identifies the upload |
804 | * @param tc task context | 784 | * @param tc task context |
805 | */ | 785 | */ |
806 | static void | 786 | void |
807 | do_upload (void *cls, | 787 | GNUNET_FS_publish_main_ (void *cls, |
808 | const struct GNUNET_SCHEDULER_TaskContext *tc) | 788 | const struct GNUNET_SCHEDULER_TaskContext *tc) |
809 | { | 789 | { |
810 | struct GNUNET_FS_PublishContext *sc = cls; | 790 | struct GNUNET_FS_PublishContext *sc = cls; |
811 | struct GNUNET_FS_ProgressInfo pi; | 791 | struct GNUNET_FS_ProgressInfo pi; |
@@ -856,12 +836,9 @@ do_upload (void *cls, | |||
856 | } | 836 | } |
857 | GNUNET_FS_file_information_sync (p); | 837 | GNUNET_FS_file_information_sync (p); |
858 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; | 838 | pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; |
859 | make_publish_status (&pi, sc, p, 0); | ||
860 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; | 839 | pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; |
861 | pi.value.publish.specifics.error.message = p->emsg; | 840 | pi.value.publish.specifics.error.message = p->emsg; |
862 | p->client_info | 841 | p->client_info = GNUNET_FS_publish_make_status_ (&pi, sc, p, 0); |
863 | = sc->h->upcb (sc->h->upcb_cls, | ||
864 | &pi); | ||
865 | } | 842 | } |
866 | sc->all_done = GNUNET_YES; | 843 | sc->all_done = GNUNET_YES; |
867 | return; | 844 | return; |
@@ -953,9 +930,7 @@ fip_signal_start(void *cls, | |||
953 | struct GNUNET_FS_ProgressInfo pi; | 930 | struct GNUNET_FS_ProgressInfo pi; |
954 | 931 | ||
955 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; | 932 | pi.status = GNUNET_FS_STATUS_PUBLISH_START; |
956 | make_publish_status (&pi, sc, fi, 0); | 933 | *client_info = GNUNET_FS_publish_make_status_ (&pi, sc, fi, 0); |
957 | *client_info = sc->h->upcb (sc->h->upcb_cls, | ||
958 | &pi); | ||
959 | return GNUNET_OK; | 934 | return GNUNET_OK; |
960 | } | 935 | } |
961 | 936 | ||
@@ -1018,12 +993,12 @@ GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h, | |||
1018 | 993 | ||
1019 | // FIXME: calculate space needed for "fi" | 994 | // FIXME: calculate space needed for "fi" |
1020 | // and reserve as first task (then trigger | 995 | // and reserve as first task (then trigger |
1021 | // "do_upload" from that continuation)! | 996 | // "publish_main" from that continuation)! |
1022 | ret->upload_task | 997 | ret->upload_task |
1023 | = GNUNET_SCHEDULER_add_with_priority (h->sched, | 998 | = GNUNET_SCHEDULER_add_with_priority (h->sched, |
1024 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, | 999 | GNUNET_SCHEDULER_PRIORITY_BACKGROUND, |
1025 | &do_upload, | 1000 | &GNUNET_FS_publish_main_, |
1026 | ret); | 1001 | ret); |
1027 | return ret; | 1002 | return ret; |
1028 | } | 1003 | } |
1029 | 1004 | ||
@@ -1058,12 +1033,20 @@ fip_signal_stop(void *cls, | |||
1058 | struct GNUNET_FS_ProgressInfo pi; | 1033 | struct GNUNET_FS_ProgressInfo pi; |
1059 | uint64_t off; | 1034 | uint64_t off; |
1060 | 1035 | ||
1036 | if (fi->serialization != NULL) | ||
1037 | { | ||
1038 | if (0 != UNLINK (fi->serialization)) | ||
1039 | { | ||
1040 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
1041 | "unlink", | ||
1042 | fi->serialization); | ||
1043 | } | ||
1044 | GNUNET_free (fi->serialization); | ||
1045 | fi->serialization = NULL; | ||
1046 | } | ||
1061 | off = (fi->chk_uri == NULL) ? 0 : length; | 1047 | off = (fi->chk_uri == NULL) ? 0 : length; |
1062 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; | 1048 | pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; |
1063 | make_publish_status (&pi, sc, fi, off); | 1049 | GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, sc, fi, off)); |
1064 | GNUNET_break (NULL == | ||
1065 | sc->h->upcb (sc->h->upcb_cls, | ||
1066 | &pi)); | ||
1067 | *client_info = NULL; | 1050 | *client_info = NULL; |
1068 | return GNUNET_OK; | 1051 | return GNUNET_OK; |
1069 | } | 1052 | } |
@@ -1075,24 +1058,31 @@ fip_signal_stop(void *cls, | |||
1075 | * simply clean up the state for completed uploads. | 1058 | * simply clean up the state for completed uploads. |
1076 | * Must NOT be called from within the event callback! | 1059 | * Must NOT be called from within the event callback! |
1077 | * | 1060 | * |
1078 | * @param sc context for the upload to stop | 1061 | * @param pc context for the upload to stop |
1079 | */ | 1062 | */ |
1080 | void | 1063 | void |
1081 | GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *sc) | 1064 | GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc) |
1082 | { | 1065 | { |
1083 | if (GNUNET_SCHEDULER_NO_TASK != sc->upload_task) | 1066 | if (GNUNET_SCHEDULER_NO_TASK != pc->upload_task) |
1084 | GNUNET_SCHEDULER_cancel (sc->h->sched, sc->upload_task); | 1067 | GNUNET_SCHEDULER_cancel (pc->h->sched, pc->upload_task); |
1085 | // FIXME: remove from persistence DB (?) --- think more about | 1068 | if (pc->serialization != NULL) |
1086 | // shutdown / persistent-resume APIs!!! | 1069 | { |
1087 | GNUNET_FS_file_information_inspect (sc->fi, | 1070 | if (0 != UNLINK (pc->serialization)) |
1071 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
1072 | "unlink", | ||
1073 | pc->serialization); | ||
1074 | GNUNET_free (pc->serialization); | ||
1075 | pc->serialization = NULL; | ||
1076 | } | ||
1077 | GNUNET_FS_file_information_inspect (pc->fi, | ||
1088 | &fip_signal_stop, | 1078 | &fip_signal_stop, |
1089 | sc); | 1079 | pc); |
1090 | if (GNUNET_YES == sc->in_network_wait) | 1080 | if (GNUNET_YES == pc->in_network_wait) |
1091 | { | 1081 | { |
1092 | sc->in_network_wait = GNUNET_SYSERR; | 1082 | pc->in_network_wait = GNUNET_SYSERR; |
1093 | return; | 1083 | return; |
1094 | } | 1084 | } |
1095 | publish_cleanup (sc); | 1085 | publish_cleanup (pc); |
1096 | } | 1086 | } |
1097 | 1087 | ||
1098 | 1088 | ||