libgnunetchat

library for GNUnet Messenger
Log | Files | Refs | README | LICENSE

commit f20fb24047d2416023425e657cb141acc08065c4
parent 2ee30f372acad534246beaf579b7bbfefab0b246
Author: Jacki <jacki@thejackimonster.de>
Date:   Thu,  4 Jan 2024 21:01:58 +0100

Revoke tickets on account deletion/update

Signed-off-by: Jacki <jacki@thejackimonster.de>

Diffstat:
Mmeson.build | 3++-
Msrc/gnunet_chat_handle.c | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/gnunet_chat_handle.h | 24++++++++++++++++++++++++
Msrc/gnunet_chat_handle_intern.c | 112++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
4 files changed, 209 insertions(+), 11 deletions(-)

diff --git a/meson.build b/meson.build @@ -1,6 +1,6 @@ # # This file is part of GNUnet. -# Copyright (C) 2023 GNUnet e.V. +# Copyright (C) 2023--2024 GNUnet e.V. # # GNUnet is free software: you can redistribute it and/or modify it # under the terms of the GNU Affero General Public License as published @@ -37,6 +37,7 @@ gnunetchat_deps = [ dependency('gnunetidentity'), dependency('gnunetmessenger'), dependency('gnunetnamestore'), + dependency('gnunetreclaim'), dependency('gnunetregex'), dependency('gnunetutil'), ] diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c @@ -25,6 +25,7 @@ #include "gnunet_chat_handle.h" #include "gnunet_chat_handle_intern.c" +#include <gnunet/gnunet_reclaim_service.h> static const unsigned int initial_map_size_of_handle = 8; static const unsigned int minimum_amount_of_other_members_in_group = 2; @@ -95,8 +96,11 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->lobbies_head = NULL; handle->lobbies_tail = NULL; - handle->lobbies_head = NULL; - handle->lobbies_tail = NULL; + handle->lookups_head = NULL; + handle->lookups_tail = NULL; + + handle->tickets_head = NULL; + handle->tickets_tail = NULL; handle->files = NULL; handle->contexts = NULL; @@ -122,6 +126,10 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, handle->cfg ); + handle->reclaim = GNUNET_RECLAIM_connect( + handle->cfg + ); + handle->fs = NULL; handle->gns = NULL; handle->messenger = NULL; @@ -171,6 +179,29 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) if (handle->namestore) GNUNET_NAMESTORE_disconnect(handle->namestore); + struct GNUNET_CHAT_TicketProcess *tickets; + while (handle->tickets_head) + { + tickets = handle->tickets_head; + + if (tickets->iter) + GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); + + if (tickets->op) + GNUNET_RECLAIM_cancel(tickets->op); + + GNUNET_CONTAINER_DLL_remove( + handle->tickets_head, + handle->tickets_tail, + tickets + ); + + GNUNET_free(tickets); + } + + if (handle->reclaim) + GNUNET_RECLAIM_disconnect(handle->reclaim); + struct GNUNET_CHAT_InternalAccounts *accounts; while (handle->accounts_head) @@ -298,10 +329,6 @@ handle_connect (struct GNUNET_CHAT_Handle *handle, const char *name = account->name; - const struct GNUNET_CRYPTO_PrivateKey *key = NULL; - if (account->ego) - key = GNUNET_IDENTITY_ego_get_private_key(account->ego); - char* fs_client_name = NULL; GNUNET_asprintf ( &fs_client_name, @@ -321,6 +348,10 @@ handle_connect (struct GNUNET_CHAT_Handle *handle, handle->gns = GNUNET_GNS_connect(handle->cfg); + const struct GNUNET_CRYPTO_PrivateKey *key = NULL; + if (account->ego) + key = GNUNET_IDENTITY_ego_get_private_key(account->ego); + handle->messenger = GNUNET_MESSENGER_connect( handle->cfg, name, key, on_handle_message, @@ -962,3 +993,41 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, return context; } + +void +handle_update_tickets (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CRYPTO_PrivateKey *identity) +{ + GNUNET_assert((handle) && (identity)); + + struct GNUNET_CHAT_TicketProcess *tickets = GNUNET_new( + struct GNUNET_CHAT_TicketProcess + ); + + if (!tickets) + return; + + memset(tickets, 0, sizeof(struct GNUNET_CHAT_TicketProcess)); + GNUNET_memcpy( + &(tickets->identity), + identity, + sizeof(tickets->identity) + ); + + tickets->iter = GNUNET_RECLAIM_ticket_iteration_start( + handle->reclaim, + identity, + cb_task_error_ticket_update, + tickets, + cb_iterate_ticket_update, + tickets, + cb_task_finish_ticket_update, + tickets + ); + + GNUNET_CONTAINER_DLL_insert_tail( + handle->tickets_head, + handle->tickets_tail, + tickets + ); +} diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h @@ -31,6 +31,7 @@ #include <gnunet/gnunet_identity_service.h> #include <gnunet/gnunet_messenger_service.h> #include <gnunet/gnunet_namestore_service.h> +#include <gnunet/gnunet_reclaim_service.h> #include <gnunet/gnunet_util_lib.h> #include "gnunet_chat_lib.h" @@ -80,6 +81,19 @@ struct GNUNET_CHAT_UriLookups struct GNUNET_CHAT_UriLookups *prev; }; +struct GNUNET_CHAT_TicketProcess +{ + struct GNUNET_CHAT_Handle *handle; + + struct GNUNET_CRYPTO_PrivateKey identity; + + struct GNUNET_RECLAIM_TicketIterator *iter; + struct GNUNET_RECLAIM_Operation *op; + + struct GNUNET_CHAT_TicketProcess *next; + struct GNUNET_CHAT_TicketProcess *prev; +}; + struct GNUNET_CHAT_Handle { const struct GNUNET_CONFIGURATION_Handle* cfg; @@ -106,6 +120,9 @@ struct GNUNET_CHAT_Handle struct GNUNET_CHAT_UriLookups *lookups_head; struct GNUNET_CHAT_UriLookups *lookups_tail; + struct GNUNET_CHAT_TicketProcess *tickets_head; + struct GNUNET_CHAT_TicketProcess *tickets_tail; + struct GNUNET_CONTAINER_MultiHashMap *files; struct GNUNET_CONTAINER_MultiHashMap *contexts; struct GNUNET_CONTAINER_MultiShortmap *contacts; @@ -117,6 +134,7 @@ struct GNUNET_CHAT_Handle struct GNUNET_IDENTITY_Handle *identity; struct GNUNET_MESSENGER_Handle *messenger; struct GNUNET_NAMESTORE_Handle *namestore; + struct GNUNET_RECLAIM_Handle *reclaim; char *public_key; void *user_pointer; @@ -326,4 +344,10 @@ handle_process_records (struct GNUNET_CHAT_Handle *handle, unsigned int count, const struct GNUNET_GNSRECORD_Data *data); +/** + */ +void +handle_update_tickets (struct GNUNET_CHAT_Handle *handle, + const struct GNUNET_CRYPTO_PrivateKey *identity); + #endif /* GNUNET_CHAT_HANDLE_H_ */ diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c @@ -31,9 +31,13 @@ #include "gnunet_chat_message.h" #include "gnunet_chat_util.h" +#include <gnunet/gnunet_common.h> +#include <gnunet/gnunet_identity_service.h> #include <gnunet/gnunet_messenger_service.h> +#include <gnunet/gnunet_reclaim_service.h> #include <gnunet/gnunet_util_lib.h> #include <stdio.h> +#include <string.h> #define GNUNET_UNUSED __attribute__ ((unused)) @@ -242,11 +246,98 @@ notify_handle_fs_progress(void* cls, } void -on_handle_gnunet_identity(void *cls, - struct GNUNET_IDENTITY_Ego *ego, - void **ctx, - const char *name) +cb_task_finish_ticket_update (void *cls) { + GNUNET_assert(cls); + + struct GNUNET_CHAT_TicketProcess *tickets = ( + (struct GNUNET_CHAT_TicketProcess*) cls + ); + + struct GNUNET_CHAT_Handle *handle = tickets->handle; + + if (tickets->iter) + GNUNET_RECLAIM_ticket_iteration_stop(tickets->iter); + + if (tickets->op) + GNUNET_RECLAIM_cancel(tickets->op); + + GNUNET_CONTAINER_DLL_remove( + handle->tickets_head, + handle->tickets_tail, + tickets + ); + + GNUNET_free(tickets); +} + +void +cb_task_error_ticket_update (void *cls) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_TicketProcess *tickets = ( + (struct GNUNET_CHAT_TicketProcess*) cls + ); + + handle_send_internal_message( + tickets->handle, + NULL, + GNUNET_CHAT_FLAG_WARNING, + "Ticket update failed!" + ); + + cb_task_finish_ticket_update(cls); +} + +static void +cont_revoke_ticket_with_status (void *cls, + int32_t success, + const char *emsg) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_TicketProcess *tickets = ( + (struct GNUNET_CHAT_TicketProcess*) cls + ); + + tickets->op = NULL; + + GNUNET_RECLAIM_ticket_iteration_next(tickets->iter); +} + +void +cb_iterate_ticket_update (void *cls, + const struct GNUNET_RECLAIM_Ticket *ticket) +{ + GNUNET_assert(cls); + + struct GNUNET_CHAT_TicketProcess *tickets = ( + (struct GNUNET_CHAT_TicketProcess*) cls + ); + + struct GNUNET_CHAT_Handle *handle = tickets->handle; + + if (tickets->op) + GNUNET_RECLAIM_cancel(tickets->op); + + tickets->op = GNUNET_RECLAIM_ticket_revoke( + handle->reclaim, + &(tickets->identity), + ticket, + cont_revoke_ticket_with_status, + tickets + ); +} + +void +on_handle_gnunet_identity (void *cls, + struct GNUNET_IDENTITY_Ego *ego, + void **ctx, + const char *name) +{ + GNUNET_assert(cls); + struct GNUNET_CHAT_Handle* handle = cls; if (!ctx) @@ -279,6 +370,12 @@ on_handle_gnunet_identity(void *cls, } else { + const struct GNUNET_CRYPTO_PrivateKey *key; + key = GNUNET_IDENTITY_ego_get_private_key(ego); + + if (key) + handle_update_tickets(handle, key); + if (handle->current == accounts->account) handle_disconnect(handle); @@ -465,7 +562,14 @@ cb_account_update_completion (void *cls, struct GNUNET_CHAT_Handle *handle = accounts->handle; if ((GNUNET_EC_NONE == ec) && (key)) + { + const struct GNUNET_CRYPTO_PrivateKey *prev= handle_get_key(handle); + + if (prev) + handle_update_tickets(handle, prev); + GNUNET_MESSENGER_set_key(handle->messenger, key); + } cb_account_creation(cls, key, ec); }