aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_publish.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs_publish.c')
-rw-r--r--src/fs/fs_publish.c1652
1 files changed, 834 insertions, 818 deletions
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index b599bb06e..8bb57b1e2 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -44,10 +44,10 @@
44 * @return value returned from callback 44 * @return value returned from callback
45 */ 45 */
46void * 46void *
47GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi, 47GNUNET_FS_publish_make_status_ (struct GNUNET_FS_ProgressInfo *pi,
48 struct GNUNET_FS_PublishContext *pc, 48 struct GNUNET_FS_PublishContext *pc,
49 const struct GNUNET_FS_FileInformation *p, 49 const struct GNUNET_FS_FileInformation *p,
50 uint64_t offset) 50 uint64_t offset)
51{ 51{
52 pi->value.publish.pc = pc; 52 pi->value.publish.pc = pc;
53 pi->value.publish.fi = p; 53 pi->value.publish.fi = p;
@@ -55,16 +55,17 @@ GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi,
55 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info; 55 pi->value.publish.pctx = (NULL == p->dir) ? NULL : p->dir->client_info;
56 pi->value.publish.filename = p->filename; 56 pi->value.publish.filename = p->filename;
57 pi->value.publish.size = 57 pi->value.publish.size =
58 (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; 58 (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size :
59 p->data.file.file_size;
59 pi->value.publish.eta = 60 pi->value.publish.eta =
60 GNUNET_TIME_calculate_eta(p->start_time, offset, 61 GNUNET_TIME_calculate_eta (p->start_time, offset,
61 pi->value.publish.size); 62 pi->value.publish.size);
62 pi->value.publish.completed = offset; 63 pi->value.publish.completed = offset;
63 pi->value.publish.duration = 64 pi->value.publish.duration =
64 GNUNET_TIME_absolute_get_duration(p->start_time); 65 GNUNET_TIME_absolute_get_duration (p->start_time);
65 pi->value.publish.anonymity = p->bo.anonymity_level; 66 pi->value.publish.anonymity = p->bo.anonymity_level;
66 pi->fsh = pc->h; 67 pi->fsh = pc->h;
67 return pc->h->upcb(pc->h->upcb_cls, pi); 68 return pc->h->upcb (pc->h->upcb_cls, pi);
68} 69}
69 70
70 71
@@ -74,31 +75,31 @@ GNUNET_FS_publish_make_status_(struct GNUNET_FS_ProgressInfo *pi,
74 * @param pc struct to clean up 75 * @param pc struct to clean up
75 */ 76 */
76static void 77static void
77publish_cleanup(struct GNUNET_FS_PublishContext *pc) 78publish_cleanup (struct GNUNET_FS_PublishContext *pc)
78{ 79{
79 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "Cleaning up publish context (done!)\n"); 81 "Cleaning up publish context (done!)\n");
81 if (NULL != pc->fhc) 82 if (NULL != pc->fhc)
82 { 83 {
83 GNUNET_CRYPTO_hash_file_cancel(pc->fhc); 84 GNUNET_CRYPTO_hash_file_cancel (pc->fhc);
84 pc->fhc = NULL; 85 pc->fhc = NULL;
85 } 86 }
86 GNUNET_FS_file_information_destroy(pc->fi, NULL, NULL); 87 GNUNET_FS_file_information_destroy (pc->fi, NULL, NULL);
87 GNUNET_free_non_null(pc->nid); 88 GNUNET_free_non_null (pc->nid);
88 GNUNET_free_non_null(pc->nuid); 89 GNUNET_free_non_null (pc->nuid);
89 GNUNET_free_non_null(pc->serialization); 90 GNUNET_free_non_null (pc->serialization);
90 if (NULL != pc->dsh) 91 if (NULL != pc->dsh)
91 { 92 {
92 GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); 93 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
93 pc->dsh = NULL; 94 pc->dsh = NULL;
94 } 95 }
95 if (NULL != pc->mq) 96 if (NULL != pc->mq)
96 { 97 {
97 GNUNET_MQ_destroy(pc->mq); 98 GNUNET_MQ_destroy (pc->mq);
98 pc->mq = NULL; 99 pc->mq = NULL;
99 } 100 }
100 GNUNET_assert(NULL == pc->upload_task); 101 GNUNET_assert (NULL == pc->upload_task);
101 GNUNET_free(pc); 102 GNUNET_free (pc);
102} 103}
103 104
104 105
@@ -112,42 +113,42 @@ publish_cleanup(struct GNUNET_FS_PublishContext *pc)
112 * @param msg error message (or NULL) 113 * @param msg error message (or NULL)
113 */ 114 */
114static void 115static void
115ds_put_cont(void *cls, 116ds_put_cont (void *cls,
116 int success, 117 int success,
117 struct GNUNET_TIME_Absolute min_expiration, 118 struct GNUNET_TIME_Absolute min_expiration,
118 const char *msg) 119 const char *msg)
119{ 120{
120 struct GNUNET_FS_PublishContext *pc = cls; 121 struct GNUNET_FS_PublishContext *pc = cls;
121 struct GNUNET_FS_ProgressInfo pi; 122 struct GNUNET_FS_ProgressInfo pi;
122 123
123 pc->qre = NULL; 124 pc->qre = NULL;
124 if (GNUNET_SYSERR == success) 125 if (GNUNET_SYSERR == success)
126 {
127 GNUNET_asprintf (&pc->fi_pos->emsg,
128 _ ("Publishing failed: %s"),
129 msg);
130 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
131 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
132 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
133 pc->fi_pos->client_info =
134 GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi_pos, 0);
135 if ((GNUNET_YES != pc->fi_pos->is_directory) &&
136 (NULL != pc->fi_pos->filename) &&
137 (GNUNET_YES == pc->any_done) &&
138 (GNUNET_YES == pc->fi_pos->data.file.do_index))
125 { 139 {
126 GNUNET_asprintf(&pc->fi_pos->emsg, 140 /* run unindex to clean up */
127 _("Publishing failed: %s"), 141 GNUNET_FS_unindex_start (pc->h,
128 msg); 142 pc->fi_pos->filename,
129 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 143 NULL);
130 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
131 pi.value.publish.specifics.error.message = pc->fi_pos->emsg;
132 pc->fi_pos->client_info =
133 GNUNET_FS_publish_make_status_(&pi, pc, pc->fi_pos, 0);
134 if ((GNUNET_YES != pc->fi_pos->is_directory) &&
135 (NULL != pc->fi_pos->filename) &&
136 (GNUNET_YES == pc->any_done) &&
137 (GNUNET_YES == pc->fi_pos->data.file.do_index))
138 {
139 /* run unindex to clean up */
140 GNUNET_FS_unindex_start(pc->h,
141 pc->fi_pos->filename,
142 NULL);
143 }
144 return;
145 } 144 }
145 return;
146 }
146 pc->any_done = GNUNET_YES; 147 pc->any_done = GNUNET_YES;
147 GNUNET_assert(NULL == pc->upload_task); 148 GNUNET_assert (NULL == pc->upload_task);
148 pc->upload_task = 149 pc->upload_task =
149 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 150 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
150 &GNUNET_FS_publish_main_, pc); 151 &GNUNET_FS_publish_main_, pc);
151} 152}
152 153
153 154
@@ -160,8 +161,8 @@ ds_put_cont(void *cls,
160 * @param pc context of the publication 161 * @param pc context of the publication
161 */ 162 */
162static void 163static void
163signal_publish_completion(struct GNUNET_FS_FileInformation *p, 164signal_publish_completion (struct GNUNET_FS_FileInformation *p,
164 struct GNUNET_FS_PublishContext *pc) 165 struct GNUNET_FS_PublishContext *pc)
165{ 166{
166 struct GNUNET_FS_ProgressInfo pi; 167 struct GNUNET_FS_ProgressInfo pi;
167 168
@@ -170,8 +171,8 @@ signal_publish_completion(struct GNUNET_FS_FileInformation *p,
170 pi.value.publish.specifics.completed.chk_uri = p->chk_uri; 171 pi.value.publish.specifics.completed.chk_uri = p->chk_uri;
171 pi.value.publish.specifics.completed.sks_uri = p->sks_uri; 172 pi.value.publish.specifics.completed.sks_uri = p->sks_uri;
172 p->client_info = 173 p->client_info =
173 GNUNET_FS_publish_make_status_(&pi, pc, p, 174 GNUNET_FS_publish_make_status_ (&pi, pc, p,
174 p->data.file.file_size); 175 p->data.file.file_size);
175} 176}
176 177
177 178
@@ -185,27 +186,27 @@ signal_publish_completion(struct GNUNET_FS_FileInformation *p,
185 * @param emsg error message 186 * @param emsg error message
186 */ 187 */
187static void 188static void
188signal_publish_error(struct GNUNET_FS_FileInformation *p, 189signal_publish_error (struct GNUNET_FS_FileInformation *p,
189 struct GNUNET_FS_PublishContext *pc, 190 struct GNUNET_FS_PublishContext *pc,
190 const char *emsg) 191 const char *emsg)
191{ 192{
192 struct GNUNET_FS_ProgressInfo pi; 193 struct GNUNET_FS_ProgressInfo pi;
193 194
194 p->emsg = GNUNET_strdup(emsg); 195 p->emsg = GNUNET_strdup (emsg);
195 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 196 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
196 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 197 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
197 pi.value.publish.specifics.error.message = emsg; 198 pi.value.publish.specifics.error.message = emsg;
198 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); 199 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
199 if ((p->is_directory != GNUNET_YES) && 200 if ((p->is_directory != GNUNET_YES) &&
200 (NULL != p->filename) && 201 (NULL != p->filename) &&
201 (GNUNET_YES == pc->any_done) && 202 (GNUNET_YES == pc->any_done) &&
202 (p->data.file.do_index == GNUNET_YES)) 203 (p->data.file.do_index == GNUNET_YES))
203 { 204 {
204 /* run unindex to clean up */ 205 /* run unindex to clean up */
205 GNUNET_FS_unindex_start(pc->h, 206 GNUNET_FS_unindex_start (pc->h,
206 p->filename, 207 p->filename,
207 NULL); 208 NULL);
208 } 209 }
209} 210}
210 211
211 212
@@ -218,18 +219,18 @@ signal_publish_error(struct GNUNET_FS_FileInformation *p,
218 * @param msg error message (typically NULL, not used) 219 * @param msg error message (typically NULL, not used)
219 */ 220 */
220static void 221static void
221finish_release_reserve(void *cls, int success, 222finish_release_reserve (void *cls, int success,
222 struct GNUNET_TIME_Absolute min_expiration, 223 struct GNUNET_TIME_Absolute min_expiration,
223 const char *msg) 224 const char *msg)
224{ 225{
225 struct GNUNET_FS_PublishContext *pc = cls; 226 struct GNUNET_FS_PublishContext *pc = cls;
226 227
227 pc->qre = NULL; 228 pc->qre = NULL;
228 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
229 "Releasing reserve done!\n"); 230 "Releasing reserve done!\n");
230 signal_publish_completion(pc->fi, pc); 231 signal_publish_completion (pc->fi, pc);
231 pc->all_done = GNUNET_YES; 232 pc->all_done = GNUNET_YES;
232 GNUNET_FS_publish_sync_(pc); 233 GNUNET_FS_publish_sync_ (pc);
233} 234}
234 235
235 236
@@ -242,35 +243,35 @@ finish_release_reserve(void *cls, int success,
242 * @param emsg NULL on success, otherwise error message 243 * @param emsg NULL on success, otherwise error message
243 */ 244 */
244static void 245static void
245publish_sblocks_cont(void *cls, 246publish_sblocks_cont (void *cls,
246 const struct GNUNET_FS_Uri *uri, 247 const struct GNUNET_FS_Uri *uri,
247 const char *emsg) 248 const char *emsg)
248{ 249{
249 struct GNUNET_FS_PublishContext *pc = cls; 250 struct GNUNET_FS_PublishContext *pc = cls;
250 251
251 pc->sks_pc = NULL; 252 pc->sks_pc = NULL;
252 if (NULL != emsg) 253 if (NULL != emsg)
253 { 254 {
254 signal_publish_error(pc->fi, pc, emsg); 255 signal_publish_error (pc->fi, pc, emsg);
255 GNUNET_FS_publish_sync_(pc); 256 GNUNET_FS_publish_sync_ (pc);
256 return; 257 return;
257 } 258 }
258 if (NULL != uri) 259 if (NULL != uri)
259 { 260 {
260 /* sks publication, remember namespace URI */ 261 /* sks publication, remember namespace URI */
261 pc->fi->sks_uri = GNUNET_FS_uri_dup(uri); 262 pc->fi->sks_uri = GNUNET_FS_uri_dup (uri);
262 } 263 }
263 GNUNET_assert(pc->qre == NULL); 264 GNUNET_assert (pc->qre == NULL);
264 if ((pc->dsh != NULL) && (pc->rid != 0)) 265 if ((pc->dsh != NULL) && (pc->rid != 0))
265 { 266 {
266 pc->qre = 267 pc->qre =
267 GNUNET_DATASTORE_release_reserve(pc->dsh, pc->rid, UINT_MAX, UINT_MAX, 268 GNUNET_DATASTORE_release_reserve (pc->dsh, pc->rid, UINT_MAX, UINT_MAX,
268 &finish_release_reserve, pc); 269 &finish_release_reserve, pc);
269 } 270 }
270 else 271 else
271 { 272 {
272 finish_release_reserve(pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL); 273 finish_release_reserve (pc, GNUNET_OK, GNUNET_TIME_UNIT_ZERO_ABS, NULL);
273 } 274 }
274} 275}
275 276
276 277
@@ -281,20 +282,20 @@ publish_sblocks_cont(void *cls,
281 * @param pc overall upload data 282 * @param pc overall upload data
282 */ 283 */
283static void 284static void
284publish_sblock(struct GNUNET_FS_PublishContext *pc) 285publish_sblock (struct GNUNET_FS_PublishContext *pc)
285{ 286{
286 if (NULL != pc->ns) 287 if (NULL != pc->ns)
287 pc->sks_pc = GNUNET_FS_publish_sks(pc->h, 288 pc->sks_pc = GNUNET_FS_publish_sks (pc->h,
288 pc->ns, 289 pc->ns,
289 pc->nid, 290 pc->nid,
290 pc->nuid, 291 pc->nuid,
291 pc->fi->meta, 292 pc->fi->meta,
292 pc->fi->chk_uri, 293 pc->fi->chk_uri,
293 &pc->fi->bo, 294 &pc->fi->bo,
294 pc->options, 295 pc->options,
295 &publish_sblocks_cont, pc); 296 &publish_sblocks_cont, pc);
296 else 297 else
297 publish_sblocks_cont(pc, NULL, NULL); 298 publish_sblocks_cont (pc, NULL, NULL);
298} 299}
299 300
300 301
@@ -308,44 +309,44 @@ publish_sblock(struct GNUNET_FS_PublishContext *pc)
308 * @param emsg NULL on success, otherwise error message 309 * @param emsg NULL on success, otherwise error message
309 */ 310 */
310static void 311static void
311publish_kblocks_cont(void *cls, 312publish_kblocks_cont (void *cls,
312 const struct GNUNET_FS_Uri *uri, 313 const struct GNUNET_FS_Uri *uri,
313 const char *emsg) 314 const char *emsg)
314{ 315{
315 struct GNUNET_FS_PublishContext *pc = cls; 316 struct GNUNET_FS_PublishContext *pc = cls;
316 struct GNUNET_FS_FileInformation *p = pc->fi_pos; 317 struct GNUNET_FS_FileInformation *p = pc->fi_pos;
317 318
318 pc->ksk_pc = NULL; 319 pc->ksk_pc = NULL;
319 if (NULL != emsg) 320 if (NULL != emsg)
320 { 321 {
321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322 "Error uploading KSK blocks: %s\n", 323 "Error uploading KSK blocks: %s\n",
323 emsg); 324 emsg);
324 signal_publish_error(p, pc, emsg); 325 signal_publish_error (p, pc, emsg);
325 GNUNET_FS_file_information_sync_(p); 326 GNUNET_FS_file_information_sync_ (p);
326 GNUNET_FS_publish_sync_(pc); 327 GNUNET_FS_publish_sync_ (pc);
327 GNUNET_assert(NULL == pc->upload_task); 328 GNUNET_assert (NULL == pc->upload_task);
328 pc->upload_task = 329 pc->upload_task =
329 GNUNET_SCHEDULER_add_with_priority 330 GNUNET_SCHEDULER_add_with_priority
330 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 331 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
331 &GNUNET_FS_publish_main_, 332 &GNUNET_FS_publish_main_,
332 pc); 333 pc);
333 return; 334 return;
334 } 335 }
335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "KSK blocks published, moving on to next file\n"); 337 "KSK blocks published, moving on to next file\n");
337 if (NULL != p->dir) 338 if (NULL != p->dir)
338 signal_publish_completion(p, pc); 339 signal_publish_completion (p, pc);
339 /* move on to next file */ 340 /* move on to next file */
340 if (NULL != p->next) 341 if (NULL != p->next)
341 pc->fi_pos = p->next; 342 pc->fi_pos = p->next;
342 else 343 else
343 pc->fi_pos = p->dir; 344 pc->fi_pos = p->dir;
344 GNUNET_FS_publish_sync_(pc); 345 GNUNET_FS_publish_sync_ (pc);
345 GNUNET_assert(NULL == pc->upload_task); 346 GNUNET_assert (NULL == pc->upload_task);
346 pc->upload_task = 347 pc->upload_task =
347 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 348 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
348 &GNUNET_FS_publish_main_, pc); 349 &GNUNET_FS_publish_main_, pc);
349} 350}
350 351
351 352
@@ -363,11 +364,11 @@ publish_kblocks_cont(void *cls,
363 * @return number of bytes copied to buf, 0 on error 364 * @return number of bytes copied to buf, 0 on error
364 */ 365 */
365static size_t 366static size_t
366block_reader(void *cls, 367block_reader (void *cls,
367 uint64_t offset, 368 uint64_t offset,
368 size_t max, 369 size_t max,
369 void *buf, 370 void *buf,
370 char **emsg) 371 char **emsg)
371{ 372{
372 struct GNUNET_FS_PublishContext *pc = cls; 373 struct GNUNET_FS_PublishContext *pc = cls;
373 struct GNUNET_FS_FileInformation *p; 374 struct GNUNET_FS_FileInformation *p;
@@ -376,31 +377,31 @@ block_reader(void *cls,
376 377
377 p = pc->fi_pos; 378 p = pc->fi_pos;
378 if (GNUNET_YES == p->is_directory) 379 if (GNUNET_YES == p->is_directory)
379 { 380 {
380 pt_size = GNUNET_MIN(max, p->data.dir.dir_size - offset); 381 pt_size = GNUNET_MIN (max, p->data.dir.dir_size - offset);
381 dd = p->data.dir.dir_data; 382 dd = p->data.dir.dir_data;
382 GNUNET_memcpy(buf, &dd[offset], pt_size); 383 GNUNET_memcpy (buf, &dd[offset], pt_size);
383 } 384 }
384 else 385 else
385 { 386 {
386 if (UINT64_MAX == offset) 387 if (UINT64_MAX == offset)
387 { 388 {
388 if (&GNUNET_FS_data_reader_file_ == p->data.file.reader) 389 if (&GNUNET_FS_data_reader_file_ == p->data.file.reader)
389 { 390 {
390 /* force closing the file to avoid keeping too many files open */ 391 /* force closing the file to avoid keeping too many files open */
391 p->data.file.reader(p->data.file.reader_cls, offset, 0, NULL, NULL); 392 p->data.file.reader (p->data.file.reader_cls, offset, 0, NULL, NULL);
392 } 393 }
393 return 0; 394 return 0;
394 } 395 }
395 pt_size = GNUNET_MIN(max, p->data.file.file_size - offset); 396 pt_size = GNUNET_MIN (max, p->data.file.file_size - offset);
396 if (0 == pt_size) 397 if (0 == pt_size)
397 return 0; /* calling reader with pt_size==0 398 return 0; /* calling reader with pt_size==0
398 * might free buf, so don't! */ 399 * might free buf, so don't! */
399 if (pt_size != 400 if (pt_size !=
400 p->data.file.reader(p->data.file.reader_cls, offset, pt_size, buf, 401 p->data.file.reader (p->data.file.reader_cls, offset, pt_size, buf,
401 emsg)) 402 emsg))
402 return 0; 403 return 0;
403 } 404 }
404 return pt_size; 405 return pt_size;
405} 406}
406 407
@@ -413,7 +414,7 @@ block_reader(void *cls,
413 * @param cls our publishing context 414 * @param cls our publishing context
414 */ 415 */
415static void 416static void
416encode_cont(void *cls) 417encode_cont (void *cls)
417{ 418{
418 struct GNUNET_FS_PublishContext *pc = cls; 419 struct GNUNET_FS_PublishContext *pc = cls;
419 struct GNUNET_FS_FileInformation *p; 420 struct GNUNET_FS_FileInformation *p;
@@ -421,44 +422,44 @@ encode_cont(void *cls)
421 char *emsg; 422 char *emsg;
422 uint64_t flen; 423 uint64_t flen;
423 424
424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 425 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
425 "Finished with tree encoder\n"); 426 "Finished with tree encoder\n");
426 p = pc->fi_pos; 427 p = pc->fi_pos;
427 p->chk_uri = GNUNET_FS_tree_encoder_get_uri(p->te); 428 p->chk_uri = GNUNET_FS_tree_encoder_get_uri (p->te);
428 GNUNET_FS_file_information_sync_(p); 429 GNUNET_FS_file_information_sync_ (p);
429 GNUNET_FS_tree_encoder_finish(p->te, &emsg); 430 GNUNET_FS_tree_encoder_finish (p->te, &emsg);
430 p->te = NULL; 431 p->te = NULL;
431 if (NULL != emsg) 432 if (NULL != emsg)
432 { 433 {
433 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
434 "Error during tree walk: %s\n", 435 "Error during tree walk: %s\n",
435 emsg); 436 emsg);
436 GNUNET_asprintf(&p->emsg, 437 GNUNET_asprintf (&p->emsg,
437 _("Publishing failed: %s"), 438 _ ("Publishing failed: %s"),
438 emsg); 439 emsg);
439 GNUNET_free(emsg); 440 GNUNET_free (emsg);
440 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 441 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
441 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 442 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
442 pi.value.publish.specifics.error.message = p->emsg; 443 pi.value.publish.specifics.error.message = p->emsg;
443 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); 444 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
444 } 445 }
445 else 446 else
446 { 447 {
447 /* final progress event */ 448 /* final progress event */
448 GNUNET_assert(NULL != p->chk_uri); 449 GNUNET_assert (NULL != p->chk_uri);
449 flen = GNUNET_FS_uri_chk_get_file_size(p->chk_uri); 450 flen = GNUNET_FS_uri_chk_get_file_size (p->chk_uri);
450 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS; 451 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS;
451 pi.value.publish.specifics.progress.data = NULL; 452 pi.value.publish.specifics.progress.data = NULL;
452 pi.value.publish.specifics.progress.offset = flen; 453 pi.value.publish.specifics.progress.offset = flen;
453 pi.value.publish.specifics.progress.data_len = 0; 454 pi.value.publish.specifics.progress.data_len = 0;
454 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth(flen); 455 pi.value.publish.specifics.progress.depth = GNUNET_FS_compute_depth (flen);
455 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, flen); 456 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, flen);
456 } 457 }
457 /* continue with main */ /* continue with main */ 458 /* continue with main */ /* continue with main */
458 GNUNET_assert(NULL == pc->upload_task); 459 GNUNET_assert (NULL == pc->upload_task);
459 pc->upload_task = 460 pc->upload_task =
460 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 461 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
461 &GNUNET_FS_publish_main_, pc); 462 &GNUNET_FS_publish_main_, pc);
462} 463}
463 464
464 465
@@ -477,13 +478,13 @@ encode_cont(void *cls)
477 * @param block_size size of @a block (in bytes) 478 * @param block_size size of @a block (in bytes)
478 */ 479 */
479static void 480static void
480block_proc(void *cls, 481block_proc (void *cls,
481 const struct ContentHashKey *chk, 482 const struct ContentHashKey *chk,
482 uint64_t offset, 483 uint64_t offset,
483 unsigned int depth, 484 unsigned int depth,
484 enum GNUNET_BLOCK_Type type, 485 enum GNUNET_BLOCK_Type type,
485 const void *block, 486 const void *block,
486 uint16_t block_size) 487 uint16_t block_size)
487{ 488{
488 struct GNUNET_FS_PublishContext *pc = cls; 489 struct GNUNET_FS_PublishContext *pc = cls;
489 struct GNUNET_FS_FileInformation *p; 490 struct GNUNET_FS_FileInformation *p;
@@ -491,62 +492,63 @@ block_proc(void *cls,
491 492
492 p = pc->fi_pos; 493 p = pc->fi_pos;
493 if (NULL == pc->dsh) 494 if (NULL == pc->dsh)
494 { 495 {
495 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
496 "Waiting for datastore connection\n"); 497 "Waiting for datastore connection\n");
497 GNUNET_assert(NULL == pc->upload_task); 498 GNUNET_assert (NULL == pc->upload_task);
498 pc->upload_task = 499 pc->upload_task =
499 GNUNET_SCHEDULER_add_with_priority 500 GNUNET_SCHEDULER_add_with_priority
500 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc); 501 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, pc);
501 return; 502 return;
502 } 503 }
503 504
504 if ((GNUNET_YES != p->is_directory) && 505 if ((GNUNET_YES != p->is_directory) &&
505 (GNUNET_YES == p->data.file.do_index) && 506 (GNUNET_YES == p->data.file.do_index) &&
506 (GNUNET_BLOCK_TYPE_FS_DBLOCK == type)) 507 (GNUNET_BLOCK_TYPE_FS_DBLOCK == type))
507 { 508 {
508 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
509 "Indexing block `%s' for offset %llu with index size %u\n", 510 "Indexing block `%s' for offset %llu with index size %u\n",
510 GNUNET_h2s(&chk->query), 511 GNUNET_h2s (&chk->query),
511 (unsigned long long)offset, 512 (unsigned long long) offset,
512 (unsigned int)sizeof(struct OnDemandBlock)); 513 (unsigned int) sizeof(struct OnDemandBlock));
513 odb.offset = GNUNET_htonll(offset); 514 odb.offset = GNUNET_htonll (offset);
514 odb.file_id = p->data.file.file_id; 515 odb.file_id = p->data.file.file_id;
515 GNUNET_assert(pc->qre == NULL); 516 GNUNET_assert (pc->qre == NULL);
516 pc->qre = 517 pc->qre =
517 GNUNET_DATASTORE_put(pc->dsh, 518 GNUNET_DATASTORE_put (pc->dsh,
518 (p->is_directory == GNUNET_YES) ? 0 : pc->rid, 519 (p->is_directory == GNUNET_YES) ? 0 : pc->rid,
519 &chk->query, 520 &chk->query,
520 sizeof(struct OnDemandBlock), 521 sizeof(struct OnDemandBlock),
521 &odb, 522 &odb,
522 GNUNET_BLOCK_TYPE_FS_ONDEMAND, 523 GNUNET_BLOCK_TYPE_FS_ONDEMAND,
523 p->bo.content_priority, 524 p->bo.content_priority,
524 p->bo.anonymity_level, 525 p->bo.anonymity_level,
525 p->bo.replication_level, 526 p->bo.replication_level,
526 p->bo.expiration_time, 527 p->bo.expiration_time,
527 -2, 1, 528 -2, 1,
528 &ds_put_cont, pc); 529 &ds_put_cont, pc);
529 return; 530 return;
530 } 531 }
531 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
532 "Publishing block `%s' for offset %llu with size %u\n", 533 "Publishing block `%s' for offset %llu with size %u\n",
533 GNUNET_h2s(&chk->query), 534 GNUNET_h2s (&chk->query),
534 (unsigned long long)offset, 535 (unsigned long long) offset,
535 (unsigned int)block_size); 536 (unsigned int) block_size);
536 GNUNET_assert(pc->qre == NULL); 537 GNUNET_assert (pc->qre == NULL);
537 pc->qre = 538 pc->qre =
538 GNUNET_DATASTORE_put(pc->dsh, (p->is_directory == GNUNET_YES) ? 0 : pc->rid, 539 GNUNET_DATASTORE_put (pc->dsh, (p->is_directory == GNUNET_YES) ? 0 :
539 &chk->query, 540 pc->rid,
540 block_size, 541 &chk->query,
541 block, 542 block_size,
542 type, 543 block,
543 p->bo.content_priority, 544 type,
544 p->bo.anonymity_level, 545 p->bo.content_priority,
545 p->bo.replication_level, 546 p->bo.anonymity_level,
546 p->bo.expiration_time, 547 p->bo.replication_level,
547 -2, 1, 548 p->bo.expiration_time,
548 &ds_put_cont, 549 -2, 1,
549 pc); 550 &ds_put_cont,
551 pc);
550} 552}
551 553
552 554
@@ -561,10 +563,10 @@ block_proc(void *cls,
561 * @param depth depth of the block in the tree, 0 for DBLOCK 563 * @param depth depth of the block in the tree, 0 for DBLOCK
562 */ 564 */
563static void 565static void
564progress_proc(void *cls, uint64_t offset, 566progress_proc (void *cls, uint64_t offset,
565 const void *pt_block, 567 const void *pt_block,
566 size_t pt_size, 568 size_t pt_size,
567 unsigned int depth) 569 unsigned int depth)
568{ 570{
569 struct GNUNET_FS_PublishContext *pc = cls; 571 struct GNUNET_FS_PublishContext *pc = cls;
570 struct GNUNET_FS_FileInformation *p; 572 struct GNUNET_FS_FileInformation *p;
@@ -577,23 +579,28 @@ progress_proc(void *cls, uint64_t offset,
577 pi.value.publish.specifics.progress.offset = offset; 579 pi.value.publish.specifics.progress.offset = offset;
578 pi.value.publish.specifics.progress.data_len = pt_size; 580 pi.value.publish.specifics.progress.data_len = pt_size;
579 pi.value.publish.specifics.progress.depth = depth; 581 pi.value.publish.specifics.progress.depth = depth;
580 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, offset); 582 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, offset);
581 if ((0 != depth) || 583 if ((0 != depth) ||
582 (GNUNET_YES == p->is_directory)) 584 (GNUNET_YES == p->is_directory))
583 return; 585 return;
584 while (NULL != (par = p->dir)) 586 while (NULL != (par = p->dir))
585 { 587 {
586 p = par; 588 p = par;
587 GNUNET_assert(GNUNET_YES == par->is_directory); 589 GNUNET_assert (GNUNET_YES == par->is_directory);
588 p->data.dir.contents_completed += pt_size; 590 p->data.dir.contents_completed += pt_size;
589 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY; 591 pi.status = GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY;
590 pi.value.publish.specifics.progress_directory.completed = p->data.dir.contents_completed; 592 pi.value.publish.specifics.progress_directory.completed =
591 pi.value.publish.specifics.progress_directory.total = p->data.dir.contents_size; 593 p->data.dir.contents_completed;
592 pi.value.publish.specifics.progress_directory.eta = GNUNET_TIME_calculate_eta(p->start_time, 594 pi.value.publish.specifics.progress_directory.total =
593 p->data.dir.contents_completed, 595 p->data.dir.contents_size;
594 p->data.dir.contents_size); 596 pi.value.publish.specifics.progress_directory.eta =
595 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); 597 GNUNET_TIME_calculate_eta (p->start_time,
596 } 598 p
599 ->data.dir.contents_completed,
600 p
601 ->data.dir.contents_size);
602 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
603 }
597} 604}
598 605
599 606
@@ -605,7 +612,7 @@ progress_proc(void *cls, uint64_t offset,
605 * @param pc overall upload data 612 * @param pc overall upload data
606 */ 613 */
607static void 614static void
608publish_content(struct GNUNET_FS_PublishContext *pc) 615publish_content (struct GNUNET_FS_PublishContext *pc)
609{ 616{
610 struct GNUNET_FS_FileInformation *p; 617 struct GNUNET_FS_FileInformation *p;
611 char *emsg; 618 char *emsg;
@@ -615,64 +622,66 @@ publish_content(struct GNUNET_FS_PublishContext *pc)
615 uint64_t size; 622 uint64_t size;
616 623
617 p = pc->fi_pos; 624 p = pc->fi_pos;
618 GNUNET_assert(NULL != p); 625 GNUNET_assert (NULL != p);
619 if (NULL == p->te) 626 if (NULL == p->te)
620 { 627 {
621 if (GNUNET_YES == p->is_directory) 628 if (GNUNET_YES == p->is_directory)
629 {
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n");
631 db = GNUNET_FS_directory_builder_create (p->meta);
632 dirpos = p->data.dir.entries;
633 while (NULL != dirpos)
634 {
635 if (GNUNET_YES == dirpos->is_directory)
636 {
637 raw_data = dirpos->data.dir.dir_data;
638 dirpos->data.dir.dir_data = NULL;
639 }
640 else
622 { 641 {
623 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Creating directory\n"); 642 raw_data = NULL;
624 db = GNUNET_FS_directory_builder_create(p->meta); 643 if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
625 dirpos = p->data.dir.entries; 644 (dirpos->data.file.file_size > 0))
626 while (NULL != dirpos) 645 {
646 raw_data = GNUNET_malloc (dirpos->data.file.file_size);
647 emsg = NULL;
648 if (dirpos->data.file.file_size !=
649 dirpos->data.file.reader (dirpos->data.file.reader_cls, 0,
650 dirpos->data.file.file_size, raw_data,
651 &emsg))
627 { 652 {
628 if (GNUNET_YES == dirpos->is_directory) 653 GNUNET_free_non_null (emsg);
629 { 654 GNUNET_free (raw_data);
630 raw_data = dirpos->data.dir.dir_data; 655 raw_data = NULL;
631 dirpos->data.dir.dir_data = NULL;
632 }
633 else
634 {
635 raw_data = NULL;
636 if ((dirpos->data.file.file_size < MAX_INLINE_SIZE) &&
637 (dirpos->data.file.file_size > 0))
638 {
639 raw_data = GNUNET_malloc(dirpos->data.file.file_size);
640 emsg = NULL;
641 if (dirpos->data.file.file_size !=
642 dirpos->data.file.reader(dirpos->data.file.reader_cls, 0,
643 dirpos->data.file.file_size, raw_data,
644 &emsg))
645 {
646 GNUNET_free_non_null(emsg);
647 GNUNET_free(raw_data);
648 raw_data = NULL;
649 }
650 dirpos->data.file.reader(dirpos->data.file.reader_cls, UINT64_MAX, 0, 0, NULL);
651 }
652 }
653 GNUNET_FS_directory_builder_add(db, dirpos->chk_uri, dirpos->meta,
654 raw_data);
655 GNUNET_free_non_null(raw_data);
656 dirpos = dirpos->next;
657 } 656 }
658 GNUNET_free_non_null(p->data.dir.dir_data); 657 dirpos->data.file.reader (dirpos->data.file.reader_cls, UINT64_MAX,
659 p->data.dir.dir_data = NULL; 658 0, 0, NULL);
660 p->data.dir.dir_size = 0; 659 }
661 GNUNET_FS_directory_builder_finish(db, &p->data.dir.dir_size,
662 &p->data.dir.dir_data);
663 GNUNET_FS_file_information_sync_(p);
664 } 660 }
665 size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; 661 GNUNET_FS_directory_builder_add (db, dirpos->chk_uri, dirpos->meta,
666 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 662 raw_data);
667 "Creating tree encoder\n"); 663 GNUNET_free_non_null (raw_data);
668 p->te = 664 dirpos = dirpos->next;
669 GNUNET_FS_tree_encoder_create(pc->h, size, pc, &block_reader, 665 }
670 &block_proc, &progress_proc, 666 GNUNET_free_non_null (p->data.dir.dir_data);
671 &encode_cont); 667 p->data.dir.dir_data = NULL;
672 } 668 p->data.dir.dir_size = 0;
673 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 669 GNUNET_FS_directory_builder_finish (db, &p->data.dir.dir_size,
674 "Processing next block from tree\n"); 670 &p->data.dir.dir_data);
675 GNUNET_FS_tree_encoder_next(p->te); 671 GNUNET_FS_file_information_sync_ (p);
672 }
673 size = (GNUNET_YES == p->is_directory) ? p->data.dir.dir_size :
674 p->data.file.file_size;
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 "Creating tree encoder\n");
677 p->te =
678 GNUNET_FS_tree_encoder_create (pc->h, size, pc, &block_reader,
679 &block_proc, &progress_proc,
680 &encode_cont);
681 }
682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
683 "Processing next block from tree\n");
684 GNUNET_FS_tree_encoder_next (p->te);
676} 685}
677 686
678 687
@@ -684,17 +693,17 @@ publish_content(struct GNUNET_FS_PublishContext *pc)
684 * @param msg the response we got 693 * @param msg the response we got
685 */ 694 */
686static int 695static int
687check_index_start_failed(void *cls, 696check_index_start_failed (void *cls,
688 const struct GNUNET_MessageHeader *msg) 697 const struct GNUNET_MessageHeader *msg)
689{ 698{
690 size_t msize = ntohs(msg->size) - sizeof(*msg); 699 size_t msize = ntohs (msg->size) - sizeof(*msg);
691 const char *emsg = (const char *)&msg[1]; 700 const char *emsg = (const char *) &msg[1];
692 701
693 if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0') 702 if (emsg[msize - sizeof(struct GNUNET_MessageHeader) - 1] != '\0')
694 { 703 {
695 GNUNET_break(0); 704 GNUNET_break (0);
696 return GNUNET_SYSERR; 705 return GNUNET_SYSERR;
697 } 706 }
698 return GNUNET_OK; 707 return GNUNET_OK;
699} 708}
700 709
@@ -707,27 +716,27 @@ check_index_start_failed(void *cls,
707 * @param msg the response we got 716 * @param msg the response we got
708 */ 717 */
709static void 718static void
710handle_index_start_failed(void *cls, 719handle_index_start_failed (void *cls,
711 const struct GNUNET_MessageHeader *msg) 720 const struct GNUNET_MessageHeader *msg)
712{ 721{
713 struct GNUNET_FS_PublishContext *pc = cls; 722 struct GNUNET_FS_PublishContext *pc = cls;
714 struct GNUNET_FS_FileInformation *p; 723 struct GNUNET_FS_FileInformation *p;
715 const char *emsg = (const char *)&msg[1]; 724 const char *emsg = (const char *) &msg[1];
716 char *msgtxt; 725 char *msgtxt;
717 726
718 GNUNET_MQ_destroy(pc->mq); 727 GNUNET_MQ_destroy (pc->mq);
719 pc->mq = NULL; 728 pc->mq = NULL;
720 p = pc->fi_pos; 729 p = pc->fi_pos;
721 GNUNET_asprintf(&msgtxt, 730 GNUNET_asprintf (&msgtxt,
722 _("Can not index file `%s': %s.\n"), 731 _ ("Can not index file `%s': %s.\n"),
723 p->filename, 732 p->filename,
724 gettext(emsg)); 733 gettext (emsg));
725 signal_publish_error(p, 734 signal_publish_error (p,
726 pc, 735 pc,
727 msgtxt); 736 msgtxt);
728 GNUNET_free(msgtxt); 737 GNUNET_free (msgtxt);
729 GNUNET_FS_file_information_sync_(p); 738 GNUNET_FS_file_information_sync_ (p);
730 GNUNET_FS_publish_sync_(pc); 739 GNUNET_FS_publish_sync_ (pc);
731} 740}
732 741
733 742
@@ -739,18 +748,18 @@ handle_index_start_failed(void *cls,
739 * @param msg the response we got 748 * @param msg the response we got
740 */ 749 */
741static void 750static void
742handle_index_start_ok(void *cls, 751handle_index_start_ok (void *cls,
743 const struct GNUNET_MessageHeader *msg) 752 const struct GNUNET_MessageHeader *msg)
744{ 753{
745 struct GNUNET_FS_PublishContext *pc = cls; 754 struct GNUNET_FS_PublishContext *pc = cls;
746 struct GNUNET_FS_FileInformation *p; 755 struct GNUNET_FS_FileInformation *p;
747 756
748 GNUNET_MQ_destroy(pc->mq); 757 GNUNET_MQ_destroy (pc->mq);
749 pc->mq = NULL; 758 pc->mq = NULL;
750 p = pc->fi_pos; 759 p = pc->fi_pos;
751 p->data.file.index_start_confirmed = GNUNET_YES; 760 p->data.file.index_start_confirmed = GNUNET_YES;
752 GNUNET_FS_file_information_sync_(p); 761 GNUNET_FS_file_information_sync_ (p);
753 publish_content(pc); 762 publish_content (pc);
754} 763}
755 764
756 765
@@ -763,25 +772,25 @@ handle_index_start_ok(void *cls,
763 * @param error error code 772 * @param error error code
764 */ 773 */
765static void 774static void
766index_mq_error_handler(void *cls, 775index_mq_error_handler (void *cls,
767 enum GNUNET_MQ_Error error) 776 enum GNUNET_MQ_Error error)
768{ 777{
769 struct GNUNET_FS_PublishContext *pc = cls; 778 struct GNUNET_FS_PublishContext *pc = cls;
770 struct GNUNET_FS_FileInformation *p; 779 struct GNUNET_FS_FileInformation *p;
771 780
772 if (NULL != pc->mq) 781 if (NULL != pc->mq)
773 { 782 {
774 GNUNET_MQ_destroy(pc->mq); 783 GNUNET_MQ_destroy (pc->mq);
775 pc->mq = NULL; 784 pc->mq = NULL;
776 } 785 }
777 p = pc->fi_pos; 786 p = pc->fi_pos;
778 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 787 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
779 _("Can not index file `%s': %s. Will try to insert instead.\n"), 788 _ ("Can not index file `%s': %s. Will try to insert instead.\n"),
780 p->filename, 789 p->filename,
781 _("error on index-start request to `fs' service")); 790 _ ("error on index-start request to `fs' service"));
782 p->data.file.do_index = GNUNET_NO; 791 p->data.file.do_index = GNUNET_NO;
783 GNUNET_FS_file_information_sync_(p); 792 GNUNET_FS_file_information_sync_ (p);
784 publish_content(pc); 793 publish_content (pc);
785} 794}
786 795
787 796
@@ -793,20 +802,20 @@ index_mq_error_handler(void *cls,
793 * @param res resulting hash, NULL on error 802 * @param res resulting hash, NULL on error
794 */ 803 */
795static void 804static void
796hash_for_index_cb(void *cls, 805hash_for_index_cb (void *cls,
797 const struct GNUNET_HashCode *res) 806 const struct GNUNET_HashCode *res)
798{ 807{
799 struct GNUNET_FS_PublishContext *pc = cls; 808 struct GNUNET_FS_PublishContext *pc = cls;
800 struct GNUNET_MQ_MessageHandler handlers[] = { 809 struct GNUNET_MQ_MessageHandler handlers[] = {
801 GNUNET_MQ_hd_fixed_size(index_start_ok, 810 GNUNET_MQ_hd_fixed_size (index_start_ok,
802 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK, 811 GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK,
803 struct GNUNET_MessageHeader, 812 struct GNUNET_MessageHeader,
804 pc), 813 pc),
805 GNUNET_MQ_hd_var_size(index_start_failed, 814 GNUNET_MQ_hd_var_size (index_start_failed,
806 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED, 815 GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED,
807 struct GNUNET_MessageHeader, 816 struct GNUNET_MessageHeader,
808 pc), 817 pc),
809 GNUNET_MQ_handler_end() 818 GNUNET_MQ_handler_end ()
810 }; 819 };
811 struct GNUNET_FS_FileInformation *p; 820 struct GNUNET_FS_FileInformation *p;
812 struct GNUNET_MQ_Envelope *env; 821 struct GNUNET_MQ_Envelope *env;
@@ -819,97 +828,99 @@ hash_for_index_cb(void *cls,
819 pc->fhc = NULL; 828 pc->fhc = NULL;
820 p = pc->fi_pos; 829 p = pc->fi_pos;
821 if (NULL == res) 830 if (NULL == res)
822 { 831 {
823 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 832 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
824 _("Can not index file `%s': %s. Will try to insert instead.\n"), 833 _ (
825 p->filename, 834 "Can not index file `%s': %s. Will try to insert instead.\n"),
826 _("failed to compute hash")); 835 p->filename,
827 p->data.file.do_index = GNUNET_NO; 836 _ ("failed to compute hash"));
828 GNUNET_FS_file_information_sync_(p); 837 p->data.file.do_index = GNUNET_NO;
829 publish_content(pc); 838 GNUNET_FS_file_information_sync_ (p);
830 return; 839 publish_content (pc);
831 } 840 return;
841 }
832 if (GNUNET_YES == p->data.file.index_start_confirmed) 842 if (GNUNET_YES == p->data.file.index_start_confirmed)
833 { 843 {
834 publish_content(pc); 844 publish_content (pc);
835 return; 845 return;
836 } 846 }
837 fn = GNUNET_STRINGS_filename_expand(p->filename); 847 fn = GNUNET_STRINGS_filename_expand (p->filename);
838 GNUNET_assert(fn != NULL); 848 GNUNET_assert (fn != NULL);
839 slen = strlen(fn) + 1; 849 slen = strlen (fn) + 1;
840 if (slen >= 850 if (slen >=
841 GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage)) 851 GNUNET_MAX_MESSAGE_SIZE - sizeof(struct IndexStartMessage))
842 { 852 {
843 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 853 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
844 _ 854 _
845 ("Can not index file `%s': %s. Will try to insert instead.\n"), 855 ("Can not index file `%s': %s. Will try to insert instead.\n"),
846 fn, _("filename too long")); 856 fn, _ ("filename too long"));
847 GNUNET_free(fn); 857 GNUNET_free (fn);
848 p->data.file.do_index = GNUNET_NO; 858 p->data.file.do_index = GNUNET_NO;
849 GNUNET_FS_file_information_sync_(p); 859 GNUNET_FS_file_information_sync_ (p);
850 publish_content(pc); 860 publish_content (pc);
851 return; 861 return;
852 } 862 }
853 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
854 "Hash of indexed file `%s' is `%s'\n", 864 "Hash of indexed file `%s' is `%s'\n",
855 p->filename, 865 p->filename,
856 GNUNET_h2s(res)); 866 GNUNET_h2s (res));
857 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 867 if (0 != (pc->options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
858 { 868 {
859 p->data.file.file_id = *res; 869 p->data.file.file_id = *res;
860 p->data.file.have_hash = GNUNET_YES; 870 p->data.file.have_hash = GNUNET_YES;
861 p->data.file.index_start_confirmed = GNUNET_YES; 871 p->data.file.index_start_confirmed = GNUNET_YES;
862 GNUNET_FS_file_information_sync_(p); 872 GNUNET_FS_file_information_sync_ (p);
863 publish_content(pc); 873 publish_content (pc);
864 GNUNET_free(fn); 874 GNUNET_free (fn);
865 return; 875 return;
866 } 876 }
867 pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, 877 pc->mq = GNUNET_CLIENT_connect (pc->h->cfg,
868 "fs", 878 "fs",
869 handlers, 879 handlers,
870 &index_mq_error_handler, 880 &index_mq_error_handler,
871 pc); 881 pc);
872 if (NULL == pc->mq) 882 if (NULL == pc->mq)
873 { 883 {
874 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 884 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
875 _("Can not index file `%s': %s. Will try to insert instead.\n"), 885 _ (
876 p->filename, 886 "Can not index file `%s': %s. Will try to insert instead.\n"),
877 _("could not connect to `fs' service")); 887 p->filename,
878 p->data.file.do_index = GNUNET_NO; 888 _ ("could not connect to `fs' service"));
879 publish_content(pc); 889 p->data.file.do_index = GNUNET_NO;
880 GNUNET_free(fn); 890 publish_content (pc);
881 return; 891 GNUNET_free (fn);
882 } 892 return;
893 }
883 if (p->data.file.have_hash != GNUNET_YES) 894 if (p->data.file.have_hash != GNUNET_YES)
884 { 895 {
885 p->data.file.file_id = *res; 896 p->data.file.file_id = *res;
886 p->data.file.have_hash = GNUNET_YES; 897 p->data.file.have_hash = GNUNET_YES;
887 GNUNET_FS_file_information_sync_(p); 898 GNUNET_FS_file_information_sync_ (p);
888 } 899 }
889 env = GNUNET_MQ_msg_extra(ism, 900 env = GNUNET_MQ_msg_extra (ism,
890 slen, 901 slen,
891 GNUNET_MESSAGE_TYPE_FS_INDEX_START); 902 GNUNET_MESSAGE_TYPE_FS_INDEX_START);
892 if (GNUNET_OK == 903 if (GNUNET_OK ==
893 GNUNET_DISK_file_get_identifiers(p->filename, 904 GNUNET_DISK_file_get_identifiers (p->filename,
894 &dev, 905 &dev,
895 &ino)) 906 &ino))
896 { 907 {
897 ism->device = GNUNET_htonll(dev); 908 ism->device = GNUNET_htonll (dev);
898 ism->inode = GNUNET_htonll(ino); 909 ism->inode = GNUNET_htonll (ino);
899 } 910 }
900 else 911 else
901 { 912 {
902 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 913 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
903 _("Failed to get file identifiers for `%s'\n"), 914 _ ("Failed to get file identifiers for `%s'\n"),
904 p->filename); 915 p->filename);
905 } 916 }
906 ism->file_id = *res; 917 ism->file_id = *res;
907 GNUNET_memcpy(&ism[1], 918 GNUNET_memcpy (&ism[1],
908 fn, 919 fn,
909 slen); 920 slen);
910 GNUNET_free(fn); 921 GNUNET_free (fn);
911 GNUNET_MQ_send(pc->mq, 922 GNUNET_MQ_send (pc->mq,
912 env); 923 env);
913} 924}
914 925
915 926
@@ -919,27 +930,27 @@ hash_for_index_cb(void *cls,
919 * @param pc publishing context to do this for 930 * @param pc publishing context to do this for
920 */ 931 */
921static void 932static void
922publish_kblocks(struct GNUNET_FS_PublishContext *pc) 933publish_kblocks (struct GNUNET_FS_PublishContext *pc)
923{ 934{
924 struct GNUNET_FS_FileInformation *p; 935 struct GNUNET_FS_FileInformation *p;
925 936
926 p = pc->fi_pos; 937 p = pc->fi_pos;
927 /* upload of "p" complete, publish KBlocks! */ 938 /* upload of "p" complete, publish KBlocks! */
928 if (NULL != p->keywords) 939 if (NULL != p->keywords)
929 { 940 {
930 pc->ksk_pc = GNUNET_FS_publish_ksk(pc->h, 941 pc->ksk_pc = GNUNET_FS_publish_ksk (pc->h,
931 p->keywords, 942 p->keywords,
932 p->meta, 943 p->meta,
933 p->chk_uri, 944 p->chk_uri,
934 &p->bo, 945 &p->bo,
935 pc->options, 946 pc->options,
936 &publish_kblocks_cont, 947 &publish_kblocks_cont,
937 pc); 948 pc);
938 } 949 }
939 else 950 else
940 { 951 {
941 publish_kblocks_cont(pc, p->chk_uri, NULL); 952 publish_kblocks_cont (pc, p->chk_uri, NULL);
942 } 953 }
943} 954}
944 955
945 956
@@ -950,8 +961,8 @@ publish_kblocks(struct GNUNET_FS_PublishContext *pc)
950 * @param sig the response we got 961 * @param sig the response we got
951 */ 962 */
952static void 963static void
953handle_signature_response(void *cls, 964handle_signature_response (void *cls,
954 const struct ResponseLocSignatureMessage *sig) 965 const struct ResponseLocSignatureMessage *sig)
955{ 966{
956 struct GNUNET_FS_PublishContext *pc = cls; 967 struct GNUNET_FS_PublishContext *pc = cls;
957 struct GNUNET_FS_FileInformation *p; 968 struct GNUNET_FS_FileInformation *p;
@@ -961,11 +972,11 @@ handle_signature_response(void *cls,
961 /* p->data.loc.fi kept from CHK before */ 972 /* p->data.loc.fi kept from CHK before */
962 p->chk_uri->data.loc.peer = sig->peer; 973 p->chk_uri->data.loc.peer = sig->peer;
963 p->chk_uri->data.loc.expirationTime 974 p->chk_uri->data.loc.expirationTime
964 = GNUNET_TIME_absolute_ntoh(sig->expiration_time); 975 = GNUNET_TIME_absolute_ntoh (sig->expiration_time);
965 p->chk_uri->data.loc.contentSignature = sig->signature; 976 p->chk_uri->data.loc.contentSignature = sig->signature;
966 GNUNET_FS_file_information_sync_(p); 977 GNUNET_FS_file_information_sync_ (p);
967 GNUNET_FS_publish_sync_(pc); 978 GNUNET_FS_publish_sync_ (pc);
968 publish_kblocks(pc); 979 publish_kblocks (pc);
969} 980}
970 981
971 982
@@ -978,19 +989,19 @@ handle_signature_response(void *cls,
978 * @param error error code 989 * @param error error code
979 */ 990 */
980static void 991static void
981loc_mq_error_handler(void *cls, 992loc_mq_error_handler (void *cls,
982 enum GNUNET_MQ_Error error) 993 enum GNUNET_MQ_Error error)
983{ 994{
984 struct GNUNET_FS_PublishContext *pc = cls; 995 struct GNUNET_FS_PublishContext *pc = cls;
985 996
986 if (NULL != pc->mq) 997 if (NULL != pc->mq)
987 { 998 {
988 GNUNET_MQ_destroy(pc->mq); 999 GNUNET_MQ_destroy (pc->mq);
989 pc->mq = NULL; 1000 pc->mq = NULL;
990 } 1001 }
991 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1002 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
992 _("Can not create LOC URI. Will continue with CHK instead.\n")); 1003 _ ("Can not create LOC URI. Will continue with CHK instead.\n"));
993 publish_kblocks(pc); 1004 publish_kblocks (pc);
994} 1005}
995 1006
996 1007
@@ -1002,42 +1013,43 @@ loc_mq_error_handler(void *cls,
1002 * @param pc the publishing context do to this for 1013 * @param pc the publishing context do to this for
1003 */ 1014 */
1004static void 1015static void
1005create_loc_uri(struct GNUNET_FS_PublishContext *pc) 1016create_loc_uri (struct GNUNET_FS_PublishContext *pc)
1006{ 1017{
1007 struct GNUNET_MQ_MessageHandler handlers[] = { 1018 struct GNUNET_MQ_MessageHandler handlers[] = {
1008 GNUNET_MQ_hd_fixed_size(signature_response, 1019 GNUNET_MQ_hd_fixed_size (signature_response,
1009 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE, 1020 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGNATURE,
1010 struct ResponseLocSignatureMessage, 1021 struct ResponseLocSignatureMessage,
1011 pc), 1022 pc),
1012 GNUNET_MQ_handler_end() 1023 GNUNET_MQ_handler_end ()
1013 }; 1024 };
1014 struct GNUNET_MQ_Envelope *env; 1025 struct GNUNET_MQ_Envelope *env;
1015 struct RequestLocSignatureMessage *req; 1026 struct RequestLocSignatureMessage *req;
1016 struct GNUNET_FS_FileInformation *p; 1027 struct GNUNET_FS_FileInformation *p;
1017 1028
1018 if (NULL != pc->mq) 1029 if (NULL != pc->mq)
1019 GNUNET_MQ_destroy(pc->mq); 1030 GNUNET_MQ_destroy (pc->mq);
1020 pc->mq = GNUNET_CLIENT_connect(pc->h->cfg, 1031 pc->mq = GNUNET_CLIENT_connect (pc->h->cfg,
1021 "fs", 1032 "fs",
1022 handlers, 1033 handlers,
1023 &loc_mq_error_handler, 1034 &loc_mq_error_handler,
1024 pc); 1035 pc);
1025 if (NULL == pc->mq) 1036 if (NULL == pc->mq)
1026 { 1037 {
1027 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1038 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1028 _("Can not create LOC URI. Will continue with CHK instead.\n")); 1039 _ (
1029 publish_kblocks(pc); 1040 "Can not create LOC URI. Will continue with CHK instead.\n"));
1030 return; 1041 publish_kblocks (pc);
1031 } 1042 return;
1043 }
1032 p = pc->fi_pos; 1044 p = pc->fi_pos;
1033 env = GNUNET_MQ_msg(req, 1045 env = GNUNET_MQ_msg (req,
1034 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN); 1046 GNUNET_MESSAGE_TYPE_FS_REQUEST_LOC_SIGN);
1035 req->purpose = htonl(GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT); 1047 req->purpose = htonl (GNUNET_SIGNATURE_PURPOSE_PEER_PLACEMENT);
1036 req->expiration_time = GNUNET_TIME_absolute_hton(p->bo.expiration_time); 1048 req->expiration_time = GNUNET_TIME_absolute_hton (p->bo.expiration_time);
1037 req->chk = p->chk_uri->data.chk.chk; 1049 req->chk = p->chk_uri->data.chk.chk;
1038 req->file_length = GNUNET_htonll(p->chk_uri->data.chk.file_length); 1050 req->file_length = GNUNET_htonll (p->chk_uri->data.chk.file_length);
1039 GNUNET_MQ_send(pc->mq, 1051 GNUNET_MQ_send (pc->mq,
1040 env); 1052 env);
1041} 1053}
1042 1054
1043 1055
@@ -1047,7 +1059,7 @@ create_loc_uri(struct GNUNET_FS_PublishContext *pc)
1047 * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload 1059 * @param cls `struct GNUNET_FS_PublishContext *` identifies the upload
1048 */ 1060 */
1049void 1061void
1050GNUNET_FS_publish_main_(void *cls) 1062GNUNET_FS_publish_main_ (void *cls)
1051{ 1063{
1052 struct GNUNET_FS_PublishContext *pc = cls; 1064 struct GNUNET_FS_PublishContext *pc = cls;
1053 struct GNUNET_FS_ProgressInfo pi; 1065 struct GNUNET_FS_ProgressInfo pi;
@@ -1057,108 +1069,109 @@ GNUNET_FS_publish_main_(void *cls)
1057 pc->upload_task = NULL; 1069 pc->upload_task = NULL;
1058 p = pc->fi_pos; 1070 p = pc->fi_pos;
1059 if (NULL == p) 1071 if (NULL == p)
1060 { 1072 {
1061 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1073 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1062 "Publishing complete, now publishing SKS and KSK blocks.\n"); 1074 "Publishing complete, now publishing SKS and KSK blocks.\n");
1063 /* upload of entire hierarchy complete, 1075 /* upload of entire hierarchy complete,
1064 * publish namespace entries */ 1076 * publish namespace entries */
1065 GNUNET_FS_publish_sync_(pc); 1077 GNUNET_FS_publish_sync_ (pc);
1066 publish_sblock(pc); 1078 publish_sblock (pc);
1067 return; 1079 return;
1068 } 1080 }
1069 /* find starting position */ 1081 /* find starting position */
1070 while ((GNUNET_YES == p->is_directory) && 1082 while ((GNUNET_YES == p->is_directory) &&
1071 (NULL != p->data.dir.entries) && 1083 (NULL != p->data.dir.entries) &&
1072 (NULL == p->emsg) && 1084 (NULL == p->emsg) &&
1073 (NULL == p->data.dir.entries->chk_uri)) 1085 (NULL == p->data.dir.entries->chk_uri))
1074 { 1086 {
1075 p = p->data.dir.entries; 1087 p = p->data.dir.entries;
1076 pc->fi_pos = p; 1088 pc->fi_pos = p;
1077 GNUNET_FS_publish_sync_(pc); 1089 GNUNET_FS_publish_sync_ (pc);
1078 } 1090 }
1079 /* abort on error */ 1091 /* abort on error */
1080 if (NULL != p->emsg) 1092 if (NULL != p->emsg)
1081 { 1093 {
1082 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1083 "Error uploading: %s\n", 1095 "Error uploading: %s\n",
1084 p->emsg); 1096 p->emsg);
1085 /* error with current file, abort all 1097 /* error with current file, abort all
1086 * related files as well! */ 1098 * related files as well! */
1087 while (NULL != p->dir) 1099 while (NULL != p->dir)
1088 { 1100 {
1089 fn = GNUNET_CONTAINER_meta_data_get_by_type(p->meta, 1101 fn = GNUNET_CONTAINER_meta_data_get_by_type (p->meta,
1090 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME); 1102 EXTRACTOR_METATYPE_GNUNET_ORIGINAL_FILENAME);
1091 p = p->dir; 1103 p = p->dir;
1092 if (fn != NULL) 1104 if (fn != NULL)
1093 { 1105 {
1094 GNUNET_asprintf(&p->emsg, 1106 GNUNET_asprintf (&p->emsg,
1095 _("Recursive upload failed at `%s': %s"), 1107 _ ("Recursive upload failed at `%s': %s"),
1096 fn, 1108 fn,
1097 p->emsg); 1109 p->emsg);
1098 GNUNET_free(fn); 1110 GNUNET_free (fn);
1099 } 1111 }
1100 else 1112 else
1101 { 1113 {
1102 GNUNET_asprintf(&p->emsg, 1114 GNUNET_asprintf (&p->emsg,
1103 _("Recursive upload failed: %s"), 1115 _ ("Recursive upload failed: %s"),
1104 p->emsg); 1116 p->emsg);
1105 } 1117 }
1106 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR; 1118 pi.status = GNUNET_FS_STATUS_PUBLISH_ERROR;
1107 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL; 1119 pi.value.publish.eta = GNUNET_TIME_UNIT_FOREVER_REL;
1108 pi.value.publish.specifics.error.message = p->emsg; 1120 pi.value.publish.specifics.error.message = p->emsg;
1109 p->client_info = GNUNET_FS_publish_make_status_(&pi, pc, p, 0); 1121 p->client_info = GNUNET_FS_publish_make_status_ (&pi, pc, p, 0);
1110 }
1111 pc->all_done = GNUNET_YES;
1112 GNUNET_FS_publish_sync_(pc);
1113 return;
1114 } 1122 }
1123 pc->all_done = GNUNET_YES;
1124 GNUNET_FS_publish_sync_ (pc);
1125 return;
1126 }
1115 /* handle completion */ 1127 /* handle completion */
1116 if (NULL != p->chk_uri) 1128 if (NULL != p->chk_uri)
1117 { 1129 {
1118 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1119 "File upload complete, now publishing KSK blocks.\n"); 1131 "File upload complete, now publishing KSK blocks.\n");
1120 GNUNET_FS_publish_sync_(pc); 1132 GNUNET_FS_publish_sync_ (pc);
1121 1133
1122 if ((0 == p->bo.anonymity_level) && 1134 if ((0 == p->bo.anonymity_level) &&
1123 (GNUNET_YES != 1135 (GNUNET_YES !=
1124 GNUNET_FS_uri_test_loc(p->chk_uri))) 1136 GNUNET_FS_uri_test_loc (p->chk_uri)))
1125 { 1137 {
1126 /* zero anonymity, box CHK URI in LOC URI */ 1138 /* zero anonymity, box CHK URI in LOC URI */
1127 create_loc_uri(pc); 1139 create_loc_uri (pc);
1128 } 1140 }
1129 else 1141 else
1130 { 1142 {
1131 publish_kblocks(pc); 1143 publish_kblocks (pc);
1132 }
1133 return;
1134 } 1144 }
1145 return;
1146 }
1135 if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index)) 1147 if ((GNUNET_YES != p->is_directory) && (p->data.file.do_index))
1148 {
1149 if (NULL == p->filename)
1136 { 1150 {
1137 if (NULL == p->filename) 1151 p->data.file.do_index = GNUNET_NO;
1138 { 1152 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1139 p->data.file.do_index = GNUNET_NO; 1153 _ (
1140 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 1154 "Can not index file `%s': %s. Will try to insert instead.\n"),
1141 _("Can not index file `%s': %s. Will try to insert instead.\n"), 1155 "<no-name>",
1142 "<no-name>", 1156 _ ("needs to be an actual file"));
1143 _("needs to be an actual file")); 1157 GNUNET_FS_file_information_sync_ (p);
1144 GNUNET_FS_file_information_sync_(p); 1158 publish_content (pc);
1145 publish_content(pc);
1146 return;
1147 }
1148 if (p->data.file.have_hash)
1149 {
1150 hash_for_index_cb(pc, &p->data.file.file_id);
1151 }
1152 else
1153 {
1154 p->start_time = GNUNET_TIME_absolute_get();
1155 pc->fhc =
1156 GNUNET_CRYPTO_hash_file(GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename,
1157 HASHING_BLOCKSIZE, &hash_for_index_cb, pc);
1158 }
1159 return; 1159 return;
1160 } 1160 }
1161 publish_content(pc); 1161 if (p->data.file.have_hash)
1162 {
1163 hash_for_index_cb (pc, &p->data.file.file_id);
1164 }
1165 else
1166 {
1167 p->start_time = GNUNET_TIME_absolute_get ();
1168 pc->fhc =
1169 GNUNET_CRYPTO_hash_file (GNUNET_SCHEDULER_PRIORITY_IDLE, p->filename,
1170 HASHING_BLOCKSIZE, &hash_for_index_cb, pc);
1171 }
1172 return;
1173 }
1174 publish_content (pc);
1162} 1175}
1163 1176
1164 1177
@@ -1177,14 +1190,14 @@ GNUNET_FS_publish_main_(void *cls)
1177 * @return #GNUNET_OK to continue (always) 1190 * @return #GNUNET_OK to continue (always)
1178 */ 1191 */
1179static int 1192static int
1180fip_signal_start(void *cls, 1193fip_signal_start (void *cls,
1181 struct GNUNET_FS_FileInformation *fi, 1194 struct GNUNET_FS_FileInformation *fi,
1182 uint64_t length, 1195 uint64_t length,
1183 struct GNUNET_CONTAINER_MetaData *meta, 1196 struct GNUNET_CONTAINER_MetaData *meta,
1184 struct GNUNET_FS_Uri **uri, 1197 struct GNUNET_FS_Uri **uri,
1185 struct GNUNET_FS_BlockOptions *bo, 1198 struct GNUNET_FS_BlockOptions *bo,
1186 int *do_index, 1199 int *do_index,
1187 void **client_info) 1200 void **client_info)
1188{ 1201{
1189 struct GNUNET_FS_PublishContext *pc = cls; 1202 struct GNUNET_FS_PublishContext *pc = cls;
1190 struct GNUNET_FS_ProgressInfo pi; 1203 struct GNUNET_FS_ProgressInfo pi;
@@ -1192,52 +1205,52 @@ fip_signal_start(void *cls,
1192 uint64_t left; 1205 uint64_t left;
1193 1206
1194 if (GNUNET_YES == pc->skip_next_fi_callback) 1207 if (GNUNET_YES == pc->skip_next_fi_callback)
1195 { 1208 {
1196 pc->skip_next_fi_callback = GNUNET_NO; 1209 pc->skip_next_fi_callback = GNUNET_NO;
1197 return GNUNET_OK; 1210 return GNUNET_OK;
1198 } 1211 }
1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1200 "Starting publish operation\n"); 1213 "Starting publish operation\n");
1201 if (*do_index) 1214 if (*do_index)
1202 { 1215 {
1203 /* space for on-demand blocks */ 1216 /* space for on-demand blocks */
1204 pc->reserve_space += 1217 pc->reserve_space +=
1205 ((length + DBLOCK_SIZE - 1218 ((length + DBLOCK_SIZE
1206 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock); 1219 - 1) / DBLOCK_SIZE) * sizeof(struct OnDemandBlock);
1207 } 1220 }
1208 else 1221 else
1209 { 1222 {
1210 /* space for DBlocks */ 1223 /* space for DBlocks */
1211 pc->reserve_space += length; 1224 pc->reserve_space += length;
1212 } 1225 }
1213 /* entries for IBlocks and DBlocks, space for IBlocks */ 1226 /* entries for IBlocks and DBlocks, space for IBlocks */
1214 left = length; 1227 left = length;
1215 while (1) 1228 while (1)
1216 { 1229 {
1217 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE; 1230 left = (left + DBLOCK_SIZE - 1) / DBLOCK_SIZE;
1218 pc->reserve_entries += left; 1231 pc->reserve_entries += left;
1219 if (left <= 1) 1232 if (left <= 1)
1220 break; 1233 break;
1221 left = left * sizeof(struct ContentHashKey); 1234 left = left * sizeof(struct ContentHashKey);
1222 pc->reserve_space += left; 1235 pc->reserve_space += left;
1223 } 1236 }
1224 pc->reserve_entries++; 1237 pc->reserve_entries++;
1225 /* entries and space for keywords */ 1238 /* entries and space for keywords */
1226 if (NULL != *uri) 1239 if (NULL != *uri)
1227 { 1240 {
1228 kc = GNUNET_FS_uri_ksk_get_keyword_count(*uri); 1241 kc = GNUNET_FS_uri_ksk_get_keyword_count (*uri);
1229 pc->reserve_entries += kc; 1242 pc->reserve_entries += kc;
1230 pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc; 1243 pc->reserve_space += GNUNET_MAX_MESSAGE_SIZE * kc;
1231 } 1244 }
1232 pi.status = GNUNET_FS_STATUS_PUBLISH_START; 1245 pi.status = GNUNET_FS_STATUS_PUBLISH_START;
1233 *client_info = GNUNET_FS_publish_make_status_(&pi, pc, fi, 0); 1246 *client_info = GNUNET_FS_publish_make_status_ (&pi, pc, fi, 0);
1234 GNUNET_FS_file_information_sync_(fi); 1247 GNUNET_FS_file_information_sync_ (fi);
1235 if ((fi->is_directory) && (fi->dir != NULL)) 1248 if ((fi->is_directory) && (fi->dir != NULL))
1236 { 1249 {
1237 /* We are a directory, and we are not top-level; process entries in directory */ 1250 /* We are a directory, and we are not top-level; process entries in directory */
1238 pc->skip_next_fi_callback = GNUNET_YES; 1251 pc->skip_next_fi_callback = GNUNET_YES;
1239 GNUNET_FS_file_information_inspect(fi, &fip_signal_start, pc); 1252 GNUNET_FS_file_information_inspect (fi, &fip_signal_start, pc);
1240 } 1253 }
1241 return GNUNET_OK; 1254 return GNUNET_OK;
1242} 1255}
1243 1256
@@ -1250,39 +1263,40 @@ fip_signal_start(void *cls,
1250 * @param pc the publish context of which a file is being suspended 1263 * @param pc the publish context of which a file is being suspended
1251 */ 1264 */
1252static void 1265static void
1253suspend_operation(struct GNUNET_FS_FileInformation *fi, 1266suspend_operation (struct GNUNET_FS_FileInformation *fi,
1254 struct GNUNET_FS_PublishContext *pc) 1267 struct GNUNET_FS_PublishContext *pc)
1255{ 1268{
1256 struct GNUNET_FS_ProgressInfo pi; 1269 struct GNUNET_FS_ProgressInfo pi;
1257 uint64_t off; 1270 uint64_t off;
1258 1271
1259 if (NULL != pc->ksk_pc) 1272 if (NULL != pc->ksk_pc)
1260 { 1273 {
1261 GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); 1274 GNUNET_FS_publish_ksk_cancel (pc->ksk_pc);
1262 pc->ksk_pc = NULL; 1275 pc->ksk_pc = NULL;
1263 } 1276 }
1264 if (NULL != pc->sks_pc) 1277 if (NULL != pc->sks_pc)
1265 { 1278 {
1266 GNUNET_FS_publish_sks_cancel(pc->sks_pc); 1279 GNUNET_FS_publish_sks_cancel (pc->sks_pc);
1267 pc->sks_pc = NULL; 1280 pc->sks_pc = NULL;
1268 } 1281 }
1269 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1270 "Suspending publish operation\n"); 1283 "Suspending publish operation\n");
1271 GNUNET_free_non_null(fi->serialization); 1284 GNUNET_free_non_null (fi->serialization);
1272 fi->serialization = NULL; 1285 fi->serialization = NULL;
1273 off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ? fi->data.dir.dir_size : fi->data.file.file_size; 1286 off = (NULL == fi->chk_uri) ? 0 : (GNUNET_YES == fi->is_directory) ?
1287 fi->data.dir.dir_size : fi->data.file.file_size;
1274 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND; 1288 pi.status = GNUNET_FS_STATUS_PUBLISH_SUSPEND;
1275 GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); 1289 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1276 if (NULL != pc->qre) 1290 if (NULL != pc->qre)
1277 { 1291 {
1278 GNUNET_DATASTORE_cancel(pc->qre); 1292 GNUNET_DATASTORE_cancel (pc->qre);
1279 pc->qre = NULL; 1293 pc->qre = NULL;
1280 } 1294 }
1281 if (NULL != pc->dsh) 1295 if (NULL != pc->dsh)
1282 { 1296 {
1283 GNUNET_DATASTORE_disconnect(pc->dsh, GNUNET_NO); 1297 GNUNET_DATASTORE_disconnect (pc->dsh, GNUNET_NO);
1284 pc->dsh = NULL; 1298 pc->dsh = NULL;
1285 } 1299 }
1286 pc->rid = 0; 1300 pc->rid = 0;
1287} 1301}
1288 1302
@@ -1302,29 +1316,29 @@ suspend_operation(struct GNUNET_FS_FileInformation *fi,
1302 * @return #GNUNET_OK to continue (always) 1316 * @return #GNUNET_OK to continue (always)
1303 */ 1317 */
1304static int 1318static int
1305fip_signal_suspend(void *cls, 1319fip_signal_suspend (void *cls,
1306 struct GNUNET_FS_FileInformation *fi, 1320 struct GNUNET_FS_FileInformation *fi,
1307 uint64_t length, 1321 uint64_t length,
1308 struct GNUNET_CONTAINER_MetaData *meta, 1322 struct GNUNET_CONTAINER_MetaData *meta,
1309 struct GNUNET_FS_Uri **uri, 1323 struct GNUNET_FS_Uri **uri,
1310 struct GNUNET_FS_BlockOptions *bo, 1324 struct GNUNET_FS_BlockOptions *bo,
1311 int *do_index, 1325 int *do_index,
1312 void **client_info) 1326 void **client_info)
1313{ 1327{
1314 struct GNUNET_FS_PublishContext *pc = cls; 1328 struct GNUNET_FS_PublishContext *pc = cls;
1315 1329
1316 if (GNUNET_YES == pc->skip_next_fi_callback) 1330 if (GNUNET_YES == pc->skip_next_fi_callback)
1317 { 1331 {
1318 pc->skip_next_fi_callback = GNUNET_NO; 1332 pc->skip_next_fi_callback = GNUNET_NO;
1319 return GNUNET_OK; 1333 return GNUNET_OK;
1320 } 1334 }
1321 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) 1335 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta))
1322 { 1336 {
1323 /* process entries in directory */ 1337 /* process entries in directory */
1324 pc->skip_next_fi_callback = GNUNET_YES; 1338 pc->skip_next_fi_callback = GNUNET_YES;
1325 GNUNET_FS_file_information_inspect(fi, &fip_signal_suspend, pc); 1339 GNUNET_FS_file_information_inspect (fi, &fip_signal_suspend, pc);
1326 } 1340 }
1327 suspend_operation(fi, pc); 1341 suspend_operation (fi, pc);
1328 *client_info = NULL; 1342 *client_info = NULL;
1329 return GNUNET_OK; 1343 return GNUNET_OK;
1330} 1344}
@@ -1337,21 +1351,21 @@ fip_signal_suspend(void *cls,
1337 * @param cls the `struct GNUNET_FS_PublishContext` to signal for 1351 * @param cls the `struct GNUNET_FS_PublishContext` to signal for
1338 */ 1352 */
1339void 1353void
1340GNUNET_FS_publish_signal_suspend_(void *cls) 1354GNUNET_FS_publish_signal_suspend_ (void *cls)
1341{ 1355{
1342 struct GNUNET_FS_PublishContext *pc = cls; 1356 struct GNUNET_FS_PublishContext *pc = cls;
1343 1357
1344 if (NULL != pc->upload_task) 1358 if (NULL != pc->upload_task)
1345 { 1359 {
1346 GNUNET_SCHEDULER_cancel(pc->upload_task); 1360 GNUNET_SCHEDULER_cancel (pc->upload_task);
1347 pc->upload_task = NULL; 1361 pc->upload_task = NULL;
1348 } 1362 }
1349 pc->skip_next_fi_callback = GNUNET_YES; 1363 pc->skip_next_fi_callback = GNUNET_YES;
1350 GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_suspend, pc); 1364 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_suspend, pc);
1351 suspend_operation(pc->fi, pc); 1365 suspend_operation (pc->fi, pc);
1352 GNUNET_FS_end_top(pc->h, pc->top); 1366 GNUNET_FS_end_top (pc->h, pc->top);
1353 pc->top = NULL; 1367 pc->top = NULL;
1354 publish_cleanup(pc); 1368 publish_cleanup (pc);
1355} 1369}
1356 1370
1357 1371
@@ -1365,30 +1379,30 @@ GNUNET_FS_publish_signal_suspend_(void *cls)
1365 * @param msg error message on error, otherwise NULL 1379 * @param msg error message on error, otherwise NULL
1366 */ 1380 */
1367static void 1381static void
1368finish_reserve(void *cls, 1382finish_reserve (void *cls,
1369 int success, 1383 int success,
1370 struct GNUNET_TIME_Absolute min_expiration, 1384 struct GNUNET_TIME_Absolute min_expiration,
1371 const char *msg) 1385 const char *msg)
1372{ 1386{
1373 struct GNUNET_FS_PublishContext *pc = cls; 1387 struct GNUNET_FS_PublishContext *pc = cls;
1374 1388
1375 pc->qre = NULL; 1389 pc->qre = NULL;
1376 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1377 "Reservation complete (%d)!\n", 1391 "Reservation complete (%d)!\n",
1378 success); 1392 success);
1379 if ((msg != NULL) || (success <= 0)) 1393 if ((msg != NULL) || (success <= 0))
1380 { 1394 {
1381 GNUNET_asprintf(&pc->fi->emsg, 1395 GNUNET_asprintf (&pc->fi->emsg,
1382 _("Datastore failure: %s"), 1396 _ ("Datastore failure: %s"),
1383 msg); 1397 msg);
1384 signal_publish_error(pc->fi, pc, pc->fi->emsg); 1398 signal_publish_error (pc->fi, pc, pc->fi->emsg);
1385 return; 1399 return;
1386 } 1400 }
1387 pc->rid = success; 1401 pc->rid = success;
1388 GNUNET_assert(NULL == pc->upload_task); 1402 GNUNET_assert (NULL == pc->upload_task);
1389 pc->upload_task = 1403 pc->upload_task =
1390 GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_BACKGROUND, 1404 GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_BACKGROUND,
1391 &GNUNET_FS_publish_main_, pc); 1405 &GNUNET_FS_publish_main_, pc);
1392} 1406}
1393 1407
1394 1408
@@ -1398,7 +1412,7 @@ finish_reserve(void *cls,
1398 * @param fi file structure to traverse 1412 * @param fi file structure to traverse
1399 */ 1413 */
1400static uint64_t 1414static uint64_t
1401compute_contents_size(struct GNUNET_FS_FileInformation *fi) 1415compute_contents_size (struct GNUNET_FS_FileInformation *fi)
1402{ 1416{
1403 struct GNUNET_FS_FileInformation *ent; 1417 struct GNUNET_FS_FileInformation *ent;
1404 1418
@@ -1406,7 +1420,7 @@ compute_contents_size(struct GNUNET_FS_FileInformation *fi)
1406 return fi->data.file.file_size; 1420 return fi->data.file.file_size;
1407 fi->data.dir.contents_size = 0; 1421 fi->data.dir.contents_size = 0;
1408 for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next) 1422 for (ent = fi->data.dir.entries; NULL != ent; ent = ent->next)
1409 fi->data.dir.contents_size += compute_contents_size(ent); 1423 fi->data.dir.contents_size += compute_contents_size (ent);
1410 return fi->data.dir.contents_size; 1424 return fi->data.dir.contents_size;
1411} 1425}
1412 1426
@@ -1425,67 +1439,68 @@ compute_contents_size(struct GNUNET_FS_FileInformation *fi)
1425 * @return context that can be used to control the publish operation 1439 * @return context that can be used to control the publish operation
1426 */ 1440 */
1427struct GNUNET_FS_PublishContext * 1441struct GNUNET_FS_PublishContext *
1428GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h, 1442GNUNET_FS_publish_start (struct GNUNET_FS_Handle *h,
1429 struct GNUNET_FS_FileInformation *fi, 1443 struct GNUNET_FS_FileInformation *fi,
1430 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns, 1444 const struct GNUNET_CRYPTO_EcdsaPrivateKey *ns,
1431 const char *nid, 1445 const char *nid,
1432 const char *nuid, 1446 const char *nuid,
1433 enum GNUNET_FS_PublishOptions options) 1447 enum GNUNET_FS_PublishOptions options)
1434{ 1448{
1435 struct GNUNET_FS_PublishContext *ret; 1449 struct GNUNET_FS_PublishContext *ret;
1436 struct GNUNET_DATASTORE_Handle *dsh; 1450 struct GNUNET_DATASTORE_Handle *dsh;
1437 1451
1438 GNUNET_assert(NULL != h); 1452 GNUNET_assert (NULL != h);
1439 compute_contents_size(fi); 1453 compute_contents_size (fi);
1440 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY)) 1454 if (0 == (options & GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY))
1441 { 1455 {
1442 dsh = GNUNET_DATASTORE_connect(h->cfg); 1456 dsh = GNUNET_DATASTORE_connect (h->cfg);
1443 if (NULL == dsh) 1457 if (NULL == dsh)
1444 return NULL; 1458 return NULL;
1445 } 1459 }
1446 else 1460 else
1447 { 1461 {
1448 dsh = NULL; 1462 dsh = NULL;
1449 } 1463 }
1450 ret = GNUNET_new(struct GNUNET_FS_PublishContext); 1464 ret = GNUNET_new (struct GNUNET_FS_PublishContext);
1451 ret->dsh = dsh; 1465 ret->dsh = dsh;
1452 ret->h = h; 1466 ret->h = h;
1453 ret->fi = fi; 1467 ret->fi = fi;
1454 if (NULL != ns) 1468 if (NULL != ns)
1455 { 1469 {
1456 ret->ns = GNUNET_new(struct GNUNET_CRYPTO_EcdsaPrivateKey); 1470 ret->ns = GNUNET_new (struct GNUNET_CRYPTO_EcdsaPrivateKey);
1457 *ret->ns = *ns; 1471 *ret->ns = *ns;
1458 GNUNET_assert(NULL != nid); 1472 GNUNET_assert (NULL != nid);
1459 ret->nid = GNUNET_strdup(nid); 1473 ret->nid = GNUNET_strdup (nid);
1460 if (NULL != nuid) 1474 if (NULL != nuid)
1461 ret->nuid = GNUNET_strdup(nuid); 1475 ret->nuid = GNUNET_strdup (nuid);
1462 } 1476 }
1463 ret->options = options; 1477 ret->options = options;
1464 /* signal start */ 1478 /* signal start */
1465 GNUNET_FS_file_information_inspect(ret->fi, &fip_signal_start, ret); 1479 GNUNET_FS_file_information_inspect (ret->fi, &fip_signal_start, ret);
1466 ret->fi_pos = ret->fi; 1480 ret->fi_pos = ret->fi;
1467 ret->top = GNUNET_FS_make_top(h, &GNUNET_FS_publish_signal_suspend_, ret); 1481 ret->top = GNUNET_FS_make_top (h, &GNUNET_FS_publish_signal_suspend_, ret);
1468 GNUNET_FS_publish_sync_(ret); 1482 GNUNET_FS_publish_sync_ (ret);
1469 if (NULL != ret->dsh) 1483 if (NULL != ret->dsh)
1470 { 1484 {
1471 GNUNET_assert(NULL == ret->qre); 1485 GNUNET_assert (NULL == ret->qre);
1472 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1486 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1473 _("Reserving space for %u entries and %llu bytes for publication\n"), 1487 _ (
1474 (unsigned int)ret->reserve_entries, 1488 "Reserving space for %u entries and %llu bytes for publication\n"),
1475 (unsigned long long)ret->reserve_space); 1489 (unsigned int) ret->reserve_entries,
1476 ret->qre = 1490 (unsigned long long) ret->reserve_space);
1477 GNUNET_DATASTORE_reserve(ret->dsh, ret->reserve_space, 1491 ret->qre =
1478 ret->reserve_entries, 1492 GNUNET_DATASTORE_reserve (ret->dsh, ret->reserve_space,
1479 &finish_reserve, 1493 ret->reserve_entries,
1480 ret); 1494 &finish_reserve,
1481 } 1495 ret);
1496 }
1482 else 1497 else
1483 { 1498 {
1484 GNUNET_assert(NULL == ret->upload_task); 1499 GNUNET_assert (NULL == ret->upload_task);
1485 ret->upload_task = 1500 ret->upload_task =
1486 GNUNET_SCHEDULER_add_with_priority 1501 GNUNET_SCHEDULER_add_with_priority
1487 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret); 1502 (GNUNET_SCHEDULER_PRIORITY_BACKGROUND, &GNUNET_FS_publish_main_, ret);
1488 } 1503 }
1489 return ret; 1504 return ret;
1490} 1505}
1491 1506
@@ -1505,39 +1520,39 @@ GNUNET_FS_publish_start(struct GNUNET_FS_Handle *h,
1505 * @return #GNUNET_OK to continue (always) 1520 * @return #GNUNET_OK to continue (always)
1506 */ 1521 */
1507static int 1522static int
1508fip_signal_stop(void *cls, 1523fip_signal_stop (void *cls,
1509 struct GNUNET_FS_FileInformation *fi, 1524 struct GNUNET_FS_FileInformation *fi,
1510 uint64_t length, 1525 uint64_t length,
1511 struct GNUNET_CONTAINER_MetaData *meta, 1526 struct GNUNET_CONTAINER_MetaData *meta,
1512 struct GNUNET_FS_Uri **uri, 1527 struct GNUNET_FS_Uri **uri,
1513 struct GNUNET_FS_BlockOptions *bo, 1528 struct GNUNET_FS_BlockOptions *bo,
1514 int *do_index, void **client_info) 1529 int *do_index, void **client_info)
1515{ 1530{
1516 struct GNUNET_FS_PublishContext *pc = cls; 1531 struct GNUNET_FS_PublishContext *pc = cls;
1517 struct GNUNET_FS_ProgressInfo pi; 1532 struct GNUNET_FS_ProgressInfo pi;
1518 uint64_t off; 1533 uint64_t off;
1519 1534
1520 if (GNUNET_YES == pc->skip_next_fi_callback) 1535 if (GNUNET_YES == pc->skip_next_fi_callback)
1521 { 1536 {
1522 pc->skip_next_fi_callback = GNUNET_NO; 1537 pc->skip_next_fi_callback = GNUNET_NO;
1523 return GNUNET_OK; 1538 return GNUNET_OK;
1524 } 1539 }
1525 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory(meta)) 1540 if (GNUNET_YES == GNUNET_FS_meta_data_test_for_directory (meta))
1526 { 1541 {
1527 /* process entries in directory first */ 1542 /* process entries in directory first */
1528 pc->skip_next_fi_callback = GNUNET_YES; 1543 pc->skip_next_fi_callback = GNUNET_YES;
1529 GNUNET_FS_file_information_inspect(fi, &fip_signal_stop, pc); 1544 GNUNET_FS_file_information_inspect (fi, &fip_signal_stop, pc);
1530 } 1545 }
1531 if (NULL != fi->serialization) 1546 if (NULL != fi->serialization)
1532 { 1547 {
1533 GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, 1548 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1534 fi->serialization); 1549 fi->serialization);
1535 GNUNET_free(fi->serialization); 1550 GNUNET_free (fi->serialization);
1536 fi->serialization = NULL; 1551 fi->serialization = NULL;
1537 } 1552 }
1538 off = (fi->chk_uri == NULL) ? 0 : length; 1553 off = (fi->chk_uri == NULL) ? 0 : length;
1539 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; 1554 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1540 GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, fi, off)); 1555 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, fi, off));
1541 *client_info = NULL; 1556 *client_info = NULL;
1542 return GNUNET_OK; 1557 return GNUNET_OK;
1543} 1558}
@@ -1552,56 +1567,57 @@ fip_signal_stop(void *cls,
1552 * @param pc context for the upload to stop 1567 * @param pc context for the upload to stop
1553 */ 1568 */
1554void 1569void
1555GNUNET_FS_publish_stop(struct GNUNET_FS_PublishContext *pc) 1570GNUNET_FS_publish_stop (struct GNUNET_FS_PublishContext *pc)
1556{ 1571{
1557 struct GNUNET_FS_ProgressInfo pi; 1572 struct GNUNET_FS_ProgressInfo pi;
1558 uint64_t off; 1573 uint64_t off;
1559 1574
1560 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1561 "Publish stop called\n"); 1576 "Publish stop called\n");
1562 GNUNET_FS_end_top(pc->h, pc->top); 1577 GNUNET_FS_end_top (pc->h, pc->top);
1563 if (NULL != pc->ksk_pc) 1578 if (NULL != pc->ksk_pc)
1564 { 1579 {
1565 GNUNET_FS_publish_ksk_cancel(pc->ksk_pc); 1580 GNUNET_FS_publish_ksk_cancel (pc->ksk_pc);
1566 pc->ksk_pc = NULL; 1581 pc->ksk_pc = NULL;
1567 } 1582 }
1568 if (NULL != pc->sks_pc) 1583 if (NULL != pc->sks_pc)
1569 { 1584 {
1570 GNUNET_FS_publish_sks_cancel(pc->sks_pc); 1585 GNUNET_FS_publish_sks_cancel (pc->sks_pc);
1571 pc->sks_pc = NULL; 1586 pc->sks_pc = NULL;
1572 } 1587 }
1573 if (NULL != pc->upload_task) 1588 if (NULL != pc->upload_task)
1574 { 1589 {
1575 GNUNET_SCHEDULER_cancel(pc->upload_task); 1590 GNUNET_SCHEDULER_cancel (pc->upload_task);
1576 pc->upload_task = NULL; 1591 pc->upload_task = NULL;
1577 } 1592 }
1578 pc->skip_next_fi_callback = GNUNET_YES; 1593 pc->skip_next_fi_callback = GNUNET_YES;
1579 GNUNET_FS_file_information_inspect(pc->fi, &fip_signal_stop, pc); 1594 GNUNET_FS_file_information_inspect (pc->fi, &fip_signal_stop, pc);
1580 1595
1581 if (NULL != pc->fi->serialization) 1596 if (NULL != pc->fi->serialization)
1582 { 1597 {
1583 GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO, 1598 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_FILE_INFO,
1584 pc->fi->serialization); 1599 pc->fi->serialization);
1585 GNUNET_free(pc->fi->serialization); 1600 GNUNET_free (pc->fi->serialization);
1586 pc->fi->serialization = NULL; 1601 pc->fi->serialization = NULL;
1587 } 1602 }
1588 off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll(pc->fi->chk_uri->data.chk.file_length); 1603 off = (NULL == pc->fi->chk_uri) ? 0 : GNUNET_ntohll (
1604 pc->fi->chk_uri->data.chk.file_length);
1589 1605
1590 if (NULL != pc->serialization) 1606 if (NULL != pc->serialization)
1591 { 1607 {
1592 GNUNET_FS_remove_sync_file_(pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH, 1608 GNUNET_FS_remove_sync_file_ (pc->h, GNUNET_FS_SYNC_PATH_MASTER_PUBLISH,
1593 pc->serialization); 1609 pc->serialization);
1594 GNUNET_free(pc->serialization); 1610 GNUNET_free (pc->serialization);
1595 pc->serialization = NULL; 1611 pc->serialization = NULL;
1596 } 1612 }
1597 if (NULL != pc->qre) 1613 if (NULL != pc->qre)
1598 { 1614 {
1599 GNUNET_DATASTORE_cancel(pc->qre); 1615 GNUNET_DATASTORE_cancel (pc->qre);
1600 pc->qre = NULL; 1616 pc->qre = NULL;
1601 } 1617 }
1602 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED; 1618 pi.status = GNUNET_FS_STATUS_PUBLISH_STOPPED;
1603 GNUNET_break(NULL == GNUNET_FS_publish_make_status_(&pi, pc, pc->fi, off)); 1619 GNUNET_break (NULL == GNUNET_FS_publish_make_status_ (&pi, pc, pc->fi, off));
1604 publish_cleanup(pc); 1620 publish_cleanup (pc);
1605} 1621}
1606 1622
1607 1623