diff options
Diffstat (limited to 'src/fs/gnunet-pseudonym.c')
-rw-r--r-- | src/fs/gnunet-pseudonym.c | 248 |
1 files changed, 244 insertions, 4 deletions
diff --git a/src/fs/gnunet-pseudonym.c b/src/fs/gnunet-pseudonym.c index e443d1e32..2d35e8e8c 100644 --- a/src/fs/gnunet-pseudonym.c +++ b/src/fs/gnunet-pseudonym.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2001, 2002, 2004, 2005, 2006, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -25,8 +25,152 @@ | |||
25 | #include "platform.h" | 25 | #include "platform.h" |
26 | #include "gnunet_fs_service.h" | 26 | #include "gnunet_fs_service.h" |
27 | 27 | ||
28 | /** | ||
29 | * -a optiton. | ||
30 | */ | ||
31 | static unsigned int anonymity; | ||
32 | |||
33 | /** | ||
34 | * -A option. | ||
35 | */ | ||
36 | static int start_automate; | ||
37 | |||
38 | /** | ||
39 | * -e option | ||
40 | */ | ||
41 | static int stop_automate; | ||
42 | |||
43 | /** | ||
44 | * -C option | ||
45 | */ | ||
46 | static char *create_ns; | ||
47 | |||
48 | /** | ||
49 | * -D option | ||
50 | */ | ||
51 | static char *delete_ns; | ||
52 | |||
53 | /** | ||
54 | * -k option | ||
55 | */ | ||
56 | static struct GNUNET_FS_Uri *ksk_uri; | ||
57 | |||
58 | /** | ||
59 | * -l option. | ||
60 | */ | ||
61 | static int print_local_only; | ||
62 | |||
63 | /** | ||
64 | * -m option. | ||
65 | */ | ||
66 | static struct GNUNET_CONTAINER_MetaData *adv_metadata; | ||
67 | |||
68 | /** | ||
69 | * -n option. | ||
70 | */ | ||
71 | static int no_advertising; | ||
72 | |||
73 | /** | ||
74 | * -p option. | ||
75 | */ | ||
76 | static unsigned int priority = 365; | ||
77 | |||
78 | /** | ||
79 | * -q option given. | ||
80 | */ | ||
81 | static int no_remote_printing; | ||
82 | |||
83 | /** | ||
84 | * -r option. | ||
85 | */ | ||
86 | static char *root_identifier; | ||
87 | |||
88 | /** | ||
89 | * -s option. | ||
90 | */ | ||
91 | static char *rating_change; | ||
92 | |||
93 | /** | ||
94 | * Handle to fs service. | ||
95 | */ | ||
96 | static struct GNUNET_FS_Handle *h; | ||
97 | |||
98 | /** | ||
99 | * Namespace we are looking at. | ||
100 | */ | ||
101 | static struct GNUNET_FS_Namespace *ns; | ||
102 | |||
103 | |||
28 | static int ret; | 104 | static int ret; |
29 | 105 | ||
106 | static void* | ||
107 | progress_cb (void *cls, | ||
108 | const struct GNUNET_FS_ProgressInfo *info) | ||
109 | { | ||
110 | return NULL; | ||
111 | } | ||
112 | |||
113 | |||
114 | static void | ||
115 | ns_printer (void *cls, | ||
116 | const char *name, | ||
117 | const GNUNET_HashCode *id) | ||
118 | { | ||
119 | struct GNUNET_CRYPTO_HashAsciiEncoded enc; | ||
120 | |||
121 | GNUNET_CRYPTO_hash_to_enc (id, &enc); | ||
122 | fprintf (stdout, | ||
123 | "%s (%s)\n", | ||
124 | name, | ||
125 | (const char*) &enc); | ||
126 | } | ||
127 | |||
128 | |||
129 | static void | ||
130 | post_advertising (void *cls, | ||
131 | const struct GNUNET_FS_Uri *uri, | ||
132 | const char *emsg) | ||
133 | { | ||
134 | if (emsg != NULL) | ||
135 | { | ||
136 | fprintf (stderr, "%s", emsg); | ||
137 | ret = 1; | ||
138 | } | ||
139 | if (ns != NULL) | ||
140 | { | ||
141 | if (GNUNET_OK != | ||
142 | GNUNET_FS_namespace_delete (ns, | ||
143 | GNUNET_NO)) | ||
144 | ret = 1; | ||
145 | } | ||
146 | if (0 != stop_automate) | ||
147 | { | ||
148 | GNUNET_break (0); // FIXME: not implemented | ||
149 | } | ||
150 | if (0 != start_automate) | ||
151 | { | ||
152 | GNUNET_break (0); // FIXME: not implemented | ||
153 | } | ||
154 | if (NULL != rating_change) | ||
155 | { | ||
156 | GNUNET_break (0); // FIXME: not implemented | ||
157 | } | ||
158 | if (0 != print_local_only) | ||
159 | { | ||
160 | GNUNET_FS_namespace_list (h, | ||
161 | &ns_printer, | ||
162 | NULL); | ||
163 | } | ||
164 | else if (0 == no_remote_printing) | ||
165 | { | ||
166 | GNUNET_break (0); // FIXME: not implemented | ||
167 | } | ||
168 | /* FIXME: is this OK here, or do we need | ||
169 | for completion of previous requests? */ | ||
170 | GNUNET_FS_stop (h); | ||
171 | } | ||
172 | |||
173 | |||
30 | /** | 174 | /** |
31 | * Main function that will be run by the scheduler. | 175 | * Main function that will be run by the scheduler. |
32 | * | 176 | * |
@@ -43,15 +187,111 @@ run (void *cls, | |||
43 | const char *cfgfile, | 187 | const char *cfgfile, |
44 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 188 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
45 | { | 189 | { |
46 | // FIXME | 190 | struct GNUNET_FS_Uri *ns_uri; |
47 | } | 191 | struct GNUNET_TIME_Absolute expiration; |
48 | 192 | ||
193 | h = GNUNET_FS_start (sched, | ||
194 | cfg, | ||
195 | "gnunet-pseudonym", | ||
196 | &progress_cb, | ||
197 | NULL, | ||
198 | GNUNET_FS_FLAGS_NONE); | ||
199 | if (NULL != delete_ns) | ||
200 | { | ||
201 | ns = GNUNET_FS_namespace_create (h, delete_ns); | ||
202 | if (ns == NULL) | ||
203 | { | ||
204 | ret = 1; | ||
205 | } | ||
206 | else | ||
207 | { | ||
208 | if (GNUNET_OK != | ||
209 | GNUNET_FS_namespace_delete (ns, | ||
210 | GNUNET_YES)) | ||
211 | ret = 1; | ||
212 | ns = NULL; | ||
213 | } | ||
214 | } | ||
215 | if (NULL != create_ns) | ||
216 | { | ||
217 | ns = GNUNET_FS_namespace_create (h, create_ns); | ||
218 | if (ns == NULL) | ||
219 | { | ||
220 | ret = 1; | ||
221 | } | ||
222 | else | ||
223 | { | ||
224 | if (0 == no_advertising) | ||
225 | { | ||
226 | GNUNET_break (0); // FIXME: not implemented | ||
227 | ns_uri = NULL; // FIXME!! | ||
228 | expiration = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_YEARS); | ||
229 | GNUNET_FS_publish_ksk (h, | ||
230 | ksk_uri, | ||
231 | adv_metadata, | ||
232 | ns_uri, | ||
233 | expiration, | ||
234 | anonymity, | ||
235 | priority, | ||
236 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
237 | &post_advertising, | ||
238 | NULL); | ||
239 | return; | ||
240 | } | ||
241 | } | ||
242 | } | ||
243 | post_advertising (NULL, NULL, NULL); | ||
244 | } | ||
49 | 245 | ||
50 | /** | 246 | /** |
51 | * gnunet-pseudonym command line options | 247 | * gnunet-pseudonym command line options |
52 | */ | 248 | */ |
53 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 249 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
54 | // FIXME: options! | 250 | {'a', "anonymity", "LEVEL", |
251 | gettext_noop ("set the desired LEVEL of sender-anonymity"), | ||
252 | 1, &GNUNET_GETOPT_set_uint, &anonymity}, | ||
253 | {'A', "automate", NULL, | ||
254 | gettext_noop ("start a collection"), | ||
255 | 0, &GNUNET_GETOPT_set_one, &start_automate}, | ||
256 | {'C', "create", "NAME", | ||
257 | gettext_noop | ||
258 | ("create or advertise namespace NAME"), | ||
259 | 1, &GNUNET_GETOPT_set_string, &create_ns}, | ||
260 | {'D', "delete", "NAME", | ||
261 | gettext_noop | ||
262 | ("delete namespace NAME "), | ||
263 | 1, &GNUNET_GETOPT_set_string, &delete_ns}, | ||
264 | {'e', "end", NULL, | ||
265 | gettext_noop ("end current collection"), | ||
266 | 0, &GNUNET_GETOPT_set_one, &stop_automate}, | ||
267 | {'k', "keyword", "VALUE", | ||
268 | gettext_noop | ||
269 | ("add an additional keyword for the advertisment" | ||
270 | " (this option can be specified multiple times)"), | ||
271 | 1, &GNUNET_FS_getopt_set_keywords, &ksk_uri}, | ||
272 | {'l', "local-only", NULL, | ||
273 | gettext_noop ("print names of local namespaces"), | ||
274 | 0, &GNUNET_GETOPT_set_one, &print_local_only}, | ||
275 | {'m', "meta", "TYPE:VALUE", | ||
276 | gettext_noop ("set the meta-data for the given TYPE to the given VALUE"), | ||
277 | 1, &GNUNET_FS_getopt_set_metadata, &adv_metadata}, | ||
278 | {'n', "no-advertisement", NULL, | ||
279 | gettext_noop ("do not create an advertisement"), | ||
280 | 0, &GNUNET_GETOPT_set_one, &no_advertising}, | ||
281 | {'p', "priority", "PRIORITY", | ||
282 | gettext_noop ("use the given PRIORITY for the advertisments"), | ||
283 | 1, &GNUNET_GETOPT_set_uint, &priority}, | ||
284 | {'q', "quiet", NULL, | ||
285 | gettext_noop ("do not print names of remote namespaces"), | ||
286 | 0, &GNUNET_GETOPT_set_one, &no_remote_printing}, | ||
287 | {'r', "root", "ID", | ||
288 | gettext_noop | ||
289 | ("specify ID of the root of the namespace"), | ||
290 | 1, &GNUNET_GETOPT_set_string, &root_identifier}, | ||
291 | {'s', "set-rating", "ID:VALUE", | ||
292 | gettext_noop | ||
293 | ("change rating of namespace ID by VALUE"), | ||
294 | 1, &GNUNET_GETOPT_set_string, &rating_change}, | ||
55 | GNUNET_GETOPT_OPTION_END | 295 | GNUNET_GETOPT_OPTION_END |
56 | }; | 296 | }; |
57 | 297 | ||