diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-04-28 12:40:41 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-04-28 12:40:41 +0000 |
commit | d83a3d2ac2a33d43239bbd5703574872081ba81f (patch) | |
tree | 4cf623eeec48634fa1d0ffd6ce31521ee90a3c3c /src/fs | |
parent | 0398c75b95c53ffd109635e5477e8bb3b93217de (diff) | |
download | gnunet-d83a3d2ac2a33d43239bbd5703574872081ba81f.tar.gz gnunet-d83a3d2ac2a33d43239bbd5703574872081ba81f.zip |
added option to restrict search to local-only
Diffstat (limited to 'src/fs')
-rw-r--r-- | src/fs/fs.h | 12 | ||||
-rw-r--r-- | src/fs/fs_download.c | 4 | ||||
-rw-r--r-- | src/fs/fs_search.c | 18 | ||||
-rw-r--r-- | src/fs/gnunet-download.c | 6 | ||||
-rw-r--r-- | src/fs/gnunet-search.c | 10 | ||||
-rw-r--r-- | src/fs/gnunet-service-fs.c | 13 | ||||
-rw-r--r-- | src/fs/test_fs_namespace.c | 4 | ||||
-rw-r--r-- | src/fs/test_fs_search.c | 1 |
8 files changed, 60 insertions, 8 deletions
diff --git a/src/fs/fs.h b/src/fs/fs.h index 0a656e1e9..a6a12b9cd 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -1079,7 +1079,10 @@ struct GNUNET_FS_SearchContext | |||
1079 | */ | 1079 | */ |
1080 | uint32_t mandatory_count; | 1080 | uint32_t mandatory_count; |
1081 | 1081 | ||
1082 | 1082 | /** | |
1083 | * Options for the search. | ||
1084 | */ | ||
1085 | enum GNUNET_FS_SearchOptions options; | ||
1083 | }; | 1086 | }; |
1084 | 1087 | ||
1085 | 1088 | ||
@@ -1439,9 +1442,10 @@ struct SearchMessage | |||
1439 | struct GNUNET_MessageHeader header; | 1442 | struct GNUNET_MessageHeader header; |
1440 | 1443 | ||
1441 | /** | 1444 | /** |
1442 | * Should be zero. | 1445 | * Bitmask with options. Zero for no options, one for loopback-only. |
1446 | * Other bits are currently not defined. | ||
1443 | */ | 1447 | */ |
1444 | int32_t reserved GNUNET_PACKED; | 1448 | int32_t options GNUNET_PACKED; |
1445 | 1449 | ||
1446 | /** | 1450 | /** |
1447 | * Type of the content that we're looking for. | 1451 | * Type of the content that we're looking for. |
@@ -1536,7 +1540,7 @@ struct GetMessage | |||
1536 | uint32_t priority GNUNET_PACKED; | 1540 | uint32_t priority GNUNET_PACKED; |
1537 | 1541 | ||
1538 | /** | 1542 | /** |
1539 | * Relative time to live in GNUNET_CRON_MILLISECONDS (network byte order) | 1543 | * Relative time to live in MILLISECONDS (network byte order) |
1540 | */ | 1544 | */ |
1541 | int32_t ttl GNUNET_PACKED; | 1545 | int32_t ttl GNUNET_PACKED; |
1542 | 1546 | ||
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 14e6266f8..fe9c18aa1 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -1150,6 +1150,10 @@ transmit_download_request (void *cls, | |||
1150 | memset (sm, 0, sizeof (struct SearchMessage)); | 1150 | memset (sm, 0, sizeof (struct SearchMessage)); |
1151 | sm->header.size = htons (sizeof (struct SearchMessage)); | 1151 | sm->header.size = htons (sizeof (struct SearchMessage)); |
1152 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 1152 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
1153 | if (0 != (dc->options & GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY)) | ||
1154 | sm->options = htonl (1); | ||
1155 | else | ||
1156 | sm->options = htonl (0); | ||
1153 | if (dc->pending->depth == dc->treedepth) | 1157 | if (dc->pending->depth == dc->treedepth) |
1154 | sm->type = htonl (GNUNET_BLOCK_TYPE_DBLOCK); | 1158 | sm->type = htonl (GNUNET_BLOCK_TYPE_DBLOCK); |
1155 | else | 1159 | else |
diff --git a/src/fs/fs_search.c b/src/fs/fs_search.c index 2c8022237..efe5bf34a 100644 --- a/src/fs/fs_search.c +++ b/src/fs/fs_search.c | |||
@@ -458,6 +458,7 @@ process_ksk_result (struct GNUNET_FS_SearchContext *sc, | |||
458 | * @param uri specifies the search parameters; can be | 458 | * @param uri specifies the search parameters; can be |
459 | * a KSK URI or an SKS URI. | 459 | * a KSK URI or an SKS URI. |
460 | * @param anonymity desired level of anonymity | 460 | * @param anonymity desired level of anonymity |
461 | * @param options options for the search | ||
461 | * @param cctx client context | 462 | * @param cctx client context |
462 | * @param parent parent search (for namespace update searches) | 463 | * @param parent parent search (for namespace update searches) |
463 | * @return context that can be used to control the search | 464 | * @return context that can be used to control the search |
@@ -466,6 +467,7 @@ static struct GNUNET_FS_SearchContext * | |||
466 | search_start (struct GNUNET_FS_Handle *h, | 467 | search_start (struct GNUNET_FS_Handle *h, |
467 | const struct GNUNET_FS_Uri *uri, | 468 | const struct GNUNET_FS_Uri *uri, |
468 | uint32_t anonymity, | 469 | uint32_t anonymity, |
470 | enum GNUNET_FS_SearchOptions options, | ||
469 | void *cctx, | 471 | void *cctx, |
470 | struct GNUNET_FS_SearchContext *parent); | 472 | struct GNUNET_FS_SearchContext *parent); |
471 | 473 | ||
@@ -523,6 +525,7 @@ process_sks_result (struct GNUNET_FS_SearchContext *sc, | |||
523 | search_start (sc->h, | 525 | search_start (sc->h, |
524 | &uu, | 526 | &uu, |
525 | sc->anonymity, | 527 | sc->anonymity, |
528 | sc->options, | ||
526 | NULL, | 529 | NULL, |
527 | sc); | 530 | sc); |
528 | } | 531 | } |
@@ -938,6 +941,10 @@ transmit_search_request (void *cls, | |||
938 | { | 941 | { |
939 | sm[i].header.size = htons (sizeof (struct SearchMessage)); | 942 | sm[i].header.size = htons (sizeof (struct SearchMessage)); |
940 | sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 943 | sm[i].header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
944 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
945 | sm[i].options = htonl (1); | ||
946 | else | ||
947 | sm[i].options = htonl (0); | ||
941 | sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY); | 948 | sm[i].type = htonl (GNUNET_BLOCK_TYPE_ANY); |
942 | sm[i].anonymity_level = htonl (sc->anonymity); | 949 | sm[i].anonymity_level = htonl (sc->anonymity); |
943 | sm[i].query = sc->requests[i].query; | 950 | sm[i].query = sc->requests[i].query; |
@@ -952,6 +959,10 @@ transmit_search_request (void *cls, | |||
952 | memset (sm, 0, msize); | 959 | memset (sm, 0, msize); |
953 | sm->header.size = htons (sizeof (struct SearchMessage)); | 960 | sm->header.size = htons (sizeof (struct SearchMessage)); |
954 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); | 961 | sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH); |
962 | if (0 != (sc->options & GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY)) | ||
963 | sm->options = htonl (1); | ||
964 | else | ||
965 | sm->options = htonl (0); | ||
955 | sm->type = htonl (GNUNET_BLOCK_TYPE_SBLOCK); | 966 | sm->type = htonl (GNUNET_BLOCK_TYPE_SBLOCK); |
956 | sm->anonymity_level = htonl (sc->anonymity); | 967 | sm->anonymity_level = htonl (sc->anonymity); |
957 | sm->target = sc->uri->data.sks.namespace; | 968 | sm->target = sc->uri->data.sks.namespace; |
@@ -1042,6 +1053,7 @@ try_reconnect (struct GNUNET_FS_SearchContext *sc) | |||
1042 | * @param uri specifies the search parameters; can be | 1053 | * @param uri specifies the search parameters; can be |
1043 | * a KSK URI or an SKS URI. | 1054 | * a KSK URI or an SKS URI. |
1044 | * @param anonymity desired level of anonymity | 1055 | * @param anonymity desired level of anonymity |
1056 | * @param options options for the search | ||
1045 | * @param cctx initial value for the client context | 1057 | * @param cctx initial value for the client context |
1046 | * @param parent parent search (for namespace update searches) | 1058 | * @param parent parent search (for namespace update searches) |
1047 | * @return context that can be used to control the search | 1059 | * @return context that can be used to control the search |
@@ -1050,6 +1062,7 @@ static struct GNUNET_FS_SearchContext * | |||
1050 | search_start (struct GNUNET_FS_Handle *h, | 1062 | search_start (struct GNUNET_FS_Handle *h, |
1051 | const struct GNUNET_FS_Uri *uri, | 1063 | const struct GNUNET_FS_Uri *uri, |
1052 | uint32_t anonymity, | 1064 | uint32_t anonymity, |
1065 | enum GNUNET_FS_SearchOptions options, | ||
1053 | void *cctx, | 1066 | void *cctx, |
1054 | struct GNUNET_FS_SearchContext *parent) | 1067 | struct GNUNET_FS_SearchContext *parent) |
1055 | { | 1068 | { |
@@ -1085,6 +1098,7 @@ search_start (struct GNUNET_FS_Handle *h, | |||
1085 | return NULL; | 1098 | return NULL; |
1086 | sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext)); | 1099 | sc = GNUNET_malloc (sizeof(struct GNUNET_FS_SearchContext)); |
1087 | sc->h = h; | 1100 | sc->h = h; |
1101 | sc->options = options; | ||
1088 | sc->uri = GNUNET_FS_uri_dup (uri); | 1102 | sc->uri = GNUNET_FS_uri_dup (uri); |
1089 | sc->anonymity = anonymity; | 1103 | sc->anonymity = anonymity; |
1090 | sc->start_time = GNUNET_TIME_absolute_get (); | 1104 | sc->start_time = GNUNET_TIME_absolute_get (); |
@@ -1139,6 +1153,7 @@ search_start (struct GNUNET_FS_Handle *h, | |||
1139 | * @param uri specifies the search parameters; can be | 1153 | * @param uri specifies the search parameters; can be |
1140 | * a KSK URI or an SKS URI. | 1154 | * a KSK URI or an SKS URI. |
1141 | * @param anonymity desired level of anonymity | 1155 | * @param anonymity desired level of anonymity |
1156 | * @param options options for the search | ||
1142 | * @param cctx initial value for the client context | 1157 | * @param cctx initial value for the client context |
1143 | * @return context that can be used to control the search | 1158 | * @return context that can be used to control the search |
1144 | */ | 1159 | */ |
@@ -1146,9 +1161,10 @@ struct GNUNET_FS_SearchContext * | |||
1146 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, | 1161 | GNUNET_FS_search_start (struct GNUNET_FS_Handle *h, |
1147 | const struct GNUNET_FS_Uri *uri, | 1162 | const struct GNUNET_FS_Uri *uri, |
1148 | uint32_t anonymity, | 1163 | uint32_t anonymity, |
1164 | enum GNUNET_FS_SearchOptions options, | ||
1149 | void *cctx) | 1165 | void *cctx) |
1150 | { | 1166 | { |
1151 | return search_start (h, uri, anonymity, cctx, NULL); | 1167 | return search_start (h, uri, anonymity, options, cctx, NULL); |
1152 | } | 1168 | } |
1153 | 1169 | ||
1154 | 1170 | ||
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index bc98d0275..fde254d7c 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -52,6 +52,7 @@ static int do_recursive; | |||
52 | 52 | ||
53 | static char *filename; | 53 | static char *filename; |
54 | 54 | ||
55 | static int local_only; | ||
55 | 56 | ||
56 | static void | 57 | static void |
57 | cleanup_task (void *cls, | 58 | cleanup_task (void *cls, |
@@ -225,6 +226,8 @@ run (void *cls, | |||
225 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; | 226 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
226 | if (do_recursive) | 227 | if (do_recursive) |
227 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; | 228 | options |= GNUNET_FS_DOWNLOAD_OPTION_RECURSIVE; |
229 | if (local_only) | ||
230 | options |= GNUNET_FS_DOWNLOAD_OPTION_LOOPBACK_ONLY; | ||
228 | dc = GNUNET_FS_download_start (ctx, | 231 | dc = GNUNET_FS_download_start (ctx, |
229 | uri, | 232 | uri, |
230 | NULL, | 233 | NULL, |
@@ -259,6 +262,9 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
259 | {'D', "delete-incomplete", NULL, | 262 | {'D', "delete-incomplete", NULL, |
260 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), | 263 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), |
261 | 0, &GNUNET_GETOPT_set_one, &delete_incomplete}, | 264 | 0, &GNUNET_GETOPT_set_one, &delete_incomplete}, |
265 | {'n', "no-network", NULL, | ||
266 | gettext_noop ("only search the local peer (no P2P network search)"), | ||
267 | 1, &GNUNET_GETOPT_set_uint, &local_only}, | ||
262 | {'o', "output", "FILENAME", | 268 | {'o', "output", "FILENAME", |
263 | gettext_noop ("write the file to FILENAME"), | 269 | gettext_noop ("write the file to FILENAME"), |
264 | 1, &GNUNET_GETOPT_set_string, &filename}, | 270 | 1, &GNUNET_GETOPT_set_string, &filename}, |
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 64955a3ee..0226a340e 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -46,6 +46,8 @@ static unsigned int anonymity = 1; | |||
46 | 46 | ||
47 | static int verbose; | 47 | static int verbose; |
48 | 48 | ||
49 | static int local_only; | ||
50 | |||
49 | /** | 51 | /** |
50 | * Type of a function that libextractor calls for each | 52 | * Type of a function that libextractor calls for each |
51 | * meta data item found. | 53 | * meta data item found. |
@@ -231,6 +233,7 @@ run (void *cls, | |||
231 | { | 233 | { |
232 | struct GNUNET_FS_Uri *uri; | 234 | struct GNUNET_FS_Uri *uri; |
233 | unsigned int argc; | 235 | unsigned int argc; |
236 | enum GNUNET_FS_SearchOptions options; | ||
234 | 237 | ||
235 | sched = s; | 238 | sched = s; |
236 | argc = 0; | 239 | argc = 0; |
@@ -266,9 +269,13 @@ run (void *cls, | |||
266 | } | 269 | } |
267 | if (output_filename != NULL) | 270 | if (output_filename != NULL) |
268 | db = GNUNET_FS_directory_builder_create (NULL); | 271 | db = GNUNET_FS_directory_builder_create (NULL); |
272 | options = GNUNET_FS_SEARCH_OPTION_NONE; | ||
273 | if (local_only) | ||
274 | options |= GNUNET_FS_SEARCH_OPTION_LOOPBACK_ONLY; | ||
269 | sc = GNUNET_FS_search_start (ctx, | 275 | sc = GNUNET_FS_search_start (ctx, |
270 | uri, | 276 | uri, |
271 | anonymity, | 277 | anonymity, |
278 | options, | ||
272 | NULL); | 279 | NULL); |
273 | GNUNET_FS_uri_destroy (uri); | 280 | GNUNET_FS_uri_destroy (uri); |
274 | if (NULL == sc) | 281 | if (NULL == sc) |
@@ -293,6 +300,9 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
293 | {'a', "anonymity", "LEVEL", | 300 | {'a', "anonymity", "LEVEL", |
294 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), | 301 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), |
295 | 1, &GNUNET_GETOPT_set_uint, &anonymity}, | 302 | 1, &GNUNET_GETOPT_set_uint, &anonymity}, |
303 | {'n', "no-network", NULL, | ||
304 | gettext_noop ("only search the local peer (no P2P network search)"), | ||
305 | 1, &GNUNET_GETOPT_set_uint, &local_only}, | ||
296 | {'o', "output", "PREFIX", | 306 | {'o', "output", "PREFIX", |
297 | gettext_noop | 307 | gettext_noop |
298 | ("write search results to file starting with PREFIX"), | 308 | ("write search results to file starting with PREFIX"), |
diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index 41be75e98..84a4f1d65 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c | |||
@@ -545,7 +545,12 @@ struct PendingRequest | |||
545 | /** | 545 | /** |
546 | * Remove this request after transmission of the current response. | 546 | * Remove this request after transmission of the current response. |
547 | */ | 547 | */ |
548 | int do_remove; | 548 | int16_t do_remove; |
549 | |||
550 | /** | ||
551 | * GNUNET_YES if we should not forward this request to other peers. | ||
552 | */ | ||
553 | int16_t local_only; | ||
549 | 554 | ||
550 | }; | 555 | }; |
551 | 556 | ||
@@ -1600,6 +1605,8 @@ forward_request_task (void *cls, | |||
1600 | #endif | 1605 | #endif |
1601 | return; /* already pending */ | 1606 | return; /* already pending */ |
1602 | } | 1607 | } |
1608 | if (GNUNET_YES == pr->local_only) | ||
1609 | return; /* configured to not do P2P search */ | ||
1603 | /* (1) select target */ | 1610 | /* (1) select target */ |
1604 | psc.pr = pr; | 1611 | psc.pr = pr; |
1605 | psc.target_score = DBL_MIN; | 1612 | psc.target_score = DBL_MIN; |
@@ -2783,6 +2790,10 @@ handle_start_search (void *cls, | |||
2783 | pr->anonymity_level = ntohl (sm->anonymity_level); | 2790 | pr->anonymity_level = ntohl (sm->anonymity_level); |
2784 | refresh_bloomfilter (pr); | 2791 | refresh_bloomfilter (pr); |
2785 | pr->query = sm->query; | 2792 | pr->query = sm->query; |
2793 | if (0 == (1 & ntohl (sm->options))) | ||
2794 | pr->local_only = GNUNET_NO; | ||
2795 | else | ||
2796 | pr->local_only = GNUNET_YES; | ||
2786 | switch (type) | 2797 | switch (type) |
2787 | { | 2798 | { |
2788 | case GNUNET_BLOCK_TYPE_DBLOCK: | 2799 | case GNUNET_BLOCK_TYPE_DBLOCK: |
diff --git a/src/fs/test_fs_namespace.c b/src/fs/test_fs_namespace.c index b57f19bc9..b154ce799 100644 --- a/src/fs/test_fs_namespace.c +++ b/src/fs/test_fs_namespace.c | |||
@@ -250,8 +250,8 @@ publish_cont (void *cls, | |||
250 | GNUNET_free (msg); | 250 | GNUNET_free (msg); |
251 | return; | 251 | return; |
252 | } | 252 | } |
253 | ksk_search = GNUNET_FS_search_start (fs, ksk_uri, 1, "ksk_search"); | 253 | ksk_search = GNUNET_FS_search_start (fs, ksk_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "ksk_search"); |
254 | sks_search = GNUNET_FS_search_start (fs, sks_uri, 1, "sks_search"); | 254 | sks_search = GNUNET_FS_search_start (fs, sks_uri, 1, GNUNET_FS_SEARCH_OPTION_NONE, "sks_search"); |
255 | GNUNET_FS_uri_destroy (sks_uri); | 255 | GNUNET_FS_uri_destroy (sks_uri); |
256 | } | 256 | } |
257 | 257 | ||
diff --git a/src/fs/test_fs_search.c b/src/fs/test_fs_search.c index 5f5f7f62a..32f885814 100644 --- a/src/fs/test_fs_search.c +++ b/src/fs/test_fs_search.c | |||
@@ -115,6 +115,7 @@ progress_cb (void *cls, | |||
115 | search = GNUNET_FS_search_start (fs, | 115 | search = GNUNET_FS_search_start (fs, |
116 | kuri, | 116 | kuri, |
117 | 1, | 117 | 1, |
118 | GNUNET_FS_SEARCH_OPTION_NONE, | ||
118 | "search"); | 119 | "search"); |
119 | GNUNET_FS_uri_destroy (kuri); | 120 | GNUNET_FS_uri_destroy (kuri); |
120 | GNUNET_assert (search != NULL); | 121 | GNUNET_assert (search != NULL); |