diff options
author | Christian Grothoff <christian@grothoff.org> | 2009-09-06 21:03:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2009-09-06 21:03:16 +0000 |
commit | 2a534fc5efadca1b65648efb903c3b4c17ac33ad (patch) | |
tree | d20be6f1d2ce6faff9ae6475c507f2aa33691e16 /src | |
parent | c263f813925949b97bfd899e174eefe4ecccced8 (diff) | |
download | gnunet-2a534fc5efadca1b65648efb903c3b4c17ac33ad.tar.gz gnunet-2a534fc5efadca1b65648efb903c3b4c17ac33ad.zip |
fs tools
Diffstat (limited to 'src')
-rw-r--r-- | src/fs/fs.c | 9 | ||||
-rw-r--r-- | src/fs/fs.h | 5 | ||||
-rw-r--r-- | src/fs/fs_download.c | 2 | ||||
-rw-r--r-- | src/fs/fs_publish.c | 2 | ||||
-rw-r--r-- | src/fs/gnunet-download.c | 120 | ||||
-rw-r--r-- | src/fs/gnunet-publish.c | 62 | ||||
-rw-r--r-- | src/fs/gnunet-search.c | 104 | ||||
-rw-r--r-- | src/fs/gnunet-unindex.c | 54 | ||||
-rw-r--r-- | src/include/gnunet_fs_service.h | 59 |
9 files changed, 387 insertions, 30 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c index 66699507b..8396fc18f 100644 --- a/src/fs/fs.c +++ b/src/fs/fs.c | |||
@@ -37,13 +37,18 @@ | |||
37 | * @param client_name unique identifier for this client | 37 | * @param client_name unique identifier for this client |
38 | * @param upcb function to call to notify about FS actions | 38 | * @param upcb function to call to notify about FS actions |
39 | * @param upcb_cls closure for upcb | 39 | * @param upcb_cls closure for upcb |
40 | * @param flags specific attributes for fs-operations | ||
41 | * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END | ||
42 | * @return NULL on error | ||
40 | */ | 43 | */ |
41 | struct GNUNET_FS_Handle * | 44 | struct GNUNET_FS_Handle * |
42 | GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, | 45 | GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, |
43 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 46 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
44 | const char *client_name, | 47 | const char *client_name, |
45 | GNUNET_FS_ProgressCallback upcb, | 48 | GNUNET_FS_ProgressCallback upcb, |
46 | void *upcb_cls) | 49 | void *upcb_cls, |
50 | enum GNUNET_FS_Flags flags, | ||
51 | ...) | ||
47 | { | 52 | { |
48 | struct GNUNET_FS_Handle *ret; | 53 | struct GNUNET_FS_Handle *ret; |
49 | struct GNUNET_CLIENT_Connection *client; | 54 | struct GNUNET_CLIENT_Connection *client; |
@@ -60,6 +65,8 @@ GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, | |||
60 | ret->upcb = upcb; | 65 | ret->upcb = upcb; |
61 | ret->upcb_cls = upcb_cls; | 66 | ret->upcb_cls = upcb_cls; |
62 | ret->client = client; | 67 | ret->client = client; |
68 | ret->flags = flags; | ||
69 | // FIXME: process varargs! | ||
63 | // FIXME: setup receive-loop with client | 70 | // FIXME: setup receive-loop with client |
64 | 71 | ||
65 | // FIXME: deserialize state; use client-name to find master-directory! | 72 | // FIXME: deserialize state; use client-name to find master-directory! |
diff --git a/src/fs/fs.h b/src/fs/fs.h index 70e02360c..c2a2e7d03 100644 --- a/src/fs/fs.h +++ b/src/fs/fs.h | |||
@@ -389,6 +389,11 @@ struct GNUNET_FS_Handle | |||
389 | */ | 389 | */ |
390 | unsigned int active_probes; | 390 | unsigned int active_probes; |
391 | 391 | ||
392 | /** | ||
393 | * General flags. | ||
394 | */ | ||
395 | enum GNUNET_FS_Flags flags; | ||
396 | |||
392 | }; | 397 | }; |
393 | 398 | ||
394 | 399 | ||
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index 145e16818..77fbb1139 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c | |||
@@ -142,6 +142,8 @@ make_download_status (struct GNUNET_FS_ProgressInfo *pi, | |||
142 | = (dc->parent == NULL) ? NULL : dc->parent->client_info; | 142 | = (dc->parent == NULL) ? NULL : dc->parent->client_info; |
143 | pi->value.download.uri | 143 | pi->value.download.uri |
144 | = dc->uri; | 144 | = dc->uri; |
145 | pi->value.download.filename | ||
146 | = dc->filename; | ||
145 | pi->value.download.length | 147 | pi->value.download.length |
146 | = dc->length; | 148 | = dc->length; |
147 | pi->value.download.duration | 149 | pi->value.download.duration |
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c index d58ea3f37..db38b76da 100644 --- a/src/fs/fs_publish.c +++ b/src/fs/fs_publish.c | |||
@@ -111,6 +111,8 @@ make_publish_status (struct GNUNET_FS_ProgressInfo *pi, | |||
111 | = p->client_info; | 111 | = p->client_info; |
112 | pi->value.publish.pctx | 112 | pi->value.publish.pctx |
113 | = (NULL == p->dir) ? NULL : p->dir->client_info; | 113 | = (NULL == p->dir) ? NULL : p->dir->client_info; |
114 | pi->value.publish.filename | ||
115 | = (p->is_directory) ? p->data.dir.dirname : p->data.file.filename; | ||
114 | pi->value.publish.size | 116 | pi->value.publish.size |
115 | = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; | 117 | = (p->is_directory) ? p->data.dir.dir_size : p->data.file.file_size; |
116 | pi->value.publish.eta | 118 | pi->value.publish.eta |
diff --git a/src/fs/gnunet-download.c b/src/fs/gnunet-download.c index c6bb7c115..681608d6b 100644 --- a/src/fs/gnunet-download.c +++ b/src/fs/gnunet-download.c | |||
@@ -26,21 +26,26 @@ | |||
26 | * @author Igor Wronsky | 26 | * @author Igor Wronsky |
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - all | 29 | * - many command-line options |
30 | */ | 30 | */ |
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include "gnunet_fs_service.h" | 32 | #include "gnunet_fs_service.h" |
33 | 33 | ||
34 | static int ret; | 34 | static int ret; |
35 | 35 | ||
36 | static int verbose; | ||
37 | |||
38 | static int delete_incomplete; | ||
39 | |||
36 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 40 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
37 | 41 | ||
38 | static struct GNUNET_FS_Handle *ctx; | 42 | static struct GNUNET_FS_Handle *ctx; |
39 | 43 | ||
40 | static struct GNUNET_TIME_Absolute start_time; | 44 | static struct GNUNET_FS_DownloadContext *dc; |
41 | 45 | ||
42 | static unsigned int anonymity = 1; | 46 | static unsigned int anonymity = 1; |
43 | 47 | ||
48 | static char *filename; | ||
44 | 49 | ||
45 | /** | 50 | /** |
46 | * Called by FS client to give information about the progress of an | 51 | * Called by FS client to give information about the progress of an |
@@ -59,6 +64,44 @@ static void * | |||
59 | progress_cb (void *cls, | 64 | progress_cb (void *cls, |
60 | const struct GNUNET_FS_ProgressInfo *info) | 65 | const struct GNUNET_FS_ProgressInfo *info) |
61 | { | 66 | { |
67 | switch (info->status) | ||
68 | { | ||
69 | case GNUNET_FS_STATUS_DOWNLOAD_START: | ||
70 | break; | ||
71 | case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: | ||
72 | if (verbose) | ||
73 | fprintf (stdout, | ||
74 | _("Downloading `%s' at %llu/%llu (%s remaining, %s/s)\n"), | ||
75 | info->value.download.filename, | ||
76 | (unsigned long long) info->value.download.completed, | ||
77 | (unsigned long long) info->value.download.length, | ||
78 | GNUNET_STRINGS_relative_time_to_string(info->value.download.eta), | ||
79 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); | ||
80 | break; | ||
81 | case GNUNET_FS_STATUS_DOWNLOAD_ERROR: | ||
82 | fprintf (stderr, | ||
83 | _("Error downloading: %s.\n"), | ||
84 | info->value.download.specifics.error.message); | ||
85 | GNUNET_FS_file_download_stop (dc, delete_incomplete); | ||
86 | break; | ||
87 | case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: | ||
88 | fprintf (stdout, | ||
89 | _("Downloading `%s' done (%s/s).\n"), | ||
90 | info->value.download.filename, | ||
91 | GNUNET_STRINGS_byte_size_fancy(info->value.download.completed * 1000 / (info->value.download.duration.value + 1))); | ||
92 | if (info->value.download.dc == dc) | ||
93 | GNUNET_FS_file_download_stop (dc, delete_incomplete); | ||
94 | break; | ||
95 | case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: | ||
96 | if (info->value.download.dc == dc) | ||
97 | GNUNET_FS_stop (ctx); | ||
98 | break; | ||
99 | default: | ||
100 | fprintf (stderr, | ||
101 | _("Unexpected status: %d\n"), | ||
102 | info->status); | ||
103 | break; | ||
104 | } | ||
62 | return NULL; | 105 | return NULL; |
63 | } | 106 | } |
64 | 107 | ||
@@ -79,23 +122,66 @@ run (void *cls, | |||
79 | const char *cfgfile, | 122 | const char *cfgfile, |
80 | const struct GNUNET_CONFIGURATION_Handle *c) | 123 | const struct GNUNET_CONFIGURATION_Handle *c) |
81 | { | 124 | { |
125 | struct GNUNET_FS_Uri *uri; | ||
126 | char *emsg; | ||
127 | enum GNUNET_FS_DownloadOptions options; | ||
128 | |||
82 | /* FIXME: check arguments */ | 129 | /* FIXME: check arguments */ |
130 | uri = GNUNET_FS_uri_parse (args[0], | ||
131 | &emsg); | ||
132 | if (NULL == uri) | ||
133 | { | ||
134 | fprintf (stderr, | ||
135 | _("Failed to parse URI: %s\n"), | ||
136 | emsg); | ||
137 | GNUNET_free (emsg); | ||
138 | ret = 1; | ||
139 | return; | ||
140 | } | ||
141 | if (! GNUNET_FS_uri_test_chk (uri)) | ||
142 | { | ||
143 | fprintf (stderr, | ||
144 | "Only CHK URIs supported right now.\n"); | ||
145 | ret = 1; | ||
146 | GNUNET_FS_uri_destroy (uri); | ||
147 | return; | ||
148 | } | ||
149 | if (NULL == filename) | ||
150 | { | ||
151 | fprintf (stderr, | ||
152 | "Target filename must be specified.\n"); | ||
153 | ret = 1; | ||
154 | GNUNET_FS_uri_destroy (uri); | ||
155 | return; | ||
156 | } | ||
83 | cfg = c; | 157 | cfg = c; |
84 | ctx = GNUNET_FS_start (sched, | 158 | ctx = GNUNET_FS_start (sched, |
85 | cfg, | 159 | cfg, |
86 | "gnunet-download", | 160 | "gnunet-download", |
87 | &progress_cb, | 161 | &progress_cb, |
88 | NULL); | 162 | NULL, |
163 | GNUNET_FS_FLAGS_NONE, | ||
164 | GNUNET_FS_OPTIONS_END); | ||
89 | if (NULL == ctx) | 165 | if (NULL == ctx) |
90 | { | 166 | { |
91 | fprintf (stderr, | 167 | fprintf (stderr, |
92 | _("Could not initialize `%s' subsystem.\n"), | 168 | _("Could not initialize `%s' subsystem.\n"), |
93 | "FS"); | 169 | "FS"); |
170 | GNUNET_FS_uri_destroy (uri); | ||
94 | ret = 1; | 171 | ret = 1; |
95 | return; | 172 | return; |
96 | } | 173 | } |
97 | start_time = GNUNET_TIME_absolute_get (); | 174 | options = GNUNET_FS_DOWNLOAD_OPTION_NONE; |
98 | // FIXME: start download | 175 | dc = GNUNET_FS_file_download_start (ctx, |
176 | uri, | ||
177 | NULL, | ||
178 | filename, | ||
179 | 0, | ||
180 | GNUNET_FS_uri_chk_get_file_size (uri), | ||
181 | anonymity, | ||
182 | options, | ||
183 | NULL); | ||
184 | GNUNET_FS_uri_destroy (uri); | ||
99 | } | 185 | } |
100 | 186 | ||
101 | 187 | ||
@@ -106,7 +192,31 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
106 | {'a', "anonymity", "LEVEL", | 192 | {'a', "anonymity", "LEVEL", |
107 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), | 193 | gettext_noop ("set the desired LEVEL of receiver-anonymity"), |
108 | 1, &GNUNET_GETOPT_set_uint, &anonymity}, | 194 | 1, &GNUNET_GETOPT_set_uint, &anonymity}, |
195 | #if 0 | ||
109 | // FIXME: options! | 196 | // FIXME: options! |
197 | {'d', "directory", NULL, | ||
198 | gettext_noop | ||
199 | ("download a GNUnet directory that has already been downloaded. Requires that a filename of an existing file is specified instead of the URI. The download will only download the top-level files in the directory unless the `-R' option is also specified."), | ||
200 | 0, &GNUNET_getopt_configure_set_one, &do_directory}, | ||
201 | {'D', "delete-incomplete", NULL, | ||
202 | gettext_noop ("delete incomplete downloads (when aborted with CTRL-C)"), | ||
203 | 0, &GNUNET_getopt_configure_set_one, &do_delete_incomplete}, | ||
204 | #endif | ||
205 | {'o', "output", "FILENAME", | ||
206 | gettext_noop ("write the file to FILENAME"), | ||
207 | 1, &GNUNET_GETOPT_set_string, &filename}, | ||
208 | #if 0 | ||
209 | {'p', "parallelism", "DOWNLOADS", | ||
210 | gettext_noop | ||
211 | ("set the maximum number of parallel downloads that are allowed"), | ||
212 | 1, &GNUNET_getopt_configure_set_uint, ¶llelism}, | ||
213 | {'R', "recursive", NULL, | ||
214 | gettext_noop ("download a GNUnet directory recursively"), | ||
215 | 0, &GNUNET_getopt_configure_set_one, &do_recursive}, | ||
216 | #endif | ||
217 | {'V', "verbose", NULL, | ||
218 | gettext_noop ("be verbose (print progress information)"), | ||
219 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
110 | GNUNET_GETOPT_OPTION_END | 220 | GNUNET_GETOPT_OPTION_END |
111 | }; | 221 | }; |
112 | 222 | ||
diff --git a/src/fs/gnunet-publish.c b/src/fs/gnunet-publish.c index b6b9199d0..a30b36c9e 100644 --- a/src/fs/gnunet-publish.c +++ b/src/fs/gnunet-publish.c | |||
@@ -27,8 +27,6 @@ | |||
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - support for some options is still missing (uri argument) | 29 | * - support for some options is still missing (uri argument) |
30 | * - progress callbacks not implemented (and need verbosity option) | ||
31 | * - clean shutdown is not implemented (stop ctx, etc.) | ||
32 | */ | 30 | */ |
33 | #include "platform.h" | 31 | #include "platform.h" |
34 | #include "gnunet_fs_service.h" | 32 | #include "gnunet_fs_service.h" |
@@ -37,14 +35,14 @@ | |||
37 | 35 | ||
38 | static int ret; | 36 | static int ret; |
39 | 37 | ||
38 | static int verbose; | ||
39 | |||
40 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 40 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
41 | 41 | ||
42 | static struct GNUNET_FS_Handle *ctx; | 42 | static struct GNUNET_FS_Handle *ctx; |
43 | 43 | ||
44 | static struct GNUNET_FS_PublishContext *pc; | 44 | static struct GNUNET_FS_PublishContext *pc; |
45 | 45 | ||
46 | static struct GNUNET_TIME_Absolute start_time; | ||
47 | |||
48 | static struct GNUNET_CONTAINER_MetaData *meta; | 46 | static struct GNUNET_CONTAINER_MetaData *meta; |
49 | 47 | ||
50 | static struct GNUNET_FS_Uri *topKeywords; | 48 | static struct GNUNET_FS_Uri *topKeywords; |
@@ -89,7 +87,43 @@ static void * | |||
89 | progress_cb (void *cls, | 87 | progress_cb (void *cls, |
90 | const struct GNUNET_FS_ProgressInfo *info) | 88 | const struct GNUNET_FS_ProgressInfo *info) |
91 | { | 89 | { |
92 | return NULL; | 90 | switch (info->status) |
91 | { | ||
92 | case GNUNET_FS_STATUS_PUBLISH_START: | ||
93 | break; | ||
94 | case GNUNET_FS_STATUS_PUBLISH_PROGRESS: | ||
95 | if (verbose) | ||
96 | fprintf (stdout, | ||
97 | _("Publishing `%s' at %llu/%llu (%s remaining)\n"), | ||
98 | info->value.publish.filename, | ||
99 | (unsigned long long) info->value.publish.completed, | ||
100 | (unsigned long long) info->value.publish.size, | ||
101 | GNUNET_STRINGS_relative_time_to_string(info->value.publish.eta)); | ||
102 | break; | ||
103 | case GNUNET_FS_STATUS_PUBLISH_ERROR: | ||
104 | fprintf (stderr, | ||
105 | _("Error publishing: %s.\n"), | ||
106 | info->value.publish.specifics.error.message); | ||
107 | GNUNET_FS_publish_stop (pc); | ||
108 | break; | ||
109 | case GNUNET_FS_STATUS_PUBLISH_COMPLETED: | ||
110 | fprintf (stdout, | ||
111 | _("Publishing `%s' done.\n"), | ||
112 | info->value.publish.filename); | ||
113 | if (info->value.publish.pctx == NULL) | ||
114 | GNUNET_FS_publish_stop (pc); | ||
115 | break; | ||
116 | case GNUNET_FS_STATUS_PUBLISH_STOPPED: | ||
117 | if (info->value.publish.sc == pc) | ||
118 | GNUNET_FS_stop (ctx); | ||
119 | return NULL; | ||
120 | default: | ||
121 | fprintf (stderr, | ||
122 | _("Unexpected status: %d\n"), | ||
123 | info->status); | ||
124 | return NULL; | ||
125 | } | ||
126 | return ""; /* non-null */ | ||
93 | } | 127 | } |
94 | 128 | ||
95 | 129 | ||
@@ -302,7 +336,9 @@ run (void *cls, | |||
302 | cfg, | 336 | cfg, |
303 | "gnunet-publish", | 337 | "gnunet-publish", |
304 | &progress_cb, | 338 | &progress_cb, |
305 | NULL); | 339 | NULL, |
340 | GNUNET_FS_FLAGS_NONE, | ||
341 | GNUNET_FS_OPTIONS_END); | ||
306 | if (NULL == ctx) | 342 | if (NULL == ctx) |
307 | { | 343 | { |
308 | fprintf (stderr, | 344 | fprintf (stderr, |
@@ -331,7 +367,6 @@ run (void *cls, | |||
331 | // FIXME -- implement! | 367 | // FIXME -- implement! |
332 | return; | 368 | return; |
333 | } | 369 | } |
334 | start_time = GNUNET_TIME_absolute_get (); | ||
335 | 370 | ||
336 | l = NULL; | 371 | l = NULL; |
337 | if (! disable_extractor) | 372 | if (! disable_extractor) |
@@ -389,6 +424,14 @@ run (void *cls, | |||
389 | (do_simulate) | 424 | (do_simulate) |
390 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY | 425 | ? GNUNET_FS_PUBLISH_OPTION_SIMULATE_ONLY |
391 | : GNUNET_FS_PUBLISH_OPTION_NONE); | 426 | : GNUNET_FS_PUBLISH_OPTION_NONE); |
427 | if (NULL == pc) | ||
428 | { | ||
429 | fprintf (stderr, | ||
430 | _("Could not start publishing.\n")); | ||
431 | GNUNET_FS_stop (ctx); | ||
432 | ret = 1; | ||
433 | return; | ||
434 | } | ||
392 | } | 435 | } |
393 | 436 | ||
394 | 437 | ||
@@ -449,7 +492,10 @@ static struct GNUNET_GETOPT_CommandLineOption options[] = { | |||
449 | {'u', "uri", "URI", | 492 | {'u', "uri", "URI", |
450 | gettext_noop ("URI to be published (can be used instead of passing a " | 493 | gettext_noop ("URI to be published (can be used instead of passing a " |
451 | "file to add keywords to the file with the respective URI)"), | 494 | "file to add keywords to the file with the respective URI)"), |
452 | 1, &GNUNET_GETOPT_set_string, &uri_string}, | 495 | 1, &GNUNET_GETOPT_set_string, &uri_string}, |
496 | {'V', "verbose", NULL, | ||
497 | gettext_noop ("be verbose (print progress information)"), | ||
498 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
453 | GNUNET_GETOPT_OPTION_END | 499 | GNUNET_GETOPT_OPTION_END |
454 | }; | 500 | }; |
455 | 501 | ||
diff --git a/src/fs/gnunet-search.c b/src/fs/gnunet-search.c index 10a3c82fd..b744d2e1a 100644 --- a/src/fs/gnunet-search.c +++ b/src/fs/gnunet-search.c | |||
@@ -26,7 +26,7 @@ | |||
26 | * @author Igor Wronsky | 26 | * @author Igor Wronsky |
27 | * | 27 | * |
28 | * TODO: | 28 | * TODO: |
29 | * - all | 29 | * - add many options (timeout, namespace search, etc.) |
30 | */ | 30 | */ |
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include "gnunet_fs_service.h" | 32 | #include "gnunet_fs_service.h" |
@@ -37,10 +37,24 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
37 | 37 | ||
38 | static struct GNUNET_FS_Handle *ctx; | 38 | static struct GNUNET_FS_Handle *ctx; |
39 | 39 | ||
40 | static struct GNUNET_TIME_Absolute start_time; | 40 | static struct GNUNET_FS_SearchContext *sc; |
41 | 41 | ||
42 | static unsigned int anonymity = 1; | 42 | static unsigned int anonymity = 1; |
43 | 43 | ||
44 | static int verbose; | ||
45 | |||
46 | static int | ||
47 | item_printer (void *cls, | ||
48 | EXTRACTOR_KeywordType type, | ||
49 | const char *data) | ||
50 | { | ||
51 | printf ("\t%20s: %s\n", | ||
52 | dgettext (LIBEXTRACTOR_GETTEXT_DOMAIN, | ||
53 | EXTRACTOR_getKeywordTypeAsString (type)), | ||
54 | data); | ||
55 | return GNUNET_OK; | ||
56 | } | ||
57 | |||
44 | 58 | ||
45 | /** | 59 | /** |
46 | * Called by FS client to give information about the progress of an | 60 | * Called by FS client to give information about the progress of an |
@@ -59,6 +73,56 @@ static void * | |||
59 | progress_cb (void *cls, | 73 | progress_cb (void *cls, |
60 | const struct GNUNET_FS_ProgressInfo *info) | 74 | const struct GNUNET_FS_ProgressInfo *info) |
61 | { | 75 | { |
76 | char *uri; | ||
77 | char *dotdot; | ||
78 | char *filename; | ||
79 | |||
80 | switch (info->status) | ||
81 | { | ||
82 | case GNUNET_FS_STATUS_SEARCH_START: | ||
83 | break; | ||
84 | case GNUNET_FS_STATUS_SEARCH_RESULT: | ||
85 | uri = GNUNET_FS_uri_to_string (info->value.search.specifics.result.uri); | ||
86 | printf ("%s:\n", uri); | ||
87 | filename = | ||
88 | GNUNET_CONTAINER_meta_data_get_by_type (info->value.search.specifics.result.meta, | ||
89 | EXTRACTOR_FILENAME); | ||
90 | if (filename != NULL) | ||
91 | { | ||
92 | while (NULL != (dotdot = strstr (filename, ".."))) | ||
93 | dotdot[0] = dotdot[1] = '_'; | ||
94 | printf ("gnunet-download -o \"%s\" %s\n", | ||
95 | filename, | ||
96 | uri); | ||
97 | } | ||
98 | else | ||
99 | printf ("gnunet-download %s\n", uri); | ||
100 | if (verbose) | ||
101 | GNUNET_CONTAINER_meta_data_get_contents (info->value.search.specifics.result.meta, | ||
102 | &item_printer, | ||
103 | NULL); | ||
104 | printf ("\n"); | ||
105 | fflush(stdout); | ||
106 | GNUNET_free_non_null (filename); | ||
107 | GNUNET_free (uri); | ||
108 | break; | ||
109 | case GNUNET_FS_STATUS_SEARCH_UPDATE: | ||
110 | break; | ||
111 | case GNUNET_FS_STATUS_SEARCH_ERROR: | ||
112 | fprintf (stderr, | ||
113 | _("Error searching: %s.\n"), | ||
114 | info->value.search.specifics.error.message); | ||
115 | GNUNET_FS_search_stop (sc); | ||
116 | break; | ||
117 | case GNUNET_FS_STATUS_SEARCH_STOPPED: | ||
118 | GNUNET_FS_stop (ctx); | ||
119 | break; | ||
120 | default: | ||
121 | fprintf (stderr, | ||
122 | _("Unexpected status: %d\n"), | ||
123 | info->status); | ||
124 | break; | ||
125 | } | ||
62 | return NULL; | 126 | return NULL; |
63 | } | 127 | } |
64 | 128 | ||
@@ -79,23 +143,51 @@ run (void *cls, | |||
79 | const char *cfgfile, | 143 | const char *cfgfile, |
80 | const struct GNUNET_CONFIGURATION_Handle *c) | 144 | const struct GNUNET_CONFIGURATION_Handle *c) |
81 | { | 145 | { |
82 | /* FIXME: check arguments */ | 146 | struct GNUNET_FS_Uri *uri; |
147 | unsigned int argc; | ||
148 | |||
149 | argc = 0; | ||
150 | while (NULL != args[argc]) | ||
151 | argc++; | ||
152 | uri = GNUNET_FS_uri_ksk_create_from_args (argc, | ||
153 | (const char **) args); | ||
154 | if (NULL == uri) | ||
155 | { | ||
156 | fprintf (stderr, | ||
157 | _("Could not create keyword URI from arguments.\n")); | ||
158 | ret = 1; | ||
159 | GNUNET_FS_uri_destroy (uri); | ||
160 | return; | ||
161 | } | ||
83 | cfg = c; | 162 | cfg = c; |
84 | ctx = GNUNET_FS_start (sched, | 163 | ctx = GNUNET_FS_start (sched, |
85 | cfg, | 164 | cfg, |
86 | "gnunet-search", | 165 | "gnunet-search", |
87 | &progress_cb, | 166 | &progress_cb, |
88 | NULL); | 167 | NULL, |
168 | GNUNET_FS_FLAGS_NONE, | ||
169 | GNUNET_FS_OPTIONS_END); | ||
89 | if (NULL == ctx) | 170 | if (NULL == ctx) |
90 | { | 171 | { |
91 | fprintf (stderr, | 172 | fprintf (stderr, |
92 | _("Could not initialize `%s' subsystem.\n"), | 173 | _("Could not initialize `%s' subsystem.\n"), |
93 | "FS"); | 174 | "FS"); |
175 | GNUNET_FS_uri_destroy (uri); | ||
176 | GNUNET_FS_stop (ctx); | ||
177 | ret = 1; | ||
178 | return; | ||
179 | } | ||
180 | sc = GNUNET_FS_search_start (ctx, | ||
181 | uri, | ||
182 | anonymity); | ||
183 | GNUNET_FS_uri_destroy (uri); | ||
184 | if (NULL == sc) | ||
185 | { | ||
186 | fprintf (stderr, | ||
187 | _("Could not start searching.\n")); | ||
94 | ret = 1; | 188 | ret = 1; |
95 | return; | 189 | return; |
96 | } | 190 | } |
97 | start_time = GNUNET_TIME_absolute_get (); | ||
98 | // FIXME: start search | ||
99 | } | 191 | } |
100 | 192 | ||
101 | 193 | ||
diff --git a/src/fs/gnunet-unindex.c b/src/fs/gnunet-unindex.c index 2dfef9432..9b335eec0 100644 --- a/src/fs/gnunet-unindex.c +++ b/src/fs/gnunet-unindex.c | |||
@@ -24,24 +24,20 @@ | |||
24 | * @author Krista Bennett | 24 | * @author Krista Bennett |
25 | * @author James Blackwell | 25 | * @author James Blackwell |
26 | * @author Igor Wronsky | 26 | * @author Igor Wronsky |
27 | * | ||
28 | * TODO: | ||
29 | * - progress callback | ||
30 | * - error checking | ||
31 | */ | 27 | */ |
32 | #include "platform.h" | 28 | #include "platform.h" |
33 | #include "gnunet_fs_service.h" | 29 | #include "gnunet_fs_service.h" |
34 | 30 | ||
35 | static int ret; | 31 | static int ret; |
36 | 32 | ||
33 | static int verbose; | ||
34 | |||
37 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | 35 | static const struct GNUNET_CONFIGURATION_Handle *cfg; |
38 | 36 | ||
39 | static struct GNUNET_FS_Handle *ctx; | 37 | static struct GNUNET_FS_Handle *ctx; |
40 | 38 | ||
41 | static struct GNUNET_FS_UnindexContext *uc; | 39 | static struct GNUNET_FS_UnindexContext *uc; |
42 | 40 | ||
43 | static struct GNUNET_TIME_Absolute start_time; | ||
44 | |||
45 | 41 | ||
46 | /** | 42 | /** |
47 | * Called by FS client to give information about the progress of an | 43 | * Called by FS client to give information about the progress of an |
@@ -60,6 +56,38 @@ static void * | |||
60 | progress_cb (void *cls, | 56 | progress_cb (void *cls, |
61 | const struct GNUNET_FS_ProgressInfo *info) | 57 | const struct GNUNET_FS_ProgressInfo *info) |
62 | { | 58 | { |
59 | switch (info->status) | ||
60 | { | ||
61 | case GNUNET_FS_STATUS_UNINDEX_START: | ||
62 | break; | ||
63 | case GNUNET_FS_STATUS_UNINDEX_PROGRESS: | ||
64 | if (verbose) | ||
65 | fprintf (stdout, | ||
66 | _("Unindexing at %llu/%llu (%s remaining)\n"), | ||
67 | (unsigned long long) info->value.unindex.completed, | ||
68 | (unsigned long long) info->value.unindex.size, | ||
69 | GNUNET_STRINGS_relative_time_to_string(info->value.unindex.eta)); | ||
70 | break; | ||
71 | case GNUNET_FS_STATUS_UNINDEX_ERROR: | ||
72 | fprintf (stderr, | ||
73 | _("Error unindexing: %s.\n"), | ||
74 | info->value.unindex.specifics.error.message); | ||
75 | GNUNET_FS_unindex_stop (uc); | ||
76 | break; | ||
77 | case GNUNET_FS_STATUS_UNINDEX_COMPLETED: | ||
78 | fprintf (stdout, | ||
79 | _("Unindexing done.\n")); | ||
80 | GNUNET_FS_unindex_stop (uc); | ||
81 | break; | ||
82 | case GNUNET_FS_STATUS_UNINDEX_STOPPED: | ||
83 | GNUNET_FS_stop (ctx); | ||
84 | break; | ||
85 | default: | ||
86 | fprintf (stderr, | ||
87 | _("Unexpected status: %d\n"), | ||
88 | info->status); | ||
89 | break; | ||
90 | } | ||
63 | return NULL; | 91 | return NULL; |
64 | } | 92 | } |
65 | 93 | ||
@@ -93,7 +121,9 @@ run (void *cls, | |||
93 | cfg, | 121 | cfg, |
94 | "gnunet-unindex", | 122 | "gnunet-unindex", |
95 | &progress_cb, | 123 | &progress_cb, |
96 | NULL); | 124 | NULL, |
125 | GNUNET_FS_FLAGS_NONE, | ||
126 | GNUNET_FS_OPTIONS_END); | ||
97 | if (NULL == ctx) | 127 | if (NULL == ctx) |
98 | { | 128 | { |
99 | fprintf (stderr, | 129 | fprintf (stderr, |
@@ -102,9 +132,14 @@ run (void *cls, | |||
102 | ret = 1; | 132 | ret = 1; |
103 | return; | 133 | return; |
104 | } | 134 | } |
105 | start_time = GNUNET_TIME_absolute_get (); | ||
106 | uc = GNUNET_FS_unindex (ctx, | 135 | uc = GNUNET_FS_unindex (ctx, |
107 | args[0]); | 136 | args[0]); |
137 | if (NULL == uc) | ||
138 | { | ||
139 | fprintf (stderr, | ||
140 | _("Could not start unindex operation.\n")); | ||
141 | GNUNET_FS_stop (ctx); | ||
142 | } | ||
108 | } | 143 | } |
109 | 144 | ||
110 | 145 | ||
@@ -112,6 +147,9 @@ run (void *cls, | |||
112 | * gnunet-unindex command line options | 147 | * gnunet-unindex command line options |
113 | */ | 148 | */ |
114 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 149 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
150 | {'V', "verbose", NULL, | ||
151 | gettext_noop ("be verbose (print progress information)"), | ||
152 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
115 | GNUNET_GETOPT_OPTION_END | 153 | GNUNET_GETOPT_OPTION_END |
116 | }; | 154 | }; |
117 | 155 | ||
diff --git a/src/include/gnunet_fs_service.h b/src/include/gnunet_fs_service.h index ee10a0156..114128823 100644 --- a/src/include/gnunet_fs_service.h +++ b/src/include/gnunet_fs_service.h | |||
@@ -360,7 +360,7 @@ GNUNET_FS_uri_test_chk (const struct GNUNET_FS_Uri *uri); | |||
360 | * What is the size of the file that this URI | 360 | * What is the size of the file that this URI |
361 | * refers to? | 361 | * refers to? |
362 | * | 362 | * |
363 | * @param uri the CHK URI to inspect | 363 | * @param uri the CHK (or LOC) URI to inspect |
364 | * @return size of the file as specified in the CHK URI | 364 | * @return size of the file as specified in the CHK URI |
365 | */ | 365 | */ |
366 | uint64_t | 366 | uint64_t |
@@ -718,6 +718,11 @@ struct GNUNET_FS_ProgressInfo | |||
718 | * (if this is a file in a directory or a subdirectory). | 718 | * (if this is a file in a directory or a subdirectory). |
719 | */ | 719 | */ |
720 | void *pctx; | 720 | void *pctx; |
721 | |||
722 | /** | ||
723 | * Name of the file being published; can be NULL. | ||
724 | */ | ||
725 | const char *filename; | ||
721 | 726 | ||
722 | /** | 727 | /** |
723 | * How large is the file overall? For directories, | 728 | * How large is the file overall? For directories, |
@@ -862,6 +867,11 @@ struct GNUNET_FS_ProgressInfo | |||
862 | * URI used for this download. | 867 | * URI used for this download. |
863 | */ | 868 | */ |
864 | const struct GNUNET_FS_Uri *uri; | 869 | const struct GNUNET_FS_Uri *uri; |
870 | |||
871 | /** | ||
872 | * Name of the file that we are downloading. | ||
873 | */ | ||
874 | const char *filename; | ||
865 | 875 | ||
866 | /** | 876 | /** |
867 | * How large is the download overall? This | 877 | * How large is the download overall? This |
@@ -1394,6 +1404,46 @@ typedef void* (*GNUNET_FS_ProgressCallback) | |||
1394 | 1404 | ||
1395 | 1405 | ||
1396 | /** | 1406 | /** |
1407 | * General (global) option flags for file-sharing. | ||
1408 | */ | ||
1409 | enum GNUNET_FS_Flags | ||
1410 | { | ||
1411 | /** | ||
1412 | * No special flags set. | ||
1413 | */ | ||
1414 | GNUNET_FS_FLAGS_NONE = 0, | ||
1415 | |||
1416 | /** | ||
1417 | * Is persistence of operations desired? | ||
1418 | * (will create SUSPEND/RESUME events). | ||
1419 | */ | ||
1420 | GNUNET_FS_FLAGS_PERSISTENCE = 1 | ||
1421 | |||
1422 | }; | ||
1423 | |||
1424 | /** | ||
1425 | * Options specified in the VARARGs | ||
1426 | * portion of GNUNET_FS_start. | ||
1427 | */ | ||
1428 | enum GNUNET_FS_OPTIONS | ||
1429 | { | ||
1430 | |||
1431 | /** | ||
1432 | * Last option in the VARARG list. | ||
1433 | */ | ||
1434 | GNUNET_FS_OPTIONS_END = 0, | ||
1435 | |||
1436 | /** | ||
1437 | * Select the desired amount of parallelism (this option should be | ||
1438 | * followed by an "unsigned int" giving the desired maximum number | ||
1439 | * of parallel downloads). | ||
1440 | */ | ||
1441 | GNUNET_FS_OPTIONS_DOWNLOAD_PARALLELISM = 1 | ||
1442 | |||
1443 | }; | ||
1444 | |||
1445 | |||
1446 | /** | ||
1397 | * Handle to the file-sharing service. | 1447 | * Handle to the file-sharing service. |
1398 | */ | 1448 | */ |
1399 | struct GNUNET_FS_Handle; | 1449 | struct GNUNET_FS_Handle; |
@@ -1407,13 +1457,18 @@ struct GNUNET_FS_Handle; | |||
1407 | * @param client_name unique identifier for this client | 1457 | * @param client_name unique identifier for this client |
1408 | * @param upcb function to call to notify about FS actions | 1458 | * @param upcb function to call to notify about FS actions |
1409 | * @param upcb_cls closure for upcb | 1459 | * @param upcb_cls closure for upcb |
1460 | * @param flags specific attributes for fs-operations | ||
1461 | * @param ... list of optional options, terminated with GNUNET_FS_OPTIONS_END | ||
1462 | * @return NULL on error | ||
1410 | */ | 1463 | */ |
1411 | struct GNUNET_FS_Handle * | 1464 | struct GNUNET_FS_Handle * |
1412 | GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, | 1465 | GNUNET_FS_start (struct GNUNET_SCHEDULER_Handle *sched, |
1413 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1466 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1414 | const char *client_name, | 1467 | const char *client_name, |
1415 | GNUNET_FS_ProgressCallback upcb, | 1468 | GNUNET_FS_ProgressCallback upcb, |
1416 | void *upcb_cls); | 1469 | void *upcb_cls, |
1470 | enum GNUNET_FS_Flags flags, | ||
1471 | ...); | ||
1417 | 1472 | ||
1418 | 1473 | ||
1419 | /** | 1474 | /** |