diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-07 20:07:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-07 20:07:56 +0000 |
commit | 58046b5a6645944d8f0941fb1d3afc13c4caa3ea (patch) | |
tree | 2e88e12b201f6408275c6b5b2e132b6d839f186c /src/identity/gnunet-identity-gtk_advertise.c | |
parent | 7459ebc4df78f2d5c7b69451434d9c4ec90a16b9 (diff) | |
download | gnunet-gtk-58046b5a6645944d8f0941fb1d3afc13c4caa3ea.tar.gz gnunet-gtk-58046b5a6645944d8f0941fb1d3afc13c4caa3ea.zip |
-first implementation of execute function for ego advertisement
Diffstat (limited to 'src/identity/gnunet-identity-gtk_advertise.c')
-rw-r--r-- | src/identity/gnunet-identity-gtk_advertise.c | 198 |
1 files changed, 195 insertions, 3 deletions
diff --git a/src/identity/gnunet-identity-gtk_advertise.c b/src/identity/gnunet-identity-gtk_advertise.c index 07ab09fd..63bba35e 100644 --- a/src/identity/gnunet-identity-gtk_advertise.c +++ b/src/identity/gnunet-identity-gtk_advertise.c | |||
@@ -24,6 +24,7 @@ | |||
24 | * @author Christian Grothoff | 24 | * @author Christian Grothoff |
25 | */ | 25 | */ |
26 | #include "gnunet-identity-gtk_advertise.h" | 26 | #include "gnunet-identity-gtk_advertise.h" |
27 | #include "gnunet-identity-gtk.h" | ||
27 | #include <gnunet/gnunet_fs_service.h> | 28 | #include <gnunet/gnunet_fs_service.h> |
28 | 29 | ||
29 | 30 | ||
@@ -148,6 +149,120 @@ struct AdvertiseContext | |||
148 | }; | 149 | }; |
149 | 150 | ||
150 | 151 | ||
152 | /** | ||
153 | * Context for the publishing operation. | ||
154 | */ | ||
155 | struct PublishContext | ||
156 | { | ||
157 | |||
158 | /** | ||
159 | * Kept in a DLL. | ||
160 | */ | ||
161 | struct PublishContext *next; | ||
162 | |||
163 | /** | ||
164 | * Kept in a DLL. | ||
165 | */ | ||
166 | struct PublishContext *prev; | ||
167 | |||
168 | /** | ||
169 | * Handle to FS subsystem. | ||
170 | */ | ||
171 | struct GNUNET_FS_Handle *fs; | ||
172 | |||
173 | /** | ||
174 | * Handle to the publish operation. | ||
175 | */ | ||
176 | struct GNUNET_FS_PublishKskContext *pub; | ||
177 | |||
178 | }; | ||
179 | |||
180 | |||
181 | /** | ||
182 | * Kept in a DLL. | ||
183 | */ | ||
184 | static struct PublishContext *pc_head; | ||
185 | |||
186 | /** | ||
187 | * Kept in a DLL. | ||
188 | */ | ||
189 | static struct PublishContext *pc_tail; | ||
190 | |||
191 | |||
192 | /** | ||
193 | * Shutdown advertisement subsystem, this process is terminating. | ||
194 | */ | ||
195 | void | ||
196 | GIG_advertise_shutdown_ () | ||
197 | { | ||
198 | struct PublishContext *pc; | ||
199 | |||
200 | while (NULL != (pc = pc_head)) | ||
201 | { | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
203 | _("Aborting advertising operation due to shutdown.\n")); | ||
204 | GNUNET_CONTAINER_DLL_remove (pc_head, | ||
205 | pc_tail, | ||
206 | pc); | ||
207 | GNUNET_FS_publish_ksk_cancel (pc->pub); | ||
208 | GNUNET_FS_stop (pc->fs); | ||
209 | GNUNET_free (pc); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | |||
214 | /** | ||
215 | * Function called once we published the advertisement. | ||
216 | * | ||
217 | * @param cls closure with the `struct PublishContext` | ||
218 | * @param uri URI under which the block is now available, NULL on error | ||
219 | * @param emsg error message, NULL on success | ||
220 | */ | ||
221 | static void | ||
222 | publish_continuation (void *cls, | ||
223 | const struct GNUNET_FS_Uri *uri, | ||
224 | const char *emsg) | ||
225 | { | ||
226 | struct PublishContext *pc = cls; | ||
227 | |||
228 | pc->pub = NULL; | ||
229 | if (NULL == uri) | ||
230 | { | ||
231 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
232 | _("Failed to advertise ego: %s\n"), | ||
233 | emsg); | ||
234 | /* FIXME: might want to output to GUI... */ | ||
235 | } | ||
236 | GNUNET_FS_stop (pc->fs); | ||
237 | GNUNET_CONTAINER_DLL_remove (pc_head, | ||
238 | pc_tail, | ||
239 | pc); | ||
240 | GNUNET_free (pc); | ||
241 | } | ||
242 | |||
243 | |||
244 | /** | ||
245 | * Notification of FS to a client about the progress of an | ||
246 | * operation. Callbacks of this type will be used for uploads, | ||
247 | * downloads and searches. Some of the arguments depend a bit | ||
248 | * in their meaning on the context in which the callback is used. | ||
249 | * | ||
250 | * @param cls closure | ||
251 | * @param info details about the event, specifying the event type | ||
252 | * and various bits about the event | ||
253 | * @return client-context (for the next progress call | ||
254 | * for this operation; should be set to NULL for | ||
255 | * SUSPEND and STOPPED events). The value returned | ||
256 | * will be passed to future callbacks in the respective | ||
257 | * field in the `struct GNUNET_FS_ProgressInfo`. | ||
258 | */ | ||
259 | static void * | ||
260 | progress_cb (void *cls, | ||
261 | const struct GNUNET_FS_ProgressInfo *info) | ||
262 | { | ||
263 | return NULL; | ||
264 | } | ||
265 | |||
151 | 266 | ||
152 | /** | 267 | /** |
153 | * The user terminated the dialog. Perform the appropriate action. | 268 | * The user terminated the dialog. Perform the appropriate action. |
@@ -162,12 +277,89 @@ GNUNET_GTK_identity_advertise_dialog_response_cb (GtkDialog *dialog, | |||
162 | gpointer user_data) | 277 | gpointer user_data) |
163 | { | 278 | { |
164 | struct AdvertiseContext *ac = user_data; | 279 | struct AdvertiseContext *ac = user_data; |
165 | 280 | struct GNUNET_FS_Uri *ksk_uri; | |
166 | if (GTK_RESPONSE_OK == response_id) | 281 | struct GNUNET_FS_Uri *uri; |
282 | gchar *keyword; | ||
283 | struct GNUNET_CONTAINER_MetaData *meta; | ||
284 | guint ntype; | ||
285 | gchar *value; | ||
286 | GtkTreeIter iter; | ||
287 | struct GNUNET_FS_BlockOptions bo; | ||
288 | struct GNUNET_CRYPTO_EccPublicKey pk; | ||
289 | struct PublishContext *pc; | ||
290 | |||
291 | if (GTK_RESPONSE_OK != response_id) | ||
292 | goto cleanup; | ||
293 | ksk_uri = NULL; | ||
294 | if (! gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->keywords), &iter)) | ||
295 | { | ||
296 | GNUNET_break (0); | ||
297 | goto cleanup; | ||
298 | } | ||
299 | do | ||
300 | { | ||
301 | gtk_tree_model_get (GTK_TREE_MODEL (ac->keywords), &iter, | ||
302 | KEYWORDS_MC_KEYWORD, &keyword, | ||
303 | -1); | ||
304 | if (NULL == ksk_uri) | ||
305 | ksk_uri = GNUNET_FS_uri_ksk_create_from_args (1, (const char **) &keyword); | ||
306 | else | ||
307 | GNUNET_FS_uri_ksk_add_keyword (ksk_uri, keyword, GNUNET_NO); | ||
308 | g_free (keyword); | ||
309 | } | ||
310 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->keywords), &iter)); | ||
311 | |||
312 | meta = GNUNET_CONTAINER_meta_data_create (); | ||
313 | if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (ac->metadata), | ||
314 | &iter)) | ||
315 | { | ||
316 | do | ||
167 | { | 317 | { |
168 | GNUNET_break (0); // FIXME: not implemented | 318 | gtk_tree_model_get (GTK_TREE_MODEL (ac->metadata), &iter, |
319 | METADATA_MC_TYPE_AS_ENUM, &ntype, | ||
320 | METADATA_MC_VALUE, &value, | ||
321 | -1); | ||
322 | if (ntype > 0) | ||
323 | { | ||
324 | GNUNET_CONTAINER_meta_data_insert (meta, "<user>", | ||
325 | ntype, | ||
326 | EXTRACTOR_METAFORMAT_UTF8, | ||
327 | "text/plain", value, | ||
328 | strlen (value) + 1); | ||
329 | } | ||
330 | g_free (value); | ||
169 | } | 331 | } |
332 | while (gtk_tree_model_iter_next (GTK_TREE_MODEL (ac->metadata), &iter)); | ||
333 | } | ||
170 | 334 | ||
335 | bo.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS; /* FIXME: allow user to specify */ | ||
336 | bo.anonymity_level = 1; /* FIXME: allow user to specify */ | ||
337 | bo.content_priority = 1000; /* FIXME: allow user to specify */ | ||
338 | bo.replication_level = 5; | ||
339 | GNUNET_CRYPTO_ecc_key_get_public (&ac->priv, | ||
340 | &pk); | ||
341 | uri = GNUNET_FS_uri_sks_create (&pk, | ||
342 | "root"); /* FIXME: allow user to specify! */ | ||
343 | |||
344 | pc = GNUNET_new (struct PublishContext); | ||
345 | pc->fs = GNUNET_FS_start (GIG_get_configuration (), | ||
346 | "gnunet-identity-gtk", | ||
347 | &progress_cb, pc, | ||
348 | GNUNET_FS_FLAGS_NONE, | ||
349 | GNUNET_FS_OPTIONS_END); | ||
350 | pc->pub = GNUNET_FS_publish_ksk (pc->fs, | ||
351 | ksk_uri, | ||
352 | meta, | ||
353 | uri, | ||
354 | &bo, | ||
355 | GNUNET_FS_PUBLISH_OPTION_NONE, | ||
356 | &publish_continuation, pc); | ||
357 | GNUNET_CONTAINER_DLL_insert (pc_head, | ||
358 | pc_tail, | ||
359 | pc); | ||
360 | GNUNET_FS_uri_destroy (uri); | ||
361 | GNUNET_CONTAINER_meta_data_destroy (meta); | ||
362 | cleanup: | ||
171 | gtk_widget_destroy (ac->dialog); | 363 | gtk_widget_destroy (ac->dialog); |
172 | g_object_unref (G_OBJECT (ac->builder)); | 364 | g_object_unref (G_OBJECT (ac->builder)); |
173 | GNUNET_free (ac); | 365 | GNUNET_free (ac); |