aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_download.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-10-19 21:58:41 +0000
committerChristian Grothoff <christian@grothoff.org>2009-10-19 21:58:41 +0000
commit2ca3d0343fdda87012cedd096d891627b3c59cb2 (patch)
tree980de35f422a026dff4f19b17b25996037eeed38 /src/fs/fs_download.c
parentea0a274cbf6132260b7f0de868cdd1076688ed8b (diff)
downloadgnunet-2ca3d0343fdda87012cedd096d891627b3c59cb2.tar.gz
gnunet-2ca3d0343fdda87012cedd096d891627b3c59cb2.zip
fixing bugs, diagnosis summary
Diffstat (limited to 'src/fs/fs_download.c')
-rw-r--r--src/fs/fs_download.c101
1 files changed, 81 insertions, 20 deletions
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index e6342a067..defc9724f 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -120,7 +120,7 @@ compute_dblock_offset (uint64_t offset,
120 lsize = DBLOCK_SIZE; 120 lsize = DBLOCK_SIZE;
121 for (i=treedepth-1;i>depth;i--) 121 for (i=treedepth-1;i>depth;i--)
122 lsize *= CHK_PER_INODE; 122 lsize *= CHK_PER_INODE;
123 return offset + i * lsize; 123 return offset + k * lsize;
124} 124}
125 125
126 126
@@ -154,6 +154,22 @@ make_download_status (struct GNUNET_FS_ProgressInfo *pi,
154 = dc->anonymity; 154 = dc->anonymity;
155} 155}
156 156
157/**
158 * We're ready to transmit a search request to the
159 * file-sharing service. Do it. If there is
160 * more than one request pending, try to send
161 * multiple or request another transmission.
162 *
163 * @param cls closure
164 * @param size number of bytes available in buf
165 * @param buf where the callee should write the message
166 * @return number of bytes written to buf
167 */
168static size_t
169transmit_download_request (void *cls,
170 size_t size,
171 void *buf);
172
157 173
158/** 174/**
159 * Schedule the download of the specified 175 * Schedule the download of the specified
@@ -217,6 +233,15 @@ schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
217 &chk->query, 233 &chk->query,
218 sm, 234 sm,
219 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 235 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
236
237 if ( (dc->th == NULL) &&
238 (dc->client != NULL) )
239 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
240 sizeof (struct SearchMessage),
241 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
242 &transmit_download_request,
243 dc);
244
220} 245}
221 246
222 247
@@ -298,7 +323,7 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
298 char pt[size]; 323 char pt[size];
299 uint64_t off; 324 uint64_t off;
300 size_t app; 325 size_t app;
301 unsigned int i; 326 int i;
302 struct ContentHashKey *chk; 327 struct ContentHashKey *chk;
303 char *emsg; 328 char *emsg;
304 329
@@ -310,11 +335,16 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
310 GNUNET_h2s (&query), 335 GNUNET_h2s (&query),
311 "FS"); 336 "FS");
312#endif 337#endif
313 sm = GNUNET_CONTAINER_multihashmap_get (dc->active, 338 sm = GNUNET_CONTAINER_multihashmap_get (dc->active,
314 &query); 339 &query);
315 if (NULL == sm) 340 if (NULL == sm)
316 { 341 {
317 GNUNET_break (0); 342 GNUNET_break (0); /* FIXME: this assertion actually fails for one
343 of my tests, the ascii-strings of the
344 query match what was printed when the
345 request was originally made; this does
346 NOT happen if in line ~825 a HT size
347 of 1 is used! => bug in HT? */
318 return; 348 return;
319 } 349 }
320 if (size != calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length), 350 if (size != calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length),
@@ -323,8 +353,13 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
323 sm->depth)) 353 sm->depth))
324 { 354 {
325#if DEBUG_DOWNLOAD 355#if DEBUG_DOWNLOAD
326 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
327 "Internal error or bogus download URI\n"); 357 "Internal error or bogus download URI (expected %u bytes, got %u)\n",
358 calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length),
359 dc->treedepth,
360 sm->offset,
361 sm->depth),
362 size);
328#endif 363#endif
329 dc->emsg = GNUNET_strdup ("Internal error or bogus download URI"); 364 dc->emsg = GNUNET_strdup ("Internal error or bogus download URI");
330 /* signal error */ 365 /* signal error */
@@ -334,6 +369,11 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
334 dc->client_info = dc->h->upcb (dc->h->upcb_cls, 369 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
335 &pi); 370 &pi);
336 /* abort all pending requests */ 371 /* abort all pending requests */
372 if (NULL != dc->th)
373 {
374 GNUNET_CONNECTION_notify_transmit_ready_cancel (dc->th);
375 dc->th = NULL;
376 }
337 GNUNET_CLIENT_disconnect (dc->client); 377 GNUNET_CLIENT_disconnect (dc->client);
338 dc->client = NULL; 378 dc->client = NULL;
339 return; 379 return;
@@ -395,6 +435,11 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
395 &pi); 435 &pi);
396 436
397 /* abort all pending requests */ 437 /* abort all pending requests */
438 if (NULL != dc->th)
439 {
440 GNUNET_CONNECTION_notify_transmit_ready_cancel (dc->th);
441 dc->th = NULL;
442 }
398 GNUNET_CLIENT_disconnect (dc->client); 443 GNUNET_CLIENT_disconnect (dc->client);
399 dc->client = NULL; 444 dc->client = NULL;
400 return; 445 return;
@@ -459,12 +504,13 @@ process_result (struct GNUNET_FS_DownloadContext *dc,
459 return; 504 return;
460#if DEBUG_DOWNLOAD 505#if DEBUG_DOWNLOAD
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "Triggering downloads of children (this block was at level %u)\n", 507 "Triggering downloads of children (this block was at level %u and offset %llu)\n",
463 dc->treedepth); 508 sm->depth,
509 (unsigned long long) sm->offset);
464#endif 510#endif
465 GNUNET_assert (0 == (size % sizeof(struct ContentHashKey))); 511 GNUNET_assert (0 == (size % sizeof(struct ContentHashKey)));
466 chk = (struct ContentHashKey*) pt; 512 chk = (struct ContentHashKey*) pt;
467 for (i=0;i<(size / sizeof(struct ContentHashKey));i++) 513 for (i=(size / sizeof(struct ContentHashKey))-1;i>=0;i--)
468 { 514 {
469 off = compute_dblock_offset (sm->offset, 515 off = compute_dblock_offset (sm->offset,
470 sm->depth, 516 sm->depth,
@@ -508,6 +554,8 @@ receive_results (void *cls,
508 ntohl (cm->type), 554 ntohl (cm->type),
509 &cm[1], 555 &cm[1],
510 msize - sizeof (struct ContentMessage)); 556 msize - sizeof (struct ContentMessage));
557 if (dc->client == NULL)
558 return; /* fatal error */
511 /* continue receiving */ 559 /* continue receiving */
512 GNUNET_CLIENT_receive (dc->client, 560 GNUNET_CLIENT_receive (dc->client,
513 &receive_results, 561 &receive_results,
@@ -537,6 +585,7 @@ transmit_download_request (void *cls,
537 size_t msize; 585 size_t msize;
538 struct SearchMessage *sm; 586 struct SearchMessage *sm;
539 587
588 dc->th = NULL;
540 if (NULL == buf) 589 if (NULL == buf)
541 { 590 {
542 try_reconnect (dc); 591 try_reconnect (dc);
@@ -565,6 +614,12 @@ transmit_download_request (void *cls,
565 msize += sizeof (struct SearchMessage); 614 msize += sizeof (struct SearchMessage);
566 sm++; 615 sm++;
567 } 616 }
617 if (dc->pending != NULL)
618 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
619 sizeof (struct SearchMessage),
620 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
621 &transmit_download_request,
622 dc);
568 return msize; 623 return msize;
569} 624}
570 625
@@ -596,11 +651,11 @@ do_reconnect (void *cls,
596 return; 651 return;
597 } 652 }
598 dc->client = client; 653 dc->client = client;
599 GNUNET_CLIENT_notify_transmit_ready (client, 654 dc->th = GNUNET_CLIENT_notify_transmit_ready (client,
600 sizeof (struct SearchMessage), 655 sizeof (struct SearchMessage),
601 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 656 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
602 &transmit_download_request, 657 &transmit_download_request,
603 dc); 658 dc);
604 GNUNET_CLIENT_receive (client, 659 GNUNET_CLIENT_receive (client,
605 &receive_results, 660 &receive_results,
606 dc, 661 dc,
@@ -647,6 +702,11 @@ try_reconnect (struct GNUNET_FS_DownloadContext *dc)
647 702
648 if (NULL != dc->client) 703 if (NULL != dc->client)
649 { 704 {
705 if (NULL != dc->th)
706 {
707 GNUNET_CONNECTION_notify_transmit_ready_cancel (dc->th);
708 dc->th = NULL;
709 }
650 GNUNET_CONTAINER_multihashmap_iterate (dc->active, 710 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
651 &retry_entry, 711 &retry_entry,
652 dc); 712 dc);
@@ -762,6 +822,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
762 dc->length = length; 822 dc->length = length;
763 dc->anonymity = anonymity; 823 dc->anonymity = anonymity;
764 dc->options = options; 824 dc->options = options;
825 // dc->active = GNUNET_CONTAINER_multihashmap_create (1); // + (length / DBLOCK_SIZE));
765 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + (length / DBLOCK_SIZE)); 826 dc->active = GNUNET_CONTAINER_multihashmap_create (1 + (length / DBLOCK_SIZE));
766 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length)); 827 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length));
767#if DEBUG_DOWNLOAD 828#if DEBUG_DOWNLOAD
@@ -773,12 +834,7 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
773 schedule_block_download (dc, 834 schedule_block_download (dc,
774 &dc->uri->data.chk.chk, 835 &dc->uri->data.chk.chk,
775 0, 836 0,
776 0); 837 1 /* 0 == CHK, 1 == top */);
777 GNUNET_CLIENT_notify_transmit_ready (client,
778 sizeof (struct SearchMessage),
779 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
780 &transmit_download_request,
781 dc);
782 GNUNET_CLIENT_receive (client, 838 GNUNET_CLIENT_receive (client,
783 &receive_results, 839 &receive_results,
784 dc, 840 dc,
@@ -832,6 +888,11 @@ GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
832 if (GNUNET_SCHEDULER_NO_TASK != dc->task) 888 if (GNUNET_SCHEDULER_NO_TASK != dc->task)
833 GNUNET_SCHEDULER_cancel (dc->h->sched, 889 GNUNET_SCHEDULER_cancel (dc->h->sched,
834 dc->task); 890 dc->task);
891 if (NULL != dc->th)
892 {
893 GNUNET_CONNECTION_notify_transmit_ready_cancel (dc->th);
894 dc->th = NULL;
895 }
835 if (NULL != dc->client) 896 if (NULL != dc->client)
836 GNUNET_CLIENT_disconnect (dc->client); 897 GNUNET_CLIENT_disconnect (dc->client);
837 GNUNET_CONTAINER_multihashmap_iterate (dc->active, 898 GNUNET_CONTAINER_multihashmap_iterate (dc->active,