diff options
Diffstat (limited to 'src/gns/gnunet-gns-gtk.c')
-rw-r--r-- | src/gns/gnunet-gns-gtk.c | 80 |
1 files changed, 63 insertions, 17 deletions
diff --git a/src/gns/gnunet-gns-gtk.c b/src/gns/gnunet-gns-gtk.c index f2d6f219..59edb42b 100644 --- a/src/gns/gnunet-gns-gtk.c +++ b/src/gns/gnunet-gns-gtk.c | |||
@@ -46,10 +46,7 @@ static GNUNET_HashCode zone; | |||
46 | */ | 46 | */ |
47 | static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey; | 47 | static struct GNUNET_CRYPTO_RsaPrivateKey *zone_pkey; |
48 | 48 | ||
49 | /** | 49 | |
50 | * Handle to the namestore. | ||
51 | */ | ||
52 | static struct GNUNET_NAMESTORE_Handle *ns; | ||
53 | 50 | ||
54 | /** | 51 | /** |
55 | * Name of our zone as a string. | 52 | * Name of our zone as a string. |
@@ -63,6 +60,19 @@ static char *zonekey_directory; | |||
63 | 60 | ||
64 | static GtkWidget *main_window; | 61 | static GtkWidget *main_window; |
65 | 62 | ||
63 | struct GNUNET_GNS_Context | ||
64 | { | ||
65 | /** | ||
66 | * Handle to the namestore. | ||
67 | */ | ||
68 | struct GNUNET_NAMESTORE_Handle *ns; | ||
69 | |||
70 | GtkBuilder builder; | ||
71 | |||
72 | |||
73 | }; | ||
74 | |||
75 | |||
66 | /** | 76 | /** |
67 | * Get cfg. | 77 | * Get cfg. |
68 | */ | 78 | */ |
@@ -235,10 +245,12 @@ GNUNET_GNS_GTK_public_key_copy_button_clicked_cb (GtkButton *button, | |||
235 | static void | 245 | static void |
236 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 246 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
237 | { | 247 | { |
238 | if (NULL != ns) | 248 | struct GNUNET_GNS_Context *gns = cls; |
249 | GNUNET_assert (gns != NULL); | ||
250 | if (NULL != gns->ns) | ||
239 | { | 251 | { |
240 | GNUNET_NAMESTORE_disconnect (ns, GNUNET_NO); | 252 | GNUNET_NAMESTORE_disconnect (gns->ns, GNUNET_NO); |
241 | ns = NULL; | 253 | gns->ns = NULL; |
242 | } | 254 | } |
243 | if (NULL != zone_pkey) | 255 | if (NULL != zone_pkey) |
244 | { | 256 | { |
@@ -250,6 +262,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
250 | GNUNET_free (zonekey_directory); | 262 | GNUNET_free (zonekey_directory); |
251 | zonekey_directory = NULL; | 263 | zonekey_directory = NULL; |
252 | } | 264 | } |
265 | GNUNET_free (gns); | ||
253 | } | 266 | } |
254 | 267 | ||
255 | 268 | ||
@@ -265,7 +278,7 @@ GNUNET_GNS_GTK_quit_imagemenuitem_activate_cb (GtkMenuItem *menuitem, | |||
265 | { | 278 | { |
266 | GNUNET_GTK_tray_icon_destroy (); | 279 | GNUNET_GTK_tray_icon_destroy (); |
267 | GNUNET_GTK_main_loop_quit (ml); | 280 | GNUNET_GTK_main_loop_quit (ml); |
268 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 281 | GNUNET_SCHEDULER_add_now (&shutdown_task, user_data); |
269 | } | 282 | } |
270 | 283 | ||
271 | 284 | ||
@@ -283,10 +296,35 @@ GNUNET_GNS_GTK_main_window_delete_event_cb (GtkWidget *widget, | |||
283 | { | 296 | { |
284 | GNUNET_GTK_tray_icon_destroy (); | 297 | GNUNET_GTK_tray_icon_destroy (); |
285 | GNUNET_GTK_main_loop_quit (ml); | 298 | GNUNET_GTK_main_loop_quit (ml); |
286 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 299 | GNUNET_SCHEDULER_add_now (&shutdown_task, user_data); |
300 | } | ||
301 | |||
302 | struct ZoneIteration_Context | ||
303 | { | ||
304 | GNUNET_HashCode zone; | ||
305 | struct GNUNET_NAMESTORE_ZoneIterator * it; | ||
306 | }; | ||
307 | |||
308 | void zone_iteration_proc (void *cls, | ||
309 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
310 | struct GNUNET_TIME_Absolute expire, | ||
311 | const char *name, | ||
312 | unsigned int rd_len, | ||
313 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
314 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
315 | { | ||
316 | struct ZoneIteration_Context * zc_ctx = cls; | ||
317 | GNUNET_assert (zc_ctx != NULL); | ||
318 | if ((NULL == zone_key) && (NULL == name)) | ||
319 | { | ||
320 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Zone iteration done\n"); | ||
321 | return; | ||
322 | } | ||
323 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Zone iteration dummy\n"); | ||
287 | } | 324 | } |
288 | 325 | ||
289 | 326 | ||
327 | |||
290 | /** | 328 | /** |
291 | * Actual main function run right after GNUnet's scheduler | 329 | * Actual main function run right after GNUnet's scheduler |
292 | * is initialized. Initializes up GTK and Glade. | 330 | * is initialized. Initializes up GTK and Glade. |
@@ -298,7 +336,7 @@ static void | |||
298 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 336 | run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
299 | { | 337 | { |
300 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; | 338 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pub; |
301 | 339 | struct GNUNET_GNS_Context *gns = GNUNET_malloc (sizeof (struct GNUNET_GNS_Context)); | |
302 | char *keyfile; | 340 | char *keyfile; |
303 | char *label; | 341 | char *label; |
304 | 342 | ||
@@ -333,22 +371,30 @@ run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
333 | _("Failed to read or create private zone key\n")); | 371 | _("Failed to read or create private zone key\n")); |
334 | return; | 372 | return; |
335 | } | 373 | } |
336 | GNUNET_CRYPTO_rsa_key_get_public (zone_pkey, | 374 | GNUNET_CRYPTO_rsa_key_get_public (zone_pkey, &pub); |
337 | &pub); | ||
338 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone); | 375 | GNUNET_CRYPTO_hash (&pub, sizeof (pub), &zone); |
339 | 376 | ||
340 | ns = GNUNET_NAMESTORE_connect (get_configuration ()); | 377 | gns->ns = GNUNET_NAMESTORE_connect (get_configuration ()); |
341 | if (NULL == ns) | 378 | if (NULL == gns->ns) |
342 | { | 379 | { |
343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 380 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
344 | _("Failed to connect to namestore\n")); | 381 | _("Failed to connect to namestore\n")); |
345 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 382 | GNUNET_SCHEDULER_add_now (&shutdown_task, gns); |
346 | return; | 383 | return; |
347 | } | 384 | } |
348 | if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, NULL)) | 385 | |
386 | struct ZoneIteration_Context * zc_ctx = GNUNET_malloc (sizeof (struct ZoneIteration_Context)); | ||
387 | zc_ctx->zone = zone; | ||
388 | GNUNET_NAMESTORE_zone_iteration_start(gns->ns, &zone, | ||
389 | GNUNET_NAMESTORE_RF_NONE, | ||
390 | GNUNET_NAMESTORE_RF_NONE, | ||
391 | &zone_iteration_proc, | ||
392 | zc_ctx); | ||
393 | |||
394 | if (GNUNET_OK != GNUNET_GTK_main_loop_build_window (ml, gns)) | ||
349 | { | 395 | { |
350 | GNUNET_break (0); | 396 | GNUNET_break (0); |
351 | GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | 397 | GNUNET_SCHEDULER_add_now (&shutdown_task, gns); |
352 | return; | 398 | return; |
353 | } | 399 | } |
354 | zone_as_string = GNUNET_strdup (GNUNET_h2s_full (&zone)); | 400 | zone_as_string = GNUNET_strdup (GNUNET_h2s_full (&zone)); |