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