diff options
Diffstat (limited to 'src/gnunet_chat_handle_intern.c')
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 115 |
1 files changed, 112 insertions, 3 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index d3f4694..0662850 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -64,6 +64,12 @@ on_handle_arm_connection(void *cls, | |||
64 | GNUNET_OS_INHERIT_STD_NONE, | 64 | GNUNET_OS_INHERIT_STD_NONE, |
65 | NULL, NULL | 65 | NULL, NULL |
66 | ); | 66 | ); |
67 | |||
68 | GNUNET_ARM_request_service_start( | ||
69 | chat->arm, "namestore", | ||
70 | GNUNET_OS_INHERIT_STD_NONE, | ||
71 | NULL, NULL | ||
72 | ); | ||
67 | } else { | 73 | } else { |
68 | GNUNET_ARM_request_service_start( | 74 | GNUNET_ARM_request_service_start( |
69 | chat->arm, "arm", | 75 | chat->arm, "arm", |
@@ -359,6 +365,93 @@ scan_handle_room_members (void* cls, | |||
359 | } | 365 | } |
360 | 366 | ||
361 | void | 367 | void |
368 | on_monitor_namestore_record(void *cls, | ||
369 | GNUNET_UNUSED const | ||
370 | struct GNUNET_IDENTITY_PrivateKey *zone, | ||
371 | const char *label, | ||
372 | unsigned int count, | ||
373 | const struct GNUNET_GNSRECORD_Data *data) | ||
374 | { | ||
375 | struct GNUNET_CHAT_Handle *chat = cls; | ||
376 | |||
377 | if (count <= 0) | ||
378 | goto skip_records; | ||
379 | |||
380 | const struct GNUNET_MESSENGER_RoomEntryRecord *record = NULL; | ||
381 | |||
382 | for (unsigned int i = 0; i < count; i++) | ||
383 | { | ||
384 | if (GNUNET_YES == GNUNET_GNSRECORD_is_expired(data + i)) | ||
385 | continue; | ||
386 | |||
387 | if ((GNUNET_GNSRECORD_TYPE_MESSENGER_ROOM_ENTRY == data[i].record_type) && | ||
388 | (!(GNUNET_GNSRECORD_RF_SUPPLEMENTAL & data[i].flags))) | ||
389 | { | ||
390 | record = data[i].data; | ||
391 | break; | ||
392 | } | ||
393 | } | ||
394 | |||
395 | if (!record) | ||
396 | goto skip_records; | ||
397 | |||
398 | struct GNUNET_CHAT_Context *context = GNUNET_CONTAINER_multihashmap_get( | ||
399 | chat->contexts, | ||
400 | &(record->key) | ||
401 | ); | ||
402 | |||
403 | if (context) | ||
404 | { | ||
405 | context_read_records(context, label, count, data); | ||
406 | |||
407 | printf("PATCH: %s %u %d %s\n", label, count, (int) context->type, context->topic); | ||
408 | |||
409 | goto skip_records; | ||
410 | } | ||
411 | |||
412 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_enter_room( | ||
413 | chat->messenger, | ||
414 | &(record->door), | ||
415 | &(record->key) | ||
416 | ); | ||
417 | |||
418 | if (!room) | ||
419 | goto skip_records; | ||
420 | |||
421 | context = context_create_from_room(chat, room); | ||
422 | context_read_records(context, label, count, data); | ||
423 | |||
424 | printf("READ: %s %u %d %s\n", label, count, (int) context->type, context->topic); | ||
425 | |||
426 | handle_send_room_name(chat, room); | ||
427 | |||
428 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
429 | chat->contexts, &(record->key), context, | ||
430 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
431 | { | ||
432 | context_destroy(context); | ||
433 | goto skip_records; | ||
434 | } | ||
435 | |||
436 | if (GNUNET_CHAT_CONTEXT_TYPE_GROUP != context->type) | ||
437 | goto skip_records; | ||
438 | |||
439 | struct GNUNET_CHAT_Group *group = group_create_from_context(chat, context); | ||
440 | |||
441 | if (context->topic) | ||
442 | group_publish(group); | ||
443 | |||
444 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
445 | chat->groups, &(record->key), group, | ||
446 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
447 | group_destroy(group); | ||
448 | |||
449 | skip_records: | ||
450 | if (chat->monitor) | ||
451 | GNUNET_NAMESTORE_zone_monitor_next(chat->monitor, 1); | ||
452 | } | ||
453 | |||
454 | void | ||
362 | on_handle_identity(void *cls, | 455 | on_handle_identity(void *cls, |
363 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) | 456 | GNUNET_UNUSED struct GNUNET_MESSENGER_Handle *messenger) |
364 | { | 457 | { |
@@ -377,7 +470,8 @@ on_handle_identity(void *cls, | |||
377 | return; | 470 | return; |
378 | 471 | ||
379 | GNUNET_assert(handle->messenger); | 472 | GNUNET_assert(handle->messenger); |
380 | context_scan_configs(handle); | 473 | |
474 | printf("HURRAY!\n"); | ||
381 | 475 | ||
382 | handle_send_internal_message( | 476 | handle_send_internal_message( |
383 | handle, | 477 | handle, |
@@ -385,6 +479,23 @@ on_handle_identity(void *cls, | |||
385 | GNUNET_CHAT_FLAG_LOGIN, | 479 | GNUNET_CHAT_FLAG_LOGIN, |
386 | NULL | 480 | NULL |
387 | ); | 481 | ); |
482 | |||
483 | const struct GNUNET_IDENTITY_PrivateKey *zone = handle_get_key(handle); | ||
484 | |||
485 | if ((!zone) || (handle->monitor)) | ||
486 | return; | ||
487 | |||
488 | handle->monitor = GNUNET_NAMESTORE_zone_monitor_start( | ||
489 | handle->cfg, | ||
490 | zone, | ||
491 | GNUNET_YES, | ||
492 | NULL, | ||
493 | NULL, | ||
494 | on_monitor_namestore_record, | ||
495 | handle, | ||
496 | NULL, | ||
497 | NULL | ||
498 | ); | ||
388 | } | 499 | } |
389 | 500 | ||
390 | void | 501 | void |
@@ -583,7 +694,6 @@ it_destroy_handle_groups (GNUNET_UNUSED void *cls, | |||
583 | GNUNET_assert(value); | 694 | GNUNET_assert(value); |
584 | 695 | ||
585 | struct GNUNET_CHAT_Group *group = value; | 696 | struct GNUNET_CHAT_Group *group = value; |
586 | group_save_config(group); | ||
587 | group_destroy(group); | 697 | group_destroy(group); |
588 | return GNUNET_YES; | 698 | return GNUNET_YES; |
589 | } | 699 | } |
@@ -608,7 +718,6 @@ it_destroy_handle_contexts (GNUNET_UNUSED void *cls, | |||
608 | GNUNET_assert(value); | 718 | GNUNET_assert(value); |
609 | 719 | ||
610 | struct GNUNET_CHAT_Context *context = value; | 720 | struct GNUNET_CHAT_Context *context = value; |
611 | context_save_config(context); | ||
612 | context_destroy(context); | 721 | context_destroy(context); |
613 | return GNUNET_YES; | 722 | return GNUNET_YES; |
614 | } | 723 | } |