aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-05-30 15:20:02 +0000
committerChristian Grothoff <christian@grothoff.org>2013-05-30 15:20:02 +0000
commit4647e06936db32a1829223e48eb3d6b6a52b0c3d (patch)
treececf4c425161d04a41254eed1ba534b019737abf /src
parent40b50b568b0c74d168b4b009c8f528568bfe8ac1 (diff)
downloadgnunet-4647e06936db32a1829223e48eb3d6b6a52b0c3d.tar.gz
gnunet-4647e06936db32a1829223e48eb3d6b6a52b0c3d.zip
-towards allowing probes for directory entries
Diffstat (limited to 'src')
-rw-r--r--src/fs/fs_api.h5
-rw-r--r--src/fs/fs_search.c98
-rw-r--r--src/include/gnunet_fs_service.h27
3 files changed, 114 insertions, 16 deletions
diff --git a/src/fs/fs_api.h b/src/fs/fs_api.h
index 9e3e9e787..f3daeb85a 100644
--- a/src/fs/fs_api.h
+++ b/src/fs/fs_api.h
@@ -599,6 +599,11 @@ struct GNUNET_FS_SearchResult
599 struct GNUNET_TIME_Relative remaining_probe_time; 599 struct GNUNET_TIME_Relative remaining_probe_time;
600 600
601 /** 601 /**
602 * Anonymity level to use for probes using this search result.
603 */
604 uint32_t anonymity;
605
606 /**
602 * Number of mandatory keywords for which we have NOT yet found the 607 * Number of mandatory keywords for which we have NOT yet found the
603 * search result; when this value hits zero, the search result is 608 * search result; when this value hits zero, the search result is
604 * given to the callback. 609 * given to the callback.
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c
index 0c51ed394..2fa14f68d 100644
--- a/src/fs/fs_search.c
+++ b/src/fs/fs_search.c
@@ -429,7 +429,7 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
429 2 * (1 + sr->availability_trials)); 429 2 * (1 + sr->availability_trials));
430 sr->probe_ctx = 430 sr->probe_ctx =
431 GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off, 431 GNUNET_FS_download_start (sr->h, sr->uri, sr->meta, NULL, NULL, off,
432 len, sr->sc->anonymity, 432 len, sr->anonymity,
433 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES | 433 GNUNET_FS_DOWNLOAD_NO_TEMPORARIES |
434 GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL); 434 GNUNET_FS_DOWNLOAD_IS_PROBE, sr, NULL);
435 sr->probe_ping_task 435 sr->probe_ping_task
@@ -439,6 +439,84 @@ GNUNET_FS_search_start_probe_ (struct GNUNET_FS_SearchResult *sr)
439 439
440 440
441/** 441/**
442 * Start download probes for the given search result.
443 *
444 * @param h file-sharing handle to use for the operation
445 * @param uri URI to probe
446 * @param meta meta data associated with the URI
447 * @param client_info client info pointer to use for associated events
448 * @param anonymity anonymity level to use for the probes
449 * @return the search result handle to access the probe activity
450 */
451struct GNUNET_FS_SearchResult *
452GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
453 const struct GNUNET_FS_Uri *uri,
454 const struct GNUNET_CONTAINER_MetaData *meta,
455 void *client_info,
456 uint32_t anonymity)
457{
458 struct GNUNET_FS_SearchResult *sr;
459
460 sr = GNUNET_new (struct GNUNET_FS_SearchResult);
461 sr->h = h;
462 sr->uri = GNUNET_FS_uri_dup (uri);
463 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
464 sr->client_info = client_info;
465 sr->anonymity = anonymity;
466 GNUNET_FS_search_start_probe_ (sr);
467 return sr;
468}
469
470
471/**
472 * Stop probing activity associated with a search result.
473 *
474 * @param sr search result
475 */
476static void
477GNUNET_FS_search_stop_probe_ (struct GNUNET_FS_SearchResult *sr)
478{
479 if (NULL != sr->probe_ctx)
480 {
481 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
482 sr->probe_ctx = NULL;
483 }
484 if (GNUNET_SCHEDULER_NO_TASK != sr->probe_ping_task)
485 {
486 GNUNET_SCHEDULER_cancel (sr->probe_ping_task);
487 sr->probe_ping_task = GNUNET_SCHEDULER_NO_TASK;
488 }
489 if (GNUNET_SCHEDULER_NO_TASK != sr->probe_cancel_task)
490 {
491 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
492 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
493 }
494}
495
496
497/**
498 * Stop probe activity. Must ONLY be used on values
499 * returned from 'GNUNET_FS_probe'.
500 *
501 * @param sr search result to stop probing for (freed)
502 * @return the value of the 'client_info' pointer
503 */
504void *
505GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr)
506{
507 void *client_info;
508
509 GNUNET_assert (NULL == sr->sc);
510 GNUNET_FS_search_stop_probe_ (sr);
511 GNUNET_FS_uri_destroy (sr->uri);
512 GNUNET_CONTAINER_meta_data_destroy (sr->meta);
513 client_info = sr->client_info;
514 GNUNET_free (sr);
515 return client_info;
516}
517
518
519/**
442 * We have received a KSK result. Check how it fits in with the 520 * We have received a KSK result. Check how it fits in with the
443 * overall query and notify the client accordingly. 521 * overall query and notify the client accordingly.
444 * 522 *
@@ -480,6 +558,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc,
480 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 558 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
481 sr->h = sc->h; 559 sr->h = sc->h;
482 sr->sc = sc; 560 sr->sc = sc;
561 sr->anonymity = sc->anonymity;
483 sr->uri = GNUNET_FS_uri_dup (uri); 562 sr->uri = GNUNET_FS_uri_dup (uri);
484 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 563 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
485 sr->mandatory_missing = sc->mandatory_count; 564 sr->mandatory_missing = sc->mandatory_count;
@@ -560,6 +639,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, const char *id_update,
560 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult)); 639 sr = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchResult));
561 sr->h = sc->h; 640 sr->h = sc->h;
562 sr->sc = sc; 641 sr->sc = sc;
642 sr->anonymity = sc->anonymity;
563 sr->uri = GNUNET_FS_uri_dup (uri); 643 sr->uri = GNUNET_FS_uri_dup (uri);
564 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta); 644 sr->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
565 sr->key = key; 645 sr->key = key;
@@ -1489,21 +1569,7 @@ search_result_stop (void *cls, const struct GNUNET_HashCode * key, void *value)
1489 struct GNUNET_FS_SearchResult *sr = value; 1569 struct GNUNET_FS_SearchResult *sr = value;
1490 struct GNUNET_FS_ProgressInfo pi; 1570 struct GNUNET_FS_ProgressInfo pi;
1491 1571
1492 if (NULL != sr->probe_ctx) 1572 GNUNET_FS_search_stop_probe_ (sr);
1493 {
1494 GNUNET_FS_download_stop (sr->probe_ctx, GNUNET_YES);
1495 sr->probe_ctx = NULL;
1496 }
1497 if (GNUNET_SCHEDULER_NO_TASK != sr->probe_ping_task)
1498 {
1499 GNUNET_SCHEDULER_cancel (sr->probe_ping_task);
1500 sr->probe_ping_task = GNUNET_SCHEDULER_NO_TASK;
1501 }
1502 if (GNUNET_SCHEDULER_NO_TASK != sr->probe_cancel_task)
1503 {
1504 GNUNET_SCHEDULER_cancel (sr->probe_cancel_task);
1505 sr->probe_cancel_task = GNUNET_SCHEDULER_NO_TASK;
1506 }
1507 1573
1508 if (NULL != sr->download) 1574 if (NULL != sr->download)
1509 { 1575 {
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h
index 32f7dad40..d1859fa05 100644
--- a/src/include/gnunet_fs_service.h
+++ b/src/include/gnunet_fs_service.h
@@ -2775,6 +2775,33 @@ void
2775GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc); 2775GNUNET_FS_search_stop (struct GNUNET_FS_SearchContext *sc);
2776 2776
2777 2777
2778/**
2779 * Start download probes for the given search result.
2780 *
2781 * @param h file-sharing handle to use for the operation
2782 * @param uri URI to probe
2783 * @param meta meta data associated with the URI
2784 * @param client_info client info pointer to use for associated events
2785 * @param anonymity anonymity level to use for the probes
2786 * @return the search result handle to access the probe activity
2787 */
2788struct GNUNET_FS_SearchResult *
2789GNUNET_FS_probe (struct GNUNET_FS_Handle *h,
2790 const struct GNUNET_FS_Uri *uri,
2791 const struct GNUNET_CONTAINER_MetaData *meta,
2792 void *client_info,
2793 uint32_t anonymity);
2794
2795
2796/**
2797 * Stop probe activity. Must ONLY be used on values
2798 * returned from 'GNUNET_FS_probe'.
2799 *
2800 * @param sr search result to stop probing for (freed)
2801 * @return the value of the 'client_info' pointer
2802 */
2803void *
2804GNUNET_FS_probe_stop (struct GNUNET_FS_SearchResult *sr);
2778 2805
2779 2806
2780/** 2807/**